-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.php
449 lines (361 loc) · 13.3 KB
/
index.php
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
<meta charset='utf-8'/>
<meta name="viewport" content="width=device-width, initial-scale=0.6">
<html lang="en-us">
<head>
<meta name="google-site-verification" content="OKvej4xSIY4zxFPd7v6mor2L0hzDXUJaV2gzl5rKYJY" />
<title>Plange</title>
<link rel=StyleSheet href='css/general.css' type='text/css' />
<link rel="icon" type="image/png" href="/plange_favicon.png" />
</head>
<body>
<?php require('header.php') ?>
<p>
Plange is an open-source development suite. The language consists of semantics from imperative, functional, and constraint-based programming. ODE solving, first-order logic, and type checking are examples of the available algebra and calculuses. A hybrid memory model supports garbage collection and native pointers. Many abstractions are available including inline multi-platform assembler, algebraic types, database records, code-level reflection and docstrings. The IDE communicates the success of verification, compilation, and validation steps to the user though real-time feedback, and also displays the results of symbolic workloads. This web domain hosts documentation, standard and third-party import libraries, cloud resources, a support community, and more.
</p>
<ul>
<li>The status of the project is pre-alpha.</li>
<li>license: <a href="https://tldrlegal.com/license/bsd-3-clause-license-(revised)#fulltext">New BSD</a></li>
<li>source code: <a href="https://github.com/coder0xff/Plange">git repository</a></li>
<li>pronunciation<sup>[<a href="http://www.internationalphoneticalphabet.org/ipa-sounds/ipa-chart-with-sounds/">ipa</a>]</sup>: plænd͡ʒ</li>
</ul>
<p>
<div class="code2">
<pre>
print("Hello, world!");
</pre>
</div>
</p>
<div class="code2">
<p>End of line comment (red is comment text)</p>
<pre>
print("My name is HAL 9000."); <span style="color: red">//only kidding!</span>
</pre>
</div>
<div class="code2">
<p>Inline comment (red is comment text) <small><small><small><a href="https://www.xkcd.com/221/">xkcd.com</a></small></small></small></p>
<pre>
getRandomNumber := { return 4; <span style="color: red">/*choosen by fair dice roll*/</span> }; <span style="color: red">//guaranteed to be random</span>
</pre>
</div>
<div class="code2">
<p>print the voltage across a discharging capacitor</p>
<pre>
V := coerce<Real>(input("Volts: "));
R := coerce<Real>(input("Ohms: "));
C := coerce<Real>(input("Farads: "));
𝑡 := coerce<Real>(input("Seconds: "));
𝜏 := R * C;
print(V * 𝑒^(-𝑡/𝜏));
</pre>
</div>
operators:
<?php include('./documentation/operators_printer.php') ?>
<p>Variables can be reassigned.</p>
<div class="code2">
<p>Reassign a variable</p>
<pre>
color ← "Blue";
color ← "Red";
</pre>
</div>
<div class="code2">
<p>Type constraint on a variable</p>
<pre>
<Number> x ← 1337;
</pre>
</div>
<div class="code2">
<p>Memory Model</p>
<pre>
x ← 2.718281;
<Pointer<Float>> x_ptr = address_of(x);
echo(dereference(x_ptr));
</pre>
</div>
<div class="code2">
<p>Symbolic manipulation</p>
<pre>
x = 1337;
tan(y*2) = x; // y is a free variable
echo(y); // arctan(1337) / 2 = { 1.570048, -1.571544 };
</pre>
</div>
<h2>Constants</h2>
<p>A symbol with an immutable value is a constant.</p>
<div class="code2">
<p>Example</p>
<pre>
echo(π);
</pre>
</div>
<p><code>π</code> or <code>pi</code> is a predefined constant, and provides arbitrarily high precision in symbolic manipulation.</p>
<p>Constants are created using the definition operator <code>:=</code></p>
<div class="code2">
<p>Example</p>
<pre>
daysInAWeek := 7;
</pre>
</div>
<h2>Functions</h2>
<p>Function are created with parenthesis <code>( )</code> containing the parameter list, and curly braces <code>{ }</code> containing the implementation. Nullary functions may elide their parameter list.</p>
<div class="code2">
<p>Example</p>
<pre>
doubler := (x) { return x * 2; };
</pre>
</div>
<p>Functions have arity.</p>
<div class="code2">
<p>A binary function</p>
<pre>
geometric_mean := (x, y) { return √(x * y); };
</pre>
</div>
<h2>Types</h2>
<p>Constants and variables may be strongly typed implicitly or explicitly, late bound, or duck typed.</p>
<div class="code2">
<p>Explicit strong typing</p>
<pre>
<Int> x ← 10;
</pre>
</div>
<p><code>Int</code> or <code>ℤ</code> is shorthand for <a href="https://en.wikipedia.org/wiki/Integer">integer</a>. The first line constrains x to <code>Int</code> values. See <a href="documentation/type-system.php">Type System</a>.</p>
<h3>Functions Types</h3>
<p>Create function types using the <code>→</code> operator, or <code>-></code>.</p>
<div class="code2">
<p>Example</p>
<pre>
<Int → Int> doubler = (x) { return x * 2; };
</pre>
</div>
<p>doubler will only accept an <code>Int</code> as input, and will only return an <code>Int</code>. Function arguments may also be given types.</p>
<div class="code2">
<p>Semantically equivalent to the previous example</p>
<pre>
doubler := (<Int> x) { return x * 2; };
</pre>
</div>
<p>Variables that have no specified type constraint are dynamically typed.</p>
<div class="code2">
<p>Assigning objects of varied type to a variable</p>
<pre>
x ← 10;
x ← "Alice";
x ← { print("fubar"); };
</pre>
</div>
<h3>Making Types</h3>
<p>The <a href="/documentation/keywords/type.php"><code>type</code></a> keyword (not capitalized) is used to make a new <a href="/documentation/standard-library/Type.php"><code>Type</code></a> object (capitalized). </p>
<div class="code2">
<p>Example</p>
<pre>
Color := type {
<Double> r;
<Double> g;
<Double> b;
};
<Color> red ← (| 1, 0, 0 |);
print(type_of( (| 1, 0, 0 |) )); // output: Tuple<Number, Number, Number>
print(type_of(red)); // output: Color
print(type_of(Color)); // output: Type
</pre>
</div>
<h2>Parametric Types</h2>
<p>Parametric types are functions that return Type objects.</p>
<div class="code2">
<p>Example</p>
<pre>
Node := (<Type> valueType) {
return type {
<valueType> v;
Maybe<Node<valueType>> next;
};
};
</pre>
</div>
<p>Constant folding evaluates some invocations of type functions at compile time. Functions that return Type objects (<a href="/documentation/syntax.php?name=INVOCATION">or another type function</a>) should be called with the angle bracket syntax:</p>
<div class="code2">
<p>Example invoking List using angle bracket syntax</p>
<pre>
<List<Int>> myList;
</pre>
</div>
<h2>Pattern Matching</h2>
<p>Pattern matching decomposes values into unbound symbols. Patterns are tested sequentially in the order given.</p>
<div class="code2">
<p>Tail recursive function to print the last element of a list</p>
<pre>
<List<_> → Void> printLast :=
(_ & tail) { printLast(tail); } |
(x) { print(x); };
myList := [ 5, 12, 8, 9 ];
printLast(myList);
</pre>
</div>
<div class="code2">
<p>Output</p>
<pre>
9
</pre>
</div>
<p>The prepend operator <code>&</code> takes a value on the left, and a list on the right. In the examples above the first parameter to the function is being broken apart into two pieces.</p>
<p>Note the use of the underscore <code>_</code> character. It's substituted for a variable when the code doesn't care about the value. In the first line of the example above, we are unconcerned with the type of the elements the input list contains, and only need to ensure that the input is a list of something. In the second line, we don't need to know the value of the head element. The underscore keyword is called <a href="documentation/keywords/dont_care.php">dont_care</a>.</p>
<div class="code2">
<p>Another recursive function to filter values</p>
<pre>
filter :=
(head & tail, predicate) {
return predicate(head) ?
head & this_func(tail, predicate) :
this_func(tail, predicate);
} |
([], predicate) { return []; };
</pre>
</div>
<h2>Polymorphism</h2>
<p>The <a href="documentation/keywords/inheriting.php">inheriting</a> keyword, used in conjunction with the type keyword, makes a new Type object inheriting the members of the specified base Types. See also: <a href="documentation/keywords/implementing.php">implementing</a></p>
<div class="code2">
<p>Example</p>
<pre>
// base Type
Widget := type {
<Void → Image> Paint;
};
// derived Type
TextBox := type inheriting Widget {
<String> text ← "Hello, world!";
// override the inherited Paint method
Paint ← (<Canvas> c) {
return c.print(text);
};
};
</pre>
</div>
<h2>Algebraic Types</h2>
<p>Types can be combined together to make algebraic Types using the compound operator <code>|</code>.</p>
<div class="code2">
<p>Example</p>
<pre>
Some := (t) { return type { <t> value; }; };
None := type {};
Maybe := (t) { return Some<t> | None };
<Void → Maybe<Int>> get_age := {
return coerce(input("What's your age? You don't have to tell me."));
};
print(get_age());
</pre>
</div>
<h2>Constraint solving</h2>
<p>Many interesting problems may be constructed as one or more constraints using operators and functions. When an appropriate normal form or canonical form is given, constant folding, satisfiability solving, and symbolic manipulation yield equality constraints upon termination. See <a href="documentation/computer-algebra-systems.php">the computer algebra systems page</a>. All the results in this section have been computed manually for demonstrative purposes.</p>
<div class="code2">
<p>Example</p>
<pre>
children := {| abe, dan, mary, sue |};
ages := {| 3, 5, 6, 9 |};
children ↔ ages; // One child per one age (bijection operator)
abe > dan; //abe is older than dan
sue < mary; //sue is younger than mary
sue = dan + 3; //sue's age is dan's age plus 3 years
mary > abe; //mary is older than abe
print(abe);
print(dan);
print(mary);
print(sue);
</pre>
</div>
<p>The output when ran:</p>
<div class="code2">
<p>Output</p>
<pre>
5
3
9
6
</pre>
</div>
<div class="code2">
<p>Example of a linear system</p>
<pre>
<Real * Real * Real → Real> linear_interpolation :=
(min, max, x) { min * (1 - x) + max * x }
;
inverted_linear_interpolation := (min, max, interpolated) {
interpolated = linear_interpolation(min, max, x); // solve for free variable x
return x;
}
linear_map := (minIn, maxIn, v, minOut, maxOut) {
v = linear_interpolation(minIn, maxIn, x); // solve for free variable x
return linear_interpolation(minOut, maxOut, x);
}
assert(x = inverted_linear_interpolation(y, z, linear_interpolation(y, z, x));
</pre>
</div>
<p>One well studied domain is <a href="https://en.wikipedia.org/wiki/Initial_value_problem">initial value problems</a>. An ordinary differential equation is given with boundary conditions on free variables:</p>
<div class="code2">
<p>Example: Aerodynamic Drag On A Projectile</p>
<pre>
projectilePosition := (
<Vector3D> initialPos,
<Vector3D> initialVel,
<Real> mass,
<Real> drag,
<Vector3D> gravity,
<Real> t
) {
// declare the position function, x
<Real → Vector3> x;
// model x as a differential equation
mass * Δ^2x(t)/Δt^2 = -drag * Δx(t)/Δt + mass * gravity;
// with boundary conditions
x(0) = initialPos;
Δx(0)/Δt = initialVel;
// solve, substitute, evaluate
return x(delta_t);
};
</pre>
</div>
<p>ODE solving gives a symbolic solution for x such that the following program is functionally equivalent. This constant folding is performed and cached at compile time.</p>
<div class="code2">
<p>Example (continued)</p>
<pre>
projectilePosition := (
<Vector3D> initialPos,
<Vector3D> initialVel,
<Real> mass,
<Real> drag,
<Vector3D> gravity,
<Real> t
) {
a := 𝑒^(drag*t/mass);
return (
gravity * (mass-(mass*a + drag*t)) +
initialPos*a*drag^2 +
drag*mass*initialVel*(a-1)
) / (a*drag^2);
};
</pre>
</div>
<h3>Limitations</h3>
<p>Constraint solving is intractible in the general case. Users must familiarize themselves with the capabilities of the language, which are expected to expand. A demonstration of a semantically correct but nonfunctional program is in order.</p>
<div class="code2">
<p>Counter Example</p>
<pre>
<Collection * BinaryRelation → Collection> sort := (items, ordering) {
result ↔ items; // result and items make a bijection
∀ { ordering(result[i - 1], result[i]) | i ∈ (0...|result|) }; //the result has to be sorted
return result; // solve, substitute, and return
};
</pre>
</div>
<p>The above function, sort, is functionaly equivalent to the sorting functions. However, this constraint based problem is not yet solvable using available techniques.</p>
</div>
<h2>Further reading</h2>
<ul>
<li><a href="/documentation/syntax.php?name=IF">if (syntax)</a></li>
<li><a href="/documentation/syntax.php?name=FOR">for (syntax)</a></li>
<li><a href="/documentation/syntax.php?name=STATEMENT_SCOPE">statement_scope (syntax)</a></li>
<li><a href="/documentation/operators.php">operators</a></li>
</ul>
<?php require('footer.php') ?>
</body>
</html>