In the Dave Thomas book there's an example of defining a map-function:
(extracted:)
def map([], _func), do: []
def map([ head | tail ], func), do: [ func.(head) | map(tail, func) ]
Look at these runs: Why do the runs marked 'NB' produce so strange results?
(Erlang 18.1, Elixir 1,1)
iex(9)> MyList.map [5,6,7,8], &(&1*&1)
[25, 36, 49, 64]
iex(10)> MyList.map [5,6,7,8], &(&1*&1)
[25, 36, 49, 64]
iex(11)> MyList.map [6,7,8], &(&1*&1) NB
'$1@'
iex(12)> MyList.map [7,8,9], &(&1*&1) NB
'1@Q'
iex(13)> MyList.map [17,18,19], &(&1*&1)
[289, 324, 361]
iex(14)> MyList.map [8,9,10], &(&1*&1) NB
'@Qd'
iex(15)> MyList.map [9,10,11], &(&1*&1) NB
'Qdy'
iex(16)> MyList.map [9,10,12], &(&1*&1)
[81, 100, 144]
iex(25)> MyList.map [6,7,8,12], &(&1*&1)
[36, 49, 64, 144]
Grateful for suggestions!