Skip to content
Martin Trojer edited this page Aug 26, 2013 · 17 revisions

Frinj keeps tracks of units, 2 kinds of prefixes and fundamental units.

All fjv's are always normalised to fundamental units to make it possible to add, multiply and convert them.

Fundamentals

* length              m     meter
* mass                kg    kilogram
* time                s	    second
* current             A	    ampere
* luminous_intensity  cd    candela
* substance           mol   mole
* temperature         K	    Kelvin
* information         bit   bit
* currency            USD   U.S. dollar

It's worth pointing out that these fundamental units are configurable (see units.txt), i.e. not hardcoded.

Prefixes

Prefixes are units-less factors that are multiplied to the units. There are 2 kinds of prefixes, normal and standalone. A normal prefix can only "prefix" a unit name where-as standalone prefix can be used as both a prefix and a unit.

  • (fj :cm) is prefix c + unit m. Being 1/100 * m
  • (fj :c) is the unit speed of light (299792458 m/s)
  • (fj :m) is unit m
  • (fj :kilo) is a standalone prefix of value 1000
  • (fj :kilobit) is 1000 of unit bits

Frinj tries to pick the longest prefix name that results in a valid prefix + unit combination. If no valid combination is found, frinj will treat the input as a new unit.

Only one prefix can by used before a unit name; :ccm is not centi-centi-meter, but the unit called ccm. (fj :centi :cm) is a centi-centi-meter.

Plurals

Most of the units come in both singular and plural form. So :meter and :meters is the same.

Finding units / fundamentals

There are 2 functions to search the units database.

find-units

Takes a string and returns a sequence of results

user> (clojure.pprint/print-table (find-units "moon"))

|        :name |                      :unit |
|--------------+----------------------------|
|      moonlum | 2500 cd m^-2 [illuminance] |
| moongravitys | 1.62 m s^-2 [acceleration] |
|     moondist |         3.844E8 m [length] |
|    moondists |         3.844E8 m [length] |
|  moongravity | 1.62 m s^-2 [acceleration] |
|     moonlums | 2500 cd m^-2 [illuminance] |
|   moonradius |         1738000 m [length] |
|     moonmass |        7.3483E22 kg [mass] |
nil

find-fundamentals

Takes a string and returns a sequence of results

user> (clojure.pprint/print-table (find-fundamentals "mass"))

|                          :name |                 :unit |
|--------------------------------+-----------------------|
|          concentration_by_mass |    {"mol" 1, "kg" -1} |
|                 price_per_mass | {"kg" -1, "dollar" 1} |
| reciprocal_linear_mass_density |      {"kg" -1, "m" 1} |
|                           mass |              {"kg" 1} |
|            linear_mass_density |      {"m" -1, "kg" 1} |
|                     molar_mass |    {"mol" -1, "kg" 1} |
|                   mass_density |      {"kg" 1, "m" -3} |
nil
Clone this wiki locally