diff options
Diffstat (limited to 'js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-04_Currying.html')
-rw-r--r-- | js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-04_Currying.html | 192 |
1 files changed, 0 insertions, 192 deletions
diff --git a/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-04_Currying.html b/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-04_Currying.html deleted file mode 100644 index 8583d14..0000000 --- a/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-04_Currying.html +++ /dev/null @@ -1,192 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="utf-8"> - <meta name="viewport" content="width=device-width,initial-scale=1"> - <title>04_Currying - 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">04_Currying</h1> - - - <section> - -<header> - -</header> - -<article> - <h1>Currying</h1> -<h2>What is Partial Application?</h2> -<p>Partial application means that functions automatically return new functions when called with fewer arguments than they expect. This is also called currying.</p> -<pre class="prettyprint source lang-plaintext"><code>/* Functions automatically return new functions when partially applied */ -add : x y -> x + y; -add_five : add 5; /* Returns a function that adds 5 */ -result : add_five 3; /* 8 */ -</code></pre> -<p>Most programming languages require explicit syntax for partial application or currying. When using Baba Yagay, every function is automatically curried.</p> -<h2>Basic Examples</h2> -<pre class="prettyprint source lang-plaintext"><code>/* Define a two-argument function */ -add : x y -> x + y; - -/* Call with both arguments */ -result1 : add 5 3; /* 8 */ - -/* Call with one argument - returns a new function */ -add_five : add 5; /* Returns: y -> 5 + y */ - -/* Call the returned function */ -result2 : add_five 3; /* 8 */ - -/* Chain partial applications */ -add_ten : add 10; /* y -> 10 + y */ -add_ten_five : add_ten 5; /* 15 */ -</code></pre> -<h2>How It Works</h2> -<p>Partial application happens automatically with nested function returns.</p> -<pre class="prettyprint source lang-plaintext"><code>/* When you define: add : x y -> x + y; */ -/* Baba Yaga creates: add = x -> (y -> x + y) */ - -/* When you call: add 5 */ -/* It returns: y -> 5 + y */ - -/* When you call: add 5 3 */ -/* It calls: (y -> 5 + y)(3) = 5 + 3 = 8 */ -</code></pre> -<p>Partial application works with any number of arguments.</p> -<pre class="prettyprint source lang-plaintext"><code>/* Three-argument function */ -multiply_add : x y z -> x * y + z; - -/* Partial application examples */ -multiply_by_two : multiply_add 2; /* y z -> 2 * y + z */ -multiply_by_two_add_ten : multiply_add 2 5; /* z -> 2 * 5 + z */ - -/* Full application */ -result1 : multiply_add 2 5 3; /* 2 * 5 + 3 = 13 */ -result2 : multiply_by_two 5 3; /* 2 * 5 + 3 = 13 */ -result3 : multiply_by_two_add_ten 3; /* 2 * 5 + 3 = 13 */ -</code></pre> -<p>All standard library functions support partial application, too!</p> -<pre class="prettyprint source lang-plaintext"><code>/* Arithmetic functions */ -double : multiply 2; /* x -> 2 * x */ -increment : add 1; /* x -> x + 1 */ -decrement : subtract 1; /* x -> x - 1 */ - -/* Comparison functions */ -is_positive : greaterThan 0; /* x -> x > 0 */ -is_even : equals 0; /* This won't work as expected - see below */ - -/* Logical functions */ -always_true : logicalOr true; /* x -> true || x */ -always_false : logicalAnd false; /* x -> false && x */ -</code></pre> -<h2>Common Patterns</h2> -<pre class="prettyprint source lang-plaintext"><code>/* Pattern 1: Creating specialized functions */ -numbers : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - -/* Create specialized filters */ -is_even : x -> x % 2 = 0; -is_odd : x -> x % 2 = 1; -is_greater_than_five : x -> x > 5; - -/* Use with map and filter - note the @ operator for higher-order functions */ -evens : filter @is_even numbers; /* {2, 4, 6, 8, 10} */ -odds : filter @is_odd numbers; /* {1, 3, 5, 7, 9} */ -large_numbers : filter @is_greater_than_five numbers; /* {6, 7, 8, 9, 10} */ - -/* Pattern 2: Creating transformation functions */ -double : multiply 2; -triple : multiply 3; -add_ten : add 10; - -/* Apply transformations - @ operator required for map */ -doubled : map @double numbers; /* {2, 4, 6, 8, 10, 12, 14, 16, 18, 20} */ -tripled : map @triple numbers; /* {3, 6, 9, 12, 15, 18, 21, 24, 27, 30} */ -plus_ten : map @add_ten numbers; /* {11, 12, 13, 14, 15, 16, 17, 18, 19, 20} */ -</code></pre> -<p>You can use partial application with function composition.</p> -<pre class="prettyprint source lang-plaintext"><code>/* Create specialized functions */ -double : multiply 2; -increment : add 1; -square : x -> x * x; - -/* Compose partially applied functions - @ operator required for compose */ -double_then_increment : compose @increment @double; -increment_then_square : compose @square @increment; - -/* Use in pipelines */ -result1 : double_then_increment 5; /* double(5)=10, increment(10)=11 */ -result2 : increment_then_square 5; /* increment(5)=6, square(6)=36 */ -</code></pre> -<h2>Table Operations with Partial Application</h2> -<p>The <code>t.</code> namespace functions also support partial application:</p> -<pre class="prettyprint source lang-plaintext"><code>/* Create specialized table operations */ -get_name : t.get "name"; -get_age : t.get "age"; -has_admin : t.has "admin"; - -/* Use with map - @ operator required for higher-order functions */ -people : { - alice: {name: "Alice", age: 30, admin: true}, - bob: {name: "Bob", age: 25, admin: false}, - charlie: {name: "Charlie", age: 35, admin: true} -}; - -names : map @get_name people; /* {alice: "Alice", bob: "Bob", charlie: "Charlie"} */ -ages : map @get_age people; /* {alice: 30, bob: 25, charlie: 35} */ -admins : map @has_admin people; /* {alice: true, bob: false, charlie: true} */ -</code></pre> -<h2>The <code>each</code> Combinator with Partial Application</h2> -<p>The <code>each</code> combinator works well with partial application:</p> -<pre class="prettyprint source lang-plaintext"><code>/* Create specialized comparison functions */ -is_greater_than_three : x -> x > 3; -is_less_than_seven : x -> x < 7; - -/* Use with each for element-wise comparison - @ operator required for each */ -numbers : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - -greater_than_three : each @is_greater_than_three numbers; -/* Result: {false, false, false, true, true, true, true, true, true, true} */ - -less_than_seven : each @is_less_than_seven numbers; -/* Result: {true, true, true, true, true, true, false, false, false, false} */ -</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 |