From fa04f8212d282ea1535c07683660de1a23565b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 10 Jan 2017 14:44:00 +0100 Subject: Modernize section about list handling and list comprehensions --- system/doc/efficiency_guide/listhandling.xml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'system/doc/efficiency_guide') 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) ->

Lists comprehensions still have a reputation for being slow. They used to be implemented using funs, which used to be slow.

-

In recent Erlang/OTP releases (including R12B), a list comprehension:

+

A list comprehension:

@@ -102,7 +102,7 @@ tail_recursive_fib(N, Current, Next, Fibs) -> [Expr(E)|'lc^0'(Tail, Expr)]; 'lc^0'([], _Expr) -> []. -

In R12B, if the result of the list comprehension will obviously +

If the result of the list comprehension will obviously not be used, a list will not be constructed. For example, in this code:

[]. +

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:

+ + +
@@ -209,11 +217,11 @@ some_function(...),
Recursive List Functions -

In Section 7.2, the following myth was exposed: +

In section about myths, the following myth was exposed: Tail-Recursive Functions are Much Faster Than Recursive Functions.

-

To summarize, in R12B there is usually not much difference between +

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 -- cgit v1.2.3