KX Community

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

Home Forums kdb+ initial item of each prior ‘: match

  • initial item of each prior ‘: match

    Posted by lestat-jin on March 25, 2025 at 2:55 pm

    <div>the example is taken from the Q for mortals each prior section:</div>

    q)(~’:) 1 1 1 2 2 3 4 5 5 5 6 6 

    011010001101b

    was wondering why the first out is 0b instead of integer 1, given each prior returns initial item of the input list? or it is 0b since there is nothing to compare 1 to?

    in general, is it the case (~’:) list  always output 0 as the first element of the output?

    thanks!

    lestat-jin replied 5 days, 18 hours ago 2 Members · 2 Replies
  • 2 Replies
  • rocuinneagain

    Member
    March 25, 2025 at 3:29 pm

    Printing the values being passed each time you can see a null 0N is passed for the first value of y

    q)({-1 .Q.s1 (x;y;x~y);x~y}':) 1 1 1 2 2 3 4 5 5 5 6 6
    (1;0N;0b)
    (1;1;1b)
    (1;1;1b)
    (2;1;0b)
    (2;2;1b)
    (3;2;0b)
    (4;3;0b)
    (5;4;0b)
    (5;5;1b)
    (5;5;1b)
    (6;5;0b)
    (6;6;1b)
    011010001101b

    We can also we with prev and next that nulls are padded as needed:

    q)prev 1 2 3
    0N 1 2
    q)next 1 2 3
    2 3 0N
    • lestat-jin

      Member
      March 25, 2025 at 10:34 pm

      I see, thanks!

Log in to reply.