Original JavaScript Figure 2.7 The sequence 1, 2, 3, 4 represented as a chain of pairs. Figure 2.8 The sequence 1, 2, 3, 4 represented as a chain of pairs.
 Original JavaScript Box notation is sometimes difficult to read. In this book, when we want to indicate the list nature of a data structure, we will employ the alternative list notation: Whenever possible, list notation uses applications of list whose evaluation would result in the desired structure. For example, instead of the box notation [1, [[2, 3], [[4, [5, null]], [6, null]]]] we write list(1, [2, 3], list(4, 5), 6) in list notation.[5]
 Original JavaScript Exercise 2.20 The procedures +, *, and list take arbitrary numbers of arguments. One way to define such procedures is to use define with dotted-tail notation. In a procedure definition, a parameter list that has a dot before the last parameter name indicates that, when the procedure is called, the initial parameters (if any) will have as values the initial arguments, as usual, but the final parameter's value will be a list of any remaining arguments. For instance, given the definition (define (f x y . z) $\langle \textit{body} \rangle$) the procedure f can be called with two or more arguments. If we evaluate (f 1 2 3 4 5 6) then in the body of f, x will be 1, y will be 2, and z will be the list (3 4 5 6). Given the definition (define (g . w) $\langle \textit{body} \rangle$) the procedure g can be called with zero or more arguments. If we evaluate (g 1 2 3 4 5 6) then in the body of g, w will be the list (1 2 3 4 5 6).[6] Use this notation to write a procedure same-parity that takes one or more integers and returns a list of all the arguments that have the same even-odd parity as the first argument. For example, ;; same-parity to be given by student (same-parity 1 2 3 4 5 6 7) (1 3 5 7) (same-parity 2 3 4 5 6 7) (2 4 6) There is currently no solution available for this exercise. This textbook adaptation is a community effort. Do consider contributing by providing a solution for this exercise, using a Pull Request in Github. Exercise 2.21 In the presence of higher-order functions, it is not strictly necessary for functions to have multiple parameters; one would suffice. If we have a function such as plus that naturally requires two arguments, we could write a variant of the function to which we pass the arguments one at a time. An application of the variant to the first argument could return a function that we can then apply to the second argument, and so on. This practice—called currying and named after the American mathematician and logician Haskell Brooks Curry—is quite common in programming languages such as Haskell and OCaml. In JavaScript, a curried version of plus looks as follows. function plus_curried(x) { return y => x + y; } Write a function brooks that takes a curried function as first argument and as second argument a list of arguments to which the curried function is then applied, one by one, in the given order. For example, the following application of brooks should have the same effect as plus_curried(3)(4): brooks(plus_curried, list(3, 4)); 7 While we are at it, we might as well curry the function brooks! Write a function brooks_curried that can be applied as follows: brooks_curried(list(plus_curried, 3, 4)); 7 With this function brooks_curried, what are the results of evaluating the following two statements? brooks_curried(list(brooks_curried, list(plus_curried, 3, 4))); brooks_curried(list(brooks_curried, list(brooks_curried, list(plus_curried, 3, 4)))); function brooks(f, items) { return is_null(items) ? f : brooks(f(head(items)), tail(items)); } function brooks_curried(items) { return brooks(head(items), tail(items)); } The statement brooks_curried(list(brooks_curried, list(plus_curried, 3, 4))); of course evaluates to 7, as does brooks_curried(list(brooks_curried, list(brooks_curried, list(plus_curried, 3, 4))));

[1] In this book, we use list to mean a chain of pairs terminated by the end-of-list marker. In contrast, the term list structure refers to any data structure made out of pairs, not just to lists.
[2] Since nested applications of car and cdr are cumbersome to write, Lisp dialects provide abbreviations for them—for instance, (cadr $\langle arg \rangle$) = (car (cdr $\langle arg \rangle$)) The names of all such procedures start with c and end with r. Each a between them stands for a car operation and each d for a cdr operation, to be applied in the same order in which they appear in the name. The names car and cdr persist because simple combinations like cadr are pronounceable.
[3] It's remarkable how much energy in the standardization of Lisp dialects has been dissipated in arguments that are literally over nothing: Should nil be an ordinary name? Should the value of nil be a symbol? Should it be a list? Should it be a pair? In Scheme, nil is an ordinary name, which we use in this section as a variable whose value is the end-of-list marker (just as true is an ordinary variable that has a true value). Other dialects of Lisp, including Common Lisp, treat nil as a special symbol. The authors of this book, who have endured too many language standardization brawls, would like to avoid the entire issue. Once we have introduced quotation in section 2.3, we will denote the empty list as '() and dispense with the variable nil entirely.
[4] The value null is used in JavaScript for various purposes, but in this book we shall only use it to represent the empty list.
[5] Our JavaScript environment provides a primitive function display_list that works like the primitive function display, except that it uses list notation instead of box notation.
[6] To define f and g using lambda we would write (define f (lambda (x y . z) body)) (define g (lambda w body))
[7] Scheme standardly provides a map procedure that is more general than the one described here. This more general map takes a procedure of $n$ arguments, together with $n$ lists, and applies the procedure to all the first elements of the lists, all the second elements of the lists, and so on, returning a list of the results. For example: (map + (list 1 2 3) (list 40 50 60) (list 700 800 900)) (741 852 963) (map (lambda (x y) (+ x (* 2 y))) (list 1 2 3) (list 4 5 6))
2.2.1   Representing Sequences