Fixed cfold

This commit is contained in:
Sharjeel Khan
2022-11-11 04:01:08 -05:00
parent 4eb42d48f9
commit d440260d1c
5 changed files with 32 additions and 21 deletions

View File

@@ -47,9 +47,9 @@
('M c d) (append-mul (reassoc a) (reassoc b))
e e))
(define (cfold e) (my-match e
('A a b) (letn (ap (cfold a)
bp (cfold b))
(define (cfoldD e) (my-match e
('A a b) (letn (ap (cfoldD a)
bp (cfoldD b))
(my-match ap
('VL s t) (my-match bp
('VL m n) (list 'VL (+ s m) 0)
@@ -60,8 +60,8 @@
ep (list 'A ap bp)
)
)
('M c d) (letn (cp (cfold c)
dp (cfold dec))
('M c d) (letn (cp (cfoldD c)
dp (cfoldD dec))
(my-match cp
('VL s t) (my-match dp
('VL m n) (list 'VL (* s m) 0)
@@ -74,13 +74,13 @@
)
e e))
(define (eval e) (my-match e
(define (evalD e) (my-match e
('VR a b) 0
('VL c d) c
('A e f) (+ (eval e) (eval f))
('M l r) (* (eval l) (eval r))))
('A e f) (+ (evalD e) (evalD f))
('M l r) (* (evalD l) (evalD r))))
(println (eval (cfold (reassoc (mk-expr (integer (main-args 2)) 1)))))
(println (evalD (cfoldD (reassoc (mk-expr (integer (main-args 2)) 1)))))
(exit)