RosettaCodeData/Task/Currying/M2000-Interpreter/currying-1.m2000
2023-07-01 13:44:08 -04:00

42 lines
1.2 KiB
Text

Module LikeGroovy {
divide=lambda (x, y)->x/y
partsof120=lambda divide ->divide(120, ![])
Print "half of 120 is ";partsof120(2)
Print "a third is ";partsof120(3)
Print "and a quarter is ";partsof120(4)
}
LikeGroovy
Module Joke {
\\ we can call F1(), with any number of arguments, and always read one and then
\\ call itself passing the remain arguments
\\ ![] take stack of values and place it in the next call.
F1=lambda -> {
if empty then exit
Read x
=x+lambda(![])
}
Print F1(F1(2),2,F1(-4))=0
Print F1(-4,F1(2),2)=0
Print F1(2, F1(F1(2),2))=F1(F1(F1(2),2),2)
Print F1(F1(F1(2),2),2)=6
Print F1(2, F1(2, F1(2),2))=F1(F1(F1(2),2, F1(2)),2)
Print F1(F1(F1(2),2, F1(2)),2)=8
Print F1(2, F1(10, F1(2, F1(2),2)))=F1(F1(F1(2),2, F1(2)),2, 10)
Print F1(F1(F1(2),2, F1(2)),2, 10)=18
Print F1(2,2,2,2,10)=18
Print F1()=0
Group F2 {
Sum=0
Function Add (x){
.Sum+=x
=x
}
}
Link F2.Add() to F2()
Print F1(F1(F1(F2(2)),F2(2), F1(F2(2))),F2(2))=8
Print F2.Sum=8
}
Joke