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.
Files changed (195) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +135 -0
  3. package/bin/eliscript +16 -0
  4. package/bin/eliscript-bootstrap +15 -0
  5. package/bin/eliscript-build +15 -0
  6. package/bin/eliscript-check +15 -0
  7. package/bin/eliscript-eval +15 -0
  8. package/bin/eliscript-format +15 -0
  9. package/bin/eliscript-org +10 -0
  10. package/bin/eliscript-portable +17 -0
  11. package/bin/eliscript-seed +10 -0
  12. package/bin/eliscript-seed-build +10 -0
  13. package/bin/eliscript-watch +15 -0
  14. package/bootstrap/README.md +100 -0
  15. package/bootstrap/compiler/analyzer.eli +1426 -0
  16. package/bootstrap/compiler/compiler.eli +472 -0
  17. package/bootstrap/compiler/emitter.eli +1745 -0
  18. package/bootstrap/compiler/expander.eli +2522 -0
  19. package/bootstrap/compiler/formatter.eli +359 -0
  20. package/bootstrap/compiler/ir.eli +297 -0
  21. package/bootstrap/compiler/lower.eli +661 -0
  22. package/bootstrap/compiler/project.eli +1120 -0
  23. package/bootstrap/compiler/reader.eli +321 -0
  24. package/bootstrap/compiler/source-map.eli +165 -0
  25. package/bootstrap/compiler/symbol.eli +92 -0
  26. package/bootstrap/compiler/syntax.eli +54 -0
  27. package/bootstrap/compiler/transient-analysis.eli +825 -0
  28. package/bootstrap/host/build.mjs +28 -0
  29. package/bootstrap/host/bun.mjs +282 -0
  30. package/bootstrap/host/check-cli.mjs +163 -0
  31. package/bootstrap/host/eliscript-cli.mjs +36 -0
  32. package/bootstrap/host/evaluation-cli.mjs +401 -0
  33. package/bootstrap/host/evaluation.mjs +560 -0
  34. package/bootstrap/host/format-cli.mjs +139 -0
  35. package/bootstrap/host/project-cli.mjs +295 -0
  36. package/bootstrap/host/project.mjs +1080 -0
  37. package/bootstrap/host/watch-cli.mjs +129 -0
  38. package/bootstrap/host/watch.mjs +267 -0
  39. package/browser/host.mjs +357 -0
  40. package/browser/worker.mjs +60 -0
  41. package/compiler/README.md +118 -0
  42. package/compiler/eliscript-analyzer.el +716 -0
  43. package/compiler/eliscript-cli.el +108 -0
  44. package/compiler/eliscript-diagnostic.el +158 -0
  45. package/compiler/eliscript-emitter.el +1351 -0
  46. package/compiler/eliscript-evaluation.el +259 -0
  47. package/compiler/eliscript-expander.el +1630 -0
  48. package/compiler/eliscript-form.el +79 -0
  49. package/compiler/eliscript-ir-emitter.el +1460 -0
  50. package/compiler/eliscript-ir.el +356 -0
  51. package/compiler/eliscript-lower.el +463 -0
  52. package/compiler/eliscript-macro-eval.el +811 -0
  53. package/compiler/eliscript-parameters.el +324 -0
  54. package/compiler/eliscript-portable.el +492 -0
  55. package/compiler/eliscript-project-cli.el +156 -0
  56. package/compiler/eliscript-project.el +1676 -0
  57. package/compiler/eliscript-reader.el +421 -0
  58. package/compiler/eliscript-source-map.el +192 -0
  59. package/compiler/eliscript-symbol.el +101 -0
  60. package/compiler/eliscript-transient-analysis.el +817 -0
  61. package/compiler/eliscript.el +239 -0
  62. package/dist/bootstrap/analyzer.mjs +968 -0
  63. package/dist/bootstrap/analyzer.mjs.map +1 -0
  64. package/dist/bootstrap/compiler.mjs +228 -0
  65. package/dist/bootstrap/compiler.mjs.map +1 -0
  66. package/dist/bootstrap/emitter.mjs +1173 -0
  67. package/dist/bootstrap/emitter.mjs.map +1 -0
  68. package/dist/bootstrap/expander.mjs +1469 -0
  69. package/dist/bootstrap/expander.mjs.map +1 -0
  70. package/dist/bootstrap/formatter.mjs +304 -0
  71. package/dist/bootstrap/formatter.mjs.map +1 -0
  72. package/dist/bootstrap/ir.mjs +193 -0
  73. package/dist/bootstrap/ir.mjs.map +1 -0
  74. package/dist/bootstrap/lower.mjs +344 -0
  75. package/dist/bootstrap/lower.mjs.map +1 -0
  76. package/dist/bootstrap/project.mjs +585 -0
  77. package/dist/bootstrap/project.mjs.map +1 -0
  78. package/dist/bootstrap/reader.mjs +259 -0
  79. package/dist/bootstrap/reader.mjs.map +1 -0
  80. package/dist/bootstrap/source-map.mjs +154 -0
  81. package/dist/bootstrap/source-map.mjs.map +1 -0
  82. package/dist/bootstrap/symbol.mjs +74 -0
  83. package/dist/bootstrap/symbol.mjs.map +1 -0
  84. package/dist/bootstrap/syntax.mjs +38 -0
  85. package/dist/bootstrap/syntax.mjs.map +1 -0
  86. package/dist/bootstrap/transient-analysis.mjs +660 -0
  87. package/dist/bootstrap/transient-analysis.mjs.map +1 -0
  88. package/dist/browser/compiler.js +6491 -0
  89. package/editor/README.md +83 -0
  90. package/editor/eliscript-mode.el +878 -0
  91. package/editor/eliscript-repl.el +501 -0
  92. package/package.json +163 -0
  93. package/platform/README.md +48 -0
  94. package/platform/browser.mjs +204 -0
  95. package/platform/worker.mjs +166 -0
  96. package/runtime/README.md +296 -0
  97. package/runtime/core/collection-internals.mjs +512 -0
  98. package/runtime/core/collection.mjs +645 -0
  99. package/runtime/core/data-text.mjs +532 -0
  100. package/runtime/core/data.mjs +268 -0
  101. package/runtime/core/identifier.mjs +314 -0
  102. package/runtime/core/lazy-sequence.mjs +244 -0
  103. package/runtime/core/list-internals.mjs +18 -0
  104. package/runtime/core/list.mjs +273 -0
  105. package/runtime/core/map-internals.mjs +793 -0
  106. package/runtime/core/map.mjs +394 -0
  107. package/runtime/core/metadata-internals.mjs +14 -0
  108. package/runtime/core/metadata.mjs +44 -0
  109. package/runtime/core/object-impl.mjs +65 -0
  110. package/runtime/core/object-impl.mjs.map +1 -0
  111. package/runtime/core/object.mjs +13 -0
  112. package/runtime/core/order.mjs +234 -0
  113. package/runtime/core/persistent-kind.mjs +43 -0
  114. package/runtime/core/protocol-error.mjs +36 -0
  115. package/runtime/core/protocol-impl.mjs +326 -0
  116. package/runtime/core/protocol-impl.mjs.map +1 -0
  117. package/runtime/core/protocol.mjs +14 -0
  118. package/runtime/core/queue-internals.mjs +27 -0
  119. package/runtime/core/queue.mjs +238 -0
  120. package/runtime/core/record.mjs +346 -0
  121. package/runtime/core/regex.mjs +184 -0
  122. package/runtime/core/sequence.mjs +632 -0
  123. package/runtime/core/set-algebra.mjs +287 -0
  124. package/runtime/core/set-internals.mjs +33 -0
  125. package/runtime/core/set.mjs +378 -0
  126. package/runtime/core/sorted-internals.mjs +215 -0
  127. package/runtime/core/sorted.mjs +598 -0
  128. package/runtime/core/text-impl.mjs +95 -0
  129. package/runtime/core/text-impl.mjs.map +1 -0
  130. package/runtime/core/text.mjs +15 -0
  131. package/runtime/core/transducer.mjs +668 -0
  132. package/runtime/core/transient-internals.mjs +38 -0
  133. package/runtime/core/transient.mjs +53 -0
  134. package/runtime/core/truth.mjs +3 -0
  135. package/runtime/core/type.mjs +262 -0
  136. package/runtime/core/value-internals.mjs +188 -0
  137. package/runtime/core/value.mjs +93 -0
  138. package/runtime/core/vector-internals.mjs +102 -0
  139. package/runtime/core/vector.mjs +951 -0
  140. package/runtime/literals.mjs +34 -0
  141. package/runtime/source-mapping.mjs +220 -0
  142. package/runtime/testing/list.mjs +52 -0
  143. package/runtime/testing/map.mjs +145 -0
  144. package/runtime/testing/queue.mjs +49 -0
  145. package/runtime/testing/set.mjs +61 -0
  146. package/runtime/testing/sorted.mjs +105 -0
  147. package/runtime/testing/value.mjs +17 -0
  148. package/runtime/testing/vector.mjs +102 -0
  149. package/runtime/worker-value-codec.mjs +565 -0
  150. package/runtime/worker-value-stream.mjs +786 -0
  151. package/runtime/worker.mjs +975 -0
  152. package/stdlib/README.md +774 -0
  153. package/stdlib/bit.eli +36 -0
  154. package/stdlib/core/collection.eli +134 -0
  155. package/stdlib/core/data-text.eli +16 -0
  156. package/stdlib/core/data.eli +306 -0
  157. package/stdlib/core/identifier.eli +32 -0
  158. package/stdlib/core/lazy-sequence.eli +63 -0
  159. package/stdlib/core/metadata.eli +20 -0
  160. package/stdlib/core/object.eli +89 -0
  161. package/stdlib/core/order.eli +133 -0
  162. package/stdlib/core/protocol.eli +387 -0
  163. package/stdlib/core/record.eli +16 -0
  164. package/stdlib/core/regex.eli +17 -0
  165. package/stdlib/core/seq.eli +701 -0
  166. package/stdlib/core/set.eli +312 -0
  167. package/stdlib/core/sorted.eli +53 -0
  168. package/stdlib/core/text.eli +103 -0
  169. package/stdlib/core/transducer.eli +59 -0
  170. package/stdlib/core/transient.eli +24 -0
  171. package/stdlib/core/type.eli +19 -0
  172. package/stdlib/core/walk.eli +195 -0
  173. package/stdlib/core/zipper.eli +508 -0
  174. package/stdlib/data-text.eli +1092 -0
  175. package/stdlib/data.eli +42 -0
  176. package/stdlib/deferred.eli +70 -0
  177. package/stdlib/function.eli +120 -0
  178. package/stdlib/hierarchy.eli +245 -0
  179. package/stdlib/identifier.eli +147 -0
  180. package/stdlib/interop/js.eli +616 -0
  181. package/stdlib/json.eli +870 -0
  182. package/stdlib/metadata.eli +56 -0
  183. package/stdlib/multimethod.eli +464 -0
  184. package/stdlib/numeric.eli +193 -0
  185. package/stdlib/object.eli +96 -0
  186. package/stdlib/persistent-list.eli +145 -0
  187. package/stdlib/persistent-map.eli +724 -0
  188. package/stdlib/persistent-queue.eli +32 -0
  189. package/stdlib/persistent-set.eli +236 -0
  190. package/stdlib/persistent-vector.eli +342 -0
  191. package/stdlib/result.eli +141 -0
  192. package/stdlib/sequence.eli +106 -0
  193. package/stdlib/state/atom.eli +265 -0
  194. package/stdlib/text.eli +88 -0
  195. package/stdlib/value.eli +325 -0
@@ -0,0 +1,701 @@
1
+ (module eliscript.core.seq
2
+ (import "../../runtime/core/collection.mjs"
3
+ count
4
+ isReduced
5
+ IReversible
6
+ nth
7
+ reduce
8
+ reduced
9
+ rseq
10
+ seq
11
+ sequenceView
12
+ unboundedSequenceView
13
+ unreduced)
14
+ (import "../../runtime/core/protocol.mjs" implementsProtocolOperation)
15
+ (import "../../runtime/core/collection-internals.mjs"
16
+ prependSequenceView
17
+ sliceSequenceView)
18
+ (import "../../runtime/core/list.mjs" EMPTY_LIST isPersistentList)
19
+ (import "../../runtime/core/transducer.mjs"
20
+ deduping
21
+ distincting
22
+ dropping
23
+ droppingWhile
24
+ filtering
25
+ into
26
+ interposing
27
+ keeping
28
+ keepingIndexed
29
+ mapcatting
30
+ mapping
31
+ mappingIndexed
32
+ partitioningAll
33
+ partitioningBy
34
+ removing
35
+ taking
36
+ takingNth
37
+ takingWhile)
38
+ (import "../../runtime/core/transient.mjs" conjBang persistentBang transient)
39
+ (import "../../runtime/core/truth.mjs" isTruthy)
40
+ (import "../../runtime/core/vector.mjs"
41
+ EMPTY_VECTOR
42
+ isPersistentVector
43
+ persistentVector)
44
+ (defconst not-found (js-object))
45
+ (defconst sequence-no-partition-pad (js-object))
46
+ (defconst sequence-ring (js* "() => new Map()"))
47
+ (defconst sequence-array? (js* "Array.isArray"))
48
+ (defconst sequence-safe-integer? (js* "Number.isSafeInteger"))
49
+ (defconst sequence-finite? (js* "Number.isFinite"))
50
+ (defconst sequence-ceil (js* "Math.ceil"))
51
+ (defun require-function
52
+ (value label)
53
+ (if (= (value-type value) "function")
54
+ value
55
+ (throw (new globalThis/TypeError (str label " must be a function")))))
56
+ (defun require-non-negative-safe-integer
57
+ (value label)
58
+ (if (and (funcall sequence-safe-integer? value) (>= value 0))
59
+ value
60
+ (throw
61
+ (new globalThis/TypeError (str label " must be a non-negative safe integer")))))
62
+ (defun require-positive-safe-integer
63
+ (value label)
64
+ (if (and (funcall sequence-safe-integer? value) (> value 0))
65
+ value
66
+ (throw (new globalThis/TypeError (str label " must be a positive safe integer")))))
67
+ (defun sequence-materialize-sources
68
+ (collections)
69
+ (let ((sources (js-array)) (index 0))
70
+ (while (< index (js-length collections))
71
+ (js-call sources :push (into EMPTY_VECTOR (js-nth index collections)))
72
+ (setq index (1+ index)))
73
+ sources))
74
+ (defun sequence-partition-windows
75
+ (size step pad include-partial collection)
76
+ (require-positive-safe-integer size "partition size")
77
+ (require-positive-safe-integer step "partition step")
78
+ (let*
79
+ ((values (into EMPTY_VECTOR collection))
80
+ (value-count (count values))
81
+ (result (transient EMPTY_VECTOR))
82
+ (start 0))
83
+ (while (< start value-count)
84
+ (let*
85
+ ((remaining (- value-count start))
86
+ (group-count (if (< remaining size) remaining size))
87
+ (partial (< group-count size))
88
+ (group (transient EMPTY_VECTOR))
89
+ (offset 0))
90
+ (while (< offset group-count)
91
+ (conjBang group (nth (+ start offset) values))
92
+ (setq offset (1+ offset)))
93
+ (when (and partial (not (eq pad sequence-no-partition-pad)))
94
+ (reduce
95
+ pad
96
+ (lambda
97
+ (builder value)
98
+ (conjBang builder value)
99
+ (setq group-count (1+ group-count))
100
+ (if (>= group-count size) (reduced builder) builder))
101
+ group))
102
+ (let ((completed (persistentBang group)))
103
+ (when
104
+ (or
105
+ (not partial)
106
+ include-partial
107
+ (not (eq pad sequence-no-partition-pad)))
108
+ (conjBang result completed)))
109
+ (setq start (+ start step))
110
+ (when (and partial (not include-partial)) (setq start value-count))))
111
+ (persistentBang result)))
112
+ (defun sequence-sequential-branch?
113
+ (value)
114
+ (or
115
+ (funcall sequence-array? value)
116
+ (isPersistentList value)
117
+ (isPersistentVector value)))
118
+ (defun require-finite-number
119
+ (value label)
120
+ (if (funcall sequence-finite? value)
121
+ value
122
+ (throw (new globalThis/TypeError (str label " must be a finite number")))))
123
+ (defun sequence-iterator-result (value done) (js-object :value value :done done))
124
+ (defun sequence-iterator (next) (js-object :next next))
125
+ (defun sequence-range-count
126
+ (start end step)
127
+ (let ((distance (/ (- end start) step)))
128
+ (if (> distance 0)
129
+ (require-non-negative-safe-integer
130
+ (funcall sequence-ceil distance)
131
+ "range count")
132
+ 0)))
133
+ (defun sequence-range-factory
134
+ (start step limit)
135
+ (lambda
136
+ ()
137
+ (let ((index 0))
138
+ (sequence-iterator
139
+ (lambda
140
+ ()
141
+ (if (and (not (nil? limit)) (>= index limit))
142
+ (sequence-iterator-result undefined t)
143
+ (let ((value (+ start (* index step))))
144
+ (setq index (1+ index))
145
+ (sequence-iterator-result value false))))))))
146
+ (defun range
147
+ (&rest bounds)
148
+ (let ((arity (js-length bounds)))
149
+ (if (= arity 0)
150
+ (unboundedSequenceView (sequence-range-factory 0 1 nil))
151
+ (progn
152
+ (when (> arity 3)
153
+ (throw (new globalThis/TypeError "range expects zero to three arguments")))
154
+ (let*
155
+ (
156
+ (start
157
+ (require-finite-number
158
+ (if (= arity 1) 0 (js-nth 0 bounds))
159
+ "range start"))
160
+ (end
161
+ (require-finite-number
162
+ (if (= arity 1) (js-nth 0 bounds) (js-nth 1 bounds))
163
+ "range end"))
164
+ (step
165
+ (require-finite-number
166
+ (if (= arity 3) (js-nth 2 bounds) 1)
167
+ "range step")))
168
+ (when (= step 0)
169
+ (throw (new globalThis/TypeError "range step must be non-zero")))
170
+ (let ((limit (sequence-range-count start end step)))
171
+ (sequenceView (sequence-range-factory start step limit) limit)))))))
172
+ (defun sequence-repeat-factory
173
+ (value limit)
174
+ (lambda
175
+ ()
176
+ (let ((index 0))
177
+ (sequence-iterator
178
+ (lambda
179
+ ()
180
+ (if (and (not (nil? limit)) (>= index limit))
181
+ (sequence-iterator-result undefined t)
182
+ (progn (setq index (1+ index)) (sequence-iterator-result value false))))))))
183
+ (defun repeat
184
+ (&rest arguments)
185
+ (let ((arity (js-length arguments)))
186
+ (cond
187
+ ((= arity 1)
188
+ (unboundedSequenceView (sequence-repeat-factory (js-nth 0 arguments) nil)))
189
+ ((= arity 2)
190
+ (let
191
+ (
192
+ (limit
193
+ (require-non-negative-safe-integer (js-nth 0 arguments) "repeat count")))
194
+ (sequenceView (sequence-repeat-factory (js-nth 1 arguments) limit) limit)))
195
+ (t
196
+ (throw
197
+ (new globalThis/TypeError "repeat expects a value or a count and value"))))))
198
+ (defun sequence-repeatedly-factory
199
+ (producer limit)
200
+ (lambda
201
+ ()
202
+ (let ((index 0))
203
+ (sequence-iterator
204
+ (lambda
205
+ ()
206
+ (if (and (not (nil? limit)) (>= index limit))
207
+ (sequence-iterator-result undefined t)
208
+ (progn
209
+ (setq index (1+ index))
210
+ (sequence-iterator-result (funcall producer) false))))))))
211
+ (defun repeatedly
212
+ (&rest arguments)
213
+ (let ((arity (js-length arguments)))
214
+ (cond
215
+ ((= arity 1)
216
+ (let
217
+ ((producer (require-function (js-nth 0 arguments) "repeatedly producer")))
218
+ (unboundedSequenceView (sequence-repeatedly-factory producer nil))))
219
+ ((= arity 2)
220
+ (let
221
+ (
222
+ (limit
223
+ (require-non-negative-safe-integer
224
+ (js-nth 0 arguments)
225
+ "repeatedly count"))
226
+ (producer (require-function (js-nth 1 arguments) "repeatedly producer")))
227
+ (sequenceView (sequence-repeatedly-factory producer limit) limit)))
228
+ (t
229
+ (throw
230
+ (new
231
+ globalThis/TypeError
232
+ "repeatedly expects a producer or a count and producer"))))))
233
+ (defun iterate
234
+ (transform seed)
235
+ (require-function transform "iterate transform")
236
+ (unboundedSequenceView
237
+ (lambda
238
+ ()
239
+ (let ((value seed) (started false))
240
+ (sequence-iterator
241
+ (lambda
242
+ ()
243
+ (if started (setq value (funcall transform value)) (setq started t))
244
+ (sequence-iterator-result value false)))))))
245
+ (defun cycle
246
+ (collection)
247
+ (let* ((values (into EMPTY_VECTOR collection)) (limit (count values)))
248
+ (if (= limit 0)
249
+ nil
250
+ (unboundedSequenceView
251
+ (lambda
252
+ ()
253
+ (let ((index 0))
254
+ (sequence-iterator
255
+ (lambda
256
+ ()
257
+ (let ((value (nth index values)))
258
+ (setq index (% (1+ index) limit))
259
+ (sequence-iterator-result value false))))))))))
260
+ (defun generate
261
+ (limit producer)
262
+ (require-non-negative-safe-integer limit "generate count")
263
+ (require-function producer "generate producer")
264
+ (sequenceView
265
+ (lambda
266
+ ()
267
+ (let ((index 0))
268
+ (sequence-iterator
269
+ (lambda
270
+ ()
271
+ (if (>= index limit)
272
+ (sequence-iterator-result undefined t)
273
+ (let ((value (funcall producer index)))
274
+ (setq index (1+ index))
275
+ (sequence-iterator-result value false)))))))
276
+ limit))
277
+ (defun first
278
+ (collection &optional not-found-value)
279
+ (let
280
+ (
281
+ (result
282
+ (reduce
283
+ collection
284
+ (lambda (missing value) (reduced (js-object :value value)))
285
+ not-found)))
286
+ (if (eq result not-found) not-found-value (get result :value))))
287
+ (defun nth-rest
288
+ (limit collection)
289
+ (require-non-negative-safe-integer limit "nth-rest limit")
290
+ (if (= limit 0)
291
+ collection
292
+ (let ((result (sliceSequenceView (seq collection) limit)))
293
+ (if (nil? result) EMPTY_LIST result))))
294
+ (defun nth-next
295
+ (limit collection)
296
+ (require-non-negative-safe-integer limit "nth-next limit")
297
+ (let
298
+ (
299
+ (result
300
+ (if (= limit 0) (seq collection) (sliceSequenceView (seq collection) limit))))
301
+ (if (nil? result) nil (seq result))))
302
+ (defun rest (collection) (nth-rest 1 collection))
303
+ (defun next (collection) (nth-next 1 collection))
304
+ (defun prepend (value collection) (prependSequenceView value (seq collection)))
305
+ (defun second
306
+ (collection &optional not-found-value)
307
+ (first (next collection) not-found-value))
308
+ (defun ffirst (collection) (first (first collection)))
309
+ (defun nfirst (collection) (next (first collection)))
310
+ (defun fnext (collection) (first (next collection)))
311
+ (defun nnext (collection) (next (next collection)))
312
+ (defun sequence-nth
313
+ (index collection &optional not-found-value)
314
+ (require-non-negative-safe-integer index "sequence-nth index")
315
+ (let*
316
+ ((position 0)
317
+ (result
318
+ (reduce
319
+ collection
320
+ (lambda
321
+ (missing value)
322
+ (if (= position index)
323
+ (reduced (js-object :value value))
324
+ (progn (setq position (1+ position)) missing)))
325
+ not-found)))
326
+ (if (eq result not-found) not-found-value (get result :value))))
327
+ (defun last
328
+ (collection &optional not-found-value)
329
+ (if (implementsProtocolOperation IReversible "rseq" collection)
330
+ (first (rseq collection) not-found-value)
331
+ (let
332
+ (
333
+ (result
334
+ (reduce
335
+ collection
336
+ (lambda (missing value) (js-object :value value))
337
+ not-found)))
338
+ (if (eq result not-found) not-found-value (get result :value)))))
339
+ (defun take-last
340
+ (limit collection)
341
+ (require-non-negative-safe-integer limit "take-last limit")
342
+ (if (= limit 0)
343
+ EMPTY_VECTOR
344
+ (let ((ring (funcall sequence-ring)) (count 0) (start 0))
345
+ (reduce
346
+ collection
347
+ (lambda
348
+ (state value)
349
+ (if (< count limit)
350
+ (progn (js-call ring :set count value) (setq count (1+ count)))
351
+ (progn (js-call ring :set start value) (setq start (% (1+ start) limit))))
352
+ state)
353
+ nil)
354
+ (let ((builder (transient EMPTY_VECTOR)) (index 0))
355
+ (while (< index count)
356
+ (conjBang builder (js-call ring :get (% (+ start index) limit)))
357
+ (setq index (1+ index)))
358
+ (persistentBang builder)))))
359
+ (defun drop-last
360
+ (limit collection)
361
+ (require-non-negative-safe-integer limit "drop-last limit")
362
+ (if (= limit 0)
363
+ (into EMPTY_VECTOR collection)
364
+ (let
365
+ ((ring (funcall sequence-ring))
366
+ (builder (transient EMPTY_VECTOR))
367
+ (count 0)
368
+ (start 0))
369
+ (reduce
370
+ collection
371
+ (lambda
372
+ (state value)
373
+ (if (< count limit)
374
+ (progn (js-call ring :set count value) (setq count (1+ count)))
375
+ (progn
376
+ (conjBang builder (js-call ring :get start))
377
+ (js-call ring :set start value)
378
+ (setq start (% (1+ start) limit))))
379
+ state)
380
+ nil)
381
+ (persistentBang builder))))
382
+ (defun butlast (collection) (drop-last 1 collection))
383
+ (defun split-at
384
+ (limit collection)
385
+ (require-non-negative-safe-integer limit "split-at limit")
386
+ (let ((left (transient EMPTY_VECTOR)) (right (transient EMPTY_VECTOR)) (index 0))
387
+ (reduce
388
+ collection
389
+ (lambda
390
+ (state value)
391
+ (conjBang (if (< index limit) left right) value)
392
+ (setq index (1+ index))
393
+ state)
394
+ nil)
395
+ (persistentVector (persistentBang left) (persistentBang right))))
396
+ (defun split-with
397
+ (predicate collection)
398
+ (require-function predicate "split-with predicate")
399
+ (let ((left (transient EMPTY_VECTOR)) (right (transient EMPTY_VECTOR)) (prefix t))
400
+ (reduce
401
+ collection
402
+ (lambda
403
+ (state value)
404
+ (if (and prefix (isTruthy (funcall predicate value)))
405
+ (conjBang left value)
406
+ (progn (setq prefix false) (conjBang right value)))
407
+ state)
408
+ nil)
409
+ (persistentVector (persistentBang left) (persistentBang right))))
410
+ (defun reverse
411
+ (collection)
412
+ (if (implementsProtocolOperation IReversible "rseq" collection)
413
+ (into EMPTY_VECTOR (rseq collection))
414
+ (let
415
+ (
416
+ (values
417
+ (reduce
418
+ collection
419
+ (lambda (result value) (js-call result :push value) result)
420
+ (js-array))))
421
+ (js-call values :reverse)
422
+ (into EMPTY_VECTOR values))))
423
+ (defun map (transform collection) (into EMPTY_VECTOR (mapping transform) collection))
424
+ (defun map-indexed
425
+ (transform collection)
426
+ (into EMPTY_VECTOR (mappingIndexed transform) collection))
427
+ (defun keep (transform collection) (into EMPTY_VECTOR (keeping transform) collection))
428
+ (defun keep-indexed
429
+ (transform collection)
430
+ (into EMPTY_VECTOR (keepingIndexed transform) collection))
431
+ (defun filter
432
+ (predicate collection)
433
+ (into EMPTY_VECTOR (filtering predicate) collection))
434
+ (defun remove
435
+ (predicate collection)
436
+ (into EMPTY_VECTOR (removing predicate) collection))
437
+ (defun take (limit collection) (into EMPTY_VECTOR (taking limit) collection))
438
+ (defun drop (limit collection) (into EMPTY_VECTOR (dropping limit) collection))
439
+ (defun take-while
440
+ (predicate collection)
441
+ (into EMPTY_VECTOR (takingWhile predicate) collection))
442
+ (defun drop-while
443
+ (predicate collection)
444
+ (into EMPTY_VECTOR (droppingWhile predicate) collection))
445
+ (defun take-nth
446
+ (interval collection)
447
+ (into EMPTY_VECTOR (takingNth interval) collection))
448
+ (defun interpose
449
+ (separator collection)
450
+ (into EMPTY_VECTOR (interposing separator) collection))
451
+ (defun dedupe (collection) (into EMPTY_VECTOR (deduping) collection))
452
+ (defun distinct (collection) (into EMPTY_VECTOR (distincting) collection))
453
+ (defun mapcat
454
+ (transform collection)
455
+ (into EMPTY_VECTOR (mapcatting transform) collection))
456
+ (defun partition
457
+ (size &rest arguments)
458
+ (let ((arity (js-length arguments)))
459
+ (cond
460
+ ((= arity 1)
461
+ (sequence-partition-windows
462
+ size
463
+ size
464
+ sequence-no-partition-pad
465
+ false
466
+ (js-nth 0 arguments)))
467
+ ((= arity 2)
468
+ (sequence-partition-windows
469
+ size
470
+ (js-nth 0 arguments)
471
+ sequence-no-partition-pad
472
+ false
473
+ (js-nth 1 arguments)))
474
+ ((= arity 3)
475
+ (sequence-partition-windows
476
+ size
477
+ (js-nth 0 arguments)
478
+ (js-nth 1 arguments)
479
+ false
480
+ (js-nth 2 arguments)))
481
+ (t
482
+ (throw
483
+ (new
484
+ globalThis/TypeError
485
+ "partition expects size and collection, optional step, or step and pad"))))))
486
+ (defun partition-all
487
+ (size &rest arguments)
488
+ (let ((arity (js-length arguments)))
489
+ (cond
490
+ ((= arity 1)
491
+ (require-positive-safe-integer size "partition size")
492
+ (into EMPTY_VECTOR (partitioningAll size) (js-nth 0 arguments)))
493
+ ((= arity 2)
494
+ (sequence-partition-windows
495
+ size
496
+ (js-nth 0 arguments)
497
+ sequence-no-partition-pad
498
+ t
499
+ (js-nth 1 arguments)))
500
+ (t
501
+ (throw
502
+ (new
503
+ globalThis/TypeError
504
+ "partition-all expects size and collection or size, step, and collection"))))))
505
+ (defun partition-by
506
+ (classifier collection)
507
+ (into EMPTY_VECTOR (partitioningBy classifier) collection))
508
+ (defun concat
509
+ (&rest collections)
510
+ (let ((result (transient EMPTY_VECTOR)) (index 0))
511
+ (while (< index (js-length collections))
512
+ (reduce
513
+ (js-nth index collections)
514
+ (lambda (builder value) (conjBang builder value))
515
+ result)
516
+ (setq index (1+ index)))
517
+ (persistentBang result)))
518
+ (defun interleave
519
+ (&rest collections)
520
+ (if (= (js-length collections) 0)
521
+ EMPTY_VECTOR
522
+ (let*
523
+ ((sources (sequence-materialize-sources collections))
524
+ (source-count (js-length sources))
525
+ (limit (count (js-nth 0 sources)))
526
+ (source-index 1)
527
+ (value-index 0)
528
+ (result (transient EMPTY_VECTOR)))
529
+ (while (< source-index source-count)
530
+ (let ((source-size (count (js-nth source-index sources))))
531
+ (when (< source-size limit) (setq limit source-size)))
532
+ (setq source-index (1+ source-index)))
533
+ (while (< value-index limit)
534
+ (setq source-index 0)
535
+ (while (< source-index source-count)
536
+ (conjBang result (nth value-index (js-nth source-index sources)))
537
+ (setq source-index (1+ source-index)))
538
+ (setq value-index (1+ value-index)))
539
+ (persistentBang result))))
540
+ (defun interleave-all
541
+ (&rest collections)
542
+ (if (= (js-length collections) 0)
543
+ EMPTY_VECTOR
544
+ (let*
545
+ ((sources (sequence-materialize-sources collections))
546
+ (source-count (js-length sources))
547
+ (limit 0)
548
+ (source-index 0)
549
+ (value-index 0)
550
+ (result (transient EMPTY_VECTOR)))
551
+ (while (< source-index source-count)
552
+ (let ((source-size (count (js-nth source-index sources))))
553
+ (when (> source-size limit) (setq limit source-size)))
554
+ (setq source-index (1+ source-index)))
555
+ (while (< value-index limit)
556
+ (setq source-index 0)
557
+ (while (< source-index source-count)
558
+ (let ((source (js-nth source-index sources)))
559
+ (when (< value-index (count source))
560
+ (conjBang result (nth value-index source))))
561
+ (setq source-index (1+ source-index)))
562
+ (setq value-index (1+ value-index)))
563
+ (persistentBang result))))
564
+ (defun some
565
+ (predicate collection &optional not-found-value)
566
+ (require-function predicate "some predicate")
567
+ (let
568
+ (
569
+ (result
570
+ (reduce
571
+ collection
572
+ (lambda
573
+ (missing value)
574
+ (let ((matched (funcall predicate value)))
575
+ (if (isTruthy matched) (reduced matched) missing)))
576
+ not-found)))
577
+ (if (eq result not-found) not-found-value result)))
578
+ (defun every?
579
+ (predicate collection)
580
+ (require-function predicate "every predicate")
581
+ (reduce
582
+ collection
583
+ (lambda
584
+ (result value)
585
+ (if (isTruthy (funcall predicate value)) result (reduced false)))
586
+ t))
587
+ (defun not-any? (predicate collection) (not (isTruthy (some predicate collection))))
588
+ (defun not-every? (predicate collection) (not (every? predicate collection)))
589
+ (defun find
590
+ (predicate collection &optional not-found-value)
591
+ (require-function predicate "find predicate")
592
+ (let
593
+ (
594
+ (result
595
+ (reduce
596
+ collection
597
+ (lambda
598
+ (missing value)
599
+ (if (isTruthy (funcall predicate value))
600
+ (reduced (js-object :value value))
601
+ missing))
602
+ not-found)))
603
+ (if (eq result not-found) not-found-value (get result :value))))
604
+ (defun reductions
605
+ (step initial collection)
606
+ (require-function step "reductions step")
607
+ (let ((builder (transient EMPTY_VECTOR)) (seed (unreduced initial)))
608
+ (conjBang builder seed)
609
+ (unless (isReduced initial)
610
+ (reduce
611
+ collection
612
+ (lambda
613
+ (current input)
614
+ (let ((next (funcall step current input)))
615
+ (conjBang builder (unreduced next))
616
+ (if (isReduced next) (reduced (unreduced next)) next)))
617
+ seed))
618
+ (persistentBang builder)))
619
+ (defun tree-seq
620
+ (branch-predicate children-function root)
621
+ (require-function branch-predicate "tree-seq branch predicate")
622
+ (require-function children-function "tree-seq children function")
623
+ (let ((result (transient EMPTY_VECTOR)) (stack (js-array root)))
624
+ (while (> (js-length stack) 0)
625
+ (let ((value (js-call stack :pop)))
626
+ (conjBang result value)
627
+ (when (isTruthy (funcall branch-predicate value))
628
+ (let*
629
+ ((children (into EMPTY_VECTOR (funcall children-function value)))
630
+ (index (1- (count children))))
631
+ (while (>= index 0)
632
+ (js-call stack :push (nth index children))
633
+ (setq index (1- index)))))))
634
+ (persistentBang result)))
635
+ (defun flatten
636
+ (root)
637
+ (let ((result (transient EMPTY_VECTOR)) (stack (js-array root)))
638
+ (while (> (js-length stack) 0)
639
+ (let ((value (js-call stack :pop)))
640
+ (if (sequence-sequential-branch? value)
641
+ (let* ((children (into EMPTY_VECTOR value)) (index (1- (count children))))
642
+ (while (>= index 0)
643
+ (js-call stack :push (nth index children))
644
+ (setq index (1- index))))
645
+ (conjBang result value))))
646
+ (persistentBang result)))
647
+ (export
648
+ butlast
649
+ concat
650
+ cycle
651
+ dedupe
652
+ distinct
653
+ drop
654
+ drop-last
655
+ drop-while
656
+ every?
657
+ ffirst
658
+ filter
659
+ find
660
+ flatten
661
+ fnext
662
+ first
663
+ generate
664
+ interpose
665
+ interleave
666
+ interleave-all
667
+ keep
668
+ keep-indexed
669
+ last
670
+ iterate
671
+ map
672
+ map-indexed
673
+ mapcat
674
+ next
675
+ nfirst
676
+ nnext
677
+ not-any?
678
+ not-every?
679
+ partition
680
+ partition-all
681
+ partition-by
682
+ prepend
683
+ reductions
684
+ remove
685
+ repeat
686
+ repeatedly
687
+ rest
688
+ reverse
689
+ range
690
+ second
691
+ nth-next
692
+ nth-rest
693
+ sequence-nth
694
+ some
695
+ split-at
696
+ split-with
697
+ take
698
+ take-last
699
+ take-nth
700
+ take-while
701
+ tree-seq))