I use
ifany=: ^:(*@#@])
butifnull =: 2 : 'v"_`u@.(*@#@])'
rad ifany C
rad butifnull (2 0$0) C
Henry Rich
On 10/4/2012 7:22 PM, Linda Alvord wrote:
I just realized that all these choices, change B in some way. I want it to
always be a two row table of pairs in columns.
B=:2 4 $3 5 5 4 2 1 1 6
3 5 5 4
2 1 1 6
''$ B
3 5 5 4
{. B
3 5 5 4
0 { B
3 5 5 4
,/ B
3 5 5 4 2 1 1 6
My only concern is when B happens to have no pairs, in which case I want a
result that is an empty array when rad is used.
I'm glad I noticed these problems as they would have caused even more grief.
Thanks for you continuing assistance.
Linda
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Raul Miller
Sent: Thursday, October 04, 2012 11:34 AM
To: [email protected]
Subject: Re: [Jprogramming] Why the length error?
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 <[email protected]>
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: [email protected]
[mailto:[email protected]] On Behalf Of Ric
Sherlock
Sent: Thursday, October 04, 2012 2:40 AM
To: [email protected]
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 <[email protected]>
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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm