[Aldor-l] Correct program?

Ralf Hemmecke ralf at hemmecke.de
Sun Aug 17 15:44:16 EDT 2008


Ooops, I forgot to CC the list...
---------------------------------------------------------------
Wow! That was quick. But have you seen the end of my mail (the segfault)?

On 08/17/2008 09:30 PM, Stephen Watt wrote:
 > I have not compiled your code, but at a quick look the two occurrances
 > of X look ok, even if funny.
 >
 >
 > You are allowed to do
 >
 >     f(n: Integer): Integer == {
 >           m := n;
 >            g(n: Integer): Integer == n+m;
 >            g
 >    }
 >
 > and
 >
 >    f(n: Integer)(n: Integer): Integer == n + 1
 >
 > is just a variant.   The inner n covers up the outer n.

Yes, I thought of that. But I did not dare to say so. Still, if the 
second X hides the first, then the type of x is no longer visible. It is 
also called X, but of course it is a different X than the type X of y.

So the compiler should rather reject this program, otherwise this 
program is another way of saying 'pretend' without using the this 
keyword. Dangerous...

Ralf

 > On Sun, Aug 17, 2008 at 3:24 PM, Ralf Hemmecke <ralf at hemmecke.de> wrote:
 >> Stephen,
 >>
 >> could you tell me whether the following program is proper Aldor? And if
 >> yes, what is it supposed to do?
 >>
 >> Actually, the program behaves as I want (which doesn't necessarily mean
 >> correct).
 >>
 >> But I fear putting the same X two times in the arguments of 'equals?'
 >> cannot be OK, because the code is certainly not type safe (case C3). It
 >> is unclear, whether =$Z or =$String is actually called.
 >>
 >> Ralf
 >>
 >>  >aldor -fx -DC1 -laldor aaa.as && ./aaa
 >> Name(X)=AldorInteger
 >> s1 = s2 is ... T
 >>  >aldor -fx -DC2 -laldor aaa.as && ./aaa
 >> Name(X)=AldorInteger
 >> s1 = s2 is ... F
 >>  >aldor -fx -DC3 -laldor aaa.as && ./aaa
 >> Name(X)=String
 >> s1 = s2 is ... F
 >>
 >> ---BEGIN aaa.as
 >> #include "aldor"
 >> #include "aldorio"
 >>
 >> PT ==> PrimitiveType;
 >> define ObjectLabelType: Category == with {
 >>         PrimitiveType;
 >>        object: (P: PT, P) -> %;
 >>        explode: % -> (P: PT, P);
 >> }
 >>
 >> Label: ObjectLabelType == add {
 >>        Rep == Record(LabDom: PT, label: LabDom);
 >>         import from Rep;
 >>        object(P: PT, p: P): % == per [P, p];
 >>        explode(x: %): (P: PT, P) == explode rep x;
 >>        equals?(X: PT, x: X)(X: PT, y: X): Boolean == {
 >> ----------------^------------^
 >>                import from Trace;
 >>                stdout << "Name(X)=" << name(X) << newline;
 >>                x = y
 >>        }
 >>        (x: %) = (y: %): Boolean == {
 >>                equals?(explode x)(explode y);
 >>        }
 >> }
 >> main(): () == {
 >>        Z ==> Integer;
 >>        import from Z, Label;
 >> #if C1
 >>        s1 := object(Z, 2);
 >>        s2 := object(Z, 2);
 >> #elseif C2
 >>        s1 := object(Z, 1);
 >>        s2 := object(Z, 2);
 >> #else
 >>        s1 := object(Z, 1);
 >>        s2 := object(String, "AAA");
 >> #endif
 >>        b: Boolean := s1 = s2;
 >>        stdout << "s1 = s2 is ... " << b << newline;
 >> }
 >>
 >> main();
 >> ---END aaa.as
 >>
 >>
 >> PS: Oh, I guess that says it all... put
 >>
 >>   (s1, s2) := (s2, s1)
 >>
 >> just after the #endif line.
 >>
 >> aldor -fx -DC3 -laldor aaa.as && ./aaa
 >> Name(X)=AldorInteger
 >> Segmentation fault
 >>
 >> But still, some comments are highly appreciated.




More information about the Aldor-l mailing list