@plylang/plylang 1.0.5 → 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.
Files changed (2) hide show
  1. package/README.md +31 -57
  2. 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, 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 )
@@ -81,6 +81,7 @@ The same permutations as in Factor follow, with names made of letters: `dupd`, `
81
81
  : bi ( ..s a (a -- b) (a -- c) -- ..s b c )
82
82
  : if ( ..s Bool (..s -- ..t) (..s -- ..t) -- ..t )
83
83
  : quote ( ..s a -- ..s (-- a) )
84
+ : cons ( ..r a (..s a -- ..t) -- ..r (..s -- ..t) )
84
85
  ```
85
86
 
86
87
  `call` takes a quotation and runs it on the rest. `dip` hides the value under the quotation, runs the quotation, and returns what it hid to the top. `dip2` and `dip3` hide two and three values. `keep` runs the quotation and returns the value it took. `keep2` returns two.
@@ -91,6 +92,8 @@ The same permutations as in Factor follow, with names made of letters: `dupd`, `
91
92
 
92
93
  `quote` wraps the top. `42 quote` is a quotation of type `(-- Num)`.
93
94
 
95
+ `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
+
94
97
  ```ply
95
98
  ~ "Num" (eq, sub, mul)
96
99
 
@@ -124,7 +127,7 @@ When the first line of a body is patterns and `->`, the whole body is equations.
124
127
 
125
128
  `true` together with `false` covers `Bool`. `Num`, `Int`, and `Str` need a final branch with a name or `_`.
126
129
 
127
- 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.
128
131
 
129
132
  An array in a pattern has a fixed length. `<>` matches only the empty array. One length does not cover every `Array`.
130
133
 
@@ -134,13 +137,6 @@ An array in a pattern has a fixed length. `<>` matches only the empty array. One
134
137
  _ -> false
135
138
  ```
136
139
 
137
- 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.
138
-
139
- ```ply
140
- : nameOf ( { name : Str | r } -- Str )
141
- { name : n } -> n
142
- ```
143
-
144
140
  ## Data
145
141
 
146
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.
@@ -162,14 +158,28 @@ The empty body of the `Nothing` branch leaves the fallback value. For `Just` the
162
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.
163
159
 
164
160
  ```ply
165
- ; List a = Nil | Cons a (List a)
161
+ ; List a = Nil | Cons head : a, tail : (List a)
166
162
  ```
167
163
 
168
- 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 })`.
169
179
 
170
180
  ## Array
171
181
 
172
- `< 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.
173
183
 
174
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.
175
185
 
@@ -184,58 +194,19 @@ A word that walks an array is imported. In the example the quotation sits on top
184
194
 
185
195
  Empty parentheses bring the instances of a module and bring no names. The result is `2`, `3`, `4`.
186
196
 
187
- ## Record
188
-
189
- 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.
190
-
191
- ```ply
192
- : person ( -- { name : Str, age : Num } )
193
- { name: "Ada", age: 36 }
194
-
195
- : nameOf ( { name : Str | r } -- Str )
196
- /name
197
-
198
- : older ( { name : Str, age : Num } -- { name : Str, age : Num } )
199
- 37 =age
200
- ```
201
-
202
- `/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.
203
-
204
- `=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.
205
-
206
- ```ply
207
- - Person { name : Str, age : Num }
208
- - PersonWithCity { city : Str | Person }
209
-
210
- : inParis ( Person -- PersonWithCity )
211
- "Paris" +city
212
- ```
213
-
214
- `| 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 `{}`.
215
-
216
- When the record is still needed after a read, copy it: `dup /name`.
217
-
218
- A named type and a record do different jobs. A constructor may carry a record whole.
219
-
220
- ```ply
221
- ; Person = Mk { name : Str, age : Num }
222
-
223
- : personName ( Person -- Str )
224
- Mk -> /name
225
- ```
226
-
227
197
  ## A name for a type
228
198
 
229
199
  `-` names a type that already exists. The right-hand side follows immediately. It is the same type, and the name has no constructor.
230
200
 
231
201
  ```ply
232
- - Person { name : Str, age : Num }
202
+ ; Person = Person name : Str, age : Num
203
+ - Human Person
233
204
 
234
- : older ( Person -- Person )
235
- 37 =age
205
+ : older ( Human -- Human )
206
+ 37 >>age
236
207
  ```
237
208
 
238
- 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)`.
239
210
 
240
211
  ## Wrapper
241
212
 
@@ -359,6 +330,7 @@ A `foreign` word has no body. Its implementation lives in the `ply.foreign` dire
359
330
  ```text
360
331
  plylang check [dir]
361
332
  plylang build [dir] [--exports]
333
+ plylang test [pattern]
362
334
  plylang docs [dir] [--out <file>]
363
335
  plylang check --parse <file>
364
336
  plylang check --js <file>
@@ -366,6 +338,8 @@ plylang check --js <file>
366
338
 
367
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.
368
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
+
369
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.
370
344
 
371
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.
@@ -374,7 +348,7 @@ A word named `main` whose scheme is `( -- Unit )` is the program of that module.
374
348
 
375
349
  The exit code is 0 for success, 1 for a diagnostic, and 2 for bad arguments. `--help` prints the same lines. Messages are in English: `file:line:column: error: PLxxxx: message`, and the next line is a link to the matching section of `docs/Errors.md`.
376
350
 
377
- What enters a word's function is its own prefix, from the bottom upward. One result is returned by itself. Several results come back as a JavaScript array: that is the calling convention, and it is not an `(Array a)` value. The words from `dup` through `over2` do not become calls. `call`, `dip`, `keep`, `bi`, `if`, and their neighbors inline the body of the quotation.
351
+ What enters a word's function is its own prefix, from the bottom upward. One result is returned by itself. Several results come back as a JavaScript array: that is the calling convention, and it is not an `(Array a)` value. The words from `dup` through `over2` do not become calls. `call`, `dip`, `keep`, `bi`, `if`, and their neighbors inline the body of the quotation. `cons` builds a quotation that pushes the value under it and then runs it.
378
352
 
379
353
  ## Building
380
354
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plylang/plylang",
3
- "version": "1.0.5",
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.5",
37
- "@plylang/plylang-darwin-x64": "1.0.5",
38
- "@plylang/plylang-linux-arm64": "1.0.5",
39
- "@plylang/plylang-linux-x64": "1.0.5",
40
- "@plylang/plylang-win32-arm64": "1.0.5",
41
- "@plylang/plylang-win32-x64": "1.0.5"
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",