axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Axiom-developer] about Expression Integer


From: Ralf Hemmecke
Subject: Re: [Axiom-developer] about Expression Integer
Date: Fri, 24 Feb 2006 15:14:49 +0100
User-agent: Thunderbird 1.5 (X11/20051201)

Hi Bill,

(4) -> Z:Float:=1

   (4)  1.0
   Type: Float

(5) -> Z::INT        <---- this is a conversion of Float to INT

   (5)  1
   Type: Integer

Now, I learned something new. And maybe Axiom behaves here different from Aldor.

In Aldor "Z::Integer" is just syntactic sugar for writing
"coerce(Z)@Integer" (which looks for a function

coerce: Float -> Integer

currently in scope and applies it).

In Aldor there is (almost) never a coercion (type cast) done automatically. Of course you can write something like

aldor -gloop
#include "aldor"
#include "aldorinterp"
Z:SingleFloat := 1;

But there is no coercion involved. Since SingleFloat is of type ArtithmeticType.

%10 >> SingleFloat has ArithmeticType
T @ Boolean
%11 >> ArithmeticType
 @ Category == AdditiveType with
        1: %
        *: (%, %) -> %
        ^: (%, MachineInteger) -> %
        commutative?: Boolean
        one?: % -> Boolean
        times!: (%, %) -> %
        default
                local copy?: Boolean == % has CopyableType
                one?(a: %): Boolean == ..
                times!(a: %, b: %): % == ..

The 1 is simply interpreted as the constant 1 in SingleFloat.

Now the following is also clear.

%14 >> Z := 2
       .....^
[L14 C6] #1 (Error) No meaning for integer-style literal `2'.
%15 >> Z:=2.0
2 @ SingleFloat
%16 >> import from Integer
%17 >> Z := 2
       .....^
[L17 C6] #1 (Error) There is no suitable interpretation for the expression 2
  The context requires an expression of type SingleFloat.
     The possible types of the right hand side (`2') are:
          -- AldorInteger

I like that Aldor does nothing automatically.

Ralf

PS: To be correct there is one case that comes to my mind where the Aldor compiler is a bit more relaxed.
See "Curtesy conversions" at
http://www.aldor.org/docs/HTML/chap7.html#6




reply via email to

[Prev in Thread] Current Thread [Next in Thread]