Question

I am trying the following sample from 7 Languages in 7 Weeks:

Object ancestors := method(
    prototype := self proto
        if(prototype != Object,
            writeln("Slots of ", prototype type, "\n---------------")
            prototype slotNames foreach(slotName, writeln(slotName))
            writeln
            prototype ancestors))

If I put the code in a file with the rest of the example (e.g. animals.io) and execute it via the command line io animals.io then it works as expected.

However, if I attempt to type the method in manually and execute it for any object, I get the following error:

Exception: Object does not respond to 'prototype'
---------
Object prototype                     Command Line 1
Object ancestors                     Command Line 1

Is it possible to enter this multi-line method via the interactive interpreter?

Was it helpful?

Solution

use semicolon as a line separator in REPL.

Object ancestors := method(
    prototype := self proto;
        if(prototype != Object,
            writeln("Slots of ", prototype type, "\n---------------");
            prototype slotNames foreach(slotName, writeln(slotName));
            writeln;
            prototype ancestors))

OTHER TIPS

While the Io REPL allows you to enter multiline statements [1], it unfortunately seems to just concatenate the lines together :(

Io> Object getSlot("ancestors")
==> method(
    prototype := self proto if(prototype != Object, writeln("Slots of ", prototype type, "\n---------------") prototype slotNames foreach(slotName, writeln(slotName)) writeln prototype ancestors)
)

[1] - You will probably need ReadLine installed on your OS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top