[HN Gopher] K/simple: a tiny K interpreter for educational purpo...
___________________________________________________________________
K/simple: a tiny K interpreter for educational purposes by Arthur
Whitney
Author : todsacerdoti
Score : 121 points
Date : 2024-01-17 11:57 UTC (11 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| sxp wrote:
| I 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 wrote:
| Ah, 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 wrote:
| "contributors" is essentially me. what needs to be clarified?
|
| it is by arthur whitney.
|
| anything else?
| Keyframe wrote:
| Whitney is an unrealized IOCCC champion.
| kelas wrote:
| > 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 wrote:
| > 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 wrote:
| You 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.
| gaze wrote:
| I know you're joking but people who write C like him would
| argue it's not obfuscated. It's certainly not intentionally
| written to be more difficult to read, and those who are
| practiced in the art often say that it's _easier_ to read.
| dchest wrote:
| Pity that he writes in C; if he wrote in JavaScript, he
| wouldn't need a minifier.
| up2isomorphism wrote:
| Sorry, you didn't get him. He does not do it for the sake
| of making it harder to read, nor he would entertain
| language like Javascript.
| dchest wrote:
| it was a joke. i'm fascinated by his approach.
|
| shakti.com has a suspiciously familiar looking snippet of
| javascript
|
| was it him?
| max_ wrote:
| What do they mean by "atw-style" ?
| tromp wrote:
| I'm guessing it's his initials; Arthur T. Whitney or perhaps
| ArThur Whitney, and possibly his account name.
| nuclearnice3 wrote:
| Sounds right.
|
| Additional examples at
|
| https://github.com/louyx/aplus/blob/master/src/a/k.h
|
| 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 wrote:
| You 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?
| steveBK123 wrote:
| less code less bug
| tom_ wrote:
| An occasional HN poster did a presentation a few years
| ago about his compiler, written in a similar sort of
| style: https://news.ycombinator.com/item?id=13638086
| tosh wrote:
| Arthur Whitney
|
| https://en.wikipedia.org/wiki/Arthur_Whitney_(computer_scien...
|
| https://queue.acm.org/detail.cfm?id=1531242
|
| https://hn.algolia.com/?q=arthur+whitney
| gavinray wrote:
| This is some of the most heinous code I've ever seen.
| kelas wrote:
| you must have seen a lot of code.
| anonzzzies wrote:
| Your code better? What metric?
| itishappy wrote:
| Ha! 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
|
| Have you seen anything written in K itself? Here's a program to
| calculate primes: 2_&{&/x!/:2_!x}'!R
| microtherion wrote:
| APL 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 wrote:
| I'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
| up2isomorphism wrote:
| Might 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 wrote:
| I 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 wrote:
| For me Haskell, point free functions, and lenses are a happy
| medium :)
| zozbot234 wrote:
| I don't know about Golang but there are languages where this
| sort of highly domain-optimized, super terse syntax could be
| embedded as a domain-specific sublanguage, in a significantly
| less hackish way than what C allows.
| blibble wrote:
| my fascination with Q/kdb/K/... disappeared once I had to debug
| it in production
|
| you want a stack trace? tough luck, you'll get back:
|
| `type
|
| and that's it
| p0w3n3d wrote:
| I believe that all one letter names for a language are already
| taken... Even C
| yard2010 wrote:
| This 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 wrote:
| Arthur 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 wrote:
| Ha! 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.
| jhbadger wrote:
| Basically it is an APL-like language that is used (or was, I
| think it has moved on to a successor language called q now) in
| the proprietary kdb+ system used by some financial companies.
| Even if you aren't into finance it is a fun language to play
| around with.
|
| https://en.wikipedia.org/wiki/Kdb%2B
| gitonthescene wrote:
| One of us.. one of us..
|
| But seriously, if you haven't given it a try you should. You
| won't be disappointed.
| biosed wrote:
| I 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 wrote:
| Everything I've found that's public is documented here:
|
| https://gist.github.com/chrispsn/da00835bb122c42f429a084df83...
|
| The kparc.com links are down though.
| aquestion wrote:
| The K language seems to be limited to CPU only. Yes, it can call
| out to GPU (https://code.kx.com/q/interfaces/gpus/) but K only
| runs on the CPU. This strikes me as odd for an array language.
| eismcc wrote:
| shakti has GPU support now, i believe.
| geph2021 wrote:
| Anyone 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/
___________________________________________________________________
(page generated 2024-01-17 23:00 UTC)