Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Evaluate a simple string?

13 views
Skip to first unread message

Asif

unread,
Oct 9, 2012, 3:46:08 AM10/9/12
to
Trying to figure out how to evaluate a simple string.

(setq x "princ 3")
(eval x)
=> "princ 3"

Hpw do I evaluate x to get:
=> 3

By-the-way I tried:
(eval `,x)
=> "princ 3"

Thanks for any help!
____
Asif

Julian Bradfield

unread,
Oct 9, 2012, 3:53:39 AM10/9/12
to
On 2012-10-09, Asif <asif.h...@gmail.com> wrote:
> Trying to figure out how to evaluate a simple string.
>
> (setq x "princ 3")
> (eval x)
>=> "princ 3"
>
> Hpw do I evaluate x to get:
>=> 3

With difficulty, since "princ 3" is not a Lisp expression.
You mean "(princ 3)", I guess.

Then you can do

(eval (car (read-from-string "(princ 3)")))

which will print 3 to the output, and evaluate to 3.

Asif

unread,
Oct 9, 2012, 1:22:58 PM10/9/12
to
On Tuesday, October 9, 2012 12:55:04 AM UTC-7, Julian Bradfield wrote:
Nice!
Thanks very much Julian!
____
Asif
0 new messages