4 ms·
Couldn’t you just: /* do */ { const foo = “bar” do_the_stuff(foo) } /* while(JS_sux) */ Typing code on a phone is hard…
by UncleEntity 4y ago
Couldn’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); }