Got it, Thank you all.
I had thought about the overloading, but at that moment, I thought a map is (or acts as) a (partial) function too, so this design is not very self-consistent.
So how do we usually do the overloading in Q? Is it doing some predicating on the argument(using type/count/… etc) then going to different branches the right way?
– ZHUO QL (KDr2) http://kdr2.com
On Wednesday, November 16, 2016 7:36 AM, Jack Andrews <effbiae@gmail.com> wrote:
>for the amend the first parameter has to be a map
i believe markus is correct. the wiki for trap has been updated:
“Triadic @ and . are trap /when x is a function/.”
@ is overloaded like many other operators eg: dyadic/triadic ‘?’
q)?[1 2 0;2]
1
q)?[3;2]
1 0 1
both of the ? expressions are dyadic, but the first is ‘find’ and the second is ‘rand’.
note that ? also has two triadic forms (vector conditional and select)
to understand how q achieves this, recall that you can get the type of any value. when @, . or ? is called with three arguments, the q function checks the type of the arguments* and then decides what function (trap/amend,find/rand) applies.
it’s “overloading”. in C++:
char*string(int);
char*string(struct timeval);
string behaves according to it’s argument.
*it seems that q only needs to check the type of the first parameter to determine what function @ is.
..this explains the order of arguments to dyadic ‘?’ - it’s unusual to have control in y and data in x.