[erlang-patches] EEP37: Funs with names

Anthony Ramine <>
Thu Nov 15 13:04:59 CET 2012


Sorry for the double post, I thought it was erlang-eeps@ and not 

Le 14 nov. 2012 à 17:42, Anthony Ramine a écrit :

> 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
> 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.
> 
> 	https://github.com/nox/otp/compare/erlang:master...eep37
> 	https://github.com/nox/otp/compare/erlang:master...eep37.patch
> 
> 	git fetch https://github.com/nox/otp eep37
> 
> Regards,
> 
> -- 
> Anthony Ramine
> 



More information about the erlang-patches mailing list