functionalscript 0.0.401 → 0.0.404
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 +1 -1
- package/commonjs/build/module.f.cjs +1 -1
- package/{LANGUAGE.md → doc/LANGUAGE.md} +3 -1
- package/doc/predefined.md +143 -0
- package/package.json +1 -1
- package/test.f.cjs +1 -1
- package/types/btree/module.f.cjs +5 -4
- package/types/map/module.f.cjs +17 -16
- package/types/map/test.f.cjs +2 -2
- package/types/module.f.cjs +1 -1
- package/types/{string_set → stringset}/module.f.cjs +4 -1
- /package/types/{string_set → stringset}/test.f.cjs +0 -0
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ FunctionalScript is a purely functional programming language and a strict subset
|
|
|
7
7
|
- [asm.JS](https://en.wikipedia.org/wiki/Asm.js)/[WebAssembly](https://en.wikipedia.org/wiki/WebAssembly), as a subset of JavaScript.
|
|
8
8
|
- [TypeScript](https://en.wikipedia.org/wiki/TypeScript), as a superset of JavaScript.
|
|
9
9
|
|
|
10
|
-
[A brief description of FunctionalScript Programming Language](./LANGUAGE.md).
|
|
10
|
+
[A brief description of FunctionalScript Programming Language](./doc/LANGUAGE.md).
|
|
11
11
|
|
|
12
12
|
Create a new FunctionalScript repository on GitHub [here](https://github.com/functionalscript/template/generate).
|
|
13
13
|
|
|
@@ -8,7 +8,7 @@ const object = require('../../types/object/module.f.cjs')
|
|
|
8
8
|
const { fromMap } = object
|
|
9
9
|
const path = require('../path/module.f.cjs')
|
|
10
10
|
const { parseAndFind } = path
|
|
11
|
-
const stringSet = require('../../types/
|
|
11
|
+
const stringSet = require('../../types/stringset/module.f.cjs')
|
|
12
12
|
const { set: setSet, contains: setContains } = stringSet
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -139,7 +139,9 @@ Expressions could fall under these categories:
|
|
|
139
139
|
- Relations Operators: `in`, `instanceof`.
|
|
140
140
|
- Member Operators: `.`, `[]`.
|
|
141
141
|
|
|
142
|
-
**Note:** the `.` member operator has prohibited property names, such as `constructor` and `push`. To access such properties, it's recommended to use the
|
|
142
|
+
**Note:** the `.` member operator has prohibited property names, such as `constructor` and `push`. To access such properties, it's recommended to use the
|
|
143
|
+
[Object.getOwnPropertyDescriptor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor) function.
|
|
144
|
+
`[]` accepts only numbers. For example `+'0'`
|
|
143
145
|
|
|
144
146
|
## 8. Arrow Functions
|
|
145
147
|
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Predefined Object And Properties
|
|
2
|
+
|
|
3
|
+
## Global Objects
|
|
4
|
+
|
|
5
|
+
Global objects. Global objects can't be assigned to something `const r = Object`. They can only be used as namespaces `Object.getOwnProperties()`.
|
|
6
|
+
|
|
7
|
+
### Value properties
|
|
8
|
+
|
|
9
|
+
- [x] `Infinity`
|
|
10
|
+
- [x] `NaN`
|
|
11
|
+
- [x] `undefined`
|
|
12
|
+
- [ ] `globalThis`
|
|
13
|
+
|
|
14
|
+
### Function properties
|
|
15
|
+
|
|
16
|
+
- [ ] `eval`
|
|
17
|
+
- [x] `isFinite()`
|
|
18
|
+
- [x] `isNan()`
|
|
19
|
+
- [x] `parseFloat()`
|
|
20
|
+
- [x] `parseInt()`
|
|
21
|
+
- [ ] `encodeURI()`
|
|
22
|
+
- [ ] `encodeURIComponent()`
|
|
23
|
+
- [ ] `decodeURI()`
|
|
24
|
+
- [ ] `decodeURIComponent()`
|
|
25
|
+
|
|
26
|
+
### Fundamental objects
|
|
27
|
+
|
|
28
|
+
- [x] `Object`. For example `Object.entries`, `Object.fromEntries`.
|
|
29
|
+
- [ ] `Function`
|
|
30
|
+
- [ ] `Boolean`
|
|
31
|
+
- [ ] `Symbol`
|
|
32
|
+
|
|
33
|
+
### Error objects
|
|
34
|
+
|
|
35
|
+
- [ ] `Number`
|
|
36
|
+
- [ ] `BigInt`
|
|
37
|
+
- [ ] `Math`
|
|
38
|
+
- [ ] `Date`
|
|
39
|
+
|
|
40
|
+
### Text processing
|
|
41
|
+
|
|
42
|
+
- [ ] `String`
|
|
43
|
+
- [ ] `RegExp`
|
|
44
|
+
|
|
45
|
+
### Indexed collections:
|
|
46
|
+
|
|
47
|
+
- [x] `Array`. For example `x instanceof Array`
|
|
48
|
+
- [ ] `Int8Array`
|
|
49
|
+
- [ ] `UInt8Array`
|
|
50
|
+
- [ ] `UInt8ClampedArray`
|
|
51
|
+
- [ ] `Int16Array`
|
|
52
|
+
- [ ] `UInt16Array`
|
|
53
|
+
- [ ] `Int32Array`
|
|
54
|
+
- [ ] `UInt32Array`
|
|
55
|
+
- [ ] `Float32Array`
|
|
56
|
+
- [ ] `Float64Array`
|
|
57
|
+
- [ ] `BigInt64Array`
|
|
58
|
+
- [ ] `BigUint64Array`
|
|
59
|
+
|
|
60
|
+
### Keyed collections:
|
|
61
|
+
|
|
62
|
+
- [ ] `Map`
|
|
63
|
+
- [ ] `Set`
|
|
64
|
+
- [ ] `WeakMap`
|
|
65
|
+
- [ ] `WeakSet`
|
|
66
|
+
|
|
67
|
+
### Structured data:
|
|
68
|
+
|
|
69
|
+
- [ ] `ArrayBuffer`
|
|
70
|
+
- [ ] `SharedArrayBuffer`
|
|
71
|
+
- [ ] `Atomics`
|
|
72
|
+
- [ ] `DataView`
|
|
73
|
+
- [x] `JSON`. For example `JSON.stringify`
|
|
74
|
+
|
|
75
|
+
### Control abstraction objects
|
|
76
|
+
|
|
77
|
+
- [ ] `Promise`
|
|
78
|
+
- [ ] `Generator`
|
|
79
|
+
- [ ] `GeneratorFunction`
|
|
80
|
+
- [ ] `AsyncFunction`
|
|
81
|
+
- [ ] `AsyncGeneratorFunction`
|
|
82
|
+
|
|
83
|
+
### Reflection
|
|
84
|
+
|
|
85
|
+
- [ ] `Reflect`
|
|
86
|
+
- [ ] `Proxy`
|
|
87
|
+
|
|
88
|
+
### Internalization
|
|
89
|
+
|
|
90
|
+
- [ ] `Intl`
|
|
91
|
+
|
|
92
|
+
### WebAssembly
|
|
93
|
+
|
|
94
|
+
- [ ] `WebAssembly`
|
|
95
|
+
- [ ] `WebAssembly.Module`
|
|
96
|
+
- [ ] `WebAssembly.Instance`
|
|
97
|
+
- [ ] `WebAssembly.Memory`
|
|
98
|
+
- [ ] `WebAssembly.Table`
|
|
99
|
+
- [ ] `WebAssembly.CompileError`
|
|
100
|
+
- [ ] `WebAssembly.LinkError`
|
|
101
|
+
- [ ] `WebAssembly.RuntimeError`
|
|
102
|
+
|
|
103
|
+
## Prohibited Properties
|
|
104
|
+
|
|
105
|
+
Allowed types:
|
|
106
|
+
|
|
107
|
+
- object `{}`
|
|
108
|
+
- `null` has no properties
|
|
109
|
+
- array `[]`
|
|
110
|
+
- number `-3`
|
|
111
|
+
- bigint `42n`
|
|
112
|
+
- string `"xx"`
|
|
113
|
+
- boolean `true`
|
|
114
|
+
- function `x => x * x`
|
|
115
|
+
- `undefined` has no properties
|
|
116
|
+
|
|
117
|
+
### Object
|
|
118
|
+
|
|
119
|
+
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
120
|
+
|
|
121
|
+
- [ ] ! `constructor`. The property can create a new function. For example
|
|
122
|
+
```js
|
|
123
|
+
const f = (() => undefined).constructor('a', 'return a * a')
|
|
124
|
+
```
|
|
125
|
+
- [ ] deprecated `__proto__`
|
|
126
|
+
- [ ] ! deprecated `__defineGetter__`. The property can mutate an object.
|
|
127
|
+
- [ ] ! deprecated `__defineSetter__`. The property can mutate an object.
|
|
128
|
+
- [ ] deprecated `__lookupGetter__`
|
|
129
|
+
- [ ] deprecated `__lookupSetter__`
|
|
130
|
+
|
|
131
|
+
### Array
|
|
132
|
+
|
|
133
|
+
These properties can mutate an array:
|
|
134
|
+
|
|
135
|
+
- [ ] ! `copyWithin`.
|
|
136
|
+
- [ ] ! `fill`
|
|
137
|
+
- [ ] ! `pop`
|
|
138
|
+
- [ ] ! `push`
|
|
139
|
+
- [ ] ! `reverse`
|
|
140
|
+
- [ ] ! `shift`
|
|
141
|
+
- [ ] ! `sort`
|
|
142
|
+
- [ ] ! `splice`
|
|
143
|
+
- [ ] ! `unshift`
|
package/package.json
CHANGED
package/test.f.cjs
CHANGED
|
@@ -16,7 +16,7 @@ require('./commonjs/package/test.f.cjs')
|
|
|
16
16
|
require('./commonjs/path/test.f.cjs')
|
|
17
17
|
require('./types/function/test.f.cjs')
|
|
18
18
|
require('./types/function/compare/test.f.cjs')
|
|
19
|
-
require('./types/
|
|
19
|
+
require('./types/stringset/test.f.cjs')
|
|
20
20
|
require('./types/option/test.f.cjs')
|
|
21
21
|
require('./commonjs/build/test.f.cjs')
|
|
22
22
|
require('./types/range/test.f.cjs')
|
package/types/btree/module.f.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const list = require('../list/module.f.cjs')
|
|
2
|
-
const
|
|
2
|
+
const { flat } = list
|
|
3
|
+
const { map } = require('../option/module.f.cjs')
|
|
3
4
|
const _ = require('./types/module.f.cjs')
|
|
4
5
|
|
|
5
6
|
/** @type {<T>(node: _.Node<T>) => list.Thunk<T>} */
|
|
@@ -7,14 +8,14 @@ const nodeValues = node => () => {
|
|
|
7
8
|
switch (node.length) {
|
|
8
9
|
case 1: case 2: { return node }
|
|
9
10
|
case 3: {
|
|
10
|
-
return
|
|
11
|
+
return flat([
|
|
11
12
|
nodeValues(node[0]),
|
|
12
13
|
[node[1]],
|
|
13
14
|
nodeValues(node[2])
|
|
14
15
|
])
|
|
15
16
|
}
|
|
16
17
|
default: {
|
|
17
|
-
return
|
|
18
|
+
return flat([
|
|
18
19
|
nodeValues(node[0]),
|
|
19
20
|
[node[1]],
|
|
20
21
|
nodeValues(node[2]),
|
|
@@ -26,7 +27,7 @@ const nodeValues = node => () => {
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
/** @type {<T>(tree: _.Tree<T>) => list.List<T>} */
|
|
29
|
-
const values =
|
|
30
|
+
const values = map(nodeValues)
|
|
30
31
|
|
|
31
32
|
module.exports = {
|
|
32
33
|
/** @readonly */
|
package/types/map/module.f.cjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
const btreeTypes = require('../btree/types/module.f.cjs')
|
|
2
|
-
const {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
const {
|
|
3
|
+
values,
|
|
4
|
+
find: { value, find },
|
|
5
|
+
set: { set },
|
|
6
|
+
remove: { remove: btreeRemove }
|
|
7
|
+
} = require("../btree/module.f.cjs")
|
|
6
8
|
const compare = require('../function/compare/module.f.cjs')
|
|
7
9
|
const { cmp } = require('../string/module.f.cjs')
|
|
8
10
|
const list = require('../list/module.f.cjs')
|
|
9
11
|
const { fold } = list
|
|
10
|
-
const { remove: btreeRemove } = require('../btree/remove/module.f.cjs')
|
|
11
12
|
const operator = require('../function/operator/module.f.cjs')
|
|
12
13
|
|
|
13
14
|
/** @typedef {compare.Sign} Sign */
|
|
@@ -37,26 +38,26 @@ const at = name => map => {
|
|
|
37
38
|
return result === undefined ? undefined : result[1]
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
/** @type {<T>(
|
|
41
|
-
const
|
|
41
|
+
/** @type {<T>(reduce: operator.Reduce<T>) => (entry: Entry<T>) => (map: Map<T>) => Map<T>} */
|
|
42
|
+
const setReduceEntry = reduce => entry => set(keyCmp(entry[0]))(old => old === undefined ? entry : [old[0], reduce(old[1])(entry[1])])
|
|
42
43
|
|
|
43
|
-
/** @type {<T>(
|
|
44
|
-
const
|
|
44
|
+
/** @type {<T>(reduce: operator.Reduce<T>) => (name: string) => (value: T) => (map: Map<T>) => Map<T>} */
|
|
45
|
+
const setReduce = reduce => name => value => setReduceEntry(reduce)([name, value])
|
|
46
|
+
|
|
47
|
+
/** @type {<T>(a: T) => (b: T) => T} */
|
|
48
|
+
const replace = () => b => b
|
|
45
49
|
|
|
46
50
|
/** @type {(name: string) => <T>(value: T) => (map: Map<T>) => Map<T>} */
|
|
47
|
-
const setReplace = name => value =>
|
|
51
|
+
const setReplace = name => value => setReduceEntry(replace)([name, value])
|
|
48
52
|
|
|
49
53
|
/** @type {<T>(map: Map<T>) => list.List<Entry<T>>} */
|
|
50
54
|
const entries = values
|
|
51
55
|
|
|
52
|
-
/** @type {<T>(a: T) => (b: T) => T} */
|
|
53
|
-
const replace = () => b => b
|
|
54
|
-
|
|
55
56
|
/** @type {<T>(entries: list.List<Entry<T>>) => Map<T>} */
|
|
56
|
-
const fromEntries = fold(
|
|
57
|
+
const fromEntries = fold(setReduceEntry(replace))(undefined)
|
|
57
58
|
|
|
58
59
|
/** @type {(name: string) => <T>(map: Map<T>) => Map<T>} */
|
|
59
|
-
const remove =
|
|
60
|
+
const remove = name => btreeRemove(keyCmp(name))
|
|
60
61
|
|
|
61
62
|
module.exports = {
|
|
62
63
|
/** @readonly */
|
|
@@ -64,7 +65,7 @@ module.exports = {
|
|
|
64
65
|
/** @readonly */
|
|
65
66
|
at,
|
|
66
67
|
/** @readonly */
|
|
67
|
-
|
|
68
|
+
setReduce,
|
|
68
69
|
/** @readonly */
|
|
69
70
|
setReplace,
|
|
70
71
|
/** @readonly */
|
package/types/map/test.f.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { at, setReplace,
|
|
1
|
+
const { at, setReplace, setReduce, empty, entries, remove } = require('./module.f.cjs')
|
|
2
2
|
const seq = require('../list/module.f.cjs')
|
|
3
3
|
|
|
4
4
|
{
|
|
@@ -41,7 +41,7 @@ const seq = require('../list/module.f.cjs')
|
|
|
41
41
|
m = remove('Hello world!')(m)
|
|
42
42
|
if (at('Hello world!')(m) !== undefined) { throw m }
|
|
43
43
|
|
|
44
|
-
m =
|
|
44
|
+
m = setReduce(a => b => a + b)('a')(43)(m)
|
|
45
45
|
if (at('a')(m) !== 44) { throw 'error' }
|
|
46
46
|
}
|
|
47
47
|
|
package/types/module.f.cjs
CHANGED
|
@@ -16,7 +16,7 @@ module.exports = {
|
|
|
16
16
|
/** @readonly */
|
|
17
17
|
result: require('./result/module.f.cjs'),
|
|
18
18
|
/** @readonly */
|
|
19
|
-
|
|
19
|
+
stringset: require('./stringset/module.f.cjs'),
|
|
20
20
|
/** @readonly */
|
|
21
21
|
bigint: require('./bigint/module.f.cjs'),
|
|
22
22
|
/** @readonly */
|
|
@@ -15,7 +15,10 @@ const { compose } = require('../function/module.f.cjs')
|
|
|
15
15
|
/** @typedef {btTypes.Tree<string>} StringSet */
|
|
16
16
|
|
|
17
17
|
/** @type {(value: string) => (set: StringSet) => boolean} */
|
|
18
|
-
const contains = value =>
|
|
18
|
+
const contains = value => {
|
|
19
|
+
const f = find(cmp(value))
|
|
20
|
+
return s => s !== undefined && isFound(f(s).first)
|
|
21
|
+
}
|
|
19
22
|
|
|
20
23
|
/** @type {(value: string) => (s: StringSet) => StringSet} */
|
|
21
24
|
const set = value => btreeSet(cmp(value))(() => value)
|
|
File without changes
|