On May 1, 9:28 am, Julien <julien.ma...@gmail.com> wrote:
> How could (read-string "") access to a binding local to a form?
> Is this possible?

(let...) defines a lexical scope, which is only available to forms
that are physically (lexically) inside the let.  The result of read-
string doesn't count as "inside", because the form you've "read"
doesn't exist until the read-string function is called.

(eval (read-string...)) is a little like calling a function.  You can
pass arguments to the function, as Christophe suggested, or use a
dynamic scope.  A dynamic scope, created with (binding...), makes a
value available to the code inside the binding AND any functions
called by that code.  But you can only use binding on vars that have
already been defined or declared.  So this works:

(declare *stuff*)
(binding [*stuff* "my stuff"]
   (eval (read-string "(println *stuff*)")))
;;=> my stuff

-SS
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to