@mojir/lits 2.1.40 → 2.2.0

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 (324) hide show
  1. package/README.md +25 -24
  2. package/dist/cli/cli.js +21071 -20546
  3. package/dist/cli/reference/api.d.ts +32 -18
  4. package/dist/cli/reference/index.d.ts +129 -209
  5. package/dist/cli/src/builtin/bindingNode.d.ts +1 -1
  6. package/dist/cli/src/builtin/core/vector.d.ts +2 -0
  7. package/dist/cli/src/builtin/interface.d.ts +23 -23
  8. package/dist/cli/src/builtin/modules/bitwise/index.d.ts +2 -0
  9. package/dist/cli/src/builtin/modules/collection/index.d.ts +2 -0
  10. package/dist/cli/src/builtin/modules/functional/index.d.ts +2 -0
  11. package/dist/cli/src/builtin/modules/math/index.d.ts +2 -0
  12. package/dist/cli/src/builtin/modules/sequence/index.d.ts +2 -0
  13. package/dist/cli/src/builtin/modules/string/index.d.ts +2 -0
  14. package/dist/cli/src/parser/Parser.d.ts +1 -1
  15. package/dist/cli/src/parser/types.d.ts +1 -1
  16. package/dist/cli/src/tokenizer/token.d.ts +2 -2
  17. package/dist/full.esm.js +1 -1
  18. package/dist/full.esm.js.map +1 -1
  19. package/dist/full.js +1 -1
  20. package/dist/full.js.map +1 -1
  21. package/dist/index.esm.js +1 -1
  22. package/dist/index.esm.js.map +1 -1
  23. package/dist/index.js +1 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/lits.iife.js +1 -1
  26. package/dist/lits.iife.js.map +1 -1
  27. package/dist/modules/assert.esm.js +1 -1
  28. package/dist/modules/assert.esm.js.map +1 -1
  29. package/dist/modules/assert.js +1 -1
  30. package/dist/modules/assert.js.map +1 -1
  31. package/dist/modules/bitwise.esm.js +2 -0
  32. package/dist/modules/bitwise.esm.js.map +1 -0
  33. package/dist/modules/bitwise.js +2 -0
  34. package/dist/modules/bitwise.js.map +1 -0
  35. package/dist/modules/collection.esm.js +2 -0
  36. package/dist/modules/collection.esm.js.map +1 -0
  37. package/dist/modules/collection.js +2 -0
  38. package/dist/modules/collection.js.map +1 -0
  39. package/dist/modules/functional.esm.js +2 -0
  40. package/dist/modules/functional.esm.js.map +1 -0
  41. package/dist/modules/functional.js +2 -0
  42. package/dist/modules/functional.js.map +1 -0
  43. package/dist/modules/grid.esm.js +1 -1
  44. package/dist/modules/grid.esm.js.map +1 -1
  45. package/dist/modules/grid.js +1 -1
  46. package/dist/modules/grid.js.map +1 -1
  47. package/dist/modules/linear-algebra.esm.js +2 -0
  48. package/dist/modules/linear-algebra.esm.js.map +1 -0
  49. package/dist/modules/linear-algebra.js +2 -0
  50. package/dist/modules/linear-algebra.js.map +1 -0
  51. package/dist/modules/math.esm.js +2 -0
  52. package/dist/modules/math.esm.js.map +1 -0
  53. package/dist/modules/math.js +2 -0
  54. package/dist/modules/math.js.map +1 -0
  55. package/dist/modules/matrix.esm.js +1 -1
  56. package/dist/modules/matrix.esm.js.map +1 -1
  57. package/dist/modules/matrix.js +1 -1
  58. package/dist/modules/matrix.js.map +1 -1
  59. package/dist/modules/number-theory.esm.js +2 -0
  60. package/dist/modules/number-theory.esm.js.map +1 -0
  61. package/dist/modules/number-theory.js +2 -0
  62. package/dist/modules/number-theory.js.map +1 -0
  63. package/dist/modules/random.esm.js +1 -1
  64. package/dist/modules/random.esm.js.map +1 -1
  65. package/dist/modules/random.js +1 -1
  66. package/dist/modules/random.js.map +1 -1
  67. package/dist/modules/reference/api.d.ts +32 -18
  68. package/dist/modules/reference/index.d.ts +129 -209
  69. package/dist/modules/sequence.esm.js +2 -0
  70. package/dist/modules/sequence.esm.js.map +1 -0
  71. package/dist/modules/sequence.js +2 -0
  72. package/dist/modules/sequence.js.map +1 -0
  73. package/dist/modules/src/builtin/bindingNode.d.ts +1 -1
  74. package/dist/modules/src/builtin/core/vector.d.ts +2 -0
  75. package/dist/modules/src/builtin/interface.d.ts +23 -23
  76. package/dist/modules/src/builtin/modules/bitwise/index.d.ts +2 -0
  77. package/dist/modules/src/builtin/modules/collection/index.d.ts +2 -0
  78. package/dist/modules/src/builtin/modules/functional/index.d.ts +2 -0
  79. package/dist/modules/src/builtin/modules/math/index.d.ts +2 -0
  80. package/dist/modules/src/builtin/modules/sequence/index.d.ts +2 -0
  81. package/dist/modules/src/builtin/modules/string/index.d.ts +2 -0
  82. package/dist/modules/src/full.d.ts +6 -16
  83. package/dist/modules/src/modules/bitwise.d.ts +2 -0
  84. package/dist/modules/src/modules/collection.d.ts +2 -0
  85. package/dist/modules/src/modules/functional.d.ts +2 -0
  86. package/dist/modules/src/modules/linear-algebra.d.ts +2 -0
  87. package/dist/modules/src/modules/math.d.ts +2 -0
  88. package/dist/modules/src/modules/number-theory.d.ts +2 -0
  89. package/dist/modules/src/modules/sequence.d.ts +2 -0
  90. package/dist/modules/src/modules/string.d.ts +2 -0
  91. package/dist/modules/src/parser/Parser.d.ts +1 -1
  92. package/dist/modules/src/parser/types.d.ts +1 -1
  93. package/dist/modules/src/tokenizer/token.d.ts +2 -2
  94. package/dist/modules/string.esm.js +2 -0
  95. package/dist/modules/string.esm.js.map +1 -0
  96. package/dist/modules/string.js +2 -0
  97. package/dist/modules/string.js.map +1 -0
  98. package/dist/modules/vector.esm.js +1 -1
  99. package/dist/modules/vector.esm.js.map +1 -1
  100. package/dist/modules/vector.js +1 -1
  101. package/dist/modules/vector.js.map +1 -1
  102. package/dist/reference/api.d.ts +32 -18
  103. package/dist/reference/index.d.ts +129 -209
  104. package/dist/src/builtin/bindingNode.d.ts +1 -1
  105. package/dist/src/builtin/core/vector.d.ts +2 -0
  106. package/dist/src/builtin/interface.d.ts +23 -23
  107. package/dist/src/builtin/modules/bitwise/index.d.ts +2 -0
  108. package/dist/src/builtin/modules/collection/index.d.ts +2 -0
  109. package/dist/src/builtin/modules/functional/index.d.ts +2 -0
  110. package/dist/src/builtin/modules/math/index.d.ts +2 -0
  111. package/dist/src/builtin/modules/sequence/index.d.ts +2 -0
  112. package/dist/src/builtin/modules/string/index.d.ts +2 -0
  113. package/dist/src/full.d.ts +6 -16
  114. package/dist/src/modules/bitwise.d.ts +2 -0
  115. package/dist/src/modules/collection.d.ts +2 -0
  116. package/dist/src/modules/functional.d.ts +2 -0
  117. package/dist/src/modules/linear-algebra.d.ts +2 -0
  118. package/dist/src/modules/math.d.ts +2 -0
  119. package/dist/src/modules/number-theory.d.ts +2 -0
  120. package/dist/src/modules/sequence.d.ts +2 -0
  121. package/dist/src/modules/string.d.ts +2 -0
  122. package/dist/src/parser/Parser.d.ts +1 -1
  123. package/dist/src/parser/types.d.ts +1 -1
  124. package/dist/src/tokenizer/token.d.ts +2 -2
  125. package/dist/testFramework.esm.js +1 -1
  126. package/dist/testFramework.esm.js.map +1 -1
  127. package/dist/testFramework.js +1 -1
  128. package/dist/testFramework.js.map +1 -1
  129. package/package.json +39 -9
  130. package/dist/cli/src/builtin/modules/vector/reductionFunctions/max.d.ts +0 -2
  131. package/dist/cli/src/builtin/modules/vector/reductionFunctions/min.d.ts +0 -2
  132. package/dist/modules/linearAlgebra.esm.js +0 -2
  133. package/dist/modules/linearAlgebra.esm.js.map +0 -1
  134. package/dist/modules/linearAlgebra.js +0 -2
  135. package/dist/modules/linearAlgebra.js.map +0 -1
  136. package/dist/modules/numberTheory.esm.js +0 -2
  137. package/dist/modules/numberTheory.esm.js.map +0 -1
  138. package/dist/modules/numberTheory.js +0 -2
  139. package/dist/modules/numberTheory.js.map +0 -1
  140. package/dist/modules/src/builtin/modules/vector/reductionFunctions/max.d.ts +0 -2
  141. package/dist/modules/src/builtin/modules/vector/reductionFunctions/min.d.ts +0 -2
  142. package/dist/modules/src/modules/linearAlgebra.d.ts +0 -2
  143. package/dist/modules/src/modules/numberTheory.d.ts +0 -2
  144. package/dist/src/builtin/modules/vector/reductionFunctions/max.d.ts +0 -2
  145. package/dist/src/builtin/modules/vector/reductionFunctions/min.d.ts +0 -2
  146. package/dist/src/modules/linearAlgebra.d.ts +0 -2
  147. package/dist/src/modules/numberTheory.d.ts +0 -2
  148. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/docs.d.ts +0 -0
  149. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/calcFractionalRanks.d.ts +0 -0
  150. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/collinear.d.ts +0 -0
  151. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/corrleation.d.ts +0 -0
  152. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/covariance.d.ts +0 -0
  153. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/dot.d.ts +0 -0
  154. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/gaussJordanElimination.d.ts +0 -0
  155. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/getUnit.d.ts +0 -0
  156. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/isZeroVector.d.ts +0 -0
  157. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/kendallTau.d.ts +0 -0
  158. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/length.d.ts +0 -0
  159. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/pearsonCorr.d.ts +0 -0
  160. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/scale.d.ts +0 -0
  161. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/solve.d.ts +0 -0
  162. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/subtract.d.ts +0 -0
  163. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/index.d.ts +0 -0
  164. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/binomialCefficient.d.ts +0 -0
  165. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/combinations.d.ts +0 -0
  166. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/derangements.d.ts +0 -0
  167. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/divisors.d.ts +0 -0
  168. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/docs.d.ts +0 -0
  169. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/factorial.d.ts +0 -0
  170. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/index.d.ts +0 -0
  171. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/partitions.d.ts +0 -0
  172. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/permutations.d.ts +0 -0
  173. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/powerSet.d.ts +0 -0
  174. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/primeFactors.d.ts +0 -0
  175. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/abundant.d.ts +0 -0
  176. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/arithmetic.d.ts +0 -0
  177. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/bell.d.ts +0 -0
  178. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/bernoulli.d.ts +0 -0
  179. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/catalan.d.ts +0 -0
  180. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/collatz.d.ts +0 -0
  181. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/composite.d.ts +0 -0
  182. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/deficient.d.ts +0 -0
  183. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/factorial.d.ts +0 -0
  184. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/fibonacci.d.ts +0 -0
  185. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/geometric.d.ts +0 -0
  186. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/golomb.d.ts +0 -0
  187. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/happy.d.ts +0 -0
  188. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/index.d.ts +0 -0
  189. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/juggler.d.ts +0 -0
  190. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/lookAndSay.d.ts +0 -0
  191. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/lucas.d.ts +0 -0
  192. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/lucky.d.ts +0 -0
  193. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/mersenne.d.ts +0 -0
  194. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/padovan.d.ts +0 -0
  195. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/partition.d.ts +0 -0
  196. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/pell.d.ts +0 -0
  197. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/perfect.d.ts +0 -0
  198. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/perfectCube.d.ts +0 -0
  199. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/perfectPower.d.ts +0 -0
  200. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/perfectSquare.d.ts +0 -0
  201. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/poligonal.d.ts +0 -0
  202. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/prime.d.ts +0 -0
  203. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/recaman.d.ts +0 -0
  204. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/sylvester.d.ts +0 -0
  205. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/thueMorse.d.ts +0 -0
  206. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/tribonacci.d.ts +0 -0
  207. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/docs.d.ts +0 -0
  208. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/calcFractionalRanks.d.ts +0 -0
  209. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/collinear.d.ts +0 -0
  210. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/corrleation.d.ts +0 -0
  211. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/covariance.d.ts +0 -0
  212. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/dot.d.ts +0 -0
  213. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/gaussJordanElimination.d.ts +0 -0
  214. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/getUnit.d.ts +0 -0
  215. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/isZeroVector.d.ts +0 -0
  216. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/kendallTau.d.ts +0 -0
  217. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/length.d.ts +0 -0
  218. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/pearsonCorr.d.ts +0 -0
  219. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/scale.d.ts +0 -0
  220. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/solve.d.ts +0 -0
  221. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/subtract.d.ts +0 -0
  222. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/index.d.ts +0 -0
  223. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/binomialCefficient.d.ts +0 -0
  224. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/combinations.d.ts +0 -0
  225. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/derangements.d.ts +0 -0
  226. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/divisors.d.ts +0 -0
  227. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/docs.d.ts +0 -0
  228. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/factorial.d.ts +0 -0
  229. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/index.d.ts +0 -0
  230. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/partitions.d.ts +0 -0
  231. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/permutations.d.ts +0 -0
  232. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/powerSet.d.ts +0 -0
  233. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/primeFactors.d.ts +0 -0
  234. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/abundant.d.ts +0 -0
  235. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/arithmetic.d.ts +0 -0
  236. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/bell.d.ts +0 -0
  237. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/bernoulli.d.ts +0 -0
  238. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/catalan.d.ts +0 -0
  239. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/collatz.d.ts +0 -0
  240. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/composite.d.ts +0 -0
  241. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/deficient.d.ts +0 -0
  242. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/factorial.d.ts +0 -0
  243. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/fibonacci.d.ts +0 -0
  244. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/geometric.d.ts +0 -0
  245. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/golomb.d.ts +0 -0
  246. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/happy.d.ts +0 -0
  247. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/index.d.ts +0 -0
  248. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/juggler.d.ts +0 -0
  249. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/lookAndSay.d.ts +0 -0
  250. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/lucas.d.ts +0 -0
  251. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/lucky.d.ts +0 -0
  252. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/mersenne.d.ts +0 -0
  253. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/padovan.d.ts +0 -0
  254. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/partition.d.ts +0 -0
  255. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/pell.d.ts +0 -0
  256. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/perfect.d.ts +0 -0
  257. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/perfectCube.d.ts +0 -0
  258. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/perfectPower.d.ts +0 -0
  259. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/perfectSquare.d.ts +0 -0
  260. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/poligonal.d.ts +0 -0
  261. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/prime.d.ts +0 -0
  262. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/recaman.d.ts +0 -0
  263. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/sylvester.d.ts +0 -0
  264. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/thueMorse.d.ts +0 -0
  265. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/tribonacci.d.ts +0 -0
  266. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/docs.d.ts +0 -0
  267. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/calcFractionalRanks.d.ts +0 -0
  268. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/collinear.d.ts +0 -0
  269. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/corrleation.d.ts +0 -0
  270. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/covariance.d.ts +0 -0
  271. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/dot.d.ts +0 -0
  272. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/gaussJordanElimination.d.ts +0 -0
  273. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/getUnit.d.ts +0 -0
  274. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/isZeroVector.d.ts +0 -0
  275. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/kendallTau.d.ts +0 -0
  276. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/length.d.ts +0 -0
  277. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/pearsonCorr.d.ts +0 -0
  278. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/scale.d.ts +0 -0
  279. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/solve.d.ts +0 -0
  280. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/subtract.d.ts +0 -0
  281. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/index.d.ts +0 -0
  282. /package/dist/src/builtin/modules/{numberTheory → number-theory}/binomialCefficient.d.ts +0 -0
  283. /package/dist/src/builtin/modules/{numberTheory → number-theory}/combinations.d.ts +0 -0
  284. /package/dist/src/builtin/modules/{numberTheory → number-theory}/derangements.d.ts +0 -0
  285. /package/dist/src/builtin/modules/{numberTheory → number-theory}/divisors.d.ts +0 -0
  286. /package/dist/src/builtin/modules/{numberTheory → number-theory}/docs.d.ts +0 -0
  287. /package/dist/src/builtin/modules/{numberTheory → number-theory}/factorial.d.ts +0 -0
  288. /package/dist/src/builtin/modules/{numberTheory → number-theory}/index.d.ts +0 -0
  289. /package/dist/src/builtin/modules/{numberTheory → number-theory}/partitions.d.ts +0 -0
  290. /package/dist/src/builtin/modules/{numberTheory → number-theory}/permutations.d.ts +0 -0
  291. /package/dist/src/builtin/modules/{numberTheory → number-theory}/powerSet.d.ts +0 -0
  292. /package/dist/src/builtin/modules/{numberTheory → number-theory}/primeFactors.d.ts +0 -0
  293. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/abundant.d.ts +0 -0
  294. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/arithmetic.d.ts +0 -0
  295. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/bell.d.ts +0 -0
  296. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/bernoulli.d.ts +0 -0
  297. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/catalan.d.ts +0 -0
  298. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/collatz.d.ts +0 -0
  299. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/composite.d.ts +0 -0
  300. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/deficient.d.ts +0 -0
  301. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/factorial.d.ts +0 -0
  302. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/fibonacci.d.ts +0 -0
  303. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/geometric.d.ts +0 -0
  304. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/golomb.d.ts +0 -0
  305. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/happy.d.ts +0 -0
  306. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/index.d.ts +0 -0
  307. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/juggler.d.ts +0 -0
  308. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/lookAndSay.d.ts +0 -0
  309. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/lucas.d.ts +0 -0
  310. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/lucky.d.ts +0 -0
  311. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/mersenne.d.ts +0 -0
  312. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/padovan.d.ts +0 -0
  313. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/partition.d.ts +0 -0
  314. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/pell.d.ts +0 -0
  315. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/perfect.d.ts +0 -0
  316. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/perfectCube.d.ts +0 -0
  317. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/perfectPower.d.ts +0 -0
  318. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/perfectSquare.d.ts +0 -0
  319. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/poligonal.d.ts +0 -0
  320. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/prime.d.ts +0 -0
  321. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/recaman.d.ts +0 -0
  322. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/sylvester.d.ts +0 -0
  323. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/thueMorse.d.ts +0 -0
  324. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/tribonacci.d.ts +0 -0
package/dist/lits.iife.js CHANGED
@@ -1,2 +1,2 @@
1
- var Lits=function(e){"use strict";function t(e){if(!e.position||!e.code)return"";const t=e.position.column-1,n=e.code.length-t-1;return`${" ".repeat(Math.max(t,0))}^${" ".repeat(Math.max(n,0))}`}class n extends Error{params;constructor(e){super(`recur, params: ${e}`),Object.setPrototypeOf(this,n.prototype),this.name="RecurSignal",this.params=e}}class r extends Error{sourceCodeInfo;shortMessage;constructor(e,n){const i=e instanceof Error?e.message:`${e}`;super(function(e,n){if(!n)return e;const r=`${n.position.line}:${n.position.column}`;return`${e}${n.filePath?`\n${n.filePath}:${r}`:`\nLocation ${r}`}\n${n.code}\n${t(n)}`}(i,n)),this.shortMessage=i,this.sourceCodeInfo=n,Object.setPrototypeOf(this,r.prototype),this.name="LitsError"}getCodeMarker(){return this.sourceCodeInfo&&t(this.sourceCodeInfo)}}class i extends r{userMessage;constructor(e,t){super(e,t),this.userMessage=e,Object.setPrototypeOf(this,i.prototype),this.name="UserDefinedError"}}class s extends r{symbol;constructor(e,t){super(`Undefined symbol '${e}'.`,t),this.symbol=e,Object.setPrototypeOf(this,s.prototype),this.name="UndefinedSymbolError"}}const o={Number:1,String:2,NormalExpression:3,SpecialExpression:4,UserDefinedSymbol:5,NormalBuiltinSymbol:6,SpecialBuiltinSymbol:7,ReservedSymbol:8,Binding:9,Spread:10},a=new Set(Object.values(o));function u(e){return Object.keys(o).find(t=>o[t]===e)}const c=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);const l="^^fn^^",f="^^re^^";function h(e){return null!==e&&"object"==typeof e&&(l in e&&"functionType"in e&&function(e){return"string"==typeof e&&c.has(e)}(e.functionType))}function p(e){return!(!Array.isArray(e)||e.length<2)&&function(e){return"number"==typeof e&&a.has(e)}(e[0])}function d(e){return h(e)?`<function ${e.name||"λ"}>`:p(e)?`${u(e[0])}-node`:null===e?"null":"object"==typeof e&&e instanceof RegExp?`${e}`:"object"==typeof e&&e instanceof Error?e.toString():JSON.stringify(e)}function y(e,t){return e?.sourceCodeInfo??t}function g(e,t,n){return new r(`Expected ${e}, got ${d(t)}.`,y(t,n))}function m(e,t){return v(e,t),e}function v(e,t){if(!function(e){return void 0!==e}(e))throw new r("Unexpected undefined",y(e,t))}function b(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function w(e){return null!==e&&"object"==typeof e&&!!e[l]}function x(e,t){if(!w(e))throw g("LitsFunction",e,t)}function S(e){return w(e)&&"UserDefined"===e.functionType}function k(e,t){if(!S(e))throw g("NativeJsFunction",e,t)}function E(e){return w(e)&&"NativeJsFunction"===e.functionType}function N(e,t){if(!E(e))throw g("NativeJsFunction",e,t)}function A(e,t={}){return"number"==typeof e&&(!Number.isNaN(e)&&(!(t.integer&&!Number.isInteger(e))&&(!(t.finite&&!Number.isFinite(e))&&((!t.zero||0===e)&&((!t.nonZero||0!==e)&&(!(t.positive&&e<=0)&&(!(t.negative&&e>=0)&&(!(t.nonPositive&&e>0)&&(!(t.nonNegative&&e<0)&&(!("number"==typeof t.gt&&e<=t.gt)&&(!("number"==typeof t.gte&&e<t.gte)&&(!("number"==typeof t.lt&&e>=t.lt)&&!("number"==typeof t.lte&&e>t.lte)))))))))))))}function $(e,t,n={}){if(!A(e,n))throw new r(`Expected ${function(e){if(e.zero)return"zero";const t=function(e){return e.positive?"positive":e.negative?"negative":e.nonNegative?"non negative":e.nonPositive?"non positive":e.nonZero?"non zero":""}(e),n=e.integer?"integer":"number",r=e.finite?"finite":"",i=function(e){return"number"!=typeof e.gt&&"number"!=typeof e.gte||"number"!=typeof e.lt&&"number"!=typeof e.lte?"number"==typeof e.gt||"number"==typeof e.gte?"number"==typeof e.gt?`n > ${e.gt}`:`n >= ${e.gte}`:"number"==typeof e.lt||"number"==typeof e.lte?"number"==typeof e.lt?`n < ${e.lt}`:`n <= ${e.lte}`:"":`${"number"==typeof e.gt?`${e.gt} < n `:`${e.gte} <= n `}${"number"==typeof e.lt?`< ${e.lt}`:`<= ${e.lte}`}`}(e);return[t,r,n,i].filter(e=>!!e).join(" ")}(n)}, got ${d(e)}.`,y(e,t))}function I(e,t,n={}){return $(e,t,n),e}function j(e){return void 0!==e}function C(e,t){return O(e,t),e}function O(e,t){if(!j(e))throw g("not undefined",e,t)}function F(e){return Array.isArray(e)||"string"==typeof e}function M(e,t){return U(e,t),e}function U(e,t){if(!F(e))throw g("string or array",e,t)}function T(e){return!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof RegExp||w(e)||L(e))}function B(e,t){if(!T(e))throw g("object",e,t)}function P(e){return F(e)||T(e)}function R(e,t){return D(e,t),e}function D(e,t){if(!P(e))throw g("string, array or object",e,t)}function L(e){return null!==e&&"object"==typeof e&&!!e[f]}function _(e,t){if(!function(e){return L(e)||"string"==typeof e}(e))throw g("string or RegularExpression",e,t)}function V(e,t){return z(e,t),e}function z(e,t){if(!function(e){return"number"==typeof e||!!P(e)||!!w(e)}(e))throw g("FunctionLike",e,t)}function J(e,t){const{min:n}=e;return!("number"==typeof n&&t<n)}function W(e){return"number"==typeof e||P(e)?Y(1):e.arity}function q(e,t,n){const{min:i,max:s}=e;if("number"==typeof i&&t<i)throw new r(`Wrong number of arguments, expected at least ${i}, got ${d(t)}.`,n);if("number"==typeof s&&t>s)throw new r(`Wrong number of arguments, expected at most ${s}, got ${d(t)}.`,n)}function Y(e){return{min:e,max:e}}const G={"<<":{evaluate:([e,t],n)=>($(e,n,{integer:!0}),$(t,n,{integer:!0,nonNegative:!0}),e<<t),arity:Y(2)},">>":{evaluate:([e,t],n)=>($(e,n,{integer:!0}),$(t,n,{integer:!0,nonNegative:!0}),e>>t),arity:Y(2)},">>>":{evaluate:([e,t],n)=>($(e,n,{integer:!0}),$(t,n,{integer:!0,nonNegative:!0}),e>>>t),arity:Y(2)},"bit-not":{evaluate:([e],t)=>($(e,t,{integer:!0}),~e),arity:Y(1)},"&":{evaluate:([e,...t],n)=>($(e,n,{integer:!0}),t.reduce((e,t)=>($(t,n,{integer:!0}),e&t),e)),arity:{min:2}},"bit-and-not":{evaluate:([e,...t],n)=>($(e,n,{integer:!0}),t.reduce((e,t)=>($(t,n,{integer:!0}),e&~t),e)),arity:{min:2}},"|":{evaluate:([e,...t],n)=>($(e,n,{integer:!0}),t.reduce((e,t)=>($(t,n,{integer:!0}),e|t),e)),arity:{min:2}},xor:{evaluate:([e,...t],n)=>($(e,n,{integer:!0}),t.reduce((e,t)=>($(t,n,{integer:!0}),e^t),e)),arity:{min:2}},"bit-flip":{evaluate:([e,t],n)=>{$(e,n,{integer:!0}),$(t,n,{integer:!0,nonNegative:!0});return e^1<<t},arity:Y(2)},"bit-set":{evaluate:([e,t],n)=>{$(e,n,{integer:!0}),$(t,n,{integer:!0,nonNegative:!0});return e|1<<t},arity:Y(2)},"bit-clear":{evaluate:([e,t],n)=>{$(e,n,{integer:!0}),$(t,n,{integer:!0,nonNegative:!0});return e&~(1<<t)},arity:Y(2)},"bit-test":{evaluate:([e,t],n)=>{$(e,n,{integer:!0}),$(t,n,{integer:!0,nonNegative:!0});return!!(e&1<<t)},arity:Y(2)}};function K(e,t={}){return"string"==typeof e&&((!t.nonEmpty||0!==e.length)&&(!t.char||1===e.length))}function X(e,t,n={}){if(!K(e,n))throw g(""+(n.nonEmpty?"non empty string":n.char?"character":"string"),e,t)}function Z(e,t,n={}){return X(e,t,n),e}function H(e){return"string"==typeof e||"number"==typeof e}function Q(e,t){return ee(e,t),e}function ee(e,t){if(!H(e))throw g("string or number",e,t)}function te(e,t){return!!P(e)&&("string"==typeof e||Array.isArray(e)?!!A(t,{integer:!0})&&(t>=0&&t<e.length):!!Object.getOwnPropertyDescriptor(e,t))}function ne(e,t,n){if(ee(e,n),ee(t,n),"string"==typeof e&&"string"==typeof t)return e<t?-1:e>t?1:0;if("number"==typeof e&&"number"==typeof t)return Math.sign(e-t);throw new r(`Cannot compare values of different types: ${typeof e} and ${typeof t}`,n)}function re(e,t,n){if(e===t)return!0;if("number"==typeof e&&"number"==typeof t)return function(e,t,n=le){if(e===t)return!0;const r=Math.abs(e-t);if(0===e||0===t||r<n)return r<n;const i=Math.abs(e),s=Math.abs(t);return r/(i+s)<n}(e,t);if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r+=1)if(!re(C(e[r],n),C(t[r],n),n))return!1;return!0}if(L(e)&&L(t))return e.s===t.s&&e.f===t.f;if(b(e)&&b(t)){const r=Object.keys(e),i=Object.keys(t);if(r.length!==i.length)return!1;for(let i=0;i<r.length;i+=1){const s=Z(r[i],n);if(!re(e[s],t[s],n))return!1}return!0}return!1}function ie(e){return Math.max(0,Math.ceil(e))}function se(e){return e??null}function oe(e){return T(e)?Object.entries(e).reduce((e,t)=>{const[n,r]=t;return e[n]=oe(r),e},{}):Array.isArray(e)?e.map(e=>oe(e)):e}function ae(e){return oe(e)}function ue(...e){const t=new Set;for(const n of e)n.forEach(e=>t.add(e));return t}function ce(e,t){t.forEach(t=>e.add(t))}const le=1e-10;function fe(e,t=0){const n=e.split("\n");for(;n[0]?.match(/^\s*$/);)n.shift();for(;n[n.length-1]?.match(/^\s*$/);)n.pop();const r=n.reduce((e,t)=>{if(t.match(/^\s*$/))return e;const n=t.match(/^\s*/)[0].length;return Math.min(e,n)},1/0);return n.map(e=>" ".repeat(t)+e.slice(r)).join("\n").trimEnd()}function he(e,t){if(!Array.isArray(e))throw g("array",e,t)}function pe(e,t){if(!function(e){return Array.isArray(e)&&e.every(e=>"string"==typeof e)}(e))throw g("array of strings",e,t)}function de(e,t){if(!function(e){return Array.isArray(e)&&e.every(e=>"string"==typeof e&&1===e.length)}(e))throw g("array of strings",e,t)}function ye(e,t,n){const r=ae(e);return{coll:r,innerCollMeta:t.slice(0,t.length-1).reduce((e,t)=>{const r=e.coll;let i;return Array.isArray(r)?($(t,n),i=R(r[t],n)):(B(r,n),X(t,n),te(e.coll,t)||(r[t]={}),i=R(r[t],n)),{coll:i,parent:r}},{coll:r,parent:{}})}}function ge(e,t){if(T(e)){if("string"==typeof t&&te(e,t))return se(e[t])}else if(A(t,{nonNegative:!0,integer:!0})&&t>=0&&t<e.length)return se(e[t])}function me(e,t,n,r,i,s,o){if(T(e)){X(t,o);const a={...e};return a[t]=s(n,[a[t],...r],i,o),a}{$(t,o);const a=ie(t);if($(a,o,{lte:e.length}),Array.isArray(e)){const t=e.map((e,t)=>a===t?s(n,[e,...r],i,o):e);return a===e.length&&(t[a]=s(n,[void 0,...r],i,o)),t}{const t=e.split("").map((e,t)=>a===t?Z(s(n,[e,...r],i,o),o,{char:!0}):e);return a===e.length&&(t[a]=Z(s(n,[void 0,...r],i,o),o,{char:!0})),t.join("")}}}function ve(e,t,n,r){if(D(e,r),ee(t,r),Array.isArray(e)||"string"==typeof e){if($(t,r,{integer:!0}),$(t,r,{gte:0}),$(t,r,{lte:e.length}),"string"==typeof e)return X(n,r,{char:!0}),`${e.slice(0,t)}${n}${e.slice(t+1)}`;const i=[...e];return i[t]=n,i}X(t,r);const i={...e};return i[t]=n,i}const be={filter:{evaluate:([e,t],n,r,{executeFunction:i})=>{if(D(e,n),z(t,n),Array.isArray(e)){return e.filter(e=>i(t,[e],r,n))}return K(e)?e.split("").filter(e=>i(t,[e],r,n)).join(""):Object.entries(e).filter(([,e])=>i(t,[e],r,n)).reduce((e,[t,n])=>(e[t]=n,e),{})},arity:Y(2)},filteri:{evaluate:([e,t],n,r,{executeFunction:i})=>{if(D(e,n),z(t,n),Array.isArray(e)){return e.filter((e,s)=>i(t,[e,s],r,n))}return K(e)?e.split("").filter((e,s)=>i(t,[e,s],r,n)).join(""):Object.entries(e).filter(([e,s])=>i(t,[s,e],r,n)).reduce((e,[t,n])=>(e[t]=n,e),{})},arity:Y(2)},map:{evaluate:(e,t,n,{executeFunction:i})=>{const s=V(e.at(-1),t);if(T(e[0]))return function({colls:e,contextStack:t,executeFunction:n,fn:i,sourceCodeInfo:s}){B(e[0],s);const o=Object.keys(e[0]),a={};return e.forEach(e=>{B(e,s);const t=Object.keys(e);if(t.length!==o.length)throw new r(`All objects must have the same keys. Expected: ${o.join(", ")}. Found: ${t.join(", ")}`,s);if(!t.every(e=>o.includes(e)))throw new r(`All objects must have the same keys. Expected: ${o.join(", ")}. Found: ${t.join(", ")}`,s);Object.entries(e).forEach(([e,t])=>{a[e]||(a[e]=[]),a[e].push(t)})}),o.reduce((e,r)=>(e[r]=n(i,a[r],t,s),e),{})}({colls:e.slice(0,-1),fn:s,sourceCodeInfo:t,contextStack:n,executeFunction:i});const o=e.slice(0,-1);U(o[0],t);const a="string"==typeof o[0];let u=o[0].length;o.slice(1).forEach(e=>{a?X(e,t):he(e,t),u=Math.min(u,e.length)});const c=[];for(let e=0;e<u;e++)c.push(o.map(t=>t[e]));const l=c.map(e=>i(s,e,n,t));return a?(l.forEach(e=>X(e,t)),l.join("")):l},arity:{min:2}},mapi:{evaluate:([e,t],n,r,{executeFunction:i})=>(D(e,n),z(t,n),Array.isArray(e)?e.map((e,s)=>i(t,[e,s],r,n)):K(e)?e.split("").map((e,s)=>i(t,[e,s],r,n)).join(""):Object.entries(e).reduce((e,[s,o])=>(e[s]=i(t,[o,s],r,n),e),{})),arity:Y(2)},reduce:{evaluate:([e,t,n],r,i,{executeFunction:s})=>(D(e,r),z(t,r),O(n,r),"string"==typeof e?(X(n,r),0===e.length?n:e.split("").reduce((e,n)=>s(t,[e,n],i,r),n)):Array.isArray(e)?0===e.length?n:e.reduce((e,n)=>s(t,[e,n],i,r),n):0===Object.keys(e).length?n:Object.entries(e).reduce((e,[,n])=>s(t,[e,n],i,r),n)),arity:Y(3)},reducei:{evaluate:([e,t,n],r,i,{executeFunction:s})=>(D(e,r),z(t,r),O(n,r),"string"==typeof e?(X(n,r),0===e.length?n:e.split("").reduce((e,n,o)=>s(t,[e,n,o],i,r),n)):Array.isArray(e)?0===e.length?n:e.reduce((e,n,o)=>s(t,[e,n,o],i,r),n):0===Object.keys(e).length?n:Object.entries(e).reduce((e,[n,o])=>s(t,[e,o,n],i,r),n)),arity:Y(3)},"reduce-right":{evaluate:([e,t,n],r,i,{executeFunction:s})=>(D(e,r),z(t,r),O(n,r),"string"==typeof e?0===e.length?n:e.split("").reduceRight((e,n)=>s(t,[e,n],i,r),n):Array.isArray(e)?0===e.length?n:e.reduceRight((e,n)=>s(t,[e,n],i,r),n):0===Object.keys(e).length?n:Object.entries(e).reduceRight((e,[,n])=>s(t,[e,n],i,r),n)),arity:Y(3)},"reducei-right":{evaluate:([e,t,n],r,i,{executeFunction:s})=>(D(e,r),z(t,r),O(n,r),"string"==typeof e?0===e.length?n:e.split("").reduceRight((e,n,o)=>s(t,[e,n,o],i,r),n):Array.isArray(e)?0===e.length?n:e.reduceRight((e,n,o)=>s(t,[e,n,o],i,r),n):0===Object.keys(e).length?n:Object.entries(e).reduceRight((e,[n,o])=>s(t,[e,o,n],i,r),n)),arity:Y(3)},reductions:{evaluate:([e,t,n],r,i,{executeFunction:s})=>{if(D(e,r),z(t,r),O(n,r),O(n,r),"string"==typeof e){if(X(n,r),0===e.length)return[n];const o=[n];return e.split("").reduce((e,n)=>{const a=s(t,[e,n],i,r);return o.push(a),a},n),o}if(Array.isArray(e)){if(0===e.length)return[n];const o=[n];return e.reduce((e,n)=>{const a=s(t,[e,n],i,r);return o.push(a),a},n),o}{if(0===Object.keys(e).length)return[n];const o=[n];return Object.entries(e).reduce((e,[,n])=>{const a=s(t,[e,n],i,r);return o.push(a),a},n),o}},arity:Y(3)},reductionsi:{evaluate:([e,t,n],r,i,{executeFunction:s})=>{if(D(e,r),z(t,r),O(n,r),O(n,r),"string"==typeof e){if(X(n,r),0===e.length)return[n];const o=[n];return e.split("").reduce((e,n,a)=>{const u=s(t,[e,n,a],i,r);return o.push(u),u},n),o}if(Array.isArray(e)){if(0===e.length)return[n];const o=[n];return e.reduce((e,n,a)=>{const u=s(t,[e,n,a],i,r);return o.push(u),u},n),o}{if(0===Object.keys(e).length)return[n];const o=[n];return Object.entries(e).reduce((e,[n,a])=>{const u=s(t,[e,a,n],i,r);return o.push(u),u},n),o}},arity:Y(3)},get:{evaluate:(e,t)=>{const[n,r]=e,i=se(e[2]);if(ee(r,t),null===n)return i;D(n,t);const s=ge(n,r);return void 0===s?i:s},arity:{min:2,max:3}},"get-in":{evaluate:(e,t)=>{let n=se(e[0]);const r=e[1]??[],i=se(e[2]);he(r,t);for(const e of r){if(ee(e,t),!P(n))return i;{const t=ge(n,e);if(void 0===t)return i;n=t}}return n},arity:{min:2,max:3}},count:{evaluate:([e],t)=>null===e?0:"string"==typeof e?e.length:(D(e,t),Array.isArray(e)?e.length:Object.keys(e).length),arity:Y(1)},"contains?":{evaluate:([e,t],n)=>null!==e&&(D(e,n),K(e)?(X(t,n),e.includes(t)):F(e)?(O(t,n),!!e.find(e=>re(C(e),t,n))):(X(t,n),t in e)),arity:Y(2)},assoc:{evaluate:([e,t,n],r)=>(D(e,r),ee(t,r),O(n,r),ve(e,t,n,r)),arity:Y(3)},"assoc-in":{evaluate:([e,t,n],r)=>{if(D(e,r),he(t,r),O(n,r),1===t.length)return ee(t[0],r),ve(e,t[0],n,r);const{coll:i,innerCollMeta:s}=ye(e,t,r),o=Q(t[t.length-1],r),a=Q(t[t.length-2],r);return Array.isArray(s.parent)?($(a,r),s.parent[a]=ve(s.coll,o,n,r)):(X(a,r),s.parent[a]=ve(s.coll,o,n,r)),i},arity:Y(3)},update:{evaluate:([e,t,n,...r],i,s,{executeFunction:o})=>(D(e,i),ee(t,i),z(n,i),me(e,t,n,r,s,o,i)),arity:{min:3}},"update-in":{evaluate:([e,t,n,...r],i,s,{executeFunction:o})=>{if(D(e,i),he(t,i),z(n,i),1===t.length)return ee(t[0],i),me(e,t[0],n,r,s,o,i);const{coll:a,innerCollMeta:u}=ye(e,t,i),c=Q(t[t.length-1],i),l=Q(t[t.length-2],i);return Array.isArray(u.parent)?($(l,i),u.parent[l]=me(u.coll,c,n,r,s,o,i)):(X(l,i),u.parent[l]=me(u.coll,c,n,r,s,o,i)),a},arity:{min:3}},"++":{evaluate:(e,t)=>(A(e[0])||D(e[0],t),Array.isArray(e[0])?e.reduce((e,n)=>(he(n,t),e.concat(n)),[]):H(e[0])?e.reduce((e,n)=>(ee(n,t),`${e}${n}`),""):e.reduce((e,n)=>(B(n,t),Object.assign(e,n)),{})),arity:{min:1}},"not-empty":{evaluate:([e],t)=>null===e?null:(D(e,t),"string"==typeof e||Array.isArray(e)?e.length>0?e:null:Object.keys(e).length>0?e:null),arity:Y(1)},"every?":{evaluate:([e,t],n,r,{executeFunction:i})=>(D(e,n),z(t,n),Array.isArray(e)?e.every(e=>i(t,[e],r,n)):"string"==typeof e?e.split("").every(e=>i(t,[e],r,n)):Object.entries(e).every(e=>i(t,[e],r,n))),arity:Y(2)},"any?":{evaluate:([e,t],n,r,{executeFunction:i})=>(z(t,n),D(e,n),Array.isArray(e)?e.some(e=>i(t,[e],r,n)):"string"==typeof e?e.split("").some(e=>i(t,[e],r,n)):Object.entries(e).some(e=>i(t,[e],r,n))),arity:Y(2)},"not-any?":{evaluate:([e,t],n,r,{executeFunction:i})=>(z(t,n),D(e,n),Array.isArray(e)?!e.some(e=>i(t,[e],r,n)):"string"==typeof e?!e.split("").some(e=>i(t,[e],r,n)):!Object.entries(e).some(e=>i(t,[e],r,n))),arity:Y(2)},"not-every?":{evaluate:([e,t],n,r,{executeFunction:i})=>(z(t,n),D(e,n),Array.isArray(e)?!e.every(e=>i(t,[e],r,n)):"string"==typeof e?!e.split("").every(e=>i(t,[e],r,n)):!Object.entries(e).every(e=>i(t,[e],r,n))),arity:Y(2)}},we={range:{evaluate:(e,t)=>{const[n,r,i]=e;let s,o,a;$(n,t,{finite:!0}),1===e.length?(s=0,o=n,a=o>=0?1:-1):2===e.length?($(r,t,{finite:!0}),s=n,o=r,a=o>=s?1:-1):($(r,t,{finite:!0}),$(i,t,{finite:!0}),s=n,o=r,a=i,$(a,t,o>s?{positive:!0}:o<s?{negative:!0}:{nonZero:!0}));const u=[];for(let e=s;a<0?e>o:e<o;e+=a)u.push(e);return u},arity:{min:1,max:3}},repeat:{evaluate:([e,t],n)=>{$(t,n,{integer:!0,nonNegative:!0});const r=[];for(let n=0;n<t;n+=1)r.push(e);return r},arity:Y(2)},flatten:{evaluate:([e,t],n)=>{he(e,n);const r=void 0===t||t===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:I(t,n,{integer:!0,nonNegative:!0});return e.flat(r)},arity:{min:1,max:2}},mapcat:{evaluate:([e,t],n,r,{executeFunction:i})=>(he(e,n),z(t,n),e.map(e=>i(t,[e],r,n)).flat(1)),arity:Y(2)},"moving-fn":{evaluate:([e,t,n],r,i,{executeFunction:s})=>{he(e,r),$(t,r,{integer:!0,lte:e.length}),z(n,r);const o=[];for(let a=0;a<=e.length-t;a++){const u=s(n,[e.slice(a,a+t)],i,r);o.push(u)}return o},arity:Y(3)},"running-fn":{evaluate:([e,t],n,r,{executeFunction:i})=>{he(e,n),z(t,n);const s=[];for(let o=0;o<e.length;o+=1){const a=e.slice(0,o+1);s.push(i(t,[a],r,n))}return s},arity:Y(2)}},xe={nth:{evaluate:(e,t)=>{const[n,r]=e,i=se(e[2]);if($(r,t,{integer:!0}),null===n)return i;if(U(n,t),r>=0&&r<n.length){return se(n[r])}return i},arity:{min:2,max:3}},first:{evaluate:([e],t)=>{if(null===e)return null;U(e,t);return se(e[0])},arity:Y(1)},last:{evaluate:([e],t)=>{if(null===e)return null;U(e,t);return se(e.at(-1))},arity:Y(1)},pop:{evaluate:([e],t)=>(U(e,t),"string"==typeof e?e.substring(0,e.length-1):e.slice(0,e.length-1)),arity:Y(1)},position:{evaluate:([e,t],n,r,{executeFunction:i})=>{if(z(t,n),null===e)return null;if(U(e,n),"string"==typeof e){const s=e.split("").findIndex(e=>i(t,[e],r,n));return-1!==s?s:null}{const s=e.findIndex(e=>i(t,[e],r,n));return-1!==s?s:null}},arity:Y(2)},"index-of":{evaluate:([e,t],n)=>{if(O(t,n),null===e)return null;if(U(e,n),"string"==typeof e){X(t,n);const r=e.indexOf(t);return-1!==r?r:null}{const r=e.findIndex(e=>re(C(e,n),t),n);return-1!==r?r:null}},arity:Y(2)},"last-index-of":{evaluate:([e,t],n)=>{if(O(t,n),null===e)return null;if(U(e,n),"string"==typeof e){X(t,n);const r=e.lastIndexOf(t);return-1!==r?r:null}{const r=e.findLastIndex(e=>re(C(e,n),t),n);return-1!==r?r:null}},arity:Y(2)},push:{evaluate:([e,...t],n)=>(U(e,n),"string"==typeof e?(de(t,n),[e,...t].join("")):[...e,...t]),arity:{min:2}},rest:{evaluate:([e],t)=>(U(e,t),Array.isArray(e)?e.length<=1?[]:e.slice(1):e.substring(1)),arity:Y(1)},next:{evaluate:([e],t)=>(U(e,t),Array.isArray(e)?e.length<=1?null:e.slice(1):e.length<=1?null:e.substring(1)),arity:Y(1)},reverse:{evaluate:([e],t)=>null===e?null:(U(e,t),Array.isArray(e)?[...e].reverse():e.split("").reverse().join("")),arity:Y(1)},second:{evaluate:([e],t)=>null===e?null:(U(e,t),se(e[1])),arity:Y(1)},shift:{evaluate:([e],t)=>{if(U(e,t),"string"==typeof e)return e.substring(1);const n=[...e];return n.shift(),n},arity:Y(1)},slice:{evaluate:(e,t)=>{const[n,r,i]=e;return U(n,t),$(r,t,{integer:!0}),2===e.length?(Array.isArray(n),n.slice(r)):($(i,t,{integer:!0}),Array.isArray(n),n.slice(r,i))},arity:{min:2,max:3}},splice:{evaluate:(e,t)=>{const[n,r,i,...s]=e;U(n,t),$(r,t,{integer:!0}),$(i,t,{integer:!0,nonNegative:!0});const o=r<0?n.length+r:r;return Array.isArray(n)?[...n.slice(0,o),...s,...n.slice(o+i)]:(s.forEach(e=>X(e,t)),`${n.substring(0,o)}${s.join("")}${n.substring(o+i)}`)},arity:{min:3}},some:{evaluate:([e,t],n,r,{executeFunction:i})=>(z(t,n),null===e?null:(U(e,n),0===e.length?null:"string"==typeof e?e.split("").find(e=>i(t,[e],r,n))??null:se(e.find(e=>i(t,[e],r,n))))),arity:Y(2)},sort:{evaluate:(e,t,n,{executeFunction:r})=>{const[i]=e,s=1===e.length,o=s?null:e[1];if(U(i,t),"string"==typeof i){const e=i.split("");return s?e.sort((e,n)=>ne(e,n,t)):(z(o,t),e.sort((e,i)=>{const s=r(o,[e,i],n,t);return $(s,t,{finite:!0}),s})),e.join("")}const a=[...i];return s?a.sort((e,n)=>(ee(e,t),ee(n,t),ne(e,n,t))):a.sort((e,i)=>{z(o,t);const s=r(o,[e,i],n,t);return $(s,t,{finite:!0}),s}),a},arity:{min:1,max:2}},"sort-by":{evaluate:(e,t,n,{executeFunction:r})=>{const[i,s]=e,o=2===e.length;U(i,t),z(s,t);const a=o?null:e[2];if("string"==typeof i){const e=i.split("");return o?e.sort((e,i)=>{const o=r(s,[e],n,t);ee(o,t);const a=r(s,[i],n,t);return ee(a,t),ne(o,a,t)}):(z(a,t),e.sort((e,i)=>{const o=r(s,[e],n,t),u=r(s,[i],n,t),c=r(a,[o,u],n,t);return $(c,t,{finite:!0}),c})),e.join("")}const u=[...i];return o?u.sort((e,i)=>{const o=r(s,[e],n,t);ee(o,t);const a=r(s,[i],n,t);return ee(a,t),ne(o,a,t)}):(z(a,t),u.sort((e,i)=>{const o=r(s,[e],n,t),u=r(s,[i],n,t),c=r(a,[o,u],n,t);return $(c,t,{finite:!0}),c})),u},arity:{min:2,max:3}},take:{evaluate:([e,t],n)=>{$(t,n),U(e,n);const r=Math.max(Math.ceil(t),0);return e.slice(0,r)},arity:Y(2)},"take-last":{evaluate:([e,t],n)=>{U(e,n),$(t,n);const r=Math.max(Math.ceil(t),0),i=e.length-r;return e.slice(i)},arity:Y(2)},"take-while":{evaluate:([e,t],n,r,{executeFunction:i})=>{U(e,n),z(t,n);const s=[];for(const o of e){if(!i(t,[o],r,n))break;s.push(o)}return"string"==typeof e?s.join(""):s},arity:Y(2)},drop:{evaluate:([e,t],n)=>{$(t,n);const r=Math.max(Math.ceil(t),0);return U(e,n),e.slice(r)},arity:Y(2)},"drop-last":{evaluate:([e,t],n)=>{U(e,n),$(t,n);const r=Math.max(Math.ceil(t),0),i=e.length-r;return e.slice(0,i)},arity:Y(2)},"drop-while":{evaluate:([e,t],n,r,{executeFunction:i})=>{if(U(e,n),z(t,n),Array.isArray(e)){const s=e.findIndex(e=>!i(t,[e],r,n));return e.slice(s)}const s=e.split(""),o=s.findIndex(e=>!i(t,[e],r,n));return s.slice(o).join("")},arity:Y(2)},unshift:{evaluate:([e,...t],n)=>{if(U(e,n),"string"==typeof e)return de(t,n),[...t,e].join("");const r=[...e];return r.unshift(...t),r},arity:{min:2}},distinct:{evaluate:([e],t)=>{if(U(e,t),Array.isArray(e)){const n=[];for(const r of e)O(r,t),n.some(e=>re(e,r,t))||n.push(r);return n}return Array.from(new Set(e.split(""))).join("")},arity:Y(1)},remove:{evaluate:([e,t],n,r,{executeFunction:i})=>(z(t,n),U(e,n),Array.isArray(e)?e.filter(e=>!i(t,[e],r,n)):e.split("").filter(e=>!i(t,[e],r,n)).join("")),arity:Y(2)},"remove-at":{evaluate:([e,t],n)=>{$(t,n,{integer:!0}),U(e,n);const r=t<0?e.length+t:t;return r<0||r>=e.length?e:Array.isArray(e)?e.filter((e,t)=>t!==r):`${e.substring(0,r)}${e.substring(r+1)}`},arity:Y(2)},"split-at":{evaluate:([e,t],n)=>{$(t,n,{integer:!0}),U(e,n);const r=t<0?e.length+t:t;return[e.slice(0,r),e.slice(r)]},arity:Y(2)},"split-with":{evaluate:([e,t],n,r,{executeFunction:i})=>{z(t,n),U(e,n);const s=Array.isArray(e),o=(s?e:e.split("")).findIndex(e=>!i(t,[e],r,n));return-1===o?[e,s?[]:""]:[e.slice(0,o),e.slice(o)]},arity:Y(2)},frequencies:{evaluate:([e],t)=>{U(e,t);return("string"==typeof e?e.split(""):e).reduce((e,n)=>(X(n,t),te(e,n)?e[n]=e[n]+1:e[n]=1,e),{})},arity:Y(1)},"group-by":{evaluate:([e,t],n,r,{executeFunction:i})=>{z(t,n),U(e,n);return(Array.isArray(e)?e:e.split("")).reduce((e,s)=>{const o=i(t,[s],r,n);return X(o,n),te(e,o)||(e[o]=[]),e[o].push(s),e},{})},arity:Y(2)},partition:{evaluate:(e,t)=>{const n=M(e[0],t),r=ie(I(e[1],t)),i=e.length>=3?ie(I(e[2],t)):r,s=4===e.length?null===e[3]?[]:function(e,t){return he(e,t),e}(e[3],t):void 0;return Se(r,i,n,s,t)},arity:{min:2,max:4}},"partition-all":{evaluate:(e,t)=>{const n=M(e[0],t),r=ie(I(e[1],t));return Se(r,3===e.length?ie(I(e[2],t)):r,n,[],t)},arity:{min:2,max:3}},"partition-by":{evaluate:([e,t],n,r,{executeFunction:i})=>{z(t,n),U(e,n);const s="string"==typeof e;let o;const a=(s?e.split(""):e).reduce((e,s)=>{const a=i(t,[s],r,n);return a!==o&&(e.push([]),o=a),e[e.length-1].push(s),e},[]);return s?a.map(e=>e.join("")):a},arity:Y(2)},"ends-with?":{evaluate:([e,t],n)=>(U(e,n),"string"==typeof e?(X(t,n),e.endsWith(t)):re(C(e.at(-1),n),C(t,n),n)),arity:Y(2)},"starts-with?":{evaluate:([e,t],n)=>(U(e,n),"string"==typeof e?(X(t,n),e.startsWith(t)):re(C(e[0],n),C(t,n),n)),arity:Y(2)},interleave:{evaluate:([...e],t)=>{const n="string"==typeof e[0],r=n?e.map(e=>(X(e,t),e.split(""))):e.map(e=>(he(e,t),e)),i=Math.min(...r.map(e=>e.length)),s=[];for(let e=0;e<i;e+=1)for(const t of r)e<t.length&&s.push(t[e]);return n?s.join(""):s},arity:{min:1}},interpose:{evaluate:([e,t],n)=>{if(U(e,n),"string"==typeof e)return X(t,n),e.split("").join(t);if(0===e.length)return[];const r=[];for(let n=0;n<e.length-1;n+=1)r.push(e[n],t);return r.push(e[e.length-1]),r},arity:Y(2)}};function Se(e,t,n,r,i){$(t,i,{positive:!0});const s="string"==typeof n,o=[];let a=0;e:for(;a<n.length;){const i=[];for(let s=a;s<a+e;s+=1)if(s>=n.length){const e=s-n.length;if(!r){a+=t;continue e}if(e>=r.length)break;i.push(r[e])}else i.push(n[s]);o.push(i),a+=t}return s?o.map(e=>e.join("")):o}const ke=new WeakSet,Ee=new WeakSet,Ne=new WeakSet,Ae=new WeakSet;function $e(e){return Array.isArray(e)?(ke.has(e)||(Ie(e),Ce(e)||je(e)),e):e}function Ie(e){return!!Array.isArray(e)&&(!!Ee.has(e)||!!e.every(e=>A(e))&&(ke.add(e),Ee.add(e),!0))}function je(e){if(!Array.isArray(e))return!1;if(Ae.has(e))return!0;if(0===e.length)return!1;if(!Array.isArray(e[0]))return!1;const t=e[0].length;for(const n of e.slice(1)){if(!Array.isArray(n))return!1;if(n.length!==t)return!1}return ke.add(e),Ae.add(e),!0}function Ce(e){if(!Array.isArray(e))return!1;if(Ne.has(e))return!0;if(0===e.length)return!1;if(!Array.isArray(e[0]))return!1;if(0===e[0].length)return!1;const t=e[0].length;for(const n of e.slice(1)){if(!Array.isArray(n))return!1;if(n.length!==t)return!1;if(n.some(e=>!A(e)))return!1}return ke.add(e),Ae.add(e),Ne.add(e),!0}function Oe(e,t){let n=!1,i=!1;for(const s of e)if(Ie(s))n=!0;else if(Ce(s))i=!0;else if(!A(s))throw new r("Invalid parameter type: "+typeof s,t);if(i){if(n)throw new r("Cannot mix vector and matrix types",t);let i=null,s=null;for(const n of e)if(Ce(n))if(null===i)i=n.length,s=n[0].length;else if(n.length!==i||n[0].length!==s)throw new r("Matrix dimensions do not match",t);return["matrix",e.map(e=>Ce(e)?e:Array.from({length:i},()=>Array.from({length:s},()=>e)))]}if(n){let n=null;for(const i of e)if(Ie(i))if(null===n)n=i.length;else if(i.length!==n)throw new r("Vector lengths do not match",t);return["vector",e.map(e=>Ie(e)?e:Array.from({length:n},()=>e))]}return["number",e]}function Fe(e){return(t,n)=>{const[r,i]=Oe(t,n);return"number"===r?e(i[0]):"vector"===r?i[0].map(t=>e(t)):i[0].map(t=>t.map(t=>e(t)))}}function Me(e){return(t,n)=>{const[r,i]=Oe(t,n);return"number"===r?e(i[0],i[1]):"vector"===r?i[0].map((t,n)=>e(t,i[1][n])):i[0].map((t,n)=>t.map((t,r)=>e(t,i[1][n][r])))}}function Ue(e,t){return(n,r)=>{if(0===n.length)return e;const[i,s]=Oe(n,r);if("number"===i)return s.reduce((e,n)=>t(e,n),e);if("vector"===i){const[e,...n]=s;return n.reduce((e,n)=>e.map((e,r)=>t(e,n[r])),e)}{const[e,...n]=s;return n.reduce((e,n)=>e.map((e,r)=>e.map((e,i)=>t(e,n[r][i]))),e)}}}const Te={inc:{evaluate:Fe(e=>e+1),arity:Y(1)},dec:{evaluate:Fe(e=>e-1),arity:Y(1)},"+":{evaluate:Ue(0,(e,t)=>e+t),arity:{}},"*":{evaluate:Ue(1,(e,t)=>e*t),arity:{}},"/":{evaluate:(e,t)=>{if(0===e.length)return 1;const[n,r]=Oe(e,t);if("number"===n){const[e,...t]=r;return 0===t.length?1/e:t.reduce((e,t)=>e/t,e)}if("vector"===n){const e=r[0];return r.slice(1).reduce((e,t)=>e.map((e,n)=>e/t[n]),e)}{const e=r[0];return r.slice(1).reduce((e,t)=>e.map((e,n)=>e.map((e,r)=>e/t[n][r])),e)}},arity:{}},"-":{evaluate:(e,t)=>{if(0===e.length)return 0;const[n,r]=Oe(e,t);if("number"===n){const[e,...t]=r;return 0===t.length?-e:t.reduce((e,t)=>e-t,e)}if("vector"===n){const e=r[0];return r.slice(1).reduce((e,t)=>e.map((e,n)=>e-t[n]),e)}{const e=r[0];return r.slice(1).reduce((e,t)=>e.map((e,n)=>e.map((e,r)=>e-t[n][r])),e)}},arity:{}},quot:{evaluate:Me((e,t)=>Math.trunc(e/t)),arity:Y(2)},mod:{evaluate:Me((e,t)=>e-t*Math.floor(e/t)),arity:Y(2)},"%":{evaluate:Me((e,t)=>e%t),arity:Y(2)},sqrt:{evaluate:Fe(e=>Math.sqrt(e)),arity:Y(1)},cbrt:{evaluate:Fe(e=>Math.cbrt(e)),arity:Y(1)},"^":{evaluate:Me((e,t)=>e**t),arity:Y(2)},round:{evaluate:([e,t],n)=>{const[r,i]=Oe([e],n);if("number"===r){if(void 0===t||0===t)return Math.round(i[0]);{$(t,n,{integer:!0,positive:!0});const e=10**t;return Math.round(i[0]*e)/e}}if("vector"===r){const e=i[0];if(void 0===t||0===t)return e.map(e=>Math.round(e));{$(t,n,{integer:!0,positive:!0});const r=10**t;return e.map(e=>Math.round(e*r)/r)}}{const e=i[0];if(void 0===t||0===t)return e.map(e=>e.map(e=>Math.round(e)));{$(t,n,{integer:!0,positive:!0});const r=10**t;return e.map(e=>e.map(e=>Math.round(e*r)/r))}}},arity:{min:1,max:2}},trunc:{evaluate:Fe(e=>Math.trunc(e)),arity:Y(1)},floor:{evaluate:Fe(e=>Math.floor(e)),arity:Y(1)},ceil:{evaluate:Fe(e=>Math.ceil(e)),arity:Y(1)},min:{evaluate:([e,...t],n)=>($(e,n),0===t.length?e:t.reduce((e,t)=>($(t,n),Math.min(e,t)),e)),arity:{min:1}},max:{evaluate:([e,...t],n)=>($(e,n),0===t.length?e:t.reduce((e,t)=>($(t,n),Math.max(e,t)),e)),arity:{min:1}},abs:{evaluate:Fe(e=>Math.abs(e)),arity:Y(1)},sign:{evaluate:Fe(e=>Math.sign(e)),arity:Y(1)},ln:{evaluate:Fe(e=>Math.log(e)),arity:Y(1)},log2:{evaluate:Fe(e=>Math.log2(e)),arity:Y(1)},log10:{evaluate:Fe(e=>Math.log10(e)),arity:Y(1)},sin:{evaluate:Fe(e=>Math.sin(e)),arity:Y(1)},asin:{evaluate:Fe(e=>Math.asin(e)),arity:Y(1)},sinh:{evaluate:Fe(e=>Math.sinh(e)),arity:Y(1)},asinh:{evaluate:Fe(e=>Math.asinh(e)),arity:Y(1)},cos:{evaluate:Fe(e=>Math.cos(e)),arity:Y(1)},acos:{evaluate:Fe(e=>Math.acos(e)),arity:Y(1)},cosh:{evaluate:Fe(e=>Math.cosh(e)),arity:Y(1)},acosh:{evaluate:Fe(e=>Math.acosh(e)),arity:Y(1)},tan:{evaluate:Fe(e=>Math.tan(e)),arity:Y(1)},atan:{evaluate:Fe(e=>Math.atan(e)),arity:Y(1)},tanh:{evaluate:Fe(e=>Math.tanh(e)),arity:Y(1)},atanh:{evaluate:Fe(e=>Math.atanh(e)),arity:Y(1)},"to-rad":{evaluate:Fe(e=>e*Math.PI/180),arity:Y(1)},"to-deg":{evaluate:Fe(e=>180*e/Math.PI),arity:Y(1)}};function Be([e,...t],n){const r=C(e,n);for(const e of t)if(!re(r,C(e,n),n))return!1;return!0}const Pe={"==":{evaluate:(e,t)=>Be(e,t),arity:{min:1}},"≠":{evaluate:(e,t)=>!Be(e,t),arity:{min:1}},"identical?":{evaluate:e=>function([e,...t]){for(const n of t)if(n!==e)return!1;return!0}(e),arity:{min:1}},">":{evaluate:([e,...t],n)=>{let r=Q(e);for(const e of t){if(ne(r,Q(e),n)<=0)return!1;r=Q(e)}return!0},arity:{min:1}},"<":{evaluate:([e,...t],n)=>{let r=Q(e);for(const e of t){if(ne(r,Q(e),n)>=0)return!1;r=Q(e)}return!0},arity:{min:1}},">=":{evaluate:([e,...t],n)=>{let r=Q(e);for(const e of t){if(ne(r,Q(e),n)<0)return!1;r=Q(e)}return!0},arity:{min:1}},"<=":{evaluate:([e,...t],n)=>{let r=Q(e);for(const e of t){if(ne(r,Q(e),n)>0)return!1;r=Q(e)}return!0},arity:{min:1}},"!":{evaluate:([e])=>!e,arity:Y(1)},"epoch->iso-date":{evaluate:([e],t)=>($(e,t),new Date(e).toISOString()),arity:Y(1)},"iso-date->epoch":{evaluate:([e],t)=>{X(e,t);const n=new Date(e).valueOf();return $(n,t,{finite:!0}),n},arity:Y(1)},"write!":{evaluate:(e,t)=>(console.log(...e),e.length>0?C(e[e.length-1],t):null),arity:{}},boolean:{evaluate:([e])=>!!e,arity:Y(1)},compare:{evaluate:([e,t],n)=>(ee(e,n),ee(t,n),ne(e,t,n)),arity:Y(2)},"json-parse":{evaluate:([e],t)=>(X(e,t),JSON.parse(e)),arity:Y(1)},"json-stringify":{evaluate:([e,t],n)=>(O(e,n),void 0===t?JSON.stringify(e):($(t,n),JSON.stringify(e,null,t))),arity:{min:1,max:2}},import:{evaluate:([e],t,n)=>{X(e,t);const i=e.indexOf(".");if(-1!==i){const s=e.substring(0,i),o=e.substring(i+1),a=n.getModule(s);if(!a)throw new r(`Unknown module: '${s}'`,t);const u=a.functions[o];if(!u)throw new r(`Function '${o}' not found in module '${s}'`,t);return{[l]:!0,sourceCodeInfo:t,functionType:"Module",moduleName:s,functionName:o,arity:u.arity}}const s=e,o=n.getModule(s);if(!o)throw new r(`Unknown module: '${s}'`,t);const a={};for(const[e,n]of Object.entries(o.functions))a[e]={[l]:!0,sourceCodeInfo:t,functionType:"Module",moduleName:s,functionName:e,arity:n.arity};return a},arity:Y(1)}},Re={keys:{evaluate:([e],t)=>(B(e,t),Object.keys(e)),arity:Y(1)},vals:{evaluate:([e],t)=>(B(e,t),Object.values(e)),arity:Y(1)},entries:{evaluate:([e],t)=>(B(e,t),Object.entries(e)),arity:Y(1)},find:{evaluate:([e,t],n)=>(B(e,n),X(t,n),te(e,t)?[t,e[t]]:null),arity:Y(2)},dissoc:{evaluate:([e,t],n)=>{B(e,n),X(t,n);const r={...e};return delete r[t],r},arity:Y(2)},merge:{evaluate:(e,t)=>{if(0===e.length)return null;const[n,...r]=e;return B(n,t),r.reduce((e,n)=>(B(n,t),{...e,...n}),{...n})},arity:{min:0}},"merge-with":{evaluate:(e,t,n,{executeFunction:r})=>{const i=e[0],s=e.at(-1),o=e.slice(1,-1);return B(i,t),z(s,t),o.reduce((e,i)=>(B(i,t),Object.entries(i).forEach(i=>{const o=Z(i[0],t),a=se(i[1]);te(e,o)?e[o]=r(s,[e[o],a],n,t):e[o]=a}),e),{...i})},arity:{min:2}},zipmap:{evaluate:([e,t],n)=>{pe(e,n),he(t,n);const r=Math.min(e.length,t.length),i={};for(let s=0;s<r;s+=1){i[Z(e[s],n)]=se(t[s])}return i},arity:Y(2)},"select-keys":{evaluate:([e,t],n)=>(pe(t,n),B(e,n),t.reduce((t,n)=>(te(e,n)&&(t[n]=se(e[n])),t),{})),arity:Y(2)}},De={"function?":{evaluate:([e])=>w(e),arity:Y(1)},"string?":{evaluate:([e])=>"string"==typeof e,arity:Y(1)},"number?":{evaluate:([e])=>"number"==typeof e,arity:Y(1)},"integer?":{evaluate:([e])=>"number"==typeof e&&A(e,{integer:!0}),arity:Y(1)},"boolean?":{evaluate:([e])=>"boolean"==typeof e,arity:Y(1)},"null?":{evaluate:([e])=>null==e,arity:Y(1)},"zero?":{evaluate:([e],t)=>($(e,t,{finite:!0}),Math.abs(e)<le),arity:Y(1)},"pos?":{evaluate:([e],t)=>($(e,t,{finite:!0}),e>0),arity:Y(1)},"neg?":{evaluate:([e],t)=>($(e,t,{finite:!0}),e<0),arity:Y(1)},"even?":{evaluate:([e],t)=>($(e,t,{finite:!0}),e%2==0),arity:Y(1)},"odd?":{evaluate:([e],t)=>($(e,t,{finite:!0}),A(e,{integer:!0})&&e%2!=0),arity:Y(1)},"array?":{evaluate:([e])=>Array.isArray(e),arity:Y(1)},"coll?":{evaluate:([e])=>P(e),arity:Y(1)},"seq?":{evaluate:([e])=>F(e),arity:Y(1)},"object?":{evaluate:([e])=>T(e),arity:Y(1)},"regexp?":{evaluate:([e])=>L(e),arity:Y(1)},"finite?":{evaluate:([e],t)=>($(e,t),Number.isFinite(e)),arity:Y(1)},"positive-infinity?":{evaluate:([e],t)=>($(e,t),e===Number.POSITIVE_INFINITY),arity:Y(1)},"negative-infinity?":{evaluate:([e],t)=>($(e,t),e===Number.NEGATIVE_INFINITY),arity:Y(1)},"true?":{evaluate:([e])=>!0===e,arity:Y(1)},"false?":{evaluate:([e])=>!1===e,arity:Y(1)},"empty?":{evaluate:([e],t)=>null===e||(D(e,t),"string"==typeof e||Array.isArray(e)?0===e.length:0===Object.keys(e).length),arity:Y(1)},"not-empty?":{evaluate:([e],t)=>null!==e&&(D(e,t),"string"==typeof e||Array.isArray(e)?e.length>0:Object.keys(e).length>0),arity:Y(1)},"vector?":{evaluate:([e])=>Ie(e),arity:Y(1)},"matrix?":{evaluate:([e])=>Ce(e),arity:Y(1)},"grid?":{evaluate:([e])=>je(e),arity:Y(1)}},Le={regexp:{evaluate:([e,t],n)=>{X(e,n);const i=e||"(?:)",s="string"==typeof t?t:"";try{new RegExp(i,s)}catch(e){throw new r(`Invalid regular expression: ${i} ${s}`,n)}return{[f]:!0,sourceCodeInfo:n,s:i,f:s}},arity:{min:1,max:2}},match:{evaluate:([e,t],n)=>{if(function(e,t){if(!L(e))throw g("RegularExpression",e,t)}(t,n),!K(e))return null;const r=new RegExp(t.s,t.f).exec(e);return r?[...r]:null},arity:Y(2)},replace:{evaluate:([e,t,n],r)=>{X(e,r),_(t,r),X(n,r);const i=L(t)?new RegExp(t.s,`${t.f}`):t;return e.replace(i,n)},arity:Y(3)},"replace-all":{evaluate:([e,t,n],r)=>{X(e,r),_(t,r),X(n,r);const i=L(t)?new RegExp(t.s,`${t.f.includes("g")?t.f:`${t.f}g`}`):t;return e.replaceAll(i,n)},arity:Y(3)}},_e=/^\s*$/,Ve={"string-repeat":{evaluate:([e,t],n)=>(X(e,n),$(t,n,{integer:!0,nonNegative:!0}),e.repeat(t)),arity:Y(2)},str:{evaluate:e=>e.reduce((e,t)=>e+(null==t?"":T(t)||Array.isArray(t)?JSON.stringify(t):`${t}`),""),arity:{}},number:{evaluate:([e],t)=>{X(e,t);const n=Number(e);if(Number.isNaN(n))throw new r(`Could not convert '${e}' to a number.`,t);return n},arity:Y(1)},"from-char-code":{evaluate:([e],t)=>{$(e,t,{finite:!0});const n=ie(e);try{return String.fromCodePoint(n)}catch(e){throw new r(e,t)}},arity:Y(1)},"to-char-code":{evaluate:([e],t)=>(X(e,t,{nonEmpty:!0}),m(e.codePointAt(0),t)),arity:Y(1)},"lower-case":{evaluate:([e],t)=>(X(e,t),e.toLowerCase()),arity:Y(1)},"upper-case":{evaluate:([e],t)=>(X(e,t),e.toUpperCase()),arity:Y(1)},trim:{evaluate:([e],t)=>(X(e,t),e.trim()),arity:Y(1)},"trim-left":{evaluate:([e],t)=>(X(e,t),e.replace(/^\s+/,"")),arity:Y(1)},"trim-right":{evaluate:([e],t)=>(X(e,t),e.replace(/\s+$/,"")),arity:Y(1)},join:{evaluate:([e,t],n)=>(he(e,n),e.forEach(e=>ee(e,n)),X(t,n),e.join(t)),arity:Y(2)},split:{evaluate:([e,t,n],r)=>{X(e,r),_(t,r),void 0!==n&&$(n,r,{integer:!0,nonNegative:!0});const i="string"==typeof t?t:new RegExp(t.s,t.f);return e.split(i,n)},arity:{min:2,max:3}},"split-lines":{evaluate:([e],t)=>(X(e,t),e.split(/\r\n|\n|\r/).filter(e=>""!==e)),arity:Y(1)},"pad-left":{evaluate:([e,t,n],r)=>(X(e,r),$(t,r,{integer:!0}),void 0!==n&&X(n,r),e.padStart(t,n)),arity:{min:2,max:3}},"pad-right":{evaluate:([e,t,n],r)=>(X(e,r),$(t,r,{integer:!0}),void 0!==n&&X(n,r),e.padEnd(t,n)),arity:{min:2,max:3}},template:{evaluate:([e,...t],n)=>{X(e,n),he(t,n);const r=e.split("||||");if(r.length<=1)return Je(r[0],t,n);{const e=t[0];$(e,n,{integer:!0,nonNegative:!0});const i=[`${e}`,...t.slice(1)];if(2===r.length){return Je(r[1===e?0:1],i,n)}return Je(r[Math.min(e,r.length-1)],i,n)}},arity:{min:1,max:10}},"encode-base64":{evaluate:([e],t)=>(X(e,t),btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(e,t)=>String.fromCharCode(Number.parseInt(t,16))))),arity:Y(1)},"decode-base64":{evaluate:([e],t)=>{X(e,t);try{return decodeURIComponent(Array.prototype.map.call(atob(e),e=>`%${`00${e.charCodeAt(0).toString(16)}`.slice(-2)}`).join(""))}catch(e){throw new r(e,t)}},arity:Y(1)},"encode-uri-component":{evaluate:([e],t)=>(X(e,t),encodeURIComponent(e)),arity:Y(1)},"decode-uri-component":{evaluate:([e],t)=>{X(e,t);try{return decodeURIComponent(e)}catch(e){throw new r(e,t)}},arity:Y(1)},capitalize:{evaluate:([e],t)=>(X(e,t),e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()),arity:Y(1)},"blank?":{evaluate:([e],t)=>null===e||(X(e,t),_e.test(e)),arity:Y(1)}},ze=/\$\$/g;function Je(e,t,n){for(let r=0;r<9;r+=1){const i=new RegExp(`(\\$\\$|[^$]|^)\\$${r+1}`,"g");if(i.test(e)){const s=Q(t[r],n);e=e.replace(i,`$1${s}`)}}return e=e.replace(ze,"$")}const We={"|>":{evaluate:([e,t],n,r,{executeFunction:i})=>(z(t,n),i(t,[e],r,n)),arity:Y(2)},apply:{evaluate:([e,...t],n,r,{executeFunction:i})=>{z(e,n);const s=t[t.length-1];he(s,n);return i(e,[...t.slice(0,-1),...s],r,n)},arity:{min:2}},identity:{evaluate:([e])=>se(e),arity:Y(1)},comp:{evaluate:(e,t)=>(e.forEach(e=>z(e,t)),{[l]:!0,sourceCodeInfo:t,functionType:"Comp",params:e,arity:e.length>0?W(e.at(-1)):{min:1,max:1}}),arity:{}},constantly:{evaluate:([e],t)=>({[l]:!0,sourceCodeInfo:t,functionType:"Constantly",value:se(e),arity:{}}),arity:Y(1)},juxt:{evaluate:(e,t)=>{e.forEach(e=>z(e,t));const n=function(e){return e.reduce((e,t)=>{if(null===e)return null;const n="number"==typeof t||P(t)?Y(1):t.arity,{min:r,max:i}=n,{min:s,max:o}=e,a="number"==typeof r&&"number"==typeof s?Math.max(r,s):"number"==typeof r?r:"number"==typeof s?s:void 0,u="number"==typeof i&&"number"==typeof o?Math.min(i,o):"number"==typeof i?i:"number"==typeof o?o:void 0;return"number"==typeof a&&"number"==typeof u&&a>u?null:{min:a,max:u}},{})}(e);if(null===n)throw new r("All functions must accept the same number of arguments",t);return{[l]:!0,sourceCodeInfo:t,functionType:"Juxt",params:e,arity:n}},arity:{min:1}},complement:{evaluate:([e],t)=>{const n=V(e,t);return{[l]:!0,sourceCodeInfo:t,functionType:"Complement",function:n,arity:W(n)}},arity:Y(1)},"every-pred":{evaluate:(e,t)=>({[l]:!0,sourceCodeInfo:t,functionType:"EveryPred",params:e,arity:{min:1,max:1}}),arity:{min:1}},"some-pred":{evaluate:(e,t)=>({[l]:!0,sourceCodeInfo:t,functionType:"SomePred",params:e,arity:{min:1,max:1}}),arity:{min:1}},fnull:{evaluate:([e,...t],n)=>{const r=V(e,n);return{[l]:!0,sourceCodeInfo:n,functionType:"Fnull",function:r,params:t,arity:W(r)}},arity:{min:2}}};function qe(e){return fe(`\n ${e.title}\n\n ${e.description.replace(/`(.+?)`/g,"$1").replace(/\$(\w+)/g,"$1").replace(/\*\*\*(.+)\*\*\*/g,"$1").replace(/\*\*(.+)\*\*/g,"$1")}\n\n Signature:\n ${function({title:e,variants:t,args:n,returns:r,_isOperator:i}){const s=t.map(t=>`${` ${e}(${t.argumentNames.map(e=>{let t="";return n[e].rest&&(t+="..."),t+=e,t}).join(", ")})`} -> ${Ye(r)}`),o=i?["","Operator:",` a ${e} b -> ${Ye(r)}`]:[];return[...s,...o]}(e).join("\n ")}\n\n Arguments:\n ${function(e){return Object.entries(e.args).map(([e,t])=>`${e}: ${Ye(t)}`)}(e).join("\n ")}\n\n Examples:\n${e.examples.map(e=>fe(e,4)).join("\n\n")}`)}function Ye(e){const t=e.type,n=(Array.isArray(t)?t:[t]).join(" | ");return e.array||e.rest?`Array<${n}>`:n}const Ge={...G,...be,...we,...xe,...Te,...function(e){return{doc:{evaluate:([t],n)=>{if(v(e),z(t,n),!w(t))return"";if("Builtin"===t.functionType){const n=e[t.name];return n?qe(n):""}return"UserDefined"===t.functionType||"NativeJsFunction"===t.functionType?t.docString:""},arity:Y(1)},arity:{evaluate:([e],t)=>(z(e,t),w(e)?e.arity:Y(1)),arity:Y(1)}}}({}),...Pe,...Re,...De,...Le,...Ve,...We};Object.entries(Ge).forEach(([e,t])=>{t.name=e});const Ke={...Ge},Xe={},Ze=[];Object.entries(Ke).forEach(([e,t],n)=>{Xe[e]=n,Ze.push(t)});const He={arity:{},evaluate:(e,t,{evaluateNode:n})=>{let r=!0;for(const i of e[1][1])if(r=n(i,t),!r)break;return r},evaluateAsNormalExpression:(e,t)=>{let n=!0;for(const r of e)if(n=C(r,t),!n)break;return n},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)};function Qe(e){const t=e[0];return o.UserDefinedSymbol===t||o.NormalBuiltinSymbol===t||o.SpecialBuiltinSymbol===t}function et(e){return o.UserDefinedSymbol===e[0]}function tt(e,t){return function(e,t){if(!et(e))throw g("UserDefinedSymbolNode",e,t)}(e,t),e}function nt(e){return o.NormalBuiltinSymbol===e[0]}function rt(e){return o.SpecialBuiltinSymbol===e[0]}function it(e){return!!function(e){return e[0]===o.NormalExpression}(e)&&Qe(e[1][0])}function st(e){return e[0]===o.Spread}const ot={arity:Y(1),evaluate:(e,t)=>{const n=e[1][1];if(function(e,t){if(!Qe(e))throw g("SymbolNode",e,t)}(n),!et(n))return!0;return null!==t.lookUp(n)},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n([e[1][1]],t,r,i)};const at=11,ut=12,ct=13,lt=14;function ft(e,t){if(e[0]===ct)Object.values(e[1][0]).forEach(e=>{e[1][1]&&t(e[1][1]),ft(e,t)});else if(e[0]===lt)for(let n=0;n<e[1][0].length;n+=1){const r=e[1][0][n]??null;null!==r&&(r[1][1]&&t(r[1][1]),ft(r,t))}}function ht(e,t,n){const r={};return pt(e,t,n,e[2],r),r}function pt(e,t,n,i,s){if(e[0]===ct){!function(e,t){if(!b(e))throw new r(`Expected UnknownRecord, got ${d(e)}.`,y(e,t))}(t,i);const o=new Set;let a;if(Object.entries(e[1][0]).forEach(([e,r])=>{if(r[0]===ut)return void(a=r);o.add(e);const u=(void 0!==t[e]?t[e]:r[1][1]&&n(r[1][1]))??null;O(u,i),pt(r,u,n,i,s)}),a){const e=Object.entries(t).filter(([e])=>!o.has(e)).reduce((e,[t,n])=>(e[t]=C(n),e),{});s[a[1][0]]=e}}else if(e[0]===lt){let r=null;he(t,i);for(let o=0;o<e[1][0].length;o+=1){const a=e[1][0][o]??null;if(null===a)continue;if(a[0]===ut){r=o;break}const u=(void 0!==t[o]?t[o]:a[1][1]&&n(a[1][1]))??null;O(u,i),pt(a,u,n,i,s)}if(null!==r){const n=t.slice(r),i=e[1][0][r];s[i[1][0]]=n}}else e[0]===ut?s[e[1][0]]=C(t):s[e[1][0][1]]=C(t)}function dt(e){const t={};return yt(e,t),t}function yt(e,t){if(null!==e)if(e[0]===lt)for(const n of e[1][0])yt(n,t);else if(e[0]===ct)for(const n of Object.values(e[1][0]))yt(n,t);else if(e[0]===ut){if(t[e[1][0]])throw new r(`Duplicate binding name: ${e[1][0]}`,e[2]);t[e[1][0]]=!0}else{if(t[e[1][0][1]])throw new r(`Duplicate binding name: ${e[1][0]}`,e[2]);t[e[1][0][1]]=!0}}const gt={arity:{},evaluate:(e,t,{evaluateNode:n})=>{const r=e[1][1],i=r[1][0],s=r[1][1],o=n(s,t),a=ht(i,o,e=>n(e,t));return t.exportValues(a,i[2]),o},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>{const s=e[1][1],o=s[1][0],a=s[1][1],u=n([a],t,r,i);return ft(o,e=>{ce(u,n([e],t,r,i))}),t.addValues(dt(o),o[2]),u}},mt={arity:{},evaluate:(e,t,{builtin:n,getUndefinedSymbols:r,evaluateNode:i})=>{const s=e[1][1],o=e[1][2],a=function(e,t,n,r,i){const s={},o=e[0].reduce((e,t)=>(Object.keys(dt(t)).forEach(t=>{e[t]={value:null}}),e),{}),a=r(e[1],t.new(o),n,i);a.forEach(e=>{const n=t.getValue(e);j(n)&&(s[e]={value:n})});const u=[e[0],e[1],s];return u}(s,t,n,r,i),u=a[0].filter(e=>e[0]!==ut&&void 0===e[1][1]).length,c={min:u>0?u:void 0,max:a[0].some(e=>e[0]===ut)?void 0:a[0].length};return{[l]:!0,sourceCodeInfo:e[2],functionType:"UserDefined",name:void 0,evaluatedfunction:a,arity:c,docString:o}},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>function(e,t,n,r,i){const s=new Set,o={self:{value:null}};e[0].forEach(e=>{Object.assign(o,dt(e)),ft(e,e=>{ce(s,n([e],t,r,i))})});const a=t.create(o),u=n(e[1],a,r,i);return ce(s,u),s}(e[1][1],t,n,r,i)};const vt={arity:Y(0),evaluate:(e,t,{evaluateNode:n})=>{const r=e[1][1],i=r[1][0],s=r[1][1],o=n(s,t),a=ht(i,o,e=>n(e,t));return t.addValues(a,i[2]),o},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>{const s=e[1][1],o=s[1][0],a=s[1][1],u=n([a],t,r,i);return ft(o,e=>{ce(u,n([e],t,r,i))}),t.addValues(dt(o),o[2]),u}},bt={arity:{},evaluate:(e,t,{evaluateNode:i})=>{const s=e[1][1],o=s.reduce((e,n)=>{const r=i(n[1][1],t.create(e)),s=ht(n[1][0],r,e=>i(e,t));return Object.entries(s).forEach(([t,n])=>{e[t]={value:n}}),e},{}),a=t.create(o),u=e[1][2];for(;;){let c=null;try{c=i(u,a)}catch(a){if(a instanceof n){const n=a.params;if(n.length!==s.length)throw new r(`recur expected ${s.length} parameters, got ${d(n.length)}`,e[2]);s.forEach((e,r)=>{const s=ht(e[1][0],C(n[r]),e=>i(e,t));for(const[e,t]of Object.entries(s))o[e].value=t});continue}throw a}return c}},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>{const s=e[1][1],o=s.reduce((e,t)=>{const n=dt(t[1][0]);return Object.keys(n).forEach(t=>{e[t]={value:!0}}),e},{});return ue(n(s.map(e=>e[1][1]),t,r,i),n([e[1][2]],t.create(o),r,i))}};function wt(e,t,n,r){for(const i of e){const[e,s]=i[1],o=ht(e,r(s,n),e=>r(e,n));Object.entries(o).forEach(([e,n])=>{t[e]={value:n}})}}function xt(e,t,n,r){const i=t[2],[,s,o]=t[1],a=[],u=s.map(()=>0);let c=!1;for(;!c;){const t={},l=n.create(t);let f=!1;e:for(let e=0;e<s.length;e+=1){const[n,o,a,h]=s[e],[p,d]=n[1],y=R(r(d,l),i),g=F(y)?y:Object.entries(y);if(0===g.length){f=!0,c=!0;break}const v=m(u[e],i);if(v>=g.length){if(f=!0,0===e){c=!0;break}u[e]=0,u[e-1]=m(u[e-1],i)+1;break}const b=ht(p,C(g[v],i),e=>r(e,l));if(Object.entries(b).forEach(([e,n])=>{t[e]={value:n}}),o&&wt(o,t,l,r),a&&!r(a,l)){u[e]=m(u[e],i)+1,f=!0;break e}if(h&&!r(h,l)){u[e]=Number.POSITIVE_INFINITY,f=!0;break e}}if(!f){const t=r(o,l);e&&a.push(t),u.length>0&&(u[u.length-1]+=1)}}return e?a:null}function St(e,t,n,r,i){const s=new Set,o={},[,a,u]=e[1];return a.forEach(e=>{const[a,u,c,l]=e,[f,h]=a[1];n([h],t.create(o),r,i).forEach(e=>s.add(e)),Object.assign(o,dt(f)),u&&u.forEach(e=>{const[a,u]=e[1];n([u],t.create(o),r,i).forEach(e=>s.add(e)),Object.assign(o,dt(a))}),c&&n([c],t.create(o),r,i).forEach(e=>s.add(e)),l&&n([l],t.create(o),r,i).forEach(e=>s.add(e))}),n([u],t.create(o),r,i).forEach(e=>s.add(e)),s}const kt={arity:Y(1),evaluate:(e,t,n)=>xt(!0,e,t,n.evaluateNode),getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>St(e,t,n,r,i)},Et={arity:Y(1),evaluate:(e,t,n)=>(xt(!1,e,t,n.evaluateNode),null),getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>St(e,t,n,r,i)},Nt={arity:{},evaluate:(e,t,{evaluateNode:n})=>{let r=!1;for(const i of e[1][1])if(r=n(i,t),r)break;return r},evaluateAsNormalExpression:(e,t)=>{let n=!1;for(const r of e)if(n=C(r,t),n)break;return n},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)},At={arity:{min:1},evaluate:(e,t,{evaluateNode:n})=>{for(const r of e[1][1]){if(et(r)&&null===t.lookUp(r))continue;const e=n(r,t);if(null!==e)return e}return null},evaluateAsNormalExpression:(e,t)=>{for(const n of e){const e=C(n,t);if(null!==e)return e}return null},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)},$t={arity:{},evaluate:(e,t,{evaluateNode:r})=>{const i=e[1][1].map(e=>r(e,t));throw new n(i)},evaluateAsNormalExpression:e=>{throw new n(e)},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)},It={arity:Y(1),evaluate:(e,t,{evaluateNode:n})=>{const r=Z(n(e[1][1],t),e[2],{nonEmpty:!0});throw new i(r,e[2])},evaluateAsNormalExpression:(e,t)=>{const n=Z(e[0],t,{nonEmpty:!0});throw new i(n,void 0)},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n([e[1][1]],t,r,i)},jt={arity:{},evaluate:(e,t,{evaluateNode:n})=>{const[,r,i,s]=e[1];try{return n(r,t)}catch(e){const r=i?{[i[1]]:{value:e}}:{};return n(s,t.create(r))}},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>{const[,s,o,a]=e[1],u=n([s],t,r,i),c=o?{[o[1]]:{value:!0}}:{};return ue(u,n([a],t.create(c),r,i))}},Ct={arity:{},evaluate:(e,t,{evaluateNode:n})=>{const i=[];for(const s of e[1][1])if(st(s)){const e=n(s[1],t);if(!Array.isArray(e))throw new r("Spread value is not an array",s[2]);i.push(...e)}else i.push(n(s,t));return i},evaluateAsNormalExpression:(e,t)=>{const n=[];for(const r of e)n.push(C(r,t));return n},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)},Ot={arity:{},evaluate:(e,t,{evaluateNode:n})=>{const i={},s=e[1][1];for(let e=0;e<s.length;e+=2){const o=s[e];if(st(o)){const s=n(o[1],t);if(!b(s))throw new r("Spread value is not an object",o[2]);Object.assign(i,s),e-=1}else{const a=n(o,t),u=s[e+1];if(void 0===u)throw new r("Missing value for key",o[2]);const c=n(u,t);X(a,o[2]),i[a]=c}}return i},evaluateAsNormalExpression:(e,t)=>{const n={};for(let r=0;r<e.length;r+=2){const i=e[r],s=e[r+1];X(i,t),n[i]=s??null}return n},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)},Ft={"??":0,"&&":1,"||":2,array:3,cond:4,"0_def":5,"defined?":6,block:7,doseq:8,"0_lambda":9,for:10,if:11,let:12,loop:13,object:14,recur:15,switch:16,throw:17,try:18,unless:19},Mt=[At,He,Nt,Ct,{arity:{},evaluate:(e,t,{evaluateNode:n})=>{const r=e[1][1];for(const[e,i]of r){if(n(e,t))return n(i,t)}return null},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1].flat(),t,r,i)},gt,ot,{arity:{},evaluate:(e,t,{evaluateNode:n})=>{const r=t.create({});let i=null;for(const t of e[1][1])i=n(t,r);return i},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t.create({}),r,i)},Et,mt,kt,{arity:{min:2,max:3},evaluate:(e,t,{evaluateNode:n})=>{const[r,i,s]=e[1][1];return n(r,t)?n(i,t):s?n(s,t):null},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1].filter(e=>!!e),t,r,i)},vt,bt,Ot,$t,{arity:{},evaluate:(e,t,{evaluateNode:n})=>{const[,r,i]=e[1],s=n(r,t);for(const[e,r]of i){if(n(e,t)===s)return n(r,t)}return null},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n([e[1][1],...e[1][2].flat()],t,r,i)},It,jt,{arity:{},evaluate:(e,t,{evaluateNode:n})=>{const[r,i,s]=e[1][1];return n(r,t)?s?n(s,t):null:n(i,t)},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1].filter(e=>!!e),t,r,i)}],Ut={normalExpressions:Ke,specialExpressions:Mt,allNormalExpressions:Ze},Tt=Object.keys(Ke),Bt=Object.keys(Ft);new Set(Bt);const Pt=(e,t,n,r)=>{const i=Array.isArray(e)?e:[[o.SpecialExpression,[Ft.block,e.body]]],s=new Set;for(const e of i)Rt(e,t,n,r)?.forEach(e=>s.add(e));return s};function Rt(e,t,n,i){const s=e[0];switch(s){case o.UserDefinedSymbol:{const n=e;return null===t.lookUp(n)?new Set([n[1]]):null}case o.NormalBuiltinSymbol:case o.SpecialBuiltinSymbol:case o.String:case o.Number:case o.ReservedSymbol:case o.Binding:return null;case o.NormalExpression:{const r=e,s=new Set;if(it(r)){const[,[e]]=r;if(et(e)){null===t.lookUp(e)&&s.add(e[1])}}else{const[,[e]]=r;Rt(e,t,n,i)?.forEach(e=>s.add(e))}for(const e of r[1][1])Rt(e,t,n,i)?.forEach(e=>s.add(e));return s}case o.SpecialExpression:{const r=e,s=r[1][0];return(0,n.specialExpressions[s].getUndefinedSymbols)(r,t,{getUndefinedSymbols:Pt,builtin:n,evaluateNode:i})}case o.Spread:return Rt(e[1],t,n,i);default:throw new r(`Unhandled node type: ${s}`,e[2])}}const Dt=(1+Math.sqrt(5))/2,Lt={E:Math.E,"-E":-Math.E,"ε":Math.E,"-ε":-Math.E,PI:Math.PI,"-PI":-Math.PI,"π":Math.PI,"-π":-Math.PI,PHI:Dt,"-PHI":-Dt,"φ":Dt,"-φ":-Dt,POSITIVE_INFINITY:Number.POSITIVE_INFINITY,"∞":Number.POSITIVE_INFINITY,NEGATIVE_INFINITY:Number.NEGATIVE_INFINITY,"-∞":Number.NEGATIVE_INFINITY,MAX_SAFE_INTEGER:Number.MAX_SAFE_INTEGER,MIN_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,MAX_VALUE:Number.MAX_VALUE,MIN_VALUE:Number.MIN_VALUE,NaN:Number.NaN},_t={true:!0,false:!1,null:null,do:null,else:null,case:null,each:null,in:null,when:null,while:null,catch:null,function:null,export:null,as:null,then:null,end:null,_:null,...Lt};const Vt={NativeJsFunction:(e,t,n)=>{try{return se(e.nativeFn.fn(...t))}catch(e){const t="string"==typeof e?e:b(e)&&"string"==typeof e.message?e.message:"<no message>";throw new r(`Native function throwed: "${t}"`,n)}},UserDefined:(e,t,i,s,{evaluateNode:o})=>{for(;;){if(!J(e.arity,t.length))throw new r(`Expected ${e.arity} arguments, got ${t.length}.`,i);const a=e.evaluatedfunction,u=a[0],c=u.filter(e=>e[0]!==ut).length,l=s.create(e.evaluatedfunction[2]),f={self:{value:e}},h=[];for(let e=0;e<t.length;e+=1)if(e<c){const n=se(t[e]),r=ht(u[e],n,e=>o(e,l.create(f)));Object.entries(r).forEach(([e,t])=>{f[e]={value:t}})}else h.push(se(t[e]));for(let e=t.length;e<c;e++){const t=u[e],n=ht(t,o(t[1][1],s.create(f)),e=>o(e,s.create(f)));Object.entries(n).forEach(([e,t])=>{f[e]={value:t}})}const p=u.find(e=>e[0]===ut);if(void 0!==p){const e=ht(p,h,e=>o(e,s.create(f)));Object.entries(e).forEach(([e,t])=>{f[e]={value:t}})}try{let e=null;const t=l.create(f);for(const n of a[1])e=o(n,t);return e}catch(e){if(e instanceof n){t=e.params;continue}throw e}}},Partial:(e,t,n,i,{executeFunction:s})=>{const o=[...e.params];if(t.length!==e.placeholders.length)throw new r(`(partial) expects ${e.placeholders.length} arguments, got ${t.length}.`,n);const a=[...t];for(const t of e.placeholders)o.splice(t,0,a.shift());return s(e.function,o,i,n)},Comp:(e,t,n,i,{executeFunction:s})=>{const{params:o}=e;if(0===o.length){if(1!==t.length)throw new r(`(comp) expects one argument, got ${d(t.length)}.`,n);return C(t[0],n)}return C(o.reduceRight((e,t)=>[s(V(t,n),e,i,n)],t)[0],n)},Constantly:e=>e.value,Juxt:(e,t,n,r,{executeFunction:i})=>e.params.map(e=>i(V(e,n),t,r,n)),Complement:(e,t,n,r,{executeFunction:i})=>!i(e.function,t,r,n),EveryPred:(e,t,n,r,{executeFunction:i})=>{for(const s of e.params)for(const e of t){if(!i(V(s,n),[e],r,n))return!1}return!0},SomePred:(e,t,n,r,{executeFunction:i})=>{for(const s of e.params)for(const e of t){if(i(V(s,n),[e],r,n))return!0}return!1},Fnull:(e,t,n,r,{executeFunction:i})=>{const s=t.map((t,n)=>null===t?se(e.params[n]):t);return i(V(e.function,n),s,r,n)},Builtin:(e,t,n,r,{executeFunction:i})=>m(Ze[e.normalBuitinSymbolType],n).evaluate(t,n,r,{executeFunction:i}),SpecialBuiltin:(e,t,n,i,{executeFunction:s})=>{const o=m(Mt[e.specialBuiltinSymbolType],n);if(o.evaluateAsNormalExpression)return o.evaluateAsNormalExpression(t,n,i,{executeFunction:s});throw new r(`Special builtin function ${e.specialBuiltinSymbolType} is not supported as normal expression.`,n)},Module:(e,t,n,i,{executeFunction:s})=>{const o=i.getModule(e.moduleName);if(!o)throw new r(`Module '${e.moduleName}' not found.`,n);const a=o.functions[e.functionName];if(!a)throw new r(`Function '${e.functionName}' not found in module '${e.moduleName}'.`,n);return q(a.arity,t.length,n),a.evaluate(t,n,i,{executeFunction:s})}};function zt(e,t){let n=null;for(const r of e.body)n=Jt(r,t);return n}function Jt(e,t){switch(e[0]){case o.Number:case o.String:return function(e){return e[1]}(e);case o.NormalBuiltinSymbol:case o.SpecialBuiltinSymbol:case o.UserDefinedSymbol:return t.evaluateSymbol(e);case o.ReservedSymbol:return function(e){const t=e[1];if(!["true","false","null"].includes(t))throw new r(`Reserved symbol ${t} cannot be evaluated`,e[2]);return m(_t[t],e[2])}(e);case o.NormalExpression:{const n=function(e,t){const n=e[2],i=e[1][1],a=[],u=[];if(i.forEach((e,n)=>{if(st(e)){const n=Jt(e[1],t);if(!Array.isArray(n))throw new r(`Spread operator requires an array, got ${d(e)}`,e[2]);a.push(...n)}else e[0]===o.ReservedSymbol&&"_"===e[1]?u.push(n):a.push(Jt(e,t))}),it(e)){const r=e[1][0];if(u.length>0){const e=Jt(r,t);return{[l]:!0,function:V(e,n),functionType:"Partial",params:a,placeholders:u,sourceCodeInfo:n,arity:Y(u.length)}}if(nt(r)){const n=r[1];return Ut.allNormalExpressions[n].evaluate(a,e[2],t,{executeFunction:Wt})}{const i=t.getValue(r[1]);if(void 0!==i)return Wt(V(i,n),a,t,n);throw new s(r[1],e[2])}}{const r=V(Jt(e[1][0],t),n);if(u.length>0){return{[l]:!0,function:r,functionType:"Partial",params:a,placeholders:u,sourceCodeInfo:n,arity:Y(u.length)}}return Wt(r,a,t,n)}}(e,t);if("number"==typeof n&&Number.isNaN(n))throw new r("Number is NaN",e[2]);return $e(n)}case o.SpecialExpression:return $e(function(e,t){const n=e[1][0],r=m(Ut.specialExpressions[n],e[2]);return(0,r.evaluate)(e,t,{evaluateNode:Jt,builtin:Ut,getUndefinedSymbols:Pt})}(e,t));default:throw new r(`${u(e[0])}-node cannot be evaluated`,e[2])}}function Wt(e,t,n,i){if(w(e))return Vt[e.functionType](e,t,i,n,{evaluateNode:Jt,executeFunction:Wt});if(Array.isArray(e))return function(e,t,n){if(1!==t.length)throw new r("Array as function requires one non negative integer parameter.",n);const i=t[0];return $(i,n,{integer:!0,nonNegative:!0}),se(e[i])}(e,t,i);if(T(e))return function(e,t,n){if(1!==t.length)throw new r("Object as function requires one string parameter.",n);const i=t[0];return X(i,n),se(e[i])}(e,t,i);if("string"==typeof e)return function(e,t,n){if(1!==t.length)throw new r("String as function requires one Obj parameter.",n);const i=se(t[0]);if(T(i))return se(i[e]);if(A(i,{integer:!0}))return se(e[i]);throw new r(`string as function expects Obj or integer parameter, got ${d(i)}`,n)}(e,t,i);if(A(e))return function(e,t,n){if($(e,n,{integer:!0}),1!==t.length)throw new r("Number as function requires one Arr parameter.",n);const i=t[0];return U(i,n),se(i[e])}(e,t,i);throw new r("Unexpected function type",i)}class qt{contexts;globalContext;values;nativeJsFunctions;modules;constructor({contexts:e,values:t,nativeJsFunctions:n,modules:r}){this.globalContext=m(e[0]),this.contexts=e,this.values=t,this.nativeJsFunctions=n,this.modules=r??new Map}getModule(e){return this.modules.get(e)}create(e){const t=this.globalContext,n=new qt({contexts:[e,...this.contexts],values:this.values,nativeJsFunctions:this.nativeJsFunctions,modules:this.modules});return n.globalContext=t,n}new(e){return new qt({contexts:[{},e],modules:this.modules})}exportValues(e,t){for(const[n,i]of Object.entries(e)){if(this.globalContext[n])throw new r(`Cannot redefine exported value "${n}"`,t);if(Bt.includes(n))throw new r(`Cannot shadow special expression "${n}"`,t);if(Tt.includes(n))throw new r(`Cannot shadow builtin function "${n}"`,t);if("self"===n)throw new r(`Cannot shadow builtin value "${n}"`,t);this.globalContext[n]={value:i}}this.contexts[0]!==this.globalContext&&this.addValues(e,t)}addValues(e,t){const n=this.contexts[0];for(const[i,s]of Object.entries(e)){if(n[i])throw new r(`Cannot redefine value "${i}"`,t);if(Bt.includes(i))throw new r(`Cannot shadow special expression "${i}"`,t);if(Tt.includes(i))throw new r(`Cannot shadow builtin function "${i}"`,t);if("self"===i)throw new r(`Cannot shadow builtin value "${i}"`,t);n[i]={value:se(s)}}}getValue(e){for(const t of this.contexts){const n=t[e];if(n)return n.value}const t=this.nativeJsFunctions?.[e];return t||this.values?.[e]}lookUp(e){const t=e[1];for(const e of this.contexts){const n=e[t];if(n)return n}const n=this.values?.[t];if(void 0!==n)return{value:se(n)};const r=this.nativeJsFunctions?.[t];return r?{value:r}:null}evaluateSymbol(e){if(rt(e)){const t=e[1];switch(t){case Ft["&&"]:case Ft["||"]:case Ft.array:case Ft.object:case Ft["defined?"]:case Ft.recur:case Ft.throw:case Ft["??"]:{const n=m(Ut.specialExpressions[t],e[2]);return{[l]:!0,functionType:"SpecialBuiltin",specialBuiltinSymbolType:t,sourceCodeInfo:e[2],arity:n.arity}}default:throw new r(`Unknown special builtin symbol type: ${t}`,e[2])}}if(nt(e)){const t=e[1],n=Ze[t],r=n.name;return{[l]:!0,functionType:"Builtin",normalBuitinSymbolType:t,sourceCodeInfo:e[2],arity:n.arity,name:r}}const t=this.lookUp(e);if(b(n=t)&&void 0!==n.value)return t.value;var n;throw new s(e[1],e[2])}}function Yt(e={},t){const n=e.globalContext??{},r=e.contexts?[n,...e.contexts]:[n],i=new qt({contexts:r,values:e.values,modules:t,nativeJsFunctions:e.jsFunctions&&Object.entries(e.jsFunctions).reduce((e,[t,n])=>{const r=t.split("."),i=r.pop();if(/^[A-Z]/.test(i))return console.warn(`Invalid identifier "${t}" in jsFunctions, function name must not start with an uppercase letter`,void 0),e;let s=e;for(const n of r){if(0===n.length)return console.warn(`Invalid empty identifier "${t}" in nativeJsFunctions`,void 0),e;if(!/^[A-Z]/.test(n))return console.warn(`Invalid identifier "${t}" in jsFunctions, module name must start with an uppercase letter`,void 0),e;s[n]||(s[n]={}),s=s[n]}!function(e){if(!function(e){return"object"==typeof e&&null!==e&&"fn"in e&&"function"==typeof e.fn}(e))throw new TypeError("Expected a NativeJsFunction")}(n);const o={functionType:"NativeJsFunction",nativeFn:n,name:i,[l]:!0,arity:n.arity??{},docString:n.docString??""};return s!==e||function(e){return Bt.includes(e)?(console.warn(`Cannot shadow special expression "${e}", ignoring.`),!1):Tt.includes(e)?(console.warn(`Cannot shadow builtin function "${e}", ignoring.`),!1):"self"!==e||(console.warn(`Cannot shadow builtin value "${e}", ignoring.`),!1)}(i)?(s[i]=o,e):e},{})});return e.globalModuleScope?i:i.create({})}const Gt=["^","*","/","%","+","-","<<",">>",">>>","++","<","<=","≤",">",">=","≥","==","!=","≠","&","xor","|","&&","||","??","|>"],Kt=[...Gt,"?",":","->","...",".",",","=",":",";"],Xt=new Set(["comment","cond","def","defined?","block","doseq","if","let","loop","recur","throw","try","unless","while"]);function Zt(e){return!Xt.has(e)}const Ht=new Set(Gt);function Qt(e){return Ht.has(e)}const en=new Set(Kt);function tn(e){return en.has(e)}const nn=["(",")","[","]","{","}","'",'"',"`",",",".",";"," ","\n","\r","\t"],rn=["0","1","2","3","4","5","6","7","8","9",...nn],sn=new Set(nn),on=new Set(rn),an=/\s/,un=[0],cn=(e,t)=>{if('"'!==e[t])return un;let n='"',r=1,i=e[t+r],s=!1;for(;i&&('"'!==i||s);)r+=1,s?(s=!1,n+=i):("\\"===i&&(s=!0),n+=i),i=e[t+r];return i?(n+='"',[r+1,["String",n]]):[r,["Error",n,void 0,`Unclosed string at position ${t}`]]};function ln(e,t,n,r){return t===n.slice(r,r+t.length)?[t.length,[e,t]]:un}const fn=/\d/,hn=/[0-7]/,pn=/[0-9a-f]/i,dn=/[01]/,yn=/[\s)\]}(,;]/,gn=(e,t)=>{let n=e[t];if("'"===n){let r=1,i=e[t+r],s=!1;for(;"'"!==i||s;){if(void 0===i)return[r,["Error",n,void 0,`Unclosed quoted symbol at position ${t}`]];r+=1,s?(s=!1,n+=i):("\\"===i&&(s=!0),n+=i),i=e[t+r]}return n+="'",[r+1,["Symbol",n]]}if(!on.has(n)){const r=t;let i=e[t+=1];for(;i&&!sn.has(i);)n+=i,i=e[t+=1];return n.endsWith(":")?[t-r-1,["Symbol",n.slice(0,-1)]]:[t-r,["Symbol",n]]}return un},mn=[(e,t)=>{let n=e[t];if(!n||!an.test(n))return un;let r=n;for(n=e[t+=1];n&&an.test(n);)r+=n,n=e[t+=1];return[r.length,["Whitespace",r]]},(e,t)=>{if("/"===e[t]&&"*"===e[t+1]){let n=2,r="/*";for(;("*"!==e[t+n]||"/"!==e[t+n+1])&&t+n+1<e.length;)r+=e[t+n],n+=1;return t+n+1>=e.length?[n,["Error",r,void 0,`Unclosed multi-line comment at position ${t}`]]:(r+="*/",n+=2,[n,["MultiLineComment",r]])}return un},(e,t)=>{if("/"===e[t]&&"/"===e[t+1]){let n=2,r="//";for(;"\n"!==e[t+n]&&t+n<e.length;)r+=e[t+n],n+=1;return[n,["SingleLineComment",r]]}return un},(e,t)=>{const n=gn(e,t);if(0===n[0]||!n[1])return un;let r=n[1][1];r=r.startsWith("'")?r.slice(1,r.length-1):r;return void 0===_t[r]?un:[n[0],["ReservedSymbol",r]]},(e,t)=>ln("LParen","(",e,t),(e,t)=>ln("RParen",")",e,t),(e,t)=>ln("LBracket","[",e,t),(e,t)=>ln("RBracket","]",e,t),(e,t)=>ln("LBrace","{",e,t),(e,t)=>ln("RBrace","}",e,t),(e,t)=>{if('"'!==e[t]||'"'!==e[t+1]||'"'!==e[t+2])return un;let n='"""',r=3,i=e[t+r],s=e.slice(t+r,t+r+3),o=!1;for(;i&&('"""'!==s||o);)r+=1,o?(o=!1,n+=i):("\\"===i&&(o=!0),n+=i),i=e[t+r],s=e.slice(t+r,t+r+3);return i?(n+='"""',[r+3,["DocString",n]]):[r,["Error",n,void 0,`Unclosed doc string at position ${t}`]]},cn,(e,t)=>{if("#"!==e[t])return un;const[n,r]=cn(e,t+1);if(!r)return un;if("Error"===r[0]){return[n+1,["Error",`#${r[1]}`,void 0,`Unclosed regexp at position ${t}`]]}t+=n+1;let i=n+1,s="";for(;"g"===e[t]||"i"===e[t];)if(s+=e[t],i+=1,t+=1,s.includes(e[t]))return[i,["Error",`#${r[1]}${s}`,void 0,`Duplicated regexp option "${e[t]}"`]];return[i,["RegexpShorthand",`#${r[1]}${s}`]]},(e,t)=>{if("0"!==e[t])return un;const n=e[t+1],r="b"===n||"B"===n?"binary":"o"===n||"O"===n?"octal":"x"===n||"X"===n?"hex":null;if(null===r)return un;let i;for(i=t+2;i<e.length;i+=1){const t=e[i];if("binary"===r&&!dn.test(t))break;if("octal"===r&&!hn.test(t))break;if("hex"===r&&!pn.test(t))break}const s=i-t;if(s<=2)return un;const o=e[i];return o&&!yn.test(o)?un:[s,["BasePrefixedNumber",e.substring(t,i)]]},(e,t)=>{let n;const r="-"===e[t],i="+"===e[t],s=r||i?t+1:t;let o=!1,a=!1;for(n=s;n<e.length;n+=1){const r=e[n];if("_"===r){if(!fn.test(e[n-1])||!fn.test(e[n+1]))return n===s?un:[n-t+1,["Error",e.substring(t,n+1),void 0,`Invalid number format at position ${n+1}`]]}else if("."===r){if(n===s)return un;if(o||a)return[n-t+1,["Error",e.substring(t,n+1),void 0,`Invalid number format at position ${n+1}`]];o=!0}else if("e"===r||"E"===r){if(n===s)return un;if(a)return[n-t+1,["Error",e.substring(t,n+1),void 0,`Invalid number format at position ${n+1}`]];if("."===e[n-1]||"+"===e[n-1]||"-"===e[n-1])return[n-t+1,["Error",e.substring(t,n+1),void 0,`Invalid number format at position ${n+1}`]];"+"!==e[n+1]&&"-"!==e[n+1]||(n+=1),a=!0}else if(!fn.test(r))break}if((r||i)&&n===s)return un;const u=n-t;if(0===u)return un;const c=e[n];return c&&":"!==c&&!yn.test(c)?[n-t+1,["Error",e.substring(t,n+1),void 0,`Invalid number format at position ${n+1}`]]:[u,["Number",e.substring(t,n)]]},(e,t)=>{const n=e.slice(t,t+3);if(t+2<e.length&&tn(n))return[3,["Operator",n]];const r=e.slice(t,t+2);if(t+1<e.length&&tn(r))return[2,["Operator",r]];const i=e[t]??"";return tn(i)?[1,["Operator",i]]:un},gn];function vn(e,t,n){const r=e.substring(0,t+1).split(/\r\n|\r|\n/),i=r[r.length-1],s=function(e,t){return e.split(/\r\n|\r|\n/)[t]}(e,r.length-1);return{code:s,position:{line:r.length,column:i.length},filePath:n}}function bn(e,t){const n=t;if(0===t){const[r,i]=((e,t)=>{if("#"===e[t]&&"!"===e[t+1]){let n=2,r="#!";for(;"\n"!==e[t+n]&&t+n<e.length;)r+=e[t+n],n+=1;return[n,["SingleLineComment",r]]}return un})(e,t);if(t+=r,r>0)return[t-n,i]}for(const r of mn){const[i,s]=r(e,t);if(t+=i,0!==i)return[t-n,s]}return[1,["Error",e[n],void 0,"Unrecognized character"]]}function wn(e,t){return"Symbol"===e?.[0]&&(!t||e[1]===t)}function xn(e,t){return function(e,t){wn(e,t)||Ln("Symbol",void 0,e)}(e,t),e}function Sn(e,t){return"ReservedSymbol"===e?.[0]&&(!t||e[1]===t)}function kn(e,t){Sn(e,t)||Ln("ReservedSymbol",t,e)}function En(e,t){return kn(e,t),e}function Nn(e,t){return"Operator"===e?.[0]&&(!t||e[1]===t)}function An(e,t){Nn(e,t)||Ln("Operator",t,e)}function $n(e){return"LParen"===e?.[0]}function In(e){$n(e)||Ln("LParen",void 0,e)}function jn(e){return"RParen"===e?.[0]}function Cn(e){jn(e)||Ln("RParen",void 0,e)}function On(e){return"LBracket"===e?.[0]}function Fn(e){return function(e){On(e)||Ln("LBracket",void 0,e)}(e),e}function Mn(e){return"RBracket"===e?.[0]}function Un(e){Mn(e)||Ln("RBracket",void 0,e)}function Tn(e){return"LBrace"===e?.[0]}function Bn(e){return function(e){Tn(e)||Ln("LBrace",void 0,e)}(e),e}function Pn(e){return"RBrace"===e?.[0]}function Rn(e){return"String"===e?.[0]}function Dn(e){return"Operator"===e?.[0]&&Qt(e[1])}function Ln(e,t,n){const i=n?`${n[0]} '${n[1]}'`:"end of input";throw new r(`Unexpected token: ${i}, expected ${e}${t?` '${t}'`:""}`,n?.[2])}function _n(e,{removeWhiteSpace:t}){const n=e.tokens.filter(e=>!(function(e){return"SingleLineComment"===e?.[0]}(e)||function(e){return"MultiLineComment"===e?.[0]}(e)||function(e){return"Shebang"===e?.[0]}(e)||t&&function(e){return"Whitespace"===e?.[0]}(e)));return{...e,tokens:n}}const Vn=Object.entries(Xe).reduce((e,[t,n])=>(e[n]=t,e),[]),zn=Object.entries(Ft).reduce((e,[t,n])=>(e[n]=t,e),[]);function Jn(e){return et(e)?e[1]:nt(e)?Vn[e[1]]:zn[e[1]]}const Wn=/^\$([1-9]\d?)?$/;function qn(e,t){return t&&(e[2]=t),e}function Yn(e,t){switch(e){case"^":return 12;case"*":case"/":case"%":return 11;case"+":case"-":return 10;case"<<":case">>":case">>>":return 9;case"++":return 8;case"<":case"<=":case"≤":case">":case">=":case"≥":return 7;case"==":case"!=":case"≠":return 6;case"&":case"xor":case"|":return 5;case"&&":case"||":case"??":return 4;case"|>":return 2;default:throw new r(`Unknown binary operator: ${e}`,t)}}function Gn(e,t,n){const r=qn([o.NormalExpression,[e,t]],n);return nt(e)&&q(Ze[e[1]].arity,r[1][1].length,n),r}function Kn(e,t,n){return qn([o.NormalExpression,[[o.NormalBuiltinSymbol,Xe.get],[e,t]]],n)}function Xn(e,t,n,i,s){const a=e[1];switch(a){case"^":case"*":case"/":case"%":case"+":case"-":case"<<":case">>":case">>>":case"++":case"<":case"<=":case"≤":case">":case">=":case"≥":case"==":case"!=":case"≠":case"&":case"xor":case"|":case"|>":return Gn(t,[n,i],s);case"&&":case"||":case"??":return qn([o.SpecialExpression,[Ft[a],[n,i]]],s);default:throw new r(`Unknown binary operator: ${a}`,s)}}class Zn{tokenStream;parseState;constructor(e,t){this.tokenStream=e,this.parseState=t}peek(){return this.tokenStream.tokens[this.parseState.position]}peekSourceCodeInfo(){const e=this.peek();return e?e[2]:this.tokenStream.tokens.at(-1)?.[2]}peekAhead(e){return this.tokenStream.tokens[this.parseState.position+e]}advance(){this.parseState.position+=1}parse(){this.tokenStream.tokens.forEach(e=>{if("Error"===e[0])throw new r(e[3],e[2])});const e=[];for(;!this.isAtEnd();)if(e.push(this.parseExpression(0,!0)),Nn(this.peek(),";"))this.advance();else if(!this.isAtEnd())throw new r("Expected ;",this.peekSourceCodeInfo());return e}parseExpression(e=0,t=!1){const n=this.peek();let i;if(wn(n))switch(n[1]){case"let":return this.parseLet(n);case"if":case"unless":i=this.parseIfOrUnless(n);break;case"cond":i=this.parseCond(n);break;case"switch":i=this.parseSwitch(n);break;case"for":case"doseq":i=this.parseForOrDoseq(n);break;case"loop":i=this.parseLoop(n);break;case"try":i=this.parseTry(n)}else if(Sn(n,"do"))i=this.parseBlock()[0];else if(Sn(n,"export")){if(!t)throw new r("export is only allowed in module scope",n[2]);return this.parseExport(n)}i||=this.parseOperand();let s=this.peek();for(;!this.isAtExpressionEnd();){if(Dn(s)){const t=s[1],n=Yn(t,s[2]);if(n<=e&&(12!==n||12!==e))break;const r=qn(Ft[t]?[o.SpecialBuiltinSymbol,Ft[t]]:[o.NormalBuiltinSymbol,Xe[t]],s[2]);this.advance();i=Xn(s,r,i,this.parseExpression(n),s[2])}else if(wn(s)){if(!Zt(s[1]))break;const t=3;if(t<=e)break;const n=this.parseSymbol(),o=this.parseExpression(t);if(rt(n))throw new r("Special expressions are not allowed in binary functional operators",n[2]);i=Gn(n,[i,o],s[2])}else{if("?"!==s?.[1])break;{if(1<=e)break;this.advance();const t=this.parseExpression();if(!Nn(this.peek(),":"))throw new r("Expected :",this.peekSourceCodeInfo());this.advance();const n=this.parseExpression();i=qn([o.SpecialExpression,[Ft.if,[i,t,n]]],i[2])}}s=this.peek()}return i}asToken(e){if(!e)throw new r("Unexpected end of input",this.peekSourceCodeInfo());return e}parseOperand(){let e=this.parseOperandPart(),t=this.peek();for(;Nn(t,".")||On(t)||$n(t);)if("."===t[1]){this.advance();const n=this.asToken(this.peek());if(!wn(n))throw new r("Expected symbol",this.peekSourceCodeInfo());e=Kn(e,qn([o.String,n[1]],n[2]),t[2]),this.advance(),t=this.peek()}else if(On(t)){this.advance();const n=this.parseExpression();if(!Mn(this.peek()))throw new r("Expected closing bracket",this.peekSourceCodeInfo());e=Kn(e,n,t[2]),this.advance(),t=this.peek()}else $n(t)&&(e=this.parseFunctionCall(e),t=this.peek());return e}parseOperandPart(){const e=this.asToken(this.peek());if($n(e)){const e=this.parseState.position,t=this.parseLambdaFunction();if(t)return t;this.parseState.position=e,this.advance();const n=this.parseExpression();if(!jn(this.peek()))throw new r("Expected closing parenthesis",this.peekSourceCodeInfo());return this.advance(),n}if(Nn(e)){const t=e[1];if(Qt(t))return this.advance(),qn(void 0!==Ft[t]?[o.SpecialBuiltinSymbol,Ft[t]]:[o.NormalBuiltinSymbol,Xe[t]],e[2]);if("->"===t)return this.parseShorthandLamdaFunction();throw new r(`Illegal operator: ${t}`,e[2])}if(Tn(e))return this.parseObject();if(On(e))return this.parseArray();const t=e[0];switch(t){case"Number":case"BasePrefixedNumber":return this.parseNumber();case"String":return this.parseString(e);case"Symbol":{const e=this.parseState.position,t=this.parseLambdaFunction();return t||(this.parseState.position=e,this.parseSymbol())}case"ReservedSymbol":return this.parseReservedSymbol();case"RegexpShorthand":return this.parseRegexpShorthand();default:throw new r(`Unknown token type: ${t}`,e[2])}}parseObject(){const e=Bn(this.peek());this.advance();const t=[];for(;!this.isAtEnd()&&!Pn(this.peek());){if(Nn(this.peek(),"..."))this.advance(),t.push(qn([o.Spread,this.parseExpression()],this.peekSourceCodeInfo()));else{const e=this.peek();if(Rn(e)){const n=this.parseString(e);t.push(qn([o.String,n[1]],e[2]))}else if(wn(e)){const n=e[1].startsWith("'")?this.stringFromQuotedSymbol(e[1]):e[1];t.push(qn([o.String,n],e[2])),this.advance()}else{if(!On(e))throw new r("Expected key to be a symbol or a string",this.peekSourceCodeInfo());this.advance(),t.push(this.parseExpression()),Un(this.peek()),this.advance()}An(this.peek(),":"),this.advance(),t.push(this.parseExpression())}const e=this.peek();if(!Nn(e,",")&&!Pn(e))throw new r("Expected comma or closing brace",this.peekSourceCodeInfo());Nn(e,",")&&this.advance()}var n;return Pn(n=this.peek())||Ln("RBrace",void 0,n),this.advance(),qn([o.SpecialExpression,[Ft.object,t]],e[2])}parseArray(){const e=Fn(this.peek());this.advance();const t=[];for(;!this.isAtEnd()&&!Mn(this.peek());){Nn(this.peek(),"...")?(this.advance(),t.push(qn([o.Spread,this.parseExpression()],this.peekSourceCodeInfo()))):t.push(this.parseExpression());const e=this.peek();if(!Nn(e,",")&&!Mn(e))throw new r("Expected comma or closing parenthesis",this.peekSourceCodeInfo());Nn(e,",")&&this.advance()}return Un(this.peek()),this.advance(),qn([o.SpecialExpression,[Ft.array,t]],e[2])}parseFunctionCall(e){this.advance();const t=[];for(;!this.isAtEnd()&&!jn(this.peek());){Nn(this.peek(),"...")?(this.advance(),t.push(qn([o.Spread,this.parseExpression()],this.peekSourceCodeInfo()))):t.push(this.parseExpression());const e=this.peek();if(!Nn(e,",")&&!jn(e))throw new r("Expected comma or closing parenthesis",this.peek()?.[2]);Nn(e,",")&&this.advance()}if(!jn(this.peek()))throw new r("Expected closing parenthesis",this.peekSourceCodeInfo());if(this.advance(),!rt(e))return nt(e)||nt(e)?Gn(e,t,e[2]):qn([o.NormalExpression,[e,t]],e[2]);{const n=e[1];switch(q(Ut.specialExpressions[n].arity,t.length,e[2]),n){case Ft["||"]:case Ft["&&"]:case Ft.recur:case Ft.array:case Ft.object:case Ft["??"]:return qn([o.SpecialExpression,[n,t]],e[2]);case Ft["defined?"]:{const[r]=t;return qn([o.SpecialExpression,[n,r]],e[2])}case Ft.throw:{const[r]=t;return qn([o.SpecialExpression,[n,r]],e[2])}case Ft["0_lambda"]:case Ft["0_def"]:throw new r(`${n} is not allowed`,e[2]);default:throw new r(`Unknown special expression: ${n}`,e[2])}}}parseLambdaFunction(){const e=this.asToken(this.peek());if($n(e)&&wn(this.peekAhead(1))&&Nn(this.peekAhead(2),"->"))return null;try{const t=this.parseFunctionArguments();if(!Nn(this.peek(),"->"))return null;let n;this.advance();let r="";if(Sn(this.peek(),"do")){const e=this.parseBlock(!0);r=e[1],n=e[0][1][1]}else n=[this.parseExpression()];return qn([o.SpecialExpression,[Ft["0_lambda"],[t,n],r]],e[2])}catch{return null}}parseFunctionArguments(){const e=this.peek();if(wn(e))return[qn([at,[this.parseSymbol(),void 0]],e[2])];In(e),this.advance();let t=!1,n=!1;const i=[];for(;!this.isAtEnd()&&!jn(this.peek())&&!wn(this.peek(),"let");){if(t)throw new r("Rest argument must be last",this.peekSourceCodeInfo());const e=this.parseBindingTarget();if(void 0!==e[1][1]&&(n=!0),e[0]===ut&&(t=!0),n&&!e[1][1])throw new r("Default arguments must be last",this.peekSourceCodeInfo());if(i.push(e),!Nn(this.peek(),",")&&!jn(this.peek())&&!wn(this.peek(),"let"))throw new r("Expected comma or closing parenthesis",this.peekSourceCodeInfo());Nn(this.peek(),",")&&this.advance()}if(!jn(this.peek()))throw new r("Expected closing parenthesis",this.peekSourceCodeInfo());return this.advance(),i}parseShorthandLamdaFunction(){const e=this.asToken(this.peek());this.advance();const t=this.parseState.position;let n,i="";if(Sn(this.peek(),"do")){const e=this.parseBlock(!0);i=e[1],n=e[0][1][1]}else n=[this.parseExpression()];const s=this.parseState.position-1;let a=0,u="NOT_SET";for(let n=t;n<=s;n+=1){const t=this.tokenStream.tokens[n];if(wn(t)){const n=Wn.exec(t[1]);if(n){const t=n[1]??"1";if("1"===t){if(!n[1]&&"WITH_1"===u||n[1]&&"NAKED"===u)throw new r("Please make up your mind, either use $ or $1",e[2]);u=n[1]?"WITH_1":"NAKED"}if(a=Math.max(a,Number(t)),a>20)throw new r("Can't specify more than 20 arguments",e[2])}}}const c=[];for(let t=1;t<=a;t+=1)1===t&&"NAKED"===u?c.push(qn([at,[[o.UserDefinedSymbol,"$"],void 0]],e[2])):c.push(qn([at,[[o.UserDefinedSymbol,`$${t}`],void 0]],e[2]));return qn([o.SpecialExpression,[Ft["0_lambda"],[c,n],i]],e[2])}parseOptionalDefaulValue(){if(Nn(this.peek(),"="))return this.advance(),this.parseExpression()}parseBindingTarget({requireDefaultValue:e,noRest:t}={}){const n=this.peek();if(wn(n)){const t=this.parseSymbol();if(!et(t))throw new r("Expected user defined symbol",n[2]);const i=this.parseOptionalDefaulValue();if(e&&!i)throw new r("Expected assignment",this.peekSourceCodeInfo());return qn([at,[t,i]],n[2])}if(Nn(n,"...")){if(t)throw new r("Rest element not allowed",n[2]);this.advance();const e=tt(this.parseSymbol());if(Nn(this.peek(),"="))throw new r("Rest argument can not have default value",this.peekSourceCodeInfo());return qn([ut,[e[1],void 0]],n[2])}if(On(n)){this.advance();const t=[];let i=this.asToken(this.peek()),s=!1;for(;!Mn(i);){if(s)throw new r("Rest argument must be last",i[2]);if(Nn(i,",")){t.push(null),this.advance(),i=this.asToken(this.peek());continue}const e=this.parseBindingTarget();e[0]===ut&&(s=!0),t.push(e),i=this.asToken(this.peek()),Mn(i)||(An(i,","),this.advance()),i=this.asToken(this.peek())}this.advance();const o=this.parseOptionalDefaulValue();if(e&&!o)throw new r("Expected assignment",this.peekSourceCodeInfo());return qn([lt,[t,o]],n[2])}if(Tn(n)){this.advance();const t={};let i=this.asToken(this.peek()),s=!1;for(;!Pn(i);){if(s)throw new r("Rest argument must be last",i[2]);Nn(i,"...")&&(s=!0,this.advance());const e=this.parseSymbol(),o=Jn(e);if(i=this.asToken(this.peek()),Sn(i,"as")){if(s)throw new r("Rest argument can not have alias",i[2]);this.advance();const e=tt(this.parseSymbol());if(t[e[1]])throw new r(`Duplicate binding name: ${e}`,i[2]);t[o]=qn([at,[e,this.parseOptionalDefaulValue()]],n[2])}else if(Pn(i)||Nn(i,",")||Nn(i,"=")){const o=tt(e,e[2]);if(t[o[1]])throw new r(`Duplicate binding name: ${o}`,i[2]);if(s&&Nn(this.peek(),"="))throw new r("Rest argument can not have default value",this.peekSourceCodeInfo());t[o[1]]=qn(s?[ut,[o[1],this.parseOptionalDefaulValue()]]:[at,[o,this.parseOptionalDefaulValue()]],n[2])}else if(Nn(i,":")){if(this.advance(),i=this.asToken(this.peek()),!Tn(i)&&!On(i))throw new r("Expected object or array",i[2]);t[o]=this.parseBindingTarget()}Pn(this.peek())||(An(this.peek(),","),this.advance()),i=this.asToken(this.peek())}this.advance(),i=this.asToken(this.peek());const o=this.parseOptionalDefaulValue();if(e&&!o)throw new r("Expected assignment",i[2]);return qn([ct,[t,o]],n[2])}throw new r("Expected symbol",this.peekSourceCodeInfo())}parseLet(e){this.advance();const t=this.parseBindingTarget({requireDefaultValue:!0,noRest:!0}),n=t[1][1];t[1][1]=void 0;const r=qn([o.Binding,[t,n]],e[2]);return qn([o.SpecialExpression,[Ft.let,r]],e[2])}parseBlock(e=!1){const t=En(this.peek(),"do");this.advance();let n="";e&&function(e){return"DocString"===e?.[0]}(this.peek())&&(n=this.parseDocString());const i=[];for(;!this.isAtEnd()&&!Sn(this.peek(),"end");)if(i.push(this.parseExpression()),Nn(this.peek(),";"))this.advance();else if(!Sn(this.peek(),"end"))throw new r("Expected end",this.peekSourceCodeInfo());return kn(this.peek(),"end"),this.advance(),[qn([o.SpecialExpression,[Ft.block,i]],t[2]),n]}parseImplicitBlock(e){const t=[];for(;!this.isAtEnd()&&!this.isImplicitBlockEnd(e);)Nn(this.peek(),";")?this.advance():t.push(this.parseExpression());if(this.assertImplicitBlockEnd(e),0===t.length)throw new r("Expected expression",this.peekSourceCodeInfo());return 1===t.length?t[0]:qn([o.SpecialExpression,[Ft.block,t]],this.peekSourceCodeInfo())}assertImplicitBlockEnd(e){if(!this.isImplicitBlockEnd(e))throw new r(`Expected ${e.map(e=>e[1]).join(" or ")}`,this.peekSourceCodeInfo())}isImplicitBlockEnd(e){for(const t of e)if(Sn(this.peek(),t))return!0;return!1}parseLoop(e){this.advance(),In(this.peek()),this.advance();const t=[];let n=this.peek();for(;!this.isAtEnd()&&!jn(n);){const e=this.parseBindingTarget({requireDefaultValue:!0,noRest:!0}),r=e[1][1];e[1][1]=void 0,t.push(qn([o.Binding,[e,r]],e[2])),Nn(this.peek(),",")&&this.advance(),n=this.peek()}if(0===t.length)throw new r("Expected binding",this.peekSourceCodeInfo());Cn(n),this.advance(),An(this.peek(),"->"),this.advance();const i=this.parseExpression();return qn([o.SpecialExpression,[Ft.loop,t,i]],e[2])}parseTry(e){this.advance();const t=this.parseImplicitBlock(["catch"]);let n;this.advance(),$n(this.peek())&&(this.advance(),n=this.parseSymbol(),Cn(this.peek()),this.advance());const r=this.parseImplicitBlock(["end"]);return this.advance(),qn([o.SpecialExpression,[Ft.try,t,n,r]],e[2])}parseForOrDoseq(e){const t="doseq"===e[1];this.advance(),In(this.peek()),this.advance();const n=[];for(;!this.isAtEnd()&&!jn(this.peek());){const e=this.parseForLoopBinding(),t=n.flatMap(e=>Object.keys(dt(e[0][1][0]))),i=dt(e[0][1][0]);if(Object.keys(i).some(e=>t.includes(e)))throw new r("Duplicate binding",e[0][2]);n.push(e),Nn(this.peek(),",")&&this.advance()}Cn(this.peek()),this.advance(),An(this.peek(),"->"),this.advance();const i=this.parseExpression();return qn(t?[o.SpecialExpression,[Ft.doseq,n,i]]:[o.SpecialExpression,[Ft.for,n,i]],e[2])}parseForLoopBinding(){const e=this.parseBinding(),t=[];let n=this.asToken(this.peek());this.assertInternalLoopBindingDelimiter(n,["let","when","while"]);const i=[];if("let"===n[1])for(t.push("&let");wn(n,"let");){const e=this.parseLet(n),t=i.flatMap(e=>Object.keys(dt(e[1][0])));if(Object.keys(dt(e[1][1][1][0])).some(e=>t.includes(e)))throw new r("Duplicate binding",e[1][1][2]);i.push(e[1][1]),n=this.asToken(this.peek()),this.assertInternalLoopBindingDelimiter(n,["let","when","while"]),n=this.asToken(this.peek())}let s,o;for(;Sn(n,"when")||Sn(n,"while");){this.advance(),"when"===n[1]?(t.push("&when"),s=this.parseExpression()):(t.push("&while"),o=this.parseExpression()),n=this.asToken(this.peek());const e=t.includes("&when")&&t.includes("&while")?[]:t.includes("&when")?["while"]:["when"];this.assertInternalLoopBindingDelimiter(n,e),n=this.asToken(this.peek())}return this.assertInternalLoopBindingDelimiter(n,[]),[e,i,s,o]}assertInternalLoopBindingDelimiter(e,t){if(!this.isInternalLoopBindingDelimiter(e,t)){const n=`${[...t,","].map(e=>`"${e}"`).join(", ")} or ")"`;throw new r(`Expected symbol ${n}`,e[2])}}isInternalLoopBindingDelimiter(e,t){if(Nn(e,",")||jn(e))return!0;for(const n of t){if("let"===n&&wn(e,"let"))return!0;if(["when","while"].includes(n)&&Sn(e,n))return!0}return!1}parseBinding(){const e=xn(this.peek()),t=tt(this.parseSymbol());kn(this.peek(),"in"),this.advance();const n=this.parseExpression();return qn([o.Binding,[qn([at,[t,void 0]],e[2]),n]],e[2])}parseIfOrUnless(e){const t="unless"===e[1];this.advance();const n=this.parseExpression();kn(this.peek(),"then"),this.advance();const r=this.parseImplicitBlock(["else","end"]);let i;return Sn(this.peek(),"else")&&(this.advance(),i=this.parseImplicitBlock(["end"])),this.advance(),qn(t?[o.SpecialExpression,[Ft.unless,[n,r,i]]]:[o.SpecialExpression,[Ft.if,[n,r,i]]],e[2])}parseCond(e){this.advance();const t=[];for(;!this.isAtEnd()&&!Sn(this.peek(),"end");){kn(this.peek(),"case"),this.advance();const e=this.parseExpression();kn(this.peek(),"then"),this.advance();const n=this.parseImplicitBlock(["case","end"]);if(t.push([e,n]),Sn(this.peek(),"end"))break}return kn(this.peek()),this.advance(),qn([o.SpecialExpression,[Ft.cond,t]],e[2])}parseSwitch(e){this.advance();const t=this.parseExpression(),n=[];for(;!this.isAtEnd()&&!Sn(this.peek(),"end");){kn(this.peek(),"case"),this.advance();const e=this.parseExpression();kn(this.peek(),"then"),this.advance();const t=this.parseImplicitBlock(["case","end"]);if(n.push([e,t]),Sn(this.peek(),"end"))break}return kn(this.peek(),"end"),this.advance(),qn([o.SpecialExpression,[Ft.switch,t,n]],e[2])}isAtEnd(){return this.parseState.position>=this.tokenStream.tokens.length}isAtExpressionEnd(){if(this.isAtEnd())return!0;const e=this.peek();return Nn(e)?[";",",",":"].includes(e[1]):!!Sn(e)&&["else","when","while","case","catch","let","then","end","do"].includes(e[1])}parseExport(e){this.advance();const t=this.peek();if(wn(t,"let")){const n=this.parseLet(xn(t));return qn([o.SpecialExpression,[Ft["0_def"],n[1][1]]],e[2])}throw new r("Expected let",this.peekSourceCodeInfo())}stringToSymbolNode(e,t){return void 0!==Ft[e]&&"fn"!==e&&"def"!==e&&"defn"!==e?qn([o.SpecialBuiltinSymbol,Ft[e]],t):void 0!==Xe[e]?qn([o.NormalBuiltinSymbol,Xe[e]],t):qn([o.UserDefinedSymbol,e],t)}stringFromQuotedSymbol(e){return e.substring(1,e.length-1).replace(/(\\{2})|(\\')|\\(.)/g,(e,t,n,r)=>t?"\\":n?"'":`\\${r}`)}parseSymbol(){const e=this.asToken(this.peek());if(this.advance(),!wn(e))throw new r(`Expected symbol token, got ${e[0]}`,e[2]);return"'"===e[1][0]?this.stringToSymbolNode(this.stringFromQuotedSymbol(e[1]),e[2]):this.stringToSymbolNode(e[1],e[2])}parseReservedSymbol(){const e=En(this.peek());this.advance();const t=e[1];return function(e){return e in Lt}(t)?qn([o.Number,Lt[t]],e[2]):qn([o.ReservedSymbol,e[1]],e[2])}parseNumber(){const e=this.asToken(this.peek());this.advance();const t=e[1],n="-"===t[0],r=(n?t.substring(1):t).replace(/_/g,"");return qn([o.Number,n?-Number(r):Number(r)],e[2])}parseDocString(){const e=this.asToken(this.peek()),t=e[2]?["String",e[1].slice(2,-2),e[2]]:["String",e[1].slice(2,-2)];return fe(this.parseString(t)[1])}parseString(e){this.advance();const t=e[1].substring(1,e[1].length-1).replace(/(\\{2})|(\\")|(\\n)|(\\t)|(\\r)|(\\b)|(\\f)|\\(.)/g,(e,t,n,r,i,s,o,a,u)=>t?"\\":r?"\n":i?"\t":s?"\r":o?"\b":a?"\f":n?'"':u);return qn([o.String,t],e[2])}parseRegexpShorthand(){const e=this.asToken(this.peek());this.advance();const t=e[1].lastIndexOf('"'),n=e[1].substring(2,t),r=e[1].substring(t+1),i=qn([o.String,n],e[2]),s=qn([o.String,r],e[2]);return qn([o.NormalExpression,[qn([o.NormalBuiltinSymbol,Xe.regexp],e[2]),[i,s]]],e[2])}}const Hn=new Set([...Tt,...Bt,...Object.keys(_t)]);class Qn{originalProgram;originalPosition;prefixProgram="";suffixProgram="";searchString="";suggestions=[];suggestionIndex=null;constructor(e,t,n,r){this.originalProgram=e,this.originalPosition=t;const i=this.originalProgram.slice(0,this.originalPosition),s=n.tokenize(i).tokens.at(-1);s&&"Error"!==s[0]&&(this.searchString=s[1],this.prefixProgram=this.originalProgram.slice(0,this.originalPosition-this.searchString.length),this.suffixProgram=this.originalProgram.slice(this.prefixProgram.length+this.searchString.length),this.originalProgram.slice(this.prefixProgram.length+this.searchString.length),this.suggestions=this.generateSuggestions(r))}getNextSuggestion(){return this.getAutoCompleteSuggestionResult(this.getNextSuggestionSymbol())}getPreviousSuggestion(){return this.getAutoCompleteSuggestionResult(this.getPreviousSuggestionSymbol())}getAutoCompleteSuggestionResult(e){return null===e?null:{program:this.prefixProgram+e+this.suffixProgram,position:this.prefixProgram.length+e.length}}getNextSuggestionSymbol(){return 0===this.suggestions.length?null:(null===this.suggestionIndex?this.suggestionIndex=0:(this.suggestionIndex+=1,this.suggestionIndex>=this.suggestions.length&&(this.suggestionIndex=0)),this.suggestions[this.suggestionIndex])}getPreviousSuggestionSymbol(){return 0===this.suggestions.length?null:(null===this.suggestionIndex?this.suggestionIndex=this.suggestions.length-1:(this.suggestionIndex-=1,this.suggestionIndex<0&&(this.suggestionIndex=this.suggestions.length-1)),this.suggestions[this.suggestionIndex])}getSuggestions(){return[...this.suggestions]}getSearchString(){return this.searchString}generateSuggestions(e){const t=new Set(["0_def","0_defn","0_lambda"]),n=this.generateWithPredicate(e,e=>!t.has(e)&&e.startsWith(this.searchString));n.forEach(e=>t.add(e));const r=this.generateWithPredicate(e,e=>!t.has(e)&&e.toLowerCase().startsWith(this.searchString.toLowerCase()));r.forEach(e=>t.add(e));const i=this.generateWithPredicate(e,e=>!t.has(e)&&e.includes(this.searchString));i.forEach(e=>t.add(e));const s=this.generateWithPredicate(e,e=>!t.has(e)&&e.includes(this.searchString.toLowerCase()));return s.forEach(e=>t.add(e)),[...n,...r,...i,...s]}generateWithPredicate(e,t){const n=new Set;return Hn.forEach(e=>{t(e)&&n.add(e)}),Object.keys(e.globalContext??{}).filter(t).forEach(e=>n.add(e)),e.contexts?.forEach(e=>{Object.keys(e).filter(t).forEach(e=>n.add(e))}),Object.keys(e.jsFunctions??{}).filter(t).forEach(e=>n.add(e)),Object.keys(e.values??{}).filter(t).forEach(e=>n.add(e)),[...n].sort((e,t)=>e.localeCompare(t))}}class er{cache={};firstEntry=void 0;lastEntry=void 0;_size=0;maxSize;constructor(e){if(this.maxSize=null===e?null:ie(e),"number"==typeof this.maxSize&&this.maxSize<1)throw new Error(`1 is the minimum maxSize, got ${d(e)}`)}getContent(){return Object.entries(this.cache).reduce((e,[t,n])=>(e[t]=n.value,e),{})}get size(){return this._size}get(e){return this.cache[e]?.value}clear(){this.cache={},this.firstEntry=void 0,this.lastEntry=void 0,this._size=0}has(e){return!!this.cache[e]}set(e,t){if(this.has(e))throw new Error(`AstCache - key already present: ${e}`);const n={value:t,nextEntry:void 0,key:e};for(this.cache[e]=n,this._size+=1,this.lastEntry&&(this.lastEntry.nextEntry=n),this.lastEntry=n,this.firstEntry||(this.firstEntry=this.lastEntry);null!==this.maxSize&&this.size>this.maxSize;)this.dropFirstEntry()}dropFirstEntry(){const e=this.firstEntry;delete this.cache[e.key],this._size-=1,this.firstEntry=e.nextEntry}}return e.Lits=class{astCache;astCacheSize;debug;modules;constructor(e={}){if(this.debug=e.debug??!1,this.astCacheSize=e.astCacheSize??null,this.astCacheSize){this.astCache=new er(this.astCacheSize);const t=e.initialCache??{};for(const e of Object.keys(t))this.astCache.set(e,t[e])}else this.astCache=null;const t=e.modules??[];this.modules=new Map(t.map(e=>[e.name,e]))}getRuntimeInfo(){return{astCacheSize:this.astCacheSize,astCache:this.astCache,debug:this.debug}}run(e,t={}){const n=this.generateAst(e,t);return this.evaluate(n,t)}context(e,t={}){const n="string"==typeof e?this.generateAst(e,t):e,r=Yt(t,this.modules);return zt(n,r),r.globalContext}getUndefinedSymbols(e,t={}){const n="string"==typeof e?this.generateAst(e,t):e,r=Yt(t,this.modules);return Pt(n,r,Ut,Jt)}tokenize(e,t={}){const n=function(e,t,n){let r=0;const i={tokens:[],filePath:n,hasDebugData:t};for(;r<e.length;){const s=t?vn(e,r,n):void 0,o=bn(e,r),[a,u]=o;r+=a,u&&(s&&(u[2]=s),i.tokens.push(u))}return i}(e,this.debug,t.filePath);return t.minify?_n(n,{removeWhiteSpace:!1}):n}parse(e){const t={body:[],hasDebugData:(e=_n(e,{removeWhiteSpace:!0})).hasDebugData};return t.body=new Zn(e,{position:0}).parse(),t}evaluate(e,t){return zt(e,Yt(t,this.modules))}transformSymbols(e,t){return function(e,t){return{...e,tokens:e.tokens.map(e=>wn(e)?[e[0],t(e[1])]:e)}}(e,t)}untokenize(e){return function(e){return e.tokens.reduce((e,t)=>`${e}${t[1]}`,"")}(e)}apply(e,t,n={}){const r="FN_2eb7b316_471c_5bfa_90cb_d3dfd9164a59",i=this.generateApplyFunctionCall(r,t),s=this.generateAst(i,n),o=t.reduce((e,t,n)=>(e[`${r}_${n}`]=t,e),{[r]:e});return n.values={...n.values,...o},this.evaluate(s,n)}generateApplyFunctionCall(e,t){const n=t.map((t,n)=>`${e}_${n}`).join(", ");return`${e}(${n})`}generateAst(e,t){if(this.astCache){const t=this.astCache.get(e);if(t)return t}const n=this.tokenize(e,{filePath:t.filePath}),r=this.parse(n);return this.astCache?.set(e,r),r}getAutoCompleter(e,t,n={}){return new Qn(e,t,this,n)}},e.asLitsFunction=function(e,t){return x(e,t),e},e.asNativeJsFunction=function(e,t){return N(e,t),e},e.asUserDefinedFunction=function(e,t){return k(e,t),e},e.assertLitsFunction=x,e.assertNativeJsFunction=N,e.assertUserDefinedFunction=k,e.isBuiltinFunction=function(e){return b(e)&&"Builtin"===e.functionType},e.isGrid=je,e.isLitsError=function(e){return e instanceof r},e.isLitsFunction=w,e.isMatrix=Ce,e.isNativeJsFunction=E,e.isUserDefinedFunction=S,e.isVector=Ie,e.normalExpressionKeys=Tt,e.specialExpressionKeys=Bt,e}({});
1
+ var Lits=function(e){"use strict";function t(e){if(!e.position||!e.code)return"";const t=e.position.column-1,n=e.code.length-t-1;return`${" ".repeat(Math.max(t,0))}^${" ".repeat(Math.max(n,0))}`}class n extends Error{params;constructor(e){super(`recur, params: ${e}`),Object.setPrototypeOf(this,n.prototype),this.name="RecurSignal",this.params=e}}class r extends Error{sourceCodeInfo;shortMessage;constructor(e,n){const i=e instanceof Error?e.message:`${e}`;super(function(e,n){if(!n)return e;const r=`${n.position.line}:${n.position.column}`;return`${e}${n.filePath?`\n${n.filePath}:${r}`:`\nLocation ${r}`}\n${n.code}\n${t(n)}`}(i,n)),this.shortMessage=i,this.sourceCodeInfo=n,Object.setPrototypeOf(this,r.prototype),this.name="LitsError"}getCodeMarker(){return this.sourceCodeInfo&&t(this.sourceCodeInfo)}}class i extends r{userMessage;constructor(e,t){super(e,t),this.userMessage=e,Object.setPrototypeOf(this,i.prototype),this.name="UserDefinedError"}}class s extends r{symbol;constructor(e,t){super(`Undefined symbol '${e}'.`,t),this.symbol=e,Object.setPrototypeOf(this,s.prototype),this.name="UndefinedSymbolError"}}const o={Number:1,String:2,NormalExpression:3,SpecialExpression:4,UserDefinedSymbol:5,NormalBuiltinSymbol:6,SpecialBuiltinSymbol:7,ReservedSymbol:8,Binding:9,Spread:10},a=new Set(Object.values(o));function u(e){return Object.keys(o).find(t=>o[t]===e)}const c=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);const l="^^fn^^",f="^^re^^";function h(e){return null!==e&&"object"==typeof e&&(l in e&&"functionType"in e&&function(e){return"string"==typeof e&&c.has(e)}(e.functionType))}function p(e){return!(!Array.isArray(e)||e.length<2)&&function(e){return"number"==typeof e&&a.has(e)}(e[0])}function d(e){return h(e)?`<function ${e.name||"λ"}>`:p(e)?`${u(e[0])}-node`:null===e?"null":"object"==typeof e&&e instanceof RegExp?`${e}`:"object"==typeof e&&e instanceof Error?e.toString():JSON.stringify(e)}function g(e,t){return e?.sourceCodeInfo??t}function m(e,t,n){return new r(`Expected ${e}, got ${d(t)}.`,g(t,n))}function y(e,t){return v(e,t),e}function v(e,t){if(!function(e){return void 0!==e}(e))throw new r("Unexpected undefined",g(e,t))}function b(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function w(e){return null!==e&&"object"==typeof e&&!!e[l]}function S(e,t){if(!w(e))throw m("LitsFunction",e,t)}function k(e){return w(e)&&"UserDefined"===e.functionType}function x(e,t){if(!k(e))throw m("NativeJsFunction",e,t)}function E(e){return w(e)&&"NativeJsFunction"===e.functionType}function N(e,t){if(!E(e))throw m("NativeJsFunction",e,t)}function $(e,t={}){return"number"==typeof e&&(!Number.isNaN(e)&&(!(t.integer&&!Number.isInteger(e))&&(!(t.finite&&!Number.isFinite(e))&&((!t.zero||0===e)&&((!t.nonZero||0!==e)&&(!(t.positive&&e<=0)&&(!(t.negative&&e>=0)&&(!(t.nonPositive&&e>0)&&(!(t.nonNegative&&e<0)&&(!("number"==typeof t.gt&&e<=t.gt)&&(!("number"==typeof t.gte&&e<t.gte)&&(!("number"==typeof t.lt&&e>=t.lt)&&!("number"==typeof t.lte&&e>t.lte)))))))))))))}function I(e,t,n={}){if(!$(e,n))throw new r(`Expected ${function(e){if(e.zero)return"zero";const t=function(e){return e.positive?"positive":e.negative?"negative":e.nonNegative?"non negative":e.nonPositive?"non positive":e.nonZero?"non zero":""}(e),n=e.integer?"integer":"number",r=e.finite?"finite":"",i=function(e){return"number"!=typeof e.gt&&"number"!=typeof e.gte||"number"!=typeof e.lt&&"number"!=typeof e.lte?"number"==typeof e.gt||"number"==typeof e.gte?"number"==typeof e.gt?`n > ${e.gt}`:`n >= ${e.gte}`:"number"==typeof e.lt||"number"==typeof e.lte?"number"==typeof e.lt?`n < ${e.lt}`:`n <= ${e.lte}`:"":`${"number"==typeof e.gt?`${e.gt} < n `:`${e.gte} <= n `}${"number"==typeof e.lt?`< ${e.lt}`:`<= ${e.lte}`}`}(e);return[t,r,n,i].filter(e=>!!e).join(" ")}(n)}, got ${d(e)}.`,g(e,t))}function A(e){return void 0!==e}function j(e,t){return O(e,t),e}function O(e,t){if(!A(e))throw m("not undefined",e,t)}function C(e){return Array.isArray(e)||"string"==typeof e}function F(e,t){if(!C(e))throw m("string or array",e,t)}function U(e){return!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof RegExp||w(e)||D(e))}function T(e,t){if(!U(e))throw m("object",e,t)}function B(e){return C(e)||U(e)}function P(e,t){return M(e,t),e}function M(e,t){if(!B(e))throw m("string, array or object",e,t)}function D(e){return null!==e&&"object"==typeof e&&!!e[f]}function R(e,t){if(!function(e){return D(e)||"string"==typeof e}(e))throw m("string or RegularExpression",e,t)}function _(e,t){return L(e,t),e}function L(e,t){if(!function(e){return"number"==typeof e||!!B(e)||!!w(e)}(e))throw m("FunctionLike",e,t)}function V(e,t){const{min:n}=e;return!("number"==typeof n&&t<n)}function z(e,t,n){const{min:i,max:s}=e;if("number"==typeof i&&t<i)throw new r(`Wrong number of arguments, expected at least ${i}, got ${d(t)}.`,n);if("number"==typeof s&&t>s)throw new r(`Wrong number of arguments, expected at most ${s}, got ${d(t)}.`,n)}function J(e){return{min:e,max:e}}const W={"<<":{evaluate:([e,t],n)=>(I(e,n,{integer:!0}),I(t,n,{integer:!0,nonNegative:!0}),e<<t),arity:J(2)},">>":{evaluate:([e,t],n)=>(I(e,n,{integer:!0}),I(t,n,{integer:!0,nonNegative:!0}),e>>t),arity:J(2)},">>>":{evaluate:([e,t],n)=>(I(e,n,{integer:!0}),I(t,n,{integer:!0,nonNegative:!0}),e>>>t),arity:J(2)},"&":{evaluate:([e,...t],n)=>(I(e,n,{integer:!0}),t.reduce((e,t)=>(I(t,n,{integer:!0}),e&t),e)),arity:{min:2}},"|":{evaluate:([e,...t],n)=>(I(e,n,{integer:!0}),t.reduce((e,t)=>(I(t,n,{integer:!0}),e|t),e)),arity:{min:2}},xor:{evaluate:([e,...t],n)=>(I(e,n,{integer:!0}),t.reduce((e,t)=>(I(t,n,{integer:!0}),e^t),e)),arity:{min:2}}};function q(e,t={}){return"string"==typeof e&&((!t.nonEmpty||0!==e.length)&&(!t.char||1===e.length))}function Y(e,t,n={}){if(!q(e,n))throw m(""+(n.nonEmpty?"non empty string":n.char?"character":"string"),e,t)}function G(e,t,n={}){return Y(e,t,n),e}function K(e){return"string"==typeof e||"number"==typeof e}function X(e,t){return Z(e,t),e}function Z(e,t){if(!K(e))throw m("string or number",e,t)}function H(e,t){return!!B(e)&&("string"==typeof e||Array.isArray(e)?!!$(t,{integer:!0})&&(t>=0&&t<e.length):!!Object.getOwnPropertyDescriptor(e,t))}function Q(e,t,n){if(Z(e,n),Z(t,n),"string"==typeof e&&"string"==typeof t)return e<t?-1:e>t?1:0;if("number"==typeof e&&"number"==typeof t)return Math.sign(e-t);throw new r(`Cannot compare values of different types: ${typeof e} and ${typeof t}`,n)}function ee(e,t,n){if(e===t)return!0;if("number"==typeof e&&"number"==typeof t)return function(e,t,n=ie){if(e===t)return!0;const r=Math.abs(e-t);if(0===e||0===t||r<n)return r<n;const i=Math.abs(e),s=Math.abs(t);return r/(i+s)<n}(e,t);if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r+=1)if(!ee(j(e[r],n),j(t[r],n),n))return!1;return!0}if(D(e)&&D(t))return e.s===t.s&&e.f===t.f;if(b(e)&&b(t)){const r=Object.keys(e),i=Object.keys(t);if(r.length!==i.length)return!1;for(let i=0;i<r.length;i+=1){const s=G(r[i],n);if(!ee(e[s],t[s],n))return!1}return!0}return!1}function te(e){return e??null}function ne(...e){const t=new Set;for(const n of e)n.forEach(e=>t.add(e));return t}function re(e,t){t.forEach(t=>e.add(t))}const ie=1e-10;function se(e,t=0){const n=e.split("\n");for(;n[0]?.match(/^\s*$/);)n.shift();for(;n[n.length-1]?.match(/^\s*$/);)n.pop();const r=n.reduce((e,t)=>{if(t.match(/^\s*$/))return e;const n=t.match(/^\s*/)[0].length;return Math.min(e,n)},1/0);return n.map(e=>" ".repeat(t)+e.slice(r)).join("\n").trimEnd()}function oe(e,t){if(!Array.isArray(e))throw m("array",e,t)}function ae(e,t){if(!function(e){return Array.isArray(e)&&e.every(e=>"string"==typeof e)}(e))throw m("array of strings",e,t)}function ue(e,t){if(!function(e){return Array.isArray(e)&&e.every(e=>"string"==typeof e&&1===e.length)}(e))throw m("array of strings",e,t)}const ce={filter:{evaluate:([e,t],n,r,{executeFunction:i})=>{if(M(e,n),L(t,n),Array.isArray(e)){return e.filter(e=>i(t,[e],r,n))}return q(e)?e.split("").filter(e=>i(t,[e],r,n)).join(""):Object.entries(e).filter(([,e])=>i(t,[e],r,n)).reduce((e,[t,n])=>(e[t]=n,e),{})},arity:J(2)},map:{evaluate:(e,t,n,{executeFunction:i})=>{const s=_(e.at(-1),t);if(U(e[0]))return function({colls:e,contextStack:t,executeFunction:n,fn:i,sourceCodeInfo:s}){T(e[0],s);const o=Object.keys(e[0]),a={};return e.forEach(e=>{T(e,s);const t=Object.keys(e);if(t.length!==o.length)throw new r(`All objects must have the same keys. Expected: ${o.join(", ")}. Found: ${t.join(", ")}`,s);if(!t.every(e=>o.includes(e)))throw new r(`All objects must have the same keys. Expected: ${o.join(", ")}. Found: ${t.join(", ")}`,s);Object.entries(e).forEach(([e,t])=>{a[e]||(a[e]=[]),a[e].push(t)})}),o.reduce((e,r)=>(e[r]=n(i,a[r],t,s),e),{})}({colls:e.slice(0,-1),fn:s,sourceCodeInfo:t,contextStack:n,executeFunction:i});const o=e.slice(0,-1);F(o[0],t);const a="string"==typeof o[0];let u=o[0].length;o.slice(1).forEach(e=>{a?Y(e,t):oe(e,t),u=Math.min(u,e.length)});const c=[];for(let e=0;e<u;e++)c.push(o.map(t=>t[e]));const l=c.map(e=>i(s,e,n,t));return a?(l.forEach(e=>Y(e,t)),l.join("")):l},arity:{min:2}},reduce:{evaluate:([e,t,n],r,i,{executeFunction:s})=>(M(e,r),L(t,r),O(n,r),"string"==typeof e?(Y(n,r),0===e.length?n:e.split("").reduce((e,n)=>s(t,[e,n],i,r),n)):Array.isArray(e)?0===e.length?n:e.reduce((e,n)=>s(t,[e,n],i,r),n):0===Object.keys(e).length?n:Object.entries(e).reduce((e,[,n])=>s(t,[e,n],i,r),n)),arity:J(3)},get:{evaluate:(e,t)=>{const[n,r]=e,i=te(e[2]);if(Z(r,t),null===n)return i;M(n,t);const s=function(e,t){if(U(e)){if("string"==typeof t&&H(e,t))return te(e[t])}else if($(t,{nonNegative:!0,integer:!0})&&t>=0&&t<e.length)return te(e[t])}(n,r);return void 0===s?i:s},arity:{min:2,max:3}},count:{evaluate:([e],t)=>null===e?0:"string"==typeof e?e.length:(M(e,t),Array.isArray(e)?e.length:Object.keys(e).length),arity:J(1)},"contains?":{evaluate:([e,t],n)=>null!==e&&(M(e,n),q(e)?(Y(t,n),e.includes(t)):C(e)?(O(t,n),!!e.find(e=>ee(j(e),t,n))):(Y(t,n),t in e)),arity:J(2)},assoc:{evaluate:([e,t,n],r)=>(M(e,r),Z(t,r),O(n,r),function(e,t,n,r){if(M(e,r),Z(t,r),Array.isArray(e)||"string"==typeof e){if(I(t,r,{integer:!0}),I(t,r,{gte:0}),I(t,r,{lte:e.length}),"string"==typeof e)return Y(n,r,{char:!0}),`${e.slice(0,t)}${n}${e.slice(t+1)}`;const i=[...e];return i[t]=n,i}Y(t,r);const i={...e};return i[t]=n,i}(e,t,n,r)),arity:J(3)},"++":{evaluate:(e,t)=>($(e[0])||M(e[0],t),Array.isArray(e[0])?e.reduce((e,n)=>(oe(n,t),e.concat(n)),[]):K(e[0])?e.reduce((e,n)=>(Z(n,t),`${e}${n}`),""):e.reduce((e,n)=>(T(n,t),Object.assign(e,n)),{})),arity:{min:1}}},le={range:{evaluate:(e,t)=>{const[n,r,i]=e;let s,o,a;I(n,t,{finite:!0}),1===e.length?(s=0,o=n,a=o>=0?1:-1):2===e.length?(I(r,t,{finite:!0}),s=n,o=r,a=o>=s?1:-1):(I(r,t,{finite:!0}),I(i,t,{finite:!0}),s=n,o=r,a=i,I(a,t,o>s?{positive:!0}:o<s?{negative:!0}:{nonZero:!0}));const u=[];for(let e=s;a<0?e>o:e<o;e+=a)u.push(e);return u},arity:{min:1,max:3}},repeat:{evaluate:([e,t],n)=>{I(t,n,{integer:!0,nonNegative:!0});const r=[];for(let n=0;n<t;n+=1)r.push(e);return r},arity:J(2)},flatten:{evaluate:([e,t],n)=>{oe(e,n);const r=void 0===t||t===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:function(e,t,n={}){return I(e,t,n),e}(t,n,{integer:!0,nonNegative:!0});return e.flat(r)},arity:{min:1,max:2}},mapcat:{evaluate:([e,t],n,r,{executeFunction:i})=>(oe(e,n),L(t,n),e.map(e=>i(t,[e],r,n)).flat(1)),arity:J(2)},"moving-fn":{evaluate:([e,t,n],r,i,{executeFunction:s})=>{oe(e,r),I(t,r,{integer:!0,lte:e.length}),L(n,r);const o=[];for(let a=0;a<=e.length-t;a++){const u=s(n,[e.slice(a,a+t)],i,r);o.push(u)}return o},arity:J(3)},"running-fn":{evaluate:([e,t],n,r,{executeFunction:i})=>{oe(e,n),L(t,n);const s=[];for(let o=0;o<e.length;o+=1){const a=e.slice(0,o+1);s.push(i(t,[a],r,n))}return s},arity:J(2)}},fe={nth:{evaluate:(e,t)=>{const[n,r]=e,i=te(e[2]);if(I(r,t,{integer:!0}),null===n)return i;if(F(n,t),r>=0&&r<n.length){return te(n[r])}return i},arity:{min:2,max:3}},first:{evaluate:([e],t)=>{if(null===e)return null;F(e,t);return te(e[0])},arity:J(1)},last:{evaluate:([e],t)=>{if(null===e)return null;F(e,t);return te(e.at(-1))},arity:J(1)},pop:{evaluate:([e],t)=>(F(e,t),"string"==typeof e?e.substring(0,e.length-1):e.slice(0,e.length-1)),arity:J(1)},"index-of":{evaluate:([e,t],n)=>{if(O(t,n),null===e)return null;if(F(e,n),"string"==typeof e){Y(t,n);const r=e.indexOf(t);return-1!==r?r:null}{const r=e.findIndex(e=>ee(j(e,n),t),n);return-1!==r?r:null}},arity:J(2)},push:{evaluate:([e,...t],n)=>(F(e,n),"string"==typeof e?(ue(t,n),[e,...t].join("")):[...e,...t]),arity:{min:2}},rest:{evaluate:([e],t)=>(F(e,t),Array.isArray(e)?e.length<=1?[]:e.slice(1):e.substring(1)),arity:J(1)},next:{evaluate:([e],t)=>(F(e,t),Array.isArray(e)?e.length<=1?null:e.slice(1):e.length<=1?null:e.substring(1)),arity:J(1)},reverse:{evaluate:([e],t)=>null===e?null:(F(e,t),Array.isArray(e)?[...e].reverse():e.split("").reverse().join("")),arity:J(1)},second:{evaluate:([e],t)=>null===e?null:(F(e,t),te(e[1])),arity:J(1)},slice:{evaluate:(e,t)=>{const[n,r,i]=e;return F(n,t),I(r,t,{integer:!0}),2===e.length?(Array.isArray(n),n.slice(r)):(I(i,t,{integer:!0}),Array.isArray(n),n.slice(r,i))},arity:{min:2,max:3}},some:{evaluate:([e,t],n,r,{executeFunction:i})=>(L(t,n),null===e?null:(F(e,n),0===e.length?null:"string"==typeof e?e.split("").find(e=>i(t,[e],r,n))??null:te(e.find(e=>i(t,[e],r,n))))),arity:J(2)},sort:{evaluate:(e,t,n,{executeFunction:r})=>{const[i]=e,s=1===e.length,o=s?null:e[1];if(F(i,t),"string"==typeof i){const e=i.split("");return s?e.sort((e,n)=>Q(e,n,t)):(L(o,t),e.sort((e,i)=>{const s=r(o,[e,i],n,t);return I(s,t,{finite:!0}),s})),e.join("")}const a=[...i];return s?a.sort((e,n)=>(Z(e,t),Z(n,t),Q(e,n,t))):a.sort((e,i)=>{L(o,t);const s=r(o,[e,i],n,t);return I(s,t,{finite:!0}),s}),a},arity:{min:1,max:2}}},he=new WeakSet,pe=new WeakSet,de=new WeakSet,ge=new WeakSet,me=new WeakSet,ye=new WeakSet,ve=new WeakSet;function be(e){return Array.isArray(e)?(he.has(e)||(we(e),Ee(e)||xe(e)),e):e}function we(e){return!!Array.isArray(e)&&(!!pe.has(e)||!de.has(e)&&(e.every(e=>$(e))?(he.add(e),pe.add(e),!0):(de.add(e),!1)))}function Se(e,t){if(!we(e))throw new r(`Expected a vector, but got ${e}`,t)}function ke(e,t){if(Se(e,t),0===e.length)throw new r(`Expected a non empty vector, but got ${e}`,t)}function xe(e){if(!Array.isArray(e))return!1;if(ye.has(e))return!0;if(ve.has(e))return!1;if(0===e.length)return ve.add(e),!1;if(!Array.isArray(e[0]))return ve.add(e),!1;const t=e[0].length;for(const n of e.slice(1)){if(!Array.isArray(n))return ve.add(e),!1;if(n.length!==t)return ve.add(e),!1}return he.add(e),ye.add(e),!0}function Ee(e){if(!Array.isArray(e))return!1;if(ge.has(e))return!0;if(me.has(e))return!1;if(0===e.length)return me.add(e),!1;if(!Array.isArray(e[0])||0===e[0].length)return me.add(e),!1;const t=e[0].length;for(const n of e)if(!Array.isArray(n)||n.length!==t||n.some(e=>!$(e)))return me.add(e),!1;return he.add(e),ye.add(e),ge.add(e),!0}function Ne(e,t){let n=!1,i=!1;for(const s of e)if(we(s))n=!0;else if(Ee(s))i=!0;else if(!$(s))throw new r("Invalid parameter type: "+typeof s,t);if(i){if(n)throw new r("Cannot mix vector and matrix types",t);let i=null,s=null;for(const n of e)if(Ee(n))if(null===i)i=n.length,s=n[0].length;else if(n.length!==i||n[0].length!==s)throw new r("Matrix dimensions do not match",t);return["matrix",e.map(e=>Ee(e)?e:Array.from({length:i},()=>Array.from({length:s},()=>e)))]}if(n){let n=null;for(const i of e)if(we(i))if(null===n)n=i.length;else if(i.length!==n)throw new r("Vector lengths do not match",t);return["vector",e.map(e=>we(e)?e:Array.from({length:n},()=>e))]}return["number",e]}function $e(e){return(t,n)=>{const[r,i]=Ne(t,n);return"number"===r?e(i[0]):"vector"===r?i[0].map(t=>e(t)):i[0].map(t=>t.map(t=>e(t)))}}function Ie(e){return(t,n)=>{const[r,i]=Ne(t,n);return"number"===r?e(i[0],i[1]):"vector"===r?i[0].map((t,n)=>e(t,i[1][n])):i[0].map((t,n)=>t.map((t,r)=>e(t,i[1][n][r])))}}function Ae(e,t){return(n,r)=>{if(0===n.length)return e;const[i,s]=Ne(n,r);if("number"===i)return s.reduce((e,n)=>t(e,n),e);if("vector"===i){const[e,...n]=s;return n.reduce((e,n)=>e.map((e,r)=>t(e,n[r])),e)}{const[e,...n]=s;return n.reduce((e,n)=>e.map((e,r)=>e.map((e,i)=>t(e,n[r][i]))),e)}}}const je={inc:{evaluate:$e(e=>e+1),arity:J(1)},dec:{evaluate:$e(e=>e-1),arity:J(1)},"+":{evaluate:Ae(0,(e,t)=>e+t),arity:{}},"*":{evaluate:Ae(1,(e,t)=>e*t),arity:{}},"/":{evaluate:(e,t)=>{if(0===e.length)return 1;const[n,r]=Ne(e,t);if("number"===n){const[e,...t]=r;return 0===t.length?1/e:t.reduce((e,t)=>e/t,e)}if("vector"===n){const e=r[0];return r.slice(1).reduce((e,t)=>e.map((e,n)=>e/t[n]),e)}{const e=r[0];return r.slice(1).reduce((e,t)=>e.map((e,n)=>e.map((e,r)=>e/t[n][r])),e)}},arity:{}},"-":{evaluate:(e,t)=>{if(0===e.length)return 0;const[n,r]=Ne(e,t);if("number"===n){const[e,...t]=r;return 0===t.length?-e:t.reduce((e,t)=>e-t,e)}if("vector"===n){const e=r[0];return r.slice(1).reduce((e,t)=>e.map((e,n)=>e-t[n]),e)}{const e=r[0];return r.slice(1).reduce((e,t)=>e.map((e,n)=>e.map((e,r)=>e-t[n][r])),e)}},arity:{}},quot:{evaluate:Ie((e,t)=>Math.trunc(e/t)),arity:J(2)},mod:{evaluate:Ie((e,t)=>e-t*Math.floor(e/t)),arity:J(2)},"%":{evaluate:Ie((e,t)=>e%t),arity:J(2)},sqrt:{evaluate:$e(e=>Math.sqrt(e)),arity:J(1)},cbrt:{evaluate:$e(e=>Math.cbrt(e)),arity:J(1)},"^":{evaluate:Ie((e,t)=>e**t),arity:J(2)},round:{evaluate:([e,t],n)=>{const[r,i]=Ne([e],n);if("number"===r){if(void 0===t||0===t)return Math.round(i[0]);{I(t,n,{integer:!0,positive:!0});const e=10**t;return Math.round(i[0]*e)/e}}if("vector"===r){const e=i[0];if(void 0===t||0===t)return e.map(e=>Math.round(e));{I(t,n,{integer:!0,positive:!0});const r=10**t;return e.map(e=>Math.round(e*r)/r)}}{const e=i[0];if(void 0===t||0===t)return e.map(e=>e.map(e=>Math.round(e)));{I(t,n,{integer:!0,positive:!0});const r=10**t;return e.map(e=>e.map(e=>Math.round(e*r)/r))}}},arity:{min:1,max:2}},trunc:{evaluate:$e(e=>Math.trunc(e)),arity:J(1)},floor:{evaluate:$e(e=>Math.floor(e)),arity:J(1)},ceil:{evaluate:$e(e=>Math.ceil(e)),arity:J(1)},min:{evaluate:(e,t)=>{if(1===e.length&&we(e[0])){const n=e[0];return ke(n,t),n.reduce((e,t)=>Math.min(e,t),1/0)}const[n,...r]=e;return I(n,t),r.reduce((e,n)=>(I(n,t),Math.min(e,n)),n)},arity:{min:1}},max:{evaluate:(e,t)=>{if(1===e.length&&we(e[0])){const n=e[0];return ke(n,t),n.reduce((e,t)=>Math.max(e,t),-1/0)}const[n,...r]=e;return I(n,t),r.reduce((e,n)=>(I(n,t),Math.max(e,n)),n)},arity:{min:1}},abs:{evaluate:$e(e=>Math.abs(e)),arity:J(1)},sign:{evaluate:$e(e=>Math.sign(e)),arity:J(1)}};function Oe([e,...t],n){const r=j(e,n);for(const e of t)if(!ee(r,j(e,n),n))return!1;return!0}const Ce={"==":{evaluate:(e,t)=>Oe(e,t),arity:{min:1}},"≠":{evaluate:(e,t)=>!Oe(e,t),arity:{min:1}},"identical?":{evaluate:e=>function([e,...t]){for(const n of t)if(n!==e)return!1;return!0}(e),arity:{min:1}},">":{evaluate:([e,...t],n)=>{let r=X(e);for(const e of t){if(Q(r,X(e),n)<=0)return!1;r=X(e)}return!0},arity:{min:1}},"<":{evaluate:([e,...t],n)=>{let r=X(e);for(const e of t){if(Q(r,X(e),n)>=0)return!1;r=X(e)}return!0},arity:{min:1}},">=":{evaluate:([e,...t],n)=>{let r=X(e);for(const e of t){if(Q(r,X(e),n)<0)return!1;r=X(e)}return!0},arity:{min:1}},"<=":{evaluate:([e,...t],n)=>{let r=X(e);for(const e of t){if(Q(r,X(e),n)>0)return!1;r=X(e)}return!0},arity:{min:1}},"!":{evaluate:([e])=>!e,arity:J(1)},"epoch->iso-date":{evaluate:([e],t)=>(I(e,t),new Date(e).toISOString()),arity:J(1)},"iso-date->epoch":{evaluate:([e],t)=>{Y(e,t);const n=new Date(e).valueOf();return I(n,t,{finite:!0}),n},arity:J(1)},"write!":{evaluate:(e,t)=>(console.log(...e),e.length>0?j(e[e.length-1],t):null),arity:{}},boolean:{evaluate:([e])=>!!e,arity:J(1)},compare:{evaluate:([e,t],n)=>(Z(e,n),Z(t,n),Q(e,t,n)),arity:J(2)},"json-parse":{evaluate:([e],t)=>(Y(e,t),JSON.parse(e)),arity:J(1)},"json-stringify":{evaluate:([e,t],n)=>(O(e,n),void 0===t?JSON.stringify(e):(I(t,n),JSON.stringify(e,null,t))),arity:{min:1,max:2}},import:{evaluate:([e],t,n)=>{Y(e,t);const i=e.indexOf(".");if(-1!==i){const s=e.substring(0,i),o=e.substring(i+1),a=n.getModule(s);if(!a)throw new r(`Unknown module: '${s}'`,t);const u=a.functions[o];if(!u)throw new r(`Function '${o}' not found in module '${s}'`,t);return{[l]:!0,sourceCodeInfo:t,functionType:"Module",moduleName:s,functionName:o,arity:u.arity}}const s=e,o=n.getModule(s);if(!o)throw new r(`Unknown module: '${s}'`,t);const a={};for(const[e,n]of Object.entries(o.functions))a[e]={[l]:!0,sourceCodeInfo:t,functionType:"Module",moduleName:s,functionName:e,arity:n.arity};return a},arity:J(1)}},Fe={keys:{evaluate:([e],t)=>(T(e,t),Object.keys(e)),arity:J(1)},vals:{evaluate:([e],t)=>(T(e,t),Object.values(e)),arity:J(1)},entries:{evaluate:([e],t)=>(T(e,t),Object.entries(e)),arity:J(1)},find:{evaluate:([e,t],n)=>(T(e,n),Y(t,n),H(e,t)?[t,e[t]]:null),arity:J(2)},dissoc:{evaluate:([e,t],n)=>{T(e,n),Y(t,n);const r={...e};return delete r[t],r},arity:J(2)},merge:{evaluate:(e,t)=>{if(0===e.length)return null;const[n,...r]=e;return T(n,t),r.reduce((e,n)=>(T(n,t),{...e,...n}),{...n})},arity:{min:0}},"merge-with":{evaluate:(e,t,n,{executeFunction:r})=>{const i=e[0],s=e.at(-1),o=e.slice(1,-1);return T(i,t),L(s,t),o.reduce((e,i)=>(T(i,t),Object.entries(i).forEach(i=>{const o=G(i[0],t),a=te(i[1]);H(e,o)?e[o]=r(s,[e[o],a],n,t):e[o]=a}),e),{...i})},arity:{min:2}},zipmap:{evaluate:([e,t],n)=>{ae(e,n),oe(t,n);const r=Math.min(e.length,t.length),i={};for(let s=0;s<r;s+=1){i[G(e[s],n)]=te(t[s])}return i},arity:J(2)},"select-keys":{evaluate:([e,t],n)=>(ae(t,n),T(e,n),t.reduce((t,n)=>(H(e,n)&&(t[n]=te(e[n])),t),{})),arity:J(2)}},Ue={"function?":{evaluate:([e])=>w(e),arity:J(1)},"string?":{evaluate:([e])=>"string"==typeof e,arity:J(1)},"number?":{evaluate:([e])=>"number"==typeof e,arity:J(1)},"integer?":{evaluate:([e])=>"number"==typeof e&&$(e,{integer:!0}),arity:J(1)},"boolean?":{evaluate:([e])=>"boolean"==typeof e,arity:J(1)},"null?":{evaluate:([e])=>null==e,arity:J(1)},"zero?":{evaluate:([e],t)=>(I(e,t,{finite:!0}),Math.abs(e)<ie),arity:J(1)},"pos?":{evaluate:([e],t)=>(I(e,t,{finite:!0}),e>0),arity:J(1)},"neg?":{evaluate:([e],t)=>(I(e,t,{finite:!0}),e<0),arity:J(1)},"even?":{evaluate:([e],t)=>(I(e,t,{finite:!0}),e%2==0),arity:J(1)},"odd?":{evaluate:([e],t)=>(I(e,t,{finite:!0}),$(e,{integer:!0})&&e%2!=0),arity:J(1)},"array?":{evaluate:([e])=>Array.isArray(e),arity:J(1)},"collection?":{evaluate:([e])=>B(e),arity:J(1)},"sequence?":{evaluate:([e])=>C(e),arity:J(1)},"object?":{evaluate:([e])=>U(e),arity:J(1)},"regexp?":{evaluate:([e])=>D(e),arity:J(1)},"finite?":{evaluate:([e],t)=>(I(e,t),Number.isFinite(e)),arity:J(1)},"positive-infinity?":{evaluate:([e],t)=>(I(e,t),e===Number.POSITIVE_INFINITY),arity:J(1)},"negative-infinity?":{evaluate:([e],t)=>(I(e,t),e===Number.NEGATIVE_INFINITY),arity:J(1)},"true?":{evaluate:([e])=>!0===e,arity:J(1)},"false?":{evaluate:([e])=>!1===e,arity:J(1)},"empty?":{evaluate:([e],t)=>null===e||(M(e,t),"string"==typeof e||Array.isArray(e)?0===e.length:0===Object.keys(e).length),arity:J(1)},"not-empty?":{evaluate:([e],t)=>null!==e&&(M(e,t),"string"==typeof e||Array.isArray(e)?e.length>0:Object.keys(e).length>0),arity:J(1)},"vector?":{evaluate:([e])=>we(e),arity:J(1)},"matrix?":{evaluate:([e])=>Ee(e),arity:J(1)},"grid?":{evaluate:([e])=>xe(e),arity:J(1)}},Te={regexp:{evaluate:([e,t],n)=>{Y(e,n);const i=e||"(?:)",s="string"==typeof t?t:"";try{new RegExp(i,s)}catch(e){throw new r(`Invalid regular expression: ${i} ${s}`,n)}return{[f]:!0,sourceCodeInfo:n,s:i,f:s}},arity:{min:1,max:2}},match:{evaluate:([e,t],n)=>{if(function(e,t){if(!D(e))throw m("RegularExpression",e,t)}(t,n),!q(e))return null;const r=new RegExp(t.s,t.f).exec(e);return r?[...r]:null},arity:J(2)},replace:{evaluate:([e,t,n],r)=>{Y(e,r),R(t,r),Y(n,r);const i=D(t)?new RegExp(t.s,`${t.f}`):t;return e.replace(i,n)},arity:J(3)},"replace-all":{evaluate:([e,t,n],r)=>{Y(e,r),R(t,r),Y(n,r);const i=D(t)?new RegExp(t.s,`${t.f.includes("g")?t.f:`${t.f}g`}`):t;return e.replaceAll(i,n)},arity:J(3)}},Be=/^\s*$/,Pe={str:{evaluate:e=>e.reduce((e,t)=>e+(null==t?"":U(t)||Array.isArray(t)?JSON.stringify(t):`${t}`),""),arity:{}},number:{evaluate:([e],t)=>{Y(e,t);const n=Number(e);if(Number.isNaN(n))throw new r(`Could not convert '${e}' to a number.`,t);return n},arity:J(1)},"lower-case":{evaluate:([e],t)=>(Y(e,t),e.toLowerCase()),arity:J(1)},"upper-case":{evaluate:([e],t)=>(Y(e,t),e.toUpperCase()),arity:J(1)},trim:{evaluate:([e],t)=>(Y(e,t),e.trim()),arity:J(1)},join:{evaluate:([e,t],n)=>(oe(e,n),e.forEach(e=>Z(e,n)),Y(t,n),e.join(t)),arity:J(2)},split:{evaluate:([e,t,n],r)=>{Y(e,r),R(t,r),void 0!==n&&I(n,r,{integer:!0,nonNegative:!0});const i="string"==typeof t?t:new RegExp(t.s,t.f);return e.split(i,n)},arity:{min:2,max:3}},"blank?":{evaluate:([e],t)=>null===e||(Y(e,t),Be.test(e)),arity:J(1)}},Me={"|>":{evaluate:([e,t],n,r,{executeFunction:i})=>(L(t,n),i(t,[e],r,n)),arity:J(2)},apply:{evaluate:([e,...t],n,r,{executeFunction:i})=>{L(e,n);const s=t[t.length-1];oe(s,n);return i(e,[...t.slice(0,-1),...s],r,n)},arity:{min:2}},identity:{evaluate:([e])=>te(e),arity:J(1)},comp:{evaluate:(e,t)=>{return e.forEach(e=>L(e,t)),{[l]:!0,sourceCodeInfo:t,functionType:"Comp",params:e,arity:e.length>0?(n=e.at(-1),"number"==typeof n||B(n)?J(1):n.arity):{min:1,max:1}};var n},arity:{}},constantly:{evaluate:([e],t)=>({[l]:!0,sourceCodeInfo:t,functionType:"Constantly",value:te(e),arity:{}}),arity:J(1)}};function De(e){return se(`\n ${e.title}\n\n ${e.description.replace(/`(.+?)`/g,"$1").replace(/\$(\w+)/g,"$1").replace(/\*\*\*(.+)\*\*\*/g,"$1").replace(/\*\*(.+)\*\*/g,"$1")}\n\n Signature:\n ${function({title:e,variants:t,args:n,returns:r,_isOperator:i}){const s=t.map(t=>`${` ${e}(${t.argumentNames.map(e=>{let t="";return n[e].rest&&(t+="..."),t+=e,t}).join(", ")})`} -> ${Re(r)}`),o=i?["","Operator:",` a ${e} b -> ${Re(r)}`]:[];return[...s,...o]}(e).join("\n ")}\n\n Arguments:\n ${function(e){return Object.entries(e.args).map(([e,t])=>`${e}: ${Re(t)}`)}(e).join("\n ")}\n\n Examples:\n${e.examples.map(e=>se(e,4)).join("\n\n")}`)}function Re(e){const t=e.type,n=(Array.isArray(t)?t:[t]).join(" | ");return e.array||e.rest?`Array<${n}>`:n}const _e={sum:{evaluate:([e],t)=>(Se(e,t),e.reduce((e,t)=>e+t,0)),arity:J(1)},prod:{evaluate:([e],t)=>(Se(e,t),e.reduce((e,t)=>e*t,1)),arity:J(1)},mean:{evaluate:([e],t)=>(ke(e,t),e.reduce((e,t)=>e+t,0)/e.length),arity:J(1)},median:{evaluate:([e],t)=>(ke(e,t),function(e){const t=[...e].sort((e,t)=>e-t),n=Math.floor(t.length/2);return t.length%2==0?(t[n-1]+t[n])/2:t[n]}(e)),arity:J(1)}},Le={...W,...ce,...le,...fe,...je,...function(e){return{doc:{evaluate:([t],n)=>{if(v(e),L(t,n),!w(t))return"";if("Builtin"===t.functionType){const n=e[t.name];return n?De(n):""}return"UserDefined"===t.functionType||"NativeJsFunction"===t.functionType?t.docString:""},arity:J(1)},arity:{evaluate:([e],t)=>(L(e,t),w(e)?e.arity:J(1)),arity:J(1)}}}({}),...Ce,...Fe,...Ue,...Te,...Pe,...Me,..._e};Object.entries(Le).forEach(([e,t])=>{t.name=e});const Ve={...Le},ze={},Je=[];Object.entries(Ve).forEach(([e,t],n)=>{ze[e]=n,Je.push(t)});const We={arity:{},evaluate:(e,t,{evaluateNode:n})=>{let r=!0;for(const i of e[1][1])if(r=n(i,t),!r)break;return r},evaluateAsNormalExpression:(e,t)=>{let n=!0;for(const r of e)if(n=j(r,t),!n)break;return n},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)};function qe(e){const t=e[0];return o.UserDefinedSymbol===t||o.NormalBuiltinSymbol===t||o.SpecialBuiltinSymbol===t}function Ye(e){return o.UserDefinedSymbol===e[0]}function Ge(e,t){return function(e,t){if(!Ye(e))throw m("UserDefinedSymbolNode",e,t)}(e,t),e}function Ke(e){return o.NormalBuiltinSymbol===e[0]}function Xe(e){return o.SpecialBuiltinSymbol===e[0]}function Ze(e){return!!function(e){return e[0]===o.NormalExpression}(e)&&qe(e[1][0])}function He(e){return e[0]===o.Spread}const Qe={arity:J(1),evaluate:(e,t)=>{const n=e[1][1];if(function(e,t){if(!qe(e))throw m("SymbolNode",e,t)}(n),!Ye(n))return!0;return null!==t.lookUp(n)},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n([e[1][1]],t,r,i)};const et=11,tt=12,nt=13,rt=14;function it(e,t){if(e[0]===nt)Object.values(e[1][0]).forEach(e=>{e[1][1]&&t(e[1][1]),it(e,t)});else if(e[0]===rt)for(let n=0;n<e[1][0].length;n+=1){const r=e[1][0][n]??null;null!==r&&(r[1][1]&&t(r[1][1]),it(r,t))}}function st(e,t,n){const r={};return ot(e,t,n,e[2],r),r}function ot(e,t,n,i,s){if(e[0]===nt){!function(e,t){if(!b(e))throw new r(`Expected UnknownRecord, got ${d(e)}.`,g(e,t))}(t,i);const o=new Set;let a;if(Object.entries(e[1][0]).forEach(([e,r])=>{if(r[0]===tt)return void(a=r);o.add(e);const u=(void 0!==t[e]?t[e]:r[1][1]&&n(r[1][1]))??null;O(u,i),ot(r,u,n,i,s)}),a){const e=Object.entries(t).filter(([e])=>!o.has(e)).reduce((e,[t,n])=>(e[t]=j(n),e),{});s[a[1][0]]=e}}else if(e[0]===rt){let r=null;oe(t,i);for(let o=0;o<e[1][0].length;o+=1){const a=e[1][0][o]??null;if(null===a)continue;if(a[0]===tt){r=o;break}const u=(void 0!==t[o]?t[o]:a[1][1]&&n(a[1][1]))??null;O(u,i),ot(a,u,n,i,s)}if(null!==r){const n=t.slice(r),i=e[1][0][r];s[i[1][0]]=n}}else e[0]===tt?s[e[1][0]]=j(t):s[e[1][0][1]]=j(t)}function at(e){const t={};return ut(e,t),t}function ut(e,t){if(null!==e)if(e[0]===rt)for(const n of e[1][0])ut(n,t);else if(e[0]===nt)for(const n of Object.values(e[1][0]))ut(n,t);else if(e[0]===tt){if(t[e[1][0]])throw new r(`Duplicate binding name: ${e[1][0]}`,e[2]);t[e[1][0]]=!0}else{if(t[e[1][0][1]])throw new r(`Duplicate binding name: ${e[1][0]}`,e[2]);t[e[1][0][1]]=!0}}const ct={arity:{},evaluate:(e,t,{evaluateNode:n})=>{const r=e[1][1],i=r[1][0],s=r[1][1],o=n(s,t),a=st(i,o,e=>n(e,t));return t.exportValues(a,i[2]),o},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>{const s=e[1][1],o=s[1][0],a=s[1][1],u=n([a],t,r,i);return it(o,e=>{re(u,n([e],t,r,i))}),t.addValues(at(o),o[2]),u}},lt={arity:{},evaluate:(e,t,{builtin:n,getUndefinedSymbols:r,evaluateNode:i})=>{const s=e[1][1],o=e[1][2],a=function(e,t,n,r,i){const s={},o=e[0].reduce((e,t)=>(Object.keys(at(t)).forEach(t=>{e[t]={value:null}}),e),{}),a=r(e[1],t.new(o),n,i);a.forEach(e=>{const n=t.getValue(e);A(n)&&(s[e]={value:n})});const u=[e[0],e[1],s];return u}(s,t,n,r,i),u=a[0].filter(e=>e[0]!==tt&&void 0===e[1][1]).length,c={min:u>0?u:void 0,max:a[0].some(e=>e[0]===tt)?void 0:a[0].length};return{[l]:!0,sourceCodeInfo:e[2],functionType:"UserDefined",name:void 0,evaluatedfunction:a,arity:c,docString:o}},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>function(e,t,n,r,i){const s=new Set,o={self:{value:null}};e[0].forEach(e=>{Object.assign(o,at(e)),it(e,e=>{re(s,n([e],t,r,i))})});const a=t.create(o),u=n(e[1],a,r,i);return re(s,u),s}(e[1][1],t,n,r,i)};const ft={arity:J(0),evaluate:(e,t,{evaluateNode:n})=>{const r=e[1][1],i=r[1][0],s=r[1][1],o=n(s,t),a=st(i,o,e=>n(e,t));return t.addValues(a,i[2]),o},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>{const s=e[1][1],o=s[1][0],a=s[1][1],u=n([a],t,r,i);return it(o,e=>{re(u,n([e],t,r,i))}),t.addValues(at(o),o[2]),u}},ht={arity:{},evaluate:(e,t,{evaluateNode:i})=>{const s=e[1][1],o=s.reduce((e,n)=>{const r=i(n[1][1],t.create(e)),s=st(n[1][0],r,e=>i(e,t));return Object.entries(s).forEach(([t,n])=>{e[t]={value:n}}),e},{}),a=t.create(o),u=e[1][2];for(;;){let c=null;try{c=i(u,a)}catch(a){if(a instanceof n){const n=a.params;if(n.length!==s.length)throw new r(`recur expected ${s.length} parameters, got ${d(n.length)}`,e[2]);s.forEach((e,r)=>{const s=st(e[1][0],j(n[r]),e=>i(e,t));for(const[e,t]of Object.entries(s))o[e].value=t});continue}throw a}return c}},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>{const s=e[1][1],o=s.reduce((e,t)=>{const n=at(t[1][0]);return Object.keys(n).forEach(t=>{e[t]={value:!0}}),e},{});return ne(n(s.map(e=>e[1][1]),t,r,i),n([e[1][2]],t.create(o),r,i))}};function pt(e,t,n,r){for(const i of e){const[e,s]=i[1],o=st(e,r(s,n),e=>r(e,n));Object.entries(o).forEach(([e,n])=>{t[e]={value:n}})}}function dt(e,t,n,r){const i=t[2],[,s,o]=t[1],a=[],u=s.map(()=>0);let c=!1;for(;!c;){const t={},l=n.create(t);let f=!1;e:for(let e=0;e<s.length;e+=1){const[n,o,a,h]=s[e],[p,d]=n[1],g=P(r(d,l),i),m=C(g)?g:Object.entries(g);if(0===m.length){f=!0,c=!0;break}const v=y(u[e],i);if(v>=m.length){if(f=!0,0===e){c=!0;break}u[e]=0,u[e-1]=y(u[e-1],i)+1;break}const b=st(p,j(m[v],i),e=>r(e,l));if(Object.entries(b).forEach(([e,n])=>{t[e]={value:n}}),o&&pt(o,t,l,r),a&&!r(a,l)){u[e]=y(u[e],i)+1,f=!0;break e}if(h&&!r(h,l)){u[e]=Number.POSITIVE_INFINITY,f=!0;break e}}if(!f){const t=r(o,l);e&&a.push(t),u.length>0&&(u[u.length-1]+=1)}}return e?a:null}function gt(e,t,n,r,i){const s=new Set,o={},[,a,u]=e[1];return a.forEach(e=>{const[a,u,c,l]=e,[f,h]=a[1];n([h],t.create(o),r,i).forEach(e=>s.add(e)),Object.assign(o,at(f)),u&&u.forEach(e=>{const[a,u]=e[1];n([u],t.create(o),r,i).forEach(e=>s.add(e)),Object.assign(o,at(a))}),c&&n([c],t.create(o),r,i).forEach(e=>s.add(e)),l&&n([l],t.create(o),r,i).forEach(e=>s.add(e))}),n([u],t.create(o),r,i).forEach(e=>s.add(e)),s}const mt={arity:J(1),evaluate:(e,t,n)=>dt(!0,e,t,n.evaluateNode),getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>gt(e,t,n,r,i)},yt={arity:J(1),evaluate:(e,t,n)=>(dt(!1,e,t,n.evaluateNode),null),getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>gt(e,t,n,r,i)},vt={arity:{},evaluate:(e,t,{evaluateNode:n})=>{let r=!1;for(const i of e[1][1])if(r=n(i,t),r)break;return r},evaluateAsNormalExpression:(e,t)=>{let n=!1;for(const r of e)if(n=j(r,t),n)break;return n},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)},bt={arity:{min:1},evaluate:(e,t,{evaluateNode:n})=>{for(const r of e[1][1]){if(Ye(r)&&null===t.lookUp(r))continue;const e=n(r,t);if(null!==e)return e}return null},evaluateAsNormalExpression:(e,t)=>{for(const n of e){const e=j(n,t);if(null!==e)return e}return null},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)},wt={arity:{},evaluate:(e,t,{evaluateNode:r})=>{const i=e[1][1].map(e=>r(e,t));throw new n(i)},evaluateAsNormalExpression:e=>{throw new n(e)},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)},St={arity:J(1),evaluate:(e,t,{evaluateNode:n})=>{const r=G(n(e[1][1],t),e[2],{nonEmpty:!0});throw new i(r,e[2])},evaluateAsNormalExpression:(e,t)=>{const n=G(e[0],t,{nonEmpty:!0});throw new i(n,void 0)},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n([e[1][1]],t,r,i)},kt={arity:{},evaluate:(e,t,{evaluateNode:n})=>{const[,r,i,s]=e[1];try{return n(r,t)}catch(e){const r=i?{[i[1]]:{value:e}}:{};return n(s,t.create(r))}},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>{const[,s,o,a]=e[1],u=n([s],t,r,i),c=o?{[o[1]]:{value:!0}}:{};return ne(u,n([a],t.create(c),r,i))}},xt={arity:{},evaluate:(e,t,{evaluateNode:n})=>{const i=[];for(const s of e[1][1])if(He(s)){const e=n(s[1],t);if(!Array.isArray(e))throw new r("Spread value is not an array",s[2]);i.push(...e)}else i.push(n(s,t));return i},evaluateAsNormalExpression:(e,t)=>{const n=[];for(const r of e)n.push(j(r,t));return n},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)},Et={arity:{},evaluate:(e,t,{evaluateNode:n})=>{const i={},s=e[1][1];for(let e=0;e<s.length;e+=2){const o=s[e];if(He(o)){const s=n(o[1],t);if(!b(s))throw new r("Spread value is not an object",o[2]);Object.assign(i,s),e-=1}else{const a=n(o,t),u=s[e+1];if(void 0===u)throw new r("Missing value for key",o[2]);const c=n(u,t);Y(a,o[2]),i[a]=c}}return i},evaluateAsNormalExpression:(e,t)=>{const n={};for(let r=0;r<e.length;r+=2){const i=e[r],s=e[r+1];Y(i,t),n[i]=s??null}return n},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)},Nt={"??":0,"&&":1,"||":2,array:3,cond:4,"0_def":5,"defined?":6,block:7,doseq:8,"0_lambda":9,for:10,if:11,let:12,loop:13,object:14,recur:15,switch:16,throw:17,try:18,unless:19},$t=[bt,We,vt,xt,{arity:{},evaluate:(e,t,{evaluateNode:n})=>{const r=e[1][1];for(const[e,i]of r){if(n(e,t))return n(i,t)}return null},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1].flat(),t,r,i)},ct,Qe,{arity:{},evaluate:(e,t,{evaluateNode:n})=>{const r=t.create({});let i=null;for(const t of e[1][1])i=n(t,r);return i},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t.create({}),r,i)},yt,lt,mt,{arity:{min:2,max:3},evaluate:(e,t,{evaluateNode:n})=>{const[r,i,s]=e[1][1];return n(r,t)?n(i,t):s?n(s,t):null},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1].filter(e=>!!e),t,r,i)},ft,ht,Et,wt,{arity:{},evaluate:(e,t,{evaluateNode:n})=>{const[,r,i]=e[1],s=n(r,t);for(const[e,r]of i){if(n(e,t)===s)return n(r,t)}return null},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n([e[1][1],...e[1][2].flat()],t,r,i)},St,kt,{arity:{},evaluate:(e,t,{evaluateNode:n})=>{const[r,i,s]=e[1][1];return n(r,t)?s?n(s,t):null:n(i,t)},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1].filter(e=>!!e),t,r,i)}],It={normalExpressions:Ve,specialExpressions:$t,allNormalExpressions:Je},At=Object.keys(Ve),jt=Object.keys(Nt);new Set(jt);const Ot=(e,t,n,r)=>{const i=Array.isArray(e)?e:[[o.SpecialExpression,[Nt.block,e.body]]],s=new Set;for(const e of i)Ct(e,t,n,r)?.forEach(e=>s.add(e));return s};function Ct(e,t,n,i){const s=e[0];switch(s){case o.UserDefinedSymbol:{const n=e;return null===t.lookUp(n)?new Set([n[1]]):null}case o.NormalBuiltinSymbol:case o.SpecialBuiltinSymbol:case o.String:case o.Number:case o.ReservedSymbol:case o.Binding:return null;case o.NormalExpression:{const r=e,s=new Set;if(Ze(r)){const[,[e]]=r;if(Ye(e)){null===t.lookUp(e)&&s.add(e[1])}}else{const[,[e]]=r;Ct(e,t,n,i)?.forEach(e=>s.add(e))}for(const e of r[1][1])Ct(e,t,n,i)?.forEach(e=>s.add(e));return s}case o.SpecialExpression:{const r=e,s=r[1][0];return(0,n.specialExpressions[s].getUndefinedSymbols)(r,t,{getUndefinedSymbols:Ot,builtin:n,evaluateNode:i})}case o.Spread:return Ct(e[1],t,n,i);default:throw new r(`Unhandled node type: ${s}`,e[2])}}const Ft=(1+Math.sqrt(5))/2,Ut={E:Math.E,"-E":-Math.E,"ε":Math.E,"-ε":-Math.E,PI:Math.PI,"-PI":-Math.PI,"π":Math.PI,"-π":-Math.PI,PHI:Ft,"-PHI":-Ft,"φ":Ft,"-φ":-Ft,POSITIVE_INFINITY:Number.POSITIVE_INFINITY,"∞":Number.POSITIVE_INFINITY,NEGATIVE_INFINITY:Number.NEGATIVE_INFINITY,"-∞":Number.NEGATIVE_INFINITY,MAX_SAFE_INTEGER:Number.MAX_SAFE_INTEGER,MIN_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,MAX_VALUE:Number.MAX_VALUE,MIN_VALUE:Number.MIN_VALUE,NaN:Number.NaN},Tt={true:!0,false:!1,null:null,do:null,else:null,case:null,each:null,in:null,when:null,while:null,catch:null,function:null,export:null,as:null,then:null,end:null,_:null,...Ut};const Bt={NativeJsFunction:(e,t,n)=>{try{return te(e.nativeFn.fn(...t))}catch(e){const t="string"==typeof e?e:b(e)&&"string"==typeof e.message?e.message:"<no message>";throw new r(`Native function threw: "${t}"`,n)}},UserDefined:(e,t,i,s,{evaluateNode:o})=>{for(;;){if(!V(e.arity,t.length))throw new r(`Expected ${e.arity} arguments, got ${t.length}.`,i);const a=e.evaluatedfunction,u=a[0],c=u.filter(e=>e[0]!==tt).length,l=s.create(e.evaluatedfunction[2]),f={self:{value:e}},h=[];for(let e=0;e<t.length;e+=1)if(e<c){const n=te(t[e]),r=st(u[e],n,e=>o(e,l.create(f)));Object.entries(r).forEach(([e,t])=>{f[e]={value:t}})}else h.push(te(t[e]));for(let e=t.length;e<c;e++){const t=u[e],n=st(t,o(t[1][1],s.create(f)),e=>o(e,s.create(f)));Object.entries(n).forEach(([e,t])=>{f[e]={value:t}})}const p=u.find(e=>e[0]===tt);if(void 0!==p){const e=st(p,h,e=>o(e,s.create(f)));Object.entries(e).forEach(([e,t])=>{f[e]={value:t}})}try{let e=null;const t=l.create(f);for(const n of a[1])e=o(n,t);return e}catch(e){if(e instanceof n){t=e.params;continue}throw e}}},Partial:(e,t,n,i,{executeFunction:s})=>{const o=[...e.params];if(t.length!==e.placeholders.length)throw new r(`(partial) expects ${e.placeholders.length} arguments, got ${t.length}.`,n);const a=[...t];for(const t of e.placeholders)o.splice(t,0,a.shift());return s(e.function,o,i,n)},Comp:(e,t,n,i,{executeFunction:s})=>{const{params:o}=e;if(0===o.length){if(1!==t.length)throw new r(`(comp) expects one argument, got ${d(t.length)}.`,n);return j(t[0],n)}return j(o.reduceRight((e,t)=>[s(_(t,n),e,i,n)],t)[0],n)},Constantly:e=>e.value,Juxt:(e,t,n,r,{executeFunction:i})=>e.params.map(e=>i(_(e,n),t,r,n)),Complement:(e,t,n,r,{executeFunction:i})=>!i(e.function,t,r,n),EveryPred:(e,t,n,r,{executeFunction:i})=>{for(const s of e.params)for(const e of t){if(!i(_(s,n),[e],r,n))return!1}return!0},SomePred:(e,t,n,r,{executeFunction:i})=>{for(const s of e.params)for(const e of t){if(i(_(s,n),[e],r,n))return!0}return!1},Fnull:(e,t,n,r,{executeFunction:i})=>{const s=t.map((t,n)=>null===t?te(e.params[n]):t);return i(_(e.function,n),s,r,n)},Builtin:(e,t,n,r,{executeFunction:i})=>y(Je[e.normalBuiltinSymbolType],n).evaluate(t,n,r,{executeFunction:i}),SpecialBuiltin:(e,t,n,i,{executeFunction:s})=>{const o=y($t[e.specialBuiltinSymbolType],n);if(o.evaluateAsNormalExpression)return o.evaluateAsNormalExpression(t,n,i,{executeFunction:s});throw new r(`Special builtin function ${e.specialBuiltinSymbolType} is not supported as normal expression.`,n)},Module:(e,t,n,i,{executeFunction:s})=>{const o=i.getModule(e.moduleName);if(!o)throw new r(`Module '${e.moduleName}' not found.`,n);const a=o.functions[e.functionName];if(!a)throw new r(`Function '${e.functionName}' not found in module '${e.moduleName}'.`,n);return z(a.arity,t.length,n),a.evaluate(t,n,i,{executeFunction:s})}};function Pt(e,t){let n=null;for(const r of e.body)n=Mt(r,t);return n}function Mt(e,t){switch(e[0]){case o.Number:case o.String:return function(e){return e[1]}(e);case o.NormalBuiltinSymbol:case o.SpecialBuiltinSymbol:case o.UserDefinedSymbol:return t.evaluateSymbol(e);case o.ReservedSymbol:return function(e){const t=e[1];if(!["true","false","null"].includes(t))throw new r(`Reserved symbol ${t} cannot be evaluated`,e[2]);return y(Tt[t],e[2])}(e);case o.NormalExpression:{const n=function(e,t){const n=e[2],i=e[1][1],a=[],u=[];if(i.forEach((e,n)=>{if(He(e)){const n=Mt(e[1],t);if(!Array.isArray(n))throw new r(`Spread operator requires an array, got ${d(e)}`,e[2]);a.push(...n)}else e[0]===o.ReservedSymbol&&"_"===e[1]?u.push(n):a.push(Mt(e,t))}),Ze(e)){const r=e[1][0];if(u.length>0){const e=Mt(r,t);return{[l]:!0,function:_(e,n),functionType:"Partial",params:a,placeholders:u,sourceCodeInfo:n,arity:J(u.length)}}if(Ke(r)){const n=r[1];return It.allNormalExpressions[n].evaluate(a,e[2],t,{executeFunction:Dt})}{const i=t.getValue(r[1]);if(void 0!==i)return Dt(_(i,n),a,t,n);throw new s(r[1],e[2])}}{const r=_(Mt(e[1][0],t),n);if(u.length>0){return{[l]:!0,function:r,functionType:"Partial",params:a,placeholders:u,sourceCodeInfo:n,arity:J(u.length)}}return Dt(r,a,t,n)}}(e,t);if("number"==typeof n&&Number.isNaN(n))throw new r("Number is NaN",e[2]);return be(n)}case o.SpecialExpression:return be(function(e,t){const n=e[1][0],r=y(It.specialExpressions[n],e[2]);return(0,r.evaluate)(e,t,{evaluateNode:Mt,builtin:It,getUndefinedSymbols:Ot})}(e,t));default:throw new r(`${u(e[0])}-node cannot be evaluated`,e[2])}}function Dt(e,t,n,i){if(w(e))return Bt[e.functionType](e,t,i,n,{evaluateNode:Mt,executeFunction:Dt});if(Array.isArray(e))return function(e,t,n){if(1!==t.length)throw new r("Array as function requires one non negative integer parameter.",n);const i=t[0];return I(i,n,{integer:!0,nonNegative:!0}),te(e[i])}(e,t,i);if(U(e))return function(e,t,n){if(1!==t.length)throw new r("Object as function requires one string parameter.",n);const i=t[0];return Y(i,n),te(e[i])}(e,t,i);if("string"==typeof e)return function(e,t,n){if(1!==t.length)throw new r("String as function requires one Obj parameter.",n);const i=te(t[0]);if(U(i))return te(i[e]);if($(i,{integer:!0}))return te(e[i]);throw new r(`string as function expects Obj or integer parameter, got ${d(i)}`,n)}(e,t,i);if($(e))return function(e,t,n){if(I(e,n,{integer:!0}),1!==t.length)throw new r("Number as function requires one Arr parameter.",n);const i=t[0];return F(i,n),te(i[e])}(e,t,i);throw new r("Unexpected function type",i)}class Rt{contexts;globalContext;values;nativeJsFunctions;modules;constructor({contexts:e,values:t,nativeJsFunctions:n,modules:r}){this.globalContext=y(e[0]),this.contexts=e,this.values=t,this.nativeJsFunctions=n,this.modules=r??new Map}getModule(e){return this.modules.get(e)}create(e){const t=this.globalContext,n=new Rt({contexts:[e,...this.contexts],values:this.values,nativeJsFunctions:this.nativeJsFunctions,modules:this.modules});return n.globalContext=t,n}new(e){return new Rt({contexts:[{},e],modules:this.modules})}exportValues(e,t){for(const[n,i]of Object.entries(e)){if(this.globalContext[n])throw new r(`Cannot redefine exported value "${n}"`,t);const e=_t(n);if(e)throw new r(`Cannot shadow ${e}`,t);this.globalContext[n]={value:i}}this.contexts[0]!==this.globalContext&&this.addValues(e,t)}addValues(e,t){const n=this.contexts[0];for(const[i,s]of Object.entries(e)){if(n[i])throw new r(`Cannot redefine value "${i}"`,t);const e=_t(i);if(e)throw new r(`Cannot shadow ${e}`,t);n[i]={value:te(s)}}}getValue(e){for(const t of this.contexts){const n=t[e];if(n)return n.value}const t=this.nativeJsFunctions?.[e];return t||this.values?.[e]}lookUp(e){const t=e[1];for(const e of this.contexts){const n=e[t];if(n)return n}const n=this.values?.[t];if(void 0!==n)return{value:te(n)};const r=this.nativeJsFunctions?.[t];return r?{value:r}:null}evaluateSymbol(e){if(Xe(e)){const t=e[1];switch(t){case Nt["&&"]:case Nt["||"]:case Nt.array:case Nt.object:case Nt["defined?"]:case Nt.recur:case Nt.throw:case Nt["??"]:{const n=y(It.specialExpressions[t],e[2]);return{[l]:!0,functionType:"SpecialBuiltin",specialBuiltinSymbolType:t,sourceCodeInfo:e[2],arity:n.arity}}default:throw new r(`Unknown special builtin symbol type: ${t}`,e[2])}}if(Ke(e)){const t=e[1],n=Je[t],r=n.name;return{[l]:!0,functionType:"Builtin",normalBuiltinSymbolType:t,sourceCodeInfo:e[2],arity:n.arity,name:r}}const t=this.lookUp(e);if(b(n=t)&&void 0!==n.value)return t.value;var n;throw new s(e[1],e[2])}}function _t(e){return jt.includes(e)?`special expression "${e}"`:At.includes(e)?`builtin function "${e}"`:"self"===e?`builtin value "${e}"`:null}function Lt(e={},t){const n=e.globalContext??{},i=e.contexts?[n,...e.contexts]:[n],s=new Rt({contexts:i,values:e.values,modules:t,nativeJsFunctions:e.jsFunctions&&Object.entries(e.jsFunctions).reduce((e,[t,n])=>{const i=t.split("."),s=i.pop();if(/^[A-Z]/.test(s))throw new r(`Invalid identifier "${t}" in jsFunctions, function name must not start with an uppercase letter`,void 0);let o=e;for(const e of i){if(0===e.length)throw new r(`Invalid empty identifier "${t}" in jsFunctions`,void 0);if(!/^[A-Z]/.test(e))throw new r(`Invalid identifier "${t}" in jsFunctions, module name must start with an uppercase letter`,void 0);o[e]||(o[e]={}),o=o[e]}!function(e){if(!function(e){return"object"==typeof e&&null!==e&&"fn"in e&&"function"==typeof e.fn}(e))throw new TypeError("Expected a NativeJsFunction")}(n);const a={functionType:"NativeJsFunction",nativeFn:n,name:s,[l]:!0,arity:n.arity??{},docString:n.docString??""};return o===e&&function(e){const t=_t(e);if(t)throw new r(`Cannot shadow ${t}`,void 0)}(s),o[s]=a,e},{})});return e.globalModuleScope?s:s.create({})}const Vt=["^","*","/","%","+","-","<<",">>",">>>","++","<","<=","≤",">",">=","≥","==","!=","≠","&","xor","|","&&","||","??","|>"],zt=[...Vt,"?",":","->","...",".",",","=",":",";"],Jt=new Set(["comment","cond","def","defined?","block","doseq","if","let","loop","recur","throw","try","unless","while"]);function Wt(e){return!Jt.has(e)}const qt=new Set(Vt);function Yt(e){return qt.has(e)}const Gt=new Set(zt);function Kt(e){return Gt.has(e)}const Xt=["(",")","[","]","{","}","'",'"',"`",",",".",";"," ","\n","\r","\t"],Zt=["0","1","2","3","4","5","6","7","8","9",...Xt],Ht=new Set(Xt),Qt=new Set(Zt),en=/\s/,tn=[0],nn=(e,t)=>{if('"'!==e[t])return tn;let n='"',r=1,i=e[t+r],s=!1;for(;i&&('"'!==i||s);)r+=1,s?(s=!1,n+=i):("\\"===i&&(s=!0),n+=i),i=e[t+r];return i?(n+='"',[r+1,["string",n]]):[r,["Error",n,void 0,`Unclosed string at position ${t}`]]};function rn(e,t,n,r){return t===n.slice(r,r+t.length)?[t.length,[e,t]]:tn}const sn=/\d/,on=/[0-7]/,an=/[0-9a-f]/i,un=/[01]/,cn=/[\s)\]}(,;]/,ln=(e,t)=>{let n=e[t];if("'"===n){let r=1,i=e[t+r],s=!1;for(;"'"!==i||s;){if(void 0===i)return[r,["Error",n,void 0,`Unclosed quoted symbol at position ${t}`]];r+=1,s?(s=!1,n+=i):("\\"===i&&(s=!0),n+=i),i=e[t+r]}return n+="'",[r+1,["Symbol",n]]}if(!Qt.has(n)){const r=t;let i=e[t+=1];for(;i&&!Ht.has(i);)n+=i,i=e[t+=1];return n.endsWith(":")?[t-r-1,["Symbol",n.slice(0,-1)]]:[t-r,["Symbol",n]]}return tn},fn=[(e,t)=>{let n=e[t];if(!n||!en.test(n))return tn;let r=n;for(n=e[t+=1];n&&en.test(n);)r+=n,n=e[t+=1];return[r.length,["Whitespace",r]]},(e,t)=>{if("/"===e[t]&&"*"===e[t+1]){let n=2,r="/*";for(;("*"!==e[t+n]||"/"!==e[t+n+1])&&t+n+1<e.length;)r+=e[t+n],n+=1;return t+n+1>=e.length?[n,["Error",r,void 0,`Unclosed multi-line comment at position ${t}`]]:(r+="*/",n+=2,[n,["MultiLineComment",r]])}return tn},(e,t)=>{if("/"===e[t]&&"/"===e[t+1]){let n=2,r="//";for(;"\n"!==e[t+n]&&t+n<e.length;)r+=e[t+n],n+=1;return[n,["SingleLineComment",r]]}return tn},(e,t)=>{const n=ln(e,t);if(0===n[0]||!n[1])return tn;let r=n[1][1];r=r.startsWith("'")?r.slice(1,r.length-1):r;return void 0===Tt[r]?tn:[n[0],["ReservedSymbol",r]]},(e,t)=>rn("LParen","(",e,t),(e,t)=>rn("RParen",")",e,t),(e,t)=>rn("LBracket","[",e,t),(e,t)=>rn("RBracket","]",e,t),(e,t)=>rn("LBrace","{",e,t),(e,t)=>rn("RBrace","}",e,t),(e,t)=>{if('"'!==e[t]||'"'!==e[t+1]||'"'!==e[t+2])return tn;let n='"""',r=3,i=e[t+r],s=e.slice(t+r,t+r+3),o=!1;for(;i&&('"""'!==s||o);)r+=1,o?(o=!1,n+=i):("\\"===i&&(o=!0),n+=i),i=e[t+r],s=e.slice(t+r,t+r+3);return i?(n+='"""',[r+3,["DocString",n]]):[r,["Error",n,void 0,`Unclosed doc string at position ${t}`]]},nn,(e,t)=>{if("#"!==e[t])return tn;const[n,r]=nn(e,t+1);if(!r)return tn;if("Error"===r[0]){return[n+1,["Error",`#${r[1]}`,void 0,`Unclosed regexp at position ${t}`]]}t+=n+1;let i=n+1,s="";for(;"g"===e[t]||"i"===e[t];)if(s+=e[t],i+=1,t+=1,s.includes(e[t]))return[i,["Error",`#${r[1]}${s}`,void 0,`Duplicated regexp option "${e[t]}"`]];return[i,["RegexpShorthand",`#${r[1]}${s}`]]},(e,t)=>{if("0"!==e[t])return tn;const n=e[t+1],r="b"===n||"B"===n?"binary":"o"===n||"O"===n?"octal":"x"===n||"X"===n?"hex":null;if(null===r)return tn;let i;for(i=t+2;i<e.length;i+=1){const t=e[i];if("binary"===r&&!un.test(t))break;if("octal"===r&&!on.test(t))break;if("hex"===r&&!an.test(t))break}const s=i-t;if(s<=2)return tn;const o=e[i];return o&&!cn.test(o)?tn:[s,["BasePrefixedNumber",e.substring(t,i)]]},(e,t)=>{let n;const r="-"===e[t],i="+"===e[t],s=r||i?t+1:t;let o=!1,a=!1;for(n=s;n<e.length;n+=1){const r=e[n];if("_"===r){if(!sn.test(e[n-1])||!sn.test(e[n+1]))return n===s?tn:[n-t+1,["Error",e.substring(t,n+1),void 0,`Invalid number format at position ${n+1}`]]}else if("."===r){if(n===s)return tn;if(o||a)return[n-t+1,["Error",e.substring(t,n+1),void 0,`Invalid number format at position ${n+1}`]];o=!0}else if("e"===r||"E"===r){if(n===s)return tn;if(a)return[n-t+1,["Error",e.substring(t,n+1),void 0,`Invalid number format at position ${n+1}`]];if("."===e[n-1]||"+"===e[n-1]||"-"===e[n-1])return[n-t+1,["Error",e.substring(t,n+1),void 0,`Invalid number format at position ${n+1}`]];"+"!==e[n+1]&&"-"!==e[n+1]||(n+=1),a=!0}else if(!sn.test(r))break}if((r||i)&&n===s)return tn;const u=n-t;if(0===u)return tn;const c=e[n];return c&&":"!==c&&!cn.test(c)?[n-t+1,["Error",e.substring(t,n+1),void 0,`Invalid number format at position ${n+1}`]]:[u,["Number",e.substring(t,n)]]},(e,t)=>{const n=e.slice(t,t+3);if(t+2<e.length&&Kt(n))return[3,["Operator",n]];const r=e.slice(t,t+2);if(t+1<e.length&&Kt(r))return[2,["Operator",r]];const i=e[t]??"";return Kt(i)?[1,["Operator",i]]:tn},ln];function hn(e,t,n){const r=e.substring(0,t+1).split(/\r\n|\r|\n/),i=r[r.length-1],s=function(e,t){return e.split(/\r\n|\r|\n/)[t]}(e,r.length-1);return{code:s,position:{line:r.length,column:i.length},filePath:n}}function pn(e,t){const n=t;if(0===t){const[r,i]=((e,t)=>{if("#"===e[t]&&"!"===e[t+1]){let n=2,r="#!";for(;"\n"!==e[t+n]&&t+n<e.length;)r+=e[t+n],n+=1;return[n,["SingleLineComment",r]]}return tn})(e,t);if(t+=r,r>0)return[t-n,i]}for(const r of fn){const[i,s]=r(e,t);if(t+=i,0!==i)return[t-n,s]}return[1,["Error",e[n],void 0,"Unrecognized character"]]}function dn(e,t){return"Symbol"===e?.[0]&&(!t||e[1]===t)}function gn(e,t){return function(e,t){dn(e,t)||Tn("Symbol",void 0,e)}(e,t),e}function mn(e,t){return"ReservedSymbol"===e?.[0]&&(!t||e[1]===t)}function yn(e,t){mn(e,t)||Tn("ReservedSymbol",t,e)}function vn(e,t){return yn(e,t),e}function bn(e,t){return"Operator"===e?.[0]&&(!t||e[1]===t)}function wn(e,t){bn(e,t)||Tn("Operator",t,e)}function Sn(e){return"LParen"===e?.[0]}function kn(e){Sn(e)||Tn("LParen",void 0,e)}function xn(e){return"RParen"===e?.[0]}function En(e){xn(e)||Tn("RParen",void 0,e)}function Nn(e){return"LBracket"===e?.[0]}function $n(e){return function(e){Nn(e)||Tn("LBracket",void 0,e)}(e),e}function In(e){return"RBracket"===e?.[0]}function An(e){In(e)||Tn("RBracket",void 0,e)}function jn(e){return"LBrace"===e?.[0]}function On(e){return function(e){jn(e)||Tn("LBrace",void 0,e)}(e),e}function Cn(e){return"RBrace"===e?.[0]}function Fn(e){return"string"===e?.[0]}function Un(e){return"Operator"===e?.[0]&&Yt(e[1])}function Tn(e,t,n){const i=n?`${n[0]} '${n[1]}'`:"end of input";throw new r(`Unexpected token: ${i}, expected ${e}${t?` '${t}'`:""}`,n?.[2])}function Bn(e,{removeWhiteSpace:t}){const n=e.tokens.filter(e=>!(function(e){return"SingleLineComment"===e?.[0]}(e)||function(e){return"MultiLineComment"===e?.[0]}(e)||function(e){return"Shebang"===e?.[0]}(e)||t&&function(e){return"Whitespace"===e?.[0]}(e)));return{...e,tokens:n}}const Pn=Object.entries(ze).reduce((e,[t,n])=>(e[n]=t,e),[]),Mn=Object.entries(Nt).reduce((e,[t,n])=>(e[n]=t,e),[]);function Dn(e){return Ye(e)?e[1]:Ke(e)?Pn[e[1]]:Mn[e[1]]}const Rn=/^\$([1-9]\d?)?$/;function _n(e,t){return t&&(e[2]=t),e}function Ln(e,t){switch(e){case"^":return 12;case"*":case"/":case"%":return 11;case"+":case"-":return 10;case"<<":case">>":case">>>":return 9;case"++":return 8;case"<":case"<=":case"≤":case">":case">=":case"≥":return 7;case"==":case"!=":case"≠":return 6;case"&":case"xor":case"|":return 5;case"&&":case"||":case"??":return 4;case"|>":return 2;default:throw new r(`Unknown binary operator: ${e}`,t)}}function Vn(e,t,n){const r=_n([o.NormalExpression,[e,t]],n);return Ke(e)&&z(Je[e[1]].arity,r[1][1].length,n),r}function zn(e,t,n){return _n([o.NormalExpression,[[o.NormalBuiltinSymbol,ze.get],[e,t]]],n)}function Jn(e,t,n,i,s){const a=e[1];switch(a){case"^":case"*":case"/":case"%":case"+":case"-":case"<<":case">>":case">>>":case"++":case"<":case"<=":case"≤":case">":case">=":case"≥":case"==":case"!=":case"≠":case"&":case"xor":case"|":case"|>":return Vn(t,[n,i],s);case"&&":case"||":case"??":return _n([o.SpecialExpression,[Nt[a],[n,i]]],s);default:throw new r(`Unknown binary operator: ${a}`,s)}}class Wn{tokenStream;parseState;constructor(e,t){this.tokenStream=e,this.parseState=t}peek(){return this.tokenStream.tokens[this.parseState.position]}peekSourceCodeInfo(){const e=this.peek();return e?e[2]:this.tokenStream.tokens.at(-1)?.[2]}peekAhead(e){return this.tokenStream.tokens[this.parseState.position+e]}advance(){this.parseState.position+=1}parse(){this.tokenStream.tokens.forEach(e=>{if("Error"===e[0])throw new r(e[3],e[2])});const e=[];for(;!this.isAtEnd();)if(e.push(this.parseExpression(0,!0)),bn(this.peek(),";"))this.advance();else if(!this.isAtEnd())throw new r("Expected ;",this.peekSourceCodeInfo());return e}parseExpression(e=0,t=!1){const n=this.peek();let i;if(dn(n))switch(n[1]){case"let":return this.parseLet(n);case"if":case"unless":i=this.parseIfOrUnless(n);break;case"cond":i=this.parseCond(n);break;case"switch":i=this.parseSwitch(n);break;case"for":case"doseq":i=this.parseForOrDoseq(n);break;case"loop":i=this.parseLoop(n);break;case"try":i=this.parseTry(n)}else if(mn(n,"do"))i=this.parseBlock()[0];else if(mn(n,"export")){if(!t)throw new r("export is only allowed in module scope",n[2]);return this.parseExport(n)}i||=this.parseOperand();let s=this.peek();for(;!this.isAtExpressionEnd();){if(Un(s)){const t=s[1],n=Ln(t,s[2]);if(n<=e&&(12!==n||12!==e))break;const r=_n(Nt[t]?[o.SpecialBuiltinSymbol,Nt[t]]:[o.NormalBuiltinSymbol,ze[t]],s[2]);this.advance();i=Jn(s,r,i,this.parseExpression(n),s[2])}else if(dn(s)){if(!Wt(s[1]))break;const t=3;if(t<=e)break;const n=this.parseSymbol(),o=this.parseExpression(t);if(Xe(n))throw new r("Special expressions are not allowed in binary functional operators",n[2]);i=Vn(n,[i,o],s[2])}else{if("?"!==s?.[1])break;{if(1<=e)break;this.advance();const t=this.parseExpression();if(!bn(this.peek(),":"))throw new r("Expected :",this.peekSourceCodeInfo());this.advance();const n=this.parseExpression();i=_n([o.SpecialExpression,[Nt.if,[i,t,n]]],i[2])}}s=this.peek()}return i}asToken(e){if(!e)throw new r("Unexpected end of input",this.peekSourceCodeInfo());return e}parseOperand(){let e=this.parseOperandPart(),t=this.peek();for(;bn(t,".")||Nn(t)||Sn(t);)if("."===t[1]){this.advance();const n=this.asToken(this.peek());if(!dn(n))throw new r("Expected symbol",this.peekSourceCodeInfo());e=zn(e,_n([o.String,n[1]],n[2]),t[2]),this.advance(),t=this.peek()}else if(Nn(t)){this.advance();const n=this.parseExpression();if(!In(this.peek()))throw new r("Expected closing bracket",this.peekSourceCodeInfo());e=zn(e,n,t[2]),this.advance(),t=this.peek()}else Sn(t)&&(e=this.parseFunctionCall(e),t=this.peek());return e}parseOperandPart(){const e=this.asToken(this.peek());if(Sn(e)){const e=this.parseState.position,t=this.parseLambdaFunction();if(t)return t;this.parseState.position=e,this.advance();const n=this.parseExpression();if(!xn(this.peek()))throw new r("Expected closing parenthesis",this.peekSourceCodeInfo());return this.advance(),n}if(bn(e)){const t=e[1];if(Yt(t))return this.advance(),_n(void 0!==Nt[t]?[o.SpecialBuiltinSymbol,Nt[t]]:[o.NormalBuiltinSymbol,ze[t]],e[2]);if("->"===t)return this.parseShorthandLambdaFunction();throw new r(`Illegal operator: ${t}`,e[2])}if(jn(e))return this.parseObject();if(Nn(e))return this.parseArray();const t=e[0];switch(t){case"Number":case"BasePrefixedNumber":return this.parseNumber();case"string":return this.parseString(e);case"Symbol":{const e=this.parseState.position,t=this.parseLambdaFunction();return t||(this.parseState.position=e,this.parseSymbol())}case"ReservedSymbol":return this.parseReservedSymbol();case"RegexpShorthand":return this.parseRegexpShorthand();default:throw new r(`Unknown token type: ${t}`,e[2])}}parseObject(){const e=On(this.peek());this.advance();const t=[];for(;!this.isAtEnd()&&!Cn(this.peek());){if(bn(this.peek(),"..."))this.advance(),t.push(_n([o.Spread,this.parseExpression()],this.peekSourceCodeInfo()));else{const e=this.peek();if(Fn(e)){const n=this.parseString(e);t.push(_n([o.String,n[1]],e[2]))}else if(dn(e)){const n=e[1].startsWith("'")?this.stringFromQuotedSymbol(e[1]):e[1];t.push(_n([o.String,n],e[2])),this.advance()}else{if(!Nn(e))throw new r("Expected key to be a symbol or a string",this.peekSourceCodeInfo());this.advance(),t.push(this.parseExpression()),An(this.peek()),this.advance()}wn(this.peek(),":"),this.advance(),t.push(this.parseExpression())}const e=this.peek();if(!bn(e,",")&&!Cn(e))throw new r("Expected comma or closing brace",this.peekSourceCodeInfo());bn(e,",")&&this.advance()}var n;return Cn(n=this.peek())||Tn("RBrace",void 0,n),this.advance(),_n([o.SpecialExpression,[Nt.object,t]],e[2])}parseArray(){const e=$n(this.peek());this.advance();const t=[];for(;!this.isAtEnd()&&!In(this.peek());){bn(this.peek(),"...")?(this.advance(),t.push(_n([o.Spread,this.parseExpression()],this.peekSourceCodeInfo()))):t.push(this.parseExpression());const e=this.peek();if(!bn(e,",")&&!In(e))throw new r("Expected comma or closing parenthesis",this.peekSourceCodeInfo());bn(e,",")&&this.advance()}return An(this.peek()),this.advance(),_n([o.SpecialExpression,[Nt.array,t]],e[2])}parseFunctionCall(e){this.advance();const t=[];for(;!this.isAtEnd()&&!xn(this.peek());){bn(this.peek(),"...")?(this.advance(),t.push(_n([o.Spread,this.parseExpression()],this.peekSourceCodeInfo()))):t.push(this.parseExpression());const e=this.peek();if(!bn(e,",")&&!xn(e))throw new r("Expected comma or closing parenthesis",this.peek()?.[2]);bn(e,",")&&this.advance()}if(!xn(this.peek()))throw new r("Expected closing parenthesis",this.peekSourceCodeInfo());if(this.advance(),!Xe(e))return Ke(e)||Ye(e)?Vn(e,t,e[2]):_n([o.NormalExpression,[e,t]],e[2]);{const n=e[1];switch(z(It.specialExpressions[n].arity,t.length,e[2]),n){case Nt["||"]:case Nt["&&"]:case Nt.recur:case Nt.array:case Nt.object:case Nt["??"]:return _n([o.SpecialExpression,[n,t]],e[2]);case Nt["defined?"]:{const[r]=t;return _n([o.SpecialExpression,[n,r]],e[2])}case Nt.throw:{const[r]=t;return _n([o.SpecialExpression,[n,r]],e[2])}case Nt["0_lambda"]:case Nt["0_def"]:throw new r(`${n} is not allowed`,e[2]);default:throw new r(`Unknown special expression: ${n}`,e[2])}}}parseLambdaFunction(){const e=this.asToken(this.peek());if(Sn(e)&&dn(this.peekAhead(1))&&bn(this.peekAhead(2),"->"))return null;try{const t=this.parseFunctionArguments();if(!bn(this.peek(),"->"))return null;let n;this.advance();let r="";if(mn(this.peek(),"do")){const e=this.parseBlock(!0);r=e[1],n=e[0][1][1]}else n=[this.parseExpression()];return _n([o.SpecialExpression,[Nt["0_lambda"],[t,n],r]],e[2])}catch{return null}}parseFunctionArguments(){const e=this.peek();if(dn(e))return[_n([et,[this.parseSymbol(),void 0]],e[2])];kn(e),this.advance();let t=!1,n=!1;const i=[];for(;!this.isAtEnd()&&!xn(this.peek())&&!dn(this.peek(),"let");){if(t)throw new r("Rest argument must be last",this.peekSourceCodeInfo());const e=this.parseBindingTarget();if(void 0!==e[1][1]&&(n=!0),e[0]===tt&&(t=!0),n&&!e[1][1])throw new r("Default arguments must be last",this.peekSourceCodeInfo());if(i.push(e),!bn(this.peek(),",")&&!xn(this.peek())&&!dn(this.peek(),"let"))throw new r("Expected comma or closing parenthesis",this.peekSourceCodeInfo());bn(this.peek(),",")&&this.advance()}if(!xn(this.peek()))throw new r("Expected closing parenthesis",this.peekSourceCodeInfo());return this.advance(),i}parseShorthandLambdaFunction(){const e=this.asToken(this.peek());this.advance();const t=this.parseState.position;let n,i="";if(mn(this.peek(),"do")){const e=this.parseBlock(!0);i=e[1],n=e[0][1][1]}else n=[this.parseExpression()];const s=this.parseState.position-1;let a=0,u="NOT_SET";for(let n=t;n<=s;n+=1){const t=this.tokenStream.tokens[n];if(dn(t)){const n=Rn.exec(t[1]);if(n){const t=n[1]??"1";if("1"===t){if(!n[1]&&"WITH_1"===u||n[1]&&"NAKED"===u)throw new r("Please make up your mind, either use $ or $1",e[2]);u=n[1]?"WITH_1":"NAKED"}if(a=Math.max(a,Number(t)),a>20)throw new r("Can't specify more than 20 arguments",e[2])}}}const c=[];for(let t=1;t<=a;t+=1)1===t&&"NAKED"===u?c.push(_n([et,[[o.UserDefinedSymbol,"$"],void 0]],e[2])):c.push(_n([et,[[o.UserDefinedSymbol,`$${t}`],void 0]],e[2]));return _n([o.SpecialExpression,[Nt["0_lambda"],[c,n],i]],e[2])}parseOptionalDefaulValue(){if(bn(this.peek(),"="))return this.advance(),this.parseExpression()}parseBindingTarget({requireDefaultValue:e,noRest:t}={}){const n=this.peek();if(dn(n)){const t=this.parseSymbol();if(!Ye(t))throw new r("Expected user defined symbol",n[2]);const i=this.parseOptionalDefaulValue();if(e&&!i)throw new r("Expected assignment",this.peekSourceCodeInfo());return _n([et,[t,i]],n[2])}if(bn(n,"...")){if(t)throw new r("Rest element not allowed",n[2]);this.advance();const e=Ge(this.parseSymbol());if(bn(this.peek(),"="))throw new r("Rest argument can not have default value",this.peekSourceCodeInfo());return _n([tt,[e[1],void 0]],n[2])}if(Nn(n)){this.advance();const t=[];let i=this.asToken(this.peek()),s=!1;for(;!In(i);){if(s)throw new r("Rest argument must be last",i[2]);if(bn(i,",")){t.push(null),this.advance(),i=this.asToken(this.peek());continue}const e=this.parseBindingTarget();e[0]===tt&&(s=!0),t.push(e),i=this.asToken(this.peek()),In(i)||(wn(i,","),this.advance()),i=this.asToken(this.peek())}this.advance();const o=this.parseOptionalDefaulValue();if(e&&!o)throw new r("Expected assignment",this.peekSourceCodeInfo());return _n([rt,[t,o]],n[2])}if(jn(n)){this.advance();const t={};let i=this.asToken(this.peek()),s=!1;for(;!Cn(i);){if(s)throw new r("Rest argument must be last",i[2]);bn(i,"...")&&(s=!0,this.advance());const e=this.parseSymbol(),o=Dn(e);if(i=this.asToken(this.peek()),mn(i,"as")){if(s)throw new r("Rest argument can not have alias",i[2]);this.advance();const e=Ge(this.parseSymbol());if(t[e[1]])throw new r(`Duplicate binding name: ${e}`,i[2]);t[o]=_n([et,[e,this.parseOptionalDefaulValue()]],n[2])}else if(Cn(i)||bn(i,",")||bn(i,"=")){const o=Ge(e,e[2]);if(t[o[1]])throw new r(`Duplicate binding name: ${o}`,i[2]);if(s&&bn(this.peek(),"="))throw new r("Rest argument can not have default value",this.peekSourceCodeInfo());t[o[1]]=_n(s?[tt,[o[1],this.parseOptionalDefaulValue()]]:[et,[o,this.parseOptionalDefaulValue()]],n[2])}else if(bn(i,":")){if(this.advance(),i=this.asToken(this.peek()),!jn(i)&&!Nn(i))throw new r("Expected object or array",i[2]);t[o]=this.parseBindingTarget()}Cn(this.peek())||(wn(this.peek(),","),this.advance()),i=this.asToken(this.peek())}this.advance(),i=this.asToken(this.peek());const o=this.parseOptionalDefaulValue();if(e&&!o)throw new r("Expected assignment",i[2]);return _n([nt,[t,o]],n[2])}throw new r("Expected symbol",this.peekSourceCodeInfo())}parseLet(e){this.advance();const t=this.parseBindingTarget({requireDefaultValue:!0,noRest:!0}),n=t[1][1];t[1][1]=void 0;const r=_n([o.Binding,[t,n]],e[2]);return _n([o.SpecialExpression,[Nt.let,r]],e[2])}parseBlock(e=!1){const t=vn(this.peek(),"do");this.advance();let n="";e&&function(e){return"DocString"===e?.[0]}(this.peek())&&(n=this.parseDocString());const i=[];for(;!this.isAtEnd()&&!mn(this.peek(),"end");)if(i.push(this.parseExpression()),bn(this.peek(),";"))this.advance();else if(!mn(this.peek(),"end"))throw new r("Expected end",this.peekSourceCodeInfo());return yn(this.peek(),"end"),this.advance(),[_n([o.SpecialExpression,[Nt.block,i]],t[2]),n]}parseImplicitBlock(e){const t=[];for(;!this.isAtEnd()&&!this.isImplicitBlockEnd(e);)bn(this.peek(),";")?this.advance():t.push(this.parseExpression());if(this.assertImplicitBlockEnd(e),0===t.length)throw new r("Expected expression",this.peekSourceCodeInfo());return 1===t.length?t[0]:_n([o.SpecialExpression,[Nt.block,t]],this.peekSourceCodeInfo())}assertImplicitBlockEnd(e){if(!this.isImplicitBlockEnd(e))throw new r(`Expected ${e.map(e=>e[1]).join(" or ")}`,this.peekSourceCodeInfo())}isImplicitBlockEnd(e){for(const t of e)if(mn(this.peek(),t))return!0;return!1}parseLoop(e){this.advance(),kn(this.peek()),this.advance();const t=[];let n=this.peek();for(;!this.isAtEnd()&&!xn(n);){const e=this.parseBindingTarget({requireDefaultValue:!0,noRest:!0}),r=e[1][1];e[1][1]=void 0,t.push(_n([o.Binding,[e,r]],e[2])),bn(this.peek(),",")&&this.advance(),n=this.peek()}if(0===t.length)throw new r("Expected binding",this.peekSourceCodeInfo());En(n),this.advance(),wn(this.peek(),"->"),this.advance();const i=this.parseExpression();return _n([o.SpecialExpression,[Nt.loop,t,i]],e[2])}parseTry(e){this.advance();const t=this.parseImplicitBlock(["catch"]);let n;this.advance(),Sn(this.peek())&&(this.advance(),n=this.parseSymbol(),En(this.peek()),this.advance());const r=this.parseImplicitBlock(["end"]);return this.advance(),_n([o.SpecialExpression,[Nt.try,t,n,r]],e[2])}parseForOrDoseq(e){const t="doseq"===e[1];this.advance(),kn(this.peek()),this.advance();const n=[];for(;!this.isAtEnd()&&!xn(this.peek());){const e=this.parseForLoopBinding(),t=n.flatMap(e=>Object.keys(at(e[0][1][0]))),i=at(e[0][1][0]);if(Object.keys(i).some(e=>t.includes(e)))throw new r("Duplicate binding",e[0][2]);n.push(e),bn(this.peek(),",")&&this.advance()}En(this.peek()),this.advance(),wn(this.peek(),"->"),this.advance();const i=this.parseExpression();return _n(t?[o.SpecialExpression,[Nt.doseq,n,i]]:[o.SpecialExpression,[Nt.for,n,i]],e[2])}parseForLoopBinding(){const e=this.parseBinding(),t=[];let n=this.asToken(this.peek());this.assertInternalLoopBindingDelimiter(n,["let","when","while"]);const i=[];if("let"===n[1])for(t.push("&let");dn(n,"let");){const e=this.parseLet(n),t=i.flatMap(e=>Object.keys(at(e[1][0])));if(Object.keys(at(e[1][1][1][0])).some(e=>t.includes(e)))throw new r("Duplicate binding",e[1][1][2]);i.push(e[1][1]),n=this.asToken(this.peek()),this.assertInternalLoopBindingDelimiter(n,["let","when","while"]),n=this.asToken(this.peek())}let s,o;for(;mn(n,"when")||mn(n,"while");){this.advance(),"when"===n[1]?(t.push("&when"),s=this.parseExpression()):(t.push("&while"),o=this.parseExpression()),n=this.asToken(this.peek());const e=t.includes("&when")&&t.includes("&while")?[]:t.includes("&when")?["while"]:["when"];this.assertInternalLoopBindingDelimiter(n,e),n=this.asToken(this.peek())}return this.assertInternalLoopBindingDelimiter(n,[]),[e,i,s,o]}assertInternalLoopBindingDelimiter(e,t){if(!this.isInternalLoopBindingDelimiter(e,t)){const n=`${[...t,","].map(e=>`"${e}"`).join(", ")} or ")"`;throw new r(`Expected symbol ${n}`,e[2])}}isInternalLoopBindingDelimiter(e,t){if(bn(e,",")||xn(e))return!0;for(const n of t){if("let"===n&&dn(e,"let"))return!0;if(["when","while"].includes(n)&&mn(e,n))return!0}return!1}parseBinding(){const e=gn(this.peek()),t=Ge(this.parseSymbol());yn(this.peek(),"in"),this.advance();const n=this.parseExpression();return _n([o.Binding,[_n([et,[t,void 0]],e[2]),n]],e[2])}parseIfOrUnless(e){const t="unless"===e[1];this.advance();const n=this.parseExpression();yn(this.peek(),"then"),this.advance();const r=this.parseImplicitBlock(["else","end"]);let i;return mn(this.peek(),"else")&&(this.advance(),i=this.parseImplicitBlock(["end"])),this.advance(),_n(t?[o.SpecialExpression,[Nt.unless,[n,r,i]]]:[o.SpecialExpression,[Nt.if,[n,r,i]]],e[2])}parseCond(e){this.advance();const t=[];for(;!this.isAtEnd()&&!mn(this.peek(),"end");){yn(this.peek(),"case"),this.advance();const e=this.parseExpression();yn(this.peek(),"then"),this.advance();const n=this.parseImplicitBlock(["case","end"]);if(t.push([e,n]),mn(this.peek(),"end"))break}return yn(this.peek()),this.advance(),_n([o.SpecialExpression,[Nt.cond,t]],e[2])}parseSwitch(e){this.advance();const t=this.parseExpression(),n=[];for(;!this.isAtEnd()&&!mn(this.peek(),"end");){yn(this.peek(),"case"),this.advance();const e=this.parseExpression();yn(this.peek(),"then"),this.advance();const t=this.parseImplicitBlock(["case","end"]);if(n.push([e,t]),mn(this.peek(),"end"))break}return yn(this.peek(),"end"),this.advance(),_n([o.SpecialExpression,[Nt.switch,t,n]],e[2])}isAtEnd(){return this.parseState.position>=this.tokenStream.tokens.length}isAtExpressionEnd(){if(this.isAtEnd())return!0;const e=this.peek();return bn(e)?[";",",",":"].includes(e[1]):!!mn(e)&&["else","when","while","case","catch","let","then","end","do"].includes(e[1])}parseExport(e){this.advance();const t=this.peek();if(dn(t,"let")){const n=this.parseLet(gn(t));return _n([o.SpecialExpression,[Nt["0_def"],n[1][1]]],e[2])}throw new r("Expected let",this.peekSourceCodeInfo())}stringToSymbolNode(e,t){return void 0!==Nt[e]&&"fn"!==e&&"def"!==e&&"defn"!==e?_n([o.SpecialBuiltinSymbol,Nt[e]],t):void 0!==ze[e]?_n([o.NormalBuiltinSymbol,ze[e]],t):_n([o.UserDefinedSymbol,e],t)}stringFromQuotedSymbol(e){return e.substring(1,e.length-1).replace(/(\\{2})|(\\')|\\(.)/g,(e,t,n,r)=>t?"\\":n?"'":`\\${r}`)}parseSymbol(){const e=this.asToken(this.peek());if(this.advance(),!dn(e))throw new r(`Expected symbol token, got ${e[0]}`,e[2]);return"'"===e[1][0]?this.stringToSymbolNode(this.stringFromQuotedSymbol(e[1]),e[2]):this.stringToSymbolNode(e[1],e[2])}parseReservedSymbol(){const e=vn(this.peek());this.advance();const t=e[1];return function(e){return e in Ut}(t)?_n([o.Number,Ut[t]],e[2]):_n([o.ReservedSymbol,e[1]],e[2])}parseNumber(){const e=this.asToken(this.peek());this.advance();const t=e[1],n="-"===t[0],r=(n?t.substring(1):t).replace(/_/g,"");return _n([o.Number,n?-Number(r):Number(r)],e[2])}parseDocString(){const e=this.asToken(this.peek()),t=e[2]?["string",e[1].slice(2,-2),e[2]]:["string",e[1].slice(2,-2)];return se(this.parseString(t)[1])}parseString(e){this.advance();const t=e[1].substring(1,e[1].length-1).replace(/(\\{2})|(\\")|(\\n)|(\\t)|(\\r)|(\\b)|(\\f)|\\(.)/g,(e,t,n,r,i,s,o,a,u)=>t?"\\":r?"\n":i?"\t":s?"\r":o?"\b":a?"\f":n?'"':u);return _n([o.String,t],e[2])}parseRegexpShorthand(){const e=this.asToken(this.peek());this.advance();const t=e[1].lastIndexOf('"'),n=e[1].substring(2,t),r=e[1].substring(t+1),i=_n([o.String,n],e[2]),s=_n([o.String,r],e[2]);return _n([o.NormalExpression,[_n([o.NormalBuiltinSymbol,ze.regexp],e[2]),[i,s]]],e[2])}}const qn=new Set([...At,...jt,...Object.keys(Tt)]);class Yn{originalProgram;originalPosition;prefixProgram="";suffixProgram="";searchString="";suggestions=[];suggestionIndex=null;constructor(e,t,n,r){this.originalProgram=e,this.originalPosition=t;const i=this.originalProgram.slice(0,this.originalPosition),s=n.tokenize(i).tokens.at(-1);s&&"Error"!==s[0]&&(this.searchString=s[1],this.prefixProgram=this.originalProgram.slice(0,this.originalPosition-this.searchString.length),this.suffixProgram=this.originalProgram.slice(this.prefixProgram.length+this.searchString.length),this.originalProgram.slice(this.prefixProgram.length+this.searchString.length),this.suggestions=this.generateSuggestions(r))}getNextSuggestion(){return this.getAutoCompleteSuggestionResult(this.getNextSuggestionSymbol())}getPreviousSuggestion(){return this.getAutoCompleteSuggestionResult(this.getPreviousSuggestionSymbol())}getAutoCompleteSuggestionResult(e){return null===e?null:{program:this.prefixProgram+e+this.suffixProgram,position:this.prefixProgram.length+e.length}}getNextSuggestionSymbol(){return 0===this.suggestions.length?null:(null===this.suggestionIndex?this.suggestionIndex=0:(this.suggestionIndex+=1,this.suggestionIndex>=this.suggestions.length&&(this.suggestionIndex=0)),this.suggestions[this.suggestionIndex])}getPreviousSuggestionSymbol(){return 0===this.suggestions.length?null:(null===this.suggestionIndex?this.suggestionIndex=this.suggestions.length-1:(this.suggestionIndex-=1,this.suggestionIndex<0&&(this.suggestionIndex=this.suggestions.length-1)),this.suggestions[this.suggestionIndex])}getSuggestions(){return[...this.suggestions]}getSearchString(){return this.searchString}generateSuggestions(e){const t=new Set(["0_def","0_defn","0_lambda"]),n=this.generateWithPredicate(e,e=>!t.has(e)&&e.startsWith(this.searchString));n.forEach(e=>t.add(e));const r=this.generateWithPredicate(e,e=>!t.has(e)&&e.toLowerCase().startsWith(this.searchString.toLowerCase()));r.forEach(e=>t.add(e));const i=this.generateWithPredicate(e,e=>!t.has(e)&&e.includes(this.searchString));i.forEach(e=>t.add(e));const s=this.generateWithPredicate(e,e=>!t.has(e)&&e.includes(this.searchString.toLowerCase()));return s.forEach(e=>t.add(e)),[...n,...r,...i,...s]}generateWithPredicate(e,t){const n=new Set;return qn.forEach(e=>{t(e)&&n.add(e)}),Object.keys(e.globalContext??{}).filter(t).forEach(e=>n.add(e)),e.contexts?.forEach(e=>{Object.keys(e).filter(t).forEach(e=>n.add(e))}),Object.keys(e.jsFunctions??{}).filter(t).forEach(e=>n.add(e)),Object.keys(e.values??{}).filter(t).forEach(e=>n.add(e)),[...n].sort((e,t)=>e.localeCompare(t))}}class Gn{cache={};firstEntry=void 0;lastEntry=void 0;_size=0;maxSize;constructor(e){var t;if(this.maxSize=null===e?null:(t=e,Math.max(0,Math.ceil(t))),"number"==typeof this.maxSize&&this.maxSize<1)throw new Error(`1 is the minimum maxSize, got ${d(e)}`)}getContent(){return Object.entries(this.cache).reduce((e,[t,n])=>(e[t]=n.value,e),{})}get size(){return this._size}get(e){return this.cache[e]?.value}clear(){this.cache={},this.firstEntry=void 0,this.lastEntry=void 0,this._size=0}has(e){return!!this.cache[e]}set(e,t){if(this.has(e))throw new Error(`AstCache - key already present: ${e}`);const n={value:t,nextEntry:void 0,key:e};for(this.cache[e]=n,this._size+=1,this.lastEntry&&(this.lastEntry.nextEntry=n),this.lastEntry=n,this.firstEntry||(this.firstEntry=this.lastEntry);null!==this.maxSize&&this.size>this.maxSize;)this.dropFirstEntry()}dropFirstEntry(){const e=this.firstEntry;delete this.cache[e.key],this._size-=1,this.firstEntry=e.nextEntry}}return e.Lits=class{astCache;astCacheSize;debug;modules;constructor(e={}){if(this.debug=e.debug??!1,this.astCacheSize=e.astCacheSize??null,this.astCacheSize){this.astCache=new Gn(this.astCacheSize);const t=e.initialCache??{};for(const e of Object.keys(t))this.astCache.set(e,t[e])}else this.astCache=null;const t=e.modules??[];this.modules=new Map(t.map(e=>[e.name,e]))}getRuntimeInfo(){return{astCacheSize:this.astCacheSize,astCache:this.astCache,debug:this.debug}}run(e,t={}){const n=this.generateAst(e,t);return this.evaluate(n,t)}context(e,t={}){const n="string"==typeof e?this.generateAst(e,t):e,r=Lt(t,this.modules);return Pt(n,r),r.globalContext}getUndefinedSymbols(e,t={}){const n="string"==typeof e?this.generateAst(e,t):e,r=Lt(t,this.modules);return Ot(n,r,It,Mt)}tokenize(e,t={}){const n=function(e,t,n){let r=0;const i={tokens:[],filePath:n,hasDebugData:t};for(;r<e.length;){const s=t?hn(e,r,n):void 0,o=pn(e,r),[a,u]=o;r+=a,u&&(s&&(u[2]=s),i.tokens.push(u))}return i}(e,this.debug,t.filePath);return t.minify?Bn(n,{removeWhiteSpace:!1}):n}parse(e){const t={body:[],hasDebugData:(e=Bn(e,{removeWhiteSpace:!0})).hasDebugData};return t.body=new Wn(e,{position:0}).parse(),t}evaluate(e,t){return Pt(e,Lt(t,this.modules))}transformSymbols(e,t){return function(e,t){return{...e,tokens:e.tokens.map(e=>dn(e)?[e[0],t(e[1])]:e)}}(e,t)}untokenize(e){return function(e){return e.tokens.reduce((e,t)=>`${e}${t[1]}`,"")}(e)}apply(e,t,n={}){const r="FN_2eb7b316_471c_5bfa_90cb_d3dfd9164a59",i=this.generateApplyFunctionCall(r,t),s=this.generateAst(i,n),o=t.reduce((e,t,n)=>(e[`${r}_${n}`]=t,e),{[r]:e});return n.values={...n.values,...o},this.evaluate(s,n)}generateApplyFunctionCall(e,t){const n=t.map((t,n)=>`${e}_${n}`).join(", ");return`${e}(${n})`}generateAst(e,t){if(this.astCache){const t=this.astCache.get(e);if(t)return t}const n=this.tokenize(e,{filePath:t.filePath}),r=this.parse(n);return this.astCache?.set(e,r),r}getAutoCompleter(e,t,n={}){return new Yn(e,t,this,n)}},e.asLitsFunction=function(e,t){return S(e,t),e},e.asNativeJsFunction=function(e,t){return N(e,t),e},e.asUserDefinedFunction=function(e,t){return x(e,t),e},e.assertLitsFunction=S,e.assertNativeJsFunction=N,e.assertUserDefinedFunction=x,e.isBuiltinFunction=function(e){return b(e)&&"Builtin"===e.functionType},e.isGrid=xe,e.isLitsError=function(e){return e instanceof r},e.isLitsFunction=w,e.isMatrix=Ee,e.isNativeJsFunction=E,e.isUserDefinedFunction=k,e.isVector=we,e.normalExpressionKeys=At,e.specialExpressionKeys=jt,e}({});
2
2
  //# sourceMappingURL=lits.iife.js.map