I screwed up the code in the last posting, so now I have to reply to a reply to my own post - of two weeks back.
The code should be more like:
(define (infix x) (eval (append (list (cadr x) (car x)) (cddr x))))
I actually tested this one (under Guile), and it works right, even if it is a bit long for a one-liner. a cleaner, but longer, version would be:
(define (infix x)
(let* ((op (cadr x))
(term1 (car x))
(term2 (cddr x))
(operation (append (list op term1) term2)))
(eval operation)))
Also, the other example I gave should have been:
(infix '('a cons 'b))
==> (a . b)
It still doesn't have any error checking, though, and I'm just too lazy to bother right now.
|