SICP — Scheme/JS Structure and Interpretation of Computer Programs — Comparison Edition
Original Python
Original Python
To analyze an application, we analyze the function expression and argument expressions and construct an execution function that calls the execution function of the function expression (to obtain the actual function to be applied) and the argument-expression execution functions (to obtain the actual arguments). We then pass these to execute_application, which is the analog of apply in section 4.1.1. The function execute_application differs from apply in that the function body for a compound function has already been analyzed, so there is no need to do further analysis. Instead, we just call the execution function for the body on the extended environment. def analyze_application(component): ffun = analyze(function_expression(component)) afuns = map(analyze, arg_expressions(component)) return lambda env: (execute_application(ffun(env), map(lambda afun: (afun(env)), afuns))) def execute_application(fun, args): if is_primitive_function(fun): return apply_primitive_function(fun, args) elif is_compound_function(fun): result = function_body(fun) (extend_environment(function_parameters(fun), args, function_environment(fun))) return return_value_content(result) if is_return_value(result) else None else: error("unknown function type -- execute_application", fun)
Original Python
Original Python

[1] This technique is an integral part of the compilation process, which we shall discuss in chapter 5. Jonathan Rees wrote a Scheme interpreter like this in about 1982 for the T project (Rees and Adams 1982). Marc Feeley 1986 (see also Feeley and Lapalme 1987) independently invented this technique in his master's thesis.
[2] There is, however, an important part of the variable search search for a name that can be done as part of the syntactic analysis. As we will show in section 5.5.6, one can determine the position in the environment structure where the value of the variable will be found, thus obviating the need to scan the environment for the entry that matches the variable.
[3] See exercise 4.21 for some insight into the processing of sequences.
[4] See exercise 4.21 for some insight into the processing of sequences.
4.1.7   Separating Syntactic Analysis from Execution