This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: (Const (+ v1 v2)))] [(Negate? e) (Const (- 0 (Const-int (eval-exp (Negate-e e)))))] [#t (error "eval-exp expected an exp")])) (define (test1) (eval-exp (Negate (Add (Const 2) (Const 2))))) ;; much more convenient is define-struct ; (for any conceptual record or datatype) (define-struct const (int)) (define-struct add (e1 e2)) (define-struct negate (e)) ( (define (eval-exp2 e) (cond [(const? e) e] [(add? e) (let ([v1 (const-int (eval-exp2 (add-e1 e)))] [v2 (const-int (eval-exp2 (add-e2 e)))]) (make-const (+ v1 v2)))] [(negate? e) (make-const (- 0 (const-int (eval-exp2 (negate-e e)))))] [#t (error "eval-exp2 expected an exp")])) (define (test2) (eval-exp2 (make-negate (make-add (make-const 2) (make-const 2))))) ;; but it's much more than convenience, the result of make-add is _not_ ;; a list (or anything else in Pure Scheme) ;...
View Full Document
- Spring '08
- Semantics, Convenience, EverQuest