Now, my question is whether anyone knows of an even faster way to do it? Alternatively, whether there’s a more elegant way to do it with similar performance.
The lack of lexical scoping and having function arguments always be copied seems unfortunate from a performance point of view. Is my approach (i.e., to allocate data structures in the global scope and then pass around the symbol name) the standard approach?
The definition you see for reverse is the monad form of the K verb | . The colon is an aid to the interpreter, as unless immediately used, the verb always denotes it’s dyad.
e.g. you can see the difference here, where the first item returned is the reverse of the list, and the second item is a projection of the OR dyad.
Thank you for the suggestion . That’s an elegant solution.
I’m struggling to understand it though. Could you please help explain the following?
q) reverse sums 1 2 3 6 3 1 / This makes sense. q) (reverse sums) 1 2 3 1 3 6 / Why did we lose the reverse? q) (reverse sums::) 1 2 3 6 3 1 / Why did this recover the reverse? q) q) sums + / Makes sense. q) reverse |: / Reverse is a combination of the max and assignment operators? q) reverse sums + / Reverse was lost. q) reverse sums:: |+ / Max operator combined with sums?
I suspect the issue is I don’t understand the meaning of | and ::. I had thought | was just the max operator but maybe is also has other meanings? I know :: has at least these meanings:
Defining a view.
Assignment in-place.
Assignment to a global variable.
The generic null.
The identity function.
An elided index used to select everything.
Does :: have yet another meaning here or does one of the above apply?