Representing Information as Data�Part I: Scalar, Itemization, and Partition Data
CS 5010 Program Design Paradigms “Bootcamp”
Lesson 1.3
© Mitchell Wand, 2012-2013
This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License.
Learning Objectives for Lessons 1.3-1.4
Information Analysis and Data Design
Let’s recall what we learned about this step in the last lesson.
Information and Data
Information
Data
representation
interpretation
Information Analysis
Some of the information about a classroom
Classroom Scheduling Application
If we were writing a classroom scheduling application, what information would we need to represent?
HVAC Application
(Heating, Ventilation, and Air-Conditioning)
If we were writing an application to control the heating, ventilation, and air-conditioning, what information would we need to represent?
Building Maintenance Application
If we were writing a building maintenance application, what information would we need to represent?
Data Design
Kinds of Information
We’ll do 1-3 in this lesson, and 4-5 in the next lesson
1. Scalar Information
2. Itemization Information
Sample Data Definition for Itemization Information
A TLState is one of
-- "red"
-- "yellow"
-- "green"
We use CamelCase for names of kinds of data
Itemization Data was called “Enumeration Data” in HtDP 1/e.
interpretation is obvious, so it’s not necessary here. We'll get to more complicated examples later.
Video: How to write a template for itemization data
Itemization Data: Example
;; A TLState is one of
;; -- "red" interp: the traffic light is red
;; -- "yellow" interp: the traffic light is yellow
;; -- "green" interp: the traffic light is green
;; tls-fn : TLState -> ??
;(define (tls-fn tls)
; (cond
; [(string=? tls "red") ...]
; [(string=? tls "yellow") ...]
; [(string=? tls "green") ...]))
Write it without comments, then comment it
Templates give us the shape of the program
3. Partition Information
Partition Data
Data Definitions for Partition Data: Example 1
;; A TaxableIncome is a partition of NonNegInt into
;; the following categories:
;; [0-10000) interp: low income
;; [10000,20000) interp: medium income
;; all others interp: high income
;; taxable-income-fn : TaxableIncome -> ??
;; (define (taxable-income-fn income)
;; (cond
;; [(< income 10000) ...]
;; [(and
;; (<= 10000 income)
;; (< income 20000)) ...]
;; [else ...]))
Every positive number falls into exactly one of these categories
The predicates in the cond clause distinguish between them
Data Definition for Partition Data: Example 2
;; An FallingCatKeyEvent is a partition of
;; KeyEvent into the following categories:
;; -- " " (interp: pause/unpause)
;; -- any other KeyEvent (interp: ignore)
;; cat-kev-fn : FallingCatKeyEvent -> ??
(define (cat-kev-fn kev)
(cond
[(string=? kev " ") ...]
[else ...]))
Itemization Data vs. Partition Data: how to tell the difference
Summary
To be covered in the next lesson
Next Steps