aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Ramine <[email protected]>2012-11-12 10:07:37 +0100
committerAnthony Ramine <[email protected]>2013-12-12 12:54:24 +0100
commita929df291877df45c93303d22995bbbebf6a2c45 (patch)
tree036a9ee74bc9f1f30f9378795e8b235b462b8212
parenta0988a638a92211ae0af6ec35ca99edfc05110aa (diff)
downloadotp-a929df291877df45c93303d22995bbbebf6a2c45.tar.gz
otp-a929df291877df45c93303d22995bbbebf6a2c45.tar.bz2
otp-a929df291877df45c93303d22995bbbebf6a2c45.zip
Document named fun expressions
-rw-r--r--erts/doc/src/absform.xml12
-rw-r--r--system/doc/reference_manual/expressions.xml23
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 @@
<item>If E is <c><![CDATA[fun Fc_1 ; ... ; Fc_k end]]></c>
where each <c><![CDATA[Fc_i]]></c> is a function clause then Rep(E) =
<c><![CDATA[{'fun',LINE,{clauses,[Rep(Fc_1), ..., Rep(Fc_k)]}}]]></c>.</item>
+ <item>If E is <c><![CDATA[fun Name Fc_1 ; ... ; Name Fc_k end]]></c>
+ where <c><![CDATA[Name]]></c> is a variable and each
+ <c><![CDATA[Fc_i]]></c> is a function clause then Rep(E) =
+ <c><![CDATA[{named_fun,LINE,Name,[Rep(Fc_1), ..., Rep(Fc_k)]}]]></c>.
+ </item>
+ <item>If E is <c><![CDATA[query [E_0 || W_1, ..., W_k] end]]></c>,
+ where each <c><![CDATA[W_i]]></c> is a generator or a filter, then
+ Rep(E) = <c><![CDATA[{'query',LINE,{lc,LINE,Rep(E_0),[Rep(W_1), ..., Rep(W_k)]}}]]></c>.
+ For Rep(W), see below.</item>
+ <item>If E is <c><![CDATA[E_0.Field]]></c>, a Mnesia record access
+ inside a query, then
+ Rep(E) = <c><![CDATA[{record_field,LINE,Rep(E_0),Rep(Field)}]]></c>.</item>
<item>If E is <c><![CDATA[( E_0 )]]></c>, then
Rep(E) = <c><![CDATA[Rep(E_0)]]></c>,
i.e., parenthesized expressions cannot be distinguished from their bodies.</item>
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 |
<title>Fun Expressions</title>
<pre>
fun
- (Pattern11,...,Pattern1N) [when GuardSeq1] ->
- Body1;
+ [Name](Pattern11,...,Pattern1N) [when GuardSeq1] ->
+ Body1;
...;
- (PatternK1,...,PatternKN) [when GuardSeqK] ->
- BodyK
+ [Name](PatternK1,...,PatternKN) [when GuardSeqK] ->
+ BodyK
end</pre>
<p>A fun expression begins with the keyword <c>fun</c> and ends
with the keyword <c>end</c>. Between them should be a function
declaration, similar to a
- <seealso marker="functions#syntax">regular function declaration</seealso>, except that no function name is
- specified.</p>
- <p>Variables in a fun head shadow variables in the
- function clause surrounding the fun expression, and
+ <seealso marker="functions#syntax">regular function declaration</seealso>,
+ except that the function name is optional and should be a variable if
+ any.</p>
+ <p>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.</p>
<p>The return value of the expression is the resulting fun.</p>
<p>Examples:</p>
@@ -978,7 +979,11 @@ end</pre>
3> <input>Fun2 = fun (X) when X>=5 -> gt; (X) -> lt end.</input>
#Fun&lt;erl_eval.6.39074546&gt;
4> <input>Fun2(7).</input>
-gt</pre>
+gt
+5> <input>Fun3 = fun Fact(1) -> 1; Fact(X) when X > 1 -> X * Fact(X - 1) end.</input>
+#Fun&lt;erl_eval.6.39074546&gt;
+6> <input>Fun3(4).</input>
+24</pre>
<p>The following fun expressions are also allowed:</p>
<pre>
fun Name/Arity