jorts/examples/closures.jt

23 lines
328 B
Text
Raw Normal View History

import io
fn main () {
x := 0
// since variable are immutable but updatable, x is 1 inside clojure, but
// 0 inside main()
fn inner() {
x++
}
inner()
// shows 0
io.puts("x is {x}")
// however, if you explicitly update x:
x = inner()
// shows 1
io.puts("x is {x}")
}