diff options
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.html | 229 |
1 files changed, 0 insertions, 229 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 deleted file mode 100644 index 6b9df04..0000000 --- a/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-12_IO_Operations.html +++ /dev/null @@ -1,229 +0,0 @@ -<!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 "Hello, World!"; -..out 42; -..out true; -..out {name: "Alice", 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 "5 equals 5" 5 = 5; /* Passes */ -..assert "3 + 2 equals 5" 3 + 2 = 5; /* Passes */ -..assert "This will fail" 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 "factorial 0 = 1" factorial 0 = 1; -..assert "factorial 1 = 1" factorial 1 = 1; -..assert "factorial 5 = 120" 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 "user_created" {id: 123, name: "Alice"}; -..emit "data_processed" {count: 42, success: true}; -..emit "error_occurred" {message: "Invalid input", code: 400}; -</code></pre> -<h3>Listening for Events</h3> -<pre class="prettyprint source lang-plaintext"><code>/* Listen for specific events */ -..listen "user_created" handle_user_created; -..listen "data_processed" handle_data_processed; -..listen "error_occurred" handle_error; -</code></pre> -<h3>Event Handlers</h3> -<pre class="prettyprint source lang-plaintext"><code>/* Define event handlers */ -handle_user_created : user_data -> - ..out "New user created:"; - ..out user_data.name; - -handle_data_processed : result -> - when result.success is - true then ..out "Processing successful: " + result.count + " items" - false then ..out "Processing failed"; - -handle_error : error -> - ..out "Error: " + error.message; - ..out "Code: " + 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 "Enter your name: "; -..out "Hello, " + name + "!"; - -/* Read and process input */ -age_input : ..in "Enter your age: "; -age : parseInt age_input; -..out "You are " + age + " years old"; -</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 "Processing complete"; - ..emit "data_processed" result; - result; - -/* Avoid: Hidden side effects in pure functions */ -bad_transform : data -> - ..out "Processing..."; /* Side effect in "pure" 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 "0 is even" is_even 0 = true; -..assert "1 is not even" is_even 1 = false; -..assert "double 5 = 10" double 5 = 10; - -/* Test composed functions */ -doubled_evens : compose @double @is_even; -..assert "doubled_evens 6 = true" doubled_evens 6 = true; -</code></pre> -<h3>Structured Output</h3> -<pre class="prettyprint source lang-plaintext"><code>/* Use tables for structured output */ -user : {name: "Alice", age: 30, city: "NYC"}; -..out "User Profile:"; -..out " Name: " + user.name; -..out " Age: " + user.age; -..out " City: " + 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 "Processing " + t.length data + " items"; - -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 "Found " + t.length evens + " even numbers"; - -doubled : map @double evens; -..out "Doubled values:"; -..out doubled; - -total : sum doubled; -..out "Sum of doubled evens: " + total; - -/* Emit final result */ -..emit "processing_complete" {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 "division_error" {dividend: x, divisor: y}; - "Error: Division by zero" - _ 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 |