diff options
author | Björn Gustavsson <[email protected]> | 2017-01-10 14:44:00 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2017-01-10 14:46:05 +0100 |
commit | fa04f8212d282ea1535c07683660de1a23565b0f (patch) | |
tree | 4366ec01e34fdbd3587c2e21320b83e4ffa57a18 /system | |
parent | 953f57e3a86f3b714a634177e32f630b56a05240 (diff) | |
download | otp-fa04f8212d282ea1535c07683660de1a23565b0f.tar.gz otp-fa04f8212d282ea1535c07683660de1a23565b0f.tar.bz2 otp-fa04f8212d282ea1535c07683660de1a23565b0f.zip |
Modernize section about list handling and list comprehensions
Diffstat (limited to 'system')
-rw-r--r-- | system/doc/efficiency_guide/listhandling.xml | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/system/doc/efficiency_guide/listhandling.xml b/system/doc/efficiency_guide/listhandling.xml index 2ebc877820..ec258d7c2a 100644 --- a/system/doc/efficiency_guide/listhandling.xml +++ b/system/doc/efficiency_guide/listhandling.xml @@ -90,7 +90,7 @@ tail_recursive_fib(N, Current, Next, Fibs) -> <p>Lists comprehensions still have a reputation for being slow. They used to be implemented using funs, which used to be slow.</p> - <p>In recent Erlang/OTP releases (including R12B), a list comprehension:</p> + <p>A list comprehension:</p> <code type="erl"><![CDATA[ [Expr(E) || E <- List]]]></code> @@ -102,7 +102,7 @@ tail_recursive_fib(N, Current, Next, Fibs) -> [Expr(E)|'lc^0'(Tail, Expr)]; 'lc^0'([], _Expr) -> [].</code> - <p>In R12B, if the result of the list comprehension will <em>obviously</em> + <p>If the result of the list comprehension will <em>obviously</em> not be used, a list will not be constructed. For example, in this code:</p> <code type="erl"><![CDATA[ @@ -131,6 +131,14 @@ some_function(...), 'lc^0'(Tail, Expr); 'lc^0'([], _Expr) -> [].</code> + <p>The compiler also understands that assigning to '_' means that + the value will not used. Therefore, the code in the following example + will also be optimized:</p> + + <code type="erl"><![CDATA[ +_ = [io:put_chars(E) || E <- List], +ok.]]></code> + </section> <section> @@ -209,11 +217,11 @@ some_function(...), <section> <title>Recursive List Functions</title> - <p>In Section 7.2, the following myth was exposed: + <p>In section about myths, the following myth was exposed: <seealso marker="myths#tail_recursive">Tail-Recursive Functions are Much Faster Than Recursive Functions</seealso>.</p> - <p>To summarize, in R12B there is usually not much difference between + <p>There is usually not much difference between a body-recursive list function and tail-recursive function that reverses the list at the end. Therefore, concentrate on writing beautiful code and forget about the performance of your list functions. In the |