Functional Problem Solving (CSC 151 2015F) : Reference
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric] [Remote Access]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Curtsinger (2015F)] [Davis (2013F)] [Rebelsky (2015S)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
Believe it or not, but every list operation (more or less) can be defined in terms of these five basic operations.
null
(cons
value
lst
)
value
to the front of lst
.
(cdr
lst
)
lst
but without
the first element. (car
lst
)
lst
.
(null?
lst
)
lst
is the empty list.
(list
val_0
val_1
...
val_n
)
n
+1 of the form
(val_0
val_1
... val_n
)
.
(make-list
n
val
)
n
copies of val
.
(list-drop
lst
n
)
n
elements of lst
.
(list-take
lst
n
)
n
elements of lst
.
(for-each
proc!
lst
)
proc!
to each element of the
given list. Called primarily for side effects.
(map
func
lst
)
func
to the corresponding element of
lst
.
Most of these are forthcoming.
(list-ref
lst
n
)
n
th element of
lst
. Note that elements are numbered
starting at 0.
(reverse
lst
)
lst
, but in the opposite order.
(member?
val
lst
)
val
appears in
lst
. If so, returns true
(#t
). If not, returns false
(#f
).
(member
val
lst
)
val
appears in
lst
. If so, returns the sublist
that starts with val
.
If not, returns false
(#f
).
car
and cdr
(caar
lst
)
lst
's first element is a list,
gets the first element of that first element, the
the car
of the car
of lst
. If
lst
is not a list, or its first element
is not a list, reports an error.
(cadr
lst
)
lst
,
the car
of the cdr
of lst
(cddr
lst
)
lst
,
the cdr
of the cdr
of lst
(caddr
lst
)
lst
,
the car
of the cdr
of the cdr
of lst
.