Name: Anonymous 2009-05-23 12:23
hey /prog/, I'm trying to do something simple and failing hard. I seem to be missing something obvious, but I'm not sure what. Using DrScheme here.
Suppose I have a list that represents infix notation, e.g.,
(1 + 2)
and I want to evaluate it. I can create a list that is in prefix notation assuming a simple list in this form:
(define infix->prefix (lambda (x)
(list (cadr x)
(car x)
(caddr x))))
And then
> (infix->prefix '(2 + 3))
(list '+ 2 3)
>
But, er, how would I evaluate this? That is, what am I missing so that
> (infix->prefix '(2 + 3))
5
>
Thanks for any insight.
Suppose I have a list that represents infix notation, e.g.,
(1 + 2)
and I want to evaluate it. I can create a list that is in prefix notation assuming a simple list in this form:
(define infix->prefix (lambda (x)
(list (cadr x)
(car x)
(caddr x))))
And then
> (infix->prefix '(2 + 3))
(list '+ 2 3)
>
But, er, how would I evaluate this? That is, what am I missing so that
> (infix->prefix '(2 + 3))
5
>
Thanks for any insight.