~icefox/garnet#44: 
Blocks as shortcuts for anonymous methods?

Lightly inspired by https://animaomnium.github.io/optional-if-expressions/

So we have block expressions that just bundle a bunch of expr's together and return the last one:

do
    foo()
    bar()
end

What if they were a no-argument closure? Then we could have nicer syntax sugar than Rust's argless closures:

quotient = (den != 0.0).then do 
    num / den
end

...that then makes the actual block expression have a return type of a function though, which you presumably then need to call. Hnyrn. Ugh. I do hate Rust's || expr syntax though. Why don't we have enough types of wiggly braces in the world?

Status
REPORTED
Submitter
~icefox
Assigned to
No-one
Submitted
1 year, 3 months ago
Updated
8 months ago
Labels
T-THOUGHTS

~akavel 8 months ago

~icefox 8 months ago

Hmm, that's an interesting option, so if I'm reading it right that makes do: ... a block of statements and do (...): ... a function. Iiiii don't hate that.

(touches on the "Closure and function type syntax" part of #53.)

Register here or Log in to comment, or comment via email.