diff options
Diffstat (limited to 'html/074list.mu.html')
-rw-r--r-- | html/074list.mu.html | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/html/074list.mu.html b/html/074list.mu.html new file mode 100644 index 00000000..76b64ad5 --- /dev/null +++ b/html/074list.mu.html @@ -0,0 +1,142 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - 074list.mu</title> +<meta name="Generator" content="Vim/7.4"> +<meta name="plugin-version" content="vim7.4_v2"> +<meta name="syntax" content="none"> +<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy="> +<meta name="colorscheme" content="minimal"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } +body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color: #080808; } +* { font-size: 12pt; font-size: 1em; } +.muRecipe { color: #ff8700; } +.muData { color: #ffff00; } +.muScenario { color: #00af00; } +.Delimiter { color: #800080; } +.Comment { color: #9090ff; } +.Constant { color: #00a0a0; } +.Special { color: #c00000; } +.muControl { color: #c0a020; } +--> +</style> + +<script type='text/javascript'> +<!-- + +--> +</script> +</head> +<body> +<pre id='vimCodeElement'> +<span class="Comment"># A list links up multiple objects together to make them easier to manage.</span> +<span class="Comment">#</span> +<span class="Comment"># The objects must be of the same type. If you want to store multiple types in</span> +<span class="Comment"># a single list, use an exclusive-container.</span> + +<span class="muData">container</span> list:_elem [ + value:_elem + next:address:shared:list:_elem +] + +<span class="muRecipe">def</span> push x:_elem, in:address:shared:list:_elem<span class="muRecipe"> -> </span>in:address:shared:list:_elem [ + <span class="Constant">local-scope</span> + <span class="Constant">load-ingredients</span> + result:address:shared:list:_elem<span class="Special"> <- </span>new <span class="Delimiter">{</span>(list _elem): type<span class="Delimiter">}</span> + val:address:_elem<span class="Special"> <- </span>get-address *result, <span class="Constant">value:offset</span> + *val<span class="Special"> <- </span>copy x + next:address:address:shared:list:_elem<span class="Special"> <- </span>get-address *result, <span class="Constant">next:offset</span> + *next<span class="Special"> <- </span>copy in + <span class="muControl">return</span> result <span class="Comment"># needed explicitly because we need to replace 'in' with 'result'</span> +] + +<span class="muRecipe">def</span> first in:address:shared:list:_elem<span class="muRecipe"> -> </span>result:_elem [ + <span class="Constant">local-scope</span> + <span class="Constant">load-ingredients</span> + result<span class="Special"> <- </span>get *in, <span class="Constant">value:offset</span> +] + +<span class="muRecipe">def</span> rest in:address:shared:list:_elem<span class="muRecipe"> -> </span>result:address:shared:list:_elem/contained-in:in [ + <span class="Constant">local-scope</span> + <span class="Constant">load-ingredients</span> + result<span class="Special"> <- </span>get *in, <span class="Constant">next:offset</span> +] + +<span class="muScenario">scenario</span> list-handling [ + run [ + <span class="Constant">1</span>:address:shared:list:number<span class="Special"> <- </span>push <span class="Constant">3</span>, <span class="Constant">0</span> + <span class="Constant">1</span>:address:shared:list:number<span class="Special"> <- </span>push <span class="Constant">4</span>, <span class="Constant">1</span>:address:shared:list:number + <span class="Constant">1</span>:address:shared:list:number<span class="Special"> <- </span>push <span class="Constant">5</span>, <span class="Constant">1</span>:address:shared:list:number + <span class="Constant">2</span>:number<span class="Special"> <- </span>first <span class="Constant">1</span>:address:shared:list:number + <span class="Constant">1</span>:address:shared:list:number<span class="Special"> <- </span>rest <span class="Constant">1</span>:address:shared:list:number + <span class="Constant">3</span>:number<span class="Special"> <- </span>first <span class="Constant">1</span>:address:shared:list:number + <span class="Constant">1</span>:address:shared:list:number<span class="Special"> <- </span>rest <span class="Constant">1</span>:address:shared:list:number + <span class="Constant">4</span>:number<span class="Special"> <- </span>first <span class="Constant">1</span>:address:shared:list:number + <span class="Constant">1</span>:address:shared:list:number<span class="Special"> <- </span>rest <span class="Constant">1</span>:address:shared:list:number + ] + memory-should-contain [ + <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># empty to empty, dust to dust..</span> + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">5</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">4</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">3</span> + ] +] + +<span class="muRecipe">def</span> to-text in:address:shared:list:_elem<span class="muRecipe"> -> </span>result:address:shared:array:character [ + <span class="Constant">local-scope</span> + <span class="Constant">load-ingredients</span> + buf:address:shared:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">80</span> + buf<span class="Special"> <- </span>to-buffer in, buf + result<span class="Special"> <- </span>buffer-to-array buf +] + +<span class="Comment"># variant of 'to-text' which stops printing after a few elements (and so is robust to cycles)</span> +<span class="muRecipe">def</span> to-text-line in:address:shared:list:_elem<span class="muRecipe"> -> </span>result:address:shared:array:character [ + <span class="Constant">local-scope</span> + <span class="Constant">load-ingredients</span> + buf:address:shared:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">80</span> + buf<span class="Special"> <- </span>to-buffer in, buf, <span class="Constant">6</span> <span class="Comment"># max elements to display</span> + result<span class="Special"> <- </span>buffer-to-array buf +] + +<span class="muRecipe">def</span> to-buffer in:address:shared:list:_elem, buf:address:shared:buffer<span class="muRecipe"> -> </span>buf:address:shared:buffer [ + <span class="Constant">local-scope</span> + <span class="Constant">load-ingredients</span> + <span class="Delimiter">{</span> + <span class="muControl">break-if</span> in + buf<span class="Special"> <- </span>append buf, <span class="Constant">48/0</span> + <span class="muControl">return</span> + <span class="Delimiter">}</span> + <span class="Comment"># append in.value to buf</span> + val:_elem<span class="Special"> <- </span>get *in, <span class="Constant">value:offset</span> + buf<span class="Special"> <- </span>append buf, val + <span class="Comment"># now prepare next</span> + next:address:shared:list:_elem<span class="Special"> <- </span>rest in + nextn:number<span class="Special"> <- </span>copy next + <span class="muControl">return-unless</span> next + buf<span class="Special"> <- </span>append buf, <span class="Constant">[ -> ]</span> + <span class="Comment"># and recurse</span> + remaining:number, optional-ingredient-found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + <span class="Delimiter">{</span> + <span class="muControl">break-if</span> optional-ingredient-found? + <span class="Comment"># unlimited recursion</span> + buf<span class="Special"> <- </span>to-buffer next, buf + <span class="muControl">return</span> + <span class="Delimiter">}</span> + <span class="Delimiter">{</span> + <span class="muControl">break-unless</span> remaining + <span class="Comment"># limited recursion</span> + remaining<span class="Special"> <- </span>subtract remaining, <span class="Constant">1</span> + buf<span class="Special"> <- </span>to-buffer next, buf, remaining + <span class="muControl">return</span> + <span class="Delimiter">}</span> + <span class="Comment"># past recursion depth; insert ellipses and stop</span> + append buf, <span class="Constant">[...]</span> +] +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> |