K: War on Raze(gist.github.com) |
K: War on Raze(gist.github.com) |
This difference in array models is also part of the reason why Dyalog's ⍸ does a "deep where". In APL it's not considered "deep" at all, because the argument is a numeric array; it would be called "high rank". There's still a problem with this version though, because the high-rank version of ⍸ needs each index[1] to be a list, but the normal version (when the argument is 1-dimensional) uses one number for an index. The results of ⍸ for different rank arguments are actually inconsistent. In BQN, I decided Where should just be restricted to the 1-dimensional case. I wrote a little more about the kinds of array indices at [2]. It's worth noting that K has this problem a lot less than APL, because most of the time you will only index into a single dimension. But with constructs like deep where these problems appear in K as well, and you'll end up with the same inconsistency if you try to combine the two versions.
[0] https://mlochbaum.github.io/BQN/doc/search.html#higher-ranks (in the code examples, "high"≍"rank" couples rows to give the 2x4 shape seen below, and similarly 3‿2⥊4 creates a 3x2 array)
There's not much of a custom DSL problem, because APL/K emphasize using the primitives that are built in, and user-defined functions will have names not symbols. Some codebases will be a challenge to read because these languages tend to attract programmers who write things their own way, and for K in particular many users—the inventor Arthur Whitney most of all—don't like to write long explanations of how their code works. The OP, while well explained, is pretty advanced material. Knowing a lot about array programming makes the high-level picture clear but I would say many of the code examples would take some effort for even a good array programmer to understand.
If anything, K is the opposite of a language where everyone disappears into DSLs- you can write expressive code without wrapping it in custom abstractions. An anti-lisp, if you will. It's not uncommon for K programmers playing with a puzzle to independently arrive at character-for-character identical solutions.
Don't know DSL ability, though aware someone wrote expanders from symbols to words, - imagine DSL doable but forth, lisp macros spring to mind first in the DSL space
Yep. For this reason deep where ideally wouldn't live on '&'. It should be able to absorb any structure for subsequent use with deep indexing etc, regardless of rank. Perhaps another reason to make 'explode' an adverb...?
I wouldn't call it "common", but it's pretty well known.
kdb+/q devs certainly have good job security, heh.
The beauty of ngn k is I can compile it on NetBSD and with musl on Linux.
"ugh why can't this sort() just give me a grade instead?"
"why does this provide reduce(), but no scan?"
"this would be so much cleaner if I had transpose, or even just laminate..."
Would be curious to hear from someone's that's used both
The quote by Alan Perlis, 'It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures.' is also relevant to both lisp dialects and array languages.
I guess Clojure takes things a step further. It goes from "everything is a list" to something slightly broader with Vectors/Maps/Sets/etc. - all through language primitives. (the algorithmic layer is cleverly done through the sequence abstraction)
Coming from C++, in effect having your STL containers/algos baked into the language is a breath of fresh air :)