1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
<!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 - counters.mu</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v1">
<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-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 1.05em; }
.Underlined { color: #c000c0; text-decoration: underline; }
.Comment { color: #9090ff; }
.Special { color: #ff6060; }
.Identifier { color: #804000; }
-->
</style>
<script type='text/javascript'>
<!--
-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment"># example program: maintain multiple counters with isolated lexical scopes</span>
<span class="Comment"># (spaces)</span>
recipe <span class="Identifier">new</span>-counter [
default-space:address:<span class="Identifier">array</span>:location<span class="Special"> <- </span><span class="Identifier">new</span> location:<span class="Identifier">type</span>, 30
n:number<span class="Special"> <- </span>next-ingredient
reply default-space
]
recipe increment-counter [
<span class="Underlined">local</span>-scope
0:address:<span class="Identifier">array</span>:location/names:<span class="Identifier">new</span>-counter<span class="Special"> <- </span>next-ingredient <span class="Comment"># setup outer space; it *must* come from 'new-counter'</span>
x:number<span class="Special"> <- </span>next-ingredient
n:number/space:1<span class="Special"> <- </span>add n:number/space:1, x
reply n:number/space:1
]
recipe main [
<span class="Underlined">local</span>-scope
<span class="Comment"># counter A</span>
a:address:<span class="Identifier">array</span>:location<span class="Special"> <- </span><span class="Identifier">new</span>-counter 34
<span class="Comment"># counter B</span>
b:address:<span class="Identifier">array</span>:location<span class="Special"> <- </span><span class="Identifier">new</span>-counter 23
<span class="Comment"># increment both by 2 but in different ways</span>
increment-counter a, 1
b-value:number<span class="Special"> <- </span>increment-counter b, 2
a-value:number<span class="Special"> <- </span>increment-counter a, 1
<span class="Comment"># check results</span>
$<span class="Identifier">print</span> [Contents of counters
]
<span class="Comment"># trailing space in next line is to help with syntax highlighting</span>
$<span class="Identifier">print</span> [a: ], a-value, [ b: ], b-value, [
]
]
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->
|