I'm solving SICP exercise 4.3 It's about writing a data-directed evaluator (eval procedure) instead of the one presented in section 4.1.1 of the book. The basic idea is to get the procedures used by eval from a table according to each type of expression instead of using conditions. The beginning of the eval procedure presented in the book is implemented as follows:
(define (eval exp env)
(cond ((self-evaluating? exp) exp)
((variable? exp) (lookup-variable-value exp env))
((quoted? exp) (text-of-quotation exp))
((assignment? exp) (eval-assignment exp env))
[...]
And a data-directed version could be:
(define (eval exp env)
(cond ((self-evaluating? exp) exp)
((variable? exp) (lookup-variable-value exp env))
((get 'op (car exp)) exp env)
[...]
Where all the cases besides self-evaluating? and variable? will be handled directly by get. This procedure is linked to a table with the required procedures (identified with 'op) and returns the procedure associated with the expression type (car exp).
The issue I was having is that some procedures have only one parameter ((text-of-quotation exp)) while others use two ((eval-assignment exp env)), so once (get 'op (car exp)) returns the appropriate procedure, I can't get the correct number of parameters (I'm already using two parameters with ((get 'op (car exp)) exp env).
One solution I found on the scheme wiki (here) does the following to handle getting the procedure and the parameters:
((get 'op (car expr)) (get 'op (car expr) expr env))
However, I don't understand at all how does the (get 'op (car expr) expr env) part will get the correct parameters to apply with (get 'op (car expr)).
I would really appreciate if someone could explain me how does this scheme wiki solution handles the parameters on that specific line of code, as it handles very elegantly the issue I'm having difficulties working around.