CSC151, Class 19: Numeric Recursion
HAPPY BIRTHDAY AMANDA!
Overview:
* Questions and answers on list recursion
* Questions and answers on numeric recursion
* Lab
Notes:
* I'll be gone on Friday. Mr. Stone will be teaching the class.
* No new reading for Friday.
* Exam 1 distributed. The content of the problems is unlikely
to change. The wording may.
* Comments on class? EBoards? Web site?
* Notes on writeup 1.
3.14
(define pi 3.14)
(define sams-gpa 3.14)
....
----------------------------------------
Confusion about the six P's
Procedure: Names the procedure
Parameters: Names and types the parameters
Purpose: A few sentences giving the intent
Produces: Names and types the result
Preconditions: What must hold in order for your procedure
to work reasonably (in addition to the typing).
Postconditions:
Guarantees about the result
"Returns a number"
(define square (lambda (x) 1)
Procedure:
swap-first-two
Parameters:
lst, a list with at least two elements.
Purpose:
Build a new list that resembles lst except that the first
two elements are swapped.
Produces:
newlst, a list
Preconditions:
[See above]
Postconditions:
lst is unchanged
(list-ref newlst 0) is the same as (list-ref lst 1)
(list-ref newlst 1) is the same as (list-ref lst 0)
(list-ref newlst x) is the same as (list-ref lst x)
"for all other reasonable x"
for 2 <= x < (length lst)