Hi,
Baishampayan beat me to it. But to elaborate more:
You have to expose each contract up the function chain. Say it looks like
this:
(defn calculate-insurance
[& items]
{:pre [(every? #(contains? % :cost-replace-with-new) items)]}
...)
Then funcE and funcD have to check this also. funcC doesn't because it adds
said key to the data structure. If you change funcC to not add it, you'll
also have to change funcC's contract. So you'd find the error in the call
to funcD in funcC which is the first possible place to spot it (in case the
change of contract was missed). If you'd change the contracts of the
complete function chain, you'd spot it immediatelly in funcA.
This is similar to changing the type of the items from Insurable to
WrappedInsurableAdapter or such. There are things which bubble up.
If you'd want something more akin classes and interfaces, you could use
defrecord with (partial satisfies? PInsurable).
Sincerely
Meikel
/me is waiting for David and Ambrose coming up with contract checker
written in core.logic.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en