|
|
@ -2,11 +2,15 @@ |
|
|
|
|
|
|
|
@{ |
|
|
|
//creation of the object class |
|
|
|
Object = initClass(); |
|
|
|
Object = initClass(); |
|
|
|
Object.type = "object"; |
|
|
|
type_t = { type_Nil: 0, type_Int: 1, type_Pair: 2}; |
|
|
|
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; |
|
|
@ -14,7 +18,7 @@ |
|
|
|
case type_t.type_Pair: { |
|
|
|
print("("); |
|
|
|
printf(x.values.a); |
|
|
|
print(", "); |
|
|
|
print(" . "); |
|
|
|
printf(x.values.d); |
|
|
|
print(")"); |
|
|
|
return; |
|
|
@ -24,24 +28,30 @@ |
|
|
|
Object.functions.printf = printf; |
|
|
|
|
|
|
|
// from object |
|
|
|
Nil = classCopy(Object); |
|
|
|
Nil.type = type_t.type_Nil; |
|
|
|
Int = classCopy(Object); |
|
|
|
Int.values.value = "null"; |
|
|
|
Int.type = type_t.type_Int; |
|
|
|
Pair = classCopy(Object); |
|
|
|
Pair.values.a = "null"; |
|
|
|
Pair.values.d = "null"; |
|
|
|
Pair.type = type_t.type_Pair; |
|
|
|
// 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}); } |
|
|
|
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 = newPair(newInt(1), newPair(newInt(2), newPair(newInt(3), newNil()))); |
|
|
|
l.functions.printf(l); |
|
|
|
print("\n"); |
|
|
|
s = newInt(1); |
|
|
|
s.functions.printf(s); |
|
|
|
|
|
|
|
nil; |
|
|
|
} |