summaryrefslogtreecommitdiff
path: root/doc/colm/0_05_fizzbuzz.adoc
blob: 6e30279e30d37b997d9c3610eb9e0b25e677c2c8 (plain)
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
FizzBuzz
========

== Slightly modified example of thesis: Figure 4.4, page 87

The colm language has evolved since it has been described in the thesis.
With some modifications we can reactivate this example.

[source,chapel]
.figure_44.lm
----
include::code/figure_44.lm[]
----

Please Note:

* the syntax is very c-ish
* the variables are defined with their type
* there is no postfix increment operator (i = i +1)

[source,bash]
----
/opt/colm/bin/colm fizzbuzz.lm
./fizzbuzz
----

That gives us:
----
hello 0 0
hello 1 1
hello 2 2
hello 8 3
hello 9 4
----

== Real FizzBuzz

The fizzbuzz test is often used to check is someone has programming skils.
It is the next logical step to 'hello world'.

[source,chapel]
.fizzbuzz.lm
----
include::code/fizzbuzz.lm[]
----

It appears that there is no modulo operator ('%').
Therefor we'll resort to a function.
Writing a function seems rather straight forward

Please note:
* that '&&' is working.
* The return type is needed, but if 'nil' is retuned by default.

[source,bash]
----
/opt/colm/bin/colm fizzbuzz.lm
./fizzbuzz
----

That gives us
----
FizzBuzz
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
----