Re: Why not {,n} in quantifiers?

2002-05-15 Thread Aaron Sherman

On Tue, 2002-05-14 at 20:13, Larry Wall wrote:

 It's unlikely that {n,m} will still have that meaning in Perl 6.  Maybe we'll
 have something like this:
 
 Perl 5Perl 6
 {1,3} 1..3
 {3}   3
 {3,}  3+
 {0,3} 3-
 
 Then again, maybe not...

Hopefully there will be some replacement. I can't count the number of
times I've relied on things like:

$b = qr/\d{1,3}/;
if (ip = ($addr =~ /($b)\.($b)\.($b)\.($b)/)) {
die $0: \$addr\: bad IP\n if grep {$_255} ip;
print(0x,(map {sprintf %02x, $_} ip),\n);
} else {
die $0: \$addr\ is not an IP address\n;
}

It would be a shame to loose that.





Re: Why not {,n} in quantifiers?

2002-05-15 Thread Larry Wall

Aaron Sherman writes:
: Hopefully there will be some replacement. I can't count the number of
: times I've relied on things like:
: 
: $b = qr/\d{1,3}/;
: if (ip = ($addr =~ /($b)\.($b)\.($b)\.($b)/)) {
:   die $0: \$addr\: bad IP\n if grep {$_255} ip;
:   print(0x,(map {sprintf %02x, $_} ip),\n);
: } else {
:   die $0: \$addr\ is not an IP address\n;
: }
: 
: It would be a shame to loose that.

Bear in mind we have to translate Perl 5 to Perl 6, so it's quite unlikely
that we would drop the general case.  The only question here is what it
ought to look like in the general re-huffmanization of regexen.

Larry



Re: Why not {,n} in quantifiers?

2002-05-15 Thread Miko O'Sullivan

From: Larry Wall [EMAIL PROTECTED]
 It's unlikely that {n,m} will still have that meaning in Perl 6.  Maybe
we'll
 have something like this:

 Perl 5 Perl 6
 {1,3} 1..3
 {3} 3
 {3,} 3+
 {0,3} 3-

What are your feelings on multiple ranges for matches?  E.g. the following
expression means 1 to 3, 5, or 10 or more:

1..3|5|10+

-Miko




Re: Why not {,n} in quantifiers?

2002-05-15 Thread Larry Wall

Miko O'Sullivan writes:
: From: Larry Wall [EMAIL PROTECTED]
:  It's unlikely that {n,m} will still have that meaning in Perl 6.  Maybe
: we'll
:  have something like this:
: 
:  Perl 5 Perl 6
:  {1,3} 1..3
:  {3} 3
:  {3,} 3+
:  {0,3} 3-
: 
: What are your feelings on multiple ranges for matches?  E.g. the following
: expression means 1 to 3, 5, or 10 or more:
: 
: 1..3|5|10+

My feelings are that nobody has ever asked me for it before, so it's
not something worth making special syntax for.  On the other hand, if
instead of inventing new syntax we stick to a more Perlish syntax, we
could generalize it to an ordinary slice kind of list:

 1..3,5,10..Inf

But you'd still have the complexity of making it work, and it still
seems like something almost nobody would ever use.  And you could get
the same effect with an appropriate assertion:

(...)* { @$+.length =~ (1..3,5,10..Inf) or fail }

That's assuming that quantified captures produce arrays rather than
the final match as Perl 5 does.

Larry



Why not {,n} in quantifiers?

2002-05-14 Thread Trey Harris

One of the little bugaboos that got me a lot my first N years of doing
Perl was that {m,} is a quantifier meaning m or more, but {,n} is *not*
a quantifier meaning up to n.  People like symmetry, and it seems
logical that {,n} would DWIM, but it doesn't.  I still make the mistake on
occassion.

I can only think of one reason to disallow it (unless there's a parsing
issue somewhere that I can't immediately see): some people might expect
DWIM behavior to be implicit M=0, and others might expect M=1.  But I
honestly don't see that as compelling--if you read {m,} as m or more,
and {,n} as n or less, then I think M should clearly default to 0.

Is there something I'm missing here?  If not, why not add some DWIMiness
and make {,n} work?

Trey
-- 
Trey Harris
Secretary and Executive
SAGE -- The System Administrators Guild (www.sage.org)
Opinions above are not necessarily those of SAGE.





Re: Why not {,n} in quantifiers?

2002-05-14 Thread Larry Wall

Trey Harris writes:
: One of the little bugaboos that got me a lot my first N years of doing
: Perl was that {m,} is a quantifier meaning m or more, but {,n} is *not*
: a quantifier meaning up to n.  People like symmetry, and it seems
: logical that {,n} would DWIM, but it doesn't.  I still make the mistake on
: occassion.
: 
: I can only think of one reason to disallow it (unless there's a parsing
: issue somewhere that I can't immediately see): some people might expect
: DWIM behavior to be implicit M=0, and others might expect M=1.  But I
: honestly don't see that as compelling--if you read {m,} as m or more,
: and {,n} as n or less, then I think M should clearly default to 0.
: 
: Is there something I'm missing here?  If not, why not add some DWIMiness
: and make {,n} work?

It's unlikely that {n,m} will still have that meaning in Perl 6.  Maybe we'll
have something like this:

Perl 5  Perl 6
{1,3}   1..3
{3} 3
{3,}3+
{0,3}   3-

Then again, maybe not...

Larry