C compiler with embedded metalanguage.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

40 строки
1.0 KiB

@(import("fake-static-classes.mc"))
@{
//creation of the class
P = initClass();
P.values.x = "null";
P.values.y = "null";
printf(p) { // Can we create a self variable or somthing like that ?
print("P(", p.values.x, ", ", p.values.y, ")\n");
}
P.functions.printf = printf;
// To know if the parameter is known
(P.values.x != null) ? print("\nyes") : print("\nno");
(P.values.w != null) ? print("\nyes\n\n") : print("\nno\n\n");
// Use of the P class
// x = new(P, { x: 2, y: 4, z: 6 });
// or
newP(a, b) { new(P, { x: a, y: b }) }
x = newP(2, 4);
x.functions.printf(x);
// Create another class from P
Q = initClass(P);
Q.values.z = "null";
printf(q) {
print("Q(", q.values.x, ", ", q.values.y, ", ", q.values.z, ")\n");
}
Q.functions.printf = printf;
// Use of the Q class
// y = new(Q, { x: 1, y: 2, z: 3 });
// or
newQ(a, b, c) { new(Q, { x: a, y: b, z: c }) }
y = newQ(1, 2, 3);
y.functions.printf(y);
nil;
}