Programming paradigms are overarching styles or approaches to programming that dictate the structure and organization of code. They encompass fundamental ideas, principles, and patterns that shape the way developers conceptualize and solve problems in a programming language. Uiua is not our typical programming language—it’s a mix of two unique styles: arrays and stacks.
Array-oriented paradigm: This paradigm places arrays at the forefront of the language's design. Unlike traditional languages, where arrays are just one of many data structures, in array-oriented languages like Uiua, arrays are the primary data structure. Operations that typically apply to a single value can effortlessly extend to every element within an array, a characteristic known as
Stack-based paradigm: In a stack-based programming approach, all operations manipulate a global stack of values. Functions pop values off the top of the stack, perform their computations, and then push the results back onto the stack. This approach provides a transparent and efficient way to manage data flow, making code concise and readable.
Uiua stands out by seamlessly merging these two paradigms. This blending allows developers to leverage the strengths of both approaches within a single language. For instance, you can use array-oriented operations for bulk transformations while employing stack-based operations for managing data flow concisely.
Uiua code runs from right to left, top to bottom. Operators are put to the left of their arguments rather than in between. One common query surrounding Uiua is the question of why its code execution follows a right-to-left direction, contrary to the left-to-right pattern observed in many other stack-oriented languages. The key clarification here is that while Uiua is indeed stack based, it diverges from strict stackorientation, providing a nuanced approach to its execution flow.
For clarity, let's briefly define what stack-oriented means:
Stack-oriented: A stack-oriented language typically follows a left-to-right execution order, where operations are applied to values appearing on the stack.
Uiua, while being stack-based, introduces a departure from strict stack-orientation, allowing for more flexible and expressive code execution. Let's take a look at the following Uiua code:
+1 ⇡10
The code above involves two primary operations:
First, the ⇡
operator is used to generate an array comprising all natural numbers less than the specified value, in this case, 10
. The resulting array would include integers from
Note: In programming, glyphs refer to visual symbols or characters, and in Uiua, the arrow symbol (
⇡
) is a specific glyph representing the keywordrange
.
Then, the +1
operation is applied, adding one to each element in the array. Consequently, every number in the array is incremented by
In mathematical terms, the code effectively produces an array representing the set of natural numbers less than
We can find a list of some commonly used functions in Uiua in the table below, with an example code that you can use in the code widget below to test the examples by yourselves:
Function | Description | Gylph | Example | Output |
| Duplicates the top item on the stack. |
|
| 4 |
| Swap the top two values on the stack |
|
| [2 1 3 4 5] |
| Removes the top item from the stack. |
|
| 6 4 3 1 |
| Get the dimensions of an array |
|
| [2 3] |
# You can replace these lines with any of the examples in the table above to see their outputs yourselves.
Uiua introduces some innovative ideas, but its current status depends on adoption and stability. The language is still likely in the early stages of development.
Its practicality for real-world use depends on factors like stability, community support, and the strength of its ecosystem. Developers should check for recent updates and community feedback to assess how mature and reliable it is.
As with any new technology, it’s also essential to consider the availability of documentation, libraries, and tooling. These resources play a significant role in making the development experience productive and accessible.
Free Resources