[ANN] etran: added support of default function arguments
Serge Aleynikov
serge@REDACTED
Tue Aug 31 21:13:51 CEST 2021
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20210831/5d9bdc5f/attachment.htm>
More information about the erlang-questions
mailing list