Uiua: Difference between revisions

Jump to navigation Jump to search
7,103 bytes added ,  14 April
→‎Function with unique glyph: Cut Cross, since it's been removed
No edit summary
(→‎Function with unique glyph: Cut Cross, since it's been removed)
 
(20 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Infobox array language
{{Infobox array language
| logo                    = [[File:Uiua logo.png]]
| logo                    = [[File:Uiua logo.png]]
| array model              = [[flat array model|flat]] with box-like niladic functions
| array model              = [[flat array model|flat]] with [[boxes]]
| index origin            = 0
| index origin            = 0
| function styles          = stack-based [[tacit]]
| function styles          = stack-based [[tacit]]
Line 8: Line 8:
| released                = 2023
| released                = 2023
| developer                = Kai Schmidt
| developer                = Kai Schmidt
| latest release version  = 2024 (unversioned)
| latest release version  = 0.8.0 / 2024
| implementation languages = [[wikipedia:Rust (programming language)|Rust]]
| implementation languages = [[Wikipedia:Rust (programming language)|Rust]]
| source                  = [https://github.com/uiua-lang/uiua GitHub]
| source                  = [https://github.com/uiua-lang/uiua GitHub]
| platforms                = native, in-browser
| platforms                = native, in-browser
Line 16: Line 16:
| file ext                = .ua
| file ext                = .ua
| documentation            = [https://www.uiua.org/docs Documentation]
| documentation            = [https://www.uiua.org/docs Documentation]
| influenced by            = [[wikipedia:Forth (programming language)|Forth]], [[BQN]]
| influenced by            = [[wikipedia:Forth (programming language)|Forth]], [[BQN]], [[J]]
| run online              = [https://www.uiua.org/pad Pad]
| run online              = [https://www.uiua.org/pad Pad]
}}
}}


'''Uiua''' is a stack-based array language designed by Kai Schmidt using [[glyph]]s inspired mainly by [[BQN]].
'''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 [[Array model#boxes|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 ==
== Overview ==
Uiua uses concatenative evaluation (a [[wikipedia:context-free grammar|context-free grammar]]) with a right-to-left ordering as in [[wikipedia:Polish notation|Polish notation]]. The language supports [[tacit programming]] using stack manipulation [[primitive]]s, and all complex functions must be defined this way as there is no explicit function form that allows local variables. [[Function]]s have a fixed number of input and output values, meaning the overloading of [[ambivalent function]]s 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.
Uiua uses concatenative evaluation (a [[wikipedia:context-free grammar|context-free grammar]]) with a right-to-left ordering as in [[Wikipedia: Polish notation|Polish notation]]. The language supports [[tacit programming]] using stack manipulation [[primitive]]s, and all complex functions must be defined this way as there is no explicit function form that allows local variables. [[Function]]s have a fixed number of input and output values, meaning the overloading of [[ambivalent function]]s 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, [[Array_model#Flat_array_theory|arrays are flat]] with a homogeneous [[type]]; however, functions in Uiua are first-class values, and instead of [[boxes]], [[niladic]] constant-valued functions are used to provide [[Nested array|array nesting]].
Like the [[SHARP APL]] family, Uiua supports only [[Array_model#Flat_array_theory|flat arrays]] with a homogeneous [[type]], and has a dedicated [[box]] type for [[Nested array|array nesting]]. However, arithmetic is [[pervasion|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 [[wikipedia:Julia (programming language)|Julia]] and [[wikipedia:NumPy|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.
 
Uiua was [[Array Cast#uiua|featured on Array Cast]] in 2023.


== Primitives ==
== Primitives ==
=== Function ===
=== 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.
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 base on the [[Uiua]] 0.8.0 Version.
 
Tables below are based on Uiua version 0.8.0, with since-removed primitives taken out.
 
==== Stack ====
==== Stack ====
Work with the stack
Work with the stack
{| class="wikitable" style="margin:auto"
{| class="wikitable"
|+ Table of Stack function in Uiua
|+ Table of Stack function in Uiua
|-
|-
! Glyph !! Name !! Type !! Definition
! Glyph !! Name !! Type !! Definition
|-
|-
| <code>.</code> || [[Duplicate]] || Monadic 2-output function || Duplicate the top value on the stack
| <code>.</code> || Duplicate || Monadic 2-output function || Duplicate the top value on the stack
|-
|-
| <code>,</code> || [[Over]]|| Dyadic 3-output function || Duplicate the second-to-top value to the top of the stack  
| <code>,</code> || Over || Dyadic 3-output function || Duplicate the second-to-top value to the top of the stack  
|-
|-
| <code>:</code> || [[Flip]] || Dyadic 2-output function || Swap the top two values on the stack  
| <code>:</code> || Flip || Dyadic 2-output function || Swap the top two values on the stack  
|-
|-
| <code>◌(;)</code> || [[Pop]] ||Monadic 0-output function || Discard the top stack value
| <code>◌(;)</code> || Pop ||Monadic 0-output function || Discard the top stack value
|-
|-
| <code>?</code> || [[Stack]] || Noadic 0-output function || Debug print all stack values without popping them
| <code>?</code> || Stack || Noadic 0-output function || Debug print all stack values without popping them
|-
|-
| <code>⸮</code> || [[Trace]] || Monadic function || Debug print the top value on the stack without popping it
| <code>⸮</code> || Trace || Monadic function || Debug print the top value on the stack without popping it
|-
|-
|}
|}
==== Constants ====
==== Constants ====
Push a constant value onto the stack
Push a constant value onto the stack
{| class="wikitable" style="margin:auto"
{| class="wikitable"
|+ Table of Constants in Uiua
|+ Table of Constants in Uiua
!Glyph !! Name !! Definition
!Glyph !! Name !! Definition
|-
|-
| <code>η</code> || [[Eta]] || The number of radians in a quarter circle
| <code>η</code> || Eta || The number of radians in a quarter circle
|-
|-
| <code>π</code> || [[Pi]] || The ratio of a circle's circumference to its diameter
| <code>π</code> || [[Pi]] || The ratio of a circle's circumference to its diameter
|-
|-
| <code>τ</code> || [[Tau]] || The ratio of a circle's circumference to its radius
| <code>τ</code> || Tau || The ratio of a circle's circumference to its radius
|-
|-
| <code>∞</code> || [[Infinity]] || The biggest number
| <code>∞</code> || [[Infinity]] || The biggest number
|}
|}
==== Monadic Pervasive ====
==== Monadic Pervasive ====
Operate on every element in an array
Operate on every element in an array
{| class="wikitable" style="margin:auto"
{| class="wikitable"
|+ Table of Monadic Pervasive in Uiua
|+ Table of Monadic Pervasive in Uiua
! Glyph !! Name !! Definition
! Glyph !! Name !! Definition
Line 81: Line 82:
| <code>⌵</code> || [[Absolute value]] || Get the absolute value of a number
| <code>⌵</code> || [[Absolute value]] || Get the absolute value of a number
|-
|-
| <code>√</code> || [[Sqrt]] || Take the square root of a number
| <code>√</code> || [[Square Root|Sqrt]] || Take the square root of a number
|-
|-
| <code>○</code> || [[Sine]] || Get the sine of a number
| <code>○</code> || Sine || Get the sine of a number
|-
|-
| <code>⌊</code> || [[Floor]] || Round to the nearest integer towards <code>¯∞</code>
| <code>⌊</code> || [[Floor]] || Round to the nearest integer towards <code>¯∞</code>
Line 93: Line 94:
==== Dyadic Pervasive ====
==== Dyadic Pervasive ====
Operate on every pair of elements in two arrays (Note that True is 1 and False is 0)
Operate on every pair of elements in two arrays (Note that True is 1 and False is 0)
{| class="wikitable" style="margin:auto"
{| class="wikitable"
|+ Table of Monadic Pervasive in Uiua
|+ Table of Monadic Pervasive in Uiua
! Glyph !! Name !! Definition !! Formats from:
! Glyph !! Name !! Definition !! Formats from:
Line 127: Line 128:
| <code>↥</code> || [[Maximum]]/[[Logical Or]] || Take the maximum of two arrays (Can use for logical OR.) || max
| <code>↥</code> || [[Maximum]]/[[Logical Or]] || Take the maximum of two arrays (Can use for logical OR.) || max
|-
|-
| <code>∠</code> || [[Atangent]] || Take the arctangent of two numbers || atan
| <code>∠</code> || Atangent || Take the arctangent of two numbers || atan
|-
|-
| <code>ℂ</code> || [[Complex]] || Make a complex number.The first argument is the imaginary part, and the second argument is the real part || com
| <code>ℂ</code> || [[Complex (function)|Complex]] || Make a complex number from imaginary and real parts || com
|}
|}
====  Monadic Array ====
====  Monadic Array ====
Operate on a single array
Operate on a single array
{| class="wikitable" style="margin:auto"
{| class="wikitable"
|+ Table of Monadic Array in Uiua
|+ Table of Monadic Array in Uiua
! Glyph !! Name !! Definition  
! Glyph !! Name !! Definition  
Line 141: Line 142:
| <code>△</code> || [[Shape]] || Get the dimensions of an array
| <code>△</code> || [[Shape]] || Get the dimensions of an array
|-
|-
| <code>⇡</code> || [[Range]] || Make an array of all natural numbers less than a number  
| <code>⇡</code> || [[Index Generator|Range]] || Make an array of all natural numbers less than a number  
|-
|-
| <code>⊢</code> || [[First]] || Get the first row of an array
| <code>⊢</code> || First || Get the first row of an array
|-
|-
| <code>⇌</code> || [[Reverse]] || Reverse the rows of an array
| <code>⇌</code> || [[Reverse]] || Reverse the rows of an array
Line 149: Line 150:
| <code>♭</code> || [[Deshape]] || Make an array 1-dimensional
| <code>♭</code> || [[Deshape]] || Make an array 1-dimensional
|-
|-
| <code>¤</code> || [[Fix]] || Add a length-1 axis to an array
| <code>¤</code> || [[Promote|Fix]] || Add a length-1 axis to an array
|-
|-
| <code>⋯</code> || [[Bits]] || Encode an array as bits (LSB-first)
| <code>⋯</code> || [[Encode|Bits]] || Encode an array as bits (LSB-first)
|-
|-
| <code>⍉</code> || [[Transpose]] || Rotate the shape of an array
| <code>⍉</code> || [[Transpose]] || Rotate the shape of an array
|-
|-
| <code>⍏</code> || [[Rise]] || Get the indices into an array if it were sorted ascending
| <code>⍏</code> || [[Grade|Rise]] || Get the indices into an array if it were sorted ascending
|-
|-
| <code>⍖</code> || [[Fall]] || Get the indices into an array if it were sorted descending
| <code>⍖</code> || [[Grade|Fall]] || Get the indices into an array if it were sorted descending
|-
|-
| <code>⊚</code> || [[Where]] || Get indices where array values are not equal to zero
| <code>⊚</code> || [[Where]] || Get indices where array values are not equal to zero
Line 165: Line 166:
| <code>◴</code> || [[Deduplicate]] || Remove duplicate elements from an array
| <code>◴</code> || [[Deduplicate]] || Remove duplicate elements from an array
|-
|-
| <code>◰</code> || [[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. The box function is complicated, so you can look at [https://www.uiua.org/docs/box] for more information
| <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])
|-
|-
|}
|}
==== Dyadic Array ====
==== Dyadic Array ====
Operate on two arrays
Operate on two arrays
{| class="wikitable" style="margin:auto"
{| class="wikitable"
|+ Table of Monadic Array in Uiua
|+ Table of Monadic Array in Uiua
! Glyph !! Name !! Definition  
! Glyph !! Name !! Definition  
Line 180: Line 186:
| <code>⊟</code> || [[Couple]] || Combine two arrays as rows of a new array
| <code>⊟</code> || [[Couple]] || Combine two arrays as rows of a new array
|-
|-
| <code>⊂</code> || [[Join]] || Append two arrays end-to-end
| <code>⊂</code> || [[Catenate|Join]] || Append two arrays end-to-end
|-
|-
| <code>⊏</code> || [[Select]] || Select multiple rows from an array
| <code>⊏</code> || [[Select]] || Select multiple rows from an array
|-
| <code>⊡</code> || [[Pick]] || Index a row or elements from an array
|-
| <code>↯</code> || [[Reshape]] || Change the shape of an array
|-
| <code>☇</code> || Rerank || Change the rank of an array's rows
|-
| <code>↙</code> || [[Take]] || Take the first n elements of an array
|-
| <code>↘</code> || [[Drop]] || Drop the first n elements of an array
|-
| <code>↻</code> || [[Rotate]] || Rotate the elements of an array by n
|-
| <code>◫</code> || [[Windows]] || The n-wise windows of an array
|-
| <code>▽</code> || [[Replicate|Keep]] || Discard or copy some rows of an array
|-
| <code>⌕</code> || [[Find]] || Find the occurrence's of one array in another
|-
| <code>∊</code> || [[Member]] || Check if each row of one array exists in another
|-
| <code>⊗</code> || [[Index Of|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
{| class="wikitable"
|+ Table of Iterating Modifiers in Uiua
! 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> || 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> || [[Repeat]] || Monadic modifier || Repeat a function a number of times
|-
| <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 (BQN)|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 <code>≡ rows</code>. This is called iterating <code>⊜ partition.</code>
|}
==== Inversion Modifiers ====
Work with the inverses of functions
{| class="wikitable"
|+ Table of Iterating Modifiers in Uiua
! Glyph !! Name !! Type !! Definition
|-
| <code>°</code> || [[Un]] || Monadic modifier || Invert the behavior of a function
Most functions are not invertible.
|-
| <code>⍜</code> || [[Under]] || Dyadic modifier || Apply a function under another
This is a more powerful version of <code>° un.</code>
Conceptually, <code>⍜ under</code> transforms a value, modifies it, then reverses the transformation.


<code>⍜ under</code> takes 2 functions <code>f</code> and <code>g</code> and another argument <code>x</code>.
It applies <code>f</code> to <code>x</code>, then applies <code>g</code> to the result.
It then applies the inverse of <code>f</code> to the result of <code>g</code>.
Any function that can be <code>° un</code>ed can be used with <code>⍜ under</code>.
Some functions that can't be <code>° un</code>ed can still be used with <code>⍜ under</code>.
You can go to ([https://www.uiua.org/docs/under To See more information about the <code>⍜ under</code> function])
|}
==== 🌎 Planet 🪐 ====
Advanced stack manipulation
{| class="wikitable"
|+ Table of Iterating Modifiers in Uiua
! Glyph !! Name !! Type !! Definition
|-
| <code>∘</code> || [[Identity]] || Monadic function || Do nothing with one value
|-
| <code>⋅</code> || Gap || Monadic modifier || Discard the top stack value then call a function
|-
| <code>⊙</code> || Dip || Monadic modifier || Temporarily pop the top value off the stack and call a function
|-
| <code>∩</code> || Both || Monadic 2-argument modifier || Call a function on two sets of values
For monadic functions, <code>∩ both</code> calls its function on each of the top 2 values on the stack.
|-
| <code>⊃</code> || [[Fork]] || Dyadic modifier || Call two functions on the same values
<code>⊃ fork</code> is one of the most important functions for working with the stack.
|-
| <code>⊓</code> || Bracket || Dyadic modifier || Call two functions on two distinct sets of values
|}


== 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
* [https://www.arraycast.com/episodes/episode63-uiua Uiua, a Stack based Array language] on the [[Array Cast]]
* [https://www.uiua.org/docs Doc] for the Documentation
* [https://www.uiua.org/docs Doc] for the Documentation
* [https://www.uiua.org Interpreter] for the interpreter
* [https://www.uiua.org Interpreter] for the interpreter

Navigation menu