All pastes #907661 Raw Edit

Untitled

public text v1 · immutable
·published 2008-02-17 20:30 UTC
rendered paste body
(define (eval num code)
  (cond
    [(number? code) code] ; if its a number, then it is equal to that number
    [(symbol? code) num] ; if it is a variable, then it is equal to the number the user gave
    [(cons? code) ; it is something like (op ex1 ex2)
     (cond
       ; first case: we add the two arguments. we must evaluate the arguments first.
       [(equal? (first code) '+) (+ (eval num (second code)) (eval num (third code)))] 
       [(equal? (first code) '-) (- (eval num (second code)) (eval num (third code)))]
       [(equal? (first code) '/) (/ (eval num (second code)) (eval num (third code)))])]))