I’m reading the Programming Elixir 1.2 book, and I’m at the chapter where we use head and tail to build lists. The example code given is:
defmodule MyList do
def square([]), do: []
def square([ head | tail ]), do: [ head*head | square(tail) ]
def add_1([]), do: []
def add_1([ head | tail ]), do: [ head+1 | add_1(tail) ]
end
When I run:
MyList.add_1([1000]) it returns 1001
however if I do:
MyList.add_1([10])
> '\v'
MyList.add_1 [100]
> 'e'
does anybody know why this is happening? If I try it with the number given in the example it works out.