Prev | Current Page 150 | Next

Carl Reynolds and Paul Tymann

"Schaum's Outline of Principles of Computer Science"

)
As our example functional language, we will use Scheme, a newer (1975) descendent of LISP, which has
particularly consistent syntax. An expression in Scheme is an atom or a list. An atom is a single number, character
string, name, or function. A list is a collection of expressions contained within parentheses. Note that the elements
of a list may be atoms or other lists.
Computing in Scheme means evaluating the Scheme expressions. In particular, to evaluate a list, Scheme
expects the first element of the list to be a function, and the following elements of the list to be arguments to
the function. Since the elements of the list may themselves be lists, evaluation proceeds recursively, by first
evaluating the lists at the lowest level, and then proceeding to final evaluation of the function at the top level.
To add two numbers in Scheme, one creates a list. The first element within parentheses is the function ???+??™,
and the following elements are the arguments to the function. When an expression is complete, the Scheme
interpreter evaluates the function and returns the result. This cycle is called the REPL??”the Read, Evaluate,
Print, Loop. Here is the code to add 3 and 5 together:
(+ 3 5 )
8
If we wish to add more than two numbers, we simply include more parameters to the function.


Pages:
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
traktorki ogrodowe terapia magnetyczna Pompy zatapialne mapa Niemiec Wnętrza Poznań