Reputation: 49
I'm trying to run this scheme program from my book, yet whenever I try to evaluate (minus 5 4). The error: "reference to undefined identifier: minus" appears. Running the function as (minus 5 4) obviously doesn't work. Did I call the evaluation wrong?
(define (eval-expr E)
(cond
((number? E) E)
((eqv? (car E) 'plus) (apply + (eval-params (cdr E))))
((eqv? (car E) 'times) (apply * (eval-params (cdr E))))
((eqv? (car E) 'minus) (apply - (eval-params (cdr E))))
((eqv? (car E) 'divide) (apply / (eval-params (cdr E))))
(else '()) ; confused - return ()
)
)
(define (eval-params E)
(if (null? E) '()
(cons (eval-expr (car E)) (eval-params (cdr E)))
)
)
Upvotes: 1
Views: 3066
Reputation: 993125
It looks like you want to call
(eval-expr '(minus 5 4))
The eval-expr
function takes data that represents an arithmetic expression. On the other hand, your example (minus 5 4)
is code that's trying to call a function called minus
.
Upvotes: 5