repositories
/
TD_LISP.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixlet to the arithmetic expressions calculator
[TD_LISP.git]
/
exercices
/
arithmetic.lsp
diff --git
a/exercices/arithmetic.lsp
b/exercices/arithmetic.lsp
index 4bfa94f319b2d8fa207a1a01af672a33da8a2123..f020099e8ea8be02431afe00dcc9d298375155c3 100755
(executable)
--- a/
exercices/arithmetic.lsp
+++ b/
exercices/arithmetic.lsp
@@
-63,13
+63,14
@@
(setq N '(10 10 5 / +))
(define (calculExp P L)
(cond
(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 (- (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)))
;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)
(println "calculExp")
(println (calculExp '() L))
;(trace true)