Earlier quoted context omitted.
If this were me, and I needed a function like us, I would have written this: us:{$[x~(z;y);,"_";y]}[(*K;,"*")]': I would be interested in seeing anything that was shorter[1] and faster than that in any language , and I would be very curious to learn from anyone who could also do that faster than me. But I'm not a fetishist: I didn't learn k because it was cute, and I don't wake up every day looking for ways to rewrit…
Why do you pass in (*K;,"*") as x instead of hard-coding it in x~(z;y)? Clarity?
v:("select";,"*";"from";"tacos")
us:{$[#i:&{(y~*K)&"*"~*x}':x;@[x;i;:[;,"_"]];x]}
\t:100000 us v
233
us:{$[(*K;,"*")~(y;x);,"_";x]}':
\t:100000 us v
206
w:(*K;,"*");us:{$[w~(y;x);,"_";x]}':
\t:100000 us v
179
us:{$[x~(z;y);,"_";y]}[(*K;,"*")]':
\t:100000 us v
129
I think it's important to remember just how simple k is: We the programmer know that (*K;,"*") isn't supposed to change, so we should be explicit so k "knows" this as well. In addition to never changing, we also know the value is only used once, so we really don't want to look anything up in the workspace every time we call us: Again, let us be explicit.On the other hand, this:
us:{$[#i:& XXX ;@[x;i;:[; YYY ]];x]}
is an extremely recognisable idiom. It occurs several times in sql.k so the reader is probably used to seeing it at this point. It also has a similar syntactic structure to the APL '@' so it may be more "obvious" to an APL programmer. Maybe the reason I write it this way is that I'm not a very experienced APL programmer :)