es-discuss Digest, Vol 150, Issue 20

Artem Kobzar a.kobzar.nlt at gmail.com
Mon Aug 19 08:52:56 UTC 2019


I think it could be problems with this slice syntax, because if we want to
use variable as an argument for the operator in some cases it could be
perceived as label or object property by tokenizer.
In addition, could be problem with tokenizing of slice syntax with step,
because we need to look forward to check next symbol for decision between
raw slice and slice with step 😶

On Mon, Aug 19, 2019 at 11:30 AM <es-discuss-request at mozilla.org> wrote:

> Send es-discuss mailing list submissions to
>         es-discuss at mozilla.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://mail.mozilla.org/listinfo/es-discuss
> or, via email, send a message with subject or body 'help' to
>         es-discuss-request at mozilla.org
>
> You can reach the person managing the list at
>         es-discuss-owner at mozilla.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of es-discuss digest..."
> Today's Topics:
>
>    1. Proposal: Range Expression (Artem Kobzar)
>    2. Re: Proposal: Range Expression (Naveen Chawla)
>    3. Re: Proposal: Range Expression (Cyril Auburtin)
>
>
>
> ---------- Forwarded message ----------
> From: Artem Kobzar <a.kobzar.nlt at gmail.com>
> To: es-discuss at mozilla.org
> Cc:
> Bcc:
> Date: Mon, 19 Aug 2019 01:23:52 +0300
> Subject: Proposal: Range Expression
> ### Proposal: Range Expression
>
> The proposal based on one of the worst things in JavaScript Arrays.
>
> If i as developer want to make sequence of some numbers or characters then
> i need to use weird methods like `Array.from`, manual filling or
> imperative-style array filling.
>
> ```js
> const group1 = [1, 2, 3, 4, 5, ...]// manual filling
> const group2= Array.from({ length: 15 }).map((_, i) => i + 1);
> const group3 = [];
> for (let i = 0; i < 15; i++) group3[i] = i + 1;
> ```
>
> This ways to describe range sequence is huge and unreadable.
>
>
> So, my proposal is: range expression which help to create lazy iterable
> range sequence in declarative way.
>
> ```js
> const group0 = 1...15; // from 1 to 15
> const group1 = 15...1; // from 15 to 1
> const group2 = 1n...15n // from 'a' to 'z'
> const group3 = 'a'...'z' // from 'a' to 'z'
> const group4 = 82... // lazy collection of numbers
>
> for (const odd of 1...85) {
>  // ...
> }
>
> // in combination with https://github.com/tc39/proposal-iterator-helpers
> const allEven = (1...100).filter(isEven);
> ```
>
> So, this operator is syntax sugar for the next generator which create lazy
> iterable sequence:
>
> ```js
> function* range(start, end, second) {
>   validate(start, end, second)// type assertion of start, second and end
>   const step = difference(start, second); // difference calculation
>   let current = start;
>   while(isNotEnd(current, end)) { // logic for negative step and different
> types
>     yield current;
>     current = next(current, step); // function which change current number
> | bigint | string by difference
>   }
> }
> ```
>
>
>
> ---------- Forwarded message ----------
> From: Naveen Chawla <naveen.chwl at gmail.com>
> To: Artem Kobzar <a.kobzar.nlt at gmail.com>
> Cc: es-discuss <es-discuss at mozilla.org>
> Bcc:
> Date: Mon, 19 Aug 2019 08:34:11 +0100
> Subject: Re: Proposal: Range Expression
> I like it. I might prefer it in square brackets e.g. [ x ... y ] ?
>
> On Sun, 18 Aug 2019 at 23:24, Artem Kobzar <a.kobzar.nlt at gmail.com> wrote:
>
>> ### Proposal: Range Expression
>>
>> The proposal based on one of the worst things in JavaScript Arrays.
>>
>> If i as developer want to make sequence of some numbers or characters
>> then i need to use weird methods like `Array.from`, manual filling or
>> imperative-style array filling.
>>
>> ```js
>> const group1 = [1, 2, 3, 4, 5, ...]// manual filling
>> const group2= Array.from({ length: 15 }).map((_, i) => i + 1);
>> const group3 = [];
>> for (let i = 0; i < 15; i++) group3[i] = i + 1;
>> ```
>>
>> This ways to describe range sequence is huge and unreadable.
>>
>>
>> So, my proposal is: range expression which help to create lazy iterable
>> range sequence in declarative way.
>>
>> ```js
>> const group0 = 1...15; // from 1 to 15
>> const group1 = 15...1; // from 15 to 1
>> const group2 = 1n...15n // from 'a' to 'z'
>> const group3 = 'a'...'z' // from 'a' to 'z'
>> const group4 = 82... // lazy collection of numbers
>>
>> for (const odd of 1...85) {
>>  // ...
>> }
>>
>> // in combination with https://github.com/tc39/proposal-iterator-helpers
>> const allEven = (1...100).filter(isEven);
>> ```
>>
>> So, this operator is syntax sugar for the next generator which create
>> lazy iterable sequence:
>>
>> ```js
>> function* range(start, end, second) {
>>   validate(start, end, second)// type assertion of start, second and end
>>   const step = difference(start, second); // difference calculation
>>   let current = start;
>>   while(isNotEnd(current, end)) { // logic for negative step and
>> different types
>>     yield current;
>>     current = next(current, step); // function which change current
>> number | bigint | string by difference
>>   }
>> }
>> ```
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
>
>
> ---------- Forwarded message ----------
> From: Cyril Auburtin <cyril.auburtin at gmail.com>
> To: es-discuss <es-discuss at mozilla.org>
> Cc:
> Bcc:
> Date: Mon, 19 Aug 2019 10:29:27 +0200
> Subject: Re: Proposal: Range Expression
> I'd prefer to have it in slice-notation
> https://github.com/tc39/proposal-slice-notation/issues/1#issuecomment-522227270
>
> ```js
> [...0:8] // [0,1,2,3,4,5,6,7]
> ```
>
> On Mon, Aug 19, 2019 at 9:34 AM Naveen Chawla <naveen.chwl at gmail.com>
> wrote:
>
>> I like it. I might prefer it in square brackets e.g. [ x ... y ] ?
>>
>> On Sun, 18 Aug 2019 at 23:24, Artem Kobzar <a.kobzar.nlt at gmail.com>
>> wrote:
>>
>>> ### Proposal: Range Expression
>>>
>>> The proposal based on one of the worst things in JavaScript Arrays.
>>>
>>> If i as developer want to make sequence of some numbers or characters
>>> then i need to use weird methods like `Array.from`, manual filling or
>>> imperative-style array filling.
>>>
>>> ```js
>>> const group1 = [1, 2, 3, 4, 5, ...]// manual filling
>>> const group2= Array.from({ length: 15 }).map((_, i) => i + 1);
>>> const group3 = [];
>>> for (let i = 0; i < 15; i++) group3[i] = i + 1;
>>> ```
>>>
>>> This ways to describe range sequence is huge and unreadable.
>>>
>>>
>>> So, my proposal is: range expression which help to create lazy iterable
>>> range sequence in declarative way.
>>>
>>> ```js
>>> const group0 = 1...15; // from 1 to 15
>>> const group1 = 15...1; // from 15 to 1
>>> const group2 = 1n...15n // from 'a' to 'z'
>>> const group3 = 'a'...'z' // from 'a' to 'z'
>>> const group4 = 82... // lazy collection of numbers
>>>
>>> for (const odd of 1...85) {
>>>  // ...
>>> }
>>>
>>> // in combination with https://github.com/tc39/proposal-iterator-helpers
>>> const allEven = (1...100).filter(isEven);
>>> ```
>>>
>>> So, this operator is syntax sugar for the next generator which create
>>> lazy iterable sequence:
>>>
>>> ```js
>>> function* range(start, end, second) {
>>>   validate(start, end, second)// type assertion of start, second and end
>>>   const step = difference(start, second); // difference calculation
>>>   let current = start;
>>>   while(isNotEnd(current, end)) { // logic for negative step and
>>> different types
>>>     yield current;
>>>     current = next(current, step); // function which change current
>>> number | bigint | string by difference
>>>   }
>>> }
>>> ```
>>> _______________________________________________
>>> es-discuss mailing list
>>> es-discuss at mozilla.org
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
> _______________________________________________
> 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/20190819/c0613d59/attachment.html>


More information about the es-discuss mailing list