@plylang/plylang 1.0.18 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -24
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -6,14 +6,15 @@ The compiler translates a module into JavaScript. There is no separate virtual m
|
|
|
6
6
|
|
|
7
7
|
This text walks through the language once, with a short example of each feature.
|
|
8
8
|
|
|
9
|
-
The repository contains the `plylang` compiler and the `plylang-ls` server. Words that work on ready-made values are not built into the compiler: they are imported. The neighboring package `@
|
|
9
|
+
The repository contains the `plylang` compiler and the `plylang-ls` server. Words that work on ready-made values are not built into the compiler: they are imported. The neighboring package `@plylang/prelude` is one such place, and it has its own documentation. The import lines below name that package. They check in a package that depends on it.
|
|
10
10
|
|
|
11
11
|
## Stack
|
|
12
12
|
|
|
13
13
|
A signature says what a word takes and what it puts. The tail under that prefix stays in place.
|
|
14
14
|
|
|
15
15
|
```ply
|
|
16
|
-
~ "
|
|
16
|
+
~ "@plylang/prelude/Classes/Arithmetic" add
|
|
17
|
+
~ "@plylang/prelude/Data/Num"
|
|
17
18
|
|
|
18
19
|
: double ( Num -- Num )
|
|
19
20
|
dup add
|
|
@@ -95,15 +96,18 @@ The same permutations as in Factor follow, with names made of letters: `dupd`, `
|
|
|
95
96
|
`cons` pushes a value and then runs a quotation. The value sits under the quotation, so `5 [ 1 add ] cons` is a quotation of type `(-- Num)` that pushes five and then adds one. The call site does not name that value.
|
|
96
97
|
|
|
97
98
|
```ply
|
|
98
|
-
~ "
|
|
99
|
+
~ "@plylang/prelude/Classes/Comparable" equal
|
|
100
|
+
~ "@plylang/prelude/Classes/Subtractable" subtract
|
|
101
|
+
~ "@plylang/prelude/Classes/Arithmetic" multiply
|
|
102
|
+
~ "@plylang/prelude/Data/Num"
|
|
99
103
|
|
|
100
104
|
: fact ( Num -- Num )
|
|
101
|
-
dup 0
|
|
105
|
+
dup 0 equal [ drop 1 ] [ dup 1 subtract fact multiply ] if
|
|
102
106
|
```
|
|
103
107
|
|
|
104
|
-
Zero is replaced by one. Otherwise `n` and `n - 1` remain on the stack, the recursive `fact` computes the second, and `
|
|
108
|
+
Zero is replaced by one. Otherwise `n` and `n - 1` remain on the stack, the recursive `fact` computes the second, and `multiply` multiplies.
|
|
105
109
|
|
|
106
|
-
Names before `->` name stack values. The left name is the deeper value, the right name is the top. A quotation sees these names, and they are not part of the input.
|
|
110
|
+
Names before `->` name stack values. The left name is the deeper value, the right name is the top. A quotation sees these names, and they are not part of the input. A clause that only renames the stack, and whose names do not appear in a quotation, is ordinary stack code written without `->`.
|
|
107
111
|
|
|
108
112
|
```ply
|
|
109
113
|
: curry ( a (a b -- c) -- (b -- c) )
|
|
@@ -184,15 +188,16 @@ In JavaScript a constructor with no fields is `{ tag: "Nothing" }`. One field is
|
|
|
184
188
|
A word that walks an array is imported. In the example the quotation sits on top. The name comes from one module, and the instance for the array comes from another.
|
|
185
189
|
|
|
186
190
|
```ply
|
|
187
|
-
~ "
|
|
188
|
-
~ "
|
|
189
|
-
~ "
|
|
191
|
+
~ "@plylang/prelude/Classes/Mappable" map
|
|
192
|
+
~ "@plylang/prelude/Classes/Arithmetic" add
|
|
193
|
+
~ "@plylang/prelude/Data/Num"
|
|
194
|
+
~ "@plylang/prelude/Data/Array"
|
|
190
195
|
|
|
191
196
|
: shifted ( -- (Array Num) )
|
|
192
197
|
< 1 2 3 > [ 1 add ] map
|
|
193
198
|
```
|
|
194
199
|
|
|
195
|
-
The bare import of `
|
|
200
|
+
The bare import of `Data/Array` brings the instances of that module and brings no names. The result is `2`, `3`, `4`. `dup` of an array shares the JavaScript reference. A word that writes returns a new array, and the input stays.
|
|
196
201
|
|
|
197
202
|
## A name for a type
|
|
198
203
|
|
|
@@ -213,7 +218,8 @@ Parameters are written as they are on a type: `- Twin a (Pair a a)`. In a slot a
|
|
|
213
218
|
`;` with `==` is a distinct type with one constructor and one field. It does not unify with the field. In JavaScript the constructor returns its argument as it is.
|
|
214
219
|
|
|
215
220
|
```ply
|
|
216
|
-
~ "
|
|
221
|
+
~ "@plylang/prelude/Classes/Arithmetic" add
|
|
222
|
+
~ "@plylang/prelude/Data/Num"
|
|
217
223
|
|
|
218
224
|
; Age == Age Num
|
|
219
225
|
|
|
@@ -228,10 +234,10 @@ Zero fields, two fields, or two constructors do not fit `==`. A type with `=` is
|
|
|
228
234
|
`(StrMap a)` is a dictionary with key `Str`. The key becomes known at run time and is not named in the type ahead of time. There is no literal. An empty dictionary in JavaScript is `Object.create(null)`.
|
|
229
235
|
|
|
230
236
|
```ply
|
|
231
|
-
~ "
|
|
237
|
+
~ "@plylang/prelude/Data/StrMap" emptyStrMap, insertStrMap
|
|
232
238
|
|
|
233
239
|
: ages ( -- (StrMap Num) )
|
|
234
|
-
|
|
240
|
+
emptyStrMap "Ada" 36 insertStrMap
|
|
235
241
|
```
|
|
236
242
|
|
|
237
243
|
The order in the example is the dictionary, the key, and the value on top.
|
|
@@ -242,35 +248,35 @@ The order in the example is the dictionary, the key, and the value on top.
|
|
|
242
248
|
|
|
243
249
|
```ply
|
|
244
250
|
& Equal a
|
|
245
|
-
|
|
251
|
+
equal ( a a -- Bool )
|
|
246
252
|
|
|
247
253
|
& Equal a => Ordered a
|
|
248
254
|
before ( a a -- Bool )
|
|
249
255
|
```
|
|
250
256
|
|
|
251
257
|
```ply
|
|
252
|
-
~ "
|
|
253
|
-
~ "Num"
|
|
258
|
+
~ "@plylang/prelude/Classes/Comparable" Comparable, equal
|
|
259
|
+
~ "@plylang/prelude/Data/Num"
|
|
254
260
|
|
|
255
|
-
: same (
|
|
256
|
-
|
|
261
|
+
: same ( Comparable a => a a -- Bool )
|
|
262
|
+
equal
|
|
257
263
|
```
|
|
258
264
|
|
|
259
|
-
The instance for numbers is declared in
|
|
265
|
+
The instance for numbers is declared in `@plylang/prelude/Data/Num`. The bare import brings the instances of that module and brings no names. That import gives `same` that instance.
|
|
260
266
|
|
|
261
267
|
A hand-written instance is a word for each method. A module may write one when it defines the class, the type, or the wrapper in the head, or when the head contains a built-in constructor `Int`, `Num`, `Bool`, `Str`, `Unit`, `Array`, or `StrMap`.
|
|
262
268
|
|
|
263
269
|
```ply
|
|
264
270
|
& Equal a
|
|
265
|
-
|
|
271
|
+
equal ( a a -- Bool )
|
|
266
272
|
|
|
267
273
|
; Box a = Mk a
|
|
268
274
|
|
|
269
275
|
: eqBox ( Equal a => (Box a) (Box a) -- Bool )
|
|
270
|
-
(Mk x) (Mk y) -> x y
|
|
276
|
+
(Mk x) (Mk y) -> x y equal
|
|
271
277
|
|
|
272
278
|
# Equal (Box a)
|
|
273
|
-
|
|
279
|
+
equal = eqBox
|
|
274
280
|
```
|
|
275
281
|
|
|
276
282
|
A parameter of kind `Type -> Type` writes the constructor in the head.
|
|
@@ -325,7 +331,7 @@ A package is described by `package.json`.
|
|
|
325
331
|
}
|
|
326
332
|
```
|
|
327
333
|
|
|
328
|
-
A `foreign` word has no body. Its implementation lives in the foreign directory, and the number of JavaScript parameters matches the input length. Leave it out of the `@` list when it stays in this file.
|
|
334
|
+
A `foreign` word has no body. Its implementation lives in the foreign directory, and the number of JavaScript parameters matches the input length. Leave it out of the `@` list when it stays in this file. A foreign word that receives an array or a `StrMap` does not change that value. It copies, then writes. `dup` shares the reference. `Cell` is the type of a shared cell.
|
|
329
335
|
|
|
330
336
|
```ply
|
|
331
337
|
: foreign length ( (Array a) -- Num )
|
|
@@ -349,7 +355,7 @@ plylang check --js <file>
|
|
|
349
355
|
|
|
350
356
|
A word named `main` whose scheme is `( -- Unit )` is the program of that module. It may stay off the `@` list. `build` calls it at the bottom of that module's `.js`, and only when Node started that file. `node dist/App.js` runs the program. An import of the module does not. A `package.json` script can name that file. Several modules may each have a `main`. A module without one is a library. Any other scheme on the name `main` is an error. `plylang compile` also writes those modules, then `script.js` beside them. The file is the program of `ply.entry`. A binding is inlined when `main` can call it. The modules themselves still carry the Node guard. `compile` does not rewrite `exports`.
|
|
351
357
|
|
|
352
|
-
`plylang docs` writes `DOCS.md` at the package root. `--out` names another file. A module heading is the string used to import it: the package name and the path, or only the path when there is no name. The prose comes from `..`. Inside a module the sections are `Types`, `Classes`, `Instances`, and `Words`. An empty section is left out. The name of a type, a class, or a word is a heading under its section. `Instances` is a list of `#` heads, with no comment and no method bindings.
|
|
358
|
+
`plylang docs` writes `DOCS.md` at the package root. `--out` names another file. A module heading is the string used to import it: the package name and the path, or only the path when there is no name. The prose comes from `..`. Inside a module the sections are `Types`, `Classes`, `Instances`, and `Words`. An empty section is left out. The name of a type, a class, or a word is a heading under its section. `Instances` is a list of `#` heads, with no comment and no method bindings. A head whose type is defined in another module of this package is listed there too.
|
|
353
359
|
|
|
354
360
|
`plylang check --parse` prints how one file was parsed, and it does not check types. `plylang check --js` prints the JavaScript that `build` would write for that file. Outside a package that is the JavaScript of the one file, and imports are not resolved.
|
|
355
361
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plylang/plylang",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"description": "Ply compiler and language server",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Algosail",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"bin/native.js"
|
|
34
34
|
],
|
|
35
35
|
"optionalDependencies": {
|
|
36
|
-
"@plylang/plylang-darwin-arm64": "1.0.
|
|
37
|
-
"@plylang/plylang-darwin-x64": "1.0.
|
|
38
|
-
"@plylang/plylang-linux-arm64": "1.0.
|
|
39
|
-
"@plylang/plylang-linux-x64": "1.0.
|
|
40
|
-
"@plylang/plylang-win32-arm64": "1.0.
|
|
41
|
-
"@plylang/plylang-win32-x64": "1.0.
|
|
36
|
+
"@plylang/plylang-darwin-arm64": "1.0.20",
|
|
37
|
+
"@plylang/plylang-darwin-x64": "1.0.20",
|
|
38
|
+
"@plylang/plylang-linux-arm64": "1.0.20",
|
|
39
|
+
"@plylang/plylang-linux-x64": "1.0.20",
|
|
40
|
+
"@plylang/plylang-win32-arm64": "1.0.20",
|
|
41
|
+
"@plylang/plylang-win32-x64": "1.0.20"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "cargo build --release",
|