diff options
-rw-r--r-- | continuation1.mu | 5 | ||||
-rw-r--r-- | continuation2.mu | 5 | ||||
-rw-r--r-- | continuation3.mu | 5 | ||||
-rw-r--r-- | continuation4.mu | 5 | ||||
-rw-r--r-- | continuation5.mu | 5 | ||||
-rw-r--r-- | html/continuation1.mu.html | 37 | ||||
-rw-r--r-- | html/continuation2.mu.html | 63 | ||||
-rw-r--r-- | html/continuation3.mu.html | 57 | ||||
-rw-r--r-- | html/continuation4.mu.html | 79 | ||||
-rw-r--r-- | html/continuation5.mu.html | 81 |
10 files changed, 196 insertions, 146 deletions
diff --git a/continuation1.mu b/continuation1.mu index 8e9b1d03..47d036fa 100644 --- a/continuation1.mu +++ b/continuation1.mu @@ -2,6 +2,11 @@ # function call, returning a continuation, and that calling the continuation # can 'resume' the paused function call. # +# To run: +# $ git clone https://github.com/akkartik/mu +# $ cd mu +# $ ./mu continuation1.mu +# # Expected output: # 1 diff --git a/continuation2.mu b/continuation2.mu index a522b0bf..0e698aec 100644 --- a/continuation2.mu +++ b/continuation2.mu @@ -1,6 +1,11 @@ # Example program showing that a 'paused' continuation can be 'resumed' # multiple times from the same point (but with changes to data). # +# To run: +# $ git clone https://github.com/akkartik/mu +# $ cd mu +# $ ./mu continuation2.mu +# # Expected output: # 1 # 2 diff --git a/continuation3.mu b/continuation3.mu index 57d54084..5d44bb4c 100644 --- a/continuation3.mu +++ b/continuation3.mu @@ -1,6 +1,11 @@ # Example program showing that a function call can be 'paused' multiple times, # creating different continuation values. # +# To run: +# $ git clone https://github.com/akkartik/mu +# $ cd mu +# $ ./mu continuation3.mu +# # Expected output: # caller 0 # callee 0 diff --git a/continuation4.mu b/continuation4.mu index adbb70d9..b8398945 100644 --- a/continuation4.mu +++ b/continuation4.mu @@ -3,6 +3,11 @@ # # Print out a given list of numbers. # +# To run: +# $ git clone https://github.com/akkartik/mu +# $ cd mu +# $ ./mu continuation4.mu +# # Expected output: # 1 # 2 diff --git a/continuation5.mu b/continuation5.mu index 663d99c2..9f9b87cb 100644 --- a/continuation5.mu +++ b/continuation5.mu @@ -4,6 +4,11 @@ # Print out a list of numbers, first adding 0 to the first, 1 to the second, 2 # to the third, and so on. # +# To run: +# $ git clone https://github.com/akkartik/mu +# $ cd mu +# $ ./mu continuation5.mu +# # Expected output: # 1 # 3 diff --git a/html/continuation1.mu.html b/html/continuation1.mu.html index 65db879f..2a63f0bb 100644 --- a/html/continuation1.mu.html +++ b/html/continuation1.mu.html @@ -60,22 +60,27 @@ if ('onhashchange' in window) { <span id="L2" class="LineNr"> 2 </span><span class="Comment"># function call, returning a continuation, and that calling the continuation</span> <span id="L3" class="LineNr"> 3 </span><span class="Comment"># can 'resume' the paused function call.</span> <span id="L4" class="LineNr"> 4 </span><span class="Comment">#</span> -<span id="L5" class="LineNr"> 5 </span><span class="Comment"># Expected output:</span> -<span id="L6" class="LineNr"> 6 </span><span class="Comment"># 1</span> -<span id="L7" class="LineNr"> 7 </span> -<span id="L8" class="LineNr"> 8 </span><span class="muRecipe">def</span> <a href='continuation1.mu.html#L8'>main</a> [ -<span id="L9" class="LineNr"> 9 </span> <span class="Constant">local-scope</span> -<span id="L10" class="LineNr">10 </span> k:continuation <span class="Special"><-</span> call-with-continuation-mark <a href='continuation1.mu.html#L15'>create-yielder</a> -<span id="L11" class="LineNr">11 </span> x:num <span class="Special"><-</span> call k <span class="Comment"># should return 1</span> -<span id="L12" class="LineNr">12 </span> $print x <span class="Constant">10/newline</span> -<span id="L13" class="LineNr">13 </span>] -<span id="L14" class="LineNr">14 </span> -<span id="L15" class="LineNr">15 </span><span class="muRecipe">def</span> <a href='continuation1.mu.html#L15'>create-yielder</a><span class="muRecipe"> -> </span>n:num [ -<span id="L16" class="LineNr">16 </span> <span class="Constant">local-scope</span> -<span id="L17" class="LineNr">17 </span> <span class="Constant">load-ingredients</span> -<span id="L18" class="LineNr">18 </span> return-continuation-until-mark -<span id="L19" class="LineNr">19 </span> <span class="muControl">return</span><span class="Constant"> 1</span> -<span id="L20" class="LineNr">20 </span>] +<span id="L5" class="LineNr"> 5 </span><span class="Comment"># To run:</span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment"># $ git clone <a href="https://github.com/akkartik/mu">https://github.com/akkartik/mu</a></span> +<span id="L7" class="LineNr"> 7 </span><span class="Comment"># $ cd mu</span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment"># $ ./mu continuation1.mu</span> +<span id="L9" class="LineNr"> 9 </span><span class="Comment">#</span> +<span id="L10" class="LineNr">10 </span><span class="Comment"># Expected output:</span> +<span id="L11" class="LineNr">11 </span><span class="Comment"># 1</span> +<span id="L12" class="LineNr">12 </span> +<span id="L13" class="LineNr">13 </span><span class="muRecipe">def</span> <a href='continuation1.mu.html#L13'>main</a> [ +<span id="L14" class="LineNr">14 </span> <span class="Constant">local-scope</span> +<span id="L15" class="LineNr">15 </span> k:continuation <span class="Special"><-</span> call-with-continuation-mark <a href='continuation1.mu.html#L20'>create-yielder</a> +<span id="L16" class="LineNr">16 </span> x:num <span class="Special"><-</span> call k <span class="Comment"># should return 1</span> +<span id="L17" class="LineNr">17 </span> $print x <span class="Constant">10/newline</span> +<span id="L18" class="LineNr">18 </span>] +<span id="L19" class="LineNr">19 </span> +<span id="L20" class="LineNr">20 </span><span class="muRecipe">def</span> <a href='continuation1.mu.html#L20'>create-yielder</a><span class="muRecipe"> -> </span>n:num [ +<span id="L21" class="LineNr">21 </span> <span class="Constant">local-scope</span> +<span id="L22" class="LineNr">22 </span> <span class="Constant">load-ingredients</span> +<span id="L23" class="LineNr">23 </span> return-continuation-until-mark +<span id="L24" class="LineNr">24 </span> <span class="muControl">return</span><span class="Constant"> 1</span> +<span id="L25" class="LineNr">25 </span>] </pre> </body> </html> diff --git a/html/continuation2.mu.html b/html/continuation2.mu.html index 46e33c2f..95756684 100644 --- a/html/continuation2.mu.html +++ b/html/continuation2.mu.html @@ -61,35 +61,40 @@ if ('onhashchange' in window) { <span id="L1" class="LineNr"> 1 </span><span class="Comment"># Example program showing that a 'paused' continuation can be 'resumed'</span> <span id="L2" class="LineNr"> 2 </span><span class="Comment"># multiple times from the same point (but with changes to data).</span> <span id="L3" class="LineNr"> 3 </span><span class="Comment">#</span> -<span id="L4" class="LineNr"> 4 </span><span class="Comment"># Expected output:</span> -<span id="L5" class="LineNr"> 5 </span><span class="Comment"># 1</span> -<span id="L6" class="LineNr"> 6 </span><span class="Comment"># 2</span> -<span id="L7" class="LineNr"> 7 </span><span class="Comment"># 3</span> -<span id="L8" class="LineNr"> 8 </span> -<span id="L9" class="LineNr"> 9 </span><span class="muRecipe">def</span> <a href='continuation2.mu.html#L9'>main</a> [ -<span id="L10" class="LineNr">10 </span> <span class="Constant">local-scope</span> -<span id="L11" class="LineNr">11 </span> l:&:<a href='064list.mu.html#L6'>list</a>:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> -<span id="L12" class="LineNr">12 </span> l <span class="Special"><-</span> push<span class="Constant"> 3</span>, l -<span id="L13" class="LineNr">13 </span> l <span class="Special"><-</span> push<span class="Constant"> 2</span>, l -<span id="L14" class="LineNr">14 </span> l <span class="Special"><-</span> push<span class="Constant"> 1</span>, l -<span id="L15" class="LineNr">15 </span> k:continuation <span class="Special"><-</span> call-with-continuation-mark <a href='continuation2.mu.html#L24'>create-yielder</a>, l -<span id="L16" class="LineNr">16 </span> <span class="Delimiter">{</span> -<span id="L17" class="LineNr">17 </span> <span class="Conceal">¦</span> x:num, done?:bool <span class="Special"><-</span> call k -<span id="L18" class="LineNr">18 </span> <span class="Conceal">¦</span> <span class="muControl">break-if</span> done? -<span id="L19" class="LineNr">19 </span> <span class="Conceal">¦</span> $print x <span class="Constant">10/newline</span> -<span id="L20" class="LineNr">20 </span> <span class="Conceal">¦</span> <span class="muControl">loop</span> -<span id="L21" class="LineNr">21 </span> <span class="Delimiter">}</span> -<span id="L22" class="LineNr">22 </span>] -<span id="L23" class="LineNr">23 </span> -<span id="L24" class="LineNr">24 </span><span class="muRecipe">def</span> <a href='continuation2.mu.html#L24'>create-yielder</a> l:&:<a href='064list.mu.html#L6'>list</a>:num<span class="muRecipe"> -> </span>n:num, done?:bool [ -<span id="L25" class="LineNr">25 </span> <span class="Constant">local-scope</span> -<span id="L26" class="LineNr">26 </span> <span class="Constant">load-ingredients</span> -<span id="L27" class="LineNr">27 </span> return-continuation-until-mark -<span id="L28" class="LineNr">28 </span> done? <span class="Special"><-</span> equal l,<span class="Constant"> 0</span> -<span id="L29" class="LineNr">29 </span> <span class="muControl">return-if</span> done?,<span class="Constant"> 0</span> -<span id="L30" class="LineNr">30 </span> n <span class="Special"><-</span> first l -<span id="L31" class="LineNr">31 </span> l <span class="Special"><-</span> <a href='064list.mu.html#L24'>rest</a> l -<span id="L32" class="LineNr">32 </span>] +<span id="L4" class="LineNr"> 4 </span><span class="Comment"># To run:</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment"># $ git clone <a href="https://github.com/akkartik/mu">https://github.com/akkartik/mu</a></span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment"># $ cd mu</span> +<span id="L7" class="LineNr"> 7 </span><span class="Comment"># $ ./mu continuation2.mu</span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment">#</span> +<span id="L9" class="LineNr"> 9 </span><span class="Comment"># Expected output:</span> +<span id="L10" class="LineNr">10 </span><span class="Comment"># 1</span> +<span id="L11" class="LineNr">11 </span><span class="Comment"># 2</span> +<span id="L12" class="LineNr">12 </span><span class="Comment"># 3</span> +<span id="L13" class="LineNr">13 </span> +<span id="L14" class="LineNr">14 </span><span class="muRecipe">def</span> <a href='continuation2.mu.html#L14'>main</a> [ +<span id="L15" class="LineNr">15 </span> <span class="Constant">local-scope</span> +<span id="L16" class="LineNr">16 </span> l:&:<a href='064list.mu.html#L6'>list</a>:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> +<span id="L17" class="LineNr">17 </span> l <span class="Special"><-</span> push<span class="Constant"> 3</span>, l +<span id="L18" class="LineNr">18 </span> l <span class="Special"><-</span> push<span class="Constant"> 2</span>, l +<span id="L19" class="LineNr">19 </span> l <span class="Special"><-</span> push<span class="Constant"> 1</span>, l +<span id="L20" class="LineNr">20 </span> k:continuation <span class="Special"><-</span> call-with-continuation-mark <a href='continuation2.mu.html#L29'>create-yielder</a>, l +<span id="L21" class="LineNr">21 </span> <span class="Delimiter">{</span> +<span id="L22" class="LineNr">22 </span> <span class="Conceal">¦</span> x:num, done?:bool <span class="Special"><-</span> call k +<span id="L23" class="LineNr">23 </span> <span class="Conceal">¦</span> <span class="muControl">break-if</span> done? +<span id="L24" class="LineNr">24 </span> <span class="Conceal">¦</span> $print x <span class="Constant">10/newline</span> +<span id="L25" class="LineNr">25 </span> <span class="Conceal">¦</span> <span class="muControl">loop</span> +<span id="L26" class="LineNr">26 </span> <span class="Delimiter">}</span> +<span id="L27" class="LineNr">27 </span>] +<span id="L28" class="LineNr">28 </span> +<span id="L29" class="LineNr">29 </span><span class="muRecipe">def</span> <a href='continuation2.mu.html#L29'>create-yielder</a> l:&:<a href='064list.mu.html#L6'>list</a>:num<span class="muRecipe"> -> </span>n:num, done?:bool [ +<span id="L30" class="LineNr">30 </span> <span class="Constant">local-scope</span> +<span id="L31" class="LineNr">31 </span> <span class="Constant">load-ingredients</span> +<span id="L32" class="LineNr">32 </span> return-continuation-until-mark +<span id="L33" class="LineNr">33 </span> done? <span class="Special"><-</span> equal l,<span class="Constant"> 0</span> +<span id="L34" class="LineNr">34 </span> <span class="muControl">return-if</span> done?,<span class="Constant"> 0</span> +<span id="L35" class="LineNr">35 </span> n <span class="Special"><-</span> first l +<span id="L36" class="LineNr">36 </span> l <span class="Special"><-</span> <a href='064list.mu.html#L24'>rest</a> l +<span id="L37" class="LineNr">37 </span>] </pre> </body> </html> diff --git a/html/continuation3.mu.html b/html/continuation3.mu.html index e9a9a309..318d01b3 100644 --- a/html/continuation3.mu.html +++ b/html/continuation3.mu.html @@ -58,32 +58,37 @@ if ('onhashchange' in window) { <span id="L1" class="LineNr"> 1 </span><span class="Comment"># Example program showing that a function call can be 'paused' multiple times,</span> <span id="L2" class="LineNr"> 2 </span><span class="Comment"># creating different continuation values.</span> <span id="L3" class="LineNr"> 3 </span><span class="Comment">#</span> -<span id="L4" class="LineNr"> 4 </span><span class="Comment"># Expected output:</span> -<span id="L5" class="LineNr"> 5 </span><span class="Comment"># caller 0</span> -<span id="L6" class="LineNr"> 6 </span><span class="Comment"># callee 0</span> -<span id="L7" class="LineNr"> 7 </span><span class="Comment"># caller 1</span> -<span id="L8" class="LineNr"> 8 </span><span class="Comment"># callee 1</span> -<span id="L9" class="LineNr"> 9 </span><span class="Comment"># caller 2</span> -<span id="L10" class="LineNr">10 </span><span class="Comment"># callee 2</span> -<span id="L11" class="LineNr">11 </span> -<span id="L12" class="LineNr">12 </span><span class="muRecipe">def</span> <a href='continuation3.mu.html#L12'>main</a> [ -<span id="L13" class="LineNr">13 </span> <span class="Constant">local-scope</span> -<span id="L14" class="LineNr">14 </span> $print <span class="Constant">[caller 0]</span> <span class="Constant">10/newline</span> -<span id="L15" class="LineNr">15 </span> k:continuation <span class="Special"><-</span> call-with-continuation-mark <a href='continuation3.mu.html#L22'>f</a> -<span id="L16" class="LineNr">16 </span> $print <span class="Constant">[caller 1]</span> <span class="Constant">10/newline</span> -<span id="L17" class="LineNr">17 </span> k <span class="Special"><-</span> call k -<span id="L18" class="LineNr">18 </span> $print <span class="Constant">[caller 2]</span> <span class="Constant">10/newline</span> -<span id="L19" class="LineNr">19 </span> call k -<span id="L20" class="LineNr">20 </span>] -<span id="L21" class="LineNr">21 </span> -<span id="L22" class="LineNr">22 </span><span class="muRecipe">def</span> <a href='continuation3.mu.html#L22'>f</a> [ -<span id="L23" class="LineNr">23 </span> <span class="Constant">local-scope</span> -<span id="L24" class="LineNr">24 </span> $print <span class="Constant">[callee 0]</span> <span class="Constant">10/newline</span> -<span id="L25" class="LineNr">25 </span> return-continuation-until-mark -<span id="L26" class="LineNr">26 </span> $print <span class="Constant">[callee 1]</span> <span class="Constant">10/newline</span> -<span id="L27" class="LineNr">27 </span> return-continuation-until-mark -<span id="L28" class="LineNr">28 </span> $print <span class="Constant">[callee 2]</span> <span class="Constant">10/newline</span> -<span id="L29" class="LineNr">29 </span>] +<span id="L4" class="LineNr"> 4 </span><span class="Comment"># To run:</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment"># $ git clone <a href="https://github.com/akkartik/mu">https://github.com/akkartik/mu</a></span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment"># $ cd mu</span> +<span id="L7" class="LineNr"> 7 </span><span class="Comment"># $ ./mu continuation3.mu</span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment">#</span> +<span id="L9" class="LineNr"> 9 </span><span class="Comment"># Expected output:</span> +<span id="L10" class="LineNr">10 </span><span class="Comment"># caller 0</span> +<span id="L11" class="LineNr">11 </span><span class="Comment"># callee 0</span> +<span id="L12" class="LineNr">12 </span><span class="Comment"># caller 1</span> +<span id="L13" class="LineNr">13 </span><span class="Comment"># callee 1</span> +<span id="L14" class="LineNr">14 </span><span class="Comment"># caller 2</span> +<span id="L15" class="LineNr">15 </span><span class="Comment"># callee 2</span> +<span id="L16" class="LineNr">16 </span> +<span id="L17" class="LineNr">17 </span><span class="muRecipe">def</span> <a href='continuation3.mu.html#L17'>main</a> [ +<span id="L18" class="LineNr">18 </span> <span class="Constant">local-scope</span> +<span id="L19" class="LineNr">19 </span> $print <span class="Constant">[caller 0]</span> <span class="Constant">10/newline</span> +<span id="L20" class="LineNr">20 </span> k:continuation <span class="Special"><-</span> call-with-continuation-mark <a href='continuation3.mu.html#L27'>f</a> +<span id="L21" class="LineNr">21 </span> $print <span class="Constant">[caller 1]</span> <span class="Constant">10/newline</span> +<span id="L22" class="LineNr">22 </span> k <span class="Special"><-</span> call k +<span id="L23" class="LineNr">23 </span> $print <span class="Constant">[caller 2]</span> <span class="Constant">10/newline</span> +<span id="L24" class="LineNr">24 </span> call k +<span id="L25" class="LineNr">25 </span>] +<span id="L26" class="LineNr">26 </span> +<span id="L27" class="LineNr">27 </span><span class="muRecipe">def</span> <a href='continuation3.mu.html#L27'>f</a> [ +<span id="L28" class="LineNr">28 </span> <span class="Constant">local-scope</span> +<span id="L29" class="LineNr">29 </span> $print <span class="Constant">[callee 0]</span> <span class="Constant">10/newline</span> +<span id="L30" class="LineNr">30 </span> return-continuation-until-mark +<span id="L31" class="LineNr">31 </span> $print <span class="Constant">[callee 1]</span> <span class="Constant">10/newline</span> +<span id="L32" class="LineNr">32 </span> return-continuation-until-mark +<span id="L33" class="LineNr">33 </span> $print <span class="Constant">[callee 2]</span> <span class="Constant">10/newline</span> +<span id="L34" class="LineNr">34 </span>] </pre> </body> </html> diff --git a/html/continuation4.mu.html b/html/continuation4.mu.html index e59c5aa4..2a1cd000 100644 --- a/html/continuation4.mu.html +++ b/html/continuation4.mu.html @@ -63,43 +63,48 @@ if ('onhashchange' in window) { <span id="L3" class="LineNr"> 3 </span><span class="Comment">#</span> <span id="L4" class="LineNr"> 4 </span><span class="Comment"># Print out a given list of numbers.</span> <span id="L5" class="LineNr"> 5 </span><span class="Comment">#</span> -<span id="L6" class="LineNr"> 6 </span><span class="Comment"># Expected output:</span> -<span id="L7" class="LineNr"> 7 </span><span class="Comment"># 1</span> -<span id="L8" class="LineNr"> 8 </span><span class="Comment"># 2</span> -<span id="L9" class="LineNr"> 9 </span><span class="Comment"># 3</span> -<span id="L10" class="LineNr">10 </span> -<span id="L11" class="LineNr">11 </span><span class="muRecipe">def</span> <a href='continuation4.mu.html#L11'>main</a> [ -<span id="L12" class="LineNr">12 </span> <span class="Constant">local-scope</span> -<span id="L13" class="LineNr">13 </span> l:&:<a href='064list.mu.html#L6'>list</a>:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> -<span id="L14" class="LineNr">14 </span> l <span class="Special"><-</span> push<span class="Constant"> 3</span>, l -<span id="L15" class="LineNr">15 </span> l <span class="Special"><-</span> push<span class="Constant"> 2</span>, l -<span id="L16" class="LineNr">16 </span> l <span class="Special"><-</span> push<span class="Constant"> 1</span>, l -<span id="L17" class="LineNr">17 </span> k:continuation, x:num, done?:bool <span class="Special"><-</span> call-with-continuation-mark <a href='continuation4.mu.html#L26'>create-yielder</a>, l -<span id="L18" class="LineNr">18 </span> <span class="Delimiter">{</span> -<span id="L19" class="LineNr">19 </span> <span class="Conceal">¦</span> <span class="muControl">break-if</span> done? -<span id="L20" class="LineNr">20 </span> <span class="Conceal">¦</span> $print x <span class="Constant">10/newline</span> -<span id="L21" class="LineNr">21 </span> <span class="Conceal">¦</span> k, x:num, done?:bool <span class="Special"><-</span> call k -<span id="L22" class="LineNr">22 </span> <span class="Conceal">¦</span> <span class="muControl">loop</span> -<span id="L23" class="LineNr">23 </span> <span class="Delimiter">}</span> -<span id="L24" class="LineNr">24 </span>] -<span id="L25" class="LineNr">25 </span> -<span id="L26" class="LineNr">26 </span><span class="muRecipe">def</span> <a href='continuation4.mu.html#L26'>create-yielder</a> l:&:<a href='064list.mu.html#L6'>list</a>:num<span class="muRecipe"> -> </span>n:num, done?:bool [ -<span id="L27" class="LineNr">27 </span> <span class="Constant">local-scope</span> -<span id="L28" class="LineNr">28 </span> <span class="Constant">load-ingredients</span> -<span id="L29" class="LineNr">29 </span> <span class="Delimiter">{</span> -<span id="L30" class="LineNr">30 </span> <span class="Conceal">¦</span> done? <span class="Special"><-</span> equal l,<span class="Constant"> 0</span> -<span id="L31" class="LineNr">31 </span> <span class="Conceal">¦</span> <span class="muControl">break-if</span> done? -<span id="L32" class="LineNr">32 </span> <span class="Conceal">¦</span> n <span class="Special"><-</span> first l -<span id="L33" class="LineNr">33 </span> <span class="Conceal">¦</span> l <span class="Special"><-</span> <a href='064list.mu.html#L24'>rest</a> l -<span id="L34" class="LineNr">34 </span> <span class="Conceal">¦</span> return-continuation-until-mark n, done? -<span id="L35" class="LineNr">35 </span> <span class="Conceal">¦</span> <span class="muControl">loop</span> -<span id="L36" class="LineNr">36 </span> <span class="Delimiter">}</span> -<span id="L37" class="LineNr">37 </span> <span class="Comment"># A function that returns continuations shouldn't get the opportunity to</span> -<span id="L38" class="LineNr">38 </span> <span class="Comment"># return. Calling functions should stop calling its continuation after this</span> -<span id="L39" class="LineNr">39 </span> <span class="Comment"># point.</span> -<span id="L40" class="LineNr">40 </span> return-continuation-until-mark<span class="Constant"> -1</span>, done? -<span id="L41" class="LineNr">41 </span> assert <span class="Constant">0/false</span>, <span class="Constant">[called too many times, ran out of continuations to return]</span> -<span id="L42" class="LineNr">42 </span>] +<span id="L6" class="LineNr"> 6 </span><span class="Comment"># To run:</span> +<span id="L7" class="LineNr"> 7 </span><span class="Comment"># $ git clone <a href="https://github.com/akkartik/mu">https://github.com/akkartik/mu</a></span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment"># $ cd mu</span> +<span id="L9" class="LineNr"> 9 </span><span class="Comment"># $ ./mu continuation4.mu</span> +<span id="L10" class="LineNr">10 </span><span class="Comment">#</span> +<span id="L11" class="LineNr">11 </span><span class="Comment"># Expected output:</span> +<span id="L12" class="LineNr">12 </span><span class="Comment"># 1</span> +<span id="L13" class="LineNr">13 </span><span class="Comment"># 2</span> +<span id="L14" class="LineNr">14 </span><span class="Comment"># 3</span> +<span id="L15" class="LineNr">15 </span> +<span id="L16" class="LineNr">16 </span><span class="muRecipe">def</span> <a href='continuation4.mu.html#L16'>main</a> [ +<span id="L17" class="LineNr">17 </span> <span class="Constant">local-scope</span> +<span id="L18" class="LineNr">18 </span> l:&:<a href='064list.mu.html#L6'>list</a>:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> +<span id="L19" class="LineNr">19 </span> l <span class="Special"><-</span> push<span class="Constant"> 3</span>, l +<span id="L20" class="LineNr">20 </span> l <span class="Special"><-</span> push<span class="Constant"> 2</span>, l +<span id="L21" class="LineNr">21 </span> l <span class="Special"><-</span> push<span class="Constant"> 1</span>, l +<span id="L22" class="LineNr">22 </span> k:continuation, x:num, done?:bool <span class="Special"><-</span> call-with-continuation-mark <a href='continuation4.mu.html#L31'>create-yielder</a>, l +<span id="L23" class="LineNr">23 </span> <span class="Delimiter">{</span> +<span id="L24" class="LineNr">24 </span> <span class="Conceal">¦</span> <span class="muControl">break-if</span> done? +<span id="L25" class="LineNr">25 </span> <span class="Conceal">¦</span> $print x <span class="Constant">10/newline</span> +<span id="L26" class="LineNr">26 </span> <span class="Conceal">¦</span> k, x:num, done?:bool <span class="Special"><-</span> call k +<span id="L27" class="LineNr">27 </span> <span class="Conceal">¦</span> <span class="muControl">loop</span> +<span id="L28" class="LineNr">28 </span> <span class="Delimiter">}</span> +<span id="L29" class="LineNr">29 </span>] +<span id="L30" class="LineNr">30 </span> +<span id="L31" class="LineNr">31 </span><span class="muRecipe">def</span> <a href='continuation4.mu.html#L31'>create-yielder</a> l:&:<a href='064list.mu.html#L6'>list</a>:num<span class="muRecipe"> -> </span>n:num, done?:bool [ +<span id="L32" class="LineNr">32 </span> <span class="Constant">local-scope</span> +<span id="L33" class="LineNr">33 </span> <span class="Constant">load-ingredients</span> +<span id="L34" class="LineNr">34 </span> <span class="Delimiter">{</span> +<span id="L35" class="LineNr">35 </span> <span class="Conceal">¦</span> done? <span class="Special"><-</span> equal l,<span class="Constant"> 0</span> +<span id="L36" class="LineNr">36 </span> <span class="Conceal">¦</span> <span class="muControl">break-if</span> done? +<span id="L37" class="LineNr">37 </span> <span class="Conceal">¦</span> n <span class="Special"><-</span> first l +<span id="L38" class="LineNr">38 </span> <span class="Conceal">¦</span> l <span class="Special"><-</span> <a href='064list.mu.html#L24'>rest</a> l +<span id="L39" class="LineNr">39 </span> <span class="Conceal">¦</span> return-continuation-until-mark n, done? +<span id="L40" class="LineNr">40 </span> <span class="Conceal">¦</span> <span class="muControl">loop</span> +<span id="L41" class="LineNr">41 </span> <span class="Delimiter">}</span> +<span id="L42" class="LineNr">42 </span> <span class="Comment"># A function that returns continuations shouldn't get the opportunity to</span> +<span id="L43" class="LineNr">43 </span> <span class="Comment"># return. Calling functions should stop calling its continuation after this</span> +<span id="L44" class="LineNr">44 </span> <span class="Comment"># point.</span> +<span id="L45" class="LineNr">45 </span> return-continuation-until-mark<span class="Constant"> -1</span>, done? +<span id="L46" class="LineNr">46 </span> assert <span class="Constant">0/false</span>, <span class="Constant">[called too many times, ran out of continuations to return]</span> +<span id="L47" class="LineNr">47 </span>] </pre> </body> </html> diff --git a/html/continuation5.mu.html b/html/continuation5.mu.html index c32b1d39..500e926f 100644 --- a/html/continuation5.mu.html +++ b/html/continuation5.mu.html @@ -64,44 +64,49 @@ if ('onhashchange' in window) { <span id="L4" class="LineNr"> 4 </span><span class="Comment"># Print out a list of numbers, first adding 0 to the first, 1 to the second, 2</span> <span id="L5" class="LineNr"> 5 </span><span class="Comment"># to the third, and so on.</span> <span id="L6" class="LineNr"> 6 </span><span class="Comment">#</span> -<span id="L7" class="LineNr"> 7 </span><span class="Comment"># Expected output:</span> -<span id="L8" class="LineNr"> 8 </span><span class="Comment"># 1</span> -<span id="L9" class="LineNr"> 9 </span><span class="Comment"># 3</span> -<span id="L10" class="LineNr">10 </span><span class="Comment"># 5</span> -<span id="L11" class="LineNr">11 </span> -<span id="L12" class="LineNr">12 </span><span class="muRecipe">def</span> <a href='continuation5.mu.html#L12'>main</a> [ -<span id="L13" class="LineNr">13 </span> <span class="Constant">local-scope</span> -<span id="L14" class="LineNr">14 </span> l:&:<a href='064list.mu.html#L6'>list</a>:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> -<span id="L15" class="LineNr">15 </span> l <span class="Special"><-</span> push<span class="Constant"> 3</span>, l -<span id="L16" class="LineNr">16 </span> l <span class="Special"><-</span> push<span class="Constant"> 2</span>, l -<span id="L17" class="LineNr">17 </span> l <span class="Special"><-</span> push<span class="Constant"> 1</span>, l -<span id="L18" class="LineNr">18 </span> k:continuation, x:num, done?:bool <span class="Special"><-</span> call-with-continuation-mark <a href='continuation5.mu.html#L29'>create-yielder</a>, l -<span id="L19" class="LineNr">19 </span> a:num <span class="Special"><-</span> copy<span class="Constant"> 1</span> -<span id="L20" class="LineNr">20 </span> <span class="Delimiter">{</span> -<span id="L21" class="LineNr">21 </span> <span class="Conceal">¦</span> <span class="muControl">break-if</span> done? -<span id="L22" class="LineNr">22 </span> <span class="Conceal">¦</span> $print x <span class="Constant">10/newline</span> -<span id="L23" class="LineNr">23 </span> <span class="Conceal">¦</span> k, x:num, done?:bool <span class="Special"><-</span> call k, a <span class="Comment"># resume; x = a + next l value</span> -<span id="L24" class="LineNr">24 </span> <span class="Conceal">¦</span> a <span class="Special"><-</span> add a,<span class="Constant"> 1</span> -<span id="L25" class="LineNr">25 </span> <span class="Conceal">¦</span> <span class="muControl">loop</span> -<span id="L26" class="LineNr">26 </span> <span class="Delimiter">}</span> -<span id="L27" class="LineNr">27 </span>] -<span id="L28" class="LineNr">28 </span> -<span id="L29" class="LineNr">29 </span><span class="muRecipe">def</span> <a href='continuation5.mu.html#L29'>create-yielder</a> l:&:<a href='064list.mu.html#L6'>list</a>:num<span class="muRecipe"> -> </span>n:num, done?:bool [ -<span id="L30" class="LineNr">30 </span> <span class="Constant">local-scope</span> -<span id="L31" class="LineNr">31 </span> <span class="Constant">load-ingredients</span> -<span id="L32" class="LineNr">32 </span> a:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> -<span id="L33" class="LineNr">33 </span> <span class="Delimiter">{</span> -<span id="L34" class="LineNr">34 </span> <span class="Conceal">¦</span> done? <span class="Special"><-</span> equal l,<span class="Constant"> 0</span> -<span id="L35" class="LineNr">35 </span> <span class="Conceal">¦</span> <span class="muControl">break-if</span> done? -<span id="L36" class="LineNr">36 </span> <span class="Conceal">¦</span> n <span class="Special"><-</span> first l -<span id="L37" class="LineNr">37 </span> <span class="Conceal">¦</span> l <span class="Special"><-</span> <a href='064list.mu.html#L24'>rest</a> l -<span id="L38" class="LineNr">38 </span> <span class="Conceal">¦</span> n <span class="Special"><-</span> add n, a -<span id="L39" class="LineNr">39 </span> <span class="Conceal">¦</span> a <span class="Special"><-</span> return-continuation-until-mark n, done? <span class="Comment"># pause/resume</span> -<span id="L40" class="LineNr">40 </span> <span class="Conceal">¦</span> <span class="muControl">loop</span> -<span id="L41" class="LineNr">41 </span> <span class="Delimiter">}</span> -<span id="L42" class="LineNr">42 </span> return-continuation-until-mark<span class="Constant"> -1</span>, done? -<span id="L43" class="LineNr">43 </span> assert <span class="Constant">0/false</span>, <span class="Constant">[called too many times, ran out of continuations to return]</span> -<span id="L44" class="LineNr">44 </span>] +<span id="L7" class="LineNr"> 7 </span><span class="Comment"># To run:</span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment"># $ git clone <a href="https://github.com/akkartik/mu">https://github.com/akkartik/mu</a></span> +<span id="L9" class="LineNr"> 9 </span><span class="Comment"># $ cd mu</span> +<span id="L10" class="LineNr">10 </span><span class="Comment"># $ ./mu continuation5.mu</span> +<span id="L11" class="LineNr">11 </span><span class="Comment">#</span> +<span id="L12" class="LineNr">12 </span><span class="Comment"># Expected output:</span> +<span id="L13" class="LineNr">13 </span><span class="Comment"># 1</span> +<span id="L14" class="LineNr">14 </span><span class="Comment"># 3</span> +<span id="L15" class="LineNr">15 </span><span class="Comment"># 5</span> +<span id="L16" class="LineNr">16 </span> +<span id="L17" class="LineNr">17 </span><span class="muRecipe">def</span> <a href='continuation5.mu.html#L17'>main</a> [ +<span id="L18" class="LineNr">18 </span> <span class="Constant">local-scope</span> +<span id="L19" class="LineNr">19 </span> l:&:<a href='064list.mu.html#L6'>list</a>:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> +<span id="L20" class="LineNr">20 </span> l <span class="Special"><-</span> push<span class="Constant"> 3</span>, l +<span id="L21" class="LineNr">21 </span> l <span class="Special"><-</span> push<span class="Constant"> 2</span>, l +<span id="L22" class="LineNr">22 </span> l <span class="Special"><-</span> push<span class="Constant"> 1</span>, l +<span id="L23" class="LineNr">23 </span> k:continuation, x:num, done?:bool <span class="Special"><-</span> call-with-continuation-mark <a href='continuation5.mu.html#L34'>create-yielder</a>, l +<span id="L24" class="LineNr">24 </span> a:num <span class="Special"><-</span> copy<span class="Constant"> 1</span> +<span id="L25" class="LineNr">25 </span> <span class="Delimiter">{</span> +<span id="L26" class="LineNr">26 </span> <span class="Conceal">¦</span> <span class="muControl">break-if</span> done? +<span id="L27" class="LineNr">27 </span> <span class="Conceal">¦</span> $print x <span class="Constant">10/newline</span> +<span id="L28" class="LineNr">28 </span> <span class="Conceal">¦</span> k, x:num, done?:bool <span class="Special"><-</span> call k, a <span class="Comment"># resume; x = a + next l value</span> +<span id="L29" class="LineNr">29 </span> <span class="Conceal">¦</span> a <span class="Special"><-</span> add a,<span class="Constant"> 1</span> +<span id="L30" class="LineNr">30 </span> <span class="Conceal">¦</span> <span class="muControl">loop</span> +<span id="L31" class="LineNr">31 </span> <span class="Delimiter">}</span> +<span id="L32" class="LineNr">32 </span>] +<span id="L33" class="LineNr">33 </span> +<span id="L34" class="LineNr">34 </span><span class="muRecipe">def</span> <a href='continuation5.mu.html#L34'>create-yielder</a> l:&:<a href='064list.mu.html#L6'>list</a>:num<span class="muRecipe"> -> </span>n:num, done?:bool [ +<span id="L35" class="LineNr">35 </span> <span class="Constant">local-scope</span> +<span id="L36" class="LineNr">36 </span> <span class="Constant">load-ingredients</span> +<span id="L37" class="LineNr">37 </span> a:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> +<span id="L38" class="LineNr">38 </span> <span class="Delimiter">{</span> +<span id="L39" class="LineNr">39 </span> <span class="Conceal">¦</span> done? <span class="Special"><-</span> equal l,<span class="Constant"> 0</span> +<span id="L40" class="LineNr">40 </span> <span class="Conceal">¦</span> <span class="muControl">break-if</span> done? +<span id="L41" class="LineNr">41 </span> <span class="Conceal">¦</span> n <span class="Special"><-</span> first l +<span id="L42" class="LineNr">42 </span> <span class="Conceal">¦</span> l <span class="Special"><-</span> <a href='064list.mu.html#L24'>rest</a> l +<span id="L43" class="LineNr">43 </span> <span class="Conceal">¦</span> n <span class="Special"><-</span> add n, a +<span id="L44" class="LineNr">44 </span> <span class="Conceal">¦</span> a <span class="Special"><-</span> return-continuation-until-mark n, done? <span class="Comment"># pause/resume</span> +<span id="L45" class="LineNr">45 </span> <span class="Conceal">¦</span> <span class="muControl">loop</span> +<span id="L46" class="LineNr">46 </span> <span class="Delimiter">}</span> +<span id="L47" class="LineNr">47 </span> return-continuation-until-mark<span class="Constant"> -1</span>, done? +<span id="L48" class="LineNr">48 </span> assert <span class="Constant">0/false</span>, <span class="Constant">[called too many times, ran out of continuations to return]</span> +<span id="L49" class="LineNr">49 </span>] </pre> </body> </html> |