Hi James,
I'm trying to access the local bindings of the closure like it is an object
(.-x bar) should give  1. I can use a defrecord for this but I want to use 
regular functions and no macro magic

On Friday, May 25, 2018 at 9:01:22 AM UTC+3, James Gatannah wrote:

> On Thursday, May 24, 2018 at 1:22:42 PM UTC-5, Sonny To wrote:
>>
>> (defn foo[]
>>  (let [x  1]
>>    (fn []  
>>      (+ x 1)
>>     )
>>  )
>>
>> (def bar  (foo))
>>
>> Is there a way to get the value of x from closure bar?
>>
>
> I may be describing this incorrectly.
>
> You're creating a top-level var named bar.
>
> You're calling the function foo, and associating the value it returns to 
> that var bar.
>
> foo's return value happens to be a function that looks like it should be a 
> counter. Except that, in clojure, it isn't.
>
> This vaguely looks like an approach to lexical closures that I vaguely 
> remember from scheme textbooks (and Paul Graham essays).
>
> What are you really trying to do?
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to