On Wednesday, 23 September 2015 at 06:06:42 UTC, Ola Fosheim
Grøstad wrote:
In Beta, the successor to Simula, all execution follows this
pattern:
this(){
begin_prepare_stuff();
subclass.this();
end_prepare_stuff();
}
Actually, this was how Simula did it too. If you didn't provide
the slot for the subclass constructor ("inner") it would inject
it at the end. Unfortunately C++ didn't add the slot, and just
mimics default construction in Simula...
But Beta is actually much more powerful than I suggested, more
like this (Cish syntaxification):
B {
int x,y,a,b,sum;
virtual init1 {
int aa;
enter(aa,b);
b = b*2;
inner;
a = aa;
}
enter (a,b,x,y);
enter (init1,(x,y));
sum = 0;
inner;
sum = sum + x + y + a + b;
}
D : B {
int z;
init1 : super.init1 {
z = aa+b;
inner;
}
sum = sum + z;
inner;
}
"enter" is the parameter list, the compiler will pick the one
that matches the tuple and execute it before it executes the body.
"inner" is where you inject code when specializing.
(Beta is a very minimal stackless language, it does not
differentiate between construction and function call. Which bring
some other problems.)