KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums KX Academy Why does this work: value each {x+y+z}[1;;],’enlist (2;enlist 3)

  • Why does this work: value each {x+y+z}[1;;],’enlist (2;enlist 3)

    Posted by mannix on April 14, 2022 at 12:00 am

    I understand the function and the projec`tion.

    I’m wondering what is ”   ,’    ” and why is it used here

    Why do we enlist the list, and enlist 3 inside the list but not 2.

    What is the “each” doing here, as far as I can see {x+y+z}[1;;],’enlist (2;enlist 3) is one thing in itself?

    mannix replied 8 months, 2 weeks ago 2 Members · 1 Reply
  • 1 Reply
  • eohara

    Member
    April 14, 2022 at 12:00 am

    Might be best to deal with this in pieces

    q)(2;3)
    2 3
    q)(2;enlist 3)
    2
    ,3

    Here, the enlist is to prevent 2 and 3 concatenating into a simple list of longs.

    The difference in the final output is an extra level of enlisting:

    q)value each{x+y+z}[1;;],’enlist(2;3)
    ,6
    q)value each{x+y+z}[1;;],’enlist(2;enlist 3)
    6
    q)type value each{x+y+z}[1;;],’enlist(2;enlist 3)
    0h
    q)type value each{x+y+z}[1;;],’enlist(2;3)
    7h

    Why the other enlist?

    q){x+y+z}[1;;],'(2;enlist 3)
    {x+y+z}[1;;] 2
    {x+y+z}[1;;] 3
    q){x+y+z}[1;;],’enlist(2;enlist 3)
    {x+y+z}[1;;] 2 ,3

    In the first example, each element of the right-hand list (2 and ,3) is joined to the projection, which results in two projections being returned.
    With the enlist, the right-hand side is now a one-element list (the element being (2;,3)). This is joined to the projection.

Log in to reply.