On 4 February 2010 17:24, Bryce <[email protected]> wrote:
> I'm sure I'm messing up something fairly basic; any idea what I'm
> doing wrong?

1. At the time the code inside your macro definition executes, the "a"
you pass in as the first argument in your example is just a symbol.
Ditto for "b". It makes no sense to use replace on that.

2. Even if the replace bit worked, you'd get something like (* a b)
from it -- that's a list containing three symbols, not a function, so
you can't use it as a function.

It seems that what you're trying to do is to use the expression, plus
the replacements, as the *body* of a function to be applied to the
arguments specified as the third argument to the macro, which brings
me to my third point:

3. Making your example work would necessitate discovering which of the
symbols in the (+ a b) form are to be treated as formal arguments. In
this case, the answer would be a (to be bound to 3) and b (to be bound
to 4). In general, that's very nearly impossible, as any symbol not in
your replacements map may equally well be a function which you don't
want to replace.

Example: Say your expression changes to (+ a (inc b)) -- you might
expect this to evaluate to (* 3 (inc 4)) => 15, but how's your code to
tell that it's meant to substitute stuff from target into the
expression while leaving the symbol inc alone? You could come up with
some heuristic, but that doesn't seem worthwhile.

I thought I'd come up with some alternate design to get you started on
reimagining this, but I'm finding it problematic without knowing your
purpose in wanting this kind of thing... I hope the above helps
somewhat.

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