Skip to content

Commit

Permalink
Remove naked car and empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
dbgrigsby committed Feb 20, 2018
1 parent 4f675bf commit 2e0a70c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions interpreter.scm
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
(cond
; not all programs/ segments must end in return
; empty list should return the state (ie: at the end of an if statement's statements)
((null? program) (cons '() (list state)))
((null? program) (cons nullreturn (list state)))
((not (list? program)) (error "Invalid program syntax"))
((not (null? (get-value-from-pair (evaluate-statement->retval_state (program-head program) state))))
(evaluate-statement->retval_state (program-head program) state))
Expand All @@ -75,10 +75,10 @@
(cond
((null? arglist) (error "Not a statement"))
((eq? 'return (get-upcoming-statement-name arglist)) (G-evaluate-return-statement->retvalue_state arglist state))
((eq? 'var (get-upcoming-statement-name arglist)) (cons '() (list (G-evaluate-var-declare-statement->state arglist state))))
((eq? 'while (get-upcoming-statement-name arglist)) (G-evaluate-while-statement->retval_state arglist state '()))
((eq? 'var (get-upcoming-statement-name arglist)) (cons nullreturn (list (G-evaluate-var-declare-statement->state arglist state))))
((eq? 'while (get-upcoming-statement-name arglist)) (G-evaluate-while-statement->retval_state arglist state nullreturn))
((eq? 'if (get-upcoming-statement-name arglist)) (G-evaluate-if-statement->retval_state arglist state))
(else (cons '() (list (get-state-from-pair (G-eval-atomic-statement->value_state arglist state))))))))
(else (cons nullreturn (list (get-state-from-pair (G-eval-atomic-statement->value_state arglist state))))))))

; Important section helper functions for abstraction are defined below
(define program-head car)
Expand Down Expand Up @@ -147,7 +147,7 @@
(get-state-from-pair (G-eval-atomic-statement->value_state (get-if-cond arglist) state))))

; If the if condition is false, return '() for the return value, and also return the updated state after evaluating the condition (side effects challenge)
(else (cons '() (list (get-state-from-pair (G-eval-atomic-statement->value_state (get-if-cond arglist) state))))))))
(else (cons nullreturn (list (get-state-from-pair (G-eval-atomic-statement->value_state (get-if-cond arglist) state))))))))

(define get-if-else
(lambda (arglist)
Expand Down Expand Up @@ -200,7 +200,7 @@
(get-state-from-pair (G-eval-atomic-statement->value_state (get-while-cond arglist) state))))))

; If the while condition is false, return '() for the return value, and also return the updated state after evaluating the condition (side effects challenge)
(else (cons '() (list (get-state-from-pair (G-eval-atomic-statement->value_state (get-while-cond arglist) state))))))))
(else (cons nullreturn (list (get-state-from-pair (G-eval-atomic-statement->value_state (get-while-cond arglist) state))))))))


; Important section helper functions for abstraction are defined below
Expand Down Expand Up @@ -746,7 +746,7 @@
(lambda (variable state)
(cond
((null? state) (error "State is empty"))
((null? (car state)) (error "Variable not found in state"))
((null? (get-variable-section-state state)) (error "Variable not found in state"))
((eq? (get-state-variable-head state) variable)
(get-state-value-head state))
(else (variable-value-lookup variable (get-tail-state state))))))
Expand Down

0 comments on commit 2e0a70c

Please sign in to comment.