Re: A5: a few simple questions

2002-06-06 Thread Damian Conway

David Whipp wrote:
 
 First, a slight clarification: if I say:
 
   m:w/ %foo := [ (\w+) = (\w+) [ , (\w+) ]* ] /
 
 does this give me a hash of arrays? (i.e. is the rhs of a hash processed as
 a scalar context)

That's an error. The grouping bound to a hypothetical hash has to have
either exactly one or exactly two captures in it. To get what you want 
you'd need something like:

rule wordlist { (\w+) [ , (\w+) ]* }
m:w/ %foo := [ (\w+) = (wordlist) ] /

or just:

m:w/ %foo := [ (\w+) = ({ /(\w+) [ , (\w+) ]*/ }) ] /



 When I look at this, I see a common pattern: the join/split concept. It
 feels like there should be a standard assertion:

These are good ideas for assertions. If they don't become standard, it will
certainly be possible to write a module that makes them available.


 And a question about m,n (I think something similar came up a few weeks
 ago): why isn't it m..n, i.e. a list of the numbers of matches allowed.
 This seems to be the only place in perl6 where a list of numbers, as a
 range, isn't constructed using the .. operator.

Because a m,n isn't a list of numbers. It's the lower and upper bounds on a
repetition count.

Damian



Re: A5: a few simple questions

2002-06-06 Thread John Siracusa

On 6/6/02 2:43 AM, Damian Conway wrote:
   rule wordlist { (\w+) [ , (\w+) ]* }

No semicolon at the end of that line?  I've already forgotten the new
rules for that type of thing... :)

-John




Re: A5: a few simple questions

2002-06-06 Thread Allison Randal

On Thu, Jun 06, 2002 at 10:38:39AM -0400, John Siracusa wrote:
 On 6/6/02 2:43 AM, Damian Conway wrote:
rule wordlist { (\w+) [ , (\w+) ]* }
 
 No semicolon at the end of that line?  I've already forgotten the new
 rules for that type of thing... :)

No, because rules are basically methods, just like grammars are
basically classes. You would only need a semi-colon if you were defining
an anonymous Crule (similar to an anonymous Csub):

my $wordlist = rule { (\w+) [ , (\w+) ]* };

Allison



Re: A5: a few simple questions

2002-06-06 Thread Piers Cawley

Allison Randal [EMAIL PROTECTED] writes:

 On Thu, Jun 06, 2002 at 10:38:39AM -0400, John Siracusa wrote:
 On 6/6/02 2:43 AM, Damian Conway wrote:
rule wordlist { (\w+) [ , (\w+) ]* }
 
 No semicolon at the end of that line?  I've already forgotten the new
 rules for that type of thing... :)

 No, because rules are basically methods, just like grammars are
 basically classes. You would only need a semi-colon if you were defining
 an anonymous Crule (similar to an anonymous Csub):

   my $wordlist = rule { (\w+) [ , (\w+) ]* };

You wouldn't even need it then. Assuming you're following the closing
brace with nothing but white space and a newline.

-- 
Piers

   It is a truth universally acknowledged that a language in
possession of a rich syntax must be in need of a rewrite.
 -- Jane Austen?




Re: A5: a few simple questions

2002-06-06 Thread Allison Randal

On Thu, Jun 06, 2002 at 08:21:25PM +0100, Piers Cawley wrote:
 Allison Randal [EMAIL PROTECTED] writes:
 
  No, because rules are basically methods, just like grammars are
  basically classes. You would only need a semi-colon if you were defining
  an anonymous Crule (similar to an anonymous Csub):
 
  my $wordlist = rule { (\w+) [ , (\w+) ]* };
 
 You wouldn't even need it then. Assuming you're following the closing
 brace with nothing but white space and a newline.

I guess you're talking about the bit of A4 to do with When do I put a
semicolon after a curly?. But that is if the final curly is on a line
by itself. So you could get away with:

my $wordlist = rule { 
(\w+) [ , (\w+) ]* 
}

Allison



A5: a few simple questions

2002-06-05 Thread David Whipp

First, a slight clarification: if I say:

  m:w/ %foo := [ (\w+) = (\w+) [ , (\w+) ]* ] /

does this give me a hash of arrays? (i.e. is the rhs of a hash processed as
a scalar context) 

When I look at this, I see a common pattern: the join/split concept. It
feels like there should be a standard assertion:

  m:w/ %foo := [ (\w+) = split , (w+) ] /
..

Another useful assertion might the the long form of m,n repeat count:

  m:w/ list := (\w+) repeat grep { even } 0..Inf ] /

to match an even number of words.

And a question about m,n (I think something similar came up a few weeks
ago): why isn't it m..n, i.e. a list of the numbers of matches allowed.
This seems to be the only place in perl6 where a list of numbers, as a
range, isn't constructed using the .. operator.


Dave.

--
Dave Whipp, Senior Verification Engineer,
Fast-Chip inc., 950 Kifer Rd, Sunnyvale, CA. 94086
tel: 408 523 8071; http://www.fast-chip.com
Opinions my own; statements of fact may be in error.