25 lines
799 B
Plaintext
25 lines
799 B
Plaintext
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
|