conjure-js 0.0.12 → 0.0.13
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/dist-cli/conjure-js.mjs +9360 -5298
- package/dist-vite-plugin/index.mjs +9463 -5185
- package/package.json +3 -1
- package/src/bin/cli.ts +2 -2
- package/src/bin/nrepl-symbol.ts +150 -0
- package/src/bin/nrepl.ts +289 -167
- package/src/bin/version.ts +1 -1
- package/src/clojure/core.clj +757 -29
- package/src/clojure/core.clj.d.ts +75 -131
- package/src/clojure/generated/builtin-namespace-registry.ts +4 -0
- package/src/clojure/generated/clojure-core-source.ts +758 -29
- package/src/clojure/generated/clojure-set-source.ts +136 -0
- package/src/clojure/generated/clojure-walk-source.ts +72 -0
- package/src/clojure/set.clj +132 -0
- package/src/clojure/set.clj.d.ts +20 -0
- package/src/clojure/string.clj.d.ts +14 -0
- package/src/clojure/walk.clj +68 -0
- package/src/clojure/walk.clj.d.ts +7 -0
- package/src/core/assertions.ts +114 -6
- package/src/core/bootstrap.ts +337 -0
- package/src/core/conversions.ts +48 -31
- package/src/core/core-module.ts +303 -0
- package/src/core/env.ts +20 -6
- package/src/core/evaluator/apply.ts +40 -25
- package/src/core/evaluator/arity.ts +8 -8
- package/src/core/evaluator/async-evaluator.ts +565 -0
- package/src/core/evaluator/collections.ts +28 -5
- package/src/core/evaluator/destructure.ts +180 -69
- package/src/core/evaluator/dispatch.ts +12 -14
- package/src/core/evaluator/evaluate.ts +22 -20
- package/src/core/evaluator/expand.ts +45 -15
- package/src/core/evaluator/form-parsers.ts +178 -0
- package/src/core/evaluator/index.ts +7 -9
- package/src/core/evaluator/js-interop.ts +189 -0
- package/src/core/evaluator/quasiquote.ts +14 -8
- package/src/core/evaluator/recur-check.ts +6 -6
- package/src/core/evaluator/special-forms.ts +234 -191
- package/src/core/factories.ts +182 -3
- package/src/core/index.ts +54 -4
- package/src/core/module.ts +136 -0
- package/src/core/ns-forms.ts +107 -0
- package/src/core/printer.ts +371 -11
- package/src/core/reader.ts +84 -33
- package/src/core/registry.ts +209 -0
- package/src/core/runtime.ts +376 -0
- package/src/core/session.ts +253 -487
- package/src/core/stdlib/arithmetic.ts +528 -194
- package/src/core/stdlib/async-fns.ts +132 -0
- package/src/core/stdlib/atoms.ts +291 -56
- package/src/core/stdlib/errors.ts +54 -50
- package/src/core/stdlib/hof.ts +82 -166
- package/src/core/stdlib/js-namespace.ts +344 -0
- package/src/core/stdlib/lazy.ts +34 -0
- package/src/core/stdlib/maps-sets.ts +322 -0
- package/src/core/stdlib/meta.ts +61 -30
- package/src/core/stdlib/predicates.ts +325 -187
- package/src/core/stdlib/regex.ts +126 -98
- package/src/core/stdlib/seq.ts +564 -0
- package/src/core/stdlib/strings.ts +164 -135
- package/src/core/stdlib/transducers.ts +95 -100
- package/src/core/stdlib/utils.ts +292 -130
- package/src/core/stdlib/vars.ts +27 -27
- package/src/core/stdlib/vectors.ts +122 -0
- package/src/core/tokenizer.ts +2 -2
- package/src/core/transformations.ts +117 -9
- package/src/core/types.ts +98 -2
- package/src/host/node-host-module.ts +74 -0
- package/src/{vite-plugin-clj/nrepl-relay.ts → nrepl/relay.ts} +72 -11
- package/src/vite-plugin-clj/codegen.ts +87 -95
- package/src/vite-plugin-clj/index.ts +178 -23
- package/src/vite-plugin-clj/namespace-utils.ts +39 -0
- package/src/vite-plugin-clj/static-analysis.ts +211 -0
- package/src/clojure/demo.clj +0 -72
- package/src/clojure/demo.clj.d.ts +0 -0
- package/src/core/core-env.ts +0 -61
- package/src/core/stdlib/collections.ts +0 -739
- package/src/host/node.ts +0 -55
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
// Transducer protocol primitives: reduced, volatile!, transduce
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
isAFunction,
|
|
5
|
-
isNil,
|
|
6
|
-
isReduced,
|
|
7
|
-
isSeqable,
|
|
8
|
-
isVolatile,
|
|
9
|
-
} from '../assertions'
|
|
3
|
+
import { is } from '../assertions'
|
|
10
4
|
import { EvaluationError } from '../errors'
|
|
11
|
-
import {
|
|
12
|
-
cljBoolean,
|
|
13
|
-
cljNativeFunction,
|
|
14
|
-
cljNativeFunctionWithContext,
|
|
15
|
-
cljReduced,
|
|
16
|
-
cljVolatile,
|
|
17
|
-
withDoc,
|
|
18
|
-
} from '../factories'
|
|
5
|
+
import { v } from '../factories'
|
|
19
6
|
import { joinLines, printString } from '../printer'
|
|
20
7
|
import { toSeq } from '../transformations'
|
|
21
8
|
import type {
|
|
@@ -28,71 +15,76 @@ import type {
|
|
|
28
15
|
|
|
29
16
|
export const transducerFunctions: Record<string, CljValue> = {
|
|
30
17
|
// ── Reduced sentinel ────────────────────────────────────────────────────
|
|
31
|
-
reduced:
|
|
32
|
-
|
|
18
|
+
reduced: v
|
|
19
|
+
.nativeFn('reduced', function reducedImpl(value: CljValue) {
|
|
33
20
|
if (value === undefined) {
|
|
34
21
|
throw new EvaluationError('reduced expects one argument', {})
|
|
35
22
|
}
|
|
36
|
-
return
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
23
|
+
return v.reduced(value)
|
|
24
|
+
})
|
|
25
|
+
.doc(
|
|
26
|
+
'Returns a reduced value, indicating termination of the reduction process.',
|
|
27
|
+
[['value']]
|
|
28
|
+
),
|
|
29
|
+
'reduced?': v
|
|
30
|
+
.nativeFn('reduced?', function isReducedImpl(value: CljValue) {
|
|
43
31
|
if (value === undefined) {
|
|
44
32
|
throw new EvaluationError('reduced? expects one argument', {})
|
|
45
33
|
}
|
|
46
|
-
return
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
34
|
+
return v.boolean(is.reduced(value))
|
|
35
|
+
})
|
|
36
|
+
.doc(
|
|
37
|
+
'Returns true if the given value is a reduced value, false otherwise.',
|
|
38
|
+
[['value']]
|
|
39
|
+
),
|
|
40
|
+
unreduced: v
|
|
41
|
+
.nativeFn('unreduced', function unreducedImpl(value: CljValue) {
|
|
53
42
|
if (value === undefined) {
|
|
54
43
|
throw new EvaluationError('unreduced expects one argument', {})
|
|
55
44
|
}
|
|
56
|
-
return
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
45
|
+
return is.reduced(value) ? value.value : value
|
|
46
|
+
})
|
|
47
|
+
.doc(
|
|
48
|
+
'Returns the unreduced value of the given value. If the value is not a reduced value, it is returned unchanged.',
|
|
49
|
+
[['value']]
|
|
50
|
+
),
|
|
51
|
+
'ensure-reduced': v
|
|
52
|
+
.nativeFn('ensure-reduced', function ensureReducedImpl(value: CljValue) {
|
|
63
53
|
if (value === undefined) {
|
|
64
54
|
throw new EvaluationError('ensure-reduced expects one argument', {})
|
|
65
55
|
}
|
|
66
|
-
return
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
56
|
+
return is.reduced(value) ? value : v.reduced(value)
|
|
57
|
+
})
|
|
58
|
+
.doc(
|
|
59
|
+
'Returns the given value if it is a reduced value, otherwise returns a reduced value with the given value as its value.',
|
|
60
|
+
[['value']]
|
|
61
|
+
),
|
|
71
62
|
|
|
72
63
|
// ── Volatile ─────────────────────────────────────────────────────────────
|
|
73
|
-
'volatile!':
|
|
74
|
-
|
|
64
|
+
'volatile!': v
|
|
65
|
+
.nativeFn('volatile!', function volatileImpl(value: CljValue) {
|
|
75
66
|
if (value === undefined) {
|
|
76
67
|
throw new EvaluationError('volatile! expects one argument', {})
|
|
77
68
|
}
|
|
78
|
-
return
|
|
79
|
-
})
|
|
80
|
-
'Returns a volatile value with the given value as its value.',
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
'volatile?':
|
|
84
|
-
|
|
69
|
+
return v.volatile(value)
|
|
70
|
+
})
|
|
71
|
+
.doc('Returns a volatile value with the given value as its value.', [
|
|
72
|
+
['value'],
|
|
73
|
+
]),
|
|
74
|
+
'volatile?': v
|
|
75
|
+
.nativeFn('volatile?', function isVolatileImpl(value: CljValue) {
|
|
85
76
|
if (value === undefined) {
|
|
86
77
|
throw new EvaluationError('volatile? expects one argument', {})
|
|
87
78
|
}
|
|
88
|
-
return
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
79
|
+
return v.boolean(is.volatile(value))
|
|
80
|
+
})
|
|
81
|
+
.doc(
|
|
82
|
+
'Returns true if the given value is a volatile value, false otherwise.',
|
|
83
|
+
[['value']]
|
|
84
|
+
),
|
|
85
|
+
'vreset!': v
|
|
86
|
+
.nativeFn('vreset!', function vresetImpl(vol: CljValue, newVal: CljValue) {
|
|
87
|
+
if (!is.volatile(vol)) {
|
|
96
88
|
throw new EvaluationError(
|
|
97
89
|
`vreset! expects a volatile as its first argument, got ${printString(vol)}`,
|
|
98
90
|
{ vol }
|
|
@@ -103,27 +95,28 @@ export const transducerFunctions: Record<string, CljValue> = {
|
|
|
103
95
|
}
|
|
104
96
|
vol.value = newVal
|
|
105
97
|
return newVal
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
98
|
+
})
|
|
99
|
+
.doc(
|
|
100
|
+
'Resets the value of the given volatile to the given new value and returns the new value.',
|
|
101
|
+
[['vol', 'newVal']]
|
|
102
|
+
),
|
|
103
|
+
'vswap!': v
|
|
104
|
+
.nativeFnCtx(
|
|
112
105
|
'vswap!',
|
|
113
|
-
(
|
|
106
|
+
function vswapImpl(
|
|
114
107
|
ctx: EvaluationContext,
|
|
115
108
|
callEnv: Env,
|
|
116
109
|
vol: CljValue,
|
|
117
110
|
fn: CljValue,
|
|
118
111
|
...extraArgs: CljValue[]
|
|
119
|
-
)
|
|
120
|
-
if (!
|
|
112
|
+
) {
|
|
113
|
+
if (!is.volatile(vol)) {
|
|
121
114
|
throw new EvaluationError(
|
|
122
115
|
`vswap! expects a volatile as its first argument, got ${printString(vol)}`,
|
|
123
116
|
{ vol }
|
|
124
117
|
)
|
|
125
118
|
}
|
|
126
|
-
if (!
|
|
119
|
+
if (!is.aFunction(fn)) {
|
|
127
120
|
throw new EvaluationError(
|
|
128
121
|
`vswap! expects a function as its second argument, got ${printString(fn)}`,
|
|
129
122
|
{ fn }
|
|
@@ -137,13 +130,14 @@ export const transducerFunctions: Record<string, CljValue> = {
|
|
|
137
130
|
vol.value = newVal
|
|
138
131
|
return newVal
|
|
139
132
|
}
|
|
133
|
+
)
|
|
134
|
+
.doc(
|
|
135
|
+
'Applies fn to the current value of the volatile, replacing the current value with the result. Returns the new value.',
|
|
136
|
+
[
|
|
137
|
+
['vol', 'fn'],
|
|
138
|
+
['vol', 'fn', '&', 'extraArgs'],
|
|
139
|
+
]
|
|
140
140
|
),
|
|
141
|
-
'Applies fn to the current value of the volatile, replacing the current value with the result. Returns the new value.',
|
|
142
|
-
[
|
|
143
|
-
['vol', 'fn'],
|
|
144
|
-
['vol', 'fn', '&', 'extraArgs'],
|
|
145
|
-
]
|
|
146
|
-
),
|
|
147
141
|
|
|
148
142
|
// ── transduce ─────────────────────────────────────────────────────────────
|
|
149
143
|
|
|
@@ -153,24 +147,24 @@ export const transducerFunctions: Record<string, CljValue> = {
|
|
|
153
147
|
// f — bottom reducing function (must support 0-arity when used as 3-arity)
|
|
154
148
|
// init — initial accumulator value
|
|
155
149
|
// coll — source collection (nil is treated as empty)
|
|
156
|
-
transduce:
|
|
157
|
-
|
|
150
|
+
transduce: v
|
|
151
|
+
.nativeFnCtx(
|
|
158
152
|
'transduce',
|
|
159
|
-
(
|
|
153
|
+
function transduceImpl(
|
|
160
154
|
ctx: EvaluationContext,
|
|
161
155
|
callEnv: Env,
|
|
162
156
|
xform: CljValue,
|
|
163
157
|
f: CljValue,
|
|
164
158
|
init: CljValue,
|
|
165
159
|
coll: CljValue
|
|
166
|
-
)
|
|
167
|
-
if (!
|
|
160
|
+
) {
|
|
161
|
+
if (!is.aFunction(xform)) {
|
|
168
162
|
throw new EvaluationError(
|
|
169
163
|
`transduce expects a transducer (function) as first argument, got ${printString(xform)}`,
|
|
170
164
|
{ xf: xform }
|
|
171
165
|
)
|
|
172
166
|
}
|
|
173
|
-
if (!
|
|
167
|
+
if (!is.aFunction(f)) {
|
|
174
168
|
throw new EvaluationError(
|
|
175
169
|
`transduce expects a reducing function as second argument, got ${printString(f)}`,
|
|
176
170
|
{ f }
|
|
@@ -206,7 +200,7 @@ export const transducerFunctions: Record<string, CljValue> = {
|
|
|
206
200
|
) as CljFunction | CljNativeFunction
|
|
207
201
|
|
|
208
202
|
// nil collection is treated as empty — skip loop, run completion only
|
|
209
|
-
if (
|
|
203
|
+
if (is.nil(actualColl)) {
|
|
210
204
|
return ctx.applyFunction(
|
|
211
205
|
rf as CljFunction | CljNativeFunction,
|
|
212
206
|
[actualInit],
|
|
@@ -214,7 +208,7 @@ export const transducerFunctions: Record<string, CljValue> = {
|
|
|
214
208
|
)
|
|
215
209
|
}
|
|
216
210
|
|
|
217
|
-
if (!
|
|
211
|
+
if (!is.seqable(actualColl)) {
|
|
218
212
|
throw new EvaluationError(
|
|
219
213
|
`transduce expects a collection or string as ${coll === undefined ? 'third' : 'fourth'} argument, got ${printString(actualColl)}`,
|
|
220
214
|
{ coll: actualColl }
|
|
@@ -227,7 +221,7 @@ export const transducerFunctions: Record<string, CljValue> = {
|
|
|
227
221
|
for (const item of items) {
|
|
228
222
|
// 2-arity call on the composed rf
|
|
229
223
|
const result = ctx.applyFunction(rf, [acc, item], callEnv)
|
|
230
|
-
if (
|
|
224
|
+
if (is.reduced(result)) {
|
|
231
225
|
acc = result.value
|
|
232
226
|
break
|
|
233
227
|
}
|
|
@@ -237,20 +231,21 @@ export const transducerFunctions: Record<string, CljValue> = {
|
|
|
237
231
|
// Completion (1-arity call on the composed rf)
|
|
238
232
|
return ctx.applyFunction(rf, [acc], callEnv)
|
|
239
233
|
}
|
|
234
|
+
)
|
|
235
|
+
.doc(
|
|
236
|
+
joinLines([
|
|
237
|
+
'reduce with a transformation of f (xf). If init is not',
|
|
238
|
+
'supplied, (f) will be called to produce it. f should be a reducing',
|
|
239
|
+
'step function that accepts both 1 and 2 arguments, if it accepts',
|
|
240
|
+
"only 2 you can add the arity-1 with 'completing'. Returns the result",
|
|
241
|
+
'of applying (the transformed) xf to init and the first item in coll,',
|
|
242
|
+
'then applying xf to that result and the 2nd item, etc. If coll',
|
|
243
|
+
'contains no items, returns init and f is not called. Note that',
|
|
244
|
+
'certain transforms may inject or skip items.',
|
|
245
|
+
]),
|
|
246
|
+
[
|
|
247
|
+
['xform', 'f', 'coll'],
|
|
248
|
+
['xform', 'f', 'init', 'coll'],
|
|
249
|
+
]
|
|
240
250
|
),
|
|
241
|
-
joinLines([
|
|
242
|
-
'reduce with a transformation of f (xf). If init is not',
|
|
243
|
-
'supplied, (f) will be called to produce it. f should be a reducing',
|
|
244
|
-
'step function that accepts both 1 and 2 arguments, if it accepts',
|
|
245
|
-
"only 2 you can add the arity-1 with 'completing'. Returns the result",
|
|
246
|
-
'of applying (the transformed) xf to init and the first item in coll,',
|
|
247
|
-
'then applying xf to that result and the 2nd item, etc. If coll',
|
|
248
|
-
'contains no items, returns init and f is not called. Note that',
|
|
249
|
-
'certain transforms may inject or skip items.',
|
|
250
|
-
]),
|
|
251
|
-
[
|
|
252
|
-
['xform', 'f', 'coll'],
|
|
253
|
-
['xform', 'f', 'init', 'coll'],
|
|
254
|
-
]
|
|
255
|
-
),
|
|
256
251
|
}
|