Rod Adams <[EMAIL PROTECTED]> wrote:
>  - Can junctions be used as array/hash subscripts?
> 
> In an rvalue context, this makes sense, in that you can simply return a
> junction of the deferences. But in an lvalue context, this gets dubious
> for everything except all() junctions. Consider:
> 
>     @x = 1..10;
>     @x[any(4,3)] = 7;
> 
> What does @x look like now?
> 
>     @x[all(4,3,2)] = 7;
> 
> makes sense, as long as it means:
> 
>     @x[4,3,2] »=« 7;
> 
> I don't want to even think about what:
> 
>     @x[none(1,2)] = 7;
> 
> does.

The naive meaning of all of these would be::

    any(map { @x[$_] = 7 } 4,3)
    all(map { @x[$_] = 7 } 4,3,2)
    one(map { @x[$_] = 7 } 1,2)
    none(map { @x[$_] = 7 } 1,2)

But I'm not sure the naive interpretation is correct.

>  - Can you have non-scalar junctions?
> 
> As the discussions surrounding C< .. > demonstrated, it's not that hard
> for someone to create a situation where a junction of lists might come
> into existence. But let's consider something a step beyond.
> 
>     %x = (a => 1, b => 2, c => 3) | (d => 4, e => 5, f => 6);
>     @y = %x.keys;
> 
> Does this explode, or does @y have something useful in it now?

Do junctive operators force scalar context on their arguments?  If so,
we know what happens (you get a junction of arrayrefs); if not, I
suppose it's up for negotiation.

>  - What does it mean to sort a list of junctions?
> 
>     @x = any(1,6), all(2,5), one(3,4);
>     @x = @x.sort;
> 
> Does sort() carp on junctions, or is it just one of the weird things you
> have to live with if you're playing with junctions?

Good question.  Spaceship and cmp aren't quite like the normal boolean
ops, unfortunately; I'm not quite sure what to do about that.

...actually...

Pretend for a moment that cmp is implemented exactly as:

    multi sub infix:<cmp> (Any|Junction $lhs, Any|Junction $rhs) {
        return -1 if $lhs lt $rhs;
        return 0  if $lhs eq $rhs;
        return 1  if $lhs gt $rhs;
    }

Then things compare this way:

   any(1,6) cmp all(2,5) = -1  (1 is less than both 2 and 5)
   all(2,5) cmp any(1,6) = 1 (both 2 and 5 are greater than 1)
   all(2,5) cmp one(3,4) = undef (no conditions match)
   one(3,4) cmp all(2,5) = undef (no conditions match)
   one(3,4) cmp any(1,6) = undef (no conditions match)
   any(1,6) cmp one(3,4) = undef (no conditions match)

Happily, all of these are commutative (is this generally true?), and
the C<undef>s would be treated as 0s.  So this actually would work,
although it would sort in an...interesting...order.

-- 
Brent 'Dax' Royal-Gordon <[EMAIL PROTECTED]>
Perl and Parrot hacker

"I used to have a life, but I liked mail-reading so much better."

Reply via email to