eliscript 0.0.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/LICENSE +674 -0
- package/README.md +135 -0
- package/bin/eliscript +16 -0
- package/bin/eliscript-bootstrap +15 -0
- package/bin/eliscript-build +15 -0
- package/bin/eliscript-check +15 -0
- package/bin/eliscript-eval +15 -0
- package/bin/eliscript-format +15 -0
- package/bin/eliscript-org +10 -0
- package/bin/eliscript-portable +17 -0
- package/bin/eliscript-seed +10 -0
- package/bin/eliscript-seed-build +10 -0
- package/bin/eliscript-watch +15 -0
- package/bootstrap/README.md +100 -0
- package/bootstrap/compiler/analyzer.eli +1426 -0
- package/bootstrap/compiler/compiler.eli +472 -0
- package/bootstrap/compiler/emitter.eli +1745 -0
- package/bootstrap/compiler/expander.eli +2522 -0
- package/bootstrap/compiler/formatter.eli +359 -0
- package/bootstrap/compiler/ir.eli +297 -0
- package/bootstrap/compiler/lower.eli +661 -0
- package/bootstrap/compiler/project.eli +1120 -0
- package/bootstrap/compiler/reader.eli +321 -0
- package/bootstrap/compiler/source-map.eli +165 -0
- package/bootstrap/compiler/symbol.eli +92 -0
- package/bootstrap/compiler/syntax.eli +54 -0
- package/bootstrap/compiler/transient-analysis.eli +825 -0
- package/bootstrap/host/build.mjs +28 -0
- package/bootstrap/host/bun.mjs +282 -0
- package/bootstrap/host/check-cli.mjs +163 -0
- package/bootstrap/host/eliscript-cli.mjs +36 -0
- package/bootstrap/host/evaluation-cli.mjs +401 -0
- package/bootstrap/host/evaluation.mjs +560 -0
- package/bootstrap/host/format-cli.mjs +139 -0
- package/bootstrap/host/project-cli.mjs +295 -0
- package/bootstrap/host/project.mjs +1080 -0
- package/bootstrap/host/watch-cli.mjs +129 -0
- package/bootstrap/host/watch.mjs +267 -0
- package/browser/host.mjs +357 -0
- package/browser/worker.mjs +60 -0
- package/compiler/README.md +118 -0
- package/compiler/eliscript-analyzer.el +716 -0
- package/compiler/eliscript-cli.el +108 -0
- package/compiler/eliscript-diagnostic.el +158 -0
- package/compiler/eliscript-emitter.el +1351 -0
- package/compiler/eliscript-evaluation.el +259 -0
- package/compiler/eliscript-expander.el +1630 -0
- package/compiler/eliscript-form.el +79 -0
- package/compiler/eliscript-ir-emitter.el +1460 -0
- package/compiler/eliscript-ir.el +356 -0
- package/compiler/eliscript-lower.el +463 -0
- package/compiler/eliscript-macro-eval.el +811 -0
- package/compiler/eliscript-parameters.el +324 -0
- package/compiler/eliscript-portable.el +492 -0
- package/compiler/eliscript-project-cli.el +156 -0
- package/compiler/eliscript-project.el +1676 -0
- package/compiler/eliscript-reader.el +421 -0
- package/compiler/eliscript-source-map.el +192 -0
- package/compiler/eliscript-symbol.el +101 -0
- package/compiler/eliscript-transient-analysis.el +817 -0
- package/compiler/eliscript.el +239 -0
- package/dist/bootstrap/analyzer.mjs +968 -0
- package/dist/bootstrap/analyzer.mjs.map +1 -0
- package/dist/bootstrap/compiler.mjs +228 -0
- package/dist/bootstrap/compiler.mjs.map +1 -0
- package/dist/bootstrap/emitter.mjs +1173 -0
- package/dist/bootstrap/emitter.mjs.map +1 -0
- package/dist/bootstrap/expander.mjs +1469 -0
- package/dist/bootstrap/expander.mjs.map +1 -0
- package/dist/bootstrap/formatter.mjs +304 -0
- package/dist/bootstrap/formatter.mjs.map +1 -0
- package/dist/bootstrap/ir.mjs +193 -0
- package/dist/bootstrap/ir.mjs.map +1 -0
- package/dist/bootstrap/lower.mjs +344 -0
- package/dist/bootstrap/lower.mjs.map +1 -0
- package/dist/bootstrap/project.mjs +585 -0
- package/dist/bootstrap/project.mjs.map +1 -0
- package/dist/bootstrap/reader.mjs +259 -0
- package/dist/bootstrap/reader.mjs.map +1 -0
- package/dist/bootstrap/source-map.mjs +154 -0
- package/dist/bootstrap/source-map.mjs.map +1 -0
- package/dist/bootstrap/symbol.mjs +74 -0
- package/dist/bootstrap/symbol.mjs.map +1 -0
- package/dist/bootstrap/syntax.mjs +38 -0
- package/dist/bootstrap/syntax.mjs.map +1 -0
- package/dist/bootstrap/transient-analysis.mjs +660 -0
- package/dist/bootstrap/transient-analysis.mjs.map +1 -0
- package/dist/browser/compiler.js +6491 -0
- package/editor/README.md +83 -0
- package/editor/eliscript-mode.el +878 -0
- package/editor/eliscript-repl.el +501 -0
- package/package.json +163 -0
- package/platform/README.md +48 -0
- package/platform/browser.mjs +204 -0
- package/platform/worker.mjs +166 -0
- package/runtime/README.md +296 -0
- package/runtime/core/collection-internals.mjs +512 -0
- package/runtime/core/collection.mjs +645 -0
- package/runtime/core/data-text.mjs +532 -0
- package/runtime/core/data.mjs +268 -0
- package/runtime/core/identifier.mjs +314 -0
- package/runtime/core/lazy-sequence.mjs +244 -0
- package/runtime/core/list-internals.mjs +18 -0
- package/runtime/core/list.mjs +273 -0
- package/runtime/core/map-internals.mjs +793 -0
- package/runtime/core/map.mjs +394 -0
- package/runtime/core/metadata-internals.mjs +14 -0
- package/runtime/core/metadata.mjs +44 -0
- package/runtime/core/object-impl.mjs +65 -0
- package/runtime/core/object-impl.mjs.map +1 -0
- package/runtime/core/object.mjs +13 -0
- package/runtime/core/order.mjs +234 -0
- package/runtime/core/persistent-kind.mjs +43 -0
- package/runtime/core/protocol-error.mjs +36 -0
- package/runtime/core/protocol-impl.mjs +326 -0
- package/runtime/core/protocol-impl.mjs.map +1 -0
- package/runtime/core/protocol.mjs +14 -0
- package/runtime/core/queue-internals.mjs +27 -0
- package/runtime/core/queue.mjs +238 -0
- package/runtime/core/record.mjs +346 -0
- package/runtime/core/regex.mjs +184 -0
- package/runtime/core/sequence.mjs +632 -0
- package/runtime/core/set-algebra.mjs +287 -0
- package/runtime/core/set-internals.mjs +33 -0
- package/runtime/core/set.mjs +378 -0
- package/runtime/core/sorted-internals.mjs +215 -0
- package/runtime/core/sorted.mjs +598 -0
- package/runtime/core/text-impl.mjs +95 -0
- package/runtime/core/text-impl.mjs.map +1 -0
- package/runtime/core/text.mjs +15 -0
- package/runtime/core/transducer.mjs +668 -0
- package/runtime/core/transient-internals.mjs +38 -0
- package/runtime/core/transient.mjs +53 -0
- package/runtime/core/truth.mjs +3 -0
- package/runtime/core/type.mjs +262 -0
- package/runtime/core/value-internals.mjs +188 -0
- package/runtime/core/value.mjs +93 -0
- package/runtime/core/vector-internals.mjs +102 -0
- package/runtime/core/vector.mjs +951 -0
- package/runtime/literals.mjs +34 -0
- package/runtime/source-mapping.mjs +220 -0
- package/runtime/testing/list.mjs +52 -0
- package/runtime/testing/map.mjs +145 -0
- package/runtime/testing/queue.mjs +49 -0
- package/runtime/testing/set.mjs +61 -0
- package/runtime/testing/sorted.mjs +105 -0
- package/runtime/testing/value.mjs +17 -0
- package/runtime/testing/vector.mjs +102 -0
- package/runtime/worker-value-codec.mjs +565 -0
- package/runtime/worker-value-stream.mjs +786 -0
- package/runtime/worker.mjs +975 -0
- package/stdlib/README.md +774 -0
- package/stdlib/bit.eli +36 -0
- package/stdlib/core/collection.eli +134 -0
- package/stdlib/core/data-text.eli +16 -0
- package/stdlib/core/data.eli +306 -0
- package/stdlib/core/identifier.eli +32 -0
- package/stdlib/core/lazy-sequence.eli +63 -0
- package/stdlib/core/metadata.eli +20 -0
- package/stdlib/core/object.eli +89 -0
- package/stdlib/core/order.eli +133 -0
- package/stdlib/core/protocol.eli +387 -0
- package/stdlib/core/record.eli +16 -0
- package/stdlib/core/regex.eli +17 -0
- package/stdlib/core/seq.eli +701 -0
- package/stdlib/core/set.eli +312 -0
- package/stdlib/core/sorted.eli +53 -0
- package/stdlib/core/text.eli +103 -0
- package/stdlib/core/transducer.eli +59 -0
- package/stdlib/core/transient.eli +24 -0
- package/stdlib/core/type.eli +19 -0
- package/stdlib/core/walk.eli +195 -0
- package/stdlib/core/zipper.eli +508 -0
- package/stdlib/data-text.eli +1092 -0
- package/stdlib/data.eli +42 -0
- package/stdlib/deferred.eli +70 -0
- package/stdlib/function.eli +120 -0
- package/stdlib/hierarchy.eli +245 -0
- package/stdlib/identifier.eli +147 -0
- package/stdlib/interop/js.eli +616 -0
- package/stdlib/json.eli +870 -0
- package/stdlib/metadata.eli +56 -0
- package/stdlib/multimethod.eli +464 -0
- package/stdlib/numeric.eli +193 -0
- package/stdlib/object.eli +96 -0
- package/stdlib/persistent-list.eli +145 -0
- package/stdlib/persistent-map.eli +724 -0
- package/stdlib/persistent-queue.eli +32 -0
- package/stdlib/persistent-set.eli +236 -0
- package/stdlib/persistent-vector.eli +342 -0
- package/stdlib/result.eli +141 -0
- package/stdlib/sequence.eli +106 -0
- package/stdlib/state/atom.eli +265 -0
- package/stdlib/text.eli +88 -0
- package/stdlib/value.eli +325 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
(module eliscript.core.set
|
|
2
|
+
(import "../../runtime/core/collection.mjs" :as Collection)
|
|
3
|
+
(import "../../runtime/core/data.mjs" keys merge selectKeys vals)
|
|
4
|
+
(import "../../runtime/core/map.mjs" EMPTY_MAP)
|
|
5
|
+
(import "../../runtime/core/metadata.mjs" meta withMeta)
|
|
6
|
+
(import "../../runtime/core/set.mjs" EMPTY_SET isPersistentHashSet)
|
|
7
|
+
(import "../../runtime/core/transient.mjs"
|
|
8
|
+
assocBang
|
|
9
|
+
conjBang
|
|
10
|
+
dissocBang
|
|
11
|
+
persistentBang
|
|
12
|
+
transient)
|
|
13
|
+
(import "../../runtime/core/truth.mjs" isTruthy)
|
|
14
|
+
(defconst not-found (js-object))
|
|
15
|
+
(defun require-arity
|
|
16
|
+
(arguments expected label)
|
|
17
|
+
(when (not (= (js-length arguments) expected))
|
|
18
|
+
(throw
|
|
19
|
+
(new
|
|
20
|
+
globalThis/TypeError
|
|
21
|
+
(str
|
|
22
|
+
label
|
|
23
|
+
" expects "
|
|
24
|
+
expected
|
|
25
|
+
(if (= expected 1) " collection" " collections"))))))
|
|
26
|
+
(defun require-non-empty
|
|
27
|
+
(arguments label)
|
|
28
|
+
(when (= (js-length arguments) 0)
|
|
29
|
+
(throw (new globalThis/TypeError (str label " expects at least one collection")))))
|
|
30
|
+
(defun require-function
|
|
31
|
+
(value label)
|
|
32
|
+
(if (= (value-type value) "function")
|
|
33
|
+
value
|
|
34
|
+
(throw (new globalThis/TypeError (str label " must be a function")))))
|
|
35
|
+
(defun require-join-arity
|
|
36
|
+
(arguments)
|
|
37
|
+
(unless (or (= (js-length arguments) 2) (= (js-length arguments) 3))
|
|
38
|
+
(throw (new globalThis/TypeError "join expects 2 or 3 relations"))))
|
|
39
|
+
(defun persistent-map (collection) (withMeta (merge collection) (meta collection)))
|
|
40
|
+
(defun first-value
|
|
41
|
+
(collection)
|
|
42
|
+
(Collection/reduce
|
|
43
|
+
collection
|
|
44
|
+
(lambda (_missing value) (Collection/reduced (js-object :value value)))
|
|
45
|
+
not-found))
|
|
46
|
+
(defun set
|
|
47
|
+
(&rest arguments)
|
|
48
|
+
(require-arity arguments 1 "set")
|
|
49
|
+
(let ((collection (js-nth 0 arguments)))
|
|
50
|
+
(if (isPersistentHashSet collection)
|
|
51
|
+
collection
|
|
52
|
+
(let ((result (transient EMPTY_SET)))
|
|
53
|
+
(Collection/reduce
|
|
54
|
+
collection
|
|
55
|
+
(lambda (builder value) (conjBang builder value) builder)
|
|
56
|
+
result)
|
|
57
|
+
(persistentBang result)))))
|
|
58
|
+
(defun union
|
|
59
|
+
(&rest collections)
|
|
60
|
+
(if (= (js-length collections) 0)
|
|
61
|
+
EMPTY_SET
|
|
62
|
+
(let ((result (transient (set (js-nth 0 collections)))) (index 1))
|
|
63
|
+
(while (< index (js-length collections))
|
|
64
|
+
(Collection/reduce
|
|
65
|
+
(js-nth index collections)
|
|
66
|
+
(lambda (builder value) (conjBang builder value) builder)
|
|
67
|
+
result)
|
|
68
|
+
(setq index (1+ index)))
|
|
69
|
+
(persistentBang result))))
|
|
70
|
+
(defun intersect-pair
|
|
71
|
+
(left right)
|
|
72
|
+
(let*
|
|
73
|
+
((left-set (set left))
|
|
74
|
+
(right-set (set right))
|
|
75
|
+
(candidates
|
|
76
|
+
(if (<= (Collection/count left-set) (Collection/count right-set))
|
|
77
|
+
left-set
|
|
78
|
+
right-set))
|
|
79
|
+
(membership (if (eq candidates left-set) right-set left-set))
|
|
80
|
+
(builder (transient (Collection/empty left-set))))
|
|
81
|
+
(Collection/reduce
|
|
82
|
+
candidates
|
|
83
|
+
(lambda
|
|
84
|
+
(result value)
|
|
85
|
+
(when (Collection/contains membership value) (conjBang result value))
|
|
86
|
+
result)
|
|
87
|
+
builder)
|
|
88
|
+
(let ((retained (persistentBang builder)))
|
|
89
|
+
(if (= (Collection/count retained) (Collection/count left-set))
|
|
90
|
+
left-set
|
|
91
|
+
retained))))
|
|
92
|
+
(defun intersection
|
|
93
|
+
(&rest collections)
|
|
94
|
+
(require-non-empty collections "intersection")
|
|
95
|
+
(let
|
|
96
|
+
((result (set (js-nth 0 collections))) (index 1) (size (js-length collections)))
|
|
97
|
+
(while (and (< index size) (> (Collection/count result) 0))
|
|
98
|
+
(setq
|
|
99
|
+
result
|
|
100
|
+
(intersect-pair result (js-nth index collections))
|
|
101
|
+
index
|
|
102
|
+
(1+ index)))
|
|
103
|
+
result))
|
|
104
|
+
(defun difference
|
|
105
|
+
(&rest collections)
|
|
106
|
+
(require-non-empty collections "difference")
|
|
107
|
+
(let
|
|
108
|
+
((result (transient (set (js-nth 0 collections))))
|
|
109
|
+
(index 1)
|
|
110
|
+
(size (js-length collections)))
|
|
111
|
+
(while (< index size)
|
|
112
|
+
(Collection/reduce
|
|
113
|
+
(js-nth index collections)
|
|
114
|
+
(lambda (builder value) (dissocBang builder value) builder)
|
|
115
|
+
result)
|
|
116
|
+
(setq index (1+ index)))
|
|
117
|
+
(persistentBang result)))
|
|
118
|
+
(defun subset?
|
|
119
|
+
(&rest arguments)
|
|
120
|
+
(require-arity arguments 2 "subset")
|
|
121
|
+
(let
|
|
122
|
+
((candidates (set (js-nth 0 arguments))) (membership (set (js-nth 1 arguments))))
|
|
123
|
+
(if (> (Collection/count candidates) (Collection/count membership))
|
|
124
|
+
false
|
|
125
|
+
(Collection/reduce
|
|
126
|
+
candidates
|
|
127
|
+
(lambda
|
|
128
|
+
(result value)
|
|
129
|
+
(if (Collection/contains membership value)
|
|
130
|
+
result
|
|
131
|
+
(Collection/reduced false)))
|
|
132
|
+
t))))
|
|
133
|
+
(defun superset?
|
|
134
|
+
(&rest arguments)
|
|
135
|
+
(require-arity arguments 2 "superset")
|
|
136
|
+
(subset? (js-nth 1 arguments) (js-nth 0 arguments)))
|
|
137
|
+
(defun disjoint?
|
|
138
|
+
(&rest arguments)
|
|
139
|
+
(require-arity arguments 2 "disjoint")
|
|
140
|
+
(let*
|
|
141
|
+
((left-set (set (js-nth 0 arguments)))
|
|
142
|
+
(right-set (set (js-nth 1 arguments)))
|
|
143
|
+
(candidates
|
|
144
|
+
(if (<= (Collection/count left-set) (Collection/count right-set))
|
|
145
|
+
left-set
|
|
146
|
+
right-set))
|
|
147
|
+
(membership (if (eq candidates left-set) right-set left-set)))
|
|
148
|
+
(Collection/reduce
|
|
149
|
+
candidates
|
|
150
|
+
(lambda
|
|
151
|
+
(result value)
|
|
152
|
+
(if (Collection/contains membership value) (Collection/reduced false) result))
|
|
153
|
+
t)))
|
|
154
|
+
(defun select
|
|
155
|
+
(&rest arguments)
|
|
156
|
+
(require-arity arguments 2 "select")
|
|
157
|
+
(let*
|
|
158
|
+
((predicate (require-function (js-nth 0 arguments) "select predicate"))
|
|
159
|
+
(source (set (js-nth 1 arguments)))
|
|
160
|
+
(builder (transient source)))
|
|
161
|
+
(Collection/reduce
|
|
162
|
+
source
|
|
163
|
+
(lambda
|
|
164
|
+
(result value)
|
|
165
|
+
(unless (isTruthy (funcall predicate value)) (dissocBang result value))
|
|
166
|
+
result)
|
|
167
|
+
builder)
|
|
168
|
+
(let ((selected (persistentBang builder)))
|
|
169
|
+
(if (= (Collection/count selected) (Collection/count source)) source selected))))
|
|
170
|
+
(defun project
|
|
171
|
+
(&rest arguments)
|
|
172
|
+
(require-arity arguments 2 "project")
|
|
173
|
+
(let*
|
|
174
|
+
((source (set (js-nth 0 arguments)))
|
|
175
|
+
(key-set (set (js-nth 1 arguments)))
|
|
176
|
+
(builder (transient (Collection/empty source))))
|
|
177
|
+
(Collection/reduce
|
|
178
|
+
source
|
|
179
|
+
(lambda (result row) (conjBang result (selectKeys row key-set)) result)
|
|
180
|
+
builder)
|
|
181
|
+
(persistentBang builder)))
|
|
182
|
+
(defun rename-keys
|
|
183
|
+
(&rest arguments)
|
|
184
|
+
(require-arity arguments 2 "renameKeys")
|
|
185
|
+
(let*
|
|
186
|
+
((source (persistent-map (js-nth 0 arguments)))
|
|
187
|
+
(mappings (persistent-map (js-nth 1 arguments)))
|
|
188
|
+
(builder (transient source)))
|
|
189
|
+
(Collection/reduceKV
|
|
190
|
+
mappings
|
|
191
|
+
(lambda (result old-key _new-key) (dissocBang result old-key) result)
|
|
192
|
+
builder)
|
|
193
|
+
(Collection/reduceKV
|
|
194
|
+
mappings
|
|
195
|
+
(lambda
|
|
196
|
+
(result old-key new-key)
|
|
197
|
+
(when (Collection/contains source old-key)
|
|
198
|
+
(assocBang result new-key (Collection/get source old-key)))
|
|
199
|
+
result)
|
|
200
|
+
builder)
|
|
201
|
+
(persistentBang builder)))
|
|
202
|
+
(defun rename
|
|
203
|
+
(&rest arguments)
|
|
204
|
+
(require-arity arguments 2 "rename")
|
|
205
|
+
(let*
|
|
206
|
+
((source (set (js-nth 0 arguments)))
|
|
207
|
+
(mappings (persistent-map (js-nth 1 arguments)))
|
|
208
|
+
(builder (transient (Collection/empty source))))
|
|
209
|
+
(Collection/reduce
|
|
210
|
+
source
|
|
211
|
+
(lambda (result row) (conjBang result (rename-keys row mappings)) result)
|
|
212
|
+
builder)
|
|
213
|
+
(persistentBang builder)))
|
|
214
|
+
(defun index
|
|
215
|
+
(&rest arguments)
|
|
216
|
+
(require-arity arguments 2 "index")
|
|
217
|
+
(let ((source (set (js-nth 0 arguments))) (key-set (set (js-nth 1 arguments))))
|
|
218
|
+
(Collection/reduce
|
|
219
|
+
source
|
|
220
|
+
(lambda
|
|
221
|
+
(result row)
|
|
222
|
+
(let*
|
|
223
|
+
((indexed-key (selectKeys row key-set))
|
|
224
|
+
(group (Collection/get result indexed-key EMPTY_SET)))
|
|
225
|
+
(Collection/assoc result indexed-key (Collection/conj group row))))
|
|
226
|
+
EMPTY_MAP)))
|
|
227
|
+
(defun map-invert
|
|
228
|
+
(&rest arguments)
|
|
229
|
+
(require-arity arguments 1 "mapInvert")
|
|
230
|
+
(let ((collection (js-nth 0 arguments)) (builder (transient EMPTY_MAP)))
|
|
231
|
+
(Collection/reduceKV
|
|
232
|
+
collection
|
|
233
|
+
(lambda (result key value) (assocBang result value key) result)
|
|
234
|
+
builder)
|
|
235
|
+
(withMeta (persistentBang builder) (meta collection))))
|
|
236
|
+
(defun join-indexed
|
|
237
|
+
(probe indexed probe-keys key-map builder)
|
|
238
|
+
(Collection/reduce
|
|
239
|
+
probe
|
|
240
|
+
(lambda
|
|
241
|
+
(result row)
|
|
242
|
+
(let*
|
|
243
|
+
((selected (selectKeys row probe-keys))
|
|
244
|
+
(indexed-key (if (eq key-map nil) selected (rename-keys selected key-map)))
|
|
245
|
+
(matches (Collection/get indexed indexed-key EMPTY_SET)))
|
|
246
|
+
(Collection/reduce
|
|
247
|
+
matches
|
|
248
|
+
(lambda (output matched) (conjBang output (merge matched row)) output)
|
|
249
|
+
result)
|
|
250
|
+
result))
|
|
251
|
+
builder))
|
|
252
|
+
(defun join
|
|
253
|
+
(&rest arguments)
|
|
254
|
+
(require-join-arity arguments)
|
|
255
|
+
(let*
|
|
256
|
+
((left-set (set (js-nth 0 arguments)))
|
|
257
|
+
(right-set (set (js-nth 1 arguments)))
|
|
258
|
+
(builder (transient (Collection/empty left-set))))
|
|
259
|
+
(cond
|
|
260
|
+
((or (= (Collection/count left-set) 0) (= (Collection/count right-set) 0))
|
|
261
|
+
(persistentBang builder))
|
|
262
|
+
((= (js-length arguments) 2)
|
|
263
|
+
(let*
|
|
264
|
+
((left-row (get (first-value left-set) :value))
|
|
265
|
+
(right-row (get (first-value right-set) :value))
|
|
266
|
+
(join-keys (intersection (set (keys left-row)) (set (keys right-row))))
|
|
267
|
+
(indexed-relation
|
|
268
|
+
(if (<= (Collection/count left-set) (Collection/count right-set))
|
|
269
|
+
left-set
|
|
270
|
+
right-set))
|
|
271
|
+
(probe-relation (if (eq indexed-relation left-set) right-set left-set)))
|
|
272
|
+
(persistentBang
|
|
273
|
+
(join-indexed
|
|
274
|
+
probe-relation
|
|
275
|
+
(index indexed-relation join-keys)
|
|
276
|
+
join-keys
|
|
277
|
+
nil
|
|
278
|
+
builder))))
|
|
279
|
+
(t
|
|
280
|
+
(let*
|
|
281
|
+
((mappings (persistent-map (js-nth 2 arguments)))
|
|
282
|
+
(effective-map
|
|
283
|
+
(if (<= (Collection/count left-set) (Collection/count right-set))
|
|
284
|
+
(map-invert mappings)
|
|
285
|
+
mappings))
|
|
286
|
+
(indexed-relation
|
|
287
|
+
(if (<= (Collection/count left-set) (Collection/count right-set))
|
|
288
|
+
left-set
|
|
289
|
+
right-set))
|
|
290
|
+
(probe-relation (if (eq indexed-relation left-set) right-set left-set)))
|
|
291
|
+
(persistentBang
|
|
292
|
+
(join-indexed
|
|
293
|
+
probe-relation
|
|
294
|
+
(index indexed-relation (vals effective-map))
|
|
295
|
+
(keys effective-map)
|
|
296
|
+
effective-map
|
|
297
|
+
builder)))))))
|
|
298
|
+
(export
|
|
299
|
+
difference
|
|
300
|
+
disjoint?
|
|
301
|
+
index
|
|
302
|
+
intersection
|
|
303
|
+
join
|
|
304
|
+
map-invert
|
|
305
|
+
project
|
|
306
|
+
rename
|
|
307
|
+
rename-keys
|
|
308
|
+
select
|
|
309
|
+
set
|
|
310
|
+
subset?
|
|
311
|
+
superset?
|
|
312
|
+
union))
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
(module eliscript.core.sorted
|
|
2
|
+
(import "../../runtime/core/sorted.mjs" :as Runtime)
|
|
3
|
+
(defun empty-sorted-map () Runtime/EMPTY_SORTED_MAP)
|
|
4
|
+
(defun empty-sorted-map-by (comparison) (Runtime/emptySortedMapBy comparison))
|
|
5
|
+
(defun empty-sorted-set () Runtime/EMPTY_SORTED_SET)
|
|
6
|
+
(defun empty-sorted-set-by (comparison) (Runtime/emptySortedSetBy comparison))
|
|
7
|
+
(defun sorted-map (&rest key-values) (apply Runtime/persistentSortedMap key-values))
|
|
8
|
+
(defun sorted-map-by
|
|
9
|
+
(comparison &rest key-values)
|
|
10
|
+
(apply Runtime/persistentSortedMapBy (js-cons comparison key-values)))
|
|
11
|
+
(defun sorted-set (&rest values) (apply Runtime/persistentSortedSet values))
|
|
12
|
+
(defun sorted-set-by
|
|
13
|
+
(comparison &rest values)
|
|
14
|
+
(apply Runtime/persistentSortedSetBy (js-cons comparison values)))
|
|
15
|
+
(defun sorted-map? (value) (Runtime/isPersistentSortedMap value))
|
|
16
|
+
(defun sorted-set? (value) (Runtime/isPersistentSortedSet value))
|
|
17
|
+
(defun sorted? (value) (Runtime/isPersistentSortedCollection value))
|
|
18
|
+
(defun comparator (collection) (Runtime/sortedComparator collection))
|
|
19
|
+
(defun sorted-seq
|
|
20
|
+
(collection &rest direction)
|
|
21
|
+
(Runtime/sortedSequence
|
|
22
|
+
collection
|
|
23
|
+
(if (= (js-length direction) 0) t (js-nth 0 direction))))
|
|
24
|
+
(defun sorted-seq-from
|
|
25
|
+
(collection key &rest options)
|
|
26
|
+
(Runtime/sortedSequenceFrom
|
|
27
|
+
collection
|
|
28
|
+
key
|
|
29
|
+
(if (= (js-length options) 0) t (js-nth 0 options))
|
|
30
|
+
(if (< (js-length options) 2) t (js-nth 1 options))))
|
|
31
|
+
(defun subseq
|
|
32
|
+
(collection &rest bounds)
|
|
33
|
+
(apply Runtime/subsequence (js-cons collection bounds)))
|
|
34
|
+
(defun rsubseq
|
|
35
|
+
(collection &rest bounds)
|
|
36
|
+
(apply Runtime/reverseSubsequence (js-cons collection bounds)))
|
|
37
|
+
(export
|
|
38
|
+
comparator
|
|
39
|
+
empty-sorted-map
|
|
40
|
+
empty-sorted-map-by
|
|
41
|
+
empty-sorted-set
|
|
42
|
+
empty-sorted-set-by
|
|
43
|
+
rsubseq
|
|
44
|
+
sorted-map
|
|
45
|
+
sorted-map-by
|
|
46
|
+
sorted-map?
|
|
47
|
+
sorted-seq
|
|
48
|
+
sorted-seq-from
|
|
49
|
+
sorted-set
|
|
50
|
+
sorted-set-by
|
|
51
|
+
sorted-set?
|
|
52
|
+
sorted?
|
|
53
|
+
subseq))
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
(module eliscript.core.text
|
|
2
|
+
(import "../../runtime/core/collection.mjs" :as Collection)
|
|
3
|
+
|
|
4
|
+
(defun empty? (text)
|
|
5
|
+
(= (Collection/count text) 0))
|
|
6
|
+
|
|
7
|
+
(defun slice (start end text)
|
|
8
|
+
(let ((result "")
|
|
9
|
+
(index (if (< start 0) 0 start))
|
|
10
|
+
(limit
|
|
11
|
+
(if (> end (Collection/count text))
|
|
12
|
+
(Collection/count text)
|
|
13
|
+
end)))
|
|
14
|
+
(while (< index limit)
|
|
15
|
+
(setq result (str result (Collection/nth text index))
|
|
16
|
+
index (1+ index)))
|
|
17
|
+
result))
|
|
18
|
+
|
|
19
|
+
(defun starts-at? (prefix offset text)
|
|
20
|
+
(let ((matched
|
|
21
|
+
(and (>= offset 0)
|
|
22
|
+
(<= (+ offset (Collection/count prefix))
|
|
23
|
+
(Collection/count text))))
|
|
24
|
+
(index 0))
|
|
25
|
+
(while (and matched (< index (Collection/count prefix)))
|
|
26
|
+
(unless (= (Collection/nth prefix index)
|
|
27
|
+
(Collection/nth text (+ offset index)))
|
|
28
|
+
(setq matched false))
|
|
29
|
+
(setq index (1+ index)))
|
|
30
|
+
matched))
|
|
31
|
+
|
|
32
|
+
(defun starts-with? (prefix text)
|
|
33
|
+
(starts-at? prefix 0 text))
|
|
34
|
+
|
|
35
|
+
(defun ends-with? (suffix text)
|
|
36
|
+
(starts-at? suffix
|
|
37
|
+
(- (Collection/count text) (Collection/count suffix))
|
|
38
|
+
text))
|
|
39
|
+
|
|
40
|
+
(defun contains? (needle text)
|
|
41
|
+
(let ((found false)
|
|
42
|
+
(offset 0)
|
|
43
|
+
(last-offset
|
|
44
|
+
(- (Collection/count text) (Collection/count needle))))
|
|
45
|
+
(while (and (not found) (<= offset last-offset))
|
|
46
|
+
(when (starts-at? needle offset text)
|
|
47
|
+
(setq found t))
|
|
48
|
+
(setq offset (1+ offset)))
|
|
49
|
+
found))
|
|
50
|
+
|
|
51
|
+
(defun strip-prefix (prefix text)
|
|
52
|
+
(if (starts-with? prefix text)
|
|
53
|
+
(slice (Collection/count prefix) (Collection/count text) text)
|
|
54
|
+
text))
|
|
55
|
+
|
|
56
|
+
(defun strip-suffix (suffix text)
|
|
57
|
+
(if (ends-with? suffix text)
|
|
58
|
+
(slice 0 (- (Collection/count text) (Collection/count suffix)) text)
|
|
59
|
+
text))
|
|
60
|
+
|
|
61
|
+
(defun whitespace? (character)
|
|
62
|
+
(or (= character " ")
|
|
63
|
+
(= character "\t")
|
|
64
|
+
(= character "\n")
|
|
65
|
+
(= character "\r")))
|
|
66
|
+
|
|
67
|
+
(defun trim (text)
|
|
68
|
+
(let ((start 0)
|
|
69
|
+
(end (1- (Collection/count text))))
|
|
70
|
+
(while (and (<= start end)
|
|
71
|
+
(whitespace? (Collection/nth text start)))
|
|
72
|
+
(setq start (1+ start)))
|
|
73
|
+
(while (and (>= end start)
|
|
74
|
+
(whitespace? (Collection/nth text end)))
|
|
75
|
+
(setq end (1- end)))
|
|
76
|
+
(slice start (1+ end) text)))
|
|
77
|
+
|
|
78
|
+
(defun blank? (text)
|
|
79
|
+
(empty? (trim text)))
|
|
80
|
+
|
|
81
|
+
(defun join (separator values)
|
|
82
|
+
(get
|
|
83
|
+
(Collection/reduce
|
|
84
|
+
values
|
|
85
|
+
(lambda (state value)
|
|
86
|
+
(js-object
|
|
87
|
+
:first false
|
|
88
|
+
:text (str (get state :text)
|
|
89
|
+
(if (get state :first) "" separator)
|
|
90
|
+
value)))
|
|
91
|
+
(js-object :first t :text ""))
|
|
92
|
+
:text))
|
|
93
|
+
|
|
94
|
+
(defun repeat (count text)
|
|
95
|
+
(let ((result "")
|
|
96
|
+
(index 0))
|
|
97
|
+
(while (< index count)
|
|
98
|
+
(setq result (str result text)
|
|
99
|
+
index (1+ index)))
|
|
100
|
+
result))
|
|
101
|
+
|
|
102
|
+
(export blank? contains? empty? ends-with? join repeat slice starts-at?
|
|
103
|
+
starts-with? strip-prefix strip-suffix trim whitespace?))
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
(module eliscript.core.transducer
|
|
2
|
+
(import "../../runtime/core/transducer.mjs" :as Runtime)
|
|
3
|
+
(defun completing
|
|
4
|
+
(step &rest completion)
|
|
5
|
+
(apply Runtime/completing (js-cons step completion)))
|
|
6
|
+
(defun compose-transducers
|
|
7
|
+
(&rest transducers)
|
|
8
|
+
(apply Runtime/composeTransducers transducers))
|
|
9
|
+
(defun mapping (transform) (Runtime/mapping transform))
|
|
10
|
+
(defun mapping-indexed (transform) (Runtime/mappingIndexed transform))
|
|
11
|
+
(defun keeping (transform) (Runtime/keeping transform))
|
|
12
|
+
(defun keeping-indexed (transform) (Runtime/keepingIndexed transform))
|
|
13
|
+
(defun catting () (Runtime/catting))
|
|
14
|
+
(defun mapcatting (transform) (Runtime/mapcatting transform))
|
|
15
|
+
(defun filtering (predicate) (Runtime/filtering predicate))
|
|
16
|
+
(defun removing (predicate) (Runtime/removing predicate))
|
|
17
|
+
(defun taking (limit) (Runtime/taking limit))
|
|
18
|
+
(defun dropping (limit) (Runtime/dropping limit))
|
|
19
|
+
(defun taking-while (predicate) (Runtime/takingWhile predicate))
|
|
20
|
+
(defun dropping-while (predicate) (Runtime/droppingWhile predicate))
|
|
21
|
+
(defun taking-nth (interval) (Runtime/takingNth interval))
|
|
22
|
+
(defun interposing (separator) (Runtime/interposing separator))
|
|
23
|
+
(defun partitioning-all (size) (Runtime/partitioningAll size))
|
|
24
|
+
(defun partitioning-by (classifier) (Runtime/partitioningBy classifier))
|
|
25
|
+
(defun deduping () (Runtime/deduping))
|
|
26
|
+
(defun distincting () (Runtime/distincting))
|
|
27
|
+
(defun transduce
|
|
28
|
+
(transducer reducer initial collection)
|
|
29
|
+
(Runtime/transduce transducer reducer initial collection))
|
|
30
|
+
(defun eduction (&rest arguments) (apply Runtime/eduction arguments))
|
|
31
|
+
(defun sequence (transducer collection) (Runtime/sequence transducer collection))
|
|
32
|
+
(defun run! (procedure collection) (Runtime/runBang procedure collection))
|
|
33
|
+
(defun into (target &rest arguments) (apply Runtime/into (js-cons target arguments)))
|
|
34
|
+
(export
|
|
35
|
+
catting
|
|
36
|
+
completing
|
|
37
|
+
compose-transducers
|
|
38
|
+
deduping
|
|
39
|
+
distincting
|
|
40
|
+
dropping
|
|
41
|
+
eduction
|
|
42
|
+
dropping-while
|
|
43
|
+
filtering
|
|
44
|
+
interposing
|
|
45
|
+
into
|
|
46
|
+
keeping
|
|
47
|
+
keeping-indexed
|
|
48
|
+
mapcatting
|
|
49
|
+
mapping
|
|
50
|
+
mapping-indexed
|
|
51
|
+
partitioning-all
|
|
52
|
+
partitioning-by
|
|
53
|
+
removing
|
|
54
|
+
run!
|
|
55
|
+
sequence
|
|
56
|
+
taking
|
|
57
|
+
taking-nth
|
|
58
|
+
taking-while
|
|
59
|
+
transduce))
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
(module eliscript.core.transient
|
|
2
|
+
(import "../../runtime/core/transient.mjs" :as Runtime)
|
|
3
|
+
|
|
4
|
+
(defconst IEditable Runtime/IEditable)
|
|
5
|
+
(defconst ITransientCollection Runtime/ITransientCollection)
|
|
6
|
+
|
|
7
|
+
(defun transient (collection)
|
|
8
|
+
(Runtime/transient collection))
|
|
9
|
+
|
|
10
|
+
(defun conj! (collection &rest values)
|
|
11
|
+
(apply Runtime/conjBang (js-cons collection values)))
|
|
12
|
+
|
|
13
|
+
(defun assoc! (collection key value &rest key-values)
|
|
14
|
+
(apply Runtime/assocBang
|
|
15
|
+
(js-cons collection (js-cons key (js-cons value key-values)))))
|
|
16
|
+
|
|
17
|
+
(defun dissoc! (collection &rest keys)
|
|
18
|
+
(apply Runtime/dissocBang (js-cons collection keys)))
|
|
19
|
+
|
|
20
|
+
(defun persistent! (collection)
|
|
21
|
+
(Runtime/persistentBang collection))
|
|
22
|
+
|
|
23
|
+
(export IEditable ITransientCollection assoc! conj! dissoc! persistent!
|
|
24
|
+
transient))
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
(module eliscript.core.type
|
|
2
|
+
(import "../../runtime/core/type.mjs" :as Runtime)
|
|
3
|
+
(defun define-type (name fields protocol-plans)
|
|
4
|
+
(Runtime/defineType name fields protocol-plans))
|
|
5
|
+
(defun reify-protocols (protocol-plans)
|
|
6
|
+
(Runtime/reifyProtocols protocol-plans))
|
|
7
|
+
(defun type-definition? (value) (Runtime/isType value))
|
|
8
|
+
(defun type-value? (value) (Runtime/isTypeValue value))
|
|
9
|
+
(defun type-of (value) (Runtime/typeOf value))
|
|
10
|
+
(defun defined-type-name (value) (Runtime/typeName value))
|
|
11
|
+
(defun defined-type-fields (value) (Runtime/typeFieldNames value))
|
|
12
|
+
(export
|
|
13
|
+
define-type
|
|
14
|
+
reify-protocols
|
|
15
|
+
type-definition?
|
|
16
|
+
type-value?
|
|
17
|
+
type-of
|
|
18
|
+
defined-type-name
|
|
19
|
+
defined-type-fields))
|