CSC151.02 2010S Functional Problem Solving : Reference
Primary: [Front Door] [Schedule] - [Academic Honesty] [Instructions]
Current: [Outline] [EBoard] [Reading] [Lab] - [Assignment] [Quiz]
Groupings: [Assignments] [EBoards] [Examples] [Exams] [Handouts] [Labs] [Outlines] [Projects] [Quizzes] [Readings]
References: [A-Z] [By Topic] - [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [CSC151.01 2010S (Weinman)] [CSC151 2009F (Rebelsky)]
Misc: [SamR] [MediaScript] [GIMP]
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.
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
.
Primary: [Front Door] [Schedule] - [Academic Honesty] [Instructions]
Current: [Outline] [EBoard] [Reading] [Lab] - [Assignment] [Quiz]
Groupings: [Assignments] [EBoards] [Examples] [Exams] [Handouts] [Labs] [Outlines] [Projects] [Quizzes] [Readings]
References: [A-Z] [By Topic] - [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [CSC151.01 2010S (Weinman)] [CSC151 2009F (Rebelsky)]
Misc: [SamR] [MediaScript] [GIMP]
Copyright (c) 2007-10 Janet Davis, Matthew Kluber, Samuel A. Rebelsky, and Jerod Weinman. (Selected materials copyright by John David Stone and Henry Walker and used by permission.)
This material is based upon work partially supported by the National Science Foundation under Grant No. CCLI-0633090. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.
This work is licensed under a Creative Commons
Attribution-NonCommercial 2.5 License. To view a copy of this
license, visit http://creativecommons.org/licenses/by-nc/2.5/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.