Hello, thanks everyone for replies,
On Thu, Sep 3, 2009 at 2:36 PM, Konrad Hinsen <konrad.hin...@fastmail.net> wrote: > > On 3 Sep 2009, at 08:24, Miron Brezuleanu wrote: > > > user=> (let [x 1] (eval '(inc x))) > > java.lang.Exception: Unable to resolve symbol: x in this context > > (NO_SOURCE_FILE:1) > > > > (on a freshly downloaded&compiled clojure from github) > > > > According to my understanding of http://clojure.org/evaluation, my > > code should simply return 2. > > The critical point here is the environment in which eval evaluates its > argument. This is not specified on the documentation page you cite. > Eval uses the environment of the current namespace, not taking into > account the lexical environment surrounding the call to eval itself. > Said differently, the result is the same as if the argument to eval > were placed at the outermost expression level of the module inside > which eval is called. > Turns out my question was asked before, I just used the wrong keywords when searching (local environment instead of local bindings). I'm interested in eval because I thought it would be nice if we could use something like Python's code.interact() for debugging. Basically, get a repl inside an executing function, that has access to the environment of the function. Poor man's debugger :-) I guess that is rather hard to obtain, since eval executes in a 'global' context and there is no way to specify an environment in which to execute the code. That could be simulated, if it was a way to reach to the environment of a function (as a map of symbols to values). Then the expression to eval could be bound in a let, something like this: ;; assuming that the local environment is {'a 1 'b 2} ;; and we want to execute (+ a b) ;; we would have to generate something like `(let [a ~(get-local-value 'a) b ~(get-local-value 'b)] (+ a b) and 'eval' that. Is there a way to get the list of symbols bound locally and to access their values? ... Or a better way to simulate code.interact() ? Thanks, -- Miron Brezuleanu --~--~---------~--~----~------------~-------~--~----~ 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 Note that posts from new members are moderated - please be patient with your first post. 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 -~----------~----~----~----~------~----~------~--~---