I'm trying to learn scheme (more specifically R5RS), and I want to define a procedure that takes as input a list with 3 elements, for example: '(5 + 2), where the middle argument always is an operator, and the 1st and 3rd are always operands.
Examples:
(proc-mid '(1 + 2))
--> 3
(proc-mid '(1 list 2))
--> (1 2)
(proc-mid '(20 * 5))
--> 100
My code so far is this:
(define (proc-mid exp)
(define proc (cadr exp))
(proc (car exp) cddr exp))
However, I get an error saying:
application: not a procedure;
expected a procedure that can be applied to arguments
given: +
arguments...:
My question is then, why is + not evaluated as a procedure?