Built-ins

nametypewhat it does
+Num a => a -> a -> a

Plus.

−Num a => a -> a -> a

Minus. Written spaced (3 − 1): a minus touching a number makes it negative.

×Num a => a -> a -> a

Times, drawn as the times sign.

^Num a => a -> a -> a

Power, spaced: x ^ n. An exponent written touching a value (x²) is a literal superscript instead; touching a function it is function power (see p_ower).

m̲axNum a => a -> a -> a

The larger of two numbers; 'm̲ax r̲/ is the largest item.

m̲inNum a => a -> a -> a

The smaller of two numbers.

÷Num a => a -> a -> Float

Divide, drawn as the division sign; the result is a Float.

d̲ivInt -> Int -> Int

Whole-number division, in maths order: 7 d̲iv 2 is 3.

m̲odInt -> Int -> Int

Remainder, in maths order: 7 m̲od 3 is 1 (the left argument is divided by the right).

n̲egNum a => a -> a

Negate.

a̲bsNum a => a -> a

Absolute value.

f̲loorNum a => a -> Int

Round down to an Int.

c̲eilingNum a => a -> Int

Round up to an Int.

e̲xpNum a => a -> Float

e to a power.

l̲ogNum a => a -> Float

Natural logarithm.

f̲loatNum a => a -> Float

An Int as a Float.

s̲inNum a => a -> Float

Sine.

c̲osNum a => a -> Float

Cosine.

a̲tanNum a => a -> Float

Arctangent, the angle whose tangent is the argument.

p̲iUnit -> Float

The constant pi. It is niladic, so it is applied to @.

=(Eq a, Truthy b) => a -> a -> b

Equal (any scalar type).

≠(Eq a, Truthy b) => a -> a -> b

Not equal.

<(Ord a, Truthy b) => a -> a -> b

Less than (numbers and characters).

>(Ord a, Truthy b) => a -> a -> b

Greater than.

≤(Ord a, Truthy b) => a -> a -> b

At most.

≥(Ord a, Truthy b) => a -> a -> b

At least.

e̲q~(Num a, Truthy b) => a -> a -> b

Equal within a small tolerance, for Floats.

∧(Truthy a, Truthy b) => a -> a -> b

And.

∨(Truthy a, Truthy b) => a -> a -> b

Or.

n̲ot(Truthy a, Truthy b) => a -> b

Not.

p̲rint!a -> a

Print a value and give it back (the ! marks an effect).

r̲oll!Int -> Int

A random whole number from 1 to n for every n (seeded here, so the example repeats).

i̲da -> a

The value itself. As the left function of a fork it gives the argument unchanged: [i̲d F G] x is (i̲d x) F (G x), that is x F (G x) (a hook); [i̲d − n̲eg] 5 is 5 − (n̲eg 5).

l̲efta -> b -> a

The left argument. In a dyadic train, x [l̲eft F r̲ight] y is x F y, so the tacks pick an argument for each side of a fork.

r̲ighta -> b -> b

The right argument.

⎕AChar

The alphabet, the uppercase letters: a system value, written without an underline and read where it is used.

⎕DChar

The digits, as characters.

⎕AVChar

The atomic vector: every character, ASCII 0 to 127 (source is ASCII), so a character's code is its place in it, less one.

⎕IOInt

The index origin: always 1 (there is no setting).

⎕TSInt

The local time stamp: year, month, day, hour, minute, second and millisecond, read each time it is used (a host without a clock reports error[no−clock]). Shown here by its shape, since it changes.

⎕D̲LNum a => a -> Float

Wait the given seconds (an Int or a Float); the result is the seconds actually waited, at least those asked for. A negative delay is an error.

⎕U̲CSChar -> Int

The code of each character, keeping the shape. Codes go back to characters with ⎕U̲CHAR.

⎕U̲CHARInt -> Char

The character of each code, 0 to 127; another code is an error.

⎕N̲PUTChar -> Char -> Int

Write the text on the left to the file on the right (made, with its directories, if missing); how many characters it wrote.

⎕N̲GETChar -> Char

A file's text.

⎕R̲EADUnit -> Char

A line typed at the keyboard (here, the line "a typed line").

⎕E̲RRChar -> Char

Write a line to standard error (red in the live demo), and give the text back.

⎕P̲ANICChar -> a

Stop the program with error[panic] and the text as its message (what @ p̲anic< "..." writes). Its result has any type, so it stands where any value may.

⎕S̲IGNALChar -> Char -> a

Stop with an error of your own: the code on the left names the error class, as xetal's own codes do (lowercase letters, digits and hyphens), and the text on the right is its message. Uncaught, it ends the program with exit status 1, like any error. Its result has any type.

⎕W̲ARNa -> Box Char -> a

An error the program can go on from (a warning): the left argument is the value to go on with, of the type of the place the warning stands in, and the right is the code and the message, a strand of two strings. Uncaught, a warning is an error like a signal. A handler that answers ⎕C̲ONTINUE makes the program go on from the warning with that value; the other answers unwind as they do for any error.

⎕T̲RAP(Unit -> a) -> (Error -> Outcome a) -> a

Run the body; on any error, call the handler with it. The trap's value is the body's, or what the handler recovers with.

⎕E̲NSURE(Unit -> a) -> (Unit -> b) -> a

Run the body, then the cleanup (a function of @), whether the body gave a value or stopped with an error; the body's value, or its error going on. The f̲inally< macro writes it.

⎕R̲ECOVERa -> Outcome a

The handler's answer: the trap's value is this one, of the body's type.

⎕R̲ETRYError -> Outcome a

The handler's answer: run the body again. After 1000 runs the trap gives up with error[retry-limit].

⎕H̲ALTError -> Outcome a

The handler's answer: the error goes on as it was, from where it was raised. A handler for one kind of error halts on the others.

⎕C̲ONTINUEError -> Outcome a

The handler's answer to a warning: go on from it, with its value. The handler runs where the warning was raised, before any cleanup between it and the trap, so nothing has been undone. Halting a warning passes it outward still a warning; continuing an error raised by ⎕S̲IGNAL is error[not-resumable], since it has no value to go on with.

⎕E̲CODEError -> Char

The code of a caught error (mine of error[mine]).

⎕E̲MESSAGEError -> Char

The message of a caught error.

⎕E̲WHEREError -> Char

Where a caught error was raised, as errors print it: the span of source text, start..end.

⎕T̲EUnit -> Int

The terminal's facts: rows, columns, 1 when output is a terminal, 1 when it does screen control (here, output to a file).

⎕K̲EYUnit -> Key

One key, without Enter, as a Key (here, the key a): the terminal reads it raw; in the live demo the program waits in the terminal pane. Keys are named in the Terminal library (ᵗ⁼u̲se< "Terminal", then ᵗUP, ᵗENTER, ...) and compare with =.

⎕K̲CHARKey -> Char

A printing key's character, or nothing for a named key such as Up.

⎕K̲NAMEDInt -> Key

Named key n (1 to 11: Up, Down, Left, Right, Enter, Escape, Backspace, Tab, Delete, Home, End), for the Terminal library, which names them.

⎕V̲IEWChar -> Box Char

Source text as the editor and the HTML export see it: a matrix of boxed texts, a row per run of one class, two columns: the decorated text (underlines drawn, as xetal render shows it) and the class (builtin, userfunc, libfunc, variable, lambdaarg, number, exponent, string, symbol, quote, punct, unit, comment, space, macro, error). A program colors code in a picture or a page from it, so the coloring never drifts from the language.

⎕L̲ISTChar -> Char -> Box Char

A top-level list of strings in a TOML file, as boxed texts: "file" ⎕L̲IST "name". Strings only, and nothing in the file is run; a missing list, a value that is not a list of strings, or a file that is not TOML is error[bad-table], naming the file and the key.

⎕T̲ABLEBox Char -> Box Char -> Box Char

A table of tables in a TOML file as a matrix of texts whose rows and columns follow two top-level lists: ("file" "name") ⎕T̲ABLE ("rows" "cols"); a cell the file does not have is the empty text. The Rosetta stone reads its idioms this way: ("data.toml" "source") ⎕T̲ABLE ("idioms" "languages").

⎕E̲VENTUnit -> Event

The next event from the host, as an Event: a tick of the clock, a pointer down, move, up or click, a key, or end when there are no more. The command line reads them one per line from standard input or −−events FILE (tick 0.016, down 120 80, key Up); in the live demo the page gives ticks on each frame and the keys pressed. A program that draws loops on them: e ← ⎕E̲VENT @, update, ⎕S̲HOW, again, until ⎕E̲KIND e is end. Here the next event is down 120 80.

⎕E̲KINDEvent -> Char

What kind an event is, as text: tick, down, move, up, click, key, choose (a choice in the host's controls, ⎕E̲AT giving which list and which item) or end.

⎕E̲ATEvent -> Float

An event's numbers: x y for a pointer, the seconds since the last tick for a tick, the list and the item for a choice, none for a key or the end.

⎕E̲KEYEvent -> Key

A key event's key (⎕K̲CHAR reads its character); an error for the other kinds. Here the events are down 120 80 then key a.

⎕C̲OLORInt -> Color

Color n (1 to 8: black, red, green, yellow, blue, magenta, cyan, white), for the Terminal library, which names them (ᵗRED).

⎕F̲GColor -> Char -> Char

Text in a foreground color: the text wrapped in the codes a terminal (or the live demo's grid) colors it with; print it to see it. Here, its length: five characters on each side of the text.

⎕B̲GColor -> Char -> Char

Text on a background color, as []F_G does the foreground.

⎕B̲OLDChar -> Char

Text in bold (wrapped in its codes, as []F_G).

⎕A̲TInt -> Char -> Char

Text placed at a row and a column (1-origin), for a program that draws a screen: the code moving the cursor there, then the text.

⎕C̲LSUnit -> Char

The text that clears the screen and moves the cursor home; print it.

f̲ormata -> Char

A value as the text it prints as.

n̲umbersChar -> Float

The numbers in a text, as Floats.

⎕R̲EJECTChar -> Char -> Char

Fail the macro call being expanded: the left text is a code and where to report it (call, left or right), the right text the message.

⎕S̲TATEMENTTruthy a => Unit -> a

Whether the call being expanded stands as a statement of its own.

⎕F̲ILEUnit -> Char

The file the call being expanded is written in (@ f̲ile< @).

⎕L̲INEUnit -> Int

The line the call being expanded is written on (@ l̲ine< @).

⎕I̲NCLUDEChar -> Char

The text of a file, by a path relative to the file the call being expanded is written in (@ i̲nclude< "data.txt").

⎕C̲FGTruthy a => Char -> a

Whether a configuration fact holds: the platform (cli or web) or a flag set with xetal −−cfg NAME (@ c̲fg< "web").

⎕G̲RIDEq a => a -> Char

An array as a picture, returned as SVG text: a vector as one row of cells, a matrix as a grid, a rank-3 array as frames shown in turn. Numbers that are all 0 or 1 draw their 1s dark; other numbers are colored from the least (dark purple) to the greatest (yellow); characters are drawn in their cells. A frame of more than 64 by 64 numbers is drawn as an image, a pixel per cell.

⎕P̲ATHNum a => a -> Char

Points as a picture, returned as SVG text: 2 rows, x over y, joined in order and fitted into a 400-pixel picture with y pointing up; a rank-3 array is frames of paths shown in turn.

⎕S̲HOWChar -> Char

Show a picture, and return it: the command line writes it to a numbered file (−−draw DIR, else XETAL̲DRAW, else the current directory), the browser shows it beside the program.

s̲hapea -> Int

The length of each axis.

t̲allya -> Int

How many items along the first axis: the rows of a matrix. With a subscript it counts along that axis only when the result keeps a rank the rule allows: t̲ally₂ would drop two ranks, an error.

r̲angeInt -> Int

The numbers 1 to n.

o̲ffsetsInt -> Int

The numbers 0 to n - 1.

f̲irsta -> a

The first item along the first axis: the first row. With a subscript, along that axis: f̲irst₂ is the first column.

r̲avela -> a

Every item as one vector, row after row. With axis 2, column after column.

r̲eshapeInt -> a -> a

The items of the right argument, taken in order and repeated as needed, into the shape on the left.

t̲akeInt -> a -> a

The first n items (the last n for a negative n) along the first axis, or along the subscript's axis.

d̲ropInt -> a -> a

All but the first n items (the last n for a negative n), along the first axis or the subscript's.

s̲electInt -> a -> a

The items at the given positions (from 1) along the first axis, or along the subscript's axis.

r̲eplicateTruthy a => a -> b -> b

Replicate: each item (each row of a matrix) repeated as many times as its count on the left, so a 0 drops it and a mask of 1s and 0s keeps the items where it is 1; one count extends to every item, and with a subscript the counts go along that axis. A negative count is an error.

c̲ata -> a -> a

Join along the first axis, or with a subscript along that axis of both arguments: c̲at₂ puts matrices side by side. The other axes must match; a single value extends, and an argument of one rank less is one row (or, along axis 2, one column).

r̲/(a -> a -> a) -> a -> a

Reduce: combine the items along the first axis with the function, from the right ('− r̲/ 1 2 3 is 1 - (2 - 3)). On a matrix that combines the rows. A subscript picks the axis; two digits reduce both axes.

s̲\(a -> a -> a) -> a -> a

Scan: every running reduce, the last being the whole reduce. On a matrix down the rows; with a subscript along that axis.

e̲ach(a -> b) -> a -> b

Apply a function to every item. Given a dyadic function it pairs items of two arrays.

m̲ap(a -> b) -> a -> Box b

Map: the function on each item, every result boxed, so the function may give an array (e_ach wants one value per item).

t̲able(a -> b -> c) -> a -> b -> c

Every pairing of an item on the left with one on the right (APL's outer product): the result has both shapes.

i̲nner(a -> b -> c) -> (c -> c -> c) -> a -> b -> c

Inner product: A '+ '× i̲nner B is matrix multiplication (the last axis of A with the first of B).

c̲ompose(a -> b) -> (b -> c) -> a -> c

'f 'g c̲ompose x is f applied to g applied to x; the atop train [f g] x is the same.

s̲wap(a -> b -> c) -> b -> a -> c

x 'f s̲wap y is y f x: the arguments swapped.

p̲ower(a -> a) -> Int -> a -> a

n 'f p̲ower x applies f to x n times; f̲^n is the same with a literal count.

i̲ndexOfEq a => a -> a -> Int

Where each item of the right argument is first found among the items of the left, from 1; one past the end when it is not there.

m̲ember?(Eq a, Truthy b) => a -> a -> b

Whether each item of the left is among the items of the right.

m̲atch(Eq a, Truthy b) => a -> a -> b

Whether both sides have the same shape and equal items (APL's match): one result for the whole arrays, where = compares item by item. The same items in another shape do not match.

u̲niqueEq a => a -> a

The items without repeats, in first-seen order.

s̲ortOrd a => a -> a

The items in ascending order (the rows of a matrix, compared in order); with a subscript, sorted along that axis.

g̲radeOrd a => a -> Int

The positions that would sort the items: (g̲rade v) s̲elect v is s̲ort v.

w̲hereTruthy a => a -> Int

The positions of the 1s in a vector.

e̲nclosea -> Box a

Enclose: the whole value as one item, a box, so arrays can be items of other arrays; a strand of strings encloses each string. A nested array prints in frames, as APL2's DISPLAY draws them (shown here as xetal −−ascii draws them; a terminal gets box characters): an arrow along the top, a down arrow for each leading axis, and a mark at the bottom for what it holds (~ numbers, e boxes).

d̲iscloseBox a -> a

Disclose: what a box holds. It opens one box (select one item first).

d̲isplaya -> Char

Display: any value as APL2's DISPLAY draws it, as a character matrix, flat arrays framed too: an arrow along the top, a down arrow for each leading axis, and a mark at the bottom for what it holds (~ numbers, a plain line characters, e boxes); a simple scalar is itself. xetal −−box prints every array result this way (shown here as xetal −−ascii draws them).

p̲artitionTruthy a => a -> b -> Box b

Partition: the items (rows of a matrix) cut into pieces by the keys on the left, one per item: a new piece starts where the key goes up, and an item with key 0 is left out, so a mask of 1s and 0s cuts out the runs of 1s. Each piece is a box; one key extends to every item.

e̲ncodeInt -> Int -> Int

Encode: the digits of a number in the radix on the left, most significant first (APL's encode). Radixes may differ from digit to digit (hours, minutes, seconds), a radix of 0 takes all that is left, and digits beyond the radix are dropped. A vector gives one column of digits per item.

d̲ecodeNum a => a -> a -> a

Decode: the number whose digits, in the radix on the left, are on the right (APL's decode), the inverse of e̲ncode. One radix extends to every digit; a matrix gives one number per column. It is Horner's rule on any numbers, radix and digits of one type, so on Floats x d̲ecode r̲ev c is the polynomial with coefficients c (lowest first) at x.

r̲eva -> a

Reverse the order of the items along the first axis (the rows of a matrix), or along the subscript's axis.

o̲-Int -> a -> a

Rotate: shift the items round by n (APL's rotate); positive n moves items toward the front. Along the first axis by default, so a matrix's rows move; with a subscript along that axis. A list of amounts gives one result per amount.

o̲\a -> a

Transpose: reverse the order of the axes, so a matrix's rows become its columns; a vector or a single value is unchanged. A subscript of two axes swaps just those two.

t̲ransposeInt -> a -> a

Permute the axes: the left argument lists each axis once, and axis i of the right argument becomes the axis that item i of the list names (APL's dyadic transpose), so 3 1 2 moves axis 1 to the end. Listing the axes in reverse is o̲\.