Support ambiguities
There are times when
- multiple units might wish to use the same symbol (and/or name)
- combinations of a prefix and unit might match the name/symbol of another unit.
Ideally, we would like to support these as broadly as possible. Because we are usually trying to parse units in the context of conversion, we can make use of that information to disambiguate parsing.
Examples
- Both minutes (units of time) and arc-minutes (units of angle, which are dimensionless) use the double-quote(
"
) symbol and perhaps even the nameminute
/minutes
in many engineering contexts. The same goes for seconds and arc-seconds. - The minutes (units of time) unit is sometimes abbreviated
min
(and seconds aresec
). Butmin
can also be parsed as a milli-inch.
Proposed approach
Currently, the units library parses string identifiers into an abstract syntax tree and then visits tree nodes to perform "arithmetic" (multiplication, division, and exponentiation) on a Unit
instance. Instead, we could store a set of results by combinatorial expansion of all possible intermediate results. Algorithms such as unit-conversion could search the set for compatible alternatives and present them to users to disambiguate. Obviously, with large expressions, the combinatorics could explode but that would be unusual.