force-lang 0.0.13 → 0.1.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.
- package/.eslintrc.cjs +54 -0
- package/README.md +19 -14
- package/doc/force-lang.1 +33 -35
- package/doc/force.1 +33 -35
- package/examples/cli-args.j +2 -2
- package/examples/nodejs-js-interaction.j +2 -1
- package/examples/testjs.js +2 -2
- package/examples/web_scrap.j +3 -0
- package/force +88 -88
- package/force-lang-0.1.0.tgz +0 -0
- package/package.json +17 -15
- package/src/BKlib.j +51 -0
- package/src/env.js +221 -162
- package/src/error.js +71 -59
- package/src/eval.js +454 -319
- package/src/force-lang.js +38 -34
- package/src/lib.j +11 -0
- package/src/load-file.js +62 -62
- package/src/native_lib.js +1702 -1458
- package/src/obj_utils.js +20 -18
- package/src/read.js +431 -309
- package/src/stack.js +113 -72
- package/src/token-stream.js +34 -28
- package/tests/pippo.j +1 -1
- package/tests/test-js-require.js +13 -9
- package/tests/test.j +1 -1
- package/tests/unit_tests.j +1 -1
- package/.eslintrc.js +0 -60
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
env: {
|
|
4
|
+
es6: true,
|
|
5
|
+
node: true,
|
|
6
|
+
},
|
|
7
|
+
parserOptions: {
|
|
8
|
+
ecmaVersion: 'latest',
|
|
9
|
+
sourceType: 'module',
|
|
10
|
+
},
|
|
11
|
+
extends: ['airbnb-base', 'prettier'],
|
|
12
|
+
plugins: ['prettier'],
|
|
13
|
+
rules: {
|
|
14
|
+
'prettier/prettier': [
|
|
15
|
+
'error',
|
|
16
|
+
{
|
|
17
|
+
printWidth: 120,
|
|
18
|
+
tabWidth: 2, // reformat to 2 eventually
|
|
19
|
+
useTabs: false, // default
|
|
20
|
+
semi: true, // default
|
|
21
|
+
singleQuote: true,
|
|
22
|
+
trailingComma: 'all',
|
|
23
|
+
bracketSpacing: true, // default
|
|
24
|
+
jsxBracketSameLine: true,
|
|
25
|
+
arrowParens: 'avoid', // default
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
indent: ['warn', 2],
|
|
29
|
+
camelcase: [0, { properties: 'never' }],
|
|
30
|
+
eqeqeq: ['error', 'always'],
|
|
31
|
+
curly: ['error', 'all'],
|
|
32
|
+
'no-prototype-builtins': 0, // refactor and enable
|
|
33
|
+
'consistent-return': 0, // refactor and enable
|
|
34
|
+
'no-param-reassign': 0, // refactor and enable
|
|
35
|
+
'no-unsafe-finally': 0, // refactor and enable
|
|
36
|
+
'no-use-before-define': 0, // refactor and enable
|
|
37
|
+
'import/no-unresolved': 0, // some linter import errors
|
|
38
|
+
'no-underscore-dangle': ['off'],
|
|
39
|
+
'no-undef': 0,
|
|
40
|
+
'class-methods-use-this': 0, // refactor and enable
|
|
41
|
+
'max-len': ['warn', 1000], // usage of SVG
|
|
42
|
+
'no-restricted-syntax': [
|
|
43
|
+
'error',
|
|
44
|
+
{
|
|
45
|
+
selector: 'LabeledStatement',
|
|
46
|
+
message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
selector: 'WithStatement',
|
|
50
|
+
message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
};
|
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ Options:
|
|
|
25
25
|
```text
|
|
26
26
|
$ cat example.j
|
|
27
27
|
|
|
28
|
-
#!/usr/
|
|
28
|
+
#!/usr/bin/env force
|
|
29
29
|
|
|
30
30
|
2 2 + .
|
|
31
31
|
```
|
|
@@ -37,27 +37,22 @@ echo "2 2 + ."|force
|
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
39
|
$ npm i force-lang
|
|
40
|
+
|
|
41
|
+
# or
|
|
42
|
+
|
|
43
|
+
npm install git+https://github.com/elboza/force-lang#master
|
|
40
44
|
```
|
|
41
45
|
|
|
42
46
|
```javascript
|
|
43
|
-
|
|
47
|
+
import force from 'force-lang';
|
|
44
48
|
|
|
45
49
|
var x = '2 2 + .';
|
|
46
50
|
|
|
47
51
|
(async function(){
|
|
48
52
|
await force.load_lib();
|
|
49
|
-
force.exec(x);
|
|
53
|
+
await force.exec(x);
|
|
50
54
|
})();
|
|
51
55
|
```
|
|
52
|
-
or using sync functions:
|
|
53
|
-
```javascript
|
|
54
|
-
const force = require ('force-lang');
|
|
55
|
-
|
|
56
|
-
var x = '2 2 + .';
|
|
57
|
-
|
|
58
|
-
force.load_lib_sync();
|
|
59
|
-
force.exec(x);
|
|
60
|
-
```
|
|
61
56
|
## repl multiline
|
|
62
57
|
in the force-lang repl `force -i` you can input multiline by appending `\` (backslash) at the end of the current line before enter
|
|
63
58
|
|
|
@@ -142,6 +137,7 @@ v variable name
|
|
|
142
137
|
```text
|
|
143
138
|
bye \ ( -- )
|
|
144
139
|
noop \ ( -- )
|
|
140
|
+
nop \ ( -- )
|
|
145
141
|
.s \ ( -- )
|
|
146
142
|
.e \ ( -- )
|
|
147
143
|
words \ ( -- )
|
|
@@ -150,6 +146,8 @@ emit \ ( n -- )
|
|
|
150
146
|
.? \ ( x -- )
|
|
151
147
|
! \ ( x v -- )
|
|
152
148
|
@ \ ( v -- x )
|
|
149
|
+
>r \ ( x -- )
|
|
150
|
+
r> \ ( -- x )
|
|
153
151
|
not \ ( b -- b )
|
|
154
152
|
and \ ( b -- b )
|
|
155
153
|
or \ ( b -- b )
|
|
@@ -182,12 +180,17 @@ a:! \ ( a n x -- a )
|
|
|
182
180
|
m:@ \ ( o s -- x )
|
|
183
181
|
m:! \ ( o s x -- a )
|
|
184
182
|
a:len \ ( a -- n )
|
|
183
|
+
a:nth \ ( a n -- x )
|
|
184
|
+
a:head \ ( a -- x )
|
|
185
|
+
a:tail \ ( a -- a )
|
|
185
186
|
a:push \ ( a x -- a )
|
|
186
187
|
a:pop \ ( a -- x )
|
|
187
188
|
m:keys \ ( o -- a )
|
|
188
189
|
m:values \ ( o -- a )
|
|
189
190
|
s:split \ ( s s -- a )
|
|
190
191
|
s:join \ ( a s -- s )
|
|
192
|
+
s:chomp \ ( s -- s )
|
|
193
|
+
s:to_num \ ( s -- n )
|
|
191
194
|
j:stringify \ ( j -- s )
|
|
192
195
|
j:parse \ ( s -- j )
|
|
193
196
|
s:@ \ ( s n -- s )
|
|
@@ -226,7 +229,9 @@ a:each \ ( a f -- )
|
|
|
226
229
|
await \ ( p -- x )
|
|
227
230
|
os:argv \ ( -- a )
|
|
228
231
|
os:parse-args \ ( -- o )
|
|
229
|
-
|
|
232
|
+
os:exec \ ( s -- s )
|
|
233
|
+
os:exec-i \ ( s -- )
|
|
234
|
+
s:format \ ( s a -- s )
|
|
230
235
|
s:len \ ( s -- n )
|
|
231
236
|
s:to_upper \ ( s -- s )
|
|
232
237
|
s:to_lower \ ( s -- s )
|
|
@@ -254,7 +259,7 @@ This function throws an error object on TOS and will trigger the current `handle
|
|
|
254
259
|
you can throw a string or an object.
|
|
255
260
|
|
|
256
261
|
### G:delete \ ( s -- )
|
|
257
|
-
This function removes the latest definition of the
|
|
262
|
+
This function removes the latest definition of the word from the dictionary list restoring the previous definition if present.
|
|
258
263
|
|
|
259
264
|
### s:format \ ( s a -- s )
|
|
260
265
|
This function if an implementation of vsprintf. It takes a format string (fmt) and an args list [args] and returns a formatted string (char* vsprintf(*fmt, *args)):
|
package/doc/force-lang.1
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
.TH "
|
|
1
|
+
.TH "" "1" "January 2026" "0.1.0"
|
|
2
2
|
.SH "NAME"
|
|
3
|
-
\
|
|
3
|
+
\fB\fRForce lang
|
|
4
4
|
.SS (force\-lang)
|
|
5
5
|
.SH naming the lang
|
|
6
6
|
.P
|
|
7
7
|
Force is a modern dialect of Forth written in NodeJS and can use the NodeJS packages universe\.
|
|
8
|
+
.br
|
|
8
9
|
It is called Force because of its assonance of Forth and since the Force is the main power of the Jedi the files have \.j (or \.jedi) extension\. So Force is the Jedi programmers language !
|
|
9
10
|
.SH using Force as standalone interpreter
|
|
10
|
-
.P
|
|
11
11
|
.RS 2
|
|
12
12
|
.nf
|
|
13
13
|
$ npm install force\-lang \-g
|
|
@@ -25,61 +25,47 @@ Options:
|
|
|
25
25
|
.fi
|
|
26
26
|
.RE
|
|
27
27
|
.SH using Force in script
|
|
28
|
-
.P
|
|
29
28
|
.RS 2
|
|
30
29
|
.nf
|
|
31
30
|
$ cat example\.j
|
|
32
31
|
|
|
33
|
-
#!/usr/
|
|
32
|
+
#!/usr/bin/env force
|
|
34
33
|
|
|
35
34
|
2 2 + \.
|
|
36
35
|
.fi
|
|
37
36
|
.RE
|
|
38
37
|
.SH using force in shell
|
|
39
|
-
.P
|
|
40
38
|
.RS 2
|
|
41
39
|
.nf
|
|
42
40
|
echo "2 2 + \."|force
|
|
43
41
|
.fi
|
|
44
42
|
.RE
|
|
45
43
|
.SH using Force as node module
|
|
46
|
-
.P
|
|
47
44
|
.RS 2
|
|
48
45
|
.nf
|
|
49
46
|
$ npm i force\-lang
|
|
47
|
+
|
|
48
|
+
# or
|
|
49
|
+
|
|
50
|
+
npm install git+https://github\.com/elboza/force\-lang#master
|
|
50
51
|
.fi
|
|
51
52
|
.RE
|
|
52
|
-
.P
|
|
53
53
|
.RS 2
|
|
54
54
|
.nf
|
|
55
|
-
|
|
55
|
+
import force from 'force\-lang';
|
|
56
56
|
|
|
57
57
|
var x = '2 2 + \.';
|
|
58
58
|
|
|
59
59
|
(async function(){
|
|
60
60
|
await force\.load_lib();
|
|
61
|
-
force\.exec(x);
|
|
61
|
+
await force\.exec(x);
|
|
62
62
|
})();
|
|
63
63
|
.fi
|
|
64
64
|
.RE
|
|
65
|
-
.P
|
|
66
|
-
or using sync functions:
|
|
67
|
-
.P
|
|
68
|
-
.RS 2
|
|
69
|
-
.nf
|
|
70
|
-
const force = require ('force\-lang');
|
|
71
|
-
|
|
72
|
-
var x = '2 2 + \.';
|
|
73
|
-
|
|
74
|
-
force\.load_lib_sync();
|
|
75
|
-
force\.exec(x);
|
|
76
|
-
.fi
|
|
77
|
-
.RE
|
|
78
65
|
.SH repl multiline
|
|
79
66
|
.P
|
|
80
67
|
in the force\-lang repl \fBforce \-i\fP you can input multiline by appending \fB\\\fP (backslash) at the end of the current line before enter
|
|
81
68
|
.SH language constructs
|
|
82
|
-
.P
|
|
83
69
|
.RS 2
|
|
84
70
|
.nf
|
|
85
71
|
: word_def \.\.\. [exit] \.\.\. ;
|
|
@@ -90,13 +76,11 @@ example: ( 1 2 + )
|
|
|
90
76
|
|
|
91
77
|
see \.\.\. \\ see function definition
|
|
92
78
|
example: see cr
|
|
93
|
-
|
|
94
79
|
\|\.\.\. if \.\.\. else \.\.\. then
|
|
95
80
|
\\ if ( x \-\- )
|
|
96
81
|
\\ else ( \-\- )
|
|
97
82
|
\\ then ( \-\- )
|
|
98
83
|
example: T if "no" \. else "yes" \. then
|
|
99
|
-
|
|
100
84
|
\|\.\.\. begin \.\.\.while \.\.\.repeat
|
|
101
85
|
\\ begin ( \-\- )
|
|
102
86
|
\\ repeat ( \-\- )
|
|
@@ -126,9 +110,10 @@ endcase
|
|
|
126
110
|
.SH functions prefix
|
|
127
111
|
.P
|
|
128
112
|
functions name can be prefixed to give more meaningful name to the function and the type it act on\.
|
|
113
|
+
.br
|
|
129
114
|
For example \fB@\fP is applied to normal variables to get values, \fBa:@\fP applies to array, \fBm:@\fP applies to maps (hash)\.
|
|
115
|
+
.br
|
|
130
116
|
The main prefixes are:
|
|
131
|
-
.P
|
|
132
117
|
.RS 2
|
|
133
118
|
.nf
|
|
134
119
|
n: for numbers
|
|
@@ -146,7 +131,6 @@ xml: for xml/dom parser
|
|
|
146
131
|
.SH functions signatures
|
|
147
132
|
.P
|
|
148
133
|
in the comments of the stadard lib section is described the stack consumption and the type that the function requires\.
|
|
149
|
-
.P
|
|
150
134
|
.RS 2
|
|
151
135
|
.nf
|
|
152
136
|
o object (map)
|
|
@@ -166,11 +150,11 @@ v variable name
|
|
|
166
150
|
.fi
|
|
167
151
|
.RE
|
|
168
152
|
.SH standard lib
|
|
169
|
-
.P
|
|
170
153
|
.RS 2
|
|
171
154
|
.nf
|
|
172
155
|
bye \\ ( \-\- )
|
|
173
156
|
noop \\ ( \-\- )
|
|
157
|
+
nop \\ ( \-\- )
|
|
174
158
|
\|\.s \\ ( \-\- )
|
|
175
159
|
\|\.e \\ ( \-\- )
|
|
176
160
|
words \\ ( \-\- )
|
|
@@ -179,6 +163,8 @@ emit \\ ( n \-\- )
|
|
|
179
163
|
\|\.? \\ ( x \-\- )
|
|
180
164
|
! \\ ( x v \-\- )
|
|
181
165
|
@ \\ ( v \-\- x )
|
|
166
|
+
>r \\ ( x \-\- )
|
|
167
|
+
r> \\ ( \-\- x )
|
|
182
168
|
not \\ ( b \-\- b )
|
|
183
169
|
and \\ ( b \-\- b )
|
|
184
170
|
or \\ ( b \-\- b )
|
|
@@ -211,12 +197,17 @@ a:! \\ ( a n x \-\- a )
|
|
|
211
197
|
m:@ \\ ( o s \-\- x )
|
|
212
198
|
m:! \\ ( o s x \-\- a )
|
|
213
199
|
a:len \\ ( a \-\- n )
|
|
200
|
+
a:nth \\ ( a n \-\- x )
|
|
201
|
+
a:head \\ ( a \-\- x )
|
|
202
|
+
a:tail \\ ( a \-\- a )
|
|
214
203
|
a:push \\ ( a x \-\- a )
|
|
215
204
|
a:pop \\ ( a \-\- x )
|
|
216
205
|
m:keys \\ ( o \-\- a )
|
|
217
206
|
m:values \\ ( o \-\- a )
|
|
218
207
|
s:split \\ ( s s \-\- a )
|
|
219
208
|
s:join \\ ( a s \-\- s )
|
|
209
|
+
s:chomp \\ ( s \-\- s )
|
|
210
|
+
s:to_num \\ ( s \-\- n )
|
|
220
211
|
j:stringify \\ ( j \-\- s )
|
|
221
212
|
j:parse \\ ( s \-\- j )
|
|
222
213
|
s:@ \\ ( s n \-\- s )
|
|
@@ -255,7 +246,9 @@ a:each \\ ( a f \-\- )
|
|
|
255
246
|
await \\ ( p \-\- x )
|
|
256
247
|
os:argv \\ ( \-\- a )
|
|
257
248
|
os:parse\-args \\ ( \-\- o )
|
|
258
|
-
|
|
249
|
+
os:exec \\ ( s \-\- s )
|
|
250
|
+
os:exec\-i \\ ( s \-\- )
|
|
251
|
+
s:format \\ ( s a \-\- s )
|
|
259
252
|
s:len \\ ( s \-\- n )
|
|
260
253
|
s:to_upper \\ ( s \-\- s )
|
|
261
254
|
s:to_lower \\ ( s \-\- s )
|
|
@@ -276,20 +269,25 @@ xml:get_val \\ ( j \-\- s )
|
|
|
276
269
|
.SS handle \\ ( e \-\- )
|
|
277
270
|
.P
|
|
278
271
|
This function is called every time there is an error object on top of the stack\.
|
|
279
|
-
|
|
272
|
+
.br
|
|
273
|
+
You can override this function with you own to provide a custom error handling\. This can be permanent or temporary (by deleting the latest definition with \fB'handle' G:delete\fP)\.
|
|
274
|
+
.br
|
|
280
275
|
The first thing that your custom handler function should do is to remove the error object from the TOS\. This can be done by eighter removing it (\fBdrop\fP or print \fB\|\.\fP) or by adding another item on top of it (in case you want to preserve it for future use)\.
|
|
281
276
|
.SS throw \\ ( s \-\- ) or ( o \-\- )
|
|
282
277
|
.P
|
|
283
278
|
This function throws an error object on TOS and will trigger the current \fBhandle\fP function\.
|
|
279
|
+
.br
|
|
284
280
|
you can throw a string or an object\.
|
|
285
281
|
.SS G:delete \\ ( s \-\- )
|
|
286
282
|
.P
|
|
287
|
-
This function removes the latest definition of the
|
|
283
|
+
This function removes the latest definition of the word from the dictionary list restoring the previous definition if present\.
|
|
288
284
|
.SS s:format \\ ( s a \-\- s )
|
|
289
285
|
.P
|
|
290
|
-
This function if an implementation of vsprintf\. It takes a format string (fmt) and an args list [args] and returns a formatted string (char
|
|
291
|
-
|
|
292
|
-
|
|
286
|
+
This function if an implementation of vsprintf\. It takes a format string (fmt) and an args list [args] and returns a formatted string (char* vsprintf(*fmt, *args)):
|
|
287
|
+
.br
|
|
288
|
+
example:
|
|
289
|
+
.br
|
|
290
|
+
\fB"the number %d and the string %s" [22, "hey"] f:format \.\fP
|
|
293
291
|
.SS TODO
|
|
294
292
|
.P
|
|
295
293
|
other standard lib functions descriptions coming soon \.\.\.
|
package/doc/force.1
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
.TH "
|
|
1
|
+
.TH "" "1" "January 2026" "0.1.0"
|
|
2
2
|
.SH "NAME"
|
|
3
|
-
\
|
|
3
|
+
\fB\fRForce lang
|
|
4
4
|
.SS (force\-lang)
|
|
5
5
|
.SH naming the lang
|
|
6
6
|
.P
|
|
7
7
|
Force is a modern dialect of Forth written in NodeJS and can use the NodeJS packages universe\.
|
|
8
|
+
.br
|
|
8
9
|
It is called Force because of its assonance of Forth and since the Force is the main power of the Jedi the files have \.j (or \.jedi) extension\. So Force is the Jedi programmers language !
|
|
9
10
|
.SH using Force as standalone interpreter
|
|
10
|
-
.P
|
|
11
11
|
.RS 2
|
|
12
12
|
.nf
|
|
13
13
|
$ npm install force\-lang \-g
|
|
@@ -25,61 +25,47 @@ Options:
|
|
|
25
25
|
.fi
|
|
26
26
|
.RE
|
|
27
27
|
.SH using Force in script
|
|
28
|
-
.P
|
|
29
28
|
.RS 2
|
|
30
29
|
.nf
|
|
31
30
|
$ cat example\.j
|
|
32
31
|
|
|
33
|
-
#!/usr/
|
|
32
|
+
#!/usr/bin/env force
|
|
34
33
|
|
|
35
34
|
2 2 + \.
|
|
36
35
|
.fi
|
|
37
36
|
.RE
|
|
38
37
|
.SH using force in shell
|
|
39
|
-
.P
|
|
40
38
|
.RS 2
|
|
41
39
|
.nf
|
|
42
40
|
echo "2 2 + \."|force
|
|
43
41
|
.fi
|
|
44
42
|
.RE
|
|
45
43
|
.SH using Force as node module
|
|
46
|
-
.P
|
|
47
44
|
.RS 2
|
|
48
45
|
.nf
|
|
49
46
|
$ npm i force\-lang
|
|
47
|
+
|
|
48
|
+
# or
|
|
49
|
+
|
|
50
|
+
npm install git+https://github\.com/elboza/force\-lang#master
|
|
50
51
|
.fi
|
|
51
52
|
.RE
|
|
52
|
-
.P
|
|
53
53
|
.RS 2
|
|
54
54
|
.nf
|
|
55
|
-
|
|
55
|
+
import force from 'force\-lang';
|
|
56
56
|
|
|
57
57
|
var x = '2 2 + \.';
|
|
58
58
|
|
|
59
59
|
(async function(){
|
|
60
60
|
await force\.load_lib();
|
|
61
|
-
force\.exec(x);
|
|
61
|
+
await force\.exec(x);
|
|
62
62
|
})();
|
|
63
63
|
.fi
|
|
64
64
|
.RE
|
|
65
|
-
.P
|
|
66
|
-
or using sync functions:
|
|
67
|
-
.P
|
|
68
|
-
.RS 2
|
|
69
|
-
.nf
|
|
70
|
-
const force = require ('force\-lang');
|
|
71
|
-
|
|
72
|
-
var x = '2 2 + \.';
|
|
73
|
-
|
|
74
|
-
force\.load_lib_sync();
|
|
75
|
-
force\.exec(x);
|
|
76
|
-
.fi
|
|
77
|
-
.RE
|
|
78
65
|
.SH repl multiline
|
|
79
66
|
.P
|
|
80
67
|
in the force\-lang repl \fBforce \-i\fP you can input multiline by appending \fB\\\fP (backslash) at the end of the current line before enter
|
|
81
68
|
.SH language constructs
|
|
82
|
-
.P
|
|
83
69
|
.RS 2
|
|
84
70
|
.nf
|
|
85
71
|
: word_def \.\.\. [exit] \.\.\. ;
|
|
@@ -90,13 +76,11 @@ example: ( 1 2 + )
|
|
|
90
76
|
|
|
91
77
|
see \.\.\. \\ see function definition
|
|
92
78
|
example: see cr
|
|
93
|
-
|
|
94
79
|
\|\.\.\. if \.\.\. else \.\.\. then
|
|
95
80
|
\\ if ( x \-\- )
|
|
96
81
|
\\ else ( \-\- )
|
|
97
82
|
\\ then ( \-\- )
|
|
98
83
|
example: T if "no" \. else "yes" \. then
|
|
99
|
-
|
|
100
84
|
\|\.\.\. begin \.\.\.while \.\.\.repeat
|
|
101
85
|
\\ begin ( \-\- )
|
|
102
86
|
\\ repeat ( \-\- )
|
|
@@ -126,9 +110,10 @@ endcase
|
|
|
126
110
|
.SH functions prefix
|
|
127
111
|
.P
|
|
128
112
|
functions name can be prefixed to give more meaningful name to the function and the type it act on\.
|
|
113
|
+
.br
|
|
129
114
|
For example \fB@\fP is applied to normal variables to get values, \fBa:@\fP applies to array, \fBm:@\fP applies to maps (hash)\.
|
|
115
|
+
.br
|
|
130
116
|
The main prefixes are:
|
|
131
|
-
.P
|
|
132
117
|
.RS 2
|
|
133
118
|
.nf
|
|
134
119
|
n: for numbers
|
|
@@ -146,7 +131,6 @@ xml: for xml/dom parser
|
|
|
146
131
|
.SH functions signatures
|
|
147
132
|
.P
|
|
148
133
|
in the comments of the stadard lib section is described the stack consumption and the type that the function requires\.
|
|
149
|
-
.P
|
|
150
134
|
.RS 2
|
|
151
135
|
.nf
|
|
152
136
|
o object (map)
|
|
@@ -166,11 +150,11 @@ v variable name
|
|
|
166
150
|
.fi
|
|
167
151
|
.RE
|
|
168
152
|
.SH standard lib
|
|
169
|
-
.P
|
|
170
153
|
.RS 2
|
|
171
154
|
.nf
|
|
172
155
|
bye \\ ( \-\- )
|
|
173
156
|
noop \\ ( \-\- )
|
|
157
|
+
nop \\ ( \-\- )
|
|
174
158
|
\|\.s \\ ( \-\- )
|
|
175
159
|
\|\.e \\ ( \-\- )
|
|
176
160
|
words \\ ( \-\- )
|
|
@@ -179,6 +163,8 @@ emit \\ ( n \-\- )
|
|
|
179
163
|
\|\.? \\ ( x \-\- )
|
|
180
164
|
! \\ ( x v \-\- )
|
|
181
165
|
@ \\ ( v \-\- x )
|
|
166
|
+
>r \\ ( x \-\- )
|
|
167
|
+
r> \\ ( \-\- x )
|
|
182
168
|
not \\ ( b \-\- b )
|
|
183
169
|
and \\ ( b \-\- b )
|
|
184
170
|
or \\ ( b \-\- b )
|
|
@@ -211,12 +197,17 @@ a:! \\ ( a n x \-\- a )
|
|
|
211
197
|
m:@ \\ ( o s \-\- x )
|
|
212
198
|
m:! \\ ( o s x \-\- a )
|
|
213
199
|
a:len \\ ( a \-\- n )
|
|
200
|
+
a:nth \\ ( a n \-\- x )
|
|
201
|
+
a:head \\ ( a \-\- x )
|
|
202
|
+
a:tail \\ ( a \-\- a )
|
|
214
203
|
a:push \\ ( a x \-\- a )
|
|
215
204
|
a:pop \\ ( a \-\- x )
|
|
216
205
|
m:keys \\ ( o \-\- a )
|
|
217
206
|
m:values \\ ( o \-\- a )
|
|
218
207
|
s:split \\ ( s s \-\- a )
|
|
219
208
|
s:join \\ ( a s \-\- s )
|
|
209
|
+
s:chomp \\ ( s \-\- s )
|
|
210
|
+
s:to_num \\ ( s \-\- n )
|
|
220
211
|
j:stringify \\ ( j \-\- s )
|
|
221
212
|
j:parse \\ ( s \-\- j )
|
|
222
213
|
s:@ \\ ( s n \-\- s )
|
|
@@ -255,7 +246,9 @@ a:each \\ ( a f \-\- )
|
|
|
255
246
|
await \\ ( p \-\- x )
|
|
256
247
|
os:argv \\ ( \-\- a )
|
|
257
248
|
os:parse\-args \\ ( \-\- o )
|
|
258
|
-
|
|
249
|
+
os:exec \\ ( s \-\- s )
|
|
250
|
+
os:exec\-i \\ ( s \-\- )
|
|
251
|
+
s:format \\ ( s a \-\- s )
|
|
259
252
|
s:len \\ ( s \-\- n )
|
|
260
253
|
s:to_upper \\ ( s \-\- s )
|
|
261
254
|
s:to_lower \\ ( s \-\- s )
|
|
@@ -276,20 +269,25 @@ xml:get_val \\ ( j \-\- s )
|
|
|
276
269
|
.SS handle \\ ( e \-\- )
|
|
277
270
|
.P
|
|
278
271
|
This function is called every time there is an error object on top of the stack\.
|
|
279
|
-
|
|
272
|
+
.br
|
|
273
|
+
You can override this function with you own to provide a custom error handling\. This can be permanent or temporary (by deleting the latest definition with \fB'handle' G:delete\fP)\.
|
|
274
|
+
.br
|
|
280
275
|
The first thing that your custom handler function should do is to remove the error object from the TOS\. This can be done by eighter removing it (\fBdrop\fP or print \fB\|\.\fP) or by adding another item on top of it (in case you want to preserve it for future use)\.
|
|
281
276
|
.SS throw \\ ( s \-\- ) or ( o \-\- )
|
|
282
277
|
.P
|
|
283
278
|
This function throws an error object on TOS and will trigger the current \fBhandle\fP function\.
|
|
279
|
+
.br
|
|
284
280
|
you can throw a string or an object\.
|
|
285
281
|
.SS G:delete \\ ( s \-\- )
|
|
286
282
|
.P
|
|
287
|
-
This function removes the latest definition of the
|
|
283
|
+
This function removes the latest definition of the word from the dictionary list restoring the previous definition if present\.
|
|
288
284
|
.SS s:format \\ ( s a \-\- s )
|
|
289
285
|
.P
|
|
290
|
-
This function if an implementation of vsprintf\. It takes a format string (fmt) and an args list [args] and returns a formatted string (char
|
|
291
|
-
|
|
292
|
-
|
|
286
|
+
This function if an implementation of vsprintf\. It takes a format string (fmt) and an args list [args] and returns a formatted string (char* vsprintf(*fmt, *args)):
|
|
287
|
+
.br
|
|
288
|
+
example:
|
|
289
|
+
.br
|
|
290
|
+
\fB"the number %d and the string %s" [22, "hey"] f:format \.\fP
|
|
293
291
|
.SS TODO
|
|
294
292
|
.P
|
|
295
293
|
other standard lib functions descriptions coming soon \.\.\.
|
package/examples/cli-args.j
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/
|
|
1
|
+
#!/usr/bin/env force
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
os:argv @ .
|
|
@@ -14,4 +14,4 @@ os:parse-args .s
|
|
|
14
14
|
// ./cli-args.j -x 99
|
|
15
15
|
// the putput will be:
|
|
16
16
|
// ["/usr/local/bin/node","/usr/local/bin/force","./cli-args.j","-x","99"]
|
|
17
|
-
// { argv: [], xray: '99' }
|
|
17
|
+
// { argv: [], xray: '99' }
|
package/examples/testjs.js
CHANGED
package/examples/web_scrap.j
CHANGED