about summary refs log tree commit diff stats
path: root/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-12_IO_Operations.html
diff options
context:
space:
mode:
Diffstat (limited to 'js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-12_IO_Operations.html')
-rw-r--r--js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-12_IO_Operations.html229
1 files changed, 229 insertions, 0 deletions
diff --git a/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-12_IO_Operations.html b/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-12_IO_Operations.html
new file mode 100644
index 0000000..6b9df04
--- /dev/null
+++ b/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-12_IO_Operations.html
@@ -0,0 +1,229 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width,initial-scale=1">
+    <title>12_IO_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">12_IO_Operations</h1>
+    
+
+    <section>
+
+<header>
+    
+</header>
+
+<article>
+    <h1>IO Operations</h1>
+<h2>What are IO Operations?</h2>
+<p>IO (Input/Output) operations allow your functional programs to interact with the outside world. Baba Yaga provides a minimal set of IO operations that keep side effects contained and explicit.</p>
+<h2>Basic Output</h2>
+<h3>Simple Output</h3>
+<pre class="prettyprint source lang-plaintext"><code>/* Output values to console */
+..out &quot;Hello, World!&quot;;
+..out 42;
+..out true;
+..out {name: &quot;Alice&quot;, age: 30};
+</code></pre>
+<h3>Output with Expressions</h3>
+<pre class="prettyprint source lang-plaintext"><code>/* Output computed values */
+result : 5 + 3 * 2;
+..out result;  /* Output: 11 */
+
+/* Output function results */
+double : x -> x * 2;
+..out double 7;  /* Output: 14 */
+
+/* Output table operations */
+numbers : {1, 2, 3, 4, 5};
+doubled : map @double numbers;
+..out doubled;  /* Output: {2, 4, 6, 8, 10} */
+</code></pre>
+<h2>Assertions</h2>
+<p>Assertions help you verify your program's behavior:</p>
+<pre class="prettyprint source lang-plaintext"><code>/* Basic assertions */
+..assert 5 = 5;                    /* Passes */
+..assert 3 + 2 = 5;                /* Passes */
+..assert true;                     /* Passes */
+..assert false;                    /* Fails with error */
+
+/* Assertions with messages */
+..assert &quot;5 equals 5&quot; 5 = 5;       /* Passes */
+..assert &quot;3 + 2 equals 5&quot; 3 + 2 = 5; /* Passes */
+..assert &quot;This will fail&quot; 1 = 2;   /* Fails with message */
+</code></pre>
+<h3>Testing Functions</h3>
+<pre class="prettyprint source lang-plaintext"><code>/* Test function behavior */
+factorial : n -> 
+  when n is
+    0 then 1
+    _ then n * (factorial (n - 1));
+
+/* Test cases */
+..assert &quot;factorial 0 = 1&quot; factorial 0 = 1;
+..assert &quot;factorial 1 = 1&quot; factorial 1 = 1;
+..assert &quot;factorial 5 = 120&quot; factorial 5 = 120;
+</code></pre>
+<h2>Emit and Listen Pattern</h2>
+<p>The <code>..emit</code> and <code>..listen</code> pattern provides a way to interface functional code with external systems:</p>
+<h3>Emitting Events</h3>
+<pre class="prettyprint source lang-plaintext"><code>/* Emit events with data */
+..emit &quot;user_created&quot; {id: 123, name: &quot;Alice&quot;};
+..emit &quot;data_processed&quot; {count: 42, success: true};
+..emit &quot;error_occurred&quot; {message: &quot;Invalid input&quot;, code: 400};
+</code></pre>
+<h3>Listening for Events</h3>
+<pre class="prettyprint source lang-plaintext"><code>/* Listen for specific events */
+..listen &quot;user_created&quot; handle_user_created;
+..listen &quot;data_processed&quot; handle_data_processed;
+..listen &quot;error_occurred&quot; handle_error;
+</code></pre>
+<h3>Event Handlers</h3>
+<pre class="prettyprint source lang-plaintext"><code>/* Define event handlers */
+handle_user_created : user_data -> 
+  ..out &quot;New user created:&quot;;
+  ..out user_data.name;
+
+handle_data_processed : result -> 
+  when result.success is
+    true then ..out &quot;Processing successful: &quot; + result.count + &quot; items&quot;
+    false then ..out &quot;Processing failed&quot;;
+
+handle_error : error -> 
+  ..out &quot;Error: &quot; + error.message;
+  ..out &quot;Code: &quot; + error.code;
+</code></pre>
+<h2>Input Operations</h2>
+<h3>Reading Input</h3>
+<pre class="prettyprint source lang-plaintext"><code>/* Read input from user */
+name : ..in &quot;Enter your name: &quot;;
+..out &quot;Hello, &quot; + name + &quot;!&quot;;
+
+/* Read and process input */
+age_input : ..in &quot;Enter your age: &quot;;
+age : parseInt age_input;
+..out &quot;You are &quot; + age + &quot; years old&quot;;
+</code></pre>
+<h2>IO Best Practices</h2>
+<h3>Keep Side Effects Explicit</h3>
+<pre class="prettyprint source lang-plaintext"><code>/* Good: Clear IO operations */
+process_data : data -> 
+  result : transform data;
+  ..out &quot;Processing complete&quot;;
+  ..emit &quot;data_processed&quot; result;
+  result;
+
+/* Avoid: Hidden side effects in pure functions */
+bad_transform : data -> 
+  ..out &quot;Processing...&quot;;  /* Side effect in &quot;pure&quot; function */
+  data * 2;
+</code></pre>
+<h3>Use Assertions for Testing</h3>
+<pre class="prettyprint source lang-plaintext"><code>/* Test your functions thoroughly */
+is_even : x -> x % 2 = 0;
+double : x -> x * 2;
+
+/* Test individual functions */
+..assert &quot;0 is even&quot; is_even 0 = true;
+..assert &quot;1 is not even&quot; is_even 1 = false;
+..assert &quot;double 5 = 10&quot; double 5 = 10;
+
+/* Test composed functions */
+doubled_evens : compose @double @is_even;
+..assert &quot;doubled_evens 6 = true&quot; doubled_evens 6 = true;
+</code></pre>
+<h3>Structured Output</h3>
+<pre class="prettyprint source lang-plaintext"><code>/* Use tables for structured output */
+user : {name: &quot;Alice&quot;, age: 30, city: &quot;NYC&quot;};
+..out &quot;User Profile:&quot;;
+..out &quot;  Name: &quot; + user.name;
+..out &quot;  Age: &quot; + user.age;
+..out &quot;  City: &quot; + user.city;
+
+/* Or output the entire structure */
+..out user;
+</code></pre>
+<h2>Common Patterns</h2>
+<h3>Data Processing Pipeline</h3>
+<pre class="prettyprint source lang-plaintext"><code>/* Process data with IO feedback */
+data : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+..out &quot;Processing &quot; + t.length data + &quot; items&quot;;
+
+is_even : x -> x % 2 = 0;
+double : x -> x * 2;
+sum : x -> reduce @add 0 x;
+
+/* Process with progress updates */
+evens : filter @is_even data;
+..out &quot;Found &quot; + t.length evens + &quot; even numbers&quot;;
+
+doubled : map @double evens;
+..out &quot;Doubled values:&quot;;
+..out doubled;
+
+total : sum doubled;
+..out &quot;Sum of doubled evens: &quot; + total;
+
+/* Emit final result */
+..emit &quot;processing_complete&quot; {input_count: t.length data, result: total};
+</code></pre>
+<h3>Error Handling</h3>
+<pre class="prettyprint source lang-plaintext"><code>/* Handle potential errors gracefully */
+safe_divide : x y -> 
+  when y = 0 then 
+    ..emit &quot;division_error&quot; {dividend: x, divisor: y};
+    &quot;Error: Division by zero&quot;
+  _ then x / y;
+
+/* Test error handling */
+..out safe_divide 10 2;   /* 5 */
+..out safe_divide 10 0;   /* Error: Division by zero */
+</code></pre>
+<h2>Next Steps</h2>
+<p>Now that you understand IO operations, explore:</p>
+<ul>
+<li><a href="13_Error_Handling.md">Error Handling</a> for robust error management</li>
+<li><a href="15_Integration_Patterns.md">Integration Patterns</a> for external system integration</li>
+<li><a href="16_Best_Practices.md">Best Practices</a> for writing clean code</li>
+</ul>
+</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