Thomas Sandlaß wrote:

Patrick R. Michaud wrote:

On Wed, Apr 27, 2005 at 08:46:53AM -0400, Joshua Gatcomb wrote:

The problem is that in the regex version I use capturing parens to
identify the character matched.  For the purposes of the problem I
don't need to rely on the first character matched I just need to know
1.

Without doing a lot of research into junctions, I thought the
following would work:

my $matches = any( @x_chars ) eq any( @y_chars );
my $match = $matches.pick;



Perhaps the easiest way to explain the difficulty here is to note that executing a relational op (i.e. returning a boolean) value on a junction argument returns a junction of boolean values.


Is that so? Does Perl6 have some fundamental law of junction preservation?
I would expect $matches to be either false or true---the junction values
are garbage collected.

You're both right.

The junction of junctions of bools gets created from the threading... and then gets collapsed into a single bool, based on the predicates. ("any" in all cases here).


...  or if it could "pick" one of the empty
string values.


That's my understanding. The junctive value is lazily evaluating the
list of all permutations from @x_chars and @y_chars one at a time.
The myeq is called once for .pick and the result goes into $match.

I'm pretty sure the ".pick" would return one of the junctions of chars/empty strings. You could do a ".pick.pick" to get a single result back out. However, you'd be stuck with all the empty strings again. I think you'd likely want something like

   $matches.values».values.grep:{$_ ne ''}

but if you're going through that much trouble, just do:

   @matches = @x_chars.grep:{$_ ~~ @y_chars};

and be done with it.



It's been established before that getting at _which_ values in a junctions made the evaluation turn one way or the other is _not_ something that will be readily supported.

-- Rod Adams

Reply via email to