Uiua
9 min read
Stack-based array programming language with a unique glyph-based syntax. Each built-in function is a single Unicode character. Code is written right-to-left. Runs in the browser via WebAssembly.
Core concepts
• Stack-based: Functions consume from and push to an implicit stack
• Array-oriented: All values are arrays; scalar = rank-0 array
• Tacit/point-free: Functions compose without naming arguments
• Glyphs: Built-ins are single Unicode chars (e.g. + add, ⇌ reverse, △ shape)
Basic syntax
uiua
# Numbers push to the stack
1 2 3 # stack: [1, 2, 3]
# Add consumes two, pushes one
+ 1 2 # → 3
# Arrays
[1 2 3 4 5]
# String
"hello"
# Arithmetic (right-to-left reads as left-to-right math)
× 2 + 1 3 # (1 + 3) × 2 = 8
Common glyphs
Algorithm
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
derivative | ∂ | `` | 1 | Calculate the derivative of a mathematical expression |
fft | `` | 1 | 1 | Run the Fast Fourier Transform on an array |
geometric | ⩜ | `` | 1 | Convert an operation to be in geometric algebra |
hsv | `` | 1 | 1 | Convert a color array from RGB to HSV |
integral | ∫ | `` | 1 | Calculate an antiderivative of a mathematical expression |
oklch | `` | 1 | 1 | Convert a color array from RGB to Oklch |
path | `` | `` | 2 | Find the shortest path between two things |
recur | `` | `` | 1 | Execute a recursive or tree algorithm |
regex | `` | 2 | 1 | Match a regex pattern |
Arguments
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
above | ◠ | `` | 1 | Keep all arguments to a function before the outputs |
backward | ˜ | `` | 1 | Call a function with its arguments swapped |
below | ◡ | `` | 1 | Keep all arguments to a function after the outputs |
both | ∩ | `` | 1 | Call a function on two sets of values |
bracket | ⊓ | `` | 1 | Call two functions on two distinct sets of values |
by | ⊸ | `` | 1 | Call a function but keep its last argument after its outputs |
dip | ⊙ | `` | 1 | Skip the first argument and call a function on later arguments |
duplicate | . | 1 | 2 | Duplicate the top value on the stack |
flip | : | 2 | 2 | Swap the top two values on the stack |
fork | ⊃ | `` | 1 | Call two functions on the same values |
gap | ⋅ | `` | 1 | Discard the first argument then call a function |
identity | ∘ | 1 | 1 | Do nothing with one value |
off | ⤚ | `` | 1 | Call a function but keep its first argument after its outputs |
old reach | 𝄐 | `` | 1 | Old reach |
on | ⟜ | `` | 1 | Call a function but keep its first argument before its outputs |
pop | ◌ | 1 | 0 | Discard the first argument |
reach | ∪ | `` | 1 | Call a function skipping the second argument |
self | ˙ | `` | 1 | Call a function with the same array as all arguments |
with | ⤙ | `` | 1 | Call a function but keep its last argument before its outputs |
Command
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
&invk | `` | 1 | 0 | Invoke a path with the system's default program |
&runc | `` | 1 | 3 | Run a command and wait for it to finish |
&runi | `` | 1 | 1 | Run a command and wait for it to finish |
&runs | `` | 1 | 3 | Run a command with streaming IO |
Comptime
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
comptime | `` | `` | 1 | Run a function at compile time |
quote | `` | 0 | 1 | Convert a string into code at compile time |
Constant
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
eta | η | 0 | 1 | The number of radians in a quarter circle |
infinity | ∞ | 0 | 1 | The biggest number |
pi | π | 0 | 1 | The ratio of a circle's circumference to its diameter |
tau | τ | 0 | 1 | The ratio of a circle's circumference to its radius |
Debug
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
args | ? | 0 | 0 | Debug print all arguments without consuming them |
dump | `` | 0 | 0 | Preprocess and print all arguments without popping them |
DyadicArray
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
base | ⊥ | 2 | 1 | Get the base digits of a number |
couple | ⊟ | 2 | 1 | Combine two arrays as rows of a new array |
drop | ↘ | 2 | 1 | Drop the first n rows of an array |
find | ⌕ | 2 | 1 | Find the occurrences of one array in another |
indexin | ⨂ | 2 | 1 | Find the first index in an array of each row of another array |
indexof | ⊗ | 2 | 1 | Find the first index of each row of one array in another |
join | ⊂ | 2 | 1 | Append two arrays end-to-end |
keep | ▽ | 2 | 1 | Discard or copy some rows of an array |
mask | ⦷ | 2 | 1 | Mask the occurrences of one array in another |
match | ≍ | 2 | 1 | Check if two arrays are exactly the same |
memberof | ∊ | 2 | 1 | Check if each row of one array exists in another |
orient | ⤸ | 2 | 1 | Change the order of the axes of an array |
pick | ⊡ | 2 | 1 | Index a row or elements from an array |
rerank | ☇ | 2 | 1 | Change the rank of an array's rows |
reshape | ↯ | 2 | 1 | Change the shape of an array |
rotate | ↻ | 2 | 1 | Rotate the elements of an array by n |
select | ⊏ | 2 | 1 | Select multiple rows from an array |
take | ↙ | 2 | 1 | Take the first n rows of an array |
windows | ◫ | 2 | 1 | The n-wise windows of an array |
DyadicPervasive
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
add | + | 2 | 1 | Add values |
atangent | ∠ | 2 | 1 | Take the arctangent of two numbers |
complex | ℂ | 2 | 1 | Make a complex number |
divide | ÷ | 2 | 1 | Divide values |
equals | = | 2 | 1 | Compare for equality |
greater or equal | ≥ | 2 | 1 | Compare for greater than or equal |
greater than | > | 2 | 1 | Compare for greater than |
less or equal | ≤ | 2 | 1 | Compare for less than or equal |
less than | < | 2 | 1 | Compare for less than |
maximum | ↥ | 2 | 1 | Take the maximum of two arrays |
minimum | ↧ | 2 | 1 | Take the minimum of two arrays |
modulo | ◿ | 2 | 1 | Modulo values |
multiply | × | 2 | 1 | Multiply values |
not equals | ≠ | 2 | 1 | Compare for inequality |
or | ∨ | 2 | 1 | Logical OR and greatest common divisor |
power | ⁿ | 2 | 1 | Raise a value to a power |
subtract | - | 2 | 1 | Subtract values |
Encoding
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
apng | `` | 2 | 1 | Encode an array of image frames in an APNG-encoded byte array |
audio | `` | 3 | 1 | Encode audio into a byte array |
binary | `` | 1 | 1 | Encode an array into a compact binary representation |
bytes | `` | 2 | 1 | Convert a value to a byte representation |
compress | `` | 2 | 1 | Compress bytes according to some algorithm |
csv | `` | 1 | 1 | Encode an array into a CSV string |
gif | `` | 2 | 1 | Encode an array of image frames in a GIF-encoded byte array |
graphemes | `` | 1 | 1 | Convert a string to a list of UTF-8 grapheme clusters |
img | `` | 2 | 1 | Encode an image into a byte array with the specified format |
json | `` | 1 | 1 | Encode an array into a JSON string |
layout | `` | 2 | 1 | Render text into an image array |
parse | ⋕ | 1 | 1 | Parse a string as a number |
utf₈ | `` | 1 | 1 | Convert a string to UTF-8 bytes |
voxels | `` | 1 | 1 | Project a voxel array to an image |
xlsx | `` | 1 | 1 | Encode an array into XLSX bytes |
Env
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
&args | `` | 0 | 1 | Get the command line arguments |
&raw | `` | 1 | 0 | Set the terminal to raw mode |
&ts | `` | 0 | 1 | Get the size of the terminal |
&var | `` | 1 | 1 | Get the value of an environment variable |
Environment
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
arch | `` | 0 | 1 | Get the current architecture |
dllext | `` | 0 | 1 | Get the DLL extension for the current platform |
exeext | `` | 0 | 1 | Get the executable extension for the current platform |
numprocs | `` | 0 | 1 | Get the number of processors on the current system |
os | `` | 0 | 1 | Get the current operating system |
osfamily | `` | 0 | 1 | Get the current operating system family |
pathsep | `` | 0 | 1 | Get the primary path separator for the current platform |
Ffi
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
&ffi | `` | 2 | 1 | Call a foreign function interface |
&malloc | `` | 1 | 1 | Allocate memory for the given number of bytes and return a pointer to it |
&memcpy | `` | 2 | 1 | Copy data from a pointer into an array |
&memfree | `` | 1 | 0 | Free a pointer |
&memset | `` | 3 | 0 | Write data from an array into a pointer |
Filesystem
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
&cd | `` | 1 | 0 | Change the current directory |
&fc | `` | 1 | 1 | Create a file and return a handle to it |
&fde | `` | 1 | 0 | Delete a file or directory |
&fe | `` | 1 | 1 | Check if a file, directory, or symlink exists at a path |
&fif | `` | 1 | 1 | Check if a path is a file |
&fld | `` | 1 | 1 | List the contents of a directory |
&fmd | `` | 1 | 0 | Create a directory |
&fo | `` | 1 | 1 | Open a file and return a handle to it |
&frab | `` | 1 | 1 | Read all the contents of a file into a byte array |
&fras | `` | 1 | 1 | Read all the contents of a file into a string |
&ftr | `` | 1 | 0 | Move a file or directory to the trash |
&fwa | `` | 2 | 0 | Write the entire contents of an array to a file |
InversionModifier
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
anti | ⌝ | `` | 1 | Invert the behavior of a function, treating its first argument as a constant |
obverse | ⌅ | `` | 1 | Define the various inverses of a function |
un | ° | `` | 1 | Invert the behavior of a function |
under | ⍜ | `` | 1 | Operate on a transformed array, then reverse the transformation |
IteratingModifier
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
do | ⍢ | `` | 1 | Repeat a function while a condition holds |
fold | ∧ | `` | 1 | Apply a function to aggregate arrays |
reduce | / | `` | 1 | Apply a reducing function to an array |
repeat | ⍥ | `` | 1 | Repeat a function a number of times |
scan | \ | 1 | 1 | Reduce, but keep intermediate values |
Map
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
get | `` | 2 | 1 | Get the value corresponding to a key in a map array |
has | `` | 2 | 1 | Check if a map array has a key |
insert | `` | 3 | 1 | Insert a key-value pair into a map array |
map | `` | 2 | 1 | Create a hashmap from a list of keys and list values |
remove | `` | 2 | 1 | Remove the value corresponding to a key from a map array |
MappingModifier
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
each | ∵ | `` | 1 | Apply a function to each element of an array or arrays |
group | ⊕ | `` | 1 | Group elements of an array into buckets by index |
inventory | ⍚ | `` | 1 | Apply a function to each unboxed row of an array and re-box the results |
partition | ⊜ | `` | 1 | Group sequential sections of an array |
rows | ≡ | `` | 1 | Apply a function to each row of an array or arrays |
stencil | ⧈ | 2 | 1 | Call a function on windows of an array |
table | ⊞ | `` | 1 | Apply a function to each combination of rows of some arrays |
tuples | ⧅ | `` | 1 | Get permutations or combinations of an array |
Media
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
&ap | `` | 1 | 0 | Play some audio |
&apngs | `` | 2 | 0 | Show an APNG |
&asr | `` | 0 | 1 | Get the sample rate of the audio output backend |
&ast | `` | 0 | 0 | Synthesize and stream audio |
&gifs | `` | 2 | 0 | Show a gif |
&ims | `` | 1 | 0 | Show an image |
Misc
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
&b | `` | 0 | 0 | Pause the execution and print the argument list |
&camcap | `` | 1 | 1 | Capture an image from a webcam |
&camlist | `` | 0 | 1 | List names of available webcams |
&clip | `` | 0 | 1 | Get the contents of the clipboard |
&exit | `` | 1 | 0 | Exit the program with a status code |
&sl | `` | 1 | 0 | Sleep for n seconds |
assert | ⍤ | 2 | 0 | Throw an error if a condition is not met |
case | ⍩ | `` | 1 | Call a pattern matching case |
pattern | ⍡ | `` | 1 | Choose different cases based on pattern matching |
pretty | `` | 1 | 1 | Convert a value to its pretty-printed output representation |
repr | `` | 1 | 1 | Convert a value to its code representation |
try | ⍣ | `` | 1 | Call a function and catch errors |
type | `` | 1 | 1 | Check the type of an array |
MonadicArray
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
bits | ⋯ | 1 | 1 | Encode an array as bits (LSB-first) |
box | □ | 1 | 1 | Turn an array into a box |
classify | ⊛ | 1 | 1 | Assign a unique index to each unique row in an array |
deduplicate | ◴ | 1 | 1 | Remove duplicate rows from an array |
deshape | ♭ | 1 | 1 | Make an array 1-dimensional |
fall | ⍖ | 1 | 1 | Get the indices into an array if it were sorted descending |
first | ⊢ | 1 | 1 | Get the first row of an array |
fix | ¤ | 1 | 1 | Add a length-1 axis to an array |
last | ⊣ | 1 | 1 | Get the last row of an array |
length | ⧻ | 1 | 1 | Get the number of rows in an array |
occurrences | ⧆ | 1 | 1 | Mark each row of an array with its occurrence count |
range | ⇡ | 1 | 1 | Make an array of all natural numbers less than a number |
reverse | ⇌ | 1 | 1 | Reverse the rows of an array |
rise | ⍏ | 1 | 1 | Get the indices into an array if it were sorted ascending |
shape | △ | 1 | 1 | Get the dimensions of an array |
sort | ⍆ | 1 | 1 | Sort an array |
transpose | ⍉ | 1 | 1 | Rotate the shape of an array |
unique | ◰ | 1 | 1 | Get a mask of first occurrences of items in an array |
where | ⊚ | 1 | 1 | Get indices where array values are not equal to zero |
MonadicPervasive
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
absolute value | ⌵ | 1 | 1 | Get the absolute value of a number |
ceiling | ⌈ | 1 | 1 | Round to the nearest integer towards ∞ |
exponential | ₑ | 1 | 1 | Get the exponential of a number |
floor | ⌊ | 1 | 1 | Round to the nearest integer towards ¯∞ |
negate | ¯ | 1 | 1 | Negate a number |
not | ¬ | 1 | 1 | Logical not |
reciprocal | ⨪ | 1 | 1 | Get the reciprocal of a number |
round | ⁅ | 1 | 1 | Round to the nearest integer |
sign | ± | 1 | 1 | Numerical sign (1, ¯1, or 0) |
sine | ∿ | 1 | 1 | Get the sine of a number |
sqrt | √ | 1 | 1 | Take the square root of a number |
OtherModifier
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
content | ◇ | `` | 1 | Unbox the arguments to a function before calling it |
evert | ⧋ | `` | 1 | Call a function with its arguments' axes reversed |
fill | ⬚ | `` | 1 | Set the fill value for a function |
memo | `` | `` | 1 | Memoize a function |
switch | ⨬ | `` | 1 | Call the function at the given index |
RNG
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
gen | `` | 2 | 1 | Generate an array of random numbers with a seed |
noise | `` | 3 | 1 | Generate random noise |
random | ⚂ | 0 | 1 | Generate a random number in the range [0, 1) |
StdIO
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
&ep | `` | 1 | 0 | Print a value to stderr followed by a newline |
&epf | `` | 1 | 0 | Print a value to stderr |
&p | `` | 1 | 0 | Print a value to stdout followed by a newline |
&pf | `` | 1 | 0 | Print a value to stdout |
&s | `` | 1 | 0 | Print a nicely formatted representation of a value to stdout |
&sc | `` | 0 | 1 | Read a line from stdin |
Stream
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
&cl | `` | 1 | 0 | Close a stream by its handle |
&rb | `` | 2 | 1 | Read n bytes from a stream |
&rl | `` | 1 | 1 | Read lines from a stream |
&rs | `` | 2 | 1 | Read characters formed by n bytes from a stream |
&ru | `` | 2 | 1 | Read from a stream until a delimiter is reached |
&seek | `` | 2 | 0 | Move to an absolute position in a file stream |
&w | `` | 2 | 0 | Write an array to a stream |
Tcp
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
&fetch | `` | 1 | 1 | Fetch data from a url |
&tcpa | `` | 1 | 1 | Accept a connection with a TCP or TLS listener |
&tcpaddr | `` | 1 | 1 | Get the connection address of a TCP socket |
&tcpc | `` | 1 | 1 | Create a TCP socket and connect it to an address |
&tcpl | `` | 1 | 1 | Create a TCP listener and bind it to an address |
&tcpsnb | `` | 1 | 1 | Set a TCP socket to non-blocking mode |
&tcpsrt | `` | 2 | 0 | Set the read timeout of a TCP socket in seconds |
&tcpswt | `` | 2 | 0 | Set the write timeout of a TCP socket in seconds |
&tlsc | `` | 1 | 1 | Create a TCP socket with TLS support |
&tlsl | `` | 3 | 1 | Create a TLS listener and bind it to an address |
Thread
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
pool | `` | `` | 1 | Spawn a thread in a thread pool |
recv | `` | 1 | 1 | Receive a value from a thread |
send | `` | 2 | 0 | Send a value to a thread |
spawn | `` | `` | 1 | Spawn a thread |
tryrecv | `` | 1 | 1 | Try to receive a value from a thread |
wait | `` | 1 | 1 | Wait for a thread to finish and return its results |
Time
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
datetime | `` | 1 | 1 | Get the date and time information from a time |
now | `` | 0 | 1 | Get the current time in seconds |
timezone | `` | 0 | 1 | Get the local timezone offset |
UDP
| Name | Glyph | Args | Outputs | Description |
|---|---|---|---|---|
&udpb | `` | 1 | 1 | Bind a UDP socket |
&udpr | `` | 1 | 2 | Receive a single message from a UDP socket |
&udps | `` | 3 | 0 | Send a message on a UDP socket |
&udpsml | `` | 2 | 0 | Set the maximum message length for incoming messages |
Functions
uiua
# Named function
Square ← × . # dup then multiply
# Call it
Square 5 # → 25
Try it
• cargo install uiua for the CLI