[Aldor-l] Correct program?

Ralf Hemmecke ralf at hemmecke.de
Sun Aug 17 15:24:08 EDT 2008


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