Eirik Berg Hanssen wrote:

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> > /;


That doesn't quite do it, but something along those lines is possible. You'd have to make sure the look ahead/behinds match to the end of the string, not just some substring. And then you'd have to put in something to actually match the string. So possible, but not straightforward in the least.


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?


I believe you are correct in your analysis.

It's also something that I will cover as soon as I have time to write down the revelation I had about junctions laying in bed last night. (Don't cringe everyone. I actually figured out why Damian insists on implicit threading. And I agree with him. Now I want to clamp a completely different kind of restriction on Junctions.)

I might be able to find time for it late tonight. Might take a few days.

-- Rod Adams



Reply via email to