| ▲ | NetMageSCW 4 hours ago | ||||||||||||||||||||||
My favorite APL one liner reduces spans of consecutive spaces in a string to one space by doing boolean algebra on the vector of which characters are spaces. APL provided me with a whole different perspective on vector style operation (it was my second language to be familiar with after Basic due to finding an APL introductory book at a discount shop). I find that way of thinking has been very helpful in developing with LINQ in C# and my personal library has many methods inspired by APL operators. | |||||||||||||||||||||||
| ▲ | icen 4 hours ago | parent [-] | ||||||||||||||||||||||
Do you remember what it was? This is how I would spell that in BQN, and you could write something very similar in APL (you don't have shift, so you'd have to write 1 drop 0 cat swap instead)
This works by building a boolean mask of spaces, and converting it to a mask of 'is a space, preceded by a space', negates that, and replicates out by that inverted mask (i.e. is not a space preceded by a space):Here's stepping through it with some input. | |||||||||||||||||||||||
| |||||||||||||||||||||||