« first day (2064 days earlier)      last day (887 days later) » 

03:51
hi, noob question maybe;
this will sound like an xy problem but i really just want to understand why my y is wrong so i can approach x better lolol
im trying to reduce over... a ragged array? with this: {(⍺[1]+⍺[2]) ⍺[1]}/ and then an array to the right, something like (1 0) 0 0 0, but it keeps giving me errors like "length error" or "rank error" for the thing in {}, specifically it keeps pointing at the rightmost ⍺[1]
      {⍺[1]+⍺[2],⍺[1]}/(1 0)0 0
RANK ERROR
      {⍺[1]+⍺[2],⍺[1]}/(1 0)0 0
                  ∧
      {((1⌷⍺)+(2⌷⍺)) (1⌷⍺)}/(1 0) 0 0 0
LENGTH ERROR
      {((1⌷⍺)+(2⌷⍺))(1⌷⍺)}/(1 0)0 0 0
                      ∧
wait i think i see it i should have rubberducked more before i came here, will report back in a sec
actually come to think of it, even if what i think is happening is happening, i wouldnt know how to fix it
so yeah, im not sure why im getting an error, where did i bad pls advise :')
most likely people have wrong understanding to /
it is executed from right to left
so it first try to execute 0{⍺[1]+⍺[2],⍺[1]}0 which give the rank error
ok yeah that was literally it whew, i thought i was crazy i was just dumb ^_^
i can live with the latter
thank you :-) now it works as expected
aplcart.info?q=fold%20left and this is the "fold" you expected
04:01
right lol, its definitely better (or at least simpler for me) to take the list in the reverse order and switch ⍺ to ⍵
in my defense; scan seems to work left to right :P i figured reduce was the same
live and learn i suppose
scan is also right to left
although for primitives like + the implementation takes the shortcut
you can lookup IBM's APL2 specification which explains these
fair but i wish it were consistent instead of playing tricks on me y_y but ok yeah ill just read more
as an example, scan op\a b c d is (op/,a) (op/a b) (op/a b c) (op/a b c d)
04:10
ohh
⍝\o/ enlightenment
again, the "left" scan is here aplcart.info?q=scan%20left
@thejonymyster Uh, it is consistent. The things with + is internal, and only affects precision when summing floats.
04:26
@Adám no, no i was totally misreading it
but yea i appreciate the clarification lol
 
4 hours later…
08:00
@LdBeth Sort of... It doesn't actually collect the accumulated results but rather does reduce (right-to-left) on longer and longer prefixes. So, the reduce part is right-to-left, but what grows are prefixes and not suffixes.
Not collecting results has performance implications (and with it so does @thejonymyster's work around), but because the reduce is right-to-left there was no choice if you want it to operate on longer and longer prefixes.
... which is the way people picture scan.
 
4 hours later…
12:23
@doug oh am i writing slow code
i can be better :triumph:
actually i never sent what i ended up doing here lol i just logged off once i got answers XD
uhh i dont have apl keyboard on me but basically i just did {((ω[1])+(ω[2]),(ω[1])}/ (except spelled way better) and then made sure the starting element was the last element of the list instead of the first
is there a better alternative? this seems pretty straightforward, and i wouldnt want to like.. fold left instead that seems like way too much effort just to like, circumvent something that doesnt need circumventing. am i missing something?
13:03
oh, specifically for performance btw; i know its not golfy or elegant as shown currently, i just want to ensure im not going to make my code super slow for no reason lol
that's the normal way to do it
ok good im not crazy hooray
ty
 
10 hours later…
22:52
I use the hacky translation of left fold a bunch because I think better with left folds. I was just pointing out that performance could be a concern you might have.

« first day (2064 days earlier)      last day (887 days later) »