Charlie Harvey

Io — Day One

After getting Io installed, I am feeling a little smug with myself. I don't know if its just because the language is so different, or because I’ve had a beer or what but the Io introductory material seems more complex than that for Ruby. However, looking back at what was covered I suspect that there was actually less material. Io is an extremely minimalist language with a tiny and beautifully consistent syntax. In day one we look at the basics of the syntax -- messages, inheritence, prototypes, slots, methods and the basic collections, lists and maps (read arrays and hashes, roughly). We also get a quick interview with Steve Dekorte, the language's creator.

Evaluate 1+1 and 1+"one". Is Io strongly typed or weakly typed. Suport your answer with code.

Io> 1+1 ==> 2 Io> 1+"one" Exception: argument 0 to method '+' must be a Number, not a 'Sequence' --------- message '+' in 'Command Line' on line 1 Well that looks strongly typed to me! We don't implicitly cast to an integer value. I suppose that something like this may be used instead, depending on what you were trying to achieve. Io> 1+"one" itemSize ==> 2

Is 0 true or false? What about the empty string? Is nil true or false? Support your answer with code.

Zero is true. Io> 0 and true ==> true Io> 0 and false ==> false Io> 0 and 0 ==> true "" is true Io> "" and true ==> true Io> "" and "" ==> true Io> "" and false ==> false nil evaluates to false. Not to neither as I’d previously thought. Props to oldak for putting me straight in the comments. Io> nil and true ==> false Io> nil and nil ==> false Io> nil and false ==> false Io> nil or not nil ==> false

How can you tell what slots a prototype supports?

It seems to me like you would use slotNames. Io> Object slotNames ==> list(newSlot, ownsSlots, isError, foreachSlot, currentCoro, <, removeAllSlots, list, for, doString, uniqueHexId, clone, become, write, evalArgAndReturnNil, serializedSlots, isNil, method, block, pause, isActivatable, deprecatedWarning, isLaunchScript, coroWith, evalArg, uniqueId, ?, actorProcessQueue, do, in, setProto, super, writeln, setSlot, !=, inlineMethod, doRelativeFile, removeAllProtos, coroDo, asyncSend, continue, stopStatus, ancestorWithSlot, print, protos, evalArgAndReturnSelf, actorRun, not, type, and, return, break, slotSummary, >, message, ==, serialized, slotNames, ifNonNilEval, asSimpleString, hasLocalSlot, while, updateSlot, switch, perform, returnIfError, asString, hasSlot, try, returnIfNonNil, hasProto, prependProto, getSlot, wait, justSerialized, hasDirtySlot, thisContext, removeProto, appendProto, println, lazySlot, loop, slotDescriptionMap, launchFile, .., relativeDoFile, serializedSlotsWithNames, compare, , yield, setSlotWithType, init, resend, isTrue, lexicalDo, or, doFile, argIsActivationRecord, raiseIfError, ancestors, isIdenticalTo, ifNil, ifNilEval, performWithArgList, cloneWithoutInit, contextWithSlot, thisLocalContext, >=, if, isKindOf, memorySize, <=, ifNonNil, coroFor, thisMessage, apropos, @, getLocalSlot, ifError, markClean, coroDoLater, slotValues, -, doMessage, proto, setIsActivatable, futureSend, removeSlot, shallowCopy, handleActorException, @@, setProtos, argIsCall)

What is the difference between =, :=, ::= and when should each one be used? When would you use each one?

According to the Io guide's assignment syntax section,
::= Creates slot, creates setter, assigns value
:= Creates slot, assigns value
= Assigns value to slot if it exists, otherwise raises exception

I suppose you'd use ::= if you were creating and setting a slot at the same time and you wanted a setter available for the slot (i.e. same as the newSlot method). := Would be used when you wanted to create a new slot and set it, like the setSlot method. And = would be used to udate an existing slot, like the updateSlot method.

Run an io program from a file.

I nicked the code for this from Io programming begginers guide. $ cat #!/usr/local/bin/io greet := method( writeln ("What is your name?"); you := File standardInput readLine ("> "); writeln ("Hello ", you) ) greet $ ./ What is your name? > dave Hello dave $

Execute the code in a slot given its name.

I wasn't entirely sure what I was doing here. I think it was basically call a method from a named slot. Here was my attempt, anyhow. $ cat #!/usr/local/bin/io runner := Object clone runner run := method ("Running like a fool!" println) runner getSlot("run") call // I /think/ that's what Tate meant. $ ./ Running like a fool!

Final thoughts on Day One

Io is definitely totally different from the C-like languages — C, C++, Java — and the 'P' scripting languages which have eveolved from them. So I found the learning curve a bit steep, even on day one learning the very basics. However, Io is very cute and I suspect will be relatively straightforward to pick up. At least compared to perl or something!


  • Be respectful. You may want to read the comment guidelines before posting.
  • You can use Markdown syntax to format your comments. You can only use level 5 and 6 headings.
  • You can add class="your language" to code blocks to help highlight.js highlight them correctly.

Privacy note: This form will forward your IP address, user agent and referrer to the Akismet, StopForumSpam and Botscout spam filtering services. I don’t log these details. Those services will. I do log everything you type into the form. Full privacy statement.