Re: [Axiom-mail] Assigning to Element of Array of Records Doesn't Seem to Work
Ralf Hemmecke <[email protected]>
| Newsgroups | gmane.comp.mathematics.axiom.devel,gmane.comp.mathematics.axiom.user |
|---|---|
| Message-ID | <[email protected]> |
I think you have just found a bug in the Axiom interpreter/compiler.
The following Aldor program compiles fine.
aldor -fx -laldor aaa.as
and gives as output
xs = [
[0, 0]
[0, 0]
[10, 0]
]
ys = [
[0, 0]
[0, 0]
[10, 0]
]
Don't be distracted by this output stuff (TextWriter). Your code
basically appears in the main() function. And in Aldor that works.
Since this special form of assignment is actually a call to the function
set! (Aldor) the line
ys(2).k := 10;
is equivalent to
set!(ys(2), k, 10);
There is no problem with the actual form of the first argument of set!.
As long as there is a function
set!: (R, Enumeration(k: Type), INT) -> INT
that should compile fine. Well, and "ys(2)" is of type R.
(Of course, all this is Aldor specific, but Axiom should try hard to get
close.)
I have no idea, though, why Axiom is unable to deal correctly with that
expression. That should be dealt with by our compiler experts.
Ralf
---BEGIN aaa.as
#include "aldor"
#include "aldorio"
INT == MachineInteger;
R ==> Record(k: INT, rad: INT);
import from R, INT;
initrec(): R == [0,0];
(tw: TextWriter) <= (r: R): TextWriter == {
tw << "[" << r.k << ", " << r.rad << "]"
}
(tw: TextWriter) << (g: Generator R): TextWriter == {
tw << "[" << newline;
for r in g repeat tw << " " <= r << newline;
tw << "]" << newline;
}
main(): () == {
xs: List R := [initrec() for i in 1..3];
ys: Array R := [z for z in xs];
ys(2).k := 10;
stdout << "xs = " << generator xs << newline;
stdout << "ys = " << generator ys << newline;
}
main();---END aaa.as
On 08/08/2007 11:41 AM, Bill Wood wrote:
> I'm just trying to assign to a field of a record in a one-dimensional
> array of records, but I get this incomprehensible message:
> =====================================================================
> (1) -> )clear all
> All user variables and function definitions have been cleared.
> (1) -> )read foo.input
> -- File of Axiom definitions solving problem 124.
> -- Created 2007/08/08 by Bill Wood.
>
> init_rec() ==
> r : Record(k: INT, rad: INT) := [0,0]
> r
>
> Type: Void
> (2) -> xs := [init_rec() for i in 1..3]
> Compiling function initrec with type () -> Record(k: Integer,rad:
> Integer)
>
> (2) [[k= 0,rad= 0],[k= 0,rad= 0],[k= 0,rad= 0]]
> Type: List Record(k: Integer,rad: Integer)
> (3) -> ys := oneDimensionalArray(xs)
> (3) ->
> (3) [[k= 0,rad= 0],[k= 0,rad= 0],[k= 0,rad= 0]]
> Type: OneDimensionalArray Record(k: Integer,rad: Integer)
> (4) -> ys
> (4) ->
> (4) [[k= 0,rad= 0],[k= 0,rad= 0],[k= 0,rad= 0]]
> Type: OneDimensionalArray Record(k: Integer,rad: Integer)
> (5) -> ys(2).k := 10
> 5) ->
> The form on the left hand side of an assignment must be a single
> variable, a Tuple of variables or a reference to an entry in an
> object supporting the setelt operation.
> (5) ->
> =======================================================================
> What do I have to do to set the fields of the records to desired
> values???
>
> -- Bill Wood