@J.Sallé Notice that it is your exact program, except using indexing instead of the inner :Ifs and collapsing :For-loops to {_}¨ while giving a left argument to replace the global.
@J.Sallé Of course, one should never write like this in production code. Yours was perfectly good and legible.
@Adám hahahahah I'll keep that in mind. I'm trying to use it on the simplest case '>' but it throws a value error on the last ⍳⍺, do I need to call it with parens?
@J.Sallé Actually, if you want, you can change i⊢←i+ into i⊣i+← for the same byte count but easier to explain and ungolfed. This is what I used in above "ungolfed" version.
@EriktheOutgolfer But he's right, I just golfed his code with not understanding of what it was supposed to do. ngn would use a (cumulative) reduction like you did.
The agenda is now available for SwedAPL '18 on the 4th April in Malmö. It is free to attend but places are limited - see here for details and to register http://swedapl.se/#home
Constant functions
=⍨ and ≠⍨ thanks to ngn.
Sometimes you just need a single value for each element of a list. While you might be tempted to use {value}¨, it is shorter to use value⊣¨ but for some common values, you can get even shorter (using ⎕IO←0):
¯1s with ⍬⍸list
0s with ⍬⍳list
1s with ⍬...
@J.Sallé It finds the locations of each element of ⍺ in ⍬, but since there are no elements in ⍬, each becomes the first index beyond the end, i.e. 0 in ⎕IO←0. So it makes one zero for each element in ⍺, and since that's all zeros of course, we can take the first one and use for i.
@J.Sallé No, notice the ⊣. It is ⍵ which becomes the left argument, but the result isn't needed, so we discard it in favour of ⍵ using ⊣. Then t, which is the final memory state is used to compress ⍵ (the length), because if there are is a 1 in the final memory state, it will give ,⍵, while if there are none, it gives ⍬.
@Adám ah, I see. I'm also having trouble with explaining i+←¯1 1 0⊃⍨'<>'⍳⍵. I think it's 'mapping' (perhaps not the best word, but anyways) '<>' in ⍵, but where does the 0 comes from?
@J.Sallé Yes, remember that dyadic ⍳ will give an index one higher than the last index if the sought element isn't found. That's exactly the same principle as used with ⍬⍳.
@J.Sallé Remember that all functions are right-associative, so the dfn can only "catch" ⍵ while the ⊣ must use the dfn's result as its right argument.