foolang
foolang copied to clipboard
use let and var to declare class slots
Let declares an immutable slot.
class Point { x y }
end
-->
class Point
let x.
let y.
end
Can define slots which use values from earlier slots. (Evaluated in context where there is no self, and slots are represented by temporary variables -- object is always fully constructed)
class Page
let url.
let content = url fetch.
end
Var declares a mutable slot:
class Counter
var value := 0
method next
value := value + 1!