Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why did elixir change the notation for sending a message to a process?

Tags:

elixir

I noticed that in elixir version 0.10.1, you send a message to a process like this

 my_process <- :message, self

But now in elixir 1.0.2, you send a message to a process like this

 Process.send my_process, :message, self

What was the reason for this change?

like image 318
User314159 Avatar asked Feb 11 '23 16:02

User314159


1 Answers

Prior to this change, list comprehensions looked like this:

lc x inlist my_list do
  # ...
end

However, the syntax was strange for newcomers and so the Elixir team set out to find an alternative. The winning syntax was

for x <- my_list do
  # ...
end

Now, the meaning of <- suddenly became dependent on the context. This is not generally a bad thing, but it is often harder to parse and may allow for ambiguities, so they decided to change it.

Another reason to use send instead of <- is to be consistent with the receive syntax. It makes much more sense to let these two have a similar visual appearance than handling them on different syntactic levels.

By the way, your usage of Process.send/3 is wrong. The third parameter must be :noconnect or :nosuspend. Typically you would use the simpler and shorter send (aka Kernel.send) instead.

like image 59
Patrick Oscity Avatar answered Mar 27 '23 06:03

Patrick Oscity