Subject: Re: Atop continues to puzzle me
This post was initially titled 'The benefits of function composition' See my PS. There are things you can achieve with function composition that cannot be achieved so elegantly any other way: 3 4 5<@#"0 i.3 +-----+-------+---------+ |0 0 0|1 1 1 1|2 2 2 2 2| +-----+-------+---------+ This is what I want - a set of 3 0s, a set of 4 1s and a set of 5 2s. This doesn't give me what I want: 3 4 5#"0 i.3 0 0 0 0 0 1 1 1 1 0 2 2 2 2 2 Nor does this: 3 4 5 ([: <"1 #"0) i.3 +---------+---------+---------+ |0 0 0 0 0|1 1 1 1 0|2 2 2 2 2| +---------+---------+---------+ But this does: each +--+-+ |&.|>| +--+-+ 3 4 5#"0 each i.3 +-----+-------+---------+ |0 0 0|1 1 1 1|2 2 2 2 2| +-----+-------+---------+ ... but then &. is function composition. The unavoidable problem with not using function composition in such instances is that J turns the result from every execution of a verb into a rectangular array. When a series of verbs is executed in succession without composition, J has to produce a succession of 'properly finished' results along the way. With composition, this finishing process is confined to just once at the end of the process. ------------------------------------------------------------------------ PS I wrote this before reading Linda's recent post on 'atop continues to puzzle me' (Wed, 02 Jan 2013 03:02:54 -0500): > Here's another, hopefully simpler, example of my problem > with @ > > ]a=:?>:i.6 > > 0 1 1 3 1 5 > > ]a=:=a > > 1 0 0 0 0 0 > > 0 1 1 0 1 0 > > 0 0 0 1 0 0 > > 0 0 0 0 0 1 > > ]b=:?>:i.6 > > 0 1 0 3 1 3 > > a #@# b > > 1 3 1 1 Linda, this example is another illustration of the point I have made above. Not using @, as you rightly suggest, we might expect # a # b 4 not to give 4 but 1 3 1 1. But no, for the reasons I have explained above. a # b has to produce an intermediate rectangular result: a # b 0 0 0 1 0 1 3 0 0 3 0 0 But 6 of those zeroes are padding. If J didn't have to mould that intermediate result it would look like 0 1 0 1 3 3 and the tally of those is 1 3 1 1! I hope this is helpful. Regards Graham ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
