What is the bold highlight in r.q?

What does the bold highlight in r.q do ? Can someone walk me through it?

u.rep:{**(****.[;();:;].)**each x;if[null first y;:()];-11!y;system "cd ",1_-10_string first reverse y};

Context :- This piece of code is used by a rdb process to define table schemas received from tickerplant on subscription, this is done before replaying the log file.

Lets break the code bit by bit

.[;();:;] is basically a projection of amend, more info here https://code.kx.com/q/ref/amend/#amend-entire

q)type (.[;();:;])

104h

(.[;();:;].) this is projecting (apply) a dyadic projection, thus allowing input arguments to be passed as a list to a n-ary function, more info here https://code.kx.com/q/ref/apply/#apply-index

q)type (.[;();:;].)

104h

q)(.[;();:;].) each ((t;([]$())); (q;([]$())))

tq

q)t

x

q)q

x

Same as this

q).[.[;();:;]] each ((t;([]$())); (q;([]$())))

 

-Ajay

Let’s see if we can  get you started.

The dot followed by the bracketed expression is an operator being applied or projected. From the list of overloads for dot we see it is the quaternary form of Apply known as Replace.

Only two of the arguments are supplied (the second and third) so we have a projection, a binary function of the first and fourth arguments of Replace.

Within the parens that binary function is the left argument of another dot. Back to the list of overloads, where we see this is the binary form of Apply: apply argument g to gx, a list of g’s arguments. Here g is the foregoing binary projection, so the argument of (.[;);:;].) will be a 2-list.

This function is applied to each x, from which we can infer x is a list of name-value pairs.




Stephen Taylor | Librarian | Kx | +44 7713 400852 | stephen@kx.com