Klong – a simple array language
t3x.org
t3x.org
I've never felt the same confidence when looking at K - perhaps it really does suddenly "click" if you just sit down and start trying to do something useful with it, but right now, I really do just see gibberish. A couple of times I've glanced at a K tutorial and I've been confused by about the second paragraph (and not really able to commit any of the cryptic runes to memory). I sincerely wonder whether if my career, or perhaps my life, depended on it, I would suddenly find myself able to write and understand (!R)@&{&/x!/:2_!x}'!R (I took that from the Wikipedia page; it may or may not just be line noise, I can't tell).
Has anyone else experienced this and overcome it (with K, or something similar)? It hardly matters to me since I'm unlikely ever to have to write K, but it does make me wonder!
But you begin to see patterns. You write programs and begin to feel out the fringes of the language. You start to be able to write small programs that work correctly the first time.
With Forth, I learned to track the stack in my head. With K, I learned to think in parallel, collective operations. They are eminently learnable, and when you make it through the learning process, you will emerge with new tools for thinking about problem solving.
I now find K a very pleasant language to reach for when I want to tinker. I can write complex and interesting programs quickly, and completely rewrite them in seconds when I get a different idea. Here is a GIF recording of me making a series of programs in K, perhaps demonstrating the kind of fluidity you can get when you become conversant in the language:
https://raw.githubusercontent.com/JohnEarnest/ok/gh-pages/ik...
It's a lot like learning any new language, and probably spoken languages are a better comparison than programming languages.
At first, you have trouble even differentiating boundaries between words, but as you gain experience, your brain extracts the features as units. You begin to see units directly, which gives context that assists in reading component characters, whereas before you'd have to first labor through each character individually to construct the context.
You need to treat it as a conversation with the REPL and build up little parts.
Also, reading other people's solutions to problems you've solved yourself is enlightening.
On HN, geocar and beagle3 are both names that come to mind as proponents of these types of languages and have very interesting comments. You could search their name for more info, probably. There's a couple good breakdowns of code here[1] and here[2].
[0] https://twitter.com/losvedir/status/636034419359289344 [1] https://news.ycombinator.com/item?id=9120246 [2] https://news.ycombinator.com/item?id=8476016
http://johnearnest.github.io/ok/index.html
There's a manual, and a guide to some programming techniques here:
https://github.com/JohnEarnest/ok/blob/gh-pages/docs/Manual....
https://github.com/JohnEarnest/ok/blob/gh-pages/docs/Program...
Examples and more discussion can be found in the same repo. This implementation is "unofficial" (reverse-engineered) and quite slow compared to the real thing, but it has a substantial portion of the functionality and is quite usable for writing meaningful programs.
For example, the column formatter from http://t3x.org/klong/klong-intro.txt.html:
(-|/{#$x}'x)$x
It is pronounced (Negate Max-Over (Size [of] Format [of] x)-Each x) Format2 x
Of course, doing this will not lead to instant enlightenment, but it really helped me understand K.
The example from Wikipedia is a bit more challenging. What also complicates things here is that K overloads operators, so it may not be obvious, for instance, that ! means Modulo and not Rotate in that program. That's why I started developing Klong in the first place.
https://github.com/JohnEarnest/ok
I'll have a deeper look at Klong's implementation when I have time to see if there are tricks worth borrowing.
1) functions that take multiple arguments break the pattern of concatenating functions to build advanced expressions (yes, there is . but it's not nice to use)
2) the right to left evaluation means you constantly have to go back to the begin of the line to append functions
Both of these problems go away if you make it a stack based language with postfix notation.
* - I love the notation in J/K/APL but really want to see it written left to right, much like chaining together map/reduce/filter methods in Ruby with dot notation. I also want auto-vivification from Perl and the use of implicit variables for map/reduce/filter.
I look forward to messing with Klong.
It combines all the readability of K with... all the readability of Forth.
It's at https://github.com/alpha123/vio if you're interested, but very much WIP. The VM is rather simple if you feel like poking around.
Other notable features would be built-in parser combinators (with an unreadable postfix regex-like syntax). Concatenative parser combinators are pleasantly surprising to use.
I'm interested in the idea, but without anything to go on it's pretty impossible to look at.
Something of a README is now up.
[home] http://lang5.sourceforge.net/tiki-index.php
[examples] http://lang5.sourceforge.net/tiki-index.php?page=About
As I understand it, the original K is closed-source and no one has really used it. All the derivative languages were reverse-engineered from programs and descriptions, and it spun into it's own family of APL-like languages. As far as I know, at least.