-
Notifications
You must be signed in to change notification settings - Fork 0
/
samples.xhtml
326 lines (309 loc) · 47.7 KB
/
samples.xhtml
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8"/>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="description" content=""/>
<meta name="author" content="ink, cookbook, recipes"/>
<meta name="HandheldFriendly" content="True"/>
<meta name="MobileOptimized" content="320"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
<meta property="og:title" content="Wrapl, The Programming Language"/>
<meta property="og:description" content="Wrapl, The Programming Language"/>
<meta property="og:url" content="http://wrapl.sf.net"/>
<meta property="og:image" content="http://wrapl.sf.net/sample.png"/>
<link rel="stylesheet" type="text/css" href="/css/spectre.css"/>
<link rel="stylesheet" type="text/css" href="/css/spectre-exp.css"/>
<link rel="stylesheet" type="text/css" href="/css/spectre-icons.css"/>
<link rel="stylesheet" type="text/css" href="/code.css"/>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous"/>
<link href="https://fonts.googleapis.com/css?family=Roboto|Roboto+Mono" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/css?family=Fira+Sans" rel="stylesheet"/>
<link rel="stylesheet" href="https://cdn.rawgit.com/tonsky/FiraCode/1.205/distr/fira_code.css"/>
<title>Samples</title>
</head>
<body>
<div class="off-canvas off-canvas-sidebar-show">
<a class="off-canvas-toggle btn btn-primary btn-action" href="#sidebar-id">
<i class="icon icon-menu"></i>
</a>
<div id="sidebar-id" class="off-canvas-sidebar">
<ul class="nav">
<li class="nav-item"><a href="/index.xhtml" class="toplevel"><i class="fa fa-home"></i> Home</a>
<ul class="nav">
<li class="nav-item"><a href="/index.xhtml#Features">Features</a></li>
<li class="nav-item"><a href="/index.xhtml#Contact">Contact</a></li>
</ul>
</li>
<li class="nav-item"><a href="/news.xhtml" class="toplevel"><i class="fa fa-clock"></i> News</a></li>
<li class="nav-item"><a href="/docs.xhtml" class="toplevel"><i class="fa fa-book"></i> Documentation</a>
<ul class="nav">
<li class="nav-item"><a href="/ref/tutorial.xhtml">Tutorial</a></li>
<li class="nav-item"><a href="/docs.xhtml#Reference">Reference</a>
<ul class="nav flyout right">
<li class="nav-item"><a href="/ref/syntax.xhtml">Syntax</a></li>
<li class="nav-item"><a href="/ref/expressions.xhtml">Expressions</a></li>
</ul>
</li>
<li class="nav-item"><a href="/samples.xhtml">Sample</a></li>
<li class="nav-item"><a href="/lib.xhtml">Libraries</a></li>
<li class="nav-item"><a href="/docs.xhtml#tools">Tools</a></li>
<li class="nav-item"><a href="/internals.xhtml">Internals</a></li>
</ul>
</li>
<li class="nav-item"><a href="/download.xhtml" class="toplevel"><i class="fa fa-download"></i> Download</a>
<ul class="nav">
<li class="nav-item"><a href="/download.xhtml#Source">Source</a></li>
<li class="nav-item"><a href="/download.xhtml#Binaries">Binaries</a></li>
</ul>
</li>
<li class="nav-item"><a href="/links.xhtml" class="toplevel"><i class="fa fa-globe"></i> Links</a>
<ul class="nav">
<li class="nav-item"><a href="/links.xhtml#Programming_Languages">Other Languages</a></li>
<li class="nav-item"><a href="/links.xhtml#Development_Tools">Development Tools</a></li>
<li class="nav-item"><a href="/links.xhtml#Libraries">Libraries</a></li>
</ul>
</li>
</ul>
</div>
<a class="off-canvas-overlay" href="#close"></a>
<div class="off-canvas-content">
<h1 id="title"><img src="/logo.png" alt="W"/> Wrapl, The Programming Language</h1>
<section id="Basic_Samples" class="section"><h2>Basic Samples</h2>
<section id="Hello_world_" data-spy="true" data-target="#side-menu"><h3>Hello world!</h3>
<div class="code"><span class="lineno"> 1</span><span class="keyword">MOD</span> <span class="var">Hello</span><span class="delimiter">;</span>
<span class="lineno"> 2</span>
<span class="lineno"> 3</span><span class="keyword">IMP</span> <span class="var">IO</span><span class="delimiter">.</span><span class="var">Terminal</span> <span class="keyword">USE</span> <span class="var">Out</span><span class="delimiter">;</span>
<span class="lineno"> 4</span>
<span class="lineno"> 5</span><span class="var">Out</span><span class="symbol">:write</span><span class="delimiter">(</span><span class="literal">"Hello world!"</span><span class="delimiter">);</span>
<span class="lineno"> 6</span>
<span class="lineno"> 7</span><span class="keyword">END</span> <span class="var">Hello</span><span class="delimiter">.</span></div>
</section>
<section id="Factorials" data-spy="true" data-target="#side-menu"><h3>Factorials</h3>
<h4 id="Recursive">Recursive</h4>
<div class="code"><span class="lineno"> 1</span><span class="keyword">MOD</span> <span class="var">Fact</span><span class="delimiter">;</span>
<span class="lineno"> 2</span>
<span class="lineno"> 3</span><span class="keyword">IMP</span> <span class="var">IO</span><span class="delimiter">.</span><span class="var">Terminal</span> <span class="keyword">USE</span> <span class="var">Out</span><span class="delimiter">;</span>
<span class="lineno"> 4</span>
<span class="lineno"> 5</span><span class="keyword">DEF</span> <span class="var">Fact</span><span class="delimiter">(</span><span class="var">n</span><span class="delimiter">)</span> <span class="var">n</span> <span class="delimiter"><</span> 2 <span class="delimiter">=></span> 1 <span class="delimiter">//</span> <span class="var">n</span> <span class="delimiter">*</span> <span class="var">Fact</span><span class="delimiter">(</span><span class="var">n</span> <span class="delimiter">-</span> 1<span class="delimiter">);</span>
<span class="lineno"> 6</span>
<span class="lineno"> 7</span><span class="var">Out</span><span class="symbol">:write</span><span class="delimiter">(</span><span class="literal">'10! = </span><span class="nested"><span class="delimiter">{</span><span class="var">Fact</span><span class="delimiter">(</span>10<span class="delimiter">)}</span></span><span class="literal">'</span><span class="delimiter">);</span>
<span class="lineno"> 8</span>
<span class="lineno"> 9</span><span class="keyword">END</span> <span class="var">Fact</span><span class="delimiter">.</span></div>
<h4 id="Iterative">Iterative</h4>
<div class="code"><span class="lineno"> 1</span><span class="keyword">MOD</span> <span class="var">Fact</span><span class="delimiter">;</span>
<span class="lineno"> 2</span>
<span class="lineno"> 3</span><span class="keyword">DEF</span> <span class="var">Fact</span><span class="delimiter">(</span><span class="var">n</span><span class="delimiter">)</span> <span class="delimiter">(</span>
<span class="lineno"> 4</span> <span class="keyword">VAR</span> <span class="var">f</span> <span class="delimiter"><-</span> 1<span class="delimiter">;</span>
<span class="lineno"> 5</span> <span class="keyword">EVERY</span> <span class="var">f</span> <span class="delimiter"><-</span> <span class="var">f</span> <span class="delimiter">*</span> 1<span class="symbol">:to</span><span class="delimiter">(</span><span class="var">n</span><span class="delimiter">);</span>
<span class="lineno"> 6</span> <span class="keyword">RET</span> <span class="var">f</span><span class="delimiter">;</span>
<span class="lineno"> 7</span><span class="delimiter">);</span>
<span class="lineno"> 8</span>
<span class="lineno"> 9</span><span class="var">Out</span><span class="symbol">:write</span><span class="delimiter">(</span><span class="literal">'10! = </span><span class="nested"><span class="delimiter">{</span><span class="var">Fact</span><span class="delimiter">(</span>10<span class="delimiter">)}</span></span><span class="literal">'</span><span class="delimiter">);</span>
<span class="lineno"> 10</span>
<span class="lineno"> 11</span><span class="keyword">END</span> <span class="var">Fact</span><span class="delimiter">.</span></div>
</section>
<section id="Prime_Numbers" data-spy="true" data-target="#side-menu"><h3>Prime Numbers</h3>
<p>The following function generates all the prime numbers.</p>
<div class="code"><span class="lineno"> 1</span><span class="keyword">DEF</span> <span class="var">Primes</span><span class="delimiter">()</span> <span class="delimiter">(</span>
<span class="lineno"> 2</span> <span class="keyword">WITH</span> <span class="var">store</span> <span class="delimiter"><-</span> <span class="delimiter">[]</span> <span class="keyword">DO</span> <span class="keyword">EVERY</span> <span class="var">store</span><span class="symbol">:put</span><span class="delimiter">(</span><span class="keyword">SUSP</span> 2<span class="symbol">:up</span> <span class="delimiter">\</span> <span class="keyword">NOT</span> <span class="delimiter">($</span> <span class="delimiter">%</span> <span class="var">store</span><span class="symbol">:values</span> <span class="delimiter">=</span> 0<span class="delimiter">));</span>
<span class="lineno"> 3</span><span class="delimiter">);</span></div>
<div class="term"><span class="prompt">--></span> ALL 10 OF 10 SKIP Primes();
[31, 37, 41, 43, 47, 53, 59, 61, 67, 71]
</div>
<p>How it works is left as an exercise to the reader :).</p>
</section>
</section>
<section id="Objects_and_Methods" class="section"><h2>Objects and Methods</h2>
<section id="Complex_Numbers" data-spy="true" data-target="#side-menu"><h3>Complex Numbers</h3>
<div class="code"><span class="lineno"> 1</span><span class="keyword">MOD</span> <span class="var">Complex</span><span class="delimiter">;</span>
<span class="lineno"> 2</span>
<span class="lineno"> 3</span><span class="keyword">IMP</span> <span class="var">Std</span><span class="delimiter">.</span><span class="var">String</span><span class="delimiter">;</span>
<span class="lineno"> 4</span>
<span class="lineno"> 5</span><span class="comment">-- Type for complex numbers</span>
<span class="lineno"> 6</span><span class="keyword">DEF</span> <span class="var">T</span><span class="delimiter">!</span> <span class="delimiter"><-</span> <span class="delimiter"><[]</span> <span class="var">re</span><span class="delimiter">,</span> <span class="var">im</span><span class="delimiter">>;</span>
<span class="lineno"> 7</span>
<span class="lineno"> 8</span><span class="comment">-- Converts a complex number to a string</span>
<span class="lineno"> 9</span><span class="keyword">TO</span> <span class="symbol">:</span><span class="literal">"@"</span><span class="delimiter">(</span><span class="var">cmplx</span><span class="delimiter">@</span><span class="var">T</span><span class="delimiter">,</span> <span class="delimiter">=</span><span class="var">String</span><span class="delimiter">.</span><span class="var">T</span><span class="delimiter">)</span> <span class="literal">'</span><span class="nested"><span class="delimiter">{</span><span class="var">cmplx</span><span class="symbol">:re</span><span class="delimiter">}</span></span><span class="literal"> + </span><span class="nested"><span class="delimiter">{</span><span class="var">cmplx</span><span class="symbol">:im</span><span class="delimiter">}</span></span><span class="literal">i'</span><span class="delimiter">;</span>
<span class="lineno"> 10</span>
<span class="lineno"> 11</span><span class="comment">-- Arithmetic methods</span>
<span class="lineno"> 12</span><span class="keyword">TO</span> <span class="symbol">:</span><span class="literal">"+"</span><span class="delimiter">(</span><span class="var">a</span><span class="delimiter">@</span><span class="var">T</span><span class="delimiter">,</span> <span class="var">b</span><span class="delimiter">@</span><span class="var">T</span><span class="delimiter">)</span> <span class="var">T</span><span class="delimiter">(</span><span class="var">a</span><span class="symbol">:re</span> <span class="delimiter">+</span> <span class="var">b</span><span class="symbol">:re</span><span class="delimiter">,</span> <span class="var">a</span><span class="symbol">:im</span> <span class="delimiter">+</span> <span class="var">b</span><span class="symbol">:im</span><span class="delimiter">);</span>
<span class="lineno"> 13</span>
<span class="lineno"> 14</span><span class="keyword">TO</span> <span class="symbol">:</span><span class="literal">"-"</span><span class="delimiter">(</span><span class="var">a</span><span class="delimiter">@</span><span class="var">T</span><span class="delimiter">,</span> <span class="var">b</span><span class="delimiter">@</span><span class="var">T</span><span class="delimiter">)</span> <span class="var">T</span><span class="delimiter">(</span><span class="var">a</span><span class="symbol">:re</span> <span class="delimiter">-</span> <span class="var">b</span><span class="symbol">:re</span><span class="delimiter">,</span> <span class="var">a</span><span class="symbol">:im</span> <span class="delimiter">-</span> <span class="var">b</span><span class="symbol">:im</span><span class="delimiter">);</span>
<span class="lineno"> 15</span>
<span class="lineno"> 16</span><span class="keyword">TO</span> <span class="symbol">:</span><span class="literal">"*"</span><span class="delimiter">(</span><span class="var">a</span><span class="delimiter">@</span><span class="var">T</span><span class="delimiter">,</span> <span class="var">b</span><span class="delimiter">@</span><span class="var">T</span><span class="delimiter">)</span> <span class="var">T</span><span class="delimiter">(</span><span class="var">a</span><span class="symbol">:re</span> <span class="delimiter">*</span> <span class="var">b</span><span class="symbol">:re</span> <span class="delimiter">-</span> <span class="var">a</span><span class="symbol">:im</span> <span class="delimiter">*</span> <span class="var">b</span><span class="symbol">:im</span><span class="delimiter">,</span> <span class="var">a</span><span class="symbol">:re</span> <span class="delimiter">*</span> <span class="var">b</span><span class="symbol">:im</span> <span class="delimiter">+</span> <span class="var">a</span><span class="symbol">:im</span> <span class="delimiter">*</span> <span class="var">b</span><span class="symbol">:re</span><span class="delimiter">);</span>
<span class="lineno"> 17</span>
<span class="lineno"> 18</span><span class="keyword">END</span> <span class="var">Complex</span><span class="delimiter">.</span></div>
<div class="term"><span class="prompt">$</span> wrapl
<span class="prompt">--></span> IMP .Complex;
NIL
<span class="prompt">--></span> VAR a <- Complex.T(1, 2);
1 + 2i
<span class="prompt">--></span> VAR b <- Complex.T(3, -5);
3 + -5i
<span class="prompt">--></span> a + b;
4 + -3i
<span class="prompt">--></span> a - b;
-2 + 7i
<span class="prompt">--></span> a * b;
13 + -7i
</div>
</section>
</section>
<section id="wrpp" class="section"><h2>wrpp</h2>
<section id="wrpp" data-spy="true" data-target="#side-menu"><h3>wrpp</h3>
<p>Here is the entire source code for the <a href="/tools/wrpp.xhtml"><span class="var">wrpp</span></a> preprocessor.</p>
<div class="code"><span class="lineno"> 1</span><span class="delimiter">#!</span><span class="var">INTERPRETER</span> <span class="delimiter">-</span><span class="var">tWrapl</span>
<span class="lineno"> 2</span><span class="keyword">MOD</span> <span class="var">Mark</span><span class="delimiter">;</span>
<span class="lineno"> 3</span>
<span class="lineno"> 4</span><span class="keyword">IMP</span> <span class="var">Sys</span><span class="delimiter">.</span><span class="var">FileSys</span><span class="delimiter">;</span>
<span class="lineno"> 5</span><span class="keyword">IMP</span> <span class="var">Sys</span><span class="delimiter">.</span><span class="var">Config</span><span class="delimiter">;</span>
<span class="lineno"> 6</span><span class="keyword">IMP</span> <span class="var">Sys</span><span class="delimiter">.</span><span class="var">Program</span> <span class="keyword">USE</span> <span class="var">Args</span><span class="delimiter">;</span>
<span class="lineno"> 7</span><span class="keyword">IMP</span> <span class="var">Sys</span><span class="delimiter">.</span><span class="var">Module</span><span class="delimiter">;</span>
<span class="lineno"> 8</span><span class="keyword">IMP</span> <span class="var">IO</span><span class="delimiter">.</span><span class="var">Terminal</span> <span class="keyword">USE</span> <span class="var">Out</span><span class="delimiter">;</span>
<span class="lineno"> 9</span><span class="keyword">IMP</span> <span class="var">IO</span><span class="delimiter">.</span><span class="var">File</span><span class="delimiter">;</span>
<span class="lineno"> 10</span><span class="keyword">IMP</span> <span class="var">IO</span><span class="delimiter">.</span><span class="var">Buffer</span><span class="delimiter">;</span>
<span class="lineno"> 11</span><span class="keyword">IMP</span> <span class="var">IO</span><span class="delimiter">.</span><span class="var">Stream</span><span class="delimiter">;</span>
<span class="lineno"> 12</span><span class="keyword">IMP</span> <span class="var">Wrapl</span><span class="delimiter">.</span><span class="var">Loader</span><span class="delimiter">;</span>
<span class="lineno"> 13</span><span class="keyword">IMP</span> <span class="var">Std</span><span class="delimiter">.</span><span class="var">Function</span><span class="delimiter">;</span>
<span class="lineno"> 14</span><span class="keyword">IMP</span> <span class="var">Std</span><span class="delimiter">.</span><span class="var">String</span><span class="delimiter">;</span>
<span class="lineno"> 15</span><span class="keyword">IMP</span> <span class="var">Std</span><span class="delimiter">.</span><span class="var">Integer</span><span class="delimiter">;</span>
<span class="lineno"> 16</span>
<span class="lineno"> 17</span><span class="keyword">DEF</span> <span class="var">Defines</span> <span class="delimiter"><-</span> <span class="delimiter">{};</span>
<span class="lineno"> 18</span><span class="keyword">DEF</span> <span class="var">Includes</span> <span class="delimiter"><-</span> <span class="delimiter">[</span><span class="literal">""</span><span class="delimiter">];</span>
<span class="lineno"> 19</span>
<span class="lineno"> 20</span><span class="keyword">DEF</span> <span class="var">SourceT</span> <span class="delimiter"><-</span> <span class="delimiter"><[</span><span class="var">Stream</span><span class="delimiter">.</span><span class="var">ReaderT</span><span class="delimiter">]>;</span>
<span class="lineno"> 21</span><span class="keyword">DEF</span> <span class="var">buffer</span> <span class="delimiter"><-</span> <span class="delimiter">[];</span>
<span class="lineno"> 22</span>
<span class="lineno"> 23</span><span class="keyword">VAR</span> <span class="var">in</span> <span class="delimiter"><-</span> <span class="var">Terminal</span><span class="delimiter">.</span><span class="var">In</span><span class="delimiter">,</span> <span class="var">out</span> <span class="delimiter"><-</span> <span class="var">Terminal</span><span class="delimiter">.</span><span class="var">Out</span><span class="delimiter">,</span> <span class="var">line</span><span class="delimiter">;</span>
<span class="lineno"> 24</span>
<span class="lineno"> 25</span><span class="keyword">TO</span> <span class="symbol">:readi</span><span class="delimiter">(</span><span class="var">src</span><span class="delimiter">@</span><span class="var">SourceT</span><span class="delimiter">,</span> <span class="var">n</span><span class="delimiter">@</span><span class="var">Integer</span><span class="delimiter">.</span><span class="var">SmallT</span><span class="delimiter">,</span> <span class="var">t</span><span class="delimiter">@</span><span class="var">String</span><span class="delimiter">.</span><span class="var">T</span><span class="delimiter">)</span> <span class="var">buffer</span><span class="symbol">:pop</span> <span class="delimiter">|</span> <span class="var">in</span><span class="symbol">:readi</span><span class="delimiter">(</span><span class="var">n</span><span class="delimiter">,</span> <span class="var">t</span><span class="delimiter">);</span>
<span class="lineno"> 26</span>
<span class="lineno"> 27</span><span class="keyword">VAR</span> <span class="var">source</span> <span class="delimiter"><-</span> <span class="var">SourceT</span><span class="delimiter">();</span>
<span class="lineno"> 28</span><span class="keyword">VAR</span> <span class="var">session</span> <span class="delimiter"><-</span> <span class="var">Loader</span><span class="delimiter">.</span><span class="var">SessionNew</span><span class="delimiter">(</span><span class="var">source</span><span class="delimiter">);</span>
<span class="lineno"> 29</span>
<span class="lineno"> 30</span><span class="var">session</span><span class="symbol">:var</span><span class="delimiter">(</span><span class="literal">"out"</span><span class="delimiter">,</span> <span class="var">out</span><span class="delimiter">);</span>
<span class="lineno"> 31</span>
<span class="lineno"> 32</span><span class="keyword">VAR</span> <span class="var">stack</span> <span class="delimiter"><-</span> <span class="delimiter">[];</span>
<span class="lineno"> 33</span><span class="var">session</span><span class="symbol">:def</span><span class="delimiter">(</span><span class="literal">"stack"</span><span class="delimiter">,</span> <span class="var">stack</span><span class="delimiter">);</span>
<span class="lineno"> 34</span><span class="var">session</span><span class="symbol">:def</span><span class="delimiter">(</span><span class="literal">"push"</span><span class="delimiter">,</span> <span class="delimiter"><</span><span class="var">b</span><span class="delimiter">></span> <span class="var">stack</span><span class="symbol">:push</span><span class="delimiter">(</span><span class="var">out</span> <span class="delimiter"><-</span> <span class="delimiter">(</span><span class="keyword">NIL</span> <span class="delimiter">~==</span> <span class="var">b</span><span class="delimiter">)</span> <span class="delimiter">|</span> <span class="var">Buffer</span><span class="delimiter">.</span><span class="var">New</span><span class="delimiter">()));</span>
<span class="lineno"> 35</span><span class="var">session</span><span class="symbol">:def</span><span class="delimiter">(</span><span class="literal">"pop"</span><span class="delimiter">,</span> <span class="delimiter"><></span> <span class="var">stack</span><span class="symbol">:pop</span> <span class="delimiter">\</span> <span class="delimiter">(</span><span class="var">out</span> <span class="delimiter"><-</span> <span class="var">stack</span><span class="delimiter">[</span>1<span class="delimiter">]));</span>
<span class="lineno"> 36</span><span class="var">session</span><span class="symbol">:def</span><span class="delimiter">(</span><span class="literal">"begin"</span><span class="delimiter">,</span> <span class="symbol">:</span><span class="delimiter">?);</span>
<span class="lineno"> 37</span><span class="var">session</span><span class="symbol">:def</span><span class="delimiter">(</span><span class="literal">"end"</span><span class="delimiter">,</span> <span class="symbol">:</span><span class="delimiter">?);</span>
<span class="lineno"> 38</span><span class="var">session</span><span class="symbol">:def</span><span class="delimiter">(</span><span class="literal">"buffer"</span><span class="delimiter">,</span> <span class="var">Buffer</span><span class="delimiter">.</span><span class="var">New</span><span class="delimiter">);</span>
<span class="lineno"> 39</span><span class="var">session</span><span class="symbol">:def</span><span class="delimiter">(</span><span class="literal">"include"</span><span class="delimiter">,</span> <span class="var">Include</span><span class="delimiter">);</span>
<span class="lineno"> 40</span><span class="var">session</span><span class="symbol">:def</span><span class="delimiter">(</span><span class="literal">"_include_"</span><span class="delimiter">,</span> <span class="delimiter"><</span><span class="var">filename</span><span class="delimiter">></span> <span class="var">Include</span><span class="delimiter">(</span><span class="var">filename</span><span class="delimiter">,</span> 1<span class="delimiter">));</span>
<span class="lineno"> 41</span><span class="var">session</span><span class="symbol">:def</span><span class="delimiter">(</span><span class="literal">"write"</span><span class="delimiter">,</span> <span class="delimiter"><</span><span class="var">text</span><span class="delimiter">></span> <span class="var">out</span><span class="symbol">:write</span><span class="delimiter">(</span><span class="var">text</span><span class="delimiter">));</span>
<span class="lineno"> 42</span><span class="var">session</span><span class="symbol">:def</span><span class="delimiter">(</span><span class="literal">"defines"</span><span class="delimiter">,</span> <span class="var">Defines</span><span class="delimiter">);</span>
<span class="lineno"> 43</span><span class="var">session</span><span class="symbol">:def</span><span class="delimiter">(</span><span class="literal">"includes"</span><span class="delimiter">,</span> <span class="var">Includes</span><span class="delimiter">);</span>
<span class="lineno"> 44</span><span class="var">session</span><span class="symbol">:def</span><span class="delimiter">(</span><span class="literal">"dbg"</span><span class="delimiter">,</span> <span class="var">Out</span><span class="delimiter">);</span>
<span class="lineno"> 45</span>
<span class="lineno"> 46</span><span class="keyword">VAR</span> <span class="var">escape</span> <span class="delimiter"><-</span> <span class="literal">"\\"</span><span class="delimiter">;</span>
<span class="lineno"> 47</span><span class="var">session</span><span class="symbol">:var</span><span class="delimiter">(</span><span class="literal">"escape"</span><span class="delimiter">,</span> <span class="var">escape</span><span class="delimiter">);</span>
<span class="lineno"> 48</span>
<span class="lineno"> 49</span><span class="keyword">DEF</span> <span class="var">Process</span><span class="delimiter">(</span><span class="var">strip</span><span class="delimiter">)</span> <span class="delimiter">(</span>
<span class="lineno"> 50</span> <span class="keyword">VAR</span> <span class="var">pos</span><span class="delimiter">;</span>
<span class="lineno"> 51</span> <span class="var">line</span> <span class="delimiter"><-</span> <span class="var">in</span><span class="symbol">:readi</span><span class="delimiter">(</span>0<span class="delimiter">,</span> <span class="literal">"\n"</span><span class="delimiter">);</span>
<span class="lineno"> 52</span> <span class="keyword">REP</span> <span class="delimiter">(</span>
<span class="lineno"> 53</span> <span class="var">pos</span> <span class="delimiter"><-</span> 1<span class="delimiter">;</span>
<span class="lineno"> 54</span> <span class="keyword">REP</span> <span class="delimiter">(</span><span class="keyword">WHILE</span> <span class="var">pos</span> <span class="delimiter"><-</span> <span class="var">line</span><span class="symbol">:find</span><span class="delimiter">(</span><span class="var">escape</span><span class="delimiter">,</span> <span class="var">pos</span><span class="delimiter">);</span>
<span class="lineno"> 55</span> <span class="var">line</span><span class="delimiter">[</span><span class="var">pos</span> <span class="delimiter">+</span> 1<span class="delimiter">]</span> <span class="delimiter">=</span> <span class="literal">";"</span> <span class="delimiter">=></span> <span class="delimiter">(</span>
<span class="lineno"> 56</span> <span class="var">line</span> <span class="delimiter"><-</span> <span class="var">line</span><span class="delimiter">[</span>1<span class="delimiter">,</span> <span class="var">pos</span> <span class="delimiter">+</span> 1<span class="delimiter">]</span> <span class="delimiter">+</span> <span class="delimiter">(</span><span class="var">line</span><span class="delimiter">[</span><span class="var">pos</span> <span class="delimiter">+</span> 2<span class="delimiter">,</span> 0<span class="delimiter">]</span> <span class="delimiter">|</span> <span class="literal">""</span><span class="delimiter">);</span>
<span class="lineno"> 57</span> <span class="var">pos</span> <span class="delimiter"><-</span> <span class="var">pos</span> <span class="delimiter">+</span> 1<span class="delimiter">;</span>
<span class="lineno"> 58</span> <span class="delimiter">)</span> <span class="delimiter">//</span> <span class="delimiter">(</span>
<span class="lineno"> 59</span> <span class="var">out</span><span class="symbol">:write</span><span class="delimiter">(</span><span class="var">line</span><span class="delimiter">[</span>1<span class="delimiter">,</span> <span class="var">pos</span><span class="delimiter">]);</span>
<span class="lineno"> 60</span> <span class="var">buffer</span><span class="symbol">:put</span><span class="delimiter">(</span><span class="var">line</span><span class="delimiter">[</span><span class="var">pos</span> <span class="delimiter">+</span> 1<span class="delimiter">,</span> 0<span class="delimiter">]);</span>
<span class="lineno"> 61</span> <span class="var">line</span> <span class="delimiter"><-</span> <span class="keyword">NIL</span><span class="delimiter">;</span>
<span class="lineno"> 62</span> <span class="var">pos</span> <span class="delimiter"><-</span> 1<span class="delimiter">;</span>
<span class="lineno"> 63</span> <span class="var">session</span><span class="symbol">:eval</span><span class="delimiter">;</span>
<span class="lineno"> 64</span> <span class="delimiter">(</span><span class="keyword">NIL</span> <span class="delimiter">==</span> <span class="var">line</span><span class="delimiter">)</span> <span class="delimiter"><-</span> <span class="var">session</span><span class="symbol">:line</span><span class="delimiter">;</span>
<span class="lineno"> 65</span> <span class="delimiter">);</span>
<span class="lineno"> 66</span> <span class="delimiter">);</span>
<span class="lineno"> 67</span> <span class="delimiter">(</span><span class="keyword">NIL</span> <span class="delimiter">~==</span> <span class="var">strip</span><span class="delimiter">)</span> <span class="delimiter">&</span> <span class="delimiter">(</span><span class="var">line</span> <span class="delimiter">=</span> <span class="literal">"\n"</span><span class="delimiter">)</span> <span class="delimiter">=></span> <span class="var">line</span> <span class="delimiter"><-</span> <span class="literal">""</span><span class="delimiter">;</span>
<span class="lineno"> 68</span> <span class="var">out</span><span class="symbol">:write</span><span class="delimiter">(</span><span class="var">line</span><span class="delimiter">);</span>
<span class="lineno"> 69</span> <span class="keyword">WHILE</span> <span class="var">line</span> <span class="delimiter"><-</span> <span class="var">in</span><span class="symbol">:readi</span><span class="delimiter">(</span>0<span class="delimiter">,</span> <span class="literal">"\n"</span><span class="delimiter">);</span>
<span class="lineno"> 70</span> <span class="delimiter">);</span>
<span class="lineno"> 71</span><span class="delimiter">);</span>
<span class="lineno"> 72</span>
<span class="lineno"> 73</span><span class="keyword">DEF</span> <span class="var">Include</span><span class="delimiter">(</span><span class="var">filename</span><span class="delimiter">,</span> <span class="var">strip</span><span class="delimiter">)</span> <span class="delimiter">(</span>
<span class="lineno"> 74</span> <span class="keyword">VAR</span> <span class="var">oldline</span> <span class="delimiter"><-</span> <span class="var">session</span><span class="symbol">:line</span><span class="delimiter">;</span>
<span class="lineno"> 75</span> <span class="keyword">VAR</span> <span class="var">oldin</span> <span class="delimiter"><-</span> <span class="var">in</span><span class="delimiter">;</span>
<span class="lineno"> 76</span> <span class="keyword">VAR</span> <span class="var">path</span><span class="delimiter">;</span>
<span class="lineno"> 77</span> <span class="var">FileSys</span><span class="delimiter">.</span><span class="var">Exists</span><span class="delimiter">(</span><span class="var">path</span> <span class="delimiter"><-</span> <span class="var">Includes</span><span class="symbol">:values</span> <span class="delimiter">+</span> <span class="var">filename</span><span class="delimiter">)</span> <span class="delimiter">//</span> <span class="delimiter">(</span>
<span class="lineno"> 78</span> <span class="var">Out</span><span class="symbol">:write</span><span class="delimiter">(</span><span class="literal">'Error: file "</span><span class="nested"><span class="delimiter">{</span><span class="var">filename</span><span class="delimiter">}</span></span><span class="literal">" not found.\n'</span><span class="delimiter">);</span>
<span class="lineno"> 79</span> <span class="keyword">FAIL</span><span class="delimiter">;</span>
<span class="lineno"> 80</span> <span class="delimiter">);</span>
<span class="lineno"> 81</span> <span class="var">in</span> <span class="delimiter"><-</span> <span class="var">File</span><span class="delimiter">.</span><span class="var">Open</span><span class="delimiter">(</span><span class="var">path</span><span class="delimiter">,</span> <span class="var">File</span><span class="delimiter">.</span><span class="var">Flag</span><span class="delimiter">.</span><span class="var">Read</span> <span class="delimiter">+</span> <span class="var">File</span><span class="delimiter">.</span><span class="var">Flag</span><span class="delimiter">.</span><span class="var">Text</span><span class="delimiter">);</span>
<span class="lineno"> 82</span> <span class="var">Process</span><span class="delimiter">(</span><span class="var">strip</span><span class="delimiter">);</span>
<span class="lineno"> 83</span> <span class="var">in</span><span class="symbol">:close</span><span class="delimiter">;</span>
<span class="lineno"> 84</span> <span class="var">in</span> <span class="delimiter"><-</span> <span class="var">oldin</span><span class="delimiter">;</span>
<span class="lineno"> 85</span> <span class="var">line</span> <span class="delimiter"><-</span> <span class="var">oldline</span><span class="delimiter">;</span>
<span class="lineno"> 86</span><span class="delimiter">);</span>
<span class="lineno"> 87</span>
<span class="lineno"> 88</span><span class="keyword">DEF</span> <span class="var">ParseArgs</span><span class="delimiter">()</span> <span class="delimiter">(</span>
<span class="lineno"> 89</span> <span class="keyword">VAR</span> <span class="var">i</span> <span class="delimiter"><-</span> 1<span class="delimiter">,</span> <span class="var">arg</span><span class="delimiter">;</span>
<span class="lineno"> 90</span> <span class="keyword">REP</span> <span class="delimiter">(</span><span class="keyword">WHILE</span> <span class="var">i</span> <span class="delimiter"><=</span> <span class="var">Args</span><span class="symbol">:length</span><span class="delimiter">;</span>
<span class="lineno"> 91</span> <span class="var">arg</span> <span class="delimiter"><-</span> <span class="var">Args</span><span class="delimiter">[</span><span class="var">i</span><span class="delimiter">];</span>
<span class="lineno"> 92</span> <span class="var">arg</span><span class="delimiter">[</span>1<span class="delimiter">]</span> <span class="delimiter">=</span> <span class="literal">'-'</span> <span class="delimiter">=></span> <span class="delimiter">(</span>
<span class="lineno"> 93</span> <span class="keyword">WHEN</span> <span class="var">arg</span><span class="delimiter">[</span>2<span class="delimiter">]</span> <span class="keyword">IS</span> <span class="literal">"u"</span> <span class="keyword">DO</span> <span class="delimiter">(</span>
<span class="lineno"> 94</span> <span class="var">Config</span><span class="delimiter">.</span><span class="var">Set</span><span class="delimiter">(</span><span class="literal">"Wrapl.AllowUndeclared"</span><span class="delimiter">);</span>
<span class="lineno"> 95</span> <span class="delimiter">)</span> <span class="keyword">IS</span> <span class="literal">"D"</span> <span class="keyword">DO</span> <span class="delimiter">(</span>
<span class="lineno"> 96</span> <span class="var">arg</span> <span class="delimiter"><-</span> <span class="var">arg</span><span class="delimiter">[</span>3<span class="delimiter">,</span> 0<span class="delimiter">]</span> <span class="delimiter">|</span> <span class="var">Args</span><span class="delimiter">[</span><span class="var">i</span> <span class="delimiter"><-</span> <span class="var">i</span> <span class="delimiter">+</span> 1<span class="delimiter">]</span> <span class="delimiter">|</span> <span class="keyword">SEND</span> <span class="literal">"Missing argument"</span><span class="delimiter">;</span>
<span class="lineno"> 97</span> <span class="var">Defines</span><span class="symbol">:insert</span><span class="delimiter">(</span><span class="var">arg</span><span class="symbol">:before</span><span class="delimiter">(</span><span class="literal">"="</span><span class="delimiter">),</span> <span class="var">arg</span><span class="symbol">:after</span><span class="delimiter">(</span><span class="literal">"="</span><span class="delimiter">));</span>
<span class="lineno"> 98</span> <span class="delimiter">)</span> <span class="keyword">IS</span> <span class="literal">"o"</span> <span class="keyword">DO</span> <span class="delimiter">(</span>
<span class="lineno"> 99</span> <span class="var">arg</span> <span class="delimiter"><-</span> <span class="var">arg</span><span class="delimiter">[</span>3<span class="delimiter">,</span> 0<span class="delimiter">]</span> <span class="delimiter">|</span> <span class="var">Args</span><span class="delimiter">[</span><span class="var">i</span> <span class="delimiter"><-</span> <span class="var">i</span> <span class="delimiter">+</span> 1<span class="delimiter">]</span> <span class="delimiter">|</span> <span class="keyword">SEND</span> <span class="literal">"Missing argument"</span><span class="delimiter">;</span>
<span class="lineno"> 100</span> <span class="var">out</span> <span class="delimiter"><-</span> <span class="var">File</span><span class="delimiter">.</span><span class="var">Open</span><span class="delimiter">(</span><span class="var">arg</span><span class="delimiter">,</span> <span class="var">File</span><span class="delimiter">.</span><span class="var">Flag</span><span class="delimiter">.</span><span class="var">Write</span> <span class="delimiter">+</span> <span class="var">File</span><span class="delimiter">.</span><span class="var">Flag</span><span class="delimiter">.</span><span class="var">Text</span><span class="delimiter">);</span>
<span class="lineno"> 101</span> <span class="delimiter">)</span> <span class="keyword">IS</span> <span class="literal">"I"</span> <span class="keyword">DO</span> <span class="delimiter">(</span>
<span class="lineno"> 102</span> <span class="var">arg</span> <span class="delimiter"><-</span> <span class="var">arg</span><span class="delimiter">[</span>3<span class="delimiter">,</span> 0<span class="delimiter">]</span> <span class="delimiter">|</span> <span class="var">Args</span><span class="delimiter">[</span><span class="var">i</span> <span class="delimiter"><-</span> <span class="var">i</span> <span class="delimiter">+</span> 1<span class="delimiter">]</span> <span class="delimiter">|</span> <span class="keyword">SEND</span> <span class="literal">"Missing argument"</span><span class="delimiter">;</span>
<span class="lineno"> 103</span> <span class="var">arg</span> <span class="delimiter"><-</span> <span class="var">arg</span> <span class="delimiter">+</span> <span class="delimiter">(</span><span class="var">arg</span><span class="delimiter">[-</span>1<span class="delimiter">]</span> <span class="delimiter">~=</span> <span class="literal">"/"</span><span class="delimiter">);</span>
<span class="lineno"> 104</span> <span class="var">Includes</span><span class="symbol">:put</span><span class="delimiter">(</span><span class="var">arg</span><span class="delimiter">);</span>
<span class="lineno"> 105</span> <span class="delimiter">)</span> <span class="keyword">IS</span> <span class="literal">"L"</span> <span class="keyword">DO</span> <span class="delimiter">(</span>
<span class="lineno"> 106</span> <span class="var">arg</span> <span class="delimiter"><-</span> <span class="var">arg</span><span class="delimiter">[</span>3<span class="delimiter">,</span> 0<span class="delimiter">]</span> <span class="delimiter">|</span> <span class="var">Args</span><span class="delimiter">[</span><span class="var">i</span> <span class="delimiter"><-</span> <span class="var">i</span> <span class="delimiter">+</span> 1<span class="delimiter">]</span> <span class="delimiter">|</span> <span class="keyword">SEND</span> <span class="literal">"Missing argument"</span><span class="delimiter">;</span>
<span class="lineno"> 107</span> <span class="var">Module</span><span class="delimiter">.</span><span class="var">AddDirectory</span><span class="delimiter">(</span><span class="var">arg</span><span class="delimiter">);</span>
<span class="lineno"> 108</span> <span class="delimiter">)</span> <span class="keyword">IS</span> <span class="literal">"p"</span> <span class="keyword">DO</span> <span class="delimiter">(</span>
<span class="lineno"> 109</span> <span class="var">arg</span> <span class="delimiter"><-</span> <span class="var">arg</span><span class="delimiter">[</span>3<span class="delimiter">,</span> 0<span class="delimiter">]</span> <span class="delimiter">|</span> <span class="var">Args</span><span class="delimiter">[</span><span class="var">i</span> <span class="delimiter"><-</span> <span class="var">i</span> <span class="delimiter">+</span> 1<span class="delimiter">]</span> <span class="delimiter">|</span> <span class="keyword">SEND</span> <span class="literal">"Missing argument"</span><span class="delimiter">;</span>
<span class="lineno"> 110</span> <span class="var">Include</span><span class="delimiter">(</span><span class="var">arg</span><span class="delimiter">);</span>
<span class="lineno"> 111</span> <span class="delimiter">)</span> <span class="keyword">IS</span> <span class="literal">"P"</span> <span class="keyword">DO</span> <span class="delimiter">(</span>
<span class="lineno"> 112</span> <span class="var">arg</span> <span class="delimiter"><-</span> <span class="var">arg</span><span class="delimiter">[</span>3<span class="delimiter">,</span> 0<span class="delimiter">]</span> <span class="delimiter">|</span> <span class="var">Args</span><span class="delimiter">[</span><span class="var">i</span> <span class="delimiter"><-</span> <span class="var">i</span> <span class="delimiter">+</span> 1<span class="delimiter">]</span> <span class="delimiter">|</span> <span class="keyword">SEND</span> <span class="literal">"Missing argument"</span><span class="delimiter">;</span>
<span class="lineno"> 113</span> <span class="var">Include</span><span class="delimiter">(</span><span class="var">arg</span><span class="delimiter">,</span> 1<span class="delimiter">);</span>
<span class="lineno"> 114</span> <span class="delimiter">)</span> <span class="keyword">DO</span> <span class="delimiter">(</span>
<span class="lineno"> 115</span> <span class="keyword">SEND</span> <span class="literal">'Unknown argument: </span><span class="nested"><span class="delimiter">{</span><span class="var">arg</span><span class="delimiter">}</span></span><span class="literal">'</span><span class="delimiter">;</span>
<span class="lineno"> 116</span> <span class="delimiter">);</span>
<span class="lineno"> 117</span> <span class="delimiter">)</span> <span class="delimiter">//</span> <span class="delimiter">(</span>
<span class="lineno"> 118</span> <span class="var">in</span> <span class="delimiter"><-</span> <span class="var">File</span><span class="delimiter">.</span><span class="var">Open</span><span class="delimiter">(</span><span class="var">arg</span><span class="delimiter">,</span> <span class="var">File</span><span class="delimiter">.</span><span class="var">Flag</span><span class="delimiter">.</span><span class="var">Read</span> <span class="delimiter">+</span> <span class="var">File</span><span class="delimiter">.</span><span class="var">Flag</span><span class="delimiter">.</span><span class="var">Text</span><span class="delimiter">);</span>
<span class="lineno"> 119</span> <span class="delimiter">);</span>
<span class="lineno"> 120</span> <span class="var">i</span> <span class="delimiter"><-</span> <span class="var">i</span> <span class="delimiter">+</span> 1<span class="delimiter">;</span>
<span class="lineno"> 121</span> <span class="delimiter">);</span>
<span class="lineno"> 122</span> <span class="comment">--(in == NIL) => in <- Terminal.In;</span>
<span class="lineno"> 123</span> <span class="comment">--(out == NIL) => out <- Terminal.Out;</span>
<span class="lineno"> 124</span> <span class="var">stack</span><span class="symbol">:put</span><span class="delimiter">(</span><span class="var">out</span><span class="delimiter">);</span>
<span class="lineno"> 125</span> <span class="keyword">RECV</span> <span class="var">msg</span> <span class="keyword">DO</span> <span class="delimiter">(</span>
<span class="lineno"> 126</span> <span class="var">Out</span><span class="symbol">:write</span><span class="delimiter">(</span><span class="literal">'Error[125]: </span><span class="nested"><span class="delimiter">{</span><span class="var">msg</span><span class="delimiter">}</span></span><span class="literal">\n'</span><span class="delimiter">);</span>
<span class="lineno"> 127</span> <span class="var">Program</span><span class="delimiter">.</span><span class="var">Exit</span><span class="delimiter">(</span>1<span class="delimiter">);</span>
<span class="lineno"> 128</span> <span class="delimiter">);</span>
<span class="lineno"> 129</span><span class="delimiter">);</span>
<span class="lineno"> 130</span>
<span class="lineno"> 131</span><span class="var">ParseArgs</span><span class="delimiter">();</span>
<span class="lineno"> 132</span><span class="var">Process</span><span class="delimiter">();</span>
<span class="lineno"> 133</span><span class="var">Program</span><span class="delimiter">.</span><span class="var">Exit</span><span class="delimiter">(</span>0<span class="delimiter">);</span>
<span class="lineno"> 134</span>
<span class="lineno"> 135</span><span class="keyword">END</span> <span class="var">Mark</span><span class="delimiter">.</span></div>
</section>
</section>
<section id="Other_Examples" class="section"><h2>Other Examples</h2>
<p>To see some more complex sample code using several of the included libraries, check the following:</p>
<section id="GTK+" data-spy="true" data-target="#side-menu"><h3>GTK+</h3>
<p>For an example on using the GTK+ binding, see <a href="/samples/gtk.xhtml">here</a>.</p>
</section>
</section>
<footer>
<div class="text-center">
<span>Copyright: © 2008-2018 Raja Mukherji</span>
</div>
</footer>
</div>
</div>
</body>
</html>