unitsys module

unitsys module allows you to register a unit system at run time.

For example, the following script defines units for "length". When a unit system is defined, the symbols in the first array parameter are registered as unit symbols.

use("unitsys")

UnitSystem(
 ["mm", "cm", "m", "km"],
 [1, 10, 1000, 1000000]
)

In this case, a result of a unit expression is a pnuts.lang.Numeric object. Therefore, arithmetic operations can be applied to the quantities with same dimension.

1mm ==> 1mm
1mm + 1cm ==> 11.000mm

The following script is another example for unitsys module.

e.g.
use("unitsys")

UnitSystem(
  ["mm", "cm", "m"],
  [1, 10, 1000]
)

UnitSystem(
  ["g", "kg"],
  [1, 1000]
)

function show(exp) println(exp + " = " + eval(exp))

show("1g * 3mm")
show("1g * 3mm * 1m")