bshimmin 10 years ago

Several times, over the years, when I've looked at a new and challenging (to me, in both cases) programming language I've thought, "If I put a day or two of effort in, I'm sure I'd eventually be able to make sense of this." The few times I've actually tried this, eg. with Haskell, I've been proven correct.

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!

  • RodgerTheGreat 10 years ago

    I've taught myself Forth and K. Each time, it was like going back to the beginning of learning to program. Familiar algorithms are hard to implement. Subtle typos and confusion abound. It takes time to learn how to break down the syntax of the language and read the code fluently.

    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...

  • philipov 10 years ago

    I expect that learning to read (and write) K is a lot like learning regular expressions. I don't know K, but regular expressions are eminently useful in everyday life, so I've had the experience of learning to casually read and write them.

    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.

  • avmich 10 years ago

    I had the opposite experience with learning J. After a couple of days meditating about concept of rank (here is the most relevant part of the excellent book - http://www.jsoftware.com/help/jforc/declarations.htm#_Toc191...) it went much easier. On the other hand, with Haskell I can even write monads myself now, but I hardly see their usefulness yet.

  • minikomi 10 years ago

    I recently started coming to grips little by little with J. The best way I found was doing /r/dailyprogrammer "easy" problems.

    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.

  • losvedir 10 years ago

    Heh, I'm in a similar boat to you. I actually tweeted the other day[0]: "Ah, APL/J/K. Time for my annual crisis of thinking everything I've ever learned about programming is wrong...". It's so interesting to me that some people claim fantastic productivity with it, while others find it completely impenetrable. I've spent maybe a day or two trying to get over the initial learning curve, but have never made significant progress.

    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

  • nils-m-holm 10 years ago

    One thing that really helped me in the beginning was to pronounce K programs properly, i.e. know what the operators are called and read programs to myself. Incidentally that also was the way I approached math in the beginning.

    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.

  • bshimmin 10 years ago

    Thanks to everyone for the great responses (and apologies for hijacking the comments a little here, which should have been about Klong) - much to delve into!

RodgerTheGreat 10 years ago

Very cool! I wrote (and am working on) a K interpreter in JavaScript called "oK". Might be useful to compare notes:

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.

murbard2 10 years ago

Two disappointments I have with K/Q is that

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.

  • jboggan 10 years ago

    I've been thinking about this a lot myself, these are my main problems with them as well. I've starting messing around with an unholy abomination that is taking the worst features of Ruby, Perl, and J* and making such a postfix language. I'm taking the rest of the year off to work on this so hopefully it yields something fun and stupid.

    * - 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.

    • PeCaN 10 years ago

      What is it with J/Perl hybrids? My own inspirations for Vio[1] are J, Perl, and Factor. It's about as unreadable as you might expect. It borrows more from Perl's text processing capabilities than things like auto-vivification or implicit variables (well, all its variables are implicit, since it's a purely tacit/concatenative stack language).

      1: https://github.com/alpha123/vio

  • PeCaN 10 years ago

    Coincidentally, a stack-based concatenative array language is exactly what I'm working on right now.

    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.

    • chc4 10 years ago

      It's be great if you had some examples to read through, or any documentation really. Even a minimal README.

      I'm interested in the idea, but without anything to go on it's pretty impossible to look at.

      • PeCaN 10 years ago

        Yeah sorry, it's a week old and I pushed it to GitHub just so I could link to something in that comment ;)

        Something of a README is now up.

scottlocklin 10 years ago

People who want to learn a useful and (more) easy to read K relative might have a look at Kerf. It has the columnar database baked in. http://www.getkerf.com

chc4 10 years ago

A great article about K is http://archive.vector.org.uk/art10501320 - it introduces K as a magical, end-all programming language that is blazingly fast and would solve lots of problems...if only someone other than the author understood it.

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.