about summary refs log tree commit diff stats
path: root/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-06_Immutable_Tables.html
diff options
context:
space:
mode:
Diffstat (limited to 'js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-06_Immutable_Tables.html')
-rw-r--r--js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-06_Immutable_Tables.html266
1 files changed, 266 insertions, 0 deletions
diff --git a/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-06_Immutable_Tables.html b/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-06_Immutable_Tables.html
new file mode 100644
index 0000000..3829487
--- /dev/null
+++ b/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-06_Immutable_Tables.html
@@ -0,0 +1,266 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width,initial-scale=1">
+    <title>06_Immutable_Tables - 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">06_Immutable_Tables</h1>
+    
+
+    <section>
+
+<header>
+    
+</header>
+
+<article>
+    <h1>Immutable Tables with Functional Operations</h1>
+<h2>What are Immutable Tables?</h2>
+<p>Immutable tables are data structures that <strong>cannot be modified after creation</strong>. All operations on tables return <strong>new tables</strong> rather than modifying the original.</p>
+<pre class="prettyprint source lang-plaintext"><code>/* All table operations return new tables */
+original : {a: 1, b: 2, c: 3};
+modified : t.set original &quot;d&quot; 4;  /* Returns new table */
+/* original is unchanged: {a: 1, b: 2, c: 3} */
+/* modified is: {a: 1, b: 2, c: 3, d: 4} */
+</code></pre>
+<h2>Why is This Esoteric?</h2>
+<p>Most programming languages allow direct modification of data structures. Our language enforces <strong>complete immutability</strong> - no mutation operations exist at all.</p>
+<h2>Basic Examples</h2>
+<pre class="prettyprint source lang-plaintext"><code>/* Create a table */
+original : {name: &quot;Alice&quot;, age: 30, city: &quot;New York&quot;};
+
+/* All operations return new tables */
+with_job : t.set original &quot;job&quot; &quot;Engineer&quot;;
+with_updated_age : t.set original &quot;age&quot; 31;
+without_city : t.delete original &quot;city&quot;;
+
+/* Original table is unchanged */
+/* original is still {name: &quot;Alice&quot;, age: 30, city: &quot;New York&quot;} */
+</code></pre>
+<h2>Table Operations</h2>
+<h3>Setting Values</h3>
+<pre class="prettyprint source lang-plaintext"><code>/* t.set table key value - returns new table with key set */
+data : {a: 1, b: 2};
+updated : t.set data &quot;c&quot; 3;
+/* updated: {a: 1, b: 2, c: 3} */
+/* data: {a: 1, b: 2} (unchanged) */
+</code></pre>
+<h3>Deleting Keys</h3>
+<pre class="prettyprint source lang-plaintext"><code>/* t.delete table key - returns new table without the key */
+data : {a: 1, b: 2, c: 3};
+without_b : t.delete data &quot;b&quot;;
+/* without_b: {a: 1, c: 3} */
+/* data: {a: 1, b: 2, c: 3} (unchanged) */
+</code></pre>
+<h3>Merging Tables</h3>
+<pre class="prettyprint source lang-plaintext"><code>/* t.merge table1 table2 - returns new table with combined keys */
+table1 : {a: 1, b: 2};
+table2 : {c: 3, d: 4};
+merged : t.merge table1 table2;
+/* merged: {a: 1, b: 2, c: 3, d: 4} */
+/* table1 and table2 unchanged */
+</code></pre>
+<h3>Getting Values</h3>
+<pre class="prettyprint source lang-plaintext"><code>/* t.get table key - returns value (doesn't modify table) */
+data : {name: &quot;Alice&quot;, age: 30};
+name : t.get data &quot;name&quot;;  /* &quot;Alice&quot; */
+age : t.get data &quot;age&quot;;    /* 30 */
+/* data unchanged */
+</code></pre>
+<h3>Checking Keys</h3>
+<pre class="prettyprint source lang-plaintext"><code>/* t.has table key - returns boolean (doesn't modify table) */
+data : {name: &quot;Alice&quot;, age: 30};
+has_name : t.has data &quot;name&quot;;    /* true */
+has_job : t.has data &quot;job&quot;;      /* false */
+/* data unchanged */
+</code></pre>
+<h2>Element-Wise Operations</h2>
+<p>All element-wise operations return new tables:</p>
+<pre class="prettyprint source lang-plaintext"><code>/* map returns new table - @ operator required for higher-order functions */
+numbers : {a: 1, b: 2, c: 3};
+double : x -> x * 2;
+doubled : map @double numbers;  /* {a: 2, b: 4, c: 6} */
+/* numbers unchanged: {a: 1, b: 2, c: 3} */
+
+/* filter returns new table - @ operator required for higher-order functions */
+is_greater_than_one : x -> x > 1;
+filtered : filter @is_greater_than_one numbers;  /* {b: 2, c: 3} */
+/* numbers unchanged: {a: 1, b: 2, c: 3} */
+</code></pre>
+<h2>Complex Examples</h2>
+<pre class="prettyprint source lang-plaintext"><code>/* Building complex tables immutably */
+base_user : {name: &quot;Alice&quot;, age: 30};
+
+/* Add multiple properties */
+with_email : t.set base_user &quot;email&quot; &quot;alice@example.com&quot;;
+with_address : t.set with_email &quot;address&quot; &quot;123 Main St&quot;;
+with_phone : t.set with_address &quot;phone&quot; &quot;555-1234&quot;;
+
+/* Or merge with another table */
+contact_info : {email: &quot;alice@example.com&quot;, phone: &quot;555-1234&quot;};
+complete_user : t.merge base_user contact_info;
+/* Result: {name: &quot;Alice&quot;, age: 30, email: &quot;alice@example.com&quot;, phone: &quot;555-1234&quot;} */
+</code></pre>
+<h2>Nested Tables</h2>
+<p>Immutability works with nested table structures:</p>
+<pre class="prettyprint source lang-plaintext"><code>/* Nested table */
+user : {
+  name: &quot;Alice&quot;,
+  profile: {
+    age: 30,
+    preferences: {
+      theme: &quot;dark&quot;,
+      notifications: true
+    }
+  }
+};
+
+/* Update nested property - creates new nested structure */
+updated_preferences : t.set user.profile.preferences &quot;theme&quot; &quot;light&quot;;
+/* This creates new tables at each level */
+/* user unchanged, updated_preferences has new nested structure */
+</code></pre>
+<h2>Functional Programming Patterns</h2>
+<p>Immutability enables pure functional programming patterns:</p>
+<pre class="prettyprint source lang-plaintext"><code>/* Pure function - no side effects */
+update_age : user new_age -> t.set user &quot;age&quot; new_age;
+
+/* Multiple updates create new tables */
+user1 : {name: &quot;Alice&quot;, age: 30};
+user2 : update_age user1 31;
+user3 : update_age user2 32;
+
+/* All tables exist independently */
+/* user1: {name: &quot;Alice&quot;, age: 30} */
+/* user2: {name: &quot;Alice&quot;, age: 31} */
+/* user3: {name: &quot;Alice&quot;, age: 32} */
+</code></pre>
+<h2>When to Use Immutable Tables</h2>
+<p><strong>Use immutable tables when:</strong></p>
+<ul>
+<li>You want to prevent accidental data modification</li>
+<li>You're building functional programming patterns</li>
+<li>You need to track data changes over time</li>
+<li>You want to ensure thread safety (if applicable)</li>
+<li>You're working with complex data transformations</li>
+</ul>
+<p><strong>Don't use immutable tables when:</strong></p>
+<ul>
+<li>You need to modify data in place for performance reasons</li>
+<li>You're working with very large datasets that can't be copied</li>
+<li>You need to perform side effects on data structures</li>
+</ul>
+<h2>Common Patterns</h2>
+<pre class="prettyprint source lang-plaintext"><code>/* Pattern 1: Building up data structures */
+base_config : {debug: false, timeout: 30};
+
+/* Add development settings */
+dev_config : t.merge base_config {
+  debug: true,
+  log_level: &quot;verbose&quot;
+};
+
+/* Add production settings */
+prod_config : t.merge base_config {
+  timeout: 60,
+  cache_enabled: true
+};
+
+/* Pattern 2: Data transformation pipeline */
+user_data : {name: &quot;Alice&quot;, age: 30, scores: {85, 90, 88}};
+
+/* Transform user data */
+with_average : t.set user_data &quot;average_score&quot; (reduce @add 0 user_data.scores / 3);
+with_grade : t.set with_average &quot;grade&quot; (when with_average.average_score is
+  when with_average.average_score >= 90 then &quot;A&quot;
+  when with_average.average_score >= 80 then &quot;B&quot;
+  _ then &quot;C&quot;);
+
+/* Pattern 3: State management */
+initial_state : {count: 0, items: {}};
+
+/* State transitions */
+increment_state : state -> t.set state &quot;count&quot; (state.count + 1);
+add_item_state : state item -> t.set state &quot;items&quot; (t.set state.items item.id item);
+
+/* Apply transitions */
+state1 : increment_state initial_state;
+state2 : add_item_state state1 {id: &quot;item1&quot;, name: &quot;First Item&quot;};
+</code></pre>
+<h2>Performance Considerations</h2>
+<pre class="prettyprint source lang-plaintext"><code>/* Immutability can be expensive for large tables */
+large_table : {/* ... many entries ... */};
+
+/* Each operation creates a new copy */
+updated1 : t.set large_table &quot;key&quot; &quot;value&quot;;
+updated2 : t.set updated1 &quot;key2&quot; &quot;value2&quot;;
+/* This creates multiple copies of the large table */
+
+/* Consider batching operations */
+batch_update : table -> t.merge table {
+  key1: &quot;value1&quot;,
+  key2: &quot;value2&quot;,
+  key3: &quot;value3&quot;
+};
+/* Single operation instead of multiple */
+</code></pre>
+<h2>Key Takeaways</h2>
+<ol>
+<li><strong>Complete immutability</strong> - no mutation operations exist</li>
+<li><strong>New tables returned</strong> - all operations return new data structures</li>
+<li><strong>Original unchanged</strong> - source tables are never modified</li>
+<li><strong>Functional patterns</strong> - enables pure functional programming</li>
+<li><strong>Composable operations</strong> - operations can be chained safely</li>
+<li><strong>@ operator required</strong> - for higher-order functions like <code>map</code>, <code>filter</code>, <code>reduce</code></li>
+</ol>
+<h2>Why This Matters</h2>
+<p>Immutable tables make the language safer and more functional:</p>
+<ul>
+<li><strong>No side effects</strong> - functions can't accidentally modify data</li>
+<li><strong>Predictable behavior</strong> - data never changes unexpectedly</li>
+<li><strong>Functional style</strong> - encourages pure functions and composition</li>
+<li><strong>Debugging ease</strong> - data state is always predictable</li>
+<li><strong>Thread safety</strong> - no shared mutable state issues</li>
+</ul>
+<p>This feature makes the language feel more like pure functional languages like Haskell! 🚀</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