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
package/stdlib/bit.eli ADDED
@@ -0,0 +1,36 @@
1
+ (module eliscript.bit
2
+ (defportable bit-count (value)
3
+ (let* ((bits (uint32 value))
4
+ (pairs
5
+ (- bits
6
+ (bit-and
7
+ (unsigned-bit-shift-right bits 1)
8
+ 1431655765)))
9
+ (quads
10
+ (+ (bit-and pairs 858993459)
11
+ (bit-and
12
+ (unsigned-bit-shift-right pairs 2)
13
+ 858993459)))
14
+ (octets
15
+ (bit-and
16
+ (+ quads (unsigned-bit-shift-right quads 4))
17
+ 252645135)))
18
+ (unsigned-bit-shift-right
19
+ (imul32 octets 16843009)
20
+ 24)))
21
+
22
+ (defportable rotate-left (value distance)
23
+ (let ((amount (bit-and distance 31)))
24
+ (uint32
25
+ (bit-or
26
+ (bit-shift-left value amount)
27
+ (unsigned-bit-shift-right value (- 32 amount))))))
28
+
29
+ (defportable rotate-right (value distance)
30
+ (let ((amount (bit-and distance 31)))
31
+ (uint32
32
+ (bit-or
33
+ (unsigned-bit-shift-right value amount)
34
+ (bit-shift-left value (- 32 amount))))))
35
+
36
+ (export bit-count rotate-left rotate-right))
@@ -0,0 +1,134 @@
1
+ (module eliscript.core.collection
2
+ (import "../../runtime/core/collection.mjs" :as Runtime)
3
+ (import "../../runtime/core/vector.mjs" :as Vector)
4
+ (defconst ICounted Runtime/ICounted)
5
+ (defconst IEmptyable Runtime/IEmptyable)
6
+ (defconst IConj Runtime/IConj)
7
+ (defconst ILookup Runtime/ILookup)
8
+ (defconst IAssociative Runtime/IAssociative)
9
+ (defconst IIndexed Runtime/IIndexed)
10
+ (defconst ISeqable Runtime/ISeqable)
11
+ (defconst IReduce Runtime/IReduce)
12
+ (defconst IKVReduce Runtime/IKVReduce)
13
+ (defconst IMap Runtime/IMap)
14
+ (defconst ISet Runtime/ISet)
15
+ (defconst IStack Runtime/IStack)
16
+ (defconst IReversible Runtime/IReversible)
17
+ (defconst ReductionView Runtime/ReductionView)
18
+ (defconst SequenceView Runtime/SequenceView)
19
+ (defun collection-count (collection) (Runtime/count collection))
20
+ (defun counted? (collection) (Runtime/isCounted collection))
21
+ (defun indexed? (collection) (Runtime/isIndexed collection))
22
+ (defun seqable? (collection) (Runtime/isSeqable collection))
23
+ (defun reducible? (collection) (Runtime/isReducible collection))
24
+ (defun reversible? (collection) (Runtime/isReversible collection))
25
+ (defun associative? (collection) (Runtime/isAssociative collection))
26
+ (defun collection? (value) (Runtime/isCollection value))
27
+ (defun list? (value) (Runtime/isList value))
28
+ (defun vector? (value) (Runtime/isVector value))
29
+ (defun map? (value) (Runtime/isMap value))
30
+ (defun queue? (value) (Runtime/isQueue value))
31
+ (defun set? (value) (Runtime/isSet value))
32
+ (defun sequential? (value) (Runtime/isSequential value))
33
+ (defun sequence? (value) (Runtime/isSequence value))
34
+ (defun bounded-count (limit collection) (Runtime/boundedCount limit collection))
35
+ (defun distinct? (&rest values) (apply Runtime/areDistinct values))
36
+ (defun subvec (vector start &optional end) (Vector/subvec vector start end))
37
+ (defun empty (collection) (Runtime/empty collection))
38
+ (defun conj
39
+ (collection &rest values)
40
+ (apply Runtime/conj (js-cons collection values)))
41
+ (defun assoc
42
+ (collection key value &rest key-values)
43
+ (apply Runtime/assoc (js-cons collection (js-cons key (js-cons value key-values)))))
44
+ (defun lookup
45
+ (collection key &rest not-found)
46
+ (apply Runtime/get (js-cons collection (js-cons key not-found))))
47
+ (defun contains? (collection key) (Runtime/contains collection key))
48
+ (defun collection-nth
49
+ (collection index &rest not-found)
50
+ (apply Runtime/nth (js-cons collection (js-cons index not-found))))
51
+ (defun reduce
52
+ (collection reducer &rest initial)
53
+ (apply Runtime/reduce (js-cons collection (js-cons reducer initial))))
54
+ (defun reduce-kv
55
+ (collection reducer initial)
56
+ (Runtime/reduceKV collection reducer initial))
57
+ (defun dissoc
58
+ (collection &rest keys)
59
+ (apply Runtime/dissoc (js-cons collection keys)))
60
+ (defun disj
61
+ (collection &rest values)
62
+ (apply Runtime/disj (js-cons collection values)))
63
+ (defun peek (collection) (Runtime/peek collection))
64
+ (defun pop (collection) (Runtime/pop collection))
65
+ (defun rseq (collection) (Runtime/rseq collection))
66
+ (defun collection-seq (collection) (Runtime/seq collection))
67
+ (defun empty? (collection) (Runtime/isEmpty collection))
68
+ (defun not-empty (collection) (Runtime/notEmpty collection))
69
+ (defun reduced (value) (Runtime/reduced value))
70
+ (defun reduced? (value) (Runtime/isReduced value))
71
+ (defun unreduced (value) (Runtime/unreduced value))
72
+ (defun sequence-view
73
+ (factory &rest count)
74
+ (apply Runtime/sequenceView (js-cons factory count)))
75
+ (defun unbounded-sequence-view (factory) (Runtime/unboundedSequenceView factory))
76
+ (defun reduction-view (reduce-function) (Runtime/reductionView reduce-function))
77
+ (defun reduction-view? (value) (Runtime/isReductionView value))
78
+ (export
79
+ IAssociative
80
+ IConj
81
+ ICounted
82
+ IEmptyable
83
+ IIndexed
84
+ ILookup
85
+ IReduce
86
+ IKVReduce
87
+ IMap
88
+ ISet
89
+ IStack
90
+ IReversible
91
+ ISeqable
92
+ ReductionView
93
+ SequenceView
94
+ assoc
95
+ associative?
96
+ bounded-count
97
+ collection-count
98
+ collection-nth
99
+ collection-seq
100
+ collection?
101
+ conj
102
+ contains?
103
+ counted?
104
+ empty
105
+ empty?
106
+ indexed?
107
+ list?
108
+ lookup
109
+ map?
110
+ not-empty
111
+ queue?
112
+ reduce
113
+ reduce-kv
114
+ reducible?
115
+ dissoc
116
+ disj
117
+ distinct?
118
+ peek
119
+ pop
120
+ rseq
121
+ reversible?
122
+ sequence?
123
+ sequential?
124
+ seqable?
125
+ set?
126
+ subvec
127
+ reduced
128
+ reduced?
129
+ reduction-view
130
+ reduction-view?
131
+ sequence-view
132
+ unbounded-sequence-view
133
+ unreduced
134
+ vector?))
@@ -0,0 +1,16 @@
1
+ (module eliscript.core.data-text
2
+ (import "../../runtime/core/data-text.mjs" :as Runtime)
3
+
4
+ (defconst DataTextError Runtime/DataTextError)
5
+ (defconst IPrint Runtime/IPrint)
6
+
7
+ (defun print-value (value &optional options)
8
+ (Runtime/printValue value options))
9
+
10
+ (defun read-value (source &optional options)
11
+ (Runtime/readValue source options))
12
+
13
+ (defun read-values (source &optional options)
14
+ (Runtime/readValues source options))
15
+
16
+ (export DataTextError IPrint print-value read-value read-values))
@@ -0,0 +1,306 @@
1
+ (module eliscript.core.data
2
+ (import "../../runtime/core/collection.mjs" :as Collection)
3
+ (import "../../runtime/core/map.mjs" EMPTY_MAP)
4
+ (import "../../runtime/core/protocol.mjs" :as Protocol)
5
+ (import "../../runtime/core/transducer.mjs" into)
6
+ (import "../../runtime/core/transient.mjs"
7
+ assocBang
8
+ conjBang
9
+ persistentBang
10
+ transient)
11
+ (import "../../runtime/core/vector.mjs" EMPTY_VECTOR)
12
+ (defconst missing-value (js-object))
13
+ (defun require-function
14
+ (value label)
15
+ (if (= (value-type value) "function")
16
+ value
17
+ (throw (new globalThis/TypeError (str label " must be a function")))))
18
+ (defun nullish? (value) (or (eq value nil) (eq value globalThis/undefined)))
19
+ (defun path-vector (path) (into EMPTY_VECTOR path))
20
+ (defun read-entry
21
+ (entry)
22
+ (if (= (Collection/count entry) 2)
23
+ (js-object :key (Collection/nth entry 0) :value (Collection/nth entry 1))
24
+ (throw
25
+ (new
26
+ globalThis/TypeError
27
+ "data entries must contain exactly one key/value pair"))))
28
+ (defun reduce-entries
29
+ (collection reducer initial)
30
+ (if
31
+ (and
32
+ (Protocol/implementsProtocolOperation
33
+ Collection/IKVReduce
34
+ "reduceKV"
35
+ collection)
36
+ (not
37
+ (Protocol/implementsProtocolOperation Collection/IIndexed "nth" collection)))
38
+ (Collection/reduceKV collection reducer initial)
39
+ (Collection/reduce
40
+ collection
41
+ (lambda
42
+ (result entry)
43
+ (let ((pair (read-entry entry)))
44
+ (funcall reducer result (get pair :key) (get pair :value))))
45
+ initial)))
46
+ (defun collect-buckets
47
+ (key-function collection create-bucket update-bucket)
48
+ (require-function key-function "data key function")
49
+ (let ((bucket-index EMPTY_MAP) (keys (js-array)) (buckets (js-array)))
50
+ (Collection/reduce
51
+ collection
52
+ (lambda
53
+ (result value)
54
+ (let*
55
+ ((key (funcall key-function value))
56
+ (index (js-call bucket-index :get key missing-value)))
57
+ (if (eq index missing-value)
58
+ (progn
59
+ (setq
60
+ index
61
+ (js-length keys)
62
+ bucket-index
63
+ (js-call bucket-index :assoc key index))
64
+ (js-call keys :push key)
65
+ (js-call buckets :push (funcall create-bucket value)))
66
+ (funcall update-bucket buckets index value))
67
+ result))
68
+ nil)
69
+ (js-object :keys keys :buckets buckets)))
70
+ (defun persistent-map-from-buckets
71
+ (keys buckets finish-bucket)
72
+ (let ((result (transient EMPTY_MAP)) (index 0))
73
+ (while (< index (js-length keys))
74
+ (assocBang
75
+ result
76
+ (js-nth index keys)
77
+ (funcall finish-bucket (js-nth index buckets)))
78
+ (setq index (1+ index)))
79
+ (persistentBang result)))
80
+ (defun index-by
81
+ (key-function collection)
82
+ (require-function key-function "indexBy key function")
83
+ (let ((result (transient EMPTY_MAP)))
84
+ (Collection/reduce
85
+ collection
86
+ (lambda
87
+ (builder value)
88
+ (assocBang builder (funcall key-function value) value)
89
+ builder)
90
+ result)
91
+ (persistentBang result)))
92
+ (defun group-by
93
+ (key-function collection)
94
+ (let*
95
+ (
96
+ (grouped
97
+ (collect-buckets
98
+ key-function
99
+ collection
100
+ (lambda (value) (js-array value))
101
+ (lambda (buckets index value) (js-call (js-nth index buckets) :push value))))
102
+ (keys (get grouped :keys))
103
+ (buckets (get grouped :buckets)))
104
+ (persistent-map-from-buckets
105
+ keys
106
+ buckets
107
+ (lambda (values) (into EMPTY_VECTOR values)))))
108
+ (defun count-by
109
+ (key-function collection)
110
+ (let*
111
+ (
112
+ (counted
113
+ (collect-buckets
114
+ key-function
115
+ collection
116
+ (lambda (_value) 1)
117
+ (lambda (counts index _value) (put counts index (1+ (js-nth index counts))))))
118
+ (keys (get counted :keys))
119
+ (buckets (get counted :buckets)))
120
+ (persistent-map-from-buckets keys buckets (lambda (count) count))))
121
+ (defun frequencies (collection) (count-by (lambda (value) value) collection))
122
+ (defun get-in
123
+ (collection path &optional not-found)
124
+ (let*
125
+ ((keys (path-vector path))
126
+ (size (Collection/count keys))
127
+ (index 0)
128
+ (current collection))
129
+ (while (and (< index size) (not (nullish? current)))
130
+ (setq
131
+ current
132
+ (Collection/get current (Collection/nth keys index) missing-value))
133
+ (if (eq current missing-value) (setq index size) (setq index (1+ index))))
134
+ (if (or (eq current missing-value) (and (< index size) (nullish? current)))
135
+ not-found
136
+ current)))
137
+ (defun assoc-in
138
+ (collection path value)
139
+ (let* ((keys (path-vector path)) (size (Collection/count keys)))
140
+ (if (= size 0)
141
+ value
142
+ (let ((parents (js-array)) (current collection) (index 0))
143
+ (while (< index (1- size))
144
+ (js-call parents :push current)
145
+ (if (nullish? current)
146
+ (setq current EMPTY_MAP)
147
+ (let
148
+ (
149
+ (child
150
+ (Collection/get current (Collection/nth keys index) missing-value)))
151
+ (setq
152
+ current
153
+ (if (or (eq child missing-value) (nullish? child)) EMPTY_MAP child))))
154
+ (setq index (1+ index)))
155
+ (let
156
+ (
157
+ (result
158
+ (Collection/assoc
159
+ (if (nullish? current) EMPTY_MAP current)
160
+ (Collection/nth keys (1- size))
161
+ value)))
162
+ (setq index (- size 2))
163
+ (while (>= index 0)
164
+ (setq
165
+ current
166
+ (js-nth index parents)
167
+ result
168
+ (Collection/assoc
169
+ (if (nullish? current) EMPTY_MAP current)
170
+ (Collection/nth keys index)
171
+ result)
172
+ index
173
+ (1- index)))
174
+ result)))))
175
+ (defun update
176
+ (collection key transform &rest arguments)
177
+ (require-function transform "update transform")
178
+ (let ((target (if (nullish? collection) EMPTY_MAP collection)))
179
+ (Collection/assoc
180
+ target
181
+ key
182
+ (apply transform (js-cons (Collection/get target key) arguments)))))
183
+ (defun update-in
184
+ (collection path transform &rest arguments)
185
+ (require-function transform "updateIn transform")
186
+ (assoc-in
187
+ collection
188
+ path
189
+ (apply transform (js-cons (get-in collection path) arguments))))
190
+ (defun keys
191
+ (collection)
192
+ (let ((result (transient EMPTY_VECTOR)))
193
+ (Collection/reduceKV
194
+ collection
195
+ (lambda (builder key _value) (conjBang builder key) builder)
196
+ result)
197
+ (persistentBang result)))
198
+ (defun vals
199
+ (collection)
200
+ (let ((result (transient EMPTY_VECTOR)))
201
+ (Collection/reduceKV
202
+ collection
203
+ (lambda (builder _key value) (conjBang builder value) builder)
204
+ result)
205
+ (persistentBang result)))
206
+ (defun update-keys
207
+ (collection transform)
208
+ (require-function transform "updateKeys transform")
209
+ (let ((result (transient EMPTY_MAP)))
210
+ (Collection/reduceKV
211
+ collection
212
+ (lambda
213
+ (builder key value)
214
+ (assocBang builder (funcall transform key) value)
215
+ builder)
216
+ result)
217
+ (persistentBang result)))
218
+ (defun update-vals
219
+ (collection transform)
220
+ (require-function transform "updateVals transform")
221
+ (let ((result (transient EMPTY_MAP)))
222
+ (Collection/reduceKV
223
+ collection
224
+ (lambda
225
+ (builder key value)
226
+ (assocBang builder key (funcall transform value))
227
+ builder)
228
+ result)
229
+ (persistentBang result)))
230
+ (defun select-keys
231
+ (collection keys)
232
+ (let ((result (transient EMPTY_MAP)))
233
+ (Collection/reduce
234
+ keys
235
+ (lambda
236
+ (builder key)
237
+ (when (and (not (nullish? collection)) (Collection/contains collection key))
238
+ (assocBang builder key (Collection/get collection key)))
239
+ builder)
240
+ result)
241
+ (persistentBang result)))
242
+ (defun merge
243
+ (&rest collections)
244
+ (let ((result (transient EMPTY_MAP)) (index 0))
245
+ (while (< index (js-length collections))
246
+ (reduce-entries
247
+ (js-nth index collections)
248
+ (lambda (builder key value) (assocBang builder key value) builder)
249
+ result)
250
+ (setq index (1+ index)))
251
+ (persistentBang result)))
252
+ (defun merge-with
253
+ (combine &rest collections)
254
+ (require-function combine "mergeWith combine function")
255
+ (let ((result EMPTY_MAP) (index 0))
256
+ (while (< index (js-length collections))
257
+ (setq
258
+ result
259
+ (reduce-entries
260
+ (js-nth index collections)
261
+ (lambda
262
+ (current key value)
263
+ (Collection/assoc
264
+ current
265
+ key
266
+ (if (Collection/contains current key)
267
+ (funcall combine (Collection/get current key) value)
268
+ value)))
269
+ result)
270
+ index
271
+ (1+ index)))
272
+ result))
273
+ (defun zipmap
274
+ (keys values)
275
+ (let*
276
+ ((key-vector (path-vector keys))
277
+ (value-vector (path-vector values))
278
+ (key-count (Collection/count key-vector))
279
+ (value-count (Collection/count value-vector))
280
+ (size (if (< key-count value-count) key-count value-count))
281
+ (result (transient EMPTY_MAP))
282
+ (index 0))
283
+ (while (< index size)
284
+ (assocBang
285
+ result
286
+ (Collection/nth key-vector index)
287
+ (Collection/nth value-vector index))
288
+ (setq index (1+ index)))
289
+ (persistentBang result)))
290
+ (export
291
+ assoc-in
292
+ count-by
293
+ frequencies
294
+ get-in
295
+ group-by
296
+ index-by
297
+ keys
298
+ merge
299
+ merge-with
300
+ select-keys
301
+ update
302
+ update-in
303
+ update-keys
304
+ update-vals
305
+ vals
306
+ zipmap))
@@ -0,0 +1,32 @@
1
+ (module eliscript.core.identifier
2
+ (import "../../runtime/core/identifier.mjs" :as Runtime)
3
+
4
+ (defconst Keyword Runtime/Keyword)
5
+ (defconst EliscriptSymbol Runtime/EliscriptSymbol)
6
+
7
+ (defun keyword (&rest arguments)
8
+ (apply Runtime/keyword arguments))
9
+
10
+ (defun keyword? (value)
11
+ (Runtime/isKeyword value))
12
+
13
+ (defun symbol (&rest arguments)
14
+ (apply Runtime/eliscriptSymbol arguments))
15
+
16
+ (defun symbol? (value)
17
+ (Runtime/isEliscriptSymbol value))
18
+
19
+ (defun identifier? (value)
20
+ (Runtime/isIdentifier value))
21
+
22
+ (defun identifier-name (value)
23
+ (Runtime/identifierName value))
24
+
25
+ (defun identifier-namespace (value)
26
+ (Runtime/identifierNamespace value))
27
+
28
+ (defun qualified-name (value)
29
+ (Runtime/qualifiedIdentifierName value))
30
+
31
+ (export EliscriptSymbol Keyword identifier-name identifier-namespace
32
+ identifier? keyword keyword? qualified-name symbol symbol?))
@@ -0,0 +1,63 @@
1
+ (module eliscript.core.lazy-sequence
2
+ (import "../../runtime/core/lazy-sequence.mjs" :as Runtime)
3
+ (defun lazy-seq (thunk) (Runtime/lazySequence thunk))
4
+ (defun lazy-cons (value tail-thunk) (Runtime/lazyCons value tail-thunk))
5
+ (defun lazy-map (transform collection) (Runtime/lazyMap transform collection))
6
+ (defun lazy-map-indexed
7
+ (transform collection)
8
+ (Runtime/lazyMapIndexed transform collection))
9
+ (defun lazy-keep (transform collection) (Runtime/lazyKeep transform collection))
10
+ (defun lazy-keep-indexed
11
+ (transform collection)
12
+ (Runtime/lazyKeepIndexed transform collection))
13
+ (defun lazy-filter (predicate collection) (Runtime/lazyFilter predicate collection))
14
+ (defun lazy-remove (predicate collection) (Runtime/lazyRemove predicate collection))
15
+ (defun lazy-take (limit collection) (Runtime/lazyTake limit collection))
16
+ (defun lazy-drop (limit collection) (Runtime/lazyDrop limit collection))
17
+ (defun lazy-take-while
18
+ (predicate collection)
19
+ (Runtime/lazyTakeWhile predicate collection))
20
+ (defun lazy-drop-while
21
+ (predicate collection)
22
+ (Runtime/lazyDropWhile predicate collection))
23
+ (defun lazy-take-nth (interval collection) (Runtime/lazyTakeNth interval collection))
24
+ (defun lazy-interpose
25
+ (separator collection)
26
+ (Runtime/lazyInterpose separator collection))
27
+ (defun lazy-dedupe (collection) (Runtime/lazyDedupe collection))
28
+ (defun lazy-distinct (collection) (Runtime/lazyDistinct collection))
29
+ (defun lazy-mapcat (transform collection) (Runtime/lazyMapcat transform collection))
30
+ (defun lazy-partition-all
31
+ (size collection)
32
+ (Runtime/lazyPartitionAll size collection))
33
+ (defun lazy-partition-by
34
+ (classifier collection)
35
+ (Runtime/lazyPartitionBy classifier collection))
36
+ (defun lazy-seq? (value) (Runtime/isLazySequence value))
37
+ (defun realized? (value) (Runtime/isLazySequenceRealized value))
38
+ (defun realized-count (value) (Runtime/realizedLazySequenceCount value))
39
+ (defun realize (value) (Runtime/realizeLazySequence value))
40
+ (export
41
+ lazy-cons
42
+ lazy-dedupe
43
+ lazy-distinct
44
+ lazy-drop
45
+ lazy-drop-while
46
+ lazy-filter
47
+ lazy-interpose
48
+ lazy-keep
49
+ lazy-keep-indexed
50
+ lazy-map
51
+ lazy-map-indexed
52
+ lazy-mapcat
53
+ lazy-partition-all
54
+ lazy-partition-by
55
+ lazy-remove
56
+ lazy-seq
57
+ lazy-seq?
58
+ lazy-take
59
+ lazy-take-nth
60
+ lazy-take-while
61
+ realize
62
+ realized-count
63
+ realized?))
@@ -0,0 +1,20 @@
1
+ (module eliscript.core.metadata
2
+ (import "../../runtime/core/metadata.mjs" :as Runtime)
3
+
4
+ (defconst IMeta Runtime/IMeta)
5
+ (defconst IWithMeta Runtime/IWithMeta)
6
+
7
+ (defun supports-metadata? (value)
8
+ (Runtime/supportsMetadata value))
9
+
10
+ (defun meta (value)
11
+ (Runtime/meta value))
12
+
13
+ (defun with-meta (value metadata)
14
+ (Runtime/withMeta value metadata))
15
+
16
+ (defun vary-meta (value transform &rest arguments)
17
+ (apply Runtime/varyMeta
18
+ (js-cons value (js-cons transform arguments))))
19
+
20
+ (export IMeta IWithMeta meta supports-metadata? vary-meta with-meta))
@@ -0,0 +1,89 @@
1
+ (module eliscript.core.object
2
+ (import "../../runtime/core/collection.mjs" :as Collection)
3
+ (import "../../runtime/core/transducer.mjs" :as Transducer)
4
+ (import "../../runtime/core/truth.mjs" isTruthy)
5
+ (import "../../runtime/core/value.mjs" equalValues)
6
+ (import "../../runtime/core/vector.mjs" EMPTY_VECTOR)
7
+
8
+ (defun entry-key (entry)
9
+ (Collection/nth entry 0))
10
+
11
+ (defun entry-value (entry)
12
+ (Collection/nth entry 1))
13
+
14
+ (defun keys (object)
15
+ (Transducer/into
16
+ EMPTY_VECTOR
17
+ (Transducer/mapping entry-key)
18
+ object))
19
+
20
+ (defun has? (object key)
21
+ (Collection/contains object key))
22
+
23
+ (defun assoc (object key value &rest key-values)
24
+ (apply Collection/assoc
25
+ (js-cons object (js-cons key (js-cons value key-values)))))
26
+
27
+ (defun key-in? (key key-list)
28
+ (Collection/reduce
29
+ key-list
30
+ (lambda (matched current)
31
+ (if (equalValues key current)
32
+ (Collection/reduced t)
33
+ matched))
34
+ false))
35
+
36
+ (defun dissoc (object key)
37
+ (if (not (has? object key))
38
+ object
39
+ (Transducer/into
40
+ object
41
+ (Transducer/filtering
42
+ (lambda (entry) (not (equalValues key (entry-key entry)))))
43
+ object)))
44
+
45
+ (defun merge (left right)
46
+ (Collection/reduce
47
+ right
48
+ (lambda (result entry)
49
+ (Collection/assoc result (entry-key entry) (entry-value entry)))
50
+ left))
51
+
52
+ (defun map-values (function object)
53
+ (Transducer/into
54
+ object
55
+ (Transducer/mapping
56
+ (lambda (entry)
57
+ (js-array (entry-key entry) (funcall function (entry-value entry)))))
58
+ object))
59
+
60
+ (defun filter-values (predicate object)
61
+ (Transducer/into
62
+ object
63
+ (Transducer/filtering
64
+ (lambda (entry)
65
+ (isTruthy (funcall predicate (entry-value entry)))))
66
+ object))
67
+
68
+ (defun pick (object wanted-keys)
69
+ (Transducer/into
70
+ object
71
+ (Transducer/composeTransducers
72
+ (Transducer/filtering (lambda (key) (has? object key)))
73
+ (Transducer/mapping
74
+ (lambda (key) (js-array key (Collection/get object key)))))
75
+ wanted-keys))
76
+
77
+ (defun omit (object omitted-keys)
78
+ (Transducer/into
79
+ object
80
+ (Transducer/filtering
81
+ (lambda (entry) (not (key-in? (entry-key entry) omitted-keys))))
82
+ object))
83
+
84
+ (defun update (object key function)
85
+ (Collection/assoc
86
+ object key (funcall function (Collection/get object key))))
87
+
88
+ (export assoc dissoc filter-values has? key-in? keys map-values merge omit
89
+ pick update))