Fresh variable names in Erlang

Hector Rivas Gandara keymon@REDACTED
Fri Aug 27 14:21:01 CEST 2004


Hi,
I'm trying to define some macros to simulate the "try ... with ..." 
syntax of caml.
I wrote this macros:

-define(TRY, case catch).
-define(WITH, of).
-define(END_TRY, ; Finally -> Finally end).

and it works with:

?TRY begin
    Y = X,
    Y = 1
end
?WITH
    {'EXIT', R} -> {catched, R}
?END_TRY.

but if you write more TRY_WITH in the same function:

?TRY begin
    Y = X,
    Y = 1,
    ?TRY
        throw(hello)
    ?WITH
        hola -> {catched, hello}
    ?END_TRY
end
?WITH
    {'EXIT', R} -> {catched, R}
?END_TRY.

I get "variable 'Finally' unsafe in 'catch'" error (The Finally variable 
is used in two pattern matching).

So, I need a fresh variable name.

I've tryed this hack:

-define(END_TRY, ; Finally?LINE -> Finally?LINE end).

but ?LINE expands to " 25" (it adds a space).

--
Thank you
Greets





More information about the erlang-questions mailing list