Skip to content

Examples

kwikius edited this page Sep 7, 2025 · 5 revisions

Great — here’s a draft Examples.md you can drop into your wiki alongside Home.md and Units-and-Quantities-Principles.md. I’ve kept the style consistent with the rest.


Examples

This page shows example usage of gzScript for units and quantities.


Basic Quantities

length = 25.4:mm:;    // 25.4 mm
distance = 1:m:;      // 1 metre

// automatic SI conversion
sum = length + distance;   // = 1.0254:m:

Velocity

d = 100:m:;
t = 9.58:s:;

v = d / t;      // = 10.44:m/s:;

Multiplication and Division

w = 2:m:;
h = 3:m:;

area = w * h;   // = 6:m^2:;

Refinements

h:height: = 1.75:m:;
w:width:  = 0.30:m:;

// ok: assign from anonymous length
h = 2:m:;

// error: width cannot be assigned from height
w = h;     // compile error

Angles

phi = 180:deg:;
theta = 3.14159:rad:;

// explicit conversion deg → rad
phi_r = phi:rad:;

// ok: radians interchangeable with dimensionless
x = sin(theta);

Mixed Units

a = 2:ft:;
b = 1:m:;

// result is SI
c = a + b;    // 1.6096:m:

Derived Units

force = 10:N:;    // newton
area  = 2:m^2:;

pressure = force / area;   // 5:Pa:

Status

This page is a living draft. More examples will be added as gzScript features evolve.


Would you like me to also prepare a Design-Notes.md wiki page where you can log open questions (like integer literal promotion, or how refinements interact with comparisons)? That might help keep track of the evolving semantics.

Clone this wiki locally