eliscript 0.0.2 → 0.0.4
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 +13 -11
- package/bootstrap/README.md +13 -8
- package/bootstrap/host/build.eli +2 -0
- package/bootstrap/host/bun.eli +2 -0
- package/bootstrap/host/check-cli-legacy.eli +2 -0
- package/bootstrap/host/evaluation-cli.eli +2 -0
- package/bootstrap/host/evaluation.eli +2 -0
- package/bootstrap/host/format-cli.eli +2 -0
- package/bootstrap/host/project-cli-legacy.eli +2 -0
- package/bootstrap/host/project-legacy.eli +2 -0
- package/bootstrap/host/watch-cli.eli +2 -0
- package/bootstrap/host/watch.eli +2 -0
- package/browser/README.md +33 -0
- package/browser/host.eli +2 -0
- package/browser/host.mjs +643 -11
- package/browser/worker.eli +2 -0
- package/browser/worker.mjs +6 -3
- package/dist/browser/host.mjs +643 -11
- package/dist/browser/worker.mjs +6 -3
- package/dist/compiler-artifact.json +1 -1
- package/dist/literal-sources/runtime/core/collection.eli +76 -16
- package/dist/literal-sources/runtime/core/metadata.eli +25 -8
- package/dist/literal-sources/runtime/core/vector.eli +7 -2
- package/dist/literal-sources/stdlib/managed-literal-protocols.eli +18 -7
- package/dist/literal-sources/stdlib/managed-literals.eli +121 -66
- package/dist/stage3-release.json +1 -1
- package/package.json +11 -2
- package/platform/README.md +33 -12
- package/platform/browser.eli +2 -0
- package/platform/http.eli +2 -0
- package/platform/worker.eli +2 -0
- package/runtime/README.md +34 -14
- package/runtime/array-text.eli +2 -0
- package/runtime/core/collection-internals.eli +2 -0
- package/runtime/core/collection.eli +2 -0
- package/runtime/core/collection.mjs +99 -17
- package/runtime/core/data-text.eli +2 -0
- package/runtime/core/data.eli +2 -0
- package/runtime/core/data.mjs +7 -5
- package/runtime/core/identifier.eli +2 -0
- package/runtime/core/lazy-sequence.eli +2 -0
- package/runtime/core/list-internals.eli +2 -0
- package/runtime/core/list.eli +2 -0
- package/runtime/core/list.mjs +3 -0
- package/runtime/core/map-internals.eli +2 -0
- package/runtime/core/map.eli +2 -0
- package/runtime/core/map.mjs +5 -0
- package/runtime/core/metadata-internals.eli +2 -0
- package/runtime/core/metadata.eli +2 -0
- package/runtime/core/metadata.mjs +14 -0
- package/runtime/core/object.eli +2 -0
- package/runtime/core/order.eli +2 -0
- package/runtime/core/order.mjs +35 -6
- package/runtime/core/persistent-kind.eli +2 -0
- package/runtime/core/persistent-kind.mjs +6 -0
- package/runtime/core/protocol-error.eli +2 -0
- package/runtime/core/protocol.eli +2 -0
- package/runtime/core/queue-internals.eli +2 -0
- package/runtime/core/queue.eli +2 -0
- package/runtime/core/queue.mjs +3 -0
- package/runtime/core/record.eli +2 -0
- package/runtime/core/regex.eli +2 -0
- package/runtime/core/sequence.eli +2 -0
- package/runtime/core/sequence.mjs +75 -13
- package/runtime/core/set-algebra.eli +2 -0
- package/runtime/core/set-internals.eli +2 -0
- package/runtime/core/set.eli +2 -0
- package/runtime/core/sorted-internals.eli +2 -0
- package/runtime/core/sorted.eli +2 -0
- package/runtime/core/text.eli +2 -0
- package/runtime/core/transducer.eli +2 -0
- package/runtime/core/transient-internals.eli +2 -0
- package/runtime/core/transient.eli +2 -0
- package/runtime/core/transient.mjs +59 -10
- package/runtime/core/truth.eli +2 -0
- package/runtime/core/type.eli +2 -0
- package/runtime/core/value-internals.eli +2 -0
- package/runtime/core/value.eli +2 -0
- package/runtime/core/vector-internals.eli +2 -0
- package/runtime/core/vector-internals.mjs +3 -6
- package/runtime/core/vector.eli +2 -0
- package/runtime/core/vector.mjs +125 -7
- package/runtime/literals.eli +2 -0
- package/runtime/number-radix.eli +2 -0
- package/runtime/source-mapping.eli +2 -0
- package/runtime/testing/list.eli +2 -0
- package/runtime/testing/map.eli +2 -0
- package/runtime/testing/queue.eli +2 -0
- package/runtime/testing/set.eli +2 -0
- package/runtime/testing/sorted.eli +2 -0
- package/runtime/testing/value.eli +2 -0
- package/runtime/testing/vector.eli +2 -0
- package/runtime/wire/http-rpc.eli +2 -0
- package/runtime/wire/markdown.eli +2 -0
- package/runtime/wire/schema.eli +2 -0
- package/runtime/worker-value-codec.eli +2 -0
- package/runtime/worker-value-stream.eli +2 -0
- package/runtime/worker.eli +2 -0
- package/stdlib/README.md +2 -2
- package/stdlib/core/order.eli +36 -10
- package/stdlib/core/seq.eli +104 -75
- package/stdlib/core/zipper.eli +274 -101
- package/stdlib/managed-literal-protocols.eli +18 -7
- package/stdlib/managed-literals.eli +121 -66
- package/stdlib/managed-runtime-collection.eli +76 -16
- package/stdlib/managed-runtime-metadata.eli +25 -8
- package/stdlib/managed-runtime-order.eli +32 -10
- package/stdlib/managed-runtime-sequence.eli +69 -28
- package/stdlib/managed-runtime-vector.eli +7 -2
- package/tools/acceptance/check.eli +13 -3
- package/tools/backends/compiler-build.mjs +140 -140
- package/tools/backends/dist/release-cli.mjs +2 -0
- package/tools/backends/dist/release-cli.mjs.map +1 -1
- package/tools/backends/stage3-targets.mjs +121 -114
- package/bootstrap/host/eliscript-cli-legacy.mjs +0 -37
package/stdlib/core/order.eli
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
(module eliscript.core.order
|
|
2
2
|
(import "../../runtime/core/collection.mjs" reduce)
|
|
3
3
|
(import "../../runtime/core/order.mjs" :as Runtime)
|
|
4
|
-
(import "../../runtime/core/
|
|
4
|
+
(import "../../runtime/core/transient.mjs" conjBang persistentBang transient)
|
|
5
5
|
(import "../../runtime/core/truth.mjs" isTruthy)
|
|
6
6
|
(import "../../runtime/core/vector.mjs" EMPTY_VECTOR)
|
|
7
7
|
(defconst IComparable Runtime/IComparable)
|
|
@@ -22,12 +22,14 @@
|
|
|
22
22
|
(defun comparator
|
|
23
23
|
(comparison)
|
|
24
24
|
(require-function comparison "comparator comparison")
|
|
25
|
-
(
|
|
26
|
-
|
|
27
|
-
(
|
|
28
|
-
(
|
|
29
|
-
|
|
30
|
-
(if (
|
|
25
|
+
(if (or (eq comparison compare-values) (eq comparison Runtime/compareValues))
|
|
26
|
+
Runtime/compareValues
|
|
27
|
+
(lambda
|
|
28
|
+
(left right)
|
|
29
|
+
(let ((result (funcall comparison left right)))
|
|
30
|
+
(if (= (value-type result) "number")
|
|
31
|
+
(normalize-comparison-result result "comparator comparison")
|
|
32
|
+
(if (isTruthy result) -1 (if (isTruthy (funcall comparison right left)) 1 0)))))))
|
|
31
33
|
(defun reverse-comparator
|
|
32
34
|
(&rest arguments)
|
|
33
35
|
(let ((length (js-length arguments)))
|
|
@@ -66,7 +68,31 @@
|
|
|
66
68
|
(left right)
|
|
67
69
|
(let ((result (funcall comparison (get left :key) (get right :key))))
|
|
68
70
|
(if (= result 0) (- (get left :index) (get right :index)) result))))
|
|
69
|
-
(
|
|
71
|
+
(let ((builder (transient EMPTY_VECTOR)) (index 0) (limit (js-length values)))
|
|
72
|
+
(while (< index limit)
|
|
73
|
+
(conjBang builder (get (js-nth index values) :value))
|
|
74
|
+
(setq index (1+ index)))
|
|
75
|
+
(persistentBang builder)))
|
|
76
|
+
(defun collect-values
|
|
77
|
+
(collection)
|
|
78
|
+
(reduce
|
|
79
|
+
collection
|
|
80
|
+
(lambda
|
|
81
|
+
(result value)
|
|
82
|
+
(js-call result :push value)
|
|
83
|
+
result)
|
|
84
|
+
(js-array)))
|
|
85
|
+
(defun sort-values
|
|
86
|
+
(values comparison)
|
|
87
|
+
(js-call values :sort comparison)
|
|
88
|
+
(let ((from-fn (get (get EMPTY_VECTOR :constructor) :from)))
|
|
89
|
+
(if (not (undefined? from-fn))
|
|
90
|
+
(js-call (get EMPTY_VECTOR :constructor) :from values)
|
|
91
|
+
(let ((builder (transient EMPTY_VECTOR)) (index 0) (limit (js-length values)))
|
|
92
|
+
(while (< index limit)
|
|
93
|
+
(conjBang builder (js-nth index values))
|
|
94
|
+
(setq index (1+ index)))
|
|
95
|
+
(persistentBang builder)))))
|
|
70
96
|
(defun sort
|
|
71
97
|
(&rest arguments)
|
|
72
98
|
(let ((length (js-length arguments)))
|
|
@@ -78,8 +104,8 @@
|
|
|
78
104
|
(let
|
|
79
105
|
((comparison (if (= length 1) compare-values (js-nth 0 arguments)))
|
|
80
106
|
(collection (js-nth (1- length) arguments)))
|
|
81
|
-
(sort-
|
|
82
|
-
(collect-
|
|
107
|
+
(sort-values
|
|
108
|
+
(collect-values collection)
|
|
83
109
|
(comparator comparison))))))
|
|
84
110
|
(defun sort-by
|
|
85
111
|
(key-function &rest arguments)
|
package/stdlib/core/seq.eli
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
persistentVector)
|
|
44
44
|
(defconst not-found (js-object))
|
|
45
45
|
(defconst sequence-no-partition-pad (js-object))
|
|
46
|
-
(defconst sequence-ring (lambda () (new globalThis/
|
|
46
|
+
(defconst sequence-ring (lambda (limit) (new globalThis/Array limit)))
|
|
47
47
|
(defconst sequence-array? (js* "Array.isArray"))
|
|
48
48
|
(defconst sequence-safe-integer? (js* "Number.isSafeInteger"))
|
|
49
49
|
(defconst sequence-finite? (js* "Number.isFinite"))
|
|
@@ -276,14 +276,20 @@
|
|
|
276
276
|
limit))
|
|
277
277
|
(defun first
|
|
278
278
|
(collection &optional not-found-value)
|
|
279
|
-
(
|
|
280
|
-
(
|
|
281
|
-
(
|
|
279
|
+
(cond
|
|
280
|
+
((isPersistentList collection)
|
|
281
|
+
(if (get collection :isEmpty) not-found-value (js-call collection :first not-found-value)))
|
|
282
|
+
((isPersistentVector collection)
|
|
283
|
+
(if (= (get collection :count) 0) not-found-value (js-call collection :nth 0)))
|
|
284
|
+
(t
|
|
285
|
+
(let ((found false) (found-value nil))
|
|
282
286
|
(reduce
|
|
283
287
|
collection
|
|
284
|
-
(lambda (missing value)
|
|
285
|
-
|
|
286
|
-
|
|
288
|
+
(lambda (missing value)
|
|
289
|
+
(setq found t found-value value)
|
|
290
|
+
(reduced missing))
|
|
291
|
+
nil)
|
|
292
|
+
(if found found-value not-found-value)))))
|
|
287
293
|
(defun nth-rest
|
|
288
294
|
(limit collection)
|
|
289
295
|
(require-non-negative-safe-integer limit "nth-rest limit")
|
|
@@ -312,73 +318,98 @@
|
|
|
312
318
|
(defun sequence-nth
|
|
313
319
|
(index collection &optional not-found-value)
|
|
314
320
|
(require-non-negative-safe-integer index "sequence-nth index")
|
|
315
|
-
(let
|
|
316
|
-
(
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
not-found)))
|
|
326
|
-
(if (eq result not-found) not-found-value (get result :value))))
|
|
321
|
+
(let ((position 0) (found false) (found-value nil))
|
|
322
|
+
(reduce
|
|
323
|
+
collection
|
|
324
|
+
(lambda
|
|
325
|
+
(missing value)
|
|
326
|
+
(if (= position index)
|
|
327
|
+
(progn (setq found t found-value value) (reduced missing))
|
|
328
|
+
(progn (setq position (1+ position)) missing)))
|
|
329
|
+
nil)
|
|
330
|
+
(if found found-value not-found-value)))
|
|
327
331
|
(defun last
|
|
328
332
|
(collection &optional not-found-value)
|
|
329
|
-
(
|
|
330
|
-
(
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
333
|
+
(cond
|
|
334
|
+
((isPersistentVector collection)
|
|
335
|
+
(js-call collection :peek not-found-value))
|
|
336
|
+
((implementsProtocolOperation IReversible "rseq" collection)
|
|
337
|
+
(first (rseq collection) not-found-value))
|
|
338
|
+
(t
|
|
339
|
+
(let ((found false) (last-value nil))
|
|
340
|
+
(reduce
|
|
341
|
+
collection
|
|
342
|
+
(lambda (missing value) (setq found t last-value value) missing)
|
|
343
|
+
nil)
|
|
344
|
+
(if found last-value not-found-value)))))
|
|
339
345
|
(defun take-last
|
|
340
346
|
(limit collection)
|
|
341
347
|
(require-non-negative-safe-integer limit "take-last limit")
|
|
342
348
|
(if (= limit 0)
|
|
343
349
|
EMPTY_VECTOR
|
|
344
|
-
(
|
|
345
|
-
(
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
(
|
|
349
|
-
|
|
350
|
-
(
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
(
|
|
350
|
+
(if (isPersistentVector collection)
|
|
351
|
+
(let ((total (get collection :count)))
|
|
352
|
+
(if (= total 0)
|
|
353
|
+
EMPTY_VECTOR
|
|
354
|
+
(if (>= limit total)
|
|
355
|
+
collection
|
|
356
|
+
(if (not (undefined? (get collection :sliceVector)))
|
|
357
|
+
(js-call collection :sliceVector (- total limit) total)
|
|
358
|
+
(let ((builder (transient EMPTY_VECTOR)) (index (- total limit)))
|
|
359
|
+
(while (< index total)
|
|
360
|
+
(conjBang builder (js-call collection :nth index))
|
|
361
|
+
(setq index (1+ index)))
|
|
362
|
+
(persistentBang builder))))))
|
|
363
|
+
(let ((ring (funcall sequence-ring limit)) (count 0) (start 0))
|
|
364
|
+
(reduce
|
|
365
|
+
collection
|
|
366
|
+
(lambda
|
|
367
|
+
(state value)
|
|
368
|
+
(if (< count limit)
|
|
369
|
+
(progn (put ring count value) (setq count (1+ count)))
|
|
370
|
+
(progn (put ring start value) (setq start (% (1+ start) limit))))
|
|
371
|
+
state)
|
|
372
|
+
nil)
|
|
373
|
+
(let ((builder (transient EMPTY_VECTOR)) (index 0))
|
|
374
|
+
(while (< index count)
|
|
375
|
+
(conjBang builder (js-nth (% (+ start index) limit) ring))
|
|
376
|
+
(setq index (1+ index)))
|
|
377
|
+
(persistentBang builder))))))
|
|
359
378
|
(defun drop-last
|
|
360
379
|
(limit collection)
|
|
361
380
|
(require-non-negative-safe-integer limit "drop-last limit")
|
|
362
381
|
(if (= limit 0)
|
|
363
|
-
(into EMPTY_VECTOR collection)
|
|
364
|
-
(
|
|
365
|
-
((
|
|
366
|
-
(
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
+
(if (isPersistentVector collection) collection (into EMPTY_VECTOR collection))
|
|
383
|
+
(if (isPersistentVector collection)
|
|
384
|
+
(let ((total (get collection :count)))
|
|
385
|
+
(if (>= limit total)
|
|
386
|
+
EMPTY_VECTOR
|
|
387
|
+
(let ((keep (- total limit)))
|
|
388
|
+
(if (not (undefined? (get collection :sliceVector)))
|
|
389
|
+
(js-call collection :sliceVector 0 keep)
|
|
390
|
+
(let ((builder (transient EMPTY_VECTOR)) (index 0))
|
|
391
|
+
(while (< index keep)
|
|
392
|
+
(conjBang builder (js-call collection :nth index))
|
|
393
|
+
(setq index (1+ index)))
|
|
394
|
+
(persistentBang builder))))))
|
|
395
|
+
(let
|
|
396
|
+
((ring (funcall sequence-ring limit))
|
|
397
|
+
(builder (transient EMPTY_VECTOR))
|
|
398
|
+
(count 0)
|
|
399
|
+
(start 0))
|
|
400
|
+
(reduce
|
|
401
|
+
collection
|
|
402
|
+
(lambda
|
|
403
|
+
(state value)
|
|
404
|
+
(if (< count limit)
|
|
405
|
+
(progn (put ring count value) (setq count (1+ count)))
|
|
406
|
+
(progn
|
|
407
|
+
(conjBang builder (js-nth start ring))
|
|
408
|
+
(put ring start value)
|
|
409
|
+
(setq start (% (1+ start) limit))))
|
|
410
|
+
state)
|
|
411
|
+
nil)
|
|
412
|
+
(persistentBang builder)))))
|
|
382
413
|
(defun butlast (collection) (drop-last 1 collection))
|
|
383
414
|
(defun split-at
|
|
384
415
|
(limit collection)
|
|
@@ -589,18 +620,16 @@
|
|
|
589
620
|
(defun find
|
|
590
621
|
(predicate collection &optional not-found-value)
|
|
591
622
|
(require-function predicate "find predicate")
|
|
592
|
-
(let
|
|
593
|
-
(
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
not-found)))
|
|
603
|
-
(if (eq result not-found) not-found-value (get result :value))))
|
|
623
|
+
(let ((found false) (found-value nil))
|
|
624
|
+
(reduce
|
|
625
|
+
collection
|
|
626
|
+
(lambda
|
|
627
|
+
(missing value)
|
|
628
|
+
(if (isTruthy (funcall predicate value))
|
|
629
|
+
(progn (setq found t found-value value) (reduced missing))
|
|
630
|
+
missing))
|
|
631
|
+
nil)
|
|
632
|
+
(if found found-value not-found-value)))
|
|
604
633
|
(defun reductions
|
|
605
634
|
(step initial collection)
|
|
606
635
|
(require-function step "reductions step")
|