@(import("fake-static-classes.mc")) @{ //creation of the object class Object = initClass(); Object.type = "object"; type_t = { type_Nil: 0, type_Int: 1, type_Pair: 2}; printf(x) { switch (x.type) { case type_t.type_Nil: { print("Nil"); return; } case type_t.type_Int: { print(x.values.value); return; } case type_t.type_Pair: { print("("); printf(x.values.a); print(" . "); printf(x.values.d); print(")"); return; } } } Object.functions.printf = printf; // from object // Nil Nil = initClass(Object); Nil.type = type_t.type_Nil; // Int Int = initClass(Object); Int.values.value = "null"; Int.type = type_t.type_Int; // Pair Pair = initClass(Object); Pair.values.a = "null"; Pair.values.d = "null"; Pair.type = type_t.type_Pair; // function to simplify the writting of example newNil(x) { new(Nil , { }); } newInt(x) { new(Int , { value: x }); } newPair(x, y) { new(Pair, { a: x, d: y }); } // example l = newPair(newInt(1), newPair(newInt(2), newPair(newInt(3), newNil()))); l.functions.printf(l); print("\n"); s = newInt(1); s.functions.printf(s); nil; }