Function template for several-case output

If the data definition for the output reveals several possible cases, e.g.

Data definition:
A Mastermind score is one of the symbols
  1. 'perfect!
  2. 'OneColorAtCorrectPosition
  3. 'TheColorsOccur
  4. 'NothingCorrect
then the function body will (almost always) be a cond with the same number of clauses, with these outputs as the respective answers:
  (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.


Last modified: Thu Jan 20 11:16:58 EST 2000
Stephen Bloch / sbloch@adelphi.edu