Introducing Elixir by Simon St. Laurent

Introducing Elixir by Simon St. Laurent

Author:Simon St. Laurent
Language: eng
Format: epub
ISBN: 9781449369996
Publisher: O'Reilly Media
Published: 2014-08-15T00:00:00+00:00


iex(24)> divide = fn(value, accumulator) -> value / accumulator end #Function<12.106461118/2 in :erl_eval.expr/5> iex(25)> 1/2/4/8/16/32 3.0517578125e-5 iex(26)> List.foldl(list, 1, divide) 8.0 iex(24)> 32/16/8/4/2/1 0.03125 iex(25)> List.foldr(list, 1, divide) 0.125

This code seems too simple to have a bug, so what’s going on? Table 8-1 walks through the calculations for List.foldl(list, 1, divide), and Table 8-2 walks through List.foldr(list, 1, divide) step by step.

Table 8-1. Recursive division of a list forward with List.foldl/3

Value from list Accumulator Result of division

1

1

1



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.