laylight tour
0/25
3/4

Basics · 3 of 4

Numbers and units

Lengths and angles carry units, and the compiler checks them:

UnitsFor
nm, um (or µm), mmlengths
deg, radangles

The unit follows the number without a space: 500nm, 0.5um, 90deg. The same length can be written in several ways; 0.5um and 500nm are equal.

A number without a unit is not a length. (0, 10) is an error, and the compiler asks "did you mean 10um?". The one exception is a literal 0, which can stand for a zero of any kind: (0, 10um) is fine.

Arithmetic follows the units:

  • +, - and comparisons need the same kind of value on both sides: 1um + 500nm is 1.5um, but 1um + 2 is an error.
  • * and / combine them: 3 * 10um is a length, 10um / 2um is the plain number 5, and 10um * 2um is an area — fine in a calculation, but not as a coordinate.

Every value has a type: integer (3), number (0.5), size (a length), angle, string ("text"), bool (true) or point ((x, y)).

The compiler's suggestions are a starting point, not an answer: for a bare number it always proposes micrometres, which is not always what was meant.

Exercise

The program does not compile. Fix the units so that it draws the three 500 nm wide waveguides the comments describe, 10, 20 and 30 µm long.

loading compiler…

Edit the code, watch the layout, then press Submit to check your solution against the exercise.

Compiling…