I'm trying to use EQL specialization to generic functions. A trivial
example follows:
(defpackage mtest
(:use :common-lisp)
(:export :mt))
(in-package :mtest)
(defmethod mt ((n integer))
(format t "integer~%"))
(defmethod mt ((s symbol))
(format t "symbol~%"))
(defmethod mt ((s (eql 'hello)))
(format t "hello~%"))
When running this code from within the MTEST package, everything works
exactly as I expect: (MT 1) prints "integer", (MT 'ABC) prints
"symbol", and (MT 'HELLO) prints "hello". When running it from another
package, (MTEST:MT 'HELLO) prints "symbol". I suppose this happens
because the HELLO in the method is interned within the MTEST package,
and I'm passing in a HELLO interned in some other package, say
CL-USER. I thought about using uninterned symbols instead, but
uninterned symbols are not EQL.
Am I missing something obvious, or expecting unreasonable behavior?
If the latter, then I probably do not understand the use of EQL
specializers. In any case, I will greatly appreciate some
enlightenment.
--
Regards, (concatenate
Constantine Vetoshev 'string (mapcar #'code-char
(reverse '(109 111 99 46 111 111 104
97 121 64 118 99 100 114 97 112 101 103))))
Constantine Vetoshev <················@for.my.e-mail.address> wrote:
+---------------
| I'm trying to use EQL specialization to generic functions...
...
| (defmethod mt ((s (eql 'hello)))
| (format t "hello~%"))
|
| When running this code from within the MTEST package, everything works
| [and] (MTEST:MT 'HELLO) prints "symbol". I suppose this happens
| because the HELLO in the method is interned within the MTEST package,
| and I'm passing in a HELLO interned in some other package...
+---------------
Exactly so.
+---------------
| Am I missing something obvious, or expecting unreasonable behavior?
| If the latter, then I probably do not understand the use of EQL
| specializers.
+---------------
Sure you do! It's symbols (and maybe packages) you're having
trouble with. ;-} ;-}
Try executing (MTEST:MT 'MTEST::HELLO) and see what you get,
then think about the results...
-Rob
-----
Rob Warnock <····@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607
Rob Warnock wrote:
> Try executing (MTEST:MT 'MTEST::HELLO) and see what you get,
> then think about the results...
and Kenny Tilton wrote:
> But if you want 'hello to be part of the package interface (and you
> do by expecting a 'hello coded in a using package to match the
> 'hello in the eql specialization, you need to export it.
Thank you, Rob and Kenny; I understand my mistake. I haven't quite
decided how I'll get around the problem in my original code, but at
least I'm no longer stuck.
--
Regards, (concatenate
Constantine Vetoshev 'string (mapcar #'code-char
(reverse '(109 111 99 46 111 111 104
97 121 64 118 99 100 114 97 112 101 103))))
Constantine Vetoshev wrote:
> I'm trying to use EQL specialization to generic functions. A trivial
> example follows:
>
> (defpackage mtest
> (:use :common-lisp)
> (:export :mt))
>
> (in-package :mtest)
>
> (defmethod mt ((n integer))
> (format t "integer~%"))
>
> (defmethod mt ((s symbol))
> (format t "symbol~%"))
>
> (defmethod mt ((s (eql 'hello)))
> (format t "hello~%"))
>
> When running this code from within the MTEST package, everything works
> exactly as I expect: (MT 1) prints "integer", (MT 'ABC) prints
> "symbol", and (MT 'HELLO) prints "hello". When running it from another
> package, (MTEST:MT 'HELLO) prints "symbol". I suppose this happens
> because the HELLO in the method is interned within the MTEST package,
> and I'm passing in a HELLO interned in some other package, say
> CL-USER. I thought about using uninterned symbols instead, but
> uninterned symbols are not EQL.
>
> Am I missing something obvious, or expecting unreasonable behavior?
> If the latter, then I probably do not understand the use of EQL
> specializers. In any case, I will greatly appreciate some
> enlightenment.
Did you try exporting 'hello?
You understand eql specializers fine, and the package system, too,
because I think you have the analysis right.
But if you want 'hello to be part of the package interface (and you do
by expecting a 'hello coded in a using package to match the 'hello in
the eql specialization, you need to export it.
Or use keywords. :)
kenny (desperately hoping his untested advice is correct)
--
Home? http://tilton-technology.com
Cells? http://www.common-lisp.net/project/cells/
Cello? http://www.common-lisp.net/project/cello/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Your Project Here! http://alu.cliki.net/Industry%20Application