@plylang/plylang 1.1.3 → 1.2.0

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 +22 -22
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -32,19 +32,19 @@ An omitted stack bottom is the same tail on the left and on the right. An explic
32
32
 
33
33
  ## Values
34
34
 
35
- Five built-in types and two constructors of arity 1 are visible in every module. They cannot be redefined.
35
+ Five built-in types and `Array` are visible in every module. They cannot be redefined.
36
36
 
37
- | Type | Literal | In JavaScript |
38
- | --- | --- | --- |
39
- | `Num` | `1`, `42`, `1.5`, `1e-3` | number |
40
- | `Int` | `0n`, `42n`, `-42n` | `bigint` |
41
- | `Str` | `"hi"`, `"a\nb"` | string |
42
- | `Bool` | `true`, `false` | boolean |
43
- | `Unit` | the word `Unit` | `undefined` |
37
+ | Type | Literal | In JavaScript |
38
+ | ------ | ------------------------ | ------------- |
39
+ | `Num` | `1`, `42`, `1.5`, `1e-3` | number |
40
+ | `Int` | `0n`, `42n`, `-42n` | `bigint` |
41
+ | `Str` | `"hi"`, `"a\nb"` | string |
42
+ | `Bool` | `true`, `false` | boolean |
43
+ | `Unit` | `unit` | `undefined` |
44
44
 
45
- `(Array a)` is an array. `(StrMap a)` is a dictionary with a string key. Bare digits are `Num`, an ordinary number in JavaScript. `Int` is written with the suffix `n` and becomes a `bigint`. In the examples below a number is `Num`. `1.0` is a number. `1.` is the number `1` and a separate dot. A string accepts `\\`, `\"`, `\n`, `\t`, and `\r`.
45
+ `(Array a)` is an array. Bare digits are `Num`, an ordinary number in JavaScript. `Int` is written with the suffix `n` and becomes a `bigint`. In the examples below a number is `Num`. `1.0` is a number. `1.` is the number `1` and a separate dot. A string accepts `\\`, `\"`, `\n`, `\t`, and `\r`.
46
46
 
47
- `Unit` is both a type and a word. The word puts the single value of that type.
47
+ `unit` is the one value of type `Unit`. It needs no import. `Unit ->` leaves that value when `Nullary` for `Unit` is visible.
48
48
 
49
49
  Operations on these values are imported. This text does not list them.
50
50
 
@@ -96,13 +96,13 @@ The same permutations as in Factor follow, with names made of letters: `dupd`, `
96
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.
97
97
 
98
98
  ```ply
99
- ~ "@plylang/prelude/Classes/Eq" equal
100
- ~ "@plylang/prelude/Classes/Subtractable" subtract
99
+ ~ "@plylang/prelude/Classes/Setoid" equal
100
+ ~ "@plylang/prelude/Classes/Subtractable" sub
101
101
  ~ "@plylang/prelude/Classes/Arithmetic" multiply
102
102
  ~ "@plylang/prelude/Data/Num"
103
103
 
104
104
  : fact ( Num -- Num )
105
- dup 0 equal [ drop 1 ] [ dup 1 subtract fact multiply ] if
105
+ dup 0 equal [ drop 1 ] [ dup 1 sub fact multiply ] if
106
106
  ```
107
107
 
108
108
  Zero is replaced by one. Otherwise `n` and `n - 1` remain on the stack, the recursive `fact` computes the second, and `multiply` multiplies.
@@ -121,7 +121,7 @@ This is an ordinary word of a module. It is not built into the compiler.
121
121
 
122
122
  ## Pattern matching
123
123
 
124
- When the first line of a body is patterns and `->`, the whole body is equations. The right-hand pattern is the top. A name binds a slot. A literal is compared with the value. `_` discards a value. The first match wins. A value cannot be matched in the middle of a body: write a separate word for that, and make its whole body equations.
124
+ When the first line of a body is patterns and `->`, the whole body is equations. The right-hand pattern is the top. A name takes a slot. A literal is compared with the value and taken. `_` matches any value and leaves it. The first match wins. A value cannot be matched in the middle of a body: write a separate word for that, and make its whole body equations.
125
125
 
126
126
  ```ply
127
127
  : toString ( Bool -- Str )
@@ -129,16 +129,16 @@ When the first line of a body is patterns and `->`, the whole body is equations.
129
129
  false -> "false"
130
130
  ```
131
131
 
132
- `true` together with `false` covers `Bool`. `Num`, `Int`, and `Str` need a final branch with a name or `_`.
132
+ `true` together with `false` covers `Bool`. `unit` covers `Unit`. A literal of `Num`, `Int`, or `Str` does not. `Num ->`, `Int ->`, `Str ->`, `Bool ->`, `Array ->`, and `Unit ->` match a visible `Nullary` or `Unary` instance and leave the value. The test calls that instance's word. On a wider type they do not cover the slot, so a later name or `_` remains. The arm sees the word's signature with that shape filled in. The other arms do not. A `; foreign` type is matched the same way when its module defines `Nullary`, `Unary`, or `Binary`.
133
133
 
134
- A bare constructor checks the tag and leaves the value. `(Ctor ..)` spills every field, last on top. `(Just x)` names the one field and does not put it until the name is mentioned. `(Person n _)` is positional: the first field is kept under `n` and the second is discarded. `(Person age name)` binds by name, in either order, when every name is a field. `(Person)` is an error. `(Some (Array Num) items)` checks that the field is an array of numbers and names that array. The check runs when the field's type is still open. `(Some (Array Num))` without a name is an error. `(Some (Num) ..)` checks and spills that number. `(Some (Num) _)` only checks.
134
+ A bare constructor checks the tag and leaves the value. `(Ctor ..)` spills every field, last on top. `(Just x)` names the one field and does not put it until the name is mentioned. `(Person n _)` is positional: the first field is kept under `n` and the second stays off the stack. `(Person age name)` binds by name, in either order, when every name is a field. `(Person)` is an error. `(Some (Array Num) items)` checks that the field is an array of numbers and names that array. The check runs when the field's type is still open. `(Some (Num) ..)` checks and spills that number. `(Some (Num) _)` only checks. `(Array x)` does not bind `x`.
135
135
 
136
136
  An array in a pattern has a fixed length. `<>` matches only the empty array. One length does not cover every `Array`.
137
137
 
138
138
  ```ply
139
139
  : isEmpty ( (Array a) -- Bool )
140
140
  <> -> true
141
- _ -> false
141
+ _ -> drop false
142
142
  ```
143
143
 
144
144
  ## Data
@@ -235,10 +235,10 @@ Zero fields, two fields, or two constructors do not fit `==`. A type with `=` is
235
235
 
236
236
  ## Dictionary
237
237
 
238
- `(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)`.
238
+ `(StrMap a)` comes from `@plylang/prelude/Data/StrMap`. The key is `Str`. The program chooses the key when it runs, and the type does not name that key. There is no literal. An empty dictionary in JavaScript is `Object.create(null)`.
239
239
 
240
240
  ```ply
241
- ~ "@plylang/prelude/Data/StrMap" emptyStrMap, insertStrMap
241
+ ~ "@plylang/prelude/Data/StrMap" StrMap, emptyStrMap, insertStrMap
242
242
 
243
243
  : ages ( -- (StrMap Num) )
244
244
  emptyStrMap "Ada" 36 insertStrMap
@@ -259,16 +259,16 @@ The order in the example is the dictionary, the key, and the value on top.
259
259
  ```
260
260
 
261
261
  ```ply
262
- ~ "@plylang/prelude/Classes/Eq" Eq, equal
262
+ ~ "@plylang/prelude/Classes/Setoid" Setoid, equal
263
263
  ~ "@plylang/prelude/Data/Num"
264
264
 
265
- : same ( Eq a => a a -- Bool )
265
+ : same ( Setoid a => a a -- Bool )
266
266
  equal
267
267
  ```
268
268
 
269
269
  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.
270
270
 
271
- 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`.
271
+ 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`, or `Array`.
272
272
 
273
273
  ```ply
274
274
  & Equal a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plylang/plylang",
3
- "version": "1.1.3",
3
+ "version": "1.2.0",
4
4
  "description": "Ply compiler",
5
5
  "license": "MIT",
6
6
  "author": "Algosail",
@@ -30,12 +30,12 @@
30
30
  "bin/native.js"
31
31
  ],
32
32
  "optionalDependencies": {
33
- "@plylang/plylang-darwin-arm64": "1.1.3",
34
- "@plylang/plylang-darwin-x64": "1.1.3",
35
- "@plylang/plylang-linux-arm64": "1.1.3",
36
- "@plylang/plylang-linux-x64": "1.1.3",
37
- "@plylang/plylang-win32-arm64": "1.1.3",
38
- "@plylang/plylang-win32-x64": "1.1.3"
33
+ "@plylang/plylang-darwin-arm64": "1.2.0",
34
+ "@plylang/plylang-darwin-x64": "1.2.0",
35
+ "@plylang/plylang-linux-arm64": "1.2.0",
36
+ "@plylang/plylang-linux-x64": "1.2.0",
37
+ "@plylang/plylang-win32-arm64": "1.2.0",
38
+ "@plylang/plylang-win32-x64": "1.2.0"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "cargo build --release",