Vocabulary/adot

From J Wiki
Jump to: navigation, search

>> <<   Back to: Vocabulary Thru to: Dictionary

a. Alphabet Noun

The alphabet of the J language — a built-in list of all bytes

i.e. atoms of type: character with byte precision.

   $ a.
256

Bytes 0 to 127 are (mostly) the ASCII characters.

Bytes in J serve two purposes:

  • To store ASCII characters (using byte indexes 32 to 127)
  • To store 8-bit bytes for interacting with external hardware and software.

Though a. is a simple list, displaying it is a challenge because only half of it contains displayable ASCII characters, and a quarter of the ASCII codes are control characters that mess up the display. See Screen Output and Input for details.

Note: Unicode characters may be stored in character nouns of unicode precision. Bytes using UTF-8 encoding are not automatically recognized as representing Unicode characters; you must explicitly convert them to unicode precision using (u:).


Common uses

1. Find the ASCII code(s) of any letter (or string). This converts from characters to numbers

   a. i. 'A'
65
   a. i. 'AZaz09'
65 90 97 122 48 57

2. Find the letter for a given ASCII code

   65 { a.
A

3. Make lists of the ASCII roman alphabet, upper- and lowercase, plus the number digits

   a. {~ 65+i.26
ABCDEFGHIJKLMNOPQRSTUVWXYZ
   a. {~ 97+i.26
abcdefghijklmnopqrstuvwxyz
   a. {~ 48+i.10
0123456789

See the stdlib verbs: tolower and toupper for their use of this construct.

4. Translate one set of characters to another

   lc =: 'abcdefghijklmnopqrstuvwxyz'
   uc =: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
   tolow =: (lc,a.) {~ (uc,a.) i. ]   NB. a. fills in the other characters
   tolow 'Ike Newton'
ike newton

Use These Combinations

Combinations using  a. y that have exceptionally good performance include:

What it does Type;

Precisions;
Ranks

Syntax Variants;

Restrictions

Benefits;

Bug Warnings

Bitwise operations on bytes byte u&.(a.&i.) y (u y) -: u"0 y avoids conversion to integer
(m b.)/&.(a.&i.) y

x (m b.)&.(a.&i.) y

m is 16 to 31

CategoryVoc CategoryVocConstant