Single-line discrepancy.

Monkey Forums/Monkey Programming/Single-line discrepancy.

Belimoth(Posted 2012) [#1]
I have code that looks something like this.

[monkeycode]
Class IMyInterface
Method SetSomething:Void(x:Int, y:Int)
Method DoSomething:Void()
End

Class MyComponent Implements IMyInterface
Field x:Int, y:Int

Method SetSomething(x:Int, y:Int)
Self.x = x
Self.y = y
End

Method DoSomething:Void()
Print "Did something."
End
End

Class MyClass Implements IMyInterface
Field component:MyComponent
'works fine
Method SetSomething:Void(x:Int, y:Int) component.SetSomething(x, y) End
'doesn't work unless it is written in block form
Method DoSomething:Void() component.DoSomething() End
End
[/monkeycode]

I get this error:
Syntax error - unexpected token ')'


I can avoid it by not putting the parameter-less methods on one line, but it seems silly.

EDIT: It also works if I add a semicolon like so:
[monkeycode]
Class MyClass Implements IMyInterface
'...
Method DoSomething:Void() component.DoSomething(); End
End
[/monkeycode]

It's still silly.


Goodlookinguy(Posted 2012) [#2]
If you want it to be consistent you need to add a semi-colons between the code as shown below.

Class MyClass Implements IMyInterface
        '...
        Method SetSomething:Void(x:Int, y:Int); component.SetSomething(x, y); End
        Method DoSomething:Void(); component.DoSomething(); End
End



Belimoth(Posted 2012) [#3]
Yes, I arrived at the same place and was just editing my post. Thank you for your quick response anyhow.


Belimoth(Posted 2012) [#4]
Maybe we can use this thread to discuss the weather? It's very cloudy here.


maltic(Posted 2012) [#5]
Its boiling where I am.

It seems weird seeing semicolons in a BASIC like language.


Gerry Quinn(Posted 2012) [#6]
Are semicolons official? I hadn't realised that was an option, so I have been using blocks always.

I don't think it's silly - in a Basic-like language the compiler is always likely to be limited in how much it can understand without newline cues. It is no sillier than having to put semicolons on the end of every single-statement line in C.

Edit: I see it's in the official Monkey documentation.


maltic(Posted 2012) [#7]
Nice grammatically incorrect but contextually correct semicolon. Its like a grammar pun!

Edit: Why did you edit it out!