diff options
author | Hugo <hugo.hornquist@gmail.com> | 2016-04-26 23:14:04 +0200 |
---|---|---|
committer | Hugo <hugo.hornquist@gmail.com> | 2016-04-26 23:14:04 +0200 |
commit | eecac5ffb5451e6e21bf926ea3fbdfdab2af5737 (patch) | |
tree | 431492e613d8068d452b622d599e232c09ae6c7b | |
parent | parser now handles the four basic '(+ - * /) (diff) | |
download | math-parse-eecac5ffb5451e6e21bf926ea3fbdfdab2af5737.tar.gz math-parse-eecac5ffb5451e6e21bf926ea3fbdfdab2af5737.tar.xz |
improved variable names in full-parse
-rw-r--r-- | full-parse.rkt | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/full-parse.rkt b/full-parse.rkt index ae80640..cec14e2 100644 --- a/full-parse.rkt +++ b/full-parse.rkt @@ -11,6 +11,7 @@ ((if (char-numeric? c) string->number string->symbol) (string c))) + ; used to add a completed part of the operation to the list of operations ; 5 is one of those in the addition iteration ; 3 and x are in the product iteration @@ -21,16 +22,19 @@ (char->wanted (car operation)) (next-operation operation)) seq)) + (define (contains value seq) (memq value seq)) - (define (inner cfac facts rexpr) + + (define (inner current-term other-terms remaining-expression) (cond - [(null? rexpr) - (reverse (add-operation-to-list cfac facts))] - [(eqv? (car rexpr) operator) - (inner '() (add-operation-to-list cfac facts) (cdr rexpr))] + [(null? remaining-expression) + (reverse (add-operation-to-list current-term other-terms))] + [(eqv? (car remaining-expression) operator) + (inner '() (add-operation-to-list current-term other-terms) (cdr remaining-expression))] [else - (inner (cons (car rexpr) cfac) facts (cdr rexpr))])) + (inner (cons (car remaining-expression) current-term) other-terms (cdr remaining-expression))])) + (if (not (contains operator expr)) (next-operation expr) (cons (char->wanted operator) (inner '() '() expr)))) |