Hacker News new | ask | show | jobs
by Gys 1345 days ago
https://en.wikipedia.org/wiki/K_(programming_language)
2 comments

Most of the time when you open a PL article on Wikipedia you're greeted with a Hello World example, but here you get this:

"""

[...] As a result, K expressions can be opaque and difficult to parse for humans. For example, in the following contrived expression the exclamation point ! refers to three distinct functions:

    2!!7!4
Reading from right to left the first ! is modulo division that is performed on 7 and 4 resulting in 3. The next ! is enumeration and lists the integers less than 3, resulting in the list 0 1 2. The final ! is rotation where the list on the right is rotated two times to the left producing the final result of 2 0 1.

"""

That has to be the tersest language I have ever seen in my life. Code golf but it's actually a real language used heavily in finance.
I think ‘used heavily’ is a bit of an overstatement.

I think the right intuition for APL-family languages is that they mostly do numpy-like operations except their set of operations tend to compose very nicely. So the idea is that one can quickly and interactively figure out a composition of the operations which will do the calculation you want, but you don’t have a complicated compiler and spend most of your time in the operators rather than the interpreted language, and the operators tend to make the cpu happy – they work on contiguous memory, tend to be vectorized, don’t branch unpredictably, etc – so even if you have to compose many steps, you win on the time to write and the time to execute can be hard to beat because the constant factors of each individual operation are good.

For obvious reasons, things like numpy, pandas, dplyr, etc are more popular as their syntax is a bit more readable and it is easier to get data in/out. I think they do lose a bit by not having lots of the useful compostable APL-style operators because those things don’t have comprehensible names.

I wrote http://KlongPy.org to blend Klong and python. Eat your cake and have it too :)
> compostable APL-style operators

APL-style operators have been sent to the compost heap of history for a reason.

Fold

Scan

Map

Head/tail

Index (with an array)

The integers up to n

Concatenate

Flatten

Most of the operators are already familiar but they tend to work well on multidimensional arrays and with each other due to broadcast semantics (and some axis selection features). In other languages you may see the magic broadcasting for some operations like addition but many of the functions only work on vectors.

Some exchanges like BitMEX are written in kdb+, as in, the trade engine.
What is a trade engine?
The actual thing that lines up a series of sell-at-this-price bids and the series of buy-at-this-price bids (or even more complicated types of orders, this the easy case) and crosses them over, figuring out who gets what bids filled by whom at what price, at supremely fast speeds and large volumes.
I think I’ve only heard of such a component referred to as a matching engine.
I've heard it both ways. Now you have as well, so next time you see it, you won't need someone to explain it to you.