On 8 March 2010 17:37, Michael Gardner <[email protected]> wrote:
> Thanks for the tip. After some experimentation:
>
> (apply (memfn connect a b c d) store (map config [:host :port :user 
> :password]))

Oh right, you wanted more arguments. So I should have suggested
#(.connect %1 %2 %3 %4).

> but why does memfn require these "dummy" arguments?

It's simple to write this way... And if you provide type hints, I'd
expect the resulting function to be quite performant. If you don't
care about that, here's a flexible alternative using eval:

user> (defmacro methodfn [name]
        `(fn [& args#]
           (apply
            (eval (concat (list '~`memfn '~name)
                          (map (fn [~'_] (gensym)) (rest args#))))
            args#)))
#'user/methodfn
user> ((methodfn substring) "asdf" 1)
"sdf"
user> ((methodfn substring) "asdf" 1 3)
"sd"

Sincerely,
Michał

-- 
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

Reply via email to