Coding Note on Elixir

In Assignment 7 you are to implement in Elixir the chain of message passing processes that you did in Erlang. There is an issue of how Elixir uses what is typed at the keybpard compared to how Erlang does things. I did not intend this to be a time consuming issue, but I suspect it is becomming one. So here is some info that should help.

There is one important difference in the Erlang shell vs. the Elixir shell. In the Erlang shell, your input (which is technically text, strings from the keyboard) is interpreted as Erlang terms. Thus when your Erlang code asks for an input message, and you type "{add, 3, 7}" Erlang gets that as an actual data structure, a tuple in this case and can pass your input directly as a tuple message.

Elixir does not do that. If you type input like "{:add,3,7}" at the keyboard then your Elixir code gets a string. Our code is looking for mailbox messages that are tuples, list, etc. So we must convert the text input into the data structures.

We can do this with the Elixir Code module, which has various ways to parse string data into valid Elixir terms (including data structures like tuples and lists). Here is a session in the iex shell showing this:

iex(20)>
nil
iex(21)> Code.eval_string("{:add,3,7}")
{{:add, 3, 7}, []}
iex(22)> elem(Code.eval_string("{:add,3,7}"), 0)
{:add, 3, 7}
iex(23)>
nil
iex(24)> Code.eval_string("[11,-5,:goheels, 23.4, 6]")
{[11, -5, :goheels, 23.4, 6], []}
iex(25)> elem(Code.eval_string("[11,-5,:goheels, 23.4, 6]"), 0)
[11, -5, :goheels, 23.4, 6]
iex(26)> is_tuple( elem(Code.eval_string("{:add,3,7}"), 0))
true
iex(27)> t =  elem(Code.eval_string("{:add,3,7}"), 0)
{:add, 3, 7}
iex(28)> t
{:add, 3, 7}
iex(29)> is_tuple(t)
true
iex(30)>

Feel free to use this. Also feel free to use ChatGPT to help for this input transforming (although it may not help much more than this).