help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to convert a string to a symbol?


From: Pascal J. Bourguignon
Subject: Re: how to convert a string to a symbol?
Date: Sun, 14 Sep 2008 09:25:45 +0200
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.2 (gnu/linux)

"Drew Adams" <drew.adams@oracle.com> writes:

>> > (setq str "(> 2 1)")
>> > I want something like: (eval (string-to-symbol str))
>> 
>> (intern str)
>
> And if you really want the value of the symbol (per your use of `eval' above):
>
> (symbol-value (intern str))
>
> But you might want to give it a value first ;-) -
>
> (set (intern "(> 2 1)") 42)
>
> (symbol-value '\(>\ 2\ 1\)) ; The answer is 42.
>
> However, as always with questions of this type, one wonders what you are
> _really_ trying to do (not to mention why)...

sunways, what Drew tries to hint at is that you don't want
string-to-symbol.

(By the way, there's another way to get a symbol from a string, it's
make-symbol, but it makes an uninterned symbol, which is even less
what you want).

So as you may have realized by now, what you want is to get the
symbolic expression, or s-exp (> 2 1) from "(> 2 1)", and this can be
done by "reading" the string, so, logically, with read-from-string.
(car (read-from-string "(> 2 1)")) -> (> 2 1)


Now the question would be where did you get this string from in the
first place?  You probably could have used read, or specified you
wanted a s-exp instead of a string at the source.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
You never feed me.
Perhaps I'll sleep on your face.
That will sure show you.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]