RECAP: Discuss need to think about reuse and breaking up
problems *before* selecting a recipe. `check-guess-for-list',
for example, treats its argument list as an atomic entity
passed to `convert'.
WARM UP:
given a list of temperatures in C,
determine whether they are all between 0 and 100
LIST QUOTE
[Demo in DrScheme's intermediate language]
PROBLEM:
given a list of temperatures in C,
produce list of equivalent F temperatures
the program produces a list, it doesn't just consume one
; convert-temps : list-of-num -> list-of-num
; consume list of Celsius temps, produce list of equivalent Fahr
; temps
[Note: they wrote C->F in class on Monday]
SORT:
given a list of numbers,
produce a list of numbers with the exact same numbers,
but sorted in descending order
DON'T FORGET: compose functions/make up helpers!!!
AUXILIARY PROGRAMS:
(1) cond expressions are in-line
(2) auxiliary programs: if they encapsulate domain knowledge
(3) auxiliary programs: if they are required -- process arb-large data
-------------------------------------------------------------------
Structures in Lists: celestial bodies
;; a celestial-body is a structure
;; (make-celbody name relwgt photo)
;; where name is a symbol, relwgt is a num, photo is a picture
;; [leave picture undefined]
define list-of-celbody
set up template for program over celbody.
-- two data definitions, two templates
-- show arrow between data definitions
PROBLEM: LOOKUP picture of planet
(What happens if the lookup fails? We went with errors, but
false would have probably been better.)
|
LAB |