Re:AMA: Explaining my 750 line compiler+runtime designed to ...
by arcfide on Sunday March 05, 2017 @06:09PM
(#13799439)
I believe the translation of |/0(0|+)\ is ⌈/0,(0⌈+)\
[ Parent
| on HN ]
Re:AMA: Explaining my 750 line compiler+runtime designed to ...
by beagle3 on Monday March 06, 2017 @04:53AM
(#13801689)
I think this gives the correct answer, but the computation is different (which is fine - we're only looking at the answer); K over/scan go left-to-right, and if I'm not mistaken, APL and J go right to left, that is, in K:
+/!5 equals ((((1+2)+3)+4)+5) which is not 1+2+3+4+5
whereas in APL/J it is +/iota5 equals (1+(2+(3+(4+5)))) which is 1+2+3+4+5
I find the APL approach mathematically consistent and elegant, but the K approach is more practical - it makes over and scan useful for state machines, parsing, and many other uses without having to reverse anything twice.But often, as in this case (or the flatten case) it doesn't matter which direction you start folding from.
Re:AMA: Explaining my 750 line compiler+runtime designed to ...
by Avshalom on Sunday March 05, 2017 @06:13PM
(#13799453)
K does a thing (like J I think?) where it's scan/reduce returns each subsequence/intermediate-value as it goes which is what makes that problem so trivial in K.
Re:AMA: Explaining my 750 line compiler+runtime designed to ...
by RodgerTheGreat on Sunday March 05, 2017 @06:21PM
(#13799505)
The K "over" adverb (/) is like a conventional reduce/accumulate/fold. The K "scan" adverb (\) produces a list of the intermediate results. Having both is extremely handy.
If the verb argument of over/scan takes a single argument (rather than two), the adverbs will iterate to a fixed point. As before, "/" will return the final result and "\" returns all the intermediates.
For example:
+/1 2 3
6
+\1 2 3
1 3 6
*:/,,,0
0
*:\,,,0
(,,,0
,,0
,0
0)
Re:AMA: Explaining my 750 line compiler+runtime designed to ...
by arcfide on Sunday March 05, 2017 @06:33PM
(#13799561)
Oh wait, so you're not preserving the subsequence, you just preserving the sum. So it's a standard scan. So my original translation is correct, my subsequence preserving version is doing a bit more than this by preserving the subarray as well as the sum.