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

Use Statement

You might be wondering why we always have to write std::geo2d:: and std::ops:: in front of Rect and subtract. This is because builtin sketches (and parts) in µcad are organized within modules in a standard library. std is the name of the top module of this library and geo2d is a submodule of std and contains all built-in sketches.

Writing std::ops and std::geo2d in front of each element seems redundant and cumbersome. Luckily, µcad has syntax elements called use statements. Apart from the shorter code, another useful feature of the statement is that it allows you to explicitly specify which parts of a module you want to use throughout the source file. This means instead of the previous code, we can simply write:

test

use std::geo2d::Rect;
use std::ops::subtract;

thickness = 1.2mm;
width = 31.8mm;
height = 15.8mm;
{
    Rect(width, height);
    Rect(width = width - 2 * thickness, height = height - 2 * thickness);
}.subtract();

Picture

As you can see, this makes the code much simpler and clearer.