bog icon indicating copy to clipboard operation
bog copied to clipboard

Add lazy expressions

Open Vexu opened this issue 5 years ago • 0 comments

lazy expressions would be the language level equivalent of std.once. The value of the expression would only be executed once and only if needed. These would mainly be beneficial for expensive calculations that are only needed sometimes.

const {print} = import("std.io")
const {assert} = import("std.debug")
const x = lazy
    print("resolved")
    2

let y = 2
y += x # "resolved"
y += x # nothing
assert(y == 6)

Vexu avatar Jun 14 '20 14:06 Vexu