Combinations Operator Combinations - SICP Comparison Edition" />
One of our goals in this chapter is to isolate issues about thinking procedurally. As a case in point, let us consider that, in evaluating operator combinations, the interpreter is itself following a procedure. Due to the prominence of the keyword function, we are generally replacing references to "procedure/procedural" with references to "function/functional". The above sentences are an exception; the terms "thinking procedurally" and "procedure" are perhaps still adequate for the JavaScript edition here.
Notice how succinctly the idea of recursion can be used to express what, in the case of a deeply nested combination, would otherwise be viewed as a rather complicated process. For example, evaluating
Original | JavaScript |
(* (+ 2 (* 4 6)) (+ 3 5 7)) | (2 + 4 * 6) * (3 + 12); |
percolate values upwardform of the evaluation rule is an example of a general kind of process known as tree accumulation.
Original | JavaScript | |
Next, observe that the repeated application of the first step brings us to the point where we need to evaluate, not combinations, but primitive expressions such as numerals, built-in operators, or other names. numerals or names. We take care of the primitive cases by stipulating that
values.The key point to notice is the role of the environment in determining the meaning of the symbols names in expressions. In an interactive language such as Lisp, JavaScript, it is meaningless to speak of the value of an expression such as (+ x 1) x + 1 without specifying any information about the environment that would provide a meaning for the symbol x (or even for the symbol +). name x. As we shall see in chapter 3, the general notion of the environment as providing a context in which evaluation takes place will play an important role in our understanding of program execution.
Notice that the evaluation rule given above does not handle definitions. declarations. For instance, evaluating (define x 3) const x = 3; does not apply define an equality operator = to two arguments, one of which is the value of the symbol name x and the other of which is 3, since the purpose of the define declaration is precisely to associate x with a value. (That is, (define x 3) const x = 3; is not a combination.)
Original | JavaScript | |
Such exceptions to the general evaluation rule are called special forms. Define is the only example of a special form that we have seen so far, but we will meet others shortly. Each special form has its own evaluation rule. The various kinds of expressions (each with its associated evaluation rule) constitute the syntax of the programming language. In comparison with most other programming languages, Lisp has a very simple syntax; that is, the evaluation rule for expressions can be described by a simple general rule together with specialized rules for a small number of special forms.[2] |
The word const is a keyword in JavaScript. Keywords carry a particular meaning, and thus cannot be used as names. A keyword or a combination of keywords in a statement instructs the JavaScript interpreter to treat the statement in a special way. Each such syntactic form has its own evaluation rule. The various kinds of statements and expressions (each with its associated evaluation rule) constitute the syntax of the programming language. |
convenientsyntactic constructs, which make the language less uniform, end up causing more trouble than they are worth when programs become large and complex. In the words of Alan Perlis,
Syntactic sugar causes cancer of the semicolon.