[Aldor-l] recursive polynomial
Christian Aistleitner
tmgisi at gmx.at
Mon Jul 31 02:51:52 EDT 2006
Hello,
On Sat, 29 Jul 2006 16:39:44 +0200, Preininger <d.i.preininger at tele2.at>
wrote:
> hello
>
> I need a recursive datastructure for a multivariate polynomial in aldor
> 1.0.2 (without algebra).
> Something like:
>
> Record(variable:String,List(Record(exponent:MachineInteger,factor:Union(%,fa
> ct:Integer))))
>
> I am not able to compile a new function, like new("x",2,5) - any idea?
I tried it out myself and did come across any problems:
#include "aldor"
Poly: with {
new: (String, MachineInteger, Integer ) -> %;
var: % -> String;
} == add {
--------------------------------------------------
FACT == Union( rec: %, fact: Integer);
EXP == Record( exponent:MachineInteger, factor: FACT );
EXPS == List( EXP );
Rep == Record( variable:String, exp: EXPS );
--------------------------------------------------
import from FACT;
import from EXP;
import from EXPS;
import from Rep;
--------------------------------------------------
new( v: String, e: MachineInteger, f: Integer ): % == {
per record( v, [ record( e, union f ) ] );
}
--------------------------------------------------
var( a: % ): String == {
( rep a ) . variable;
}
--------------------------------------------------
}
import from String;
import from MachineInteger;
import from Integer;
import from Poly;
new( "x", 2, 5 );
import from TextWriter;
import from Character;
stdout << (var new( "x", 2, 5 )) << newline;
____________________________________________
tmgisi at spencer
cwd: ~
$ LC_ALL=C /opt/aldor/bin/aldor -M no-abbrev -C args=-Wopts=-m32 -Ffm -Fx
-lalgebra -laldor test2.as && ./test2
cc1: note: -fwritable-strings is deprecated; see documentation for details
cc1: note: -fwritable-strings is deprecated; see documentation for details
x
Maybe some notes about:
> Record(variable:String,List(Record(exponent:MachineInteger,factor:Union(%,fa
> ct:Integer))))
You'd probably want to import from
Union( %, fact: Integer )
, from
Record( exponent: MachineInteger, Union( %, fact: Integer ))
, and so on. Therefore, I converted these item to constants. Fucthermore
you did not supply a name for the element of type % in the Union. Neither
for the element of type List(...) in the top-level Record. These kind of
omission typically cause compiler troubles sooner or later. I'd suggest
giving a name to every field within a Record or Union (See my working
example above).
--
Kind regards,
Christian
More information about the Aldor-l
mailing list