^:a: is like ^:(<0 1 2 3 4 5 6...) so the first result is the result of u^:0 y
which is just y (when you apply u to y 0 times, you don't change anything) The same idea applies when you use ^: to mean 'if': x u^:test y where test returns 0 or 1: if test returns 0, y is unchanged; otherwise u is applied. Henry Rich Tracy Harms wrote: > Thanks, Henry and Raul. I've seen this pattern in JfC and elsewhere, > but apparently it's one I'm still working on fully assimilating. > > The most important thing I'd missed was the effect of ~ such that each > pass changes what index is used to draw from an unchanged reference > vector. Careless. > > The other puzzling thing for me was the inclusion of the initial > argument. It's very nice that it works that way, but I am again > surprised that the first item resulting from the ^:a: pattern is the > unprocessed argument. Maybe this time I'll remember. Or next time. ;) > > Anyway, now I fully understand the algorithm, and that's satisfying. > > T > > On Fri, May 8, 2009 at 8:55 PM, Henry Rich <[email protected]> wrote: >> x {~^:a: y >> >> turns into >> >> ((y { x) { x) { x ... >> >> repeated until you get the same value fetched from x twice in a row. >> The results of all the fetches are concatenated into a list. This is >> the idiom to use for chasing a linked-list. >> >> Henry Rich >> >> Tracy Harms wrote: >>> I'm having difficulty understanding the following verb: >>> >>> {~^:a:~ >>> >>> from the following bowling-score verb: >>> >>> framex =: 10 {. 0 {~^:a:~ _1 _1 ,~ i...@# >:@:+ 10&~: >>> >>> >>> I understand several aspects of what it does. I know it's drawing the >>> head element, I know it's doing this repeatedly until stable, and I >>> know it's returning the accumulated result of all iterations. I know >>> that it's qualifying 10s that have the right remainder-of-two to count >>> as a strike in context. What I'm not comprehending is how it produces >>> more than the first element of the right-hand argument. >>> >>> Thank you. >>> ---------------------------------------------------------------------- >>> For information about J forums see http://www.jsoftware.com/forums.htm >>> >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
