-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc.html
More file actions
executable file
·672 lines (613 loc) · 32.6 KB
/
doc.html
File metadata and controls
executable file
·672 lines (613 loc) · 32.6 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ReactiveML - Documentation</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="./bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="./style.css" rel="stylesheet">
<link href="./bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<link href="./rml.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="masthead">
<div class="navbar navbar-defaultbar-defaultbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-default btn btn-default-default btn btn-default btn btn-default-default-default navbar-inverse navbar-btn btn-default btn btn-default-default btn btn-default btn btn-default-default-default" data-toggle="collapse" data-target=".navbar-collapse" style="padding-top: 3px">
<!-- <col-md- class="glyphicon glyphglyphicon glyphglyphicon glyphicon-bar"></col-md-> -->
<!-- <col-md- class="glyphicon glyphglyphicon glyphglyphicon glyphicon-bar"></col-md-> -->
<!-- <col-md- class="glyphicon glyphglyphicon glyphglyphicon glyphicon-bar"></col-md-> -->
menu
</a>
<a class="brand" href="./index.html">ReactiveML</a>
<div class="navbar-collapse collapse">
<ul class="nav">
<li><a href="./index.html">Home</a></li>
<li><a href="./tryrml/tryrml.html">Try online</a></li>
<li class="active"><a href="./documentation.html">Documentation</a></li>
<li><a href="./examples.html">Examples</a></li>
<li><a href="./videos.html">Videos</a></li>
<li><a href="./publications.html">Publications</a></li>
<li><a href="./contact.html">Contact</a></li>
</ul>
</div> <!-- /navbar-collapse -->
</div> <!-- /container -->
</div> <!-- /navbar-inner -->
</div> <!-- /navbar -->
</div> <!-- /masthead -->
<div class="row">
<div class="col-md-3">
<div class="well sidebar-nav sidebar-nav-fixed">
<ul class="nav nav-list">
<li class="nav-header">Try ReactiveML</li>
<li><a href="./tryrml/tryrml.html"><i class="glyphicon glyphglyphicon glyphglyphicon glyphicon-globe glyphicon glyphglyphicon glyphglyphicon glyphicon-black"></i> Try it online</a></li>
<li><a href="./distrib"><i class="glyphicon glyphglyphicon glyphglyphicon glyphicon-globe glyphicon glyphglyphicon glyphglyphicon glyphicon-black"></i> Download</a></li>
<li class="nav-header">Compilation</li>
<li><a href="#rmlc"><i class="glyphicon glyphglyphicon glyphglyphicon glyphicon-chevron-right"></i> rmlc</a></li>
<li><a href="#rmlbuild"><i class="glyphicon glyphglyphicon glyphglyphicon glyphicon-chevron-right"></i> rmlbuild</a></li>
<li class="nav-header">Process</li>
<li><a href="#process"><i class="glyphicon glyphglyphicon glyphglyphicon glyphicon-chevron-right"></i> Process definitions</a></li>
<li><a href="#statements"><i class="glyphicon glyphglyphicon glyphglyphicon glyphicon-chevron-right"></i> Basic statements</a></li>
<li><a href="#compositions"><i class="glyphicon glyphglyphicon glyphglyphicon glyphicon-chevron-right"></i> Compositions</a></li>
<li><a href="#iterators"><i class="glyphicon glyphglyphicon glyphglyphicon glyphicon-chevron-right"></i> Iterators</a></li>
<li class="nav-header">Communication</li>
<li><a href="#signalDecl"><i class="glyphicon glyphglyphicon glyphglyphicon glyphicon-chevron-right"></i> Signal declaration</a></li>
<li><a href="#signalEm"><i class="glyphicon glyphglyphicon glyphglyphicon glyphicon-chevron-right"></i> Signal emission</a></li>
<li><a href="#signalSt"><i class="glyphicon glyphglyphicon glyphglyphicon glyphicon-chevron-right"></i> Signal status</a></li>
<li><a href="#signalVal"><i class="glyphicon glyphglyphicon glyphglyphicon glyphicon-chevron-right"></i> Signal value</a></li>
<li class="nav-header">Control</li>
<li><a href="#control"><i class="glyphicon glyphglyphicon glyphglyphicon glyphicon-chevron-right"></i> Control structures</a></li>
<li><a href="#config"><i class="glyphicon glyphglyphicon glyphglyphicon glyphicon-chevron-right"></i> Event configurations</a></li>
<li class="nav-header">Library</li>
<li><a href="#stdlib"><i class="glyphicon glyphglyphicon glyphglyphicon glyphicon-chevron-right"></i> Standard library</a></li>
</ul>
</div>
</div><!--/col-md--->
<div class="col-md-9">
<h1>ReactiveML Manual</h1>
<hr>
<p>
<b>ReactiveML</b> is based on
the <a href="http://www-sop.inria.fr/mimosa/rp/generalPresentation/index.html">synchronous
reactive model</a> <!-- of Boussinot --> embedded in an ML language
(here a subset of <a href="http://caml.inria.fr">OCaml</a>). It provides
synchronous parallel composition and dynamic features like the dynamic
creation of processes. In <b>ReactiveML</b>, the reactive model is
integrated at the language level (not as a library) which leads to
safer and more natural programming.
</p>
<p>
This page presents how to <a href="#rmlc">compile a ReactiveML program</a>, the <a href="#summary">syntax and
an intuitive semantics</a> of the language. It terminates with the
documentation of the <a href="#stdlib">standard library</a>. An <a href="./tryrml">interactive tutorial</a> is also available.
</p>
<section id="rmlc">
<h3></h3>
<h2>Compiling ReactiveML Programs</h2>
<p>
Let <code>hello.rml</code> be a file containing the following program:
</p>
<pre>
<col-md- style="color: #008b8b;">let</col-md-> <col-md- style="color: #008b8b;">process</col-md-> main = print_endline <col-md- style="color: #8b2252;">"Hello World!"</col-md->
<col-md- style="color: #008b8b;">let</col-md-> () = <col-md- style="color: #008b8b;">run</col-md-> main
</pre>
<p>
To produce an executable, the file must be first compiled into pure
OCaml code using the following command:
</p>
<pre>
rmlc hello.rml
</pre>
<p>
Then, the generated OCaml file (<code>hello.ml</code>) can compiled
and linked with the ReactiveML runtime as follows:
</p>
<pre>
ocamlopt -o hello -I `rmlc -where` unix.cmxa rmllib.cmxa hello.ml
</pre>
<p>
It produces an executable file <code>hello</code> which
displays <code>Hello World!</code>.
</p>
</section>
<section id="rmlbuild">
<h3></h3>
<p>
You can also automate the compilation of ReactiveML programs
using <code>rmlbuild</code>. You can compile the ReactiveML file and
the generated OCaml file in one command:
</p>
<pre>
rmlbuild hello.rml.native
</pre>
<p>
This tool is based on <code>ocamlbuild</code>.
</p>
</section>
<br>
<section id="summary">
<h2>Summary of ReactiveML Expressions</h2>
<p>
Terminal symbols are set
in <code>typewriter font</code>.
Non-terminal symbols are set
in <code><i>italic font</i></code>.
Square
brackets <i><code>[]</code></i>
denote optional components. Curly
brackets <i><code>{}</code></i>
denote zero, one or several repetitions of the enclosed
components. Parentheses <i><code>()</code></i>
denote grouping
and <code><i>|</i></code>
denotes alternatives.
</p>
<br>
<!-- <div class="row"> -->
<!-- <div class="col-md-6"> -->
<section id="process">
<h3>Process Definitions</h3>
<pre>
<col-md- style="color: #008b8b;">let</col-md-> <col-md- style="color: #008b8b;">process</col-md-> <i><id></i> <i>{</i> <i><pattern></i> <i>}</i> = <i><expr></i> <col-md- style="color: #008b8b;">in</col-md-> <i><expr></i>
<col-md- style="color: #008b8b;">process</col-md-> <i><expr></i>
<col-md- style="color: #008b8b;">proc</col-md-> <i><pattern></i> <i>{</i> <i><pattern></i> <i>}</i> <col-md- style="color: #008b8b;">-></col-md-> <i><expr></i>
</pre>
<br>
<p>
Process definitions are introduced by
the <code><col-md- style="color: #008b8b;">process</col-md-></code>
keyword. For instance <code><col-md- style="color: #008b8b;">let</col-md-> <col-md- style="color: #008b8b;">process</col-md-> p x1 x2 ... = e</code>
defines a process <code>p</code> with several
arguments <code>x1</code>, <code>x2</code>, ... and a
body <code>e</code>.
The notation
<code>
<col-md- style="color: #008b8b;">let</col-md-> <col-md- style="color: #008b8b;">process</col-md-> p x1 x2 ... = e</code>
is a shortcut for
<code>
<col-md- style="color: #008b8b;">let</col-md-> p = <col-md- style="color: #008b8b;">fun</col-md-> x1 x2 ... -> <col-md- style="color: #008b8b;">process</col-md-> e</code>
and the notation
<code>
(<col-md- style="color: #008b8b;">proc</col-md-> x1 x2 ... <col-md- style="color: #008b8b;">-></col-md-> e)</code>
is a shortcut for
<code>
(<col-md- style="color: #008b8b;">fun</col-md-> x1 x2 ... <col-md- style="color: #008b8b;">-></col-md-> (<col-md- style="color: #008b8b;">process</col-md-> e))</code>.
</p>
</section>
<hr>
<section id="statements">
<h3>Basic statements</h3>
<pre>
<col-md- style="color: #008b8b;">nothing</col-md->
<col-md- style="color: #008b8b;">pause</col-md->
<col-md- style="color: #008b8b;">halt</col-md->
<col-md- style="color: #008b8b;">run</col-md-> <i><process></i>
</pre>
<br>
<p>
<code><col-md- style="color: #008b8b;">nothing</col-md-></code> is equivalent to<code>()</code> (can be used only in a process).<br>
<code><col-md- style="color: #008b8b;">pause</col-md-></code> suspends the
execution until next instant.<br>
<code><col-md- style="color: #008b8b;">halt</col-md-></code>
suspends the execution forever (it is equivalent
to <code><col-md- style="color:
#008b8b;">loop</col-md-> <col-md- style="color:
#008b8b;">pause</col-md-> <col-md- style="color:
#008b8b;">end</col-md-></code>, see below).<br>
<code><col-md- style="color: #008b8b;">run</col-md-> p</code> executes the process <code>p</code>.
</p>
</section>
<hr>
<section id="compositions">
<h3>Compositions</h3>
<pre>
<i><expr></i> ; <i><expr></i>
<i><expr></i> || <i><expr></i>
<col-md- style="color: #008b8b;">let</col-md-> <i><pattern></i> = <i><expr> {</i> <col-md- style="color: #008b8b;">and</col-md-> <i><pattern></i> = <i><expr> }</i> <col-md- style="color: #008b8b;">in</col-md-> <i><expr></i>
<i><expr></i> |> <i><expr></i></pre>
<br>
<p>
In ReactiveML, expressions can be composed in
sequence (<code>p;q</code>) or in
parallel (<code>p||q</code>). The expression
<col-md- style="color: #008b8b;">let</col-md->
x1 = e1 <col-md- style="color: #008b8b;">and</col-md->
x2 = e2 <col-md- style="color: #008b8b;">and</col-md->
x3 = e3 <col-md- style="color: #008b8b;">and</col-md->
... <col-md- style="color: #008b8b;">in</col-md-> e</pre> compute
expressions <code>e1, e2, e3, ...</code> in parallel to use
the result in expresion <code>e</code>.
<br><br> The expression <code>e1 |> e2</code> executes <code>e1</code>
and <code>e2</code> in parallel, but at each
instant <code>e1</code> is executed before <code>e2</code>
(this construct is not supported in all runtime).
</p>
</section>
<hr>
<section id="iterators">
<h3>Iterators</h3>
<pre>
<col-md- style="color: #008b8b;">loop</col-md-> <i><expr></i> <col-md- style="color: #008b8b;">end</col-md->
<col-md- style="color: #008b8b;">while</col-md-> <i><expr></i> <col-md- style="color: #008b8b;">do</col-md-> <i><expr></i> <col-md- style="color: #008b8b;">done</col-md->
<col-md- style="color: #008b8b;">for</col-md-> <i><id></i> = <i><expr> (</i> <col-md- style="color: #008b8b;">to</col-md-> <i> | </i> <col-md- style="color: #008b8b;">downto</col-md-> <i>) </i> <col-md- style="color: #008b8b;">do</col-md-> <i><expr></i> <col-md- style="color: #008b8b;">done</col-md->
<col-md- style="color: #008b8b;">for</col-md-> <i><id></i> = <i><expr> (</i> <col-md- style="color: #008b8b;">to</col-md-> <i> | </i> <col-md- style="color: #008b8b;">downto</col-md-> <i>)</i> <col-md- style="color: #008b8b;">dopar</col-md-> <i><expr></i> <col-md- style="color: #008b8b;">done</col-md-></pre>
<br>
<p>
The construct <code><col-md- style="color:
#008b8b;">loop</col-md->/<col-md- style="color:
#008b8b;">end</col-md-></code> is an infinite
loop. <code><col-md- style="color:
#008b8b;">while</col-md->/<col-md- style="color:
#008b8b;">do</col-md->/<col-md- style="color:
#008b8b;">done</col-md-></code> and <code><col-md- style="color:
#008b8b;">for</col-md->/<col-md- style="color:
#008b8b;">do</col-md->/<col-md- style="color:
#008b8b;">done</col-md-></code> are the classical loops. They
execute their body several times in sequence. Contrarily,
the <code><col-md- style="color:
#008b8b;">for</col-md->/<col-md- style="color:
#008b8b;">dopar</col-md->/<col-md- style="color:
#008b8b;">done</col-md-></code> loop executes its body several
times in parallel.
</p>
</section>
<hr>
<!-- </div> -->
<!-- <div class="col-md-6"> -->
<section id="signalDecl">
<h3>Signal declaration</h3>
<pre>
<col-md- style="color: #008b8b;">signal</col-md-> <i><id> {</i> , <i><id> }</i> <col-md- style="color: #008b8b;">in</col-md-> <i><expr></i>
<col-md- style="color: #008b8b;">signal</col-md-> <i><id></i> <col-md- style="color: #008b8b;">default</col-md-> <i><value></i> <col-md- style="color: #008b8b;">gather</col-md-> <i><function></i> <col-md- style="color: #008b8b;">in</col-md-> <i><expr></i></pre>
<br>
<p>
The construct <code><col-md- style="color:
#008b8b;">signal</col-md-> s</code> declares a new signal.
It is also possible to declare several signals at once: <code><col-md- style="color:
#008b8b;">signal</col-md-> s1, s2, s3, ...</code>.
<br>
<br>
Sometimes, multiple values can be emitted on a signal during the same
logical instant. This phenomenon is
called <i>Multi-emission</i>. Hence, when a signal is declared, it is
possible to define how to combine the values emitted during an instant
with the <code>
<col-md- style="color: #008b8b;">signal</col-md->/<col-md- style="color: #008b8b;">default</col-md->/<col-md- style="color: #008b8b;">gather</col-md->
</code> construct. Note that in this case, a default value is required.
<br>
For instance
<code>
<col-md- style="color: #008b8b;">signal</col-md-> s
<col-md- style="color: #008b8b;">default</col-md-> 0
<col-md- style="color: #008b8b;">gather</col-md->
(<col-md- style="color: #008b8b;">fun</col-md-> x y <col-md- style="color: #008b8b;">-></col-md-> x + y)
</code>
defines a a signal <code>s</code> with <code>0</code> as default
value, and <code>(+)</code> as combination function. Thus, in case of
multi-emission, the value of the signal is the sum of all emitted
values. If no combination function is given, the behavior of the
signal is to collect all emitted values in a list.
</p>
</section>
<hr>
<section id="signalEm">
<h3>Signal emission</h3>
<pre>
<col-md- style="color: #008b8b;">emit</col-md-> <i><signal> [ <value> ]</i></pre>
<br>
<p>
Signal emissions are instantaneous broadcasting. Hence, a
signal is present or absent during an instant but it cannot
have both status. The notation <code> <col-md- style="color:
#008b8b;">emit</col-md-> s</code> is a shortcut
for <code> <col-md- style="color: #008b8b;">emit</col-md-> s
()</code>, i.e., emit the value <code>()</code> on
signal <code>s</code>.
</p>
</section>
<hr>
<section id="signalSt">
<h3>Signal status</h3>
<pre>
<col-md- style="color: #008b8b;">present</col-md-> <i><signal></i> <col-md- style="color: #008b8b;">then</col-md-> <i><expr></i> <col-md- style="color: #008b8b;">else</col-md-> <i><expr></i>
<col-md- style="color: #008b8b;">await</col-md-> <i>[</i> <col-md- style="color: #008b8b;">immediate</col-md-> <i>]</i> <i><signal></i>
<col-md- style="color: #008b8b;">pre</col-md-> <i><signal></i></pre>
<br>
<p>
The expression <code><col-md- style="color: #008b8b;">present</col-md->
s <col-md- style="color: #008b8b;">then</col-md-> p <col-md- style="color:
#008b8b;">else</col-md-> q</code> tests the status of a
signal <code>s</code>. If the signal is present,
the <code><col-md- style="color: #008b8b;">then</col-md-></code>
branch <code>p</code> is executed instantaneously, otherwise
the <code><col-md- style="color: #008b8b;">else</col-md-></code>
branch <code>q</code> is executed at the following instant.
<br><br>
The expression <code><col-md- style="color: #008b8b;">await</col-md-> s</code>
waits <code>s</code> to be emitted and terminates at
the following instant. Whereas the expression
<code><col-md- style="color: #008b8b;">await</col-md-> <col-md- style="color:
#008b8b;">immediate</col-md-> s</code> waits <code>s</code> to be
emitted and terminates instantaneously.
<br><br>
Like in Esterel, the non-immediate version
of <code><col-md- style="color: #008b8b;">await</col-md-></code> is the
default one. Hence <code><col-md- style="color: #008b8b;">await</col-md->
s; <col-md- style="color: #008b8b;">await</col-md-> s</code> waits two
occurrences of <code>s</code>, while
<code><col-md- style="color: #008b8b;">await</col-md-> <col-md- style="color:
#008b8b;">immediate</col-md-> s; <col-md- style="color:
#008b8b;">await</col-md-> <col-md- style="color:
#008b8b;">immediate</col-md-> s</code> is equivalent
to <code><col-md- style="color:
#008b8b;">await</col-md-> <col-md- style="color:
#008b8b;">immediate</col-md-> s</code>.
<br><br>
The expression <code><col-md- style="color: #008b8b;">pre</col-md-> s</code> returns <code>true</code> if the signal
<code>s</code> has been emitted at the preceding, and <code>false</code> otherwise.
</p>
</section>
<hr>
<section id="signalVal">
<h3>Signal value</h3>
<pre>
<col-md- style="color: #008b8b;">await</col-md-> <i><signal> (<pattern>) [</i> <col-md- style="color: #008b8b;">when</col-md-> <i><expr> ]</i> <col-md- style="color: #008b8b;">in</col-md-> <i><expr></i>
<col-md- style="color: #008b8b;">await</col-md-> <i>[</i> <col-md- style="color: #008b8b;">immediate</col-md-> <i>]</i> <col-md- style="color: #008b8b;">one</col-md-> <i><signal> (<variable>)</i> <col-md- style="color: #008b8b;">in</col-md-> <i><expr></i>
<col-md- style="color: #008b8b;">pre</col-md-> ?<i><signal></i>
<col-md- style="color: #008b8b;">last</col-md-> ?<i><signal></i>
<col-md- style="color: #008b8b;">default</col-md-> ?<i><signal></i></pre>
<br>
<p>
The construct <code><col-md- style="color:
#008b8b;">await</col-md-> s(v) <col-md- style="color:
#008b8b;">in</col-md-> p</code> waits the emission of a signal <code>s</code>. At
the instant following the emission, the body <code>p</code> is executed in an
environment where the pattern <code>v</code> is bind to the value of the
signal (the combination of the values emitted at the preceding
instant).
<br>
<br>
It is possible to match the value of a signal and keep waiting
if the condition is not satisfied. For instance the
expression <code><col-md- style="color: #008b8b;">await</col-md->
s(x::y::_) <col-md- style="color: #008b8b;">when</col-md-> (x + y >
42) <col-md- style="color: #008b8b;">in</col-md-> p</code> waits for
a list of at least two elements. Then, the sum of the first two
elements of the list <code>x + y</code> must be greater
than <code>42</code> to trigger the execution
of <code>p</code>.
Notice that this construct keeps waiting when the value of the
signal does not match the pattern (e.g., <code>x::y::_</code>) or if
the condition specified after the when keyword is not
satisfied (e.g., <code>x + y > 42</code>).<br><br>
The expression expression <code><col-md- style="color:
#008b8b;">await</col-md-> <col-md- style="color:
#008b8b;">one</col-md-> s (v) <col-md- style="color:
#008b8b;">in</col-md-> p</code> waits the emission of a
signal <code>s</code> to bind the pattern <code>v</code> with
one of the emitted values on signal <code>s</code>. In case of
multiple emission during an instant, the choice of the value
is not specified. Like <code><col-md- style="color:
#008b8b;">await</col-md-></code>, the body of the expression is
executed at the instant following the reception of the signal
(except if there is the <code><col-md- style="color:
#008b8b;">immediate</col-md-></code> keyword). To be causal by
construction, there is no immediate version of
the <code><col-md- style="color:
#008b8b;">await</col-md->/<col-md- style="color:
#008b8b;">in</col-md-></code> construct.<br><br>
The expression <code><col-md- style="color: #008b8b;">pre</col-md-> ?s</code> evaluates to the value
associated to <code>s</code> at the preceding instant. If <code>s</code>
has not been emitted at the preceding instant,
<code><col-md- style="color: #008b8b;">pre</col-md-> ?s</code> is equal to the default value given at
the declaration point of the signal. <code><col-md- style="color: #008b8b;">last</col-md-> ?s</code>
has a slight different behavior. It evaluates
to the last value associated to <code>s</code> when it was
emitted. Until the first emission of signal <code>s</code>, <code><col-md- style="color: #008b8b;">pre</col-md->
?s</code> and <code><col-md- style="color: #008b8b;">last</col-md-> ?s</code> both evaluates to the default
value of <code>s</code>.<br><br>
The expression <code><col-md- style="color: #008b8b;">default</col-md-> s</code> returns the default value
of a signal <code>s</code>.
</p>
</section>
<!-- </div> -->
<hr>
<h3>Control structures</h3>
<section id="control">
<pre>
<col-md- style="color: #008b8b;">do</col-md-> <i><expr></i> <col-md- style="color: #008b8b;">when</col-md-> <i><signal></i> <col-md- style="color: #008b8b;">done</col-md->
<col-md- style="color: #008b8b;">control</col-md-> <i><expr></i> <col-md- style="color: #008b8b;">with</col-md-> <i><signal> [ (<pattern>) [</i> <col-md- style="color: #008b8b;">when</col-md-> <i> <expr> ] ]</i> <col-md- style="color: #008b8b;">done</col-md->
<col-md- style="color: #008b8b;">do</col-md-> <i><expr></i> <col-md- style="color: #008b8b;">until</col-md-> <i><signal> [ (<pattern>) [</i> <col-md- style="color: #008b8b;">when</col-md-> <i> <expr> ] [</i> <col-md- style="color: #008b8b;">-></col-md-> <i> <expr> ] ]</i> <col-md- style="color: #008b8b;">done</col-md->
<col-md- style="color: #008b8b;">do</col-md-> <i><expr></i> <col-md- style="color: #008b8b;">until</col-md-> <i><signal> (<pattern>) [</i> <col-md- style="color: #008b8b;">when</col-md-> <i> <expr> ]</i> <col-md- style="color: #008b8b;">-></col-md-> <i><expr></i>
<i>{</i> | <i><signal> (<pattern>) [</i> <col-md- style="color: #008b8b;">when</col-md-> <i> <expr> ]</i> <col-md- style="color: #008b8b;">-></col-md-> <i><expr></i> <i>}</i> <col-md- style="color: #008b8b;">done</col-md->
</pre>
<br>
<p>
The <code><col-md- style="color:
#008b8b;">do</col-md->/<col-md- style="color:
#008b8b;">when</col-md->/<col-md- style="color:
#008b8b;">done</col-md-></code> and <code><col-md- style="color:
#008b8b;">control</col-md->/<col-md- style="color:
#008b8b;">with</col-md->/<col-md- style="color:
#008b8b;">done</col-md-></code> constructs allow to suspend the
execution of an expression. <code><col-md- style="color:
#008b8b;">do</col-md-> p <col-md- style="color:
#008b8b;">when</col-md-> s <col-md- style="color:
#008b8b;">done</col-md-></code> executes its body <code>p</code>
only when the signal <code>s</code> is
present. <code><col-md- style="color:
#008b8b;">control</col-md-> p <col-md- style="color:
#008b8b;">with</col-md-> s <col-md- style="color:
#008b8b;">done</col-md-></code> switches between an active mode
and a suspended one each time that the signal <code>s</code>is
present.<br><br>
The preemption construct <code><col-md- style="color:
#008b8b;">do</col-md-> p <col-md- style="color:
#008b8b;">until</col-md-> s <col-md- style="color:
#008b8b;">done</col-md-></code> stops the execution of its
body <code>p</code> at the end of instant when the
signal <code>s</code> is emitted (it is not a looping
construct). It is also posible to define a
handler <code><col-md- style="color: #008b8b;">do</col-md->
p <col-md- style="color: #008b8b;">until</col-md->
s <col-md- style="color: #008b8b;">-></col-md->
q <col-md- style="color: #008b8b;">done</col-md-></code>. In this case, an
emission of signal <code>s</code> stops the execution
of <code>p</code> and launches the execution of <code>q</code>
at the following instant.
<br><br>
Besides, it is always possible to match a given pattern in the
control structure. For instance the
code <code><col-md- style="color: #008b8b;">do</col-md->
p <col-md- style="color: #008b8b;">until</col-md-> s
(v) <col-md- style="color: #008b8b;">when</col-md-> (v >
0) <col-md- style="color: #008b8b;">-></col-md->
q <col-md- style="color: #008b8b;">done</col-md-></code> stops the
execution of <code>p</code> and launches <code>q</code> only
if the value emitted on signal <code>s</code> is positive.
</p>
</section>
<hr>
<h3>Event configurations</h3>
<section id="config">
<pre>
<col-md- style="color: #008b8b;">present</col-md-> <i><config></i> <col-md- style="color: #008b8b;">then</col-md-> <i><expr></i> <col-md- style="color: #008b8b;">else</col-md-> <i><expr></i>
<col-md- style="color: #008b8b;">await</col-md-> <i>[</i> <col-md- style="color: #008b8b;">immediate</col-md-> <i>]</i> <i><config></i>
<col-md- style="color: #008b8b;">await</col-md-> <i><config-patt> [</i> <col-md- style="color: #008b8b;">when</col-md-> <i><expr> ]</i> <col-md- style="color: #008b8b;">in</col-md-> <i><expr></i>
<col-md- style="color: #008b8b;">do</col-md-> <i><expr></i> <col-md- style="color: #008b8b;">when</col-md-> <i><config></i> <col-md- style="color: #008b8b;">done</col-md->
<col-md- style="color: #008b8b;">control</col-md-> <i><expr></i> <col-md- style="color: #008b8b;">with</col-md-> <i><config-patt> [</i> <col-md- style="color: #008b8b;">when</col-md-> <i> <expr> ]</i> <col-md- style="color: #008b8b;">done</col-md->
<col-md- style="color: #008b8b;">do</col-md-> <i><expr></i> <col-md- style="color: #008b8b;">until</col-md-> <i><config-patt> [</i> <col-md- style="color: #008b8b;">when</col-md-> <i> <expr> ]</i> <col-md- style="color: #008b8b;">-></col-md-> <i><expr></i>
<i>{</i> | <i><config-patt>) [</i> <col-md- style="color: #008b8b;">when</col-md-> <i> <expr> ]</i> <col-md- style="color: #008b8b;">-></col-md-> <i><expr></i> <i>}</i> <col-md- style="color: #008b8b;">done</col-md->
</pre>
<br>
<p>
The behavior of these expressions is the same as before except
that instead of depending on a signal, they depend on a Boolean
configuration of signals. The
expressions <code><i><config></i></code>
and <code><i><config-patt></i></code> are defined as follows:
</p>
<pre>
<i><config></i> ::= <i><signal></i>
| <i><config></i> /\ <i><config></i>
| <i><config></i> \/ <i><config></i>
<i><config-patt></i> ::= <i><signal></i>
| <i><signal></i> (<i><pattern></i>)
| <i><config-patt></i> /\ <i><config-patt></i>
| <i><config-patt></i> \/ <i><config-patt></i>
</pre>
<!-- <table cellspacing=6 cellpadding=0> -->
<!-- <tr> -->
<!-- <td align=right nowrap><code><i><config></i></code></td> -->
<!-- <td align=center nowrap>::=</td> -->
<!-- <td align=left nowrap> <code><i><signal></i><code></td> -->
<!-- </tr> -->
<!-- <tr> -->
<!-- <td align=right nowrap> </td> -->
<!-- <td align=center nowrap>∣</td> -->
<!-- <td align=left nowrap> <code><i><config></i> /\ <i><config></i></td> -->
<!-- </tr> -->
<!-- <tr> -->
<!-- <td align=right nowrap> </td> -->
<!-- <td align=center nowrap>∣</td> -->
<!-- <td align=left nowrap> <code><i><config></i> \/ <i><config></i></td> -->
<!-- </tr> -->
<!-- <tr> -->
<!-- <td align=right nowrap><code><i><config-patt></i></code></td> -->
<!-- <td align=center nowrap>::=</td> -->
<!-- <td align=left nowrap> <code><i><signal></i><code> ∣ <code><i><signal></i>(<i><pattern></i>)<code></td> -->
<!-- </tr> -->
<!-- <tr> -->
<!-- <td align=right nowrap> </td> -->
<!-- <td align=center nowrap>∣</td> -->
<!-- <td align=left nowrap> <code><i><config-patt></i> /\ <i><config-patt></i></td> -->
<!-- </tr> -->
<!-- <tr> -->
<!-- <td align=right nowrap> </td> -->
<!-- <td align=center nowrap>∣</td> -->
<!-- <td align=left nowrap> <code><i><config-patt></i> \/ <i><config-patt></i></td> -->
<!-- </tr> -->
<!-- </table> -->
<br>
<p>
For example, the expression <code><col-md- style="color:
#008b8b;">await</col-md-> (s1(x) /\ s2(y)) \/
s3(x::y::_) <col-md- style="color: #008b8b;">when</col-md-> (x + y > 42)
<col-md- style="color: #008b8b;">in</col-md-> e</code> waits for either <code>s1</code> and <code>s2</code>
to be present simultaneously or <code>s3</code> to be present if
its associated value is a list of at least two elements. In
both cases, the variables <code>x</code> and <code>y</code> are
bound and the sum of their value must be greater
than <code>42</code> to trigger the execution of <code>e</code>.
</p>
</section>
</section>
<br>
<section id="stdlib">
<h2>Standard Library</h2>
<p>
Any OCaml code can be linked to a ReactiveML program as long as
it provides an interface file (<code>file.rmli</code>) which is compatible with
ReactiveML. Therefore, the standard library of OCaml is
available in ReactiveML.
</p>
<p>
The ReactiveML standard library also provides new modules:
</p>
<ul>
<li><a href="./documentation/stdlib/Rml_list.html">Module <code>Rml_list</code>: process iterators on lists</a></li>
<li><a href="./documentation/stdlib/Rml_process_manager.html">Module <code>Rml_process_manager</code>: process management combinators</a></li>
<li><a href="./documentation/stdlib/Async.html">Module <code>Async</code>: launching asychronous computations.</a></li>
</ul>
<p>
The full list of modules available in the standard library is <a href="./documentation/stdlib/index.html">here</a>.
</p>
</section>
</div>
</div>
<div class="row">
<div class="col-md-12">
<hr>
<div class="footer">
<div class="row">
<div class="col-md-6">
<p>
<small>
<a href="./navigation.html">navigation</a>
</small>
</p>
</div> <!-- /col-md-6 -->
<div class="col-md-6">
<p style="text-align: right">
<small>
<a href="./distrib">ReactiveML version 1.09.04-dev</a><br>
2014-09-22 <a href="./distrib/changes">changes</a>
<!-- <br> -->
<!-- Warning: incompatible changes with previous versions are marked with <tt>*</tt>: <a href="distrib/changes">changes</a> -->
</small>
</p>
</div> <!-- /col-md-6 -->
</div> <!-- /row -->
</div> <!-- /footer -->
</div> <!-- /col-md-12 -->
</div> <!-- /row -->
</div> <!-- /container -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-37633890-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script type="text/javascript" src="./bootstrap/js/jquery.js"></script>
<script type="text/javascript" src="./bootstrap/js/bootstrap.min.js"></script>
</body>
</html>