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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
<head>
<link href="../favicon.ico" rel="shortcut icon" type="image/x-icon"/>
<link href="../style.css" rel="stylesheet"/>
<title>Object-oriented programming in BQN</title>
</head>
<div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">doc</a></div>
<h1 id="object-oriented-programming-in-bqn">Object-oriented programming in BQN</h1>
<p>BQN's <a href="namespace.html">namespaces</a> can be used to support a simple form of <a href="https://en.wikipedia.org/wiki/Object-oriented_programming">object-oriented programming</a> (OOP) without type checking or inheritance. It's suitable for some program architectures but not others: making OOP work as a solution to every problem isn't a BQN design goal. In fact, BQN was never designed to support OOP at all! I added namespaces or modules as a way to structure programs. The techniques we're going to discuss are all just ways to use namespaces, and if it ever starts seeming like confusing magic it might help to go back to this model. However, thinking of namespaces as objects can be quite powerful in the right circumstances, and on this page I'm going to frame things in OOP terms. The following table shows which well-known aspects of OOP are supported in BQN:</p>
<table>
<thead>
<tr>
<th>Feature</th>
<th>In BQN?</th>
</tr>
</thead>
<tbody>
<tr>
<td>Objects</td>
<td><a href="#objects">Yes</a> (namespaces)</td>
</tr>
<tr>
<td>Classes</td>
<td><a href="#classes">Yes</a> (function returning namespace)</td>
</tr>
<tr>
<td>Fields</td>
<td><a href="#objects">Yes</a></td>
</tr>
<tr>
<td>Methods</td>
<td><a href="#objects">Yes</a></td>
</tr>
<tr>
<td>Class variables</td>
<td><a href="#class-members">Yes</a> (awkward syntax)</td>
</tr>
<tr>
<td>Access</td>
<td>Public or instance-private</td>
</tr>
<tr>
<td><code><span class='Value'>this</span></code></td>
<td>No (<a href="#self-reference">well…</a>)</td>
</tr>
<tr>
<td>Inheritance (is-a)</td>
<td>No</td>
</tr>
<tr>
<td>Composition (has-a)</td>
<td><a href="#composition">Yes</a></td>
</tr>
<tr>
<td>Interfaces</td>
<td>No</td>
</tr>
<tr>
<td>Abstract classes</td>
<td>No</td>
</tr>
<tr>
<td>Mixins</td>
<td>Not really (needs <code><span class='Value'>this</span></code>)</td>
</tr>
</tbody>
</table>
<h2 id="objects">Objects</h2>
<p>An object in BQN is simply a namespace: its fields and methods are variables in the namespace, and one of these can be accessed outside of the namespace with dot syntax if it's exported with <code><span class='Gets'>⇐</span></code>. Unexported variables are instance-private in OOP parlance, meaning that only they're only visible to the object containing them. They could be utilities, or hold state for the object. As an example, the object below implements the <a href="https://en.wikipedia.org/wiki/Tower_of_Hanoi">Tower of Hanoi</a> puzzle with five disks. You can view the state (a list of disks occupying each of the three rods) with <code><span class='Value'>towerOfHanoi.</span><span class='Function'>View</span></code>, or move the top disk from one rod to another with <code><span class='Value'>towerOfHanoi.</span><span class='Function'>Move</span></code>.</p>
<pre><span class='Value'>towerOfHanoi</span> <span class='Gets'>←</span> <span class='Brace'>{</span>
<span class='Value'>l</span> <span class='Gets'>←</span> <span class='Function'>↕</span><span class='Modifier'>¨</span><span class='Number'>5</span><span class='Ligature'>‿</span><span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>0</span>
<span class='Function'>View</span> <span class='Gets'>⇐</span> <span class='Brace'>{</span><span class='Value'>𝕤</span>
<span class='Value'>l</span>
<span class='Brace'>}</span>
<span class='Function'>Move</span> <span class='Gets'>⇐</span> <span class='Brace'>{</span><span class='Value'>from</span><span class='Ligature'>‿</span><span class='Value'>to:</span>
<span class='Value'>l</span> <span class='Gets'>↩</span> <span class='Function'>Transfer</span><span class='Modifier'>´</span><span class='Modifier2'>⌾</span><span class='Paren'>(</span><span class='Value'>𝕩</span><span class='Modifier2'>⊸</span><span class='Function'>⊏</span><span class='Paren'>)</span><span class='Modifier2'>⍟</span><span class='Paren'>(</span><span class='Function'>≠</span><span class='Modifier'>´</span><span class='Value'>𝕩</span><span class='Paren'>)</span> <span class='Value'>l</span>
<span class='Brace'>}</span>
<span class='Comment'># Move a disk from 𝕨 to 𝕩
</span> <span class='Function'>Transfer</span> <span class='Gets'>←</span> <span class='Brace'>{</span>
<span class='String'>"No disk to move"</span><span class='Function'>!</span><span class='Number'>0</span><span class='Function'><≠</span><span class='Value'>𝕨</span>
<span class='String'>"Can't place larger disk on smaller one"</span><span class='Function'>!</span><span class='Paren'>(</span><span class='Number'>0</span><span class='Function'><≠</span><span class='Paren'>)</span><span class='Modifier2'>◶</span><span class='Bracket'>⟨</span><span class='Number'>1</span><span class='Separator'>,</span><span class='Value'>𝕨</span><span class='Function'><</span><span class='Modifier2'>○</span><span class='Function'>⊑⊢</span><span class='Bracket'>⟩</span><span class='Value'>𝕩</span>
<span class='Bracket'>⟨</span><span class='Number'>1</span><span class='Function'>↓</span><span class='Value'>𝕨</span><span class='Separator'>,</span> <span class='Value'>𝕨</span><span class='Function'>⊏</span><span class='Modifier2'>⊸</span><span class='Function'>∾</span><span class='Value'>𝕩</span><span class='Bracket'>⟩</span>
<span class='Brace'>}</span>
<span class='Brace'>}</span>
</pre>
<p>Two fields <code><span class='Value'>l</span></code> and <code><span class='Function'>Transfer</span></code> aren't exported, for two different reasons. <code><span class='Value'>l</span></code> encodes the state of the tower, but it's often better to expose it with the function <code><span class='Function'>View</span></code> instead to allow the internal representation to be changed freely. <code><span class='Function'>Transfer</span></code> is just a utility function. While it's not dangerous to use outside of the object, there's no reason to expose it through <code><span class='Value'>towerOfHanoi</span></code>'s interface. If it's wanted in another place it should be moved to a common location.</p>
<p>Here are the results of a few applications of these functions.</p>
<pre> <span class='Value'>t</span> <span class='Gets'>←</span> <span class='Value'>towerOfHanoi</span>
<span class='Value'>t.</span><span class='Function'>View</span><span class='String'>@</span>
<span class='Bracket'>⟨</span> <span class='Bracket'>⟨</span> <span class='Number'>0</span> <span class='Number'>1</span> <span class='Number'>2</span> <span class='Number'>3</span> <span class='Number'>4</span> <span class='Bracket'>⟩</span> <span class='Bracket'>⟨⟩</span> <span class='Bracket'>⟨⟩</span> <span class='Bracket'>⟩</span>
<span class='Value'>t.</span><span class='Function'>Move</span> <span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>2</span>
<span class='Bracket'>⟨</span> <span class='Bracket'>⟨</span> <span class='Number'>1</span> <span class='Number'>2</span> <span class='Number'>3</span> <span class='Number'>4</span> <span class='Bracket'>⟩</span> <span class='Bracket'>⟨⟩</span> <span class='Bracket'>⟨</span> <span class='Number'>0</span> <span class='Bracket'>⟩</span> <span class='Bracket'>⟩</span>
<span class='Value'>t.</span><span class='Function'>Move</span> <span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>2</span>
<span class='Function'>!</span> <span class='String'>"No disk to move"</span>
<span class='Value'>t.</span><span class='Function'>Move</span> <span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span>
<span class='Bracket'>⟨</span> <span class='Bracket'>⟨</span> <span class='Number'>2</span> <span class='Number'>3</span> <span class='Number'>4</span> <span class='Bracket'>⟩</span> <span class='Bracket'>⟨</span> <span class='Number'>1</span> <span class='Bracket'>⟩</span> <span class='Bracket'>⟨</span> <span class='Number'>0</span> <span class='Bracket'>⟩</span> <span class='Bracket'>⟩</span>
<span class='Value'>t.</span><span class='Function'>Move</span> <span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>1</span>
<span class='Bracket'>⟨</span> <span class='Bracket'>⟨</span> <span class='Number'>2</span> <span class='Number'>3</span> <span class='Number'>4</span> <span class='Bracket'>⟩</span> <span class='Bracket'>⟨</span> <span class='Number'>0</span> <span class='Number'>1</span> <span class='Bracket'>⟩</span> <span class='Bracket'>⟨⟩</span> <span class='Bracket'>⟩</span>
</pre>
<h2 id="classes">Classes</h2>
<p>The object above is a singleton: there's just one of it, at least in the scope it occupies. It's often more useful to have a class that can be used to create objects. What we'll call a "class" is a namespace function, that is, a function that contains <code><span class='Gets'>⇐</span></code> and so returns a namespace. It's very easy to convert a singleton object to a class: just add a no-op <code><span class='Value'>𝕤</span></code> line to force it to be a function, and call it with <code><span class='String'>@</span></code> when needed.</p>
<pre><span class='Function'>MakeStack</span> <span class='Gets'>←</span> <span class='Brace'>{</span><span class='Value'>𝕤</span>
<span class='Value'>st</span><span class='Gets'>←</span><span class='String'>@</span>
<span class='Function'>Push</span><span class='Gets'>⇐</span><span class='Brace'>{</span> <span class='Value'>st</span><span class='Gets'>↩</span><span class='Value'>𝕩</span><span class='Ligature'>‿</span><span class='Value'>st</span><span class='Brace'>}</span>
<span class='Function'>Pop</span> <span class='Gets'>⇐</span><span class='Brace'>{</span><span class='Value'>𝕤</span><span class='Separator'>⋄</span> <span class='Value'>r</span><span class='Ligature'>‿</span><span class='Value'>s</span><span class='Gets'>←</span><span class='Value'>st</span> <span class='Separator'>⋄</span> <span class='Value'>st</span><span class='Gets'>↩</span><span class='Value'>s</span> <span class='Separator'>⋄</span> <span class='Value'>r</span><span class='Brace'>}</span>
<span class='Brace'>}</span>
</pre>
<p>But there's no need to ignore the argument: often it's useful to initialize a class using one or two arguments. For example, the stack class above can be modified to use <code><span class='Value'>𝕩</span></code> as an initial list of values for the stack.</p>
<pre><span class='Function'>MakeStackInit</span> <span class='Gets'>←</span> <span class='Brace'>{</span>
<span class='Value'>st</span><span class='Gets'>←</span><span class='String'>@</span>
<span class='Function'>Push</span><span class='Gets'>⇐</span><span class='Brace'>{</span> <span class='Value'>st</span><span class='Gets'>↩</span><span class='Value'>𝕩</span><span class='Ligature'>‿</span><span class='Value'>st</span><span class='Brace'>}</span>
<span class='Function'>Pop</span> <span class='Gets'>⇐</span><span class='Brace'>{</span><span class='Value'>𝕤</span><span class='Separator'>⋄</span> <span class='Value'>r</span><span class='Ligature'>‿</span><span class='Value'>s</span><span class='Gets'>←</span><span class='Value'>st</span> <span class='Separator'>⋄</span> <span class='Value'>st</span><span class='Gets'>↩</span><span class='Value'>s</span> <span class='Separator'>⋄</span> <span class='Value'>r</span><span class='Brace'>}</span>
<span class='Function'>Push</span><span class='Modifier'>¨</span> <span class='Value'>𝕩</span>
<span class='Brace'>}</span>
</pre>
<p>A stack is a particularly simple class to make because its state can be represented efficiently as a BQN value. Other data structures don't allow this, and will often require an extra <code><span class='Function'>Node</span></code> class when they are implemented—see <code><span class='Function'>MakeQueue</span></code> below.</p>
<h2 id="mutability">Mutability</h2>
<p>An object is one way to transform <em>variable mutation</em> <code><span class='Gets'>↩</span></code> into <em>mutable data</em>. These are two different concepts: <code><span class='Gets'>↩</span></code> changes which value is attached to a <em>name</em> in a scope, while mutable data means that the behavior of a particular <em>value</em> can change. But if a value is linked to a scope (for an object, the scope that contains its fields), then variable mutation in that scope can change the value's behavior. In fact, in BQN this is the only way to create mutable data. Which doesn't mean it's rare: functions, modifiers, and namespaces are all potentially mutable. The difference between objects and the operations is just a matter of syntax. Mutability in operations can only be observed by calling them. For instance <code><span class='Function'>F</span> <span class='Number'>10</span></code> or <code><span class='Function'>-</span><span class='Modifier'>_m</span></code> could return a different result even if the variables involved don't change value. Mutability in an object can only be observed by accessing a member, meaning that <code><span class='Value'>obj.field</span></code> or <code><span class='Bracket'>⟨</span><span class='Value'>field</span><span class='Bracket'>⟩</span><span class='Gets'>←</span><span class='Value'>obj</span></code> can yield different values over the course of a program even if <code><span class='Value'>obj</span></code> is still the same object.</p>
<p>Let's look at how mutability plays out in an example class for a single-ended queue. This queue works by linking new nodes to the tail <code><span class='Value'>t</span></code> of the queue, and detaching nodes from the head <code><span class='Value'>h</span></code> when requested (a detached node will still point to <code><span class='Value'>h</span></code>, but nothing in the queue points to <em>it</em>, so it's unreachable and will eventually be garbage collected). Each node has some data <code><span class='Value'>v</span></code> and a single node reference <code><span class='Value'>n</span></code> directed tailwards; in a double-ended queue or more complicated structure it would have more references. You can find every mutable variable in the queue by searching for <code><span class='Gets'>↩</span></code>, which shows that <code><span class='Value'>t</span></code> and <code><span class='Value'>h</span></code> in the queue, and <code><span class='Value'>n</span></code> in a node, may be mutated. It's impossible for the other variables to change value once they're assigned.</p>
<pre><span class='Function'>MakeQueue</span> <span class='Gets'>←</span> <span class='Brace'>{</span><span class='Value'>𝕤</span>
<span class='Value'>t</span><span class='Gets'>←</span><span class='Value'>h</span><span class='Gets'>←</span><span class='Value'>e</span><span class='Gets'>←</span><span class='Brace'>{</span><span class='Function'>SetN</span><span class='Gets'>⇐</span><span class='Brace'>{</span><span class='Value'>h</span><span class='Gets'>↩</span><span class='Value'>𝕩</span><span class='Brace'>}}</span>
<span class='Function'>Node</span><span class='Gets'>←</span><span class='Brace'>{</span><span class='Value'>v</span><span class='Gets'>⇐</span><span class='Value'>𝕩</span><span class='Separator'>⋄</span><span class='Value'>n</span><span class='Gets'>⇐</span><span class='Value'>e</span> <span class='Separator'>⋄</span> <span class='Function'>SetN</span><span class='Gets'>⇐</span><span class='Brace'>{</span><span class='Value'>n</span><span class='Gets'>↩</span><span class='Value'>𝕩</span><span class='Brace'>}}</span>
<span class='Function'>Push</span><span class='Gets'>⇐</span><span class='Brace'>{</span><span class='Value'>t.</span><span class='Function'>SetN</span> <span class='Value'>n</span><span class='Gets'>←</span><span class='Function'>Node</span> <span class='Value'>𝕩</span> <span class='Separator'>⋄</span> <span class='Value'>t</span><span class='Gets'>↩</span><span class='Value'>n</span><span class='Brace'>}</span>
<span class='Function'>Pop</span> <span class='Gets'>⇐</span><span class='Brace'>{</span><span class='Value'>𝕤</span><span class='Separator'>⋄</span><span class='Value'>v</span><span class='Gets'>←</span><span class='Value'>h.v</span><span class='Separator'>⋄</span><span class='Brace'>{</span><span class='Value'>t</span><span class='Gets'>↩</span><span class='Value'>𝕩</span><span class='Brace'>}</span><span class='Modifier2'>⍟</span><span class='Paren'>(</span><span class='Value'>e</span><span class='Modifier2'>⊸</span><span class='Function'>=</span><span class='Paren'>)</span><span class='Value'>h</span><span class='Gets'>↩</span><span class='Value'>h.n</span><span class='Separator'>⋄</span><span class='Value'>v</span><span class='Brace'>}</span>
<span class='Brace'>}</span>
</pre>
<p>Unlike a stack, a node's successor isn't known when it's created, and it has to be set. You might be inclined to make <code><span class='Value'>n</span></code> settable directly, but we'll get more mileage out of a setter function <code><span class='Function'>SetN</span></code>. This allows us to create a pseudo-node <code><span class='Value'>e</span></code> (for "empty") indicating there are no values in the queue. Because it has no <code><span class='Value'>.v</span></code> field, if <code><span class='Value'>h</span></code> is <code><span class='Value'>e</span></code> then <code><span class='Function'>Pop</span></code> gives an error (but in a real implementation you'd want to test explicitly instead in order to give an appropriate error message). In fact it doesn't have an <code><span class='Value'>n</span></code> field, and essentially uses the queue head <code><span class='Value'>h</span></code> instead. With this empty "node", the queue definition is straightforward. The only tricky part to remember is that if <code><span class='Function'>Pop</span></code> removes the last node, resulting in <code><span class='Value'>e</span><span class='Function'>=</span><span class='Value'>h</span></code>, then the tail has to be set to <code><span class='Value'>e</span></code> as well, or it will keep pointing to the removed node and cause bugs.</p>
<h2 id="composition">Composition</h2>
<p>BQN classes don't support inheritance because there's no way to extend an existing class with new fields. But a lot of OOP enthusiasts these days are promoting <a href="https://en.wikipedia.org/wiki/Composition_over_inheritance">composition over inheritance</a>, and here BQN does pretty well. Forwarding methods from another class is as simple as a multiple assignment, like <code><span class='Bracket'>⟨</span><span class='Function'>View</span><span class='Bracket'>⟩</span></code> below (in a real program <code><span class='Value'>undoableTowerOfHanoi</span></code> should almost certainly be a class, but I introduced <code><span class='Value'>towerOfHanoi</span></code> before classes, and I'm not about to write it again just to add an <code><span class='Value'>𝕤</span></code>).</p>
<pre><span class='Value'>undoableTowerOfHanoi</span> <span class='Gets'>←</span> <span class='Brace'>{</span>
<span class='Function'>Push</span><span class='Ligature'>‿</span><span class='Function'>Pop</span> <span class='Gets'>←</span> <span class='Function'>MakeStack</span><span class='String'>@</span> <span class='Comment'># Copy methods as private
</span> <span class='Bracket'>⟨</span><span class='Function'>View</span><span class='Bracket'>⟩</span> <span class='Gets'>⇐</span> <span class='Value'>t</span><span class='Gets'>←</span><span class='Value'>towerOfHanoi</span> <span class='Comment'># Copy and export
</span> <span class='Function'>Move</span> <span class='Gets'>⇐</span> <span class='Value'>t.</span><span class='Function'>Move</span> <span class='Function'>⊣</span> <span class='Function'>Push</span>
<span class='Function'>Undo</span> <span class='Gets'>⇐</span> <span class='Value'>t.</span><span class='Function'>Move</span><span class='Modifier2'>∘</span><span class='Function'>⌽</span><span class='Modifier2'>∘</span><span class='Function'>Pop</span>
<span class='Brace'>}</span>
</pre>
<p>This class composes a Tower of Hanoi with an undo stack that stores previous moves. To undo a move from <code><span class='Value'>a</span></code> to <code><span class='Value'>b</span></code>, it moves from <code><span class='Value'>b</span></code> to <code><span class='Value'>a</span></code>, although if you felt really fancy you might define <code><span class='Function'>Move</span><span class='Modifier'>⁼</span></code> in <code><span class='Value'>towerOfHanoi</span></code> instead with <code><span class='Function'>𝕊</span><span class='Modifier'>⁼</span><span class='Value'>𝕩:</span> <span class='Function'>𝕊⌽</span><span class='Value'>𝕩</span></code>.</p>
<p>It's also possible to copy several variables and only export some of them, with an export statement. For example, if I wasn't going to make another method called <code><span class='Function'>Move</span></code>, I might have written <code><span class='Function'>View</span><span class='Ligature'>‿</span><span class='Function'>Move</span> <span class='Gets'>←</span> <span class='Value'>towerOfHanoi</span></code> and then <code><span class='Function'>View</span><span class='Gets'>⇐</span></code>. In fact, depending on your personal style and how complicated your classes are, you might prefer to avoid inline <code><span class='Gets'>⇐</span></code> exports entirely, and declare all the exports at the top.</p>
<h2 id="self-reference">Self-reference</h2>
<p>An object's class is given by <code><span class='Function'>𝕊</span></code>. Remember, a class is an ordinary BQN function! It might be useful for an object to produce another object of the same class (particularly if it's immutable), and an object might also expose a field <code><span class='Value'>class</span><span class='Gets'>⇐</span><span class='Value'>𝕤</span></code> to test whether an object <code><span class='Value'>o</span></code> belongs to a class <code><span class='Value'>c</span></code> with <code><span class='Value'>o.class</span> <span class='Function'>=</span> <span class='Value'>c</span></code>.</p>
<p>It's not currently possible for an object to know its own value without some outside help, such as a special constructor:</p>
<pre><span class='Function'>IntrospectiveClass</span> <span class='Gets'>←</span> <span class='Brace'>{</span>
<span class='Value'>obj</span> <span class='Gets'>←</span> <span class='Brace'>{</span>
<span class='Value'>this</span><span class='Gets'>⇐</span><span class='String'>@</span>
<span class='Function'>SetThis</span> <span class='Gets'>⇐</span> <span class='Brace'>{</span> <span class='Function'>!</span><span class='Value'>this</span><span class='Function'>=</span><span class='String'>@</span> <span class='Separator'>⋄</span> <span class='Value'>this</span><span class='Gets'>↩</span><span class='Value'>𝕩</span> <span class='Brace'>}</span>
<span class='Brace'>}</span>
<span class='Value'>obj.setThis</span> <span class='Value'>obj</span>
<span class='Brace'>}</span>
</pre>
<p>This is a pretty clunky solution, and exports a useless method <code><span class='Function'>SetThis</span></code> (which gives an error if it's ever called). It would be possible for BQN to define a system value <code><span class='Value'>•this</span></code> that just gets the namespace's value. It would work only at the top level, so it would have to be assigned (<code><span class='Value'>this</span><span class='Gets'>←</span><span class='Value'>•this</span></code>) in order to use it in functions. This means it's always used before the namespace is done being defined, so a drawback is that it introduces the possibility that an object used in a program has undefined fields. The reason this isn't possible for objects without <code><span class='Value'>•this</span></code> is that BQN's blocks don't have any sort of control flow, so that they always execute every statement in order. The namespace becomes accessible as a value once the block finishes, and at this point every statement has been executed and every field is initialized.</p>
<h2 id="class-members">Class members</h2>
<p>As with <code><span class='Value'>this</span></code>, giving a class variables that belong to it is a do-it-yourself sort of thing (or more positively, not at all magic (funny how programmer jargon goes the opposite way to ordinary English)). It's an easy one though, as this is exactly what <a href="lexical.html">lexical scoping</a> does:</p>
<pre><span class='Value'>staticClass</span> <span class='Gets'>←</span> <span class='Brace'>{</span>
<span class='Value'>counter</span> <span class='Gets'>←</span> <span class='Number'>0</span>
<span class='Brace'>{</span><span class='Value'>𝕤</span>
<span class='Value'>class</span> <span class='Gets'>⇐</span> <span class='Value'>staticClass</span>
<span class='Function'>Count</span> <span class='Gets'>⇐</span> <span class='Brace'>{</span><span class='Value'>𝕤</span><span class='Separator'>⋄</span> <span class='Value'>counter</span><span class='Function'>+</span><span class='Gets'>↩</span><span class='Number'>1</span> <span class='Brace'>}</span>
<span class='Brace'>}</span>
<span class='Brace'>}</span>
</pre>
<p>Now <code><span class='Function'>StaticClass</span></code> is the inner function, because that function is the block's result, and it has some extra state that only it knows how to access. The differences in the definition are that <code><span class='Value'>staticClass</span></code> ends up with a subject role and that each object's <code><span class='Value'>class</span></code> has to be set to <code><span class='Value'>staticClass</span></code> instead of the shortcut <code><span class='Value'>𝕤</span></code>, but these are purely syntactic issues: under it all, <code><span class='Value'>staticClass</span></code> is the same as any other class, but has some extra state attached.</p>
|