7 Languages in 7 Weeks, Day 1 of Io
Day 1 of Io has been rather interesting. The language feels different from everything I've had experience with so far, and I'm enjoying the fresh feeling. I think I may be comfortable with certain aspects of Io due to my many hours playing with JavaScript (mostly creating scripts to make certain browser games more trivial...) but the syntax feels different from anything I've dealt with yet, and whether that attests to Io's uniqueness or my own lack of experience with multiple languages, I'm unsure.
Evaluate 1 + 1 and then 1 + "one". Is Io strongly typed or weakly typed?
(1 + 1) asString println # 2 (1 + "one") asString println # Exception: argument 0 to method '+' must be a Number, not a 'Sequence'
The exception suggests "Strongly typed" to me.
Is 0 true or false? What about the empty string? Is nil true or false?
# Conditions are in parenthesis because # "false println" would print "false" for me, # but "true println" was throwing an exception # Is 0 true or false? (0 or false) println # true (0 and true) println # true # What about the empty string? ("" or false) println # true ("" and true) println # true # Is nil true or false? (nil or false) println # false (nil and true) println # false
From the minimal testing I ran against 0, "", and nil, I believe both 0 and the emptry string equate to true, while nil equates to false.
How can you tell what slots a prototype supports?
Object slotNames asString println # list(slotSummary, ownsSlots, and, apropos, foreachSlot, performWithArgList, coroWith, <, actorRun, removeAllSlots, for, isTrue, clone, become, !=, write, switch, setSlotWithType, method, ancestors, futureSend, resend, isActivatable, lazySlot, list, justSerialized, evalArg, uniqueId, @@, do, thisContext, deprecatedWarning, setProto, println, hasProto, writeln, setSlot, handleActorException, inlineMethod, ifNonNil, isKindOf, setIsActivatable, removeAllProtos, coroFor, pause, continue, ifNil, stopStatus, prependProto, ancestorWithSlot, print, protos, evalArgAndReturnSelf, doString, type, ?, return, break, >, message, ==, currentCoro, slotNames, hasLocalSlot, while, perform, serialized, ifNonNilEval, wait, asString, returnIfNonNil, getLocalSlot, or, getSlot, asSimpleString, compare, coroDoLater, hasDirtySlot, slotDescriptionMap, removeProto, appendProto, in, isNil, uniqueHexId, loop, lexicalDo, not, .., doRelativeFile, try, launchFile, , yield, isError, ifNilEval, init, evalArgAndReturnNil, doFile, serializedSlotsWithNames, argIsActivationRecord, returnIfError, isIdenticalTo, super, isLaunchScript, serializedSlots, cloneWithoutInit, hasSlot, contextWithSlot, thisLocalContext, >=, if, relativeDoFile, memorySize, <=, asyncSend, thisMessage, @, markClean, coroDo, slotValues, -, doMessage, proto, ifError, newSlot, updateSlot, removeSlot, shallowCopy, block, actorProcessQueue, raiseIfError, setProtos, argIsCall)
The slotNames slot gives a list of the slots a prototype directly supports, but doesn't list slots a prototype's parent may support.
The book also asks "What is the difference between = (equals), := (colon equals), and ::= (colon colon equals)? When would you use each one?" The book previously mentioned that := sets a slot, and = updates a slot, but doesn't mention what ::= does. Googling suggests ::= creates a slot and a setter as well as assigning a value, while := just creates a slot and assigns the value, and = will only assign a value to an already created slot. I'm not exactly sure yet when you would choose to use ::= over :=, but := is useful for creating a new slot, while = would be used to update any already existing slot.
The book also asks the reader to run an Io program from a file, which—similar to the last langauge—I've been doing all along, in order to upload my solutions to Github. Running an Io program from a file works similar to runnin a Ruby program from a file: from the command line, call Io, passing it the file to run.
Execute the code in a slot given its name.
Greeter := Object clone Greeter sayHello := method("Hello, world!" println) Greeter perform("sayHello") # Hello, world!
While not the longest section, reading through online documentation and fiddling with the various "slots" while solving the problems in the book made this section fun and educating. I'm looking forward to day 2 more, now that I've completed the exercises.










