[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A variable that holds a string which may be the name of a variable.
From: |
Neil Jerram |
Subject: |
Re: A variable that holds a string which may be the name of a variable. |
Date: |
Wed, 02 Dec 2009 22:19:56 +0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
Richard Shann <address@hidden> 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