functionalscript 0.0.258 → 0.0.264

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 +72 -19
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -3,34 +3,28 @@
3
3
  FunctionalScript is a pure functional programming language and a strict subset of
4
4
  [ECMAScript](https://en.wikipedia.org/wiki/ECMAScript)/[JavaScript](https://en.wikipedia.org/wiki/JavaScript). It's inspired by
5
5
 
6
- - [JSON](https://en.wikipedia.org/wiki/JSON), as a subset of JavaScript. JSON is also a subset of FunctionalScript.
6
+ - [JSON](https://en.wikipedia.org/wiki/JSON) as a subset of JavaScript. JSON is also a subset of FunctionalScript.
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
- Try FunctionalScript [here](https://functionalscript.com/).
11
-
12
10
  Create a new FunctionalScript repository on GitHub [here](https://github.com/functionalscript/template/generate).
13
11
 
14
- To install this repository as a library use:
15
-
16
- ```
17
- npm install -S github:functionalscript/functionalscript
18
- ```
12
+ Try FunctionalScript [here](https://functionalscript.com/).
19
13
 
20
14
  ## 1. Design Principles
21
15
 
22
16
  In FunctionalScript:
23
17
 
24
18
  - Any module is a valid JavaScript module
19
+ - Code should not have [side-effects](https://en.wikipedia.org/wiki/Side_effect_(computer_science)). Any JavaScript statement, expression, or function which has a side effect is not allowed in FunctionalScript. There are no exceptions to this rule, such as `unsafe` code which can be found in Rust, C#, and other languages.
25
20
  - 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.
21
+ - It also has no standard library, only a safe subset of standard JavaScript API can be used without referencing other modules.
28
22
 
29
23
  ## 2. Outlines
30
24
 
31
25
  ### 2.1. Module Ecosystem
32
26
 
33
- FunctionalScript uses Common.JS conventions as a module ecosystem. For example,
27
+ FunctionalScript uses [CommonJS](https://en.wikipedia.org/wiki/CommonJS) conventions as a module ecosystem. For example,
34
28
 
35
29
  ```js
36
30
  const thirdPartyModule = require('third-party-package/module')
@@ -40,8 +34,8 @@ const result = thirdPartyModule.someFunction('hello')
40
34
 
41
35
  ### 2.2. Packages
42
36
 
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:
37
+ FunctionalScript uses a `package.json` file to define a package. This file is compatible with [Node.js `package.json`](https://nodejs.org/en/knowledge/getting-started/npm/what-is-the-file-package-json/).
38
+ The prefered way to refence dependencies is to use a GitHub URL. These dependencies in a `package.json` file could look like this,
45
39
 
46
40
  ```json
47
41
  {
@@ -53,7 +47,13 @@ The prefered way to refence dependencies is to use a GitHub URL. An example of d
53
47
  }
54
48
  ```
55
49
 
56
- ### 2.2. Module Structure
50
+ **Note:** this repository is also a FunctionalScript package, and it can be used as a library. To install this package, use
51
+
52
+ ```
53
+ npm install -S github:functionalscript/functionalscript
54
+ ```
55
+
56
+ ### 2.3. Module Structure
57
57
 
58
58
  A module is a file with the `.js` extention. It contains three parts: references to other modules, definitions, and exports. For example
59
59
 
@@ -64,6 +64,7 @@ const math = require('math')
64
64
 
65
65
  // 2. definitions
66
66
  const myConst = 42
67
+ // addition(a)(b) = a + b
67
68
  const addition = a => b => a + b
68
69
  const add42 = addition(42)
69
70
  const _10digitsOfPi = math.calculatePi(10)
@@ -84,9 +85,9 @@ const first = require('./first.js')
84
85
  const _42plus7 = first.add42(7)
85
86
  ```
86
87
 
87
- ### 2.3. References To Other Modules
88
+ ### 2.4. References To Other Modules
88
89
 
89
- The format of references is `const ANYNAME = require('PATH_TO_A_MODULE')`. For example
90
+ The format of references is `const ANYNAME = require('PATH_TO_A_MODULE')`. For example,
90
91
 
91
92
  ```js
92
93
  const math = require('math')
@@ -94,7 +95,7 @@ const algebra = require('math/algebra')
94
95
  const localFile = require('../some-directory/some-file.js')
95
96
  ```
96
97
 
97
- ### 2.4. Definitions
98
+ ### 2.5. Definitions
98
99
 
99
100
  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).
100
101
 
@@ -114,10 +115,12 @@ const nestedStructure = {
114
115
  }
115
116
  ```
116
117
 
117
- ### 2.5. Exports
118
+ See [3. Expressions](#3-Expressions).
119
+
120
+ ### 2.6. Exports
118
121
 
119
122
  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
123
+ the end of a FunctionalScript file. For example,
121
124
 
122
125
  ```js
123
126
  module.exports = {
@@ -126,3 +129,53 @@ module.exports = {
126
129
  structure,
127
130
  }
128
131
  ```
132
+
133
+ ## 3. Expressions
134
+
135
+ Expressions could fall under these categories:
136
+
137
+ - Literals:
138
+ - Number Literals, e.g. `0`, `3.14`, `4e8`
139
+ - Boolean Literals: `true` or `false`
140
+ - A `null` Literal
141
+ - An `undefined` Literal
142
+ - String Literals, e.g. `"Hello world!"`
143
+ - Complex Structures
144
+ - Arrays, e.g. `[2, 5]`
145
+ - Objects, e.g. `{ a: "Hello", b: "world!" }`
146
+ - Arrow functions, e.g. `x => x * 2`
147
+ - Operators
148
+ - Comparison Operators: `===`, `!==`, `>`, `>=`, `<`, `<=`
149
+ - Arithmetic Operators: `+`, `-`, `*`, `/`, `%`, `**`
150
+ - Bitwise Operators: `&`, `|`, `^`, `~`, `<<`, `>>`, `>>>`
151
+ - Logical Operators: `&&`, `||`, `!`, `??`
152
+ - Conditional Operator, e.g. `condition ? val1 : val2`
153
+ - Template Literals, e.g. `string ${expression}`
154
+ - `typeof`
155
+ - Relations Operators: `in`, `instanceof`.
156
+ - Member Operators: `.`, `[]`.
157
+
158
+ Note: the `.` member operator has prohibitted property names, such as `constructor` and `push`. To access such properties, it's recommeded to use the `Object.getPropertyDescriptor` function.
159
+
160
+ ## 4. Arrow Functions
161
+
162
+ An arrow function is also known as [a lambda function](https://en.wikipedia.org/wiki/Anonymous_function).
163
+ The format of an arrow function is `ARGUMENT_NAME => FUNCTION_BODY`. An arrow function must have either a single argument or no arguments at all. For example
164
+
165
+ ```js
166
+ x => x * 2
167
+ a => a + 4
168
+ s => `template literal ${s}`
169
+ () => 'hello' // an arrow function with no arguments
170
+ ```
171
+
172
+ A function body is either an expression or a block statement. A block statement format is `{ A_LIST_OF_STATEMENTS }`. For example
173
+
174
+ ```js
175
+ // a function with one argument and a block statement
176
+ const f = x => {
177
+ const a = 2 + x
178
+ const r = a + 4
179
+ return r
180
+ }
181
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.258",
3
+ "version": "0.0.264",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {