Re: significance of newline in io?
"dennisf486" <[email protected]>
| Newsgroups | gmane.comp.lang.io |
|---|---|
| Message-ID | <[email protected]> |
The genius of Io though, which distinguishes it from other languages with newlines-terminate-expressions is that Io treats lines following an unmatched left-parens ( as part of one expression until the parens is closed.
That's what allows syntax like:
f := method(arg1, arg2,
writeln(
arg1,
arg2
)
)
Instead of "writeln(" generating an error on the newline as similar syntax would in e.g. a BASIC-dialect, it's just implicit that you want to continue the expression on multiple lines. So you don't need a line continuation character, just parenthesis.
This, on the other hand, would not work:
f := method
(
arg1, arg2,
writeln
(arg1, arg2)
)
--- In [email protected], Steve Dekorte <steve@...> wrote:
>
> A newline in Io is like a semicolon in C - it ends the expression and returns the evaluation scope to the locals.
>
>
>
> On Aug 7, 2011, at 8:05 PM, Paul Sanwald <pcsanwald@...> wrote:
>
> >
> >
> > working through "7 languages in 7 weeks", I noticed something interesting. This method definition me an error when invoking:
> > Object ancestors := method(
> > prototype := self proto
> > if (prototype != Object,
> > writeln("Slots of ",prototype type,"\n-------")
> > prototype slotNames foreach(slotName, writeln(slotName))
> > writeln prototype ancestors))
> >
> > Whereas, this definition does not:
> >
> > Object ancestors := method(
> > prototype := self proto
> > if (prototype != Object,
> > writeln("Slots of ",prototype type,"\n-------")
> > prototype slotNames foreach(slotName, writeln(slotName))
> > writeln
> > prototype ancestors))
> >
> > the only difference here is the newline after "writeln". what is the significance of the newline in the language? am I missing something in the docs?
> >
> > thanks for your help!
> >
> > --paul
> >
> >
> >
>