Rebind transform in Erlang 21 and Hygienic macro

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Rebind transform in Erlang 21 and Hygienic macro

Xavier Wang
Hi,

I use the rebind[1] transform for create Hygienic macro.

such as:

-define(CASE(Expr, A, B),
        try Expr of
          {ok, rebind(Result)} -> A;
          {error, rebind(Err)} -> B
        catch
          throw: {ok, rebind(Result)} -> A;
                 {error, rebind(Err)} -> B
        end).

then I can use ?CASE in A or B, each time macro expanded, the Result and Err will have a new name such as _Result_REBIND_1_, etc.

But this can not work on Erlang 21, because function call are not allowed in pattern with the new AST.  How can I get over it? Or are there any other way to implement the hygienic macro?

--
regards,
Xavier Wang.

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Rebind transform in Erlang 21 and Hygienic macro

Dmitry Kolesnikov-2
Hello,

rebind macro looks like identity composition. You’ve trying to build either composition with that macro.

I am maintaining this and few other composition under category transform. Please check them out if they solve your problems.

Shoot a questions/raise an issue if something is not clear. 

Best Regards, 
Dmitry

On 28 Nov 2018, at 10.48, Xavier Wang <[hidden email]> wrote:

Hi,

I use the rebind[1] transform for create Hygienic macro.

such as:

-define(CASE(Expr, A, B),
        try Expr of
          {ok, rebind(Result)} -> A;
          {error, rebind(Err)} -> B
        catch
          throw: {ok, rebind(Result)} -> A;
                 {error, rebind(Err)} -> B
        end).

then I can use ?CASE in A or B, each time macro expanded, the Result and Err will have a new name such as _Result_REBIND_1_, etc.

But this can not work on Erlang 21, because function call are not allowed in pattern with the new AST.  How can I get over it? Or are there any other way to implement the hygienic macro?

--
regards,
Xavier Wang.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions