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
|
// Example code.
// - NOTE: The syntax is very likely to change, and this may be not
// up-to-date.
function square(int n) = ($n * $n)
function f(int x, int y, str s, bool b) =
( $x + 4 * ($y + 5) == $y - $x + 4
|| $b
&& (int $s == $x || $s == str $x)
)
// Recursion.
function f(int n) = (n + f n);
procedure int p(str x, int n, bool b)
{
int ret;
// Pass $x into `sed`, store result in $s.
s <= @sed "-E" "s/x/y/g" <= $x;
// Pass $x into grep, get return code.
ret <- @grep "-qE" "x" <= $s;
if ($ret == 0 && b)
{
return 0 /* return/exit code */, int $x /* return value */;
}
else
{
return 1, 0;
}
}
procedure int q()
{
str s;
read_line $s;
print $s;
print_err $s;
return 0, 42;
}
procedure int r()
{
int ret;
str stdout, stderr;
int value;
// Evaluate an expression.
value = square 7 - 5;
// Get all data from a procedure call.
(ret, value, stdout, stderr) <- p "x" 42 (3 == 4) <= "stdin";
// Minimal procedure call.
// - stdout, stderr, stdin are passed through.
// - Non-zero return code causes this procedure to return with that return
// code.
q;
// Get some data from a procedure call.
// - `:` means pass through, `_` means ignore.
(ret, value) <- q;
(ret, _, :, stderr) <- q;
(value, stdout, stderr) <= q;
value <= q;
(value, stdout) <= q;
(_, stdout) <= q;
return 0, $value;
}
procedure main()
{
while true
{
@date "-u";
r;
}
return 127; // no return value, only return code
}
// vi: ts=2 sw=0 et
|