From 25450b8430ab9b9f699580f0bef9ab0c1f65c5b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 7 May 2017 23:17:01 +0200 Subject: [PATCH] Fixlet to the arithmetic expressions calculator MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- exercices/arithmetic.lsp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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) -- 2.34.1