On 29 Jul 2011, at 07:22, Ken Wesson wrote:
> On Fri, Jul 29, 2011 at 12:49 AM, Jeff Rose <[email protected]> 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 precisely what I was considering. I should have explicitly made
mk-dynamically-bound-fn a macro in my example - a miscommunication on my part.
On 29 Jul 2011, at 02:12, Alan Malloy wrote:
>
> It's not clear how much of this is relevant to your actual problem, vs
> the simple version you're posting here.
Sorry, I was just trying to simplify things to try and get directly to the meat
of the problem.
> If you want something more general, that implicitly binds things for
> you based on some code somewhere else (ew ew ew), then you need a
> macro. This implementation is pretty gross; I suspect it could be
> better, but you're trying to do something that seems weird to me.
>
> (defn binding-vec []
> ['size '(count args)])
>
> (defmacro magic-fn
> [& forms]
> `(fn [& ~'args]
> (let ~(binding-vec)
> ~@forms)))
>
>
> user> ((magic-fn (+ size 10)) 1 2)
> 12
Very cool, although it's not quite what I'd like. I'd like binding-vec to be a
function of the resulting magic-fn's args.
I'm aiming for something like this, but can't get it to quite work:
(defn binding-vec [foos]
'[size (count ~foos)])
(defmacro magic-fn
[& forms]
`(fn [& ~'args]
(let ~(binding-vec ~'args)
~@forms)))
((magic-fn (+ size 10)) 1 2) ;=> BOOM
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 [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en