Syntax
val identity = Matrix4 1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
Positional way to set fields works well for matrices. Integer literal is also used for real numeric types.
control.set_width width
set_height control.measure_height
arrange
import num/vector_f32/Vector3
Vector4
vector_i32/Vector2i
Methods set_width
, set_height
and arrange
are called on the same control
binding.
let enabled_extension_names = ["VK_EXT_debug_report"
"VK_EXT_debug_utils"
"VK_KHR_surface"
"VK_KHR_xcb_surface"
"VK_KHR_xlib_surface"]
Commas are not required if each element is located on a separate line or lines.
let thickness = (left = border.left
right = border.right
up = border.up
down = border.down)
let sizes = List<(u32, u32) width height>.new
Tuple fields can be named on creation, or when a tuple type is specified. Names have no impact on compatibility.
let vector = Vector3 1
y = 3
f@ struct@zero
Field values can be set positionally, by name or with a filler. Type of a filler must either match the type of the entity being created, or be a tuple with named fields. Works for object creation, initialization of a structure, type inheritance and function invocation.
let vector_ref = Vector3@ref 1 3 8
Structure is initialized on the heap if @ref
suffix is added to the type name. Binding vector_ref
is of type mut ref Vector3
, which can also be written as MutRef<Vector3>
. References of this kind in essence are pointers without arithmetics.
text
|> lines
|> filter { line -> line.starts_with "layout" }
|> map { remove_comment _ }
Closures are enclosed in curly braces. Each use of underscore returns the next parameter.
var array @internal = Array<T> 0
var size : u32 @[mut internal] = 0
Visibility is restricted using the @private
, @protected
and @internal
attributes. Only access from outside of the file is affected.
The @mut
attribute argument specifies the mutability scope.
let up_right = Vector3 left.as<f32> 0 border_z
let adjusted_size = size as f32 * 1.5 |> as<u32>
Type cast can be written without parentheses.
type Vector3
def with_y self (y : f32) = Vector3 self.x y self.z
Explicit self
is required inside of a method if self
is the first parameter.
type Entry =
path : String
created : DateTime
| File size : u32
| Directory entries : Slice<Entry>
| Local
| Remote url : String
Entry
and Directory
are sum types. Structures File
, Local
and Remote
inherit the path
and created
fields. Local
and Remote
also contain the entries
.
type CString ptr
fun get (i : u32) = ptr[i]
The only item of a tuple is bound to the ptr
.
Special functions are defined with fun
, fun get
is an indexer getter.
type Slice<T> @byval =
val ptr : Ptr<T>
val size : u32
type MutSlice<T> @byval @[mut_of Slice] =
val ptr : MutPtr<T> @impl
inherit Slice<T>
The ptr
field has different types for Slice
and mut Slice
.
type Object =
var room : Room @late
The room
binding is not a constructor parameter, will throw an error if accessed before assigned.
# Single-line comment
/* Multiline comment */
Closing part of a multiline lexeme is optional.
Dependency injection
type Selector =
let add_popup : Control -> Unit @auto
let remove_popup : Control -> Unit @auto
let main () =
let selector = Selector.new
let add_popup @publish = app.display.add_popup
let remove_popup @publish = app.display.remove_popup
main
Values of the published add_popup
and remove_popup
bindings will be passed to the corresponding fields of the Selector
object. Both name and type need to match.
Object tree
let stack = Stack
align_h = AlignH/Left
items = margin
text_block
Stack
object is created, then AlignH/Left
is assigned to the align_h
field, then margin
and text_block
are added to the items
list.
stack
align_v = AlignV/Center
is_horizontal = true
Type name is replaced with the binding name, thus no object is created. Result of the expression is the stack
itself.
let border = Border.new
let stack = Stack.new
border
thickness = 5
stack
Button
text = "start"
on_press = { start_calculation }
Button
text = "stop"
on_press = { stop_calculation }
stack
is assigned to the border.content
and buttons are added to the stack.items
. The content
and items
fields have @dst
attribute.