RU beehive logo promo banner for Computing & Info Sciences
ITEC 380
2022fall
ibarland

union-of-structs

Review (optional): video: a struct for DVDs (6m50s)

Another example of using structs to represent DVDs (and practice using the design recipe). The dvd struct will be used, along with book, in the following examples.
code: The initial version to follow along and type in yourself (starting around line 80, the datatype def'n for dvd); and, the completed code


Making a lib-item: video: union-of-structs (35m30s)

In the template for a union-type, if we are in a branch where we know we have a struct, let's go ahead and pull out the fields of that struct right here in that cond-branch.
code: The initial version to follow along and type in yourself (starting around line 100, the datatype def'n for lib-item); and, the completed code

Practice for class-discussion: htdp: spiders, dillos, and more

Note: “girth” means circumference


But don't nest other templates; call a helper-function rather than process a union-type inside a struct-type-handling-function. video (23m53s)


Source code: see the last part of union-of-structs.rkt.

Here is a programming-contest-problem (for Google Hashcode) which clearly asks for a union of structs: City Plans.


logo for creative commons by-attribution license
This page licensed CC-BY 4.0 Ian Barland
Page last generated
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.