Seven weeks and seven languages: understanding a variety of programming patterns; answers to exercises after I/O

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.