Add tests for recursion
This commit is contained in:
parent
d950cce57b
commit
815fb10e89
2 changed files with 27 additions and 0 deletions
|
@ -27,8 +27,17 @@
|
|||
(define (exp-final-node e)
|
||||
(program-final-node (exp->program e)))
|
||||
|
||||
(define rec-program
|
||||
'((define (pair x y f) ((f x) y))
|
||||
(define (fst p) (p K))
|
||||
(define (snd p) (p K1))
|
||||
(define (f x y)
|
||||
(letrec ((a ((pair x) b)) (b ((pair y) a))) (fst (snd (snd (snd a))))))
|
||||
(define (main) ((f 3) 4))))
|
||||
|
||||
(check-equal? (exp-final-node (ap-exp 'S 'K 'K 3)) 3)
|
||||
(check-equal? (exp-final-node (ap-exp 'K 100 99)) 100)
|
||||
(check-equal? (exp-final-node `(let ((x ,(ap-exp 'S 'K 'K 3)) (y 5)) ,(ap-exp 'K 'x 'x))) 3)
|
||||
(check-equal? (exp-final-node `(let ((x ,(ap-exp 'S 'K 'K 3)) (y 5)) ,(ap-exp 'K 'y 'x))) 5)
|
||||
(check-equal? (exp-final-node `(letrec ((y x) (x ,(ap-exp 'S 'K 'K 3))) ,(ap-exp 'K 'y 'x))) 3)
|
||||
(check-equal? (program-final-node rec-program) 4)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue