On Thu, May 15, 2008 at 6:02 AM, Gabriel Dos Reis wrote:
> Ralf Hemmecke writes:
>
> | > If the scope of 'x' is intended to be global, then the type of 'x'
> | > must be a Union.
> | > x:Union(Integer,Float)
> | > if cond then
> | > x := 1
> | > else
> | > x := 2.3
> |
> | Of course that cannot work. What function pointer for
> | multiplication should the compiler put in for the following
> |
> | x := x*x
> |
> | ? Union does not export a multiplication.
>
> True, and given that why
>
> x := x * x
>
> would have to be valid at all?
>
??? No, it is not true. I guess you didn't try it before you wrote ... :-)
The code example I provided works as advertised in both the
interpreter and the SPAD compiler:
(1) -> x:Union(Integer,Float)
Type: Void
(2) -> if 0<1 then x:=1 else x:=2.3
(2) 1
Type: Union(Integer,...)
(3) -> x := x*x
(3) 1
Type: Union(Integer,...)
(4) -> if 1<0 then x:=1 else x:=2.3
(4) 2.3
Type: Union(Float,...)
(5) -> x := x*x
(5) 5.29
Type: Union(Float,...)
---------
For the compiler see:
http://axiom-wiki.newsynthesis.org/SandBoxLexicalScope#bottom
\begin{spad}
)abbrev domain BBB Bbb
Bbb: with
foo: Integer -> Integer
== add
foo(a: Integer): Integer ==
x:Union(Integer,Float)
if a>0 then
x := 1
else
x := 2.3
x case Integer => (x*x)::Integer
wholePart(x*x)
\end{spad}
\begin{axiom}
foo(0)
foo(1)
\end{axiom}
This outputs 5 and 1 respectively. Even the compiler is smart enough
to select the right * operation given enough context.
Regards,
Bill Page.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
open-axiom-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/open-axiom-devel