Académique Documents
Professionnel Documents
Culture Documents
a template
CS 5010 Program Design
Paradigms Bootcamp
Lesson 2.1
Mitchell Wand, 2012-2014
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
Data
Representatio
ns
Basics
Mixed Data
Recursive
Data
Functional
Data
Design
Strategies
Combine
simpler
functions
Use a
template
Divide into
Cases
Objects &
Classes
Call a more
general
function
Stateful
Objects
Communicate
via State
Module
02
Generalizatio
n
Over
Constants
Over
Expressions
Over
Contexts
Over Data
Representatio
ns
Over Method
Implementati
ons
Data
Representatio
ns
Basics
Mixed Data
Recursive
Data
Functional
Data
Design
Strategies
Combine
simpler
functions
Use a
template
Divide into
Cases
Objects &
Classes
Call a more
general
function
Stateful
Objects
Communicate
via State
Lesson
2.1
Generalizatio
n
Over
Constants
Over
Expressions
Over
Contexts
Over Data
Representatio
ns
Over Method
Implementati
ons
Introduction
In this lesson, we will show how to
take apart non-scalar data using the
destructor template for that type of
data.
This is the strategy you will use for
the vast majority of your functions.
Design Strategies
1. Combine simpler
functions
2. Use template for <data
def> on <vble>
3. Divide into cases on
<condition>
4. Use HOF <mapfn> on
<vble>
5. Call a more general5
function
Example: book-receipts
;;
;;
;;
;;
;;
;;
;;
;;
10
11
12
13
DATA DEFINITION:
a TrafficLightState (TLState) is one of
-- "red"
-- "yellow"
-- "green"
INTERPRETATION: self-evident
14
15
16
state)
"red")
...]
"yellow") ...]
"green") ...]))
17
state)
"red")
...]
"yellow") ...]
"green") ...]))
18
state)
"red")
...]
"yellow") ...]
"green") ...]))
19
state)
"red")
"green"]
"yellow") ...]
"green") ...]))
Answer (from
examples):
green
20
state)
"red")
"green"]
"yellow") "red"]
"green") ...]))
Answer (from
examples): red
21
state)
"red")
"green"]
Answer (from
"yellow") "red"]
examples):
"green") "yellow"]))
yellow
22
Next Steps
Study 02-1-book-receipts.rkt and 022-traffic-light.rkt in the Examples
folder.
Be sure to finish the previous-state
example in 02-2-traffic-light.rkt
25