reify closes over surrounding locals, so can't you do:
(let [context-map {:me this}]
+1 to using reify as a closure.The feature would only be necessary if you need to include "this" in the context-map.
Is it really worth to complect reify in order to gain that possibility?
--
--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/clojure-dev/-/oKnRndNNAnQJ.
To post to this group, send email to cloju...@googlegroups.com.
To unsubscribe from this group, send email to clojure-dev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/clojure-dev?hl=en.
Even if I split things out using a deftype, I just don't see how I can achieve my goal, which is to capture the reified instance in a single map; I'm back to constantly regenerating the map, somewhat needlessly.
I think "complect" is in the eye of the beholder.
To me, the devil is in how to introduce this feature without allowing random fns (called from the let-style block) to see an object half initialized?
--
Why can't you just implement ILookup and the other relevant bits for map-like behavior if you need it?
On Wednesday, November 14, 2012, Howard M. Lewis Ship wrote:
I'm in a situation where, if I was using Java code, I would introduce final fields initialized in the constructor. Instead I'm using reify with protocols, and hitting what I perceive to be a small limitation.Here's a simplified version of what I'm doing.(reifyMyProtocol(do-that-thing [this event] (handle-event {:me this} event)))... in my real code there's a lot of repetition concerning building that context map; in addition, it has to be built all the time, when a single instance could be created once and shared.To address this repetition, i'd like to have some syntax for initializing fields of the reified class, perhaps:(reify[context-map {:me this}]MyProtocol(do-that-thing [this event] (handle-event context-map event)))In other words, a let-style block of field assignments that are implicitly part of the generated class' constructor, and with values that are in lexical scope of the protocol function implementations.I think this is a reasonable thing to want to do ... as is, I have several protocol methods that all want to extend a context map with a reference back to this reified instance and I don't like the duplication.Thoughts?--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/clojure-dev/-/oKnRndNNAnQJ.
To post to this group, send email to cloju...@googlegroups.com.
To unsubscribe from this group, send email to clojure-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/clojure-dev/-/o26H0xsrpbEJ.
To unsubscribe from this group, send email to clojure-dev...@googlegroups.com.