This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Symbols

6 posts · 4674 views

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

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.
--Dan B.

Re: Symbols

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)
(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

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

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.
--Dan B.

Re: Symbols

Thxs! I guess that clear up my not-so-useful question :)