Skip to main content
The number module covers all basic arithmetic and comparison operations for numeric values in Lion. Every function validates its arguments through Effect schemas, so passing a non-number produces a typed error rather than a runtime surprise. All nine functions take exactly two arguments.

Arithmetic

number/add

Returns the sum of two numbers.
["number/add", 1, 2]
Result: 3

number/subtract

Subtracts the second number from the first.
["number/subtract", 10, 3]
Result: 7

number/multiply

Returns the product of two numbers.
["number/multiply", 5, 4]
Result: 20

number/divide

Divides the first number by the second.
["number/divide", 20, 4]
Result: 5
Division by zero follows JavaScript semantics and returns Infinity rather than throwing. Validate your divisor with number/equals? if you need to guard against it.

Comparisons

All comparison functions return a boolean.

number/equals?

Returns true when both numbers are strictly equal.
["number/equals?", 5, 5]
Result: true

number/lessThan

Returns true when the first number is less than the second.
["number/lessThan", 3, 5]
Result: true

number/greaterThan

Returns true when the first number is greater than the second.
["number/greaterThan", 5, 3]
Result: true

number/lessThanOrEqualTo

Returns true when the first number is less than or equal to the second.
["number/lessThanOrEqualTo", 3, 5]
Result: true

number/greaterThanOrEqualTo

Returns true when the first number is greater than or equal to the second.
["number/greaterThanOrEqualTo", 5, 5]
Result: true

Using comparisons with cond

Comparison functions are the natural fit for cond branches:
["cond",
  [["number/greaterThan", "score", 90], "great"],
  [["number/greaterThan", "score", 70], "pass"],
  ["else", "retry"]]
Bind frequently used values with define before computing with them. For example, store a tax rate once and reference it by name in multiply expressions.