@plylang/plylang 1.0.6 → 1.0.9

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.
Files changed (2) hide show
  1. package/README.md +41 -66
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -21,7 +21,7 @@ A signature says what a word takes and what it puts. The tail under that prefix
21
21
 
22
22
  The body runs from left to right. A number is on the stack. `dup` copies the top. `add` takes both numbers and puts the sum.
23
23
 
24
- A word starts with `:`. Then `foreign` and `private` may appear, in either order and each at most once, followed by the name and the scheme in parentheses. Spaces inside the parentheses do not matter. The body may continue on the same line: `: double ( Num -- Num ) dup add`.
24
+ A word starts with `:`. Then `foreign` may appear, followed by the name and the scheme in parentheses. Spaces inside the parentheses do not matter. The body may continue on the same line: `: double ( Num -- Num ) dup add`.
25
25
 
26
26
  A name in a scheme is one slot. `Num Num` is two slots. `Maybe a` is also two: the constructor needs an argument, and that argument is written in parentheses, `(Maybe a)`. `(Num)` is the same type as `Num`.
27
27
 
@@ -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, a record in braces.
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)
169
162
  ```
170
163
 
171
- In JavaScript a constructor with no fields is `{ tag: "Nothing" }`. One field is the function `(value) => ({ tag: "Just", value })`. Several fields are `value0`, `value1`, from left to right.
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
174
+ ```
175
+
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, or a record.
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
- - Person { name : Str, age : Num }
202
+ ; Person = Person name : Str, age : Num
203
+ - Human Person
236
204
 
237
- : older ( Person -- Person )
238
- 37 =age
205
+ : older ( Human -- Human )
206
+ 37 >>age
239
207
  ```
240
208
 
241
- Parameters are written as they are on a type: `- Pair a b { left : a, right : b }`. In a slot a synonym is saturated, `(Pair Num Str)`.
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
 
@@ -314,7 +282,7 @@ A parameter of kind `Type -> Type` writes the constructor in the head.
314
282
 
315
283
  An instance of such a class begins with `# Mapped Box`.
316
284
 
317
- Two classes with one head are written with a comma. An instance arrives only through a direct import: it does not pass through a second module.
285
+ Two classes with one head are written with a comma. An instance is not a name. Any import carries the instances of that module, and those instances pass along the next import. The word on the right of `=` stays in the file that writes `#` unless that name is also in the `@` list. The caller writes the class method.
318
286
 
319
287
  When an exported word has a constraint in its scheme, the method dictionary becomes the first argument in JavaScript.
320
288
 
@@ -322,18 +290,22 @@ When an exported word has a constraint in its scheme, the method dictionary beco
322
290
 
323
291
  One `*.ply` file is one module. The file itself has no name. The path from the source directory gives it: `src/Data/Maybe.ply` is called `Data.Maybe`. Each segment starts with a capital Latin letter.
324
292
 
325
- Imports stand at the beginning of the file. A path inside this package is written from the source directory. A path into another package is a package specifier. `..` in the parentheses means every public name.
293
+ A module names what it publishes with one `@` list. The list may stand anywhere in the file. A name in the list leaves the file. Any other name stays in the file. The same list holds words, types, constructors, synonyms, classes, methods, and names brought in by an import. A type and its constructor share one entry when they share a name. Names are separated by commas. A bare `@` publishes nothing. A second `@` is a duplicate definition.
326
294
 
327
295
  ```ply
328
296
  ~ "Data/Maybe" (Just, Nothing, fromMaybe)
329
297
  ~ "@algosail/example/Num" (add)
298
+
299
+ @ Maybe, Nothing, Just, fromMaybe
330
300
  ```
331
301
 
332
- `private` is visible in this file, is written into `.d.ply`, and is not exported.
302
+ Imports stay together and come before the first `:`, `;`, `-`, `&`, or `#`. A path inside this package is written from the source directory. A path into another package is a package specifier. The parentheses name what this file uses. `..` means every published name. Writing an imported name again in the `@` list publishes it. `()` brings instances and no names.
303
+
304
+ A test entry, a word `( -- Verdict )` or `suite`, is not a module and has no list. A utility under `test/` is a module and has one. A word `main` with scheme `( -- Unit )` may stay off the list. Node still runs it when it starts that file.
333
305
 
334
306
  A comment runs from `.` to the end of the line, when the dot is not inside `()`. `..` in column 0, directly above `:`, `;`, `-`, or `&`, is the text of that declaration. One space after `..` is not part of the text. A type has one text for all of its constructors. A class has one text for its name and for all of its methods. A `..` line above `#` does not attach to the declaration.
335
307
 
336
- A declaration stands in column 0 and starts with `:`, `;`, `-`, `&`, `#`, or `~`.
308
+ A declaration stands in column 0 and starts with `@`, `:`, `;`, `-`, `&`, `#`, or `~`.
337
309
 
338
310
  A package is described by `package.json`.
339
311
 
@@ -351,25 +323,28 @@ A package is described by `package.json`.
351
323
  }
352
324
  ```
353
325
 
354
- A `foreign` word has no body. Its implementation lives in the `ply.foreign` directory, and the number of JavaScript parameters matches the input length. It combines with `private`.
326
+ 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.
355
327
 
356
328
  ```ply
357
- : foreign private length ( (Array a) -- Num )
329
+ : foreign length ( (Array a) -- Num )
358
330
  ```
359
331
 
360
- `ply.foreign` is required when the package has such a word. The directory lies inside the package and is distinct from `source` and `out`. The generated `.js` imports the implementation from there. Those files are not copied into `dist`.
332
+ The foreign directory is `foreign` when that directory exists, or the string `ply.foreign` when the field is set. It is required when the package has such a word. It lies inside the package and is distinct from the source directory and the output directory. The generated `.js` imports the implementation from there. Those files are not copied into `dist`. A new package writes `ply.language` and leaves `source`, `foreign`, and `out` unset: those directories are `src`, `foreign`, and `dist`. `ply.entry` names the module a pathless package import opens, and the `exports` key `.`.
361
333
 
362
334
  ```text
363
335
  plylang check [dir]
364
336
  plylang build [dir] [--exports]
337
+ plylang test [pattern]
365
338
  plylang docs [dir] [--out <file>]
366
339
  plylang check --parse <file>
367
340
  plylang check --js <file>
368
341
  ```
369
342
 
370
- `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.
343
+ `plylang check` checks a package the same way `build` does: every file under the source directory, the imports, and `foreign`. It writes no files and does not walk `test/`. The default directory is the current one. After the same check, `plylang build` writes a `.js` file and a `.d.ply` interface into the output directory, then aligns `exports` with those modules. A key is `./` followed by the module path. When `ply.entry` is set, `.` points at that module too. `ply` points at the `.d.ply`, and `import` points at the `.js`. A key this tool does not own stays, and so does a hand-written `.` when `ply.entry` is absent. `plylang build --exports` does the same alignment. The other fields of the file stay as they were. A module of this package is imported by its path under the source directory, whether or not `exports` lists it. Another package finds the module through the `exports` entry.
344
+
345
+ `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 word `( -- Verdict )`. The runner calls each one in source order and uses the word as its name. `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 `test/` with neither is a utility. A test imports it by its path under `test/`, and a source file cannot. The runner does not run a utility. A source file cannot import a package that is only a `devDependency`. A test can. A file under the source directory stays where `build` wrote it. Any other test file is compiled in that package, written under the output directory 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.
371
346
 
372
- 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.
347
+ 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.
373
348
 
374
349
  `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.
375
350
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plylang/plylang",
3
- "version": "1.0.6",
3
+ "version": "1.0.9",
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.6",
37
- "@plylang/plylang-darwin-x64": "1.0.6",
38
- "@plylang/plylang-linux-arm64": "1.0.6",
39
- "@plylang/plylang-linux-x64": "1.0.6",
40
- "@plylang/plylang-win32-arm64": "1.0.6",
41
- "@plylang/plylang-win32-x64": "1.0.6"
36
+ "@plylang/plylang-darwin-arm64": "1.0.9",
37
+ "@plylang/plylang-darwin-x64": "1.0.9",
38
+ "@plylang/plylang-linux-arm64": "1.0.9",
39
+ "@plylang/plylang-linux-x64": "1.0.9",
40
+ "@plylang/plylang-win32-arm64": "1.0.9",
41
+ "@plylang/plylang-win32-x64": "1.0.9"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "cargo build --release",