functionalscript 0.0.250 → 0.0.258

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 +83 -113
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,158 +1,128 @@
1
1
  # FunctionalScript
2
2
 
3
- FunctionalScript is a pure functional programming language and a strict subset of [ECMAScript](https://en.wikipedia.org/wiki/ECMAScript)/[JavaScript](https://en.wikipedia.org/wiki/JavaScript). It's inspired by
3
+ FunctionalScript is a pure functional programming language and a strict subset of
4
+ [ECMAScript](https://en.wikipedia.org/wiki/ECMAScript)/[JavaScript](https://en.wikipedia.org/wiki/JavaScript). It's inspired by
4
5
 
5
- - [JSON](https://en.wikipedia.org/wiki/JSON), as a subset of JavaScript; FunctionalScript is a superset of JSON.
6
- - [asm.JS](https://en.wikipedia.org/wiki/Asm.js)/[WebAssembly](https://en.wikipedia.org/wiki/WebAssembly), as a subset of JavaScript;
6
+ - [JSON](https://en.wikipedia.org/wiki/JSON), as a subset of JavaScript. JSON is also a subset of FunctionalScript.
7
+ - [asm.JS](https://en.wikipedia.org/wiki/Asm.js)/[WebAssembly](https://en.wikipedia.org/wiki/WebAssembly), as a subset of JavaScript.
7
8
  - [TypeScript](https://en.wikipedia.org/wiki/TypeScript), as a superset of JavaScript.
8
9
 
9
10
  Try FunctionalScript [here](https://functionalscript.com/).
10
11
 
11
12
  Create a new FunctionalScript repository on GitHub [here](https://github.com/functionalscript/template/generate).
12
13
 
13
- One of the main challenges is how to make a pure functional language when ES6 TCO is not supported by Chrome and Firefox.
14
- A workaround for this problem is to use `let` for renaming objects.
15
-
16
- ## Install FunctionalScript As A Library
14
+ To install this repository as a library use:
17
15
 
18
16
  ```
19
17
  npm install -S github:functionalscript/functionalscript
20
18
  ```
21
19
 
22
- ## JSON
20
+ ## 1. Design Principles
23
21
 
24
- ```js
25
- jsonFile = expression
26
- expression = primitive | array | objects
27
- primitive = 'true' | 'false' | 'null' | number | string
28
- array = '[' (() | items) ']'
29
- items = expression (() | ',' items)
30
- object = '{' (() | properties) '}'
31
- properties = propertyId ':' expression (() | ',' properties)
32
- propertyId = string
33
- ```
22
+ In FunctionalScript:
34
23
 
35
- ## Stage 0
24
+ - Any module is a valid JavaScript module
25
+ - A module can't depend on non FunctionalScript module.
26
+ - A module can contain only pure functional statements. There are no exceptions to this rule, such as `unsafe` code in Rust or C#.
27
+ - It also has no standard library, only a safe subset of standard JavaScript API is allowed.
36
28
 
37
- This stage can be used as an intermediate-code for VMs.
29
+ ## 2. Outlines
38
30
 
39
- ```js
40
- fjsFile = expression
41
- expression = primitive | array | object | func | id | propertyAccessor
42
- func = ('()' | id) '=>' body
43
- body = '{' statements 'return' expression ';' '}'
44
- statements = () | (statement statements)
45
- statement = decl | ifStatement
46
- decl = `const` id `=` expression `;`
47
- ifStatement = `if` `(` expression `)` body
48
- propertyAccessor = expression `[` expression `]`
49
- call = expression `(` ( expression | ()) `)`
50
- ```
31
+ ### 2.1. Module Ecosystem
51
32
 
52
- ### Stage 0.1. Node.js
33
+ FunctionalScript uses Common.JS conventions as a module ecosystem. For example,
53
34
 
54
35
  ```js
55
- nodeFile = statements 'module.exports' '=' expression ';'
36
+ const thirdPartyModule = require('third-party-package/module')
37
+
38
+ const result = thirdPartyModule.someFunction('hello')
56
39
  ```
57
40
 
58
- ### Stage 0.2.
41
+ ### 2.2. Packages
59
42
 
60
- #### Operators
43
+ FunctionalScript uses a `package.json` file to define a package. This file is compatible with Node.js `package.json`.
44
+ The prefered way to refence dependencies is to use a GitHub URL. An example of dependencies in a `package.json` file:
61
45
 
62
- ```js
63
- expression = ... | 'undefined' | groupingOperator | binaryOperatorExpression | unaryOperator | conditionalOperator
64
- groupingOperator = '(' expression ')'
65
- binaryOperatorExpression = expression binaryOperator expression
66
- binaryOperator = comparisonOperator | arithmeticOperator | bitwiseOperator | logicalOperators | '??'
67
- comparisonBinaryOperator = '===' | '!==' | '>' | '<' | '>=' | '<='
68
- arithmeticBinaryOperator = '+' | '-' | '*' | '/' | '%' | '**'
69
- bitwiseBinaryOperator = '&' | '|' | '^' | '<<' | '>>' | '>>>'
70
- logicalBinaryOperator = '&&' | '||'
71
- unaryOperator = '-' | '~' | '!'
46
+ ```json
47
+ {
48
+ ...
49
+ "dependencies": {
50
+ "third-party-package": "github:exampleorg/thirdpartypackage"
51
+ }
52
+ ...
53
+ }
72
54
  ```
73
55
 
74
- Note: the syntax should be fixed to reflect operator precedents.
75
-
76
- No `==`, `!=`, `=...` operators.
56
+ ### 2.2. Module Structure
77
57
 
78
- #### Function Expression
58
+ A module is a file with the `.js` extention. It contains three parts: references to other modules, definitions, and exports. For example
79
59
 
60
+ `./first.js`
80
61
  ```js
81
- func = ('()' | id) '=>' (('{' statements 'return' expression ';' '}') | expression)
62
+ // 1. references
63
+ const math = require('math')
64
+
65
+ // 2. definitions
66
+ const myConst = 42
67
+ const addition = a => b => a + b
68
+ const add42 = addition(42)
69
+ const _10digitsOfPi = math.calculatePi(10)
70
+
71
+ // 3. exports
72
+ module.exports = {
73
+ addition,
74
+ add42,
75
+ _10digitsOfPi,
76
+ }
82
77
  ```
83
78
 
84
- #### PropertyAccessor
85
-
79
+ `./second.js`
86
80
  ```js
87
- propertyAccessor = expression (('[' expression ']') | ('.' id))
81
+ // 1. references
82
+ const first = require('./first.js')
83
+
84
+ const _42plus7 = first.add42(7)
88
85
  ```
89
86
 
87
+ ### 2.3. References To Other Modules
88
+
89
+ The format of references is `const ANYNAME = require('PATH_TO_A_MODULE')`. For example
90
+
90
91
  ```js
91
- propertyId = string | id
92
+ const math = require('math')
93
+ const algebra = require('math/algebra')
94
+ const localFile = require('../some-directory/some-file.js')
92
95
  ```
93
96
 
94
- #### BigInt
97
+ ### 2.4. Definitions
95
98
 
96
- For example `42n`.
97
-
98
- #### Additional Operators
99
+ The format of defintions is `const NAME = EXPRESSION`, where the `EXPRESSION` is a subset of [JavaScript expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators).
99
100
 
100
101
  ```js
101
- typeOfOperator = 'typeof' expression
102
- inOperator = expression 'in' expression
102
+ const myConst = 42
103
+ const functionDouble = a => a * 2
104
+ const structure = { name: "John", surname: "Smith" }
105
+ const array = [1, 2, 3]
106
+ const nestedStructure = {
107
+ address: undefined,
108
+ serialNumber: "123-45-78",
109
+ sum: 14 + myConst + functionDouble(4),
110
+ moreInfo: {
111
+ name: "Ivan",
112
+ surname: "Terrible",
113
+ }
114
+ }
103
115
  ```
104
116
 
105
- ### Stage 0.3. Syntax sugar
106
-
107
- Hex, binary and octal literals
108
- Functions with multiple parameters.
109
- Spread syntax. For example `...object`.
110
- Destructing assignments. For example `const {a,b} = exp;`, `const [a, b] = exp`.
111
- Property Id expression `{ [exp]: exp }`.
112
- Allow no semicolons.
113
- Optional comma in arrays and objects.
114
- Template literals ``const r= `onst r = ${exp}`;``.
115
- An `if` statement `if (exp) { ... return exp }`
116
- Multiline strings
117
+ ### 2.5. Exports
118
+
119
+ The format of exports is `module.exports = { A_LIST_OF_EXPORTED_DEFINITIONS }`. There should be only one `module.exports` at
120
+ the end of a FunctionalScript file. For example
121
+
117
122
  ```js
118
- 'sss\
119
- wwww'
123
+ module.exports = {
124
+ nestedStructure,
125
+ array,
126
+ structure,
127
+ }
120
128
  ```
121
- Regular expressions.
122
-
123
- ## Stage 1
124
-
125
- Typing using [JSDoc](https://jsdoc.app/) and TypeScript types.
126
-
127
- ## Stage 2
128
-
129
- Mutable types with exclusive ownership (similar to Rust mutability).
130
-
131
- - `let`, `for`, `while` etc.
132
- Note: `let` can work as an object name reuse.
133
- In this case, `let` objects can't be used in nested functions. It means we can't reference `let` object.
134
- ```js
135
- let x = 5 // ok
136
- f(x)
137
- x = 'hello!' // ok
138
- f(x)
139
- const r = () => {
140
- return x // compilation error
141
- }
142
- ```
143
- Translated into
144
- ```js
145
- const x0 = 5
146
- f(x0)
147
- const x1 = 'hello!'
148
- f(x1)
149
- ```
150
- - Generators `function*(){ ... yield ... }`.
151
- - Async `async () => f(await exp())`.
152
- - hopefully, we will have [ES pipe operator](https://tc39.es/proposal-pipeline-operator/) at this time.
153
- - [pattern matching](https://github.com/tc39/proposal-pattern-matching)
154
-
155
- Controversial ideas:
156
-
157
- - Import and export `import x from "..."`, `export const x = ...`, `export default = ` e.t.c. This may break `new Function` runners.
158
- - Functional-TypeScript as a subset of TypeScript. Note: FunctionalScript doesn't require an additional build step in contrast to TypeScript.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.250",
3
+ "version": "0.0.258",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {