|
@@ -62,6 +62,7 @@ let q3: Length / Time = 2 m/s # more complex type annotation
|
|
|
fn foo(z: Scalar) -> Scalar = 2 * z + 3 # A simple function
|
|
|
fn speed(len: Length, dur: Time) -> Speed = len / dur # Two parameters
|
|
|
fn my_sqrt<T>(q: T^2) -> T = q^(1/2) # A generic function
|
|
|
+fn is_non_negative(x: Scalar) -> bool = x ≥ 0 # Returns a bool
|
|
|
|
|
|
# 6. Dimension definitions
|
|
|
|
|
@@ -94,6 +95,8 @@ fn step(x: Scalar) -> Scalar = # The construct 'if <cond> then <expr> else <ex
|
|
|
# 9. Procedures
|
|
|
|
|
|
print(2 kilowarhol) # Print the value of an expression
|
|
|
+print("hello world") # Print a message
|
|
|
+print("value of pi = {pi}") # String interpolation
|
|
|
assert_eq(1 ft, 12 in) # Assert that two quantities are equal
|
|
|
assert_eq(1 yd, 1 m, 10 cm) # Assert that two quantities are equal, up to
|
|
|
# the given precision
|