Re: accessing symbols in local context of a closure

2018-05-26 Thread Sonny To
James, that works but i would use a record instead of something like that. I want to extract the local bindings only with a var to the closure. I thought there might be some meta data or properties i can access. Josh, I didn't think about using java reflection api. thanks! On Saturday, May 26,

Re: accessing symbols in local context of a closure

2018-05-25 Thread James Gatannah
On Friday, May 25, 2018 at 7:40:12 AM UTC-5, Sonny To wrote: > > 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 > This isn't quite what yo

Re: accessing symbols in local context of a closure

2018-05-25 Thread Josh Tilles
My curiosity got the better of me: (require '[clojure.spec.alpha :as spec] '[clojure.test :refer [is with-test]]) (spec/fdef local-bindings :args (spec/cat :closure fn?) :ret (spec/map-of simple-keyword? any?)) (with-test (defn local-bindings [closure] (into {} (map

Re: accessing symbols in local context of a closure

2018-05-25 Thread Sonny To
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

Re: accessing symbols in local context of a closure

2018-05-24 Thread James Gatannah
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

Re: accessing symbols in local context of a closure

2018-05-24 Thread Alan Thompson
No, it is hidden inside the closure and can't be accessed from the outside. On Thu, May 24, 2018 at 11:22 AM, 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? > > -- > You received

accessing symbols in local context of a closure

2018-05-24 Thread Sonny To
(defn foo[] (let [x 1] (fn [] (+ x 1) ) ) (def bar (foo)) Is there a way to get the value of x from closure bar? -- 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 tha