Richard Shann <richard.sh...@virgin.net> writes: > I am stuck on one of those symbol/variable-name-in-a-string things > again: > > (define mything "display") > (display (eval-string mything)) > > that's fine. But can I test that the string in mything is the name of a > variable before doing the eval-string and finding out the hard way? I've > been doing (symbol? mything) etc, and going witless. Do I have to do all > that catch stuff? > > The situation is that I can guess (programmatically construct that is) > the name of the variable, but it may not be defined. If it isn't I will > just say so, but if it is I want the string it is defined to hold. > > Any help much appreciated!
Hi Richard... :-) You can use defined? to find out if an arbitrary symbol is defined (in the current module). It takes a symbol, so for example: (let ((sym (with-input-from-string mything read))) (if (defined? sym) (eval sym (current-module)) (display "Sorry, that isn't defined"))) Does that help? Regards, Neil