axiom-developer
[Top][All Lists]
Advanced

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

Re: [Axiom-developer] Unions in Spad


From: Ralf Hemmecke
Subject: Re: [Axiom-developer] Unions in Spad
Date: Mon, 09 Jul 2007 20:08:48 +0200
User-agent: Thunderbird 2.0.0.4 (X11/20070604)

It looks as if one also could do

   if u case MachineInteger then ...

with the current Aldor compiler, I just don't know how to type
"MachineInteger" since the compiler immediately takes the *type*
MachineInteger and not the *tag* MachineInteger.

Use quotes like this?

 'MachineInteger'

That makes in a member of an Enumeration. Maybe that is what Aldor expects?

I should have told that I, of course, had already considered that option.

woodpecker:~/scratch>aldor -laldor -fx aaa.as
"aaa.as", line 13:         if u case 'MachineInteger' then {
                   ..................^
[L13 C19] #1 (Error) Argument 2 of `case' did not match any possible parameter type.
    The rejected type is Join(
                 with
                    ==  add ()
  ....
    Expected one of:
      -- Enumeration(machInt: Type)
      -- Enumeration(sStr: Type)

But, of course it must fail.

  'MachineInteger'

is nothing else than

  Enumeration(MachineInteger: Type)

but what I need is an element of this enumeration type.

Anyway, that usage of MachineInteger is not specified in the AUG so
maybe one better does not use it that way.

I have become quite confident that Aldor takes the most general road
whenever possible inspite of what might or might not be written in the
user's guide, so I am inclined to think that you are right.
'Union(Integer,String)' might very well be acceptible to the Aldor
compiler, we just need to intuit the proper usage.

It seems that MachineInteger is rather special. Look at the following session.

Ralf

woodpecker:~/scratch>aldor -gloop
     AA  L      DDDD      OOO    RRRR
    A A  L      D   D    O   O   R   R
   A  A  L      D    D  O     O  R   R
  AAAAA  L      D    D  O     O  RRRR
 A    A  L      D   D    O   O   R  R
A     A  LLLLL  DDDD      OOO    R   R

(c) Numerical Algorithms Group Ltd 1995-2001
Release: Aldor(C) version 1.0.3 for LINUX(glibc2.3) (debug version)
Type "#int help" for more details.
%1 >> #include "aldor"
                                           Comp: 190 msec, Interp: 50 msec
%2 >> #include "aldorinterp"
                                           Comp: 80 msec, Interp: 0 msec
%3 >> MyDom: with == add;
Defined MyDom @
 with
    ==  add ()

                                           Comp: 10 msec, Interp: 0 msec
%4 >> MyDom
  () @
 with
    ==  add ()

                                           Comp: 0 msec, Interp: 0 msec
%5 >> import from 'MyDom'
                                           Comp: 0 msec, Interp: 0 msec
%6 >> MyDom
      ^
[L6 C1] #1 (Error) Have determined 2 possible types for the expression.
        Meaning 1:
                 with
                    ==  add ()
       ...
        Meaning 2: Enumeration(MyDom: Type)

%7 >> MachineInteger
  () @ Join(
PrimitiveType with
        0: %
        1: %
        -: (%, %) -> %
        bytes: %
        coerce: SInt -> %
        coerce: % -> SInt
        integer: Literal -> %
        min: %
        max: %
        odd?: % -> Boolean
        zero?: % -> Boolean
    ==  add ()
,
Join(CopyableType, IntegerType) with
        mod+: (%, %, %) -> %
        mod-: (%, %, %) -> %
        mod*: (%, %, %) -> %
        mod/: (%, %, %) -> %
        mod^: (%, %, %) -> %
        modInverse: (%, %) -> %
        export to IntegerSegment(%)
    ==  add ()
,
 with
    ==  add ()
)
                                           Comp: 0 msec, Interp: 0 msec
%8 >> import from 'MachineInteger'
                                           Comp: 10 msec, Interp: 0 msec
%9 >> MachineInteger
  () @ Join(
PrimitiveType with
        0: %
        1: %
        -: (%, %) -> %
        bytes: %
        coerce: SInt -> %
        coerce: % -> SInt
        integer: Literal -> %
        min: %
        max: %
        odd?: % -> Boolean
        zero?: % -> Boolean
    ==  add ()
,
Join(CopyableType, IntegerType) with
        mod+: (%, %, %) -> %
        mod-: (%, %, %) -> %
        mod*: (%, %, %) -> %
        mod/: (%, %, %) -> %
        mod^: (%, %, %) -> %
        modInverse: (%, %) -> %
        export to IntegerSegment(%)
    ==  add ()
,
 with
    ==  add ()
)
                                           Comp: 0 msec, Interp: 0 msec


But try to compile

---BEGIN aaa.as
#include "aldor"
#include "aldorio"
macro I == MachineInteger;
M1: with == add;
main(): () == {
        U == Union(M1, String);
        import from String;
        import from U;
        import from 'M1';
        s: String := "I am a string";
        u: U := union s;
        if u case M1 then {
                stdout << "Integer: " << newline;
        } else {
                stdout << "String: " << newline;
        }
}

main();
---END aaa.as

woodpecker:~/scratch>aldor -laldor -fx aaa.as
Compiler bug...Bug: gen0UnionCaseIndex: branch not in union

Cool!




reply via email to

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