Standard Library/stdlib

From J Wiki
Jump to navigation Jump to search
Overview | android | break | colib | compare | coutil | dates | debug | dir | dll | files | jade | jal | stdlib | strings | sysenv | text | unxlib

This script defines core utilities for the J standard library. Definitions are loaded into the z locale.

Definitions

A AND, abspath, adverb, anddf, android_exec_am, android_exec_host, android_getdisplaymetrics, andunzip, apply, assert
C CR, CRLF, calendar, cd, cdcb, cder, cderx, cdf, charsub, chopstring, clear, coclass, cocreate, cocurrent, codestroy, coerase, cofind, cofindv, cofullname, coinfo, coinsert, compare, coname, conames, conew, conjunction, conl, conouns, conounsx, copath, copathnl, copathnlx, coreset, costate, cut, cutLF, cutopen, cutpara, cuts
D DEL, Debug, datatype, dbctx, dbcut, dberm, dberr, dbg, dbhelp, dbinto, dbjmp, dblocals, dblxq, dblxs, dbnxt, dbout, dbover, dbq, dbr, dbret, dbrr, dbrrx, dbrun, dbs, dbsig, dbsq, dbss, dbst, dbstack, dbstk, dbstop, dbstopme, dbstopnext, dbstops, dbtrace, dbview, deb, debc, def, define, delstring, detab, dfh, dir, dircompare, dircompares, dirfind, dirpath, dirss, dirssrplc, dirtree, dirused, dlb, dltb, dltbs, do, dquote, dquotex, drop, dropafter, dropto, dtb, dtbs, dyad
E EAV, EMPTY, Endian, each, empty, endian, erase, every, evtloop, exit, expand
F FF, f2utf8, fappend, fappends, fapplylines, fboxname, fc, fcompare, fcompares, fcopynew, fdir, ferase, fetch, fexist, fexists, fgets, file2url, fixdotdot, fliprgb, fmakex, foldpara, foldtext, fpathcreate, fpathname, fputs, fread, freadblock, freadr, freads, frename, freplace, fsize, fss, fssrplc, fstamp, fstringreplace, ftype, fview, fwrite, fwritenew, fwrites
I IF64, IFBE, IFDEF, IFIOS, IFJHS, IFJNET, IFRASPI, IFUNIX, IFWIN, IFWINCE, IFWINE, IFWOW64, ic, install, inv, inverse, iospath, isatty, isotimestamp, isutf16, isutf8, items
J JB01, JBOXED, JCHAR, JCHAR2, JCHAR4, JCMPX, JFL, JINT, JLIB, JPTR, JSB, JSIZES, JSTR, JSTR2, JSTR4, JTYPES, jcwdpath, joinstring, jpath, jpathsep, jsystemdefs
L LF, LF2, leaf, list, ljust, load, loadd
N Note, nameclass, namelist, names, nc, nl, noun
O OR, on
R RUNJSCRIPT, require, rjust, rows, rplc, rplci
S SZI, script, scriptd, scripts, setalpha, setbreak, show, sign, sminfo, smoutput, sort, split, splitnostring, splitstring, ss, stderr, stdin, stdout, stringreplace, stringreplacei, symdat, symget, symset
T TAB, table, take, takeafter, taketo, timespacex, timestamp, timex, tmoutput, toCRLF, toHOST, toJ, todate, todayno, tolist, tolower, topara, toupper, tsdiff, tsrep, tstamp, type
U UNXLIB, ucp, ucpcount, undquote, unxlib, usleep, utf8, uucp
X XOR, xedit
B bind, boxopen, boxxopen, break, bx
G getalpha, getargs, getdate, getenv, getqtbin
H hfd, hostpathsep
M mema, memf, memr, memu, memw, monad
P pick
Q quote
V valdate, verb
W wcsize, weekday, weeknumber, weeksinyear, winpathsep

abspath v absolute file system path name
adverb n integer 1
apply v apply verb x to y
bx v indices of 1's in boolean (same as I.)
conjunction n integer 2
CR n carriage return character
CRLF n CR,LF pair
cutLF v cut text on LF, removing empties
Debug n debug flag, initialized to 0
def c : (explicit definition)
define a : 0 (explicit definition script form)
DEL n ascii 127 character
dfh v decimal from hex
do v name for ".
drop v name for }.
dyad n integer 4
each a each (&.>)
EAV n ascii 255 character
echo v output to session
EMPTY n empty matrix (i.0 0)
empty v return empty result (0 0$0)
erase v erase namelist
every a every (&>)
evtloop v initialize event loop
exit v name for 2!:55 (exit)
fetch v name for {::
FF n formfeed character
file2url v convert to file:// format
fixdotdot v fix up a/b/c/d/../../e/../f to a/b/f
fliprgb v flip between argb and abgr byte order
getalpha v get alpha channel
getargs v get args
getenv v cover for get environment variable, 2!:5
hfd v hex from decimal
inv a inverse (^:_1)
inverse a inverse (^:_1)
iospath v iOS file system path
isutf16 v if character string is valid UTF-16
isutf8 v if character string is valid UTF-8
items a name for ("_1)
leaf a leaf (L:0)
LF n linefeed character
LF2 n LF,LF pair
monad n integer 3
nameclass v name for 4!:0
namelist v name for 4!:1
names v formatted namelist
nc v name for 4!:0
noun n integer 0
on c name for @:
pick v pick (>@{)
rows a rows ("1)
script v load script, cover for 0!:0
scriptd v load script with display, cover for 0!:1
setalpha v set alpha channel
sign v sign (*)
sminfo v info box or output to session
smoutput v output to session
sort v sort up
stderr v name for 1!:2&5
stdin v name for 1!:1&3 with obverse stdout
stdout v name for 1!:2&4
TAB n tab character
take v name for {.
tmoutput v output to stdout
toCRLF v converts character strings to CRLF delimiter
toHOST v converts character strings to Host delimiter
toJ v converts character strings to J delimiter (linefeed)
tolist v convert boxed to list
tolower v convert text to lower case
toupper v convert text to upper case
type v object type
verb n integer 3

AND (verb)

logical and on packed bits in the 2s complement representation of integers

   4 AND 6
4
   AND 6 _1
6
   AND 6 _1 4
4

assert (verb)

assertion failure if 0 e. y e.g. 'invalid age' assert 0 <: age

bind (conjunction)

binds monadic verb to an argument creating a new verb that ignores its argument. e.g. fini=: sminfo bind 'finished...'

boxopen (verb)

Box argument if open.

e.g. if script=: 0!:0 @ boxopen, then either
  script 'work.ijs' or script <'work.ijs'

See also boxxopen.

Use cutopen to allow multiple arguments.

boxxopen (verb)

Box argument if open and not empty.

See also boxopen.

clear (verb)

Clear all names in locale, returns any names not erased.

Example:

clear 'myloc'

cutopen (verb)

Cut argument if open. This allows an open argument to be given where a boxed list is required.

Most common situations are handled. it is similar to boxopen, except allowing multiple arguments in the character string.

x is optional delimiters, default LF if in y, else blank
y is boxed or an open character array.

if y is boxed it is returned unchanged, otherwise:
if y has rank 2 or more, the boxed major cells are returned
if y has rank 0 or 1, it is cut on delimiters in given in x, or
  if x not given, LF if in y else blank. Empty items are deleted.

e.g. if script=: 0!:0 @ cutopen, then

   script 'work.ijs util.ijs'

datatype (verb)

unicode/unicode4 are literal2/literal4 in J dictionary

Endian (verb)

Given a literal representation of a machine word in little-endian format (least significant byte first), arranges the literal in the native endian format. In other words, on a little-endian architecture such as i386 this is an identity function. On a big-endian architecture such as ARMv6 this would reverse the literal.

expand (verb)

form: boolean expand data

feature tests

IF64 n 1 on 64 bit architectures, 0 on 32 bit architectures.
IFBE n 1 on big endian architectures, 0 on little endian architectures.
IFIOS n 1 on iOS machines, 0 otherwise
IFJHS n 1 in the JHS IDE, 0 otherwise
IFJNET n 1 in a JNET IDE session, 0 otherwise
IFRASPI n 1 on a raspberry pi machine, 0 otherwise
IFUNIX n 1 on a unix or linux machine (or virtual machine), 0 otherwise
IFWIN n 1 on a windows machine, 0 otherwise
IFWINCE n 1 for windows embedded compact machines, 0 otherwise
IFWINE n 1 under the WINE windows emulator, 0 otherwise
IFWOW64 n 1 for certain 64 bit systems which might run windows 32 bit executables, 0 otherwise

isatty (verb)

Test whether a file descriptor refers to a terminal

FILE_TYPE_CHAR=: 2
STD_INPUT_HANDLE=: _10
STD_OUTPUT_HANDLE=: _11
STD_ERROR_HANDLE=: _12

JTYPES (noun) and JSIZES (noun)

JTYPES lists some result values which might be obtained from the 3!:0 foreign and JSIZES contains the corresponding size (in bytes) needed to represent a value of that type on the currently running architecture.

These result values are also given labels: JB01 (bit type), JBOXED (boxed type - the size here is the size of a machine pointer), JCHAR (literal type), JCHAR2 (wide character or ucs-16 encoding of text), JCHAR4 (ucs-32 encoding of test), JCMPX (complex number), JFL (IEEE-754 floating point number), JINT (integer), JPTR (same as JINT), JSB (symbols).

JLIB (noun)

Version number of the current instance stdlib

JSTR (noun), JSTR2 (noun) and JSTR2 (noun)

_1 followed by the corresponding JCHAR, JCHAR2 or JCHAR4 value for convenience when reading null terminated strings from memory using memr.

list (verb)

syntax: {width} list data accepts data as one of:

 boxed list
 character vector, delimited by CR, LF or CRLF; or by ' '
 character matrix

formats in given width, default screenwidth

nl (verb)

Selective namelist.

Syntax:

[mp] nl sel

 sel: one or more integer name classes, or a name list.
       if empty use: 0 1 2 3.
 mp: optional matching pattern. If mp contains '*', list names
       containing mp, otherwise list names starting mp. If mp
       contains '~', list names that do not match.

e.g. 'f' nl 3 - list verbs that begin with 'f'
     '*com nl - list names containing 'com'

Note (verb)

Monadic form:

This enables multi line comments without repeated NB.-and requires a right parenthesis in the first column of a line to close. The right argument may be empty, numeric, text, or any noun. Reads and displays the comment text but always returns an empty character string so the comment is not duplicated on screen.

The right argument can number or describe the notes, e.g.

  Note 1     Note 2.2   or    Note 'The special case' etc.

Dyadic form:

This permits a single consist form of comment for any lines which are not tacit definitions. The left argument must be a noun. The function code displays the right argument and returns the left argument.

Example:

Note 1
... note text
)

OR (verb)

Logical or on packed bits in a 2s complement representation of integers.

   OR/~ 0 1 2 4
0 1 2 4
1 1 3 5
2 3 2 6
4 5 6 4
   OR 0 1 2 4
7

RUNJSCRIPT (noun)

0 (unless defined as 1 in some other script).

SZI (noun)

Number of bytes to represent a J integer (or machine pointer). The same value as JSIZES{~JTYPES i.JINT

split (verb)

Split head from tail.

Example:

   split 'abcde'
┌─┬────┐
│a│bcde│
└─┴────┘
   2 split 'abcde'
┌──┬───┐
│ab│cde│
└──┴───┘

table (adverb)

table - function table (adverb)

Example:

   1 2 3 * table 10 11 12 13
┌─┬───────────┐
│*│10 11 12 13│
├─┼───────────┤
│1│10 11 12 13│
│2│20 22 24 26│
│3│30 33 36 39│
└─┴───────────┘

timespacex (verb)

Time and space for expressions.

Syntax:

[repetitions] timespacex 'expression'

Example:

   10 timespacex &> 'q:123456787';'3^10000x'
0.005 58432
0.061 52352

See also timex.

timex (verb)

Time expressions.

Syntax:

[repetitions] timex 'expression'

See also timespacex.

ucp (verb)

This is 7-bit ascii (if possible) or literal2 with UTF-16 encoding (compare uucp).

inverse is utf8.

ucpcount (verb)

Counts number of literal2 in a string when converted to UTF-16

A unicode codepoint has one or two literal2, this gives the number of literal2, not unicode codepoint

usleep (verb)

linux max value around 33 minutes
windows minimum resolution in milliseconds.

utf8 (verb)

Convert string to literal with UTF-8 encoding

Inverse of ucp.

uucp (verb)

Convert text to literal2 with UTF-16 encoding

This is always literal2 (compare ucp)