Vocabulary of Minimal Scheme

Outline


Functions, Operators, and Programs

I use the words "function", "operator", and "program" almost interchangeably. All three words mean "something that takes in some information, does some computation, and produces some information as a result".

The word "operator" tends to be used for built-in arithmetic functions like addition, subtraction, multiplication, division, square root, and comparison. The word "program" tends to be used for functions you or I have defined. The word "function" applies equally to both. Don't worry too much about this distinction.

For example, consider the familiar arithmetic operators "+", "-", etc. from grade school: in the algebraic expression 3 + 4, the operator "+" operates on the two pieces of information "3" and "4" and produces the result "7".

Arithmetic operators

Examples:

Predefined numeric constants
The define keyword

The define keyword is used in two common ways: defining variables and defining functions.

Boolean operators

Examples:

(or (<= price 10.00) (symbol=? my-symbol 'bluebird))
Legal. This determines whether price is less than or equal to 10.00; if so, it returns true. If not, it then tests whether my-symbol is the symbol 'bluebird; if so, it returns true, otherwise false.
(or 3 4)
Illegal because or works on booleans, not numbers
(< true false)
Illegal because < works on numbers, not booleans
(+ 3 (< 4 5))
The first step of simplification turns this into (+ 3 true), because the value of (< 4 5) is true. The second step fails because + only works on numbers, not on a number and a boolean.
Conditionals

Scheme contains several conditional constructs, but the only one we need in this course is cond.

Defining structures

The define-struct keyword allows you to add new aggregate data types to the language.

Graphics

Note: to use any of these functions, you need to load the image.ss teachpack (or the world.ss teachpack, which includes all the same stuff and more). See also Dr. Felleisen's exercises on animation worlds.

See updated documentation for the image teachpack. (I'll add some of my own if I think it necessary.)

Lists

Examples:

(cons 'bluebird empty)
returns exactly the same thing
(define bird-list (cons 'bluebird (cons 'mallard (cons 'crow empty)))
returns nothing, but defines bird-list to be a list of three symbols.
bird-list
returns (cons 'bluebird (cons 'mallard (cons 'crow empty)))
(first bird-list)
returns 'bluebird
(rest bird-list)
returns (cons 'mallard (cons 'crow empty))
(first (rest bird-list))
returns 'mallard
(rest (first bird-list))
produces an error message: (first bird-list) returns the symbol 'bluebird, but rest can only be applied to a non-empty list, not a symbol.
Note: A one-element list is not the same thing as that one element, e.g. 'bluebird is a symbol, whereas (cons 'bluebird empty) is a list whose one element is a symbol.
(empty? bird-list)
returns false
(cons? bird-list)
returns true
(empty? (rest (rest (rest bird-list))))
returns true
(list 'bluebird 'mallard 'crow)
returns the exact same list as (cons 'bluebird (cons 'mallard (cons 'crow empty))).
(list 'bluebird (list 'mallard (list 'crow empty)))
is a perfectly legal list, but it's probably not what you meant; in particular, it is not the same list as in the previous example. In fact, this is a list of two (not three) elements, the second of which is itself a list of two elements, the second of which is a list of two elements, the second of which is an empty list.

Last modified: Wed Jun 13 11:26:59 EDT 2001
Stephen Bloch / sbloch@adelphi.edu