Uiua: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 170: Line 170:
| <code>◰</code> || [[Nub Sieve|Unique]] || Get a mask of first occurrences of items in an array
| <code>◰</code> || [[Nub Sieve|Unique]] || Get a mask of first occurrences of items in an array
|-
|-
| <code>□</code> || [[Box]] || Turn an array into a box ([https://www.uiua.org/docs/box documentation])
| <code>□</code> || [[Box]] || Turn an array into a box
This is Uiua's primary way to create nested or mixed-type arrays.
Normally, arrays can only be created if their rows have the same shape and type.
⬚ fill can help you with the shape part, but it is not always wanted, and it can't help with the type part.
You can go to ([https://www.uiua.org/docs/box To See more information about the <code>□ box</code> function])
|-
|-
|}
|}
Line 216: Line 220:
! Glyph !! Name !! Type !! Definition
! Glyph !! Name !! Type !! Definition
|-
|-
| <code>∵</code> || [[Each]] || Monadic modifier || Apply a function to each element of an array or arrays. This is the element-wise version of <code>≡ rows.</code>
| <code>∵</code> || [[Each]] || Monadic modifier || Apply a function to each element of an array or arrays.
This is the element-wise version of <code>≡ rows.</code>
|-
|-
| <code>≡</code> || [[Rows]] || Monadic modifier ||Apply a function to each row of an array or arrays. This is the row-wise version of <code>∵ each.</code>
| <code>≡</code> || [[Rows]] || Monadic modifier ||Apply a function to each row of an array or arrays.
This is the row-wise version of <code>∵ each.</code>
|-
|-
| <code>⊞</code> || [[Table]] || Monadic 2-argument modifier || Apply a function to each combination of rows of two arrays. This is often what you want instead of <code>∵ each.</code>
| <code>⊞</code> || [[Table]] || Monadic 2-argument modifier || Apply a function to each combination of rows of two arrays.
This is often what you want instead of <code>∵ each.</code>
|-
|-
| <code>⊠</code> || <span style="color:black; background-color: yellow">[[Cross]]</span> || Monadic 2-argument modifier || Apply a function to each combination of rows of arrays. This was the row-wise version of <code>⊞ Table</code>
| <code>⊠</code> || <span style="color:black; background-color: yellow">[[Cross]]</span> || Monadic 2-argument modifier || Apply a function to each combination of rows of arrays.
This was the row-wise version of <code>⊞ Table</code>
|-
|-
| <code>⍥</code> || [[Repeat]] || Monadic modifier || Repeat a function a number of times
| <code>⍥</code> || [[Repeat]] || Monadic modifier || Repeat a function a number of times
Line 228: Line 236:
| <code>⍢</code> || [[Do]] || Dyadic modifier || Repeat a function while a condition holds
| <code>⍢</code> || [[Do]] || Dyadic modifier || Repeat a function while a condition holds
|}
|}
==== Aggregating Modifiers ====
Apply a function to aggregate an array
{| class="wikitable"
|+ Table of Aggregating Modifiers in Uiua
! Glyph !! Name !! Definition
|-
| <code>/</code> || [[Reduce]] || Apply a reducing function to an array.
For reducing with an initial value, see <code>∧ fold</code>
|-
| <code>∧</code> || [[Fold]] || Apply a function to aggregate arrays.
|-
| <code>\</code> || [[Scan]] || Reduce, but keep intermediate values
|-
| <code>⊕</code> || [[Group]] || Group elements of an array into buckets by index
Takes a function and two arrays.
The arrays must be the same <code>⧻ length.</code>
The first array must be rank <code>1</code> and contain integers.
Rows in the second array will be grouped into buckets by the indices in the first array.
Keys <code><0</code> will be omitted.
The function then processes each group in order. The result depends on what the function is.
If the function takes 0 or 1 arguments, then <code>⊕ group</code> behaves like <code>≡ rows.</code> This is called iterating <code>⊕ group.</code>
Expects as many arguments as its function takes.
The function must take at least 1 more argument than it returns outputs.
Arguments that are lower on the stack that will be used as accumulators.
Arguments that are higher on the stack will be iterated over.
The function will be repeatdely called with the rows of the iterated arrays followed by the accumulators.
On each iteration, the returned values will be used as the new accumulators.
|-
| <code>⊜</code> || [[Partition]] || Group sequential sections of an array
The most common use of <code>⊜ partition</code> is to split an array by a delimiter.


Takes a function and two arrays.
The arrays must be the same <code>⧻ length.</code>
The first array must be rank <code>1</code> and contain integers.
Consecutive rows in the second array that line up with groups of the same key in the first array will be grouped together.
Keys <code>≤0</code> will be omitted.
The function then processes each group in order. The result depends on what the function is.
If the function takes 0 or 1 arguments, then <code>⊜ partition</code> behaves like ≡ rows. This is called iterating ⊜ partition.
|}
==== Inversion Modifiers ====
Work with the inverses of functions
{| class="wikitable"
|+ Table of Iterating Modifiers in Uiua
! Glyph !! Name !! Definition
== External links ==
== External links ==
* [https://concatenative.org/wiki/view/Uiua Uiua] on the concatenative language wiki
* [https://concatenative.org/wiki/view/Uiua Uiua] on the concatenative language wiki

Revision as of 09:32, 28 January 2024


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 Wikipedia: Polish notation 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 the need for 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

Function with unique glyph

In the web version of Uiua, we can type in the name of the function or a part of it and when run, the interpreter will format the name to Unicode Symbol, so that we don't need use of non-ASCII keyboards.

All table below are based on Uiua version 0.8.0-1/28/2024.

And yellow background text mean that the glyph is deprecated and will be removed in a future version

Stack

Work with the stack

Table of Stack function 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
? 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 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 (Note that True is 1 and False is 0)

Table of Monadic Pervasive 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 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 first occurrences of items in an array
Box Turn an array into a box

This is Uiua's primary way to create nested or mixed-type arrays. Normally, arrays can only be created if their rows have the same shape and type. ⬚ fill can help you with the shape part, but it is not always wanted, and it can't help with the type part. You can go to (To See more information about the □ box function)

Dyadic Array

Operate on two arrays

Table of Monadic Array 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
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

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.

This is the element-wise version of ≡ rows.

Rows Monadic modifier Apply a function to each row of an array or arrays.

This is the row-wise version of ∵ each.

Table Monadic 2-argument modifier Apply a function to each combination of rows of two arrays.

This is often what you want instead of ∵ each.

Cross Monadic 2-argument modifier Apply a function to each combination of rows of arrays.

This was the row-wise version of ⊞ Table

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

Takes a function and two arrays. The arrays must be the same ⧻ length. The first array must be rank 1 and contain integers. Rows in the second array will be grouped into buckets by the indices in the first array. Keys <0 will be omitted. The function then processes each group in order. The result depends on what the function is. If the function takes 0 or 1 arguments, then ⊕ group behaves like ≡ rows. This is called iterating ⊕ group. Expects as many arguments as its function takes. The function must take at least 1 more argument than it returns outputs. Arguments that are lower on the stack that will be used as accumulators. Arguments that are higher on the stack will be iterated over. The function will be repeatdely called with the rows of the iterated arrays followed by the accumulators. On each iteration, the returned values will be used as the new accumulators.

Partition Group sequential sections of an array

The most common use of ⊜ partition is to split an array by a delimiter.

Takes a function and two arrays. The arrays must be the same ⧻ length. The first array must be rank 1 and contain integers. Consecutive rows in the second array that line up with groups of the same key in the first array will be grouped together. Keys ≤0 will be omitted. The function then processes each group in order. The result depends on what the function is. If the function takes 0 or 1 arguments, then ⊜ partition behaves like ≡ rows. This is called iterating ⊜ partition.

Inversion Modifiers

Work with the inverses of functions

Table of Iterating Modifiers in Uiua
Glyph Name Definition

External links


APL dialects [edit]
Maintained APL+WinAPL2APL64APL\ivApletteAprilCo-dfnsDyalog APLDyalog APL Visiondzaima/APLGNU APLKapNARS2000PometoTinyAPL
Historical A Programming LanguageA+ (A) ∙ APL#APL2CAPL\360APL/700APL\1130APL\3000APL.68000APL*PLUSAPL.jlAPL.SVAPLXExtended Dyalog APLIverson notationIVSYS/7090NARSngn/aplopenAPLOperators and FunctionsPATRowanSAXSHARP APLRationalized APLVisualAPL (APLNext) ∙ VS APLYork APL
Derivatives AHPLBQNCoSyELIGleeIIvyJJellyK (Goal, Klong, Q) ∙ KamilaLispLang5LilNialRADUiua
Overviews Comparison of APL dialectsTimeline of array languagesTimeline of influential array languagesFamily tree of array languages