From a929df291877df45c93303d22995bbbebf6a2c45 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 12 Nov 2012 10:07:37 +0100 Subject: Document named fun expressions --- erts/doc/src/absform.xml | 12 ++++++++++++ system/doc/reference_manual/expressions.xml | 23 ++++++++++++++--------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/erts/doc/src/absform.xml b/erts/doc/src/absform.xml index 55aef9f8ab..4acc03b133 100644 --- a/erts/doc/src/absform.xml +++ b/erts/doc/src/absform.xml @@ -290,6 +290,18 @@ If E is where each is a function clause then Rep(E) = . + If E is + where is a variable and each + is a function clause then Rep(E) = + . + + If E is , + where each is a generator or a filter, then + Rep(E) = . + For Rep(W), see below. + If E is , a Mnesia record access + inside a query, then + Rep(E) = . If E is , then Rep(E) = , i.e., parenthesized expressions cannot be distinguished from their bodies. diff --git a/system/doc/reference_manual/expressions.xml b/system/doc/reference_manual/expressions.xml index 0dc6bfe576..e9de3e006e 100644 --- a/system/doc/reference_manual/expressions.xml +++ b/system/doc/reference_manual/expressions.xml @@ -954,19 +954,20 @@ Ei = Value | Fun Expressions
 fun
-    (Pattern11,...,Pattern1N) [when GuardSeq1] ->
-        Body1;
+    [Name](Pattern11,...,Pattern1N) [when GuardSeq1] ->
+              Body1;
     ...;
-    (PatternK1,...,PatternKN) [when GuardSeqK] ->
-        BodyK
+    [Name](PatternK1,...,PatternKN) [when GuardSeqK] ->
+              BodyK
 end

A fun expression begins with the keyword fun and ends with the keyword end. Between them should be a function declaration, similar to a - regular function declaration, except that no function name is - specified.

-

Variables in a fun head shadow variables in the - function clause surrounding the fun expression, and + regular function declaration, + except that the function name is optional and should be a variable if + any.

+

Variables in a fun head shadow the function name and both shadow + variables in the function clause surrounding the fun expression, and variables bound in a fun body are local to the fun body.

The return value of the expression is the resulting fun.

Examples:

@@ -978,7 +979,11 @@ end 3> Fun2 = fun (X) when X>=5 -> gt; (X) -> lt end. #Fun<erl_eval.6.39074546> 4> Fun2(7). -gt +gt +5> Fun3 = fun Fact(1) -> 1; Fact(X) when X > 1 -> X * Fact(X - 1) end. +#Fun<erl_eval.6.39074546> +6> Fun3(4). +24

The following fun expressions are also allowed:

 fun Name/Arity
-- 
cgit v1.2.3