Opinions needed on neg and absolute
Paul C. Anagnostopoulos
paul at windfall.com
Mon Aug 30 23:22:09 UTC 2010
At 8/30/2010 07:12 PM, Joshua Juran wrote:
>On Aug 30, 2010, at 3:45 PM, Paul C. Anagnostopoulos wrote:
>
>>As an example of a PMC that inherits from Integer and might rely on
>>the current behavior, I give you Boolean. It inherits 'neg' and
>>relies on the fact that it does not promote to implement the
>>following bizarre behavior:
>>
>>-(Boolean true) => true
>>-(Boolean false) => false
>>
>>I will simply implement 'neg' in Boolean to preserve this whackiness.
>
>What's so odd about that? If you think of 'false' as zero, then the
>inverse of zero equals zero (false) and the inverse of any non-zero
>integer is non-zero (true, e.g. 1 -> -1). Though if Boolean is a one- bit integer, it must be an unsigned type, and -true will wrap around
>to true anyway.
I don't think of booleans as integers, so negating them is incoherent. But let's not get into that religious war.
I agree that if you think of 0 as false and everything else as true, then negating a boolean should not change its value. But providing negation for booleans is just another way to end up with obscure and possibly buggy code.
~~ Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.parrot.org/pipermail/parrot-dev/attachments/20100830/fde22f18/attachment.html>
More information about the parrot-dev
mailing list