-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
718 lines (558 loc) · 24.6 KB
/
index.html
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2024-06-25 Tue 19:30 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Diane</title>
<meta name="author" content="Nathan Mull" />
<meta name="generator" content="Org Mode" />
<link rel="stylesheet" type="text/css" href="indexStyle.css" />
<script src="diane.js"></script>
</head>
<body>
<div id="content" class="content">
<h1 class="title">Diane</h1>
<div id="table-of-contents" role="doc-toc">
<h2>Table of Contents</h2>
<div id="text-table-of-contents" role="doc-toc">
<ul>
<li><a href="#orgaa5ccda">The Playground</a>
<ul>
<li><a href="#org333ad0d">Instructions</a></li>
<li><a href="#org4264913">Keyboard Shortcuts</a></li>
</ul>
</li>
<li><a href="#org6c25255">Syntax</a></li>
<li><a href="#orgaf554bf">Semantics</a>
<ul>
<li><a href="#orgf3e6779">Notation for Environments</a></li>
<li><a href="#org0e806ae">Stack Manipulation</a></li>
<li><a href="#orgea6df44">Arithmetic and Comparisons</a></li>
<li><a href="#org8301bf3">Subroutines</a></li>
<li><a href="#org27cdfbd">Variables</a></li>
<li><a href="#org87fb8f8">Conditionals</a></li>
</ul>
</li>
</ul>
</div>
</div>
<p>
<a href="https://github.com/nmmull/Diane">Diane</a> is a <b>toy stack-oriented language with dynamic scoping</b>. It's
not pretty or all that interesting, but it's simple enough to present
the syntax and semantics in a straightforward way (and to build a
reasonable playground for it).
</p>
<p>
Diane was born out of a need to visualize evaluation. During the
spring (2024), I co-taught a course on <a href="https://nmmull.github.io/CS320/landing/Spring-2024/index.html">programming languages</a> in which
we often used stack-oriented languages to motivate and demonstrate
operational semantics. I worked through step-by-step evaluations on
the board often enough to want a process for doing it which is <i>automatic</i> and
<i>interactive</i>, along the same lines as the <a href="https://pythontutor.com/cp/composingprograms.html#mode=edit">Python Tutor</a> for <a href="https://www.composingprograms.com">Composing
Programs</a>.
</p>
<p>
<b>Disclaimer.</b> This page is not a tutorial, just a description of
the language and playground.
</p>
<div id="outline-container-orgaa5ccda" class="outline-2">
<h2 id="orgaa5ccda">The Playground</h2>
<div class="outline-text-2" id="text-orgaa5ccda">
<p>
The primary goal of this project was to build a <a href="playground.html">playground</a> (in <a href="https://elm-lang.org">Elm</a>)
for toying with Diane programs. The playground consists of an editor
window for writing programs, a visualization window for seeing how the
stack and environment change over the course of evaluation, and a
console window for seeing intermediate print statements and error
messages.
</p>
<p>
The playground can also be embedded:
</p>
<div id="embed-example"></div>
<script>
var app = Elm.Main.init({
node: document.getElementById('embed-example'),
flags: {
hasTrace: true,
adjustable: false,
program: `def SUMSQUARES {
dup * swap dup * +
}
2 3 #SUMSQUARES @X
X print`
}});
</script>
<p>
We take advantage of this below to highlight features of the
semantics.
</p>
<p>
Partly out of laziness, partly out of a general bent towards minimal
interfaces, there are no instructions for using the playground
<i>within</i> the playground itself, so I've included them here.
</p>
</div>
<div id="outline-container-org333ad0d" class="outline-3">
<h3 id="org333ad0d">Instructions</h3>
<div class="outline-text-3" id="text-org333ad0d">
<ul class="org-ul">
<li>The <b>step</b> button consumes a single command of the program in the
editor window and updates the stack and environment accordingly.</li>
<li>The <b>run</b> button consumes as much of the program as possible until
<ul class="org-ul">
<li>the entire program is consumed</li>
<li>there is an error</li>
<li>the evaluation times out</li>
</ul></li>
<li>The <b>undo</b> button reverses a step taken by pressing either the
<b>step</b> button or the <b>run</b>.</li>
<li>The <b>reset</b> button resets the program state to its initial state,
clearing the undo history.</li>
<li>The <b>save</b> button sets the program in the editor window to be the
program of the initial state. This also clears the undo
history.<sup><a id="fnr.1" class="footref" href="#fn.1" role="doc-backlink">1</a></sup></li>
<li>The <b>clear</b> button in the console window clears the messages printed
there.<sup><a id="fnr.2" class="footref" href="#fn.2" role="doc-backlink">2</a></sup></li>
</ul>
</div>
</div>
<div id="outline-container-org4264913" class="outline-3">
<h3 id="org4264913">Keyboard Shortcuts</h3>
<div class="outline-text-3" id="text-org4264913">
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left">\</td>
<td class="org-left"><b>step</b></td>
</tr>
<tr>
<td class="org-left">ALT</td>
<td class="org-left"><b>run</b></td>
</tr>
<tr>
<td class="org-left">`</td>
<td class="org-left"><b>undo</b></td>
</tr>
</tbody>
</table>
<p>
It's possible to step through a program while writing it using the
above keyboard shortcuts. In most cases you can also hold down the
key to rapidly step through a program, providing a make-shift
animation mechanism.
</p>
</div>
</div>
</div>
<div id="outline-container-org6c25255" class="outline-2">
<h2 id="org6c25255">Syntax</h2>
<div class="outline-text-2" id="text-org6c25255">
<p>
The following is a simple <a href="https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form">EBNF Grammar</a> describing a Diane program. In
short, a program is a sequence of whitespace-separated commands.
</p>
<hr />
<pre class="example">
<program> ::= { <command> }
<body> ::= '{' <program> '}'
<command> ::= <int> | 'drop' | 'swap' | 'dup' | 'rot'
| '+' | '-' | '*' | '/' | '%' | '=' | '<'
| 'def' <ident> <body> | '#' <ident>
| '@' <ident> | '[' | ']'
| '?' <body> 'else' <body> | 'while' <body> 'do' <body>
<int> ::= ℤ
<ident> ::= ALL_CAPS_SNAKE
</pre>
<hr />
</div>
</div>
<div id="outline-container-orgaf554bf" class="outline-2">
<h2 id="orgaf554bf">Semantics</h2>
<div class="outline-text-2" id="text-orgaf554bf">
<p>
We take a <b>value</b> (𝕍) to be a integer (ℤ) or a program representing a
subroutine (ℙ).<sup><a id="fnr.3" class="footref" href="#fn.3" role="doc-backlink">3</a></sup> A <b>configuration</b>,
written ( S, E, P ), is made up of a stack of integers (S), an
environment consisting of a list of collections identifier-value
bindings (E), and a program as given by the above
grammar (P). The <a href="https://en.wikipedia.org/wiki/Operational_semantics#Structural_operational_semantics">operational semantics</a> of Diane are given by the
reduction rules below.
</p>
</div>
<div id="outline-container-orgf3e6779" class="outline-3">
<h3 id="orgf3e6779">Notation for Environments</h3>
<div class="outline-text-3" id="text-orgf3e6779">
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left">⟨⟩</td>
<td class="org-left">empty collection of bindings</td>
</tr>
<tr>
<td class="org-left">𝒢</td>
<td class="org-left">global bindings</td>
</tr>
<tr>
<td class="org-left">L · E</td>
<td class="org-left">E with (shadowing) local bindings L</td>
</tr>
<tr>
<td class="org-left">E[X ↦ A]</td>
<td class="org-left">E with X bound to the value A (in topmost local bindings)</td>
</tr>
<tr>
<td class="org-left">X ∈ E</td>
<td class="org-left">X is bound in E</td>
</tr>
<tr>
<td class="org-left">E[X]</td>
<td class="org-left">the value to which X is bound in E (searched for top down)</td>
</tr>
<tr>
<td class="org-left">E/X</td>
<td class="org-left">E with any binding of X removed</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="outline-container-org0e806ae" class="outline-3">
<h3 id="org0e806ae">Stack Manipulation</h3>
<div class="outline-text-3" id="text-org0e806ae">
<p>
Several commands are dedicated to manipulating the stack. We can
</p>
<ul class="org-ul">
<li><b>push</b> an integer onto the stack</li>
<li><b>drop</b> the top element off the stack</li>
<li><b>swap</b> the top two elements on the stack</li>
<li><b>dup</b>-licate the top element on the stack</li>
<li><b>rot</b>-ate the top three elements on the stack</li>
</ul>
<p>
In the case that there aren't enough integers on the stack to perform
a given operation, a stack underflow error message is printed to the
console.
</p>
<p>
There is also an unofficial command for <b>print</b>-ing the top element of
the stack and removing it. See the example below.<sup><a id="fnr.4" class="footref" href="#fn.4" role="doc-backlink">4</a></sup>
</p>
<pre class="example">
𝑘 ∈ ℤ
────────────────────────────────── ( push )
( S, E, k P ) ⟶ ( 𝑘 :: S, E, P )
───────────────────────────────────── ( drop )
( 𝑛 :: S, E, drop P ) ⟶ ( S, E, P )
─────────────────────────────────── ( dropErr )
( ⊥, E, drop P ) ⟶ StackUnderflow
──────────────────────────────────────────────────── ( swap )
( 𝑚 :: 𝑛 :: S, E, swap P) ⟶ ( 𝑛 :: 𝑚 :: S, E, P )
──────────────────────────────────────── ( swapErr₁ )
( 𝑛 :: ⊥, E, swap P ) ⟶ StackUnderflow
─────────────────────────────────── ( swapErr₀ )
( ⊥, E, swap P ) ⟶ StackUnderflow
──────────────────────────────────────────────────── ( dup )
( 𝑛 :: S, E, dup P ) ⟶ ( 𝑛 :: 𝑛 :: S, E, P )
─────────────────────────────────── ( dupErr₀ )
( ⊥, E, dup P ) ⟶ StackUnderflow
──────────────────────────────────────────────────────────── ( rot )
( 𝑙 :: 𝑚 :: 𝑛 :: S, E, rot P ) ⟶ ( 𝑚 :: 𝑛 :: 𝑙 :: S, E, P )
──────────────────────────────────────────── ( rotErr₂ )
( 𝑚 :: 𝑛 :: S, E, rot P ) ⟶ StackUnderflow
─────────────────────────────────────── ( rotErr₁ )
( 𝑛 :: ⊥, E, rot P ) ⟶ StackUnderflow
─────────────────────────────────── ( rotErr₀ )
( ⊥, E, rot P ) ⟶ StackUnderflow
</pre>
<p>
The following is a small example program using these commands. Press
the <b>step</b> button to see how the stack changes as each command is
consumed and evaluated. Note that the last command cannot be consumed
because there are no integers on the stack to duplicate. Attempting
to evaluate this command results in a stack underflow error message.
</p>
<div id="push-example"></div>
<script>
var app = Elm.Main.init({
node: document.getElementById('push-example'),
flags: {
hasTrace: true,
adjustable: false,
program: `1 2 3
drop swap dup
rot rot rot
print print print
dup`
}});
</script>
</div>
</div>
<div id="outline-container-orgea6df44" class="outline-3">
<h3 id="orgea6df44">Arithmetic and Comparisons</h3>
<div class="outline-text-3" id="text-orgea6df44">
<p>
The commands in this section are used to operate on the integers on the
stack. We can
</p>
<ul class="org-ul">
<li>(+) add</li>
<li>(-) subtract</li>
<li>(*) multiply</li>
<li>(/) divide</li>
<li>(%) determine the modulus</li>
<li>(=) check for equality</li>
<li>(<) check for less-than</li>
</ul>
<p>
As above, if there aren't enough integers on the stack to perform an
operation, a stack underflow error message is printed. An error may
also occur when trying to divide by zero.
</p>
<pre class="example">
────────────────────────────────────────────────── ( add )
( 𝑚 :: 𝑛 :: S, E, + P ) ⟶ ( 𝑚 + 𝑛 :: S, E, P )
───────────────────────────────────── ( addErr₁ )
( 𝑛 :: ⊥, E, + P ) ⟶ StackUnderflow
──────────────────────────────── ( addErr₀ )
( ⊥, E, - P ) ⟶ StackUnderflow
─────────────────────────────────────────────── ( sub )
( 𝑚 :: 𝑛 :: S, E, - P ) ⟶ ( 𝑚 ─ 𝑛 :: S, E, P )
───────────────────────────────────── ( subErr₁ )
( 𝑛 :: ⊥, E, - P ) ⟶ StackUnderflow
──────────────────────────────── ( subErr₀ )
( ⊥, E, - P ) ⟶ StackUnderflow
───────────────────────────────────────────────── ( mul )
( 𝑚 :: 𝑛 :: S, E, * P ) ⟶ ( 𝑚 × 𝑛 :: S, E, P )
───────────────────────────────────── ( mulErr₁ )
( 𝑛 :: ⊥, E, * P ) ⟶ StackUnderflow
──────────────────────────────── ( mulErr₀ )
( ⊥, E, * P ) ⟶ StackUnderflow
n ≠ 0
────────────────────────────────────────────────── ( div )
( 𝑚 :: 𝑛 :: S, E, / P ) ⟶ ( 𝑚 / 𝑛 :: S, E, P )
────────────────────────────────────── ( divErrByZero )
( 𝑚 :: 0 :: S, E, / P ) ⟶ DivByZero
───────────────────────────────────── ( divErr₁ )
( 𝑛 :: ⊥, E, / P ) ⟶ StackUnderflow
──────────────────────────────── ( divErr₀ )
( ⊥, E, / P ) ⟶ StackUnderflow
n ≠ 0
─────────────────────────────────────────────────── ( mod )
( 𝑚 :: 𝑛 :: S, E, % P ) ⟶ ( 𝑚 mod 𝑛 :: S, E, P )
────────────────────────────────────── ( modErrByZero )
( 𝑚 :: 0 :: S, E, % P ) ⟶ DivByZero
───────────────────────────────────── ( modErr₁ )
( 𝑛 :: ⊥, E, % P ) ⟶ StackUnderflow
──────────────────────────────── ( modErr₀ )
( ⊥, E, % P ) ⟶ StackUnderflow
𝑚 = 𝑛
──────────────────────────────────────────── ( eq )
( 𝑚 :: 𝑛 :: S, E, = P ) ⟶ ( 1 :: S, E, P )
𝑚 ≠ 𝑛
──────────────────────────────────────────── ( neq )
( 𝑚 :: 𝑛 :: S, E, = P ) ⟶ ( 0 :: S, E, P )
───────────────────────────────────── ( eqErr₁ )
( 𝑛 :: ⊥, E, = P ) ⟶ StackUnderflow
──────────────────────────────── ( eqErr₀ )
( ⊥, E, = P ) ⟶ StackUnderflow
𝑚 < 𝑛
──────────────────────────────────────────── ( le )
( 𝑚 :: 𝑛 :: S, E, < P ) ⟶ ( 1 :: S, E, P )
𝑚 ≮ 𝑛
──────────────────────────────────────────── ( nle )
( 𝑚 :: 𝑛 :: S, E, = P ) ⟶ ( 0 :: S, E, P )
───────────────────────────────────── ( leErr₁ )
( 𝑛 :: ⊥, E, = P ) ⟶ StackUnderflow
──────────────────────────────── ( leErr₀ )
( ⊥, E, = P ) ⟶ StackUnderflow
</pre>
<div id="arith-example"></div>
<script>
var app = Elm.Main.init({
node: document.getElementById('arith-example'),
flags: {
hasTrace: true,
adjustable: false,
program: `3 4 5 + * 4 swap / 7 < 5 /`
}});
</script>
</div>
</div>
<div id="outline-container-org8301bf3" class="outline-3">
<h3 id="org8301bf3">Subroutines</h3>
<div class="outline-text-3" id="text-org8301bf3">
<p>
A subroutine is just a named program. We can <i>define</i> subroutines and
<i>call</i> them. Defining a subroutine adds a binding in the environment
of its name to the program in the body of its definition. Calling a
subroutine simply prepends its body to the program being
evaluated.<sup><a id="fnr.5" class="footref" href="#fn.5" role="doc-backlink">5</a></sup>
</p>
<pre class="example">
────────────────────────────────────────────── ( def )
( S, E, def F { Q } P ) ⟶ ( S, E[F ↦ Q], P )
F ∈ E E[X] ∈ ℙ
─────────────────────────────────── ( call )
( S, E, #F P ) ⟶ ( S, E, E[F] P )
F ∈ E E[X] ∉ ℙ
────────────────────────────── ( callErr₁ )
( S, E, #F P ) ⟶ InvalidCall
F ∉ E
────────────────────────────────── ( callErr₀ )
( S, E, #F P ) ⟶ UnknownVariable
</pre>
<div id="arith-example"></div>
<script>
var app = Elm.Main.init({
node: document.getElementById('arith-example'),
flags: {
hasTrace: false,
adjustable: false,
program: `def INCR {
1 +
}
2 #INCR
5 #INCR #INCR
def DUPTWO {
swap
dup rot
dup rot
swap
}
#DUPTWO`
}});
</script>
</div>
</div>
<div id="outline-container-org27cdfbd" class="outline-3">
<h3 id="org27cdfbd">Variables</h3>
<div class="outline-text-3" id="text-org27cdfbd">
<p>
A variable is just a named integer. We can
</p>
<ul class="org-ul">
<li><i>assign</i> an integer to a variable, which adds a binding to the environment</li>
<li><i>lookup</i> a variable binding in the environment (by typing the variable itself)</li>
</ul>
<p>
Variables bindings are available within <i>blocks</i> (or globally). Local
blocks can be opened and closed using the delimiters '[' and ']',
respectively.<sup><a id="fnr.6" class="footref" href="#fn.6" role="doc-backlink">6</a></sup>
Bindings created within a local block are available only within the
evaluation of that block. Bindings not created within a local block
are available anywhere in the program after they've been created.
</p>
<pre class="example">
────────────────────────────────────────── ( assign )
( 𝑛 :: S, E, @X P ) ⟶ ( S, E[X ↦ 𝑛], P )
───────────────────────────────── ( assignErr₀ )
( ⊥, E, @X P ) ⟶ StackUnderflow
X ∈ E E[X] ∈ ℤ
───────────────────────────────────── ( lookup )
( S, E, X P ) ⟶ ( E[X] :: S, E, P )
X ∈ E E[X] ∉ ℤ
─────────────────────────────── ( lookupErr₁ )
( S, E, X P ) ⟶ InvalidLookup
X ∉ E
───────────────────────────────── ( lookupErr₂ )
( S, E, X P ) ⟶ UnknownVariable
────────────────────────────────── ( openLocal )
( S, E, [ P ) ⟶ ( S, ⟨⟩ · E, P )
───────────────────────────────── ( closeLocal )
( S, L · E, ] P ) ⟶ ( S, E, P )
───────────────────────────── ( closeLocalErr )
( S, 𝒢, ] P ) ⟶ GlobalClose
</pre>
<div id="arith-example"></div>
<script>
var app = Elm.Main.init({
node: document.getElementById('arith-example'),
flags: {
hasTrace: false,
adjustable: false,
program: `1 @X
X 1 + @Y
[
X Y
10 @X
X 10 + @Y
X Y
]
X Y`
}});
</script>
</div>
</div>
<div id="outline-container-org87fb8f8" class="outline-3">
<h3 id="org87fb8f8">Conditionals</h3>
<div class="outline-text-3" id="text-org87fb8f8">
<p>
Finally, there are if-statements for conditional reasoning. We also
include while-loops with the usual semantics (i.e., defined in terms of if-statements).
</p>
<pre class="example">
𝑛 ≠ 0
─────────────────────────────────────────────────────── ( ifTrue )
( 𝑛 :: S, E, ? { Q₁ } else { Q₂ } P ) ⟶ ( S, E, Q₂ P )
──────────────────────────────────────────────────────── ( ifFalse )
( 0 :: S, E, ? { Q₁ } else { Q₂ } P ) ⟶ ( S, E, Q₁ P )
─────────────────────────────────────────────────── ( ifErr₀ )
( ⊥, E, ? { Q₁ } else { Q₂ } P ) ⟶ StackUnderflow
─────────────────────────────────────────────────────── ( while )
( S, E, while { Q₁ } do { Q₂ } P ) ⟶
( S, E, Q₁ ? { Q₂ while { Q₁ } do { Q₂ } } else { } P )
</pre>
<div id="cond-example"></div>
<script>
var app = Elm.Main.init({
node: document.getElementById('cond-example'),
flags: {
hasTrace: true,
adjustable: false,
program: `0 @N
N 5 = ? {
24 print
} else {
37 print
}
while { 5 N < } do {
N print
1 N + @N
}`
}});
</script>
</div>
</div>
</div>
<div id="footnotes">
<h2 class="footnotes">Footnotes: </h2>
<div id="text-footnotes">
<div class="footdef"><sup><a id="fn.1" class="footnum" href="#fnr.1" role="doc-backlink">1</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">Note that this only saves the program, not the whole
program state. When reseting, the stack and environment will be
empty, but the inital program will be the most recently saved
program.</p></div></div>
<div class="footdef"><sup><a id="fn.2" class="footnum" href="#fnr.2" role="doc-backlink">2</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">This cannot be undone.</p></div></div>
<div class="footdef"><sup><a id="fn.3" class="footnum" href="#fnr.3" role="doc-backlink">3</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">In other word, 𝕍 = ℤ ∪ ℙ.</p></div></div>
<div class="footdef"><sup><a id="fn.4" class="footnum" href="#fnr.4" role="doc-backlink">4</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">It's
unofficial because printed strings are not a part of the
configuration. Semantically, <b>print</b> is identical to <b>drop</b>.</p></div></div>
<div class="footdef"><sup><a id="fn.5" class="footnum" href="#fnr.5" role="doc-backlink">5</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">Its truly amazing to me how simple this is.</p></div></div>
<div class="footdef"><sup><a id="fn.6" class="footnum" href="#fnr.6" role="doc-backlink">6</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">Note that they aren't actually delimiters. It's
possible to write program which opens more blocks than it closes.</p></div></div>
</div>
</div></div>
</body>
</html>