Fundamentals of CS I (CS151 2001S)
[Current]
[Discussions]
[Glance]
[Honesty]
[Instructions]
[Links]
[News]
[Search]
[Syllabus]
Primary
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Quizzes]
[Readings]
[Reference]
Sets
[Blackboard]
[Scheme Report]
[SamR's Schedule]
[Rebelsky/Fall 2000]
[Walker/Fall2000]
[Stone/Spring2000]
Links
a. Review the corresponding notes on
letrec and named let.
b. Start DrScheme.
Write a letrec-expression in which (a) the identifier
last-of-list is locally bound to a procedure that finds and
returns the last element of a given list, and (b) the body of the
expression computes the sum of the last elements of the lists
(3 8 2), (7), and
(8 5 9 8), invoking
last-of-list three times.
A non-empty list is an s-n-alternator if its elements are alternately symbols and numbers, beginning with a symbol. It is an n-s-alternator if its elements are alternately numbers and symbols, beginning with a number.
Write a letrec-expression in which (a) the identifiers
s-n-alternator? and n-s-alternator? are bound to
mutually recursive predicates, each of which determines whether a given
non-empty list has the indicated characteristic, and (b) the body invokes
each of these predicates to determine whether the list (2 a 3 b 4 c
5) fits either description.
As you may recall, Iota takes a natural number as argument
and returns a list of all the lesser natural numbers in ascending order.
a. Define and test a version of the iota procedure that uses
letrec to pack an appropriate kernel inside a husk that
performs precondition testing.
b. Define and test a version of the iota procedure that uses
a named let.
Define and test a procedure named take that takes a list
ls and a non-negative integer len as arguments
and returns a list consisting of the first len elements of
ls, in their original order. The procedure should signal an
error if ls is not a list, if len is not an exact
integer, if len is negative, or if len is greater
than the length of ls.
a. Define and test a procedure named intersection that takes two
lists of symbols, left and right, as arguments
and returns a list of which the elements are precisely those symbols that
are elements of both left and right.
b. What does your proceduer do if a symbol appears in both lists and appears more than once in one or both of the lists?
Monday, 24 October 2000
http://www.cs.grinnell.edu/~stone/courses/scheme/local-binding-and-recursion.xhtml
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2000F/Labs/letrec.html
Wednesday, 14 March 2001
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/Labs/letrec.html
[Current]
[Discussions]
[Glance]
[Honesty]
[Instructions]
[Links]
[News]
[Search]
[Syllabus]
Primary
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Quizzes]
[Readings]
[Reference]
Sets
[Blackboard]
[Scheme Report]
[SamR's Schedule]
[Rebelsky/Fall 2000]
[Walker/Fall2000]
[Stone/Spring2000]
Links
Disclaimer: I usually create these pages on the fly. This means that they are rarely proofread and may contain bad grammar and incorrect details. It also means that I may update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.
This page was generated by Siteweaver on Thu May 3 23:07:50 2001.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/letrec.html.
You may validate
this page's HTML.
The source was last modified Wed Mar 14 08:09:11 2001.