axiom-developer
[Top][All Lists]
Advanced

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

Re: [Axiom-developer] Bug in Tuple


From: Ralf Hemmecke
Subject: Re: [Axiom-developer] Bug in Tuple
Date: Tue, 28 Feb 2006 10:40:40 +0100
User-agent: Thunderbird 1.5 (X11/20051201)

On 02/27/2006 09:57 PM, Bill Page wrote:
Ralf,

On February 25, 2006 4:22 PM you wrote:
Can someone explain that?

Ralf

(6) -> Tuple(Integer) has coerce: Tuple(Integer)->PrimitiveArrayInteger

    (6)  false
Type: Boolean

I presume what you meant to write was:

  Tuple(Integer) has coerce:Tuple(Integer)->PrimitiveArray(Integer)

and that something like this might be possible in Aldor, right?

Well, I should have written something like

Tuple(Integer) has with {length: % -> MachineInteger}

but that doesn't work in Axiom either. And the reason in my eyes is that I cannot remember that there exists a description of SPAD/Axiom that covers something like http://www.aldor.org/docs/HTML/chap7.html#9.

But try in Aldor...

aldor -gloop
#include "aldor"
#include "aldorinterp"
%3 >> Tuple Integer
  () @ Join(
 with
    ==  add ()
,
 with
        element: (%, MachineInteger) -> AldorInteger
        dispose!: % -> ()
        length: % -> MachineInteger
        tuple: (MachineInteger, Pointer) -> %
    ==  add ()
)
T%4 >> Tuple(Integer) has with {length: % -> MachineInteger}
T @ Boolean

However the result the Axiom interpreter returns is still 'false'.

So far as I can tell from the available Axiom documentation the
'has' expression only allows categories and axioms on the right
hand side (rhs). So we can write:

  Tuple(Integer) has CoercibleTo(OuputForm)

and

  Integer has commutative("*")

but almost anything else on the rhs returns either 'false' or
an error message. You might have expected to be able to write:

(14) -> Tuple(Integer) has with Tuple(Integer)->PrimitiveArray(Integer)
   Internal Error
   Unexpected error in call to system function pf2Sex1

but that apparently doesn't work either. :(

Well, you probably meant:

Tuple(Integer) has with coerce: %->PrimitiveArray(Integer)

However, you agree, that the "with" expression *is* a category.

Just as in Aldor different things might be possible in SPAD, but
I was't able to find any documentation about this.

Right, Axiom is a bit weak here. But since we are (hopefully) agree to take Aldor for further development, then this is not such a big problem. The only point is that Axiom (as interpreter) should behave according to the Aldor language specification.

BTW, you cannot simply write something like

define MyCat: Category == with {
  +: (%, %) -> %;
  Commutative(+);
}

in Aldor, since that "commutative" is interpreted as a function with one argument and it should return a category. So you would have to write another category

define Commutative(f: (%, %) -> %): Category == with;

But that doesn't work since it is not clear what % refers to.

But you can at least compile the following:
--BEGIN
#include "aldor"
define Commutative(T: Type, f: (T, T) -> T): Category == with;
define CommutativePlus: Category == with {
  +: (%, %) -> %;
  Commutative(%, +);
}
--END

What is the problem here? Look at the definition of "Commutative".
Shouldn't Aldor allow me to write something like

--BEGIN
#include "aldor"
define Commutative(T: Type, f: (T, T) -> T): Category == {
  n: Integer := 1$Integer; while n>0 repeat n:=n+1;
  with;
}
define PlusCat: Category == with {
  +: (%, %) -> %;
  *: (%, %) -> %;
  Commutative(%, +);
}

Dom: PlusCat == add {
        (x: %) + (y: %): % == x;
        (x: %) * (y: %): % == y;
}

main(): () == {
        import from Dom;
        import from TextWriter, String, Character;
        b: Boolean == Dom has Commutative(Dom, +$Dom);
        stdout << "Dom has Commutative(Dom, +) = " << b << newline;
        c: Boolean == Dom has Commutative(Dom, *$Dom);
        stdout << "Dom has Commutative(Dom, *) = " << c << newline;
}
main();
--END

Yes, this file compiles and runs successfully.
aldor -grun -laldor comm.as
Dom has Commutative(Dom, +) = T
Dom has Commutative(Dom, *) = T

How could this program stop? In fact, already the compiler has to perform an evaluation of "Commutativive(%, +)", so it could never have produced the program. And why T is returned for "*"?

Very strange. Can somebody explain?

Ralf




reply via email to

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