If the data definition for the output reveals several possible cases, e.g.
Data definition:then the function body will (almost always) be a cond with the same number of clauses, with these outputs as the respective answers:
A Mastermind score is one of the symbols
- 'perfect!
- 'OneColorAtCorrectPosition
- 'TheColorsOccur
- 'NothingCorrect
(define (check-guess target1 target2 guess1 guess2) (cond [... 'perfect!] [... 'OneColorAtCorrectPosition] [... 'TheColorsOccur] [... 'NothingCorrect]))Note that it may be more convenient to change the order -- you'll need to look at the "question" parts of the cond-clauses to decide that. It may also be more convenient to return the same answer in two different cases, e.g.
(define (check-guess target1 target2 guess1 guess2) (cond [... 'perfect!] [... 'OneColorAtCorrectPosition] [... 'OneColorAtCorrectPosition] [... 'TheColorsOccur] [... 'TheColorsOccur] [... 'NothingCorrect]))Again, this depends on the "question" parts of the cond-clauses.
Once you've written a function definition using this template, you can go through all the possible answers in the output data definition, and quickly and easily tell under what circumstances that kind of output will be produced. If some possible output doesn't appear in any of your cond-clauses, there's something wrong with your function.