-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
1230 lines (1183 loc) · 51.5 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
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Dialogue Manager Programming Language (DMPL)</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<script
src='https://www.w3.org/Tools/respec/respec-w3c-common'
class='remove'></script>
<script class='remove'>
let respecConfig = {
wg: "Conversational Interfaces Working Group",
wgURI: "https://www.w3.org/community/conv/",
wgPublicList: "public-conv",
specStatus: "CG-FINAL",
shortName: "dmpl",
editors: [{
name: "Nishant Shukla",
url: "http://shukla.io",
w3cid: 112944
}],
authors: [{
name: "Nelson Solano",
url: "https://www.linkedin.com/in/nelson-solano-24a935126",
w3cid: 113168
}, {
name: "Victor Zhang",
url: "https://www.linkedin.com/in/victor-zhang-a8b303108",
w3cid: 113469
}],
edDraftURI: "https://github.com/w3c/dmpl",
addSectionLinks: true,
isPreview: false,
lint: {
"check-punctuation": true
}
};
</script>
</head>
<body>
<section id='abstract'>
<p>
This specification defines the syntax and semantics of a language for defining the behavior of interactive dialogue.
It formalizes the representation of states (i.e. fluents), how they change (i.e. actions), and which are preferred (i.e. utility).
These three components characterize a task, so we call DMPL a task-oriented programming language.
The interpreter of the language resolves the task by identifying and executing actions that maximize utility.
</p>
</section>
<section id='sotd'></section>
<section id="conformance"></section>
<section>
<h2>Introduction</h2>
This specification aims to decouple the representation of dialogue from its execution.
For example, conversational interfaces employ artificial intelligence in different ways:
finite state machines, path planning, or reinforcement learning systems.
Regardless of the execution framework, the logical representation may be shared.
An agreed upon representation of dialogue allows content writers to author and share conversational experiences
without being distracted by the underlying runtime.
<section>
<h2>Scope</h2>
<i>This section is informative.</i>
<p>
This document is limited to specifying the syntax and semantics for a <dfn>task-oriented</dfn> language for interactive behavior.
One example application of DMPL is an intermediate represenation of content written in authoring tools for non-technical users.
Another use-case of DMPL is exporting and importing dialogue content authored by writers from different web platforms.
Technologies closely related to these use-cases are in scope.
</p>
</section>
<section>
<h2>Goals and Motivation</h2>
<i>This section is informative.</i>
<p>
DMPL is a task-oriented programming language, which may be better explained by extending <a href="https://bit.ly/2Huf6fG">Microsoft's Functional
Programming vs. Imperative Programming</a> table, shown below.
</p>
<table id="comparison-table">
<tr>
<th></th>
<th>Imperative</th>
<th>Functional</th>
<th>Task-Oriented</th>
</tr>
<tr>
<th>Programmer Focus</th>
<td>How to perform tasks (algorithms) and how to track changes in state</td>
<td>What information is desired and what transformations are required</td>
<td>Why an action is taken and how information changes</td>
</tr>
<tr>
<th>State Changes</th>
<td>Important</td>
<td>Non-existant (for purely functional languages)</td>
<td>Important</td>
</tr>
<tr>
<th>Order of Execution</th>
<td>Programmer is mostly responsible</td>
<td>Hybrid resposibility</td>
<td>Compiler is mostly responsible</td>
</tr>
<tr>
<th>Loops</th>
<td>For/While, Recursion</td>
<td>Recursion</td>
<td>None, loops are implicit</td>
</tr>
<tr>
<th>Primary Manipulation Unit</th>
<td>Instances of structures or classes</td>
<td>Functions</td>
<td>Utility</td>
</tr>
</table>
</section>
<p>
The runtime shall evaluate DMPL in an infinite loop, similar to game-loops inherent in most game engines.
</p>
</section>
<section>
<h2>Language Syntax</h2>
<i>This section is normative.</i>
<p>
This section of the document defines the types used within this specification using
<a href="https://bit.ly/2g2U4aa">EBNF</a> notation with corresponding
<a href="https://www.bottlecaps.de/rr/ui">railroad diagrams</a>.
</p>
<section>
<h2><dfn>Atomic Types</dfn></h2>
<section>
<h2><code><dfn>literal</dfn></code></h2>
<p>
A <a>literal</a> is a terminal atom that may be assigned to a <a>variable</a>,
used in a <a>dictionary</a>, or used as an operand to build an <a>expression</a>.
</p>
<blockquote>
<pre>
<a>literal</a> ::= <a>string</a> | <a>number</a> | <a>boolean</a> | 'null'
</pre>
</blockquote>
<figure id="literal-railroad">
<img src="diagrams/literal.png" alt="Literal rail-road diagram">
<figcaption>Literal</figcaption>
</figure>
</section>
<section>
<h2><code><dfn>boolean</dfn></code></h2>
<p>
A <a>boolean</a> may take on values <code>true</code> or <code>false</code>.
</p>
<blockquote>
<pre>
<a>boolean</a> ::= 'true' | 'false'
</pre>
</blockquote>
<figure id="boolean-railroad">
<img src="diagrams/boolean.png" alt="Boolean rail-road diagram">
<figcaption>Boolean</figcaption>
</figure>
</section>
<section>
<h2><code><dfn>name</dfn></code></h2>
<p>
A <a>name</a> is a sequence of characters conforming to those in the [[XML-NAMES]] standard.
</p>
<blockquote>
<pre>
<a>name</a> ::= [ <a href="http://www.w3.org/TR/xml-names/#NT-NCName">http://www.w3.org/TR/xml-names/#NT-NCName</a> ]
</pre>
</blockquote>
<figure id="name-railroad">
<img src="diagrams/name.png" alt="Name rail-road diagram">
<figcaption>Name</figcaption>
</figure>
</section>
<section>
<h2><code><dfn>quote_start</dfn></code></h2>
<p>
A <a>quote_start</a> is the starting quotation mark, which indicates the beginning of a string.
</p>
<blockquote>
<pre>
<a>quote_start</a> ::= '"' '`'
</pre>
</blockquote>
<figure id="quote-start-railroad">
<img src="diagrams/quote_start.png" alt="Quote-start rail-road diagram">
<figcaption>Quote-start</figcaption>
</figure>
</section>
<section>
<h2><code><dfn>quote_close</dfn></code></h2>
<p>
A <a>quote_close</a> is the ending quotation mark, which indicates the termination of a string.
</p>
<blockquote>
<pre>
<a>quote_close</a> ::= '`' '"'
</pre>
</blockquote>
<figure id="quote-close-railroad">
<img src="diagrams/quote_close.png" alt="Quote-close rail-road diagram">
<figcaption>Quote-close</figcaption>
</figure>
</section>
<section>
<h2><code><dfn>string</dfn></code></h2>
<p>
A <a>string</a> literal represents a finite sequence of characters.
It is surrounded by starting and ending quotation marks.
</p>
<blockquote>
<pre>
<a>string</a> ::= <a>quote_start</a> <a>name</a> <a>quote_close</a>
</pre>
</blockquote>
<figure id="string-railroad">
<img src="diagrams/string.png" alt="String railroad diagram">
<figcaption>String</figcaption>
</figure>
<pre class="example" title="string literal">
"`hello`"
</pre>
</section>
<section>
<h2><code><dfn>digit</dfn></code></h2>
<p>
A <a>digit</a> represents a real valued integer in the range [0-9].
</p>
<blockquote>
<pre>
<a>digit</a> ::= [0-9]
</pre>
</blockquote>
<figure id="digit-railroad">
<img src="diagrams/digit.png" alt="Digit railroad diagram">
<figcaption>Digit</figcaption>
</figure>
</section>
<section>
<h2><code><dfn>number</dfn></code></h2>
<p>
A <a>number</a> literal may represent either a positive or negative decimal value.
</p>
<blockquote>
<pre>
<a>number</a> ::= '-'? ( <a>digit</a>+ ( '.' <a>digit</a>* )? | '.' <a>digit</a>+ )
</pre>
</blockquote>
<figure id="number-railroad">
<img src="diagrams/number.png" alt="Number railroad diagram">
<figcaption>Number</figcaption>
</figure>
<pre class="example" title="number literal">
0.2
</pre>
</section>
</section>
<section>
<h2><dfn>Container Structures</dfn></h2>
<section>
<h2><code><dfn>variable</dfn></code></h2>
<p>
A <a>variable</a> is a named reference to the result of evaluating an <a>expression</a>.
</p>
<blockquote>
<pre>
<a>variable</a> :: = '"' <a>name</a> '"'
</pre>
</blockquote>
<figure id="variable-railroad">
<img src="diagrams/variable.png" alt="Variable railroad diagram">
<figcaption>Variable</figcaption>
</figure>
<pre class="example" title="variable">
"num_correct_answers" // => 3
</pre>
A <a>variable</a> should not be confused with a <a>string</a>, which uses backticks (<code>`</code>) like so:
<pre class="example" title="string uses backticks">
"`num_correct_answers`" // => "num_correct_answers"
</pre>
</section>
<section>
<h2><code><dfn>dictionary</dfn></code></h2>
<p>
A <a>dictionary</a> is a structure that maps data in key-value pairs.
The keys and values are all evaluated.
The keys can be either strings or variables that evaluate to strings.
</p>
<blockquote>
<pre>
<a>dictionary</a> : : = '{' ( <a>string</a> | <a>variable</a> ) ':' <a>expression</a>
( ',' ( <a>string</a> | <a>variable</a> ) ':' <a>expression</a> )* '}'
</pre>
</blockquote>
<figure id="dictionary-railroad">
<img src="diagrams/dictionary.png" alt="Dictionary railroad diagram">
<figcaption>Dictionary</figcaption>
</figure>
<pre class="example" title="dictionary">
{"`age`": "x", "`score`": 10, "`name`": "`Joe`"}
</pre>
</section>
<section>
<h2><code><dfn>expression</dfn></code></h2>
<p>
An <a>expression</a> may be evaluated, and that result is stored in memory to be referenced later.
An expression may be denoted by a JSON array [[RFC7159]], in which case it is also called a <dfn>function</dfn>.
The first element of the array represents the operator of the <a>function</a>.
The operator can be either a string or a variable that evaluates to a string.
All remaining elements of the array constitute the operands.
</p>
<blockquote>
<pre>
<a>expression</a> ::= <a>literal</a>
| <a>variable</a>
| <a>dictionary</a>
| '[' ( <a>literal</a> | <a>variable</a> ) ( ',' <a>expression</a> )* ']'
</pre>
</blockquote>
<figure id="expression-railroad">
<img src="diagrams/expression.png" alt="Expression railroad diagram">
<figcaption>Expression</figcaption>
</figure>
<table id="expression-table">
<tr>
<th>Return Type</th>
<th>Operator</th>
<th>Example</th>
</tr>
<tr>
<th><a>string</a></th>
<td><pre>"to_str"</pre></td>
<td><pre class="example">["to_str", 4] // => "4"</pre></td>
</tr>
<tr>
<th><a>string</a></th>
<td><pre>"+"</pre></td>
<td><pre class="example">["+", "`hello `", "`world`"] // => "hello world"</pre></td>
</tr>
<tr>
<th><a>number</a></th>
<td><pre>"+"</pre></td>
<td><pre class="example">["+", 1, 2] // => 3</pre></td>
</tr>
<tr>
<th><a>number</a></th>
<td><pre>"-"</pre></td>
<td><pre class="example">["-", 5, 3] // => 2</pre></td>
</tr>
<tr>
<th><a>number</a></th>
<td><pre>"*"</pre></td>
<td><pre class="example">["*", 2, 4] // => 8</pre></td>
</tr>
<tr>
<th><a>number</a></th>
<td><pre>"/"</pre></td>
<td><pre class="example">["/", 1, 2] // => 0.5</pre></td>
</tr>
<tr>
<th><a>number</a></th>
<td><pre>"//"</pre></td>
<td><pre class="example">["//", 1, 2] // => 0</pre></td>
</tr>
<tr>
<th><a>number</a></th>
<td><pre>"%"</pre></td>
<td><pre class="example">["%", 168, 2] // => 0</pre></td>
</tr>
<tr>
<th><a>number</a></th>
<td><pre>"to_num"</pre></td>
<td><pre class="example">["to_num", "`4`"] // => 4</pre></td>
</tr>
<tr>
<th><a>number</a></th>
<td><pre>"len"</pre></td>
<td><pre class="example">["len", ["", 1, 2, 3]] // => 3</pre></td>
</tr>
<tr>
<th><a>number</a></th>
<td><pre>"floor"</pre></td>
<td><pre class="example">["floor", 1.5] // => 1</pre></td>
</tr>
<tr>
<th>list</th>
<td><pre>""</pre></td>
<td><pre class="example">["", 1, 2, 3, 4, 5] // => [1, 2, 3, 4, 5]</pre></td>
</tr>
<tr>
<th>list</th>
<td><pre>"++"</pre></td>
<td><pre class="example">["++", ["", 1, 2], ["", "`hello`"]] // => [1, 2, "hello"]</pre></td>
</tr>
<tr>
<th>list</th>
<td><pre>"range"</pre></td>
<td>
<pre class="example">["range", 1, 5] // => [1, 2, 3, 4]</pre>
<pre class="example">["range", 0, 8, 2] // => [0, 2, 4, 6]</pre>
</td>
</tr>
<tr>
<th>list</th>
<td><pre>"map"</pre></td>
<td>
<pre class="example">
["map", "to_str", ["", 1, 2, 3]] // => ["1", "2", "3"]
</pre>
<pre class="example">
["map", "+", ["", 1, 2, 3], ["", 4, 5, 6]] // => [5, 7, 9]
</pre>
</td>
</tr>
<tr>
<th>list</th>
<td><pre>"foldl"</pre></td>
<td>
<pre class="example">
["foldl", "+", 0, ["", 1, 2, 3]] // => 6
</pre>
</td>
</tr>
<tr>
<th>list</th>
<td><pre>"sort"</pre></td>
<td>
<pre class="example">
["sort", ["", 1, 3, 2]] // => [1, 2, 3]
</pre>
</td>
</tr>
<tr>
<th>list</th>
<td><pre>"shuffle"</pre></td>
<td>
<pre class="example">
["shuffle", ["", 1, 2, 3]] // => [1, 3, 2] randomly shuffled
</pre>
</td>
</tr>
<tr>
<th>list</th>
<td><pre>"reverse"</pre></td>
<td>
<pre class="example">
["reverse", ["", 1, 2, 3]] // => [3, 2, 1]
</pre>
</td>
</tr>
<tr>
<th><a>boolean</a></th>
<td><pre>"=="</pre></td>
<td><pre class="example">["==", 1, 2] // => false</pre></td>
</tr>
<tr>
<th><a>boolean</a></th>
<td><pre>"!="</pre></td>
<td><pre class="example">["!=", 1, 2] // => true</pre></td>
</tr>
<tr>
<th><a>boolean</a></th>
<td><pre>">"</pre></td>
<td><pre class="example">[">", 2, 3] // => false</pre></td>
</tr>
<tr>
<th><a>boolean</a></th>
<td><pre>">="</pre></td>
<td><pre class="example">[">=", 2, 3] // => false</pre></td>
</tr>
<tr>
<th><a>boolean</a></th>
<td><pre>"<"</pre></td>
<td><pre class="example">["<", 2, 3] // => true</pre></td>
</tr>
<tr>
<th><a>boolean</a></th>
<td><pre>"<="</pre></td>
<td><pre class="example">["<=", 2, 3] // => true</pre></td>
</tr>
<tr>
<th><a>boolean</a></th>
<td><pre>"&&"</pre></td>
<td><pre class="example">["&&", true, false] // => false</pre></td>
</tr>
<tr>
<th><a>boolean</a></th>
<td><pre>"||"</pre></td>
<td><pre class="example">["||", true, false] // => true</pre></td>
</tr>
<tr>
<th><a>boolean</a></th>
<td><pre>"!"</pre></td>
<td><pre class="example">["!", false] // => true</pre></td>
</tr>
<tr>
<th><a>boolean</a></th>
<td><pre>"in"</pre></td>
<td><pre class="example">["in", 3, ["", 1, 2, 3]] // => true</pre></td>
</tr>
<tr>
<th><a>boolean</a></th>
<td><pre>"input"</pre></td>
<td>
<pre class="example">["input"] // => true if there's an input</pre>
<pre class="example">["input", "`yes`"] // => true if there's an input and it equals "yes"</pre>
</td>
</tr>
<tr>
<th><a>boolean</a></th>
<td><pre>"return"</pre></td>
<td>
<pre class="example">["return"] // => true if there's an return result from callee</pre>
</td>
</tr>
<tr>
<th><a>boolean</a></th>
<td><pre>"?"</pre></td>
<td><pre class="example">["?", "`is_greeted`"] // => true if variable defined</pre></td>
</tr>
<tr>
<th>dynamic</th>
<td><pre>"get"</pre></td>
<td>
<pre class="example">["get", 0, ["", 1, 2, 3]] // => 1</pre>
<pre class="example">["get", "`a`", {"`a`": 1}] // => 1</pre>
</td>
</tr>
<tr>
<th>dynamic</th>
<td><pre>"pick"</pre></td>
<td>
<pre class="example">["pick", ["", 1, 2, 3]] // => 1, 2, or 3 uniformly at random</pre>
</td>
</tr>
<tr>
<th>dynamic</th>
<td><pre>"patch"</pre></td>
<td>
<pre class="example">["patch", {"`a`": 1, "`b`": 2}, {"`a`": 2}] // => {a: 2, b: 2}</pre>
Reference: <a href="https://tools.ietf.org/html/rfc7396" target="_blank">RFC 7386</a>
</td>
</tr>
<tr>
<th>dynamic</th>
<td><pre>"edit"</pre></td>
<td>
<pre class="example">["edit", {"`a`": 1}, 2, "`a`"] // => {a: 2}</pre>
</td>
</tr>
<tr>
<th>dynamic</th>
<td><pre>"from_list"</pre></td>
<td>
<pre class="example">["from_list", ["", ["", "`a`", 1], ["", "`b`", 2]]] // => {a: 1, b: 2}</pre>
</td>
</tr>
</table>
</section>
</section>
<section>
<h2><dfn>Statements</dfn></h2>
<section>
<h2><code><dfn>statement</dfn></code></h2>
<p>
A <a>statement</a> may be a non-terminal such as <a>do</a> or <a>fork</a>, or a terminal such as <a>effect</a>.
Optionally, statements may contain <a>condition</a>, <a>await</a>, or <a>once</a> flags.
</p>
<blockquote>
<pre>
<a>statement</a> ::= '{' ( <a>condition</a> ',' )?
( <a>await</a> ',' )?
( <a>once</a> ',' )?
( <a>effect</a> | <a>do</a> | <a>fork</a> ) '}'
</pre>
</blockquote>
<figure id="statement-railroad">
<img src="diagrams/statement.png" alt="Statement railroad diagram">
<figcaption>Statement</figcaption>
</figure>
</section>
<section>
<h2><code><dfn>condition</dfn></code></h2>
<p>
A <a>condition</a> is a boolean expression that runs the statement if the expression evaluates to true.
A condition check takes priority over other parts of the statement.
If a statement does not explicitly contain a condition, then that statement's condition is trivially true.
</p>
<blockquote>
<pre>
<a>condition</a> : : = '"if"' ':' <a>expression</a>
</pre>
</blockquote>
<figure id="condition-railroad">
<img src="diagrams/condition.png" alt="Condition railroad diagram">
<figcaption>Condition</figcaption>
</figure>
<pre class="example" title="condition">
"if": [">", "num_wrong_answers", 3]
</pre>
</section>
<section>
<h2><code><dfn>await</dfn></code></h2>
<p>
An <a>await</a> blocks execution until a boolean expression evaluates to true.
</p>
<blockquote>
<pre>
<a>await</a> ::= '"await"' ':' <a>expression</a>
</pre>
</blockquote>
<figure id="await-railroad">
<img src="diagrams/await.png" alt="Await railroad diagram">
<figcaption>Await</figcaption>
</figure>
<pre class="example" title="await">
"await": ["input"]
</pre>
</section>
<section>
<h2><code><dfn>once</dfn></code></h2>
<p>
A <a>once</a> flag specifies whether the statement can only be run once.
The statement is then ignored in all subsequent instances.
By default, the once flag is set to false.
</p>
<blockquote>
<pre>
<a>once</a> ::= '"once"' ':' <a>boolean</a>
</pre>
</blockquote>
<figure id="once-railroad">
<img src="diagrams/once.png" alt="Once railroad diagram">
<figcaption>Once</figcaption>
</figure>
<pre class="example" title="once">
"once": true
</pre>
</section>
<section>
<h2><code><dfn>effect</dfn></code></h2>
<p>
An <a>effect</a> is a terminal node, meaning it does not produce more statements. There are 6 types of effects.
</p>
<blockquote>
<pre>
<a>effect</a> ::= <a>act</a> | <a>set</a> | <a>def</a> | <a>run</a> | <a>use</a> | <a>pop</a>
</pre>
</blockquote>
<figure id="effect-railroad">
<img src="diagrams/effect.png" alt="Effect railroad diagram">
<figcaption>Effect</figcaption>
</figure>
</section>
<section>
<h2><code><dfn>act</dfn></code></h2>
<p>
An <a>act</a> represents an action for the client to realize.
The expression is evaluated before being sent out to the client.
For example, the payload of the <a>act</a> statement may be represented using
<a href="http://www.mindmakers.org/projects/bml-1-0/wiki">Behavior Markup Language (BML)</a>.
The client is then responsible for realizing the behavior defined in the <a>act</a> message.
</p>
<blockquote>
<pre>
<a>act</a> ::= '"@act"' ':' <a>expression</a>
</pre>
</blockquote>
<figure id="act-railroad">
<img src="diagrams/act.png" alt="Act railroad diagram">
<figcaption>Act</figcaption>
</figure>
<pre class="example" title="act">
"@act": {
"`object`": "`tutor`",
"`action`": "`say`",
"`params`": {"`intent`": "`greeting`"}
}
</pre>
</section>
<section>
<h2><code><dfn>set</dfn></code></h2>
<p>
A <a>set</a> updates the value of a <a>variable</a>,
where the names of the variables and the updated values are specified by evaluating the corresponding expressions.
The expression specifying the names of the variables must evaluate to a string,
a list consisting of only strings, or a dictionary consisting of only strings.
</p>
<blockquote>
<pre>
<a>set</a> ::= '"@set"' ':' <a>expression</a> ',' '"val"' ':' <a>expression</a>
</pre>
</blockquote>
<figure id="set-railroad">
<img src="diagrams/set.png" alt="Set railroad diagram">
<figcaption>Set</figcaption>
</figure>
<pre class="example" title="set">
"@set": "`is_user_greeted`", "val": true
</pre>
<pre class="example" title="set (unpack)">
"@set": ["", "`is_user_greeted`", "`num_questions`"], "val": ["", true, 7]
</pre>
</section>
<section>
<h2><code><dfn>def</dfn></code></h2>
<p>
A <a>def</a> defines a new <a>expression</a> operator that can be used later in the code.
The signature of the new <a>expression</a> operator is specified by an expression that must evaluate to a list of strings,
which maps to the operator name followed by the argument names.
These argument names are valid only for this scope, and may shadow global variables.
The result is returned by a <a>pop</a> statement.
</p>
<p>
When running a user-defined operator, a <i>copy</i> of its surrounding environment (e.g. variables/operators) is coupled to the newly defined
operator. In contrast, functions in Javascript keep <i>references</i> to the surrounding state.
</p>
<p>
Custom operators support <dfn><a>closure</a></dfn>, since the operator is enclosed with a copy of its
surrounding environment. After an operator is defined, the copy of the enclosing scope does not change.
When an operator is called, <a>def</a> and <a>set</a> statements inside the body of the operator
will only create local symbols that shadow symbols in the enclosing scope.
</p>
<blockquote>
<pre>
<a>def</a> ::= '"@def"' ':' <a>expression</a> ',' '"val"' ':' <a>statement</a>
</pre>
</blockquote>
<figure id="def-railroad">
<img src="diagrams/def.png" alt="Def railroad diagram">
<figcaption>Def</figcaption>
</figure>
<pre class="example" title="def">
"@def": ["", "`inc`", "`x`"], "val": {"@pop": ["+", 1, "x"]}
</pre>
<pre class="example" title="closure">
"@def":["","`custom`","`divisor`"], "val":{
"@do":[
{"@def":["","`mod`","`num`"], "val": {"@pop":["%","num","divisor"]}},
{"@pop":"mod"}
]
}
</pre>
</section>
<section>
<h2><code><dfn>run</dfn></code></h2>
<p>
A <a>run</a> calls DMPL code from another component, optionally passing in arguments.
The name of the called component is specified by an expression that must evaluate to a string.
The current variables stored in memory are pushed to a stack before the call, and popped back after the call.
</p>
<p>
The passed in arguments is a JSON array [[RFC7159]] accessible inside the called component, stored in a
built-in variable called <dfn><a>_args</a></dfn>. Note that <a>_args</a> is <dfn>null</dfn> by default if the component
is not called by another component. If a component is called with no passed in arguments, <a>_args</a>
will be an empty array.
</p>
<blockquote>
<pre>
<a>run</a> ::= '"@run"' ':' <a>expression</a> ( ',' '"args"' ':' <a>expression</a> )?
</pre>
</blockquote>
<figure id="run-railroad">
<img src="diagrams/run.png" alt="Run railroad diagram">
<figcaption>Run</figcaption>
</figure>
<pre class="example" title="run">
"@run": "`Outro`"
</pre>
<pre class="example" title="run with args">
"@run": "`Question`", "args": ["", "`What's the largest planet?`", "`Jupiter`"]
</pre>
</section>
<section>
<h2><code><dfn>use</dfn></code></h2>
<p>
A <a>use</a> imports <a>variables</a> and expression operators defined in another component.
The name of the imported component is specified by an expression that must evaluate to a string.
The variable and expression operator names can be optionally specified, or all variables and expression operators will be imported.
It's similar to the Python notation: <code>from os import path</code>.
</p>
<blockquote>
<pre>
<a>use</a> ::= '"@use"' ':' <a>expression</a> ( ',' '"import"' ':' <a>expression</a> )?
</pre>
</blockquote>
<figure id="use-railroad">
<img src="diagrams/use.png" alt="Use railroad diagram">
<figcaption>Use</figcaption>
</figure>
<pre class="example" title="use">
"@use": "`MathExpressions`", "import": ["", "`inc`", "`square`", "`exp`"]
</pre>
</section>
<section>
<h2><code><dfn>pop</dfn></code></h2>
<p>
A <a>pop</a> quits execution on the current DMPL code, pops the variables from the stack, and resumes execution from the previous <a>run</a> location.
</p>
<blockquote>
<pre>
<a>pop</a> ::= '"@pop"' ':' <a>expression</a>
</pre>
</blockquote>
<figure id="pop-railroad">
<img src="diagrams/pop.png" alt="Pop railroad diagram">
<figcaption>Pop</figcaption>
</figure>
<pre class="example" title="pop">
"@pop": true
</pre>
</section>
<section>
<h2><code><dfn>do</dfn></code></h2>
<p>
A <a>do</a> statement specifies a list of statements to be executed.
</p>
<blockquote>
<pre>
<a>do</a> ::= '"@do"' ':' '[' ( <a>statement</a> ( ',' <a>statement</a> )* )? ']'
</pre>
</blockquote>
<figure id="do-railroad">
<img src="diagrams/do.png" alt="Do railroad diagram">
<figcaption>Do</figcaption>
</figure>
<pre class="example" title="do">
"@do": [
{"@act": "a"},
{"@act": "b"},
{"@act": "c"}
]
</pre>
</section>
<section>
<h2><code><dfn>fork</dfn></code></h2>
<p>
A <a>fork</a> statement specifies a branch in program-execution for the list of statements that follow.
Only one is chosen, and the strategy to pick one may be provided using the <a>scheme</a> attribute.
By default, a greedy scheme is used, meaning the first statement whose <a>condition</a> is met will be chosen.
More complicated schemes, such as depth-first-search or Monte Carlo Tree Search may be indicated,
leaving the implementation up to the interpreter.
</p>
<blockquote>
<pre>
<a>fork</a> ::= '"@fork"' ':' '[' ( <a>statement</a> ( ',' <a>statement</a> )* )? ']' ( ',' <a>scheme</a> )?
</pre>
</blockquote>
<figure id="fork-railroad">
<img src="diagrams/fork.png" alt="Fork railroad diagram">
<figcaption>Fork</figcaption>
</figure>
<p>When no scheme is provided, a fork is essentially the traditional <code>if</code>/<code>elif</code>/<code>else</code> logical flow:</p>
<pre class="example" title="fork">
"@fork": [
{"if": "is_user_greeted", "@act": "a"},
{"if": [">", "num_wrong_answers", 3], "@act": "b"},
{"@act": "c"}
]
</pre>
<p>Providing a scheme allows stochastic behavior to take place:</p>
<pre class="example" title="fork with scheme">
"scheme": {"depth": 3}, "@fork": [
{"@set": "`do_action_1`", "val": "true"},
{"@set": "`do_action_2`", "val": "true"},
{"@set": "`do_action_3`", "val": "true"},
{"if": "is_entry_condition_met", "@set": "`do_action_4`", "val": "true"},
{"if": false, "@act": "`never reached`"}
]
</pre>
</section>
<section>
<h2><code><dfn>scheme</dfn></code></h2>
<p>
A <a>scheme</a> is associated with a <a>fork</a> statement, and it describes the fork branch resolution strategy.
</p>
<blockquote>
<pre>
<a>scheme</a> ::= '"scheme"' ':' <a>expression</a>
</pre>
</blockquote>
<figure id="scheme-railroad">
<img src="diagrams/scheme.png" alt="Scheme railroad diagram">
<figcaption>Scheme</figcaption>
</figure>
<pre class="example" title="scheme">
{"depth": 3}
</pre>
</section>
</section>
</section>
<section>
<h2>Examples</h2>
<i>This section is informative.</i>
<p>
This section details DMPL conforming example programs.
</p>
<p>The following sends "hello world" to the action realizer.
<pre class="example" title="Hello World!">
{
"@act": "`hello world`"
}
</pre>
<br />
<p>Two actions can be sent sequentially.</p>
<pre class="example" title="Do-statement">
{
"@do": [
{"@act": "`hello`"},
{"@act": "`world`"}
]
}
</pre>
<br />
<p>Fork statements allow branching logic.</p>
<pre class="example" title="If-Else Control Flow">
{
"@fork": [
{"if": ["==", ["+", 2, 2], 4], "@act": "`this statement is run`"},
{"@act": "`never reached`"}
]
}
</pre>
<br />
<p>Variables can be set and accessed like so.</p>
<pre class="example" title="Variables">
{
"@do": [
{"@set": "`a`", "val": 1},
{"@set": "`b`", "val": 2},
{"@set": "`c`", "val": ["+", "a", "b"]}
]
}
</pre>
<br />
<p>Here we define a new expression called <code>inc</code> which takes an argument called <code>x</code>.</p>
<pre class="example" title="Define New Expression">
{
"@do": [
{"@def": ["", "`inc`", "`x`"], "val": {"@pop": ["+", 1, "x"]}},
{"@act", ["`inc`", 5]}
]
}
</pre>
<br />
<p>The set statement allows unpacking a list.</p>
<pre class="example" title="Unpacking an Array">
{
"@do": [
{"@set": "`content`", "val": ["", "`What's the biggest planet?`", "`Jupiter`"]},
{"@set": ["", "`Prompt`", "`Correct-Answer`"], "val": "`content`"}
]
}
</pre>
<br />
<p>Run an external file and pass in arguments. The return value can be considered in the following fork statement.</p>
<pre class="example" title="Running Components">
{"@do":
{"@run": "`Question`", "args": ["", "`What's the biggest planet?`", "`Jupiter`"]},