Created
January 12, 2013 06:57
-
-
Save ageldama/4516496 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defprotocol Fruit | |
| (subtotal [item])) | |
| (extend-type Orange | |
| Fruit | |
| (subtotal [item] (* 98 (:qty item)))) | |
| ;;; 'coupon' is the function returing a 'reify' of subtotal. This is | |
| ;;; when someone uses a coupon ticket, the price of some fruits is | |
| ;;; taken off 25%. | |
| (defn coupon [item] | |
| (reify Fruit (subtotal [_] (int (* 0.75 (subtotal item)))))) | |
| (subtotal (Orange. 10)) | |
| (subtotal (coupon (Orange. 10))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment