Uiua: Difference between revisions

Jump to navigation Jump to search
→‎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)
 
(11 intermediate revisions by 3 users not shown)
Line 23: Line 23:


== 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, 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.
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.


== Primitives ==
== Primitives ==
Line 31: Line 31:
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 based on Uiua version 0.8.0-1/28/2024.
Tables below are based on Uiua version 0.8.0, with since-removed primitives taken out.


<span style="color:black; background-color: yellow">Yellow background text </span> mean that the glyph is deprecated and will be removed in a future version
And 🧪 emoji mean that the glyph is experimental and may be changed or removed in the future.
==== Stack ====
==== Stack ====
Work with the stack
Work with the stack
Line 153: 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> || [[Encode|Bits]] || Encode an array as bits (LSB-first)
| <code>⋯</code> || [[Encode|Bits]] || Encode an array as bits (LSB-first)
Line 224: Line 221:
This is the element-wise version of <code>≡ rows.</code>
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.
| <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>
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.
| <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>
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> || [[Repeat]] || Monadic modifier || Repeat a function a number of times
| <code>⍥</code> || [[Repeat]] || Monadic modifier || Repeat a function a number of times
Line 246: Line 240:
For reducing with an initial value, see <code>∧ fold</code>
For reducing with an initial value, see <code>∧ fold</code>
|-
|-
| <code>∧</code> || [[Fold]] || Apply a function to aggregate arrays.
| <code>∧</code> || Fold || Apply a function to aggregate arrays.
|-
|-
| <code>\</code> || [[Scan]] || Reduce, but keep intermediate values
| <code>\</code> || [[Scan]] || Reduce, but keep intermediate values
|-
|-
| <code>⊕</code> || [[Group]] || Group elements of an array into buckets by index
| <code>⊕</code> || [[Group (BQN)|Group]] || Group elements of an array into buckets by index
Takes a function and two arrays.
Takes a function and two arrays.
The arrays must be the same <code>⧻ length.</code>
The arrays must be the same <code>⧻ length.</code>
Line 274: Line 268:
Keys <code>≤0</code> will be omitted.
Keys <code>≤0</code> will be omitted.
The function then processes each group in order. The result depends on what the function is.
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 <code>⊜ partition.</code>
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 ====
==== Inversion Modifiers ====
Work with the inverses of functions
Work with the inverses of functions
Line 284: Line 279:
| <code>°</code> || [[Un]] || Monadic modifier || Invert the behavior of a function
| <code>°</code> || [[Un]] || Monadic modifier || Invert the behavior of a function
Most functions are not invertible.
Most functions are not invertible.
|-
| <code>⌅</code> || <span style="color:black; background-color: yellow">🧪[[Rectify]]</span> || Monadic modifier ||🧪Set a function as its own inverse
|-
|-
| <code>⍜</code> || [[Under]] || Dyadic modifier || Apply a function under another
| <code>⍜</code> || [[Under]] || Dyadic modifier || Apply a function under another
Line 297: Line 290:
Any function that can be <code>° un</code>ed can be used with <code>⍜ under</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>.
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

Navigation menu