I don't think it's very typical to pass a form to a function, unless you plan on using eval at runtime. If it doesn't need to happen at runtime, then you'd do this with a macro approximately like this:
user=> (defmacro bar [f] `(fn [& args#] (let [~'size (count args#)] ~f))) #'user/bar user=> (bar (+ size 10)) #<user$eval675$fn__676 user$eval675$fn__676@11b4c2> user=> (*1 1 2 3 4) 14 ~Jeff On Jul 28, 6:48 pm, Sam Aaron <samaa...@gmail.com> wrote: > Hi there, > > I'm trying to create a fn which does the following: > > * returns a fn which takes an arbitrary number of args > * calls a helper fn, passing the incoming args returning a vector of > alternating symbols and vals > * creates a let form using the vector of alternating symbols and vals > returned by the helper fn as the bindings > * contains some inner form that makes use of the bindings > > i.e. is it possible to implement something that allows the following to work: > > (defn binding-vec > [args] > ['size (count args)]) > > (defn mk-dynamically-bound-fn > [form] > ;; returns a fn with sign [& args] which > ;; uses binding-vec to create a the vec for > ;; which a let statement binds around form > ) > > (def a (mk-dynamically-bound-fn '(+ size 10))) > > (a 1 2 3 4) ;=> 14 (the number of args + 10) > > Please let me know if I'm being a bit crazy with the question. It's totally > possible that I'm barking up the wrong tree with this line of enquiry. > > Sam > > ---http://sam.aaron.name -- 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