# Rune Language Specification ## Introduction Name: Rune Paradigm: Functional, strongly-typed, with support for algebraic data types and function piping. Purpose: Designed for mathematical and functional programming with a clean and expressive syntax. ## Lexical Structure Identifiers: Sequences of letters, digits, and underscores, starting with a letter or underscore. Keywords: let, fn, if, else, for, in, union, Ok, None, Error, True, False Operators: +, -, *, /, ==, !=, >, <,>=, <=, |>, -> Delimiters: {, }, (, ), [, ], :, ;, , ## Basic Types Int: Signed 64-bit integer. Boolean: Boolean type with values true and false. String: Sequence of unsigned 8-bit integers. List: Ordered collection of elements of the same type. ## Variable Declarations Syntax: let = ; Example: ``` let x = 10; let y = 20; ``` ## Functions Syntax: let = fn -> ; Parameters: Comma-separated list of parameters. Example: ``` let sum = fn x, y -> x + y; let real = fn x -> if x > 0 { Ok x } else { None }; let divide = fn x, y -> if y == 0 { Error } else { Ok x / y }; ``` ## Function Piping Syntax: |> Example: ``` let list_of_ints = parse filepath |> buffer_to_lines |> extract_int_from_lines |> collect_to_list; ``` ## Control Flow If Expressions: Conditional expressions. Syntax: if { } else { } Example: ``` let real = fn x -> if x > 0 { Ok x } else { None }; ``` ## For Loops (Set Builder): Iterates over a range and returns a list of results. Syntax: for { in -> } Example: ``` for { x in [0..10] -> sum x x }; ``` ## Algebraic Data Types Union Types: Define a type that can be one of several variants. Syntax: let = union -> | -> | ... ; Example: ``` let Result = union -> | Ok -> Int | None | Error; ``` ## Matching Matching is a powerful data inspection protocol, for almost everything except functions. Syntax: match in | -> | ... ; Example: ``` let Expr = union -> | Const -> Int | Add -> (Expr, Expr) | Mul -> (Expr, Expr) ; let eval = fn expr -> match expr in | Const n -> n | Add (e1, e2) -> eval e1 + eval e2 | Mul (e1, e2) -> eval e1 * eval e2 ; ``` ## Expressions Arithmetic Expressions: +, -, *, / Comparison Expressions: ==, !=, >, <,>=, <= Function Application: Example: ``` sum x y; real 10; divide 10 0; ``` ## Example Programs Example 1: Basic Arithmetic and Functions ``` let x = 10; let y = 20; let sum = fn x, y -> x + y; let result = sum x y; ``` Example 2: Conditional Expressions and Result Type ``` let real = fn x -> if x > 0 { Ok x } else { None }; let divide = fn x, y -> if y == 0 { Error } else { Ok x / y }; real 10; divide 10 0; ``` Example 3: Function Piping and Set Builder ``` let list_of_ints = parse filepath |> buffer_to_lines |> extract_int_from_lines |> collect_to_list; for { x in [0..10] : sum x x }; ``` ## Conclusion This specification provides a foundation for the Rune language, covering its syntax, core features, and examples. You can expand this specification by adding more details on advanced features, error handling, standard library functions, and more.