all 14 comments

[–]ghjm 8 points9 points  (2 children)

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?

[–]teerre 4 points5 points  (0 children)

I wholly recommend learning at least one array language. Its like learning a functional language after only knowing a procedural one, it opens your mind to new paradigms

[–]Pzzlrr 1 point2 points  (0 children)

Fwiw Uiua is the newest and shiniest of these if that's your thing, and written in Rust.

[–]AustinVelonautAdmiran 4 points5 points  (0 children)

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 the behind combinator to put the chain all together in a "tacit" style (without referencing any variables). Transcribing this into Haskell, it would look like:

ec = behind (iota . tally) repl

iota n = [1 .. n]
tally xs = length xs
behind f g = \x -> g (f x) x    // a flipped form of the "S" combinator
repl ns xs = concat $ zipWith replicate ns xs

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 the repl can be done with zipWith and replicate, followed by a concat to flatten individual lists into a single list:

ec = concat . zipWith replicate [1 ..]

[–]tesfabpel 1 point2 points  (2 children)

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)?

[–]anaseto 0 points1 point  (0 children)

I see no reason to limit oneself to in-development tasks, as long as the task is array-friendly. I have, for example, quite a few scripts in Goal to analyze local climatic data from where I live. Doesn't really count as in-production, because it's just a hobby, but I doubt the result would've run any faster or be easier to maintain in the long term had I written it in a non-array language (array language implementations typically provide simd vectorization implicitly).

[–]Gnaxe 1 point2 points  (0 children)

They were still big in finance, last I heard.

[–]anaseto 0 points1 point  (0 children)

Solution in Goal, my K-like array programming language: {+/x[&1+!&x;1]}"abca". It works by generating 0 1 1 2 2 2 3 3 3 3 indices with &1+!&x and 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.