d83_sven_a@tekno.chalmers.se (Sven (Sciz) Axelsson) (10/02/89)
I havve run into a problem programming in Allegro Common LISP's object extensions. Basically I have a menu containing names of different classes and I want to create an instance of the class that is selected. I've tried the following: ... (setq an-object (oneof (find-symbol a-menu-item-title))) ... but it doesn't work. If someone knows what I'm talking about, please help. +-------------------------+--------------------------------+------------------+ | Sven Axelsson | d83_sven_a@tekno.chalmers.se | DISCLAIMER: | | dep:t of Linguistics | (^^ best ^^) | | | univ. of Gothenburg | dlv_sa@hum.gu.se | This is not | | SWEDEN | usdsa@seguc21.bitnet | a disclaimer. | +-------------------------+--------------------------------+------------------+
asg@pyuxf.UUCP (alan geller) (10/09/89)
In article <1966@tekno.chalmers.se>, d83_sven_a@tekno.chalmers.se (Sven (Sciz) Axelsson) writes: > I havve run into a problem programming in Allegro Common LISP's object > extensions. Basically I have a menu containing names of different classes > and I want to create an instance of the class that is selected. I've tried > the following: > > ... > (setq an-object (oneof (find-symbol a-menu-item-title))) > ... > > but it doesn't work. If someone knows what I'm talking about, please help. > > +-------------------------+--------------------------------+-----------------+ > | Sven Axelsson | d83_sven_a@tekno.chalmers.se | DISCLAIMER: | > | dep:t of Linguistics | (^^ best ^^) | | > | univ. of Gothenburg | dlv_sa@hum.gu.se | This is not | > | SWEDEN | usdsa@seguc21.bitnet | a disclaimer. | > +-------------------------+--------------------------------+-----------------+ There are two problems with your attempt, both fairly easily solved: - You may need to pass (find-package "CCL") as a second parameter to find-symbol. This is true for most of the pre-defined classes, such as *WINDOW*. Note, also, that it is important that the menu item title that you pass to find-package be in upper-case (i.e., *WINDOW*, not *window*), or the symbol won't be found. Alternatively, you could use string-upcase to make the upper-case symbol name. - You need to call symbol-value on the return of find-symbol. This is because find-symbol's value is the symbol itself, rather than the current value of the symbol (that is, it is '*WINDOW* rather than *WINDOW*). Thus, you wind up with something like (setq x (oneof (symbol-value (find-symbol (string-upcase a-menu-item-title) (find-package menu-item-package))))) I've tested this, in the Listener, in ACL 1.2.2; it works fine. The toughest thing to keep track of will be the package that the object symbols are defined in; while the predefined objects are all in "CCL", I think, user defined ones will be in "USER", or in whatever package your user chooses. Alan Geller Bellcore ...!{princeton,rutgers}!bellcore!pyuxf!asg "I only work AT Bellcore, not FOR Bellcore, so leave them out of it."