The second language in the book is Io.
The first thing I have liked about Io is that you send messages to the objects :) Instead of “calling a method” we send messages. I think that can help us a lot with our design once we start building complex programs. We will see.
I also like a lot how simple Io syntax is. There are no exceptions in the syntax rules, things can only be done in one way. That makes it really easy to start playing with Io.
There are none exercises for this day, but the author asks some questions:
Is Io strongly typed or weakly typed? I do not know how to answer this question. Io is a prototype language, and I do not think it cares about types. It has a slot named type, but it is not a “type” as in Ruby (A class was a type in Ruby). The slot type is only informative. But, why 1 + “one” throws an error asking for a Number instead of a “Sequence”? The operator + works as follows:
Io> 1 getSlot("+") > Number_+() Io> add := Number getSlot("+") > Number_+() Io> 1 add(2) > 3 Io> add Exception: CFunction defined for type Number but called on type Object
Ok! So the operator ”+” is a CFunction :) Io is written in C. I imagine that ”+” is implemented using the C primitives for the integers(it uses doubles).
So, summarizing, Io is not strongly or weakly typed. It implementation is strongly typed (but I think that only for numbers).
Is 0 true or false? what about the empty string? and nil? 0 and ”” are true, nil is false, as you can see if you execute those commands:
0 or false "" or false nil and true
How can you tell what slots a prototype supports? To know all the slots a prototype supports we just need to call slotNames. For Object, it shows:
Io> Object slotNames > list(newSlot, ownsSlots, foreachSlot, currentCoro, <, removeAllSlots, list, for, doString, uniqueHexId, clone, become, write, evalArgAndReturnNil, setSlotWithType, isNil, method, block, pause, isActivatable, deprecatedWarning, isLaunchScript, coroWith, evalArg, uniqueId, ?, ifError, serializedSlots, actorProcessQueue, do, in, setProto, super, writeln, setSlot, !=, inlineMethod, justSerialized, doRelativeFile, removeAllProtos, coroDo, asyncSend, continue, stopStatus, ancestorWithSlot, print, protos, evalArgAndReturnSelf, actorRun, not, type, and, return, break, slotSummary, >, message, ==, slotNames, ifNonNilEval, asSimpleString, serializedSlotsWithNames, hasLocalSlot, while, updateSlot, serialized, switch, perform, asString, hasSlot, try, returnIfNonNil, hasProto, prependProto, getSlot, wait, hasDirtySlot, thisContext, removeProto, appendProto, println, lazySlot, loop, slotDescriptionMap, launchFile, .., relativeDoFile, compare, , yield, init, resend, isTrue, lexicalDo, or, doFile, argIsActivationRecord, isError, ancestors, isIdenticalTo, ifNil, ifNilEval, performWithArgList, cloneWithoutInit, contextWithSlot, thisLocalContext, >=, if, isKindOf, memorySize, <=, ifNonNil, coroFor, thisMessage, apropos, @, getLocalSlot, returnIfError, markClean, coroDoLater, slotValues, -, doMessage, proto, raiseIfError, setIsActivatable, futureSend, removeSlot, shallowCopy, handleActorException, @@, setProtos, argIsCall)
We can also use “do” instead of “slotNames”, but I let you discover what it does ;)
What is the difference between ”=”, “:=” and “::=”? When should you use each one? “:=” creates a new slot and assigns a value to that slot. ”=” assigns a value to an existing slot. If we use ”=” with a new slot Io throws an exception. “::=” creates a new slot, assigns a value for that slot and creates a setter for that slot. What does it meansto create a setter? You can have a look at this link
He also asks us to:
run an Io program from a file. You can see my program here, but it is not very much…
execute the code in a slot given its name.
aClone := Object clone anotherClone := Object doString("clone")
See you tomorrow!