2

I figure, to be a real KDB expert, I should learn K, right? So I can write some fast functions and understand how things actually work, etc.?

I found this definition of factorial that does not work, even though it was an example in K-Lite Ref Manual.

fac1: {:[x>1; x * fac[x-1]; 1]}

I modified it to use if rather than conditional (:) and it works.

fac2: {if[x>1; :x * fac[x-1]]; 1}

Has the ":[a;b;c]" syntax gone away? What replaced it?

Is there a cheat sheet for the actual version of K that is underlying KDB+ that I can get a copy of?

Please?

I'm actually kind of falling in love with K. Get a load of Quicksort in K:

https://rosettacode.org/wiki/Sorting_algorithms/Quicksort#K

OMG! Makes other languages seem SO long winded!

JSLover
  • 165
  • 1
  • 10

1 Answers1

2

Try using $ (if-else) instead of :

http://code.kx.com/q/ref/control/#cond

Here is a cheat sheet for learning q/kdb+. https://github.com/KxSystems/kdb/blob/master/d/primer.htm

IMO it will much easier to start learning q as there are much more resources available. i.e code.kx

Example:

fac:{$[x>1; x * fac[x-1]; 1]}

Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
Connor Gervin
  • 935
  • 5
  • 16
  • That DOES seem to work inside of K functions as well, as far as I can tell. THANKS! – JSLover Sep 27 '16 at 15:22
  • Yes, the dollar operator is natively from k. Remember that q, in it's simplest form, is an additional layer of functions written in k. Have a look at $QHOME/q.k :) – Connor Gervin Sep 27 '16 at 15:58
  • 2
    @JSLover: please note that writing functions in k will not make them any faster than _equivalent_ q implementations. – Igor Korkhov Sep 28 '16 at 09:10
  • 1
    @IgorKorkhov I'm assuming that, by learning to read k, I will then be able to study q.k and understand the underlying data structures. When I understand how things really work, I will be able to do all kinds of cool stuff, like write my own join operators, etc. Am I making sense? – JSLover Oct 01 '16 at 14:00