diff options
Diffstat (limited to 'js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-03_Table_Operations.html')
-rw-r--r-- | js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-03_Table_Operations.html | 166 |
1 files changed, 0 insertions, 166 deletions
diff --git a/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-03_Table_Operations.html b/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-03_Table_Operations.html deleted file mode 100644 index e6d372e..0000000 --- a/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-03_Table_Operations.html +++ /dev/null @@ -1,166 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="utf-8"> - <meta name="viewport" content="width=device-width,initial-scale=1"> - <title>03_Table_Operations - 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">03_Table_Operations</h1> - - - <section> - -<header> - -</header> - -<article> - <h1>Table Operations</h1> -<h2>What are Element-Wise Operations?</h2> -<p>Element-wise operations automatically apply functions to every element in a table without explicit loops or iteration syntax like <code>forEach</code>.</p> -<pre class="prettyprint source lang-plaintext"><code>/* Instead of for each element in table, apply function */ -/* You write function table */ -numbers : {1, 2, 3, 4, 5}; -doubled : map @double numbers; /* {2, 4, 6, 8, 10} */ -</code></pre> -<p>Most main-stream programming languages require explicit loops or iteration. Baba Yaga takes a clue from array languages like APL, BQN, uiua, K, etc., and automatically handles element-wise operations.</p> -<h2>Basic Examples</h2> -<pre class="prettyprint source lang-plaintext"><code>/* Define a simple function */ -double : x -> x * 2; - -/* Apply to table elements automatically */ -numbers : {1, 2, 3, 4, 5}; -result : map @double numbers; -/* Result: {2, 4, 6, 8, 10} */ - -/* Filter elements automatically */ -is_even : x -> x % 2 = 0; -evens : filter @is_even numbers; -/* Result: {2, 4} */ - -/* Reduce all elements automatically */ -sum : reduce @add 0 numbers; -/* Result: 15 (1+2+3+4+5) */ -</code></pre> -<h2>Table-Specific Operations</h2> -<p>The <code>t.</code> namespace provides additional element-wise operations especially meant for tables.</p> -<pre class="prettyprint source lang-plaintext"><code>/* Table-specific operations */ -data : {a: 1, b: 2, c: 3}; - -/* Get all keys */ -keys : t.keys data; /* {"a", "b", "c"} */ - -/* Get all values */ -values : t.values data; /* {1, 2, 3} */ - -/* Get key-value pairs */ -pairs : t.pairs data; /* {{key: "a", value: 1}, {key: "b", value: 2}, {key: "c", value: 3}} */ - -/* Check if key exists */ -has_a : t.has data "a"; /* true */ -has_d : t.has data "d"; /* false */ - -/* Get value by key */ -value_a : t.get data "a"; /* 1 */ -</code></pre> -<h2>Complex Examples</h2> -<pre class="prettyprint source lang-plaintext"><code>/* Data processing pipeline */ -data : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - -/* Define helper functions */ -is_even : x -> x % 2 = 0; -double : x -> x * 2; -sum : x -> reduce @add 0 x; - -/* Complete pipeline: filter → map → reduce */ -result : sum map double filter is_even data; -/* Step 1: filter @is_even data → {2, 4, 6, 8, 10} */ -/* Step 2: map @double {2, 4, 6, 8, 10} → {4, 8, 12, 16, 20} */ -/* Step 3: sum {4, 8, 12, 16, 20} → 60 */ -/* Result: 60 */ -</code></pre> -<h2>Nested Tables</h2> -<p>Element-wise operations work with nested table structures, too</p> -<pre class="prettyprint source lang-plaintext"><code>/* Nested table */ -people : { - alice: {name: "Alice", age: 30, scores: {85, 90, 88}}, - bob: {name: "Bob", age: 25, scores: {92, 87, 95}}, - charlie: {name: "Charlie", age: 35, scores: {78, 85, 82}} -}; - -/* Extract ages */ -ages : map (x -> x.age) people; -/* Result: {alice: 30, bob: 25, charlie: 35} */ - -/* Calculate average scores for each person */ -get_average : person -> reduce add 0 person.scores / 3; -averages : map get_average people; -/* Result: {alice: 87.67, bob: 91.33, charlie: 81.67} */ -</code></pre> -<h2>The <code>each</code> Combinator</h2> -<p>The <code>each</code> combinator provides multi-argument element-wise operations:</p> -<pre class="prettyprint source lang-plaintext"><code>/* each for multi-argument operations */ -numbers : {1, 2, 3, 4, 5}; -multipliers : {10, 20, 30, 40, 50}; - -/* Multiply corresponding elements */ -result : each @multiply numbers multipliers; -/* Result: {10, 40, 90, 160, 250} */ - -/* Compare corresponding elements */ -is_greater : each @greaterThan numbers {3, 3, 3, 3, 3}; -/* Result: {false, false, false, true, true} */ -</code></pre> -<h2>Immutability</h2> -<p>All element-wise operations return new tables. In Baba Yaga all values, including tables are immutable.</p> -<pre class="prettyprint source lang-plaintext"><code>/* Original table */ -original : {a: 1, b: 2, c: 3}; - -/* Operations return new tables */ -doubled : map @double original; /* {a: 2, b: 4, c: 6} */ -greater_then : x -> x > 1; -filtered : filter @greater_then original; /* {b: 2, c: 3} */ - -/* Original is unchanged */ -/* original is still {a: 1, b: 2, c: 3} */ -</code></pre> -</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 |