CS 61A Scheme
Spring 2020 Discussion 9: April 1, 2020 Solutions
1 Introduction
In the next part of the course, we will be working with the Scheme programming
language. In addition to learning how to write Scheme programs, we will eventually
write a Scheme interpreter in Project 4!
Scheme is a dialect of the Lisp programming language, a language dating back
to 1958. The popularity of Scheme within the programming language community
stems from its simplicity – in fact, previous versions of CS 61A were taught in the
Scheme language.
2 Primitives and Defining Variables
Scheme has a set of atomic primitive expressions. Atomic means that these expres-
sions cannot be divided up.
scm> 123
123
scm> #t
True
scm> #f
False
Unlike in Python, the only primitive in Scheme that is a false value is #f and its
equivalents, false and False. This means that 0 is not false.
The define special form defines variables and procedures by binding a value to a
variable, just like the assignment statement in Python. When a variable is defined,
the define special form returns a symbol of its name. A procedure is what we call
a function in Scheme!
The syntax to define a variable and procedure are:
• (define <variable name> <value>)
• (define (<function name> <parameters>) <function body>)
Special forms are types of expressions with unique evaluation rules that can do a
variety of things. Often times, speical forms are analagous to statements in Python,
such as assignment statements, if statements, and def statements. However, all
special forms in Scheme evaluate to a value. We’ll learn more about special forms
later in the discussion.