On Fri, Dec 10, 2004 at 08:50:46PM +0100, Leopold Toetsch wrote:
> >> We need language lawyers ;)
> 
> > IANAL, but I am a mathematician.    Because C<xor> necessarily always
> > depends on *both* its arguments, analogies with C<and> and C<or> are
> > inappropriate.    C<xor> cannot short-circuit, and it is not sensible
> > to return as result either of the arguments.
> 
> 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.
    
> > Perl5 C<xor> always returns a "standard" boolean value, i.e.
> > dualvar(0, '') or dualvar(1, '1').    Perl6/Parrot should do the same
> > thing.

Keep in mind that in Perl 6 the boolean forms of C<and>, C<or>, and C<xor>
(the ones that always return 0 or 1)  are  C<?&>, C<?|>, and C<?^>.  
So perhaps C<xor> should be able to return more than just 0 or 1.

Pm

Reply via email to