Search code examples
kdb+

Why does flipping a list inside a function change the outcome?


I want to flip a list of lists inside a function, but the behaviour changes:

l:(1 5; 7 9; 12 15)

{[x]: x[1] - x[0]} flip l
4 2 3

{[x]: xx:flip x; xx[1] - xx[0]} l
(1 7 12;5 9 15)


Solution

  • The issue is you have a stray : which is causing the function to exit early. Remove it and it runs as expected:

    {[x] xx:flip x; xx[1] - xx[0]} l
    4 2 3
    

    https://code.kx.com/q/basics/syntax/#explicit-return