I rewrote a python one in numpy, wrote it in APL, wondered why I was getting the wrong answer for about 20 minutes and then realised I had to set ⎕FR to 1287
Hello folks, is there a way to get rid of the parentheses in ⊃(//⎕VFI'1 2 3 4') ? I tried various combinations with ∘ ⍤ ⍨ but no luck, seems like I can't make APL think of the // as one unit and the things to the left of that as a separate unit
APL's order of execution is very simple: Operators bind first (from the left), then functions are applied (from the right).
So, since ⍤ is a dyadic operator, it binds ⊢ and (the closest) / as its operands, yielding a new function equivalent to {⍺/⍵} which then becomes the operand of the rightmost /
@KamilaSzewczyk Also, I'd avoid Classic unless you have to. I know it is a bit awkward to adjust byte counts to char counts, but you'll avoid garbage on stdout, and byte-counting pitfalls.
@MartinJaniczek Aha, markdown is not active in multi-line messages, but you can use two consecutive messages, and it'll look pretty much the same.
@Adám It's not an APL tutorial in the sense that I introduce primitives as the application needs them, rather than following a systematic plan of instruction for an APL novice.
At first I put each solution in its own file but now I just stick them all in one big file
I should probably sed it at some point so that `⍝ Problem 76 ⍝ Counting summations` becomes `⍝ Problem 76 Counting summations` to avoid the extra line per problem
Actually, it doesn't matter, the solution I'm thinking of would be shortest with the life function in dfns, a non-toroidal solution wouldn't change anything.
Well, I was originally thinking of removing the 0-padding necessary to make the life function work, but if that's removed, then it won't be treated as an infinite grid.
GNU APL recently introduced something called "structured variables". It actually looks a bit like the similar concept in COBOL of all languages. Is this something that exists in other APL's? gnu.org/software/apl/apl.html#Structured-Variables
Hey folks! I was trying to implement "replace all chars X with char Y in string Z", got {'Y'@(⍸'X'=⍵)⊢⍵} Z, then looked at the APLCart, found 'Y'@(=∘'X')Z which looks awesome but I'm confused by how it works. (I think I get @ when the right arg is list of indices like 2 4. But, how does the binary selection example work? Does @ figure out it has a function instead of a vector on the right side and switches into different mode in that case?
One more question. The =∘'X' inside the "replace occurences" example... Does the order matter? As in, the above snippet would apply 'X' as ⍵, and 'X'∘= would apply it as ⍺ instead?
But you're right, that binding (a.k.a. currying) an argument to a dyadic function renders a monadic function where the right (and sole) argument is used in the remaining argument slot of the original function.
<phantomics> Dyalog's docs enumerate the arguments and operands, mentioning the left operand may be an array, or the right may be an array, they could have a sentence mentioning the particular case where both may be arrays
Well, it isn't particular to ∘ but rather falls under a general rule that every operator (except the slashes) can take any (combination of) array(s) and/or function(s) as operand(s), even if no meaning has been given to the derived function.
So really, our docs are all wrong. They claim about operators that they have a specific domain, when the technical reality is that the derived function may or may not have an argument domain.
E.g. any array or function is a valid operand to ⌶ but only a select few positive integers have meaning.
one definition of "valid" is "when i type it and press enter, it doesn't error". another is: "when i apply the derived function to a valid argument, it doesn't error".
@ngn OK, but then I challenge you to find an invalid derived function (i.e. the function itself does not error if entered by itself) in the sense that there exist no arguments that cause it to not error.
Heh, if you turn boxing on, then you can find the line box←{susp ⍺(⍵⌶Box)⍵} in ⎕SE.Dyalog.Out.Filter where ⌶ is meaningfully used to construct a meaningless derived function!