; Simulate a spreadsheet by interpreting commands of the form ; (set variable constant-value) to assign the value to a variable. ; (define variable expression) to assign the value of the given ; expression to the variable. ; (value-of variable) to print the value of the variable. ; Inputs to the spreadsheet are a list of formulas and a variable-value ; table. Each formula has the form ; (variable expression variable-list) ; where variable-list is the list of variables occurring in the ; expression. (define (spreadsheet formulas var-val-table) (display 'command?) (let ((cmd (read))) (cond ((equal? (first cmd) 'set) (spreadsheet formulas (new-values (list (second cmd)) formulas (updated var-val-table (rest cmd))) ) ) ((equal? (first cmd) 'define) (let ((v (eval-expr (third cmd) var-val-table))) (if (equal? v 'unknown) (spreadsheet (cons (new-formula (rest cmd)) formulas) var-val-table) (spreadsheet (cons (new-formula (rest cmd)) formulas) (new-values (list (second cmd)) formulas (updated var-val-table (list (second cmd) v)) ) ) ) ) ) ((equal? (first cmd) 'value-of) (display (eval-expr (second cmd) var-val-table)) (newline) (spreadsheet formulas var-val-table) ) ) ) ) (define formulas '((c (+ a b) (a b)) (d (* a c) (a c)) ) )