diff options
Diffstat (limited to 'js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-08_Combinators.html')
-rw-r--r-- | js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-08_Combinators.html | 276 |
1 files changed, 0 insertions, 276 deletions
diff --git a/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-08_Combinators.html b/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-08_Combinators.html deleted file mode 100644 index f5684e0..0000000 --- a/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-08_Combinators.html +++ /dev/null @@ -1,276 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="utf-8"> - <meta name="viewport" content="width=device-width,initial-scale=1"> - <title>08_Combinators - Documentation</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="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"> - <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> - <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> -</head> -<body> - -<input type="checkbox" id="nav-trigger" class="nav-trigger" /> -<label for="nav-trigger" class="navicon-button x"> - <div class="navicon"></div> -</label> - -<label for="nav-trigger" class="overlay"></label> - -<nav> - <li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading">Tutorials</li><li class="nav-item"><a href="tutorial-00_Introduction.html">00_Introduction</a></li><li class="nav-item"><a href="tutorial-01_Function_Calls.html">01_Function_Calls</a></li><li class="nav-item"><a href="tutorial-02_Function_Composition.html">02_Function_Composition</a></li><li class="nav-item"><a href="tutorial-03_Table_Operations.html">03_Table_Operations</a></li><li class="nav-item"><a href="tutorial-04_Currying.html">04_Currying</a></li><li class="nav-item"><a href="tutorial-05_Pattern_Matching.html">05_Pattern_Matching</a></li><li class="nav-item"><a href="tutorial-06_Immutable_Tables.html">06_Immutable_Tables</a></li><li class="nav-item"><a href="tutorial-07_Function_References.html">07_Function_References</a></li><li class="nav-item"><a href="tutorial-08_Combinators.html">08_Combinators</a></li><li class="nav-item"><a href="tutorial-09_Expression_Based.html">09_Expression_Based</a></li><li class="nav-item"><a href="tutorial-10_Tables_Deep_Dive.html">10_Tables_Deep_Dive</a></li><li class="nav-item"><a href="tutorial-11_Standard_Library.html">11_Standard_Library</a></li><li class="nav-item"><a href="tutorial-12_IO_Operations.html">12_IO_Operations</a></li><li class="nav-item"><a href="tutorial-13_Error_Handling.html">13_Error_Handling</a></li><li class="nav-item"><a href="tutorial-14_Advanced_Combinators.html">14_Advanced_Combinators</a></li><li class="nav-item"><a href="tutorial-15_Integration_Patterns.html">15_Integration_Patterns</a></li><li class="nav-item"><a href="tutorial-16_Best_Practices.html">16_Best_Practices</a></li><li class="nav-item"><a href="tutorial-README.html">README</a></li><li class="nav-heading"><a href="global.html">Globals</a></li><li class="nav-item"><span class="nav-item-type type-member">M</span><span class="nav-item-name"><a href="global.html#callStackTracker">callStackTracker</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#debugError">debugError</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#debugLog">debugLog</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#executeFile">executeFile</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#initializeStandardLibrary">initializeStandardLibrary</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#interpreter">interpreter</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#lexer">lexer</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#main">main</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#parser">parser</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#readFile">readFile</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#run">run</a></span></li> -</nav> - -<div id="main"> - - <h1 class="page-title">08_Combinators</h1> - - - <section> - -<header> - -</header> - -<article> - <h1>Combinator-Based Architecture</h1> -<h2>What is Combinator-Based Architecture?</h2> -<p>Combinator-based architecture means the entire language is built from simple, composable functions called <strong>combinators</strong>. There are no classes, no inheritance, no methods - everything is function composition.</p> -<pre class="prettyprint source lang-plaintext"><code>/* Everything is built from combinators */ -/* map, filter, reduce, compose, pipe, each, via */ -/* No classes, no inheritance, no methods */ -</code></pre> -<h2>Why is This Esoteric?</h2> -<p>Most programming languages are built around objects, classes, and methods. Our language is built entirely around <strong>function composition</strong> and <strong>combinators</strong> - a completely different paradigm.</p> -<h2>Core Combinators</h2> -<h3><code>map</code> - Transform Elements</h3> -<pre class="prettyprint source lang-plaintext"><code>/* map applies a function to every element in a collection */ -double : x -> x * 2; -numbers : {1, 2, 3, 4, 5}; -doubled : map @double numbers; /* {2, 4, 6, 8, 10} */ - -/* map works with any function */ -increment : x -> x + 1; -incremented : map @increment numbers; /* {2, 3, 4, 5, 6} */ -</code></pre> -<h3><code>filter</code> - Select Elements</h3> -<pre class="prettyprint source lang-plaintext"><code>/* filter keeps elements that satisfy a condition */ -is_even : x -> x % 2 = 0; -numbers : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; -evens : filter @is_even numbers; /* {2, 4, 6, 8, 10} */ - -/* filter with custom conditions */ -is_greater_than_five : x -> x > 5; -large_numbers : filter @is_greater_than_five numbers; /* {6, 7, 8, 9, 10} */ -</code></pre> -<h3><code>reduce</code> - Accumulate Elements</h3> -<pre class="prettyprint source lang-plaintext"><code>/* reduce combines all elements into a single value */ -numbers : {1, 2, 3, 4, 5}; -sum : reduce @add 0 numbers; /* 15 */ -product : reduce @multiply 1 numbers; /* 120 */ - -/* reduce with custom accumulation */ -max_value : reduce @max 0 numbers; /* 5 */ -min_value : reduce @min 1000 numbers; /* 1 */ -</code></pre> -<h3><code>each</code> - Multi-Argument Operations</h3> -<pre class="prettyprint source lang-plaintext"><code>/* each applies a function to corresponding elements from multiple collections */ -numbers1 : {1, 2, 3, 4, 5}; -numbers2 : {10, 20, 30, 40, 50}; - -/* Element-wise addition */ -sums : each @add numbers1 numbers2; /* {11, 22, 33, 44, 55} */ - -/* Element-wise multiplication */ -products : each @multiply numbers1 numbers2; /* {10, 40, 90, 160, 250} */ -</code></pre> -<h2>Function Composition Combinators</h2> -<h3><code>compose</code> - Mathematical Composition</h3> -<pre class="prettyprint source lang-plaintext"><code>/* compose(f, g)(x) = f(g(x)) */ -double : x -> x * 2; -increment : x -> x + 1; -square : x -> x * x; - -/* Compose functions */ -double_then_increment : compose @increment @double; -increment_then_square : compose @square @increment; - -/* Use composed functions */ -result1 : double_then_increment 5; /* double(5)=10, increment(10)=11 */ -result2 : increment_then_square 5; /* increment(5)=6, square(6)=36 */ -</code></pre> -<h3><code>pipe</code> - Pipeline Composition</h3> -<pre class="prettyprint source lang-plaintext"><code>/* pipe(f, g)(x) = g(f(x)) - left to right */ -double_then_square : pipe @double @square; -result : double_then_square 5; /* double(5)=10, square(10)=100 */ -</code></pre> -<h3><code>via</code> - Natural Composition</h3> -<pre class="prettyprint source lang-plaintext"><code>/* via provides natural composition syntax */ -complex_transform : double via increment via square; -result : complex_transform 3; /* square(3)=9, increment(9)=10, double(10)=20 */ -</code></pre> -<h2>Building Complex Operations</h2> -<h3>Data Processing Pipeline</h3> -<pre class="prettyprint source lang-plaintext"><code>/* Build complex operations from simple combinators */ -data : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - -/* Pipeline: filter → map → reduce */ -is_even : x -> x % 2 = 0; -double : x -> x * 2; -sum : x -> reduce @add 0 x; - -/* Combine combinators */ -pipeline : sum via map @double via filter @is_even; -result : pipeline data; /* 60 */ - -/* Step by step: - 1. filter @is_even data → {2, 4, 6, 8, 10} - 2. map @double {2, 4, 6, 8, 10} → {4, 8, 12, 16, 20} - 3. sum {4, 8, 12, 16, 20} → 60 -*/ -</code></pre> -<h3>Validation Chain</h3> -<pre class="prettyprint source lang-plaintext"><code>/* Build validation from combinators */ -validate_positive : x -> x > 0; -validate_even : x -> x % 2 = 0; -validate_small : x -> x < 10; - -/* Chain validations */ -all_validations : validate_small via validate_even via validate_positive; -result : all_validations 6; /* true (6 > 0, 6 % 2 = 0, 6 < 10) */ -</code></pre> -<h2>Table-Specific Combinators</h2> -<p>The <code>t.</code> namespace provides table-specific combinators:</p> -<pre class="prettyprint source lang-plaintext"><code>/* Table operations as combinators */ -data : {a: 1, b: 2, c: 3}; - -/* Get keys and values */ -keys : t.keys data; /* {"a", "b", "c"} */ -values : t.values data; /* {1, 2, 3} */ - -/* Check and get values */ -has_a : t.has data "a"; /* true */ -value_a : t.get data "a"; /* 1 */ - -/* Transform tables */ -with_d : t.set data "d" 4; /* {a: 1, b: 2, c: 3, d: 4} */ -without_b : t.delete data "b"; /* {a: 1, c: 3} */ - -/* Merge tables */ -table1 : {a: 1, b: 2}; -table2 : {c: 3, d: 4}; -merged : t.merge table1 table2; /* {a: 1, b: 2, c: 3, d: 4} */ -</code></pre> -<h2>Advanced Combinator Patterns</h2> -<h3>Function Factories</h3> -<pre class="prettyprint source lang-plaintext"><code>/* Create combinators that generate other combinators */ -create_multiplier : factor -> multiply factor; -double : create_multiplier 2; -triple : create_multiplier 3; - -/* Use generated combinators */ -numbers : {1, 2, 3, 4, 5}; -doubled : map @double numbers; /* {2, 4, 6, 8, 10} */ -tripled : map @triple numbers; /* {3, 6, 9, 12, 15} */ -</code></pre> -<h3>Conditional Combinators</h3> -<pre class="prettyprint source lang-plaintext"><code>/* Combinators that choose based on conditions */ -conditional_map : condition transform_false transform_true -> - when condition is - true then transform_true - _ then transform_false; - -/* Use conditional combinator */ -is_positive : x -> x > 0; -double : x -> x * 2; -square : x -> x * x; - -conditional_transform : conditional_map is_positive @square @double; -result : map conditional_transform {1, -2, 3, -4, 5}; -/* Result: {1, -4, 9, -8, 25} (positive numbers squared, negative doubled) */ -</code></pre> -<h3>Recursive Combinators</h3> -<pre class="prettyprint source lang-plaintext"><code>/* Combinators that can be applied recursively */ -repeat_transform : n transform -> - when n is - 0 then identity - _ then compose transform (repeat_transform (n - 1) transform); - -/* Use recursive combinator */ -double : x -> x * 2; -double_three_times : repeat_transform 3 @double; -result : double_three_times 5; /* 40 (5 * 2 * 2 * 2) */ -</code></pre> -<h2>When to Use Combinators</h2> -<p><strong>Use combinators when:</strong></p> -<ul> -<li>Processing collections of data</li> -<li>Building data transformation pipelines</li> -<li>Creating reusable function components</li> -<li>Working with functional programming patterns</li> -<li>Building complex operations from simple ones</li> -</ul> -<p><strong>Don't use combinators when:</strong></p> -<ul> -<li>You need side effects (combinators are pure)</li> -<li>You need complex object-oriented patterns</li> -<li>You're working with simple, one-off operations</li> -<li>You need imperative control flow</li> -</ul> -<h2>Common Patterns</h2> -<pre class="prettyprint source lang-plaintext"><code>/* Pattern 1: Data transformation pipeline */ -data : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - -/* Build pipeline from combinators */ -pipeline : sum via map @double via filter @is_even; -result : pipeline data; /* 60 */ - -/* Pattern 2: Validation pipeline */ -validate_user : user -> - all_validations : validate_email via validate_age via validate_name; - all_validations user; - -/* Pattern 3: Configuration builder */ -build_config : base_config overrides -> - t.merge base_config overrides; -</code></pre> -<h2>Key Takeaways</h2> -<ol> -<li><strong>Function composition</strong> - everything is built from function composition</li> -<li><strong>No objects</strong> - no classes, inheritance, or methods</li> -<li><strong>Composable</strong> - combinators can be combined into complex operations</li> -<li><strong>Pure functions</strong> - no side effects, predictable behavior</li> -<li><strong>Mathematical thinking</strong> - operations are mathematical transformations</li> -</ol> -<h2>Why This Matters</h2> -<p>Combinator-based architecture makes the language fundamentally different:</p> -<ul> -<li><strong>Mathematical foundation</strong> - based on function theory and category theory</li> -<li><strong>Composability</strong> - complex operations built from simple, reusable parts</li> -<li><strong>Predictability</strong> - pure functions with no side effects</li> -<li><strong>Functional thinking</strong> - encourages thinking in terms of transformations</li> -<li><strong>No state management</strong> - no mutable state to manage</li> -</ul> -<p>This architecture makes the language feel more like mathematical notation than traditional programming! 🚀</p> -</article> - -</section> - -</div> - -<br class="clear"> - -<footer> - Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a> on Tue Jul 29 2025 23:15:00 GMT-0400 (Eastern Daylight Time) using the Minami theme. -</footer> - -<script>prettyPrint();</script> -<script src="scripts/linenumber.js"></script> -</body> -</html> \ No newline at end of file |