@mojir/lits 2.0.15 → 2.0.17

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 (112) hide show
  1. package/dist/cli/cli.js +1008 -1516
  2. package/dist/cli/reference/api.d.ts +5 -5
  3. package/dist/cli/src/analyze/index.d.ts +0 -2
  4. package/dist/cli/src/builtin/index.d.ts +3 -10
  5. package/dist/cli/src/builtin/specialExpressions/declared.d.ts +1 -1
  6. package/dist/cli/src/builtin/specialExpressions/functions.d.ts +0 -5
  7. package/dist/cli/src/builtin/specialExpressions/try.d.ts +1 -1
  8. package/dist/{src/builtin/specialExpressions/if_not.d.ts → cli/src/builtin/specialExpressions/unless.d.ts} +2 -2
  9. package/dist/cli/src/evaluator/ContextStack.d.ts +2 -0
  10. package/dist/cli/src/parser/AlgebraicParser.d.ts +13 -8
  11. package/dist/cli/src/parser/commonTokenParsers.d.ts +2 -1
  12. package/dist/cli/src/tokenizer/algebraic/algebraicReservedNames.d.ts +27 -27
  13. package/dist/cli/src/tokenizer/algebraic/algebraicTokenizers.d.ts +1 -1
  14. package/dist/cli/src/tokenizer/algebraic/algebraicTokens.d.ts +5 -5
  15. package/dist/cli/src/tokenizer/common/commonTokenizers.d.ts +3 -2
  16. package/dist/cli/src/tokenizer/common/commonTokens.d.ts +6 -2
  17. package/dist/cli/src/tokenizer/polish/polishTokenizers.d.ts +2 -3
  18. package/dist/cli/src/tokenizer/polish/polishTokens.d.ts +4 -8
  19. package/dist/cli/src/tokenizer/tokens.d.ts +2 -2
  20. package/dist/index.esm.js +1004 -1514
  21. package/dist/index.esm.js.map +1 -1
  22. package/dist/index.js +1004 -1514
  23. package/dist/index.js.map +1 -1
  24. package/dist/lits.iife.js +1004 -1514
  25. package/dist/lits.iife.js.map +1 -1
  26. package/dist/reference/api.d.ts +5 -5
  27. package/dist/src/analyze/index.d.ts +0 -2
  28. package/dist/src/builtin/index.d.ts +3 -10
  29. package/dist/src/builtin/specialExpressions/declared.d.ts +1 -1
  30. package/dist/src/builtin/specialExpressions/functions.d.ts +0 -5
  31. package/dist/src/builtin/specialExpressions/try.d.ts +1 -1
  32. package/dist/src/builtin/specialExpressions/{when.d.ts → unless.d.ts} +2 -2
  33. package/dist/src/evaluator/ContextStack.d.ts +2 -0
  34. package/dist/src/parser/AlgebraicParser.d.ts +13 -8
  35. package/dist/src/parser/commonTokenParsers.d.ts +2 -1
  36. package/dist/src/tokenizer/algebraic/algebraicReservedNames.d.ts +27 -27
  37. package/dist/src/tokenizer/algebraic/algebraicTokenizers.d.ts +1 -1
  38. package/dist/src/tokenizer/algebraic/algebraicTokens.d.ts +5 -5
  39. package/dist/src/tokenizer/common/commonTokenizers.d.ts +3 -2
  40. package/dist/src/tokenizer/common/commonTokens.d.ts +6 -2
  41. package/dist/src/tokenizer/polish/polishTokenizers.d.ts +2 -3
  42. package/dist/src/tokenizer/polish/polishTokens.d.ts +4 -8
  43. package/dist/src/tokenizer/tokens.d.ts +2 -2
  44. package/dist/testFramework.esm.js +631 -1193
  45. package/dist/testFramework.esm.js.map +1 -1
  46. package/dist/testFramework.js +631 -1193
  47. package/dist/testFramework.js.map +1 -1
  48. package/package.json +1 -1
  49. package/dist/cli/src/analyze/calculateOutcomes/calculateAndOutcomes.d.ts +0 -3
  50. package/dist/cli/src/analyze/calculateOutcomes/calculateCommentOutcomes.d.ts +0 -3
  51. package/dist/cli/src/analyze/calculateOutcomes/calculateCondOutcomes.d.ts +0 -3
  52. package/dist/cli/src/analyze/calculateOutcomes/calculateDeclaredOutcomes.d.ts +0 -3
  53. package/dist/cli/src/analyze/calculateOutcomes/calculateDefOutcomes.d.ts +0 -3
  54. package/dist/cli/src/analyze/calculateOutcomes/calculateDefsOutcomes.d.ts +0 -3
  55. package/dist/cli/src/analyze/calculateOutcomes/calculateDoOutcomes.d.ts +0 -3
  56. package/dist/cli/src/analyze/calculateOutcomes/calculateFunctionOutcomes.d.ts +0 -5
  57. package/dist/cli/src/analyze/calculateOutcomes/calculateIfLetOutcomes.d.ts +0 -3
  58. package/dist/cli/src/analyze/calculateOutcomes/calculateIfNotOutcomes.d.ts +0 -3
  59. package/dist/cli/src/analyze/calculateOutcomes/calculateIfOutcomes.d.ts +0 -3
  60. package/dist/cli/src/analyze/calculateOutcomes/calculateLetOutcomes.d.ts +0 -3
  61. package/dist/cli/src/analyze/calculateOutcomes/calculateLoopOutcomes.d.ts +0 -3
  62. package/dist/cli/src/analyze/calculateOutcomes/calculateLoopsOutcomes.d.ts +0 -4
  63. package/dist/cli/src/analyze/calculateOutcomes/calculateOrOutcomes.d.ts +0 -3
  64. package/dist/cli/src/analyze/calculateOutcomes/calculateQqOutcomes.d.ts +0 -3
  65. package/dist/cli/src/analyze/calculateOutcomes/calculateRecurOutcomes.d.ts +0 -3
  66. package/dist/cli/src/analyze/calculateOutcomes/calculateSwitchOutcomes.d.ts +0 -3
  67. package/dist/cli/src/analyze/calculateOutcomes/calculateThrowOutcomes.d.ts +0 -3
  68. package/dist/cli/src/analyze/calculateOutcomes/calculateTryOutcomes.d.ts +0 -3
  69. package/dist/cli/src/analyze/calculateOutcomes/calculateWhenFirstOutcomes.d.ts +0 -3
  70. package/dist/cli/src/analyze/calculateOutcomes/calculateWhenLetOutcomes.d.ts +0 -3
  71. package/dist/cli/src/analyze/calculateOutcomes/calculateWhenNotOutcomes.d.ts +0 -3
  72. package/dist/cli/src/analyze/calculateOutcomes/calculateWhenOutcomes.d.ts +0 -3
  73. package/dist/cli/src/analyze/calculateOutcomes/index.d.ts +0 -18
  74. package/dist/cli/src/analyze/calculateOutcomes/specialExpressionCalculators.d.ts +0 -55
  75. package/dist/cli/src/builtin/specialExpressions/defs.d.ts +0 -5
  76. package/dist/cli/src/builtin/specialExpressions/if_let.d.ts +0 -7
  77. package/dist/cli/src/builtin/specialExpressions/if_not.d.ts +0 -6
  78. package/dist/cli/src/builtin/specialExpressions/when.d.ts +0 -6
  79. package/dist/cli/src/builtin/specialExpressions/when_first.d.ts +0 -7
  80. package/dist/cli/src/builtin/specialExpressions/when_let.d.ts +0 -7
  81. package/dist/cli/src/builtin/specialExpressions/when_not.d.ts +0 -6
  82. package/dist/src/analyze/calculateOutcomes/calculateAndOutcomes.d.ts +0 -3
  83. package/dist/src/analyze/calculateOutcomes/calculateCommentOutcomes.d.ts +0 -3
  84. package/dist/src/analyze/calculateOutcomes/calculateCondOutcomes.d.ts +0 -3
  85. package/dist/src/analyze/calculateOutcomes/calculateDeclaredOutcomes.d.ts +0 -3
  86. package/dist/src/analyze/calculateOutcomes/calculateDefOutcomes.d.ts +0 -3
  87. package/dist/src/analyze/calculateOutcomes/calculateDefsOutcomes.d.ts +0 -3
  88. package/dist/src/analyze/calculateOutcomes/calculateDoOutcomes.d.ts +0 -3
  89. package/dist/src/analyze/calculateOutcomes/calculateFunctionOutcomes.d.ts +0 -5
  90. package/dist/src/analyze/calculateOutcomes/calculateIfLetOutcomes.d.ts +0 -3
  91. package/dist/src/analyze/calculateOutcomes/calculateIfNotOutcomes.d.ts +0 -3
  92. package/dist/src/analyze/calculateOutcomes/calculateIfOutcomes.d.ts +0 -3
  93. package/dist/src/analyze/calculateOutcomes/calculateLetOutcomes.d.ts +0 -3
  94. package/dist/src/analyze/calculateOutcomes/calculateLoopOutcomes.d.ts +0 -3
  95. package/dist/src/analyze/calculateOutcomes/calculateLoopsOutcomes.d.ts +0 -4
  96. package/dist/src/analyze/calculateOutcomes/calculateOrOutcomes.d.ts +0 -3
  97. package/dist/src/analyze/calculateOutcomes/calculateQqOutcomes.d.ts +0 -3
  98. package/dist/src/analyze/calculateOutcomes/calculateRecurOutcomes.d.ts +0 -3
  99. package/dist/src/analyze/calculateOutcomes/calculateSwitchOutcomes.d.ts +0 -3
  100. package/dist/src/analyze/calculateOutcomes/calculateThrowOutcomes.d.ts +0 -3
  101. package/dist/src/analyze/calculateOutcomes/calculateTryOutcomes.d.ts +0 -3
  102. package/dist/src/analyze/calculateOutcomes/calculateWhenFirstOutcomes.d.ts +0 -3
  103. package/dist/src/analyze/calculateOutcomes/calculateWhenLetOutcomes.d.ts +0 -3
  104. package/dist/src/analyze/calculateOutcomes/calculateWhenNotOutcomes.d.ts +0 -3
  105. package/dist/src/analyze/calculateOutcomes/calculateWhenOutcomes.d.ts +0 -3
  106. package/dist/src/analyze/calculateOutcomes/index.d.ts +0 -18
  107. package/dist/src/analyze/calculateOutcomes/specialExpressionCalculators.d.ts +0 -55
  108. package/dist/src/builtin/specialExpressions/defs.d.ts +0 -5
  109. package/dist/src/builtin/specialExpressions/if_let.d.ts +0 -7
  110. package/dist/src/builtin/specialExpressions/when_first.d.ts +0 -7
  111. package/dist/src/builtin/specialExpressions/when_let.d.ts +0 -7
  112. package/dist/src/builtin/specialExpressions/when_not.d.ts +0 -6
package/dist/index.esm.js CHANGED
@@ -281,6 +281,7 @@ var commonSimpleTokenTypes = [
281
281
  ];
282
282
  var commomValueTokenTypes = [
283
283
  'String',
284
+ 'RegexpShorthand',
284
285
  ];
285
286
  function isLParenToken(token) {
286
287
  return (token === null || token === void 0 ? void 0 : token[0]) === 'LParen';
@@ -354,6 +355,18 @@ function asStringToken(token) {
354
355
  assertStringToken(token);
355
356
  return token;
356
357
  }
358
+ function isRegexpShorthandToken(token) {
359
+ return (token === null || token === void 0 ? void 0 : token[0]) === 'RegexpShorthand';
360
+ }
361
+ function assertRegexpShorthandToken(token) {
362
+ if (!isRegexpShorthandToken(token)) {
363
+ throwUnexpectedToken('RegexpShorthand', undefined, token);
364
+ }
365
+ }
366
+ function asRegexpShorthandToken(token) {
367
+ assertRegexpShorthandToken(token);
368
+ return token;
369
+ }
357
370
  function isAlgebraicNotationToken(token) {
358
371
  return (token === null || token === void 0 ? void 0 : token[0]) === 'AlgNotation';
359
372
  }
@@ -424,29 +437,22 @@ var symbolicOperators = __spreadArray(__spreadArray(__spreadArray([], __read(sym
424
437
  var nonFunctionOperators = [
425
438
  '??',
426
439
  '&&',
440
+ '||',
427
441
  'comment',
428
442
  'cond',
429
- 'declared?',
430
- 'if',
431
- 'if_not',
432
- '||',
433
- 'when',
434
- 'when_not',
435
- 'do',
436
- 'throw',
437
- 'let',
438
443
  'def',
439
- 'defs',
440
- 'if_let',
441
- 'when_let',
442
- 'when_first',
443
- 'fn',
444
+ 'defined?',
444
445
  'defn',
445
- 'defns',
446
- 'try',
447
- 'recur',
448
- 'loop',
446
+ 'do',
449
447
  'doseq',
448
+ 'fn',
449
+ 'if',
450
+ 'let',
451
+ 'loop',
452
+ 'recur',
453
+ 'throw',
454
+ 'try',
455
+ 'unless',
450
456
  'while',
451
457
  ];
452
458
  var nonFunctionOperatorSet = new Set(nonFunctionOperators);
@@ -465,16 +471,22 @@ var symbolicOperatorSet = new Set(symbolicOperators);
465
471
  function isSymbolicOperator(operator) {
466
472
  return symbolicOperatorSet.has(operator);
467
473
  }
468
- function isA_SymbolToken(token) {
469
- return (token === null || token === void 0 ? void 0 : token[0]) === 'A_Symbol';
474
+ function isA_SymbolToken(token, symbolName) {
475
+ if ((token === null || token === void 0 ? void 0 : token[0]) !== 'A_Symbol') {
476
+ return false;
477
+ }
478
+ if (symbolName && token[1] !== symbolName) {
479
+ return false;
480
+ }
481
+ return true;
470
482
  }
471
- function assertA_SymbolToken(token) {
472
- if (!isA_SymbolToken(token)) {
483
+ function assertA_SymbolToken(token, symbolName) {
484
+ if (!isA_SymbolToken(token, symbolName)) {
473
485
  throwUnexpectedToken('A_Symbol', undefined, token);
474
486
  }
475
487
  }
476
- function asA_SymbolToken(token) {
477
- assertA_SymbolToken(token);
488
+ function asA_SymbolToken(token, symbolName) {
489
+ assertA_SymbolToken(token, symbolName);
478
490
  return token;
479
491
  }
480
492
  function isA_BinaryOperatorToken(token) {
@@ -511,9 +523,10 @@ function isA_OperatorToken(token, operatorName) {
511
523
  }
512
524
  function assertA_OperatorToken(token, operatorName) {
513
525
  if (!isA_OperatorToken(token, operatorName)) {
514
- {
526
+ if (operatorName) {
515
527
  throw new LitsError("Unexpected token: ".concat(token, ", expected operator ").concat(operatorName), undefined);
516
528
  }
529
+ throwUnexpectedToken('A_Operator', operatorName, token);
517
530
  }
518
531
  }
519
532
  function isA_WhitespaceToken(token) {
@@ -536,7 +549,6 @@ var polishOnlyValueTokenTypes = [
536
549
  'P_StringShorthand',
537
550
  'P_Symbol',
538
551
  'P_ReservedSymbol',
539
- 'P_RegexpShorthand',
540
552
  'P_CollectionAccessor',
541
553
  'P_Comment',
542
554
  'P_Whitespace',
@@ -574,18 +586,6 @@ function isP_ReservedSymbolToken(token) {
574
586
  function isP_ModifierToken(token) {
575
587
  return (token === null || token === void 0 ? void 0 : token[0]) === 'P_Modifier';
576
588
  }
577
- function isP_RegexpShorthandToken(token) {
578
- return (token === null || token === void 0 ? void 0 : token[0]) === 'P_RegexpShorthand';
579
- }
580
- function assertP_RegexpShorthandToken(token) {
581
- if (!isP_RegexpShorthandToken(token)) {
582
- throwUnexpectedToken('P_RegexpShorthand', undefined, token);
583
- }
584
- }
585
- function asP_RegexpShorthandToken(token) {
586
- assertP_RegexpShorthandToken(token);
587
- return token;
588
- }
589
589
  function isP_FnShorthandToken(token) {
590
590
  return (token === null || token === void 0 ? void 0 : token[0]) === 'P_FnShorthand';
591
591
  }
@@ -757,7 +757,7 @@ var specialExpressionCommentRemovers = {
757
757
  removeOptions.removeCommenNodesFromArray(node.p);
758
758
  node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
759
759
  },
760
- 'declared?': function (node, removeOptions) {
760
+ 'defined?': function (node, removeOptions) {
761
761
  removeOptions.removeCommenNodesFromArray(node.p);
762
762
  node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
763
763
  },
@@ -766,11 +766,6 @@ var specialExpressionCommentRemovers = {
766
766
  removeOptions.removeCommenNodesFromArray(node.p);
767
767
  node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
768
768
  },
769
- 'defns': function (_node, _removeOptions) { },
770
- 'defs': function (node, removeOptions) {
771
- removeOptions.removeCommenNodesFromArray(node.p);
772
- node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
773
- },
774
769
  'do': function (node, removeOptions) {
775
770
  removeOptions.removeCommenNodesFromArray(node.p);
776
771
  node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
@@ -778,12 +773,11 @@ var specialExpressionCommentRemovers = {
778
773
  'doseq': function (_node, _removeOptions) { },
779
774
  'fn': function (_node, _removeOptions) { },
780
775
  'for': function (_node, _removeOptions) { },
781
- 'if_let': function (_node, _removeOptions) { },
782
776
  'if': function (node, removeOptions) {
783
777
  removeOptions.removeCommenNodesFromArray(node.p);
784
778
  node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
785
779
  },
786
- 'if_not': function (node, removeOptions) {
780
+ 'unless': function (node, removeOptions) {
787
781
  removeOptions.removeCommenNodesFromArray(node.p);
788
782
  node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
789
783
  },
@@ -812,10 +806,6 @@ var specialExpressionCommentRemovers = {
812
806
  node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
813
807
  },
814
808
  'try': function (_node, _removeOptions) { },
815
- 'when_first': function (_node, _removeOptions) { },
816
- 'when_let': function (_node, _removeOptions) { },
817
- 'when': function (_node, _removeOptions) { },
818
- 'when_not': function (_node, _removeOptions) { },
819
809
  };
820
810
  function removeCommentNodesFromSpecialExpression(node, removeOptions) {
821
811
  var uncommenter = specialExpressionCommentRemovers[node.n];
@@ -1980,7 +1970,7 @@ var arrayNormalExpression = {
1980
1970
  };
1981
1971
 
1982
1972
  var sequenceNormalExpression = {
1983
- nth: {
1973
+ 'nth': {
1984
1974
  evaluate: function (params, sourceCodeInfo) {
1985
1975
  var _a = __read(params, 2), seq = _a[0], i = _a[1];
1986
1976
  var defaultValue = toAny(params[2]);
@@ -1992,7 +1982,7 @@ var sequenceNormalExpression = {
1992
1982
  },
1993
1983
  validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
1994
1984
  },
1995
- filter: {
1985
+ 'filter': {
1996
1986
  evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
1997
1987
  var _c = __read(_a, 2), seq = _c[0], fn = _c[1];
1998
1988
  var executeFunction = _b.executeFunction;
@@ -2007,7 +1997,7 @@ var sequenceNormalExpression = {
2007
1997
  },
2008
1998
  validate: function (node) { return assertNumberOfParams(2, node); },
2009
1999
  },
2010
- first: {
2000
+ 'first': {
2011
2001
  evaluate: function (_a, sourceCodeInfo) {
2012
2002
  var _b = __read(_a, 1), array = _b[0];
2013
2003
  if (array === null)
@@ -2017,7 +2007,7 @@ var sequenceNormalExpression = {
2017
2007
  },
2018
2008
  validate: function (node) { return assertNumberOfParams(1, node); },
2019
2009
  },
2020
- last: {
2010
+ 'last': {
2021
2011
  evaluate: function (_a, sourceCodeInfo) {
2022
2012
  var _b = __read(_a, 1), array = _b[0];
2023
2013
  if (array === null)
@@ -2027,7 +2017,7 @@ var sequenceNormalExpression = {
2027
2017
  },
2028
2018
  validate: function (node) { return assertNumberOfParams(1, node); },
2029
2019
  },
2030
- map: {
2020
+ 'map': {
2031
2021
  evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
2032
2022
  var _c = __read(_a, 2), seq = _c[0], fn = _c[1];
2033
2023
  var executeFunction = _b.executeFunction;
@@ -2049,7 +2039,7 @@ var sequenceNormalExpression = {
2049
2039
  },
2050
2040
  validate: function (node) { return assertNumberOfParams(2, node); },
2051
2041
  },
2052
- pop: {
2042
+ 'pop': {
2053
2043
  evaluate: function (_a, sourceCodeInfo) {
2054
2044
  var _b = __read(_a, 1), seq = _b[0];
2055
2045
  assertSeq(seq, sourceCodeInfo);
@@ -2060,7 +2050,7 @@ var sequenceNormalExpression = {
2060
2050
  },
2061
2051
  validate: function (node) { return assertNumberOfParams(1, node); },
2062
2052
  },
2063
- position: {
2053
+ 'position': {
2064
2054
  evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
2065
2055
  var _c = __read(_a, 2), seq = _c[0], fn = _c[1];
2066
2056
  var executeFunction = _b.executeFunction;
@@ -2079,7 +2069,7 @@ var sequenceNormalExpression = {
2079
2069
  },
2080
2070
  validate: function (node) { return assertNumberOfParams(2, node); },
2081
2071
  },
2082
- index_of: {
2072
+ 'index_of': {
2083
2073
  evaluate: function (_a, sourceCodeInfo) {
2084
2074
  var _b = __read(_a, 2), seq = _b[0], value = _b[1];
2085
2075
  assertAny(value, sourceCodeInfo);
@@ -2098,7 +2088,26 @@ var sequenceNormalExpression = {
2098
2088
  },
2099
2089
  validate: function (node) { return assertNumberOfParams(2, node); },
2100
2090
  },
2101
- push: {
2091
+ 'last_index_of': {
2092
+ evaluate: function (_a, sourceCodeInfo) {
2093
+ var _b = __read(_a, 2), seq = _b[0], value = _b[1];
2094
+ assertAny(value, sourceCodeInfo);
2095
+ if (seq === null)
2096
+ return null;
2097
+ assertSeq(seq, sourceCodeInfo);
2098
+ if (typeof seq === 'string') {
2099
+ assertString(value, sourceCodeInfo);
2100
+ var index = seq.lastIndexOf(value);
2101
+ return index !== -1 ? index : null;
2102
+ }
2103
+ else {
2104
+ var index = seq.lastIndexOf(value);
2105
+ return index !== -1 ? index : null;
2106
+ }
2107
+ },
2108
+ validate: function (node) { return assertNumberOfParams(2, node); },
2109
+ },
2110
+ 'push': {
2102
2111
  evaluate: function (_a, sourceCodeInfo) {
2103
2112
  var _b = __read(_a), seq = _b[0], values = _b.slice(1);
2104
2113
  assertSeq(seq, sourceCodeInfo);
@@ -2112,7 +2121,7 @@ var sequenceNormalExpression = {
2112
2121
  },
2113
2122
  validate: function (node) { return assertNumberOfParams({ min: 2 }, node); },
2114
2123
  },
2115
- reductions: {
2124
+ 'reductions': {
2116
2125
  evaluate: function (params, sourceCodeInfo, contextStack, _a) {
2117
2126
  var executeFunction = _a.executeFunction;
2118
2127
  var _b = __read(params, 2), seq = _b[0], fn = _b[1];
@@ -2173,7 +2182,7 @@ var sequenceNormalExpression = {
2173
2182
  },
2174
2183
  validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
2175
2184
  },
2176
- reduce: {
2185
+ 'reduce': {
2177
2186
  evaluate: function (params, sourceCodeInfo, contextStack, _a) {
2178
2187
  var executeFunction = _a.executeFunction;
2179
2188
  var _b = __read(params, 2), seq = _b[0], fn = _b[1];
@@ -2220,7 +2229,7 @@ var sequenceNormalExpression = {
2220
2229
  },
2221
2230
  validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
2222
2231
  },
2223
- reduce_right: {
2232
+ 'reduce_right': {
2224
2233
  evaluate: function (params, sourceCodeInfo, contextStack, _a) {
2225
2234
  var executeFunction = _a.executeFunction;
2226
2235
  var _b = __read(params, 2), seq = _b[0], fn = _b[1];
@@ -2268,7 +2277,7 @@ var sequenceNormalExpression = {
2268
2277
  },
2269
2278
  validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
2270
2279
  },
2271
- rest: {
2280
+ 'rest': {
2272
2281
  evaluate: function (_a, sourceCodeInfo) {
2273
2282
  var _b = __read(_a, 1), seq = _b[0];
2274
2283
  assertSeq(seq, sourceCodeInfo);
@@ -2281,7 +2290,7 @@ var sequenceNormalExpression = {
2281
2290
  },
2282
2291
  validate: function (node) { return assertNumberOfParams(1, node); },
2283
2292
  },
2284
- nthrest: {
2293
+ 'nthrest': {
2285
2294
  evaluate: function (_a, sourceCodeInfo) {
2286
2295
  var _b = __read(_a, 2), seq = _b[0], count = _b[1];
2287
2296
  assertSeq(seq, sourceCodeInfo);
@@ -2293,7 +2302,7 @@ var sequenceNormalExpression = {
2293
2302
  },
2294
2303
  validate: function (node) { return assertNumberOfParams(2, node); },
2295
2304
  },
2296
- next: {
2305
+ 'next': {
2297
2306
  evaluate: function (_a, sourceCodeInfo) {
2298
2307
  var _b = __read(_a, 1), seq = _b[0];
2299
2308
  assertSeq(seq, sourceCodeInfo);
@@ -2308,7 +2317,7 @@ var sequenceNormalExpression = {
2308
2317
  },
2309
2318
  validate: function (node) { return assertNumberOfParams(1, node); },
2310
2319
  },
2311
- nthnext: {
2320
+ 'nthnext': {
2312
2321
  evaluate: function (_a, sourceCodeInfo) {
2313
2322
  var _b = __read(_a, 2), seq = _b[0], count = _b[1];
2314
2323
  assertSeq(seq, sourceCodeInfo);
@@ -2322,7 +2331,7 @@ var sequenceNormalExpression = {
2322
2331
  },
2323
2332
  validate: function (node) { return assertNumberOfParams(2, node); },
2324
2333
  },
2325
- reverse: {
2334
+ 'reverse': {
2326
2335
  evaluate: function (_a, sourceCodeInfo) {
2327
2336
  var _b = __read(_a, 1), seq = _b[0];
2328
2337
  if (seq === null)
@@ -2334,7 +2343,7 @@ var sequenceNormalExpression = {
2334
2343
  },
2335
2344
  validate: function (node) { return assertNumberOfParams(1, node); },
2336
2345
  },
2337
- second: {
2346
+ 'second': {
2338
2347
  evaluate: function (_a, sourceCodeInfo) {
2339
2348
  var _b = __read(_a, 1), seq = _b[0];
2340
2349
  if (seq === null)
@@ -2344,7 +2353,7 @@ var sequenceNormalExpression = {
2344
2353
  },
2345
2354
  validate: function (node) { return assertNumberOfParams(1, node); },
2346
2355
  },
2347
- shift: {
2356
+ 'shift': {
2348
2357
  evaluate: function (_a, sourceCodeInfo) {
2349
2358
  var _b = __read(_a, 1), seq = _b[0];
2350
2359
  assertSeq(seq, sourceCodeInfo);
@@ -2356,7 +2365,7 @@ var sequenceNormalExpression = {
2356
2365
  },
2357
2366
  validate: function (node) { return assertNumberOfParams(1, node); },
2358
2367
  },
2359
- slice: {
2368
+ 'slice': {
2360
2369
  evaluate: function (params, sourceCodeInfo) {
2361
2370
  var _a = __read(params, 3), seq = _a[0], from = _a[1], to = _a[2];
2362
2371
  assertSeq(seq, sourceCodeInfo);
@@ -2370,7 +2379,7 @@ var sequenceNormalExpression = {
2370
2379
  },
2371
2380
  validate: function (node) { return assertNumberOfParams({ min: 1, max: 3 }, node); },
2372
2381
  },
2373
- some: {
2382
+ 'some': {
2374
2383
  evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
2375
2384
  var _c;
2376
2385
  var _d = __read(_a, 2), seq = _d[0], fn = _d[1];
@@ -2387,7 +2396,7 @@ var sequenceNormalExpression = {
2387
2396
  },
2388
2397
  validate: function (node) { return assertNumberOfParams(2, node); },
2389
2398
  },
2390
- sort: {
2399
+ 'sort': {
2391
2400
  evaluate: function (params, sourceCodeInfo, contextStack, _a) {
2392
2401
  var executeFunction = _a.executeFunction;
2393
2402
  var _b = __read(params, 1), seq = _b[0];
@@ -2425,7 +2434,7 @@ var sequenceNormalExpression = {
2425
2434
  },
2426
2435
  validate: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
2427
2436
  },
2428
- sort_by: {
2437
+ 'sort_by': {
2429
2438
  evaluate: function (params, sourceCodeInfo, contextStack, _a) {
2430
2439
  var executeFunction = _a.executeFunction;
2431
2440
  var _b = __read(params, 2), seq = _b[0], keyfn = _b[1];
@@ -2476,7 +2485,7 @@ var sequenceNormalExpression = {
2476
2485
  },
2477
2486
  validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
2478
2487
  },
2479
- take: {
2488
+ 'take': {
2480
2489
  evaluate: function (_a, sourceCodeInfo) {
2481
2490
  var _b = __read(_a, 2), input = _b[0], n = _b[1];
2482
2491
  assertNumber(n, sourceCodeInfo);
@@ -2486,7 +2495,7 @@ var sequenceNormalExpression = {
2486
2495
  },
2487
2496
  validate: function (node) { return assertNumberOfParams(2, node); },
2488
2497
  },
2489
- take_last: {
2498
+ 'take_last': {
2490
2499
  evaluate: function (_a, sourceCodeInfo) {
2491
2500
  var _b = __read(_a, 2), array = _b[0], n = _b[1];
2492
2501
  assertSeq(array, sourceCodeInfo);
@@ -2497,7 +2506,7 @@ var sequenceNormalExpression = {
2497
2506
  },
2498
2507
  validate: function (node) { return assertNumberOfParams(2, node); },
2499
2508
  },
2500
- take_while: {
2509
+ 'take_while': {
2501
2510
  evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
2502
2511
  var e_1, _c;
2503
2512
  var _d = __read(_a, 2), seq = _d[0], fn = _d[1];
@@ -2525,7 +2534,7 @@ var sequenceNormalExpression = {
2525
2534
  },
2526
2535
  validate: function (node) { return assertNumberOfParams(2, node); },
2527
2536
  },
2528
- drop: {
2537
+ 'drop': {
2529
2538
  evaluate: function (_a, sourceCodeInfo) {
2530
2539
  var _b = __read(_a, 2), input = _b[0], n = _b[1];
2531
2540
  assertNumber(n, sourceCodeInfo);
@@ -2535,7 +2544,7 @@ var sequenceNormalExpression = {
2535
2544
  },
2536
2545
  validate: function (node) { return assertNumberOfParams(2, node); },
2537
2546
  },
2538
- drop_last: {
2547
+ 'drop_last': {
2539
2548
  evaluate: function (_a, sourceCodeInfo) {
2540
2549
  var _b = __read(_a, 2), array = _b[0], n = _b[1];
2541
2550
  assertSeq(array, sourceCodeInfo);
@@ -2546,7 +2555,7 @@ var sequenceNormalExpression = {
2546
2555
  },
2547
2556
  validate: function (node) { return assertNumberOfParams(2, node); },
2548
2557
  },
2549
- drop_while: {
2558
+ 'drop_while': {
2550
2559
  evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
2551
2560
  var _c = __read(_a, 2), seq = _c[0], fn = _c[1];
2552
2561
  var executeFunction = _b.executeFunction;
@@ -2562,7 +2571,7 @@ var sequenceNormalExpression = {
2562
2571
  },
2563
2572
  validate: function (node) { return assertNumberOfParams(2, node); },
2564
2573
  },
2565
- unshift: {
2574
+ 'unshift': {
2566
2575
  evaluate: function (_a, sourceCodeInfo) {
2567
2576
  var _b = __read(_a), seq = _b[0], values = _b.slice(1);
2568
2577
  assertSeq(seq, sourceCodeInfo);
@@ -2576,7 +2585,7 @@ var sequenceNormalExpression = {
2576
2585
  },
2577
2586
  validate: function (node) { return assertNumberOfParams({ min: 2 }, node); },
2578
2587
  },
2579
- distinct: {
2588
+ 'distinct': {
2580
2589
  evaluate: function (_a, sourceCodeInfo) {
2581
2590
  var _b = __read(_a, 1), input = _b[0];
2582
2591
  assertSeq(input, sourceCodeInfo);
@@ -2586,9 +2595,9 @@ var sequenceNormalExpression = {
2586
2595
  },
2587
2596
  validate: function (node) { return assertNumberOfParams(1, node); },
2588
2597
  },
2589
- remove: {
2598
+ 'remove': {
2590
2599
  evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
2591
- var _c = __read(_a, 2), fn = _c[0], input = _c[1];
2600
+ var _c = __read(_a, 2), input = _c[0], fn = _c[1];
2592
2601
  var executeFunction = _b.executeFunction;
2593
2602
  assertLitsFunction(fn, sourceCodeInfo);
2594
2603
  assertSeq(input, sourceCodeInfo);
@@ -2601,9 +2610,9 @@ var sequenceNormalExpression = {
2601
2610
  },
2602
2611
  validate: function (node) { return assertNumberOfParams(2, node); },
2603
2612
  },
2604
- remove_at: {
2613
+ 'remove_at': {
2605
2614
  evaluate: function (_a, sourceCodeInfo) {
2606
- var _b = __read(_a, 2), index = _b[0], input = _b[1];
2615
+ var _b = __read(_a, 2), input = _b[0], index = _b[1];
2607
2616
  assertNumber(index, sourceCodeInfo);
2608
2617
  assertSeq(input, sourceCodeInfo);
2609
2618
  var intIndex = Math.ceil(index);
@@ -2618,9 +2627,9 @@ var sequenceNormalExpression = {
2618
2627
  },
2619
2628
  validate: function (node) { return assertNumberOfParams(2, node); },
2620
2629
  },
2621
- split_at: {
2630
+ 'split_at': {
2622
2631
  evaluate: function (_a, sourceCodeInfo) {
2623
- var _b = __read(_a, 2), pos = _b[0], seq = _b[1];
2632
+ var _b = __read(_a, 2), seq = _b[0], pos = _b[1];
2624
2633
  assertNumber(pos, sourceCodeInfo, { finite: true });
2625
2634
  var intPos = toNonNegativeInteger(pos);
2626
2635
  assertSeq(seq, sourceCodeInfo);
@@ -2628,9 +2637,9 @@ var sequenceNormalExpression = {
2628
2637
  },
2629
2638
  validate: function (node) { return assertNumberOfParams(2, node); },
2630
2639
  },
2631
- split_with: {
2640
+ 'split_with': {
2632
2641
  evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
2633
- var _c = __read(_a, 2), fn = _c[0], seq = _c[1];
2642
+ var _c = __read(_a, 2), seq = _c[0], fn = _c[1];
2634
2643
  var executeFunction = _b.executeFunction;
2635
2644
  assertLitsFunction(fn, sourceCodeInfo);
2636
2645
  assertSeq(seq, sourceCodeInfo);
@@ -2643,7 +2652,7 @@ var sequenceNormalExpression = {
2643
2652
  },
2644
2653
  validate: function (node) { return assertNumberOfParams(2, node); },
2645
2654
  },
2646
- frequencies: {
2655
+ 'frequencies': {
2647
2656
  evaluate: function (_a, sourceCodeInfo) {
2648
2657
  var _b = __read(_a, 1), seq = _b[0];
2649
2658
  assertSeq(seq, sourceCodeInfo);
@@ -2659,9 +2668,9 @@ var sequenceNormalExpression = {
2659
2668
  },
2660
2669
  validate: function (node) { return assertNumberOfParams(1, node); },
2661
2670
  },
2662
- group_by: {
2671
+ 'group_by': {
2663
2672
  evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
2664
- var _c = __read(_a, 2), fn = _c[0], seq = _c[1];
2673
+ var _c = __read(_a, 2), seq = _c[0], fn = _c[1];
2665
2674
  var executeFunction = _b.executeFunction;
2666
2675
  assertAny(fn, sourceCodeInfo);
2667
2676
  assertSeq(seq, sourceCodeInfo);
@@ -2677,34 +2686,30 @@ var sequenceNormalExpression = {
2677
2686
  },
2678
2687
  validate: function (node) { return assertNumberOfParams(2, node); },
2679
2688
  },
2680
- partition: {
2689
+ 'partition': {
2681
2690
  evaluate: function (params, sourceCodeInfo) {
2682
- var len = params.length;
2683
- var n = toNonNegativeInteger(asNumber(params[0], sourceCodeInfo));
2684
- var seq = len === 2
2685
- ? asSeq(params[1], sourceCodeInfo)
2686
- : len === 3
2687
- ? asSeq(params[2], sourceCodeInfo)
2688
- : asSeq(params[3], sourceCodeInfo);
2689
- var step = len >= 3 ? toNonNegativeInteger(asNumber(params[1], sourceCodeInfo)) : n;
2690
- var pad = len === 4 ? (params[2] === null ? [] : asArray(params[2], sourceCodeInfo)) : undefined;
2691
+ var seq = asSeq(params[0], sourceCodeInfo);
2692
+ var n = toNonNegativeInteger(asNumber(params[1], sourceCodeInfo));
2693
+ var step = params.length >= 3 ? toNonNegativeInteger(asNumber(params[2], sourceCodeInfo)) : n;
2694
+ var pad = params.length === 4
2695
+ ? params[3] === null ? [] : asArray(params[3], sourceCodeInfo)
2696
+ : undefined;
2691
2697
  return partition(n, step, seq, pad, sourceCodeInfo);
2692
2698
  },
2693
2699
  validate: function (node) { return assertNumberOfParams({ min: 2, max: 4 }, node); },
2694
2700
  },
2695
- partition_all: {
2701
+ 'partition_all': {
2696
2702
  evaluate: function (params, sourceCodeInfo) {
2697
- var len = params.length;
2698
- var n = toNonNegativeInteger(asNumber(params[0], sourceCodeInfo));
2699
- var seq = len === 2 ? asSeq(params[1], sourceCodeInfo) : asSeq(params[2], sourceCodeInfo);
2700
- var step = len >= 3 ? toNonNegativeInteger(asNumber(params[1], sourceCodeInfo)) : n;
2703
+ var seq = asSeq(params[0], sourceCodeInfo);
2704
+ var n = toNonNegativeInteger(asNumber(params[1], sourceCodeInfo));
2705
+ var step = params.length === 3 ? toNonNegativeInteger(asNumber(params[2], sourceCodeInfo)) : n;
2701
2706
  return partition(n, step, seq, [], sourceCodeInfo);
2702
2707
  },
2703
2708
  validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
2704
2709
  },
2705
- partition_by: {
2710
+ 'partition_by': {
2706
2711
  evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
2707
- var _c = __read(_a, 2), fn = _c[0], seq = _c[1];
2712
+ var _c = __read(_a, 2), seq = _c[0], fn = _c[1];
2708
2713
  var executeFunction = _b.executeFunction;
2709
2714
  assertLitsFunction(fn, sourceCodeInfo);
2710
2715
  assertSeq(seq, sourceCodeInfo);
@@ -2721,7 +2726,88 @@ var sequenceNormalExpression = {
2721
2726
  }, []);
2722
2727
  return isStringSeq ? result.map(function (elem) { return elem.join(''); }) : result;
2723
2728
  },
2724
- validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
2729
+ validate: function (node) { return assertNumberOfParams(2, node); },
2730
+ },
2731
+ 'ends_with?': {
2732
+ evaluate: function (_a, sourceCodeInfo) {
2733
+ var _b = __read(_a, 2), str = _b[0], search = _b[1];
2734
+ assertSeq(str, sourceCodeInfo);
2735
+ if (typeof str === 'string') {
2736
+ assertString(search, sourceCodeInfo);
2737
+ return str.endsWith(search);
2738
+ }
2739
+ return str.at(-1) === search;
2740
+ },
2741
+ validate: function (node) { return assertNumberOfParams(2, node); },
2742
+ },
2743
+ 'starts_with?': {
2744
+ evaluate: function (_a, sourceCodeInfo) {
2745
+ var _b = __read(_a, 2), str = _b[0], search = _b[1];
2746
+ assertSeq(str, sourceCodeInfo);
2747
+ if (typeof str === 'string') {
2748
+ assertString(search, sourceCodeInfo);
2749
+ return str.startsWith(search);
2750
+ }
2751
+ return str[0] === search;
2752
+ },
2753
+ validate: function (node) { return assertNumberOfParams(2, node); },
2754
+ },
2755
+ 'interleave': {
2756
+ evaluate: function (_a, sourceCodeInfo) {
2757
+ var e_2, _b;
2758
+ var _c = __read(_a), seqs = _c.slice(0);
2759
+ var isStringSeq = typeof seqs[0] === 'string';
2760
+ var seqsArr = isStringSeq
2761
+ ? seqs.map(function (seq) {
2762
+ assertString(seq, sourceCodeInfo);
2763
+ if (typeof seq === 'string')
2764
+ return seq.split('');
2765
+ return seq;
2766
+ })
2767
+ : seqs.map(function (seq) {
2768
+ assertArray(seq, sourceCodeInfo);
2769
+ return seq;
2770
+ });
2771
+ var maxLength = Math.min.apply(Math, __spreadArray([], __read(seqsArr.map(function (seq) { return seq.length; })), false));
2772
+ var result = [];
2773
+ for (var i = 0; i < maxLength; i += 1) {
2774
+ try {
2775
+ for (var seqsArr_1 = (e_2 = void 0, __values(seqsArr)), seqsArr_1_1 = seqsArr_1.next(); !seqsArr_1_1.done; seqsArr_1_1 = seqsArr_1.next()) {
2776
+ var seq = seqsArr_1_1.value;
2777
+ if (i < seq.length)
2778
+ result.push(seq[i]);
2779
+ }
2780
+ }
2781
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
2782
+ finally {
2783
+ try {
2784
+ if (seqsArr_1_1 && !seqsArr_1_1.done && (_b = seqsArr_1.return)) _b.call(seqsArr_1);
2785
+ }
2786
+ finally { if (e_2) throw e_2.error; }
2787
+ }
2788
+ }
2789
+ return isStringSeq ? result.join('') : result;
2790
+ },
2791
+ validate: function (node) { return assertNumberOfParams({ min: 1 }, node); },
2792
+ },
2793
+ 'interpose': {
2794
+ evaluate: function (_a, sourceCodeInfo) {
2795
+ var _b = __read(_a, 2), seq = _b[0], separator = _b[1];
2796
+ assertSeq(seq, sourceCodeInfo);
2797
+ if (typeof seq === 'string') {
2798
+ assertString(separator, sourceCodeInfo);
2799
+ return seq.split('').join(separator);
2800
+ }
2801
+ if (seq.length === 0)
2802
+ return [];
2803
+ var result = [];
2804
+ for (var i = 0; i < seq.length - 1; i += 1) {
2805
+ result.push(seq[i], separator);
2806
+ }
2807
+ result.push(seq[seq.length - 1]);
2808
+ return result;
2809
+ },
2810
+ validate: function (node) { return assertNumberOfParams(2, node); },
2725
2811
  },
2726
2812
  };
2727
2813
  function partition(n, step, seq, pad, sourceCodeInfo) {
@@ -3884,7 +3970,7 @@ var regexpNormalExpression = {
3884
3970
  },
3885
3971
  match: {
3886
3972
  evaluate: function (_a, sourceCodeInfo) {
3887
- var _b = __read(_a, 2), regexp = _b[0], text = _b[1];
3973
+ var _b = __read(_a, 2), text = _b[0], regexp = _b[1];
3888
3974
  assertRegularExpression(regexp, sourceCodeInfo);
3889
3975
  if (!isString(text))
3890
3976
  return null;
@@ -3900,15 +3986,27 @@ var regexpNormalExpression = {
3900
3986
  evaluate: function (_a, sourceCodeInfo) {
3901
3987
  var _b = __read(_a, 3), str = _b[0], regexp = _b[1], value = _b[2];
3902
3988
  assertString(str, sourceCodeInfo);
3903
- assertRegularExpression(regexp, sourceCodeInfo);
3989
+ assertStringOrRegularExpression(regexp, sourceCodeInfo);
3904
3990
  assertString(value, sourceCodeInfo);
3905
- var regExp = new RegExp(regexp.s, regexp.f);
3906
- return str.replace(regExp, value);
3991
+ var matcher = isRegularExpression(regexp) ? new RegExp(regexp.s, "".concat(regexp.f)) : regexp;
3992
+ return str.replace(matcher, value);
3993
+ },
3994
+ validate: function (node) { return assertNumberOfParams(3, node); },
3995
+ },
3996
+ replace_all: {
3997
+ evaluate: function (_a, sourceCodeInfo) {
3998
+ var _b = __read(_a, 3), str = _b[0], regexp = _b[1], value = _b[2];
3999
+ assertString(str, sourceCodeInfo);
4000
+ assertStringOrRegularExpression(regexp, sourceCodeInfo);
4001
+ assertString(value, sourceCodeInfo);
4002
+ var matcher = isRegularExpression(regexp) ? new RegExp(regexp.s, "".concat(regexp.f.includes('g') ? regexp.f : "".concat(regexp.f, "g"))) : regexp;
4003
+ return str.replaceAll(matcher, value);
3907
4004
  },
3908
4005
  validate: function (node) { return assertNumberOfParams(3, node); },
3909
4006
  },
3910
4007
  };
3911
4008
 
4009
+ var blankRegexp = /^\s*$/;
3912
4010
  var stringNormalExpression = {
3913
4011
  'subs': {
3914
4012
  evaluate: function (_a, sourceCodeInfo) {
@@ -4066,6 +4164,14 @@ var stringNormalExpression = {
4066
4164
  },
4067
4165
  validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
4068
4166
  },
4167
+ 'split_lines': {
4168
+ evaluate: function (_a, sourceCodeInfo) {
4169
+ var _b = __read(_a, 1), str = _b[0];
4170
+ assertString(str, sourceCodeInfo);
4171
+ return str.split((/\r\n|\n|\r/)).filter(function (line) { return line !== ''; });
4172
+ },
4173
+ validate: function (node) { return assertNumberOfParams(1, node); },
4174
+ },
4069
4175
  'pad_left': {
4070
4176
  evaluate: function (_a, sourceCodeInfo) {
4071
4177
  var _b = __read(_a, 3), str = _b[0], length = _b[1], padString = _b[2];
@@ -4169,6 +4275,25 @@ var stringNormalExpression = {
4169
4275
  },
4170
4276
  validate: function (node) { return assertNumberOfParams(1, node); },
4171
4277
  },
4278
+ 'blank?': {
4279
+ evaluate: function (_a, sourceCodeInfo) {
4280
+ var _b = __read(_a, 1), value = _b[0];
4281
+ if (value === null) {
4282
+ return true;
4283
+ }
4284
+ assertString(value, sourceCodeInfo);
4285
+ return blankRegexp.test(value);
4286
+ },
4287
+ validate: function (node) { return assertNumberOfParams(1, node); },
4288
+ },
4289
+ 'capitalize': {
4290
+ evaluate: function (_a, sourceCodeInfo) {
4291
+ var _b = __read(_a, 1), str = _b[0];
4292
+ assertString(str, sourceCodeInfo);
4293
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
4294
+ },
4295
+ validate: function (node) { return assertNumberOfParams(1, node); },
4296
+ },
4172
4297
  };
4173
4298
  var doubleDollarRegexp = /\$\$/g;
4174
4299
  function applyPlaceholders(templateString, placeholders, sourceCodeInfo) {
@@ -4442,7 +4567,7 @@ var switchSpecialExpression = {
4442
4567
  };
4443
4568
 
4444
4569
  var declaredSpecialExpression = {
4445
- polishParse: getCommonPolishSpecialExpressionParser('declared?'),
4570
+ polishParse: getCommonPolishSpecialExpressionParser('defined?'),
4446
4571
  validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
4447
4572
  evaluate: function (node, contextStack) {
4448
4573
  var lookUpResult = contextStack.lookUp(node.p[0]);
@@ -4498,9 +4623,7 @@ var defSpecialExpression = {
4498
4623
  var sourceCodeInfo = (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo;
4499
4624
  var name = node.p[0].v;
4500
4625
  assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
4501
- contextStack.globalContext[name] = {
4502
- value: evaluateAstNode(node.p[1], contextStack),
4503
- };
4626
+ contextStack.exportValue(name, evaluateAstNode(node.p[1], contextStack));
4504
4627
  return null;
4505
4628
  },
4506
4629
  findUnresolvedIdentifiers: function (node, contextStack, _a) {
@@ -4511,47 +4634,7 @@ var defSpecialExpression = {
4511
4634
  var result = findUnresolvedIdentifiers([subNode], contextStack, builtin);
4512
4635
  var name = asSymbolNode(node.p[0]).v;
4513
4636
  assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
4514
- contextStack.globalContext[name] = { value: true };
4515
- return result;
4516
- },
4517
- };
4518
-
4519
- var defsSpecialExpression = {
4520
- polishParse: function (tokenStream, parseState, firstToken, _a) {
4521
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4522
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4523
- assertRParenToken(tokenStream.tokens[parseState.position++]);
4524
- var node = {
4525
- t: AstNodeType.SpecialExpression,
4526
- n: 'defs',
4527
- p: params,
4528
- token: getTokenDebugData(firstToken) && firstToken,
4529
- };
4530
- return node;
4531
- },
4532
- validateParameterCount: function (node) { return assertNumberOfParams(2, node); },
4533
- evaluate: function (node, contextStack, _a) {
4534
- var _b, _c;
4535
- var evaluateAstNode = _a.evaluateAstNode, builtin = _a.builtin;
4536
- var sourceCodeInfo = (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo;
4537
- var name = evaluateAstNode(node.p[0], contextStack);
4538
- assertString(name, sourceCodeInfo);
4539
- assertNameNotDefined(name, contextStack, builtin, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
4540
- contextStack.globalContext[name] = {
4541
- value: evaluateAstNode(node.p[1], contextStack),
4542
- };
4543
- return null;
4544
- },
4545
- findUnresolvedIdentifiers: function (node, contextStack, _a) {
4546
- var _b;
4547
- var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin, evaluateAstNode = _a.evaluateAstNode;
4548
- var sourceCodeInfo = (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo;
4549
- var subNode = node.p[1];
4550
- var result = findUnresolvedIdentifiers([subNode], contextStack, builtin);
4551
- var name = evaluateAstNode(node.p[0], contextStack);
4552
- assertString(name, sourceCodeInfo);
4553
- assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
4554
- contextStack.globalContext[name] = { value: true };
4637
+ contextStack.exportValue(name, true);
4555
4638
  return result;
4556
4639
  },
4557
4640
  };
@@ -4582,7 +4665,7 @@ var doSpecialExpression = {
4582
4665
  },
4583
4666
  findUnresolvedIdentifiers: function (node, contextStack, _a) {
4584
4667
  var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
4585
- return findUnresolvedIdentifiers(node.p, contextStack, builtin);
4668
+ return findUnresolvedIdentifiers(node.p, contextStack.create({}), builtin);
4586
4669
  },
4587
4670
  };
4588
4671
 
@@ -4611,11 +4694,6 @@ function joinAnalyzeResults() {
4611
4694
  function addAnalyzeResults(target, source) {
4612
4695
  source.forEach(function (symbol) { return target.add(symbol); });
4613
4696
  }
4614
- function combinate(arrays) {
4615
- return arrays.reduce(function (acc, curr) {
4616
- return acc.flatMap(function (a) { return curr.map(function (c) { return __spreadArray(__spreadArray([], __read(a), false), [c], false); }); });
4617
- }, [[]]);
4618
- }
4619
4697
 
4620
4698
  var defnSpecialExpression = {
4621
4699
  polishParse: function (tokenStream, parseState, firstToken, parsers) {
@@ -4640,7 +4718,7 @@ var defnSpecialExpression = {
4640
4718
  var _b;
4641
4719
  var _c, _d;
4642
4720
  var builtin = _a.builtin, evaluateAstNode = _a.evaluateAstNode;
4643
- var name = getFunctionName('defn', node, contextStack, evaluateAstNode);
4721
+ var name = node.f.v;
4644
4722
  assertNameNotDefined(name, contextStack, builtin, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
4645
4723
  var evaluatedFunctionOverloades = evaluateFunctionOverloades(node, contextStack, evaluateAstNode);
4646
4724
  var litsFunction = (_b = {},
@@ -4650,64 +4728,17 @@ var defnSpecialExpression = {
4650
4728
  _b.n = name,
4651
4729
  _b.o = evaluatedFunctionOverloades,
4652
4730
  _b);
4653
- contextStack.globalContext[name] = { value: litsFunction };
4731
+ contextStack.exportValue(name, litsFunction);
4654
4732
  return null;
4655
4733
  },
4656
4734
  findUnresolvedIdentifiers: function (node, contextStack, _a) {
4657
4735
  var _b;
4658
4736
  var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
4659
- contextStack.globalContext[node.f.v] = { value: true };
4737
+ contextStack.exportValue(node.f.v, true);
4660
4738
  var newContext = (_b = {}, _b[node.f.v] = { value: true }, _b);
4661
4739
  return addOverloadsUnresolvedIdentifiers(node.o, contextStack, findUnresolvedIdentifiers, builtin, newContext);
4662
4740
  },
4663
4741
  };
4664
- var defnsSpecialExpression = {
4665
- polishParse: function (tokenStream, parseState, firstToken, parsers) {
4666
- var parseToken = parsers.parseToken;
4667
- var functionName = parseToken(tokenStream, parseState);
4668
- var functionOverloades = parseFunctionOverloades(tokenStream, parseState, parsers);
4669
- assertRParenToken(tokenStream.tokens[parseState.position++]);
4670
- var node = {
4671
- t: AstNodeType.SpecialExpression,
4672
- n: 'defns',
4673
- p: [],
4674
- f: functionName,
4675
- o: functionOverloades,
4676
- token: getTokenDebugData(firstToken) && firstToken,
4677
- };
4678
- return node;
4679
- },
4680
- validateParameterCount: function () { return undefined; },
4681
- evaluate: function (node, contextStack, _a) {
4682
- var _b;
4683
- var _c, _d;
4684
- var builtin = _a.builtin, evaluateAstNode = _a.evaluateAstNode;
4685
- var name = getFunctionName('defns', node, contextStack, evaluateAstNode);
4686
- assertNameNotDefined(name, contextStack, builtin, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
4687
- var evaluatedFunctionOverloades = evaluateFunctionOverloades(node, contextStack, evaluateAstNode);
4688
- var litsFunction = (_b = {},
4689
- _b[FUNCTION_SYMBOL] = true,
4690
- _b.sourceCodeInfo = (_d = getTokenDebugData(node.token)) === null || _d === void 0 ? void 0 : _d.sourceCodeInfo,
4691
- _b.t = FunctionType.UserDefined,
4692
- _b.n = name,
4693
- _b.o = evaluatedFunctionOverloades,
4694
- _b);
4695
- contextStack.globalContext[name] = { value: litsFunction };
4696
- return null;
4697
- },
4698
- findUnresolvedIdentifiers: function (node, contextStack, _a) {
4699
- var _b;
4700
- var _c;
4701
- var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin, evaluateAstNode = _a.evaluateAstNode;
4702
- var sourceCodeInfo = (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo;
4703
- var name = evaluateAstNode(asAstNode(node.f, sourceCodeInfo), contextStack);
4704
- assertString(name, sourceCodeInfo);
4705
- assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
4706
- contextStack.globalContext[name] = { value: true };
4707
- var newContext = (_b = {}, _b[name] = { value: true }, _b);
4708
- return addOverloadsUnresolvedIdentifiers(node.o, contextStack, findUnresolvedIdentifiers, builtin, newContext);
4709
- },
4710
- };
4711
4742
  var fnSpecialExpression = {
4712
4743
  polishParse: function (tokenStream, parseState, firstToken, parsers) {
4713
4744
  var functionOverloades = parseFunctionOverloades(tokenStream, parseState, parsers);
@@ -4741,14 +4772,6 @@ var fnSpecialExpression = {
4741
4772
  return addOverloadsUnresolvedIdentifiers(node.o, contextStack, findUnresolvedIdentifiers, builtin);
4742
4773
  },
4743
4774
  };
4744
- function getFunctionName(expressionName, node, contextStack, evaluateAstNode) {
4745
- var _a;
4746
- var sourceCodeInfo = (_a = getTokenDebugData(node.token)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo;
4747
- if (expressionName === 'defn')
4748
- return (node.f).v;
4749
- var name = evaluateAstNode(node.f, contextStack);
4750
- return asString(name, sourceCodeInfo);
4751
- }
4752
4775
  function evaluateFunctionOverloades(node, contextStack, evaluateAstNode) {
4753
4776
  var e_1, _a, e_2, _b;
4754
4777
  var evaluatedFunctionOverloades = [];
@@ -4976,56 +4999,8 @@ var ifSpecialExpression = {
4976
4999
  },
4977
5000
  };
4978
5001
 
4979
- var ifLetSpecialExpression = {
4980
- polishParse: function (tokenStream, parseState, firstToken, _a) {
4981
- var _b, _c;
4982
- var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4983
- var bindings = parseBindings(tokenStream, parseState);
4984
- if (bindings.length !== 1) {
4985
- throw new LitsError("Expected exactly one binding, got ".concat(valueToString(bindings.length)), (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
4986
- }
4987
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4988
- assertRParenToken(tokenStream.tokens[parseState.position++]);
4989
- var node = {
4990
- t: AstNodeType.SpecialExpression,
4991
- n: 'if_let',
4992
- b: asNonUndefined(bindings[0], (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo),
4993
- p: params,
4994
- token: getTokenDebugData(firstToken) && firstToken,
4995
- };
4996
- return node;
4997
- },
4998
- validateParameterCount: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
4999
- evaluate: function (node, contextStack, _a) {
5000
- var _b;
5001
- var evaluateAstNode = _a.evaluateAstNode;
5002
- var sourceCodeInfo = (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo;
5003
- var locals = {};
5004
- var bindingValue = evaluateAstNode(node.b.v, contextStack);
5005
- if (bindingValue) {
5006
- locals[node.b.n] = { value: bindingValue };
5007
- var newContextStack = contextStack.create(locals);
5008
- var thenForm = asAstNode(node.p[0], sourceCodeInfo);
5009
- return evaluateAstNode(thenForm, newContextStack);
5010
- }
5011
- if (node.p.length === 2) {
5012
- var elseForm = asAstNode(node.p[1], sourceCodeInfo);
5013
- return evaluateAstNode(elseForm, contextStack);
5014
- }
5015
- return null;
5016
- },
5017
- findUnresolvedIdentifiers: function (node, contextStack, _a) {
5018
- var _b;
5019
- var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
5020
- var newContext = (_b = {}, _b[node.b.n] = { value: true }, _b);
5021
- var bindingResult = findUnresolvedIdentifiers([node.b.v], contextStack, builtin);
5022
- var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
5023
- return joinAnalyzeResults(bindingResult, paramsResult);
5024
- },
5025
- };
5026
-
5027
- var ifNotSpecialExpression = {
5028
- polishParse: getCommonPolishSpecialExpressionParser('if_not'),
5002
+ var unlessSpecialExpression = {
5003
+ polishParse: getCommonPolishSpecialExpressionParser('unless'),
5029
5004
  validateParameterCount: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
5030
5005
  evaluate: function (node, contextStack, _a) {
5031
5006
  var _b;
@@ -5050,55 +5025,39 @@ var ifNotSpecialExpression = {
5050
5025
 
5051
5026
  var letSpecialExpression = {
5052
5027
  polishParse: function (tokenStream, parseState, firstToken, _a) {
5053
- var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5028
+ var parseBindings = _a.parseBindings;
5054
5029
  var bindings = parseBindings(tokenStream, parseState);
5055
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5030
+ // const params = parseTokensUntilClosingBracket(tokenStream, parseState)
5056
5031
  assertRParenToken(tokenStream.tokens[parseState.position++]);
5057
5032
  var node = {
5058
5033
  t: AstNodeType.SpecialExpression,
5059
5034
  n: 'let',
5060
- p: params,
5035
+ p: [],
5061
5036
  bs: bindings,
5062
5037
  token: getTokenDebugData(firstToken) && firstToken,
5063
5038
  };
5064
5039
  return node;
5065
5040
  },
5066
- validateParameterCount: function () { return undefined; },
5041
+ validateParameterCount: function (node) { return assertNumberOfParams(0, node); },
5067
5042
  evaluate: function (node, contextStack, _a) {
5068
- var e_1, _b, e_2, _c;
5043
+ var e_1, _b;
5069
5044
  var evaluateAstNode = _a.evaluateAstNode;
5070
- var locals = {};
5071
- var newContextStack = contextStack.create(locals);
5072
5045
  try {
5073
- for (var _d = __values(node.bs), _e = _d.next(); !_e.done; _e = _d.next()) {
5074
- var binding = _e.value;
5046
+ for (var _c = __values(node.bs), _d = _c.next(); !_d.done; _d = _c.next()) {
5047
+ var binding = _d.value;
5075
5048
  var bindingValueNode = binding.v;
5076
- var bindingValue = evaluateAstNode(bindingValueNode, newContextStack);
5077
- locals[binding.n] = { value: bindingValue };
5049
+ var bindingValue = evaluateAstNode(bindingValueNode, contextStack);
5050
+ contextStack.addValue(binding.n, bindingValue);
5078
5051
  }
5079
5052
  }
5080
5053
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
5081
5054
  finally {
5082
5055
  try {
5083
- if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
5056
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
5084
5057
  }
5085
5058
  finally { if (e_1) throw e_1.error; }
5086
5059
  }
5087
- var result = null;
5088
- try {
5089
- for (var _f = __values(node.p), _g = _f.next(); !_g.done; _g = _f.next()) {
5090
- var astNode = _g.value;
5091
- result = evaluateAstNode(astNode, newContextStack);
5092
- }
5093
- }
5094
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
5095
- finally {
5096
- try {
5097
- if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
5098
- }
5099
- finally { if (e_2) throw e_2.error; }
5100
- }
5101
- return result;
5060
+ return null;
5102
5061
  },
5103
5062
  findUnresolvedIdentifiers: function (node, contextStack, _a) {
5104
5063
  var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
@@ -5108,11 +5067,10 @@ var letSpecialExpression = {
5108
5067
  context[name] = { value: true };
5109
5068
  return context;
5110
5069
  }, {});
5111
- var bindingContext = {};
5112
5070
  var bindingResults = node.bs.map(function (bindingNode) {
5113
5071
  var valueNode = bindingNode.v;
5114
- var bindingsResult = findUnresolvedIdentifiers([valueNode], contextStack.create(bindingContext), builtin);
5115
- bindingContext[bindingNode.n] = { value: true };
5072
+ var bindingsResult = findUnresolvedIdentifiers([valueNode], contextStack, builtin);
5073
+ contextStack.addValue(bindingNode.n, { value: true });
5116
5074
  return bindingsResult;
5117
5075
  });
5118
5076
  var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
@@ -5563,9 +5521,10 @@ var trySpecialExpression = {
5563
5521
  return evaluateAstNode(tryExpressions[0], contextStack);
5564
5522
  }
5565
5523
  catch (error) {
5566
- var newContext = (_b = {},
5567
- _b[errorNode.v] = { value: asAny(error, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo) },
5568
- _b);
5524
+ var newContext = errorNode
5525
+ ? (_b = {},
5526
+ _b[errorNode.v] = { value: asAny(error, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo) },
5527
+ _b) : {};
5569
5528
  return evaluateAstNode(catchExpression, contextStack.create(newContext));
5570
5529
  }
5571
5530
  },
@@ -5574,199 +5533,15 @@ var trySpecialExpression = {
5574
5533
  var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
5575
5534
  var tryExpressions = node.p, catchExpression = node.ce, errorNode = node.e;
5576
5535
  var tryResult = findUnresolvedIdentifiers(tryExpressions, contextStack, builtin);
5577
- var newContext = (_b = {},
5578
- _b[errorNode.v] = { value: true },
5579
- _b);
5536
+ var newContext = errorNode
5537
+ ? (_b = {},
5538
+ _b[errorNode.v] = { value: true },
5539
+ _b) : {};
5580
5540
  var catchResult = findUnresolvedIdentifiers([catchExpression], contextStack.create(newContext), builtin);
5581
5541
  return joinAnalyzeResults(tryResult, catchResult);
5582
5542
  },
5583
5543
  };
5584
5544
 
5585
- var whenSpecialExpression = {
5586
- polishParse: getCommonPolishSpecialExpressionParser('when'),
5587
- validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
5588
- evaluate: function (node, contextStack, _a) {
5589
- var e_1, _b;
5590
- var _c;
5591
- var evaluateAstNode = _a.evaluateAstNode;
5592
- var _d = __read(node.p), whenExpression = _d[0], body = _d.slice(1);
5593
- assertAstNode(whenExpression, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
5594
- if (!evaluateAstNode(whenExpression, contextStack))
5595
- return null;
5596
- var result = null;
5597
- try {
5598
- for (var body_1 = __values(body), body_1_1 = body_1.next(); !body_1_1.done; body_1_1 = body_1.next()) {
5599
- var form = body_1_1.value;
5600
- result = evaluateAstNode(form, contextStack);
5601
- }
5602
- }
5603
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
5604
- finally {
5605
- try {
5606
- if (body_1_1 && !body_1_1.done && (_b = body_1.return)) _b.call(body_1);
5607
- }
5608
- finally { if (e_1) throw e_1.error; }
5609
- }
5610
- return result;
5611
- },
5612
- findUnresolvedIdentifiers: function (node, contextStack, _a) {
5613
- var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
5614
- return findUnresolvedIdentifiers(node.p, contextStack, builtin);
5615
- },
5616
- };
5617
-
5618
- var whenFirstSpecialExpression = {
5619
- polishParse: function (tokenStream, parseState, firstToken, _a) {
5620
- var _b, _c;
5621
- var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5622
- var bindings = parseBindings(tokenStream, parseState);
5623
- if (bindings.length !== 1) {
5624
- throw new LitsError("Expected exactly one binding, got ".concat(valueToString(bindings.length)), (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
5625
- }
5626
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5627
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5628
- var node = {
5629
- t: AstNodeType.SpecialExpression,
5630
- n: 'when_first',
5631
- b: asNonUndefined(bindings[0], (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo),
5632
- p: params,
5633
- token: getTokenDebugData(firstToken) && firstToken,
5634
- };
5635
- return node;
5636
- },
5637
- validateParameterCount: function () { return undefined; },
5638
- evaluate: function (node, contextStack, _a) {
5639
- var e_1, _b;
5640
- var _c;
5641
- var evaluateAstNode = _a.evaluateAstNode;
5642
- var locals = {};
5643
- var binding = node.b;
5644
- var evaluatedBindingForm = evaluateAstNode(binding.v, contextStack);
5645
- if (!isSeq(evaluatedBindingForm)) {
5646
- throw new LitsError("Expected undefined or a sequence, got ".concat(valueToString(evaluatedBindingForm)), (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
5647
- }
5648
- if (evaluatedBindingForm.length === 0)
5649
- return null;
5650
- var bindingValue = toAny(evaluatedBindingForm[0]);
5651
- locals[binding.n] = { value: bindingValue };
5652
- var newContextStack = contextStack.create(locals);
5653
- var result = null;
5654
- try {
5655
- for (var _d = __values(node.p), _e = _d.next(); !_e.done; _e = _d.next()) {
5656
- var form = _e.value;
5657
- result = evaluateAstNode(form, newContextStack);
5658
- }
5659
- }
5660
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
5661
- finally {
5662
- try {
5663
- if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
5664
- }
5665
- finally { if (e_1) throw e_1.error; }
5666
- }
5667
- return result;
5668
- },
5669
- findUnresolvedIdentifiers: function (node, contextStack, _a) {
5670
- var _b;
5671
- var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
5672
- var binding = node.b;
5673
- var newContext = (_b = {}, _b[binding.n] = { value: true }, _b);
5674
- var bindingResult = findUnresolvedIdentifiers([binding.v], contextStack, builtin);
5675
- var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
5676
- return joinAnalyzeResults(bindingResult, paramsResult);
5677
- },
5678
- };
5679
-
5680
- var whenLetSpecialExpression = {
5681
- polishParse: function (tokenStream, parseState, firstToken, _a) {
5682
- var _b, _c;
5683
- var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5684
- var bindings = parseBindings(tokenStream, parseState);
5685
- if (bindings.length !== 1) {
5686
- throw new LitsError("Expected exactly one binding, got ".concat(valueToString(bindings.length)), (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
5687
- }
5688
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5689
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5690
- var node = {
5691
- t: AstNodeType.SpecialExpression,
5692
- n: 'when_let',
5693
- b: asNonUndefined(bindings[0], (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo),
5694
- p: params,
5695
- token: getTokenDebugData(firstToken) && firstToken,
5696
- };
5697
- return node;
5698
- },
5699
- validateParameterCount: function () { return undefined; },
5700
- evaluate: function (node, contextStack, _a) {
5701
- var e_1, _b;
5702
- var evaluateAstNode = _a.evaluateAstNode;
5703
- var binding = node.b;
5704
- var locals = {};
5705
- var bindingValue = evaluateAstNode(binding.v, contextStack);
5706
- if (!bindingValue)
5707
- return null;
5708
- locals[binding.n] = { value: bindingValue };
5709
- var newContextStack = contextStack.create(locals);
5710
- var result = null;
5711
- try {
5712
- for (var _c = __values(node.p), _d = _c.next(); !_d.done; _d = _c.next()) {
5713
- var form = _d.value;
5714
- result = evaluateAstNode(form, newContextStack);
5715
- }
5716
- }
5717
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
5718
- finally {
5719
- try {
5720
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
5721
- }
5722
- finally { if (e_1) throw e_1.error; }
5723
- }
5724
- return result;
5725
- },
5726
- findUnresolvedIdentifiers: function (node, contextStack, _a) {
5727
- var _b;
5728
- var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
5729
- var binding = node.b;
5730
- var newContext = (_b = {}, _b[binding.n] = { value: true }, _b);
5731
- var bindingResult = findUnresolvedIdentifiers([binding.v], contextStack, builtin);
5732
- var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
5733
- return joinAnalyzeResults(bindingResult, paramsResult);
5734
- },
5735
- };
5736
-
5737
- var whenNotSpecialExpression = {
5738
- polishParse: getCommonPolishSpecialExpressionParser('when_not'),
5739
- validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
5740
- evaluate: function (node, contextStack, _a) {
5741
- var e_1, _b;
5742
- var _c;
5743
- var evaluateAstNode = _a.evaluateAstNode;
5744
- var _d = __read(node.p), whenExpression = _d[0], body = _d.slice(1);
5745
- assertAstNode(whenExpression, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
5746
- if (evaluateAstNode(whenExpression, contextStack))
5747
- return null;
5748
- var result = null;
5749
- try {
5750
- for (var body_1 = __values(body), body_1_1 = body_1.next(); !body_1_1.done; body_1_1 = body_1.next()) {
5751
- var form = body_1_1.value;
5752
- result = evaluateAstNode(form, contextStack);
5753
- }
5754
- }
5755
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
5756
- finally {
5757
- try {
5758
- if (body_1_1 && !body_1_1.done && (_b = body_1.return)) _b.call(body_1);
5759
- }
5760
- finally { if (e_1) throw e_1.error; }
5761
- }
5762
- return result;
5763
- },
5764
- findUnresolvedIdentifiers: function (node, contextStack, _a) {
5765
- var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
5766
- return findUnresolvedIdentifiers(node.p, contextStack, builtin);
5767
- },
5768
- };
5769
-
5770
5545
  var specialExpressions = {
5771
5546
  '&&': andSpecialExpression,
5772
5547
  'comment': commentSpecialExpression,
@@ -5774,26 +5549,19 @@ var specialExpressions = {
5774
5549
  'switch': switchSpecialExpression,
5775
5550
  'def': defSpecialExpression,
5776
5551
  'defn': defnSpecialExpression,
5777
- 'defns': defnsSpecialExpression,
5778
- 'defs': defsSpecialExpression,
5779
5552
  'do': doSpecialExpression,
5780
5553
  'doseq': doseqSpecialExpression,
5781
5554
  'for': forSpecialExpression,
5782
5555
  'fn': fnSpecialExpression,
5783
5556
  'if': ifSpecialExpression,
5784
- 'if_let': ifLetSpecialExpression,
5785
- 'if_not': ifNotSpecialExpression,
5557
+ 'unless': unlessSpecialExpression,
5786
5558
  'let': letSpecialExpression,
5787
5559
  'loop': loopSpecialExpression,
5788
5560
  '||': orSpecialExpression,
5789
5561
  'recur': recurSpecialExpression,
5790
5562
  'throw': throwSpecialExpression,
5791
5563
  'try': trySpecialExpression,
5792
- 'when': whenSpecialExpression,
5793
- 'when_first': whenFirstSpecialExpression,
5794
- 'when_let': whenLetSpecialExpression,
5795
- 'when_not': whenNotSpecialExpression,
5796
- 'declared?': declaredSpecialExpression,
5564
+ 'defined?': declaredSpecialExpression,
5797
5565
  '??': qqSpecialExpression,
5798
5566
  };
5799
5567
  Object.keys(specialExpressions).forEach(function (key) {
@@ -5815,8 +5583,8 @@ function isContextEntry(value) {
5815
5583
  var ContextStackImpl = /** @class */ (function () {
5816
5584
  function ContextStackImpl(_a) {
5817
5585
  var contexts = _a.contexts, hostValues = _a.values, lazyHostValues = _a.lazyValues, nativeJsFunctions = _a.nativeJsFunctions;
5818
- this.contexts = contexts;
5819
5586
  this.globalContext = asNonUndefined(contexts[0]);
5587
+ this.contexts = contexts;
5820
5588
  this.values = hostValues;
5821
5589
  this.lazyValues = lazyHostValues;
5822
5590
  this.nativeJsFunctions = nativeJsFunctions;
@@ -5832,6 +5600,34 @@ var ContextStackImpl = /** @class */ (function () {
5832
5600
  contextStack.globalContext = globalContext;
5833
5601
  return contextStack;
5834
5602
  };
5603
+ ContextStackImpl.prototype.exportValue = function (name, value) {
5604
+ if (this.globalContext[name]) {
5605
+ throw new Error("Cannot redefine exported value \"".concat(name, "\""));
5606
+ }
5607
+ if (specialExpressionKeys.includes(name)) {
5608
+ throw new Error("Cannot shadow special expression \"".concat(name, "\""));
5609
+ }
5610
+ if (normalExpressionKeys.includes(name)) {
5611
+ throw new Error("Cannot shadow builtin function \"".concat(name, "\""));
5612
+ }
5613
+ this.globalContext[name] = { value: value };
5614
+ };
5615
+ ContextStackImpl.prototype.addValue = function (name, value) {
5616
+ var currentContext = this.contexts[0];
5617
+ if (!currentContext) {
5618
+ throw new Error('No context to add value to');
5619
+ }
5620
+ if (currentContext[name]) {
5621
+ throw new Error("Cannot redefine value \"".concat(name, "\""));
5622
+ }
5623
+ if (specialExpressionKeys.includes(name)) {
5624
+ throw new Error("Cannot shadow special expression \"".concat(name, "\""));
5625
+ }
5626
+ if (normalExpressionKeys.includes(name)) {
5627
+ throw new Error("Cannot shadow builtin function \"".concat(name, "\""));
5628
+ }
5629
+ currentContext[name] = { value: toAny(value) };
5630
+ };
5835
5631
  ContextStackImpl.prototype.clone = function () {
5836
5632
  // eslint-disable-next-line ts/no-unsafe-argument
5837
5633
  return new ContextStackImpl(JSON.parse(JSON.stringify({
@@ -5961,7 +5757,7 @@ function createContextStack(params) {
5961
5757
  return acc;
5962
5758
  }, {}),
5963
5759
  });
5964
- return contextStack;
5760
+ return contextStack.create({});
5965
5761
  }
5966
5762
 
5967
5763
  var _a$1;
@@ -6273,7 +6069,14 @@ function evaluateNumberAsFunction(fn, params, sourceCodeInfo) {
6273
6069
 
6274
6070
  var findUnresolvedIdentifiers = function (ast, contextStack, builtin) {
6275
6071
  var e_1, _a;
6276
- var astNodes = Array.isArray(ast) ? ast : ast.b;
6072
+ var astNodes = Array.isArray(ast)
6073
+ ? ast
6074
+ : [{
6075
+ t: AstNodeType.SpecialExpression,
6076
+ n: 'do',
6077
+ p: ast.b,
6078
+ token: undefined,
6079
+ }];
6277
6080
  var unresolvedIdentifiers = new Set();
6278
6081
  try {
6279
6082
  for (var astNodes_1 = __values(astNodes), astNodes_1_1 = astNodes_1.next(); !astNodes_1_1.done; astNodes_1_1 = astNodes_1.next()) {
@@ -6345,537 +6148,9 @@ function findUnresolvedIdentifiersInAstNode(astNode, contextStack, builtin) {
6345
6148
  }
6346
6149
  }
6347
6150
 
6348
- var calculateAndOutcomes = function (_a) {
6349
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
6350
- return combinateAstNodes(astNode.p)
6351
- .map(function (p) { return ({
6352
- n: '&&',
6353
- t: AstNodeType.SpecialExpression,
6354
- p: p,
6355
- token: astNode.token,
6356
- }); });
6357
- };
6358
-
6359
- var calculateCondOutcomes = function (_a) {
6360
- var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, isAstComputable = _a.isAstComputable;
6361
- var testNodes = arrayToPairs(astNode.p).map(function (_a) {
6362
- var _b = __read(_a, 1), t = _b[0];
6363
- return t;
6364
- });
6365
- if (isAstComputable(testNodes)) {
6366
- return combinate(arrayToPairs(astNode.p)
6367
- // Create a list of ast nodes from the test and form of each condition
6368
- .reduce(function (acc, _a) {
6369
- var _b = __read(_a, 2), test = _b[0], form = _b[1];
6370
- acc.push(calculatePossibleAstNodes(test), calculatePossibleAstNodes(form));
6371
- return acc;
6372
- }, []))
6373
- // Create a new CondNode for each combination of test and form outcomes
6374
- .map(function (conditionAsts) { return (__assign(__assign({}, astNode), { c: arrayToPairs(conditionAsts).map(function (_a) {
6375
- var _b = __read(_a, 2), t = _b[0], f = _b[1];
6376
- return ({ t: t, f: f });
6377
- }) })); });
6378
- }
6379
- return __spreadArray(__spreadArray([], __read(arrayToPairs(astNode.p).flatMap(function (_a) {
6380
- var _b = __read(_a, 2); _b[0]; var form = _b[1];
6381
- return calculatePossibleAstNodes(form);
6382
- })), false), [
6383
- nilNode,
6384
- ], false);
6385
- };
6386
-
6387
- var trueNode = { t: AstNodeType.ReservedSymbol, v: 'true', token: undefined, p: [], n: undefined };
6388
- var falseNode = { t: AstNodeType.ReservedSymbol, v: 'false', token: undefined, p: [], n: undefined };
6389
- var calculateDeclaredOutcomes = function (_a) {
6390
- var astNode = _a.astNode, isAstComputable = _a.isAstComputable;
6391
- if (isAstComputable(astNode.p))
6392
- return [trueNode];
6393
- return [trueNode, falseNode];
6394
- };
6395
-
6396
- var calculateDefOutcomes = function (_a) {
6397
- var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, addGlobalIdentifier = _a.addGlobalIdentifier;
6398
- var nameNode = asSymbolNode(astNode.p[0]);
6399
- var valueNode = astNode.p[1];
6400
- addGlobalIdentifier(nameNode.v);
6401
- return calculatePossibleAstNodes(valueNode)
6402
- .map(function (node) { return (__assign(__assign({}, astNode), { p: [nameNode, node] })); });
6403
- };
6404
-
6405
- var calculateDefsOutcomes = function (_a) {
6406
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
6407
- return combinateAstNodes(astNode.p)
6408
- .map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
6409
- };
6410
-
6411
- var calculateDoOutcomes = function (_a) {
6412
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
6413
- return combinateAstNodes(astNode.p).map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
6414
- };
6415
-
6416
- function calculateFunctionOverloadOutcomes(combinateAstNodes, functionOverloads) {
6417
- return combinate(functionOverloads
6418
- // For each overload, calculate the possible outcomes for each parameter
6419
- .map(function (functionOverload) {
6420
- var _a;
6421
- return combinateAstNodes(functionOverload.b, [
6422
- functionOverload.as.m,
6423
- functionOverload.as.b.map(function (bindingNode) { return bindingNode.n; }),
6424
- (_a = functionOverload.as.r) !== null && _a !== void 0 ? _a : [],
6425
- ].flat())
6426
- // For each combination of parameter outcomes, create a new overload
6427
- .map(function (body) { return (__assign(__assign({}, functionOverload), { b: body })); });
6428
- }));
6429
- }
6430
- var calculateDefnOutcomes = function (_a) {
6431
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, addGlobalIdentifier = _a.addGlobalIdentifier;
6432
- addGlobalIdentifier(astNode.f.v);
6433
- // astNode.o is an array of overloads
6434
- return calculateFunctionOverloadOutcomes(combinateAstNodes, astNode.o).map(function (functionOverloads) { return (__assign(__assign({}, astNode), { o: functionOverloads })); });
6435
- };
6436
- var calculateDefnsOutcomes = function (_a) {
6437
- var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes;
6438
- // astNode.o is an array of overloads
6439
- return calculatePossibleAstNodes(astNode.f).flatMap(function (functionName) {
6440
- return calculateFunctionOverloadOutcomes(combinateAstNodes, astNode.o).map(function (functionOverloads) { return (__assign(__assign({}, astNode), { f: functionName, o: functionOverloads })); });
6441
- });
6442
- };
6443
- var calculateFnOutcomes = function (_a) {
6444
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
6445
- // astNode.o is an array of overloads
6446
- return calculateFunctionOverloadOutcomes(combinateAstNodes, astNode.o).map(function (functionOverloads) { return (__assign(__assign({}, astNode), { o: functionOverloads })); });
6447
- };
6448
-
6449
- var calculateIfLetOutcomes = function (_a) {
6450
- var _b;
6451
- var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
6452
- var bindingNode = astNode.b;
6453
- var thenBranch = astNode.p[0];
6454
- var elseBranch = (_b = astNode.p[1]) !== null && _b !== void 0 ? _b : nilNode;
6455
- if (!isAstComputable(bindingNode.v)) {
6456
- return __spreadArray(__spreadArray([], __read(calculatePossibleAstNodes(thenBranch)), false), __read(calculatePossibleAstNodes(elseBranch)), false);
6457
- }
6458
- var newIdentifier = bindingNode.n;
6459
- return calculatePossibleAstNodes(bindingNode.v)
6460
- .map(function (bindingValue) { return (__assign(__assign({}, bindingNode), { v: bindingValue })); })
6461
- .flatMap(function (b) { return combinateAstNodes(astNode.p, [newIdentifier])
6462
- .map(function (p) { return (__assign(__assign({}, astNode), { b: b, p: p })); }); });
6463
- };
6464
-
6465
- var calculateIfNotOutcomes = function (_a) {
6466
- var _b;
6467
- var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
6468
- var condition = astNode.p[0];
6469
- var thenBranch = astNode.p[1];
6470
- var elseBranch = (_b = astNode.p[2]) !== null && _b !== void 0 ? _b : nilNode;
6471
- if (isAstComputable(condition)) {
6472
- return combinateAstNodes(astNode.p)
6473
- .map(function (p) { return ({
6474
- n: 'if_not',
6475
- t: astNode.t,
6476
- p: p,
6477
- token: astNode.token,
6478
- }); });
6479
- }
6480
- return __spreadArray(__spreadArray([], __read(calculatePossibleAstNodes(thenBranch)), false), __read(calculatePossibleAstNodes(elseBranch)), false);
6481
- };
6482
-
6483
- var calculateIfOutcomes = function (_a) {
6484
- var _b;
6485
- var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
6486
- var condition = astNode.p[0];
6487
- var thenBranch = astNode.p[1];
6488
- var elseBranch = (_b = astNode.p[2]) !== null && _b !== void 0 ? _b : nilNode;
6489
- if (isAstComputable(condition)) {
6490
- return combinateAstNodes(astNode.p)
6491
- .map(function (p) { return ({
6492
- n: 'if',
6493
- t: astNode.t,
6494
- p: p,
6495
- token: astNode.token,
6496
- }); });
6497
- }
6498
- return __spreadArray(__spreadArray([], __read(calculatePossibleAstNodes(thenBranch)), false), __read(calculatePossibleAstNodes(elseBranch)), false);
6499
- };
6500
-
6501
- var calculateLetOutcomes = function (_a) {
6502
- var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
6503
- try {
6504
- // check bindings, if any binding value cannot be calculated, convert the whole let to a do-expression
6505
- if (!isAstComputable(astNode.bs.map(function (b) { return calculatePossibleAstNodes(b.v); })))
6506
- throw new Error('Could not calculate binding value');
6507
- }
6508
- catch (_b) {
6509
- var doNodes = combinateAstNodes(astNode.p)
6510
- .map(function (p) {
6511
- return {
6512
- n: 'do',
6513
- t: AstNodeType.SpecialExpression,
6514
- p: p,
6515
- token: astNode.token,
6516
- };
6517
- });
6518
- return doNodes;
6519
- }
6520
- var newIdentifiers = astNode.bs.map(function (bindingNode) { return bindingNode.n; });
6521
- var letNodes = combinate(astNode.bs.map(function (bindingNode) {
6522
- return calculatePossibleAstNodes(bindingNode.v)
6523
- .map(function (bindingValues) { return (__assign(__assign({}, bindingNode), { v: bindingValues })); });
6524
- }))
6525
- .flatMap(function (bindingNodes) { return combinate(astNode.p.map(function (p) { return calculatePossibleAstNodes(p, newIdentifiers); }))
6526
- .map(function (p) {
6527
- return {
6528
- n: 'let',
6529
- bs: bindingNodes,
6530
- t: AstNodeType.SpecialExpression,
6531
- p: p,
6532
- token: astNode.token,
6533
- };
6534
- }); });
6535
- return letNodes;
6536
- };
6537
-
6538
- var calculateForOutcomes = function (_a) {
6539
- var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
6540
- if (!isDeterministic(calculatePossibleAstNodes, astNode))
6541
- throw new Error('Could not calculate for loop, not deterministic');
6542
- return [astNode];
6543
- };
6544
- var calculateDoSeqOutcomes = function (_a) {
6545
- var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
6546
- if (!isDeterministic(calculatePossibleAstNodes, astNode))
6547
- throw new Error('Could not calculate doSeq node, not deterministic');
6548
- return [astNode];
6549
- };
6550
- function isDeterministic(calculatePossibleAstNodes, astNode) {
6551
- var e_1, _a;
6552
- try {
6553
- for (var _b = __values(astNode.l), _c = _b.next(); !_c.done; _c = _b.next()) {
6554
- var _d = _c.value, b = _d.b, l = _d.l, wn = _d.wn, we = _d.we;
6555
- if (l && l.some(function (_a) {
6556
- var v = _a.v;
6557
- return !astIsDeterministic(calculatePossibleAstNodes, v);
6558
- }))
6559
- return false;
6560
- if (!astIsDeterministic(calculatePossibleAstNodes, b.v))
6561
- return false;
6562
- if (wn && !astIsDeterministic(calculatePossibleAstNodes, wn))
6563
- return false;
6564
- if (we && !astIsDeterministic(calculatePossibleAstNodes, we))
6565
- return false;
6566
- }
6567
- }
6568
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
6569
- finally {
6570
- try {
6571
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
6572
- }
6573
- finally { if (e_1) throw e_1.error; }
6574
- }
6575
- if (!astIsDeterministic(calculatePossibleAstNodes, astNode.p[0]))
6576
- return false;
6577
- return true;
6578
- }
6579
- function astIsDeterministic(calculatePossibleAstNodes, astNode) {
6580
- return calculatePossibleAstNodes(astNode).length === 1;
6581
- }
6582
-
6583
- var calculateOrOutcomes = function (_a) {
6584
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
6585
- return combinateAstNodes(astNode.p)
6586
- .map(function (p) { return ({
6587
- n: '||',
6588
- t: AstNodeType.SpecialExpression,
6589
- p: p,
6590
- token: astNode.token,
6591
- }); });
6592
- };
6593
-
6594
- var calculateQqOutcomes = function (_a) {
6595
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
6596
- if (!isAstComputable(astNode.p[0]))
6597
- throw new Error('First argument of ?? not computable');
6598
- return combinateAstNodes(astNode.p)
6599
- .map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
6600
- };
6601
-
6602
- var calculateThrowOutcomes = function (_a) {
6603
- var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
6604
- return calculatePossibleAstNodes(astNode.p[0]).map(function (m) { return (__assign(__assign({}, astNode), { p: [m] })); });
6605
- };
6606
-
6607
- var calculateTryOutcomes = function (_a) {
6608
- var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
6609
- var _b = calculatePossibleAstNodes(astNode.p[0]).reduce(function (acc, node) {
6610
- if (node.n === 'throw') {
6611
- acc.throws.push(node.p[0]);
6612
- }
6613
- else {
6614
- acc.vals.push(node);
6615
- }
6616
- return acc;
6617
- }, { vals: [], throws: [] }), vals = _b.vals, throws = _b.throws;
6618
- var catches = throws.flatMap(function (throwNode) {
6619
- var letNode = {
6620
- t: AstNodeType.SpecialExpression,
6621
- n: 'let',
6622
- bs: [{
6623
- t: AstNodeType.Binding,
6624
- n: astNode.e.v,
6625
- v: throwNode,
6626
- token: undefined,
6627
- p: [],
6628
- }],
6629
- p: [astNode.ce],
6630
- token: undefined,
6631
- };
6632
- return calculatePossibleAstNodes(letNode);
6633
- });
6634
- return __spreadArray(__spreadArray([], __read(vals), false), __read(catches), false);
6635
- };
6636
-
6637
- var calculateWhenFirstOutcomes = function (_a) {
6638
- var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
6639
- var bindingNode = astNode.b;
6640
- if (!isAstComputable(bindingNode.v))
6641
- throw new Error('Could not calculate binding value');
6642
- var newIdentifier = bindingNode.n;
6643
- return calculatePossibleAstNodes(bindingNode.v)
6644
- .map(function (bindingValue) { return (__assign(__assign({}, bindingNode), { v: bindingValue })); })
6645
- .flatMap(function (b) {
6646
- return combinateAstNodes(astNode.p, [newIdentifier])
6647
- .map(function (p) { return (__assign(__assign({}, astNode), { b: b, p: p })); });
6648
- });
6649
- };
6650
-
6651
- var calculateWhenLetOutcomes = function (_a) {
6652
- var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
6653
- var bindingNode = astNode.b;
6654
- if (!isAstComputable(bindingNode.v)) {
6655
- return __spreadArray(__spreadArray([], __read(combinateAstNodes(astNode.p)
6656
- .map(function (p) { return ({
6657
- n: 'do',
6658
- t: astNode.t,
6659
- p: p,
6660
- token: astNode.token,
6661
- }); })), false), [
6662
- nilNode,
6663
- ], false);
6664
- }
6665
- var newIdentifier = bindingNode.n;
6666
- return calculatePossibleAstNodes(bindingNode.v)
6667
- .map(function (bindingValue) { return (__assign(__assign({}, bindingNode), { v: bindingValue })); })
6668
- .flatMap(function (b) {
6669
- return combinateAstNodes(astNode.p, [newIdentifier])
6670
- .map(function (p) { return (__assign(__assign({}, astNode), { b: b, p: p })); });
6671
- });
6672
- };
6673
-
6674
- var calculateWhenNotOutcomes = function (_a) {
6675
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, nilNode = _a.nilNode, isAstComputable = _a.isAstComputable;
6676
- var condition = astNode.p[0];
6677
- if (isAstComputable(condition)) {
6678
- return combinateAstNodes(astNode.p)
6679
- .map(function (p) { return ({
6680
- n: 'when_not',
6681
- t: astNode.t,
6682
- p: p,
6683
- token: astNode.token,
6684
- }); });
6685
- }
6686
- var body = astNode.p.slice(1);
6687
- return __spreadArray(__spreadArray([], __read(combinateAstNodes(body)
6688
- .map(function (p) { return ({
6689
- n: 'do',
6690
- t: astNode.t,
6691
- p: p,
6692
- token: astNode.token,
6693
- }); })), false), [
6694
- nilNode,
6695
- ], false);
6696
- };
6697
-
6698
- var calculateWhenOutcomes = function (_a) {
6699
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, nilNode = _a.nilNode, isAstComputable = _a.isAstComputable;
6700
- var condition = astNode.p[0];
6701
- if (isAstComputable(condition)) {
6702
- return combinateAstNodes(astNode.p)
6703
- .map(function (p) { return ({
6704
- n: 'when',
6705
- t: astNode.t,
6706
- p: p,
6707
- token: astNode.token,
6708
- }); });
6709
- }
6710
- var body = astNode.p.slice(1);
6711
- return __spreadArray(__spreadArray([], __read(combinateAstNodes(body)
6712
- .map(function (p) { return ({
6713
- n: 'do',
6714
- t: astNode.t,
6715
- p: p,
6716
- token: astNode.token,
6717
- }); })), false), [
6718
- nilNode,
6719
- ], false);
6720
- };
6721
-
6722
- var calculateRecurOutcomes = function (_a) {
6723
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
6724
- return combinateAstNodes(astNode.p)
6725
- .map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
6726
- };
6727
-
6728
- var calculateCommentOutcomes = function (_a) {
6729
- var nilNode = _a.nilNode;
6730
- return [nilNode];
6731
- };
6732
-
6733
- var calculateLoopOutcomes = function (_a) {
6734
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
6735
- return combinateAstNodes(astNode.p, astNode.bs.map(function (bindingNode) { return bindingNode.n; }))
6736
- .map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
6737
- };
6738
-
6739
- var calculateSwitchOutcomes = function (_a) {
6740
- var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
6741
- // TODO be smarter about this
6742
- return __spreadArray(__spreadArray([], __read(arrayToPairs(astNode.p.slice(1)).flatMap(function (_a) {
6743
- var _b = __read(_a, 2); _b[0]; var form = _b[1];
6744
- return calculatePossibleAstNodes(form);
6745
- })), false), [
6746
- nilNode,
6747
- ], false);
6748
- };
6749
-
6750
- var specialExpressionCalculator = {
6751
- '&&': function (astNode, helperOptions) { return calculateAndOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6752
- 'comment': function (astNode, helperOptions) { return calculateCommentOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6753
- 'cond': function (astNode, helperOptions) { return calculateCondOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6754
- 'switch': function (astNode, helperOptions) { return calculateSwitchOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6755
- 'declared?': function (astNode, helperOptions) { return calculateDeclaredOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6756
- 'defn': function (astNode, helperOptions) { return calculateDefnOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6757
- 'def': function (astNode, helperOptions) { return calculateDefOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6758
- 'defns': function (astNode, helperOptions) { return calculateDefnsOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6759
- 'defs': function (astNode, helperOptions) { return calculateDefsOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6760
- 'do': function (astNode, helperOptions) { return calculateDoOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6761
- 'doseq': function (astNode, helperOptions) { return calculateDoSeqOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6762
- 'fn': function (astNode, helperOptions) { return calculateFnOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6763
- 'for': function (astNode, helperOptions) { return calculateForOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6764
- 'if_let': function (astNode, helperOptions) { return calculateIfLetOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6765
- 'if': function (astNode, helperOptions) { return calculateIfOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6766
- 'if_not': function (astNode, helperOptions) { return calculateIfNotOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6767
- 'let': function (astNode, helperOptions) { return calculateLetOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6768
- 'loop': function (astNode, helperOptions) { return calculateLoopOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6769
- '||': function (astNode, helperOptions) { return calculateOrOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6770
- '??': function (astNode, helperOptions) { return calculateQqOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6771
- 'recur': function (astNode, helperOptions) { return calculateRecurOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6772
- 'throw': function (astNode, helperOptions) { return calculateThrowOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6773
- 'try': function (astNode, helperOptions) { return calculateTryOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6774
- 'when_first': function (astNode, helperOptions) { return calculateWhenFirstOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6775
- 'when_let': function (astNode, helperOptions) { return calculateWhenLetOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6776
- 'when': function (astNode, helperOptions) { return calculateWhenOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6777
- 'when_not': function (astNode, helperOptions) { return calculateWhenNotOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6778
- };
6779
-
6780
- function calculateOutcomes(contextStack, astNodes) {
6781
- // First, we try to calculate outcomes for the whole astNodes array.
6782
- // If that fails, we try to calculate outcomes for the array without the first element.
6783
- // If that fails, we try to calculate outcomes for the array without the first two elements.
6784
- // And so on.
6785
- // This makes it possible to calculate outcomes for e.g.
6786
- // (write! x) x
6787
- // Problems occur for e.g.
6788
- // (def x 1) (write! x) x
6789
- // This should output [1], but since (write! x) fails to calculate outcomes, we get null.
6790
- // Ok, but not optimal
6791
- // The contract is that when an array is returned, it must be correct.
6792
- // But returning null (indicating that the calculation failed) is always a way out.
6793
- for (var i = 0; i < astNodes.length; i++) {
6794
- var usingAstNode = astNodes.slice(i);
6795
- var outcomes = calculateOutcomesInner(contextStack, usingAstNode);
6796
- if (outcomes !== null)
6797
- return outcomes;
6798
- }
6799
- return null;
6800
- }
6801
- function calculateOutcomesInner(contextStack, astNodes) {
6802
- var e_1, _a;
6803
- var possibleAsts = calculatePossibleAsts(contextStack.clone(), astNodes);
6804
- if (possibleAsts === null)
6805
- return null;
6806
- var outcomes = [];
6807
- try {
6808
- for (var possibleAsts_1 = __values(possibleAsts), possibleAsts_1_1 = possibleAsts_1.next(); !possibleAsts_1_1.done; possibleAsts_1_1 = possibleAsts_1.next()) {
6809
- var possibleAst = possibleAsts_1_1.value;
6810
- var unresolvedIdentifiers = findUnresolvedIdentifiers(possibleAst, contextStack.clone(), builtin);
6811
- if (unresolvedIdentifiers.size !== 0)
6812
- return null;
6813
- var ast = {
6814
- b: possibleAst,
6815
- hasDebugData: true,
6816
- };
6817
- try {
6818
- outcomes.push(evaluate(ast, contextStack.clone()));
6819
- }
6820
- catch (e) {
6821
- outcomes.push(e);
6822
- }
6823
- }
6824
- }
6825
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
6826
- finally {
6827
- try {
6828
- if (possibleAsts_1_1 && !possibleAsts_1_1.done && (_a = possibleAsts_1.return)) _a.call(possibleAsts_1);
6829
- }
6830
- finally { if (e_1) throw e_1.error; }
6831
- }
6832
- return outcomes;
6833
- }
6834
- function calculatePossibleAsts(contextStack, astNodes) {
6835
- var possibleAsts;
6836
- try {
6837
- possibleAsts = combinate(astNodes.map(function (astNode) { return calculatePossibleAstNodes(contextStack, astNode); }));
6838
- }
6839
- catch (e) {
6840
- return null;
6841
- }
6842
- return possibleAsts;
6843
- }
6844
- var nilNode = { t: AstNodeType.ReservedSymbol, v: 'nil', token: undefined, p: [], n: undefined };
6845
- function calculatePossibleAstNodes(contextStack, astNode, newIndentifiers) {
6846
- var newContext = newIndentifiers
6847
- ? newIndentifiers.reduce(function (acc, identity) {
6848
- acc[identity] = { value: null };
6849
- return acc;
6850
- }, {})
6851
- : undefined;
6852
- var newContextStack = newContext ? contextStack.create(newContext) : contextStack;
6853
- if (astNode.t === AstNodeType.NormalExpression) {
6854
- return combinate(astNode.p.map(function (n) { return calculatePossibleAstNodes(newContextStack, n); }))
6855
- .map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
6856
- }
6857
- else if (astNode.t === AstNodeType.SpecialExpression) {
6858
- var helperOptions = {
6859
- nilNode: nilNode,
6860
- calculatePossibleAstNodes: function (node, identifiers) { return calculatePossibleAstNodes(newContextStack.clone(), node, identifiers); },
6861
- combinateAstNodes: function (nodes, identifiers) {
6862
- return combinate(nodes.map(function (node) { return calculatePossibleAstNodes(newContextStack.clone(), node, identifiers); }));
6863
- },
6864
- isAstComputable: function (node) {
6865
- return calculateOutcomesInner(newContextStack, Array.isArray(node) ? node.flat() : [node]) !== null;
6866
- },
6867
- addGlobalIdentifier: function (name) { return newContextStack.globalContext[name] = { value: null }; },
6868
- };
6869
- // eslint-disable-next-line ts/no-unsafe-argument
6870
- return specialExpressionCalculator[astNode.n](astNode, helperOptions);
6871
- }
6872
- return [astNode];
6873
- }
6874
-
6875
6151
  function analyze(ast, params) {
6876
6152
  return {
6877
6153
  unresolvedIdentifiers: findUnresolvedIdentifiers(ast, createContextStack(params), builtin),
6878
- outcomes: calculateOutcomes(createContextStack(params), ast.b),
6879
6154
  };
6880
6155
  }
6881
6156
 
@@ -6998,6 +6273,33 @@ function parseString(tokenStream, parseState) {
6998
6273
  token: getTokenDebugData(tkn) && tkn,
6999
6274
  };
7000
6275
  }
6276
+ function parseRegexpShorthand(tokenStream, parseState) {
6277
+ var tkn = asRegexpShorthandToken(tokenStream.tokens[parseState.position++]);
6278
+ var endStringPosition = tkn[1].lastIndexOf('"');
6279
+ var regexpString = tkn[1].substring(2, endStringPosition);
6280
+ var optionsString = tkn[1].substring(endStringPosition + 1);
6281
+ var stringNode = {
6282
+ t: AstNodeType.String,
6283
+ v: regexpString,
6284
+ p: [],
6285
+ n: undefined,
6286
+ token: getTokenDebugData(tkn) && tkn,
6287
+ };
6288
+ var optionsNode = {
6289
+ t: AstNodeType.String,
6290
+ v: optionsString,
6291
+ p: [],
6292
+ n: undefined,
6293
+ token: getTokenDebugData(tkn) && tkn,
6294
+ };
6295
+ var node = {
6296
+ t: AstNodeType.NormalExpression,
6297
+ n: 'regexp',
6298
+ p: [stringNode, optionsNode],
6299
+ token: getTokenDebugData(tkn) && tkn,
6300
+ };
6301
+ return node;
6302
+ }
7001
6303
 
7002
6304
  var exponentiationPrecedence = 10;
7003
6305
  var binaryFunctionalOperatorPrecedence = 1;
@@ -7139,6 +6441,12 @@ var AlgebraicParser = /** @class */ (function () {
7139
6441
  this.tokenStream = tokenStream;
7140
6442
  this.parseState = parseState;
7141
6443
  }
6444
+ AlgebraicParser.prototype.peek = function () {
6445
+ return this.tokenStream.tokens[this.parseState.position];
6446
+ };
6447
+ AlgebraicParser.prototype.peekAhead = function (count) {
6448
+ return this.tokenStream.tokens[this.parseState.position + count];
6449
+ };
7142
6450
  AlgebraicParser.prototype.advance = function () {
7143
6451
  this.parseState.position += 1;
7144
6452
  };
@@ -7157,38 +6465,45 @@ var AlgebraicParser = /** @class */ (function () {
7157
6465
  var _a;
7158
6466
  if (precedence === void 0) { precedence = 0; }
7159
6467
  var firstToken = this.peek();
7160
- if (isA_SymbolToken(firstToken) && firstToken[1] === 'def') {
7161
- return this.parseDef(firstToken);
7162
- }
7163
- else if (isA_SymbolToken(firstToken) && firstToken[1] === 'defn') {
7164
- return this.parseDefn(firstToken);
7165
- }
7166
6468
  var left;
7167
- if (isA_SymbolToken(firstToken) && firstToken[1] === 'if') {
7168
- left = this.parseIf(firstToken);
7169
- }
7170
- else if (isA_SymbolToken(firstToken) && firstToken[1] === 'cond') {
7171
- left = this.parseCond(firstToken);
7172
- }
7173
- else if (isA_SymbolToken(firstToken) && firstToken[1] === 'switch') {
7174
- left = this.parseSwitch(firstToken);
6469
+ if (isA_SymbolToken(firstToken)) {
6470
+ switch (firstToken[1]) {
6471
+ case 'let':
6472
+ return this.parseLet(firstToken);
6473
+ case 'if':
6474
+ case 'unless':
6475
+ left = this.parseIfOrUnless(firstToken);
6476
+ break;
6477
+ case 'cond':
6478
+ left = this.parseCond(firstToken);
6479
+ break;
6480
+ case 'switch':
6481
+ left = this.parseSwitch(firstToken);
6482
+ break;
6483
+ case 'for':
6484
+ case 'doseq':
6485
+ left = this.parseForOrDoseq(firstToken);
6486
+ break;
6487
+ case 'do':
6488
+ left = this.parseDo(firstToken);
6489
+ break;
6490
+ case 'loop':
6491
+ left = this.parseLoop(firstToken);
6492
+ break;
6493
+ case 'try':
6494
+ left = this.parseTry(firstToken);
6495
+ break;
6496
+ }
7175
6497
  }
7176
- else if (isA_SymbolToken(firstToken) && firstToken[1] === 'for') {
7177
- left = this.parseFor(firstToken);
6498
+ else if (isA_ReservedSymbolToken(firstToken, 'function')) {
6499
+ return this.parseFunction(firstToken);
7178
6500
  }
7179
- else {
7180
- left = this.parseOperand();
6501
+ else if (isA_ReservedSymbolToken(firstToken, 'export')) {
6502
+ return this.parseExport(firstToken);
7181
6503
  }
6504
+ left || (left = this.parseOperand());
7182
6505
  var operator = this.peek();
7183
- while (!this.isAtEnd()
7184
- && !isA_OperatorToken(operator, ',')
7185
- && !isA_OperatorToken(operator, ';')
7186
- && !isRBracketToken(operator)
7187
- && !isA_ReservedSymbolToken(operator, 'else')
7188
- && !isA_ReservedSymbolToken(operator, 'then')
7189
- && !isA_ReservedSymbolToken(operator, 'end')
7190
- && !isA_ReservedSymbolToken(operator, 'case')
7191
- && !isRParenToken(operator)) {
6506
+ while (!this.isAtExpressionEnd()) {
7192
6507
  if (isA_BinaryOperatorToken(operator)) {
7193
6508
  var name_1 = operator[1];
7194
6509
  var newPrecedece = getPrecedence(name_1);
@@ -7317,10 +6632,18 @@ var AlgebraicParser = /** @class */ (function () {
7317
6632
  case 'String':
7318
6633
  return parseString(this.tokenStream, this.parseState);
7319
6634
  case 'A_Symbol': {
6635
+ var positionBefore = this.parseState.position;
6636
+ var lamdaFunction = this.parseLambdaFunction();
6637
+ if (lamdaFunction) {
6638
+ return lamdaFunction;
6639
+ }
6640
+ this.parseState.position = positionBefore;
7320
6641
  return parseSymbol(this.tokenStream, this.parseState);
7321
6642
  }
7322
6643
  case 'A_ReservedSymbol':
7323
6644
  return parseReservedSymbol(this.tokenStream, this.parseState);
6645
+ case 'RegexpShorthand':
6646
+ return parseRegexpShorthand(this.tokenStream, this.parseState);
7324
6647
  case 'PolNotation': {
7325
6648
  this.parseState.algebraic = false;
7326
6649
  var astNodes = [];
@@ -7441,12 +6764,9 @@ var AlgebraicParser = /** @class */ (function () {
7441
6764
  case '??':
7442
6765
  case '&&':
7443
6766
  case 'comment':
7444
- case 'declared?':
7445
- case 'if_not':
6767
+ case 'defined?':
7446
6768
  case '||':
7447
- case 'when':
7448
- case 'when_not':
7449
- case 'do':
6769
+ case 'recur':
7450
6770
  case 'throw': {
7451
6771
  var node = {
7452
6772
  t: AstNodeType.SpecialExpression,
@@ -7457,18 +6777,9 @@ var AlgebraicParser = /** @class */ (function () {
7457
6777
  builtin.specialExpressions[node.n].validateParameterCount(node);
7458
6778
  return node;
7459
6779
  }
7460
- case 'let':
7461
- return this.parseLet(symbol, params);
7462
- case 'defs':
7463
- case 'if_let':
7464
- case 'when_let':
7465
- case 'when_first':
7466
6780
  case 'fn':
7467
- case 'defns':
7468
- case 'try':
7469
- case 'recur':
7470
- case 'loop':
7471
- case 'doseq':
6781
+ case 'def':
6782
+ case 'defn':
7472
6783
  throw new Error("Special expression ".concat(name_2, " is not available in algebraic notation"));
7473
6784
  default:
7474
6785
  throw new Error("Unknown special expression: ".concat(name_2));
@@ -7487,6 +6798,11 @@ var AlgebraicParser = /** @class */ (function () {
7487
6798
  };
7488
6799
  AlgebraicParser.prototype.parseLambdaFunction = function () {
7489
6800
  var firstToken = this.peek();
6801
+ if (isLParenToken(firstToken)
6802
+ && isA_SymbolToken(this.peekAhead(1))
6803
+ && isA_OperatorToken(this.peekAhead(2), '=>')) {
6804
+ return null;
6805
+ }
7490
6806
  try {
7491
6807
  var _a = this.parseFunctionArguments(), functionArguments = _a.functionArguments, arity = _a.arity;
7492
6808
  if (!isA_OperatorToken(this.peek(), '=>')) {
@@ -7512,6 +6828,18 @@ var AlgebraicParser = /** @class */ (function () {
7512
6828
  };
7513
6829
  AlgebraicParser.prototype.parseFunctionArguments = function () {
7514
6830
  var _a, _b, _c, _d, _e;
6831
+ var firstToken = this.peek();
6832
+ if (isA_SymbolToken(firstToken)) {
6833
+ this.advance();
6834
+ return {
6835
+ functionArguments: {
6836
+ m: [firstToken[1]],
6837
+ b: [],
6838
+ r: undefined,
6839
+ },
6840
+ arity: 1,
6841
+ };
6842
+ }
7515
6843
  this.advance();
7516
6844
  var rest = false;
7517
6845
  var letBindingObject;
@@ -7630,36 +6958,146 @@ var AlgebraicParser = /** @class */ (function () {
7630
6958
  };
7631
6959
  return node;
7632
6960
  };
7633
- AlgebraicParser.prototype.parseLet = function (letSymbol, params) {
7634
- var _a, _b;
7635
- if (params.length !== 2) {
7636
- throw new LitsError('let expects two arguments', (_a = getTokenDebugData(letSymbol.token)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
7637
- }
7638
- var letObject = params[0];
7639
- if (letObject.t !== AstNodeType.NormalExpression || letObject.n !== 'object') {
7640
- throw new LitsError('let expects an object as first argument', (_b = getTokenDebugData(letObject.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
6961
+ AlgebraicParser.prototype.parseLet = function (token, optionalSemicolon) {
6962
+ if (optionalSemicolon === void 0) { optionalSemicolon = false; }
6963
+ this.advance();
6964
+ var letSymbol = parseSymbol(this.tokenStream, this.parseState);
6965
+ assertA_OperatorToken(this.peek(), '=');
6966
+ this.advance();
6967
+ var value = this.parseExpression();
6968
+ if (!optionalSemicolon) {
6969
+ assertA_OperatorToken(this.peek(), ';');
7641
6970
  }
7642
- var letBindings = arrayToPairs(letObject.p);
7643
- var expression = params[1];
7644
6971
  return {
7645
6972
  t: AstNodeType.SpecialExpression,
7646
6973
  n: 'let',
7647
- p: [expression],
7648
- token: getTokenDebugData(letSymbol.token) && letSymbol.token,
7649
- bs: letBindings.map(function (pair) {
7650
- var key = pair[0];
7651
- var value = pair[1];
7652
- return {
6974
+ p: [],
6975
+ bs: [{
7653
6976
  t: AstNodeType.Binding,
7654
- n: key.v,
6977
+ n: letSymbol.v,
7655
6978
  v: value,
7656
6979
  p: [],
7657
- token: getTokenDebugData(key.token) && key.token,
7658
- };
7659
- }),
6980
+ token: getTokenDebugData(token) && token,
6981
+ }],
6982
+ token: getTokenDebugData(letSymbol.token) && letSymbol.token,
6983
+ };
6984
+ };
6985
+ AlgebraicParser.prototype.parseDo = function (token) {
6986
+ this.advance();
6987
+ var expressions = [];
6988
+ while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
6989
+ expressions.push(this.parseExpression());
6990
+ if (isA_OperatorToken(this.peek(), ';')) {
6991
+ this.advance();
6992
+ }
6993
+ }
6994
+ assertA_ReservedSymbolToken(this.peek(), 'end');
6995
+ this.advance();
6996
+ return {
6997
+ t: AstNodeType.SpecialExpression,
6998
+ n: 'do',
6999
+ p: expressions,
7000
+ token: getTokenDebugData(token) && token,
7001
+ };
7002
+ };
7003
+ AlgebraicParser.prototype.parseLoop = function (token) {
7004
+ var _a;
7005
+ this.advance();
7006
+ assertLParenToken(this.peek());
7007
+ this.advance();
7008
+ var bindingNodes = [];
7009
+ while (!this.isAtEnd() && !isRParenToken(this.peek())) {
7010
+ var symbol = parseSymbol(this.tokenStream, this.parseState);
7011
+ assertA_OperatorToken(this.peek(), '=');
7012
+ this.advance();
7013
+ var value = this.parseExpression();
7014
+ bindingNodes.push({
7015
+ t: AstNodeType.Binding,
7016
+ n: symbol.v,
7017
+ v: value,
7018
+ p: [],
7019
+ token: getTokenDebugData(symbol.token) && symbol.token,
7020
+ });
7021
+ if (isA_OperatorToken(this.peek(), ',')) {
7022
+ this.advance();
7023
+ }
7024
+ }
7025
+ if (bindingNodes.length === 0) {
7026
+ throw new LitsError('Expected binding', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
7027
+ }
7028
+ assertRParenToken(this.peek());
7029
+ this.advance();
7030
+ var params = [];
7031
+ while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
7032
+ params.push(this.parseExpression());
7033
+ if (isA_OperatorToken(this.peek(), ';')) {
7034
+ this.advance();
7035
+ }
7036
+ }
7037
+ assertA_ReservedSymbolToken(this.peek(), 'end');
7038
+ this.advance();
7039
+ return {
7040
+ t: AstNodeType.SpecialExpression,
7041
+ n: 'loop',
7042
+ p: params,
7043
+ bs: bindingNodes,
7044
+ token: getTokenDebugData(token) && token,
7045
+ };
7046
+ };
7047
+ AlgebraicParser.prototype.parseTry = function (token) {
7048
+ this.advance();
7049
+ var tryExpressions = [];
7050
+ while (!this.isAtEnd() && !isA_SymbolToken(this.peek(), 'catch')) {
7051
+ tryExpressions.push(this.parseExpression());
7052
+ if (isA_OperatorToken(this.peek(), ';')) {
7053
+ this.advance();
7054
+ }
7055
+ }
7056
+ var tryExpression = tryExpressions.length === 1
7057
+ ? tryExpressions[0]
7058
+ : {
7059
+ t: AstNodeType.SpecialExpression,
7060
+ n: 'do',
7061
+ p: tryExpressions,
7062
+ token: getTokenDebugData(token) && token,
7063
+ };
7064
+ assertA_SymbolToken(this.peek(), 'catch');
7065
+ this.advance();
7066
+ var errorSymbol;
7067
+ if (isLParenToken(this.peek())) {
7068
+ this.advance();
7069
+ errorSymbol = parseSymbol(this.tokenStream, this.parseState);
7070
+ assertRParenToken(this.peek());
7071
+ this.advance();
7072
+ }
7073
+ var catchExpressions = [];
7074
+ while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
7075
+ catchExpressions.push(this.parseExpression());
7076
+ if (isA_OperatorToken(this.peek(), ';')) {
7077
+ this.advance();
7078
+ }
7079
+ }
7080
+ assertA_ReservedSymbolToken(this.peek(), 'end');
7081
+ this.advance();
7082
+ var catchExpression = catchExpressions.length === 1
7083
+ ? catchExpressions[0]
7084
+ : {
7085
+ t: AstNodeType.SpecialExpression,
7086
+ n: 'do',
7087
+ p: catchExpressions,
7088
+ token: getTokenDebugData(token) && token,
7089
+ };
7090
+ return {
7091
+ t: AstNodeType.SpecialExpression,
7092
+ n: 'try',
7093
+ p: [tryExpression],
7094
+ ce: catchExpression,
7095
+ e: errorSymbol,
7096
+ token: getTokenDebugData(token) && token,
7660
7097
  };
7661
7098
  };
7662
- AlgebraicParser.prototype.parseFor = function (token) {
7099
+ AlgebraicParser.prototype.parseForOrDoseq = function (token) {
7100
+ var isDoseq = token[1] === 'doseq';
7663
7101
  this.advance();
7664
7102
  assertLParenToken(this.peek());
7665
7103
  this.advance();
@@ -7679,7 +7117,7 @@ var AlgebraicParser = /** @class */ (function () {
7679
7117
  this.advance();
7680
7118
  return {
7681
7119
  t: AstNodeType.SpecialExpression,
7682
- n: 'for',
7120
+ n: isDoseq ? 'doseq' : 'for',
7683
7121
  p: [expression],
7684
7122
  token: getTokenDebugData(token) && token,
7685
7123
  l: forLoopBindings,
@@ -7699,33 +7137,26 @@ var AlgebraicParser = /** @class */ (function () {
7699
7137
  }
7700
7138
  var modifiers = [];
7701
7139
  var token = this.peek();
7702
- if (!isA_SymbolToken(token)) {
7140
+ if (!isA_SymbolToken(token, 'let')
7141
+ && !isA_ReservedSymbolToken(token, 'when')
7142
+ && !isA_ReservedSymbolToken(token, 'while')) {
7703
7143
  throw new LitsError('Expected symbol let, when or while', (_a = getTokenDebugData(token)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
7704
7144
  }
7705
7145
  var letBindings;
7706
7146
  if (token[1] === 'let') {
7707
7147
  modifiers.push('&let');
7708
7148
  letBindings = [];
7709
- this.advance();
7710
- var letObject = this.parseObject();
7711
- letBindings = arrayToPairs(letObject.p).map(function (pair) {
7712
- var key = pair[0];
7713
- var value = pair[1];
7714
- return {
7715
- t: AstNodeType.Binding,
7716
- n: key.v,
7717
- v: value,
7718
- p: [],
7719
- token: getTokenDebugData(key.token) && key.token,
7720
- };
7721
- });
7149
+ while (isA_SymbolToken(token, 'let')) {
7150
+ var letNode = this.parseLet(token, true);
7151
+ letBindings.push(letNode.bs[0]);
7152
+ token = this.peek();
7153
+ }
7722
7154
  }
7723
7155
  token = this.peek();
7724
7156
  var whenNode;
7725
7157
  var whileNode;
7726
- while (isA_SymbolToken(token)
7727
- && ((token[1] === 'when' && !modifiers.includes('&when'))
7728
- || (token[1] === 'while' && !modifiers.includes('&while')))) {
7158
+ while (isA_ReservedSymbolToken(token, 'when')
7159
+ || isA_ReservedSymbolToken(token, 'while')) {
7729
7160
  this.advance();
7730
7161
  if (token[1] === 'when') {
7731
7162
  modifiers.push('&when');
@@ -7768,7 +7199,8 @@ var AlgebraicParser = /** @class */ (function () {
7768
7199
  };
7769
7200
  return node;
7770
7201
  };
7771
- AlgebraicParser.prototype.parseIf = function (token) {
7202
+ AlgebraicParser.prototype.parseIfOrUnless = function (token) {
7203
+ var isUnless = token[1] === 'unless';
7772
7204
  this.advance();
7773
7205
  var condition = this.parseExpression();
7774
7206
  assertA_ReservedSymbolToken(this.peek(), 'then');
@@ -7817,7 +7249,7 @@ var AlgebraicParser = /** @class */ (function () {
7817
7249
  }
7818
7250
  return {
7819
7251
  t: AstNodeType.SpecialExpression,
7820
- n: 'if',
7252
+ n: isUnless ? 'unless' : 'if',
7821
7253
  p: params,
7822
7254
  token: getTokenDebugData(token) && token,
7823
7255
  };
@@ -7902,20 +7334,7 @@ var AlgebraicParser = /** @class */ (function () {
7902
7334
  token: getTokenDebugData(token) && token,
7903
7335
  };
7904
7336
  };
7905
- AlgebraicParser.prototype.parseDef = function (token) {
7906
- this.advance();
7907
- var symbol = parseSymbol(this.tokenStream, this.parseState);
7908
- assertA_OperatorToken(this.peek(), '=');
7909
- this.advance();
7910
- var value = this.parseExpression();
7911
- return {
7912
- t: AstNodeType.SpecialExpression,
7913
- n: 'def',
7914
- p: [symbol, value],
7915
- token: getTokenDebugData(token) && token,
7916
- };
7917
- };
7918
- AlgebraicParser.prototype.parseDefn = function (token) {
7337
+ AlgebraicParser.prototype.parseFunction = function (token) {
7919
7338
  this.advance();
7920
7339
  var symbol = parseSymbol(this.tokenStream, this.parseState);
7921
7340
  var _a = this.parseFunctionArguments(), functionArguments = _a.functionArguments, arity = _a.arity;
@@ -7928,10 +7347,9 @@ var AlgebraicParser = /** @class */ (function () {
7928
7347
  }
7929
7348
  assertA_ReservedSymbolToken(this.peek(), 'end');
7930
7349
  this.advance();
7931
- return {
7350
+ var fnNode = {
7932
7351
  t: AstNodeType.SpecialExpression,
7933
- n: 'defn',
7934
- f: symbol,
7352
+ n: 'fn',
7935
7353
  p: [],
7936
7354
  o: [{
7937
7355
  as: functionArguments,
@@ -7940,12 +7358,63 @@ var AlgebraicParser = /** @class */ (function () {
7940
7358
  }],
7941
7359
  token: getTokenDebugData(token) && token,
7942
7360
  };
7361
+ return {
7362
+ t: AstNodeType.SpecialExpression,
7363
+ n: 'let',
7364
+ p: [],
7365
+ bs: [{
7366
+ t: AstNodeType.Binding,
7367
+ n: symbol.v,
7368
+ v: fnNode,
7369
+ p: [],
7370
+ token: getTokenDebugData(symbol.token) && symbol.token,
7371
+ }],
7372
+ token: getTokenDebugData(token) && token,
7373
+ };
7943
7374
  };
7944
7375
  AlgebraicParser.prototype.isAtEnd = function () {
7945
7376
  return this.parseState.position >= this.tokenStream.tokens.length;
7946
7377
  };
7947
- AlgebraicParser.prototype.peek = function () {
7948
- return this.tokenStream.tokens[this.parseState.position];
7378
+ AlgebraicParser.prototype.isAtExpressionEnd = function () {
7379
+ if (this.isAtEnd()) {
7380
+ return true;
7381
+ }
7382
+ var token = this.peek();
7383
+ if (isA_OperatorToken(token)) {
7384
+ return [';', ','].includes(token[1]);
7385
+ }
7386
+ if (isA_SymbolToken(token)) {
7387
+ return ['catch'].includes(token[1]);
7388
+ }
7389
+ if (isA_ReservedSymbolToken(token)) {
7390
+ return ['else', 'when', 'while', 'then', 'end', 'case'].includes(token[1]);
7391
+ }
7392
+ return false;
7393
+ };
7394
+ AlgebraicParser.prototype.parseExport = function (token) {
7395
+ var _a;
7396
+ this.advance();
7397
+ var symbol = parseSymbol(this.tokenStream, this.parseState);
7398
+ if (isA_OperatorToken(this.peek(), ';')) {
7399
+ return {
7400
+ t: AstNodeType.SpecialExpression,
7401
+ n: 'def',
7402
+ p: [symbol, symbol],
7403
+ token: getTokenDebugData(token) && token,
7404
+ };
7405
+ }
7406
+ if (!isA_OperatorToken(this.peek(), '=')) {
7407
+ throw new LitsError('Expected = or ;', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
7408
+ }
7409
+ this.advance();
7410
+ var value = this.parseExpression();
7411
+ assertA_OperatorToken(this.peek(), ';');
7412
+ return {
7413
+ t: AstNodeType.SpecialExpression,
7414
+ n: 'def',
7415
+ p: [symbol, value],
7416
+ token: getTokenDebugData(token) && token,
7417
+ };
7949
7418
  };
7950
7419
  return AlgebraicParser;
7951
7420
  }());
@@ -8021,33 +7490,6 @@ function parseObjectLitteral(tokenStream, parseState) {
8021
7490
  assertEvenNumberOfParams(node);
8022
7491
  return node;
8023
7492
  }
8024
- function parseRegexpShorthand(tokenStream, parseState) {
8025
- var tkn = asP_RegexpShorthandToken(tokenStream.tokens[parseState.position++]);
8026
- var endStringPosition = tkn[1].lastIndexOf('"');
8027
- var regexpString = tkn[1].substring(2, endStringPosition);
8028
- var optionsString = tkn[1].substring(endStringPosition + 1);
8029
- var stringNode = {
8030
- t: AstNodeType.String,
8031
- v: regexpString,
8032
- p: [],
8033
- n: undefined,
8034
- token: getTokenDebugData(tkn) && tkn,
8035
- };
8036
- var optionsNode = {
8037
- t: AstNodeType.String,
8038
- v: optionsString,
8039
- p: [],
8040
- n: undefined,
8041
- token: getTokenDebugData(tkn) && tkn,
8042
- };
8043
- var node = {
8044
- t: AstNodeType.NormalExpression,
8045
- n: 'regexp',
8046
- p: [stringNode, optionsNode],
8047
- token: getTokenDebugData(tkn) && tkn,
8048
- };
8049
- return node;
8050
- }
8051
7493
  var placeholderRegexp = /^%([1-9]\d?)?$/;
8052
7494
  function parseFnShorthand(tokenStream, parseState) {
8053
7495
  var _a, _b, _c, _d;
@@ -8217,7 +7659,7 @@ function parsePolishToken(tokenStream, parseState) {
8217
7659
  return parseArrayLitteral(tokenStream, parseState);
8218
7660
  case 'LBrace':
8219
7661
  return parseObjectLitteral(tokenStream, parseState);
8220
- case 'P_RegexpShorthand':
7662
+ case 'RegexpShorthand':
8221
7663
  return parseRegexpShorthand(tokenStream, parseState);
8222
7664
  case 'P_FnShorthand':
8223
7665
  return parseFnShorthand(tokenStream, parseState);
@@ -8381,6 +7823,25 @@ var tokenizeString = function (input, position) {
8381
7823
  value += '"'; // closing quote
8382
7824
  return [length + 1, ['String', value]];
8383
7825
  };
7826
+ var tokenizeRegexpShorthand = function (input, position) {
7827
+ if (input[position] !== '#')
7828
+ return NO_MATCH;
7829
+ var _a = __read(tokenizeString(input, position + 1), 2), stringLength = _a[0], token = _a[1];
7830
+ if (!token)
7831
+ return NO_MATCH;
7832
+ position += stringLength + 1;
7833
+ var length = stringLength + 1;
7834
+ var options = '';
7835
+ while (input[position] === 'g' || input[position] === 'i') {
7836
+ if (options.includes(input[position])) {
7837
+ throw new LitsError("Duplicated regexp option \"".concat(input[position], "\" at position ").concat(position, "."), undefined);
7838
+ }
7839
+ options += input[position];
7840
+ length += 1;
7841
+ position += 1;
7842
+ }
7843
+ return [length, ['RegexpShorthand', "#".concat(token[1]).concat(options)]];
7844
+ };
8384
7845
  function tokenizeSimpleToken(type, value, input, position) {
8385
7846
  if (value === input.slice(position, position + value.length))
8386
7847
  return [value.length, [type]];
@@ -8398,6 +7859,7 @@ var commonTokenizers = [
8398
7859
  tokenizeLBrace,
8399
7860
  tokenizeRBrace,
8400
7861
  tokenizeString,
7862
+ tokenizeRegexpShorthand,
8401
7863
  ];
8402
7864
 
8403
7865
  var validAlgebraicReservedNamesRecord = {
@@ -8409,17 +7871,13 @@ var validAlgebraicReservedNamesRecord = {
8409
7871
  else: { value: null, forbidden: false },
8410
7872
  end: { value: null, forbidden: false },
8411
7873
  case: { value: null, forbidden: false },
7874
+ when: { value: null, forbidden: false },
7875
+ while: { value: null, forbidden: false },
7876
+ function: { value: null, forbidden: false },
7877
+ export: { value: null, forbidden: false },
8412
7878
  };
8413
7879
  var forbiddenAlgebraicReservedNamesRecord = {
8414
- if_let: { value: null, forbidden: true },
8415
- when_let: { value: null, forbidden: true },
8416
- when_first: { value: null, forbidden: true },
8417
7880
  fn: { value: null, forbidden: true },
8418
- defns: { value: null, forbidden: true },
8419
- try: { value: null, forbidden: true },
8420
- recur: { value: null, forbidden: true },
8421
- loop: { value: null, forbidden: true },
8422
- doseq: { value: null, forbidden: true },
8423
7881
  };
8424
7882
  var algebraicReservedNamesRecord = __assign(__assign({}, validAlgebraicReservedNamesRecord), forbiddenAlgebraicReservedNamesRecord);
8425
7883
 
@@ -8804,25 +8262,6 @@ var tokenizeP_CollectionAccessor = function (input, position) {
8804
8262
  return NO_MATCH;
8805
8263
  return [1, ['P_CollectionAccessor', char]];
8806
8264
  };
8807
- var tokenizeP_RegexpShorthand = function (input, position) {
8808
- if (input[position] !== '#')
8809
- return NO_MATCH;
8810
- var _a = __read(tokenizeString(input, position + 1), 2), stringLength = _a[0], token = _a[1];
8811
- if (!token)
8812
- return NO_MATCH;
8813
- position += stringLength + 1;
8814
- var length = stringLength + 1;
8815
- var options = '';
8816
- while (input[position] === 'g' || input[position] === 'i') {
8817
- if (options.includes(input[position])) {
8818
- throw new LitsError("Duplicated regexp option \"".concat(input[position], "\" at position ").concat(position, "."), undefined);
8819
- }
8820
- options += input[position];
8821
- length += 1;
8822
- position += 1;
8823
- }
8824
- return [length, ['P_RegexpShorthand', "#".concat(token[1]).concat(options)]];
8825
- };
8826
8265
  // All tokenizers, order matters!
8827
8266
  var polishTokenizers = __spreadArray(__spreadArray([
8828
8267
  tokenizeP_Whitespace,
@@ -8833,7 +8272,6 @@ var polishTokenizers = __spreadArray(__spreadArray([
8833
8272
  tokenizeP_ReservedSymbol,
8834
8273
  tokenizeP_Modifier,
8835
8274
  tokenizeP_Symbol,
8836
- tokenizeP_RegexpShorthand,
8837
8275
  tokenizeP_FnShorthand,
8838
8276
  tokenizeP_CollectionAccessor,
8839
8277
  ], false);
@@ -10118,7 +9556,7 @@ var arrayReference = {
10118
9556
  description: 'Takes a nested array $x and flattens it.',
10119
9557
  examples: [
10120
9558
  '(flatten [1 2 [3 4] 5])',
10121
- "\n(let [foo :bar]\n (flatten\n [1\n \" 2 A \"\n [foo [4 [:ABC]]] 6]))",
9559
+ "\n(let [foo :bar])\n(flatten\n [1\n \" 2 A \"\n [foo [4 [:ABC]]] 6])",
10122
9560
  '(flatten 12)',
10123
9561
  ],
10124
9562
  },
@@ -10152,7 +9590,7 @@ var arrayReference = {
10152
9590
  };
10153
9591
 
10154
9592
  var sequenceReference = {
10155
- nth: {
9593
+ 'nth': {
10156
9594
  title: 'nth',
10157
9595
  category: 'Sequence',
10158
9596
  linkName: 'nth',
@@ -10188,7 +9626,7 @@ var sequenceReference = {
10188
9626
  '(nth nil 1 "Default value")',
10189
9627
  ],
10190
9628
  },
10191
- push: {
9629
+ 'push': {
10192
9630
  title: 'push',
10193
9631
  category: 'Sequence',
10194
9632
  linkName: 'push',
@@ -10218,7 +9656,7 @@ var sequenceReference = {
10218
9656
  '(def l [1 2 3]) (push l 4) l',
10219
9657
  ],
10220
9658
  },
10221
- pop: {
9659
+ 'pop': {
10222
9660
  title: 'pop',
10223
9661
  category: 'Sequence',
10224
9662
  linkName: 'pop',
@@ -10241,7 +9679,7 @@ var sequenceReference = {
10241
9679
  '(pop [])',
10242
9680
  ],
10243
9681
  },
10244
- unshift: {
9682
+ 'unshift': {
10245
9683
  title: 'unshift',
10246
9684
  category: 'Sequence',
10247
9685
  linkName: 'unshift',
@@ -10270,7 +9708,7 @@ var sequenceReference = {
10270
9708
  "\n(def l [1 2 3])\n(unshift l 4)\nl",
10271
9709
  ],
10272
9710
  },
10273
- shift: {
9711
+ 'shift': {
10274
9712
  title: 'shift',
10275
9713
  category: 'Sequence',
10276
9714
  linkName: 'shift',
@@ -10294,7 +9732,7 @@ var sequenceReference = {
10294
9732
  '(shift [])',
10295
9733
  ],
10296
9734
  },
10297
- slice: {
9735
+ 'slice': {
10298
9736
  title: 'slice',
10299
9737
  category: 'Sequence',
10300
9738
  linkName: 'slice',
@@ -10328,7 +9766,7 @@ var sequenceReference = {
10328
9766
  '(slice [1 2 3 4 5] 2)',
10329
9767
  ],
10330
9768
  },
10331
- reductions: {
9769
+ 'reductions': {
10332
9770
  title: 'reductions',
10333
9771
  category: 'Sequence',
10334
9772
  linkName: 'reductions',
@@ -10360,7 +9798,7 @@ var sequenceReference = {
10360
9798
  "\n(reductions\n (fn [result value] (+ result (if (even? value) value 0)))\n 0\n [1 2 3 4 5 6 7 8 9])",
10361
9799
  ],
10362
9800
  },
10363
- reduce: {
9801
+ 'reduce': {
10364
9802
  title: 'reduce',
10365
9803
  category: 'Sequence',
10366
9804
  linkName: 'reduce',
@@ -10390,7 +9828,7 @@ var sequenceReference = {
10390
9828
  "\n(reduce\n (fn [result value] (+ result (if (even? value) value 0)))\n 0\n [1 2 3 4 5 6 7 8 9])",
10391
9829
  ],
10392
9830
  },
10393
- reduce_right: {
9831
+ 'reduce_right': {
10394
9832
  title: 'reduce_right',
10395
9833
  category: 'Sequence',
10396
9834
  linkName: 'reduce_right',
@@ -10418,7 +9856,7 @@ var sequenceReference = {
10418
9856
  '(reduce_right str [:A :B :C] "")',
10419
9857
  ],
10420
9858
  },
10421
- map: {
9859
+ 'map': {
10422
9860
  title: 'map',
10423
9861
  category: 'Sequence',
10424
9862
  linkName: 'map',
@@ -10443,7 +9881,7 @@ var sequenceReference = {
10443
9881
  '(map [1 2 3] inc)',
10444
9882
  ],
10445
9883
  },
10446
- filter: {
9884
+ 'filter': {
10447
9885
  title: 'filter',
10448
9886
  category: 'Sequence',
10449
9887
  linkName: 'filter',
@@ -10467,7 +9905,7 @@ var sequenceReference = {
10467
9905
  "\n(filter\n[5 10 15 20]\n (fn [x] (> x 10)))",
10468
9906
  ],
10469
9907
  },
10470
- position: {
9908
+ 'position': {
10471
9909
  title: 'position',
10472
9910
  category: 'Sequence',
10473
9911
  linkName: 'position',
@@ -10494,7 +9932,7 @@ var sequenceReference = {
10494
9932
  "\n(position\n (fn [x] (> x 100))\n nil)",
10495
9933
  ],
10496
9934
  },
10497
- index_of: {
9935
+ 'index_of': {
10498
9936
  title: 'index_of',
10499
9937
  category: 'Sequence',
10500
9938
  linkName: 'index_of',
@@ -10521,7 +9959,34 @@ var sequenceReference = {
10521
9959
  '(index_of nil 1)',
10522
9960
  ],
10523
9961
  },
10524
- some: {
9962
+ 'last_index_of': {
9963
+ title: 'last_index_of',
9964
+ category: 'Sequence',
9965
+ linkName: 'last_index_of',
9966
+ clojureDocs: null,
9967
+ returns: {
9968
+ type: ['number', 'null'],
9969
+ },
9970
+ args: {
9971
+ seq: {
9972
+ type: ['sequence', 'null'],
9973
+ },
9974
+ x: {
9975
+ type: 'any',
9976
+ },
9977
+ },
9978
+ variants: [
9979
+ { argumentNames: ['seq', 'x'] },
9980
+ ],
9981
+ description: 'Returns the last index of $x in $seq. If element is not present in $seq `nil` is returned.',
9982
+ examples: [
9983
+ '(last_index_of ["Albert" "Mojir" 160 [1 2]] "Mojir")',
9984
+ '(last_index_of [5 10 15 20] 15)',
9985
+ '(last_index_of [5 10 15 20] 1)',
9986
+ '(last_index_of nil 1)',
9987
+ ],
9988
+ },
9989
+ 'some': {
10525
9990
  title: 'some',
10526
9991
  category: 'Sequence',
10527
9992
  linkName: 'some',
@@ -10548,7 +10013,7 @@ var sequenceReference = {
10548
10013
  "\n(some\n nil\n (fn [x] (> x 10)))",
10549
10014
  ],
10550
10015
  },
10551
- reverse: {
10016
+ 'reverse': {
10552
10017
  title: 'reverse',
10553
10018
  category: 'Sequence',
10554
10019
  linkName: 'reverse',
@@ -10571,7 +10036,7 @@ var sequenceReference = {
10571
10036
  '(reverse nil)',
10572
10037
  ],
10573
10038
  },
10574
- first: {
10039
+ 'first': {
10575
10040
  title: 'first',
10576
10041
  category: 'Sequence',
10577
10042
  linkName: 'first',
@@ -10593,7 +10058,7 @@ var sequenceReference = {
10593
10058
  '(first nil)',
10594
10059
  ],
10595
10060
  },
10596
- second: {
10061
+ 'second': {
10597
10062
  title: 'second',
10598
10063
  category: 'Sequence',
10599
10064
  linkName: 'second',
@@ -10616,7 +10081,7 @@ var sequenceReference = {
10616
10081
  '(second nil)',
10617
10082
  ],
10618
10083
  },
10619
- last: {
10084
+ 'last': {
10620
10085
  title: 'last',
10621
10086
  category: 'Sequence',
10622
10087
  linkName: 'last',
@@ -10640,7 +10105,7 @@ var sequenceReference = {
10640
10105
  '(last nil)',
10641
10106
  ],
10642
10107
  },
10643
- rest: {
10108
+ 'rest': {
10644
10109
  title: 'rest',
10645
10110
  category: 'Sequence',
10646
10111
  linkName: 'rest',
@@ -10665,7 +10130,7 @@ var sequenceReference = {
10665
10130
  '(rest "")',
10666
10131
  ],
10667
10132
  },
10668
- nthrest: {
10133
+ 'nthrest': {
10669
10134
  title: 'nthrest',
10670
10135
  category: 'Sequence',
10671
10136
  linkName: 'nthrest',
@@ -10693,7 +10158,7 @@ var sequenceReference = {
10693
10158
  '(nthrest "" 0)',
10694
10159
  ],
10695
10160
  },
10696
- next: {
10161
+ 'next': {
10697
10162
  title: 'next',
10698
10163
  category: 'Sequence',
10699
10164
  linkName: 'next',
@@ -10718,7 +10183,7 @@ var sequenceReference = {
10718
10183
  '(next "")',
10719
10184
  ],
10720
10185
  },
10721
- nthnext: {
10186
+ 'nthnext': {
10722
10187
  title: 'nthnext',
10723
10188
  category: 'Sequence',
10724
10189
  linkName: 'nthnext',
@@ -10746,7 +10211,7 @@ var sequenceReference = {
10746
10211
  '(nthnext "" 0)',
10747
10212
  ],
10748
10213
  },
10749
- take: {
10214
+ 'take': {
10750
10215
  title: 'take',
10751
10216
  category: 'Sequence',
10752
10217
  linkName: 'take',
@@ -10772,7 +10237,7 @@ var sequenceReference = {
10772
10237
  '(take 50 "Albert")',
10773
10238
  ],
10774
10239
  },
10775
- take_last: {
10240
+ 'take_last': {
10776
10241
  title: 'take_last',
10777
10242
  category: 'Sequence',
10778
10243
  linkName: 'take_last',
@@ -10796,7 +10261,7 @@ var sequenceReference = {
10796
10261
  '(take_last 0 [1 2 3 4 5])',
10797
10262
  ],
10798
10263
  },
10799
- take_while: {
10264
+ 'take_while': {
10800
10265
  title: 'take_while',
10801
10266
  category: 'Sequence',
10802
10267
  linkName: 'take_while',
@@ -10820,7 +10285,7 @@ var sequenceReference = {
10820
10285
  "\n(take_while\n [1 2 3 2 1]\n (fn [x] (> x 3)))",
10821
10286
  ],
10822
10287
  },
10823
- drop: {
10288
+ 'drop': {
10824
10289
  title: 'drop',
10825
10290
  category: 'Sequence',
10826
10291
  linkName: 'drop',
@@ -10846,7 +10311,7 @@ var sequenceReference = {
10846
10311
  '(drop "Albert" 50)',
10847
10312
  ],
10848
10313
  },
10849
- drop_last: {
10314
+ 'drop_last': {
10850
10315
  title: 'drop_last',
10851
10316
  category: 'Sequence',
10852
10317
  linkName: 'drop_last',
@@ -10870,7 +10335,7 @@ var sequenceReference = {
10870
10335
  '(drop_last [1 2 3 4 5] 0)',
10871
10336
  ],
10872
10337
  },
10873
- drop_while: {
10338
+ 'drop_while': {
10874
10339
  title: 'drop_while',
10875
10340
  category: 'Sequence',
10876
10341
  linkName: 'drop_while',
@@ -10894,7 +10359,7 @@ var sequenceReference = {
10894
10359
  "\n(drop_while\n [1 2 3 2 1]\n (fn [x] (> x 3)))",
10895
10360
  ],
10896
10361
  },
10897
- sort: {
10362
+ 'sort': {
10898
10363
  title: 'sort',
10899
10364
  category: 'Sequence',
10900
10365
  linkName: 'sort',
@@ -10921,7 +10386,7 @@ var sequenceReference = {
10921
10386
  "\n(sort\n [3 1 2]\n (fn [a b] (cond (> a b) -1 (< a b) 1 true -1)))",
10922
10387
  ],
10923
10388
  },
10924
- sort_by: {
10389
+ 'sort_by': {
10925
10390
  title: 'sort_by',
10926
10391
  category: 'Sequence',
10927
10392
  linkName: 'sort_by',
@@ -10950,7 +10415,7 @@ var sequenceReference = {
10950
10415
  '(sort_by "Albert" lower_case #(compare %2 %1))',
10951
10416
  ],
10952
10417
  },
10953
- distinct: {
10418
+ 'distinct': {
10954
10419
  title: 'distinct',
10955
10420
  category: 'Sequence',
10956
10421
  linkName: 'distinct',
@@ -10973,7 +10438,7 @@ var sequenceReference = {
10973
10438
  '(distinct "")',
10974
10439
  ],
10975
10440
  },
10976
- remove: {
10441
+ 'remove': {
10977
10442
  title: 'remove',
10978
10443
  category: 'Sequence',
10979
10444
  linkName: 'remove',
@@ -10997,7 +10462,7 @@ var sequenceReference = {
10997
10462
  '(remove "Albert Mojir" #(has? "aoueiyAOUEIY" %1))',
10998
10463
  ],
10999
10464
  },
11000
- remove_at: {
10465
+ 'remove_at': {
11001
10466
  title: 'remove_at',
11002
10467
  category: 'Sequence',
11003
10468
  linkName: 'remove_at',
@@ -11023,7 +10488,7 @@ var sequenceReference = {
11023
10488
  '(remove_at "Albert Mojir" 6)',
11024
10489
  ],
11025
10490
  },
11026
- split_at: {
10491
+ 'split_at': {
11027
10492
  title: 'split_at',
11028
10493
  category: 'Sequence',
11029
10494
  linkName: 'split_at',
@@ -11048,7 +10513,7 @@ var sequenceReference = {
11048
10513
  '(split_at "Albert" 2)',
11049
10514
  ],
11050
10515
  },
11051
- split_with: {
10516
+ 'split_with': {
11052
10517
  title: 'split_with',
11053
10518
  category: 'Sequence',
11054
10519
  linkName: 'split_with',
@@ -11073,7 +10538,7 @@ var sequenceReference = {
11073
10538
  '(split_with "Albert" #(<= %1 :Z))',
11074
10539
  ],
11075
10540
  },
11076
- frequencies: {
10541
+ 'frequencies': {
11077
10542
  title: 'frequencies',
11078
10543
  category: 'Sequence',
11079
10544
  linkName: 'frequencies',
@@ -11094,7 +10559,7 @@ var sequenceReference = {
11094
10559
  '(frequencies "Pneumonoultramicroscopicsilicovolcanoconiosis")',
11095
10560
  ],
11096
10561
  },
11097
- group_by: {
10562
+ 'group_by': {
11098
10563
  title: 'group_by',
11099
10564
  category: 'Sequence',
11100
10565
  linkName: 'group_by',
@@ -11118,7 +10583,7 @@ var sequenceReference = {
11118
10583
  '(group_by "Albert Mojir" (fn [char] (if (has? "aoueiAOUEI" char) "vowel" "other")))',
11119
10584
  ],
11120
10585
  },
11121
- partition: {
10586
+ 'partition': {
11122
10587
  title: 'partition',
11123
10588
  category: 'Sequence',
11124
10589
  linkName: 'partition',
@@ -11135,67 +10600,175 @@ var sequenceReference = {
11135
10600
  step: {
11136
10601
  type: 'number',
11137
10602
  },
11138
- pad: {
11139
- type: 'array',
10603
+ pad: {
10604
+ type: 'array',
10605
+ },
10606
+ },
10607
+ variants: [
10608
+ { argumentNames: ['seq', 'n'] },
10609
+ { argumentNames: ['seq', 'n', 'step'] },
10610
+ { argumentNames: ['seq', 'n', 'step', 'pad'] },
10611
+ ],
10612
+ description: 'Returns an array of sequences of $n items each, at offsets $step apart. If $step is not supplied, defaults to $n. If a $pad array is supplied, use its elements as necessary to complete last partition upto $n items. In case there are not enough padding elements, return a partition with less than $n items.',
10613
+ examples: [
10614
+ '(partition (range 20) 4)',
10615
+ '(partition (range 22) 4)',
10616
+ '(partition (range 20) 4 6)',
10617
+ '(partition (range 20) 4 3)',
10618
+ '(partition (range 20) 3 6 [:a])',
10619
+ '(partition (range 20) 4 6 [:a])',
10620
+ '(partition (range 20) 4 6 [:a :b :c :d])',
10621
+ '(partition [:a :b :c :d :e :f] 3 1)',
10622
+ '(partition [1 2 3 4] 10)',
10623
+ '(partition [1 2 3 4] 10 10)',
10624
+ '(partition [1 2 3 4] 10 10 [])',
10625
+ '(partition [1 2 3 4] 10 10 nil)',
10626
+ '(partition "superfragilistic" 5)',
10627
+ '(partition "superfragilistic" 5 5 nil)',
10628
+ '(def foo [5 6 7 8]) (partition foo 2 1 foo)',
10629
+ ],
10630
+ },
10631
+ 'partition_all': {
10632
+ title: 'partition_all',
10633
+ category: 'Sequence',
10634
+ linkName: 'partition_all',
10635
+ returns: {
10636
+ type: 'sequence',
10637
+ },
10638
+ args: {
10639
+ seq: {
10640
+ type: 'sequence',
10641
+ },
10642
+ n: {
10643
+ type: 'number',
10644
+ },
10645
+ step: {
10646
+ type: 'number',
10647
+ },
10648
+ },
10649
+ variants: [
10650
+ { argumentNames: ['seq', 'n'] },
10651
+ { argumentNames: ['seq', 'n', 'step'] },
10652
+ ],
10653
+ description: 'Returns an array of sequences like partition, but may include partitions with fewer than n items at the end.',
10654
+ examples: [
10655
+ '(partition_all [0 1 2 3 4 5 6 7 8 9] 4)',
10656
+ '(partition [0 1 2 3 4 5 6 7 8 9] 4)',
10657
+ '(partition_all [0 1 2 3 4 5 6 7 8 9] 2 4)',
10658
+ ],
10659
+ },
10660
+ 'partition_by': {
10661
+ title: 'partition_by',
10662
+ category: 'Sequence',
10663
+ linkName: 'partition_by',
10664
+ returns: {
10665
+ type: 'sequence',
10666
+ },
10667
+ args: {
10668
+ seq: {
10669
+ type: 'sequence',
10670
+ },
10671
+ fn: {
10672
+ type: 'function',
10673
+ },
10674
+ },
10675
+ variants: [
10676
+ { argumentNames: ['seq', 'fn'] },
10677
+ ],
10678
+ description: 'Applies $fn to each value in $seq, splitting it each time $fn returns a new value. Returns an array of sequences.',
10679
+ examples: [
10680
+ '(partition_by [1 2 3 4 5] #(== 3 %1))',
10681
+ '(partition_by [1 1 1 2 2 3 3] odd?)',
10682
+ '(partition_by "Leeeeeerrroyyy" identity)',
10683
+ ],
10684
+ },
10685
+ 'starts_with?': {
10686
+ title: 'starts_with?',
10687
+ category: 'Sequence',
10688
+ linkName: 'starts_with-question',
10689
+ clojureDocs: null,
10690
+ returns: {
10691
+ type: 'boolean',
10692
+ },
10693
+ args: {
10694
+ seq: {
10695
+ type: 'sequence',
10696
+ },
10697
+ prefix: {
10698
+ type: 'sequence',
10699
+ },
10700
+ },
10701
+ variants: [
10702
+ { argumentNames: ['seq', 'prefix'] },
10703
+ ],
10704
+ description: 'Returns `true` if $seq starts with $prefix, otherwise `false`.',
10705
+ examples: [
10706
+ '(starts_with? [1 2 3 4 5] 1)',
10707
+ '(starts_with? [1 2 3 4 5] [1])',
10708
+ '(starts_with? "Albert" "Al")',
10709
+ '(starts_with? "Albert" "al")',
10710
+ ],
10711
+ },
10712
+ 'ends_with?': {
10713
+ title: 'ends_with?',
10714
+ category: 'Sequence',
10715
+ linkName: 'ends_with-question',
10716
+ clojureDocs: null,
10717
+ returns: {
10718
+ type: 'boolean',
10719
+ },
10720
+ args: {
10721
+ seq: {
10722
+ type: 'sequence',
10723
+ },
10724
+ suffix: {
10725
+ type: 'sequence',
11140
10726
  },
11141
10727
  },
11142
10728
  variants: [
11143
- { argumentNames: ['seq', 'n'] },
11144
- { argumentNames: ['seq', 'n', 'step'] },
11145
- { argumentNames: ['seq', 'n', 'step', 'pad'] },
10729
+ { argumentNames: ['seq', 'suffix'] },
11146
10730
  ],
11147
- description: 'Returns an array of sequences of $n items each, at offsets $step apart. If $step is not supplied, defaults to $n. If a $pad array is supplied, use its elements as necessary to complete last partition upto $n items. In case there are not enough padding elements, return a partition with less than $n items.',
10731
+ description: 'Returns `true` if $seq ends with $suffix, otherwise `false`.',
11148
10732
  examples: [
11149
- '(partition (range 20) 4)',
11150
- '(partition (range 22) 4)',
11151
- '(partition (range 20) 4 6)',
11152
- '(partition (range 20) 4 3)',
11153
- '(partition (range 20) 3 6 [:a])',
11154
- '(partition (range 20) 4 6 [:a])',
11155
- '(partition (range 20) 4 6 [:a :b :c :d])',
11156
- '(partition [:a :b :c :d :e :f] 3 1)',
11157
- '(partition [1 2 3 4] 10)',
11158
- '(partition [1 2 3 4] 10 10)',
11159
- '(partition [1 2 3 4] 10 10 [])',
11160
- '(partition [1 2 3 4] 10 10 nil)',
11161
- '(partition "superfragilistic" 5)',
11162
- '(partition "superfragilistic" 5 5 nil)',
11163
- '(def foo [5 6 7 8]) (partition foo 2 1 foo)',
10733
+ '(ends_with? [1 2 3 4 5] 5)',
10734
+ '(ends_with? [1 2 3 4 5] [5])',
10735
+ '(ends_with? "Albert" "rt")',
10736
+ '(ends_with? "Albert" "RT")',
11164
10737
  ],
11165
10738
  },
11166
- partition_all: {
11167
- title: 'partition_all',
10739
+ 'interleave': {
10740
+ title: 'interleave',
11168
10741
  category: 'Sequence',
11169
- linkName: 'partition_all',
10742
+ linkName: 'interleave',
10743
+ clojureDocs: null,
11170
10744
  returns: {
11171
10745
  type: 'sequence',
11172
10746
  },
11173
10747
  args: {
11174
- seq: {
10748
+ seqs: {
11175
10749
  type: 'sequence',
11176
- },
11177
- n: {
11178
- type: 'number',
11179
- },
11180
- step: {
11181
- type: 'number',
10750
+ array: true,
11182
10751
  },
11183
10752
  },
11184
10753
  variants: [
11185
- { argumentNames: ['seq', 'n'] },
11186
- { argumentNames: ['seq', 'n', 'step'] },
10754
+ { argumentNames: ['seqs'] },
11187
10755
  ],
11188
- description: 'Returns an array of sequences like partition, but may include partitions with fewer than n items at the end.',
10756
+ description: 'Returns a sequence of the first item from each of the $seqs, then the second item from each of the $seqs, until all items from the shortest seq are exhausted.',
11189
10757
  examples: [
11190
- '(partition_all [0 1 2 3 4 5 6 7 8 9] 4)',
11191
- '(partition [0 1 2 3 4 5 6 7 8 9] 4)',
11192
- '(partition_all [0 1 2 3 4 5 6 7 8 9] 2 4)',
10758
+ '(interleave [1 2 3] [4 5 6])',
10759
+ '(interleave [1 2 3] [4 5 6] [7 8 9])',
10760
+ '(interleave [1 2 3] [4 5 6] [7 8])',
10761
+ '(interleave [1 2 3] [4 5 6] [7])',
10762
+ '(interleave [1 2 3] [4 5 6] [])',
10763
+ '(interleave [1 2 3] [])',
10764
+ '(interleave [])',
11193
10765
  ],
11194
10766
  },
11195
- partition_by: {
11196
- title: 'partition_by',
10767
+ 'interpose': {
10768
+ title: 'interpose',
11197
10769
  category: 'Sequence',
11198
- linkName: 'partition_by',
10770
+ linkName: 'interpose',
10771
+ clojureDocs: null,
11199
10772
  returns: {
11200
10773
  type: 'sequence',
11201
10774
  },
@@ -11203,18 +10776,18 @@ var sequenceReference = {
11203
10776
  seq: {
11204
10777
  type: 'sequence',
11205
10778
  },
11206
- fn: {
11207
- type: 'function',
10779
+ separator: {
10780
+ type: 'any',
11208
10781
  },
11209
10782
  },
11210
10783
  variants: [
11211
- { argumentNames: ['seq', 'fn'] },
10784
+ { argumentNames: ['seq', 'separator'] },
11212
10785
  ],
11213
- description: 'Applies $fn to each value in $seq, splitting it each time $fn returns a new value. Returns an array of sequences.',
10786
+ description: 'Returns a sequence of the elements of $seq separated by $separator. If $seq is a string, the separator must be a string.',
11214
10787
  examples: [
11215
- '(partition_by [1 2 3 4 5] #(== 3 %1))',
11216
- '(partition_by [1 1 1 2 2 3 3] odd?)',
11217
- '(partition_by "Leeeeeerrroyyy" identity)',
10788
+ '(interpose :a [1 2 3 4 5])',
10789
+ '(interpose " " ["Albert" "Mojir" "Nina"])',
10790
+ '(interpose "." "Albert")',
11218
10791
  ],
11219
10792
  },
11220
10793
  };
@@ -13811,12 +13384,12 @@ var regularExpressionReference = {
13811
13384
  ],
13812
13385
  description: "Matches $s against regular expression $r.\nIf $s is a string and matches the regular expression, a `match`-array is returned, otherwise `nil` is returned.",
13813
13386
  examples: [
13814
- '(match (regexp "^\\s*(.*)$") " A string")',
13815
- '(match #"albert"i "My name is Albert")',
13816
- '(match #"albert"i "My name is Ben")',
13817
- '(match #"albert"i nil)',
13818
- '(match #"albert"i 1)',
13819
- '(match #"albert"i {})',
13387
+ '(match " A string" (regexp "^\\s*(.*)$"))',
13388
+ '(match "My name is Albert" #"albert"i)',
13389
+ '(match "My name is Ben" #"albert"i)',
13390
+ '(match nil #"albert"i)',
13391
+ '(match 1 #"albert"i)',
13392
+ '(match {} #"albert"i)',
13820
13393
  ],
13821
13394
  },
13822
13395
  replace: {
@@ -13833,7 +13406,7 @@ var regularExpressionReference = {
13833
13406
  type: 'string',
13834
13407
  },
13835
13408
  r: {
13836
- type: 'regexp',
13409
+ type: ['regexp', 'string'],
13837
13410
  },
13838
13411
  x: {
13839
13412
  type: 'string',
@@ -13842,13 +13415,49 @@ var regularExpressionReference = {
13842
13415
  variants: [
13843
13416
  { argumentNames: ['s', 'r', 'x'] },
13844
13417
  ],
13845
- description: 'Returns a new string with some or all matches of regular expression $r replaced by $x.',
13418
+ description: 'Returns a new string with first match of regular expression $r replaced by $x.',
13846
13419
  examples: [
13847
- '(replace "Duck" (regexp :u) :i)',
13420
+ '(replace "Duck duck" "u" :i)',
13421
+ '(replace "Duck duck" (regexp :u) :i)',
13422
+ '(replace "abcABC" (regexp :a "i") "-")',
13848
13423
  '(replace "abcABC" (regexp :a "gi") "-")',
13424
+ '(replace "abcABC" #"a"i "-")',
13849
13425
  '(replace "abcABC" #"a"gi "-")',
13850
13426
  ],
13851
13427
  },
13428
+ replace_all: {
13429
+ title: 'replace_all',
13430
+ category: 'Regular expression',
13431
+ linkName: 'replace_all',
13432
+ clojureDocs: null,
13433
+ returns: {
13434
+ type: 'any',
13435
+ array: true,
13436
+ },
13437
+ args: {
13438
+ s: {
13439
+ type: 'string',
13440
+ },
13441
+ r: {
13442
+ type: ['regexp', 'string'],
13443
+ },
13444
+ x: {
13445
+ type: 'string',
13446
+ },
13447
+ },
13448
+ variants: [
13449
+ { argumentNames: ['s', 'r', 'x'] },
13450
+ ],
13451
+ description: 'Returns a new string with all matches of regular expression $r replaced by $x.',
13452
+ examples: [
13453
+ '(replace_all "Duck duck" "u" :i)',
13454
+ '(replace_all "Duck duck" (regexp :u) :i)',
13455
+ '(replace_all "abcABC" (regexp :a "i") "-")',
13456
+ '(replace_all "abcABC" (regexp :a "gi") "-")',
13457
+ '(replace_all "abcABC" #"a"i "-")',
13458
+ '(replace_all "abcABC" #"a"gi "-")',
13459
+ ],
13460
+ },
13852
13461
  };
13853
13462
 
13854
13463
  var specialExpressionsReference = {
@@ -13927,32 +13536,6 @@ var specialExpressionsReference = {
13927
13536
  '(def a (object :x 10 :y true :z "A string"))',
13928
13537
  ],
13929
13538
  },
13930
- 'defs': {
13931
- title: 'defs',
13932
- category: 'Special expression',
13933
- linkName: 'defs',
13934
- clojureDocs: null,
13935
- returns: {
13936
- type: 'any',
13937
- },
13938
- args: {
13939
- name: {
13940
- type: '*expression',
13941
- },
13942
- value: {
13943
- type: '*expression',
13944
- },
13945
- },
13946
- variants: [
13947
- { argumentNames: ['name', 'value'] },
13948
- ],
13949
- description: "\nCreates a variable with name set to $name evaluated and value set to $value.\n\nIf a variable with name $name is already defined, an error is thrown.",
13950
- examples: [
13951
- '(defs :a :b)',
13952
- "\n(defs (str :a :1) (object :x 10 :y true :z \"A string\"))\na1",
13953
- "\n(defs :a :b)\n(defs a :c)\nb",
13954
- ],
13955
- },
13956
13539
  'let': {
13957
13540
  title: 'let',
13958
13541
  category: 'Special expression',
@@ -13965,97 +13548,12 @@ var specialExpressionsReference = {
13965
13548
  type: '*binding',
13966
13549
  rest: true,
13967
13550
  },
13968
- expressions: {
13969
- type: '*expression',
13970
- rest: true,
13971
- },
13972
- },
13973
- variants: [
13974
- { argumentNames: ['bindings', 'expressions'] },
13975
- ],
13976
- description: "\nBinds local variables. The variables lives only within $expressions.\nIt returns evaluation of the last expression in $expressions.",
13977
- examples: ["\n (let [a (+ 1 2 3 4) \n b (* 1 2 3 4)]\n (write! a b))"],
13978
- },
13979
- 'if_let': {
13980
- title: 'if_let',
13981
- category: 'Special expression',
13982
- linkName: 'if_let',
13983
- returns: {
13984
- type: 'any',
13985
- },
13986
- args: {
13987
- 'binding': {
13988
- type: '*binding',
13989
- },
13990
- 'then-expr': {
13991
- type: '*expression',
13992
- },
13993
- 'else-expr': {
13994
- type: '*expression',
13995
- },
13996
- },
13997
- variants: [
13998
- { argumentNames: ['binding', 'then-expr'] },
13999
- { argumentNames: ['binding', 'then-expr', 'else-expr'] },
14000
- ],
14001
- description: "\nBinds one local variable. If it evaluates to a truthy value\n$then-expr is executed with the variable accessable.\nIf the bound variable evaluates to false, the $else-expr is evaluated\n(without variable accessable).",
14002
- examples: [
14003
- "\n(if_let [a (> (count \"Albert\") 4)]\n (write! (str a \", is big enough\"))\n (write! \"Sorry, not big enough.\"))",
14004
- "\n(if_let [a (> (count \"Albert\") 10)]\n (write! (str a \", is big enough\"))\n (write! \"Sorry, not big enough.\"))",
14005
- ],
14006
- },
14007
- 'when_let': {
14008
- title: 'when_let',
14009
- category: 'Special expression',
14010
- linkName: 'when_let',
14011
- returns: {
14012
- type: 'any',
14013
- },
14014
- args: {
14015
- binding: {
14016
- type: '*binding',
14017
- },
14018
- expressions: {
14019
- type: '*expression',
14020
- rest: true,
14021
- },
14022
- },
14023
- variants: [
14024
- { argumentNames: ['binding', 'expressions'] },
14025
- ],
14026
- description: "\nBinds one local variable. If it evaluates to a truthy value\n$expressions is executed with the variable accessable.\nIf the bound variable evaluates to a falsy value, `nil` is returned.",
14027
- examples: [
14028
- "\n(when_let [a (> (count \"Albert\") 4)]\n (write! a))",
14029
- ],
14030
- },
14031
- 'when_first': {
14032
- title: 'when_first',
14033
- category: 'Special expression',
14034
- linkName: 'when_first',
14035
- returns: {
14036
- type: 'any',
14037
- },
14038
- args: {
14039
- binding: {
14040
- type: '*binding',
14041
- rest: true,
14042
- },
14043
- expressions: {
14044
- type: '*expression',
14045
- rest: true,
14046
- },
14047
13551
  },
14048
13552
  variants: [
14049
- { argumentNames: ['binding', 'expressions'] },
14050
- ],
14051
- description: 'When the binding value in $binding is a non empty sequence, the first element of that sequence (instead of the sequence itself) is bound to the variable.',
14052
- examples: [
14053
- "\n(when_first [x [1 2 3]]\n (write! x)\n x)",
14054
- "\n(when_first [x \"Albert\"]\n (write! x)\n x)",
14055
- "\n(when_first [x [0]]\n (write! x)\n x)",
14056
- "\n(when_first [x [nil]]\n (write! x)\n x)",
14057
- "\n(when_first [x []]\n (write! x)\n x)",
13553
+ { argumentNames: ['bindings'] },
14058
13554
  ],
13555
+ description: "\nBinds local variables.",
13556
+ examples: ["\n(let [a (+ 1 2 3 4) \n b (* 1 2 3 4)])\n(write! a b)"],
14059
13557
  },
14060
13558
  'fn': {
14061
13559
  title: 'fn',
@@ -14111,36 +13609,6 @@ var specialExpressionsReference = {
14111
13609
  "\n(defn sumOfSquares [& s]\n (apply\n +\n (map\n (fn [x] (* x x))\n s)))\n(sumOfSquares 1 2 3 4 5)",
14112
13610
  ],
14113
13611
  },
14114
- 'defns': {
14115
- title: 'defns',
14116
- category: 'Special expression',
14117
- linkName: 'defns',
14118
- clojureDocs: null,
14119
- returns: {
14120
- type: 'function',
14121
- },
14122
- args: {
14123
- name: {
14124
- type: '*expression',
14125
- },
14126
- args: {
14127
- type: '*arguments',
14128
- },
14129
- expressions: {
14130
- type: '*expression',
14131
- rest: true,
14132
- },
14133
- },
14134
- variants: [
14135
- { argumentNames: ['name', 'args', 'expressions'] },
14136
- ],
14137
- description: 'Creates a named global function with its name set to $name evaluated. When called, evaluation of the last expression in the body is returned.',
14138
- examples: [
14139
- "\n(defns \"hyp\" [a b]\n (sqrt\n (+\n (* a a)\n (* b b))))\nhyp",
14140
- "\n(defns\n (str :h :y :p)\n [a b]\n (sqrt\n (+\n (* a a)\n (* b b))))\n(hyp 3 4)",
14141
- "\n(defns \"sumOfSquares\" [& s]\n (apply\n +\n (map\n (fn [x] (* x x))\n s)))\n(sumOfSquares 1 2 3 4 5)",
14142
- ],
14143
- },
14144
13612
  'try': {
14145
13613
  title: 'try',
14146
13614
  category: 'Special expression',
@@ -14219,10 +13687,11 @@ var specialExpressionsReference = {
14219
13687
  '(if false (write! "TRUE"))',
14220
13688
  ],
14221
13689
  },
14222
- 'if_not': {
14223
- title: 'if_not',
13690
+ 'unless': {
13691
+ title: 'unless',
14224
13692
  category: 'Special expression',
14225
- linkName: 'if_not',
13693
+ linkName: 'unless',
13694
+ clojureDocs: 'if-not',
14226
13695
  returns: {
14227
13696
  type: 'any',
14228
13697
  },
@@ -14243,10 +13712,10 @@ var specialExpressionsReference = {
14243
13712
  ],
14244
13713
  description: 'Either $then-expr or $else-expr branch is taken. $then-expr is selected when $test is falsy. If $test is truthy $else-expr is executed, if no $else-expr exists, `nil` is returned.',
14245
13714
  examples: [
14246
- '(if_not true (write! "TRUE") (write! "FALSE"))',
14247
- '(if_not false (write! "TRUE") (write! "FALSE"))',
14248
- '(if_not true (write! "TRUE"))',
14249
- '(if_not false (write! "TRUE"))',
13715
+ '(unless true (write! "TRUE") (write! "FALSE"))',
13716
+ '(unless false (write! "TRUE") (write! "FALSE"))',
13717
+ '(unless true (write! "TRUE"))',
13718
+ '(unless false (write! "TRUE"))',
14250
13719
  ],
14251
13720
  },
14252
13721
  'cond': {
@@ -14296,60 +13765,6 @@ var specialExpressionsReference = {
14296
13765
  "\n(switch 3\n 1 (write! \"FALSE\")\n 2 (write! \"nil\"))",
14297
13766
  ],
14298
13767
  },
14299
- 'when': {
14300
- title: 'when',
14301
- category: 'Special expression',
14302
- linkName: 'when',
14303
- returns: {
14304
- type: 'any',
14305
- },
14306
- args: {
14307
- test: {
14308
- type: '*expression',
14309
- },
14310
- expressions: {
14311
- type: '*expression',
14312
- rest: true,
14313
- },
14314
- },
14315
- variants: [
14316
- { argumentNames: ['test', 'expressions'] },
14317
- ],
14318
- description: "If $test yields a thruthy value, the expressions are evaluated\nand the value returned by the last expression is returned.\nOtherwise, if $test yields a falsy value, the expressions are not evaluated,\nand `nil` is returned. If no $expressions are provided, `nil` is returned.",
14319
- examples: [
14320
- "(when true\n (write! \"Hi\")\n (write! \"There\"))",
14321
- "(when false\n (write! \"Hi\")\n (write! \"There\"))",
14322
- '(when true)',
14323
- '(when false)',
14324
- ],
14325
- },
14326
- 'when_not': {
14327
- title: 'when_not',
14328
- category: 'Special expression',
14329
- linkName: 'when_not',
14330
- returns: {
14331
- type: 'any',
14332
- },
14333
- args: {
14334
- test: {
14335
- type: '*expression',
14336
- },
14337
- expressions: {
14338
- type: '*expression',
14339
- rest: true,
14340
- },
14341
- },
14342
- variants: [
14343
- { argumentNames: ['test', 'expressions'] },
14344
- ],
14345
- description: "If $test yields a falsy value, the expressions are evaluated\nand the value returned by the last `expression` is returned.\nOtherwise, if $test yields a truthy value, the $expressions are not evaluated,\nand `nil` is returned. If no `expression` is provided, `nil` is returned.",
14346
- examples: [
14347
- '(when_not true (write! "Hi") (write! "There"))',
14348
- '(when_not false (write! "Hi") (write! "There"))',
14349
- '(when_not true)',
14350
- '(when_not false)',
14351
- ],
14352
- },
14353
13768
  'comment': {
14354
13769
  title: 'comment',
14355
13770
  category: 'Special expression',
@@ -14409,9 +13824,9 @@ var specialExpressionsReference = {
14409
13824
  ],
14410
13825
  description: 'Recursevly calls enclosing function or loop with its evaluated $expressions.',
14411
13826
  examples: [
14412
- "\n(defn foo [n]\n (write! n)\n (when (! (zero? n))\n (recur\n (dec n))))\n(foo 3)",
14413
- "\n(\n (fn [n]\n (write! n)\n (when (! (zero? n))\n (recur\n (dec n))))\n 3)",
14414
- "\n(\n loop [n 3]\n (write! n)\n (when\n (! (zero? n))\n (recur (dec n))))",
13827
+ "\n(defn foo [n]\n (write! n)\n (if (! (zero? n))\n (recur\n (dec n))))\n(foo 3)",
13828
+ "\n(\n (fn [n]\n (write! n)\n (if (! (zero? n))\n (recur\n (dec n))))\n 3)",
13829
+ "\n(\n loop [n 3]\n (write! n)\n (if\n (! (zero? n))\n (recur (dec n))))",
14415
13830
  ],
14416
13831
  },
14417
13832
  'loop': {
@@ -14436,7 +13851,7 @@ var specialExpressionsReference = {
14436
13851
  ],
14437
13852
  description: 'Executes $expressions with initial $bindings. The $bindings will be replaced with the recur parameters for subsequent recursions.',
14438
13853
  examples: [
14439
- "\n(loop [n 3]\n (write! n)\n (when\n (! (zero? n))\n (recur (dec n))))",
13854
+ "\n(loop [n 3]\n (write! n)\n (if\n (! (zero? n))\n (recur (dec n))))",
14440
13855
  "\n(loop [n 3]\n (write! n)\n (if\n (! (zero? n))\n (recur (dec n))\n n))",
14441
13856
  ],
14442
13857
  },
@@ -14495,10 +13910,10 @@ var specialExpressionsReference = {
14495
13910
  "\n(for\n [x [1 2 3] y [1 2 3] z [1 2 3]\n &while (<= x y)]\n \n [x y z])",
14496
13911
  ],
14497
13912
  },
14498
- 'declared?': {
14499
- title: 'declared?',
13913
+ 'defined?': {
13914
+ title: 'defined?',
14500
13915
  category: 'Special expression',
14501
- linkName: 'declared-question',
13916
+ linkName: 'defined-question',
14502
13917
  returns: {
14503
13918
  type: 'boolean',
14504
13919
  },
@@ -14512,11 +13927,11 @@ var specialExpressionsReference = {
14512
13927
  ],
14513
13928
  description: 'Returns `true` if $n is a declared variable or a builtin function, otherwise `false`.',
14514
13929
  examples: [
14515
- '(declared? foo)',
14516
- "\n(def foo :foo)\n(declared? foo)",
14517
- '(declared? +)',
14518
- "\n(def foo nil)\n(declared? foo)",
14519
- '(declared? if)',
13930
+ '(defined? foo)',
13931
+ "\n(def foo :foo)\n(defined? foo)",
13932
+ '(defined? +)',
13933
+ "\n(def foo nil)\n(defined? foo)",
13934
+ '(defined? if)',
14520
13935
  ],
14521
13936
  },
14522
13937
  '??': {
@@ -14862,6 +14277,30 @@ var stringReference = {
14862
14277
  '(map number (split "0123456789" "" 5))',
14863
14278
  ],
14864
14279
  },
14280
+ 'split_lines': {
14281
+ title: 'split_lines',
14282
+ category: 'String',
14283
+ linkName: 'split_lines',
14284
+ clojureDocs: null,
14285
+ returns: {
14286
+ type: 'string',
14287
+ },
14288
+ args: {
14289
+ s: {
14290
+ type: 'string',
14291
+ },
14292
+ },
14293
+ variants: [
14294
+ { argumentNames: ['s'] },
14295
+ ],
14296
+ description: 'Divides $s into an array of substrings, each representing a line.',
14297
+ examples: [
14298
+ '(split_lines "Albert\nMojir\n")',
14299
+ '(split_lines "Albert\n\nMojir")',
14300
+ '(split_lines "Albert\nMojir\n\n")',
14301
+ '(split_lines "")',
14302
+ ],
14303
+ },
14865
14304
  'template': {
14866
14305
  title: 'template',
14867
14306
  category: 'String',
@@ -15078,6 +14517,55 @@ var stringReference = {
15078
14517
  '(++)',
15079
14518
  ],
15080
14519
  },
14520
+ 'capitalize': {
14521
+ title: 'capitalize',
14522
+ category: 'String',
14523
+ linkName: 'capitalize',
14524
+ clojureDocs: 'clojure.string/capitalize',
14525
+ returns: {
14526
+ type: 'string',
14527
+ },
14528
+ args: {
14529
+ s: {
14530
+ type: 'string',
14531
+ },
14532
+ },
14533
+ variants: [
14534
+ { argumentNames: ['s'] },
14535
+ ],
14536
+ description: 'Returns $s with the first character converted to uppercase and the rest to lowercase.',
14537
+ examples: [
14538
+ '(capitalize "albert")',
14539
+ '(capitalize "ALBERT")',
14540
+ '(capitalize "aLBERT")',
14541
+ '(capitalize "")',
14542
+ ],
14543
+ },
14544
+ 'blank?': {
14545
+ title: 'blank?',
14546
+ category: 'String',
14547
+ linkName: 'blank-question',
14548
+ clojureDocs: 'clojure.string/blank_q',
14549
+ returns: {
14550
+ type: 'boolean',
14551
+ },
14552
+ args: {
14553
+ s: {
14554
+ type: ['string', 'null'],
14555
+ },
14556
+ },
14557
+ variants: [
14558
+ { argumentNames: ['s'] },
14559
+ ],
14560
+ description: 'Returns true if $s is null or only contains whitespace characters.',
14561
+ examples: [
14562
+ '(blank? "")',
14563
+ '(blank? null)',
14564
+ '(blank? "\n")',
14565
+ '(blank? " ")',
14566
+ '(blank? ".")',
14567
+ ],
14568
+ },
15081
14569
  };
15082
14570
 
15083
14571
  var bitwiseReference = { '<<': {
@@ -15641,6 +15129,7 @@ var api = {
15641
15129
  'filter',
15642
15130
  'position',
15643
15131
  'index_of',
15132
+ 'last_index_of',
15644
15133
  'some',
15645
15134
  'reverse',
15646
15135
  'first',
@@ -15668,6 +15157,10 @@ var api = {
15668
15157
  'partition',
15669
15158
  'partition_all',
15670
15159
  'partition_by',
15160
+ 'starts_with?',
15161
+ 'ends_with?',
15162
+ 'interleave',
15163
+ 'interpose',
15671
15164
  ],
15672
15165
  math: [
15673
15166
  '+',
@@ -15788,34 +15281,28 @@ var api = {
15788
15281
  'regexp',
15789
15282
  'match',
15790
15283
  'replace',
15284
+ 'replace_all',
15791
15285
  ],
15792
15286
  specialExpressions: [
15793
15287
  '&&',
15794
15288
  '||',
15795
15289
  'def',
15796
- 'defs',
15797
15290
  'let',
15798
- 'if_let',
15799
- 'when_let',
15800
- 'when_first',
15801
15291
  'fn',
15802
15292
  'defn',
15803
- 'defns',
15804
15293
  'try',
15805
15294
  'throw',
15806
15295
  'if',
15807
- 'if_not',
15296
+ 'unless',
15808
15297
  'cond',
15809
15298
  'switch',
15810
- 'when',
15811
- 'when_not',
15812
15299
  'comment',
15813
15300
  'do',
15814
15301
  'recur',
15815
15302
  'loop',
15816
15303
  'doseq',
15817
15304
  'for',
15818
- 'declared?',
15305
+ 'defined?',
15819
15306
  '??',
15820
15307
  ],
15821
15308
  string: [
@@ -15831,6 +15318,7 @@ var api = {
15831
15318
  'pad_left',
15832
15319
  'pad_right',
15833
15320
  'split',
15321
+ 'split_lines',
15834
15322
  'template',
15835
15323
  'to_char_code',
15836
15324
  'from_char_code',
@@ -15840,6 +15328,8 @@ var api = {
15840
15328
  'decode_uri_component',
15841
15329
  'join',
15842
15330
  '++',
15331
+ 'capitalize',
15332
+ 'blank?',
15843
15333
  ],
15844
15334
  bitwise: [
15845
15335
  '<<',