Re: Letting RegExp method return something iterable?

2017-06-18 Thread 森建
@Oriol Thanks for your reply! On 2017/06/18 21:33, Oriol _ wrote: There is a `String#matchAll` proposal in stage 1. https://github.com/tc39/String.prototype.matchAll https://github.com/tc39/String.prototype.matchAll> Oriol ___ es-discuss mailing

Re: Re: Letting RegExp method return something iterable?

2017-06-18 Thread Oriol _
There is a `String#matchAll` proposal in stage 1. https://github.com/tc39/String.prototype.matchAll Oriol ___ es-discuss mailing list es-discuss@mozilla.org

Re: Re: Letting RegExp method return something iterable?

2017-06-18 Thread 森建
Although It seems that some people agreed with appending `RegExp#execAll` to EcmaScript 4 years ago, what happened to it after that? topic: https://esdiscuss.org/topic/letting-regexp-method-return-something-iterable implementation: https://www.npmjs.com/package/regexp.execall

Re: Letting RegExp method return something iterable?

2013-08-29 Thread Axel Rauschmayer
The fact that s.match(/re/g) returns the array of all matches (with captures) sucks some of the oxygen away from any /re/g.execAll(s) proposal. But String.prototype.match has perlish hair (e.g., those capture groups showing up in the result array). Really? AFAICT, only the complete

Re: Letting RegExp method return something iterable?

2013-08-29 Thread Axel Rauschmayer
[...] I think this makes a good case for a lazy execAll -- with a much better name. Candidates: r.iterate(s), r.iterateOver(s), r.execIterator(s) (blech!). Suggest some! I think “exec” should be in the name, to indicate that the new method is a version of `exec()`. Ideas: –

Re: Letting RegExp method return something iterable?

2013-08-29 Thread Brendan Eich
Axel Rauschmayer wrote: The fact that s.match(/re/g) returns the array of all matches (with captures) sucks some of the oxygen away from any /re/g.execAll(s) proposal. But String.prototype.match has perlish hair (e.g., those capture groups showing up in the result array). Really? AFAICT,

Re: Letting RegExp method return something iterable?

2013-08-29 Thread Brendan Eich
Axel Rauschmayer wrote: – execIter() Not bad, I think better than execAll, which does not connote return of an iterator, but which does perversely suggest returning an array of all exec results. `execAll()` may not be that bad. It’s not pretty, but it’s fairly easy to guess what it does

Re: Letting RegExp method return something iterable?

2013-08-29 Thread Axel Rauschmayer
I agree that execAll() is not a 100% winner, more like a clean-up of a quirky corner. But exec() in “multi” mode has a surprising amount of pitfalls: * /g flag must be set * lastIndex must be 0 * can’t inline the regex, because it is needed as a pseudo-iterator (more of an anti-pattern, anyway,

Re: Letting RegExp method return something iterable?

2013-08-29 Thread Brendan Eich
Axel Rauschmayer wrote: * /g flag must be set * lastIndex must be 0 * can’t inline the regex, because it is needed as a pseudo-iterator (more of an anti-pattern, anyway, but still) * side effects via lastIndex may be a problem Anything we do of the execAll/execIter kind had better be immune

Re: Letting RegExp method return something iterable?

2013-08-29 Thread Dean Landolt
On Thu, Aug 29, 2013 at 4:13 AM, Brendan Eich bren...@mozilla.com wrote: Axel Rauschmayer wrote: * /g flag must be set * lastIndex must be 0 * can’t inline the regex, because it is needed as a pseudo-iterator (more of an anti-pattern, anyway, but still) * side effects via lastIndex may be

Re: Letting RegExp method return something iterable?

2013-08-29 Thread Oliver Hunt
On Aug 29, 2013, at 1:13 AM, Brendan Eich bren...@mozilla.com wrote: Axel Rauschmayer wrote: * /g flag must be set * lastIndex must be 0 * can’t inline the regex, because it is needed as a pseudo-iterator (more of an anti-pattern, anyway, but still) * side effects via lastIndex may be a

Re: Letting RegExp method return something iterable?

2013-08-29 Thread Andrea Giammarchi
then you are probably looking for something like this? ```javascript String.prototype.matchAll = function (re) { for (var re = new RegExp( re.source, g + (re.ignoreCase ? i : ) + (re.multiline ? m : ) ), a = [], m; m = re.exec(this); a.push(m) );

Re: Letting RegExp method return something iterable?

2013-08-29 Thread Brendan Eich
Dean Landolt wrote: I'd hate to see it throw. Ignoring lastIndex seems friendlier, especially if it were called `execAll`. It probably shouldn't be called `execIter` considering `exec` is already an iterator (even if a bit crazy). 'exec' is not an iterator in any well-defined ES6 sense.

Re: Letting RegExp method return something iterable?

2013-08-29 Thread Brendan Eich
Oliver Hunt wrote: I would favor ignoring lastIndex rather than throwing, but to be sure can you clarify what you mean by global regexp? One created with the 'g' flag, either literally (/re/g) or via the constructor (new RegExp(src, 'g')). If we're talking /.../g, then my feeling is that

RE: Letting RegExp method return something iterable?

2013-08-28 Thread Forbes Lindesay
Right, my impression is that most of us are in agreement that it would be extremely useful to have a simple way to loop over the list of matches for a regular expression and do something with each one. I don't see why @andrea doesn't see this need (maybe it's not something he's found need to

Re: Letting RegExp method return something iterable?

2013-08-28 Thread Tab Atkins Jr.
On Wed, Aug 28, 2013 at 2:12 AM, Forbes Lindesay for...@lindesay.co.uk wrote: Right, my impression is that most of us are in agreement that it would be extremely useful to have a simple way to loop over the list of matches for a regular expression and do something with each one. I don't see

RE: Letting RegExp method return something iterable?

2013-08-28 Thread Forbes Lindesay
So you're in favor of returning the Iterable and then having people use `Array.from` if they need an array? ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Re: Letting RegExp method return something iterable?

2013-08-28 Thread Axel Rauschmayer
I'm guessing that code like: ```js var matches = /foo/.execMultipleLazy('str') for (let match of matches) { //do something } for (let match of matches) { //do something } for (let match of matches) { //do something } ``` Would go wrong somehow Yes. This is a standard Python

Re: Letting RegExp method return something iterable?

2013-08-28 Thread Andrea Giammarchi
On Wed, Aug 28, 2013 at 2:12 AM, Forbes Lindesay for...@lindesay.co.ukwrote: a simple way to loop over the list of matches for a regular expression it's about 10 years or more we have that .. so to make my very personal statement clear: I've got 99 problems in JS, make everything an iterator

RE: Letting RegExp method return something iterable?

2013-08-28 Thread Forbes Lindesay
Right, I don't care whether it's lazy. I only care that it exists. Nobody's crying out for a lazy version of string split (at least not yet anyway). I have had the issue of needing to loop over all the matches that a regular expression has. It is a common, recurring issue that many

Re: Letting RegExp method return something iterable?

2013-08-28 Thread Brendan Eich
Forbes Lindesay wrote: Let’s move on from whether it should exist (clearly it should) Does String.prototype.match not count? and stick to whether it should be an array, or lazy. Does anyone have a strong opinion either way? The fact that all our regular expression iteration thus far has

RE: Letting RegExp method return something iterable?

2013-08-28 Thread Ron Buckton
/‎2013 4:55 PM To: Andrea Giammarchimailto:andrea.giammar...@gmail.com Cc: Brendan Eichmailto:bren...@mozilla.com; es-discuss listmailto:es-discuss@mozilla.org; Erik Arvidssonmailto:erik.arvids...@gmail.com Subject: RE: Letting RegExp method return something iterable? Right, I don’t care whether

Re: Letting RegExp method return something iterable?

2013-08-28 Thread Brendan Eich
Ron Buckton wrote: The advantage of a lazy execAll, is the ability to break out of the for..of loop without the need to continue to traverse the input string looking for matches. This is the same advantage that the `while(m = re.exec())` has going for it. You can always be greedy by using

Re: Letting RegExp method return something iterable?

2013-08-27 Thread Claude Pache
Le 27 août 2013 à 01:23, Brendan Eich bren...@mozilla.com a écrit : Andrea Giammarchi wrote: Is it very useful because you wrote for instead of while ? ```javascript while (m = re.exec(str)) console.log(m[0]) ; ``` It is, for two reasons: 1. in JS only for can have a let or var

Re: Letting RegExp method return something iterable?

2013-08-27 Thread Andrea Giammarchi
sure you know everything as soon as you read `of` ... right ? How objectives are your points ? If you know JS that while looks very simple, IMO On Tue, Aug 27, 2013 at 5:24 AM, Claude Pache claude.pa...@gmail.comwrote: Le 27 août 2013 à 01:23, Brendan Eich bren...@mozilla.com a écrit :

Re: Letting RegExp method return something iterable?

2013-08-27 Thread Andrea Giammarchi
let me rephrase ... I've no idea what this code does if not a syntax error (and for different reasons) `for (let m of re.execAll(str) {` what is `of` ... will `let` mark that variable as local ? what is returned and what will be `m` ? I need to know these things ... this has nothing to do with

Re: Letting RegExp method return something iterable?

2013-08-27 Thread Brendan Eich
On Aug 27, 2013, at 9:42 AM, Andrea Giammarchi andrea.giammar...@gmail.com wrote: sure you know everything as soon as you read `of` ... right ? Wrong. The nested assignment is idiomatic in C but not good for everyone (see gcc's warning when not parenthesized in such contexts) due to == and =

Re: Letting RegExp method return something iterable?

2013-08-27 Thread Andrea Giammarchi
losing argument ... as if assignment within condition has been a real problem except for JSLint ... uhm, I don't think so but I am off this conversation. Already said my point, feel free to (as usual) disagree ^_^ On Tue, Aug 27, 2013 at 9:48 AM, Brendan Eich bren...@mozilla.com wrote: On Aug

Re: Letting RegExp method return something iterable?

2013-08-27 Thread Claude Pache
Le 27 août 2013 à 18:48, Andrea Giammarchi andrea.giammar...@gmail.com a écrit : let me rephrase ... I've no idea what this code does if not a syntax error (and for different reasons) `for (let m of re.execAll(str) {` what is `of` ... will `let` mark that variable as local ? what is

Re: Letting RegExp method return something iterable?

2013-08-26 Thread Andrea Giammarchi
you don't need to reset the `lastIndex` to zero if you don't break the loop before unless you are sharing that regexp with some other part of code you don't control. What I am saying is that the example is very wrong as it is since there's no way to have an unsafe `regexES5` behavior in there.

Re: Letting RegExp method return something iterable?

2013-08-26 Thread Erik Arvidsson
On Mon, Aug 26, 2013 at 1:05 PM, Andrea Giammarchi andrea.giammar...@gmail.com wrote: Long story short, I don't see any real use/case or any concrete advantage with those examples so please make it more clear what's the problem you are trying to solve and how these methods will concretely make

Re: Letting RegExp method return something iterable?

2013-08-26 Thread Andrea Giammarchi
Is it very useful because you wrote for instead of while ? ```javascript while (m = re.exec(str)) console.log(m[0]) ; ``` I don't really see any concrete advantage, sorry, but maybe it's me not liking at all this `iterable all the things` new trend. On Mon, Aug 26, 2013 at 11:33 AM, Erik

Re: Letting RegExp method return something iterable?

2013-08-26 Thread Brendan Eich
Andrea Giammarchi wrote: Is it very useful because you wrote for instead of while ? ```javascript while (m = re.exec(str)) console.log(m[0]) ; ``` It is, for two reasons: 1. in JS only for can have a let or var binding in the head. 2. the utility extends to all for-of variations: array

Re: Letting RegExp method return something iterable?

2013-08-26 Thread Forbes Lindesay
`String#split` already is iterable because it returns an array. What it isn't is **lazy**. To be equivalent to the for code, the let needs to go inside the body of the while, not outside. This neatly demonstrates the key point: - as it stands, writing this kind of code tends to be bug prone

Re: Letting RegExp method return something iterable?

2013-08-26 Thread Andrea Giammarchi
to be really honest, most people will get it wrong regardless since thanks to JSLint and friends they are use to declare everything on top and they probably forgot for accepts `var` declarations. I've never ever needed this syntax and I don't see the miracle. I am sure somebody one day will use

Letting RegExp method return something iterable?

2013-08-24 Thread Axel Rauschmayer
At the moment, the following two methods abuse regular expressions as iterators (if the /g flag is set): * `RegExp.prototype.test()` * `RegExp.prototype.exec()` Would it make sense to create similar methods that return something iterable, so that for-of can iterate over the result? Axel --

Re: Letting RegExp method return something iterable?

2013-08-24 Thread Axel Rauschmayer
Well, obviously it doesn’t make much sense to do that for `text()`, but it would be great to have for `exec()`. On Aug 24, 2013, at 21:39 , Axel Rauschmayer a...@rauschma.de wrote: At the moment, the following two methods abuse regular expressions as iterators (if the /g flag is set): *

Re: Letting RegExp method return something iterable?

2013-08-24 Thread Axel Rauschmayer
An example to make things clearer (thanks for the suggestion, Domenic): https://gist.github.com/rauschma/6330265 On Aug 24, 2013, at 21:43 , Axel Rauschmayer a...@rauschma.de wrote: Well, obviously it doesn’t make much sense to do that for `text()`, but it would be great to have for

RE: Letting RegExp method return something iterable?

2013-08-24 Thread Domenic Denicola
, August 24, 2013 16:45 To: es-discuss list Subject: Re: Letting RegExp method return something iterable? An example to make things clearer (thanks for the suggestion, Domenic): https://gist.github.com/rauschma/6330265 On Aug 24, 2013, at 21:43 , Axel Rauschmayer a...@rauschma.demailto:a