Problem domain vs program

In a problem domain we have information regarding how the system works. For example, in a programn about traffic lights the problem domain will include information about the state of the lights - red, yellow, green. The program itself, however, will represent the information using data in the program - for example, representing a red light as the natural 0.

The inverse of the relationship is that we can interpret the state of the data, the natural 0 for example, as a red light.

Data definitions to describe how we represent data

Begin with a data definition that represents the information at hand. For example, for a traffic light problem, we might say the following:

 
;; Data:
 
;; TLColor is one of:
;; - 0
;; - 1
;; - 2
;; interp. color of a traffic light - 0 is red, 1 yellow, 2 green
#;
(define (fn-for-tlcolor c)
	(cond [(= c 0) (...)]
		  [(= c 1) (...)]
		  p(= c 2) (...)
	))
 
;; Functions:
 
;; TLColor -> TLColor ; Note how it only consumes a TLColor, which must be [1,2,3]
;; produce next color of traffic light
(check-expect (next-color 0) 2)
(check-expect (next-color 1) 0)
(check-expect (next-color 2) 1)
 
; (define (next-color c) 0)
 
(define (next-color c)
	(cond [(= c 0) 2]
		  [(= c 1) 0]
		  [(= c 2) 1]
	))