4 ms·
{x#x{x,+/-2#x}/0 1} I'm sure if you used K for a year or so, that would be obvious and understandable at a single glance. But all I can think of is that I use
by chiph 5y ago
{x#x{x,+/-2#x}/0 1}
I'm sure if you used K for a year or so, that would be obvious and understandable at a single glance. But all I can think of is that I used to see that in my terminal session right after my modem got disconnected.
- rak1507 5y agoBeen doing k for a bit (under a year). A single glance is optimistic, but probably only took me a few seconds. Almost certainly faster than any equivalent code in any other language. It's even easier if you give it a nice name, like "fib".
- pabs3 5y agoWhat kind of projects does K get used in?
- rak1507 5y agoI don't use it professionally or anything like that but most of the real world use as far as I know is in finance stuff.
- WillDaSilva 5y agoMainly time-series data processing through kdb+. There's an IDE and language tools for q (which is a thin layer over k) that is primarily written in q called: https://code.kx.com/developer/ https://code.kx.com/developer/ Unfortunately it's closed source so I can't share much about the world of application and library development with q/k. If you want to learn more about how it's used though, I'd recommend checking out KX and kdb+.
- razetime 5y agoThis website has a few companies which use K: https://github.com/interregna/arraylanguage-companies https://github.com/interregna/arraylanguage-companies
- travisjungroth 5y agoI think this hints at the main issue people have when reading more terse code: you need to read it slower. If you try to read K at the same speed as C, it’s going to fly by. I can feel this in my own Python code when I write in a more or less compact style. But on the more dense code, if I slow down, I can understand it faster and more clearly than the verbose code.
- gjulianm 5y agoIt's not only slower to read but requires much more context to understand. Take a look at the Rosetta code page for Fibonacci [1]. For most languages you'll be able to mostly identify what each part is doing. They rely on concepts that most programmers consider intuitive. K relies on a completely different set of knowledge that you need to have to even start to grasp what the code is doing. 1: https://rosettacode.org/wiki/Fibonacci_sequence https://rosettacode.org/wiki/Fibonacci_sequence
- rak1507 5y agoI'm not going to deny that learning any array language requires thinking slightly differently (as does any new paradigm), but really this example doesn't use anything particularly strange. {x#x{x,+/-2#x}/0 1} x x is the argument of an anonymous function {} , concat +/ plus reduce (sum) -2#x last two elements of x x f /0 1 applied x times to 0 1 x# take first x elements
- gjulianm 5y agoIt does have some strange things: - What's the scope of x? it appears to be the argument of two different anonymous functions. - Is / both apply and reduce? - So 'x f list' applies f to list x times. What if I use ',' instead of f? That is, what does 'x,/list-of-lists' do? does it flatten the list of lists and then concatenates x or does it flatten the list of lists x times? It seems confusing to have symbols that act both as operators and as functions. - Why is '-2#x' "take last two elements of x" and not "negate the first two elements of x"? If I understand correctly, based on the evaluation order you're using it should be the latter, no? And all of that from a simple Fibonacci function. I can't imagine how difficult it must be to dive into an actually complex codebase. And it's not just about the different paradigm. That's not the problem, the problem is focusing on terseness above all. I get that once you are deep into a language or codebase you lose sight of the complexities because you get used to them. But it doesn't mean they aren't there.
- WillDaSilva 5y agoThe /0 1 gives it away practically immediately for me, but that might just be because I've seen/used that particular example so many times.
- Aerroon 5y agoHow many years did you spend on mathematics? How comfortable are you with reading math notation? I think the same problem applies. If you don't remember the specific of a symbol it becomes difficult to understand what the symbol might be without context.
- lvncelot 5y agoIs it that much worse than, for instance: kvPairs.reduce((acc, [k,v]) => ({...acc, [k]: v}), {}) (Which obviously has nothing to do with the K-Snippet but is the first thing that came to my mind that's equally as symbol-heavy)
- wizzwizz4 5y agoYes. I don't know what language that is, but I know what it means: take some key-value pairs, and reduce them with an accumulator, and make a new dictionary with the items from the accumulator, plus another entry mapping a list of the key to a value, starting with {}. Alternatively: mut acc = {} for k, v in kvPairs { acc[[k]] = v; } acc Am I much wrong?
- lvncelot 5y agoHuh, no you're exactly right. (It's javascript, btw)
- still_grokking 5y agofib = 0 fby ( 1 fby fib + next fib ); That's how this would look in a data-flow language. "fby" means "flowed by". It constructs a stream. So you can be quite terse without loosing the clarity just by using the right abstraction. Example taken form: https://en.wikipedia.org/wiki/Lucid_(programming_language) https://en.wikipedia.org/wiki/Lucid_(programming_language)