I try to use protocols to create an engineering number type ("knumber"), so I can say (+ "1k" "2Meg") and get something like "2.001Meg" . I would have to get the floating point value from the dense type (:val my-knumber) , but usually the printer should display a string that is also available like this (:string my-knumber) . This number will support all regular p, n, u, m, k, Meg, G suffixes and convert them as needed, for example (/ "1Meg" "1G") -> "1m") . I want to pass this to any function that expects a number.
Anyway, can anyone suggest a strategy for this? I think I need to use protocols. I currently have (defrecord knumber [val string]) , but I'm not sure what next.
What protocols have clojure satsify numbers? I think I need to extend some existing protocols / interfaces for this.
thanks
source share