Indeed a good point Julian that is also a handy idiom for “pairwise” in J.

Note the q version also allows the null (0N) to be placed anywhere in the shape 
vector, so if you knew the list had 3 groups, but weren’t sure how many items 
in the group then you could also do this:

q)3 0N#args                     /Comment:  From my list of 6 items I know there 
are 3 keys … let # determine the groups
"Code" 33
"Name" "Iverson"
"Age”  34

Then in J, the usual
        (3,($args)%3)$args      NB. Produces the same result as below, but one 
only needs to know the “3” rows

The key advantage is simply a “handy benefit”.  I recall having to calculate 
the shape for these types examples frequently in APL.

@Joseph: Not sure about how this idiom is factored in to the q implementation, 
the q version does handle higher rank lists too, but would need to experiment 
to determine impact on your idiom.

Rob


> On 22 Aug 2020, at 2:18 am, Julian Fondren <[email protected]> wrote:
> 
> On 2020-08-21 10:55, 'Rob Hodgkinson' via Programming wrote:
> ...
>> q)0N 2#args
>>           /Comment: q uses the NULL value (0N) to say “I know the
>> list is in pairs, so work out the rows" (hence here 3 x 2)
>> "Code" 33
>> "Name" "Iverson"
>> "Age”  34
>> The equivalent mechanism in APL or J is along these lines:
>>   args=: 'Code';33;'Name';'Iverson';'Age';34
> 
>   _2]\args
> ┌────┬───────┐
> │Code│33     │
> ├────┼───────┤
> │Name│Iverson│
> ├────┼───────┤
> │Age │34     │
> └────┴───────┘
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to