Whenever there is a complex data type inside a structure, the template should call that complex data type’s template function.
;; A RedBlackPurple (RBP) is one of:
;; - "red"
;; - "black"
;; - "purple"
;; Interpretation: available font colors
(define RED "red")
(define BLACK "black")
(define PURPLE "purple")
(define (rbp-template rbp)
(cond
[(string=? rbp RED) ...]
[(string=? rbp BLACK) ...]
[(string=? rbp PURPLE) ...]))
RBP is a complex data type.
(define-struct tm [str pos col])
;; A TextMover (TM) is a (make-tm String Position RBP)
;; - str is the text to be displayed
;; - pos is the location of the text
;; - col is the color of the text
;; Interpretation: all the information needed for the text-mover program.
(define TM-1 (make-tm "Hello" POSITION-1 RED))
(define TM-2 (make-tm "Husky" POSITION-2 BLACK))
(define TM-3 (make-tm "Bye" POSITION-3 PURPLE))
(define (tm-template tm)
(... (tm-str tm) ...
(position-template (tm-pos tm)) ...
(rbp-template (tm-col tm)) ...))
Note that in tm-template it is necessary to call rbp-template.