In addition to the excellent accepted answer, I would like to give more explanations why rap
is required.
The environment ( E
in SECD
) stores all stored objects (functions, constants, variables, etc.). E
is essentially a stack of lists. Things in E
are loaded onto the S
stack, and then executed or used by commands in C
Everyone in E
gets an identifier so that it can be referenced later. This identifier is usually a tuple (x,y)
, where x
represents the location of the list on the stack and y
represents the position in the list.
In a typical function call, a new list is pressed on E
, and now any local variables can have identifiers of the type (|E|, y)
, where |E|
denotes size E
This is very problematic for recursive functions, however, since the stack size grows with every function call, it is therefore impossible to assign identifiers for the local variables used.
To solve this problem, rap
does most of the things ap
does, but instead of dragging the new list onto the environment stack, it replaces everything that is in chapter E
with the new environment list.
source share