Original JavaScript
Original JavaScript

[1] Any procedure function defined in the underlying Lisp JavaScript can be used as a primitive for the metacircular evaluator. The name of a primitive installed in the evaluator need not be the same as the name of its implementation in the underlying Lisp; JavaScript; the names are the same here because the metacircular evaluator implements Scheme JavaScript itself. Thus, for example, we could put (list 'first car) list("first", head) or (list 'square (lambda (x) (* x x))) list("square", x => x * x) in the list of primitive-procedures. primitive_functions.
[2]
Original JavaScript
Apply-in-underlying-scheme is the apply procedure we have used in earlier chapters. The metacircular evaluator's apply procedure (section 4.1.1) models the working of this primitive. Having two different things called apply leads to a technical problem in running the metacircular evaluator, because defining the metacircular evaluator's apply will mask the definition of the primitive. One way around this is to rename the metacircular apply to avoid conflict with the name of the primitive procedure. We have assumed instead that we have saved a reference to the underlying apply by doing (define apply-in-underlying-scheme apply) before defining the metacircular apply. This allows us to access the original version of apply under a different name. JavaScript's apply method expects the function arguments in a vector. (Vectors are called arrays in JavaScript.) Thus, the arglist is transformed into a vector—here using a while loop (see exercise 4.11): function apply_in_underlying_javascript(prim, arglist) { const arg_vector = []; // empty vector let i = 0; while (!is_null(arglist)) { arg_vector[i] = head(arglist); // store value at index $\texttt{i}$ i = i + 1; arglist = tail(arglist); } return prim.apply(prim, arg_vector); // $\texttt{apply}$ is accessed via $\texttt{prim}$ } We also made use of apply_in_underlying_javascript to declare the function apply_generic in section 2.4.3.
[3] The primitive procedure read waits for input from the user, and returns the next complete expression that is typed. For example, if the user types (+ 23 x), read returns a three-element list containing the symbol +, the number 23, and the symbol x. If the user types 'x, read returns a two-element list containing the symbol quote and the symbol x.
4.1.4   Running the Evaluator as a Program