What does the q @ symbol mean in the context of a function call?

What's going on in the example here?

Source: http://code.kx.com/q/ref/select/#index-at

@[d;1 1 1;+;3]
((1 2 3;4 5 6 7);(17 18;19;20 21);(13 14;15 16 17 18;19 20))

      

+3


source to share


1 answer


http://code.kx.com/wiki/JB:QforMortals2/functions#Functional_Forms_of_Amend

@ [L, I, F, Y]
L = your list
I = index of items to change f = function to apply y = second parameter to f

You can see what it does by posting +

in functions and adding some log output. In this case, it indexes into the second element d@1

, extracts (8 9;10;11 12)

, adds 3, leads to (11 12;13;14 15)

, uses this as next input, adds 3, leads to (14 15;16;17 18)

.



    q)@[d;1 1 1;{0N!("x is:",.Q.s1 x;"y is:",.Q.s1 y);x+y};3]
    ("x is:(8 9;10;11 12)";"y is:3")
    ("x is:(11 12;13;14 15)";"y is:3")
    ("x is:(14 15;16;17 18)";"y is:3")
    (1 2 3;4 5 6 7)
    (17 18;19;20 21)
    (13 14;15 16 17 18;19 20)

      

Or it can be seen using over ( /

):

    q)@/[d;;{0N!(x;y);x+y};3]1 1 1
    ((8 9;10;11 12);3)
    ((11 12;13;14 15);3)
    ((14 15;16;17 18);3)
    (1 2 3;4 5 6 7)
    (17 18;19;20 21)
    (13 14;15 16 17 18;19 20)

      

+2


source







All Articles