Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
42
Task/Currying/M2000-Interpreter/currying-1.m2000
Normal file
42
Task/Currying/M2000-Interpreter/currying-1.m2000
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
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
|
||||
26
Task/Currying/M2000-Interpreter/currying-2.m2000
Normal file
26
Task/Currying/M2000-Interpreter/currying-2.m2000
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
Module Puzzle {
|
||||
Global Group F2 {
|
||||
Sum=0
|
||||
Sum2=0
|
||||
Function Add (x){
|
||||
.Sum+=x
|
||||
=x
|
||||
}
|
||||
}
|
||||
F1=lambda -> {
|
||||
if empty then exit
|
||||
Read x
|
||||
Print ">>>", F2.Sum
|
||||
F2.Sum2++ ' add one each time we read x
|
||||
=x+lambda(![])
|
||||
}
|
||||
Link F2.Add() to F2()
|
||||
P=F1(F1(F1(F2(2)),F2(2), F1(F2(2))),F2(2))=8
|
||||
Print F2.Sum=8
|
||||
Print F2.Sum2=7
|
||||
\\ We read 7 times x, but we get 8, 2+2+2+2
|
||||
\\ So 3 times x was zero, or not?
|
||||
\\ but where we pass zero?
|
||||
\\ zero return from F1 if no argument pass, so how x get zero??
|
||||
}
|
||||
Puzzle
|
||||
Loading…
Add table
Add a link
Reference in a new issue