Data Definition Guidelines

Data Definition Guidelines - Data Definition Guidelines :...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Data Definition Guidelines : Structures Example : a structure for capturing the name, weight, and favorite food for a boa Data definition format : ;; A boa is a ;; (make-boa symbol number symbol) (define-struct boa (name weight food)) Template format : the template pulls out all the fields from the structure (define (fun-for-boa a-boa) (boa-name a-boa) . .. (boa-weight a-boa) . .. (boa-food a-boa) . .. )
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Data Definition Guidelines : Mixed Data Example : a data definition for capturing various animals (boas, dillos, etc) Data definition format : ;; An animal is ;; - a boa, or ;; - a dillo Note that no define-structs are needed because we are only naming a set of possible animals. We are not introducing any new kinds of structures (assuming that boas and dillos are already defined). Template format : the template does two things: decides which case of data we have pulls out any pieces of each kind of data (define (fun-for-animal an-ani) (cond [(boa? an-ani) ... (boa-name an-ani) . .. (boa-weight an-ani) . .. (boa-food an-ani) . .. ] [(dillo? an-ani) . .. (dillo-weight an-ani) . .. (dillo-dead? an-ani) . .. ])) Note how this builds on templates for structures: within each case, if the case captures a structure, we pull out the same information as in the template for that structure.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

Data Definition Guidelines - Data Definition Guidelines :...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online