Anonymous recursion: Difference between revisions

Content added Content deleted
Line 1,400: Line 1,400:
Inventory Alfa = "key1":=Z
Inventory Alfa = "key1":=Z
Print Alfa("key1")(12)=144
Print Alfa("key1")(12)=144
</lang>

Using a Group (object in M2000) like a function

A Group may have a name like k (which hold a unique group), or can be unnamed like item in A(4), or can be pointed by a variable (or an array item) (we can use many pointers for the same group)


<lang M2000 Interpreter>
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
</lang>
</lang>