[erlang-questions] scope of variables

Vlad Dumitrescu vladdu55@REDACTED
Mon Sep 4 15:17:38 CEST 2006


On 9/4/06, Richard Carlsson <richardc@REDACTED> wrote:
> Ok, so it's not just a question of being able to use local bindings -
> i's also about being able to inject code (the macro body) into some
> arbitrary context and avoid accidental name capture of variables in the
> macro. But then the injected code (not the context) must be written with
> this in mind, or you will have to do renaming when you inject it.

Yes, or better: have the compiler do it for me. Which is what I'm trying to do.

If it will work as advertised, there are a lot of cool things that
will become posible to do. Like for example optimizations. If I have
to do a lot of math:pow(X, 72) with different X, I could write a
powN/2 macro that produces an optimized powN/1 for any particular N
(72 in this case). That would be
  Pow72 = fun(X) ->
    X2 = X*X,
    X4 = X2*X2,
    X8 = X4*X4,
    X16 = X8*X8,
    X32 = X16*X16,
    X64 = X32*X32,
   X64+X8.
Maybe not so spectacular, but a similar example wouuld be to produce
custom regexp-matching funs, that might be much more efficient than
the current ones. I didn't take that example because it's not as
simple to produce one by hand :-)

regards,
Vlad



More information about the erlang-questions mailing list