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:kibi
orKi
(2^10),mebi
orMi
(2^20),gibi
orGi
(2^30),tebi
orTi
(2^40),pebi
orTi
(2^50),exbi
orEi
(2^60),zebi
orZi
(2^70),yobi
orYi
(2^80).LARGE
– Gives these prefixes:deca
ordeka
orda
(10^1),hecto
orh
(10^2),kilo
ork
(10^3),mega
orM
(10^6),giga
orG
(10^9),tera
orT
(10^12),peta
orP
(10^15),exa
orE
(10^18),zetta
orZ
(10^21),yotta
orY
(10^24),ronna
orR
(10^27),quetta
orQ
(10^30).SMALL
– Gives these prefixes:deci
ord
(10^−1),centi
orc
(10^−2),milli
orm
(10^−3),micro
orµ
orμ
oru
(10^−6),nano
orn
(10^−9),pico
orp
(10^−12),femto
orf
(10^−15),atto
ora
(10^−18),zepto
orz
(10^−21),yocto
ory
(10^−24),ronto
orr
(10^−27),quecto
orq
(10^−30).
If not supplied, the default prefixes are those given by
LARGE
andsmall
put 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
–name
is irregular and grammatically singular. For example, «1 foot
».2
–name
is irregular and grammatically plural. For example, «2 feet
».0
–name
is grammatically singular for zero and one. This occurs in some languages, for example, French. You can use0
(and no others) withsuffix
orprefix
.
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
expression
for 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_2
Comparison construct
When Is comparison_op expression
Equality construct
When expression
- The range construct lets you compare a range of values.
The value of
expression_1
must 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
Raise
is necessary to cause an exception. The variablevalue
holds 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