1module: sample
2comment: for make sure that does not highlight per word.
3         and it continues on to the next line.
4
5define class <car> (<object>)
6  slot serial-number :: <integer> = unique-serial-number();
7  constant slot model-name :: <string>,
8    required-init-keyword: model:;
9  each-subclass slot has-sunroof? :: <boolean>,
10    init-keyword: sunroof?:,
11    init-value: #f;
12  keyword foo:;
13  required keyword bar:;
14end class <car>;
15
16define class <flying-car> (<car>)
17end class <flying-car>;
18
19let flying-car = make(<flying-car>);
20let car? :: <car?> = #f;
21let prefixed-car :: <vehicles/car> = #f;
22let model :: <car-911> = #f;
23
24define constant $empty-string = "";
25define constant $escaped-backslash = '\\';
26define constant $escaped-single-quote = '\'';
27
28define variable *unique-serial-number* = 0;
29
30define function unique-serial-number() => (usn :: <integer>)
31  let serial = *unique-serial-number*;
32  *unique-serial-number* := *unique-serial-number* + 1;
33  serial;
34end function;
35
36define constant $blue-car = make(<car>, model: "Viper");
37define constant $black-car = make(<car>, model: "Town Car", sunroof?: #t);
38define constant $red-car = make(<car>, model: "F40", sunroof?: #f);
39
40define method foo() => _ :: <boolean>
41  #t
42end method;
43
44define method foo() => _ :: <boolean>;
45  #t
46end method;
47
48define method \+
49    (offset1 :: <time-offset>, offset2 :: <time-offset>)
50 => (sum :: <time-offset>)
51  let sum = offset1.total-seconds + offset2.total-seconds;
52  make(<time-offset>, total-seconds: sum);
53end method \+;
54
55define method bar ()
56  1 | 2 & 3
57end
58
59if (bar)
60  1
61elseif (foo)
62  2
63else
64  3
65end if;
66
67select (foo by instance?)
68  <integer> => 1
69  otherwise => 3
70end select;
71
72/* multi
73   line
74   comment
75*/
76
77/* multi line comments
78  /* can be */
79  nested */
80
81define constant $symbol = #"hello";
82define variable *vector* = #[3.5, 5]
83define constant $list = #(1, 2);
84define constant $pair = #(1 . "foo")
85
86let octal-number = #o238;
87let hex-number = #x3890ADEF;
88let binary-number = #b1010;
89let float-exponent = 3.5e10;
90
91block (return)
92  with-lock (lock)
93    return();
94  end;
95exception (e :: <error>)
96    format-out("Oh no");
97cleanup
98    return();
99afterwards
100    format-out("Hello");
101end;
102
103define macro repeat
104  { repeat ?:body end }
105   => { block (?=stop!)
106          local method again() ?body; again() end;
107          again();
108        end }
109end macro repeat;
110
111define macro with-decoded-seconds
112  {
113    with-decoded-seconds
114      (?max:variable, ?min:variable, ?sec:variable = ?time:expression)
115      ?:body
116    end
117  }
118    => {
119         let (?max, ?min, ?sec) = decode-total-seconds(?time);
120         ?body
121       }
122end macro;
123
124let x = "This size call should be seen as a builtin despite the odd case.".siZe;
125
126