slightly verbose example but heres gnu apl as a pipe-like interface. Often this would be abstracted to a library that gets included when you call it:
printf "1,2,3,4\n5,6,7,8" | apl --eval "f←{4⎕CR ⍵}◊s←{⍺~⍨¨⍵⊂⍨1++\⍺⋸⍵}◊f ⊃{⍎⎕UCS ⍵}¨¨44 s¨10 s⊣⎕FIO[41] 0"
┏→━━━━━━┓
↓1 2 3 4┃
┃5 6 7 8┃
┗━━━━━━━┛
DESCRIPTION: --eval ≡ evaluate the text
f ≡ formatting function for printing nested values
s ≡ partition a line of text and remove the partition character
⎕FIO ≡ read stdin as byte stream (see FILE_IO.apl)
⎕UCS ≡ convert bytes to characters
⍎ ≡ execute an expression (convert characters to numbers)
SUMMARY: read stdin as a bytestream
partition at newlines and commas
convert to characters
interpret characters as numbers
disclose into a rank-2 array
format to stdoutYour description and summary blocks have started me wondering... has there been much work done on converting APL statements to more verbose explanations?
The sigil-to-meaning mapping is likely automatic for seasoned APL programmers but it might make such one liners more effective for evangelist purposes by making them somewhat more self-documenting.
I'm of the opinion that code should be documented. Short description, arguments, return, purpose etc. However rebinding primitives kindve defeats the purpose after a little familiarity. For example:
commute ← {⍵ ⍶ ⍺} ⍝ or commute ← { ⍺ ⍶⍨ ⍵ }
will get tedious quickly. Its better to lean into the terseness of the language, rather than attempt to transform it into something it isn't. There has been work done for easing the learning curve, for example https://aplcart.info/ . Keep in mind aplcart generally targets dyalog, however many of the idioms should work for alternate implementations with possibly some tweaking.
I've been looking for a good "diff" of the language differences between Dyalog APL and GNU APL, as much as to understand the extent of the progress since 'APL2' (or whatever the ISO standard name is considered equivalent to it) as any for any specific list of what GNU APL can't do relative to it's modern commercial compatriots.
(EDIT: Fixed final sentence to be a complete thought/sentence).
from example: f←{4⎕CR ⍵}◊s←{⍺~⍨¨⍵⊂⍨1++\⍺⋸⍵}◊f ⊃{⍎⎕UCS ⍵}¨¨44 s¨10 s⊣⎕FIO[41] 0
Mmmm... I code in C, Java, PHP, CaML, Prolog... for a long time... so I guess that I'm quite used to programming. But really: I can't make any sense of these hieroglyphs !!!! And NO user I ever worked with would either...
So I guess that I'll need a lot more sugar to taste APL...
APL has an initially steep learning curve, because it is so distinct historically from other languages. But it is a quite simple language once you learn it.
1. Every statement is executed right-to-left. Statements are executed top to bottom (or left to right with ◊ as a separator).
2. The only precedence rule is parentheses
3. Functions can be called with one operand (monadic) or two (dyadic)
4. Values in APL have a shape (dimensional size), a rank (number of dimensions), and a ravel (a list of elements). Values can contain other values (nesting)
{} define lambdas
⍺ is the left operand
⍵ is the right operand
⍶/⍹ are the left/right operators (higher-order functions)
← assignment
◊ statement separators
¨/\⌿⍀⍣⍤⍨ builtin higher order functions
After some familiarity it becomes as easy (or easier) to read as any other language. You can encode a remarkable conciseness of expression into each lambda, that you plumb together (similar to unix pipes in a way) in higher order patterns.EDIT: They also discuss how the upcoming convergence of .Net Framework and .Net Core is going to have a major impact on their cross-platform capabilities.
The scripting ability is quite good IMHO.
I suspect that's because it isn't the primary use-case of APL, much like trying to use MIT Scratch[1] to write one. Sure, they're all Turing-complete, but I/O and other interfacing varies greatly between different environments.
[1] https://en.wikipedia.org/wiki/Scratch_(programming_language)
Common Lisp can do the same, but it's a much bigger language so you see less of this effort and more standalone CL implementations like SBCL.
However, I also decided that it is still a bit too dead, at least for me. Specifically, it does not work well with other programs, at least on *nix. This is reflected not only in the lack of external libraries, but even in some basic areas – both FFI and even reading/writing to standard input and output are surprisingly challenging. Summing all this up, writing a basic Linux CLI app (read from stdin, take and parse arguments, print to stdout) is still a pretty large challenge.
As great as APL is, for me, it's hard to overcome the ability to work with the whole existing Linux/FOSS ecosystem. (I might feel differently if I did any Windows development, which does feel like much more of a first-class citizen for Dyalog APL)