February 2018
Intermediate to advanced
304 pages
7h 11m
English
Your interaction with the player so far has been represented by a single function, next-guess. It’s time to fill out that idea a bit more. There are many potential ways to implement either a human or computer player. Any time you determine a function is open for extension, you should strongly consider using a multimethod or protocol to make that possible.
In this case, you only have a single function, so either choice is viable. There might be a need for players to keep state (remembering what they’ve guessed), so protocols are a bit easier to use, by encapsulating that state in a record which extends the protocol.
So replace that function with a protocol:
| | (defprotocol Player |
| | (next-guess [player ... |
Read now
Unlock full access