proposal-do-expressions icon indicating copy to clipboard operation
proposal-do-expressions copied to clipboard

Block-Like vs IIFE-Like

Open Jamesernator opened this issue 8 years ago • 4 comments

Basically this issue is about whether to treat do-expressions as block like therefore allowing control flow or whether they should behave like IIFE's and disallow control flow that affects anything outside the do-block.

Note: For the IIFE-like form I don't propose requiring return instead of completion values, I'd propose for that form that instead of implicit return undefined like in regular functions there'd be an implicit return <<CompletionValue>>

Something that'd be nice to see is examples and advantages of both types.


In favor of IIFE-like I see extensibility for async (and/or generator) variants (see here and here).

It also has the advantage that there's no difference if moving the do ... into a function.

e.g. These would always do the same thing irrespective of context:

const x = do {
    ...
}

const f = _ => do {
    ...
}
const x = f()


In favor of Block-like I can see how early interruption in case of certain conditions (e.g. trivial cases) could be used. But I don't see cases where it wouldn't be trivial to move those cases before the do-block so some motivating examples for control flow in do-expressions would be nice.

Jamesernator avatar Sep 15 '17 08:09 Jamesernator

I prefer block-like behavior, but I wouldn't mind additional syntax for IIFE behavior

phaux avatar Sep 15 '17 12:09 phaux

👍 for block-behavior. I'd expect yields inside a do expression in a generator to work:

function *gen() {
  return do {
    yield x;
  };
}

clemmy avatar Dec 14 '17 22:12 clemmy

Any further discussion on this?

I much prefer the ability to do early returns with IIFE behavior.

vjpr avatar Jul 25 '18 15:07 vjpr

Recent discussion at #34

hax avatar Jul 16 '19 07:07 hax