Manuel Albarran

A random notes about Elixir

Nodes

12 Feb 2017 » elixir

One terminal

$ iex --sname a  --cookie monster
alias :global, as: Global
yc = fn f -> (fn z -> z.(z) end).(fn y -> f.(fn arg -> y.(y).(arg) end) end) end
loop = fn f -> fn -> yc.(fn l -> fn d -> d.(); l.(d) end end).(f) end end
catch_all = fn f -> spawn(loop.(fn -> receive do msg -> f.(msg) end end)) end

defmodule A, do: def p(arg), do: IO.inspect [self, arg]
Global.register_name(:server, catch_all.(fn msg -> IO.puts "Received! #{inspect msg}" end))

Another terminal

$ iex --sname b --cookie monster
{:ok, hostname } = :inet.gethostname

Node.spawn_link :"a@#{hostname}", A, :p, [:a]

Node.connect(:"a@#{hostname}")
:global.whereis_name(:server) |> send("hello from node 2!"); nil