I'm not sure what you're trying to do with this and, based on that
ignorance, I'm not sure I think it's a great idea. Maybe you are being
a bit crazy, and maybe your a genius.  Who am I to say?

Here is a function that does what you want.  The only difference is
that my function also takes the "binding-vec" function as an argument.


(defn mdbf [form binding-func]
  (fn [& args]
    (eval `(let ~(binding-func args) ~form))))

Here it is used in your example.

(defn binding-vec
  [args]
   ['size (count args)]

(def a (mdbf '(+ size 10) binding-vec))

(a 1 2 3 4) => 14

Kent.

On Jul 28, 3: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

Reply via email to