Objects
An object stores a list of values, organized as a dictionary. The type is {}
.
#![allow(unused)] fn main() { a := {x: 1, y: "hi"} }
To change a value in an object:
#![allow(unused)] fn main() { a.x = 2 }
Alternative:
#![allow(unused)] fn main() { a["x"] = 2 }
The value must be of the same type.
If you want to change the type, use :=
:
#![allow(unused)] fn main() { a.x := "hi!" }
Insert new keys and values with :=
:
#![allow(unused)] fn main() { a := {} a.x := 1 a.y := 2 a.z := 3 }
Some useful functions
fn has({}, str) -> bool
- returntrue
if object has keyfn keys({}) -> [str]
- return keys of object