KX Community

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

Home Forums kdb+ Five easy pieces #4: Little Six Re: Five easy pieces #4: Little Six

  • SJT

    Member
    March 19, 2024 at 10:55 am

    Very nice! Especially the use of Converge. Your expression makes it clear that the permutation returns to the original order and that the envoi has the order of the original.

    Further thoughts: if you use Do with a left argument of 6, you can then use Apply At @ to apply " "sv'2 cut to the last item. This expression emphasises that the permutation returns the envoi to the original order.

     

    sest1:{1_raze” “,/:@[;6;” “sv’2 cut]6 @[;5 0 4 1 3 2]x}

     

    Getting down to a single reference to the argument introduces the possibility of writing the function as a composition, which eliminates the tiny overhead of a lambda. Here we can use the bracket notation you introduced earlier for Do.

     

    sest2:1_ raze ” “,/: @[;6;” “sv’2 cut] @[;5 0 4 1 3 2][6;] @

     

    Above spaces clarify the structure a composition of five unaries:

    1. 1_
    2. raze
    3. " ",/:
    4. @[;6;" "sv'2 cut]
    5. @[;5 0 4 1 3 2][6;]

    If you’ve read this far, test your understanding!

    When projecting a binary function f onto its first argument (e.g. 6) we can elide the semicolon and write either f[6;] or f[6]. Why can we not do that here why does @[;5 0 4 1 3 2][6] not work?

    Lastly, can 5 0 4 1 3 2 become a function of the stanza length assuming an even number of lines? That would support new forms, such as an octrina (I just made that word up) or a quatrina.