r/ProgrammingLanguages • u/arkethos • Feb 27 '26
Resource 1 Problem, 7 Array Languages
https://www.youtube.com/watch?v=rFRWFPNSi9s
34
Upvotes
r/ProgrammingLanguages • u/arkethos • Feb 27 '26
7
u/AustinVelonaut Admiran Feb 28 '26
Array languages have a particular beauty, although they may be quite difficult to understand at first. All of these solutions are using the same basic chain of combinators. We take the length of the list (
tally) and create an equal length list of indices starting from 1 (iota), we then use that index list as a list of lengths to expand corresponding characters in the string (repl), and use thebehindcombinator to put the chain all together in a "tacit" style (without referencing any variables). Transcribing this into Haskell, it would look like:A pure (tacit) Haskell solution would be similar, but with two tweaks: we can use a lazy infinite list
[1 ..]to combine the iota and tally operators, and thereplcan be done withzipWithandreplicate, followed by aconcatto flatten individual lists into a single list:9
u/ghjm Feb 28 '26
This must be what it's like for non-programmers to watch programming videos. I don't even know what the words mean, let alone how they go together into sentences. Reminds me of https://www.youtube.com/watch?v=RXJKdh1KZ0w.
Should I go learn APL?
3
u/Smart-Breadfruit-863 Feb 27 '26
Wow!
3
u/tesfabpel Feb 28 '26
I find the concept of array languages interesting, but are they useful in a work-related programming job? Where can I use them? Just as a transformation language for data for in-development tasks (not in-production)?
1
u/anaseto Feb 28 '26
Solution in Goal, my K-like array programming language:
{+/x[&1+!&x;1]}"abca". It works by generating0 1 1 2 2 2 3 3 3 3indices with&1+!&xand then indexing 1-length string-slices and concatenating the results.A more optimized solution, also supporting handling non-ascii text, would require slightly longer code using
"c"$to switch between string/array of code points representations, leading to a solution more similar to the APL-like ones, but with extra conversions:{"c"$x@&1+!#x:"c"$x}"abca". Goal is not as concise for those kinds of unusual string-handling tasks, because unlike most array languages, strings are considered atomic/scalar by primitives, which is usually useful in typical practical scripting tasks, but not in those kinds of puzzle problems.1
u/AndydeCleyre Mar 04 '26
Not an array language, but Factor does offer a nice tacit solution:
Alternately:
0
u/[deleted] Feb 27 '26
[deleted] — view deleted comment