aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/examples/erl_id_trans.erl
diff options
context:
space:
mode:
authorAnthony Ramine <[email protected]>2012-11-10 17:06:01 +0100
committerAnthony Ramine <[email protected]>2013-12-12 10:46:08 +0100
commitacbca8379bdde12612e27f3313a5c73f4db25381 (patch)
tree536f5f2d71f4ef1339b03472048e1b932d7064c5 /lib/stdlib/examples/erl_id_trans.erl
parent6c5c39827cc06a9e9b3e3fa4fa856f4610eb40b6 (diff)
downloadotp-acbca8379bdde12612e27f3313a5c73f4db25381.tar.gz
otp-acbca8379bdde12612e27f3313a5c73f4db25381.tar.bz2
otp-acbca8379bdde12612e27f3313a5c73f4db25381.zip
EEP 37: Funs with names
This adds optional names to fun expressions. A named fun expression is parsed as a tuple `{named_fun,Loc,Name,Clauses}` in erl_parse. If a fun expression has a name, it must be present and be the same in every of its clauses. The function name shadows the environment of the expression shadowing the environment and it is shadowed by the environment of the clauses' arguments. An unused function name triggers a warning unless it is prefixed by _, just as every variable. Variable _ is allowed as a function name. It is not an error to put a named function in a record field default value. When transforming to Core Erlang, the named fun Fun is changed into the following expression: letrec 'Fun'/Arity = fun (Args) -> let <Fun> = 'Fun'/Arity in Case in 'Fun'/Arity where Args is the list of arguments of 'Fun'/Arity and Case the Core Erlang expression corresponding to the clauses of Fun. This transformation allows us to entirely skip any k_var to k_local transformation in the fun's clauses bodies.
Diffstat (limited to 'lib/stdlib/examples/erl_id_trans.erl')
-rw-r--r--lib/stdlib/examples/erl_id_trans.erl2
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/stdlib/examples/erl_id_trans.erl b/lib/stdlib/examples/erl_id_trans.erl
index 51def8c8e1..2c842fafc7 100644
--- a/lib/stdlib/examples/erl_id_trans.erl
+++ b/lib/stdlib/examples/erl_id_trans.erl
@@ -419,6 +419,8 @@ expr({'fun',Line,Body}) ->
A = expr(A0),
{'fun',Line,{function,M,F,A}}
end;
+expr({named_fun,Loc,Name,Cs}) ->
+ {named_fun,Loc,Name,fun_clauses(Cs)};
expr({call,Line,F0,As0}) ->
%% N.B. If F an atom then call to local function or BIF, if F a
%% remote structure (see below) then call to other module,