[Jprogramming] What would be a nicer way to check if argument is numeric
Raul Miller
rauldmiller at gmail.com
Thu Nov 9 18:15:50 UTC 2017
That implementation also does not work on sparse data types:
numeric 4+0 $.i.3
1
isnumeric 4+0 $.i.3
0
FYI,
--
Raul
On Thu, Nov 9, 2017 at 1:03 PM, Kenneth Lettow <klettow at thomasnet.com> wrote:
> From ~addons/general/misc/validate.ijs
>
> isnumeric=: 3!:0 e. 1 4 8 16 64 128"_
>
> Though I don't know if this qualifies as nicer!
>
> On Thu, Nov 9, 2017 at 12:20 PM, Michael Berry <mjaberry at gmail.com> wrote:
>
>> Hello J world,
>>
>> I have a verb that returns scalar 1 if the argument is numeric of any shape
>> and scalar 0 otherwise.
>> It works fine:
>>
>> numeric i. 5
>>
>> 1
>>
>> numeric 9
>>
>> 1
>>
>> numeric i. 2 3 4
>>
>> 1
>>
>> numeric 'cat'
>>
>> 0
>>
>> numeric 3#<i. 4
>>
>> 0
>>
>>
>> My definition feels clumsy, however. Can anyone suggest something nicer?
>>
>>
>> numeric=: monad : '0 -: 0{ , 1{. 0#y'
>>
>>
>> -Michael
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>
>
>
>
> --
> *Kenneth Lettow*
> Director Market Intelligence | Thomas™
> Thomasnet.com <https://www.thomasnet.com> | #ThomasForIndustry
> <https://www.thomasnet.com> <https://www.thomasnet.com>[image: Thomas For
> Industry] <https://www.thomasnet.com>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list