6 ms·
K/simple: a tiny K interpreter for educational purposes by Arthur Whitney
- 1vuio0pswjnm7 3y agoHere's the code https://raw.githubusercontent.com/kparc/ksimple/main/a.c https://raw.githubusercontent.com/kparc/ksimple/main/a.c https://raw.githubusercontent.com/kparc/ksimple/main/a.h https://raw.githubusercontent.com/kparc/ksimple/main/a.h
- skruger 3y agoFor people discovering k for the first time, I wrote https://xpqz.github.io/kbook https://xpqz.github.io/kbook as a gentle intro.
- graemep 3y agoI am interested, but one thing I have still not quite understood is where to use this family of languages. As far as I can tell they are best for data analysis but not for heavy numerical computation because most or all of them lack GPU support. is that right or have I got it wrong? Are there any other use cases?
- scrawl 3y agoq/kdb+ is used in finance (banking + funds) for heavy numerical computation every day. high-volume realtime data straight from markets, and petabyte/trillion-row historical DBs. it runs on CPU but computation easily parallelizes over cores/clusters. regarding use cases, see https://kx.com/resources/use-cases/ https://kx.com/resources/use-cases/
- graemep 3y agoThanks, that gives me better feel for it. Mostly analytics, good with large datasets, but probably not great for things where you get a big gain from GPU?
- scrawl 3y agowhat tasks are you thinking? i'm not a gpu expert q is good with bulk operations on compact arrays; these are cache-friendly and the interpreter can utilize cache-level parallelism. and with q it's convenient to go from idea -> MVP in short time. it's a high-level language with functional features so expressing algos and complex logic is natural. but it's interpreted and optimized for array ops. so really latency-critical (e.g. high-freq trading) or highly scalar logic will be done with C++. the trade-off is convenience of development.
- cachvico 3y agoHedge funds use ML
- horsellama 3y agoarray languages are very fascinating and I'd love spending more time learning about them I read that they are (K in particular) used in finance...would you reckon it would be easier to find job in that field having that in the CV? I know I cannot compete on the C++/Python side but maybe as a skilled K developer I could sneak in
- deleted 3y ago[deleted]
- up2isomorphism 3y agoMy god, AW is even willing to #include <stdio.h> now!
- sxp 3y agoI was surprised at how verbose and commented the code was. Then I read the note saying that Whitney's original code was in `ref/` and the two files in the root were annotated by other kparc members.
- eatonphil 3y agoAh, thank you for clarifying this. I was confused why it said "by Arthur Whitney" when the contributors do not seem to be Arthur Whitney.
- kelas 3y ago"contributors" is essentially me. what needs to be clarified? it is by arthur whitney. anything else?
- Keyframe 3y agoWhitney is an unrealized IOCCC champion.
- kelas 3y ago> Whitney is an unrealized IOCCC champion. no, that'd be fabrice bellard, who is actually a "realized" ioccc champ. atw doesn't do obfuscated c. you are led astray.
- huhtenberg 3y ago> atw doesn't do obfuscated c. He writes as most of us code-golf. Makes you wonder how good his golfing would be if he tries.
- Keyframe 3y agoYou know it's in jest, of course. However, he doesn't write C either - and you know that better than us. It's a DSL with its own idioms and quirks that just happens to be in C. Often hearing about "evils" of preprocessor (which I do and don't agree with) I wonder if he ever considered anything else, aside from C, that's also low level. Heck, even asm can be macro'd away.
- max_ 3y agoWhat do they mean by "atw-style" ?
- tromp 3y agoI'm guessing it's his initials; Arthur T. Whitney or perhaps ArThur Whitney, and possibly his account name.
- 5jt 3y agoWhitney and I both worked in the 1970s for I.P. Sharp Associates, which used an email system written beautifully in APL by Leslie Goldsmith. Most user names were simply our initials. Ian Sharp was IPS, Leslie LHG, and Arthur ATW. (Middle name Taylor.) I’ve been SJT ever since (including to two wives) but was not smart enough to grab the domain: see 5jt.com.
- nuclearnice3 3y agoSounds right. Additional examples at https://github.com/louyx/aplus/blob/master/src/a/k.h https://github.com/louyx/aplus/blob/master/src/a/k.h https://code.jsoftware.com/wiki/Essays/Incunabulum https://code.jsoftware.com/wiki/Essays/Incunabulum How would you characterize that? Heavy use of the C preprocessor and C defaults to embed a functional programming language. Language with a small number of core functions and ability to apply functions to lists of atoms. Aesthetically favoring short identifiers and minimal whitespace to create high semantic density. Eschew comments.
- gipp 3y agoYou know how when you first start learning to code, the kids who really "get it" right away start off thinking shorter code = smarter code = better code? k always seemed like a bunch of those kids managed to become highly accomplished and brilliant engineers without ever breaking that terrible habit. Is there actually a reason to write these array languages (and interpreters for them, apparently) this way, or is it just a cultural difference?
- 3y ago
- deleted 3y ago[deleted]
- nimchimpsky 3y ago[dead]
- gavinray 3y ago[flagged]
- kelas 3y agoyou must have seen a lot of code.
- anonzzzies 3y agoYour code better? What metric?
- itishappy 3y agoHa! The guy who wrote this is the same guy who invented ~~APL~~ a number of APL inspired languages (Edit: He did not invent APL. Thanks for the corrections!), so I suspect he may just be built different. https://www.jsoftware.com/ioj/iojATW.htm https://www.jsoftware.com/ioj/iojATW.htm Have you seen anything written in K itself? Here's a program to calculate primes: 2_&{&/x!/:2_!x}'!R
- microtherion 3y agoAPL was invented by Kenneth Iverson, the other person mentioned on the page, not Arthur Whitney. I was not convinced of the readability of APL, but compared to its successors which tried to stick to ASCII, I've learned to appreciate the merits of an extended character set.
- jhbadger 3y agoI'm sure ATW knows a lot of APL, but APL itself was created by Ken Iverson when ATW was just a small child. https://en.wikipedia.org/wiki/Kenneth_E._Iverson https://en.wikipedia.org/wiki/Kenneth_E._Iverson
- anthk 3y agoA program written in Unix dc(1) would look as weird as that.
- up2isomorphism 3y agoMight not, since for this kind of thing most likely either you give up in couple minutes (which it is not a heinous since it does not waste your time anyway) or you just read it.
- vessenes 3y agoI have a longstanding fascination with K and other "modern" APL derivatives. There are a few intersecting truisms about coding that I believe: one is that people's working memory varies: some have an immense amount, some less. Humans definitely process spatially better than in time series (e.g. comparing side by side rather than turning over a page.) This implies you should prefer succinct code and languages because they are less memory load for engineers working on them. At the same time, a corollary is that a smaller standard library / language is generally better, in that less needs to be learned by an engineer for full coverage of the language. Another truism is that some people's processing speed is higher than others, and in general I think of the combination of working memory + speed as roughly equivalent to "g", general intelligence. K occupies this weirdo place though, because it's absolutely succinct, a very small language as counted by number of atoms supported by the interpreter, and also incredibly hard to scan. One of the K intros I read mentioned that the language is designed to be something that takes down your thinking; essentially the idea is that the workflow is "drink coffee with fellow PhDs, annotate on the chalkboard, and then when ready, capture it directly." This seems about right to me with my own K/J/Q experiences -- the bulk of the time is spent thinking about structuring a problem solution. I compare this to go, a language I love for its long-term readability and maintainability, where I spend a lot of time writing boilerplate and dealing with errors in-situ. At any rate, somehow there's a sort of event horizon of terse solution making where you come out the other side and need a 170 IQ to feel comfortable, and Mr. Whitney lives where he lives, and I live where I live. :) People complaining about how ugly the C code is here are definitely missing the point: he has bent C's preprocessor to his will in order to encapsulate how he thinks about coding: essentially functional, vectorized. It's using C to write a DSL for solving programming problems interesting to Arthur Whitney. I think it's fascinating on those terms. In a world where you have to read 10,000 lines of code from 100 developers, the C is terrible, and hard to parse. In a world where you will mostly write code to a style you've honed over 40+ years, it's super expressive, minimal, pared down to what matters, and probably fits his brain perfectly.
- ParetoOptimal 3y agoFor me Haskell, point free functions, and lenses are a happy medium :)
- p0w3n3d 3y agoI believe that all one letter names for a language are already taken... Even Ć
- p0w3n3d 3y agoI've just learned that Ć is no longer a viable name (thankfully). Now it's Fusion Programming Language (or fut?) https://github.com/fusionlanguage/fut https://github.com/fusionlanguage/fut
- yard2010 3y agoThis looks like a cult I would happily dive into. Does anyone care to ELI5? I tried to read the code but did not understand a single line
- eismcc 3y agoArthur Whitney is showing how to build an array language using C in array language form. AW is known for kdb+ which is often used in finance due to its extreme performance properties and ability for quants to quickly explore ideas. Personally, to get a better handle on how array languages worked, I implemented KlongPy which is a python implementation of Klong, which descends from K (which AW wrote). You have to play with this stuff to understand it intuitively.
- bwanab 3y agoHa! For those of us who were in the Morgan Stanley Fixed Income group for many years in the 1990s and 2000s AW is known for APLus which was used extensively for modeling and application work.
- CraigRo 3y agoThere were a lot of different and kind of weird attempts at this in the industry. The basic problem is that recalculating DAGs and monte-carlo simulations using a ton of floating point math was extremely expensive. Excel was way too slow, C++ required expert programmers and much better organization of programming teams to figure how to coordinate cached intermediate values. MS went with APL, which reduced a lot of the boilerplate and allowed for relatively easy memoization. GS went with SecDB which treated computation as memoized DAGs. Not sure what the others did
- sudosysgen 3y agoFWIW, kdb+ is not that extremely performant - there's a lot of things that could be faster, and a lot of limitations that mean that you often would be better of not using a DB at all (or to use another DB and just pull everything you might need into memory). There is/was a tradeoff in that many things that would make it faster would require more code, and a cool thing about q/kdb+ is that it takes so little code you don't have I$ issues, but I think that's a tradeoff that doesn't make as much sense anymore in 2023. What it's really great for is that it's really neatly integrated into the q language, which is great for exploratory programming, and it's fast enough not to get in the way.
- biosed 3y agoI recall a chap called Geocar demoing kOS, in a very impressive fashion. (I additionally recall an individual had to awkwardly hold the mic for the whole presentation) Did anything ever come of kOS?
- chrispsn 3y agoEverything I've found that's public is documented here: https://gist.github.com/chrispsn/da00835bb122c42f429a084df83fd746 https://gist.github.com/chrispsn/da00835bb122c42f429a084df83... The kparc.com links are down though.
- aquestion 3y agoThe K language seems to be limited to CPU only. Yes, it can call out to GPU (https://code.kx.com/q/interfaces/gpus/ https://code.kx.com/q/interfaces/gpus/) but K only runs on the CPU. This strikes me as odd for an array language.
- eismcc 3y agoshakti has GPU support now, i believe.
- cianigga 3y ago[dead]
- fredrickhumphre 3y ago[flagged]
- geph2021 3y agoAnyone know what is happening, or happened, with shakti db[1]? It's been years since Arthur started this other k-variant. 1- https://shakti.com/ https://shakti.com/
- vessenes 3y agoIt's around, and they recently stopped providing free download links for recent versions, from which I take it that they have a reasonable enterprise sales program rolling now. The feature split on the free / enterprise edition holds a lot back; my vibe on the free version was it was just enough to validate that shakti is performant, and then they want you to pay.
- nilamo 3y agoI started with the header file. It was a gentle warning of the madness in "a.c". At least it's well commented.
- userbinator 3y agoJ, the predecessor to K, also by the same author, is written in nearly the same style, but shorter: https://www.jsoftware.com/ioj/iojATW.htm https://www.jsoftware.com/ioj/iojATW.htm (Discussed previously: https://news.ycombinator.com/item?id=25902615 https://news.ycombinator.com/item?id=25902615 ) There's something very satisfying about how this style seems to "climb the abstraction ladder" very quickly, but all of those abstractions he creates are not wasted and immediately put to use. I think much of the amazement and beauty is that there isn't much code at all, and yet it does so much. It's the complete opposite of the bloated, lazy, lowest-common-denominator trend that's been spreading in many other languages's communities.
- mhuffman 3y agoWhitney seems to have an obsession, and a real knack, for writing or rewriting array languages.