Io and The Princess Bride

I’ve been working my way through Seven Languages in Seven Weeks and loving it so far. This evening, on the train, I got a little stuck on one of the examples…

This was Io (IoLanguage for Googlers) Day 2, and an example of reflection and delayed evaluation. Perhaps cleverly, Mr. Tate does not give the full source of his example, leaving the reader to figure out the rest. He first provides the following snippet to create an unless method:

unless := method(
	(call sender doMessage(call message argAt(0))) ifFalse(
	 call sender doMessage(call message argAt(1))) ifTrue(
	 call sender doMessage(call message argAt(2))) 

Then, he simply says, “Say the object westley sends the message

princessButtercup unless(trueLove, ("It is false" println), ("It is true" println))

This had me stumped for a while but after battling a little, and going back and reading the chapter again (and again), I came up with the following working code:

westley := Object clone
westley trueLove := true
westley princessButtercup := method( unless(trueLove, "You lie!" println, "True love!" println))
westley princessButtercup

I think that’s what Bruce meant; either way, it certainly helped me understand the flow of the unless method. I would love to know the thoughts of any iolanguage devs / people who have worked through the book.