1 | from context import Context |
---|
2 | from objects import * |
---|
3 | context = Context() |
---|
4 | |
---|
5 | #context.push({}) |
---|
6 | print OMV("x") |
---|
7 | print OMA(OMV("x"),[OMV("y"),1]) |
---|
8 | |
---|
9 | |
---|
10 | #from binding import OMBinding, lambdasym |
---|
11 | |
---|
12 | |
---|
13 | context["x"] = 1 |
---|
14 | |
---|
15 | x = OMV("x") |
---|
16 | |
---|
17 | y = OMV("y") |
---|
18 | |
---|
19 | print context.evaluate(x) |
---|
20 | print context.evaluateVariable(x) |
---|
21 | print context.evaluate(y) |
---|
22 | import cd.arith1 as arith1 |
---|
23 | context.addCDImplementation(arith1.implementation) |
---|
24 | def test(expr): |
---|
25 | print "Original: ", expr |
---|
26 | print "Evaluated: ", context.evaluate(expr) |
---|
27 | test(OMA(arith1.implementation.plus, [1,2])) |
---|
28 | test(OMA(arith1.implementation.unary_minus, [10])) |
---|
29 | test(OMA(arith1.implementation.times, [3,4])) |
---|
30 | test(OMA(arith1.implementation.abs, [-123])) |
---|
31 | print context.evaluate(OMA(arith1.implementation.plus, [1,2])) |
---|
32 | application = OMA(OMS("plus", arith1.content), [1,2]) |
---|
33 | |
---|
34 | print context.evaluate(application) |
---|
35 | firstArg=OMBIND(lambdasym,[OMV("x"), OMV("y")], OMV("x")) |
---|
36 | #print context.evaluate(firstArg) |
---|
37 | test(OMA(firstArg, [37,777777])) |
---|
38 | |
---|