3

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?

Jedidja
  • 16,610
  • 17
  • 73
  • 112

2 Answers2

2

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))
1

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

draegtun
  • 22,441
  • 5
  • 48
  • 71
  • 1
    Ah ok. Maybe I can submit a bug report :) At least it's not something weird happening just on my machine. – Jedidja Oct 23 '12 at 13:39
  • I seem to recall that readline/multilines in the REPL as had problems in the past and it was often switched off by default (because occasionally the REPL would sporadically die). – draegtun Dec 31 '12 at 17:40