On Fri, Apr 23, 2010 at 10:15 AM, bb <bblo...@arcor.de> wrote:

> Simon King schrieb:
>
>  Hi!
>>
>> On Apr 23, 2:05 pm, bb <bblo...@arcor.de> wrote:
>>
>>
>>> ...
>>> The second passage I found was at
>>>
>>> http://www.sagemath.org/doc/tutorial/programming.html
>>>
>>> ... When comparing objects of different types in Sage, in most cases
>>> Sage tries to find a canonical coercion of both objects to a common
>>> parent.
>>>
>>>
>>
>> I am translating the whole tutorial, so, you are right with both
>> passages you mention. IIRC there was a number of questions on sage-
>> support about coercion (understandably, I think). But the tutorial and
>> the "Sage constructions" don't seem to address it. Therefore I
>> consider to add a new section on conversion vs. coercion in tutorial/
>> programming (in English as well), apart from just translating.
>>
>> The notions of type conversion (in C), conversion (in Sage) and
>> coercion (in Sage) are distinct, but have a big semantic overlap.
>> "Being distinct and having a semantic overlap" means: One has to be
>> particularly careful in choosing sound notions in translation, or
>> confusion will rise.
>>
>> Examples:
>> 1) In C:
>>  int i = 10;
>>  char j;
>>  j = (char)i; // type conversion
>>
>>
> cast:
> Sorry, I only see that from a perspective of computer science/programming.
> The conversion in the example above is called "explicit  type conversion".
> That is done by "casting". In your example you used a C-like casting:
> (char)i;. In C++ there is also a functional casting possible:  char (i) -
> may be its possible in newer  C versions as well? And you assign that to a
> proper variable j. That is the way in strong-typed languages. If you try
> i=(char) i; you should get an error message. Very often people do not
> understand, that in the cast process the original type of the casted
> variable will be preserved! i is integer before and after casting!
>
> I know a lot of C literature and do not know any one calling any form of
> type conversion coercion! Because there is no implicit conversion in
> strong-typed languages possible. (Well, there are exceptions, i. e.
> short a=2000;
> int b;
> b=a;
> and in printing with printf() by format code.  That only holds, because you
> can always fit a short in an int, but the opposite is not true, and it is
> also not true for many other data types (see a C reference!).)
> sage: i=2000
> sage: float(i)
> 2000.0
> sage: i
> 2000
> sage: f=23.34
> sage: f
> 23.3400000000000
> sage: int (f)
> 23
> sage: f
> 23.3400000000000
> sage:
>
>
>
> coercion:
> is an implicit type conversion. Python/Sage are not strong-typed languages!
>


Actually, Python *is* strongly typed.   Instead of trying to explain the
meaning of terms such as "strongly typed", "dynamically typed", etc. I refer
the reader to Wikipedia [1].

 -- William

[1] http://en.wikipedia.org/wiki/Python_(programming_language)

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to