Quantities and Units

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.

Kawa quantities are a generalization of the quantities in DSSSL, which only has length-derived quantities.

The precise syntax of quantity literals may change, but some examples are 10pt (10 points), 5s (5 seconds), and 4cm^2 (4 square centimeters).

Function: quantity? object

True iff object is 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 complex?.

Function: quantity->number q

Returns the pure number part of the quantity q, relative to primitive (base) units. If q is a number, returns q. If q is a unit, yields the magitude of q relative to base units.

Function: quantity->unit q

Returns the unit of the quantity q. If q is a number, returns the empty unit.

Function: make-quantity x unit

Returns the product of x (a pure number) and unit. You can specify a string instead of unit, such as "cm" or "s" (seconds).

Syntax: define-base-unit unit-name dimension

Define unit-name as a base (primitive) unit, which is used to measure along the specified dimension.

(define-base-unit dollar "Money")

Syntax: define-unit unit-name expression

Define unit-name as a unit (that can be used in literals) equal to the quantity expression.

(define-unit cent 0.01dollar)