Qu

unit_scale

Builtin index · REPL & diagnostics

result = unit_scale(name)

Input: name · Output: result

What it is

name: a string.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = unit_scale(name)
name stringnot documented yet
result —
Returns the scale factor a unit name = ... declaration registered, or errors naming name if nothing was ever declared under it.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

unit ppm = 1e-6
x = 5 * ppm            # 5e-6 -- ordinary arithmetic, works immediately

y = 5 ppm               # 5e-6 -- literal-suffix adjacency also works

print(unit_scale("ppm"))   # 0.000001 -- reads the declaration back

output
1e-6

from repl-diagnostics

How it works

unit_scale(name) — the scale factor a unit name = ... declaration registered for name (see Stmt::UnitDecl), introspection for the custom-unit registry the same way unit_family reads the built-in one. Errors, naming the unit, when nothing was ever declared under that name (rather than silently returning e.g. 1.0) — a typo'd unit name is exactly the kind of mistake that should surface immediately, not read back as "no scaling".

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.