[ From p6i ]

Patrick R. Michaud writes:
> On Fri, Dec 10, 2004 at 08:50:46PM +0100, Leopold Toetsch wrote:
> > Not quite. It gives one value if one is true or 0 (false). This is more
> > information then the perl5 implementation returns. The returned value (if
> > any) is still true but usable, if I just want one of both. Well that's
> > "logical xor" - not binary xor.
> 
> Agreed.   At some point this probably belongs on perl6-languages (and
> apologies if this posting to p6i is therefore inappropriate).  But if
> the following hold (Perl 5):
> 
>     print (0 and "hello");    # outputs "0"
>     print ("" and "hello");   # outputs ""
>     print (0 or "hello");     # outputs "hello"
>     print ("" or "hello");    # outputs "hello"
>     print ("" or 0);          # outputs "0"
>     print (0 or "");          # outputs ""
>     print (not("" or 0));     # outputs "1"
>     print (not("a" and "b")); # outputs ""
> 
> it seems like one should be able to do:
> 
>     print (0 xor "hello");        # outputs "hello"
>     print ("" xor "hello");       # outputs "hello"
>     print ("hello" xor 0);        # outputs "hello"
>     print ("hello" xor "");       # outputs "hello"
>     print ("world" xor "hello");  # outputs ""
>     print (0 xor "");             # outputs "1"
>     print ("" xor 0);             # outputs "1"
> 
> Just as C<or> returns its first non-false argument, the interpretation
> of C<xor> would be that it returns its single non-false argument, or 1 if
> both (all?) arguments logically evaluate to false.

Well, IAAL. :-)

In particular, xor is analogous, operatorwise, to the junctive one().
one() represents its single true value when it evaluates to true in
conditionals:

    my $smin = one(3,6,9,12) < 5;

So it seems logical that xor do the same.  I don't see any loss of
generality in doing so, and you're keeping around more information.

For the PMC variant, it seems like returning *the* true PMC is the
correct thing to do, because the definiton of the canonical "true"
differs from language to language.  Parrot has a canonical false.

Luke

Reply via email to