Rod Adams <[EMAIL PROTECTED]> writes:

>     $re1 = /^ <-[x]>* x <-[x]>* $/; # match a string with exactly one
> 'x' in it.
>     $re2 = /^ <-[y]>* y <-[y]>* $/; #  ditto 'y'
>     $re3 = /^ <-[z]>* z <-[z]>* $/; #  ditto 'z'

>     $re7 = none($re1, $re2, $re3); # matches if there are 0 or 2+ of
> each of x,y,z.

> #7 I have no idea how to attack as a single RE in anything close to
> approaching elegance.

  Depending on your idea of elegance ... anchored zero-width negative
lookahead:

$re7 = qr/^ (?!= $re1 | $re2 | $re3 ) /x;

  Oh right.  Perl6.  Well, if I understand "<$re1>" correctly, I think
this is what it will look like:

$re7 = /^ <!before <$re1> | <$re2> | <$re3> > /;


  I still want junctions, but I also still am not quite sure how they
will behave.  For instance, I wonder how this would autothread or not:

my sub f (Int $x) {
  if $x {
    return 0, 1, $x;
  }
  else {
    return 0, 1;
  }
}

my $j = 0 | 7;
my @a = (1, f($j), 0);

  - How many elements are there in @a?  3? 5? 4|5?

  - What is @a[-1]?  0?  any(0)?  0|undef?

  - What is @a[4]?  undef?  0|undef?  0?

  Na�vely, I would expect that setting of @a be equivalent to this:

my @a = (1, ([0,1]|[0,1,7]), 0);

  And so from the callers perspective, &f, which usually returns two
or three values, suddenly returns a single (junctive) value.  New
semantics for &f, courtesy of autothreading.  I expect this is too
na�ve.  But what am I missing?


Eirik
-- 
All bridge hands are equally likely, but some are more equally likely
than others.
                -- Alan Truscott

Reply via email to