Types and values
Argon's types fall into scalars, collections, tuples, and layout types. Write types out in cell and function signatures: some can be inferred, but explicit signatures make call sites and error messages clearer.
Structs, enums, functions, and cells may take type parameters, written in angle brackets after the name: struct Pair<A, B>, fn last<T>(items: [T]) -> T. A type parameter stands for one type per use, which is inferred from the arguments, and a value of type T can only be stored, passed, and returned.
| Type | Example | Used for |
|---|---|---|
Float | 12., -0.5 | Coordinates, distances, and linear expressions |
Int | 12, -3 | Counts, indices, and discrete parameters |
Bool | true, false | Conditions and flags |
String | "met1" | Layer names and text |
Rect | rect("met1") | Rectangles, drawn or construction-only |
Polygon | polygon("met1", 3) | Polygons |
Path | path("met1", 2) | Paths with a width |
Point | shape.points[0] | A polygon or path vertex |
Inst | inst(child()) | A placed cell |
[T] | [Float] | A sequence of one type |
(A, B) | (3, 5,) | A fixed-size tuple of mixed types |
Option<T> | Some(3), None | A value that may be absent |
Any | — | A value of any type |
() | () | The unit value and type |
Numeric literals
The decimal point is what makes a literal a float:
let count = 50; // Int
let distance = 50.; // Float
Geometry and constraints use Float. Counts and indices use Int.
Operators and casts
Arithmetic: +, -, *, /, and %. Comparison: ==, !=, <, <=, >, and >=.
Cast with as:
let offset = (index as Float) * pitch;
Sequences and tuples
Build a sequence with list or cons, index it with brackets, and walk it with head and tail.
let widths = list(80., 120., 160.);
let first = widths[0];
let pair = (first, 3,);
std::range makes an integer sequence for loops.