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.
Returns Float. x1 when x0 < x1; otherwise x0.
std::min
std::min(x0: Float, x1: Float) -> Float
Returns the lesser of two floats.
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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
o | Option<T> | Required | The 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
o | Option<T> | Required | The 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
o | Option<T> | Required | The option to unwrap. |
default | T | Required | The 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
items | [T] | Required | Any 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
items | [T] | Required | A 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
items | [T] | Required | Any sequence. |
Returns Int. The element count; 0 for [].
std::concat
std::concat<T>(first: [T], second: [T]) -> [T]
Joins two sequences.
| Argument | Type | Requirement | Description |
|---|---|---|---|
first | [T] | Required | The leading elements. |
second | [T] | Required | The 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
sequences | [[T]] | Required | The 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
values | [Int] | Required | The integers to add. |
Returns Int. Their sum; 0 for [].
std::any
std::any(values: [Bool]) -> Bool
Whether any value is true.
| Argument | Type | Requirement | Description |
|---|---|---|---|
values | [Bool] | Required | The 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
values | [Bool] | Required | The 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
stop | Int | Required | Exclusive 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
}