tenticon
tenticon

Reputation: 2913

q - Applying arbitrary function while zipping

in q the dyadic zip operation is done by '. I.e.

l1:("a1";"a2")
l2:("b1";"b2")
(l1,'l2)~("a1b1";"a2b2")

I parse this ' as a dyadic operator '[g;l2] where g is a projection of some dyadic function on lists onto a monadic function, e.g. g:,[l1;].

So if we want to perform any other map apart from , during the zipping operation, I would redefine g.

However, '[g;l2] does not give me the expected list output but returns func

The question is: how do I apply arbitrary maps during the zipping operation? E.g. how do I do something like l1 f' l2 where in the example f:, but in general f some dyadic operator on to list items?

Thanks for the help

Upvotes: 0

Views: 98

Answers (1)

Alexander Belopolsky
Alexander Belopolsky

Reputation: 2268

how do I apply arbitrary maps during the zipping operation?

Like this:

q)f:{x+y}
q)f'[10*x;x:til 5]
0 11 22 33 44

If you like the infix notation, you can also do

q)(10*x) f' til 5
0 11 22 33 44

Note that '[g;l1] is a composition. If you want to create a projection, do

q)g:,'[l1;]
q)g l2
"a1b1"
"a2b2"

Upvotes: 1

Related Questions