CISC 108 Glossary
Stephen F. Siegel, University of Delaware
September 6, 2015
argument
an expression occurring in a function call that follows the function name and specifies
the “actual value” that will be substituted for the corresponding parameter in the
function definition. Every function call consists of an open parenthesis, followed by a
function name (or, more generally, an expression that evaluates to a function), followed
by a sequence of arguments, and finally a right parenthesis. For example, the function
call (f 2.7 (+ x y)) contains two arguments: 2.7 and (+ x y). The word argument
is also used to refer to the run-time value of such an expression. Returning to the
example above, if the function call is evaluated in a context where x is 2 and y is 3,
one could say “the second argument in the function call is 5.”
Boolean
a type of data consisting precisely of the two values #true and #false
clause
part of a cond expression consisting of a single question-answer pair. Every cond
expression consists of an open parenthesis, followed by the word cond, followed by a
sequence of clauses, and finally a right parenthesis. A clause is usually delineated by
square brackets. For example, the cond expression
(cond
[(> x 0) 1]
[(< x 0) -1] [else 0]) contains three clauses: [(> x 0) 1], [(< x 0) -1], and [else 0]. comment part of a program that is ignored by the programming environment when evaluating the program, but provides additional information to a human reading the program. Comments may be inserted using a semi-colon, among other ways. constant definition a definition that assigns a value to a variable that will never change. For example, (define TAX-RATE 0.28). constructor a function, introduced automatically by a structure definition, that produces a value of that structure type from the given components. For example, the structure definition for EmployeeRecord (see structure definition) automatically defines the constructor 1 ;; make-employee-record: String Number -> EmployeeRecord
which, as the signature above indicates, consumes a String and a Number and produces
an EmployeeRecord.
design recipe
a specified methodical process for constructing a program or a component of a program
together with documentation and tests
enumeration
a type which is specified by an explicit finite list of elements, e.g.,
;; A TrafficLight shows one of three colors:
;; – “red”
;; – “green”
;; – “yellow”
;; interpretation each element of TrafficLight represents which colored
;; bulb is currently turned on
expression
a syntactic unit of code that may be evaluated to yield a value. Examples of expressions
include atomic expressions such as 5, 3.14, #true, and “hello”, as well as compound
expressions such as (* (+ 2 3) 4), and (image-width DOG).
function body
an expression which is part of a function definition and occurs immediately after the
header. The body specifies what the function will compute and produce when it is
called. For example, in the function definition of mags (see function definition), the
body is (+ (* x x) (* y y)).
function call
an expression which consists of an open parenthesis followed by a function name (or,
more generally, an expression which evaluates to a function), followed by zero or more
expressions (known as arguments), followed by a right parenthesis. To evaluate a
function call, the arguments are first evaluated, then the resulting values are substituted
for the corresponding parameters in the function body, and the resulting expression is
evaluated. An example of a function call is (mags (+ 1 1) 3), where mags is defined
in the entry for function definition. To evaluate that function call, the arguments are
evaluated, yielding 2 and 3; these are substituted for x and y in the function body to
yield the expression (+ (* 2 2) (* 3 3)), which evaluates to 13. A function call is
also known as a function application.
function definition
a syntactic unit of code which specifies what a function computes and produces. Syn-
tactically, a function definition consists of the following items, in order: a left parenthe-
sis, the word define, a left parenthesis, the function name, zero or more parameters, a
right parenthesis, the function body, and a right parenthesis. An example of a function
definition is:
2
(define (mags x y)
(+ (* x x) (* y y)))
function
an abstract machine which consumes data, performs a computation, and produces a
result.
header
the part of a function definition that includes only the name of the function and
the names of its parameters. Specifically, the header begins with the left parenthesis
immediately following define and ending with the right parenthesis immediately after
the last parameter. For example, the header in the definition of mags (see function
definition) is (mags x y).
interval
a type of data consisting of either integer or real numbers specified by minimum and
maximum values. Intervals are often denoted using interval notation, which specifies
the minimum and maximum values as an ordered pair, and uses parentheses for an
“open” (exclusive) end-point, and square brackets for a “closed” (inclusive) end-point.
For example, the integer interval denoted (2, 5] consists of the numbers 3, 4, and 5; this
interval is said to be “open on the left” and “closed on the right”. The real interval
(2, 5] consists of all real numbers x for which x > 2 and x ≤ 5; in particular, 2 is
not in that interval, but 2.00001 is. Notice that the interval notation does not specify
whether an interval is integer or real, so this must be made clear some other way.
itemization
a type of data which is specified as the union of other types. For example, the following
defines an itemization called “NoS”:
;; a NumberOrString (NoS) is one of:
;; – Number
;; – String
Hence 3.1415 is a Number and is also an NoS. The string “hello” is a String and is
also an NoS. Itemizations are sometimes referred to as mixtures or union types.
parameter
a variable used as a “place-holder” in the header of a function definition, representing
a value the function will consume when it is called. For example, the parameters in
the definition of mags (see function definition) are x and y. The parameters may also
appear (and usually do) in the function body.
predicate
a function which consumes some data and determines whether that data belongs to
some type. A predicate always returns a Boolean value, i.e., it returns either #true
or #false. Examples of predicates include number? (which determines if an object is
3
a Number), and string? (which determines if an object is a String). Each structure
definition also introduces, automatically, a predicate for the new structure type; the
name of the predicate will be the name of the structure type followed by the ? symbol.
For example, if the name of the structure is employee-record, the predicate will be
named employee-record?. By convention, predicate names always end in ‘?’.
purpose statement
documentation associated to a function definition which explains what the function
consumes, computes, and produces. A well-designed purpose statement explicitly lists
each parameter, specifies the type and interpretation of that parameter, and explicitly
states what the function produces. The purpose statement typically comes right after
the function signature. The following example consists of a function signature and
purpose statement:
;; add-subtitle: Image String -> Image
;; Consumes:
;; Image an-image: a rectangular image to which subtitle will be added
;; String content: the text of the subtitle
;; Produces: a new Image produced by converting content to 18-point
;; blue type and placing it over an-image. The text will be
;; centered horizontally and positioned vertically at 85% of the
;; height of an-image from the top.
selector
a function, introduced automatically by a structure definition, which consumes an
object of the structure type and produces one of the components of that structure.
For example, the structure definition for EmployeeRecord (see structure definition)
introduces two selectors, with the following signatures:
;; employee-record-name: EmployeeRecord -> String
;; employee-record-id: EmployeeRecord -> Number
signature
a specification of the number and types of data a function consumes and the type
of data it produces. The signature is written by listing the input types, followed by
an arrow, followed by the output type. For example, a function which consumes two
numbers, a string, and an image (in that order), and produces an image, would have
signature
Number Number String Image -> Image
To express the fact that a function f has a signature T , one writes “f:T” (i.e., the
function name, followed by a colon, followed by the signature). For example,
add-text-to-image : Number Number String Image -> Image
4
says that the function add-text-to-image consumes two numbers, a string, and an
image, and produces an image.
string
a type of data comprised of a sequence of characters. Characters include upper and
lower case letters, punctuation marks, digits, and even symbols from alphabets from
all over the world. Literal string values are denoted by surrounding the character
sequence with double quotes, e.g., “hello”. When used as the name of a type, e.g., in
a signature, the word is usually capitalized, as in String.
structure definition
a definition of a type consisting of a finite set of name-type pairs (fields). An object
of that type contains one value of the approrpiate type for each field. For example, in
the following structure definition:
;; An EmployeeRecord is a (make-employee-record name id)
;; interpretation:
;; – name (String): the employee’s full name
;; – id (Number) : the employee’s ID number
(define-struct employee-record (name id))
there are two fields, one named name with type String and one named id with type
Number. A single value of type EmployeeRecord (sometimes referred to simply as
“an EmployeeRecord”, or “an EmployeeRecord structure”) contains both a name and
an ID component. These components can be extracted from the structure using the
appropriate selectors. A structure definition automatically generates a constructor,
selectors for each field, and a predicate.
stub
a syntactically complete but usually incorrect definition of a function returning a trivial
value of the correct type. A stub for the function mags (see function definition) could
be
(define (mags x y)
0)
because mags produces a Number, and 0 is a Number. A program containing this
stub will compile and execute, though tests using mags will likely fail. It is common
practice, when designing a function, to start with a stub, and then write unit tests for
the function. The tests should be runnable, but will likely fail. Then as the function
definition is developed from the stub, the tests can be re-run at various points during
the process.
template
a general pattern for a function definition of a particular kind, often expressed us-
ing ellipses (“…”) to indicate parts that must be filled in on a case-by-case basis.
5
For example, a template for a function consuming an EmployeeRecord (see structure
definition) is
;; employee-record-fun: EmployeeRecord -> …
(define (employee-record-fun erec)
( … (employee-record-name erec) …
… (employee-record-id erec) … ))
This template indicates that the function definition probably combines the expressions
(employee-record-name erec) and (employee-record-id erec) in some way, but
the exact way must be determined by the particular circumstances of the problem
being solved. Note that a template is not syntactically correct code, so when included
in a file must be placed in a commented region.
type
a category of data. Examples include Number, String, Image, and Boolean. More
types can be defined as enumerations, intervals, itemizations, or structure definitions,
among other ways.
unit test
A test targeting a single function in a program. DrRacket provides several mech-
anisms for specifying unit tests. These include check-expect, check-random, and
check-within. A unit test typically specifies an actual and expected result, and the
test passes if the actual and expected results agree, else the test fails. For example,
the unit test
(check-expect (mags 3 4) 25)
will pass if and only if the function call (mags 3 4) returns 25.
variable
a named program element used to represent a value. There are several different kinds
of variables, including those defined in a constant definition and function parameters.
6