Prev Up Next

The reader will have noted that the Scheme example programs provided thus far are also s-expressions. This is true of all Scheme programs: Programs are data.

Thus, the character datum #\c is a program, or a form. We will use the more general term form instead of program, so that we can deal with program fragments too.

Scheme evaluates the form #\c to the value #\c, because #\c is self-evaluating. Not all s-expressions are self-evaluating. For instance the symbol s-expression xyz evaluates to the value held by the variable xyz. The list s-expression (string->number "16") evaluates to the number 16.

Not all s-expressions are valid programs. If you typed the dotted-pair s-expression (1 . 2) at the Scheme listener, you will get an error.

Scheme evaluates a list form by examining the first element, or head, of the form. If the head evaluates to a procedure, the rest of the form is evaluated to get the procedure's arguments, and the procedure is applied to the arguments.

If the head of the form is a special form, the evaluation proceeds in a manner idiosyncratic to that form. Some special forms we have already seen are begin, define, and set!. begin causes its subforms to be evaluated in order, the result of the entire form being the result of the last subform. define introduces and initializes a variable. set! changes the binding of a variable.

Prev Up Next

Log in or register to write something here or to contact authors.