### Install Uiua with Cargo Source: https://github.com/uiua-lang/uiua/blob/main/readme.md Installs the Uiua interpreter locally using Cargo. The 'full' feature installs all optional features, while the default installation omits audio, webcam, and window features. Ensure Rust (>=1.88) is installed. ```bash cargo install uiua -F full # Installs all features cargo install uiua # No audio, webcam, or window features ``` -------------------------------- ### Install Uiua from Git Repository Source: https://github.com/uiua-lang/uiua/blob/main/readme.md Installs the latest development version of Uiua directly from its GitHub repository using Cargo. The '-F full' flag includes all optional features. ```bash cargo install --git https://github.com/uiua-lang/uiua uiua -F full cargo install --git https://github.com/uiua-lang/uiua uiua ``` -------------------------------- ### Uiua CLI Usage Examples Source: https://context7.com/uiua-lang/uiua/llms.txt This snippet covers various command-line interface commands for the Uiua interpreter. It demonstrates how to run Uiua programs, format code (converting ASCII to glyphs), check for errors, start an interactive REPL, watch files for changes, create standalone executables, evaluate expressions, and install Uiua using Cargo. ```bash # Run a Uiua file uiua run program.ua # Run with command-line arguments uiua run program.ua arg1 arg2 # Format a file (converts ASCII to glyphs) uiua fmt program.ua # Format and check for errors without running uiua check program.ua # Start interactive REPL uiua repl # Watch file for changes and re-run uiua watch program.ua # Create standalone executable uiua stand program.ua # Evaluate expression directly uiua eval "+ 1 2" # Install/update Uiua via Cargo cargo install uiua -F full ``` -------------------------------- ### Uiua Nix/NixOS Development Environment Source: https://github.com/uiua-lang/uiua/blob/main/readme.md Commands for setting up and using the Uiua development environment with Nix or NixOS. This includes entering a development shell, checking compilation, building the latest version, and running the REPL. ```bash nix develop # to drop into a shell prompt with all the dependencies cargo check # to make sure you can compile/build latest version cargo build # to build latest debug version of uiua cargo run repl # to get uiua repl ``` -------------------------------- ### Uiua Cargo.toml Configuration for Library Usage Source: https://context7.com/uiua-lang/uiua/llms.txt This example shows how to configure the 'Cargo.toml' file when using Uiua as a Rust library. It demonstrates minimal configurations by disabling default features and enabling specific features like 'batteries' and 'native_sys' for optimized builds. It also includes an example for a full installation with all features. ```toml [dependencies] # Minimal configuration for embedding uiua = { version = "0.18", default-features = false } # With common features (regex, image/audio encoding) uiua = { version = "0.18", default-features = false, features = ["batteries"] } # With native system access (filesystem, TCP) uiua = { version = "0.18", default-features = false, features = ["batteries", "native_sys"] } # Full installation with all features uiua = { version = "0.18", features = ["full"] } ``` -------------------------------- ### Uiua Linux Dependencies for Cargo Installation Source: https://github.com/uiua-lang/uiua/blob/main/readme.md Installs necessary development libraries on Linux systems for compiling Uiua via Cargo, specifically for X11 and FFI support. These are often required for features like windowing. ```bash apt install libx11-dev libffi-dev ``` -------------------------------- ### Uiua HTTP Server Example Source: https://context7.com/uiua-lang/uiua/llms.txt A practical example of building a simple HTTP server in Uiua. It demonstrates TCP listening, accepting connections, reading request headers, parsing the request path, generating a basic text response, and closing the connection. ```uiua # Simple HTTP server Listener <- &tcpl "0.0.0.0:8080" &p "Server started on port 8080" # Response helper: Status Mime Bytes -> Response Response <- ( ⊙⊙⊸⧻ $"HTTP/1.1 _\r\nContent-Type: _\r\nContent-Length: _\r\n\r\n" ⊂ utf8 ) # Main loop ⍢( pool( &tcpa Listener # Accept connection ⊸&ru "\r\n\r\n" # Read request headers °□⊡1 ⊜□⊸≠@ . # Extract path (second word) &p⊸$"Request: _" # Generate response Response "200 OK" "text/plain" utf8"Hello from Uiua!" ⊃⋅&cl&w # Write and close ) )1 ``` -------------------------------- ### Uiua Color Data Definition Example Source: https://github.com/uiua-lang/uiua/blob/main/site/blog/uiua-0.13.0-text.md Demonstrates the experimental 'Color' data definition in Uiua, showing how to initialize and manipulate color values. It includes basic assignment and an example of applying a function to color components. ```uiua # Experimental! ~Color [r g b a ← 1] Color 0.5 1 0.2 Color!(+r⟜b) . ``` -------------------------------- ### Uiua: Implement Quadratic Formula (Initial) Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Tacit Code.md The initial definition of the Quad function in Uiua, before any implementation details are added. This serves as a starting point for building the quadratic formula. ```uiua Quad ← Quad 1 ¯3 2 ``` -------------------------------- ### Uiua Experimental Function Example Source: https://github.com/uiua-lang/uiua/blob/main/site/blog/uiua-0.13.0-text.md A simple example demonstrating an experimental function or operator in Uiua, represented by '▽⟜≡▽'. This snippet shows basic usage with a numerical input. ```uiua ▽⟜≡▽ 0.5 Cats ``` -------------------------------- ### Uiua: Multi-argument reduce example Source: https://github.com/uiua-lang/uiua/blob/main/site/blog/uiua-0.11.0-text.md Demonstrates the use of `reduce /` with multiple arguments, where additional arguments are interspersed between rows. This is useful for operations like joining strings with a delimiter. ```uiua /+ [1 2 3 4 5] ``` ```uiua /(⊂⊂) 0 [1 2 3 4] ``` ```uiua /◇(⊂⊂) @, {"cat" "dog" "bird" "fish"} ``` -------------------------------- ### Uiua Format String Example Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Modifiers and Functions.md Demonstrates the basic usage of a format string, denoted by a '$' prefix. It replaces the placeholder '_' with the stringified version of the provided argument. ```uiua "World" $"Hello, _!" ``` -------------------------------- ### Uiua: Example of Complex Function Composition Source: https://github.com/uiua-lang/uiua/blob/main/site/blog/uiua-0.17.0-text.md A complex example demonstrating function composition in Uiua, including operations for coordinates, scaling, and drawing a heart shape, along with color application. ```uiua °⍉ -⊸¬÷¤¤⟜⇡˙⊟100 # Coords ≡⌟× +1 ×0.1 ∿×τ÷⟜⇡20 # Scale ≡(⊃⊢(⊃+-⊃(√˜-0.5˙×|ⁿ2/3÷2⌵)⊣) # Heart ⇌×⊓⌞>< ×1.1+0.1) ⊏⊙Black_Red # Color ``` -------------------------------- ### Uiua Operator Precedence Example Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Introduction.md Demonstrates Uiua's syntax where operators are placed to the left of their arguments. This differs from mathematical notation and allows for unambiguous code execution, even without named variables. ```Uiua + 1 2 ×4-2 ``` -------------------------------- ### Uiua: Prefix Pattern Matching with [un]() and [join]() Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Pattern Matching.md Shows how to use [un]() combined with [join]() and a constant to match arrays that start with a specific prefix. This is useful for validating the beginning of a sequence. ```uiua °(⊂1) [1 2 3] ``` ```uiua °(⊂1) [4 5 6] ```uiua should fail ``` ```uiua °(⊂1_2) [1 2 3] ``` -------------------------------- ### Uiua: Apply 'under' with 'multiply' and constants Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Inverses.md An example of using the 'under' pattern in Uiua with the 'multiply' function and constants. This snippet shows a concise way to apply a multiplication transformation. ```uiua ⍜×⁅ 1e3 π ``` -------------------------------- ### Uiua: Repeat and Do Modifier Changes (Fibonacci Example) Source: https://github.com/uiua-lang/uiua/blob/main/site/blog/uiua-0.16.0-text.md Illustrates the breaking change in Uiua's `repeat ⍥` and `do ⍢` modifiers, which now always have static signatures. This example shows how to generate the Fibonacci sequence with the new syntax, highlighting the removal of wrapping `[]` and `⇌`. ```not uiua ⇌[⍥◡+9]∩1 ``` ```uiua ⍥◡+9 ∩1 ``` -------------------------------- ### Uiua Media Constants Example Source: https://github.com/uiua-lang/uiua/blob/main/site/blog/uiua-0.12.0-text.md Demonstrates the usage of built-in image and audio constants in Uiua. These constants, such as 'Logo', 'Lena', and 'Music', can be manipulated using functions like scaling. ```uiua Logo ▽⟜≡▽ 0.5 # Scales the image down Lena ▽⟜≡▽ 0.5 Music ``` -------------------------------- ### Argument Handling in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tour.md Shows how number literals in Uiua act as the first argument to the next function, shifting existing arguments to the right. This example demonstrates basic arithmetic operations with multiple arguments. ```uiua + 2 7 5 ``` -------------------------------- ### Uiua: Pretty Array Formatting Examples Source: https://github.com/uiua-lang/uiua/blob/main/site/blog/uiua-0.16.0-text.md Demonstrates the new pretty array formatter in Uiua 0.16.0. It shows how high-rank arrays and box arrays are displayed with improved layout and box-drawing characters. ```uiua °△2_2_3_4 ``` ```uiua ⧈□ 2_3 °△3_5 ``` -------------------------------- ### Uiua Subscripts Example Source: https://github.com/uiua-lang/uiua/blob/main/site/blog/uiua-0.14.0-text.md Demonstrates the use of subscripts in Uiua for shorter code and new behavior. Subscripts are typed with a comma followed by digits and are formatted into subscript characters. ```uiua undertake,3*,10 [1 2 3 4 5] # Try formatting! ⍜↙₃×₁₀ [1 2 3 4 5] ``` ```uiua ⊟₄ 1 2 3 4 □₂ "Uiua" 0_14_0 ``` ```uiua [∩₃+ 1 2 3 4 5 6] ``` -------------------------------- ### Uiua: Use 'under' with 'rotate' and 'concat' Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Inverses.md Demonstrates the 'under' pattern in Uiua combined with 'rotate' and 'concat' operations. This example shows how to manipulate array structures by rotating elements and concatenating them. ```uiua ⍜(↻3|⊂0) [1 2 3 4 5] ``` -------------------------------- ### Operating on Multiple Arguments in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tour.md Demonstrates how Uiua functions consistently take a fixed number of arguments, allowing for operations on a large list of arguments simultaneously. This example uses nested arithmetic operations. ```uiua ×++ 1 2 3 4 ``` -------------------------------- ### Uiua: Apply 'under' with 'pick' and 'multiply' Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Inverses.md An example of using the 'under' pattern in Uiua with the 'pick' and 'multiply' functions. This snippet demonstrates modifying elements within an array based on specific indices. ```uiua ⍜(↙2)/× [3 5 4 2] ``` -------------------------------- ### Build and Serve Uiua Website with Trunk Source: https://github.com/uiua-lang/uiua/blob/main/site/readme.md This snippet outlines the steps to build and serve the Uiua website. It requires adding the wasm32-unknown-unknown target to Rust, installing the Trunk build tool, and then running the trunk serve command from the project directory. ```sh rustup target add wasm32-unknown-unknown car go install trunk trunk serve # from this folder ``` -------------------------------- ### Comparison Operations in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Math and Comparison.md Illustrates comparison operations in Uiua, where results are represented as 0 (false) or 1 (true) due to the absence of a boolean type. Examples include equality and less than. ```uiua =2 5 =2 2 ``` ```uiua -2 5 ``` ```uiua <2 5 ``` ```uiua ÷2 5 ``` -------------------------------- ### Get Last Row of Array (String) Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Arrays.md The 'last' function retrieves the last row of an array. This example uses a string, where each character can be considered a row. Input is a string. ```uiua ⊣ "hello" ``` -------------------------------- ### Get Array Shape and Rank in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tour.md Demonstrates how to get the shape (dimensions) and rank (number of axes) of arrays in Uiua using the △ and ⧻ operators. ```Uiua △5 ``` ```Uiua △[] ``` ```Uiua △[9 1 6] ``` ```Uiua △[4_π_9 1_5_∞] ``` ```Uiua A ← [1_2_3_4 5_6_7_8 9_10_11_12] △A ⧻A ⧻△A ``` -------------------------------- ### Uiua Gap Modifier Example Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/More Argument Manipulation.md Demonstrates the basic usage of the 'gap' modifier in Uiua, which discards the first argument before calling its function. This example shows its effect on addition. ```uiua ⋅+ 1 2 3 ``` -------------------------------- ### Uiua: Pre-format String Fragments with 'fork' and Format String Source: https://github.com/uiua-lang/uiua/blob/main/site/text/other_tutorial/strings.md Explains how to use 'fork' or 'bracket' to pre-format specific parts of a format string. This enhances readability by isolating the logic for each placeholder. ```uiua F ← $"_ is _ year_ old." ⊃(∘|⋅∘|▽⊙@s≠1⋅∘) F "Dave" 31 F "Remi" 1 ``` -------------------------------- ### Import Specific Bindings from File Module in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Modules.md Demonstrates importing specific bindings ('Increment', 'Square') from the 'example.ua' module into the current scope by using two '~' operators. ```uiua ```uiua ~ "example.ua" ~ Increment Square Increment Square 3 ``` ``` -------------------------------- ### Uiua Private Data Definition Example (Should Fail) Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Data Definitions.md Illustrates the use of `≁` for creating private data definitions in Uiua. The provided example is marked as 'should fail' indicating a potential issue with visibility or scope. ```uiua ┌─╴M ~~C {A} ≁D {A} └─╴ M~D 5 ``` -------------------------------- ### Uiua Data Validation Example Source: https://github.com/uiua-lang/uiua/blob/main/site/text/experimental.md Demonstrates adding validation functions to data fields in Uiua. Validators are called on construction and mutation to ensure data integrity. This example shows type validation for fields 'Foo' and 'Bar'. ```uiua # Experimental! ~MyData {Foo: °0type|Bar: °1type} MyData 1 "hi" # Works MyData 3 5 # Fails ``` ```uiua # Experimental! ~MyData {Foo: °0type|Bar: °1type} MyData 1 "hi" °⊸MyData~Bar 5 ``` -------------------------------- ### Create Simple Lists in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tour.md Demonstrates two ways to create simple lists (1D arrays) in Uiua: using underscores as separators and using square brackets. ```Uiua 1_2_3_4 ``` ```Uiua [5 6 7 8] ``` -------------------------------- ### Rust: Create and Run Uiua Interpreter Source: https://context7.com/uiua-lang/uiua/llms.txt Demonstrates how to instantiate the Uiua interpreter in Rust, execute Uiua code from strings, and interact with the stack by pushing and popping values. It also shows how to run code from files and retrieve the entire stack. ```rust use uiua::* // Create a Uiua runtime with native system access let mut uiua = Uiua::with_native_sys(); // Run Uiua code directly from a string uiua.run_str("+ 1 2").unwrap(); let result = uiua.pop_int().unwrap(); assert_eq!(result, 3); // Push values onto the stack before running uiua.push(10); uiua.push(5); uiua.run_str("×").unwrap(); // Multiply let product = uiua.pop_int().unwrap(); assert_eq!(product, 50); // Run code from a file // uiua.run_file("program.ua").unwrap(); // Get the entire stack as a vector let mut uiua = Uiua::with_native_sys(); uiua.run_str("1 2 3").unwrap(); let stack = uiua.take_stack(); assert_eq!(stack.len(), 3); ``` -------------------------------- ### Get Array Length and Rank in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Arrays.md Illustrates how to get the length (number of rows) and rank (number of dimensions) of an array using `⧻` (length) and `⧻△` (rank). Length is the first element of the shape, and rank is the length of the shape. ```uiua △[1_2_3 4_5_6 7_8_9] # Shape ⧻[1_2_3 4_5_6 7_8_9] # Length ⧻△[1_2_3 4_5_6 7_8_9] # Rank ``` -------------------------------- ### Define and Use Simple Data Structures in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/blog/uiua-0.15.0-text.md Demonstrates defining a simple data structure 'Customer' with fields like Name, Phone, and Address. It shows how to construct an instance of this data structure and access its fields using their names. ```uiua ~Customer {Name Phone Address} Customer "John Doe" "555-1234" "123 Main St" Customer~Name . ``` -------------------------------- ### Uiua: Basic Data Function Example Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Data Definitions.md Introduces Uiua's 'data functions' where a data definition becomes a function. This example shows a 'Person' data type with 'Name' and optional 'Surname', and how the data definition's code is executed. ```uiua ~Person {Name Surname ← ""} $"_ _"⊃(Name|Surname) Person "Dave" ``` -------------------------------- ### Generate Range with Step Size using Uiua `under` and `divide` Source: https://github.com/uiua-lang/uiua/blob/main/site/text/other_tutorial/ranges.md To create a range with a specific step size, use `under` (⍜) with `divide` (÷). The idiom `⍜÷⇡ start end` generates a range from `start` to `end` with a step determined by the division. This requires the numbers to be divisible. ```uiua ⍜÷⇡ 0.5 4 ``` -------------------------------- ### Uiua Signature Mismatch Warning Example Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Modifiers and Functions.md Illustrates a scenario in Uiua where a declared signature mismatches the inferred signature, resulting in a warning. This example shows a function declared with 3 arguments and 2 outputs, but its implementation only uses 2 arguments and produces 1 output. ```uiua should fail F ← |3.2 ⊟+1 F 1 4 ``` -------------------------------- ### Get First Row of Array Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Arrays.md The 'first' function retrieves the first row of an array. Input is an array. ```uiua ⊢ [4 7 1] ``` -------------------------------- ### Uiua: Implement Quadratic Formula (Full) Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Tacit Code.md The complete implementation of the quadratic formula in Uiua, including division by 2a. This version emphasizes readability by keeping argument flow clear. ```uiua Quad ← ÷⊃(×2|-⊃⋅∘(⊟⟜¯ √ℂ0 -⊃(×4×⊙⋅∘)⋅˙×)) Quad 1 ¯3 2 ``` -------------------------------- ### Uiua: Both Modifier Example Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/More Argument Manipulation.md Demonstrates the 'both' modifier, which applies a single function to multiple sets of arguments. This is contrasted with 'fork'. ```uiua ∩⇌ [1 2 3] [4 5 6] ``` ```uiua ∩× 2 3 5 7 ``` -------------------------------- ### Uiua: Bracket Modifier Example Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/More Argument Manipulation.md Shows the 'bracket' modifier, a dyadic modifier that applies its two functions to different sets of arguments. ```uiua [⊓+× 1 2 3 4] ``` -------------------------------- ### Uiua: Take and Drop with infinity Source: https://github.com/uiua-lang/uiua/blob/main/site/blog/uiua-0.11.0-text.md Demonstrates the `take ↙` and `drop ↘` functions, including their use with multidimensional indices and the `infinity ∞` placeholder to select entire axes of an array. ```uiua ↙ 3 [1 2 3 4 5] ``` ```uiua ↘ 3 [1 2 3 4 5] ``` ```uiua ↙2_2 . ↯3_4⇡12 ``` ```uiua ↙∞_2 . ↯3_4⇡12 ``` ```uiua ↙1_∞_2 . ↯2_3_4⇡24 ``` -------------------------------- ### Uiua Variant Field Access Error Example Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Data Definitions.md Illustrates an error case where attempting to access a field from an incorrect variant type fails. ```uiua ┌─╴Shape |Circle {Radius} |Rectangle {Width Height} └─╴ Shape~Circle 5 Shape~Rectangle~Height ``` -------------------------------- ### Uiua: Reorder Arguments for Quadratic Formula Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Tacit Code.md Demonstrates reordering arguments at the beginning of a Uiua function to simplify subsequent operations. This version of the quadratic formula requires less argument manipulation later on. ```uiua Quad ← ( ⊃⊙⋅∘⋅∘ # ? a c b ÷⊃(×2|-⤙(⊟⟜¯ √ℂ0 -×4⊓×˙×)) ) Quad 1 ¯3 2 ``` -------------------------------- ### Get First Row of Array of Arrays Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Arrays.md Illustrates the 'first' function applied to an array where each element is itself an array (a row). Input is an array of arrays. ```uiua ⊢ [1_2 3_4 5_6] ``` -------------------------------- ### Recommended PascalCase Binding in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Bindings.md Demonstrates the recommended practice of using PascalCase for binding names in Uiua to prevent potential parser misinterpretations of lowercase names as built-in functions. ```uiua Part = 5 *2 Part ``` -------------------------------- ### Uiua Chained Field Access Example Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Data Definitions.md Illustrates the basic concept of nested data structures and accessing nested fields using multiple accessors. ```uiua ~Bars [Hp ← 100|Mp ← 100|Sta ← 100] ~Player {Name Bars ← Bars} Player "Roni" Bars~Hp Player~Bars ``` -------------------------------- ### Import Module by File Path in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Modules.md Shows the basic syntax for importing a module from a file path using the '~' operator. ```uiua ```uiua ~ "example.ua" ``` ``` -------------------------------- ### Uiua Raw Format String Example Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Modifiers and Functions.md Shows a raw format string, created by prefixing with '$$'. This allows for literal newlines and includes placeholders for arguments. ```uiua ◡+ 1 2 &p $$ What are two numbers that add up to _? $$ _ and _ do! ``` -------------------------------- ### Reduce Operation in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tour.md Explains and demonstrates the `reduce` modifier (/) in Uiua, which applies a function between elements of an array. Examples include summing and finding column maximums. ```Uiua /+ [1 2 3 4 5] ``` ```Uiua ⊸/+ [1_2_3 4_5_6 7_8_9] ``` ```Uiua /↥ [1_2_3 4_5_2 3_1_8] ``` -------------------------------- ### Take First N Elements Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Arrays.md The 'take' function selects the first N elements from an array. Input is the number of elements to take and the array. ```uiua ↙3 [1 2 3 4 5] ``` -------------------------------- ### Define and Call Functions in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tour.md Illustrates how to define functions in Uiua by assigning code to a name with `←`. If the code has fewer arguments than provided, it's treated as a function. ```Uiua F ← +1 F5 ``` ```Uiua 👋 ← ⊂"Hello, " 👋"World" ``` -------------------------------- ### Uiua Modifier: Self Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tour.md Introduces the 'self' modifier in Uiua, which causes a function to accept a single value as all of its arguments. This is an example of how modifiers alter function behavior. ```uiua ˙× 3 self+ 5 ``` -------------------------------- ### Uiua: Fork Modifier Example Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/More Argument Manipulation.md Illustrates the 'fork' modifier, which applies two functions to the same arguments. It shows how argument count affects function application. ```uiua [⊃+× 3 5] ``` ```uiua ⊃×⇌ [1 2 3] 10 ``` -------------------------------- ### Partition Array with Explicit Keys - Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Thinking With Arrays.md Demonstrates 'partition' (⊜) with explicit key arrays. It splits an input array into sections based on runs of non-zero values in the key array, boxing the resulting sections. ```uiua [1 2 3 4 5 6 7 8] [1 1 0 5 6 6 0 1] ⊜□ ``` -------------------------------- ### Looping with State Cleanup (Uiua) Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Control Flow.md Illustrates using [pop]() with the [do]() modifier to manage state during a loop. This example doubles a number conditionally while cleaning up an empty array. ```uiua ◌⍢(⊃(×2)⊂|<100) 1 [] ``` -------------------------------- ### Binding a Function (0 Arguments, Function) in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Bindings.md Demonstrates how to bind a function that takes zero arguments and should be treated as a function in Uiua. This requires wrapping the expression in parentheses `()` to ensure it's bound as a function. ```uiua F ← (⚂) F F F ``` -------------------------------- ### Repeating Function Execution (Uiua) Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Control Flow.md Uses the [repeat]() modifier to call a function a specified number of times. This example multiplies a number by 2, 10 times. ```uiua ⍥(×2)10 5 ``` -------------------------------- ### Bind Module to a Name in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Modules.md Shows how to bind an entire module from a file path to a new name ('Ex'). Items from the module can then be accessed using the new name followed by '~'. ```uiua ```uiua Ex ~ "example.ua" Ex~Increment 10 ``` ``` -------------------------------- ### Uiua `map` Function Usage Source: https://github.com/uiua-lang/uiua/blob/main/site/blog/uiua-0.10.0-text.md Shows a basic example of the `map` function in Uiua. The `map` function and related utilities are now stable and no longer experimental. ```uiua map 1_2_3 4_5_6 ``` -------------------------------- ### Get First and Last Rows of Array in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tour.md Demonstrates retrieving the first row using `first` (⊢) and the last row using `last` (darr) from an array. ```Uiua ⊢ [1 2 3] ``` ```Uiua fir [1_2_3 4_5_6] ``` ```Uiua lst "hello" ``` -------------------------------- ### Create Heterogeneous Array using Boxes Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Arrays.md Demonstrates how to simulate heterogeneous arrays in Uiua by boxing individual elements. Each element is wrapped in a 'box' to allow different types or shapes within the same array. Input uses the box operator on various values. ```uiua [□1_2 □3 □[4 5 6] □[7]] ``` -------------------------------- ### Generate Audio Waveforms Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tour.md Audio data in Uiua is represented as an array of numbers between -1 and 1, corresponding to waveform samples. This example generates a series of musical notes. ```uiua ♭↯4[0 2 4 7 12 9 7 4] # Notes ×220 ˜ⁿ2÷12 # Frequencies ÷⟜(⇡⁅÷8) &asr # Time ÷2 ∿×τ ♭⍉⊞× # Modulate ``` -------------------------------- ### Uiua: Visualize Argument List with Array Notation Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/More Argument Manipulation.md Demonstrates how Uiua's argument list can be visualized using array notation, showing the state before and after function application. ```uiua [ 1.21 5 4.8 2] [⁅ 1.21 5 4.8 2] ``` ```uiua [ 2 4 5 0 1] [+ 2 4 5 0 1] ``` ```uiua { 2_3 0 5 1_2_3} {↯ 2_3 0 5 1_2_3} ``` -------------------------------- ### Basic Binding Assignment in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Bindings.md Demonstrates the basic syntax for assigning values to names using the `←` operator in Uiua. The formatter can convert `=` to `←`. It shows how to declare variables and perform operations with them. ```uiua A = 3 B ← 5 + A B ``` -------------------------------- ### Get Shape of Boxed Array Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Arrays.md Illustrates that the shape of an array containing boxes reflects the number of boxes, not the shapes of the boxed contents. Input is an array of boxes. ```uiua △ [□1_2 □3 □[4 5 6] □[7]] ``` -------------------------------- ### Join Arrays End-to-End (Scalar) Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Arrays.md The 'join' function concatenates two arrays. This example joins a list with a scalar. Input are two arrays (one scalar). ```uiua ⊂ 1_2_3 4 ``` -------------------------------- ### Basic Math Operations in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Math and Comparison.md Demonstrates basic arithmetic operations like addition, ceiling, exponentiation, and square root in Uiua. These functions operate on numerical inputs. ```uiua +2 5 ``` ```uiua ↥2 5 ``` ```uiua ⁿ2 5 ``` ```uiua ⌈2.5 ``` ```uiua √4 ``` -------------------------------- ### Uiua Pattern Matching with `un` and `try` Source: https://github.com/uiua-lang/uiua/blob/main/site/blog/uiua-0.10.0-text.md Demonstrates pattern matching using the `un` function on constant values, combined with `try` for conditional matching and extraction. This allows for flexible data processing based on input patterns. ```uiua F ← ⍣( ×10 °[1⊙3] # Extract and multiply.. | °(⊂5) # ..or remove leading 5.. | ⇌ # ..else reverse ) F [1 2 3] F [5 6 7] F "cool!" ``` -------------------------------- ### Array Splitting (Python vs. Uiua) Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Control Flow.md Demonstrates how to split an array into even and odd numbers. Python uses explicit loops and conditionals, while Uiua achieves this concisely with array operations. ```python def splitArray(array): even = [] odd = [] for i in array: if i % 2 == 0: even.append(i) else: odd.append(i) return even, odd splitArray([1, 2, 3, 7, 2, 4, 5]) ``` -------------------------------- ### Looping with Condition (Uiua) Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Control Flow.md Implements a loop using the [do]() modifier, which repeatedly calls a function as long as a condition function returns 1. This example doubles a number until it reaches 1000. ```uiua ⍢(×2|<1000) 1 ``` -------------------------------- ### Uiua: Split String by Delimiter using 'un', 'reduce', and Format String Source: https://github.com/uiua-lang/uiua/blob/main/site/text/other_tutorial/strings.md Demonstrates splitting a string by a delimiter using a combination of 'un', 'reduce', and a format string. The results are boxed, meaning they are returned as a list of strings. ```uiua °/$"_ ; _" "5;cool;26;([])" ``` -------------------------------- ### Binding a Function (String Concatenation) in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Bindings.md Shows an example of binding a function that performs string concatenation in Uiua. The `⊂` operator is used here to create a function that prepends a string. ```uiua 👋 ← ⊂"Hello, " 👋 "World!" ``` -------------------------------- ### Case Sensitivity of Bindings in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Bindings.md Highlights that binding names in Uiua are case-sensitive. This example shows how a lowercase binding name might be misinterpreted by the parser as an unformatted built-in function. ```uiua part = 5 ``` -------------------------------- ### Uiua: Using 'assert' for Tests Source: https://github.com/uiua-lang/uiua/blob/main/site/blog/uiua-0.13.0-text.md Provides examples of using the `assert ⍤` modifier in Uiua, which is interpreted as a test in certain contexts like the website pad or `uiua watch`/`uiua test` commands. ```Uiua ⍤⤙≍ 3 +1 2 # Asserts that 3 equals the result of (+1) 2. ⍤⤙≍ [1 2 3] ⊂1 [2 3] # Asserts that [1 2 3] equals a box containing [2 3]. ⍤⤙≍ "Hello" ⍜⊢⌵ "hello" # Asserts that 'Hello' equals 'hello' (case-insensitive comparison). ``` -------------------------------- ### Define and Use Data Structures with Associated Functions in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/blog/uiua-0.15.0-text.md Illustrates defining a 'Customer' data structure within a module, including associated functions like 'Format' and 'HouseNum'. It shows how to use module import macros and construct data structures with associated function calls. ```uiua ┌─╴Customer ~ {Name Phone Address} Format ← $"_ lives at _" ⊃(Name|Address) HouseNum ← ⋕▽⊸∊+@0⇡10 Address └─╴ Customer!( New "Bob" "555-1234" "123 Main St" $"_'s house number is _" ⊃(Name|HouseNum) Format New "Alice" "555-2843" "456 Broadway St" ) ``` -------------------------------- ### Evert Primitive Usage in Uiua Source: https://github.com/uiua-lang/uiua/blob/main/site/blog/uiua-0.18.0-text.md Shows examples of the stabilized 'evert' primitive in Uiua, which operates on the last axis of an array. It can be used for various formatting and manipulation tasks. ```uiua ⧋÷⟜⇡ 4_4 # Formats from `edor` ``` ```uiua /+ [[1_2 0_5] [¯6_10 3_3]] ⧋/+ [[1_2 0_5] [¯6_10 3_3]] ``` -------------------------------- ### Uiua Quadratic Formula with Data Functions Source: https://github.com/uiua-lang/uiua/blob/main/site/blog/uiua-0.18.0-text.md Illustrates using Uiua's data functions with the fork modifier to implement the quadratic formula. This example showcases how to handle complex argument structures explicitly by leveraging field accessors within the data function. ```uiua ~Quad [A B C] ÷×2⊃A(-⊃B(⊟⊸¯√ℂ0 -/×⊃⊃[4|A|C](˙×B))) Quad 1 2 0 ``` -------------------------------- ### Uiua Derivative Modifier Examples Source: https://github.com/uiua-lang/uiua/blob/main/site/text/experimental.md Illustrates the use of the '∂' (derivative) modifier in Uiua on mathematical expressions. Currently supports polynomials, transforming expressions like x² to 2x. ```uiua # Experimental! ∂˙× 5 # x² → 2x ∂√ 1/9 # √x → 1/(2√x) ∂(-4+⊃(ⁿ2|ׯ2)) [0 1 2] # x² - 2x - 4 → 2x² - 2x ``` -------------------------------- ### Uiua Complex Number Literals Source: https://github.com/uiua-lang/uiua/blob/main/site/text/tutorial/Types.md Demonstrates the literal syntax for complex numbers in Uiua, using 'r' for the real part and 'i' for the imaginary part. Includes examples with various combinations and constants. ```uiua [3r4i 5r2i 2ri i/5 rπi] ```