Discussion:
Evaluate a simple string?
(too old to reply)
Asif
2012-10-09 07:46:08 UTC
Permalink
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
2012-10-09 07:53:39 UTC
Permalink
Post by Asif
Trying to figure out how to evaluate a simple string.
(setq x "princ 3")
(eval x)
=> "princ 3"
=> 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
2012-10-09 17:22:58 UTC
Permalink
Post by Julian Bradfield
Post by Asif
Trying to figure out how to evaluate a simple string.
(setq x "princ 3")
(eval x)
=> "princ 3"
=> 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.
Nice!
Thanks very much Julian!
____
Asif

Loading...