Ah, it took a week to learn Io language because I was busy writing a draft of the oauth2.0 Server framework last week.
The answer to this exercise is followed by seven weeks and seven languages: understanding a variety of programming patterns; answers to the exercises after Ruby class
I/O is a prototype language, similar to Javascript, and does not distinguish between classes and objects. All things are objects, the data structure of an object is maintained by a key-value table (in Io, It is a so-called slot). It passes various messages to the object to implement printing, copying, and other functions. Because the syntax is very simple (there are also syntactic sugar), you can build your own library and functions as much as you like.
Day 1:
1. Evaluate 1 + 1, and then 1 + "one. Is Io strongly typed or weakly typed? Use code to confirm your answer.
Io is a dynamic (type is checked at runtime), strong language.
Io 20110905Io> 1+"one" Exception: argument 0 to method ‘+‘ must be a Number, not a ‘Sequence‘ --------- message ‘+‘ in ‘Command Line‘ on line 1
2. is 0 true or false? Is the Null String true or false? Is nil true or false? Use code to confirm your answer.
0, null strings are considered to be true, while Nil is considered to be false
Io> if (0) then ("OK\n" print)OK==> nilIo> if ("") then ("OK\n" print)OK==> nilIo> if (nil) then ("OK\n" print)==> false
3. How do I know the slots supported by a prototype?
Xxx proto
Xxx slotnames
4. = (equal sign),: = (colon equal sign),: = (colon equal sign) What is the difference? Under what circumstances will you use them?
Assign Operators ::= newSlot := setSlot = updateSlot
Io> Vehicle := Object clone==> Vehicle_0x7fc3dbeb7110: type = "Vehicle"Io> Vehicle description := "a fast car"==> a fast carIo> Vehicle slotNames==> list(description, type)Io> Ferrari := Vehicle clone==> Ferrari_0x7fc3dbe4f2e0: type = "Ferrari"Io> Ferrari colour ::= "red"==> redIo> Ferrari slotNames==> list(setColour, type, colour)
Look, the difference between: = And: = is that: = is an additional setcolour slot.
You can use Ferrari setcolour ("blue") to define the color of colour.
Seven weeks and seven languages: understanding a variety of programming patterns; answers to exercises after I/O