3 ms·
> For me, I'd rather have an explicit form for bodies that implicity return their result and have the default be to not do that. So that's what I did for Wren.
by twic 12y ago
> For me, I'd rather have an explicit form for bodies that implicity return their result and have the default be to not do that. So that's what I did for Wren.
That strikes me as an excellent decision.
> A single-line body implicitly returns its result, but a multi-line one does not
That, i'm sorry to say, does not! Assigning different semantics to two passages of code whose only syntactic difference is in the composition of their whitespace seems like it might be a misfeature.
Is it too late to consider a louder way of marking the difference? How about:
name = { "Fred" } // implicit return
Or even just introducing a terser explicit return:
name { = "Fred" } // explicit but barfulous return
name { ^"Fred" } // explicit return, also homage to Smalltalk
- munificent 12y ago> Assigning different semantics to two passages of code whose only syntactic difference is in the composition of their whitespace seems like it might be a misfeature. I'll admit it's a bit iffy. However, newlines are already significant as statement separators, so this isn't totally outside the bounds of reason. name = { "Fred" } // implicit return This looks a little too similar to a setter definition to me. Also, it makes sense here, but would look really strange for a lambda: people.map {= |person| person.name } The typical solution is "=>", like: people.map (person) => person.name But then without a trailing delimiter, it's hard to chain multiple of these calls together, which is really common in list manipulation.