-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhello.diderot
63 lines (52 loc) · 2.53 KB
/
hello.diderot
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
#version 1.0
/* ==========================================
## hello.diderot: The usual greeting, in Diderot
<!-- In this and other examples, the code blocks are on lines starting -->
<!-- with a tab character; these are generally intended to be shown as -->
<!-- pre-formatted text blocks via Markdown. The ../gen-readme.sh script -->
<!-- converts the current Diderot comment into the contents of the -->
<!-- README.md in this directory. This script also does some -->
<!-- experimental things to generate a test script .test.sh for each -->
<!-- example; the contents of these test scripts is based on the -->
<!-- (tab-indicated) code blocks herein, but with some modifications. -->
<!-- Those modifications are controlled with the lines starting with -->
<!-- "\t#" (tab pound), which are also processed by -->
<!-- ../gen-readme.sh. These lines (as well as these HTML comments) will -->
<!-- not show up in the generated README.md; but they do control the -->
<!-- contents of the generated .test.sh, which are run as a group with -->
<!-- ../runtests.py -->
<!-- THUS: you can ignore all the \t# lines, and read ./README.md -->
<!-- for the program documentation as it was intended to be seen. -->
You can compile `hello.diderot` with:
#!
diderotc --exec hello.diderot
#prog hello.diderot
and then run it with:
./hello
#_junk out.nrrd
After the `hello` executable prints `hello, world`, it saves a single-element
1-D array into `out.nrrd`. We can inspect its contents with:
unu save -f text -i out.nrrd
which should print the number 42.
========================================== */
/* Strands normally have parameters, so that different strands can be
initialized with different values. This unusual case, with only a single
strand, does not need parameters (and having an unused parameter would
produce a warning. */
strand hello () {
/* Every Diderot program must have at least one output variable. */
output int out = 42;
update {
print("hello, world\n");
/* this minimal program can be repurposed as a simple expression
debugging tool. For example, if you were uncertain about the
order of arguments to atan2(), you could use:
real a = 0; real b = 1;
print("atan2(", a, ",", b, ") = ", atan2(a,b), "\n");
to learn that atan2(0,1) = 0, so its atan2(y,x), like in C. */
/* The strand runs for only its initial iteration, then stops
by stabilizing, which stores the final value of the output. */
stabilize;
}
}
initially [ hello() | ii in 0..0 ]; // only one strand