Skip to content

References

Ref<T> points to a value of type T. It compiles to a Go pointer *T but is never nil.

& takes a reference to a value that has an address: a variable, a field, or an element.

let user = User { name: "Alice", tags: ["admin"] }
let user_ref = &userRef<User> pointing to user
let name_ref = &user.nameRef<string> pointing to user.name
let tag_ref = &user.tags[0]Ref<string> pointing to user.tags[0]

Literals, map values, and constants have no address.

const LIMIT = 10
let ages = Map.new<string, int>()
let a = &42error: cannot take address of literal
let b = &ages["Bob"]error: cannot take address of map index expression
let c = &LIMITerror: const bindings are not addressable

.* reads the value that a reference points to:

let name = name_ref.*"Alice"
let tag = tag_ref.*"admin"

Only a mut Ref<T> accepts writes. To get one, take & of a writable value:

fn bump(n: mut Ref<int>) {
n.* += 1
}
let mut count = 1
let total = 1
bump(&count)&count is a mut Ref<int>
bump(&total)error: expected mut Ref<int>, found Ref<int>

In a method call, Lisette auto-adds & or .* to the receiver as needed:

struct Rectangle {
width: float64,
height: float64,
}
impl Rectangle {
fn area(self) -> float64 {
self.width * self.height
}
fn scale(self: mut Ref<Rectangle>, factor: float64) {
self.width *= factor
}
}
let mut rect = Rectangle { width: 10.0, height: 5.0 }
let rect_ref = &rect
rect_ref.area()same as rect_ref.*.area()
rect.scale(2.0)same as (&rect).scale(2.0)