Hi,
I want to read a lisp expression from a string and evaluate it in the
correct lexical env:
(let ((x 1))
(eval (read-from-string "x")))
will (for obvious reasons) not work. However, I have no workaround, any
suggestions?
Thanks,
tunc
e.g.
----
(let ((x 1))
(eval-correctly (read-from-string "x")))
=> 1
is the desired result.
"H. Tunc Simsek" <······@EECS.Berkeley.Edu> writes:
> Hi,
>
> I want to read a lisp expression from a string and evaluate it in the
> correct lexical env:
>
> (let ((x 1))
> (eval (read-from-string "x")))
>
> will (for obvious reasons) not work. However, I have no workaround, any
> suggestions?
>
> Thanks,
> tunc
>
> e.g.
> ----
>
> (let ((x 1))
> (eval-correctly (read-from-string "x")))
>
> => 1
>
> is the desired result.
Whatever it is you are trying to do, there is a better way.
EVAL evaluates its form in the current dynamic environment and the
null lexical environment. The best you can do is:
(progv '(x) '(1)
(eval (read-from-string "x")))
Christopher
Christopher R. Barry <······@2xtreme.net> wrote:
+---------------
| "H. Tunc Simsek" <······@EECS.Berkeley.Edu> writes:
| > (let ((x 1))
| > (eval (read-from-string "x")))
...
| EVAL evaluates its form in the current dynamic environment and the
| null lexical environment. The best you can do is:
|
| (progv '(x) '(1)
| (eval (read-from-string "x")))
+---------------
Yeah, that works, but might cause conflicts if the string contains inner
lexical bindings for "x", or if for some reason you didn't *want* "x" to
be dynamic. If he really wanted a lexical environment for EVAL, he could
always do something hacky like this:
(eval
`(let ((x 1))
,(read-from-string "x")))
-Rob
-----
Rob Warnock, 8L-846 ····@sgi.com
Applied Networking http://reality.sgi.com/rpw3/
Silicon Graphics, Inc. Phone: 650-933-1673
1600 Amphitheatre Pkwy. FAX: 650-933-0511
Mountain View, CA 94043 PP-ASEL-IA