Supporting fractional values for a unit converter function
Heime <[email protected]>
| Newsgroups | gmane.emacs.help |
|---|---|
| Message-ID | <0Pmq-Tizd8DeRL63DnLc0P_PTZLBQjt_IVcmWzlKAzXNZ4qHia0bM22IHU52OnkOp8820PtqqVi0XT1qJTTq2IX4PrpPAulQBIcG2U3jd8A=@protonmail.com> |
I want to extend a unit conversion framework that accepts fractional
inches by letting value be a Lisp rational (like 7/64) and then treating
it as a normal number in the conversion.
To write (units 7/64 :inch :mm) rather than the cumbersome
(units ((float 7) / (float 64)) :inch :mm)
(defun units (value from to)
(cond
;; inches to cm
((and (eq from :inch) (eq to :cm))
(* value 2.54))
;; cm to inches
((and (eq from :cm) (eq to :inch))
(/ value 2.54))
;; catch invalid combinations
(t nil)))