## Determine if the argument is integer or string

General APL language issues

### Determine if the argument is integer or string

I've encountered a following code to determine if the argument is an integer or a string:
Code: Select all
{' '≡↑0⍴⍵}

This works! But how else it is possible to detect it in pure APL-way ?
alexeyv

Posts: 56
Joined: Tue Nov 17, 2015 4:18 pm

### Re: Determine if the argument is integer or string

Strictly speaking, that expression tells you whether the argument is character or not, it doesn't tell you what kind of number (boolean, integer, float, complex) it might be. On the other hand, I would say that it is "pure APL", since it only uses primitives.

It might be more direct to use ⎕DR, which returns a number which is the data type + 10×the bit size of the element:

Code: Select all
{(⍕¨⍵),⍪⎕DR¨⍵}'A' '⍋' (0 1) 127 1000 40000 1.1 1J2
A        80
⍋       160
0 1      11
127      83
1000    163
40000   323
1.1     645
1J2    1289

Type 0 is character, 3 is integer (but boolean arrays can have type 1). You can read all about ⎕DR on the online help pages

Morten|Dyalog

Posts: 394
Joined: Tue Sep 09, 2008 3:52 pm

### Re: Determine if the argument is integer or string

In case this is helping:

Code: Select all
isString←{0 2∊⍨10|⎕DR ⍵}

PGilbert

Posts: 401
Joined: Sun Dec 13, 2009 8:46 pm

### Re: Determine if the argument is integer or string

I use ischar←{(⎕DR ⍵)∊80 160 320}
michaelk

Posts: 22
Joined: Wed Feb 10, 2010 8:38 am

### Re: Determine if the argument is integer or string

At present, numbers have an odd ⎕DR type, so this fork works:
isnum ← 2|⎕DR
However, we might be forced to break this rule in future when allocating the remaining codes: 4, 6 and 8.
JohnS|Dyalog

### Re: Determine if the argument is integer or string

alexeyv

Posts: 56
Joined: Tue Nov 17, 2015 4:18 pm

### Re: Determine if the argument is integer or string

isChar←{0=80|⎕DR ⍵}

norbertjurkiewicz84

Posts: 60
Joined: Mon Nov 01, 2010 7:26 pm