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?
use semicolon as a line separator in REPL.