@plylang/plylang 1.0.6 → 1.0.7
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 +27 -56
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ The same permutations as in Factor follow, with names made of letters: `dupd`, `
|
|
|
72
72
|
|
|
73
73
|
## Quotation
|
|
74
74
|
|
|
75
|
-
`[ ... ]` is a value. It does not capture the stack outside, and it does not run by itself. Square brackets are a quotation. An array is written in angle brackets
|
|
75
|
+
`[ ... ]` is a value. It does not capture the stack outside, and it does not run by itself. Square brackets are a quotation. An array is written in angle brackets.
|
|
76
76
|
|
|
77
77
|
```text
|
|
78
78
|
: call ( ..s (..s -- ..t) -- ..t )
|
|
@@ -127,7 +127,7 @@ When the first line of a body is patterns and `->`, the whole body is equations.
|
|
|
127
127
|
|
|
128
128
|
`true` together with `false` covers `Bool`. `Num`, `Int`, and `Str` need a final branch with a name or `_`.
|
|
129
129
|
|
|
130
|
-
A bare constructor puts its fields on the stack from left to right, the last field on top. Parentheses hold one slot: `(Just x)` names the field and does not put it until the name is mentioned.
|
|
130
|
+
A bare constructor puts its fields on the stack from left to right, the last field on top. Parentheses hold one slot: `(Just x)` names the field and does not put it until the name is mentioned. `(Person n _)` names the first field of `Person` and discards the second.
|
|
131
131
|
|
|
132
132
|
An array in a pattern has a fixed length. `<>` matches only the empty array. One length does not cover every `Array`.
|
|
133
133
|
|
|
@@ -137,13 +137,6 @@ An array in a pattern has a fixed length. `<>` matches only the empty array. One
|
|
|
137
137
|
_ -> false
|
|
138
138
|
```
|
|
139
139
|
|
|
140
|
-
A record in a pattern reads the named fields. The tail `| r` is written in the type of the slot, not in the pattern. `{}` fits any record of that slot.
|
|
141
|
-
|
|
142
|
-
```ply
|
|
143
|
-
: nameOf ( { name : Str | r } -- Str )
|
|
144
|
-
{ name : n } -> n
|
|
145
|
-
```
|
|
146
|
-
|
|
147
140
|
## Data
|
|
148
141
|
|
|
149
142
|
`;` in column 0 names an algebraic type. A constructor is a word. A type and a word with one name live in different spaces.
|
|
@@ -165,14 +158,28 @@ The empty body of the `Nothing` branch leaves the fallback value. For `Just` the
|
|
|
165
158
|
A list with its own structure is a separate type. The head sits in the constructor, and the tail is another value of that type.
|
|
166
159
|
|
|
167
160
|
```ply
|
|
168
|
-
; List a = Nil | Cons a (List a)
|
|
161
|
+
; List a = Nil | Cons head : a, tail : (List a)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Zero fields and one field have no names. `Nothing` stores nothing. `Just a` stores one value, and the equation names it. Two or more fields are `name : Type`, separated by commas. A second positional type is [PL0117](docs/Errors.md#pl0117). One named field is [PL0118](docs/Errors.md#pl0118).
|
|
165
|
+
|
|
166
|
+
```ply
|
|
167
|
+
; Pair a b = Pair frs : a, snd : b
|
|
168
|
+
|
|
169
|
+
: frs ( a b. (Pair a b) -- a )
|
|
170
|
+
frs>>
|
|
171
|
+
|
|
172
|
+
: setSnd ( a b. (Pair a b) b -- (Pair a b) )
|
|
173
|
+
>>snd
|
|
169
174
|
```
|
|
170
175
|
|
|
171
|
-
|
|
176
|
+
`Pair` the word takes the fields in that order, last on top. `frs>>` consumes the pair and leaves the field. When the pair is still needed, copy it first: `dup frs>>`. `>>snd` takes the new field above the pair and returns a new pair. The previous pair is a separate value. A sum has no reader: `->` picks the constructor. `name>>` on `Maybe` is [PL0119](docs/Errors.md#pl0119). `frs>>` on `Int`, on a type variable, or on a synonym of `Num` is [PL0063](docs/Errors.md#pl0063). A missing field is [PL0120](docs/Errors.md#pl0120).
|
|
177
|
+
|
|
178
|
+
In JavaScript a constructor with no fields is `{ tag: "Nothing" }`. One field is `(value) => ({ tag: "Just", value })`. Named fields are properties: `(v0, v1) => ({ tag: "Pair", frs: v0, snd: v1 })`.
|
|
172
179
|
|
|
173
180
|
## Array
|
|
174
181
|
|
|
175
|
-
`< 1 2 3 >` is an array of three numbers, of type `(Array Num)`. Index 0 is the left element. The empty array is `<>`. A word is not written inside the angle brackets: an element is a literal, a quotation, a nested array
|
|
182
|
+
`< 1 2 3 >` is an array of three numbers, of type `(Array Num)`. Index 0 is the left element. The empty array is `<>`. A word is not written inside the angle brackets: an element is a literal, a quotation, or a nested array.
|
|
176
183
|
|
|
177
184
|
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.
|
|
178
185
|
|
|
@@ -187,58 +194,19 @@ A word that walks an array is imported. In the example the quotation sits on top
|
|
|
187
194
|
|
|
188
195
|
Empty parentheses bring the instances of a module and bring no names. The result is `2`, `3`, `4`.
|
|
189
196
|
|
|
190
|
-
## Record
|
|
191
|
-
|
|
192
|
-
A record is an unnamed set of fields. Field order does not matter: `{ name : Str, age : Num }` and `{ age : Num, name : Str }` are one type.
|
|
193
|
-
|
|
194
|
-
```ply
|
|
195
|
-
: person ( -- { name : Str, age : Num } )
|
|
196
|
-
{ name: "Ada", age: 36 }
|
|
197
|
-
|
|
198
|
-
: nameOf ( { name : Str | r } -- Str )
|
|
199
|
-
/name
|
|
200
|
-
|
|
201
|
-
: older ( { name : Str, age : Num } -- { name : Str, age : Num } )
|
|
202
|
-
37 =age
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
`/name` reads a field. An open tail `| r` accepts extra labels, so `nameOf` also takes a record with an `age` field. A closed record `{ name : Str }` accepts no extra field.
|
|
206
|
-
|
|
207
|
-
`=age` replaces a field that is already there and returns a new record. The old JavaScript object stays as it was. `+city` adds a label that is not there yet. The record under `+name` must be closed.
|
|
208
|
-
|
|
209
|
-
```ply
|
|
210
|
-
- Person { name : Str, age : Num }
|
|
211
|
-
- PersonWithCity { city : Str | Person }
|
|
212
|
-
|
|
213
|
-
: inParis ( Person -- PersonWithCity )
|
|
214
|
-
"Paris" +city
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
`| Person` substitutes the fields of a closed record. `| (Person a)` does the same when the synonym has an argument: the parentheses are required. The empty record is `{}`.
|
|
218
|
-
|
|
219
|
-
When the record is still needed after a read, copy it: `dup /name`.
|
|
220
|
-
|
|
221
|
-
A named type and a record do different jobs. A constructor may carry a record whole.
|
|
222
|
-
|
|
223
|
-
```ply
|
|
224
|
-
; Person = Mk { name : Str, age : Num }
|
|
225
|
-
|
|
226
|
-
: personName ( Person -- Str )
|
|
227
|
-
Mk -> /name
|
|
228
|
-
```
|
|
229
|
-
|
|
230
197
|
## A name for a type
|
|
231
198
|
|
|
232
199
|
`-` names a type that already exists. The right-hand side follows immediately. It is the same type, and the name has no constructor.
|
|
233
200
|
|
|
234
201
|
```ply
|
|
235
|
-
|
|
202
|
+
; Person = Person name : Str, age : Num
|
|
203
|
+
- Human Person
|
|
236
204
|
|
|
237
|
-
: older (
|
|
238
|
-
37
|
|
205
|
+
: older ( Human -- Human )
|
|
206
|
+
37 >>age
|
|
239
207
|
```
|
|
240
208
|
|
|
241
|
-
Parameters are written as they are on a type: `-
|
|
209
|
+
Parameters are written as they are on a type: `- Twin a (Pair a a)`. In a slot a synonym is saturated, `(Twin Num)`.
|
|
242
210
|
|
|
243
211
|
## Wrapper
|
|
244
212
|
|
|
@@ -362,6 +330,7 @@ A `foreign` word has no body. Its implementation lives in the `ply.foreign` dire
|
|
|
362
330
|
```text
|
|
363
331
|
plylang check [dir]
|
|
364
332
|
plylang build [dir] [--exports]
|
|
333
|
+
plylang test [pattern]
|
|
365
334
|
plylang docs [dir] [--out <file>]
|
|
366
335
|
plylang check --parse <file>
|
|
367
336
|
plylang check --js <file>
|
|
@@ -369,6 +338,8 @@ plylang check --js <file>
|
|
|
369
338
|
|
|
370
339
|
`plylang check` checks a package the same way `build` does: every file under `ply.source`, the imports, and `foreign`. It writes no files. The default directory is the current one. After the same check, `plylang build` writes a `.js` file and a `.d.ply` interface into `ply.out`. `plylang build --exports` replaces the `exports` field of `package.json` with entries for the built modules. A key is `./` followed by the module path. `ply` points at the `.d.ply`, and `import` points at the `.js`. The other fields of the file stay as they were. A module of this package is imported by its path under `ply.source`, whether or not `exports` lists it. Another package finds the module through the `exports` entry.
|
|
371
340
|
|
|
341
|
+
`plylang test` builds the package, then compiles and runs the files that match one pattern. The pattern is relative to the package root. The default is `test/**/*.ply`. `*` matches inside one path segment. `**` matches across directories. Quote the pattern so the shell does not expand `*`. A test is a public word `( -- Verdict )`. The runner calls each one in source order and uses the word as its name. A `private` word is not a test. `expect` compares two values. `pass` and `differ` build a verdict when those values have no `Showable` instance. The words live in `@plylang/test`. A file with no such word may export `suite` with scheme `( -- (Array Verdict) )` instead. A file under `ply.source` stays where `build` wrote it. Any other test file is compiled in that package, written under `ply.out` for the run, and deleted afterwards. The report names each file and each check. A check also prints `file:line` of its word. A failing check prints its text under the name. One check that throws still lets the other checks run. A file that does not compile or does not run prints the diagnostic, and the other files still run. A failed check, a compile error, or a thrown suite exits 1. No file matched exits 1 with `no tests matched`. Color is used when stdout is a terminal and `NO_COLOR` is unset.
|
|
342
|
+
|
|
372
343
|
A word named `main` whose scheme is `( -- Unit )` is the program of that module. It may be `private`. `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.
|
|
373
344
|
|
|
374
345
|
`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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plylang/plylang",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
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.7",
|
|
37
|
+
"@plylang/plylang-darwin-x64": "1.0.7",
|
|
38
|
+
"@plylang/plylang-linux-arm64": "1.0.7",
|
|
39
|
+
"@plylang/plylang-linux-x64": "1.0.7",
|
|
40
|
+
"@plylang/plylang-win32-arm64": "1.0.7",
|
|
41
|
+
"@plylang/plylang-win32-x64": "1.0.7"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "cargo build --release",
|