;; ^ 在 Clojure 中并不是运算符,而是元数据语法,
;; bit-xor 则是普通函数。因此为自己的类型提供“额外运算符”,
;; 说到底也只是再写一个具名函数。
(defrecord Point [x y])
(defn p-pow [p n]
(->Point (long (Math/pow (:x p) n))
(long (Math/pow (:y p) n))))
(def p1 (p-pow (->Point 2 3) 3))
;; p1 is 8, 27
(def p2 (p-pow (->Point 2 3) 2))
;; p2 is 4, 9
(println "p1 is" (:x p1) (:y p1))
(println "p2 is" (:x p2) (:y p2))