Skip to main content

Standard library

The std module is written in Argon itself. Call its functions with the std:: prefix, or import them with use, as in use std::{max, min};.

Layout functions live in the submodule std::layout: the geometry constructors, inst, bbox, dimension, and helpers such as std::layout::array and std::layout::intersection. Schematic entry lives in std::schematic: Signal, connect, device, inst, signals, Device, and DeviceKind. Symbols are drawn with std::symbol: line, polygon, rect, circle, arc, text, inst_name, param, pin, Align, and the device symbol helpers.

std::max​

std::max(x0: Float, x1: Float) -> Float

Returns the greater of two floats.

ArgumentTypeRequirementDescription
x0FloatRequiredFirst value.
x1FloatRequiredSecond value.

Returns Float. x1 when x0 < x1; otherwise x0.

std::min​

std::min(x0: Float, x1: Float) -> Float

Returns the lesser of two floats.

ArgumentTypeRequirementDescription
x0FloatRequiredFirst value.
x1FloatRequiredSecond value.

Returns Float. x0 when x0 < x1; otherwise x1.

std::Option​

enum Option<T> {
Some(T),
None,
}

A value that may be absent. Option, Some, and None are in scope in every module without a use. A cell parameter typed Option<Int> with a None default is optional, and a struct field typed Option<Node> lets a struct contain itself. Take an Option apart with match:

fn count(n: Option<Int>) -> Int {
match n {
Some(value) => value,
None => 1,
}
}

std::is_some​

std::is_some<T>(o: Option<T>) -> Bool

Whether an option holds a value.

ArgumentTypeRequirementDescription
oOption<T>RequiredThe option to test.

Returns Bool. true for Some, false for None.

std::is_none​

std::is_none<T>(o: Option<T>) -> Bool

Whether an option is empty.

ArgumentTypeRequirementDescription
oOption<T>RequiredThe option to test.

Returns Bool. true for None, false for Some.

std::unwrap_or​

std::unwrap_or<T>(o: Option<T>, default: T) -> T

The value inside an option, or a default.

ArgumentTypeRequirementDescription
oOption<T>RequiredThe option to unwrap.
defaultTRequiredThe value returned for `None`.

Returns T. The payload of Some, or default.

std::first​

std::first<T>(items: [T]) -> Option<T>

Returns the first element of a sequence, if it has one.

ArgumentTypeRequirementDescription
items[T]RequiredAny sequence.

Returns Option<T>. Some of the first element, or None for an empty sequence.

std::last​

std::last<T>(items: [T]) -> T

Returns the last element of a sequence.

ArgumentTypeRequirementDescription
items[T]RequiredA non-empty sequence.

Returns T. The last element, with the sequence's element type.

std::len​

std::len<T>(items: [T]) -> Int

Returns the number of elements in a sequence.

ArgumentTypeRequirementDescription
items[T]RequiredAny sequence.

Returns Int. The element count; 0 for [].

std::concat​

std::concat<T>(first: [T], second: [T]) -> [T]

Joins two sequences.

ArgumentTypeRequirementDescription
first[T]RequiredThe leading elements.
second[T]RequiredThe trailing elements.

Returns [T]. The elements of first, then those of second.

std::flatten​

std::flatten<T>(sequences: [[T]]) -> [T]

Joins a sequence of sequences.

ArgumentTypeRequirementDescription
sequences[[T]]RequiredThe sequences to join, in order.

Returns [T]. Every element of every sequence, in order.

let wires = std::flatten([for net in nets { net.wires }]);

std::sum​

std::sum(values: [Int]) -> Int

Adds up a sequence of integers.

ArgumentTypeRequirementDescription
values[Int]RequiredThe integers to add.

Returns Int. Their sum; 0 for [].

std::any​

std::any(values: [Bool]) -> Bool

Whether any value is true.

ArgumentTypeRequirementDescription
values[Bool]RequiredThe values to test.

Returns Bool. true if at least one value is true; false for [].

let blocked = std::any([for other in rails { overlaps(rail, other) }]);

std::all​

std::all(values: [Bool]) -> Bool

Whether every value is true.

ArgumentTypeRequirementDescription
values[Bool]RequiredThe values to test.

Returns Bool. true if no value is false; true for [].

std::range​

std::range(stop: Int) -> [Int]

Returns the integers from 0 up to stop.

ArgumentTypeRequirementDescription
stopIntRequiredExclusive upper bound.

Returns [Int]. Integers from zero up to, but not including, stop.

for index in std::range(4) {
// index is 0, 1, 2, then 3
}