wren icon indicating copy to clipboard operation
wren copied to clipboard

if/else - docs need to mention that else must follow brace on the same line

Open xemjeff opened this issue 3 years ago • 4 comments

From the wren html doc page on control flow:

if (ready) {
  System.print("go!")
} else {
  System.print("not ready!")
}

This compiles and executes as expected.

However, with the else statement on the next line, we get an error. from my module file: clip.wren

if (ready) {
  System.print("go!")
}
else {
  System.print("not ready!")
}

error output when trying to load the module:

wren v0.4.0
> import "./clip"
[./clip line 4] Error at 'else': Expected expression.
[./clip line 4] Error at '{': Expect end of file.
Runtime error: Could not compile module './clip'.

If the compile error is the intended behavior, then perhaps we need to update the doc page with some advice or a warning: doc: https://wren.io/control-flow.html

xemjeff avatar Jun 05 '22 19:06 xemjeff

It is currently intended and required to be on the same line yea.

ruby0x1 avatar Jun 05 '22 20:06 ruby0x1

Removing that requirement could be easily implemented (like it was done for the '.' after new line) it is only a political decision/design choice.

mhermier avatar Jun 05 '22 22:06 mhermier

yea @mhermier I've been experimenting with it in luxe for a while looking for edge cases in daily use, I think there's value in reducing friction for the 99% when a 0.1% of use case can cause confusion. I'd rather the confusion be on the small subset than the majority so I'm revisiting this in practice at scale with many users

ruby0x1 avatar Jun 05 '22 22:06 ruby0x1

@ruby0x1 Any update of this?

antopilo avatar Apr 02 '23 16:04 antopilo