diff --git a/content/cftbat/multimethods-records-protocols.html b/content/cftbat/multimethods-records-protocols.html index 9bc5da9c..75ff42af 100644 --- a/content/cftbat/multimethods-records-protocols.html +++ b/content/cftbat/multimethods-records-protocols.html @@ -108,7 +108,7 @@

Protocols

(feelings-about [x] [x & others])
 
-

By defining a protocol, you’re defining an abstraction, but you haven’t yet defined how that abstraction is implemented. It’s like you’re reserving names for behavior (in this example, you’re reserving thoughts and feelings), but you haven’t defined what exactly the behavior should be. If you were to evaluate (thoughts "blorb"), you would get an exception that reads, “No implementation of method: thoughts of protocol: data-psychology/Psychodynamics found for class: java.lang.String.” Protocols dispatch on the first argument’s type, so when you call (thoughts "blorb"), Clojure tries to look up the implementation of the thoughts method for strings, and fails.

+

By defining a protocol, you’re defining an abstraction, but you haven’t yet defined how that abstraction is implemented. It’s like you’re reserving names for behavior (in this example, you’re reserving thoughts and feelings-about), but you haven’t defined what exactly the behavior should be. If you were to evaluate (thoughts "blorb"), you would get an exception that reads, “No implementation of method: thoughts of protocol: data-psychology/Psychodynamics found for class: java.lang.String.” Protocols dispatch on the first argument’s type, so when you call (thoughts "blorb"), Clojure tries to look up the implementation of the thoughts method for strings, and fails.

You can fix this sorry state of affairs by extending the string data type to implement the Psychodynamics protocol:

 (extend-type java.lang.String
    Psychodynamics