Re:KX Systems (KDB/k/q) overhauls its website
by tlack on Monday January 07, 2013 @02:21AM
(#5019866)
Like everything else in our business, it seems harder at first glance than it really is. It's a powerful language and like many powerful things it takes a while to learn. For instance here's my really rough I've-forgotten-most-of-K translation of that first snippet:
x@>#:'x
Read from right to left: :'x
means apply the function/operator to the left of the : to each item of x (the default first parameter to a function is called simply x - big time saver) #:'x
means the length of each item of x, and adding the sorting function: >
means sort the items and return the indices the items would have if they were in ascending order. Finally: @
is just the indexing operator (as you'd kind of expect when saying 'at'), so the whole line means: return the elements of x after sorting them by their length.
Re:KX Systems (KDB/k/q) overhauls its website
by necubi on Monday January 07, 2013 @02:11AM
(#5019845)
And K isn't nearly as bad as its predecessor APL [0], which makes extensive use of non-ASCII characters to bring even greater compactness.
For example, the Game of Life in APL is
life←{↑1 ⍵∨.∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵}
[0] http://en.wikipedia.org/wiki/APL_(programming_language)
The following expression sorts a list of strings by their lengths:
x@>#:'x
A function to determine if a number is prime can be written as:
{&/x!/:2_!x}
This looks like brainfuck's cousin, but I'll bet Perl users feel right at home. Edit: I'm not trying to make fun of Perl or anything, it's just that I've seen some really hard to read one liners come out of it as well.