K, by Arthur Whitney (2005)
archive.vector.org.uk
archive.vector.org.uk
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.
(J is a different language; both J and K can be traced back to the origin of A, a 20 C line implementation of an APL dialect)
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/) 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. :)
ps: just in case here's a very enjoyable talk, not about, but by Slava http://www.youtube.com/watch?v=f_0QlhYlS8g Beautiful and impressive.
I found these on the K OS project page - 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....
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....
life:{3=a-x*4=a:2{+(0+':x)+1_x,0}/x}
0+':x -> "sum each element with one to the left
(0 left of the first)"
1_x,0 -> "drop first, add zero at the end"
(0+':x)+1_x,0 -> "sum each element with the one
to the left and the one to the
right (sum of previous expressions)"
a:2{+...}/x -> "do that; transpose; do that;
transpose again, and assign to a.
2{}/ means 'do twice'"
At this point, "a" has the same shape of "x", but in every element is the sum of the elements of x from that location, one above, one below, one left, and one right. 4=a -> "1 where a=4, 0 otherwise"
x*4=a -> "1 where x is 1 and a=4, 0 otherwise"
a-x*4=a -> "decrease a from 4 to 3 if x=1 in the
that place"
3=a-x*4=a -> "1 where one has 3 neighbours"
So, if x is a 1/0 matrix "life x" does one iteration of Conway's game of life. And "1000 life/ x" would seek convergence or return to first state (but no more than 1000 iterations).There is code golfing here; It would have been purely readable K code if it wasn't golfed. But it would also have been two to three times as long.
Thanks, I enjoyed that article. It gives a vivid picture of the gap between the array languages niche and mainstream programming culture.
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.
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)
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!
Then there are great tutorials on the code k website. It's a beautiful language full of unique original ideas.
* 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.
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.
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.
But would you rather remain blissfully unaware?
⍝
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
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. "