03 Dec 2013, 08:25
Generic-user-small

Ved Antani (2 posts)

Page 21 section 3.3 says “But Elixir knows that list1 will never change, so it simply constructs a new list with a head of 4 and a tail of list1” But Elixir lets list1 hold other values.

iex(9)> list1 = [1,2,3]
[1, 2, 3]
iex(10)> list1 = [3,4,5]
[3, 4, 5]
--------------------------->list1 changed
iex(11)> list1
[3, 4, 5]
iex(12)> list2 = [5 | list1]
[5, 3, 4, 5]
iex(13)> list1 = [6,7,8]
---------------------------> list1 changed
[6, 7, 8]
iex(14)> list2
[5, 3, 4, 5]
iex(16)> list1
[6, 7, 8]
12 Dec 2013, 16:44
Dave_gnome_head_isolated_pragsmall

Dave Thomas (337 posts)

There are two things here. Variables and values.

The list itself never changes. But the variable can reference other values. THe data itself is immutable.

  You must be logged in to comment