On Mon, May 09, 2005 at 09:14:02AM -0700, Larry Wall wrote:
> :      m/ <alt: tea>  (don't) (ray) (me) (for) (solar tea), (d'oh!)
> :       | <alt: BEM>  (every) (green) (BEM) (devours) (faces)
> :       /;
> 
> This seems like a rather ugly syntax for what is essentially a label,
> or a <null> rule.  I wonder if we can come up with something a little
> prettier.  

I wonder if it's deserving of much in the way of special syntax at all,
given that we have a variety of ways to do it (closures come to mind).  
In the example above, one could just as easily test $1 for "don't" vs.
"every" to figure out which alternation matched.  Indeed, a simple answer
is:

     m/ $<tea>:=<null>  (don't) (ray) (me) (for) (solar tea), (d'oh!)
      | $<bem>:=<null>  (every) (green) (BEM) (devours) (faces)
      /;

and then 

    if ($/<tea>) { say "I hate solar tea" }
    if ($/<bem>) { say "I love bug-eyed monsters" }

But from your examples:

>      m/ <null:tea>  (don't) (ray) (me) (for) (solar tea), (d'oh!)
>       | <null:BEM>  (every) (green) (BEM) (devours) (faces)
>       /;

Hmm, capturing to $<null> seems odd.

>      m/ <tea:=>  (don't) (ray) (me) (for) (solar tea), (d'oh!)
>       | <BEM:=>  (every) (green) (BEM) (devours) (faces)
>       /;

Please, not this one -- it looks too much like a subrule call to
tea("=") (from A05).

>      m/ <:tea>  (don't) (ray) (me) (for) (solar tea), (d'oh!)
>       | <:BEM>  (every) (green) (BEM) (devours) (faces)
>       /;

This one has possibilities.   It looks like a generalization of
pair constructors though, so one could also conceivably do things
like  <:tea(0)> and <:tea('foo')>.  With that one could then write

     m/ <:alt('tea')>  (don't) (ray) (me) (for) (solar tea), (d'oh!)
      | <:alt('BEM')>  (every) (green) (BEM) (devours) (faces)
      /;

and have

    given $<alt> {
        when 'tea' { say "I hate solar tea" }
        when 'BEM' { say "I love bug-eyed monsters" }
    }

> or even plain label syntax:
> 
>      m/ tea: (don't) (ray) (me) (for) (solar tea), (d'oh!)
>       | BEM:  (every) (green) (BEM) (devours) (faces)
>       /;
> 
> if we recognize that : makes no sense as a backtrack control on a
> non-quantified item.

This sounds too "special-case" to me.  Also, I think it does make
sense to backtrack control on non-quantified subrules and subpatterns,
so we'd have to say that : has this meaning only after a non-quantified
literal.  I feel there are too many other good ways to do it to
add this one.

Pm

Reply via email to