Re: dynamically generated let bindings

2011-07-30 Thread Ken Wesson
On Sat, Jul 30, 2011 at 9:07 PM, Alan Malloy wrote: > (get :foo argmap__5673__auto 42) is the right way to solve this > problem. Is another way to solve it, yes, and a good one. > Or if, as in the current example, you want to destructure a map with > lots of defaults, simply: > > (let [{:keys [f

Re: dynamically generated let bindings

2011-07-30 Thread Alan Malloy
On Jul 29, 2:02 pm, Ken Wesson wrote: > (fn [& args] >   (let [argmap__5673__auto (#'some-ns/parse-args args) >         foo (or (:foo argmap__5673__auto) 42) >         bar (or (:bar argmap__5673__auto) nil) >         ...] >     (body goes here))) > where you define a private parse-args function in

Re: dynamically generated let bindings

2011-07-30 Thread Ken Wesson
On Sat, Jul 30, 2011 at 7:29 AM, Sam Aaron wrote: >> (fn [& args] >>  (let [foo (some logic goes here) >>        bar (some logic goes here) >>        ...] >>    (body goes here))) > > I just finished implementing a solution and it looks exactly like this. > You're absolutely right - this is preci

Re: dynamically generated let bindings

2011-07-30 Thread Sam Aaron
Hi Ken, On 29 Jul 2011, at 22:02, Ken Wesson wrote: >> P.S. Thanks everyone for your help so far. My brain is overheating but I am >> learning a lot. > > You're welcome. > > To do what you're proposing you will probably need the emitted > function to look like: > > (fn [& args] > (let [foo (s

Re: dynamically generated let bindings

2011-07-29 Thread Ken Wesson
> P.S. Thanks everyone for your help so far. My brain is overheating but I am > learning a lot. You're welcome. To do what you're proposing you will probably need the emitted function to look like: (fn [& args] (let [foo (some logic goes here) bar (some logic goes here) ...]

Re: dynamically generated let bindings

2011-07-29 Thread Sam Aaron
On 29 Jul 2011, at 12:56, Ken Wesson wrote: >>> >> >> That seems to blow up > > How so? (defn binding-vec [foos] (vec (interleave names (take (count names) (repeat `(count ~foos)) (defmacro magic-fn [& forms] (let [args (gensym 'args)] `(fn [& ~args] (let ~(binding-vec args)

Re: dynamically generated let bindings

2011-07-29 Thread Ken Wesson
On Fri, Jul 29, 2011 at 7:35 AM, Sam Aaron wrote: > > On 29 Jul 2011, at 12:11, Ken Wesson wrote: >> >> Why not just (vec (interleave names (take (count names) (repeat >> `(count ~foos)? >> > > That seems to blow up How so? > The actual end goal is to be able to define a macro (or whatever)

Re: dynamically generated let bindings

2011-07-29 Thread Sam Aaron
On 29 Jul 2011, at 12:11, Ken Wesson wrote: > > Why not just (vec (interleave names (take (count names) (repeat > `(count ~foos)? > That seems to blow up: (defn binding-vec [foos] (vec (interleave names (take (count names) (repeat `(count ~foos)) (defmacro magic-fn [& forms] (let

Re: dynamically generated let bindings

2011-07-29 Thread Ken Wesson
On Fri, Jul 29, 2011 at 6:57 AM, Sam Aaron wrote: > However, something like the following doesn't work: > > (defn binding-vec [foos] >  `(vec (interleave ~names ~(take (count names) (repeat '`(count ~foos)) > > A, because the above code is probably incorrect (I just cobbled it together > for

Re: dynamically generated let bindings

2011-07-29 Thread Sam Aaron
Hi there, On 29 Jul 2011, at 10:05, Alan Malloy wrote: > > (defn binding-vec [foos] > ['size `(count ~foos)]) > > (defmacro magic-fn > [& forms] > (let [args (gensym 'args)] >`(fn [& ~args] > (let ~(binding-vec args) > ~@forms > > ((magic-fn (+ size 10)) 1 2) ;=> 12 Ac

Re: dynamically generated let bindings

2011-07-29 Thread Sam Aaron
Hi Alan, On 29 Jul 2011, at 10:05, Alan Malloy wrote: >> >> Sorry, I was just trying to simplify things to try and get directly to the >> meat of the problem. > > No apologies needed - reducing to a simple case is great. But here, > the simplification was probably too severe. > Sorry, I'm Eng

Re: dynamically generated let bindings

2011-07-29 Thread Alan Malloy
On Jul 29, 1:49 am, Sam Aaron wrote: > On 29 Jul 2011, at 07:22, Ken Wesson wrote: > > > On Fri, Jul 29, 2011 at 12:49 AM, Jeff Rose wrote: > >> I don't think it's very typical to pass a form to a function, unless > >> you plan on using eval at runtime. > > > Or it's a function called by a macro

Re: dynamically generated let bindings

2011-07-29 Thread Sam Aaron
On 29 Jul 2011, at 00:46, Kent wrote: > 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

Re: dynamically generated let bindings

2011-07-29 Thread Sam Aaron
On 29 Jul 2011, at 07:22, Ken Wesson wrote: > On Fri, Jul 29, 2011 at 12:49 AM, Jeff Rose wrote: >> I don't think it's very typical to pass a form to a function, unless >> you plan on using eval at runtime. > > Or it's a function called by a macro to do some processing of forms. Yep, this is p

Re: dynamically generated let bindings

2011-07-28 Thread Ken Wesson
On Fri, Jul 29, 2011 at 12:49 AM, Jeff Rose wrote: > I don't think it's very typical to pass a form to a function, unless > you plan on using eval at runtime. Or it's a function called by a macro to do some processing of forms. -- Protege: What is this seething mass of parentheses?! Master: You

Re: dynamically generated let bindings

2011-07-28 Thread Jeff Rose
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=> (ba

Re: dynamically generated let bindings

2011-07-28 Thread Alan Malloy
On Jul 28, 3:48 pm, Sam Aaron 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 th

Re: dynamically generated let bindings

2011-07-28 Thread Ken Wesson
On Thu, Jul 28, 2011 at 6:48 PM, Sam Aaron 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

Re: dynamically generated let bindings

2011-07-28 Thread Kent
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 "bin

dynamically generated let bindings

2011-07-28 Thread Sam Aaron
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 b