Unit Statement
Identifies a unit of measure.
Syntax
Usual construct
[ @SI [ prefix_type ] ] _
Unit unit_names [ = expression ]
Interval-scale construct
Unit unit_names ( parameter In unit ) = expression
Block construct
block_start
{ When condition
[ statements ] }
…
End [ Unit ]
Parts
@SI- Optional indication of an SI (metric) unit.
prefix_type- Optional after
@SI, one of these identifiers:BINARY– Gives these prefixes:kibiorKi(2^10),mebiorMi(2^20),gibiorGi(2^30),tebiorTi(2^40),pebiorTi(2^50),exbiorEi(2^60),zebiorZi(2^70),yobiorYi(2^80).LARGE– Gives these prefixes:decaordekaorda(10^1),hectoorh(10^2),kiloork(10^3),megaorM(10^6),gigaorG(10^9),teraorT(10^12),petaorP(10^15),exaorE(10^18),zettaorZ(10^21),yottaorY(10^24),ronnaorR(10^27),quettaorQ(10^30).SMALL– Gives these prefixes:deciord(10^−1),centiorc(10^−2),milliorm(10^−3),microorµorμoru(10^−6),nanoorn(10^−9),picoorp(10^−12),femtoorf(10^−15),attoora(10^−18),zeptoorz(10^−21),yoctoory(10^−24),rontoorr(10^−27),quectoorq(10^−30).
If not supplied, the default prefixes are those given by
LARGEandsmallput together. unit_names- Mandatory one or more names with spaces between each.
All names identify the same unit.
Unit name
[ number ] { name | name + suffix | prefix - name }name- Mandatory basic name for a unit of measure.
number- One of the integer literals that follow:
1–nameis irregular and grammatically singular. For example, «1 foot».2–nameis irregular and grammatically plural. For example, «2 feet».0–nameis grammatically singular for zero and one. This occurs in some languages, for example, French. You can use0(and no others) withsuffixorprefix.
suffix- Mandatory after
+. Identifies the regular plural suffix forname. For example, «metre+s» or «inch+es». prefix- Mandatory before a hyphen (
-). Identifies the regular plural prefix forname. This occurs in some languages, most frequently in Africa. For example, in Swahili, «ma-debe».
expression- A conversion factor.
- Optional in the usual construct.
- Mandatory in the interval-scale construct.
parameter- Mandatory in the interval-scale construct.
You use it with
expressionfor a unit with an interval scale, for example, a unit of temperature. unit- A different unit that is related to this unit.
block_start- The usual construct or interval-scale construct that starts a block construct.
When- Mandatory keyword in the block construct that you can use again and again. It starts a block with a condition and statements.
condition- A clause used to do one or more tests when you try to change a unit variable.
Range construct
When expression_1 To expression_2Comparison construct
When Is comparison_op expressionEquality construct
When expression- The range construct lets you compare a range of values.
The value of
expression_1must be less than or equal toexpression_2. - The comparison construct lets you use all the comparison operators:
<,<=,>,>=,=, or<>. - The equality construct operates the same as «
Is =».
- The range construct lets you compare a range of values.
The value of
statements- Optional one or more statements.
Frequently only the statement
Raiseis necessary to cause an exception. The variablevalueholds the new value. End- Completes the block construct.
You can also use
End Unit.
Instructions
TODO
Examples
// Make meter, metres, kilometer, millimetres, m, km, mm ...
@SI Unit meter+s metre+s m
// Derived unit.
Unit light_year+s ly = 9.4605284 petameters
// in. is not permitted because IN is a keyword
// and a name cannot have a period,
// but you can write IN between backticks.
Unit inch+es `in` = 2.54 cm
// Kelvin cannot be plural.
Unit Kelvin K
When Is < 0.0
// Cannot be negative.
Raise RangeError(value)
End Unit
// °C is not given because it is not easy to write.
// 1 makes a singular name and 2 makes a plural name.
// This is an interval-scale unit, thus the parameter k.
// Also gets the range check from Kelvin.
Unit Celsius 1 degree_C 2 degrees_C (k In Kelvin) = k + 273.15
// Make second, secs, milliseconds, s, ms, ...
@SI SMALL Unit second+s sec+s s
// Make byte, kibibytes, mebibyte, B, KiB, MiB, ...
// Does not permit Kilobyte, megabytes, KB, MB, ...
@SI BINARY Unit byte+s B