(defprotocol symbolicExpr (evalx [this args])) (deftype x [a]) (let [y #(+ 1 2)] (extend-type x symbolicExpr (evalx [this args] (y)))) (evalx (x. 0) 0)
On Wednesday, December 26, 2012 6:16:13 PM UTC-8, Sunil Nandihalli wrote: > > Hi Everybody, > It looks like the following way of definition is not allowed.. what is a > good alternative way of doing this > > (defprotocol symbolicExpr > > > (evalx [this args])) > > (let [y #(+ 1 2)] > > > (deftype x [a] > > > symbolicExpr > > > (evalx [this args] > > > (y)))) > > I know I can do a (def y #(+ 1 2)) but that would unnecessarily make the > variable global to the namespace. and I don't want to put it inside the > method either, since it would have to re-evaluate the same var multiple > times when I know it will remain constant across *evalx* method calls. > what is a good way of achieving my goal without making *y *global to the > namespace? > Thanks, > Sunil. > -- 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