Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Types

The µcad type system consists of a group of builtin types. The type system is static, which means a every value has a fixed type which cannot be changed or overwritten.

Here is a complete list of the builtin types:

TypeDescriptionType DeclarationsExample Values
BooleanBoolean valueBooltrue, false
IntegerInteger value without unitInteger4, -1
QuantityFloating point value with or without unitScalar, Length, Area, Volume, Density, Angle, Weight0.5, 50%, -1.23e10, -4mm, 1.3m2, 2cm², 23.0e5deg, 100g
StringUTF-8 text stringString"Hello, World!"
ArrayList of values with common type[Integer][1,2,3], [1m,2cm,3µm]
TupleList of named values or distinct types(Length,Scalar,Bool), (x:Scalar,y:Length), (x:Scalar,Length)(4mm,4.0,true), (x=4.0,y=4mm), (x=4.0,4mm)
ModelGeometric 2D or 3D modelModelstd::geo3d::Cube(2mm)

Declaration

The examples in the table above declare the type explicitly. However, we can use units to declare the implicitly. Using units is recommended and what you get in return is that declarations are quite handy:

test

x: Length = 4mm; // explicit type declaration
y = 4mm; // implicit type declaration via units.

Declarations without any initializations are not allowed in µcad. Hence, the following example will fail:

test

x: Length;         // parse_error

However, for parameter lists in functions and workbenches, you can declare the type only but also pass a default value:

test

fn f(x = 4mm) {} // use unit (with default)
fn g(x: Length) {} // use type (without default)

[!NOTE] Find out more about what types are used for in the sections about argument matching and assignments.