@thi.ng/lispy 0.2.0 → 0.3.1
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/CHANGELOG.md +7 -1
- package/README.md +26 -12
- package/index.js +6 -1
- package/kernel.d.ts +1 -1
- package/kernel.js +1 -2
- package/package.json +13 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2025-
|
|
3
|
+
- **Last updated**: 2025-06-09T17:24:08Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -11,6 +11,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
11
11
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
12
12
|
and/or version bumps of transitive dependencies.
|
|
13
13
|
|
|
14
|
+
## [0.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/lispy@0.3.0) (2025-05-28)
|
|
15
|
+
|
|
16
|
+
#### 🚀 Features
|
|
17
|
+
|
|
18
|
+
- add/update builtins ([ab7cdec](https://github.com/thi-ng/umbrella/commit/ab7cdec))
|
|
19
|
+
|
|
14
20
|
## [0.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/lispy@0.2.0) (2025-05-21)
|
|
15
21
|
|
|
16
22
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 209 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
|
@@ -51,7 +51,8 @@ Lightweight, extensible, interpreted Lisp-style DSL for embedding in other proje
|
|
|
51
51
|
## Core language features
|
|
52
52
|
|
|
53
53
|
The core language is intentionally kept minimal, aimed at data transformations,
|
|
54
|
-
and currently only contains the
|
|
54
|
+
configuration, user code snippets/expressions, and currently only contains the
|
|
55
|
+
following:
|
|
55
56
|
|
|
56
57
|
### Constants
|
|
57
58
|
- `T`: true
|
|
@@ -60,6 +61,8 @@ and currently only contains the following:
|
|
|
60
61
|
- `PI`
|
|
61
62
|
- `HALF_PI`
|
|
62
63
|
- `TAU`
|
|
64
|
+
- `INF`: ∞
|
|
65
|
+
- `-INF`: -∞
|
|
63
66
|
|
|
64
67
|
### Predicates
|
|
65
68
|
|
|
@@ -133,7 +136,7 @@ All included...
|
|
|
133
136
|
- `(env! (sym val ...))`: modify bindings in current env
|
|
134
137
|
- `(if test truthy falsey?)`: conditional with optional false branch
|
|
135
138
|
- `(let (sym val ...) body)`: locally scoped var bindings/expression
|
|
136
|
-
- `(while test body...
|
|
139
|
+
- `(while test body...)`: loop while test is truthy
|
|
137
140
|
- `(-> ...)`: Clojure-style thread-first S-expression re-writing
|
|
138
141
|
- `(-> a (+ b) (* c))` → `(* (+ a b) c)`
|
|
139
142
|
- `(->> ...)`: Clojure-style thread-last S-expression re-writing
|
|
@@ -181,9 +184,10 @@ All included...
|
|
|
181
184
|
|
|
182
185
|
## Extensibility
|
|
183
186
|
|
|
184
|
-
The core language can be easily customized/extended by defining new
|
|
185
|
-
root environment `ENV` (see example below) or
|
|
186
|
-
|
|
187
|
+
The core language can be easily customized/extended by defining new symbols (or
|
|
188
|
+
redefining existing ones) in the root environment `ENV` (see example below) or
|
|
189
|
+
passing a custom environment to
|
|
190
|
+
[`evalSource()`](https://docs.thi.ng/umbrella/lispy/functions/evalSource.html).
|
|
187
191
|
|
|
188
192
|
## Status
|
|
189
193
|
|
|
@@ -217,7 +221,7 @@ For Node.js REPL:
|
|
|
217
221
|
const lispy = await import("@thi.ng/lispy");
|
|
218
222
|
```
|
|
219
223
|
|
|
220
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 1.
|
|
224
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 1.96 KB
|
|
221
225
|
|
|
222
226
|
## Dependencies
|
|
223
227
|
|
|
@@ -247,12 +251,22 @@ directory is using this package:
|
|
|
247
251
|
|
|
248
252
|
[Generated API docs](https://docs.thi.ng/umbrella/lispy/)
|
|
249
253
|
|
|
254
|
+
> [!NOTE]
|
|
255
|
+
> Please also see
|
|
256
|
+
> [/tests](https://github.com/thi-ng/umbrella/blob/develop/packages/lispy/test)
|
|
257
|
+
> for more small code examples..
|
|
258
|
+
|
|
250
259
|
```ts tangle:export/readme-1.ts
|
|
251
260
|
import { evalSource, ENV } from "@thi.ng/lispy";
|
|
252
261
|
|
|
253
|
-
// define custom
|
|
254
|
-
|
|
255
|
-
ENV
|
|
262
|
+
// define custom root environment
|
|
263
|
+
const CUSTOM_ENV = {
|
|
264
|
+
...ENV,
|
|
265
|
+
// re-define print fn (actually the same as default)
|
|
266
|
+
print: console.log,
|
|
267
|
+
// pre-define new global variable
|
|
268
|
+
name: "lispy"
|
|
269
|
+
};
|
|
256
270
|
|
|
257
271
|
const SRC = `
|
|
258
272
|
(print (+ 1 2 3 4))
|
|
@@ -266,7 +280,7 @@ const SRC = `
|
|
|
266
280
|
;; here, a curried version of the built-in print fn
|
|
267
281
|
(def greetings! (partial print "hello,"))
|
|
268
282
|
|
|
269
|
-
;; print greeting (name
|
|
283
|
+
;; print greeting ('name' symbol provided via custom env)
|
|
270
284
|
(greetings! name)
|
|
271
285
|
;; hello, lispy!
|
|
272
286
|
|
|
@@ -290,7 +304,7 @@ const SRC = `
|
|
|
290
304
|
`;
|
|
291
305
|
|
|
292
306
|
// execute with customized environment
|
|
293
|
-
evalSource(SRC,
|
|
307
|
+
evalSource(SRC, CUSTOM_ENV);
|
|
294
308
|
|
|
295
309
|
// output:
|
|
296
310
|
// 10
|
package/index.js
CHANGED
|
@@ -104,6 +104,9 @@ const BUILTINS = defmulti(
|
|
|
104
104
|
}
|
|
105
105
|
return obj;
|
|
106
106
|
},
|
|
107
|
+
keys: ([_, x], env) => Object.keys(interpret(x, env)),
|
|
108
|
+
vals: ([_, x], env) => Object.values(interpret(x, env)),
|
|
109
|
+
pairs: ([_, x], env) => Object.entries(interpret(x, env)),
|
|
107
110
|
// rewriting operators:
|
|
108
111
|
// iteratively threads first child as FIRST arg of next child
|
|
109
112
|
// (-> a (+ b) (* c)) = (* (+ a b) c)
|
|
@@ -151,6 +154,8 @@ const ENV = {
|
|
|
151
154
|
T: true,
|
|
152
155
|
F: false,
|
|
153
156
|
null: null,
|
|
157
|
+
INF: Infinity,
|
|
158
|
+
"-INF": -Infinity,
|
|
154
159
|
and: (...args) => {
|
|
155
160
|
let x;
|
|
156
161
|
for (x of args) {
|
|
@@ -229,7 +234,7 @@ const ENV = {
|
|
|
229
234
|
step,
|
|
230
235
|
smoothstep: smoothStep,
|
|
231
236
|
get: (arr, i) => arr[i],
|
|
232
|
-
"set!": (arr, i, x) => arr[i] = x,
|
|
237
|
+
"set!": (arr, i, x) => (arr[i] = x, arr),
|
|
233
238
|
push: (list, ...x) => (list.push(...x), list),
|
|
234
239
|
concat: (list, ...x) => list.concat(...x),
|
|
235
240
|
// returns length of first argument (presumably a list or string)
|
package/kernel.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const KERNEL = "\n; partial functional application (currying for 1 arg)\n(defn partial (f x) (fn (y) (f x y)))\n\n; partial functional application (currying for 2 args)\n(defn partial2 (f x y) (fn (z) (f x y z)))\n\n; functional composition for 1-arg fns\n(defn comp (f g) (fn (x) (f (g x))))\n\n
|
|
1
|
+
export declare const KERNEL = "\n; partial functional application (currying for 1 arg)\n(defn partial (f x) (fn (y) (f x y)))\n\n; partial functional application (currying for 2 args)\n(defn partial2 (f x y) (fn (z) (f x y z)))\n\n; functional composition for 1-arg fns\n(defn comp (f g) (fn (x) (f (g x))))\n\n(defn complement (f) (fn (x) (not (f x))))\n\n; calls f if x is nullish\n(defn fnull? (x f) (if (null? x) (f) x))\n\n; list reduction\n(defn reduce (f acc xs) (if xs (reduce f (f acc (first xs)) (next xs)) acc))\n\n; list transformation (expressed as reduction)\n(defn map (f xs) (reduce (fn (acc x) (concat acc (f x))) (list) xs))\n\n; filter list with predicate function\n(defn filter (f xs) (reduce (fn (acc x) (if (f x) (concat acc x) acc)) (list) xs))\n";
|
|
2
2
|
//# sourceMappingURL=kernel.d.ts.map
|
package/kernel.js
CHANGED
|
@@ -8,8 +8,7 @@ const KERNEL = `
|
|
|
8
8
|
; functional composition for 1-arg fns
|
|
9
9
|
(defn comp (f g) (fn (x) (f (g x))))
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
(defn comp2 (f g) (fn (x y z) (f (g x y) z)))
|
|
11
|
+
(defn complement (f) (fn (x) (not (f x))))
|
|
13
12
|
|
|
14
13
|
; calls f if x is nullish
|
|
15
14
|
(defn fnull? (x f) (if (null? x) (f) x))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/lispy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Lightweight, extensible, interpreted Lisp-style DSL for embedding in other projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -39,19 +39,19 @@
|
|
|
39
39
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@thi.ng/api": "^8.11.
|
|
43
|
-
"@thi.ng/checks": "^3.7.
|
|
44
|
-
"@thi.ng/compare": "^2.4.
|
|
45
|
-
"@thi.ng/defmulti": "^3.0.
|
|
46
|
-
"@thi.ng/errors": "^2.5.
|
|
47
|
-
"@thi.ng/math": "^5.11.
|
|
48
|
-
"@thi.ng/object-utils": "^1.1.
|
|
49
|
-
"@thi.ng/sexpr": "^1.0.
|
|
50
|
-
"@thi.ng/strings": "^3.9.
|
|
42
|
+
"@thi.ng/api": "^8.11.29",
|
|
43
|
+
"@thi.ng/checks": "^3.7.9",
|
|
44
|
+
"@thi.ng/compare": "^2.4.21",
|
|
45
|
+
"@thi.ng/defmulti": "^3.0.69",
|
|
46
|
+
"@thi.ng/errors": "^2.5.35",
|
|
47
|
+
"@thi.ng/math": "^5.11.29",
|
|
48
|
+
"@thi.ng/object-utils": "^1.1.25",
|
|
49
|
+
"@thi.ng/sexpr": "^1.0.19",
|
|
50
|
+
"@thi.ng/strings": "^3.9.14"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"esbuild": "^0.25.
|
|
54
|
-
"typedoc": "^0.28.
|
|
53
|
+
"esbuild": "^0.25.5",
|
|
54
|
+
"typedoc": "^0.28.5",
|
|
55
55
|
"typescript": "^5.8.3"
|
|
56
56
|
},
|
|
57
57
|
"keywords": [
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
"status": "beta",
|
|
97
97
|
"year": 2023
|
|
98
98
|
},
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "93cdcd8db4d4669561a7f0ebc47697bdbfd04214\n"
|
|
100
100
|
}
|