Back Summary

Session #10

Multiple choice: 15/15 correct ยท Short answer: 5/5 answered · completed Sep 7, 2026

Answers

What is the main purpose of a data definition?

✓ To document how problem-domain information is represented as program data

Which chain best matches the design principle in the notes?

✓ Information structure -> data structure -> template structure -> function structure

When is an enumeration appropriate?

✓ When information is one of a fixed number of distinct cases

Which type comment describes an inclusive integer interval from 1 through 32?

✓ Integer[1,32]

What is the template shape for an atomic non-distinct type such as CityName is String?

✓ A single body placeholder using the value

What makes an itemization different from a simple enumeration?

✓ At least one subclass is not a single distinct value

How does cond choose an answer?

✓ It evaluates questions in order and uses the answer for the first true question

Why might an itemization cond use (and (number? c) (<= 1 c) ...)?

✓ To guard numeric operations so they are not applied to non-numbers

Why can the last numeric subclass sometimes be tested with only (number? c)?

✓ Because the type comment guarantees that any legal remaining number belongs to that subclass

What does it mean that HtDF and HtDD are orthogonal?

✓ The function-design recipe remains largely the same while different data definitions supply different templates

If LetterGrade has exactly "A", "B", and "C", how many main cond branches should its template have?

✓ 3

What is the interpretation in a data definition for?

✓ To state how the represented data corresponds to information in the problem domain

A function consumes SeatNum defined as Integer[1,32]. Is 50 a legal input according to the data definition?

✓ No because it is outside the SeatNum interval

Which statement correctly distinguishes purpose from interpretation?

✓ Purpose belongs to function design; interpretation belongs to data design

Why should tests for an itemization cover every subclass?

✓ Because the data definition identifies distinct forms that can drive different function behavior

Define a data definition named LetterGrade that represents exactly the three strings "A", "B", and "C". Include the type comment, an interpretation, and the template for a function that consumes a LetterGrade.

; LetterGrade is an enumeration
; - "A"
; - "B"
; - "C"
; Represents the letter grade as either A, B or C
(define (fn-for-letter-grade l)
  (cond [(string=? "A" l) (l)]
        [(string=? "B" l) (l)]
        [else l]))
not graded

Accepted answer

; LetterGrade is one of:
; - "A"
; - "B"
; - "C"
; interp. a letter grade earned by a student
#;
(define (fn-for-letter-grade lg)
(cond [(string=? lg "A") (...)]
[(string=? lg "B") (...)]
[(string=? lg "C") (...)]))

Define a data definition named SeatNum for legal seat numbers from 1 through 32 inclusive. Include the type comment, an interpretation, and the basic template for a function that consumes a SeatNum.

; SeatNum is Number
; SeatNum represents the number of a seat from 1 to 32 inclusive
(define (fn-on-seat-num n) n)
not graded

Accepted answer

; SeatNum is Integer[1,32]
; interp. the number of a legal seat
#;
(define (fn-for-seat-num sn)
(... sn))

Consider this itemization: Status is one of "closed" or an Integer from 1 through 10 inclusive. Write a template for a function that consumes a Status. Make sure the numeric test cannot accidentally be applied to the string case.

; Status is Enumeration
; - "closed"
; - [1, 10]
; Status represents the value until closed or the closed value itself
(define (fn-on-status s)
(cond [(number? s) (s)]
      [else s]))
not graded

Accepted answer

#;
(define (fn-for-status s)
(cond [(and (string? s) (string=? s "closed")) (...)]
[(and (integer? s) (<= 1 s) (<= s 10)) (... s)]))
A simpler first branch such as (string=? s "closed") is also acceptable if it is guaranteed to be reached only for strings.

In your own words, explain the difference between a function purpose statement and the interpretation in a data definition.

the function purpose is what the function is suppose to do or the relationship between the input data and the output data. Interpretation of the data is how that data is suppose to represent the information about the problem domain

not graded

Accepted answer

A function purpose describes the relationship between the data a particular function consumes and the result it produces. A data interpretation explains what values of the data definition mean as information in the problem domain.

Suppose an itemization says a value is either Integer[0,10] or Integer[5,20]. What problem does the value 7 create? If a cond checks the first interval before the second, what will happen?

You can tell which interval the 7 belongs to so you need to redo the data definition

not graded

Accepted answer

The subclasses overlap, so 7 belongs to both and the data definition does not uniquely identify which subclass it represents. A cond uses the first true clause, so if the 0-to-10 interval is checked first, 7 will always be handled by that first branch. The itemization should normally be redesigned so its cases are unambiguous, or the intended priority must be made explicit.