Monday, December 15, 2014

7L7W Week 2: Io Day X>Digging in

Feeling almost human again after my weekend. Serious 2 week prep & 4 hour imp software updates suck. Moving right along.

Let me try to break this down.

Io> test := method(stuff, stuff println)
==> method(stuff,
    stuff println
)
Io> test("Hello World")
Hello World
==> Hello World
Io> 

Interesting things are happening here. First I'm creating a slot in the Lobby...
Io> Lobby slotSummary
==>  Object_0x5bc8c0:
  Lobby            = Object_0x5bc8c0
  Protos           = Object_0x5bc860
  _                = "Hello World"
  exit             = method(...)
  forward          = method(...)
  set_             = method(...)
  test             = method(stuff, ...)

Io>

called test. But... I'm already ahead of myself. >.<

The method() block is sent as a message to the := assignment operator which becomes setSlot("test", method ... ) via a macro creating a slot in the Lobby and loads the method message into it. setSlot()sends the method block as a message, I think, and so the Lobby outputs the method with ==>.

In the next line I craft a message test and give it the string "Hello World" as an argument. This message is sent to the Lobby, where everything eventually lands I guess? It's the default evaluation context when there's no other object to catch the message. The Lobby responds to the test message with its test slot.

The Lobby's test slot is a method block that sends the println message to the first message argument (any additional arguments are ignored and generate no errors that I can see, coder beware). So a println message is sent to my "Hello World" object causing it to print to output. The "Hello World" message also gets sent on to the Lobby which outputs it with ==>.

That's a lot to follow in two lines of code. Time to take another hack at day 2.
Point of interest: the Lobby slot _ seems to contain whatever message was last output by Lobby via ==>. I could stand to learn the terminology for that. But I wonder how long it would take to crash the runtime by repeatedly sending Lobby slotSummary >.>

No comments: