4 ms·
Hm, 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).
by e12e 12y ago
Hm, 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).