26 lines
420 B
Plaintext
26 lines
420 B
Plaintext
# Tests closures
|
|
import std;
|
|
|
|
|
|
fn makeClosure(x: int): fn: int {
|
|
fn inner: int {
|
|
return x;
|
|
}
|
|
return inner;
|
|
}
|
|
|
|
|
|
fn makeClosureTwo(y: int): fn: int {
|
|
fn inner: int {
|
|
return y;
|
|
}
|
|
return inner;
|
|
}
|
|
|
|
|
|
# These should all print true!
|
|
var closure = makeClosure(42);
|
|
print(closure() == 42);
|
|
print(makeClosureTwo(38)() == 38);
|
|
var closureTwo = makeClosureTwo(420);
|
|
print(closureTwo() == 420); |