
K, by Arthur Whitney (2005) - agumonkey
http://archive.vector.org.uk/art10010830
======
fidotron
I had to write a lot of K at university (thus disclosing where I went to, and
confusing people that have written any K with the idea you could possibly
write a lot of it).

Get by the symbolic confusion (Arthur himself used to respond to confused
students on the mailing list about such things) and it's really quite
inspired. I can appreciate how an APL with proper symbols would be properly
productive. Your code ends up super dense, with non-trivial stuff easily
fitting on just a few screens, so you can keep track of what's going on. (KDB
itself, the commercial column based DB product built with K, was notoriously
small for the functionality). The real pain I seem to recall was interfacing
it with anything else, but the entire environment is tiny.

This is one of those languages that really expanded my mind and made me hope
the rest of the world would one day revisit the ideas of the APL family.

~~~
evincarofautumn
> the idea you could possibly write a lot of it

Presumably it’s one of those things where if you find yourself writing a lot
of code, you really ought to question what you’re doing?

> Your code ends up super dense, with non-trivial stuff easily fitting on just
> a few screens, so you can keep track of what's going on.

I have found it really difficult to convince people that the latter follows
from the former—that denser notations actually make code easier to grasp, as
long as you know the notation. The farthest I’ve gotten is: “Look, in a
language that rhymes with Slava, you often have to write an enormous amount of
code in order to accomplish anything and keep it maintainable, right? Well,
there are languages even better about that than the ones you use.”

You may be interested in concatenative programming, a cousin of tacit
programming. Factor ([http://factorcode.org/](http://factorcode.org/)) is a
good dynamic language with a great environment and helpful (though quiet)
community in #concatenative on Freenode. I am working—alas, very slowly—on a
statically typed concatenative language and hope that it will one day help
take these ideas to the mainstream. :)

~~~
agumonkey
I see what you did there.

ps: just in case here's a very enjoyable talk, not about, but by Slava
[http://www.youtube.com/watch?v=f_0QlhYlS8g](http://www.youtube.com/watch?v=f_0QlhYlS8g)
Beautiful and impressive.

------
swannodette
For a real eye opener compare the length of these K versions of the Alioth
benchmarks to their more verbose brethren
[http://kparc.com/$/z/comp.k](http://kparc.com/$/z/comp.k).

I found these on the K OS project page -
[http://kparc.com/os.htm](http://kparc.com/os.htm). There's a great
description of Arthur Whitney building a Notepad like text editor (1K) in 30
minutes or so using this system here - [http://coding-is-like-
cooking.info/2013/09/an-introduction-t...](http://coding-is-like-
cooking.info/2013/09/an-introduction-to-array-languages/).

Personally K is a bit too terse for my tastes - I think something like Nile
achieves some of the terseness of APL without looking like line noise -
[http://github.com/damelang/nile/blob/master/examples/text-
la...](http://github.com/damelang/nile/blob/master/examples/text-layout.nl).

~~~
gruseom
_[http://coding-is-like-cooking.info/2013/09/an-
introduction-t...](http://coding-is-like-cooking.info/2013/09/an-
introduction-t..). _

Thanks, I enjoyed that article. It gives a vivid picture of the gap between
the array languages niche and mainstream programming culture.

~~~
vorg
> Despite my head start with J, by the end of the conference I found APL code
> easier to grasp – J seems more extreme to me. Roger calls J “executable
> mathematical notation”, and I’ve always been a bit more of an engineer than
> a mathematician.

I found this too, when I tried them both, first J then APL, perhaps because:

* APL uses () [] and {} in their pairs to parenthesize things, just like other languages, while J uses the 6 symbols as standalones, harder to read the code.

* All verbs in APL are single characters, whereas J symbols might be more than one.

* J, unlike APL, uses the concepts of rank, and forks and hooks, which are both difficult to grasp and don't seem to add much to the array processing idea.

------
beagle3
Compared to how different k/j/apl are from mainstream programming languages,
c/c++/c#/java/pascal are all dialects of the same language.

You have to think differently when using them - an exercise well worth the
effort. Much like Lisp, if you grok them, your code in any language will be
much better.

And they are not new - APL goes back to the 1950's. K is the refined-for-
practicality version, J is the refined-for-purity-and-mathematical-beauty
version (but it IS practical; in fact, it drops APL's special graphic symbols
which made APL more beautiful but less useful)

------
karterk
K's successor Q is used heavily in financial systems and costs a bomb. Despite
all the big data rage these days, I think Q has been handling very high
volumes of data for a while now with some amazing performance.

The 32-bit trial version of kdb+ is available for non-commercial use [1], so I
went and downloaded it. The linux zip download is 278KB. Uh ok! I was
expecting it to download more stuff (much like Chrome's installation), but
nope, that's all there is to it!

[1]: [http://kx.com/software-download.php](http://kx.com/software-
download.php)

------
mmmbeer
I used K and KDB full-time from around 2003-2005. Very, very good performance,
but very steep learning curve and some frustrating bugs, but getting quick
direct support from Arthur helped a lot (even if his emails were frustratingly
terse! ). What else do you expect from a guy whose email address was a@kx.com?
It forced me to learn functional programming before it was "in". Once you got
the way to think about vectors and functions over vectors you could be very
productive chopping up big data in finance. Fun stuff actually.

------
alexcash
Long time HN lurker...I've worked with kdb+ / k the last few years, it's in
every major bank and is great for storing and querying market data. If you're
looking for a nice GUI I use qStudio, it helps make it a little more friendly.

Then there are great tutorials on the code k website. It's a beautiful
language full of unique original ideas.

------
sz4kerto
Q (post-K) is really fast. However, the arrogance of the language design is
really irritating. It's quite enjoyable to write Q as every working line of
code makes you feel very clever. That's the biggest problem with it, though.

* Disclaimer: I maintained/wrote Q programs for years in a production environment. I'd never choose Q as a production platform again. It's fast but not because it's cleverly written, it's fast because it does not do anything for you.

~~~
beagle3
It doesn't do much for you, true - but after using K for awhile I came to the
conclusion that the vast majority of what other languages give you is not
required.

Sort of like realizing that a lot of lawyers, finance people and even doctors
do not actually provide society at large and even their direct customers any
benefit (though having nontrivial cost), and the world would be a better place
if there were fewer of them.

~~~
soup10
I came to a similar conclusion when programming using a hex editor and the x86
instruction set manual. Without having to clutter my mind with the
abstractions other languages introduce I found I had a ton of free memory to
reason about my code and handle much larger portions of code than I usually
do. Also, by typing in data directly I avoided having to do the mental
translation of thinking about what a compiler or interpreter would do to my
code. Additionally, working directly with the data allows plenty of
opportunity to write self modifying code to minimize memory usage and optimize
program execution to avoid cache misses. I do all my programming in hex
editors now and encourage junior developers at my company to do the same.

~~~
beagle3
I'm sure this was supposed to be funny. But unlike x86 hex coding, people
actually get stuff done in k/q - in fact stuff that runs faster and better
than equivalent systems in C++ and Java. So the reduction ad absurdum does
not, in fact, add to the discussion.

~~~
soup10
What are you talking about. I assure you we get a lot done at the office doing
x86 coding in hex, and even more in MIPS due to the simpler instruction set.

~~~
beagle3
Can you still find usable MIPS hardware these days? You're probably eschewing
keyboards and monitors as well, and program $20 routers by toggling
connections on their serial ports.

------
paddy_m
NumPy is an array oriented library/language too. Idiomatic NumPy usage is
quite terse too. I can see how you can start with NumPy like syntax and then
want something still more terse, but starting from K/Q seems quite hard.

~~~
beagle3
It's more than just terser notation for numpy-style operations. Q (verbose K)
reads cleaner than numpy code - closer to English, in fact, without giving up
any speed. K is the terse mathematical notation for that language.

K has 3 types: atoms, lists, and dictionaries. (atoms can be int, char, float,
symbol, time or function). No objects, no strings, not even files. And yet, it
is enough to express many algorithms concisely and efficiently, with bugs
largely reduced to the class of off-by-one family.

The syntax is not just a superficial aspect of the language - it is
fundamental to its evolution.

------
eddie_the_head
I have a fear that the problem with these APL family languages is that they
ruin coding in any other language for you.

~~~
beagle3
That, in fact, sort of happened to me.

But would you rather remain blissfully unaware?

~~~
eddie_the_head
I want to reach Satori, but the Iversonian enlightenment may be too powerful
to bear for a mere ALGOL-like accustomed mortal.

⍝

------
juliangamble
I didn't 'get' K until I read an interview with Arthur Whitney in the ACM
Queue. Apart from performance, you're also getting craftsmanship.

[http://queue.acm.org/detail.cfm?id=1531242](http://queue.acm.org/detail.cfm?id=1531242)

It turns out he rewrites the whole compiler from scratch in C every four
years.

This is a snapshot from the source code of 'J' also by Arthur Whitney - the
precursor to 'K'.

[http://keiapl.org/rhui/remember.htm#incunabulum](http://keiapl.org/rhui/remember.htm#incunabulum)

This is it described by Ken Iverson:

"The final impetus that got J started was the one-page interpreter fragment
that Arthur wrote, recorded in Appendix A of An Implementation of J [29] and
also reproduced in Appendix A below. My immediate reaction on seeing the page
was recoil and puzzlement: it looked nothing like any C code I had ever seen.
(“Is it even C?”) However, Ken counselled that I should reserve judgment. "

[http://keiapl.org/rhui/remember.htm](http://keiapl.org/rhui/remember.htm)

------
sam_bwut
We use a lot Q (K's kind of successor) and kdb+ at work pretty daunting at
first but the performance is amazing.

------
rtpg
I have a really hard time understanding what APL-likes are useful for. I guess
I don't do a lot of stuff with big vectors, but I feel like it would be hard
to structure code (maybe you don't need to?)

~~~
beagle3
Well, it is very different - but if you have for loops anywhere, then K is
probably useful for what you do. It's like reading/wriing Japanese kanji for
an English speaker - it looks foreign, but it is equally capable and much
terser.

