Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
|
|
@ -1,42 +0,0 @@
|
|||
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
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
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
|
||||
59
Task/Currying/M2000-Interpreter/currying.m2000
Normal file
59
Task/Currying/M2000-Interpreter/currying.m2000
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
Module LikeGroovy {
|
||||
divide=lambda (x, y)->x/y
|
||||
Curry=lambda (f as lambda, k)->(lambda f, k ->(f(k,![])))
|
||||
partsof120=Curry(divide, 120)
|
||||
Print "half of 120 is ";partsof120(2)
|
||||
Print "a third is ";partsof120(3)
|
||||
Print "and a quarter is ";partsof120(4)
|
||||
|
||||
joinTwoWordsWithSymbol=lambda (s, a, b)->a+s+b
|
||||
Assert joinTwoWordsWithSymbol("#","Hello", "World")="Hello#World"
|
||||
concatWords =Curry(joinTwoWordsWithSymbol, " ")
|
||||
Assert concatWords("Hello", "World")="Hello World"
|
||||
prependHello =Curry(concatWords, "Hello")
|
||||
Assert prependHello("World")="Hello World"
|
||||
Print "done"
|
||||
}
|
||||
LikeGroovy
|
||||
Module M2000way {
|
||||
class curry{
|
||||
private:
|
||||
p=stack ' stack of values
|
||||
func$ ' field for the weak reference
|
||||
public:
|
||||
property counter {value } ' readonly
|
||||
class:
|
||||
module curry(.func$) {
|
||||
.p<=[]
|
||||
class value {
|
||||
value () {
|
||||
' symbol ! used for feeding stack of values from arrays or stacks.
|
||||
' [] is the current stack (leave emtpy stack as current stack)
|
||||
' Stack(.p) make a copy of .p (which have a stack object)
|
||||
=function(.func$, !stack(.p), ![])
|
||||
.[counter]++
|
||||
}
|
||||
}
|
||||
this=value() ' make this as a property
|
||||
}
|
||||
}
|
||||
' using a general function
|
||||
Function Divide(a, b) {
|
||||
=a/b
|
||||
}
|
||||
Print "Divide(10, 6) is ";Divide(10, 5)
|
||||
partsof120=Curry(&Divide(), 120)
|
||||
Print "half of 120 is ";partsof120(2)
|
||||
Print "a third is ";partsof120(3)
|
||||
Print "and a quarter is ";partsof120(4)
|
||||
Print "Use of partsof120 so far: "; partsof120.counter; " times"
|
||||
' using a lambda function
|
||||
joinTwoWordsWithSymbol=lambda (s, a, b)->a+s+b
|
||||
Assert joinTwoWordsWithSymbol("#","Hello", "World")="Hello#World"
|
||||
concatWords =Curry(&joinTwoWordsWithSymbol, " ")
|
||||
Assert concatWords("Hello", "World")="Hello World"
|
||||
prependHello =Curry(&concatWords, "Hello")
|
||||
Assert prependHello("World")="Hello World"
|
||||
Print "done"
|
||||
}
|
||||
M2000way
|
||||
Loading…
Add table
Add a link
Reference in a new issue