EECS 111

Home General Information Schedule Homework Newsgroup Resources 

So: now that we're getting serious about programming, it seems appropriate to enumerate all of the procedures that we know how to use. There aren't so terribly many, are there?
(define {variablename} {value}) (define ({name} {arg1} {arg2} ...) {body}) (define {name} (lambda ({arg1} {arg2} ...) {body})) 
Bind a value (or function) to a variable (or procedure) name. Note: the second and third examples are functionally identical. 
(if {predicate} {consequent} {alternative}) 
To evaluate an if expression, the interpreter starts by evaluating the predicate part of the expression. If predicate evaluates to a true value, the interpreter evaluates the consequent and returns its value. Otherwise it evaluates the alternative and returns its value. 
(cond ({p1} {e1}) ({p2} {e2}) ... (else {en})) 
Conditional expressions are evaluated as follows. The predicate p1 is evaluated first. If its value is false, then p2 is evaluated. If p2's value is also false, then p3 is evaluated. This process continues until a predicate {pj} is found whose value is true, in which case the interpreter returns the value of the corresponding consequent {ej} of the clause as the value of the conditional expression. 
(lambda ({arg1} {arg2} ...) {body}) 
(let (({var1} {value1}) ({var2} {value2}) ...) {body}) 
Boolean predicates are boolean expressions that take other boolean expressions as arguments.
(and {e1} {e2} ...) 
Return #t iff all the expressions evaluate to #t. Note: This is a special form, but we'll talk about that later. 
(or {e1} {e2} ...) 
Return #t if at least on of the expressions evaluates to #t. Note: This is a special form, but we'll talk about that later. 
(not {e}) 
Return #t if e is #f, otherwise return #f. 
Numeric predicates are boolean expressions that take numeric expressions as arguments.
(= {e1} {e2} ...) 
Return #t iff all the expressions evaluate to the same value 
(< {e1} {e2} ...) (<= {e1} {e2} ...) (> {e1} {e2} ...) (>= {e1} {e2} ...) 
... 
(even? {e1}) (odd? {e1}) (divides? {numerator} {denominator}) 
... 
Numeric operators are numeric expressions that take numeric expressions as arguments.
(+ {e1} {e2} ...) ( {e1} {e2}) (* {e1} {e2} ...) (/ {e1} {e2}) (abs {e}) (exp {e}) (log {e}) (max {e1} {e2} ...) (min {e1} {e2} ...) (quotient {number} {divisor}) (remainder {number} {divisor}) (sqrt {e}) 
Return the result of performing the given mathematical operation.  and / have special meaning when given only one argument: ( 10) = 10 and (/ 10) = 1/10. 
The procedures deal with building and accessing compound data types: lists and cons cells.
(cons {first} {rest}) 
Construct a conscell with {first} as the "car" and {rest} as the "cdr". 
(car {conscell}) 
Get the "first" part of {conscell}. 
(cdr {conscell}) 
Get the "rest" part of {conscell}. 
(list {e1} {e2} ... {en}) 
Build a proper list of all the elements. The list will be a chain of n conscells, where the "car" of each points to one element, and the "cdr" of each points to the next conscell. The "cdr" of the last conscell is '(). 
(null? {thing}) 
Return #t if {thing} is nil (= '()), #f otherwise. 
(pair? {thing}) 
Return #t if {thing} is a conscell, #f otherwise. 
(display {e}) 
Display the result of evaluating {e}, in the interpreter window. 
(newline) 
Display a linefeed (i.e. go on to the next line.) 
(string>list {string}) 
Convert the string to a list of characters: (string>list "foo") is '(#\f #\o #\o) 
(char=? {char1} {char2}) 
Return #t if the two operands evaluate to the same character. Uppercase versus lowercase does matter. 