Uiua

From APL Wiki
Jump to navigation Jump to search


Uiua is a stack-based array language emphasizing tacit programming, designed by Kai Schmidt. Initially influenced strongly by BQN, Uiua has added original stack-based features and glyphs and moved to the boxed array model of SHARP APL and J. It also makes functions second-class rather than first-class to facilitate features that depend on the number of arguments functions take.

Overview

Uiua uses concatenative evaluation (a context-free grammar) with a right-to-left ordering as in Polish notation. The language supports tacit programming using stack manipulation primitives, and all complex functions must be defined this way as there is no explicit function form that allows local variables. Functions have a fixed number of input and output values, meaning the overloading of ambivalent functions is removed. Because of this, Uiua often splits APL primitives into two functions. Its primitives use Unicode glyphs including many not found in other languages. To avoid typing glyphs necessitating a keyboard layout containing these, each primitive can also be spelled using a name that consists of lowercase letters (user-defined names must have at least one uppercase letter). By default, the language formats source files when run to convert these names into the corresponding glyphs.

Like the SHARP APL family, Uiua supports only flat arrays with a homogeneous type, and has a dedicated box type for array nesting. However, arithmetic is pervasive as in the nested array model. Arithmetic also follows leading axis agreement, extended so that a length-1 axis is matched with an axis of any length by replicating along it (like the broadcasting system of Julia and NumPy). It supports character arithmetic as in BQN, as well as other primitives characteristic of BQN such as structural Under, Classify, and a Transpose that rotates the axes of its argument by one.

Primitives

Functions with unique glyphs

In Uiua, we can type in the name of the function or a part of it and when formatted, it will format the name to its corresponding Unicode Symbol, so that we don't have to use non-ASCII keyboards (or Alt-codes).

The tables below are based on Uiua version 0.12.0, with since-removed primitives taken out.

Stack

Work with the stack

Table of Stack functions in Uiua
Glyph Name Type Definition
. Duplicate Monadic 2-output function Duplicate the top value on the stack
, Over Dyadic 3-output function Duplicate the second-to-top value to the top of the stack
: Flip Dyadic 2-output function Swap the top two values on the stack
โ—Œ Pop Monadic 0-output function Discard the top stack value
โŸœ On Monadic modifier Call a function but keep its top argument on top of the stack
โค™ But Monadic modifier Call a function but keep its last argument on top of the stack
โคš With Monadic modifier Call a function but keep its top argument below the outputs on the stack
โŠธ By Monadic modifier Duplicate a function's last argument before calling it
ยจ Backward Monadic modifier Call a function with its arguments reversed
? Stack Noadic 0-output function Debug print all stack values without popping them
โธฎ Trace Monadic function Debug print the top value on the stack without popping it

Constants

Push a constant value onto the stack

Table of Constants in Uiua
Glyph Name Definition
ฮท Eta The number of radians in a quarter circle
ฯ€ Pi The ratio of a circle's circumference to its diameter
ฯ„ Tau The ratio of a circle's circumference to its radius
โˆž Infinity The biggest number

Monadic Pervasive

Operate on every element in an array

Table of Monadic Pervasive functions in Uiua
Glyph Name Definition
ยฌ Not Logical not
ยฑ Sign Numerical sign (1, ยฏ1, or 0)
ยฏ Negate Negate a number
โŒต Absolute value Get the absolute value of a number
โˆš Sqrt Take the square root of a number
โˆฟ Sine Get the sine of a number
โŒŠ Floor Round to the nearest integer towards ยฏโˆž
โŒˆ Ceiling Round to the nearest integer towards โˆž
โ… Round Round to the nearest integer

Dyadic Pervasive

Operate on every pair of elements in two arrays

Table of Dyadic Pervasive functions in Uiua
Glyph Name Definition Formats from:
= Equals Compare for equality =
โ‰  Not equals Compare for inequality !=
< Less than Compare for less than <
> Greater than Compare for greater than >
โ‰ค Less or equal Compare for less than or equal <=
โ‰ฅ Greater or equal Compare for greater than or equal >=
+ Add Add values +
- Subtract Subtract values -
ร— Multiply Multiply values *
รท Divide Divide values %
โ—ฟ Modulus Modulo values mod
โฟ Power Raise a value to a power pow
โ‚™ Logarithm Get the based logarithm of a number log
โ†ง Minimum/Logical And Take the minimum of two arrays (Can use for logical AND.) min
โ†ฅ Maximum/Logical Or Take the maximum of two arrays (Can use for logical OR.) max
โˆ  Atangent Take the arctangent of two numbers atan
โ„‚ Complex Make a complex number from imaginary and real parts com

Monadic Array

Operate on a single array

Table of Monadic Array functions in Uiua
Glyph Name Definition
โงป Length Get the number of rows in an array
โ–ณ Shape Get the dimensions of an array
โ‡ก Range Make an array of all natural numbers less than a number
โŠข First Get the first row of an array
โ‡Œ Reverse Reverse the rows of an array
โ™ญ Deshape Make an array 1-dimensional
ยค Fix Add a length-1 axis to an array
โ‹ฏ Bits Encode an array as bits (LSB-first)
โ‰ Transpose Rotate the shape of an array
โ Rise Get the indices into an array if it were sorted ascending
โ– Fall Get the indices into an array if it were sorted descending
โŠš Where Get indices where array values are not equal to zero
โŠ› Classify Assign a unique index to each unique element in an array
โ—ด Deduplicate Remove duplicate elements from an array
โ—ฐ Unique Get a mask of the first occurrences of items in an array
โ–ก Box Turn an array into a box

Dyadic Array

Operate on two arrays

Table of Dyadic Array functions in Uiua
Glyph Name Definition
โ‰ Match Check if two arrays are exactly the same
โŠŸ Couple Combine two arrays as rows of a new array
โŠ‚ Join Append two arrays end-to-end
โŠ Select Select multiple rows from an array
โŠก Pick Index a row or elements from an array
โ†ฏ Reshape Change the shape of an array
โ˜‡ Rerank Change the rank of an array's rows
โ†™ Take Take the first n elements of an array
โ†˜ Drop Drop the first n elements of an array
โ†ป Rotate Rotate the elements of an array by n
โฎŒ Orient Change the order of the axes of an array.
โ—ซ Windows The n-wise windows of an array
โ–ฝ Keep Discard or copy some rows of an array
โŒ• Find Find the occurrence's of one array in another
โˆŠ Member Check if each row of one array exists in another
โŠ— Indexof Find the first index of each row of one array in another
โŸ” Coordinate Find the first deep index of an array in another

Iterating Modifiers

Iterate and apply a function to an array or arrays

Table of Iterating Modifiers in Uiua
Glyph Name Type Definition
โˆต Each Monadic modifier Apply a function to each element of an array or arrays.
โ‰ก Rows Monadic modifier Apply a function to each row of an array or arrays.
โŠž Table Monadic 2-argument modifier Apply a function to each combination of rows of two arrays.
โš Inventory Monadic modifier Apply a function to each unboxed row of an array and re-box the results.
โฅ Repeat Monadic modifier Repeat a function a number of times
โข Do Dyadic modifier Repeat a function while a condition holds

Aggregating Modifiers

Apply a function to aggregate an array

Table of Aggregating Modifiers in Uiua
Glyph Name Definition
/ Reduce Apply a reducing function to an array.

For reducing with an initial value, see โˆง fold

โˆง Fold Apply a function to aggregate arrays.
\ Scan Reduce, but keep intermediate values
โŠ• Group Group elements of an array into buckets by index
โŠœ Partition Group sequential sections of an array
โ—น Triangle Apply a function to each shrinking row of an array

Inversion Modifiers

Work with the inverses of functions

Table of Inversion Modifiers in Uiua
Glyph Name Type Definition
ยฐ Un Monadic modifier Invert the behavior of a function
โœ Under Dyadic modifier Apply a function under another

๐ŸŒŽ Planet ๐Ÿช

Advanced stack manipulation

Table of Planet modifiers in Uiua
Glyph Name Type Definition
โˆ˜ Identity Monadic function Do nothing with one value
โ‹… Gap Monadic modifier Discard the top stack value then call a function
โŠ™ Dip Monadic modifier Temporarily pop the top value off the stack and call a function
โˆฉ Both Monadic 2-argument modifier Call a function on two sets of values
โŠƒ Fork Dyadic modifier Call two functions on the same values
โŠ“ Bracket Dyadic modifier Call two functions on two distinct sets of values

Other Modifiers

Table of Other Modifiers in Uiua
Glyph Name Type Definition
โ—‡ Content Monadic Modifier Unbox the arguments to a function before calling it
โฌš Fill Dyadic Modifier Set the fill value for a function
โจฌ Switch Dyadic modifier Call the function at the given index

External links


APL dialectsโ€ƒ[edit]
Maintained APL+Win โˆ™ APL2 โˆ™ APL64 โˆ™ APL\iv โˆ™ Aplette โˆ™ April โˆ™ Co-dfns โˆ™ Dyalog APL โˆ™ Dyalog APL Vision โˆ™ dzaima/APL โˆ™ GNU APL โˆ™ Kap โˆ™ NARS2000 โˆ™ Pometo โˆ™ TinyAPL
Historical A Programming Language โˆ™ A+ (A) โˆ™ APL# โˆ™ APL2C โˆ™ APL\360 โˆ™ APL/700 โˆ™ APL\1130 โˆ™ APL\3000 โˆ™ APL.68000 โˆ™ APL*PLUS โˆ™ APL.jl โˆ™ APL.SV โˆ™ APLGOL โˆ™ APLX โˆ™ Extended Dyalog APL โˆ™ Iverson notation โˆ™ IVSYS/7090 โˆ™ NARS โˆ™ ngn/apl โˆ™ openAPL โˆ™ Operators and Functions โˆ™ PAT โˆ™ Rowan โˆ™ SAX โˆ™ SHARP APL โˆ™ Rationalized APL โˆ™ VisualAPL (APLNext) โˆ™ VS APL โˆ™ York APL
Derivatives AHPL โˆ™ BQN โˆ™ CoSy โˆ™ ELI โˆ™ Glee โˆ™ I โˆ™ Ivy โˆ™ J โˆ™ Jelly โˆ™ K (Goal, Klong, Q) โˆ™ KamilaLisp โˆ™ Lang5 โˆ™ Lil โˆ™ Nial โˆ™ RAD โˆ™ Uiua
Overviews Comparison of APL dialects โˆ™ Timeline of array languages โˆ™ Timeline of influential array languages โˆ™ Family tree of array languages