~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
2 years ago
Updated
1 year, 6 months ago
Labels
T-THOUGHTS

~akavel 1 year, 6 months ago

~icefox 1 year, 6 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.