Order of evaluation?

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
I'm still playing with the @REGEX thing. In the latest incarnation of my plugin @XMATCH[], it returns the number of matches and sets the plugin _GMATCH to the number of groups matched. When used together in the command, like this
Code:
v:\> echo %@xmatch[(i)|(s)|(q),Mississippi] %_gmatch
8 2
it seems the two variables are evaluated left to right. Is that reliable behavior?
 
#2
| I'm still playing with the @REGEX thing. In the latest incarnation of my
plugin @XMATCH[], it returns the number of matches and sets the plugin
_GMATCH to the number of groups matched.

Possibly _GMATCH could return a set of integers, separated by space or
comma, representing the number of matches for each group, in the same order
as the groups. The function value itself could be the sum, i.e., the total
number of matches. If you think counting nonzero values in _GMATCH is too
much trouble for the user, you could add another internal variable, _GGROUP,
the number of groups matched.

BTW, I doubt I will have much use for any variant myself. Take my suggestion
with a grain of salt (or an ounce).
--
Steve
 
#3
On Wed, 21 Jul 2010 00:10:27 -0400, Steve Fábián
<> wrote:

|| I'm still playing with the @REGEX thing. In the latest incarnation of my
|plugin @XMATCH[], it returns the number of matches and sets the plugin
|_GMATCH to the number of groups matched.
|
|Possibly _GMATCH could return a set of integers, separated by space or
|comma, representing the number of matches for each group, in the same order
|as the groups. The function value itself could be the sum, i.e., the total
|number of matches. If you think counting nonzero values in _GMATCH is too
|much trouble for the user, you could add another internal variable, _GGROUP,
|the number of groups matched.

Unless I'm misunderstanding you, that's what it does now ... returns
the total number of matches and sets _GMATCH to the number of groups
matched.

I suppose I could create an array and put the individual group
match-counts there, or I could add a function @GMATCH[N] to get the
count for group N from the last @XMATCH, but I'm not sure it'd see
much application.

I find regexes (and the programming) interesting but I have little use
for them beyond the basics. Anyone who knows regexes well probably
also knows PERL or RUBY or some other way of using them more
efficiently.
 
#4
On Wed, 21 Jul 2010 04:03:36 -0400, vefatica <>
wrote:

||Possibly _GMATCH could return a set of integers, separated by space or
||comma, representing the number of matches for each group, in the same order
||as the groups. The function value itself could be the sum, i.e., the total
||number of matches. If you think counting nonzero values in _GMATCH is too
||much trouble for the user, you could add another internal variable, _GGROUP,
||the number of groups matched.

At the moment I have this. It's still fast; hasn't slowed down at
all. Comments welcome.

v:\> uhelp @XMATCH
@XMATCH[regex,string] = number of matches

v:\> uhelp @GMATCH
@GMATCH[0] = number of groups matched by last @XMATCH
@GMATCH[N(1~63)] = number of matches for group N

[CODE}v:\> echo %@xmatch[(i)|(q)|(s),Mississippi]
8

v:\> echo %@GMATCH[0]
2

v:\> echo %@GMATCH[1]
4

v:\> echo %@GMATCH[2]
0

v:\> echo %@GMATCH[3]
4[/CODE]