(setq N '(10 10 5 / +))
(define (calculExp P L)
(cond
- ((null? L) P)
- ((= (first L) '+) (calculExp (cons (+ (first P) (P 1)) (rest (rest P))) (rest L)))
+ ((null? L) (first P))
+ ; all these conditions could probably be simplified
+ ((= (first L) '+) (calculExp (cons (+ (P 1) (first P)) (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)))
+ ((= (first L) '*) (calculExp (cons (* (P 1) (first P)) (rest (rest P))) (rest L)))
;FIXME: test for divide by zero
((= (first L) '/) (calculExp (cons (/ (P 1) (first P)) (rest (rest P))) (rest L)))
- ((calculExp (cons (first L) P) (rest L)))))
+ ((number? (first L)) (calculExp (cons (first L) P) (rest L)))))
(println "calculExp")
(println (calculExp '() L))
;(trace true)