Thursday, December 11, 2014

7L7W Week 2(early): Io Day 1>Scrumptious

Now this, this is something that looks exciting on day1. Yes, it's actually even easier to blow your foot off with a single line of code than in Ruby (Object clone := "hosed" indeed!) but for that only slighter greater power you get an incredibly flexible language. The syntax is extremely small and there seems to be only a very limited number of concepts to grok. No doubt the libraries are an even bigger elephant to devour than in most languages, or at any rate an even higher priority, simply because Io doesn't seem to have much in the way of plumbing available in the base language (file handling? don't see it yet) Even so... I think I'll spend some time with this one and see how it fits. Probably after this 7 weeks course is done in... oh at this rate about 3 weeks.

Enough prologue. Io is ridiculously tricky to search for on Google so I'm dropping links to my 'Find' results.

  • Examples: 
  • Community: There's an official mailing list, twitter, and IRC channel. No idea how active they are. Otherwise, Stack Overflow is all I could find.
  • Style guide: This wikibooks entry looks decent. No idea if there's anything more canonical. I'm not terribly perturbed about style right at the moment though. If I stay in Io long enough to have to find more resources I expect I'll find style canon alongside those searches.
Amusingly, many of my searches related to Io have turned up blogs of people, like me, working and blogging their way through this book. I find that quite amusing, though it highlights an apparent lack of external resources.

Anyway. On with the show. 'Answers'
  • 1+1 runs, 1+"one" does not. 1 is a Number type and "one" is a Sequence type. Sequences don't respond to the + operator. On the other hand, an object can be assigned to any other object at will and according to the Io programming guide even inheritance can be changed at runtime. Which, it seems, would make Io very weakly typed.
  • Everything is true. The cake is always honest. Unless cake := false clone or cake := nil clone. For proofs:
    • true and 0
      • ==> true
    • true and ""
      • ==> true
    • true and nil
      • ==> false
    • true and false
      • ==> false
  • <Object> slotNames or perhaps <Object> proto slotNames. You can also send the slotSummary message to an object if you also want to know what's in each slot.
  • = is assignment to a slot. := creates and assigns a slot (no unassigned variables, ever?) ::= creates and assigns a slot and defines an accessor method set<slotname>() in the object where <slotname> is the name of the slot with an upshifted first letter (existing catpitals are unchanged, only the first letter is upshifted).

So. Do:
  • doFile("filename") filesystem context is where the Io binary is executed from, rather than where it resides. This can also be sent like any other message to an object.
  • Execute the code in a slot given its name... I interpret that as 'how do you eval() a string'. Which is as so:
Bond := Object clone
Bond martini ::= nil
Bond orderMartini := "setMartini(\"shaken, not stirred\")"
Bond slotSummary
Bond doString(Bond orderMartini)
Of course he might just have meant Bond setMartini("shaken, not stirred") or in words, send the slot name as a message to the object in order to execute the code in the slot. In fact, that's probably the simple answer that was being looked for. I tend to overcomplicate >.>

So far so good. I'm quite a bit more excited by Io than Ruby on D1.

No comments: