Builtin functions

Contents

Builtin functions#

The registry#

The names an author calls as a function without declaring one. A row named math.<name>, distance.<name> or calendar.<name> is a member of that module, called through its import by its qualified name or by the bare <name> a selective import binds. Every other row is global, and its name is a reserved word.

Column

Holds

Arities

the argument counts accepted. A call with any other count is a compile error

Tier

the call’s purity tier, pure or sync-impure

Signature

each form’s parameters and result, ? marking a nullable result and ; separating the forms

Summary

what the call answers

Defined by

the defining clause, which is right where it and the row differ

A Float parameter takes an Int, converted. cursor is a series cursor, and T the type of the slot it reads.

A parameter is a value: a T? argument is refused, and a null that reaches one at run time raises a TypeError. has and math.fma differ: has tests a Json path for resolution, and math.fma takes its operands as x * y + z does.

Name

Arities

Tier

Signature

Summary

Defined by

abs

1

pure

(x: Int) → Int; (x: Float) → Float

Absolute value, of the argument’s type.

[LEXP.3.2]

math.acos

1

pure

(x: Float) → Float

Inverse cosine, in radians.

[LEXP.3.9.1]

math.asin

1

pure

(x: Float) → Float

Inverse sine, in radians.

[LEXP.3.9.1]

math.atan

1

pure

(x: Float) → Float

Inverse tangent, in radians.

[LEXP.3.9.1]

math.atan2

2

pure

(y: Float, x: Float) → Float

Angle of the point (x, y) from the positive x axis, in radians, in [−π, π].

[LEXP.3.9.1]

cached

1

sync-impure

(key: String) → String?

The cache’s value for the key, as JSON text; null on a miss.

[LSTO.4.3.1]

math.ceil

1

pure

(x: Int) → Int; (x: Float) → Int

Smallest integer not less than x; a Float with no Int answer traps.

[LEXP.3.2]

distance.chebyshev

4, 6

pure

(x1, y1, x2, y2: Float) → Float; (x1, y1, z1, x2, y2, z2: Float) → Float

L∞ (chessboard) distance between two points, 2D or 3D.

[LEXP.5.3.1]

math.cos

1

pure

(x: Float) → Float

Cosine of x radians.

[LEXP.3.9.1]

math.cosh

1

pure

(x: Float) → Float

Hyperbolic cosine.

[LEXP.3.9.1]

distance.cosine

4, 6

pure

(ax, ay, bx, by: Float) → Float; (ax, ay, az, bx, by, bz: Float) → Float

Cosine distance, 1 − cos θ, between two vectors, in [0, 2].

[LEXP.5.7.1]

calendar.date

3

pure

(year: Int, month: Int, day: Int) → Date

The Date of that calendar day.

[LTIM.14.1]

math.degrees

1

pure

(x: Float) → Float

Radians to degrees.

[LEXP.3.6.1]

distance.euclidean

4, 6

pure

(x1, y1, x2, y2: Float) → Float; (x1, y1, z1, x2, y2, z2: Float) → Float

L₂ distance between two points, 2D or 3D.

[LEXP.5.3.1]

math.exp

1

pure

(x: Float) → Float

e to the power x.

[LEXP.3.9.1]

math.floor

1

pure

(x: Int) → Int; (x: Float) → Int

Largest integer not greater than x; a Float with no Int answer traps.

[LEXP.3.2]

math.fma

3

pure

(x: Float, y: Float, z: Float) → Float

x × y + z, rounded once.

[LEXP.3.2.2]

distance.great_circle

4

pure

(lat1, lon1, lat2, lon2: Float) → meter

Distance along the Earth’s surface between two points given in degrees.

[LEXP.5.11.1]

has

1

pure

(path: Json path) → Bool

Whether the Json path resolves.

[LEXP.6.1]

distance.hypotenuse

2, 3

pure

(x, y: Float) → Float; (x, y, z: Float) → Float

Length of a vector from the origin, 2D or 3D.

[LEXP.5.5]

len

1

pure

(j: Json) → Int; (s: String) → Int; (b: Bytes) → Int

A Json array’s length, a String’s code points, or a Bytes value’s bytes.

[LEXP.6.1], [LSTR.2.1], [LSTR.4.2]

math.ln

1

pure

(x: Float) → Float

Natural logarithm.

[LEXP.3.9.1]

math.log10

1

pure

(x: Float) → Float

Base-10 logarithm.

[LEXP.3.9.1]

math.log2

1

pure

(x: Float) → Float

Base-2 logarithm.

[LEXP.3.9.1]

distance.manhattan

4, 6

pure

(x1, y1, x2, y2: Float) → Float; (x1, y1, z1, x2, y2, z2: Float) → Float

L₁ (taxicab) distance between two points, 2D or 3D.

[LEXP.5.3.1]

max

2

pure

(a, b: Int | Float) → Int | Float; (cursor) → T?

The larger of a and b, of the winning operand’s type, a tie giving a; with a cursor alone, the series’ maximum.

[LEXP.3.8.1]

min

2

pure

(a, b: Int | Float) → Int | Float; (cursor) → T?

The smaller of a and b, of the winning operand’s type, a tie giving a; with a cursor alone, the series’ minimum.

[LEXP.3.8.1]

monotonic_ns

0

sync-impure

() → Duration

The monotonic clock’s reading.

[LGRA.9.8.10]

now

0

sync-impure

() → Time

The wall-clock instant.

[LGRA.9.8.10]

math.pow

2

pure

(x: Int, y: Int) → Int; (x: Float, y: Float) → Float

x to the power y; an Int only for an Int base and a statically non-negative Int exponent.

[LEXP.3.2]

math.radians

1

pure

(x: Float) → Float

Degrees to radians.

[LEXP.3.6.1]

round

1

pure

(x: Int) → Int; (x: Float) → Int

Nearest integer, ties to even; a Float with no Int answer traps.

[LEXP.3.2]

math.sign

1

pure

(x: Int) → Int; (x: Float) → Int

1 when x > 0, −1 when x < 0, else 0.

[LEXP.3.2]

math.sin

1

pure

(x: Float) → Float

Sine of x radians.

[LEXP.3.9.1]

math.sinh

1

pure

(x: Float) → Float

Hyperbolic sine.

[LEXP.3.9.1]

math.sqrt

1

pure

(x: Float) → Float

Square root, correctly rounded; NaN for a negative x.

[LEXP.3.2]

math.tan

1

pure

(x: Float) → Float

Tangent of x radians.

[LEXP.3.9.1]

math.tanh

1

pure

(x: Float) → Float

Hyperbolic tangent.

[LEXP.3.9.1]

calendar.time

3, 6, 7

pure

(year, month, day: Int) → Time; (year, month, day, hour, minute, second: Int) → Time; (year, month, day, hour, minute, second, nanosecond: Int) → Time

The UTC instant of that calendar day and wall-clock time.

[LTIM.14.1]

math.trunc

1

pure

(x: Int) → Int; (x: Float) → Int

x truncated toward zero; a Float with no Int answer traps.

[LEXP.3.2]

(Spec: [LEXP.17.1], [LEXP.17.2])