Skip to content
Martin Trojer edited this page Aug 25, 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> (pprint (find-units "moo"))
(["moonlum" {:v 2500, :u {"m" -2, "cd" 1}}]
 ["moongravitys" {:v 1.62, :u {"s" -2, "m" 1}}]
 ["moondist" {:v 3.844E8, :u {"m" 1}}]
 ["moondists" {:v 3.844E8, :u {"m" 1}}]
 ["moongravity" {:v 1.62, :u {"s" -2, "m" 1}}]
 ["moonlums" {:v 2500, :u {"m" -2, "cd" 1}}]
 ["moonradius" {:v 1738000, :u {"m" 1}}]
 ["moonmass" {:v 7.3483E22, :u {"kg" 1}}]
 ["smoots" {:v 8509/5000, :u {"m" 1}}]
 ["smoot" {:v 8509/5000, :u {"m" 1}}])
nil

find-fundamentals

Takes a string and returns a sequence of results

user> (pprint (find-fundamentals "mass"))
(["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