-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathegel.1.html
360 lines (288 loc) · 9.85 KB
/
egel.1.html
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='content-type' content='text/html;charset=utf-8'>
<meta name='generator' content='Ronn-NG/v0.10.1 (http://github.com/apjanke/ronn-ng/tree/0.10.1)'>
<title>egel(1) - EGEL(1) Version 0.1 | The Egel interpreter</title>
<style type='text/css' media='all'>
/* style: man */
body#manpage {margin:0}
.mp {max-width:100ex;padding:0 9ex 1ex 4ex}
.mp p,.mp pre,.mp ul,.mp ol,.mp dl {margin:0 0 20px 0}
.mp h2 {margin:10px 0 0 0}
.mp > p,.mp > pre,.mp > ul,.mp > ol,.mp > dl {margin-left:8ex}
.mp h3 {margin:0 0 0 4ex}
.mp dt {margin:0;clear:left}
.mp dt.flush {float:left;width:8ex}
.mp dd {margin:0 0 0 9ex}
.mp h1,.mp h2,.mp h3,.mp h4 {clear:left}
.mp pre {margin-bottom:20px}
.mp pre+h2,.mp pre+h3 {margin-top:22px}
.mp h2+pre,.mp h3+pre {margin-top:5px}
.mp img {display:block;margin:auto}
.mp h1.man-title {display:none}
.mp,.mp code,.mp pre,.mp tt,.mp kbd,.mp samp,.mp h3,.mp h4 {font-family:monospace;font-size:14px;line-height:1.42857142857143}
.mp h2 {font-size:16px;line-height:1.25}
.mp h1 {font-size:20px;line-height:2}
.mp {text-align:justify;background:#fff}
.mp,.mp code,.mp pre,.mp pre code,.mp tt,.mp kbd,.mp samp {color:#131211}
.mp h1,.mp h2,.mp h3,.mp h4 {color:#030201}
.mp u {text-decoration:underline}
.mp code,.mp strong,.mp b {font-weight:bold;color:#131211}
.mp em,.mp var {font-style:italic;color:#232221;text-decoration:none}
.mp a,.mp a:link,.mp a:hover,.mp a code,.mp a pre,.mp a tt,.mp a kbd,.mp a samp {color:#0000ff}
.mp b.man-ref {font-weight:normal;color:#434241}
.mp pre {padding:0 4ex}
.mp pre code {font-weight:normal;color:#434241}
.mp h2+pre,h3+pre {padding-left:0}
ol.man-decor,ol.man-decor li {margin:3px 0 10px 0;padding:0;float:left;width:33%;list-style-type:none;text-transform:uppercase;color:#999;letter-spacing:1px}
ol.man-decor {width:100%}
ol.man-decor li.tl {text-align:left}
ol.man-decor li.tc {text-align:center;letter-spacing:4px}
ol.man-decor li.tr {text-align:right;float:right}
</style>
</head>
<!--
The following styles are deprecated and will be removed at some point:
div#man, div#man ol.man, div#man ol.head, div#man ol.man.
The .man-page, .man-decor, .man-head, .man-foot, .man-title, and
.man-navigation should be used instead.
-->
<body id='manpage'>
<div class='mp' id='man'>
<div class='man-navigation' style='display:none'>
<a href="#NAME">NAME</a>
<a href="#SYNOPSIS">SYNOPSIS</a>
<a href="#DESCRIPTION">DESCRIPTION</a>
<a href="#OPTIONS">OPTIONS</a>
<a href="#TUTORIAL">TUTORIAL</a>
<a href="#EXAMPLES">EXAMPLES</a>
<a href="#FILES">FILES</a>
<a href="#ENVIRONMENT">ENVIRONMENT</a>
<a href="#BUGS">BUGS</a>
<a href="#AUTHOR">AUTHOR</a>
<a href="#SEE-ALSO">SEE ALSO</a>
</div>
<ol class='man-decor man-head man head'>
<li class='tl'>egel(1)</li>
<li class='tc'></li>
<li class='tr'>egel(1)</li>
</ol>
<h1 id="EGEL-1-Version-0-1-The-Egel-interpreter">EGEL(1) Version 0.1 | The Egel interpreter</h1>
<h2 id="NAME">NAME</h2>
<p><strong>egel</strong> - an untyped functional scripting language</p>
<h2 id="SYNOPSIS">SYNOPSIS</h2>
<table>
<tbody>
<tr>
<td>
<code>egel</code> [-</td>
<td>--interact] [-I <var>path</var>
</td>
<td>--include <var>path</var>] [<var>file</var>]</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td>
<code>egel</code> [-I <var>path</var>
</td>
<td>--include <var>path</var>] -e <var>command</var>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td>
<code>egel</code> [-h</td>
<td>--help</td>
<td>-v</td>
<td>--version]</td>
</tr>
</tbody>
</table>
<h2 id="DESCRIPTION">DESCRIPTION</h2>
<p>Egel is an untyped concurrent functional scripting language based on
eager combinator rewriting with a concise but remarkably powerful
syntax.</p>
<p>Egel's basic functionality can be extended with your own modules
written in C++. Those modules are dynamically loaded.</p>
<h2 id="OPTIONS">OPTIONS</h2>
<dl>
<dt>
<code>-h</code>, <code>--help</code>
</dt>
<dd> Prints brief usage information, may list debug options.</dd>
<dt>
<code>-v</code>, <code>--version</code>
</dt>
<dd> Prints the current version number.</dd>
<dt>
<code>-</code>, <code>--interact</code>
</dt>
<dd> Enter interactive mode unconditionally.</dd>
<dt>
<code>-e</code>, <code>--eval <command></code>
</dt>
<dd> Evaluate the given command.</dd>
<dt>
<code>-I</code>, <code>--include <path></code>
</dt>
<dd> Add an include path.</dd>
</dl>
<h2 id="TUTORIAL">TUTORIAL</h2>
<p>Egel is an expression language and the interpreter a symbolic
evaluator.</p>
<h3 id="Expressions">Expressions</h3>
<p>Egel code consist of expression which are evaluated eagerly.</p>
<ul>
<li>
<p>Basic primitives are integers, floats, complex, unicode characters, and
unicode strings.</p>
<p><code>0 1 2</code> , <code>0.0 3.14 -1.2+3.4j</code> , <code>'a'</code> <code>'∀'</code> , or <code>"Hello World!"</code></p>
</li>
<li>
<p>All constants compose.</p>
<p><code>(0 1)</code> is just as legal as <code>(cons 'a' nil)</code></p>
</li>
<li>
<p>Rewriting is done with the pattern-matching anonymous abstraction,
uppercase letters denote variables.</p>
<p><code>[ X -> X ]</code> , <code>[ (cons HEAD TAIL) -> HEAD ]</code></p>
<p>The abstraction consists of a number of matches, it may be variadic
without penalty.</p>
<p><code>[ X Y -> 2 | X -> 1 | -> 0]</code></p>
<p>A backslash <code>\</code> starts a lambda abstraction.</p>
<p><code>\(cons X XX) -> X</code></p>
</li>
<li>
<p>Patterns may match against tags.</p>
<p><code>[ I:int -> "an int" | C:cons -> "a cons" ]</code></p>
</li>
<li>
<p>Let expressions assign values to intermediaries.</p>
<p><code>let X = 1 + 2 in X * X</code></p>
</li>
<li>
<p>A semicolon separates computations.</p>
<p><code>print (1+2); "done"</code></p>
</li>
<li>
<p>Exception handling is supported, any value may be thrown and
caught.</p>
<p><code>try 1 + throw "failure" catch [ EXC -> print EXC ]</code></p>
</li>
<li>
<p>The do notation composes chains of transformations.</p>
<p><code>(do ((+) 1) |> foldl (*) 1) (from_to 0 4)</code></p>
</li>
<li>
<p>Parallell programming is achieved through the <code>async/await</code>
combinators.
Asynchronous programs start threads that return future objects.</p>
<p><code>let F = async [ _ -> fib 35 ] in await F</code></p>
</li>
<li>
<p>Formatting strings is handled with the <code>format</code> combinator, see
<a href="https://fmt.dev/" data-bare-link="true">https://fmt.dev/</a>.</p>
<p><code>print (format "Hello {}" "world")</code></p>
</li>
<li>
<p>The interpreter implements a term rewriter though has mutable
references.
Cycles won't be garbage collected.</p>
<p><code>let X = ref 0 in set_ref X 1; get_ref X</code></p>
</li>
</ul>
<h3 id="Declarations">Declarations</h3>
<p>Declarations define combinators.</p>
<ul>
<li>
<p>A <code>data</code> declaration introduces constants.</p>
<p><code>data leaf, branch</code></p>
</li>
<li>
<p>A <code>def</code> declaration introduces a combinator.</p>
<p><code>def fac = [0 -> 1 | N -> N * fac (N - 1)]</code></p>
</li>
<li>
<p>A <code>val</code> declaration introduces a combinator who's body is
evaluated prior to it's definition.</p>
<p><code>val global = ref 3.14</code></p>
</li>
</ul>
<h3 id="Modules">Modules</h3>
<p>A module is a series of combinator declarations possibly encapsulated
in a namespace. All combinators are named lowercase, there is some
provisional support for unicode. Modules may import each other. The
<code>main</code> combinator of the top module drives all computation when
present.</p>
<p>Tying it all together:</p>
<pre><code># A Fibonacci implementation.
import "prelude.eg"
namespace Fibonacci (
using System
def fib =
[ 0 -> 0
| 1 -> 1
| N -> fib (N- 2) + fib (N - 1) ]
)
using System
def main = Fibonacci::fib (3+2)
</code></pre>
<h2 id="EXAMPLES">EXAMPLES</h2>
<p>There are three modes in which the interpreter is used: batch,
interactive, or command mode.</p>
<p>In batch mode, just supply the top module with a <code>main</code> combinator.</p>
<pre><code>$ egel helloworld.eg
Hello world!
</code></pre>
<p>The interpreter will start in interactive mode when invoked without a
module argument.</p>
<pre><code>$ egel
> using System
> 1 + 1
2
</code></pre>
<p>Supply a command to use <code>egel -e</code> as a simple calculator. Double
semicolons are separators.</p>
<pre><code>$ egel fib.eg -e "using Fibonacci;; fib 3"
5
</code></pre>
<h2 id="FILES">FILES</h2>
<p>The following files should be in the <code>EGEL_PATH</code> directory.</p>
<dl>
<dt>
<code>prelude.eg</code> <code>calculate.eg</code> <code>search.eg</code>
</dt>
<dd>The standard Egel prelude and additional scripts.</dd>
<dt>
<code>random.ego</code>, etc. </dt>
<dd>Dynamically loaded libraries.</dd>
</dl>
<h2 id="ENVIRONMENT">ENVIRONMENT</h2>
<dl>
<dt><code>EGEL_PATH</code></dt>
<dd> The directories that are searched for inclusion.</dd>
<dt><code>EGEL_PS0</code></dt>
<dd> The prompt given by the interpreter in interactive mode.</dd>
</dl>
<h2 id="BUGS">BUGS</h2>
<p>See GitHub Issues: <a href="https://github.com/egel-lang/egel/issues" data-bare-link="true">https://github.com/egel-lang/egel/issues</a></p>
<h2 id="AUTHOR">AUTHOR</h2>
<p>MIT License (c) 2017 M.C.A. (Marco) Devillers
<a href="mailto:[email protected]" data-bare-link="true">[email protected]</a></p>
<h2 id="SEE-ALSO">SEE ALSO</h2>
<p><strong><span class="man-ref">c++<span class="s">(1)</span></span></strong></p>
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>December 2024</li>
<li class='tr'>egel(1)</li>
</ol>
</div>
</body>
</html>