diff options
Diffstat (limited to 'js/scripting-lang/docs/repl/baba-yaga/0.0.1/index.html')
-rw-r--r-- | js/scripting-lang/docs/repl/baba-yaga/0.0.1/index.html | 287 |
1 files changed, 0 insertions, 287 deletions
diff --git a/js/scripting-lang/docs/repl/baba-yaga/0.0.1/index.html b/js/scripting-lang/docs/repl/baba-yaga/0.0.1/index.html deleted file mode 100644 index 60a91ec..0000000 --- a/js/scripting-lang/docs/repl/baba-yaga/0.0.1/index.html +++ /dev/null @@ -1,287 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="utf-8"> - <title>JSDoc: Home</title> - - <script src="scripts/prettify/prettify.js"> </script> - <script src="scripts/prettify/lang-css.js"> </script> - <!--[if lt IE 9]> - <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> - <![endif]--> - <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> - <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> -</head> - -<body> - -<div id="main"> - - <h1 class="page-title">Home</h1> - - - - - - - - - <h3>baba-yaga 0.0.1</h3> - - - - - - - - - - - - - - - - <section> - <article><h1>Baba Yaga</h1> -<h2>A Scripting Language</h2> -<p>Baba Yaga is a combinator-based scripting language with functional programming features, pattern matching, and hopefully enough of a standard library to be useful.</p> -<h2>Overview</h2> -<p>Baba Yaga supports:</p> -<ul> -<li><strong>Function Definitions</strong>: Arrow syntax with lexical scoping</li> -<li><strong>Pattern Matching</strong>: When expressions with wildcards and nested expressions</li> -<li><strong>Tables</strong>: Array-like and key-value entries with boolean keys</li> -<li><strong>Function References</strong>: @ operator for higher-order programming</li> -<li><strong>IO Operations</strong>: Input, output, and assertions</li> -<li><strong>Standard Library</strong>: Complete set of arithmetic, comparison, logical, and higher-order combinators</li> -<li><strong>Table Enhancements</strong>: APL-inspired element-wise operations and immutable table operations</li> -</ul> -<h2>Quick Start</h2> -<h3>Usage</h3> -<pre class="prettyprint source lang-bash"><code># Run a script file -node lang.js your-script.txt - -# Or with Bun -bun lang.js your-script.txt -</code></pre> -<h3>Example Script</h3> -<pre class="prettyprint source lang-plaintext"><code>// Basic arithmetic -result : 5 + 3 * 2; -..out result; - -// Function definition -factorial : n -> - when n is - 0 then 1 - _ then n * (factorial (n - 1)); - -// Pattern matching -classify : x y -> - when x y is - 0 0 then "both zero" - 0 _ then "x is zero" - _ 0 then "y is zero" - _ _ then "neither zero"; - -// Tables -person : {name: "Alice", age: 30, active: true}; -..out person.name; -..out person["age"]; - -// Function composition -double : x -> x * 2; -increment : x -> x + 1; -composed : compose @double @increment 5; -..out composed; // Output: 12 - -// Table enhancements -numbers : {1, 2, 3, 4, 5}; -doubled : map @double numbers; -..out doubled[1]; // Output: 2 - -// APL-style element-wise operations -table1 : {a: 1, b: 2, c: 3}; -table2 : {a: 10, b: 20, c: 30}; -sum : each @add table1 table2; -..out sum.a; // Output: 11 -</code></pre> -<h2>Key Features</h2> -<h3>Function Application</h3> -<p>Functions are applied using juxtaposition (space-separated):</p> -<pre class="prettyprint source lang-plaintext"><code>f x // Apply function f to argument x -f x y // Apply f to x, then apply result to y -f (g x) // Apply g to x, then apply f to result -</code></pre> -<h3>Pattern Matching</h3> -<p>Use <code>when</code> expressions for pattern matching:</p> -<pre class="prettyprint source lang-plaintext"><code>result : when value is - 0 then "zero" - 1 then "one" - _ then "other"; -</code></pre> -<h3>Tables</h3> -<p>Create and access data structures:</p> -<pre class="prettyprint source lang-plaintext"><code>// Array-like -numbers : {1, 2, 3, 4, 5}; - -// Key-value pairs -person : {name: "Alice", age: 30, active: true}; - -// Boolean keys -flags : {true: "enabled", false: "disabled"}; -</code></pre> -<h3>Function References</h3> -<p>Use <code>@</code> to reference functions:</p> -<pre class="prettyprint source lang-plaintext"><code>numbers : {1, 2, 3, 4, 5}; -doubled : map @double numbers; -</code></pre> -<h2>Combinators and Higher-Order Functions</h2> -<p>The language provides a comprehensive set of combinators for functional programming:</p> -<h3>Core Combinators</h3> -<ul> -<li><strong><code>map(f, x)</code></strong> - Transform elements in collections</li> -<li><strong><code>filter(p, x)</code></strong> - Select elements based on predicates</li> -<li><strong><code>reduce(f, init, x)</code></strong> - Accumulate values into a single result</li> -<li><strong><code>each(f, x)</code></strong> - Multi-argument element-wise operations</li> -</ul> -<h3>Function Composition</h3> -<ul> -<li><strong><code>compose(f, g)</code></strong> - Right-to-left composition (mathematical style)</li> -<li><strong><code>pipe(f, g)</code></strong> - Left-to-right composition (pipeline style)</li> -<li><strong><code>via</code> operator</strong> - Natural composition syntax: <code>f via g via h</code></li> -</ul> -<h3>Table Operations (<code>t.</code> namespace)</h3> -<ul> -<li><strong><code>t.map</code></strong>, <strong><code>t.filter</code></strong>, <strong><code>t.set</code></strong>, <strong><code>t.delete</code></strong>, <strong><code>t.merge</code></strong>, <strong><code>t.get</code></strong>, <strong><code>t.has</code></strong>, <strong><code>t.length</code></strong></li> -<li>All operations are immutable and return new tables</li> -</ul> -<h3>When to Use Which Combinator</h3> -<ul> -<li><strong><code>map</code> vs <code>t.map</code></strong>: Use <code>map</code> for general collections, <code>t.map</code> to emphasize table operations</li> -<li><strong><code>each</code> vs <code>map</code></strong>: Use <code>each</code> for multi-argument operations, <code>map</code> for single-table transformations</li> -<li><strong><code>compose</code> vs <code>pipe</code></strong>: Use <code>compose</code> for mathematical notation, <code>pipe</code> for pipeline notation</li> -</ul> -<h3>Standard Library</h3> -<p>The language includes a comprehensive standard library:</p> -<p><strong>Arithmetic</strong>: <code>add</code>, <code>subtract</code>, <code>multiply</code>, <code>divide</code>, <code>modulo</code>, <code>power</code>, <code>negate</code><br> -<strong>Comparison</strong>: <code>equals</code>, <code>notEquals</code>, <code>lessThan</code>, <code>greaterThan</code>, <code>lessEqual</code>, <code>greaterEqual</code><br> -<strong>Logical</strong>: <code>logicalAnd</code>, <code>logicalOr</code>, <code>logicalXor</code>, <code>logicalNot</code><br> -<strong>Higher-Order</strong>: <code>map</code>, <code>compose</code>, <code>pipe</code>, <code>apply</code>, <code>filter</code>, <code>reduce</code>, <code>fold</code>, <code>curry</code>, <code>each</code><br> -<strong>Enhanced</strong>: <code>identity</code>, <code>constant</code>, <code>flip</code>, <code>on</code>, <code>both</code>, <code>either</code><br> -<strong>Table Operations</strong>: <code>t.map</code>, <code>t.filter</code>, <code>t.set</code>, <code>t.delete</code>, <code>t.merge</code>, <code>t.get</code>, <code>t.has</code>, <code>t.length</code></p> -<h2>Key Language Takeaways</h2> -<ul> -<li><strong>Unary minus works without parentheses:</strong> -<ul> -<li>Example: <code>-5</code> is parsed as <code>negate(5)</code> (no leading space required).</li> -<li>Example: <code>f -5</code> applies <code>f</code> to <code>negate(5)</code>.</li> -</ul> -</li> -<li><strong>Binary operators require spaces for clarity:</strong> -<ul> -<li>Example: <code>3 - 4</code> is parsed as <code>subtract(3, 4)</code> (spaces required).</li> -<li>Example: <code>5 + 3</code> is parsed as <code>add(5, 3)</code> (spaces required).</li> -<li>Example: <code>5 * 3</code> is parsed as <code>multiply(5, 3)</code> (spaces required).</li> -</ul> -</li> -<li><strong>Legacy syntax continues to work:</strong> -<ul> -<li>Example: <code>(-5)</code> still works for explicit grouping.</li> -<li>Example: <code>5-3</code> falls back to legacy parsing (but spaces are recommended).</li> -</ul> -</li> -<li><strong>Table operations are immutable:</strong> -<ul> -<li>All <code>t.</code> namespace operations return new tables, never modify existing ones.</li> -</ul> -</li> -<li><strong><code>each</code> is for multi-argument operations:</strong> -<ul> -<li>Use <code>map</code> for single-table transformations, <code>each</code> for combining multiple collections.</li> -</ul> -</li> -</ul> -<p>These rules ensure that function application and infix operators are unambiguous and match functional language conventions. <strong>Best practice: Always use spaces around binary operators for clarity and consistency.</strong></p> -<p>📖 <strong>Learn more</strong>: See the <a href="tutorials/13_Operator_Spacing_Best_Practices.md">Operator Spacing Best Practices tutorial</a> for detailed examples and guidelines.</p> -<h2>Architecture</h2> -<p>The language uses a combinator-based architecture where all operations are translated to function calls:</p> -<ol> -<li><strong>Lexer</strong>: Converts source code into tokens</li> -<li><strong>Parser</strong>: Translates tokens into AST, converting operators to combinator calls</li> -<li><strong>Interpreter</strong>: Executes combinator functions from the standard library</li> -</ol> -<p>This approach eliminates parsing ambiguity while preserving syntax and enabling powerful functional programming patterns.</p> -<h2>Testing</h2> -<p>Run the complete test suite:</p> -<pre class="prettyprint source lang-bash"><code>./run_tests.sh -</code></pre> -<p>All 24 tests should pass, covering:</p> -<ul> -<li>Basic lexer and parser functionality</li> -<li>Arithmetic and comparison operations</li> -<li>Function definitions and calls</li> -<li>Pattern matching and case expressions</li> -<li>Table literals and access</li> -<li>Standard library functions</li> -<li>Error handling and edge cases</li> -<li>Table enhancements and combinators</li> -<li>Integration tests</li> -</ul> -<h2>Documentation</h2> -<ul> -<li><strong><a href="tutorials/Introduction.md">tutorials/Introduction.md</a></strong> - Learn how to use the language</li> -<li><strong><a href="tutorials/Combinators_Deep_Dive.md">tutorials/Combinators_Deep_Dive.md</a></strong> - Advanced combinator patterns and problem-solving</li> -<li><strong><a href="design/ARCHITECTURE.md">design/ARCHITECTURE.md</a></strong> - Detailed architecture overview</li> -<li><strong><a href="design/README.md">design/README.md</a></strong> - Design principles and patterns</li> -<li><strong><a href="design/HISTORY/">design/HISTORY/</a></strong> - Implementation journey and decisions</li> -</ul> -<h2>Development</h2> -<h3>Project Structure</h3> -<pre class="prettyprint source"><code>scripting-lang/ -├── lang.js # Main interpreter and standard library -├── lexer.js # Lexical analysis -├── parser.js # Parsing and AST generation -├── tests/ # Test files (.txt format) -├── design/ # Architecture and design documentation -│ ├── ARCHITECTURE.md -│ ├── README.md -│ └── HISTORY/ # Historical implementation records -└── docs/ # Generated documentation -</code></pre> -<h3>Debug Mode</h3> -<p>Enable debug output for development:</p> -<pre class="prettyprint source lang-bash"><code>DEBUG=1 node lang.js your-script.txt -</code></pre> -<h3>Adding Features</h3> -<p>The language is designed to be extensible. To add new features:</p> -<ol> -<li><strong>Add tokens</strong> in <code>lexer.js</code></li> -<li><strong>Add parsing logic</strong> in <code>parser.js</code></li> -<li><strong>Add evaluation logic</strong> in <code>lang.js</code></li> -<li><strong>Add tests</strong> in <code>tests/</code></li> -<li><strong>Update documentation</strong></li> -</ol></article> - </section> - - - - - - -</div> - -<nav> - <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="REPL.html">REPL</a></li></ul> -</nav> - -<br class="clear"> - -<footer> - Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.4</a> on Tue Jul 29 2025 14:41:59 GMT-0400 (Eastern Daylight Time) -</footer> - -<script> prettyPrint(); </script> -<script src="scripts/linenumber.js"> </script> -</body> -</html> \ No newline at end of file |