Pascal J. Bourguignon <pjb@informatimago.com> wrote:
+---------------
| Madhu <enometh@meer.net> writes:
| > This is the easiest clearest way to solve the problem with the
| > mechanism provided by the tilde-slash directive. You _have_ to
| > have a global function in CL-USER because the spec demands it.
|
| Actually, this is wrong.
|
| C/USER[411]> (defpackage "F" (:use "CL") (:export "X"))
| #<PACKAGE F>
| C/USER[412]> (defun F:X (stream object &rest args) (princ "X" stream))
| F:X
| C/USER[413]> (format t "~/F:X/" 'toto)
| X
| NIL
| C/USER[414]>
+---------------
By the way, have you ever noticed that ~/NAME/ violates the ":"/"::"
reader protocol for "external/internal" symbol indication?
> (defpackage "F" (:use "CL"))
#<The F package, 0/9 internal, 0/2 external>
> (defun F::X (stream object &rest args)
(declare (ignorable object args))
(princ "X" stream))
F::X
> (format t "~/F::X/" 'toto) ; This I expected to work.
X
NIL
> (format t "~/F:X/" 'toto) ; This I didn't.
X
NIL
>
And, no, I didn't accidentally make X external: ;-}
> (find-symbol "X" "F")
F::X
:INTERNAL
> (ignore-errors (read-from-string "F::X"))
F::X
4
> (ignore-errors (read-from-string "F:X")) ; Error expected here.
NIL
#<LISP::READER-PACKAGE-ERROR {48A42615}>
>
Anyway, as odd as this is, the CLHS seems to require it:
22.3.5.4 Tilde Slash: Call Function
...
If NAME contains a single colon (:) or double colon (::), then
everything up to but not including the first ":" or "::" is taken
to be a string that names a package. Everything after the first
":" or "::" (if any) is taken to be a string that names a symbol.
The function corresponding to a ~/NAME/ directive is obtained by
looking up the symbol that has the indicated name in the indicated
package.
...
Notice that the lookup is *not* described in terms of READ of
the whole name, but rather as a FIND-SYMBOL or INTERN of the
pieces of NAME separately. Anybody know why?
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607