Arr.ai Documentation
website·Indexed 31 days ago
https://arr.ai/docs/Arr.ai is a functional data representation and transformation language. It features a standard library accessible via the // syntax, including modules for math, os, str, and re, and provides compilers implemented in Go and JS (Wasm). The language supports numbers, tuples, and sets, along with powerful transform operators, macros, and built-in grammar encoding for parsing.
What's inside Arr.ai
- Arr.ai is a functional programming language specifically designed for data representation and transformation.
Define and use grammars in Arr.ai
Arr.ai allows the encoding of grammars directly within the language. These grammars are treated as data structures, meaning they can be transformed, composited, or subsetted. Their primary application is within the macro system to parse content and apply transformations to the resulting parsed syntax.{://grammar.lang.wbnf: expr -> @:[-+] > @:[/*] > \d+; :} -> {:.:1+2*3:}Use expression strings for text templating
Expression strings in arr.ai allow for dynamic content by nesting expressions within strings. They are identified by a$prefix. A regular string like"abc"is equivalent to the expression string$"abc". This applies to single-quoted and backquoted strings as well.// Evaluates to "id = 42;" if i equals 42 $"id = ${i};"Work with immutable values and pure expressions in arr.ai
All values in arr.ai are immutable. Every program is a single, pure expression that defines an output based on inputs, meaning there are no side effects. Because the language prohibits direct filesystem writes, arr.ai provides native support for outputting zip and tar archives to handle data persistence.Use Tuples for fixed-dimension data
Tuples are used to capture known dimensions of a concept. Unlike C structs, tuple names are not values (they cannot be stored in variables) and do not require a predefined definition; any field can hold any value of any type.
Shorthand syntax allows omitting the key if the value is an expression of the form
nameorexpr.name(e.g.,:xis equivalent tox: x).() (a:1) ('t.m.o.l.': 42) (x: (a: (), b: 2), y: -3i) (:x, :y) // Shorthand for (x: x, y: y)Access the arr.ai standard library packages
The arr.ai standard library is accessed using the
//syntax. The following standard packages are available for various utilities://archive: Archive format utilities//bits: Bit utilities//encoding: Encoded data processing//eval: Evaluate strings containing arr.ai code//fmt: String formatting//fn: Function manipulation//grammar: Grammar features and processing//log: Print utilities//math: Math operations and functions//net: Network utilities//os: OS support//re: Regular expressions//rel: Relational operations//seq: Sequence utilities//str: String utilities//test: Testing utilities
Understand Arr.ai testing fundamentals
In Arr.ai, tests are defined as data structures where every leaf node must evaluate to a literaltrueorfalse. A leaf evaluating totrueindicates a passing test, whilefalseindicates a failure. Any leaf that evaluates to a value other than a boolean is considered an invalid test and will cause the test run to fail.( passingTest: //math.cos(//math.pi) = -1, failingTest: 5 > 10, invalidTest: 7, )Understand the Arr.ai data model
Arr.ai uses a minimal data model consisting of only three immutable primitive types. All other data structures are syntactic sugar for combinations of these three:
- Numbers: 64-bit binary floats.
- Tuples: Associate names with values.
- Sets: Hold sets of values.
Common types represented via these primitives include:
- Arrays: e.g.,
[2, 4, 8] - Strings: e.g.,
"hello"(internally represented as a set of tuples containing@for position and@charfor the character code). - Booleans:
true,false - Maps: e.g.,
{"a": 42} - Functions: Unary functions (e.g.,
\x 1 / x). Binary functions are implemented as unary functions that return another unary function. - Packages: Referenced via paths like
//math.sin(1)or URLs.
Understand the arr.ai type system philosophy
arr.ai utilizes a minimal set of simple, immutable types to represent all information structures. The core types are numbers, tuples, and sets. These three primitives are sufficient to construct more complex structures such as arrays, strings, dictionaries, and functions.Access the math library
Themathlibrary contains functions and constants used for mathematical operations. It is accessed using the expression//math.Understand the arr.ai core type system
The arr.ai type system is designed for extreme simplicity, using only three fundamental types: numbers, tuples, and sets. All other data structures—including strings, arrays, dictionaries, and functions—are syntactic sugar for arrangements of these three core types. For example, a string is represented internally as a set of tuples containing index and character codes. Because these representations are identical, string syntax and set syntax can be used interchangeably in any expression.// The string "abc" is exactly equivalent to this set: {(@: 0, @char: 97), (@: 1, @char: 98), (@: 2, @char: 99)}Understand the arr.ai language design and syntax
arr.ai is a functional language designed around relational algebra. It prioritizes expressivity over ease of learning, aiming to significantly reduce the volume of code required to implement logic once the user understands its fundamental concepts, operations, and idioms.