;; Self referencial expressions ;; Expr: can be ;; -- Number ;; --(make-add (Expr Expr) ;; --(make-mul (Expr Expr) ;; --(make-sub (Expr Expr) (define-struct add (left right)) (define-struct mul (left right)) (define-struct sub (left right)) ;;TODO: write the template for Expr ;; Ask the 4 questions when writing a template! ;; Lets define a function, compute ;; -that when given a number, returns that number ;; -when given add, adds the two expressions, sub, subtracts the two expressions ;; -and mul multiplies the two expressions ;;examples: ;; (compute 3) => 3 ;; (compute (make-add 1 2))=> 3 ;; (compute (make-sub 2 1))=> 1 ;; Expr2 can be ;; --number ;; --(make-expression Symbol Expr2 Expr2) (define-struct expression ( op left right)) ;;TODO: Create the template for Expr2 ;; Ask the 4 questions again! ;;Create a function, expr2 that performs the same function as compute, except we only use one struct ;; Only allow Symbol to be one of the following, +,-,*. Any other inputed symbol should return the string "error" ;; (expr2 expression) -> number ;; examples: ;; (expr2 2) => 2 ;; (expr2 (make-expression '+ 1 2)) => 3 ;; (expr2 (make-expression '- 4 3)) => 1 ;; (expr2 (make-expression '* (make-expression '- 3 1) 1)) => 2 ;; (expr2 (make-expression '/ 1 2)) => "error"