![]() |
![]() |
|
Due:
Feb.18 (Fri.) 23:59
Your submitted file should be named “hw04.rkt”
Some handy predicates: For your signatures, you can use built-in predicates like string?. Some other handy predicates aren't built-in, but feel free to use them anyway: For some handy type-predicates to help your signatures, natural?, non-negative-real?, and non-empty-string?. And if you want to actually call those functions, you can easily write them yourself, or you can download (right-click) and then (require "student-extras.rkt").
A team is:
- a name (non-empty string), AND
- an offense rating (real number), AND
- a defense rating (real number).
Follow steps 1-3 of the design recipe (including template).
Remember that a datatype definition can be a define-struct which
includes, after each field-name, a type-predicate in an expression-comment #;
.
Give at least three examples of a team.
We’ll say one team is “greater” than another if its offense is higher than the other’s defense, and its defense is higher than the other’s offense. Write the function team>? to implement this. Follow all the steps of the design recipe1. As always, be sure to think about enough test-cases to cover the interesting situations (half of the pts). (In this case, six or seven should suffice, if they each cover a different situation.)
Various rovers on Mars (Curiosity) and the moon (Yutu 2) take scientific measurements, including oxygen-levels in the atmosphere (indicating the capability to support life), and actual signs of life (by-products like methane, or perhaps finding actual bacteria or other life!) Occasionally, the equipment might malfunction and give no result.
A rover-measurement is one of:
In turn, a lifesign is one of:
hint: For life-signs, I used symbols for chemicals, and strings for specie-names. This let my code distinguish the two variants easily, as types.
Write the function lifesign-strength.
hint: In addition to string-length and max, symbol->string will be helpful.
hint: Figuring out exactly what your code needs to do becomes easier after writing your unit-tests.
remember: Follow all steps of the design recipe as appropriate, of course. If handling a union-type, and one variant happens to itself be another union-type, a helper-function is more appropriate than having one function which does all the details of two different union types.
“One function, one task”: If a concept like "lifesign strength" is its own definition (described in its own paragraph above), then good design suggests it’s probably worth its own function, rather than being anonymously folded into a larger function that does even more.
Standard instructions for all homeworks:
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |