RosettaCodeData/Task/Apply-a-callback-to-an-array/M2000-Interpreter/apply-a-callback-to-an-array.m2000
2023-07-01 13:44:08 -04:00

26 lines
513 B
Text

a=(1,2,3,4,5)
b=lambda->{
push number**2
}
Print a#map(b) ' 1 4 9 16 25
Print a#map(b, b) ' 1 16 81 256 625
b=lambda (z) ->{
=lambda z ->{
push number**z
}
}
Print a#map(b(2)) ' 1 4 9 16 25
Print a#map(b(3)) ' 1 8 27 64 125
\\ second example
a=(1,2,3,4,5)
class s {sum=0}
\\ s is a pointer to an instance of s()
s->s()
c=lambda s -> {
push number+number
s=>sum=stackitem() ' peek the value from stack
}
\\ c passed by value to fold(), but has a pointer to s
Print a#fold(c, 100)=115
Print s=>sum=115