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:
| Type | Description | Type Declarations | Example Values |
|---|---|---|---|
| Boolean | Boolean value | Bool | true, false |
| Integer | Integer value without unit | Integer | 4, -1 |
| Quantity | Floating point value with or without unit | Scalar, Length, Area, Volume, Density, Angle, Weight | 0.5, 50%, -1.23e10, -4mm, 1.3m2, 2cm², 23.0e5deg, 100g |
| String | UTF-8 text string | String | "Hello, World!" |
| Array | List of values with common type | [Integer] | [1,2,3], [1m,2cm,3µm] |
| Tuple | List 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) |
| Model | Geometric 2D or 3D model | Model | std::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:
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:
x: Length; // parse_error
However, for parameter lists in functions and workbenches, you can declare the type only but also pass a default value:
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.