4 ms·
That's two glaring flaws. You may want to try J, which only has one glaring flaw.
by murbard2 11y ago
That's two glaring flaws. You may want to try J, which only has one glaring flaw.
- yummyfajitas 11y agoOr numpy, which from what I can tell is basically a readable version of J. As a concrete example, I've gotten partway through translating the APL examples in "Notation as a Tool of Thought" (http://www.jsoftware.com/papers/tot.htm http://www.jsoftware.com/papers/tot.htm) into numpy, and they work pretty much unchanged. If anyone knows APL/J/K well, and could show some programs where idiomatic APL/J/K does not directly translate into idiomatic numpy, I'd love to see them.
- murbard2 11y agoThey have vectorization in common, but the commonalities really stop there.
- yummyfajitas 11y agoCan you suggest a simple program for which idiomatic J differs significantly from idiomatic python/numpy? As I said, I've been unable to come up with one, or find one in aforementioned paper.
- murbard2 11y agoSure, this is how you compute Hofstader's Q sequence in J Q=: 1:`(+&$:/@:- $:@-& 1 2)@.(>&2)"0 M. http://rosettacode.org/wiki/Hofstadter_Q_sequence#J http://rosettacode.org/wiki/Hofstadter_Q_sequence#J
- Avshalom 11y agoI cant speak for J but this is the first APL program I ever wrote (it's in Dyalog) it take a wolfram code on it's right and an array of 1s and 0s on the left and returns the next generation for that one dimensional automaton (it treats the world as wrapping but it would be easy to clamp the sides to 1 or 0): ODAT ← {(⊂[1] ¯1 0 1 ⌽ (3,⍴⍵)⍴⍵) ∊ ((8 ⍴ 2) ⊤ ⍺) / ⊂[1] 2 2 2 ⊤ ⌽ 0,⍳7 } as a traditional function with comments and stuff its: NG←R ODAT S;N;P;PS ⍝ First construct the eight *P*ossible states: ⍝ Creates an array 7 6 5 4 3 2 1 0 (⌽0,⍳7) and converts to binary (2 2 2⊤) ⍝ 1 1 1 1 0 0 0 0 ⍝ 1 1 0 0 1 1 0 0 ⍝ 1 0 1 0 1 0 1 0 ⍝ Then encloses along vertical axis (⊂[1]) P←⊂[1]2 2 2⊤⌽0,⍳7 ⍝ Convert the *R*ule from wolfram number to binary ((8⍴2)⊤R) ⍝ 110 becomes 0 1 1 0 1 1 1 0 ⍝ Then choose *P*ropogating *S*tates (/P) PS←((8⍴2)⊤R)/P ⍝ Take *S*tate and triplicates ((3,⍴S)⍴S) and rotates (¯1 0 1⌽) to create a matrix ⍝ each colume is a cell and it's *N*eighbors ⍝ A state 1 0 1 1 0 0 becomes: ⍝ 0 1 1 0 0 1 ⍝ 1 0 1 1 0 0 ⍝ 0 1 1 0 1 0 ⍝ Then encloses vertically again N←⊂[1]¯1 0 1⌽(3,⍴S)⍴S ⍝ Now we have two arrays: ⍝ *N* which is the current generation of state/neighbor triplets ⍝ *PS* which is the triplets that produce a live cell in the *N*ext *G*eneration. ⍝ we create a new array by testing for membership (∊) of current generation ⍝ and *P*ropogating *S*tates NG ← N∊PS Some of that might be idiomatic python but the thing is I didn't write it as the multi-line function. I wrote it by modifying the one line function. Which I did because that's how APL's data-flowy syntax/semantics encourages you write things and doing that in one line sure as hell isn't idiomatic python. The determined programmer can write any language in any language. It's what we write when we aren't being determined fortran/smalltalk/whatever programmers that speaks to the difference in programming languages.
- vezzy-fnord 11y agoYMMV, but I find the readability of J and K to be far worse precisely because of the ASCII charset instead of the glyphs. The APL glyphs give me a concrete context switching mechanism that I'm operating within its "alphabet" and the semantics thereof. Whereas because I associate ASCII characters with plenty of other meanings already, I find J and K to look like complete line noise in comparison.
- joe_the_user 11y agoIt seems like translating J or K to a glyph format for reading would be a relatively simple matter.
- murbard2 11y agoWould have to be a one to many relationship. Part of the problem with K is that the meaning of an operator depends on the type of the operands. "?" can be "generate a random number" or "search for an element in a list" for instance. And yes, that is insane.
- joe_the_user 11y agoWell, a parsing display system still sounds like a reasonably simple piece of software. Still, while I met J author Roger Hui years ago in college, I've never run a line of J so I probably would be the one to create such a system.
- zaphar 11y agoIf we are being precise then It's two symptoms of the same flaw.