Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

S5 - Question about repetition qualifier

5 views
Skip to first unread message

Joe Gottman

unread,
Apr 25, 2006, 9:57:58 PM4/25/06
to Perl6
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.

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.

Joe Gottman


Jonathan Scott Duff

unread,
Apr 26, 2006, 12:35:27 AM4/26/06
to Joe Gottman, Perl6
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
du...@pobox.com

Juerd

unread,
Apr 26, 2006, 2:17:53 AM4/26/06
to perl6-l...@perl.org, Joe Gottman
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 ~~ /^ <hexdigit>**{10|26} $/

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

Markus Laire

unread,
Apr 26, 2006, 6:00:37 AM4/26/06
to jgot...@carolina.rr.com, Perl6
On 4/26/06, Joe Gottman <jgot...@carolina.rr.com> 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:
<quote>
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).
</quote>

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

ja...@mastros.biz

unread,
Apr 26, 2006, 6:36:50 AM4/26/06
to Joe Gottman, Perl6
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

Larry Wall

unread,
Apr 26, 2006, 11:52:29 AM4/26/06
to Perl6
On Wed, Apr 26, 2006 at 11:36:50AM +0100, ja...@mastros.biz 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

0 new messages