As a super-class of numbers, Kawa also provides quantities. A quantity is a product of a unit and a pure number. The number part can be an arbitrary complex number. The unit is a product of integer powers of base units, such as meter or second.
Quantity literals have the following syntax:
Some examples are
10pt (10 points),
5s (5 seconds),
4cm^2 (4 square centimeters).
quantity syntax is not recognized by the reader.
Instead these are read as symbols.
Assuming there is no lexical binding the for the symbol, it will be
rewritten at compile-time into an expression. For example
is transformed into:
(* 4.0 (expt unit:cm 2))
objectis a quantity. Note that all numbers are quantities, but not the other way round. Currently, there are no quantities that re not numbers. To distinguish a plain unit-less number from a quantity, you can use
Returns the pure number part of the quantity
q, relative to primitive (base) units. If
qis a number, returns
qis a unit, yields the magitude of
qrelative to base units.
Returns the unit of the quantity
qis a number, returns the empty unit.
Returns the product of
x(a pure number) and
unit. You can specify a string instead of
unit, such as
unit-nameas a base (primitive) unit, which is used to measure along the specified
dimension.(define-base-unit dollar "Money")
unit-nameas a unit (that can be used in literals) equal to the quantity
expression.(define-unit cent 0.01dollar)
unit-nameis declared in the
unitnamespace, so the above is equivalent to:(define-constant unit:cent (* 0.01 unit:dollar))