Skip to content

Numbers And Collections

Chris Michael edited this page Sep 2, 2026 · 2 revisions

Pudu

Numbers And Collections

let exact = 1.50d
let bytes = [1u8, 2u8, 3u8]
let names = setOf(["Ada", "Grace"])

Status: numeric widths, checked/wrapping/saturating integer operators, IEEE floats, exact decimals, arrays, maps, sets, strings, tuples, and iteration execute in the interpreter.

Integers

Unsuffixed integer literals remain arbitrary precision during inference, then must fit their selected type. If context selects none, they default to Int. Width suffixes include forms such as i8, u64, and the other wired-in integer widths.

Operators Meaning
+ - * Checked; overflow reports a typed runtime diagnostic.
&+ &- &* Wrapping modulo the type width.
`+ -

Integer division truncates toward zero. Division by zero and invalid shift counts are reported. Implicit numeric narrowing is not performed.

Floating point

Unsuffixed and f64 literals are Float64; f32 explicitly selects Float32. Float32 operations round at binary32 precision instead of keeping hidden binary64 precision.

Decimal

Decimal stores an arbitrary-precision coefficient and base-ten scale. Addition, subtraction, and multiplication are exact. Ordinary division succeeds only for a terminating decimal; explicit Std.Decimal.divide selects precision and a rounding mode when rounding is intended. Decimal does not convert implicitly to or from binary floating point.

Built-in collections

Type Core behavior
Array[T] Ordered sequence and built-in array methods.
Map[K, V] Key/value lookup, update, keys, values, and iteration as (K, V).
Set[T] Membership, insertion/removal, set algebra, and value iteration.
Str Unicode scalar access and text methods.
Tuple Fixed heterogeneous product.

Collections are values. Standard modules provide the larger operation vocabulary without turning every function into a method.

Iteration

for pattern in expression obtains a deterministic element type. Built-ins include arrays, strings, sets, maps, tuples with a common member type, and sums with a common payload type.

User-defined iteration uses Std.Iter.Sequence:

trait Sequence[S, T] {
  fn begin(self: &Self) -> S
  fn advance(self: &Self, state: S) -> Option[(S, T)]
}

State is passed as a value rather than hidden mutation. Iterator adapters are lazy until consumed.

Related

Clone this wiki locally