-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand-reference.html
More file actions
484 lines (412 loc) · 14.6 KB
/
command-reference.html
File metadata and controls
484 lines (412 loc) · 14.6 KB
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The disc Programming Language -- The Command Reference</title>
<link rel="stylesheet" href="./styles/bootstrap.min.css">
<link rel="stylesheet" href="./styles/styles.css">
</head>
<body id="command-reference">
<header class="container">
<h1>The <em>disc</em> Language : Language Reference</h1>
<nav class="nav navbar">
<ul class="nav-list text-center">
<li><a href="./" id="home-link">home</a></li>
<li><a href="./getting-started/" id="getting-started-link">getting started</a></li>
<li><a href="./build.html" id="build-link">create something</a></li>
<li><a href="./command-reference.html" id="command-reference-link">language reference</a></li>
<li><a href="./about.html" id="about-link">about <em>disc</em> lang design</a></li>
</ul>
</nav>
</header>
<div class="container">
<p>
<strong>WARNING: This document will not teach you to program.</strong>
</p>
<p>
This document collects the basic commands, operators, and other good stuff the disc language has to offer in
a no-nonsense listing. This will not teach you how to program, how to be a better programmer, or how to
program differently. It's just a list of things and what they do. Thanks for your attention.
</p>
<h2>Commands</h2>
<h4>Variables</h4>
<dl>
<dt>define ... as ...</dt>
<dd>
<ul>
<li>Defines a new block-level constant. Constants cannot be updated.</li>
<li>Example: <code><strong>define</strong> PI <strong>as</strong> 3.14159</code></li>
</ul>
</dd>
<dt>let ... be ...</dt>
<dd>
<ul>
<li>Defines a new block-level variable. These variables can be updated.</li>
<li>Example: <code><strong>let</strong> clifford <strong>be</strong> "Big red dog"</code></li>
</ul>
</dd>
<dt>update ... to ...</dt>
<dd>
<ul>
<li>Updates variable with a new value. Update cannot change the value of defined constants.</li>
<li>Example: <code><strong>update</strong> count <strong>to</strong> count + 1</code></li>
</ul>
</dd>
</dl>
<h4>Flow Control (conditions and loops)</h4>
<dl>
<dt>if ...</dt>
<dd>
<ul>
<li>Runs containing code only if the condition is met.</li>
<li>Runs all code contained before "end"</li>
<li>Example:
<code>
<pre>
<strong>if</strong> count isEqualTo 3
print: "Count is three"
<strong>end</strong>
</pre>
</code>
</li>
</ul>
</dd>
<dt>else if ...</dt>
<dd>
<ul>
<li>Runs containing code only if the previous condition is NOT met, and this condition is.</li>
<li>Runs all code contained before "end"</li>
<li>Example:
<code>
<pre>
if count isEqualTo 3
print: "Count is three"
<strong>else if</strong> count isGreaterThan 5
print: "No, no, MUCH bigger than 3"
<strong>end</strong>
</pre>
</code>
</li>
</ul>
</dd>
<dt>else</dt>
<dd>
<ul>
<li>Runs containing code only if all previous conditions are NOT met.</li>
<li>Runs all code contained before "end"</li>
<li>Example:
<code>
<pre>
if count isEqualTo 3
print: "Count is three"
else if count isGreaterThan 5
print: "No, no, MUCH bigger than 3"
<strong>else</strong>
print: "No, it's far smaller than 3"
<strong>end</strong>
</pre>
</code>
</li>
</ul>
</dd>
<dt>loop while ...</dt>
<dd>
<ul>
<li>Loops while the given condition is true.</li>
<li>Repeats the lines between "loop while" and "end"</li>
<li>Example: <code>
<pre>
<strong>loop while</strong> count isLessThan 5
print: join: "Looping to five. Current count: " count
<strong>end</strong>
</pre>
</code></li>
</ul>
</dd>
</dl>
<dl>
<dt>repeat while ...</dt>
<dd>
<ul>
<li>Alias of "loop while"</li>
<li>Example: <code>
<pre>
<strong>repeat while</strong> count isLessThan 5
print: join: "Looping to five. Current count: " count
<strong>end</strong>
</pre>
</code></li>
</ul>
</dd>
</dl>
<h2>Operators</h2>
<h4>Arithmetic</h4>
<dl>
<dt><code>+, -, *, /</code></dt>
<dd>
<ul>
<li>Addition, subtraction, multiplication, and division, respectively</li>
<li>Order of operations are as follows:
<ol>
<li>Parenthetical grouping (parentheses)</li>
<li>Multiplication and division (left to right priority)</li>
<li>Addition and subtractions (left to right priority)</li>
</ol>
</li>
</ul>
</dd>
</dl>
<h4>Comparison</h4>
<dl>
<dt>... isLessThan ...</dt>
<dd>
<ul>
<li>Produces <code>true</code> when the value on the left is less than the one on the right,
otherwise <code>false</code>.</li>
<li>Compares number values only</li>
<li>Examples: <code>
<pre>
5 <strong>isLessThan</strong> 12 # produces true
7 <strong>isLessThan</strong> -3 # produces false
</pre>
</code></li>
</ul>
</dd>
<dt>... isLessOrEqualTo ...</dt>
<dd>
<ul>
<li>Produces <code>true</code> when the value on the left is either less, or equal to than the one
on the right, otherwise <code>false</code>.</li>
<li>Compares number values only</li>
<li>Examples: <code>
<pre>
5 <strong>isLessOrEqualTo</strong> 12 # produces true
7 <strong>isLessOrEqualTo</strong> 7 # produces true
7 <strong>isLessOrEqualTo</strong> -2 # produces false
</pre>
</code></li>
</ul>
</dd>
<dt>... isGreaterThan ...</dt>
<dd>
<ul>
<li>Produces <code>true</code> when the value on the left is less than the one on the right,
otherwise <code>false</code>.</li>
<li>Compares number values only</li>
<li>Examples: <code>
<pre>
5 <strong>isGreaterThan</strong> 12 # produces false
7 <strong>isGreaterThan</strong> -3 # produces true
</pre>
</code></li>
</ul>
</dd>
<dt>... isGreaterOrEqualTo ...</dt>
<dd>
<ul>
<li>Produces <code>true</code> when the value on the left is either less, or equal to than the one
on the right, otherwise <code>false</code>.</li>
<li>Compares number values only</li>
<li>Examples: <code>
<pre>
5 <strong>isGreaterOrEqualTo</strong> 12 # produces false
7 <strong>isGreaterOrEqualTo</strong> 7 # produces true
7 <strong>isGreaterOrEqualTo</strong> -2 # produces true
</pre>
</code></li>
</ul>
</dd>
<dt>... isEqualTo ...</dt>
<dd>
<ul>
<li>Produces <code>true</code> when values are equal, otherwise <code>false</code>.</li>
<li>Compares number, and string values only</li>
<li>Examples: <code>
<pre>
7 <strong>isEqualTo</strong> 7 # produces true
"this is fine" <strong>isEqualTo</strong> "this is fine" # produces true
7 <strong>isEqualTo</strong> -2 # produces false
"this is fine" <strong>isEqualTo</strong> "this is not fine" # produces false
</pre>
</code></li>
</ul>
</dd>
</dl>
<h4>Logical</h4>
<dl>
<dt><code>... and ..., ... or ...</code></dt>
<dd>
<ul>
<li>Evaluates truthiness of a boolean expression</li>
<li>Only works with boolean values</li>
<li>Examples: <code>
<pre>
(count isLessThan 3) <strong>and</strong> (count isGreaterThan 0)
(count isLessThan 3) <strong>or</strong> (count isGreaterThan 0)
</pre>
</code></li>
</ul>
</dd>
</dl>
<h4>Other</h4>
<dl>
<dt><code>...</code></dt>
<dd>
<ul>
<li>Line continuation operator, yes it's '...'</li>
<li>Example:
<code>
<pre>
let numberIsInRange be ...
number isLessThan 5 ...
and number isGreaterThan -5
</pre>
</code>
</li>
</ul>
</dd>
<dt>declare function ... (withParameters ...)</dt>
<dd>
<ul>
<li>Declares a new function, optionally with parameters</li>
<li>Example:
<code>
<pre>
declare function displayScore withParameters wins losses ties
call clear
print: join: "wins: " wins " losses: " losses " ties: " ties
end
declare function displayRandomNumber
print: random: 0 100
end
</pre>
</code>
</li>
</ul>
</dd>
<dt>call ... (with ...)</dt>
<dd>
<ul>
<li>Calls a function, optionally with arguments</li>
<li>Examples:
<code>
<pre>
let myArray be (call newArray)
let myArray be (call newArray with 1 2 3 4)
</pre>
</code>
</li>
</ul>
</dd>
<dt><code>...: ...</code></dt>
<dd>
<ul>
<li>Shorthand for call</li>
<li>Examples:
<code>
<pre>
let myArray be (newArray:)
let myArray be (newArray: 1 2 3 4)
</pre>
</code>
</li>
</ul>
</dd>
<dt>toInfix ...</dt>
<dd>
<ul>
<li>Turns a function into an infix operator</li>
<li>Example:
<code>
<pre>
# without toInfix
join: "a left-handed string" "a right-handed string"
# with toInfix
toInfix "a left-handed string" join "a right-handed string"
</pre>
</code>
</li>
</ul>
</dd>
<dt><code>:: ...</code></dt>
<dd>
<ul>
<li>Shorthand for <code>toInfix</code></li>
<li>Example:
<code>
<pre>
# without :: (toInfix)
join: "a left-handed string" "a right-handed string"
# with :: (toInfix)
:: "a left-handed string" join "a right-handed string"
</pre>
</code>
</li>
</ul>
</dd>
</dl>
<h2>Functions</h2>
<h4>Array</h4>
<dl>
<dt>newArray (...)</dt>
<dt>appendTo ...</dt>
<dt>readFrom ...</dt>
<dt>removeFrom ...</dt>
<dt>setOn ...</dt>
<dt>lengthOf ...</dt>
</dl>
<h4>Dictionary</h4>
<dl>
<dt>newDictionary</dt>
<dt>hasKey ...</dt>
<dt>getKeysFrom ...</dt>
<dt>readFrom ...</dt>
<dt>removeFrom ...</dt>
<dt>setOn ...</dt>
</dl>
<h4>Logic</h4>
<dl>
<dt>not ...</dt>
</dl>
<h4>Mathematical</h4>
<dl>
<dt>numberToString ...</dt>
<dt>random (...)</dt>
<dt>absoluteValue ...</dt>
<dt>floor ...</dt>
<dt>ceiling ...</dt>
<dt>squareRoot ...</dt>
<dt>power ...</dt>
<dt>maximum ...</dt>
<dt>minimum ...</dt>
<dt>remainder ...</dt>
<dt>round ...</dt>
<dt>log ...</dt>
</dl>
<h4>Nil</h4>
<dl>
<dt>newNil</dt>
<dt>isNil ...</dt>
</dl>
<h4>String</h4>
<dl>
<dt>join ...</dt>
<dt>toLowerCase ...</dt>
<dt>toUpperCase ...</dt>
<dt>toArray ...</dt>
<dt>stringToNumber ...</dt>
<dt>getCharacterAtIndex ...</dt>
<dt>lengthOf ...</dt>
</dl>
<h4>User Input/Output</h4>
<dl>
<dt>print ...</dt>
<dt>clear</dt>
<dt>prompt ...</dt>
<dt>wait ...</dt>
<dt>readKey</dt>
</dl>
</div>
</body>
</html>