4 ms·
To bring it back to a normal Erlang analogy level, the rooms are instances of Erlang VMs. Since Erlang has isolated memory between processes, the only way to as
by e_proxus 12y ago
To bring it back to a normal Erlang analogy level, the rooms are instances of Erlang VMs. Since Erlang has isolated memory between processes, the only way to ask one process in one virtual machine (reaching it either by its registered name or if you know the pid somehow) for data (i.e. values of variables) is to send messages to it. You can't access variables/data across VMs/processes directly, you have to talk to them.
Regarding Erlang on Wheezy, I'd recommend the Erlang Solutions repository with pre-built and tested packages: https://www.erlang-solutions.com/downloads/download-erlang-otp https://www.erlang-solutions.com/downloads/download-erlang-o...
- e12e 12y agoI suppose I want the example to show how, when I push data through the portal, it appears on the other side. I'm guessing the idomatic way has to do something with registering a function to be called on message/data received on the "other" end. It just feel like the article could/should be extended a bit there, to make it "full circle" so to speak. What's already there is good, but it leaves me hungry for more, and a little lost as to how to achieve more. Thanks for the tip on upstream packages for Debian -- I somehow missed the fact that there was a repo for Debian (well, that, and I already had wheezy-backports enabled, and it turned out to work fine with Elixir from source).
- alco 12y agoI don't understand what you are asking here. The example at the beginning of the "Distribution" section shows how to get the value from the door in room1 while running on the node corresponding to room2. The same way you can call 'Portal.Door.get({:orange, :"room2@COMPUTER-NAME"})' on the first node (the one corresponding to room1).
- e12e 12y agoHm, I believe that is what I was asking :) I'll have to look when I'm back at my computer with the example code (and and more importantly an elixir install).
- e12e 12y agoOk, now I see a little more of how things are connected. In my opinion, it would've been nice to be a) more explicit about the naming/aliasing of blue/orange in the final section, and b) Show how to actually read data sent from room2 in room1, eg: # Start session for room1, shoot orange portal in room1 $ iex --sname room1 --cookie secrit -S mix iex(room1@COMPUTER-NAME)1> Portal.shoot(:blue) {:ok, #PID<0.67.0>} # Start session for room2, shoot orange portal in room2 $ iex --sname room2 --cookie secret -S mix iex(room2@COMPUTER-NAME)1> Portal.shoot(:orange) # set up aliases/variables for blue/orange in room2 iex(room2@COMPUTER-NAME)1> blue = {:blue, :"room1@COMPUTER-NAME"} {:blue, :room1@COMPUTER-NAME} {:ok, #PID<0.68.0>} iex(room2@COMPUTER-NAME)3> orange = {:orange, :"room2@COMPUTER-NAME"} {:orange, :room2@COMPUTER-NAME} # Use aliases to set up portal transfer in room2 iex(room2@COMPUTER-NAME)4> portal = Portal.transfer(orange, blue, [1,2,3,4]) #Portal< {:orange, :room2@COMPUTER-NAME} <=> {:blue, :room1@COMPUTER-NAME} [1, 2, 3, 4] <=> [] iex(room2@COMPUTER-NAME)5> Portal.push_right(portal) #Portal< {:orange, :room2@COMPUTER-NAME} <=> {:blue, :room1@COMPUTER-NAME} [1, 2, 3] <=> [4] # set up aliases/variables for blue/orange in room1 (saves typing!) iex(room1@COMPUTER-NAME)2> orange = {:orange, :"room2@COMPUTER-NAME"} {:orange, :room2@COMPUTER-NAME} iex(room1@COMPUTER-NAME)3> blue = {:blue, :"room1@COMPUTER-NAME"} {:blue, :room1@COMPUTER-NAME} # Anything in the door? iex(room1@COMPUTER-NAME)4> Portal.Door.get(orange) [4, 3, 2, 1] iex(room1@COMPUTER-NAME)5> Portal.Door.get(blue) [] #Switch to room2, push a value: iex(room1@COMPUTER-NAME)6> Portal.Door.get(blue) [4] iex(room1@COMPUTER-NAME)7> Portal.Door.get(orange) [3, 2, 1] # Verify that we're communicating, in room1: iex(room1@kuromaki)6> Portal.Door.get(blue) [4] iex(room1@kuromaki)7> Portal.Door.get(orange) [3, 2, 1] I'm still not entirely clear on if it's possible to access the "portal" from both rooms [edit: to call push_right from room1 on the portal instantiated in the session in room2] -- could I get at it from room1 by qualifying it with room2@COMPUTER-NAME? If so what would the implications be? I assume functions are called via message passing, so this would be safe? I think a lot of the stuff up to the very last bit is good, I just feel the article stops a little short. Maybe I just need to read it again (and play more with elixir).
- e_proxus 12y agoThere really isn't anything more to it than in Pid1 doing Pid2 ! MyMessage (that is the literal syntax in Erlang). The rest is taken care of by the Erlang VM. How do you figure out Pid2 (on :room2) from Pid1 (on :room1) then? Either substitute it for Pid2Name, which could be :orange for example, or call and RPC function to room2, MySystem.give_me_a_pid() for example.