15 Jul 2013, 03:42
Dave_gnome_head_isolated_pragsmall

Dave Thomas (338 posts)

  • Go into iex. Create and run the functions that do the following
    • list_concat.([1,2,3], [4,5,6]) #=> [1,2,3,4,5,6]
    • sum.(1, 2, 3) #=> 6
    • pair_tuple_to_list.( { 8, 7 } ) #=> [ 8, 7 ]
A Possible Solution
iex(1)> list_concat = fn a, b -> a ++ b end
#Function<erl_eval.12.17052888>
iex(2)> list_concat.([1,2,3], [4,5,6])
[1, 2, 3, 4, 5, 6]

iex(3)> sum = fn a, b, c -> a + b + c end
#Function<erl_eval.18.17052888>
iex(4)> sum.(1,2,3)
6

iex(5)> pair_tuple_to_list = fn {a, b} -> [ a, b ] end
#Function<erl_eval.6.17052888>
iex(6)> pair_tuple_to_list.({ 8, 7 })
[8, 7]
29 May 2014, 18:30
Me_pragsmall

Paul Barry (3 posts)

Strange things happening to me for that last one. On my machine, here’s what I see:

Erlang/OTP 17 [erts-6.0] [source] [64-bit] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (0.13.3) - press Ctrl+C to exit (type h() ENTER for help)

iex(1)> pair_tuple_to_list = fn {a, b} -> [ a, b ] end
#Function<6.106461118/1 in :erl_eval.expr/5>

iex(2)> pair_tuple_to_list.({ 8, 7 })
'\b\a'

iex(5)> pair_tuple_to_list.({ 4, 5 })
[4, 5]

I’m not sure why this (with {8, 7} as input to the function) is happening. As you can see, it works for {4, 5}. In fact, any time I use 7 through 13 as the first number, it does not return a list. Weird.

30 May 2014, 13:31
Cnv000015_pragsmall

Fred George (1 post)

I had the same strange result as Paul Barry. '\b\a' was returned for {8, 7}. Works for {8, 3} and {3, 7}. Fails for {8, 8}, {7, 7}, and {7, 8} with predictable letters returned.

03 Jun 2014, 14:34
28aa4bd_pragsmall

José Valim (28 posts)

Hello Paul and Fred!

It is not a bug. Elixir actually shows a list of integers as a char list if the list of integers contains printable characters up to 128. For example, if I write:

iex> [106, 111, 115, 101]
'jose'

See how the list ended up being printed as list of characters?

The reason we have this behaviour is because char lists are still used a lot in Erlang and error messages may be returned as char lists and you may stable against those from time to time and it is better to see them as a char list than a bunch of integers. If you want, however, you can disable this behaviour (on the very latest Elixir) with the following:

iex> IEx.configure [inspect: [char_lists: false]]

I hope you are having fun!

11 Jun 2014, 04:11
Generic-user-small

Miguel Diaz (1 post)

Thanks for the reply José( and explanation ) I was scratching my head wondering what was going on .

  You must be logged in to comment