Re: significance of newline in io?

Jan-Paul Bultmann <[email protected]>
Newsgroups gmane.comp.lang.io
Message-ID <[email protected]>
I'd say missing something ^^

On object there is a slot defined names "" (the empty string).
You can get it with Object getSlot(""). This method is used to implement precedence operations with ().
Think of it as if you would call a method whose argument expression will be evaluated and the result returned, thus it's contents can't be ripped apart by adjacent operators with higher precedence.

So Ios synax is not ambiguous :)

Cheers Jan

Ps. This is what it would evaluate to:
f := method
-> method()

(
	arg1, arg2,
	writeln
	(arg1, arg2)
	->arg1
)
-> arg1
This is because the method of "" only evaluates the first parameter.

On Aug 10, 2011, at 3:57 AM, paul sanwald wrote:

> ok, I think I've got it, thanks Steve and Dennis.
> 
> 
>  The second definition in your example wouldn't work because its syntax is ambiguous, there's no way for the interpreter to know if (arg1, arg2) belongs to f or writeln, is this correct? or, am I missing something? 
> 
> --paul
> 
> On Aug 9, 2011, at 9:47 PM, dennisf486 wrote:
> 
>>  
>> 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
>> > > 
>> > > 
>> > >
>> >
>> 
> 
> 
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.