Open dobkeratops opened 9 years ago
If we have the ability to omit brackets, could this situation be solved like this?
foreach items, (x) ->
// ... code using x...
You're right, omitting brackets would make rust 'do' basically redundant. do you do this already ?
I've now implemented foreach(a,b) do x{...code using x..}
...'suffix do' .. but thats' basically yet another syntax for a lambda, seems messy.
Perhaps the bracketless option is more elegant. I'm personally a bit torn since my brain is heavily conditioned to C++ syntax, but I can see the bracketless idea from haskell is a lot more elegant, objectively speaking.
I'll implement when I have time (soon). It will take some time since lots of ambiguous brings. (',' separator uses really common, for x <- f x, y != 0, z
, and function arguments with default value).
foreach items, (x) -> // ... code using x...
Ah yeah, that's how you'd do it in LS, no special exception powdering, just a clean common func (closure) def..
2014-12-10 15:04 GMT+01:00 curimit notifications@github.com:
I'll implement when I have time (soon). It will take some time since lots of ambiguous brings. (',' separator uses really common, for x <- f x, y != 0, z, and function arguments with default value).
— Reply to this email directly or view it on GitHub https://github.com/curimit/SugarCpp/issues/43#issuecomment-66455270.
one thing i'm after is rusts' old do notation which I think was inspired by ruby? it's good for internal iterators & hence parallelizable code.. makes it look natural
Rust used to do this:-
do foreach(items) |x| {
... code using x ...
}
//could easily be a data-parallel iterator
// desugars as foreach(items, |x| { ... code using x...} ), saves a nesting level
do spawn { ...some code on another thread }
'desugars as spawn(||{....})'Swift has something similar - a lambda can be inserted into the previous function call
would you be interested in something similar. what syntax permutations might work well I had considered 'postfix do' introducing a lambda:
foreach(items) do x { // maybe drop the |x|, 'do' explicitely introduces a lambda } do {code... }
perhaps that doesn't suit significant whitespace so well , since in the 1line case there isn't a way of separating
how else could this be written