@dzaima I think I'd prefer the naught (⍬) behavior more often, but would go with the backward (←) behavior personally, assuming it's a primitive you want to add to a dialect. Only because I think it's easier to extend from ← to ⍬ than from ⍬ to ←. @all Is that a reasonable enough reason to implement something ceteris paribus?
AKA something like {⍺<⍵: ⍬ ⋄ primitive} vs. {⍺<⍵: ⌽primitive ⋄ primitive}
@dzaima Agreed! If they're similar enough then it doesn't matter. But I find the first one significantly clearer somehow
In a case like this it seems better to overextend and let the user de-extend, than under extend and force them to craft an extension. I suppose that's what I was trying to say
So conceptually and efficiently-wise, they're equal. But on a more fundamental level, the first one seems better to me somehow. I may very well be wrong here, but that's my two cents
Holy moly!!! Same exact time... I was just about to paste in a CMQ I wrote. I suppose you'll get a heard start, @Bubbler :)
Was reading it over & hovering over 'send' when you sent that, so I deleted it to express my astonishment ⍥
@Bubbler Agreed, but that seems more the case when it's actually complicated
Alright, here goes:
CMQ: You have a grid of lights arranged on/off in a checkerboard pattern. It's an n by n square grid where n is odd. And n is the right operand, ⍵. There's a light switch connected to each lamp in the grid. The left operand, ⍺, is the number of times you should flip the light switch. Print the final state after ⍺ flips.
--- Note: You may start with the grid in either of the two possible states below. But whatever is given by 0 {...} *n* must remain consistent throughout as the starting state.
Also, think I'll add it as CGCC, or whatever the acronym is, question. Though, I'll probably remove the constraint that n must be odd. I won't for the APL challenge because there's a nice solution which doesn't work in that case. Feel free to answer for the more general question where n can be any integer, and please note if it also works for evens!
The other variant that I recommend solving/competing for is the specific case where n = 3. Likely an easier starting point, and would be interesting to see alternatives to that if there are some which don't generalize trivially to an odd n.
@Bubbler Not quite. They should all switch every time. So it should go from the first state shown, to the second, back to the first, and back to the second
@Bubbler Shoot! I'd no idea it was that easy!! You've completely outdone me, too :(
I was so happy, haha!
I had: {2|⍺+⍵ ⍵⍴⍳2}
@Bubbler Wow. You have me beat clean!
Well, it should be really interesting to see implementations of this in all sorts of esolangs, methinks!
@Marshall @all You missed the fun...
Don't look at the end; there's spoilers. @Bubbler beat me in half a minute at my own game
RE asking as code golf challenge: This difficulty, or even far more trivial, tends to be the level of question I like to see there because it encourages all the ridiculous esolangs and tarpits to come out from the corners where they were hiding. Otherwise no one bothers writing solutions in some of the really other-worldly languages if it gets any trickier than this! Seem worth writing up the Sandbox post?
@Marshall So we were the ones missing out! In Soviet Russia, out misses you ( ͡° ͜ʖ ͡°)
@Bubbler Any chance that's further golfable? (That doesn't sound right; conjugated properly?) AKA is it worth leaving the generalized CMQ up for battle?
@AviF.S. {2|⍺+∘.+⍨⍳⍵} has the same length as this one. BQN's version {2|𝕨++⌜˜↕𝕩} is one character shorter (matching Bubbler's) because of the single-character Outer Product ⌜.
@AviF.S. No, f/3 1⍴⍳3 has shape 3 regardless of what f is: reduction always removes the reduced axis from the shape and leaves the rest. 3 1⍴⍳3 is a flat array so it doesn't have much for insides either.
@Marshall On the first part: I know that it won't work but I was conceptually thinking about summing the insides. Maybe that's a silly way to think. On the second part: I think I totally screwed up. I believe I was thinking of ⊂⍳3
Hmm, I suppose I'm way off. I was attempting to think of another case where one could demonstrate that same phenomenon re: 'the argument is a matrix so =/ gives you a vector instead of a scalar.'
@AviF.S. I think Marshall wanted to say this: in f⌺x, f is called several times with a matrix argument. If f gives simple scalar, the entire result of f⌺x becomes a simple matrix; otherwise the result becomes nested.
@Bubbler Thanks for the clarification! As it happens, I did understand that. However my go at replicating that behavior in an instance where it would be easier to see was not fruitful
A close thing is probably a non-scalar reduction such as ,/, which encloses the result of reduction in order to keep the invariant "the result of f/ has the last axis removed".
I have a vector containing 9000 integer elements, where each group of 9 has 3 sub-groups that I'd like to separate out, resulting in a matrix with the shape 3 1000 3. Here's what I did:
⎕IO←0
m←(9÷⍨≢data) 9⍴data
a←m[;0 1 2]
b←m[;3 4 5]
c←m[;6 7 8]
d←↑a b c
Ah, gotcha, yeah. The signature syntax is kind of special, leveraging a lot of the builtin features. You've got inline default assignment going on here as well as Pair shorthand (:key ≡ Pair.new(k => 'key', v => True))
the use of :v($verbose) is more specific to the MAIN as it creates two named CLI flags to assign to a single variable. In a signature to a regular subroutine this just means you pass the value assigned to be assigned to $verbose to the named argument v.
@Adám :) ... it's definitely not a small language but a lot of that kind of stuff gets picked up by the brain pretty quick, similar I guess to APL idioms
The pair syntax I miss a whole lot whenever I have to go to another dynamic language that makes me do func( request => request, otherObviousNameForBothCalleeAndCaller => otherObviousNameForBothCalleeAndCaller)
Yes, in fact monadic ⍉ is just dyadic ⍉ with a default left argument (⌽⍳≢⍴⍵). I occasionally claim that one has not mastered array programming until one has mastered dyadic ⍉.
So this is probably going to sound random... I've been searching for an APL paper by someone who was writing from a standpoint of having long sought a language which could convey and model systems of management. I don't think it is located in the J Papers archive, IIRC I found it by following a link on a bio page to the page of someone's mentor..
OK, so first I used ⍳90 as sample data. This allowed me to see that we're filling one row from each layer first, then the second row from each layer, etc.
I have a vector containing 9000 integer elements, where each group of 9 has 3 sub-groups that I'd like to separate out, resulting in a matrix with the shape 3 1000 3. Here's what I did:
⎕IO←0
m←(9÷⍨≢data) 9⍴data
a←m[;0 1 2]
b←m[;3 4 5]
c←m[;6 7 8]
d←↑a b c
which does what I want -- but can I sha...
@Adám Do you mean add it as a request for the paper? Because my issue is that the I've lost track of it and have been unable to find it after digging in around. I'll expand the search to include all of the links on that page though, thank you!
I have a vector containing 9000 integer elements, where each group of 9 has 3 sub-groups that I'd like to separate out, resulting in a matrix with the shape 3 1000 3. Here's what I did:
⎕IO←0
m←(9÷⍨≢data) 9⍴data
a←m[;0 1 2]
b←m[;3 4 5]
c←m[;6 7 8]
d←↑a b c
which does what I want -- but can I sha...
@ab5tract Yeah, saw that. Why do you have empty lines after "⊢ lines"? (Also, I recommend ⎕← over ⊢ for various reasons I can elaborate on if you're interested.)
@Adám And now I feel that I truly understand how you got there. My explanation relied on having the insight of the intermediate slices being each of shape n 3 but this explanation goes from the basis of the output shape alone. I like it!
There should be a section on the song contents with links to the rest of the wiki though. I just wouldn't quote it directly. There are plenty of other pages that reprint it.
@Adám No, just something like "The first verse describes [[Ken Iverson]]'s publication of [[A Programming Language]], describing the notation he had written about before in a more organized and complete way. The second describes the usage of Iverson's notation as a hardware description language at [[IBM]]..."
@Adám That doesn't work unless they're able to grant us rights. You can talk to Bob Armstrong or Jim Brown to see if you can figure out who owns it and what permissions they have, but I suspect it's just copied without any regard for copyright. That's fine for smaller sites, but APL Wiki will probably become more prominent and we'd rather not attract legal attention.
Same goes for many of the papers on jsoftware.com. In most cases I think Roger has permission from the author, but we still shouldn't copy anything from them onto the wiki.
@RGS most APLs have scalar/singleton extension (args either have to be of exactly the same shape, or one can be a scalar), but that'd require leading axis agreement; see this (unfortunately no page on "Leading axis agreement")
Next step is to remove all the redefinitions of primitives that actually work, and then of course more functionality can gradually be moved to the main dzaima/BQN.
It runs as an executable that takes all input from stdin.
@RGS 1=≡⍺ ⍵ ⍵ checks if both ⍺ and ⍵ are of rank 0 (as a vector of them would be rank 1); there are 2 ⍵ so in the case of ⍺←⊢ the 1 = ≡⍵ ⍵ would still act the same (really it could be 1=≡⍺ ⍵ 0 or whatever)
This auto-mapping happens only when the arguments have identical shape (then it pairs up) or when one of them is a single element (then it distributes the singleton to all elements).
Think of indexing into a book. In order to pinpoint a specific letter in the book, you'd have to give a page (layer) number, line (row) number, and character (element) number.