Home

Units

This Clojure library allows you to define unit conversions without repeating yourself and includes some common ones predefined.

It does some cool things thanks to a few features in Clojure. One is that if you define the equation for fahrenheit to celsius, it will derive celsius to fahrenheit for you. This uses symbolic algebra and it is accomplished easily thanks to lisp's prefix syntax and the fact that code is a normal data structure.

See the function invert, which can take (/ (- x 1) 2) and return (+ (* x 2) 1). That's like solving y=(x-1)/2 for x.

It also figures out which conversions haven't been defined but can be derived from the conversions that have been defined. So if you define inches-to-feet and feet-to-meters it will derive meters-to-inches and inches-to-meters.

Also, if you tell it that a unit can be squared or cubed it will define those automatically.

So for inches, feet, yards, meters, centimeters, millimeters, miles, and kilometers, if you specify 7 equations this library will define 168 conversion functions for you (56 each for length, area, and volume).


Contact me by email at my first name at my last name dot com.