Do-Expressions Proposal Stalled?

Michael Rosefield rosyatrandom at gmail.com
Thu Jan 18 12:32:49 UTC 2018


Addendum: all non-function/class statement blocks seem to act like this,

```
for (x of ['val']) { x; }
// "val"

for (x in ['val']) { x; }
// "0"

let x = 1
// undefined
while (x) {
    x-= 1;
    x;
}
// 0

switch(1) {
    case 0: 2;
    case 1: 6;
}
// 6
```

This raises the general question: why not let *all* statement blocks be
used as expressions?

On Thu, 18 Jan 2018 at 12:21 Michael Rosefield <rosyatrandom at gmail.com>
wrote:

> Just to stick my uninformed oar into this, I notice what `do-while`
> statements *already* return a value in the exact way as the proposal.
>
> ```
> do {
> if(true) 1;
> else 2;
>  } while(false)
> // 1
> do {
> if(!true) 1;
> else 2;
>  } while(false)
> // 2
> ```
>
> Of course, since this is a statement rather than an expression, there's
> little you can do with that.
>
> So I have 2 questions:
> 1. Would changing `do-while` from a statement to an expression cause any
> issues?
> 2. Would having the while clause optional (and leaving it out being
> equivalent to `while(false)`) cause any issues?
>
> On Thu, 18 Jan 2018 at 12:01 Naveen Chawla <naveen.chwl at gmail.com> wrote:
>
>> I agree it's a misuse, my point is simply why introduce the possibility?
>> Key question for me (for any feature): show how it can reduce the chances
>> of bugs.
>>
>> Arrow functions succeed, for example: by removing nested "this" context,
>> thereby simplifying moving of code around etc.
>> Async await succeeds, for example: by linearizing and hence considerably
>> simplifying the building and reading of asynchronous data flows in code.
>> Classes succeed, for example: by removing the fiddly overhead in
>> establishing (especially multi-level) inheritance using prototypes.
>>
>> The examples on the proposal page don't succeed, for me, in establishing
>> how (if at all) using a do-expression could (vs the most elegant
>> alternative currently).
>>
>> On Thu, 18 Jan 2018 at 17:16 T.J. Crowder <
>> tj.crowder at farsightsoftware.com> wrote:
>>
>>> On Thu, Jan 18, 2018 at 11:39 AM, Naveen Chawla <naveen.chwl at gmail.com>
>>> wrote:
>>> > ...but can you imagine a heavily nested conditional algorithm
>>> > where it's not immediately clear you're inside a "do" expression?
>>>
>>> I can. I would call it a misuse of the `do` operator, just like it is
>>> when you do that with conditionals or nested callbacks or switches or arrow
>>> functions or (etc.), or some combination of same. :-)
>>>
>>> -- T.J. Crowder
>>>
>>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180118/9f696cc7/attachment-0001.html>


More information about the es-discuss mailing list