From 0d7e9989b592f499dfa8d93f2e102758e7acd395 Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Fri, 22 Mar 2024 17:47:07 +0100 Subject: [PATCH] Refactor Parser to alow #!fold-case in REPL #342 --- dist/lips.cjs | 607 +++++++++++++++++++++++-------------------- dist/lips.esm.js | 607 +++++++++++++++++++++++-------------------- dist/lips.esm.min.js | 4 +- dist/lips.js | 607 +++++++++++++++++++++++-------------------- dist/lips.min.js | 6 +- src/lips.js | 39 ++- 6 files changed, 1001 insertions(+), 869 deletions(-) diff --git a/dist/lips.cjs b/dist/lips.cjs index 5608ff98..a8985ed4 100644 --- a/dist/lips.cjs +++ b/dist/lips.cjs @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Fri, 22 Mar 2024 13:26:48 +0000 + * build: Fri, 22 Mar 2024 16:45:56 +0000 */ 'use strict'; @@ -4848,21 +4848,17 @@ function match_or_null(re, _char6) { // :: ref: https://github.com/biwascheme/biwascheme/blob/master/src/system/parser.js // ---------------------------------------------------------------------- var Parser = /*#__PURE__*/function () { - function Parser(arg) { - var _ref9 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + function Parser() { + var _ref9 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, env = _ref9.env, _ref9$meta = _ref9.meta, meta = _ref9$meta === void 0 ? false : _ref9$meta, _ref9$formatter = _ref9.formatter, formatter = _ref9$formatter === void 0 ? multiline_formatter : _ref9$formatter; _classCallCheck(this, Parser); - if (arg instanceof LString) { - arg = arg.toString(); - } read_only(this, '_formatter', formatter, { hidden: true }); - read_only(this, '__lexer__', new Lexer(arg)); read_only(this, '__env__', env); read_only(this, '_meta', meta, { hidden: true @@ -4879,6 +4875,14 @@ var Parser = /*#__PURE__*/function () { }); } _createClass(Parser, [{ + key: "parse", + value: function parse(arg) { + if (arg instanceof LString) { + arg = arg.toString(); + } + read_only(this, '__lexer__', new Lexer(arg)); + } + }, { key: "resolve", value: function resolve(name) { return this.__env__ && this.__env__.get(name, { @@ -5500,9 +5504,14 @@ function _parse2() { env = user_env; } } - parser = new Parser(arg, { - env: env - }); + if (arg instanceof Parser) { + parser = arg; + } else { + parser = new Parser({ + env: env + }); + parser.parse(arg); + } case 2: _context9.next = 5; return _awaitAsyncGenerator(parser.read_object()); @@ -5613,65 +5622,65 @@ function uniterate_async(_x5) { // :: Function that return matcher function that match string against string // ---------------------------------------------------------------------- function _uniterate_async() { - _uniterate_async = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21(object) { + _uniterate_async = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22(object) { var result, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, item; - return _regeneratorRuntime.wrap(function _callee21$(_context22) { - while (1) switch (_context22.prev = _context22.next) { + return _regeneratorRuntime.wrap(function _callee22$(_context23) { + while (1) switch (_context23.prev = _context23.next) { case 0: result = []; _iteratorAbruptCompletion = false; _didIteratorError = false; - _context22.prev = 3; + _context23.prev = 3; _iterator = _asyncIterator(object); case 5: - _context22.next = 7; + _context23.next = 7; return _iterator.next(); case 7: - if (!(_iteratorAbruptCompletion = !(_step = _context22.sent).done)) { - _context22.next = 13; + if (!(_iteratorAbruptCompletion = !(_step = _context23.sent).done)) { + _context23.next = 13; break; } item = _step.value; result.push(item); case 10: _iteratorAbruptCompletion = false; - _context22.next = 5; + _context23.next = 5; break; case 13: - _context22.next = 19; + _context23.next = 19; break; case 15: - _context22.prev = 15; - _context22.t0 = _context22["catch"](3); + _context23.prev = 15; + _context23.t0 = _context23["catch"](3); _didIteratorError = true; - _iteratorError = _context22.t0; + _iteratorError = _context23.t0; case 19: - _context22.prev = 19; - _context22.prev = 20; + _context23.prev = 19; + _context23.prev = 20; if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) { - _context22.next = 24; + _context23.next = 24; break; } - _context22.next = 24; + _context23.next = 24; return _iterator["return"](); case 24: - _context22.prev = 24; + _context23.prev = 24; if (!_didIteratorError) { - _context22.next = 27; + _context23.next = 27; break; } throw _iteratorError; case 27: - return _context22.finish(24); + return _context23.finish(24); case 28: - return _context22.finish(19); + return _context23.finish(19); case 29: - return _context22.abrupt("return", result); + return _context23.abrupt("return", result); case 30: case "end": - return _context22.stop(); + return _context23.stop(); } - }, _callee21, null, [[3, 15, 19, 29], [20,, 24, 28]]); + }, _callee22, null, [[3, 15, 19, 29], [20,, 24, 28]]); })); return _uniterate_async.apply(this, arguments); } @@ -11252,19 +11261,20 @@ function InputPort(read) { while (1) switch (_context14.prev = _context14.next) { case 0: if (_this8.char_ready()) { - _context14.next = 5; + _context14.next = 6; break; } _context14.next = 3; return _this8._read(); case 3: line = _context14.sent; - parser = new Parser(line, { + parser = new Parser({ env: _this8 }); - case 5: - return _context14.abrupt("return", _this8.__parser__); + parser.parse(line); case 6: + return _context14.abrupt("return", _this8.__parser__); + case 7: case "end": return _context14.stop(); } @@ -11515,9 +11525,10 @@ function InputStringPort(string, env) { string = string.valueOf(); this._with_parser = this._with_init_parser.bind(this, function () { if (!_this16.__parser__) { - _this16.__parser__ = new Parser(string, { + _this16.__parser__ = new Parser({ env: env }); + _this16.__parser__.parse(string); } return _this16.__parser__; }); @@ -11765,6 +11776,9 @@ function Interpreter(name) { if (typeof name === 'undefined') { name = 'anonymous'; } + this.__parser__ = new Parser({ + env: this.__env__ + }); this.__env__ = user_env.inherit(name, obj); this.__env__.set('parent.frame', doc('parent.frame', function () { return _this19.__env__; @@ -11785,29 +11799,54 @@ function Interpreter(name) { set_interaction_env(this.__env__, inter); } // ------------------------------------------------------------------------- -Interpreter.prototype.exec = function (code) { - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var _options$use_dynamic = options.use_dynamic, - use_dynamic = _options$use_dynamic === void 0 ? false : _options$use_dynamic, - dynamic_env = options.dynamic_env, - env = options.env; - typecheck('Interpreter::exec', code, ['string', 'array'], 1); - typecheck('Interpreter::exec', use_dynamic, 'boolean', 2); - // simple solution to overwrite this variable in each interpreter - // before evaluation of user code - if (!env) { - env = this.__env__; - } - if (!dynamic_env) { - dynamic_env = env; - } - global_env.set('**interaction-environment**', this.__env__); - return exec(code, { - env: env, - dynamic_env: dynamic_env, - use_dynamic: use_dynamic +Interpreter.prototype.exec = /*#__PURE__*/function () { + var _ref28 = _asyncToGenerator(function (arg) { + var _this20 = this; + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + return /*#__PURE__*/_regeneratorRuntime.mark(function _callee16() { + var _options$use_dynamic, use_dynamic, dynamic_env, env; + return _regeneratorRuntime.wrap(function _callee16$(_context16) { + while (1) switch (_context16.prev = _context16.next) { + case 0: + _options$use_dynamic = options.use_dynamic, use_dynamic = _options$use_dynamic === void 0 ? false : _options$use_dynamic, dynamic_env = options.dynamic_env, env = options.env; + typecheck('Interpreter::exec', arg, ['string', 'array'], 1); + typecheck('Interpreter::exec', use_dynamic, 'boolean', 2); + // simple solution to overwrite this variable in each interpreter + // before evaluation of user code + if (!env) { + env = _this20.__env__; + } + if (!dynamic_env) { + dynamic_env = env; + } + global_env.set('**interaction-environment**', _this20.__env__); + if (!Array.isArray(arg)) { + _context16.next = 10; + break; + } + return _context16.abrupt("return", exec(arg, { + env: env, + dynamic_env: dynamic_env, + use_dynamic: use_dynamic + })); + case 10: + _this20.__parser__.parse(arg); + return _context16.abrupt("return", exec(_this20.__parser__, { + env: env, + dynamic_env: dynamic_env, + use_dynamic: use_dynamic + })); + case 12: + case "end": + return _context16.stop(); + } + }, _callee16); + })(); }); -}; + return function (_x13) { + return _ref28.apply(this, arguments); + }; +}(); // ------------------------------------------------------------------------- Interpreter.prototype.get = function (value) { var result = this.__env__.get(value); @@ -11968,12 +12007,12 @@ Environment.prototype.toString = function () { }; // ------------------------------------------------------------------------- Environment.prototype.clone = function () { - var _this20 = this; + var _this21 = this; // duplicate refs var env = {}; // TODO: duplicated Symbols Object.keys(this.__env__).forEach(function (key) { - env[key] = _this20.__env__[key]; + env[key] = _this21.__env__[key]; }); return new Environment(env, this.__parent__, this.__name__); }; @@ -12107,14 +12146,14 @@ Environment.prototype.set = function (name, value) { // For internal use only // ------------------------------------------------------------------------- Environment.prototype.constant = function (name, value) { - var _this21 = this; + var _this22 = this; if (this.__env__.hasOwnProperty(name)) { throw new Error("Environment::constant: ".concat(name, " already exists")); } if (arguments.length === 1 && is_plain_object(arguments[0])) { var obj = arguments[0]; Object.keys(obj).forEach(function (key) { - _this21.constant(name, obj[key]); + _this22.constant(name, obj[key]); }); } else { Object.defineProperty(this.__env__, name, { @@ -12286,26 +12325,26 @@ var global_env = new Environment({ // ------------------------------------------------------------------ read: doc('read', /*#__PURE__*/function () { var _read2 = _asyncToGenerator(function () { - var _this22 = this; + var _this23 = this; var arg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - return /*#__PURE__*/_regeneratorRuntime.mark(function _callee16() { + return /*#__PURE__*/_regeneratorRuntime.mark(function _callee17() { var env, port; - return _regeneratorRuntime.wrap(function _callee16$(_context16) { - while (1) switch (_context16.prev = _context16.next) { + return _regeneratorRuntime.wrap(function _callee17$(_context17) { + while (1) switch (_context17.prev = _context17.next) { case 0: - env = _this22.env; + env = _this23.env; if (arg === null) { port = internal(env, 'stdin'); } else { port = arg; } typecheck_text_port('read', port, 'input-port'); - return _context16.abrupt("return", port.read.call(env)); + return _context17.abrupt("return", port.read.call(env)); case 4: case "end": - return _context16.stop(); + return _context17.stop(); } - }, _callee16); + }, _callee17); })(); }); function read() { @@ -12418,10 +12457,10 @@ var global_env = new Environment({ return unbind(a) === unbind(b); }, "(%same-functions a b)\n\n A helper function that checks if the two input functions are\n the same."), // ------------------------------------------------------------------ - help: doc(new Macro('help', function (code, _ref28) { - var dynamic_env = _ref28.dynamic_env, - use_dynamic = _ref28.use_dynamic, - error = _ref28.error; + help: doc(new Macro('help', function (code, _ref29) { + var dynamic_env = _ref29.dynamic_env, + use_dynamic = _ref29.use_dynamic, + error = _ref29.error; var symbol; if (code.car instanceof LSymbol) { symbol = code.car; @@ -12471,10 +12510,10 @@ var global_env = new Environment({ }, "(cdr pair)\n\n This function returns the cdr (all but first) of the list."), // ------------------------------------------------------------------ 'set!': doc(new Macro('set!', function (code) { - var _this23 = this; - var _ref29 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - use_dynamic = _ref29.use_dynamic, - rest = _objectWithoutProperties(_ref29, _excluded4); + var _this24 = this; + var _ref30 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + use_dynamic = _ref30.use_dynamic, + rest = _objectWithoutProperties(_ref30, _excluded4); var dynamic_env = this; var env = this; var ref; @@ -12525,7 +12564,7 @@ var global_env = new Environment({ if (parts.length > 1) { var key = parts.pop(); var name = parts.join('.'); - var obj = _this23.get(name, { + var obj = _this24.get(name, { throwError: false }); if (obj) { @@ -12624,36 +12663,36 @@ var global_env = new Environment({ } if (is_node()) { return new Promise( /*#__PURE__*/function () { - var _ref30 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(resolve, reject) { - var path, cmd, _args19; - return _regeneratorRuntime.wrap(function _callee17$(_context17) { - while (1) switch (_context17.prev = _context17.next) { + var _ref31 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(resolve, reject) { + var path, cmd, _args20; + return _regeneratorRuntime.wrap(function _callee18$(_context18) { + while (1) switch (_context18.prev = _context18.next) { case 0: path = nodeRequire('path'); if (!module_path) { - _context17.next = 6; + _context18.next = 6; break; } module_path = module_path.valueOf(); file = path.join(module_path, file); - _context17.next = 12; + _context18.next = 12; break; case 6: cmd = g_env.get('command-line', { throwError: false }); if (!cmd) { - _context17.next = 11; + _context18.next = 11; break; } - _context17.next = 10; + _context18.next = 10; return cmd(); case 10: - _args19 = _context17.sent; + _args20 = _context18.sent; case 11: - if (_args19 && !is_nil(_args19)) { + if (_args20 && !is_nil(_args20)) { process.cwd(); - file = path.join(path.dirname(_args19.car.valueOf()), file); + file = path.join(path.dirname(_args20.car.valueOf()), file); } case 12: global_env.set(PATH, path.dirname(file)); @@ -12674,12 +12713,12 @@ var global_env = new Environment({ }); case 14: case "end": - return _context17.stop(); + return _context18.stop(); } - }, _callee17); + }, _callee18); })); - return function (_x13, _x14) { - return _ref30.apply(this, arguments); + return function (_x14, _x15) { + return _ref31.apply(this, arguments); }; }()); } @@ -12711,16 +12750,16 @@ var global_env = new Environment({ }), "(while cond body)\n\n Creates a loop, it executes cond and body until cond expression is false."), // ------------------------------------------------------------------ 'do': doc(new Macro('do', /*#__PURE__*/function () { - var _ref31 = _asyncToGenerator(function (code, _ref32) { - var _this24 = this; - var use_dynamic = _ref32.use_dynamic, - error = _ref32.error; - return /*#__PURE__*/_regeneratorRuntime.mark(function _callee18() { + var _ref32 = _asyncToGenerator(function (code, _ref33) { + var _this25 = this; + var use_dynamic = _ref33.use_dynamic, + error = _ref33.error; + return /*#__PURE__*/_regeneratorRuntime.mark(function _callee19() { var self, dynamic_env, scope, vars, test, body, eval_args, node, item, _loop3; - return _regeneratorRuntime.wrap(function _callee18$(_context19) { - while (1) switch (_context19.prev = _context19.next) { + return _regeneratorRuntime.wrap(function _callee19$(_context20) { + while (1) switch (_context20.prev = _context20.next) { case 0: - self = _this24; + self = _this25; dynamic_env = self; scope = self.inherit('do'); vars = code.car; @@ -12738,19 +12777,19 @@ var global_env = new Environment({ node = vars; // init variables case 9: if (is_nil(node)) { - _context19.next = 20; + _context20.next = 20; break; } item = node.car; - _context19.t0 = scope; - _context19.t1 = item.car; - _context19.next = 15; + _context20.t0 = scope; + _context20.t1 = item.car; + _context20.next = 15; return _evaluate(item.cdr.car, eval_args); case 15: - _context19.t2 = _context19.sent; - _context19.t0.set.call(_context19.t0, _context19.t1, _context19.t2); + _context20.t2 = _context20.sent; + _context20.t0.set.call(_context20.t0, _context20.t1, _context20.t2); node = node.cdr; - _context19.next = 9; + _context20.next = 9; break; case 20: eval_args = { @@ -12760,36 +12799,36 @@ var global_env = new Environment({ }; _loop3 = /*#__PURE__*/_regeneratorRuntime.mark(function _loop3() { var node, next, _item, value, symbols; - return _regeneratorRuntime.wrap(function _loop3$(_context18) { - while (1) switch (_context18.prev = _context18.next) { + return _regeneratorRuntime.wrap(function _loop3$(_context19) { + while (1) switch (_context19.prev = _context19.next) { case 0: if (is_nil(body)) { - _context18.next = 3; + _context19.next = 3; break; } - _context18.next = 3; + _context19.next = 3; return lips.evaluate(body, eval_args); case 3: node = vars; next = {}; // next value of variables case 5: if (is_nil(node)) { - _context18.next = 15; + _context19.next = 15; break; } _item = node.car; if (is_nil(_item.cdr.cdr)) { - _context18.next = 12; + _context19.next = 12; break; } - _context18.next = 10; + _context19.next = 10; return _evaluate(_item.cdr.cdr.car, eval_args); case 10: - value = _context18.sent; + value = _context19.sent; next[_item.car.valueOf()] = value; case 12: node = node.cdr; - _context18.next = 5; + _context19.next = 5; break; case 15: symbols = Object.getOwnPropertySymbols(next); // new scope for new iteration @@ -12799,47 +12838,47 @@ var global_env = new Environment({ }); case 18: case "end": - return _context18.stop(); + return _context19.stop(); } }, _loop3); }); case 22: - _context19.next = 24; + _context20.next = 24; return _evaluate(test.car, eval_args); case 24: - _context19.t3 = _context19.sent; - if (!(_context19.t3 === false)) { - _context19.next = 29; + _context20.t3 = _context20.sent; + if (!(_context20.t3 === false)) { + _context20.next = 29; break; } - return _context19.delegateYield(_loop3(), "t4", 27); + return _context20.delegateYield(_loop3(), "t4", 27); case 27: - _context19.next = 22; + _context20.next = 22; break; case 29: if (is_nil(test.cdr)) { - _context19.next = 33; + _context20.next = 33; break; } - _context19.next = 32; + _context20.next = 32; return _evaluate(test.cdr.car, eval_args); case 32: - return _context19.abrupt("return", _context19.sent); + return _context20.abrupt("return", _context20.sent); case 33: case "end": - return _context19.stop(); + return _context20.stop(); } - }, _callee18); + }, _callee19); })(); }); - return function (_x15, _x16) { - return _ref31.apply(this, arguments); + return function (_x16, _x17) { + return _ref32.apply(this, arguments); }; }()), "(do (( )) (test return) . body)\n\n Iteration macro that evaluates the expression body in scope of the variables.\n On each loop it changes the variables according to the expression and runs\n test to check if the loop should continue. If test is a single value, the macro\n will return undefined. If the test is a pair of expressions the macro will\n evaluate and return the second expression after the loop exits."), // ------------------------------------------------------------------ - 'if': doc(new Macro('if', function (code, _ref33) { - var error = _ref33.error, - use_dynamic = _ref33.use_dynamic; + 'if': doc(new Macro('if', function (code, _ref34) { + var error = _ref34.error, + use_dynamic = _ref34.use_dynamic; var dynamic_env = this; var env = this; var eval_args = { @@ -13157,28 +13196,28 @@ var global_env = new Environment({ }, "(parent.frame)\n\n Returns the parent environment if called from inside a function.\n If no parent frame can be found it returns nil."), // ------------------------------------------------------------------ 'eval': doc('eval', function (code, env) { - var _this25 = this; + var _this26 = this; env = env || this.get('interaction-environment').call(this); return _evaluate(code, { env: env, dynamic_env: env, error: function error(e) { var error = global_env.get('display-error'); - error.call(_this25, e.message); + error.call(_this26, e.message); if (e.code) { var stack = e.code.map(function (line, i) { return "[".concat(i + 1, "]: ").concat(line); }).join('\n'); - error.call(_this25, stack); + error.call(_this26, stack); } } }); }, "(eval expr)\n (eval expr environment)\n\n Function that evaluates LIPS Scheme code. If the second argument is provided\n it will be the environment that the code is evaluated in."), // ------------------------------------------------------------------ lambda: new Macro('lambda', function (code) { - var _ref34 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - use_dynamic = _ref34.use_dynamic, - error = _ref34.error; + var _ref35 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + use_dynamic = _ref35.use_dynamic, + error = _ref35.error; var self = this; var __doc__; if (is_pair(code.cdr) && LString.isString(code.cdr.car) && !is_nil(code.cdr.cdr)) { @@ -13186,10 +13225,10 @@ var global_env = new Environment({ } function lambda() { // lambda got scopes as context in apply - var _ref35 = is_context(this) ? this : { + var _ref36 = is_context(this) ? this : { dynamic_env: self }, - dynamic_env = _ref35.dynamic_env; + dynamic_env = _ref36.dynamic_env; var env = self.inherit('lambda'); dynamic_env = dynamic_env.inherit('lambda'); if (this && !is_context(this)) { @@ -13272,9 +13311,9 @@ var global_env = new Environment({ // ------------------------------------------------------------------ 'macroexpand-1': doc(new Macro('macroexpand-1', macro_expand(true)), "(macroexpand-1 expr)\n\n Macro similar to macroexpand but it expand macros only one level\n and return single expression as output."), // ------------------------------------------------------------------ - 'define-macro': doc(new Macro(macro, function (macro, _ref36) { - var use_dynamic = _ref36.use_dynamic, - error = _ref36.error; + 'define-macro': doc(new Macro(macro, function (macro, _ref37) { + var use_dynamic = _ref37.use_dynamic, + error = _ref37.error; if (is_pair(macro.car) && macro.car.car instanceof LSymbol) { var name = macro.car.car.__name__; var __doc__; @@ -13364,8 +13403,8 @@ var global_env = new Environment({ } else { validate_identifiers(macro.car); } - var syntax = new Syntax(function (code, _ref37) { - var macro_expand = _ref37.macro_expand; + var syntax = new Syntax(function (code, _ref38) { + var macro_expand = _ref38.macro_expand; log('>> SYNTAX'); log(code); log(macro); @@ -13491,10 +13530,10 @@ var global_env = new Environment({ cdr = fn(cdr); } if (is_promise(car) || is_promise(cdr)) { - return promise_all([car, cdr]).then(function (_ref38) { - var _ref39 = _slicedToArray(_ref38, 2), - car = _ref39[0], - cdr = _ref39[1]; + return promise_all([car, cdr]).then(function (_ref39) { + var _ref40 = _slicedToArray(_ref39, 2), + car = _ref40[0], + cdr = _ref40[1]; return new Pair(car, cdr); }); } else { @@ -14114,10 +14153,10 @@ var global_env = new Environment({ return false; }, "(string->number number [radix])\n\n Function that parses a string into a number."), // ------------------------------------------------------------------ - 'try': doc(new Macro('try', function (code, _ref40) { - var _this26 = this; - var use_dynamic = _ref40.use_dynamic; - _ref40.error; + 'try': doc(new Macro('try', function (code, _ref41) { + var _this27 = this; + var use_dynamic = _ref41.use_dynamic; + _ref41.error; return new Promise(function (resolve, reject) { var catch_clause, finally_clause; if (LSymbol.is(code.cdr.car.car, 'catch')) { @@ -14151,15 +14190,15 @@ var global_env = new Environment({ }; } var args = { - env: _this26, + env: _this27, use_dynamic: use_dynamic, - dynamic_env: _this26, + dynamic_env: _this27, error: function error(e) { if (e instanceof IgnoreException) { throw e; } if (catch_clause) { - var env = _this26.inherit('try'); + var env = _this27.inherit('try'); var name = catch_clause.cdr.car.car; if (!(name instanceof LSymbol)) { throw new Error('try: invalid syntax: catch require variable name'); @@ -14169,7 +14208,7 @@ var global_env = new Environment({ var catch_args = { env: env, use_dynamic: use_dynamic, - dynamic_env: _this26, + dynamic_env: _this27, error: function error(e) { catch_error = true; reject(e); @@ -14237,7 +14276,7 @@ var global_env = new Environment({ }, "(for-each fn . lists)\n\n Higher-order function that calls function `fn` on each\n value of the argument. If you provide more than one list\n it will take each value from each list and call `fn` function\n with that many arguments as number of list arguments."), // ------------------------------------------------------------------ map: doc('map', function map(fn) { - var _this27 = this; + var _this28 = this; for (var _len32 = arguments.length, lists = new Array(_len32 > 1 ? _len32 - 1 : 0), _key32 = 1; _key32 < _len32; _key32++) { lists[_key32 - 1] = arguments[_key32]; } @@ -14246,7 +14285,7 @@ var global_env = new Environment({ lists.forEach(function (arg, i) { typecheck('map', arg, ['pair', 'nil'], i + 1); // detect cycles - if (is_pair(arg) && !is_list.call(_this27, arg)) { + if (is_pair(arg) && !is_list.call(_this28, arg)) { throw new Error("map: argument ".concat(i + 1, " is not a list")); } }); @@ -14268,7 +14307,7 @@ var global_env = new Environment({ use_dynamic: use_dynamic }); return unpromise(result, function (head) { - return unpromise(map.call.apply(map, [_this27, fn].concat(_toConsumableArray(lists.map(function (l) { + return unpromise(map.call.apply(map, [_this28, fn].concat(_toConsumableArray(lists.map(function (l) { return l.cdr; })))), function (rest) { return new Pair(head, rest); @@ -14350,7 +14389,7 @@ var global_env = new Environment({ }, "(pluck . strings)\n\n If called with a single string it will return a function that when\n called with an object will return that key from the object.\n If called with more then one string the returned function will\n create a new object by copying all properties from the given object."), // ------------------------------------------------------------------ reduce: doc('reduce', fold('reduce', function (reduce, fn, init) { - var _this28 = this; + var _this29 = this; for (var _len35 = arguments.length, lists = new Array(_len35 > 3 ? _len35 - 3 : 0), _key36 = 3; _key36 < _len35; _key36++) { lists[_key36 - 3] = arguments[_key36]; } @@ -14364,7 +14403,7 @@ var global_env = new Environment({ return unpromise(fn.apply(void 0, _toConsumableArray(lists.map(function (l) { return l.car; })).concat([init])), function (value) { - return reduce.call.apply(reduce, [_this28, fn, value].concat(_toConsumableArray(lists.map(function (l) { + return reduce.call.apply(reduce, [_this29, fn, value].concat(_toConsumableArray(lists.map(function (l) { return l.cdr; })))); }); @@ -14578,9 +14617,9 @@ var global_env = new Environment({ // ------------------------------------------------------------------ 'eq?': doc('eq?', equal, "(eq? a b)\n\n Function that compares two values if they are identical."), // ------------------------------------------------------------------ - or: doc(new Macro('or', function (code, _ref41) { - var use_dynamic = _ref41.use_dynamic, - error = _ref41.error; + or: doc(new Macro('or', function (code, _ref42) { + var use_dynamic = _ref42.use_dynamic, + error = _ref42.error; var args = global_env.get('list->array')(code); var self = this; var dynamic_env = self; @@ -14617,9 +14656,9 @@ var global_env = new Environment({ }), "(or . expressions)\n\n Macro that executes the values one by one and returns the first that is\n a truthy value. If there are no expressions that evaluate to true it\n returns false."), // ------------------------------------------------------------------ and: doc(new Macro('and', function (code) { - var _ref42 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - use_dynamic = _ref42.use_dynamic, - error = _ref42.error; + var _ref43 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + use_dynamic = _ref43.use_dynamic, + error = _ref43.error; var args = global_env.get('list->array')(code); var self = this; var dynamic_env = self; @@ -14788,25 +14827,25 @@ function node_specific() { } // ------------------------------------------------------------------------- /* c8 ignore next 11 */ function _node_specific() { - _node_specific = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22() { + _node_specific = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee23() { var _yield$import, createRequire, moduleURL, __dirname, __filename; - return _regeneratorRuntime.wrap(function _callee22$(_context23) { - while (1) switch (_context23.prev = _context23.next) { + return _regeneratorRuntime.wrap(function _callee23$(_context24) { + while (1) switch (_context24.prev = _context24.next) { case 0: - _context23.next = 2; + _context24.next = 2; return import('mod' + 'ule'); case 2: - _yield$import = _context23.sent; + _yield$import = _context24.sent; createRequire = _yield$import.createRequire; nodeRequire = createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('lips.cjs', document.baseURI).href))); - _context23.next = 7; + _context24.next = 7; return import('fs'); case 7: - fs = _context23.sent; - _context23.next = 10; + fs = _context24.sent; + _context24.next = 10; return import('path'); case 10: - path = _context23.sent; + path = _context24.sent; global_env.set('global', global); global_env.set('self', global); global_env.set('window', undefined); @@ -14854,9 +14893,9 @@ function _node_specific() { }); case 22: case "end": - return _context23.stop(); + return _context24.stop(); } - }, _callee22); + }, _callee23); })); return _node_specific.apply(this, arguments); } @@ -15060,54 +15099,54 @@ function resolve_promises(arg) { node.forEach(traverse); } } - function promise(_x17) { + function promise(_x18) { return _promise.apply(this, arguments); } function _promise() { - _promise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(node) { + _promise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20(node) { var pair; - return _regeneratorRuntime.wrap(function _callee19$(_context20) { - while (1) switch (_context20.prev = _context20.next) { + return _regeneratorRuntime.wrap(function _callee20$(_context21) { + while (1) switch (_context21.prev = _context21.next) { case 0: - _context20.t0 = Pair; + _context21.t0 = Pair; if (!node.have_cycles('car')) { - _context20.next = 5; + _context21.next = 5; break; } - _context20.t1 = node.car; - _context20.next = 8; + _context21.t1 = node.car; + _context21.next = 8; break; case 5: - _context20.next = 7; + _context21.next = 7; return resolve(node.car); case 7: - _context20.t1 = _context20.sent; + _context21.t1 = _context21.sent; case 8: - _context20.t2 = _context20.t1; + _context21.t2 = _context21.t1; if (!node.have_cycles('cdr')) { - _context20.next = 13; + _context21.next = 13; break; } - _context20.t3 = node.cdr; - _context20.next = 16; + _context21.t3 = node.cdr; + _context21.next = 16; break; case 13: - _context20.next = 15; + _context21.next = 15; return resolve(node.cdr); case 15: - _context20.t3 = _context20.sent; + _context21.t3 = _context21.sent; case 16: - _context20.t4 = _context20.t3; - pair = new _context20.t0(_context20.t2, _context20.t4); + _context21.t4 = _context21.t3; + pair = new _context21.t0(_context21.t2, _context21.t4); if (node[__data__]) { pair[__data__] = true; } - return _context20.abrupt("return", pair); + return _context21.abrupt("return", pair); case 20: case "end": - return _context20.stop(); + return _context21.stop(); } - }, _callee19); + }, _callee20); })); return _promise.apply(this, arguments); } @@ -15122,9 +15161,9 @@ function resolve_promises(arg) { } } // ------------------------------------------------------------------------- -function evaluate_args(rest, _ref43) { - var use_dynamic = _ref43.use_dynamic, - options = _objectWithoutProperties(_ref43, _excluded5); +function evaluate_args(rest, _ref44) { + var use_dynamic = _ref44.use_dynamic, + options = _objectWithoutProperties(_ref44, _excluded5); var args = []; var node = rest; function next() { @@ -15232,10 +15271,10 @@ function prepare_fn_args(fn, args) { // ------------------------------------------------------------------------- function call_function(fn, args) { - var _ref44 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, - env = _ref44.env, - dynamic_env = _ref44.dynamic_env, - use_dynamic = _ref44.use_dynamic; + var _ref45 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + env = _ref45.env, + dynamic_env = _ref45.dynamic_env, + use_dynamic = _ref45.use_dynamic; var scope = env === null || env === void 0 ? void 0 : env.new_frame(fn, args); var dynamic_scope = dynamic_env === null || dynamic_env === void 0 ? void 0 : dynamic_env.new_frame(fn, args); var context = new LambdaContext({ @@ -15248,12 +15287,12 @@ function call_function(fn, args) { // ------------------------------------------------------------------------- function apply(fn, args) { - var _ref45 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, - env = _ref45.env, - dynamic_env = _ref45.dynamic_env, - use_dynamic = _ref45.use_dynamic, - _ref45$error = _ref45.error, - error = _ref45$error === void 0 ? function () {} : _ref45$error; + var _ref46 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + env = _ref46.env, + dynamic_env = _ref46.dynamic_env, + use_dynamic = _ref46.use_dynamic, + _ref46$error = _ref46.error, + error = _ref46$error === void 0 ? function () {} : _ref46$error; args = evaluate_args(args, { env: env, dynamic_env: dynamic_env, @@ -15408,13 +15447,13 @@ var Continuation = /*#__PURE__*/function () { return Continuation; }(); // ------------------------------------------------------------------------- function _evaluate(code) { - var _ref46 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - env = _ref46.env, - dynamic_env = _ref46.dynamic_env, - use_dynamic = _ref46.use_dynamic, - _ref46$error = _ref46.error, - error = _ref46$error === void 0 ? noop : _ref46$error, - rest = _objectWithoutProperties(_ref46, _excluded6); + var _ref47 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + env = _ref47.env, + dynamic_env = _ref47.dynamic_env, + use_dynamic = _ref47.use_dynamic, + _ref47$error = _ref47.error, + error = _ref47$error === void 0 ? noop : _ref47$error, + rest = _objectWithoutProperties(_ref47, _excluded6); return function (rest) { try { if (!is_env(dynamic_env)) { @@ -15522,10 +15561,10 @@ var exec = exec_collect(function (code, value) { }); // ------------------------------------------------------------------------- function exec_with_stacktrace(code) { - var _ref47 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - env = _ref47.env, - dynamic_env = _ref47.dynamic_env, - use_dynamic = _ref47.use_dynamic; + var _ref48 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + env = _ref48.env, + dynamic_env = _ref48.dynamic_env, + use_dynamic = _ref48.use_dynamic; return _evaluate(code, { env: env, dynamic_env: dynamic_env, @@ -15555,14 +15594,14 @@ function exec_with_stacktrace(code) { function exec_collect(collect_callback) { return /*#__PURE__*/function () { var _exec_lambda = _asyncToGenerator(function (arg) { - var _ref48 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - env = _ref48.env, - dynamic_env = _ref48.dynamic_env, - use_dynamic = _ref48.use_dynamic; - return /*#__PURE__*/_regeneratorRuntime.mark(function _callee20() { + var _ref49 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + env = _ref49.env, + dynamic_env = _ref49.dynamic_env, + use_dynamic = _ref49.use_dynamic; + return /*#__PURE__*/_regeneratorRuntime.mark(function _callee21() { var results, input, _iteratorAbruptCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, code, value; - return _regeneratorRuntime.wrap(function _callee20$(_context21) { - while (1) switch (_context21.prev = _context21.next) { + return _regeneratorRuntime.wrap(function _callee21$(_context22) { + while (1) switch (_context22.prev = _context22.next) { case 0: if (!is_env(dynamic_env)) { dynamic_env = env === true ? user_env : env || user_env; @@ -15574,92 +15613,92 @@ function exec_collect(collect_callback) { } results = []; if (!is_pair(arg)) { - _context21.next = 8; + _context22.next = 8; break; } - _context21.next = 6; + _context22.next = 6; return exec_with_stacktrace(arg, { env: env, dynamic_env: dynamic_env, use_dynamic: use_dynamic }); case 6: - _context21.t0 = _context21.sent; - return _context21.abrupt("return", [_context21.t0]); + _context22.t0 = _context22.sent; + return _context22.abrupt("return", [_context22.t0]); case 8: input = Array.isArray(arg) ? arg : _parse(arg); _iteratorAbruptCompletion2 = false; _didIteratorError2 = false; - _context21.prev = 11; + _context22.prev = 11; _iterator2 = _asyncIterator(input); case 13: - _context21.next = 15; + _context22.next = 15; return _iterator2.next(); case 15: - if (!(_iteratorAbruptCompletion2 = !(_step2 = _context21.sent).done)) { - _context21.next = 31; + if (!(_iteratorAbruptCompletion2 = !(_step2 = _context22.sent).done)) { + _context22.next = 31; break; } code = _step2.value; - _context21.next = 19; + _context22.next = 19; return exec_with_stacktrace(code, { env: env, dynamic_env: dynamic_env, use_dynamic: use_dynamic }); case 19: - value = _context21.sent; - _context21.t1 = results; - _context21.t2 = collect_callback; - _context21.t3 = code; - _context21.next = 25; + value = _context22.sent; + _context22.t1 = results; + _context22.t2 = collect_callback; + _context22.t3 = code; + _context22.next = 25; return value; case 25: - _context21.t4 = _context21.sent; - _context21.t5 = (0, _context21.t2)(_context21.t3, _context21.t4); - _context21.t1.push.call(_context21.t1, _context21.t5); + _context22.t4 = _context22.sent; + _context22.t5 = (0, _context22.t2)(_context22.t3, _context22.t4); + _context22.t1.push.call(_context22.t1, _context22.t5); case 28: _iteratorAbruptCompletion2 = false; - _context21.next = 13; + _context22.next = 13; break; case 31: - _context21.next = 37; + _context22.next = 37; break; case 33: - _context21.prev = 33; - _context21.t6 = _context21["catch"](11); + _context22.prev = 33; + _context22.t6 = _context22["catch"](11); _didIteratorError2 = true; - _iteratorError2 = _context21.t6; + _iteratorError2 = _context22.t6; case 37: - _context21.prev = 37; - _context21.prev = 38; + _context22.prev = 37; + _context22.prev = 38; if (!(_iteratorAbruptCompletion2 && _iterator2["return"] != null)) { - _context21.next = 42; + _context22.next = 42; break; } - _context21.next = 42; + _context22.next = 42; return _iterator2["return"](); case 42: - _context21.prev = 42; + _context22.prev = 42; if (!_didIteratorError2) { - _context21.next = 45; + _context22.next = 45; break; } throw _iteratorError2; case 45: - return _context21.finish(42); + return _context22.finish(42); case 46: - return _context21.finish(37); + return _context22.finish(37); case 47: - return _context21.abrupt("return", results); + return _context22.abrupt("return", results); case 48: case "end": - return _context21.stop(); + return _context22.stop(); } - }, _callee20, null, [[11, 33, 37, 47], [38,, 42, 46]]); + }, _callee21, null, [[11, 33, 37, 47], [38,, 42, 46]]); })(); }); - function exec_lambda(_x18) { + function exec_lambda(_x19) { return _exec_lambda.apply(this, arguments); } return exec_lambda; @@ -15868,9 +15907,9 @@ function Worker(url) { this.rpc('init', [url])["catch"](function (error) { console.error(error); }); - this.exec = function (code, _ref49) { - var _ref49$use_dynamic = _ref49.use_dynamic, - use_dynamic = _ref49$use_dynamic === void 0 ? false : _ref49$use_dynamic; + this.exec = function (code, _ref50) { + var _ref50$use_dynamic = _ref50.use_dynamic, + use_dynamic = _ref50$use_dynamic === void 0 ? false : _ref50$use_dynamic; return this.rpc('eval', [code, use_dynamic]); }; } @@ -15879,10 +15918,10 @@ function Worker(url) { // :: Serialization // ------------------------------------------------------------------------- var serialization_map = { - 'pair': function pair(_ref50) { - var _ref51 = _slicedToArray(_ref50, 2), - car = _ref51[0], - cdr = _ref51[1]; + 'pair': function pair(_ref51) { + var _ref52 = _slicedToArray(_ref51, 2), + car = _ref52[0], + cdr = _ref52[1]; return Pair(car, cdr); }, 'number': function number(value) { @@ -15891,10 +15930,10 @@ var serialization_map = { } return LNumber(value); }, - 'regex': function regex(_ref52) { - var _ref53 = _slicedToArray(_ref52, 2), - pattern = _ref53[0], - flag = _ref53[1]; + 'regex': function regex(_ref53) { + var _ref54 = _slicedToArray(_ref53, 2), + pattern = _ref54[0], + flag = _ref54[1]; return new RegExp(pattern, flag); }, 'nil': function nil() { @@ -16188,10 +16227,10 @@ if (typeof window !== 'undefined') { // ------------------------------------------------------------------------- var banner = function () { // Rollup tree-shaking is removing the variable if it's normal string because - // obviously 'Fri, 22 Mar 2024 13:26:48 +0000' == '{{' + 'DATE}}'; can be removed + // obviously 'Fri, 22 Mar 2024 16:45:56 +0000' == '{{' + 'DATE}}'; can be removed // but disabling Tree-shaking is adding lot of not used code so we use this // hack instead - var date = LString('Fri, 22 Mar 2024 13:26:48 +0000').valueOf(); + var date = LString('Fri, 22 Mar 2024 16:45:56 +0000').valueOf(); var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date); var _format = function _format(x) { return x.toString().padStart(2, '0'); @@ -16231,7 +16270,7 @@ read_only(QuotedPromise, '__class__', 'promise'); read_only(Parameter, '__class__', 'parameter'); // ------------------------------------------------------------------------- var version = 'DEV'; -var date = 'Fri, 22 Mar 2024 13:26:48 +0000'; +var date = 'Fri, 22 Mar 2024 16:45:56 +0000'; // unwrap async generator into Promise var parse = compose(uniterate_async, _parse); diff --git a/dist/lips.esm.js b/dist/lips.esm.js index fecfbc15..bc5c5149 100644 --- a/dist/lips.esm.js +++ b/dist/lips.esm.js @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Fri, 22 Mar 2024 13:26:48 +0000 + * build: Fri, 22 Mar 2024 16:45:56 +0000 */ function _classApplyDescriptorGet(receiver, descriptor) { @@ -4845,21 +4845,17 @@ function match_or_null(re, _char6) { // :: ref: https://github.com/biwascheme/biwascheme/blob/master/src/system/parser.js // ---------------------------------------------------------------------- var Parser = /*#__PURE__*/function () { - function Parser(arg) { - var _ref9 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + function Parser() { + var _ref9 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, env = _ref9.env, _ref9$meta = _ref9.meta, meta = _ref9$meta === void 0 ? false : _ref9$meta, _ref9$formatter = _ref9.formatter, formatter = _ref9$formatter === void 0 ? multiline_formatter : _ref9$formatter; _classCallCheck(this, Parser); - if (arg instanceof LString) { - arg = arg.toString(); - } read_only(this, '_formatter', formatter, { hidden: true }); - read_only(this, '__lexer__', new Lexer(arg)); read_only(this, '__env__', env); read_only(this, '_meta', meta, { hidden: true @@ -4876,6 +4872,14 @@ var Parser = /*#__PURE__*/function () { }); } _createClass(Parser, [{ + key: "parse", + value: function parse(arg) { + if (arg instanceof LString) { + arg = arg.toString(); + } + read_only(this, '__lexer__', new Lexer(arg)); + } + }, { key: "resolve", value: function resolve(name) { return this.__env__ && this.__env__.get(name, { @@ -5497,9 +5501,14 @@ function _parse2() { env = user_env; } } - parser = new Parser(arg, { - env: env - }); + if (arg instanceof Parser) { + parser = arg; + } else { + parser = new Parser({ + env: env + }); + parser.parse(arg); + } case 2: _context9.next = 5; return _awaitAsyncGenerator(parser.read_object()); @@ -5610,65 +5619,65 @@ function uniterate_async(_x5) { // :: Function that return matcher function that match string against string // ---------------------------------------------------------------------- function _uniterate_async() { - _uniterate_async = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21(object) { + _uniterate_async = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22(object) { var result, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, item; - return _regeneratorRuntime.wrap(function _callee21$(_context22) { - while (1) switch (_context22.prev = _context22.next) { + return _regeneratorRuntime.wrap(function _callee22$(_context23) { + while (1) switch (_context23.prev = _context23.next) { case 0: result = []; _iteratorAbruptCompletion = false; _didIteratorError = false; - _context22.prev = 3; + _context23.prev = 3; _iterator = _asyncIterator(object); case 5: - _context22.next = 7; + _context23.next = 7; return _iterator.next(); case 7: - if (!(_iteratorAbruptCompletion = !(_step = _context22.sent).done)) { - _context22.next = 13; + if (!(_iteratorAbruptCompletion = !(_step = _context23.sent).done)) { + _context23.next = 13; break; } item = _step.value; result.push(item); case 10: _iteratorAbruptCompletion = false; - _context22.next = 5; + _context23.next = 5; break; case 13: - _context22.next = 19; + _context23.next = 19; break; case 15: - _context22.prev = 15; - _context22.t0 = _context22["catch"](3); + _context23.prev = 15; + _context23.t0 = _context23["catch"](3); _didIteratorError = true; - _iteratorError = _context22.t0; + _iteratorError = _context23.t0; case 19: - _context22.prev = 19; - _context22.prev = 20; + _context23.prev = 19; + _context23.prev = 20; if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) { - _context22.next = 24; + _context23.next = 24; break; } - _context22.next = 24; + _context23.next = 24; return _iterator["return"](); case 24: - _context22.prev = 24; + _context23.prev = 24; if (!_didIteratorError) { - _context22.next = 27; + _context23.next = 27; break; } throw _iteratorError; case 27: - return _context22.finish(24); + return _context23.finish(24); case 28: - return _context22.finish(19); + return _context23.finish(19); case 29: - return _context22.abrupt("return", result); + return _context23.abrupt("return", result); case 30: case "end": - return _context22.stop(); + return _context23.stop(); } - }, _callee21, null, [[3, 15, 19, 29], [20,, 24, 28]]); + }, _callee22, null, [[3, 15, 19, 29], [20,, 24, 28]]); })); return _uniterate_async.apply(this, arguments); } @@ -11249,19 +11258,20 @@ function InputPort(read) { while (1) switch (_context14.prev = _context14.next) { case 0: if (_this8.char_ready()) { - _context14.next = 5; + _context14.next = 6; break; } _context14.next = 3; return _this8._read(); case 3: line = _context14.sent; - parser = new Parser(line, { + parser = new Parser({ env: _this8 }); - case 5: - return _context14.abrupt("return", _this8.__parser__); + parser.parse(line); case 6: + return _context14.abrupt("return", _this8.__parser__); + case 7: case "end": return _context14.stop(); } @@ -11512,9 +11522,10 @@ function InputStringPort(string, env) { string = string.valueOf(); this._with_parser = this._with_init_parser.bind(this, function () { if (!_this16.__parser__) { - _this16.__parser__ = new Parser(string, { + _this16.__parser__ = new Parser({ env: env }); + _this16.__parser__.parse(string); } return _this16.__parser__; }); @@ -11762,6 +11773,9 @@ function Interpreter(name) { if (typeof name === 'undefined') { name = 'anonymous'; } + this.__parser__ = new Parser({ + env: this.__env__ + }); this.__env__ = user_env.inherit(name, obj); this.__env__.set('parent.frame', doc('parent.frame', function () { return _this19.__env__; @@ -11782,29 +11796,54 @@ function Interpreter(name) { set_interaction_env(this.__env__, inter); } // ------------------------------------------------------------------------- -Interpreter.prototype.exec = function (code) { - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var _options$use_dynamic = options.use_dynamic, - use_dynamic = _options$use_dynamic === void 0 ? false : _options$use_dynamic, - dynamic_env = options.dynamic_env, - env = options.env; - typecheck('Interpreter::exec', code, ['string', 'array'], 1); - typecheck('Interpreter::exec', use_dynamic, 'boolean', 2); - // simple solution to overwrite this variable in each interpreter - // before evaluation of user code - if (!env) { - env = this.__env__; - } - if (!dynamic_env) { - dynamic_env = env; - } - global_env.set('**interaction-environment**', this.__env__); - return exec(code, { - env: env, - dynamic_env: dynamic_env, - use_dynamic: use_dynamic +Interpreter.prototype.exec = /*#__PURE__*/function () { + var _ref28 = _asyncToGenerator(function (arg) { + var _this20 = this; + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + return /*#__PURE__*/_regeneratorRuntime.mark(function _callee16() { + var _options$use_dynamic, use_dynamic, dynamic_env, env; + return _regeneratorRuntime.wrap(function _callee16$(_context16) { + while (1) switch (_context16.prev = _context16.next) { + case 0: + _options$use_dynamic = options.use_dynamic, use_dynamic = _options$use_dynamic === void 0 ? false : _options$use_dynamic, dynamic_env = options.dynamic_env, env = options.env; + typecheck('Interpreter::exec', arg, ['string', 'array'], 1); + typecheck('Interpreter::exec', use_dynamic, 'boolean', 2); + // simple solution to overwrite this variable in each interpreter + // before evaluation of user code + if (!env) { + env = _this20.__env__; + } + if (!dynamic_env) { + dynamic_env = env; + } + global_env.set('**interaction-environment**', _this20.__env__); + if (!Array.isArray(arg)) { + _context16.next = 10; + break; + } + return _context16.abrupt("return", exec(arg, { + env: env, + dynamic_env: dynamic_env, + use_dynamic: use_dynamic + })); + case 10: + _this20.__parser__.parse(arg); + return _context16.abrupt("return", exec(_this20.__parser__, { + env: env, + dynamic_env: dynamic_env, + use_dynamic: use_dynamic + })); + case 12: + case "end": + return _context16.stop(); + } + }, _callee16); + })(); }); -}; + return function (_x13) { + return _ref28.apply(this, arguments); + }; +}(); // ------------------------------------------------------------------------- Interpreter.prototype.get = function (value) { var result = this.__env__.get(value); @@ -11965,12 +12004,12 @@ Environment.prototype.toString = function () { }; // ------------------------------------------------------------------------- Environment.prototype.clone = function () { - var _this20 = this; + var _this21 = this; // duplicate refs var env = {}; // TODO: duplicated Symbols Object.keys(this.__env__).forEach(function (key) { - env[key] = _this20.__env__[key]; + env[key] = _this21.__env__[key]; }); return new Environment(env, this.__parent__, this.__name__); }; @@ -12104,14 +12143,14 @@ Environment.prototype.set = function (name, value) { // For internal use only // ------------------------------------------------------------------------- Environment.prototype.constant = function (name, value) { - var _this21 = this; + var _this22 = this; if (this.__env__.hasOwnProperty(name)) { throw new Error("Environment::constant: ".concat(name, " already exists")); } if (arguments.length === 1 && is_plain_object(arguments[0])) { var obj = arguments[0]; Object.keys(obj).forEach(function (key) { - _this21.constant(name, obj[key]); + _this22.constant(name, obj[key]); }); } else { Object.defineProperty(this.__env__, name, { @@ -12283,26 +12322,26 @@ var global_env = new Environment({ // ------------------------------------------------------------------ read: doc('read', /*#__PURE__*/function () { var _read2 = _asyncToGenerator(function () { - var _this22 = this; + var _this23 = this; var arg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - return /*#__PURE__*/_regeneratorRuntime.mark(function _callee16() { + return /*#__PURE__*/_regeneratorRuntime.mark(function _callee17() { var env, port; - return _regeneratorRuntime.wrap(function _callee16$(_context16) { - while (1) switch (_context16.prev = _context16.next) { + return _regeneratorRuntime.wrap(function _callee17$(_context17) { + while (1) switch (_context17.prev = _context17.next) { case 0: - env = _this22.env; + env = _this23.env; if (arg === null) { port = internal(env, 'stdin'); } else { port = arg; } typecheck_text_port('read', port, 'input-port'); - return _context16.abrupt("return", port.read.call(env)); + return _context17.abrupt("return", port.read.call(env)); case 4: case "end": - return _context16.stop(); + return _context17.stop(); } - }, _callee16); + }, _callee17); })(); }); function read() { @@ -12415,10 +12454,10 @@ var global_env = new Environment({ return unbind(a) === unbind(b); }, "(%same-functions a b)\n\n A helper function that checks if the two input functions are\n the same."), // ------------------------------------------------------------------ - help: doc(new Macro('help', function (code, _ref28) { - var dynamic_env = _ref28.dynamic_env, - use_dynamic = _ref28.use_dynamic, - error = _ref28.error; + help: doc(new Macro('help', function (code, _ref29) { + var dynamic_env = _ref29.dynamic_env, + use_dynamic = _ref29.use_dynamic, + error = _ref29.error; var symbol; if (code.car instanceof LSymbol) { symbol = code.car; @@ -12468,10 +12507,10 @@ var global_env = new Environment({ }, "(cdr pair)\n\n This function returns the cdr (all but first) of the list."), // ------------------------------------------------------------------ 'set!': doc(new Macro('set!', function (code) { - var _this23 = this; - var _ref29 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - use_dynamic = _ref29.use_dynamic, - rest = _objectWithoutProperties(_ref29, _excluded4); + var _this24 = this; + var _ref30 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + use_dynamic = _ref30.use_dynamic, + rest = _objectWithoutProperties(_ref30, _excluded4); var dynamic_env = this; var env = this; var ref; @@ -12522,7 +12561,7 @@ var global_env = new Environment({ if (parts.length > 1) { var key = parts.pop(); var name = parts.join('.'); - var obj = _this23.get(name, { + var obj = _this24.get(name, { throwError: false }); if (obj) { @@ -12621,36 +12660,36 @@ var global_env = new Environment({ } if (is_node()) { return new Promise( /*#__PURE__*/function () { - var _ref30 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(resolve, reject) { - var path, cmd, _args19; - return _regeneratorRuntime.wrap(function _callee17$(_context17) { - while (1) switch (_context17.prev = _context17.next) { + var _ref31 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(resolve, reject) { + var path, cmd, _args20; + return _regeneratorRuntime.wrap(function _callee18$(_context18) { + while (1) switch (_context18.prev = _context18.next) { case 0: path = nodeRequire('path'); if (!module_path) { - _context17.next = 6; + _context18.next = 6; break; } module_path = module_path.valueOf(); file = path.join(module_path, file); - _context17.next = 12; + _context18.next = 12; break; case 6: cmd = g_env.get('command-line', { throwError: false }); if (!cmd) { - _context17.next = 11; + _context18.next = 11; break; } - _context17.next = 10; + _context18.next = 10; return cmd(); case 10: - _args19 = _context17.sent; + _args20 = _context18.sent; case 11: - if (_args19 && !is_nil(_args19)) { + if (_args20 && !is_nil(_args20)) { process.cwd(); - file = path.join(path.dirname(_args19.car.valueOf()), file); + file = path.join(path.dirname(_args20.car.valueOf()), file); } case 12: global_env.set(PATH, path.dirname(file)); @@ -12671,12 +12710,12 @@ var global_env = new Environment({ }); case 14: case "end": - return _context17.stop(); + return _context18.stop(); } - }, _callee17); + }, _callee18); })); - return function (_x13, _x14) { - return _ref30.apply(this, arguments); + return function (_x14, _x15) { + return _ref31.apply(this, arguments); }; }()); } @@ -12708,16 +12747,16 @@ var global_env = new Environment({ }), "(while cond body)\n\n Creates a loop, it executes cond and body until cond expression is false."), // ------------------------------------------------------------------ 'do': doc(new Macro('do', /*#__PURE__*/function () { - var _ref31 = _asyncToGenerator(function (code, _ref32) { - var _this24 = this; - var use_dynamic = _ref32.use_dynamic, - error = _ref32.error; - return /*#__PURE__*/_regeneratorRuntime.mark(function _callee18() { + var _ref32 = _asyncToGenerator(function (code, _ref33) { + var _this25 = this; + var use_dynamic = _ref33.use_dynamic, + error = _ref33.error; + return /*#__PURE__*/_regeneratorRuntime.mark(function _callee19() { var self, dynamic_env, scope, vars, test, body, eval_args, node, item, _loop3; - return _regeneratorRuntime.wrap(function _callee18$(_context19) { - while (1) switch (_context19.prev = _context19.next) { + return _regeneratorRuntime.wrap(function _callee19$(_context20) { + while (1) switch (_context20.prev = _context20.next) { case 0: - self = _this24; + self = _this25; dynamic_env = self; scope = self.inherit('do'); vars = code.car; @@ -12735,19 +12774,19 @@ var global_env = new Environment({ node = vars; // init variables case 9: if (is_nil(node)) { - _context19.next = 20; + _context20.next = 20; break; } item = node.car; - _context19.t0 = scope; - _context19.t1 = item.car; - _context19.next = 15; + _context20.t0 = scope; + _context20.t1 = item.car; + _context20.next = 15; return _evaluate(item.cdr.car, eval_args); case 15: - _context19.t2 = _context19.sent; - _context19.t0.set.call(_context19.t0, _context19.t1, _context19.t2); + _context20.t2 = _context20.sent; + _context20.t0.set.call(_context20.t0, _context20.t1, _context20.t2); node = node.cdr; - _context19.next = 9; + _context20.next = 9; break; case 20: eval_args = { @@ -12757,36 +12796,36 @@ var global_env = new Environment({ }; _loop3 = /*#__PURE__*/_regeneratorRuntime.mark(function _loop3() { var node, next, _item, value, symbols; - return _regeneratorRuntime.wrap(function _loop3$(_context18) { - while (1) switch (_context18.prev = _context18.next) { + return _regeneratorRuntime.wrap(function _loop3$(_context19) { + while (1) switch (_context19.prev = _context19.next) { case 0: if (is_nil(body)) { - _context18.next = 3; + _context19.next = 3; break; } - _context18.next = 3; + _context19.next = 3; return lips.evaluate(body, eval_args); case 3: node = vars; next = {}; // next value of variables case 5: if (is_nil(node)) { - _context18.next = 15; + _context19.next = 15; break; } _item = node.car; if (is_nil(_item.cdr.cdr)) { - _context18.next = 12; + _context19.next = 12; break; } - _context18.next = 10; + _context19.next = 10; return _evaluate(_item.cdr.cdr.car, eval_args); case 10: - value = _context18.sent; + value = _context19.sent; next[_item.car.valueOf()] = value; case 12: node = node.cdr; - _context18.next = 5; + _context19.next = 5; break; case 15: symbols = Object.getOwnPropertySymbols(next); // new scope for new iteration @@ -12796,47 +12835,47 @@ var global_env = new Environment({ }); case 18: case "end": - return _context18.stop(); + return _context19.stop(); } }, _loop3); }); case 22: - _context19.next = 24; + _context20.next = 24; return _evaluate(test.car, eval_args); case 24: - _context19.t3 = _context19.sent; - if (!(_context19.t3 === false)) { - _context19.next = 29; + _context20.t3 = _context20.sent; + if (!(_context20.t3 === false)) { + _context20.next = 29; break; } - return _context19.delegateYield(_loop3(), "t4", 27); + return _context20.delegateYield(_loop3(), "t4", 27); case 27: - _context19.next = 22; + _context20.next = 22; break; case 29: if (is_nil(test.cdr)) { - _context19.next = 33; + _context20.next = 33; break; } - _context19.next = 32; + _context20.next = 32; return _evaluate(test.cdr.car, eval_args); case 32: - return _context19.abrupt("return", _context19.sent); + return _context20.abrupt("return", _context20.sent); case 33: case "end": - return _context19.stop(); + return _context20.stop(); } - }, _callee18); + }, _callee19); })(); }); - return function (_x15, _x16) { - return _ref31.apply(this, arguments); + return function (_x16, _x17) { + return _ref32.apply(this, arguments); }; }()), "(do (( )) (test return) . body)\n\n Iteration macro that evaluates the expression body in scope of the variables.\n On each loop it changes the variables according to the expression and runs\n test to check if the loop should continue. If test is a single value, the macro\n will return undefined. If the test is a pair of expressions the macro will\n evaluate and return the second expression after the loop exits."), // ------------------------------------------------------------------ - 'if': doc(new Macro('if', function (code, _ref33) { - var error = _ref33.error, - use_dynamic = _ref33.use_dynamic; + 'if': doc(new Macro('if', function (code, _ref34) { + var error = _ref34.error, + use_dynamic = _ref34.use_dynamic; var dynamic_env = this; var env = this; var eval_args = { @@ -13154,28 +13193,28 @@ var global_env = new Environment({ }, "(parent.frame)\n\n Returns the parent environment if called from inside a function.\n If no parent frame can be found it returns nil."), // ------------------------------------------------------------------ 'eval': doc('eval', function (code, env) { - var _this25 = this; + var _this26 = this; env = env || this.get('interaction-environment').call(this); return _evaluate(code, { env: env, dynamic_env: env, error: function error(e) { var error = global_env.get('display-error'); - error.call(_this25, e.message); + error.call(_this26, e.message); if (e.code) { var stack = e.code.map(function (line, i) { return "[".concat(i + 1, "]: ").concat(line); }).join('\n'); - error.call(_this25, stack); + error.call(_this26, stack); } } }); }, "(eval expr)\n (eval expr environment)\n\n Function that evaluates LIPS Scheme code. If the second argument is provided\n it will be the environment that the code is evaluated in."), // ------------------------------------------------------------------ lambda: new Macro('lambda', function (code) { - var _ref34 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - use_dynamic = _ref34.use_dynamic, - error = _ref34.error; + var _ref35 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + use_dynamic = _ref35.use_dynamic, + error = _ref35.error; var self = this; var __doc__; if (is_pair(code.cdr) && LString.isString(code.cdr.car) && !is_nil(code.cdr.cdr)) { @@ -13183,10 +13222,10 @@ var global_env = new Environment({ } function lambda() { // lambda got scopes as context in apply - var _ref35 = is_context(this) ? this : { + var _ref36 = is_context(this) ? this : { dynamic_env: self }, - dynamic_env = _ref35.dynamic_env; + dynamic_env = _ref36.dynamic_env; var env = self.inherit('lambda'); dynamic_env = dynamic_env.inherit('lambda'); if (this && !is_context(this)) { @@ -13269,9 +13308,9 @@ var global_env = new Environment({ // ------------------------------------------------------------------ 'macroexpand-1': doc(new Macro('macroexpand-1', macro_expand(true)), "(macroexpand-1 expr)\n\n Macro similar to macroexpand but it expand macros only one level\n and return single expression as output."), // ------------------------------------------------------------------ - 'define-macro': doc(new Macro(macro, function (macro, _ref36) { - var use_dynamic = _ref36.use_dynamic, - error = _ref36.error; + 'define-macro': doc(new Macro(macro, function (macro, _ref37) { + var use_dynamic = _ref37.use_dynamic, + error = _ref37.error; if (is_pair(macro.car) && macro.car.car instanceof LSymbol) { var name = macro.car.car.__name__; var __doc__; @@ -13361,8 +13400,8 @@ var global_env = new Environment({ } else { validate_identifiers(macro.car); } - var syntax = new Syntax(function (code, _ref37) { - var macro_expand = _ref37.macro_expand; + var syntax = new Syntax(function (code, _ref38) { + var macro_expand = _ref38.macro_expand; log('>> SYNTAX'); log(code); log(macro); @@ -13488,10 +13527,10 @@ var global_env = new Environment({ cdr = fn(cdr); } if (is_promise(car) || is_promise(cdr)) { - return promise_all([car, cdr]).then(function (_ref38) { - var _ref39 = _slicedToArray(_ref38, 2), - car = _ref39[0], - cdr = _ref39[1]; + return promise_all([car, cdr]).then(function (_ref39) { + var _ref40 = _slicedToArray(_ref39, 2), + car = _ref40[0], + cdr = _ref40[1]; return new Pair(car, cdr); }); } else { @@ -14111,10 +14150,10 @@ var global_env = new Environment({ return false; }, "(string->number number [radix])\n\n Function that parses a string into a number."), // ------------------------------------------------------------------ - 'try': doc(new Macro('try', function (code, _ref40) { - var _this26 = this; - var use_dynamic = _ref40.use_dynamic; - _ref40.error; + 'try': doc(new Macro('try', function (code, _ref41) { + var _this27 = this; + var use_dynamic = _ref41.use_dynamic; + _ref41.error; return new Promise(function (resolve, reject) { var catch_clause, finally_clause; if (LSymbol.is(code.cdr.car.car, 'catch')) { @@ -14148,15 +14187,15 @@ var global_env = new Environment({ }; } var args = { - env: _this26, + env: _this27, use_dynamic: use_dynamic, - dynamic_env: _this26, + dynamic_env: _this27, error: function error(e) { if (e instanceof IgnoreException) { throw e; } if (catch_clause) { - var env = _this26.inherit('try'); + var env = _this27.inherit('try'); var name = catch_clause.cdr.car.car; if (!(name instanceof LSymbol)) { throw new Error('try: invalid syntax: catch require variable name'); @@ -14166,7 +14205,7 @@ var global_env = new Environment({ var catch_args = { env: env, use_dynamic: use_dynamic, - dynamic_env: _this26, + dynamic_env: _this27, error: function error(e) { catch_error = true; reject(e); @@ -14234,7 +14273,7 @@ var global_env = new Environment({ }, "(for-each fn . lists)\n\n Higher-order function that calls function `fn` on each\n value of the argument. If you provide more than one list\n it will take each value from each list and call `fn` function\n with that many arguments as number of list arguments."), // ------------------------------------------------------------------ map: doc('map', function map(fn) { - var _this27 = this; + var _this28 = this; for (var _len32 = arguments.length, lists = new Array(_len32 > 1 ? _len32 - 1 : 0), _key32 = 1; _key32 < _len32; _key32++) { lists[_key32 - 1] = arguments[_key32]; } @@ -14243,7 +14282,7 @@ var global_env = new Environment({ lists.forEach(function (arg, i) { typecheck('map', arg, ['pair', 'nil'], i + 1); // detect cycles - if (is_pair(arg) && !is_list.call(_this27, arg)) { + if (is_pair(arg) && !is_list.call(_this28, arg)) { throw new Error("map: argument ".concat(i + 1, " is not a list")); } }); @@ -14265,7 +14304,7 @@ var global_env = new Environment({ use_dynamic: use_dynamic }); return unpromise(result, function (head) { - return unpromise(map.call.apply(map, [_this27, fn].concat(_toConsumableArray(lists.map(function (l) { + return unpromise(map.call.apply(map, [_this28, fn].concat(_toConsumableArray(lists.map(function (l) { return l.cdr; })))), function (rest) { return new Pair(head, rest); @@ -14347,7 +14386,7 @@ var global_env = new Environment({ }, "(pluck . strings)\n\n If called with a single string it will return a function that when\n called with an object will return that key from the object.\n If called with more then one string the returned function will\n create a new object by copying all properties from the given object."), // ------------------------------------------------------------------ reduce: doc('reduce', fold('reduce', function (reduce, fn, init) { - var _this28 = this; + var _this29 = this; for (var _len35 = arguments.length, lists = new Array(_len35 > 3 ? _len35 - 3 : 0), _key36 = 3; _key36 < _len35; _key36++) { lists[_key36 - 3] = arguments[_key36]; } @@ -14361,7 +14400,7 @@ var global_env = new Environment({ return unpromise(fn.apply(void 0, _toConsumableArray(lists.map(function (l) { return l.car; })).concat([init])), function (value) { - return reduce.call.apply(reduce, [_this28, fn, value].concat(_toConsumableArray(lists.map(function (l) { + return reduce.call.apply(reduce, [_this29, fn, value].concat(_toConsumableArray(lists.map(function (l) { return l.cdr; })))); }); @@ -14575,9 +14614,9 @@ var global_env = new Environment({ // ------------------------------------------------------------------ 'eq?': doc('eq?', equal, "(eq? a b)\n\n Function that compares two values if they are identical."), // ------------------------------------------------------------------ - or: doc(new Macro('or', function (code, _ref41) { - var use_dynamic = _ref41.use_dynamic, - error = _ref41.error; + or: doc(new Macro('or', function (code, _ref42) { + var use_dynamic = _ref42.use_dynamic, + error = _ref42.error; var args = global_env.get('list->array')(code); var self = this; var dynamic_env = self; @@ -14614,9 +14653,9 @@ var global_env = new Environment({ }), "(or . expressions)\n\n Macro that executes the values one by one and returns the first that is\n a truthy value. If there are no expressions that evaluate to true it\n returns false."), // ------------------------------------------------------------------ and: doc(new Macro('and', function (code) { - var _ref42 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - use_dynamic = _ref42.use_dynamic, - error = _ref42.error; + var _ref43 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + use_dynamic = _ref43.use_dynamic, + error = _ref43.error; var args = global_env.get('list->array')(code); var self = this; var dynamic_env = self; @@ -14785,25 +14824,25 @@ function node_specific() { } // ------------------------------------------------------------------------- /* c8 ignore next 11 */ function _node_specific() { - _node_specific = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22() { + _node_specific = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee23() { var _yield$import, createRequire, moduleURL, __dirname, __filename; - return _regeneratorRuntime.wrap(function _callee22$(_context23) { - while (1) switch (_context23.prev = _context23.next) { + return _regeneratorRuntime.wrap(function _callee23$(_context24) { + while (1) switch (_context24.prev = _context24.next) { case 0: - _context23.next = 2; + _context24.next = 2; return import('mod' + 'ule'); case 2: - _yield$import = _context23.sent; + _yield$import = _context24.sent; createRequire = _yield$import.createRequire; nodeRequire = createRequire(import.meta.url); - _context23.next = 7; + _context24.next = 7; return import('fs'); case 7: - fs = _context23.sent; - _context23.next = 10; + fs = _context24.sent; + _context24.next = 10; return import('path'); case 10: - path = _context23.sent; + path = _context24.sent; global_env.set('global', global); global_env.set('self', global); global_env.set('window', undefined); @@ -14851,9 +14890,9 @@ function _node_specific() { }); case 22: case "end": - return _context23.stop(); + return _context24.stop(); } - }, _callee22); + }, _callee23); })); return _node_specific.apply(this, arguments); } @@ -15057,54 +15096,54 @@ function resolve_promises(arg) { node.forEach(traverse); } } - function promise(_x17) { + function promise(_x18) { return _promise.apply(this, arguments); } function _promise() { - _promise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(node) { + _promise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20(node) { var pair; - return _regeneratorRuntime.wrap(function _callee19$(_context20) { - while (1) switch (_context20.prev = _context20.next) { + return _regeneratorRuntime.wrap(function _callee20$(_context21) { + while (1) switch (_context21.prev = _context21.next) { case 0: - _context20.t0 = Pair; + _context21.t0 = Pair; if (!node.have_cycles('car')) { - _context20.next = 5; + _context21.next = 5; break; } - _context20.t1 = node.car; - _context20.next = 8; + _context21.t1 = node.car; + _context21.next = 8; break; case 5: - _context20.next = 7; + _context21.next = 7; return resolve(node.car); case 7: - _context20.t1 = _context20.sent; + _context21.t1 = _context21.sent; case 8: - _context20.t2 = _context20.t1; + _context21.t2 = _context21.t1; if (!node.have_cycles('cdr')) { - _context20.next = 13; + _context21.next = 13; break; } - _context20.t3 = node.cdr; - _context20.next = 16; + _context21.t3 = node.cdr; + _context21.next = 16; break; case 13: - _context20.next = 15; + _context21.next = 15; return resolve(node.cdr); case 15: - _context20.t3 = _context20.sent; + _context21.t3 = _context21.sent; case 16: - _context20.t4 = _context20.t3; - pair = new _context20.t0(_context20.t2, _context20.t4); + _context21.t4 = _context21.t3; + pair = new _context21.t0(_context21.t2, _context21.t4); if (node[__data__]) { pair[__data__] = true; } - return _context20.abrupt("return", pair); + return _context21.abrupt("return", pair); case 20: case "end": - return _context20.stop(); + return _context21.stop(); } - }, _callee19); + }, _callee20); })); return _promise.apply(this, arguments); } @@ -15119,9 +15158,9 @@ function resolve_promises(arg) { } } // ------------------------------------------------------------------------- -function evaluate_args(rest, _ref43) { - var use_dynamic = _ref43.use_dynamic, - options = _objectWithoutProperties(_ref43, _excluded5); +function evaluate_args(rest, _ref44) { + var use_dynamic = _ref44.use_dynamic, + options = _objectWithoutProperties(_ref44, _excluded5); var args = []; var node = rest; function next() { @@ -15229,10 +15268,10 @@ function prepare_fn_args(fn, args) { // ------------------------------------------------------------------------- function call_function(fn, args) { - var _ref44 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, - env = _ref44.env, - dynamic_env = _ref44.dynamic_env, - use_dynamic = _ref44.use_dynamic; + var _ref45 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + env = _ref45.env, + dynamic_env = _ref45.dynamic_env, + use_dynamic = _ref45.use_dynamic; var scope = env === null || env === void 0 ? void 0 : env.new_frame(fn, args); var dynamic_scope = dynamic_env === null || dynamic_env === void 0 ? void 0 : dynamic_env.new_frame(fn, args); var context = new LambdaContext({ @@ -15245,12 +15284,12 @@ function call_function(fn, args) { // ------------------------------------------------------------------------- function apply(fn, args) { - var _ref45 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, - env = _ref45.env, - dynamic_env = _ref45.dynamic_env, - use_dynamic = _ref45.use_dynamic, - _ref45$error = _ref45.error, - error = _ref45$error === void 0 ? function () {} : _ref45$error; + var _ref46 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + env = _ref46.env, + dynamic_env = _ref46.dynamic_env, + use_dynamic = _ref46.use_dynamic, + _ref46$error = _ref46.error, + error = _ref46$error === void 0 ? function () {} : _ref46$error; args = evaluate_args(args, { env: env, dynamic_env: dynamic_env, @@ -15405,13 +15444,13 @@ var Continuation = /*#__PURE__*/function () { return Continuation; }(); // ------------------------------------------------------------------------- function _evaluate(code) { - var _ref46 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - env = _ref46.env, - dynamic_env = _ref46.dynamic_env, - use_dynamic = _ref46.use_dynamic, - _ref46$error = _ref46.error, - error = _ref46$error === void 0 ? noop : _ref46$error, - rest = _objectWithoutProperties(_ref46, _excluded6); + var _ref47 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + env = _ref47.env, + dynamic_env = _ref47.dynamic_env, + use_dynamic = _ref47.use_dynamic, + _ref47$error = _ref47.error, + error = _ref47$error === void 0 ? noop : _ref47$error, + rest = _objectWithoutProperties(_ref47, _excluded6); return function (rest) { try { if (!is_env(dynamic_env)) { @@ -15519,10 +15558,10 @@ var exec = exec_collect(function (code, value) { }); // ------------------------------------------------------------------------- function exec_with_stacktrace(code) { - var _ref47 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - env = _ref47.env, - dynamic_env = _ref47.dynamic_env, - use_dynamic = _ref47.use_dynamic; + var _ref48 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + env = _ref48.env, + dynamic_env = _ref48.dynamic_env, + use_dynamic = _ref48.use_dynamic; return _evaluate(code, { env: env, dynamic_env: dynamic_env, @@ -15552,14 +15591,14 @@ function exec_with_stacktrace(code) { function exec_collect(collect_callback) { return /*#__PURE__*/function () { var _exec_lambda = _asyncToGenerator(function (arg) { - var _ref48 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - env = _ref48.env, - dynamic_env = _ref48.dynamic_env, - use_dynamic = _ref48.use_dynamic; - return /*#__PURE__*/_regeneratorRuntime.mark(function _callee20() { + var _ref49 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + env = _ref49.env, + dynamic_env = _ref49.dynamic_env, + use_dynamic = _ref49.use_dynamic; + return /*#__PURE__*/_regeneratorRuntime.mark(function _callee21() { var results, input, _iteratorAbruptCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, code, value; - return _regeneratorRuntime.wrap(function _callee20$(_context21) { - while (1) switch (_context21.prev = _context21.next) { + return _regeneratorRuntime.wrap(function _callee21$(_context22) { + while (1) switch (_context22.prev = _context22.next) { case 0: if (!is_env(dynamic_env)) { dynamic_env = env === true ? user_env : env || user_env; @@ -15571,92 +15610,92 @@ function exec_collect(collect_callback) { } results = []; if (!is_pair(arg)) { - _context21.next = 8; + _context22.next = 8; break; } - _context21.next = 6; + _context22.next = 6; return exec_with_stacktrace(arg, { env: env, dynamic_env: dynamic_env, use_dynamic: use_dynamic }); case 6: - _context21.t0 = _context21.sent; - return _context21.abrupt("return", [_context21.t0]); + _context22.t0 = _context22.sent; + return _context22.abrupt("return", [_context22.t0]); case 8: input = Array.isArray(arg) ? arg : _parse(arg); _iteratorAbruptCompletion2 = false; _didIteratorError2 = false; - _context21.prev = 11; + _context22.prev = 11; _iterator2 = _asyncIterator(input); case 13: - _context21.next = 15; + _context22.next = 15; return _iterator2.next(); case 15: - if (!(_iteratorAbruptCompletion2 = !(_step2 = _context21.sent).done)) { - _context21.next = 31; + if (!(_iteratorAbruptCompletion2 = !(_step2 = _context22.sent).done)) { + _context22.next = 31; break; } code = _step2.value; - _context21.next = 19; + _context22.next = 19; return exec_with_stacktrace(code, { env: env, dynamic_env: dynamic_env, use_dynamic: use_dynamic }); case 19: - value = _context21.sent; - _context21.t1 = results; - _context21.t2 = collect_callback; - _context21.t3 = code; - _context21.next = 25; + value = _context22.sent; + _context22.t1 = results; + _context22.t2 = collect_callback; + _context22.t3 = code; + _context22.next = 25; return value; case 25: - _context21.t4 = _context21.sent; - _context21.t5 = (0, _context21.t2)(_context21.t3, _context21.t4); - _context21.t1.push.call(_context21.t1, _context21.t5); + _context22.t4 = _context22.sent; + _context22.t5 = (0, _context22.t2)(_context22.t3, _context22.t4); + _context22.t1.push.call(_context22.t1, _context22.t5); case 28: _iteratorAbruptCompletion2 = false; - _context21.next = 13; + _context22.next = 13; break; case 31: - _context21.next = 37; + _context22.next = 37; break; case 33: - _context21.prev = 33; - _context21.t6 = _context21["catch"](11); + _context22.prev = 33; + _context22.t6 = _context22["catch"](11); _didIteratorError2 = true; - _iteratorError2 = _context21.t6; + _iteratorError2 = _context22.t6; case 37: - _context21.prev = 37; - _context21.prev = 38; + _context22.prev = 37; + _context22.prev = 38; if (!(_iteratorAbruptCompletion2 && _iterator2["return"] != null)) { - _context21.next = 42; + _context22.next = 42; break; } - _context21.next = 42; + _context22.next = 42; return _iterator2["return"](); case 42: - _context21.prev = 42; + _context22.prev = 42; if (!_didIteratorError2) { - _context21.next = 45; + _context22.next = 45; break; } throw _iteratorError2; case 45: - return _context21.finish(42); + return _context22.finish(42); case 46: - return _context21.finish(37); + return _context22.finish(37); case 47: - return _context21.abrupt("return", results); + return _context22.abrupt("return", results); case 48: case "end": - return _context21.stop(); + return _context22.stop(); } - }, _callee20, null, [[11, 33, 37, 47], [38,, 42, 46]]); + }, _callee21, null, [[11, 33, 37, 47], [38,, 42, 46]]); })(); }); - function exec_lambda(_x18) { + function exec_lambda(_x19) { return _exec_lambda.apply(this, arguments); } return exec_lambda; @@ -15865,9 +15904,9 @@ function Worker(url) { this.rpc('init', [url])["catch"](function (error) { console.error(error); }); - this.exec = function (code, _ref49) { - var _ref49$use_dynamic = _ref49.use_dynamic, - use_dynamic = _ref49$use_dynamic === void 0 ? false : _ref49$use_dynamic; + this.exec = function (code, _ref50) { + var _ref50$use_dynamic = _ref50.use_dynamic, + use_dynamic = _ref50$use_dynamic === void 0 ? false : _ref50$use_dynamic; return this.rpc('eval', [code, use_dynamic]); }; } @@ -15876,10 +15915,10 @@ function Worker(url) { // :: Serialization // ------------------------------------------------------------------------- var serialization_map = { - 'pair': function pair(_ref50) { - var _ref51 = _slicedToArray(_ref50, 2), - car = _ref51[0], - cdr = _ref51[1]; + 'pair': function pair(_ref51) { + var _ref52 = _slicedToArray(_ref51, 2), + car = _ref52[0], + cdr = _ref52[1]; return Pair(car, cdr); }, 'number': function number(value) { @@ -15888,10 +15927,10 @@ var serialization_map = { } return LNumber(value); }, - 'regex': function regex(_ref52) { - var _ref53 = _slicedToArray(_ref52, 2), - pattern = _ref53[0], - flag = _ref53[1]; + 'regex': function regex(_ref53) { + var _ref54 = _slicedToArray(_ref53, 2), + pattern = _ref54[0], + flag = _ref54[1]; return new RegExp(pattern, flag); }, 'nil': function nil() { @@ -16185,10 +16224,10 @@ if (typeof window !== 'undefined') { // ------------------------------------------------------------------------- var banner = function () { // Rollup tree-shaking is removing the variable if it's normal string because - // obviously 'Fri, 22 Mar 2024 13:26:48 +0000' == '{{' + 'DATE}}'; can be removed + // obviously 'Fri, 22 Mar 2024 16:45:56 +0000' == '{{' + 'DATE}}'; can be removed // but disabling Tree-shaking is adding lot of not used code so we use this // hack instead - var date = LString('Fri, 22 Mar 2024 13:26:48 +0000').valueOf(); + var date = LString('Fri, 22 Mar 2024 16:45:56 +0000').valueOf(); var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date); var _format = function _format(x) { return x.toString().padStart(2, '0'); @@ -16228,7 +16267,7 @@ read_only(QuotedPromise, '__class__', 'promise'); read_only(Parameter, '__class__', 'parameter'); // ------------------------------------------------------------------------- var version = 'DEV'; -var date = 'Fri, 22 Mar 2024 13:26:48 +0000'; +var date = 'Fri, 22 Mar 2024 16:45:56 +0000'; // unwrap async generator into Promise var parse = compose(uniterate_async, _parse); diff --git a/dist/lips.esm.min.js b/dist/lips.esm.min.js index 540cf352..74cd16f2 100644 --- a/dist/lips.esm.min.js +++ b/dist/lips.esm.min.js @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Fri, 22 Mar 2024 13:26:48 +0000 + * build: Fri, 22 Mar 2024 16:45:56 +0000 */ function _classApplyDescriptorGet(e,r){if(r.get){return r.get.call(e)}return r.value}function _classExtractFieldDescriptor(e,r,t){if(!r.has(e)){throw new TypeError("attempted to "+t+" private field on non-instance")}return r.get(e)}function _classPrivateFieldGet(e,r){var t=_classExtractFieldDescriptor(e,r,"get");return _classApplyDescriptorGet(e,t)}function _classApplyDescriptorSet(e,r,t){if(r.set){r.set.call(e,t)}else{if(!r.writable){throw new TypeError("attempted to set read only private field")}r.value=t}}function _classPrivateFieldSet(e,r,t){var n=_classExtractFieldDescriptor(e,r,"set");_classApplyDescriptorSet(e,n,t);return t}function _getPrototypeOf(e){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function e(r){return r.__proto__||Object.getPrototypeOf(r)};return _getPrototypeOf(e)}function _setPrototypeOf(e,r){_setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function e(r,t){r.__proto__=t;return r};return _setPrototypeOf(e,r)}function _isNativeFunction(r){try{return Function.toString.call(r).indexOf("[native code]")!==-1}catch(e){return typeof r==="function"}}function _isNativeReflectConstruct$1(){try{var r=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(r){}return(_isNativeReflectConstruct$1=function e(){return!!r})()}function _construct(e,r,t){if(_isNativeReflectConstruct$1())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,r);var i=new(e.bind.apply(e,n));return t&&_setPrototypeOf(i,t.prototype),i}function _wrapNativeSuper(e){var n=typeof Map==="function"?new Map:undefined;_wrapNativeSuper=function e(r){if(r===null||!_isNativeFunction(r))return r;if(typeof r!=="function"){throw new TypeError("Super expression must either be null or a function")}if(typeof n!=="undefined"){if(n.has(r))return n.get(r);n.set(r,t)}function t(){return _construct(r,arguments,_getPrototypeOf(this).constructor)}t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:false,writable:true,configurable:true}});return _setPrototypeOf(t,r)};return _wrapNativeSuper(e)}function _typeof$1(e){"@babel/helpers - typeof";return _typeof$1="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof$1(e)}function _assertThisInitialized(e){if(e===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return e}function _possibleConstructorReturn(e,r){if(r&&(_typeof$1(r)==="object"||typeof r==="function")){return r}else if(r!==void 0){throw new TypeError("Derived constructors may only return object or undefined")}return _assertThisInitialized(e)}function _inherits(e,r){if(typeof r!=="function"&&r!==null){throw new TypeError("Super expression must either be null or a function")}e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:true,configurable:true}});Object.defineProperty(e,"prototype",{writable:false});if(r)_setPrototypeOf(e,r)}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArray(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function _arrayLikeToArray$1(e,r){if(r==null||r>e.length)r=e.length;for(var t=0,n=new Array(r);t=0)continue;t[i]=e[i]}return t}function _objectWithoutProperties(e,r){if(e==null)return{};var t=_objectWithoutPropertiesLoose(e,r);var n,i;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(i=0;i=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,n))continue;t[n]=e[n]}}return t}function _iterableToArrayLimit(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,i,o,a,u=[],s=!0,c=!1;try{if(o=(t=t.call(e)).next,0===r){if(Object(t)!==t)return;s=!1}else for(;!(s=(n=o.call(t)).done)&&(u.push(n.value),u.length!==r);s=!0);}catch(e){c=!0,i=e}finally{try{if(!s&&null!=t["return"]&&(a=t["return"](),Object(a)!==a))return}finally{if(c)throw i}}return u}}function _slicedToArray(e,r){return _arrayWithHoles(e)||_iterableToArrayLimit(e,r)||_unsupportedIterableToArray$1(e,r)||_nonIterableRest()}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray$1(e)}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray$1(e)||_nonIterableSpread()}function _OverloadYield(e,r){this.v=e,this.k=r}function _awaitAsyncGenerator(e){return new _OverloadYield(e,0)}function AsyncGenerator(a){var o,u;function s(t,e){try{var n=a[t](e),i=n.value,o=i instanceof _OverloadYield;Promise.resolve(o?i.v:i).then(function(e){if(o){var r="return"===t?"return":"next";if(!i.k||e.done)return s(r,e);e=a[r](e).value}c(n.done?"return":"normal",e)},function(e){s("throw",e)})}catch(e){c("throw",e)}}function c(e,r){switch(e){case"return":o.resolve({value:r,done:!0});break;case"throw":o.reject(r);break;default:o.resolve({value:r,done:!1})}(o=o.next)?s(o.key,o.arg):u=null}this._invoke=function(n,i){return new Promise(function(e,r){var t={key:n,arg:i,resolve:e,reject:r,next:null};u?u=u.next=t:(o=u=t,s(n,i))})},"function"!=typeof a["return"]&&(this["return"]=void 0)}AsyncGenerator.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},AsyncGenerator.prototype.next=function(e){return this._invoke("next",e)},AsyncGenerator.prototype["throw"]=function(e){return this._invoke("throw",e)},AsyncGenerator.prototype["return"]=function(e){return this._invoke("return",e)};function _wrapAsyncGenerator(e){return function(){return new AsyncGenerator(e.apply(this,arguments))}}function getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e["default"]:e}var regeneratorRuntime$1={exports:{}};var _typeof={exports:{}};(function(r){function t(e){"@babel/helpers - typeof";return r.exports=t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r.exports.__esModule=true,r.exports["default"]=r.exports,t(e)}r.exports=t,r.exports.__esModule=true,r.exports["default"]=r.exports})(_typeof);var _typeofExports=_typeof.exports;(function(O){var N=_typeofExports["default"];function B(){O.exports=B=function e(){return a},O.exports.__esModule=true,O.exports["default"]=O.exports;var c,a={},e=Object.prototype,l=e.hasOwnProperty,f=Object.defineProperty||function(e,r,t){e[r]=t.value},r="function"==typeof Symbol?Symbol:{},i=r.iterator||"@@iterator",t=r.asyncIterator||"@@asyncIterator",n=r.toStringTag||"@@toStringTag";function o(e,r,t){return Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}),e[r]}try{o({},"")}catch(c){o=function e(r,t,n){return r[t]=n}}function u(e,r,t,n){var i=r&&r.prototype instanceof s?r:s,o=Object.create(i.prototype),a=new k(n||[]);return f(o,"_invoke",{value:E(e,t,a)}),o}function _(e,r,t){try{return{type:"normal",arg:e.call(r,t)}}catch(e){return{type:"throw",arg:e}}}a.wrap=u;var p="suspendedStart",d="suspendedYield",y="executing",h="completed",m={};function s(){}function v(){}function g(){}var b={};o(b,i,function(){return this});var P=Object.getPrototypeOf,w=P&&P(P(C([])));w&&w!==e&&l.call(w,i)&&(b=w);var D=g.prototype=s.prototype=Object.create(b);function x(e){["next","throw","return"].forEach(function(r){o(e,r,function(e){return this._invoke(r,e)})})}function L(u,s){function c(e,r,t,n){var i=_(u[e],u,r);if("throw"!==i.type){var o=i.arg,a=o.value;return a&&"object"==N(a)&&l.call(a,"__await")?s.resolve(a.__await).then(function(e){c("next",e,t,n)},function(e){c("throw",e,t,n)}):s.resolve(a).then(function(e){o.value=e,t(o)},function(e){return c("throw",e,t,n)})}n(i.arg)}var i;f(this,"_invoke",{value:function e(t,n){function r(){return new s(function(e,r){c(t,n,e,r)})}return i=i?i.then(r,r):r()}})}function E(o,a,u){var s=p;return function(e,r){if(s===y)throw new Error("Generator is already running");if(s===h){if("throw"===e)throw r;return{value:c,done:!0}}for(u.method=e,u.arg=r;;){var t=u.delegate;if(t){var n=S(t,u);if(n){if(n===m)continue;return n}}if("next"===u.method)u.sent=u._sent=u.arg;else if("throw"===u.method){if(s===p)throw s=h,u.arg;u.dispatchException(u.arg)}else"return"===u.method&&u.abrupt("return",u.arg);s=y;var i=_(o,a,u);if("normal"===i.type){if(s=u.done?h:d,i.arg===m)continue;return{value:i.arg,done:u.done}}"throw"===i.type&&(s=h,u.method="throw",u.arg=i.arg)}}}function S(e,r){var t=r.method,n=e.iterator[t];if(n===c)return r.delegate=null,"throw"===t&&e.iterator["return"]&&(r.method="return",r.arg=c,S(e,r),"throw"===r.method)||"return"!==t&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+t+"' method")),m;var i=_(n,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,m;var o=i.arg;return o?o.done?(r[e.resultName]=o.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=c),r.delegate=null,m):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,m)}function A(e){var r={tryLoc:e[0]};1 in e&&(r.catchLoc=e[1]),2 in e&&(r.finallyLoc=e[2],r.afterLoc=e[3]),this.tryEntries.push(r)}function F(e){var r=e.completion||{};r.type="normal",delete r.arg,e.completion=r}function k(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(A,this),this.reset(!0)}function C(r){if(r||""===r){var e=r[i];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var t=-1,n=function e(){for(;++t=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var u=l.call(o,"catchLoc"),s=l.call(o,"finallyLoc");if(u&&s){if(this.prev=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&l.call(i,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===r)return this.complete(n.completion,n.afterLoc),F(n),m}},catch:function e(r){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===r){var i=n.completion;if("throw"===i.type){var o=i.arg;F(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function e(r,t,n){return this.delegate={iterator:C(r),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=c),m}},a}O.exports=B,O.exports.__esModule=true,O.exports["default"]=O.exports})(regeneratorRuntime$1);var regeneratorRuntimeExports=regeneratorRuntime$1.exports;var runtime=regeneratorRuntimeExports();var regenerator=runtime;try{regeneratorRuntime=runtime}catch(e){if(typeof globalThis==="object"){globalThis.regeneratorRuntime=runtime}else{Function("r","regeneratorRuntime = r")(runtime)}}var _regeneratorRuntime=getDefaultExportFromCjs(regenerator);let decoder;try{decoder=new TextDecoder}catch(e){}let src;let srcEnd;let position$1=0;const LEGACY_RECORD_INLINE_ID=105;const RECORD_DEFINITIONS_ID=57342;const RECORD_INLINE_ID=57343;const BUNDLED_STRINGS_ID=57337;const PACKED_REFERENCE_TAG_ID=6;const STOP_CODE={};let currentDecoder={};let currentStructures;let srcString;let srcStringStart=0;let srcStringEnd=0;let bundledStrings$1;let referenceMap;let currentExtensions=[];let currentExtensionRanges=[];let packedValues;let dataView;let restoreMapsAsObject;let defaultOptions={useRecords:false,mapsAsObjects:true};let sequentialMode=false;let inlineObjectReadThreshold=2;try{new Function("")}catch(e){inlineObjectReadThreshold=Infinity}class Decoder{constructor(t){if(t){if((t.keyMap||t._keyMap)&&!t.useRecords){t.useRecords=false;t.mapsAsObjects=true}if(t.useRecords===false&&t.mapsAsObjects===undefined)t.mapsAsObjects=true;if(t.getStructures)t.getShared=t.getStructures;if(t.getShared&&!t.structures)(t.structures=[]).uninitialized=true;if(t.keyMap){this.mapKey=new Map;for(let[e,r]of Object.entries(t.keyMap))this.mapKey.set(r,e)}}Object.assign(this,t)}decodeKey(e){return this.keyMap?this.mapKey.get(e)||e:e}encodeKey(e){return this.keyMap&&this.keyMap.hasOwnProperty(e)?this.keyMap[e]:e}encodeKeys(t){if(!this._keyMap)return t;let n=new Map;for(let[e,r]of Object.entries(t))n.set(this._keyMap.hasOwnProperty(e)?this._keyMap[e]:e,r);return n}decodeKeys(e){if(!this._keyMap||e.constructor.name!="Map")return e;if(!this._mapKey){this._mapKey=new Map;for(let[e,r]of Object.entries(this._keyMap))this._mapKey.set(r,e)}let t={};e.forEach((e,r)=>t[safeKey(this._mapKey.has(r)?this._mapKey.get(r):r)]=e);return t}mapDecode(e,r){let t=this.decode(e);if(this._keyMap){switch(t.constructor.name){case"Array":return t.map(e=>this.decodeKeys(e))}}return t}decode(r,e){if(src){return saveState(()=>{clearSource();return this?this.decode(r,e):Decoder.prototype.decode.call(defaultOptions,r,e)})}srcEnd=e>-1?e:r.length;position$1=0;srcStringEnd=0;srcString=null;bundledStrings$1=null;src=r;try{dataView=r.dataView||(r.dataView=new DataView(r.buffer,r.byteOffset,r.byteLength))}catch(e){src=null;if(r instanceof Uint8Array)throw e;throw new Error("Source must be a Uint8Array or Buffer but was a "+(r&&typeof r=="object"?r.constructor.name:typeof r))}if(this instanceof Decoder){currentDecoder=this;packedValues=this.sharedValues&&(this.pack?new Array(this.maxPrivatePackedValues||16).concat(this.sharedValues):this.sharedValues);if(this.structures){currentStructures=this.structures;return checkedRead()}else if(!currentStructures||currentStructures.length>0){currentStructures=[]}}else{currentDecoder=defaultOptions;if(!currentStructures||currentStructures.length>0)currentStructures=[];packedValues=null}return checkedRead()}decodeMultiple(t,n){let i,o=0;try{let e=t.length;sequentialMode=true;let r=this?this.decode(t,e):defaultDecoder.decode(t,e);if(n){if(n(r)===false){return}while(position$1=bundledStrings$1.postBundlePosition){let e=new Error("Unexpected bundle position");e.incomplete=true;throw e}position$1=bundledStrings$1.postBundlePosition;bundledStrings$1=null}if(position$1==srcEnd){currentStructures=null;src=null;if(referenceMap)referenceMap=null}else if(position$1>srcEnd){let e=new Error("Unexpected end of CBOR data");e.incomplete=true;throw e}else if(!sequentialMode){throw new Error("Data read, but end of buffer not reached")}return e}catch(e){clearSource();if(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer")){e.incomplete=true}throw e}}function read(){let n=src[position$1++];let i=n>>5;n=n&31;if(n>23){switch(n){case 24:n=src[position$1++];break;case 25:if(i==7){return getFloat16()}n=dataView.getUint16(position$1);position$1+=2;break;case 26:if(i==7){let r=dataView.getFloat32(position$1);if(currentDecoder.useFloat32>2){let e=mult10[(src[position$1]&127)<<1|src[position$1+1]>>7];position$1+=4;return(e*r+(r>0?.5:-.5)>>0)/e}position$1+=4;return r}n=dataView.getUint32(position$1);position$1+=4;break;case 27:if(i==7){let e=dataView.getFloat64(position$1);position$1+=8;return e}if(i>1){if(dataView.getUint32(position$1)>0)throw new Error("JavaScript does not support arrays, maps, or strings with length over 4294967295");n=dataView.getUint32(position$1+4)}else if(currentDecoder.int64AsNumber){n=dataView.getUint32(position$1)*4294967296;n+=dataView.getUint32(position$1+4)}else n=dataView.getBigUint64(position$1);position$1+=8;break;case 31:switch(i){case 2:case 3:throw new Error("Indefinite length not supported for byte or text strings");case 4:let e=[];let r,t=0;while((r=read())!=STOP_CODE){e[t++]=r}return i==4?e:i==3?e.join(""):Buffer.concat(e);case 5:let n;if(currentDecoder.mapsAsObjects){let e={};if(currentDecoder.keyMap)while((n=read())!=STOP_CODE)e[safeKey(currentDecoder.decodeKey(n))]=read();else while((n=read())!=STOP_CODE)e[safeKey(n)]=read();return e}else{if(restoreMapsAsObject){currentDecoder.mapsAsObjects=true;restoreMapsAsObject=false}let e=new Map;if(currentDecoder.keyMap)while((n=read())!=STOP_CODE)e.set(currentDecoder.decodeKey(n),read());else while((n=read())!=STOP_CODE)e.set(n,read());return e}case 7:return STOP_CODE;default:throw new Error("Invalid major type for indefinite length "+i)}default:throw new Error("Unknown token "+n)}}switch(i){case 0:return n;case 1:return~n;case 2:return readBin(n);case 3:if(srcStringEnd>=position$1){return srcString.slice(position$1-srcStringStart,(position$1+=n)-srcStringStart)}if(srcStringEnd==0&&srcEnd<140&&n<32){let e=n<16?shortStringInJS(n):longStringInJS(n);if(e!=null)return e}return readFixedString(n);case 4:let r=new Array(n);for(let e=0;e=BUNDLED_STRINGS_ID){let e=currentStructures[n&8191];if(e){if(!e.read)e.read=createStructureReader(e);return e.read()}if(n<65536){if(n==RECORD_INLINE_ID){let e=readJustLength();let r=read();let t=read();recordDefinition(r,t);let n={};if(currentDecoder.keyMap)for(let r=2;r23){switch(r){case 24:r=src[position$1++];break;case 25:r=dataView.getUint16(position$1);position$1+=2;break;case 26:r=dataView.getUint32(position$1);position$1+=4;break;default:throw new Error("Expected array header, but got "+src[position$1-1])}}let t=this.compiledReader;while(t){if(t.propertyCount===r)return t(read);t=t.next}if(this.slowReads++>=inlineObjectReadThreshold){let e=this.length==r?this:this.slice(0,r);t=currentDecoder.keyMap?new Function("r","return {"+e.map(e=>currentDecoder.decodeKey(e)).map(e=>validName.test(e)?safeKey(e)+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"}"):new Function("r","return {"+e.map(e=>validName.test(e)?safeKey(e)+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"}");if(this.compiledReader)t.next=this.compiledReader;t.propertyCount=r;this.compiledReader=t;return t(read)}let n={};if(currentDecoder.keyMap)for(let e=0;e64&&decoder)return decoder.decode(src.subarray(position$1,position$1+=e));const t=position$1+e;const n=[];r="";while(position$165535){e-=65536;n.push(e>>>10&1023|55296);e=56320|e&1023}n.push(e)}else{n.push(i)}if(n.length>=4096){r+=fromCharCode.apply(String,n);n.length=0}}if(n.length>0){r+=fromCharCode.apply(String,n)}return r}let fromCharCode=String.fromCharCode;function longStringInJS(r){let t=position$1;let n=new Array(r);for(let e=0;e0){position$1=t;return}n[e]=i}return fromCharCode.apply(String,n)}function shortStringInJS(y){if(y<4){if(y<2){if(y===0)return"";else{let e=src[position$1++];if((e&128)>1){position$1-=1;return}return fromCharCode(e)}}else{let e=src[position$1++];let r=src[position$1++];if((e&128)>0||(r&128)>0){position$1-=2;return}if(y<3)return fromCharCode(e,r);let t=src[position$1++];if((t&128)>0){position$1-=3;return}return fromCharCode(e,r,t)}}else{let f=src[position$1++];let _=src[position$1++];let p=src[position$1++];let d=src[position$1++];if((f&128)>0||(_&128)>0||(p&128)>0||(d&128)>0){position$1-=4;return}if(y<6){if(y===4)return fromCharCode(f,_,p,d);else{let e=src[position$1++];if((e&128)>0){position$1-=5;return}return fromCharCode(f,_,p,d,e)}}else if(y<8){let e=src[position$1++];let r=src[position$1++];if((e&128)>0||(r&128)>0){position$1-=6;return}if(y<7)return fromCharCode(f,_,p,d,e,r);let t=src[position$1++];if((t&128)>0){position$1-=7;return}return fromCharCode(f,_,p,d,e,r,t)}else{let u=src[position$1++];let s=src[position$1++];let c=src[position$1++];let l=src[position$1++];if((u&128)>0||(s&128)>0||(c&128)>0||(l&128)>0){position$1-=8;return}if(y<10){if(y===8)return fromCharCode(f,_,p,d,u,s,c,l);else{let e=src[position$1++];if((e&128)>0){position$1-=9;return}return fromCharCode(f,_,p,d,u,s,c,l,e)}}else if(y<12){let e=src[position$1++];let r=src[position$1++];if((e&128)>0||(r&128)>0){position$1-=10;return}if(y<11)return fromCharCode(f,_,p,d,u,s,c,l,e,r);let t=src[position$1++];if((t&128)>0){position$1-=11;return}return fromCharCode(f,_,p,d,u,s,c,l,e,r,t)}else{let n=src[position$1++];let i=src[position$1++];let o=src[position$1++];let a=src[position$1++];if((n&128)>0||(i&128)>0||(o&128)>0||(a&128)>0){position$1-=12;return}if(y<14){if(y===12)return fromCharCode(f,_,p,d,u,s,c,l,n,i,o,a);else{let e=src[position$1++];if((e&128)>0){position$1-=13;return}return fromCharCode(f,_,p,d,u,s,c,l,n,i,o,a,e)}}else{let e=src[position$1++];let r=src[position$1++];if((e&128)>0||(r&128)>0){position$1-=14;return}if(y<15)return fromCharCode(f,_,p,d,u,s,c,l,n,i,o,a,e,r);let t=src[position$1++];if((t&128)>0){position$1-=15;return}return fromCharCode(f,_,p,d,u,s,c,l,n,i,o,a,e,r,t)}}}}}function readBin(e){return currentDecoder.copyBuffers?Uint8Array.prototype.slice.call(src,position$1,position$1+=e):src.subarray(position$1,position$1+=e)}let f32Array=new Float32Array(1);let u8Array=new Uint8Array(f32Array.buffer,0,4);function getFloat16(){let r=src[position$1++];let t=src[position$1++];let e=(r&127)>>2;if(e===31){if(t||r&3)return NaN;return r&128?-Infinity:Infinity}if(e===0){let e=((r&3)<<8|t)/(1<<24);return r&128?-e:e}u8Array[3]=r&128|(e>>1)+56;u8Array[2]=(r&7)<<5|t>>3;u8Array[1]=t<<5;u8Array[0]=0;return f32Array[0]}new Array(4096);class Tag{constructor(e,r){this.value=e;this.tag=r}}currentExtensions[0]=e=>{return new Date(e)};currentExtensions[1]=e=>{return new Date(Math.round(e*1e3))};currentExtensions[2]=t=>{let n=BigInt(0);for(let e=0,r=t.byteLength;e{return BigInt(-1)-currentExtensions[2](e)};currentExtensions[4]=e=>{return+(e[1]+"e"+e[0])};currentExtensions[5]=e=>{return e[1]*Math.exp(e[0]*Math.log(2))};const recordDefinition=(e,r)=>{e=e-57344;let t=currentStructures[e];if(t&&t.isShared){(currentStructures.restoreStructures||(currentStructures.restoreStructures=[]))[e]=t}currentStructures[e]=r;r.read=createStructureReader(r)};currentExtensions[LEGACY_RECORD_INLINE_ID]=t=>{let e=t.length;let n=t[1];recordDefinition(t[0],n);let i={};for(let r=2;r{if(bundledStrings$1)return bundledStrings$1[0].slice(bundledStrings$1.position0,bundledStrings$1.position0+=e);return new Tag(e,14)};currentExtensions[15]=e=>{if(bundledStrings$1)return bundledStrings$1[1].slice(bundledStrings$1.position1,bundledStrings$1.position1+=e);return new Tag(e,15)};let glbl={Error:Error,RegExp:RegExp};currentExtensions[27]=e=>{return(glbl[e[0]]||Error)(e[1],e[2])};const packedTable=e=>{if(src[position$1++]!=132){let e=new Error("Packed values structure must be followed by a 4 element array");if(src.length{if(!packedValues){if(currentDecoder.getShared)loadShared();else return new Tag(e,PACKED_REFERENCE_TAG_ID)}if(typeof e=="number")return packedValues[16+(e>=0?2*e:-2*e-1)];let r=new Error("No support for non-integer packed references yet");if(e===undefined)r.incomplete=true;throw r};currentExtensions[28]=e=>{if(!referenceMap){referenceMap=new Map;referenceMap.id=0}let r=referenceMap.id++;let t=src[position$1];let n;if(t>>5==4)n=[];else n={};let i={target:n};referenceMap.set(r,i);let o=e();if(i.used)return Object.assign(n,o);i.target=o;return o};currentExtensions[28].handlesRead=true;currentExtensions[29]=e=>{let r=referenceMap.get(e);r.used=true;return r.target};currentExtensions[258]=e=>new Set(e);(currentExtensions[259]=e=>{if(currentDecoder.mapsAsObjects){currentDecoder.mapsAsObjects=false;restoreMapsAsObject=true}return e()}).handlesRead=true;function combine(e,r){if(typeof e==="string")return e+r;if(e instanceof Array)return e.concat(r);return Object.assign({},e,r)}function getPackedValues(){if(!packedValues){if(currentDecoder.getShared)loadShared();else throw new Error("No packed values available")}return packedValues}const SHARED_DATA_TAG_ID=1399353956;currentExtensionRanges.push((e,r)=>{if(e>=225&&e<=255)return combine(getPackedValues().prefixes[e-224],r);if(e>=28704&&e<=32767)return combine(getPackedValues().prefixes[e-28672],r);if(e>=1879052288&&e<=2147483647)return combine(getPackedValues().prefixes[e-1879048192],r);if(e>=216&&e<=223)return combine(r,getPackedValues().suffixes[e-216]);if(e>=27647&&e<=28671)return combine(r,getPackedValues().suffixes[e-27639]);if(e>=1811940352&&e<=1879048191)return combine(r,getPackedValues().suffixes[e-1811939328]);if(e==SHARED_DATA_TAG_ID){return{packedValues:packedValues,structures:currentStructures.slice(0),version:r}}if(e==55799)return r});const isLittleEndianMachine$1=new Uint8Array(new Uint16Array([1]).buffer)[0]==1;const typedArrays=[Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array=="undefined"?{name:"BigUint64Array"}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array=="undefined"?{name:"BigInt64Array"}:BigInt64Array,Float32Array,Float64Array];const typedArrayTags=[64,68,69,70,71,72,77,78,79,85,86];for(let e=0;e{if(!u)throw new Error("Could not find typed array for code "+s);if(!currentDecoder.copyBuffers){if(r===1||r===2&&!(e.byteOffset&1)||r===4&&!(e.byteOffset&3)||r===8&&!(e.byteOffset&7))return new u(e.buffer,e.byteOffset,e.byteLength)}return new u(Uint8Array.prototype.slice.call(e,0).buffer)}:e=>{if(!u)throw new Error("Could not find typed array for code "+s);let r=new DataView(e.buffer,e.byteOffset,e.byteLength);let t=e.length>>o;let n=new u(t);let i=r[c];for(let e=0;e23){switch(e){case 24:e=src[position$1++];break;case 25:e=dataView.getUint16(position$1);position$1+=2;break;case 26:e=dataView.getUint32(position$1);position$1+=4;break}}return e}function loadShared(){if(currentDecoder.getShared){let e=saveState(()=>{src=null;return currentDecoder.getShared()})||{};let r=e.structures||[];currentDecoder.sharedVersion=e.version;packedValues=currentDecoder.sharedValues=e.packedValues;if(currentStructures===true)currentDecoder.structures=currentStructures=r;else currentStructures.splice.apply(currentStructures,[0,r.length].concat(r))}}function saveState(e){let r=srcEnd;let t=position$1;let n=srcStringStart;let i=srcStringEnd;let o=srcString;let a=referenceMap;let u=bundledStrings$1;let s=new Uint8Array(src.slice(0,srcEnd));let c=currentStructures;let l=currentDecoder;let f=sequentialMode;let _=e();srcEnd=r;position$1=t;srcStringStart=n;srcStringEnd=i;srcString=o;referenceMap=a;bundledStrings$1=u;src=s;sequentialMode=f;currentStructures=c;currentDecoder=l;dataView=new DataView(src.buffer,src.byteOffset,src.byteLength);return _}function clearSource(){src=null;referenceMap=null;currentStructures=null}function addExtension$1(e){currentExtensions[e.tag]=e.decode}const mult10=new Array(147);for(let e=0;e<256;e++){mult10[e]=+("1e"+Math.floor(45.15-e*.30103))}let defaultDecoder=new Decoder({useRecords:false});defaultDecoder.decode;defaultDecoder.decodeMultiple;let textEncoder;try{textEncoder=new TextEncoder}catch(e){}let extensions,extensionClasses;const Buffer$1=typeof globalThis==="object"&&globalThis.Buffer;const hasNodeBuffer=typeof Buffer$1!=="undefined";const ByteArrayAllocate=hasNodeBuffer?Buffer$1.allocUnsafeSlow:Uint8Array;const ByteArray=hasNodeBuffer?Buffer$1:Uint8Array;const MAX_STRUCTURES=256;const MAX_BUFFER_SIZE=hasNodeBuffer?4294967296:2144337920;let throwOnIterable;let target;let targetView;let position=0;let safeEnd;let bundledStrings=null;const MAX_BUNDLE_SIZE=61440;const hasNonLatin=/[\u0080-\uFFFF]/;const RECORD_SYMBOL=Symbol("record-id");class Encoder extends Decoder{constructor(t){super(t);this.offset=0;let s;let a;let l;let f;let n;t=t||{};let c=ByteArray.prototype.utf8Write?function(e,r,t){return target.utf8Write(e,r,t)}:textEncoder&&textEncoder.encodeInto?function(e,r){return textEncoder.encodeInto(e,target.subarray(r)).written}:false;let o=this;let e=t.structures||t.saveStructures;let _=t.maxSharedStructures;if(_==null)_=e?128:0;if(_>8190)throw new Error("Maximum maxSharedStructure is 8190");let i=t.sequential;if(i){_=0}if(!this.structures)this.structures=[];if(this.saveStructures)this.saveShared=this.saveStructures;let p,d,u=t.sharedValues;let y;if(u){y=Object.create(null);for(let e=0,r=u.length;ethis.encodeKeys(e));break}}return this.encode(e,r)};this.encode=function(r,e){if(!target){target=new ByteArrayAllocate(8192);targetView=new DataView(target.buffer,0,8192);position=0}safeEnd=target.length-10;if(safeEnd-position<2048){target=new ByteArrayAllocate(target.length);targetView=new DataView(target.buffer,0,target.length);safeEnd=target.length-10;position=0}else if(e===REUSE_BUFFER_MODE)position=position+7&2147483640;s=position;if(o.useSelfDescribedHeader){targetView.setUint32(position,3654940416);position+=3}n=o.structuredClone?new Map:null;if(o.bundleStrings&&typeof r!=="string"){bundledStrings=[];bundledStrings.size=Infinity}else bundledStrings=null;a=o.structures;if(a){if(a.uninitialized){let e=o.getShared()||{};o.structures=a=e.structures||[];o.sharedVersion=e.version;let t=o.sharedValues=e.packedValues;if(t){y={};for(let e=0,r=t.length;e_&&!i)e=_;if(!a.transitions){a.transitions=Object.create(null);for(let o=0;o0){target[position++]=216;target[position++]=51;writeArrayHeader(4);let t=e.values;g(t);writeArrayHeader(0);writeArrayHeader(0);d=Object.create(y||null);for(let e=0,r=t.length;esafeEnd)P(position);o.offset=position;let e=insertIds(target.subarray(s,position),n.idsToInsert);n=null;return e}if(e&REUSE_BUFFER_MODE){target.start=s;target.end=position;return target}return target.subarray(s,position)}finally{if(a){if(v<10)v++;if(a.length>_)a.length=_;if(m>1e4){a.transitions=null;v=0;m=0;if(h.length>0)h=[]}else if(h.length>0&&!i){for(let e=0,r=h.length;e_){o.structures=o.structures.slice(0,_)}let e=target.subarray(s,position);if(o.updateSharedData()===false)return o.encode(r);return e}if(e&RESET_BUFFER_MODE)position=s}};this.findCommonStringsToPack=()=>{p=new Map;if(!y)y=Object.create(null);return e=>{let t=e&&e.threshold||4;let n=this.pack?e.maxPrivatePackedValues||16:0;if(!u)u=this.sharedValues=[];for(let[e,r]of p){if(r.count>t){y[e]=n++;u.push(e);l=true}}while(this.saveShared&&this.updateSharedData()===false){}p=null}};const g=a=>{if(position>safeEnd)target=P(position);var e=typeof a;var u;if(e==="string"){if(d){let e=d[a];if(e>=0){if(e<16)target[position++]=e+224;else{target[position++]=198;if(e&1)g(15-e>>1);else g(e-16>>1)}return}else if(p&&!t.pack){let e=p.get(a);if(e)e.count++;else p.set(a,{count:1})}}let i=a.length;if(bundledStrings&&i>=4&&i<1024){if((bundledStrings.size+=i)>MAX_BUNDLE_SIZE){let e;let r=(bundledStrings[0]?bundledStrings[0].length*3+bundledStrings[1].length:0)+10;if(position+r>safeEnd)target=P(position+r);target[position++]=217;target[position++]=223;target[position++]=249;target[position++]=bundledStrings.position?132:130;target[position++]=26;e=position-s;position+=4;if(bundledStrings.position){writeBundles(s,g)}bundledStrings=["",""];bundledStrings.size=0;bundledStrings.position=e}let e=hasNonLatin.test(a);bundledStrings[e?0:1]+=a;target[position++]=e?206:207;g(i);return}let o;if(i<32){o=1}else if(i<256){o=2}else if(i<65536){o=3}else{o=5}let e=i*3;if(position+e>safeEnd)target=P(position+e);if(i<64||!c){let e,r,t,n=position+o;for(e=0;e>6|192;target[n++]=r&63|128}else if((r&64512)===55296&&((t=a.charCodeAt(e+1))&64512)===56320){r=65536+((r&1023)<<10)+(t&1023);e++;target[n++]=r>>18|240;target[n++]=r>>12&63|128;target[n++]=r>>6&63|128;target[n++]=r&63|128}else{target[n++]=r>>12|224;target[n++]=r>>6&63|128;target[n++]=r&63|128}}u=n-position-o}else{u=c(a,position+o,e)}if(u<24){target[position++]=96|u}else if(u<256){if(o<2){target.copyWithin(position+2,position+1,position+1+u)}target[position++]=120;target[position++]=u}else if(u<65536){if(o<3){target.copyWithin(position+3,position+2,position+2+u)}target[position++]=121;target[position++]=u>>8;target[position++]=u&255}else{if(o<5){target.copyWithin(position+5,position+3,position+3+u)}target[position++]=122;targetView.setUint32(position,u);position+=4}position+=u}else if(e==="number"){if(!this.alwaysUseFloat&&a>>>0===a){if(a<24){target[position++]=a}else if(a<256){target[position++]=24;target[position++]=a}else if(a<65536){target[position++]=25;target[position++]=a>>8;target[position++]=a&255}else{target[position++]=26;targetView.setUint32(position,a);position+=4}}else if(!this.alwaysUseFloat&&a>>0===a){if(a>=-24){target[position++]=31-a}else if(a>=-256){target[position++]=56;target[position++]=~a}else if(a>=-65536){target[position++]=57;targetView.setUint16(position,~a);position+=2}else{target[position++]=58;targetView.setUint32(position,~a);position+=4}}else{let r;if((r=this.useFloat32)>0&&a<4294967296&&a>=-2147483648){target[position++]=250;targetView.setFloat32(position,a);let e;if(r<4||(e=a*mult10[(target[position]&127)<<1|target[position+1]>>7])>>0===e){position+=4;return}else position--}target[position++]=251;targetView.setFloat64(position,a);position+=8}}else if(e==="object"){if(!a)target[position++]=246;else{if(n){let r=n.get(a);if(r){target[position++]=216;target[position++]=29;target[position++]=25;if(!r.references){let e=n.idsToInsert||(n.idsToInsert=[]);r.references=[];e.push(r)}r.references.push(position-s);position+=2;return}else n.set(a,{offset:position-s})}let e=a.constructor;if(e===Object){b(a,true)}else if(e===Array){u=a.length;if(u<24){target[position++]=128|u}else{writeArrayHeader(u)}for(let e=0;e>8;target[position++]=u&255}else{target[position++]=186;targetView.setUint32(position,u);position+=4}if(o.keyMap){for(let[e,r]of a){g(o.encodeKey(e));g(r)}}else{for(let[e,r]of a){g(e);g(r)}}}else{for(let t=0,e=extensions.length;t>8;target[position++]=r&255}else if(r>-1){target[position++]=218;targetView.setUint32(position,r);position+=4}e.encode.call(this,a,g,P);return}}if(a[Symbol.iterator]){if(throwOnIterable){let e=new Error("Iterable should be serialized as iterator");e.iteratorNotHandled=true;throw e}target[position++]=159;for(let e of a){g(e)}target[position++]=255;return}if(a[Symbol.asyncIterator]||isBlob(a)){let e=new Error("Iterable/blob should be serialized as iterator");e.iteratorNotHandled=true;throw e}if(this.useToJSON&&a.toJSON){const r=a.toJSON();if(r!==a)return g(r)}b(a,!a.hasOwnProperty)}}}else if(e==="boolean"){target[position++]=a?245:244}else if(e==="bigint"){if(a=0){target[position++]=27;targetView.setBigUint64(position,a)}else if(a>-(BigInt(1)<{let r=Object.keys(e);let t=Object.values(e);let n=r.length;if(n<24){target[position++]=160|n}else if(n<256){target[position++]=184;target[position++]=n}else if(n<65536){target[position++]=185;target[position++]=n>>8;target[position++]=n&255}else{target[position++]=186;targetView.setUint32(position,n);position+=4}if(o.keyMap){for(let e=0;e{target[position++]=185;let e=position-s;position+=2;let n=0;if(o.keyMap){for(let e in r)if(t||r.hasOwnProperty(e)){g(o.encodeKey(e));g(r[e]);n++}}else{for(let e in r)if(t||r.hasOwnProperty(e)){g(e);g(r[e]);n++}}target[e+++s]=n>>8;target[e+s]=n&255}:(r,t)=>{let n,i=f.transitions||(f.transitions=Object.create(null));let o=0;let a=0;let u;let s;if(this.keyMap){s=Object.keys(r).map(e=>this.encodeKey(e));a=s.length;for(let r=0;r>8|224;target[position++]=c&255}else{if(!s)s=i.__keys__||(i.__keys__=Object.keys(r));if(u===undefined){c=f.nextId++;if(!c){c=0;f.nextId=1}if(c>=MAX_STRUCTURES){f.nextId=(c=_)+1}}else{c=u}f[c]=s;if(c<_){target[position++]=217;target[position++]=c>>8|224;target[position++]=c&255;i=f.transitions;for(let e=0;e=MAX_STRUCTURES-_)h.shift()[RECORD_SYMBOL]=undefined;h.push(i);writeArrayHeader(a+2);g(57344+c);g(s);if(t===null)return;for(let e in r)if(t||r.hasOwnProperty(e))g(r[e]);return}}if(a<24){target[position++]=128|a}else{writeArrayHeader(a)}if(t===null)return;for(let e in r)if(t||r.hasOwnProperty(e))g(r[e])};const P=e=>{let r;if(e>16777216){if(e-s>MAX_BUFFER_SIZE)throw new Error("Encoded buffer would be larger than maximum buffer size");r=Math.min(MAX_BUFFER_SIZE,Math.round(Math.max((e-s)*(e>67108864?1.25:2),4194304)/4096)*4096)}else r=(Math.max(e-s<<2,target.length-1)>>12)+1<<12;let t=new ByteArrayAllocate(r);targetView=new DataView(t.buffer,0,r);if(target.copy)target.copy(t,0,s,e);else t.set(target.slice(s,e));position-=s;s=0;safeEnd=t.length-10;return target=t};let w=100;let D=1e3;this.encodeAsIterable=function(e,r){return S(e,r,x)};this.encodeAsAsyncIterable=function(e,r){return S(e,r,A)};function*x(n,i,e){let r=n.constructor;if(r===Object){let t=o.useRecords!==false;if(t)b(n,null);else writeEntityLength(Object.keys(n).length,160);for(let r in n){let e=n[r];if(!t)g(r);if(e&&typeof e==="object"){if(i[r])yield*x(e,i[r]);else yield*L(e,i,r)}else g(e)}}else if(r===Array){let e=n.length;writeArrayHeader(e);for(let r=0;rw)){if(i.element)yield*x(e,i.element);else yield*L(e,i,"element")}else g(e)}}else if(n[Symbol.iterator]){target[position++]=159;for(let e of n){if(e&&(typeof e==="object"||position-s>w)){if(i.element)yield*x(e,i.element);else yield*L(e,i,"element")}else g(e)}target[position++]=255}else if(isBlob(n)){writeEntityLength(n.size,64);yield target.subarray(s,position);yield n;E()}else if(n[Symbol.asyncIterator]){target[position++]=159;yield target.subarray(s,position);yield n;E();target[position++]=255}else{g(n)}if(e&&position>s)yield target.subarray(s,position);else if(position-s>w){yield target.subarray(s,position);E()}}function*L(r,t,n){let i=position-s;try{g(r);if(position-s>w){yield target.subarray(s,position);E()}}catch(e){if(e.iteratorNotHandled){t[n]={};position=s+i;yield*x.call(this,r,t[n])}else throw e}}function E(){w=D;o.encode(null,THROW_ON_ITERABLE)}function S(e,r,t){if(r&&r.chunkThreshold)w=D=r.chunkThreshold;else w=100;if(e&&typeof e==="object"){o.encode(null,THROW_ON_ITERABLE);return t(e,o.iterateProperties||(o.iterateProperties={}),true)}return[o.encode(e)]}async function*A(e,r){for(let t of x(e,r,true)){let e=t.constructor;if(e===ByteArray||e===Uint8Array)yield t;else if(isBlob(t)){let e=t.stream().getReader();let r;while(!(r=await e.read()).done){yield r.value}}else if(t[Symbol.asyncIterator]){for await(let e of t){E();if(e)yield*A(e,r.async||(r.async={}));else yield o.encode(e)}}else{yield t}}}}useBuffer(e){target=e;targetView=new DataView(target.buffer,target.byteOffset,target.byteLength);position=0}clearSharedData(){if(this.structures)this.structures=[];if(this.sharedValues)this.sharedValues=undefined}updateSharedData(){let r=this.sharedVersion||0;this.sharedVersion=r+1;let e=this.structures.slice(0);let t=new SharedData(e,this.sharedValues,this.sharedVersion);let n=this.saveShared(t,e=>(e&&e.version||0)==r);if(n===false){t=this.getShared()||{};this.structures=t.structures||[];this.sharedValues=t.packedValues;this.sharedVersion=t.version;this.structures.nextId=this.structures.length}else{e.forEach((e,r)=>this.structures[r]=e)}return n}}function writeEntityLength(e,r){if(e<24)target[position++]=r|e;else if(e<256){target[position++]=r|24;target[position++]=e}else if(e<65536){target[position++]=r|25;target[position++]=e>>8;target[position++]=e&255}else{target[position++]=r|26;targetView.setUint32(position,e);position+=4}}class SharedData{constructor(e,r,t){this.structures=e;this.packedValues=r;this.version=t}}function writeArrayHeader(e){if(e<24)target[position++]=128|e;else if(e<256){target[position++]=152;target[position++]=e}else if(e<65536){target[position++]=153;target[position++]=e>>8;target[position++]=e&255}else{target[position++]=154;targetView.setUint32(position,e);position+=4}}const BlobConstructor=typeof Blob==="undefined"?function(){}:Blob;function isBlob(e){if(e instanceof BlobConstructor)return true;let r=e[Symbol.toStringTag];return r==="Blob"||r==="File"}function findRepetitiveStrings(t,n){switch(typeof t){case"string":if(t.length>3){if(n.objectMap[t]>-1||n.values.length>=n.maxValues)return;let e=n.get(t);if(e){if(++e.count==2){n.values.push(t)}}else{n.set(t,{count:1});if(n.samplingPackedValues){let e=n.samplingPackedValues.get(t);if(e)e.count++;else n.samplingPackedValues.set(t,{count:1})}}}break;case"object":if(t){if(t instanceof Array){for(let e=0,r=t.length;e=0&&t<4294967296){target[position++]=26;targetView.setUint32(position,t);position+=4}else{target[position++]=251;targetView.setFloat64(position,t);position+=8}}},{tag:258,encode(e,r){let t=Array.from(e);r(t)}},{tag:27,encode(e,r){r([e.name,e.message])}},{tag:27,encode(e,r){r(["RegExp",e.source,e.flags])}},{getTag(e){return e.tag},encode(e,r){r(e.value)}},{encode(e,r,t){writeBuffer(e,t)}},{getTag(e){if(e.constructor===Uint8Array){if(this.tagUint8Array||hasNodeBuffer&&this.tagUint8Array!==false)return 64}},encode(e,r,t){writeBuffer(e,t)}},typedArrayEncoder(68,1),typedArrayEncoder(69,2),typedArrayEncoder(70,4),typedArrayEncoder(71,8),typedArrayEncoder(72,1),typedArrayEncoder(77,2),typedArrayEncoder(78,4),typedArrayEncoder(79,8),typedArrayEncoder(85,4),typedArrayEncoder(86,8),{encode(r,n){let e=r.packedValues||[];let t=r.structures||[];if(e.values.length>0){target[position++]=216;target[position++]=51;writeArrayHeader(4);let t=e.values;n(t);writeArrayHeader(0);writeArrayHeader(0);packedObjectMap=Object.create(sharedPackedObjectMap||null);for(let e=0,r=t.length;e1)e-=4;return{tag:e,encode:function e(r,t){let n=r.byteLength;let i=r.byteOffset||0;let o=r.buffer||r;t(hasNodeBuffer?Buffer$1.from(o,i,n):new Uint8Array(o,i,n))}}}function writeBuffer(e,r){let t=e.byteLength;if(t<24){target[position++]=64+t}else if(t<256){target[position++]=88;target[position++]=t}else if(t<65536){target[position++]=89;target[position++]=t>>8;target[position++]=t&255}else{target[position++]=90;targetView.setUint32(position,t);position+=4}if(position+t>=target.length){r(position+t)}target.set(e.buffer?e:new Uint8Array(e),position);position+=t}function insertIds(n,e){let t;let i=e.length*2;let o=n.length-i;e.sort((e,r)=>e.offset>r.offset?1:-1);for(let t=0;t>8;n[e]=t&255}}while(t=e.pop()){let e=t.offset;n.copyWithin(e+i,e,o);i-=2;let r=e+i;n[r++]=216;n[r++]=28;o=e}return n}function writeBundles(e,r){targetView.setUint32(bundledStrings.position+e,position-bundledStrings.position-e+1);let t=bundledStrings;bundledStrings=null;r(t[0]);r(t[1])}function addExtension(e){if(e.Class){if(!e.encode)throw new Error("Extension has no encode function");extensionClasses.unshift(e.Class);extensions.unshift(e)}addExtension$1(e)}let defaultEncoder=new Encoder({useRecords:false});defaultEncoder.encode;defaultEncoder.encodeAsIterable;defaultEncoder.encodeAsAsyncIterable;const REUSE_BUFFER_MODE=512;const RESET_BUFFER_MODE=1024;const THROW_ON_ITERABLE=2048;var lzjbPack={}; /**@license @@ -42,4 +42,4 @@ function _classApplyDescriptorGet(e,r){if(r.get){return r.get.call(e)}return r.v * Released under BSD-3-Clause License * * build: Wed, 27 Oct 2021 10:43:10 GMT - */Object.defineProperty(lzjbPack,"__esModule",{value:true});const NBBY=8,MATCH_BITS=6,MATCH_MIN=3,MATCH_MAX=(1<t-MATCH_MAX){r[i++]=e[n++];continue}l=(e[n]+13^e[n+1]-13^e[n+2])&LEMPEL_SIZE-1;c=n-f[l]&OFFSET_MASK;f[l]=n;o=n-c;if(o>=0&&o!=n&&e[n]==e[o]&&e[n+1]==e[o+1]&&e[n+2]==e[o+2]){r[a]|=u;for(s=MATCH_MIN;s>NBBY;r[i++]=c;n+=s}else{r[i++]=e[n++]}}console.assert(e.length>=n);return i}function decompress(e,r,t){r=r|0;var n=0,i=0,o=0,a=0,u=1<<(NBBY-1|0),s=0,c=0;while(n>(NBBY-MATCH_BITS|0))+MATCH_MIN|0;c=(e[n]<4){t[i]=t[o];i=i+1|0;o=o+1|0;t[i]=t[o];i=i+1|0;o=o+1|0;t[i]=t[o];i=i+1|0;o=o+1|0;t[i]=t[o];i=i+1|0;o=o+1|0;s=s-4|0}while(s>0){t[i]=t[o];i=i+1|0;o=o+1|0;s=s-1|0}}}else{t[i]=e[n];i=i+1|0;n=n+1|0}}return i}function encode_magic$1(){const e=new TextEncoder("utf-8");return e.encode(MAGIC_STRING)}const MAGIC_STRING="@lzjb";const MAGIC=encode_magic$1();function merge_uint8_array$1(...e){if(e.length>1){const t=e.reduce((e,r)=>e+r.length,0);const n=new Uint8Array(t);let r=0;e.forEach(e=>{n.set(e,r);r+=e.length});return n}else if(e.length){return e[0]}}function number_to_bytes(r){const e=Math.ceil(Math.log2(r)/8);const t=new Uint8Array(e);for(let e=0;e=0;e--){t=t*256+r[e]}return t}function pack(e,{magic:r=true}={}){const t=new Uint8Array(Math.max(e.length*1.5|0,16*1024));const n=compress(e,t);const i=number_to_bytes(e.length);const o=[Uint8Array.of(i.length),i,t.slice(0,n)];if(r){o.unshift(MAGIC)}return merge_uint8_array$1(...o)}function unpack(r,{magic:e=true}={}){if(e){const e=new TextDecoder("utf-8");const s=e.decode(r.slice(0,MAGIC.length));if(s!==MAGIC_STRING){throw new Error("Invalid magic value")}}const t=e?MAGIC.length:0;const n=r[t];const i=t+1;const o=t+n+1;const a=bytes_to_number(r.slice(i,o));r=r.slice(o);const u=new Uint8Array(a);decompress(r,r.length,u);return u}var pack_1=lzjbPack.pack=pack;var unpack_1=lzjbPack.unpack=unpack;function unfetch(s,c){return c=c||{},new Promise(function(e,r){var t=new XMLHttpRequest,n=[],i=[],o={},a=function(){return{ok:2==(t.status/100|0),statusText:t.statusText,status:t.status,url:t.responseURL,text:function(){return Promise.resolve(t.responseText)},json:function(){return Promise.resolve(t.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([t.response]))},clone:a,headers:{keys:function(){return n},entries:function(){return i},get:function(e){return o[e.toLowerCase()]},has:function(e){return e.toLowerCase()in o}}}};for(var u in t.open(c.method||"get",s,!0),t.onload=function(){t.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,r,t){n.push(r=r.toLowerCase()),i.push([r,t]),o[r]=o[r]?o[r]+","+t:t}),e(a())},t.onerror=r,t.withCredentials="include"==c.credentials,c.headers)t.setRequestHeader(u,c.headers[u]);t.send(c.body||null)})}var _fold_case_mapping;var _excluded=["token"],_excluded2=["env"],_excluded3=["stderr","stdin","stdout","command_line"],_excluded4=["use_dynamic"],_excluded5=["use_dynamic"],_excluded6=["env","dynamic_env","use_dynamic","error"];function _classPrivateFieldInitSpec(e,r,t){_checkPrivateRedeclaration(e,r);r.set(e,t)}function _checkPrivateRedeclaration(e,r){if(r.has(e)){throw new TypeError("Cannot initialize the same private elements twice on an object")}}function _callSuper(e,r,t){return r=_getPrototypeOf(r),_possibleConstructorReturn(e,_isNativeReflectConstruct()?Reflect.construct(r,t||[],_getPrototypeOf(e).constructor):r.apply(e,t))}function _isNativeReflectConstruct(){try{var r=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(r){}return(_isNativeReflectConstruct=function e(){return!!r})()}function _createForOfIteratorHelper(r,e){var t=typeof Symbol!=="undefined"&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&typeof r.length==="number"){if(t)r=t;var n=0;var i=function e(){};return{s:i,n:function e(){if(n>=r.length)return{done:true};return{done:false,value:r[n++]}},e:function e(r){throw r},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o=true,a=false,u;return{s:function e(){t=t.call(r)},n:function e(){var r=t.next();o=r.done;return r},e:function e(r){a=true;u=r},f:function e(){try{if(!o&&t["return"]!=null)t["return"]()}finally{if(a)throw u}}}}function _unsupportedIterableToArray(e,r){if(!e)return;if(typeof e==="string")return _arrayLikeToArray(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);if(t==="Object"&&e.constructor)t=e.constructor.name;if(t==="Map"||t==="Set")return Array.from(e);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return _arrayLikeToArray(e,r)}function _arrayLikeToArray(e,r){if(r==null||r>e.length)r=e.length;for(var t=0,n=new Array(r);t1?t-1:0),i=1;i0&&arguments[0]!==undefined?arguments[0]:null;var r=user_env&&user_env.get("DEBUG",{throwError:false});if(e===null){return r===true}return(r===null||r===void 0?void 0:r.valueOf())===e.valueOf()}function num_mnemicic_re(e){return e?"(?:#".concat(e,"(?:#[ie])?|#[ie]#").concat(e,")"):"(?:#[ie])?"}function gen_rational_re(e,r){return"".concat(num_mnemicic_re(e),"[+-]?").concat(r,"+/").concat(r,"+")}function gen_complex_re(e,r){return"".concat(num_mnemicic_re(e),"(?:[+-]?(?:").concat(r,"+/").concat(r,"+|nan.0|inf.0|").concat(r,"+))?(?:[+-]i|[+-]?(?:").concat(r,"+/").concat(r,"+|").concat(r,"+|nan.0|inf.0)i)(?=[()[\\]\\s]|$)")}function gen_integer_re(e,r){return"".concat(num_mnemicic_re(e),"[+-]?").concat(r,"+")}var re_re=/^#\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimyus]*)$/;var float_stre="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)";var complex_float_stre="(?:#[ie])?(?:[+-]?(?:[0-9][0-9_]*/[0-9][0-9_]*|nan.0|inf.0|".concat(float_stre,"|[+-]?[0-9]+))?(?:").concat(float_stre,"|[+-](?:[0-9]+/[0-9]+|[0-9]+|nan.0|inf.0))i");var float_re=new RegExp("^(#[ie])?".concat(float_stre,"$"),"i");function make_complex_match_re(e,r){var t=e==="x"?"(?!\\+|".concat(r,")"):"(?!\\.|".concat(r,")");var n="";if(e===""){n="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+(?![0-9]))(?:[eE][-+]?[0-9]+)?))"}return new RegExp("^((?:(?:".concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(r,"+/").concat(r,"+(?!").concat(r,")|[+-]?").concat(r,"+)").concat(t,")?)(").concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(r,"+/").concat(r,"+|[+-]?").concat(r,"+|[+-])i$"),"i")}var complex_list_re=function(){var o={};[[10,"","[0-9]"],[16,"x","[0-9a-fA-F]"],[8,"o","[0-7]"],[2,"b","[01]"]].forEach(function(e){var r=_slicedToArray(e,3),t=r[0],n=r[1],i=r[2];o[t]=make_complex_match_re(n,i)});return o}();var characters={alarm:"",backspace:"\b",delete:"",escape:"",newline:"\n",null:"\0",return:"\r",space:" ",tab:"\t",dle:"",soh:"",dc1:"",stx:"",dc2:"",etx:"",dc3:"",eot:"",dc4:"",enq:"",nak:"",ack:"",syn:"",bel:"",etb:"",bs:"\b",can:"",ht:"\t",em:"",lf:"\n",sub:"",vt:"\v",esc:"",ff:"\f",fs:"",cr:"\r",gs:"",so:"",rs:"",si:"",us:"",del:""};function ucs2decode(e){var r=[];var t=0;var n=e.length;while(t=55296&&i<=56319&&t1&&arguments[1]!==undefined?arguments[1]:10;var t=num_pre_parse(e);var n=t.number.split("/");var i=LRational({num:LNumber([n[0],t.radix||r]),denom:LNumber([n[1],t.radix||r])});if(t.inexact){return i.valueOf()}else{return i}}function parse_integer(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;var t=num_pre_parse(e);if(t.inexact){return LFloat(parseInt(t.number,t.radix||r))}return LNumber([t.number,t.radix||r])}function parse_character(e){var r=e.match(/#\\x([0-9a-f]+)$/i);var t;if(r){var n=parseInt(r[1],16);t=String.fromCodePoint(n)}else{r=e.match(/#\\([\s\S]+)$/);if(r){t=r[1]}}if(t){return LCharacter(t)}throw new Error("Parse: invalid character")}function parse_complex(e){var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;function r(e){var r;if(e==="+"){r=LNumber(1)}else if(e==="-"){r=LNumber(-1)}else if(e.match(int_bare_re)){r=LNumber([e,i])}else if(e.match(rational_bare_re)){var t=e.split("/");r=LRational({num:LNumber([t[0],i]),denom:LNumber([t[1],i])})}else if(e.match(float_re)){var n=parse_float(e);if(o.exact){return n.toRational()}return n}else if(e.match(/nan.0$/)){return LNumber(NaN)}else if(e.match(/inf.0$/)){if(e[0]==="-"){return LNumber(Number.NEGATIVE_INFINITY)}return LNumber(Number.POSITIVE_INFINITY)}else{throw new Error("Internal Parser Error")}if(o.inexact){return LFloat(r.valueOf())}return r}var o=num_pre_parse(e);i=o.radix||i;var t;var n=o.number.match(complex_bare_match_re);if(i!==10&&n){t=n}else{t=o.number.match(complex_list_re[i])}var a,u;u=r(t[2]);if(t[1]){a=r(t[1])}else if(u instanceof LFloat){a=LFloat(0)}else{a=LNumber(0)}if(u.cmp(0)===0&&u.__type__==="bigint"){return a}return LComplex({im:u,re:a})}function is_int(e){return parseInt(e.toString(),10)===e}function parse_big_int(e){var r=e.match(/^(([-+]?[0-9]*)(?:\.([0-9]+))?)e([-+]?[0-9]+)/i);if(r){var t=parseInt(r[4],10);var n;var i=r[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var o=r[3]&&r[3].length;if(i0&&(r.exact||!r.number.match(/\./))){return LNumber(o).mul(u)}}}t=LFloat(t);if(r.exact){return t.toRational()}return t}function parse_string(e){e=e.replace(/\\x([0-9a-f]+);/gi,function(e,r){return"\\u"+r.padStart(4,"0")}).replace(/\n/g,"\\n");var r=e.match(/(\\*)(\\x[0-9A-F])/i);if(r&&r[1].length%2===0){throw new Error("Invalid string literal, unclosed ".concat(r[2]))}try{var t=LString(JSON.parse(e));t.freeze();return t}catch(e){var n=e.message.replace(/in JSON /,"").replace(/.*Error: /,"");throw new Error("Invalid string literal: ".concat(n))}}function parse_symbol(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var t={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,r){return String.fromCharCode(parseInt("0"+r,16))}).replace(/\\(.)/g,function(e,r){return t[r]||r})}return new LSymbol(e)}function parse_argument(e){if(constants.hasOwnProperty(e)){return constants[e]}if(e.match(/^"[\s\S]*"$/)){return parse_string(e)}else if(e[0]==="#"){var r=e.match(re_re);if(r){return new RegExp(r[1],r[2])}else if(e.match(char_re)){return parse_character(e)}var t=e.match(/#\\(.+)/);if(t&&ucs2decode(t[1]).length===1){return parse_character(e)}}if(e.match(/[0-9a-f]|[+-]i/i)){if(e.match(int_re)){return parse_integer(e)}else if(e.match(float_re)){return parse_float(e)}else if(e.match(rational_re)){return parse_rational(e)}else if(e.match(complex_re)){return parse_complex(e)}}if(e.match(/^#[iexobd]/)){throw new Error("Invalid numeric constant: "+e)}return parse_symbol(e)}function is_atom_string(e){return!(["(",")","[","]"].includes(e)||specials.names().includes(e))}function is_symbol_string(e){return is_atom_string(e)&&!(e.match(re_re)||e.match(/^"[\s\S]*"$/)||e.match(int_re)||e.match(float_re)||e.match(complex_re)||e.match(rational_re)||e.match(char_re)||["#t","#f","nil"].includes(e))}var string_re=/"(?:\\[\S\s]|[^"])*"?/g;function escape_regex(e){if(typeof e==="string"){var r=/([-\\^$[\]()+{}?*.|])/g;return e.replace(r,"\\$1")}return e}function Stack(){this.data=[]}Stack.prototype.push=function(e){this.data.push(e)};Stack.prototype.top=function(){return this.data[this.data.length-1]};Stack.prototype.pop=function(){return this.data.pop()};Stack.prototype.is_empty=function(){return!this.data.length};function tokens(e){if(e instanceof LString){e=e.valueOf()}var r=new Lexer(e,{whitespace:true});var t=[];while(true){var n=r.peek(true);if(n===eof){break}t.push(n);r.skip()}return t}function multiline_formatter(e){var r=e.token,t=_objectWithoutProperties(e,_excluded);if(r.match(/^"[\s\S]*"$/)&&r.match(/\n/)){var n=new RegExp("^ {1,"+(e.col+1)+"}","mg");r=r.replace(n,"")}return _objectSpread({token:r},t)}function Thunk(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(){};this.fn=e;this.cont=r}Thunk.prototype.toString=function(){return"#"};function trampoline(n){return function(){for(var e=arguments.length,r=new Array(e),t=0;t1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof LString){e=e.toString()}if(r){return tokens(e)}else{var t=tokens(e).map(function(e){if(e.token==="#\\ "||e.token=="#\\\n"){return e.token}return e.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return strip_s_comments(t)}}function strip_s_comments(e){var r=0;var t=null;var n=[];for(var i=0;i0&&arguments[0]!==undefined?arguments[0]:null;if(e instanceof LSymbol){if(e.is_gensym()){return e}e=e.valueOf()}if(is_gensym(e)){return LSymbol(e)}if(e!==null){return t(e,Symbol("#:".concat(e)))}r++;return t(r,Symbol("#:g".concat(r)))}}();function QuotedPromise(e){var t=this;var n={pending:true,rejected:false,fulfilled:false,reason:undefined,type:undefined};e=e.then(function(e){n.type=type(e);n.fulfilled=true;n.pending=false;return e});read_only(this,"_promise",e,{hidden:true});if(is_function(e["catch"])){e=e["catch"](function(e){n.rejected=true;n.pending=false;n.reason=e})}Object.keys(n).forEach(function(r){Object.defineProperty(t,"__".concat(r,"__"),{enumerable:true,get:function e(){return n[r]}})});read_only(this,"__promise__",e);this.then=false}QuotedPromise.prototype.then=function(e){return new QuotedPromise(this.valueOf().then(e))};QuotedPromise.prototype["catch"]=function(e){return new QuotedPromise(this.valueOf()["catch"](e))};QuotedPromise.prototype.valueOf=function(){if(!this._promise){throw new Error("QuotedPromise: invalid promise created")}return this._promise};QuotedPromise.prototype.toString=function(){if(this.__pending__){return QuotedPromise.pending_str}if(this.__rejected__){return QuotedPromise.rejected_str}return"#")};QuotedPromise.pending_str="#";QuotedPromise.rejected_str="#";function promise_all(e){if(Array.isArray(e)){return Promise.all(escape_quoted_promises(e)).then(unescape_quoted_promises)}return e}function escape_quoted_promises(e){var r=new Array(e.length),t=e.length;while(t--){var n=e[t];if(n instanceof QuotedPromise){r[t]=new Value(n)}else{r[t]=n}}return r}function unescape_quoted_promises(e){var r=new Array(e.length),t=e.length;while(t--){var n=e[t];if(n instanceof Value){r[t]=n.valueOf()}else{r[t]=n}}return r}var specials={LITERAL:Symbol["for"]("literal"),SPLICE:Symbol["for"]("splice"),SYMBOL:Symbol["for"]("symbol"),names:function e(){return Object.keys(this.__list__)},type:function e(r){try{return this.get(r).type}catch(e){console.log({name:r});console.log(e);return null}},get:function e(r){return this.__list__[r]},off:function e(r){var t=this;var n=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(Array.isArray(r)){r.forEach(function(e){return t.off(e,n)})}else if(n===null){delete this.__events__[r]}else{this.__events__=this.__events__.filter(function(e){return e!==n})}},on:function e(r,t){var n=this;if(Array.isArray(r)){r.forEach(function(e){return n.on(e,t)})}else if(!this.__events__[r]){this.__events__[r]=[t]}else{this.__events__[r].push(t)}},trigger:function e(r){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i",new LSymbol("quote-promise"),specials.LITERAL]];var builtins=defined_specials.map(function(e){return e[0]});Object.freeze(builtins);Object.defineProperty(specials,"__builtins__",{writable:false,value:builtins});defined_specials.forEach(function(e){var r=_slicedToArray(e,3),t=r[0],n=r[1],i=r[2];specials.append(t,n,i)});var Lexer=function(){function p(e){var r=this;var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=t.whitespace,i=n===void 0?false:n;_classCallCheck(this,p);read_only(this,"__input__",e.replace(/\r/g,""));var o={};["_i","_whitespace","_col","_newline","_line","_state","_next","_token","_prev_char"].forEach(function(t){Object.defineProperty(r,t,{configurable:false,enumerable:false,get:function e(){return o[t]},set:function e(r){o[t]=r}})});this._whitespace=i;this._i=this._line=this._col=this._newline=0;this._state=this._next=this._token=null;this._prev_char=""}_createClass(p,[{key:"get",value:function e(r){return this.__internal[r]}},{key:"set",value:function e(r,t){this.__internal[r]=t}},{key:"token",value:function e(){var r=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(r){var t=this._line;if(this._whitespace&&this._token==="\n"){--t}return{token:this._token,col:this._col,offset:this._i,line:t}}return this._token}},{key:"peek",value:function e(){var r=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(this._i>=this.__input__.length){return eof}if(this._token){return this.token(r)}var t=this.next_token();if(t){this._token=this.__input__.substring(this._i,this._next);return this.token(r)}return eof}},{key:"skip",value:function e(){if(this._next!==null){this._token=null;this._i=this._next}}},{key:"read_line",value:function e(){var r=this.__input__.length;if(this._i>=r){return eof}for(var t=this._i;t=t){return eof}if(r+this._i>=t){return this.read_rest()}var n=this._i+r;var i=this.__input__.substring(this._i,n);var o=i.match(/\n/g);if(o){this._line+=o.length}this._i=n;return i}},{key:"peek_char",value:function e(){if(this._i>=this.__input__.length){return eof}return LCharacter(this.__input__[this._i])}},{key:"read_char",value:function e(){var r=this.peek_char();this.skip_char();return r}},{key:"skip_char",value:function e(){if(this._i1&&arguments[1]!==undefined?arguments[1]:{},n=t.prev_char,i=t["char"],o=t.next_char;var a=_slicedToArray(r,4),u=a[0],s=a[1],c=a[2],l=a[3];if(r.length!==5){throw new Error("Lexer: Invalid rule of length ".concat(r.length))}if(is_string(u)){if(u!==i){return false}}else if(!i.match(u)){return false}if(!match_or_null(s,n)){return false}if(!match_or_null(c,o)){return false}if(l!==this._state){return false}return true}},{key:"next_token",value:function e(){if(this._i>=this.__input__.length){return false}var r=true;e:for(var t=this._i,n=this.__input__.length;t2&&arguments[2]!==undefined?arguments[2]:null;var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;if(r.length===0){throw new Error("Lexer: invalid literal rule")}if(r.length===1){return[[r,n,i,null,null]]}var o=[];for(var a=0,u=r.length;a1&&arguments[1]!==undefined?arguments[1]:{},t=r.env,n=r.meta,i=n===void 0?false:n,o=r.formatter,a=o===void 0?multiline_formatter:o;_classCallCheck(this,u);if(e instanceof LString){e=e.toString()}read_only(this,"_formatter",a,{hidden:true});read_only(this,"__lexer__",new Lexer(e));read_only(this,"__env__",t);read_only(this,"_meta",i,{hidden:true});read_only(this,"_refs",[],{hidden:true});read_only(this,"_state",{parentheses:0,fold_case:false},{hidden:true})}_createClass(u,[{key:"resolve",value:function e(r){return this.__env__&&this.__env__.get(r,{throwError:false})}},{key:"peek",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var t;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:t=this.__lexer__.peek(true);if(!(t===eof)){r.next=4;break}return r.abrupt("return",eof);case 4:if(!this.is_comment(t.token)){r.next=7;break}this.skip();return r.abrupt("continue",0);case 7:if(!is_directive(t.token)){r.next=11;break}this.skip();if(t.token==="#!fold-case"){this._state.fold_case=true}else if(t.token==="#!no-fold-case"){this._state.fold_case=false}return r.abrupt("continue",0);case 11:if(!(t.token==="#;")){r.next=18;break}this.skip();if(!(this.__lexer__.peek()===eof)){r.next=15;break}throw new Error("Lexer: syntax error eof found after comment");case 15:r.next=17;return this._read_object();case 17:return r.abrupt("continue",0);case 18:return r.abrupt("break",21);case 21:t=this._formatter(t);if(this._state.fold_case){t.token=foldcase_string(t.token)}if(!this._meta){r.next=25;break}return r.abrupt("return",t);case 25:return r.abrupt("return",t.token);case 26:case"end":return r.stop()}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"reset",value:function e(){this._refs.length=0}},{key:"skip",value:function e(){this.__lexer__.skip()}},{key:"read",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var t;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:r.next=2;return this.peek();case 2:t=r.sent;this.skip();return r.abrupt("return",t);case 5:case"end":return r.stop()}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"match_datum_label",value:function e(r){var t=r.match(/^#([0-9]+)=$/);return t&&t[1]}},{key:"match_datum_ref",value:function e(r){var t=r.match(/^#([0-9]+)#$/);return t&&t[1]}},{key:"is_open",value:function e(r){var t=["(","["].includes(r);if(t){this._state.parentheses++}return t}},{key:"is_close",value:function e(r){var t=[")","]"].includes(r);if(t){this._state.parentheses--}return t}},{key:"read_list",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var t,n,i,o,a;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:t=_nil,n=t;case 1:r.next=4;return this.peek();case 4:o=r.sent;if(!(o===eof)){r.next=7;break}return r.abrupt("break",32);case 7:if(!this.is_close(o)){r.next=10;break}this.skip();return r.abrupt("break",32);case 10:if(!(o==="."&&!is_nil(t))){r.next=18;break}this.skip();r.next=14;return this._read_object();case 14:n.cdr=r.sent;i=true;r.next=30;break;case 18:if(!i){r.next=22;break}throw new Error("Parser: syntax error more than one element after dot");case 22:r.t0=Pair;r.next=25;return this._read_object();case 25:r.t1=r.sent;r.t2=_nil;a=new r.t0(r.t1,r.t2);if(is_nil(t)){t=a}else{n.cdr=a}n=a;case 30:r.next=1;break;case 32:return r.abrupt("return",t);case 33:case"end":return r.stop()}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"read_value",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var t;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:r.next=2;return this.read();case 2:t=r.sent;if(!(t===eof)){r.next=5;break}throw new Error("Parser: Expected token eof found");case 5:return r.abrupt("return",parse_argument(t));case 6:case"end":return r.stop()}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"is_comment",value:function e(r){return r.match(/^;/)||r.match(/^#\|/)&&r.match(/\|#$/)}},{key:"evaluate",value:function e(r){return _evaluate(r,{env:this.__env__,error:function e(r){throw r}})}},{key:"read_object",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var t;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:this.reset();r.next=3;return this._read_object();case 3:t=r.sent;if(t instanceof DatumReference){t=t.valueOf()}if(!this._refs.length){r.next=7;break}return r.abrupt("return",unpromise(this._resolve_object(t),function(e){if(is_pair(e)){e.mark_cycles()}return e}));case 7:return r.abrupt("return",t);case 8:case"end":return r.stop()}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"balanced",value:function e(){return this._state.parentheses===0}},{key:"ballancing_error",value:function e(r,t){var n=this._state.parentheses;var i;if(n<0){i=new Error("Parser: unexpected parenthesis");i.__code__=[t.toString()+")"]}else{i=new Error("Parser: expected parenthesis but eof found");var o=new RegExp("\\){".concat(n,"}$"));i.__code__=[r.toString().replace(o,"")]}throw i}},{key:"_resolve_object",value:function(){var r=_asyncToGenerator(_regeneratorRuntime.mark(function e(t){var n=this;var i;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:if(!Array.isArray(t)){r.next=2;break}return r.abrupt("return",t.map(function(e){return n._resolve_object(e)}));case 2:if(!is_plain_object(t)){r.next=6;break}i={};Object.keys(t).forEach(function(e){i[e]=n._resolve_object(t[e])});return r.abrupt("return",i);case 6:if(!is_pair(t)){r.next=8;break}return r.abrupt("return",this._resolve_pair(t));case 8:return r.abrupt("return",t);case 9:case"end":return r.stop()}},e,this)}));function e(e){return r.apply(this,arguments)}return e}()},{key:"_resolve_pair",value:function(){var r=_asyncToGenerator(_regeneratorRuntime.mark(function e(t){return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:if(!is_pair(t)){r.next=15;break}if(!(t.car instanceof DatumReference)){r.next=7;break}r.next=4;return t.car.valueOf();case 4:t.car=r.sent;r.next=8;break;case 7:this._resolve_pair(t.car);case 8:if(!(t.cdr instanceof DatumReference)){r.next=14;break}r.next=11;return t.cdr.valueOf();case 11:t.cdr=r.sent;r.next=15;break;case 14:this._resolve_pair(t.cdr);case 15:return r.abrupt("return",t);case 16:case"end":return r.stop()}},e,this)}));function e(e){return r.apply(this,arguments)}return e}()},{key:"_read_object",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var t,n,i,o,a,u,s,c,l,f,_;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:r.next=2;return this.peek();case 2:t=r.sent;if(!(t===eof)){r.next=5;break}return r.abrupt("return",t);case 5:if(!is_special(t)){r.next=38;break}n=specials.get(t);i=is_builtin(t);this.skip();a=is_symbol_extension(t);if(!a){r.next=14;break}r.t0=undefined;r.next=17;break;case 14:r.next=16;return this._read_object();case 16:r.t0=r.sent;case 17:u=r.t0;if(i){r.next=25;break}s=this.__env__.get(n.symbol);if(!(typeof s==="function")){r.next=25;break}if(is_literal(t)){c=[u]}else if(is_nil(u)){c=[]}else if(is_pair(u)){c=u.to_array(false)}if(!(c||a)){r.next=24;break}return r.abrupt("return",call_function(s,a?[]:c,{env:this.__env__,dynamic_env:this.__env__,use_dynamic:false}));case 24:throw new Error("Parse Error: Invalid parser extension "+"invocation ".concat(n.symbol));case 25:if(is_literal(t)){o=new Pair(n.symbol,new Pair(u,_nil))}else{o=new Pair(n.symbol,u)}if(!i){r.next=28;break}return r.abrupt("return",o);case 28:if(!(s instanceof Macro)){r.next=37;break}r.next=31;return this.evaluate(o);case 31:l=r.sent;if(!(is_pair(l)||l instanceof LSymbol)){r.next=34;break}return r.abrupt("return",Pair.fromArray([LSymbol("quote"),l]));case 34:return r.abrupt("return",l);case 37:throw new Error("Parse Error: invalid parser extension: "+n.symbol);case 38:f=this.match_datum_ref(t);if(!(f!==null)){r.next=44;break}this.skip();if(!this._refs[f]){r.next=43;break}return r.abrupt("return",new DatumReference(f,this._refs[f]));case 43:throw new Error("Parse Error: invalid datum label #".concat(f,"#"));case 44:_=this.match_datum_label(t);if(!(_!==null)){r.next=51;break}this.skip();this._refs[_]=this._read_object();return r.abrupt("return",this._refs[_]);case 51:if(!this.is_close(t)){r.next=55;break}this.skip();r.next=61;break;case 55:if(!this.is_open(t)){r.next=60;break}this.skip();return r.abrupt("return",this.read_list());case 60:return r.abrupt("return",this.read_value());case 61:case"end":return r.stop()}},e,this)}));function r(){return e.apply(this,arguments)}return r}()}]);return u}();var DatumReference=function(){function t(e,r){_classCallCheck(this,t);this.name=e;this.data=r}_createClass(t,[{key:"valueOf",value:function e(){return this.data}}]);return t}();function _parse(e,r){return _parse2.apply(this,arguments)}function _parse2(){_parse2=_wrapAsyncGenerator(_regeneratorRuntime.mark(function e(t,n){var i,o,a;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:if(!n){if(global_env){n=global_env.get("**interaction-environment**",{throwError:false})}else{n=user_env}}i=new Parser(t,{env:n});case 2:r.next=5;return _awaitAsyncGenerator(i.read_object());case 5:a=r.sent;if(!i.balanced()){i.ballancing_error(a,o)}if(!(a===eof)){r.next=9;break}return r.abrupt("break",14);case 9:o=a;r.next=12;return a;case 12:r.next=2;break;case 14:case"end":return r.stop()}},e)}));return _parse2.apply(this,arguments)}function unpromise(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(e){return e};var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;if(is_promise(e)){var n=e.then(r);if(t===null){return n}else{return n["catch"](t)}}if(e instanceof Array){return unpromise_array(e,r,t)}if(is_plain_object(e)){return unpromise_object(e,r,t)}return r(e)}function unpromise_array(r,t,e){if(r.find(is_promise)){return unpromise(promise_all(r),function(e){if(Object.isFrozen(r)){Object.freeze(e)}return t(e)},e)}return t(r)}function unpromise_object(r,e,t){var i=Object.keys(r);var n=[],o=[];var a=i.length;while(a--){var u=i[a];var s=r[u];n[a]=s;if(is_promise(s)){o.push(s)}}if(o.length){return unpromise(promise_all(n),function(e){var n={};e.forEach(function(e,r){var t=i[r];n[t]=e});if(Object.isFrozen(r)){Object.freeze(n)}return n},t)}return e(r)}function read_only(e,r,t){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{},i=n.hidden,o=i===void 0?false:i;Object.defineProperty(e,r,{value:t,configurable:true,enumerable:!o})}function uniterate_async(e){return _uniterate_async.apply(this,arguments)}function _uniterate_async(){_uniterate_async=_asyncToGenerator(_regeneratorRuntime.mark(function e(t){var n,i,o,a,u,s,c;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:n=[];i=false;o=false;r.prev=3;u=_asyncIterator(t);case 5:r.next=7;return u.next();case 7:if(!(i=!(s=r.sent).done)){r.next=13;break}c=s.value;n.push(c);case 10:i=false;r.next=5;break;case 13:r.next=19;break;case 15:r.prev=15;r.t0=r["catch"](3);o=true;a=r.t0;case 19:r.prev=19;r.prev=20;if(!(i&&u["return"]!=null)){r.next=24;break}r.next=24;return u["return"]();case 24:r.prev=24;if(!o){r.next=27;break}throw a;case 27:return r.finish(24);case 28:return r.finish(19);case 29:return r.abrupt("return",n);case 30:case"end":return r.stop()}},e,null,[[3,15,19,29],[20,,24,28]])}));return _uniterate_async.apply(this,arguments)}function matcher(e,r){if(r instanceof RegExp){return function(e){return String(e).match(r)}}else if(is_function(r)){return r}throw new Error("Invalid matcher")}function doc(e,r,t,n){if(typeof e!=="string"){r=arguments[0];t=arguments[1];n=arguments[2];e=null}if(t){if(n){r.__doc__=t}else{r.__doc__=trim_lines(t)}}if(e){r.__name__=e}else if(r.name&&!is_lambda(r)){r.__name__=r.name}return r}function trim_lines(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function previousSexp(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var t=e.length;if(r<=0){throw Error("previousSexp: Invalid argument sexp = ".concat(r))}e:while(r--&&t>=0){var n=1;while(n>0){var i=e[--t];if(!i){break e}if(i==="("||i.token==="("){n--}else if(i===")"||i.token===")"){n++}}t--}return e.slice(t+1)}function lineIndent(e){if(!e||!e.length){return 0}var r=e.length;if(e[r-1].token==="\n"){return 0}while(--r){if(e[r].token==="\n"){var t=(e[r+1]||{}).token;if(t){return t.length}}}return 0}function match(e,r){return l(e,r)===r.length;function l(t,n){function e(e,r){var t=_createForOfIteratorHelper(e),n;try{for(t.s();!(n=t.n()).done;){var i=n.value;var o=l(i,r);if(o!==-1){return o}}}catch(e){t.e(e)}finally{t.f()}return-1}function r(){return t[o]===Symbol["for"]("symbol")&&!is_symbol_string(n[u])}function i(){var e=t[o+1];var r=n[u+1];if(e!==undefined&&r!==undefined){return l([e],[r])}}var o=0;var a={};for(var u=0;u0){continue}}else if(r()){return-1}}else if(t[o]instanceof Array){var c=l(t[o],n.slice(u));if(c===-1||c+u>n.length){return-1}u+=c-1;o++;continue}else{return-1}o++}if(t.length!==o){return-1}return n.length}}function Formatter(e){this.__code__=e.replace(/\r/g,"")}Formatter.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?(?:define(?:-values|-syntax|-macro|-class|-record-type)?|(?:call-with-(?:input-file|output-file|port))|lambda|let-env|try|catch|when|unless|while|syntax-rules|(let|letrec)(-syntax|\*?-values|\*)?)$/],shift:{1:["&","#"]}}};Formatter.match=match;Formatter.prototype._options=function e(r){var t=Formatter.defaults;if(typeof r==="undefined"){return Object.assign({},t)}var n=r&&r.exceptions||{};var i=n.specials||[];var o=n.shift||{1:[]};return _objectSpread(_objectSpread(_objectSpread({},t),r),{},{exceptions:{specials:[].concat(_toConsumableArray(t.exceptions.specials),_toConsumableArray(i)),shift:_objectSpread(_objectSpread({},o),{},{1:[].concat(_toConsumableArray(t.exceptions.shift[1]),_toConsumableArray(o[1]))})}})};Formatter.prototype.indent=function e(r){var t=tokenize(this.__code__,true);return this._indent(t,r)};Formatter.exception_shift=function(o,e){function r(e){if(!e.length){return false}if(e.indexOf(o)!==-1){return true}else{var r=e.filter(function(e){return e instanceof RegExp});if(!r.length){return false}var t=_createForOfIteratorHelper(r),n;try{for(t.s();!(n=t.n()).done;){var i=n.value;if(o.match(i)){return true}}}catch(e){t.e(e)}finally{t.f()}}return false}if(r(e.exceptions.specials)){return e.indent}var t=e.exceptions.shift;for(var n=0,i=Object.entries(t);n0){n.offset=0}if(o.toString()===r.toString()&&balanced(o)){return n.offset+o[0].col}else if(o.length===1){return n.offset+o[0].col+1}else{var s=-1;if(a){var c=Formatter.exception_shift(a.token,n);if(c!==-1){s=c}}if(s===-1){s=Formatter.exception_shift(o[1].token,n)}if(s!==-1){return n.offset+o[0].col+s}else if(o[0].line3&&o[1].line===o[3].line){if(o[1].token==="("||o[1].token==="["){return n.offset+o[1].col}return n.offset+o[3].col}else if(o[0].line===o[1].line){return n.offset+n.indent+o[0].col}else{var l=o.slice(2);for(var f=0;f")};Ahead.prototype.match=function(e){return e.match(this.pattern)};function Pattern(){for(var e=arguments.length,r=new Array(e),t=0;t")};Formatter.Pattern=Pattern;Formatter.Ahead=Ahead;var p_o=/^[[(]$/;var p_e=/^[\])]$/;var not_p=/[^()[\]]/;var not_close=new Ahead(/[^)\]]/);var glob=Symbol["for"]("*");var sexp_or_atom=new Pattern([p_o,glob,p_e],[not_p],"+");var sexp=new Pattern([p_o,glob,p_e],"+");var symbol=new Pattern([Symbol["for"]("symbol")],"?");var symbols=new Pattern([Symbol["for"]("symbol")],"*");var identifiers=[p_o,symbols,p_e];var let_value=new Pattern([p_o,Symbol["for"]("symbol"),glob,p_e],"+");var syntax_rules=keywords_re("syntax-rules");var def_lambda_re=keywords_re("define","lambda","define-macro","syntax-rules");var non_def=/^(?!.*\b(?:[()[\]]|define(?:-macro)?|let(?:\*|rec|-env|-syntax|)?|lambda|syntax-rules)\b).*$/;var let_re=/^(?:#:)?(let(?:\*|rec|-env|-syntax)?)$/;function keywords_re(){for(var e=arguments.length,r=new Array(e),t=0;t0&&!u[e]){u[e]=previousSexp(a,e)}});var s=_createForOfIteratorHelper(i),c;try{for(s.s();!(c=s.n()).done;){var l=_slicedToArray(c.value,3),f=l[0],_=l[1],p=l[2];_=_.valueOf();var d=_>0?u[_]:a;var y=d.filter(function(e){return e.trim()&&!is_special(e)});var h=t(d);var m=match(f,y);var v=n.slice(o).find(function(e){return e.trim()&&!is_special(e)});if(m&&(p instanceof Ahead&&p.match(v)||!p)){var g=o-h;if(n[g]!=="\n"){if(!n[g].trim()){n[g]="\n"}else{n.splice(g,0,"\n");o++}}o+=h;continue e}}}catch(e){s.e(e)}finally{s.f()}}this.__code__=n.join("");return this};Formatter.prototype._spaces=function(e){return" ".repeat(e)};Formatter.prototype.format=function e(r){var t=this.__code__.replace(/[ \t]*\n[ \t]*/g,"\n ");var n=tokenize(t,true);var i=this._options(r);var o=0;var a=0;for(var u=0;u0){n=Math.floor(r()*t);t--;var i=[e[n],e[t]];e[t]=i[0];e[n]=i[1]}return e}function Nil(){}Nil.prototype.toString=function(){return"()"};Nil.prototype.valueOf=function(){return undefined};Nil.prototype.serialize=function(){return 0};Nil.prototype.to_object=function(){return{}};Nil.prototype.append=function(e){return new Pair(e,_nil)};Nil.prototype.to_array=function(){return[]};var _nil=new Nil;function Pair(e,r){if(typeof this!=="undefined"&&this.constructor!==Pair||typeof this==="undefined"){return new Pair(e,r)}this.car=e;this.cdr=r}function to_array(o,a){return function e(r){typecheck(o,r,["pair","nil"]);if(is_nil(r)){return[]}var t=[];var n=r;while(true){if(is_pair(n)){if(n.have_cycles("cdr")){break}var i=n.car;if(a&&is_pair(i)){i=this.get(o).call(this,i)}t.push(i);n=n.cdr}else if(is_nil(n)){break}else{throw new Error("".concat(o,": can't convert improper list"))}}return t}}Pair.prototype.flatten=function(){return Pair.fromArray(flatten(this.to_array()))};Pair.prototype.length=function(){var e=0;var r=this;while(true){if(!r||is_nil(r)||!is_pair(r)||r.have_cycles("cdr")){break}e++;r=r.cdr}return e};Pair.match=function(e,r){if(e instanceof LSymbol){return LSymbol.is(e,r)}else if(is_pair(e)){return Pair.match(e.car,r)||Pair.match(e.cdr,r)}else if(Array.isArray(e)){return e.some(function(e){return Pair.match(e,r)})}else if(is_plain_object(e)){return Object.values(e).some(function(e){return Pair.match(e,r)})}return false};Pair.prototype.find=function(e){return Pair.match(this,e)};Pair.prototype.clone=function(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var n=new Map;function i(e){if(is_pair(e)){if(n.has(e)){return n.get(e)}var r=new Pair;n.set(e,r);if(t){r.car=i(e.car)}else{r.car=e.car}r.cdr=i(e.cdr);r[__cycles__]=e[__cycles__];return r}return e}return i(this)};Pair.prototype.last_pair=function(){var e=this;while(true){if(!is_pair(e.cdr)){return e}if(e.have_cycles("cdr")){break}e=e.cdr}};Pair.prototype.to_array=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var r=[];if(is_pair(this.car)){if(e){r.push(this.car.to_array())}else{r.push(this.car)}}else{r.push(this.car.valueOf())}if(is_pair(this.cdr)){r=r.concat(this.cdr.to_array(e))}return r};Pair.fromArray=function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(is_pair(e)||t&&e instanceof Array&&e[__data__]){return e}if(r===false){var n=_nil;for(var i=e.length;i--;){n=new Pair(e[i],n)}return n}if(e.length&&!(e instanceof Array)){e=_toConsumableArray(e)}var o=_nil;var a=e.length;while(a--){var u=e[a];if(u instanceof Array){u=Pair.fromArray(u,r,t)}else if(typeof u==="string"){u=LString(u)}else if(typeof u==="number"&&!Number.isNaN(u)){u=LNumber(u)}o=new Pair(u,o)}return o};Pair.prototype.to_object=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var r=this;var t={};while(true){if(is_pair(r)&&is_pair(r.car)){var n=r.car;var i=n.car;if(i instanceof LSymbol){i=i.__name__}if(i instanceof LString){i=i.valueOf()}var o=n.cdr;if(is_pair(o)){o=o.to_object(e)}if(is_native(o)){if(!e){o=o.valueOf()}}t[i]=o;r=r.cdr}else{break}}return t};Pair.fromPairs=function(e){return e.reduce(function(e,r){return new Pair(new Pair(new LSymbol(r[0]),r[1]),e)},_nil)};Pair.fromObject=function(r){var e=Object.keys(r).map(function(e){return[e,r[e]]});return Pair.fromPairs(e)};Pair.prototype.reduce=function(e){var r=this;var t=_nil;while(true){if(!is_nil(r)){t=e(t,r.car);r=r.cdr}else{break}}return t};Pair.prototype.reverse=function(){if(this.have_cycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var r=_nil;while(!is_nil(e)){var t=e.cdr;e.cdr=r;r=e;e=t}return r};Pair.prototype.transform=function(n){function i(e){if(is_pair(e)){if(e.replace){delete e.replace;return e}var r=n(e.car);if(is_pair(r)){r=i(r)}var t=n(e.cdr);if(is_pair(t)){t=i(t)}return new Pair(r,t)}return e}return i(this)};Pair.prototype.map=function(e){if(typeof this.car!=="undefined"){return new Pair(e(this.car),is_nil(this.cdr)?_nil:this.cdr.map(e))}else{return _nil}};var repr=new Map;function is_plain_object(e){return e&&_typeof$1(e)==="object"&&e.constructor===Object}var props=Object.getOwnPropertyNames(Array.prototype);var array_methods=[];props.forEach(function(e){array_methods.push(Array[e],Array.prototype[e])});function is_array_method(e){e=unbind(e);return array_methods.includes(e)}function is_lips_function(e){return is_function(e)&&(is_lambda(e)||e.__doc__)}function user_repr(t){var e=t.constructor||Object;var n=is_plain_object(t);var i=is_function(t[Symbol.asyncIterator])||is_function(t[Symbol.iterator]);var o;if(repr.has(e)){o=repr.get(e)}else{repr.forEach(function(e,r){r=unbind(r);if(t instanceof r&&(r===Object&&n&&!i||r!==Object)){o=e}})}return o}var str_mapping=new Map;[[true,"#t"],[false,"#f"],[null,"#null"],[undefined,"#void"]].forEach(function(e){var r=_slicedToArray(e,2),t=r[0],n=r[1];str_mapping.set(t,n)});function symbolize(t){if(t&&_typeof$1(t)==="object"){var n={};var e=Object.getOwnPropertySymbols(t);e.forEach(function(e){var r=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");n[r]=toString(t[e])});var r=Object.getOwnPropertyNames(t);r.forEach(function(e){var r=t[e];if(r&&_typeof$1(r)==="object"&&r.constructor===Object){n[e]=symbolize(r)}else{n[e]=toString(r)}});return n}return t}function get_props(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function has_own_function(e,r){return e.hasOwnProperty(r)&&is_function(e.toString)}function function_to_string(e){if(is_native_function(e)){return"#"}var r=e.prototype&&e.prototype.constructor;if(is_function(r)&&is_lambda(r)){if(e[__class__]&&r.hasOwnProperty("__name__")){var t=r.__name__;if(LString.isString(t)){t=t.toString();return"#")}return"#"}}if(e.hasOwnProperty("__name__")){var n=e.__name__;if(_typeof$1(n)==="symbol"){n=symbol_to_string(n)}if(typeof n==="string"){return"#")}}if(has_own_function(e,"toString")){return e.toString()}else if(e.name&&!is_lambda(e)){return"#")}else{return"#"}}var instances=new Map;[[Error,function(e){return e.message}],[Pair,function(e,r){var t=r.quote,n=r.skip_cycles,i=r.pair_args;if(!n){e.mark_cycles()}return e.toString.apply(e,[t].concat(_toConsumableArray(i)))}],[LCharacter,function(e,r){var t=r.quote;if(t){return e.toString()}return e.valueOf()}],[LString,function(e,r){var t=r.quote;e=e.toString();if(t){return JSON.stringify(e).replace(/\\n/g,"\n")}return e}],[RegExp,function(e){return"#"+e.toString()}]].forEach(function(e){var r=_slicedToArray(e,2),t=r[0],n=r[1];instances.set(t,n)});var native_types=[LSymbol,Macro,Values,InputPort,OutputPort,Environment,QuotedPromise];function toString(e,r,t){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(str_mapping.has(e)){return str_mapping.get(e)}if(is_prototype(e)){return"#"}if(e){var n=e.constructor;if(instances.has(n)){for(var i=arguments.length,o=new Array(i>3?i-3:0),a=3;a"}if(e===null){return"null"}if(is_function(e)){if(is_function(e.toString)&&e.hasOwnProperty("toString")){return e.toString().valueOf()}return function_to_string(e)}if(_typeof$1(e)==="object"){var l=e.constructor;if(!l){l=Object}var f;if(typeof l.__class__==="string"){f=l.__class__}else{var _=user_repr(e);if(_){if(is_function(_)){return _(e,r)}else{throw new Error("toString: Invalid repr value")}}f=l.name}if(is_function(e.toString)&&e.hasOwnProperty("toString")){return e.toString().valueOf()}if(type(e)==="instance"){if(is_lambda(l)&&l.__name__){f=l.__name__.valueOf()}else if(!is_native_function(l)){f="instance"}}if(is_iterator(e,Symbol.iterator)){if(f){return"#")}return"#"}if(is_iterator(e,Symbol.asyncIterator)){if(f){return"#")}return"#"}if(f!==""){return"#<"+f+">"}return"#"}if(typeof e!=="string"){return e.toString()}return e}Pair.prototype.mark_cycles=function(){mark_cycles(this);return this};Pair.prototype.have_cycles=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(!e){return this.have_cycles("car")||this.have_cycles("cdr")}return!!(this[__cycles__]&&this[__cycles__][e])};Pair.prototype.is_cycle=function(){return is_cycle(this)};function is_cycle(e){if(!is_pair(e)){return false}if(e.have_cycles()){return true}return is_cycle(e.car,fn)||is_cycle(e.cdr,fn)}function mark_cycles(e){var r=[];var i=[];var o=[];function a(e){if(!r.includes(e)){r.push(e)}}function u(e,r,t,n){if(is_pair(t)){if(n.includes(t)){if(!o.includes(t)){o.push(t)}if(!e[__cycles__]){e[__cycles__]={}}e[__cycles__][r]=t;if(!i.includes(e)){i.push(e)}return true}}}var s=trampoline(function e(r,t){if(is_pair(r)){delete r.ref;delete r[__cycles__];a(r);t.push(r);var n=u(r,"car",r.car,t);var i=u(r,"cdr",r.cdr,t);if(!n){s(r.car,t.slice())}if(!i){return new Thunk(function(){return e(r.cdr,t.slice())})}}});function t(e,r){if(is_pair(e[__cycles__][r])){var t=n.indexOf(e[__cycles__][r]);e[__cycles__][r]="#".concat(t,"#")}}s(e,[]);var n=r.filter(function(e){return o.includes(e)});n.forEach(function(e,r){e[__ref__]="#".concat(r,"=")});i.forEach(function(e){t(e,"car");t(e,"cdr")})}Pair.prototype.toString=function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},t=r.nested,n=t===void 0?false:t;var i=[];if(this[__ref__]){i.push(this[__ref__]+"(")}else if(!n){i.push("(")}var o;if(this[__cycles__]&&this[__cycles__].car){o=this[__cycles__].car}else{o=toString(this.car,e,true)}if(o!==undefined){i.push(o)}if(is_pair(this.cdr)){if(this[__cycles__]&&this[__cycles__].cdr){i.push(" . ");i.push(this[__cycles__].cdr)}else{if(this.cdr[__ref__]){i.push(" . ")}else{i.push(" ")}var a=this.cdr.toString(e,{nested:true});i.push(a)}}else if(!is_nil(this.cdr)){i=i.concat([" . ",toString(this.cdr,e,true)])}if(!n||this[__ref__]){i.push(")")}return i.join("")};Pair.prototype.set=function(e,r){this[e]=r;if(is_pair(r)){this.mark_cycles()}};Pair.prototype.append=function(e){if(e instanceof Array){return this.append(Pair.fromArray(e))}var r=this;if(r.car===undefined){if(is_pair(e)){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(!is_nil(e)){while(true){if(is_pair(r)&&!is_nil(r.cdr)){r=r.cdr}else{break}}r.cdr=e}return this};Pair.prototype.serialize=function(){return[this.car,this.cdr]};Pair.prototype[Symbol.iterator]=function(){var t=this;return{next:function e(){var r=t;t=r.cdr;if(is_nil(r)){return{value:undefined,done:true}}else{return{value:r.car,done:false}}}}};function abs(e){return e<0?-e:e}function seq_compare(e,r){var t=_toArray(r),n=t[0],i=t.slice(1);while(i.length>0){var o=i,a=_slicedToArray(o,1),u=a[0];if(!e(n,u)){return false}var s=i;var c=_toArray(s);n=c[0];i=c.slice(1)}return true}function equal(e,r){if(is_function(e)){return is_function(r)&&unbind(e)===unbind(r)}else if(e instanceof LNumber){if(!(r instanceof LNumber)){return false}var t;if(e.__type__===r.__type__){if(e.__type__==="complex"){t=e.__im__.__type__===r.__im__.__type__&&e.__re__.__type__===r.__re__.__type__}else{t=true}if(t&&e.cmp(r)===0){if(e.valueOf()===0){return Object.is(e.valueOf(),r.valueOf())}return true}}return false}else if(typeof e==="number"){if(typeof r!=="number"){return false}if(Number.isNaN(e)){return Number.isNaN(r)}if(e===Number.NEGATIVE_INFINITY){return r===Number.NEGATIVE_INFINITY}if(e===Number.POSITIVE_INFINITY){return r===Number.POSITIVE_INFINITY}return equal(LNumber(e),LNumber(r))}else if(e instanceof LCharacter){if(!(r instanceof LCharacter)){return false}return e.__char__===r.__char__}else{return e===r}}function same_atom(e,r){if(type(e)!==type(r)){return false}if(!is_atom(e)){return false}if(e instanceof RegExp){return e.source===r.source}if(e instanceof LString){return e.valueOf()===r.valueOf()}return equal(e,r)}function is_atom(e){return e instanceof LSymbol||LString.isString(e)||is_nil(e)||e===null||e instanceof LCharacter||e instanceof LNumber||e===true||e===false}var truncate=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e===0){return 0}else if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function Macro(e,r,t,n){if(typeof this!=="undefined"&&this.constructor!==Macro||typeof this==="undefined"){return new Macro(e,r)}typecheck("Macro",e,"string",1);typecheck("Macro",r,"function",2);if(t){if(n){this.__doc__=t}else{this.__doc__=trim_lines(t)}}this.__name__=e;this.__fn__=r}Macro.defmacro=function(e,r,t,n){var i=new Macro(e,r,t,n);i.__defmacro__=true;return i};Macro.prototype.invoke=function(e,r,t){var n=r.env,i=_objectWithoutProperties(r,_excluded2);var o=_objectSpread(_objectSpread({},i),{},{macro_expand:t});var a=this.__fn__.call(n,e,o,this.__name__);return a};Macro.prototype.toString=function(){return"#")};var macro="define-macro";var recur_guard=-1e4;function macro_expand(c){return function(){var t=_asyncToGenerator(_regeneratorRuntime.mark(function e(t,v){var o,g,n,i,a,b,P,w,D,x,L,E,u,S,s;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:s=function e(){s=_asyncToGenerator(_regeneratorRuntime.mark(function e(t,n,i){var o,a,u,s,c,l,f,_,p,d,y,h,m;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:if(!(is_pair(t)&&t.car instanceof LSymbol)){r.next=50;break}if(!t[__data__]){r.next=3;break}return r.abrupt("return",t);case 3:o=t.car.valueOf();a=i.get(t.car,{throwError:false});u=b(t.car);s=u||P(a,t)||w(a);if(!(s&&is_pair(t.cdr.car))){r.next=28;break}if(!u){r.next=15;break}g=x(t.cdr.car);r.next=12;return E(t.cdr.car,n);case 12:c=r.sent;r.next=17;break;case 15:g=D(t.cdr.car);c=t.cdr.car;case 17:r.t0=Pair;r.t1=t.car;r.t2=Pair;r.t3=c;r.next=23;return S(t.cdr.cdr,n,i);case 23:r.t4=r.sent;r.t5=new r.t2(r.t3,r.t4);return r.abrupt("return",new r.t0(r.t1,r.t5));case 28:if(!L(o,a)){r.next=50;break}l=a instanceof Syntax?t:t.cdr;r.next=32;return a.invoke(l,_objectSpread(_objectSpread({},v),{},{env:i}),true);case 32:f=r.sent;if(!(a instanceof Syntax)){r.next=41;break}_=f,p=_.expr,d=_.scope;if(!is_pair(p)){r.next=40;break}if(!(n!==-1&&n<=1||n")}return"#"};var SyntaxParameter=_createClass(function e(r){_classCallCheck(this,e);read_only(this,"_syntax",r,{hidden:true});read_only(this._syntax,"_param",true,{hidden:true})});Syntax.Parameter=SyntaxParameter;function extract_patterns(e,r,B,I){var t=arguments.length>4&&arguments[4]!==undefined?arguments[4]:{};var j={"...":{symbols:{},lists:[]},symbols:{}};var R=t.expansion,T=t.define;log(B);function M(r,e){var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:false;log({code:e,pattern:r});if(is_atom(r)&&!(r instanceof LSymbol)){return same_atom(r,e)}if(r instanceof LSymbol&&B.includes(r.literal())){if(!LSymbol.is(e,r)){return false}var i=R.ref(r);return!i||i===T||i===global_env}if(Array.isArray(r)&&Array.isArray(e)){log("<<< a 1");if(r.length===0&&e.length===0){return true}if(LSymbol.is(r[1],I)){if(r[0]instanceof LSymbol){var o=r[0].valueOf();log("<<< a 2 "+n);if(n){var a=e.length-2;var u=a>0?e.slice(0,a):e;var s=Pair.fromArray(u,false);if(!j["..."].symbols[o]){j["..."].symbols[o]=new Pair(s,_nil)}else{j["..."].symbols[o].append(new Pair(s,_nil))}}else{j["..."].symbols[o]=Pair.fromArray(e,false)}}else if(Array.isArray(r[0])){log("<<< a 3");var c=_toConsumableArray(t);if(!e.every(function(e){return M(r[0],e,c,true)})){return false}}if(r.length>2){var l=r.slice(2);return M(l,e.slice(-l.length),t,n)}return true}var f=M(r[0],e[0],t,n);log({first:f,pattern:r[0],code:e[0]});var _=M(r.slice(1),e.slice(1),t,n);log({first:f,rest:_});return f&&_}if(is_pair(r)&&is_pair(r.car)&&is_pair(r.car.cdr)&&LSymbol.is(r.car.cdr.car,I)){log(">> 0");if(is_nil(e)){log({pattern:r});if(r.car.car instanceof LSymbol){var p=r.car.car.valueOf();if(j["..."].symbols[p]){throw new Error("syntax: named ellipsis can only "+"appear onces")}j["..."].symbols[p]=e}}}if(is_pair(r)&&is_pair(r.cdr)&&LSymbol.is(r.cdr.car,I)){if(!is_nil(r.cdr.cdr)){if(is_pair(r.cdr.cdr)){var d=r.cdr.cdr.length();if(!is_pair(e)){return false}var y=e.length();var h=e;while(y-1>d){h=h.cdr;y--}var m=h.cdr;h.cdr=_nil;if(!M(r.cdr.cdr,m,t,n)){return false}}}if(r.car instanceof LSymbol){var v=r.car.__name__;if(j["..."].symbols[v]&&!t.includes(v)&&!n){throw new Error("syntax: named ellipsis can only appear onces")}log(">> 1");if(is_nil(e)){log(">> 2");if(n){log("NIL");j["..."].symbols[v]=_nil}else{log("NULL");j["..."].symbols[v]=null}}else if(is_pair(e)&&(is_pair(e.car)||is_nil(e.car))){log(">> 3 "+n);if(n){if(j["..."].symbols[v]){var g=j["..."].symbols[v];if(is_nil(g)){g=new Pair(_nil,new Pair(e,_nil))}else{g=g.append(new Pair(e,_nil))}j["..."].symbols[v]=g}else{j["..."].symbols[v]=new Pair(e,_nil)}}else{log(">> 4");j["..."].symbols[v]=new Pair(e,_nil)}}else{log(">> 6");if(is_pair(e)){if(!is_pair(e.cdr)&&!is_nil(e.cdr)){log(">> 7 (b)");if(is_nil(r.cdr.cdr)){return false}else if(!j["..."].symbols[v]){j["..."].symbols[v]=new Pair(e.car,_nil);return M(r.cdr.cdr,e.cdr)}}var b=e.last_pair();if(!is_nil(b.cdr)){if(is_nil(r.cdr.cdr)){return false}else{var P=e.clone();P.last_pair().cdr=_nil;j["..."].symbols[v]=P;return M(r.cdr.cdr,b.cdr)}}log(">> 7 "+n);t.push(v);if(!j["..."].symbols[v]){j["..."].symbols[v]=new Pair(e,_nil)}else{var w=j["..."].symbols[v];j["..."].symbols[v]=w.append(new Pair(e,_nil))}log({IIIIII:j["..."].symbols[v]})}else if(r.car instanceof LSymbol&&is_pair(r.cdr)&&LSymbol.is(r.cdr.car,I)){log(">> 8");j["..."].symbols[v]=null;return M(r.cdr.cdr,e)}else{log(">> 9");return false}}return true}else if(is_pair(r.car)){var D=_toConsumableArray(t);if(is_nil(e)){log(">> 10");j["..."].lists.push(_nil);return true}log(">> 11");var x=e;while(is_pair(x)){if(!M(r.car,x.car,D,true)){return false}x=x.cdr}return true}if(Array.isArray(r.car)){var D=_toConsumableArray(t);var L=e;while(is_pair(L)){if(!M(r.car,L.car,D,true)){return false}L=L.cdr}return true}return false}if(r instanceof LSymbol){if(LSymbol.is(r,I)){throw new Error("syntax: invalid usage of ellipsis")}log(">> 12");var E=r.__name__;if(B.includes(E)){return true}if(n){var S,A;log(j["..."].symbols[E]);(A=(S=j["..."].symbols)[E])!==null&&A!==void 0?A:S[E]=[];j["..."].symbols[E].push(e)}else{j.symbols[E]=e}return true}if(is_pair(r)&&is_pair(e)){log(">> 13");log({a:13,code:e,pattern:r});if(is_nil(e.cdr)){var F=r.car instanceof LSymbol&&r.cdr instanceof LSymbol;if(F){if(!M(r.car,e.car,t,n)){return false}log(">> 14");var k=r.cdr.valueOf();if(!(k in j.symbols)){j.symbols[k]=_nil}k=r.car.valueOf();if(!(k in j.symbols)){j.symbols[k]=e.car}return true}}log({pattern:r,code:e});if(is_pair(r.cdr)&&is_pair(r.cdr.cdr)&&r.cdr.car instanceof LSymbol&&LSymbol.is(r.cdr.cdr.car,I)&&is_pair(r.cdr.cdr.cdr)&&!LSymbol.is(r.cdr.cdr.cdr.car,I)&&M(r.car,e.car,t,n)&&M(r.cdr.cdr.cdr,e.cdr,t,n)){var C=r.cdr.car.__name__;log({pattern:r,code:e,name:C});if(B.includes(C)){return true}j["..."].symbols[C]=null;return true}log("recur");log({pattern:r,code:e});var O=M(r.car,e.car,t,n);log({car:O,pattern:r.car,code:e.car});var N=M(r.cdr,e.cdr,t,n);log({car:O,cdr:N});if(O&&N){return true}}else if(is_nil(r)&&(is_nil(e)||e===undefined)){return true}else if(is_pair(r.car)&&LSymbol.is(r.car.car,I)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(M(e,r)){return j}}function clear_gensyms(e,i){function o(r){if(is_pair(r)){if(!i.length){return r}var e=o(r.car);var t=o(r.cdr);return new Pair(e,t)}else if(r instanceof LSymbol){var n=i.find(function(e){return e.gensym===r});if(n){return LSymbol(n.name)}return r}else{return r}}return o(e)}function transform_syntax(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var O=e.bindings,r=e.expr,N=e.scope,a=e.symbols,l=e.names,B=e.ellipsis;var f={};function u(e){if(e instanceof LSymbol){return true}return["string","symbol"].includes(_typeof$1(e))}function I(e){if(!u(e)){var r=type(e);throw new Error("syntax: internal error, need symbol got ".concat(r))}var t=e.valueOf();if(t===B){throw new Error("syntax: internal error, ellipis not transformed")}var n=_typeof$1(t);if(["string","symbol"].includes(n)){if(t in O.symbols){return O.symbols[t]}else if(n==="string"&&t.match(/\./)){var i=t.split(".");var o=i[0];if(o in O.symbols){return Pair.fromArray([LSymbol("."),O.symbols[o]].concat(i.slice(1).map(function(e){return LString(e)})))}}}if(a.includes(t)){return e}return s(t,e)}function s(e,r){if(!f[e]){var t=N.ref(e);if(_typeof$1(e)==="symbol"&&!t){e=r.literal()}if(f[e]){return f[e]}var n=gensym(e);if(t){var i=N.get(e);N.set(n,i)}else{var o=N.get(e,{throwError:false});if(typeof o!=="undefined"){N.set(n,o)}}l.push({name:e,gensym:n});f[e]=n;if(typeof e==="string"&&e.match(/\./)){var a=e.split(".").filter(Boolean),u=_toArray(a),s=u[0],c=u.slice(1);if(f[s]){hidden_prop(n,"__object__",[f[s]].concat(_toConsumableArray(c)))}}}return f[e]}function j(e,r,t){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:function(){};var i=t.nested;log({bindings:r,expr:e});if(Array.isArray(e)&&!e.length){return e}if(e instanceof LSymbol){var o=e.valueOf();if(is_gensym(e)&&!r[o]);log("[t 1");if(r[o]){if(is_pair(r[o])){var a=r[o],u=a.car,s=a.cdr;if(i){var c=u.car,l=u.cdr;if(!is_nil(l)){n(o,new Pair(l,_nil))}return c}if(!is_nil(s)){n(o,s)}return u}else if(r[o]instanceof Array){n(o,r[o].slice(1));return r[o][0]}}return I(e)}var f=Array.isArray(e);if(is_pair(e)||f){var _=f?e[0]:e.car;var p=f?e[1]:is_pair(e.cdr)&&e.cdr.car;if(_ instanceof LSymbol&&LSymbol.is(p,B)){f?e.slice(2):e.cdr.cdr;log("[t 2");var d=_.valueOf();var y=r[d];if(y===null){return}else if(y){log({name:d,binding:r[d]});if(is_pair(y)){log("[t 2 Pair "+i);var h=y.car,m=y.cdr;var v=f?e.slice(2):e.cdr.cdr;if(i){if(!is_nil(m)){log("|| next 1");n(d,m)}if(f&&v.length||!is_nil(v)&&!f){var g=j(v,r,t,n);if(f){return h.concat(g)}else if(is_pair(h)){return h.append(g)}else{log("UNKNOWN")}}return h}else if(is_pair(h)){if(!is_nil(h.cdr)){log("|| next 2");n(d,new Pair(h.cdr,m))}return h.car}else if(is_nil(m)){return h}else{var b=e.last_pair();if(b.cdr instanceof LSymbol){log("|| next 3");n(d,y.last_pair());return h}}}else if(y instanceof Array){log("[t 2 Array "+i);if(i){n(d,y.slice(1));return Pair.fromArray(y)}else{var P=y.slice(1);if(P.length){n(d,P)}return y[0]}}else{return y}}}log("[t 3 recur ",e);var w=f?e.slice(1):e.cdr;var D=j(_,r,t,n);var x=j(w,r,t,n);log({head:D,rest:x});if(f){return[D].concat(x)}return new Pair(D,x)}return e}function R(r,t){var e=Object.values(r);var n=Object.getOwnPropertySymbols(r);if(n.length){e.push.apply(e,_toConsumableArray(n.map(function(e){return r[e]})))}return e.length&&e.every(function(e){if(e===null){return!t}return is_pair(e)||is_nil(e)||Array.isArray(e)&&e.length})}function T(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function M(i){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=e.disabled;log("traverse>> ",i);var o=Array.isArray(i);if(o&&i.length===0){return i}if(is_pair(i)||o){var t=o?i[0]:i.car;var n,a;if(o){n=i[1];a=i.slice(2)}else if(is_pair(i.cdr)){n=i.cdr.car;a=i.cdr.cdr}log({first:t,second:n,rest_second:a});if(!r&&is_pair(t)&&LSymbol.is(t.car,B)){return new Pair(t.cdr.car,M(i.cdr))}if(n&&LSymbol.is(n,B)&&!r){log(">> 1");var u=O["..."].symbols;var s=Object.values(u);if(s.length&&s.every(function(e){return e===null})){log(">>> 1 (a)");return M(a,{disabled:r})}var c=T(u);var l=t instanceof LSymbol&&LSymbol.is(a.car,B);if(is_pair(t)||l){log(">>> 1 (b)");if(is_nil(O["..."].lists[0])){if(!l){return M(a,{disabled:r})}log(a);return _nil}var f=t;if(l){log(">>> 1 (c)");f=new Pair(t,new Pair(n,_nil))}log(">> 2");var _;if(c.length){log(">> 2 (a)");var p=_objectSpread({},u);_=o?[]:_nil;var d=function e(){log({bind:p});if(!R(p)){return 1}var n={};var r=function e(r,t){n[r]=t};var t=j(f,p,{nested:true},r);if(t!==undefined){if(l){if(o){if(Array.isArray(t)){var i;(i=_).push.apply(i,_toConsumableArray(t))}else{log("ZONK {1}")}}else{if(is_nil(_)){_=t}else{_=_.append(t)}}}else if(o){_.push(t)}else{_=new Pair(t,_)}}p=n};while(true){if(d())break}if(!is_nil(_)&&!l&&!o){_=_.reverse()}if(o){if(a){log({rest_second:a,expr:i});var y=M(a,{disabled:r});return _.concat(y)}return _}if(!is_nil(i.cdr.cdr)&&!LSymbol.is(i.cdr.cdr.car,B)){var h=M(i.cdr.cdr,{disabled:r});return _.append(h)}return _}else{log(">> 3");var m=j(t,u,{nested:true});if(m){return new Pair(m,_nil)}return _nil}}else if(t instanceof LSymbol){log(">> 4");if(LSymbol.is(a.car,B)){log(">> 4 (a)")}else{log(">> 4 (b)")}var v=t.__name__;var g=_defineProperty({},v,u[v]);log({bind:g});var b=u[v]===null;var P=o?[]:_nil;var w=function e(){if(!R(g,true)){log({bind:g});return 1}var n={};var r=function e(r,t){n[r]=t};var t=j(i,g,{nested:false},r);log({value:t});if(typeof t!=="undefined"){if(o){P.push(t)}else{P=new Pair(t,P)}}g=n};while(true){if(w())break}if(!is_nil(P)&&!o){P=P.reverse()}if(is_pair(i.cdr)){if(is_pair(i.cdr.cdr)||i.cdr.cdr instanceof LSymbol){var D=M(i.cdr.cdr,{disabled:r});log({node:D});if(b){return D}if(is_nil(P)){P=D}else{P.append(D)}log({result:P,node:D})}}log("<<<< 2");return P}}var x=M(t,{disabled:r});var L;var E;if(t instanceof LSymbol){var S=N.get(t,{throwError:false});E=S instanceof Macro&&S.__name__==="syntax-rules"}if(E){if(i.cdr.car instanceof LSymbol){L=new Pair(M(i.cdr.car,{disabled:r}),new Pair(i.cdr.cdr.car,M(i.cdr.cdr.cdr,{disabled:r})))}else{L=new Pair(i.cdr.car,M(i.cdr.cdr,{disabled:r}))}log("REST >>>> ",L)}else{L=M(i.cdr,{disabled:r})}log({a:true,car:toString(i.car),cdr:toString(i.cdr),head:toString(x),rest:toString(L)});return new Pair(x,L)}if(i instanceof LSymbol){if(r&&LSymbol.is(i,B)){return i}var A=Object.keys(O["..."].symbols);var F=i.literal();if(A.includes(F)){var k="missing ellipsis symbol next to name `".concat(F,"'");throw new Error("syntax-rules: ".concat(k))}var C=I(i);if(typeof C!=="undefined"){return C}}return i}return M(r,{})}function is_null(e){return is_undef(e)||is_nil(e)||e===null}function is_nil(e){return e===_nil}function is_function(e){return typeof e==="function"&&typeof e.bind==="function"}function is_directive(e){return directives.includes(e)}function is_false(e){return e===false||e===null}function is_string(e){return typeof e==="string"}function is_prototype(e){return e&&_typeof$1(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}function is_continuation(e){return e instanceof Continuation}function is_context(e){return e instanceof LambdaContext}function is_parameter(e){return e instanceof Parameter}function is_pair(e){return e instanceof Pair}function is_env(e){return e instanceof Environment}function is_callable(e){return is_function(e)||is_continuation(e)||is_parameter(e)||is_macro(e)}function is_macro(e){return e instanceof Macro||e instanceof SyntaxParameter}function is_promise(e){if(e instanceof QuotedPromise){return false}if(e instanceof Promise){return true}return!!e&&is_function(e.then)}function is_undef(e){return typeof e==="undefined"}function is_iterator(e,r){if(has_own_symbol(e,r)||has_own_symbol(e.__proto__,r)){return is_function(e[r])}}function is_instance(e){if(!e){return false}if(_typeof$1(e)!=="object"){return false}if(e.__instance__){e.__instance__=false;return e.__instance__}return false}function self_evaluated(e){var r=_typeof$1(e);return["string","function"].includes(r)||_typeof$1(e)==="symbol"||e instanceof QuotedPromise||e instanceof LSymbol||e instanceof LNumber||e instanceof LString||e instanceof RegExp}function is_native(e){return e instanceof LNumber||e instanceof LString||e instanceof LCharacter}function has_own_symbol(e,r){if(e===null){return false}return _typeof$1(e)==="object"&&r in Object.getOwnPropertySymbols(e)}function box(e){switch(_typeof$1(e)){case"string":return LString(e);case"bigint":return LNumber(e);case"number":if(Number.isNaN(e)){return nan}else{return LNumber(e)}}return e}function map_object(t,n){var e=Object.getOwnPropertyNames(t);var r=Object.getOwnPropertySymbols(t);var i={};e.concat(r).forEach(function(e){var r=n(t[e]);i[e]=r});return i}function unbox(r){var e=[LString,LNumber,LCharacter].some(function(e){return r instanceof e});if(e){return r.valueOf()}if(r instanceof Array){return r.map(unbox)}if(r instanceof QuotedPromise){delete r.then}if(is_plain_object(r)){return map_object(r,unbox)}return r}function patch_value(e,r){if(is_pair(e)){e.mark_cycles();return quote(e)}if(is_function(e)){if(r){return bind(e,r)}}return box(e)}function unbind(e){if(is_bound(e)){return e[__fn__]}return e}function bind(e,r){if(e[Symbol["for"]("__bound__")]){return e}var t=e.bind(r);var n=Object.getOwnPropertyNames(e);var i=_createForOfIteratorHelper(n),o;try{for(i.s();!(o=i.n()).done;){var a=o.value;if(filter_fn_names(a)){try{t[a]=e[a]}catch(e){}}}}catch(e){i.e(e)}finally{i.f()}hidden_prop(t,"__fn__",e);hidden_prop(t,"__context__",r);hidden_prop(t,"__bound__",true);if(is_native_function(e)){hidden_prop(t,"__native__",true)}if(is_plain_object(r)&&is_lambda(e)){hidden_prop(t,"__method__",true)}t.valueOf=function(){return e};return t}function is_object_bound(e){return is_bound(e)&&e[Symbol["for"]("__context__")]===Object}function is_bound(e){return!!(is_function(e)&&e[__fn__])}function lips_context(e){if(is_function(e)){var r=e[__context__];if(r&&(r===lips||r.constructor&&r.constructor.__class__)){return true}}return false}function is_port(e){return e instanceof InputPort||e instanceof OutputPort}function is_port_method(e){if(is_function(e)){if(is_port(e[__context__])){return true}}return false}var __context__=Symbol["for"]("__context__");var __fn__=Symbol["for"]("__fn__");var __data__=Symbol["for"]("__data__");var __ref__=Symbol["for"]("__ref__");var __cycles__=Symbol["for"]("__cycles__");var __class__=Symbol["for"]("__class__");var __method__=Symbol["for"]("__method__");var __prototype__=Symbol["for"]("__prototype__");var __lambda__=Symbol["for"]("__lambda__");var exluded_names=["name","length","caller","callee","arguments","prototype"];function filter_fn_names(e){return!exluded_names.includes(e)}function hidden_prop(e,r,t){Object.defineProperty(e,Symbol["for"](r),{get:function e(){return t},set:function e(){},configurable:false,enumerable:false})}function set_fn_length(r,t){try{Object.defineProperty(r,"length",{get:function e(){return t}});return r}catch(e){var n=new Array(t).fill(0).map(function(e,r){return"a"+r}).join(",");var i=new Function("f","return function(".concat(n,") {\n return f.apply(this, arguments);\n };"));return i(r)}}function is_lambda(e){return e&&e[__lambda__]}function is_method(e){return e&&e[__method__]}function is_raw_lambda(e){return is_lambda(e)&&!e[__prototype__]&&!is_method(e)&&!is_port_method(e)}function is_native_function(e){var r=Symbol["for"]("__native__");return is_function(e)&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[r]===true||!e.name.match(/^bound /)&&!e[r])}function let_macro(e){var P;switch(e){case Symbol["for"]("letrec"):P="letrec";break;case Symbol["for"]("let"):P="let";break;case Symbol["for"]("let*"):P="let*";break;default:throw new Error("Invalid let_macro value")}return Macro.defmacro(P,function(r,e){var l=e.dynamic_env;var f=e.error,t=e.macro_expand,_=e.use_dynamic;var p;if(r.car instanceof LSymbol){if(!(is_pair(r.cdr.car)||is_nil(r.cdr.car))){throw new Error("let require list of pairs")}var n;if(is_nil(r.cdr.car)){p=_nil;n=_nil}else{n=r.cdr.car.map(function(e){return e.car});p=r.cdr.car.map(function(e){return e.cdr.car})}var i=gensym("args");return Pair.fromArray([LSymbol("let"),[[i,Pair(LSymbol("list"),p)]],[LSymbol("letrec"),[[r.car,Pair(LSymbol("lambda"),Pair(n,r.cdr.cdr))]],[LSymbol("apply"),r.car,i]]])}else if(t){return}var d=this;p=global_env.get("list->array")(r.car);var y=d.inherit(P);var h,m;if(P==="let*"){m=y}else if(P==="let"){h=[]}var v=0;function g(){var e=new Pair(new LSymbol("begin"),r.cdr);return _evaluate(e,{env:y,dynamic_env:y,use_dynamic:_,error:f})}function b(e){if(e in y.__env__){throw new Error("Duplicated let variable ".concat(e))}}return function r(){var t=p[v++];l=P==="let*"?y:d;if(!t){if(h&&h.length){var e=h.map(function(e){return e.value});var n=e.filter(is_promise);if(n.length){return promise_all(e).then(function(e){for(var r=0,t=e.length;r1&&arguments[1]!==undefined?arguments[1]:{},t=r.use_dynamic,n=r.error;var i=this;var o=this;var a=[];var u=e;while(is_pair(u)){a.push(_evaluate(u.car,{env:i,dynamic_env:o,use_dynamic:t,error:n}));u=u.cdr}var s=a.filter(is_promise).length;if(s){return promise_all(a).then(c.bind(this))}else{return c.call(this,a)}})}function guard_math_call(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n2?n-2:0),o=2;o1&&arguments[1]!==undefined?arguments[1]:null;return function(){for(var e=arguments.length,r=new Array(e),t=0;t1?e-1:0),t=1;t=a){return o.apply(this,n)}else{return i}}return i.apply(this,arguments)}}function limit(n,i){typecheck("limit",i,"function",2);return function(){for(var e=arguments.length,r=new Array(e),t=0;t1){e=e.toLowerCase();if(LCharacter.__names__[e]){r=e;e=LCharacter.__names__[e]}else{throw new Error("Internal: Unknown named character")}}else{r=LCharacter.__rev_names__[e]}Object.defineProperty(this,"__char__",{value:e,enumerable:true});if(r){Object.defineProperty(this,"__name__",{value:r,enumerable:true})}}LCharacter.__names__=characters;LCharacter.__rev_names__={};Object.keys(LCharacter.__names__).forEach(function(e){var r=LCharacter.__names__[e];LCharacter.__rev_names__[r]=e});LCharacter.prototype.toUpperCase=function(){return LCharacter(this.__char__.toUpperCase())};LCharacter.prototype.toLowerCase=function(){return LCharacter(this.__char__.toLowerCase())};LCharacter.prototype.toString=function(){return"#\\"+(this.__name__||this.__char__)};LCharacter.prototype.valueOf=LCharacter.prototype.serialize=function(){return this.__char__};function LString(e){if(typeof this!=="undefined"&&!(this instanceof LString)||typeof this==="undefined"){return new LString(e)}if(e instanceof Array){this.__string__=e.map(function(e,r){typecheck("LString",e,"character",r+1);return e.toString()}).join("")}else{this.__string__=e.valueOf()}}{var ignore=["length","constructor"];var _keys=Object.getOwnPropertyNames(String.prototype).filter(function(e){return!ignore.includes(e)});var wrap=function e(n){return function(){for(var e=arguments.length,r=new Array(e),t=0;t0){t.push(this.__string__.substring(0,e))}t.push(r);if(e1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof LNumber){return e}if(typeof this!=="undefined"&&!(this instanceof LNumber)||typeof this==="undefined"){return new LNumber(e,r)}if(typeof e==="undefined"){throw new Error("Invalid LNumber constructor call")}var t=LNumber.getType(e);if(LNumber.types[t]){return LNumber.types[t](e,r)}var n=e instanceof Array&&LString.isString(e[0])&&LNumber.isNumber(e[1]);if(e instanceof LNumber){return LNumber(e.value)}if(!LNumber.isNumber(e)&&!n){throw new Error("You can't create LNumber from ".concat(type(e)))}if(e===null){e=0}var i;if(n){var o=e,a=_slicedToArray(o,2),u=a[0],s=a[1];if(u instanceof LString){u=u.valueOf()}if(s instanceof LNumber){s=s.valueOf()}var c=u.match(/^([+-])/);var l=false;if(c){u=u.replace(/^[+-]/,"");if(c[1]==="-"){l=true}}}if(Number.isNaN(e)){return LFloat(e)}else if(n&&Number.isNaN(parseInt(u,s))){return nan}else if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(n){var f;switch(s){case 8:f="0o";break;case 16:f="0x";break;case 2:f="0b";break;case 10:f="";break}if(typeof f==="undefined"){var _=BigInt(s);i=_toConsumableArray(u).map(function(e,r){return BigInt(parseInt(e,s))*pow(_,BigInt(r))}).reduce(function(e,r){return e+r})}else{i=BigInt(f+u)}}else{i=BigInt(e)}if(l){i*=BigInt(-1)}}else{i=e}return LBigInteger(i,true)}else if(typeof BN!=="undefined"&&!(e instanceof BN)){if(e instanceof Array){return LBigInteger(_construct(BN,_toConsumableArray(e)))}return LBigInteger(new BN(e))}else if(n){this.constant(parseInt(u,s),"integer")}else{this.constant(e,"integer")}}LNumber.prototype.constant=function(e,r){Object.defineProperty(this,"__value__",{value:e,enumerable:true});Object.defineProperty(this,"__type__",{value:r,enumerable:true})};LNumber.types={float:function e(r){return new LFloat(r)},complex:function e(r){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!LNumber.isComplex(r)){r={im:0,re:r}}return new LComplex(r,t)},rational:function e(r){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!LNumber.isRational(r)){r={num:r,denom:1}}return new LRational(r,t)}};LNumber.prototype.serialize=function(){return this.__value__};LNumber.prototype.isNaN=function(){return Number.isNaN(this.__value__)};LNumber.prototype.gcd=function(e){var r=this.abs();e=e.abs();if(e.cmp(r)===1){var t=r;r=e;e=t}while(true){r=r.rem(e);if(r.cmp(0)===0){return e}e=e.rem(r);if(e.cmp(0)===0){return r}}};LNumber.isFloat=function e(r){return r instanceof LFloat||Number(r)===r&&r%1!==0};LNumber.isNumber=function(e){return e instanceof LNumber||LNumber.isNative(e)||LNumber.isBN(e)};LNumber.isComplex=function(e){if(!e){return false}var r=e instanceof LComplex||(LNumber.isNumber(e.im)||LNumber.isRational(e.im)||Number.isNaN(e.im))&&(LNumber.isNumber(e.re)||LNumber.isRational(e.re)||Number.isNaN(e.re));return r};LNumber.isRational=function(e){if(!e){return false}return e instanceof LRational||LNumber.isNumber(e.num)&&LNumber.isNumber(e.denom)};LNumber.isInteger=function(e){if(!(LNumber.isNative(e)||e instanceof LNumber)){return false}if(LNumber.isFloat(e)){return false}if(LNumber.isRational(e)){return false}if(LNumber.isComplex(e)){return false}return true};LNumber.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};LNumber.isBigInteger=function(e){return e instanceof LBigInteger||typeof e==="bigint"||LNumber.isBN(e)};LNumber.isBN=function(e){return typeof BN!=="undefined"&&e instanceof BN};LNumber.getArgsType=function(e,r){if(e instanceof LFloat||r instanceof LFloat){return LFloat}if(e instanceof LBigInteger||r instanceof LBigInteger){return LBigInteger}return LNumber};LNumber.prototype.toString=function(e){if(Number.isNaN(this.__value__)){return"+nan.0"}if(e>=2&&e<36){return this.__value__.toString(e)}return this.__value__.toString()};LNumber.prototype.asType=function(e){var r=LNumber.getType(this);return LNumber.types[r]?LNumber.types[r](e):LNumber(e)};LNumber.prototype.isBigNumber=function(){return typeof this.__value__==="bigint"||typeof BN!=="undefined"&&!(this.value instanceof BN)};["floor","ceil","round"].forEach(function(e){LNumber.prototype[e]=function(){if(this["float"]||LNumber.isFloat(this.__value__)){return LNumber(Math[e](this.__value__))}else{return LNumber(Math[e](this.valueOf()))}}});LNumber.prototype.valueOf=function(){if(LNumber.isNative(this.__value__)){return Number(this.__value__)}else if(LNumber.isBN(this.__value__)){return this.__value__.toNumber()}};var matrix=function(){var e=function e(r,t){return[r,t]};return{bigint:{bigint:e,float:function e(r,t){return[LFloat(r.valueOf()),t]},rational:function e(r,t){return[{num:r,denom:1},t]},complex:function e(r,t){return[{im:0,re:r},t]}},integer:{integer:e,float:function e(r,t){return[LFloat(r.valueOf()),t]},rational:function e(r,t){return[{num:r,denom:1},t]},complex:function e(r,t){return[{im:0,re:r},t]}},float:{bigint:function e(r,t){return[r,t&&LFloat(t.valueOf())]},integer:function e(r,t){return[r,t&&LFloat(t.valueOf())]},float:e,rational:function e(r,t){return[r,t&&LFloat(t.valueOf())]},complex:function e(r,t){return[{re:r,im:LFloat(0)},t]}},complex:{bigint:r("bigint"),integer:r("integer"),float:r("float"),rational:r("rational"),complex:function e(r,t){var n=LNumber.coerce(r.__re__,t.__re__),i=_slicedToArray(n,2),o=i[0],a=i[1];var u=LNumber.coerce(r.__im__,t.__im__),s=_slicedToArray(u,2),c=s[0],l=s[1];return[{im:c,re:o},{im:l,re:a}]}},rational:{bigint:function e(r,t){return[r,t&&{num:t,denom:1}]},integer:function e(r,t){return[r,t&&{num:t,denom:1}]},float:function e(r,t){return[LFloat(r.valueOf()),t]},rational:e,complex:function e(r,t){return[{im:coerce(r.__type__,t.__im__.__type__,0)[0],re:coerce(r.__type__,t.__re__.__type__,r)[0]},{im:coerce(r.__type__,t.__im__.__type__,t.__im__)[0],re:coerce(r.__type__,t.__re__.__type__,t.__re__)[0]}]}}};function r(t){return function(e,r){return[{im:coerce(t,e.__im__.__type__,0,e.__im__)[1],re:coerce(t,e.__re__.__type__,0,e.__re__)[1]},{im:coerce(t,e.__im__.__type__,0,0)[1],re:coerce(t,r.__type__,0,r)[1]}]}}}();function coerce(e,r,t,n){return matrix[e][r](t,n)}LNumber.coerce=function(e,r){var t=LNumber.getType(e);var n=LNumber.getType(r);if(!matrix[t]){throw new Error("LNumber::coerce unknown lhs type ".concat(t))}else if(!matrix[t][n]){throw new Error("LNumber::coerce unknown rhs type ".concat(n))}var i=matrix[t][n](e,r);return i.map(function(e){return LNumber(e,true)})};LNumber.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof LNumber)){throw new Error("LNumber: you can't coerce ".concat(type(e)))}if(typeof e==="number"){e=LNumber(e)}return LNumber.coerce(this,e)};LNumber.getType=function(e){if(e instanceof LNumber){return e.__type__}if(LNumber.isFloat(e)){return"float"}if(LNumber.isComplex(e)){return"complex"}if(LNumber.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof BN!=="undefined"&&!(e instanceof BN)){return"bigint"}};LNumber.prototype.isFloat=function(){return!!(LNumber.isFloat(this.__value__)||this["float"])};var mapping={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var rev_mapping={};Object.keys(mapping).forEach(function(r){rev_mapping[mapping[r]]=r;LNumber.prototype[r]=function(e){return this.op(mapping[r],e)}});LNumber._ops={"*":function e(r,t){return r*t},"+":function e(r,t){return r+t},"-":function e(r,t){if(typeof t==="undefined"){return-r}return r-t},"/":function e(r,t){return r/t},"%":function e(r,t){return r%t},"|":function e(r,t){return r|t},"&":function e(r,t){return r&t},"~":function e(r){return~r},">>":function e(r,t){return r>>t},"<<":function e(r,t){return r<1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof LComplex)||typeof this==="undefined"){return new LComplex(e,r)}if(e instanceof LComplex){return LComplex({im:e.__im__,re:e.__re__})}if(LNumber.isNumber(e)&&r){if(!r){return Number(e)}}else if(!LNumber.isComplex(e)){var t="Invalid constructor call for LComplex expect &(:im :re ) object but got ".concat(toString(e));throw new Error(t)}var n=e.im instanceof LNumber?e.im:LNumber(e.im);var i=e.re instanceof LNumber?e.re:LNumber(e.re);this.constant(n,i)}LComplex.prototype=Object.create(LNumber.prototype);LComplex.prototype.constructor=LComplex;LComplex.prototype.constant=function(e,r){Object.defineProperty(this,"__im__",{value:e,enumerable:true});Object.defineProperty(this,"__re__",{value:r,enumerable:true});Object.defineProperty(this,"__type__",{value:"complex",enumerable:true})};LComplex.prototype.serialize=function(){return{re:this.__re__,im:this.__im__}};LComplex.prototype.toRational=function(e){var r=this.__im__,t=this.__re__;if(LNumber.isFloat(this.__im__)){r=LFloat(this.__im__).toRational(e)}if(LNumber.isFloat(this.__re__)){t=LFloat(this.__re__).toRational(e)}return LComplex({im:r,re:t})};LComplex.prototype.pow=function(e){e.cmp(0);if(e===0){return LNumber(1)}var r=LNumber(Math.atan2(this.__im__.valueOf(),this.__re__.valueOf()));var t=LNumber(this.modulus());if(LNumber.isComplex(e)&&e.__im__.cmp(0)!==0){var n=e.mul(Math.log(t.valueOf())).add(LComplex.i.mul(r).mul(e));if(!LNumber.isComplex(n)){return LFloat(Math.E).pow(n)}var i=LFloat(Math.E).pow(n.__re__.valueOf());return LComplex({re:i.mul(Math.cos(n.__im__.valueOf())),im:i.mul(Math.sin(n.__im__.valueOf()))})}var o=e.__re__.cmp(0)>0;e=e.__re__.valueOf();if(LNumber.isInteger(e)&&o){var a=this;while(--e){a=a.mul(this)}return a}var u=t.pow(e);var s=r.mul(e);return LComplex({re:u.mul(Math.cos(s)),im:u.mul(Math.sin(s))})};LComplex.prototype.add=function(e){return this.complex_op("add",e,function(e,r,t,n){return{re:e.add(r),im:t.add(n)}})};LComplex.prototype.factor=function(){if(this.__im__ instanceof LFloat||this.__im__ instanceof LFloat){var e=this.__re__,r=this.__im__;var t,n;if(e instanceof LFloat){t=e.toRational().mul(e.toRational())}else{t=e.mul(e)}if(r instanceof LFloat){n=r.toRational().mul(r.toRational())}else{n=r.mul(r)}return t.add(n)}else{return this.__re__.mul(this.__re__).add(this.__im__.mul(this.__im__))}};LComplex.prototype.modulus=function(){return this.factor().sqrt()};LComplex.prototype.conjugate=function(){return LComplex({re:this.__re__,im:this.__im__.sub()})};LComplex.prototype.sqrt=function(){var e=this.modulus();var r,t;if(e.cmp(0)===0){r=t=e}else if(this.__re__.cmp(0)===1){r=LFloat(.5).mul(e.add(this.__re__)).sqrt();t=this.__im__.div(r).div(2)}else{t=LFloat(.5).mul(e.sub(this.__re__)).sqrt();if(this.__im__.cmp(0)===-1){t=t.sub()}r=this.__im__.div(t).div(2)}return LComplex({im:t,re:r})};LComplex.prototype.div=function(e){if(LNumber.isNumber(e)&&!LNumber.isComplex(e)){if(!(e instanceof LNumber)){e=LNumber(e)}var r=this.__re__.div(e);var t=this.__im__.div(e);return LComplex({re:r,im:t})}else if(!LNumber.isComplex(e)){throw new Error("[LComplex::div] Invalid value")}if(this.cmp(e)===0){var n=this.coerce(e),i=_slicedToArray(n,2),o=i[0],a=i[1];var u=o.__im__.div(a.__im__);return u.coerce(a.__re__)[0]}var s=this.coerce(e),c=_slicedToArray(s,2),l=c[0],f=c[1];var _=f.factor();var p=f.conjugate();var d=l.mul(p);if(!LNumber.isComplex(d)){return d.div(_)}var y=d.__re__.op("/",_);var h=d.__im__.op("/",_);return LComplex({re:y,im:h})};LComplex.prototype.sub=function(e){return this.complex_op("sub",e,function(e,r,t,n){return{re:e.sub(r),im:t.sub(n)}})};LComplex.prototype.mul=function(e){return this.complex_op("mul",e,function(e,r,t,n){var i={re:e.mul(r).sub(t.mul(n)),im:e.mul(n).add(r.mul(t))};return i})};LComplex.prototype.complex_op=function(e,r,i){var o=this;var t=function e(r,t){var n=i(o.__re__,r,o.__im__,t);if("im"in n&&"re"in n){if(n.im.cmp(0)===0){return n.re}return LComplex(n,true)}return n};if(typeof r==="undefined"){return t()}if(LNumber.isNumber(r)&&!LNumber.isComplex(r)){if(!(r instanceof LNumber)){r=LNumber(r)}var n=r.asType(0);r={__im__:n,__re__:r}}else if(!LNumber.isComplex(r)){throw new Error("[LComplex::".concat(e,"] Invalid value"))}var a=r.__re__ instanceof LNumber?r.__re__:this.__re__.asType(r.__re__);var u=r.__im__ instanceof LNumber?r.__im__:this.__im__.asType(r.__im__);return t(a,u)};LComplex._op={"+":"add","-":"sub","*":"mul","/":"div"};LComplex.prototype._op=function(e,r){var t=LComplex._op[e];return this[t](r)};LComplex.prototype.cmp=function(e){var r=this.coerce(e),t=_slicedToArray(r,2),n=t[0],i=t[1];var o=n.__re__.coerce(i.__re__),a=_slicedToArray(o,2),u=a[0],s=a[1];var c=u.cmp(s);if(c!==0){return c}else{var l=n.__im__.coerce(i.__im__),f=_slicedToArray(l,2),_=f[0],p=f[1];return _.cmp(p)}};LComplex.prototype.valueOf=function(){return[this.__re__,this.__im__].map(function(e){return e.valueOf()})};LComplex.prototype.toString=function(){var e;if(this.__re__.cmp(0)!==0){e=[toString(this.__re__)]}else{e=[]}var r=this.__im__.valueOf();var t=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY].includes(r);var n=toString(this.__im__);if(!t&&!Number.isNaN(r)){var i=this.__im__.cmp(0);if(i<0||i===0&&this.__im__._minus){e.push("-")}else{e.push("+")}n=n.replace(/^-/,"")}e.push(n);e.push("i");return e.join("")};function LFloat(e){if(typeof this!=="undefined"&&!(this instanceof LFloat)||typeof this==="undefined"){return new LFloat(e)}if(!LNumber.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof LNumber){return LFloat(e.valueOf())}if(typeof e==="number"){if(Object.is(e,-0)){Object.defineProperty(this,"_minus",{value:true})}this.constant(e,"float")}}LFloat.prototype=Object.create(LNumber.prototype);LFloat.prototype.constructor=LFloat;LFloat.prototype.toString=function(e){if(this.__value__===Number.NEGATIVE_INFINITY){return"-inf.0"}if(this.__value__===Number.POSITIVE_INFINITY){return"+inf.0"}if(Number.isNaN(this.__value__)){return"+nan.0"}e&&(e=e.valueOf());var r=this.__value__.toString(e);if(!r.match(/e[+-]?[0-9]+$/i)){var t=r.replace(/^-/,"");var n=this.__value__<0?"-":"";if(r.match(/^-?0\.0{3}/)){var i=t.match(/^[.0]+/g)[0].length-1;var o=t.replace(/^[.0]+/,"").replace(/^([0-9a-f])/i,"$1.");return"".concat(n).concat(o,"e-").concat(i.toString(e))}if(r.match(/^-?[0-9a-f]{7,}\.?/i)){var a=t.match(/^[0-9a-f]+/gi)[0].length-1;var u=t.replace(/\./,"").replace(/^([0-9a-f])/i,"$1.").replace(/0+$/,"").replace(/\.$/,".0");return"".concat(n).concat(u,"e+").concat(a.toString(e))}if(!LNumber.isFloat(this.__value__)){var s=r+".0";return this._minus?"-"+s:s}}return r.replace(/^([0-9]+)e/,"$1.0e")};LFloat.prototype._op=function(e,r){if(r instanceof LNumber){r=r.__value__}var t=LNumber._ops[e];if(e==="/"&&this.__value__===0&&r===0){return NaN}return LFloat(t(this.__value__,r))};LFloat.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){return toRational(this.__value__.valueOf())}return approxRatio(e.valueOf())(this.__value__.valueOf())};LFloat.prototype.sqrt=function(){var e=this.valueOf();if(this.cmp(0)<0){var r=LFloat(Math.sqrt(-e));return LComplex({re:0,im:r})}return LFloat(Math.sqrt(e))};LFloat.prototype.abs=function(){var e=this.valueOf();if(e<0){e=-e}return LFloat(e)};var toRational=approxRatio(1e-10);function approxRatio(n){return function(e){var r=function e(n,r,t){var i=function e(r,t){return t0){i=simplest_rational2(n,t)}else if(n.cmp(t)<=0){i=t}else if(t.cmp(0)>0){i=simplest_rational2(t,n)}else if(r.cmp(0)<0){i=LNumber(simplest_rational2(n.sub(),t.sub())).sub()}else{i=LNumber(0)}if(LNumber.isFloat(r)||LNumber.isFloat(e)){return LFloat(i)}return i}function simplest_rational2(e,r){var t=LNumber(e).floor();var n=LNumber(r).floor();if(e.cmp(t)<1){return t}else if(t.cmp(n)===0){var i=LNumber(1).div(r.sub(n));var o=LNumber(1).div(e.sub(t));return t.add(LNumber(1).div(simplest_rational2(i,o)))}else{return t.add(LNumber(1))}}function LRational(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof LRational)||typeof this==="undefined"){return new LRational(e,r)}if(!LNumber.isRational(e)){throw new Error("Invalid constructor call for LRational")}var t,n;if(e instanceof LRational){t=LNumber(e.__num__);n=LNumber(e.__denom__)}else{t=LNumber(e.num);n=LNumber(e.denom)}if(!r&&n.cmp(0)!==0){var i=t.op("%",n).cmp(0)===0;if(i){return LNumber(t.div(n))}}this.constant(t,n)}LRational.prototype=Object.create(LNumber.prototype);LRational.prototype.constructor=LRational;LRational.prototype.constant=function(e,r){Object.defineProperty(this,"__num__",{value:e,enumerable:true});Object.defineProperty(this,"__denom__",{value:r,enumerable:true});Object.defineProperty(this,"__type__",{value:"rational",enumerable:true})};LRational.prototype.serialize=function(){return{num:this.__num__,denom:this.__denom__}};LRational.prototype.pow=function(e){if(LNumber.isRational(e)){return pow(this.valueOf(),e.valueOf())}var r=e.cmp(0);if(r===0){return LNumber(1)}if(r===-1){e=e.sub();var t=this.__denom__.pow(e);var n=this.__num__.pow(e);return LRational({num:t,denom:n})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};LRational.prototype.sqrt=function(){var e=this.__num__.sqrt();var r=this.__denom__.sqrt();if(e instanceof LFloat||r instanceof LFloat){return e.div(r)}return LRational({num:e,denom:r})};LRational.prototype.abs=function(){var e=this.__num__;var r=this.__denom__;if(e.cmp(0)===-1){e=e.sub()}if(r.cmp(0)!==1){r=r.sub()}return LRational({num:e,denom:r})};LRational.prototype.cmp=function(e){return LNumber(this.valueOf(),true).cmp(e)};LRational.prototype.toString=function(){var e=this.__num__.gcd(this.__denom__);var r,t;if(e.cmp(1)!==0){r=this.__num__.div(e);if(r instanceof LRational){r=LNumber(r.valueOf(true))}t=this.__denom__.div(e);if(t instanceof LRational){t=LNumber(t.valueOf(true))}}else{r=this.__num__;t=this.__denom__}var n=this.cmp(0)<0;if(n){if(r.abs().cmp(t.abs())===0){return r.toString()}}else if(r.cmp(t)===0){return r.toString()}return r.toString()+"/"+t.toString()};LRational.prototype.valueOf=function(e){if(this.__denom__.cmp(0)===0){if(this.__num__.cmp(0)<0){return Number.NEGATIVE_INFINITY}return Number.POSITIVE_INFINITY}if(e){return LNumber._ops["/"](this.__num__.value,this.__denom__.value)}return LFloat(this.__num__.valueOf()).div(this.__denom__.valueOf())};LRational.prototype.mul=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=this.__num__.mul(e.__num__);var t=this.__denom__.mul(e.__denom__);return LRational({num:r,denom:t})}var n=LNumber.coerce(this,e),i=_slicedToArray(n,2),o=i[0],a=i[1];return o.mul(a)};LRational.prototype.div=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=this.__num__.mul(e.__denom__);var t=this.__denom__.mul(e.__num__);return LRational({num:r,denom:t})}var n=LNumber.coerce(this,e),i=_slicedToArray(n,2),o=i[0],a=i[1];var u=o.div(a);return u};LRational.prototype._op=function(e,r){return this[rev_mapping[e]](r)};LRational.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=e.__num__.sub();var t=e.__denom__;return this.add(LRational({num:r,denom:t}))}if(!(e instanceof LNumber)){e=LNumber(e).sub()}else{e=e.sub()}var n=LNumber.coerce(this,e),i=_slicedToArray(n,2),o=i[0],a=i[1];return o.add(a)};LRational.prototype.add=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=this.__denom__;var t=e.__denom__;var n=this.__num__;var i=e.__num__;var o,a;if(r!==t){a=t.mul(n).add(i.mul(r));o=r.mul(t)}else{a=n.add(i);o=r}return LRational({num:a,denom:o})}if(LNumber.isFloat(e)){return LFloat(this.valueOf()).add(e)}var u=LNumber.coerce(this,e),s=_slicedToArray(u,2),c=s[0],l=s[1];return c.add(l)};function LBigInteger(e,r){if(typeof this!=="undefined"&&!(this instanceof LBigInteger)||typeof this==="undefined"){return new LBigInteger(e,r)}if(e instanceof LBigInteger){return LBigInteger(e.__value__,e._native)}if(!LNumber.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.constant(e,"bigint");Object.defineProperty(this,"_native",{value:r})}LBigInteger.prototype=Object.create(LNumber.prototype);LBigInteger.prototype.constructor=LBigInteger;LBigInteger.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};LBigInteger.prototype.serialize=function(){return this.__value__.toString()};LBigInteger.prototype._op=function(e,r){if(typeof r==="undefined"){if(LNumber.isBN(this.__value__)){e=LBigInteger.bn_op[e];return LBigInteger(this.__value__.clone()[e](),false)}return LBigInteger(LNumber._ops[e](this.__value__),true)}if(LNumber.isBN(this.__value__)&&LNumber.isBN(r.__value__)){e=LBigInteger.bn_op[e];return LBigInteger(this.__value__.clone()[e](r),false)}var t=LNumber._ops[e](this.__value__,r.__value__);if(e==="/"){var n=this.op("%",r).cmp(0)===0;if(n){return LNumber(t)}return LRational({num:this,denom:r})}return LBigInteger(t,true)};LBigInteger.prototype.sqrt=function(){var e;var r=this.cmp(0)<0;if(LNumber.isNative(this.__value__)){e=LNumber(Math.sqrt(r?-this.valueOf():this.valueOf()))}else if(LNumber.isBN(this.__value__)){e=r?this.__value__.neg().sqrt():this.__value__.sqrt()}if(r){return LComplex({re:0,im:e})}return e};LNumber.NaN=LNumber(NaN);LComplex.i=LComplex({im:1,re:0});function InputPort(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof InputPort)||typeof this==="undefined"){return new InputPort(e)}typecheck("InputPort",e,"function");read_only(this,"__type__",text_port);var i;Object.defineProperty(this,"__parser__",{enumerable:true,get:function e(){return i},set:function e(r){typecheck("InputPort::__parser__",r,"parser");i=r}});this._read=e;this._with_parser=this._with_init_parser.bind(this,_asyncToGenerator(_regeneratorRuntime.mark(function e(){var t;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:if(n.char_ready()){r.next=5;break}r.next=3;return n._read();case 3:t=r.sent;i=new Parser(t,{env:n});case 5:return r.abrupt("return",n.__parser__);case 6:case"end":return r.stop()}},e)})));this.char_ready=function(){return!!this.__parser__&&this.__parser__.__lexer__.peek()!==eof};this._make_defaults()}InputPort.prototype._make_defaults=function(){this.read=this._with_parser(function(e){return e.read_object()});this.read_line=this._with_parser(function(e){return e.__lexer__.read_line()});this.read_char=this._with_parser(function(e){return e.__lexer__.read_char()});this.read_string=this._with_parser(function(e,r){if(!LNumber.isInteger(r)){var t=LNumber.getType(r);typeErrorMessage("read-string",t,"integer")}return e.__lexer__.read_string(r.valueOf())});this.peek_char=this._with_parser(function(e){return e.__lexer__.peek_char()})};InputPort.prototype._with_init_parser=function(u,s){var c=this;return _asyncToGenerator(_regeneratorRuntime.mark(function e(){var t,n,i,o,a=arguments;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:r.next=2;return u.call(c);case 2:t=r.sent;for(n=a.length,i=new Array(n),o=0;o"};function OutputPort(e){if(typeof this!=="undefined"&&!(this instanceof OutputPort)||typeof this==="undefined"){return new OutputPort(e)}typecheck("OutputPort",e,"function");read_only(this,"__type__",text_port);this.write=e}OutputPort.prototype.is_open=function(){return this._closed!==true};OutputPort.prototype.close=function(){Object.defineProperty(this,"_closed",{get:function e(){return true},set:function e(){},configurable:false,enumerable:false});this.write=function(){throw new Error("output-port: port is closed")}};OutputPort.prototype.flush=function(){};OutputPort.prototype.toString=function(){return"#"};var BufferedOutputPort=function(e){_inherits(t,e);function t(e){var r;_classCallCheck(this,t);r=_callSuper(this,t,[function(){var e;return(e=r)._write.apply(e,arguments)}]);typecheck("BufferedOutputPort",e,"function");read_only(_assertThisInitialized(r),"_fn",e,{hidden:true});read_only(_assertThisInitialized(r),"_buffer",[],{hidden:true});return r}_createClass(t,[{key:"flush",value:function e(){if(this._buffer.length){this._fn(this._buffer.join(""));this._buffer.length=0}}},{key:"_write",value:function e(){var r=this;for(var t=arguments.length,n=new Array(t),i=0;i"};OutputStringPort.prototype.valueOf=function(){return this.__buffer__.map(function(e){return e.valueOf()}).join("")};function OutputFilePort(e,r){var t=this;if(typeof this!=="undefined"&&!(this instanceof OutputFilePort)||typeof this==="undefined"){return new OutputFilePort(e,r)}typecheck("OutputFilePort",e,"string");read_only(this,"__filename__",e);read_only(this,"_fd",r.valueOf(),{hidden:true});read_only(this,"__type__",text_port);this.write=function(e){if(!LString.isString(e)){e=toString(e)}else{e=e.valueOf()}t.fs().write(t._fd,e,function(e){if(e){throw e}})}}OutputFilePort.prototype=Object.create(OutputPort.prototype);OutputFilePort.prototype.constructor=OutputFilePort;OutputFilePort.prototype.fs=function(){if(!this._fs){this._fs=this.internal("fs")}return this._fs};OutputFilePort.prototype.internal=function(e){return user_env.get("**internal-env**").get(e)};OutputFilePort.prototype.close=function(){var n=this;return new Promise(function(r,t){n.fs().close(n._fd,function(e){if(e){t(e)}else{read_only(n,"_fd",null,{hidden:true});OutputPort.prototype.close.call(n);r()}})})};OutputFilePort.prototype.toString=function(){return"#")};function InputStringPort(e,r){var t=this;if(typeof this!=="undefined"&&!(this instanceof InputStringPort)||typeof this==="undefined"){return new InputStringPort(e)}typecheck("InputStringPort",e,"string");r=r||global_env;e=e.valueOf();this._with_parser=this._with_init_parser.bind(this,function(){if(!t.__parser__){t.__parser__=new Parser(e,{env:r})}return t.__parser__});read_only(this,"__type__",text_port);this._make_defaults()}InputStringPort.prototype.char_ready=function(){return true};InputStringPort.prototype=Object.create(InputPort.prototype);InputStringPort.prototype.constructor=InputStringPort;InputStringPort.prototype.toString=function(){return"#"};function InputByteVectorPort(e){if(typeof this!=="undefined"&&!(this instanceof InputByteVectorPort)||typeof this==="undefined"){return new InputByteVectorPort(e)}typecheck("InputByteVectorPort",e,"uint8array");read_only(this,"__vector__",e);read_only(this,"__type__",binary_port);var t=0;Object.defineProperty(this,"__index__",{enumerable:true,get:function e(){return t},set:function e(r){typecheck("InputByteVectorPort::__index__",r,"number");if(r instanceof LNumber){r=r.valueOf()}if(typeof r==="bigint"){r=Number(r)}if(Math.floor(r)!==r){throw new Error("InputByteVectorPort::__index__ value is "+"not integer")}t=r}})}InputByteVectorPort.prototype=Object.create(InputPort.prototype);InputByteVectorPort.prototype.constructor=InputByteVectorPort;InputByteVectorPort.prototype.toString=function(){return"#"};InputByteVectorPort.prototype.close=function(){var r=this;read_only(this,"__vector__",_nil);var t=function e(){throw new Error("Input-binary-port: port is closed")};["read_u8","close","peek_u8","read_u8_vector"].forEach(function(e){r[e]=t});this.u8_ready=this.char_ready=function(){return false}};InputByteVectorPort.prototype.u8_ready=function(){return true};InputByteVectorPort.prototype.peek_u8=function(){if(this.__index__>=this.__vector__.length){return eof}return this.__vector__[this.__index__]};InputByteVectorPort.prototype.skip=function(){if(this.__index__<=this.__vector__.length){++this.__index__}};InputByteVectorPort.prototype.read_u8=function(){var e=this.peek_u8();this.skip();return e};InputByteVectorPort.prototype.read_u8_vector=function(e){if(typeof e==="undefined"){e=this.__vector__.length}else if(e>this.__index__+this.__vector__.length){e=this.__index__+this.__vector__.length}if(this.peek_u8()===eof){return eof}return this.__vector__.slice(this.__index__,e)};function OutputByteVectorPort(){if(typeof this!=="undefined"&&!(this instanceof OutputByteVectorPort)||typeof this==="undefined"){return new OutputByteVectorPort}read_only(this,"__type__",binary_port);read_only(this,"_buffer",[],{hidden:true});this.write=function(e){typecheck("write",e,["number","uint8array"]);if(LNumber.isNumber(e)){this._buffer.push(e.valueOf())}else{var r;(r=this._buffer).push.apply(r,_toConsumableArray(Array.from(e)))}};Object.defineProperty(this,"__buffer__",{enumerable:true,get:function e(){return Uint8Array.from(this._buffer)}})}OutputByteVectorPort.prototype=Object.create(OutputPort.prototype);OutputByteVectorPort.prototype.constructor=OutputByteVectorPort;OutputByteVectorPort.prototype.close=function(){OutputPort.prototype.close.call(this);read_only(this,"_buffer",null,{hidden:true})};OutputByteVectorPort.prototype._close_guard=function(){if(this._closed){throw new Error("output-port: binary port is closed")}};OutputByteVectorPort.prototype.write_u8=function(e){typecheck("OutputByteVectorPort::write_u8",e,"number");this.write(e)};OutputByteVectorPort.prototype.write_u8_vector=function(e){typecheck("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};OutputByteVectorPort.prototype.toString=function(){return"#"};OutputByteVectorPort.prototype.valueOf=function(){return this.__buffer__};function InputFilePort(e,r){if(typeof this!=="undefined"&&!(this instanceof InputFilePort)||typeof this==="undefined"){return new InputFilePort(e,r)}InputStringPort.call(this,e);typecheck("InputFilePort",r,"string");read_only(this,"__filename__",r)}InputFilePort.prototype=Object.create(InputStringPort.prototype);InputFilePort.prototype.constructor=InputFilePort;InputFilePort.prototype.toString=function(){return"#")};function InputBinaryFilePort(e,r){if(typeof this!=="undefined"&&!(this instanceof InputBinaryFilePort)||typeof this==="undefined"){return new InputBinaryFilePort(e,r)}InputByteVectorPort.call(this,e);typecheck("InputBinaryFilePort",r,"string");read_only(this,"__filename__",r)}InputBinaryFilePort.prototype=Object.create(InputByteVectorPort.prototype);InputBinaryFilePort.prototype.constructor=InputBinaryFilePort;InputBinaryFilePort.prototype.toString=function(){return"#")};function OutputBinaryFilePort(e,r){var i=this;if(typeof this!=="undefined"&&!(this instanceof OutputBinaryFilePort)||typeof this==="undefined"){return new OutputBinaryFilePort(e,r)}typecheck("OutputBinaryFilePort",e,"string");read_only(this,"__filename__",e);read_only(this,"_fd",r.valueOf(),{hidden:true});read_only(this,"__type__",binary_port);var o;this.write=function(e){typecheck("write",e,["number","uint8array"]);var n;if(!o){o=i.internal("fs")}if(LNumber.isNumber(e)){n=new Uint8Array([e.valueOf()])}else{n=new Uint8Array(Array.from(e))}return new Promise(function(r,t){o.write(i._fd,n,function(e){if(e){t(e)}else{r()}})})}}OutputBinaryFilePort.prototype=Object.create(OutputFilePort.prototype);OutputBinaryFilePort.prototype.constructor=OutputBinaryFilePort;OutputBinaryFilePort.prototype.write_u8=function(e){typecheck("OutputByteVectorPort::write_u8",e,"number");this.write(e)};OutputBinaryFilePort.prototype.write_u8_vector=function(e){typecheck("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};var binary_port=Symbol["for"]("binary");var text_port=Symbol["for"]("text");var eof=new EOF;function EOF(){}EOF.prototype.toString=function(){return"#"};function Interpreter(e){var r=this;var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=t.stderr,i=t.stdin,o=t.stdout,a=t.command_line,u=a===void 0?null:a,s=_objectWithoutProperties(t,_excluded3);if(typeof this!=="undefined"&&!(this instanceof Interpreter)||typeof this==="undefined"){return new Interpreter(e,_objectSpread({stdin:i,stdout:o,stderr:n,command_line:u},s))}if(typeof e==="undefined"){e="anonymous"}this.__env__=user_env.inherit(e,s);this.__env__.set("parent.frame",doc("parent.frame",function(){return r.__env__},global_env.__env__["parent.frame"].__doc__));var c="**interaction-environment-defaults**";this.set(c,get_props(s).concat(c));var l=internal_env.inherit("internal-".concat(e));if(is_port(i)){l.set("stdin",i)}if(is_port(n)){l.set("stderr",n)}if(is_port(o)){l.set("stdout",o)}l.set("command-line",u);set_interaction_env(this.__env__,l)}Interpreter.prototype.exec=function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var t=r.use_dynamic,n=t===void 0?false:t,i=r.dynamic_env,o=r.env;typecheck("Interpreter::exec",e,["string","array"],1);typecheck("Interpreter::exec",n,"boolean",2);if(!o){o=this.__env__}if(!i){i=o}global_env.set("**interaction-environment**",this.__env__);return exec(e,{env:o,dynamic_env:i,use_dynamic:n})};Interpreter.prototype.get=function(e){var r=this.__env__.get(e);if(is_function(r)){var t=new LambdaContext({env:this.__env__});return r.bind(t)}return r};Interpreter.prototype.set=function(e,r){return this.__env__.set(e,r)};Interpreter.prototype.constant=function(e,r){return this.__env__.constant(e,r)};function LipsError(e,r){this.name="LipsError";this.message=e;this.args=r;this.stack=(new Error).stack}LipsError.prototype=new Error;LipsError.prototype.constructor=LipsError;var IgnoreException=function(e){_inherits(r,e);function r(){_classCallCheck(this,r);return _callSuper(this,r,arguments)}return _createClass(r)}(_wrapNativeSuper(Error));function Environment(e,r,t){if(arguments.length===1){if(_typeof$1(arguments[0])==="object"){e=arguments[0];r=null}else if(typeof arguments[0]==="string"){e={};r=null;t=arguments[0]}}this.__docs__=new Map;this.__env__=e;this.__parent__=r;this.__name__=t||"anonymous"}Environment.prototype.list=function(){return get_props(this.__env__)};Environment.prototype.fs=function(){return this.get("**fs**")};Environment.prototype.unset=function(e){if(e instanceof LSymbol){e=e.valueOf()}if(e instanceof LString){e=e.valueOf()}delete this.__env__[e]};Environment.prototype.inherit=function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(_typeof$1(e)==="object"){r=e}if(!e||_typeof$1(e)==="object"){e="child of "+(this.__name__||"unknown")}return new Environment(r||{},this,e)};Environment.prototype.doc=function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}if(r){if(!t){r=trim_lines(r)}this.__docs__.set(e,r);return this}if(this.__docs__.has(e)){return this.__docs__.get(e)}if(this.__parent__){return this.__parent__.doc(e)}};Environment.prototype.new_frame=function(e,r){var n=this.inherit("__frame__");n.set("parent.frame",doc("parent.frame",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;e=e.valueOf();var r=n.__parent__;if(!is_env(r)){return _nil}if(e<=0){return r}var t=r.get("parent.frame");return t(e-1)},global_env.__env__["parent.frame"].__doc__));r.callee=e;n.set("arguments",r);return n};Environment.prototype._lookup=function(e){if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}if(this.__env__.hasOwnProperty(e)){return Value(this.__env__[e])}if(this.__parent__){return this.__parent__._lookup(e)}};Environment.prototype.toString=function(){return"#"};Environment.prototype.clone=function(){var r=this;var t={};Object.keys(this.__env__).forEach(function(e){t[e]=r.__env__[e]});return new Environment(t,this.__parent__,this.__name__)};Environment.prototype.merge=function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"merge";typecheck("Environment::merge",e,"environment");return this.inherit(r,e.__env__)};function Value(e){if(typeof this!=="undefined"&&!(this instanceof Value)||typeof this==="undefined"){return new Value(e)}this.value=e}Value.isUndefined=function(e){return e instanceof Value&&typeof e.value==="undefined"};Value.prototype.valueOf=function(){return this.value};function Values(e){if(!e.length){return}if(e.length===1){return e[0]}if(typeof this!=="undefined"&&!(this instanceof Values)||typeof this==="undefined"){return new Values(e)}this.__values__=e}Values.prototype.toString=function(){return this.__values__.map(function(e){return toString(e)}).join("\n")};Values.prototype.valueOf=function(){return this.__values__};Environment.prototype.get=function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};typecheck("Environment::get",e,["symbol","string"]);var t=r.throwError,n=t===void 0?true:t;var i=e;if(i instanceof LSymbol||i instanceof LString){i=i.valueOf()}var o=this._lookup(i);if(o instanceof Value){if(Value.isUndefined(o)){return undefined}return patch_value(o.valueOf())}var a;if(e instanceof LSymbol&&e[LSymbol.object]){a=e[LSymbol.object]}else if(typeof i==="string"){a=i.split(".").filter(Boolean)}if(a&&a.length>0){var u=a,s=_toArray(u),c=s[0],l=s.slice(1);o=this._lookup(c);if(l.length){try{if(o instanceof Value){o=o.valueOf()}else{o=get(root,c);if(is_function(o)){o=unbind(o)}}if(typeof o!=="undefined"){return get.apply(void 0,[o].concat(_toConsumableArray(l)))}}catch(e){throw e}}else if(o instanceof Value){return patch_value(o.valueOf())}o=get(root,i)}if(typeof o!=="undefined"){return o}if(n){throw new Error("Unbound variable `"+i.toString()+"'")}};Environment.prototype.set=function(e,r){var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;typecheck("Environment::set",e,["string","symbol"]);if(LNumber.isNumber(r)){r=LNumber(r)}if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}this.__env__[e]=r;if(t){this.doc(e,t,true)}return this};Environment.prototype.constant=function(r,e){var t=this;if(this.__env__.hasOwnProperty(r)){throw new Error("Environment::constant: ".concat(r," already exists"))}if(arguments.length===1&&is_plain_object(arguments[0])){var n=arguments[0];Object.keys(n).forEach(function(e){t.constant(r,n[e])})}else{Object.defineProperty(this.__env__,r,{value:e,enumerable:true})}return this};Environment.prototype.has=function(e){return this.__env__.hasOwnProperty(e)};Environment.prototype.ref=function(e){var r=this;while(true){if(!r){break}if(r.has(e)){return r}r=r.__parent__}};Environment.prototype.parents=function(){var e=this;var r=[];while(e){r.unshift(e);e=e.__parent__}return r};function quote(e){if(is_promise(e)){return e.then(quote)}if(is_pair(e)||e instanceof LSymbol){e[__data__]=true}return e}var native_lambda=_parse(tokenize('(lambda ()\n "[native code]"\n (throw "Invalid Invocation"))'))[0];var get=doc("get",function e(r){var t;for(var n=arguments.length,i=new Array(n>1?n-1:0),o=1;o0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=internal(this,"stdin")}typecheck_text_port("peek-char",e,"input-port");return e.peek_char()},"(peek-char port)\n\n This function reads and returns a character from the string\n port, or, if there is no more data in the string port, it\n returns an EOF."),"read-line":doc("read-line",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=internal(this,"stdin")}typecheck_text_port("read-line",e,"input-port");return e.read_line()},"(read-line port)\n\n This function reads and returns the next line from the input\n port."),"read-char":doc("read-char",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=internal(this,"stdin")}typecheck_text_port("read-char",e,"input-port");return e.read_char()},"(read-char port)\n\n This function reads and returns the next character from the\n input port."),read:doc("read",function(){var e=_asyncToGenerator(function(){var i=this;var o=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;return _regeneratorRuntime.mark(function e(){var t,n;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:t=i.env;if(o===null){n=internal(t,"stdin")}else{n=o}typecheck_text_port("read",n,"input-port");return r.abrupt("return",n.read.call(t));case 4:case"end":return r.stop()}},e)})()});function r(){return e.apply(this,arguments)}return r}(),"(read [port])\n\n This function, if called with a port, it will parse the next\n item from the port. If called without an input, it will read\n a string from standard input (using the browser's prompt or\n a user defined input method) and parse it. This function can be\n used together with `eval` to evaluate code from port."),pprint:doc("pprint",function e(r){if(is_pair(r)){r=new lips.Formatter(r.toString(true))["break"]().format();global_env.get("display").call(global_env,r)}else{global_env.get("write").call(global_env,r)}global_env.get("newline").call(global_env)},"(pprint expression)\n\n This function will pretty print its input to stdout. If it is called\n with a non-list, it will just call the print function on its\n input."),print:doc("print",function e(){var r=global_env.get("display");var t=global_env.get("newline");var n=this.use_dynamic;var i=global_env;var o=global_env;for(var a=arguments.length,u=new Array(a),s=0;s1?t-1:0),i=1;in.length){throw new Error("Not enough arguments")}var u=0;var s=global_env.get("repr");r=r.replace(o,function(e){var r=e[1];if(r==="~"){return"~"}else if(r==="%"){return"\n"}else{var t=n[u++];if(r==="a"){return s(t)}else{return s(t,true)}}});a=r.match(/~([\S])/);if(a){throw new Error("format: Unrecognized escape sequence ".concat(a[1]))}return r},"(format string n1 n2 ...)\n\n This function accepts a string template and replaces any\n escape sequences in its inputs:\n\n * ~a value as if printed with `display`\n * ~s value as if printed with `write`\n * ~% newline character\n * ~~ literal tilde '~'\n\n If there are missing inputs or other escape characters it\n will error."),display:doc("display",function e(r){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(t===null){t=internal(this,"stdout")}else{typecheck("display",t,"output-port")}var n=r;if(!(t instanceof OutputBinaryFilePort)){n=global_env.get("repr")(r)}t.write.call(global_env,n)},"(display string [port])\n\n This function outputs the string to the standard output or\n the port if given. No newline."),"display-error":doc("display-error",function e(){var r=internal(this,"stderr");var t=global_env.get("repr");for(var n=arguments.length,i=new Array(n),o=0;o1&&arguments[1]!==undefined?arguments[1]:{},t=r.use_dynamic,n=_objectWithoutProperties(r,_excluded4);var i=this;var a=this;var u;var s=_objectSpread(_objectSpread({},n),{},{env:this,dynamic_env:i,use_dynamic:t});var c=_evaluate(e.cdr.car,s);c=resolve_promises(c);function l(r,t,n){if(is_promise(r)){return r.then(function(e){return l(r,e,n)})}if(is_promise(t)){return t.then(function(e){return l(r,e,n)})}if(is_promise(n)){return n.then(function(e){return l(r,t,e)})}a.get("set-obj!").call(a,r,t,n);return n}if(is_pair(e.car)&&LSymbol.is(e.car.car,".")){var f=e.car.cdr.car;var _=e.car.cdr.cdr.car;var p=_evaluate(f,s);var d=_evaluate(_,s);return l(p,d,c)}if(!(e.car instanceof LSymbol)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var y=e.car.valueOf();u=this.ref(e.car.__name__);return unpromise(c,function(e){if(!u){var r=y.split(".");if(r.length>1){var t=r.pop();var n=r.join(".");var i=o.get(n,{throwError:false});if(i){l(i,t,e);return}}throw new Error("Unbound variable `"+y+"'")}u.set(y,e)})}),"(set! name value)\n\n Macro that can be used to set the value of the variable or slot (mutate it).\n set! searches the scope chain until it finds first non empty slot and sets it."),"unset!":doc(new Macro("set!",function(e){if(!(e.car instanceof LSymbol)){throw new Error("unset! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var r=e.car;var t=this.ref(r);if(t){delete t.__env__[r.__name__]}}),"(unset! name)\n\n Function to delete the specified name from environment.\n Trying to access the name afterwards will error."),"set-car!":doc("set-car!",function(e,r){typecheck("set-car!",e,"pair");e.car=r},"(set-car! obj value)\n\n Function that sets the car (first item) of the list/pair to specified value.\n The old value is lost."),"set-cdr!":doc("set-cdr!",function(e,r){typecheck("set-cdr!",e,"pair");e.cdr=r},"(set-cdr! obj value)\n\n Function that sets the cdr (tail) of the list/pair to specified value.\n It will destroy the list. The old tail is lost."),"empty?":doc("empty?",function(e){return typeof e==="undefined"||is_nil(e)},"(empty? object)\n\n Function that returns #t if value is nil (an empty list) or undefined."),gensym:doc("gensym",gensym,"(gensym)\n\n Generates a unique symbol that is not bound anywhere,\n to use with macros as meta name."),load:doc("load",function e(u,r){typecheck("load",u,"string");var s=this;if(s.__name__==="__frame__"){s=s.__parent__}if(!(r instanceof Environment)){if(s===global_env){r=s}else{r=this.get("**interaction-environment**")}}var c="**module-path**";var l=global_env.get(c,{throwError:false});u=u.valueOf();if(!u.match(/.[^.]+$/)){u+=".scm"}var t=u.match(/\.xcb$/);function f(e){if(t){e=unserialize_bin(e)}else{if(type(e)==="buffer"){e=e.toString()}e=e.replace(/^(#!.*)/,function(e,r){if(is_directive(r)){return r}return""});if(e.match(/^\{/)){e=unserialize(e)}}return exec(e,{env:r})}function n(e){return root.fetch(e).then(function(e){return t?e.arrayBuffer():e.text()}).then(function(e){if(t){e=new Uint8Array(e)}return e})}if(is_node()){return new Promise(function(){var t=_asyncToGenerator(_regeneratorRuntime.mark(function e(t,n){var i,o,a;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:i=nodeRequire("path");if(!l){r.next=6;break}l=l.valueOf();u=i.join(l,u);r.next=12;break;case 6:o=s.get("command-line",{throwError:false});if(!o){r.next=11;break}r.next=10;return o();case 10:a=r.sent;case 11:if(a&&!is_nil(a)){process.cwd();u=i.join(i.dirname(a.car.valueOf()),u)}case 12:global_env.set(c,i.dirname(u));nodeRequire("fs").readFile(u,function(e,r){if(e){n(e);global_env.set(c,l)}else{try{f(r).then(function(){t();global_env.set(c,l)})["catch"](n)}catch(e){n(e)}}});case 14:case"end":return r.stop()}},e)}));return function(e,r){return t.apply(this,arguments)}}())}if(l){l=l.valueOf();u=l+"/"+u.replace(/^\.?\/?/,"")}return n(u).then(function(e){global_env.set(c,u.replace(/\/[^/]*$/,""));return f(e)}).then(function(){})["finally"](function(){global_env.set(c,l)})},"(load filename)\n (load filename environment)\n\n Fetches the file (from disk or network) and evaluates its content as LIPS code.\n If the second argument is provided and it's an environment the evaluation\n will happen in that environment."),while:doc(new Macro("while",function(e,r){var t=e.car;var n=_objectSpread(_objectSpread({},r),{},{env:this});var i=new Pair(new LSymbol("begin"),e.cdr);return function r(){return unpromise(_evaluate(t,n),function(e){if(e){return unpromise(_evaluate(i,n),r)}})}()}),"(while cond body)\n\n Creates a loop, it executes cond and body until cond expression is false."),do:doc(new Macro("do",function(){var t=_asyncToGenerator(function(_,e){var p=this;var d=e.use_dynamic,y=e.error;return _regeneratorRuntime.mark(function e(){var u,t,s,c,n,l,f,i,o,a;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:u=p;t=u;s=u.inherit("do");c=_.car;n=_.cdr.car;l=_.cdr.cdr;if(!is_nil(l)){l=new Pair(LSymbol("begin"),l)}f={env:u,dynamic_env:t,use_dynamic:d,error:y};i=c;case 9:if(is_nil(i)){r.next=20;break}o=i.car;r.t0=s;r.t1=o.car;r.next=15;return _evaluate(o.cdr.car,f);case 15:r.t2=r.sent;r.t0.set.call(r.t0,r.t1,r.t2);i=i.cdr;r.next=9;break;case 20:f={env:s,dynamic_env:t,error:y};a=_regeneratorRuntime.mark(function e(){var t,n,i,o,a;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:if(is_nil(l)){r.next=3;break}r.next=3;return lips.evaluate(l,f);case 3:t=c;n={};case 5:if(is_nil(t)){r.next=15;break}i=t.car;if(is_nil(i.cdr.cdr)){r.next=12;break}r.next=10;return _evaluate(i.cdr.cdr.car,f);case 10:o=r.sent;n[i.car.valueOf()]=o;case 12:t=t.cdr;r.next=5;break;case 15:a=Object.getOwnPropertySymbols(n);f.env=s=u.inherit("do");Object.keys(n).concat(a).forEach(function(e){s.set(e,n[e])});case 18:case"end":return r.stop()}},e)});case 22:r.next=24;return _evaluate(n.car,f);case 24:r.t3=r.sent;if(!(r.t3===false)){r.next=29;break}return r.delegateYield(a(),"t4",27);case 27:r.next=22;break;case 29:if(is_nil(n.cdr)){r.next=33;break}r.next=32;return _evaluate(n.cdr.car,f);case 32:return r.abrupt("return",r.sent);case 33:case"end":return r.stop()}},e)})()});return function(e,r){return t.apply(this,arguments)}}()),"(do (( )) (test return) . body)\n\n Iteration macro that evaluates the expression body in scope of the variables.\n On each loop it changes the variables according to the expression and runs\n test to check if the loop should continue. If test is a single value, the macro\n will return undefined. If the test is a pair of expressions the macro will\n evaluate and return the second expression after the loop exits."),if:doc(new Macro("if",function(t,e){var r=e.error,n=e.use_dynamic;var i=this;var o=this;var a={env:o,dynamic_env:i,use_dynamic:n,error:r};var u=function e(r){if(is_false(r)){return _evaluate(t.cdr.cdr.car,a)}else{return _evaluate(t.cdr.car,a)}};if(is_nil(t)){throw new Error("too few expressions for `if`")}var s=_evaluate(t.car,a);return unpromise(s,u)}),"(if cond true-expr false-expr)\n\n Macro that evaluates cond expression and if the value is true, it\n evaluates and returns true-expression, if not it evaluates and returns\n false-expression."),"let-env":new Macro("let-env",function(r){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var t=e.dynamic_env,n=e.use_dynamic,i=e.error;typecheck("let-env",r,"pair");var o=_evaluate(r.car,{env:this,dynamic_env:t,error:i,use_dynamic:n});return unpromise(o,function(e){typecheck("let-env",e,"environment");return _evaluate(Pair(LSymbol("begin"),r.cdr),{env:e,dynamic_env:t,error:i})})},"(let-env env . body)\n\n Special macro that evaluates body in context of given environment\n object."),letrec:doc(let_macro(Symbol["for"]("letrec")),"(letrec ((a value-a) (b value-b) ...) . body)\n\n Macro that creates a new environment, then evaluates and assigns values to\n names and then evaluates the body in context of that environment.\n Values are evaluated sequentially and the next value can access the\n previous values/names."),"letrec*":doc(let_macro(Symbol["for"]("letrec")),"(letrec* ((a value-a) (b value-b) ...) . body)\n\n Same as letrec but the order of execution of the binding is guaranteed,\n so you can use recursive code as well as referencing the previous binding.\n\n In LIPS both letrec and letrec* behave the same."),"let*":doc(let_macro(Symbol["for"]("let*")),"(let* ((a value-a) (b value-b) ...) . body)\n\n Macro similar to `let`, but the subsequent bindings after the first\n are evaluated in the environment including the previous let variables,\n so you can define one variable, and use it in the next's definition."),let:doc(let_macro(Symbol["for"]("let")),"(let ((a value-a) (b value-b) ...) . body)\n\n Macro that creates a new environment, then evaluates and assigns values to names,\n and then evaluates the body in context of that environment. Values are evaluated\n sequentially but you can't access previous values/names when the next are\n evaluated. You can only get them in the body of the let expression. (If you want\n to define multiple variables and use them in each other's definitions, use\n `let*`.)"),"begin*":doc(parallel("begin*",function(e){return e.pop()}),"(begin* . body)\n\n This macro is a parallel version of begin. It evaluates each expression\n in the body and if it's a promise it will await it in parallel and return\n the value of the last expression (i.e. it uses Promise.all())."),shuffle:doc("shuffle",function(e){typecheck("shuffle",e,["pair","nil","array"]);var r=global_env.get("random");if(is_nil(e)){return _nil}if(Array.isArray(e)){return shuffle(e.slice(),r)}var t=global_env.get("list->array")(e);t=shuffle(t,r);return global_env.get("array->list")(t)},"(shuffle obj)\n\n Order items in vector or list in random order."),begin:doc(new Macro("begin",function(e,r){var n=_objectSpread(_objectSpread({},r),{},{env:this});var i=global_env.get("list->array")(e);var o;return function r(){if(i.length){var e=i.shift();var t=_evaluate(e,n);return unpromise(t,function(e){o=e;return r()})}else{return o}}()}),"(begin . args)\n\n Macro that runs a list of expressions in order and returns the value\n of the last one. It can be used in places where you can only have a\n single expression, like (if)."),ignore:new Macro("ignore",function(e,r){var t=_objectSpread(_objectSpread({},r),{},{env:this,dynamic_env:this});_evaluate(new Pair(new LSymbol("begin"),e),t)},"(ignore . body)\n\n Macro that will evaluate the expression and swallow any promises that may\n be created. It will discard any value that may be returned by the last body\n expression. The code should have side effects and/or when it's promise\n it should resolve to undefined."),"call/cc":doc(Macro.defmacro("call/cc",function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var t=_objectSpread({env:this},r);return unpromise(_evaluate(e.car,t),function(e){if(is_function(e)){return e(new Continuation(null))}})}),"(call/cc proc)\n\n Call-with-current-continuation.\n\n NOT SUPPORTED BY LIPS RIGHT NOW"),parameterize:doc(new Macro("parameterize",function(r,e){var i=e.dynamic_env;var o=i.inherit("parameterize").new_frame(null,{});var a=_objectSpread(_objectSpread({},e),{},{env:this});var u=r.car;if(!is_pair(u)){var t=type(u);throw new Error("Invalid syntax for parameterize expecting pair got ".concat(t))}function s(){var e=new Pair(new LSymbol("begin"),r.cdr);return _evaluate(e,_objectSpread(_objectSpread({},a),{},{dynamic_env:o}))}return function t(){var e=u.car;var n=e.car.valueOf();return unpromise(_evaluate(e.cdr.car,a),function(e){var r=i.get(n,{throwError:false});if(!is_parameter(r)){throw new Error("Unknown parameter ".concat(n))}o.set(n,r.inherit(e));if(!is_null(u.cdr)){u=u.cdr;return t()}else{return s()}})}()}),"(parameterize ((name value) ...)\n\n Macro that change the dynamic variable created by make-parameter."),"make-parameter":doc(new Macro("make-parameter",function(e,r){r.dynamic_env;var t=_evaluate(e.car,r);var n;if(is_pair(e.cdr.car)){n=_evaluate(e.cdr.car,r)}return new Parameter(t,n)}),"(make-parameter init converter)\n\n Function creates new dynamic variable that can be custimized with parameterize\n macro. The value should be assigned to a variable e.g.:\n\n (define radix (make-parameter 10))\n\n The result value is a procedure that return the value of dynamic variable."),"define-syntax-parameter":doc(new Macro("define-syntax-parameter",function(e,r){var t=e.car;var n=this;if(!(t instanceof LSymbol)){throw new Error("define-syntax-parameter: invalid syntax expecting symbol got ".concat(type(t)))}var i=_evaluate(e.cdr.car,_objectSpread({env:n},r));typecheck("define-syntax-parameter",i,"syntax",2);i.__name__=t.valueOf();if(i.__name__ instanceof LString){i.__name__=i.__name__.valueOf()}var o;if(is_pair(e.cdr.cdr)&&LString.isString(e.cdr.cdr.car)){o=e.cdr.cdr.car.valueOf()}n.set(e.car,new SyntaxParameter(i),o,true)}),"(define-syntax-parameter name syntax [__doc__])\n\n Binds to the transformer obtained by evaluating .\n The transformer provides the default expansion for the syntax parameter,\n and in the absence of syntax-parameterize, is functionally equivalent to\n define-syntax."),"syntax-parameterize":doc(new Macro("syntax-parameterize",function(e,r){var t=global_env.get("list->array")(e.car);var n=this.inherit("syntax-parameterize");while(t.length){var i=t.shift();if(!(is_pair(i)||i.car instanceof LSymbol)){var o="invalid syntax for syntax-parameterize: ".concat(repr(e,true));throw new Error("syntax-parameterize: ".concat(o))}var a=_evaluate(i.cdr.car,_objectSpread(_objectSpread({},r),{},{env:this}));var u=i.car;typecheck("syntax-parameterize",a,["syntax"]);typecheck("syntax-parameterize",u,"symbol");a.__name__=u.valueOf();if(a.__name__ instanceof LString){a.__name__=a.__name__.valueOf()}var s=new SyntaxParameter(a);if(u.is_gensym()){var c=u.literal();var l=this.get(c,{throwError:false});if(l instanceof SyntaxParameter){n.set(c,s)}}n.set(u,s)}var f=new Pair(new LSymbol("begin"),e.cdr);return _evaluate(f,_objectSpread(_objectSpread({},r),{},{env:n}))}),"(syntax-parameterize (bindings) body)\n\n Macro work similar to let-syntax but the the bindnds will be exposed to the user.\n With syntax-parameterize you can define anaphoric macros."),define:doc(Macro.defmacro("define",function(t,e){var n=this;if(is_pair(t.car)&&t.car.car instanceof LSymbol){var r=new Pair(new LSymbol("define"),new Pair(t.car.car,new Pair(new Pair(new LSymbol("lambda"),new Pair(t.car.cdr,t.cdr)))));return r}else if(e.macro_expand){return}e.dynamic_env=this;e.env=n;var i=t.cdr.car;var o;if(is_pair(i)){i=_evaluate(i,e);o=true}else if(i instanceof LSymbol){i=n.get(i)}typecheck("define",t.car,"symbol");return unpromise(i,function(e){if(n.__name__===Syntax.__merge_env__){n=n.__parent__}if(o&&(is_function(e)&&is_lambda(e)||e instanceof Syntax||is_parameter(e))){e.__name__=t.car.valueOf();if(e.__name__ instanceof LString){e.__name__=e.__name__.valueOf()}}var r;if(is_pair(t.cdr.cdr)&&LString.isString(t.cdr.cdr.car)){r=t.cdr.cdr.car.valueOf()}n.set(t.car,e,r,true)})}),'(define name expression)\n (define name expression "doc string")\n (define (function-name . args) . body)\n\n Macro for defining values. It can be used to define variables,\n or functions. If the first argument is list it will create a function\n with name being first element of the list. This form expands to\n `(define function-name (lambda args body))`'),"set-obj!":doc("set-obj!",function(e,r,t){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;var i=_typeof$1(e);if(is_null(e)||i!=="object"&&i!=="function"){var o=typeErrorMessage("set-obj!",type(e),["object","function"]);throw new Error(o)}typecheck("set-obj!",r,["string","symbol","number"]);e=unbind(e);r=r.valueOf();if(arguments.length===2){delete e[r]}else if(is_prototype(e)&&is_function(t)){e[r]=unbind(t);e[r][__prototype__]=true}else if(is_function(t)||is_native(t)||is_nil(t)){e[r]=t}else{e[r]=t&&!is_prototype(t)?t.valueOf():t}if(props){var a=e[r];Object.defineProperty(e,r,_objectSpread(_objectSpread({},n),{},{value:a}))}},"(set-obj! obj key value)\n (set-obj! obj key value props)\n\n Function set a property of a JavaScript object. props should be a vector of pairs,\n passed to Object.defineProperty."),"null-environment":doc("null-environment",function(){return global_env.inherit("null")},"(null-environment)\n\n Returns a clean environment with only the standard library."),values:doc("values",function e(){for(var r=arguments.length,t=new Array(r),n=0;n1&&arguments[1]!==undefined?arguments[1]:{},m=e.use_dynamic,v=e.error;var g=this;var b;if(is_pair(h.cdr)&&LString.isString(h.cdr.car)&&!is_nil(h.cdr.cdr)){b=h.cdr.car.valueOf()}function P(){var e=is_context(this)?this:{dynamic_env:g},t=e.dynamic_env;var n=g.inherit("lambda");t=t.inherit("lambda");if(this&&!is_context(this)){if(this&&!this.__instance__){Object.defineProperty(this,"__instance__",{enumerable:false,get:function e(){return true},set:function e(){},configurable:false})}n.set("this",this)}for(var r=arguments.length,i=new Array(r),o=0;o> SYNTAX");log(e);log(v);var n=P.inherit("syntax");var i=n;var o=this;if(o.__name__===Syntax.__merge_env__){var a=Object.getOwnPropertySymbols(o.__env__);a.forEach(function(e){o.__parent__.set(e,o.__env__[e])});o=o.__parent__}var u={env:n,dynamic_env:i,use_dynamic:g,error:b};var s,c,l;if(v.car instanceof LSymbol){s=v.car;l=w(v.cdr.car);c=v.cdr.cdr}else{s="...";l=w(v.car);c=v.cdr}try{while(!is_nil(c)){var f=c.car.car;var _=c.car.cdr.car;log("[[[ RULE");log(f);var p=extract_patterns(f,e,l,s,{expansion:this,define:P});if(p){if(is_debug()){console.log(JSON.stringify(symbolize(p),true,2));console.log("PATTERN: "+f.toString(true));console.log("MACRO: "+e.toString(true))}var d=[];var y=transform_syntax({bindings:p,expr:_,symbols:l,scope:n,lex_scope:o,names:d,ellipsis:s});log("OUPUT>>> ",y);if(y){_=y}var h=o.merge(n,Syntax.__merge_env__);if(t){return{expr:_,scope:h}}var m=_evaluate(_,_objectSpread(_objectSpread({},u),{},{env:h}));return clear_gensyms(m,d)}c=c.cdr}}catch(e){e.message+="\nin macro:\n ".concat(v.toString(true));throw e}throw new Error("syntax-rules: no matching syntax in macro ".concat(e.toString(true)))},P);t.__code__=v;return t},"(syntax-rules () (pattern expression) ...)\n\n Base of hygienic macros, it will return a new syntax expander\n that works like Lisp macros."),quote:doc(new Macro("quote",function(e){return quote(e.car)}),"(quote expression) or 'expression\n\n Macro that returns a single LIPS expression as data (it won't evaluate the\n argument). It will return a list if put in front of LIPS code.\n And if put in front of a symbol it will return the symbol itself, not the value\n bound to that name."),"unquote-splicing":doc("unquote-splicing",function(){throw new Error("You can't call `unquote-splicing` outside of quasiquote")},"(unquote-splicing code) or ,@code\n\n Special form used in the quasiquote macro. It evaluates the expression inside and\n splices the list into quasiquote's result. If it is not the last element of the\n expression, the computed value must be a pair."),unquote:doc("unquote",function(){throw new Error("You can't call `unquote` outside of quasiquote")},"(unquote code) or ,code\n\n Special form used in the quasiquote macro. It evaluates the expression inside and\n substitutes the value into quasiquote's result."),quasiquote:Macro.defmacro("quasiquote",function(e,r){var u=r.use_dynamic,s=r.error;var c=this;var l=c;function o(e){return is_pair(e)||is_plain_object(e)||Array.isArray(e)}function f(e,r){var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:o;if(is_pair(e)){var n=e.car;var i=e.cdr;if(t(n)){n=r(n)}if(t(i)){i=r(i)}if(is_promise(n)||is_promise(i)){return promise_all([n,i]).then(function(e){var r=_slicedToArray(e,2),t=r[0],n=r[1];return new Pair(t,n)})}else{return new Pair(n,i)}}return e}function a(e,r){if(is_pair(e)){if(!is_nil(r)){e.append(r)}}else{e=new Pair(e,r)}return e}function t(e){return!!e.filter(function(e){return is_pair(e)&&LSymbol.is(e.car,/^(unquote|unquote-splicing)$/)}).length}function _(e,n,i){return e.reduce(function(e,r){if(!is_pair(r)){e.push(r);return e}if(LSymbol.is(r.car,"unquote-splicing")){var t;if(n+11){var r="You can't splice multiple atoms inside list";throw new Error(r)}if(!(is_pair(i.cdr)&&is_nil(t[0]))){return t[0]}}t=t.map(function(e){if(y.has(e)){return e.clone()}else{y.add(e);return e}});var n=h(i.cdr,0,1);if(is_nil(n)&&is_nil(t[0])){return undefined}return unpromise(n,function(e){if(is_nil(t[0])){return e}if(t.length===1){return a(t[0],e)}var r=t.reduce(function(e,r){return a(e,r)});return a(r,e)})})}(i.car.cdr)}var y=new Set;function h(e,r,t){if(is_pair(e)){if(is_pair(e.car)){if(LSymbol.is(e.car.car,"unquote-splicing")){return d(e,r+1,t)}if(LSymbol.is(e.car.car,"unquote")){if(r+2===t&&is_pair(e.car.cdr)&&is_pair(e.car.cdr.car)&&LSymbol.is(e.car.cdr.car.car,"unquote-splicing")){var n=e.car.cdr;return new Pair(new Pair(new LSymbol("unquote"),d(n,r+2,t)),_nil)}else if(is_pair(e.car.cdr)&&!is_nil(e.car.cdr.cdr)){if(is_pair(e.car.cdr.car)){var i=[];return function r(t){if(is_nil(t)){return Pair.fromArray(i)}return unpromise(_evaluate(t.car,{env:c,dynamic_env:l,use_dynamic:u,error:s}),function(e){i.push(e);return r(t.cdr)})}(e.car.cdr)}else{return e.car.cdr}}}}if(LSymbol.is(e.car,"quasiquote")){var o=h(e.cdr,r,t+1);return new Pair(e.car,o)}if(LSymbol.is(e.car,"quote")){return new Pair(e.car,h(e.cdr,r,t))}if(LSymbol.is(e.car,"unquote")){r++;if(rt){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(is_pair(e.cdr)){if(!is_nil(e.cdr.cdr)){if(is_pair(e.cdr.car)){var a=[];return function r(t){if(is_nil(t)){return Pair.fromArray(a)}return unpromise(_evaluate(t.car,{env:c,dynamic_env:l,use_dynamic:u,error:s}),function(e){a.push(e);return r(t.cdr)})}(e.cdr)}else{return e.cdr}}else{return _evaluate(e.cdr.car,{env:c,dynamic_env:l,error:s})}}else{return e.cdr}}return f(e,function(e){return h(e,r,t)})}else if(is_plain_object(e)){return p(e,r,t)}else if(e instanceof Array){return _(e,r,t)}return e}function n(e){if(is_pair(e)){delete e[__data__];if(!e.have_cycles("car")){n(e.car)}if(!e.have_cycles("cdr")){n(e.cdr)}}}if(is_plain_object(e.car)&&!t(Object.values(e.car))){return quote(e.car)}if(Array.isArray(e.car)&&!t(e.car)){return quote(e.car)}if(is_pair(e.car)&&!e.car.find("unquote")&&!e.car.find("unquote-splicing")&&!e.car.find("quasiquote")){return quote(e.car)}var i=h(e.car,0,1);return unpromise(i,function(e){n(e);return quote(e)})},"(quasiquote list)\n\n Similar macro to `quote` but inside it you can use special expressions (unquote\n x) abbreviated to ,x that will evaluate x and insert its value verbatim or\n (unquote-splicing x) abbreviated to ,@x that will evaluate x and splice the value\n into the result. Best used with macros but it can be used outside."),clone:doc("clone",function e(r){typecheck("clone",r,"pair");return r.clone()},"(clone list)\n\n Function that returns a clone of the list, that does not share any pairs with the\n original, so the clone can be safely mutated without affecting the original."),append:doc("append",function e(){var r;for(var t=arguments.length,n=new Array(t),i=0;iarray")(r).reverse();return global_env.get("array->list")(t)}else if(Array.isArray(r)){return r.reverse()}else{throw new Error(typeErrorMessage("reverse",type(r),"array or pair"))}},"(reverse list)\n\n Function that reverses the list or array. If value is not a list\n or array it will error."),nth:doc("nth",function e(r,t){typecheck("nth",r,"number");typecheck("nth",t,["array","pair"]);if(is_pair(t)){var n=t;var i=0;while(iarray")(t).join(r)},"(join separator list)\n\n Function that returns a string by joining elements of the list using separator."),split:doc("split",function e(r,t){typecheck("split",r,["regex","string"]);typecheck("split",t,"string");return global_env.get("array->list")(t.split(r))},"(split separator string)\n\n Function that creates a list by splitting string by separator which can\n be a string or regular expression."),replace:doc("replace",function e(r,t,n){typecheck("replace",r,["regex","string"]);typecheck("replace",t,["string","function"]);typecheck("replace",n,"string");if(is_function(t)){var i=[];n.replace(r,function(){i.push(t.apply(void 0,arguments))});return unpromise(i,function(e){return n.replace(r,function(){return e.shift()})})}return n.replace(r,t)},"(replace pattern replacement string)\n\n Function that changes pattern to replacement inside string. Pattern can be a\n string or regex and replacement can be function or string. See Javascript\n String.replace()."),match:doc("match",function e(r,t){typecheck("match",r,["regex","string"]);typecheck("match",t,"string");var n=t.match(r);return n?global_env.get("array->list")(n):false},"(match pattern string)\n\n Function that returns a match object from JavaScript as a list or #f if\n no match."),search:doc("search",function e(r,t){typecheck("search",r,["regex","string"]);typecheck("search",t,"string");return t.search(r)},"(search pattern string)\n\n Function that returns the first found index of the pattern inside a string."),repr:doc("repr",function e(r,t){return toString(r,t)},"(repr obj)\n\n Function that returns a LIPS code representation of the object as a string."),"escape-regex":doc("escape-regex",function(e){typecheck("escape-regex",e,"string");return escape_regex(e.valueOf())},"(escape-regex string)\n\n Function that returns a new string where all special operators used in regex,\n are escaped with backslashes so they can be used in the RegExp constructor\n to match a literal string."),env:doc("env",function e(e){e=e||this.env;var r=Object.keys(e.__env__).map(LSymbol);var t;if(r.length){t=Pair.fromArray(r)}else{t=_nil}if(e.__parent__ instanceof Environment){return global_env.get("env").call(this,e.__parent__).append(t)}return t},"(env)\n (env obj)\n\n Function that returns a list of names (functions, macros and variables)\n that are bound in the current environment or one of its parents."),new:doc("new",function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n2&&arguments[2]!==undefined?arguments[2]:specials.LITERAL;typecheck("set-special!",e,"string",1);typecheck("set-special!",r,"symbol",2);specials.append(e.valueOf(),r,t)},'(set-special! symbol name [type])\n\n Add a special symbol to the list of transforming operators by the parser.\n e.g.: `(add-special! "#" \'x)` will allow to use `#(1 2 3)` and it will be\n transformed into (x (1 2 3)) so you can write x macro that will process\n the list. 3rd argument is optional, and it can be one of two values:\n lips.specials.LITERAL, which is the default behavior, or\n lips.specials.SPLICE which causes the value to be unpacked into the expression.\n This can be used for e.g. to make `#(1 2 3)` into (x 1 2 3) that is needed\n by # that defines vectors.'),get:get,".":get,unbind:doc(unbind,"(unbind fn)\n\n Function that removes the weak 'this' binding from a function so you\n can get properties from the actual function object."),type:doc(type,"(type object)\n\n Function that returns the type of an object as string."),debugger:doc("debugger",function(){debugger},'(debugger)\n\n Function that triggers the JavaScript debugger (e.g. the browser devtools)\n using the "debugger;" statement. If a debugger is not running this\n function does nothing.'),in:doc("in",function(e,r){if(e instanceof LSymbol||e instanceof LString||e instanceof LNumber){e=e.valueOf()}return e in unbox(r)},'(in key value)\n\n Function that uses the Javascript "in" operator to check if key is\n a valid property in the value.'),"instance?":doc("instance?",function(e){return is_instance(e)},"(instance? obj)\n\n Checks if object is an instance, created with a new operator"),instanceof:doc("instanceof",function(e,r){return r instanceof unbind(e)},"(instanceof type obj)\n\n Predicate that tests if the obj is an instance of type."),"prototype?":doc("prototype?",is_prototype,"(prototype? obj)\n\n Predicate that tests if value is a valid JavaScript prototype,\n i.e. calling (new) with it will not throw ' is not a constructor'."),"macro?":doc("macro?",function(e){return e instanceof Macro},"(macro? expression)\n\n Predicate that tests if value is a macro."),"continuation?":doc("continuation?",is_continuation,"(continuation? expression)\n\n Predicate that tests if value is a callable continuation."),"function?":doc("function?",is_function,"(function? expression)\n\n Predicate that tests if value is a callable function."),"real?":doc("real?",function(e){if(type(e)!=="number"){return false}if(e instanceof LNumber){return e.isFloat()}return LNumber.isFloat(e)},"(real? number)\n\n Predicate that tests if value is a real number (not complex)."),"number?":doc("number?",function(e){return Number.isNaN(e)||LNumber.isNumber(e)},"(number? expression)\n\n Predicate that tests if value is a number or NaN value."),"string?":doc("string?",function(e){return LString.isString(e)},"(string? expression)\n\n Predicate that tests if value is a string."),"pair?":doc("pair?",is_pair,"(pair? expression)\n\n Predicate that tests if value is a pair or list structure."),"regex?":doc("regex?",function(e){return e instanceof RegExp},"(regex? expression)\n\n Predicate that tests if value is a regular expression."),"null?":doc("null?",function(e){return is_null(e)},"(null? expression)\n\n Predicate that tests if value is null-ish (i.e. undefined, nil, or\n Javascript null)."),"boolean?":doc("boolean?",function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Predicate that tests if value is a boolean (#t or #f)."),"symbol?":doc("symbol?",function(e){return e instanceof LSymbol},"(symbol? expression)\n\n Predicate that tests if value is a LIPS symbol."),"array?":doc("array?",function(e){return e instanceof Array},"(array? expression)\n\n Predicate that tests if value is an array."),"object?":doc("object?",function(e){return!is_nil(e)&&e!==null&&!(e instanceof LCharacter)&&!(e instanceof RegExp)&&!(e instanceof LString)&&!is_pair(e)&&!(e instanceof LNumber)&&_typeof$1(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Predicate that tests if value is an plain object (not another LIPS type)."),flatten:doc("flatten",function e(r){typecheck("flatten",r,"pair");return r.flatten()},"(flatten list)\n\n Returns a shallow list from tree structure (pairs)."),"array->list":doc("array->list",function(e){typecheck("array->list",e,"array");return Pair.fromArray(e)},"(array->list array)\n\n Function that converts a JavaScript array to a LIPS cons list."),"tree->array":doc("tree->array",to_array("tree->array",true),"(tree->array list)\n\n Function that converts a LIPS cons tree structure into a JavaScript array."),"list->array":doc("list->array",to_array("list->array"),"(list->array list)\n\n Function that converts a LIPS list into a JavaScript array."),apply:doc("apply",function e(r){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;iarray").call(this,o));return r.apply(this,prepare_fn_args(r,n))},"(apply fn list)\n\n Function that calls fn with the list of arguments."),length:doc("length",function e(r){if(!r||is_nil(r)){return 0}if(is_pair(r)){return r.length()}if("length"in r){return r.length}},'(length expression)\n\n Function that returns the length of the object. The object can be a LIPS\n list or any object that has a "length" property. Returns undefined if the\n length could not be found.'),"string->number":doc("string->number",function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;typecheck("string->number",e,"string",1);typecheck("string->number",r,"number",2);e=e.valueOf();r=r.valueOf();if(e.match(rational_bare_re)||e.match(rational_re)){return parse_rational(e,r)}else if(e.match(complex_bare_re)||e.match(complex_re)){return parse_complex(e,r)}else{var t=r===10&&!e.match(/e/i)||r===16;if(e.match(int_bare_re)&&t||e.match(int_re)){return parse_integer(e,r)}if(e.match(float_re)){return parse_float(e)}}return false},"(string->number number [radix])\n\n Function that parses a string into a number."),try:doc(new Macro("try",function(t,e){var f=this;var _=e.use_dynamic;e.error;return new Promise(function(r,u){var s,n;if(LSymbol.is(t.cdr.car.car,"catch")){s=t.cdr.car;if(is_pair(t.cdr.cdr)&&LSymbol.is(t.cdr.cdr.car.car,"finally")){n=t.cdr.cdr.car}}else if(LSymbol.is(t.cdr.car.car,"finally")){n=t.cdr.car}if(!(n||s)){throw new Error("try: invalid syntax")}function c(e){r(e);throw new IgnoreException("[CATCH]")}var l=function e(r,t){t(r)};if(n){l=function e(r,t){l=u;i.error=function(e){throw e};unpromise(_evaluate(new Pair(new LSymbol("begin"),n.cdr),i),function(){t(r)})}}var i={env:f,use_dynamic:_,dynamic_env:f,error:function e(r){if(r instanceof IgnoreException){throw r}if(s){var t=f.inherit("try");var n=s.cdr.car.car;if(!(n instanceof LSymbol)){throw new Error("try: invalid syntax: catch require variable name")}t.set(n,r);var i;var o={env:t,use_dynamic:_,dynamic_env:f,error:function e(r){i=true;u(r);throw new IgnoreException("[CATCH]")}};var a=_evaluate(new Pair(new LSymbol("begin"),s.cdr.cdr),o);unpromise(a,function e(r){if(!i){l(r,c)}})}else{l(undefined,function(){u(r)})}}};var e=_evaluate(t.car,i);unpromise(e,function(e){l(e,r)},i.error)})}),"(try expr (catch (e) code))\n (try expr (catch (e) code) (finally code))\n (try expr (finally code))\n\n Macro that executes expr and catches any exceptions thrown. If catch is provided\n it's executed when an error is thrown. If finally is provided it's always\n executed at the end."),raise:doc("raise",function(e){throw e},"(raise obj)\n\n Throws the object verbatim (no wrapping an a new Error)."),throw:doc("throw",function(e){throw new Error(e)},"(throw string)\n\n Throws a new exception."),find:doc("find",function r(t,n){typecheck("find",t,["regex","function"]);typecheck("find",n,["pair","nil"]);if(is_null(n)){return _nil}var e=matcher("find",t);return unpromise(e(n.car),function(e){if(e&&!is_nil(e)){return n.car}return r(t,n.cdr)})},"(find fn list)\n (find regex list)\n\n Higher-order function that finds the first value for which fn return true.\n If called with a regex it will create a matcher function."),"for-each":doc("for-each",function(e){var r;typecheck("for-each",e,"function");for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i1?r-1:0),o=1;o3?n-3:0),o=3;o3?i-3:0),a=3;aarray")(t);var o=[];var a=matcher("filter",r);return function r(t){function e(e){if(e&&!is_nil(e)){o.push(n)}return r(++t)}if(t===i.length){return Pair.fromArray(o)}var n=i[t];return unpromise(a(n),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher-order function that calls `fn` for each element of the list\n and return a new list for only those elements for which fn returns\n a truthy value. If called with a regex it will create a matcher function."),compose:doc(compose,"(compose . fns)\n\n Higher-order function that creates a new function that applies all functions\n from right to left and returns the last value. Reverse of pipe.\n e.g.:\n ((compose (curry + 2) (curry * 3)) 10) --\x3e (+ 2 (* 3 10)) --\x3e 32"),pipe:doc(pipe,"(pipe . fns)\n\n Higher-order function that creates a new function that applies all functions\n from left to right and returns the last value. Reverse of compose.\n e.g.:\n ((pipe (curry + 2) (curry * 3)) 10) --\x3e (* 3 (+ 2 10)) --\x3e 36"),curry:doc(curry,"(curry fn . args)\n\n Higher-order function that creates a curried version of the function.\n The result function will have partially applied arguments and it\n will keep returning one-argument functions until all arguments are provided,\n then it calls the original function with the accumulated arguments.\n\n e.g.:\n (define (add a b c d) (+ a b c d))\n (define add1 (curry add 1))\n (define add12 (add 2))\n (display (add12 3 4))"),gcd:doc("gcd",function e(){for(var r=arguments.length,t=new Array(r),n=0;nu?o%=u:u%=o}o=abs(s*t[a])/(o+u)}return LNumber(o)},"(lcm n1 n2 ...)\n\n Function that returns the least common multiple of the arguments."),"odd?":doc("odd?",single_math_op(function(e){return LNumber(e).isOdd()}),"(odd? number)\n\n Checks if number is odd."),"even?":doc("even?",single_math_op(function(e){return LNumber(e).isEven()}),"(even? number)\n\n Checks if number is even."),"*":doc("*",reduce_math_op(function(e,r){return LNumber(e).mul(r)},LNumber(1)),"(* . numbers)\n\n Multiplies all numbers passed as arguments. If single value is passed\n it will return that value."),"+":doc("+",reduce_math_op(function(e,r){return LNumber(e).add(r)},LNumber(0)),"(+ . numbers)\n\n Sums all numbers passed as arguments. If single value is passed it will\n return that value."),"-":doc("-",function(){for(var e=arguments.length,r=new Array(e),t=0;t":doc(">",function(){for(var e=arguments.length,r=new Array(e),t=0;t",r,["bigint","float","rational"]);return seq_compare(function(e,r){return LNumber(e).cmp(r)===1},r)},"(> x1 x2 x3 ...)\n\n Function that compares its numerical arguments and checks if they are\n monotonically decreasing, i.e. x1 > x2 and x2 > x3 and so on."),"<":doc("<",function(){for(var e=arguments.length,r=new Array(e),t=0;t=":doc(">=",function(){for(var e=arguments.length,r=new Array(e),t=0;t=",r,["bigint","float","rational"]);return seq_compare(function(e,r){return[0,1].includes(LNumber(e).cmp(r))},r)},"(>= x1 x2 ...)\n\n Function that compares its numerical arguments and checks if they are\n monotonically nonincreasing, i.e. x1 >= x2 and x2 >= x3 and so on."),"eq?":doc("eq?",equal,"(eq? a b)\n\n Function that compares two values if they are identical."),or:doc(new Macro("or",function(e,r){var i=r.use_dynamic,o=r.error;var a=global_env.get("list->array")(e);var u=this;var s=u;if(!a.length){return false}var c;return function r(){function e(e){c=e;if(!is_false(c)){return c}else{return r()}}if(!a.length){if(!is_false(c)){return c}else{return false}}else{var t=a.shift();var n=_evaluate(t,{env:u,dynamic_env:s,use_dynamic:i,error:o});return unpromise(n,e)}}()}),"(or . expressions)\n\n Macro that executes the values one by one and returns the first that is\n a truthy value. If there are no expressions that evaluate to true it\n returns false."),and:doc(new Macro("and",function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},t=r.use_dynamic,n=r.error;var i=global_env.get("list->array")(e);var o=this;var a=o;if(!i.length){return true}var u;var s={env:o,dynamic_env:a,use_dynamic:t,error:n};return function r(){function e(e){u=e;if(is_false(u)){return u}else{return r()}}if(!i.length){if(!is_false(u)){return u}else{return false}}else{var t=i.shift();return unpromise(_evaluate(t,s),e)}}()}),"(and . expressions)\n\n Macro that evaluates each expression in sequence and if any value returns false\n it will stop and return false. If each value returns true it will return the\n last value. If it's called without arguments it will return true."),"|":doc("|",function(e,r){return LNumber(e).or(r)},"(| a b)\n\n Function that calculates the bitwise or operation."),"&":doc("&",function(e,r){return LNumber(e).and(r)},"(& a b)\n\n Function that calculates the bitwise and operation."),"~":doc("~",function(e){return LNumber(e).neg()},"(~ number)\n\n Function that calculates the bitwise inverse (flip all the bits)."),">>":doc(">>",function(e,r){return LNumber(e).shr(r)},"(>> a b)\n\n Function that right shifts the value a by value b bits."),"<<":doc("<<",function(e,r){return LNumber(e).shl(r)},"(<< a b)\n\n Function that left shifts the value a by value b bits."),not:doc("not",function e(r){if(is_null(r)){return true}return!r},"(not object)\n\n Function that returns the Boolean negation of its argument.")},undefined,"global");var user_env=global_env.inherit("user-env");function set_interaction_env(e,r){e.constant("**internal-env**",r);e.doc("**internal-env**","**internal-env**\n\n Constant used to hide stdin, stdout and stderr so they don't interfere\n with variables with the same name. Constants are an internal type\n of variable that can't be redefined, defining a variable with the same name\n will throw an error.");global_env.set("**interaction-environment**",e)}set_interaction_env(user_env,internal_env);global_env.doc("**interaction-environment**","**interaction-environment**\n\n Internal dynamic, global variable used to find interpreter environment.\n It's used so the read and write functions can locate **internal-env**\n that contains the references to stdin, stdout and stderr.");function set_fs(e){user_env.get("**internal-env**").set("fs",e)}(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(r){var t=e[r]?e[r]:r;global_env.set(t,doc(t,function(e){typecheck(t,e,"number");if(e instanceof LNumber){return e[r]()}},"(".concat(t," number)\n\n Function that calculates the ").concat(t," of a number.")))})})();function allPossibleCases(e){if(e.length===1){return e[0]}else{var r=[];var t=allPossibleCases(e.slice(1));for(var n=0;n3&&arguments[3]!==undefined?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(n!==null){i+=" (argument ".concat(n,")")}if(is_function(t)){return"Invalid type: got ".concat(r).concat(i)}if(t instanceof Array){if(t.length===1){var o=t[0].toLowerCase();t="a"+("aeiou".includes(o)?"n ":" ")+t[0]}else{t=new Intl.ListFormat("en",{style:"long",type:"disjunction"}).format(t)}}return"Expecting ".concat(t," got ").concat(r).concat(i)}function typecheck_number(e,r,t){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;typecheck(e,r,"number",n);var i=r.__type__;var o;if(is_pair(t)){t=t.to_array()}if(t instanceof Array){t=t.map(function(e){return e.valueOf()})}if(t instanceof Array){t=t.map(function(e){return e.valueOf().toLowerCase()});if(t.includes(i)){o=true}}else{t=t.valueOf().toLowerCase()}if(!o&&i!==t){throw new Error(typeErrorMessage(e,i,t,n))}}function typecheck_numbers(t,e,n){e.forEach(function(e,r){typecheck_number(t,e,n,r+1)})}function typecheck_args(t,e,n){e.forEach(function(e,r){typecheck(t,e,n,r+1)})}function typecheck_text_port(e,r,t){typecheck(e,r,t);if(r.__type__===binary_port){throw new Error(typeErrorMessage(e,"binary-port","textual-port"))}}function typecheck(e,r,t){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;e=e.valueOf();var i=type(r).toLowerCase();if(is_function(t)){if(!t(r)){throw new Error(typeErrorMessage(e,i,t,n))}return}var o=false;if(is_pair(t)){t=t.to_array()}if(t instanceof Array){t=t.map(function(e){return e.valueOf()})}if(t instanceof Array){t=t.map(function(e){return e.valueOf().toLowerCase()});if(t.includes(i)){o=true}}else{t=t.valueOf().toLowerCase()}if(!o&&i!==t){throw new Error(typeErrorMessage(e,i,t,n))}}function memoize(t){var n=new WeakMap;return function(e){var r=n.get(e);if(!r){r=t(e)}return r}}type=memoize(type);function type(e){var r=type_constants.get(e);if(r){return r}if(_typeof$1(e)==="object"){for(var t=0,n=Object.entries(type_mapping);t2&&arguments[2]!==undefined?arguments[2]:{},n=t.env,i=t.dynamic_env,o=t.use_dynamic;var a=n===null||n===void 0?void 0:n.new_frame(e,r);var u=i===null||i===void 0?void 0:i.new_frame(e,r);var s=new LambdaContext({env:a,use_dynamic:o,dynamic_env:u});return resolve_promises(e.apply(s,r))}function apply(n,e){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},i=r.env,o=r.dynamic_env,a=r.use_dynamic,t=r.error,u=t===void 0?function(){}:t;e=evaluate_args(e,{env:i,dynamic_env:o,error:u,use_dynamic:a});return unpromise(e,function(e){if(is_raw_lambda(n)){n=unbind(n)}e=prepare_fn_args(n,e);var r=e.slice();var t=call_function(n,r,{env:i,dynamic_env:o,use_dynamic:a});return unpromise(t,function(e){if(is_pair(e)){e.mark_cycles();return quote(e)}return box(e)},u)})}var _p_name__=new WeakMap;var Parameter=function(){function n(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;_classCallCheck(this,n);_defineProperty(this,"__value__",void 0);_defineProperty(this,"__fn__",void 0);_classPrivateFieldInitSpec(this,_p_name__,{writable:true,value:void 0});this.__value__=e;if(r){if(!is_function(r)){throw new Error("Section argument to Parameter need to be function "+"".concat(type(r)," given"))}this.__fn__=r}if(t){_classPrivateFieldSet(this,_p_name__,t)}}_createClass(n,[{key:"__name__",get:function e(){return _classPrivateFieldGet(this,_p_name__)},set:function e(r){_classPrivateFieldSet(this,_p_name__,r);if(this.__fn__){this.__fn__.__name__="fn-".concat(r)}}},{key:"invoke",value:function e(){if(is_function(this.__fn__)){return this.__fn__(this.__value__)}return this.__value__}},{key:"inherit",value:function e(r){return new n(r,this.__fn__,this.__name__)}}]);return n}();var LambdaContext=function(){function r(e){_classCallCheck(this,r);_defineProperty(this,"env",void 0);_defineProperty(this,"dynamic_env",void 0);_defineProperty(this,"use_dynamic",void 0);Object.assign(this,e)}_createClass(r,[{key:"__name__",get:function e(){return this.env.__name__}},{key:"__parent__",get:function e(){return this.env.__parent__}},{key:"get",value:function e(){var r;return(r=this.env).get.apply(r,arguments)}}]);return r}();function search_param(e,r){var t=e.get(r.__name__,{throwError:false});if(is_parameter(t)&&t!==r){return t}var n=user_env.get("**interaction-environment**");while(true){var i=e.get("parent.frame",{throwError:false});e=i(0);if(e===n){break}t=e.get(r.__name__,{throwError:false});if(is_parameter(t)&&t!==r){return t}}return r}var Continuation=function(){function r(e){_classCallCheck(this,r);_defineProperty(this,"__value__",void 0);this.__value__=e}_createClass(r,[{key:"invoke",value:function e(){if(this.__value__===null){throw new Error("Continuations are not implemented yet")}}}]);return r}();function _evaluate(u){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},s=e.env,c=e.dynamic_env,l=e.use_dynamic,r=e.error,f=r===void 0?noop:r,t=_objectWithoutProperties(e,_excluded6);return function(e){try{if(!is_env(c)){c=s===true?user_env:s||user_env}if(l){s=c}else if(s===true){s=user_env}else{s=s||global_env}var r={env:s,dynamic_env:c,use_dynamic:l,error:f};var t;if(is_null(u)){return u}if(u instanceof LSymbol){return s.get(u)}if(!is_pair(u)){return u}var n=u.car;var e=u.cdr;if(is_pair(n)){t=resolve_promises(_evaluate(n,r));if(is_promise(t)){return t.then(function(e){if(!is_callable(e)){throw new Error(type(e)+" "+s.get("repr")(e)+" is not callable while evaluating "+u.toString())}return _evaluate(new Pair(e,u.cdr),r)})}else if(!is_callable(t)){throw new Error(type(t)+" "+s.get("repr")(t)+" is not callable while evaluating "+u.toString())}}if(n instanceof LSymbol){t=s.get(n)}else if(is_function(n)){t=n}var i;if(t instanceof Syntax){i=evaluate_syntax(t,u,r)}else if(t instanceof Macro){i=evaluate_macro(t,e,r)}else if(is_function(t)){i=apply(t,e,r)}else if(t instanceof SyntaxParameter){i=evaluate_syntax(t._syntax,u,r)}else if(is_parameter(t)){var o=search_param(c,t);if(is_null(u.cdr)){i=o.invoke()}else{return unpromise(_evaluate(u.cdr.car,r),function(e){o.__value__=e})}}else if(is_continuation(t)){i=t.invoke()}else if(is_pair(u)){t=n&&n.toString();throw new Error("".concat(type(n)," ").concat(t," is not a function"))}else{return u}var a=s.get(Symbol["for"]("__promise__"),{throwError:false});if(a===true&&is_promise(i)){i=i.then(function(e){if(is_pair(e)&&!t[__data__]){return _evaluate(e,r)}return e});return new QuotedPromise(i)}return i}catch(e){f&&f.call(s,e,u)}}(t)}var compile=exec_collect(function(e){return e});var exec=exec_collect(function(e,r){return r});function exec_with_stacktrace(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},t=r.env,n=r.dynamic_env,i=r.use_dynamic;return _evaluate(e,{env:t,dynamic_env:n,use_dynamic:i,error:function e(r,t){if(r&&r.message){if(r.message.match(/^Error:/)){var n=/^(Error:)\s*([^:]+:\s*)/;r.message=r.message.replace(n,"$1 $2")}if(t){if(!(r.__code__ instanceof Array)){r.__code__=[]}r.__code__.push(t.toString(true))}}if(!(r instanceof IgnoreException)){throw r}}})}function exec_collect(y){return function(){var r=_asyncToGenerator(function(f){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},_=e.env,p=e.dynamic_env,d=e.use_dynamic;return _regeneratorRuntime.mark(function e(){var t,n,i,o,a,u,s,c,l;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:if(!is_env(p)){p=_===true?user_env:_||user_env}if(_===true){_=user_env}else{_=_||user_env}t=[];if(!is_pair(f)){r.next=8;break}r.next=6;return exec_with_stacktrace(f,{env:_,dynamic_env:p,use_dynamic:d});case 6:r.t0=r.sent;return r.abrupt("return",[r.t0]);case 8:n=Array.isArray(f)?f:_parse(f);i=false;o=false;r.prev=11;u=_asyncIterator(n);case 13:r.next=15;return u.next();case 15:if(!(i=!(s=r.sent).done)){r.next=31;break}c=s.value;r.next=19;return exec_with_stacktrace(c,{env:_,dynamic_env:p,use_dynamic:d});case 19:l=r.sent;r.t1=t;r.t2=y;r.t3=c;r.next=25;return l;case 25:r.t4=r.sent;r.t5=(0,r.t2)(r.t3,r.t4);r.t1.push.call(r.t1,r.t5);case 28:i=false;r.next=13;break;case 31:r.next=37;break;case 33:r.prev=33;r.t6=r["catch"](11);o=true;a=r.t6;case 37:r.prev=37;r.prev=38;if(!(i&&u["return"]!=null)){r.next=42;break}r.next=42;return u["return"]();case 42:r.prev=42;if(!o){r.next=45;break}throw a;case 45:return r.finish(42);case 46:return r.finish(37);case 47:return r.abrupt("return",t);case 48:case"end":return r.stop()}},e,null,[[11,33,37,47],[38,,42,46]])})()});function e(e){return r.apply(this,arguments)}return e}()}function balanced(e){var r={"[":"]","(":")"};var t;if(typeof e==="string"){t=tokenize(e)}else{t=e.map(function(e){return e&&e.token?e.token:e})}var n=Object.keys(r);var i=Object.values(r).concat(n);t=t.filter(function(e){return i.includes(e)});var o=new Stack;var a=_createForOfIteratorHelper(t),u;try{for(a.s();!(u=a.n()).done;){var s=u.value;if(n.includes(s)){o.push(s)}else if(!o.is_empty()){var c=o.top();var l=r[c];if(s===l){o.pop()}else{throw new Error("Syntax error: missing closing ".concat(l))}}else{throw new Error("Syntax error: not matched closing ".concat(s))}}}catch(e){a.e(e)}finally{a.f()}return o.is_empty()}function fworker(e){var r="("+e.toString()+")()";var t=window.URL||window.webkitURL;var n;try{n=new Blob([r],{type:"application/javascript"})}catch(e){var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;n=new i;n.append(r);n=n.getBlob()}return new root.Worker(t.createObjectURL(n))}function is_dev(){return lips.version.match(/^(\{\{VER\}\}|DEV)$/)}function get_current_script(){if(is_node()){return}var e;if(document.currentScript){e=document.currentScript}else{var r=document.querySelectorAll("script");if(!r.length){return}e=r[r.length-1]}var t=e.getAttribute("src");return t}var current_script=get_current_script();function bootstrap(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"";var r="dist/std.xcb";if(e===""){if(current_script){e=current_script.replace(/[^/]*$/,"std.xcb")}else if(is_dev()){e="https://cdn.jsdelivr.net/gh/jcubic/lips@devel/".concat(r)}else{e="https://cdn.jsdelivr.net/npm/@jcubic/lips@".concat(lips.version,"/").concat(r)}}var t=global_env.get("load");return t.call(user_env,e,global_env)}function Worker(e){this.url=e;var a=this.worker=fworker(function(){var a;var u;self.addEventListener("message",function(e){var t=e.data;var r=t.id;if(t.type!=="RPC"||r===null){return}function n(e){self.postMessage({id:r,type:"RPC",result:e})}function i(e){self.postMessage({id:r,type:"RPC",error:e})}if(t.method==="eval"){if(!u){i("Worker RPC: LIPS not initialized, call init first");return}u.then(function(){var e=t.params[0];var r=t.params[1];a.exec(e,{use_dynamic:r}).then(function(e){e=e.map(function(e){return e&&e.valueOf()});n(e)})["catch"](function(e){i(e)})})}else if(t.method==="init"){var o=t.params[0];if(typeof o!=="string"){i("Worker RPC: url is not a string")}else{importScripts("".concat(o,"/dist/lips.min.js"));a=new lips.Interpreter("worker");u=bootstrap(o);u.then(function(){n(true)})}}})});this.rpc=function(){var n=0;return function e(r,t){var o=++n;return new Promise(function(n,i){a.addEventListener("message",function e(r){var t=r.data;if(t&&t.type==="RPC"&&t.id===o){if(t.error){i(t.error)}else{n(t.result)}a.removeEventListener("message",e)}});a.postMessage({type:"RPC",method:r,id:o,params:t})})}}();this.rpc("init",[e])["catch"](function(e){console.error(e)});this.exec=function(e,r){var t=r.use_dynamic,n=t===void 0?false:t;return this.rpc("eval",[e,n])}}var serialization_map={pair:function e(r){var t=_slicedToArray(r,2),n=t[0],i=t[1];return Pair(n,i)},number:function e(r){if(LString.isString(r)){return LNumber([r,10])}return LNumber(r)},regex:function e(r){var t=_slicedToArray(r,2),n=t[0],i=t[1];return new RegExp(n,i)},nil:function e(){return _nil},symbol:function e(r){if(LString.isString(r)){return LSymbol(r)}else if(Array.isArray(r)){return LSymbol(Symbol["for"](r[0]))}},string:LString,character:LCharacter};var available_class=Object.keys(serialization_map);var class_map={};for(var _i6=0,_Object$entries3=Object.entries(available_class);_i6<_Object$entries3.length;_i6++){var _Object$entries3$_i=_slicedToArray(_Object$entries3[_i6],2),i=_Object$entries3$_i[0],cls=_Object$entries3$_i[1];class_map[cls]=+i}function mangle_name(e){return class_map[e]}function resolve_name(e){return available_class[e]}function serialize(e){return JSON.stringify(e,function(e,r){var t=this[e];if(t){if(t instanceof RegExp){return{"@":mangle_name("regex"),"#":[t.source,t.flags]}}var n=mangle_name(t.constructor.__class__);if(!is_undef(n)){return{"@":n,"#":t.serialize()}}}return r})}function unserialize(e){return JSON.parse(e,function(e,r){if(r&&_typeof$1(r)==="object"){if(!is_undef(r["@"])){var t=resolve_name(r["@"]);if(serialization_map[t]){return serialization_map[t](r["#"])}}}return r})}var cbor=function(){var e={pair:Pair,symbol:LSymbol,number:LNumber,string:LString,character:LCharacter,nil:_nil.constructor,regex:RegExp};function r(e,r){return{deserialize:r,Class:e}}var t=new Encoder;var o={};for(var n=0,i=Object.entries(serialization_map);n1){var n=r.reduce(function(e,r){return e+r.length},0);var i=new Uint8Array(n);var o=0;r.forEach(function(e){i.set(e,o);o+=e.length});return i}else if(r.length){return r[0]}}function encode_magic(){var e=1;var r=new TextEncoder("utf-8");return r.encode("LIPS".concat(e.toString().padStart(3," ")))}var MAGIC_LENGTH=7;function decode_magic(e){var r=new TextDecoder("utf-8");var t=r.decode(e.slice(0,MAGIC_LENGTH));var n=t.substring(0,4);if(n==="LIPS"){var i=t.match(/^(....).*([0-9]+)$/);if(i){return{type:i[1],version:Number(i[2])}}}return{type:"unknown"}}function serialize_bin(e){var r=encode_magic();var t=cbor.encode(e);return merge_uint8_array(r,pack_1(t,{magic:false}))}function unserialize_bin(e){var r=decode_magic(e),t=r.type,n=r.version;if(t==="LIPS"&&n===1){var i=unpack_1(e.slice(MAGIC_LENGTH),{magic:false});return cbor.decode(i)}else{throw new Error("Invalid file format ".concat(t))}}function execError(e){console.error(e.message||e);if(Array.isArray(e.code)){console.error(e.code.map(function(e,r){return"[".concat(r+1,"]: ").concat(e)}))}}function init(){var a=["text/x-lips","text/x-scheme"];var u;function s(e){var r;return(r=e.getAttribute("data-bootstrap"))!==null&&r!==void 0?r:e.getAttribute("bootstrap")}function c(t){return new Promise(function(r){var e=t.getAttribute("src");if(e){return fetch(e).then(function(e){return e.text()}).then(exec).then(r)["catch"](function(e){execError(e);r()})}else{return exec(t.innerHTML).then(r)["catch"](function(e){execError(e);r()})}})}function e(){return new Promise(function(i){var o=Array.from(document.querySelectorAll("script"));return function e(){var r=o.shift();if(!r){i()}else{var t=r.getAttribute("type");if(a.includes(t)){var n=s(r);if(!u&&typeof n==="string"){return bootstrap(n).then(function(){return c(r)}).then(e)}else{return c(r).then(e)}}else if(t&&t.match(/lips|lisp/)){console.warn("Expecting "+a.join(" or ")+" found "+t)}return e()}}()})}if(!window.document){return Promise.resolve()}else if(currentScript){var r=currentScript;var t=s(r);if(typeof t==="string"){return bootstrap(t).then(function(){u=true;return e()})}}return e()}var currentScript=typeof window!=="undefined"&&window.document&&document.currentScript;if(typeof window!=="undefined"){contentLoaded(window,init)}var banner=function(){var e=LString("Fri, 22 Mar 2024 13:26:48 +0000").valueOf();var r=e==="{{"+"DATE}}"?new Date:new Date(e);var t=function e(r){return r.toString().padStart(2,"0")};var n=r.getFullYear();var i=[n,t(r.getMonth()+1),t(r.getDate())].join("-");var o="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter DEV (".concat(i,") \nCopyright (c) 2018-").concat(n," Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables. You can also\nuse (help name) to display help for specific function or macro, (apropos name)\nto display list of matched names in environment and (dir object) to list\nproperties of an object.\n").replace(/^.*\n/,"");return o}();read_only(Ahead,"__class__","ahead");read_only(Pair,"__class__","pair");read_only(Nil,"__class__","nil");read_only(Pattern,"__class__","pattern");read_only(Formatter,"__class__","formatter");read_only(Macro,"__class__","macro");read_only(Syntax,"__class__","syntax");read_only(Syntax.Parameter,"__class__","syntax-parameter");read_only(Environment,"__class__","environment");read_only(InputPort,"__class__","input-port");read_only(OutputPort,"__class__","output-port");read_only(BufferedOutputPort,"__class__","output-port");read_only(OutputStringPort,"__class__","output-string-port");read_only(InputStringPort,"__class__","input-string-port");read_only(InputFilePort,"__class__","input-file-port");read_only(OutputFilePort,"__class__","output-file-port");read_only(LipsError,"__class__","lips-error");[LNumber,LComplex,LRational,LFloat,LBigInteger].forEach(function(e){read_only(e,"__class__","number")});read_only(LCharacter,"__class__","character");read_only(LSymbol,"__class__","symbol");read_only(LString,"__class__","string");read_only(QuotedPromise,"__class__","promise");read_only(Parameter,"__class__","parameter");var version="DEV";var date="Fri, 22 Mar 2024 13:26:48 +0000";var parse=compose(uniterate_async,_parse);var lips={version:version,banner:banner,date:date,exec:exec,parse:parse,tokenize:tokenize,evaluate:_evaluate,compile:compile,serialize:serialize,unserialize:unserialize,serialize_bin:serialize_bin,unserialize_bin:unserialize_bin,bootstrap:bootstrap,Environment:Environment,env:user_env,Worker:Worker,Interpreter:Interpreter,balanced_parenthesis:balanced,balancedParenthesis:balanced,balanced:balanced,Macro:Macro,Syntax:Syntax,Pair:Pair,Values:Values,QuotedPromise:QuotedPromise,Error:LipsError,quote:quote,InputPort:InputPort,OutputPort:OutputPort,BufferedOutputPort:BufferedOutputPort,InputFilePort:InputFilePort,OutputFilePort:OutputFilePort,InputStringPort:InputStringPort,OutputStringPort:OutputStringPort,InputByteVectorPort:InputByteVectorPort,OutputByteVectorPort:OutputByteVectorPort,InputBinaryFilePort:InputBinaryFilePort,OutputBinaryFilePort:OutputBinaryFilePort,set_fs:set_fs,Formatter:Formatter,Parser:Parser,Lexer:Lexer,specials:specials,repr:repr,nil:_nil,eof:eof,LSymbol:LSymbol,LNumber:LNumber,LFloat:LFloat,LComplex:LComplex,LRational:LRational,LBigInteger:LBigInteger,LCharacter:LCharacter,LString:LString,Parameter:Parameter,rationalize:rationalize};global_env.set("lips",lips);export{BufferedOutputPort,Environment,LipsError as Error,Formatter,InputBinaryFilePort,InputByteVectorPort,InputFilePort,InputPort,InputStringPort,Interpreter,LBigInteger,LCharacter,LComplex,LFloat,LNumber,LRational,LString,LSymbol,Lexer,Macro,OutputBinaryFilePort,OutputByteVectorPort,OutputFilePort,OutputPort,OutputStringPort,Pair,Parameter,Parser,QuotedPromise,Syntax,Values,Worker,is_directive as _is_directive,balanced,balanced as balancedParenthesis,balanced as balanced_parenthesis,banner,bootstrap,compile,date,user_env as env,eof,_evaluate as evaluate,exec,_nil as nil,parse,quote,rationalize,repr,serialize,serialize_bin,set_fs,specials,tokenize,unserialize,unserialize_bin,version}; \ No newline at end of file + */Object.defineProperty(lzjbPack,"__esModule",{value:true});const NBBY=8,MATCH_BITS=6,MATCH_MIN=3,MATCH_MAX=(1<t-MATCH_MAX){r[i++]=e[n++];continue}l=(e[n]+13^e[n+1]-13^e[n+2])&LEMPEL_SIZE-1;c=n-f[l]&OFFSET_MASK;f[l]=n;o=n-c;if(o>=0&&o!=n&&e[n]==e[o]&&e[n+1]==e[o+1]&&e[n+2]==e[o+2]){r[a]|=u;for(s=MATCH_MIN;s>NBBY;r[i++]=c;n+=s}else{r[i++]=e[n++]}}console.assert(e.length>=n);return i}function decompress(e,r,t){r=r|0;var n=0,i=0,o=0,a=0,u=1<<(NBBY-1|0),s=0,c=0;while(n>(NBBY-MATCH_BITS|0))+MATCH_MIN|0;c=(e[n]<4){t[i]=t[o];i=i+1|0;o=o+1|0;t[i]=t[o];i=i+1|0;o=o+1|0;t[i]=t[o];i=i+1|0;o=o+1|0;t[i]=t[o];i=i+1|0;o=o+1|0;s=s-4|0}while(s>0){t[i]=t[o];i=i+1|0;o=o+1|0;s=s-1|0}}}else{t[i]=e[n];i=i+1|0;n=n+1|0}}return i}function encode_magic$1(){const e=new TextEncoder("utf-8");return e.encode(MAGIC_STRING)}const MAGIC_STRING="@lzjb";const MAGIC=encode_magic$1();function merge_uint8_array$1(...e){if(e.length>1){const t=e.reduce((e,r)=>e+r.length,0);const n=new Uint8Array(t);let r=0;e.forEach(e=>{n.set(e,r);r+=e.length});return n}else if(e.length){return e[0]}}function number_to_bytes(r){const e=Math.ceil(Math.log2(r)/8);const t=new Uint8Array(e);for(let e=0;e=0;e--){t=t*256+r[e]}return t}function pack(e,{magic:r=true}={}){const t=new Uint8Array(Math.max(e.length*1.5|0,16*1024));const n=compress(e,t);const i=number_to_bytes(e.length);const o=[Uint8Array.of(i.length),i,t.slice(0,n)];if(r){o.unshift(MAGIC)}return merge_uint8_array$1(...o)}function unpack(r,{magic:e=true}={}){if(e){const e=new TextDecoder("utf-8");const s=e.decode(r.slice(0,MAGIC.length));if(s!==MAGIC_STRING){throw new Error("Invalid magic value")}}const t=e?MAGIC.length:0;const n=r[t];const i=t+1;const o=t+n+1;const a=bytes_to_number(r.slice(i,o));r=r.slice(o);const u=new Uint8Array(a);decompress(r,r.length,u);return u}var pack_1=lzjbPack.pack=pack;var unpack_1=lzjbPack.unpack=unpack;function unfetch(s,c){return c=c||{},new Promise(function(e,r){var t=new XMLHttpRequest,n=[],i=[],o={},a=function(){return{ok:2==(t.status/100|0),statusText:t.statusText,status:t.status,url:t.responseURL,text:function(){return Promise.resolve(t.responseText)},json:function(){return Promise.resolve(t.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([t.response]))},clone:a,headers:{keys:function(){return n},entries:function(){return i},get:function(e){return o[e.toLowerCase()]},has:function(e){return e.toLowerCase()in o}}}};for(var u in t.open(c.method||"get",s,!0),t.onload=function(){t.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,r,t){n.push(r=r.toLowerCase()),i.push([r,t]),o[r]=o[r]?o[r]+","+t:t}),e(a())},t.onerror=r,t.withCredentials="include"==c.credentials,c.headers)t.setRequestHeader(u,c.headers[u]);t.send(c.body||null)})}var _fold_case_mapping;var _excluded=["token"],_excluded2=["env"],_excluded3=["stderr","stdin","stdout","command_line"],_excluded4=["use_dynamic"],_excluded5=["use_dynamic"],_excluded6=["env","dynamic_env","use_dynamic","error"];function _classPrivateFieldInitSpec(e,r,t){_checkPrivateRedeclaration(e,r);r.set(e,t)}function _checkPrivateRedeclaration(e,r){if(r.has(e)){throw new TypeError("Cannot initialize the same private elements twice on an object")}}function _callSuper(e,r,t){return r=_getPrototypeOf(r),_possibleConstructorReturn(e,_isNativeReflectConstruct()?Reflect.construct(r,t||[],_getPrototypeOf(e).constructor):r.apply(e,t))}function _isNativeReflectConstruct(){try{var r=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(r){}return(_isNativeReflectConstruct=function e(){return!!r})()}function _createForOfIteratorHelper(r,e){var t=typeof Symbol!=="undefined"&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&typeof r.length==="number"){if(t)r=t;var n=0;var i=function e(){};return{s:i,n:function e(){if(n>=r.length)return{done:true};return{done:false,value:r[n++]}},e:function e(r){throw r},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o=true,a=false,u;return{s:function e(){t=t.call(r)},n:function e(){var r=t.next();o=r.done;return r},e:function e(r){a=true;u=r},f:function e(){try{if(!o&&t["return"]!=null)t["return"]()}finally{if(a)throw u}}}}function _unsupportedIterableToArray(e,r){if(!e)return;if(typeof e==="string")return _arrayLikeToArray(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);if(t==="Object"&&e.constructor)t=e.constructor.name;if(t==="Map"||t==="Set")return Array.from(e);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return _arrayLikeToArray(e,r)}function _arrayLikeToArray(e,r){if(r==null||r>e.length)r=e.length;for(var t=0,n=new Array(r);t1?t-1:0),i=1;i0&&arguments[0]!==undefined?arguments[0]:null;var r=user_env&&user_env.get("DEBUG",{throwError:false});if(e===null){return r===true}return(r===null||r===void 0?void 0:r.valueOf())===e.valueOf()}function num_mnemicic_re(e){return e?"(?:#".concat(e,"(?:#[ie])?|#[ie]#").concat(e,")"):"(?:#[ie])?"}function gen_rational_re(e,r){return"".concat(num_mnemicic_re(e),"[+-]?").concat(r,"+/").concat(r,"+")}function gen_complex_re(e,r){return"".concat(num_mnemicic_re(e),"(?:[+-]?(?:").concat(r,"+/").concat(r,"+|nan.0|inf.0|").concat(r,"+))?(?:[+-]i|[+-]?(?:").concat(r,"+/").concat(r,"+|").concat(r,"+|nan.0|inf.0)i)(?=[()[\\]\\s]|$)")}function gen_integer_re(e,r){return"".concat(num_mnemicic_re(e),"[+-]?").concat(r,"+")}var re_re=/^#\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimyus]*)$/;var float_stre="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)";var complex_float_stre="(?:#[ie])?(?:[+-]?(?:[0-9][0-9_]*/[0-9][0-9_]*|nan.0|inf.0|".concat(float_stre,"|[+-]?[0-9]+))?(?:").concat(float_stre,"|[+-](?:[0-9]+/[0-9]+|[0-9]+|nan.0|inf.0))i");var float_re=new RegExp("^(#[ie])?".concat(float_stre,"$"),"i");function make_complex_match_re(e,r){var t=e==="x"?"(?!\\+|".concat(r,")"):"(?!\\.|".concat(r,")");var n="";if(e===""){n="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+(?![0-9]))(?:[eE][-+]?[0-9]+)?))"}return new RegExp("^((?:(?:".concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(r,"+/").concat(r,"+(?!").concat(r,")|[+-]?").concat(r,"+)").concat(t,")?)(").concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(r,"+/").concat(r,"+|[+-]?").concat(r,"+|[+-])i$"),"i")}var complex_list_re=function(){var o={};[[10,"","[0-9]"],[16,"x","[0-9a-fA-F]"],[8,"o","[0-7]"],[2,"b","[01]"]].forEach(function(e){var r=_slicedToArray(e,3),t=r[0],n=r[1],i=r[2];o[t]=make_complex_match_re(n,i)});return o}();var characters={alarm:"",backspace:"\b",delete:"",escape:"",newline:"\n",null:"\0",return:"\r",space:" ",tab:"\t",dle:"",soh:"",dc1:"",stx:"",dc2:"",etx:"",dc3:"",eot:"",dc4:"",enq:"",nak:"",ack:"",syn:"",bel:"",etb:"",bs:"\b",can:"",ht:"\t",em:"",lf:"\n",sub:"",vt:"\v",esc:"",ff:"\f",fs:"",cr:"\r",gs:"",so:"",rs:"",si:"",us:"",del:""};function ucs2decode(e){var r=[];var t=0;var n=e.length;while(t=55296&&i<=56319&&t1&&arguments[1]!==undefined?arguments[1]:10;var t=num_pre_parse(e);var n=t.number.split("/");var i=LRational({num:LNumber([n[0],t.radix||r]),denom:LNumber([n[1],t.radix||r])});if(t.inexact){return i.valueOf()}else{return i}}function parse_integer(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;var t=num_pre_parse(e);if(t.inexact){return LFloat(parseInt(t.number,t.radix||r))}return LNumber([t.number,t.radix||r])}function parse_character(e){var r=e.match(/#\\x([0-9a-f]+)$/i);var t;if(r){var n=parseInt(r[1],16);t=String.fromCodePoint(n)}else{r=e.match(/#\\([\s\S]+)$/);if(r){t=r[1]}}if(t){return LCharacter(t)}throw new Error("Parse: invalid character")}function parse_complex(e){var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;function r(e){var r;if(e==="+"){r=LNumber(1)}else if(e==="-"){r=LNumber(-1)}else if(e.match(int_bare_re)){r=LNumber([e,i])}else if(e.match(rational_bare_re)){var t=e.split("/");r=LRational({num:LNumber([t[0],i]),denom:LNumber([t[1],i])})}else if(e.match(float_re)){var n=parse_float(e);if(o.exact){return n.toRational()}return n}else if(e.match(/nan.0$/)){return LNumber(NaN)}else if(e.match(/inf.0$/)){if(e[0]==="-"){return LNumber(Number.NEGATIVE_INFINITY)}return LNumber(Number.POSITIVE_INFINITY)}else{throw new Error("Internal Parser Error")}if(o.inexact){return LFloat(r.valueOf())}return r}var o=num_pre_parse(e);i=o.radix||i;var t;var n=o.number.match(complex_bare_match_re);if(i!==10&&n){t=n}else{t=o.number.match(complex_list_re[i])}var a,u;u=r(t[2]);if(t[1]){a=r(t[1])}else if(u instanceof LFloat){a=LFloat(0)}else{a=LNumber(0)}if(u.cmp(0)===0&&u.__type__==="bigint"){return a}return LComplex({im:u,re:a})}function is_int(e){return parseInt(e.toString(),10)===e}function parse_big_int(e){var r=e.match(/^(([-+]?[0-9]*)(?:\.([0-9]+))?)e([-+]?[0-9]+)/i);if(r){var t=parseInt(r[4],10);var n;var i=r[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var o=r[3]&&r[3].length;if(i0&&(r.exact||!r.number.match(/\./))){return LNumber(o).mul(u)}}}t=LFloat(t);if(r.exact){return t.toRational()}return t}function parse_string(e){e=e.replace(/\\x([0-9a-f]+);/gi,function(e,r){return"\\u"+r.padStart(4,"0")}).replace(/\n/g,"\\n");var r=e.match(/(\\*)(\\x[0-9A-F])/i);if(r&&r[1].length%2===0){throw new Error("Invalid string literal, unclosed ".concat(r[2]))}try{var t=LString(JSON.parse(e));t.freeze();return t}catch(e){var n=e.message.replace(/in JSON /,"").replace(/.*Error: /,"");throw new Error("Invalid string literal: ".concat(n))}}function parse_symbol(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var t={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,r){return String.fromCharCode(parseInt("0"+r,16))}).replace(/\\(.)/g,function(e,r){return t[r]||r})}return new LSymbol(e)}function parse_argument(e){if(constants.hasOwnProperty(e)){return constants[e]}if(e.match(/^"[\s\S]*"$/)){return parse_string(e)}else if(e[0]==="#"){var r=e.match(re_re);if(r){return new RegExp(r[1],r[2])}else if(e.match(char_re)){return parse_character(e)}var t=e.match(/#\\(.+)/);if(t&&ucs2decode(t[1]).length===1){return parse_character(e)}}if(e.match(/[0-9a-f]|[+-]i/i)){if(e.match(int_re)){return parse_integer(e)}else if(e.match(float_re)){return parse_float(e)}else if(e.match(rational_re)){return parse_rational(e)}else if(e.match(complex_re)){return parse_complex(e)}}if(e.match(/^#[iexobd]/)){throw new Error("Invalid numeric constant: "+e)}return parse_symbol(e)}function is_atom_string(e){return!(["(",")","[","]"].includes(e)||specials.names().includes(e))}function is_symbol_string(e){return is_atom_string(e)&&!(e.match(re_re)||e.match(/^"[\s\S]*"$/)||e.match(int_re)||e.match(float_re)||e.match(complex_re)||e.match(rational_re)||e.match(char_re)||["#t","#f","nil"].includes(e))}var string_re=/"(?:\\[\S\s]|[^"])*"?/g;function escape_regex(e){if(typeof e==="string"){var r=/([-\\^$[\]()+{}?*.|])/g;return e.replace(r,"\\$1")}return e}function Stack(){this.data=[]}Stack.prototype.push=function(e){this.data.push(e)};Stack.prototype.top=function(){return this.data[this.data.length-1]};Stack.prototype.pop=function(){return this.data.pop()};Stack.prototype.is_empty=function(){return!this.data.length};function tokens(e){if(e instanceof LString){e=e.valueOf()}var r=new Lexer(e,{whitespace:true});var t=[];while(true){var n=r.peek(true);if(n===eof){break}t.push(n);r.skip()}return t}function multiline_formatter(e){var r=e.token,t=_objectWithoutProperties(e,_excluded);if(r.match(/^"[\s\S]*"$/)&&r.match(/\n/)){var n=new RegExp("^ {1,"+(e.col+1)+"}","mg");r=r.replace(n,"")}return _objectSpread({token:r},t)}function Thunk(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(){};this.fn=e;this.cont=r}Thunk.prototype.toString=function(){return"#"};function trampoline(n){return function(){for(var e=arguments.length,r=new Array(e),t=0;t1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof LString){e=e.toString()}if(r){return tokens(e)}else{var t=tokens(e).map(function(e){if(e.token==="#\\ "||e.token=="#\\\n"){return e.token}return e.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return strip_s_comments(t)}}function strip_s_comments(e){var r=0;var t=null;var n=[];for(var i=0;i0&&arguments[0]!==undefined?arguments[0]:null;if(e instanceof LSymbol){if(e.is_gensym()){return e}e=e.valueOf()}if(is_gensym(e)){return LSymbol(e)}if(e!==null){return t(e,Symbol("#:".concat(e)))}r++;return t(r,Symbol("#:g".concat(r)))}}();function QuotedPromise(e){var t=this;var n={pending:true,rejected:false,fulfilled:false,reason:undefined,type:undefined};e=e.then(function(e){n.type=type(e);n.fulfilled=true;n.pending=false;return e});read_only(this,"_promise",e,{hidden:true});if(is_function(e["catch"])){e=e["catch"](function(e){n.rejected=true;n.pending=false;n.reason=e})}Object.keys(n).forEach(function(r){Object.defineProperty(t,"__".concat(r,"__"),{enumerable:true,get:function e(){return n[r]}})});read_only(this,"__promise__",e);this.then=false}QuotedPromise.prototype.then=function(e){return new QuotedPromise(this.valueOf().then(e))};QuotedPromise.prototype["catch"]=function(e){return new QuotedPromise(this.valueOf()["catch"](e))};QuotedPromise.prototype.valueOf=function(){if(!this._promise){throw new Error("QuotedPromise: invalid promise created")}return this._promise};QuotedPromise.prototype.toString=function(){if(this.__pending__){return QuotedPromise.pending_str}if(this.__rejected__){return QuotedPromise.rejected_str}return"#")};QuotedPromise.pending_str="#";QuotedPromise.rejected_str="#";function promise_all(e){if(Array.isArray(e)){return Promise.all(escape_quoted_promises(e)).then(unescape_quoted_promises)}return e}function escape_quoted_promises(e){var r=new Array(e.length),t=e.length;while(t--){var n=e[t];if(n instanceof QuotedPromise){r[t]=new Value(n)}else{r[t]=n}}return r}function unescape_quoted_promises(e){var r=new Array(e.length),t=e.length;while(t--){var n=e[t];if(n instanceof Value){r[t]=n.valueOf()}else{r[t]=n}}return r}var specials={LITERAL:Symbol["for"]("literal"),SPLICE:Symbol["for"]("splice"),SYMBOL:Symbol["for"]("symbol"),names:function e(){return Object.keys(this.__list__)},type:function e(r){try{return this.get(r).type}catch(e){console.log({name:r});console.log(e);return null}},get:function e(r){return this.__list__[r]},off:function e(r){var t=this;var n=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(Array.isArray(r)){r.forEach(function(e){return t.off(e,n)})}else if(n===null){delete this.__events__[r]}else{this.__events__=this.__events__.filter(function(e){return e!==n})}},on:function e(r,t){var n=this;if(Array.isArray(r)){r.forEach(function(e){return n.on(e,t)})}else if(!this.__events__[r]){this.__events__[r]=[t]}else{this.__events__[r].push(t)}},trigger:function e(r){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i",new LSymbol("quote-promise"),specials.LITERAL]];var builtins=defined_specials.map(function(e){return e[0]});Object.freeze(builtins);Object.defineProperty(specials,"__builtins__",{writable:false,value:builtins});defined_specials.forEach(function(e){var r=_slicedToArray(e,3),t=r[0],n=r[1],i=r[2];specials.append(t,n,i)});var Lexer=function(){function p(e){var r=this;var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=t.whitespace,i=n===void 0?false:n;_classCallCheck(this,p);read_only(this,"__input__",e.replace(/\r/g,""));var o={};["_i","_whitespace","_col","_newline","_line","_state","_next","_token","_prev_char"].forEach(function(t){Object.defineProperty(r,t,{configurable:false,enumerable:false,get:function e(){return o[t]},set:function e(r){o[t]=r}})});this._whitespace=i;this._i=this._line=this._col=this._newline=0;this._state=this._next=this._token=null;this._prev_char=""}_createClass(p,[{key:"get",value:function e(r){return this.__internal[r]}},{key:"set",value:function e(r,t){this.__internal[r]=t}},{key:"token",value:function e(){var r=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(r){var t=this._line;if(this._whitespace&&this._token==="\n"){--t}return{token:this._token,col:this._col,offset:this._i,line:t}}return this._token}},{key:"peek",value:function e(){var r=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(this._i>=this.__input__.length){return eof}if(this._token){return this.token(r)}var t=this.next_token();if(t){this._token=this.__input__.substring(this._i,this._next);return this.token(r)}return eof}},{key:"skip",value:function e(){if(this._next!==null){this._token=null;this._i=this._next}}},{key:"read_line",value:function e(){var r=this.__input__.length;if(this._i>=r){return eof}for(var t=this._i;t=t){return eof}if(r+this._i>=t){return this.read_rest()}var n=this._i+r;var i=this.__input__.substring(this._i,n);var o=i.match(/\n/g);if(o){this._line+=o.length}this._i=n;return i}},{key:"peek_char",value:function e(){if(this._i>=this.__input__.length){return eof}return LCharacter(this.__input__[this._i])}},{key:"read_char",value:function e(){var r=this.peek_char();this.skip_char();return r}},{key:"skip_char",value:function e(){if(this._i1&&arguments[1]!==undefined?arguments[1]:{},n=t.prev_char,i=t["char"],o=t.next_char;var a=_slicedToArray(r,4),u=a[0],s=a[1],c=a[2],l=a[3];if(r.length!==5){throw new Error("Lexer: Invalid rule of length ".concat(r.length))}if(is_string(u)){if(u!==i){return false}}else if(!i.match(u)){return false}if(!match_or_null(s,n)){return false}if(!match_or_null(c,o)){return false}if(l!==this._state){return false}return true}},{key:"next_token",value:function e(){if(this._i>=this.__input__.length){return false}var r=true;e:for(var t=this._i,n=this.__input__.length;t2&&arguments[2]!==undefined?arguments[2]:null;var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;if(r.length===0){throw new Error("Lexer: invalid literal rule")}if(r.length===1){return[[r,n,i,null,null]]}var o=[];for(var a=0,u=r.length;a0&&arguments[0]!==undefined?arguments[0]:{},r=e.env,t=e.meta,n=t===void 0?false:t,i=e.formatter,o=i===void 0?multiline_formatter:i;_classCallCheck(this,a);read_only(this,"_formatter",o,{hidden:true});read_only(this,"__env__",r);read_only(this,"_meta",n,{hidden:true});read_only(this,"_refs",[],{hidden:true});read_only(this,"_state",{parentheses:0,fold_case:false},{hidden:true})}_createClass(a,[{key:"parse",value:function e(r){if(r instanceof LString){r=r.toString()}read_only(this,"__lexer__",new Lexer(r))}},{key:"resolve",value:function e(r){return this.__env__&&this.__env__.get(r,{throwError:false})}},{key:"peek",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var t;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:t=this.__lexer__.peek(true);if(!(t===eof)){r.next=4;break}return r.abrupt("return",eof);case 4:if(!this.is_comment(t.token)){r.next=7;break}this.skip();return r.abrupt("continue",0);case 7:if(!is_directive(t.token)){r.next=11;break}this.skip();if(t.token==="#!fold-case"){this._state.fold_case=true}else if(t.token==="#!no-fold-case"){this._state.fold_case=false}return r.abrupt("continue",0);case 11:if(!(t.token==="#;")){r.next=18;break}this.skip();if(!(this.__lexer__.peek()===eof)){r.next=15;break}throw new Error("Lexer: syntax error eof found after comment");case 15:r.next=17;return this._read_object();case 17:return r.abrupt("continue",0);case 18:return r.abrupt("break",21);case 21:t=this._formatter(t);if(this._state.fold_case){t.token=foldcase_string(t.token)}if(!this._meta){r.next=25;break}return r.abrupt("return",t);case 25:return r.abrupt("return",t.token);case 26:case"end":return r.stop()}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"reset",value:function e(){this._refs.length=0}},{key:"skip",value:function e(){this.__lexer__.skip()}},{key:"read",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var t;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:r.next=2;return this.peek();case 2:t=r.sent;this.skip();return r.abrupt("return",t);case 5:case"end":return r.stop()}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"match_datum_label",value:function e(r){var t=r.match(/^#([0-9]+)=$/);return t&&t[1]}},{key:"match_datum_ref",value:function e(r){var t=r.match(/^#([0-9]+)#$/);return t&&t[1]}},{key:"is_open",value:function e(r){var t=["(","["].includes(r);if(t){this._state.parentheses++}return t}},{key:"is_close",value:function e(r){var t=[")","]"].includes(r);if(t){this._state.parentheses--}return t}},{key:"read_list",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var t,n,i,o,a;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:t=_nil,n=t;case 1:r.next=4;return this.peek();case 4:o=r.sent;if(!(o===eof)){r.next=7;break}return r.abrupt("break",32);case 7:if(!this.is_close(o)){r.next=10;break}this.skip();return r.abrupt("break",32);case 10:if(!(o==="."&&!is_nil(t))){r.next=18;break}this.skip();r.next=14;return this._read_object();case 14:n.cdr=r.sent;i=true;r.next=30;break;case 18:if(!i){r.next=22;break}throw new Error("Parser: syntax error more than one element after dot");case 22:r.t0=Pair;r.next=25;return this._read_object();case 25:r.t1=r.sent;r.t2=_nil;a=new r.t0(r.t1,r.t2);if(is_nil(t)){t=a}else{n.cdr=a}n=a;case 30:r.next=1;break;case 32:return r.abrupt("return",t);case 33:case"end":return r.stop()}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"read_value",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var t;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:r.next=2;return this.read();case 2:t=r.sent;if(!(t===eof)){r.next=5;break}throw new Error("Parser: Expected token eof found");case 5:return r.abrupt("return",parse_argument(t));case 6:case"end":return r.stop()}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"is_comment",value:function e(r){return r.match(/^;/)||r.match(/^#\|/)&&r.match(/\|#$/)}},{key:"evaluate",value:function e(r){return _evaluate(r,{env:this.__env__,error:function e(r){throw r}})}},{key:"read_object",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var t;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:this.reset();r.next=3;return this._read_object();case 3:t=r.sent;if(t instanceof DatumReference){t=t.valueOf()}if(!this._refs.length){r.next=7;break}return r.abrupt("return",unpromise(this._resolve_object(t),function(e){if(is_pair(e)){e.mark_cycles()}return e}));case 7:return r.abrupt("return",t);case 8:case"end":return r.stop()}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"balanced",value:function e(){return this._state.parentheses===0}},{key:"ballancing_error",value:function e(r,t){var n=this._state.parentheses;var i;if(n<0){i=new Error("Parser: unexpected parenthesis");i.__code__=[t.toString()+")"]}else{i=new Error("Parser: expected parenthesis but eof found");var o=new RegExp("\\){".concat(n,"}$"));i.__code__=[r.toString().replace(o,"")]}throw i}},{key:"_resolve_object",value:function(){var r=_asyncToGenerator(_regeneratorRuntime.mark(function e(t){var n=this;var i;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:if(!Array.isArray(t)){r.next=2;break}return r.abrupt("return",t.map(function(e){return n._resolve_object(e)}));case 2:if(!is_plain_object(t)){r.next=6;break}i={};Object.keys(t).forEach(function(e){i[e]=n._resolve_object(t[e])});return r.abrupt("return",i);case 6:if(!is_pair(t)){r.next=8;break}return r.abrupt("return",this._resolve_pair(t));case 8:return r.abrupt("return",t);case 9:case"end":return r.stop()}},e,this)}));function e(e){return r.apply(this,arguments)}return e}()},{key:"_resolve_pair",value:function(){var r=_asyncToGenerator(_regeneratorRuntime.mark(function e(t){return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:if(!is_pair(t)){r.next=15;break}if(!(t.car instanceof DatumReference)){r.next=7;break}r.next=4;return t.car.valueOf();case 4:t.car=r.sent;r.next=8;break;case 7:this._resolve_pair(t.car);case 8:if(!(t.cdr instanceof DatumReference)){r.next=14;break}r.next=11;return t.cdr.valueOf();case 11:t.cdr=r.sent;r.next=15;break;case 14:this._resolve_pair(t.cdr);case 15:return r.abrupt("return",t);case 16:case"end":return r.stop()}},e,this)}));function e(e){return r.apply(this,arguments)}return e}()},{key:"_read_object",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var t,n,i,o,a,u,s,c,l,f,_;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:r.next=2;return this.peek();case 2:t=r.sent;if(!(t===eof)){r.next=5;break}return r.abrupt("return",t);case 5:if(!is_special(t)){r.next=38;break}n=specials.get(t);i=is_builtin(t);this.skip();a=is_symbol_extension(t);if(!a){r.next=14;break}r.t0=undefined;r.next=17;break;case 14:r.next=16;return this._read_object();case 16:r.t0=r.sent;case 17:u=r.t0;if(i){r.next=25;break}s=this.__env__.get(n.symbol);if(!(typeof s==="function")){r.next=25;break}if(is_literal(t)){c=[u]}else if(is_nil(u)){c=[]}else if(is_pair(u)){c=u.to_array(false)}if(!(c||a)){r.next=24;break}return r.abrupt("return",call_function(s,a?[]:c,{env:this.__env__,dynamic_env:this.__env__,use_dynamic:false}));case 24:throw new Error("Parse Error: Invalid parser extension "+"invocation ".concat(n.symbol));case 25:if(is_literal(t)){o=new Pair(n.symbol,new Pair(u,_nil))}else{o=new Pair(n.symbol,u)}if(!i){r.next=28;break}return r.abrupt("return",o);case 28:if(!(s instanceof Macro)){r.next=37;break}r.next=31;return this.evaluate(o);case 31:l=r.sent;if(!(is_pair(l)||l instanceof LSymbol)){r.next=34;break}return r.abrupt("return",Pair.fromArray([LSymbol("quote"),l]));case 34:return r.abrupt("return",l);case 37:throw new Error("Parse Error: invalid parser extension: "+n.symbol);case 38:f=this.match_datum_ref(t);if(!(f!==null)){r.next=44;break}this.skip();if(!this._refs[f]){r.next=43;break}return r.abrupt("return",new DatumReference(f,this._refs[f]));case 43:throw new Error("Parse Error: invalid datum label #".concat(f,"#"));case 44:_=this.match_datum_label(t);if(!(_!==null)){r.next=51;break}this.skip();this._refs[_]=this._read_object();return r.abrupt("return",this._refs[_]);case 51:if(!this.is_close(t)){r.next=55;break}this.skip();r.next=61;break;case 55:if(!this.is_open(t)){r.next=60;break}this.skip();return r.abrupt("return",this.read_list());case 60:return r.abrupt("return",this.read_value());case 61:case"end":return r.stop()}},e,this)}));function r(){return e.apply(this,arguments)}return r}()}]);return a}();var DatumReference=function(){function t(e,r){_classCallCheck(this,t);this.name=e;this.data=r}_createClass(t,[{key:"valueOf",value:function e(){return this.data}}]);return t}();function _parse(e,r){return _parse2.apply(this,arguments)}function _parse2(){_parse2=_wrapAsyncGenerator(_regeneratorRuntime.mark(function e(t,n){var i,o,a;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:if(!n){if(global_env){n=global_env.get("**interaction-environment**",{throwError:false})}else{n=user_env}}if(t instanceof Parser){i=t}else{i=new Parser({env:n});i.parse(t)}case 2:r.next=5;return _awaitAsyncGenerator(i.read_object());case 5:a=r.sent;if(!i.balanced()){i.ballancing_error(a,o)}if(!(a===eof)){r.next=9;break}return r.abrupt("break",14);case 9:o=a;r.next=12;return a;case 12:r.next=2;break;case 14:case"end":return r.stop()}},e)}));return _parse2.apply(this,arguments)}function unpromise(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(e){return e};var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;if(is_promise(e)){var n=e.then(r);if(t===null){return n}else{return n["catch"](t)}}if(e instanceof Array){return unpromise_array(e,r,t)}if(is_plain_object(e)){return unpromise_object(e,r,t)}return r(e)}function unpromise_array(r,t,e){if(r.find(is_promise)){return unpromise(promise_all(r),function(e){if(Object.isFrozen(r)){Object.freeze(e)}return t(e)},e)}return t(r)}function unpromise_object(r,e,t){var i=Object.keys(r);var n=[],o=[];var a=i.length;while(a--){var u=i[a];var s=r[u];n[a]=s;if(is_promise(s)){o.push(s)}}if(o.length){return unpromise(promise_all(n),function(e){var n={};e.forEach(function(e,r){var t=i[r];n[t]=e});if(Object.isFrozen(r)){Object.freeze(n)}return n},t)}return e(r)}function read_only(e,r,t){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{},i=n.hidden,o=i===void 0?false:i;Object.defineProperty(e,r,{value:t,configurable:true,enumerable:!o})}function uniterate_async(e){return _uniterate_async.apply(this,arguments)}function _uniterate_async(){_uniterate_async=_asyncToGenerator(_regeneratorRuntime.mark(function e(t){var n,i,o,a,u,s,c;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:n=[];i=false;o=false;r.prev=3;u=_asyncIterator(t);case 5:r.next=7;return u.next();case 7:if(!(i=!(s=r.sent).done)){r.next=13;break}c=s.value;n.push(c);case 10:i=false;r.next=5;break;case 13:r.next=19;break;case 15:r.prev=15;r.t0=r["catch"](3);o=true;a=r.t0;case 19:r.prev=19;r.prev=20;if(!(i&&u["return"]!=null)){r.next=24;break}r.next=24;return u["return"]();case 24:r.prev=24;if(!o){r.next=27;break}throw a;case 27:return r.finish(24);case 28:return r.finish(19);case 29:return r.abrupt("return",n);case 30:case"end":return r.stop()}},e,null,[[3,15,19,29],[20,,24,28]])}));return _uniterate_async.apply(this,arguments)}function matcher(e,r){if(r instanceof RegExp){return function(e){return String(e).match(r)}}else if(is_function(r)){return r}throw new Error("Invalid matcher")}function doc(e,r,t,n){if(typeof e!=="string"){r=arguments[0];t=arguments[1];n=arguments[2];e=null}if(t){if(n){r.__doc__=t}else{r.__doc__=trim_lines(t)}}if(e){r.__name__=e}else if(r.name&&!is_lambda(r)){r.__name__=r.name}return r}function trim_lines(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function previousSexp(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var t=e.length;if(r<=0){throw Error("previousSexp: Invalid argument sexp = ".concat(r))}e:while(r--&&t>=0){var n=1;while(n>0){var i=e[--t];if(!i){break e}if(i==="("||i.token==="("){n--}else if(i===")"||i.token===")"){n++}}t--}return e.slice(t+1)}function lineIndent(e){if(!e||!e.length){return 0}var r=e.length;if(e[r-1].token==="\n"){return 0}while(--r){if(e[r].token==="\n"){var t=(e[r+1]||{}).token;if(t){return t.length}}}return 0}function match(e,r){return l(e,r)===r.length;function l(t,n){function e(e,r){var t=_createForOfIteratorHelper(e),n;try{for(t.s();!(n=t.n()).done;){var i=n.value;var o=l(i,r);if(o!==-1){return o}}}catch(e){t.e(e)}finally{t.f()}return-1}function r(){return t[o]===Symbol["for"]("symbol")&&!is_symbol_string(n[u])}function i(){var e=t[o+1];var r=n[u+1];if(e!==undefined&&r!==undefined){return l([e],[r])}}var o=0;var a={};for(var u=0;u0){continue}}else if(r()){return-1}}else if(t[o]instanceof Array){var c=l(t[o],n.slice(u));if(c===-1||c+u>n.length){return-1}u+=c-1;o++;continue}else{return-1}o++}if(t.length!==o){return-1}return n.length}}function Formatter(e){this.__code__=e.replace(/\r/g,"")}Formatter.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?(?:define(?:-values|-syntax|-macro|-class|-record-type)?|(?:call-with-(?:input-file|output-file|port))|lambda|let-env|try|catch|when|unless|while|syntax-rules|(let|letrec)(-syntax|\*?-values|\*)?)$/],shift:{1:["&","#"]}}};Formatter.match=match;Formatter.prototype._options=function e(r){var t=Formatter.defaults;if(typeof r==="undefined"){return Object.assign({},t)}var n=r&&r.exceptions||{};var i=n.specials||[];var o=n.shift||{1:[]};return _objectSpread(_objectSpread(_objectSpread({},t),r),{},{exceptions:{specials:[].concat(_toConsumableArray(t.exceptions.specials),_toConsumableArray(i)),shift:_objectSpread(_objectSpread({},o),{},{1:[].concat(_toConsumableArray(t.exceptions.shift[1]),_toConsumableArray(o[1]))})}})};Formatter.prototype.indent=function e(r){var t=tokenize(this.__code__,true);return this._indent(t,r)};Formatter.exception_shift=function(o,e){function r(e){if(!e.length){return false}if(e.indexOf(o)!==-1){return true}else{var r=e.filter(function(e){return e instanceof RegExp});if(!r.length){return false}var t=_createForOfIteratorHelper(r),n;try{for(t.s();!(n=t.n()).done;){var i=n.value;if(o.match(i)){return true}}}catch(e){t.e(e)}finally{t.f()}}return false}if(r(e.exceptions.specials)){return e.indent}var t=e.exceptions.shift;for(var n=0,i=Object.entries(t);n0){n.offset=0}if(o.toString()===r.toString()&&balanced(o)){return n.offset+o[0].col}else if(o.length===1){return n.offset+o[0].col+1}else{var s=-1;if(a){var c=Formatter.exception_shift(a.token,n);if(c!==-1){s=c}}if(s===-1){s=Formatter.exception_shift(o[1].token,n)}if(s!==-1){return n.offset+o[0].col+s}else if(o[0].line3&&o[1].line===o[3].line){if(o[1].token==="("||o[1].token==="["){return n.offset+o[1].col}return n.offset+o[3].col}else if(o[0].line===o[1].line){return n.offset+n.indent+o[0].col}else{var l=o.slice(2);for(var f=0;f")};Ahead.prototype.match=function(e){return e.match(this.pattern)};function Pattern(){for(var e=arguments.length,r=new Array(e),t=0;t")};Formatter.Pattern=Pattern;Formatter.Ahead=Ahead;var p_o=/^[[(]$/;var p_e=/^[\])]$/;var not_p=/[^()[\]]/;var not_close=new Ahead(/[^)\]]/);var glob=Symbol["for"]("*");var sexp_or_atom=new Pattern([p_o,glob,p_e],[not_p],"+");var sexp=new Pattern([p_o,glob,p_e],"+");var symbol=new Pattern([Symbol["for"]("symbol")],"?");var symbols=new Pattern([Symbol["for"]("symbol")],"*");var identifiers=[p_o,symbols,p_e];var let_value=new Pattern([p_o,Symbol["for"]("symbol"),glob,p_e],"+");var syntax_rules=keywords_re("syntax-rules");var def_lambda_re=keywords_re("define","lambda","define-macro","syntax-rules");var non_def=/^(?!.*\b(?:[()[\]]|define(?:-macro)?|let(?:\*|rec|-env|-syntax|)?|lambda|syntax-rules)\b).*$/;var let_re=/^(?:#:)?(let(?:\*|rec|-env|-syntax)?)$/;function keywords_re(){for(var e=arguments.length,r=new Array(e),t=0;t0&&!u[e]){u[e]=previousSexp(a,e)}});var s=_createForOfIteratorHelper(i),c;try{for(s.s();!(c=s.n()).done;){var l=_slicedToArray(c.value,3),f=l[0],_=l[1],p=l[2];_=_.valueOf();var d=_>0?u[_]:a;var y=d.filter(function(e){return e.trim()&&!is_special(e)});var h=t(d);var m=match(f,y);var v=n.slice(o).find(function(e){return e.trim()&&!is_special(e)});if(m&&(p instanceof Ahead&&p.match(v)||!p)){var g=o-h;if(n[g]!=="\n"){if(!n[g].trim()){n[g]="\n"}else{n.splice(g,0,"\n");o++}}o+=h;continue e}}}catch(e){s.e(e)}finally{s.f()}}this.__code__=n.join("");return this};Formatter.prototype._spaces=function(e){return" ".repeat(e)};Formatter.prototype.format=function e(r){var t=this.__code__.replace(/[ \t]*\n[ \t]*/g,"\n ");var n=tokenize(t,true);var i=this._options(r);var o=0;var a=0;for(var u=0;u0){n=Math.floor(r()*t);t--;var i=[e[n],e[t]];e[t]=i[0];e[n]=i[1]}return e}function Nil(){}Nil.prototype.toString=function(){return"()"};Nil.prototype.valueOf=function(){return undefined};Nil.prototype.serialize=function(){return 0};Nil.prototype.to_object=function(){return{}};Nil.prototype.append=function(e){return new Pair(e,_nil)};Nil.prototype.to_array=function(){return[]};var _nil=new Nil;function Pair(e,r){if(typeof this!=="undefined"&&this.constructor!==Pair||typeof this==="undefined"){return new Pair(e,r)}this.car=e;this.cdr=r}function to_array(o,a){return function e(r){typecheck(o,r,["pair","nil"]);if(is_nil(r)){return[]}var t=[];var n=r;while(true){if(is_pair(n)){if(n.have_cycles("cdr")){break}var i=n.car;if(a&&is_pair(i)){i=this.get(o).call(this,i)}t.push(i);n=n.cdr}else if(is_nil(n)){break}else{throw new Error("".concat(o,": can't convert improper list"))}}return t}}Pair.prototype.flatten=function(){return Pair.fromArray(flatten(this.to_array()))};Pair.prototype.length=function(){var e=0;var r=this;while(true){if(!r||is_nil(r)||!is_pair(r)||r.have_cycles("cdr")){break}e++;r=r.cdr}return e};Pair.match=function(e,r){if(e instanceof LSymbol){return LSymbol.is(e,r)}else if(is_pair(e)){return Pair.match(e.car,r)||Pair.match(e.cdr,r)}else if(Array.isArray(e)){return e.some(function(e){return Pair.match(e,r)})}else if(is_plain_object(e)){return Object.values(e).some(function(e){return Pair.match(e,r)})}return false};Pair.prototype.find=function(e){return Pair.match(this,e)};Pair.prototype.clone=function(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var n=new Map;function i(e){if(is_pair(e)){if(n.has(e)){return n.get(e)}var r=new Pair;n.set(e,r);if(t){r.car=i(e.car)}else{r.car=e.car}r.cdr=i(e.cdr);r[__cycles__]=e[__cycles__];return r}return e}return i(this)};Pair.prototype.last_pair=function(){var e=this;while(true){if(!is_pair(e.cdr)){return e}if(e.have_cycles("cdr")){break}e=e.cdr}};Pair.prototype.to_array=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var r=[];if(is_pair(this.car)){if(e){r.push(this.car.to_array())}else{r.push(this.car)}}else{r.push(this.car.valueOf())}if(is_pair(this.cdr)){r=r.concat(this.cdr.to_array(e))}return r};Pair.fromArray=function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(is_pair(e)||t&&e instanceof Array&&e[__data__]){return e}if(r===false){var n=_nil;for(var i=e.length;i--;){n=new Pair(e[i],n)}return n}if(e.length&&!(e instanceof Array)){e=_toConsumableArray(e)}var o=_nil;var a=e.length;while(a--){var u=e[a];if(u instanceof Array){u=Pair.fromArray(u,r,t)}else if(typeof u==="string"){u=LString(u)}else if(typeof u==="number"&&!Number.isNaN(u)){u=LNumber(u)}o=new Pair(u,o)}return o};Pair.prototype.to_object=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var r=this;var t={};while(true){if(is_pair(r)&&is_pair(r.car)){var n=r.car;var i=n.car;if(i instanceof LSymbol){i=i.__name__}if(i instanceof LString){i=i.valueOf()}var o=n.cdr;if(is_pair(o)){o=o.to_object(e)}if(is_native(o)){if(!e){o=o.valueOf()}}t[i]=o;r=r.cdr}else{break}}return t};Pair.fromPairs=function(e){return e.reduce(function(e,r){return new Pair(new Pair(new LSymbol(r[0]),r[1]),e)},_nil)};Pair.fromObject=function(r){var e=Object.keys(r).map(function(e){return[e,r[e]]});return Pair.fromPairs(e)};Pair.prototype.reduce=function(e){var r=this;var t=_nil;while(true){if(!is_nil(r)){t=e(t,r.car);r=r.cdr}else{break}}return t};Pair.prototype.reverse=function(){if(this.have_cycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var r=_nil;while(!is_nil(e)){var t=e.cdr;e.cdr=r;r=e;e=t}return r};Pair.prototype.transform=function(n){function i(e){if(is_pair(e)){if(e.replace){delete e.replace;return e}var r=n(e.car);if(is_pair(r)){r=i(r)}var t=n(e.cdr);if(is_pair(t)){t=i(t)}return new Pair(r,t)}return e}return i(this)};Pair.prototype.map=function(e){if(typeof this.car!=="undefined"){return new Pair(e(this.car),is_nil(this.cdr)?_nil:this.cdr.map(e))}else{return _nil}};var repr=new Map;function is_plain_object(e){return e&&_typeof$1(e)==="object"&&e.constructor===Object}var props=Object.getOwnPropertyNames(Array.prototype);var array_methods=[];props.forEach(function(e){array_methods.push(Array[e],Array.prototype[e])});function is_array_method(e){e=unbind(e);return array_methods.includes(e)}function is_lips_function(e){return is_function(e)&&(is_lambda(e)||e.__doc__)}function user_repr(t){var e=t.constructor||Object;var n=is_plain_object(t);var i=is_function(t[Symbol.asyncIterator])||is_function(t[Symbol.iterator]);var o;if(repr.has(e)){o=repr.get(e)}else{repr.forEach(function(e,r){r=unbind(r);if(t instanceof r&&(r===Object&&n&&!i||r!==Object)){o=e}})}return o}var str_mapping=new Map;[[true,"#t"],[false,"#f"],[null,"#null"],[undefined,"#void"]].forEach(function(e){var r=_slicedToArray(e,2),t=r[0],n=r[1];str_mapping.set(t,n)});function symbolize(t){if(t&&_typeof$1(t)==="object"){var n={};var e=Object.getOwnPropertySymbols(t);e.forEach(function(e){var r=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");n[r]=toString(t[e])});var r=Object.getOwnPropertyNames(t);r.forEach(function(e){var r=t[e];if(r&&_typeof$1(r)==="object"&&r.constructor===Object){n[e]=symbolize(r)}else{n[e]=toString(r)}});return n}return t}function get_props(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function has_own_function(e,r){return e.hasOwnProperty(r)&&is_function(e.toString)}function function_to_string(e){if(is_native_function(e)){return"#"}var r=e.prototype&&e.prototype.constructor;if(is_function(r)&&is_lambda(r)){if(e[__class__]&&r.hasOwnProperty("__name__")){var t=r.__name__;if(LString.isString(t)){t=t.toString();return"#")}return"#"}}if(e.hasOwnProperty("__name__")){var n=e.__name__;if(_typeof$1(n)==="symbol"){n=symbol_to_string(n)}if(typeof n==="string"){return"#")}}if(has_own_function(e,"toString")){return e.toString()}else if(e.name&&!is_lambda(e)){return"#")}else{return"#"}}var instances=new Map;[[Error,function(e){return e.message}],[Pair,function(e,r){var t=r.quote,n=r.skip_cycles,i=r.pair_args;if(!n){e.mark_cycles()}return e.toString.apply(e,[t].concat(_toConsumableArray(i)))}],[LCharacter,function(e,r){var t=r.quote;if(t){return e.toString()}return e.valueOf()}],[LString,function(e,r){var t=r.quote;e=e.toString();if(t){return JSON.stringify(e).replace(/\\n/g,"\n")}return e}],[RegExp,function(e){return"#"+e.toString()}]].forEach(function(e){var r=_slicedToArray(e,2),t=r[0],n=r[1];instances.set(t,n)});var native_types=[LSymbol,Macro,Values,InputPort,OutputPort,Environment,QuotedPromise];function toString(e,r,t){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(str_mapping.has(e)){return str_mapping.get(e)}if(is_prototype(e)){return"#"}if(e){var n=e.constructor;if(instances.has(n)){for(var i=arguments.length,o=new Array(i>3?i-3:0),a=3;a"}if(e===null){return"null"}if(is_function(e)){if(is_function(e.toString)&&e.hasOwnProperty("toString")){return e.toString().valueOf()}return function_to_string(e)}if(_typeof$1(e)==="object"){var l=e.constructor;if(!l){l=Object}var f;if(typeof l.__class__==="string"){f=l.__class__}else{var _=user_repr(e);if(_){if(is_function(_)){return _(e,r)}else{throw new Error("toString: Invalid repr value")}}f=l.name}if(is_function(e.toString)&&e.hasOwnProperty("toString")){return e.toString().valueOf()}if(type(e)==="instance"){if(is_lambda(l)&&l.__name__){f=l.__name__.valueOf()}else if(!is_native_function(l)){f="instance"}}if(is_iterator(e,Symbol.iterator)){if(f){return"#")}return"#"}if(is_iterator(e,Symbol.asyncIterator)){if(f){return"#")}return"#"}if(f!==""){return"#<"+f+">"}return"#"}if(typeof e!=="string"){return e.toString()}return e}Pair.prototype.mark_cycles=function(){mark_cycles(this);return this};Pair.prototype.have_cycles=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(!e){return this.have_cycles("car")||this.have_cycles("cdr")}return!!(this[__cycles__]&&this[__cycles__][e])};Pair.prototype.is_cycle=function(){return is_cycle(this)};function is_cycle(e){if(!is_pair(e)){return false}if(e.have_cycles()){return true}return is_cycle(e.car,fn)||is_cycle(e.cdr,fn)}function mark_cycles(e){var r=[];var i=[];var o=[];function a(e){if(!r.includes(e)){r.push(e)}}function u(e,r,t,n){if(is_pair(t)){if(n.includes(t)){if(!o.includes(t)){o.push(t)}if(!e[__cycles__]){e[__cycles__]={}}e[__cycles__][r]=t;if(!i.includes(e)){i.push(e)}return true}}}var s=trampoline(function e(r,t){if(is_pair(r)){delete r.ref;delete r[__cycles__];a(r);t.push(r);var n=u(r,"car",r.car,t);var i=u(r,"cdr",r.cdr,t);if(!n){s(r.car,t.slice())}if(!i){return new Thunk(function(){return e(r.cdr,t.slice())})}}});function t(e,r){if(is_pair(e[__cycles__][r])){var t=n.indexOf(e[__cycles__][r]);e[__cycles__][r]="#".concat(t,"#")}}s(e,[]);var n=r.filter(function(e){return o.includes(e)});n.forEach(function(e,r){e[__ref__]="#".concat(r,"=")});i.forEach(function(e){t(e,"car");t(e,"cdr")})}Pair.prototype.toString=function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},t=r.nested,n=t===void 0?false:t;var i=[];if(this[__ref__]){i.push(this[__ref__]+"(")}else if(!n){i.push("(")}var o;if(this[__cycles__]&&this[__cycles__].car){o=this[__cycles__].car}else{o=toString(this.car,e,true)}if(o!==undefined){i.push(o)}if(is_pair(this.cdr)){if(this[__cycles__]&&this[__cycles__].cdr){i.push(" . ");i.push(this[__cycles__].cdr)}else{if(this.cdr[__ref__]){i.push(" . ")}else{i.push(" ")}var a=this.cdr.toString(e,{nested:true});i.push(a)}}else if(!is_nil(this.cdr)){i=i.concat([" . ",toString(this.cdr,e,true)])}if(!n||this[__ref__]){i.push(")")}return i.join("")};Pair.prototype.set=function(e,r){this[e]=r;if(is_pair(r)){this.mark_cycles()}};Pair.prototype.append=function(e){if(e instanceof Array){return this.append(Pair.fromArray(e))}var r=this;if(r.car===undefined){if(is_pair(e)){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(!is_nil(e)){while(true){if(is_pair(r)&&!is_nil(r.cdr)){r=r.cdr}else{break}}r.cdr=e}return this};Pair.prototype.serialize=function(){return[this.car,this.cdr]};Pair.prototype[Symbol.iterator]=function(){var t=this;return{next:function e(){var r=t;t=r.cdr;if(is_nil(r)){return{value:undefined,done:true}}else{return{value:r.car,done:false}}}}};function abs(e){return e<0?-e:e}function seq_compare(e,r){var t=_toArray(r),n=t[0],i=t.slice(1);while(i.length>0){var o=i,a=_slicedToArray(o,1),u=a[0];if(!e(n,u)){return false}var s=i;var c=_toArray(s);n=c[0];i=c.slice(1)}return true}function equal(e,r){if(is_function(e)){return is_function(r)&&unbind(e)===unbind(r)}else if(e instanceof LNumber){if(!(r instanceof LNumber)){return false}var t;if(e.__type__===r.__type__){if(e.__type__==="complex"){t=e.__im__.__type__===r.__im__.__type__&&e.__re__.__type__===r.__re__.__type__}else{t=true}if(t&&e.cmp(r)===0){if(e.valueOf()===0){return Object.is(e.valueOf(),r.valueOf())}return true}}return false}else if(typeof e==="number"){if(typeof r!=="number"){return false}if(Number.isNaN(e)){return Number.isNaN(r)}if(e===Number.NEGATIVE_INFINITY){return r===Number.NEGATIVE_INFINITY}if(e===Number.POSITIVE_INFINITY){return r===Number.POSITIVE_INFINITY}return equal(LNumber(e),LNumber(r))}else if(e instanceof LCharacter){if(!(r instanceof LCharacter)){return false}return e.__char__===r.__char__}else{return e===r}}function same_atom(e,r){if(type(e)!==type(r)){return false}if(!is_atom(e)){return false}if(e instanceof RegExp){return e.source===r.source}if(e instanceof LString){return e.valueOf()===r.valueOf()}return equal(e,r)}function is_atom(e){return e instanceof LSymbol||LString.isString(e)||is_nil(e)||e===null||e instanceof LCharacter||e instanceof LNumber||e===true||e===false}var truncate=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e===0){return 0}else if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function Macro(e,r,t,n){if(typeof this!=="undefined"&&this.constructor!==Macro||typeof this==="undefined"){return new Macro(e,r)}typecheck("Macro",e,"string",1);typecheck("Macro",r,"function",2);if(t){if(n){this.__doc__=t}else{this.__doc__=trim_lines(t)}}this.__name__=e;this.__fn__=r}Macro.defmacro=function(e,r,t,n){var i=new Macro(e,r,t,n);i.__defmacro__=true;return i};Macro.prototype.invoke=function(e,r,t){var n=r.env,i=_objectWithoutProperties(r,_excluded2);var o=_objectSpread(_objectSpread({},i),{},{macro_expand:t});var a=this.__fn__.call(n,e,o,this.__name__);return a};Macro.prototype.toString=function(){return"#")};var macro="define-macro";var recur_guard=-1e4;function macro_expand(c){return function(){var t=_asyncToGenerator(_regeneratorRuntime.mark(function e(t,v){var o,g,n,i,a,b,P,w,D,x,L,E,u,S,s;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:s=function e(){s=_asyncToGenerator(_regeneratorRuntime.mark(function e(t,n,i){var o,a,u,s,c,l,f,_,p,d,y,h,m;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:if(!(is_pair(t)&&t.car instanceof LSymbol)){r.next=50;break}if(!t[__data__]){r.next=3;break}return r.abrupt("return",t);case 3:o=t.car.valueOf();a=i.get(t.car,{throwError:false});u=b(t.car);s=u||P(a,t)||w(a);if(!(s&&is_pair(t.cdr.car))){r.next=28;break}if(!u){r.next=15;break}g=x(t.cdr.car);r.next=12;return E(t.cdr.car,n);case 12:c=r.sent;r.next=17;break;case 15:g=D(t.cdr.car);c=t.cdr.car;case 17:r.t0=Pair;r.t1=t.car;r.t2=Pair;r.t3=c;r.next=23;return S(t.cdr.cdr,n,i);case 23:r.t4=r.sent;r.t5=new r.t2(r.t3,r.t4);return r.abrupt("return",new r.t0(r.t1,r.t5));case 28:if(!L(o,a)){r.next=50;break}l=a instanceof Syntax?t:t.cdr;r.next=32;return a.invoke(l,_objectSpread(_objectSpread({},v),{},{env:i}),true);case 32:f=r.sent;if(!(a instanceof Syntax)){r.next=41;break}_=f,p=_.expr,d=_.scope;if(!is_pair(p)){r.next=40;break}if(!(n!==-1&&n<=1||n")}return"#"};var SyntaxParameter=_createClass(function e(r){_classCallCheck(this,e);read_only(this,"_syntax",r,{hidden:true});read_only(this._syntax,"_param",true,{hidden:true})});Syntax.Parameter=SyntaxParameter;function extract_patterns(e,r,B,I){var t=arguments.length>4&&arguments[4]!==undefined?arguments[4]:{};var j={"...":{symbols:{},lists:[]},symbols:{}};var R=t.expansion,T=t.define;log(B);function M(r,e){var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:false;log({code:e,pattern:r});if(is_atom(r)&&!(r instanceof LSymbol)){return same_atom(r,e)}if(r instanceof LSymbol&&B.includes(r.literal())){if(!LSymbol.is(e,r)){return false}var i=R.ref(r);return!i||i===T||i===global_env}if(Array.isArray(r)&&Array.isArray(e)){log("<<< a 1");if(r.length===0&&e.length===0){return true}if(LSymbol.is(r[1],I)){if(r[0]instanceof LSymbol){var o=r[0].valueOf();log("<<< a 2 "+n);if(n){var a=e.length-2;var u=a>0?e.slice(0,a):e;var s=Pair.fromArray(u,false);if(!j["..."].symbols[o]){j["..."].symbols[o]=new Pair(s,_nil)}else{j["..."].symbols[o].append(new Pair(s,_nil))}}else{j["..."].symbols[o]=Pair.fromArray(e,false)}}else if(Array.isArray(r[0])){log("<<< a 3");var c=_toConsumableArray(t);if(!e.every(function(e){return M(r[0],e,c,true)})){return false}}if(r.length>2){var l=r.slice(2);return M(l,e.slice(-l.length),t,n)}return true}var f=M(r[0],e[0],t,n);log({first:f,pattern:r[0],code:e[0]});var _=M(r.slice(1),e.slice(1),t,n);log({first:f,rest:_});return f&&_}if(is_pair(r)&&is_pair(r.car)&&is_pair(r.car.cdr)&&LSymbol.is(r.car.cdr.car,I)){log(">> 0");if(is_nil(e)){log({pattern:r});if(r.car.car instanceof LSymbol){var p=r.car.car.valueOf();if(j["..."].symbols[p]){throw new Error("syntax: named ellipsis can only "+"appear onces")}j["..."].symbols[p]=e}}}if(is_pair(r)&&is_pair(r.cdr)&&LSymbol.is(r.cdr.car,I)){if(!is_nil(r.cdr.cdr)){if(is_pair(r.cdr.cdr)){var d=r.cdr.cdr.length();if(!is_pair(e)){return false}var y=e.length();var h=e;while(y-1>d){h=h.cdr;y--}var m=h.cdr;h.cdr=_nil;if(!M(r.cdr.cdr,m,t,n)){return false}}}if(r.car instanceof LSymbol){var v=r.car.__name__;if(j["..."].symbols[v]&&!t.includes(v)&&!n){throw new Error("syntax: named ellipsis can only appear onces")}log(">> 1");if(is_nil(e)){log(">> 2");if(n){log("NIL");j["..."].symbols[v]=_nil}else{log("NULL");j["..."].symbols[v]=null}}else if(is_pair(e)&&(is_pair(e.car)||is_nil(e.car))){log(">> 3 "+n);if(n){if(j["..."].symbols[v]){var g=j["..."].symbols[v];if(is_nil(g)){g=new Pair(_nil,new Pair(e,_nil))}else{g=g.append(new Pair(e,_nil))}j["..."].symbols[v]=g}else{j["..."].symbols[v]=new Pair(e,_nil)}}else{log(">> 4");j["..."].symbols[v]=new Pair(e,_nil)}}else{log(">> 6");if(is_pair(e)){if(!is_pair(e.cdr)&&!is_nil(e.cdr)){log(">> 7 (b)");if(is_nil(r.cdr.cdr)){return false}else if(!j["..."].symbols[v]){j["..."].symbols[v]=new Pair(e.car,_nil);return M(r.cdr.cdr,e.cdr)}}var b=e.last_pair();if(!is_nil(b.cdr)){if(is_nil(r.cdr.cdr)){return false}else{var P=e.clone();P.last_pair().cdr=_nil;j["..."].symbols[v]=P;return M(r.cdr.cdr,b.cdr)}}log(">> 7 "+n);t.push(v);if(!j["..."].symbols[v]){j["..."].symbols[v]=new Pair(e,_nil)}else{var w=j["..."].symbols[v];j["..."].symbols[v]=w.append(new Pair(e,_nil))}log({IIIIII:j["..."].symbols[v]})}else if(r.car instanceof LSymbol&&is_pair(r.cdr)&&LSymbol.is(r.cdr.car,I)){log(">> 8");j["..."].symbols[v]=null;return M(r.cdr.cdr,e)}else{log(">> 9");return false}}return true}else if(is_pair(r.car)){var D=_toConsumableArray(t);if(is_nil(e)){log(">> 10");j["..."].lists.push(_nil);return true}log(">> 11");var x=e;while(is_pair(x)){if(!M(r.car,x.car,D,true)){return false}x=x.cdr}return true}if(Array.isArray(r.car)){var D=_toConsumableArray(t);var L=e;while(is_pair(L)){if(!M(r.car,L.car,D,true)){return false}L=L.cdr}return true}return false}if(r instanceof LSymbol){if(LSymbol.is(r,I)){throw new Error("syntax: invalid usage of ellipsis")}log(">> 12");var E=r.__name__;if(B.includes(E)){return true}if(n){var S,A;log(j["..."].symbols[E]);(A=(S=j["..."].symbols)[E])!==null&&A!==void 0?A:S[E]=[];j["..."].symbols[E].push(e)}else{j.symbols[E]=e}return true}if(is_pair(r)&&is_pair(e)){log(">> 13");log({a:13,code:e,pattern:r});if(is_nil(e.cdr)){var F=r.car instanceof LSymbol&&r.cdr instanceof LSymbol;if(F){if(!M(r.car,e.car,t,n)){return false}log(">> 14");var k=r.cdr.valueOf();if(!(k in j.symbols)){j.symbols[k]=_nil}k=r.car.valueOf();if(!(k in j.symbols)){j.symbols[k]=e.car}return true}}log({pattern:r,code:e});if(is_pair(r.cdr)&&is_pair(r.cdr.cdr)&&r.cdr.car instanceof LSymbol&&LSymbol.is(r.cdr.cdr.car,I)&&is_pair(r.cdr.cdr.cdr)&&!LSymbol.is(r.cdr.cdr.cdr.car,I)&&M(r.car,e.car,t,n)&&M(r.cdr.cdr.cdr,e.cdr,t,n)){var C=r.cdr.car.__name__;log({pattern:r,code:e,name:C});if(B.includes(C)){return true}j["..."].symbols[C]=null;return true}log("recur");log({pattern:r,code:e});var O=M(r.car,e.car,t,n);log({car:O,pattern:r.car,code:e.car});var N=M(r.cdr,e.cdr,t,n);log({car:O,cdr:N});if(O&&N){return true}}else if(is_nil(r)&&(is_nil(e)||e===undefined)){return true}else if(is_pair(r.car)&&LSymbol.is(r.car.car,I)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(M(e,r)){return j}}function clear_gensyms(e,i){function o(r){if(is_pair(r)){if(!i.length){return r}var e=o(r.car);var t=o(r.cdr);return new Pair(e,t)}else if(r instanceof LSymbol){var n=i.find(function(e){return e.gensym===r});if(n){return LSymbol(n.name)}return r}else{return r}}return o(e)}function transform_syntax(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var O=e.bindings,r=e.expr,N=e.scope,a=e.symbols,l=e.names,B=e.ellipsis;var f={};function u(e){if(e instanceof LSymbol){return true}return["string","symbol"].includes(_typeof$1(e))}function I(e){if(!u(e)){var r=type(e);throw new Error("syntax: internal error, need symbol got ".concat(r))}var t=e.valueOf();if(t===B){throw new Error("syntax: internal error, ellipis not transformed")}var n=_typeof$1(t);if(["string","symbol"].includes(n)){if(t in O.symbols){return O.symbols[t]}else if(n==="string"&&t.match(/\./)){var i=t.split(".");var o=i[0];if(o in O.symbols){return Pair.fromArray([LSymbol("."),O.symbols[o]].concat(i.slice(1).map(function(e){return LString(e)})))}}}if(a.includes(t)){return e}return s(t,e)}function s(e,r){if(!f[e]){var t=N.ref(e);if(_typeof$1(e)==="symbol"&&!t){e=r.literal()}if(f[e]){return f[e]}var n=gensym(e);if(t){var i=N.get(e);N.set(n,i)}else{var o=N.get(e,{throwError:false});if(typeof o!=="undefined"){N.set(n,o)}}l.push({name:e,gensym:n});f[e]=n;if(typeof e==="string"&&e.match(/\./)){var a=e.split(".").filter(Boolean),u=_toArray(a),s=u[0],c=u.slice(1);if(f[s]){hidden_prop(n,"__object__",[f[s]].concat(_toConsumableArray(c)))}}}return f[e]}function j(e,r,t){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:function(){};var i=t.nested;log({bindings:r,expr:e});if(Array.isArray(e)&&!e.length){return e}if(e instanceof LSymbol){var o=e.valueOf();if(is_gensym(e)&&!r[o]);log("[t 1");if(r[o]){if(is_pair(r[o])){var a=r[o],u=a.car,s=a.cdr;if(i){var c=u.car,l=u.cdr;if(!is_nil(l)){n(o,new Pair(l,_nil))}return c}if(!is_nil(s)){n(o,s)}return u}else if(r[o]instanceof Array){n(o,r[o].slice(1));return r[o][0]}}return I(e)}var f=Array.isArray(e);if(is_pair(e)||f){var _=f?e[0]:e.car;var p=f?e[1]:is_pair(e.cdr)&&e.cdr.car;if(_ instanceof LSymbol&&LSymbol.is(p,B)){f?e.slice(2):e.cdr.cdr;log("[t 2");var d=_.valueOf();var y=r[d];if(y===null){return}else if(y){log({name:d,binding:r[d]});if(is_pair(y)){log("[t 2 Pair "+i);var h=y.car,m=y.cdr;var v=f?e.slice(2):e.cdr.cdr;if(i){if(!is_nil(m)){log("|| next 1");n(d,m)}if(f&&v.length||!is_nil(v)&&!f){var g=j(v,r,t,n);if(f){return h.concat(g)}else if(is_pair(h)){return h.append(g)}else{log("UNKNOWN")}}return h}else if(is_pair(h)){if(!is_nil(h.cdr)){log("|| next 2");n(d,new Pair(h.cdr,m))}return h.car}else if(is_nil(m)){return h}else{var b=e.last_pair();if(b.cdr instanceof LSymbol){log("|| next 3");n(d,y.last_pair());return h}}}else if(y instanceof Array){log("[t 2 Array "+i);if(i){n(d,y.slice(1));return Pair.fromArray(y)}else{var P=y.slice(1);if(P.length){n(d,P)}return y[0]}}else{return y}}}log("[t 3 recur ",e);var w=f?e.slice(1):e.cdr;var D=j(_,r,t,n);var x=j(w,r,t,n);log({head:D,rest:x});if(f){return[D].concat(x)}return new Pair(D,x)}return e}function R(r,t){var e=Object.values(r);var n=Object.getOwnPropertySymbols(r);if(n.length){e.push.apply(e,_toConsumableArray(n.map(function(e){return r[e]})))}return e.length&&e.every(function(e){if(e===null){return!t}return is_pair(e)||is_nil(e)||Array.isArray(e)&&e.length})}function T(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function M(i){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=e.disabled;log("traverse>> ",i);var o=Array.isArray(i);if(o&&i.length===0){return i}if(is_pair(i)||o){var t=o?i[0]:i.car;var n,a;if(o){n=i[1];a=i.slice(2)}else if(is_pair(i.cdr)){n=i.cdr.car;a=i.cdr.cdr}log({first:t,second:n,rest_second:a});if(!r&&is_pair(t)&&LSymbol.is(t.car,B)){return new Pair(t.cdr.car,M(i.cdr))}if(n&&LSymbol.is(n,B)&&!r){log(">> 1");var u=O["..."].symbols;var s=Object.values(u);if(s.length&&s.every(function(e){return e===null})){log(">>> 1 (a)");return M(a,{disabled:r})}var c=T(u);var l=t instanceof LSymbol&&LSymbol.is(a.car,B);if(is_pair(t)||l){log(">>> 1 (b)");if(is_nil(O["..."].lists[0])){if(!l){return M(a,{disabled:r})}log(a);return _nil}var f=t;if(l){log(">>> 1 (c)");f=new Pair(t,new Pair(n,_nil))}log(">> 2");var _;if(c.length){log(">> 2 (a)");var p=_objectSpread({},u);_=o?[]:_nil;var d=function e(){log({bind:p});if(!R(p)){return 1}var n={};var r=function e(r,t){n[r]=t};var t=j(f,p,{nested:true},r);if(t!==undefined){if(l){if(o){if(Array.isArray(t)){var i;(i=_).push.apply(i,_toConsumableArray(t))}else{log("ZONK {1}")}}else{if(is_nil(_)){_=t}else{_=_.append(t)}}}else if(o){_.push(t)}else{_=new Pair(t,_)}}p=n};while(true){if(d())break}if(!is_nil(_)&&!l&&!o){_=_.reverse()}if(o){if(a){log({rest_second:a,expr:i});var y=M(a,{disabled:r});return _.concat(y)}return _}if(!is_nil(i.cdr.cdr)&&!LSymbol.is(i.cdr.cdr.car,B)){var h=M(i.cdr.cdr,{disabled:r});return _.append(h)}return _}else{log(">> 3");var m=j(t,u,{nested:true});if(m){return new Pair(m,_nil)}return _nil}}else if(t instanceof LSymbol){log(">> 4");if(LSymbol.is(a.car,B)){log(">> 4 (a)")}else{log(">> 4 (b)")}var v=t.__name__;var g=_defineProperty({},v,u[v]);log({bind:g});var b=u[v]===null;var P=o?[]:_nil;var w=function e(){if(!R(g,true)){log({bind:g});return 1}var n={};var r=function e(r,t){n[r]=t};var t=j(i,g,{nested:false},r);log({value:t});if(typeof t!=="undefined"){if(o){P.push(t)}else{P=new Pair(t,P)}}g=n};while(true){if(w())break}if(!is_nil(P)&&!o){P=P.reverse()}if(is_pair(i.cdr)){if(is_pair(i.cdr.cdr)||i.cdr.cdr instanceof LSymbol){var D=M(i.cdr.cdr,{disabled:r});log({node:D});if(b){return D}if(is_nil(P)){P=D}else{P.append(D)}log({result:P,node:D})}}log("<<<< 2");return P}}var x=M(t,{disabled:r});var L;var E;if(t instanceof LSymbol){var S=N.get(t,{throwError:false});E=S instanceof Macro&&S.__name__==="syntax-rules"}if(E){if(i.cdr.car instanceof LSymbol){L=new Pair(M(i.cdr.car,{disabled:r}),new Pair(i.cdr.cdr.car,M(i.cdr.cdr.cdr,{disabled:r})))}else{L=new Pair(i.cdr.car,M(i.cdr.cdr,{disabled:r}))}log("REST >>>> ",L)}else{L=M(i.cdr,{disabled:r})}log({a:true,car:toString(i.car),cdr:toString(i.cdr),head:toString(x),rest:toString(L)});return new Pair(x,L)}if(i instanceof LSymbol){if(r&&LSymbol.is(i,B)){return i}var A=Object.keys(O["..."].symbols);var F=i.literal();if(A.includes(F)){var k="missing ellipsis symbol next to name `".concat(F,"'");throw new Error("syntax-rules: ".concat(k))}var C=I(i);if(typeof C!=="undefined"){return C}}return i}return M(r,{})}function is_null(e){return is_undef(e)||is_nil(e)||e===null}function is_nil(e){return e===_nil}function is_function(e){return typeof e==="function"&&typeof e.bind==="function"}function is_directive(e){return directives.includes(e)}function is_false(e){return e===false||e===null}function is_string(e){return typeof e==="string"}function is_prototype(e){return e&&_typeof$1(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}function is_continuation(e){return e instanceof Continuation}function is_context(e){return e instanceof LambdaContext}function is_parameter(e){return e instanceof Parameter}function is_pair(e){return e instanceof Pair}function is_env(e){return e instanceof Environment}function is_callable(e){return is_function(e)||is_continuation(e)||is_parameter(e)||is_macro(e)}function is_macro(e){return e instanceof Macro||e instanceof SyntaxParameter}function is_promise(e){if(e instanceof QuotedPromise){return false}if(e instanceof Promise){return true}return!!e&&is_function(e.then)}function is_undef(e){return typeof e==="undefined"}function is_iterator(e,r){if(has_own_symbol(e,r)||has_own_symbol(e.__proto__,r)){return is_function(e[r])}}function is_instance(e){if(!e){return false}if(_typeof$1(e)!=="object"){return false}if(e.__instance__){e.__instance__=false;return e.__instance__}return false}function self_evaluated(e){var r=_typeof$1(e);return["string","function"].includes(r)||_typeof$1(e)==="symbol"||e instanceof QuotedPromise||e instanceof LSymbol||e instanceof LNumber||e instanceof LString||e instanceof RegExp}function is_native(e){return e instanceof LNumber||e instanceof LString||e instanceof LCharacter}function has_own_symbol(e,r){if(e===null){return false}return _typeof$1(e)==="object"&&r in Object.getOwnPropertySymbols(e)}function box(e){switch(_typeof$1(e)){case"string":return LString(e);case"bigint":return LNumber(e);case"number":if(Number.isNaN(e)){return nan}else{return LNumber(e)}}return e}function map_object(t,n){var e=Object.getOwnPropertyNames(t);var r=Object.getOwnPropertySymbols(t);var i={};e.concat(r).forEach(function(e){var r=n(t[e]);i[e]=r});return i}function unbox(r){var e=[LString,LNumber,LCharacter].some(function(e){return r instanceof e});if(e){return r.valueOf()}if(r instanceof Array){return r.map(unbox)}if(r instanceof QuotedPromise){delete r.then}if(is_plain_object(r)){return map_object(r,unbox)}return r}function patch_value(e,r){if(is_pair(e)){e.mark_cycles();return quote(e)}if(is_function(e)){if(r){return bind(e,r)}}return box(e)}function unbind(e){if(is_bound(e)){return e[__fn__]}return e}function bind(e,r){if(e[Symbol["for"]("__bound__")]){return e}var t=e.bind(r);var n=Object.getOwnPropertyNames(e);var i=_createForOfIteratorHelper(n),o;try{for(i.s();!(o=i.n()).done;){var a=o.value;if(filter_fn_names(a)){try{t[a]=e[a]}catch(e){}}}}catch(e){i.e(e)}finally{i.f()}hidden_prop(t,"__fn__",e);hidden_prop(t,"__context__",r);hidden_prop(t,"__bound__",true);if(is_native_function(e)){hidden_prop(t,"__native__",true)}if(is_plain_object(r)&&is_lambda(e)){hidden_prop(t,"__method__",true)}t.valueOf=function(){return e};return t}function is_object_bound(e){return is_bound(e)&&e[Symbol["for"]("__context__")]===Object}function is_bound(e){return!!(is_function(e)&&e[__fn__])}function lips_context(e){if(is_function(e)){var r=e[__context__];if(r&&(r===lips||r.constructor&&r.constructor.__class__)){return true}}return false}function is_port(e){return e instanceof InputPort||e instanceof OutputPort}function is_port_method(e){if(is_function(e)){if(is_port(e[__context__])){return true}}return false}var __context__=Symbol["for"]("__context__");var __fn__=Symbol["for"]("__fn__");var __data__=Symbol["for"]("__data__");var __ref__=Symbol["for"]("__ref__");var __cycles__=Symbol["for"]("__cycles__");var __class__=Symbol["for"]("__class__");var __method__=Symbol["for"]("__method__");var __prototype__=Symbol["for"]("__prototype__");var __lambda__=Symbol["for"]("__lambda__");var exluded_names=["name","length","caller","callee","arguments","prototype"];function filter_fn_names(e){return!exluded_names.includes(e)}function hidden_prop(e,r,t){Object.defineProperty(e,Symbol["for"](r),{get:function e(){return t},set:function e(){},configurable:false,enumerable:false})}function set_fn_length(r,t){try{Object.defineProperty(r,"length",{get:function e(){return t}});return r}catch(e){var n=new Array(t).fill(0).map(function(e,r){return"a"+r}).join(",");var i=new Function("f","return function(".concat(n,") {\n return f.apply(this, arguments);\n };"));return i(r)}}function is_lambda(e){return e&&e[__lambda__]}function is_method(e){return e&&e[__method__]}function is_raw_lambda(e){return is_lambda(e)&&!e[__prototype__]&&!is_method(e)&&!is_port_method(e)}function is_native_function(e){var r=Symbol["for"]("__native__");return is_function(e)&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[r]===true||!e.name.match(/^bound /)&&!e[r])}function let_macro(e){var P;switch(e){case Symbol["for"]("letrec"):P="letrec";break;case Symbol["for"]("let"):P="let";break;case Symbol["for"]("let*"):P="let*";break;default:throw new Error("Invalid let_macro value")}return Macro.defmacro(P,function(r,e){var l=e.dynamic_env;var f=e.error,t=e.macro_expand,_=e.use_dynamic;var p;if(r.car instanceof LSymbol){if(!(is_pair(r.cdr.car)||is_nil(r.cdr.car))){throw new Error("let require list of pairs")}var n;if(is_nil(r.cdr.car)){p=_nil;n=_nil}else{n=r.cdr.car.map(function(e){return e.car});p=r.cdr.car.map(function(e){return e.cdr.car})}var i=gensym("args");return Pair.fromArray([LSymbol("let"),[[i,Pair(LSymbol("list"),p)]],[LSymbol("letrec"),[[r.car,Pair(LSymbol("lambda"),Pair(n,r.cdr.cdr))]],[LSymbol("apply"),r.car,i]]])}else if(t){return}var d=this;p=global_env.get("list->array")(r.car);var y=d.inherit(P);var h,m;if(P==="let*"){m=y}else if(P==="let"){h=[]}var v=0;function g(){var e=new Pair(new LSymbol("begin"),r.cdr);return _evaluate(e,{env:y,dynamic_env:y,use_dynamic:_,error:f})}function b(e){if(e in y.__env__){throw new Error("Duplicated let variable ".concat(e))}}return function r(){var t=p[v++];l=P==="let*"?y:d;if(!t){if(h&&h.length){var e=h.map(function(e){return e.value});var n=e.filter(is_promise);if(n.length){return promise_all(e).then(function(e){for(var r=0,t=e.length;r1&&arguments[1]!==undefined?arguments[1]:{},t=r.use_dynamic,n=r.error;var i=this;var o=this;var a=[];var u=e;while(is_pair(u)){a.push(_evaluate(u.car,{env:i,dynamic_env:o,use_dynamic:t,error:n}));u=u.cdr}var s=a.filter(is_promise).length;if(s){return promise_all(a).then(c.bind(this))}else{return c.call(this,a)}})}function guard_math_call(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n2?n-2:0),o=2;o1&&arguments[1]!==undefined?arguments[1]:null;return function(){for(var e=arguments.length,r=new Array(e),t=0;t1?e-1:0),t=1;t=a){return o.apply(this,n)}else{return i}}return i.apply(this,arguments)}}function limit(n,i){typecheck("limit",i,"function",2);return function(){for(var e=arguments.length,r=new Array(e),t=0;t1){e=e.toLowerCase();if(LCharacter.__names__[e]){r=e;e=LCharacter.__names__[e]}else{throw new Error("Internal: Unknown named character")}}else{r=LCharacter.__rev_names__[e]}Object.defineProperty(this,"__char__",{value:e,enumerable:true});if(r){Object.defineProperty(this,"__name__",{value:r,enumerable:true})}}LCharacter.__names__=characters;LCharacter.__rev_names__={};Object.keys(LCharacter.__names__).forEach(function(e){var r=LCharacter.__names__[e];LCharacter.__rev_names__[r]=e});LCharacter.prototype.toUpperCase=function(){return LCharacter(this.__char__.toUpperCase())};LCharacter.prototype.toLowerCase=function(){return LCharacter(this.__char__.toLowerCase())};LCharacter.prototype.toString=function(){return"#\\"+(this.__name__||this.__char__)};LCharacter.prototype.valueOf=LCharacter.prototype.serialize=function(){return this.__char__};function LString(e){if(typeof this!=="undefined"&&!(this instanceof LString)||typeof this==="undefined"){return new LString(e)}if(e instanceof Array){this.__string__=e.map(function(e,r){typecheck("LString",e,"character",r+1);return e.toString()}).join("")}else{this.__string__=e.valueOf()}}{var ignore=["length","constructor"];var _keys=Object.getOwnPropertyNames(String.prototype).filter(function(e){return!ignore.includes(e)});var wrap=function e(n){return function(){for(var e=arguments.length,r=new Array(e),t=0;t0){t.push(this.__string__.substring(0,e))}t.push(r);if(e1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof LNumber){return e}if(typeof this!=="undefined"&&!(this instanceof LNumber)||typeof this==="undefined"){return new LNumber(e,r)}if(typeof e==="undefined"){throw new Error("Invalid LNumber constructor call")}var t=LNumber.getType(e);if(LNumber.types[t]){return LNumber.types[t](e,r)}var n=e instanceof Array&&LString.isString(e[0])&&LNumber.isNumber(e[1]);if(e instanceof LNumber){return LNumber(e.value)}if(!LNumber.isNumber(e)&&!n){throw new Error("You can't create LNumber from ".concat(type(e)))}if(e===null){e=0}var i;if(n){var o=e,a=_slicedToArray(o,2),u=a[0],s=a[1];if(u instanceof LString){u=u.valueOf()}if(s instanceof LNumber){s=s.valueOf()}var c=u.match(/^([+-])/);var l=false;if(c){u=u.replace(/^[+-]/,"");if(c[1]==="-"){l=true}}}if(Number.isNaN(e)){return LFloat(e)}else if(n&&Number.isNaN(parseInt(u,s))){return nan}else if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(n){var f;switch(s){case 8:f="0o";break;case 16:f="0x";break;case 2:f="0b";break;case 10:f="";break}if(typeof f==="undefined"){var _=BigInt(s);i=_toConsumableArray(u).map(function(e,r){return BigInt(parseInt(e,s))*pow(_,BigInt(r))}).reduce(function(e,r){return e+r})}else{i=BigInt(f+u)}}else{i=BigInt(e)}if(l){i*=BigInt(-1)}}else{i=e}return LBigInteger(i,true)}else if(typeof BN!=="undefined"&&!(e instanceof BN)){if(e instanceof Array){return LBigInteger(_construct(BN,_toConsumableArray(e)))}return LBigInteger(new BN(e))}else if(n){this.constant(parseInt(u,s),"integer")}else{this.constant(e,"integer")}}LNumber.prototype.constant=function(e,r){Object.defineProperty(this,"__value__",{value:e,enumerable:true});Object.defineProperty(this,"__type__",{value:r,enumerable:true})};LNumber.types={float:function e(r){return new LFloat(r)},complex:function e(r){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!LNumber.isComplex(r)){r={im:0,re:r}}return new LComplex(r,t)},rational:function e(r){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!LNumber.isRational(r)){r={num:r,denom:1}}return new LRational(r,t)}};LNumber.prototype.serialize=function(){return this.__value__};LNumber.prototype.isNaN=function(){return Number.isNaN(this.__value__)};LNumber.prototype.gcd=function(e){var r=this.abs();e=e.abs();if(e.cmp(r)===1){var t=r;r=e;e=t}while(true){r=r.rem(e);if(r.cmp(0)===0){return e}e=e.rem(r);if(e.cmp(0)===0){return r}}};LNumber.isFloat=function e(r){return r instanceof LFloat||Number(r)===r&&r%1!==0};LNumber.isNumber=function(e){return e instanceof LNumber||LNumber.isNative(e)||LNumber.isBN(e)};LNumber.isComplex=function(e){if(!e){return false}var r=e instanceof LComplex||(LNumber.isNumber(e.im)||LNumber.isRational(e.im)||Number.isNaN(e.im))&&(LNumber.isNumber(e.re)||LNumber.isRational(e.re)||Number.isNaN(e.re));return r};LNumber.isRational=function(e){if(!e){return false}return e instanceof LRational||LNumber.isNumber(e.num)&&LNumber.isNumber(e.denom)};LNumber.isInteger=function(e){if(!(LNumber.isNative(e)||e instanceof LNumber)){return false}if(LNumber.isFloat(e)){return false}if(LNumber.isRational(e)){return false}if(LNumber.isComplex(e)){return false}return true};LNumber.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};LNumber.isBigInteger=function(e){return e instanceof LBigInteger||typeof e==="bigint"||LNumber.isBN(e)};LNumber.isBN=function(e){return typeof BN!=="undefined"&&e instanceof BN};LNumber.getArgsType=function(e,r){if(e instanceof LFloat||r instanceof LFloat){return LFloat}if(e instanceof LBigInteger||r instanceof LBigInteger){return LBigInteger}return LNumber};LNumber.prototype.toString=function(e){if(Number.isNaN(this.__value__)){return"+nan.0"}if(e>=2&&e<36){return this.__value__.toString(e)}return this.__value__.toString()};LNumber.prototype.asType=function(e){var r=LNumber.getType(this);return LNumber.types[r]?LNumber.types[r](e):LNumber(e)};LNumber.prototype.isBigNumber=function(){return typeof this.__value__==="bigint"||typeof BN!=="undefined"&&!(this.value instanceof BN)};["floor","ceil","round"].forEach(function(e){LNumber.prototype[e]=function(){if(this["float"]||LNumber.isFloat(this.__value__)){return LNumber(Math[e](this.__value__))}else{return LNumber(Math[e](this.valueOf()))}}});LNumber.prototype.valueOf=function(){if(LNumber.isNative(this.__value__)){return Number(this.__value__)}else if(LNumber.isBN(this.__value__)){return this.__value__.toNumber()}};var matrix=function(){var e=function e(r,t){return[r,t]};return{bigint:{bigint:e,float:function e(r,t){return[LFloat(r.valueOf()),t]},rational:function e(r,t){return[{num:r,denom:1},t]},complex:function e(r,t){return[{im:0,re:r},t]}},integer:{integer:e,float:function e(r,t){return[LFloat(r.valueOf()),t]},rational:function e(r,t){return[{num:r,denom:1},t]},complex:function e(r,t){return[{im:0,re:r},t]}},float:{bigint:function e(r,t){return[r,t&&LFloat(t.valueOf())]},integer:function e(r,t){return[r,t&&LFloat(t.valueOf())]},float:e,rational:function e(r,t){return[r,t&&LFloat(t.valueOf())]},complex:function e(r,t){return[{re:r,im:LFloat(0)},t]}},complex:{bigint:r("bigint"),integer:r("integer"),float:r("float"),rational:r("rational"),complex:function e(r,t){var n=LNumber.coerce(r.__re__,t.__re__),i=_slicedToArray(n,2),o=i[0],a=i[1];var u=LNumber.coerce(r.__im__,t.__im__),s=_slicedToArray(u,2),c=s[0],l=s[1];return[{im:c,re:o},{im:l,re:a}]}},rational:{bigint:function e(r,t){return[r,t&&{num:t,denom:1}]},integer:function e(r,t){return[r,t&&{num:t,denom:1}]},float:function e(r,t){return[LFloat(r.valueOf()),t]},rational:e,complex:function e(r,t){return[{im:coerce(r.__type__,t.__im__.__type__,0)[0],re:coerce(r.__type__,t.__re__.__type__,r)[0]},{im:coerce(r.__type__,t.__im__.__type__,t.__im__)[0],re:coerce(r.__type__,t.__re__.__type__,t.__re__)[0]}]}}};function r(t){return function(e,r){return[{im:coerce(t,e.__im__.__type__,0,e.__im__)[1],re:coerce(t,e.__re__.__type__,0,e.__re__)[1]},{im:coerce(t,e.__im__.__type__,0,0)[1],re:coerce(t,r.__type__,0,r)[1]}]}}}();function coerce(e,r,t,n){return matrix[e][r](t,n)}LNumber.coerce=function(e,r){var t=LNumber.getType(e);var n=LNumber.getType(r);if(!matrix[t]){throw new Error("LNumber::coerce unknown lhs type ".concat(t))}else if(!matrix[t][n]){throw new Error("LNumber::coerce unknown rhs type ".concat(n))}var i=matrix[t][n](e,r);return i.map(function(e){return LNumber(e,true)})};LNumber.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof LNumber)){throw new Error("LNumber: you can't coerce ".concat(type(e)))}if(typeof e==="number"){e=LNumber(e)}return LNumber.coerce(this,e)};LNumber.getType=function(e){if(e instanceof LNumber){return e.__type__}if(LNumber.isFloat(e)){return"float"}if(LNumber.isComplex(e)){return"complex"}if(LNumber.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof BN!=="undefined"&&!(e instanceof BN)){return"bigint"}};LNumber.prototype.isFloat=function(){return!!(LNumber.isFloat(this.__value__)||this["float"])};var mapping={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var rev_mapping={};Object.keys(mapping).forEach(function(r){rev_mapping[mapping[r]]=r;LNumber.prototype[r]=function(e){return this.op(mapping[r],e)}});LNumber._ops={"*":function e(r,t){return r*t},"+":function e(r,t){return r+t},"-":function e(r,t){if(typeof t==="undefined"){return-r}return r-t},"/":function e(r,t){return r/t},"%":function e(r,t){return r%t},"|":function e(r,t){return r|t},"&":function e(r,t){return r&t},"~":function e(r){return~r},">>":function e(r,t){return r>>t},"<<":function e(r,t){return r<1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof LComplex)||typeof this==="undefined"){return new LComplex(e,r)}if(e instanceof LComplex){return LComplex({im:e.__im__,re:e.__re__})}if(LNumber.isNumber(e)&&r){if(!r){return Number(e)}}else if(!LNumber.isComplex(e)){var t="Invalid constructor call for LComplex expect &(:im :re ) object but got ".concat(toString(e));throw new Error(t)}var n=e.im instanceof LNumber?e.im:LNumber(e.im);var i=e.re instanceof LNumber?e.re:LNumber(e.re);this.constant(n,i)}LComplex.prototype=Object.create(LNumber.prototype);LComplex.prototype.constructor=LComplex;LComplex.prototype.constant=function(e,r){Object.defineProperty(this,"__im__",{value:e,enumerable:true});Object.defineProperty(this,"__re__",{value:r,enumerable:true});Object.defineProperty(this,"__type__",{value:"complex",enumerable:true})};LComplex.prototype.serialize=function(){return{re:this.__re__,im:this.__im__}};LComplex.prototype.toRational=function(e){var r=this.__im__,t=this.__re__;if(LNumber.isFloat(this.__im__)){r=LFloat(this.__im__).toRational(e)}if(LNumber.isFloat(this.__re__)){t=LFloat(this.__re__).toRational(e)}return LComplex({im:r,re:t})};LComplex.prototype.pow=function(e){e.cmp(0);if(e===0){return LNumber(1)}var r=LNumber(Math.atan2(this.__im__.valueOf(),this.__re__.valueOf()));var t=LNumber(this.modulus());if(LNumber.isComplex(e)&&e.__im__.cmp(0)!==0){var n=e.mul(Math.log(t.valueOf())).add(LComplex.i.mul(r).mul(e));if(!LNumber.isComplex(n)){return LFloat(Math.E).pow(n)}var i=LFloat(Math.E).pow(n.__re__.valueOf());return LComplex({re:i.mul(Math.cos(n.__im__.valueOf())),im:i.mul(Math.sin(n.__im__.valueOf()))})}var o=e.__re__.cmp(0)>0;e=e.__re__.valueOf();if(LNumber.isInteger(e)&&o){var a=this;while(--e){a=a.mul(this)}return a}var u=t.pow(e);var s=r.mul(e);return LComplex({re:u.mul(Math.cos(s)),im:u.mul(Math.sin(s))})};LComplex.prototype.add=function(e){return this.complex_op("add",e,function(e,r,t,n){return{re:e.add(r),im:t.add(n)}})};LComplex.prototype.factor=function(){if(this.__im__ instanceof LFloat||this.__im__ instanceof LFloat){var e=this.__re__,r=this.__im__;var t,n;if(e instanceof LFloat){t=e.toRational().mul(e.toRational())}else{t=e.mul(e)}if(r instanceof LFloat){n=r.toRational().mul(r.toRational())}else{n=r.mul(r)}return t.add(n)}else{return this.__re__.mul(this.__re__).add(this.__im__.mul(this.__im__))}};LComplex.prototype.modulus=function(){return this.factor().sqrt()};LComplex.prototype.conjugate=function(){return LComplex({re:this.__re__,im:this.__im__.sub()})};LComplex.prototype.sqrt=function(){var e=this.modulus();var r,t;if(e.cmp(0)===0){r=t=e}else if(this.__re__.cmp(0)===1){r=LFloat(.5).mul(e.add(this.__re__)).sqrt();t=this.__im__.div(r).div(2)}else{t=LFloat(.5).mul(e.sub(this.__re__)).sqrt();if(this.__im__.cmp(0)===-1){t=t.sub()}r=this.__im__.div(t).div(2)}return LComplex({im:t,re:r})};LComplex.prototype.div=function(e){if(LNumber.isNumber(e)&&!LNumber.isComplex(e)){if(!(e instanceof LNumber)){e=LNumber(e)}var r=this.__re__.div(e);var t=this.__im__.div(e);return LComplex({re:r,im:t})}else if(!LNumber.isComplex(e)){throw new Error("[LComplex::div] Invalid value")}if(this.cmp(e)===0){var n=this.coerce(e),i=_slicedToArray(n,2),o=i[0],a=i[1];var u=o.__im__.div(a.__im__);return u.coerce(a.__re__)[0]}var s=this.coerce(e),c=_slicedToArray(s,2),l=c[0],f=c[1];var _=f.factor();var p=f.conjugate();var d=l.mul(p);if(!LNumber.isComplex(d)){return d.div(_)}var y=d.__re__.op("/",_);var h=d.__im__.op("/",_);return LComplex({re:y,im:h})};LComplex.prototype.sub=function(e){return this.complex_op("sub",e,function(e,r,t,n){return{re:e.sub(r),im:t.sub(n)}})};LComplex.prototype.mul=function(e){return this.complex_op("mul",e,function(e,r,t,n){var i={re:e.mul(r).sub(t.mul(n)),im:e.mul(n).add(r.mul(t))};return i})};LComplex.prototype.complex_op=function(e,r,i){var o=this;var t=function e(r,t){var n=i(o.__re__,r,o.__im__,t);if("im"in n&&"re"in n){if(n.im.cmp(0)===0){return n.re}return LComplex(n,true)}return n};if(typeof r==="undefined"){return t()}if(LNumber.isNumber(r)&&!LNumber.isComplex(r)){if(!(r instanceof LNumber)){r=LNumber(r)}var n=r.asType(0);r={__im__:n,__re__:r}}else if(!LNumber.isComplex(r)){throw new Error("[LComplex::".concat(e,"] Invalid value"))}var a=r.__re__ instanceof LNumber?r.__re__:this.__re__.asType(r.__re__);var u=r.__im__ instanceof LNumber?r.__im__:this.__im__.asType(r.__im__);return t(a,u)};LComplex._op={"+":"add","-":"sub","*":"mul","/":"div"};LComplex.prototype._op=function(e,r){var t=LComplex._op[e];return this[t](r)};LComplex.prototype.cmp=function(e){var r=this.coerce(e),t=_slicedToArray(r,2),n=t[0],i=t[1];var o=n.__re__.coerce(i.__re__),a=_slicedToArray(o,2),u=a[0],s=a[1];var c=u.cmp(s);if(c!==0){return c}else{var l=n.__im__.coerce(i.__im__),f=_slicedToArray(l,2),_=f[0],p=f[1];return _.cmp(p)}};LComplex.prototype.valueOf=function(){return[this.__re__,this.__im__].map(function(e){return e.valueOf()})};LComplex.prototype.toString=function(){var e;if(this.__re__.cmp(0)!==0){e=[toString(this.__re__)]}else{e=[]}var r=this.__im__.valueOf();var t=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY].includes(r);var n=toString(this.__im__);if(!t&&!Number.isNaN(r)){var i=this.__im__.cmp(0);if(i<0||i===0&&this.__im__._minus){e.push("-")}else{e.push("+")}n=n.replace(/^-/,"")}e.push(n);e.push("i");return e.join("")};function LFloat(e){if(typeof this!=="undefined"&&!(this instanceof LFloat)||typeof this==="undefined"){return new LFloat(e)}if(!LNumber.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof LNumber){return LFloat(e.valueOf())}if(typeof e==="number"){if(Object.is(e,-0)){Object.defineProperty(this,"_minus",{value:true})}this.constant(e,"float")}}LFloat.prototype=Object.create(LNumber.prototype);LFloat.prototype.constructor=LFloat;LFloat.prototype.toString=function(e){if(this.__value__===Number.NEGATIVE_INFINITY){return"-inf.0"}if(this.__value__===Number.POSITIVE_INFINITY){return"+inf.0"}if(Number.isNaN(this.__value__)){return"+nan.0"}e&&(e=e.valueOf());var r=this.__value__.toString(e);if(!r.match(/e[+-]?[0-9]+$/i)){var t=r.replace(/^-/,"");var n=this.__value__<0?"-":"";if(r.match(/^-?0\.0{3}/)){var i=t.match(/^[.0]+/g)[0].length-1;var o=t.replace(/^[.0]+/,"").replace(/^([0-9a-f])/i,"$1.");return"".concat(n).concat(o,"e-").concat(i.toString(e))}if(r.match(/^-?[0-9a-f]{7,}\.?/i)){var a=t.match(/^[0-9a-f]+/gi)[0].length-1;var u=t.replace(/\./,"").replace(/^([0-9a-f])/i,"$1.").replace(/0+$/,"").replace(/\.$/,".0");return"".concat(n).concat(u,"e+").concat(a.toString(e))}if(!LNumber.isFloat(this.__value__)){var s=r+".0";return this._minus?"-"+s:s}}return r.replace(/^([0-9]+)e/,"$1.0e")};LFloat.prototype._op=function(e,r){if(r instanceof LNumber){r=r.__value__}var t=LNumber._ops[e];if(e==="/"&&this.__value__===0&&r===0){return NaN}return LFloat(t(this.__value__,r))};LFloat.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){return toRational(this.__value__.valueOf())}return approxRatio(e.valueOf())(this.__value__.valueOf())};LFloat.prototype.sqrt=function(){var e=this.valueOf();if(this.cmp(0)<0){var r=LFloat(Math.sqrt(-e));return LComplex({re:0,im:r})}return LFloat(Math.sqrt(e))};LFloat.prototype.abs=function(){var e=this.valueOf();if(e<0){e=-e}return LFloat(e)};var toRational=approxRatio(1e-10);function approxRatio(n){return function(e){var r=function e(n,r,t){var i=function e(r,t){return t0){i=simplest_rational2(n,t)}else if(n.cmp(t)<=0){i=t}else if(t.cmp(0)>0){i=simplest_rational2(t,n)}else if(r.cmp(0)<0){i=LNumber(simplest_rational2(n.sub(),t.sub())).sub()}else{i=LNumber(0)}if(LNumber.isFloat(r)||LNumber.isFloat(e)){return LFloat(i)}return i}function simplest_rational2(e,r){var t=LNumber(e).floor();var n=LNumber(r).floor();if(e.cmp(t)<1){return t}else if(t.cmp(n)===0){var i=LNumber(1).div(r.sub(n));var o=LNumber(1).div(e.sub(t));return t.add(LNumber(1).div(simplest_rational2(i,o)))}else{return t.add(LNumber(1))}}function LRational(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof LRational)||typeof this==="undefined"){return new LRational(e,r)}if(!LNumber.isRational(e)){throw new Error("Invalid constructor call for LRational")}var t,n;if(e instanceof LRational){t=LNumber(e.__num__);n=LNumber(e.__denom__)}else{t=LNumber(e.num);n=LNumber(e.denom)}if(!r&&n.cmp(0)!==0){var i=t.op("%",n).cmp(0)===0;if(i){return LNumber(t.div(n))}}this.constant(t,n)}LRational.prototype=Object.create(LNumber.prototype);LRational.prototype.constructor=LRational;LRational.prototype.constant=function(e,r){Object.defineProperty(this,"__num__",{value:e,enumerable:true});Object.defineProperty(this,"__denom__",{value:r,enumerable:true});Object.defineProperty(this,"__type__",{value:"rational",enumerable:true})};LRational.prototype.serialize=function(){return{num:this.__num__,denom:this.__denom__}};LRational.prototype.pow=function(e){if(LNumber.isRational(e)){return pow(this.valueOf(),e.valueOf())}var r=e.cmp(0);if(r===0){return LNumber(1)}if(r===-1){e=e.sub();var t=this.__denom__.pow(e);var n=this.__num__.pow(e);return LRational({num:t,denom:n})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};LRational.prototype.sqrt=function(){var e=this.__num__.sqrt();var r=this.__denom__.sqrt();if(e instanceof LFloat||r instanceof LFloat){return e.div(r)}return LRational({num:e,denom:r})};LRational.prototype.abs=function(){var e=this.__num__;var r=this.__denom__;if(e.cmp(0)===-1){e=e.sub()}if(r.cmp(0)!==1){r=r.sub()}return LRational({num:e,denom:r})};LRational.prototype.cmp=function(e){return LNumber(this.valueOf(),true).cmp(e)};LRational.prototype.toString=function(){var e=this.__num__.gcd(this.__denom__);var r,t;if(e.cmp(1)!==0){r=this.__num__.div(e);if(r instanceof LRational){r=LNumber(r.valueOf(true))}t=this.__denom__.div(e);if(t instanceof LRational){t=LNumber(t.valueOf(true))}}else{r=this.__num__;t=this.__denom__}var n=this.cmp(0)<0;if(n){if(r.abs().cmp(t.abs())===0){return r.toString()}}else if(r.cmp(t)===0){return r.toString()}return r.toString()+"/"+t.toString()};LRational.prototype.valueOf=function(e){if(this.__denom__.cmp(0)===0){if(this.__num__.cmp(0)<0){return Number.NEGATIVE_INFINITY}return Number.POSITIVE_INFINITY}if(e){return LNumber._ops["/"](this.__num__.value,this.__denom__.value)}return LFloat(this.__num__.valueOf()).div(this.__denom__.valueOf())};LRational.prototype.mul=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=this.__num__.mul(e.__num__);var t=this.__denom__.mul(e.__denom__);return LRational({num:r,denom:t})}var n=LNumber.coerce(this,e),i=_slicedToArray(n,2),o=i[0],a=i[1];return o.mul(a)};LRational.prototype.div=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=this.__num__.mul(e.__denom__);var t=this.__denom__.mul(e.__num__);return LRational({num:r,denom:t})}var n=LNumber.coerce(this,e),i=_slicedToArray(n,2),o=i[0],a=i[1];var u=o.div(a);return u};LRational.prototype._op=function(e,r){return this[rev_mapping[e]](r)};LRational.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=e.__num__.sub();var t=e.__denom__;return this.add(LRational({num:r,denom:t}))}if(!(e instanceof LNumber)){e=LNumber(e).sub()}else{e=e.sub()}var n=LNumber.coerce(this,e),i=_slicedToArray(n,2),o=i[0],a=i[1];return o.add(a)};LRational.prototype.add=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=this.__denom__;var t=e.__denom__;var n=this.__num__;var i=e.__num__;var o,a;if(r!==t){a=t.mul(n).add(i.mul(r));o=r.mul(t)}else{a=n.add(i);o=r}return LRational({num:a,denom:o})}if(LNumber.isFloat(e)){return LFloat(this.valueOf()).add(e)}var u=LNumber.coerce(this,e),s=_slicedToArray(u,2),c=s[0],l=s[1];return c.add(l)};function LBigInteger(e,r){if(typeof this!=="undefined"&&!(this instanceof LBigInteger)||typeof this==="undefined"){return new LBigInteger(e,r)}if(e instanceof LBigInteger){return LBigInteger(e.__value__,e._native)}if(!LNumber.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.constant(e,"bigint");Object.defineProperty(this,"_native",{value:r})}LBigInteger.prototype=Object.create(LNumber.prototype);LBigInteger.prototype.constructor=LBigInteger;LBigInteger.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};LBigInteger.prototype.serialize=function(){return this.__value__.toString()};LBigInteger.prototype._op=function(e,r){if(typeof r==="undefined"){if(LNumber.isBN(this.__value__)){e=LBigInteger.bn_op[e];return LBigInteger(this.__value__.clone()[e](),false)}return LBigInteger(LNumber._ops[e](this.__value__),true)}if(LNumber.isBN(this.__value__)&&LNumber.isBN(r.__value__)){e=LBigInteger.bn_op[e];return LBigInteger(this.__value__.clone()[e](r),false)}var t=LNumber._ops[e](this.__value__,r.__value__);if(e==="/"){var n=this.op("%",r).cmp(0)===0;if(n){return LNumber(t)}return LRational({num:this,denom:r})}return LBigInteger(t,true)};LBigInteger.prototype.sqrt=function(){var e;var r=this.cmp(0)<0;if(LNumber.isNative(this.__value__)){e=LNumber(Math.sqrt(r?-this.valueOf():this.valueOf()))}else if(LNumber.isBN(this.__value__)){e=r?this.__value__.neg().sqrt():this.__value__.sqrt()}if(r){return LComplex({re:0,im:e})}return e};LNumber.NaN=LNumber(NaN);LComplex.i=LComplex({im:1,re:0});function InputPort(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof InputPort)||typeof this==="undefined"){return new InputPort(e)}typecheck("InputPort",e,"function");read_only(this,"__type__",text_port);var i;Object.defineProperty(this,"__parser__",{enumerable:true,get:function e(){return i},set:function e(r){typecheck("InputPort::__parser__",r,"parser");i=r}});this._read=e;this._with_parser=this._with_init_parser.bind(this,_asyncToGenerator(_regeneratorRuntime.mark(function e(){var t;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:if(n.char_ready()){r.next=6;break}r.next=3;return n._read();case 3:t=r.sent;i=new Parser({env:n});i.parse(t);case 6:return r.abrupt("return",n.__parser__);case 7:case"end":return r.stop()}},e)})));this.char_ready=function(){return!!this.__parser__&&this.__parser__.__lexer__.peek()!==eof};this._make_defaults()}InputPort.prototype._make_defaults=function(){this.read=this._with_parser(function(e){return e.read_object()});this.read_line=this._with_parser(function(e){return e.__lexer__.read_line()});this.read_char=this._with_parser(function(e){return e.__lexer__.read_char()});this.read_string=this._with_parser(function(e,r){if(!LNumber.isInteger(r)){var t=LNumber.getType(r);typeErrorMessage("read-string",t,"integer")}return e.__lexer__.read_string(r.valueOf())});this.peek_char=this._with_parser(function(e){return e.__lexer__.peek_char()})};InputPort.prototype._with_init_parser=function(u,s){var c=this;return _asyncToGenerator(_regeneratorRuntime.mark(function e(){var t,n,i,o,a=arguments;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:r.next=2;return u.call(c);case 2:t=r.sent;for(n=a.length,i=new Array(n),o=0;o"};function OutputPort(e){if(typeof this!=="undefined"&&!(this instanceof OutputPort)||typeof this==="undefined"){return new OutputPort(e)}typecheck("OutputPort",e,"function");read_only(this,"__type__",text_port);this.write=e}OutputPort.prototype.is_open=function(){return this._closed!==true};OutputPort.prototype.close=function(){Object.defineProperty(this,"_closed",{get:function e(){return true},set:function e(){},configurable:false,enumerable:false});this.write=function(){throw new Error("output-port: port is closed")}};OutputPort.prototype.flush=function(){};OutputPort.prototype.toString=function(){return"#"};var BufferedOutputPort=function(e){_inherits(t,e);function t(e){var r;_classCallCheck(this,t);r=_callSuper(this,t,[function(){var e;return(e=r)._write.apply(e,arguments)}]);typecheck("BufferedOutputPort",e,"function");read_only(_assertThisInitialized(r),"_fn",e,{hidden:true});read_only(_assertThisInitialized(r),"_buffer",[],{hidden:true});return r}_createClass(t,[{key:"flush",value:function e(){if(this._buffer.length){this._fn(this._buffer.join(""));this._buffer.length=0}}},{key:"_write",value:function e(){var r=this;for(var t=arguments.length,n=new Array(t),i=0;i"};OutputStringPort.prototype.valueOf=function(){return this.__buffer__.map(function(e){return e.valueOf()}).join("")};function OutputFilePort(e,r){var t=this;if(typeof this!=="undefined"&&!(this instanceof OutputFilePort)||typeof this==="undefined"){return new OutputFilePort(e,r)}typecheck("OutputFilePort",e,"string");read_only(this,"__filename__",e);read_only(this,"_fd",r.valueOf(),{hidden:true});read_only(this,"__type__",text_port);this.write=function(e){if(!LString.isString(e)){e=toString(e)}else{e=e.valueOf()}t.fs().write(t._fd,e,function(e){if(e){throw e}})}}OutputFilePort.prototype=Object.create(OutputPort.prototype);OutputFilePort.prototype.constructor=OutputFilePort;OutputFilePort.prototype.fs=function(){if(!this._fs){this._fs=this.internal("fs")}return this._fs};OutputFilePort.prototype.internal=function(e){return user_env.get("**internal-env**").get(e)};OutputFilePort.prototype.close=function(){var n=this;return new Promise(function(r,t){n.fs().close(n._fd,function(e){if(e){t(e)}else{read_only(n,"_fd",null,{hidden:true});OutputPort.prototype.close.call(n);r()}})})};OutputFilePort.prototype.toString=function(){return"#")};function InputStringPort(e,r){var t=this;if(typeof this!=="undefined"&&!(this instanceof InputStringPort)||typeof this==="undefined"){return new InputStringPort(e)}typecheck("InputStringPort",e,"string");r=r||global_env;e=e.valueOf();this._with_parser=this._with_init_parser.bind(this,function(){if(!t.__parser__){t.__parser__=new Parser({env:r});t.__parser__.parse(e)}return t.__parser__});read_only(this,"__type__",text_port);this._make_defaults()}InputStringPort.prototype.char_ready=function(){return true};InputStringPort.prototype=Object.create(InputPort.prototype);InputStringPort.prototype.constructor=InputStringPort;InputStringPort.prototype.toString=function(){return"#"};function InputByteVectorPort(e){if(typeof this!=="undefined"&&!(this instanceof InputByteVectorPort)||typeof this==="undefined"){return new InputByteVectorPort(e)}typecheck("InputByteVectorPort",e,"uint8array");read_only(this,"__vector__",e);read_only(this,"__type__",binary_port);var t=0;Object.defineProperty(this,"__index__",{enumerable:true,get:function e(){return t},set:function e(r){typecheck("InputByteVectorPort::__index__",r,"number");if(r instanceof LNumber){r=r.valueOf()}if(typeof r==="bigint"){r=Number(r)}if(Math.floor(r)!==r){throw new Error("InputByteVectorPort::__index__ value is "+"not integer")}t=r}})}InputByteVectorPort.prototype=Object.create(InputPort.prototype);InputByteVectorPort.prototype.constructor=InputByteVectorPort;InputByteVectorPort.prototype.toString=function(){return"#"};InputByteVectorPort.prototype.close=function(){var r=this;read_only(this,"__vector__",_nil);var t=function e(){throw new Error("Input-binary-port: port is closed")};["read_u8","close","peek_u8","read_u8_vector"].forEach(function(e){r[e]=t});this.u8_ready=this.char_ready=function(){return false}};InputByteVectorPort.prototype.u8_ready=function(){return true};InputByteVectorPort.prototype.peek_u8=function(){if(this.__index__>=this.__vector__.length){return eof}return this.__vector__[this.__index__]};InputByteVectorPort.prototype.skip=function(){if(this.__index__<=this.__vector__.length){++this.__index__}};InputByteVectorPort.prototype.read_u8=function(){var e=this.peek_u8();this.skip();return e};InputByteVectorPort.prototype.read_u8_vector=function(e){if(typeof e==="undefined"){e=this.__vector__.length}else if(e>this.__index__+this.__vector__.length){e=this.__index__+this.__vector__.length}if(this.peek_u8()===eof){return eof}return this.__vector__.slice(this.__index__,e)};function OutputByteVectorPort(){if(typeof this!=="undefined"&&!(this instanceof OutputByteVectorPort)||typeof this==="undefined"){return new OutputByteVectorPort}read_only(this,"__type__",binary_port);read_only(this,"_buffer",[],{hidden:true});this.write=function(e){typecheck("write",e,["number","uint8array"]);if(LNumber.isNumber(e)){this._buffer.push(e.valueOf())}else{var r;(r=this._buffer).push.apply(r,_toConsumableArray(Array.from(e)))}};Object.defineProperty(this,"__buffer__",{enumerable:true,get:function e(){return Uint8Array.from(this._buffer)}})}OutputByteVectorPort.prototype=Object.create(OutputPort.prototype);OutputByteVectorPort.prototype.constructor=OutputByteVectorPort;OutputByteVectorPort.prototype.close=function(){OutputPort.prototype.close.call(this);read_only(this,"_buffer",null,{hidden:true})};OutputByteVectorPort.prototype._close_guard=function(){if(this._closed){throw new Error("output-port: binary port is closed")}};OutputByteVectorPort.prototype.write_u8=function(e){typecheck("OutputByteVectorPort::write_u8",e,"number");this.write(e)};OutputByteVectorPort.prototype.write_u8_vector=function(e){typecheck("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};OutputByteVectorPort.prototype.toString=function(){return"#"};OutputByteVectorPort.prototype.valueOf=function(){return this.__buffer__};function InputFilePort(e,r){if(typeof this!=="undefined"&&!(this instanceof InputFilePort)||typeof this==="undefined"){return new InputFilePort(e,r)}InputStringPort.call(this,e);typecheck("InputFilePort",r,"string");read_only(this,"__filename__",r)}InputFilePort.prototype=Object.create(InputStringPort.prototype);InputFilePort.prototype.constructor=InputFilePort;InputFilePort.prototype.toString=function(){return"#")};function InputBinaryFilePort(e,r){if(typeof this!=="undefined"&&!(this instanceof InputBinaryFilePort)||typeof this==="undefined"){return new InputBinaryFilePort(e,r)}InputByteVectorPort.call(this,e);typecheck("InputBinaryFilePort",r,"string");read_only(this,"__filename__",r)}InputBinaryFilePort.prototype=Object.create(InputByteVectorPort.prototype);InputBinaryFilePort.prototype.constructor=InputBinaryFilePort;InputBinaryFilePort.prototype.toString=function(){return"#")};function OutputBinaryFilePort(e,r){var i=this;if(typeof this!=="undefined"&&!(this instanceof OutputBinaryFilePort)||typeof this==="undefined"){return new OutputBinaryFilePort(e,r)}typecheck("OutputBinaryFilePort",e,"string");read_only(this,"__filename__",e);read_only(this,"_fd",r.valueOf(),{hidden:true});read_only(this,"__type__",binary_port);var o;this.write=function(e){typecheck("write",e,["number","uint8array"]);var n;if(!o){o=i.internal("fs")}if(LNumber.isNumber(e)){n=new Uint8Array([e.valueOf()])}else{n=new Uint8Array(Array.from(e))}return new Promise(function(r,t){o.write(i._fd,n,function(e){if(e){t(e)}else{r()}})})}}OutputBinaryFilePort.prototype=Object.create(OutputFilePort.prototype);OutputBinaryFilePort.prototype.constructor=OutputBinaryFilePort;OutputBinaryFilePort.prototype.write_u8=function(e){typecheck("OutputByteVectorPort::write_u8",e,"number");this.write(e)};OutputBinaryFilePort.prototype.write_u8_vector=function(e){typecheck("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};var binary_port=Symbol["for"]("binary");var text_port=Symbol["for"]("text");var eof=new EOF;function EOF(){}EOF.prototype.toString=function(){return"#"};function Interpreter(e){var r=this;var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=t.stderr,i=t.stdin,o=t.stdout,a=t.command_line,u=a===void 0?null:a,s=_objectWithoutProperties(t,_excluded3);if(typeof this!=="undefined"&&!(this instanceof Interpreter)||typeof this==="undefined"){return new Interpreter(e,_objectSpread({stdin:i,stdout:o,stderr:n,command_line:u},s))}if(typeof e==="undefined"){e="anonymous"}this.__parser__=new Parser({env:this.__env__});this.__env__=user_env.inherit(e,s);this.__env__.set("parent.frame",doc("parent.frame",function(){return r.__env__},global_env.__env__["parent.frame"].__doc__));var c="**interaction-environment-defaults**";this.set(c,get_props(s).concat(c));var l=internal_env.inherit("internal-".concat(e));if(is_port(i)){l.set("stdin",i)}if(is_port(n)){l.set("stderr",n)}if(is_port(o)){l.set("stdout",o)}l.set("command-line",u);set_interaction_env(this.__env__,l)}Interpreter.prototype.exec=function(){var r=_asyncToGenerator(function(a){var u=this;var s=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return _regeneratorRuntime.mark(function e(){var t,n,i,o;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:t=s.use_dynamic,n=t===void 0?false:t,i=s.dynamic_env,o=s.env;typecheck("Interpreter::exec",a,["string","array"],1);typecheck("Interpreter::exec",n,"boolean",2);if(!o){o=u.__env__}if(!i){i=o}global_env.set("**interaction-environment**",u.__env__);if(!Array.isArray(a)){r.next=10;break}return r.abrupt("return",exec(a,{env:o,dynamic_env:i,use_dynamic:n}));case 10:u.__parser__.parse(a);return r.abrupt("return",exec(u.__parser__,{env:o,dynamic_env:i,use_dynamic:n}));case 12:case"end":return r.stop()}},e)})()});return function(e){return r.apply(this,arguments)}}();Interpreter.prototype.get=function(e){var r=this.__env__.get(e);if(is_function(r)){var t=new LambdaContext({env:this.__env__});return r.bind(t)}return r};Interpreter.prototype.set=function(e,r){return this.__env__.set(e,r)};Interpreter.prototype.constant=function(e,r){return this.__env__.constant(e,r)};function LipsError(e,r){this.name="LipsError";this.message=e;this.args=r;this.stack=(new Error).stack}LipsError.prototype=new Error;LipsError.prototype.constructor=LipsError;var IgnoreException=function(e){_inherits(r,e);function r(){_classCallCheck(this,r);return _callSuper(this,r,arguments)}return _createClass(r)}(_wrapNativeSuper(Error));function Environment(e,r,t){if(arguments.length===1){if(_typeof$1(arguments[0])==="object"){e=arguments[0];r=null}else if(typeof arguments[0]==="string"){e={};r=null;t=arguments[0]}}this.__docs__=new Map;this.__env__=e;this.__parent__=r;this.__name__=t||"anonymous"}Environment.prototype.list=function(){return get_props(this.__env__)};Environment.prototype.fs=function(){return this.get("**fs**")};Environment.prototype.unset=function(e){if(e instanceof LSymbol){e=e.valueOf()}if(e instanceof LString){e=e.valueOf()}delete this.__env__[e]};Environment.prototype.inherit=function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(_typeof$1(e)==="object"){r=e}if(!e||_typeof$1(e)==="object"){e="child of "+(this.__name__||"unknown")}return new Environment(r||{},this,e)};Environment.prototype.doc=function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}if(r){if(!t){r=trim_lines(r)}this.__docs__.set(e,r);return this}if(this.__docs__.has(e)){return this.__docs__.get(e)}if(this.__parent__){return this.__parent__.doc(e)}};Environment.prototype.new_frame=function(e,r){var n=this.inherit("__frame__");n.set("parent.frame",doc("parent.frame",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;e=e.valueOf();var r=n.__parent__;if(!is_env(r)){return _nil}if(e<=0){return r}var t=r.get("parent.frame");return t(e-1)},global_env.__env__["parent.frame"].__doc__));r.callee=e;n.set("arguments",r);return n};Environment.prototype._lookup=function(e){if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}if(this.__env__.hasOwnProperty(e)){return Value(this.__env__[e])}if(this.__parent__){return this.__parent__._lookup(e)}};Environment.prototype.toString=function(){return"#"};Environment.prototype.clone=function(){var r=this;var t={};Object.keys(this.__env__).forEach(function(e){t[e]=r.__env__[e]});return new Environment(t,this.__parent__,this.__name__)};Environment.prototype.merge=function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"merge";typecheck("Environment::merge",e,"environment");return this.inherit(r,e.__env__)};function Value(e){if(typeof this!=="undefined"&&!(this instanceof Value)||typeof this==="undefined"){return new Value(e)}this.value=e}Value.isUndefined=function(e){return e instanceof Value&&typeof e.value==="undefined"};Value.prototype.valueOf=function(){return this.value};function Values(e){if(!e.length){return}if(e.length===1){return e[0]}if(typeof this!=="undefined"&&!(this instanceof Values)||typeof this==="undefined"){return new Values(e)}this.__values__=e}Values.prototype.toString=function(){return this.__values__.map(function(e){return toString(e)}).join("\n")};Values.prototype.valueOf=function(){return this.__values__};Environment.prototype.get=function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};typecheck("Environment::get",e,["symbol","string"]);var t=r.throwError,n=t===void 0?true:t;var i=e;if(i instanceof LSymbol||i instanceof LString){i=i.valueOf()}var o=this._lookup(i);if(o instanceof Value){if(Value.isUndefined(o)){return undefined}return patch_value(o.valueOf())}var a;if(e instanceof LSymbol&&e[LSymbol.object]){a=e[LSymbol.object]}else if(typeof i==="string"){a=i.split(".").filter(Boolean)}if(a&&a.length>0){var u=a,s=_toArray(u),c=s[0],l=s.slice(1);o=this._lookup(c);if(l.length){try{if(o instanceof Value){o=o.valueOf()}else{o=get(root,c);if(is_function(o)){o=unbind(o)}}if(typeof o!=="undefined"){return get.apply(void 0,[o].concat(_toConsumableArray(l)))}}catch(e){throw e}}else if(o instanceof Value){return patch_value(o.valueOf())}o=get(root,i)}if(typeof o!=="undefined"){return o}if(n){throw new Error("Unbound variable `"+i.toString()+"'")}};Environment.prototype.set=function(e,r){var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;typecheck("Environment::set",e,["string","symbol"]);if(LNumber.isNumber(r)){r=LNumber(r)}if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}this.__env__[e]=r;if(t){this.doc(e,t,true)}return this};Environment.prototype.constant=function(r,e){var t=this;if(this.__env__.hasOwnProperty(r)){throw new Error("Environment::constant: ".concat(r," already exists"))}if(arguments.length===1&&is_plain_object(arguments[0])){var n=arguments[0];Object.keys(n).forEach(function(e){t.constant(r,n[e])})}else{Object.defineProperty(this.__env__,r,{value:e,enumerable:true})}return this};Environment.prototype.has=function(e){return this.__env__.hasOwnProperty(e)};Environment.prototype.ref=function(e){var r=this;while(true){if(!r){break}if(r.has(e)){return r}r=r.__parent__}};Environment.prototype.parents=function(){var e=this;var r=[];while(e){r.unshift(e);e=e.__parent__}return r};function quote(e){if(is_promise(e)){return e.then(quote)}if(is_pair(e)||e instanceof LSymbol){e[__data__]=true}return e}var native_lambda=_parse(tokenize('(lambda ()\n "[native code]"\n (throw "Invalid Invocation"))'))[0];var get=doc("get",function e(r){var t;for(var n=arguments.length,i=new Array(n>1?n-1:0),o=1;o0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=internal(this,"stdin")}typecheck_text_port("peek-char",e,"input-port");return e.peek_char()},"(peek-char port)\n\n This function reads and returns a character from the string\n port, or, if there is no more data in the string port, it\n returns an EOF."),"read-line":doc("read-line",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=internal(this,"stdin")}typecheck_text_port("read-line",e,"input-port");return e.read_line()},"(read-line port)\n\n This function reads and returns the next line from the input\n port."),"read-char":doc("read-char",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=internal(this,"stdin")}typecheck_text_port("read-char",e,"input-port");return e.read_char()},"(read-char port)\n\n This function reads and returns the next character from the\n input port."),read:doc("read",function(){var e=_asyncToGenerator(function(){var i=this;var o=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;return _regeneratorRuntime.mark(function e(){var t,n;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:t=i.env;if(o===null){n=internal(t,"stdin")}else{n=o}typecheck_text_port("read",n,"input-port");return r.abrupt("return",n.read.call(t));case 4:case"end":return r.stop()}},e)})()});function r(){return e.apply(this,arguments)}return r}(),"(read [port])\n\n This function, if called with a port, it will parse the next\n item from the port. If called without an input, it will read\n a string from standard input (using the browser's prompt or\n a user defined input method) and parse it. This function can be\n used together with `eval` to evaluate code from port."),pprint:doc("pprint",function e(r){if(is_pair(r)){r=new lips.Formatter(r.toString(true))["break"]().format();global_env.get("display").call(global_env,r)}else{global_env.get("write").call(global_env,r)}global_env.get("newline").call(global_env)},"(pprint expression)\n\n This function will pretty print its input to stdout. If it is called\n with a non-list, it will just call the print function on its\n input."),print:doc("print",function e(){var r=global_env.get("display");var t=global_env.get("newline");var n=this.use_dynamic;var i=global_env;var o=global_env;for(var a=arguments.length,u=new Array(a),s=0;s1?t-1:0),i=1;in.length){throw new Error("Not enough arguments")}var u=0;var s=global_env.get("repr");r=r.replace(o,function(e){var r=e[1];if(r==="~"){return"~"}else if(r==="%"){return"\n"}else{var t=n[u++];if(r==="a"){return s(t)}else{return s(t,true)}}});a=r.match(/~([\S])/);if(a){throw new Error("format: Unrecognized escape sequence ".concat(a[1]))}return r},"(format string n1 n2 ...)\n\n This function accepts a string template and replaces any\n escape sequences in its inputs:\n\n * ~a value as if printed with `display`\n * ~s value as if printed with `write`\n * ~% newline character\n * ~~ literal tilde '~'\n\n If there are missing inputs or other escape characters it\n will error."),display:doc("display",function e(r){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(t===null){t=internal(this,"stdout")}else{typecheck("display",t,"output-port")}var n=r;if(!(t instanceof OutputBinaryFilePort)){n=global_env.get("repr")(r)}t.write.call(global_env,n)},"(display string [port])\n\n This function outputs the string to the standard output or\n the port if given. No newline."),"display-error":doc("display-error",function e(){var r=internal(this,"stderr");var t=global_env.get("repr");for(var n=arguments.length,i=new Array(n),o=0;o1&&arguments[1]!==undefined?arguments[1]:{},t=r.use_dynamic,n=_objectWithoutProperties(r,_excluded4);var i=this;var a=this;var u;var s=_objectSpread(_objectSpread({},n),{},{env:this,dynamic_env:i,use_dynamic:t});var c=_evaluate(e.cdr.car,s);c=resolve_promises(c);function l(r,t,n){if(is_promise(r)){return r.then(function(e){return l(r,e,n)})}if(is_promise(t)){return t.then(function(e){return l(r,e,n)})}if(is_promise(n)){return n.then(function(e){return l(r,t,e)})}a.get("set-obj!").call(a,r,t,n);return n}if(is_pair(e.car)&&LSymbol.is(e.car.car,".")){var f=e.car.cdr.car;var _=e.car.cdr.cdr.car;var p=_evaluate(f,s);var d=_evaluate(_,s);return l(p,d,c)}if(!(e.car instanceof LSymbol)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var y=e.car.valueOf();u=this.ref(e.car.__name__);return unpromise(c,function(e){if(!u){var r=y.split(".");if(r.length>1){var t=r.pop();var n=r.join(".");var i=o.get(n,{throwError:false});if(i){l(i,t,e);return}}throw new Error("Unbound variable `"+y+"'")}u.set(y,e)})}),"(set! name value)\n\n Macro that can be used to set the value of the variable or slot (mutate it).\n set! searches the scope chain until it finds first non empty slot and sets it."),"unset!":doc(new Macro("set!",function(e){if(!(e.car instanceof LSymbol)){throw new Error("unset! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var r=e.car;var t=this.ref(r);if(t){delete t.__env__[r.__name__]}}),"(unset! name)\n\n Function to delete the specified name from environment.\n Trying to access the name afterwards will error."),"set-car!":doc("set-car!",function(e,r){typecheck("set-car!",e,"pair");e.car=r},"(set-car! obj value)\n\n Function that sets the car (first item) of the list/pair to specified value.\n The old value is lost."),"set-cdr!":doc("set-cdr!",function(e,r){typecheck("set-cdr!",e,"pair");e.cdr=r},"(set-cdr! obj value)\n\n Function that sets the cdr (tail) of the list/pair to specified value.\n It will destroy the list. The old tail is lost."),"empty?":doc("empty?",function(e){return typeof e==="undefined"||is_nil(e)},"(empty? object)\n\n Function that returns #t if value is nil (an empty list) or undefined."),gensym:doc("gensym",gensym,"(gensym)\n\n Generates a unique symbol that is not bound anywhere,\n to use with macros as meta name."),load:doc("load",function e(u,r){typecheck("load",u,"string");var s=this;if(s.__name__==="__frame__"){s=s.__parent__}if(!(r instanceof Environment)){if(s===global_env){r=s}else{r=this.get("**interaction-environment**")}}var c="**module-path**";var l=global_env.get(c,{throwError:false});u=u.valueOf();if(!u.match(/.[^.]+$/)){u+=".scm"}var t=u.match(/\.xcb$/);function f(e){if(t){e=unserialize_bin(e)}else{if(type(e)==="buffer"){e=e.toString()}e=e.replace(/^(#!.*)/,function(e,r){if(is_directive(r)){return r}return""});if(e.match(/^\{/)){e=unserialize(e)}}return exec(e,{env:r})}function n(e){return root.fetch(e).then(function(e){return t?e.arrayBuffer():e.text()}).then(function(e){if(t){e=new Uint8Array(e)}return e})}if(is_node()){return new Promise(function(){var t=_asyncToGenerator(_regeneratorRuntime.mark(function e(t,n){var i,o,a;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:i=nodeRequire("path");if(!l){r.next=6;break}l=l.valueOf();u=i.join(l,u);r.next=12;break;case 6:o=s.get("command-line",{throwError:false});if(!o){r.next=11;break}r.next=10;return o();case 10:a=r.sent;case 11:if(a&&!is_nil(a)){process.cwd();u=i.join(i.dirname(a.car.valueOf()),u)}case 12:global_env.set(c,i.dirname(u));nodeRequire("fs").readFile(u,function(e,r){if(e){n(e);global_env.set(c,l)}else{try{f(r).then(function(){t();global_env.set(c,l)})["catch"](n)}catch(e){n(e)}}});case 14:case"end":return r.stop()}},e)}));return function(e,r){return t.apply(this,arguments)}}())}if(l){l=l.valueOf();u=l+"/"+u.replace(/^\.?\/?/,"")}return n(u).then(function(e){global_env.set(c,u.replace(/\/[^/]*$/,""));return f(e)}).then(function(){})["finally"](function(){global_env.set(c,l)})},"(load filename)\n (load filename environment)\n\n Fetches the file (from disk or network) and evaluates its content as LIPS code.\n If the second argument is provided and it's an environment the evaluation\n will happen in that environment."),while:doc(new Macro("while",function(e,r){var t=e.car;var n=_objectSpread(_objectSpread({},r),{},{env:this});var i=new Pair(new LSymbol("begin"),e.cdr);return function r(){return unpromise(_evaluate(t,n),function(e){if(e){return unpromise(_evaluate(i,n),r)}})}()}),"(while cond body)\n\n Creates a loop, it executes cond and body until cond expression is false."),do:doc(new Macro("do",function(){var t=_asyncToGenerator(function(_,e){var p=this;var d=e.use_dynamic,y=e.error;return _regeneratorRuntime.mark(function e(){var u,t,s,c,n,l,f,i,o,a;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:u=p;t=u;s=u.inherit("do");c=_.car;n=_.cdr.car;l=_.cdr.cdr;if(!is_nil(l)){l=new Pair(LSymbol("begin"),l)}f={env:u,dynamic_env:t,use_dynamic:d,error:y};i=c;case 9:if(is_nil(i)){r.next=20;break}o=i.car;r.t0=s;r.t1=o.car;r.next=15;return _evaluate(o.cdr.car,f);case 15:r.t2=r.sent;r.t0.set.call(r.t0,r.t1,r.t2);i=i.cdr;r.next=9;break;case 20:f={env:s,dynamic_env:t,error:y};a=_regeneratorRuntime.mark(function e(){var t,n,i,o,a;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:if(is_nil(l)){r.next=3;break}r.next=3;return lips.evaluate(l,f);case 3:t=c;n={};case 5:if(is_nil(t)){r.next=15;break}i=t.car;if(is_nil(i.cdr.cdr)){r.next=12;break}r.next=10;return _evaluate(i.cdr.cdr.car,f);case 10:o=r.sent;n[i.car.valueOf()]=o;case 12:t=t.cdr;r.next=5;break;case 15:a=Object.getOwnPropertySymbols(n);f.env=s=u.inherit("do");Object.keys(n).concat(a).forEach(function(e){s.set(e,n[e])});case 18:case"end":return r.stop()}},e)});case 22:r.next=24;return _evaluate(n.car,f);case 24:r.t3=r.sent;if(!(r.t3===false)){r.next=29;break}return r.delegateYield(a(),"t4",27);case 27:r.next=22;break;case 29:if(is_nil(n.cdr)){r.next=33;break}r.next=32;return _evaluate(n.cdr.car,f);case 32:return r.abrupt("return",r.sent);case 33:case"end":return r.stop()}},e)})()});return function(e,r){return t.apply(this,arguments)}}()),"(do (( )) (test return) . body)\n\n Iteration macro that evaluates the expression body in scope of the variables.\n On each loop it changes the variables according to the expression and runs\n test to check if the loop should continue. If test is a single value, the macro\n will return undefined. If the test is a pair of expressions the macro will\n evaluate and return the second expression after the loop exits."),if:doc(new Macro("if",function(t,e){var r=e.error,n=e.use_dynamic;var i=this;var o=this;var a={env:o,dynamic_env:i,use_dynamic:n,error:r};var u=function e(r){if(is_false(r)){return _evaluate(t.cdr.cdr.car,a)}else{return _evaluate(t.cdr.car,a)}};if(is_nil(t)){throw new Error("too few expressions for `if`")}var s=_evaluate(t.car,a);return unpromise(s,u)}),"(if cond true-expr false-expr)\n\n Macro that evaluates cond expression and if the value is true, it\n evaluates and returns true-expression, if not it evaluates and returns\n false-expression."),"let-env":new Macro("let-env",function(r){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var t=e.dynamic_env,n=e.use_dynamic,i=e.error;typecheck("let-env",r,"pair");var o=_evaluate(r.car,{env:this,dynamic_env:t,error:i,use_dynamic:n});return unpromise(o,function(e){typecheck("let-env",e,"environment");return _evaluate(Pair(LSymbol("begin"),r.cdr),{env:e,dynamic_env:t,error:i})})},"(let-env env . body)\n\n Special macro that evaluates body in context of given environment\n object."),letrec:doc(let_macro(Symbol["for"]("letrec")),"(letrec ((a value-a) (b value-b) ...) . body)\n\n Macro that creates a new environment, then evaluates and assigns values to\n names and then evaluates the body in context of that environment.\n Values are evaluated sequentially and the next value can access the\n previous values/names."),"letrec*":doc(let_macro(Symbol["for"]("letrec")),"(letrec* ((a value-a) (b value-b) ...) . body)\n\n Same as letrec but the order of execution of the binding is guaranteed,\n so you can use recursive code as well as referencing the previous binding.\n\n In LIPS both letrec and letrec* behave the same."),"let*":doc(let_macro(Symbol["for"]("let*")),"(let* ((a value-a) (b value-b) ...) . body)\n\n Macro similar to `let`, but the subsequent bindings after the first\n are evaluated in the environment including the previous let variables,\n so you can define one variable, and use it in the next's definition."),let:doc(let_macro(Symbol["for"]("let")),"(let ((a value-a) (b value-b) ...) . body)\n\n Macro that creates a new environment, then evaluates and assigns values to names,\n and then evaluates the body in context of that environment. Values are evaluated\n sequentially but you can't access previous values/names when the next are\n evaluated. You can only get them in the body of the let expression. (If you want\n to define multiple variables and use them in each other's definitions, use\n `let*`.)"),"begin*":doc(parallel("begin*",function(e){return e.pop()}),"(begin* . body)\n\n This macro is a parallel version of begin. It evaluates each expression\n in the body and if it's a promise it will await it in parallel and return\n the value of the last expression (i.e. it uses Promise.all())."),shuffle:doc("shuffle",function(e){typecheck("shuffle",e,["pair","nil","array"]);var r=global_env.get("random");if(is_nil(e)){return _nil}if(Array.isArray(e)){return shuffle(e.slice(),r)}var t=global_env.get("list->array")(e);t=shuffle(t,r);return global_env.get("array->list")(t)},"(shuffle obj)\n\n Order items in vector or list in random order."),begin:doc(new Macro("begin",function(e,r){var n=_objectSpread(_objectSpread({},r),{},{env:this});var i=global_env.get("list->array")(e);var o;return function r(){if(i.length){var e=i.shift();var t=_evaluate(e,n);return unpromise(t,function(e){o=e;return r()})}else{return o}}()}),"(begin . args)\n\n Macro that runs a list of expressions in order and returns the value\n of the last one. It can be used in places where you can only have a\n single expression, like (if)."),ignore:new Macro("ignore",function(e,r){var t=_objectSpread(_objectSpread({},r),{},{env:this,dynamic_env:this});_evaluate(new Pair(new LSymbol("begin"),e),t)},"(ignore . body)\n\n Macro that will evaluate the expression and swallow any promises that may\n be created. It will discard any value that may be returned by the last body\n expression. The code should have side effects and/or when it's promise\n it should resolve to undefined."),"call/cc":doc(Macro.defmacro("call/cc",function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var t=_objectSpread({env:this},r);return unpromise(_evaluate(e.car,t),function(e){if(is_function(e)){return e(new Continuation(null))}})}),"(call/cc proc)\n\n Call-with-current-continuation.\n\n NOT SUPPORTED BY LIPS RIGHT NOW"),parameterize:doc(new Macro("parameterize",function(r,e){var i=e.dynamic_env;var o=i.inherit("parameterize").new_frame(null,{});var a=_objectSpread(_objectSpread({},e),{},{env:this});var u=r.car;if(!is_pair(u)){var t=type(u);throw new Error("Invalid syntax for parameterize expecting pair got ".concat(t))}function s(){var e=new Pair(new LSymbol("begin"),r.cdr);return _evaluate(e,_objectSpread(_objectSpread({},a),{},{dynamic_env:o}))}return function t(){var e=u.car;var n=e.car.valueOf();return unpromise(_evaluate(e.cdr.car,a),function(e){var r=i.get(n,{throwError:false});if(!is_parameter(r)){throw new Error("Unknown parameter ".concat(n))}o.set(n,r.inherit(e));if(!is_null(u.cdr)){u=u.cdr;return t()}else{return s()}})}()}),"(parameterize ((name value) ...)\n\n Macro that change the dynamic variable created by make-parameter."),"make-parameter":doc(new Macro("make-parameter",function(e,r){r.dynamic_env;var t=_evaluate(e.car,r);var n;if(is_pair(e.cdr.car)){n=_evaluate(e.cdr.car,r)}return new Parameter(t,n)}),"(make-parameter init converter)\n\n Function creates new dynamic variable that can be custimized with parameterize\n macro. The value should be assigned to a variable e.g.:\n\n (define radix (make-parameter 10))\n\n The result value is a procedure that return the value of dynamic variable."),"define-syntax-parameter":doc(new Macro("define-syntax-parameter",function(e,r){var t=e.car;var n=this;if(!(t instanceof LSymbol)){throw new Error("define-syntax-parameter: invalid syntax expecting symbol got ".concat(type(t)))}var i=_evaluate(e.cdr.car,_objectSpread({env:n},r));typecheck("define-syntax-parameter",i,"syntax",2);i.__name__=t.valueOf();if(i.__name__ instanceof LString){i.__name__=i.__name__.valueOf()}var o;if(is_pair(e.cdr.cdr)&&LString.isString(e.cdr.cdr.car)){o=e.cdr.cdr.car.valueOf()}n.set(e.car,new SyntaxParameter(i),o,true)}),"(define-syntax-parameter name syntax [__doc__])\n\n Binds to the transformer obtained by evaluating .\n The transformer provides the default expansion for the syntax parameter,\n and in the absence of syntax-parameterize, is functionally equivalent to\n define-syntax."),"syntax-parameterize":doc(new Macro("syntax-parameterize",function(e,r){var t=global_env.get("list->array")(e.car);var n=this.inherit("syntax-parameterize");while(t.length){var i=t.shift();if(!(is_pair(i)||i.car instanceof LSymbol)){var o="invalid syntax for syntax-parameterize: ".concat(repr(e,true));throw new Error("syntax-parameterize: ".concat(o))}var a=_evaluate(i.cdr.car,_objectSpread(_objectSpread({},r),{},{env:this}));var u=i.car;typecheck("syntax-parameterize",a,["syntax"]);typecheck("syntax-parameterize",u,"symbol");a.__name__=u.valueOf();if(a.__name__ instanceof LString){a.__name__=a.__name__.valueOf()}var s=new SyntaxParameter(a);if(u.is_gensym()){var c=u.literal();var l=this.get(c,{throwError:false});if(l instanceof SyntaxParameter){n.set(c,s)}}n.set(u,s)}var f=new Pair(new LSymbol("begin"),e.cdr);return _evaluate(f,_objectSpread(_objectSpread({},r),{},{env:n}))}),"(syntax-parameterize (bindings) body)\n\n Macro work similar to let-syntax but the the bindnds will be exposed to the user.\n With syntax-parameterize you can define anaphoric macros."),define:doc(Macro.defmacro("define",function(t,e){var n=this;if(is_pair(t.car)&&t.car.car instanceof LSymbol){var r=new Pair(new LSymbol("define"),new Pair(t.car.car,new Pair(new Pair(new LSymbol("lambda"),new Pair(t.car.cdr,t.cdr)))));return r}else if(e.macro_expand){return}e.dynamic_env=this;e.env=n;var i=t.cdr.car;var o;if(is_pair(i)){i=_evaluate(i,e);o=true}else if(i instanceof LSymbol){i=n.get(i)}typecheck("define",t.car,"symbol");return unpromise(i,function(e){if(n.__name__===Syntax.__merge_env__){n=n.__parent__}if(o&&(is_function(e)&&is_lambda(e)||e instanceof Syntax||is_parameter(e))){e.__name__=t.car.valueOf();if(e.__name__ instanceof LString){e.__name__=e.__name__.valueOf()}}var r;if(is_pair(t.cdr.cdr)&&LString.isString(t.cdr.cdr.car)){r=t.cdr.cdr.car.valueOf()}n.set(t.car,e,r,true)})}),'(define name expression)\n (define name expression "doc string")\n (define (function-name . args) . body)\n\n Macro for defining values. It can be used to define variables,\n or functions. If the first argument is list it will create a function\n with name being first element of the list. This form expands to\n `(define function-name (lambda args body))`'),"set-obj!":doc("set-obj!",function(e,r,t){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;var i=_typeof$1(e);if(is_null(e)||i!=="object"&&i!=="function"){var o=typeErrorMessage("set-obj!",type(e),["object","function"]);throw new Error(o)}typecheck("set-obj!",r,["string","symbol","number"]);e=unbind(e);r=r.valueOf();if(arguments.length===2){delete e[r]}else if(is_prototype(e)&&is_function(t)){e[r]=unbind(t);e[r][__prototype__]=true}else if(is_function(t)||is_native(t)||is_nil(t)){e[r]=t}else{e[r]=t&&!is_prototype(t)?t.valueOf():t}if(props){var a=e[r];Object.defineProperty(e,r,_objectSpread(_objectSpread({},n),{},{value:a}))}},"(set-obj! obj key value)\n (set-obj! obj key value props)\n\n Function set a property of a JavaScript object. props should be a vector of pairs,\n passed to Object.defineProperty."),"null-environment":doc("null-environment",function(){return global_env.inherit("null")},"(null-environment)\n\n Returns a clean environment with only the standard library."),values:doc("values",function e(){for(var r=arguments.length,t=new Array(r),n=0;n1&&arguments[1]!==undefined?arguments[1]:{},m=e.use_dynamic,v=e.error;var g=this;var b;if(is_pair(h.cdr)&&LString.isString(h.cdr.car)&&!is_nil(h.cdr.cdr)){b=h.cdr.car.valueOf()}function P(){var e=is_context(this)?this:{dynamic_env:g},t=e.dynamic_env;var n=g.inherit("lambda");t=t.inherit("lambda");if(this&&!is_context(this)){if(this&&!this.__instance__){Object.defineProperty(this,"__instance__",{enumerable:false,get:function e(){return true},set:function e(){},configurable:false})}n.set("this",this)}for(var r=arguments.length,i=new Array(r),o=0;o> SYNTAX");log(e);log(v);var n=P.inherit("syntax");var i=n;var o=this;if(o.__name__===Syntax.__merge_env__){var a=Object.getOwnPropertySymbols(o.__env__);a.forEach(function(e){o.__parent__.set(e,o.__env__[e])});o=o.__parent__}var u={env:n,dynamic_env:i,use_dynamic:g,error:b};var s,c,l;if(v.car instanceof LSymbol){s=v.car;l=w(v.cdr.car);c=v.cdr.cdr}else{s="...";l=w(v.car);c=v.cdr}try{while(!is_nil(c)){var f=c.car.car;var _=c.car.cdr.car;log("[[[ RULE");log(f);var p=extract_patterns(f,e,l,s,{expansion:this,define:P});if(p){if(is_debug()){console.log(JSON.stringify(symbolize(p),true,2));console.log("PATTERN: "+f.toString(true));console.log("MACRO: "+e.toString(true))}var d=[];var y=transform_syntax({bindings:p,expr:_,symbols:l,scope:n,lex_scope:o,names:d,ellipsis:s});log("OUPUT>>> ",y);if(y){_=y}var h=o.merge(n,Syntax.__merge_env__);if(t){return{expr:_,scope:h}}var m=_evaluate(_,_objectSpread(_objectSpread({},u),{},{env:h}));return clear_gensyms(m,d)}c=c.cdr}}catch(e){e.message+="\nin macro:\n ".concat(v.toString(true));throw e}throw new Error("syntax-rules: no matching syntax in macro ".concat(e.toString(true)))},P);t.__code__=v;return t},"(syntax-rules () (pattern expression) ...)\n\n Base of hygienic macros, it will return a new syntax expander\n that works like Lisp macros."),quote:doc(new Macro("quote",function(e){return quote(e.car)}),"(quote expression) or 'expression\n\n Macro that returns a single LIPS expression as data (it won't evaluate the\n argument). It will return a list if put in front of LIPS code.\n And if put in front of a symbol it will return the symbol itself, not the value\n bound to that name."),"unquote-splicing":doc("unquote-splicing",function(){throw new Error("You can't call `unquote-splicing` outside of quasiquote")},"(unquote-splicing code) or ,@code\n\n Special form used in the quasiquote macro. It evaluates the expression inside and\n splices the list into quasiquote's result. If it is not the last element of the\n expression, the computed value must be a pair."),unquote:doc("unquote",function(){throw new Error("You can't call `unquote` outside of quasiquote")},"(unquote code) or ,code\n\n Special form used in the quasiquote macro. It evaluates the expression inside and\n substitutes the value into quasiquote's result."),quasiquote:Macro.defmacro("quasiquote",function(e,r){var u=r.use_dynamic,s=r.error;var c=this;var l=c;function o(e){return is_pair(e)||is_plain_object(e)||Array.isArray(e)}function f(e,r){var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:o;if(is_pair(e)){var n=e.car;var i=e.cdr;if(t(n)){n=r(n)}if(t(i)){i=r(i)}if(is_promise(n)||is_promise(i)){return promise_all([n,i]).then(function(e){var r=_slicedToArray(e,2),t=r[0],n=r[1];return new Pair(t,n)})}else{return new Pair(n,i)}}return e}function a(e,r){if(is_pair(e)){if(!is_nil(r)){e.append(r)}}else{e=new Pair(e,r)}return e}function t(e){return!!e.filter(function(e){return is_pair(e)&&LSymbol.is(e.car,/^(unquote|unquote-splicing)$/)}).length}function _(e,n,i){return e.reduce(function(e,r){if(!is_pair(r)){e.push(r);return e}if(LSymbol.is(r.car,"unquote-splicing")){var t;if(n+11){var r="You can't splice multiple atoms inside list";throw new Error(r)}if(!(is_pair(i.cdr)&&is_nil(t[0]))){return t[0]}}t=t.map(function(e){if(y.has(e)){return e.clone()}else{y.add(e);return e}});var n=h(i.cdr,0,1);if(is_nil(n)&&is_nil(t[0])){return undefined}return unpromise(n,function(e){if(is_nil(t[0])){return e}if(t.length===1){return a(t[0],e)}var r=t.reduce(function(e,r){return a(e,r)});return a(r,e)})})}(i.car.cdr)}var y=new Set;function h(e,r,t){if(is_pair(e)){if(is_pair(e.car)){if(LSymbol.is(e.car.car,"unquote-splicing")){return d(e,r+1,t)}if(LSymbol.is(e.car.car,"unquote")){if(r+2===t&&is_pair(e.car.cdr)&&is_pair(e.car.cdr.car)&&LSymbol.is(e.car.cdr.car.car,"unquote-splicing")){var n=e.car.cdr;return new Pair(new Pair(new LSymbol("unquote"),d(n,r+2,t)),_nil)}else if(is_pair(e.car.cdr)&&!is_nil(e.car.cdr.cdr)){if(is_pair(e.car.cdr.car)){var i=[];return function r(t){if(is_nil(t)){return Pair.fromArray(i)}return unpromise(_evaluate(t.car,{env:c,dynamic_env:l,use_dynamic:u,error:s}),function(e){i.push(e);return r(t.cdr)})}(e.car.cdr)}else{return e.car.cdr}}}}if(LSymbol.is(e.car,"quasiquote")){var o=h(e.cdr,r,t+1);return new Pair(e.car,o)}if(LSymbol.is(e.car,"quote")){return new Pair(e.car,h(e.cdr,r,t))}if(LSymbol.is(e.car,"unquote")){r++;if(rt){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(is_pair(e.cdr)){if(!is_nil(e.cdr.cdr)){if(is_pair(e.cdr.car)){var a=[];return function r(t){if(is_nil(t)){return Pair.fromArray(a)}return unpromise(_evaluate(t.car,{env:c,dynamic_env:l,use_dynamic:u,error:s}),function(e){a.push(e);return r(t.cdr)})}(e.cdr)}else{return e.cdr}}else{return _evaluate(e.cdr.car,{env:c,dynamic_env:l,error:s})}}else{return e.cdr}}return f(e,function(e){return h(e,r,t)})}else if(is_plain_object(e)){return p(e,r,t)}else if(e instanceof Array){return _(e,r,t)}return e}function n(e){if(is_pair(e)){delete e[__data__];if(!e.have_cycles("car")){n(e.car)}if(!e.have_cycles("cdr")){n(e.cdr)}}}if(is_plain_object(e.car)&&!t(Object.values(e.car))){return quote(e.car)}if(Array.isArray(e.car)&&!t(e.car)){return quote(e.car)}if(is_pair(e.car)&&!e.car.find("unquote")&&!e.car.find("unquote-splicing")&&!e.car.find("quasiquote")){return quote(e.car)}var i=h(e.car,0,1);return unpromise(i,function(e){n(e);return quote(e)})},"(quasiquote list)\n\n Similar macro to `quote` but inside it you can use special expressions (unquote\n x) abbreviated to ,x that will evaluate x and insert its value verbatim or\n (unquote-splicing x) abbreviated to ,@x that will evaluate x and splice the value\n into the result. Best used with macros but it can be used outside."),clone:doc("clone",function e(r){typecheck("clone",r,"pair");return r.clone()},"(clone list)\n\n Function that returns a clone of the list, that does not share any pairs with the\n original, so the clone can be safely mutated without affecting the original."),append:doc("append",function e(){var r;for(var t=arguments.length,n=new Array(t),i=0;iarray")(r).reverse();return global_env.get("array->list")(t)}else if(Array.isArray(r)){return r.reverse()}else{throw new Error(typeErrorMessage("reverse",type(r),"array or pair"))}},"(reverse list)\n\n Function that reverses the list or array. If value is not a list\n or array it will error."),nth:doc("nth",function e(r,t){typecheck("nth",r,"number");typecheck("nth",t,["array","pair"]);if(is_pair(t)){var n=t;var i=0;while(iarray")(t).join(r)},"(join separator list)\n\n Function that returns a string by joining elements of the list using separator."),split:doc("split",function e(r,t){typecheck("split",r,["regex","string"]);typecheck("split",t,"string");return global_env.get("array->list")(t.split(r))},"(split separator string)\n\n Function that creates a list by splitting string by separator which can\n be a string or regular expression."),replace:doc("replace",function e(r,t,n){typecheck("replace",r,["regex","string"]);typecheck("replace",t,["string","function"]);typecheck("replace",n,"string");if(is_function(t)){var i=[];n.replace(r,function(){i.push(t.apply(void 0,arguments))});return unpromise(i,function(e){return n.replace(r,function(){return e.shift()})})}return n.replace(r,t)},"(replace pattern replacement string)\n\n Function that changes pattern to replacement inside string. Pattern can be a\n string or regex and replacement can be function or string. See Javascript\n String.replace()."),match:doc("match",function e(r,t){typecheck("match",r,["regex","string"]);typecheck("match",t,"string");var n=t.match(r);return n?global_env.get("array->list")(n):false},"(match pattern string)\n\n Function that returns a match object from JavaScript as a list or #f if\n no match."),search:doc("search",function e(r,t){typecheck("search",r,["regex","string"]);typecheck("search",t,"string");return t.search(r)},"(search pattern string)\n\n Function that returns the first found index of the pattern inside a string."),repr:doc("repr",function e(r,t){return toString(r,t)},"(repr obj)\n\n Function that returns a LIPS code representation of the object as a string."),"escape-regex":doc("escape-regex",function(e){typecheck("escape-regex",e,"string");return escape_regex(e.valueOf())},"(escape-regex string)\n\n Function that returns a new string where all special operators used in regex,\n are escaped with backslashes so they can be used in the RegExp constructor\n to match a literal string."),env:doc("env",function e(e){e=e||this.env;var r=Object.keys(e.__env__).map(LSymbol);var t;if(r.length){t=Pair.fromArray(r)}else{t=_nil}if(e.__parent__ instanceof Environment){return global_env.get("env").call(this,e.__parent__).append(t)}return t},"(env)\n (env obj)\n\n Function that returns a list of names (functions, macros and variables)\n that are bound in the current environment or one of its parents."),new:doc("new",function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n2&&arguments[2]!==undefined?arguments[2]:specials.LITERAL;typecheck("set-special!",e,"string",1);typecheck("set-special!",r,"symbol",2);specials.append(e.valueOf(),r,t)},'(set-special! symbol name [type])\n\n Add a special symbol to the list of transforming operators by the parser.\n e.g.: `(add-special! "#" \'x)` will allow to use `#(1 2 3)` and it will be\n transformed into (x (1 2 3)) so you can write x macro that will process\n the list. 3rd argument is optional, and it can be one of two values:\n lips.specials.LITERAL, which is the default behavior, or\n lips.specials.SPLICE which causes the value to be unpacked into the expression.\n This can be used for e.g. to make `#(1 2 3)` into (x 1 2 3) that is needed\n by # that defines vectors.'),get:get,".":get,unbind:doc(unbind,"(unbind fn)\n\n Function that removes the weak 'this' binding from a function so you\n can get properties from the actual function object."),type:doc(type,"(type object)\n\n Function that returns the type of an object as string."),debugger:doc("debugger",function(){debugger},'(debugger)\n\n Function that triggers the JavaScript debugger (e.g. the browser devtools)\n using the "debugger;" statement. If a debugger is not running this\n function does nothing.'),in:doc("in",function(e,r){if(e instanceof LSymbol||e instanceof LString||e instanceof LNumber){e=e.valueOf()}return e in unbox(r)},'(in key value)\n\n Function that uses the Javascript "in" operator to check if key is\n a valid property in the value.'),"instance?":doc("instance?",function(e){return is_instance(e)},"(instance? obj)\n\n Checks if object is an instance, created with a new operator"),instanceof:doc("instanceof",function(e,r){return r instanceof unbind(e)},"(instanceof type obj)\n\n Predicate that tests if the obj is an instance of type."),"prototype?":doc("prototype?",is_prototype,"(prototype? obj)\n\n Predicate that tests if value is a valid JavaScript prototype,\n i.e. calling (new) with it will not throw ' is not a constructor'."),"macro?":doc("macro?",function(e){return e instanceof Macro},"(macro? expression)\n\n Predicate that tests if value is a macro."),"continuation?":doc("continuation?",is_continuation,"(continuation? expression)\n\n Predicate that tests if value is a callable continuation."),"function?":doc("function?",is_function,"(function? expression)\n\n Predicate that tests if value is a callable function."),"real?":doc("real?",function(e){if(type(e)!=="number"){return false}if(e instanceof LNumber){return e.isFloat()}return LNumber.isFloat(e)},"(real? number)\n\n Predicate that tests if value is a real number (not complex)."),"number?":doc("number?",function(e){return Number.isNaN(e)||LNumber.isNumber(e)},"(number? expression)\n\n Predicate that tests if value is a number or NaN value."),"string?":doc("string?",function(e){return LString.isString(e)},"(string? expression)\n\n Predicate that tests if value is a string."),"pair?":doc("pair?",is_pair,"(pair? expression)\n\n Predicate that tests if value is a pair or list structure."),"regex?":doc("regex?",function(e){return e instanceof RegExp},"(regex? expression)\n\n Predicate that tests if value is a regular expression."),"null?":doc("null?",function(e){return is_null(e)},"(null? expression)\n\n Predicate that tests if value is null-ish (i.e. undefined, nil, or\n Javascript null)."),"boolean?":doc("boolean?",function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Predicate that tests if value is a boolean (#t or #f)."),"symbol?":doc("symbol?",function(e){return e instanceof LSymbol},"(symbol? expression)\n\n Predicate that tests if value is a LIPS symbol."),"array?":doc("array?",function(e){return e instanceof Array},"(array? expression)\n\n Predicate that tests if value is an array."),"object?":doc("object?",function(e){return!is_nil(e)&&e!==null&&!(e instanceof LCharacter)&&!(e instanceof RegExp)&&!(e instanceof LString)&&!is_pair(e)&&!(e instanceof LNumber)&&_typeof$1(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Predicate that tests if value is an plain object (not another LIPS type)."),flatten:doc("flatten",function e(r){typecheck("flatten",r,"pair");return r.flatten()},"(flatten list)\n\n Returns a shallow list from tree structure (pairs)."),"array->list":doc("array->list",function(e){typecheck("array->list",e,"array");return Pair.fromArray(e)},"(array->list array)\n\n Function that converts a JavaScript array to a LIPS cons list."),"tree->array":doc("tree->array",to_array("tree->array",true),"(tree->array list)\n\n Function that converts a LIPS cons tree structure into a JavaScript array."),"list->array":doc("list->array",to_array("list->array"),"(list->array list)\n\n Function that converts a LIPS list into a JavaScript array."),apply:doc("apply",function e(r){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;iarray").call(this,o));return r.apply(this,prepare_fn_args(r,n))},"(apply fn list)\n\n Function that calls fn with the list of arguments."),length:doc("length",function e(r){if(!r||is_nil(r)){return 0}if(is_pair(r)){return r.length()}if("length"in r){return r.length}},'(length expression)\n\n Function that returns the length of the object. The object can be a LIPS\n list or any object that has a "length" property. Returns undefined if the\n length could not be found.'),"string->number":doc("string->number",function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;typecheck("string->number",e,"string",1);typecheck("string->number",r,"number",2);e=e.valueOf();r=r.valueOf();if(e.match(rational_bare_re)||e.match(rational_re)){return parse_rational(e,r)}else if(e.match(complex_bare_re)||e.match(complex_re)){return parse_complex(e,r)}else{var t=r===10&&!e.match(/e/i)||r===16;if(e.match(int_bare_re)&&t||e.match(int_re)){return parse_integer(e,r)}if(e.match(float_re)){return parse_float(e)}}return false},"(string->number number [radix])\n\n Function that parses a string into a number."),try:doc(new Macro("try",function(t,e){var f=this;var _=e.use_dynamic;e.error;return new Promise(function(r,u){var s,n;if(LSymbol.is(t.cdr.car.car,"catch")){s=t.cdr.car;if(is_pair(t.cdr.cdr)&&LSymbol.is(t.cdr.cdr.car.car,"finally")){n=t.cdr.cdr.car}}else if(LSymbol.is(t.cdr.car.car,"finally")){n=t.cdr.car}if(!(n||s)){throw new Error("try: invalid syntax")}function c(e){r(e);throw new IgnoreException("[CATCH]")}var l=function e(r,t){t(r)};if(n){l=function e(r,t){l=u;i.error=function(e){throw e};unpromise(_evaluate(new Pair(new LSymbol("begin"),n.cdr),i),function(){t(r)})}}var i={env:f,use_dynamic:_,dynamic_env:f,error:function e(r){if(r instanceof IgnoreException){throw r}if(s){var t=f.inherit("try");var n=s.cdr.car.car;if(!(n instanceof LSymbol)){throw new Error("try: invalid syntax: catch require variable name")}t.set(n,r);var i;var o={env:t,use_dynamic:_,dynamic_env:f,error:function e(r){i=true;u(r);throw new IgnoreException("[CATCH]")}};var a=_evaluate(new Pair(new LSymbol("begin"),s.cdr.cdr),o);unpromise(a,function e(r){if(!i){l(r,c)}})}else{l(undefined,function(){u(r)})}}};var e=_evaluate(t.car,i);unpromise(e,function(e){l(e,r)},i.error)})}),"(try expr (catch (e) code))\n (try expr (catch (e) code) (finally code))\n (try expr (finally code))\n\n Macro that executes expr and catches any exceptions thrown. If catch is provided\n it's executed when an error is thrown. If finally is provided it's always\n executed at the end."),raise:doc("raise",function(e){throw e},"(raise obj)\n\n Throws the object verbatim (no wrapping an a new Error)."),throw:doc("throw",function(e){throw new Error(e)},"(throw string)\n\n Throws a new exception."),find:doc("find",function r(t,n){typecheck("find",t,["regex","function"]);typecheck("find",n,["pair","nil"]);if(is_null(n)){return _nil}var e=matcher("find",t);return unpromise(e(n.car),function(e){if(e&&!is_nil(e)){return n.car}return r(t,n.cdr)})},"(find fn list)\n (find regex list)\n\n Higher-order function that finds the first value for which fn return true.\n If called with a regex it will create a matcher function."),"for-each":doc("for-each",function(e){var r;typecheck("for-each",e,"function");for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i1?r-1:0),o=1;o3?n-3:0),o=3;o3?i-3:0),a=3;aarray")(t);var o=[];var a=matcher("filter",r);return function r(t){function e(e){if(e&&!is_nil(e)){o.push(n)}return r(++t)}if(t===i.length){return Pair.fromArray(o)}var n=i[t];return unpromise(a(n),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher-order function that calls `fn` for each element of the list\n and return a new list for only those elements for which fn returns\n a truthy value. If called with a regex it will create a matcher function."),compose:doc(compose,"(compose . fns)\n\n Higher-order function that creates a new function that applies all functions\n from right to left and returns the last value. Reverse of pipe.\n e.g.:\n ((compose (curry + 2) (curry * 3)) 10) --\x3e (+ 2 (* 3 10)) --\x3e 32"),pipe:doc(pipe,"(pipe . fns)\n\n Higher-order function that creates a new function that applies all functions\n from left to right and returns the last value. Reverse of compose.\n e.g.:\n ((pipe (curry + 2) (curry * 3)) 10) --\x3e (* 3 (+ 2 10)) --\x3e 36"),curry:doc(curry,"(curry fn . args)\n\n Higher-order function that creates a curried version of the function.\n The result function will have partially applied arguments and it\n will keep returning one-argument functions until all arguments are provided,\n then it calls the original function with the accumulated arguments.\n\n e.g.:\n (define (add a b c d) (+ a b c d))\n (define add1 (curry add 1))\n (define add12 (add 2))\n (display (add12 3 4))"),gcd:doc("gcd",function e(){for(var r=arguments.length,t=new Array(r),n=0;nu?o%=u:u%=o}o=abs(s*t[a])/(o+u)}return LNumber(o)},"(lcm n1 n2 ...)\n\n Function that returns the least common multiple of the arguments."),"odd?":doc("odd?",single_math_op(function(e){return LNumber(e).isOdd()}),"(odd? number)\n\n Checks if number is odd."),"even?":doc("even?",single_math_op(function(e){return LNumber(e).isEven()}),"(even? number)\n\n Checks if number is even."),"*":doc("*",reduce_math_op(function(e,r){return LNumber(e).mul(r)},LNumber(1)),"(* . numbers)\n\n Multiplies all numbers passed as arguments. If single value is passed\n it will return that value."),"+":doc("+",reduce_math_op(function(e,r){return LNumber(e).add(r)},LNumber(0)),"(+ . numbers)\n\n Sums all numbers passed as arguments. If single value is passed it will\n return that value."),"-":doc("-",function(){for(var e=arguments.length,r=new Array(e),t=0;t":doc(">",function(){for(var e=arguments.length,r=new Array(e),t=0;t",r,["bigint","float","rational"]);return seq_compare(function(e,r){return LNumber(e).cmp(r)===1},r)},"(> x1 x2 x3 ...)\n\n Function that compares its numerical arguments and checks if they are\n monotonically decreasing, i.e. x1 > x2 and x2 > x3 and so on."),"<":doc("<",function(){for(var e=arguments.length,r=new Array(e),t=0;t=":doc(">=",function(){for(var e=arguments.length,r=new Array(e),t=0;t=",r,["bigint","float","rational"]);return seq_compare(function(e,r){return[0,1].includes(LNumber(e).cmp(r))},r)},"(>= x1 x2 ...)\n\n Function that compares its numerical arguments and checks if they are\n monotonically nonincreasing, i.e. x1 >= x2 and x2 >= x3 and so on."),"eq?":doc("eq?",equal,"(eq? a b)\n\n Function that compares two values if they are identical."),or:doc(new Macro("or",function(e,r){var i=r.use_dynamic,o=r.error;var a=global_env.get("list->array")(e);var u=this;var s=u;if(!a.length){return false}var c;return function r(){function e(e){c=e;if(!is_false(c)){return c}else{return r()}}if(!a.length){if(!is_false(c)){return c}else{return false}}else{var t=a.shift();var n=_evaluate(t,{env:u,dynamic_env:s,use_dynamic:i,error:o});return unpromise(n,e)}}()}),"(or . expressions)\n\n Macro that executes the values one by one and returns the first that is\n a truthy value. If there are no expressions that evaluate to true it\n returns false."),and:doc(new Macro("and",function(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},t=r.use_dynamic,n=r.error;var i=global_env.get("list->array")(e);var o=this;var a=o;if(!i.length){return true}var u;var s={env:o,dynamic_env:a,use_dynamic:t,error:n};return function r(){function e(e){u=e;if(is_false(u)){return u}else{return r()}}if(!i.length){if(!is_false(u)){return u}else{return false}}else{var t=i.shift();return unpromise(_evaluate(t,s),e)}}()}),"(and . expressions)\n\n Macro that evaluates each expression in sequence and if any value returns false\n it will stop and return false. If each value returns true it will return the\n last value. If it's called without arguments it will return true."),"|":doc("|",function(e,r){return LNumber(e).or(r)},"(| a b)\n\n Function that calculates the bitwise or operation."),"&":doc("&",function(e,r){return LNumber(e).and(r)},"(& a b)\n\n Function that calculates the bitwise and operation."),"~":doc("~",function(e){return LNumber(e).neg()},"(~ number)\n\n Function that calculates the bitwise inverse (flip all the bits)."),">>":doc(">>",function(e,r){return LNumber(e).shr(r)},"(>> a b)\n\n Function that right shifts the value a by value b bits."),"<<":doc("<<",function(e,r){return LNumber(e).shl(r)},"(<< a b)\n\n Function that left shifts the value a by value b bits."),not:doc("not",function e(r){if(is_null(r)){return true}return!r},"(not object)\n\n Function that returns the Boolean negation of its argument.")},undefined,"global");var user_env=global_env.inherit("user-env");function set_interaction_env(e,r){e.constant("**internal-env**",r);e.doc("**internal-env**","**internal-env**\n\n Constant used to hide stdin, stdout and stderr so they don't interfere\n with variables with the same name. Constants are an internal type\n of variable that can't be redefined, defining a variable with the same name\n will throw an error.");global_env.set("**interaction-environment**",e)}set_interaction_env(user_env,internal_env);global_env.doc("**interaction-environment**","**interaction-environment**\n\n Internal dynamic, global variable used to find interpreter environment.\n It's used so the read and write functions can locate **internal-env**\n that contains the references to stdin, stdout and stderr.");function set_fs(e){user_env.get("**internal-env**").set("fs",e)}(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(r){var t=e[r]?e[r]:r;global_env.set(t,doc(t,function(e){typecheck(t,e,"number");if(e instanceof LNumber){return e[r]()}},"(".concat(t," number)\n\n Function that calculates the ").concat(t," of a number.")))})})();function allPossibleCases(e){if(e.length===1){return e[0]}else{var r=[];var t=allPossibleCases(e.slice(1));for(var n=0;n3&&arguments[3]!==undefined?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(n!==null){i+=" (argument ".concat(n,")")}if(is_function(t)){return"Invalid type: got ".concat(r).concat(i)}if(t instanceof Array){if(t.length===1){var o=t[0].toLowerCase();t="a"+("aeiou".includes(o)?"n ":" ")+t[0]}else{t=new Intl.ListFormat("en",{style:"long",type:"disjunction"}).format(t)}}return"Expecting ".concat(t," got ").concat(r).concat(i)}function typecheck_number(e,r,t){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;typecheck(e,r,"number",n);var i=r.__type__;var o;if(is_pair(t)){t=t.to_array()}if(t instanceof Array){t=t.map(function(e){return e.valueOf()})}if(t instanceof Array){t=t.map(function(e){return e.valueOf().toLowerCase()});if(t.includes(i)){o=true}}else{t=t.valueOf().toLowerCase()}if(!o&&i!==t){throw new Error(typeErrorMessage(e,i,t,n))}}function typecheck_numbers(t,e,n){e.forEach(function(e,r){typecheck_number(t,e,n,r+1)})}function typecheck_args(t,e,n){e.forEach(function(e,r){typecheck(t,e,n,r+1)})}function typecheck_text_port(e,r,t){typecheck(e,r,t);if(r.__type__===binary_port){throw new Error(typeErrorMessage(e,"binary-port","textual-port"))}}function typecheck(e,r,t){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;e=e.valueOf();var i=type(r).toLowerCase();if(is_function(t)){if(!t(r)){throw new Error(typeErrorMessage(e,i,t,n))}return}var o=false;if(is_pair(t)){t=t.to_array()}if(t instanceof Array){t=t.map(function(e){return e.valueOf()})}if(t instanceof Array){t=t.map(function(e){return e.valueOf().toLowerCase()});if(t.includes(i)){o=true}}else{t=t.valueOf().toLowerCase()}if(!o&&i!==t){throw new Error(typeErrorMessage(e,i,t,n))}}function memoize(t){var n=new WeakMap;return function(e){var r=n.get(e);if(!r){r=t(e)}return r}}type=memoize(type);function type(e){var r=type_constants.get(e);if(r){return r}if(_typeof$1(e)==="object"){for(var t=0,n=Object.entries(type_mapping);t2&&arguments[2]!==undefined?arguments[2]:{},n=t.env,i=t.dynamic_env,o=t.use_dynamic;var a=n===null||n===void 0?void 0:n.new_frame(e,r);var u=i===null||i===void 0?void 0:i.new_frame(e,r);var s=new LambdaContext({env:a,use_dynamic:o,dynamic_env:u});return resolve_promises(e.apply(s,r))}function apply(n,e){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},i=r.env,o=r.dynamic_env,a=r.use_dynamic,t=r.error,u=t===void 0?function(){}:t;e=evaluate_args(e,{env:i,dynamic_env:o,error:u,use_dynamic:a});return unpromise(e,function(e){if(is_raw_lambda(n)){n=unbind(n)}e=prepare_fn_args(n,e);var r=e.slice();var t=call_function(n,r,{env:i,dynamic_env:o,use_dynamic:a});return unpromise(t,function(e){if(is_pair(e)){e.mark_cycles();return quote(e)}return box(e)},u)})}var _p_name__=new WeakMap;var Parameter=function(){function n(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;_classCallCheck(this,n);_defineProperty(this,"__value__",void 0);_defineProperty(this,"__fn__",void 0);_classPrivateFieldInitSpec(this,_p_name__,{writable:true,value:void 0});this.__value__=e;if(r){if(!is_function(r)){throw new Error("Section argument to Parameter need to be function "+"".concat(type(r)," given"))}this.__fn__=r}if(t){_classPrivateFieldSet(this,_p_name__,t)}}_createClass(n,[{key:"__name__",get:function e(){return _classPrivateFieldGet(this,_p_name__)},set:function e(r){_classPrivateFieldSet(this,_p_name__,r);if(this.__fn__){this.__fn__.__name__="fn-".concat(r)}}},{key:"invoke",value:function e(){if(is_function(this.__fn__)){return this.__fn__(this.__value__)}return this.__value__}},{key:"inherit",value:function e(r){return new n(r,this.__fn__,this.__name__)}}]);return n}();var LambdaContext=function(){function r(e){_classCallCheck(this,r);_defineProperty(this,"env",void 0);_defineProperty(this,"dynamic_env",void 0);_defineProperty(this,"use_dynamic",void 0);Object.assign(this,e)}_createClass(r,[{key:"__name__",get:function e(){return this.env.__name__}},{key:"__parent__",get:function e(){return this.env.__parent__}},{key:"get",value:function e(){var r;return(r=this.env).get.apply(r,arguments)}}]);return r}();function search_param(e,r){var t=e.get(r.__name__,{throwError:false});if(is_parameter(t)&&t!==r){return t}var n=user_env.get("**interaction-environment**");while(true){var i=e.get("parent.frame",{throwError:false});e=i(0);if(e===n){break}t=e.get(r.__name__,{throwError:false});if(is_parameter(t)&&t!==r){return t}}return r}var Continuation=function(){function r(e){_classCallCheck(this,r);_defineProperty(this,"__value__",void 0);this.__value__=e}_createClass(r,[{key:"invoke",value:function e(){if(this.__value__===null){throw new Error("Continuations are not implemented yet")}}}]);return r}();function _evaluate(u){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},s=e.env,c=e.dynamic_env,l=e.use_dynamic,r=e.error,f=r===void 0?noop:r,t=_objectWithoutProperties(e,_excluded6);return function(e){try{if(!is_env(c)){c=s===true?user_env:s||user_env}if(l){s=c}else if(s===true){s=user_env}else{s=s||global_env}var r={env:s,dynamic_env:c,use_dynamic:l,error:f};var t;if(is_null(u)){return u}if(u instanceof LSymbol){return s.get(u)}if(!is_pair(u)){return u}var n=u.car;var e=u.cdr;if(is_pair(n)){t=resolve_promises(_evaluate(n,r));if(is_promise(t)){return t.then(function(e){if(!is_callable(e)){throw new Error(type(e)+" "+s.get("repr")(e)+" is not callable while evaluating "+u.toString())}return _evaluate(new Pair(e,u.cdr),r)})}else if(!is_callable(t)){throw new Error(type(t)+" "+s.get("repr")(t)+" is not callable while evaluating "+u.toString())}}if(n instanceof LSymbol){t=s.get(n)}else if(is_function(n)){t=n}var i;if(t instanceof Syntax){i=evaluate_syntax(t,u,r)}else if(t instanceof Macro){i=evaluate_macro(t,e,r)}else if(is_function(t)){i=apply(t,e,r)}else if(t instanceof SyntaxParameter){i=evaluate_syntax(t._syntax,u,r)}else if(is_parameter(t)){var o=search_param(c,t);if(is_null(u.cdr)){i=o.invoke()}else{return unpromise(_evaluate(u.cdr.car,r),function(e){o.__value__=e})}}else if(is_continuation(t)){i=t.invoke()}else if(is_pair(u)){t=n&&n.toString();throw new Error("".concat(type(n)," ").concat(t," is not a function"))}else{return u}var a=s.get(Symbol["for"]("__promise__"),{throwError:false});if(a===true&&is_promise(i)){i=i.then(function(e){if(is_pair(e)&&!t[__data__]){return _evaluate(e,r)}return e});return new QuotedPromise(i)}return i}catch(e){f&&f.call(s,e,u)}}(t)}var compile=exec_collect(function(e){return e});var exec=exec_collect(function(e,r){return r});function exec_with_stacktrace(e){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},t=r.env,n=r.dynamic_env,i=r.use_dynamic;return _evaluate(e,{env:t,dynamic_env:n,use_dynamic:i,error:function e(r,t){if(r&&r.message){if(r.message.match(/^Error:/)){var n=/^(Error:)\s*([^:]+:\s*)/;r.message=r.message.replace(n,"$1 $2")}if(t){if(!(r.__code__ instanceof Array)){r.__code__=[]}r.__code__.push(t.toString(true))}}if(!(r instanceof IgnoreException)){throw r}}})}function exec_collect(y){return function(){var r=_asyncToGenerator(function(f){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},_=e.env,p=e.dynamic_env,d=e.use_dynamic;return _regeneratorRuntime.mark(function e(){var t,n,i,o,a,u,s,c,l;return _regeneratorRuntime.wrap(function e(r){while(1)switch(r.prev=r.next){case 0:if(!is_env(p)){p=_===true?user_env:_||user_env}if(_===true){_=user_env}else{_=_||user_env}t=[];if(!is_pair(f)){r.next=8;break}r.next=6;return exec_with_stacktrace(f,{env:_,dynamic_env:p,use_dynamic:d});case 6:r.t0=r.sent;return r.abrupt("return",[r.t0]);case 8:n=Array.isArray(f)?f:_parse(f);i=false;o=false;r.prev=11;u=_asyncIterator(n);case 13:r.next=15;return u.next();case 15:if(!(i=!(s=r.sent).done)){r.next=31;break}c=s.value;r.next=19;return exec_with_stacktrace(c,{env:_,dynamic_env:p,use_dynamic:d});case 19:l=r.sent;r.t1=t;r.t2=y;r.t3=c;r.next=25;return l;case 25:r.t4=r.sent;r.t5=(0,r.t2)(r.t3,r.t4);r.t1.push.call(r.t1,r.t5);case 28:i=false;r.next=13;break;case 31:r.next=37;break;case 33:r.prev=33;r.t6=r["catch"](11);o=true;a=r.t6;case 37:r.prev=37;r.prev=38;if(!(i&&u["return"]!=null)){r.next=42;break}r.next=42;return u["return"]();case 42:r.prev=42;if(!o){r.next=45;break}throw a;case 45:return r.finish(42);case 46:return r.finish(37);case 47:return r.abrupt("return",t);case 48:case"end":return r.stop()}},e,null,[[11,33,37,47],[38,,42,46]])})()});function e(e){return r.apply(this,arguments)}return e}()}function balanced(e){var r={"[":"]","(":")"};var t;if(typeof e==="string"){t=tokenize(e)}else{t=e.map(function(e){return e&&e.token?e.token:e})}var n=Object.keys(r);var i=Object.values(r).concat(n);t=t.filter(function(e){return i.includes(e)});var o=new Stack;var a=_createForOfIteratorHelper(t),u;try{for(a.s();!(u=a.n()).done;){var s=u.value;if(n.includes(s)){o.push(s)}else if(!o.is_empty()){var c=o.top();var l=r[c];if(s===l){o.pop()}else{throw new Error("Syntax error: missing closing ".concat(l))}}else{throw new Error("Syntax error: not matched closing ".concat(s))}}}catch(e){a.e(e)}finally{a.f()}return o.is_empty()}function fworker(e){var r="("+e.toString()+")()";var t=window.URL||window.webkitURL;var n;try{n=new Blob([r],{type:"application/javascript"})}catch(e){var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;n=new i;n.append(r);n=n.getBlob()}return new root.Worker(t.createObjectURL(n))}function is_dev(){return lips.version.match(/^(\{\{VER\}\}|DEV)$/)}function get_current_script(){if(is_node()){return}var e;if(document.currentScript){e=document.currentScript}else{var r=document.querySelectorAll("script");if(!r.length){return}e=r[r.length-1]}var t=e.getAttribute("src");return t}var current_script=get_current_script();function bootstrap(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"";var r="dist/std.xcb";if(e===""){if(current_script){e=current_script.replace(/[^/]*$/,"std.xcb")}else if(is_dev()){e="https://cdn.jsdelivr.net/gh/jcubic/lips@devel/".concat(r)}else{e="https://cdn.jsdelivr.net/npm/@jcubic/lips@".concat(lips.version,"/").concat(r)}}var t=global_env.get("load");return t.call(user_env,e,global_env)}function Worker(e){this.url=e;var a=this.worker=fworker(function(){var a;var u;self.addEventListener("message",function(e){var t=e.data;var r=t.id;if(t.type!=="RPC"||r===null){return}function n(e){self.postMessage({id:r,type:"RPC",result:e})}function i(e){self.postMessage({id:r,type:"RPC",error:e})}if(t.method==="eval"){if(!u){i("Worker RPC: LIPS not initialized, call init first");return}u.then(function(){var e=t.params[0];var r=t.params[1];a.exec(e,{use_dynamic:r}).then(function(e){e=e.map(function(e){return e&&e.valueOf()});n(e)})["catch"](function(e){i(e)})})}else if(t.method==="init"){var o=t.params[0];if(typeof o!=="string"){i("Worker RPC: url is not a string")}else{importScripts("".concat(o,"/dist/lips.min.js"));a=new lips.Interpreter("worker");u=bootstrap(o);u.then(function(){n(true)})}}})});this.rpc=function(){var n=0;return function e(r,t){var o=++n;return new Promise(function(n,i){a.addEventListener("message",function e(r){var t=r.data;if(t&&t.type==="RPC"&&t.id===o){if(t.error){i(t.error)}else{n(t.result)}a.removeEventListener("message",e)}});a.postMessage({type:"RPC",method:r,id:o,params:t})})}}();this.rpc("init",[e])["catch"](function(e){console.error(e)});this.exec=function(e,r){var t=r.use_dynamic,n=t===void 0?false:t;return this.rpc("eval",[e,n])}}var serialization_map={pair:function e(r){var t=_slicedToArray(r,2),n=t[0],i=t[1];return Pair(n,i)},number:function e(r){if(LString.isString(r)){return LNumber([r,10])}return LNumber(r)},regex:function e(r){var t=_slicedToArray(r,2),n=t[0],i=t[1];return new RegExp(n,i)},nil:function e(){return _nil},symbol:function e(r){if(LString.isString(r)){return LSymbol(r)}else if(Array.isArray(r)){return LSymbol(Symbol["for"](r[0]))}},string:LString,character:LCharacter};var available_class=Object.keys(serialization_map);var class_map={};for(var _i6=0,_Object$entries3=Object.entries(available_class);_i6<_Object$entries3.length;_i6++){var _Object$entries3$_i=_slicedToArray(_Object$entries3[_i6],2),i=_Object$entries3$_i[0],cls=_Object$entries3$_i[1];class_map[cls]=+i}function mangle_name(e){return class_map[e]}function resolve_name(e){return available_class[e]}function serialize(e){return JSON.stringify(e,function(e,r){var t=this[e];if(t){if(t instanceof RegExp){return{"@":mangle_name("regex"),"#":[t.source,t.flags]}}var n=mangle_name(t.constructor.__class__);if(!is_undef(n)){return{"@":n,"#":t.serialize()}}}return r})}function unserialize(e){return JSON.parse(e,function(e,r){if(r&&_typeof$1(r)==="object"){if(!is_undef(r["@"])){var t=resolve_name(r["@"]);if(serialization_map[t]){return serialization_map[t](r["#"])}}}return r})}var cbor=function(){var e={pair:Pair,symbol:LSymbol,number:LNumber,string:LString,character:LCharacter,nil:_nil.constructor,regex:RegExp};function r(e,r){return{deserialize:r,Class:e}}var t=new Encoder;var o={};for(var n=0,i=Object.entries(serialization_map);n1){var n=r.reduce(function(e,r){return e+r.length},0);var i=new Uint8Array(n);var o=0;r.forEach(function(e){i.set(e,o);o+=e.length});return i}else if(r.length){return r[0]}}function encode_magic(){var e=1;var r=new TextEncoder("utf-8");return r.encode("LIPS".concat(e.toString().padStart(3," ")))}var MAGIC_LENGTH=7;function decode_magic(e){var r=new TextDecoder("utf-8");var t=r.decode(e.slice(0,MAGIC_LENGTH));var n=t.substring(0,4);if(n==="LIPS"){var i=t.match(/^(....).*([0-9]+)$/);if(i){return{type:i[1],version:Number(i[2])}}}return{type:"unknown"}}function serialize_bin(e){var r=encode_magic();var t=cbor.encode(e);return merge_uint8_array(r,pack_1(t,{magic:false}))}function unserialize_bin(e){var r=decode_magic(e),t=r.type,n=r.version;if(t==="LIPS"&&n===1){var i=unpack_1(e.slice(MAGIC_LENGTH),{magic:false});return cbor.decode(i)}else{throw new Error("Invalid file format ".concat(t))}}function execError(e){console.error(e.message||e);if(Array.isArray(e.code)){console.error(e.code.map(function(e,r){return"[".concat(r+1,"]: ").concat(e)}))}}function init(){var a=["text/x-lips","text/x-scheme"];var u;function s(e){var r;return(r=e.getAttribute("data-bootstrap"))!==null&&r!==void 0?r:e.getAttribute("bootstrap")}function c(t){return new Promise(function(r){var e=t.getAttribute("src");if(e){return fetch(e).then(function(e){return e.text()}).then(exec).then(r)["catch"](function(e){execError(e);r()})}else{return exec(t.innerHTML).then(r)["catch"](function(e){execError(e);r()})}})}function e(){return new Promise(function(i){var o=Array.from(document.querySelectorAll("script"));return function e(){var r=o.shift();if(!r){i()}else{var t=r.getAttribute("type");if(a.includes(t)){var n=s(r);if(!u&&typeof n==="string"){return bootstrap(n).then(function(){return c(r)}).then(e)}else{return c(r).then(e)}}else if(t&&t.match(/lips|lisp/)){console.warn("Expecting "+a.join(" or ")+" found "+t)}return e()}}()})}if(!window.document){return Promise.resolve()}else if(currentScript){var r=currentScript;var t=s(r);if(typeof t==="string"){return bootstrap(t).then(function(){u=true;return e()})}}return e()}var currentScript=typeof window!=="undefined"&&window.document&&document.currentScript;if(typeof window!=="undefined"){contentLoaded(window,init)}var banner=function(){var e=LString("Fri, 22 Mar 2024 16:45:56 +0000").valueOf();var r=e==="{{"+"DATE}}"?new Date:new Date(e);var t=function e(r){return r.toString().padStart(2,"0")};var n=r.getFullYear();var i=[n,t(r.getMonth()+1),t(r.getDate())].join("-");var o="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter DEV (".concat(i,") \nCopyright (c) 2018-").concat(n," Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables. You can also\nuse (help name) to display help for specific function or macro, (apropos name)\nto display list of matched names in environment and (dir object) to list\nproperties of an object.\n").replace(/^.*\n/,"");return o}();read_only(Ahead,"__class__","ahead");read_only(Pair,"__class__","pair");read_only(Nil,"__class__","nil");read_only(Pattern,"__class__","pattern");read_only(Formatter,"__class__","formatter");read_only(Macro,"__class__","macro");read_only(Syntax,"__class__","syntax");read_only(Syntax.Parameter,"__class__","syntax-parameter");read_only(Environment,"__class__","environment");read_only(InputPort,"__class__","input-port");read_only(OutputPort,"__class__","output-port");read_only(BufferedOutputPort,"__class__","output-port");read_only(OutputStringPort,"__class__","output-string-port");read_only(InputStringPort,"__class__","input-string-port");read_only(InputFilePort,"__class__","input-file-port");read_only(OutputFilePort,"__class__","output-file-port");read_only(LipsError,"__class__","lips-error");[LNumber,LComplex,LRational,LFloat,LBigInteger].forEach(function(e){read_only(e,"__class__","number")});read_only(LCharacter,"__class__","character");read_only(LSymbol,"__class__","symbol");read_only(LString,"__class__","string");read_only(QuotedPromise,"__class__","promise");read_only(Parameter,"__class__","parameter");var version="DEV";var date="Fri, 22 Mar 2024 16:45:56 +0000";var parse=compose(uniterate_async,_parse);var lips={version:version,banner:banner,date:date,exec:exec,parse:parse,tokenize:tokenize,evaluate:_evaluate,compile:compile,serialize:serialize,unserialize:unserialize,serialize_bin:serialize_bin,unserialize_bin:unserialize_bin,bootstrap:bootstrap,Environment:Environment,env:user_env,Worker:Worker,Interpreter:Interpreter,balanced_parenthesis:balanced,balancedParenthesis:balanced,balanced:balanced,Macro:Macro,Syntax:Syntax,Pair:Pair,Values:Values,QuotedPromise:QuotedPromise,Error:LipsError,quote:quote,InputPort:InputPort,OutputPort:OutputPort,BufferedOutputPort:BufferedOutputPort,InputFilePort:InputFilePort,OutputFilePort:OutputFilePort,InputStringPort:InputStringPort,OutputStringPort:OutputStringPort,InputByteVectorPort:InputByteVectorPort,OutputByteVectorPort:OutputByteVectorPort,InputBinaryFilePort:InputBinaryFilePort,OutputBinaryFilePort:OutputBinaryFilePort,set_fs:set_fs,Formatter:Formatter,Parser:Parser,Lexer:Lexer,specials:specials,repr:repr,nil:_nil,eof:eof,LSymbol:LSymbol,LNumber:LNumber,LFloat:LFloat,LComplex:LComplex,LRational:LRational,LBigInteger:LBigInteger,LCharacter:LCharacter,LString:LString,Parameter:Parameter,rationalize:rationalize};global_env.set("lips",lips);export{BufferedOutputPort,Environment,LipsError as Error,Formatter,InputBinaryFilePort,InputByteVectorPort,InputFilePort,InputPort,InputStringPort,Interpreter,LBigInteger,LCharacter,LComplex,LFloat,LNumber,LRational,LString,LSymbol,Lexer,Macro,OutputBinaryFilePort,OutputByteVectorPort,OutputFilePort,OutputPort,OutputStringPort,Pair,Parameter,Parser,QuotedPromise,Syntax,Values,Worker,is_directive as _is_directive,balanced,balanced as balancedParenthesis,balanced as balanced_parenthesis,banner,bootstrap,compile,date,user_env as env,eof,_evaluate as evaluate,exec,_nil as nil,parse,quote,rationalize,repr,serialize,serialize_bin,set_fs,specials,tokenize,unserialize,unserialize_bin,version}; \ No newline at end of file diff --git a/dist/lips.js b/dist/lips.js index 90d05d11..09b4b0c3 100644 --- a/dist/lips.js +++ b/dist/lips.js @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Fri, 22 Mar 2024 13:26:48 +0000 + * build: Fri, 22 Mar 2024 16:45:56 +0000 */ (function (global, factory) { @@ -4852,21 +4852,17 @@ // :: ref: https://github.com/biwascheme/biwascheme/blob/master/src/system/parser.js // ---------------------------------------------------------------------- var Parser = /*#__PURE__*/function () { - function Parser(arg) { - var _ref9 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + function Parser() { + var _ref9 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, env = _ref9.env, _ref9$meta = _ref9.meta, meta = _ref9$meta === void 0 ? false : _ref9$meta, _ref9$formatter = _ref9.formatter, formatter = _ref9$formatter === void 0 ? multiline_formatter : _ref9$formatter; _classCallCheck(this, Parser); - if (arg instanceof LString) { - arg = arg.toString(); - } read_only(this, '_formatter', formatter, { hidden: true }); - read_only(this, '__lexer__', new Lexer(arg)); read_only(this, '__env__', env); read_only(this, '_meta', meta, { hidden: true @@ -4883,6 +4879,14 @@ }); } _createClass(Parser, [{ + key: "parse", + value: function parse(arg) { + if (arg instanceof LString) { + arg = arg.toString(); + } + read_only(this, '__lexer__', new Lexer(arg)); + } + }, { key: "resolve", value: function resolve(name) { return this.__env__ && this.__env__.get(name, { @@ -5504,9 +5508,14 @@ env = user_env; } } - parser = new Parser(arg, { - env: env - }); + if (arg instanceof Parser) { + parser = arg; + } else { + parser = new Parser({ + env: env + }); + parser.parse(arg); + } case 2: _context9.next = 5; return _awaitAsyncGenerator(parser.read_object()); @@ -5617,65 +5626,65 @@ // :: Function that return matcher function that match string against string // ---------------------------------------------------------------------- function _uniterate_async() { - _uniterate_async = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21(object) { + _uniterate_async = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22(object) { var result, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, item; - return _regeneratorRuntime.wrap(function _callee21$(_context22) { - while (1) switch (_context22.prev = _context22.next) { + return _regeneratorRuntime.wrap(function _callee22$(_context23) { + while (1) switch (_context23.prev = _context23.next) { case 0: result = []; _iteratorAbruptCompletion = false; _didIteratorError = false; - _context22.prev = 3; + _context23.prev = 3; _iterator = _asyncIterator(object); case 5: - _context22.next = 7; + _context23.next = 7; return _iterator.next(); case 7: - if (!(_iteratorAbruptCompletion = !(_step = _context22.sent).done)) { - _context22.next = 13; + if (!(_iteratorAbruptCompletion = !(_step = _context23.sent).done)) { + _context23.next = 13; break; } item = _step.value; result.push(item); case 10: _iteratorAbruptCompletion = false; - _context22.next = 5; + _context23.next = 5; break; case 13: - _context22.next = 19; + _context23.next = 19; break; case 15: - _context22.prev = 15; - _context22.t0 = _context22["catch"](3); + _context23.prev = 15; + _context23.t0 = _context23["catch"](3); _didIteratorError = true; - _iteratorError = _context22.t0; + _iteratorError = _context23.t0; case 19: - _context22.prev = 19; - _context22.prev = 20; + _context23.prev = 19; + _context23.prev = 20; if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) { - _context22.next = 24; + _context23.next = 24; break; } - _context22.next = 24; + _context23.next = 24; return _iterator["return"](); case 24: - _context22.prev = 24; + _context23.prev = 24; if (!_didIteratorError) { - _context22.next = 27; + _context23.next = 27; break; } throw _iteratorError; case 27: - return _context22.finish(24); + return _context23.finish(24); case 28: - return _context22.finish(19); + return _context23.finish(19); case 29: - return _context22.abrupt("return", result); + return _context23.abrupt("return", result); case 30: case "end": - return _context22.stop(); + return _context23.stop(); } - }, _callee21, null, [[3, 15, 19, 29], [20,, 24, 28]]); + }, _callee22, null, [[3, 15, 19, 29], [20,, 24, 28]]); })); return _uniterate_async.apply(this, arguments); } @@ -11256,19 +11265,20 @@ while (1) switch (_context14.prev = _context14.next) { case 0: if (_this8.char_ready()) { - _context14.next = 5; + _context14.next = 6; break; } _context14.next = 3; return _this8._read(); case 3: line = _context14.sent; - parser = new Parser(line, { + parser = new Parser({ env: _this8 }); - case 5: - return _context14.abrupt("return", _this8.__parser__); + parser.parse(line); case 6: + return _context14.abrupt("return", _this8.__parser__); + case 7: case "end": return _context14.stop(); } @@ -11519,9 +11529,10 @@ string = string.valueOf(); this._with_parser = this._with_init_parser.bind(this, function () { if (!_this16.__parser__) { - _this16.__parser__ = new Parser(string, { + _this16.__parser__ = new Parser({ env: env }); + _this16.__parser__.parse(string); } return _this16.__parser__; }); @@ -11769,6 +11780,9 @@ if (typeof name === 'undefined') { name = 'anonymous'; } + this.__parser__ = new Parser({ + env: this.__env__ + }); this.__env__ = user_env.inherit(name, obj); this.__env__.set('parent.frame', doc('parent.frame', function () { return _this19.__env__; @@ -11789,29 +11803,54 @@ set_interaction_env(this.__env__, inter); } // ------------------------------------------------------------------------- - Interpreter.prototype.exec = function (code) { - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var _options$use_dynamic = options.use_dynamic, - use_dynamic = _options$use_dynamic === void 0 ? false : _options$use_dynamic, - dynamic_env = options.dynamic_env, - env = options.env; - typecheck('Interpreter::exec', code, ['string', 'array'], 1); - typecheck('Interpreter::exec', use_dynamic, 'boolean', 2); - // simple solution to overwrite this variable in each interpreter - // before evaluation of user code - if (!env) { - env = this.__env__; - } - if (!dynamic_env) { - dynamic_env = env; - } - global_env.set('**interaction-environment**', this.__env__); - return exec(code, { - env: env, - dynamic_env: dynamic_env, - use_dynamic: use_dynamic + Interpreter.prototype.exec = /*#__PURE__*/function () { + var _ref28 = _asyncToGenerator(function (arg) { + var _this20 = this; + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + return /*#__PURE__*/_regeneratorRuntime.mark(function _callee16() { + var _options$use_dynamic, use_dynamic, dynamic_env, env; + return _regeneratorRuntime.wrap(function _callee16$(_context16) { + while (1) switch (_context16.prev = _context16.next) { + case 0: + _options$use_dynamic = options.use_dynamic, use_dynamic = _options$use_dynamic === void 0 ? false : _options$use_dynamic, dynamic_env = options.dynamic_env, env = options.env; + typecheck('Interpreter::exec', arg, ['string', 'array'], 1); + typecheck('Interpreter::exec', use_dynamic, 'boolean', 2); + // simple solution to overwrite this variable in each interpreter + // before evaluation of user code + if (!env) { + env = _this20.__env__; + } + if (!dynamic_env) { + dynamic_env = env; + } + global_env.set('**interaction-environment**', _this20.__env__); + if (!Array.isArray(arg)) { + _context16.next = 10; + break; + } + return _context16.abrupt("return", exec(arg, { + env: env, + dynamic_env: dynamic_env, + use_dynamic: use_dynamic + })); + case 10: + _this20.__parser__.parse(arg); + return _context16.abrupt("return", exec(_this20.__parser__, { + env: env, + dynamic_env: dynamic_env, + use_dynamic: use_dynamic + })); + case 12: + case "end": + return _context16.stop(); + } + }, _callee16); + })(); }); - }; + return function (_x13) { + return _ref28.apply(this, arguments); + }; + }(); // ------------------------------------------------------------------------- Interpreter.prototype.get = function (value) { var result = this.__env__.get(value); @@ -11972,12 +12011,12 @@ }; // ------------------------------------------------------------------------- Environment.prototype.clone = function () { - var _this20 = this; + var _this21 = this; // duplicate refs var env = {}; // TODO: duplicated Symbols Object.keys(this.__env__).forEach(function (key) { - env[key] = _this20.__env__[key]; + env[key] = _this21.__env__[key]; }); return new Environment(env, this.__parent__, this.__name__); }; @@ -12111,14 +12150,14 @@ // For internal use only // ------------------------------------------------------------------------- Environment.prototype.constant = function (name, value) { - var _this21 = this; + var _this22 = this; if (this.__env__.hasOwnProperty(name)) { throw new Error("Environment::constant: ".concat(name, " already exists")); } if (arguments.length === 1 && is_plain_object(arguments[0])) { var obj = arguments[0]; Object.keys(obj).forEach(function (key) { - _this21.constant(name, obj[key]); + _this22.constant(name, obj[key]); }); } else { Object.defineProperty(this.__env__, name, { @@ -12290,26 +12329,26 @@ // ------------------------------------------------------------------ read: doc('read', /*#__PURE__*/function () { var _read2 = _asyncToGenerator(function () { - var _this22 = this; + var _this23 = this; var arg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - return /*#__PURE__*/_regeneratorRuntime.mark(function _callee16() { + return /*#__PURE__*/_regeneratorRuntime.mark(function _callee17() { var env, port; - return _regeneratorRuntime.wrap(function _callee16$(_context16) { - while (1) switch (_context16.prev = _context16.next) { + return _regeneratorRuntime.wrap(function _callee17$(_context17) { + while (1) switch (_context17.prev = _context17.next) { case 0: - env = _this22.env; + env = _this23.env; if (arg === null) { port = internal(env, 'stdin'); } else { port = arg; } typecheck_text_port('read', port, 'input-port'); - return _context16.abrupt("return", port.read.call(env)); + return _context17.abrupt("return", port.read.call(env)); case 4: case "end": - return _context16.stop(); + return _context17.stop(); } - }, _callee16); + }, _callee17); })(); }); function read() { @@ -12422,10 +12461,10 @@ return unbind(a) === unbind(b); }, "(%same-functions a b)\n\n A helper function that checks if the two input functions are\n the same."), // ------------------------------------------------------------------ - help: doc(new Macro('help', function (code, _ref28) { - var dynamic_env = _ref28.dynamic_env, - use_dynamic = _ref28.use_dynamic, - error = _ref28.error; + help: doc(new Macro('help', function (code, _ref29) { + var dynamic_env = _ref29.dynamic_env, + use_dynamic = _ref29.use_dynamic, + error = _ref29.error; var symbol; if (code.car instanceof LSymbol) { symbol = code.car; @@ -12475,10 +12514,10 @@ }, "(cdr pair)\n\n This function returns the cdr (all but first) of the list."), // ------------------------------------------------------------------ 'set!': doc(new Macro('set!', function (code) { - var _this23 = this; - var _ref29 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - use_dynamic = _ref29.use_dynamic, - rest = _objectWithoutProperties(_ref29, _excluded4); + var _this24 = this; + var _ref30 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + use_dynamic = _ref30.use_dynamic, + rest = _objectWithoutProperties(_ref30, _excluded4); var dynamic_env = this; var env = this; var ref; @@ -12529,7 +12568,7 @@ if (parts.length > 1) { var key = parts.pop(); var name = parts.join('.'); - var obj = _this23.get(name, { + var obj = _this24.get(name, { throwError: false }); if (obj) { @@ -12628,36 +12667,36 @@ } if (is_node()) { return new Promise( /*#__PURE__*/function () { - var _ref30 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(resolve, reject) { - var path, cmd, _args19; - return _regeneratorRuntime.wrap(function _callee17$(_context17) { - while (1) switch (_context17.prev = _context17.next) { + var _ref31 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(resolve, reject) { + var path, cmd, _args20; + return _regeneratorRuntime.wrap(function _callee18$(_context18) { + while (1) switch (_context18.prev = _context18.next) { case 0: path = nodeRequire('path'); if (!module_path) { - _context17.next = 6; + _context18.next = 6; break; } module_path = module_path.valueOf(); file = path.join(module_path, file); - _context17.next = 12; + _context18.next = 12; break; case 6: cmd = g_env.get('command-line', { throwError: false }); if (!cmd) { - _context17.next = 11; + _context18.next = 11; break; } - _context17.next = 10; + _context18.next = 10; return cmd(); case 10: - _args19 = _context17.sent; + _args20 = _context18.sent; case 11: - if (_args19 && !is_nil(_args19)) { + if (_args20 && !is_nil(_args20)) { process.cwd(); - file = path.join(path.dirname(_args19.car.valueOf()), file); + file = path.join(path.dirname(_args20.car.valueOf()), file); } case 12: global_env.set(PATH, path.dirname(file)); @@ -12678,12 +12717,12 @@ }); case 14: case "end": - return _context17.stop(); + return _context18.stop(); } - }, _callee17); + }, _callee18); })); - return function (_x13, _x14) { - return _ref30.apply(this, arguments); + return function (_x14, _x15) { + return _ref31.apply(this, arguments); }; }()); } @@ -12715,16 +12754,16 @@ }), "(while cond body)\n\n Creates a loop, it executes cond and body until cond expression is false."), // ------------------------------------------------------------------ 'do': doc(new Macro('do', /*#__PURE__*/function () { - var _ref31 = _asyncToGenerator(function (code, _ref32) { - var _this24 = this; - var use_dynamic = _ref32.use_dynamic, - error = _ref32.error; - return /*#__PURE__*/_regeneratorRuntime.mark(function _callee18() { + var _ref32 = _asyncToGenerator(function (code, _ref33) { + var _this25 = this; + var use_dynamic = _ref33.use_dynamic, + error = _ref33.error; + return /*#__PURE__*/_regeneratorRuntime.mark(function _callee19() { var self, dynamic_env, scope, vars, test, body, eval_args, node, item, _loop3; - return _regeneratorRuntime.wrap(function _callee18$(_context19) { - while (1) switch (_context19.prev = _context19.next) { + return _regeneratorRuntime.wrap(function _callee19$(_context20) { + while (1) switch (_context20.prev = _context20.next) { case 0: - self = _this24; + self = _this25; dynamic_env = self; scope = self.inherit('do'); vars = code.car; @@ -12742,19 +12781,19 @@ node = vars; // init variables case 9: if (is_nil(node)) { - _context19.next = 20; + _context20.next = 20; break; } item = node.car; - _context19.t0 = scope; - _context19.t1 = item.car; - _context19.next = 15; + _context20.t0 = scope; + _context20.t1 = item.car; + _context20.next = 15; return _evaluate(item.cdr.car, eval_args); case 15: - _context19.t2 = _context19.sent; - _context19.t0.set.call(_context19.t0, _context19.t1, _context19.t2); + _context20.t2 = _context20.sent; + _context20.t0.set.call(_context20.t0, _context20.t1, _context20.t2); node = node.cdr; - _context19.next = 9; + _context20.next = 9; break; case 20: eval_args = { @@ -12764,36 +12803,36 @@ }; _loop3 = /*#__PURE__*/_regeneratorRuntime.mark(function _loop3() { var node, next, _item, value, symbols; - return _regeneratorRuntime.wrap(function _loop3$(_context18) { - while (1) switch (_context18.prev = _context18.next) { + return _regeneratorRuntime.wrap(function _loop3$(_context19) { + while (1) switch (_context19.prev = _context19.next) { case 0: if (is_nil(body)) { - _context18.next = 3; + _context19.next = 3; break; } - _context18.next = 3; + _context19.next = 3; return lips.evaluate(body, eval_args); case 3: node = vars; next = {}; // next value of variables case 5: if (is_nil(node)) { - _context18.next = 15; + _context19.next = 15; break; } _item = node.car; if (is_nil(_item.cdr.cdr)) { - _context18.next = 12; + _context19.next = 12; break; } - _context18.next = 10; + _context19.next = 10; return _evaluate(_item.cdr.cdr.car, eval_args); case 10: - value = _context18.sent; + value = _context19.sent; next[_item.car.valueOf()] = value; case 12: node = node.cdr; - _context18.next = 5; + _context19.next = 5; break; case 15: symbols = Object.getOwnPropertySymbols(next); // new scope for new iteration @@ -12803,47 +12842,47 @@ }); case 18: case "end": - return _context18.stop(); + return _context19.stop(); } }, _loop3); }); case 22: - _context19.next = 24; + _context20.next = 24; return _evaluate(test.car, eval_args); case 24: - _context19.t3 = _context19.sent; - if (!(_context19.t3 === false)) { - _context19.next = 29; + _context20.t3 = _context20.sent; + if (!(_context20.t3 === false)) { + _context20.next = 29; break; } - return _context19.delegateYield(_loop3(), "t4", 27); + return _context20.delegateYield(_loop3(), "t4", 27); case 27: - _context19.next = 22; + _context20.next = 22; break; case 29: if (is_nil(test.cdr)) { - _context19.next = 33; + _context20.next = 33; break; } - _context19.next = 32; + _context20.next = 32; return _evaluate(test.cdr.car, eval_args); case 32: - return _context19.abrupt("return", _context19.sent); + return _context20.abrupt("return", _context20.sent); case 33: case "end": - return _context19.stop(); + return _context20.stop(); } - }, _callee18); + }, _callee19); })(); }); - return function (_x15, _x16) { - return _ref31.apply(this, arguments); + return function (_x16, _x17) { + return _ref32.apply(this, arguments); }; }()), "(do (( )) (test return) . body)\n\n Iteration macro that evaluates the expression body in scope of the variables.\n On each loop it changes the variables according to the expression and runs\n test to check if the loop should continue. If test is a single value, the macro\n will return undefined. If the test is a pair of expressions the macro will\n evaluate and return the second expression after the loop exits."), // ------------------------------------------------------------------ - 'if': doc(new Macro('if', function (code, _ref33) { - var error = _ref33.error, - use_dynamic = _ref33.use_dynamic; + 'if': doc(new Macro('if', function (code, _ref34) { + var error = _ref34.error, + use_dynamic = _ref34.use_dynamic; var dynamic_env = this; var env = this; var eval_args = { @@ -13161,28 +13200,28 @@ }, "(parent.frame)\n\n Returns the parent environment if called from inside a function.\n If no parent frame can be found it returns nil."), // ------------------------------------------------------------------ 'eval': doc('eval', function (code, env) { - var _this25 = this; + var _this26 = this; env = env || this.get('interaction-environment').call(this); return _evaluate(code, { env: env, dynamic_env: env, error: function error(e) { var error = global_env.get('display-error'); - error.call(_this25, e.message); + error.call(_this26, e.message); if (e.code) { var stack = e.code.map(function (line, i) { return "[".concat(i + 1, "]: ").concat(line); }).join('\n'); - error.call(_this25, stack); + error.call(_this26, stack); } } }); }, "(eval expr)\n (eval expr environment)\n\n Function that evaluates LIPS Scheme code. If the second argument is provided\n it will be the environment that the code is evaluated in."), // ------------------------------------------------------------------ lambda: new Macro('lambda', function (code) { - var _ref34 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - use_dynamic = _ref34.use_dynamic, - error = _ref34.error; + var _ref35 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + use_dynamic = _ref35.use_dynamic, + error = _ref35.error; var self = this; var __doc__; if (is_pair(code.cdr) && LString.isString(code.cdr.car) && !is_nil(code.cdr.cdr)) { @@ -13190,10 +13229,10 @@ } function lambda() { // lambda got scopes as context in apply - var _ref35 = is_context(this) ? this : { + var _ref36 = is_context(this) ? this : { dynamic_env: self }, - dynamic_env = _ref35.dynamic_env; + dynamic_env = _ref36.dynamic_env; var env = self.inherit('lambda'); dynamic_env = dynamic_env.inherit('lambda'); if (this && !is_context(this)) { @@ -13276,9 +13315,9 @@ // ------------------------------------------------------------------ 'macroexpand-1': doc(new Macro('macroexpand-1', macro_expand(true)), "(macroexpand-1 expr)\n\n Macro similar to macroexpand but it expand macros only one level\n and return single expression as output."), // ------------------------------------------------------------------ - 'define-macro': doc(new Macro(macro, function (macro, _ref36) { - var use_dynamic = _ref36.use_dynamic, - error = _ref36.error; + 'define-macro': doc(new Macro(macro, function (macro, _ref37) { + var use_dynamic = _ref37.use_dynamic, + error = _ref37.error; if (is_pair(macro.car) && macro.car.car instanceof LSymbol) { var name = macro.car.car.__name__; var __doc__; @@ -13368,8 +13407,8 @@ } else { validate_identifiers(macro.car); } - var syntax = new Syntax(function (code, _ref37) { - var macro_expand = _ref37.macro_expand; + var syntax = new Syntax(function (code, _ref38) { + var macro_expand = _ref38.macro_expand; log('>> SYNTAX'); log(code); log(macro); @@ -13495,10 +13534,10 @@ cdr = fn(cdr); } if (is_promise(car) || is_promise(cdr)) { - return promise_all([car, cdr]).then(function (_ref38) { - var _ref39 = _slicedToArray(_ref38, 2), - car = _ref39[0], - cdr = _ref39[1]; + return promise_all([car, cdr]).then(function (_ref39) { + var _ref40 = _slicedToArray(_ref39, 2), + car = _ref40[0], + cdr = _ref40[1]; return new Pair(car, cdr); }); } else { @@ -14118,10 +14157,10 @@ return false; }, "(string->number number [radix])\n\n Function that parses a string into a number."), // ------------------------------------------------------------------ - 'try': doc(new Macro('try', function (code, _ref40) { - var _this26 = this; - var use_dynamic = _ref40.use_dynamic; - _ref40.error; + 'try': doc(new Macro('try', function (code, _ref41) { + var _this27 = this; + var use_dynamic = _ref41.use_dynamic; + _ref41.error; return new Promise(function (resolve, reject) { var catch_clause, finally_clause; if (LSymbol.is(code.cdr.car.car, 'catch')) { @@ -14155,15 +14194,15 @@ }; } var args = { - env: _this26, + env: _this27, use_dynamic: use_dynamic, - dynamic_env: _this26, + dynamic_env: _this27, error: function error(e) { if (e instanceof IgnoreException) { throw e; } if (catch_clause) { - var env = _this26.inherit('try'); + var env = _this27.inherit('try'); var name = catch_clause.cdr.car.car; if (!(name instanceof LSymbol)) { throw new Error('try: invalid syntax: catch require variable name'); @@ -14173,7 +14212,7 @@ var catch_args = { env: env, use_dynamic: use_dynamic, - dynamic_env: _this26, + dynamic_env: _this27, error: function error(e) { catch_error = true; reject(e); @@ -14241,7 +14280,7 @@ }, "(for-each fn . lists)\n\n Higher-order function that calls function `fn` on each\n value of the argument. If you provide more than one list\n it will take each value from each list and call `fn` function\n with that many arguments as number of list arguments."), // ------------------------------------------------------------------ map: doc('map', function map(fn) { - var _this27 = this; + var _this28 = this; for (var _len32 = arguments.length, lists = new Array(_len32 > 1 ? _len32 - 1 : 0), _key32 = 1; _key32 < _len32; _key32++) { lists[_key32 - 1] = arguments[_key32]; } @@ -14250,7 +14289,7 @@ lists.forEach(function (arg, i) { typecheck('map', arg, ['pair', 'nil'], i + 1); // detect cycles - if (is_pair(arg) && !is_list.call(_this27, arg)) { + if (is_pair(arg) && !is_list.call(_this28, arg)) { throw new Error("map: argument ".concat(i + 1, " is not a list")); } }); @@ -14272,7 +14311,7 @@ use_dynamic: use_dynamic }); return unpromise(result, function (head) { - return unpromise(map.call.apply(map, [_this27, fn].concat(_toConsumableArray(lists.map(function (l) { + return unpromise(map.call.apply(map, [_this28, fn].concat(_toConsumableArray(lists.map(function (l) { return l.cdr; })))), function (rest) { return new Pair(head, rest); @@ -14354,7 +14393,7 @@ }, "(pluck . strings)\n\n If called with a single string it will return a function that when\n called with an object will return that key from the object.\n If called with more then one string the returned function will\n create a new object by copying all properties from the given object."), // ------------------------------------------------------------------ reduce: doc('reduce', fold('reduce', function (reduce, fn, init) { - var _this28 = this; + var _this29 = this; for (var _len35 = arguments.length, lists = new Array(_len35 > 3 ? _len35 - 3 : 0), _key36 = 3; _key36 < _len35; _key36++) { lists[_key36 - 3] = arguments[_key36]; } @@ -14368,7 +14407,7 @@ return unpromise(fn.apply(void 0, _toConsumableArray(lists.map(function (l) { return l.car; })).concat([init])), function (value) { - return reduce.call.apply(reduce, [_this28, fn, value].concat(_toConsumableArray(lists.map(function (l) { + return reduce.call.apply(reduce, [_this29, fn, value].concat(_toConsumableArray(lists.map(function (l) { return l.cdr; })))); }); @@ -14582,9 +14621,9 @@ // ------------------------------------------------------------------ 'eq?': doc('eq?', equal, "(eq? a b)\n\n Function that compares two values if they are identical."), // ------------------------------------------------------------------ - or: doc(new Macro('or', function (code, _ref41) { - var use_dynamic = _ref41.use_dynamic, - error = _ref41.error; + or: doc(new Macro('or', function (code, _ref42) { + var use_dynamic = _ref42.use_dynamic, + error = _ref42.error; var args = global_env.get('list->array')(code); var self = this; var dynamic_env = self; @@ -14621,9 +14660,9 @@ }), "(or . expressions)\n\n Macro that executes the values one by one and returns the first that is\n a truthy value. If there are no expressions that evaluate to true it\n returns false."), // ------------------------------------------------------------------ and: doc(new Macro('and', function (code) { - var _ref42 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - use_dynamic = _ref42.use_dynamic, - error = _ref42.error; + var _ref43 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + use_dynamic = _ref43.use_dynamic, + error = _ref43.error; var args = global_env.get('list->array')(code); var self = this; var dynamic_env = self; @@ -14792,25 +14831,25 @@ } // ------------------------------------------------------------------------- /* c8 ignore next 11 */ function _node_specific() { - _node_specific = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22() { + _node_specific = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee23() { var _yield$import, createRequire, moduleURL, __dirname, __filename; - return _regeneratorRuntime.wrap(function _callee22$(_context23) { - while (1) switch (_context23.prev = _context23.next) { + return _regeneratorRuntime.wrap(function _callee23$(_context24) { + while (1) switch (_context24.prev = _context24.next) { case 0: - _context23.next = 2; + _context24.next = 2; return import('mod' + 'ule'); case 2: - _yield$import = _context23.sent; + _yield$import = _context24.sent; createRequire = _yield$import.createRequire; nodeRequire = createRequire((typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('lips.js', document.baseURI).href))); - _context23.next = 7; + _context24.next = 7; return import('fs'); case 7: - fs = _context23.sent; - _context23.next = 10; + fs = _context24.sent; + _context24.next = 10; return import('path'); case 10: - path = _context23.sent; + path = _context24.sent; global_env.set('global', global); global_env.set('self', global); global_env.set('window', undefined); @@ -14858,9 +14897,9 @@ }); case 22: case "end": - return _context23.stop(); + return _context24.stop(); } - }, _callee22); + }, _callee23); })); return _node_specific.apply(this, arguments); } @@ -15064,54 +15103,54 @@ node.forEach(traverse); } } - function promise(_x17) { + function promise(_x18) { return _promise.apply(this, arguments); } function _promise() { - _promise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(node) { + _promise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20(node) { var pair; - return _regeneratorRuntime.wrap(function _callee19$(_context20) { - while (1) switch (_context20.prev = _context20.next) { + return _regeneratorRuntime.wrap(function _callee20$(_context21) { + while (1) switch (_context21.prev = _context21.next) { case 0: - _context20.t0 = Pair; + _context21.t0 = Pair; if (!node.have_cycles('car')) { - _context20.next = 5; + _context21.next = 5; break; } - _context20.t1 = node.car; - _context20.next = 8; + _context21.t1 = node.car; + _context21.next = 8; break; case 5: - _context20.next = 7; + _context21.next = 7; return resolve(node.car); case 7: - _context20.t1 = _context20.sent; + _context21.t1 = _context21.sent; case 8: - _context20.t2 = _context20.t1; + _context21.t2 = _context21.t1; if (!node.have_cycles('cdr')) { - _context20.next = 13; + _context21.next = 13; break; } - _context20.t3 = node.cdr; - _context20.next = 16; + _context21.t3 = node.cdr; + _context21.next = 16; break; case 13: - _context20.next = 15; + _context21.next = 15; return resolve(node.cdr); case 15: - _context20.t3 = _context20.sent; + _context21.t3 = _context21.sent; case 16: - _context20.t4 = _context20.t3; - pair = new _context20.t0(_context20.t2, _context20.t4); + _context21.t4 = _context21.t3; + pair = new _context21.t0(_context21.t2, _context21.t4); if (node[__data__]) { pair[__data__] = true; } - return _context20.abrupt("return", pair); + return _context21.abrupt("return", pair); case 20: case "end": - return _context20.stop(); + return _context21.stop(); } - }, _callee19); + }, _callee20); })); return _promise.apply(this, arguments); } @@ -15126,9 +15165,9 @@ } } // ------------------------------------------------------------------------- - function evaluate_args(rest, _ref43) { - var use_dynamic = _ref43.use_dynamic, - options = _objectWithoutProperties(_ref43, _excluded5); + function evaluate_args(rest, _ref44) { + var use_dynamic = _ref44.use_dynamic, + options = _objectWithoutProperties(_ref44, _excluded5); var args = []; var node = rest; function next() { @@ -15236,10 +15275,10 @@ // ------------------------------------------------------------------------- function call_function(fn, args) { - var _ref44 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, - env = _ref44.env, - dynamic_env = _ref44.dynamic_env, - use_dynamic = _ref44.use_dynamic; + var _ref45 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + env = _ref45.env, + dynamic_env = _ref45.dynamic_env, + use_dynamic = _ref45.use_dynamic; var scope = env === null || env === void 0 ? void 0 : env.new_frame(fn, args); var dynamic_scope = dynamic_env === null || dynamic_env === void 0 ? void 0 : dynamic_env.new_frame(fn, args); var context = new LambdaContext({ @@ -15252,12 +15291,12 @@ // ------------------------------------------------------------------------- function apply(fn, args) { - var _ref45 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, - env = _ref45.env, - dynamic_env = _ref45.dynamic_env, - use_dynamic = _ref45.use_dynamic, - _ref45$error = _ref45.error, - error = _ref45$error === void 0 ? function () {} : _ref45$error; + var _ref46 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + env = _ref46.env, + dynamic_env = _ref46.dynamic_env, + use_dynamic = _ref46.use_dynamic, + _ref46$error = _ref46.error, + error = _ref46$error === void 0 ? function () {} : _ref46$error; args = evaluate_args(args, { env: env, dynamic_env: dynamic_env, @@ -15412,13 +15451,13 @@ return Continuation; }(); // ------------------------------------------------------------------------- function _evaluate(code) { - var _ref46 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - env = _ref46.env, - dynamic_env = _ref46.dynamic_env, - use_dynamic = _ref46.use_dynamic, - _ref46$error = _ref46.error, - error = _ref46$error === void 0 ? noop : _ref46$error, - rest = _objectWithoutProperties(_ref46, _excluded6); + var _ref47 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + env = _ref47.env, + dynamic_env = _ref47.dynamic_env, + use_dynamic = _ref47.use_dynamic, + _ref47$error = _ref47.error, + error = _ref47$error === void 0 ? noop : _ref47$error, + rest = _objectWithoutProperties(_ref47, _excluded6); return function (rest) { try { if (!is_env(dynamic_env)) { @@ -15526,10 +15565,10 @@ }); // ------------------------------------------------------------------------- function exec_with_stacktrace(code) { - var _ref47 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - env = _ref47.env, - dynamic_env = _ref47.dynamic_env, - use_dynamic = _ref47.use_dynamic; + var _ref48 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + env = _ref48.env, + dynamic_env = _ref48.dynamic_env, + use_dynamic = _ref48.use_dynamic; return _evaluate(code, { env: env, dynamic_env: dynamic_env, @@ -15559,14 +15598,14 @@ function exec_collect(collect_callback) { return /*#__PURE__*/function () { var _exec_lambda = _asyncToGenerator(function (arg) { - var _ref48 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - env = _ref48.env, - dynamic_env = _ref48.dynamic_env, - use_dynamic = _ref48.use_dynamic; - return /*#__PURE__*/_regeneratorRuntime.mark(function _callee20() { + var _ref49 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + env = _ref49.env, + dynamic_env = _ref49.dynamic_env, + use_dynamic = _ref49.use_dynamic; + return /*#__PURE__*/_regeneratorRuntime.mark(function _callee21() { var results, input, _iteratorAbruptCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, code, value; - return _regeneratorRuntime.wrap(function _callee20$(_context21) { - while (1) switch (_context21.prev = _context21.next) { + return _regeneratorRuntime.wrap(function _callee21$(_context22) { + while (1) switch (_context22.prev = _context22.next) { case 0: if (!is_env(dynamic_env)) { dynamic_env = env === true ? user_env : env || user_env; @@ -15578,92 +15617,92 @@ } results = []; if (!is_pair(arg)) { - _context21.next = 8; + _context22.next = 8; break; } - _context21.next = 6; + _context22.next = 6; return exec_with_stacktrace(arg, { env: env, dynamic_env: dynamic_env, use_dynamic: use_dynamic }); case 6: - _context21.t0 = _context21.sent; - return _context21.abrupt("return", [_context21.t0]); + _context22.t0 = _context22.sent; + return _context22.abrupt("return", [_context22.t0]); case 8: input = Array.isArray(arg) ? arg : _parse(arg); _iteratorAbruptCompletion2 = false; _didIteratorError2 = false; - _context21.prev = 11; + _context22.prev = 11; _iterator2 = _asyncIterator(input); case 13: - _context21.next = 15; + _context22.next = 15; return _iterator2.next(); case 15: - if (!(_iteratorAbruptCompletion2 = !(_step2 = _context21.sent).done)) { - _context21.next = 31; + if (!(_iteratorAbruptCompletion2 = !(_step2 = _context22.sent).done)) { + _context22.next = 31; break; } code = _step2.value; - _context21.next = 19; + _context22.next = 19; return exec_with_stacktrace(code, { env: env, dynamic_env: dynamic_env, use_dynamic: use_dynamic }); case 19: - value = _context21.sent; - _context21.t1 = results; - _context21.t2 = collect_callback; - _context21.t3 = code; - _context21.next = 25; + value = _context22.sent; + _context22.t1 = results; + _context22.t2 = collect_callback; + _context22.t3 = code; + _context22.next = 25; return value; case 25: - _context21.t4 = _context21.sent; - _context21.t5 = (0, _context21.t2)(_context21.t3, _context21.t4); - _context21.t1.push.call(_context21.t1, _context21.t5); + _context22.t4 = _context22.sent; + _context22.t5 = (0, _context22.t2)(_context22.t3, _context22.t4); + _context22.t1.push.call(_context22.t1, _context22.t5); case 28: _iteratorAbruptCompletion2 = false; - _context21.next = 13; + _context22.next = 13; break; case 31: - _context21.next = 37; + _context22.next = 37; break; case 33: - _context21.prev = 33; - _context21.t6 = _context21["catch"](11); + _context22.prev = 33; + _context22.t6 = _context22["catch"](11); _didIteratorError2 = true; - _iteratorError2 = _context21.t6; + _iteratorError2 = _context22.t6; case 37: - _context21.prev = 37; - _context21.prev = 38; + _context22.prev = 37; + _context22.prev = 38; if (!(_iteratorAbruptCompletion2 && _iterator2["return"] != null)) { - _context21.next = 42; + _context22.next = 42; break; } - _context21.next = 42; + _context22.next = 42; return _iterator2["return"](); case 42: - _context21.prev = 42; + _context22.prev = 42; if (!_didIteratorError2) { - _context21.next = 45; + _context22.next = 45; break; } throw _iteratorError2; case 45: - return _context21.finish(42); + return _context22.finish(42); case 46: - return _context21.finish(37); + return _context22.finish(37); case 47: - return _context21.abrupt("return", results); + return _context22.abrupt("return", results); case 48: case "end": - return _context21.stop(); + return _context22.stop(); } - }, _callee20, null, [[11, 33, 37, 47], [38,, 42, 46]]); + }, _callee21, null, [[11, 33, 37, 47], [38,, 42, 46]]); })(); }); - function exec_lambda(_x18) { + function exec_lambda(_x19) { return _exec_lambda.apply(this, arguments); } return exec_lambda; @@ -15872,9 +15911,9 @@ this.rpc('init', [url])["catch"](function (error) { console.error(error); }); - this.exec = function (code, _ref49) { - var _ref49$use_dynamic = _ref49.use_dynamic, - use_dynamic = _ref49$use_dynamic === void 0 ? false : _ref49$use_dynamic; + this.exec = function (code, _ref50) { + var _ref50$use_dynamic = _ref50.use_dynamic, + use_dynamic = _ref50$use_dynamic === void 0 ? false : _ref50$use_dynamic; return this.rpc('eval', [code, use_dynamic]); }; } @@ -15883,10 +15922,10 @@ // :: Serialization // ------------------------------------------------------------------------- var serialization_map = { - 'pair': function pair(_ref50) { - var _ref51 = _slicedToArray(_ref50, 2), - car = _ref51[0], - cdr = _ref51[1]; + 'pair': function pair(_ref51) { + var _ref52 = _slicedToArray(_ref51, 2), + car = _ref52[0], + cdr = _ref52[1]; return Pair(car, cdr); }, 'number': function number(value) { @@ -15895,10 +15934,10 @@ } return LNumber(value); }, - 'regex': function regex(_ref52) { - var _ref53 = _slicedToArray(_ref52, 2), - pattern = _ref53[0], - flag = _ref53[1]; + 'regex': function regex(_ref53) { + var _ref54 = _slicedToArray(_ref53, 2), + pattern = _ref54[0], + flag = _ref54[1]; return new RegExp(pattern, flag); }, 'nil': function nil() { @@ -16192,10 +16231,10 @@ // ------------------------------------------------------------------------- var banner = function () { // Rollup tree-shaking is removing the variable if it's normal string because - // obviously 'Fri, 22 Mar 2024 13:26:48 +0000' == '{{' + 'DATE}}'; can be removed + // obviously 'Fri, 22 Mar 2024 16:45:56 +0000' == '{{' + 'DATE}}'; can be removed // but disabling Tree-shaking is adding lot of not used code so we use this // hack instead - var date = LString('Fri, 22 Mar 2024 13:26:48 +0000').valueOf(); + var date = LString('Fri, 22 Mar 2024 16:45:56 +0000').valueOf(); var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date); var _format = function _format(x) { return x.toString().padStart(2, '0'); @@ -16235,7 +16274,7 @@ read_only(Parameter, '__class__', 'parameter'); // ------------------------------------------------------------------------- var version = 'DEV'; - var date = 'Fri, 22 Mar 2024 13:26:48 +0000'; + var date = 'Fri, 22 Mar 2024 16:45:56 +0000'; // unwrap async generator into Promise var parse = compose(uniterate_async, _parse); diff --git a/dist/lips.min.js b/dist/lips.min.js index 82259787..aebddb70 100644 --- a/dist/lips.min.js +++ b/dist/lips.min.js @@ -31,9 +31,9 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Fri, 22 Mar 2024 13:26:48 +0000 + * build: Fri, 22 Mar 2024 16:45:56 +0000 */ -(function(e,t){typeof exports==="object"&&typeof module!=="undefined"?t(exports):typeof define==="function"&&define.amd?define(["exports"],t):(e=typeof globalThis!=="undefined"?globalThis:e||self,t(e.lips={}))})(this,function(e){"use strict";var o=typeof document!=="undefined"?document.currentScript:null;function n(e,t){if(t.get){return t.get.call(e)}return t.value}function i(e,t,r){if(!t.has(e)){throw new TypeError("attempted to "+r+" private field on non-instance")}return t.get(e)}function r(e,t){var r=i(e,t,"get");return n(e,r)}function a(e,t,r){if(t.set){t.set.call(e,r)}else{if(!t.writable){throw new TypeError("attempted to set read only private field")}t.value=r}}function f(e,t,r){var n=i(e,t,"set");a(e,n,r);return r}function k(e){k=Object.setPrototypeOf?Object.getPrototypeOf.bind():function e(t){return t.__proto__||Object.getPrototypeOf(t)};return k(e)}function B(e,t){B=Object.setPrototypeOf?Object.setPrototypeOf.bind():function e(t,r){t.__proto__=r;return t};return B(e,t)}function I(t){try{return Function.toString.call(t).indexOf("[native code]")!==-1}catch(e){return typeof t==="function"}}function P(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(P=function e(){return!!t})()}function N(e,t,r){if(P())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,t);var i=new(e.bind.apply(e,n));return r&&B(i,r.prototype),i}function T(e){var n=typeof Map==="function"?new Map:undefined;T=function e(t){if(t===null||!I(t))return t;if(typeof t!=="function"){throw new TypeError("Super expression must either be null or a function")}if(typeof n!=="undefined"){if(n.has(t))return n.get(t);n.set(t,r)}function r(){return N(t,arguments,k(this).constructor)}r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:false,writable:true,configurable:true}});return B(r,t)};return T(e)}function _(e){"@babel/helpers - typeof";return _="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_(e)}function L(e){if(e===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return e}function M(e,t){if(t&&(_(t)==="object"||typeof t==="function")){return t}else if(t!==void 0){throw new TypeError("Derived constructors may only return object or undefined")}return L(e)}function R(e,t){if(typeof t!=="function"&&t!==null){throw new TypeError("Super expression must either be null or a function")}e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:true,configurable:true}});Object.defineProperty(e,"prototype",{writable:false});if(t)B(e,t)}function Q(e){if(Array.isArray(e))return e}function Z(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function X(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r=0)continue;r[i]=e[i]}return r}function le(e,t){if(e==null)return{};var r=fe(e,t);var n,i;if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);for(i=0;i=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,n))continue;r[n]=e[n]}}return r}function he(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,u,a,o=[],s=!0,c=!1;try{if(u=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=u.call(r)).done)&&(o.push(n.value),o.length!==t);s=!0);}catch(e){c=!0,i=e}finally{try{if(!s&&null!=r["return"]&&(a=r["return"](),Object(a)!==a))return}finally{if(c)throw i}}return o}}function b(e,t){return Q(e)||he(e,t)||ee(e,t)||te()}function _e(e){if(Array.isArray(e))return X(e)}function pe(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function U(e){return _e(e)||Z(e)||ee(e)||pe()}function de(e,t){this.v=e,this.k=t}function ve(e){return new de(e,0)}function me(a){var u,o;function s(r,e){try{var n=a[r](e),i=n.value,u=i instanceof de;Promise.resolve(u?i.v:i).then(function(e){if(u){var t="return"===r?"return":"next";if(!i.k||e.done)return s(t,e);e=a[t](e).value}c(n.done?"return":"normal",e)},function(e){s("throw",e)})}catch(e){c("throw",e)}}function c(e,t){switch(e){case"return":u.resolve({value:t,done:!0});break;case"throw":u.reject(t);break;default:u.resolve({value:t,done:!1})}(u=u.next)?s(u.key,u.arg):o=null}this._invoke=function(n,i){return new Promise(function(e,t){var r={key:n,arg:i,resolve:e,reject:t,next:null};o?o=o.next=r:(u=o=r,s(n,i))})},"function"!=typeof a["return"]&&(this["return"]=void 0)}me.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},me.prototype.next=function(e){return this._invoke("next",e)},me.prototype["throw"]=function(e){return this._invoke("throw",e)},me.prototype["return"]=function(e){return this._invoke("return",e)};function ye(e){return function(){return new me(e.apply(this,arguments))}}function ge(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e["default"]:e}var be={exports:{}};var we={exports:{}};(function(t){function r(e){"@babel/helpers - typeof";return t.exports=r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t.exports.__esModule=true,t.exports["default"]=t.exports,r(e)}t.exports=r,t.exports.__esModule=true,t.exports["default"]=t.exports})(we);var De=we.exports;(function(B){var I=De["default"];function P(){B.exports=P=function e(){return a},B.exports.__esModule=true,B.exports["default"]=B.exports;var c,a={},e=Object.prototype,f=e.hasOwnProperty,l=Object.defineProperty||function(e,t,r){e[t]=r.value},t="function"==typeof Symbol?Symbol:{},i=t.iterator||"@@iterator",r=t.asyncIterator||"@@asyncIterator",n=t.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(c){u=function e(t,r,n){return t[r]=n}}function o(e,t,r,n){var i=t&&t.prototype instanceof s?t:s,u=Object.create(i.prototype),a=new S(n||[]);return l(u,"_invoke",{value:A(e,r,a)}),u}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}a.wrap=o;var _="suspendedStart",p="suspendedYield",d="executing",v="completed",m={};function s(){}function y(){}function g(){}var b={};u(b,i,function(){return this});var w=Object.getPrototypeOf,D=w&&w(w(j([])));D&&D!==e&&f.call(D,i)&&(b=D);var x=g.prototype=s.prototype=Object.create(b);function E(e){["next","throw","return"].forEach(function(t){u(e,t,function(e){return this._invoke(t,e)})})}function F(o,s){function c(e,t,r,n){var i=h(o[e],o,t);if("throw"!==i.type){var u=i.arg,a=u.value;return a&&"object"==I(a)&&f.call(a,"__await")?s.resolve(a.__await).then(function(e){c("next",e,r,n)},function(e){c("throw",e,r,n)}):s.resolve(a).then(function(e){u.value=e,r(u)},function(e){return c("throw",e,r,n)})}n(i.arg)}var i;l(this,"_invoke",{value:function e(r,n){function t(){return new s(function(e,t){c(r,n,e,t)})}return i=i?i.then(t,t):t()}})}function A(u,a,o){var s=_;return function(e,t){if(s===d)throw new Error("Generator is already running");if(s===v){if("throw"===e)throw t;return{value:c,done:!0}}for(o.method=e,o.arg=t;;){var r=o.delegate;if(r){var n=k(r,o);if(n){if(n===m)continue;return n}}if("next"===o.method)o.sent=o._sent=o.arg;else if("throw"===o.method){if(s===_)throw s=v,o.arg;o.dispatchException(o.arg)}else"return"===o.method&&o.abrupt("return",o.arg);s=d;var i=h(u,a,o);if("normal"===i.type){if(s=o.done?v:p,i.arg===m)continue;return{value:i.arg,done:o.done}}"throw"===i.type&&(s=v,o.method="throw",o.arg=i.arg)}}}function k(e,t){var r=t.method,n=e.iterator[r];if(n===c)return t.delegate=null,"throw"===r&&e.iterator["return"]&&(t.method="return",t.arg=c,k(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),m;var i=h(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,m;var u=i.arg;return u?u.done?(t[e.resultName]=u.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=c),t.delegate=null,m):u:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,m)}function O(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function C(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function S(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function j(t){if(t||""===t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,n=function e(){for(;++r=0;--i){var u=this.tryEntries[i],a=u.completion;if("root"===u.tryLoc)return t("end");if(u.tryLoc<=this.prev){var o=f.call(u,"catchLoc"),s=f.call(u,"finallyLoc");if(o&&s){if(this.prev=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&f.call(i,"finallyLoc")&&this.prev=0;--r){var n=this.tryEntries[r];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),C(n),m}},catch:function e(t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc===t){var i=n.completion;if("throw"===i.type){var u=i.arg;C(n)}return u}}throw new Error("illegal catch attempt")},delegateYield:function e(t,r,n){return this.delegate={iterator:j(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=c),m}},a}B.exports=P,B.exports.__esModule=true,B.exports["default"]=B.exports})(be);var xe=be.exports;var Ee=xe();var Fe=Ee;try{regeneratorRuntime=Ee}catch(e){if(typeof globalThis==="object"){globalThis.regeneratorRuntime=Ee}else{Function("r","regeneratorRuntime = r")(Ee)}}var O=ge(Fe);let Ae;try{Ae=new TextDecoder}catch(e){}let v;let ke;let m=0;const Oe=105;const Ce=57342;const Se=57343;const je=57337;const Be=6;const Ie={};let p={};let Pe;let Ne;let Te=0;let Le=0;let Me;let Re;let qe=[];let Ue=[];let ze;let Ve;let $e;let Ye={useRecords:false,mapsAsObjects:true};let Je=false;let Ke=2;try{new Function("")}catch(e){Ke=Infinity}class He{constructor(r){if(r){if((r.keyMap||r._keyMap)&&!r.useRecords){r.useRecords=false;r.mapsAsObjects=true}if(r.useRecords===false&&r.mapsAsObjects===undefined)r.mapsAsObjects=true;if(r.getStructures)r.getShared=r.getStructures;if(r.getShared&&!r.structures)(r.structures=[]).uninitialized=true;if(r.keyMap){this.mapKey=new Map;for(let[e,t]of Object.entries(r.keyMap))this.mapKey.set(t,e)}}Object.assign(this,r)}decodeKey(e){return this.keyMap?this.mapKey.get(e)||e:e}encodeKey(e){return this.keyMap&&this.keyMap.hasOwnProperty(e)?this.keyMap[e]:e}encodeKeys(r){if(!this._keyMap)return r;let n=new Map;for(let[e,t]of Object.entries(r))n.set(this._keyMap.hasOwnProperty(e)?this._keyMap[e]:e,t);return n}decodeKeys(e){if(!this._keyMap||e.constructor.name!="Map")return e;if(!this._mapKey){this._mapKey=new Map;for(let[e,t]of Object.entries(this._keyMap))this._mapKey.set(t,e)}let r={};e.forEach((e,t)=>r[Ze(this._mapKey.has(t)?this._mapKey.get(t):t)]=e);return r}mapDecode(e,t){let r=this.decode(e);if(this._keyMap){switch(r.constructor.name){case"Array":return r.map(e=>this.decodeKeys(e))}}return r}decode(t,e){if(v){return Dt(()=>{xt();return this?this.decode(t,e):He.prototype.decode.call(Ye,t,e)})}ke=e>-1?e:t.length;m=0;Le=0;Ne=null;Me=null;v=t;try{Ve=t.dataView||(t.dataView=new DataView(t.buffer,t.byteOffset,t.byteLength))}catch(e){v=null;if(t instanceof Uint8Array)throw e;throw new Error("Source must be a Uint8Array or Buffer but was a "+(t&&typeof t=="object"?t.constructor.name:typeof t))}if(this instanceof He){p=this;ze=this.sharedValues&&(this.pack?new Array(this.maxPrivatePackedValues||16).concat(this.sharedValues):this.sharedValues);if(this.structures){Pe=this.structures;return Ge()}else if(!Pe||Pe.length>0){Pe=[]}}else{p=Ye;if(!Pe||Pe.length>0)Pe=[];ze=null}return Ge()}decodeMultiple(r,n){let i,u=0;try{let e=r.length;Je=true;let t=this?this.decode(r,e):At.decode(r,e);if(n){if(n(t)===false){return}while(m=Me.postBundlePosition){let e=new Error("Unexpected bundle position");e.incomplete=true;throw e}m=Me.postBundlePosition;Me=null}if(m==ke){Pe=null;v=null;if(Re)Re=null}else if(m>ke){let e=new Error("Unexpected end of CBOR data");e.incomplete=true;throw e}else if(!Je){throw new Error("Data read, but end of buffer not reached")}return e}catch(e){xt();if(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer")){e.incomplete=true}throw e}}function u(){let n=v[m++];let i=n>>5;n=n&31;if(n>23){switch(n){case 24:n=v[m++];break;case 25:if(i==7){return ot()}n=Ve.getUint16(m);m+=2;break;case 26:if(i==7){let t=Ve.getFloat32(m);if(p.useFloat32>2){let e=Ft[(v[m]&127)<<1|v[m+1]>>7];m+=4;return(e*t+(t>0?.5:-.5)>>0)/e}m+=4;return t}n=Ve.getUint32(m);m+=4;break;case 27:if(i==7){let e=Ve.getFloat64(m);m+=8;return e}if(i>1){if(Ve.getUint32(m)>0)throw new Error("JavaScript does not support arrays, maps, or strings with length over 4294967295");n=Ve.getUint32(m+4)}else if(p.int64AsNumber){n=Ve.getUint32(m)*4294967296;n+=Ve.getUint32(m+4)}else n=Ve.getBigUint64(m);m+=8;break;case 31:switch(i){case 2:case 3:throw new Error("Indefinite length not supported for byte or text strings");case 4:let e=[];let t,r=0;while((t=u())!=Ie){e[r++]=t}return i==4?e:i==3?e.join(""):Buffer.concat(e);case 5:let n;if(p.mapsAsObjects){let e={};if(p.keyMap)while((n=u())!=Ie)e[Ze(p.decodeKey(n))]=u();else while((n=u())!=Ie)e[Ze(n)]=u();return e}else{if($e){p.mapsAsObjects=true;$e=false}let e=new Map;if(p.keyMap)while((n=u())!=Ie)e.set(p.decodeKey(n),u());else while((n=u())!=Ie)e.set(n,u());return e}case 7:return Ie;default:throw new Error("Invalid major type for indefinite length "+i)}default:throw new Error("Unknown token "+n)}}switch(i){case 0:return n;case 1:return~n;case 2:return it(n);case 3:if(Le>=m){return Ne.slice(m-Te,(m+=n)-Te)}if(Le==0&&ke<140&&n<32){let e=n<16?nt(n):rt(n);if(e!=null)return e}return Xe(n);case 4:let t=new Array(n);for(let e=0;e=je){let e=Pe[n&8191];if(e){if(!e.read)e.read=Qe(e);return e.read()}if(n<65536){if(n==Se){let e=bt();let t=u();let r=u();ct(t,r);let n={};if(p.keyMap)for(let t=2;t23){switch(t){case 24:t=v[m++];break;case 25:t=Ve.getUint16(m);m+=2;break;case 26:t=Ve.getUint32(m);m+=4;break;default:throw new Error("Expected array header, but got "+v[m-1])}}let r=this.compiledReader;while(r){if(r.propertyCount===t)return r(u);r=r.next}if(this.slowReads++>=Ke){let e=this.length==t?this:this.slice(0,t);r=p.keyMap?new Function("r","return {"+e.map(e=>p.decodeKey(e)).map(e=>We.test(e)?Ze(e)+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"}"):new Function("r","return {"+e.map(e=>We.test(e)?Ze(e)+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"}");if(this.compiledReader)r.next=this.compiledReader;r.propertyCount=t;this.compiledReader=r;return r(u)}let n={};if(p.keyMap)for(let e=0;e64&&Ae)return Ae.decode(v.subarray(m,m+=e));const r=m+e;const n=[];t="";while(m65535){e-=65536;n.push(e>>>10&1023|55296);e=56320|e&1023}n.push(e)}else{n.push(i)}if(n.length>=4096){t+=tt.apply(String,n);n.length=0}}if(n.length>0){t+=tt.apply(String,n)}return t}let tt=String.fromCharCode;function rt(t){let r=m;let n=new Array(t);for(let e=0;e0){m=r;return}n[e]=i}return tt.apply(String,n)}function nt(d){if(d<4){if(d<2){if(d===0)return"";else{let e=v[m++];if((e&128)>1){m-=1;return}return tt(e)}}else{let e=v[m++];let t=v[m++];if((e&128)>0||(t&128)>0){m-=2;return}if(d<3)return tt(e,t);let r=v[m++];if((r&128)>0){m-=3;return}return tt(e,t,r)}}else{let l=v[m++];let h=v[m++];let _=v[m++];let p=v[m++];if((l&128)>0||(h&128)>0||(_&128)>0||(p&128)>0){m-=4;return}if(d<6){if(d===4)return tt(l,h,_,p);else{let e=v[m++];if((e&128)>0){m-=5;return}return tt(l,h,_,p,e)}}else if(d<8){let e=v[m++];let t=v[m++];if((e&128)>0||(t&128)>0){m-=6;return}if(d<7)return tt(l,h,_,p,e,t);let r=v[m++];if((r&128)>0){m-=7;return}return tt(l,h,_,p,e,t,r)}else{let o=v[m++];let s=v[m++];let c=v[m++];let f=v[m++];if((o&128)>0||(s&128)>0||(c&128)>0||(f&128)>0){m-=8;return}if(d<10){if(d===8)return tt(l,h,_,p,o,s,c,f);else{let e=v[m++];if((e&128)>0){m-=9;return}return tt(l,h,_,p,o,s,c,f,e)}}else if(d<12){let e=v[m++];let t=v[m++];if((e&128)>0||(t&128)>0){m-=10;return}if(d<11)return tt(l,h,_,p,o,s,c,f,e,t);let r=v[m++];if((r&128)>0){m-=11;return}return tt(l,h,_,p,o,s,c,f,e,t,r)}else{let n=v[m++];let i=v[m++];let u=v[m++];let a=v[m++];if((n&128)>0||(i&128)>0||(u&128)>0||(a&128)>0){m-=12;return}if(d<14){if(d===12)return tt(l,h,_,p,o,s,c,f,n,i,u,a);else{let e=v[m++];if((e&128)>0){m-=13;return}return tt(l,h,_,p,o,s,c,f,n,i,u,a,e)}}else{let e=v[m++];let t=v[m++];if((e&128)>0||(t&128)>0){m-=14;return}if(d<15)return tt(l,h,_,p,o,s,c,f,n,i,u,a,e,t);let r=v[m++];if((r&128)>0){m-=15;return}return tt(l,h,_,p,o,s,c,f,n,i,u,a,e,t,r)}}}}}function it(e){return p.copyBuffers?Uint8Array.prototype.slice.call(v,m,m+=e):v.subarray(m,m+=e)}let ut=new Float32Array(1);let at=new Uint8Array(ut.buffer,0,4);function ot(){let t=v[m++];let r=v[m++];let e=(t&127)>>2;if(e===31){if(r||t&3)return NaN;return t&128?-Infinity:Infinity}if(e===0){let e=((t&3)<<8|r)/(1<<24);return t&128?-e:e}at[3]=t&128|(e>>1)+56;at[2]=(t&7)<<5|r>>3;at[1]=r<<5;at[0]=0;return ut[0]}new Array(4096);class st{constructor(e,t){this.value=e;this.tag=t}}qe[0]=e=>{return new Date(e)};qe[1]=e=>{return new Date(Math.round(e*1e3))};qe[2]=r=>{let n=BigInt(0);for(let e=0,t=r.byteLength;e{return BigInt(-1)-qe[2](e)};qe[4]=e=>{return+(e[1]+"e"+e[0])};qe[5]=e=>{return e[1]*Math.exp(e[0]*Math.log(2))};const ct=(e,t)=>{e=e-57344;let r=Pe[e];if(r&&r.isShared){(Pe.restoreStructures||(Pe.restoreStructures=[]))[e]=r}Pe[e]=t;t.read=Qe(t)};qe[Oe]=r=>{let e=r.length;let n=r[1];ct(r[0],n);let i={};for(let t=2;t{if(Me)return Me[0].slice(Me.position0,Me.position0+=e);return new st(e,14)};qe[15]=e=>{if(Me)return Me[1].slice(Me.position1,Me.position1+=e);return new st(e,15)};let ft={Error:Error,RegExp:RegExp};qe[27]=e=>{return(ft[e[0]]||Error)(e[1],e[2])};const lt=e=>{if(v[m++]!=132){let e=new Error("Packed values structure must be followed by a 4 element array");if(v.length{if(!ze){if(p.getShared)wt();else return new st(e,Be)}if(typeof e=="number")return ze[16+(e>=0?2*e:-2*e-1)];let t=new Error("No support for non-integer packed references yet");if(e===undefined)t.incomplete=true;throw t};qe[28]=e=>{if(!Re){Re=new Map;Re.id=0}let t=Re.id++;let r=v[m];let n;if(r>>5==4)n=[];else n={};let i={target:n};Re.set(t,i);let u=e();if(i.used)return Object.assign(n,u);i.target=u;return u};qe[28].handlesRead=true;qe[29]=e=>{let t=Re.get(e);t.used=true;return t.target};qe[258]=e=>new Set(e);(qe[259]=e=>{if(p.mapsAsObjects){p.mapsAsObjects=false;$e=true}return e()}).handlesRead=true;function ht(e,t){if(typeof e==="string")return e+t;if(e instanceof Array)return e.concat(t);return Object.assign({},e,t)}function _t(){if(!ze){if(p.getShared)wt();else throw new Error("No packed values available")}return ze}const pt=1399353956;Ue.push((e,t)=>{if(e>=225&&e<=255)return ht(_t().prefixes[e-224],t);if(e>=28704&&e<=32767)return ht(_t().prefixes[e-28672],t);if(e>=1879052288&&e<=2147483647)return ht(_t().prefixes[e-1879048192],t);if(e>=216&&e<=223)return ht(t,_t().suffixes[e-216]);if(e>=27647&&e<=28671)return ht(t,_t().suffixes[e-27639]);if(e>=1811940352&&e<=1879048191)return ht(t,_t().suffixes[e-1811939328]);if(e==pt){return{packedValues:ze,structures:Pe.slice(0),version:t}}if(e==55799)return t});const dt=new Uint8Array(new Uint16Array([1]).buffer)[0]==1;const vt=[Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array=="undefined"?{name:"BigUint64Array"}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array=="undefined"?{name:"BigInt64Array"}:BigInt64Array,Float32Array,Float64Array];const mt=[64,68,69,70,71,72,77,78,79,85,86];for(let e=0;e{if(!o)throw new Error("Could not find typed array for code "+s);if(!p.copyBuffers){if(t===1||t===2&&!(e.byteOffset&1)||t===4&&!(e.byteOffset&3)||t===8&&!(e.byteOffset&7))return new o(e.buffer,e.byteOffset,e.byteLength)}return new o(Uint8Array.prototype.slice.call(e,0).buffer)}:e=>{if(!o)throw new Error("Could not find typed array for code "+s);let t=new DataView(e.buffer,e.byteOffset,e.byteLength);let r=e.length>>u;let n=new o(r);let i=t[c];for(let e=0;e23){switch(e){case 24:e=v[m++];break;case 25:e=Ve.getUint16(m);m+=2;break;case 26:e=Ve.getUint32(m);m+=4;break}}return e}function wt(){if(p.getShared){let e=Dt(()=>{v=null;return p.getShared()})||{};let t=e.structures||[];p.sharedVersion=e.version;ze=p.sharedValues=e.packedValues;if(Pe===true)p.structures=Pe=t;else Pe.splice.apply(Pe,[0,t.length].concat(t))}}function Dt(e){let t=ke;let r=m;let n=Te;let i=Le;let u=Ne;let a=Re;let o=Me;let s=new Uint8Array(v.slice(0,ke));let c=Pe;let f=p;let l=Je;let h=e();ke=t;m=r;Te=n;Le=i;Ne=u;Re=a;Me=o;v=s;Je=l;Pe=c;p=f;Ve=new DataView(v.buffer,v.byteOffset,v.byteLength);return h}function xt(){v=null;Re=null;Pe=null}function Et(e){qe[e.tag]=e.decode}const Ft=new Array(147);for(let e=0;e<256;e++){Ft[e]=+("1e"+Math.floor(45.15-e*.30103))}let At=new He({useRecords:false});At.decode;At.decodeMultiple;let kt;try{kt=new TextEncoder}catch(e){}let Ot,Ct;const St=typeof globalThis==="object"&&globalThis.Buffer;const jt=typeof St!=="undefined";const Bt=jt?St.allocUnsafeSlow:Uint8Array;const It=jt?St:Uint8Array;const Pt=256;const Nt=jt?4294967296:2144337920;let Tt;let C;let Lt;let S=0;let Mt;let Rt=null;const qt=61440;const Ut=/[\u0080-\uFFFF]/;const zt=Symbol("record-id");class Vt extends He{constructor(r){super(r);this.offset=0;let s;let a;let f;let l;let n;r=r||{};let c=It.prototype.utf8Write?function(e,t,r){return C.utf8Write(e,t,r)}:kt&&kt.encodeInto?function(e,t){return kt.encodeInto(e,C.subarray(t)).written}:false;let u=this;let e=r.structures||r.saveStructures;let h=r.maxSharedStructures;if(h==null)h=e?128:0;if(h>8190)throw new Error("Maximum maxSharedStructure is 8190");let i=r.sequential;if(i){h=0}if(!this.structures)this.structures=[];if(this.saveStructures)this.saveShared=this.saveStructures;let _,p,o=r.sharedValues;let d;if(o){d=Object.create(null);for(let e=0,t=o.length;ethis.encodeKeys(e));break}}return this.encode(e,t)};this.encode=function(t,e){if(!C){C=new Bt(8192);Lt=new DataView(C.buffer,0,8192);S=0}Mt=C.length-10;if(Mt-S<2048){C=new Bt(C.length);Lt=new DataView(C.buffer,0,C.length);Mt=C.length-10;S=0}else if(e===nr)S=S+7&2147483640;s=S;if(u.useSelfDescribedHeader){Lt.setUint32(S,3654940416);S+=3}n=u.structuredClone?new Map:null;if(u.bundleStrings&&typeof t!=="string"){Rt=[];Rt.size=Infinity}else Rt=null;a=u.structures;if(a){if(a.uninitialized){let e=u.getShared()||{};u.structures=a=e.structures||[];u.sharedVersion=e.version;let r=u.sharedValues=e.packedValues;if(r){d={};for(let e=0,t=r.length;eh&&!i)e=h;if(!a.transitions){a.transitions=Object.create(null);for(let u=0;u0){C[S++]=216;C[S++]=51;Jt(4);let r=e.values;g(r);Jt(0);Jt(0);p=Object.create(d||null);for(let e=0,t=r.length;eMt)w(S);u.offset=S;let e=Xt(C.subarray(s,S),n.idsToInsert);n=null;return e}if(e&nr){C.start=s;C.end=S;return C}return C.subarray(s,S)}finally{if(a){if(y<10)y++;if(a.length>h)a.length=h;if(m>1e4){a.transitions=null;y=0;m=0;if(v.length>0)v=[]}else if(v.length>0&&!i){for(let e=0,t=v.length;eh){u.structures=u.structures.slice(0,h)}let e=C.subarray(s,S);if(u.updateSharedData()===false)return u.encode(t);return e}if(e&ir)S=s}};this.findCommonStringsToPack=()=>{_=new Map;if(!d)d=Object.create(null);return e=>{let r=e&&e.threshold||4;let n=this.pack?e.maxPrivatePackedValues||16:0;if(!o)o=this.sharedValues=[];for(let[e,t]of _){if(t.count>r){d[e]=n++;o.push(e);f=true}}while(this.saveShared&&this.updateSharedData()===false){}_=null}};const g=a=>{if(S>Mt)C=w(S);var e=typeof a;var o;if(e==="string"){if(p){let e=p[a];if(e>=0){if(e<16)C[S++]=e+224;else{C[S++]=198;if(e&1)g(15-e>>1);else g(e-16>>1)}return}else if(_&&!r.pack){let e=_.get(a);if(e)e.count++;else _.set(a,{count:1})}}let i=a.length;if(Rt&&i>=4&&i<1024){if((Rt.size+=i)>qt){let e;let t=(Rt[0]?Rt[0].length*3+Rt[1].length:0)+10;if(S+t>Mt)C=w(S+t);C[S++]=217;C[S++]=223;C[S++]=249;C[S++]=Rt.position?132:130;C[S++]=26;e=S-s;S+=4;if(Rt.position){er(s,g)}Rt=["",""];Rt.size=0;Rt.position=e}let e=Ut.test(a);Rt[e?0:1]+=a;C[S++]=e?206:207;g(i);return}let u;if(i<32){u=1}else if(i<256){u=2}else if(i<65536){u=3}else{u=5}let e=i*3;if(S+e>Mt)C=w(S+e);if(i<64||!c){let e,t,r,n=S+u;for(e=0;e>6|192;C[n++]=t&63|128}else if((t&64512)===55296&&((r=a.charCodeAt(e+1))&64512)===56320){t=65536+((t&1023)<<10)+(r&1023);e++;C[n++]=t>>18|240;C[n++]=t>>12&63|128;C[n++]=t>>6&63|128;C[n++]=t&63|128}else{C[n++]=t>>12|224;C[n++]=t>>6&63|128;C[n++]=t&63|128}}o=n-S-u}else{o=c(a,S+u,e)}if(o<24){C[S++]=96|o}else if(o<256){if(u<2){C.copyWithin(S+2,S+1,S+1+o)}C[S++]=120;C[S++]=o}else if(o<65536){if(u<3){C.copyWithin(S+3,S+2,S+2+o)}C[S++]=121;C[S++]=o>>8;C[S++]=o&255}else{if(u<5){C.copyWithin(S+5,S+3,S+3+o)}C[S++]=122;Lt.setUint32(S,o);S+=4}S+=o}else if(e==="number"){if(!this.alwaysUseFloat&&a>>>0===a){if(a<24){C[S++]=a}else if(a<256){C[S++]=24;C[S++]=a}else if(a<65536){C[S++]=25;C[S++]=a>>8;C[S++]=a&255}else{C[S++]=26;Lt.setUint32(S,a);S+=4}}else if(!this.alwaysUseFloat&&a>>0===a){if(a>=-24){C[S++]=31-a}else if(a>=-256){C[S++]=56;C[S++]=~a}else if(a>=-65536){C[S++]=57;Lt.setUint16(S,~a);S+=2}else{C[S++]=58;Lt.setUint32(S,~a);S+=4}}else{let t;if((t=this.useFloat32)>0&&a<4294967296&&a>=-2147483648){C[S++]=250;Lt.setFloat32(S,a);let e;if(t<4||(e=a*Ft[(C[S]&127)<<1|C[S+1]>>7])>>0===e){S+=4;return}else S--}C[S++]=251;Lt.setFloat64(S,a);S+=8}}else if(e==="object"){if(!a)C[S++]=246;else{if(n){let t=n.get(a);if(t){C[S++]=216;C[S++]=29;C[S++]=25;if(!t.references){let e=n.idsToInsert||(n.idsToInsert=[]);t.references=[];e.push(t)}t.references.push(S-s);S+=2;return}else n.set(a,{offset:S-s})}let e=a.constructor;if(e===Object){b(a,true)}else if(e===Array){o=a.length;if(o<24){C[S++]=128|o}else{Jt(o)}for(let e=0;e>8;C[S++]=o&255}else{C[S++]=186;Lt.setUint32(S,o);S+=4}if(u.keyMap){for(let[e,t]of a){g(u.encodeKey(e));g(t)}}else{for(let[e,t]of a){g(e);g(t)}}}else{for(let r=0,e=Ot.length;r>8;C[S++]=t&255}else if(t>-1){C[S++]=218;Lt.setUint32(S,t);S+=4}e.encode.call(this,a,g,w);return}}if(a[Symbol.iterator]){if(Tt){let e=new Error("Iterable should be serialized as iterator");e.iteratorNotHandled=true;throw e}C[S++]=159;for(let e of a){g(e)}C[S++]=255;return}if(a[Symbol.asyncIterator]||Ht(a)){let e=new Error("Iterable/blob should be serialized as iterator");e.iteratorNotHandled=true;throw e}if(this.useToJSON&&a.toJSON){const t=a.toJSON();if(t!==a)return g(t)}b(a,!a.hasOwnProperty)}}}else if(e==="boolean"){C[S++]=a?245:244}else if(e==="bigint"){if(a=0){C[S++]=27;Lt.setBigUint64(S,a)}else if(a>-(BigInt(1)<{let t=Object.keys(e);let r=Object.values(e);let n=t.length;if(n<24){C[S++]=160|n}else if(n<256){C[S++]=184;C[S++]=n}else if(n<65536){C[S++]=185;C[S++]=n>>8;C[S++]=n&255}else{C[S++]=186;Lt.setUint32(S,n);S+=4}if(u.keyMap){for(let e=0;e{C[S++]=185;let e=S-s;S+=2;let n=0;if(u.keyMap){for(let e in t)if(r||t.hasOwnProperty(e)){g(u.encodeKey(e));g(t[e]);n++}}else{for(let e in t)if(r||t.hasOwnProperty(e)){g(e);g(t[e]);n++}}C[e+++s]=n>>8;C[e+s]=n&255}:(t,r)=>{let n,i=l.transitions||(l.transitions=Object.create(null));let u=0;let a=0;let o;let s;if(this.keyMap){s=Object.keys(t).map(e=>this.encodeKey(e));a=s.length;for(let t=0;t>8|224;C[S++]=c&255}else{if(!s)s=i.__keys__||(i.__keys__=Object.keys(t));if(o===undefined){c=l.nextId++;if(!c){c=0;l.nextId=1}if(c>=Pt){l.nextId=(c=h)+1}}else{c=o}l[c]=s;if(c>8|224;C[S++]=c&255;i=l.transitions;for(let e=0;e=Pt-h)v.shift()[zt]=undefined;v.push(i);Jt(a+2);g(57344+c);g(s);if(r===null)return;for(let e in t)if(r||t.hasOwnProperty(e))g(t[e]);return}}if(a<24){C[S++]=128|a}else{Jt(a)}if(r===null)return;for(let e in t)if(r||t.hasOwnProperty(e))g(t[e])};const w=e=>{let t;if(e>16777216){if(e-s>Nt)throw new Error("Encoded buffer would be larger than maximum buffer size");t=Math.min(Nt,Math.round(Math.max((e-s)*(e>67108864?1.25:2),4194304)/4096)*4096)}else t=(Math.max(e-s<<2,C.length-1)>>12)+1<<12;let r=new Bt(t);Lt=new DataView(r.buffer,0,t);if(C.copy)C.copy(r,0,s,e);else r.set(C.slice(s,e));S-=s;s=0;Mt=r.length-10;return C=r};let D=100;let x=1e3;this.encodeAsIterable=function(e,t){return k(e,t,E)};this.encodeAsAsyncIterable=function(e,t){return k(e,t,O)};function*E(n,i,e){let t=n.constructor;if(t===Object){let r=u.useRecords!==false;if(r)b(n,null);else $t(Object.keys(n).length,160);for(let t in n){let e=n[t];if(!r)g(t);if(e&&typeof e==="object"){if(i[t])yield*E(e,i[t]);else yield*F(e,i,t)}else g(e)}}else if(t===Array){let e=n.length;Jt(e);for(let t=0;tD)){if(i.element)yield*E(e,i.element);else yield*F(e,i,"element")}else g(e)}}else if(n[Symbol.iterator]){C[S++]=159;for(let e of n){if(e&&(typeof e==="object"||S-s>D)){if(i.element)yield*E(e,i.element);else yield*F(e,i,"element")}else g(e)}C[S++]=255}else if(Ht(n)){$t(n.size,64);yield C.subarray(s,S);yield n;A()}else if(n[Symbol.asyncIterator]){C[S++]=159;yield C.subarray(s,S);yield n;A();C[S++]=255}else{g(n)}if(e&&S>s)yield C.subarray(s,S);else if(S-s>D){yield C.subarray(s,S);A()}}function*F(t,r,n){let i=S-s;try{g(t);if(S-s>D){yield C.subarray(s,S);A()}}catch(e){if(e.iteratorNotHandled){r[n]={};S=s+i;yield*E.call(this,t,r[n])}else throw e}}function A(){D=x;u.encode(null,ur)}function k(e,t,r){if(t&&t.chunkThreshold)D=x=t.chunkThreshold;else D=100;if(e&&typeof e==="object"){u.encode(null,ur);return r(e,u.iterateProperties||(u.iterateProperties={}),true)}return[u.encode(e)]}async function*O(e,t){for(let r of E(e,t,true)){let e=r.constructor;if(e===It||e===Uint8Array)yield r;else if(Ht(r)){let e=r.stream().getReader();let t;while(!(t=await e.read()).done){yield t.value}}else if(r[Symbol.asyncIterator]){for await(let e of r){A();if(e)yield*O(e,t.async||(t.async={}));else yield u.encode(e)}}else{yield r}}}}useBuffer(e){C=e;Lt=new DataView(C.buffer,C.byteOffset,C.byteLength);S=0}clearSharedData(){if(this.structures)this.structures=[];if(this.sharedValues)this.sharedValues=undefined}updateSharedData(){let t=this.sharedVersion||0;this.sharedVersion=t+1;let e=this.structures.slice(0);let r=new Yt(e,this.sharedValues,this.sharedVersion);let n=this.saveShared(r,e=>(e&&e.version||0)==t);if(n===false){r=this.getShared()||{};this.structures=r.structures||[];this.sharedValues=r.packedValues;this.sharedVersion=r.version;this.structures.nextId=this.structures.length}else{e.forEach((e,t)=>this.structures[t]=e)}return n}}function $t(e,t){if(e<24)C[S++]=t|e;else if(e<256){C[S++]=t|24;C[S++]=e}else if(e<65536){C[S++]=t|25;C[S++]=e>>8;C[S++]=e&255}else{C[S++]=t|26;Lt.setUint32(S,e);S+=4}}class Yt{constructor(e,t,r){this.structures=e;this.packedValues=t;this.version=r}}function Jt(e){if(e<24)C[S++]=128|e;else if(e<256){C[S++]=152;C[S++]=e}else if(e<65536){C[S++]=153;C[S++]=e>>8;C[S++]=e&255}else{C[S++]=154;Lt.setUint32(S,e);S+=4}}const Kt=typeof Blob==="undefined"?function(){}:Blob;function Ht(e){if(e instanceof Kt)return true;let t=e[Symbol.toStringTag];return t==="Blob"||t==="File"}function Gt(r,n){switch(typeof r){case"string":if(r.length>3){if(n.objectMap[r]>-1||n.values.length>=n.maxValues)return;let e=n.get(r);if(e){if(++e.count==2){n.values.push(r)}}else{n.set(r,{count:1});if(n.samplingPackedValues){let e=n.samplingPackedValues.get(r);if(e)e.count++;else n.samplingPackedValues.set(r,{count:1})}}}break;case"object":if(r){if(r instanceof Array){for(let e=0,t=r.length;e=0&&r<4294967296){C[S++]=26;Lt.setUint32(S,r);S+=4}else{C[S++]=251;Lt.setFloat64(S,r);S+=8}}},{tag:258,encode(e,t){let r=Array.from(e);t(r)}},{tag:27,encode(e,t){t([e.name,e.message])}},{tag:27,encode(e,t){t(["RegExp",e.source,e.flags])}},{getTag(e){return e.tag},encode(e,t){t(e.value)}},{encode(e,t,r){Zt(e,r)}},{getTag(e){if(e.constructor===Uint8Array){if(this.tagUint8Array||jt&&this.tagUint8Array!==false)return 64}},encode(e,t,r){Zt(e,r)}},Qt(68,1),Qt(69,2),Qt(70,4),Qt(71,8),Qt(72,1),Qt(77,2),Qt(78,4),Qt(79,8),Qt(85,4),Qt(86,8),{encode(t,n){let e=t.packedValues||[];let r=t.structures||[];if(e.values.length>0){C[S++]=216;C[S++]=51;Jt(4);let r=e.values;n(r);Jt(0);Jt(0);packedObjectMap=Object.create(sharedPackedObjectMap||null);for(let e=0,t=r.length;e1)e-=4;return{tag:e,encode:function e(t,r){let n=t.byteLength;let i=t.byteOffset||0;let u=t.buffer||t;r(jt?St.from(u,i,n):new Uint8Array(u,i,n))}}}function Zt(e,t){let r=e.byteLength;if(r<24){C[S++]=64+r}else if(r<256){C[S++]=88;C[S++]=r}else if(r<65536){C[S++]=89;C[S++]=r>>8;C[S++]=r&255}else{C[S++]=90;Lt.setUint32(S,r);S+=4}if(S+r>=C.length){t(S+r)}C.set(e.buffer?e:new Uint8Array(e),S);S+=r}function Xt(n,e){let r;let i=e.length*2;let u=n.length-i;e.sort((e,t)=>e.offset>t.offset?1:-1);for(let r=0;r>8;n[e]=r&255}}while(r=e.pop()){let e=r.offset;n.copyWithin(e+i,e,u);i-=2;let t=e+i;n[t++]=216;n[t++]=28;u=e}return n}function er(e,t){Lt.setUint32(Rt.position+e,S-Rt.position-e+1);let r=Rt;Rt=null;t(r[0]);t(r[1])}function tr(e){if(e.Class){if(!e.encode)throw new Error("Extension has no encode function");Ct.unshift(e.Class);Ot.unshift(e)}Et(e)}let rr=new Vt({useRecords:false});rr.encode;rr.encodeAsIterable;rr.encodeAsAsyncIterable;const nr=512;const ir=1024;const ur=2048;var ar={}; +(function(e,t){typeof exports==="object"&&typeof module!=="undefined"?t(exports):typeof define==="function"&&define.amd?define(["exports"],t):(e=typeof globalThis!=="undefined"?globalThis:e||self,t(e.lips={}))})(this,function(e){"use strict";var s=typeof document!=="undefined"?document.currentScript:null;function n(e,t){if(t.get){return t.get.call(e)}return t.value}function a(e,t,r){if(!t.has(e)){throw new TypeError("attempted to "+r+" private field on non-instance")}return t.get(e)}function r(e,t){var r=a(e,t,"get");return n(e,r)}function c(e,t,r){if(t.set){t.set.call(e,r)}else{if(!t.writable){throw new TypeError("attempted to set read only private field")}t.value=r}}function f(e,t,r){var n=a(e,t,"set");c(e,n,r);return r}function k(e){k=Object.setPrototypeOf?Object.getPrototypeOf.bind():function e(t){return t.__proto__||Object.getPrototypeOf(t)};return k(e)}function B(e,t){B=Object.setPrototypeOf?Object.setPrototypeOf.bind():function e(t,r){t.__proto__=r;return t};return B(e,t)}function I(t){try{return Function.toString.call(t).indexOf("[native code]")!==-1}catch(e){return typeof t==="function"}}function P(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(P=function e(){return!!t})()}function N(e,t,r){if(P())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,t);var i=new(e.bind.apply(e,n));return r&&B(i,r.prototype),i}function T(e){var n=typeof Map==="function"?new Map:undefined;T=function e(t){if(t===null||!I(t))return t;if(typeof t!=="function"){throw new TypeError("Super expression must either be null or a function")}if(typeof n!=="undefined"){if(n.has(t))return n.get(t);n.set(t,r)}function r(){return N(t,arguments,k(this).constructor)}r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:false,writable:true,configurable:true}});return B(r,t)};return T(e)}function _(e){"@babel/helpers - typeof";return _="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_(e)}function L(e){if(e===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return e}function M(e,t){if(t&&(_(t)==="object"||typeof t==="function")){return t}else if(t!==void 0){throw new TypeError("Derived constructors may only return object or undefined")}return L(e)}function R(e,t){if(typeof t!=="function"&&t!==null){throw new TypeError("Super expression must either be null or a function")}e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:true,configurable:true}});Object.defineProperty(e,"prototype",{writable:false});if(t)B(e,t)}function Q(e){if(Array.isArray(e))return e}function Z(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function X(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r=0)continue;r[i]=e[i]}return r}function le(e,t){if(e==null)return{};var r=fe(e,t);var n,i;if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);for(i=0;i=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,n))continue;r[n]=e[n]}}return r}function he(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,u,a,o=[],s=!0,c=!1;try{if(u=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=u.call(r)).done)&&(o.push(n.value),o.length!==t);s=!0);}catch(e){c=!0,i=e}finally{try{if(!s&&null!=r["return"]&&(a=r["return"](),Object(a)!==a))return}finally{if(c)throw i}}return o}}function b(e,t){return Q(e)||he(e,t)||ee(e,t)||te()}function _e(e){if(Array.isArray(e))return X(e)}function pe(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function U(e){return _e(e)||Z(e)||ee(e)||pe()}function de(e,t){this.v=e,this.k=t}function ve(e){return new de(e,0)}function me(a){var u,o;function s(r,e){try{var n=a[r](e),i=n.value,u=i instanceof de;Promise.resolve(u?i.v:i).then(function(e){if(u){var t="return"===r?"return":"next";if(!i.k||e.done)return s(t,e);e=a[t](e).value}c(n.done?"return":"normal",e)},function(e){s("throw",e)})}catch(e){c("throw",e)}}function c(e,t){switch(e){case"return":u.resolve({value:t,done:!0});break;case"throw":u.reject(t);break;default:u.resolve({value:t,done:!1})}(u=u.next)?s(u.key,u.arg):o=null}this._invoke=function(n,i){return new Promise(function(e,t){var r={key:n,arg:i,resolve:e,reject:t,next:null};o?o=o.next=r:(u=o=r,s(n,i))})},"function"!=typeof a["return"]&&(this["return"]=void 0)}me.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},me.prototype.next=function(e){return this._invoke("next",e)},me.prototype["throw"]=function(e){return this._invoke("throw",e)},me.prototype["return"]=function(e){return this._invoke("return",e)};function ye(e){return function(){return new me(e.apply(this,arguments))}}function ge(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e["default"]:e}var be={exports:{}};var we={exports:{}};(function(t){function r(e){"@babel/helpers - typeof";return t.exports=r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t.exports.__esModule=true,t.exports["default"]=t.exports,r(e)}t.exports=r,t.exports.__esModule=true,t.exports["default"]=t.exports})(we);var De=we.exports;(function(B){var I=De["default"];function P(){B.exports=P=function e(){return a},B.exports.__esModule=true,B.exports["default"]=B.exports;var c,a={},e=Object.prototype,f=e.hasOwnProperty,l=Object.defineProperty||function(e,t,r){e[t]=r.value},t="function"==typeof Symbol?Symbol:{},i=t.iterator||"@@iterator",r=t.asyncIterator||"@@asyncIterator",n=t.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(c){u=function e(t,r,n){return t[r]=n}}function o(e,t,r,n){var i=t&&t.prototype instanceof s?t:s,u=Object.create(i.prototype),a=new S(n||[]);return l(u,"_invoke",{value:A(e,r,a)}),u}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}a.wrap=o;var _="suspendedStart",p="suspendedYield",d="executing",v="completed",m={};function s(){}function y(){}function g(){}var b={};u(b,i,function(){return this});var w=Object.getPrototypeOf,D=w&&w(w(j([])));D&&D!==e&&f.call(D,i)&&(b=D);var x=g.prototype=s.prototype=Object.create(b);function E(e){["next","throw","return"].forEach(function(t){u(e,t,function(e){return this._invoke(t,e)})})}function F(o,s){function c(e,t,r,n){var i=h(o[e],o,t);if("throw"!==i.type){var u=i.arg,a=u.value;return a&&"object"==I(a)&&f.call(a,"__await")?s.resolve(a.__await).then(function(e){c("next",e,r,n)},function(e){c("throw",e,r,n)}):s.resolve(a).then(function(e){u.value=e,r(u)},function(e){return c("throw",e,r,n)})}n(i.arg)}var i;l(this,"_invoke",{value:function e(r,n){function t(){return new s(function(e,t){c(r,n,e,t)})}return i=i?i.then(t,t):t()}})}function A(u,a,o){var s=_;return function(e,t){if(s===d)throw new Error("Generator is already running");if(s===v){if("throw"===e)throw t;return{value:c,done:!0}}for(o.method=e,o.arg=t;;){var r=o.delegate;if(r){var n=k(r,o);if(n){if(n===m)continue;return n}}if("next"===o.method)o.sent=o._sent=o.arg;else if("throw"===o.method){if(s===_)throw s=v,o.arg;o.dispatchException(o.arg)}else"return"===o.method&&o.abrupt("return",o.arg);s=d;var i=h(u,a,o);if("normal"===i.type){if(s=o.done?v:p,i.arg===m)continue;return{value:i.arg,done:o.done}}"throw"===i.type&&(s=v,o.method="throw",o.arg=i.arg)}}}function k(e,t){var r=t.method,n=e.iterator[r];if(n===c)return t.delegate=null,"throw"===r&&e.iterator["return"]&&(t.method="return",t.arg=c,k(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),m;var i=h(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,m;var u=i.arg;return u?u.done?(t[e.resultName]=u.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=c),t.delegate=null,m):u:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,m)}function O(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function C(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function S(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function j(t){if(t||""===t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,n=function e(){for(;++r=0;--i){var u=this.tryEntries[i],a=u.completion;if("root"===u.tryLoc)return t("end");if(u.tryLoc<=this.prev){var o=f.call(u,"catchLoc"),s=f.call(u,"finallyLoc");if(o&&s){if(this.prev=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&f.call(i,"finallyLoc")&&this.prev=0;--r){var n=this.tryEntries[r];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),C(n),m}},catch:function e(t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc===t){var i=n.completion;if("throw"===i.type){var u=i.arg;C(n)}return u}}throw new Error("illegal catch attempt")},delegateYield:function e(t,r,n){return this.delegate={iterator:j(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=c),m}},a}B.exports=P,B.exports.__esModule=true,B.exports["default"]=B.exports})(be);var xe=be.exports;var Ee=xe();var Fe=Ee;try{regeneratorRuntime=Ee}catch(e){if(typeof globalThis==="object"){globalThis.regeneratorRuntime=Ee}else{Function("r","regeneratorRuntime = r")(Ee)}}var O=ge(Fe);let Ae;try{Ae=new TextDecoder}catch(e){}let v;let ke;let m=0;const Oe=105;const Ce=57342;const Se=57343;const je=57337;const Be=6;const Ie={};let p={};let Pe;let Ne;let Te=0;let Le=0;let Me;let Re;let qe=[];let Ue=[];let ze;let Ve;let $e;let Ye={useRecords:false,mapsAsObjects:true};let Je=false;let Ke=2;try{new Function("")}catch(e){Ke=Infinity}class He{constructor(r){if(r){if((r.keyMap||r._keyMap)&&!r.useRecords){r.useRecords=false;r.mapsAsObjects=true}if(r.useRecords===false&&r.mapsAsObjects===undefined)r.mapsAsObjects=true;if(r.getStructures)r.getShared=r.getStructures;if(r.getShared&&!r.structures)(r.structures=[]).uninitialized=true;if(r.keyMap){this.mapKey=new Map;for(let[e,t]of Object.entries(r.keyMap))this.mapKey.set(t,e)}}Object.assign(this,r)}decodeKey(e){return this.keyMap?this.mapKey.get(e)||e:e}encodeKey(e){return this.keyMap&&this.keyMap.hasOwnProperty(e)?this.keyMap[e]:e}encodeKeys(r){if(!this._keyMap)return r;let n=new Map;for(let[e,t]of Object.entries(r))n.set(this._keyMap.hasOwnProperty(e)?this._keyMap[e]:e,t);return n}decodeKeys(e){if(!this._keyMap||e.constructor.name!="Map")return e;if(!this._mapKey){this._mapKey=new Map;for(let[e,t]of Object.entries(this._keyMap))this._mapKey.set(t,e)}let r={};e.forEach((e,t)=>r[Ze(this._mapKey.has(t)?this._mapKey.get(t):t)]=e);return r}mapDecode(e,t){let r=this.decode(e);if(this._keyMap){switch(r.constructor.name){case"Array":return r.map(e=>this.decodeKeys(e))}}return r}decode(t,e){if(v){return Dt(()=>{xt();return this?this.decode(t,e):He.prototype.decode.call(Ye,t,e)})}ke=e>-1?e:t.length;m=0;Le=0;Ne=null;Me=null;v=t;try{Ve=t.dataView||(t.dataView=new DataView(t.buffer,t.byteOffset,t.byteLength))}catch(e){v=null;if(t instanceof Uint8Array)throw e;throw new Error("Source must be a Uint8Array or Buffer but was a "+(t&&typeof t=="object"?t.constructor.name:typeof t))}if(this instanceof He){p=this;ze=this.sharedValues&&(this.pack?new Array(this.maxPrivatePackedValues||16).concat(this.sharedValues):this.sharedValues);if(this.structures){Pe=this.structures;return Ge()}else if(!Pe||Pe.length>0){Pe=[]}}else{p=Ye;if(!Pe||Pe.length>0)Pe=[];ze=null}return Ge()}decodeMultiple(r,n){let i,u=0;try{let e=r.length;Je=true;let t=this?this.decode(r,e):At.decode(r,e);if(n){if(n(t)===false){return}while(m=Me.postBundlePosition){let e=new Error("Unexpected bundle position");e.incomplete=true;throw e}m=Me.postBundlePosition;Me=null}if(m==ke){Pe=null;v=null;if(Re)Re=null}else if(m>ke){let e=new Error("Unexpected end of CBOR data");e.incomplete=true;throw e}else if(!Je){throw new Error("Data read, but end of buffer not reached")}return e}catch(e){xt();if(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer")){e.incomplete=true}throw e}}function u(){let n=v[m++];let i=n>>5;n=n&31;if(n>23){switch(n){case 24:n=v[m++];break;case 25:if(i==7){return ot()}n=Ve.getUint16(m);m+=2;break;case 26:if(i==7){let t=Ve.getFloat32(m);if(p.useFloat32>2){let e=Ft[(v[m]&127)<<1|v[m+1]>>7];m+=4;return(e*t+(t>0?.5:-.5)>>0)/e}m+=4;return t}n=Ve.getUint32(m);m+=4;break;case 27:if(i==7){let e=Ve.getFloat64(m);m+=8;return e}if(i>1){if(Ve.getUint32(m)>0)throw new Error("JavaScript does not support arrays, maps, or strings with length over 4294967295");n=Ve.getUint32(m+4)}else if(p.int64AsNumber){n=Ve.getUint32(m)*4294967296;n+=Ve.getUint32(m+4)}else n=Ve.getBigUint64(m);m+=8;break;case 31:switch(i){case 2:case 3:throw new Error("Indefinite length not supported for byte or text strings");case 4:let e=[];let t,r=0;while((t=u())!=Ie){e[r++]=t}return i==4?e:i==3?e.join(""):Buffer.concat(e);case 5:let n;if(p.mapsAsObjects){let e={};if(p.keyMap)while((n=u())!=Ie)e[Ze(p.decodeKey(n))]=u();else while((n=u())!=Ie)e[Ze(n)]=u();return e}else{if($e){p.mapsAsObjects=true;$e=false}let e=new Map;if(p.keyMap)while((n=u())!=Ie)e.set(p.decodeKey(n),u());else while((n=u())!=Ie)e.set(n,u());return e}case 7:return Ie;default:throw new Error("Invalid major type for indefinite length "+i)}default:throw new Error("Unknown token "+n)}}switch(i){case 0:return n;case 1:return~n;case 2:return it(n);case 3:if(Le>=m){return Ne.slice(m-Te,(m+=n)-Te)}if(Le==0&&ke<140&&n<32){let e=n<16?nt(n):rt(n);if(e!=null)return e}return Xe(n);case 4:let t=new Array(n);for(let e=0;e=je){let e=Pe[n&8191];if(e){if(!e.read)e.read=Qe(e);return e.read()}if(n<65536){if(n==Se){let e=bt();let t=u();let r=u();ct(t,r);let n={};if(p.keyMap)for(let t=2;t23){switch(t){case 24:t=v[m++];break;case 25:t=Ve.getUint16(m);m+=2;break;case 26:t=Ve.getUint32(m);m+=4;break;default:throw new Error("Expected array header, but got "+v[m-1])}}let r=this.compiledReader;while(r){if(r.propertyCount===t)return r(u);r=r.next}if(this.slowReads++>=Ke){let e=this.length==t?this:this.slice(0,t);r=p.keyMap?new Function("r","return {"+e.map(e=>p.decodeKey(e)).map(e=>We.test(e)?Ze(e)+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"}"):new Function("r","return {"+e.map(e=>We.test(e)?Ze(e)+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"}");if(this.compiledReader)r.next=this.compiledReader;r.propertyCount=t;this.compiledReader=r;return r(u)}let n={};if(p.keyMap)for(let e=0;e64&&Ae)return Ae.decode(v.subarray(m,m+=e));const r=m+e;const n=[];t="";while(m65535){e-=65536;n.push(e>>>10&1023|55296);e=56320|e&1023}n.push(e)}else{n.push(i)}if(n.length>=4096){t+=tt.apply(String,n);n.length=0}}if(n.length>0){t+=tt.apply(String,n)}return t}let tt=String.fromCharCode;function rt(t){let r=m;let n=new Array(t);for(let e=0;e0){m=r;return}n[e]=i}return tt.apply(String,n)}function nt(d){if(d<4){if(d<2){if(d===0)return"";else{let e=v[m++];if((e&128)>1){m-=1;return}return tt(e)}}else{let e=v[m++];let t=v[m++];if((e&128)>0||(t&128)>0){m-=2;return}if(d<3)return tt(e,t);let r=v[m++];if((r&128)>0){m-=3;return}return tt(e,t,r)}}else{let l=v[m++];let h=v[m++];let _=v[m++];let p=v[m++];if((l&128)>0||(h&128)>0||(_&128)>0||(p&128)>0){m-=4;return}if(d<6){if(d===4)return tt(l,h,_,p);else{let e=v[m++];if((e&128)>0){m-=5;return}return tt(l,h,_,p,e)}}else if(d<8){let e=v[m++];let t=v[m++];if((e&128)>0||(t&128)>0){m-=6;return}if(d<7)return tt(l,h,_,p,e,t);let r=v[m++];if((r&128)>0){m-=7;return}return tt(l,h,_,p,e,t,r)}else{let o=v[m++];let s=v[m++];let c=v[m++];let f=v[m++];if((o&128)>0||(s&128)>0||(c&128)>0||(f&128)>0){m-=8;return}if(d<10){if(d===8)return tt(l,h,_,p,o,s,c,f);else{let e=v[m++];if((e&128)>0){m-=9;return}return tt(l,h,_,p,o,s,c,f,e)}}else if(d<12){let e=v[m++];let t=v[m++];if((e&128)>0||(t&128)>0){m-=10;return}if(d<11)return tt(l,h,_,p,o,s,c,f,e,t);let r=v[m++];if((r&128)>0){m-=11;return}return tt(l,h,_,p,o,s,c,f,e,t,r)}else{let n=v[m++];let i=v[m++];let u=v[m++];let a=v[m++];if((n&128)>0||(i&128)>0||(u&128)>0||(a&128)>0){m-=12;return}if(d<14){if(d===12)return tt(l,h,_,p,o,s,c,f,n,i,u,a);else{let e=v[m++];if((e&128)>0){m-=13;return}return tt(l,h,_,p,o,s,c,f,n,i,u,a,e)}}else{let e=v[m++];let t=v[m++];if((e&128)>0||(t&128)>0){m-=14;return}if(d<15)return tt(l,h,_,p,o,s,c,f,n,i,u,a,e,t);let r=v[m++];if((r&128)>0){m-=15;return}return tt(l,h,_,p,o,s,c,f,n,i,u,a,e,t,r)}}}}}function it(e){return p.copyBuffers?Uint8Array.prototype.slice.call(v,m,m+=e):v.subarray(m,m+=e)}let ut=new Float32Array(1);let at=new Uint8Array(ut.buffer,0,4);function ot(){let t=v[m++];let r=v[m++];let e=(t&127)>>2;if(e===31){if(r||t&3)return NaN;return t&128?-Infinity:Infinity}if(e===0){let e=((t&3)<<8|r)/(1<<24);return t&128?-e:e}at[3]=t&128|(e>>1)+56;at[2]=(t&7)<<5|r>>3;at[1]=r<<5;at[0]=0;return ut[0]}new Array(4096);class st{constructor(e,t){this.value=e;this.tag=t}}qe[0]=e=>{return new Date(e)};qe[1]=e=>{return new Date(Math.round(e*1e3))};qe[2]=r=>{let n=BigInt(0);for(let e=0,t=r.byteLength;e{return BigInt(-1)-qe[2](e)};qe[4]=e=>{return+(e[1]+"e"+e[0])};qe[5]=e=>{return e[1]*Math.exp(e[0]*Math.log(2))};const ct=(e,t)=>{e=e-57344;let r=Pe[e];if(r&&r.isShared){(Pe.restoreStructures||(Pe.restoreStructures=[]))[e]=r}Pe[e]=t;t.read=Qe(t)};qe[Oe]=r=>{let e=r.length;let n=r[1];ct(r[0],n);let i={};for(let t=2;t{if(Me)return Me[0].slice(Me.position0,Me.position0+=e);return new st(e,14)};qe[15]=e=>{if(Me)return Me[1].slice(Me.position1,Me.position1+=e);return new st(e,15)};let ft={Error:Error,RegExp:RegExp};qe[27]=e=>{return(ft[e[0]]||Error)(e[1],e[2])};const lt=e=>{if(v[m++]!=132){let e=new Error("Packed values structure must be followed by a 4 element array");if(v.length{if(!ze){if(p.getShared)wt();else return new st(e,Be)}if(typeof e=="number")return ze[16+(e>=0?2*e:-2*e-1)];let t=new Error("No support for non-integer packed references yet");if(e===undefined)t.incomplete=true;throw t};qe[28]=e=>{if(!Re){Re=new Map;Re.id=0}let t=Re.id++;let r=v[m];let n;if(r>>5==4)n=[];else n={};let i={target:n};Re.set(t,i);let u=e();if(i.used)return Object.assign(n,u);i.target=u;return u};qe[28].handlesRead=true;qe[29]=e=>{let t=Re.get(e);t.used=true;return t.target};qe[258]=e=>new Set(e);(qe[259]=e=>{if(p.mapsAsObjects){p.mapsAsObjects=false;$e=true}return e()}).handlesRead=true;function ht(e,t){if(typeof e==="string")return e+t;if(e instanceof Array)return e.concat(t);return Object.assign({},e,t)}function _t(){if(!ze){if(p.getShared)wt();else throw new Error("No packed values available")}return ze}const pt=1399353956;Ue.push((e,t)=>{if(e>=225&&e<=255)return ht(_t().prefixes[e-224],t);if(e>=28704&&e<=32767)return ht(_t().prefixes[e-28672],t);if(e>=1879052288&&e<=2147483647)return ht(_t().prefixes[e-1879048192],t);if(e>=216&&e<=223)return ht(t,_t().suffixes[e-216]);if(e>=27647&&e<=28671)return ht(t,_t().suffixes[e-27639]);if(e>=1811940352&&e<=1879048191)return ht(t,_t().suffixes[e-1811939328]);if(e==pt){return{packedValues:ze,structures:Pe.slice(0),version:t}}if(e==55799)return t});const dt=new Uint8Array(new Uint16Array([1]).buffer)[0]==1;const vt=[Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array=="undefined"?{name:"BigUint64Array"}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array=="undefined"?{name:"BigInt64Array"}:BigInt64Array,Float32Array,Float64Array];const mt=[64,68,69,70,71,72,77,78,79,85,86];for(let e=0;e{if(!o)throw new Error("Could not find typed array for code "+s);if(!p.copyBuffers){if(t===1||t===2&&!(e.byteOffset&1)||t===4&&!(e.byteOffset&3)||t===8&&!(e.byteOffset&7))return new o(e.buffer,e.byteOffset,e.byteLength)}return new o(Uint8Array.prototype.slice.call(e,0).buffer)}:e=>{if(!o)throw new Error("Could not find typed array for code "+s);let t=new DataView(e.buffer,e.byteOffset,e.byteLength);let r=e.length>>u;let n=new o(r);let i=t[c];for(let e=0;e23){switch(e){case 24:e=v[m++];break;case 25:e=Ve.getUint16(m);m+=2;break;case 26:e=Ve.getUint32(m);m+=4;break}}return e}function wt(){if(p.getShared){let e=Dt(()=>{v=null;return p.getShared()})||{};let t=e.structures||[];p.sharedVersion=e.version;ze=p.sharedValues=e.packedValues;if(Pe===true)p.structures=Pe=t;else Pe.splice.apply(Pe,[0,t.length].concat(t))}}function Dt(e){let t=ke;let r=m;let n=Te;let i=Le;let u=Ne;let a=Re;let o=Me;let s=new Uint8Array(v.slice(0,ke));let c=Pe;let f=p;let l=Je;let h=e();ke=t;m=r;Te=n;Le=i;Ne=u;Re=a;Me=o;v=s;Je=l;Pe=c;p=f;Ve=new DataView(v.buffer,v.byteOffset,v.byteLength);return h}function xt(){v=null;Re=null;Pe=null}function Et(e){qe[e.tag]=e.decode}const Ft=new Array(147);for(let e=0;e<256;e++){Ft[e]=+("1e"+Math.floor(45.15-e*.30103))}let At=new He({useRecords:false});At.decode;At.decodeMultiple;let kt;try{kt=new TextEncoder}catch(e){}let Ot,Ct;const St=typeof globalThis==="object"&&globalThis.Buffer;const jt=typeof St!=="undefined";const Bt=jt?St.allocUnsafeSlow:Uint8Array;const It=jt?St:Uint8Array;const Pt=256;const Nt=jt?4294967296:2144337920;let Tt;let C;let Lt;let S=0;let Mt;let Rt=null;const qt=61440;const Ut=/[\u0080-\uFFFF]/;const zt=Symbol("record-id");class Vt extends He{constructor(r){super(r);this.offset=0;let s;let a;let f;let l;let n;r=r||{};let c=It.prototype.utf8Write?function(e,t,r){return C.utf8Write(e,t,r)}:kt&&kt.encodeInto?function(e,t){return kt.encodeInto(e,C.subarray(t)).written}:false;let u=this;let e=r.structures||r.saveStructures;let h=r.maxSharedStructures;if(h==null)h=e?128:0;if(h>8190)throw new Error("Maximum maxSharedStructure is 8190");let i=r.sequential;if(i){h=0}if(!this.structures)this.structures=[];if(this.saveStructures)this.saveShared=this.saveStructures;let _,p,o=r.sharedValues;let d;if(o){d=Object.create(null);for(let e=0,t=o.length;ethis.encodeKeys(e));break}}return this.encode(e,t)};this.encode=function(t,e){if(!C){C=new Bt(8192);Lt=new DataView(C.buffer,0,8192);S=0}Mt=C.length-10;if(Mt-S<2048){C=new Bt(C.length);Lt=new DataView(C.buffer,0,C.length);Mt=C.length-10;S=0}else if(e===nr)S=S+7&2147483640;s=S;if(u.useSelfDescribedHeader){Lt.setUint32(S,3654940416);S+=3}n=u.structuredClone?new Map:null;if(u.bundleStrings&&typeof t!=="string"){Rt=[];Rt.size=Infinity}else Rt=null;a=u.structures;if(a){if(a.uninitialized){let e=u.getShared()||{};u.structures=a=e.structures||[];u.sharedVersion=e.version;let r=u.sharedValues=e.packedValues;if(r){d={};for(let e=0,t=r.length;eh&&!i)e=h;if(!a.transitions){a.transitions=Object.create(null);for(let u=0;u0){C[S++]=216;C[S++]=51;Jt(4);let r=e.values;g(r);Jt(0);Jt(0);p=Object.create(d||null);for(let e=0,t=r.length;eMt)w(S);u.offset=S;let e=Xt(C.subarray(s,S),n.idsToInsert);n=null;return e}if(e&nr){C.start=s;C.end=S;return C}return C.subarray(s,S)}finally{if(a){if(y<10)y++;if(a.length>h)a.length=h;if(m>1e4){a.transitions=null;y=0;m=0;if(v.length>0)v=[]}else if(v.length>0&&!i){for(let e=0,t=v.length;eh){u.structures=u.structures.slice(0,h)}let e=C.subarray(s,S);if(u.updateSharedData()===false)return u.encode(t);return e}if(e&ir)S=s}};this.findCommonStringsToPack=()=>{_=new Map;if(!d)d=Object.create(null);return e=>{let r=e&&e.threshold||4;let n=this.pack?e.maxPrivatePackedValues||16:0;if(!o)o=this.sharedValues=[];for(let[e,t]of _){if(t.count>r){d[e]=n++;o.push(e);f=true}}while(this.saveShared&&this.updateSharedData()===false){}_=null}};const g=a=>{if(S>Mt)C=w(S);var e=typeof a;var o;if(e==="string"){if(p){let e=p[a];if(e>=0){if(e<16)C[S++]=e+224;else{C[S++]=198;if(e&1)g(15-e>>1);else g(e-16>>1)}return}else if(_&&!r.pack){let e=_.get(a);if(e)e.count++;else _.set(a,{count:1})}}let i=a.length;if(Rt&&i>=4&&i<1024){if((Rt.size+=i)>qt){let e;let t=(Rt[0]?Rt[0].length*3+Rt[1].length:0)+10;if(S+t>Mt)C=w(S+t);C[S++]=217;C[S++]=223;C[S++]=249;C[S++]=Rt.position?132:130;C[S++]=26;e=S-s;S+=4;if(Rt.position){er(s,g)}Rt=["",""];Rt.size=0;Rt.position=e}let e=Ut.test(a);Rt[e?0:1]+=a;C[S++]=e?206:207;g(i);return}let u;if(i<32){u=1}else if(i<256){u=2}else if(i<65536){u=3}else{u=5}let e=i*3;if(S+e>Mt)C=w(S+e);if(i<64||!c){let e,t,r,n=S+u;for(e=0;e>6|192;C[n++]=t&63|128}else if((t&64512)===55296&&((r=a.charCodeAt(e+1))&64512)===56320){t=65536+((t&1023)<<10)+(r&1023);e++;C[n++]=t>>18|240;C[n++]=t>>12&63|128;C[n++]=t>>6&63|128;C[n++]=t&63|128}else{C[n++]=t>>12|224;C[n++]=t>>6&63|128;C[n++]=t&63|128}}o=n-S-u}else{o=c(a,S+u,e)}if(o<24){C[S++]=96|o}else if(o<256){if(u<2){C.copyWithin(S+2,S+1,S+1+o)}C[S++]=120;C[S++]=o}else if(o<65536){if(u<3){C.copyWithin(S+3,S+2,S+2+o)}C[S++]=121;C[S++]=o>>8;C[S++]=o&255}else{if(u<5){C.copyWithin(S+5,S+3,S+3+o)}C[S++]=122;Lt.setUint32(S,o);S+=4}S+=o}else if(e==="number"){if(!this.alwaysUseFloat&&a>>>0===a){if(a<24){C[S++]=a}else if(a<256){C[S++]=24;C[S++]=a}else if(a<65536){C[S++]=25;C[S++]=a>>8;C[S++]=a&255}else{C[S++]=26;Lt.setUint32(S,a);S+=4}}else if(!this.alwaysUseFloat&&a>>0===a){if(a>=-24){C[S++]=31-a}else if(a>=-256){C[S++]=56;C[S++]=~a}else if(a>=-65536){C[S++]=57;Lt.setUint16(S,~a);S+=2}else{C[S++]=58;Lt.setUint32(S,~a);S+=4}}else{let t;if((t=this.useFloat32)>0&&a<4294967296&&a>=-2147483648){C[S++]=250;Lt.setFloat32(S,a);let e;if(t<4||(e=a*Ft[(C[S]&127)<<1|C[S+1]>>7])>>0===e){S+=4;return}else S--}C[S++]=251;Lt.setFloat64(S,a);S+=8}}else if(e==="object"){if(!a)C[S++]=246;else{if(n){let t=n.get(a);if(t){C[S++]=216;C[S++]=29;C[S++]=25;if(!t.references){let e=n.idsToInsert||(n.idsToInsert=[]);t.references=[];e.push(t)}t.references.push(S-s);S+=2;return}else n.set(a,{offset:S-s})}let e=a.constructor;if(e===Object){b(a,true)}else if(e===Array){o=a.length;if(o<24){C[S++]=128|o}else{Jt(o)}for(let e=0;e>8;C[S++]=o&255}else{C[S++]=186;Lt.setUint32(S,o);S+=4}if(u.keyMap){for(let[e,t]of a){g(u.encodeKey(e));g(t)}}else{for(let[e,t]of a){g(e);g(t)}}}else{for(let r=0,e=Ot.length;r>8;C[S++]=t&255}else if(t>-1){C[S++]=218;Lt.setUint32(S,t);S+=4}e.encode.call(this,a,g,w);return}}if(a[Symbol.iterator]){if(Tt){let e=new Error("Iterable should be serialized as iterator");e.iteratorNotHandled=true;throw e}C[S++]=159;for(let e of a){g(e)}C[S++]=255;return}if(a[Symbol.asyncIterator]||Ht(a)){let e=new Error("Iterable/blob should be serialized as iterator");e.iteratorNotHandled=true;throw e}if(this.useToJSON&&a.toJSON){const t=a.toJSON();if(t!==a)return g(t)}b(a,!a.hasOwnProperty)}}}else if(e==="boolean"){C[S++]=a?245:244}else if(e==="bigint"){if(a=0){C[S++]=27;Lt.setBigUint64(S,a)}else if(a>-(BigInt(1)<{let t=Object.keys(e);let r=Object.values(e);let n=t.length;if(n<24){C[S++]=160|n}else if(n<256){C[S++]=184;C[S++]=n}else if(n<65536){C[S++]=185;C[S++]=n>>8;C[S++]=n&255}else{C[S++]=186;Lt.setUint32(S,n);S+=4}if(u.keyMap){for(let e=0;e{C[S++]=185;let e=S-s;S+=2;let n=0;if(u.keyMap){for(let e in t)if(r||t.hasOwnProperty(e)){g(u.encodeKey(e));g(t[e]);n++}}else{for(let e in t)if(r||t.hasOwnProperty(e)){g(e);g(t[e]);n++}}C[e+++s]=n>>8;C[e+s]=n&255}:(t,r)=>{let n,i=l.transitions||(l.transitions=Object.create(null));let u=0;let a=0;let o;let s;if(this.keyMap){s=Object.keys(t).map(e=>this.encodeKey(e));a=s.length;for(let t=0;t>8|224;C[S++]=c&255}else{if(!s)s=i.__keys__||(i.__keys__=Object.keys(t));if(o===undefined){c=l.nextId++;if(!c){c=0;l.nextId=1}if(c>=Pt){l.nextId=(c=h)+1}}else{c=o}l[c]=s;if(c>8|224;C[S++]=c&255;i=l.transitions;for(let e=0;e=Pt-h)v.shift()[zt]=undefined;v.push(i);Jt(a+2);g(57344+c);g(s);if(r===null)return;for(let e in t)if(r||t.hasOwnProperty(e))g(t[e]);return}}if(a<24){C[S++]=128|a}else{Jt(a)}if(r===null)return;for(let e in t)if(r||t.hasOwnProperty(e))g(t[e])};const w=e=>{let t;if(e>16777216){if(e-s>Nt)throw new Error("Encoded buffer would be larger than maximum buffer size");t=Math.min(Nt,Math.round(Math.max((e-s)*(e>67108864?1.25:2),4194304)/4096)*4096)}else t=(Math.max(e-s<<2,C.length-1)>>12)+1<<12;let r=new Bt(t);Lt=new DataView(r.buffer,0,t);if(C.copy)C.copy(r,0,s,e);else r.set(C.slice(s,e));S-=s;s=0;Mt=r.length-10;return C=r};let D=100;let x=1e3;this.encodeAsIterable=function(e,t){return k(e,t,E)};this.encodeAsAsyncIterable=function(e,t){return k(e,t,O)};function*E(n,i,e){let t=n.constructor;if(t===Object){let r=u.useRecords!==false;if(r)b(n,null);else $t(Object.keys(n).length,160);for(let t in n){let e=n[t];if(!r)g(t);if(e&&typeof e==="object"){if(i[t])yield*E(e,i[t]);else yield*F(e,i,t)}else g(e)}}else if(t===Array){let e=n.length;Jt(e);for(let t=0;tD)){if(i.element)yield*E(e,i.element);else yield*F(e,i,"element")}else g(e)}}else if(n[Symbol.iterator]){C[S++]=159;for(let e of n){if(e&&(typeof e==="object"||S-s>D)){if(i.element)yield*E(e,i.element);else yield*F(e,i,"element")}else g(e)}C[S++]=255}else if(Ht(n)){$t(n.size,64);yield C.subarray(s,S);yield n;A()}else if(n[Symbol.asyncIterator]){C[S++]=159;yield C.subarray(s,S);yield n;A();C[S++]=255}else{g(n)}if(e&&S>s)yield C.subarray(s,S);else if(S-s>D){yield C.subarray(s,S);A()}}function*F(t,r,n){let i=S-s;try{g(t);if(S-s>D){yield C.subarray(s,S);A()}}catch(e){if(e.iteratorNotHandled){r[n]={};S=s+i;yield*E.call(this,t,r[n])}else throw e}}function A(){D=x;u.encode(null,ur)}function k(e,t,r){if(t&&t.chunkThreshold)D=x=t.chunkThreshold;else D=100;if(e&&typeof e==="object"){u.encode(null,ur);return r(e,u.iterateProperties||(u.iterateProperties={}),true)}return[u.encode(e)]}async function*O(e,t){for(let r of E(e,t,true)){let e=r.constructor;if(e===It||e===Uint8Array)yield r;else if(Ht(r)){let e=r.stream().getReader();let t;while(!(t=await e.read()).done){yield t.value}}else if(r[Symbol.asyncIterator]){for await(let e of r){A();if(e)yield*O(e,t.async||(t.async={}));else yield u.encode(e)}}else{yield r}}}}useBuffer(e){C=e;Lt=new DataView(C.buffer,C.byteOffset,C.byteLength);S=0}clearSharedData(){if(this.structures)this.structures=[];if(this.sharedValues)this.sharedValues=undefined}updateSharedData(){let t=this.sharedVersion||0;this.sharedVersion=t+1;let e=this.structures.slice(0);let r=new Yt(e,this.sharedValues,this.sharedVersion);let n=this.saveShared(r,e=>(e&&e.version||0)==t);if(n===false){r=this.getShared()||{};this.structures=r.structures||[];this.sharedValues=r.packedValues;this.sharedVersion=r.version;this.structures.nextId=this.structures.length}else{e.forEach((e,t)=>this.structures[t]=e)}return n}}function $t(e,t){if(e<24)C[S++]=t|e;else if(e<256){C[S++]=t|24;C[S++]=e}else if(e<65536){C[S++]=t|25;C[S++]=e>>8;C[S++]=e&255}else{C[S++]=t|26;Lt.setUint32(S,e);S+=4}}class Yt{constructor(e,t,r){this.structures=e;this.packedValues=t;this.version=r}}function Jt(e){if(e<24)C[S++]=128|e;else if(e<256){C[S++]=152;C[S++]=e}else if(e<65536){C[S++]=153;C[S++]=e>>8;C[S++]=e&255}else{C[S++]=154;Lt.setUint32(S,e);S+=4}}const Kt=typeof Blob==="undefined"?function(){}:Blob;function Ht(e){if(e instanceof Kt)return true;let t=e[Symbol.toStringTag];return t==="Blob"||t==="File"}function Gt(r,n){switch(typeof r){case"string":if(r.length>3){if(n.objectMap[r]>-1||n.values.length>=n.maxValues)return;let e=n.get(r);if(e){if(++e.count==2){n.values.push(r)}}else{n.set(r,{count:1});if(n.samplingPackedValues){let e=n.samplingPackedValues.get(r);if(e)e.count++;else n.samplingPackedValues.set(r,{count:1})}}}break;case"object":if(r){if(r instanceof Array){for(let e=0,t=r.length;e=0&&r<4294967296){C[S++]=26;Lt.setUint32(S,r);S+=4}else{C[S++]=251;Lt.setFloat64(S,r);S+=8}}},{tag:258,encode(e,t){let r=Array.from(e);t(r)}},{tag:27,encode(e,t){t([e.name,e.message])}},{tag:27,encode(e,t){t(["RegExp",e.source,e.flags])}},{getTag(e){return e.tag},encode(e,t){t(e.value)}},{encode(e,t,r){Zt(e,r)}},{getTag(e){if(e.constructor===Uint8Array){if(this.tagUint8Array||jt&&this.tagUint8Array!==false)return 64}},encode(e,t,r){Zt(e,r)}},Qt(68,1),Qt(69,2),Qt(70,4),Qt(71,8),Qt(72,1),Qt(77,2),Qt(78,4),Qt(79,8),Qt(85,4),Qt(86,8),{encode(t,n){let e=t.packedValues||[];let r=t.structures||[];if(e.values.length>0){C[S++]=216;C[S++]=51;Jt(4);let r=e.values;n(r);Jt(0);Jt(0);packedObjectMap=Object.create(sharedPackedObjectMap||null);for(let e=0,t=r.length;e1)e-=4;return{tag:e,encode:function e(t,r){let n=t.byteLength;let i=t.byteOffset||0;let u=t.buffer||t;r(jt?St.from(u,i,n):new Uint8Array(u,i,n))}}}function Zt(e,t){let r=e.byteLength;if(r<24){C[S++]=64+r}else if(r<256){C[S++]=88;C[S++]=r}else if(r<65536){C[S++]=89;C[S++]=r>>8;C[S++]=r&255}else{C[S++]=90;Lt.setUint32(S,r);S+=4}if(S+r>=C.length){t(S+r)}C.set(e.buffer?e:new Uint8Array(e),S);S+=r}function Xt(n,e){let r;let i=e.length*2;let u=n.length-i;e.sort((e,t)=>e.offset>t.offset?1:-1);for(let r=0;r>8;n[e]=r&255}}while(r=e.pop()){let e=r.offset;n.copyWithin(e+i,e,u);i-=2;let t=e+i;n[t++]=216;n[t++]=28;u=e}return n}function er(e,t){Lt.setUint32(Rt.position+e,S-Rt.position-e+1);let r=Rt;Rt=null;t(r[0]);t(r[1])}function tr(e){if(e.Class){if(!e.encode)throw new Error("Extension has no encode function");Ct.unshift(e.Class);Ot.unshift(e)}Et(e)}let rr=new Vt({useRecords:false});rr.encode;rr.encodeAsIterable;rr.encodeAsAsyncIterable;const nr=512;const ir=1024;const ur=2048;var ar={}; /**@license * * No Dependency fast and small LZJB Compression for Browser and Node @@ -42,4 +42,4 @@ * Released under BSD-3-Clause License * * build: Wed, 27 Oct 2021 10:43:10 GMT - */Object.defineProperty(ar,"__esModule",{value:true});const or=8,sr=6,cr=3,fr=(1<r-fr){t[i++]=e[n++];continue}f=(e[n]+13^e[n+1]-13^e[n+2])&hr-1;c=n-l[f]&lr;l[f]=n;u=n-c;if(u>=0&&u!=n&&e[n]==e[u]&&e[n+1]==e[u+1]&&e[n+2]==e[u+2]){t[a]|=o;for(s=cr;s>or;t[i++]=c;n+=s}else{t[i++]=e[n++]}}console.assert(e.length>=n);return i}function pr(e,t,r){t=t|0;var n=0,i=0,u=0,a=0,o=1<<(or-1|0),s=0,c=0;while(n>(or-sr|0))+cr|0;c=(e[n]<4){r[i]=r[u];i=i+1|0;u=u+1|0;r[i]=r[u];i=i+1|0;u=u+1|0;r[i]=r[u];i=i+1|0;u=u+1|0;r[i]=r[u];i=i+1|0;u=u+1|0;s=s-4|0}while(s>0){r[i]=r[u];i=i+1|0;u=u+1|0;s=s-1|0}}}else{r[i]=e[n];i=i+1|0;n=n+1|0}}return i}function dr(){const e=new TextEncoder("utf-8");return e.encode(vr)}const vr="@lzjb";const mr=dr();function yr(...e){if(e.length>1){const r=e.reduce((e,t)=>e+t.length,0);const n=new Uint8Array(r);let t=0;e.forEach(e=>{n.set(e,t);t+=e.length});return n}else if(e.length){return e[0]}}function gr(t){const e=Math.ceil(Math.log2(t)/8);const r=new Uint8Array(e);for(let e=0;e=0;e--){r=r*256+t[e]}return r}function wr(e,{magic:t=true}={}){const r=new Uint8Array(Math.max(e.length*1.5|0,16*1024));const n=_r(e,r);const i=gr(e.length);const u=[Uint8Array.of(i.length),i,r.slice(0,n)];if(t){u.unshift(mr)}return yr(...u)}function Dr(t,{magic:e=true}={}){if(e){const e=new TextDecoder("utf-8");const s=e.decode(t.slice(0,mr.length));if(s!==vr){throw new Error("Invalid magic value")}}const r=e?mr.length:0;const n=t[r];const i=r+1;const u=r+n+1;const a=br(t.slice(i,u));t=t.slice(u);const o=new Uint8Array(a);pr(t,t.length,o);return o}var xr=ar.pack=wr;var Er=ar.unpack=Dr;function Fr(s,c){return c=c||{},new Promise(function(e,t){var r=new XMLHttpRequest,n=[],i=[],u={},a=function(){return{ok:2==(r.status/100|0),statusText:r.statusText,status:r.status,url:r.responseURL,text:function(){return Promise.resolve(r.responseText)},json:function(){return Promise.resolve(r.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([r.response]))},clone:a,headers:{keys:function(){return n},entries:function(){return i},get:function(e){return u[e.toLowerCase()]},has:function(e){return e.toLowerCase()in u}}}};for(var o in r.open(c.method||"get",s,!0),r.onload=function(){r.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,t,r){n.push(t=t.toLowerCase()),i.push([t,r]),u[t]=u[t]?u[t]+","+r:r}),e(a())},r.onerror=t,r.withCredentials="include"==c.credentials,c.headers)r.setRequestHeader(o,c.headers[o]);r.send(c.body||null)})}var t;var Ar=["token"],kr=["env"],Or=["stderr","stdin","stdout","command_line"],Cr=["use_dynamic"],Sr=["use_dynamic"],jr=["env","dynamic_env","use_dynamic","error"];function Br(e,t,r){Ir(e,t);t.set(e,r)}function Ir(e,t){if(t.has(e)){throw new TypeError("Cannot initialize the same private elements twice on an object")}}function Pr(e,t,r){return t=k(t),M(e,Nr()?Reflect.construct(t,r||[],k(e).constructor):t.apply(e,r))}function Nr(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Nr=function e(){return!!t})()}function Tr(t,e){var r=typeof Symbol!=="undefined"&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=Lr(t))||e&&t&&typeof t.length==="number"){if(r)t=r;var n=0;var i=function e(){};return{s:i,n:function e(){if(n>=t.length)return{done:true};return{done:false,value:t[n++]}},e:function e(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u=true,a=false,o;return{s:function e(){r=r.call(t)},n:function e(){var t=r.next();u=t.done;return t},e:function e(t){a=true;o=t},f:function e(){try{if(!u&&r["return"]!=null)r["return"]()}finally{if(a)throw o}}}}function Lr(e,t){if(!e)return;if(typeof e==="string")return Mr(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor)r=e.constructor.name;if(r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return Mr(e,t)}function Mr(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r1?r-1:0),i=1;i0&&arguments[0]!==undefined?arguments[0]:null;var t=xo&&xo.get("DEBUG",{throwError:false});if(e===null){return t===true}return(t===null||t===void 0?void 0:t.valueOf())===e.valueOf()}function Qr(e){return e?"(?:#".concat(e,"(?:#[ie])?|#[ie]#").concat(e,")"):"(?:#[ie])?"}function Zr(e,t){return"".concat(Qr(e),"[+-]?").concat(t,"+/").concat(t,"+")}function Xr(e,t){return"".concat(Qr(e),"(?:[+-]?(?:").concat(t,"+/").concat(t,"+|nan.0|inf.0|").concat(t,"+))?(?:[+-]i|[+-]?(?:").concat(t,"+/").concat(t,"+|").concat(t,"+|nan.0|inf.0)i)(?=[()[\\]\\s]|$)")}function en(e,t){return"".concat(Qr(e),"[+-]?").concat(t,"+")}var tn=/^#\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimyus]*)$/;var rn="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)";var nn="(?:#[ie])?(?:[+-]?(?:[0-9][0-9_]*/[0-9][0-9_]*|nan.0|inf.0|".concat(rn,"|[+-]?[0-9]+))?(?:").concat(rn,"|[+-](?:[0-9]+/[0-9]+|[0-9]+|nan.0|inf.0))i");var un=new RegExp("^(#[ie])?".concat(rn,"$"),"i");function an(e,t){var r=e==="x"?"(?!\\+|".concat(t,")"):"(?!\\.|".concat(t,")");var n="";if(e===""){n="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+(?![0-9]))(?:[eE][-+]?[0-9]+)?))"}return new RegExp("^((?:(?:".concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(t,"+/").concat(t,"+(?!").concat(t,")|[+-]?").concat(t,"+)").concat(r,")?)(").concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(t,"+/").concat(t,"+|[+-]?").concat(t,"+|[+-])i$"),"i")}var on=function(){var u={};[[10,"","[0-9]"],[16,"x","[0-9a-fA-F]"],[8,"o","[0-7]"],[2,"b","[01]"]].forEach(function(e){var t=b(e,3),r=t[0],n=t[1],i=t[2];u[r]=an(n,i)});return u}();var sn={alarm:"",backspace:"\b",delete:"",escape:"",newline:"\n",null:"\0",return:"\r",space:" ",tab:"\t",dle:"",soh:"",dc1:"",stx:"",dc2:"",etx:"",dc3:"",eot:"",dc4:"",enq:"",nak:"",ack:"",syn:"",bel:"",etb:"",bs:"\b",can:"",ht:"\t",em:"",lf:"\n",sub:"",vt:"\v",esc:"",ff:"\f",fs:"",cr:"\r",gs:"",so:"",rs:"",si:"",us:"",del:""};function cn(e){var t=[];var r=0;var n=e.length;while(r=55296&&i<=56319&&r1&&arguments[1]!==undefined?arguments[1]:10;var r=En(e);var n=r.number.split("/");var i=w({num:j([n[0],r.radix||t]),denom:j([n[1],r.radix||t])});if(r.inexact){return i.valueOf()}else{return i}}function An(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;var r=En(e);if(r.inexact){return g(parseInt(r.number,r.radix||t))}return j([r.number,r.radix||t])}function kn(e){var t=e.match(/#\\x([0-9a-f]+)$/i);var r;if(t){var n=parseInt(t[1],16);r=String.fromCodePoint(n)}else{t=e.match(/#\\([\s\S]+)$/);if(t){r=t[1]}}if(r){return h(r)}throw new Error("Parse: invalid character")}function On(e){var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;function t(e){var t;if(e==="+"){t=j(1)}else if(e==="-"){t=j(-1)}else if(e.match(gn)){t=j([e,i])}else if(e.match(bn)){var r=e.split("/");t=w({num:j([r[0],i]),denom:j([r[1],i])})}else if(e.match(un)){var n=Bn(e);if(u.exact){return n.toRational()}return n}else if(e.match(/nan.0$/)){return j(NaN)}else if(e.match(/inf.0$/)){if(e[0]==="-"){return j(Number.NEGATIVE_INFINITY)}return j(Number.POSITIVE_INFINITY)}else{throw new Error("Internal Parser Error")}if(u.inexact){return g(t.valueOf())}return t}var u=En(e);i=u.radix||i;var r;var n=u.number.match(Dn);if(i!==10&&n){r=n}else{r=u.number.match(on[i])}var a,o;o=t(r[2]);if(r[1]){a=t(r[1])}else if(o instanceof g){a=g(0)}else{a=j(0)}if(o.cmp(0)===0&&o.__type__==="bigint"){return a}return y({im:o,re:a})}function Cn(e){return parseInt(e.toString(),10)===e}function Sn(e){var t=e.match(/^(([-+]?[0-9]*)(?:\.([0-9]+))?)e([-+]?[0-9]+)/i);if(t){var r=parseInt(t[4],10);var n;var i=t[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var u=t[3]&&t[3].length;if(i0&&(t.exact||!t.number.match(/\./))){return j(u).mul(o)}}}r=g(r);if(t.exact){return r.toRational()}return r}function In(e){e=e.replace(/\\x([0-9a-f]+);/gi,function(e,t){return"\\u"+t.padStart(4,"0")}).replace(/\n/g,"\\n");var t=e.match(/(\\*)(\\x[0-9A-F])/i);if(t&&t[1].length%2===0){throw new Error("Invalid string literal, unclosed ".concat(t[2]))}try{var r=x(JSON.parse(e));r.freeze();return r}catch(e){var n=e.message.replace(/in JSON /,"").replace(/.*Error: /,"");throw new Error("Invalid string literal: ".concat(n))}}function Pn(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var r={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,t){return String.fromCharCode(parseInt("0"+t,16))}).replace(/\\(.)/g,function(e,t){return r[t]||t})}return new $(e)}function Nn(e){if(Do.hasOwnProperty(e)){return Do[e]}if(e.match(/^"[\s\S]*"$/)){return In(e)}else if(e[0]==="#"){var t=e.match(tn);if(t){return new RegExp(t[1],t[2])}else if(e.match(_n)){return kn(e)}var r=e.match(/#\\(.+)/);if(r&&cn(r[1]).length===1){return kn(e)}}if(e.match(/[0-9a-f]|[+-]i/i)){if(e.match(yn)){return An(e)}else if(e.match(un)){return Bn(e)}else if(e.match(mn)){return Fn(e)}else if(e.match(vn)){return On(e)}}if(e.match(/^#[iexobd]/)){throw new Error("Invalid numeric constant: "+e)}return Pn(e)}function Tn(e){return!(["(",")","[","]"].includes(e)||ri.names().includes(e))}function Ln(e){return Tn(e)&&!(e.match(tn)||e.match(/^"[\s\S]*"$/)||e.match(yn)||e.match(un)||e.match(vn)||e.match(mn)||e.match(_n)||["#t","#f","nil"].includes(e))}var Mn=/"(?:\\[\S\s]|[^"])*"?/g;function Rn(e){if(typeof e==="string"){var t=/([-\\^$[\]()+{}?*.|])/g;return e.replace(t,"\\$1")}return e}function qn(){this.data=[]}qn.prototype.push=function(e){this.data.push(e)};qn.prototype.top=function(){return this.data[this.data.length-1]};qn.prototype.pop=function(){return this.data.pop()};qn.prototype.is_empty=function(){return!this.data.length};function Un(e){if(e instanceof x){e=e.valueOf()}var t=new s(e,{whitespace:true});var r=[];while(true){var n=t.peek(true);if(n===oo){break}r.push(n);t.skip()}return r}function zn(e){var t=e.token,r=le(e,Ar);if(t.match(/^"[\s\S]*"$/)&&t.match(/\n/)){var n=new RegExp("^ {1,"+(e.col+1)+"}","mg");t=t.replace(n,"")}return z({token:t},r)}function Vn(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(){};this.fn=e;this.cont=t}Vn.prototype.toString=function(){return"#"};function $n(n){return function(){for(var e=arguments.length,t=new Array(e),r=0;r1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof x){e=e.toString()}if(t){return Un(e)}else{var r=Un(e).map(function(e){if(e.token==="#\\ "||e.token=="#\\\n"){return e.token}return e.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return Kn(r)}}function Kn(e){var t=0;var r=null;var n=[];for(var i=0;i0&&arguments[0]!==undefined?arguments[0]:null;if(e instanceof $){if(e.is_gensym()){return e}e=e.valueOf()}if(Wn(e)){return $(e)}if(e!==null){return r(e,Symbol("#:".concat(e)))}t++;return r(t,Symbol("#:g".concat(t)))}}();function Zn(e){var r=this;var n={pending:true,rejected:false,fulfilled:false,reason:undefined,type:undefined};e=e.then(function(e){n.type=qo(e);n.fulfilled=true;n.pending=false;return e});c(this,"_promise",e,{hidden:true});if(d(e["catch"])){e=e["catch"](function(e){n.rejected=true;n.pending=false;n.reason=e})}Object.keys(n).forEach(function(t){Object.defineProperty(r,"__".concat(t,"__"),{enumerable:true,get:function e(){return n[t]}})});c(this,"__promise__",e);this.then=false}Zn.prototype.then=function(e){return new Zn(this.valueOf().then(e))};Zn.prototype["catch"]=function(e){return new Zn(this.valueOf()["catch"](e))};Zn.prototype.valueOf=function(){if(!this._promise){throw new Error("QuotedPromise: invalid promise created")}return this._promise};Zn.prototype.toString=function(){if(this.__pending__){return Zn.pending_str}if(this.__rejected__){return Zn.rejected_str}return"#")};Zn.pending_str="#";Zn.rejected_str="#";function Xn(e){if(Array.isArray(e)){return Promise.all(ei(e)).then(ti)}return e}function ei(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof Zn){t[r]=new ho(n)}else{t[r]=n}}return t}function ti(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof ho){t[r]=n.valueOf()}else{t[r]=n}}return t}var ri={LITERAL:Symbol["for"]("literal"),SPLICE:Symbol["for"]("splice"),SYMBOL:Symbol["for"]("symbol"),names:function e(){return Object.keys(this.__list__)},type:function e(t){try{return this.get(t).type}catch(e){console.log({name:t});console.log(e);return null}},get:function e(t){return this.__list__[t]},off:function e(t){var r=this;var n=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(Array.isArray(t)){t.forEach(function(e){return r.off(e,n)})}else if(n===null){delete this.__events__[t]}else{this.__events__=this.__events__.filter(function(e){return e!==n})}},on:function e(t,r){var n=this;if(Array.isArray(t)){t.forEach(function(e){return n.on(e,r)})}else if(!this.__events__[t]){this.__events__[t]=[r]}else{this.__events__[t].push(r)}},trigger:function e(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i",new $("quote-promise"),ri.LITERAL]];var si=oi.map(function(e){return e[0]});Object.freeze(si);Object.defineProperty(ri,"__builtins__",{writable:false,value:si});oi.forEach(function(e){var t=b(e,3),r=t[0],n=t[1],i=t[2];ri.append(r,n,i)});var s=function(){function _(e){var t=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=r.whitespace,i=n===void 0?false:n;ue(this,_);c(this,"__input__",e.replace(/\r/g,""));var u={};["_i","_whitespace","_col","_newline","_line","_state","_next","_token","_prev_char"].forEach(function(r){Object.defineProperty(t,r,{configurable:false,enumerable:false,get:function e(){return u[r]},set:function e(t){u[r]=t}})});this._whitespace=i;this._i=this._line=this._col=this._newline=0;this._state=this._next=this._token=null;this._prev_char=""}ce(_,[{key:"get",value:function e(t){return this.__internal[t]}},{key:"set",value:function e(t,r){this.__internal[t]=r}},{key:"token",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(t){var r=this._line;if(this._whitespace&&this._token==="\n"){--r}return{token:this._token,col:this._col,offset:this._i,line:r}}return this._token}},{key:"peek",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(this._i>=this.__input__.length){return oo}if(this._token){return this.token(t)}var r=this.next_token();if(r){this._token=this.__input__.substring(this._i,this._next);return this.token(t)}return oo}},{key:"skip",value:function e(){if(this._next!==null){this._token=null;this._i=this._next}}},{key:"read_line",value:function e(){var t=this.__input__.length;if(this._i>=t){return oo}for(var r=this._i;r=r){return oo}if(t+this._i>=r){return this.read_rest()}var n=this._i+t;var i=this.__input__.substring(this._i,n);var u=i.match(/\n/g);if(u){this._line+=u.length}this._i=n;return i}},{key:"peek_char",value:function e(){if(this._i>=this.__input__.length){return oo}return h(this.__input__[this._i])}},{key:"read_char",value:function e(){var t=this.peek_char();this.skip_char();return t}},{key:"skip_char",value:function e(){if(this._i1&&arguments[1]!==undefined?arguments[1]:{},n=r.prev_char,i=r["char"],u=r.next_char;var a=b(t,4),o=a[0],s=a[1],c=a[2],f=a[3];if(t.length!==5){throw new Error("Lexer: Invalid rule of length ".concat(t.length))}if(Su(o)){if(o!==i){return false}}else if(!i.match(o)){return false}if(!li(s,n)){return false}if(!li(c,u)){return false}if(f!==this._state){return false}return true}},{key:"next_token",value:function e(){if(this._i>=this.__input__.length){return false}var t=true;e:for(var r=this._i,n=this.__input__.length;r2&&arguments[2]!==undefined?arguments[2]:null;var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;if(t.length===0){throw new Error("Lexer: invalid literal rule")}if(t.length===1){return[[t,n,i,null,null]]}var u=[];for(var a=0,o=t.length;a1&&arguments[1]!==undefined?arguments[1]:{},r=t.env,n=t.meta,i=n===void 0?false:n,u=t.formatter,a=u===void 0?zn:u;ue(this,o);if(e instanceof x){e=e.toString()}c(this,"_formatter",a,{hidden:true});c(this,"__lexer__",new s(e));c(this,"__env__",r);c(this,"_meta",i,{hidden:true});c(this,"_refs",[],{hidden:true});c(this,"_state",{parentheses:0,fold_case:false},{hidden:true})}ce(o,[{key:"resolve",value:function e(t){return this.__env__&&this.__env__.get(t,{throwError:false})}},{key:"peek",value:function(){var e=ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=this.__lexer__.peek(true);if(!(r===oo)){t.next=4;break}return t.abrupt("return",oo);case 4:if(!this.is_comment(r.token)){t.next=7;break}this.skip();return t.abrupt("continue",0);case 7:if(!Ou(r.token)){t.next=11;break}this.skip();if(r.token==="#!fold-case"){this._state.fold_case=true}else if(r.token==="#!no-fold-case"){this._state.fold_case=false}return t.abrupt("continue",0);case 11:if(!(r.token==="#;")){t.next=18;break}this.skip();if(!(this.__lexer__.peek()===oo)){t.next=15;break}throw new Error("Lexer: syntax error eof found after comment");case 15:t.next=17;return this._read_object();case 17:return t.abrupt("continue",0);case 18:return t.abrupt("break",21);case 21:r=this._formatter(r);if(this._state.fold_case){r.token=Yi(r.token)}if(!this._meta){t.next=25;break}return t.abrupt("return",r);case 25:return t.abrupt("return",r.token);case 26:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"reset",value:function e(){this._refs.length=0}},{key:"skip",value:function e(){this.__lexer__.skip()}},{key:"read",value:function(){var e=ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return this.peek();case 2:r=t.sent;this.skip();return t.abrupt("return",r);case 5:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"match_datum_label",value:function e(t){var r=t.match(/^#([0-9]+)=$/);return r&&r[1]}},{key:"match_datum_ref",value:function e(t){var r=t.match(/^#([0-9]+)#$/);return r&&r[1]}},{key:"is_open",value:function e(t){var r=["(","["].includes(t);if(r){this._state.parentheses++}return r}},{key:"is_close",value:function e(t){var r=[")","]"].includes(t);if(r){this._state.parentheses--}return r}},{key:"read_list",value:function(){var e=ie(O.mark(function e(){var r,n,i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=Y,n=r;case 1:t.next=4;return this.peek();case 4:u=t.sent;if(!(u===oo)){t.next=7;break}return t.abrupt("break",32);case 7:if(!this.is_close(u)){t.next=10;break}this.skip();return t.abrupt("break",32);case 10:if(!(u==="."&&!H(r))){t.next=18;break}this.skip();t.next=14;return this._read_object();case 14:n.cdr=t.sent;i=true;t.next=30;break;case 18:if(!i){t.next=22;break}throw new Error("Parser: syntax error more than one element after dot");case 22:t.t0=J;t.next=25;return this._read_object();case 25:t.t1=t.sent;t.t2=Y;a=new t.t0(t.t1,t.t2);if(H(r)){r=a}else{n.cdr=a}n=a;case 30:t.next=1;break;case 32:return t.abrupt("return",r);case 33:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"read_value",value:function(){var e=ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return this.read();case 2:r=t.sent;if(!(r===oo)){t.next=5;break}throw new Error("Parser: Expected token eof found");case 5:return t.abrupt("return",Nn(r));case 6:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"is_comment",value:function e(t){return t.match(/^;/)||t.match(/^#\|/)&&t.match(/\|#$/)}},{key:"evaluate",value:function e(t){return A(t,{env:this.__env__,error:function e(t){throw t}})}},{key:"read_object",value:function(){var e=ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:this.reset();t.next=3;return this._read_object();case 3:r=t.sent;if(r instanceof _i){r=r.valueOf()}if(!this._refs.length){t.next=7;break}return t.abrupt("return",D(this._resolve_object(r),function(e){if(G(e)){e.mark_cycles()}return e}));case 7:return t.abrupt("return",r);case 8:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"balanced",value:function e(){return this._state.parentheses===0}},{key:"ballancing_error",value:function e(t,r){var n=this._state.parentheses;var i;if(n<0){i=new Error("Parser: unexpected parenthesis");i.__code__=[r.toString()+")"]}else{i=new Error("Parser: expected parenthesis but eof found");var u=new RegExp("\\){".concat(n,"}$"));i.__code__=[t.toString().replace(u,"")]}throw i}},{key:"_resolve_object",value:function(){var t=ie(O.mark(function e(r){var n=this;var i;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!Array.isArray(r)){t.next=2;break}return t.abrupt("return",r.map(function(e){return n._resolve_object(e)}));case 2:if(!Qi(r)){t.next=6;break}i={};Object.keys(r).forEach(function(e){i[e]=n._resolve_object(r[e])});return t.abrupt("return",i);case 6:if(!G(r)){t.next=8;break}return t.abrupt("return",this._resolve_pair(r));case 8:return t.abrupt("return",r);case 9:case"end":return t.stop()}},e,this)}));function e(e){return t.apply(this,arguments)}return e}()},{key:"_resolve_pair",value:function(){var t=ie(O.mark(function e(r){return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!G(r)){t.next=15;break}if(!(r.car instanceof _i)){t.next=7;break}t.next=4;return r.car.valueOf();case 4:r.car=t.sent;t.next=8;break;case 7:this._resolve_pair(r.car);case 8:if(!(r.cdr instanceof _i)){t.next=14;break}t.next=11;return r.cdr.valueOf();case 11:r.cdr=t.sent;t.next=15;break;case 14:this._resolve_pair(r.cdr);case 15:return t.abrupt("return",r);case 16:case"end":return t.stop()}},e,this)}));function e(e){return t.apply(this,arguments)}return e}()},{key:"_read_object",value:function(){var e=ie(O.mark(function e(){var r,n,i,u,a,o,s,c,f,l,h;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return this.peek();case 2:r=t.sent;if(!(r===oo)){t.next=5;break}return t.abrupt("return",r);case 5:if(!ni(r)){t.next=38;break}n=ri.get(r);i=ii(r);this.skip();a=ai(r);if(!a){t.next=14;break}t.t0=undefined;t.next=17;break;case 14:t.next=16;return this._read_object();case 16:t.t0=t.sent;case 17:o=t.t0;if(i){t.next=25;break}s=this.__env__.get(n.symbol);if(!(typeof s==="function")){t.next=25;break}if(ui(r)){c=[o]}else if(H(o)){c=[]}else if(G(o)){c=o.to_array(false)}if(!(c||a)){t.next=24;break}return t.abrupt("return",Jo(s,a?[]:c,{env:this.__env__,dynamic_env:this.__env__,use_dynamic:false}));case 24:throw new Error("Parse Error: Invalid parser extension "+"invocation ".concat(n.symbol));case 25:if(ui(r)){u=new J(n.symbol,new J(o,Y))}else{u=new J(n.symbol,o)}if(!i){t.next=28;break}return t.abrupt("return",u);case 28:if(!(s instanceof K)){t.next=37;break}t.next=31;return this.evaluate(u);case 31:f=t.sent;if(!(G(f)||f instanceof $)){t.next=34;break}return t.abrupt("return",J.fromArray([$("quote"),f]));case 34:return t.abrupt("return",f);case 37:throw new Error("Parse Error: invalid parser extension: "+n.symbol);case 38:l=this.match_datum_ref(r);if(!(l!==null)){t.next=44;break}this.skip();if(!this._refs[l]){t.next=43;break}return t.abrupt("return",new _i(l,this._refs[l]));case 43:throw new Error("Parse Error: invalid datum label #".concat(l,"#"));case 44:h=this.match_datum_label(r);if(!(h!==null)){t.next=51;break}this.skip();this._refs[h]=this._read_object();return t.abrupt("return",this._refs[h]);case 51:if(!this.is_close(r)){t.next=55;break}this.skip();t.next=61;break;case 55:if(!this.is_open(r)){t.next=60;break}this.skip();return t.abrupt("return",this.read_list());case 60:return t.abrupt("return",this.read_value());case 61:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()}]);return o}();var _i=function(){function r(e,t){ue(this,r);this.name=e;this.data=t}ce(r,[{key:"valueOf",value:function e(){return this.data}}]);return r}();function pi(e,t){return di.apply(this,arguments)}function di(){di=ye(O.mark(function e(r,n){var i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!n){if(W){n=W.get("**interaction-environment**",{throwError:false})}else{n=xo}}i=new hi(r,{env:n});case 2:t.next=5;return ve(i.read_object());case 5:a=t.sent;if(!i.balanced()){i.ballancing_error(a,u)}if(!(a===oo)){t.next=9;break}return t.abrupt("break",14);case 9:u=a;t.next=12;return a;case 12:t.next=2;break;case 14:case"end":return t.stop()}},e)}));return di.apply(this,arguments)}function D(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(e){return e};var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;if(Mu(e)){var n=e.then(t);if(r===null){return n}else{return n["catch"](r)}}if(e instanceof Array){return vi(e,t,r)}if(Qi(e)){return mi(e,t,r)}return t(e)}function vi(t,r,e){if(t.find(Mu)){return D(Xn(t),function(e){if(Object.isFrozen(t)){Object.freeze(e)}return r(e)},e)}return r(t)}function mi(t,e,r){var i=Object.keys(t);var n=[],u=[];var a=i.length;while(a--){var o=i[a];var s=t[o];n[a]=s;if(Mu(s)){u.push(s)}}if(u.length){return D(Xn(n),function(e){var n={};e.forEach(function(e,t){var r=i[t];n[r]=e});if(Object.isFrozen(t)){Object.freeze(n)}return n},r)}return e(t)}function c(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{},i=n.hidden,u=i===void 0?false:i;Object.defineProperty(e,t,{value:r,configurable:true,enumerable:!u})}function yi(e){return gi.apply(this,arguments)}function gi(){gi=ie(O.mark(function e(r){var n,i,u,a,o,s,c;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:n=[];i=false;u=false;t.prev=3;o=qr(r);case 5:t.next=7;return o.next();case 7:if(!(i=!(s=t.sent).done)){t.next=13;break}c=s.value;n.push(c);case 10:i=false;t.next=5;break;case 13:t.next=19;break;case 15:t.prev=15;t.t0=t["catch"](3);u=true;a=t.t0;case 19:t.prev=19;t.prev=20;if(!(i&&o["return"]!=null)){t.next=24;break}t.next=24;return o["return"]();case 24:t.prev=24;if(!u){t.next=27;break}throw a;case 27:return t.finish(24);case 28:return t.finish(19);case 29:return t.abrupt("return",n);case 30:case"end":return t.stop()}},e,null,[[3,15,19,29],[20,,24,28]])}));return gi.apply(this,arguments)}function bi(e,t){if(t instanceof RegExp){return function(e){return String(e).match(t)}}else if(d(t)){return t}throw new Error("Invalid matcher")}function l(e,t,r,n){if(typeof e!=="string"){t=arguments[0];r=arguments[1];n=arguments[2];e=null}if(r){if(n){t.__doc__=r}else{t.__doc__=wi(r)}}if(e){t.__name__=e}else if(t.name&&!da(t)){t.__name__=t.name}return t}function wi(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function Di(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var r=e.length;if(t<=0){throw Error("previousSexp: Invalid argument sexp = ".concat(t))}e:while(t--&&r>=0){var n=1;while(n>0){var i=e[--r];if(!i){break e}if(i==="("||i.token==="("){n--}else if(i===")"||i.token===")"){n++}}r--}return e.slice(r+1)}function xi(e){if(!e||!e.length){return 0}var t=e.length;if(e[t-1].token==="\n"){return 0}while(--t){if(e[t].token==="\n"){var r=(e[t+1]||{}).token;if(r){return r.length}}}return 0}function Ei(e,t){return f(e,t)===t.length;function f(r,n){function e(e,t){var r=Tr(e),n;try{for(r.s();!(n=r.n()).done;){var i=n.value;var u=f(i,t);if(u!==-1){return u}}}catch(e){r.e(e)}finally{r.f()}return-1}function t(){return r[u]===Symbol["for"]("symbol")&&!Ln(n[o])}function i(){var e=r[u+1];var t=n[o+1];if(e!==undefined&&t!==undefined){return f([e],[t])}}var u=0;var a={};for(var o=0;o0){continue}}else if(t()){return-1}}else if(r[u]instanceof Array){var c=f(r[u],n.slice(o));if(c===-1||c+o>n.length){return-1}o+=c-1;u++;continue}else{return-1}u++}if(r.length!==u){return-1}return n.length}}function Fi(e){this.__code__=e.replace(/\r/g,"")}Fi.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?(?:define(?:-values|-syntax|-macro|-class|-record-type)?|(?:call-with-(?:input-file|output-file|port))|lambda|let-env|try|catch|when|unless|while|syntax-rules|(let|letrec)(-syntax|\*?-values|\*)?)$/],shift:{1:["&","#"]}}};Fi.match=Ei;Fi.prototype._options=function e(t){var r=Fi.defaults;if(typeof t==="undefined"){return Object.assign({},r)}var n=t&&t.exceptions||{};var i=n.specials||[];var u=n.shift||{1:[]};return z(z(z({},r),t),{},{exceptions:{specials:[].concat(U(r.exceptions.specials),U(i)),shift:z(z({},u),{},{1:[].concat(U(r.exceptions.shift[1]),U(u[1]))})}})};Fi.prototype.indent=function e(t){var r=Jn(this.__code__,true);return this._indent(r,t)};Fi.exception_shift=function(u,e){function t(e){if(!e.length){return false}if(e.indexOf(u)!==-1){return true}else{var t=e.filter(function(e){return e instanceof RegExp});if(!t.length){return false}var r=Tr(t),n;try{for(r.s();!(n=r.n()).done;){var i=n.value;if(u.match(i)){return true}}}catch(e){r.e(e)}finally{r.f()}}return false}if(t(e.exceptions.specials)){return e.indent}var r=e.exceptions.shift;for(var n=0,i=Object.entries(r);n0){n.offset=0}if(u.toString()===t.toString()&&ns(u)){return n.offset+u[0].col}else if(u.length===1){return n.offset+u[0].col+1}else{var s=-1;if(a){var c=Fi.exception_shift(a.token,n);if(c!==-1){s=c}}if(s===-1){s=Fi.exception_shift(u[1].token,n)}if(s!==-1){return n.offset+u[0].col+s}else if(u[0].line3&&u[1].line===u[3].line){if(u[1].token==="("||u[1].token==="["){return n.offset+u[1].col}return n.offset+u[3].col}else if(u[0].line===u[1].line){return n.offset+n.indent+u[0].col}else{var f=u.slice(2);for(var l=0;l")};Ai.prototype.match=function(e){return e.match(this.pattern)};function ki(){for(var e=arguments.length,t=new Array(e),r=0;r")};Fi.Pattern=ki;Fi.Ahead=Ai;var Oi=/^[[(]$/;var Ci=/^[\])]$/;var Si=/[^()[\]]/;var ji=new Ai(/[^)\]]/);var Bi=Symbol["for"]("*");var Ii=new ki([Oi,Bi,Ci],[Si],"+");var Pi=new ki([Oi,Bi,Ci],"+");var Ni=new ki([Symbol["for"]("symbol")],"?");var Ti=new ki([Symbol["for"]("symbol")],"*");var Li=[Oi,Ti,Ci];var Mi=new ki([Oi,Symbol["for"]("symbol"),Bi,Ci],"+");var Ri=Vi("syntax-rules");var qi=Vi("define","lambda","define-macro","syntax-rules");var Ui=/^(?!.*\b(?:[()[\]]|define(?:-macro)?|let(?:\*|rec|-env|-syntax|)?|lambda|syntax-rules)\b).*$/;var zi=/^(?:#:)?(let(?:\*|rec|-env|-syntax)?)$/;function Vi(){for(var e=arguments.length,t=new Array(e),r=0;r0&&!o[e]){o[e]=Di(a,e)}});var s=Tr(i),c;try{for(s.s();!(c=s.n()).done;){var f=b(c.value,3),l=f[0],h=f[1],_=f[2];h=h.valueOf();var p=h>0?o[h]:a;var d=p.filter(function(e){return e.trim()&&!ni(e)});var v=r(p);var m=Ei(l,d);var y=n.slice(u).find(function(e){return e.trim()&&!ni(e)});if(m&&(_ instanceof Ai&&_.match(y)||!_)){var g=u-v;if(n[g]!=="\n"){if(!n[g].trim()){n[g]="\n"}else{n.splice(g,0,"\n");u++}}u+=v;continue e}}}catch(e){s.e(e)}finally{s.f()}}this.__code__=n.join("");return this};Fi.prototype._spaces=function(e){return" ".repeat(e)};Fi.prototype.format=function e(t){var r=this.__code__.replace(/[ \t]*\n[ \t]*/g,"\n ");var n=Jn(r,true);var i=this._options(t);var u=0;var a=0;for(var o=0;o0){n=Math.floor(t()*r);r--;var i=[e[n],e[r]];e[r]=i[0];e[n]=i[1]}return e}function Hi(){}Hi.prototype.toString=function(){return"()"};Hi.prototype.valueOf=function(){return undefined};Hi.prototype.serialize=function(){return 0};Hi.prototype.to_object=function(){return{}};Hi.prototype.append=function(e){return new J(e,Y)};Hi.prototype.to_array=function(){return[]};var Y=new Hi;function J(e,t){if(typeof this!=="undefined"&&this.constructor!==J||typeof this==="undefined"){return new J(e,t)}this.car=e;this.cdr=t}function Gi(u,a){return function e(t){F(u,t,["pair","nil"]);if(H(t)){return[]}var r=[];var n=t;while(true){if(G(n)){if(n.have_cycles("cdr")){break}var i=n.car;if(a&&G(i)){i=this.get(u).call(this,i)}r.push(i);n=n.cdr}else if(H(n)){break}else{throw new Error("".concat(u,": can't convert improper list"))}}return r}}J.prototype.flatten=function(){return J.fromArray(Ji(this.to_array()))};J.prototype.length=function(){var e=0;var t=this;while(true){if(!t||H(t)||!G(t)||t.have_cycles("cdr")){break}e++;t=t.cdr}return e};J.match=function(e,t){if(e instanceof $){return $.is(e,t)}else if(G(e)){return J.match(e.car,t)||J.match(e.cdr,t)}else if(Array.isArray(e)){return e.some(function(e){return J.match(e,t)})}else if(Qi(e)){return Object.values(e).some(function(e){return J.match(e,t)})}return false};J.prototype.find=function(e){return J.match(this,e)};J.prototype.clone=function(){var r=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var n=new Map;function i(e){if(G(e)){if(n.has(e)){return n.get(e)}var t=new J;n.set(e,t);if(r){t.car=i(e.car)}else{t.car=e.car}t.cdr=i(e.cdr);t[aa]=e[aa];return t}return e}return i(this)};J.prototype.last_pair=function(){var e=this;while(true){if(!G(e.cdr)){return e}if(e.have_cycles("cdr")){break}e=e.cdr}};J.prototype.to_array=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var t=[];if(G(this.car)){if(e){t.push(this.car.to_array())}else{t.push(this.car)}}else{t.push(this.car.valueOf())}if(G(this.cdr)){t=t.concat(this.cdr.to_array(e))}return t};J.fromArray=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(G(e)||r&&e instanceof Array&&e[ia]){return e}if(t===false){var n=Y;for(var i=e.length;i--;){n=new J(e[i],n)}return n}if(e.length&&!(e instanceof Array)){e=U(e)}var u=Y;var a=e.length;while(a--){var o=e[a];if(o instanceof Array){o=J.fromArray(o,t,r)}else if(typeof o==="string"){o=x(o)}else if(typeof o==="number"&&!Number.isNaN(o)){o=j(o)}u=new J(o,u)}return u};J.prototype.to_object=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var t=this;var r={};while(true){if(G(t)&&G(t.car)){var n=t.car;var i=n.car;if(i instanceof $){i=i.__name__}if(i instanceof x){i=i.valueOf()}var u=n.cdr;if(G(u)){u=u.to_object(e)}if(Vu(u)){if(!e){u=u.valueOf()}}r[i]=u;t=t.cdr}else{break}}return r};J.fromPairs=function(e){return e.reduce(function(e,t){return new J(new J(new $(t[0]),t[1]),e)},Y)};J.fromObject=function(t){var e=Object.keys(t).map(function(e){return[e,t[e]]});return J.fromPairs(e)};J.prototype.reduce=function(e){var t=this;var r=Y;while(true){if(!H(t)){r=e(r,t.car);t=t.cdr}else{break}}return r};J.prototype.reverse=function(){if(this.have_cycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var t=Y;while(!H(e)){var r=e.cdr;e.cdr=t;t=e;e=r}return t};J.prototype.transform=function(n){function i(e){if(G(e)){if(e.replace){delete e.replace;return e}var t=n(e.car);if(G(t)){t=i(t)}var r=n(e.cdr);if(G(r)){r=i(r)}return new J(t,r)}return e}return i(this)};J.prototype.map=function(e){if(typeof this.car!=="undefined"){return new J(e(this.car),H(this.cdr)?Y:this.cdr.map(e))}else{return Y}};var Wi=new Map;function Qi(e){return e&&_(e)==="object"&&e.constructor===Object}var Zi=Object.getOwnPropertyNames(Array.prototype);var Xi=[];Zi.forEach(function(e){Xi.push(Array[e],Array.prototype[e])});function eu(e){e=Gu(e);return Xi.includes(e)}function tu(e){return d(e)&&(da(e)||e.__doc__)}function ru(r){var e=r.constructor||Object;var n=Qi(r);var i=d(r[Symbol.asyncIterator])||d(r[Symbol.iterator]);var u;if(Wi.has(e)){u=Wi.get(e)}else{Wi.forEach(function(e,t){t=Gu(t);if(r instanceof t&&(t===Object&&n&&!i||t!==Object)){u=e}})}return u}var nu=new Map;[[true,"#t"],[false,"#f"],[null,"#null"],[undefined,"#void"]].forEach(function(e){var t=b(e,2),r=t[0],n=t[1];nu.set(r,n)});function iu(r){if(r&&_(r)==="object"){var n={};var e=Object.getOwnPropertySymbols(r);e.forEach(function(e){var t=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");n[t]=fu(r[e])});var t=Object.getOwnPropertyNames(r);t.forEach(function(e){var t=r[e];if(t&&_(t)==="object"&&t.constructor===Object){n[e]=iu(t)}else{n[e]=fu(t)}});return n}return r}function uu(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function au(e,t){return e.hasOwnProperty(t)&&d(e.toString)}function ou(e){if(ya(e)){return"#"}var t=e.prototype&&e.prototype.constructor;if(d(t)&&da(t)){if(e[oa]&&t.hasOwnProperty("__name__")){var r=t.__name__;if(x.isString(r)){r=r.toString();return"#")}return"#"}}if(e.hasOwnProperty("__name__")){var n=e.__name__;if(_(n)==="symbol"){n=Gn(n)}if(typeof n==="string"){return"#")}}if(au(e,"toString")){return e.toString()}else if(e.name&&!da(e)){return"#")}else{return"#"}}var su=new Map;[[Error,function(e){return e.message}],[J,function(e,t){var r=t.quote,n=t.skip_cycles,i=t.pair_args;if(!n){e.mark_cycles()}return e.toString.apply(e,[r].concat(U(i)))}],[h,function(e,t){var r=t.quote;if(r){return e.toString()}return e.valueOf()}],[x,function(e,t){var r=t.quote;e=e.toString();if(r){return JSON.stringify(e).replace(/\\n/g,"\n")}return e}],[RegExp,function(e){return"#"+e.toString()}]].forEach(function(e){var t=b(e,2),r=t[0],n=t[1];su.set(r,n)});var cu=[$,K,_o,Ha,Ga,E,Zn];function fu(e,t,r){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(nu.has(e)){return nu.get(e)}if(ju(e)){return"#"}if(e){var n=e.constructor;if(su.has(n)){for(var i=arguments.length,u=new Array(i>3?i-3:0),a=3;a"}if(e===null){return"null"}if(d(e)){if(d(e.toString)&&e.hasOwnProperty("toString")){return e.toString().valueOf()}return ou(e)}if(_(e)==="object"){var f=e.constructor;if(!f){f=Object}var l;if(typeof f.__class__==="string"){l=f.__class__}else{var h=ru(e);if(h){if(d(h)){return h(e,t)}else{throw new Error("toString: Invalid repr value")}}l=f.name}if(d(e.toString)&&e.hasOwnProperty("toString")){return e.toString().valueOf()}if(qo(e)==="instance"){if(da(f)&&f.__name__){l=f.__name__.valueOf()}else if(!ya(f)){l="instance"}}if(qu(e,Symbol.iterator)){if(l){return"#")}return"#"}if(qu(e,Symbol.asyncIterator)){if(l){return"#")}return"#"}if(l!==""){return"#<"+l+">"}return"#"}if(typeof e!=="string"){return e.toString()}return e}J.prototype.mark_cycles=function(){hu(this);return this};J.prototype.have_cycles=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(!e){return this.have_cycles("car")||this.have_cycles("cdr")}return!!(this[aa]&&this[aa][e])};J.prototype.is_cycle=function(){return lu(this)};function lu(e){if(!G(e)){return false}if(e.have_cycles()){return true}return lu(e.car,fn)||lu(e.cdr,fn)}function hu(e){var t=[];var i=[];var u=[];function a(e){if(!t.includes(e)){t.push(e)}}function o(e,t,r,n){if(G(r)){if(n.includes(r)){if(!u.includes(r)){u.push(r)}if(!e[aa]){e[aa]={}}e[aa][t]=r;if(!i.includes(e)){i.push(e)}return true}}}var s=$n(function e(t,r){if(G(t)){delete t.ref;delete t[aa];a(t);r.push(t);var n=o(t,"car",t.car,r);var i=o(t,"cdr",t.cdr,r);if(!n){s(t.car,r.slice())}if(!i){return new Vn(function(){return e(t.cdr,r.slice())})}}});function r(e,t){if(G(e[aa][t])){var r=n.indexOf(e[aa][t]);e[aa][t]="#".concat(r,"#")}}s(e,[]);var n=t.filter(function(e){return u.includes(e)});n.forEach(function(e,t){e[ua]="#".concat(t,"=")});i.forEach(function(e){r(e,"car");r(e,"cdr")})}J.prototype.toString=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.nested,n=r===void 0?false:r;var i=[];if(this[ua]){i.push(this[ua]+"(")}else if(!n){i.push("(")}var u;if(this[aa]&&this[aa].car){u=this[aa].car}else{u=fu(this.car,e,true)}if(u!==undefined){i.push(u)}if(G(this.cdr)){if(this[aa]&&this[aa].cdr){i.push(" . ");i.push(this[aa].cdr)}else{if(this.cdr[ua]){i.push(" . ")}else{i.push(" ")}var a=this.cdr.toString(e,{nested:true});i.push(a)}}else if(!H(this.cdr)){i=i.concat([" . ",fu(this.cdr,e,true)])}if(!n||this[ua]){i.push(")")}return i.join("")};J.prototype.set=function(e,t){this[e]=t;if(G(t)){this.mark_cycles()}};J.prototype.append=function(e){if(e instanceof Array){return this.append(J.fromArray(e))}var t=this;if(t.car===undefined){if(G(e)){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(!H(e)){while(true){if(G(t)&&!H(t.cdr)){t=t.cdr}else{break}}t.cdr=e}return this};J.prototype.serialize=function(){return[this.car,this.cdr]};J.prototype[Symbol.iterator]=function(){var r=this;return{next:function e(){var t=r;r=t.cdr;if(H(t)){return{value:undefined,done:true}}else{return{value:t.car,done:false}}}}};function _u(e){return e<0?-e:e}function pu(e,t){var r=re(t),n=r[0],i=r.slice(1);while(i.length>0){var u=i,a=b(u,1),o=a[0];if(!e(n,o)){return false}var s=i;var c=re(s);n=c[0];i=c.slice(1)}return true}function du(e,t){if(d(e)){return d(t)&&Gu(e)===Gu(t)}else if(e instanceof j){if(!(t instanceof j)){return false}var r;if(e.__type__===t.__type__){if(e.__type__==="complex"){r=e.__im__.__type__===t.__im__.__type__&&e.__re__.__type__===t.__re__.__type__}else{r=true}if(r&&e.cmp(t)===0){if(e.valueOf()===0){return Object.is(e.valueOf(),t.valueOf())}return true}}return false}else if(typeof e==="number"){if(typeof t!=="number"){return false}if(Number.isNaN(e)){return Number.isNaN(t)}if(e===Number.NEGATIVE_INFINITY){return t===Number.NEGATIVE_INFINITY}if(e===Number.POSITIVE_INFINITY){return t===Number.POSITIVE_INFINITY}return du(j(e),j(t))}else if(e instanceof h){if(!(t instanceof h)){return false}return e.__char__===t.__char__}else{return e===t}}function vu(e,t){if(qo(e)!==qo(t)){return false}if(!mu(e)){return false}if(e instanceof RegExp){return e.source===t.source}if(e instanceof x){return e.valueOf()===t.valueOf()}return du(e,t)}function mu(e){return e instanceof $||x.isString(e)||H(e)||e===null||e instanceof h||e instanceof j||e===true||e===false}var yu=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e===0){return 0}else if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function K(e,t,r,n){if(typeof this!=="undefined"&&this.constructor!==K||typeof this==="undefined"){return new K(e,t)}F("Macro",e,"string",1);F("Macro",t,"function",2);if(r){if(n){this.__doc__=r}else{this.__doc__=wi(r)}}this.__name__=e;this.__fn__=t}K.defmacro=function(e,t,r,n){var i=new K(e,t,r,n);i.__defmacro__=true;return i};K.prototype.invoke=function(e,t,r){var n=t.env,i=le(t,kr);var u=z(z({},i),{},{macro_expand:r});var a=this.__fn__.call(n,e,u,this.__name__);return a};K.prototype.toString=function(){return"#")};var gu="define-macro";var bu=-1e4;function wu(c){return function(){var r=ie(O.mark(function e(r,y){var u,g,n,i,a,b,w,D,x,E,F,A,o,k,s;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:s=function e(){s=ie(O.mark(function e(r,n,i){var u,a,o,s,c,f,l,h,_,p,d,v,m;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!(G(r)&&r.car instanceof $)){t.next=50;break}if(!r[ia]){t.next=3;break}return t.abrupt("return",r);case 3:u=r.car.valueOf();a=i.get(r.car,{throwError:false});o=b(r.car);s=o||w(a,r)||D(a);if(!(s&&G(r.cdr.car))){t.next=28;break}if(!o){t.next=15;break}g=E(r.cdr.car);t.next=12;return A(r.cdr.car,n);case 12:c=t.sent;t.next=17;break;case 15:g=x(r.cdr.car);c=r.cdr.car;case 17:t.t0=J;t.t1=r.car;t.t2=J;t.t3=c;t.next=23;return k(r.cdr.cdr,n,i);case 23:t.t4=t.sent;t.t5=new t.t2(t.t3,t.t4);return t.abrupt("return",new t.t0(t.t1,t.t5));case 28:if(!F(u,a)){t.next=50;break}f=a instanceof Du?r:r.cdr;t.next=32;return a.invoke(f,z(z({},y),{},{env:i}),true);case 32:l=t.sent;if(!(a instanceof Du)){t.next=41;break}h=l,_=h.expr,p=h.scope;if(!G(_)){t.next=40;break}if(!(n!==-1&&n<=1||n")}return"#"};var xu=ce(function e(t){ue(this,e);c(this,"_syntax",t,{hidden:true});c(this._syntax,"_param",true,{hidden:true})});Du.Parameter=xu;function Eu(e,t,P,N){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:{};var T={"...":{symbols:{},lists:[]},symbols:{}};var L=r.expansion,M=r.define;V(P);function R(t,e){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:false;V({code:e,pattern:t});if(mu(t)&&!(t instanceof $)){return vu(t,e)}if(t instanceof $&&P.includes(t.literal())){if(!$.is(e,t)){return false}var i=L.ref(t);return!i||i===M||i===W}if(Array.isArray(t)&&Array.isArray(e)){V("<<< a 1");if(t.length===0&&e.length===0){return true}if($.is(t[1],N)){if(t[0]instanceof $){var u=t[0].valueOf();V("<<< a 2 "+n);if(n){var a=e.length-2;var o=a>0?e.slice(0,a):e;var s=J.fromArray(o,false);if(!T["..."].symbols[u]){T["..."].symbols[u]=new J(s,Y)}else{T["..."].symbols[u].append(new J(s,Y))}}else{T["..."].symbols[u]=J.fromArray(e,false)}}else if(Array.isArray(t[0])){V("<<< a 3");var c=U(r);if(!e.every(function(e){return R(t[0],e,c,true)})){return false}}if(t.length>2){var f=t.slice(2);return R(f,e.slice(-f.length),r,n)}return true}var l=R(t[0],e[0],r,n);V({first:l,pattern:t[0],code:e[0]});var h=R(t.slice(1),e.slice(1),r,n);V({first:l,rest:h});return l&&h}if(G(t)&&G(t.car)&&G(t.car.cdr)&&$.is(t.car.cdr.car,N)){V(">> 0");if(H(e)){V({pattern:t});if(t.car.car instanceof $){var _=t.car.car.valueOf();if(T["..."].symbols[_]){throw new Error("syntax: named ellipsis can only "+"appear onces")}T["..."].symbols[_]=e}}}if(G(t)&&G(t.cdr)&&$.is(t.cdr.car,N)){if(!H(t.cdr.cdr)){if(G(t.cdr.cdr)){var p=t.cdr.cdr.length();if(!G(e)){return false}var d=e.length();var v=e;while(d-1>p){v=v.cdr;d--}var m=v.cdr;v.cdr=Y;if(!R(t.cdr.cdr,m,r,n)){return false}}}if(t.car instanceof $){var y=t.car.__name__;if(T["..."].symbols[y]&&!r.includes(y)&&!n){throw new Error("syntax: named ellipsis can only appear onces")}V(">> 1");if(H(e)){V(">> 2");if(n){V("NIL");T["..."].symbols[y]=Y}else{V("NULL");T["..."].symbols[y]=null}}else if(G(e)&&(G(e.car)||H(e.car))){V(">> 3 "+n);if(n){if(T["..."].symbols[y]){var g=T["..."].symbols[y];if(H(g)){g=new J(Y,new J(e,Y))}else{g=g.append(new J(e,Y))}T["..."].symbols[y]=g}else{T["..."].symbols[y]=new J(e,Y)}}else{V(">> 4");T["..."].symbols[y]=new J(e,Y)}}else{V(">> 6");if(G(e)){if(!G(e.cdr)&&!H(e.cdr)){V(">> 7 (b)");if(H(t.cdr.cdr)){return false}else if(!T["..."].symbols[y]){T["..."].symbols[y]=new J(e.car,Y);return R(t.cdr.cdr,e.cdr)}}var b=e.last_pair();if(!H(b.cdr)){if(H(t.cdr.cdr)){return false}else{var w=e.clone();w.last_pair().cdr=Y;T["..."].symbols[y]=w;return R(t.cdr.cdr,b.cdr)}}V(">> 7 "+n);r.push(y);if(!T["..."].symbols[y]){T["..."].symbols[y]=new J(e,Y)}else{var D=T["..."].symbols[y];T["..."].symbols[y]=D.append(new J(e,Y))}V({IIIIII:T["..."].symbols[y]})}else if(t.car instanceof $&&G(t.cdr)&&$.is(t.cdr.car,N)){V(">> 8");T["..."].symbols[y]=null;return R(t.cdr.cdr,e)}else{V(">> 9");return false}}return true}else if(G(t.car)){var x=U(r);if(H(e)){V(">> 10");T["..."].lists.push(Y);return true}V(">> 11");var E=e;while(G(E)){if(!R(t.car,E.car,x,true)){return false}E=E.cdr}return true}if(Array.isArray(t.car)){var x=U(r);var F=e;while(G(F)){if(!R(t.car,F.car,x,true)){return false}F=F.cdr}return true}return false}if(t instanceof $){if($.is(t,N)){throw new Error("syntax: invalid usage of ellipsis")}V(">> 12");var A=t.__name__;if(P.includes(A)){return true}if(n){var k,O;V(T["..."].symbols[A]);(O=(k=T["..."].symbols)[A])!==null&&O!==void 0?O:k[A]=[];T["..."].symbols[A].push(e)}else{T.symbols[A]=e}return true}if(G(t)&&G(e)){V(">> 13");V({a:13,code:e,pattern:t});if(H(e.cdr)){var C=t.car instanceof $&&t.cdr instanceof $;if(C){if(!R(t.car,e.car,r,n)){return false}V(">> 14");var S=t.cdr.valueOf();if(!(S in T.symbols)){T.symbols[S]=Y}S=t.car.valueOf();if(!(S in T.symbols)){T.symbols[S]=e.car}return true}}V({pattern:t,code:e});if(G(t.cdr)&&G(t.cdr.cdr)&&t.cdr.car instanceof $&&$.is(t.cdr.cdr.car,N)&&G(t.cdr.cdr.cdr)&&!$.is(t.cdr.cdr.cdr.car,N)&&R(t.car,e.car,r,n)&&R(t.cdr.cdr.cdr,e.cdr,r,n)){var j=t.cdr.car.__name__;V({pattern:t,code:e,name:j});if(P.includes(j)){return true}T["..."].symbols[j]=null;return true}V("recur");V({pattern:t,code:e});var B=R(t.car,e.car,r,n);V({car:B,pattern:t.car,code:e.car});var I=R(t.cdr,e.cdr,r,n);V({car:B,cdr:I});if(B&&I){return true}}else if(H(t)&&(H(e)||e===undefined)){return true}else if(G(t.car)&&$.is(t.car.car,N)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(R(e,t)){return T}}function Fu(e,i){function u(t){if(G(t)){if(!i.length){return t}var e=u(t.car);var r=u(t.cdr);return new J(e,r)}else if(t instanceof $){var n=i.find(function(e){return e.gensym===t});if(n){return $(n.name)}return t}else{return t}}return u(e)}function Au(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var B=e.bindings,t=e.expr,I=e.scope,a=e.symbols,f=e.names,P=e.ellipsis;var l={};function o(e){if(e instanceof $){return true}return["string","symbol"].includes(_(e))}function N(e){if(!o(e)){var t=qo(e);throw new Error("syntax: internal error, need symbol got ".concat(t))}var r=e.valueOf();if(r===P){throw new Error("syntax: internal error, ellipis not transformed")}var n=_(r);if(["string","symbol"].includes(n)){if(r in B.symbols){return B.symbols[r]}else if(n==="string"&&r.match(/\./)){var i=r.split(".");var u=i[0];if(u in B.symbols){return J.fromArray([$("."),B.symbols[u]].concat(i.slice(1).map(function(e){return x(e)})))}}}if(a.includes(r)){return e}return s(r,e)}function s(e,t){if(!l[e]){var r=I.ref(e);if(_(e)==="symbol"&&!r){e=t.literal()}if(l[e]){return l[e]}var n=Qn(e);if(r){var i=I.get(e);I.set(n,i)}else{var u=I.get(e,{throwError:false});if(typeof u!=="undefined"){I.set(n,u)}}f.push({name:e,gensym:n});l[e]=n;if(typeof e==="string"&&e.match(/\./)){var a=e.split(".").filter(Boolean),o=re(a),s=o[0],c=o.slice(1);if(l[s]){_a(n,"__object__",[l[s]].concat(U(c)))}}}return l[e]}function T(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:function(){};var i=r.nested;V({bindings:t,expr:e});if(Array.isArray(e)&&!e.length){return e}if(e instanceof $){var u=e.valueOf();if(Wn(e)&&!t[u]);V("[t 1");if(t[u]){if(G(t[u])){var a=t[u],o=a.car,s=a.cdr;if(i){var c=o.car,f=o.cdr;if(!H(f)){n(u,new J(f,Y))}return c}if(!H(s)){n(u,s)}return o}else if(t[u]instanceof Array){n(u,t[u].slice(1));return t[u][0]}}return N(e)}var l=Array.isArray(e);if(G(e)||l){var h=l?e[0]:e.car;var _=l?e[1]:G(e.cdr)&&e.cdr.car;if(h instanceof $&&$.is(_,P)){l?e.slice(2):e.cdr.cdr;V("[t 2");var p=h.valueOf();var d=t[p];if(d===null){return}else if(d){V({name:p,binding:t[p]});if(G(d)){V("[t 2 Pair "+i);var v=d.car,m=d.cdr;var y=l?e.slice(2):e.cdr.cdr;if(i){if(!H(m)){V("|| next 1");n(p,m)}if(l&&y.length||!H(y)&&!l){var g=T(y,t,r,n);if(l){return v.concat(g)}else if(G(v)){return v.append(g)}else{V("UNKNOWN")}}return v}else if(G(v)){if(!H(v.cdr)){V("|| next 2");n(p,new J(v.cdr,m))}return v.car}else if(H(m)){return v}else{var b=e.last_pair();if(b.cdr instanceof $){V("|| next 3");n(p,d.last_pair());return v}}}else if(d instanceof Array){V("[t 2 Array "+i);if(i){n(p,d.slice(1));return J.fromArray(d)}else{var w=d.slice(1);if(w.length){n(p,w)}return d[0]}}else{return d}}}V("[t 3 recur ",e);var D=l?e.slice(1):e.cdr;var x=T(h,t,r,n);var E=T(D,t,r,n);V({head:x,rest:E});if(l){return[x].concat(E)}return new J(x,E)}return e}function L(t,r){var e=Object.values(t);var n=Object.getOwnPropertySymbols(t);if(n.length){e.push.apply(e,U(n.map(function(e){return t[e]})))}return e.length&&e.every(function(e){if(e===null){return!r}return G(e)||H(e)||Array.isArray(e)&&e.length})}function M(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function R(i){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},t=e.disabled;V("traverse>> ",i);var u=Array.isArray(i);if(u&&i.length===0){return i}if(G(i)||u){var r=u?i[0]:i.car;var n,a;if(u){n=i[1];a=i.slice(2)}else if(G(i.cdr)){n=i.cdr.car;a=i.cdr.cdr}V({first:r,second:n,rest_second:a});if(!t&&G(r)&&$.is(r.car,P)){return new J(r.cdr.car,R(i.cdr))}if(n&&$.is(n,P)&&!t){V(">> 1");var o=B["..."].symbols;var s=Object.values(o);if(s.length&&s.every(function(e){return e===null})){V(">>> 1 (a)");return R(a,{disabled:t})}var c=M(o);var f=r instanceof $&&$.is(a.car,P);if(G(r)||f){V(">>> 1 (b)");if(H(B["..."].lists[0])){if(!f){return R(a,{disabled:t})}V(a);return Y}var l=r;if(f){V(">>> 1 (c)");l=new J(r,new J(n,Y))}V(">> 2");var h;if(c.length){V(">> 2 (a)");var _=z({},o);h=u?[]:Y;var p=function e(){V({bind:_});if(!L(_)){return 1}var n={};var t=function e(t,r){n[t]=r};var r=T(l,_,{nested:true},t);if(r!==undefined){if(f){if(u){if(Array.isArray(r)){var i;(i=h).push.apply(i,U(r))}else{V("ZONK {1}")}}else{if(H(h)){h=r}else{h=h.append(r)}}}else if(u){h.push(r)}else{h=new J(r,h)}}_=n};while(true){if(p())break}if(!H(h)&&!f&&!u){h=h.reverse()}if(u){if(a){V({rest_second:a,expr:i});var d=R(a,{disabled:t});return h.concat(d)}return h}if(!H(i.cdr.cdr)&&!$.is(i.cdr.cdr.car,P)){var v=R(i.cdr.cdr,{disabled:t});return h.append(v)}return h}else{V(">> 3");var m=T(r,o,{nested:true});if(m){return new J(m,Y)}return Y}}else if(r instanceof $){V(">> 4");if($.is(a.car,P)){V(">> 4 (a)")}else{V(">> 4 (b)")}var y=r.__name__;var g=q({},y,o[y]);V({bind:g});var b=o[y]===null;var w=u?[]:Y;var D=function e(){if(!L(g,true)){V({bind:g});return 1}var n={};var t=function e(t,r){n[t]=r};var r=T(i,g,{nested:false},t);V({value:r});if(typeof r!=="undefined"){if(u){w.push(r)}else{w=new J(r,w)}}g=n};while(true){if(D())break}if(!H(w)&&!u){w=w.reverse()}if(G(i.cdr)){if(G(i.cdr.cdr)||i.cdr.cdr instanceof $){var x=R(i.cdr.cdr,{disabled:t});V({node:x});if(b){return x}if(H(w)){w=x}else{w.append(x)}V({result:w,node:x})}}V("<<<< 2");return w}}var E=R(r,{disabled:t});var F;var A;if(r instanceof $){var k=I.get(r,{throwError:false});A=k instanceof K&&k.__name__==="syntax-rules"}if(A){if(i.cdr.car instanceof $){F=new J(R(i.cdr.car,{disabled:t}),new J(i.cdr.cdr.car,R(i.cdr.cdr.cdr,{disabled:t})))}else{F=new J(i.cdr.car,R(i.cdr.cdr,{disabled:t}))}V("REST >>>> ",F)}else{F=R(i.cdr,{disabled:t})}V({a:true,car:fu(i.car),cdr:fu(i.cdr),head:fu(E),rest:fu(F)});return new J(E,F)}if(i instanceof $){if(t&&$.is(i,P)){return i}var O=Object.keys(B["..."].symbols);var C=i.literal();if(O.includes(C)){var S="missing ellipsis symbol next to name `".concat(C,"'");throw new Error("syntax-rules: ".concat(S))}var j=N(i);if(typeof j!=="undefined"){return j}}return i}return R(t,{})}function ku(e){return Ru(e)||H(e)||e===null}function H(e){return e===Y}function d(e){return typeof e==="function"&&typeof e.bind==="function"}function Ou(e){return fi.includes(e)}function Cu(e){return e===false||e===null}function Su(e){return typeof e==="string"}function ju(e){return e&&_(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}function Bu(e){return e instanceof Zo}function Iu(e){return e instanceof Wo}function Pu(e){return e instanceof Go}function G(e){return e instanceof J}function Nu(e){return e instanceof E}function Tu(e){return d(e)||Bu(e)||Pu(e)||Lu(e)}function Lu(e){return e instanceof K||e instanceof xu}function Mu(e){if(e instanceof Zn){return false}if(e instanceof Promise){return true}return!!e&&d(e.then)}function Ru(e){return typeof e==="undefined"}function qu(e,t){if($u(e,t)||$u(e.__proto__,t)){return d(e[t])}}function Uu(e){if(!e){return false}if(_(e)!=="object"){return false}if(e.__instance__){e.__instance__=false;return e.__instance__}return false}function zu(e){var t=_(e);return["string","function"].includes(t)||_(e)==="symbol"||e instanceof Zn||e instanceof $||e instanceof j||e instanceof x||e instanceof RegExp}function Vu(e){return e instanceof j||e instanceof x||e instanceof h}function $u(e,t){if(e===null){return false}return _(e)==="object"&&t in Object.getOwnPropertySymbols(e)}function Yu(e){switch(_(e)){case"string":return x(e);case"bigint":return j(e);case"number":if(Number.isNaN(e)){return wo}else{return j(e)}}return e}function Ju(r,n){var e=Object.getOwnPropertyNames(r);var t=Object.getOwnPropertySymbols(r);var i={};e.concat(t).forEach(function(e){var t=n(r[e]);i[e]=t});return i}function Ku(t){var e=[x,j,h].some(function(e){return t instanceof e});if(e){return t.valueOf()}if(t instanceof Array){return t.map(Ku)}if(t instanceof Zn){delete t.then}if(Qi(t)){return Ju(t,Ku)}return t}function Hu(e,t){if(G(e)){e.mark_cycles();return po(e)}if(d(e)){if(t){return Wu(e,t)}}return Yu(e)}function Gu(e){if(Zu(e)){return e[na]}return e}function Wu(e,t){if(e[Symbol["for"]("__bound__")]){return e}var r=e.bind(t);var n=Object.getOwnPropertyNames(e);var i=Tr(n),u;try{for(i.s();!(u=i.n()).done;){var a=u.value;if(ha(a)){try{r[a]=e[a]}catch(e){}}}}catch(e){i.e(e)}finally{i.f()}_a(r,"__fn__",e);_a(r,"__context__",t);_a(r,"__bound__",true);if(ya(e)){_a(r,"__native__",true)}if(Qi(t)&&da(e)){_a(r,"__method__",true)}r.valueOf=function(){return e};return r}function Qu(e){return Zu(e)&&e[Symbol["for"]("__context__")]===Object}function Zu(e){return!!(d(e)&&e[na])}function Xu(e){if(d(e)){var t=e[ra];if(t&&(t===Ts||t.constructor&&t.constructor.__class__)){return true}}return false}function ea(e){return e instanceof Ha||e instanceof Ga}function ta(e){if(d(e)){if(ea(e[ra])){return true}}return false}var ra=Symbol["for"]("__context__");var na=Symbol["for"]("__fn__");var ia=Symbol["for"]("__data__");var ua=Symbol["for"]("__ref__");var aa=Symbol["for"]("__cycles__");var oa=Symbol["for"]("__class__");var sa=Symbol["for"]("__method__");var ca=Symbol["for"]("__prototype__");var fa=Symbol["for"]("__lambda__");var la=["name","length","caller","callee","arguments","prototype"];function ha(e){return!la.includes(e)}function _a(e,t,r){Object.defineProperty(e,Symbol["for"](t),{get:function e(){return r},set:function e(){},configurable:false,enumerable:false})}function pa(t,r){try{Object.defineProperty(t,"length",{get:function e(){return r}});return t}catch(e){var n=new Array(r).fill(0).map(function(e,t){return"a"+t}).join(",");var i=new Function("f","return function(".concat(n,") {\n return f.apply(this, arguments);\n };"));return i(t)}}function da(e){return e&&e[fa]}function va(e){return e&&e[sa]}function ma(e){return da(e)&&!e[ca]&&!va(e)&&!ta(e)}function ya(e){var t=Symbol["for"]("__native__");return d(e)&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[t]===true||!e.name.match(/^bound /)&&!e[t])}function ga(e){var w;switch(e){case Symbol["for"]("letrec"):w="letrec";break;case Symbol["for"]("let"):w="let";break;case Symbol["for"]("let*"):w="let*";break;default:throw new Error("Invalid let_macro value")}return K.defmacro(w,function(t,e){var f=e.dynamic_env;var l=e.error,r=e.macro_expand,h=e.use_dynamic;var _;if(t.car instanceof $){if(!(G(t.cdr.car)||H(t.cdr.car))){throw new Error("let require list of pairs")}var n;if(H(t.cdr.car)){_=Y;n=Y}else{n=t.cdr.car.map(function(e){return e.car});_=t.cdr.car.map(function(e){return e.cdr.car})}var i=Qn("args");return J.fromArray([$("let"),[[i,J($("list"),_)]],[$("letrec"),[[t.car,J($("lambda"),J(n,t.cdr.cdr))]],[$("apply"),t.car,i]]])}else if(r){return}var p=this;_=W.get("list->array")(t.car);var d=p.inherit(w);var v,m;if(w==="let*"){m=d}else if(w==="let"){v=[]}var y=0;function g(){var e=new J(new $("begin"),t.cdr);return A(e,{env:d,dynamic_env:d,use_dynamic:h,error:l})}function b(e){if(e in d.__env__){throw new Error("Duplicated let variable ".concat(e))}}return function t(){var r=_[y++];f=w==="let*"?d:p;if(!r){if(v&&v.length){var e=v.map(function(e){return e.value});var n=e.filter(Mu);if(n.length){return Xn(e).then(function(e){for(var t=0,r=e.length;t1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=t.error;var i=this;var u=this;var a=[];var o=e;while(G(o)){a.push(A(o.car,{env:i,dynamic_env:u,use_dynamic:r,error:n}));o=o.cdr}var s=a.filter(Mu).length;if(s){return Xn(a).then(c.bind(this))}else{return c.call(this,a)}})}function wa(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n2?n-2:0),u=2;u1&&arguments[1]!==undefined?arguments[1]:null;return function(){for(var e=arguments.length,t=new Array(e),r=0;r1?e-1:0),r=1;r=a){return u.apply(this,n)}else{return i}}return i.apply(this,arguments)}}function Sa(n,i){F("limit",i,"function",2);return function(){for(var e=arguments.length,t=new Array(e),r=0;r1){e=e.toLowerCase();if(h.__names__[e]){t=e;e=h.__names__[e]}else{throw new Error("Internal: Unknown named character")}}else{t=h.__rev_names__[e]}Object.defineProperty(this,"__char__",{value:e,enumerable:true});if(t){Object.defineProperty(this,"__name__",{value:t,enumerable:true})}}h.__names__=sn;h.__rev_names__={};Object.keys(h.__names__).forEach(function(e){var t=h.__names__[e];h.__rev_names__[t]=e});h.prototype.toUpperCase=function(){return h(this.__char__.toUpperCase())};h.prototype.toLowerCase=function(){return h(this.__char__.toLowerCase())};h.prototype.toString=function(){return"#\\"+(this.__name__||this.__char__)};h.prototype.valueOf=h.prototype.serialize=function(){return this.__char__};function x(e){if(typeof this!=="undefined"&&!(this instanceof x)||typeof this==="undefined"){return new x(e)}if(e instanceof Array){this.__string__=e.map(function(e,t){F("LString",e,"character",t+1);return e.toString()}).join("")}else{this.__string__=e.valueOf()}}{var ja=["length","constructor"];var Ba=Object.getOwnPropertyNames(String.prototype).filter(function(e){return!ja.includes(e)});var Ia=function e(n){return function(){for(var e=arguments.length,t=new Array(e),r=0;r0){r.push(this.__string__.substring(0,e))}r.push(t);if(e1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof j){return e}if(typeof this!=="undefined"&&!(this instanceof j)||typeof this==="undefined"){return new j(e,t)}if(typeof e==="undefined"){throw new Error("Invalid LNumber constructor call")}var r=j.getType(e);if(j.types[r]){return j.types[r](e,t)}var n=e instanceof Array&&x.isString(e[0])&&j.isNumber(e[1]);if(e instanceof j){return j(e.value)}if(!j.isNumber(e)&&!n){throw new Error("You can't create LNumber from ".concat(qo(e)))}if(e===null){e=0}var i;if(n){var u=e,a=b(u,2),o=a[0],s=a[1];if(o instanceof x){o=o.valueOf()}if(s instanceof j){s=s.valueOf()}var c=o.match(/^([+-])/);var f=false;if(c){o=o.replace(/^[+-]/,"");if(c[1]==="-"){f=true}}}if(Number.isNaN(e)){return g(e)}else if(n&&Number.isNaN(parseInt(o,s))){return wo}else if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(n){var l;switch(s){case 8:l="0o";break;case 16:l="0x";break;case 2:l="0b";break;case 10:l="";break}if(typeof l==="undefined"){var h=BigInt(s);i=U(o).map(function(e,t){return BigInt(parseInt(e,s))*Ua(h,BigInt(t))}).reduce(function(e,t){return e+t})}else{i=BigInt(l+o)}}else{i=BigInt(e)}if(f){i*=BigInt(-1)}}else{i=e}return Ka(i,true)}else if(typeof Hr!=="undefined"&&!(e instanceof Hr)){if(e instanceof Array){return Ka(N(Hr,U(e)))}return Ka(new Hr(e))}else if(n){this.constant(parseInt(o,s),"integer")}else{this.constant(e,"integer")}}j.prototype.constant=function(e,t){Object.defineProperty(this,"__value__",{value:e,enumerable:true});Object.defineProperty(this,"__type__",{value:t,enumerable:true})};j.types={float:function e(t){return new g(t)},complex:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!j.isComplex(t)){t={im:0,re:t}}return new y(t,r)},rational:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!j.isRational(t)){t={num:t,denom:1}}return new w(t,r)}};j.prototype.serialize=function(){return this.__value__};j.prototype.isNaN=function(){return Number.isNaN(this.__value__)};j.prototype.gcd=function(e){var t=this.abs();e=e.abs();if(e.cmp(t)===1){var r=t;t=e;e=r}while(true){t=t.rem(e);if(t.cmp(0)===0){return e}e=e.rem(t);if(e.cmp(0)===0){return t}}};j.isFloat=function e(t){return t instanceof g||Number(t)===t&&t%1!==0};j.isNumber=function(e){return e instanceof j||j.isNative(e)||j.isBN(e)};j.isComplex=function(e){if(!e){return false}var t=e instanceof y||(j.isNumber(e.im)||j.isRational(e.im)||Number.isNaN(e.im))&&(j.isNumber(e.re)||j.isRational(e.re)||Number.isNaN(e.re));return t};j.isRational=function(e){if(!e){return false}return e instanceof w||j.isNumber(e.num)&&j.isNumber(e.denom)};j.isInteger=function(e){if(!(j.isNative(e)||e instanceof j)){return false}if(j.isFloat(e)){return false}if(j.isRational(e)){return false}if(j.isComplex(e)){return false}return true};j.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};j.isBigInteger=function(e){return e instanceof Ka||typeof e==="bigint"||j.isBN(e)};j.isBN=function(e){return typeof Hr!=="undefined"&&e instanceof Hr};j.getArgsType=function(e,t){if(e instanceof g||t instanceof g){return g}if(e instanceof Ka||t instanceof Ka){return Ka}return j};j.prototype.toString=function(e){if(Number.isNaN(this.__value__)){return"+nan.0"}if(e>=2&&e<36){return this.__value__.toString(e)}return this.__value__.toString()};j.prototype.asType=function(e){var t=j.getType(this);return j.types[t]?j.types[t](e):j(e)};j.prototype.isBigNumber=function(){return typeof this.__value__==="bigint"||typeof Hr!=="undefined"&&!(this.value instanceof Hr)};["floor","ceil","round"].forEach(function(e){j.prototype[e]=function(){if(this["float"]||j.isFloat(this.__value__)){return j(Math[e](this.__value__))}else{return j(Math[e](this.valueOf()))}}});j.prototype.valueOf=function(){if(j.isNative(this.__value__)){return Number(this.__value__)}else if(j.isBN(this.__value__)){return this.__value__.toNumber()}};var La=function(){var e=function e(t,r){return[t,r]};return{bigint:{bigint:e,float:function e(t,r){return[g(t.valueOf()),r]},rational:function e(t,r){return[{num:t,denom:1},r]},complex:function e(t,r){return[{im:0,re:t},r]}},integer:{integer:e,float:function e(t,r){return[g(t.valueOf()),r]},rational:function e(t,r){return[{num:t,denom:1},r]},complex:function e(t,r){return[{im:0,re:t},r]}},float:{bigint:function e(t,r){return[t,r&&g(r.valueOf())]},integer:function e(t,r){return[t,r&&g(r.valueOf())]},float:e,rational:function e(t,r){return[t,r&&g(r.valueOf())]},complex:function e(t,r){return[{re:t,im:g(0)},r]}},complex:{bigint:t("bigint"),integer:t("integer"),float:t("float"),rational:t("rational"),complex:function e(t,r){var n=j.coerce(t.__re__,r.__re__),i=b(n,2),u=i[0],a=i[1];var o=j.coerce(t.__im__,r.__im__),s=b(o,2),c=s[0],f=s[1];return[{im:c,re:u},{im:f,re:a}]}},rational:{bigint:function e(t,r){return[t,r&&{num:r,denom:1}]},integer:function e(t,r){return[t,r&&{num:r,denom:1}]},float:function e(t,r){return[g(t.valueOf()),r]},rational:e,complex:function e(t,r){return[{im:Ma(t.__type__,r.__im__.__type__,0)[0],re:Ma(t.__type__,r.__re__.__type__,t)[0]},{im:Ma(t.__type__,r.__im__.__type__,r.__im__)[0],re:Ma(t.__type__,r.__re__.__type__,r.__re__)[0]}]}}};function t(r){return function(e,t){return[{im:Ma(r,e.__im__.__type__,0,e.__im__)[1],re:Ma(r,e.__re__.__type__,0,e.__re__)[1]},{im:Ma(r,e.__im__.__type__,0,0)[1],re:Ma(r,t.__type__,0,t)[1]}]}}}();function Ma(e,t,r,n){return La[e][t](r,n)}j.coerce=function(e,t){var r=j.getType(e);var n=j.getType(t);if(!La[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!La[r][n]){throw new Error("LNumber::coerce unknown rhs type ".concat(n))}var i=La[r][n](e,t);return i.map(function(e){return j(e,true)})};j.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof j)){throw new Error("LNumber: you can't coerce ".concat(qo(e)))}if(typeof e==="number"){e=j(e)}return j.coerce(this,e)};j.getType=function(e){if(e instanceof j){return e.__type__}if(j.isFloat(e)){return"float"}if(j.isComplex(e)){return"complex"}if(j.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof Hr!=="undefined"&&!(e instanceof Hr)){return"bigint"}};j.prototype.isFloat=function(){return!!(j.isFloat(this.__value__)||this["float"])};var Ra={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var qa={};Object.keys(Ra).forEach(function(t){qa[Ra[t]]=t;j.prototype[t]=function(e){return this.op(Ra[t],e)}});j._ops={"*":function e(t,r){return t*r},"+":function e(t,r){return t+r},"-":function e(t,r){if(typeof r==="undefined"){return-t}return t-r},"/":function e(t,r){return t/r},"%":function e(t,r){return t%r},"|":function e(t,r){return t|r},"&":function e(t,r){return t&r},"~":function e(t){return~t},">>":function e(t,r){return t>>r},"<<":function e(t,r){return t<1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof y)||typeof this==="undefined"){return new y(e,t)}if(e instanceof y){return y({im:e.__im__,re:e.__re__})}if(j.isNumber(e)&&t){if(!t){return Number(e)}}else if(!j.isComplex(e)){var r="Invalid constructor call for LComplex expect &(:im :re ) object but got ".concat(fu(e));throw new Error(r)}var n=e.im instanceof j?e.im:j(e.im);var i=e.re instanceof j?e.re:j(e.re);this.constant(n,i)}y.prototype=Object.create(j.prototype);y.prototype.constructor=y;y.prototype.constant=function(e,t){Object.defineProperty(this,"__im__",{value:e,enumerable:true});Object.defineProperty(this,"__re__",{value:t,enumerable:true});Object.defineProperty(this,"__type__",{value:"complex",enumerable:true})};y.prototype.serialize=function(){return{re:this.__re__,im:this.__im__}};y.prototype.toRational=function(e){var t=this.__im__,r=this.__re__;if(j.isFloat(this.__im__)){t=g(this.__im__).toRational(e)}if(j.isFloat(this.__re__)){r=g(this.__re__).toRational(e)}return y({im:t,re:r})};y.prototype.pow=function(e){e.cmp(0);if(e===0){return j(1)}var t=j(Math.atan2(this.__im__.valueOf(),this.__re__.valueOf()));var r=j(this.modulus());if(j.isComplex(e)&&e.__im__.cmp(0)!==0){var n=e.mul(Math.log(r.valueOf())).add(y.i.mul(t).mul(e));if(!j.isComplex(n)){return g(Math.E).pow(n)}var i=g(Math.E).pow(n.__re__.valueOf());return y({re:i.mul(Math.cos(n.__im__.valueOf())),im:i.mul(Math.sin(n.__im__.valueOf()))})}var u=e.__re__.cmp(0)>0;e=e.__re__.valueOf();if(j.isInteger(e)&&u){var a=this;while(--e){a=a.mul(this)}return a}var o=r.pow(e);var s=t.mul(e);return y({re:o.mul(Math.cos(s)),im:o.mul(Math.sin(s))})};y.prototype.add=function(e){return this.complex_op("add",e,function(e,t,r,n){return{re:e.add(t),im:r.add(n)}})};y.prototype.factor=function(){if(this.__im__ instanceof g||this.__im__ instanceof g){var e=this.__re__,t=this.__im__;var r,n;if(e instanceof g){r=e.toRational().mul(e.toRational())}else{r=e.mul(e)}if(t instanceof g){n=t.toRational().mul(t.toRational())}else{n=t.mul(t)}return r.add(n)}else{return this.__re__.mul(this.__re__).add(this.__im__.mul(this.__im__))}};y.prototype.modulus=function(){return this.factor().sqrt()};y.prototype.conjugate=function(){return y({re:this.__re__,im:this.__im__.sub()})};y.prototype.sqrt=function(){var e=this.modulus();var t,r;if(e.cmp(0)===0){t=r=e}else if(this.__re__.cmp(0)===1){t=g(.5).mul(e.add(this.__re__)).sqrt();r=this.__im__.div(t).div(2)}else{r=g(.5).mul(e.sub(this.__re__)).sqrt();if(this.__im__.cmp(0)===-1){r=r.sub()}t=this.__im__.div(r).div(2)}return y({im:r,re:t})};y.prototype.div=function(e){if(j.isNumber(e)&&!j.isComplex(e)){if(!(e instanceof j)){e=j(e)}var t=this.__re__.div(e);var r=this.__im__.div(e);return y({re:t,im:r})}else if(!j.isComplex(e)){throw new Error("[LComplex::div] Invalid value")}if(this.cmp(e)===0){var n=this.coerce(e),i=b(n,2),u=i[0],a=i[1];var o=u.__im__.div(a.__im__);return o.coerce(a.__re__)[0]}var s=this.coerce(e),c=b(s,2),f=c[0],l=c[1];var h=l.factor();var _=l.conjugate();var p=f.mul(_);if(!j.isComplex(p)){return p.div(h)}var d=p.__re__.op("/",h);var v=p.__im__.op("/",h);return y({re:d,im:v})};y.prototype.sub=function(e){return this.complex_op("sub",e,function(e,t,r,n){return{re:e.sub(t),im:r.sub(n)}})};y.prototype.mul=function(e){return this.complex_op("mul",e,function(e,t,r,n){var i={re:e.mul(t).sub(r.mul(n)),im:e.mul(n).add(t.mul(r))};return i})};y.prototype.complex_op=function(e,t,i){var u=this;var r=function e(t,r){var n=i(u.__re__,t,u.__im__,r);if("im"in n&&"re"in n){if(n.im.cmp(0)===0){return n.re}return y(n,true)}return n};if(typeof t==="undefined"){return r()}if(j.isNumber(t)&&!j.isComplex(t)){if(!(t instanceof j)){t=j(t)}var n=t.asType(0);t={__im__:n,__re__:t}}else if(!j.isComplex(t)){throw new Error("[LComplex::".concat(e,"] Invalid value"))}var a=t.__re__ instanceof j?t.__re__:this.__re__.asType(t.__re__);var o=t.__im__ instanceof j?t.__im__:this.__im__.asType(t.__im__);return r(a,o)};y._op={"+":"add","-":"sub","*":"mul","/":"div"};y.prototype._op=function(e,t){var r=y._op[e];return this[r](t)};y.prototype.cmp=function(e){var t=this.coerce(e),r=b(t,2),n=r[0],i=r[1];var u=n.__re__.coerce(i.__re__),a=b(u,2),o=a[0],s=a[1];var c=o.cmp(s);if(c!==0){return c}else{var f=n.__im__.coerce(i.__im__),l=b(f,2),h=l[0],_=l[1];return h.cmp(_)}};y.prototype.valueOf=function(){return[this.__re__,this.__im__].map(function(e){return e.valueOf()})};y.prototype.toString=function(){var e;if(this.__re__.cmp(0)!==0){e=[fu(this.__re__)]}else{e=[]}var t=this.__im__.valueOf();var r=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY].includes(t);var n=fu(this.__im__);if(!r&&!Number.isNaN(t)){var i=this.__im__.cmp(0);if(i<0||i===0&&this.__im__._minus){e.push("-")}else{e.push("+")}n=n.replace(/^-/,"")}e.push(n);e.push("i");return e.join("")};function g(e){if(typeof this!=="undefined"&&!(this instanceof g)||typeof this==="undefined"){return new g(e)}if(!j.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof j){return g(e.valueOf())}if(typeof e==="number"){if(Object.is(e,-0)){Object.defineProperty(this,"_minus",{value:true})}this.constant(e,"float")}}g.prototype=Object.create(j.prototype);g.prototype.constructor=g;g.prototype.toString=function(e){if(this.__value__===Number.NEGATIVE_INFINITY){return"-inf.0"}if(this.__value__===Number.POSITIVE_INFINITY){return"+inf.0"}if(Number.isNaN(this.__value__)){return"+nan.0"}e&&(e=e.valueOf());var t=this.__value__.toString(e);if(!t.match(/e[+-]?[0-9]+$/i)){var r=t.replace(/^-/,"");var n=this.__value__<0?"-":"";if(t.match(/^-?0\.0{3}/)){var i=r.match(/^[.0]+/g)[0].length-1;var u=r.replace(/^[.0]+/,"").replace(/^([0-9a-f])/i,"$1.");return"".concat(n).concat(u,"e-").concat(i.toString(e))}if(t.match(/^-?[0-9a-f]{7,}\.?/i)){var a=r.match(/^[0-9a-f]+/gi)[0].length-1;var o=r.replace(/\./,"").replace(/^([0-9a-f])/i,"$1.").replace(/0+$/,"").replace(/\.$/,".0");return"".concat(n).concat(o,"e+").concat(a.toString(e))}if(!j.isFloat(this.__value__)){var s=t+".0";return this._minus?"-"+s:s}}return t.replace(/^([0-9]+)e/,"$1.0e")};g.prototype._op=function(e,t){if(t instanceof j){t=t.__value__}var r=j._ops[e];if(e==="/"&&this.__value__===0&&t===0){return NaN}return g(r(this.__value__,t))};g.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){return Va(this.__value__.valueOf())}return $a(e.valueOf())(this.__value__.valueOf())};g.prototype.sqrt=function(){var e=this.valueOf();if(this.cmp(0)<0){var t=g(Math.sqrt(-e));return y({re:0,im:t})}return g(Math.sqrt(e))};g.prototype.abs=function(){var e=this.valueOf();if(e<0){e=-e}return g(e)};var Va=$a(1e-10);function $a(n){return function(e){var t=function e(n,t,r){var i=function e(t,r){return r0){i=Ja(n,r)}else if(n.cmp(r)<=0){i=r}else if(r.cmp(0)>0){i=Ja(r,n)}else if(t.cmp(0)<0){i=j(Ja(n.sub(),r.sub())).sub()}else{i=j(0)}if(j.isFloat(t)||j.isFloat(e)){return g(i)}return i}function Ja(e,t){var r=j(e).floor();var n=j(t).floor();if(e.cmp(r)<1){return r}else if(r.cmp(n)===0){var i=j(1).div(t.sub(n));var u=j(1).div(e.sub(r));return r.add(j(1).div(Ja(i,u)))}else{return r.add(j(1))}}function w(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof w)||typeof this==="undefined"){return new w(e,t)}if(!j.isRational(e)){throw new Error("Invalid constructor call for LRational")}var r,n;if(e instanceof w){r=j(e.__num__);n=j(e.__denom__)}else{r=j(e.num);n=j(e.denom)}if(!t&&n.cmp(0)!==0){var i=r.op("%",n).cmp(0)===0;if(i){return j(r.div(n))}}this.constant(r,n)}w.prototype=Object.create(j.prototype);w.prototype.constructor=w;w.prototype.constant=function(e,t){Object.defineProperty(this,"__num__",{value:e,enumerable:true});Object.defineProperty(this,"__denom__",{value:t,enumerable:true});Object.defineProperty(this,"__type__",{value:"rational",enumerable:true})};w.prototype.serialize=function(){return{num:this.__num__,denom:this.__denom__}};w.prototype.pow=function(e){if(j.isRational(e)){return Ua(this.valueOf(),e.valueOf())}var t=e.cmp(0);if(t===0){return j(1)}if(t===-1){e=e.sub();var r=this.__denom__.pow(e);var n=this.__num__.pow(e);return w({num:r,denom:n})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};w.prototype.sqrt=function(){var e=this.__num__.sqrt();var t=this.__denom__.sqrt();if(e instanceof g||t instanceof g){return e.div(t)}return w({num:e,denom:t})};w.prototype.abs=function(){var e=this.__num__;var t=this.__denom__;if(e.cmp(0)===-1){e=e.sub()}if(t.cmp(0)!==1){t=t.sub()}return w({num:e,denom:t})};w.prototype.cmp=function(e){return j(this.valueOf(),true).cmp(e)};w.prototype.toString=function(){var e=this.__num__.gcd(this.__denom__);var t,r;if(e.cmp(1)!==0){t=this.__num__.div(e);if(t instanceof w){t=j(t.valueOf(true))}r=this.__denom__.div(e);if(r instanceof w){r=j(r.valueOf(true))}}else{t=this.__num__;r=this.__denom__}var n=this.cmp(0)<0;if(n){if(t.abs().cmp(r.abs())===0){return t.toString()}}else if(t.cmp(r)===0){return t.toString()}return t.toString()+"/"+r.toString()};w.prototype.valueOf=function(e){if(this.__denom__.cmp(0)===0){if(this.__num__.cmp(0)<0){return Number.NEGATIVE_INFINITY}return Number.POSITIVE_INFINITY}if(e){return j._ops["/"](this.__num__.value,this.__denom__.value)}return g(this.__num__.valueOf()).div(this.__denom__.valueOf())};w.prototype.mul=function(e){if(!(e instanceof j)){e=j(e)}if(j.isRational(e)){var t=this.__num__.mul(e.__num__);var r=this.__denom__.mul(e.__denom__);return w({num:t,denom:r})}var n=j.coerce(this,e),i=b(n,2),u=i[0],a=i[1];return u.mul(a)};w.prototype.div=function(e){if(!(e instanceof j)){e=j(e)}if(j.isRational(e)){var t=this.__num__.mul(e.__denom__);var r=this.__denom__.mul(e.__num__);return w({num:t,denom:r})}var n=j.coerce(this,e),i=b(n,2),u=i[0],a=i[1];var o=u.div(a);return o};w.prototype._op=function(e,t){return this[qa[e]](t)};w.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof j)){e=j(e)}if(j.isRational(e)){var t=e.__num__.sub();var r=e.__denom__;return this.add(w({num:t,denom:r}))}if(!(e instanceof j)){e=j(e).sub()}else{e=e.sub()}var n=j.coerce(this,e),i=b(n,2),u=i[0],a=i[1];return u.add(a)};w.prototype.add=function(e){if(!(e instanceof j)){e=j(e)}if(j.isRational(e)){var t=this.__denom__;var r=e.__denom__;var n=this.__num__;var i=e.__num__;var u,a;if(t!==r){a=r.mul(n).add(i.mul(t));u=t.mul(r)}else{a=n.add(i);u=t}return w({num:a,denom:u})}if(j.isFloat(e)){return g(this.valueOf()).add(e)}var o=j.coerce(this,e),s=b(o,2),c=s[0],f=s[1];return c.add(f)};function Ka(e,t){if(typeof this!=="undefined"&&!(this instanceof Ka)||typeof this==="undefined"){return new Ka(e,t)}if(e instanceof Ka){return Ka(e.__value__,e._native)}if(!j.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.constant(e,"bigint");Object.defineProperty(this,"_native",{value:t})}Ka.prototype=Object.create(j.prototype);Ka.prototype.constructor=Ka;Ka.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};Ka.prototype.serialize=function(){return this.__value__.toString()};Ka.prototype._op=function(e,t){if(typeof t==="undefined"){if(j.isBN(this.__value__)){e=Ka.bn_op[e];return Ka(this.__value__.clone()[e](),false)}return Ka(j._ops[e](this.__value__),true)}if(j.isBN(this.__value__)&&j.isBN(t.__value__)){e=Ka.bn_op[e];return Ka(this.__value__.clone()[e](t),false)}var r=j._ops[e](this.__value__,t.__value__);if(e==="/"){var n=this.op("%",t).cmp(0)===0;if(n){return j(r)}return w({num:this,denom:t})}return Ka(r,true)};Ka.prototype.sqrt=function(){var e;var t=this.cmp(0)<0;if(j.isNative(this.__value__)){e=j(Math.sqrt(t?-this.valueOf():this.valueOf()))}else if(j.isBN(this.__value__)){e=t?this.__value__.neg().sqrt():this.__value__.sqrt()}if(t){return y({re:0,im:e})}return e};j.NaN=j(NaN);y.i=y({im:1,re:0});function Ha(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof Ha)||typeof this==="undefined"){return new Ha(e)}F("InputPort",e,"function");c(this,"__type__",ao);var i;Object.defineProperty(this,"__parser__",{enumerable:true,get:function e(){return i},set:function e(t){F("InputPort::__parser__",t,"parser");i=t}});this._read=e;this._with_parser=this._with_init_parser.bind(this,ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(n.char_ready()){t.next=5;break}t.next=3;return n._read();case 3:r=t.sent;i=new hi(r,{env:n});case 5:return t.abrupt("return",n.__parser__);case 6:case"end":return t.stop()}},e)})));this.char_ready=function(){return!!this.__parser__&&this.__parser__.__lexer__.peek()!==oo};this._make_defaults()}Ha.prototype._make_defaults=function(){this.read=this._with_parser(function(e){return e.read_object()});this.read_line=this._with_parser(function(e){return e.__lexer__.read_line()});this.read_char=this._with_parser(function(e){return e.__lexer__.read_char()});this.read_string=this._with_parser(function(e,t){if(!j.isInteger(t)){var r=j.getType(t);Po("read-string",r,"integer")}return e.__lexer__.read_string(t.valueOf())});this.peek_char=this._with_parser(function(e){return e.__lexer__.peek_char()})};Ha.prototype._with_init_parser=function(o,s){var c=this;return ie(O.mark(function e(){var r,n,i,u,a=arguments;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return o.call(c);case 2:r=t.sent;for(n=a.length,i=new Array(n),u=0;u"};function Ga(e){if(typeof this!=="undefined"&&!(this instanceof Ga)||typeof this==="undefined"){return new Ga(e)}F("OutputPort",e,"function");c(this,"__type__",ao);this.write=e}Ga.prototype.is_open=function(){return this._closed!==true};Ga.prototype.close=function(){Object.defineProperty(this,"_closed",{get:function e(){return true},set:function e(){},configurable:false,enumerable:false});this.write=function(){throw new Error("output-port: port is closed")}};Ga.prototype.flush=function(){};Ga.prototype.toString=function(){return"#"};var Wa=function(e){R(r,e);function r(e){var t;ue(this,r);t=Pr(this,r,[function(){var e;return(e=t)._write.apply(e,arguments)}]);F("BufferedOutputPort",e,"function");c(L(t),"_fn",e,{hidden:true});c(L(t),"_buffer",[],{hidden:true});return t}ce(r,[{key:"flush",value:function e(){if(this._buffer.length){this._fn(this._buffer.join(""));this._buffer.length=0}}},{key:"_write",value:function e(){var t=this;for(var r=arguments.length,n=new Array(r),i=0;i"};Qa.prototype.valueOf=function(){return this.__buffer__.map(function(e){return e.valueOf()}).join("")};function Za(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof Za)||typeof this==="undefined"){return new Za(e,t)}F("OutputFilePort",e,"string");c(this,"__filename__",e);c(this,"_fd",t.valueOf(),{hidden:true});c(this,"__type__",ao);this.write=function(e){if(!x.isString(e)){e=fu(e)}else{e=e.valueOf()}r.fs().write(r._fd,e,function(e){if(e){throw e}})}}Za.prototype=Object.create(Ga.prototype);Za.prototype.constructor=Za;Za.prototype.fs=function(){if(!this._fs){this._fs=this.internal("fs")}return this._fs};Za.prototype.internal=function(e){return xo.get("**internal-env**").get(e)};Za.prototype.close=function(){var n=this;return new Promise(function(t,r){n.fs().close(n._fd,function(e){if(e){r(e)}else{c(n,"_fd",null,{hidden:true});Ga.prototype.close.call(n);t()}})})};Za.prototype.toString=function(){return"#")};function Xa(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof Xa)||typeof this==="undefined"){return new Xa(e)}F("InputStringPort",e,"string");t=t||W;e=e.valueOf();this._with_parser=this._with_init_parser.bind(this,function(){if(!r.__parser__){r.__parser__=new hi(e,{env:t})}return r.__parser__});c(this,"__type__",ao);this._make_defaults()}Xa.prototype.char_ready=function(){return true};Xa.prototype=Object.create(Ha.prototype);Xa.prototype.constructor=Xa;Xa.prototype.toString=function(){return"#"};function eo(e){if(typeof this!=="undefined"&&!(this instanceof eo)||typeof this==="undefined"){return new eo(e)}F("InputByteVectorPort",e,"uint8array");c(this,"__vector__",e);c(this,"__type__",uo);var r=0;Object.defineProperty(this,"__index__",{enumerable:true,get:function e(){return r},set:function e(t){F("InputByteVectorPort::__index__",t,"number");if(t instanceof j){t=t.valueOf()}if(typeof t==="bigint"){t=Number(t)}if(Math.floor(t)!==t){throw new Error("InputByteVectorPort::__index__ value is "+"not integer")}r=t}})}eo.prototype=Object.create(Ha.prototype);eo.prototype.constructor=eo;eo.prototype.toString=function(){return"#"};eo.prototype.close=function(){var t=this;c(this,"__vector__",Y);var r=function e(){throw new Error("Input-binary-port: port is closed")};["read_u8","close","peek_u8","read_u8_vector"].forEach(function(e){t[e]=r});this.u8_ready=this.char_ready=function(){return false}};eo.prototype.u8_ready=function(){return true};eo.prototype.peek_u8=function(){if(this.__index__>=this.__vector__.length){return oo}return this.__vector__[this.__index__]};eo.prototype.skip=function(){if(this.__index__<=this.__vector__.length){++this.__index__}};eo.prototype.read_u8=function(){var e=this.peek_u8();this.skip();return e};eo.prototype.read_u8_vector=function(e){if(typeof e==="undefined"){e=this.__vector__.length}else if(e>this.__index__+this.__vector__.length){e=this.__index__+this.__vector__.length}if(this.peek_u8()===oo){return oo}return this.__vector__.slice(this.__index__,e)};function to(){if(typeof this!=="undefined"&&!(this instanceof to)||typeof this==="undefined"){return new to}c(this,"__type__",uo);c(this,"_buffer",[],{hidden:true});this.write=function(e){F("write",e,["number","uint8array"]);if(j.isNumber(e)){this._buffer.push(e.valueOf())}else{var t;(t=this._buffer).push.apply(t,U(Array.from(e)))}};Object.defineProperty(this,"__buffer__",{enumerable:true,get:function e(){return Uint8Array.from(this._buffer)}})}to.prototype=Object.create(Ga.prototype);to.prototype.constructor=to;to.prototype.close=function(){Ga.prototype.close.call(this);c(this,"_buffer",null,{hidden:true})};to.prototype._close_guard=function(){if(this._closed){throw new Error("output-port: binary port is closed")}};to.prototype.write_u8=function(e){F("OutputByteVectorPort::write_u8",e,"number");this.write(e)};to.prototype.write_u8_vector=function(e){F("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};to.prototype.toString=function(){return"#"};to.prototype.valueOf=function(){return this.__buffer__};function ro(e,t){if(typeof this!=="undefined"&&!(this instanceof ro)||typeof this==="undefined"){return new ro(e,t)}Xa.call(this,e);F("InputFilePort",t,"string");c(this,"__filename__",t)}ro.prototype=Object.create(Xa.prototype);ro.prototype.constructor=ro;ro.prototype.toString=function(){return"#")};function no(e,t){if(typeof this!=="undefined"&&!(this instanceof no)||typeof this==="undefined"){return new no(e,t)}eo.call(this,e);F("InputBinaryFilePort",t,"string");c(this,"__filename__",t)}no.prototype=Object.create(eo.prototype);no.prototype.constructor=no;no.prototype.toString=function(){return"#")};function io(e,t){var i=this;if(typeof this!=="undefined"&&!(this instanceof io)||typeof this==="undefined"){return new io(e,t)}F("OutputBinaryFilePort",e,"string");c(this,"__filename__",e);c(this,"_fd",t.valueOf(),{hidden:true});c(this,"__type__",uo);var u;this.write=function(e){F("write",e,["number","uint8array"]);var n;if(!u){u=i.internal("fs")}if(j.isNumber(e)){n=new Uint8Array([e.valueOf()])}else{n=new Uint8Array(Array.from(e))}return new Promise(function(t,r){u.write(i._fd,n,function(e){if(e){r(e)}else{t()}})})}}io.prototype=Object.create(Za.prototype);io.prototype.constructor=io;io.prototype.write_u8=function(e){F("OutputByteVectorPort::write_u8",e,"number");this.write(e)};io.prototype.write_u8_vector=function(e){F("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};var uo=Symbol["for"]("binary");var ao=Symbol["for"]("text");var oo=new so;function so(){}so.prototype.toString=function(){return"#"};function co(e){var t=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=r.stderr,i=r.stdin,u=r.stdout,a=r.command_line,o=a===void 0?null:a,s=le(r,Or);if(typeof this!=="undefined"&&!(this instanceof co)||typeof this==="undefined"){return new co(e,z({stdin:i,stdout:u,stderr:n,command_line:o},s))}if(typeof e==="undefined"){e="anonymous"}this.__env__=xo.inherit(e,s);this.__env__.set("parent.frame",l("parent.frame",function(){return t.__env__},W.__env__["parent.frame"].__doc__));var c="**interaction-environment-defaults**";this.set(c,uu(s).concat(c));var f=bo.inherit("internal-".concat(e));if(ea(i)){f.set("stdin",i)}if(ea(n)){f.set("stderr",n)}if(ea(u)){f.set("stdout",u)}f.set("command-line",o);Eo(this.__env__,f)}co.prototype.exec=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=t.use_dynamic,n=r===void 0?false:r,i=t.dynamic_env,u=t.env;F("Interpreter::exec",e,["string","array"],1);F("Interpreter::exec",n,"boolean",2);if(!u){u=this.__env__}if(!i){i=u}W.set("**interaction-environment**",this.__env__);return es(e,{env:u,dynamic_env:i,use_dynamic:n})};co.prototype.get=function(e){var t=this.__env__.get(e);if(d(t)){var r=new Wo({env:this.__env__});return t.bind(r)}return t};co.prototype.set=function(e,t){return this.__env__.set(e,t)};co.prototype.constant=function(e,t){return this.__env__.constant(e,t)};function fo(e,t){this.name="LipsError";this.message=e;this.args=t;this.stack=(new Error).stack}fo.prototype=new Error;fo.prototype.constructor=fo;var lo=function(e){R(t,e);function t(){ue(this,t);return Pr(this,t,arguments)}return ce(t)}(T(Error));function E(e,t,r){if(arguments.length===1){if(_(arguments[0])==="object"){e=arguments[0];t=null}else if(typeof arguments[0]==="string"){e={};t=null;r=arguments[0]}}this.__docs__=new Map;this.__env__=e;this.__parent__=t;this.__name__=r||"anonymous"}E.prototype.list=function(){return uu(this.__env__)};E.prototype.fs=function(){return this.get("**fs**")};E.prototype.unset=function(e){if(e instanceof $){e=e.valueOf()}if(e instanceof x){e=e.valueOf()}delete this.__env__[e]};E.prototype.inherit=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(_(e)==="object"){t=e}if(!e||_(e)==="object"){e="child of "+(this.__name__||"unknown")}return new E(t||{},this,e)};E.prototype.doc=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(e instanceof $){e=e.__name__}if(e instanceof x){e=e.valueOf()}if(t){if(!r){t=wi(t)}this.__docs__.set(e,t);return this}if(this.__docs__.has(e)){return this.__docs__.get(e)}if(this.__parent__){return this.__parent__.doc(e)}};E.prototype.new_frame=function(e,t){var n=this.inherit("__frame__");n.set("parent.frame",l("parent.frame",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;e=e.valueOf();var t=n.__parent__;if(!Nu(t)){return Y}if(e<=0){return t}var r=t.get("parent.frame");return r(e-1)},W.__env__["parent.frame"].__doc__));t.callee=e;n.set("arguments",t);return n};E.prototype._lookup=function(e){if(e instanceof $){e=e.__name__}if(e instanceof x){e=e.valueOf()}if(this.__env__.hasOwnProperty(e)){return ho(this.__env__[e])}if(this.__parent__){return this.__parent__._lookup(e)}};E.prototype.toString=function(){return"#"};E.prototype.clone=function(){var t=this;var r={};Object.keys(this.__env__).forEach(function(e){r[e]=t.__env__[e]});return new E(r,this.__parent__,this.__name__)};E.prototype.merge=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"merge";F("Environment::merge",e,"environment");return this.inherit(t,e.__env__)};function ho(e){if(typeof this!=="undefined"&&!(this instanceof ho)||typeof this==="undefined"){return new ho(e)}this.value=e}ho.isUndefined=function(e){return e instanceof ho&&typeof e.value==="undefined"};ho.prototype.valueOf=function(){return this.value};function _o(e){if(!e.length){return}if(e.length===1){return e[0]}if(typeof this!=="undefined"&&!(this instanceof _o)||typeof this==="undefined"){return new _o(e)}this.__values__=e}_o.prototype.toString=function(){return this.__values__.map(function(e){return fu(e)}).join("\n")};_o.prototype.valueOf=function(){return this.__values__};E.prototype.get=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};F("Environment::get",e,["symbol","string"]);var r=t.throwError,n=r===void 0?true:r;var i=e;if(i instanceof $||i instanceof x){i=i.valueOf()}var u=this._lookup(i);if(u instanceof ho){if(ho.isUndefined(u)){return undefined}return Hu(u.valueOf())}var a;if(e instanceof $&&e[$.object]){a=e[$.object]}else if(typeof i==="string"){a=i.split(".").filter(Boolean)}if(a&&a.length>0){var o=a,s=re(o),c=s[0],f=s.slice(1);u=this._lookup(c);if(f.length){try{if(u instanceof ho){u=u.valueOf()}else{u=mo(zr,c);if(d(u)){u=Gu(u)}}if(typeof u!=="undefined"){return mo.apply(void 0,[u].concat(U(f)))}}catch(e){throw e}}else if(u instanceof ho){return Hu(u.valueOf())}u=mo(zr,i)}if(typeof u!=="undefined"){return u}if(n){throw new Error("Unbound variable `"+i.toString()+"'")}};E.prototype.set=function(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;F("Environment::set",e,["string","symbol"]);if(j.isNumber(t)){t=j(t)}if(e instanceof $){e=e.__name__}if(e instanceof x){e=e.valueOf()}this.__env__[e]=t;if(r){this.doc(e,r,true)}return this};E.prototype.constant=function(t,e){var r=this;if(this.__env__.hasOwnProperty(t)){throw new Error("Environment::constant: ".concat(t," already exists"))}if(arguments.length===1&&Qi(arguments[0])){var n=arguments[0];Object.keys(n).forEach(function(e){r.constant(t,n[e])})}else{Object.defineProperty(this.__env__,t,{value:e,enumerable:true})}return this};E.prototype.has=function(e){return this.__env__.hasOwnProperty(e)};E.prototype.ref=function(e){var t=this;while(true){if(!t){break}if(t.has(e)){return t}t=t.__parent__}};E.prototype.parents=function(){var e=this;var t=[];while(e){t.unshift(e);e=e.__parent__}return t};function po(e){if(Mu(e)){return e.then(po)}if(G(e)||e instanceof $){e[ia]=true}return e}var vo=pi(Jn('(lambda ()\n "[native code]"\n (throw "Invalid Invocation"))'))[0];var mo=l("get",function e(t){var r;for(var n=arguments.length,i=new Array(n>1?n-1:0),u=1;u0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=yo(this,"stdin")}Mo("peek-char",e,"input-port");return e.peek_char()},"(peek-char port)\n\n This function reads and returns a character from the string\n port, or, if there is no more data in the string port, it\n returns an EOF."),"read-line":l("read-line",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=yo(this,"stdin")}Mo("read-line",e,"input-port");return e.read_line()},"(read-line port)\n\n This function reads and returns the next line from the input\n port."),"read-char":l("read-char",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=yo(this,"stdin")}Mo("read-char",e,"input-port");return e.read_char()},"(read-char port)\n\n This function reads and returns the next character from the\n input port."),read:l("read",function(){var e=ie(function(){var i=this;var u=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;return O.mark(function e(){var r,n;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=i.env;if(u===null){n=yo(r,"stdin")}else{n=u}Mo("read",n,"input-port");return t.abrupt("return",n.read.call(r));case 4:case"end":return t.stop()}},e)})()});function t(){return e.apply(this,arguments)}return t}(),"(read [port])\n\n This function, if called with a port, it will parse the next\n item from the port. If called without an input, it will read\n a string from standard input (using the browser's prompt or\n a user defined input method) and parse it. This function can be\n used together with `eval` to evaluate code from port."),pprint:l("pprint",function e(t){if(G(t)){t=new Ts.Formatter(t.toString(true))["break"]().format();W.get("display").call(W,t)}else{W.get("write").call(W,t)}W.get("newline").call(W)},"(pprint expression)\n\n This function will pretty print its input to stdout. If it is called\n with a non-list, it will just call the print function on its\n input."),print:l("print",function e(){var t=W.get("display");var r=W.get("newline");var n=this.use_dynamic;var i=W;var u=W;for(var a=arguments.length,o=new Array(a),s=0;s1?r-1:0),i=1;in.length){throw new Error("Not enough arguments")}var o=0;var s=W.get("repr");t=t.replace(u,function(e){var t=e[1];if(t==="~"){return"~"}else if(t==="%"){return"\n"}else{var r=n[o++];if(t==="a"){return s(r)}else{return s(r,true)}}});a=t.match(/~([\S])/);if(a){throw new Error("format: Unrecognized escape sequence ".concat(a[1]))}return t},"(format string n1 n2 ...)\n\n This function accepts a string template and replaces any\n escape sequences in its inputs:\n\n * ~a value as if printed with `display`\n * ~s value as if printed with `write`\n * ~% newline character\n * ~~ literal tilde '~'\n\n If there are missing inputs or other escape characters it\n will error."),display:l("display",function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(r===null){r=yo(this,"stdout")}else{F("display",r,"output-port")}var n=t;if(!(r instanceof io)){n=W.get("repr")(t)}r.write.call(W,n)},"(display string [port])\n\n This function outputs the string to the standard output or\n the port if given. No newline."),"display-error":l("display-error",function e(){var t=yo(this,"stderr");var r=W.get("repr");for(var n=arguments.length,i=new Array(n),u=0;u1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=le(t,Cr);var i=this;var a=this;var o;var s=z(z({},n),{},{env:this,dynamic_env:i,use_dynamic:r});var c=A(e.cdr.car,s);c=Uo(c);function f(t,r,n){if(Mu(t)){return t.then(function(e){return f(t,e,n)})}if(Mu(r)){return r.then(function(e){return f(t,e,n)})}if(Mu(n)){return n.then(function(e){return f(t,r,e)})}a.get("set-obj!").call(a,t,r,n);return n}if(G(e.car)&&$.is(e.car.car,".")){var l=e.car.cdr.car;var h=e.car.cdr.cdr.car;var _=A(l,s);var p=A(h,s);return f(_,p,c)}if(!(e.car instanceof $)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var d=e.car.valueOf();o=this.ref(e.car.__name__);return D(c,function(e){if(!o){var t=d.split(".");if(t.length>1){var r=t.pop();var n=t.join(".");var i=u.get(n,{throwError:false});if(i){f(i,r,e);return}}throw new Error("Unbound variable `"+d+"'")}o.set(d,e)})}),"(set! name value)\n\n Macro that can be used to set the value of the variable or slot (mutate it).\n set! searches the scope chain until it finds first non empty slot and sets it."),"unset!":l(new K("set!",function(e){if(!(e.car instanceof $)){throw new Error("unset! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var t=e.car;var r=this.ref(t);if(r){delete r.__env__[t.__name__]}}),"(unset! name)\n\n Function to delete the specified name from environment.\n Trying to access the name afterwards will error."),"set-car!":l("set-car!",function(e,t){F("set-car!",e,"pair");e.car=t},"(set-car! obj value)\n\n Function that sets the car (first item) of the list/pair to specified value.\n The old value is lost."),"set-cdr!":l("set-cdr!",function(e,t){F("set-cdr!",e,"pair");e.cdr=t},"(set-cdr! obj value)\n\n Function that sets the cdr (tail) of the list/pair to specified value.\n It will destroy the list. The old tail is lost."),"empty?":l("empty?",function(e){return typeof e==="undefined"||H(e)},"(empty? object)\n\n Function that returns #t if value is nil (an empty list) or undefined."),gensym:l("gensym",Qn,"(gensym)\n\n Generates a unique symbol that is not bound anywhere,\n to use with macros as meta name."),load:l("load",function e(o,t){F("load",o,"string");var s=this;if(s.__name__==="__frame__"){s=s.__parent__}if(!(t instanceof E)){if(s===W){t=s}else{t=this.get("**interaction-environment**")}}var c="**module-path**";var f=W.get(c,{throwError:false});o=o.valueOf();if(!o.match(/.[^.]+$/)){o+=".scm"}var r=o.match(/\.xcb$/);function l(e){if(r){e=Os(e)}else{if(qo(e)==="buffer"){e=e.toString()}e=e.replace(/^(#!.*)/,function(e,t){if(Ou(t)){return t}return""});if(e.match(/^\{/)){e=ws(e)}}return es(e,{env:t})}function n(e){return zr.fetch(e).then(function(e){return r?e.arrayBuffer():e.text()}).then(function(e){if(r){e=new Uint8Array(e)}return e})}if(So()){return new Promise(function(){var r=ie(O.mark(function e(r,n){var i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:i=Kr("path");if(!f){t.next=6;break}f=f.valueOf();o=i.join(f,o);t.next=12;break;case 6:u=s.get("command-line",{throwError:false});if(!u){t.next=11;break}t.next=10;return u();case 10:a=t.sent;case 11:if(a&&!H(a)){process.cwd();o=i.join(i.dirname(a.car.valueOf()),o)}case 12:W.set(c,i.dirname(o));Kr("fs").readFile(o,function(e,t){if(e){n(e);W.set(c,f)}else{try{l(t).then(function(){r();W.set(c,f)})["catch"](n)}catch(e){n(e)}}});case 14:case"end":return t.stop()}},e)}));return function(e,t){return r.apply(this,arguments)}}())}if(f){f=f.valueOf();o=f+"/"+o.replace(/^\.?\/?/,"")}return n(o).then(function(e){W.set(c,o.replace(/\/[^/]*$/,""));return l(e)}).then(function(){})["finally"](function(){W.set(c,f)})},"(load filename)\n (load filename environment)\n\n Fetches the file (from disk or network) and evaluates its content as LIPS code.\n If the second argument is provided and it's an environment the evaluation\n will happen in that environment."),while:l(new K("while",function(e,t){var r=e.car;var n=z(z({},t),{},{env:this});var i=new J(new $("begin"),e.cdr);return function t(){return D(A(r,n),function(e){if(e){return D(A(i,n),t)}})}()}),"(while cond body)\n\n Creates a loop, it executes cond and body until cond expression is false."),do:l(new K("do",function(){var r=ie(function(h,e){var _=this;var p=e.use_dynamic,d=e.error;return O.mark(function e(){var o,r,s,c,n,f,l,i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:o=_;r=o;s=o.inherit("do");c=h.car;n=h.cdr.car;f=h.cdr.cdr;if(!H(f)){f=new J($("begin"),f)}l={env:o,dynamic_env:r,use_dynamic:p,error:d};i=c;case 9:if(H(i)){t.next=20;break}u=i.car;t.t0=s;t.t1=u.car;t.next=15;return A(u.cdr.car,l);case 15:t.t2=t.sent;t.t0.set.call(t.t0,t.t1,t.t2);i=i.cdr;t.next=9;break;case 20:l={env:s,dynamic_env:r,error:d};a=O.mark(function e(){var r,n,i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(H(f)){t.next=3;break}t.next=3;return Ts.evaluate(f,l);case 3:r=c;n={};case 5:if(H(r)){t.next=15;break}i=r.car;if(H(i.cdr.cdr)){t.next=12;break}t.next=10;return A(i.cdr.cdr.car,l);case 10:u=t.sent;n[i.car.valueOf()]=u;case 12:r=r.cdr;t.next=5;break;case 15:a=Object.getOwnPropertySymbols(n);l.env=s=o.inherit("do");Object.keys(n).concat(a).forEach(function(e){s.set(e,n[e])});case 18:case"end":return t.stop()}},e)});case 22:t.next=24;return A(n.car,l);case 24:t.t3=t.sent;if(!(t.t3===false)){t.next=29;break}return t.delegateYield(a(),"t4",27);case 27:t.next=22;break;case 29:if(H(n.cdr)){t.next=33;break}t.next=32;return A(n.cdr.car,l);case 32:return t.abrupt("return",t.sent);case 33:case"end":return t.stop()}},e)})()});return function(e,t){return r.apply(this,arguments)}}()),"(do (( )) (test return) . body)\n\n Iteration macro that evaluates the expression body in scope of the variables.\n On each loop it changes the variables according to the expression and runs\n test to check if the loop should continue. If test is a single value, the macro\n will return undefined. If the test is a pair of expressions the macro will\n evaluate and return the second expression after the loop exits."),if:l(new K("if",function(r,e){var t=e.error,n=e.use_dynamic;var i=this;var u=this;var a={env:u,dynamic_env:i,use_dynamic:n,error:t};var o=function e(t){if(Cu(t)){return A(r.cdr.cdr.car,a)}else{return A(r.cdr.car,a)}};if(H(r)){throw new Error("too few expressions for `if`")}var s=A(r.car,a);return D(s,o)}),"(if cond true-expr false-expr)\n\n Macro that evaluates cond expression and if the value is true, it\n evaluates and returns true-expression, if not it evaluates and returns\n false-expression."),"let-env":new K("let-env",function(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=e.dynamic_env,n=e.use_dynamic,i=e.error;F("let-env",t,"pair");var u=A(t.car,{env:this,dynamic_env:r,error:i,use_dynamic:n});return D(u,function(e){F("let-env",e,"environment");return A(J($("begin"),t.cdr),{env:e,dynamic_env:r,error:i})})},"(let-env env . body)\n\n Special macro that evaluates body in context of given environment\n object."),letrec:l(ga(Symbol["for"]("letrec")),"(letrec ((a value-a) (b value-b) ...) . body)\n\n Macro that creates a new environment, then evaluates and assigns values to\n names and then evaluates the body in context of that environment.\n Values are evaluated sequentially and the next value can access the\n previous values/names."),"letrec*":l(ga(Symbol["for"]("letrec")),"(letrec* ((a value-a) (b value-b) ...) . body)\n\n Same as letrec but the order of execution of the binding is guaranteed,\n so you can use recursive code as well as referencing the previous binding.\n\n In LIPS both letrec and letrec* behave the same."),"let*":l(ga(Symbol["for"]("let*")),"(let* ((a value-a) (b value-b) ...) . body)\n\n Macro similar to `let`, but the subsequent bindings after the first\n are evaluated in the environment including the previous let variables,\n so you can define one variable, and use it in the next's definition."),let:l(ga(Symbol["for"]("let")),"(let ((a value-a) (b value-b) ...) . body)\n\n Macro that creates a new environment, then evaluates and assigns values to names,\n and then evaluates the body in context of that environment. Values are evaluated\n sequentially but you can't access previous values/names when the next are\n evaluated. You can only get them in the body of the let expression. (If you want\n to define multiple variables and use them in each other's definitions, use\n `let*`.)"),"begin*":l(ba("begin*",function(e){return e.pop()}),"(begin* . body)\n\n This macro is a parallel version of begin. It evaluates each expression\n in the body and if it's a promise it will await it in parallel and return\n the value of the last expression (i.e. it uses Promise.all())."),shuffle:l("shuffle",function(e){F("shuffle",e,["pair","nil","array"]);var t=W.get("random");if(H(e)){return Y}if(Array.isArray(e)){return Ki(e.slice(),t)}var r=W.get("list->array")(e);r=Ki(r,t);return W.get("array->list")(r)},"(shuffle obj)\n\n Order items in vector or list in random order."),begin:l(new K("begin",function(e,t){var n=z(z({},t),{},{env:this});var i=W.get("list->array")(e);var u;return function t(){if(i.length){var e=i.shift();var r=A(e,n);return D(r,function(e){u=e;return t()})}else{return u}}()}),"(begin . args)\n\n Macro that runs a list of expressions in order and returns the value\n of the last one. It can be used in places where you can only have a\n single expression, like (if)."),ignore:new K("ignore",function(e,t){var r=z(z({},t),{},{env:this,dynamic_env:this});A(new J(new $("begin"),e),r)},"(ignore . body)\n\n Macro that will evaluate the expression and swallow any promises that may\n be created. It will discard any value that may be returned by the last body\n expression. The code should have side effects and/or when it's promise\n it should resolve to undefined."),"call/cc":l(K.defmacro("call/cc",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=z({env:this},t);return D(A(e.car,r),function(e){if(d(e)){return e(new Zo(null))}})}),"(call/cc proc)\n\n Call-with-current-continuation.\n\n NOT SUPPORTED BY LIPS RIGHT NOW"),parameterize:l(new K("parameterize",function(t,e){var i=e.dynamic_env;var u=i.inherit("parameterize").new_frame(null,{});var a=z(z({},e),{},{env:this});var o=t.car;if(!G(o)){var r=qo(o);throw new Error("Invalid syntax for parameterize expecting pair got ".concat(r))}function s(){var e=new J(new $("begin"),t.cdr);return A(e,z(z({},a),{},{dynamic_env:u}))}return function r(){var e=o.car;var n=e.car.valueOf();return D(A(e.cdr.car,a),function(e){var t=i.get(n,{throwError:false});if(!Pu(t)){throw new Error("Unknown parameter ".concat(n))}u.set(n,t.inherit(e));if(!ku(o.cdr)){o=o.cdr;return r()}else{return s()}})}()}),"(parameterize ((name value) ...)\n\n Macro that change the dynamic variable created by make-parameter."),"make-parameter":l(new K("make-parameter",function(e,t){t.dynamic_env;var r=A(e.car,t);var n;if(G(e.cdr.car)){n=A(e.cdr.car,t)}return new Go(r,n)}),"(make-parameter init converter)\n\n Function creates new dynamic variable that can be custimized with parameterize\n macro. The value should be assigned to a variable e.g.:\n\n (define radix (make-parameter 10))\n\n The result value is a procedure that return the value of dynamic variable."),"define-syntax-parameter":l(new K("define-syntax-parameter",function(e,t){var r=e.car;var n=this;if(!(r instanceof $)){throw new Error("define-syntax-parameter: invalid syntax expecting symbol got ".concat(qo(r)))}var i=A(e.cdr.car,z({env:n},t));F("define-syntax-parameter",i,"syntax",2);i.__name__=r.valueOf();if(i.__name__ instanceof x){i.__name__=i.__name__.valueOf()}var u;if(G(e.cdr.cdr)&&x.isString(e.cdr.cdr.car)){u=e.cdr.cdr.car.valueOf()}n.set(e.car,new xu(i),u,true)}),"(define-syntax-parameter name syntax [__doc__])\n\n Binds to the transformer obtained by evaluating .\n The transformer provides the default expansion for the syntax parameter,\n and in the absence of syntax-parameterize, is functionally equivalent to\n define-syntax."),"syntax-parameterize":l(new K("syntax-parameterize",function(e,t){var r=W.get("list->array")(e.car);var n=this.inherit("syntax-parameterize");while(r.length){var i=r.shift();if(!(G(i)||i.car instanceof $)){var u="invalid syntax for syntax-parameterize: ".concat(Wi(e,true));throw new Error("syntax-parameterize: ".concat(u))}var a=A(i.cdr.car,z(z({},t),{},{env:this}));var o=i.car;F("syntax-parameterize",a,["syntax"]);F("syntax-parameterize",o,"symbol");a.__name__=o.valueOf();if(a.__name__ instanceof x){a.__name__=a.__name__.valueOf()}var s=new xu(a);if(o.is_gensym()){var c=o.literal();var f=this.get(c,{throwError:false});if(f instanceof xu){n.set(c,s)}}n.set(o,s)}var l=new J(new $("begin"),e.cdr);return A(l,z(z({},t),{},{env:n}))}),"(syntax-parameterize (bindings) body)\n\n Macro work similar to let-syntax but the the bindnds will be exposed to the user.\n With syntax-parameterize you can define anaphoric macros."),define:l(K.defmacro("define",function(r,e){var n=this;if(G(r.car)&&r.car.car instanceof $){var t=new J(new $("define"),new J(r.car.car,new J(new J(new $("lambda"),new J(r.car.cdr,r.cdr)))));return t}else if(e.macro_expand){return}e.dynamic_env=this;e.env=n;var i=r.cdr.car;var u;if(G(i)){i=A(i,e);u=true}else if(i instanceof $){i=n.get(i)}F("define",r.car,"symbol");return D(i,function(e){if(n.__name__===Du.__merge_env__){n=n.__parent__}if(u&&(d(e)&&da(e)||e instanceof Du||Pu(e))){e.__name__=r.car.valueOf();if(e.__name__ instanceof x){e.__name__=e.__name__.valueOf()}}var t;if(G(r.cdr.cdr)&&x.isString(r.cdr.cdr.car)){t=r.cdr.cdr.car.valueOf()}n.set(r.car,e,t,true)})}),'(define name expression)\n (define name expression "doc string")\n (define (function-name . args) . body)\n\n Macro for defining values. It can be used to define variables,\n or functions. If the first argument is list it will create a function\n with name being first element of the list. This form expands to\n `(define function-name (lambda args body))`'),"set-obj!":l("set-obj!",function(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;var i=_(e);if(ku(e)||i!=="object"&&i!=="function"){var u=Po("set-obj!",qo(e),["object","function"]);throw new Error(u)}F("set-obj!",t,["string","symbol","number"]);e=Gu(e);t=t.valueOf();if(arguments.length===2){delete e[t]}else if(ju(e)&&d(r)){e[t]=Gu(r);e[t][ca]=true}else if(d(r)||Vu(r)||H(r)){e[t]=r}else{e[t]=r&&!ju(r)?r.valueOf():r}if(Zi){var a=e[t];Object.defineProperty(e,t,z(z({},n),{},{value:a}))}},"(set-obj! obj key value)\n (set-obj! obj key value props)\n\n Function set a property of a JavaScript object. props should be a vector of pairs,\n passed to Object.defineProperty."),"null-environment":l("null-environment",function(){return W.inherit("null")},"(null-environment)\n\n Returns a clean environment with only the standard library."),values:l("values",function e(){for(var t=arguments.length,r=new Array(t),n=0;n1&&arguments[1]!==undefined?arguments[1]:{},m=e.use_dynamic,y=e.error;var g=this;var b;if(G(v.cdr)&&x.isString(v.cdr.car)&&!H(v.cdr.cdr)){b=v.cdr.car.valueOf()}function w(){var e=Iu(this)?this:{dynamic_env:g},r=e.dynamic_env;var n=g.inherit("lambda");r=r.inherit("lambda");if(this&&!Iu(this)){if(this&&!this.__instance__){Object.defineProperty(this,"__instance__",{enumerable:false,get:function e(){return true},set:function e(){},configurable:false})}n.set("this",this)}for(var t=arguments.length,i=new Array(t),u=0;u> SYNTAX");V(e);V(y);var n=w.inherit("syntax");var i=n;var u=this;if(u.__name__===Du.__merge_env__){var a=Object.getOwnPropertySymbols(u.__env__);a.forEach(function(e){u.__parent__.set(e,u.__env__[e])});u=u.__parent__}var o={env:n,dynamic_env:i,use_dynamic:g,error:b};var s,c,f;if(y.car instanceof $){s=y.car;f=D(y.cdr.car);c=y.cdr.cdr}else{s="...";f=D(y.car);c=y.cdr}try{while(!H(c)){var l=c.car.car;var h=c.car.cdr.car;V("[[[ RULE");V(l);var _=Eu(l,e,f,s,{expansion:this,define:w});if(_){if(Wr()){console.log(JSON.stringify(iu(_),true,2));console.log("PATTERN: "+l.toString(true));console.log("MACRO: "+e.toString(true))}var p=[];var d=Au({bindings:_,expr:h,symbols:f,scope:n,lex_scope:u,names:p,ellipsis:s});V("OUPUT>>> ",d);if(d){h=d}var v=u.merge(n,Du.__merge_env__);if(r){return{expr:h,scope:v}}var m=A(h,z(z({},o),{},{env:v}));return Fu(m,p)}c=c.cdr}}catch(e){e.message+="\nin macro:\n ".concat(y.toString(true));throw e}throw new Error("syntax-rules: no matching syntax in macro ".concat(e.toString(true)))},w);r.__code__=y;return r},"(syntax-rules () (pattern expression) ...)\n\n Base of hygienic macros, it will return a new syntax expander\n that works like Lisp macros."),quote:l(new K("quote",function(e){return po(e.car)}),"(quote expression) or 'expression\n\n Macro that returns a single LIPS expression as data (it won't evaluate the\n argument). It will return a list if put in front of LIPS code.\n And if put in front of a symbol it will return the symbol itself, not the value\n bound to that name."),"unquote-splicing":l("unquote-splicing",function(){throw new Error("You can't call `unquote-splicing` outside of quasiquote")},"(unquote-splicing code) or ,@code\n\n Special form used in the quasiquote macro. It evaluates the expression inside and\n splices the list into quasiquote's result. If it is not the last element of the\n expression, the computed value must be a pair."),unquote:l("unquote",function(){throw new Error("You can't call `unquote` outside of quasiquote")},"(unquote code) or ,code\n\n Special form used in the quasiquote macro. It evaluates the expression inside and\n substitutes the value into quasiquote's result."),quasiquote:K.defmacro("quasiquote",function(e,t){var o=t.use_dynamic,s=t.error;var c=this;var f=c;function u(e){return G(e)||Qi(e)||Array.isArray(e)}function l(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:u;if(G(e)){var n=e.car;var i=e.cdr;if(r(n)){n=t(n)}if(r(i)){i=t(i)}if(Mu(n)||Mu(i)){return Xn([n,i]).then(function(e){var t=b(e,2),r=t[0],n=t[1];return new J(r,n)})}else{return new J(n,i)}}return e}function a(e,t){if(G(e)){if(!H(t)){e.append(t)}}else{e=new J(e,t)}return e}function r(e){return!!e.filter(function(e){return G(e)&&$.is(e.car,/^(unquote|unquote-splicing)$/)}).length}function h(e,n,i){return e.reduce(function(e,t){if(!G(t)){e.push(t);return e}if($.is(t.car,"unquote-splicing")){var r;if(n+11){var t="You can't splice multiple atoms inside list";throw new Error(t)}if(!(G(i.cdr)&&H(r[0]))){return r[0]}}r=r.map(function(e){if(d.has(e)){return e.clone()}else{d.add(e);return e}});var n=v(i.cdr,0,1);if(H(n)&&H(r[0])){return undefined}return D(n,function(e){if(H(r[0])){return e}if(r.length===1){return a(r[0],e)}var t=r.reduce(function(e,t){return a(e,t)});return a(t,e)})})}(i.car.cdr)}var d=new Set;function v(e,t,r){if(G(e)){if(G(e.car)){if($.is(e.car.car,"unquote-splicing")){return p(e,t+1,r)}if($.is(e.car.car,"unquote")){if(t+2===r&&G(e.car.cdr)&&G(e.car.cdr.car)&&$.is(e.car.cdr.car.car,"unquote-splicing")){var n=e.car.cdr;return new J(new J(new $("unquote"),p(n,t+2,r)),Y)}else if(G(e.car.cdr)&&!H(e.car.cdr.cdr)){if(G(e.car.cdr.car)){var i=[];return function t(r){if(H(r)){return J.fromArray(i)}return D(A(r.car,{env:c,dynamic_env:f,use_dynamic:o,error:s}),function(e){i.push(e);return t(r.cdr)})}(e.car.cdr)}else{return e.car.cdr}}}}if($.is(e.car,"quasiquote")){var u=v(e.cdr,t,r+1);return new J(e.car,u)}if($.is(e.car,"quote")){return new J(e.car,v(e.cdr,t,r))}if($.is(e.car,"unquote")){t++;if(tr){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(G(e.cdr)){if(!H(e.cdr.cdr)){if(G(e.cdr.car)){var a=[];return function t(r){if(H(r)){return J.fromArray(a)}return D(A(r.car,{env:c,dynamic_env:f,use_dynamic:o,error:s}),function(e){a.push(e);return t(r.cdr)})}(e.cdr)}else{return e.cdr}}else{return A(e.cdr.car,{env:c,dynamic_env:f,error:s})}}else{return e.cdr}}return l(e,function(e){return v(e,t,r)})}else if(Qi(e)){return _(e,t,r)}else if(e instanceof Array){return h(e,t,r)}return e}function n(e){if(G(e)){delete e[ia];if(!e.have_cycles("car")){n(e.car)}if(!e.have_cycles("cdr")){n(e.cdr)}}}if(Qi(e.car)&&!r(Object.values(e.car))){return po(e.car)}if(Array.isArray(e.car)&&!r(e.car)){return po(e.car)}if(G(e.car)&&!e.car.find("unquote")&&!e.car.find("unquote-splicing")&&!e.car.find("quasiquote")){return po(e.car)}var i=v(e.car,0,1);return D(i,function(e){n(e);return po(e)})},"(quasiquote list)\n\n Similar macro to `quote` but inside it you can use special expressions (unquote\n x) abbreviated to ,x that will evaluate x and insert its value verbatim or\n (unquote-splicing x) abbreviated to ,@x that will evaluate x and splice the value\n into the result. Best used with macros but it can be used outside."),clone:l("clone",function e(t){F("clone",t,"pair");return t.clone()},"(clone list)\n\n Function that returns a clone of the list, that does not share any pairs with the\n original, so the clone can be safely mutated without affecting the original."),append:l("append",function e(){var t;for(var r=arguments.length,n=new Array(r),i=0;iarray")(t).reverse();return W.get("array->list")(r)}else if(Array.isArray(t)){return t.reverse()}else{throw new Error(Po("reverse",qo(t),"array or pair"))}},"(reverse list)\n\n Function that reverses the list or array. If value is not a list\n or array it will error."),nth:l("nth",function e(t,r){F("nth",t,"number");F("nth",r,["array","pair"]);if(G(r)){var n=r;var i=0;while(iarray")(r).join(t)},"(join separator list)\n\n Function that returns a string by joining elements of the list using separator."),split:l("split",function e(t,r){F("split",t,["regex","string"]);F("split",r,"string");return W.get("array->list")(r.split(t))},"(split separator string)\n\n Function that creates a list by splitting string by separator which can\n be a string or regular expression."),replace:l("replace",function e(t,r,n){F("replace",t,["regex","string"]);F("replace",r,["string","function"]);F("replace",n,"string");if(d(r)){var i=[];n.replace(t,function(){i.push(r.apply(void 0,arguments))});return D(i,function(e){return n.replace(t,function(){return e.shift()})})}return n.replace(t,r)},"(replace pattern replacement string)\n\n Function that changes pattern to replacement inside string. Pattern can be a\n string or regex and replacement can be function or string. See Javascript\n String.replace()."),match:l("match",function e(t,r){F("match",t,["regex","string"]);F("match",r,"string");var n=r.match(t);return n?W.get("array->list")(n):false},"(match pattern string)\n\n Function that returns a match object from JavaScript as a list or #f if\n no match."),search:l("search",function e(t,r){F("search",t,["regex","string"]);F("search",r,"string");return r.search(t)},"(search pattern string)\n\n Function that returns the first found index of the pattern inside a string."),repr:l("repr",function e(t,r){return fu(t,r)},"(repr obj)\n\n Function that returns a LIPS code representation of the object as a string."),"escape-regex":l("escape-regex",function(e){F("escape-regex",e,"string");return Rn(e.valueOf())},"(escape-regex string)\n\n Function that returns a new string where all special operators used in regex,\n are escaped with backslashes so they can be used in the RegExp constructor\n to match a literal string."),env:l("env",function e(e){e=e||this.env;var t=Object.keys(e.__env__).map($);var r;if(t.length){r=J.fromArray(t)}else{r=Y}if(e.__parent__ instanceof E){return W.get("env").call(this,e.__parent__).append(r)}return r},"(env)\n (env obj)\n\n Function that returns a list of names (functions, macros and variables)\n that are bound in the current environment or one of its parents."),new:l("new",function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n2&&arguments[2]!==undefined?arguments[2]:ri.LITERAL;F("set-special!",e,"string",1);F("set-special!",t,"symbol",2);ri.append(e.valueOf(),t,r)},'(set-special! symbol name [type])\n\n Add a special symbol to the list of transforming operators by the parser.\n e.g.: `(add-special! "#" \'x)` will allow to use `#(1 2 3)` and it will be\n transformed into (x (1 2 3)) so you can write x macro that will process\n the list. 3rd argument is optional, and it can be one of two values:\n lips.specials.LITERAL, which is the default behavior, or\n lips.specials.SPLICE which causes the value to be unpacked into the expression.\n This can be used for e.g. to make `#(1 2 3)` into (x 1 2 3) that is needed\n by # that defines vectors.'),get:mo,".":mo,unbind:l(Gu,"(unbind fn)\n\n Function that removes the weak 'this' binding from a function so you\n can get properties from the actual function object."),type:l(qo,"(type object)\n\n Function that returns the type of an object as string."),debugger:l("debugger",function(){debugger},'(debugger)\n\n Function that triggers the JavaScript debugger (e.g. the browser devtools)\n using the "debugger;" statement. If a debugger is not running this\n function does nothing.'),in:l("in",function(e,t){if(e instanceof $||e instanceof x||e instanceof j){e=e.valueOf()}return e in Ku(t)},'(in key value)\n\n Function that uses the Javascript "in" operator to check if key is\n a valid property in the value.'),"instance?":l("instance?",function(e){return Uu(e)},"(instance? obj)\n\n Checks if object is an instance, created with a new operator"),instanceof:l("instanceof",function(e,t){return t instanceof Gu(e)},"(instanceof type obj)\n\n Predicate that tests if the obj is an instance of type."),"prototype?":l("prototype?",ju,"(prototype? obj)\n\n Predicate that tests if value is a valid JavaScript prototype,\n i.e. calling (new) with it will not throw ' is not a constructor'."),"macro?":l("macro?",function(e){return e instanceof K},"(macro? expression)\n\n Predicate that tests if value is a macro."),"continuation?":l("continuation?",Bu,"(continuation? expression)\n\n Predicate that tests if value is a callable continuation."),"function?":l("function?",d,"(function? expression)\n\n Predicate that tests if value is a callable function."),"real?":l("real?",function(e){if(qo(e)!=="number"){return false}if(e instanceof j){return e.isFloat()}return j.isFloat(e)},"(real? number)\n\n Predicate that tests if value is a real number (not complex)."),"number?":l("number?",function(e){return Number.isNaN(e)||j.isNumber(e)},"(number? expression)\n\n Predicate that tests if value is a number or NaN value."),"string?":l("string?",function(e){return x.isString(e)},"(string? expression)\n\n Predicate that tests if value is a string."),"pair?":l("pair?",G,"(pair? expression)\n\n Predicate that tests if value is a pair or list structure."),"regex?":l("regex?",function(e){return e instanceof RegExp},"(regex? expression)\n\n Predicate that tests if value is a regular expression."),"null?":l("null?",function(e){return ku(e)},"(null? expression)\n\n Predicate that tests if value is null-ish (i.e. undefined, nil, or\n Javascript null)."),"boolean?":l("boolean?",function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Predicate that tests if value is a boolean (#t or #f)."),"symbol?":l("symbol?",function(e){return e instanceof $},"(symbol? expression)\n\n Predicate that tests if value is a LIPS symbol."),"array?":l("array?",function(e){return e instanceof Array},"(array? expression)\n\n Predicate that tests if value is an array."),"object?":l("object?",function(e){return!H(e)&&e!==null&&!(e instanceof h)&&!(e instanceof RegExp)&&!(e instanceof x)&&!G(e)&&!(e instanceof j)&&_(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Predicate that tests if value is an plain object (not another LIPS type)."),flatten:l("flatten",function e(t){F("flatten",t,"pair");return t.flatten()},"(flatten list)\n\n Returns a shallow list from tree structure (pairs)."),"array->list":l("array->list",function(e){F("array->list",e,"array");return J.fromArray(e)},"(array->list array)\n\n Function that converts a JavaScript array to a LIPS cons list."),"tree->array":l("tree->array",Gi("tree->array",true),"(tree->array list)\n\n Function that converts a LIPS cons tree structure into a JavaScript array."),"list->array":l("list->array",Gi("list->array"),"(list->array list)\n\n Function that converts a LIPS list into a JavaScript array."),apply:l("apply",function e(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;iarray").call(this,u));return t.apply(this,Yo(t,n))},"(apply fn list)\n\n Function that calls fn with the list of arguments."),length:l("length",function e(t){if(!t||H(t)){return 0}if(G(t)){return t.length()}if("length"in t){return t.length}},'(length expression)\n\n Function that returns the length of the object. The object can be a LIPS\n list or any object that has a "length" property. Returns undefined if the\n length could not be found.'),"string->number":l("string->number",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;F("string->number",e,"string",1);F("string->number",t,"number",2);e=e.valueOf();t=t.valueOf();if(e.match(bn)||e.match(mn)){return Fn(e,t)}else if(e.match(wn)||e.match(vn)){return On(e,t)}else{var r=t===10&&!e.match(/e/i)||t===16;if(e.match(gn)&&r||e.match(yn)){return An(e,t)}if(e.match(un)){return Bn(e)}}return false},"(string->number number [radix])\n\n Function that parses a string into a number."),try:l(new K("try",function(r,e){var l=this;var h=e.use_dynamic;e.error;return new Promise(function(t,o){var s,n;if($.is(r.cdr.car.car,"catch")){s=r.cdr.car;if(G(r.cdr.cdr)&&$.is(r.cdr.cdr.car.car,"finally")){n=r.cdr.cdr.car}}else if($.is(r.cdr.car.car,"finally")){n=r.cdr.car}if(!(n||s)){throw new Error("try: invalid syntax")}function c(e){t(e);throw new lo("[CATCH]")}var f=function e(t,r){r(t)};if(n){f=function e(t,r){f=o;i.error=function(e){throw e};D(A(new J(new $("begin"),n.cdr),i),function(){r(t)})}}var i={env:l,use_dynamic:h,dynamic_env:l,error:function e(t){if(t instanceof lo){throw t}if(s){var r=l.inherit("try");var n=s.cdr.car.car;if(!(n instanceof $)){throw new Error("try: invalid syntax: catch require variable name")}r.set(n,t);var i;var u={env:r,use_dynamic:h,dynamic_env:l,error:function e(t){i=true;o(t);throw new lo("[CATCH]")}};var a=A(new J(new $("begin"),s.cdr.cdr),u);D(a,function e(t){if(!i){f(t,c)}})}else{f(undefined,function(){o(t)})}}};var e=A(r.car,i);D(e,function(e){f(e,t)},i.error)})}),"(try expr (catch (e) code))\n (try expr (catch (e) code) (finally code))\n (try expr (finally code))\n\n Macro that executes expr and catches any exceptions thrown. If catch is provided\n it's executed when an error is thrown. If finally is provided it's always\n executed at the end."),raise:l("raise",function(e){throw e},"(raise obj)\n\n Throws the object verbatim (no wrapping an a new Error)."),throw:l("throw",function(e){throw new Error(e)},"(throw string)\n\n Throws a new exception."),find:l("find",function t(r,n){F("find",r,["regex","function"]);F("find",n,["pair","nil"]);if(ku(n)){return Y}var e=bi("find",r);return D(e(n.car),function(e){if(e&&!H(e)){return n.car}return t(r,n.cdr)})},"(find fn list)\n (find regex list)\n\n Higher-order function that finds the first value for which fn return true.\n If called with a regex it will create a matcher function."),"for-each":l("for-each",function(e){var t;F("for-each",e,"function");for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i1?t-1:0),u=1;u3?n-3:0),u=3;u3?i-3:0),a=3;aarray")(r);var u=[];var a=bi("filter",t);return function t(r){function e(e){if(e&&!H(e)){u.push(n)}return t(++r)}if(r===i.length){return J.fromArray(u)}var n=i[r];return D(a(n),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher-order function that calls `fn` for each element of the list\n and return a new list for only those elements for which fn returns\n a truthy value. If called with a regex it will create a matcher function."),compose:l(xa,"(compose . fns)\n\n Higher-order function that creates a new function that applies all functions\n from right to left and returns the last value. Reverse of pipe.\n e.g.:\n ((compose (curry + 2) (curry * 3)) 10) --\x3e (+ 2 (* 3 10)) --\x3e 32"),pipe:l(Da,"(pipe . fns)\n\n Higher-order function that creates a new function that applies all functions\n from left to right and returns the last value. Reverse of compose.\n e.g.:\n ((pipe (curry + 2) (curry * 3)) 10) --\x3e (* 3 (+ 2 10)) --\x3e 36"),curry:l(Ca,"(curry fn . args)\n\n Higher-order function that creates a curried version of the function.\n The result function will have partially applied arguments and it\n will keep returning one-argument functions until all arguments are provided,\n then it calls the original function with the accumulated arguments.\n\n e.g.:\n (define (add a b c d) (+ a b c d))\n (define add1 (curry add 1))\n (define add12 (add 2))\n (display (add12 3 4))"),gcd:l("gcd",function e(){for(var t=arguments.length,r=new Array(t),n=0;no?u%=o:o%=u}u=_u(s*r[a])/(u+o)}return j(u)},"(lcm n1 n2 ...)\n\n Function that returns the least common multiple of the arguments."),"odd?":l("odd?",Aa(function(e){return j(e).isOdd()}),"(odd? number)\n\n Checks if number is odd."),"even?":l("even?",Aa(function(e){return j(e).isEven()}),"(even? number)\n\n Checks if number is even."),"*":l("*",Oa(function(e,t){return j(e).mul(t)},j(1)),"(* . numbers)\n\n Multiplies all numbers passed as arguments. If single value is passed\n it will return that value."),"+":l("+",Oa(function(e,t){return j(e).add(t)},j(0)),"(+ . numbers)\n\n Sums all numbers passed as arguments. If single value is passed it will\n return that value."),"-":l("-",function(){for(var e=arguments.length,t=new Array(e),r=0;r":l(">",function(){for(var e=arguments.length,t=new Array(e),r=0;r",t,["bigint","float","rational"]);return pu(function(e,t){return j(e).cmp(t)===1},t)},"(> x1 x2 x3 ...)\n\n Function that compares its numerical arguments and checks if they are\n monotonically decreasing, i.e. x1 > x2 and x2 > x3 and so on."),"<":l("<",function(){for(var e=arguments.length,t=new Array(e),r=0;r=":l(">=",function(){for(var e=arguments.length,t=new Array(e),r=0;r=",t,["bigint","float","rational"]);return pu(function(e,t){return[0,1].includes(j(e).cmp(t))},t)},"(>= x1 x2 ...)\n\n Function that compares its numerical arguments and checks if they are\n monotonically nonincreasing, i.e. x1 >= x2 and x2 >= x3 and so on."),"eq?":l("eq?",du,"(eq? a b)\n\n Function that compares two values if they are identical."),or:l(new K("or",function(e,t){var i=t.use_dynamic,u=t.error;var a=W.get("list->array")(e);var o=this;var s=o;if(!a.length){return false}var c;return function t(){function e(e){c=e;if(!Cu(c)){return c}else{return t()}}if(!a.length){if(!Cu(c)){return c}else{return false}}else{var r=a.shift();var n=A(r,{env:o,dynamic_env:s,use_dynamic:i,error:u});return D(n,e)}}()}),"(or . expressions)\n\n Macro that executes the values one by one and returns the first that is\n a truthy value. If there are no expressions that evaluate to true it\n returns false."),and:l(new K("and",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=t.error;var i=W.get("list->array")(e);var u=this;var a=u;if(!i.length){return true}var o;var s={env:u,dynamic_env:a,use_dynamic:r,error:n};return function t(){function e(e){o=e;if(Cu(o)){return o}else{return t()}}if(!i.length){if(!Cu(o)){return o}else{return false}}else{var r=i.shift();return D(A(r,s),e)}}()}),"(and . expressions)\n\n Macro that evaluates each expression in sequence and if any value returns false\n it will stop and return false. If each value returns true it will return the\n last value. If it's called without arguments it will return true."),"|":l("|",function(e,t){return j(e).or(t)},"(| a b)\n\n Function that calculates the bitwise or operation."),"&":l("&",function(e,t){return j(e).and(t)},"(& a b)\n\n Function that calculates the bitwise and operation."),"~":l("~",function(e){return j(e).neg()},"(~ number)\n\n Function that calculates the bitwise inverse (flip all the bits)."),">>":l(">>",function(e,t){return j(e).shr(t)},"(>> a b)\n\n Function that right shifts the value a by value b bits."),"<<":l("<<",function(e,t){return j(e).shl(t)},"(<< a b)\n\n Function that left shifts the value a by value b bits."),not:l("not",function e(t){if(ku(t)){return true}return!t},"(not object)\n\n Function that returns the Boolean negation of its argument.")},undefined,"global");var xo=W.inherit("user-env");function Eo(e,t){e.constant("**internal-env**",t);e.doc("**internal-env**","**internal-env**\n\n Constant used to hide stdin, stdout and stderr so they don't interfere\n with variables with the same name. Constants are an internal type\n of variable that can't be redefined, defining a variable with the same name\n will throw an error.");W.set("**interaction-environment**",e)}Eo(xo,bo);W.doc("**interaction-environment**","**interaction-environment**\n\n Internal dynamic, global variable used to find interpreter environment.\n It's used so the read and write functions can locate **internal-env**\n that contains the references to stdin, stdout and stderr.");function Fo(e){xo.get("**internal-env**").set("fs",e)}(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(t){var r=e[t]?e[t]:t;W.set(r,l(r,function(e){F(r,e,"number");if(e instanceof j){return e[t]()}},"(".concat(r," number)\n\n Function that calculates the ").concat(r," of a number.")))})})();function Ao(e){if(e.length===1){return e[0]}else{var t=[];var r=Ao(e.slice(1));for(var n=0;n3&&arguments[3]!==undefined?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(n!==null){i+=" (argument ".concat(n,")")}if(d(r)){return"Invalid type: got ".concat(t).concat(i)}if(r instanceof Array){if(r.length===1){var u=r[0].toLowerCase();r="a"+("aeiou".includes(u)?"n ":" ")+r[0]}else{r=new Intl.ListFormat("en",{style:"long",type:"disjunction"}).format(r)}}return"Expecting ".concat(r," got ").concat(t).concat(i)}function No(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;F(e,t,"number",n);var i=t.__type__;var u;if(G(r)){r=r.to_array()}if(r instanceof Array){r=r.map(function(e){return e.valueOf()})}if(r instanceof Array){r=r.map(function(e){return e.valueOf().toLowerCase()});if(r.includes(i)){u=true}}else{r=r.valueOf().toLowerCase()}if(!u&&i!==r){throw new Error(Po(e,i,r,n))}}function To(r,e,n){e.forEach(function(e,t){No(r,e,n,t+1)})}function Lo(r,e,n){e.forEach(function(e,t){F(r,e,n,t+1)})}function Mo(e,t,r){F(e,t,r);if(t.__type__===uo){throw new Error(Po(e,"binary-port","textual-port"))}}function F(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;e=e.valueOf();var i=qo(t).toLowerCase();if(d(r)){if(!r(t)){throw new Error(Po(e,i,r,n))}return}var u=false;if(G(r)){r=r.to_array()}if(r instanceof Array){r=r.map(function(e){return e.valueOf()})}if(r instanceof Array){r=r.map(function(e){return e.valueOf().toLowerCase()});if(r.includes(i)){u=true}}else{r=r.valueOf().toLowerCase()}if(!u&&i!==r){throw new Error(Po(e,i,r,n))}}function Ro(r){var n=new WeakMap;return function(e){var t=n.get(e);if(!t){t=r(e)}return t}}qo=Ro(qo);function qo(e){var t=$r.get(e);if(t){return t}if(_(e)==="object"){for(var r=0,n=Object.entries(Vr);r2&&arguments[2]!==undefined?arguments[2]:{},n=r.env,i=r.dynamic_env,u=r.use_dynamic;var a=n===null||n===void 0?void 0:n.new_frame(e,t);var o=i===null||i===void 0?void 0:i.new_frame(e,t);var s=new Wo({env:a,use_dynamic:u,dynamic_env:o});return Uo(e.apply(s,t))}function Ko(n,e){var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},i=t.env,u=t.dynamic_env,a=t.use_dynamic,r=t.error,o=r===void 0?function(){}:r;e=zo(e,{env:i,dynamic_env:u,error:o,use_dynamic:a});return D(e,function(e){if(ma(n)){n=Gu(n)}e=Yo(n,e);var t=e.slice();var r=Jo(n,t,{env:i,dynamic_env:u,use_dynamic:a});return D(r,function(e){if(G(e)){e.mark_cycles();return po(e)}return Yu(e)},o)})}var Ho=new WeakMap;var Go=function(){function n(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;ue(this,n);q(this,"__value__",void 0);q(this,"__fn__",void 0);Br(this,Ho,{writable:true,value:void 0});this.__value__=e;if(t){if(!d(t)){throw new Error("Section argument to Parameter need to be function "+"".concat(qo(t)," given"))}this.__fn__=t}if(r){f(this,Ho,r)}}ce(n,[{key:"__name__",get:function e(){return r(this,Ho)},set:function e(t){f(this,Ho,t);if(this.__fn__){this.__fn__.__name__="fn-".concat(t)}}},{key:"invoke",value:function e(){if(d(this.__fn__)){return this.__fn__(this.__value__)}return this.__value__}},{key:"inherit",value:function e(t){return new n(t,this.__fn__,this.__name__)}}]);return n}();var Wo=function(){function t(e){ue(this,t);q(this,"env",void 0);q(this,"dynamic_env",void 0);q(this,"use_dynamic",void 0);Object.assign(this,e)}ce(t,[{key:"__name__",get:function e(){return this.env.__name__}},{key:"__parent__",get:function e(){return this.env.__parent__}},{key:"get",value:function e(){var t;return(t=this.env).get.apply(t,arguments)}}]);return t}();function Qo(e,t){var r=e.get(t.__name__,{throwError:false});if(Pu(r)&&r!==t){return r}var n=xo.get("**interaction-environment**");while(true){var i=e.get("parent.frame",{throwError:false});e=i(0);if(e===n){break}r=e.get(t.__name__,{throwError:false});if(Pu(r)&&r!==t){return r}}return t}var Zo=function(){function t(e){ue(this,t);q(this,"__value__",void 0);this.__value__=e}ce(t,[{key:"invoke",value:function e(){if(this.__value__===null){throw new Error("Continuations are not implemented yet")}}}]);return t}();function A(o){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},s=e.env,c=e.dynamic_env,f=e.use_dynamic,t=e.error,l=t===void 0?jo:t,r=le(e,jr);return function(e){try{if(!Nu(c)){c=s===true?xo:s||xo}if(f){s=c}else if(s===true){s=xo}else{s=s||W}var t={env:s,dynamic_env:c,use_dynamic:f,error:l};var r;if(ku(o)){return o}if(o instanceof $){return s.get(o)}if(!G(o)){return o}var n=o.car;var e=o.cdr;if(G(n)){r=Uo(A(n,t));if(Mu(r)){return r.then(function(e){if(!Tu(e)){throw new Error(qo(e)+" "+s.get("repr")(e)+" is not callable while evaluating "+o.toString())}return A(new J(e,o.cdr),t)})}else if(!Tu(r)){throw new Error(qo(r)+" "+s.get("repr")(r)+" is not callable while evaluating "+o.toString())}}if(n instanceof $){r=s.get(n)}else if(d(n)){r=n}var i;if(r instanceof Du){i=Vo(r,o,t)}else if(r instanceof K){i=$o(r,e,t)}else if(d(r)){i=Ko(r,e,t)}else if(r instanceof xu){i=Vo(r._syntax,o,t)}else if(Pu(r)){var u=Qo(c,r);if(ku(o.cdr)){i=u.invoke()}else{return D(A(o.cdr.car,t),function(e){u.__value__=e})}}else if(Bu(r)){i=r.invoke()}else if(G(o)){r=n&&n.toString();throw new Error("".concat(qo(n)," ").concat(r," is not a function"))}else{return o}var a=s.get(Symbol["for"]("__promise__"),{throwError:false});if(a===true&&Mu(i)){i=i.then(function(e){if(G(e)&&!r[ia]){return A(e,t)}return e});return new Zn(i)}return i}catch(e){l&&l.call(s,e,o)}}(r)}var Xo=rs(function(e){return e});var es=rs(function(e,t){return t});function ts(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.env,n=t.dynamic_env,i=t.use_dynamic;return A(e,{env:r,dynamic_env:n,use_dynamic:i,error:function e(t,r){if(t&&t.message){if(t.message.match(/^Error:/)){var n=/^(Error:)\s*([^:]+:\s*)/;t.message=t.message.replace(n,"$1 $2")}if(r){if(!(t.__code__ instanceof Array)){t.__code__=[]}t.__code__.push(r.toString(true))}}if(!(t instanceof lo)){throw t}}})}function rs(d){return function(){var t=ie(function(l){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},h=e.env,_=e.dynamic_env,p=e.use_dynamic;return O.mark(function e(){var r,n,i,u,a,o,s,c,f;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!Nu(_)){_=h===true?xo:h||xo}if(h===true){h=xo}else{h=h||xo}r=[];if(!G(l)){t.next=8;break}t.next=6;return ts(l,{env:h,dynamic_env:_,use_dynamic:p});case 6:t.t0=t.sent;return t.abrupt("return",[t.t0]);case 8:n=Array.isArray(l)?l:pi(l);i=false;u=false;t.prev=11;o=qr(n);case 13:t.next=15;return o.next();case 15:if(!(i=!(s=t.sent).done)){t.next=31;break}c=s.value;t.next=19;return ts(c,{env:h,dynamic_env:_,use_dynamic:p});case 19:f=t.sent;t.t1=r;t.t2=d;t.t3=c;t.next=25;return f;case 25:t.t4=t.sent;t.t5=(0,t.t2)(t.t3,t.t4);t.t1.push.call(t.t1,t.t5);case 28:i=false;t.next=13;break;case 31:t.next=37;break;case 33:t.prev=33;t.t6=t["catch"](11);u=true;a=t.t6;case 37:t.prev=37;t.prev=38;if(!(i&&o["return"]!=null)){t.next=42;break}t.next=42;return o["return"]();case 42:t.prev=42;if(!u){t.next=45;break}throw a;case 45:return t.finish(42);case 46:return t.finish(37);case 47:return t.abrupt("return",r);case 48:case"end":return t.stop()}},e,null,[[11,33,37,47],[38,,42,46]])})()});function e(e){return t.apply(this,arguments)}return e}()}function ns(e){var t={"[":"]","(":")"};var r;if(typeof e==="string"){r=Jn(e)}else{r=e.map(function(e){return e&&e.token?e.token:e})}var n=Object.keys(t);var i=Object.values(t).concat(n);r=r.filter(function(e){return i.includes(e)});var u=new qn;var a=Tr(r),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;if(n.includes(s)){u.push(s)}else if(!u.is_empty()){var c=u.top();var f=t[c];if(s===f){u.pop()}else{throw new Error("Syntax error: missing closing ".concat(f))}}else{throw new Error("Syntax error: not matched closing ".concat(s))}}}catch(e){a.e(e)}finally{a.f()}return u.is_empty()}function is(e){var t="("+e.toString()+")()";var r=window.URL||window.webkitURL;var n;try{n=new Blob([t],{type:"application/javascript"})}catch(e){var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;n=new i;n.append(t);n=n.getBlob()}return new zr.Worker(r.createObjectURL(n))}function us(){return Ts.version.match(/^(\{\{VER\}\}|DEV)$/)}function as(){if(So()){return}var e;if(document.currentScript){e=document.currentScript}else{var t=document.querySelectorAll("script");if(!t.length){return}e=t[t.length-1]}var r=e.getAttribute("src");return r}var os=as();function ss(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"";var t="dist/std.xcb";if(e===""){if(os){e=os.replace(/[^/]*$/,"std.xcb")}else if(us()){e="https://cdn.jsdelivr.net/gh/jcubic/lips@devel/".concat(t)}else{e="https://cdn.jsdelivr.net/npm/@jcubic/lips@".concat(Ts.version,"/").concat(t)}}var r=W.get("load");return r.call(xo,e,W)}function cs(e){this.url=e;var a=this.worker=is(function(){var a;var o;self.addEventListener("message",function(e){var r=e.data;var t=r.id;if(r.type!=="RPC"||t===null){return}function n(e){self.postMessage({id:t,type:"RPC",result:e})}function i(e){self.postMessage({id:t,type:"RPC",error:e})}if(r.method==="eval"){if(!o){i("Worker RPC: LIPS not initialized, call init first");return}o.then(function(){var e=r.params[0];var t=r.params[1];a.exec(e,{use_dynamic:t}).then(function(e){e=e.map(function(e){return e&&e.valueOf()});n(e)})["catch"](function(e){i(e)})})}else if(r.method==="init"){var u=r.params[0];if(typeof u!=="string"){i("Worker RPC: url is not a string")}else{importScripts("".concat(u,"/dist/lips.min.js"));a=new Ts.Interpreter("worker");o=ss(u);o.then(function(){n(true)})}}})});this.rpc=function(){var n=0;return function e(t,r){var u=++n;return new Promise(function(n,i){a.addEventListener("message",function e(t){var r=t.data;if(r&&r.type==="RPC"&&r.id===u){if(r.error){i(r.error)}else{n(r.result)}a.removeEventListener("message",e)}});a.postMessage({type:"RPC",method:t,id:u,params:r})})}}();this.rpc("init",[e])["catch"](function(e){console.error(e)});this.exec=function(e,t){var r=t.use_dynamic,n=r===void 0?false:r;return this.rpc("eval",[e,n])}}var fs={pair:function e(t){var r=b(t,2),n=r[0],i=r[1];return J(n,i)},number:function e(t){if(x.isString(t)){return j([t,10])}return j(t)},regex:function e(t){var r=b(t,2),n=r[0],i=r[1];return new RegExp(n,i)},nil:function e(){return Y},symbol:function e(t){if(x.isString(t)){return $(t)}else if(Array.isArray(t)){return $(Symbol["for"](t[0]))}},string:x,character:h};var ls=Object.keys(fs);var hs={};for(var _s=0,ps=Object.entries(ls);_s1){var n=t.reduce(function(e,t){return e+t.length},0);var i=new Uint8Array(n);var u=0;t.forEach(function(e){i.set(e,u);u+=e.length});return i}else if(t.length){return t[0]}}function Es(){var e=1;var t=new TextEncoder("utf-8");return t.encode("LIPS".concat(e.toString().padStart(3," ")))}var Fs=7;function As(e){var t=new TextDecoder("utf-8");var r=t.decode(e.slice(0,Fs));var n=r.substring(0,4);if(n==="LIPS"){var i=r.match(/^(....).*([0-9]+)$/);if(i){return{type:i[1],version:Number(i[2])}}}return{type:"unknown"}}function ks(e){var t=Es();var r=Ds.encode(e);return xs(t,xr(r,{magic:false}))}function Os(e){var t=As(e),r=t.type,n=t.version;if(r==="LIPS"&&n===1){var i=Er(e.slice(Fs),{magic:false});return Ds.decode(i)}else{throw new Error("Invalid file format ".concat(r))}}function Cs(e){console.error(e.message||e);if(Array.isArray(e.code)){console.error(e.code.map(function(e,t){return"[".concat(t+1,"]: ").concat(e)}))}}function Ss(){var a=["text/x-lips","text/x-scheme"];var o;function s(e){var t;return(t=e.getAttribute("data-bootstrap"))!==null&&t!==void 0?t:e.getAttribute("bootstrap")}function c(r){return new Promise(function(t){var e=r.getAttribute("src");if(e){return fetch(e).then(function(e){return e.text()}).then(es).then(t)["catch"](function(e){Cs(e);t()})}else{return es(r.innerHTML).then(t)["catch"](function(e){Cs(e);t()})}})}function e(){return new Promise(function(i){var u=Array.from(document.querySelectorAll("script"));return function e(){var t=u.shift();if(!t){i()}else{var r=t.getAttribute("type");if(a.includes(r)){var n=s(t);if(!o&&typeof n==="string"){return ss(n).then(function(){return c(t)}).then(e)}else{return c(t).then(e)}}else if(r&&r.match(/lips|lisp/)){console.warn("Expecting "+a.join(" or ")+" found "+r)}return e()}}()})}if(!window.document){return Promise.resolve()}else if(js){var t=js;var r=s(t);if(typeof r==="string"){return ss(r).then(function(){o=true;return e()})}}return e()}var js=typeof window!=="undefined"&&window.document&&document.currentScript;if(typeof window!=="undefined"){Gr(window,Ss)}var Bs=function(){var e=x("Fri, 22 Mar 2024 13:26:48 +0000").valueOf();var t=e==="{{"+"DATE}}"?new Date:new Date(e);var r=function e(t){return t.toString().padStart(2,"0")};var n=t.getFullYear();var i=[n,r(t.getMonth()+1),r(t.getDate())].join("-");var u="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter DEV (".concat(i,") \nCopyright (c) 2018-").concat(n," Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables. You can also\nuse (help name) to display help for specific function or macro, (apropos name)\nto display list of matched names in environment and (dir object) to list\nproperties of an object.\n").replace(/^.*\n/,"");return u}();c(Ai,"__class__","ahead");c(J,"__class__","pair");c(Hi,"__class__","nil");c(ki,"__class__","pattern");c(Fi,"__class__","formatter");c(K,"__class__","macro");c(Du,"__class__","syntax");c(Du.Parameter,"__class__","syntax-parameter");c(E,"__class__","environment");c(Ha,"__class__","input-port");c(Ga,"__class__","output-port");c(Wa,"__class__","output-port");c(Qa,"__class__","output-string-port");c(Xa,"__class__","input-string-port");c(ro,"__class__","input-file-port");c(Za,"__class__","output-file-port");c(fo,"__class__","lips-error");[j,y,w,g,Ka].forEach(function(e){c(e,"__class__","number")});c(h,"__class__","character");c($,"__class__","symbol");c(x,"__class__","string");c(Zn,"__class__","promise");c(Go,"__class__","parameter");var Is="DEV";var Ps="Fri, 22 Mar 2024 13:26:48 +0000";var Ns=xa(yi,pi);var Ts={version:Is,banner:Bs,date:Ps,exec:es,parse:Ns,tokenize:Jn,evaluate:A,compile:Xo,serialize:bs,unserialize:ws,serialize_bin:ks,unserialize_bin:Os,bootstrap:ss,Environment:E,env:xo,Worker:cs,Interpreter:co,balanced_parenthesis:ns,balancedParenthesis:ns,balanced:ns,Macro:K,Syntax:Du,Pair:J,Values:_o,QuotedPromise:Zn,Error:fo,quote:po,InputPort:Ha,OutputPort:Ga,BufferedOutputPort:Wa,InputFilePort:ro,OutputFilePort:Za,InputStringPort:Xa,OutputStringPort:Qa,InputByteVectorPort:eo,OutputByteVectorPort:to,InputBinaryFilePort:no,OutputBinaryFilePort:io,set_fs:Fo,Formatter:Fi,Parser:hi,Lexer:s,specials:ri,repr:Wi,nil:Y,eof:oo,LSymbol:$,LNumber:j,LFloat:g,LComplex:y,LRational:w,LBigInteger:Ka,LCharacter:h,LString:x,Parameter:Go,rationalize:Ya};W.set("lips",Ts);e.BufferedOutputPort=Wa;e.Environment=E;e.Error=fo;e.Formatter=Fi;e.InputBinaryFilePort=no;e.InputByteVectorPort=eo;e.InputFilePort=ro;e.InputPort=Ha;e.InputStringPort=Xa;e.Interpreter=co;e.LBigInteger=Ka;e.LCharacter=h;e.LComplex=y;e.LFloat=g;e.LNumber=j;e.LRational=w;e.LString=x;e.LSymbol=$;e.Lexer=s;e.Macro=K;e.OutputBinaryFilePort=io;e.OutputByteVectorPort=to;e.OutputFilePort=Za;e.OutputPort=Ga;e.OutputStringPort=Qa;e.Pair=J;e.Parameter=Go;e.Parser=hi;e.QuotedPromise=Zn;e.Syntax=Du;e.Values=_o;e.Worker=cs;e._is_directive=Ou;e.balanced=ns;e.balancedParenthesis=ns;e.balanced_parenthesis=ns;e.banner=Bs;e.bootstrap=ss;e.compile=Xo;e.date=Ps;e.env=xo;e.eof=oo;e.evaluate=A;e.exec=es;e.nil=Y;e.parse=Ns;e.quote=po;e.rationalize=Ya;e.repr=Wi;e.serialize=bs;e.serialize_bin=ks;e.set_fs=Fo;e.specials=ri;e.tokenize=Jn;e.unserialize=ws;e.unserialize_bin=Os;e.version=Is}); \ No newline at end of file + */Object.defineProperty(ar,"__esModule",{value:true});const or=8,sr=6,cr=3,fr=(1<r-fr){t[i++]=e[n++];continue}f=(e[n]+13^e[n+1]-13^e[n+2])&hr-1;c=n-l[f]&lr;l[f]=n;u=n-c;if(u>=0&&u!=n&&e[n]==e[u]&&e[n+1]==e[u+1]&&e[n+2]==e[u+2]){t[a]|=o;for(s=cr;s>or;t[i++]=c;n+=s}else{t[i++]=e[n++]}}console.assert(e.length>=n);return i}function pr(e,t,r){t=t|0;var n=0,i=0,u=0,a=0,o=1<<(or-1|0),s=0,c=0;while(n>(or-sr|0))+cr|0;c=(e[n]<4){r[i]=r[u];i=i+1|0;u=u+1|0;r[i]=r[u];i=i+1|0;u=u+1|0;r[i]=r[u];i=i+1|0;u=u+1|0;r[i]=r[u];i=i+1|0;u=u+1|0;s=s-4|0}while(s>0){r[i]=r[u];i=i+1|0;u=u+1|0;s=s-1|0}}}else{r[i]=e[n];i=i+1|0;n=n+1|0}}return i}function dr(){const e=new TextEncoder("utf-8");return e.encode(vr)}const vr="@lzjb";const mr=dr();function yr(...e){if(e.length>1){const r=e.reduce((e,t)=>e+t.length,0);const n=new Uint8Array(r);let t=0;e.forEach(e=>{n.set(e,t);t+=e.length});return n}else if(e.length){return e[0]}}function gr(t){const e=Math.ceil(Math.log2(t)/8);const r=new Uint8Array(e);for(let e=0;e=0;e--){r=r*256+t[e]}return r}function wr(e,{magic:t=true}={}){const r=new Uint8Array(Math.max(e.length*1.5|0,16*1024));const n=_r(e,r);const i=gr(e.length);const u=[Uint8Array.of(i.length),i,r.slice(0,n)];if(t){u.unshift(mr)}return yr(...u)}function Dr(t,{magic:e=true}={}){if(e){const e=new TextDecoder("utf-8");const s=e.decode(t.slice(0,mr.length));if(s!==vr){throw new Error("Invalid magic value")}}const r=e?mr.length:0;const n=t[r];const i=r+1;const u=r+n+1;const a=br(t.slice(i,u));t=t.slice(u);const o=new Uint8Array(a);pr(t,t.length,o);return o}var xr=ar.pack=wr;var Er=ar.unpack=Dr;function Fr(s,c){return c=c||{},new Promise(function(e,t){var r=new XMLHttpRequest,n=[],i=[],u={},a=function(){return{ok:2==(r.status/100|0),statusText:r.statusText,status:r.status,url:r.responseURL,text:function(){return Promise.resolve(r.responseText)},json:function(){return Promise.resolve(r.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([r.response]))},clone:a,headers:{keys:function(){return n},entries:function(){return i},get:function(e){return u[e.toLowerCase()]},has:function(e){return e.toLowerCase()in u}}}};for(var o in r.open(c.method||"get",s,!0),r.onload=function(){r.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,t,r){n.push(t=t.toLowerCase()),i.push([t,r]),u[t]=u[t]?u[t]+","+r:r}),e(a())},r.onerror=t,r.withCredentials="include"==c.credentials,c.headers)r.setRequestHeader(o,c.headers[o]);r.send(c.body||null)})}var t;var Ar=["token"],kr=["env"],Or=["stderr","stdin","stdout","command_line"],Cr=["use_dynamic"],Sr=["use_dynamic"],jr=["env","dynamic_env","use_dynamic","error"];function Br(e,t,r){Ir(e,t);t.set(e,r)}function Ir(e,t){if(t.has(e)){throw new TypeError("Cannot initialize the same private elements twice on an object")}}function Pr(e,t,r){return t=k(t),M(e,Nr()?Reflect.construct(t,r||[],k(e).constructor):t.apply(e,r))}function Nr(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Nr=function e(){return!!t})()}function Tr(t,e){var r=typeof Symbol!=="undefined"&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=Lr(t))||e&&t&&typeof t.length==="number"){if(r)t=r;var n=0;var i=function e(){};return{s:i,n:function e(){if(n>=t.length)return{done:true};return{done:false,value:t[n++]}},e:function e(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u=true,a=false,o;return{s:function e(){r=r.call(t)},n:function e(){var t=r.next();u=t.done;return t},e:function e(t){a=true;o=t},f:function e(){try{if(!u&&r["return"]!=null)r["return"]()}finally{if(a)throw o}}}}function Lr(e,t){if(!e)return;if(typeof e==="string")return Mr(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor)r=e.constructor.name;if(r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return Mr(e,t)}function Mr(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r1?r-1:0),i=1;i0&&arguments[0]!==undefined?arguments[0]:null;var t=xo&&xo.get("DEBUG",{throwError:false});if(e===null){return t===true}return(t===null||t===void 0?void 0:t.valueOf())===e.valueOf()}function Qr(e){return e?"(?:#".concat(e,"(?:#[ie])?|#[ie]#").concat(e,")"):"(?:#[ie])?"}function Zr(e,t){return"".concat(Qr(e),"[+-]?").concat(t,"+/").concat(t,"+")}function Xr(e,t){return"".concat(Qr(e),"(?:[+-]?(?:").concat(t,"+/").concat(t,"+|nan.0|inf.0|").concat(t,"+))?(?:[+-]i|[+-]?(?:").concat(t,"+/").concat(t,"+|").concat(t,"+|nan.0|inf.0)i)(?=[()[\\]\\s]|$)")}function en(e,t){return"".concat(Qr(e),"[+-]?").concat(t,"+")}var tn=/^#\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimyus]*)$/;var rn="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)";var nn="(?:#[ie])?(?:[+-]?(?:[0-9][0-9_]*/[0-9][0-9_]*|nan.0|inf.0|".concat(rn,"|[+-]?[0-9]+))?(?:").concat(rn,"|[+-](?:[0-9]+/[0-9]+|[0-9]+|nan.0|inf.0))i");var un=new RegExp("^(#[ie])?".concat(rn,"$"),"i");function an(e,t){var r=e==="x"?"(?!\\+|".concat(t,")"):"(?!\\.|".concat(t,")");var n="";if(e===""){n="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+(?![0-9]))(?:[eE][-+]?[0-9]+)?))"}return new RegExp("^((?:(?:".concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(t,"+/").concat(t,"+(?!").concat(t,")|[+-]?").concat(t,"+)").concat(r,")?)(").concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(t,"+/").concat(t,"+|[+-]?").concat(t,"+|[+-])i$"),"i")}var on=function(){var u={};[[10,"","[0-9]"],[16,"x","[0-9a-fA-F]"],[8,"o","[0-7]"],[2,"b","[01]"]].forEach(function(e){var t=b(e,3),r=t[0],n=t[1],i=t[2];u[r]=an(n,i)});return u}();var sn={alarm:"",backspace:"\b",delete:"",escape:"",newline:"\n",null:"\0",return:"\r",space:" ",tab:"\t",dle:"",soh:"",dc1:"",stx:"",dc2:"",etx:"",dc3:"",eot:"",dc4:"",enq:"",nak:"",ack:"",syn:"",bel:"",etb:"",bs:"\b",can:"",ht:"\t",em:"",lf:"\n",sub:"",vt:"\v",esc:"",ff:"\f",fs:"",cr:"\r",gs:"",so:"",rs:"",si:"",us:"",del:""};function cn(e){var t=[];var r=0;var n=e.length;while(r=55296&&i<=56319&&r1&&arguments[1]!==undefined?arguments[1]:10;var r=En(e);var n=r.number.split("/");var i=w({num:j([n[0],r.radix||t]),denom:j([n[1],r.radix||t])});if(r.inexact){return i.valueOf()}else{return i}}function An(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;var r=En(e);if(r.inexact){return g(parseInt(r.number,r.radix||t))}return j([r.number,r.radix||t])}function kn(e){var t=e.match(/#\\x([0-9a-f]+)$/i);var r;if(t){var n=parseInt(t[1],16);r=String.fromCodePoint(n)}else{t=e.match(/#\\([\s\S]+)$/);if(t){r=t[1]}}if(r){return h(r)}throw new Error("Parse: invalid character")}function On(e){var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;function t(e){var t;if(e==="+"){t=j(1)}else if(e==="-"){t=j(-1)}else if(e.match(gn)){t=j([e,i])}else if(e.match(bn)){var r=e.split("/");t=w({num:j([r[0],i]),denom:j([r[1],i])})}else if(e.match(un)){var n=Bn(e);if(u.exact){return n.toRational()}return n}else if(e.match(/nan.0$/)){return j(NaN)}else if(e.match(/inf.0$/)){if(e[0]==="-"){return j(Number.NEGATIVE_INFINITY)}return j(Number.POSITIVE_INFINITY)}else{throw new Error("Internal Parser Error")}if(u.inexact){return g(t.valueOf())}return t}var u=En(e);i=u.radix||i;var r;var n=u.number.match(Dn);if(i!==10&&n){r=n}else{r=u.number.match(on[i])}var a,o;o=t(r[2]);if(r[1]){a=t(r[1])}else if(o instanceof g){a=g(0)}else{a=j(0)}if(o.cmp(0)===0&&o.__type__==="bigint"){return a}return y({im:o,re:a})}function Cn(e){return parseInt(e.toString(),10)===e}function Sn(e){var t=e.match(/^(([-+]?[0-9]*)(?:\.([0-9]+))?)e([-+]?[0-9]+)/i);if(t){var r=parseInt(t[4],10);var n;var i=t[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var u=t[3]&&t[3].length;if(i0&&(t.exact||!t.number.match(/\./))){return j(u).mul(o)}}}r=g(r);if(t.exact){return r.toRational()}return r}function In(e){e=e.replace(/\\x([0-9a-f]+);/gi,function(e,t){return"\\u"+t.padStart(4,"0")}).replace(/\n/g,"\\n");var t=e.match(/(\\*)(\\x[0-9A-F])/i);if(t&&t[1].length%2===0){throw new Error("Invalid string literal, unclosed ".concat(t[2]))}try{var r=x(JSON.parse(e));r.freeze();return r}catch(e){var n=e.message.replace(/in JSON /,"").replace(/.*Error: /,"");throw new Error("Invalid string literal: ".concat(n))}}function Pn(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var r={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,t){return String.fromCharCode(parseInt("0"+t,16))}).replace(/\\(.)/g,function(e,t){return r[t]||t})}return new $(e)}function Nn(e){if(Do.hasOwnProperty(e)){return Do[e]}if(e.match(/^"[\s\S]*"$/)){return In(e)}else if(e[0]==="#"){var t=e.match(tn);if(t){return new RegExp(t[1],t[2])}else if(e.match(_n)){return kn(e)}var r=e.match(/#\\(.+)/);if(r&&cn(r[1]).length===1){return kn(e)}}if(e.match(/[0-9a-f]|[+-]i/i)){if(e.match(yn)){return An(e)}else if(e.match(un)){return Bn(e)}else if(e.match(mn)){return Fn(e)}else if(e.match(vn)){return On(e)}}if(e.match(/^#[iexobd]/)){throw new Error("Invalid numeric constant: "+e)}return Pn(e)}function Tn(e){return!(["(",")","[","]"].includes(e)||ri.names().includes(e))}function Ln(e){return Tn(e)&&!(e.match(tn)||e.match(/^"[\s\S]*"$/)||e.match(yn)||e.match(un)||e.match(vn)||e.match(mn)||e.match(_n)||["#t","#f","nil"].includes(e))}var Mn=/"(?:\\[\S\s]|[^"])*"?/g;function Rn(e){if(typeof e==="string"){var t=/([-\\^$[\]()+{}?*.|])/g;return e.replace(t,"\\$1")}return e}function qn(){this.data=[]}qn.prototype.push=function(e){this.data.push(e)};qn.prototype.top=function(){return this.data[this.data.length-1]};qn.prototype.pop=function(){return this.data.pop()};qn.prototype.is_empty=function(){return!this.data.length};function Un(e){if(e instanceof x){e=e.valueOf()}var t=new i(e,{whitespace:true});var r=[];while(true){var n=t.peek(true);if(n===oo){break}r.push(n);t.skip()}return r}function zn(e){var t=e.token,r=le(e,Ar);if(t.match(/^"[\s\S]*"$/)&&t.match(/\n/)){var n=new RegExp("^ {1,"+(e.col+1)+"}","mg");t=t.replace(n,"")}return z({token:t},r)}function Vn(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(){};this.fn=e;this.cont=t}Vn.prototype.toString=function(){return"#"};function $n(n){return function(){for(var e=arguments.length,t=new Array(e),r=0;r1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof x){e=e.toString()}if(t){return Un(e)}else{var r=Un(e).map(function(e){if(e.token==="#\\ "||e.token=="#\\\n"){return e.token}return e.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return Kn(r)}}function Kn(e){var t=0;var r=null;var n=[];for(var i=0;i0&&arguments[0]!==undefined?arguments[0]:null;if(e instanceof $){if(e.is_gensym()){return e}e=e.valueOf()}if(Wn(e)){return $(e)}if(e!==null){return r(e,Symbol("#:".concat(e)))}t++;return r(t,Symbol("#:g".concat(t)))}}();function Zn(e){var r=this;var n={pending:true,rejected:false,fulfilled:false,reason:undefined,type:undefined};e=e.then(function(e){n.type=qo(e);n.fulfilled=true;n.pending=false;return e});o(this,"_promise",e,{hidden:true});if(d(e["catch"])){e=e["catch"](function(e){n.rejected=true;n.pending=false;n.reason=e})}Object.keys(n).forEach(function(t){Object.defineProperty(r,"__".concat(t,"__"),{enumerable:true,get:function e(){return n[t]}})});o(this,"__promise__",e);this.then=false}Zn.prototype.then=function(e){return new Zn(this.valueOf().then(e))};Zn.prototype["catch"]=function(e){return new Zn(this.valueOf()["catch"](e))};Zn.prototype.valueOf=function(){if(!this._promise){throw new Error("QuotedPromise: invalid promise created")}return this._promise};Zn.prototype.toString=function(){if(this.__pending__){return Zn.pending_str}if(this.__rejected__){return Zn.rejected_str}return"#")};Zn.pending_str="#";Zn.rejected_str="#";function Xn(e){if(Array.isArray(e)){return Promise.all(ei(e)).then(ti)}return e}function ei(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof Zn){t[r]=new ho(n)}else{t[r]=n}}return t}function ti(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof ho){t[r]=n.valueOf()}else{t[r]=n}}return t}var ri={LITERAL:Symbol["for"]("literal"),SPLICE:Symbol["for"]("splice"),SYMBOL:Symbol["for"]("symbol"),names:function e(){return Object.keys(this.__list__)},type:function e(t){try{return this.get(t).type}catch(e){console.log({name:t});console.log(e);return null}},get:function e(t){return this.__list__[t]},off:function e(t){var r=this;var n=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(Array.isArray(t)){t.forEach(function(e){return r.off(e,n)})}else if(n===null){delete this.__events__[t]}else{this.__events__=this.__events__.filter(function(e){return e!==n})}},on:function e(t,r){var n=this;if(Array.isArray(t)){t.forEach(function(e){return n.on(e,r)})}else if(!this.__events__[t]){this.__events__[t]=[r]}else{this.__events__[t].push(r)}},trigger:function e(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i",new $("quote-promise"),ri.LITERAL]];var si=oi.map(function(e){return e[0]});Object.freeze(si);Object.defineProperty(ri,"__builtins__",{writable:false,value:si});oi.forEach(function(e){var t=b(e,3),r=t[0],n=t[1],i=t[2];ri.append(r,n,i)});var i=function(){function _(e){var t=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=r.whitespace,i=n===void 0?false:n;ue(this,_);o(this,"__input__",e.replace(/\r/g,""));var u={};["_i","_whitespace","_col","_newline","_line","_state","_next","_token","_prev_char"].forEach(function(r){Object.defineProperty(t,r,{configurable:false,enumerable:false,get:function e(){return u[r]},set:function e(t){u[r]=t}})});this._whitespace=i;this._i=this._line=this._col=this._newline=0;this._state=this._next=this._token=null;this._prev_char=""}ce(_,[{key:"get",value:function e(t){return this.__internal[t]}},{key:"set",value:function e(t,r){this.__internal[t]=r}},{key:"token",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(t){var r=this._line;if(this._whitespace&&this._token==="\n"){--r}return{token:this._token,col:this._col,offset:this._i,line:r}}return this._token}},{key:"peek",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(this._i>=this.__input__.length){return oo}if(this._token){return this.token(t)}var r=this.next_token();if(r){this._token=this.__input__.substring(this._i,this._next);return this.token(t)}return oo}},{key:"skip",value:function e(){if(this._next!==null){this._token=null;this._i=this._next}}},{key:"read_line",value:function e(){var t=this.__input__.length;if(this._i>=t){return oo}for(var r=this._i;r=r){return oo}if(t+this._i>=r){return this.read_rest()}var n=this._i+t;var i=this.__input__.substring(this._i,n);var u=i.match(/\n/g);if(u){this._line+=u.length}this._i=n;return i}},{key:"peek_char",value:function e(){if(this._i>=this.__input__.length){return oo}return h(this.__input__[this._i])}},{key:"read_char",value:function e(){var t=this.peek_char();this.skip_char();return t}},{key:"skip_char",value:function e(){if(this._i1&&arguments[1]!==undefined?arguments[1]:{},n=r.prev_char,i=r["char"],u=r.next_char;var a=b(t,4),o=a[0],s=a[1],c=a[2],f=a[3];if(t.length!==5){throw new Error("Lexer: Invalid rule of length ".concat(t.length))}if(Su(o)){if(o!==i){return false}}else if(!i.match(o)){return false}if(!li(s,n)){return false}if(!li(c,u)){return false}if(f!==this._state){return false}return true}},{key:"next_token",value:function e(){if(this._i>=this.__input__.length){return false}var t=true;e:for(var r=this._i,n=this.__input__.length;r2&&arguments[2]!==undefined?arguments[2]:null;var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;if(t.length===0){throw new Error("Lexer: invalid literal rule")}if(t.length===1){return[[t,n,i,null,null]]}var u=[];for(var a=0,o=t.length;a0&&arguments[0]!==undefined?arguments[0]:{},t=e.env,r=e.meta,n=r===void 0?false:r,i=e.formatter,u=i===void 0?zn:i;ue(this,a);o(this,"_formatter",u,{hidden:true});o(this,"__env__",t);o(this,"_meta",n,{hidden:true});o(this,"_refs",[],{hidden:true});o(this,"_state",{parentheses:0,fold_case:false},{hidden:true})}ce(a,[{key:"parse",value:function e(t){if(t instanceof x){t=t.toString()}o(this,"__lexer__",new i(t))}},{key:"resolve",value:function e(t){return this.__env__&&this.__env__.get(t,{throwError:false})}},{key:"peek",value:function(){var e=ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=this.__lexer__.peek(true);if(!(r===oo)){t.next=4;break}return t.abrupt("return",oo);case 4:if(!this.is_comment(r.token)){t.next=7;break}this.skip();return t.abrupt("continue",0);case 7:if(!Ou(r.token)){t.next=11;break}this.skip();if(r.token==="#!fold-case"){this._state.fold_case=true}else if(r.token==="#!no-fold-case"){this._state.fold_case=false}return t.abrupt("continue",0);case 11:if(!(r.token==="#;")){t.next=18;break}this.skip();if(!(this.__lexer__.peek()===oo)){t.next=15;break}throw new Error("Lexer: syntax error eof found after comment");case 15:t.next=17;return this._read_object();case 17:return t.abrupt("continue",0);case 18:return t.abrupt("break",21);case 21:r=this._formatter(r);if(this._state.fold_case){r.token=Yi(r.token)}if(!this._meta){t.next=25;break}return t.abrupt("return",r);case 25:return t.abrupt("return",r.token);case 26:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"reset",value:function e(){this._refs.length=0}},{key:"skip",value:function e(){this.__lexer__.skip()}},{key:"read",value:function(){var e=ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return this.peek();case 2:r=t.sent;this.skip();return t.abrupt("return",r);case 5:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"match_datum_label",value:function e(t){var r=t.match(/^#([0-9]+)=$/);return r&&r[1]}},{key:"match_datum_ref",value:function e(t){var r=t.match(/^#([0-9]+)#$/);return r&&r[1]}},{key:"is_open",value:function e(t){var r=["(","["].includes(t);if(r){this._state.parentheses++}return r}},{key:"is_close",value:function e(t){var r=[")","]"].includes(t);if(r){this._state.parentheses--}return r}},{key:"read_list",value:function(){var e=ie(O.mark(function e(){var r,n,i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=Y,n=r;case 1:t.next=4;return this.peek();case 4:u=t.sent;if(!(u===oo)){t.next=7;break}return t.abrupt("break",32);case 7:if(!this.is_close(u)){t.next=10;break}this.skip();return t.abrupt("break",32);case 10:if(!(u==="."&&!H(r))){t.next=18;break}this.skip();t.next=14;return this._read_object();case 14:n.cdr=t.sent;i=true;t.next=30;break;case 18:if(!i){t.next=22;break}throw new Error("Parser: syntax error more than one element after dot");case 22:t.t0=J;t.next=25;return this._read_object();case 25:t.t1=t.sent;t.t2=Y;a=new t.t0(t.t1,t.t2);if(H(r)){r=a}else{n.cdr=a}n=a;case 30:t.next=1;break;case 32:return t.abrupt("return",r);case 33:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"read_value",value:function(){var e=ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return this.read();case 2:r=t.sent;if(!(r===oo)){t.next=5;break}throw new Error("Parser: Expected token eof found");case 5:return t.abrupt("return",Nn(r));case 6:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"is_comment",value:function e(t){return t.match(/^;/)||t.match(/^#\|/)&&t.match(/\|#$/)}},{key:"evaluate",value:function e(t){return A(t,{env:this.__env__,error:function e(t){throw t}})}},{key:"read_object",value:function(){var e=ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:this.reset();t.next=3;return this._read_object();case 3:r=t.sent;if(r instanceof _i){r=r.valueOf()}if(!this._refs.length){t.next=7;break}return t.abrupt("return",D(this._resolve_object(r),function(e){if(G(e)){e.mark_cycles()}return e}));case 7:return t.abrupt("return",r);case 8:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"balanced",value:function e(){return this._state.parentheses===0}},{key:"ballancing_error",value:function e(t,r){var n=this._state.parentheses;var i;if(n<0){i=new Error("Parser: unexpected parenthesis");i.__code__=[r.toString()+")"]}else{i=new Error("Parser: expected parenthesis but eof found");var u=new RegExp("\\){".concat(n,"}$"));i.__code__=[t.toString().replace(u,"")]}throw i}},{key:"_resolve_object",value:function(){var t=ie(O.mark(function e(r){var n=this;var i;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!Array.isArray(r)){t.next=2;break}return t.abrupt("return",r.map(function(e){return n._resolve_object(e)}));case 2:if(!Qi(r)){t.next=6;break}i={};Object.keys(r).forEach(function(e){i[e]=n._resolve_object(r[e])});return t.abrupt("return",i);case 6:if(!G(r)){t.next=8;break}return t.abrupt("return",this._resolve_pair(r));case 8:return t.abrupt("return",r);case 9:case"end":return t.stop()}},e,this)}));function e(e){return t.apply(this,arguments)}return e}()},{key:"_resolve_pair",value:function(){var t=ie(O.mark(function e(r){return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!G(r)){t.next=15;break}if(!(r.car instanceof _i)){t.next=7;break}t.next=4;return r.car.valueOf();case 4:r.car=t.sent;t.next=8;break;case 7:this._resolve_pair(r.car);case 8:if(!(r.cdr instanceof _i)){t.next=14;break}t.next=11;return r.cdr.valueOf();case 11:r.cdr=t.sent;t.next=15;break;case 14:this._resolve_pair(r.cdr);case 15:return t.abrupt("return",r);case 16:case"end":return t.stop()}},e,this)}));function e(e){return t.apply(this,arguments)}return e}()},{key:"_read_object",value:function(){var e=ie(O.mark(function e(){var r,n,i,u,a,o,s,c,f,l,h;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return this.peek();case 2:r=t.sent;if(!(r===oo)){t.next=5;break}return t.abrupt("return",r);case 5:if(!ni(r)){t.next=38;break}n=ri.get(r);i=ii(r);this.skip();a=ai(r);if(!a){t.next=14;break}t.t0=undefined;t.next=17;break;case 14:t.next=16;return this._read_object();case 16:t.t0=t.sent;case 17:o=t.t0;if(i){t.next=25;break}s=this.__env__.get(n.symbol);if(!(typeof s==="function")){t.next=25;break}if(ui(r)){c=[o]}else if(H(o)){c=[]}else if(G(o)){c=o.to_array(false)}if(!(c||a)){t.next=24;break}return t.abrupt("return",Jo(s,a?[]:c,{env:this.__env__,dynamic_env:this.__env__,use_dynamic:false}));case 24:throw new Error("Parse Error: Invalid parser extension "+"invocation ".concat(n.symbol));case 25:if(ui(r)){u=new J(n.symbol,new J(o,Y))}else{u=new J(n.symbol,o)}if(!i){t.next=28;break}return t.abrupt("return",u);case 28:if(!(s instanceof K)){t.next=37;break}t.next=31;return this.evaluate(u);case 31:f=t.sent;if(!(G(f)||f instanceof $)){t.next=34;break}return t.abrupt("return",J.fromArray([$("quote"),f]));case 34:return t.abrupt("return",f);case 37:throw new Error("Parse Error: invalid parser extension: "+n.symbol);case 38:l=this.match_datum_ref(r);if(!(l!==null)){t.next=44;break}this.skip();if(!this._refs[l]){t.next=43;break}return t.abrupt("return",new _i(l,this._refs[l]));case 43:throw new Error("Parse Error: invalid datum label #".concat(l,"#"));case 44:h=this.match_datum_label(r);if(!(h!==null)){t.next=51;break}this.skip();this._refs[h]=this._read_object();return t.abrupt("return",this._refs[h]);case 51:if(!this.is_close(r)){t.next=55;break}this.skip();t.next=61;break;case 55:if(!this.is_open(r)){t.next=60;break}this.skip();return t.abrupt("return",this.read_list());case 60:return t.abrupt("return",this.read_value());case 61:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()}]);return a}();var _i=function(){function r(e,t){ue(this,r);this.name=e;this.data=t}ce(r,[{key:"valueOf",value:function e(){return this.data}}]);return r}();function pi(e,t){return di.apply(this,arguments)}function di(){di=ye(O.mark(function e(r,n){var i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!n){if(W){n=W.get("**interaction-environment**",{throwError:false})}else{n=xo}}if(r instanceof hi){i=r}else{i=new hi({env:n});i.parse(r)}case 2:t.next=5;return ve(i.read_object());case 5:a=t.sent;if(!i.balanced()){i.ballancing_error(a,u)}if(!(a===oo)){t.next=9;break}return t.abrupt("break",14);case 9:u=a;t.next=12;return a;case 12:t.next=2;break;case 14:case"end":return t.stop()}},e)}));return di.apply(this,arguments)}function D(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(e){return e};var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;if(Mu(e)){var n=e.then(t);if(r===null){return n}else{return n["catch"](r)}}if(e instanceof Array){return vi(e,t,r)}if(Qi(e)){return mi(e,t,r)}return t(e)}function vi(t,r,e){if(t.find(Mu)){return D(Xn(t),function(e){if(Object.isFrozen(t)){Object.freeze(e)}return r(e)},e)}return r(t)}function mi(t,e,r){var i=Object.keys(t);var n=[],u=[];var a=i.length;while(a--){var o=i[a];var s=t[o];n[a]=s;if(Mu(s)){u.push(s)}}if(u.length){return D(Xn(n),function(e){var n={};e.forEach(function(e,t){var r=i[t];n[r]=e});if(Object.isFrozen(t)){Object.freeze(n)}return n},r)}return e(t)}function o(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{},i=n.hidden,u=i===void 0?false:i;Object.defineProperty(e,t,{value:r,configurable:true,enumerable:!u})}function yi(e){return gi.apply(this,arguments)}function gi(){gi=ie(O.mark(function e(r){var n,i,u,a,o,s,c;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:n=[];i=false;u=false;t.prev=3;o=qr(r);case 5:t.next=7;return o.next();case 7:if(!(i=!(s=t.sent).done)){t.next=13;break}c=s.value;n.push(c);case 10:i=false;t.next=5;break;case 13:t.next=19;break;case 15:t.prev=15;t.t0=t["catch"](3);u=true;a=t.t0;case 19:t.prev=19;t.prev=20;if(!(i&&o["return"]!=null)){t.next=24;break}t.next=24;return o["return"]();case 24:t.prev=24;if(!u){t.next=27;break}throw a;case 27:return t.finish(24);case 28:return t.finish(19);case 29:return t.abrupt("return",n);case 30:case"end":return t.stop()}},e,null,[[3,15,19,29],[20,,24,28]])}));return gi.apply(this,arguments)}function bi(e,t){if(t instanceof RegExp){return function(e){return String(e).match(t)}}else if(d(t)){return t}throw new Error("Invalid matcher")}function l(e,t,r,n){if(typeof e!=="string"){t=arguments[0];r=arguments[1];n=arguments[2];e=null}if(r){if(n){t.__doc__=r}else{t.__doc__=wi(r)}}if(e){t.__name__=e}else if(t.name&&!da(t)){t.__name__=t.name}return t}function wi(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function Di(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var r=e.length;if(t<=0){throw Error("previousSexp: Invalid argument sexp = ".concat(t))}e:while(t--&&r>=0){var n=1;while(n>0){var i=e[--r];if(!i){break e}if(i==="("||i.token==="("){n--}else if(i===")"||i.token===")"){n++}}r--}return e.slice(r+1)}function xi(e){if(!e||!e.length){return 0}var t=e.length;if(e[t-1].token==="\n"){return 0}while(--t){if(e[t].token==="\n"){var r=(e[t+1]||{}).token;if(r){return r.length}}}return 0}function Ei(e,t){return f(e,t)===t.length;function f(r,n){function e(e,t){var r=Tr(e),n;try{for(r.s();!(n=r.n()).done;){var i=n.value;var u=f(i,t);if(u!==-1){return u}}}catch(e){r.e(e)}finally{r.f()}return-1}function t(){return r[u]===Symbol["for"]("symbol")&&!Ln(n[o])}function i(){var e=r[u+1];var t=n[o+1];if(e!==undefined&&t!==undefined){return f([e],[t])}}var u=0;var a={};for(var o=0;o0){continue}}else if(t()){return-1}}else if(r[u]instanceof Array){var c=f(r[u],n.slice(o));if(c===-1||c+o>n.length){return-1}o+=c-1;u++;continue}else{return-1}u++}if(r.length!==u){return-1}return n.length}}function Fi(e){this.__code__=e.replace(/\r/g,"")}Fi.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?(?:define(?:-values|-syntax|-macro|-class|-record-type)?|(?:call-with-(?:input-file|output-file|port))|lambda|let-env|try|catch|when|unless|while|syntax-rules|(let|letrec)(-syntax|\*?-values|\*)?)$/],shift:{1:["&","#"]}}};Fi.match=Ei;Fi.prototype._options=function e(t){var r=Fi.defaults;if(typeof t==="undefined"){return Object.assign({},r)}var n=t&&t.exceptions||{};var i=n.specials||[];var u=n.shift||{1:[]};return z(z(z({},r),t),{},{exceptions:{specials:[].concat(U(r.exceptions.specials),U(i)),shift:z(z({},u),{},{1:[].concat(U(r.exceptions.shift[1]),U(u[1]))})}})};Fi.prototype.indent=function e(t){var r=Jn(this.__code__,true);return this._indent(r,t)};Fi.exception_shift=function(u,e){function t(e){if(!e.length){return false}if(e.indexOf(u)!==-1){return true}else{var t=e.filter(function(e){return e instanceof RegExp});if(!t.length){return false}var r=Tr(t),n;try{for(r.s();!(n=r.n()).done;){var i=n.value;if(u.match(i)){return true}}}catch(e){r.e(e)}finally{r.f()}}return false}if(t(e.exceptions.specials)){return e.indent}var r=e.exceptions.shift;for(var n=0,i=Object.entries(r);n0){n.offset=0}if(u.toString()===t.toString()&&ns(u)){return n.offset+u[0].col}else if(u.length===1){return n.offset+u[0].col+1}else{var s=-1;if(a){var c=Fi.exception_shift(a.token,n);if(c!==-1){s=c}}if(s===-1){s=Fi.exception_shift(u[1].token,n)}if(s!==-1){return n.offset+u[0].col+s}else if(u[0].line3&&u[1].line===u[3].line){if(u[1].token==="("||u[1].token==="["){return n.offset+u[1].col}return n.offset+u[3].col}else if(u[0].line===u[1].line){return n.offset+n.indent+u[0].col}else{var f=u.slice(2);for(var l=0;l")};Ai.prototype.match=function(e){return e.match(this.pattern)};function ki(){for(var e=arguments.length,t=new Array(e),r=0;r")};Fi.Pattern=ki;Fi.Ahead=Ai;var Oi=/^[[(]$/;var Ci=/^[\])]$/;var Si=/[^()[\]]/;var ji=new Ai(/[^)\]]/);var Bi=Symbol["for"]("*");var Ii=new ki([Oi,Bi,Ci],[Si],"+");var Pi=new ki([Oi,Bi,Ci],"+");var Ni=new ki([Symbol["for"]("symbol")],"?");var Ti=new ki([Symbol["for"]("symbol")],"*");var Li=[Oi,Ti,Ci];var Mi=new ki([Oi,Symbol["for"]("symbol"),Bi,Ci],"+");var Ri=Vi("syntax-rules");var qi=Vi("define","lambda","define-macro","syntax-rules");var Ui=/^(?!.*\b(?:[()[\]]|define(?:-macro)?|let(?:\*|rec|-env|-syntax|)?|lambda|syntax-rules)\b).*$/;var zi=/^(?:#:)?(let(?:\*|rec|-env|-syntax)?)$/;function Vi(){for(var e=arguments.length,t=new Array(e),r=0;r0&&!o[e]){o[e]=Di(a,e)}});var s=Tr(i),c;try{for(s.s();!(c=s.n()).done;){var f=b(c.value,3),l=f[0],h=f[1],_=f[2];h=h.valueOf();var p=h>0?o[h]:a;var d=p.filter(function(e){return e.trim()&&!ni(e)});var v=r(p);var m=Ei(l,d);var y=n.slice(u).find(function(e){return e.trim()&&!ni(e)});if(m&&(_ instanceof Ai&&_.match(y)||!_)){var g=u-v;if(n[g]!=="\n"){if(!n[g].trim()){n[g]="\n"}else{n.splice(g,0,"\n");u++}}u+=v;continue e}}}catch(e){s.e(e)}finally{s.f()}}this.__code__=n.join("");return this};Fi.prototype._spaces=function(e){return" ".repeat(e)};Fi.prototype.format=function e(t){var r=this.__code__.replace(/[ \t]*\n[ \t]*/g,"\n ");var n=Jn(r,true);var i=this._options(t);var u=0;var a=0;for(var o=0;o0){n=Math.floor(t()*r);r--;var i=[e[n],e[r]];e[r]=i[0];e[n]=i[1]}return e}function Hi(){}Hi.prototype.toString=function(){return"()"};Hi.prototype.valueOf=function(){return undefined};Hi.prototype.serialize=function(){return 0};Hi.prototype.to_object=function(){return{}};Hi.prototype.append=function(e){return new J(e,Y)};Hi.prototype.to_array=function(){return[]};var Y=new Hi;function J(e,t){if(typeof this!=="undefined"&&this.constructor!==J||typeof this==="undefined"){return new J(e,t)}this.car=e;this.cdr=t}function Gi(u,a){return function e(t){F(u,t,["pair","nil"]);if(H(t)){return[]}var r=[];var n=t;while(true){if(G(n)){if(n.have_cycles("cdr")){break}var i=n.car;if(a&&G(i)){i=this.get(u).call(this,i)}r.push(i);n=n.cdr}else if(H(n)){break}else{throw new Error("".concat(u,": can't convert improper list"))}}return r}}J.prototype.flatten=function(){return J.fromArray(Ji(this.to_array()))};J.prototype.length=function(){var e=0;var t=this;while(true){if(!t||H(t)||!G(t)||t.have_cycles("cdr")){break}e++;t=t.cdr}return e};J.match=function(e,t){if(e instanceof $){return $.is(e,t)}else if(G(e)){return J.match(e.car,t)||J.match(e.cdr,t)}else if(Array.isArray(e)){return e.some(function(e){return J.match(e,t)})}else if(Qi(e)){return Object.values(e).some(function(e){return J.match(e,t)})}return false};J.prototype.find=function(e){return J.match(this,e)};J.prototype.clone=function(){var r=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var n=new Map;function i(e){if(G(e)){if(n.has(e)){return n.get(e)}var t=new J;n.set(e,t);if(r){t.car=i(e.car)}else{t.car=e.car}t.cdr=i(e.cdr);t[aa]=e[aa];return t}return e}return i(this)};J.prototype.last_pair=function(){var e=this;while(true){if(!G(e.cdr)){return e}if(e.have_cycles("cdr")){break}e=e.cdr}};J.prototype.to_array=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var t=[];if(G(this.car)){if(e){t.push(this.car.to_array())}else{t.push(this.car)}}else{t.push(this.car.valueOf())}if(G(this.cdr)){t=t.concat(this.cdr.to_array(e))}return t};J.fromArray=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(G(e)||r&&e instanceof Array&&e[ia]){return e}if(t===false){var n=Y;for(var i=e.length;i--;){n=new J(e[i],n)}return n}if(e.length&&!(e instanceof Array)){e=U(e)}var u=Y;var a=e.length;while(a--){var o=e[a];if(o instanceof Array){o=J.fromArray(o,t,r)}else if(typeof o==="string"){o=x(o)}else if(typeof o==="number"&&!Number.isNaN(o)){o=j(o)}u=new J(o,u)}return u};J.prototype.to_object=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var t=this;var r={};while(true){if(G(t)&&G(t.car)){var n=t.car;var i=n.car;if(i instanceof $){i=i.__name__}if(i instanceof x){i=i.valueOf()}var u=n.cdr;if(G(u)){u=u.to_object(e)}if(Vu(u)){if(!e){u=u.valueOf()}}r[i]=u;t=t.cdr}else{break}}return r};J.fromPairs=function(e){return e.reduce(function(e,t){return new J(new J(new $(t[0]),t[1]),e)},Y)};J.fromObject=function(t){var e=Object.keys(t).map(function(e){return[e,t[e]]});return J.fromPairs(e)};J.prototype.reduce=function(e){var t=this;var r=Y;while(true){if(!H(t)){r=e(r,t.car);t=t.cdr}else{break}}return r};J.prototype.reverse=function(){if(this.have_cycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var t=Y;while(!H(e)){var r=e.cdr;e.cdr=t;t=e;e=r}return t};J.prototype.transform=function(n){function i(e){if(G(e)){if(e.replace){delete e.replace;return e}var t=n(e.car);if(G(t)){t=i(t)}var r=n(e.cdr);if(G(r)){r=i(r)}return new J(t,r)}return e}return i(this)};J.prototype.map=function(e){if(typeof this.car!=="undefined"){return new J(e(this.car),H(this.cdr)?Y:this.cdr.map(e))}else{return Y}};var Wi=new Map;function Qi(e){return e&&_(e)==="object"&&e.constructor===Object}var Zi=Object.getOwnPropertyNames(Array.prototype);var Xi=[];Zi.forEach(function(e){Xi.push(Array[e],Array.prototype[e])});function eu(e){e=Gu(e);return Xi.includes(e)}function tu(e){return d(e)&&(da(e)||e.__doc__)}function ru(r){var e=r.constructor||Object;var n=Qi(r);var i=d(r[Symbol.asyncIterator])||d(r[Symbol.iterator]);var u;if(Wi.has(e)){u=Wi.get(e)}else{Wi.forEach(function(e,t){t=Gu(t);if(r instanceof t&&(t===Object&&n&&!i||t!==Object)){u=e}})}return u}var nu=new Map;[[true,"#t"],[false,"#f"],[null,"#null"],[undefined,"#void"]].forEach(function(e){var t=b(e,2),r=t[0],n=t[1];nu.set(r,n)});function iu(r){if(r&&_(r)==="object"){var n={};var e=Object.getOwnPropertySymbols(r);e.forEach(function(e){var t=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");n[t]=fu(r[e])});var t=Object.getOwnPropertyNames(r);t.forEach(function(e){var t=r[e];if(t&&_(t)==="object"&&t.constructor===Object){n[e]=iu(t)}else{n[e]=fu(t)}});return n}return r}function uu(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function au(e,t){return e.hasOwnProperty(t)&&d(e.toString)}function ou(e){if(ya(e)){return"#"}var t=e.prototype&&e.prototype.constructor;if(d(t)&&da(t)){if(e[oa]&&t.hasOwnProperty("__name__")){var r=t.__name__;if(x.isString(r)){r=r.toString();return"#")}return"#"}}if(e.hasOwnProperty("__name__")){var n=e.__name__;if(_(n)==="symbol"){n=Gn(n)}if(typeof n==="string"){return"#")}}if(au(e,"toString")){return e.toString()}else if(e.name&&!da(e)){return"#")}else{return"#"}}var su=new Map;[[Error,function(e){return e.message}],[J,function(e,t){var r=t.quote,n=t.skip_cycles,i=t.pair_args;if(!n){e.mark_cycles()}return e.toString.apply(e,[r].concat(U(i)))}],[h,function(e,t){var r=t.quote;if(r){return e.toString()}return e.valueOf()}],[x,function(e,t){var r=t.quote;e=e.toString();if(r){return JSON.stringify(e).replace(/\\n/g,"\n")}return e}],[RegExp,function(e){return"#"+e.toString()}]].forEach(function(e){var t=b(e,2),r=t[0],n=t[1];su.set(r,n)});var cu=[$,K,_o,Ha,Ga,E,Zn];function fu(e,t,r){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(nu.has(e)){return nu.get(e)}if(ju(e)){return"#"}if(e){var n=e.constructor;if(su.has(n)){for(var i=arguments.length,u=new Array(i>3?i-3:0),a=3;a"}if(e===null){return"null"}if(d(e)){if(d(e.toString)&&e.hasOwnProperty("toString")){return e.toString().valueOf()}return ou(e)}if(_(e)==="object"){var f=e.constructor;if(!f){f=Object}var l;if(typeof f.__class__==="string"){l=f.__class__}else{var h=ru(e);if(h){if(d(h)){return h(e,t)}else{throw new Error("toString: Invalid repr value")}}l=f.name}if(d(e.toString)&&e.hasOwnProperty("toString")){return e.toString().valueOf()}if(qo(e)==="instance"){if(da(f)&&f.__name__){l=f.__name__.valueOf()}else if(!ya(f)){l="instance"}}if(qu(e,Symbol.iterator)){if(l){return"#")}return"#"}if(qu(e,Symbol.asyncIterator)){if(l){return"#")}return"#"}if(l!==""){return"#<"+l+">"}return"#"}if(typeof e!=="string"){return e.toString()}return e}J.prototype.mark_cycles=function(){hu(this);return this};J.prototype.have_cycles=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(!e){return this.have_cycles("car")||this.have_cycles("cdr")}return!!(this[aa]&&this[aa][e])};J.prototype.is_cycle=function(){return lu(this)};function lu(e){if(!G(e)){return false}if(e.have_cycles()){return true}return lu(e.car,fn)||lu(e.cdr,fn)}function hu(e){var t=[];var i=[];var u=[];function a(e){if(!t.includes(e)){t.push(e)}}function o(e,t,r,n){if(G(r)){if(n.includes(r)){if(!u.includes(r)){u.push(r)}if(!e[aa]){e[aa]={}}e[aa][t]=r;if(!i.includes(e)){i.push(e)}return true}}}var s=$n(function e(t,r){if(G(t)){delete t.ref;delete t[aa];a(t);r.push(t);var n=o(t,"car",t.car,r);var i=o(t,"cdr",t.cdr,r);if(!n){s(t.car,r.slice())}if(!i){return new Vn(function(){return e(t.cdr,r.slice())})}}});function r(e,t){if(G(e[aa][t])){var r=n.indexOf(e[aa][t]);e[aa][t]="#".concat(r,"#")}}s(e,[]);var n=t.filter(function(e){return u.includes(e)});n.forEach(function(e,t){e[ua]="#".concat(t,"=")});i.forEach(function(e){r(e,"car");r(e,"cdr")})}J.prototype.toString=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.nested,n=r===void 0?false:r;var i=[];if(this[ua]){i.push(this[ua]+"(")}else if(!n){i.push("(")}var u;if(this[aa]&&this[aa].car){u=this[aa].car}else{u=fu(this.car,e,true)}if(u!==undefined){i.push(u)}if(G(this.cdr)){if(this[aa]&&this[aa].cdr){i.push(" . ");i.push(this[aa].cdr)}else{if(this.cdr[ua]){i.push(" . ")}else{i.push(" ")}var a=this.cdr.toString(e,{nested:true});i.push(a)}}else if(!H(this.cdr)){i=i.concat([" . ",fu(this.cdr,e,true)])}if(!n||this[ua]){i.push(")")}return i.join("")};J.prototype.set=function(e,t){this[e]=t;if(G(t)){this.mark_cycles()}};J.prototype.append=function(e){if(e instanceof Array){return this.append(J.fromArray(e))}var t=this;if(t.car===undefined){if(G(e)){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(!H(e)){while(true){if(G(t)&&!H(t.cdr)){t=t.cdr}else{break}}t.cdr=e}return this};J.prototype.serialize=function(){return[this.car,this.cdr]};J.prototype[Symbol.iterator]=function(){var r=this;return{next:function e(){var t=r;r=t.cdr;if(H(t)){return{value:undefined,done:true}}else{return{value:t.car,done:false}}}}};function _u(e){return e<0?-e:e}function pu(e,t){var r=re(t),n=r[0],i=r.slice(1);while(i.length>0){var u=i,a=b(u,1),o=a[0];if(!e(n,o)){return false}var s=i;var c=re(s);n=c[0];i=c.slice(1)}return true}function du(e,t){if(d(e)){return d(t)&&Gu(e)===Gu(t)}else if(e instanceof j){if(!(t instanceof j)){return false}var r;if(e.__type__===t.__type__){if(e.__type__==="complex"){r=e.__im__.__type__===t.__im__.__type__&&e.__re__.__type__===t.__re__.__type__}else{r=true}if(r&&e.cmp(t)===0){if(e.valueOf()===0){return Object.is(e.valueOf(),t.valueOf())}return true}}return false}else if(typeof e==="number"){if(typeof t!=="number"){return false}if(Number.isNaN(e)){return Number.isNaN(t)}if(e===Number.NEGATIVE_INFINITY){return t===Number.NEGATIVE_INFINITY}if(e===Number.POSITIVE_INFINITY){return t===Number.POSITIVE_INFINITY}return du(j(e),j(t))}else if(e instanceof h){if(!(t instanceof h)){return false}return e.__char__===t.__char__}else{return e===t}}function vu(e,t){if(qo(e)!==qo(t)){return false}if(!mu(e)){return false}if(e instanceof RegExp){return e.source===t.source}if(e instanceof x){return e.valueOf()===t.valueOf()}return du(e,t)}function mu(e){return e instanceof $||x.isString(e)||H(e)||e===null||e instanceof h||e instanceof j||e===true||e===false}var yu=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e===0){return 0}else if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function K(e,t,r,n){if(typeof this!=="undefined"&&this.constructor!==K||typeof this==="undefined"){return new K(e,t)}F("Macro",e,"string",1);F("Macro",t,"function",2);if(r){if(n){this.__doc__=r}else{this.__doc__=wi(r)}}this.__name__=e;this.__fn__=t}K.defmacro=function(e,t,r,n){var i=new K(e,t,r,n);i.__defmacro__=true;return i};K.prototype.invoke=function(e,t,r){var n=t.env,i=le(t,kr);var u=z(z({},i),{},{macro_expand:r});var a=this.__fn__.call(n,e,u,this.__name__);return a};K.prototype.toString=function(){return"#")};var gu="define-macro";var bu=-1e4;function wu(c){return function(){var r=ie(O.mark(function e(r,y){var u,g,n,i,a,b,w,D,x,E,F,A,o,k,s;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:s=function e(){s=ie(O.mark(function e(r,n,i){var u,a,o,s,c,f,l,h,_,p,d,v,m;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!(G(r)&&r.car instanceof $)){t.next=50;break}if(!r[ia]){t.next=3;break}return t.abrupt("return",r);case 3:u=r.car.valueOf();a=i.get(r.car,{throwError:false});o=b(r.car);s=o||w(a,r)||D(a);if(!(s&&G(r.cdr.car))){t.next=28;break}if(!o){t.next=15;break}g=E(r.cdr.car);t.next=12;return A(r.cdr.car,n);case 12:c=t.sent;t.next=17;break;case 15:g=x(r.cdr.car);c=r.cdr.car;case 17:t.t0=J;t.t1=r.car;t.t2=J;t.t3=c;t.next=23;return k(r.cdr.cdr,n,i);case 23:t.t4=t.sent;t.t5=new t.t2(t.t3,t.t4);return t.abrupt("return",new t.t0(t.t1,t.t5));case 28:if(!F(u,a)){t.next=50;break}f=a instanceof Du?r:r.cdr;t.next=32;return a.invoke(f,z(z({},y),{},{env:i}),true);case 32:l=t.sent;if(!(a instanceof Du)){t.next=41;break}h=l,_=h.expr,p=h.scope;if(!G(_)){t.next=40;break}if(!(n!==-1&&n<=1||n")}return"#"};var xu=ce(function e(t){ue(this,e);o(this,"_syntax",t,{hidden:true});o(this._syntax,"_param",true,{hidden:true})});Du.Parameter=xu;function Eu(e,t,P,N){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:{};var T={"...":{symbols:{},lists:[]},symbols:{}};var L=r.expansion,M=r.define;V(P);function R(t,e){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:false;V({code:e,pattern:t});if(mu(t)&&!(t instanceof $)){return vu(t,e)}if(t instanceof $&&P.includes(t.literal())){if(!$.is(e,t)){return false}var i=L.ref(t);return!i||i===M||i===W}if(Array.isArray(t)&&Array.isArray(e)){V("<<< a 1");if(t.length===0&&e.length===0){return true}if($.is(t[1],N)){if(t[0]instanceof $){var u=t[0].valueOf();V("<<< a 2 "+n);if(n){var a=e.length-2;var o=a>0?e.slice(0,a):e;var s=J.fromArray(o,false);if(!T["..."].symbols[u]){T["..."].symbols[u]=new J(s,Y)}else{T["..."].symbols[u].append(new J(s,Y))}}else{T["..."].symbols[u]=J.fromArray(e,false)}}else if(Array.isArray(t[0])){V("<<< a 3");var c=U(r);if(!e.every(function(e){return R(t[0],e,c,true)})){return false}}if(t.length>2){var f=t.slice(2);return R(f,e.slice(-f.length),r,n)}return true}var l=R(t[0],e[0],r,n);V({first:l,pattern:t[0],code:e[0]});var h=R(t.slice(1),e.slice(1),r,n);V({first:l,rest:h});return l&&h}if(G(t)&&G(t.car)&&G(t.car.cdr)&&$.is(t.car.cdr.car,N)){V(">> 0");if(H(e)){V({pattern:t});if(t.car.car instanceof $){var _=t.car.car.valueOf();if(T["..."].symbols[_]){throw new Error("syntax: named ellipsis can only "+"appear onces")}T["..."].symbols[_]=e}}}if(G(t)&&G(t.cdr)&&$.is(t.cdr.car,N)){if(!H(t.cdr.cdr)){if(G(t.cdr.cdr)){var p=t.cdr.cdr.length();if(!G(e)){return false}var d=e.length();var v=e;while(d-1>p){v=v.cdr;d--}var m=v.cdr;v.cdr=Y;if(!R(t.cdr.cdr,m,r,n)){return false}}}if(t.car instanceof $){var y=t.car.__name__;if(T["..."].symbols[y]&&!r.includes(y)&&!n){throw new Error("syntax: named ellipsis can only appear onces")}V(">> 1");if(H(e)){V(">> 2");if(n){V("NIL");T["..."].symbols[y]=Y}else{V("NULL");T["..."].symbols[y]=null}}else if(G(e)&&(G(e.car)||H(e.car))){V(">> 3 "+n);if(n){if(T["..."].symbols[y]){var g=T["..."].symbols[y];if(H(g)){g=new J(Y,new J(e,Y))}else{g=g.append(new J(e,Y))}T["..."].symbols[y]=g}else{T["..."].symbols[y]=new J(e,Y)}}else{V(">> 4");T["..."].symbols[y]=new J(e,Y)}}else{V(">> 6");if(G(e)){if(!G(e.cdr)&&!H(e.cdr)){V(">> 7 (b)");if(H(t.cdr.cdr)){return false}else if(!T["..."].symbols[y]){T["..."].symbols[y]=new J(e.car,Y);return R(t.cdr.cdr,e.cdr)}}var b=e.last_pair();if(!H(b.cdr)){if(H(t.cdr.cdr)){return false}else{var w=e.clone();w.last_pair().cdr=Y;T["..."].symbols[y]=w;return R(t.cdr.cdr,b.cdr)}}V(">> 7 "+n);r.push(y);if(!T["..."].symbols[y]){T["..."].symbols[y]=new J(e,Y)}else{var D=T["..."].symbols[y];T["..."].symbols[y]=D.append(new J(e,Y))}V({IIIIII:T["..."].symbols[y]})}else if(t.car instanceof $&&G(t.cdr)&&$.is(t.cdr.car,N)){V(">> 8");T["..."].symbols[y]=null;return R(t.cdr.cdr,e)}else{V(">> 9");return false}}return true}else if(G(t.car)){var x=U(r);if(H(e)){V(">> 10");T["..."].lists.push(Y);return true}V(">> 11");var E=e;while(G(E)){if(!R(t.car,E.car,x,true)){return false}E=E.cdr}return true}if(Array.isArray(t.car)){var x=U(r);var F=e;while(G(F)){if(!R(t.car,F.car,x,true)){return false}F=F.cdr}return true}return false}if(t instanceof $){if($.is(t,N)){throw new Error("syntax: invalid usage of ellipsis")}V(">> 12");var A=t.__name__;if(P.includes(A)){return true}if(n){var k,O;V(T["..."].symbols[A]);(O=(k=T["..."].symbols)[A])!==null&&O!==void 0?O:k[A]=[];T["..."].symbols[A].push(e)}else{T.symbols[A]=e}return true}if(G(t)&&G(e)){V(">> 13");V({a:13,code:e,pattern:t});if(H(e.cdr)){var C=t.car instanceof $&&t.cdr instanceof $;if(C){if(!R(t.car,e.car,r,n)){return false}V(">> 14");var S=t.cdr.valueOf();if(!(S in T.symbols)){T.symbols[S]=Y}S=t.car.valueOf();if(!(S in T.symbols)){T.symbols[S]=e.car}return true}}V({pattern:t,code:e});if(G(t.cdr)&&G(t.cdr.cdr)&&t.cdr.car instanceof $&&$.is(t.cdr.cdr.car,N)&&G(t.cdr.cdr.cdr)&&!$.is(t.cdr.cdr.cdr.car,N)&&R(t.car,e.car,r,n)&&R(t.cdr.cdr.cdr,e.cdr,r,n)){var j=t.cdr.car.__name__;V({pattern:t,code:e,name:j});if(P.includes(j)){return true}T["..."].symbols[j]=null;return true}V("recur");V({pattern:t,code:e});var B=R(t.car,e.car,r,n);V({car:B,pattern:t.car,code:e.car});var I=R(t.cdr,e.cdr,r,n);V({car:B,cdr:I});if(B&&I){return true}}else if(H(t)&&(H(e)||e===undefined)){return true}else if(G(t.car)&&$.is(t.car.car,N)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(R(e,t)){return T}}function Fu(e,i){function u(t){if(G(t)){if(!i.length){return t}var e=u(t.car);var r=u(t.cdr);return new J(e,r)}else if(t instanceof $){var n=i.find(function(e){return e.gensym===t});if(n){return $(n.name)}return t}else{return t}}return u(e)}function Au(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var B=e.bindings,t=e.expr,I=e.scope,a=e.symbols,f=e.names,P=e.ellipsis;var l={};function o(e){if(e instanceof $){return true}return["string","symbol"].includes(_(e))}function N(e){if(!o(e)){var t=qo(e);throw new Error("syntax: internal error, need symbol got ".concat(t))}var r=e.valueOf();if(r===P){throw new Error("syntax: internal error, ellipis not transformed")}var n=_(r);if(["string","symbol"].includes(n)){if(r in B.symbols){return B.symbols[r]}else if(n==="string"&&r.match(/\./)){var i=r.split(".");var u=i[0];if(u in B.symbols){return J.fromArray([$("."),B.symbols[u]].concat(i.slice(1).map(function(e){return x(e)})))}}}if(a.includes(r)){return e}return s(r,e)}function s(e,t){if(!l[e]){var r=I.ref(e);if(_(e)==="symbol"&&!r){e=t.literal()}if(l[e]){return l[e]}var n=Qn(e);if(r){var i=I.get(e);I.set(n,i)}else{var u=I.get(e,{throwError:false});if(typeof u!=="undefined"){I.set(n,u)}}f.push({name:e,gensym:n});l[e]=n;if(typeof e==="string"&&e.match(/\./)){var a=e.split(".").filter(Boolean),o=re(a),s=o[0],c=o.slice(1);if(l[s]){_a(n,"__object__",[l[s]].concat(U(c)))}}}return l[e]}function T(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:function(){};var i=r.nested;V({bindings:t,expr:e});if(Array.isArray(e)&&!e.length){return e}if(e instanceof $){var u=e.valueOf();if(Wn(e)&&!t[u]);V("[t 1");if(t[u]){if(G(t[u])){var a=t[u],o=a.car,s=a.cdr;if(i){var c=o.car,f=o.cdr;if(!H(f)){n(u,new J(f,Y))}return c}if(!H(s)){n(u,s)}return o}else if(t[u]instanceof Array){n(u,t[u].slice(1));return t[u][0]}}return N(e)}var l=Array.isArray(e);if(G(e)||l){var h=l?e[0]:e.car;var _=l?e[1]:G(e.cdr)&&e.cdr.car;if(h instanceof $&&$.is(_,P)){l?e.slice(2):e.cdr.cdr;V("[t 2");var p=h.valueOf();var d=t[p];if(d===null){return}else if(d){V({name:p,binding:t[p]});if(G(d)){V("[t 2 Pair "+i);var v=d.car,m=d.cdr;var y=l?e.slice(2):e.cdr.cdr;if(i){if(!H(m)){V("|| next 1");n(p,m)}if(l&&y.length||!H(y)&&!l){var g=T(y,t,r,n);if(l){return v.concat(g)}else if(G(v)){return v.append(g)}else{V("UNKNOWN")}}return v}else if(G(v)){if(!H(v.cdr)){V("|| next 2");n(p,new J(v.cdr,m))}return v.car}else if(H(m)){return v}else{var b=e.last_pair();if(b.cdr instanceof $){V("|| next 3");n(p,d.last_pair());return v}}}else if(d instanceof Array){V("[t 2 Array "+i);if(i){n(p,d.slice(1));return J.fromArray(d)}else{var w=d.slice(1);if(w.length){n(p,w)}return d[0]}}else{return d}}}V("[t 3 recur ",e);var D=l?e.slice(1):e.cdr;var x=T(h,t,r,n);var E=T(D,t,r,n);V({head:x,rest:E});if(l){return[x].concat(E)}return new J(x,E)}return e}function L(t,r){var e=Object.values(t);var n=Object.getOwnPropertySymbols(t);if(n.length){e.push.apply(e,U(n.map(function(e){return t[e]})))}return e.length&&e.every(function(e){if(e===null){return!r}return G(e)||H(e)||Array.isArray(e)&&e.length})}function M(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function R(i){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},t=e.disabled;V("traverse>> ",i);var u=Array.isArray(i);if(u&&i.length===0){return i}if(G(i)||u){var r=u?i[0]:i.car;var n,a;if(u){n=i[1];a=i.slice(2)}else if(G(i.cdr)){n=i.cdr.car;a=i.cdr.cdr}V({first:r,second:n,rest_second:a});if(!t&&G(r)&&$.is(r.car,P)){return new J(r.cdr.car,R(i.cdr))}if(n&&$.is(n,P)&&!t){V(">> 1");var o=B["..."].symbols;var s=Object.values(o);if(s.length&&s.every(function(e){return e===null})){V(">>> 1 (a)");return R(a,{disabled:t})}var c=M(o);var f=r instanceof $&&$.is(a.car,P);if(G(r)||f){V(">>> 1 (b)");if(H(B["..."].lists[0])){if(!f){return R(a,{disabled:t})}V(a);return Y}var l=r;if(f){V(">>> 1 (c)");l=new J(r,new J(n,Y))}V(">> 2");var h;if(c.length){V(">> 2 (a)");var _=z({},o);h=u?[]:Y;var p=function e(){V({bind:_});if(!L(_)){return 1}var n={};var t=function e(t,r){n[t]=r};var r=T(l,_,{nested:true},t);if(r!==undefined){if(f){if(u){if(Array.isArray(r)){var i;(i=h).push.apply(i,U(r))}else{V("ZONK {1}")}}else{if(H(h)){h=r}else{h=h.append(r)}}}else if(u){h.push(r)}else{h=new J(r,h)}}_=n};while(true){if(p())break}if(!H(h)&&!f&&!u){h=h.reverse()}if(u){if(a){V({rest_second:a,expr:i});var d=R(a,{disabled:t});return h.concat(d)}return h}if(!H(i.cdr.cdr)&&!$.is(i.cdr.cdr.car,P)){var v=R(i.cdr.cdr,{disabled:t});return h.append(v)}return h}else{V(">> 3");var m=T(r,o,{nested:true});if(m){return new J(m,Y)}return Y}}else if(r instanceof $){V(">> 4");if($.is(a.car,P)){V(">> 4 (a)")}else{V(">> 4 (b)")}var y=r.__name__;var g=q({},y,o[y]);V({bind:g});var b=o[y]===null;var w=u?[]:Y;var D=function e(){if(!L(g,true)){V({bind:g});return 1}var n={};var t=function e(t,r){n[t]=r};var r=T(i,g,{nested:false},t);V({value:r});if(typeof r!=="undefined"){if(u){w.push(r)}else{w=new J(r,w)}}g=n};while(true){if(D())break}if(!H(w)&&!u){w=w.reverse()}if(G(i.cdr)){if(G(i.cdr.cdr)||i.cdr.cdr instanceof $){var x=R(i.cdr.cdr,{disabled:t});V({node:x});if(b){return x}if(H(w)){w=x}else{w.append(x)}V({result:w,node:x})}}V("<<<< 2");return w}}var E=R(r,{disabled:t});var F;var A;if(r instanceof $){var k=I.get(r,{throwError:false});A=k instanceof K&&k.__name__==="syntax-rules"}if(A){if(i.cdr.car instanceof $){F=new J(R(i.cdr.car,{disabled:t}),new J(i.cdr.cdr.car,R(i.cdr.cdr.cdr,{disabled:t})))}else{F=new J(i.cdr.car,R(i.cdr.cdr,{disabled:t}))}V("REST >>>> ",F)}else{F=R(i.cdr,{disabled:t})}V({a:true,car:fu(i.car),cdr:fu(i.cdr),head:fu(E),rest:fu(F)});return new J(E,F)}if(i instanceof $){if(t&&$.is(i,P)){return i}var O=Object.keys(B["..."].symbols);var C=i.literal();if(O.includes(C)){var S="missing ellipsis symbol next to name `".concat(C,"'");throw new Error("syntax-rules: ".concat(S))}var j=N(i);if(typeof j!=="undefined"){return j}}return i}return R(t,{})}function ku(e){return Ru(e)||H(e)||e===null}function H(e){return e===Y}function d(e){return typeof e==="function"&&typeof e.bind==="function"}function Ou(e){return fi.includes(e)}function Cu(e){return e===false||e===null}function Su(e){return typeof e==="string"}function ju(e){return e&&_(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}function Bu(e){return e instanceof Zo}function Iu(e){return e instanceof Wo}function Pu(e){return e instanceof Go}function G(e){return e instanceof J}function Nu(e){return e instanceof E}function Tu(e){return d(e)||Bu(e)||Pu(e)||Lu(e)}function Lu(e){return e instanceof K||e instanceof xu}function Mu(e){if(e instanceof Zn){return false}if(e instanceof Promise){return true}return!!e&&d(e.then)}function Ru(e){return typeof e==="undefined"}function qu(e,t){if($u(e,t)||$u(e.__proto__,t)){return d(e[t])}}function Uu(e){if(!e){return false}if(_(e)!=="object"){return false}if(e.__instance__){e.__instance__=false;return e.__instance__}return false}function zu(e){var t=_(e);return["string","function"].includes(t)||_(e)==="symbol"||e instanceof Zn||e instanceof $||e instanceof j||e instanceof x||e instanceof RegExp}function Vu(e){return e instanceof j||e instanceof x||e instanceof h}function $u(e,t){if(e===null){return false}return _(e)==="object"&&t in Object.getOwnPropertySymbols(e)}function Yu(e){switch(_(e)){case"string":return x(e);case"bigint":return j(e);case"number":if(Number.isNaN(e)){return wo}else{return j(e)}}return e}function Ju(r,n){var e=Object.getOwnPropertyNames(r);var t=Object.getOwnPropertySymbols(r);var i={};e.concat(t).forEach(function(e){var t=n(r[e]);i[e]=t});return i}function Ku(t){var e=[x,j,h].some(function(e){return t instanceof e});if(e){return t.valueOf()}if(t instanceof Array){return t.map(Ku)}if(t instanceof Zn){delete t.then}if(Qi(t)){return Ju(t,Ku)}return t}function Hu(e,t){if(G(e)){e.mark_cycles();return po(e)}if(d(e)){if(t){return Wu(e,t)}}return Yu(e)}function Gu(e){if(Zu(e)){return e[na]}return e}function Wu(e,t){if(e[Symbol["for"]("__bound__")]){return e}var r=e.bind(t);var n=Object.getOwnPropertyNames(e);var i=Tr(n),u;try{for(i.s();!(u=i.n()).done;){var a=u.value;if(ha(a)){try{r[a]=e[a]}catch(e){}}}}catch(e){i.e(e)}finally{i.f()}_a(r,"__fn__",e);_a(r,"__context__",t);_a(r,"__bound__",true);if(ya(e)){_a(r,"__native__",true)}if(Qi(t)&&da(e)){_a(r,"__method__",true)}r.valueOf=function(){return e};return r}function Qu(e){return Zu(e)&&e[Symbol["for"]("__context__")]===Object}function Zu(e){return!!(d(e)&&e[na])}function Xu(e){if(d(e)){var t=e[ra];if(t&&(t===Ts||t.constructor&&t.constructor.__class__)){return true}}return false}function ea(e){return e instanceof Ha||e instanceof Ga}function ta(e){if(d(e)){if(ea(e[ra])){return true}}return false}var ra=Symbol["for"]("__context__");var na=Symbol["for"]("__fn__");var ia=Symbol["for"]("__data__");var ua=Symbol["for"]("__ref__");var aa=Symbol["for"]("__cycles__");var oa=Symbol["for"]("__class__");var sa=Symbol["for"]("__method__");var ca=Symbol["for"]("__prototype__");var fa=Symbol["for"]("__lambda__");var la=["name","length","caller","callee","arguments","prototype"];function ha(e){return!la.includes(e)}function _a(e,t,r){Object.defineProperty(e,Symbol["for"](t),{get:function e(){return r},set:function e(){},configurable:false,enumerable:false})}function pa(t,r){try{Object.defineProperty(t,"length",{get:function e(){return r}});return t}catch(e){var n=new Array(r).fill(0).map(function(e,t){return"a"+t}).join(",");var i=new Function("f","return function(".concat(n,") {\n return f.apply(this, arguments);\n };"));return i(t)}}function da(e){return e&&e[fa]}function va(e){return e&&e[sa]}function ma(e){return da(e)&&!e[ca]&&!va(e)&&!ta(e)}function ya(e){var t=Symbol["for"]("__native__");return d(e)&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[t]===true||!e.name.match(/^bound /)&&!e[t])}function ga(e){var w;switch(e){case Symbol["for"]("letrec"):w="letrec";break;case Symbol["for"]("let"):w="let";break;case Symbol["for"]("let*"):w="let*";break;default:throw new Error("Invalid let_macro value")}return K.defmacro(w,function(t,e){var f=e.dynamic_env;var l=e.error,r=e.macro_expand,h=e.use_dynamic;var _;if(t.car instanceof $){if(!(G(t.cdr.car)||H(t.cdr.car))){throw new Error("let require list of pairs")}var n;if(H(t.cdr.car)){_=Y;n=Y}else{n=t.cdr.car.map(function(e){return e.car});_=t.cdr.car.map(function(e){return e.cdr.car})}var i=Qn("args");return J.fromArray([$("let"),[[i,J($("list"),_)]],[$("letrec"),[[t.car,J($("lambda"),J(n,t.cdr.cdr))]],[$("apply"),t.car,i]]])}else if(r){return}var p=this;_=W.get("list->array")(t.car);var d=p.inherit(w);var v,m;if(w==="let*"){m=d}else if(w==="let"){v=[]}var y=0;function g(){var e=new J(new $("begin"),t.cdr);return A(e,{env:d,dynamic_env:d,use_dynamic:h,error:l})}function b(e){if(e in d.__env__){throw new Error("Duplicated let variable ".concat(e))}}return function t(){var r=_[y++];f=w==="let*"?d:p;if(!r){if(v&&v.length){var e=v.map(function(e){return e.value});var n=e.filter(Mu);if(n.length){return Xn(e).then(function(e){for(var t=0,r=e.length;t1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=t.error;var i=this;var u=this;var a=[];var o=e;while(G(o)){a.push(A(o.car,{env:i,dynamic_env:u,use_dynamic:r,error:n}));o=o.cdr}var s=a.filter(Mu).length;if(s){return Xn(a).then(c.bind(this))}else{return c.call(this,a)}})}function wa(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n2?n-2:0),u=2;u1&&arguments[1]!==undefined?arguments[1]:null;return function(){for(var e=arguments.length,t=new Array(e),r=0;r1?e-1:0),r=1;r=a){return u.apply(this,n)}else{return i}}return i.apply(this,arguments)}}function Sa(n,i){F("limit",i,"function",2);return function(){for(var e=arguments.length,t=new Array(e),r=0;r1){e=e.toLowerCase();if(h.__names__[e]){t=e;e=h.__names__[e]}else{throw new Error("Internal: Unknown named character")}}else{t=h.__rev_names__[e]}Object.defineProperty(this,"__char__",{value:e,enumerable:true});if(t){Object.defineProperty(this,"__name__",{value:t,enumerable:true})}}h.__names__=sn;h.__rev_names__={};Object.keys(h.__names__).forEach(function(e){var t=h.__names__[e];h.__rev_names__[t]=e});h.prototype.toUpperCase=function(){return h(this.__char__.toUpperCase())};h.prototype.toLowerCase=function(){return h(this.__char__.toLowerCase())};h.prototype.toString=function(){return"#\\"+(this.__name__||this.__char__)};h.prototype.valueOf=h.prototype.serialize=function(){return this.__char__};function x(e){if(typeof this!=="undefined"&&!(this instanceof x)||typeof this==="undefined"){return new x(e)}if(e instanceof Array){this.__string__=e.map(function(e,t){F("LString",e,"character",t+1);return e.toString()}).join("")}else{this.__string__=e.valueOf()}}{var ja=["length","constructor"];var Ba=Object.getOwnPropertyNames(String.prototype).filter(function(e){return!ja.includes(e)});var Ia=function e(n){return function(){for(var e=arguments.length,t=new Array(e),r=0;r0){r.push(this.__string__.substring(0,e))}r.push(t);if(e1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof j){return e}if(typeof this!=="undefined"&&!(this instanceof j)||typeof this==="undefined"){return new j(e,t)}if(typeof e==="undefined"){throw new Error("Invalid LNumber constructor call")}var r=j.getType(e);if(j.types[r]){return j.types[r](e,t)}var n=e instanceof Array&&x.isString(e[0])&&j.isNumber(e[1]);if(e instanceof j){return j(e.value)}if(!j.isNumber(e)&&!n){throw new Error("You can't create LNumber from ".concat(qo(e)))}if(e===null){e=0}var i;if(n){var u=e,a=b(u,2),o=a[0],s=a[1];if(o instanceof x){o=o.valueOf()}if(s instanceof j){s=s.valueOf()}var c=o.match(/^([+-])/);var f=false;if(c){o=o.replace(/^[+-]/,"");if(c[1]==="-"){f=true}}}if(Number.isNaN(e)){return g(e)}else if(n&&Number.isNaN(parseInt(o,s))){return wo}else if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(n){var l;switch(s){case 8:l="0o";break;case 16:l="0x";break;case 2:l="0b";break;case 10:l="";break}if(typeof l==="undefined"){var h=BigInt(s);i=U(o).map(function(e,t){return BigInt(parseInt(e,s))*Ua(h,BigInt(t))}).reduce(function(e,t){return e+t})}else{i=BigInt(l+o)}}else{i=BigInt(e)}if(f){i*=BigInt(-1)}}else{i=e}return Ka(i,true)}else if(typeof Hr!=="undefined"&&!(e instanceof Hr)){if(e instanceof Array){return Ka(N(Hr,U(e)))}return Ka(new Hr(e))}else if(n){this.constant(parseInt(o,s),"integer")}else{this.constant(e,"integer")}}j.prototype.constant=function(e,t){Object.defineProperty(this,"__value__",{value:e,enumerable:true});Object.defineProperty(this,"__type__",{value:t,enumerable:true})};j.types={float:function e(t){return new g(t)},complex:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!j.isComplex(t)){t={im:0,re:t}}return new y(t,r)},rational:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!j.isRational(t)){t={num:t,denom:1}}return new w(t,r)}};j.prototype.serialize=function(){return this.__value__};j.prototype.isNaN=function(){return Number.isNaN(this.__value__)};j.prototype.gcd=function(e){var t=this.abs();e=e.abs();if(e.cmp(t)===1){var r=t;t=e;e=r}while(true){t=t.rem(e);if(t.cmp(0)===0){return e}e=e.rem(t);if(e.cmp(0)===0){return t}}};j.isFloat=function e(t){return t instanceof g||Number(t)===t&&t%1!==0};j.isNumber=function(e){return e instanceof j||j.isNative(e)||j.isBN(e)};j.isComplex=function(e){if(!e){return false}var t=e instanceof y||(j.isNumber(e.im)||j.isRational(e.im)||Number.isNaN(e.im))&&(j.isNumber(e.re)||j.isRational(e.re)||Number.isNaN(e.re));return t};j.isRational=function(e){if(!e){return false}return e instanceof w||j.isNumber(e.num)&&j.isNumber(e.denom)};j.isInteger=function(e){if(!(j.isNative(e)||e instanceof j)){return false}if(j.isFloat(e)){return false}if(j.isRational(e)){return false}if(j.isComplex(e)){return false}return true};j.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};j.isBigInteger=function(e){return e instanceof Ka||typeof e==="bigint"||j.isBN(e)};j.isBN=function(e){return typeof Hr!=="undefined"&&e instanceof Hr};j.getArgsType=function(e,t){if(e instanceof g||t instanceof g){return g}if(e instanceof Ka||t instanceof Ka){return Ka}return j};j.prototype.toString=function(e){if(Number.isNaN(this.__value__)){return"+nan.0"}if(e>=2&&e<36){return this.__value__.toString(e)}return this.__value__.toString()};j.prototype.asType=function(e){var t=j.getType(this);return j.types[t]?j.types[t](e):j(e)};j.prototype.isBigNumber=function(){return typeof this.__value__==="bigint"||typeof Hr!=="undefined"&&!(this.value instanceof Hr)};["floor","ceil","round"].forEach(function(e){j.prototype[e]=function(){if(this["float"]||j.isFloat(this.__value__)){return j(Math[e](this.__value__))}else{return j(Math[e](this.valueOf()))}}});j.prototype.valueOf=function(){if(j.isNative(this.__value__)){return Number(this.__value__)}else if(j.isBN(this.__value__)){return this.__value__.toNumber()}};var La=function(){var e=function e(t,r){return[t,r]};return{bigint:{bigint:e,float:function e(t,r){return[g(t.valueOf()),r]},rational:function e(t,r){return[{num:t,denom:1},r]},complex:function e(t,r){return[{im:0,re:t},r]}},integer:{integer:e,float:function e(t,r){return[g(t.valueOf()),r]},rational:function e(t,r){return[{num:t,denom:1},r]},complex:function e(t,r){return[{im:0,re:t},r]}},float:{bigint:function e(t,r){return[t,r&&g(r.valueOf())]},integer:function e(t,r){return[t,r&&g(r.valueOf())]},float:e,rational:function e(t,r){return[t,r&&g(r.valueOf())]},complex:function e(t,r){return[{re:t,im:g(0)},r]}},complex:{bigint:t("bigint"),integer:t("integer"),float:t("float"),rational:t("rational"),complex:function e(t,r){var n=j.coerce(t.__re__,r.__re__),i=b(n,2),u=i[0],a=i[1];var o=j.coerce(t.__im__,r.__im__),s=b(o,2),c=s[0],f=s[1];return[{im:c,re:u},{im:f,re:a}]}},rational:{bigint:function e(t,r){return[t,r&&{num:r,denom:1}]},integer:function e(t,r){return[t,r&&{num:r,denom:1}]},float:function e(t,r){return[g(t.valueOf()),r]},rational:e,complex:function e(t,r){return[{im:Ma(t.__type__,r.__im__.__type__,0)[0],re:Ma(t.__type__,r.__re__.__type__,t)[0]},{im:Ma(t.__type__,r.__im__.__type__,r.__im__)[0],re:Ma(t.__type__,r.__re__.__type__,r.__re__)[0]}]}}};function t(r){return function(e,t){return[{im:Ma(r,e.__im__.__type__,0,e.__im__)[1],re:Ma(r,e.__re__.__type__,0,e.__re__)[1]},{im:Ma(r,e.__im__.__type__,0,0)[1],re:Ma(r,t.__type__,0,t)[1]}]}}}();function Ma(e,t,r,n){return La[e][t](r,n)}j.coerce=function(e,t){var r=j.getType(e);var n=j.getType(t);if(!La[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!La[r][n]){throw new Error("LNumber::coerce unknown rhs type ".concat(n))}var i=La[r][n](e,t);return i.map(function(e){return j(e,true)})};j.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof j)){throw new Error("LNumber: you can't coerce ".concat(qo(e)))}if(typeof e==="number"){e=j(e)}return j.coerce(this,e)};j.getType=function(e){if(e instanceof j){return e.__type__}if(j.isFloat(e)){return"float"}if(j.isComplex(e)){return"complex"}if(j.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof Hr!=="undefined"&&!(e instanceof Hr)){return"bigint"}};j.prototype.isFloat=function(){return!!(j.isFloat(this.__value__)||this["float"])};var Ra={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var qa={};Object.keys(Ra).forEach(function(t){qa[Ra[t]]=t;j.prototype[t]=function(e){return this.op(Ra[t],e)}});j._ops={"*":function e(t,r){return t*r},"+":function e(t,r){return t+r},"-":function e(t,r){if(typeof r==="undefined"){return-t}return t-r},"/":function e(t,r){return t/r},"%":function e(t,r){return t%r},"|":function e(t,r){return t|r},"&":function e(t,r){return t&r},"~":function e(t){return~t},">>":function e(t,r){return t>>r},"<<":function e(t,r){return t<1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof y)||typeof this==="undefined"){return new y(e,t)}if(e instanceof y){return y({im:e.__im__,re:e.__re__})}if(j.isNumber(e)&&t){if(!t){return Number(e)}}else if(!j.isComplex(e)){var r="Invalid constructor call for LComplex expect &(:im :re ) object but got ".concat(fu(e));throw new Error(r)}var n=e.im instanceof j?e.im:j(e.im);var i=e.re instanceof j?e.re:j(e.re);this.constant(n,i)}y.prototype=Object.create(j.prototype);y.prototype.constructor=y;y.prototype.constant=function(e,t){Object.defineProperty(this,"__im__",{value:e,enumerable:true});Object.defineProperty(this,"__re__",{value:t,enumerable:true});Object.defineProperty(this,"__type__",{value:"complex",enumerable:true})};y.prototype.serialize=function(){return{re:this.__re__,im:this.__im__}};y.prototype.toRational=function(e){var t=this.__im__,r=this.__re__;if(j.isFloat(this.__im__)){t=g(this.__im__).toRational(e)}if(j.isFloat(this.__re__)){r=g(this.__re__).toRational(e)}return y({im:t,re:r})};y.prototype.pow=function(e){e.cmp(0);if(e===0){return j(1)}var t=j(Math.atan2(this.__im__.valueOf(),this.__re__.valueOf()));var r=j(this.modulus());if(j.isComplex(e)&&e.__im__.cmp(0)!==0){var n=e.mul(Math.log(r.valueOf())).add(y.i.mul(t).mul(e));if(!j.isComplex(n)){return g(Math.E).pow(n)}var i=g(Math.E).pow(n.__re__.valueOf());return y({re:i.mul(Math.cos(n.__im__.valueOf())),im:i.mul(Math.sin(n.__im__.valueOf()))})}var u=e.__re__.cmp(0)>0;e=e.__re__.valueOf();if(j.isInteger(e)&&u){var a=this;while(--e){a=a.mul(this)}return a}var o=r.pow(e);var s=t.mul(e);return y({re:o.mul(Math.cos(s)),im:o.mul(Math.sin(s))})};y.prototype.add=function(e){return this.complex_op("add",e,function(e,t,r,n){return{re:e.add(t),im:r.add(n)}})};y.prototype.factor=function(){if(this.__im__ instanceof g||this.__im__ instanceof g){var e=this.__re__,t=this.__im__;var r,n;if(e instanceof g){r=e.toRational().mul(e.toRational())}else{r=e.mul(e)}if(t instanceof g){n=t.toRational().mul(t.toRational())}else{n=t.mul(t)}return r.add(n)}else{return this.__re__.mul(this.__re__).add(this.__im__.mul(this.__im__))}};y.prototype.modulus=function(){return this.factor().sqrt()};y.prototype.conjugate=function(){return y({re:this.__re__,im:this.__im__.sub()})};y.prototype.sqrt=function(){var e=this.modulus();var t,r;if(e.cmp(0)===0){t=r=e}else if(this.__re__.cmp(0)===1){t=g(.5).mul(e.add(this.__re__)).sqrt();r=this.__im__.div(t).div(2)}else{r=g(.5).mul(e.sub(this.__re__)).sqrt();if(this.__im__.cmp(0)===-1){r=r.sub()}t=this.__im__.div(r).div(2)}return y({im:r,re:t})};y.prototype.div=function(e){if(j.isNumber(e)&&!j.isComplex(e)){if(!(e instanceof j)){e=j(e)}var t=this.__re__.div(e);var r=this.__im__.div(e);return y({re:t,im:r})}else if(!j.isComplex(e)){throw new Error("[LComplex::div] Invalid value")}if(this.cmp(e)===0){var n=this.coerce(e),i=b(n,2),u=i[0],a=i[1];var o=u.__im__.div(a.__im__);return o.coerce(a.__re__)[0]}var s=this.coerce(e),c=b(s,2),f=c[0],l=c[1];var h=l.factor();var _=l.conjugate();var p=f.mul(_);if(!j.isComplex(p)){return p.div(h)}var d=p.__re__.op("/",h);var v=p.__im__.op("/",h);return y({re:d,im:v})};y.prototype.sub=function(e){return this.complex_op("sub",e,function(e,t,r,n){return{re:e.sub(t),im:r.sub(n)}})};y.prototype.mul=function(e){return this.complex_op("mul",e,function(e,t,r,n){var i={re:e.mul(t).sub(r.mul(n)),im:e.mul(n).add(t.mul(r))};return i})};y.prototype.complex_op=function(e,t,i){var u=this;var r=function e(t,r){var n=i(u.__re__,t,u.__im__,r);if("im"in n&&"re"in n){if(n.im.cmp(0)===0){return n.re}return y(n,true)}return n};if(typeof t==="undefined"){return r()}if(j.isNumber(t)&&!j.isComplex(t)){if(!(t instanceof j)){t=j(t)}var n=t.asType(0);t={__im__:n,__re__:t}}else if(!j.isComplex(t)){throw new Error("[LComplex::".concat(e,"] Invalid value"))}var a=t.__re__ instanceof j?t.__re__:this.__re__.asType(t.__re__);var o=t.__im__ instanceof j?t.__im__:this.__im__.asType(t.__im__);return r(a,o)};y._op={"+":"add","-":"sub","*":"mul","/":"div"};y.prototype._op=function(e,t){var r=y._op[e];return this[r](t)};y.prototype.cmp=function(e){var t=this.coerce(e),r=b(t,2),n=r[0],i=r[1];var u=n.__re__.coerce(i.__re__),a=b(u,2),o=a[0],s=a[1];var c=o.cmp(s);if(c!==0){return c}else{var f=n.__im__.coerce(i.__im__),l=b(f,2),h=l[0],_=l[1];return h.cmp(_)}};y.prototype.valueOf=function(){return[this.__re__,this.__im__].map(function(e){return e.valueOf()})};y.prototype.toString=function(){var e;if(this.__re__.cmp(0)!==0){e=[fu(this.__re__)]}else{e=[]}var t=this.__im__.valueOf();var r=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY].includes(t);var n=fu(this.__im__);if(!r&&!Number.isNaN(t)){var i=this.__im__.cmp(0);if(i<0||i===0&&this.__im__._minus){e.push("-")}else{e.push("+")}n=n.replace(/^-/,"")}e.push(n);e.push("i");return e.join("")};function g(e){if(typeof this!=="undefined"&&!(this instanceof g)||typeof this==="undefined"){return new g(e)}if(!j.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof j){return g(e.valueOf())}if(typeof e==="number"){if(Object.is(e,-0)){Object.defineProperty(this,"_minus",{value:true})}this.constant(e,"float")}}g.prototype=Object.create(j.prototype);g.prototype.constructor=g;g.prototype.toString=function(e){if(this.__value__===Number.NEGATIVE_INFINITY){return"-inf.0"}if(this.__value__===Number.POSITIVE_INFINITY){return"+inf.0"}if(Number.isNaN(this.__value__)){return"+nan.0"}e&&(e=e.valueOf());var t=this.__value__.toString(e);if(!t.match(/e[+-]?[0-9]+$/i)){var r=t.replace(/^-/,"");var n=this.__value__<0?"-":"";if(t.match(/^-?0\.0{3}/)){var i=r.match(/^[.0]+/g)[0].length-1;var u=r.replace(/^[.0]+/,"").replace(/^([0-9a-f])/i,"$1.");return"".concat(n).concat(u,"e-").concat(i.toString(e))}if(t.match(/^-?[0-9a-f]{7,}\.?/i)){var a=r.match(/^[0-9a-f]+/gi)[0].length-1;var o=r.replace(/\./,"").replace(/^([0-9a-f])/i,"$1.").replace(/0+$/,"").replace(/\.$/,".0");return"".concat(n).concat(o,"e+").concat(a.toString(e))}if(!j.isFloat(this.__value__)){var s=t+".0";return this._minus?"-"+s:s}}return t.replace(/^([0-9]+)e/,"$1.0e")};g.prototype._op=function(e,t){if(t instanceof j){t=t.__value__}var r=j._ops[e];if(e==="/"&&this.__value__===0&&t===0){return NaN}return g(r(this.__value__,t))};g.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){return Va(this.__value__.valueOf())}return $a(e.valueOf())(this.__value__.valueOf())};g.prototype.sqrt=function(){var e=this.valueOf();if(this.cmp(0)<0){var t=g(Math.sqrt(-e));return y({re:0,im:t})}return g(Math.sqrt(e))};g.prototype.abs=function(){var e=this.valueOf();if(e<0){e=-e}return g(e)};var Va=$a(1e-10);function $a(n){return function(e){var t=function e(n,t,r){var i=function e(t,r){return r0){i=Ja(n,r)}else if(n.cmp(r)<=0){i=r}else if(r.cmp(0)>0){i=Ja(r,n)}else if(t.cmp(0)<0){i=j(Ja(n.sub(),r.sub())).sub()}else{i=j(0)}if(j.isFloat(t)||j.isFloat(e)){return g(i)}return i}function Ja(e,t){var r=j(e).floor();var n=j(t).floor();if(e.cmp(r)<1){return r}else if(r.cmp(n)===0){var i=j(1).div(t.sub(n));var u=j(1).div(e.sub(r));return r.add(j(1).div(Ja(i,u)))}else{return r.add(j(1))}}function w(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof w)||typeof this==="undefined"){return new w(e,t)}if(!j.isRational(e)){throw new Error("Invalid constructor call for LRational")}var r,n;if(e instanceof w){r=j(e.__num__);n=j(e.__denom__)}else{r=j(e.num);n=j(e.denom)}if(!t&&n.cmp(0)!==0){var i=r.op("%",n).cmp(0)===0;if(i){return j(r.div(n))}}this.constant(r,n)}w.prototype=Object.create(j.prototype);w.prototype.constructor=w;w.prototype.constant=function(e,t){Object.defineProperty(this,"__num__",{value:e,enumerable:true});Object.defineProperty(this,"__denom__",{value:t,enumerable:true});Object.defineProperty(this,"__type__",{value:"rational",enumerable:true})};w.prototype.serialize=function(){return{num:this.__num__,denom:this.__denom__}};w.prototype.pow=function(e){if(j.isRational(e)){return Ua(this.valueOf(),e.valueOf())}var t=e.cmp(0);if(t===0){return j(1)}if(t===-1){e=e.sub();var r=this.__denom__.pow(e);var n=this.__num__.pow(e);return w({num:r,denom:n})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};w.prototype.sqrt=function(){var e=this.__num__.sqrt();var t=this.__denom__.sqrt();if(e instanceof g||t instanceof g){return e.div(t)}return w({num:e,denom:t})};w.prototype.abs=function(){var e=this.__num__;var t=this.__denom__;if(e.cmp(0)===-1){e=e.sub()}if(t.cmp(0)!==1){t=t.sub()}return w({num:e,denom:t})};w.prototype.cmp=function(e){return j(this.valueOf(),true).cmp(e)};w.prototype.toString=function(){var e=this.__num__.gcd(this.__denom__);var t,r;if(e.cmp(1)!==0){t=this.__num__.div(e);if(t instanceof w){t=j(t.valueOf(true))}r=this.__denom__.div(e);if(r instanceof w){r=j(r.valueOf(true))}}else{t=this.__num__;r=this.__denom__}var n=this.cmp(0)<0;if(n){if(t.abs().cmp(r.abs())===0){return t.toString()}}else if(t.cmp(r)===0){return t.toString()}return t.toString()+"/"+r.toString()};w.prototype.valueOf=function(e){if(this.__denom__.cmp(0)===0){if(this.__num__.cmp(0)<0){return Number.NEGATIVE_INFINITY}return Number.POSITIVE_INFINITY}if(e){return j._ops["/"](this.__num__.value,this.__denom__.value)}return g(this.__num__.valueOf()).div(this.__denom__.valueOf())};w.prototype.mul=function(e){if(!(e instanceof j)){e=j(e)}if(j.isRational(e)){var t=this.__num__.mul(e.__num__);var r=this.__denom__.mul(e.__denom__);return w({num:t,denom:r})}var n=j.coerce(this,e),i=b(n,2),u=i[0],a=i[1];return u.mul(a)};w.prototype.div=function(e){if(!(e instanceof j)){e=j(e)}if(j.isRational(e)){var t=this.__num__.mul(e.__denom__);var r=this.__denom__.mul(e.__num__);return w({num:t,denom:r})}var n=j.coerce(this,e),i=b(n,2),u=i[0],a=i[1];var o=u.div(a);return o};w.prototype._op=function(e,t){return this[qa[e]](t)};w.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof j)){e=j(e)}if(j.isRational(e)){var t=e.__num__.sub();var r=e.__denom__;return this.add(w({num:t,denom:r}))}if(!(e instanceof j)){e=j(e).sub()}else{e=e.sub()}var n=j.coerce(this,e),i=b(n,2),u=i[0],a=i[1];return u.add(a)};w.prototype.add=function(e){if(!(e instanceof j)){e=j(e)}if(j.isRational(e)){var t=this.__denom__;var r=e.__denom__;var n=this.__num__;var i=e.__num__;var u,a;if(t!==r){a=r.mul(n).add(i.mul(t));u=t.mul(r)}else{a=n.add(i);u=t}return w({num:a,denom:u})}if(j.isFloat(e)){return g(this.valueOf()).add(e)}var o=j.coerce(this,e),s=b(o,2),c=s[0],f=s[1];return c.add(f)};function Ka(e,t){if(typeof this!=="undefined"&&!(this instanceof Ka)||typeof this==="undefined"){return new Ka(e,t)}if(e instanceof Ka){return Ka(e.__value__,e._native)}if(!j.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.constant(e,"bigint");Object.defineProperty(this,"_native",{value:t})}Ka.prototype=Object.create(j.prototype);Ka.prototype.constructor=Ka;Ka.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};Ka.prototype.serialize=function(){return this.__value__.toString()};Ka.prototype._op=function(e,t){if(typeof t==="undefined"){if(j.isBN(this.__value__)){e=Ka.bn_op[e];return Ka(this.__value__.clone()[e](),false)}return Ka(j._ops[e](this.__value__),true)}if(j.isBN(this.__value__)&&j.isBN(t.__value__)){e=Ka.bn_op[e];return Ka(this.__value__.clone()[e](t),false)}var r=j._ops[e](this.__value__,t.__value__);if(e==="/"){var n=this.op("%",t).cmp(0)===0;if(n){return j(r)}return w({num:this,denom:t})}return Ka(r,true)};Ka.prototype.sqrt=function(){var e;var t=this.cmp(0)<0;if(j.isNative(this.__value__)){e=j(Math.sqrt(t?-this.valueOf():this.valueOf()))}else if(j.isBN(this.__value__)){e=t?this.__value__.neg().sqrt():this.__value__.sqrt()}if(t){return y({re:0,im:e})}return e};j.NaN=j(NaN);y.i=y({im:1,re:0});function Ha(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof Ha)||typeof this==="undefined"){return new Ha(e)}F("InputPort",e,"function");o(this,"__type__",ao);var i;Object.defineProperty(this,"__parser__",{enumerable:true,get:function e(){return i},set:function e(t){F("InputPort::__parser__",t,"parser");i=t}});this._read=e;this._with_parser=this._with_init_parser.bind(this,ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(n.char_ready()){t.next=6;break}t.next=3;return n._read();case 3:r=t.sent;i=new hi({env:n});i.parse(r);case 6:return t.abrupt("return",n.__parser__);case 7:case"end":return t.stop()}},e)})));this.char_ready=function(){return!!this.__parser__&&this.__parser__.__lexer__.peek()!==oo};this._make_defaults()}Ha.prototype._make_defaults=function(){this.read=this._with_parser(function(e){return e.read_object()});this.read_line=this._with_parser(function(e){return e.__lexer__.read_line()});this.read_char=this._with_parser(function(e){return e.__lexer__.read_char()});this.read_string=this._with_parser(function(e,t){if(!j.isInteger(t)){var r=j.getType(t);Po("read-string",r,"integer")}return e.__lexer__.read_string(t.valueOf())});this.peek_char=this._with_parser(function(e){return e.__lexer__.peek_char()})};Ha.prototype._with_init_parser=function(o,s){var c=this;return ie(O.mark(function e(){var r,n,i,u,a=arguments;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return o.call(c);case 2:r=t.sent;for(n=a.length,i=new Array(n),u=0;u"};function Ga(e){if(typeof this!=="undefined"&&!(this instanceof Ga)||typeof this==="undefined"){return new Ga(e)}F("OutputPort",e,"function");o(this,"__type__",ao);this.write=e}Ga.prototype.is_open=function(){return this._closed!==true};Ga.prototype.close=function(){Object.defineProperty(this,"_closed",{get:function e(){return true},set:function e(){},configurable:false,enumerable:false});this.write=function(){throw new Error("output-port: port is closed")}};Ga.prototype.flush=function(){};Ga.prototype.toString=function(){return"#"};var Wa=function(e){R(r,e);function r(e){var t;ue(this,r);t=Pr(this,r,[function(){var e;return(e=t)._write.apply(e,arguments)}]);F("BufferedOutputPort",e,"function");o(L(t),"_fn",e,{hidden:true});o(L(t),"_buffer",[],{hidden:true});return t}ce(r,[{key:"flush",value:function e(){if(this._buffer.length){this._fn(this._buffer.join(""));this._buffer.length=0}}},{key:"_write",value:function e(){var t=this;for(var r=arguments.length,n=new Array(r),i=0;i"};Qa.prototype.valueOf=function(){return this.__buffer__.map(function(e){return e.valueOf()}).join("")};function Za(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof Za)||typeof this==="undefined"){return new Za(e,t)}F("OutputFilePort",e,"string");o(this,"__filename__",e);o(this,"_fd",t.valueOf(),{hidden:true});o(this,"__type__",ao);this.write=function(e){if(!x.isString(e)){e=fu(e)}else{e=e.valueOf()}r.fs().write(r._fd,e,function(e){if(e){throw e}})}}Za.prototype=Object.create(Ga.prototype);Za.prototype.constructor=Za;Za.prototype.fs=function(){if(!this._fs){this._fs=this.internal("fs")}return this._fs};Za.prototype.internal=function(e){return xo.get("**internal-env**").get(e)};Za.prototype.close=function(){var n=this;return new Promise(function(t,r){n.fs().close(n._fd,function(e){if(e){r(e)}else{o(n,"_fd",null,{hidden:true});Ga.prototype.close.call(n);t()}})})};Za.prototype.toString=function(){return"#")};function Xa(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof Xa)||typeof this==="undefined"){return new Xa(e)}F("InputStringPort",e,"string");t=t||W;e=e.valueOf();this._with_parser=this._with_init_parser.bind(this,function(){if(!r.__parser__){r.__parser__=new hi({env:t});r.__parser__.parse(e)}return r.__parser__});o(this,"__type__",ao);this._make_defaults()}Xa.prototype.char_ready=function(){return true};Xa.prototype=Object.create(Ha.prototype);Xa.prototype.constructor=Xa;Xa.prototype.toString=function(){return"#"};function eo(e){if(typeof this!=="undefined"&&!(this instanceof eo)||typeof this==="undefined"){return new eo(e)}F("InputByteVectorPort",e,"uint8array");o(this,"__vector__",e);o(this,"__type__",uo);var r=0;Object.defineProperty(this,"__index__",{enumerable:true,get:function e(){return r},set:function e(t){F("InputByteVectorPort::__index__",t,"number");if(t instanceof j){t=t.valueOf()}if(typeof t==="bigint"){t=Number(t)}if(Math.floor(t)!==t){throw new Error("InputByteVectorPort::__index__ value is "+"not integer")}r=t}})}eo.prototype=Object.create(Ha.prototype);eo.prototype.constructor=eo;eo.prototype.toString=function(){return"#"};eo.prototype.close=function(){var t=this;o(this,"__vector__",Y);var r=function e(){throw new Error("Input-binary-port: port is closed")};["read_u8","close","peek_u8","read_u8_vector"].forEach(function(e){t[e]=r});this.u8_ready=this.char_ready=function(){return false}};eo.prototype.u8_ready=function(){return true};eo.prototype.peek_u8=function(){if(this.__index__>=this.__vector__.length){return oo}return this.__vector__[this.__index__]};eo.prototype.skip=function(){if(this.__index__<=this.__vector__.length){++this.__index__}};eo.prototype.read_u8=function(){var e=this.peek_u8();this.skip();return e};eo.prototype.read_u8_vector=function(e){if(typeof e==="undefined"){e=this.__vector__.length}else if(e>this.__index__+this.__vector__.length){e=this.__index__+this.__vector__.length}if(this.peek_u8()===oo){return oo}return this.__vector__.slice(this.__index__,e)};function to(){if(typeof this!=="undefined"&&!(this instanceof to)||typeof this==="undefined"){return new to}o(this,"__type__",uo);o(this,"_buffer",[],{hidden:true});this.write=function(e){F("write",e,["number","uint8array"]);if(j.isNumber(e)){this._buffer.push(e.valueOf())}else{var t;(t=this._buffer).push.apply(t,U(Array.from(e)))}};Object.defineProperty(this,"__buffer__",{enumerable:true,get:function e(){return Uint8Array.from(this._buffer)}})}to.prototype=Object.create(Ga.prototype);to.prototype.constructor=to;to.prototype.close=function(){Ga.prototype.close.call(this);o(this,"_buffer",null,{hidden:true})};to.prototype._close_guard=function(){if(this._closed){throw new Error("output-port: binary port is closed")}};to.prototype.write_u8=function(e){F("OutputByteVectorPort::write_u8",e,"number");this.write(e)};to.prototype.write_u8_vector=function(e){F("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};to.prototype.toString=function(){return"#"};to.prototype.valueOf=function(){return this.__buffer__};function ro(e,t){if(typeof this!=="undefined"&&!(this instanceof ro)||typeof this==="undefined"){return new ro(e,t)}Xa.call(this,e);F("InputFilePort",t,"string");o(this,"__filename__",t)}ro.prototype=Object.create(Xa.prototype);ro.prototype.constructor=ro;ro.prototype.toString=function(){return"#")};function no(e,t){if(typeof this!=="undefined"&&!(this instanceof no)||typeof this==="undefined"){return new no(e,t)}eo.call(this,e);F("InputBinaryFilePort",t,"string");o(this,"__filename__",t)}no.prototype=Object.create(eo.prototype);no.prototype.constructor=no;no.prototype.toString=function(){return"#")};function io(e,t){var i=this;if(typeof this!=="undefined"&&!(this instanceof io)||typeof this==="undefined"){return new io(e,t)}F("OutputBinaryFilePort",e,"string");o(this,"__filename__",e);o(this,"_fd",t.valueOf(),{hidden:true});o(this,"__type__",uo);var u;this.write=function(e){F("write",e,["number","uint8array"]);var n;if(!u){u=i.internal("fs")}if(j.isNumber(e)){n=new Uint8Array([e.valueOf()])}else{n=new Uint8Array(Array.from(e))}return new Promise(function(t,r){u.write(i._fd,n,function(e){if(e){r(e)}else{t()}})})}}io.prototype=Object.create(Za.prototype);io.prototype.constructor=io;io.prototype.write_u8=function(e){F("OutputByteVectorPort::write_u8",e,"number");this.write(e)};io.prototype.write_u8_vector=function(e){F("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};var uo=Symbol["for"]("binary");var ao=Symbol["for"]("text");var oo=new so;function so(){}so.prototype.toString=function(){return"#"};function co(e){var t=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=r.stderr,i=r.stdin,u=r.stdout,a=r.command_line,o=a===void 0?null:a,s=le(r,Or);if(typeof this!=="undefined"&&!(this instanceof co)||typeof this==="undefined"){return new co(e,z({stdin:i,stdout:u,stderr:n,command_line:o},s))}if(typeof e==="undefined"){e="anonymous"}this.__parser__=new hi({env:this.__env__});this.__env__=xo.inherit(e,s);this.__env__.set("parent.frame",l("parent.frame",function(){return t.__env__},W.__env__["parent.frame"].__doc__));var c="**interaction-environment-defaults**";this.set(c,uu(s).concat(c));var f=bo.inherit("internal-".concat(e));if(ea(i)){f.set("stdin",i)}if(ea(n)){f.set("stderr",n)}if(ea(u)){f.set("stdout",u)}f.set("command-line",o);Eo(this.__env__,f)}co.prototype.exec=function(){var t=ie(function(a){var o=this;var s=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return O.mark(function e(){var r,n,i,u;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=s.use_dynamic,n=r===void 0?false:r,i=s.dynamic_env,u=s.env;F("Interpreter::exec",a,["string","array"],1);F("Interpreter::exec",n,"boolean",2);if(!u){u=o.__env__}if(!i){i=u}W.set("**interaction-environment**",o.__env__);if(!Array.isArray(a)){t.next=10;break}return t.abrupt("return",es(a,{env:u,dynamic_env:i,use_dynamic:n}));case 10:o.__parser__.parse(a);return t.abrupt("return",es(o.__parser__,{env:u,dynamic_env:i,use_dynamic:n}));case 12:case"end":return t.stop()}},e)})()});return function(e){return t.apply(this,arguments)}}();co.prototype.get=function(e){var t=this.__env__.get(e);if(d(t)){var r=new Wo({env:this.__env__});return t.bind(r)}return t};co.prototype.set=function(e,t){return this.__env__.set(e,t)};co.prototype.constant=function(e,t){return this.__env__.constant(e,t)};function fo(e,t){this.name="LipsError";this.message=e;this.args=t;this.stack=(new Error).stack}fo.prototype=new Error;fo.prototype.constructor=fo;var lo=function(e){R(t,e);function t(){ue(this,t);return Pr(this,t,arguments)}return ce(t)}(T(Error));function E(e,t,r){if(arguments.length===1){if(_(arguments[0])==="object"){e=arguments[0];t=null}else if(typeof arguments[0]==="string"){e={};t=null;r=arguments[0]}}this.__docs__=new Map;this.__env__=e;this.__parent__=t;this.__name__=r||"anonymous"}E.prototype.list=function(){return uu(this.__env__)};E.prototype.fs=function(){return this.get("**fs**")};E.prototype.unset=function(e){if(e instanceof $){e=e.valueOf()}if(e instanceof x){e=e.valueOf()}delete this.__env__[e]};E.prototype.inherit=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(_(e)==="object"){t=e}if(!e||_(e)==="object"){e="child of "+(this.__name__||"unknown")}return new E(t||{},this,e)};E.prototype.doc=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(e instanceof $){e=e.__name__}if(e instanceof x){e=e.valueOf()}if(t){if(!r){t=wi(t)}this.__docs__.set(e,t);return this}if(this.__docs__.has(e)){return this.__docs__.get(e)}if(this.__parent__){return this.__parent__.doc(e)}};E.prototype.new_frame=function(e,t){var n=this.inherit("__frame__");n.set("parent.frame",l("parent.frame",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;e=e.valueOf();var t=n.__parent__;if(!Nu(t)){return Y}if(e<=0){return t}var r=t.get("parent.frame");return r(e-1)},W.__env__["parent.frame"].__doc__));t.callee=e;n.set("arguments",t);return n};E.prototype._lookup=function(e){if(e instanceof $){e=e.__name__}if(e instanceof x){e=e.valueOf()}if(this.__env__.hasOwnProperty(e)){return ho(this.__env__[e])}if(this.__parent__){return this.__parent__._lookup(e)}};E.prototype.toString=function(){return"#"};E.prototype.clone=function(){var t=this;var r={};Object.keys(this.__env__).forEach(function(e){r[e]=t.__env__[e]});return new E(r,this.__parent__,this.__name__)};E.prototype.merge=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"merge";F("Environment::merge",e,"environment");return this.inherit(t,e.__env__)};function ho(e){if(typeof this!=="undefined"&&!(this instanceof ho)||typeof this==="undefined"){return new ho(e)}this.value=e}ho.isUndefined=function(e){return e instanceof ho&&typeof e.value==="undefined"};ho.prototype.valueOf=function(){return this.value};function _o(e){if(!e.length){return}if(e.length===1){return e[0]}if(typeof this!=="undefined"&&!(this instanceof _o)||typeof this==="undefined"){return new _o(e)}this.__values__=e}_o.prototype.toString=function(){return this.__values__.map(function(e){return fu(e)}).join("\n")};_o.prototype.valueOf=function(){return this.__values__};E.prototype.get=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};F("Environment::get",e,["symbol","string"]);var r=t.throwError,n=r===void 0?true:r;var i=e;if(i instanceof $||i instanceof x){i=i.valueOf()}var u=this._lookup(i);if(u instanceof ho){if(ho.isUndefined(u)){return undefined}return Hu(u.valueOf())}var a;if(e instanceof $&&e[$.object]){a=e[$.object]}else if(typeof i==="string"){a=i.split(".").filter(Boolean)}if(a&&a.length>0){var o=a,s=re(o),c=s[0],f=s.slice(1);u=this._lookup(c);if(f.length){try{if(u instanceof ho){u=u.valueOf()}else{u=mo(zr,c);if(d(u)){u=Gu(u)}}if(typeof u!=="undefined"){return mo.apply(void 0,[u].concat(U(f)))}}catch(e){throw e}}else if(u instanceof ho){return Hu(u.valueOf())}u=mo(zr,i)}if(typeof u!=="undefined"){return u}if(n){throw new Error("Unbound variable `"+i.toString()+"'")}};E.prototype.set=function(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;F("Environment::set",e,["string","symbol"]);if(j.isNumber(t)){t=j(t)}if(e instanceof $){e=e.__name__}if(e instanceof x){e=e.valueOf()}this.__env__[e]=t;if(r){this.doc(e,r,true)}return this};E.prototype.constant=function(t,e){var r=this;if(this.__env__.hasOwnProperty(t)){throw new Error("Environment::constant: ".concat(t," already exists"))}if(arguments.length===1&&Qi(arguments[0])){var n=arguments[0];Object.keys(n).forEach(function(e){r.constant(t,n[e])})}else{Object.defineProperty(this.__env__,t,{value:e,enumerable:true})}return this};E.prototype.has=function(e){return this.__env__.hasOwnProperty(e)};E.prototype.ref=function(e){var t=this;while(true){if(!t){break}if(t.has(e)){return t}t=t.__parent__}};E.prototype.parents=function(){var e=this;var t=[];while(e){t.unshift(e);e=e.__parent__}return t};function po(e){if(Mu(e)){return e.then(po)}if(G(e)||e instanceof $){e[ia]=true}return e}var vo=pi(Jn('(lambda ()\n "[native code]"\n (throw "Invalid Invocation"))'))[0];var mo=l("get",function e(t){var r;for(var n=arguments.length,i=new Array(n>1?n-1:0),u=1;u0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=yo(this,"stdin")}Mo("peek-char",e,"input-port");return e.peek_char()},"(peek-char port)\n\n This function reads and returns a character from the string\n port, or, if there is no more data in the string port, it\n returns an EOF."),"read-line":l("read-line",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=yo(this,"stdin")}Mo("read-line",e,"input-port");return e.read_line()},"(read-line port)\n\n This function reads and returns the next line from the input\n port."),"read-char":l("read-char",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=yo(this,"stdin")}Mo("read-char",e,"input-port");return e.read_char()},"(read-char port)\n\n This function reads and returns the next character from the\n input port."),read:l("read",function(){var e=ie(function(){var i=this;var u=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;return O.mark(function e(){var r,n;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=i.env;if(u===null){n=yo(r,"stdin")}else{n=u}Mo("read",n,"input-port");return t.abrupt("return",n.read.call(r));case 4:case"end":return t.stop()}},e)})()});function t(){return e.apply(this,arguments)}return t}(),"(read [port])\n\n This function, if called with a port, it will parse the next\n item from the port. If called without an input, it will read\n a string from standard input (using the browser's prompt or\n a user defined input method) and parse it. This function can be\n used together with `eval` to evaluate code from port."),pprint:l("pprint",function e(t){if(G(t)){t=new Ts.Formatter(t.toString(true))["break"]().format();W.get("display").call(W,t)}else{W.get("write").call(W,t)}W.get("newline").call(W)},"(pprint expression)\n\n This function will pretty print its input to stdout. If it is called\n with a non-list, it will just call the print function on its\n input."),print:l("print",function e(){var t=W.get("display");var r=W.get("newline");var n=this.use_dynamic;var i=W;var u=W;for(var a=arguments.length,o=new Array(a),s=0;s1?r-1:0),i=1;in.length){throw new Error("Not enough arguments")}var o=0;var s=W.get("repr");t=t.replace(u,function(e){var t=e[1];if(t==="~"){return"~"}else if(t==="%"){return"\n"}else{var r=n[o++];if(t==="a"){return s(r)}else{return s(r,true)}}});a=t.match(/~([\S])/);if(a){throw new Error("format: Unrecognized escape sequence ".concat(a[1]))}return t},"(format string n1 n2 ...)\n\n This function accepts a string template and replaces any\n escape sequences in its inputs:\n\n * ~a value as if printed with `display`\n * ~s value as if printed with `write`\n * ~% newline character\n * ~~ literal tilde '~'\n\n If there are missing inputs or other escape characters it\n will error."),display:l("display",function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(r===null){r=yo(this,"stdout")}else{F("display",r,"output-port")}var n=t;if(!(r instanceof io)){n=W.get("repr")(t)}r.write.call(W,n)},"(display string [port])\n\n This function outputs the string to the standard output or\n the port if given. No newline."),"display-error":l("display-error",function e(){var t=yo(this,"stderr");var r=W.get("repr");for(var n=arguments.length,i=new Array(n),u=0;u1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=le(t,Cr);var i=this;var a=this;var o;var s=z(z({},n),{},{env:this,dynamic_env:i,use_dynamic:r});var c=A(e.cdr.car,s);c=Uo(c);function f(t,r,n){if(Mu(t)){return t.then(function(e){return f(t,e,n)})}if(Mu(r)){return r.then(function(e){return f(t,e,n)})}if(Mu(n)){return n.then(function(e){return f(t,r,e)})}a.get("set-obj!").call(a,t,r,n);return n}if(G(e.car)&&$.is(e.car.car,".")){var l=e.car.cdr.car;var h=e.car.cdr.cdr.car;var _=A(l,s);var p=A(h,s);return f(_,p,c)}if(!(e.car instanceof $)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var d=e.car.valueOf();o=this.ref(e.car.__name__);return D(c,function(e){if(!o){var t=d.split(".");if(t.length>1){var r=t.pop();var n=t.join(".");var i=u.get(n,{throwError:false});if(i){f(i,r,e);return}}throw new Error("Unbound variable `"+d+"'")}o.set(d,e)})}),"(set! name value)\n\n Macro that can be used to set the value of the variable or slot (mutate it).\n set! searches the scope chain until it finds first non empty slot and sets it."),"unset!":l(new K("set!",function(e){if(!(e.car instanceof $)){throw new Error("unset! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var t=e.car;var r=this.ref(t);if(r){delete r.__env__[t.__name__]}}),"(unset! name)\n\n Function to delete the specified name from environment.\n Trying to access the name afterwards will error."),"set-car!":l("set-car!",function(e,t){F("set-car!",e,"pair");e.car=t},"(set-car! obj value)\n\n Function that sets the car (first item) of the list/pair to specified value.\n The old value is lost."),"set-cdr!":l("set-cdr!",function(e,t){F("set-cdr!",e,"pair");e.cdr=t},"(set-cdr! obj value)\n\n Function that sets the cdr (tail) of the list/pair to specified value.\n It will destroy the list. The old tail is lost."),"empty?":l("empty?",function(e){return typeof e==="undefined"||H(e)},"(empty? object)\n\n Function that returns #t if value is nil (an empty list) or undefined."),gensym:l("gensym",Qn,"(gensym)\n\n Generates a unique symbol that is not bound anywhere,\n to use with macros as meta name."),load:l("load",function e(o,t){F("load",o,"string");var s=this;if(s.__name__==="__frame__"){s=s.__parent__}if(!(t instanceof E)){if(s===W){t=s}else{t=this.get("**interaction-environment**")}}var c="**module-path**";var f=W.get(c,{throwError:false});o=o.valueOf();if(!o.match(/.[^.]+$/)){o+=".scm"}var r=o.match(/\.xcb$/);function l(e){if(r){e=Os(e)}else{if(qo(e)==="buffer"){e=e.toString()}e=e.replace(/^(#!.*)/,function(e,t){if(Ou(t)){return t}return""});if(e.match(/^\{/)){e=ws(e)}}return es(e,{env:t})}function n(e){return zr.fetch(e).then(function(e){return r?e.arrayBuffer():e.text()}).then(function(e){if(r){e=new Uint8Array(e)}return e})}if(So()){return new Promise(function(){var r=ie(O.mark(function e(r,n){var i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:i=Kr("path");if(!f){t.next=6;break}f=f.valueOf();o=i.join(f,o);t.next=12;break;case 6:u=s.get("command-line",{throwError:false});if(!u){t.next=11;break}t.next=10;return u();case 10:a=t.sent;case 11:if(a&&!H(a)){process.cwd();o=i.join(i.dirname(a.car.valueOf()),o)}case 12:W.set(c,i.dirname(o));Kr("fs").readFile(o,function(e,t){if(e){n(e);W.set(c,f)}else{try{l(t).then(function(){r();W.set(c,f)})["catch"](n)}catch(e){n(e)}}});case 14:case"end":return t.stop()}},e)}));return function(e,t){return r.apply(this,arguments)}}())}if(f){f=f.valueOf();o=f+"/"+o.replace(/^\.?\/?/,"")}return n(o).then(function(e){W.set(c,o.replace(/\/[^/]*$/,""));return l(e)}).then(function(){})["finally"](function(){W.set(c,f)})},"(load filename)\n (load filename environment)\n\n Fetches the file (from disk or network) and evaluates its content as LIPS code.\n If the second argument is provided and it's an environment the evaluation\n will happen in that environment."),while:l(new K("while",function(e,t){var r=e.car;var n=z(z({},t),{},{env:this});var i=new J(new $("begin"),e.cdr);return function t(){return D(A(r,n),function(e){if(e){return D(A(i,n),t)}})}()}),"(while cond body)\n\n Creates a loop, it executes cond and body until cond expression is false."),do:l(new K("do",function(){var r=ie(function(h,e){var _=this;var p=e.use_dynamic,d=e.error;return O.mark(function e(){var o,r,s,c,n,f,l,i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:o=_;r=o;s=o.inherit("do");c=h.car;n=h.cdr.car;f=h.cdr.cdr;if(!H(f)){f=new J($("begin"),f)}l={env:o,dynamic_env:r,use_dynamic:p,error:d};i=c;case 9:if(H(i)){t.next=20;break}u=i.car;t.t0=s;t.t1=u.car;t.next=15;return A(u.cdr.car,l);case 15:t.t2=t.sent;t.t0.set.call(t.t0,t.t1,t.t2);i=i.cdr;t.next=9;break;case 20:l={env:s,dynamic_env:r,error:d};a=O.mark(function e(){var r,n,i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(H(f)){t.next=3;break}t.next=3;return Ts.evaluate(f,l);case 3:r=c;n={};case 5:if(H(r)){t.next=15;break}i=r.car;if(H(i.cdr.cdr)){t.next=12;break}t.next=10;return A(i.cdr.cdr.car,l);case 10:u=t.sent;n[i.car.valueOf()]=u;case 12:r=r.cdr;t.next=5;break;case 15:a=Object.getOwnPropertySymbols(n);l.env=s=o.inherit("do");Object.keys(n).concat(a).forEach(function(e){s.set(e,n[e])});case 18:case"end":return t.stop()}},e)});case 22:t.next=24;return A(n.car,l);case 24:t.t3=t.sent;if(!(t.t3===false)){t.next=29;break}return t.delegateYield(a(),"t4",27);case 27:t.next=22;break;case 29:if(H(n.cdr)){t.next=33;break}t.next=32;return A(n.cdr.car,l);case 32:return t.abrupt("return",t.sent);case 33:case"end":return t.stop()}},e)})()});return function(e,t){return r.apply(this,arguments)}}()),"(do (( )) (test return) . body)\n\n Iteration macro that evaluates the expression body in scope of the variables.\n On each loop it changes the variables according to the expression and runs\n test to check if the loop should continue. If test is a single value, the macro\n will return undefined. If the test is a pair of expressions the macro will\n evaluate and return the second expression after the loop exits."),if:l(new K("if",function(r,e){var t=e.error,n=e.use_dynamic;var i=this;var u=this;var a={env:u,dynamic_env:i,use_dynamic:n,error:t};var o=function e(t){if(Cu(t)){return A(r.cdr.cdr.car,a)}else{return A(r.cdr.car,a)}};if(H(r)){throw new Error("too few expressions for `if`")}var s=A(r.car,a);return D(s,o)}),"(if cond true-expr false-expr)\n\n Macro that evaluates cond expression and if the value is true, it\n evaluates and returns true-expression, if not it evaluates and returns\n false-expression."),"let-env":new K("let-env",function(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=e.dynamic_env,n=e.use_dynamic,i=e.error;F("let-env",t,"pair");var u=A(t.car,{env:this,dynamic_env:r,error:i,use_dynamic:n});return D(u,function(e){F("let-env",e,"environment");return A(J($("begin"),t.cdr),{env:e,dynamic_env:r,error:i})})},"(let-env env . body)\n\n Special macro that evaluates body in context of given environment\n object."),letrec:l(ga(Symbol["for"]("letrec")),"(letrec ((a value-a) (b value-b) ...) . body)\n\n Macro that creates a new environment, then evaluates and assigns values to\n names and then evaluates the body in context of that environment.\n Values are evaluated sequentially and the next value can access the\n previous values/names."),"letrec*":l(ga(Symbol["for"]("letrec")),"(letrec* ((a value-a) (b value-b) ...) . body)\n\n Same as letrec but the order of execution of the binding is guaranteed,\n so you can use recursive code as well as referencing the previous binding.\n\n In LIPS both letrec and letrec* behave the same."),"let*":l(ga(Symbol["for"]("let*")),"(let* ((a value-a) (b value-b) ...) . body)\n\n Macro similar to `let`, but the subsequent bindings after the first\n are evaluated in the environment including the previous let variables,\n so you can define one variable, and use it in the next's definition."),let:l(ga(Symbol["for"]("let")),"(let ((a value-a) (b value-b) ...) . body)\n\n Macro that creates a new environment, then evaluates and assigns values to names,\n and then evaluates the body in context of that environment. Values are evaluated\n sequentially but you can't access previous values/names when the next are\n evaluated. You can only get them in the body of the let expression. (If you want\n to define multiple variables and use them in each other's definitions, use\n `let*`.)"),"begin*":l(ba("begin*",function(e){return e.pop()}),"(begin* . body)\n\n This macro is a parallel version of begin. It evaluates each expression\n in the body and if it's a promise it will await it in parallel and return\n the value of the last expression (i.e. it uses Promise.all())."),shuffle:l("shuffle",function(e){F("shuffle",e,["pair","nil","array"]);var t=W.get("random");if(H(e)){return Y}if(Array.isArray(e)){return Ki(e.slice(),t)}var r=W.get("list->array")(e);r=Ki(r,t);return W.get("array->list")(r)},"(shuffle obj)\n\n Order items in vector or list in random order."),begin:l(new K("begin",function(e,t){var n=z(z({},t),{},{env:this});var i=W.get("list->array")(e);var u;return function t(){if(i.length){var e=i.shift();var r=A(e,n);return D(r,function(e){u=e;return t()})}else{return u}}()}),"(begin . args)\n\n Macro that runs a list of expressions in order and returns the value\n of the last one. It can be used in places where you can only have a\n single expression, like (if)."),ignore:new K("ignore",function(e,t){var r=z(z({},t),{},{env:this,dynamic_env:this});A(new J(new $("begin"),e),r)},"(ignore . body)\n\n Macro that will evaluate the expression and swallow any promises that may\n be created. It will discard any value that may be returned by the last body\n expression. The code should have side effects and/or when it's promise\n it should resolve to undefined."),"call/cc":l(K.defmacro("call/cc",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=z({env:this},t);return D(A(e.car,r),function(e){if(d(e)){return e(new Zo(null))}})}),"(call/cc proc)\n\n Call-with-current-continuation.\n\n NOT SUPPORTED BY LIPS RIGHT NOW"),parameterize:l(new K("parameterize",function(t,e){var i=e.dynamic_env;var u=i.inherit("parameterize").new_frame(null,{});var a=z(z({},e),{},{env:this});var o=t.car;if(!G(o)){var r=qo(o);throw new Error("Invalid syntax for parameterize expecting pair got ".concat(r))}function s(){var e=new J(new $("begin"),t.cdr);return A(e,z(z({},a),{},{dynamic_env:u}))}return function r(){var e=o.car;var n=e.car.valueOf();return D(A(e.cdr.car,a),function(e){var t=i.get(n,{throwError:false});if(!Pu(t)){throw new Error("Unknown parameter ".concat(n))}u.set(n,t.inherit(e));if(!ku(o.cdr)){o=o.cdr;return r()}else{return s()}})}()}),"(parameterize ((name value) ...)\n\n Macro that change the dynamic variable created by make-parameter."),"make-parameter":l(new K("make-parameter",function(e,t){t.dynamic_env;var r=A(e.car,t);var n;if(G(e.cdr.car)){n=A(e.cdr.car,t)}return new Go(r,n)}),"(make-parameter init converter)\n\n Function creates new dynamic variable that can be custimized with parameterize\n macro. The value should be assigned to a variable e.g.:\n\n (define radix (make-parameter 10))\n\n The result value is a procedure that return the value of dynamic variable."),"define-syntax-parameter":l(new K("define-syntax-parameter",function(e,t){var r=e.car;var n=this;if(!(r instanceof $)){throw new Error("define-syntax-parameter: invalid syntax expecting symbol got ".concat(qo(r)))}var i=A(e.cdr.car,z({env:n},t));F("define-syntax-parameter",i,"syntax",2);i.__name__=r.valueOf();if(i.__name__ instanceof x){i.__name__=i.__name__.valueOf()}var u;if(G(e.cdr.cdr)&&x.isString(e.cdr.cdr.car)){u=e.cdr.cdr.car.valueOf()}n.set(e.car,new xu(i),u,true)}),"(define-syntax-parameter name syntax [__doc__])\n\n Binds to the transformer obtained by evaluating .\n The transformer provides the default expansion for the syntax parameter,\n and in the absence of syntax-parameterize, is functionally equivalent to\n define-syntax."),"syntax-parameterize":l(new K("syntax-parameterize",function(e,t){var r=W.get("list->array")(e.car);var n=this.inherit("syntax-parameterize");while(r.length){var i=r.shift();if(!(G(i)||i.car instanceof $)){var u="invalid syntax for syntax-parameterize: ".concat(Wi(e,true));throw new Error("syntax-parameterize: ".concat(u))}var a=A(i.cdr.car,z(z({},t),{},{env:this}));var o=i.car;F("syntax-parameterize",a,["syntax"]);F("syntax-parameterize",o,"symbol");a.__name__=o.valueOf();if(a.__name__ instanceof x){a.__name__=a.__name__.valueOf()}var s=new xu(a);if(o.is_gensym()){var c=o.literal();var f=this.get(c,{throwError:false});if(f instanceof xu){n.set(c,s)}}n.set(o,s)}var l=new J(new $("begin"),e.cdr);return A(l,z(z({},t),{},{env:n}))}),"(syntax-parameterize (bindings) body)\n\n Macro work similar to let-syntax but the the bindnds will be exposed to the user.\n With syntax-parameterize you can define anaphoric macros."),define:l(K.defmacro("define",function(r,e){var n=this;if(G(r.car)&&r.car.car instanceof $){var t=new J(new $("define"),new J(r.car.car,new J(new J(new $("lambda"),new J(r.car.cdr,r.cdr)))));return t}else if(e.macro_expand){return}e.dynamic_env=this;e.env=n;var i=r.cdr.car;var u;if(G(i)){i=A(i,e);u=true}else if(i instanceof $){i=n.get(i)}F("define",r.car,"symbol");return D(i,function(e){if(n.__name__===Du.__merge_env__){n=n.__parent__}if(u&&(d(e)&&da(e)||e instanceof Du||Pu(e))){e.__name__=r.car.valueOf();if(e.__name__ instanceof x){e.__name__=e.__name__.valueOf()}}var t;if(G(r.cdr.cdr)&&x.isString(r.cdr.cdr.car)){t=r.cdr.cdr.car.valueOf()}n.set(r.car,e,t,true)})}),'(define name expression)\n (define name expression "doc string")\n (define (function-name . args) . body)\n\n Macro for defining values. It can be used to define variables,\n or functions. If the first argument is list it will create a function\n with name being first element of the list. This form expands to\n `(define function-name (lambda args body))`'),"set-obj!":l("set-obj!",function(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;var i=_(e);if(ku(e)||i!=="object"&&i!=="function"){var u=Po("set-obj!",qo(e),["object","function"]);throw new Error(u)}F("set-obj!",t,["string","symbol","number"]);e=Gu(e);t=t.valueOf();if(arguments.length===2){delete e[t]}else if(ju(e)&&d(r)){e[t]=Gu(r);e[t][ca]=true}else if(d(r)||Vu(r)||H(r)){e[t]=r}else{e[t]=r&&!ju(r)?r.valueOf():r}if(Zi){var a=e[t];Object.defineProperty(e,t,z(z({},n),{},{value:a}))}},"(set-obj! obj key value)\n (set-obj! obj key value props)\n\n Function set a property of a JavaScript object. props should be a vector of pairs,\n passed to Object.defineProperty."),"null-environment":l("null-environment",function(){return W.inherit("null")},"(null-environment)\n\n Returns a clean environment with only the standard library."),values:l("values",function e(){for(var t=arguments.length,r=new Array(t),n=0;n1&&arguments[1]!==undefined?arguments[1]:{},m=e.use_dynamic,y=e.error;var g=this;var b;if(G(v.cdr)&&x.isString(v.cdr.car)&&!H(v.cdr.cdr)){b=v.cdr.car.valueOf()}function w(){var e=Iu(this)?this:{dynamic_env:g},r=e.dynamic_env;var n=g.inherit("lambda");r=r.inherit("lambda");if(this&&!Iu(this)){if(this&&!this.__instance__){Object.defineProperty(this,"__instance__",{enumerable:false,get:function e(){return true},set:function e(){},configurable:false})}n.set("this",this)}for(var t=arguments.length,i=new Array(t),u=0;u> SYNTAX");V(e);V(y);var n=w.inherit("syntax");var i=n;var u=this;if(u.__name__===Du.__merge_env__){var a=Object.getOwnPropertySymbols(u.__env__);a.forEach(function(e){u.__parent__.set(e,u.__env__[e])});u=u.__parent__}var o={env:n,dynamic_env:i,use_dynamic:g,error:b};var s,c,f;if(y.car instanceof $){s=y.car;f=D(y.cdr.car);c=y.cdr.cdr}else{s="...";f=D(y.car);c=y.cdr}try{while(!H(c)){var l=c.car.car;var h=c.car.cdr.car;V("[[[ RULE");V(l);var _=Eu(l,e,f,s,{expansion:this,define:w});if(_){if(Wr()){console.log(JSON.stringify(iu(_),true,2));console.log("PATTERN: "+l.toString(true));console.log("MACRO: "+e.toString(true))}var p=[];var d=Au({bindings:_,expr:h,symbols:f,scope:n,lex_scope:u,names:p,ellipsis:s});V("OUPUT>>> ",d);if(d){h=d}var v=u.merge(n,Du.__merge_env__);if(r){return{expr:h,scope:v}}var m=A(h,z(z({},o),{},{env:v}));return Fu(m,p)}c=c.cdr}}catch(e){e.message+="\nin macro:\n ".concat(y.toString(true));throw e}throw new Error("syntax-rules: no matching syntax in macro ".concat(e.toString(true)))},w);r.__code__=y;return r},"(syntax-rules () (pattern expression) ...)\n\n Base of hygienic macros, it will return a new syntax expander\n that works like Lisp macros."),quote:l(new K("quote",function(e){return po(e.car)}),"(quote expression) or 'expression\n\n Macro that returns a single LIPS expression as data (it won't evaluate the\n argument). It will return a list if put in front of LIPS code.\n And if put in front of a symbol it will return the symbol itself, not the value\n bound to that name."),"unquote-splicing":l("unquote-splicing",function(){throw new Error("You can't call `unquote-splicing` outside of quasiquote")},"(unquote-splicing code) or ,@code\n\n Special form used in the quasiquote macro. It evaluates the expression inside and\n splices the list into quasiquote's result. If it is not the last element of the\n expression, the computed value must be a pair."),unquote:l("unquote",function(){throw new Error("You can't call `unquote` outside of quasiquote")},"(unquote code) or ,code\n\n Special form used in the quasiquote macro. It evaluates the expression inside and\n substitutes the value into quasiquote's result."),quasiquote:K.defmacro("quasiquote",function(e,t){var o=t.use_dynamic,s=t.error;var c=this;var f=c;function u(e){return G(e)||Qi(e)||Array.isArray(e)}function l(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:u;if(G(e)){var n=e.car;var i=e.cdr;if(r(n)){n=t(n)}if(r(i)){i=t(i)}if(Mu(n)||Mu(i)){return Xn([n,i]).then(function(e){var t=b(e,2),r=t[0],n=t[1];return new J(r,n)})}else{return new J(n,i)}}return e}function a(e,t){if(G(e)){if(!H(t)){e.append(t)}}else{e=new J(e,t)}return e}function r(e){return!!e.filter(function(e){return G(e)&&$.is(e.car,/^(unquote|unquote-splicing)$/)}).length}function h(e,n,i){return e.reduce(function(e,t){if(!G(t)){e.push(t);return e}if($.is(t.car,"unquote-splicing")){var r;if(n+11){var t="You can't splice multiple atoms inside list";throw new Error(t)}if(!(G(i.cdr)&&H(r[0]))){return r[0]}}r=r.map(function(e){if(d.has(e)){return e.clone()}else{d.add(e);return e}});var n=v(i.cdr,0,1);if(H(n)&&H(r[0])){return undefined}return D(n,function(e){if(H(r[0])){return e}if(r.length===1){return a(r[0],e)}var t=r.reduce(function(e,t){return a(e,t)});return a(t,e)})})}(i.car.cdr)}var d=new Set;function v(e,t,r){if(G(e)){if(G(e.car)){if($.is(e.car.car,"unquote-splicing")){return p(e,t+1,r)}if($.is(e.car.car,"unquote")){if(t+2===r&&G(e.car.cdr)&&G(e.car.cdr.car)&&$.is(e.car.cdr.car.car,"unquote-splicing")){var n=e.car.cdr;return new J(new J(new $("unquote"),p(n,t+2,r)),Y)}else if(G(e.car.cdr)&&!H(e.car.cdr.cdr)){if(G(e.car.cdr.car)){var i=[];return function t(r){if(H(r)){return J.fromArray(i)}return D(A(r.car,{env:c,dynamic_env:f,use_dynamic:o,error:s}),function(e){i.push(e);return t(r.cdr)})}(e.car.cdr)}else{return e.car.cdr}}}}if($.is(e.car,"quasiquote")){var u=v(e.cdr,t,r+1);return new J(e.car,u)}if($.is(e.car,"quote")){return new J(e.car,v(e.cdr,t,r))}if($.is(e.car,"unquote")){t++;if(tr){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(G(e.cdr)){if(!H(e.cdr.cdr)){if(G(e.cdr.car)){var a=[];return function t(r){if(H(r)){return J.fromArray(a)}return D(A(r.car,{env:c,dynamic_env:f,use_dynamic:o,error:s}),function(e){a.push(e);return t(r.cdr)})}(e.cdr)}else{return e.cdr}}else{return A(e.cdr.car,{env:c,dynamic_env:f,error:s})}}else{return e.cdr}}return l(e,function(e){return v(e,t,r)})}else if(Qi(e)){return _(e,t,r)}else if(e instanceof Array){return h(e,t,r)}return e}function n(e){if(G(e)){delete e[ia];if(!e.have_cycles("car")){n(e.car)}if(!e.have_cycles("cdr")){n(e.cdr)}}}if(Qi(e.car)&&!r(Object.values(e.car))){return po(e.car)}if(Array.isArray(e.car)&&!r(e.car)){return po(e.car)}if(G(e.car)&&!e.car.find("unquote")&&!e.car.find("unquote-splicing")&&!e.car.find("quasiquote")){return po(e.car)}var i=v(e.car,0,1);return D(i,function(e){n(e);return po(e)})},"(quasiquote list)\n\n Similar macro to `quote` but inside it you can use special expressions (unquote\n x) abbreviated to ,x that will evaluate x and insert its value verbatim or\n (unquote-splicing x) abbreviated to ,@x that will evaluate x and splice the value\n into the result. Best used with macros but it can be used outside."),clone:l("clone",function e(t){F("clone",t,"pair");return t.clone()},"(clone list)\n\n Function that returns a clone of the list, that does not share any pairs with the\n original, so the clone can be safely mutated without affecting the original."),append:l("append",function e(){var t;for(var r=arguments.length,n=new Array(r),i=0;iarray")(t).reverse();return W.get("array->list")(r)}else if(Array.isArray(t)){return t.reverse()}else{throw new Error(Po("reverse",qo(t),"array or pair"))}},"(reverse list)\n\n Function that reverses the list or array. If value is not a list\n or array it will error."),nth:l("nth",function e(t,r){F("nth",t,"number");F("nth",r,["array","pair"]);if(G(r)){var n=r;var i=0;while(iarray")(r).join(t)},"(join separator list)\n\n Function that returns a string by joining elements of the list using separator."),split:l("split",function e(t,r){F("split",t,["regex","string"]);F("split",r,"string");return W.get("array->list")(r.split(t))},"(split separator string)\n\n Function that creates a list by splitting string by separator which can\n be a string or regular expression."),replace:l("replace",function e(t,r,n){F("replace",t,["regex","string"]);F("replace",r,["string","function"]);F("replace",n,"string");if(d(r)){var i=[];n.replace(t,function(){i.push(r.apply(void 0,arguments))});return D(i,function(e){return n.replace(t,function(){return e.shift()})})}return n.replace(t,r)},"(replace pattern replacement string)\n\n Function that changes pattern to replacement inside string. Pattern can be a\n string or regex and replacement can be function or string. See Javascript\n String.replace()."),match:l("match",function e(t,r){F("match",t,["regex","string"]);F("match",r,"string");var n=r.match(t);return n?W.get("array->list")(n):false},"(match pattern string)\n\n Function that returns a match object from JavaScript as a list or #f if\n no match."),search:l("search",function e(t,r){F("search",t,["regex","string"]);F("search",r,"string");return r.search(t)},"(search pattern string)\n\n Function that returns the first found index of the pattern inside a string."),repr:l("repr",function e(t,r){return fu(t,r)},"(repr obj)\n\n Function that returns a LIPS code representation of the object as a string."),"escape-regex":l("escape-regex",function(e){F("escape-regex",e,"string");return Rn(e.valueOf())},"(escape-regex string)\n\n Function that returns a new string where all special operators used in regex,\n are escaped with backslashes so they can be used in the RegExp constructor\n to match a literal string."),env:l("env",function e(e){e=e||this.env;var t=Object.keys(e.__env__).map($);var r;if(t.length){r=J.fromArray(t)}else{r=Y}if(e.__parent__ instanceof E){return W.get("env").call(this,e.__parent__).append(r)}return r},"(env)\n (env obj)\n\n Function that returns a list of names (functions, macros and variables)\n that are bound in the current environment or one of its parents."),new:l("new",function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n2&&arguments[2]!==undefined?arguments[2]:ri.LITERAL;F("set-special!",e,"string",1);F("set-special!",t,"symbol",2);ri.append(e.valueOf(),t,r)},'(set-special! symbol name [type])\n\n Add a special symbol to the list of transforming operators by the parser.\n e.g.: `(add-special! "#" \'x)` will allow to use `#(1 2 3)` and it will be\n transformed into (x (1 2 3)) so you can write x macro that will process\n the list. 3rd argument is optional, and it can be one of two values:\n lips.specials.LITERAL, which is the default behavior, or\n lips.specials.SPLICE which causes the value to be unpacked into the expression.\n This can be used for e.g. to make `#(1 2 3)` into (x 1 2 3) that is needed\n by # that defines vectors.'),get:mo,".":mo,unbind:l(Gu,"(unbind fn)\n\n Function that removes the weak 'this' binding from a function so you\n can get properties from the actual function object."),type:l(qo,"(type object)\n\n Function that returns the type of an object as string."),debugger:l("debugger",function(){debugger},'(debugger)\n\n Function that triggers the JavaScript debugger (e.g. the browser devtools)\n using the "debugger;" statement. If a debugger is not running this\n function does nothing.'),in:l("in",function(e,t){if(e instanceof $||e instanceof x||e instanceof j){e=e.valueOf()}return e in Ku(t)},'(in key value)\n\n Function that uses the Javascript "in" operator to check if key is\n a valid property in the value.'),"instance?":l("instance?",function(e){return Uu(e)},"(instance? obj)\n\n Checks if object is an instance, created with a new operator"),instanceof:l("instanceof",function(e,t){return t instanceof Gu(e)},"(instanceof type obj)\n\n Predicate that tests if the obj is an instance of type."),"prototype?":l("prototype?",ju,"(prototype? obj)\n\n Predicate that tests if value is a valid JavaScript prototype,\n i.e. calling (new) with it will not throw ' is not a constructor'."),"macro?":l("macro?",function(e){return e instanceof K},"(macro? expression)\n\n Predicate that tests if value is a macro."),"continuation?":l("continuation?",Bu,"(continuation? expression)\n\n Predicate that tests if value is a callable continuation."),"function?":l("function?",d,"(function? expression)\n\n Predicate that tests if value is a callable function."),"real?":l("real?",function(e){if(qo(e)!=="number"){return false}if(e instanceof j){return e.isFloat()}return j.isFloat(e)},"(real? number)\n\n Predicate that tests if value is a real number (not complex)."),"number?":l("number?",function(e){return Number.isNaN(e)||j.isNumber(e)},"(number? expression)\n\n Predicate that tests if value is a number or NaN value."),"string?":l("string?",function(e){return x.isString(e)},"(string? expression)\n\n Predicate that tests if value is a string."),"pair?":l("pair?",G,"(pair? expression)\n\n Predicate that tests if value is a pair or list structure."),"regex?":l("regex?",function(e){return e instanceof RegExp},"(regex? expression)\n\n Predicate that tests if value is a regular expression."),"null?":l("null?",function(e){return ku(e)},"(null? expression)\n\n Predicate that tests if value is null-ish (i.e. undefined, nil, or\n Javascript null)."),"boolean?":l("boolean?",function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Predicate that tests if value is a boolean (#t or #f)."),"symbol?":l("symbol?",function(e){return e instanceof $},"(symbol? expression)\n\n Predicate that tests if value is a LIPS symbol."),"array?":l("array?",function(e){return e instanceof Array},"(array? expression)\n\n Predicate that tests if value is an array."),"object?":l("object?",function(e){return!H(e)&&e!==null&&!(e instanceof h)&&!(e instanceof RegExp)&&!(e instanceof x)&&!G(e)&&!(e instanceof j)&&_(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Predicate that tests if value is an plain object (not another LIPS type)."),flatten:l("flatten",function e(t){F("flatten",t,"pair");return t.flatten()},"(flatten list)\n\n Returns a shallow list from tree structure (pairs)."),"array->list":l("array->list",function(e){F("array->list",e,"array");return J.fromArray(e)},"(array->list array)\n\n Function that converts a JavaScript array to a LIPS cons list."),"tree->array":l("tree->array",Gi("tree->array",true),"(tree->array list)\n\n Function that converts a LIPS cons tree structure into a JavaScript array."),"list->array":l("list->array",Gi("list->array"),"(list->array list)\n\n Function that converts a LIPS list into a JavaScript array."),apply:l("apply",function e(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;iarray").call(this,u));return t.apply(this,Yo(t,n))},"(apply fn list)\n\n Function that calls fn with the list of arguments."),length:l("length",function e(t){if(!t||H(t)){return 0}if(G(t)){return t.length()}if("length"in t){return t.length}},'(length expression)\n\n Function that returns the length of the object. The object can be a LIPS\n list or any object that has a "length" property. Returns undefined if the\n length could not be found.'),"string->number":l("string->number",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;F("string->number",e,"string",1);F("string->number",t,"number",2);e=e.valueOf();t=t.valueOf();if(e.match(bn)||e.match(mn)){return Fn(e,t)}else if(e.match(wn)||e.match(vn)){return On(e,t)}else{var r=t===10&&!e.match(/e/i)||t===16;if(e.match(gn)&&r||e.match(yn)){return An(e,t)}if(e.match(un)){return Bn(e)}}return false},"(string->number number [radix])\n\n Function that parses a string into a number."),try:l(new K("try",function(r,e){var l=this;var h=e.use_dynamic;e.error;return new Promise(function(t,o){var s,n;if($.is(r.cdr.car.car,"catch")){s=r.cdr.car;if(G(r.cdr.cdr)&&$.is(r.cdr.cdr.car.car,"finally")){n=r.cdr.cdr.car}}else if($.is(r.cdr.car.car,"finally")){n=r.cdr.car}if(!(n||s)){throw new Error("try: invalid syntax")}function c(e){t(e);throw new lo("[CATCH]")}var f=function e(t,r){r(t)};if(n){f=function e(t,r){f=o;i.error=function(e){throw e};D(A(new J(new $("begin"),n.cdr),i),function(){r(t)})}}var i={env:l,use_dynamic:h,dynamic_env:l,error:function e(t){if(t instanceof lo){throw t}if(s){var r=l.inherit("try");var n=s.cdr.car.car;if(!(n instanceof $)){throw new Error("try: invalid syntax: catch require variable name")}r.set(n,t);var i;var u={env:r,use_dynamic:h,dynamic_env:l,error:function e(t){i=true;o(t);throw new lo("[CATCH]")}};var a=A(new J(new $("begin"),s.cdr.cdr),u);D(a,function e(t){if(!i){f(t,c)}})}else{f(undefined,function(){o(t)})}}};var e=A(r.car,i);D(e,function(e){f(e,t)},i.error)})}),"(try expr (catch (e) code))\n (try expr (catch (e) code) (finally code))\n (try expr (finally code))\n\n Macro that executes expr and catches any exceptions thrown. If catch is provided\n it's executed when an error is thrown. If finally is provided it's always\n executed at the end."),raise:l("raise",function(e){throw e},"(raise obj)\n\n Throws the object verbatim (no wrapping an a new Error)."),throw:l("throw",function(e){throw new Error(e)},"(throw string)\n\n Throws a new exception."),find:l("find",function t(r,n){F("find",r,["regex","function"]);F("find",n,["pair","nil"]);if(ku(n)){return Y}var e=bi("find",r);return D(e(n.car),function(e){if(e&&!H(e)){return n.car}return t(r,n.cdr)})},"(find fn list)\n (find regex list)\n\n Higher-order function that finds the first value for which fn return true.\n If called with a regex it will create a matcher function."),"for-each":l("for-each",function(e){var t;F("for-each",e,"function");for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i1?t-1:0),u=1;u3?n-3:0),u=3;u3?i-3:0),a=3;aarray")(r);var u=[];var a=bi("filter",t);return function t(r){function e(e){if(e&&!H(e)){u.push(n)}return t(++r)}if(r===i.length){return J.fromArray(u)}var n=i[r];return D(a(n),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher-order function that calls `fn` for each element of the list\n and return a new list for only those elements for which fn returns\n a truthy value. If called with a regex it will create a matcher function."),compose:l(xa,"(compose . fns)\n\n Higher-order function that creates a new function that applies all functions\n from right to left and returns the last value. Reverse of pipe.\n e.g.:\n ((compose (curry + 2) (curry * 3)) 10) --\x3e (+ 2 (* 3 10)) --\x3e 32"),pipe:l(Da,"(pipe . fns)\n\n Higher-order function that creates a new function that applies all functions\n from left to right and returns the last value. Reverse of compose.\n e.g.:\n ((pipe (curry + 2) (curry * 3)) 10) --\x3e (* 3 (+ 2 10)) --\x3e 36"),curry:l(Ca,"(curry fn . args)\n\n Higher-order function that creates a curried version of the function.\n The result function will have partially applied arguments and it\n will keep returning one-argument functions until all arguments are provided,\n then it calls the original function with the accumulated arguments.\n\n e.g.:\n (define (add a b c d) (+ a b c d))\n (define add1 (curry add 1))\n (define add12 (add 2))\n (display (add12 3 4))"),gcd:l("gcd",function e(){for(var t=arguments.length,r=new Array(t),n=0;no?u%=o:o%=u}u=_u(s*r[a])/(u+o)}return j(u)},"(lcm n1 n2 ...)\n\n Function that returns the least common multiple of the arguments."),"odd?":l("odd?",Aa(function(e){return j(e).isOdd()}),"(odd? number)\n\n Checks if number is odd."),"even?":l("even?",Aa(function(e){return j(e).isEven()}),"(even? number)\n\n Checks if number is even."),"*":l("*",Oa(function(e,t){return j(e).mul(t)},j(1)),"(* . numbers)\n\n Multiplies all numbers passed as arguments. If single value is passed\n it will return that value."),"+":l("+",Oa(function(e,t){return j(e).add(t)},j(0)),"(+ . numbers)\n\n Sums all numbers passed as arguments. If single value is passed it will\n return that value."),"-":l("-",function(){for(var e=arguments.length,t=new Array(e),r=0;r":l(">",function(){for(var e=arguments.length,t=new Array(e),r=0;r",t,["bigint","float","rational"]);return pu(function(e,t){return j(e).cmp(t)===1},t)},"(> x1 x2 x3 ...)\n\n Function that compares its numerical arguments and checks if they are\n monotonically decreasing, i.e. x1 > x2 and x2 > x3 and so on."),"<":l("<",function(){for(var e=arguments.length,t=new Array(e),r=0;r=":l(">=",function(){for(var e=arguments.length,t=new Array(e),r=0;r=",t,["bigint","float","rational"]);return pu(function(e,t){return[0,1].includes(j(e).cmp(t))},t)},"(>= x1 x2 ...)\n\n Function that compares its numerical arguments and checks if they are\n monotonically nonincreasing, i.e. x1 >= x2 and x2 >= x3 and so on."),"eq?":l("eq?",du,"(eq? a b)\n\n Function that compares two values if they are identical."),or:l(new K("or",function(e,t){var i=t.use_dynamic,u=t.error;var a=W.get("list->array")(e);var o=this;var s=o;if(!a.length){return false}var c;return function t(){function e(e){c=e;if(!Cu(c)){return c}else{return t()}}if(!a.length){if(!Cu(c)){return c}else{return false}}else{var r=a.shift();var n=A(r,{env:o,dynamic_env:s,use_dynamic:i,error:u});return D(n,e)}}()}),"(or . expressions)\n\n Macro that executes the values one by one and returns the first that is\n a truthy value. If there are no expressions that evaluate to true it\n returns false."),and:l(new K("and",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=t.error;var i=W.get("list->array")(e);var u=this;var a=u;if(!i.length){return true}var o;var s={env:u,dynamic_env:a,use_dynamic:r,error:n};return function t(){function e(e){o=e;if(Cu(o)){return o}else{return t()}}if(!i.length){if(!Cu(o)){return o}else{return false}}else{var r=i.shift();return D(A(r,s),e)}}()}),"(and . expressions)\n\n Macro that evaluates each expression in sequence and if any value returns false\n it will stop and return false. If each value returns true it will return the\n last value. If it's called without arguments it will return true."),"|":l("|",function(e,t){return j(e).or(t)},"(| a b)\n\n Function that calculates the bitwise or operation."),"&":l("&",function(e,t){return j(e).and(t)},"(& a b)\n\n Function that calculates the bitwise and operation."),"~":l("~",function(e){return j(e).neg()},"(~ number)\n\n Function that calculates the bitwise inverse (flip all the bits)."),">>":l(">>",function(e,t){return j(e).shr(t)},"(>> a b)\n\n Function that right shifts the value a by value b bits."),"<<":l("<<",function(e,t){return j(e).shl(t)},"(<< a b)\n\n Function that left shifts the value a by value b bits."),not:l("not",function e(t){if(ku(t)){return true}return!t},"(not object)\n\n Function that returns the Boolean negation of its argument.")},undefined,"global");var xo=W.inherit("user-env");function Eo(e,t){e.constant("**internal-env**",t);e.doc("**internal-env**","**internal-env**\n\n Constant used to hide stdin, stdout and stderr so they don't interfere\n with variables with the same name. Constants are an internal type\n of variable that can't be redefined, defining a variable with the same name\n will throw an error.");W.set("**interaction-environment**",e)}Eo(xo,bo);W.doc("**interaction-environment**","**interaction-environment**\n\n Internal dynamic, global variable used to find interpreter environment.\n It's used so the read and write functions can locate **internal-env**\n that contains the references to stdin, stdout and stderr.");function Fo(e){xo.get("**internal-env**").set("fs",e)}(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(t){var r=e[t]?e[t]:t;W.set(r,l(r,function(e){F(r,e,"number");if(e instanceof j){return e[t]()}},"(".concat(r," number)\n\n Function that calculates the ").concat(r," of a number.")))})})();function Ao(e){if(e.length===1){return e[0]}else{var t=[];var r=Ao(e.slice(1));for(var n=0;n3&&arguments[3]!==undefined?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(n!==null){i+=" (argument ".concat(n,")")}if(d(r)){return"Invalid type: got ".concat(t).concat(i)}if(r instanceof Array){if(r.length===1){var u=r[0].toLowerCase();r="a"+("aeiou".includes(u)?"n ":" ")+r[0]}else{r=new Intl.ListFormat("en",{style:"long",type:"disjunction"}).format(r)}}return"Expecting ".concat(r," got ").concat(t).concat(i)}function No(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;F(e,t,"number",n);var i=t.__type__;var u;if(G(r)){r=r.to_array()}if(r instanceof Array){r=r.map(function(e){return e.valueOf()})}if(r instanceof Array){r=r.map(function(e){return e.valueOf().toLowerCase()});if(r.includes(i)){u=true}}else{r=r.valueOf().toLowerCase()}if(!u&&i!==r){throw new Error(Po(e,i,r,n))}}function To(r,e,n){e.forEach(function(e,t){No(r,e,n,t+1)})}function Lo(r,e,n){e.forEach(function(e,t){F(r,e,n,t+1)})}function Mo(e,t,r){F(e,t,r);if(t.__type__===uo){throw new Error(Po(e,"binary-port","textual-port"))}}function F(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;e=e.valueOf();var i=qo(t).toLowerCase();if(d(r)){if(!r(t)){throw new Error(Po(e,i,r,n))}return}var u=false;if(G(r)){r=r.to_array()}if(r instanceof Array){r=r.map(function(e){return e.valueOf()})}if(r instanceof Array){r=r.map(function(e){return e.valueOf().toLowerCase()});if(r.includes(i)){u=true}}else{r=r.valueOf().toLowerCase()}if(!u&&i!==r){throw new Error(Po(e,i,r,n))}}function Ro(r){var n=new WeakMap;return function(e){var t=n.get(e);if(!t){t=r(e)}return t}}qo=Ro(qo);function qo(e){var t=$r.get(e);if(t){return t}if(_(e)==="object"){for(var r=0,n=Object.entries(Vr);r2&&arguments[2]!==undefined?arguments[2]:{},n=r.env,i=r.dynamic_env,u=r.use_dynamic;var a=n===null||n===void 0?void 0:n.new_frame(e,t);var o=i===null||i===void 0?void 0:i.new_frame(e,t);var s=new Wo({env:a,use_dynamic:u,dynamic_env:o});return Uo(e.apply(s,t))}function Ko(n,e){var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},i=t.env,u=t.dynamic_env,a=t.use_dynamic,r=t.error,o=r===void 0?function(){}:r;e=zo(e,{env:i,dynamic_env:u,error:o,use_dynamic:a});return D(e,function(e){if(ma(n)){n=Gu(n)}e=Yo(n,e);var t=e.slice();var r=Jo(n,t,{env:i,dynamic_env:u,use_dynamic:a});return D(r,function(e){if(G(e)){e.mark_cycles();return po(e)}return Yu(e)},o)})}var Ho=new WeakMap;var Go=function(){function n(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;ue(this,n);q(this,"__value__",void 0);q(this,"__fn__",void 0);Br(this,Ho,{writable:true,value:void 0});this.__value__=e;if(t){if(!d(t)){throw new Error("Section argument to Parameter need to be function "+"".concat(qo(t)," given"))}this.__fn__=t}if(r){f(this,Ho,r)}}ce(n,[{key:"__name__",get:function e(){return r(this,Ho)},set:function e(t){f(this,Ho,t);if(this.__fn__){this.__fn__.__name__="fn-".concat(t)}}},{key:"invoke",value:function e(){if(d(this.__fn__)){return this.__fn__(this.__value__)}return this.__value__}},{key:"inherit",value:function e(t){return new n(t,this.__fn__,this.__name__)}}]);return n}();var Wo=function(){function t(e){ue(this,t);q(this,"env",void 0);q(this,"dynamic_env",void 0);q(this,"use_dynamic",void 0);Object.assign(this,e)}ce(t,[{key:"__name__",get:function e(){return this.env.__name__}},{key:"__parent__",get:function e(){return this.env.__parent__}},{key:"get",value:function e(){var t;return(t=this.env).get.apply(t,arguments)}}]);return t}();function Qo(e,t){var r=e.get(t.__name__,{throwError:false});if(Pu(r)&&r!==t){return r}var n=xo.get("**interaction-environment**");while(true){var i=e.get("parent.frame",{throwError:false});e=i(0);if(e===n){break}r=e.get(t.__name__,{throwError:false});if(Pu(r)&&r!==t){return r}}return t}var Zo=function(){function t(e){ue(this,t);q(this,"__value__",void 0);this.__value__=e}ce(t,[{key:"invoke",value:function e(){if(this.__value__===null){throw new Error("Continuations are not implemented yet")}}}]);return t}();function A(o){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},s=e.env,c=e.dynamic_env,f=e.use_dynamic,t=e.error,l=t===void 0?jo:t,r=le(e,jr);return function(e){try{if(!Nu(c)){c=s===true?xo:s||xo}if(f){s=c}else if(s===true){s=xo}else{s=s||W}var t={env:s,dynamic_env:c,use_dynamic:f,error:l};var r;if(ku(o)){return o}if(o instanceof $){return s.get(o)}if(!G(o)){return o}var n=o.car;var e=o.cdr;if(G(n)){r=Uo(A(n,t));if(Mu(r)){return r.then(function(e){if(!Tu(e)){throw new Error(qo(e)+" "+s.get("repr")(e)+" is not callable while evaluating "+o.toString())}return A(new J(e,o.cdr),t)})}else if(!Tu(r)){throw new Error(qo(r)+" "+s.get("repr")(r)+" is not callable while evaluating "+o.toString())}}if(n instanceof $){r=s.get(n)}else if(d(n)){r=n}var i;if(r instanceof Du){i=Vo(r,o,t)}else if(r instanceof K){i=$o(r,e,t)}else if(d(r)){i=Ko(r,e,t)}else if(r instanceof xu){i=Vo(r._syntax,o,t)}else if(Pu(r)){var u=Qo(c,r);if(ku(o.cdr)){i=u.invoke()}else{return D(A(o.cdr.car,t),function(e){u.__value__=e})}}else if(Bu(r)){i=r.invoke()}else if(G(o)){r=n&&n.toString();throw new Error("".concat(qo(n)," ").concat(r," is not a function"))}else{return o}var a=s.get(Symbol["for"]("__promise__"),{throwError:false});if(a===true&&Mu(i)){i=i.then(function(e){if(G(e)&&!r[ia]){return A(e,t)}return e});return new Zn(i)}return i}catch(e){l&&l.call(s,e,o)}}(r)}var Xo=rs(function(e){return e});var es=rs(function(e,t){return t});function ts(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.env,n=t.dynamic_env,i=t.use_dynamic;return A(e,{env:r,dynamic_env:n,use_dynamic:i,error:function e(t,r){if(t&&t.message){if(t.message.match(/^Error:/)){var n=/^(Error:)\s*([^:]+:\s*)/;t.message=t.message.replace(n,"$1 $2")}if(r){if(!(t.__code__ instanceof Array)){t.__code__=[]}t.__code__.push(r.toString(true))}}if(!(t instanceof lo)){throw t}}})}function rs(d){return function(){var t=ie(function(l){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},h=e.env,_=e.dynamic_env,p=e.use_dynamic;return O.mark(function e(){var r,n,i,u,a,o,s,c,f;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!Nu(_)){_=h===true?xo:h||xo}if(h===true){h=xo}else{h=h||xo}r=[];if(!G(l)){t.next=8;break}t.next=6;return ts(l,{env:h,dynamic_env:_,use_dynamic:p});case 6:t.t0=t.sent;return t.abrupt("return",[t.t0]);case 8:n=Array.isArray(l)?l:pi(l);i=false;u=false;t.prev=11;o=qr(n);case 13:t.next=15;return o.next();case 15:if(!(i=!(s=t.sent).done)){t.next=31;break}c=s.value;t.next=19;return ts(c,{env:h,dynamic_env:_,use_dynamic:p});case 19:f=t.sent;t.t1=r;t.t2=d;t.t3=c;t.next=25;return f;case 25:t.t4=t.sent;t.t5=(0,t.t2)(t.t3,t.t4);t.t1.push.call(t.t1,t.t5);case 28:i=false;t.next=13;break;case 31:t.next=37;break;case 33:t.prev=33;t.t6=t["catch"](11);u=true;a=t.t6;case 37:t.prev=37;t.prev=38;if(!(i&&o["return"]!=null)){t.next=42;break}t.next=42;return o["return"]();case 42:t.prev=42;if(!u){t.next=45;break}throw a;case 45:return t.finish(42);case 46:return t.finish(37);case 47:return t.abrupt("return",r);case 48:case"end":return t.stop()}},e,null,[[11,33,37,47],[38,,42,46]])})()});function e(e){return t.apply(this,arguments)}return e}()}function ns(e){var t={"[":"]","(":")"};var r;if(typeof e==="string"){r=Jn(e)}else{r=e.map(function(e){return e&&e.token?e.token:e})}var n=Object.keys(t);var i=Object.values(t).concat(n);r=r.filter(function(e){return i.includes(e)});var u=new qn;var a=Tr(r),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;if(n.includes(s)){u.push(s)}else if(!u.is_empty()){var c=u.top();var f=t[c];if(s===f){u.pop()}else{throw new Error("Syntax error: missing closing ".concat(f))}}else{throw new Error("Syntax error: not matched closing ".concat(s))}}}catch(e){a.e(e)}finally{a.f()}return u.is_empty()}function is(e){var t="("+e.toString()+")()";var r=window.URL||window.webkitURL;var n;try{n=new Blob([t],{type:"application/javascript"})}catch(e){var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;n=new i;n.append(t);n=n.getBlob()}return new zr.Worker(r.createObjectURL(n))}function us(){return Ts.version.match(/^(\{\{VER\}\}|DEV)$/)}function as(){if(So()){return}var e;if(document.currentScript){e=document.currentScript}else{var t=document.querySelectorAll("script");if(!t.length){return}e=t[t.length-1]}var r=e.getAttribute("src");return r}var os=as();function ss(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"";var t="dist/std.xcb";if(e===""){if(os){e=os.replace(/[^/]*$/,"std.xcb")}else if(us()){e="https://cdn.jsdelivr.net/gh/jcubic/lips@devel/".concat(t)}else{e="https://cdn.jsdelivr.net/npm/@jcubic/lips@".concat(Ts.version,"/").concat(t)}}var r=W.get("load");return r.call(xo,e,W)}function cs(e){this.url=e;var a=this.worker=is(function(){var a;var o;self.addEventListener("message",function(e){var r=e.data;var t=r.id;if(r.type!=="RPC"||t===null){return}function n(e){self.postMessage({id:t,type:"RPC",result:e})}function i(e){self.postMessage({id:t,type:"RPC",error:e})}if(r.method==="eval"){if(!o){i("Worker RPC: LIPS not initialized, call init first");return}o.then(function(){var e=r.params[0];var t=r.params[1];a.exec(e,{use_dynamic:t}).then(function(e){e=e.map(function(e){return e&&e.valueOf()});n(e)})["catch"](function(e){i(e)})})}else if(r.method==="init"){var u=r.params[0];if(typeof u!=="string"){i("Worker RPC: url is not a string")}else{importScripts("".concat(u,"/dist/lips.min.js"));a=new Ts.Interpreter("worker");o=ss(u);o.then(function(){n(true)})}}})});this.rpc=function(){var n=0;return function e(t,r){var u=++n;return new Promise(function(n,i){a.addEventListener("message",function e(t){var r=t.data;if(r&&r.type==="RPC"&&r.id===u){if(r.error){i(r.error)}else{n(r.result)}a.removeEventListener("message",e)}});a.postMessage({type:"RPC",method:t,id:u,params:r})})}}();this.rpc("init",[e])["catch"](function(e){console.error(e)});this.exec=function(e,t){var r=t.use_dynamic,n=r===void 0?false:r;return this.rpc("eval",[e,n])}}var fs={pair:function e(t){var r=b(t,2),n=r[0],i=r[1];return J(n,i)},number:function e(t){if(x.isString(t)){return j([t,10])}return j(t)},regex:function e(t){var r=b(t,2),n=r[0],i=r[1];return new RegExp(n,i)},nil:function e(){return Y},symbol:function e(t){if(x.isString(t)){return $(t)}else if(Array.isArray(t)){return $(Symbol["for"](t[0]))}},string:x,character:h};var ls=Object.keys(fs);var hs={};for(var _s=0,ps=Object.entries(ls);_s1){var n=t.reduce(function(e,t){return e+t.length},0);var i=new Uint8Array(n);var u=0;t.forEach(function(e){i.set(e,u);u+=e.length});return i}else if(t.length){return t[0]}}function Es(){var e=1;var t=new TextEncoder("utf-8");return t.encode("LIPS".concat(e.toString().padStart(3," ")))}var Fs=7;function As(e){var t=new TextDecoder("utf-8");var r=t.decode(e.slice(0,Fs));var n=r.substring(0,4);if(n==="LIPS"){var i=r.match(/^(....).*([0-9]+)$/);if(i){return{type:i[1],version:Number(i[2])}}}return{type:"unknown"}}function ks(e){var t=Es();var r=Ds.encode(e);return xs(t,xr(r,{magic:false}))}function Os(e){var t=As(e),r=t.type,n=t.version;if(r==="LIPS"&&n===1){var i=Er(e.slice(Fs),{magic:false});return Ds.decode(i)}else{throw new Error("Invalid file format ".concat(r))}}function Cs(e){console.error(e.message||e);if(Array.isArray(e.code)){console.error(e.code.map(function(e,t){return"[".concat(t+1,"]: ").concat(e)}))}}function Ss(){var a=["text/x-lips","text/x-scheme"];var o;function s(e){var t;return(t=e.getAttribute("data-bootstrap"))!==null&&t!==void 0?t:e.getAttribute("bootstrap")}function c(r){return new Promise(function(t){var e=r.getAttribute("src");if(e){return fetch(e).then(function(e){return e.text()}).then(es).then(t)["catch"](function(e){Cs(e);t()})}else{return es(r.innerHTML).then(t)["catch"](function(e){Cs(e);t()})}})}function e(){return new Promise(function(i){var u=Array.from(document.querySelectorAll("script"));return function e(){var t=u.shift();if(!t){i()}else{var r=t.getAttribute("type");if(a.includes(r)){var n=s(t);if(!o&&typeof n==="string"){return ss(n).then(function(){return c(t)}).then(e)}else{return c(t).then(e)}}else if(r&&r.match(/lips|lisp/)){console.warn("Expecting "+a.join(" or ")+" found "+r)}return e()}}()})}if(!window.document){return Promise.resolve()}else if(js){var t=js;var r=s(t);if(typeof r==="string"){return ss(r).then(function(){o=true;return e()})}}return e()}var js=typeof window!=="undefined"&&window.document&&document.currentScript;if(typeof window!=="undefined"){Gr(window,Ss)}var Bs=function(){var e=x("Fri, 22 Mar 2024 16:45:56 +0000").valueOf();var t=e==="{{"+"DATE}}"?new Date:new Date(e);var r=function e(t){return t.toString().padStart(2,"0")};var n=t.getFullYear();var i=[n,r(t.getMonth()+1),r(t.getDate())].join("-");var u="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter DEV (".concat(i,") \nCopyright (c) 2018-").concat(n," Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables. You can also\nuse (help name) to display help for specific function or macro, (apropos name)\nto display list of matched names in environment and (dir object) to list\nproperties of an object.\n").replace(/^.*\n/,"");return u}();o(Ai,"__class__","ahead");o(J,"__class__","pair");o(Hi,"__class__","nil");o(ki,"__class__","pattern");o(Fi,"__class__","formatter");o(K,"__class__","macro");o(Du,"__class__","syntax");o(Du.Parameter,"__class__","syntax-parameter");o(E,"__class__","environment");o(Ha,"__class__","input-port");o(Ga,"__class__","output-port");o(Wa,"__class__","output-port");o(Qa,"__class__","output-string-port");o(Xa,"__class__","input-string-port");o(ro,"__class__","input-file-port");o(Za,"__class__","output-file-port");o(fo,"__class__","lips-error");[j,y,w,g,Ka].forEach(function(e){o(e,"__class__","number")});o(h,"__class__","character");o($,"__class__","symbol");o(x,"__class__","string");o(Zn,"__class__","promise");o(Go,"__class__","parameter");var Is="DEV";var Ps="Fri, 22 Mar 2024 16:45:56 +0000";var Ns=xa(yi,pi);var Ts={version:Is,banner:Bs,date:Ps,exec:es,parse:Ns,tokenize:Jn,evaluate:A,compile:Xo,serialize:bs,unserialize:ws,serialize_bin:ks,unserialize_bin:Os,bootstrap:ss,Environment:E,env:xo,Worker:cs,Interpreter:co,balanced_parenthesis:ns,balancedParenthesis:ns,balanced:ns,Macro:K,Syntax:Du,Pair:J,Values:_o,QuotedPromise:Zn,Error:fo,quote:po,InputPort:Ha,OutputPort:Ga,BufferedOutputPort:Wa,InputFilePort:ro,OutputFilePort:Za,InputStringPort:Xa,OutputStringPort:Qa,InputByteVectorPort:eo,OutputByteVectorPort:to,InputBinaryFilePort:no,OutputBinaryFilePort:io,set_fs:Fo,Formatter:Fi,Parser:hi,Lexer:i,specials:ri,repr:Wi,nil:Y,eof:oo,LSymbol:$,LNumber:j,LFloat:g,LComplex:y,LRational:w,LBigInteger:Ka,LCharacter:h,LString:x,Parameter:Go,rationalize:Ya};W.set("lips",Ts);e.BufferedOutputPort=Wa;e.Environment=E;e.Error=fo;e.Formatter=Fi;e.InputBinaryFilePort=no;e.InputByteVectorPort=eo;e.InputFilePort=ro;e.InputPort=Ha;e.InputStringPort=Xa;e.Interpreter=co;e.LBigInteger=Ka;e.LCharacter=h;e.LComplex=y;e.LFloat=g;e.LNumber=j;e.LRational=w;e.LString=x;e.LSymbol=$;e.Lexer=i;e.Macro=K;e.OutputBinaryFilePort=io;e.OutputByteVectorPort=to;e.OutputFilePort=Za;e.OutputPort=Ga;e.OutputStringPort=Qa;e.Pair=J;e.Parameter=Go;e.Parser=hi;e.QuotedPromise=Zn;e.Syntax=Du;e.Values=_o;e.Worker=cs;e._is_directive=Ou;e.balanced=ns;e.balancedParenthesis=ns;e.balanced_parenthesis=ns;e.banner=Bs;e.bootstrap=ss;e.compile=Xo;e.date=Ps;e.env=xo;e.eof=oo;e.evaluate=A;e.exec=es;e.nil=Y;e.parse=Ns;e.quote=po;e.rationalize=Ya;e.repr=Wi;e.serialize=bs;e.serialize_bin=ks;e.set_fs=Fo;e.specials=ri;e.tokenize=Jn;e.unserialize=ws;e.unserialize_bin=Os;e.version=Is}); \ No newline at end of file diff --git a/src/lips.js b/src/lips.js index b7b0da72..7e08f6d8 100644 --- a/src/lips.js +++ b/src/lips.js @@ -1428,13 +1428,8 @@ function match_or_null(re, char) { // :: ref: https://github.com/biwascheme/biwascheme/blob/master/src/system/parser.js // ---------------------------------------------------------------------- class Parser { - constructor(arg, { env, meta = false, formatter = multiline_formatter } = {}) { - if (arg instanceof LString) { - arg = arg.toString(); - } - + constructor({ env, meta = false, formatter = multiline_formatter } = {}) { read_only(this, '_formatter', formatter, { hidden: true }); - read_only(this, '__lexer__', new Lexer(arg)); read_only(this, '__env__', env); read_only(this, '_meta', meta, { hidden: true }); @@ -1445,6 +1440,12 @@ class Parser { fold_case: false }, { hidden: true }); } + parse(arg) { + if (arg instanceof LString) { + arg = arg.toString(); + } + read_only(this, '__lexer__', new Lexer(arg)); + } resolve(name) { return this.__env__ && this.__env__.get(name, { throwError: false }); } @@ -1759,7 +1760,13 @@ async function* _parse(arg, env) { env = user_env; } } - const parser = new Parser(arg, { env }); + let parser; + if (arg instanceof Parser) { + parser = arg; + } else { + parser = new Parser({ env }); + parser.parse(arg); + } let prev; while (true) { const expr = await parser.read_object(); @@ -6888,7 +6895,8 @@ function InputPort(read) { this._with_parser = this._with_init_parser.bind(this, async () => { if (!this.char_ready()) { const line = await this._read(); - parser = new Parser(line, { env: this }); + parser = new Parser({ env: this }); + parser.parse(line); } return this.__parser__; }); @@ -7089,7 +7097,8 @@ function InputStringPort(string, env) { string = string.valueOf(); this._with_parser = this._with_init_parser.bind(this, () => { if (!this.__parser__) { - this.__parser__ = new Parser(string, { env }); + this.__parser__ = new Parser({ env }); + this.__parser__.parse(string); } return this.__parser__; }); @@ -7322,6 +7331,7 @@ function Interpreter(name, { stderr, stdin, stdout, command_line = null, ...obj if (typeof name === 'undefined') { name = 'anonymous'; } + this.__parser__ = new Parser({ env: this.__env__ }); this.__env__ = user_env.inherit(name, obj); this.__env__.set('parent.frame', doc('parent.frame', () => { return this.__env__; @@ -7342,13 +7352,13 @@ function Interpreter(name, { stderr, stdin, stdout, command_line = null, ...obj set_interaction_env(this.__env__, inter); } // ------------------------------------------------------------------------- -Interpreter.prototype.exec = function(code, options = {}) { +Interpreter.prototype.exec = async function(arg, options = {}) { let { use_dynamic = false, dynamic_env, env } = options; - typecheck('Interpreter::exec', code, ['string', 'array'], 1); + typecheck('Interpreter::exec', arg, ['string', 'array'], 1); typecheck('Interpreter::exec', use_dynamic, 'boolean', 2); // simple solution to overwrite this variable in each interpreter // before evaluation of user code @@ -7359,7 +7369,12 @@ Interpreter.prototype.exec = function(code, options = {}) { dynamic_env = env; } global_env.set('**interaction-environment**', this.__env__); - return exec(code, { env, dynamic_env, use_dynamic }); + if (Array.isArray(arg)) { + return exec(arg, { env, dynamic_env, use_dynamic }); + } else { + this.__parser__.parse(arg); + return exec(this.__parser__, { env, dynamic_env, use_dynamic }); + } }; // ------------------------------------------------------------------------- Interpreter.prototype.get = function(value) {