Page 1 of 1

Symbols

Posted: Sat Aug 23, 2008 8:29 am
by Harnon
Basically, i'm trying to automatically define a method which expands into something like this:
(defmethod general-walker::application-form ...)
This code is in another package. The problem is getting the general-walker::application-form to be produced. I don't want to export the symbol application-form from general-walker package. I tried (find-symbol 'application-form :general-walker), but it only returns a symbol which has been inhereted from another package (:arnesi). So, all in all, i want to be able to find multiple symbols in a package which have the same name (they're both method names). How can i do this?
Thx! :D

Re: Symbols

Posted: Sat Aug 23, 2008 9:49 am
by danb
Harnon wrote:Basically, i'm trying to automatically define a method
What do you mean "automatically"? Are you trying to do it at runtime?
This code is in another package.
Why?
i want to be able to find multiple symbols in a package which have the same name
You can't do that.
Within one package, any particular name can refer to at most one symbol.
(they're both method names)
You can't access methods directly. You can only define them and then call or pass the corresponding generic function.
Can you say more about your application? Maybe there's a simpler way to do what you have in mind.

Re: Symbols

Posted: Sat Aug 23, 2008 4:10 pm
by Harnon
Sorry, i was in a rush, i wasn't thinking. I actually didn't need to do this, but here's a convoluted example to demonstrate my question, which i guess has no practical use :D .
Question rephrased: Let's say there is a package, named arnesi, which exports the symbol walker. This symbol is actually the name of a method. The package :general-walker uses the arnesi package, but also defines a method named
walker which specializes on a different class. Since you can create methods with the same name, there'll be no error. So, the question is, if you try to find the symbol 'walker in package :general-walker, will it return the inherited method symbol from arnesi or that from general-walker? Why? On lispworks, using (find-symbol 'walker :general-walker) will return (values 'arnesi:walker :external). I half expected it to return (values 'general-walker::walker :internal)

Code: Select all

(defpackage :arnesi (:use :cl) (:export :walker :application-form))
(in-package :arnesi)
(defclass application-form () ())
(defmethod walker ((class application-form)) (print "arnesi-walker"))

(defpackage :general-walker (:use :cl :arnesi) (:export :walker))
(in-package :general-walker)
(defmethod walker ((class application-form))
 (print "general-walker-form"))

(defpackage :test (:use :cl ))
(in-package :test)
(find-symbol 'walker :general-walker)

Re: Symbols

Posted: Sat Aug 23, 2008 10:01 pm
by qbg
WALKER is created in ARNESI, so its SYMBOL-PACKAGE is ARNESI. Because when you inherit a symbol it is the same symbol its SYMBOL-PACKAGE doesn't change.

Re: Symbols

Posted: Sat Aug 23, 2008 11:00 pm
by danb
Harnon wrote:So, the question is, if you try to find the symbol 'walker in package :general-walker, will it return the inherited method symbol from arnesi or that from general-walker? Why?
As qbg said, GENERAL-WALKER uses the existing symbol in ARNESI. It doesn't create a new one. So general-walker:walker is EQ to arnesi:walker. The methods have to be named by exactly the same symbol to be dispatched by the same generic function.
On lispworks, using (find-symbol 'walker :general-walker) will return (values 'arnesi:walker :external). I half expected it to return (values 'general-walker::walker :internal)
In SBCL, (find-symbol "WALKER" :general-walker) returns ARNESI:WALKER and :INHERITED.

Re: Symbols

Posted: Sun Aug 24, 2008 11:05 am
by Harnon
Thxs! I guess that clear up my not-so-useful question :)