In q, a general illustration for an operator over
/
is the implementation of a Fibonacci sequence
10 {x,sum -2
This does print the first 10 Fibonacci numbers, but it makes no sense regarding the definition of the operator over
in this whitepaper (p. 8)
With two arguments, the second is a list, the function is called with the left argument as the first parameter and the first element of the right argument as the second parameter. Then, the function is called with the result of the previous iteration as the first parameter and the third element as the second parameter. the process continues in this way for the rest of the list items.
So, in the example with the fibonacci above, at the first iteration, the function will be called using [10;1]
("the first parameter and the first element of the second parameter"), which would already give the wrong result.
My implementation matches the definition (and works)
1 1 {[l;c] l,sum -2
but I don’t like it, because the parameter is c
never used.
How can the first example be reconciled with a definition?
thanks for the help
source
share