12 ms·
K: We need to talk about group
- nextaccountic 4y agoWhat is group?
- geoah 4y agoSome context would be really nice indeed.
- Jtsummers 4y agohttps://gist.github.com/chrispsn/3450fe6172a7cc441d0819379ed3a32a#a-history-of-group https://gist.github.com/chrispsn/3450fe6172a7cc441d0819379ed... <- Here you go, some context about what group is and does (or was and did, in this case) in the K language.
- deleted 4y ago[deleted]
- ape4 4y agoThe Linux /etc/group file was my first and incorrect thought.
- jpf0 4y agoGroup is (was) a function in various array languages, including K, APL, BQN, J, and Shakti.
- chrispsn 4y agoGood point - added a simple explanation in the article: Group tells you the places each element occurs in a list. It generates lists of indices.
- nextaccountic 4y agoNice! Sounds useful for scatter and gather algorithms https://en.wikipedia.org/wiki/Gather/scatter_(vector_addressing) https://en.wikipedia.org/wiki/Gather/scatter_(vector_address...
- gdprrrr 4y agoA group is a non-empty set and an operation that combines any two elements of the set to produce a third element of the set, in such a way that the operation is associative, an identity element exists and every element has an inverse. /s
- co_dh 4y agohttps://code.kx.com/q/ref/ https://code.kx.com/q/ref/
- co_dh 4y agoGroup is actually like inverse a mapping. Given an array A which map index to value, group A map value to index. A common idiom is: desc count each group A , which list most frequent element first
- Gys 4y agohttps://en.wikipedia.org/wiki/K_(programming_language) https://en.wikipedia.org/wiki/K_(programming_language)
- sergiotapia 4y agoThat has to be the tersest language I have ever seen in my life. Code golf but it's actually a real language used heavily in finance.
- dan-robertson 4y agoI think ‘used heavily’ is a bit of an overstatement. I think the right intuition for APL-family languages is that they mostly do numpy-like operations except their set of operations tend to compose very nicely. So the idea is that one can quickly and interactively figure out a composition of the operations which will do the calculation you want, but you don’t have a complicated compiler and spend most of your time in the operators rather than the interpreted language, and the operators tend to make the cpu happy – they work on contiguous memory, tend to be vectorized, don’t branch unpredictably, etc – so even if you have to compose many steps, you win on the time to write and the time to execute can be hard to beat because the constant factors of each individual operation are good. For obvious reasons, things like numpy, pandas, dplyr, etc are more popular as their syntax is a bit more readable and it is easier to get data in/out. I think they do lose a bit by not having lots of the useful compostable APL-style operators because those things don’t have comprehensible names.
- rippercushions 4y ago> compostable APL-style operators APL-style operators have been sent to the compost heap of history for a reason.
- dan-robertson 4y agoFold Scan Map Head/tail Index (with an array) The integers up to n Concatenate Flatten Most of the operators are already familiar but they tend to work well on multidimensional arrays and with each other due to broadcast semantics (and some axis selection features). In other languages you may see the magic broadcasting for some operations like addition but many of the functions only work on vectors.
- ldayley 4y agoFor context: This is regarding the function of "group" as it is implemented in the K array-oriented programming language (dialect of APL).
- KrugerDunnings 4y agois there any way i can try this out?
- maximus-decimus 4y agongn k : https://codeberg.org/ngn/k https://codeberg.org/ngn/k kona : https://github.com/kevinlawler/kona https://github.com/kevinlawler/kona alto a javascript implementation even with a graphics library : https://github.com/JohnEarnest/ok https://github.com/JohnEarnest/ok edit : assuming you were talking about k and not freq
- semi-extrinsic 4y agoAh, look at that ngn k link. They even golf the file names of the source code of the interpreter itself :D
- tluyben2 4y agoNot golf; that’s the norm. Makes things easier to fit a page without scrolling and looks/feels more like programming in k. https://code.jsoftware.com/wiki/Essays/Incunabulum https://code.jsoftware.com/wiki/Essays/Incunabulum
- yakubin 4y agoOMG: <https://codeberg.org/ngn/k/src/branch/master/a.c https://codeberg.org/ngn/k/src/branch/master/a.c> My maths notebook from high school looked like that. I'm having flashbacks. (At least in text files you can't cram 4 lines of text into 1.)
- eggy 4y agoOr you could try J. Another terse array language that uses ASCII symbols. https://www.jsoftware.com/#/ https://www.jsoftware.com/#/
- chrispsn 4y agoYep - added a link to some simple examples in the article (below). Throughout the article there are also a few links to executable versions of the code examples. https://ngn.codeberg.page/k/#eJxdjssKwjAQRffzFddVFyLFoiiFQD8lr0GFpCkJKSn48WKDi3hX9zEMp4xnXDDgjituRKIQlUkMh0LHvqsOP/VI2Z9YmSfm7DXHhEcMeWELvSFYixDBK89Ei1Mbx1Eq9zIsddDSqBjcf6ZkQuQGYW8mUR/Qu++a4gvhVakQ+9Iw1KMP3zFDVw== https://ngn.codeberg.page/k/#eJxdjssKwjAQRffzFddVFyLFoiiFQD8...
- pavlov 4y agoIt’s awe-inspiring to see a K program where the comments are in another APL variant (I can’t pretend to know which): {d:~1=':s:^x / s‿e←1⊸»⊸(>⋈<)' '=𝕩 c:^"aeiou"?_x@&d&~s / c←¬(s/𝕩)∊"aeiou" x,:,/$`pig`dog c / ins←⥊c⊏["pig","dog"] x@<(+\d),{3}#c+2*!#c} / ((+`s+e)∾3/c+2×↕≠c) ⍋⊸⊏ 𝕩∾ins This program implements a Pigdog Latin translator, bien sûr.
- warent 4y agothis looks like some compiled program's binary viewed as unicode WTF
- qsort 4y agoI... just can't. I work a lot with data, so it sounds like it should be a good fit for what I do, but I find that writing the damn code in a normal language is much more productive. Maybe it's my brain that's wired wrong, but I fail to see how the entire construction is supposed to help.
- mandevil 4y agoA friend worked on a project in 2005 that had lots of K code in production. They had a contract with Kx Systems and Arthur Whitney in particular because, in my friend's opinion, only Whitney could really understand K code well enough to debug it. Friend's description was it took my friend two days just to comment the code into something grokkable by a normal developer, whereas AW didn't need to do that. Of course, it took Whitney those same two days of staring at the code before he said "Oh, of course, how silly of me." and found the bug and all resolved. Part of those two days of commenting was that since K is interpreted all of the developers would hand-obfuscate all of the code so that the variables were a, b, c, etc. so that they would be slightly faster to parse than a multi-character string. This sort of thing is done all the time now, with JS to make it load faster, but his team at least didn't have any scripts to automatically turn developer-friendly code into interpreter-friendly code, they worked with the interpreter-friendly code version.
- twoodfin 4y ago
- idle_zealot 4y agoThese line-noise programming languages read like a cruel joke on engineers in the finance world.
- co_dh 4y agoI am happily programming in a for 6 years now, and will not give it up
- pwdisswordfishc 4y agoHappily programming in a what?
- CraigRo 4y agoMS has a 500+ person mailing list for peer help on kdb/q/whatever. They also have a site license, and herds of consultants from first derivatives. It is much easier to become good at k/q if you have experts sitting next to you. Learning this at home (or reading about it on hn) can be very frustrating!
- msla 4y agoImagine what APL could do with a Haskell-style type system and enforced referential transparency. APL programmers want to say their language is mathematical notation, well, make it mathematical notation.
- chrispsn 4y agoIn the Wordle dict example, it would have helped if a type system could tell me I was wrong when I assumed that an indexing miss would generate an empty list.
- anigbrowl 4y agoI like how clever the language is, but it seems only slightly less hostile than Brainfuck. Guess I'll stick with being slow but comprehensible.
- anyfoo 4y agoFrom the way I often use Haskell, Matlab, and even crazy shell one-lines with lots of pipes, awk, sort, and other stuff, I often have the impression that array languages are exactly what I'm looking for for certain problems. The question is... which array language should I pick? What are the reasons to pick one over the other?
- Avshalom 4y agoJ i guess. https://www.jsoftware.com/#/ https://www.jsoftware.com/#/ I don't really like J but the only serious APL left is the proprietary (though free, and fun) Dyalog; K, the official product, is also proprietary and because Arthur rewrites it every couple of years all the open source clones are of different versions so there isn't much of an ecosystem.
- anyfoo 4y agoHmm, so why J over Dyalog APL then?
- Avshalom 4y agoit's libre and gratis, if that's not something that bothers you (and to be sure if you're just writing code for your own edification it's not a practical problem) then i would recommend dyalog, although as a side effect of being open J has a (perhaps only slightly) larger free ecosystem and community. the down side is that subjectively some people (myself included) find J uglier, less effective as a tool of thought and due to some syntactic features (hooks and forks, but no proper lightweight anonymous function syntax)-prone to people posting impenetrably dense code as "examples"
- anyfoo 4y agoI see, thanks! Looks like I might try both. The "no proper lightweight anonymous function syntax" sounds weird to me, I would have thought that's paramount for an array language? Do I misunderstand?
- anonu 4y agoSo the summary of that long post: we still need group but Shakti/k9 gets rid of it because it's too slow forcing the user to diy it with other primitives as needed? I love it... It's the exact opposite of every other language design. Others: lets ship it with every tool a developer might ask for. K9: Occam's razor to everything. Nothing is safe.
- chrispsn 4y agoI think we need some kind of grouping function, but it doesn't have to be the 'generate group indices' function. I'm sure we'll have alternatives available such as `update ... by`.
- r9550684 4y agothere's a number of visionaries for lack of better term who have been following similar paths in their respective schools. chuck moore after FORTH got standardized went back to drawing board and made colorForth, where he reduced the number of available words to bare essential, very similar to how Arthur is rethinking and removing elements of apl in K, and then K in Shakti to what he sees as bare essentials. but you have less extreme cases, like Wirth developing pascal, then more capable modula, but then removing even arguable useful parts of modula in oberon, for being non-essential. I'm pretty sure there are other examples, but they like the examples I have given have small dedicated followings, rather than wide industry adoption, for reasons that wide industry adopted technologies tend to be all things for all people as a direct cause and effect of the wide adoption.
- natas 4y agoArthur will address this in k10 :)