Hi again,

Am 31.03.2009 um 19:04 schrieb Meikel Brandmeyer:

(Disclaimer: Henceforth everything is untested.)

I knew, why I put that there....

Here some hopefully more functional version:

 (defmacro bind-agent
   [a bindings]
   (let [bindings (mapcat (fn [[the-var the-val]]
                            [`(var ~the-var) the-val])
                          (partition 2 bindings))]
     `(let [bound-agent# ~a]
        (alter-meta! bound-agent# assoc
                     :agent-bindings (hash-map ~...@bindings)))))

Note the ~ in front of the a in the let....

- send-bound is not a macro anymore. (<- That's a Good Thing)

Maybe I should also give some more rationale, why this
is a Good Thing.

send-bound depends on runtime information: the metadata
of the agent. (Actually the binding is the problem.)

This is a sign, that using a macro is not a good idea. The
macro happens at compile time. So it can't really use this
information, since the agent doesn't exist, yet. Only in
special cases with Vars. But even then one can do things
like this, I would expect not to work:

  (do
    (def a (bind-agent (agent 1) [z 2]))
    (send-bound a some-fun))

One can try to push the limits with tricks and eval, but this
will lead to fragile, contorted code, which almost surely
will come back to haunt you....

So use macros wisely, but prefer functions were ever
possible.

Sincerely
Meikel

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to