[Jprogramming] testing for variations of false null empty
'Pascal Jasmin' via Programming
programming at jsoftware.com
Mon May 12 01:16:01 UTC 2014
thank you Kip and Raul,
I settled on:
booltest=: [: -. [: *./ 0 = ,
booltest booltest S:0 a:;a:
0
booltest booltest S:0 ] 3;a:
1
I'm not sure its a good general idea, but there is some clear use cases:
+:^:(booltest i.0) 2
2
(i.0) -: +:^:(i.0) 2
1
+:^:booltest 2
4
----- Original Message -----
From: Raul Miller <rauldmiller at gmail.com>
To: Programming forum <programming at jsoftware.com>
Cc:
Sent: Sunday, May 11, 2014 7:53:35 PM
Subject: Re: [Jprogramming] testing for variations of false null empty
On Sun, May 11, 2014 at 5:08 PM, 'Pascal Jasmin' via Programming
<programming at jsoftware.com> wrote:
> booltest =. (0<+./) *. 0<#
> is designed to return 0 for 0 0 0 and i.0, and hopefully this:
> booltest i.0 0, but:
>
> (i.0) -: booltest i.0 0
> 1
>
> the problem with all of this is:
> 3 : 'if. booltest i. 0 0 do. 1 else. 0 end.' 4
> 1
>
> so, it appears I need a 3 part test? How would I write it?
booltest=: [: */ 0 = ,
You do not care about rank or shape, so the argument needs to be raveled.
You want to test if values are zero, so that gives us 0 = ,
And you want to know if all of them are, so */ (or *./) combines them.
The empty case gets the identity value for * (or *.) which happens to
be what you want.
Thanks,
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list