Here are some options (I'm repeating concepts expressed by Roger Hui and Devon McCormick:
L=: 1,'' ''$ L {. L 0 { L ,/ L Roger's suggestion is equivalent to the APL classic in this context, but in the general case you would need to ravel the right argument if L had a rank greater than 1 (APL's rho is like ($,) in J). {. L and ''$L and 0 { L do exactly the same thing, but the syntax is different, which can be significant if you are building a train (Roger's approach re-expresses nicely as a fork -- 0 { L is also nice in a fork but since numbers stick to other numbers to form numeric words it's not quite as nice as Roger's approach).. ,/ L is different -- the others will discard extra elements and always reduce the rank of the result while ,/ removes a leading dimension but never gets rid of any elements (so if you have multiple elements it will not take you below rank 1). Anyways... simplest depends on you and where you are going. And note that there's other options also, depending... (+/L for example, would also get you an atomic 1 in this case).. -- Raul On Thu, Oct 4, 2012 at 9:35 AM, Linda Alvord <lindaalv...@verizon.net> wrote: > This is the crux of the problem: > > 1,'' > 1 > $1 > $1,'' > 1 > > What is the simplest way to make the shape of 1,'' be empty? > > Linda > > > -----Original Messapege----- > From: programming-boun...@forums.jsoftware.com > [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Ric Sherlock > Sent: Thursday, October 04, 2012 2:40 AM > To: programm...@jsoftware.com > Subject: Re: [Jprogramming] Why the length error? > > This gives a length error because > (1,'') # '' > |length error > | (1,'') #'' > > An simple solution to your problem is to returns the input on error: > rad=: (#~ [: -. 0 , 2 -:/\ ])@|: :: ] > rad '' > > rad B > 3 2 > 5 1 > 4 6 > > On Thu, Oct 4, 2012 at 6:41 PM, Linda Alvord <lindaalv...@verizon.net> > wrote: >> >> rad=: 13 :'(A=:1,-. 2-:/\|:y)#"1 y' NB. Remove adjacent >> duplicates >> >> ]B=:2 4 $3 5 5 4 2 1 1 6 >> 3 5 5 4 >> 2 1 1 6 >> rad B >> 3 5 4 >> 2 1 6 >> >> >> The verb rad works as expected, but suppose in an earlier step B >> has become empty, I get a length error. Why does this happen? >> >> >> C=:'' >> rad C >> |length error: rad >> | (A=:1,-.2-:/\|:y) #"1 y >> A >> 1 >> 1#"1 C >> >> What can I do to get an empty result? >> >> Linda >> >> ---------------------------------------------------------------------- >> 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