Перегрузка операторов

;; + cannot be overloaded, but a protocol gives one NAME that
;; several types may answer to - that is the Clojure way to
;; "add two points"
(defprotocol Addable
  (v+ [a b]))

(defrecord Point [x y]
  Addable
  (v+ [a b] (->Point (+ (:x a) (:x b))
                     (+ (:y a) (:y b)))))

(def p3 (v+ (->Point 1 1) (->Point 2 2)))
;; p3 is 3, 3
(def p4 (v+ p3 (->Point 3 5)))
;; p4 is 6, 8

;; there is no "+=" either: values are immutable, v+ returns a new one
(println "p3 is" (:x p3) (:y p3))
(println "p4 is" (:x p4) (:y p4))