3 ms·
I’ll just cross my fingers for do expressions getting adopted. Before then functions work for me and none of the gist convinced me otherwise.
by teg4n_ 4y ago
I’ll just cross my fingers for do expressions getting adopted. Before then functions work for me and none of the gist convinced me otherwise.
- UncleEntity 4y agoCouldn’t you just: /* do */ { const foo = “bar” do_the_stuff(foo) } /* while(JS_sux) */ Typing code on a phone is hard…
- eyelidlessness 4y agoYou can even just use `do { … } while (false)` without comments, but neither is an expression. Neither produce a value. The do expression would have similar encapsulation but allow assigning a derived value to a lhs binding, as you could do in a lisp (or Rust [or Swift, or…]).
- matthews2 4y ago> as you could do in a lisp (or Rust [or Swift, or…]) There's also a GCC extension for this! https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html I'm using this for something a bit like Rust's unwrap (but uglier): #define UNWRAP(expr) \ {{ \ auto result_ = (expr); \ if (!result_.present()) panic(); \ result_.disown(); \ }} optional<int> foo(); void bar() { int val = UNWRAP(foo); }
- stkdump 4y agoIsn't a do expression the same + ability for the block to return a value? So what if you don't need to return a value?
- teg4n_ 4y agoDon’t return one then?