Symbols

Discussion of Common Lisp

Symbols

Postby Harnon » Sat Aug 23, 2008 8:29 am

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
Harnon
 
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am

Re: Symbols

Postby danb » Sat Aug 23, 2008 9:49 am

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.
danb
 
Posts: 35
Joined: Sat Jun 28, 2008 1:05 pm
Location: Urbana, Illinois, US

Re: Symbols

Postby Harnon » Sat Aug 23, 2008 4:10 pm

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)
Harnon
 
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am

Re: Symbols

Postby qbg » Sat Aug 23, 2008 10:01 pm

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.
qbg
 
Posts: 64
Joined: Mon Jun 30, 2008 1:05 pm
Location: Minnesota

Re: Symbols

Postby danb » Sat Aug 23, 2008 11:00 pm

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.
danb
 
Posts: 35
Joined: Sat Jun 28, 2008 1:05 pm
Location: Urbana, Illinois, US

Re: Symbols

Postby Harnon » Sun Aug 24, 2008 11:05 am

Thxs! I guess that clear up my not-so-useful question :)
Harnon
 
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am


Return to Common Lisp

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests