![]() |
![]() |
|
Due:
Your submitted file should be named “hw03.rkt”.
We wish to write code about whether or not the Radford Highlanders won their basketball game, this last weekend. We want to capture: whether they won/lost, or tied, or there wasn't any game this weekend, or (if the game is still in-progress) what the name of the team currently being played is. (Oddly, we will not track the opposing team's name when the game isn't in progress1. Perhaps we don't care about such details once a game is over?)
Hint: To represent whether they won or lost, a boolean seems appropriate. What types seem appropriate for each of the other variants?
Hint: Of course, it is not “as appropriate” to return a string mentioning the Wytheville Wallabies when we're actually playing the Dublin Dingoes, or the Pulaski Pangolins! Recall from our data-definition in #1, agame-result should capable of representing, among other things, the name of a team (which therefore means that the game must be in-progress). (Moreover, this means your function does not need to be given any additional information, since thegame-result already represents the info you need.)
(10 pts) 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:
Some lifesigns are stronger indicators than others;
we'll say the "strength" of a lifesign
(on a scale of 0 to 1) is:
1.0 for a species,
and for by-products it's 0.1 per character
in the chemical-name
(with a maximum possible value of 1, of course).
(Longer, fancier chemical-names are more likely the result of an organic process?)
E.g.
hint: In addition tostring-length andmin ,maxsymbol->string will be helpful.
Write the function
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 (unless instructed otherwise):
(And on further thought, we'll also note that while opposing-team-name could conceivably be information worth tracking for several cases, it wouldn't make sense for no-game-this-week. This complicates a correct data-representation; more on that in class.)
↩This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |