@Aearnus OK, so let's have a look at ((⍵-96) (⍵-64) 0). You are essentially subtracting three numbers from ⍵, so you can write this as ⍵-96 64 0. Also, it doesn't need any parens at all, as it is right-most, and APL is right-associative.
@Aearnus Oops, yes, my bad. You're only subtracting two, and appending 0, so (⍵-96 64),0 and if you want to remove the last paren, "swap" the arguments of , to 0,⍨⍵-96 64
@Adám I don't either, haha. I checked out an APL2 book from the library earlier and I haven't run into a bit of code that hasn't worked in my interpreter though
@Aearnus I think you can safely remove the 0,⍨ part btw, because if the argument doesn't fall in any of the ranges, then the compression ends up giving an empty numeric vector, and the first (↑ in GNU APL) element of that coerces out a prototypical 0.
@Aearnus Right, I think GNU APL is pretty much a superset of APL2 maybe except for certain advanced system features.
@Aearnus Exactly like in J. (f g h)⍵ is (f ⍵)g(h ⍵)
@Aearnus Here is another thing you can do: The two subtractions are really unnecessary, as you will only ever subtract at most one, so you can write: {↑⍵-((⍵≥97 65)∧⍵≤122 90)/96 64}
@Aearnus Now here is a think I'm not sure about in GNU APL: whether ⍨ can swap the arguments of / or not. If it can, then {↑⍵-96 64/⍨(⍵≥97 65)∧⍵≤122 90} should work.
@Adám Hmm, that sounds super useful. I feel like it'd be just as unwieldy though to check if it's in interval 1 or 3 (which is what I'm looking for in this specific example)
@Adám I would be, but there's more to it. Now I have a vector defined as `{⍵<normalize¨ ⎕UCS ⍺}`, and I want to use that to take the characters of ⍺ and keep them the same if 1, or replace with a space if 0
{(⍵<normalize¨ ⎕UCS ⍺)/⍺} would work if it didn't just remove the characters -- but it's very close to what I want
Notice that a) we can operate straight on the characters, rather than their code points, and b) we don't need to loop with ¨ any more.
Now, listing the alphabets may be a bit verbose, but some APLs (e.g. Dyalog) have ⎕A which is the uppercase alphabet, and a special service (819⌶) to lowercase, so it can be written as ⎕A,0,819⌶⎕A
@Aearnus Items that do not occur get the index of 1+ the last index, so if it was just a single alphabet (all uppercase) we could get away with 27|'ABC...Z'⍳⍵ but since we have lowercase as well, 'a' would also end up 0, so we push it one step right by inserting an element that won't hurt. Could have been any non-letter too.
@Aearnus Right, you have code to compress away the unwanted elements, but now you want to expand with an inserted space in those exact same location. Luckily, APL has an expand function \
@Aearnus You should get the license still today. Made its case, just wait and see. Dyalog has introduced the @ operator which appropriately amends its argument at locations indicated by its right operand. E.g. you can add 10 to the third element with 10+@3:
@Aearnus If the right operand is a function, it must return a mask that indicates where the changes are to be made, and the left operand can also be an array with substitution values:
@Aearnus ⎕ML←3 is Migration Level, and 3 means be as similar to APL2 as you can.
There are not too many differences. The most frequently encountered one is that the meanings of monadic ⊃ and monadic ↑ are swapped. Also, monadic ≡ is a bit more informative in Dyalog's normal behaviour (⎕ML←1) and partition (dyadic ⊂) has a different definition, but APL2's partition is always available as ⊆.
@Aearnus Also, Dyalog has really neatly integrated regular expressions, so you could also just have done:
@Aearnus (btw, you can't use markdown in multi-line messages, but if you write multiple messages right after each other, the system will merge them visually.)
@Adám
Hello World
Hello World
Hello World
Hello Worl
H llo Worl
H llo Worl
H llo Worl
llo Worl
llo Worl
llo Worl
llo Worl
o Wor
o Wor
o Wor
W r
W r
W r
W
W
W
W
W
The ⍕ is to avoid drawing a lot of lines indicating nestedness which would make the output very verbose.
@Aearnus Note that your "real" argument, which is the string, is hard-coded into your lambda. This is hardly desirable, but you can of course code around that with an additional lambda layer: {⍵∘{' '@(~(⍵↓⎕A)∊⍨819⌶⍨∘1)⍺}¨⍪⍳26}
(it's a code golf challenge between a few friends and I, and one of the requirements was the original string still had to be printed on the first line, hence the lone W)
@Aearnus Also, you may notice that all but the first line are indented one space. This is due to the result being nested. If you remove the ⍪ and instead put ⊃ on the left of the left-most { then it will line up better. In fact, then you can even replace the diamond there with a ⍪ so the full result is truly returned as a single array.
@Aearnus If GNU APL supports ∘ as an operator, you can write {⍵⍪⊃⍵∘{⍺{b\b/⍺⊣b←⍵<{↑⍵-((⍵≥97 65)∧⍵≤122 90)/96 64}¨⎕UCS ⍺}⍵}¨⍳26} to have a true lambda at the same character count. GNU may even allow you to remove the space in ⎕UCS ⍺.
@Aearnus ∘ used like that (of course only in APLs that support it) curries an argument to a function. So 1∘+ is the increment function and ÷∘2 is the halve function.
@Aearnus Here, I was using it to let ¨ apply the lambda with a bound argument as a monadic function. Without ∘ it would try to pair the letters of the string with the 26 numbers.
@Adám currying! That's a comforting tool to have (coming from a Haskell background)
Makes a lot of sense. I'm going to put this project on the shelf for the night though -- early classes tomorrow. Thank you so much for all of this help! I appreciate it
@Aearnus Yes, but it does more than that, it is generally called composition as it composes an argument with a function, but it can also compose two functions exactly like the identical symbol is used in traditional mathematical notation, so you can define a new function f←g∘h which when applied to x gives you f(g(x)).
@Aearnus Not a problem at all. You're always welcome, and there are more people here than me who are happy to help. Once you have Dyalog APL installed, you may want to look at our lessons for features that don't exist in GNU APL.
Working for fun on a Pentaminoes 5x5x5 Cube Puzzle
check it out at https://www.youtube.com/watch?v=PjmFjIDYdiw
I enjoyed so much the process of making the program using Dyalog APL.
@dyalogapl
Our CXO, @mkromberg, together with Ray Polivka, is proud to be giving a lecture for The Winifred Asprey Lecture Series in Computer Science at @Vassar College. Details of the lecture can be found here https://www.cs.vassar.edu/_media/events/individual_events/apl_2019-2-13_ray_polivka_morten_kromberg_11x17_flyer.pdf