evaluator: closures work
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
tests
|
||||
testEvalBegin
|
||||
self assert: (ph parseAndEval: '(begin 1 2 3)') equals: 3
|
@@ -0,0 +1,3 @@
|
||||
tests
|
||||
testEvalBeginSet
|
||||
self assert: (ph parseAndEval: '(begin (define x 1) (set x 2) x)') equals: 2
|
@@ -0,0 +1,13 @@
|
||||
tests
|
||||
testEvalSetAtCorrectLevel
|
||||
| proc |
|
||||
ph parseAndEval: '
|
||||
(define fy3
|
||||
((lambda (x)
|
||||
(lambda (y)
|
||||
(begin
|
||||
(set x (+ x 2))
|
||||
(+ x y))))
|
||||
3))'.
|
||||
proc := ph eval: #fy3.
|
||||
self assert: (ph parseAndEval: '(fy3 5)') equals: 10
|
@@ -0,0 +1,5 @@
|
||||
tests
|
||||
testEvalSimpleSet
|
||||
self assert: (ph parseAndEval: '(define x2 21') equals: #undefined.
|
||||
self assert: (ph parseAndEval: '(set x2 22)') equals: #undefined.
|
||||
self assert: (ph parseAndEval: 'x2') equals: 22.
|
@@ -1,3 +1,3 @@
|
||||
as yet unclassified
|
||||
tests
|
||||
testLambdaProcedureExecution
|
||||
self assert: (ph parseAndEval: '((lambda (x) (* x x)) 3)') equals: 9.
|
@@ -1,4 +1,4 @@
|
||||
as yet unclassified
|
||||
tests
|
||||
testProcedureDefinition
|
||||
| proc |
|
||||
ph parseAndEval: '(define squared (lambda (x) (* x x)))'.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
as yet unclassified
|
||||
tests
|
||||
testProcedureExecution
|
||||
ph parseAndEval: '(define squared (lambda (x) (* x x)))'.
|
||||
self assert: (ph parseAndEval: '(squared 3)') equals: 9
|
@@ -0,0 +1,10 @@
|
||||
tests
|
||||
testSimpleClosure
|
||||
| res |
|
||||
res := ph eval: (ph parse: '(
|
||||
((lambda (x)
|
||||
(lambda (y)
|
||||
(+ x y)))
|
||||
3)
|
||||
7)').
|
||||
self assert: res equals: 10
|
@@ -0,0 +1,11 @@
|
||||
tests
|
||||
testSimpleClosureIntrospection
|
||||
| proc |
|
||||
ph parseAndEval: '(define fy3
|
||||
((lambda (x)
|
||||
(lambda (y)
|
||||
x))
|
||||
3))'.
|
||||
proc := ph parseAndEval: '#fy3'.
|
||||
self assert: proc params equals: #(y).
|
||||
self assert: (proc env at: #x) equals: 3.
|
Reference in New Issue
Block a user