Data update
This commit is contained in:
parent
52a6ef48dd
commit
157b70a810
604 changed files with 14253 additions and 2100 deletions
|
|
@ -0,0 +1,11 @@
|
|||
local fn Fibonacci( n as long ) as long
|
||||
if n < 0 then printf @"Invalid argument: \b" : return n
|
||||
if n < 2 then return n else return fn Fibonacci( n - 1 ) + fn Fibonacci( n - 2 )
|
||||
end fn = 0
|
||||
|
||||
print fn Fibonacci(20)
|
||||
print fn Fibonacci(30)
|
||||
print fn Fibonacci(-10)
|
||||
print fn Fibonacci(10)
|
||||
|
||||
handleevents
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
def fib(n):
|
||||
def aux: if . == 0 then 0
|
||||
elif . == 1 then 1
|
||||
else (. - 1 | aux) + (. - 2 | aux)
|
||||
end;
|
||||
if n < 0 then error("negative arguments not allowed")
|
||||
else n | aux
|
||||
end ;
|
||||
else [2, 0, 1]
|
||||
| recurse( if .[0] > n then empty
|
||||
else [ .[0]+1, .[2], .[1]+.[2] ]
|
||||
end)
|
||||
| .[1]
|
||||
end;
|
||||
|
|
|
|||
8
Task/Anonymous-recursion/Jq/anonymous-recursion-3.jq
Normal file
8
Task/Anonymous-recursion/Jq/anonymous-recursion-3.jq
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
def fib(n):
|
||||
def aux: if . == 0 then 0
|
||||
elif . == 1 then 1
|
||||
else (. - 1 | aux) + (. - 2 | aux)
|
||||
end;
|
||||
if n < 0 then error("negative arguments not allowed")
|
||||
else n | aux
|
||||
end ;
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
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
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
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
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
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
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
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
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
module Anonymus_lambda {
|
||||
Print lambda (x as long long)->{=If(x>1->lambda(x-1)+lambda(x-2), x)}(10)=55
|
||||
}
|
||||
Anonymus_Lambda
|
||||
Loading…
Add table
Add a link
Reference in a new issue