(println "(comb 12 8) = "(comb 12 8))
;(trace nil)
+;(trace true)
(setq L '(3 7 + 4 2 + *))
-(setq P '())
+(setq M '(4 3 7 + * 2 -))
(define (calculExp P L)
(cond
- ((null? L) 0)
- ((= (first L) '+) (+ (first P) (calculExp (rest P) (rest L))))
- ((= (first L) '-) (- (first P) (calculExp (rest P) (rest L))))
- ((= (first L) '*) (* (first P) (calculExp (rest P) (rest L))))
+ ((null? L) P)
+ ((= (first L) '+) (calculExp (cons (+ (first P) (P 1)) (rest (rest P))) (rest L)))
+ ((= (first L) '-) (calculExp (cons (- (P 1) (first P)) (rest (rest P))) (rest L)))
+ ((= (first L) '*) (calculExp (cons (* (first P) (P 1)) (rest (rest P))) (rest L)))
;FIXME: test for divide by zero
- ((= (first L) '/) (/ (first P) (calculExp (rest P) (rest L))))
- ((cons (first L) (calculExp P (rest L))))))
-;(println (calculExp P L))
+ ((= (first L) '/) (calculExp (cons (/ (P 1) (first P)) (rest (rest P))) (rest L)))
+ ((calculExp (cons (first L) P) (rest L)))))
+(println "calculExp")
+(println (calculExp '() L))
+;(trace true)
+(println (calculExp '() M))
+
+;(trace nil)
(exit)