Original JavaScript It does not matter how we represent the primitive procedure objects, so long as apply can identify and apply them by using the procedures primitive-procedure? and apply-primitive-procedure. We have chosen to represent a primitive procedure as a list beginning with the symbol primitive and containing a procedure in the underlying Lisp that implements that primitive. (define (primitive-procedure? proc) (tagged-list? proc 'primitive)) (define (primitive-implementation proc) (cadr proc)) It does not matter how we represent primitive function objects, so long as apply can identify and apply them using the functions is_primitive_function and apply_primitive_function. We have chosen to represent a primitive function as a list beginning with the string "primitive" and containing a function in the underlying JavaScript that implements that primitive. function is_primitive_function(fun) { return is_tagged_list(fun, "primitive"); } function primitive_implementation(fun) { return head(tail(fun)); }
 Original JavaScript Similar to primitive functions, we define other primitive constants that are installed in the global environment by the function setup_environment. const primitive_constants = list(list("undefined", undefined), list("math_PI", math_PI) $\langle{}$more primitive constants$\rangle$ ); const primitive_constant_symbols = map(c => head(c), primitive_constants); const primitive_constant_values = map(c => head(tail(c)), primitive_constants);

[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