about summary refs log tree commit diff stats
path: root/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-01_Function_Calls.html
diff options
context:
space:
mode:
Diffstat (limited to 'js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-01_Function_Calls.html')
-rw-r--r--js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-01_Function_Calls.html203
1 files changed, 203 insertions, 0 deletions
diff --git a/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-01_Function_Calls.html b/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-01_Function_Calls.html
new file mode 100644
index 0000000..7614571
--- /dev/null
+++ b/js/scripting-lang/docs/baba-yaga/0.0.1/tutorial-01_Function_Calls.html
@@ -0,0 +1,203 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width,initial-scale=1">
+    <title>01_Function_Calls - 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">01_Function_Calls</h1>
+    
+
+    <section>
+
+<header>
+    
+</header>
+
+<article>
+    <h1>Function Calls</h1>
+<h2>What is Juxtaposition?</h2>
+<p>In Baba Yaga you call functions by putting them next to each other.</p>
+<pre class="prettyprint source lang-plaintext"><code>/* 
+   JavaScript: f(x, y)
+    Baba Yaga: f x y
+*/
+</code></pre>
+<h2>Basic Examples</h2>
+<pre class="prettyprint source lang-plaintext"><code>/* Simple function calls */
+add 5 3;           /* Instead of add(5, 3) */
+multiply 4 7;      /* Instead of multiply(4, 7) */
+subtract 10 3;     /* Instead of subtract(10, 3) */
+
+/* Function calls with tables */
+/* ...we'll talk more about @ in a bit */ 
+map @double {1, 2, 3, 4, 5};
+filter @is_even {1, 2, 3, 4, 5, 6};
+reduce @add 0 {1, 2, 3, 4, 5};
+</code></pre>
+<h2>How It Works</h2>
+<p>The parser automatically translates juxtaposition into nested calls to <code>apply</code>, so that</p>
+<pre class="prettyprint source lang-plaintext"><code>/* f x y becomes: apply(apply(f, x), y) */
+/* map double {1, 2, 3} becomes: apply(apply(map, double), {1, 2, 3}) */
+</code></pre>
+<h2>Precedence Rules</h2>
+<p>Juxtaposition has lower precedence than operators,</p>
+<pre class="prettyprint source lang-plaintext"><code>result : add 5 multiply 3 4;
+/* Parsed as: add 5 (multiply 3 4) */
+/* Result: 5 + (3 * 4) = 17 */
+/* Not as: (add 5 multiply) 3 4 */
+</code></pre>
+<p>With Baba Yaga you'll use juxtaposition when you</p>
+<ul>
+<li>call functions with arguments</li>
+<li>build function composition chains</li>
+<li>work with combinators like <code>map</code>, <code>filter</code>, <code>reduce</code></li>
+</ul>
+<p>You won't use it, exactly, when you are</p>
+<ul>
+<li>defining functions (use <code>:</code> and <code>-&gt;</code>)</li>
+<li>assigning values (use <code>:</code>)</li>
+<li>using operators (use <code>+</code>, <code>-</code>, <code>*</code>, etc.)</li>
+</ul>
+<h2>Common Patterns</h2>
+<pre class="prettyprint source lang-plaintext"><code>/* Data processing pipeline */
+data : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+is_even : x -> x % 2 = 0;
+double : x -> x * 2;
+sum : x -> reduce add 0 x;
+
+/* Pipeline using juxtaposition */
+result : sum map double filter is_even data;
+/* Reads: sum (map double (filter is_even data)) */
+/* Result: 60 */
+</code></pre>
+<h2>Using Parentheses for Control</h2>
+<p>Juxtaposition eliminates the need for parentheses in most cases, parentheses are available for when you need explicit control over precedence or grouping.</p>
+<pre class="prettyprint source lang-plaintext"><code>/* Without parentheses - left-associative */
+result1 : add 5 multiply 3 4;
+/* Parsed as: add 5 (multiply 3 4) */
+/* Result: 5 + (3 * 4) = 17 */
+
+/* With parentheses - explicit grouping */
+result2 : add (add 1 2) (multiply 3 4);
+/* Explicitly: (1 + 2) + (3 * 4) = 3 + 12 = 15 */
+
+/* Complex nested operations */
+result3 : map double (filter is_even (map increment {1, 2, 3, 4, 5}));
+/* Step by step:
+   1. map increment {1, 2, 3, 4, 5} → {2, 3, 4, 5, 6}
+   2. filter is_even {2, 3, 4, 5, 6} → {2, 4, 6}
+   3. map double {2, 4, 6} → {4, 8, 12}
+*/
+
+/* Hard to read without parentheses */
+complex : map double filter is_even map increment {1, 2, 3, 4, 5};
+
+/* Much clearer with parentheses */
+complex : map double (filter is_even (map increment {1, 2, 3, 4, 5}));
+
+/* Or break it into steps for maximum clarity */
+step1 : map increment {1, 2, 3, 4, 5};
+step2 : filter is_even step1;
+step3 : map double step2;
+</code></pre>
+<p>Parentheses are also helpful for debugging because they let you isolate specific pieces of a program or chain.</p>
+<pre class="prettyprint source lang-plaintext"><code>data : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+
+/* Test each step separately */
+filtered : filter @is_even data;
+doubled : map @double filtered;
+final : reduce @add 0 doubled;
+
+/* Or use parentheses to test intermediate results */
+test1 : filter is_even data;               /* {2, 4, 6, 8, 10} */
+test2 : map double (filter is_even data);  /* {4, 8, 12, 16, 20} */
+</code></pre>
+<h2>Spacing Rules</h2>
+<p>Baba Yaga uses spacing to distinguish between unary and binary operators...mostly just minus.</p>
+<ul>
+<li><strong>Unary minus</strong>: <code>-5</code> (no leading space) → <code>negate(5)</code></li>
+<li><strong>Binary minus</strong>: <code>5 - 3</code> (spaces required) → <code>subtract(5, 3)</code></li>
+<li><strong>Legacy fallback</strong>: <code>5-3</code> → <code>subtract(5, 3)</code> (but spaces are recommended)</li>
+</ul>
+<p>The parser distinguishes between these scenarios based off of spaces, and kinda best guess heuristics. It <em>should</em> work as expected in most cases.</p>
+<ul>
+<li><strong>Unary minus</strong> (negative numbers): <code>-5</code> → <code>negate(5)</code></li>
+<li><strong>Binary minus</strong> (subtraction): <code>5 - 3</code> → <code>subtract(5, 3)</code></li>
+</ul>
+<p>Spacing makes expressions less ambiguous.</p>
+<h3>Common Patterns</h3>
+<pre class="prettyprint source lang-plaintext"><code>/* Function calls with negative numbers */
+double : x -> x * 2;
+result : double -5;      /* unary minus */
+result2 : double (-5);   /* explicit grouping */
+
+/* Comparisons with negative numbers */
+is_negative : x -> x &lt; 0;
+test1 : is_negative -5;  /* unary minus */
+
+/* Complex expressions with negative numbers */
+validate_age : age -> (age >= 0) and (age &lt;= 120);
+test2 : validate_age -5; /* unary minus */
+
+/* Arithmetic with proper spacing */
+result3 : -5 + 3;        /* unary minus + binary plus */
+result4 : 5 - 3;         /* binary minus with spaces */
+result5 : (-5) + 3;      /* explicit grouping */
+</code></pre>
+<h4>Best Practices</h4>
+<ul>
+<li><strong>Use spaces around binary operators</strong>: <code>5 - 3</code>, <code>5 + 3</code>, <code>5 * 3</code></li>
+<li><strong>Unary minus works without parentheses</strong>: <code>-5</code>, <code>f -5</code></li>
+<li><strong>Legacy syntax still works</strong>: <code>(-5)</code>, <code>5-3</code> (but spaces are recommended)</li>
+<li><strong>When in doubt, use spaces</strong>: It makes code more readable and follows conventions</li>
+</ul>
+<h4>When You Might Encounter This</h4>
+<ul>
+<li><strong>Arithmetic operations</strong>: <code>-5 + 3</code>, <code>5 - 3</code>, <code>(-5) + 3</code></li>
+<li><strong>Comparisons</strong>: <code>-5 &gt;= 0</code>, <code>5 - 3 &gt;= 0</code></li>
+<li><strong>Function calls</strong>: <code>f -5</code>, <code>f (-5)</code>, <code>map double -3</code></li>
+<li><strong>Logical expressions</strong>: <code>(-5 &gt;= 0) and (-5 &lt;= 120)</code></li>
+<li><strong>Pattern matching</strong>: <code>when x is -5 then &quot;negative five&quot;</code></li>
+</ul>
+<p>To make everyone's life easier, use spaces around binary operators.</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