Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,6 @@
|
|||
A$={{ Module "Fibonacci" : Read X :If X<0 then {Error {X<0}} Else Fib=Lambda (x)->if(x>1->fib(x-1)+fib(x-2), x) : =fib(x)}}
|
||||
Try Ok {
|
||||
Print Function(A$, -12)
|
||||
}
|
||||
If Error or Not Ok Then Print Error$
|
||||
Print Function(A$, 12)=144 ' true
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
Function fib(x) {
|
||||
If x<0 then Error "argument outside of range"
|
||||
If x<2 then =x : exit
|
||||
Def fib1(x)=If(x>1->lambda(x-1)+lambda(x-2), x)
|
||||
=fib1(x)
|
||||
}
|
||||
Module CheckIt (&k()) {
|
||||
Print k(12)
|
||||
}
|
||||
CheckIt &Fib()
|
||||
Print fib(-2) ' error
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
fib=lambda -> {
|
||||
fib1=lambda (x)->If(x>1->lambda(x-1)+lambda(x-2), x)
|
||||
=lambda fib1 (x) -> {
|
||||
If x<0 then Error "argument outside of range"
|
||||
If x<2 then =x : exit
|
||||
=fib1(x)
|
||||
}
|
||||
}() ' using () execute this lambda so fib get the returned lambda
|
||||
Module CheckIt (&k()) {
|
||||
Print k(12)
|
||||
}
|
||||
CheckIt &Fib()
|
||||
Try {
|
||||
Print fib(-2)
|
||||
}
|
||||
Print Error$
|
||||
Z=Fib
|
||||
Print Z(12)
|
||||
Dim a(10)
|
||||
a(3)=Z
|
||||
Print a(3)(12)=144
|
||||
Inventory Alfa = "key1":=Z
|
||||
Print Alfa("key1")(12)=144
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
Class Something {
|
||||
\\ this class is a global function
|
||||
\\ return a group with a value with one parameter
|
||||
private:
|
||||
\\ we can use lambda(), but here we use .fib1() as This.fib1()
|
||||
fib1=lambda (x)->If(x>1->.fib1(x-1)+.fib1(x-2), x)
|
||||
public:
|
||||
Value (x) {
|
||||
If x<0 then Error "argument outside of range"
|
||||
If x<2 then =x : exit
|
||||
=This.fib1(x) \\ we can omit This using .fib1(x)
|
||||
}
|
||||
}
|
||||
K=Something() ' K is a static group here
|
||||
Print k(12)=144
|
||||
Dim a(10)
|
||||
a(4)=Group(K)
|
||||
Print a(4)(12)=144
|
||||
pk->Something() ' pk is a pointer to group (object in M2000)
|
||||
\\ pointers need Eval to process arguments
|
||||
Print Eval(pk, 12)=144
|
||||
Inventory Alfa = "Key2":=Group(k), 10*10:=pk
|
||||
Print Alfa("Key2")(12)=144
|
||||
Print Eval(Alfa("100"),12)=144, Eval(Alfa(100),12)=144
|
||||
Loading…
Add table
Add a link
Reference in a new issue