Functional Problem Solving (CSC 151 2014F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Readings]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Davis (2013F)] [Rebelsky (2014S)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
Overview
map, for-each, repeat, and recursion.There was enough difficulty on the quiz that it seems worth going over.
(define iota
(lambda (num)
(if (not (and (number? num)
(not (negative? num))
(integer? num)))
(error "iota expected a non-negative integer, given " num)]
(let kernel ([counter 0])
(if _______________
null
(cons _______________ (kernel ___________________)))))))
iota? Make a list of the numbers from 0 to num-1.(iota 5) '(0 1 2 3 4) (iota 1) '(0) (iota 0) '()
kernel is our recursive procedure.kernel seem to be? The part of the procedure
that does the real work, now that we know that the parameter is "safe".
Use the counter to make the list of the integers up to num-1.When counter is 0 and num is 3, should we do base case or recursive case? Recursive.
(let kernel ([counter 0])
(if _______________
null
(cons _______________ (kernel ___________________)))))))
What should the first parameter to cons in the recursive case be?
When we recurse, what should we do to counter? Add 1 (see above.)
(let kernel ([counter 0])
(if _______________
null
(cons counter (kernel (+ 1 counter))))))))
Can you generalize that last check?
(let kernel ([counter 0])
(if (= counter num)
null
(cons counter (kernel (+ 1 counter))))))))
(define whatzitdo
(lambda (vals)
(and (not (null? vals))
(or (odd? (car vals))
(whatzitdo (cdr vals))))))
map, for-each, repeat, and recursion