functionalscript 0.0.403 → 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 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
 
@@ -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 [Object.getOwnPropertyDescriptor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor) function.
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.403",
3
+ "version": "0.0.404",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
@@ -1,5 +1,6 @@
1
1
  const list = require('../list/module.f.cjs')
2
- const option = require('../option/module.f.cjs')
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 list.flat([
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 list.flat([
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 = option.map(nodeValues)
30
+ const values = map(nodeValues)
30
31
 
31
32
  module.exports = {
32
33
  /** @readonly */
@@ -1,13 +1,14 @@
1
1
  const btreeTypes = require('../btree/types/module.f.cjs')
2
- const { values } = require("../btree/module.f.cjs")
3
- const btreeFind = require('../btree/find/module.f.cjs')
4
- const { value, find } = btreeFind
5
- const btreeSet = require('../btree/set/module.f.cjs').set
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>(o: operator.Reduce<T>) => (entry: Entry<T>) => (map: Map<T>) => Map<T>} */
41
- const setUpdateEntry = o => entry => btreeSet(keyCmp(entry[0]))(old => old === undefined ? entry : [old[0], o(old[1])(entry[1])])
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>(o: operator.Reduce<T>) => (name: string) => (value: T) => (map: Map<T>) => Map<T>} */
44
- const setReduce = o => name => value => setUpdateEntry(o)([name, value])
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 => setUpdateEntry(replace)([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(setUpdateEntry(replace))(undefined)
57
+ const fromEntries = fold(setReduceEntry(replace))(undefined)
57
58
 
58
59
  /** @type {(name: string) => <T>(map: Map<T>) => Map<T>} */
59
- const remove = name => btreeRemove(keyCmp(name))
60
+ const remove = name => btreeRemove(keyCmp(name))
60
61
 
61
62
  module.exports = {
62
63
  /** @readonly */