@mojir/lits 2.0.15 → 2.0.16

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 (94) hide show
  1. package/dist/cli/cli.js +318 -1113
  2. package/dist/cli/reference/api.d.ts +2 -2
  3. package/dist/cli/src/analyze/index.d.ts +0 -2
  4. package/dist/cli/src/builtin/index.d.ts +3 -8
  5. package/dist/cli/src/builtin/specialExpressions/declared.d.ts +1 -1
  6. package/dist/cli/src/builtin/specialExpressions/try.d.ts +1 -1
  7. package/dist/{src/builtin/specialExpressions/if_not.d.ts → cli/src/builtin/specialExpressions/unless.d.ts} +2 -2
  8. package/dist/cli/src/evaluator/ContextStack.d.ts +2 -0
  9. package/dist/cli/src/parser/AlgebraicParser.d.ts +7 -2
  10. package/dist/cli/src/tokenizer/algebraic/algebraicReservedNames.d.ts +14 -26
  11. package/dist/cli/src/tokenizer/algebraic/algebraicTokens.d.ts +3 -3
  12. package/dist/index.esm.js +318 -1113
  13. package/dist/index.esm.js.map +1 -1
  14. package/dist/index.js +318 -1113
  15. package/dist/index.js.map +1 -1
  16. package/dist/lits.iife.js +318 -1113
  17. package/dist/lits.iife.js.map +1 -1
  18. package/dist/reference/api.d.ts +2 -2
  19. package/dist/src/analyze/index.d.ts +0 -2
  20. package/dist/src/builtin/index.d.ts +3 -8
  21. package/dist/src/builtin/specialExpressions/declared.d.ts +1 -1
  22. package/dist/src/builtin/specialExpressions/try.d.ts +1 -1
  23. package/dist/{cli/src/builtin/specialExpressions/if_not.d.ts → src/builtin/specialExpressions/unless.d.ts} +2 -2
  24. package/dist/src/evaluator/ContextStack.d.ts +2 -0
  25. package/dist/src/parser/AlgebraicParser.d.ts +7 -2
  26. package/dist/src/tokenizer/algebraic/algebraicReservedNames.d.ts +14 -26
  27. package/dist/src/tokenizer/algebraic/algebraicTokens.d.ts +3 -3
  28. package/dist/testFramework.esm.js +285 -937
  29. package/dist/testFramework.esm.js.map +1 -1
  30. package/dist/testFramework.js +285 -937
  31. package/dist/testFramework.js.map +1 -1
  32. package/package.json +1 -1
  33. package/dist/cli/src/analyze/calculateOutcomes/calculateAndOutcomes.d.ts +0 -3
  34. package/dist/cli/src/analyze/calculateOutcomes/calculateCommentOutcomes.d.ts +0 -3
  35. package/dist/cli/src/analyze/calculateOutcomes/calculateCondOutcomes.d.ts +0 -3
  36. package/dist/cli/src/analyze/calculateOutcomes/calculateDeclaredOutcomes.d.ts +0 -3
  37. package/dist/cli/src/analyze/calculateOutcomes/calculateDefOutcomes.d.ts +0 -3
  38. package/dist/cli/src/analyze/calculateOutcomes/calculateDefsOutcomes.d.ts +0 -3
  39. package/dist/cli/src/analyze/calculateOutcomes/calculateDoOutcomes.d.ts +0 -3
  40. package/dist/cli/src/analyze/calculateOutcomes/calculateFunctionOutcomes.d.ts +0 -5
  41. package/dist/cli/src/analyze/calculateOutcomes/calculateIfLetOutcomes.d.ts +0 -3
  42. package/dist/cli/src/analyze/calculateOutcomes/calculateIfNotOutcomes.d.ts +0 -3
  43. package/dist/cli/src/analyze/calculateOutcomes/calculateIfOutcomes.d.ts +0 -3
  44. package/dist/cli/src/analyze/calculateOutcomes/calculateLetOutcomes.d.ts +0 -3
  45. package/dist/cli/src/analyze/calculateOutcomes/calculateLoopOutcomes.d.ts +0 -3
  46. package/dist/cli/src/analyze/calculateOutcomes/calculateLoopsOutcomes.d.ts +0 -4
  47. package/dist/cli/src/analyze/calculateOutcomes/calculateOrOutcomes.d.ts +0 -3
  48. package/dist/cli/src/analyze/calculateOutcomes/calculateQqOutcomes.d.ts +0 -3
  49. package/dist/cli/src/analyze/calculateOutcomes/calculateRecurOutcomes.d.ts +0 -3
  50. package/dist/cli/src/analyze/calculateOutcomes/calculateSwitchOutcomes.d.ts +0 -3
  51. package/dist/cli/src/analyze/calculateOutcomes/calculateThrowOutcomes.d.ts +0 -3
  52. package/dist/cli/src/analyze/calculateOutcomes/calculateTryOutcomes.d.ts +0 -3
  53. package/dist/cli/src/analyze/calculateOutcomes/calculateWhenFirstOutcomes.d.ts +0 -3
  54. package/dist/cli/src/analyze/calculateOutcomes/calculateWhenLetOutcomes.d.ts +0 -3
  55. package/dist/cli/src/analyze/calculateOutcomes/calculateWhenNotOutcomes.d.ts +0 -3
  56. package/dist/cli/src/analyze/calculateOutcomes/calculateWhenOutcomes.d.ts +0 -3
  57. package/dist/cli/src/analyze/calculateOutcomes/index.d.ts +0 -18
  58. package/dist/cli/src/analyze/calculateOutcomes/specialExpressionCalculators.d.ts +0 -55
  59. package/dist/cli/src/builtin/specialExpressions/if_let.d.ts +0 -7
  60. package/dist/cli/src/builtin/specialExpressions/when.d.ts +0 -6
  61. package/dist/cli/src/builtin/specialExpressions/when_first.d.ts +0 -7
  62. package/dist/cli/src/builtin/specialExpressions/when_let.d.ts +0 -7
  63. package/dist/cli/src/builtin/specialExpressions/when_not.d.ts +0 -6
  64. package/dist/src/analyze/calculateOutcomes/calculateAndOutcomes.d.ts +0 -3
  65. package/dist/src/analyze/calculateOutcomes/calculateCommentOutcomes.d.ts +0 -3
  66. package/dist/src/analyze/calculateOutcomes/calculateCondOutcomes.d.ts +0 -3
  67. package/dist/src/analyze/calculateOutcomes/calculateDeclaredOutcomes.d.ts +0 -3
  68. package/dist/src/analyze/calculateOutcomes/calculateDefOutcomes.d.ts +0 -3
  69. package/dist/src/analyze/calculateOutcomes/calculateDefsOutcomes.d.ts +0 -3
  70. package/dist/src/analyze/calculateOutcomes/calculateDoOutcomes.d.ts +0 -3
  71. package/dist/src/analyze/calculateOutcomes/calculateFunctionOutcomes.d.ts +0 -5
  72. package/dist/src/analyze/calculateOutcomes/calculateIfLetOutcomes.d.ts +0 -3
  73. package/dist/src/analyze/calculateOutcomes/calculateIfNotOutcomes.d.ts +0 -3
  74. package/dist/src/analyze/calculateOutcomes/calculateIfOutcomes.d.ts +0 -3
  75. package/dist/src/analyze/calculateOutcomes/calculateLetOutcomes.d.ts +0 -3
  76. package/dist/src/analyze/calculateOutcomes/calculateLoopOutcomes.d.ts +0 -3
  77. package/dist/src/analyze/calculateOutcomes/calculateLoopsOutcomes.d.ts +0 -4
  78. package/dist/src/analyze/calculateOutcomes/calculateOrOutcomes.d.ts +0 -3
  79. package/dist/src/analyze/calculateOutcomes/calculateQqOutcomes.d.ts +0 -3
  80. package/dist/src/analyze/calculateOutcomes/calculateRecurOutcomes.d.ts +0 -3
  81. package/dist/src/analyze/calculateOutcomes/calculateSwitchOutcomes.d.ts +0 -3
  82. package/dist/src/analyze/calculateOutcomes/calculateThrowOutcomes.d.ts +0 -3
  83. package/dist/src/analyze/calculateOutcomes/calculateTryOutcomes.d.ts +0 -3
  84. package/dist/src/analyze/calculateOutcomes/calculateWhenFirstOutcomes.d.ts +0 -3
  85. package/dist/src/analyze/calculateOutcomes/calculateWhenLetOutcomes.d.ts +0 -3
  86. package/dist/src/analyze/calculateOutcomes/calculateWhenNotOutcomes.d.ts +0 -3
  87. package/dist/src/analyze/calculateOutcomes/calculateWhenOutcomes.d.ts +0 -3
  88. package/dist/src/analyze/calculateOutcomes/index.d.ts +0 -18
  89. package/dist/src/analyze/calculateOutcomes/specialExpressionCalculators.d.ts +0 -55
  90. package/dist/src/builtin/specialExpressions/if_let.d.ts +0 -7
  91. package/dist/src/builtin/specialExpressions/when.d.ts +0 -6
  92. package/dist/src/builtin/specialExpressions/when_first.d.ts +0 -7
  93. package/dist/src/builtin/specialExpressions/when_let.d.ts +0 -7
  94. package/dist/src/builtin/specialExpressions/when_not.d.ts +0 -6
package/dist/lits.iife.js CHANGED
@@ -429,20 +429,15 @@ var Lits = (function (exports) {
429
429
  '&&',
430
430
  'comment',
431
431
  'cond',
432
- 'declared?',
432
+ 'defined?',
433
433
  'if',
434
- 'if_not',
434
+ 'unless',
435
435
  '||',
436
- 'when',
437
- 'when_not',
438
436
  'do',
439
437
  'throw',
440
438
  'let',
441
439
  'def',
442
440
  'defs',
443
- 'if_let',
444
- 'when_let',
445
- 'when_first',
446
441
  'fn',
447
442
  'defn',
448
443
  'defns',
@@ -468,16 +463,22 @@ var Lits = (function (exports) {
468
463
  function isSymbolicOperator(operator) {
469
464
  return symbolicOperatorSet.has(operator);
470
465
  }
471
- function isA_SymbolToken(token) {
472
- return (token === null || token === void 0 ? void 0 : token[0]) === 'A_Symbol';
466
+ function isA_SymbolToken(token, symbolName) {
467
+ if ((token === null || token === void 0 ? void 0 : token[0]) !== 'A_Symbol') {
468
+ return false;
469
+ }
470
+ if (symbolName && token[1] !== symbolName) {
471
+ return false;
472
+ }
473
+ return true;
473
474
  }
474
- function assertA_SymbolToken(token) {
475
- if (!isA_SymbolToken(token)) {
475
+ function assertA_SymbolToken(token, symbolName) {
476
+ if (!isA_SymbolToken(token, symbolName)) {
476
477
  throwUnexpectedToken('A_Symbol', undefined, token);
477
478
  }
478
479
  }
479
- function asA_SymbolToken(token) {
480
- assertA_SymbolToken(token);
480
+ function asA_SymbolToken(token, symbolName) {
481
+ assertA_SymbolToken(token, symbolName);
481
482
  return token;
482
483
  }
483
484
  function isA_BinaryOperatorToken(token) {
@@ -760,7 +761,7 @@ var Lits = (function (exports) {
760
761
  removeOptions.removeCommenNodesFromArray(node.p);
761
762
  node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
762
763
  },
763
- 'declared?': function (node, removeOptions) {
764
+ 'defined?': function (node, removeOptions) {
764
765
  removeOptions.removeCommenNodesFromArray(node.p);
765
766
  node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
766
767
  },
@@ -781,12 +782,11 @@ var Lits = (function (exports) {
781
782
  'doseq': function (_node, _removeOptions) { },
782
783
  'fn': function (_node, _removeOptions) { },
783
784
  'for': function (_node, _removeOptions) { },
784
- 'if_let': function (_node, _removeOptions) { },
785
785
  'if': function (node, removeOptions) {
786
786
  removeOptions.removeCommenNodesFromArray(node.p);
787
787
  node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
788
788
  },
789
- 'if_not': function (node, removeOptions) {
789
+ 'unless': function (node, removeOptions) {
790
790
  removeOptions.removeCommenNodesFromArray(node.p);
791
791
  node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
792
792
  },
@@ -815,10 +815,6 @@ var Lits = (function (exports) {
815
815
  node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
816
816
  },
817
817
  'try': function (_node, _removeOptions) { },
818
- 'when_first': function (_node, _removeOptions) { },
819
- 'when_let': function (_node, _removeOptions) { },
820
- 'when': function (_node, _removeOptions) { },
821
- 'when_not': function (_node, _removeOptions) { },
822
818
  };
823
819
  function removeCommentNodesFromSpecialExpression(node, removeOptions) {
824
820
  var uncommenter = specialExpressionCommentRemovers[node.n];
@@ -4445,7 +4441,7 @@ var Lits = (function (exports) {
4445
4441
  };
4446
4442
 
4447
4443
  var declaredSpecialExpression = {
4448
- polishParse: getCommonPolishSpecialExpressionParser('declared?'),
4444
+ polishParse: getCommonPolishSpecialExpressionParser('defined?'),
4449
4445
  validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
4450
4446
  evaluate: function (node, contextStack) {
4451
4447
  var lookUpResult = contextStack.lookUp(node.p[0]);
@@ -4501,9 +4497,7 @@ var Lits = (function (exports) {
4501
4497
  var sourceCodeInfo = (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo;
4502
4498
  var name = node.p[0].v;
4503
4499
  assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
4504
- contextStack.globalContext[name] = {
4505
- value: evaluateAstNode(node.p[1], contextStack),
4506
- };
4500
+ contextStack.exportValue(name, evaluateAstNode(node.p[1], contextStack));
4507
4501
  return null;
4508
4502
  },
4509
4503
  findUnresolvedIdentifiers: function (node, contextStack, _a) {
@@ -4514,7 +4508,7 @@ var Lits = (function (exports) {
4514
4508
  var result = findUnresolvedIdentifiers([subNode], contextStack, builtin);
4515
4509
  var name = asSymbolNode(node.p[0]).v;
4516
4510
  assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
4517
- contextStack.globalContext[name] = { value: true };
4511
+ contextStack.exportValue(name, true);
4518
4512
  return result;
4519
4513
  },
4520
4514
  };
@@ -4540,9 +4534,7 @@ var Lits = (function (exports) {
4540
4534
  var name = evaluateAstNode(node.p[0], contextStack);
4541
4535
  assertString(name, sourceCodeInfo);
4542
4536
  assertNameNotDefined(name, contextStack, builtin, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
4543
- contextStack.globalContext[name] = {
4544
- value: evaluateAstNode(node.p[1], contextStack),
4545
- };
4537
+ contextStack.exportValue(name, evaluateAstNode(node.p[1], contextStack));
4546
4538
  return null;
4547
4539
  },
4548
4540
  findUnresolvedIdentifiers: function (node, contextStack, _a) {
@@ -4554,7 +4546,7 @@ var Lits = (function (exports) {
4554
4546
  var name = evaluateAstNode(node.p[0], contextStack);
4555
4547
  assertString(name, sourceCodeInfo);
4556
4548
  assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
4557
- contextStack.globalContext[name] = { value: true };
4549
+ contextStack.exportValue(name, true);
4558
4550
  return result;
4559
4551
  },
4560
4552
  };
@@ -4585,7 +4577,7 @@ var Lits = (function (exports) {
4585
4577
  },
4586
4578
  findUnresolvedIdentifiers: function (node, contextStack, _a) {
4587
4579
  var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
4588
- return findUnresolvedIdentifiers(node.p, contextStack, builtin);
4580
+ return findUnresolvedIdentifiers(node.p, contextStack.create({}), builtin);
4589
4581
  },
4590
4582
  };
4591
4583
 
@@ -4614,11 +4606,6 @@ var Lits = (function (exports) {
4614
4606
  function addAnalyzeResults(target, source) {
4615
4607
  source.forEach(function (symbol) { return target.add(symbol); });
4616
4608
  }
4617
- function combinate(arrays) {
4618
- return arrays.reduce(function (acc, curr) {
4619
- return acc.flatMap(function (a) { return curr.map(function (c) { return __spreadArray(__spreadArray([], __read(a), false), [c], false); }); });
4620
- }, [[]]);
4621
- }
4622
4609
 
4623
4610
  var defnSpecialExpression = {
4624
4611
  polishParse: function (tokenStream, parseState, firstToken, parsers) {
@@ -4653,13 +4640,13 @@ var Lits = (function (exports) {
4653
4640
  _b.n = name,
4654
4641
  _b.o = evaluatedFunctionOverloades,
4655
4642
  _b);
4656
- contextStack.globalContext[name] = { value: litsFunction };
4643
+ contextStack.exportValue(name, litsFunction);
4657
4644
  return null;
4658
4645
  },
4659
4646
  findUnresolvedIdentifiers: function (node, contextStack, _a) {
4660
4647
  var _b;
4661
4648
  var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
4662
- contextStack.globalContext[node.f.v] = { value: true };
4649
+ contextStack.exportValue(node.f.v, true);
4663
4650
  var newContext = (_b = {}, _b[node.f.v] = { value: true }, _b);
4664
4651
  return addOverloadsUnresolvedIdentifiers(node.o, contextStack, findUnresolvedIdentifiers, builtin, newContext);
4665
4652
  },
@@ -4695,7 +4682,7 @@ var Lits = (function (exports) {
4695
4682
  _b.n = name,
4696
4683
  _b.o = evaluatedFunctionOverloades,
4697
4684
  _b);
4698
- contextStack.globalContext[name] = { value: litsFunction };
4685
+ contextStack.exportValue(name, litsFunction);
4699
4686
  return null;
4700
4687
  },
4701
4688
  findUnresolvedIdentifiers: function (node, contextStack, _a) {
@@ -4706,7 +4693,7 @@ var Lits = (function (exports) {
4706
4693
  var name = evaluateAstNode(asAstNode(node.f, sourceCodeInfo), contextStack);
4707
4694
  assertString(name, sourceCodeInfo);
4708
4695
  assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
4709
- contextStack.globalContext[name] = { value: true };
4696
+ contextStack.exportValue(name, true);
4710
4697
  var newContext = (_b = {}, _b[name] = { value: true }, _b);
4711
4698
  return addOverloadsUnresolvedIdentifiers(node.o, contextStack, findUnresolvedIdentifiers, builtin, newContext);
4712
4699
  },
@@ -4979,56 +4966,8 @@ var Lits = (function (exports) {
4979
4966
  },
4980
4967
  };
4981
4968
 
4982
- var ifLetSpecialExpression = {
4983
- polishParse: function (tokenStream, parseState, firstToken, _a) {
4984
- var _b, _c;
4985
- var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4986
- var bindings = parseBindings(tokenStream, parseState);
4987
- if (bindings.length !== 1) {
4988
- throw new LitsError("Expected exactly one binding, got ".concat(valueToString(bindings.length)), (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
4989
- }
4990
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4991
- assertRParenToken(tokenStream.tokens[parseState.position++]);
4992
- var node = {
4993
- t: exports.AstNodeType.SpecialExpression,
4994
- n: 'if_let',
4995
- b: asNonUndefined(bindings[0], (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo),
4996
- p: params,
4997
- token: getTokenDebugData(firstToken) && firstToken,
4998
- };
4999
- return node;
5000
- },
5001
- validateParameterCount: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
5002
- evaluate: function (node, contextStack, _a) {
5003
- var _b;
5004
- var evaluateAstNode = _a.evaluateAstNode;
5005
- var sourceCodeInfo = (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo;
5006
- var locals = {};
5007
- var bindingValue = evaluateAstNode(node.b.v, contextStack);
5008
- if (bindingValue) {
5009
- locals[node.b.n] = { value: bindingValue };
5010
- var newContextStack = contextStack.create(locals);
5011
- var thenForm = asAstNode(node.p[0], sourceCodeInfo);
5012
- return evaluateAstNode(thenForm, newContextStack);
5013
- }
5014
- if (node.p.length === 2) {
5015
- var elseForm = asAstNode(node.p[1], sourceCodeInfo);
5016
- return evaluateAstNode(elseForm, contextStack);
5017
- }
5018
- return null;
5019
- },
5020
- findUnresolvedIdentifiers: function (node, contextStack, _a) {
5021
- var _b;
5022
- var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
5023
- var newContext = (_b = {}, _b[node.b.n] = { value: true }, _b);
5024
- var bindingResult = findUnresolvedIdentifiers([node.b.v], contextStack, builtin);
5025
- var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
5026
- return joinAnalyzeResults(bindingResult, paramsResult);
5027
- },
5028
- };
5029
-
5030
- var ifNotSpecialExpression = {
5031
- polishParse: getCommonPolishSpecialExpressionParser('if_not'),
4969
+ var unlessSpecialExpression = {
4970
+ polishParse: getCommonPolishSpecialExpressionParser('unless'),
5032
4971
  validateParameterCount: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
5033
4972
  evaluate: function (node, contextStack, _a) {
5034
4973
  var _b;
@@ -5053,55 +4992,39 @@ var Lits = (function (exports) {
5053
4992
 
5054
4993
  var letSpecialExpression = {
5055
4994
  polishParse: function (tokenStream, parseState, firstToken, _a) {
5056
- var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4995
+ var parseBindings = _a.parseBindings;
5057
4996
  var bindings = parseBindings(tokenStream, parseState);
5058
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4997
+ // const params = parseTokensUntilClosingBracket(tokenStream, parseState)
5059
4998
  assertRParenToken(tokenStream.tokens[parseState.position++]);
5060
4999
  var node = {
5061
5000
  t: exports.AstNodeType.SpecialExpression,
5062
5001
  n: 'let',
5063
- p: params,
5002
+ p: [],
5064
5003
  bs: bindings,
5065
5004
  token: getTokenDebugData(firstToken) && firstToken,
5066
5005
  };
5067
5006
  return node;
5068
5007
  },
5069
- validateParameterCount: function () { return undefined; },
5008
+ validateParameterCount: function (node) { return assertNumberOfParams(0, node); },
5070
5009
  evaluate: function (node, contextStack, _a) {
5071
- var e_1, _b, e_2, _c;
5010
+ var e_1, _b;
5072
5011
  var evaluateAstNode = _a.evaluateAstNode;
5073
- var locals = {};
5074
- var newContextStack = contextStack.create(locals);
5075
5012
  try {
5076
- for (var _d = __values(node.bs), _e = _d.next(); !_e.done; _e = _d.next()) {
5077
- var binding = _e.value;
5013
+ for (var _c = __values(node.bs), _d = _c.next(); !_d.done; _d = _c.next()) {
5014
+ var binding = _d.value;
5078
5015
  var bindingValueNode = binding.v;
5079
- var bindingValue = evaluateAstNode(bindingValueNode, newContextStack);
5080
- locals[binding.n] = { value: bindingValue };
5016
+ var bindingValue = evaluateAstNode(bindingValueNode, contextStack);
5017
+ contextStack.addValue(binding.n, bindingValue);
5081
5018
  }
5082
5019
  }
5083
5020
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
5084
5021
  finally {
5085
5022
  try {
5086
- if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
5023
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
5087
5024
  }
5088
5025
  finally { if (e_1) throw e_1.error; }
5089
5026
  }
5090
- var result = null;
5091
- try {
5092
- for (var _f = __values(node.p), _g = _f.next(); !_g.done; _g = _f.next()) {
5093
- var astNode = _g.value;
5094
- result = evaluateAstNode(astNode, newContextStack);
5095
- }
5096
- }
5097
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
5098
- finally {
5099
- try {
5100
- if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
5101
- }
5102
- finally { if (e_2) throw e_2.error; }
5103
- }
5104
- return result;
5027
+ return null;
5105
5028
  },
5106
5029
  findUnresolvedIdentifiers: function (node, contextStack, _a) {
5107
5030
  var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
@@ -5111,11 +5034,10 @@ var Lits = (function (exports) {
5111
5034
  context[name] = { value: true };
5112
5035
  return context;
5113
5036
  }, {});
5114
- var bindingContext = {};
5115
5037
  var bindingResults = node.bs.map(function (bindingNode) {
5116
5038
  var valueNode = bindingNode.v;
5117
- var bindingsResult = findUnresolvedIdentifiers([valueNode], contextStack.create(bindingContext), builtin);
5118
- bindingContext[bindingNode.n] = { value: true };
5039
+ var bindingsResult = findUnresolvedIdentifiers([valueNode], contextStack, builtin);
5040
+ contextStack.addValue(bindingNode.n, { value: true });
5119
5041
  return bindingsResult;
5120
5042
  });
5121
5043
  var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
@@ -5566,9 +5488,10 @@ var Lits = (function (exports) {
5566
5488
  return evaluateAstNode(tryExpressions[0], contextStack);
5567
5489
  }
5568
5490
  catch (error) {
5569
- var newContext = (_b = {},
5570
- _b[errorNode.v] = { value: asAny(error, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo) },
5571
- _b);
5491
+ var newContext = errorNode
5492
+ ? (_b = {},
5493
+ _b[errorNode.v] = { value: asAny(error, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo) },
5494
+ _b) : {};
5572
5495
  return evaluateAstNode(catchExpression, contextStack.create(newContext));
5573
5496
  }
5574
5497
  },
@@ -5577,199 +5500,15 @@ var Lits = (function (exports) {
5577
5500
  var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
5578
5501
  var tryExpressions = node.p, catchExpression = node.ce, errorNode = node.e;
5579
5502
  var tryResult = findUnresolvedIdentifiers(tryExpressions, contextStack, builtin);
5580
- var newContext = (_b = {},
5581
- _b[errorNode.v] = { value: true },
5582
- _b);
5503
+ var newContext = errorNode
5504
+ ? (_b = {},
5505
+ _b[errorNode.v] = { value: true },
5506
+ _b) : {};
5583
5507
  var catchResult = findUnresolvedIdentifiers([catchExpression], contextStack.create(newContext), builtin);
5584
5508
  return joinAnalyzeResults(tryResult, catchResult);
5585
5509
  },
5586
5510
  };
5587
5511
 
5588
- var whenSpecialExpression = {
5589
- polishParse: getCommonPolishSpecialExpressionParser('when'),
5590
- validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
5591
- evaluate: function (node, contextStack, _a) {
5592
- var e_1, _b;
5593
- var _c;
5594
- var evaluateAstNode = _a.evaluateAstNode;
5595
- var _d = __read(node.p), whenExpression = _d[0], body = _d.slice(1);
5596
- assertAstNode(whenExpression, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
5597
- if (!evaluateAstNode(whenExpression, contextStack))
5598
- return null;
5599
- var result = null;
5600
- try {
5601
- for (var body_1 = __values(body), body_1_1 = body_1.next(); !body_1_1.done; body_1_1 = body_1.next()) {
5602
- var form = body_1_1.value;
5603
- result = evaluateAstNode(form, contextStack);
5604
- }
5605
- }
5606
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
5607
- finally {
5608
- try {
5609
- if (body_1_1 && !body_1_1.done && (_b = body_1.return)) _b.call(body_1);
5610
- }
5611
- finally { if (e_1) throw e_1.error; }
5612
- }
5613
- return result;
5614
- },
5615
- findUnresolvedIdentifiers: function (node, contextStack, _a) {
5616
- var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
5617
- return findUnresolvedIdentifiers(node.p, contextStack, builtin);
5618
- },
5619
- };
5620
-
5621
- var whenFirstSpecialExpression = {
5622
- polishParse: function (tokenStream, parseState, firstToken, _a) {
5623
- var _b, _c;
5624
- var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5625
- var bindings = parseBindings(tokenStream, parseState);
5626
- if (bindings.length !== 1) {
5627
- throw new LitsError("Expected exactly one binding, got ".concat(valueToString(bindings.length)), (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
5628
- }
5629
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5630
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5631
- var node = {
5632
- t: exports.AstNodeType.SpecialExpression,
5633
- n: 'when_first',
5634
- b: asNonUndefined(bindings[0], (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo),
5635
- p: params,
5636
- token: getTokenDebugData(firstToken) && firstToken,
5637
- };
5638
- return node;
5639
- },
5640
- validateParameterCount: function () { return undefined; },
5641
- evaluate: function (node, contextStack, _a) {
5642
- var e_1, _b;
5643
- var _c;
5644
- var evaluateAstNode = _a.evaluateAstNode;
5645
- var locals = {};
5646
- var binding = node.b;
5647
- var evaluatedBindingForm = evaluateAstNode(binding.v, contextStack);
5648
- if (!isSeq(evaluatedBindingForm)) {
5649
- throw new LitsError("Expected undefined or a sequence, got ".concat(valueToString(evaluatedBindingForm)), (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
5650
- }
5651
- if (evaluatedBindingForm.length === 0)
5652
- return null;
5653
- var bindingValue = toAny(evaluatedBindingForm[0]);
5654
- locals[binding.n] = { value: bindingValue };
5655
- var newContextStack = contextStack.create(locals);
5656
- var result = null;
5657
- try {
5658
- for (var _d = __values(node.p), _e = _d.next(); !_e.done; _e = _d.next()) {
5659
- var form = _e.value;
5660
- result = evaluateAstNode(form, newContextStack);
5661
- }
5662
- }
5663
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
5664
- finally {
5665
- try {
5666
- if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
5667
- }
5668
- finally { if (e_1) throw e_1.error; }
5669
- }
5670
- return result;
5671
- },
5672
- findUnresolvedIdentifiers: function (node, contextStack, _a) {
5673
- var _b;
5674
- var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
5675
- var binding = node.b;
5676
- var newContext = (_b = {}, _b[binding.n] = { value: true }, _b);
5677
- var bindingResult = findUnresolvedIdentifiers([binding.v], contextStack, builtin);
5678
- var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
5679
- return joinAnalyzeResults(bindingResult, paramsResult);
5680
- },
5681
- };
5682
-
5683
- var whenLetSpecialExpression = {
5684
- polishParse: function (tokenStream, parseState, firstToken, _a) {
5685
- var _b, _c;
5686
- var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5687
- var bindings = parseBindings(tokenStream, parseState);
5688
- if (bindings.length !== 1) {
5689
- throw new LitsError("Expected exactly one binding, got ".concat(valueToString(bindings.length)), (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
5690
- }
5691
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5692
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5693
- var node = {
5694
- t: exports.AstNodeType.SpecialExpression,
5695
- n: 'when_let',
5696
- b: asNonUndefined(bindings[0], (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo),
5697
- p: params,
5698
- token: getTokenDebugData(firstToken) && firstToken,
5699
- };
5700
- return node;
5701
- },
5702
- validateParameterCount: function () { return undefined; },
5703
- evaluate: function (node, contextStack, _a) {
5704
- var e_1, _b;
5705
- var evaluateAstNode = _a.evaluateAstNode;
5706
- var binding = node.b;
5707
- var locals = {};
5708
- var bindingValue = evaluateAstNode(binding.v, contextStack);
5709
- if (!bindingValue)
5710
- return null;
5711
- locals[binding.n] = { value: bindingValue };
5712
- var newContextStack = contextStack.create(locals);
5713
- var result = null;
5714
- try {
5715
- for (var _c = __values(node.p), _d = _c.next(); !_d.done; _d = _c.next()) {
5716
- var form = _d.value;
5717
- result = evaluateAstNode(form, newContextStack);
5718
- }
5719
- }
5720
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
5721
- finally {
5722
- try {
5723
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
5724
- }
5725
- finally { if (e_1) throw e_1.error; }
5726
- }
5727
- return result;
5728
- },
5729
- findUnresolvedIdentifiers: function (node, contextStack, _a) {
5730
- var _b;
5731
- var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
5732
- var binding = node.b;
5733
- var newContext = (_b = {}, _b[binding.n] = { value: true }, _b);
5734
- var bindingResult = findUnresolvedIdentifiers([binding.v], contextStack, builtin);
5735
- var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
5736
- return joinAnalyzeResults(bindingResult, paramsResult);
5737
- },
5738
- };
5739
-
5740
- var whenNotSpecialExpression = {
5741
- polishParse: getCommonPolishSpecialExpressionParser('when_not'),
5742
- validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
5743
- evaluate: function (node, contextStack, _a) {
5744
- var e_1, _b;
5745
- var _c;
5746
- var evaluateAstNode = _a.evaluateAstNode;
5747
- var _d = __read(node.p), whenExpression = _d[0], body = _d.slice(1);
5748
- assertAstNode(whenExpression, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
5749
- if (evaluateAstNode(whenExpression, contextStack))
5750
- return null;
5751
- var result = null;
5752
- try {
5753
- for (var body_1 = __values(body), body_1_1 = body_1.next(); !body_1_1.done; body_1_1 = body_1.next()) {
5754
- var form = body_1_1.value;
5755
- result = evaluateAstNode(form, contextStack);
5756
- }
5757
- }
5758
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
5759
- finally {
5760
- try {
5761
- if (body_1_1 && !body_1_1.done && (_b = body_1.return)) _b.call(body_1);
5762
- }
5763
- finally { if (e_1) throw e_1.error; }
5764
- }
5765
- return result;
5766
- },
5767
- findUnresolvedIdentifiers: function (node, contextStack, _a) {
5768
- var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
5769
- return findUnresolvedIdentifiers(node.p, contextStack, builtin);
5770
- },
5771
- };
5772
-
5773
5512
  var specialExpressions = {
5774
5513
  '&&': andSpecialExpression,
5775
5514
  'comment': commentSpecialExpression,
@@ -5784,19 +5523,14 @@ var Lits = (function (exports) {
5784
5523
  'for': forSpecialExpression,
5785
5524
  'fn': fnSpecialExpression,
5786
5525
  'if': ifSpecialExpression,
5787
- 'if_let': ifLetSpecialExpression,
5788
- 'if_not': ifNotSpecialExpression,
5526
+ 'unless': unlessSpecialExpression,
5789
5527
  'let': letSpecialExpression,
5790
5528
  'loop': loopSpecialExpression,
5791
5529
  '||': orSpecialExpression,
5792
5530
  'recur': recurSpecialExpression,
5793
5531
  'throw': throwSpecialExpression,
5794
5532
  'try': trySpecialExpression,
5795
- 'when': whenSpecialExpression,
5796
- 'when_first': whenFirstSpecialExpression,
5797
- 'when_let': whenLetSpecialExpression,
5798
- 'when_not': whenNotSpecialExpression,
5799
- 'declared?': declaredSpecialExpression,
5533
+ 'defined?': declaredSpecialExpression,
5800
5534
  '??': qqSpecialExpression,
5801
5535
  };
5802
5536
  Object.keys(specialExpressions).forEach(function (key) {
@@ -5818,8 +5552,8 @@ var Lits = (function (exports) {
5818
5552
  var ContextStackImpl = /** @class */ (function () {
5819
5553
  function ContextStackImpl(_a) {
5820
5554
  var contexts = _a.contexts, hostValues = _a.values, lazyHostValues = _a.lazyValues, nativeJsFunctions = _a.nativeJsFunctions;
5821
- this.contexts = contexts;
5822
5555
  this.globalContext = asNonUndefined(contexts[0]);
5556
+ this.contexts = contexts;
5823
5557
  this.values = hostValues;
5824
5558
  this.lazyValues = lazyHostValues;
5825
5559
  this.nativeJsFunctions = nativeJsFunctions;
@@ -5835,6 +5569,35 @@ var Lits = (function (exports) {
5835
5569
  contextStack.globalContext = globalContext;
5836
5570
  return contextStack;
5837
5571
  };
5572
+ ContextStackImpl.prototype.exportValue = function (name, value) {
5573
+ if (this.globalContext[name]) {
5574
+ throw new Error("Cannot redefine exported value \"".concat(name, "\""));
5575
+ }
5576
+ if (specialExpressionKeys.includes(name)) {
5577
+ throw new Error("Cannot shadow special expression \"".concat(name, "\""));
5578
+ }
5579
+ if (normalExpressionKeys.includes(name)) {
5580
+ throw new Error("Cannot shadow builtin function \"".concat(name, "\""));
5581
+ }
5582
+ this.addValue(name, value);
5583
+ this.globalContext[name] = { value: value };
5584
+ };
5585
+ ContextStackImpl.prototype.addValue = function (name, value) {
5586
+ var currentContext = this.contexts[0];
5587
+ if (!currentContext) {
5588
+ throw new Error('No context to add value to');
5589
+ }
5590
+ if (currentContext[name]) {
5591
+ throw new Error("Cannot redefine value \"".concat(name, "\""));
5592
+ }
5593
+ if (specialExpressionKeys.includes(name)) {
5594
+ throw new Error("Cannot shadow special expression \"".concat(name, "\""));
5595
+ }
5596
+ if (normalExpressionKeys.includes(name)) {
5597
+ throw new Error("Cannot shadow builtin function \"".concat(name, "\""));
5598
+ }
5599
+ currentContext[name] = { value: toAny(value) };
5600
+ };
5838
5601
  ContextStackImpl.prototype.clone = function () {
5839
5602
  // eslint-disable-next-line ts/no-unsafe-argument
5840
5603
  return new ContextStackImpl(JSON.parse(JSON.stringify({
@@ -5964,7 +5727,7 @@ var Lits = (function (exports) {
5964
5727
  return acc;
5965
5728
  }, {}),
5966
5729
  });
5967
- return contextStack;
5730
+ return contextStack.create({});
5968
5731
  }
5969
5732
 
5970
5733
  var _a$1;
@@ -6276,7 +6039,14 @@ var Lits = (function (exports) {
6276
6039
 
6277
6040
  var findUnresolvedIdentifiers = function (ast, contextStack, builtin) {
6278
6041
  var e_1, _a;
6279
- var astNodes = Array.isArray(ast) ? ast : ast.b;
6042
+ var astNodes = Array.isArray(ast)
6043
+ ? ast
6044
+ : [{
6045
+ t: exports.AstNodeType.SpecialExpression,
6046
+ n: 'do',
6047
+ p: ast.b,
6048
+ token: undefined,
6049
+ }];
6280
6050
  var unresolvedIdentifiers = new Set();
6281
6051
  try {
6282
6052
  for (var astNodes_1 = __values(astNodes), astNodes_1_1 = astNodes_1.next(); !astNodes_1_1.done; astNodes_1_1 = astNodes_1.next()) {
@@ -6337,548 +6107,20 @@ var Lits = (function (exports) {
6337
6107
  }
6338
6108
  case exports.AstNodeType.SpecialExpression: {
6339
6109
  var specialExpression = asNonUndefined(builtin.specialExpressions[astNode.n], (_b = getTokenDebugData(astNode.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
6340
- // eslint-disable-next-line ts/no-unsafe-argument
6341
- var unresolvedIdentifiers = specialExpression.findUnresolvedIdentifiers(astNode, contextStack, {
6342
- findUnresolvedIdentifiers: findUnresolvedIdentifiers,
6343
- builtin: builtin,
6344
- evaluateAstNode: evaluateAstNode,
6345
- });
6346
- return unresolvedIdentifiers;
6347
- }
6348
- }
6349
- }
6350
-
6351
- var calculateAndOutcomes = function (_a) {
6352
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
6353
- return combinateAstNodes(astNode.p)
6354
- .map(function (p) { return ({
6355
- n: '&&',
6356
- t: exports.AstNodeType.SpecialExpression,
6357
- p: p,
6358
- token: astNode.token,
6359
- }); });
6360
- };
6361
-
6362
- var calculateCondOutcomes = function (_a) {
6363
- var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, isAstComputable = _a.isAstComputable;
6364
- var testNodes = arrayToPairs(astNode.p).map(function (_a) {
6365
- var _b = __read(_a, 1), t = _b[0];
6366
- return t;
6367
- });
6368
- if (isAstComputable(testNodes)) {
6369
- return combinate(arrayToPairs(astNode.p)
6370
- // Create a list of ast nodes from the test and form of each condition
6371
- .reduce(function (acc, _a) {
6372
- var _b = __read(_a, 2), test = _b[0], form = _b[1];
6373
- acc.push(calculatePossibleAstNodes(test), calculatePossibleAstNodes(form));
6374
- return acc;
6375
- }, []))
6376
- // Create a new CondNode for each combination of test and form outcomes
6377
- .map(function (conditionAsts) { return (__assign(__assign({}, astNode), { c: arrayToPairs(conditionAsts).map(function (_a) {
6378
- var _b = __read(_a, 2), t = _b[0], f = _b[1];
6379
- return ({ t: t, f: f });
6380
- }) })); });
6381
- }
6382
- return __spreadArray(__spreadArray([], __read(arrayToPairs(astNode.p).flatMap(function (_a) {
6383
- var _b = __read(_a, 2); _b[0]; var form = _b[1];
6384
- return calculatePossibleAstNodes(form);
6385
- })), false), [
6386
- nilNode,
6387
- ], false);
6388
- };
6389
-
6390
- var trueNode = { t: exports.AstNodeType.ReservedSymbol, v: 'true', token: undefined, p: [], n: undefined };
6391
- var falseNode = { t: exports.AstNodeType.ReservedSymbol, v: 'false', token: undefined, p: [], n: undefined };
6392
- var calculateDeclaredOutcomes = function (_a) {
6393
- var astNode = _a.astNode, isAstComputable = _a.isAstComputable;
6394
- if (isAstComputable(astNode.p))
6395
- return [trueNode];
6396
- return [trueNode, falseNode];
6397
- };
6398
-
6399
- var calculateDefOutcomes = function (_a) {
6400
- var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, addGlobalIdentifier = _a.addGlobalIdentifier;
6401
- var nameNode = asSymbolNode(astNode.p[0]);
6402
- var valueNode = astNode.p[1];
6403
- addGlobalIdentifier(nameNode.v);
6404
- return calculatePossibleAstNodes(valueNode)
6405
- .map(function (node) { return (__assign(__assign({}, astNode), { p: [nameNode, node] })); });
6406
- };
6407
-
6408
- var calculateDefsOutcomes = function (_a) {
6409
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
6410
- return combinateAstNodes(astNode.p)
6411
- .map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
6412
- };
6413
-
6414
- var calculateDoOutcomes = function (_a) {
6415
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
6416
- return combinateAstNodes(astNode.p).map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
6417
- };
6418
-
6419
- function calculateFunctionOverloadOutcomes(combinateAstNodes, functionOverloads) {
6420
- return combinate(functionOverloads
6421
- // For each overload, calculate the possible outcomes for each parameter
6422
- .map(function (functionOverload) {
6423
- var _a;
6424
- return combinateAstNodes(functionOverload.b, [
6425
- functionOverload.as.m,
6426
- functionOverload.as.b.map(function (bindingNode) { return bindingNode.n; }),
6427
- (_a = functionOverload.as.r) !== null && _a !== void 0 ? _a : [],
6428
- ].flat())
6429
- // For each combination of parameter outcomes, create a new overload
6430
- .map(function (body) { return (__assign(__assign({}, functionOverload), { b: body })); });
6431
- }));
6432
- }
6433
- var calculateDefnOutcomes = function (_a) {
6434
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, addGlobalIdentifier = _a.addGlobalIdentifier;
6435
- addGlobalIdentifier(astNode.f.v);
6436
- // astNode.o is an array of overloads
6437
- return calculateFunctionOverloadOutcomes(combinateAstNodes, astNode.o).map(function (functionOverloads) { return (__assign(__assign({}, astNode), { o: functionOverloads })); });
6438
- };
6439
- var calculateDefnsOutcomes = function (_a) {
6440
- var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes;
6441
- // astNode.o is an array of overloads
6442
- return calculatePossibleAstNodes(astNode.f).flatMap(function (functionName) {
6443
- return calculateFunctionOverloadOutcomes(combinateAstNodes, astNode.o).map(function (functionOverloads) { return (__assign(__assign({}, astNode), { f: functionName, o: functionOverloads })); });
6444
- });
6445
- };
6446
- var calculateFnOutcomes = function (_a) {
6447
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
6448
- // astNode.o is an array of overloads
6449
- return calculateFunctionOverloadOutcomes(combinateAstNodes, astNode.o).map(function (functionOverloads) { return (__assign(__assign({}, astNode), { o: functionOverloads })); });
6450
- };
6451
-
6452
- var calculateIfLetOutcomes = function (_a) {
6453
- var _b;
6454
- var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
6455
- var bindingNode = astNode.b;
6456
- var thenBranch = astNode.p[0];
6457
- var elseBranch = (_b = astNode.p[1]) !== null && _b !== void 0 ? _b : nilNode;
6458
- if (!isAstComputable(bindingNode.v)) {
6459
- return __spreadArray(__spreadArray([], __read(calculatePossibleAstNodes(thenBranch)), false), __read(calculatePossibleAstNodes(elseBranch)), false);
6460
- }
6461
- var newIdentifier = bindingNode.n;
6462
- return calculatePossibleAstNodes(bindingNode.v)
6463
- .map(function (bindingValue) { return (__assign(__assign({}, bindingNode), { v: bindingValue })); })
6464
- .flatMap(function (b) { return combinateAstNodes(astNode.p, [newIdentifier])
6465
- .map(function (p) { return (__assign(__assign({}, astNode), { b: b, p: p })); }); });
6466
- };
6467
-
6468
- var calculateIfNotOutcomes = function (_a) {
6469
- var _b;
6470
- var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
6471
- var condition = astNode.p[0];
6472
- var thenBranch = astNode.p[1];
6473
- var elseBranch = (_b = astNode.p[2]) !== null && _b !== void 0 ? _b : nilNode;
6474
- if (isAstComputable(condition)) {
6475
- return combinateAstNodes(astNode.p)
6476
- .map(function (p) { return ({
6477
- n: 'if_not',
6478
- t: astNode.t,
6479
- p: p,
6480
- token: astNode.token,
6481
- }); });
6482
- }
6483
- return __spreadArray(__spreadArray([], __read(calculatePossibleAstNodes(thenBranch)), false), __read(calculatePossibleAstNodes(elseBranch)), false);
6484
- };
6485
-
6486
- var calculateIfOutcomes = function (_a) {
6487
- var _b;
6488
- var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
6489
- var condition = astNode.p[0];
6490
- var thenBranch = astNode.p[1];
6491
- var elseBranch = (_b = astNode.p[2]) !== null && _b !== void 0 ? _b : nilNode;
6492
- if (isAstComputable(condition)) {
6493
- return combinateAstNodes(astNode.p)
6494
- .map(function (p) { return ({
6495
- n: 'if',
6496
- t: astNode.t,
6497
- p: p,
6498
- token: astNode.token,
6499
- }); });
6500
- }
6501
- return __spreadArray(__spreadArray([], __read(calculatePossibleAstNodes(thenBranch)), false), __read(calculatePossibleAstNodes(elseBranch)), false);
6502
- };
6503
-
6504
- var calculateLetOutcomes = function (_a) {
6505
- var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
6506
- try {
6507
- // check bindings, if any binding value cannot be calculated, convert the whole let to a do-expression
6508
- if (!isAstComputable(astNode.bs.map(function (b) { return calculatePossibleAstNodes(b.v); })))
6509
- throw new Error('Could not calculate binding value');
6510
- }
6511
- catch (_b) {
6512
- var doNodes = combinateAstNodes(astNode.p)
6513
- .map(function (p) {
6514
- return {
6515
- n: 'do',
6516
- t: exports.AstNodeType.SpecialExpression,
6517
- p: p,
6518
- token: astNode.token,
6519
- };
6520
- });
6521
- return doNodes;
6522
- }
6523
- var newIdentifiers = astNode.bs.map(function (bindingNode) { return bindingNode.n; });
6524
- var letNodes = combinate(astNode.bs.map(function (bindingNode) {
6525
- return calculatePossibleAstNodes(bindingNode.v)
6526
- .map(function (bindingValues) { return (__assign(__assign({}, bindingNode), { v: bindingValues })); });
6527
- }))
6528
- .flatMap(function (bindingNodes) { return combinate(astNode.p.map(function (p) { return calculatePossibleAstNodes(p, newIdentifiers); }))
6529
- .map(function (p) {
6530
- return {
6531
- n: 'let',
6532
- bs: bindingNodes,
6533
- t: exports.AstNodeType.SpecialExpression,
6534
- p: p,
6535
- token: astNode.token,
6536
- };
6537
- }); });
6538
- return letNodes;
6539
- };
6540
-
6541
- var calculateForOutcomes = function (_a) {
6542
- var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
6543
- if (!isDeterministic(calculatePossibleAstNodes, astNode))
6544
- throw new Error('Could not calculate for loop, not deterministic');
6545
- return [astNode];
6546
- };
6547
- var calculateDoSeqOutcomes = function (_a) {
6548
- var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
6549
- if (!isDeterministic(calculatePossibleAstNodes, astNode))
6550
- throw new Error('Could not calculate doSeq node, not deterministic');
6551
- return [astNode];
6552
- };
6553
- function isDeterministic(calculatePossibleAstNodes, astNode) {
6554
- var e_1, _a;
6555
- try {
6556
- for (var _b = __values(astNode.l), _c = _b.next(); !_c.done; _c = _b.next()) {
6557
- var _d = _c.value, b = _d.b, l = _d.l, wn = _d.wn, we = _d.we;
6558
- if (l && l.some(function (_a) {
6559
- var v = _a.v;
6560
- return !astIsDeterministic(calculatePossibleAstNodes, v);
6561
- }))
6562
- return false;
6563
- if (!astIsDeterministic(calculatePossibleAstNodes, b.v))
6564
- return false;
6565
- if (wn && !astIsDeterministic(calculatePossibleAstNodes, wn))
6566
- return false;
6567
- if (we && !astIsDeterministic(calculatePossibleAstNodes, we))
6568
- return false;
6569
- }
6570
- }
6571
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
6572
- finally {
6573
- try {
6574
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
6575
- }
6576
- finally { if (e_1) throw e_1.error; }
6577
- }
6578
- if (!astIsDeterministic(calculatePossibleAstNodes, astNode.p[0]))
6579
- return false;
6580
- return true;
6581
- }
6582
- function astIsDeterministic(calculatePossibleAstNodes, astNode) {
6583
- return calculatePossibleAstNodes(astNode).length === 1;
6584
- }
6585
-
6586
- var calculateOrOutcomes = function (_a) {
6587
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
6588
- return combinateAstNodes(astNode.p)
6589
- .map(function (p) { return ({
6590
- n: '||',
6591
- t: exports.AstNodeType.SpecialExpression,
6592
- p: p,
6593
- token: astNode.token,
6594
- }); });
6595
- };
6596
-
6597
- var calculateQqOutcomes = function (_a) {
6598
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
6599
- if (!isAstComputable(astNode.p[0]))
6600
- throw new Error('First argument of ?? not computable');
6601
- return combinateAstNodes(astNode.p)
6602
- .map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
6603
- };
6604
-
6605
- var calculateThrowOutcomes = function (_a) {
6606
- var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
6607
- return calculatePossibleAstNodes(astNode.p[0]).map(function (m) { return (__assign(__assign({}, astNode), { p: [m] })); });
6608
- };
6609
-
6610
- var calculateTryOutcomes = function (_a) {
6611
- var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
6612
- var _b = calculatePossibleAstNodes(astNode.p[0]).reduce(function (acc, node) {
6613
- if (node.n === 'throw') {
6614
- acc.throws.push(node.p[0]);
6615
- }
6616
- else {
6617
- acc.vals.push(node);
6618
- }
6619
- return acc;
6620
- }, { vals: [], throws: [] }), vals = _b.vals, throws = _b.throws;
6621
- var catches = throws.flatMap(function (throwNode) {
6622
- var letNode = {
6623
- t: exports.AstNodeType.SpecialExpression,
6624
- n: 'let',
6625
- bs: [{
6626
- t: exports.AstNodeType.Binding,
6627
- n: astNode.e.v,
6628
- v: throwNode,
6629
- token: undefined,
6630
- p: [],
6631
- }],
6632
- p: [astNode.ce],
6633
- token: undefined,
6634
- };
6635
- return calculatePossibleAstNodes(letNode);
6636
- });
6637
- return __spreadArray(__spreadArray([], __read(vals), false), __read(catches), false);
6638
- };
6639
-
6640
- var calculateWhenFirstOutcomes = function (_a) {
6641
- var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
6642
- var bindingNode = astNode.b;
6643
- if (!isAstComputable(bindingNode.v))
6644
- throw new Error('Could not calculate binding value');
6645
- var newIdentifier = bindingNode.n;
6646
- return calculatePossibleAstNodes(bindingNode.v)
6647
- .map(function (bindingValue) { return (__assign(__assign({}, bindingNode), { v: bindingValue })); })
6648
- .flatMap(function (b) {
6649
- return combinateAstNodes(astNode.p, [newIdentifier])
6650
- .map(function (p) { return (__assign(__assign({}, astNode), { b: b, p: p })); });
6651
- });
6652
- };
6653
-
6654
- var calculateWhenLetOutcomes = function (_a) {
6655
- var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
6656
- var bindingNode = astNode.b;
6657
- if (!isAstComputable(bindingNode.v)) {
6658
- return __spreadArray(__spreadArray([], __read(combinateAstNodes(astNode.p)
6659
- .map(function (p) { return ({
6660
- n: 'do',
6661
- t: astNode.t,
6662
- p: p,
6663
- token: astNode.token,
6664
- }); })), false), [
6665
- nilNode,
6666
- ], false);
6667
- }
6668
- var newIdentifier = bindingNode.n;
6669
- return calculatePossibleAstNodes(bindingNode.v)
6670
- .map(function (bindingValue) { return (__assign(__assign({}, bindingNode), { v: bindingValue })); })
6671
- .flatMap(function (b) {
6672
- return combinateAstNodes(astNode.p, [newIdentifier])
6673
- .map(function (p) { return (__assign(__assign({}, astNode), { b: b, p: p })); });
6674
- });
6675
- };
6676
-
6677
- var calculateWhenNotOutcomes = function (_a) {
6678
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, nilNode = _a.nilNode, isAstComputable = _a.isAstComputable;
6679
- var condition = astNode.p[0];
6680
- if (isAstComputable(condition)) {
6681
- return combinateAstNodes(astNode.p)
6682
- .map(function (p) { return ({
6683
- n: 'when_not',
6684
- t: astNode.t,
6685
- p: p,
6686
- token: astNode.token,
6687
- }); });
6688
- }
6689
- var body = astNode.p.slice(1);
6690
- return __spreadArray(__spreadArray([], __read(combinateAstNodes(body)
6691
- .map(function (p) { return ({
6692
- n: 'do',
6693
- t: astNode.t,
6694
- p: p,
6695
- token: astNode.token,
6696
- }); })), false), [
6697
- nilNode,
6698
- ], false);
6699
- };
6700
-
6701
- var calculateWhenOutcomes = function (_a) {
6702
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, nilNode = _a.nilNode, isAstComputable = _a.isAstComputable;
6703
- var condition = astNode.p[0];
6704
- if (isAstComputable(condition)) {
6705
- return combinateAstNodes(astNode.p)
6706
- .map(function (p) { return ({
6707
- n: 'when',
6708
- t: astNode.t,
6709
- p: p,
6710
- token: astNode.token,
6711
- }); });
6712
- }
6713
- var body = astNode.p.slice(1);
6714
- return __spreadArray(__spreadArray([], __read(combinateAstNodes(body)
6715
- .map(function (p) { return ({
6716
- n: 'do',
6717
- t: astNode.t,
6718
- p: p,
6719
- token: astNode.token,
6720
- }); })), false), [
6721
- nilNode,
6722
- ], false);
6723
- };
6724
-
6725
- var calculateRecurOutcomes = function (_a) {
6726
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
6727
- return combinateAstNodes(astNode.p)
6728
- .map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
6729
- };
6730
-
6731
- var calculateCommentOutcomes = function (_a) {
6732
- var nilNode = _a.nilNode;
6733
- return [nilNode];
6734
- };
6735
-
6736
- var calculateLoopOutcomes = function (_a) {
6737
- var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
6738
- return combinateAstNodes(astNode.p, astNode.bs.map(function (bindingNode) { return bindingNode.n; }))
6739
- .map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
6740
- };
6741
-
6742
- var calculateSwitchOutcomes = function (_a) {
6743
- var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
6744
- // TODO be smarter about this
6745
- return __spreadArray(__spreadArray([], __read(arrayToPairs(astNode.p.slice(1)).flatMap(function (_a) {
6746
- var _b = __read(_a, 2); _b[0]; var form = _b[1];
6747
- return calculatePossibleAstNodes(form);
6748
- })), false), [
6749
- nilNode,
6750
- ], false);
6751
- };
6752
-
6753
- var specialExpressionCalculator = {
6754
- '&&': function (astNode, helperOptions) { return calculateAndOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6755
- 'comment': function (astNode, helperOptions) { return calculateCommentOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6756
- 'cond': function (astNode, helperOptions) { return calculateCondOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6757
- 'switch': function (astNode, helperOptions) { return calculateSwitchOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6758
- 'declared?': function (astNode, helperOptions) { return calculateDeclaredOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6759
- 'defn': function (astNode, helperOptions) { return calculateDefnOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6760
- 'def': function (astNode, helperOptions) { return calculateDefOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6761
- 'defns': function (astNode, helperOptions) { return calculateDefnsOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6762
- 'defs': function (astNode, helperOptions) { return calculateDefsOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6763
- 'do': function (astNode, helperOptions) { return calculateDoOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6764
- 'doseq': function (astNode, helperOptions) { return calculateDoSeqOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6765
- 'fn': function (astNode, helperOptions) { return calculateFnOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6766
- 'for': function (astNode, helperOptions) { return calculateForOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6767
- 'if_let': function (astNode, helperOptions) { return calculateIfLetOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6768
- 'if': function (astNode, helperOptions) { return calculateIfOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6769
- 'if_not': function (astNode, helperOptions) { return calculateIfNotOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6770
- 'let': function (astNode, helperOptions) { return calculateLetOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6771
- 'loop': function (astNode, helperOptions) { return calculateLoopOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6772
- '||': function (astNode, helperOptions) { return calculateOrOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6773
- '??': function (astNode, helperOptions) { return calculateQqOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6774
- 'recur': function (astNode, helperOptions) { return calculateRecurOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6775
- 'throw': function (astNode, helperOptions) { return calculateThrowOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6776
- 'try': function (astNode, helperOptions) { return calculateTryOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6777
- 'when_first': function (astNode, helperOptions) { return calculateWhenFirstOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6778
- 'when_let': function (astNode, helperOptions) { return calculateWhenLetOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6779
- 'when': function (astNode, helperOptions) { return calculateWhenOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6780
- 'when_not': function (astNode, helperOptions) { return calculateWhenNotOutcomes(__assign({ astNode: astNode }, helperOptions)); },
6781
- };
6782
-
6783
- function calculateOutcomes(contextStack, astNodes) {
6784
- // First, we try to calculate outcomes for the whole astNodes array.
6785
- // If that fails, we try to calculate outcomes for the array without the first element.
6786
- // If that fails, we try to calculate outcomes for the array without the first two elements.
6787
- // And so on.
6788
- // This makes it possible to calculate outcomes for e.g.
6789
- // (write! x) x
6790
- // Problems occur for e.g.
6791
- // (def x 1) (write! x) x
6792
- // This should output [1], but since (write! x) fails to calculate outcomes, we get null.
6793
- // Ok, but not optimal
6794
- // The contract is that when an array is returned, it must be correct.
6795
- // But returning null (indicating that the calculation failed) is always a way out.
6796
- for (var i = 0; i < astNodes.length; i++) {
6797
- var usingAstNode = astNodes.slice(i);
6798
- var outcomes = calculateOutcomesInner(contextStack, usingAstNode);
6799
- if (outcomes !== null)
6800
- return outcomes;
6801
- }
6802
- return null;
6803
- }
6804
- function calculateOutcomesInner(contextStack, astNodes) {
6805
- var e_1, _a;
6806
- var possibleAsts = calculatePossibleAsts(contextStack.clone(), astNodes);
6807
- if (possibleAsts === null)
6808
- return null;
6809
- var outcomes = [];
6810
- try {
6811
- for (var possibleAsts_1 = __values(possibleAsts), possibleAsts_1_1 = possibleAsts_1.next(); !possibleAsts_1_1.done; possibleAsts_1_1 = possibleAsts_1.next()) {
6812
- var possibleAst = possibleAsts_1_1.value;
6813
- var unresolvedIdentifiers = findUnresolvedIdentifiers(possibleAst, contextStack.clone(), builtin);
6814
- if (unresolvedIdentifiers.size !== 0)
6815
- return null;
6816
- var ast = {
6817
- b: possibleAst,
6818
- hasDebugData: true,
6819
- };
6820
- try {
6821
- outcomes.push(evaluate(ast, contextStack.clone()));
6822
- }
6823
- catch (e) {
6824
- outcomes.push(e);
6825
- }
6826
- }
6827
- }
6828
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
6829
- finally {
6830
- try {
6831
- if (possibleAsts_1_1 && !possibleAsts_1_1.done && (_a = possibleAsts_1.return)) _a.call(possibleAsts_1);
6110
+ // eslint-disable-next-line ts/no-unsafe-argument
6111
+ var unresolvedIdentifiers = specialExpression.findUnresolvedIdentifiers(astNode, contextStack, {
6112
+ findUnresolvedIdentifiers: findUnresolvedIdentifiers,
6113
+ builtin: builtin,
6114
+ evaluateAstNode: evaluateAstNode,
6115
+ });
6116
+ return unresolvedIdentifiers;
6832
6117
  }
6833
- finally { if (e_1) throw e_1.error; }
6834
- }
6835
- return outcomes;
6836
- }
6837
- function calculatePossibleAsts(contextStack, astNodes) {
6838
- var possibleAsts;
6839
- try {
6840
- possibleAsts = combinate(astNodes.map(function (astNode) { return calculatePossibleAstNodes(contextStack, astNode); }));
6841
- }
6842
- catch (e) {
6843
- return null;
6844
- }
6845
- return possibleAsts;
6846
- }
6847
- var nilNode = { t: exports.AstNodeType.ReservedSymbol, v: 'nil', token: undefined, p: [], n: undefined };
6848
- function calculatePossibleAstNodes(contextStack, astNode, newIndentifiers) {
6849
- var newContext = newIndentifiers
6850
- ? newIndentifiers.reduce(function (acc, identity) {
6851
- acc[identity] = { value: null };
6852
- return acc;
6853
- }, {})
6854
- : undefined;
6855
- var newContextStack = newContext ? contextStack.create(newContext) : contextStack;
6856
- if (astNode.t === exports.AstNodeType.NormalExpression) {
6857
- return combinate(astNode.p.map(function (n) { return calculatePossibleAstNodes(newContextStack, n); }))
6858
- .map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
6859
- }
6860
- else if (astNode.t === exports.AstNodeType.SpecialExpression) {
6861
- var helperOptions = {
6862
- nilNode: nilNode,
6863
- calculatePossibleAstNodes: function (node, identifiers) { return calculatePossibleAstNodes(newContextStack.clone(), node, identifiers); },
6864
- combinateAstNodes: function (nodes, identifiers) {
6865
- return combinate(nodes.map(function (node) { return calculatePossibleAstNodes(newContextStack.clone(), node, identifiers); }));
6866
- },
6867
- isAstComputable: function (node) {
6868
- return calculateOutcomesInner(newContextStack, Array.isArray(node) ? node.flat() : [node]) !== null;
6869
- },
6870
- addGlobalIdentifier: function (name) { return newContextStack.globalContext[name] = { value: null }; },
6871
- };
6872
- // eslint-disable-next-line ts/no-unsafe-argument
6873
- return specialExpressionCalculator[astNode.n](astNode, helperOptions);
6874
6118
  }
6875
- return [astNode];
6876
6119
  }
6877
6120
 
6878
6121
  function analyze(ast, params) {
6879
6122
  return {
6880
6123
  unresolvedIdentifiers: findUnresolvedIdentifiers(ast, createContextStack(params), builtin),
6881
- outcomes: calculateOutcomes(createContextStack(params), ast.b),
6882
6124
  };
6883
6125
  }
6884
6126
 
@@ -7160,38 +6402,43 @@ var Lits = (function (exports) {
7160
6402
  var _a;
7161
6403
  if (precedence === void 0) { precedence = 0; }
7162
6404
  var firstToken = this.peek();
7163
- if (isA_SymbolToken(firstToken) && firstToken[1] === 'def') {
7164
- return this.parseDef(firstToken);
7165
- }
7166
- else if (isA_SymbolToken(firstToken) && firstToken[1] === 'defn') {
7167
- return this.parseDefn(firstToken);
7168
- }
7169
6405
  var left;
7170
- if (isA_SymbolToken(firstToken) && firstToken[1] === 'if') {
7171
- left = this.parseIf(firstToken);
7172
- }
7173
- else if (isA_SymbolToken(firstToken) && firstToken[1] === 'cond') {
7174
- left = this.parseCond(firstToken);
7175
- }
7176
- else if (isA_SymbolToken(firstToken) && firstToken[1] === 'switch') {
7177
- left = this.parseSwitch(firstToken);
7178
- }
7179
- else if (isA_SymbolToken(firstToken) && firstToken[1] === 'for') {
7180
- left = this.parseFor(firstToken);
7181
- }
7182
- else {
7183
- left = this.parseOperand();
6406
+ if (isA_SymbolToken(firstToken)) {
6407
+ switch (firstToken[1]) {
6408
+ case 'def':
6409
+ return this.parseDef(firstToken);
6410
+ case 'defn':
6411
+ return this.parseDefn(firstToken);
6412
+ case 'let':
6413
+ return this.parseLet(firstToken);
6414
+ case 'if':
6415
+ case 'unless':
6416
+ left = this.parseIfOrUnless(firstToken);
6417
+ break;
6418
+ case 'cond':
6419
+ left = this.parseCond(firstToken);
6420
+ break;
6421
+ case 'switch':
6422
+ left = this.parseSwitch(firstToken);
6423
+ break;
6424
+ case 'for':
6425
+ case 'doseq':
6426
+ left = this.parseForOrDoseq(firstToken);
6427
+ break;
6428
+ case 'do':
6429
+ left = this.parseDo(firstToken);
6430
+ break;
6431
+ case 'loop':
6432
+ left = this.parseLoop(firstToken);
6433
+ break;
6434
+ case 'try':
6435
+ left = this.parseTry(firstToken);
6436
+ break;
6437
+ }
7184
6438
  }
6439
+ left || (left = this.parseOperand());
7185
6440
  var operator = this.peek();
7186
- while (!this.isAtEnd()
7187
- && !isA_OperatorToken(operator, ',')
7188
- && !isA_OperatorToken(operator, ';')
7189
- && !isRBracketToken(operator)
7190
- && !isA_ReservedSymbolToken(operator, 'else')
7191
- && !isA_ReservedSymbolToken(operator, 'then')
7192
- && !isA_ReservedSymbolToken(operator, 'end')
7193
- && !isA_ReservedSymbolToken(operator, 'case')
7194
- && !isRParenToken(operator)) {
6441
+ while (!this.isAtExpressionEnd()) {
7195
6442
  if (isA_BinaryOperatorToken(operator)) {
7196
6443
  var name_1 = operator[1];
7197
6444
  var newPrecedece = getPrecedence(name_1);
@@ -7444,12 +6691,9 @@ var Lits = (function (exports) {
7444
6691
  case '??':
7445
6692
  case '&&':
7446
6693
  case 'comment':
7447
- case 'declared?':
7448
- case 'if_not':
6694
+ case 'defined?':
7449
6695
  case '||':
7450
- case 'when':
7451
- case 'when_not':
7452
- case 'do':
6696
+ case 'recur':
7453
6697
  case 'throw': {
7454
6698
  var node = {
7455
6699
  t: exports.AstNodeType.SpecialExpression,
@@ -7460,17 +6704,10 @@ var Lits = (function (exports) {
7460
6704
  builtin.specialExpressions[node.n].validateParameterCount(node);
7461
6705
  return node;
7462
6706
  }
7463
- case 'let':
7464
- return this.parseLet(symbol, params);
7465
6707
  case 'defs':
7466
- case 'if_let':
7467
- case 'when_let':
7468
- case 'when_first':
7469
6708
  case 'fn':
7470
6709
  case 'defns':
7471
6710
  case 'try':
7472
- case 'recur':
7473
- case 'loop':
7474
6711
  case 'doseq':
7475
6712
  throw new Error("Special expression ".concat(name_2, " is not available in algebraic notation"));
7476
6713
  default:
@@ -7633,36 +6870,142 @@ var Lits = (function (exports) {
7633
6870
  };
7634
6871
  return node;
7635
6872
  };
7636
- AlgebraicParser.prototype.parseLet = function (letSymbol, params) {
7637
- var _a, _b;
7638
- if (params.length !== 2) {
7639
- throw new LitsError('let expects two arguments', (_a = getTokenDebugData(letSymbol.token)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
7640
- }
7641
- var letObject = params[0];
7642
- if (letObject.t !== exports.AstNodeType.NormalExpression || letObject.n !== 'object') {
7643
- throw new LitsError('let expects an object as first argument', (_b = getTokenDebugData(letObject.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
7644
- }
7645
- var letBindings = arrayToPairs(letObject.p);
7646
- var expression = params[1];
6873
+ AlgebraicParser.prototype.parseLet = function (token) {
6874
+ this.advance();
6875
+ var letSymbol = parseSymbol(this.tokenStream, this.parseState);
6876
+ assertA_OperatorToken(this.peek(), '=');
6877
+ this.advance();
6878
+ var value = this.parseExpression();
7647
6879
  return {
7648
6880
  t: exports.AstNodeType.SpecialExpression,
7649
6881
  n: 'let',
7650
- p: [expression],
6882
+ p: [],
7651
6883
  token: getTokenDebugData(letSymbol.token) && letSymbol.token,
7652
- bs: letBindings.map(function (pair) {
7653
- var key = pair[0];
7654
- var value = pair[1];
7655
- return {
6884
+ bs: [{
7656
6885
  t: exports.AstNodeType.Binding,
7657
- n: key.v,
6886
+ n: letSymbol.v,
7658
6887
  v: value,
7659
6888
  p: [],
7660
- token: getTokenDebugData(key.token) && key.token,
7661
- };
7662
- }),
6889
+ token: getTokenDebugData(token) && token,
6890
+ }],
6891
+ };
6892
+ };
6893
+ AlgebraicParser.prototype.parseDo = function (token) {
6894
+ this.advance();
6895
+ var expressions = [];
6896
+ while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
6897
+ expressions.push(this.parseExpression());
6898
+ if (isA_OperatorToken(this.peek(), ';')) {
6899
+ this.advance();
6900
+ }
6901
+ }
6902
+ assertA_ReservedSymbolToken(this.peek(), 'end');
6903
+ this.advance();
6904
+ return {
6905
+ t: exports.AstNodeType.SpecialExpression,
6906
+ n: 'do',
6907
+ p: expressions,
6908
+ token: getTokenDebugData(token) && token,
6909
+ };
6910
+ };
6911
+ AlgebraicParser.prototype.parseLoop = function (token) {
6912
+ var _a;
6913
+ this.advance();
6914
+ assertLParenToken(this.peek());
6915
+ this.advance();
6916
+ var bindingNodes = [];
6917
+ while (!this.isAtEnd() && !isRParenToken(this.peek())) {
6918
+ var symbol = parseSymbol(this.tokenStream, this.parseState);
6919
+ assertA_OperatorToken(this.peek(), '=');
6920
+ this.advance();
6921
+ var value = this.parseExpression();
6922
+ bindingNodes.push({
6923
+ t: exports.AstNodeType.Binding,
6924
+ n: symbol.v,
6925
+ v: value,
6926
+ p: [],
6927
+ token: getTokenDebugData(symbol.token) && symbol.token,
6928
+ });
6929
+ if (isA_OperatorToken(this.peek(), ',')) {
6930
+ this.advance();
6931
+ }
6932
+ }
6933
+ if (bindingNodes.length === 0) {
6934
+ throw new LitsError('Expected binding', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
6935
+ }
6936
+ assertRParenToken(this.peek());
6937
+ this.advance();
6938
+ var params = [];
6939
+ while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
6940
+ params.push(this.parseExpression());
6941
+ if (isA_OperatorToken(this.peek(), ';')) {
6942
+ this.advance();
6943
+ }
6944
+ }
6945
+ assertA_ReservedSymbolToken(this.peek(), 'end');
6946
+ this.advance();
6947
+ return {
6948
+ t: exports.AstNodeType.SpecialExpression,
6949
+ n: 'loop',
6950
+ p: params,
6951
+ bs: bindingNodes,
6952
+ token: getTokenDebugData(token) && token,
6953
+ };
6954
+ };
6955
+ AlgebraicParser.prototype.parseTry = function (token) {
6956
+ this.advance();
6957
+ var tryExpressions = [];
6958
+ while (!this.isAtEnd() && !isA_SymbolToken(this.peek(), 'catch')) {
6959
+ tryExpressions.push(this.parseExpression());
6960
+ if (isA_OperatorToken(this.peek(), ';')) {
6961
+ this.advance();
6962
+ }
6963
+ }
6964
+ var tryExpression = tryExpressions.length === 1
6965
+ ? tryExpressions[0]
6966
+ : {
6967
+ t: exports.AstNodeType.SpecialExpression,
6968
+ n: 'do',
6969
+ p: tryExpressions,
6970
+ token: getTokenDebugData(token) && token,
6971
+ };
6972
+ assertA_SymbolToken(this.peek(), 'catch');
6973
+ this.advance();
6974
+ var errorSymbol;
6975
+ if (isLParenToken(this.peek())) {
6976
+ this.advance();
6977
+ errorSymbol = parseSymbol(this.tokenStream, this.parseState);
6978
+ assertRParenToken(this.peek());
6979
+ this.advance();
6980
+ }
6981
+ var catchExpressions = [];
6982
+ while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
6983
+ catchExpressions.push(this.parseExpression());
6984
+ if (isA_OperatorToken(this.peek(), ';')) {
6985
+ this.advance();
6986
+ }
6987
+ }
6988
+ assertA_ReservedSymbolToken(this.peek(), 'end');
6989
+ this.advance();
6990
+ var catchExpression = catchExpressions.length === 1
6991
+ ? catchExpressions[0]
6992
+ : {
6993
+ t: exports.AstNodeType.SpecialExpression,
6994
+ n: 'do',
6995
+ p: catchExpressions,
6996
+ token: getTokenDebugData(token) && token,
6997
+ };
6998
+ return {
6999
+ t: exports.AstNodeType.SpecialExpression,
7000
+ n: 'try',
7001
+ p: [tryExpression],
7002
+ ce: catchExpression,
7003
+ e: errorSymbol,
7004
+ token: getTokenDebugData(token) && token,
7663
7005
  };
7664
7006
  };
7665
- AlgebraicParser.prototype.parseFor = function (token) {
7007
+ AlgebraicParser.prototype.parseForOrDoseq = function (token) {
7008
+ var isDoseq = token[1] === 'doseq';
7666
7009
  this.advance();
7667
7010
  assertLParenToken(this.peek());
7668
7011
  this.advance();
@@ -7682,7 +7025,7 @@ var Lits = (function (exports) {
7682
7025
  this.advance();
7683
7026
  return {
7684
7027
  t: exports.AstNodeType.SpecialExpression,
7685
- n: 'for',
7028
+ n: isDoseq ? 'doseq' : 'for',
7686
7029
  p: [expression],
7687
7030
  token: getTokenDebugData(token) && token,
7688
7031
  l: forLoopBindings,
@@ -7702,33 +7045,26 @@ var Lits = (function (exports) {
7702
7045
  }
7703
7046
  var modifiers = [];
7704
7047
  var token = this.peek();
7705
- if (!isA_SymbolToken(token)) {
7048
+ if (!isA_SymbolToken(token, 'let')
7049
+ && !isA_ReservedSymbolToken(token, 'when')
7050
+ && !isA_ReservedSymbolToken(token, 'while')) {
7706
7051
  throw new LitsError('Expected symbol let, when or while', (_a = getTokenDebugData(token)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
7707
7052
  }
7708
7053
  var letBindings;
7709
7054
  if (token[1] === 'let') {
7710
7055
  modifiers.push('&let');
7711
7056
  letBindings = [];
7712
- this.advance();
7713
- var letObject = this.parseObject();
7714
- letBindings = arrayToPairs(letObject.p).map(function (pair) {
7715
- var key = pair[0];
7716
- var value = pair[1];
7717
- return {
7718
- t: exports.AstNodeType.Binding,
7719
- n: key.v,
7720
- v: value,
7721
- p: [],
7722
- token: getTokenDebugData(key.token) && key.token,
7723
- };
7724
- });
7057
+ while (isA_SymbolToken(token, 'let')) {
7058
+ var letNode = this.parseLet(token);
7059
+ letBindings.push(letNode.bs[0]);
7060
+ token = this.peek();
7061
+ }
7725
7062
  }
7726
7063
  token = this.peek();
7727
7064
  var whenNode;
7728
7065
  var whileNode;
7729
- while (isA_SymbolToken(token)
7730
- && ((token[1] === 'when' && !modifiers.includes('&when'))
7731
- || (token[1] === 'while' && !modifiers.includes('&while')))) {
7066
+ while (isA_ReservedSymbolToken(token, 'when')
7067
+ || isA_ReservedSymbolToken(token, 'while')) {
7732
7068
  this.advance();
7733
7069
  if (token[1] === 'when') {
7734
7070
  modifiers.push('&when');
@@ -7771,7 +7107,8 @@ var Lits = (function (exports) {
7771
7107
  };
7772
7108
  return node;
7773
7109
  };
7774
- AlgebraicParser.prototype.parseIf = function (token) {
7110
+ AlgebraicParser.prototype.parseIfOrUnless = function (token) {
7111
+ var isUnless = token[1] === 'unless';
7775
7112
  this.advance();
7776
7113
  var condition = this.parseExpression();
7777
7114
  assertA_ReservedSymbolToken(this.peek(), 'then');
@@ -7820,7 +7157,7 @@ var Lits = (function (exports) {
7820
7157
  }
7821
7158
  return {
7822
7159
  t: exports.AstNodeType.SpecialExpression,
7823
- n: 'if',
7160
+ n: isUnless ? 'unless' : 'if',
7824
7161
  p: params,
7825
7162
  token: getTokenDebugData(token) && token,
7826
7163
  };
@@ -7947,6 +7284,22 @@ var Lits = (function (exports) {
7947
7284
  AlgebraicParser.prototype.isAtEnd = function () {
7948
7285
  return this.parseState.position >= this.tokenStream.tokens.length;
7949
7286
  };
7287
+ AlgebraicParser.prototype.isAtExpressionEnd = function () {
7288
+ if (this.isAtEnd()) {
7289
+ return true;
7290
+ }
7291
+ var token = this.peek();
7292
+ if (isA_OperatorToken(token)) {
7293
+ return [';', ','].includes(token[1]);
7294
+ }
7295
+ if (isA_SymbolToken(token)) {
7296
+ return ['catch'].includes(token[1]);
7297
+ }
7298
+ if (isA_ReservedSymbolToken(token)) {
7299
+ return ['else', 'when', 'while', 'then', 'end', 'case'].includes(token[1]);
7300
+ }
7301
+ return false;
7302
+ };
7950
7303
  AlgebraicParser.prototype.peek = function () {
7951
7304
  return this.tokenStream.tokens[this.parseState.position];
7952
7305
  };
@@ -8412,17 +7765,12 @@ var Lits = (function (exports) {
8412
7765
  else: { value: null, forbidden: false },
8413
7766
  end: { value: null, forbidden: false },
8414
7767
  case: { value: null, forbidden: false },
7768
+ when: { value: null, forbidden: false },
7769
+ while: { value: null, forbidden: false },
8415
7770
  };
8416
7771
  var forbiddenAlgebraicReservedNamesRecord = {
8417
- if_let: { value: null, forbidden: true },
8418
- when_let: { value: null, forbidden: true },
8419
- when_first: { value: null, forbidden: true },
8420
7772
  fn: { value: null, forbidden: true },
8421
7773
  defns: { value: null, forbidden: true },
8422
- try: { value: null, forbidden: true },
8423
- recur: { value: null, forbidden: true },
8424
- loop: { value: null, forbidden: true },
8425
- doseq: { value: null, forbidden: true },
8426
7774
  };
8427
7775
  var algebraicReservedNamesRecord = __assign(__assign({}, validAlgebraicReservedNamesRecord), forbiddenAlgebraicReservedNamesRecord);
8428
7776
 
@@ -10121,7 +9469,7 @@ var Lits = (function (exports) {
10121
9469
  description: 'Takes a nested array $x and flattens it.',
10122
9470
  examples: [
10123
9471
  '(flatten [1 2 [3 4] 5])',
10124
- "\n(let [foo :bar]\n (flatten\n [1\n \" 2 A \"\n [foo [4 [:ABC]]] 6]))",
9472
+ "\n(let [foo :bar])\n(flatten\n [1\n \" 2 A \"\n [foo [4 [:ABC]]] 6])",
10125
9473
  '(flatten 12)',
10126
9474
  ],
10127
9475
  },
@@ -13968,97 +13316,12 @@ var Lits = (function (exports) {
13968
13316
  type: '*binding',
13969
13317
  rest: true,
13970
13318
  },
13971
- expressions: {
13972
- type: '*expression',
13973
- rest: true,
13974
- },
13975
- },
13976
- variants: [
13977
- { argumentNames: ['bindings', 'expressions'] },
13978
- ],
13979
- description: "\nBinds local variables. The variables lives only within $expressions.\nIt returns evaluation of the last expression in $expressions.",
13980
- examples: ["\n (let [a (+ 1 2 3 4) \n b (* 1 2 3 4)]\n (write! a b))"],
13981
- },
13982
- 'if_let': {
13983
- title: 'if_let',
13984
- category: 'Special expression',
13985
- linkName: 'if_let',
13986
- returns: {
13987
- type: 'any',
13988
- },
13989
- args: {
13990
- 'binding': {
13991
- type: '*binding',
13992
- },
13993
- 'then-expr': {
13994
- type: '*expression',
13995
- },
13996
- 'else-expr': {
13997
- type: '*expression',
13998
- },
13999
- },
14000
- variants: [
14001
- { argumentNames: ['binding', 'then-expr'] },
14002
- { argumentNames: ['binding', 'then-expr', 'else-expr'] },
14003
- ],
14004
- 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).",
14005
- examples: [
14006
- "\n(if_let [a (> (count \"Albert\") 4)]\n (write! (str a \", is big enough\"))\n (write! \"Sorry, not big enough.\"))",
14007
- "\n(if_let [a (> (count \"Albert\") 10)]\n (write! (str a \", is big enough\"))\n (write! \"Sorry, not big enough.\"))",
14008
- ],
14009
- },
14010
- 'when_let': {
14011
- title: 'when_let',
14012
- category: 'Special expression',
14013
- linkName: 'when_let',
14014
- returns: {
14015
- type: 'any',
14016
- },
14017
- args: {
14018
- binding: {
14019
- type: '*binding',
14020
- },
14021
- expressions: {
14022
- type: '*expression',
14023
- rest: true,
14024
- },
14025
- },
14026
- variants: [
14027
- { argumentNames: ['binding', 'expressions'] },
14028
- ],
14029
- 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.",
14030
- examples: [
14031
- "\n(when_let [a (> (count \"Albert\") 4)]\n (write! a))",
14032
- ],
14033
- },
14034
- 'when_first': {
14035
- title: 'when_first',
14036
- category: 'Special expression',
14037
- linkName: 'when_first',
14038
- returns: {
14039
- type: 'any',
14040
- },
14041
- args: {
14042
- binding: {
14043
- type: '*binding',
14044
- rest: true,
14045
- },
14046
- expressions: {
14047
- type: '*expression',
14048
- rest: true,
14049
- },
14050
13319
  },
14051
13320
  variants: [
14052
- { argumentNames: ['binding', 'expressions'] },
14053
- ],
14054
- 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.',
14055
- examples: [
14056
- "\n(when_first [x [1 2 3]]\n (write! x)\n x)",
14057
- "\n(when_first [x \"Albert\"]\n (write! x)\n x)",
14058
- "\n(when_first [x [0]]\n (write! x)\n x)",
14059
- "\n(when_first [x [nil]]\n (write! x)\n x)",
14060
- "\n(when_first [x []]\n (write! x)\n x)",
13321
+ { argumentNames: ['bindings'] },
14061
13322
  ],
13323
+ description: "\nBinds local variables.",
13324
+ examples: ["\n(let [a (+ 1 2 3 4) \n b (* 1 2 3 4)])\n(write! a b)"],
14062
13325
  },
14063
13326
  'fn': {
14064
13327
  title: 'fn',
@@ -14222,10 +13485,11 @@ var Lits = (function (exports) {
14222
13485
  '(if false (write! "TRUE"))',
14223
13486
  ],
14224
13487
  },
14225
- 'if_not': {
14226
- title: 'if_not',
13488
+ 'unless': {
13489
+ title: 'unless',
14227
13490
  category: 'Special expression',
14228
- linkName: 'if_not',
13491
+ linkName: 'unless',
13492
+ clojureDocs: 'if-not',
14229
13493
  returns: {
14230
13494
  type: 'any',
14231
13495
  },
@@ -14246,10 +13510,10 @@ var Lits = (function (exports) {
14246
13510
  ],
14247
13511
  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.',
14248
13512
  examples: [
14249
- '(if_not true (write! "TRUE") (write! "FALSE"))',
14250
- '(if_not false (write! "TRUE") (write! "FALSE"))',
14251
- '(if_not true (write! "TRUE"))',
14252
- '(if_not false (write! "TRUE"))',
13513
+ '(unless true (write! "TRUE") (write! "FALSE"))',
13514
+ '(unless false (write! "TRUE") (write! "FALSE"))',
13515
+ '(unless true (write! "TRUE"))',
13516
+ '(unless false (write! "TRUE"))',
14253
13517
  ],
14254
13518
  },
14255
13519
  'cond': {
@@ -14299,60 +13563,6 @@ var Lits = (function (exports) {
14299
13563
  "\n(switch 3\n 1 (write! \"FALSE\")\n 2 (write! \"nil\"))",
14300
13564
  ],
14301
13565
  },
14302
- 'when': {
14303
- title: 'when',
14304
- category: 'Special expression',
14305
- linkName: 'when',
14306
- returns: {
14307
- type: 'any',
14308
- },
14309
- args: {
14310
- test: {
14311
- type: '*expression',
14312
- },
14313
- expressions: {
14314
- type: '*expression',
14315
- rest: true,
14316
- },
14317
- },
14318
- variants: [
14319
- { argumentNames: ['test', 'expressions'] },
14320
- ],
14321
- 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.",
14322
- examples: [
14323
- "(when true\n (write! \"Hi\")\n (write! \"There\"))",
14324
- "(when false\n (write! \"Hi\")\n (write! \"There\"))",
14325
- '(when true)',
14326
- '(when false)',
14327
- ],
14328
- },
14329
- 'when_not': {
14330
- title: 'when_not',
14331
- category: 'Special expression',
14332
- linkName: 'when_not',
14333
- returns: {
14334
- type: 'any',
14335
- },
14336
- args: {
14337
- test: {
14338
- type: '*expression',
14339
- },
14340
- expressions: {
14341
- type: '*expression',
14342
- rest: true,
14343
- },
14344
- },
14345
- variants: [
14346
- { argumentNames: ['test', 'expressions'] },
14347
- ],
14348
- 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.",
14349
- examples: [
14350
- '(when_not true (write! "Hi") (write! "There"))',
14351
- '(when_not false (write! "Hi") (write! "There"))',
14352
- '(when_not true)',
14353
- '(when_not false)',
14354
- ],
14355
- },
14356
13566
  'comment': {
14357
13567
  title: 'comment',
14358
13568
  category: 'Special expression',
@@ -14412,9 +13622,9 @@ var Lits = (function (exports) {
14412
13622
  ],
14413
13623
  description: 'Recursevly calls enclosing function or loop with its evaluated $expressions.',
14414
13624
  examples: [
14415
- "\n(defn foo [n]\n (write! n)\n (when (! (zero? n))\n (recur\n (dec n))))\n(foo 3)",
14416
- "\n(\n (fn [n]\n (write! n)\n (when (! (zero? n))\n (recur\n (dec n))))\n 3)",
14417
- "\n(\n loop [n 3]\n (write! n)\n (when\n (! (zero? n))\n (recur (dec n))))",
13625
+ "\n(defn foo [n]\n (write! n)\n (if (! (zero? n))\n (recur\n (dec n))))\n(foo 3)",
13626
+ "\n(\n (fn [n]\n (write! n)\n (if (! (zero? n))\n (recur\n (dec n))))\n 3)",
13627
+ "\n(\n loop [n 3]\n (write! n)\n (if\n (! (zero? n))\n (recur (dec n))))",
14418
13628
  ],
14419
13629
  },
14420
13630
  'loop': {
@@ -14439,7 +13649,7 @@ var Lits = (function (exports) {
14439
13649
  ],
14440
13650
  description: 'Executes $expressions with initial $bindings. The $bindings will be replaced with the recur parameters for subsequent recursions.',
14441
13651
  examples: [
14442
- "\n(loop [n 3]\n (write! n)\n (when\n (! (zero? n))\n (recur (dec n))))",
13652
+ "\n(loop [n 3]\n (write! n)\n (if\n (! (zero? n))\n (recur (dec n))))",
14443
13653
  "\n(loop [n 3]\n (write! n)\n (if\n (! (zero? n))\n (recur (dec n))\n n))",
14444
13654
  ],
14445
13655
  },
@@ -14498,10 +13708,10 @@ var Lits = (function (exports) {
14498
13708
  "\n(for\n [x [1 2 3] y [1 2 3] z [1 2 3]\n &while (<= x y)]\n \n [x y z])",
14499
13709
  ],
14500
13710
  },
14501
- 'declared?': {
14502
- title: 'declared?',
13711
+ 'defined?': {
13712
+ title: 'defined?',
14503
13713
  category: 'Special expression',
14504
- linkName: 'declared-question',
13714
+ linkName: 'defined-question',
14505
13715
  returns: {
14506
13716
  type: 'boolean',
14507
13717
  },
@@ -14515,11 +13725,11 @@ var Lits = (function (exports) {
14515
13725
  ],
14516
13726
  description: 'Returns `true` if $n is a declared variable or a builtin function, otherwise `false`.',
14517
13727
  examples: [
14518
- '(declared? foo)',
14519
- "\n(def foo :foo)\n(declared? foo)",
14520
- '(declared? +)',
14521
- "\n(def foo nil)\n(declared? foo)",
14522
- '(declared? if)',
13728
+ '(defined? foo)',
13729
+ "\n(def foo :foo)\n(defined? foo)",
13730
+ '(defined? +)',
13731
+ "\n(def foo nil)\n(defined? foo)",
13732
+ '(defined? if)',
14523
13733
  ],
14524
13734
  },
14525
13735
  '??': {
@@ -15798,27 +15008,22 @@ var Lits = (function (exports) {
15798
15008
  'def',
15799
15009
  'defs',
15800
15010
  'let',
15801
- 'if_let',
15802
- 'when_let',
15803
- 'when_first',
15804
15011
  'fn',
15805
15012
  'defn',
15806
15013
  'defns',
15807
15014
  'try',
15808
15015
  'throw',
15809
15016
  'if',
15810
- 'if_not',
15017
+ 'unless',
15811
15018
  'cond',
15812
15019
  'switch',
15813
- 'when',
15814
- 'when_not',
15815
15020
  'comment',
15816
15021
  'do',
15817
15022
  'recur',
15818
15023
  'loop',
15819
15024
  'doseq',
15820
15025
  'for',
15821
- 'declared?',
15026
+ 'defined?',
15822
15027
  '??',
15823
15028
  ],
15824
15029
  string: [