dyon 0.40.0

A rusty dynamically typed scripting language
Documentation
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
/// Returns an array of derived information for the truth value of `var`.
/// This can be used with the value of `∃`/`any` and `∀`/`all` loops.
fn why(var: sec[bool]) -> [any] { ... }

/// Returns an array of derived information for the value of `var`.
/// This can be used with the value of `min` and `max` loops.
fn where(var: sec[f64]) -> [any] { ... }

/// Adds message to derived information for the truth value of `var`.
/// This can be used with the value of `∃`/`any` and `∀`/`all` loops.
fn explain_why(var: bool, msg: any) -> sec[bool] { ... }

/// Adds message to derived information for the value of `var`.
/// This can be used with the value of `min` and `max` loops.
fn explain_where(var: f64, msg: any) -> sec[f64] { ... }

/// Prints out variable to standard output, adding newline character.
fn println(var: any) { ... }

/// Prints out variable to standard output.
fn print(var: any) { ... }

/// Clones the variable and all references it contains.
fn clone(var: any) -> any { ... }

/// Prints out the state of stack and local stack.
fn debug() { ... }

/// Prints out call stack.
fn backtrace() { ... }

/// Returns `true` if link is empty.
fn is_empty(l: link) -> bool { ... }

/// Returns the first item in a link.
fn head(l: link) -> opt[any] { ... }

/// Returns the whole link except first item.
fn tail(l: link) -> link { ... }

/// Returns the last item in a link.
fn tip(l: link) -> opt[any] { ... }

/// Returns the whole link except last item.
fn neck(l: link) -> link { ... }

/// Sleeps for a given amount of seconds.
fn sleep(seconds: f64) { ... }

/// Returns a random number between 0 and 1.
fn random() -> f64 { ... }

/// Reads a number from standard input with a message to the user.
/// If the input is in invalid format, it reports the error to the user,
/// and then asks again.
fn read_number(message: str) -> f64 { ... }

/// Parses number from string.
fn parse_number(text: str) -> opt[f64] { ... }

/// Reads a line from standard input.
fn read_line() -> str { ... }

/// Returns the length of array.
fn len(array: [any]) -> f64 { ... }

/// Appends an item at end of array.
fn push_ref(mut array: [any], item: 'array any) { ... }

/// Appends a deep clone of an item at end of array.
fn push(mut array: [any], item: any) { ... }

/// Inserts item at index in array.
fn insert_ref(mut array: [any], index: f64, item: 'array any) { ... }

/// Inserts a deep clone of an item at index in array.
fn insert(mut array: [any], index: f64, item: 'array any) { ... }

/// Removes last item from array.
fn pop(mut array: 'return [any]) -> any { ... }

/// Removes item from array at index.
fn remove(mut array: 'return [any], index: f64) -> any { ... }

/// Reverses the items in array.
fn reverse(mut array: [any]) { ... }

/// Removes all items from array.
fn clear(mut array: [any]) { ... }

/// Swaps two items in array.
fn swap(mut array: [any], i: f64, j: f64) { ... }

/// Returns a string with removed whitespace on both sides.
fn trim(text: str) -> str { ... }

/// Returns a string with removed whitespace at left side.
fn trim_left(text: str) -> str { ... }

/// Returns a string with removed whitespace at right side.
fn trim_right(text: str) -> str { ... }

/// Returns a string representation of variable.
fn str(var: any) -> str { ... }

/// Creates a JSON string of text.
fn json_string(text: str) -> str { ... }

/// Returns a HTML hex color string.
/// The vector is clamped in range `(0, 0, 0, 0)` to `(1, 1, 1, 1).
fn str__color(color: vec4) -> str { ... }

/// Converts from sRGB color space to linear color space.
/// This is used before mathematical operations on colors.
fn srgb_to_linear__color(color: vec4) -> vec4 { ... }

/// Converts from linear color space to sRGB.
/// This is used after mathematical operations on colors.
fn linear_to_srgb__color(color: vec4) -> vec4 { ... }

/// Returns simple description of variable type.
fn typeof(var: any) -> str { ... }

/// Rounds number, e.g. `round(0.5) == 1.0`.
fn round(v: f64) -> f64 { ... }

/// Returns absolute value, e.g. `abs(-3) == 3`.
fn abs(v: f64) -> f64 { ... }

/// Returns the highest smaller integer, e.g. `floor(3.2) == 3.0`.
fn floor(v: f64) -> f64 { ... }

/// Returns the smallest higher integer, e.g. `ceil(3.2) == 4.0`.
fn ceil(v: f64) -> f64 { ... }

/// Returns the square root of number.
fn sqrt(v: f64) -> f64 { ... }

/// Returns the sinus of number.
fn sin(v: f64) -> f64 { ... }

/// Returns the inverse sinus of number.
fn asin(v: f64) -> f64 { ... }

/// Returns the cosinus of number.
fn cos(v: f64) -> f64 { ... }

/// Returns the inverse cosinus of number.
fn acos(v: f64) -> f64 { ... }

/// Returns the tangent of number in radians.
fn tan(v: f64) -> f64 { ... }

/// Returns the inverse tangent of number in radians.
fn atan(v: f64) -> f64 { ... }

/// Returns the inverse tangent in radians.
fn atan2(y: f64, x: f64) -> f64 { ... }

/// Returns the natural exponential of number.
/// In mathematics this is often written as `e^x`.
fn exp(v: f64) -> f64 { ... }

/// Returns the natural logarithm of number.
fn ln(v: f64) -> f64 { ... }

/// Returns the logarithm of number with base 2.
fn log2(v: f64) -> f64 { ... }

/// Returns the logarithm of number with base 10.
fn log10(v: f64) -> f64 { ... }

/// Loads module from source.
/// Returns `ok(module)` if the loading succeeds.
fn load(source: str) -> res[any] { ... }

/// Loads module from source, using imports as dependencies.
/// Returns `ok(module)` if the loading succeeds.
fn load__source_imports(source: str, imports: [any]) -> res[any] { ... }

/// Creates module from string.
/// Returns `ok(module)` if it succeeds.
fn module__in_string_imports(name: str, code: str, imports: [any]) -> res[any] { ... }

/// Calls function in module with arguments.
fn call(module: any, function: str, arguments: [any]) { ... }

/// Calls function in module with arguments and returns the result.
fn call_ret(module: any, function: str, arguments: [any]) -> any { ... }

/// Returns list of available functions, sorted by name.
fn functions() -> any { ... }

/// Returns list of available functions from within module, sorted by name.
fn functions__module(module: any) -> any { ... }

/// Creates `none()` variant of option values.
fn none() -> opt[any] { ... }

/// Creates `some(var)` variant of option values.
fn some(var: any) -> opt[any] { ... }

/// Unwraps value of `some(x)` or `ok(x)`.
fn unwrap(var: any) -> any { ... }

/// Unwraps error from `err(x)`.
fn unwrap_err(var: any) -> any { ... }

/// Unwraps value or using a default.
fn unwrap_or(var: any, def: any) -> any { ... }

/// Creates `ok(var)` variant of option values.
fn ok(var: any) -> res[any] { ... }

/// Creates `err(var)` variant of result values.
fn err(var: any) -> res[any] { ... }

/// Returns `true` if `err(x)`.
fn is_err(var: res[any]) -> bool { ... }

/// Returns `true` if `ok(x)`.
fn is_ok(var: res[any]) -> bool { ... }

/// Returns smallest number in non-empty array.
/// Returns NaN if array is empty.
fn min(array: [f64]) -> f64 { ... }

/// Returns highest number in non-empty array.
/// Returns NaN if array is empty.
fn max(array: [f64]) -> f64 { ... }

/// Returns x component of 4D vector.
fn x(v: vec4) -> f64 { ... }

/// Returns y component of 4D vector.
fn y(v: vec4) -> f64 { ... }

/// Returns z component of 4D vector.
fn z(v: vec4) -> f64 { ... }

/// Returns w component of 4D vector.
fn w(v: vec4) -> f64 { ... }

/// Returns component scalar of 4D vector by index.
fn s(v: vec4, ind: f64) -> f64 { ... }

/// Returns row vector x (basis vector) of 4D matrix.
fn rx(m: mat4) -> vec4 { ... }

/// Returns row vector y (basis vector) of 4D matrix.
fn ry(m: mat4) -> vec4 { ... }

/// Returns row vector z (basis vector) of 4D matrix.
fn rz(m: mat4) -> vec4 { ... }

/// Returns row vector w (basis vector) of 4D matrix.
fn rw(m: mat4) -> vec4 { ... }

/// Returns row vector (basis vector) of 4D matrix by index.
fn rv(m: mat4, ind: f64) -> vec4 { ... }

/// Returns column vector x (transposed basis vector) of 4D matrix.
fn cx(m: mat4) -> vec4 { ... }

/// Returns column vector y (transposed basis vector) of 4D matrix.
fn cy(m: mat4) -> vec4 { ... }

/// Returns column vector z (transposed basis vector) of 4D matrix.
fn cz(m: mat4) -> vec4 { ... }

/// Returns column vector (transposed basis vector) of 4D matrix by index.
fn cv(m: mat4) -> vec4 { ... }

/// Returns determinant of 4D matrix.
fn det(m: mat4) -> f64 { ... }

/// Returns the inverse of 4D matrix.
fn inv(m: mat4) -> mat4 { ... }

/// Returns a translation 4D matrix.
/// Ignores the 4th component.
fn mov(v: vec4) -> mat4 { ... }

/// Returns rotation 4D matrix around an axis and angle.
/// The angle is in radians.
fn rot__axis_angle(axis: vec4, angle: f64) -> mat4 { ... }

/// Returns orthogonal view 4D matrix from position and axis vectors.
fn ortho__pos_right_up_forward(pos: vec4, right: vec4, up: vec4, forward: vec4) -> mat4 { ... }

/// Returns projection 4D matrix from field of view, near clip, far clip and aspect ratio.
/// The field of view is in fractions, usually 1/4.
/// The aspect ratio is usually the width of the draw buffer divided by the height.
fn proj__fov_near_far_ar(fov: f64, near: f64, far: f64, ar: f64) -> mat4 { ... }

/// Returns model view projection 4D matrix.
fn mvp__model_view_projection(model: mat4, view: mat4, projection: mat4) -> mat4 { ... }

/// Returns a scale 4D matrix from a vector.
/// Ignores the 4th component.
fn scale(v: vec4) -> mat4 { ... }

/// Returns 4D vector with length 1,
/// pointing in the direction when starting at `(1, 0)`
/// and rotating around the z axis.
fn dir__angle(angle: f64) -> vec4 { ... }

/// Returns the number of radians in a circle.
/// Use this instead of pi.
fn tau() -> f64 { ... }

/// Loads meta data from a file, using a meta syntax to parse the document.
/// The meta language used is [Piston-Meta](https://github.com/PistonDevelopers/meta).
///
/// Returns an array of arrays:
///
/// - Start character
/// - Number of characters
/// - Type of meta data
/// -- "start" Start of node
/// -- "end" End of node
/// -- "str" -> `str`
/// -- "num" -> `f64`
/// -- "bool" -> `bool`
/// - Name of property
/// - Value
fn load__meta_file(meta_file: str, file: str) -> res[[[any]]] { ... }

/// Loads meta data from an url, using a meta syntax to parse the document.
/// The meta language used is [Piston-Meta](https://github.com/PistonDevelopers/meta).
///
/// For information about fields, see `load__meta_file`.
fn load__meta_url(meta_file: str, url: str) -> res[[any]] { ... }

/// Parses meta syntax rules from string.
/// The meta language used is [Piston-Meta](https://github.com/PistonDevelopers/meta).
fn syntax__in_string(name: str, text: str) -> res[any] { ... }

/// Parses meta data from string.
fn meta__syntax_in_string(syntax: any, name: str, text: str) -> res[[any]] { ... }

/// Downloads a file from an url.
/// Returns `ok(file)` if the downloading succeeded.
/// Designed to be easy to use with threads.
fn download__url_file(url: str, file: str) -> res[str] { ... }

/// Saves a string to a file.
/// Returns `ok(file)` if the saving succeeded.
/// Designed to be easy to use with threads.
fn save__string_file(string: str, file: str) -> res[str] { ... }

/// Loads a string from file.
/// Returns `ok(text)` if the loading succeeded.
fn load_string__file(file: str) -> res[str] { ... }

/// Loads a string from url.
/// Returns `ok(text)` if the loading succeeded.
fn load_string__url(url: str) -> res[str] { ... }

/// Waits for thread to finish and returns the result.
fn join__thread(t: thr[any]) -> res[any] { ... }

/// Loads Dyon data from file.
/// Returns `ok(data)` if loading succeeded.
fn load_data__file(file: str) -> res[any] { ... }

/// Saves Dyon data to file, replacing any existing file.
/// Returns `ok(file)` if saving succeeded.
/// Designed to be easy to use with threads.
fn save__data_file(data: any, file: str) -> res[str] { ... }

/// Loads Dyon data from string.
fn load_data__string(string: str) -> res[any] { ... }

/// Returns the arguments which this program was started with.
/// The first element is usually the path of the executable.
fn args_os() -> [str] { ... }

/// Generates JSON data from meta data.
fn json_from_meta_data(meta_data: [[any]]) -> str { ... }

/// Generates string for error message.
/// Uses same format as [Piston-Meta](https://github.com/PistonDevelopers/meta).
/// The range is in characters by `start` and `len`.
fn errstr__string_start_len_msg(text: str, start: f64, len: f64, msg: str) -> str { ... }

/// Returns `true` if object has key.
fn has(obj: {}, key: str) -> bool { ... }

/// Returns all keys of an object.
fn keys(obj: {}) -> [str] { ... }

/// Returns characters of a string.
fn chars(text: str) -> [str] { ... }

/// Returns seconds since last Unix Epoch.
/// Returns `err(_)` if system clock is adjusted before Unix Epoch.
fn now() -> f64 { ... }

/// Returns `true` if number is NaN.
fn is_nan(v: f64) -> bool { ... }

/// Blocks thread until message is received from channel.
fn wait_next(channel: in) -> opt[any] { ... }

/// Checks for message on channel.
fn next(channel: in) -> opt[any] { ... }