axiom-developer
[Top][All Lists]
Advanced

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

RE: [Axiom-developer] [MutualRecursion] (new)


From: Peter Broadbery
Subject: RE: [Axiom-developer] [MutualRecursion] (new)
Date: Tue, 18 Jan 2005 20:50:27 +0000

On Tue, 2005-01-18 at 13:43 -0500, Page, Bill wrote:
> Ralf,
> 
> On Tuesday, January 18, 2005 12:22 PM you wrote:
> > 
> > Do you find the attached file relevant?
> >
> 
> ----------
> 
> #include "aldor"
> #include "aldorio"
> 
> define Parity: Category == with {
>       parity: Integer -> Boolean;
> }
> 
> Odd: Parity == add {
>       parity(n:Integer): Boolean == {
>               (n>0) => parity(n-1)$Even;
>               (n<0) => parity(n+1)$Even;
>               false;
>       }
> }
> 
> Even: Parity == add {
>       parity(n: Integer): Boolean == {
>               n>0 => parity(n-1)$Odd;
>               n<0 => parity(n+1)$Odd;
>               true;
>       }
> }
> 
> main(): () == {
>       import from Integer;
>       stdout << "parity(   10)$Even=" << parity(  10)$Even << newline;
>       stdout << "parity(    8)$Odd =" << parity(   8)$Odd  << newline;
>       stdout << "parity(-1111)$Odd =" << parity(-111)$Odd  << newline;
> }
> 
> main();
> 
> -----
> 
> Yes I do find it very relevant. Thank you!
> 
> I have tried for about 1/2 an hour without success to write
> this same category in Axiom. Perhaps someone with more
> experience with the Axiom compiler can help?
>  
> > It actually compiles with Aldor 1.0.2 and runs with the output
> > 
> > aldor -grun -laldor EvenOdd.as
> > parity(   10)$Even=T
> > parity(    8)$Odd =F
> > parity(-1111)$Odd =T
> > 
> > I wonder how the Aldor compiler handles such mutual recursive 
> > structures. Perhaps Peter Broadbery knows.
> 
> I would also like to know.

[Disclaimer: I'm not an expert on the type checking bit - and if you
want info, it is nicer to ask]

The key is that they are in the same file.  Otherwise the compiler (at
least back in '9x) will complain that it does not know about the other
domain.  The compiler will first determine the exports of mutually
referencing types, then compile the bodies - the aldor language is a bit
more careful than spad about what types are in scope (via import, etc)
so it can determine mutual references fairly easily.  Within a file,
types are compiled in an order determined by the types each one uses,
not the textual order. Various langauge constructs (nested domains,
conditionals) make this a bit tricker, but apparently doable.

If you have a situation with mutually referencing domains in separate
files, then you have to use the extend keyword, and build the defn. up
in steps - there may well be an example or two of this in the aldor
library sources shipped with the compiler.

The problem then shifts to the cateogory level, which can't be
extended. 

> > 
> > Maybe this example is easy, because both domains are in the
> > same file> Do you know a good example where it makes sense
> > to put the domains much more away from each other?
> 
> I can not give a simple example right now but I suspect that
> this happens very frequently in Axiom's algebra.
> 

All over - try OutputForm as an example.

Peter






reply via email to

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