diff options
Diffstat (limited to 'js/baba-yaga/ref.txt')
-rw-r--r-- | js/baba-yaga/ref.txt | 240 |
1 files changed, 0 insertions, 240 deletions
diff --git a/js/baba-yaga/ref.txt b/js/baba-yaga/ref.txt deleted file mode 100644 index 92579d7..0000000 --- a/js/baba-yaga/ref.txt +++ /dev/null @@ -1,240 +0,0 @@ -TOY SCRIPTING LANGUAGE REFERENCE CARD -===================================== - -SYNTAX & OPERATORS ------------------- -Declaration : name : value; // Variable assignment -Type Decl : name Type; // Type declaration -Function : name : params -> body; // Function definition -Anonymous Func : params -> body; // Anonymous function -Arrow in Table : key: params -> body; // Arrow function in table literal -Curried : x -> y -> body; // Curried function -With Header : name : params -> with (entries) -> body; // Local bindings -With Rec : name : params -> with rec (entries) -> body; // Mutually recursive locals -Function Call : (func arg1 arg2); // Function call with parentheses - func arg1 arg2; // Function call without parentheses - -OPERATORS ---------- -Arithmetic : + - * / % // Add, Subtract, Multiply, Divide, Modulo -Comparison : = != > < >= <= // Equal, NotEqual, Greater, Less, GreaterEqual, LessEqual -Logical : and or xor // And, Or, Xor -Unary : - // Negate -String Concat : .. // String concatenation -Pattern Match : _ // Wildcard pattern - -Operator Precedence (highest to lowest): - : * / % // Multiplication, Division, Modulo - : + - // Addition, Subtraction - : = != > < >= <= // Comparison - : xor // XOR - : and // Logical AND - : or // Logical OR - : .. // String concatenation - -CONTROL FLOW ------------- -When Expression: when expr is - pattern1 then result1 - pattern2 then result2 - _ then default; - -Patterns : literal // Literal value (1, "hello", true) - : _ // Wildcard (matches anything) - : Type // Type pattern (Int, String, etc.) - : [head ...tail] // List pattern (planned) - : {key: value} // Table pattern (planned) - : Ok value // Result success pattern - : Err message // Result error pattern - -DATA TYPES ----------- -Atom : Int 0 42 -5 // Integer numbers - : Float 3.14 -2.5 // Floating point numbers - : Number // supertype of Int/Float - : String "hello" // Text strings - : Bool true false // Boolean values - : Result Ok value // Success result - : Result Err message // Error result - -List : [1, 2, 3, "hello"] // Ordered collection - : list.0 // Index access (0-based) - : list.1 // Second element - -Table : {name: "Eve", age: 30} // Key-value pairs - : table.name // Property access - : table.age // Property access - -BUILT-IN FUNCTIONS ------------------- -List Operations : map func list // Apply function to each element - : filter pred list // Keep elements matching predicate - : reduce func init list // Fold list to single value - : append list element // Add element to end (immutable) - : prepend element list // Add element to beginning (immutable) - : concat list1 list2 // Combine two lists (immutable) - : update list index val // Replace element at index (immutable) - : removeAt list index // Remove element at index (immutable) - : slice list start end // Get sublist (immutable) - -Table Operations : set table key value // Add/update property (immutable) - : remove table key // Remove property (immutable) - : merge table1 table2 // Combine two tables (immutable) - : keys table // Get list of keys - : values table // Get list of values - -String Operations: - : str.concat str2 // String concatenation - : str.split delimiter // Split string into list - : str.join list // Join list into string - : str.length // String length - : str.substring start end // Extract substring - : str.replace old new // Replace substring - : str.trim // Remove whitespace - : str.upper // Convert to uppercase - : str.lower // Convert to lowercase - -I/O Operations : io.out value // Print to console - : io.in // Read entire stdin as a string - -Math Operations (math.*): - : math.abs x // Absolute value - : math.sign x // -1, 0, 1 - : math.floor x, math.ceil x, math.round x, math.trunc x - : math.min x y, math.max x y, math.clamp x lo hi - : math.pow x y, math.sqrt x, math.exp x, math.log x - : math.sin x, math.cos x, math.tan x - : math.asin x, math.acos x, math.atan x, math.atan2 y x - : math.deg x, math.rad x - : math.random // 0 <= x < 1 - : math.randomInt lo hi // inclusive - -Shape/Introspection: - : shape x // Return metadata table: kind, rank, shape, size, keys?, isEmpty - -EXAMPLES --------- -// Basic arithmetic -result : 5 + 3 * 2; // 11 - -// Function definition and call -add : x y -> x + y; -sum : add 5 3; // 8 - -// Curried function -add5 : add 5; -result : add5 3; // 8 - -// Pattern matching -checkNumber : num -> - when num is - 0 then "Zero" - 1 then "One" - _ then "Other"; - -// List operations -numbers : [1 2 3 4 5]; -doubled : map (x -> x * 2) numbers; // [2, 4, 6, 8, 10] -evens : filter (x -> x % 2 = 0) numbers; // [2, 4] -sum : reduce (acc x -> acc + x) 0 numbers; // 15 - -// Immutable list operations -appended : append numbers 6; // [1 2 3 4 5 6] -prepended : prepend 0 numbers; // [0 1 2 3 4 5] -combined : concat [1 2] [3 4]; // [1 2 3 4] -updated : update numbers 2 99; // [1 2 99 4 5] -removed : removeAt numbers 1; // [1 3 4 5] -sliced : slice numbers 1 4; // [2 3 4] - -// Table operations -user : {name: "Alice" age: 30}; -updatedUser : set user "city" "NYC"; // {name: "Alice" age: 30 city: "NYC"} -removedUser : remove user "age"; // {name: "Alice"} -merged : merge user {country: "USA"}; // {name: "Alice" age: 30 country: "USA"} -userKeys : keys user; // ["name", "age"] -userValues : values user; // ["Alice", 30] - -// Result type handling -divide : x y -> - when y is - 0 then Err "Division by zero" - _ then Ok (x / y); - -result : when (divide 10 2) is - Ok value then value - Err msg then 0; // 5 - -// Table operations -person : {name: "Alice" age: 30}; -name : person.name; // "Alice" - -// Arrow functions in table literals -calculator : { - add: x y -> x + y; - subtract: x y -> x - y; - multiply: x y -> x * (y + 1); - constant: -> 42; -}; -result : calculator.add 5 3; // 8 - -// With header locals -sumNext : (x: Int, y: Int) -> Int -> - with (nx Int; ny Int; nx : x + 1; ny : y + 1;) -> nx + ny; - -// With rec mutual recursion -isEvenOdd : z -> with rec ( - isEven : n -> when n is 0 then true _ then isOdd (n - 1); - isOdd : n -> when n is 0 then false _ then isEven (n - 1); -) -> { e: isEven 10, o: isOdd 7 }; - -// Type checking -checkType : val -> - when val is - Int then "Integer" - String then "String" - _ then "Other"; - -// Recursive functions -factorial : n -> - when n is - 0 then 1 - 1 then 1 - _ then n * (factorial (n - 1)); - -fibonacci : n -> - when n is - 0 then 0 - 1 then 1 - _ then (fibonacci (n - 1)) + (fibonacci (n - 2)); - -// Mathematical constants -circumference : radius -> 2 * PI * radius; -area : radius -> PI * radius * radius; - -COMMENTS --------- -// Single line comment - -SPECIAL VALUES --------------- -PI : PI // Mathematical constant π (3.14159...) -INFINITY : INFINITY // Positive infinity - -ERROR MESSAGES --------------- -"Undefined variable: name" // Variable not found -"Type mismatch: expected X, got Y" // Type error -"Division by zero" // Arithmetic error -"Index out of bounds" // List access error -"Unknown operator: op" // Invalid operator -"Unexpected token: token" // Syntax error - -FILE EXTENSIONS --------------- -.baba // Baba Yaga language source files - -COMMAND LINE ------------- -bun run index.js file.baba // Run a Baba Yaga script -bun run index.js file.baba --debug // Run with debug output -bun test tests/*.test.js // Run test suite \ No newline at end of file |