[ANN] etran: added support of default function arguments

Serge Aleynikov <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <CANt451nEbdrrQ9jqg7WSsTN09u5P-vS6CCsva61OAWDNz8XeFQ@mail.gmail.com>
A new version of etran parse transforms has been released.

https://github.com/saleyn/etran

In this version a "defarg" parse transform is added to support default
function arguments.

Example:

test(A / 10, B / 20) ->
  A + B.


The code above is transformed to:

test()    -> test(10);
test(A)   -> test(A, 20);
test(A,B) -> A+B.


More examples taken from unit tests:

defarg_test() ->
 ?assertEqual(3,     a()),
 ?assertEqual(9,     a(7)),
 ?assertEqual(10,    a(6,4)),
 ?assertEqual(7.0,   c()),
 ?assertEqual(9,     d()),
 ?assertEqual(5,     d(abc, [1,2])),
 ok.


a(A / 1, B / 2) ->
 A+B.


c(A / (10*2-15), B / (64 / 32)) ->
 A + B.


d(A / undefined, B / []) ->
 length(atom_to_list(A)) + length(B).


Regards,

Serge
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.