September 2013
Intermediate to advanced
548 pages
12h 25m
English
The most efficient way to build a list is to add the elements to the head of an existing list, so we often see code with this kind of pattern:
| | some_function([H|T], ..., Result, ...) -> |
| | H1 = ... H ..., |
| | some_function(T, ..., [H1|Result], ...); |
| | some_function([], ..., Result, ...) -> |
| | {..., Result, ...}. |
This code walks down a list extracting the head of the list
H and computes some value based on this function (we can
call this H1); it then adds H1 to the output list
Result. When the input list is exhausted, the final clause matches, and the
output variable Result is returned from the function.
The elements in Result are in the opposite order as the elements in the original list, which may or may not be ...
Read now
Unlock full access