[Ecls-list] Gray streams

Juan Jose Garcia-Ripoll jjgarcia at users.sourceforge.net
Mon Mar 31 07:02:25 UTC 2008


On Mon, Mar 31, 2008 at 6:40 AM, Brian Spilsbury
<brian.spilsbury at gmail.com> wrote:
>  If you were to rename the COMMON-LISP package to the ECL-CL package
>  (or whatever), and then place a COMMON-LISP package which used this,
>  then you could control what other packages receive when they use
>  COMMON-LISP:CLOSE (for example), and GRAY:CLOSE could still use
>  ECL-CL:CLOSE for its default case.

My brain must be a bit dense today, but I miss the point. GRAY:CLOSE
only has to be used when defining a method that specializes CLOSE. The
user is free to use CL:CLOSE on a Gray stream: it will simply work.
Let me illustrate it:

(defclass my-stream (fundamental-character-input-stream)
  ((a-stream :initarg :stream)))

(defmethod gray:close (stream &key abort)
  (close (slot-value stream 'a-stream) :abort abort))

(let ((a (make-instance 'my-stream :stream (open "foo.txt" :direction :input))))
  ...
 (close a)) ; Here, GRAY:CLOSE would also work

Notice that the standard function will work on your stream if you have
specialized the Gray generic function for it. Similarly for
STREAM-ELEMENT-TYPE and other functions. The important point is that
the standard functions only perform a method dispatch when the
argument is a CLOS object, thus avoiding this expesive process for
ordinary streams.

>  I suspect that that might involve changing a lot of strings, though. :)

More than that, it changes the home package of a standard symbol.

>  A cheaper option for the implementor is for the user to shadowing
>  import gray:close, etc into each package which wants to use it.

This is what I intended to write in the changelog, but probably I was
not clear enough.

Juanjo

-- 
Facultad de Fisicas, Universidad Complutense,
Ciudad Universitaria s/n Madrid 28040 (Spain)
http://juanjose.garciaripoll.googlepages.com




More information about the ecl-devel mailing list