[comp.lang.clos] Redefining FORMAT

marco@ipvvis.unipv.it (Marco Ramoni) (06/11/91)

I have defined a class named text-window and I am attempting to write a specialized version of format. My definition is:

(defmethod format ((tw text-window) string &rest arguments)
  "Specialized format for text-windows."
  (print-string-in-window tw (eval `(format nil ,string ,@arguments)))
  )

When I load the file containing this definition I get the following error:

>>Error: FORMAT already names an ordinary function or a macro

LUCID-RUNTIME-SUPPORT:DEFINE-METHOD:
   Required arg 0 (...
   Required arg 1 (...
   ...

    0: Flush the existing definition
    1: Convert current definition into default method
:C  2: Try loading "..." again
    ...
    ...

If I choose option 1 everythig works fine, I get exactly what I want (that is, both the old version and the specialized one). My problem is, is there a way of getting rid of the error message? In other words, can I "Convert the current definition into default method" directly from my program?

My Email address is: alb@ipvaim.unipv.it. Thank you in advance.

					Alberto Riva
					University of Pavia, Italy

hall@aplcen.apl.jhu.edu (Marty Hall) (06/12/91)

In <marco.676653088@ipvvis> marco@ipvvis.unipv.it (Marco Ramoni) writes:
>
>I have defined a class named text-window and I am attempting to write a 
>specialized version of format. My definition is:
>
>(defmethod format ((tw text-window) string &rest arguments)
>  "Specialized format for text-windows."
>  (print-string-in-window tw (eval `(format nil ,string ,@arguments)))
>  )

[Produces error under Lucid]
> [...] can I "Convert the current definition into default method
>directly from my program?"

My understanding is that you cannot, unless there is a Lucid-specific way.
To quote chapter and verse, CLtL2 says, on page 789, "If the given name
[defined by defmethod] names a non-generic function, a macro, or a special
form, an error is signalled."

Also, as a minor suggestion, try "apply", since "eval" is so expensive:

(apply #'format nil string arguments) instead of your "eval" form.

					- Marty Hall
------------------------------------------------------
hall@aplcen.apl.jhu.edu, hall%aplcen@jhunix.bitnet, ..uunet!aplcen!hall
Artificial Intelligence Lab, AAI Corp, PO Box 126, Hunt Valley, MD 21030

(setf (need-p 'disclaimer) NIL)

miller@FS1.cam.nist.gov (Bruce R. Miller) (06/12/91)

In article <marco.676653088@ipvvis>, Marco Ramoni writes: 
> 
> I have defined a class named text-window and I am attempting to write a specialized version of format. My definition is:
> 
> (defmethod format ((tw text-window) string &rest arguments)
>   "Specialized format for text-windows."
>   (print-string-in-window tw (eval `(format nil ,string ,@arguments)))
>   )
> 
> When I load the file containing this definition I get the following error:
> 
> >>Error: FORMAT already names an ordinary function or a macro

Of course, the `real' answer is that you should be defining your own
subclass of STREAM and defining your own versions of the char/string i/o
primitives and then format would automatically do what you want!

.. Except there isn't such a thing!
 ..  at least not the last time I heard.

A problem is that all lisp's have got to have streams, but they may or
may not have CLOS, or it might be optional.  Once you've got clos based
streams in the basic lisp, you've gotta have clos.
I suppose another problem was agreeing on the stream protocol.
And since Symbolics lisp, for ex., has had Flavors based streams since
time immemorial, that would likely have been a headache to convert.
Probably each vendor had a large investment in stream machinery
that was significantly different than everyone elses.

Any insiders care to clarify? [or is this in the FAQ-to-be?] :>

lgm@cbnewsc.ATT.COM (lawrence.g.mayka) (06/12/91)

In article <marco.676653088@ipvvis> marco@ipvvis.unipv.it (Marco Ramoni) writes:
   When I load the file containing this definition I get the following error:

   >>Error: FORMAT already names an ordinary function or a macro

   LUCID-RUNTIME-SUPPORT:DEFINE-METHOD:
      Required arg 0 (...
      Required arg 1 (...
      ...

       0: Flush the existing definition
       1: Convert current definition into default method
   :C  2: Try loading "..." again
       ...
       ...

   If I choose option 1 everythig works fine, I get exactly what I want (that is, both the old version and the specialized one). My problem is, is there a way of getting rid of the error message? In other words, can I "Convert the current definition into default method" directly from my program?

If you can find out (via the debugger, asking Lucid, etc.) the class
of condition being signaled, and the name of the restart you want, you
could call INVOKE-RESTART in a handler bound via HANDLER-BIND.


	Lawrence G. Mayka
	AT&T Bell Laboratories
	lgm@iexist.att.com

Standard disclaimer.

simon@liasun2.epfl.ch (Simon Leinen) (06/12/91)

In <marco.676653088@ipvvis> marco@ipvvis.unipv.it (Marco Ramoni) writes:

Marco> (defmethod format ((tw text-window) string &rest arguments)
Marco>   "Specialized format for text-windows."
Marco>   (print-string-in-window tw (eval `(format nil ,string ,@arguments)))
Marco>   )
   [Produces error under Lucid]
Marco>  [...] can I "Convert the current definition into default method
Marco> directly from my program?"

What you can try is this (probably not portable Common Lisp, but
should work in most implementations):

	(defvar old-format #'format)
	(defmethod new-format (stream format-string &rest args)
	  (apply old-format stream format-string args))
	(defmethod new-format ((tw text-window) string &rest args)
	  ...)
	(setf (symbol-function 'format) #'new-format)

In article <1991Jun11.182622.3303@aplcen.apl.jhu.edu>
hall@aplcen.apl.jhu.edu (Marty Hall) writes:

Marty> Also, as a minor suggestion, try "apply", since "eval" is so
Marty> expensive:
Marty>
Marty> (apply #'format nil string arguments) instead of your "eval" form.

This is a good idea.  Also, the EVAL version has the problem that the
arguments are evaluated *twice*.

Marty> (setf (need-p 'disclaimer) NIL)

(defmethod needp ((who me) (ignore (eql 'disclaimer)))
  (declare (ignore ignore)) nil)
-- 
Simon.

ncramer@bbn.com (Nichael Cramer) (06/15/91)

hall@aplcen (Marty Hall) writes:
>Also, as a minor suggestion, try "apply", since "eval" is so expensive:
>(apply #'format nil string arguments) instead of your "eval" form.

Or, alternatively,

(format nil "~?" STRING ARGUMENTS)

(This is precisely the application that I always assumed that ~? had been
invented for.)

N

jonl%kuwait@LUCID.COM (Jon L White) (06/16/91)

Twice during the past week, I've tried replying to this msg, and neither
of my messages has be maild back to me from commonloops@cis.ohio-state.edu.
Is there a ball-up here?

The content of the message was documentation of the system-level extension
in Lucid's CLOS called MAKE-SPECIALIZABLE.


-- JonL --

welch@CIS.OHIO-STATE.EDU (Arun Welch) (06/17/91)

Yup, our mail system's in a state of transition from a Pyramid to a
Sun-4, and the mailing list software didn't convert over too well. A
new version should be ready RSN, at which time I'll send out the
backlog.

...arun

stuart@rpi.edu (Stuart R. Gallant) (06/19/91)

arun,

I seem to be getting double and triple copies of the lisp postings.
This was true before the mailer malfunctioned byt it is even more
noticible since all that back mail arrived.

Thanks,
Stuart