@mojir/lits 2.1.41 → 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 (315) hide show
  1. package/README.md +18 -17
  2. package/dist/cli/cli.js +13018 -13113
  3. package/dist/cli/reference/api.d.ts +31 -17
  4. package/dist/cli/reference/index.d.ts +129 -209
  5. package/dist/cli/src/builtin/core/vector.d.ts +2 -0
  6. package/dist/cli/src/builtin/interface.d.ts +23 -23
  7. package/dist/cli/src/builtin/modules/bitwise/index.d.ts +2 -0
  8. package/dist/cli/src/builtin/modules/collection/index.d.ts +2 -0
  9. package/dist/cli/src/builtin/modules/functional/index.d.ts +2 -0
  10. package/dist/cli/src/builtin/modules/math/index.d.ts +2 -0
  11. package/dist/cli/src/builtin/modules/sequence/index.d.ts +2 -0
  12. package/dist/cli/src/builtin/modules/string/index.d.ts +2 -0
  13. package/dist/cli/src/tokenizer/token.d.ts +2 -2
  14. package/dist/full.esm.js +1 -1
  15. package/dist/full.esm.js.map +1 -1
  16. package/dist/full.js +1 -1
  17. package/dist/full.js.map +1 -1
  18. package/dist/index.esm.js +1 -1
  19. package/dist/index.esm.js.map +1 -1
  20. package/dist/index.js +1 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/lits.iife.js +1 -1
  23. package/dist/lits.iife.js.map +1 -1
  24. package/dist/modules/assert.esm.js +1 -1
  25. package/dist/modules/assert.esm.js.map +1 -1
  26. package/dist/modules/assert.js +1 -1
  27. package/dist/modules/assert.js.map +1 -1
  28. package/dist/modules/bitwise.esm.js +2 -0
  29. package/dist/modules/bitwise.esm.js.map +1 -0
  30. package/dist/modules/bitwise.js +2 -0
  31. package/dist/modules/bitwise.js.map +1 -0
  32. package/dist/modules/collection.esm.js +2 -0
  33. package/dist/modules/collection.esm.js.map +1 -0
  34. package/dist/modules/collection.js +2 -0
  35. package/dist/modules/collection.js.map +1 -0
  36. package/dist/modules/functional.esm.js +2 -0
  37. package/dist/modules/functional.esm.js.map +1 -0
  38. package/dist/modules/functional.js +2 -0
  39. package/dist/modules/functional.js.map +1 -0
  40. package/dist/modules/grid.esm.js +1 -1
  41. package/dist/modules/grid.esm.js.map +1 -1
  42. package/dist/modules/grid.js +1 -1
  43. package/dist/modules/grid.js.map +1 -1
  44. package/dist/modules/linear-algebra.esm.js +2 -0
  45. package/dist/modules/linear-algebra.esm.js.map +1 -0
  46. package/dist/modules/linear-algebra.js +2 -0
  47. package/dist/modules/linear-algebra.js.map +1 -0
  48. package/dist/modules/math.esm.js +2 -0
  49. package/dist/modules/math.esm.js.map +1 -0
  50. package/dist/modules/math.js +2 -0
  51. package/dist/modules/math.js.map +1 -0
  52. package/dist/modules/matrix.esm.js +1 -1
  53. package/dist/modules/matrix.esm.js.map +1 -1
  54. package/dist/modules/matrix.js +1 -1
  55. package/dist/modules/matrix.js.map +1 -1
  56. package/dist/modules/number-theory.esm.js +2 -0
  57. package/dist/modules/number-theory.esm.js.map +1 -0
  58. package/dist/modules/number-theory.js +2 -0
  59. package/dist/modules/number-theory.js.map +1 -0
  60. package/dist/modules/random.esm.js +1 -1
  61. package/dist/modules/random.esm.js.map +1 -1
  62. package/dist/modules/random.js +1 -1
  63. package/dist/modules/random.js.map +1 -1
  64. package/dist/modules/reference/api.d.ts +31 -17
  65. package/dist/modules/reference/index.d.ts +129 -209
  66. package/dist/modules/sequence.esm.js +2 -0
  67. package/dist/modules/sequence.esm.js.map +1 -0
  68. package/dist/modules/sequence.js +2 -0
  69. package/dist/modules/sequence.js.map +1 -0
  70. package/dist/modules/src/builtin/core/vector.d.ts +2 -0
  71. package/dist/modules/src/builtin/interface.d.ts +23 -23
  72. package/dist/modules/src/builtin/modules/bitwise/index.d.ts +2 -0
  73. package/dist/modules/src/builtin/modules/collection/index.d.ts +2 -0
  74. package/dist/modules/src/builtin/modules/functional/index.d.ts +2 -0
  75. package/dist/modules/src/builtin/modules/math/index.d.ts +2 -0
  76. package/dist/modules/src/builtin/modules/sequence/index.d.ts +2 -0
  77. package/dist/modules/src/builtin/modules/string/index.d.ts +2 -0
  78. package/dist/modules/src/full.d.ts +5 -2
  79. package/dist/modules/src/modules/bitwise.d.ts +2 -0
  80. package/dist/modules/src/modules/collection.d.ts +2 -0
  81. package/dist/modules/src/modules/functional.d.ts +2 -0
  82. package/dist/modules/src/modules/linear-algebra.d.ts +2 -0
  83. package/dist/modules/src/modules/math.d.ts +2 -0
  84. package/dist/modules/src/modules/number-theory.d.ts +2 -0
  85. package/dist/modules/src/modules/sequence.d.ts +2 -0
  86. package/dist/modules/src/modules/string.d.ts +2 -0
  87. package/dist/modules/src/tokenizer/token.d.ts +2 -2
  88. package/dist/modules/string.esm.js +2 -0
  89. package/dist/modules/string.esm.js.map +1 -0
  90. package/dist/modules/string.js +2 -0
  91. package/dist/modules/string.js.map +1 -0
  92. package/dist/modules/vector.esm.js +1 -1
  93. package/dist/modules/vector.esm.js.map +1 -1
  94. package/dist/modules/vector.js +1 -1
  95. package/dist/modules/vector.js.map +1 -1
  96. package/dist/reference/api.d.ts +31 -17
  97. package/dist/reference/index.d.ts +129 -209
  98. package/dist/src/builtin/core/vector.d.ts +2 -0
  99. package/dist/src/builtin/interface.d.ts +23 -23
  100. package/dist/src/builtin/modules/bitwise/index.d.ts +2 -0
  101. package/dist/src/builtin/modules/collection/index.d.ts +2 -0
  102. package/dist/src/builtin/modules/functional/index.d.ts +2 -0
  103. package/dist/src/builtin/modules/math/index.d.ts +2 -0
  104. package/dist/src/builtin/modules/sequence/index.d.ts +2 -0
  105. package/dist/src/builtin/modules/string/index.d.ts +2 -0
  106. package/dist/src/full.d.ts +5 -2
  107. package/dist/src/modules/bitwise.d.ts +2 -0
  108. package/dist/src/modules/collection.d.ts +2 -0
  109. package/dist/src/modules/functional.d.ts +2 -0
  110. package/dist/src/modules/linear-algebra.d.ts +2 -0
  111. package/dist/src/modules/math.d.ts +2 -0
  112. package/dist/src/modules/number-theory.d.ts +2 -0
  113. package/dist/src/modules/sequence.d.ts +2 -0
  114. package/dist/src/modules/string.d.ts +2 -0
  115. package/dist/src/tokenizer/token.d.ts +2 -2
  116. package/dist/testFramework.esm.js +1 -1
  117. package/dist/testFramework.esm.js.map +1 -1
  118. package/dist/testFramework.js +1 -1
  119. package/dist/testFramework.js.map +1 -1
  120. package/package.json +39 -9
  121. package/dist/cli/src/builtin/modules/vector/reductionFunctions/max.d.ts +0 -2
  122. package/dist/cli/src/builtin/modules/vector/reductionFunctions/min.d.ts +0 -2
  123. package/dist/modules/linearAlgebra.esm.js +0 -2
  124. package/dist/modules/linearAlgebra.esm.js.map +0 -1
  125. package/dist/modules/linearAlgebra.js +0 -2
  126. package/dist/modules/linearAlgebra.js.map +0 -1
  127. package/dist/modules/numberTheory.esm.js +0 -2
  128. package/dist/modules/numberTheory.esm.js.map +0 -1
  129. package/dist/modules/numberTheory.js +0 -2
  130. package/dist/modules/numberTheory.js.map +0 -1
  131. package/dist/modules/src/builtin/modules/vector/reductionFunctions/max.d.ts +0 -2
  132. package/dist/modules/src/builtin/modules/vector/reductionFunctions/min.d.ts +0 -2
  133. package/dist/modules/src/modules/linearAlgebra.d.ts +0 -2
  134. package/dist/modules/src/modules/numberTheory.d.ts +0 -2
  135. package/dist/src/builtin/modules/vector/reductionFunctions/max.d.ts +0 -2
  136. package/dist/src/builtin/modules/vector/reductionFunctions/min.d.ts +0 -2
  137. package/dist/src/modules/linearAlgebra.d.ts +0 -2
  138. package/dist/src/modules/numberTheory.d.ts +0 -2
  139. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/docs.d.ts +0 -0
  140. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/calcFractionalRanks.d.ts +0 -0
  141. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/collinear.d.ts +0 -0
  142. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/corrleation.d.ts +0 -0
  143. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/covariance.d.ts +0 -0
  144. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/dot.d.ts +0 -0
  145. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/gaussJordanElimination.d.ts +0 -0
  146. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/getUnit.d.ts +0 -0
  147. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/isZeroVector.d.ts +0 -0
  148. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/kendallTau.d.ts +0 -0
  149. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/length.d.ts +0 -0
  150. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/pearsonCorr.d.ts +0 -0
  151. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/scale.d.ts +0 -0
  152. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/solve.d.ts +0 -0
  153. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/subtract.d.ts +0 -0
  154. /package/dist/cli/src/builtin/modules/{linearAlgebra → linear-algebra}/index.d.ts +0 -0
  155. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/binomialCefficient.d.ts +0 -0
  156. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/combinations.d.ts +0 -0
  157. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/derangements.d.ts +0 -0
  158. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/divisors.d.ts +0 -0
  159. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/docs.d.ts +0 -0
  160. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/factorial.d.ts +0 -0
  161. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/index.d.ts +0 -0
  162. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/partitions.d.ts +0 -0
  163. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/permutations.d.ts +0 -0
  164. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/powerSet.d.ts +0 -0
  165. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/primeFactors.d.ts +0 -0
  166. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/abundant.d.ts +0 -0
  167. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/arithmetic.d.ts +0 -0
  168. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/bell.d.ts +0 -0
  169. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/bernoulli.d.ts +0 -0
  170. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/catalan.d.ts +0 -0
  171. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/collatz.d.ts +0 -0
  172. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/composite.d.ts +0 -0
  173. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/deficient.d.ts +0 -0
  174. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/factorial.d.ts +0 -0
  175. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/fibonacci.d.ts +0 -0
  176. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/geometric.d.ts +0 -0
  177. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/golomb.d.ts +0 -0
  178. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/happy.d.ts +0 -0
  179. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/index.d.ts +0 -0
  180. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/juggler.d.ts +0 -0
  181. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/lookAndSay.d.ts +0 -0
  182. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/lucas.d.ts +0 -0
  183. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/lucky.d.ts +0 -0
  184. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/mersenne.d.ts +0 -0
  185. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/padovan.d.ts +0 -0
  186. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/partition.d.ts +0 -0
  187. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/pell.d.ts +0 -0
  188. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/perfect.d.ts +0 -0
  189. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/perfectCube.d.ts +0 -0
  190. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/perfectPower.d.ts +0 -0
  191. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/perfectSquare.d.ts +0 -0
  192. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/poligonal.d.ts +0 -0
  193. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/prime.d.ts +0 -0
  194. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/recaman.d.ts +0 -0
  195. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/sylvester.d.ts +0 -0
  196. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/thueMorse.d.ts +0 -0
  197. /package/dist/cli/src/builtin/modules/{numberTheory → number-theory}/sequences/tribonacci.d.ts +0 -0
  198. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/docs.d.ts +0 -0
  199. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/calcFractionalRanks.d.ts +0 -0
  200. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/collinear.d.ts +0 -0
  201. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/corrleation.d.ts +0 -0
  202. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/covariance.d.ts +0 -0
  203. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/dot.d.ts +0 -0
  204. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/gaussJordanElimination.d.ts +0 -0
  205. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/getUnit.d.ts +0 -0
  206. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/isZeroVector.d.ts +0 -0
  207. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/kendallTau.d.ts +0 -0
  208. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/length.d.ts +0 -0
  209. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/pearsonCorr.d.ts +0 -0
  210. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/scale.d.ts +0 -0
  211. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/solve.d.ts +0 -0
  212. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/subtract.d.ts +0 -0
  213. /package/dist/modules/src/builtin/modules/{linearAlgebra → linear-algebra}/index.d.ts +0 -0
  214. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/binomialCefficient.d.ts +0 -0
  215. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/combinations.d.ts +0 -0
  216. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/derangements.d.ts +0 -0
  217. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/divisors.d.ts +0 -0
  218. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/docs.d.ts +0 -0
  219. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/factorial.d.ts +0 -0
  220. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/index.d.ts +0 -0
  221. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/partitions.d.ts +0 -0
  222. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/permutations.d.ts +0 -0
  223. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/powerSet.d.ts +0 -0
  224. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/primeFactors.d.ts +0 -0
  225. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/abundant.d.ts +0 -0
  226. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/arithmetic.d.ts +0 -0
  227. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/bell.d.ts +0 -0
  228. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/bernoulli.d.ts +0 -0
  229. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/catalan.d.ts +0 -0
  230. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/collatz.d.ts +0 -0
  231. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/composite.d.ts +0 -0
  232. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/deficient.d.ts +0 -0
  233. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/factorial.d.ts +0 -0
  234. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/fibonacci.d.ts +0 -0
  235. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/geometric.d.ts +0 -0
  236. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/golomb.d.ts +0 -0
  237. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/happy.d.ts +0 -0
  238. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/index.d.ts +0 -0
  239. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/juggler.d.ts +0 -0
  240. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/lookAndSay.d.ts +0 -0
  241. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/lucas.d.ts +0 -0
  242. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/lucky.d.ts +0 -0
  243. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/mersenne.d.ts +0 -0
  244. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/padovan.d.ts +0 -0
  245. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/partition.d.ts +0 -0
  246. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/pell.d.ts +0 -0
  247. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/perfect.d.ts +0 -0
  248. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/perfectCube.d.ts +0 -0
  249. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/perfectPower.d.ts +0 -0
  250. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/perfectSquare.d.ts +0 -0
  251. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/poligonal.d.ts +0 -0
  252. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/prime.d.ts +0 -0
  253. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/recaman.d.ts +0 -0
  254. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/sylvester.d.ts +0 -0
  255. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/thueMorse.d.ts +0 -0
  256. /package/dist/modules/src/builtin/modules/{numberTheory → number-theory}/sequences/tribonacci.d.ts +0 -0
  257. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/docs.d.ts +0 -0
  258. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/calcFractionalRanks.d.ts +0 -0
  259. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/collinear.d.ts +0 -0
  260. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/corrleation.d.ts +0 -0
  261. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/covariance.d.ts +0 -0
  262. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/dot.d.ts +0 -0
  263. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/gaussJordanElimination.d.ts +0 -0
  264. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/getUnit.d.ts +0 -0
  265. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/isZeroVector.d.ts +0 -0
  266. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/kendallTau.d.ts +0 -0
  267. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/length.d.ts +0 -0
  268. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/pearsonCorr.d.ts +0 -0
  269. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/scale.d.ts +0 -0
  270. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/solve.d.ts +0 -0
  271. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/helpers/subtract.d.ts +0 -0
  272. /package/dist/src/builtin/modules/{linearAlgebra → linear-algebra}/index.d.ts +0 -0
  273. /package/dist/src/builtin/modules/{numberTheory → number-theory}/binomialCefficient.d.ts +0 -0
  274. /package/dist/src/builtin/modules/{numberTheory → number-theory}/combinations.d.ts +0 -0
  275. /package/dist/src/builtin/modules/{numberTheory → number-theory}/derangements.d.ts +0 -0
  276. /package/dist/src/builtin/modules/{numberTheory → number-theory}/divisors.d.ts +0 -0
  277. /package/dist/src/builtin/modules/{numberTheory → number-theory}/docs.d.ts +0 -0
  278. /package/dist/src/builtin/modules/{numberTheory → number-theory}/factorial.d.ts +0 -0
  279. /package/dist/src/builtin/modules/{numberTheory → number-theory}/index.d.ts +0 -0
  280. /package/dist/src/builtin/modules/{numberTheory → number-theory}/partitions.d.ts +0 -0
  281. /package/dist/src/builtin/modules/{numberTheory → number-theory}/permutations.d.ts +0 -0
  282. /package/dist/src/builtin/modules/{numberTheory → number-theory}/powerSet.d.ts +0 -0
  283. /package/dist/src/builtin/modules/{numberTheory → number-theory}/primeFactors.d.ts +0 -0
  284. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/abundant.d.ts +0 -0
  285. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/arithmetic.d.ts +0 -0
  286. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/bell.d.ts +0 -0
  287. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/bernoulli.d.ts +0 -0
  288. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/catalan.d.ts +0 -0
  289. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/collatz.d.ts +0 -0
  290. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/composite.d.ts +0 -0
  291. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/deficient.d.ts +0 -0
  292. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/factorial.d.ts +0 -0
  293. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/fibonacci.d.ts +0 -0
  294. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/geometric.d.ts +0 -0
  295. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/golomb.d.ts +0 -0
  296. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/happy.d.ts +0 -0
  297. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/index.d.ts +0 -0
  298. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/juggler.d.ts +0 -0
  299. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/lookAndSay.d.ts +0 -0
  300. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/lucas.d.ts +0 -0
  301. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/lucky.d.ts +0 -0
  302. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/mersenne.d.ts +0 -0
  303. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/padovan.d.ts +0 -0
  304. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/partition.d.ts +0 -0
  305. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/pell.d.ts +0 -0
  306. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/perfect.d.ts +0 -0
  307. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/perfectCube.d.ts +0 -0
  308. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/perfectPower.d.ts +0 -0
  309. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/perfectSquare.d.ts +0 -0
  310. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/poligonal.d.ts +0 -0
  311. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/prime.d.ts +0 -0
  312. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/recaman.d.ts +0 -0
  313. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/sylvester.d.ts +0 -0
  314. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/thueMorse.d.ts +0 -0
  315. /package/dist/src/builtin/modules/{numberTheory → number-theory}/sequences/tribonacci.d.ts +0 -0
package/dist/index.esm.js CHANGED
@@ -1,2 +1,2 @@
1
- function e(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 t extends Error{params;constructor(e){super(`recur, params: ${e}`),Object.setPrototypeOf(this,t.prototype),this.name="RecurSignal",this.params=e}}class n extends Error{sourceCodeInfo;shortMessage;constructor(t,r){const i=t instanceof Error?t.message:`${t}`;super(function(t,n){if(!n)return t;const r=`${n.position.line}:${n.position.column}`;return`${t}${n.filePath?`\n${n.filePath}:${r}`:`\nLocation ${r}`}\n${n.code}\n${e(n)}`}(i,r)),this.shortMessage=i,this.sourceCodeInfo=r,Object.setPrototypeOf(this,n.prototype),this.name="LitsError"}getCodeMarker(){return this.sourceCodeInfo&&e(this.sourceCodeInfo)}}class r extends n{userMessage;constructor(e,t){super(e,t),this.userMessage=e,Object.setPrototypeOf(this,r.prototype),this.name="UserDefinedError"}}class i extends n{symbol;constructor(e,t){super(`Undefined symbol '${e}'.`,t),this.symbol=e,Object.setPrototypeOf(this,i.prototype),this.name="UndefinedSymbolError"}}function s(e){return e instanceof n}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,r){return new n(`Expected ${e}, got ${d(t)}.`,y(t,r))}function m(e,t){return v(e,t),e}function v(e,t){if(!function(e){return void 0!==e}(e))throw new n("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 S(e,t){return x(e,t),e}function x(e,t){if(!w(e))throw g("LitsFunction",e,t)}function k(e){return w(e)&&"UserDefined"===e.functionType}function E(e,t){return N(e,t),e}function N(e,t){if(!k(e))throw g("NativeJsFunction",e,t)}function A(e){return w(e)&&"NativeJsFunction"===e.functionType}function I(e,t){return $(e,t),e}function $(e,t){if(!A(e))throw g("NativeJsFunction",e,t)}function j(e){return b(e)&&"Builtin"===e.functionType}function O(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 C(e,t,r={}){if(!O(e,r))throw new n(`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(" ")}(r)}, got ${d(e)}.`,y(e,t))}function F(e,t,n={}){return C(e,t,n),e}function M(e){return void 0!==e}function U(e,t){return T(e,t),e}function T(e,t){if(!M(e))throw g("not undefined",e,t)}function B(e){return Array.isArray(e)||"string"==typeof e}function P(e,t){return R(e,t),e}function R(e,t){if(!B(e))throw g("string or array",e,t)}function D(e){return!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof RegExp||w(e)||W(e))}function _(e,t){if(!D(e))throw g("object",e,t)}function L(e){return B(e)||D(e)}function V(e,t){return z(e,t),e}function z(e,t){if(!L(e))throw g("string, array or object",e,t)}function W(e){return null!==e&&"object"==typeof e&&!!e[f]}function J(e,t){if(!function(e){return W(e)||"string"==typeof e}(e))throw g("string or RegularExpression",e,t)}function q(e,t){return Y(e,t),e}function Y(e,t){if(!function(e){return"number"==typeof e||!!L(e)||!!w(e)}(e))throw g("FunctionLike",e,t)}function G(e,t){const{min:n}=e;return!("number"==typeof n&&t<n)}function X(e){return"number"==typeof e||L(e)?H(1):e.arity}function Z(e,t,r){const{min:i,max:s}=e;if("number"==typeof i&&t<i)throw new n(`Wrong number of arguments, expected at least ${i}, got ${d(t)}.`,r);if("number"==typeof s&&t>s)throw new n(`Wrong number of arguments, expected at most ${s}, got ${d(t)}.`,r)}function H(e){return{min:e,max:e}}const K={"<<":{evaluate:([e,t],n)=>(C(e,n,{integer:!0}),C(t,n,{integer:!0,nonNegative:!0}),e<<t),arity:H(2)},">>":{evaluate:([e,t],n)=>(C(e,n,{integer:!0}),C(t,n,{integer:!0,nonNegative:!0}),e>>t),arity:H(2)},">>>":{evaluate:([e,t],n)=>(C(e,n,{integer:!0}),C(t,n,{integer:!0,nonNegative:!0}),e>>>t),arity:H(2)},"bit-not":{evaluate:([e],t)=>(C(e,t,{integer:!0}),~e),arity:H(1)},"&":{evaluate:([e,...t],n)=>(C(e,n,{integer:!0}),t.reduce((e,t)=>(C(t,n,{integer:!0}),e&t),e)),arity:{min:2}},"bit-and-not":{evaluate:([e,...t],n)=>(C(e,n,{integer:!0}),t.reduce((e,t)=>(C(t,n,{integer:!0}),e&~t),e)),arity:{min:2}},"|":{evaluate:([e,...t],n)=>(C(e,n,{integer:!0}),t.reduce((e,t)=>(C(t,n,{integer:!0}),e|t),e)),arity:{min:2}},xor:{evaluate:([e,...t],n)=>(C(e,n,{integer:!0}),t.reduce((e,t)=>(C(t,n,{integer:!0}),e^t),e)),arity:{min:2}},"bit-flip":{evaluate:([e,t],n)=>{C(e,n,{integer:!0}),C(t,n,{integer:!0,nonNegative:!0});return e^1<<t},arity:H(2)},"bit-set":{evaluate:([e,t],n)=>{C(e,n,{integer:!0}),C(t,n,{integer:!0,nonNegative:!0});return e|1<<t},arity:H(2)},"bit-clear":{evaluate:([e,t],n)=>{C(e,n,{integer:!0}),C(t,n,{integer:!0,nonNegative:!0});return e&~(1<<t)},arity:H(2)},"bit-test":{evaluate:([e,t],n)=>{C(e,n,{integer:!0}),C(t,n,{integer:!0,nonNegative:!0});return!!(e&1<<t)},arity:H(2)}};function Q(e,t={}){return"string"==typeof e&&((!t.nonEmpty||0!==e.length)&&(!t.char||1===e.length))}function ee(e,t,n={}){if(!Q(e,n))throw g(""+(n.nonEmpty?"non empty string":n.char?"character":"string"),e,t)}function te(e,t,n={}){return ee(e,t,n),e}function ne(e){return"string"==typeof e||"number"==typeof e}function re(e,t){return ie(e,t),e}function ie(e,t){if(!ne(e))throw g("string or number",e,t)}function se(e,t){return!!L(e)&&("string"==typeof e||Array.isArray(e)?!!O(t,{integer:!0})&&(t>=0&&t<e.length):!!Object.getOwnPropertyDescriptor(e,t))}function oe(e,t,r){if(ie(e,r),ie(t,r),"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 n(`Cannot compare values of different types: ${typeof e} and ${typeof t}`,r)}function ae(e,t,n){if(e===t)return!0;if("number"==typeof e&&"number"==typeof t)return function(e,t,n=de){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(!ae(U(e[r],n),U(t[r],n),n))return!1;return!0}if(W(e)&&W(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=te(r[i],n);if(!ae(e[s],t[s],n))return!1}return!0}return!1}function ue(e){return Math.max(0,Math.ceil(e))}function ce(e){return e??null}function le(e){return D(e)?Object.entries(e).reduce((e,t)=>{const[n,r]=t;return e[n]=le(r),e},{}):Array.isArray(e)?e.map(e=>le(e)):e}function fe(e){return le(e)}function he(...e){const t=new Set;for(const n of e)n.forEach(e=>t.add(e));return t}function pe(e,t){t.forEach(t=>e.add(t))}const de=1e-10;function ye(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 ge(e,t){if(!Array.isArray(e))throw g("array",e,t)}function me(e,t){if(!function(e){return Array.isArray(e)&&e.every(e=>"string"==typeof e)}(e))throw g("array of strings",e,t)}function ve(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 be(e,t,n){const r=fe(e);return{coll:r,innerCollMeta:t.slice(0,t.length-1).reduce((e,t)=>{const r=e.coll;let i;return Array.isArray(r)?(C(t,n),i=V(r[t],n)):(_(r,n),ee(t,n),se(e.coll,t)||(r[t]={}),i=V(r[t],n)),{coll:i,parent:r}},{coll:r,parent:{}})}}function we(e,t){if(D(e)){if("string"==typeof t&&se(e,t))return ce(e[t])}else if(O(t,{nonNegative:!0,integer:!0})&&t>=0&&t<e.length)return ce(e[t])}function Se(e,t,n,r,i,s,o){if(D(e)){ee(t,o);const a={...e};return a[t]=s(n,[a[t],...r],i,o),a}{C(t,o);const a=ue(t);if(C(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?te(s(n,[e,...r],i,o),o,{char:!0}):e);return a===e.length&&(t[a]=te(s(n,[void 0,...r],i,o),o,{char:!0})),t.join("")}}}function xe(e,t,n,r){if(z(e,r),ie(t,r),Array.isArray(e)||"string"==typeof e){if(C(t,r,{integer:!0}),C(t,r,{gte:0}),C(t,r,{lte:e.length}),"string"==typeof e)return ee(n,r,{char:!0}),`${e.slice(0,t)}${n}${e.slice(t+1)}`;const i=[...e];return i[t]=n,i}ee(t,r);const i={...e};return i[t]=n,i}const ke={filter:{evaluate:([e,t],n,r,{executeFunction:i})=>{if(z(e,n),Y(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:H(2)},filteri:{evaluate:([e,t],n,r,{executeFunction:i})=>{if(z(e,n),Y(t,n),Array.isArray(e)){return e.filter((e,s)=>i(t,[e,s],r,n))}return Q(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:H(2)},map:{evaluate:(e,t,r,{executeFunction:i})=>{const s=q(e.at(-1),t);if(D(e[0]))return function({colls:e,contextStack:t,executeFunction:r,fn:i,sourceCodeInfo:s}){_(e[0],s);const o=Object.keys(e[0]),a={};return e.forEach(e=>{_(e,s);const t=Object.keys(e);if(t.length!==o.length)throw new n(`All objects must have the same keys. Expected: ${o.join(", ")}. Found: ${t.join(", ")}`,s);if(!t.every(e=>o.includes(e)))throw new n(`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,n)=>(e[n]=r(i,a[n],t,s),e),{})}({colls:e.slice(0,-1),fn:s,sourceCodeInfo:t,contextStack:r,executeFunction:i});const o=e.slice(0,-1);R(o[0],t);const a="string"==typeof o[0];let u=o[0].length;o.slice(1).forEach(e=>{a?ee(e,t):ge(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,r,t));return a?(l.forEach(e=>ee(e,t)),l.join("")):l},arity:{min:2}},mapi:{evaluate:([e,t],n,r,{executeFunction:i})=>(z(e,n),Y(t,n),Array.isArray(e)?e.map((e,s)=>i(t,[e,s],r,n)):Q(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:H(2)},reduce:{evaluate:([e,t,n],r,i,{executeFunction:s})=>(z(e,r),Y(t,r),T(n,r),"string"==typeof e?(ee(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:H(3)},reducei:{evaluate:([e,t,n],r,i,{executeFunction:s})=>(z(e,r),Y(t,r),T(n,r),"string"==typeof e?(ee(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:H(3)},"reduce-right":{evaluate:([e,t,n],r,i,{executeFunction:s})=>(z(e,r),Y(t,r),T(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:H(3)},"reducei-right":{evaluate:([e,t,n],r,i,{executeFunction:s})=>(z(e,r),Y(t,r),T(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:H(3)},reductions:{evaluate:([e,t,n],r,i,{executeFunction:s})=>{if(z(e,r),Y(t,r),T(n,r),T(n,r),"string"==typeof e){if(ee(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:H(3)},reductionsi:{evaluate:([e,t,n],r,i,{executeFunction:s})=>{if(z(e,r),Y(t,r),T(n,r),T(n,r),"string"==typeof e){if(ee(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:H(3)},get:{evaluate:(e,t)=>{const[n,r]=e,i=ce(e[2]);if(ie(r,t),null===n)return i;z(n,t);const s=we(n,r);return void 0===s?i:s},arity:{min:2,max:3}},"get-in":{evaluate:(e,t)=>{let n=ce(e[0]);const r=e[1]??[],i=ce(e[2]);ge(r,t);for(const e of r){if(ie(e,t),!L(n))return i;{const t=we(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:(z(e,t),Array.isArray(e)?e.length:Object.keys(e).length),arity:H(1)},"contains?":{evaluate:([e,t],n)=>null!==e&&(z(e,n),Q(e)?(ee(t,n),e.includes(t)):B(e)?(T(t,n),!!e.find(e=>ae(U(e),t,n))):(ee(t,n),t in e)),arity:H(2)},assoc:{evaluate:([e,t,n],r)=>(z(e,r),ie(t,r),T(n,r),xe(e,t,n,r)),arity:H(3)},"assoc-in":{evaluate:([e,t,n],r)=>{if(z(e,r),ge(t,r),T(n,r),1===t.length)return ie(t[0],r),xe(e,t[0],n,r);const{coll:i,innerCollMeta:s}=be(e,t,r),o=re(t[t.length-1],r),a=re(t[t.length-2],r);return Array.isArray(s.parent)?(C(a,r),s.parent[a]=xe(s.coll,o,n,r)):(ee(a,r),s.parent[a]=xe(s.coll,o,n,r)),i},arity:H(3)},update:{evaluate:([e,t,n,...r],i,s,{executeFunction:o})=>(z(e,i),ie(t,i),Y(n,i),Se(e,t,n,r,s,o,i)),arity:{min:3}},"update-in":{evaluate:([e,t,n,...r],i,s,{executeFunction:o})=>{if(z(e,i),ge(t,i),Y(n,i),1===t.length)return ie(t[0],i),Se(e,t[0],n,r,s,o,i);const{coll:a,innerCollMeta:u}=be(e,t,i),c=re(t[t.length-1],i),l=re(t[t.length-2],i);return Array.isArray(u.parent)?(C(l,i),u.parent[l]=Se(u.coll,c,n,r,s,o,i)):(ee(l,i),u.parent[l]=Se(u.coll,c,n,r,s,o,i)),a},arity:{min:3}},"++":{evaluate:(e,t)=>(O(e[0])||z(e[0],t),Array.isArray(e[0])?e.reduce((e,n)=>(ge(n,t),e.concat(n)),[]):ne(e[0])?e.reduce((e,n)=>(ie(n,t),`${e}${n}`),""):e.reduce((e,n)=>(_(n,t),Object.assign(e,n)),{})),arity:{min:1}},"not-empty":{evaluate:([e],t)=>null===e?null:(z(e,t),"string"==typeof e||Array.isArray(e)?e.length>0?e:null:Object.keys(e).length>0?e:null),arity:H(1)},"every?":{evaluate:([e,t],n,r,{executeFunction:i})=>(z(e,n),Y(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:H(2)},"any?":{evaluate:([e,t],n,r,{executeFunction:i})=>(Y(t,n),z(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:H(2)},"not-any?":{evaluate:([e,t],n,r,{executeFunction:i})=>(Y(t,n),z(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:H(2)},"not-every?":{evaluate:([e,t],n,r,{executeFunction:i})=>(Y(t,n),z(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:H(2)}},Ee={range:{evaluate:(e,t)=>{const[n,r,i]=e;let s,o,a;C(n,t,{finite:!0}),1===e.length?(s=0,o=n,a=o>=0?1:-1):2===e.length?(C(r,t,{finite:!0}),s=n,o=r,a=o>=s?1:-1):(C(r,t,{finite:!0}),C(i,t,{finite:!0}),s=n,o=r,a=i,C(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)=>{C(t,n,{integer:!0,nonNegative:!0});const r=[];for(let n=0;n<t;n+=1)r.push(e);return r},arity:H(2)},flatten:{evaluate:([e,t],n)=>{ge(e,n);const r=void 0===t||t===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:F(t,n,{integer:!0,nonNegative:!0});return e.flat(r)},arity:{min:1,max:2}},mapcat:{evaluate:([e,t],n,r,{executeFunction:i})=>(ge(e,n),Y(t,n),e.map(e=>i(t,[e],r,n)).flat(1)),arity:H(2)},"moving-fn":{evaluate:([e,t,n],r,i,{executeFunction:s})=>{ge(e,r),C(t,r,{integer:!0,lte:e.length}),Y(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:H(3)},"running-fn":{evaluate:([e,t],n,r,{executeFunction:i})=>{ge(e,n),Y(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:H(2)}},Ne={nth:{evaluate:(e,t)=>{const[n,r]=e,i=ce(e[2]);if(C(r,t,{integer:!0}),null===n)return i;if(R(n,t),r>=0&&r<n.length){return ce(n[r])}return i},arity:{min:2,max:3}},first:{evaluate:([e],t)=>{if(null===e)return null;R(e,t);return ce(e[0])},arity:H(1)},last:{evaluate:([e],t)=>{if(null===e)return null;R(e,t);return ce(e.at(-1))},arity:H(1)},pop:{evaluate:([e],t)=>(R(e,t),"string"==typeof e?e.substring(0,e.length-1):e.slice(0,e.length-1)),arity:H(1)},position:{evaluate:([e,t],n,r,{executeFunction:i})=>{if(Y(t,n),null===e)return null;if(R(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:H(2)},"index-of":{evaluate:([e,t],n)=>{if(T(t,n),null===e)return null;if(R(e,n),"string"==typeof e){ee(t,n);const r=e.indexOf(t);return-1!==r?r:null}{const r=e.findIndex(e=>ae(U(e,n),t),n);return-1!==r?r:null}},arity:H(2)},"last-index-of":{evaluate:([e,t],n)=>{if(T(t,n),null===e)return null;if(R(e,n),"string"==typeof e){ee(t,n);const r=e.lastIndexOf(t);return-1!==r?r:null}{const r=e.findLastIndex(e=>ae(U(e,n),t),n);return-1!==r?r:null}},arity:H(2)},push:{evaluate:([e,...t],n)=>(R(e,n),"string"==typeof e?(ve(t,n),[e,...t].join("")):[...e,...t]),arity:{min:2}},rest:{evaluate:([e],t)=>(R(e,t),Array.isArray(e)?e.length<=1?[]:e.slice(1):e.substring(1)),arity:H(1)},next:{evaluate:([e],t)=>(R(e,t),Array.isArray(e)?e.length<=1?null:e.slice(1):e.length<=1?null:e.substring(1)),arity:H(1)},reverse:{evaluate:([e],t)=>null===e?null:(R(e,t),Array.isArray(e)?[...e].reverse():e.split("").reverse().join("")),arity:H(1)},second:{evaluate:([e],t)=>null===e?null:(R(e,t),ce(e[1])),arity:H(1)},shift:{evaluate:([e],t)=>{if(R(e,t),"string"==typeof e)return e.substring(1);const n=[...e];return n.shift(),n},arity:H(1)},slice:{evaluate:(e,t)=>{const[n,r,i]=e;return R(n,t),C(r,t,{integer:!0}),2===e.length?(Array.isArray(n),n.slice(r)):(C(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;R(n,t),C(r,t,{integer:!0}),C(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=>ee(e,t)),`${n.substring(0,o)}${s.join("")}${n.substring(o+i)}`)},arity:{min:3}},some:{evaluate:([e,t],n,r,{executeFunction:i})=>(Y(t,n),null===e?null:(R(e,n),0===e.length?null:"string"==typeof e?e.split("").find(e=>i(t,[e],r,n))??null:ce(e.find(e=>i(t,[e],r,n))))),arity:H(2)},sort:{evaluate:(e,t,n,{executeFunction:r})=>{const[i]=e,s=1===e.length,o=s?null:e[1];if(R(i,t),"string"==typeof i){const e=i.split("");return s?e.sort((e,n)=>oe(e,n,t)):(Y(o,t),e.sort((e,i)=>{const s=r(o,[e,i],n,t);return C(s,t,{finite:!0}),s})),e.join("")}const a=[...i];return s?a.sort((e,n)=>(ie(e,t),ie(n,t),oe(e,n,t))):a.sort((e,i)=>{Y(o,t);const s=r(o,[e,i],n,t);return C(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;R(i,t),Y(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);ie(o,t);const a=r(s,[i],n,t);return ie(a,t),oe(o,a,t)}):(Y(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(c,t,{finite:!0}),c})),e.join("")}const u=[...i];return o?u.sort((e,i)=>{const o=r(s,[e],n,t);ie(o,t);const a=r(s,[i],n,t);return ie(a,t),oe(o,a,t)}):(Y(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(c,t,{finite:!0}),c})),u},arity:{min:2,max:3}},take:{evaluate:([e,t],n)=>{C(t,n),R(e,n);const r=Math.max(Math.ceil(t),0);return e.slice(0,r)},arity:H(2)},"take-last":{evaluate:([e,t],n)=>{R(e,n),C(t,n);const r=Math.max(Math.ceil(t),0),i=e.length-r;return e.slice(i)},arity:H(2)},"take-while":{evaluate:([e,t],n,r,{executeFunction:i})=>{R(e,n),Y(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:H(2)},drop:{evaluate:([e,t],n)=>{C(t,n);const r=Math.max(Math.ceil(t),0);return R(e,n),e.slice(r)},arity:H(2)},"drop-last":{evaluate:([e,t],n)=>{R(e,n),C(t,n);const r=Math.max(Math.ceil(t),0),i=e.length-r;return e.slice(0,i)},arity:H(2)},"drop-while":{evaluate:([e,t],n,r,{executeFunction:i})=>{if(R(e,n),Y(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:H(2)},unshift:{evaluate:([e,...t],n)=>{if(R(e,n),"string"==typeof e)return ve(t,n),[...t,e].join("");const r=[...e];return r.unshift(...t),r},arity:{min:2}},distinct:{evaluate:([e],t)=>{if(R(e,t),Array.isArray(e)){const n=[];for(const r of e)T(r,t),n.some(e=>ae(e,r,t))||n.push(r);return n}return Array.from(new Set(e.split(""))).join("")},arity:H(1)},remove:{evaluate:([e,t],n,r,{executeFunction:i})=>(Y(t,n),R(e,n),Array.isArray(e)?e.filter(e=>!i(t,[e],r,n)):e.split("").filter(e=>!i(t,[e],r,n)).join("")),arity:H(2)},"remove-at":{evaluate:([e,t],n)=>{C(t,n,{integer:!0}),R(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:H(2)},"split-at":{evaluate:([e,t],n)=>{C(t,n,{integer:!0}),R(e,n);const r=t<0?e.length+t:t;return[e.slice(0,r),e.slice(r)]},arity:H(2)},"split-with":{evaluate:([e,t],n,r,{executeFunction:i})=>{Y(t,n),R(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:H(2)},frequencies:{evaluate:([e],t)=>{R(e,t);return("string"==typeof e?e.split(""):e).reduce((e,n)=>(ee(n,t),se(e,n)?e[n]=e[n]+1:e[n]=1,e),{})},arity:H(1)},"group-by":{evaluate:([e,t],n,r,{executeFunction:i})=>{Y(t,n),R(e,n);return(Array.isArray(e)?e:e.split("")).reduce((e,s)=>{const o=i(t,[s],r,n);return ee(o,n),se(e,o)||(e[o]=[]),e[o].push(s),e},{})},arity:H(2)},partition:{evaluate:(e,t)=>{const n=P(e[0],t),r=ue(F(e[1],t)),i=e.length>=3?ue(F(e[2],t)):r,s=4===e.length?null===e[3]?[]:function(e,t){return ge(e,t),e}(e[3],t):void 0;return Ae(r,i,n,s,t)},arity:{min:2,max:4}},"partition-all":{evaluate:(e,t)=>{const n=P(e[0],t),r=ue(F(e[1],t));return Ae(r,3===e.length?ue(F(e[2],t)):r,n,[],t)},arity:{min:2,max:3}},"partition-by":{evaluate:([e,t],n,r,{executeFunction:i})=>{Y(t,n),R(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:H(2)},"ends-with?":{evaluate:([e,t],n)=>(R(e,n),"string"==typeof e?(ee(t,n),e.endsWith(t)):ae(U(e.at(-1),n),U(t,n),n)),arity:H(2)},"starts-with?":{evaluate:([e,t],n)=>(R(e,n),"string"==typeof e?(ee(t,n),e.startsWith(t)):ae(U(e[0],n),U(t,n),n)),arity:H(2)},interleave:{evaluate:([...e],t)=>{const n="string"==typeof e[0],r=n?e.map(e=>(ee(e,t),e.split(""))):e.map(e=>(ge(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(R(e,n),"string"==typeof e)return ee(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:H(2)}};function Ae(e,t,n,r,i){C(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 Ie=new WeakSet,$e=new WeakSet,je=new WeakSet,Oe=new WeakSet,Ce=new WeakSet,Fe=new WeakSet,Me=new WeakSet;function Ue(e){return Array.isArray(e)?(Ie.has(e)||(Te(e),Pe(e)||Be(e)),e):e}function Te(e){return!!Array.isArray(e)&&(!!$e.has(e)||!je.has(e)&&(e.every(e=>O(e))?(Ie.add(e),$e.add(e),!0):(je.add(e),!1)))}function Be(e){if(!Array.isArray(e))return!1;if(Fe.has(e))return!0;if(Me.has(e))return!1;if(0===e.length)return Me.add(e),!1;if(!Array.isArray(e[0]))return Me.add(e),!1;const t=e[0].length;for(const n of e.slice(1)){if(!Array.isArray(n))return Me.add(e),!1;if(n.length!==t)return Me.add(e),!1}return Ie.add(e),Fe.add(e),!0}function Pe(e){if(!Array.isArray(e))return!1;if(Oe.has(e))return!0;if(Ce.has(e))return!1;if(0===e.length)return Ce.add(e),!1;if(!Array.isArray(e[0])||0===e[0].length)return Ce.add(e),!1;const t=e[0].length;for(const n of e)if(!Array.isArray(n)||n.length!==t||n.some(e=>!O(e)))return Ce.add(e),!1;return Ie.add(e),Fe.add(e),Oe.add(e),!0}function Re(e,t){let r=!1,i=!1;for(const s of e)if(Te(s))r=!0;else if(Pe(s))i=!0;else if(!O(s))throw new n("Invalid parameter type: "+typeof s,t);if(i){if(r)throw new n("Cannot mix vector and matrix types",t);let i=null,s=null;for(const r of e)if(Pe(r))if(null===i)i=r.length,s=r[0].length;else if(r.length!==i||r[0].length!==s)throw new n("Matrix dimensions do not match",t);return["matrix",e.map(e=>Pe(e)?e:Array.from({length:i},()=>Array.from({length:s},()=>e)))]}if(r){let r=null;for(const i of e)if(Te(i))if(null===r)r=i.length;else if(i.length!==r)throw new n("Vector lengths do not match",t);return["vector",e.map(e=>Te(e)?e:Array.from({length:r},()=>e))]}return["number",e]}function De(e){return(t,n)=>{const[r,i]=Re(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 _e(e){return(t,n)=>{const[r,i]=Re(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 Le(e,t){return(n,r)=>{if(0===n.length)return e;const[i,s]=Re(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 Ve={inc:{evaluate:De(e=>e+1),arity:H(1)},dec:{evaluate:De(e=>e-1),arity:H(1)},"+":{evaluate:Le(0,(e,t)=>e+t),arity:{}},"*":{evaluate:Le(1,(e,t)=>e*t),arity:{}},"/":{evaluate:(e,t)=>{if(0===e.length)return 1;const[n,r]=Re(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]=Re(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:_e((e,t)=>Math.trunc(e/t)),arity:H(2)},mod:{evaluate:_e((e,t)=>e-t*Math.floor(e/t)),arity:H(2)},"%":{evaluate:_e((e,t)=>e%t),arity:H(2)},sqrt:{evaluate:De(e=>Math.sqrt(e)),arity:H(1)},cbrt:{evaluate:De(e=>Math.cbrt(e)),arity:H(1)},"^":{evaluate:_e((e,t)=>e**t),arity:H(2)},round:{evaluate:([e,t],n)=>{const[r,i]=Re([e],n);if("number"===r){if(void 0===t||0===t)return Math.round(i[0]);{C(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));{C(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)));{C(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:De(e=>Math.trunc(e)),arity:H(1)},floor:{evaluate:De(e=>Math.floor(e)),arity:H(1)},ceil:{evaluate:De(e=>Math.ceil(e)),arity:H(1)},min:{evaluate:([e,...t],n)=>(C(e,n),0===t.length?e:t.reduce((e,t)=>(C(t,n),Math.min(e,t)),e)),arity:{min:1}},max:{evaluate:([e,...t],n)=>(C(e,n),0===t.length?e:t.reduce((e,t)=>(C(t,n),Math.max(e,t)),e)),arity:{min:1}},abs:{evaluate:De(e=>Math.abs(e)),arity:H(1)},sign:{evaluate:De(e=>Math.sign(e)),arity:H(1)},ln:{evaluate:De(e=>Math.log(e)),arity:H(1)},log2:{evaluate:De(e=>Math.log2(e)),arity:H(1)},log10:{evaluate:De(e=>Math.log10(e)),arity:H(1)},sin:{evaluate:De(e=>Math.sin(e)),arity:H(1)},asin:{evaluate:De(e=>Math.asin(e)),arity:H(1)},sinh:{evaluate:De(e=>Math.sinh(e)),arity:H(1)},asinh:{evaluate:De(e=>Math.asinh(e)),arity:H(1)},cos:{evaluate:De(e=>Math.cos(e)),arity:H(1)},acos:{evaluate:De(e=>Math.acos(e)),arity:H(1)},cosh:{evaluate:De(e=>Math.cosh(e)),arity:H(1)},acosh:{evaluate:De(e=>Math.acosh(e)),arity:H(1)},tan:{evaluate:De(e=>Math.tan(e)),arity:H(1)},atan:{evaluate:De(e=>Math.atan(e)),arity:H(1)},tanh:{evaluate:De(e=>Math.tanh(e)),arity:H(1)},atanh:{evaluate:De(e=>Math.atanh(e)),arity:H(1)},"to-rad":{evaluate:De(e=>e*Math.PI/180),arity:H(1)},"to-deg":{evaluate:De(e=>180*e/Math.PI),arity:H(1)}};function ze([e,...t],n){const r=U(e,n);for(const e of t)if(!ae(r,U(e,n),n))return!1;return!0}const We={"==":{evaluate:(e,t)=>ze(e,t),arity:{min:1}},"≠":{evaluate:(e,t)=>!ze(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=re(e);for(const e of t){if(oe(r,re(e),n)<=0)return!1;r=re(e)}return!0},arity:{min:1}},"<":{evaluate:([e,...t],n)=>{let r=re(e);for(const e of t){if(oe(r,re(e),n)>=0)return!1;r=re(e)}return!0},arity:{min:1}},">=":{evaluate:([e,...t],n)=>{let r=re(e);for(const e of t){if(oe(r,re(e),n)<0)return!1;r=re(e)}return!0},arity:{min:1}},"<=":{evaluate:([e,...t],n)=>{let r=re(e);for(const e of t){if(oe(r,re(e),n)>0)return!1;r=re(e)}return!0},arity:{min:1}},"!":{evaluate:([e])=>!e,arity:H(1)},"epoch->iso-date":{evaluate:([e],t)=>(C(e,t),new Date(e).toISOString()),arity:H(1)},"iso-date->epoch":{evaluate:([e],t)=>{ee(e,t);const n=new Date(e).valueOf();return C(n,t,{finite:!0}),n},arity:H(1)},"write!":{evaluate:(e,t)=>(console.log(...e),e.length>0?U(e[e.length-1],t):null),arity:{}},boolean:{evaluate:([e])=>!!e,arity:H(1)},compare:{evaluate:([e,t],n)=>(ie(e,n),ie(t,n),oe(e,t,n)),arity:H(2)},"json-parse":{evaluate:([e],t)=>(ee(e,t),JSON.parse(e)),arity:H(1)},"json-stringify":{evaluate:([e,t],n)=>(T(e,n),void 0===t?JSON.stringify(e):(C(t,n),JSON.stringify(e,null,t))),arity:{min:1,max:2}},import:{evaluate:([e],t,r)=>{ee(e,t);const i=e.indexOf(".");if(-1!==i){const s=e.substring(0,i),o=e.substring(i+1),a=r.getModule(s);if(!a)throw new n(`Unknown module: '${s}'`,t);const u=a.functions[o];if(!u)throw new n(`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=r.getModule(s);if(!o)throw new n(`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:H(1)}},Je={keys:{evaluate:([e],t)=>(_(e,t),Object.keys(e)),arity:H(1)},vals:{evaluate:([e],t)=>(_(e,t),Object.values(e)),arity:H(1)},entries:{evaluate:([e],t)=>(_(e,t),Object.entries(e)),arity:H(1)},find:{evaluate:([e,t],n)=>(_(e,n),ee(t,n),se(e,t)?[t,e[t]]:null),arity:H(2)},dissoc:{evaluate:([e,t],n)=>{_(e,n),ee(t,n);const r={...e};return delete r[t],r},arity:H(2)},merge:{evaluate:(e,t)=>{if(0===e.length)return null;const[n,...r]=e;return _(n,t),r.reduce((e,n)=>(_(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 _(i,t),Y(s,t),o.reduce((e,i)=>(_(i,t),Object.entries(i).forEach(i=>{const o=te(i[0],t),a=ce(i[1]);se(e,o)?e[o]=r(s,[e[o],a],n,t):e[o]=a}),e),{...i})},arity:{min:2}},zipmap:{evaluate:([e,t],n)=>{me(e,n),ge(t,n);const r=Math.min(e.length,t.length),i={};for(let s=0;s<r;s+=1){i[te(e[s],n)]=ce(t[s])}return i},arity:H(2)},"select-keys":{evaluate:([e,t],n)=>(me(t,n),_(e,n),t.reduce((t,n)=>(se(e,n)&&(t[n]=ce(e[n])),t),{})),arity:H(2)}},qe={"function?":{evaluate:([e])=>w(e),arity:H(1)},"string?":{evaluate:([e])=>"string"==typeof e,arity:H(1)},"number?":{evaluate:([e])=>"number"==typeof e,arity:H(1)},"integer?":{evaluate:([e])=>"number"==typeof e&&O(e,{integer:!0}),arity:H(1)},"boolean?":{evaluate:([e])=>"boolean"==typeof e,arity:H(1)},"null?":{evaluate:([e])=>null==e,arity:H(1)},"zero?":{evaluate:([e],t)=>(C(e,t,{finite:!0}),Math.abs(e)<de),arity:H(1)},"pos?":{evaluate:([e],t)=>(C(e,t,{finite:!0}),e>0),arity:H(1)},"neg?":{evaluate:([e],t)=>(C(e,t,{finite:!0}),e<0),arity:H(1)},"even?":{evaluate:([e],t)=>(C(e,t,{finite:!0}),e%2==0),arity:H(1)},"odd?":{evaluate:([e],t)=>(C(e,t,{finite:!0}),O(e,{integer:!0})&&e%2!=0),arity:H(1)},"array?":{evaluate:([e])=>Array.isArray(e),arity:H(1)},"collection?":{evaluate:([e])=>L(e),arity:H(1)},"sequence?":{evaluate:([e])=>B(e),arity:H(1)},"object?":{evaluate:([e])=>D(e),arity:H(1)},"regexp?":{evaluate:([e])=>W(e),arity:H(1)},"finite?":{evaluate:([e],t)=>(C(e,t),Number.isFinite(e)),arity:H(1)},"positive-infinity?":{evaluate:([e],t)=>(C(e,t),e===Number.POSITIVE_INFINITY),arity:H(1)},"negative-infinity?":{evaluate:([e],t)=>(C(e,t),e===Number.NEGATIVE_INFINITY),arity:H(1)},"true?":{evaluate:([e])=>!0===e,arity:H(1)},"false?":{evaluate:([e])=>!1===e,arity:H(1)},"empty?":{evaluate:([e],t)=>null===e||(z(e,t),"string"==typeof e||Array.isArray(e)?0===e.length:0===Object.keys(e).length),arity:H(1)},"not-empty?":{evaluate:([e],t)=>null!==e&&(z(e,t),"string"==typeof e||Array.isArray(e)?e.length>0:Object.keys(e).length>0),arity:H(1)},"vector?":{evaluate:([e])=>Te(e),arity:H(1)},"matrix?":{evaluate:([e])=>Pe(e),arity:H(1)},"grid?":{evaluate:([e])=>Be(e),arity:H(1)}},Ye={regexp:{evaluate:([e,t],r)=>{ee(e,r);const i=e||"(?:)",s="string"==typeof t?t:"";try{new RegExp(i,s)}catch(e){throw new n(`Invalid regular expression: ${i} ${s}`,r)}return{[f]:!0,sourceCodeInfo:r,s:i,f:s}},arity:{min:1,max:2}},match:{evaluate:([e,t],n)=>{if(function(e,t){if(!W(e))throw g("RegularExpression",e,t)}(t,n),!Q(e))return null;const r=new RegExp(t.s,t.f).exec(e);return r?[...r]:null},arity:H(2)},replace:{evaluate:([e,t,n],r)=>{ee(e,r),J(t,r),ee(n,r);const i=W(t)?new RegExp(t.s,`${t.f}`):t;return e.replace(i,n)},arity:H(3)},"replace-all":{evaluate:([e,t,n],r)=>{ee(e,r),J(t,r),ee(n,r);const i=W(t)?new RegExp(t.s,`${t.f.includes("g")?t.f:`${t.f}g`}`):t;return e.replaceAll(i,n)},arity:H(3)}},Ge=/^\s*$/,Xe={"string-repeat":{evaluate:([e,t],n)=>(ee(e,n),C(t,n,{integer:!0,nonNegative:!0}),e.repeat(t)),arity:H(2)},str:{evaluate:e=>e.reduce((e,t)=>e+(null==t?"":D(t)||Array.isArray(t)?JSON.stringify(t):`${t}`),""),arity:{}},number:{evaluate:([e],t)=>{ee(e,t);const r=Number(e);if(Number.isNaN(r))throw new n(`Could not convert '${e}' to a number.`,t);return r},arity:H(1)},"from-char-code":{evaluate:([e],t)=>{C(e,t,{finite:!0});const r=ue(e);try{return String.fromCodePoint(r)}catch(e){throw new n(e,t)}},arity:H(1)},"to-char-code":{evaluate:([e],t)=>(ee(e,t,{nonEmpty:!0}),m(e.codePointAt(0),t)),arity:H(1)},"lower-case":{evaluate:([e],t)=>(ee(e,t),e.toLowerCase()),arity:H(1)},"upper-case":{evaluate:([e],t)=>(ee(e,t),e.toUpperCase()),arity:H(1)},trim:{evaluate:([e],t)=>(ee(e,t),e.trim()),arity:H(1)},"trim-left":{evaluate:([e],t)=>(ee(e,t),e.replace(/^\s+/,"")),arity:H(1)},"trim-right":{evaluate:([e],t)=>(ee(e,t),e.replace(/\s+$/,"")),arity:H(1)},join:{evaluate:([e,t],n)=>(ge(e,n),e.forEach(e=>ie(e,n)),ee(t,n),e.join(t)),arity:H(2)},split:{evaluate:([e,t,n],r)=>{ee(e,r),J(t,r),void 0!==n&&C(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)=>(ee(e,t),e.split(/\r\n|\n|\r/).filter(e=>""!==e)),arity:H(1)},"pad-left":{evaluate:([e,t,n],r)=>(ee(e,r),C(t,r,{integer:!0}),void 0!==n&&ee(n,r),e.padStart(t,n)),arity:{min:2,max:3}},"pad-right":{evaluate:([e,t,n],r)=>(ee(e,r),C(t,r,{integer:!0}),void 0!==n&&ee(n,r),e.padEnd(t,n)),arity:{min:2,max:3}},template:{evaluate:([e,...t],n)=>{ee(e,n),ge(t,n);const r=e.split("||||");if(r.length<=1)return He(r[0],t,n);{const e=t[0];C(e,n,{integer:!0,nonNegative:!0});const i=[`${e}`,...t.slice(1)];if(2===r.length){return He(r[1===e?0:1],i,n)}return He(r[Math.min(e,r.length-1)],i,n)}},arity:{min:1,max:10}},"encode-base64":{evaluate:([e],t)=>(ee(e,t),btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(e,t)=>String.fromCharCode(Number.parseInt(t,16))))),arity:H(1)},"decode-base64":{evaluate:([e],t)=>{ee(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 n(e,t)}},arity:H(1)},"encode-uri-component":{evaluate:([e],t)=>(ee(e,t),encodeURIComponent(e)),arity:H(1)},"decode-uri-component":{evaluate:([e],t)=>{ee(e,t);try{return decodeURIComponent(e)}catch(e){throw new n(e,t)}},arity:H(1)},capitalize:{evaluate:([e],t)=>(ee(e,t),e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()),arity:H(1)},"blank?":{evaluate:([e],t)=>null===e||(ee(e,t),Ge.test(e)),arity:H(1)}},Ze=/\$\$/g;function He(e,t,n){for(let r=0;r<9;r+=1){const i=new RegExp(`(\\$\\$|[^$]|^)\\$${r+1}`,"g");if(i.test(e)){const s=re(t[r],n);e=e.replace(i,`$1${s}`)}}return e=e.replace(Ze,"$")}const Ke={"|>":{evaluate:([e,t],n,r,{executeFunction:i})=>(Y(t,n),i(t,[e],r,n)),arity:H(2)},apply:{evaluate:([e,...t],n,r,{executeFunction:i})=>{Y(e,n);const s=t[t.length-1];ge(s,n);return i(e,[...t.slice(0,-1),...s],r,n)},arity:{min:2}},identity:{evaluate:([e])=>ce(e),arity:H(1)},comp:{evaluate:(e,t)=>(e.forEach(e=>Y(e,t)),{[l]:!0,sourceCodeInfo:t,functionType:"Comp",params:e,arity:e.length>0?X(e.at(-1)):{min:1,max:1}}),arity:{}},constantly:{evaluate:([e],t)=>({[l]:!0,sourceCodeInfo:t,functionType:"Constantly",value:ce(e),arity:{}}),arity:H(1)},juxt:{evaluate:(e,t)=>{e.forEach(e=>Y(e,t));const r=function(e){return e.reduce((e,t)=>{if(null===e)return null;const n="number"==typeof t||L(t)?H(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===r)throw new n("All functions must accept the same number of arguments",t);return{[l]:!0,sourceCodeInfo:t,functionType:"Juxt",params:e,arity:r}},arity:{min:1}},complement:{evaluate:([e],t)=>{const n=q(e,t);return{[l]:!0,sourceCodeInfo:t,functionType:"Complement",function:n,arity:X(n)}},arity:H(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=q(e,n);return{[l]:!0,sourceCodeInfo:n,functionType:"Fnull",function:r,params:t,arity:X(r)}},arity:{min:2}}};function Qe(e){return ye(`\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(", ")})`} -> ${et(r)}`),o=i?["","Operator:",` a ${e} b -> ${et(r)}`]:[];return[...s,...o]}(e).join("\n ")}\n\n Arguments:\n ${function(e){return Object.entries(e.args).map(([e,t])=>`${e}: ${et(t)}`)}(e).join("\n ")}\n\n Examples:\n${e.examples.map(e=>ye(e,4)).join("\n\n")}`)}function et(e){const t=e.type,n=(Array.isArray(t)?t:[t]).join(" | ");return e.array||e.rest?`Array<${n}>`:n}const tt={...K,...ke,...Ee,...Ne,...Ve,...function(e){return{doc:{evaluate:([t],n)=>{if(v(e),Y(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:H(1)},arity:{evaluate:([e],t)=>(Y(e,t),w(e)?e.arity:H(1)),arity:H(1)}}}({}),...We,...Je,...qe,...Ye,...Xe,...Ke};Object.entries(tt).forEach(([e,t])=>{t.name=e});const nt={...tt},rt={},it=[];Object.entries(nt).forEach(([e,t],n)=>{rt[e]=n,it.push(t)});const st={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=U(r,t),!n)break;return n},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)};function ot(e){const t=e[0];return o.UserDefinedSymbol===t||o.NormalBuiltinSymbol===t||o.SpecialBuiltinSymbol===t}function at(e){return o.UserDefinedSymbol===e[0]}function ut(e,t){return function(e,t){if(!at(e))throw g("UserDefinedSymbolNode",e,t)}(e,t),e}function ct(e){return o.NormalBuiltinSymbol===e[0]}function lt(e){return o.SpecialBuiltinSymbol===e[0]}function ft(e){return!!function(e){return e[0]===o.NormalExpression}(e)&&ot(e[1][0])}function ht(e){return e[0]===o.Spread}const pt={arity:H(1),evaluate:(e,t)=>{const n=e[1][1];if(function(e,t){if(!ot(e))throw g("SymbolNode",e,t)}(n),!at(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 dt=11,yt=12,gt=13,mt=14;function vt(e,t){if(e[0]===gt)Object.values(e[1][0]).forEach(e=>{e[1][1]&&t(e[1][1]),vt(e,t)});else if(e[0]===mt)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]),vt(r,t))}}function bt(e,t,n){const r={};return wt(e,t,n,e[2],r),r}function wt(e,t,r,i,s){if(e[0]===gt){!function(e,t){if(!b(e))throw new n(`Expected UnknownRecord, got ${d(e)}.`,y(e,t))}(t,i);const o=new Set;let a;if(Object.entries(e[1][0]).forEach(([e,n])=>{if(n[0]===yt)return void(a=n);o.add(e);const u=(void 0!==t[e]?t[e]:n[1][1]&&r(n[1][1]))??null;T(u,i),wt(n,u,r,i,s)}),a){const e=Object.entries(t).filter(([e])=>!o.has(e)).reduce((e,[t,n])=>(e[t]=U(n),e),{});s[a[1][0]]=e}}else if(e[0]===mt){let n=null;ge(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]===yt){n=o;break}const u=(void 0!==t[o]?t[o]:a[1][1]&&r(a[1][1]))??null;T(u,i),wt(a,u,r,i,s)}if(null!==n){const r=t.slice(n),i=e[1][0][n];s[i[1][0]]=r}}else e[0]===yt?s[e[1][0]]=U(t):s[e[1][0][1]]=U(t)}function St(e){const t={};return xt(e,t),t}function xt(e,t){if(null!==e)if(e[0]===mt)for(const n of e[1][0])xt(n,t);else if(e[0]===gt)for(const n of Object.values(e[1][0]))xt(n,t);else if(e[0]===yt){if(t[e[1][0]])throw new n(`Duplicate binding name: ${e[1][0]}`,e[2]);t[e[1][0]]=!0}else{if(t[e[1][0][1]])throw new n(`Duplicate binding name: ${e[1][0]}`,e[2]);t[e[1][0][1]]=!0}}const kt={arity:{},evaluate:(e,t,{evaluateNode:n})=>{const r=e[1][1],i=r[1][0],s=r[1][1],o=n(s,t),a=bt(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 vt(o,e=>{pe(u,n([e],t,r,i))}),t.addValues(St(o),o[2]),u}},Et={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(St(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);M(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]!==yt&&void 0===e[1][1]).length,c={min:u>0?u:void 0,max:a[0].some(e=>e[0]===yt)?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,St(e)),vt(e,e=>{pe(s,n([e],t,r,i))})});const a=t.create(o),u=n(e[1],a,r,i);return pe(s,u),s}(e[1][1],t,n,r,i)};const Nt={arity:H(0),evaluate:(e,t,{evaluateNode:n})=>{const r=e[1][1],i=r[1][0],s=r[1][1],o=n(s,t),a=bt(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 vt(o,e=>{pe(u,n([e],t,r,i))}),t.addValues(St(o),o[2]),u}},At={arity:{},evaluate:(e,r,{evaluateNode:i})=>{const s=e[1][1],o=s.reduce((e,t)=>{const n=i(t[1][1],r.create(e)),s=bt(t[1][0],n,e=>i(e,r));return Object.entries(s).forEach(([t,n])=>{e[t]={value:n}}),e},{}),a=r.create(o),u=e[1][2];for(;;){let c=null;try{c=i(u,a)}catch(a){if(a instanceof t){const t=a.params;if(t.length!==s.length)throw new n(`recur expected ${s.length} parameters, got ${d(t.length)}`,e[2]);s.forEach((e,n)=>{const s=bt(e[1][0],U(t[n]),e=>i(e,r));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=St(t[1][0]);return Object.keys(n).forEach(t=>{e[t]={value:!0}}),e},{});return he(n(s.map(e=>e[1][1]),t,r,i),n([e[1][2]],t.create(o),r,i))}};function It(e,t,n,r){for(const i of e){const[e,s]=i[1],o=bt(e,r(s,n),e=>r(e,n));Object.entries(o).forEach(([e,n])=>{t[e]={value:n}})}}function $t(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=V(r(d,l),i),g=B(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=bt(p,U(g[v],i),e=>r(e,l));if(Object.entries(b).forEach(([e,n])=>{t[e]={value:n}}),o&&It(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 jt(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,St(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,St(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 Ot={arity:H(1),evaluate:(e,t,n)=>$t(!0,e,t,n.evaluateNode),getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>jt(e,t,n,r,i)},Ct={arity:H(1),evaluate:(e,t,n)=>($t(!1,e,t,n.evaluateNode),null),getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>jt(e,t,n,r,i)},Ft={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=U(r,t),n)break;return n},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)},Mt={arity:{min:1},evaluate:(e,t,{evaluateNode:n})=>{for(const r of e[1][1]){if(at(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=U(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)},Ut={arity:{},evaluate:(e,n,{evaluateNode:r})=>{const i=e[1][1].map(e=>r(e,n));throw new t(i)},evaluateAsNormalExpression:e=>{throw new t(e)},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)},Tt={arity:H(1),evaluate:(e,t,{evaluateNode:n})=>{const i=te(n(e[1][1],t),e[2],{nonEmpty:!0});throw new r(i,e[2])},evaluateAsNormalExpression:(e,t)=>{const n=te(e[0],t,{nonEmpty:!0});throw new r(n,void 0)},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n([e[1][1]],t,r,i)},Bt={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 he(u,n([a],t.create(c),r,i))}},Pt={arity:{},evaluate:(e,t,{evaluateNode:r})=>{const i=[];for(const s of e[1][1])if(ht(s)){const e=r(s[1],t);if(!Array.isArray(e))throw new n("Spread value is not an array",s[2]);i.push(...e)}else i.push(r(s,t));return i},evaluateAsNormalExpression:(e,t)=>{const n=[];for(const r of e)n.push(U(r,t));return n},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)},Rt={arity:{},evaluate:(e,t,{evaluateNode:r})=>{const i={},s=e[1][1];for(let e=0;e<s.length;e+=2){const o=s[e];if(ht(o)){const s=r(o[1],t);if(!b(s))throw new n("Spread value is not an object",o[2]);Object.assign(i,s),e-=1}else{const a=r(o,t),u=s[e+1];if(void 0===u)throw new n("Missing value for key",o[2]);const c=r(u,t);ee(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];ee(i,t),n[i]=s??null}return n},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)},Dt={"??":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=[Mt,st,Ft,Pt,{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)},kt,pt,{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)},Ct,Et,Ot,{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)},Nt,At,Rt,Ut,{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)},Tt,Bt,{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)}],Lt={normalExpressions:nt,specialExpressions:_t,allNormalExpressions:it},Vt=Object.keys(nt),zt=Object.keys(Dt);new Set(zt);const Wt=(e,t,n,r)=>{const i=Array.isArray(e)?e:[[o.SpecialExpression,[Dt.block,e.body]]],s=new Set;for(const e of i)Jt(e,t,n,r)?.forEach(e=>s.add(e));return s};function Jt(e,t,r,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 n=e,s=new Set;if(ft(n)){const[,[e]]=n;if(at(e)){null===t.lookUp(e)&&s.add(e[1])}}else{const[,[e]]=n;Jt(e,t,r,i)?.forEach(e=>s.add(e))}for(const e of n[1][1])Jt(e,t,r,i)?.forEach(e=>s.add(e));return s}case o.SpecialExpression:{const n=e,s=n[1][0];return(0,r.specialExpressions[s].getUndefinedSymbols)(n,t,{getUndefinedSymbols:Wt,builtin:r,evaluateNode:i})}case o.Spread:return Jt(e[1],t,r,i);default:throw new n(`Unhandled node type: ${s}`,e[2])}}const qt=(1+Math.sqrt(5))/2,Yt={E:Math.E,"-E":-Math.E,"ε":Math.E,"-ε":-Math.E,PI:Math.PI,"-PI":-Math.PI,"π":Math.PI,"-π":-Math.PI,PHI:qt,"-PHI":-qt,"φ":qt,"-φ":-qt,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},Gt={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,...Yt};const Xt={NativeJsFunction:(e,t,r)=>{try{return ce(e.nativeFn.fn(...t))}catch(e){const t="string"==typeof e?e:b(e)&&"string"==typeof e.message?e.message:"<no message>";throw new n(`Native function threw: "${t}"`,r)}},UserDefined:(e,r,i,s,{evaluateNode:o})=>{for(;;){if(!G(e.arity,r.length))throw new n(`Expected ${e.arity} arguments, got ${r.length}.`,i);const a=e.evaluatedfunction,u=a[0],c=u.filter(e=>e[0]!==yt).length,l=s.create(e.evaluatedfunction[2]),f={self:{value:e}},h=[];for(let e=0;e<r.length;e+=1)if(e<c){const t=ce(r[e]),n=bt(u[e],t,e=>o(e,l.create(f)));Object.entries(n).forEach(([e,t])=>{f[e]={value:t}})}else h.push(ce(r[e]));for(let e=r.length;e<c;e++){const t=u[e],n=bt(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]===yt);if(void 0!==p){const e=bt(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 t){r=e.params;continue}throw e}}},Partial:(e,t,r,i,{executeFunction:s})=>{const o=[...e.params];if(t.length!==e.placeholders.length)throw new n(`(partial) expects ${e.placeholders.length} arguments, got ${t.length}.`,r);const a=[...t];for(const t of e.placeholders)o.splice(t,0,a.shift());return s(e.function,o,i,r)},Comp:(e,t,r,i,{executeFunction:s})=>{const{params:o}=e;if(0===o.length){if(1!==t.length)throw new n(`(comp) expects one argument, got ${d(t.length)}.`,r);return U(t[0],r)}return U(o.reduceRight((e,t)=>[s(q(t,r),e,i,r)],t)[0],r)},Constantly:e=>e.value,Juxt:(e,t,n,r,{executeFunction:i})=>e.params.map(e=>i(q(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(q(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(q(s,n),[e],r,n))return!0}return!1},Fnull:(e,t,n,r,{executeFunction:i})=>{const s=t.map((t,n)=>null===t?ce(e.params[n]):t);return i(q(e.function,n),s,r,n)},Builtin:(e,t,n,r,{executeFunction:i})=>m(it[e.normalBuiltinSymbolType],n).evaluate(t,n,r,{executeFunction:i}),SpecialBuiltin:(e,t,r,i,{executeFunction:s})=>{const o=m(_t[e.specialBuiltinSymbolType],r);if(o.evaluateAsNormalExpression)return o.evaluateAsNormalExpression(t,r,i,{executeFunction:s});throw new n(`Special builtin function ${e.specialBuiltinSymbolType} is not supported as normal expression.`,r)},Module:(e,t,r,i,{executeFunction:s})=>{const o=i.getModule(e.moduleName);if(!o)throw new n(`Module '${e.moduleName}' not found.`,r);const a=o.functions[e.functionName];if(!a)throw new n(`Function '${e.functionName}' not found in module '${e.moduleName}'.`,r);return Z(a.arity,t.length,r),a.evaluate(t,r,i,{executeFunction:s})}};function Zt(e,t){let n=null;for(const r of e.body)n=Ht(r,t);return n}function Ht(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 n(`Reserved symbol ${t} cannot be evaluated`,e[2]);return m(Gt[t],e[2])}(e);case o.NormalExpression:{const r=function(e,t){const r=e[2],s=e[1][1],a=[],u=[];if(s.forEach((e,r)=>{if(ht(e)){const r=Ht(e[1],t);if(!Array.isArray(r))throw new n(`Spread operator requires an array, got ${d(e)}`,e[2]);a.push(...r)}else e[0]===o.ReservedSymbol&&"_"===e[1]?u.push(r):a.push(Ht(e,t))}),ft(e)){const n=e[1][0];if(u.length>0){const e=Ht(n,t);return{[l]:!0,function:q(e,r),functionType:"Partial",params:a,placeholders:u,sourceCodeInfo:r,arity:H(u.length)}}if(ct(n)){const r=n[1];return Lt.allNormalExpressions[r].evaluate(a,e[2],t,{executeFunction:Kt})}{const s=t.getValue(n[1]);if(void 0!==s)return Kt(q(s,r),a,t,r);throw new i(n[1],e[2])}}{const n=q(Ht(e[1][0],t),r);if(u.length>0){return{[l]:!0,function:n,functionType:"Partial",params:a,placeholders:u,sourceCodeInfo:r,arity:H(u.length)}}return Kt(n,a,t,r)}}(e,t);if("number"==typeof r&&Number.isNaN(r))throw new n("Number is NaN",e[2]);return Ue(r)}case o.SpecialExpression:return Ue(function(e,t){const n=e[1][0],r=m(Lt.specialExpressions[n],e[2]);return(0,r.evaluate)(e,t,{evaluateNode:Ht,builtin:Lt,getUndefinedSymbols:Wt})}(e,t));default:throw new n(`${u(e[0])}-node cannot be evaluated`,e[2])}}function Kt(e,t,r,i){if(w(e))return Xt[e.functionType](e,t,i,r,{evaluateNode:Ht,executeFunction:Kt});if(Array.isArray(e))return function(e,t,r){if(1!==t.length)throw new n("Array as function requires one non negative integer parameter.",r);const i=t[0];return C(i,r,{integer:!0,nonNegative:!0}),ce(e[i])}(e,t,i);if(D(e))return function(e,t,r){if(1!==t.length)throw new n("Object as function requires one string parameter.",r);const i=t[0];return ee(i,r),ce(e[i])}(e,t,i);if("string"==typeof e)return function(e,t,r){if(1!==t.length)throw new n("String as function requires one Obj parameter.",r);const i=ce(t[0]);if(D(i))return ce(i[e]);if(O(i,{integer:!0}))return ce(e[i]);throw new n(`string as function expects Obj or integer parameter, got ${d(i)}`,r)}(e,t,i);if(O(e))return function(e,t,r){if(C(e,r,{integer:!0}),1!==t.length)throw new n("Number as function requires one Arr parameter.",r);const i=t[0];return R(i,r),ce(i[e])}(e,t,i);throw new n("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[r,i]of Object.entries(e)){if(this.globalContext[r])throw new n(`Cannot redefine exported value "${r}"`,t);const e=en(r);if(e)throw new n(`Cannot shadow ${e}`,t);this.globalContext[r]={value:i}}this.contexts[0]!==this.globalContext&&this.addValues(e,t)}addValues(e,t){const r=this.contexts[0];for(const[i,s]of Object.entries(e)){if(r[i])throw new n(`Cannot redefine value "${i}"`,t);const e=en(i);if(e)throw new n(`Cannot shadow ${e}`,t);r[i]={value:ce(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:ce(n)};const r=this.nativeJsFunctions?.[t];return r?{value:r}:null}evaluateSymbol(e){if(lt(e)){const t=e[1];switch(t){case Dt["&&"]:case Dt["||"]:case Dt.array:case Dt.object:case Dt["defined?"]:case Dt.recur:case Dt.throw:case Dt["??"]:{const n=m(Lt.specialExpressions[t],e[2]);return{[l]:!0,functionType:"SpecialBuiltin",specialBuiltinSymbolType:t,sourceCodeInfo:e[2],arity:n.arity}}default:throw new n(`Unknown special builtin symbol type: ${t}`,e[2])}}if(ct(e)){const t=e[1],n=it[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(r=t)&&void 0!==r.value)return t.value;var r;throw new i(e[1],e[2])}}function en(e){return zt.includes(e)?`special expression "${e}"`:Vt.includes(e)?`builtin function "${e}"`:"self"===e?`builtin value "${e}"`:null}function tn(e={},t){const r=e.globalContext??{},i=e.contexts?[r,...e.contexts]:[r],s=new Qt({contexts:i,values:e.values,modules:t,nativeJsFunctions:e.jsFunctions&&Object.entries(e.jsFunctions).reduce((e,[t,r])=>{const i=t.split("."),s=i.pop();if(/^[A-Z]/.test(s))throw new n(`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 n(`Invalid empty identifier "${t}" in jsFunctions`,void 0);if(!/^[A-Z]/.test(e))throw new n(`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")}(r);const a={functionType:"NativeJsFunction",nativeFn:r,name:s,[l]:!0,arity:r.arity??{},docString:r.docString??""};return o===e&&function(e){const t=en(e);if(t)throw new n(`Cannot shadow ${t}`,void 0)}(s),o[s]=a,e},{})});return e.globalModuleScope?s:s.create({})}const nn=["^","*","/","%","+","-","<<",">>",">>>","++","<","<=","≤",">",">=","≥","==","!=","≠","&","xor","|","&&","||","??","|>"],rn=[...nn,"?",":","->","...",".",",","=",":",";"],sn=new Set(["comment","cond","def","defined?","block","doseq","if","let","loop","recur","throw","try","unless","while"]);function on(e){return!sn.has(e)}const an=new Set(nn);function un(e){return an.has(e)}const cn=new Set(rn);function ln(e){return cn.has(e)}const fn=["(",")","[","]","{","}","'",'"',"`",",",".",";"," ","\n","\r","\t"],hn=["0","1","2","3","4","5","6","7","8","9",...fn],pn=new Set(fn),dn=new Set(hn),yn=/\s/,gn=[0],mn=(e,t)=>{if('"'!==e[t])return gn;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 vn(e,t,n,r){return t===n.slice(r,r+t.length)?[t.length,[e,t]]:gn}const bn=/\d/,wn=/[0-7]/,Sn=/[0-9a-f]/i,xn=/[01]/,kn=/[\s)\]}(,;]/,En=(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(!dn.has(n)){const r=t;let i=e[t+=1];for(;i&&!pn.has(i);)n+=i,i=e[t+=1];return n.endsWith(":")?[t-r-1,["Symbol",n.slice(0,-1)]]:[t-r,["Symbol",n]]}return gn},Nn=[(e,t)=>{let n=e[t];if(!n||!yn.test(n))return gn;let r=n;for(n=e[t+=1];n&&yn.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 gn},(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 gn},(e,t)=>{const n=En(e,t);if(0===n[0]||!n[1])return gn;let r=n[1][1];r=r.startsWith("'")?r.slice(1,r.length-1):r;return void 0===Gt[r]?gn:[n[0],["ReservedSymbol",r]]},(e,t)=>vn("LParen","(",e,t),(e,t)=>vn("RParen",")",e,t),(e,t)=>vn("LBracket","[",e,t),(e,t)=>vn("RBracket","]",e,t),(e,t)=>vn("LBrace","{",e,t),(e,t)=>vn("RBrace","}",e,t),(e,t)=>{if('"'!==e[t]||'"'!==e[t+1]||'"'!==e[t+2])return gn;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}`]]},mn,(e,t)=>{if("#"!==e[t])return gn;const[n,r]=mn(e,t+1);if(!r)return gn;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 gn;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 gn;let i;for(i=t+2;i<e.length;i+=1){const t=e[i];if("binary"===r&&!xn.test(t))break;if("octal"===r&&!wn.test(t))break;if("hex"===r&&!Sn.test(t))break}const s=i-t;if(s<=2)return gn;const o=e[i];return o&&!kn.test(o)?gn:[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(!bn.test(e[n-1])||!bn.test(e[n+1]))return n===s?gn:[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 gn;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 gn;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(!bn.test(r))break}if((r||i)&&n===s)return gn;const u=n-t;if(0===u)return gn;const c=e[n];return c&&":"!==c&&!kn.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&&ln(n))return[3,["Operator",n]];const r=e.slice(t,t+2);if(t+1<e.length&&ln(r))return[2,["Operator",r]];const i=e[t]??"";return ln(i)?[1,["Operator",i]]:gn},En];function An(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 In(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 gn})(e,t);if(t+=r,r>0)return[t-n,i]}for(const r of Nn){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 $n(e,t){return"Symbol"===e?.[0]&&(!t||e[1]===t)}function jn(e,t){return function(e,t){$n(e,t)||Gn("Symbol",void 0,e)}(e,t),e}function On(e,t){return"ReservedSymbol"===e?.[0]&&(!t||e[1]===t)}function Cn(e,t){On(e,t)||Gn("ReservedSymbol",t,e)}function Fn(e,t){return Cn(e,t),e}function Mn(e,t){return"Operator"===e?.[0]&&(!t||e[1]===t)}function Un(e,t){Mn(e,t)||Gn("Operator",t,e)}function Tn(e){return"LParen"===e?.[0]}function Bn(e){Tn(e)||Gn("LParen",void 0,e)}function Pn(e){return"RParen"===e?.[0]}function Rn(e){Pn(e)||Gn("RParen",void 0,e)}function Dn(e){return"LBracket"===e?.[0]}function _n(e){return function(e){Dn(e)||Gn("LBracket",void 0,e)}(e),e}function Ln(e){return"RBracket"===e?.[0]}function Vn(e){Ln(e)||Gn("RBracket",void 0,e)}function zn(e){return"LBrace"===e?.[0]}function Wn(e){return function(e){zn(e)||Gn("LBrace",void 0,e)}(e),e}function Jn(e){return"RBrace"===e?.[0]}function qn(e){return"String"===e?.[0]}function Yn(e){return"Operator"===e?.[0]&&un(e[1])}function Gn(e,t,r){const i=r?`${r[0]} '${r[1]}'`:"end of input";throw new n(`Unexpected token: ${i}, expected ${e}${t?` '${t}'`:""}`,r?.[2])}function Xn(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 Zn=Object.entries(rt).reduce((e,[t,n])=>(e[n]=t,e),[]),Hn=Object.entries(Dt).reduce((e,[t,n])=>(e[n]=t,e),[]);function Kn(e){return at(e)?e[1]:ct(e)?Zn[e[1]]:Hn[e[1]]}const Qn=/^\$([1-9]\d?)?$/;function er(e,t){return t&&(e[2]=t),e}function tr(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 n(`Unknown binary operator: ${e}`,t)}}function nr(e,t,n){const r=er([o.NormalExpression,[e,t]],n);return ct(e)&&Z(it[e[1]].arity,r[1][1].length,n),r}function rr(e,t,n){return er([o.NormalExpression,[[o.NormalBuiltinSymbol,rt.get],[e,t]]],n)}function ir(e,t,r,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 nr(t,[r,i],s);case"&&":case"||":case"??":return er([o.SpecialExpression,[Dt[a],[r,i]]],s);default:throw new n(`Unknown binary operator: ${a}`,s)}}class sr{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 n(e[3],e[2])});const e=[];for(;!this.isAtEnd();)if(e.push(this.parseExpression(0,!0)),Mn(this.peek(),";"))this.advance();else if(!this.isAtEnd())throw new n("Expected ;",this.peekSourceCodeInfo());return e}parseExpression(e=0,t=!1){const r=this.peek();let i;if($n(r))switch(r[1]){case"let":return this.parseLet(r);case"if":case"unless":i=this.parseIfOrUnless(r);break;case"cond":i=this.parseCond(r);break;case"switch":i=this.parseSwitch(r);break;case"for":case"doseq":i=this.parseForOrDoseq(r);break;case"loop":i=this.parseLoop(r);break;case"try":i=this.parseTry(r)}else if(On(r,"do"))i=this.parseBlock()[0];else if(On(r,"export")){if(!t)throw new n("export is only allowed in module scope",r[2]);return this.parseExport(r)}i||=this.parseOperand();let s=this.peek();for(;!this.isAtExpressionEnd();){if(Yn(s)){const t=s[1],n=tr(t,s[2]);if(n<=e&&(12!==n||12!==e))break;const r=er(Dt[t]?[o.SpecialBuiltinSymbol,Dt[t]]:[o.NormalBuiltinSymbol,rt[t]],s[2]);this.advance();i=ir(s,r,i,this.parseExpression(n),s[2])}else if($n(s)){if(!on(s[1]))break;const t=3;if(t<=e)break;const r=this.parseSymbol(),o=this.parseExpression(t);if(lt(r))throw new n("Special expressions are not allowed in binary functional operators",r[2]);i=nr(r,[i,o],s[2])}else{if("?"!==s?.[1])break;{if(1<=e)break;this.advance();const t=this.parseExpression();if(!Mn(this.peek(),":"))throw new n("Expected :",this.peekSourceCodeInfo());this.advance();const r=this.parseExpression();i=er([o.SpecialExpression,[Dt.if,[i,t,r]]],i[2])}}s=this.peek()}return i}asToken(e){if(!e)throw new n("Unexpected end of input",this.peekSourceCodeInfo());return e}parseOperand(){let e=this.parseOperandPart(),t=this.peek();for(;Mn(t,".")||Dn(t)||Tn(t);)if("."===t[1]){this.advance();const r=this.asToken(this.peek());if(!$n(r))throw new n("Expected symbol",this.peekSourceCodeInfo());e=rr(e,er([o.String,r[1]],r[2]),t[2]),this.advance(),t=this.peek()}else if(Dn(t)){this.advance();const r=this.parseExpression();if(!Ln(this.peek()))throw new n("Expected closing bracket",this.peekSourceCodeInfo());e=rr(e,r,t[2]),this.advance(),t=this.peek()}else Tn(t)&&(e=this.parseFunctionCall(e),t=this.peek());return e}parseOperandPart(){const e=this.asToken(this.peek());if(Tn(e)){const e=this.parseState.position,t=this.parseLambdaFunction();if(t)return t;this.parseState.position=e,this.advance();const r=this.parseExpression();if(!Pn(this.peek()))throw new n("Expected closing parenthesis",this.peekSourceCodeInfo());return this.advance(),r}if(Mn(e)){const t=e[1];if(un(t))return this.advance(),er(void 0!==Dt[t]?[o.SpecialBuiltinSymbol,Dt[t]]:[o.NormalBuiltinSymbol,rt[t]],e[2]);if("->"===t)return this.parseShorthandLambdaFunction();throw new n(`Illegal operator: ${t}`,e[2])}if(zn(e))return this.parseObject();if(Dn(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 n(`Unknown token type: ${t}`,e[2])}}parseObject(){const e=Wn(this.peek());this.advance();const t=[];for(;!this.isAtEnd()&&!Jn(this.peek());){if(Mn(this.peek(),"..."))this.advance(),t.push(er([o.Spread,this.parseExpression()],this.peekSourceCodeInfo()));else{const e=this.peek();if(qn(e)){const n=this.parseString(e);t.push(er([o.String,n[1]],e[2]))}else if($n(e)){const n=e[1].startsWith("'")?this.stringFromQuotedSymbol(e[1]):e[1];t.push(er([o.String,n],e[2])),this.advance()}else{if(!Dn(e))throw new n("Expected key to be a symbol or a string",this.peekSourceCodeInfo());this.advance(),t.push(this.parseExpression()),Vn(this.peek()),this.advance()}Un(this.peek(),":"),this.advance(),t.push(this.parseExpression())}const e=this.peek();if(!Mn(e,",")&&!Jn(e))throw new n("Expected comma or closing brace",this.peekSourceCodeInfo());Mn(e,",")&&this.advance()}var r;return Jn(r=this.peek())||Gn("RBrace",void 0,r),this.advance(),er([o.SpecialExpression,[Dt.object,t]],e[2])}parseArray(){const e=_n(this.peek());this.advance();const t=[];for(;!this.isAtEnd()&&!Ln(this.peek());){Mn(this.peek(),"...")?(this.advance(),t.push(er([o.Spread,this.parseExpression()],this.peekSourceCodeInfo()))):t.push(this.parseExpression());const e=this.peek();if(!Mn(e,",")&&!Ln(e))throw new n("Expected comma or closing parenthesis",this.peekSourceCodeInfo());Mn(e,",")&&this.advance()}return Vn(this.peek()),this.advance(),er([o.SpecialExpression,[Dt.array,t]],e[2])}parseFunctionCall(e){this.advance();const t=[];for(;!this.isAtEnd()&&!Pn(this.peek());){Mn(this.peek(),"...")?(this.advance(),t.push(er([o.Spread,this.parseExpression()],this.peekSourceCodeInfo()))):t.push(this.parseExpression());const e=this.peek();if(!Mn(e,",")&&!Pn(e))throw new n("Expected comma or closing parenthesis",this.peek()?.[2]);Mn(e,",")&&this.advance()}if(!Pn(this.peek()))throw new n("Expected closing parenthesis",this.peekSourceCodeInfo());if(this.advance(),!lt(e))return ct(e)||at(e)?nr(e,t,e[2]):er([o.NormalExpression,[e,t]],e[2]);{const r=e[1];switch(Z(Lt.specialExpressions[r].arity,t.length,e[2]),r){case Dt["||"]:case Dt["&&"]:case Dt.recur:case Dt.array:case Dt.object:case Dt["??"]:return er([o.SpecialExpression,[r,t]],e[2]);case Dt["defined?"]:{const[n]=t;return er([o.SpecialExpression,[r,n]],e[2])}case Dt.throw:{const[n]=t;return er([o.SpecialExpression,[r,n]],e[2])}case Dt["0_lambda"]:case Dt["0_def"]:throw new n(`${r} is not allowed`,e[2]);default:throw new n(`Unknown special expression: ${r}`,e[2])}}}parseLambdaFunction(){const e=this.asToken(this.peek());if(Tn(e)&&$n(this.peekAhead(1))&&Mn(this.peekAhead(2),"->"))return null;try{const t=this.parseFunctionArguments();if(!Mn(this.peek(),"->"))return null;let n;this.advance();let r="";if(On(this.peek(),"do")){const e=this.parseBlock(!0);r=e[1],n=e[0][1][1]}else n=[this.parseExpression()];return er([o.SpecialExpression,[Dt["0_lambda"],[t,n],r]],e[2])}catch{return null}}parseFunctionArguments(){const e=this.peek();if($n(e))return[er([dt,[this.parseSymbol(),void 0]],e[2])];Bn(e),this.advance();let t=!1,r=!1;const i=[];for(;!this.isAtEnd()&&!Pn(this.peek())&&!$n(this.peek(),"let");){if(t)throw new n("Rest argument must be last",this.peekSourceCodeInfo());const e=this.parseBindingTarget();if(void 0!==e[1][1]&&(r=!0),e[0]===yt&&(t=!0),r&&!e[1][1])throw new n("Default arguments must be last",this.peekSourceCodeInfo());if(i.push(e),!Mn(this.peek(),",")&&!Pn(this.peek())&&!$n(this.peek(),"let"))throw new n("Expected comma or closing parenthesis",this.peekSourceCodeInfo());Mn(this.peek(),",")&&this.advance()}if(!Pn(this.peek()))throw new n("Expected closing parenthesis",this.peekSourceCodeInfo());return this.advance(),i}parseShorthandLambdaFunction(){const e=this.asToken(this.peek());this.advance();const t=this.parseState.position;let r,i="";if(On(this.peek(),"do")){const e=this.parseBlock(!0);i=e[1],r=e[0][1][1]}else r=[this.parseExpression()];const s=this.parseState.position-1;let a=0,u="NOT_SET";for(let r=t;r<=s;r+=1){const t=this.tokenStream.tokens[r];if($n(t)){const r=Qn.exec(t[1]);if(r){const t=r[1]??"1";if("1"===t){if(!r[1]&&"WITH_1"===u||r[1]&&"NAKED"===u)throw new n("Please make up your mind, either use $ or $1",e[2]);u=r[1]?"WITH_1":"NAKED"}if(a=Math.max(a,Number(t)),a>20)throw new n("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(er([dt,[[o.UserDefinedSymbol,"$"],void 0]],e[2])):c.push(er([dt,[[o.UserDefinedSymbol,`$${t}`],void 0]],e[2]));return er([o.SpecialExpression,[Dt["0_lambda"],[c,r],i]],e[2])}parseOptionalDefaulValue(){if(Mn(this.peek(),"="))return this.advance(),this.parseExpression()}parseBindingTarget({requireDefaultValue:e,noRest:t}={}){const r=this.peek();if($n(r)){const t=this.parseSymbol();if(!at(t))throw new n("Expected user defined symbol",r[2]);const i=this.parseOptionalDefaulValue();if(e&&!i)throw new n("Expected assignment",this.peekSourceCodeInfo());return er([dt,[t,i]],r[2])}if(Mn(r,"...")){if(t)throw new n("Rest element not allowed",r[2]);this.advance();const e=ut(this.parseSymbol());if(Mn(this.peek(),"="))throw new n("Rest argument can not have default value",this.peekSourceCodeInfo());return er([yt,[e[1],void 0]],r[2])}if(Dn(r)){this.advance();const t=[];let i=this.asToken(this.peek()),s=!1;for(;!Ln(i);){if(s)throw new n("Rest argument must be last",i[2]);if(Mn(i,",")){t.push(null),this.advance(),i=this.asToken(this.peek());continue}const e=this.parseBindingTarget();e[0]===yt&&(s=!0),t.push(e),i=this.asToken(this.peek()),Ln(i)||(Un(i,","),this.advance()),i=this.asToken(this.peek())}this.advance();const o=this.parseOptionalDefaulValue();if(e&&!o)throw new n("Expected assignment",this.peekSourceCodeInfo());return er([mt,[t,o]],r[2])}if(zn(r)){this.advance();const t={};let i=this.asToken(this.peek()),s=!1;for(;!Jn(i);){if(s)throw new n("Rest argument must be last",i[2]);Mn(i,"...")&&(s=!0,this.advance());const e=this.parseSymbol(),o=Kn(e);if(i=this.asToken(this.peek()),On(i,"as")){if(s)throw new n("Rest argument can not have alias",i[2]);this.advance();const e=ut(this.parseSymbol());if(t[e[1]])throw new n(`Duplicate binding name: ${e}`,i[2]);t[o]=er([dt,[e,this.parseOptionalDefaulValue()]],r[2])}else if(Jn(i)||Mn(i,",")||Mn(i,"=")){const o=ut(e,e[2]);if(t[o[1]])throw new n(`Duplicate binding name: ${o}`,i[2]);if(s&&Mn(this.peek(),"="))throw new n("Rest argument can not have default value",this.peekSourceCodeInfo());t[o[1]]=er(s?[yt,[o[1],this.parseOptionalDefaulValue()]]:[dt,[o,this.parseOptionalDefaulValue()]],r[2])}else if(Mn(i,":")){if(this.advance(),i=this.asToken(this.peek()),!zn(i)&&!Dn(i))throw new n("Expected object or array",i[2]);t[o]=this.parseBindingTarget()}Jn(this.peek())||(Un(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 n("Expected assignment",i[2]);return er([gt,[t,o]],r[2])}throw new n("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=er([o.Binding,[t,n]],e[2]);return er([o.SpecialExpression,[Dt.let,r]],e[2])}parseBlock(e=!1){const t=Fn(this.peek(),"do");this.advance();let r="";e&&function(e){return"DocString"===e?.[0]}(this.peek())&&(r=this.parseDocString());const i=[];for(;!this.isAtEnd()&&!On(this.peek(),"end");)if(i.push(this.parseExpression()),Mn(this.peek(),";"))this.advance();else if(!On(this.peek(),"end"))throw new n("Expected end",this.peekSourceCodeInfo());return Cn(this.peek(),"end"),this.advance(),[er([o.SpecialExpression,[Dt.block,i]],t[2]),r]}parseImplicitBlock(e){const t=[];for(;!this.isAtEnd()&&!this.isImplicitBlockEnd(e);)Mn(this.peek(),";")?this.advance():t.push(this.parseExpression());if(this.assertImplicitBlockEnd(e),0===t.length)throw new n("Expected expression",this.peekSourceCodeInfo());return 1===t.length?t[0]:er([o.SpecialExpression,[Dt.block,t]],this.peekSourceCodeInfo())}assertImplicitBlockEnd(e){if(!this.isImplicitBlockEnd(e))throw new n(`Expected ${e.map(e=>e[1]).join(" or ")}`,this.peekSourceCodeInfo())}isImplicitBlockEnd(e){for(const t of e)if(On(this.peek(),t))return!0;return!1}parseLoop(e){this.advance(),Bn(this.peek()),this.advance();const t=[];let r=this.peek();for(;!this.isAtEnd()&&!Pn(r);){const e=this.parseBindingTarget({requireDefaultValue:!0,noRest:!0}),n=e[1][1];e[1][1]=void 0,t.push(er([o.Binding,[e,n]],e[2])),Mn(this.peek(),",")&&this.advance(),r=this.peek()}if(0===t.length)throw new n("Expected binding",this.peekSourceCodeInfo());Rn(r),this.advance(),Un(this.peek(),"->"),this.advance();const i=this.parseExpression();return er([o.SpecialExpression,[Dt.loop,t,i]],e[2])}parseTry(e){this.advance();const t=this.parseImplicitBlock(["catch"]);let n;this.advance(),Tn(this.peek())&&(this.advance(),n=this.parseSymbol(),Rn(this.peek()),this.advance());const r=this.parseImplicitBlock(["end"]);return this.advance(),er([o.SpecialExpression,[Dt.try,t,n,r]],e[2])}parseForOrDoseq(e){const t="doseq"===e[1];this.advance(),Bn(this.peek()),this.advance();const r=[];for(;!this.isAtEnd()&&!Pn(this.peek());){const e=this.parseForLoopBinding(),t=r.flatMap(e=>Object.keys(St(e[0][1][0]))),i=St(e[0][1][0]);if(Object.keys(i).some(e=>t.includes(e)))throw new n("Duplicate binding",e[0][2]);r.push(e),Mn(this.peek(),",")&&this.advance()}Rn(this.peek()),this.advance(),Un(this.peek(),"->"),this.advance();const i=this.parseExpression();return er(t?[o.SpecialExpression,[Dt.doseq,r,i]]:[o.SpecialExpression,[Dt.for,r,i]],e[2])}parseForLoopBinding(){const e=this.parseBinding(),t=[];let r=this.asToken(this.peek());this.assertInternalLoopBindingDelimiter(r,["let","when","while"]);const i=[];if("let"===r[1])for(t.push("&let");$n(r,"let");){const e=this.parseLet(r),t=i.flatMap(e=>Object.keys(St(e[1][0])));if(Object.keys(St(e[1][1][1][0])).some(e=>t.includes(e)))throw new n("Duplicate binding",e[1][1][2]);i.push(e[1][1]),r=this.asToken(this.peek()),this.assertInternalLoopBindingDelimiter(r,["let","when","while"]),r=this.asToken(this.peek())}let s,o;for(;On(r,"when")||On(r,"while");){this.advance(),"when"===r[1]?(t.push("&when"),s=this.parseExpression()):(t.push("&while"),o=this.parseExpression()),r=this.asToken(this.peek());const e=t.includes("&when")&&t.includes("&while")?[]:t.includes("&when")?["while"]:["when"];this.assertInternalLoopBindingDelimiter(r,e),r=this.asToken(this.peek())}return this.assertInternalLoopBindingDelimiter(r,[]),[e,i,s,o]}assertInternalLoopBindingDelimiter(e,t){if(!this.isInternalLoopBindingDelimiter(e,t)){const r=`${[...t,","].map(e=>`"${e}"`).join(", ")} or ")"`;throw new n(`Expected symbol ${r}`,e[2])}}isInternalLoopBindingDelimiter(e,t){if(Mn(e,",")||Pn(e))return!0;for(const n of t){if("let"===n&&$n(e,"let"))return!0;if(["when","while"].includes(n)&&On(e,n))return!0}return!1}parseBinding(){const e=jn(this.peek()),t=ut(this.parseSymbol());Cn(this.peek(),"in"),this.advance();const n=this.parseExpression();return er([o.Binding,[er([dt,[t,void 0]],e[2]),n]],e[2])}parseIfOrUnless(e){const t="unless"===e[1];this.advance();const n=this.parseExpression();Cn(this.peek(),"then"),this.advance();const r=this.parseImplicitBlock(["else","end"]);let i;return On(this.peek(),"else")&&(this.advance(),i=this.parseImplicitBlock(["end"])),this.advance(),er(t?[o.SpecialExpression,[Dt.unless,[n,r,i]]]:[o.SpecialExpression,[Dt.if,[n,r,i]]],e[2])}parseCond(e){this.advance();const t=[];for(;!this.isAtEnd()&&!On(this.peek(),"end");){Cn(this.peek(),"case"),this.advance();const e=this.parseExpression();Cn(this.peek(),"then"),this.advance();const n=this.parseImplicitBlock(["case","end"]);if(t.push([e,n]),On(this.peek(),"end"))break}return Cn(this.peek()),this.advance(),er([o.SpecialExpression,[Dt.cond,t]],e[2])}parseSwitch(e){this.advance();const t=this.parseExpression(),n=[];for(;!this.isAtEnd()&&!On(this.peek(),"end");){Cn(this.peek(),"case"),this.advance();const e=this.parseExpression();Cn(this.peek(),"then"),this.advance();const t=this.parseImplicitBlock(["case","end"]);if(n.push([e,t]),On(this.peek(),"end"))break}return Cn(this.peek(),"end"),this.advance(),er([o.SpecialExpression,[Dt.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 Mn(e)?[";",",",":"].includes(e[1]):!!On(e)&&["else","when","while","case","catch","let","then","end","do"].includes(e[1])}parseExport(e){this.advance();const t=this.peek();if($n(t,"let")){const n=this.parseLet(jn(t));return er([o.SpecialExpression,[Dt["0_def"],n[1][1]]],e[2])}throw new n("Expected let",this.peekSourceCodeInfo())}stringToSymbolNode(e,t){return void 0!==Dt[e]&&"fn"!==e&&"def"!==e&&"defn"!==e?er([o.SpecialBuiltinSymbol,Dt[e]],t):void 0!==rt[e]?er([o.NormalBuiltinSymbol,rt[e]],t):er([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(),!$n(e))throw new n(`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=Fn(this.peek());this.advance();const t=e[1];return function(e){return e in Yt}(t)?er([o.Number,Yt[t]],e[2]):er([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 er([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 ye(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 er([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=er([o.String,n],e[2]),s=er([o.String,r],e[2]);return er([o.NormalExpression,[er([o.NormalBuiltinSymbol,rt.regexp],e[2]),[i,s]]],e[2])}}const or=new Set([...Vt,...zt,...Object.keys(Gt)]);class ar{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 or.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 ur{cache={};firstEntry=void 0;lastEntry=void 0;_size=0;maxSize;constructor(e){if(this.maxSize=null===e?null:ue(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}}class cr{astCache;astCacheSize;debug;modules;constructor(e={}){if(this.debug=e.debug??!1,this.astCacheSize=e.astCacheSize??null,this.astCacheSize){this.astCache=new ur(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=tn(t,this.modules);return Zt(n,r),r.globalContext}getUndefinedSymbols(e,t={}){const n="string"==typeof e?this.generateAst(e,t):e,r=tn(t,this.modules);return Wt(n,r,Lt,Ht)}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?An(e,r,n):void 0,o=In(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?Xn(n,{removeWhiteSpace:!1}):n}parse(e){const t={body:[],hasDebugData:(e=Xn(e,{removeWhiteSpace:!0})).hasDebugData};return t.body=new sr(e,{position:0}).parse(),t}evaluate(e,t){return Zt(e,tn(t,this.modules))}transformSymbols(e,t){return function(e,t){return{...e,tokens:e.tokens.map(e=>$n(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 ar(e,t,this,n)}}export{cr as Lits,S as asLitsFunction,I as asNativeJsFunction,E as asUserDefinedFunction,x as assertLitsFunction,$ as assertNativeJsFunction,N as assertUserDefinedFunction,j as isBuiltinFunction,Be as isGrid,s as isLitsError,w as isLitsFunction,Pe as isMatrix,A as isNativeJsFunction,k as isUserDefinedFunction,Te as isVector,Vt as normalExpressionKeys,zt as specialExpressionKeys};
1
+ function e(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 t extends Error{params;constructor(e){super(`recur, params: ${e}`),Object.setPrototypeOf(this,t.prototype),this.name="RecurSignal",this.params=e}}class n extends Error{sourceCodeInfo;shortMessage;constructor(t,r){const i=t instanceof Error?t.message:`${t}`;super(function(t,n){if(!n)return t;const r=`${n.position.line}:${n.position.column}`;return`${t}${n.filePath?`\n${n.filePath}:${r}`:`\nLocation ${r}`}\n${n.code}\n${e(n)}`}(i,r)),this.shortMessage=i,this.sourceCodeInfo=r,Object.setPrototypeOf(this,n.prototype),this.name="LitsError"}getCodeMarker(){return this.sourceCodeInfo&&e(this.sourceCodeInfo)}}class r extends n{userMessage;constructor(e,t){super(e,t),this.userMessage=e,Object.setPrototypeOf(this,r.prototype),this.name="UserDefinedError"}}class i extends n{symbol;constructor(e,t){super(`Undefined symbol '${e}'.`,t),this.symbol=e,Object.setPrototypeOf(this,i.prototype),this.name="UndefinedSymbolError"}}function s(e){return e instanceof n}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,r){return new n(`Expected ${e}, got ${d(t)}.`,g(t,r))}function y(e,t){return v(e,t),e}function v(e,t){if(!function(e){return void 0!==e}(e))throw new n("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){return k(e,t),e}function k(e,t){if(!w(e))throw m("LitsFunction",e,t)}function x(e){return w(e)&&"UserDefined"===e.functionType}function E(e,t){return N(e,t),e}function N(e,t){if(!x(e))throw m("NativeJsFunction",e,t)}function $(e){return w(e)&&"NativeJsFunction"===e.functionType}function I(e,t){return A(e,t),e}function A(e,t){if(!$(e))throw m("NativeJsFunction",e,t)}function j(e){return b(e)&&"Builtin"===e.functionType}function O(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 C(e,t,r={}){if(!O(e,r))throw new n(`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(" ")}(r)}, got ${d(e)}.`,g(e,t))}function F(e){return void 0!==e}function U(e,t){return T(e,t),e}function T(e,t){if(!F(e))throw m("not undefined",e,t)}function B(e){return Array.isArray(e)||"string"==typeof e}function P(e,t){if(!B(e))throw m("string or array",e,t)}function M(e){return!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof RegExp||w(e)||V(e))}function D(e,t){if(!M(e))throw m("object",e,t)}function R(e){return B(e)||M(e)}function _(e,t){return L(e,t),e}function L(e,t){if(!R(e))throw m("string, array or object",e,t)}function V(e){return null!==e&&"object"==typeof e&&!!e[f]}function z(e,t){if(!function(e){return V(e)||"string"==typeof e}(e))throw m("string or RegularExpression",e,t)}function W(e,t){return J(e,t),e}function J(e,t){if(!function(e){return"number"==typeof e||!!R(e)||!!w(e)}(e))throw m("FunctionLike",e,t)}function q(e,t){const{min:n}=e;return!("number"==typeof n&&t<n)}function Y(e,t,r){const{min:i,max:s}=e;if("number"==typeof i&&t<i)throw new n(`Wrong number of arguments, expected at least ${i}, got ${d(t)}.`,r);if("number"==typeof s&&t>s)throw new n(`Wrong number of arguments, expected at most ${s}, got ${d(t)}.`,r)}function G(e){return{min:e,max:e}}const X={"<<":{evaluate:([e,t],n)=>(C(e,n,{integer:!0}),C(t,n,{integer:!0,nonNegative:!0}),e<<t),arity:G(2)},">>":{evaluate:([e,t],n)=>(C(e,n,{integer:!0}),C(t,n,{integer:!0,nonNegative:!0}),e>>t),arity:G(2)},">>>":{evaluate:([e,t],n)=>(C(e,n,{integer:!0}),C(t,n,{integer:!0,nonNegative:!0}),e>>>t),arity:G(2)},"&":{evaluate:([e,...t],n)=>(C(e,n,{integer:!0}),t.reduce((e,t)=>(C(t,n,{integer:!0}),e&t),e)),arity:{min:2}},"|":{evaluate:([e,...t],n)=>(C(e,n,{integer:!0}),t.reduce((e,t)=>(C(t,n,{integer:!0}),e|t),e)),arity:{min:2}},xor:{evaluate:([e,...t],n)=>(C(e,n,{integer:!0}),t.reduce((e,t)=>(C(t,n,{integer:!0}),e^t),e)),arity:{min:2}}};function Z(e,t={}){return"string"==typeof e&&((!t.nonEmpty||0!==e.length)&&(!t.char||1===e.length))}function H(e,t,n={}){if(!Z(e,n))throw m(""+(n.nonEmpty?"non empty string":n.char?"character":"string"),e,t)}function K(e,t,n={}){return H(e,t,n),e}function Q(e){return"string"==typeof e||"number"==typeof e}function ee(e,t){return te(e,t),e}function te(e,t){if(!Q(e))throw m("string or number",e,t)}function ne(e,t){return!!R(e)&&("string"==typeof e||Array.isArray(e)?!!O(t,{integer:!0})&&(t>=0&&t<e.length):!!Object.getOwnPropertyDescriptor(e,t))}function re(e,t,r){if(te(e,r),te(t,r),"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 n(`Cannot compare values of different types: ${typeof e} and ${typeof t}`,r)}function ie(e,t,n){if(e===t)return!0;if("number"==typeof e&&"number"==typeof t)return function(e,t,n=ue){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(!ie(U(e[r],n),U(t[r],n),n))return!1;return!0}if(V(e)&&V(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=K(r[i],n);if(!ie(e[s],t[s],n))return!1}return!0}return!1}function se(e){return e??null}function oe(...e){const t=new Set;for(const n of e)n.forEach(e=>t.add(e));return t}function ae(e,t){t.forEach(t=>e.add(t))}const ue=1e-10;function ce(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 le(e,t){if(!Array.isArray(e))throw m("array",e,t)}function fe(e,t){if(!function(e){return Array.isArray(e)&&e.every(e=>"string"==typeof e)}(e))throw m("array of strings",e,t)}function he(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 pe={filter:{evaluate:([e,t],n,r,{executeFunction:i})=>{if(L(e,n),J(t,n),Array.isArray(e)){return e.filter(e=>i(t,[e],r,n))}return Z(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:G(2)},map:{evaluate:(e,t,r,{executeFunction:i})=>{const s=W(e.at(-1),t);if(M(e[0]))return function({colls:e,contextStack:t,executeFunction:r,fn:i,sourceCodeInfo:s}){D(e[0],s);const o=Object.keys(e[0]),a={};return e.forEach(e=>{D(e,s);const t=Object.keys(e);if(t.length!==o.length)throw new n(`All objects must have the same keys. Expected: ${o.join(", ")}. Found: ${t.join(", ")}`,s);if(!t.every(e=>o.includes(e)))throw new n(`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,n)=>(e[n]=r(i,a[n],t,s),e),{})}({colls:e.slice(0,-1),fn:s,sourceCodeInfo:t,contextStack:r,executeFunction:i});const o=e.slice(0,-1);P(o[0],t);const a="string"==typeof o[0];let u=o[0].length;o.slice(1).forEach(e=>{a?H(e,t):le(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,r,t));return a?(l.forEach(e=>H(e,t)),l.join("")):l},arity:{min:2}},reduce:{evaluate:([e,t,n],r,i,{executeFunction:s})=>(L(e,r),J(t,r),T(n,r),"string"==typeof e?(H(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:G(3)},get:{evaluate:(e,t)=>{const[n,r]=e,i=se(e[2]);if(te(r,t),null===n)return i;L(n,t);const s=function(e,t){if(M(e)){if("string"==typeof t&&ne(e,t))return se(e[t])}else if(O(t,{nonNegative:!0,integer:!0})&&t>=0&&t<e.length)return se(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:(L(e,t),Array.isArray(e)?e.length:Object.keys(e).length),arity:G(1)},"contains?":{evaluate:([e,t],n)=>null!==e&&(L(e,n),Z(e)?(H(t,n),e.includes(t)):B(e)?(T(t,n),!!e.find(e=>ie(U(e),t,n))):(H(t,n),t in e)),arity:G(2)},assoc:{evaluate:([e,t,n],r)=>(L(e,r),te(t,r),T(n,r),function(e,t,n,r){if(L(e,r),te(t,r),Array.isArray(e)||"string"==typeof e){if(C(t,r,{integer:!0}),C(t,r,{gte:0}),C(t,r,{lte:e.length}),"string"==typeof e)return H(n,r,{char:!0}),`${e.slice(0,t)}${n}${e.slice(t+1)}`;const i=[...e];return i[t]=n,i}H(t,r);const i={...e};return i[t]=n,i}(e,t,n,r)),arity:G(3)},"++":{evaluate:(e,t)=>(O(e[0])||L(e[0],t),Array.isArray(e[0])?e.reduce((e,n)=>(le(n,t),e.concat(n)),[]):Q(e[0])?e.reduce((e,n)=>(te(n,t),`${e}${n}`),""):e.reduce((e,n)=>(D(n,t),Object.assign(e,n)),{})),arity:{min:1}}},de={range:{evaluate:(e,t)=>{const[n,r,i]=e;let s,o,a;C(n,t,{finite:!0}),1===e.length?(s=0,o=n,a=o>=0?1:-1):2===e.length?(C(r,t,{finite:!0}),s=n,o=r,a=o>=s?1:-1):(C(r,t,{finite:!0}),C(i,t,{finite:!0}),s=n,o=r,a=i,C(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)=>{C(t,n,{integer:!0,nonNegative:!0});const r=[];for(let n=0;n<t;n+=1)r.push(e);return r},arity:G(2)},flatten:{evaluate:([e,t],n)=>{le(e,n);const r=void 0===t||t===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:function(e,t,n={}){return C(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})=>(le(e,n),J(t,n),e.map(e=>i(t,[e],r,n)).flat(1)),arity:G(2)},"moving-fn":{evaluate:([e,t,n],r,i,{executeFunction:s})=>{le(e,r),C(t,r,{integer:!0,lte:e.length}),J(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:G(3)},"running-fn":{evaluate:([e,t],n,r,{executeFunction:i})=>{le(e,n),J(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:G(2)}},ge={nth:{evaluate:(e,t)=>{const[n,r]=e,i=se(e[2]);if(C(r,t,{integer:!0}),null===n)return i;if(P(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;P(e,t);return se(e[0])},arity:G(1)},last:{evaluate:([e],t)=>{if(null===e)return null;P(e,t);return se(e.at(-1))},arity:G(1)},pop:{evaluate:([e],t)=>(P(e,t),"string"==typeof e?e.substring(0,e.length-1):e.slice(0,e.length-1)),arity:G(1)},"index-of":{evaluate:([e,t],n)=>{if(T(t,n),null===e)return null;if(P(e,n),"string"==typeof e){H(t,n);const r=e.indexOf(t);return-1!==r?r:null}{const r=e.findIndex(e=>ie(U(e,n),t),n);return-1!==r?r:null}},arity:G(2)},push:{evaluate:([e,...t],n)=>(P(e,n),"string"==typeof e?(he(t,n),[e,...t].join("")):[...e,...t]),arity:{min:2}},rest:{evaluate:([e],t)=>(P(e,t),Array.isArray(e)?e.length<=1?[]:e.slice(1):e.substring(1)),arity:G(1)},next:{evaluate:([e],t)=>(P(e,t),Array.isArray(e)?e.length<=1?null:e.slice(1):e.length<=1?null:e.substring(1)),arity:G(1)},reverse:{evaluate:([e],t)=>null===e?null:(P(e,t),Array.isArray(e)?[...e].reverse():e.split("").reverse().join("")),arity:G(1)},second:{evaluate:([e],t)=>null===e?null:(P(e,t),se(e[1])),arity:G(1)},slice:{evaluate:(e,t)=>{const[n,r,i]=e;return P(n,t),C(r,t,{integer:!0}),2===e.length?(Array.isArray(n),n.slice(r)):(C(i,t,{integer:!0}),Array.isArray(n),n.slice(r,i))},arity:{min:2,max:3}},some:{evaluate:([e,t],n,r,{executeFunction:i})=>(J(t,n),null===e?null:(P(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:G(2)},sort:{evaluate:(e,t,n,{executeFunction:r})=>{const[i]=e,s=1===e.length,o=s?null:e[1];if(P(i,t),"string"==typeof i){const e=i.split("");return s?e.sort((e,n)=>re(e,n,t)):(J(o,t),e.sort((e,i)=>{const s=r(o,[e,i],n,t);return C(s,t,{finite:!0}),s})),e.join("")}const a=[...i];return s?a.sort((e,n)=>(te(e,t),te(n,t),re(e,n,t))):a.sort((e,i)=>{J(o,t);const s=r(o,[e,i],n,t);return C(s,t,{finite:!0}),s}),a},arity:{min:1,max:2}}},me=new WeakSet,ye=new WeakSet,ve=new WeakSet,be=new WeakSet,we=new WeakSet,Se=new WeakSet,ke=new WeakSet;function xe(e){return Array.isArray(e)?(me.has(e)||(Ee(e),Ae(e)||Ie(e)),e):e}function Ee(e){return!!Array.isArray(e)&&(!!ye.has(e)||!ve.has(e)&&(e.every(e=>O(e))?(me.add(e),ye.add(e),!0):(ve.add(e),!1)))}function Ne(e,t){if(!Ee(e))throw new n(`Expected a vector, but got ${e}`,t)}function $e(e,t){if(Ne(e,t),0===e.length)throw new n(`Expected a non empty vector, but got ${e}`,t)}function Ie(e){if(!Array.isArray(e))return!1;if(Se.has(e))return!0;if(ke.has(e))return!1;if(0===e.length)return ke.add(e),!1;if(!Array.isArray(e[0]))return ke.add(e),!1;const t=e[0].length;for(const n of e.slice(1)){if(!Array.isArray(n))return ke.add(e),!1;if(n.length!==t)return ke.add(e),!1}return me.add(e),Se.add(e),!0}function Ae(e){if(!Array.isArray(e))return!1;if(be.has(e))return!0;if(we.has(e))return!1;if(0===e.length)return we.add(e),!1;if(!Array.isArray(e[0])||0===e[0].length)return we.add(e),!1;const t=e[0].length;for(const n of e)if(!Array.isArray(n)||n.length!==t||n.some(e=>!O(e)))return we.add(e),!1;return me.add(e),Se.add(e),be.add(e),!0}function je(e,t){let r=!1,i=!1;for(const s of e)if(Ee(s))r=!0;else if(Ae(s))i=!0;else if(!O(s))throw new n("Invalid parameter type: "+typeof s,t);if(i){if(r)throw new n("Cannot mix vector and matrix types",t);let i=null,s=null;for(const r of e)if(Ae(r))if(null===i)i=r.length,s=r[0].length;else if(r.length!==i||r[0].length!==s)throw new n("Matrix dimensions do not match",t);return["matrix",e.map(e=>Ae(e)?e:Array.from({length:i},()=>Array.from({length:s},()=>e)))]}if(r){let r=null;for(const i of e)if(Ee(i))if(null===r)r=i.length;else if(i.length!==r)throw new n("Vector lengths do not match",t);return["vector",e.map(e=>Ee(e)?e:Array.from({length:r},()=>e))]}return["number",e]}function Oe(e){return(t,n)=>{const[r,i]=je(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 Ce(e){return(t,n)=>{const[r,i]=je(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 Fe(e,t){return(n,r)=>{if(0===n.length)return e;const[i,s]=je(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 Ue={inc:{evaluate:Oe(e=>e+1),arity:G(1)},dec:{evaluate:Oe(e=>e-1),arity:G(1)},"+":{evaluate:Fe(0,(e,t)=>e+t),arity:{}},"*":{evaluate:Fe(1,(e,t)=>e*t),arity:{}},"/":{evaluate:(e,t)=>{if(0===e.length)return 1;const[n,r]=je(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]=je(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:Ce((e,t)=>Math.trunc(e/t)),arity:G(2)},mod:{evaluate:Ce((e,t)=>e-t*Math.floor(e/t)),arity:G(2)},"%":{evaluate:Ce((e,t)=>e%t),arity:G(2)},sqrt:{evaluate:Oe(e=>Math.sqrt(e)),arity:G(1)},cbrt:{evaluate:Oe(e=>Math.cbrt(e)),arity:G(1)},"^":{evaluate:Ce((e,t)=>e**t),arity:G(2)},round:{evaluate:([e,t],n)=>{const[r,i]=je([e],n);if("number"===r){if(void 0===t||0===t)return Math.round(i[0]);{C(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));{C(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)));{C(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:Oe(e=>Math.trunc(e)),arity:G(1)},floor:{evaluate:Oe(e=>Math.floor(e)),arity:G(1)},ceil:{evaluate:Oe(e=>Math.ceil(e)),arity:G(1)},min:{evaluate:(e,t)=>{if(1===e.length&&Ee(e[0])){const n=e[0];return $e(n,t),n.reduce((e,t)=>Math.min(e,t),1/0)}const[n,...r]=e;return C(n,t),r.reduce((e,n)=>(C(n,t),Math.min(e,n)),n)},arity:{min:1}},max:{evaluate:(e,t)=>{if(1===e.length&&Ee(e[0])){const n=e[0];return $e(n,t),n.reduce((e,t)=>Math.max(e,t),-1/0)}const[n,...r]=e;return C(n,t),r.reduce((e,n)=>(C(n,t),Math.max(e,n)),n)},arity:{min:1}},abs:{evaluate:Oe(e=>Math.abs(e)),arity:G(1)},sign:{evaluate:Oe(e=>Math.sign(e)),arity:G(1)}};function Te([e,...t],n){const r=U(e,n);for(const e of t)if(!ie(r,U(e,n),n))return!1;return!0}const Be={"==":{evaluate:(e,t)=>Te(e,t),arity:{min:1}},"≠":{evaluate:(e,t)=>!Te(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=ee(e);for(const e of t){if(re(r,ee(e),n)<=0)return!1;r=ee(e)}return!0},arity:{min:1}},"<":{evaluate:([e,...t],n)=>{let r=ee(e);for(const e of t){if(re(r,ee(e),n)>=0)return!1;r=ee(e)}return!0},arity:{min:1}},">=":{evaluate:([e,...t],n)=>{let r=ee(e);for(const e of t){if(re(r,ee(e),n)<0)return!1;r=ee(e)}return!0},arity:{min:1}},"<=":{evaluate:([e,...t],n)=>{let r=ee(e);for(const e of t){if(re(r,ee(e),n)>0)return!1;r=ee(e)}return!0},arity:{min:1}},"!":{evaluate:([e])=>!e,arity:G(1)},"epoch->iso-date":{evaluate:([e],t)=>(C(e,t),new Date(e).toISOString()),arity:G(1)},"iso-date->epoch":{evaluate:([e],t)=>{H(e,t);const n=new Date(e).valueOf();return C(n,t,{finite:!0}),n},arity:G(1)},"write!":{evaluate:(e,t)=>(console.log(...e),e.length>0?U(e[e.length-1],t):null),arity:{}},boolean:{evaluate:([e])=>!!e,arity:G(1)},compare:{evaluate:([e,t],n)=>(te(e,n),te(t,n),re(e,t,n)),arity:G(2)},"json-parse":{evaluate:([e],t)=>(H(e,t),JSON.parse(e)),arity:G(1)},"json-stringify":{evaluate:([e,t],n)=>(T(e,n),void 0===t?JSON.stringify(e):(C(t,n),JSON.stringify(e,null,t))),arity:{min:1,max:2}},import:{evaluate:([e],t,r)=>{H(e,t);const i=e.indexOf(".");if(-1!==i){const s=e.substring(0,i),o=e.substring(i+1),a=r.getModule(s);if(!a)throw new n(`Unknown module: '${s}'`,t);const u=a.functions[o];if(!u)throw new n(`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=r.getModule(s);if(!o)throw new n(`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:G(1)}},Pe={keys:{evaluate:([e],t)=>(D(e,t),Object.keys(e)),arity:G(1)},vals:{evaluate:([e],t)=>(D(e,t),Object.values(e)),arity:G(1)},entries:{evaluate:([e],t)=>(D(e,t),Object.entries(e)),arity:G(1)},find:{evaluate:([e,t],n)=>(D(e,n),H(t,n),ne(e,t)?[t,e[t]]:null),arity:G(2)},dissoc:{evaluate:([e,t],n)=>{D(e,n),H(t,n);const r={...e};return delete r[t],r},arity:G(2)},merge:{evaluate:(e,t)=>{if(0===e.length)return null;const[n,...r]=e;return D(n,t),r.reduce((e,n)=>(D(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 D(i,t),J(s,t),o.reduce((e,i)=>(D(i,t),Object.entries(i).forEach(i=>{const o=K(i[0],t),a=se(i[1]);ne(e,o)?e[o]=r(s,[e[o],a],n,t):e[o]=a}),e),{...i})},arity:{min:2}},zipmap:{evaluate:([e,t],n)=>{fe(e,n),le(t,n);const r=Math.min(e.length,t.length),i={};for(let s=0;s<r;s+=1){i[K(e[s],n)]=se(t[s])}return i},arity:G(2)},"select-keys":{evaluate:([e,t],n)=>(fe(t,n),D(e,n),t.reduce((t,n)=>(ne(e,n)&&(t[n]=se(e[n])),t),{})),arity:G(2)}},Me={"function?":{evaluate:([e])=>w(e),arity:G(1)},"string?":{evaluate:([e])=>"string"==typeof e,arity:G(1)},"number?":{evaluate:([e])=>"number"==typeof e,arity:G(1)},"integer?":{evaluate:([e])=>"number"==typeof e&&O(e,{integer:!0}),arity:G(1)},"boolean?":{evaluate:([e])=>"boolean"==typeof e,arity:G(1)},"null?":{evaluate:([e])=>null==e,arity:G(1)},"zero?":{evaluate:([e],t)=>(C(e,t,{finite:!0}),Math.abs(e)<ue),arity:G(1)},"pos?":{evaluate:([e],t)=>(C(e,t,{finite:!0}),e>0),arity:G(1)},"neg?":{evaluate:([e],t)=>(C(e,t,{finite:!0}),e<0),arity:G(1)},"even?":{evaluate:([e],t)=>(C(e,t,{finite:!0}),e%2==0),arity:G(1)},"odd?":{evaluate:([e],t)=>(C(e,t,{finite:!0}),O(e,{integer:!0})&&e%2!=0),arity:G(1)},"array?":{evaluate:([e])=>Array.isArray(e),arity:G(1)},"collection?":{evaluate:([e])=>R(e),arity:G(1)},"sequence?":{evaluate:([e])=>B(e),arity:G(1)},"object?":{evaluate:([e])=>M(e),arity:G(1)},"regexp?":{evaluate:([e])=>V(e),arity:G(1)},"finite?":{evaluate:([e],t)=>(C(e,t),Number.isFinite(e)),arity:G(1)},"positive-infinity?":{evaluate:([e],t)=>(C(e,t),e===Number.POSITIVE_INFINITY),arity:G(1)},"negative-infinity?":{evaluate:([e],t)=>(C(e,t),e===Number.NEGATIVE_INFINITY),arity:G(1)},"true?":{evaluate:([e])=>!0===e,arity:G(1)},"false?":{evaluate:([e])=>!1===e,arity:G(1)},"empty?":{evaluate:([e],t)=>null===e||(L(e,t),"string"==typeof e||Array.isArray(e)?0===e.length:0===Object.keys(e).length),arity:G(1)},"not-empty?":{evaluate:([e],t)=>null!==e&&(L(e,t),"string"==typeof e||Array.isArray(e)?e.length>0:Object.keys(e).length>0),arity:G(1)},"vector?":{evaluate:([e])=>Ee(e),arity:G(1)},"matrix?":{evaluate:([e])=>Ae(e),arity:G(1)},"grid?":{evaluate:([e])=>Ie(e),arity:G(1)}},De={regexp:{evaluate:([e,t],r)=>{H(e,r);const i=e||"(?:)",s="string"==typeof t?t:"";try{new RegExp(i,s)}catch(e){throw new n(`Invalid regular expression: ${i} ${s}`,r)}return{[f]:!0,sourceCodeInfo:r,s:i,f:s}},arity:{min:1,max:2}},match:{evaluate:([e,t],n)=>{if(function(e,t){if(!V(e))throw m("RegularExpression",e,t)}(t,n),!Z(e))return null;const r=new RegExp(t.s,t.f).exec(e);return r?[...r]:null},arity:G(2)},replace:{evaluate:([e,t,n],r)=>{H(e,r),z(t,r),H(n,r);const i=V(t)?new RegExp(t.s,`${t.f}`):t;return e.replace(i,n)},arity:G(3)},"replace-all":{evaluate:([e,t,n],r)=>{H(e,r),z(t,r),H(n,r);const i=V(t)?new RegExp(t.s,`${t.f.includes("g")?t.f:`${t.f}g`}`):t;return e.replaceAll(i,n)},arity:G(3)}},Re=/^\s*$/,_e={str:{evaluate:e=>e.reduce((e,t)=>e+(null==t?"":M(t)||Array.isArray(t)?JSON.stringify(t):`${t}`),""),arity:{}},number:{evaluate:([e],t)=>{H(e,t);const r=Number(e);if(Number.isNaN(r))throw new n(`Could not convert '${e}' to a number.`,t);return r},arity:G(1)},"lower-case":{evaluate:([e],t)=>(H(e,t),e.toLowerCase()),arity:G(1)},"upper-case":{evaluate:([e],t)=>(H(e,t),e.toUpperCase()),arity:G(1)},trim:{evaluate:([e],t)=>(H(e,t),e.trim()),arity:G(1)},join:{evaluate:([e,t],n)=>(le(e,n),e.forEach(e=>te(e,n)),H(t,n),e.join(t)),arity:G(2)},split:{evaluate:([e,t,n],r)=>{H(e,r),z(t,r),void 0!==n&&C(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||(H(e,t),Re.test(e)),arity:G(1)}},Le={"|>":{evaluate:([e,t],n,r,{executeFunction:i})=>(J(t,n),i(t,[e],r,n)),arity:G(2)},apply:{evaluate:([e,...t],n,r,{executeFunction:i})=>{J(e,n);const s=t[t.length-1];le(s,n);return i(e,[...t.slice(0,-1),...s],r,n)},arity:{min:2}},identity:{evaluate:([e])=>se(e),arity:G(1)},comp:{evaluate:(e,t)=>{return e.forEach(e=>J(e,t)),{[l]:!0,sourceCodeInfo:t,functionType:"Comp",params:e,arity:e.length>0?(n=e.at(-1),"number"==typeof n||R(n)?G(1):n.arity):{min:1,max:1}};var n},arity:{}},constantly:{evaluate:([e],t)=>({[l]:!0,sourceCodeInfo:t,functionType:"Constantly",value:se(e),arity:{}}),arity:G(1)}};function Ve(e){return ce(`\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(", ")})`} -> ${ze(r)}`),o=i?["","Operator:",` a ${e} b -> ${ze(r)}`]:[];return[...s,...o]}(e).join("\n ")}\n\n Arguments:\n ${function(e){return Object.entries(e.args).map(([e,t])=>`${e}: ${ze(t)}`)}(e).join("\n ")}\n\n Examples:\n${e.examples.map(e=>ce(e,4)).join("\n\n")}`)}function ze(e){const t=e.type,n=(Array.isArray(t)?t:[t]).join(" | ");return e.array||e.rest?`Array<${n}>`:n}const We={sum:{evaluate:([e],t)=>(Ne(e,t),e.reduce((e,t)=>e+t,0)),arity:G(1)},prod:{evaluate:([e],t)=>(Ne(e,t),e.reduce((e,t)=>e*t,1)),arity:G(1)},mean:{evaluate:([e],t)=>($e(e,t),e.reduce((e,t)=>e+t,0)/e.length),arity:G(1)},median:{evaluate:([e],t)=>($e(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:G(1)}},Je={...X,...pe,...de,...ge,...Ue,...function(e){return{doc:{evaluate:([t],n)=>{if(v(e),J(t,n),!w(t))return"";if("Builtin"===t.functionType){const n=e[t.name];return n?Ve(n):""}return"UserDefined"===t.functionType||"NativeJsFunction"===t.functionType?t.docString:""},arity:G(1)},arity:{evaluate:([e],t)=>(J(e,t),w(e)?e.arity:G(1)),arity:G(1)}}}({}),...Be,...Pe,...Me,...De,..._e,...Le,...We};Object.entries(Je).forEach(([e,t])=>{t.name=e});const qe={...Je},Ye={},Ge=[];Object.entries(qe).forEach(([e,t],n)=>{Ye[e]=n,Ge.push(t)});const Xe={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=U(r,t),!n)break;return n},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)};function Ze(e){const t=e[0];return o.UserDefinedSymbol===t||o.NormalBuiltinSymbol===t||o.SpecialBuiltinSymbol===t}function He(e){return o.UserDefinedSymbol===e[0]}function Ke(e,t){return function(e,t){if(!He(e))throw m("UserDefinedSymbolNode",e,t)}(e,t),e}function Qe(e){return o.NormalBuiltinSymbol===e[0]}function et(e){return o.SpecialBuiltinSymbol===e[0]}function tt(e){return!!function(e){return e[0]===o.NormalExpression}(e)&&Ze(e[1][0])}function nt(e){return e[0]===o.Spread}const rt={arity:G(1),evaluate:(e,t)=>{const n=e[1][1];if(function(e,t){if(!Ze(e))throw m("SymbolNode",e,t)}(n),!He(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 it=11,st=12,ot=13,at=14;function ut(e,t){if(e[0]===ot)Object.values(e[1][0]).forEach(e=>{e[1][1]&&t(e[1][1]),ut(e,t)});else if(e[0]===at)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]),ut(r,t))}}function ct(e,t,n){const r={};return lt(e,t,n,e[2],r),r}function lt(e,t,r,i,s){if(e[0]===ot){!function(e,t){if(!b(e))throw new n(`Expected UnknownRecord, got ${d(e)}.`,g(e,t))}(t,i);const o=new Set;let a;if(Object.entries(e[1][0]).forEach(([e,n])=>{if(n[0]===st)return void(a=n);o.add(e);const u=(void 0!==t[e]?t[e]:n[1][1]&&r(n[1][1]))??null;T(u,i),lt(n,u,r,i,s)}),a){const e=Object.entries(t).filter(([e])=>!o.has(e)).reduce((e,[t,n])=>(e[t]=U(n),e),{});s[a[1][0]]=e}}else if(e[0]===at){let n=null;le(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]===st){n=o;break}const u=(void 0!==t[o]?t[o]:a[1][1]&&r(a[1][1]))??null;T(u,i),lt(a,u,r,i,s)}if(null!==n){const r=t.slice(n),i=e[1][0][n];s[i[1][0]]=r}}else e[0]===st?s[e[1][0]]=U(t):s[e[1][0][1]]=U(t)}function ft(e){const t={};return ht(e,t),t}function ht(e,t){if(null!==e)if(e[0]===at)for(const n of e[1][0])ht(n,t);else if(e[0]===ot)for(const n of Object.values(e[1][0]))ht(n,t);else if(e[0]===st){if(t[e[1][0]])throw new n(`Duplicate binding name: ${e[1][0]}`,e[2]);t[e[1][0]]=!0}else{if(t[e[1][0][1]])throw new n(`Duplicate binding name: ${e[1][0]}`,e[2]);t[e[1][0][1]]=!0}}const pt={arity:{},evaluate:(e,t,{evaluateNode:n})=>{const r=e[1][1],i=r[1][0],s=r[1][1],o=n(s,t),a=ct(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 ut(o,e=>{ae(u,n([e],t,r,i))}),t.addValues(ft(o),o[2]),u}},dt={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(ft(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);F(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]!==st&&void 0===e[1][1]).length,c={min:u>0?u:void 0,max:a[0].some(e=>e[0]===st)?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,ft(e)),ut(e,e=>{ae(s,n([e],t,r,i))})});const a=t.create(o),u=n(e[1],a,r,i);return ae(s,u),s}(e[1][1],t,n,r,i)};const gt={arity:G(0),evaluate:(e,t,{evaluateNode:n})=>{const r=e[1][1],i=r[1][0],s=r[1][1],o=n(s,t),a=ct(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 ut(o,e=>{ae(u,n([e],t,r,i))}),t.addValues(ft(o),o[2]),u}},mt={arity:{},evaluate:(e,r,{evaluateNode:i})=>{const s=e[1][1],o=s.reduce((e,t)=>{const n=i(t[1][1],r.create(e)),s=ct(t[1][0],n,e=>i(e,r));return Object.entries(s).forEach(([t,n])=>{e[t]={value:n}}),e},{}),a=r.create(o),u=e[1][2];for(;;){let c=null;try{c=i(u,a)}catch(a){if(a instanceof t){const t=a.params;if(t.length!==s.length)throw new n(`recur expected ${s.length} parameters, got ${d(t.length)}`,e[2]);s.forEach((e,n)=>{const s=ct(e[1][0],U(t[n]),e=>i(e,r));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=ft(t[1][0]);return Object.keys(n).forEach(t=>{e[t]={value:!0}}),e},{});return oe(n(s.map(e=>e[1][1]),t,r,i),n([e[1][2]],t.create(o),r,i))}};function yt(e,t,n,r){for(const i of e){const[e,s]=i[1],o=ct(e,r(s,n),e=>r(e,n));Object.entries(o).forEach(([e,n])=>{t[e]={value:n}})}}function vt(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=_(r(d,l),i),m=B(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=ct(p,U(m[v],i),e=>r(e,l));if(Object.entries(b).forEach(([e,n])=>{t[e]={value:n}}),o&&yt(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 bt(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,ft(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,ft(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 wt={arity:G(1),evaluate:(e,t,n)=>vt(!0,e,t,n.evaluateNode),getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>bt(e,t,n,r,i)},St={arity:G(1),evaluate:(e,t,n)=>(vt(!1,e,t,n.evaluateNode),null),getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>bt(e,t,n,r,i)},kt={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=U(r,t),n)break;return n},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)},xt={arity:{min:1},evaluate:(e,t,{evaluateNode:n})=>{for(const r of e[1][1]){if(He(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=U(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)},Et={arity:{},evaluate:(e,n,{evaluateNode:r})=>{const i=e[1][1].map(e=>r(e,n));throw new t(i)},evaluateAsNormalExpression:e=>{throw new t(e)},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)},Nt={arity:G(1),evaluate:(e,t,{evaluateNode:n})=>{const i=K(n(e[1][1],t),e[2],{nonEmpty:!0});throw new r(i,e[2])},evaluateAsNormalExpression:(e,t)=>{const n=K(e[0],t,{nonEmpty:!0});throw new r(n,void 0)},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n([e[1][1]],t,r,i)},$t={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 oe(u,n([a],t.create(c),r,i))}},It={arity:{},evaluate:(e,t,{evaluateNode:r})=>{const i=[];for(const s of e[1][1])if(nt(s)){const e=r(s[1],t);if(!Array.isArray(e))throw new n("Spread value is not an array",s[2]);i.push(...e)}else i.push(r(s,t));return i},evaluateAsNormalExpression:(e,t)=>{const n=[];for(const r of e)n.push(U(r,t));return n},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)},At={arity:{},evaluate:(e,t,{evaluateNode:r})=>{const i={},s=e[1][1];for(let e=0;e<s.length;e+=2){const o=s[e];if(nt(o)){const s=r(o[1],t);if(!b(s))throw new n("Spread value is not an object",o[2]);Object.assign(i,s),e-=1}else{const a=r(o,t),u=s[e+1];if(void 0===u)throw new n("Missing value for key",o[2]);const c=r(u,t);H(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];H(i,t),n[i]=s??null}return n},getUndefinedSymbols:(e,t,{getUndefinedSymbols:n,builtin:r,evaluateNode:i})=>n(e[1][1],t,r,i)},jt={"??":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},Ot=[xt,Xe,kt,It,{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)},pt,rt,{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)},St,dt,wt,{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)},gt,mt,At,Et,{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)},Nt,$t,{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)}],Ct={normalExpressions:qe,specialExpressions:Ot,allNormalExpressions:Ge},Ft=Object.keys(qe),Ut=Object.keys(jt);new Set(Ut);const Tt=(e,t,n,r)=>{const i=Array.isArray(e)?e:[[o.SpecialExpression,[jt.block,e.body]]],s=new Set;for(const e of i)Bt(e,t,n,r)?.forEach(e=>s.add(e));return s};function Bt(e,t,r,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 n=e,s=new Set;if(tt(n)){const[,[e]]=n;if(He(e)){null===t.lookUp(e)&&s.add(e[1])}}else{const[,[e]]=n;Bt(e,t,r,i)?.forEach(e=>s.add(e))}for(const e of n[1][1])Bt(e,t,r,i)?.forEach(e=>s.add(e));return s}case o.SpecialExpression:{const n=e,s=n[1][0];return(0,r.specialExpressions[s].getUndefinedSymbols)(n,t,{getUndefinedSymbols:Tt,builtin:r,evaluateNode:i})}case o.Spread:return Bt(e[1],t,r,i);default:throw new n(`Unhandled node type: ${s}`,e[2])}}const Pt=(1+Math.sqrt(5))/2,Mt={E:Math.E,"-E":-Math.E,"ε":Math.E,"-ε":-Math.E,PI:Math.PI,"-PI":-Math.PI,"π":Math.PI,"-π":-Math.PI,PHI:Pt,"-PHI":-Pt,"φ":Pt,"-φ":-Pt,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},Dt={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,...Mt};const Rt={NativeJsFunction:(e,t,r)=>{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 n(`Native function threw: "${t}"`,r)}},UserDefined:(e,r,i,s,{evaluateNode:o})=>{for(;;){if(!q(e.arity,r.length))throw new n(`Expected ${e.arity} arguments, got ${r.length}.`,i);const a=e.evaluatedfunction,u=a[0],c=u.filter(e=>e[0]!==st).length,l=s.create(e.evaluatedfunction[2]),f={self:{value:e}},h=[];for(let e=0;e<r.length;e+=1)if(e<c){const t=se(r[e]),n=ct(u[e],t,e=>o(e,l.create(f)));Object.entries(n).forEach(([e,t])=>{f[e]={value:t}})}else h.push(se(r[e]));for(let e=r.length;e<c;e++){const t=u[e],n=ct(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]===st);if(void 0!==p){const e=ct(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 t){r=e.params;continue}throw e}}},Partial:(e,t,r,i,{executeFunction:s})=>{const o=[...e.params];if(t.length!==e.placeholders.length)throw new n(`(partial) expects ${e.placeholders.length} arguments, got ${t.length}.`,r);const a=[...t];for(const t of e.placeholders)o.splice(t,0,a.shift());return s(e.function,o,i,r)},Comp:(e,t,r,i,{executeFunction:s})=>{const{params:o}=e;if(0===o.length){if(1!==t.length)throw new n(`(comp) expects one argument, got ${d(t.length)}.`,r);return U(t[0],r)}return U(o.reduceRight((e,t)=>[s(W(t,r),e,i,r)],t)[0],r)},Constantly:e=>e.value,Juxt:(e,t,n,r,{executeFunction:i})=>e.params.map(e=>i(W(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(W(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(W(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(W(e.function,n),s,r,n)},Builtin:(e,t,n,r,{executeFunction:i})=>y(Ge[e.normalBuiltinSymbolType],n).evaluate(t,n,r,{executeFunction:i}),SpecialBuiltin:(e,t,r,i,{executeFunction:s})=>{const o=y(Ot[e.specialBuiltinSymbolType],r);if(o.evaluateAsNormalExpression)return o.evaluateAsNormalExpression(t,r,i,{executeFunction:s});throw new n(`Special builtin function ${e.specialBuiltinSymbolType} is not supported as normal expression.`,r)},Module:(e,t,r,i,{executeFunction:s})=>{const o=i.getModule(e.moduleName);if(!o)throw new n(`Module '${e.moduleName}' not found.`,r);const a=o.functions[e.functionName];if(!a)throw new n(`Function '${e.functionName}' not found in module '${e.moduleName}'.`,r);return Y(a.arity,t.length,r),a.evaluate(t,r,i,{executeFunction:s})}};function _t(e,t){let n=null;for(const r of e.body)n=Lt(r,t);return n}function Lt(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 n(`Reserved symbol ${t} cannot be evaluated`,e[2]);return y(Dt[t],e[2])}(e);case o.NormalExpression:{const r=function(e,t){const r=e[2],s=e[1][1],a=[],u=[];if(s.forEach((e,r)=>{if(nt(e)){const r=Lt(e[1],t);if(!Array.isArray(r))throw new n(`Spread operator requires an array, got ${d(e)}`,e[2]);a.push(...r)}else e[0]===o.ReservedSymbol&&"_"===e[1]?u.push(r):a.push(Lt(e,t))}),tt(e)){const n=e[1][0];if(u.length>0){const e=Lt(n,t);return{[l]:!0,function:W(e,r),functionType:"Partial",params:a,placeholders:u,sourceCodeInfo:r,arity:G(u.length)}}if(Qe(n)){const r=n[1];return Ct.allNormalExpressions[r].evaluate(a,e[2],t,{executeFunction:Vt})}{const s=t.getValue(n[1]);if(void 0!==s)return Vt(W(s,r),a,t,r);throw new i(n[1],e[2])}}{const n=W(Lt(e[1][0],t),r);if(u.length>0){return{[l]:!0,function:n,functionType:"Partial",params:a,placeholders:u,sourceCodeInfo:r,arity:G(u.length)}}return Vt(n,a,t,r)}}(e,t);if("number"==typeof r&&Number.isNaN(r))throw new n("Number is NaN",e[2]);return xe(r)}case o.SpecialExpression:return xe(function(e,t){const n=e[1][0],r=y(Ct.specialExpressions[n],e[2]);return(0,r.evaluate)(e,t,{evaluateNode:Lt,builtin:Ct,getUndefinedSymbols:Tt})}(e,t));default:throw new n(`${u(e[0])}-node cannot be evaluated`,e[2])}}function Vt(e,t,r,i){if(w(e))return Rt[e.functionType](e,t,i,r,{evaluateNode:Lt,executeFunction:Vt});if(Array.isArray(e))return function(e,t,r){if(1!==t.length)throw new n("Array as function requires one non negative integer parameter.",r);const i=t[0];return C(i,r,{integer:!0,nonNegative:!0}),se(e[i])}(e,t,i);if(M(e))return function(e,t,r){if(1!==t.length)throw new n("Object as function requires one string parameter.",r);const i=t[0];return H(i,r),se(e[i])}(e,t,i);if("string"==typeof e)return function(e,t,r){if(1!==t.length)throw new n("String as function requires one Obj parameter.",r);const i=se(t[0]);if(M(i))return se(i[e]);if(O(i,{integer:!0}))return se(e[i]);throw new n(`string as function expects Obj or integer parameter, got ${d(i)}`,r)}(e,t,i);if(O(e))return function(e,t,r){if(C(e,r,{integer:!0}),1!==t.length)throw new n("Number as function requires one Arr parameter.",r);const i=t[0];return P(i,r),se(i[e])}(e,t,i);throw new n("Unexpected function type",i)}class zt{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 zt({contexts:[e,...this.contexts],values:this.values,nativeJsFunctions:this.nativeJsFunctions,modules:this.modules});return n.globalContext=t,n}new(e){return new zt({contexts:[{},e],modules:this.modules})}exportValues(e,t){for(const[r,i]of Object.entries(e)){if(this.globalContext[r])throw new n(`Cannot redefine exported value "${r}"`,t);const e=Wt(r);if(e)throw new n(`Cannot shadow ${e}`,t);this.globalContext[r]={value:i}}this.contexts[0]!==this.globalContext&&this.addValues(e,t)}addValues(e,t){const r=this.contexts[0];for(const[i,s]of Object.entries(e)){if(r[i])throw new n(`Cannot redefine value "${i}"`,t);const e=Wt(i);if(e)throw new n(`Cannot shadow ${e}`,t);r[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(et(e)){const t=e[1];switch(t){case jt["&&"]:case jt["||"]:case jt.array:case jt.object:case jt["defined?"]:case jt.recur:case jt.throw:case jt["??"]:{const n=y(Ct.specialExpressions[t],e[2]);return{[l]:!0,functionType:"SpecialBuiltin",specialBuiltinSymbolType:t,sourceCodeInfo:e[2],arity:n.arity}}default:throw new n(`Unknown special builtin symbol type: ${t}`,e[2])}}if(Qe(e)){const t=e[1],n=Ge[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(r=t)&&void 0!==r.value)return t.value;var r;throw new i(e[1],e[2])}}function Wt(e){return Ut.includes(e)?`special expression "${e}"`:Ft.includes(e)?`builtin function "${e}"`:"self"===e?`builtin value "${e}"`:null}function Jt(e={},t){const r=e.globalContext??{},i=e.contexts?[r,...e.contexts]:[r],s=new zt({contexts:i,values:e.values,modules:t,nativeJsFunctions:e.jsFunctions&&Object.entries(e.jsFunctions).reduce((e,[t,r])=>{const i=t.split("."),s=i.pop();if(/^[A-Z]/.test(s))throw new n(`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 n(`Invalid empty identifier "${t}" in jsFunctions`,void 0);if(!/^[A-Z]/.test(e))throw new n(`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")}(r);const a={functionType:"NativeJsFunction",nativeFn:r,name:s,[l]:!0,arity:r.arity??{},docString:r.docString??""};return o===e&&function(e){const t=Wt(e);if(t)throw new n(`Cannot shadow ${t}`,void 0)}(s),o[s]=a,e},{})});return e.globalModuleScope?s:s.create({})}const qt=["^","*","/","%","+","-","<<",">>",">>>","++","<","<=","≤",">",">=","≥","==","!=","≠","&","xor","|","&&","||","??","|>"],Yt=[...qt,"?",":","->","...",".",",","=",":",";"],Gt=new Set(["comment","cond","def","defined?","block","doseq","if","let","loop","recur","throw","try","unless","while"]);function Xt(e){return!Gt.has(e)}const Zt=new Set(qt);function Ht(e){return Zt.has(e)}const Kt=new Set(Yt);function Qt(e){return Kt.has(e)}const en=["(",")","[","]","{","}","'",'"',"`",",",".",";"," ","\n","\r","\t"],tn=["0","1","2","3","4","5","6","7","8","9",...en],nn=new Set(en),rn=new Set(tn),sn=/\s/,on=[0],an=(e,t)=>{if('"'!==e[t])return on;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 un(e,t,n,r){return t===n.slice(r,r+t.length)?[t.length,[e,t]]:on}const cn=/\d/,ln=/[0-7]/,fn=/[0-9a-f]/i,hn=/[01]/,pn=/[\s)\]}(,;]/,dn=(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(!rn.has(n)){const r=t;let i=e[t+=1];for(;i&&!nn.has(i);)n+=i,i=e[t+=1];return n.endsWith(":")?[t-r-1,["Symbol",n.slice(0,-1)]]:[t-r,["Symbol",n]]}return on},gn=[(e,t)=>{let n=e[t];if(!n||!sn.test(n))return on;let r=n;for(n=e[t+=1];n&&sn.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 on},(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 on},(e,t)=>{const n=dn(e,t);if(0===n[0]||!n[1])return on;let r=n[1][1];r=r.startsWith("'")?r.slice(1,r.length-1):r;return void 0===Dt[r]?on:[n[0],["ReservedSymbol",r]]},(e,t)=>un("LParen","(",e,t),(e,t)=>un("RParen",")",e,t),(e,t)=>un("LBracket","[",e,t),(e,t)=>un("RBracket","]",e,t),(e,t)=>un("LBrace","{",e,t),(e,t)=>un("RBrace","}",e,t),(e,t)=>{if('"'!==e[t]||'"'!==e[t+1]||'"'!==e[t+2])return on;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}`]]},an,(e,t)=>{if("#"!==e[t])return on;const[n,r]=an(e,t+1);if(!r)return on;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 on;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 on;let i;for(i=t+2;i<e.length;i+=1){const t=e[i];if("binary"===r&&!hn.test(t))break;if("octal"===r&&!ln.test(t))break;if("hex"===r&&!fn.test(t))break}const s=i-t;if(s<=2)return on;const o=e[i];return o&&!pn.test(o)?on:[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(!cn.test(e[n-1])||!cn.test(e[n+1]))return n===s?on:[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 on;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 on;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(!cn.test(r))break}if((r||i)&&n===s)return on;const u=n-t;if(0===u)return on;const c=e[n];return c&&":"!==c&&!pn.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&&Qt(n))return[3,["Operator",n]];const r=e.slice(t,t+2);if(t+1<e.length&&Qt(r))return[2,["Operator",r]];const i=e[t]??"";return Qt(i)?[1,["Operator",i]]:on},dn];function mn(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 yn(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 on})(e,t);if(t+=r,r>0)return[t-n,i]}for(const r of gn){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 vn(e,t){return"Symbol"===e?.[0]&&(!t||e[1]===t)}function bn(e,t){return function(e,t){vn(e,t)||Dn("Symbol",void 0,e)}(e,t),e}function wn(e,t){return"ReservedSymbol"===e?.[0]&&(!t||e[1]===t)}function Sn(e,t){wn(e,t)||Dn("ReservedSymbol",t,e)}function kn(e,t){return Sn(e,t),e}function xn(e,t){return"Operator"===e?.[0]&&(!t||e[1]===t)}function En(e,t){xn(e,t)||Dn("Operator",t,e)}function Nn(e){return"LParen"===e?.[0]}function $n(e){Nn(e)||Dn("LParen",void 0,e)}function In(e){return"RParen"===e?.[0]}function An(e){In(e)||Dn("RParen",void 0,e)}function jn(e){return"LBracket"===e?.[0]}function On(e){return function(e){jn(e)||Dn("LBracket",void 0,e)}(e),e}function Cn(e){return"RBracket"===e?.[0]}function Fn(e){Cn(e)||Dn("RBracket",void 0,e)}function Un(e){return"LBrace"===e?.[0]}function Tn(e){return function(e){Un(e)||Dn("LBrace",void 0,e)}(e),e}function Bn(e){return"RBrace"===e?.[0]}function Pn(e){return"string"===e?.[0]}function Mn(e){return"Operator"===e?.[0]&&Ht(e[1])}function Dn(e,t,r){const i=r?`${r[0]} '${r[1]}'`:"end of input";throw new n(`Unexpected token: ${i}, expected ${e}${t?` '${t}'`:""}`,r?.[2])}function Rn(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 _n=Object.entries(Ye).reduce((e,[t,n])=>(e[n]=t,e),[]),Ln=Object.entries(jt).reduce((e,[t,n])=>(e[n]=t,e),[]);function Vn(e){return He(e)?e[1]:Qe(e)?_n[e[1]]:Ln[e[1]]}const zn=/^\$([1-9]\d?)?$/;function Wn(e,t){return t&&(e[2]=t),e}function Jn(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 n(`Unknown binary operator: ${e}`,t)}}function qn(e,t,n){const r=Wn([o.NormalExpression,[e,t]],n);return Qe(e)&&Y(Ge[e[1]].arity,r[1][1].length,n),r}function Yn(e,t,n){return Wn([o.NormalExpression,[[o.NormalBuiltinSymbol,Ye.get],[e,t]]],n)}function Gn(e,t,r,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 qn(t,[r,i],s);case"&&":case"||":case"??":return Wn([o.SpecialExpression,[jt[a],[r,i]]],s);default:throw new n(`Unknown binary operator: ${a}`,s)}}class Xn{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 n(e[3],e[2])});const e=[];for(;!this.isAtEnd();)if(e.push(this.parseExpression(0,!0)),xn(this.peek(),";"))this.advance();else if(!this.isAtEnd())throw new n("Expected ;",this.peekSourceCodeInfo());return e}parseExpression(e=0,t=!1){const r=this.peek();let i;if(vn(r))switch(r[1]){case"let":return this.parseLet(r);case"if":case"unless":i=this.parseIfOrUnless(r);break;case"cond":i=this.parseCond(r);break;case"switch":i=this.parseSwitch(r);break;case"for":case"doseq":i=this.parseForOrDoseq(r);break;case"loop":i=this.parseLoop(r);break;case"try":i=this.parseTry(r)}else if(wn(r,"do"))i=this.parseBlock()[0];else if(wn(r,"export")){if(!t)throw new n("export is only allowed in module scope",r[2]);return this.parseExport(r)}i||=this.parseOperand();let s=this.peek();for(;!this.isAtExpressionEnd();){if(Mn(s)){const t=s[1],n=Jn(t,s[2]);if(n<=e&&(12!==n||12!==e))break;const r=Wn(jt[t]?[o.SpecialBuiltinSymbol,jt[t]]:[o.NormalBuiltinSymbol,Ye[t]],s[2]);this.advance();i=Gn(s,r,i,this.parseExpression(n),s[2])}else if(vn(s)){if(!Xt(s[1]))break;const t=3;if(t<=e)break;const r=this.parseSymbol(),o=this.parseExpression(t);if(et(r))throw new n("Special expressions are not allowed in binary functional operators",r[2]);i=qn(r,[i,o],s[2])}else{if("?"!==s?.[1])break;{if(1<=e)break;this.advance();const t=this.parseExpression();if(!xn(this.peek(),":"))throw new n("Expected :",this.peekSourceCodeInfo());this.advance();const r=this.parseExpression();i=Wn([o.SpecialExpression,[jt.if,[i,t,r]]],i[2])}}s=this.peek()}return i}asToken(e){if(!e)throw new n("Unexpected end of input",this.peekSourceCodeInfo());return e}parseOperand(){let e=this.parseOperandPart(),t=this.peek();for(;xn(t,".")||jn(t)||Nn(t);)if("."===t[1]){this.advance();const r=this.asToken(this.peek());if(!vn(r))throw new n("Expected symbol",this.peekSourceCodeInfo());e=Yn(e,Wn([o.String,r[1]],r[2]),t[2]),this.advance(),t=this.peek()}else if(jn(t)){this.advance();const r=this.parseExpression();if(!Cn(this.peek()))throw new n("Expected closing bracket",this.peekSourceCodeInfo());e=Yn(e,r,t[2]),this.advance(),t=this.peek()}else Nn(t)&&(e=this.parseFunctionCall(e),t=this.peek());return e}parseOperandPart(){const e=this.asToken(this.peek());if(Nn(e)){const e=this.parseState.position,t=this.parseLambdaFunction();if(t)return t;this.parseState.position=e,this.advance();const r=this.parseExpression();if(!In(this.peek()))throw new n("Expected closing parenthesis",this.peekSourceCodeInfo());return this.advance(),r}if(xn(e)){const t=e[1];if(Ht(t))return this.advance(),Wn(void 0!==jt[t]?[o.SpecialBuiltinSymbol,jt[t]]:[o.NormalBuiltinSymbol,Ye[t]],e[2]);if("->"===t)return this.parseShorthandLambdaFunction();throw new n(`Illegal operator: ${t}`,e[2])}if(Un(e))return this.parseObject();if(jn(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 n(`Unknown token type: ${t}`,e[2])}}parseObject(){const e=Tn(this.peek());this.advance();const t=[];for(;!this.isAtEnd()&&!Bn(this.peek());){if(xn(this.peek(),"..."))this.advance(),t.push(Wn([o.Spread,this.parseExpression()],this.peekSourceCodeInfo()));else{const e=this.peek();if(Pn(e)){const n=this.parseString(e);t.push(Wn([o.String,n[1]],e[2]))}else if(vn(e)){const n=e[1].startsWith("'")?this.stringFromQuotedSymbol(e[1]):e[1];t.push(Wn([o.String,n],e[2])),this.advance()}else{if(!jn(e))throw new n("Expected key to be a symbol or a string",this.peekSourceCodeInfo());this.advance(),t.push(this.parseExpression()),Fn(this.peek()),this.advance()}En(this.peek(),":"),this.advance(),t.push(this.parseExpression())}const e=this.peek();if(!xn(e,",")&&!Bn(e))throw new n("Expected comma or closing brace",this.peekSourceCodeInfo());xn(e,",")&&this.advance()}var r;return Bn(r=this.peek())||Dn("RBrace",void 0,r),this.advance(),Wn([o.SpecialExpression,[jt.object,t]],e[2])}parseArray(){const e=On(this.peek());this.advance();const t=[];for(;!this.isAtEnd()&&!Cn(this.peek());){xn(this.peek(),"...")?(this.advance(),t.push(Wn([o.Spread,this.parseExpression()],this.peekSourceCodeInfo()))):t.push(this.parseExpression());const e=this.peek();if(!xn(e,",")&&!Cn(e))throw new n("Expected comma or closing parenthesis",this.peekSourceCodeInfo());xn(e,",")&&this.advance()}return Fn(this.peek()),this.advance(),Wn([o.SpecialExpression,[jt.array,t]],e[2])}parseFunctionCall(e){this.advance();const t=[];for(;!this.isAtEnd()&&!In(this.peek());){xn(this.peek(),"...")?(this.advance(),t.push(Wn([o.Spread,this.parseExpression()],this.peekSourceCodeInfo()))):t.push(this.parseExpression());const e=this.peek();if(!xn(e,",")&&!In(e))throw new n("Expected comma or closing parenthesis",this.peek()?.[2]);xn(e,",")&&this.advance()}if(!In(this.peek()))throw new n("Expected closing parenthesis",this.peekSourceCodeInfo());if(this.advance(),!et(e))return Qe(e)||He(e)?qn(e,t,e[2]):Wn([o.NormalExpression,[e,t]],e[2]);{const r=e[1];switch(Y(Ct.specialExpressions[r].arity,t.length,e[2]),r){case jt["||"]:case jt["&&"]:case jt.recur:case jt.array:case jt.object:case jt["??"]:return Wn([o.SpecialExpression,[r,t]],e[2]);case jt["defined?"]:{const[n]=t;return Wn([o.SpecialExpression,[r,n]],e[2])}case jt.throw:{const[n]=t;return Wn([o.SpecialExpression,[r,n]],e[2])}case jt["0_lambda"]:case jt["0_def"]:throw new n(`${r} is not allowed`,e[2]);default:throw new n(`Unknown special expression: ${r}`,e[2])}}}parseLambdaFunction(){const e=this.asToken(this.peek());if(Nn(e)&&vn(this.peekAhead(1))&&xn(this.peekAhead(2),"->"))return null;try{const t=this.parseFunctionArguments();if(!xn(this.peek(),"->"))return null;let n;this.advance();let r="";if(wn(this.peek(),"do")){const e=this.parseBlock(!0);r=e[1],n=e[0][1][1]}else n=[this.parseExpression()];return Wn([o.SpecialExpression,[jt["0_lambda"],[t,n],r]],e[2])}catch{return null}}parseFunctionArguments(){const e=this.peek();if(vn(e))return[Wn([it,[this.parseSymbol(),void 0]],e[2])];$n(e),this.advance();let t=!1,r=!1;const i=[];for(;!this.isAtEnd()&&!In(this.peek())&&!vn(this.peek(),"let");){if(t)throw new n("Rest argument must be last",this.peekSourceCodeInfo());const e=this.parseBindingTarget();if(void 0!==e[1][1]&&(r=!0),e[0]===st&&(t=!0),r&&!e[1][1])throw new n("Default arguments must be last",this.peekSourceCodeInfo());if(i.push(e),!xn(this.peek(),",")&&!In(this.peek())&&!vn(this.peek(),"let"))throw new n("Expected comma or closing parenthesis",this.peekSourceCodeInfo());xn(this.peek(),",")&&this.advance()}if(!In(this.peek()))throw new n("Expected closing parenthesis",this.peekSourceCodeInfo());return this.advance(),i}parseShorthandLambdaFunction(){const e=this.asToken(this.peek());this.advance();const t=this.parseState.position;let r,i="";if(wn(this.peek(),"do")){const e=this.parseBlock(!0);i=e[1],r=e[0][1][1]}else r=[this.parseExpression()];const s=this.parseState.position-1;let a=0,u="NOT_SET";for(let r=t;r<=s;r+=1){const t=this.tokenStream.tokens[r];if(vn(t)){const r=zn.exec(t[1]);if(r){const t=r[1]??"1";if("1"===t){if(!r[1]&&"WITH_1"===u||r[1]&&"NAKED"===u)throw new n("Please make up your mind, either use $ or $1",e[2]);u=r[1]?"WITH_1":"NAKED"}if(a=Math.max(a,Number(t)),a>20)throw new n("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(Wn([it,[[o.UserDefinedSymbol,"$"],void 0]],e[2])):c.push(Wn([it,[[o.UserDefinedSymbol,`$${t}`],void 0]],e[2]));return Wn([o.SpecialExpression,[jt["0_lambda"],[c,r],i]],e[2])}parseOptionalDefaulValue(){if(xn(this.peek(),"="))return this.advance(),this.parseExpression()}parseBindingTarget({requireDefaultValue:e,noRest:t}={}){const r=this.peek();if(vn(r)){const t=this.parseSymbol();if(!He(t))throw new n("Expected user defined symbol",r[2]);const i=this.parseOptionalDefaulValue();if(e&&!i)throw new n("Expected assignment",this.peekSourceCodeInfo());return Wn([it,[t,i]],r[2])}if(xn(r,"...")){if(t)throw new n("Rest element not allowed",r[2]);this.advance();const e=Ke(this.parseSymbol());if(xn(this.peek(),"="))throw new n("Rest argument can not have default value",this.peekSourceCodeInfo());return Wn([st,[e[1],void 0]],r[2])}if(jn(r)){this.advance();const t=[];let i=this.asToken(this.peek()),s=!1;for(;!Cn(i);){if(s)throw new n("Rest argument must be last",i[2]);if(xn(i,",")){t.push(null),this.advance(),i=this.asToken(this.peek());continue}const e=this.parseBindingTarget();e[0]===st&&(s=!0),t.push(e),i=this.asToken(this.peek()),Cn(i)||(En(i,","),this.advance()),i=this.asToken(this.peek())}this.advance();const o=this.parseOptionalDefaulValue();if(e&&!o)throw new n("Expected assignment",this.peekSourceCodeInfo());return Wn([at,[t,o]],r[2])}if(Un(r)){this.advance();const t={};let i=this.asToken(this.peek()),s=!1;for(;!Bn(i);){if(s)throw new n("Rest argument must be last",i[2]);xn(i,"...")&&(s=!0,this.advance());const e=this.parseSymbol(),o=Vn(e);if(i=this.asToken(this.peek()),wn(i,"as")){if(s)throw new n("Rest argument can not have alias",i[2]);this.advance();const e=Ke(this.parseSymbol());if(t[e[1]])throw new n(`Duplicate binding name: ${e}`,i[2]);t[o]=Wn([it,[e,this.parseOptionalDefaulValue()]],r[2])}else if(Bn(i)||xn(i,",")||xn(i,"=")){const o=Ke(e,e[2]);if(t[o[1]])throw new n(`Duplicate binding name: ${o}`,i[2]);if(s&&xn(this.peek(),"="))throw new n("Rest argument can not have default value",this.peekSourceCodeInfo());t[o[1]]=Wn(s?[st,[o[1],this.parseOptionalDefaulValue()]]:[it,[o,this.parseOptionalDefaulValue()]],r[2])}else if(xn(i,":")){if(this.advance(),i=this.asToken(this.peek()),!Un(i)&&!jn(i))throw new n("Expected object or array",i[2]);t[o]=this.parseBindingTarget()}Bn(this.peek())||(En(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 n("Expected assignment",i[2]);return Wn([ot,[t,o]],r[2])}throw new n("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=Wn([o.Binding,[t,n]],e[2]);return Wn([o.SpecialExpression,[jt.let,r]],e[2])}parseBlock(e=!1){const t=kn(this.peek(),"do");this.advance();let r="";e&&function(e){return"DocString"===e?.[0]}(this.peek())&&(r=this.parseDocString());const i=[];for(;!this.isAtEnd()&&!wn(this.peek(),"end");)if(i.push(this.parseExpression()),xn(this.peek(),";"))this.advance();else if(!wn(this.peek(),"end"))throw new n("Expected end",this.peekSourceCodeInfo());return Sn(this.peek(),"end"),this.advance(),[Wn([o.SpecialExpression,[jt.block,i]],t[2]),r]}parseImplicitBlock(e){const t=[];for(;!this.isAtEnd()&&!this.isImplicitBlockEnd(e);)xn(this.peek(),";")?this.advance():t.push(this.parseExpression());if(this.assertImplicitBlockEnd(e),0===t.length)throw new n("Expected expression",this.peekSourceCodeInfo());return 1===t.length?t[0]:Wn([o.SpecialExpression,[jt.block,t]],this.peekSourceCodeInfo())}assertImplicitBlockEnd(e){if(!this.isImplicitBlockEnd(e))throw new n(`Expected ${e.map(e=>e[1]).join(" or ")}`,this.peekSourceCodeInfo())}isImplicitBlockEnd(e){for(const t of e)if(wn(this.peek(),t))return!0;return!1}parseLoop(e){this.advance(),$n(this.peek()),this.advance();const t=[];let r=this.peek();for(;!this.isAtEnd()&&!In(r);){const e=this.parseBindingTarget({requireDefaultValue:!0,noRest:!0}),n=e[1][1];e[1][1]=void 0,t.push(Wn([o.Binding,[e,n]],e[2])),xn(this.peek(),",")&&this.advance(),r=this.peek()}if(0===t.length)throw new n("Expected binding",this.peekSourceCodeInfo());An(r),this.advance(),En(this.peek(),"->"),this.advance();const i=this.parseExpression();return Wn([o.SpecialExpression,[jt.loop,t,i]],e[2])}parseTry(e){this.advance();const t=this.parseImplicitBlock(["catch"]);let n;this.advance(),Nn(this.peek())&&(this.advance(),n=this.parseSymbol(),An(this.peek()),this.advance());const r=this.parseImplicitBlock(["end"]);return this.advance(),Wn([o.SpecialExpression,[jt.try,t,n,r]],e[2])}parseForOrDoseq(e){const t="doseq"===e[1];this.advance(),$n(this.peek()),this.advance();const r=[];for(;!this.isAtEnd()&&!In(this.peek());){const e=this.parseForLoopBinding(),t=r.flatMap(e=>Object.keys(ft(e[0][1][0]))),i=ft(e[0][1][0]);if(Object.keys(i).some(e=>t.includes(e)))throw new n("Duplicate binding",e[0][2]);r.push(e),xn(this.peek(),",")&&this.advance()}An(this.peek()),this.advance(),En(this.peek(),"->"),this.advance();const i=this.parseExpression();return Wn(t?[o.SpecialExpression,[jt.doseq,r,i]]:[o.SpecialExpression,[jt.for,r,i]],e[2])}parseForLoopBinding(){const e=this.parseBinding(),t=[];let r=this.asToken(this.peek());this.assertInternalLoopBindingDelimiter(r,["let","when","while"]);const i=[];if("let"===r[1])for(t.push("&let");vn(r,"let");){const e=this.parseLet(r),t=i.flatMap(e=>Object.keys(ft(e[1][0])));if(Object.keys(ft(e[1][1][1][0])).some(e=>t.includes(e)))throw new n("Duplicate binding",e[1][1][2]);i.push(e[1][1]),r=this.asToken(this.peek()),this.assertInternalLoopBindingDelimiter(r,["let","when","while"]),r=this.asToken(this.peek())}let s,o;for(;wn(r,"when")||wn(r,"while");){this.advance(),"when"===r[1]?(t.push("&when"),s=this.parseExpression()):(t.push("&while"),o=this.parseExpression()),r=this.asToken(this.peek());const e=t.includes("&when")&&t.includes("&while")?[]:t.includes("&when")?["while"]:["when"];this.assertInternalLoopBindingDelimiter(r,e),r=this.asToken(this.peek())}return this.assertInternalLoopBindingDelimiter(r,[]),[e,i,s,o]}assertInternalLoopBindingDelimiter(e,t){if(!this.isInternalLoopBindingDelimiter(e,t)){const r=`${[...t,","].map(e=>`"${e}"`).join(", ")} or ")"`;throw new n(`Expected symbol ${r}`,e[2])}}isInternalLoopBindingDelimiter(e,t){if(xn(e,",")||In(e))return!0;for(const n of t){if("let"===n&&vn(e,"let"))return!0;if(["when","while"].includes(n)&&wn(e,n))return!0}return!1}parseBinding(){const e=bn(this.peek()),t=Ke(this.parseSymbol());Sn(this.peek(),"in"),this.advance();const n=this.parseExpression();return Wn([o.Binding,[Wn([it,[t,void 0]],e[2]),n]],e[2])}parseIfOrUnless(e){const t="unless"===e[1];this.advance();const n=this.parseExpression();Sn(this.peek(),"then"),this.advance();const r=this.parseImplicitBlock(["else","end"]);let i;return wn(this.peek(),"else")&&(this.advance(),i=this.parseImplicitBlock(["end"])),this.advance(),Wn(t?[o.SpecialExpression,[jt.unless,[n,r,i]]]:[o.SpecialExpression,[jt.if,[n,r,i]]],e[2])}parseCond(e){this.advance();const t=[];for(;!this.isAtEnd()&&!wn(this.peek(),"end");){Sn(this.peek(),"case"),this.advance();const e=this.parseExpression();Sn(this.peek(),"then"),this.advance();const n=this.parseImplicitBlock(["case","end"]);if(t.push([e,n]),wn(this.peek(),"end"))break}return Sn(this.peek()),this.advance(),Wn([o.SpecialExpression,[jt.cond,t]],e[2])}parseSwitch(e){this.advance();const t=this.parseExpression(),n=[];for(;!this.isAtEnd()&&!wn(this.peek(),"end");){Sn(this.peek(),"case"),this.advance();const e=this.parseExpression();Sn(this.peek(),"then"),this.advance();const t=this.parseImplicitBlock(["case","end"]);if(n.push([e,t]),wn(this.peek(),"end"))break}return Sn(this.peek(),"end"),this.advance(),Wn([o.SpecialExpression,[jt.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 xn(e)?[";",",",":"].includes(e[1]):!!wn(e)&&["else","when","while","case","catch","let","then","end","do"].includes(e[1])}parseExport(e){this.advance();const t=this.peek();if(vn(t,"let")){const n=this.parseLet(bn(t));return Wn([o.SpecialExpression,[jt["0_def"],n[1][1]]],e[2])}throw new n("Expected let",this.peekSourceCodeInfo())}stringToSymbolNode(e,t){return void 0!==jt[e]&&"fn"!==e&&"def"!==e&&"defn"!==e?Wn([o.SpecialBuiltinSymbol,jt[e]],t):void 0!==Ye[e]?Wn([o.NormalBuiltinSymbol,Ye[e]],t):Wn([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(),!vn(e))throw new n(`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=kn(this.peek());this.advance();const t=e[1];return function(e){return e in Mt}(t)?Wn([o.Number,Mt[t]],e[2]):Wn([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 Wn([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 ce(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 Wn([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=Wn([o.String,n],e[2]),s=Wn([o.String,r],e[2]);return Wn([o.NormalExpression,[Wn([o.NormalBuiltinSymbol,Ye.regexp],e[2]),[i,s]]],e[2])}}const Zn=new Set([...Ft,...Ut,...Object.keys(Dt)]);class Hn{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 Zn.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 Kn{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}}class Qn{astCache;astCacheSize;debug;modules;constructor(e={}){if(this.debug=e.debug??!1,this.astCacheSize=e.astCacheSize??null,this.astCacheSize){this.astCache=new Kn(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=Jt(t,this.modules);return _t(n,r),r.globalContext}getUndefinedSymbols(e,t={}){const n="string"==typeof e?this.generateAst(e,t):e,r=Jt(t,this.modules);return Tt(n,r,Ct,Lt)}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?mn(e,r,n):void 0,o=yn(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?Rn(n,{removeWhiteSpace:!1}):n}parse(e){const t={body:[],hasDebugData:(e=Rn(e,{removeWhiteSpace:!0})).hasDebugData};return t.body=new Xn(e,{position:0}).parse(),t}evaluate(e,t){return _t(e,Jt(t,this.modules))}transformSymbols(e,t){return function(e,t){return{...e,tokens:e.tokens.map(e=>vn(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 Hn(e,t,this,n)}}export{Qn as Lits,S as asLitsFunction,I as asNativeJsFunction,E as asUserDefinedFunction,k as assertLitsFunction,A as assertNativeJsFunction,N as assertUserDefinedFunction,j as isBuiltinFunction,Ie as isGrid,s as isLitsError,w as isLitsFunction,Ae as isMatrix,$ as isNativeJsFunction,x as isUserDefinedFunction,Ee as isVector,Ft as normalExpressionKeys,Ut as specialExpressionKeys};
2
2
  //# sourceMappingURL=index.esm.js.map