diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2017-11-05 10:22:25 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2017-11-05 10:22:25 -0800 |
commit | 58d918defc54b00b0bb8ea54f5e220109e07553a (patch) | |
tree | f3a24c9df7f00b04fe86e3f5f5bd7b936201a352 | |
parent | 7df951eab66c3ab492448b28a9c5e4d697814be8 (diff) | |
download | mu-58d918defc54b00b0bb8ea54f5e220109e07553a.tar.gz |
4112
-rw-r--r-- | continuation4.mu | 16 | ||||
-rw-r--r-- | html/continuation4.mu.html | 28 |
2 files changed, 18 insertions, 26 deletions
diff --git a/continuation4.mu b/continuation4.mu index 5957c1be..26f72bf4 100644 --- a/continuation4.mu +++ b/continuation4.mu @@ -21,19 +21,15 @@ def create-yielder l:&:list:num -> n:num, done?:bool [ load-ingredients { done? <- equal l, 0 - # Our current primitives can lead to gnarly code to ensure that we always - # statically match a continuation call with a 'return-continuation-until-mark'. - # Try to design functions to either always return or always return continuation. - { - # should we have conditional versions of return-continuation-until-mark - # analogous to return-if and return-unless? Names get really long. - break-unless done? - return-continuation-until-mark 0, done? - return 0, done? # just a guard rail; should never execute - } + break-if done? n <- first l l <- rest l return-continuation-until-mark n, done? loop } + # A function that returns continuations shouldn't get the opportunity to + # return. Calling functions should stop calling its continuation after this + # point. + return-continuation-until-mark -1, done? + assert 0/false, [called too many times, ran out of continuations to return] ] diff --git a/html/continuation4.mu.html b/html/continuation4.mu.html index d827031e..546a5533 100644 --- a/html/continuation4.mu.html +++ b/html/continuation4.mu.html @@ -81,22 +81,18 @@ if ('onhashchange' in window) { <span id="L21" class="LineNr">21 </span> <span class="Constant">load-ingredients</span> <span id="L22" class="LineNr">22 </span> <span class="Delimiter">{</span> <span id="L23" class="LineNr">23 </span> <span class="Conceal">¦</span> done? <span class="Special"><-</span> equal l,<span class="Constant"> 0</span> -<span id="L24" class="LineNr">24 </span> <span class="Conceal">¦</span> <span class="Comment"># Our current primitives can lead to gnarly code to ensure that we always</span> -<span id="L25" class="LineNr">25 </span> <span class="Conceal">¦</span> <span class="Comment"># statically match a continuation call with a 'return-continuation-until-mark'.</span> -<span id="L26" class="LineNr">26 </span> <span class="Conceal">¦</span> <span class="Comment"># Try to design functions to either always return or always return continuation.</span> -<span id="L27" class="LineNr">27 </span> <span class="Conceal">¦</span> <span class="Delimiter">{</span> -<span id="L28" class="LineNr">28 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Comment"># should we have conditional versions of return-continuation-until-mark</span> -<span id="L29" class="LineNr">29 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Comment"># analogous to return-if and return-unless? Names get really long.</span> -<span id="L30" class="LineNr">30 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="muControl">break-unless</span> done? -<span id="L31" class="LineNr">31 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> return-continuation-until-mark<span class="Constant"> 0</span>, done? -<span id="L32" class="LineNr">32 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="muControl">return</span><span class="Constant"> 0</span>, done? <span class="Comment"># just a guard rail; should never execute</span> -<span id="L33" class="LineNr">33 </span> <span class="Conceal">¦</span> <span class="Delimiter">}</span> -<span id="L34" class="LineNr">34 </span> <span class="Conceal">¦</span> n <span class="Special"><-</span> first l -<span id="L35" class="LineNr">35 </span> <span class="Conceal">¦</span> l <span class="Special"><-</span> <a href='064list.mu.html#L24'>rest</a> l -<span id="L36" class="LineNr">36 </span> <span class="Conceal">¦</span> return-continuation-until-mark n, done? -<span id="L37" class="LineNr">37 </span> <span class="Conceal">¦</span> <span class="muControl">loop</span> -<span id="L38" class="LineNr">38 </span> <span class="Delimiter">}</span> -<span id="L39" class="LineNr">39 </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> n <span class="Special"><-</span> first l +<span id="L26" class="LineNr">26 </span> <span class="Conceal">¦</span> l <span class="Special"><-</span> <a href='064list.mu.html#L24'>rest</a> l +<span id="L27" class="LineNr">27 </span> <span class="Conceal">¦</span> return-continuation-until-mark n, done? +<span id="L28" class="LineNr">28 </span> <span class="Conceal">¦</span> <span class="muControl">loop</span> +<span id="L29" class="LineNr">29 </span> <span class="Delimiter">}</span> +<span id="L30" class="LineNr">30 </span> <span class="Comment"># A function that returns continuations shouldn't get the opportunity to</span> +<span id="L31" class="LineNr">31 </span> <span class="Comment"># return. Calling functions should stop calling its continuation after this</span> +<span id="L32" class="LineNr">32 </span> <span class="Comment"># point.</span> +<span id="L33" class="LineNr">33 </span> return-continuation-until-mark<span class="Constant"> -1</span>, done? +<span id="L34" class="LineNr">34 </span> assert <span class="Constant">0/false</span>, <span class="Constant">[called too many times, ran out of continuations to return]</span> +<span id="L35" class="LineNr">35 </span>] </pre> </body> </html> |