From: Jérôme Benoit Date: Sun, 7 May 2017 21:17:01 +0000 (+0200) Subject: Fixlet to the arithmetic expressions calculator X-Git-Url: https://git.piment-noir.org/?p=TD_LISP.git;a=commitdiff_plain;h=25450b8430ab9b9f699580f0bef9ab0c1f65c5b2 Fixlet to the arithmetic expressions calculator Signed-off-by: Jérôme Benoit --- diff --git a/exercices/arithmetic.lsp b/exercices/arithmetic.lsp index 4bfa94f..f020099 100755 --- a/exercices/arithmetic.lsp +++ b/exercices/arithmetic.lsp @@ -63,13 +63,14 @@ (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)