Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elixir, no circular reference possible?

I am learning Elixir, up to chapter 7 PragProg book, and after thinking about the immutability and other items, I was thinking it was not generally possible to create a circular reference in the Elixir Maps/Tuples/Lists, etc.. Where A -> B -> C -> A.

Without going into really trying to trick the system, is this true?

like image 623
Daniel Avatar asked Dec 13 '16 06:12

Daniel


1 Answers

Due to the immutability, there is a chicken-egg problem creating circulars. In fact, there is nothing done by Elixir to prevent it; it just comes out of the box within the immutability.

Proof: Since C in your chain links A on creation, A must exist in advance; A in turn links B hence B must exist even before; B links C, requiring C to exist, but it is not yet created. QED.

One can not simply refer an unexisting Term*, and can not modify the existing one, therefore, it is impossible in Elixir.


* please read the discussion in comments on wording here and why Term was finally chosen.

like image 94
Aleksei Matiushkin Avatar answered Sep 28 '22 11:09

Aleksei Matiushkin