eliscript 0.0.3 → 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.
Files changed (96) hide show
  1. package/README.md +5 -5
  2. package/bootstrap/README.md +13 -8
  3. package/bootstrap/host/build.eli +2 -0
  4. package/bootstrap/host/bun.eli +2 -0
  5. package/bootstrap/host/check-cli-legacy.eli +2 -0
  6. package/bootstrap/host/evaluation-cli.eli +2 -0
  7. package/bootstrap/host/evaluation.eli +2 -0
  8. package/bootstrap/host/format-cli.eli +2 -0
  9. package/bootstrap/host/project-cli-legacy.eli +2 -0
  10. package/bootstrap/host/project-legacy.eli +2 -0
  11. package/bootstrap/host/watch-cli.eli +2 -0
  12. package/bootstrap/host/watch.eli +2 -0
  13. package/browser/README.md +33 -0
  14. package/browser/host.eli +2 -0
  15. package/browser/worker.eli +2 -0
  16. package/package.json +2 -1
  17. package/platform/README.md +33 -12
  18. package/platform/browser.eli +2 -0
  19. package/platform/http.eli +2 -0
  20. package/platform/worker.eli +2 -0
  21. package/runtime/README.md +34 -14
  22. package/runtime/array-text.eli +2 -0
  23. package/runtime/core/collection-internals.eli +2 -0
  24. package/runtime/core/collection.eli +2 -0
  25. package/runtime/core/collection.mjs +99 -17
  26. package/runtime/core/data-text.eli +2 -0
  27. package/runtime/core/data.eli +2 -0
  28. package/runtime/core/data.mjs +7 -5
  29. package/runtime/core/identifier.eli +2 -0
  30. package/runtime/core/lazy-sequence.eli +2 -0
  31. package/runtime/core/list-internals.eli +2 -0
  32. package/runtime/core/list.eli +2 -0
  33. package/runtime/core/list.mjs +3 -0
  34. package/runtime/core/map-internals.eli +2 -0
  35. package/runtime/core/map.eli +2 -0
  36. package/runtime/core/map.mjs +5 -0
  37. package/runtime/core/metadata-internals.eli +2 -0
  38. package/runtime/core/metadata.eli +2 -0
  39. package/runtime/core/metadata.mjs +14 -0
  40. package/runtime/core/object.eli +2 -0
  41. package/runtime/core/order.eli +2 -0
  42. package/runtime/core/order.mjs +35 -6
  43. package/runtime/core/persistent-kind.eli +2 -0
  44. package/runtime/core/persistent-kind.mjs +6 -0
  45. package/runtime/core/protocol-error.eli +2 -0
  46. package/runtime/core/protocol.eli +2 -0
  47. package/runtime/core/queue-internals.eli +2 -0
  48. package/runtime/core/queue.eli +2 -0
  49. package/runtime/core/queue.mjs +3 -0
  50. package/runtime/core/record.eli +2 -0
  51. package/runtime/core/regex.eli +2 -0
  52. package/runtime/core/sequence.eli +2 -0
  53. package/runtime/core/sequence.mjs +75 -13
  54. package/runtime/core/set-algebra.eli +2 -0
  55. package/runtime/core/set-internals.eli +2 -0
  56. package/runtime/core/set.eli +2 -0
  57. package/runtime/core/sorted-internals.eli +2 -0
  58. package/runtime/core/sorted.eli +2 -0
  59. package/runtime/core/text.eli +2 -0
  60. package/runtime/core/transducer.eli +2 -0
  61. package/runtime/core/transient-internals.eli +2 -0
  62. package/runtime/core/transient.eli +2 -0
  63. package/runtime/core/transient.mjs +59 -10
  64. package/runtime/core/truth.eli +2 -0
  65. package/runtime/core/type.eli +2 -0
  66. package/runtime/core/value-internals.eli +2 -0
  67. package/runtime/core/value.eli +2 -0
  68. package/runtime/core/vector-internals.eli +2 -0
  69. package/runtime/core/vector-internals.mjs +3 -6
  70. package/runtime/core/vector.eli +2 -0
  71. package/runtime/core/vector.mjs +125 -7
  72. package/runtime/literals.eli +2 -0
  73. package/runtime/number-radix.eli +2 -0
  74. package/runtime/source-mapping.eli +2 -0
  75. package/runtime/testing/list.eli +2 -0
  76. package/runtime/testing/map.eli +2 -0
  77. package/runtime/testing/queue.eli +2 -0
  78. package/runtime/testing/set.eli +2 -0
  79. package/runtime/testing/sorted.eli +2 -0
  80. package/runtime/testing/value.eli +2 -0
  81. package/runtime/testing/vector.eli +2 -0
  82. package/runtime/wire/http-rpc.eli +2 -0
  83. package/runtime/wire/markdown.eli +2 -0
  84. package/runtime/wire/schema.eli +2 -0
  85. package/runtime/worker-value-codec.eli +2 -0
  86. package/runtime/worker-value-stream.eli +2 -0
  87. package/runtime/worker.eli +2 -0
  88. package/stdlib/README.md +2 -2
  89. package/stdlib/core/order.eli +36 -10
  90. package/stdlib/core/seq.eli +104 -75
  91. package/stdlib/core/zipper.eli +238 -98
  92. package/stdlib/managed-literal-protocols.eli +5 -5
  93. package/stdlib/managed-runtime-order.eli +32 -10
  94. package/stdlib/managed-runtime-sequence.eli +69 -28
  95. package/tools/acceptance/check.eli +13 -3
  96. package/tools/backends/compiler-build.mjs +140 -140
@@ -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/Map)))
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
- (let
280
- (
281
- (result
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) (reduced (js-object :value value)))
285
- not-found)))
286
- (if (eq result not-found) not-found-value (get result :value))))
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
- ((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))))
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
- (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)))))
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
- (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)))))
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
- (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
+ (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
- (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))))
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")