[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Axiom-developer] RE: [Aldor-l] exports and constants
From: |
Bill Page |
Subject: |
[Axiom-developer] RE: [Aldor-l] exports and constants |
Date: |
Sun, 23 Jul 2006 22:01:25 -0400 |
On July 21, 2006 2:38 AM Christian Aistleitner wrote:
> ...
> Ralf wrote:
> >
> > X: CatX == if true then (A add) else (B add); -- (*)
> > ...
> > That is clear, but why does the compiler reject the program
> > without the "add" in line (*)?
>
> I'd consider that a bug in comparison of exports. Replacing
> your (*) line by
>
> X: CatX == if true then (address@hidden) else (address@hidden);
>
> gives a working program with output
>
> X has CatA: T
> X has CatB: F
> X has CatX: T
>
Wow! Nice. And
X: CatX == if false then (address@hidden) else (address@hidden);
gives
X has CatA: F
X has CatB: T
X has CatX: T
That's excellent.
> So the problem (wild guess) is that the compiler Has problems
> with seeing that the if statement gives CatX in both branches
> of the if statement. Mainly because the types of A and B aro
> not equal. However, you can hint the compiler. My code is telling
> him "The if part gives CatX and the else part gives CatX". Then
> the compiler can infer, that the whole "if" statement gives
> CatX. And it is at least the type of X (which is CatX). So it
> matches.
>
I accept your argument and withdraw (most) of my comments about
static types in my previous message.
> ...
> > But what about...
> >
> > ---BEGIN aaa3.as
> > #include "aldor"
> > import from String, TextWriter, Character, MachineInteger;
> >
> > define CatA: Category == with;
> > define CatB: Category == with;
> > define CatX: Category == with;
> >
> > A: Join(CatX, CatA) == add;
> > B: Join(CatX, CatB) == add;
> >
> > MyPkg(X: CatX): with {isA?: () -> Boolean} == add {
> > isA?(): Boolean == X has CatA;
> > }
> > main(): () == {
> > import from CommandLine, Array String;
> > X: CatX == if zero? #arguments then (A add) else (B add);
> > stdout << isA?()$MyPkg(X) << zero? #arguments << newline;
> > }
> > main();
> > ---END aaa3.as
> >
> > >aldor -fx -laldor aaa3.as
> > >aaa3
> > FT
> > >aaa3 1
> > FF
> >
> > It is clear with the "add" in the definition of X that we
> > will always see a F in the first column of the output. Can
> > someone find a "nice" construction where X is defined by a
> > similar "if" construction and the first F would turn into T?
>
> Of course. Again, be nice to the compiler. He is old. He is
> buggy. He is a bit rusty on the edges. And he is locked in,
> in a jail of non-free source code.
Hear, hear! Please, let's find a way to free him! :-)
> But help him. Do not force him to do extra work. Tell
> him what you know, if he needs to be told.
>
> X: CatX == if zero? #arguments then (address@hidden) else (address@hidden);
>
> does the trick for me:
>
> LC_ALL=C /opt/aldor/bin/aldor -M no-abbrev -C args=-Wopts=-m32
> -Fx -lalgebra -laldor aaa3.as && ./aaa3 && ./aaa3 xx
> cc1: note: -fwritable-strings is deprecated; see
> documentation for details
> cc1: note: -fwritable-strings is deprecated; see
> documentation for details
> TT
> FF
>
That is quite fantastic to me. It means that the value of the
"constant" X is not determined at compile time. I did not expect
this to be possible. This variant also works is even better:
main4(n:Integer): Boolean == {
X: CatX == if zero? n then (address@hidden) else (address@hidden);
isA?()$MyPkg(X);
}
main4(0)
main4(1)
But then I must realize that X is local to main4, so in the
dynamic invocation context of main4 X is still "constant".
http://wiki.axiom-developer.org/SandBoxAldorSemantics
> ...
> I hope we both deem my solution to be "nice" :)
>
Very Nice, indeed!
Regards,
Bill Page.
- [Axiom-developer] RE: [Aldor-l] exports and constants, (continued)
- [Axiom-developer] Re: [Aldor-l] exports and constants, Christian Aistleitner, 2006/07/25
- [Axiom-developer] Re: [Aldor-l] exports and constants, Ralf Hemmecke, 2006/07/25
- [Axiom-developer] Re: [Aldor-l] exports and constants, Christian Aistleitner, 2006/07/26
- [Axiom-developer] Re: [Aldor-l] exports and constants, Christian Aistleitner, 2006/07/25
- [Axiom-developer] Re: [Aldor-l] exports and constants, Ralf Hemmecke, 2006/07/24
[Axiom-developer] Re: [Aldor-l] exports and constants, Christian Aistleitner, 2006/07/21
[Axiom-developer] RE: [Aldor-l] exports and constants,
Bill Page <=
[Axiom-developer] Re: [Aldor-l] exports and constants, Ralf Hemmecke, 2006/07/24