5 ms·
I'd like to be awed and amazed, but the frightening thought of encountering such a thing in production and under tight deadline kind of doesn't let me :) EDIT:
by klibertp 9y ago
I'd like to be awed and amazed, but the frightening thought of encountering such a thing in production and under tight deadline kind of doesn't let me :)
EDIT: I've edited the code a bit so that it doesn't look like PERL or J itself https://gist.github.com/piotrklibert/4d32c8cc6fcf20643a257a26bd17bcde https://gist.github.com/piotrklibert/4d32c8cc6fcf20643a257a2...
- mmjaa 9y agoI got as far as trying to build and run it, but bugged out, thusly: $ ./one-page-j warning: this program uses gets(), which is unsafe. Segmentation fault: 11 Ah well, its still cute to try to read and understand ..
- jpfr 9y agoThe code was written on paper. Without the usual compile/debug cycles during development. The amazing part is how little cleanup work is required to make the code work. It's an entire programming language after all!
- kuroguro 9y agoI got it to compile but what is it even supposed to do?
- klibertp 9y agoShould start a REPL. The `main` function looks like this: main(){ C s[99]; while(gets(s)) pr(ex(wd(s))); } which is a very direct expression of read-execute-print-loop.
- icen 9y agoIt's a tiny interpreter. You can create vectors, add them, concatenate them, store them to variables, count their lengths, and so on. An example session: x=~5 5 0 1 2 3 4 y=x,x 10 0 1 2 3 4 0 1 2 3 4 x+y 10 0 2 4 6 8 0 1 2 3 4 To understand the source, the key are the arrays `C vt[]`, `A(vd[])()`, and `A(vm[])()`, which maps the verb token to the dyads and monads respectively. `V1` functions are monads, `V2` are dyads.
- ksherlock 9y agoIt's not 64-bit clean. If you compile it as 32-bit it will run.
- atemerev 9y agoJ's commercially aligned cousin, K, is routinely encountered in financial/ trading backends. Part of job security, I presume. I know some K, but I am not a particular fan of it. I admire the efficiency, though.
- icen 9y agoA really helpful edit would be the V1 and V2 macro expansions; then it's fairly straightforward C with an odd naming scheme.
- klibertp 9y agoI don't think so. It's easier to see if something is monadic or dyadic with the macros, and you don't need to parse the function head to know what args and of what types it takes.
- cormacrelf 9y ago> monadic or dyadic Also known as unary and binary, TIL. They're arity, not FP monads.
- evincarofautumn 9y agoAdicity is an alternate naming scheme for arity, based on Greek rather than Latin roots.
- mjn 9y agoAlso a common naming scheme in music, which is where APL got the terms from: one note is a monad, two simultaneously is a dyad, three is a triad, four is a tetrad, etc. Fwiw APL's use of monad in this sense predates the FP use of the term by several decades.
- Xophmeister 9y agoMonads, in the FP sense, come from the same construction in Category Theory. According to Wikipedia, this was first "invented" in 1958, but the term "monad" was coined later by Saunders Mac Lane.
- zakk 9y agoYou could also run the preprocessor to make it clearer.