(defrecord Musician [name instrument band]
Personalized
(name [this]
(:name this))
(describe [this]
(str (:name this) " plays " (:instrument this) " for " (:band this))))
(defrecord Employee [name position company]
Personalized
(name [this]
(:name this))
(describe [this]
(str (:name this) " works as a " (:position this) " for " (:company this))))
Use the polymorphic functions on both record types:
(def people [(->Musician"Ian Hill""Bass""Judas Priest")
(->Employee"Ashok""Intern""ACME Corp.")])
(map describe people)
;; ("Ian Hill plays Bass for Judas Priest";; "Ashok works as a Intern for ACME Corp.")
Implement the Shape protocol for two new record types: Rectangle
and Circle.
Hint: Use defprotocol; the Rectangle has a width and a height;
the Circle has a radius. Use Math/PI and Math/pow for
computing the circle’s area and circumference.
Define a protocol Body with a function volume that expects a
height parameter. Extend the Rectangle and Circle records to
implement Body. The function shall compute the volume of a cuboid
(Rectangle) and a cylinder (Circle).
Hint: Use extend-protocol. A cuboid’s volume is the area of its
rectangular base multiplied by a height; a cylinder’s volume is the
area of its circular base multiplied by a height.