I read the Klong book [0] and for me it "clicked" in a way that J/K never had. The author did a really nice job paring down the language and cleaning up some of the ambiguities in a way that made it approachable. Also, after reading it I've found APL and J more approachable, which is encouraging.
If you'll forgive the style, I took a swing at implementing k-means clustering in Klong a few months ago [1]. While I did find a few slow-downs with a modestly sized data set (Fisher's iris data), I think Klong is built on a Forth-like VM using the core of a scheme implementation (all of which the author wrote!). It wasn't slow enough to really bother me, as I was more interested in learning about array languages and algorithms.
I’ve been using Q (built on K) for Advent of Code. It’s an amazing language that has made me reconsider what a language and programming should be. I come from a FP background and have always considered abstraction the heart of powerful and expressive programming.
In Q, abstraction is wholly unnecessary. Libraries are unnecessary. I can fit the entire language in my head and all code in the language is built out of the fundamental building blocks of it. There’s no layer after layer of abstraction, just a small base of operators and functions.
One might be tempted to compare it to other small languages, like Scheme. But for Scheme it’s intended that you build higher and higher levels of abstractions. With Q it’s both small and compact, and one rarely if ever feels the need to actually build a library of utility functions or anything really: it renders unnecessary the false prophet of code reuse.
I got interested in Q because some of my friends at other financial institutions were using it for HFT and research on historical tick data. I found it surprising at the time I that their software stacks could be so simple, essentially just a single small executable that entirely fit in the CPU cache that managed both the runtime and their entire database. At the time I thought this was impossible, but now I realize how possible and eminently reasonable this was. Instead of Kafka and Redis and SQL Dbs and Kubernetes and god knows what else, you just have Q. No DevOps bullshit, no containers, no complex shit to manage.
In the past 3 weeks I’ve had to rethink my philosophy of what software needs to be and have concluded that most of us are doing things very very wrong: we’ve created this unnecessary world of complexity that is tantamount to masturbation.
Now let’s talk about the language itself. It may look complex, but it’s actually quite simple. The only real data types are lists, dictionaries, symbols, and numbers. And surprisingly, that’s enough. When programming in it I have no desire for classes or objects or trees or whatever, in fact, just using lists and dictionaries can usually solve the problem in a better way.
Also, while Q is interpreted, it’s so goddamn fast. I’ve done some benchmarks against C and Q is about as fast, sometimes even faster. The optimizations the interpreter does are just insane. Not even joking, a single line of Q can accomplish somewhere between 100 to 1000 lines of what the equivalent C code would look like.
Another plus is that editor tooling is unnecessary, I have no need for autocomplete or inline docs because I can literally remember the entire thing. And since Q is so compact, I can view an entire program on a single screen, no scrolling, no jumping between files.
I’ve also noticed that I can remember the verbatim definition of my code. I can almost perfectly remember my exact code for each Advent of Code solution.
Anyways, good luck on Klong, I’m going to check it out. I don’t like J and wish there was a good open source K/Q like language. I don’t actually like K because the overloads on function arity creates a lot of complexity (Q does away with this), so Klong might be right up my alley!
For anyone who hasn’t tried an array based language, I highly recommend it. Q has expanded my mind more than I thought possible at this point in my career. My last really mind expanded experience in programming was when I picked up Scheme and Haskell in high school. And now after using Q, those languages aren’t that great anyways!
> Instead of Kafka and Redis and SQL Dbs and Kubernetes and god knows what else, you just have Q. No DevOps bullshit, no containers, no complex shit to manage.
What if you need to scale beyond what one machine can handle? Or if you need redundancy and failover? Transactional guarantees? Or need to talk to external systems?
Its easy to build a single-executable no-DB no-container no-devops application in most languages if you don’t care about the finer details of building a high scale resilient system that can survive a machine going down or has to talk to third party external systems.
IPC is pretty easy in Q. I'm not saying you could be at Google scale with one machine, I'm just saying you could get rid of your entire stack and just use a bunch of networked machines running Q. Though, for maybe the majority of businesses, a single beefy server running Q would be sufficient. The performance of the language and integrated database is pretty exceptional.
k is incredibly good for distributed computing. It's not as difficult as you're thinking: Arthur started out (as far as languages he published: he implemented a few before) with A and A+ at Morgan Stanley, and Morgan Stanley up until a few years ago actively used both. Distribution was inherent in k from the outset.
Also, your comment on "noDB" is unfounded. k and q are exclusively distributed with kdb+, which is probably the fastest SQL database on the planet.
Interesting experience report. I've seen some comments on hn on people starting out like you do, but realizing after a year that they need to work really hard to pickup old code. Do you imagine to have an easy time picking up your advent of code programs next December?
Another question - are there debuggers for these languages? Can you set breakpoints?
How do you interact with the www? Can you get some soap/json data and write a simple web service (even just a json endpoint)?
Or do you mostly see it useful to export data in some tsv/csv format, filter it through k, and write it back out?
Interesting experience report. I've seen some comments on hn on people starting out like you do, but realizing after a year that they need to work really hard to pickup old code. Do you imagine to have an easy time picking up your advent of code programs next December?
If you don't understand something in k or APL after writing it, you probably wrote it wrong to begin with.
A cool example of how much APL lends itself to this is co-dfns, which the author rewrote multiple times:
In particular, the desire to make the code as "disposable" as possible has lead to me using strictly combinatory/points-free style programming in the core compiler. It makes it very easy to change things because it's easy to see the whole picture and easier for me to delete any given piece of code. Many "fixes" in my code are single character APL fixes, or maybe two character APL fixes.
This whole discussion got started because of the amount of change that has happened with this code base (hundreds of thousands of lines). You can read more about that in the other historical threads referenced by dang. I've rewritten the compiler at least five times.
>Do you imagine to have an easy time picking up your advent of code programs next December?
Without comoments, it might be a little tough. I've gotten into the habit of commenting each line.
>Another question - are there debuggers for these languages? Can you set breakpoints?
There's an integrated debugger that supports breakpoints. I really haven't used it at all since the REPL works quite well, but I could imagine it being useful in production. Especially since you can debug and fix your program while it's running.
>How do you interact with the www? Can you get some soap/json data and write a simple web service (even just a json endpoint)?
There's included functions for parsing and generating html and json. I haven't used them though.
>Or do you mostly see it useful to export data in some tsv/csv format, filter it through k, and write it back out?
I would imagine that live Q programs work by leveraging the real-time streaming functionality and just operating directly on the stream or in-memory database. For offline analysis the ability to load and store data in binary is probably useful. You can also read and write the entire working image in order to transfer state across machines or time.
J is really nice, though different than Q (more directly a dialect of APL than a derivative).
Though if you want an open source k, ngn/k was just released under the AGPL a few days ago.
I'd recommend starting with J, though, because there are a lot more resources for it, there's a mobile app for it (that's really nice), and it's the last thing Iverson worked on.
IIRC, Iverson commented somewhere that K's (Arthur's) practicality wins over APL/J's (Iverson's) purity in some places; specifically,
K/Q does scan/reduce from left to right, which is easier for most people to reason about and use, even though it makes "-/1 2 3 4 5" different from "1-2-3-4-5" and thus less "pure"/"consistent" in some sense.
J's trains and forks (and APL's simpler products) are much more confusing for people than K/Q's juxtaposition and projection.
Can't remember or find Iverson's comments now. He might have made more, or I might be misremembering/misattributing. But I agree with these and think K is a better start than J (though not sure between APL and K).
It’s not as easy to get information as other languages, but the mailing list is super helpful and all the questions I’ve asked have been replied to by paid Kx (the people that make Q) employees:
Not the person above, but I'd recommend learning APL first. Arthur Whitney (the author of k and q) got started programming by his father and Ken Iverson (the inventor of APL) being friends, and Iverson giving him live demos of APL. Iverson has a lot of amazing resources for learning J (APL's successor) and APL, and learning it will teach you how to be more productive in q, k, J, APL and more!
This is the arthurese micro APL implementation, which inspired the J implementation - although IIRC the design for J was already well on its way at the time (and indeed, Iverson did not consider J a new language, but rather an improved APL dialect, so you could say the design goes back to 1956...)
It likely also formed a draft for A/A+ which Arthur did at Morgan Stanley (open sourced at aplusdev.org, but unmaintained and rotting theese days) - which themselves led to the creation of K.
This is function that checks if the value given as first parameter x is a prime by running through the numbers 2 to square root of x and applying the function x modulus y, then it looks at the minimum of the resulting list and see if it is 1 or 0. If it is one then x is a prime.
Written in a language with c-style syntax it would be something like:
x -> min((2 .. sqrt(x)).map(y -> x % y)) == 1
Why is Klong simple?
Is it easier to implement, parse and interpretate?
Or is the syntax somehow simpler once you get used to it?
The former maybe; but it doesn't seem to be a part of the language's pitch.
The latter is surely in the eyes of the beholder. I find it counter-intuitive to have so many single character operators & ! : _ with uncommon meaning and precedence rules.
While you are using C-style syntax, you are also using "map", which comes pretty close to using vectors in Klong (or K or APL). However, there are many different mapping and folding operstors in array languages, and their combination is what makes these languages terse. For example,
,/:~
(Join Over Converging) flattens a list in Klong.
Klong is simple, because its syntax is very regular. In K, many symbols are overloaded, so their meaning can only be deduced when knowing the types of their operands. In Klong, the syntax is unambiguous. See http://t3x.org/klong/ambiguity.html
Regarding precedence rules: there are none. Everything evaluates from the right to the left (as in K or APL).
This is actually very standard syntax for array languages. Precedence rules may be uncommon, but extremely simple: right to left, that's all; and finding the meaning of each symbol just requires checking in a table. In your c-style example, you are actually using different precedence for each operation (is it (x -> ...) == 1 or x -> (... == 1)?), you have symbols like the dot which mean different things depending on context, a function of two arguments like % works totally different to another one (map), and so on.
The only reason you find the c-style version simpler is because that's what you are used to. But while you have been able to interpret the Klong expression with no experience at all, ask yourself if someone familiar with array languages (and only array languages) would be able to understand the c-style version in a few minutes without having to read an extensive tutorial.
I do not agree simplicity is in the eyes of the beholder. If a language can be totally specified by a few paragraphs and a table, it is simpler than a language that needs a long specification. However, this does not mean the simpler language is simpler to use. That, indeed, is a subjective matter.
> The only reason you find the c-style version simpler is because that's what you are used to.
Well, yes. But we're taught infix notation early (x+y), and function application quite early too (y=f(x) - and in combiation (also note short-hand eliding multiplication): f(x) = 2x + 1).
I still find array languages to be too dense for me - but I do understand that they are simple from a certain point of view.
Hm, I could see myself playing with it - but I'm not quite seeing how I'd fit it into my day job. I do occasionally work with some simple aggregation and filtering - but usually in an sql db - and barring embedding an array language, I'd have to fetch all the data into eg: klong first, then process. It's hard to imagine a scenario where that would make sense.
Otoh, I'm still considering working through advent of code - such domains should be well suited, I guess.
If you're writing business logic, I'm not sure how helpful array-based languages are. The code would look very similar to a normal language, but without the classes or methods or objects.
For advent of code, it really shines though. Read in some big chunk of data, do a bunch of matrix and list operations to get the answer.
Really like the introduction by the way, it reads better than most I've read on apl/k - with a suitable mix of motivation and explanation - and not too much "pride" (like, lisp pride, or apl pride, where authors cannot imagine any reason why other languages exist. Seems especially common when run-times are written in such a language; namely C...).
To be clear, a little language pride is always warranted :-)
Other than that, I find it a bit funny that the factorial function is singled out as an example of why naming (short) functions are redundant - seeing as how it's one of the first "complex" functions/operands thaught/named in mathematics, and heavily used to shorten notation for for example combinatorics (that is "n!").
But I think this just reflects on the (for me) somewhat alien culture of array languages - its not wrong, but it is different.
It is for APL and derived languages (APL, J, K, A, A+, Klong)
And .. well, if you want C or Java, use C or Java.
Quickly, which is higher precedence, "&" or ">" ? You may have memorized them, but many people get it wrong often enough. APL has a very simple and consistent rule: There is no precedence in an expression except paranthese, and you go right to left.
And it may seem to not help with onboarding if you skim, but if you take the time it clicks quickly for most people, especially if you consider that "right to left" is actually "left of right", e.g. (note, a|b is the maximum of a and b, not the bitwise or)
1 + 2 * 3 + 4 | 5
is read and understood as:
(1 + ...) applied to ((2 * ...) applied to ((3 + ...) applied to (4 | 5)))
But one argument K/APL functions need no parentheses, so you would have written it
f g h 4|5
But with "f", "g" and "h" inlined you get the original expression back.
It is different - but it is simple and consistent without any arbitrary precedence and associativity rules.
Also, it's not a new idea; APL predates every other programming language still in use except, perhaps, Fortran, Lisp and COBOL -- of which only Fortran uses operator precedence and associativity in the modern C/Algol sense. Lisp is also consistent (though with a different route than APL took). And I'm afraid to describe COBOL in fear that cthulu will rise.
Besides the discussion about the GDPR which is offtopic (and in my opinion it's not handy to be openly political if you want uptake of your product as it's not related to your product but it does taint it (as can be seen here); maybe in the 'about' or 'privacy' it would fit, but that is a matter of opinion), great work on Klong and I'll buy your book to read over xmas.
I have been playing (quite a lot; to the extend my wife got me a t-shirt with some k on it for my birthday :) with Shakti(k7) for a few months now and been working through the Dyalog tutorials.
At this point Python/Numpy is really the array processing language I prefer to use. You can even use libraries like Cupy to switch the backend from BLAS/LAPACK to Nvidia CUDA libraries, which makes it lightning fast, often improving performance by 100x. And the requirement for arcane runes in Numpy is much less than APL or J.
Also the various libraries and functionalities that plug into Numpy is countless and extremely powerful.
There's also https://futhark-lang.org/ which might be an improvement in writing array processing kernels.
APL (and I assume J) uses a large range of special graphic symbols as part of its syntax, which can be difficult to internalize for folks coming from other languages. It can be easily construed as mysterious or magical lettering (arcane rune). My favorite video to illustrate this is Conway's Game of Life written in APL: https://www.youtube.com/watch?v=a9xAKttWgP4
J and K stick to Ascii (though recent K seems to accept a unicode "sqrt" sign, and "pi" character with the expected meaning).
I do find some J choices questionable - e.g. '}' and '{' are used as individual operators, rather than a parenthetical pair - which confuses editors without a special J mode, and humans who switch between languages often - but if you use it enough, it's easy to get used to; Also, K keeps () {} and [] as parenthetical pairs, like they are in C/Java/Python etc
Found this disclaimer sad and reminiscent of the endless and useless cookie prompts in the EU
Note: This text used to be interactive, but is no longer, thanks to the General Data Protection Regulation (GDPR), which makes it virtually impossible for small, non-commercal sites to "process user data" (like your input) without contacting a lawyer first.
This is excessively sensitive and represents an opinion-driven interpretation of the law. It seems like a lame attempt to make an "edgy" political statement.
Well, it is an attack on the gdpr with the huge text on the top (you could just remove that and still be safe instead of sorry?) while your site, in it's previous state, does not need lawyers etc as it doesn't fail the gdpr. Especially as you can simply (if you want to be extra careful) not log IPs or any user input into the logs. Then there is nothing to 'sue' if that would be your worry.
Name calling is uncalled for, I agree. But you seem to reside in Germany; not sure what you are worried about anyway (you would get (but will never get because your previous site already complied fine, as do most sites that are not personal data farms) multiple warnings and you can simply respond to those as a person (no lawyer needed or warranted), but yes, ofcourse, you are entitled to your opinion. Anyone is as far as i'm concerned.
In Germany in particular there exists a nasty habit of sending C&D letters to people for all kinds of minor rule violations. You can either sign these letters and pay an (often substantial) fee or get a lawyer. Or you can try to comply in advance, often to a ridiculous degree, which I do.
So I may have such a strong opinion on the GDPR because I live in Germany.
> So I may have such a strong opinion on the GDPR because I live in Germany.
Those C&Ds are pretty insane: I heard about them before, what are they for? In NL we had, for a little bit, lawyers who searched out illegal photograph usage and tried those letters. But according to Dutch law, I can remove the picture (we had a large image site) and that's it. So they made $0 of us, not did the lawyers. Is it something similar?
In Germany, this used to be quite a lucrative business model for lawyers, and it was insane indeed! It got a little less profitable when the government put a cap on the fees, but I am afraid it it still a thing. Dutch law sounds much more reasonable!
My friend with a business there said that it is not too hard or expensive to get a lawyer to spend a few minutes sending a standard response and that they (almost always) back off with even the slightest resistance? Annoying but...
> Failure of interpretation, really: I can't see how any of that could be considered personal data.
Theoretically, you could enter some personal in a free-text field and it would be stored in the log files. I am not saying that people actually would do this, but they could. Now they cannot.
Do you have an email address, or telephone voicemail? If you could get in trouble with the GDPR simply by having the capability of receiving unsolicited personal data, these are legal liabilities, too.
Well, can you? You asked 'an expert'; since the introduction of the gdpr, there was an explosion of 'experts' (even real lawyers) who know absolutely nothing and just read the EU docs line for line to spread FUD (and get clients). And the problem is, that, while the gdpr is EU wide, there are governing bodies per country which all behave different. So your expert in Italy might be completely off the mark about the Netherlands (so, disclaimer, my experts are from the Netherlands and talk about NL).
But, in general, if you want to be 100% safe; just have a static site that collects nothing and logs nothing. No need to nag about it; it makes the internet a better place anyway imho.
In my experience, if you are not frivolously collecting user data and make sure that the personal data you do collect is something you can explain in the line of your business (even if that data is very secret data, but that usually has extra laws/rules on top). And, finally, that you make sure that data is properly stored (encrypted on properly updated servers), you have no issues.
In this case, IF the owner would get an email from the governing body of the country (I think Germany in his case), he would very easily be able to explain the reason for the input and the body can see that he is not asking nor frivolously collecting user identifiable data. If people choose to enter it, for some reason, en masse, in his site, then they would ask him to throw it away when it comes (so in his case, don't log it, but why was it being logged anyway?) in and that's it. No fines, no nothing.
I guess the difference is that GDPR is new and had a bunch of of reporting about it recently. Few people stop to consult a lawyer before starting a side-project, probably because they wouldn't start a project that would violate any laws they're aware of. Of course there can always be laws you aren't aware of, but those only become scary once you realize you may have violated them.
I think the author is overreacting, to be honest. What’s wrong with having client-side interactivity? There’s no possible way that would fall afoul of GDPR.
If you'll forgive the style, I took a swing at implementing k-means clustering in Klong a few months ago [1]. While I did find a few slow-downs with a modestly sized data set (Fisher's iris data), I think Klong is built on a Forth-like VM using the core of a scheme implementation (all of which the author wrote!). It wasn't slow enough to really bother me, as I was more interested in learning about array languages and algorithms.
I'm a fan of Klong -- it's just fun.
[0]: http://www.t3x.org/klong/book.html
[1]: https://idle.nprescott.com/2019/k-means-clustering-in-klong....