RosettaCodeData/Task/Higher-order-functions/M2000-Interpreter/higher-order-functions-2.m2000
2023-07-01 13:44:08 -04:00

26 lines
531 B
Text

Foo = Lambda k=1 (x)-> {
k+=2
=x**2+K
}
\\ by ref1
Function Bar1(&f(), k) {
=f(k)
}
Print Bar1(&Foo(), 20)=403
\\ by ref2
Function Bar2(&f, k) {
=f(k)
}
Print Bar2(&Foo, 20)=405
\\ by value
Function Bar(f, k) {
=f(k)
}
\\ we sent a copy of lambda, and any value type closure copied too
Print Bar(Foo, 20)=407
Print Bar1(&Foo(), 20)=407
\\ we can get a copy of Foo to NewFoo (also we get a copy of closure too)
NewFoo=Foo
Print Bar1(&Foo(), 20)=409
Print Bar2(&Foo, 20)=411
Print Bar2(&NewFoo, 20)=409