Re: S5 - Question about repetition qualifier

2006-04-26 Thread Larry Wall
On Wed, Apr 26, 2006 at 11:36:50AM +0100, [EMAIL PROTECTED] wrote:
: Possibly we should make the syntax be a smart match, but only require that
: conformat implementations implement ranges and integers.

That is essentially the intent of the current spec, and why we defined
**{} to run a closure.  It may well be trivial to make it a smart
match by 6.0.0 since we've got smart matches elsewhere.  But the
regex engine also has to be low-level enough to bootstrap Perl 6.
On the other hand, there's no need to define a limited language--the
bootstrap can just use a subset of Perl 6 by convention.  If I had to
guess, I'd say it's actually quite likely to smartmatch by 6.0.0.

Larry


Re: S5 - Question about repetition qualifier

2006-04-26 Thread james
On Tue, Apr 25, 2006 at 09:57:58PM -0400, Joe Gottman wrote:
> According to Synopsis 5, the repetition qualifier is now **{.} where the .
> must correspond to either an Int or a Range.  This seems rather restrictive.
> Why are we not allowed a junction of Ints, for instance 
> 
> m/^ a**{1|3|5} $/ ; # Match 1,3, or 5 a's.

It would seem to me that the Right Thing is for the closure to return
something to ~~ against.  However, this obviously means that the regex
engine is going to have a harder time optimizing, and be somewhat more
complex, since it has to keep calling out to the smartmatcher.

Possibly we should make the syntax be a smart match, but only require that
conformat implementations implement ranges and integers.

 -=- James Mastros


Re: S5 - Question about repetition qualifier

2006-04-26 Thread Markus Laire
On 4/26/06, Joe Gottman <[EMAIL PROTECTED]> wrote:
> According to Synopsis 5, the repetition qualifier is now **{.} where the .
> must correspond to either an Int or a Range.  This seems rather restrictive.
> Why are we not allowed a junction of Ints, for instance

S05 also says:

It is illegal to return a list, so this easy mistake fails:
 / [foo]**{1,3} /
(At least, it fails in the absence of use rx :listquantifier, which is
likely to be unimplemented in Perl 6.0.0 anyway).


So it seems only reason not to allow lists is that they aren't yet
implemented, and likely won't be for some time.

> Also, I don't know exactly what the syntax looks like, but I can imagine
> using a repetition qualifier that takes a closure of some sort, for instance
> to match an odd number of repetitions
> m/^ a**{($_ % 2 == 0)} $/; #I'm not sure about the syntax for the code.

Are you reading some old version of S05?
http://dev.perl.org/perl6/doc/design/syn/S05.html says that "The
repetition specifier is now **{...} for maximal matching, with a
corresponding **{...}? for minimal matching. Space is allowed on
either side of the asterisks. The curlies are taken to be a closure
returning an Int or a Range object. "

So you can just put any closure which returns Int or Range directly
within the curlies.

--
Markus Laire


Re: S5 - Question about repetition qualifier

2006-04-25 Thread Juerd
Jonathan Scott Duff skribis 2006-04-25 23:35 (-0500):
> I get your point though.  There's no easy way to say "match 1, 7, 12, or
> 19" with this particular syntax.  
> How often does that come up in practice though?  I don't think I've
> ever wanted something like that.

Quite often. A silly example:

$hex_wep_key ~~ /^ **{10|26} $/


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html


Re: S5 - Question about repetition qualifier

2006-04-25 Thread Jonathan Scott Duff
On Tue, Apr 25, 2006 at 09:57:58PM -0400, Joe Gottman wrote:
> According to Synopsis 5, the repetition qualifier is now **{.} where the .
> must correspond to either an Int or a Range.  This seems rather restrictive.
> Why are we not allowed a junction of Ints, for instance 
> 
> m/^ a**{1|3|5} $/ ; # Match 1,3, or 5 a's.

m/^ a**{1..5:by(2)} $/; # Match 1, 3 or 5 a

> This does not seem noticeably more difficult than a range.  
> 
> Also, I don't know exactly what the syntax looks like, but I can imagine
> using a repetition qualifier that takes a closure of some sort, for instance
> to match an odd number of repetitions
> 
> m/^ a**{($_ % 2 == 0)} $/; #I'm not sure about the syntax for the code.

m/^ a**{1..*:by(2)} $/; # match an odd number of a

:-)

I get your point though.  There's no easy way to say "match 1, 7, 12, or
19" with this particular syntax.  

How often does that come up in practice though?  I don't think I've
ever wanted something like that.

If we allow "Junction of Int" that also gets us "Set of Int" as
Junctions are just funny Sets. Why not "Array of Int" too?

-Scott
-- 
Jonathan Scott Duff
[EMAIL PROTECTED]