Fresh variable names in Erlang
Torbjorn Tornkvist
tobbe@REDACTED
Fri Aug 27 15:31:31 CEST 2004
Check out the xxx-macros package at the User Contrib area.
It might still work...
Cheers, Tobbe
Hector Rivas Gandara wrote:
> 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