Further to Bill’s point Nollaig, your approach using rank fails for a rank 0 
item …

   $ ,:`]@.(<:@$^:2 fee) fee=:'ab'
1 2
   $ ,:`]@.(<:@$^:2 fee) fee=:,'a'
1 1
   $ ,:`]@.(<:@$^:2 fee) fee=:'a'


For this solution maybe better to just use $ rather than ,: as shown (easier to 
follow and efficient):
   $(_2{. 1 1,$ fee)$fee=:'ab'
1 2

so …
   mat=:((_2{. 1 1,$) $ ])      NB: Note in the left tine of the fork (_2{. 1 
1,$) the argument is supplied by definition of the fork
   $mat 'ab'
1 2
   $mat ,'a'
1 1
   $mat 'a'
1 1

Rob

> On 3 Oct 2015, at 11:28 am, bill lam <[email protected]> wrote:
> 
> $$ looks like a scalar but is a rank 1 array. use #$ instead.
> ,:`]@.(<:@#@$) fee=:'ab'
> 
> the verb
> ,:`]@.(<:@$^:2 fee) is reduced to  ]  and then run as ] fee
> On Oct 3, 2015 8:27 AM, "Nollaig MacKenzie" <[email protected]>
> wrote:
> 
>> 
>> 
>> I have a variable, fee, which might have shape
>> N,2  or just 2.  I want a function that converts
>> fee when it has shape 2 to shape 1 2.
>> 
>> It seems straightforward: if the rank is 2,
>> make no change, if 1, apply ,:
>> 
>> So something like ,:`]@.(<:@$^:2) should
>> do the trick. Indeed, this works:
>> 
>>   $ ,:`]@.(<:@$^:2 fee) fee=:'ab'
>>   1 3
>> 
>> But when I try to define something to do
>> what I want, I get lost.
>> 
>>    ,:`]@.(<:@$^:2) fee=:'ab'
>>    |rank error
>>    |       ,:`]@.(<:@$^:2)fee=:'ab'
>>        ,:`]@.(<:@$^:2 ]) fee=:'ab'
>>        |domain error
>>        |       ,:`]@.(<:@$^:2]) fee=:'ab'
>>            ,:`]@.((<:@$^:2)@: ]) fee=:'ab'
>>            |rank error
>>            |       ,:`]@.((<:@$^:2)@:]) fee=:'ab'
>> 
>> 
>> 
>> (I'll spare you more)
>> 
>> I must be missing something obvious.
>> 
>> --
>> Nollaig MacKenzie
>> http://www.yorku.ca/nollaig
>> ----------------------------------------------------------------------
>> 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

Reply via email to