4 ms·
The APL module is in the `lib` directory of the repo holding the code, you can see the implementation there. It wouldn't be that bad to pull all the library co
by semanticist 6y ago
The APL module is in the `lib` directory of the repo holding the code, you can see the implementation there.
It wouldn't be that bad to pull all the library code out into the 'main' command, but it would lose the 'single statement' impact and probably be harder for people to follow along with.
- kragen 6y agoAha, I thought maybe it was an existing gem. Anyway, I think it probably should lose the "single statement" impact, because in that context it's just misdirection, magician's patter. Yes, a single Ruby statement can invoke an arbitrarily complex piece of library code written for the article, but that doesn't tell you anything interesting about either Ruby or how to use it — the same is true of any programming language that supports programs in multiple modules, even assembly language: start: CALLQ play_life Now, the particular statement in question is considerably more illuminating than that, but presumably if you wanted to do almost anything else in an APLish style in Ruby, you'd probably have to implement more operations in apl.rb. I see that it doesn't include, for example, scan, slicing, or any broadcasting operations other than +, &, and |. (*, -, and / are missing, for example.) I mean, I've certainly written worse implementations of APLish operations. You could certainly extend apl.rb into something practically useful. I just don't think it's fair to put four pages of code in one file and then direct people's attention to the single statement in another file that invokes it.
- tinco 6y agoThat "ofcourse" you can implement Game of Life in one statement if you implement (parts of) the standard library of APL is not obvious to many people. The point of the blog is to introduce people to the concepts of APL, not to pitch some innovation. As a Ruby programmer who already knew about APL, I thought the title exactly matched the article. I was pleasantly surprised at how clean he designed the apl library, and the nice explanations.
- kragen 6y agoOh, I guess that's true. I remember when I was a kid I didn't have any idea how the BASIC interpreter worked either, and I didn't have any idea about how to build a tower of abstractions. So surely there are Ruby programmers who hadn't thought of trying to implement APL primitives in Ruby (especially if they haven't seen NArray.) Still, Ruby is pretty big on building embedded DSLs, so I'd think novice programmers learning Ruby would encounter that idea pretty early on. But there's always today's lucky ten thousand! I hope I didn't make any of them feel condescended to. Welcome to the wonderful world of implicitly parallel vector operations!