> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of Steven D'Aprano
> Sent: Saturday, January 05, 2008 7:01 PM
> To: python-list@python.org
> Subject: Re: dictionary/hash and '1' versus 1
> 
> The problem with automatic conversions between strings and integers is
> that it isn't clear what the user wants when they do something like
> this:
> 
> >>> x = '1' + 1
> 
> Should x be the string '11' or the int 2? Please justify your answer.
> 
> 
> On the other hand, if the language includes separate operators for
> addition and concatenation (say, + and &) then that sort of auto-
> conversion is no longer ambiguous:
> 
> >>> '2' + 3
> 5
> >>> '2' & 3
> '23'


Bingo.  Perl has specific operators to establish intent:
        > Perl -e "'1' + 1"
        > 2
        > Perl -e "'1' . 1"
        > 11
'+' is the operator for addition
'.' is the operator for string concatenation

int and string comparisons also have specific operators:
        $a == $b  # compare as integers:  ==,  >,  <, <=, >=
        $a eq $b  # compare as strings:   eq, gt, lt, le, ge


Which now morphs the conversation into the issue of how too much
operator overloading creates confusion and/or ambiguity.



*****

The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential, proprietary, and/or privileged 
material. Any review, retransmission, dissemination or other use of, or taking 
of any action in reliance upon this information by persons or entities other 
than the intended recipient is prohibited. If you received this in error, 
please contact the sender and delete the material from all computers. GA623


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to