[Aldor-l] How to emulate new infix and postfix operators in Aldor

Ralf Hemmecke ralf at hemmecke.de
Fri Aug 25 16:01:19 EDT 2006


Hello,

I think some of you might find this interesting ...

*Question:* Aldor has a number of infix operators (AUG Sect 4.4). Can 
one define other infix operators?

*Answer:* No.

*Question:* Aldor has a number of postfix operators (notably ".."). Can 
one define other postfix operators?

*Answer:* No.

*Question:* Can one experiment with syntactic sugar in Aldor?

*Anser:* *YES!!!*

---BEGIN aaaInfixPostfix.as
#include "aldor"
#include "aldorio"

macro Z == Integer;

extend Z: with {
	apply: (Z, Z -> Z) -> Z;
} == add {
	apply(z: Z, f: Z -> Z): Z == f z;
}
main(): () == {
	_42 := "I am forty-two."; -- _42 is an identifier.
	stdout << _42 << newline;
	
	_!(z: Z): Z == {zero? z => 1; z * (z-1)_!;}
	z: Z := 4 _!;
	stdout << z << newline;

	x(a: Z)(b: Z): Z == a*b;
	z := 4 x 5 x 2;
	stdout << z << newline;
}
main();
---END aaapostfix.as

 >aldor -grun -laldor aaaInfixPostfix.as
--rhx: ignore the compiler warnings...
I am forty-two.
24
40

Hope, you like that...

Ralf



More information about the Aldor-l mailing list