foolang icon indicating copy to clipboard operation
foolang copied to clipboard

use let and var to declare class slots

Open nikodemus opened this issue 2 years ago • 0 comments

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!

nikodemus avatar Jul 29 '21 15:07 nikodemus