basedpl 0.1.32 → 0.1.33
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 +3 -62
- package/basedpl_wasm_bg.wasm +0 -0
- package/layout.json +5 -8
- package/lb.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,72 +1,13 @@
|
|
|
1
1
|
# basedpl
|
|
2
2
|
|
|
3
|
-
This package runs BasedPL (BPL) in a web page. BPL is an array language derived from APL, with ideas from J and BQN. The package holds the BPL interpreter compiled to WebAssembly, a language bar for typing BPL's glyphs, and a TextMate grammar for highlighting BPL code.
|
|
4
|
-
|
|
5
|
-
## Load the package
|
|
6
|
-
|
|
7
|
-
jsDelivr serves every file in the package. An unversioned URL, such as `https://cdn.jsdelivr.net/npm/basedpl/basedpl_wasm.js`, gives the latest release. To keep one release, put its version in the URL: `https://cdn.jsdelivr.net/npm/basedpl@<version>/basedpl_wasm.js`. To install the package instead, run `npm install basedpl`.
|
|
8
|
-
|
|
9
|
-
## Run BPL
|
|
3
|
+
This package runs BasedPL (BPL) in a web page. BPL is an array language derived from APL, with ideas from J and BQN. The package holds the BPL interpreter compiled to WebAssembly, a language bar for typing BPL's glyphs, and a TextMate grammar for highlighting BPL code.
|
|
10
4
|
|
|
11
5
|
```js
|
|
12
6
|
import init, { Session, configure } from 'https://cdn.jsdelivr.net/npm/basedpl/basedpl_wasm.js';
|
|
13
7
|
|
|
14
8
|
await init();
|
|
15
9
|
configure(location.href, message => console.error(message));
|
|
16
|
-
|
|
17
|
-
const error = session.run('avg←+/÷≢ ⋄ avg 2 4 9', output => console.log(output.data['text/plain']));
|
|
10
|
+
new Session().run('avg←+/÷≢ ⋄ avg 2 4 9', output => console.log(output.data['text/plain'])); // logs 5
|
|
18
11
|
```
|
|
19
12
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
- `init()` fetches the module from beside the glue.
|
|
23
|
-
- `configure(base, panic)` sets the URL that relative file reads resolve against, and the function that receives a panic's message. After a panic, the module can't run more code.
|
|
24
|
-
- `session.run(code, output)` runs `code`, then returns `null` or the error. The error is an object with `kind`, `message` and `display`. `display` holds the error as BPL shows it. A session keeps its names from one `run` to the next.
|
|
25
|
-
- `output` receives each output as the program produces it, as `{kind, data}`. `kind` is `"display"` for a displayed value, `"explicit"` for a value assigned to `⎕`, or `"text"` for text written with `"-" •nput`. Display and explicit outputs each end a line. Text output doesn't.
|
|
26
|
-
|
|
27
|
-
`data` maps MIME types to text, or to a `Uint8Array` for a binary type:
|
|
28
|
-
|
|
29
|
-
- `text/plain`: the output as text.
|
|
30
|
-
- `text/html`: markup from element functions.
|
|
31
|
-
- `image/svg+xml`: markup from `•svg` and `•plot`.
|
|
32
|
-
- `image/x-rgba;width=N`: RGBA pixels from `•image`, `N` pixels wide. `new ImageData(new Uint8ClampedArray(bytes.buffer), N)` makes a canvas image from them.
|
|
33
|
-
- `image/png` and `image/jpeg`: encoded images. An animation from `•image` is an animated PNG.
|
|
34
|
-
- `application/x-bpl-canvas+json` and `application/x-bpl-canvas-data`: a canvas from `•canvas`. `canvas.js` is a script whose value is a function that draws it: `(0, eval)(script)(canvas, data['application/x-bpl-canvas+json'], data['application/x-bpl-canvas-data'])`, where `canvas` is a `<canvas>` element.
|
|
35
|
-
|
|
36
|
-
`run` returns only when the code finishes. To keep the page responsive, run BPL in a Web Worker. The docs' [`worker.js`](https://github.com/AnswerDotAI/basedpl/blob/main/nbs/playground/worker.js) runs BPL in a worker, and [`bpl.js`](https://github.com/AnswerDotAI/basedpl/blob/main/nbs/playground/bpl.js) starts the worker and shows each output on the page.
|
|
37
|
-
|
|
38
|
-
## Values and JavaScript functions
|
|
39
|
-
|
|
40
|
-
`session.eval(code)` returns the value of `code` as a JavaScript value, or `undefined` when the code gives no value. A BPL error throws the error object. `session.bind(names)` binds each property of the object `names` as a BPL name. A JavaScript function becomes a BPL function that calls it, with the right argument, or the left then the right. Inside BPL, `•js source` makes such a function from JavaScript source. Values cross as the [`•js`](https://answerdotai.github.io/basedpl/system/js.html) page describes: a number is a number, a string a string and a record an object. Any other array is `{shape, data}`, with `data` a typed array when every item is a number.
|
|
41
|
-
|
|
42
|
-
```js
|
|
43
|
-
session.bind({ scale: 2, log: x => console.log(x) });
|
|
44
|
-
session.eval('scale×1 2 3'); // {shape: [3], data: Float64Array [2, 4, 6]}
|
|
45
|
-
session.run('log "hi"', () => {}); // logs "hi"
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## Differences from native BPL
|
|
49
|
-
|
|
50
|
-
- `•js` exists only here.
|
|
51
|
-
- `•readdir`, `•metadata`, `•copy`, `•rename`, `•remove`, `•mkdir`, `•path` and `•delay` don't exist. `•nput` writes only to `"-"`.
|
|
52
|
-
- File reads and `•fetch` are synchronous `XMLHttpRequest`s, relative to the URL given to `configure`.
|
|
53
|
-
- `•r` uses JavaScript's `RegExp`, with its syntax and replacement templates.
|
|
54
|
-
- `•date⁻¹` has no `locale` option.
|
|
55
|
-
- Function calls nest at most 380 deep. A deeper call is a `LIMIT` error.
|
|
56
|
-
|
|
57
|
-
## Language bar
|
|
58
|
-
|
|
59
|
-
`lb.js` adds a bar of BPL's glyphs to the page. Clicking a glyph types it into the editor used last. In a textarea marked with `data-bpl`, or a Monaco editor whose language is `bpl`, a backtick followed by a glyph's name also types the glyph, as in the BPL REPL. `lb.js` and `input.js` are scripts whose value is a function. The bar needs the glyph rows from `symbols()` and the key layout from `layout.json`:
|
|
60
|
-
|
|
61
|
-
```js
|
|
62
|
-
import init, { symbols } from 'https://cdn.jsdelivr.net/npm/basedpl/basedpl_wasm.js';
|
|
63
|
-
|
|
64
|
-
const text = name => fetch(`https://cdn.jsdelivr.net/npm/basedpl/${name}`).then(r => r.text());
|
|
65
|
-
const [lb, input, layout] = await Promise.all(['lb.js', 'input.js', 'layout.json'].map(text));
|
|
66
|
-
await init();
|
|
67
|
-
(0, eval)(lb)(JSON.parse(symbols()), (0, eval)(input), JSON.parse(layout));
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
## Highlighting
|
|
71
|
-
|
|
72
|
-
`bpl.tmLanguage.json` is a TextMate grammar for BPL, with the scope name `source.bpl`. Shiki and editors that read TextMate grammars use it to highlight BPL code.
|
|
13
|
+
[BPL on the web](https://answerdotai.github.io/basedpl/web.html) documents this package: loading it, its outputs, values and JavaScript functions, drawing, the language bar, and how the gallery is built. The [playground](https://answerdotai.github.io/basedpl/playground.html) and [gallery](https://answerdotai.github.io/basedpl/gallery.html) run BPL in your browser. The [BPL documentation](https://answerdotai.github.io/basedpl/) covers the language.
|
package/basedpl_wasm_bg.wasm
CHANGED
|
Binary file
|
package/layout.json
CHANGED
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"'": "⊢",
|
|
41
41
|
"z": "⊂",
|
|
42
42
|
"x": "⊃",
|
|
43
|
-
"c":
|
|
43
|
+
"c": "∩",
|
|
44
44
|
"v": "∪",
|
|
45
|
-
"b":
|
|
46
|
-
"n":
|
|
45
|
+
"b": "⊥",
|
|
46
|
+
"n": "⊤",
|
|
47
47
|
"m": "×",
|
|
48
48
|
",": "↢",
|
|
49
49
|
".": "↣",
|
|
@@ -61,11 +61,8 @@
|
|
|
61
61
|
"bar": {"terminator": "¯", "keys": {",": "⍪", "\\": "⍀", "/": "⌿", "a": "⍶", "w": "⍹", "7": "⍙", "`": "⍚", "0": "⊼", "9": "⊽", "e": "⍷", "i": "⍸", "z": "⊆"}},
|
|
62
62
|
"match": {"terminator": "≡", "keys": {"/": "≢"}},
|
|
63
63
|
"quad": {"terminator": "⎕", "keys": {"t": "⌻", ":": "⍠", "=": "⌸", "u": "⌹", "|": "⌷", "`": "⌺", ";": "⍠", "\\": "⌷"}},
|
|
64
|
-
"circle": {"terminator": "○", "keys": {"-": "⊖", "\\": "⍉", "/": "⊘", "*": "⍟", "m": "⊗", "u": "⨸", "t": "⌾", "8": "⍟"}},
|
|
64
|
+
"circle": {"terminator": "○", "keys": {"-": "⊖", "\\": "⍉", "/": "⊘", "*": "⍟", "m": "⊗", "u": "⨸", "t": "⌾", "8": "⍟", "c": "⍝", "b": "⍎", "n": "⍕"}},
|
|
65
65
|
"stile": {"terminator": "⍭", "keys": {"7": "⍋", "g": "⍒"}},
|
|
66
|
-
"take": {"terminator": "↑", "keys": {"j": "↕"}}
|
|
67
|
-
"cap": {"terminator": "∩", "keys": {"t": "⍝"}},
|
|
68
|
-
"decode": {"terminator": "⊥", "keys": {"t": "⍎"}},
|
|
69
|
-
"encode": {"terminator": "⊤", "keys": {"t": "⍕"}}
|
|
66
|
+
"take": {"terminator": "↑", "keys": {"j": "↕"}}
|
|
70
67
|
}
|
|
71
68
|
}
|
package/lb.js
CHANGED
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
}
|
|
111
111
|
// Related glyphs stay together; arrows meet at the boundary between menus and plain buttons.
|
|
112
112
|
const order = [...new Set([
|
|
113
|
-
...'^_
|
|
113
|
+
...'^_¯¨○⎕≡⍭↑↓←→↢↣⇄∨∧⍺⍵∆∇⋄∊⍳⊂⊃∩∪⊥⊤⊣⊢×÷⌊⌈≤≥≠√π', ...groups.keys(), ...names.keys()
|
|
114
114
|
])];
|
|
115
115
|
for (const glyph of [...order.filter(g => groups.has(g)), ...order.filter(g => !groups.has(g))]) {
|
|
116
116
|
if (!groups.has(glyph) && (variants.has(glyph) || /^[\x20-\x7e]+$/.test(glyph))) continue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "basedpl",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.33",
|
|
4
4
|
"description": "BasedPL, the Based-array Programming Language, is an APL-derived array language, borrowing ideas from J and BQN, with an emphasis on simple, consistent notation.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|