[erlang-patches] EEP37: Funs with names

Anthony Ramine n.oxyde@REDACTED
Wed Nov 14 17:42:07 CET 2012

This patch implements EEP37: 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

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.


	git fetch https://github.com/nox/otp eep37


Anthony Ramine

More information about the erlang-patches mailing list