diff --git a/CHANGELOG.md b/CHANGELOG.md index 330e5b61..50cf9d11 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Features * add R7RS `guard` macro * add R7RS `parameterize` and `make-parameter` +* add `shuffle` function ### Bugfix * remove evaluating of async list data as first argument * fix `number->string` for binary numbers diff --git a/README.md b/README.md index 9d7fed1c..a6c56a7a 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.17.3-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) ![1.0.0 Complete](https://img.shields.io/github/milestones/progress-percent/jcubic/lips/1?label=1.0.0%20Complete) [![Build and test](https://github.com/jcubic/lips/actions/workflows/build.yaml/badge.svg?branch=devel&event=push)](https://github.com/jcubic/lips/actions/workflows/build.yaml) -[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&64e3a0efc0dc10af3385220fbdfc4752)](https://coveralls.io/github/jcubic/lips?branch=devel) +[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&915345bb7efef31d29f7c395edf02656)](https://coveralls.io/github/jcubic/lips?branch=devel) [![Join Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips) ![NPM Download Count](https://img.shields.io/npm/dm/@jcubic/lips) ![JSDelivr Download count](https://img.shields.io/jsdelivr/npm/hm/@jcubic/lips) diff --git a/dist/lips.js b/dist/lips.js index 6348839a..5d624913 100644 --- a/dist/lips.js +++ b/dist/lips.js @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Sun, 14 Jan 2024 00:09:28 +0000 + * build: Sun, 14 Jan 2024 12:42:38 +0000 */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : @@ -5838,7 +5838,7 @@ * The rationalize algorithm is by Per M.A. Bothner, Alan Bawden and Marc Feeley. * source: Kawa, C-Gambit * - * Build time: Sun, 14 Jan 2024 00:09:28 +0000 + * Build time: Sun, 14 Jan 2024 12:42:38 +0000 */ var _excluded = ["token"], _excluded2 = ["env"], @@ -8640,6 +8640,27 @@ return result; } // ---------------------------------------------------------------------- + // :: Fisher-Yates (aka Knuth) Shuffle + // :: ref: https://stackoverflow.com/a/2450976/387194 + // ---------------------------------------------------------------------- + function shuffle(array) { + var currentIndex = array.length, + randomIndex; + + // While there remain elements to shuffle. + while (currentIndex > 0) { + // Pick a remaining element. + randomIndex = Math.floor(Math.random() * currentIndex); + currentIndex--; + + // And swap it with the current element. + var _ref11 = [array[randomIndex], array[currentIndex]]; + array[currentIndex] = _ref11[0]; + array[randomIndex] = _ref11[1]; + } + return array; + } + // ---------------------------------------------------------------------- // :: Nil constructor with only once instance // ---------------------------------------------------------------------- function Nil() {} @@ -8985,10 +9006,10 @@ } // ---------------------------------------------------------------------- var str_mapping = new Map(); - [[true, '#t'], [false, '#f'], [null, 'null'], [undefined, '#']].forEach(function (_ref11) { - var _ref12 = _slicedToArray(_ref11, 2), - key = _ref12[0], - value = _ref12[1]; + [[true, '#t'], [false, '#f'], [null, 'null'], [undefined, '#']].forEach(function (_ref12) { + var _ref13 = _slicedToArray(_ref12, 2), + key = _ref13[0], + value = _ref13[1]; str_mapping.set(key, value); }); // ---------------------------------------------------------------------- @@ -9064,23 +9085,23 @@ // ---------------------------------------------------------------------- [[Error, function (e) { return e.message; - }], [Pair, function (pair, _ref13) { - var quote = _ref13.quote, - skip_cycles = _ref13.skip_cycles, - pair_args = _ref13.pair_args; + }], [Pair, function (pair, _ref14) { + var quote = _ref14.quote, + skip_cycles = _ref14.skip_cycles, + pair_args = _ref14.pair_args; // make sure that repr directly after update set the cycle ref if (!skip_cycles) { pair.markCycles(); } return pair.toString.apply(pair, [quote].concat(_toConsumableArray(pair_args))); - }], [LCharacter, function (chr, _ref14) { - var quote = _ref14.quote; + }], [LCharacter, function (chr, _ref15) { + var quote = _ref15.quote; if (quote) { return chr.toString(); } return chr.valueOf(); - }], [LString, function (str, _ref15) { - var quote = _ref15.quote; + }], [LString, function (str, _ref16) { + var quote = _ref16.quote; str = str.toString(); if (quote) { return JSON.stringify(str).replace(/\\n/g, '\n'); @@ -9088,10 +9109,10 @@ return str; }], [RegExp, function (re) { return '#' + re.toString(); - }]].forEach(function (_ref16) { - var _ref17 = _slicedToArray(_ref16, 2), - cls = _ref17[0], - fn = _ref17[1]; + }]].forEach(function (_ref17) { + var _ref18 = _slicedToArray(_ref17, 2), + cls = _ref18[0], + fn = _ref18[1]; instances.set(cls, fn); }); // ---------------------------------------------------------------------- @@ -9287,9 +9308,9 @@ // ---------------------------------------------------------------------- Pair.prototype.toString = function (quote) { - var _ref18 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - _ref18$nested = _ref18.nested, - nested = _ref18$nested === void 0 ? false : _ref18$nested; + var _ref19 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + _ref19$nested = _ref19.nested, + nested = _ref19$nested === void 0 ? false : _ref19$nested; var arr = []; if (this[__ref__]) { arr.push(this[__ref__] + '('); @@ -9523,9 +9544,9 @@ return macro; }; // ---------------------------------------------------------------------- - Macro.prototype.invoke = function (code, _ref19, macro_expand) { - var env = _ref19.env, - rest = _objectWithoutProperties(_ref19, _excluded2); + Macro.prototype.invoke = function (code, _ref20, macro_expand) { + var env = _ref20.env, + rest = _objectWithoutProperties(_ref20, _excluded2); var args = _objectSpread(_objectSpread({}, rest), {}, { macro_expand: macro_expand }); @@ -9543,7 +9564,7 @@ var recur_guard = -10000; function macro_expand(single) { return /*#__PURE__*/function () { - var _ref20 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(code, args) { + var _ref21 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(code, args) { var env, bindings, let_macros, lambda, define, is_let_macro, is_procedure, is_lambda, proc_bindings, let_binding, is_macro, expand_let_binding, _expand_let_binding, traverse, _traverse; return _regeneratorRuntime.wrap(function _callee12$(_context12) { while (1) { @@ -9814,7 +9835,7 @@ }, _callee12, this); })); return function (_x6, _x7) { - return _ref20.apply(this, arguments); + return _ref21.apply(this, arguments); }; }(); } @@ -9830,10 +9851,10 @@ Syntax.__merge_env__ = Symbol["for"]('merge'); // ---------------------------------------------------------------------- Syntax.prototype = Object.create(Macro.prototype); - Syntax.prototype.invoke = function (code, _ref21, macro_expand) { - var error = _ref21.error, - env = _ref21.env, - use_dynamic = _ref21.use_dynamic; + Syntax.prototype.invoke = function (code, _ref22, macro_expand) { + var error = _ref22.error, + env = _ref22.env, + use_dynamic = _ref22.use_dynamic; var args = { error: error, env: env, @@ -10362,8 +10383,8 @@ } /* eslint-disable complexity */ function traverse(expr) { - var _ref22 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - disabled = _ref22.disabled; + var _ref23 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + disabled = _ref23.disabled; log('traverse>> ' + toString(expr)); if (expr instanceof Pair) { // escape ellispsis from R7RS e.g. (... ...) @@ -10988,9 +11009,9 @@ // ------------------------------------------------------------------------- function parallel(name, fn) { return new Macro(name, function (code) { - var _ref23 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - use_dynamic = _ref23.use_dynamic, - error = _ref23.error; + var _ref24 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + use_dynamic = _ref24.use_dynamic, + error = _ref24.error; var env = this; var dynamic_env = this; var results = []; @@ -13226,13 +13247,13 @@ // ------------------------------------------------------------------------- function Interpreter(name) { var _this19 = this; - var _ref26 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - stderr = _ref26.stderr, - stdin = _ref26.stdin, - stdout = _ref26.stdout, - _ref26$command_line = _ref26.command_line, - command_line = _ref26$command_line === void 0 ? null : _ref26$command_line, - obj = _objectWithoutProperties(_ref26, _excluded3); + var _ref27 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + stderr = _ref27.stderr, + stdin = _ref27.stdin, + stdout = _ref27.stdout, + _ref27$command_line = _ref27.command_line, + command_line = _ref27$command_line === void 0 ? null : _ref27$command_line, + obj = _objectWithoutProperties(_ref27, _excluded3); if (typeof this !== 'undefined' && !(this instanceof Interpreter) || typeof this === 'undefined') { return new Interpreter(name, _objectSpread({ stdin: stdin, @@ -13940,10 +13961,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, _ref27) { - var dynamic_env = _ref27.dynamic_env, - use_dynamic = _ref27.use_dynamic, - error = _ref27.error; + help: doc(new Macro('help', function (code, _ref28) { + var dynamic_env = _ref28.dynamic_env, + use_dynamic = _ref28.use_dynamic, + error = _ref28.error; var symbol; if (code.car instanceof LSymbol) { symbol = code.car; @@ -13994,9 +14015,9 @@ // ------------------------------------------------------------------ 'set!': doc(new Macro('set!', function (code) { var _this22 = this; - var _ref28 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - use_dynamic = _ref28.use_dynamic, - rest = _objectWithoutProperties(_ref28, _excluded4); + var _ref29 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + use_dynamic = _ref29.use_dynamic, + rest = _objectWithoutProperties(_ref29, _excluded4); var dynamic_env = this; var env = this; var ref; @@ -14151,7 +14172,7 @@ } if (is_node()) { return new Promise( /*#__PURE__*/function () { - var _ref29 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(resolve, reject) { + var _ref30 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(resolve, reject) { var path, cmd, _args19; return _regeneratorRuntime.wrap(function _callee17$(_context17) { while (1) { @@ -14208,7 +14229,7 @@ }, _callee17); })); return function (_x13, _x14) { - return _ref29.apply(this, arguments); + return _ref30.apply(this, arguments); }; }()); } @@ -14225,13 +14246,13 @@ }, "(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."), // ------------------------------------------------------------------ 'do': doc(new Macro('do', /*#__PURE__*/function () { - var _ref30 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(code, _ref31) { + var _ref31 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(code, _ref32) { var use_dynamic, error, self, dynamic_env, scope, vars, test, body, eval_args, node, item, _loop3; return _regeneratorRuntime.wrap(function _callee19$(_context19) { while (1) { switch (_context19.prev = _context19.next) { case 0: - use_dynamic = _ref31.use_dynamic, error = _ref31.error; + use_dynamic = _ref32.use_dynamic, error = _ref32.error; self = this; dynamic_env = self; scope = self.inherit('do'); @@ -14346,13 +14367,13 @@ }, _callee19, this); })); return function (_x15, _x16) { - return _ref30.apply(this, arguments); + return _ref31.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, _ref32) { - var error = _ref32.error, - use_dynamic = _ref32.use_dynamic; + 'if': doc(new Macro('if', function (code, _ref33) { + var error = _ref33.error, + use_dynamic = _ref33.use_dynamic; var dynamic_env = this; var env = this; var eval_args = { @@ -14409,6 +14430,19 @@ return values.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(function (arg) { + typecheck('shuffle', arg, ['pair', 'nil', 'array']); + if (arg === _nil) { + return _nil; + } + if (Array.isArray(arg)) { + return shuffle(arg.slice()); + } + var arr = global_env.get('list->array')(arg); + arr = shuffle(arr); + return global_env.get('array->list')(arr); + }, "(shuffle obj)\n\n Order items in vector or list in random order."), + // ------------------------------------------------------------------ begin: doc(new Macro('begin', function (code, options) { var eval_args = _objectSpread(_objectSpread({}, options), {}, { env: this @@ -14615,9 +14649,9 @@ }, "(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 _ref33 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - use_dynamic = _ref33.use_dynamic, - error = _ref33.error; + var _ref34 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + use_dynamic = _ref34.use_dynamic, + error = _ref34.error; var self = this; var __doc__; if (code.cdr instanceof Pair && LString.isString(code.cdr.car) && code.cdr.cdr !== _nil) { @@ -14625,10 +14659,10 @@ } function lambda() { // lambda got scopes as context in apply - var _ref34 = is_context(this) ? this : { + var _ref35 = is_context(this) ? this : { dynamic_env: self }, - dynamic_env = _ref34.dynamic_env; + dynamic_env = _ref35.dynamic_env; var env = self.inherit('lambda'); dynamic_env = dynamic_env.inherit('lambda'); if (this && !is_context(this)) { @@ -14708,9 +14742,9 @@ 'macroexpand': new Macro('macroexpand', macro_expand()), 'macroexpand-1': new Macro('macroexpand-1', macro_expand(true)), // ------------------------------------------------------------------ - 'define-macro': doc(new Macro(macro, function (macro, _ref35) { - var use_dynamic = _ref35.use_dynamic, - error = _ref35.error; + 'define-macro': doc(new Macro(macro, function (macro, _ref36) { + var use_dynamic = _ref36.use_dynamic, + error = _ref36.error; if (macro.car instanceof Pair && macro.car.car instanceof LSymbol) { var name = macro.car.car.__name__; var __doc__; @@ -14799,8 +14833,8 @@ } else { validate_identifiers(macro.car); } - var syntax = new Syntax(function (code, _ref36) { - var macro_expand = _ref36.macro_expand; + var syntax = new Syntax(function (code, _ref37) { + var macro_expand = _ref37.macro_expand; var scope = env.inherit('syntax'); var dynamic_env = scope; var var_scope = this; @@ -14921,10 +14955,10 @@ cdr = fn(cdr); } if (is_promise(car) || is_promise(cdr)) { - return promise_all([car, cdr]).then(function (_ref37) { - var _ref38 = _slicedToArray(_ref37, 2), - car = _ref38[0], - cdr = _ref38[1]; + return promise_all([car, cdr]).then(function (_ref38) { + var _ref39 = _slicedToArray(_ref38, 2), + car = _ref39[0], + cdr = _ref39[1]; return new Pair(car, cdr); }); } else { @@ -15526,10 +15560,10 @@ return false; }, "(string->number number [radix])\n\n Function that parses a string into a number."), // ------------------------------------------------------------------ - 'try': doc(new Macro('try', function (code, _ref39) { + 'try': doc(new Macro('try', function (code, _ref40) { var _this24 = this; - var use_dynamic = _ref39.use_dynamic, - error = _ref39.error; + var use_dynamic = _ref40.use_dynamic, + error = _ref40.error; return new Promise(function (resolve, reject) { var catch_clause, finally_clause; if (LSymbol.is(code.cdr.car.car, 'catch')) { @@ -15974,9 +16008,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, _ref40) { - var use_dynamic = _ref40.use_dynamic, - error = _ref40.error; + or: doc(new Macro('or', function (code, _ref41) { + var use_dynamic = _ref41.use_dynamic, + error = _ref41.error; var args = global_env.get('list->array')(code); var self = this; var dynamic_env = self; @@ -16013,9 +16047,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 _ref41 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - use_dynamic = _ref41.use_dynamic, - error = _ref41.error; + var _ref42 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + use_dynamic = _ref42.use_dynamic, + error = _ref42.error; var args = global_env.get('list->array')(code); var self = this; var dynamic_env = self; @@ -16497,9 +16531,9 @@ } } // ------------------------------------------------------------------------- - function evaluate_args(rest, _ref42) { - var use_dynamic = _ref42.use_dynamic, - options = _objectWithoutProperties(_ref42, _excluded5); + function evaluate_args(rest, _ref43) { + var use_dynamic = _ref43.use_dynamic, + options = _objectWithoutProperties(_ref43, _excluded5); var args = []; var node = rest; markCycles(node); @@ -16603,10 +16637,10 @@ return args; } function call_function(fn, args) { - var _ref43 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, - env = _ref43.env, - dynamic_env = _ref43.dynamic_env, - use_dynamic = _ref43.use_dynamic; + var _ref44 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + env = _ref44.env, + dynamic_env = _ref44.dynamic_env, + use_dynamic = _ref44.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({ @@ -16619,12 +16653,12 @@ // ------------------------------------------------------------------------- function apply(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, - _ref44$error = _ref44.error, - error = _ref44$error === void 0 ? function () {} : _ref44$error; + 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; args = evaluate_args(args, { env: env, dynamic_env: dynamic_env, @@ -16781,13 +16815,13 @@ var noop = function noop() {}; // ------------------------------------------------------------------------- function _evaluate(code) { - var _ref45 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - env = _ref45.env, - dynamic_env = _ref45.dynamic_env, - use_dynamic = _ref45.use_dynamic, - _ref45$error = _ref45.error, - error = _ref45$error === void 0 ? noop : _ref45$error, - rest = _objectWithoutProperties(_ref45, _excluded6); + 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); return function (rest) { try { if (!is_env(dynamic_env)) { @@ -16895,7 +16929,7 @@ function exec_collect(collect_callback) { return /*#__PURE__*/function () { var _exec_lambda = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21(arg) { - var _ref46, + var _ref47, env, dynamic_env, use_dynamic, @@ -16913,7 +16947,7 @@ while (1) { switch (_context21.prev = _context21.next) { case 0: - _ref46 = _args24.length > 1 && _args24[1] !== undefined ? _args24[1] : {}, env = _ref46.env, dynamic_env = _ref46.dynamic_env, use_dynamic = _ref46.use_dynamic; + _ref47 = _args24.length > 1 && _args24[1] !== undefined ? _args24[1] : {}, env = _ref47.env, dynamic_env = _ref47.dynamic_env, use_dynamic = _ref47.use_dynamic; if (!is_env(dynamic_env)) { dynamic_env = env === true ? user_env : env || user_env; } @@ -17218,9 +17252,9 @@ this.rpc('init', [url])["catch"](function (error) { console.error(error); }); - this.exec = function (code, _ref47) { - var _ref47$use_dynamic = _ref47.use_dynamic, - use_dynamic = _ref47$use_dynamic === void 0 ? false : _ref47$use_dynamic; + this.exec = function (code, _ref48) { + var _ref48$use_dynamic = _ref48.use_dynamic, + use_dynamic = _ref48$use_dynamic === void 0 ? false : _ref48$use_dynamic; return this.rpc('eval', [code, use_dynamic]); }; } @@ -17229,10 +17263,10 @@ // :: Serialization // ------------------------------------------------------------------------- var serialization_map = { - 'pair': function pair(_ref48) { - var _ref49 = _slicedToArray(_ref48, 2), - car = _ref49[0], - cdr = _ref49[1]; + 'pair': function pair(_ref49) { + var _ref50 = _slicedToArray(_ref49, 2), + car = _ref50[0], + cdr = _ref50[1]; return Pair(car, cdr); }, 'number': function number(value) { @@ -17241,10 +17275,10 @@ } return LNumber(value); }, - 'regex': function regex(_ref50) { - var _ref51 = _slicedToArray(_ref50, 2), - pattern = _ref51[0], - flag = _ref51[1]; + 'regex': function regex(_ref51) { + var _ref52 = _slicedToArray(_ref51, 2), + pattern = _ref52[0], + flag = _ref52[1]; return new RegExp(pattern, flag); }, 'nil': function nil() { @@ -17534,10 +17568,10 @@ // ------------------------------------------------------------------------- var banner = function () { // Rollup tree-shaking is removing the variable if it's normal string because - // obviously 'Sun, 14 Jan 2024 00:09:28 +0000' == '{{' + 'DATE}}'; can be removed + // obviously 'Sun, 14 Jan 2024 12:42:38 +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('Sun, 14 Jan 2024 00:09:28 +0000').valueOf(); + var date = LString('Sun, 14 Jan 2024 12:42:38 +0000').valueOf(); var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date); var _format = function _format(x) { return x.toString().padStart(2, '0'); @@ -17578,7 +17612,7 @@ var lips = { version: 'DEV', banner: banner, - date: 'Sun, 14 Jan 2024 00:09:28 +0000', + date: 'Sun, 14 Jan 2024 12:42:38 +0000', exec: exec, // unwrap async generator into Promise parse: compose(uniterate_async, parse), diff --git a/dist/lips.min.js b/dist/lips.min.js index 084607fb..73f130f2 100644 --- a/dist/lips.min.js +++ b/dist/lips.min.js @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Sun, 14 Jan 2024 00:09:28 +0000 + * build: Sun, 14 Jan 2024 12:42:38 +0000 */ (function(e,t){typeof exports==="object"&&typeof module!=="undefined"?module.exports=t():typeof define==="function"&&define.amd?define(t):(e=typeof globalThis!=="undefined"?globalThis:e||self,e.lips=t())})(this,function(){"use strict";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 t(e,t){var r=i(e,t,"get");return n(e,r)}function u(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 a(e,t,r){var n=i(e,t,"set");u(e,n,r);return r}function o(e){if(e===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return e}function s(e,t){s=Object.setPrototypeOf||function e(t,r){t.__proto__=r;return t};return s(e,t)}function f(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true}catch(e){return false}}function p(e,t,r){if(f()){p=Reflect.construct}else{p=function e(t,r,n){var i=[null];i.push.apply(i,r);var u=Function.bind.apply(t,i);var a=new u;if(n)s(a,n.prototype);return a}}return p.apply(null,arguments)}function _(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)s(e,t)}function d(e){"@babel/helpers - typeof";return d="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},d(e)}function m(e,t){if(t&&(d(t)==="object"||typeof t==="function")){return t}else if(t!==void 0){throw new TypeError("Derived constructors may only return object or undefined")}return o(e)}function g(e){g=Object.setPrototypeOf?Object.getPrototypeOf:function e(t){return t.__proto__||Object.getPrototypeOf(t)};return g(e)}function r(e){if(Array.isArray(e))return e}function b(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function w(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 R(e,t){if(e==null)return{};var r=N(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 T(e,t){var r=e==null?null:typeof Symbol!=="undefined"&&e[Symbol.iterator]||e["@@iterator"];if(r==null)return;var n=[];var i=true;var u=false;var a,o;try{for(r=r.call(e);!(i=(a=r.next()).done);i=true){n.push(a.value);if(t&&n.length===t)break}}catch(e){u=true;o=e}finally{try{if(!i&&r["return"]!=null)r["return"]()}finally{if(u)throw o}}return n}function Y(e,t){return r(e)||T(e,t)||D(e,t)||E()}function V(e){this.wrapped=e}function z(e){return new V(e)}function $(u){var a,o;function e(n,i){return new Promise(function(e,t){var r={key:n,arg:i,resolve:e,reject:t,next:null};if(o){o=o.next=r}else{a=o=r;s(n,i)}})}function s(t,e){try{var r=u[t](e);var n=r.value;var i=n instanceof V;Promise.resolve(i?n.wrapped:n).then(function(e){if(i){s(t==="return"?"return":"next",e);return}c(r.done?"return":"normal",e)},function(e){s("throw",e)})}catch(e){c("throw",e)}}function c(e,t){switch(e){case"return":a.resolve({value:t,done:true});break;case"throw":a.reject(t);break;default:a.resolve({value:t,done:false});break}a=a.next;if(a){s(a.key,a.arg)}else{o=null}}this._invoke=e;if(typeof u["return"]!=="function"){this["return"]=undefined}}$.prototype[typeof Symbol==="function"&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this};$.prototype.next=function(e){return this._invoke("next",e)};$.prototype["throw"]=function(e){return this._invoke("throw",e)};$.prototype["return"]=function(e){return this._invoke("return",e)};function e(e){return function(){return new $(e.apply(this,arguments))}}function J(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e["default"]:e}var K={exports:{}};var G={exports:{}};(function(e){var t=function(a){var e=Object.prototype;var f=e.hasOwnProperty;var s;var o=typeof Symbol==="function"?Symbol:{};var i=o.iterator||"@@iterator";var c=o.asyncIterator||"@@asyncIterator";var p=o.toStringTag||"@@toStringTag";function r(e,t,r){Object.defineProperty(e,t,{value:r,enumerable:true,configurable:true,writable:true});return e[t]}try{r({},"")}catch(e){r=function(e,t,r){return e[t]=r}}function _(e,t,r,n){var i=t&&t.prototype instanceof g?t:g;var u=Object.create(i.prototype);var a=new O(n||[]);u._invoke=x(e,r,a);return u}a.wrap=_;function d(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}var v="suspendedStart";var y="suspendedYield";var m="executing";var l="completed";var h={};function g(){}function n(){}function t(){}var b={};r(b,i,function(){return this});var w=Object.getPrototypeOf;var D=w&&w(w(S([])));if(D&&D!==e&&f.call(D,i)){b=D}var u=t.prototype=g.prototype=Object.create(b);n.prototype=t;r(u,"constructor",t);r(t,"constructor",n);n.displayName=r(t,p,"GeneratorFunction");function E(e){["next","throw","return"].forEach(function(t){r(e,t,function(e){return this._invoke(t,e)})})}a.isGeneratorFunction=function(e){var t=typeof e==="function"&&e.constructor;return t?t===n||(t.displayName||t.name)==="GeneratorFunction":false};a.mark=function(e){if(Object.setPrototypeOf){Object.setPrototypeOf(e,t)}else{e.__proto__=t;r(e,p,"GeneratorFunction")}e.prototype=Object.create(u);return e};a.awrap=function(e){return{__await:e}};function A(o,s){function c(e,t,r,n){var i=d(o[e],o,t);if(i.type==="throw"){n(i.arg)}else{var u=i.arg;var a=u.value;if(a&&typeof a==="object"&&f.call(a,"__await")){return s.resolve(a.__await).then(function(e){c("next",e,r,n)},function(e){c("throw",e,r,n)})}return s.resolve(a).then(function(e){u.value=e;r(u)},function(e){return c("throw",e,r,n)})}}var t;function e(r,n){function e(){return new s(function(e,t){c(r,n,e,t)})}return t=t?t.then(e,e):e()}this._invoke=e}E(A.prototype);r(A.prototype,c,function(){return this});a.AsyncIterator=A;a.async=function(e,t,r,n,i){if(i===void 0)i=Promise;var u=new A(_(e,t,r,n),i);return a.isGeneratorFunction(t)?u:u.next().then(function(e){return e.done?e.value:u.next()})};function x(a,o,s){var c=v;return function e(t,r){if(c===m){throw new Error("Generator is already running")}if(c===l){if(t==="throw"){throw r}return B()}s.method=t;s.arg=r;while(true){var n=s.delegate;if(n){var i=F(n,s);if(i){if(i===h)continue;return i}}if(s.method==="next"){s.sent=s._sent=s.arg}else if(s.method==="throw"){if(c===v){c=l;throw s.arg}s.dispatchException(s.arg)}else if(s.method==="return"){s.abrupt("return",s.arg)}c=m;var u=d(a,o,s);if(u.type==="normal"){c=s.done?l:y;if(u.arg===h){continue}return{value:u.arg,done:s.done}}else if(u.type==="throw"){c=l;s.method="throw";s.arg=u.arg}}}}function F(e,t){var r=e.iterator[t.method];if(r===s){t.delegate=null;if(t.method==="throw"){if(e.iterator["return"]){t.method="return";t.arg=s;F(e,t);if(t.method==="throw"){return h}}t.method="throw";t.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var n=d(r,e.iterator,t.arg);if(n.type==="throw"){t.method="throw";t.arg=n.arg;t.delegate=null;return h}var i=n.arg;if(!i){t.method="throw";t.arg=new TypeError("iterator result is not an object");t.delegate=null;return h}if(i.done){t[e.resultName]=i.value;t.next=e.nextLoc;if(t.method!=="return"){t.method="next";t.arg=s}}else{return i}t.delegate=null;return h}E(u);r(u,p,"Generator");r(u,i,function(){return this});r(u,"toString",function(){return"[object Generator]"});function k(e){var t={tryLoc:e[0]};if(1 in e){t.catchLoc=e[1]}if(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 O(e){this.tryEntries=[{tryLoc:"root"}];e.forEach(k,this);this.reset(true)}a.keys=function(r){var n=[];for(var e in r){n.push(e)}n.reverse();return function e(){while(n.length){var t=n.pop();if(t in r){e.value=t;e.done=false;return e}}e.done=true;return e}};function S(t){if(t){var e=t[i];if(e){return e.call(t)}if(typeof t.next==="function"){return t}if(!isNaN(t.length)){var r=-1,n=function e(){while(++r=0;--t){var i=this.tryEntries[t];var u=i.completion;if(i.tryLoc==="root"){return e("end")}if(i.tryLoc<=this.prev){var a=f.call(i,"catchLoc");var o=f.call(i,"finallyLoc");if(a&&o){if(this.prev=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&f.call(n,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e){this.complete(r.completion,r.afterLoc);C(r);return h}}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if(n.type==="throw"){var i=n.arg;C(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){this.delegate={iterator:S(e),resultName:t,nextLoc:r};if(this.method==="next"){this.arg=s}return h}};return a}(e.exports);try{regeneratorRuntime=t}catch(e){if(typeof globalThis==="object"){globalThis.regeneratorRuntime=t}else{Function("r","regeneratorRuntime = r")(t)}}})(G);(function(e){e.exports=G.exports})(K);var H=J(K.exports);var W=typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{};var Q=[];var Z=[];var X=typeof Uint8Array!=="undefined"?Uint8Array:Array;var ee=false;function te(){ee=true;var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var t=0,r=e.length;t0){throw new Error("Invalid string. Length must be a multiple of 4")}u=e[o-2]==="="?2:e[o-1]==="="?1:0;a=new X(o*3/4-u);n=u>0?o-4:o;var s=0;for(t=0,r=0;t>16&255;a[s++]=i>>8&255;a[s++]=i&255}if(u===2){i=Z[e.charCodeAt(t)]<<2|Z[e.charCodeAt(t+1)]>>4;a[s++]=i&255}else if(u===1){i=Z[e.charCodeAt(t)]<<10|Z[e.charCodeAt(t+1)]<<4|Z[e.charCodeAt(t+2)]>>2;a[s++]=i>>8&255;a[s++]=i&255}return a}function ne(e){return Q[e>>18&63]+Q[e>>12&63]+Q[e>>6&63]+Q[e&63]}function ie(e,t,r){var n;var i=[];for(var u=t;us?s:o+a))}if(n===1){t=e[r-1];i+=Q[t>>2];i+=Q[t<<4&63];i+="=="}else if(n===2){t=(e[r-2]<<8)+e[r-1];i+=Q[t>>10];i+=Q[t>>4&63];i+=Q[t<<2&63];i+="="}u.push(i);return u.join("")}function ae(e,t,r,n,f){var i,u;var l=f*8-n-1;var h=(1<>1;var a=-7;var o=r?f-1:0;var s=r?-1:1;var c=e[t+o];o+=s;i=c&(1<<-a)-1;c>>=-a;a+=l;for(;a>0;i=i*256+e[t+o],o+=s,a-=8){}u=i&(1<<-a)-1;i>>=-a;a+=n;for(;a>0;u=u*256+e[t+o],o+=s,a-=8){}if(i===0){i=1-p}else if(i===h){return u?NaN:(c?-1:1)*Infinity}else{u=u+Math.pow(2,n);i=i-p}return(c?-1:1)*u*Math.pow(2,i-n)}function oe(e,t,f,l,r,h){var n,i,u;var a=h*8-r-1;var o=(1<>1;var p=r===23?Math.pow(2,-24)-Math.pow(2,-77):0;var c=l?0:h-1;var _=l?1:-1;var d=t<0||t===0&&1/t<0?1:0;t=Math.abs(t);if(isNaN(t)||t===Infinity){i=isNaN(t)?1:0;n=o}else{n=Math.floor(Math.log(t)/Math.LN2);if(t*(u=Math.pow(2,-n))<1){n--;u*=2}if(n+s>=1){t+=p/u}else{t+=p*Math.pow(2,1-s)}if(t*u>=2){n++;u/=2}if(n+s>=o){i=0;n=o}else if(n+s>=1){i=(t*u-1)*Math.pow(2,r);n=n+s}else{i=t*Math.pow(2,s-1)*Math.pow(2,r);n=0}}for(;r>=8;e[f+c]=i&255,c+=_,i/=256,r-=8){}n=n<0;e[f+c]=n&255,c+=_,n/=256,a-=8){}e[f+c-_]|=d*128}var se={}.toString;var ce=Array.isArray||function(e){return se.call(e)=="[object Array]"}; /*! @@ -83,5 +83,5 @@ * The rationalize algorithm is by Per M.A. Bothner, Alan Bawden and Marc Feeley. * source: Kawa, C-Gambit * - * Build time: Sun, 14 Jan 2024 00:09:28 +0000 - */var hn=["token"],pn=["env"],_n=["stderr","stdin","stdout","command_line"],dn=["use_dynamic"],vn=["use_dynamic"],yn=["env","dynamic_env","use_dynamic","error"];function mn(e,t,r){gn(e,t);t.set(e,r)}function gn(e,t){if(t.has(e)){throw new TypeError("Cannot initialize the same private elements twice on an object")}}function bn(i){var u=wn();return function e(){var t=g(i),r;if(u){var n=g(this).constructor;r=Reflect.construct(t,arguments,n)}else{r=t.apply(this,arguments)}return m(this,r)}}function wn(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true}catch(e){return false}}function Dn(t,e){var r=typeof Symbol!=="undefined"&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=En(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 En(e,t){if(!e)return;if(typeof e==="string")return An(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 An(e,t)}function An(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r1&&arguments[1]!==undefined?arguments[1]:null;var n=arguments[1]===true;function t(e){if(!Ln()){return}var t=ns.get("repr")(e);if(r===null||r instanceof RegExp&&r.test(t)){console.log(ns.get("type")(e)+": "+t)}if(n){console.log(e)}}if(ma(e)){e.then(t)}else{t(e)}return e}function Ln(){return is&&is.get("DEBUG",{throwError:false})}function Un(e){return e?"(?:#".concat(e,"(?:#[ie])?|#[ie]#").concat(e,")"):"(?:#[ie])?"}function Mn(e,t){return"".concat(Un(e),"[+-]?").concat(t,"+/").concat(t,"+")}function qn(e,t){return"".concat(Un(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 Yn(e,t){return"".concat(Un(e),"[+-]?").concat(t,"+")}var Vn=/^#\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimyus]*)$/;var zn="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)";var $n="(?:#[ie])?(?:[+-]?(?:[0-9]+/[0-9]+|nan.0|inf.0|".concat(zn,"|[+-]?[0-9]+))?(?:").concat(zn,"|[+-](?:[0-9]+/[0-9]+|[0-9]+|nan.0|inf.0))i");var Jn=new RegExp("^(#[ie])?".concat(zn,"$"),"i");function Kn(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 Gn=function(){var u={};[[10,"","[0-9]"],[16,"x","[0-9a-fA-F]"],[8,"o","[0-7]"],[2,"b","[01]"]].forEach(function(e){var t=Y(e,3),r=t[0],n=t[1],i=t[2];u[r]=Kn(n,i)});return u}();var Hn={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 Wn(e){var t=[];var r=0;var n=e.length;while(r=55296&&i<=56319&&r1&&arguments[1]!==undefined?arguments[1]:10;var r=fi(e);var n=r.number.split("/");var i=ko({num:y([n[0],r.radix||t]),denom:y([n[1],r.radix||t])});if(r.inexact){return i.valueOf()}else{return i}}function hi(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;var r=fi(e);if(r.inexact){return Do(parseInt(r.number,r.radix||t))}return y([r.number,r.radix||t])}function pi(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(/#\\(.+)$/);if(t){r=t[1]}}if(r){return ao(r)}throw new Error("Parse: invalid character")}function _i(e){var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;function t(e){var t;if(e==="+"){t=y(1)}else if(e==="-"){t=y(-1)}else if(e.match(ui)){t=y([e,i])}else if(e.match(ai)){var r=e.split("/");t=ko({num:y([r[0],i]),denom:y([r[1],i])})}else if(e.match(Jn)){var n=yi(e);if(u.exact){return n.toRational()}return n}else if(e.match(/nan.0$/)){return y(NaN)}else if(e.match(/inf.0$/)){if(e[0]==="-"){return y(Number.NEGATIVE_INFINITY)}return y(Number.POSITIVE_INFINITY)}else{throw new Error("Internal Parser Error")}if(u.inexact){return Do(t.valueOf())}return t}var u=fi(e);i=u.radix||i;var r;var n=u.number.match(si);if(i!==10&&n){r=n}else{r=u.number.match(Gn[i])}var a,o;o=t(r[2]);if(r[1]){a=t(r[1])}else{a=y(0)}if(o.cmp(0)===0&&o.__type__==="bigint"){return a}return wo({im:o,re:a})}function di(e){return parseInt(e.toString(),10)===e}function vi(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){return y(u).mul(o)}}}r=Do(r);if(t.exact){return r.toRational()}return r}function mi(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{return oo(JSON.parse(e))}catch(e){var r=e.message.replace(/in JSON /,"").replace(/.*Error: /,"");throw new Error("Invalid string literal: ".concat(r))}}function gi(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 L(e)}function bi(e){if(rs.hasOwnProperty(e)){return rs[e]}if(e.match(/^"[\s\S]*"$/)){return mi(e)}else if(e[0]==="#"){var t=e.match(Vn);if(t){return new RegExp(t[1],t[2])}else if(e.match(Xn)){return pi(e)}var r=e.match(/#\\(.+)/);if(r&&Wn(r[1]).length===1){return pi(e)}}if(e.match(/[0-9a-f]|[+-]i/i)){if(e.match(ii)){return hi(e)}else if(e.match(Jn)){return yi(e)}else if(e.match(ni)){return li(e)}else if(e.match(ri)){return _i(e)}}if(e.match(/^#[iexobd]/)){throw new Error("Invalid numeric constant: "+e)}return gi(e)}function wi(e){return!(["(",")","[","]"].includes(e)||qi.names().includes(e))}function Di(e){return wi(e)&&!(e.match(Vn)||e.match(/^"[\s\S]*"$/)||e.match(ii)||e.match(Jn)||e.match(ri)||e.match(ni)||e.match(Xn)||["#t","#f","nil","true","false"].includes(e))}var Ei=/"(?:\\[\S\s]|[^"])*"?/g;function Ai(e){if(typeof e==="string"){var t=/([-\\^$[\]()+{}?*.|])/g;return e.replace(t,"\\$1")}return e}function xi(){this.data=[]}xi.prototype.push=function(e){this.data.push(e)};xi.prototype.top=function(){return this.data[this.data.length-1]};xi.prototype.pop=function(){return this.data.pop()};xi.prototype.is_empty=function(){return!this.data.length};function Fi(e){if(e instanceof oo){e=e.valueOf()}var t=new Gi(e,{whitespace:true});var r=[];while(true){var n=t.peek(true);if(n===Yo){break}r.push(n);t.skip()}return r}function ki(e){var t=e.token,r=R(e,hn);if(t.match(/^"[\s\S]*"$/)&&t.match(/\n/)){var n=new RegExp("^ {1,"+(e.col+1)+"}","mg");t=t.replace(n,"")}return Fn({token:t},r)}function Ci(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(){};this.fn=e;this.cont=t}Ci.prototype.toString=function(){return"#"};function Oi(n){return function(){for(var e=arguments.length,t=new Array(e),r=0;r1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof oo){e=e.toString()}if(t){return Fi(e)}else{var r=Fi(e).map(function(e){if(e.token==="#\\ "){return e.token}return e.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return ji(r)}}function ji(e){var t=0;var r=null;var n=[];for(var i=0;i0&&arguments[0]!==undefined?arguments[0]:null;if(e instanceof L){if(e.is_gensym()){return e}e=e.valueOf()}if(Ni(e)){return L(e)}if(e!==null){return r(e,Symbol("#:".concat(e)))}t++;return r(t,Symbol("#:g".concat(t)))}}();function Ti(e){var r=this;var n={pending:true,rejected:false,fulfilled:false,reason:undefined,type:undefined};e=e.then(function(e){n.type=ws(e);n.fulfilled=true;n.pending=false;return e});nu(this,"_promise",e,{hidden:true});if(la(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]}})});nu(this,"__promise__",e);this.then=false}Ti.prototype.then=function(e){return new Ti(this.valueOf().then(e))};Ti.prototype["catch"]=function(e){return new Ti(this.valueOf()["catch"](e))};Ti.prototype.valueOf=function(){if(!this._promise){throw new Error("QuotedPromise: invalid promise created")}return this._promise};Ti.prototype.toString=function(){if(this.__pending__){return Ti.pending_str}if(this.__rejected__){return Ti.rejected_str}return"#")};Ti.pending_str="#";Ti.rejected_str="#";function Li(e){if(Array.isArray(e)){return Promise.all(Ui(e)).then(Mi)}return e}function Ui(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof Ti){t[r]=new Ko(n)}else{t[r]=n}}return t}function Mi(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof Ko){t[r]=n.valueOf()}else{t[r]=n}}return t}var qi={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 L("quote-promise"),qi.LITERAL]];var Ki=Ji.map(function(e){return e[0]});Object.freeze(Ki);Object.defineProperty(qi,"__builtins__",{writable:false,value:Ki});Ji.forEach(function(e){var t=Y(e,3),r=t[0],n=t[1],i=t[2];qi.append(r,n,i)});var Gi=function(){function p(e){var t=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=r.whitespace,i=n===void 0?false:n;j(this,p);nu(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=""}P(p,[{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 Yo}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 Yo}},{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 Yo}for(var r=this._i;r=r){return Yo}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 Yo}return ao(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]:{},r=t.prev_char,n=t["char"],i=t.next_char;var u=Y(e,4),a=u[0],o=u[1],s=u[2],f=u[3];if(e.length!==5){throw new Error("Lexer: Invalid rule of length ".concat(e.length))}if(!n.match(a)){return false}if(!Hi(o,r)){return false}if(!Hi(s,i)){return false}if(f!==this._state){return false}return true}},{key:"next_token",value:function f(){if(this._i>=this.__input__.length){return false}var e=true;e:for(var t=this._i,r=this.__input__.length;t2&&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?ki:u;j(this,o);if(e instanceof oo){e=e.toString()}nu(this,"_formatter",a,{hidden:true});nu(this,"__lexer__",new Gi(e));nu(this,"__env__",r);nu(this,"_meta",i,{hidden:true});nu(this,"_refs",[],{hidden:true});nu(this,"_state",{parentheses:0},{hidden:true})}P(o,[{key:"resolve",value:function e(t){return this.__env__&&this.__env__.get(t,{throwError:false})}},{key:"peek",value:function(){var e=B(H.mark(function e(){var r;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:r=this.__lexer__.peek(true);if(!(r===Yo)){t.next=4;break}return t.abrupt("return",Yo);case 4:if(!this.is_comment(r.token)){t.next=7;break}this.skip();return t.abrupt("continue",0);case 7:if(!(r.token==="#;")){t.next=14;break}this.skip();if(!(this.__lexer__.peek()===Yo)){t.next=11;break}throw new Error("Lexer: syntax error eof found after comment");case 11:t.next=13;return this._read_object();case 13:return t.abrupt("continue",0);case 14:return t.abrupt("break",17);case 17:r=this._formatter(r);if(!this._meta){t.next=20;break}return t.abrupt("return",r);case 20:return t.abrupt("return",r.token);case 21: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=B(H.mark(function e(){var r;return H.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=B(H.mark(function e(){var r,n,i,u;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:r=U,n=r;case 1:t.next=4;return this.peek();case 4:i=t.sent;if(!(i===Yo)){t.next=7;break}return t.abrupt("break",27);case 7:if(!this.is_close(i)){t.next=10;break}this.skip();return t.abrupt("break",27);case 10:if(!(i==="."&&r!==U)){t.next=17;break}this.skip();t.next=14;return this._read_object();case 14:n.cdr=t.sent;t.next=25;break;case 17:t.t0=M;t.next=20;return this._read_object();case 20:t.t1=t.sent;t.t2=U;u=new t.t0(t.t1,t.t2);if(r===U){r=u}else{n.cdr=u}n=u;case 25:t.next=1;break;case 27:return t.abrupt("return",r);case 28:case"end":return t.stop()}}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"read_value",value:function(){var e=B(H.mark(function e(){var r;return H.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===Yo)){t.next=5;break}throw new Error("Parser: Expected token eof found");case 5:return t.abrupt("return",bi(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 Ns(t,{env:this.__env__,error:function e(t){throw t}})}},{key:"read_object",value:function(){var e=B(H.mark(function e(){var r;return H.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 Qi){r=r.valueOf()}if(!this._refs.length){t.next=7;break}return t.abrupt("return",this._resolve_object(r));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){var r=this._state.parentheses;var n=new Error("Parser: expected parenthesis but eof found");var i=new RegExp("\\){".concat(r,"}$"));n.__code__=[t.toString().replace(i,"")];throw n}},{key:"_resolve_object",value:function(){var t=B(H.mark(function e(r){var n=this;var i;return H.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(!Iu(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(!(r instanceof M)){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=B(H.mark(function e(r){return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(!(r instanceof M)){t.next=15;break}if(!(r.car instanceof Qi)){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 Qi)){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=B(H.mark(function e(){var r,n,h,i,u,a,o,s,c,f,l;return H.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===Yo)){t.next=5;break}return t.abrupt("return",r);case 5:if(!Yi(r)){t.next=38;break}n=qi.get(r);h=Vi(r);this.skip();u=$i(r);if(!u){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:a=t.t0;if(h){t.next=25;break}o=this.__env__.get(n.symbol);if(!(typeof o==="function")){t.next=25;break}if(zi(r)){s=[a]}else if(a===U){s=[]}else if(a instanceof M){s=a.to_array(false)}if(!(s||u)){t.next=24;break}return t.abrupt("return",ks(o,u?[]:s,{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(zi(r)){i=new M(n.symbol,new M(a,U))}else{i=new M(n.symbol,a)}if(!h){t.next=28;break}return t.abrupt("return",i);case 28:if(!(o instanceof ta)){t.next=37;break}t.next=31;return this.evaluate(i);case 31:c=t.sent;if(!(c instanceof M||c instanceof L)){t.next=34;break}return t.abrupt("return",M.fromArray([L("quote"),c]));case 34:return t.abrupt("return",c);case 37:throw new Error("Parse Error: invalid parser extension: "+n.symbol);case 38:f=this.match_datum_ref(r);if(!(f!==null)){t.next=44;break}this.skip();if(!this._refs[f]){t.next=43;break}return t.abrupt("return",new Qi(f,this._refs[f]));case 43:throw new Error("Parse Error: invalid datum label #".concat(f,"#"));case 44:l=this.match_datum_label(r);if(!(l!==null)){t.next=51;break}this.skip();this._refs[l]=this._read_object();return t.abrupt("return",this._refs[l]);case 51:if(!this.is_open(r)){t.next=56;break}this.skip();return t.abrupt("return",this.read_list());case 56:return t.abrupt("return",this.read_value());case 57:case"end":return t.stop()}}},e,this)}));function t(){return e.apply(this,arguments)}return t}()}]);return o}();var Qi=function(){function r(e,t){j(this,r);this.name=e;this.data=t}P(r,[{key:"valueOf",value:function e(){return this.data}}]);return r}();function Zi(e,t){return Xi.apply(this,arguments)}function Xi(){Xi=e(H.mark(function e(r,n){var i,u;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(!n){if(ns){n=ns.get("**interaction-environment**",{throwError:false})}else{n=is}}i=new Wi(r,{env:n});case 3:t.next=6;return z(i.read_object());case 6:u=t.sent;if(!i.balanced()){i.ballancing_error(u)}if(!(u===Yo)){t.next=10;break}return t.abrupt("break",14);case 10:t.next=12;return u;case 12:t.next=3;break;case 14:case"end":return t.stop()}}},e)}));return Xi.apply(this,arguments)}function eu(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(ma(e)){var n=e.then(t);if(r===null){return n}else{return n["catch"](r)}}if(e instanceof Array){return tu(e,t,r)}if(Iu(e)){return ru(e,t,r)}return t(e)}function tu(t,r,e){if(t.find(ma)){return eu(Li(t),function(e){if(Object.isFrozen(t)){Object.freeze(e)}return r(e)},e)}return r(t)}function ru(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(ma(s)){u.push(s)}}if(u.length){return eu(Li(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 nu(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 iu(e){return uu.apply(this,arguments)}function uu(){uu=B(H.mark(function e(r){var n,i,u,a,o,s,c;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:n=[];i=false;u=false;t.prev=3;o=kn(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 uu.apply(this,arguments)}function au(e,t){if(t instanceof RegExp){return function(e){return String(e).match(t)}}else if(la(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__=ou(r)}}if(e){t.__name__=e}else if(t.name&&!za(t)){t.__name__=t.name}return t}function ou(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function su(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 cu(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 fu(e,t){return f(e,t)===t.length;function f(r,n){function e(e,t){var r=Dn(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")&&!Di(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 lu(e){this.__code__=e.replace(/\r/g,"")}lu.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|\*)?)$/],shift:{1:["&","#"]}}};lu.match=fu;lu.prototype._options=function e(t){var r=lu.defaults;if(typeof t==="undefined"){return Object.assign({},r)}var n=t&&t.exceptions||{};var i=n.specials||[];var u=n.shift||{1:[]};return Fn(Fn(Fn({},r),t),{},{exceptions:{specials:[].concat(C(r.exceptions.specials),C(i)),shift:Fn(Fn({},u),{},{1:[].concat(C(r.exceptions.shift[1]),C(u[1]))})}})};lu.prototype.indent=function e(t){var r=Bi(this.__code__,true);return this._indent(r,t)};lu.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=Dn(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){t.offset=0}if(n.toString()===e.toString()&&Us(n)){return t.offset+n[0].col}else if(n.length===1){return t.offset+n[0].col+1}else{var u=-1;if(i){var a=lu.exception_shift(i.token,t);if(a!==-1){u=a}}if(u===-1){u=lu.exception_shift(n[1].token,t)}if(u!==-1){return t.offset+n[0].col+u}else if(n[0].line3&&n[1].line===n[3].line){if(n[1].token==="("||n[1].token==="["){return t.offset+n[1].col}return t.offset+n[3].col}else if(n[0].line===n[1].line){return t.offset+t.indent+n[0].col}else{var o=n.slice(2);for(var s=0;s")};hu.prototype.match=function(e){return e.match(this.pattern)};function pu(){for(var e=arguments.length,t=new Array(e),r=0;r")};lu.Pattern=pu;lu.Ahead=hu;var _u=/^[[(]$/;var du=/^[\])]$/;var vu=/[^()[\]]/;var yu=new hu(/[^)\]]/);var mu=Symbol["for"]("*");var gu=new pu([_u,mu,du],[vu],"+");var bu=new pu([_u,mu,du],"+");var wu=new pu([Symbol["for"]("symbol")],"?");var Du=new pu([Symbol["for"]("symbol")],"*");var Eu=[_u,Du,du];var Au=new pu([_u,Symbol["for"]("symbol"),mu,du],"+");var xu=Cu("define","lambda","define-macro","syntax-rules");var Fu=/^(?!.*\b(?:[()[\]]|define(?:-macro)?|let(?:\*|rec|-env|-syntax|)?|lambda|syntax-rules)\b).*$/;var ku=/^(?:#:)?(let(?:\*|rec|-env|-syntax)?)$/;function Cu(){for(var e=arguments.length,t=new Array(e),r=0;r0&&!i[e]){i[e]=su(n,e)}});var u=Dn(t),p;try{for(u.s();!(p=u.n()).done;){var a=Y(p.value,3),_=a[0],o=a[1],s=a[2];o=o.valueOf();var d=o>0?i[o]:n;var v=d.filter(function(e){return e.trim()&&!Yi(e)});var y=h(d);var m=fu(_,v);var g=e.slice(r).find(function(e){return e.trim()&&!Yi(e)});if(m&&(s instanceof hu&&s.match(g)||!s)){var c=r-y;if(e[c]!=="\n"){if(!e[c].trim()){e[c]="\n"}else{e.splice(c,0,"\n");r++}}r+=y;continue e}}}catch(e){u.e(e)}finally{u.f()}}this.__code__=e.join("");return this};lu.prototype._spaces=function(e){return new Array(e+1).join(" ")};lu.prototype.format=function c(e){var t=this.__code__.replace(/[ \t]*\n[ \t]*/g,"\n ");var r=Bi(t,true);var n=this._options(e);var i=0;var u=0;for(var a=0;a0&&arguments[0]!==undefined?arguments[0]:true;var n=new Map;function i(e){if(e instanceof M){if(n.has(e)){return n.get(e)}var t=new M;n.set(e,t);if(r){t.car=i(e.car)}else{t.car=e.car}t.cdr=i(e.cdr);t[Na]=e[Na];return t}return e}return i(this)};M.prototype.last_pair=function(){var e=this;while(true){if(e.cdr===U){return e}e=e.cdr}};M.prototype.to_array=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var t=[];if(this.car instanceof M){if(e){t.push(this.car.to_array())}else{t.push(this.car)}}else{t.push(this.car.valueOf())}if(this.cdr instanceof M){t=t.concat(this.cdr.to_array(e))}return t};M.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(e instanceof M||r&&e instanceof Array&&e[Ia]){return e}if(t===false){var n=U;for(var i=e.length;i--;){n=new M(e[i],n)}return n}if(e.length&&!(e instanceof Array)){e=C(e)}var u=U;var a=e.length;while(a--){var o=e[a];if(o instanceof Array){o=M.fromArray(o,t,r)}else if(typeof o==="string"){o=oo(o)}else if(typeof o==="number"&&!Number.isNaN(o)){o=y(o)}u=new M(o,u)}return u};M.prototype.to_object=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var t=this;var r={};while(true){if(t instanceof M&&t.car instanceof M){var n=t.car;var i=n.car;if(i instanceof L){i=i.__name__}if(i instanceof oo){i=i.valueOf()}var u=n.cdr;if(u instanceof M){u=u.to_object(e)}if(ys(u)){if(!e){u=u.valueOf()}}r[i]=u;t=t.cdr}else{break}}return r};M.fromPairs=function(e){return e.reduce(function(e,t){return new M(new M(new L(t[0]),t[1]),e)},U)};M.fromObject=function(t){var e=Object.keys(t).map(function(e){return[e,t[e]]});return M.fromPairs(e)};M.prototype.reduce=function(e){var t=this;var r=U;while(true){if(t!==U){r=e(r,t.car);t=t.cdr}else{break}}return r};M.prototype.reverse=function(){if(this.haveCycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var t=U;while(e!==U){var r=e.cdr;e.cdr=t;t=e;e=r}return t};M.prototype.transform=function(n){function i(e){if(e instanceof M){if(e.replace){delete e.replace;return e}var t=n(e.car);if(t instanceof M){t=i(t)}var r=n(e.cdr);if(r instanceof M){r=i(r)}return new M(t,r)}return e}return i(this)};M.prototype.map=function(e){if(typeof this.car!=="undefined"){return new M(e(this.car),this.cdr===U?U:this.cdr.map(e))}else{return U}};var ju=new Map;function Iu(e){return e&&d(e)==="object"&&e.constructor===Object}var Pu=Object.getOwnPropertyNames(Array.prototype);var Nu=[];Pu.forEach(function(e){Nu.push(Array[e],Array.prototype[e])});function Ru(e){e=Aa(e);return Nu.includes(e)}function Tu(e){return la(e)&&(za(e)||e.__doc__)}function Lu(r){var e=r.constructor||Object;var n=Iu(r);var i=la(r[Symbol.asyncIterator])||la(r[Symbol.iterator]);var u;if(ju.has(e)){u=ju.get(e)}else{ju.forEach(function(e,t){t=Aa(t);if(r.constructor===t&&(t===Object&&n&&!i||t!==Object)){u=e}})}return u}var Uu=new Map;[[true,"#t"],[false,"#f"],[null,"null"],[undefined,"#"]].forEach(function(e){var t=Y(e,2),r=t[0],n=t[1];Uu.set(r,n)});function Mu(r){if(r&&d(r)==="object"){var n={};var e=Object.getOwnPropertySymbols(r);e.forEach(function(e){var t=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");n[t]=Ju(r[e])});var t=Object.getOwnPropertyNames(r);t.forEach(function(e){var t=r[e];if(t&&d(t)==="object"&&t.constructor===Object){n[e]=Mu(t)}else{n[e]=Ju(t)}});return n}return r}function qu(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function Yu(e,t){return e.hasOwnProperty(t)&&la(e.toString)}function Vu(e){if(Ka(e)){return"#"}var t=e.prototype&&e.prototype.constructor;if(la(t)&&za(t)){if(e[Ra]&&t.hasOwnProperty("__name__")){var r=t.__name__;if(oo.isString(r)){r=r.toString();return"#")}return"#"}}if(e.hasOwnProperty("__name__")){var n=e.__name__;if(d(n)==="symbol"){n=Pi(n)}if(typeof n==="string"){return"#")}}if(Yu(e,"toString")){return e.toString()}else if(e.name&&!za(e)){return"#")}else{return"#"}}var zu=new Map;[[Error,function(e){return e.message}],[M,function(e,t){var r=t.quote,n=t.skip_cycles,i=t.pair_args;if(!n){e.markCycles()}return e.toString.apply(e,[r].concat(C(i)))}],[ao,function(e,t){var r=t.quote;if(r){return e.toString()}return e.valueOf()}],[oo,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=Y(e,2),r=t[0],n=t[1];zu.set(r,n)});var $u=[L,y,ta,Go,Oo,So,Jo,Ti];function Ju(e,t,c){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(Uu.has(e)){return Uu.get(e)}if(Ku(e)){return"#"}if(e){var r=e.constructor;if(zu.has(r)){for(var n=arguments.length,f=new Array(n>3?n-3:0),i=3;i"}if(e===null){return"null"}if(d(e)==="object"){var a=e.constructor;if(!a){a=Object}var o;if(typeof a.__class__==="string"){o=a.__class__}else{var s=Lu(e);if(s){if(la(s)){return s(e,t)}else{throw new Error("toString: Invalid repr value")}}o=a.name}if(la(e.toString)&&za(e.toString)){return e.toString().valueOf()}if(ws(e)==="instance"){if(za(a)&&a.__name__){o=a.__name__.valueOf()}else if(!Ka(a)){o="instance"}}if(gs(e,Symbol.iterator)){if(o){return"#")}return"#"}if(gs(e,Symbol.asyncIterator)){if(o){return"#")}return"#"}if(o!==""){return"#<"+o+">"}return"#"}if(typeof e!=="string"){return e.toString()}return e}function Ku(e){return e&&d(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}M.prototype.markCycles=function(){Gu(this);return this};M.prototype.haveCycles=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(!e){return this.haveCycles("car")||this.haveCycles("cdr")}return!!(this[Na]&&this[Na][e])};function Gu(e){var t=[];var i=[];var u=[];function a(e){if(!t.includes(e)){t.push(e)}}function o(e,t,r,n){if(r instanceof M){if(n.includes(r)){if(!u.includes(r)){u.push(r)}if(!e[Na]){e[Na]={}}e[Na][t]=r;if(!i.includes(e)){i.push(e)}return true}}}var s=Oi(function e(t,r){if(t instanceof M){delete t.ref;delete t[Na];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 Ci(function(){return e(t.cdr,r.slice())})}}});function r(e,t){if(e[Na][t]instanceof M){var r=n.indexOf(e[Na][t]);e[Na][t]="#".concat(r,"#")}}s(e,[]);var n=t.filter(function(e){return u.includes(e)});n.forEach(function(e,t){e[Pa]="#".concat(t,"=")});i.forEach(function(e){r(e,"car");r(e,"cdr")})}M.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[Pa]){i.push(this[Pa]+"(")}else if(!n){i.push("(")}var u;if(this[Na]&&this[Na].car){u=this[Na].car}else{u=Ju(this.car,e,true)}if(u!==undefined){i.push(u)}if(this.cdr instanceof M){if(this[Na]&&this[Na].cdr){i.push(" . ");i.push(this[Na].cdr)}else{if(this.cdr[Pa]){i.push(" . ")}else{i.push(" ")}var a=this.cdr.toString(e,{nested:true});i.push(a)}}else if(this.cdr!==U){i=i.concat([" . ",Ju(this.cdr,e,true)])}if(!n||this[Pa]){i.push(")")}return i.join("")};M.prototype.set=function(e,t){this[e]=t;if(t instanceof M){this.markCycles()}};M.prototype.append=function(e){if(e instanceof Array){return this.append(M.fromArray(e))}var t=this;if(t.car===undefined){if(e instanceof M){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(e!==U){while(true){if(t instanceof M&&t.cdr!==U){t=t.cdr}else{break}}t.cdr=e}return this};M.prototype.serialize=function(){return[this.car,this.cdr]};M.prototype[Symbol.iterator]=function(){var r=this;return{next:function e(){var t=r;r=t.cdr;if(t===U){return{value:undefined,done:true}}else{return{value:t.car,done:false}}}}};function Hu(e){return e<0?-e:e}function Wu(e,t){var r=A(t),n=r[0],i=r.slice(1);while(i.length>0){var u=i,a=Y(u,1),o=a[0];if(!e(n,o)){return false}var s=i;var c=A(s);n=c[0];i=c.slice(1)}return true}function Qu(e,t){if(la(e)){return la(t)&&Aa(e)===Aa(t)}else if(e instanceof y){if(!(t instanceof y)){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 Qu(y(e),y(t))}else if(e instanceof ao){if(!(t instanceof ao)){return false}return e.__char__===t.__char__}else{return e===t}}function Zu(e,t){if(ws(e)!==ws(t)){return false}if(!Xu(e)){return false}if(e instanceof RegExp){return e.source===t.source}if(e instanceof oo){return e.valueOf()===t.valueOf()}return Qu(e,t)}function Xu(e){return e instanceof L||oo.isString(e)||e===U||e===null||e instanceof ao||e instanceof y||e===true||e===false}var ea=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 ta(e,t,r,n){if(typeof this!=="undefined"&&this.constructor!==ta||typeof this==="undefined"){return new ta(e,t)}h("Macro",e,"string",1);h("Macro",t,"function",2);if(r){if(n){this.__doc__=r}else{this.__doc__=ou(r)}}this.__name__=e;this.__fn__=t}ta.defmacro=function(e,t,r,n){var i=new ta(e,t,r,n);i.__defmacro__=true;return i};ta.prototype.invoke=function(e,t,r){var n=t.env,i=R(t,pn);var u=Fn(Fn({},i),{},{macro_expand:r});var a=this.__fn__.call(n,e,u,this.__name__);return a};ta.prototype.toString=function(){return"#")};var ra="define-macro";var na=-1e4;function ia(c){return function(){var r=B(H.mark(function e(r,m){var u,g,n,i,s,D,E,A,x,F,k,b,a,w,o;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:o=function e(){o=B(H.mark(function e(r,n,i){var h,u,a,p,o,_,s,d,c,v,f,l,y;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(!(r instanceof M&&r.car instanceof L)){t.next=50;break}if(!r[Ia]){t.next=3;break}return t.abrupt("return",r);case 3:h=r.car.valueOf();u=i.get(r.car,{throwError:false});a=D(r.car);p=a||E(u,r)||A(u);if(!(p&&r.cdr.car instanceof M)){t.next=28;break}if(!a){t.next=15;break}g=F(r.cdr.car);t.next=12;return b(r.cdr.car,n);case 12:o=t.sent;t.next=17;break;case 15:g=x(r.cdr.car);o=r.cdr.car;case 17:t.t0=M;t.t1=r.car;t.t2=M;t.t3=o;t.next=23;return w(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(!k(h,u)){t.next=50;break}_=u instanceof ua?r:r.cdr;t.next=32;return u.invoke(_,Fn(Fn({},m),{},{env:i}),true);case 32:s=t.sent;if(!(u instanceof ua)){t.next=41;break}d=s,c=d.expr,v=d.scope;if(!(c instanceof M)){t.next=40;break}if(!(n!==-1&&n<=1||n")}return"#"};ua.className="syntax";var aa=function(e){_(r,e);var t=bn(r);function r(){j(this,r);return t.apply(this,arguments)}return P(r)}(ua);ua.Parameter=aa;function oa(e,t,w,D){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:{};var E={"...":{symbols:{},lists:[]},symbols:{}};var A=r.expansion,k=r.define;function x(e){if(Ln()){console.log(e)}}x(w);function F(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:false;x({code:t&&Ju(t,true),pattern:e&&Ju(e,true)});if(Xu(e)&&!(e instanceof L)){return Zu(e,t)}if(e instanceof L&&w.includes(e.literal())){var c=A.ref(t);if(L.is(t,e)){if(typeof c==="undefined"){return true}return c===k||c===ns}return false}if(e instanceof M&&e.car instanceof M&&e.car.cdr instanceof M&&L.is(e.car.cdr.car,D)){x(">> 0");if(t===U){x({pattern:e.toString()});if(e.car.car instanceof L){if(e.car.cdr instanceof M&&L.is(e.car.cdr.car,D)){var f=e.car.car.valueOf();var l=e.last_pair();if(L.is(l.car,D)){E["..."].symbols[f]=null;return true}else{return false}}var h=e.car.car.valueOf();if(E["..."].symbols[h]){throw new Error("syntax: named ellipsis can only "+"appear onces")}E["..."].symbols[h]=t}}}if(e instanceof M&&e.cdr instanceof M&&L.is(e.cdr.car,D)){if(e.cdr.cdr!==U){if(e.cdr.cdr instanceof M){var p=e.cdr.cdr.length();var _=t.length();var i=t;while(_-1>p){i=i.cdr;_--}var d=i.cdr;i.cdr=U;if(!F(e.cdr.cdr,d,r,n)){return false}}}if(e.car instanceof L){var u=e.car.__name__;if(E["..."].symbols[u]&&!r.includes(u)&&!n){throw new Error("syntax: named ellipsis can only appear onces")}x(">> 1");if(t===U){x(">> 2");if(n){x("NIL");E["..."].symbols[u]=U}else{x("NULL");E["..."].symbols[u]=null}}else if(t instanceof M&&(t.car instanceof M||t.car===U)){x(">> 3 "+n);if(n){if(E["..."].symbols[u]){var a=E["..."].symbols[u];if(a===U){a=new M(U,new M(t,U))}else{a=a.append(new M(t,U))}E["..."].symbols[u]=a}else{E["..."].symbols[u]=new M(t,U)}}else{x(">> 4");E["..."].symbols[u]=new M(t,U)}}else{x(">> 6");if(t instanceof M){x(">> 7 "+n);r.push(u);if(!E["..."].symbols[u]){E["..."].symbols[u]=new M(t,U)}else{var v=E["..."].symbols[u];E["..."].symbols[u]=v.append(new M(t,U))}x({IIIIII:E["..."].symbols[u].toString()})}else{x(">> 8");return false}}return true}else if(e.car instanceof M){var y=C(r);if(t===U){x(">> 9");E["..."].lists.push(U);return true}x(">> 10");var m=t;while(m instanceof M){if(!F(e.car,m.car,y,true)){return false}m=m.cdr}return true}return false}if(e instanceof L){if(L.is(e,D)){throw new Error("syntax: invalid usage of ellipsis")}x(">> 11");var o=e.__name__;if(w.includes(o)){return true}x({name:o,ellipsis:n});if(n){E["..."].symbols[o]=E["..."].symbols[o]||[];E["..."].symbols[o].push(t)}E.symbols[o]=t;if(!E.symbols[o]);return true}if(e instanceof M&&t instanceof M){x(">> 12");x({a:12,code:t&&t.toString(),pattern:e.toString()});if(t.cdr===U){var g=e.car instanceof L&&e.cdr instanceof L;if(g){if(!F(e.car,t.car,r,n)){return false}x(">> 12 | 1");var s=e.cdr.valueOf();if(!(s in E.symbols)){E.symbols[s]=U}s=e.car.valueOf();if(!(s in E.symbols)){E.symbols[s]=t.car}return true}}x({pattern:e.toString(),code:t.toString()});if(e.cdr instanceof M&&e.car instanceof L&&e.cdr.cdr instanceof M&&e.cdr.car instanceof L&&L.is(e.cdr.cdr.car,D)&&e.cdr.cdr.cdr instanceof M&&!L.is(e.cdr.cdr.cdr.car,D)&&F(e.car,t.car,r,n)&&F(e.cdr.cdr.cdr,t.cdr,r,n)){var b=e.cdr.car.__name__;x({pattern:e.car.toString(),code:t.car.toString(),name:b});if(w.includes(b)){return true}E["..."].symbols[b]=null;return true}x("recur");if(F(e.car,t.car,r,n)&&F(e.cdr,t.cdr,r,n)){return true}}else if(e===U&&(t===U||t===undefined)){return true}else if(e.car instanceof M&&L.is(e.car.car,D)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(F(e,t)){return E}}function sa(e,i){function u(t){if(t instanceof M){if(!i.length){return t}var e=u(t.car);var r=u(t.cdr);return new M(e,r)}else if(t instanceof L){var n=i.find(function(e){return e.gensym===t});if(n){return L(n.name)}return t}else{return t}}return u(e)}function ca(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var O=e.bindings,t=e.expr,S=e.scope,a=e.symbols,f=e.names,B=e.ellipsis;var c={};function o(e){if(e instanceof L){return true}return["string","symbol"].includes(d(e))}function j(e){if(!o(e)){var t=ws(e);throw new Error("syntax: internal error, need symbol got ".concat(t))}var r=e.valueOf();if(r===B){throw new Error("syntax: internal error, ellipis not transformed")}var n=d(r);if(["string","symbol"].includes(n)){if(r in O.symbols){return O.symbols[r]}else if(n==="string"&&r.match(/\./)){var i=r.split(".");var u=i[0];if(u in O.symbols){return M.fromArray([L("."),O.symbols[u]].concat(i.slice(1).map(function(e){return oo(e)})))}}}if(a.includes(r)){return L(r)}return s(r)}function I(e){if(Ln()){console.log(e)}}function s(e){if(!c[e]){var t=S.ref(e);var r=Ri(e);if(t){var n=S.get(e);S.set(r,n)}else{var i=S.get(e,{throwError:false});if(typeof i!=="undefined"){S.set(r,i)}}f.push({name:e,gensym:r});c[e]=r;if(typeof e==="string"&&e.match(/\./)){var u=e.split(".").filter(Boolean),a=A(u),o=a[0],s=a.slice(1);if(c[o]){Ya(r,"__object__",[c[o]].concat(C(s)))}}}return c[e]}function P(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:function(){};var i=r.nested;I(" ==> "+e.toString(true));I(t);if(e instanceof L){var u=e.valueOf();I("[t 1");if(t[u]){if(t[u]instanceof M){var c=t[u],f=c.car,l=c.cdr;if(i){var h=f.car,p=f.cdr;if(p!==U){n(u,new M(p,U))}return h}if(l!==U){n(u,l)}return f}else if(t[u]instanceof Array){n(u,t[u].slice(1));return t[u][0]}}return j(u)}if(e instanceof M){if(e.car instanceof L&&e.cdr instanceof M&&L.is(e.cdr.car,B)){I("[t 2");var a=e.car.valueOf();var o=t[a];I({expr:e.toString(true),name:a,bindings:t,item:o});if(o===null){return}else if(o){I({b:t[a].toString()});if(o instanceof M){I("[t 2 Pair "+i);I({______:o.toString()});var s=o.car,_=o.cdr;if(i){if(_!==U){I("|| next 1");n(a,_)}I({car:s.toString()});return s}else{if(s.cdr!==U){I("|| next 2");n(a,new M(s.cdr,_))}I({car:s.car.toString()});return s.car}}else if(o instanceof Array){I("[t 2 Array "+i);if(i){n(a,o.slice(1));return M.fromArray(o)}else{var d=o.slice(1);if(d.length){n(a,d)}return o[0]}}else{return o}}}I("[t 3 recur "+e.toString());var v=P(e.car,t,r,n);var y=P(e.cdr,t,r,n);return new M(v,y)}return e}function R(t,r){var e=Object.values(t);var n=Object.getOwnPropertySymbols(t);if(n.length){e.push.apply(e,C(n.map(function(e){return t[e]})))}return e.length&&e.every(function(e){if(e===null){return!r}return e instanceof M||e===U||e instanceof Array&&e.length})}function T(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function N(i){var n=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},e=n.disabled;I("traverse>> "+Ju(i));if(i instanceof M){if(!e&&i.car instanceof M&&L.is(i.car.car,B)){return N(i.car.cdr,{disabled:true})}if(i.cdr instanceof M&&L.is(i.cdr.car,B)&&!e){I(">> 1");var t=O["..."].symbols;var f=Object.values(t);if(f.length&&f.every(function(e){return e===null})){return N(i.cdr.cdr,{disabled:e})}var l=T(t);var u=i.car instanceof L&&L.is(i.cdr.cdr.car,B);if(i.car instanceof M||u){if(O["..."].lists[0]===U){return U}var h=i.car;if(u){h=new M(i.car,new M(i.cdr.car,U))}I(">> 2");var a;if(l.length){I(">> 2 (a)");var o=Fn({},t);a=U;var p=function e(){if(!R(o)){return"break"}var n={};var t=function e(t,r){n[t]=r};var r=P(h,o,{nested:true},t);if(r!==undefined){if(u){if(a===U){a=r}else{a=a.append(r)}}else{a=new M(r,a)}}o=n};while(true){var _=p();if(_==="break")break}if(a!==U&&!u){a=a.reverse()}if(i.cdr.cdr!==U&&!L.is(i.cdr.cdr.car,B)){var d=N(i.cdr.cdr,{disabled:e});return a.append(d)}return a}else{I(">> 3");var v=P(i.car,t,{nested:true});if(v){return new M(v,U)}return U}}else if(i.car instanceof L){I(">> 4");if(L.is(i.cdr.cdr.car,B)){I(">> 4 (a)")}else{I(">> 4 (b)")}var y=i.car.__name__;var s=q({},y,t[y]);var m=t[y]===null;var c=U;var g=function e(){if(!R(s,true)){I({bind:s});return"break"}var n={};var t=function e(t,r){n[t]=r};var r=P(i,s,{nested:false},t);I({value:r.toString()});if(typeof r!=="undefined"){c=new M(r,c)}s=n};while(true){var b=g();if(b==="break")break}if(c!==U){c=c.reverse()}if(i.cdr instanceof M){if(i.cdr.cdr instanceof M||i.cdr.cdr instanceof L){var w=N(i.cdr.cdr,{disabled:e});if(m){return w}I("<<<< 1");c.append(w)}}I("<<<< 2");return c}}var D=N(i.car,{disabled:e});var r;var E;if(i.car instanceof L){var A=S.get(i.car,{throwError:false});E=A instanceof ta&&A.__name__==="syntax-rules"}if(E){if(i.cdr.car instanceof L){r=new M(N(i.cdr.car,{disabled:e}),new M(i.cdr.cdr.car,N(i.cdr.cdr.cdr,{disabled:e})))}else{r=new M(i.cdr.car,N(i.cdr.cdr,{disabled:e}))}I("REST >>>> "+r.toString())}else{r=N(i.cdr,{disabled:e})}I({a:true,car:Ju(i.car),cdr:Ju(i.cdr),head:Ju(D),rest:Ju(r)});return new M(D,r)}if(i instanceof L){if(e&&L.is(i,B)){return i}var x=Object.keys(O["..."].symbols);var F=i.literal();if(x.includes(F)){var k="missing ellipsis symbol next to name `".concat(F,"'");throw new Error("syntax-rules: ".concat(k))}var C=j(i);if(typeof C!=="undefined"){return C}}return i}return N(t,{})}function fa(e){return ga(e)||e===U||e===null}function la(e){return typeof e==="function"&&typeof e.bind==="function"}function ha(e){return e instanceof Is}function pa(e){return e instanceof Bs}function _a(e){return e instanceof Ss}function da(e){return e instanceof M}function va(e){return e instanceof Jo}function ya(e){return la(e)||ha(e)||_a(e)}function ma(e){if(e instanceof Ti){return false}if(e instanceof Promise){return true}return e&&la(e.then)}function ga(e){return typeof e==="undefined"}function ba(e){switch(d(e)){case"string":return oo(e);case"bigint":return y(e);case"number":if(Number.isNaN(e)){return ts}else{return y(e)}}return e}function wa(n,i){var e=Object.getOwnPropertyNames(n);var t=Object.getOwnPropertySymbols(n);e.concat(t).forEach(function(e){var t=i(n[e]);var r=Object.getOwnPropertyDescriptor(n,e);if(!r||r.writable&&n[e]!==t){n[e]=t}});return n}function Da(t){var e=[oo,y].some(function(e){return t instanceof e});if(e){return t.valueOf()}if(t instanceof Array){return t.map(Da)}if(t instanceof Ti){delete t.then}if(Iu(t)){return wa(t,Da)}return t}function Ea(e,t){if(e instanceof M){e.markCycles();return Ho(e)}if(la(e)){if(t){return xa(e,t)}}return ba(e)}function Aa(e){if(ka(e)){return e[ja]}return e}function xa(e,t){if(e[Symbol["for"]("__bound__")]){return e}var r=e.bind(t);var n=Object.getOwnPropertyNames(e);var i=Dn(n),u;try{for(i.s();!(u=i.n()).done;){var a=u.value;if(qa(a)){try{r[a]=e[a]}catch(e){}}}}catch(e){i.e(e)}finally{i.f()}Ya(r,"__fn__",e);Ya(r,"__context__",t);Ya(r,"__bound__",true);if(Ka(e)){Ya(r,"__native__",true)}if(Iu(t)&&za(e)){Ya(r,"__method__",true)}r.valueOf=function(){return e};return r}function Fa(e){return ka(e)&&e[Symbol["for"]("__context__")]===Object}function ka(e){return!!(la(e)&&e[ja])}function Ca(e){if(la(e)){var t=e[Ba];if(t&&(t===dc||t.constructor&&t.constructor.__class__)){return true}}return false}function Oa(e){return e instanceof Oo||e instanceof So}function Sa(e){if(la(e)){if(Oa(e[Ba])){return true}}return false}var Ba=Symbol["for"]("__context__");var ja=Symbol["for"]("__fn__");var Ia=Symbol["for"]("__data__");var Pa=Symbol["for"]("__ref__");var Na=Symbol["for"]("__cycles__");var Ra=Symbol["for"]("__class__");var Ta=Symbol["for"]("__method__");var La=Symbol["for"]("__prototype__");var Ua=Symbol["for"]("__lambda__");var Ma=["name","length","caller","callee","arguments","prototype"];function qa(e){return!Ma.includes(e)}function Ya(e,t,r){Object.defineProperty(e,Symbol["for"](t),{get:function e(){return r},set:function e(){},configurable:false,enumerable:false})}function Va(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 za(e){return e&&e[Ua]}function $a(e){return e&&e[Ta]}function Ja(e){return za(e)&&!e[La]&&!$a(e)&&!Sa(e)}function Ka(e){var t=Symbol["for"]("__native__");return la(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 b;switch(e){case Symbol["for"]("letrec"):b="letrec";break;case Symbol["for"]("let"):b="let";break;case Symbol["for"]("let*"):b="let*";break;default:throw new Error("Invalid let_macro value")}return ta.defmacro(b,function(t,e){var f=e.dynamic_env;var l=e.error,n=e.macro_expand,y=e.use_dynamic;var h;if(t.car instanceof L){if(!(t.cdr.car instanceof M||t.cdr.car===U)){throw new Error("let require list of pairs")}var r;if(t.cdr.car===U){h=U;r=U}else{r=t.cdr.car.map(function(e){return e.car});h=t.cdr.car.map(function(e){return e.cdr.car})}return M.fromArray([L("letrec"),[[t.car,M(L("lambda"),M(r,t.cdr.cdr))]],M(t.car,h)])}else if(n){return}var p=this;h=ns.get("list->array")(t.car);var _=p.inherit(b);var d,v;if(b==="let*"){v=_}else if(b==="let"){d=[]}var m=0;function g(){var e=new M(new L("begin"),t.cdr);return Ns(e,{env:_,dynamic_env:_,use_dynamic:y,error:l})}return function t(){var r=h[m++];f=b==="let*"?_:p;if(!r){if(d&&d.length){var e=d.map(function(e){return e.value});var n=e.filter(ma);if(n.length){return Li(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(o instanceof M){a.push(Ns(o.car,{env:i,dynamic_env:u,use_dynamic:r,error:n}));o=o.cdr}var s=a.filter(ma).length;if(s){return Li(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 uo(n,i){h("limit",i,"function",2);return function(){for(var e=arguments.length,t=new Array(e),r=0;r1){e=e.toLowerCase();if(ao.__names__[e]){t=e;e=ao.__names__[e]}else{throw new Error("Internal: Unknown named character")}}else{t=ao.__rev_names__[e]}Object.defineProperty(this,"__char__",{value:e,enumerable:true});if(t){Object.defineProperty(this,"__name__",{value:t,enumerable:true})}}ao.__names__=Hn;ao.__rev_names__={};Object.keys(ao.__names__).forEach(function(e){var t=ao.__names__[e];ao.__rev_names__[t]=e});ao.prototype.toUpperCase=function(){return ao(this.__char__.toUpperCase())};ao.prototype.toLowerCase=function(){return ao(this.__char__.toLowerCase())};ao.prototype.toString=function(){return"#\\"+(this.__name__||this.__char__)};ao.prototype.valueOf=ao.prototype.serialize=function(){return this.__char__};function oo(e){if(typeof this!=="undefined"&&!(this instanceof oo)||typeof this==="undefined"){return new oo(e)}if(e instanceof Array){this.__string__=e.map(function(e,t){h("LString",e,"character",t+1);return e.toString()}).join("")}else{this.__string__=e.valueOf()}}{var so=["length","constructor"];var co=Object.getOwnPropertyNames(String.prototype).filter(function(e){return!so.includes(e)});var fo=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 y){return e}if(typeof this!=="undefined"&&!(this instanceof y)||typeof this==="undefined"){return new y(e,t)}if(typeof e==="undefined"){throw new Error("Invalid LNumber constructor call")}var r=y.getType(e);if(y.types[r]){return y.types[r](e,t)}var n=e instanceof Array&&oo.isString(e[0])&&y.isNumber(e[1]);if(e instanceof y){return y(e.value)}if(!y.isNumber(e)&&!n){throw new Error("You can't create LNumber from ".concat(ws(e)))}if(e===null){e=0}var i;if(n){var c=e,u=Y(c,2),a=u[0],o=u[1];if(a instanceof oo){a=a.valueOf()}if(o instanceof y){o=o.valueOf()}var f=a.match(/^([+-])/);var l=false;if(f){a=a.replace(/^[+-]/,"");if(f[1]==="-"){l=true}}}if(Number.isNaN(e)){return Do(e)}else if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(n){var s;switch(o){case 8:s="0o";break;case 16:s="0x";break;case 2:s="0b";break;case 10:s="";break}if(typeof s==="undefined"){var h=BigInt(o);i=C(a).map(function(e,t){return BigInt(parseInt(e,o))*go(h,BigInt(t))}).reduce(function(e,t){return e+t})}else{i=BigInt(s+a)}}else{i=BigInt(e)}if(l){i*=BigInt(-1)}}else{i=e}return Co(i,true)}else if(typeof Nn!=="undefined"&&!(e instanceof Nn)){if(e instanceof Array){return Co(p(Nn,C(e)))}return Co(new Nn(e))}else if(n){this.constant(parseInt(a,o),"integer")}else{this.constant(e,"integer")}}y.prototype.constant=function(e,t){Object.defineProperty(this,"__value__",{value:e,enumerable:true});Object.defineProperty(this,"__type__",{value:t,enumerable:true})};y.types={float:function e(t){return new Do(t)},complex:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!y.isComplex(t)){t={im:0,re:t}}return new wo(t,r)},rational:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!y.isRational(t)){t={num:t,denom:1}}return new ko(t,r)}};y.prototype.serialize=function(){return this.__value__};y.prototype.isNaN=function(){return Number.isNaN(this.__value__)};y.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}}};y.isFloat=function e(t){return t instanceof Do||Number(t)===t&&t%1!==0};y.isNumber=function(e){return e instanceof y||y.isNative(e)||y.isBN(e)};y.isComplex=function(e){if(!e){return false}var t=e instanceof wo||(y.isNumber(e.im)||Number.isNaN(e.im))&&(y.isNumber(e.re)||Number.isNaN(e.re));return t};y.isRational=function(e){if(!e){return false}return e instanceof ko||y.isNumber(e.num)&&y.isNumber(e.denom)};y.isInteger=function(e){if(!(y.isNative(e)||e instanceof y)){return false}if(y.isFloat(e)){return false}if(y.isRational(e)){return false}if(y.isComplex(e)){return false}return true};y.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};y.isBigInteger=function(e){return e instanceof Co||typeof e==="bigint"||y.isBN(e)};y.isBN=function(e){return typeof Nn!=="undefined"&&e instanceof Nn};y.getArgsType=function(e,t){if(e instanceof Do||t instanceof Do){return Do}if(e instanceof Co||t instanceof Co){return Co}return y};y.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()};y.prototype.asType=function(e){var t=y.getType(this);return y.types[t]?y.types[t](e):y(e)};y.prototype.isBigNumber=function(){return typeof this.__value__==="bigint"||typeof Nn!=="undefined"&&!(this.value instanceof Nn)};["floor","ceil","round"].forEach(function(e){y.prototype[e]=function(){if(this["float"]||y.isFloat(this.__value__)){return y(Math[e](this.__value__))}else{return y(Math[e](this.valueOf()))}}});y.prototype.valueOf=function(){if(y.isNative(this.__value__)){return Number(this.__value__)}else if(y.isBN(this.__value__)){return this.__value__.toNumber()}};var _o=function(){var e=function e(t,r){return[t,r]};return{bigint:{bigint:e,float:function e(t,r){return[Do(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[Do(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&&Do(r.valueOf())]},integer:function e(t,r){return[t,r&&Do(r.valueOf())]},float:e,rational:function e(t,r){return[t,r&&Do(r.valueOf())]},complex:function e(t,r){return[{re:t,im:Do(0)},r]}},complex:{bigint:t("bigint"),integer:t("integer"),float:t("float"),rational:t("rational"),complex:function f(e,t){var r=y.coerce(e.__re__,t.__re__),n=Y(r,2),i=n[0],u=n[1];var a=y.coerce(e.__im__,t.__im__),o=Y(a,2),s=o[0],c=o[1];return[{im:s,re:i},{im:c,re:u}]}},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[Do(t.valueOf()),r]},rational:e,complex:function e(t,r){return[{im:vo(t.__type__,r.__im__.__type__,0)[0],re:vo(t.__type__,r.__re__.__type__,t)[0]},{im:vo(t.__type__,r.__im__.__type__,r.__im__)[0],re:vo(t.__type__,r.__re__.__type__,r.__re__)[0]}]}}};function t(r){return function(e,t){return[{im:vo(r,e.__im__.__type__,0,e.__im__)[1],re:vo(r,e.__re__.__type__,0,e.__re__)[1]},{im:vo(r,e.__im__.__type__,0,0)[1],re:vo(r,t.__type__,0,t)[1]}]}}}();function vo(e,t,r,n){return _o[e][t](r,n)}y.coerce=function(e,t){var r=y.getType(e);var n=y.getType(t);if(!_o[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!_o[r][n]){throw new Error("LNumber::coerce unknown rhs type ".concat(n))}var i=_o[r][n](e,t);return i.map(function(e){return y(e,true)})};y.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof y)){throw new Error("LNumber: you can't coerce ".concat(ws(e)))}if(typeof e==="number"){e=y(e)}return y.coerce(this,e)};y.getType=function(e){if(e instanceof y){return e.__type__}if(y.isFloat(e)){return"float"}if(y.isComplex(e)){return"complex"}if(y.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof Nn!=="undefined"&&!(e instanceof Nn)){return"bigint"}};y.prototype.isFloat=function(){return!!(y.isFloat(this.__value__)||this["float"])};var yo={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var mo={};Object.keys(yo).forEach(function(t){mo[yo[t]]=t;y.prototype[t]=function(e){return this.op(yo[t],e)}});y._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 wo)||typeof this==="undefined"){return new wo(e,t)}if(e instanceof wo){return wo({im:e.__im__,re:e.__re__})}if(y.isNumber(e)&&t){if(!t){return Number(e)}}else if(!y.isComplex(e)){var r="Invalid constructor call for LComplex expect &(:im :re ) object but got ".concat(Ju(e));throw new Error(r)}var n=e.im instanceof y?e.im:y(e.im);var i=e.re instanceof y?e.re:y(e.re);this.constant(n,i)}wo.prototype=Object.create(y.prototype);wo.prototype.constructor=wo;wo.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})};wo.prototype.serialize=function(){return{re:this.__re__,im:this.__im__}};wo.prototype.toRational=function(e){if(y.isFloat(this.__im__)&&y.isFloat(this.__re__)){var t=Do(this.__im__).toRational(e);var r=Do(this.__re__).toRational(e);return wo({im:t,re:r})}return this};wo.prototype.pow=function(e){throw new Error("Not yet implemented")};wo.prototype.add=function(e){return this.complex_op("add",e,function(e,t,r,n){return{re:e.add(t),im:r.add(n)}})};wo.prototype.factor=function(){if(this.__im__ instanceof Do||this.__im__ instanceof Do){var e=this.__re__,t=this.__im__;var r,n;if(e instanceof Do){r=e.toRational().mul(e.toRational())}else{r=e.mul(e)}if(t instanceof Do){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__))}};wo.prototype.modulus=function(){return this.factor().sqrt()};wo.prototype.conjugate=function(){return wo({re:this.__re__,im:this.__im__.sub()})};wo.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=Do(.5).mul(e.add(this.__re__)).sqrt();r=this.__im__.div(t).div(2)}else{r=Do(.5).mul(e.sub(this.__re__)).sqrt();if(this.__im__.cmp(0)===-1){r=r.sub()}t=this.__im__.div(r).div(2)}return wo({im:r,re:t})};wo.prototype.div=function(e){if(y.isNumber(e)&&!y.isComplex(e)){if(!(e instanceof y)){e=y(e)}var t=this.__re__.div(e);var r=this.__im__.div(e);return wo({re:t,im:r})}else if(!y.isComplex(e)){throw new Error("[LComplex::div] Invalid value")}if(this.cmp(e)===0){var n=this.coerce(e),i=Y(n,2),f=i[0],u=i[1];var l=f.__im__.div(u.__im__);return l.coerce(u.__re__)[0]}var h=this.coerce(e),a=Y(h,2),p=a[0],o=a[1];var s=o.factor();var _=o.conjugate();var c=p.mul(_);if(!y.isComplex(c)){return c.div(s)}var d=c.__re__.op("/",s);var v=c.__im__.op("/",s);return wo({re:d,im:v})};wo.prototype.sub=function(e){return this.complex_op("sub",e,function(e,t,r,n){return{re:e.sub(t),im:r.sub(n)}})};wo.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})};wo.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 wo(n,true)}return n};if(typeof t==="undefined"){return r()}if(y.isNumber(t)&&!y.isComplex(t)){if(!(t instanceof y)){t=y(t)}var n=t.asType(0);t={__im__:n,__re__:t}}else if(!y.isComplex(t)){throw new Error("[LComplex::".concat(e,"] Invalid value"))}var a=t.__re__ instanceof y?t.__re__:this.__re__.asType(t.__re__);var o=t.__im__ instanceof y?t.__im__:this.__im__.asType(t.__im__);return r(a,o)};wo._op={"+":"add","-":"sub","*":"mul","/":"div"};wo.prototype._op=function(e,t){var r=wo._op[e];return this[r](t)};wo.prototype.cmp=function(e){var t=this.coerce(e),r=Y(t,2),n=r[0],i=r[1];var u=n.__re__.coerce(i.__re__),a=Y(u,2),o=a[0],f=a[1];var s=o.cmp(f);if(s!==0){return s}else{var l=n.__im__.coerce(i.__im__),c=Y(l,2),h=c[0],p=c[1];return h.cmp(p)}};wo.prototype.valueOf=function(){return[this.__re__,this.__im__].map(function(e){return e.valueOf()})};wo.prototype.toString=function(){var e;if(this.__re__.cmp(0)!==0){e=[Ju(this.__re__)]}else{e=[]}var t=this.__im__.valueOf();var r=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY].includes(t);var n=Ju(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 Do(e){if(typeof this!=="undefined"&&!(this instanceof Do)||typeof this==="undefined"){return new Do(e)}if(!y.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof y){return Do(e.valueOf())}if(typeof e==="number"){if(Object.is(e,-0)){Object.defineProperty(this,"_minus",{value:true})}this.constant(e,"float")}}Do.prototype=Object.create(y.prototype);Do.prototype.constructor=Do;Do.prototype.toString=function(){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"}var e=this.__value__.toString();if(!y.isFloat(this.__value__)&&!e.match(/e/i)){var t=e+".0";return this._minus?"-"+t:t}return e.replace(/^([0-9]+)e/,"$1.0e")};Do.prototype._op=function(e,t){if(t instanceof y){t=t.__value__}var r=y._ops[e];if(e==="/"&&this.__value__===0&&t===0){return NaN}return Do(r(this.__value__,t))};Do.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){return Eo(this.__value__.valueOf())}return Ao(e.valueOf())(this.__value__.valueOf())};Do.prototype.sqrt=function(){var e=this.valueOf();if(this.cmp(0)<0){var t=Do(Math.sqrt(-e));return wo({re:0,im:t})}return Do(Math.sqrt(e))};Do.prototype.abs=function(){var e=this.valueOf();if(e<0){e=-e}return Do(e)};var Eo=Ao(1e-10);function Ao(n){return function(e){var t=function e(n,t,r){var i=function e(t,r){return r0){i=Fo(n,r)}else if(n.cmp(r)<=0){i=r}else if(r.cmp(0)>0){i=Fo(r,n)}else if(t.cmp(0)<0){i=y(Fo(n.sub(),r.sub())).sub()}else{i=y(0)}if(y.isFloat(t)||y.isFloat(e)){return Do(i)}return i}function Fo(e,t){var r=y(e).floor();var n=y(t).floor();if(e.cmp(r)<1){return r}else if(r.cmp(n)===0){var i=y(1).div(t.sub(n));var u=y(1).div(e.sub(r));return r.add(y(1).div(Fo(i,u)))}else{return r.add(y(1))}}function ko(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof ko)||typeof this==="undefined"){return new ko(e,t)}if(!y.isRational(e)){throw new Error("Invalid constructor call for LRational")}var r,n;if(e instanceof ko){r=y(e.__num__);n=y(e.__denom__)}else{r=y(e.num);n=y(e.denom)}if(!t&&n.cmp(0)!==0){var i=r.op("%",n).cmp(0)===0;if(i){return y(r.div(n))}}this.constant(r,n)}ko.prototype=Object.create(y.prototype);ko.prototype.constructor=ko;ko.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})};ko.prototype.serialize=function(){return{num:this.__num__,denom:this.__denom__}};ko.prototype.pow=function(e){var t=e.cmp(0);if(t===0){return y(1)}if(t===-1){e=e.sub();var r=this.__denom__.pow(e);var n=this.__num__.pow(e);return ko({num:r,denom:n})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};ko.prototype.sqrt=function(){var e=this.__num__.sqrt();var t=this.__denom__.sqrt();if(e instanceof Do||t instanceof Do){return e.div(t)}return ko({num:e,denom:t})};ko.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 ko({num:e,denom:t})};ko.prototype.cmp=function(e){return y(this.valueOf(),true).cmp(e)};ko.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 ko){t=y(t.valueOf(true))}r=this.__denom__.div(e);if(r instanceof ko){r=y(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()};ko.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 y._ops["/"](this.__num__.value,this.__denom__.value)}return Do(this.__num__.valueOf()).div(this.__denom__.valueOf())};ko.prototype.mul=function(e){if(!(e instanceof y)){e=y(e)}if(y.isRational(e)){var t=this.__num__.mul(e.__num__);var r=this.__denom__.mul(e.__denom__);return ko({num:t,denom:r})}var n=y.coerce(this,e),i=Y(n,2),u=i[0],a=i[1];return u.mul(a)};ko.prototype.div=function(e){if(!(e instanceof y)){e=y(e)}if(y.isRational(e)){var t=this.__num__.mul(e.__denom__);var r=this.__denom__.mul(e.__num__);return ko({num:t,denom:r})}var n=y.coerce(this,e),i=Y(n,2),u=i[0],a=i[1];var o=u.div(a);return o};ko.prototype._op=function(e,t){return this[mo[e]](t)};ko.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof y)){e=y(e)}if(y.isRational(e)){var t=e.__num__.sub();var r=e.__denom__;return this.add(ko({num:t,denom:r}))}if(!(e instanceof y)){e=y(e).sub()}else{e=e.sub()}var n=y.coerce(this,e),i=Y(n,2),u=i[0],a=i[1];return u.add(a)};ko.prototype.add=function(e){if(!(e instanceof y)){e=y(e)}if(y.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 ko({num:a,denom:u})}if(y.isFloat(e)){return Do(this.valueOf()).add(e)}var o=y.coerce(this,e),s=Y(o,2),c=s[0],f=s[1];return c.add(f)};function Co(e,t){if(typeof this!=="undefined"&&!(this instanceof Co)||typeof this==="undefined"){return new Co(e,t)}if(e instanceof Co){return Co(e.__value__,e._native)}if(!y.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.constant(e,"bigint");Object.defineProperty(this,"_native",{value:t})}Co.prototype=Object.create(y.prototype);Co.prototype.constructor=Co;Co.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};Co.prototype.serialize=function(){return this.__value__.toString()};Co.prototype._op=function(e,t){if(typeof t==="undefined"){if(y.isBN(this.__value__)){e=Co.bn_op[e];return Co(this.__value__.clone()[e](),false)}return Co(y._ops[e](this.__value__),true)}if(y.isBN(this.__value__)&&y.isBN(t.__value__)){e=Co.bn_op[e];return Co(this.__value__.clone()[e](t),false)}var r=y._ops[e](this.__value__,t.__value__);if(e==="/"){var n=this.op("%",t).cmp(0)===0;if(n){return y(r)}return ko({num:this,denom:t})}return Co(r,true)};Co.prototype.sqrt=function(){var e;var t=this.cmp(0)<0;if(y.isNative(this.__value__)){e=y(Math.sqrt(t?-this.valueOf():this.valueOf()))}else if(y.isBN(this.__value__)){e=t?this.__value__.neg().sqrt():this.__value__.sqrt()}if(t){return wo({re:0,im:e})}return e};y.NaN=y(NaN);function Oo(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof Oo)||typeof this==="undefined"){return new Oo(e)}h("InputPort",e,"function");nu(this,"__type__",qo);var i;Object.defineProperty(this,"__parser__",{enumerable:true,get:function e(){return i},set:function e(t){h("InputPort::__parser__",t,"parser");i=t}});this._read=e;this._with_parser=this._with_init_parser.bind(this,B(H.mark(function e(){var r;return H.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 Wi(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()!==Yo};this._make_defaults()}Oo.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(!y.isInteger(t)){var r=y.getType(t);ps("read-string",r,"integer")}return e.__lexer__.read_string(t.valueOf())});this.peek_char=this._with_parser(function(e){return e.__lexer__.peek_char()})};Oo.prototype._with_init_parser=function(o,s){var c=this;return B(H.mark(function e(){var r,n,i,u,a=arguments;return H.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 So(e){if(typeof this!=="undefined"&&!(this instanceof So)||typeof this==="undefined"){return new So(e)}h("OutputPort",e,"function");nu(this,"__type__",qo);this.write=e}So.prototype.is_open=function(){return this._closed!==true};So.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")}};So.prototype.flush=function(){};So.prototype.toString=function(){return"#"};var Bo=function(e){_(n,e);var r=bn(n);function n(e){var t;j(this,n);t=r.call(this,function(){var e;return(e=t)._write.apply(e,arguments)});h("BufferedOutputPort",e,"function");nu(o(t),"_fn",e,{hidden:true});nu(o(t),"_buffer",[],{hidden:true});return t}P(n,[{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"};jo.prototype.valueOf=function(){return this.__buffer__.map(function(e){return e.valueOf()}).join("")};function Io(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof Io)||typeof this==="undefined"){return new Io(e,t)}h("OutputFilePort",e,"string");nu(this,"__filename__",e);nu(this,"_fd",t.valueOf(),{hidden:true});nu(this,"__type__",qo);this.write=function(e){if(!oo.isString(e)){e=Ju(e)}else{e=e.valueOf()}r.fs().write(r._fd,e,function(e){if(e){throw e}})}}Io.prototype=Object.create(So.prototype);Io.prototype.constructor=Io;Io.prototype.fs=function(){if(!this._fs){this._fs=this.internal("fs")}return this._fs};Io.prototype.internal=function(e){return is.get("**internal-env**").get(e)};Io.prototype.close=function(){var n=this;return new Promise(function(t,r){n.fs().close(n._fd,function(e){if(e){r(e)}else{nu(n,"_fd",null,{hidden:true});So.prototype.close.call(n);t()}})})};Io.prototype.toString=function(){return"#")};function Po(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof Po)||typeof this==="undefined"){return new Po(e)}h("InputStringPort",e,"string");t=t||ns;e=e.valueOf();this._with_parser=this._with_init_parser.bind(this,function(){if(!r.__parser__){r.__parser__=new Wi(e,{env:t})}return r.__parser__});nu(this,"__type__",qo);this._make_defaults()}Po.prototype.char_ready=function(){return true};Po.prototype=Object.create(Oo.prototype);Po.prototype.constructor=Po;Po.prototype.toString=function(){return"#"};function No(e){if(typeof this!=="undefined"&&!(this instanceof No)||typeof this==="undefined"){return new No(e)}h("InputByteVectorPort",e,"uint8array");nu(this,"__vector__",e);nu(this,"__type__",Mo);var r=0;Object.defineProperty(this,"__index__",{enumerable:true,get:function e(){return r},set:function e(t){h("InputByteVectorPort::__index__",t,"number");if(t instanceof y){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}})}No.prototype=Object.create(Oo.prototype);No.prototype.constructor=No;No.prototype.toString=function(){return"#"};No.prototype.close=function(){var t=this;nu(this,"__vector__",U);["read_u8","close","peek_u8","read_u8_vector"].forEach(function(e){t[e]=function(){throw new Error("Input-binary-port: port is closed")}});this.char_ready=function(){return false}};No.prototype.u8_ready=function(){return true};No.prototype.peek_u8=function(){if(this.__index__>=this.__vector__.length){return Yo}return this.__vector__[this.__index__]};No.prototype.skip=function(){if(this.__index__<=this.__vector__.length){++this.__index__}};No.prototype.read_u8=function(){var e=this.peek_u8();this.skip();return e};No.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()===Yo){return Yo}return this.__vector__.slice(this.__index__,e)};function Ro(){if(typeof this!=="undefined"&&!(this instanceof Ro)||typeof this==="undefined"){return new Ro}nu(this,"__type__",Mo);nu(this,"_buffer",[],{hidden:true});this.write=function(e){h("write",e,["number","uint8array"]);if(y.isNumber(e)){this._buffer.push(e.valueOf())}else{var t;(t=this._buffer).push.apply(t,C(Array.from(e)))}};Object.defineProperty(this,"__buffer__",{enumerable:true,get:function e(){return Uint8Array.from(this._buffer)}})}Ro.prototype=Object.create(So.prototype);Ro.prototype.constructor=Ro;Ro.prototype.close=function(){So.prototype.close.call(this);nu(this,"_buffer",null,{hidden:true})};Ro.prototype._close_guard=function(){if(this._closed){throw new Error("output-port: binary port is closed")}};Ro.prototype.write_u8=function(e){h("OutputByteVectorPort::write_u8",e,"number");this.write(e)};Ro.prototype.write_u8_vector=function(e){h("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};Ro.prototype.toString=function(){return"#"};Ro.prototype.valueOf=function(){return this.__buffer__};function To(e,t){if(typeof this!=="undefined"&&!(this instanceof To)||typeof this==="undefined"){return new To(e,t)}Po.call(this,e);h("InputFilePort",t,"string");nu(this,"__filename__",t)}To.prototype=Object.create(Po.prototype);To.prototype.constructor=To;To.prototype.toString=function(){return"#")};function Lo(e,t){if(typeof this!=="undefined"&&!(this instanceof Lo)||typeof this==="undefined"){return new Lo(e,t)}No.call(this,e);h("InputBinaryFilePort",t,"string");nu(this,"__filename__",t)}Lo.prototype=Object.create(No.prototype);Lo.prototype.constructor=Lo;Lo.prototype.toString=function(){return"#")};function Uo(e,t){if(typeof this!=="undefined"&&!(this instanceof Uo)||typeof this==="undefined"){return new Uo(e,t)}h("OutputBinaryFilePort",e,"string");nu(this,"__filename__",e);nu(this,"_fd",t.valueOf(),{hidden:true});nu(this,"__type__",Mo);var u,r;this.write=function(e){var n=this;h("write",e,["number","uint8array"]);var i;if(!u){u=this.internal("fs")}if(!r){r=this.internal("Buffer")}if(y.isNumber(e)){i=r.from([e.valueOf()])}else{i=r.from(Array.from(e))}return new Promise(function(t,r){u.write(n._fd,i,function(e){if(e){r(e)}else{t()}})})}}Uo.prototype=Object.create(Io.prototype);Uo.prototype.constructor=Uo;Uo.prototype.write_u8=function(e){h("OutputByteVectorPort::write_u8",e,"number");this.write(e)};Uo.prototype.write_u8_vector=function(e){h("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};var Mo=Symbol["for"]("binary");var qo=Symbol["for"]("text");var Yo=new Vo;function Vo(){}Vo.prototype.toString=function(){return"#"};function zo(e){var c=this;var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.stderr,n=t.stdin,i=t.stdout,u=t.command_line,a=u===void 0?null:u,o=R(t,_n);if(typeof this!=="undefined"&&!(this instanceof zo)||typeof this==="undefined"){return new zo(e,Fn({stdin:n,stdout:i,stderr:r,command_line:a},o))}if(typeof e==="undefined"){e="anonymous"}this.__env__=is.inherit(e,o);this.__env__.set("parent.frame",l("parent.frame",function(){return c.__env__},ns.__env__["parent.frame"].__doc__));var f="**interaction-environment-defaults**";this.set(f,qu(o).concat(f));var s=es.inherit("internal-".concat(e));if(Oa(n)){s.set("stdin",n)}if(Oa(r)){s.set("stderr",r)}if(Oa(i)){s.set("stdout",i)}s.set("command-line",a);us(this.__env__,s)}zo.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;h("Interpreter::exec",e,["string","array"],1);h("Interpreter::exec",n,"boolean",2);if(!u){u=this.__env__}if(!i){i=u}ns.set("**interaction-environment**",this.__env__);return Ts(e,{env:u,dynamic_env:i,use_dynamic:n})};zo.prototype.get=function(e){var t=this.__env__.get(e);if(la(t)){return t.bind(this.__env__)}return t};zo.prototype.set=function(e,t){return this.__env__.set(e,t)};zo.prototype.constant=function(e,t){return this.__env__.constant(e,t)};function $o(e,t){this.name="LipsError";this.message=e;this.args=t;this.stack=(new Error).stack}$o.prototype=new Error;$o.prototype.constructor=$o;function Jo(e,t,r){if(arguments.length===1){if(d(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"}Jo.prototype.list=function(){return qu(this.__env__)};Jo.prototype.fs=function(){return this.get("**fs**")};Jo.prototype.unset=function(e){if(e instanceof L){e=e.valueOf()}if(e instanceof oo){e=e.valueOf()}delete this.__env__[e]};Jo.prototype.inherit=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(d(e)==="object"){t=e}if(!e||d(e)==="object"){e="child of "+(this.__name__||"unknown")}return new Jo(t||{},this,e)};Jo.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 L){e=e.__name__}if(e instanceof oo){e=e.valueOf()}if(t){if(!r){t=ou(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)}};Jo.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(!va(t)){return U}if(e<=0){return t}var r=t.get("parent.frame");return r(e-1)},ns.__env__["parent.frame"].__doc__));t.callee=e;n.set("arguments",t);return n};Jo.prototype._lookup=function(e){if(e instanceof L){e=e.__name__}if(e instanceof oo){e=e.valueOf()}if(this.__env__.hasOwnProperty(e)){return Ko(this.__env__[e])}if(this.__parent__){return this.__parent__._lookup(e)}};Jo.prototype.toString=function(){return"#"};Jo.prototype.clone=function(){var t=this;var r={};Object.keys(this.__env__).forEach(function(e){r[e]=t.__env__[e]});return new Jo(r,this.__parent__,this.__name__)};Jo.prototype.merge=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"merge";h("Environment::merge",e,"environment");return this.inherit(t,e.__env__)};function Ko(e){if(typeof this!=="undefined"&&!(this instanceof Ko)||typeof this==="undefined"){return new Ko(e)}this.value=e}Ko.isUndefined=function(e){return e instanceof Ko&&typeof e.value==="undefined"};Ko.prototype.valueOf=function(){return this.value};function Go(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof Go)||typeof this==="undefined"){return new Go(e)}this.__values__=e}Go.prototype.toString=function(){return this.__values__.map(function(e){return Ju(e)}).join("\n")};Go.prototype.valueOf=function(){return this.__values__};Jo.prototype.get=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};h("Environment::get",e,["symbol","string"]);var r=t.throwError,c=r===void 0?true:r;var n=e;if(n instanceof L||n instanceof oo){n=n.valueOf()}var i=this._lookup(n);if(i instanceof Ko){if(Ko.isUndefined(i)){return undefined}return Ea(i.valueOf())}var u;if(e instanceof L&&e[L.object]){u=e[L.object]}else if(typeof n==="string"){u=n.split(".").filter(Boolean)}if(u&&u.length>0){var f=u,a=A(f),o=a[0],s=a.slice(1);i=this._lookup(o);if(s.length){try{if(i instanceof Ko){i=i.valueOf()}else{i=Qo(On,o);if(la(i)){i=Aa(i)}}if(typeof i!=="undefined"){return Qo.apply(void 0,[i].concat(C(s)))}}catch(e){throw e}}else if(i instanceof Ko){return Ea(i.valueOf())}i=Qo(On,n)}if(typeof i!=="undefined"){return i}if(c){throw new Error("Unbound variable `"+n.toString()+"'")}};Jo.prototype.set=function(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;h("Environment::set",e,["string","symbol"]);if(y.isNumber(t)){t=y(t)}if(e instanceof L){e=e.__name__}if(e instanceof oo){e=e.valueOf()}this.__env__[e]=t;if(r){this.doc(e,r,true)}return this};Jo.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&&Iu(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};Jo.prototype.has=function(e){return this.__env__.hasOwnProperty(e)};Jo.prototype.ref=function(e){var t=this;while(true){if(!t){break}if(t.has(e)){return t}t=t.__parent__}};Jo.prototype.parents=function(){var e=this;var t=[];while(e){t.unshift(e);e=e.__parent__}return t};function Ho(e){if(ma(e)){return e.then(Ho)}if(e instanceof M||e instanceof L){e[Ia]=true}return e}var Wo=Zi(Bi('(lambda ()\n "[native code]"\n (throw "Invalid Invocation"))'))[0];var Qo=l("get",function c(e){var t;for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=Zo(this,"stdin")}ds("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=Zo(this,"stdin")}ds("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=Zo(this,"stdin")}ds("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=B(H.mark(function e(){var r,n,i,u,a,o,s,c,f,l=arguments;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:r=l.length>0&&l[0]!==undefined?l[0]:null;n=this.env;if(!oo.isString(r)){t.next=31;break}i=false;u=false;t.prev=5;o=kn(Zi(r,n));case 7:t.next=9;return o.next();case 9:if(!(i=!(s=t.sent).done)){t.next=15;break}c=s.value;return t.abrupt("return",c);case 12:i=false;t.next=7;break;case 15:t.next=21;break;case 17:t.prev=17;t.t0=t["catch"](5);u=true;a=t.t0;case 21:t.prev=21;t.prev=22;if(!(i&&o["return"]!=null)){t.next=26;break}t.next=26;return o["return"]();case 26:t.prev=26;if(!u){t.next=29;break}throw a;case 29:return t.finish(26);case 30:return t.finish(21);case 31:if(r===null){f=Zo(n,"stdin")}else{f=r}ds("read",f,"input-port");return t.abrupt("return",f.read.call(n));case 34:case"end":return t.stop()}}},e,this,[[5,17,21,31],[22,,26,30]])}));function t(){return e.apply(this,arguments)}return t}(),"(read [string])\n\n This function, if used with a string, will parse it and\n return the LIPS code, if there is any. If called with a\n port, it will parse the next item from the port. If called\n without an input, it will read a string from standard input\n (using the browser's prompt or a user defined input method)\n and calls itself with that string. This function can be used\n together with `eval` to evaluate code from a string."),pprint:l("pprint",function e(t){if(t instanceof M){t=new dc.Formatter(t.toString(true))["break"]().format();ns.get("display").call(ns,t)}else{ns.get("write").call(ns,t)}ns.get("newline").call(ns)},"(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=ns.get("display");var r=ns.get("newline");var n=this.use_dynamic;var i=ns;var u=ns;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=ns.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=Zo(this,"stdout")}else{h("display",r,"output-port")}var n=ns.get("repr")(t);r.write.call(ns,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=Zo(this,"stderr");var r=ns.get("repr");for(var n=arguments.length,i=new Array(n),u=0;u1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,f=R(t,dn);var n=this;var i=this;var u;var l=Fn(Fn({},f),{},{env:this,dynamic_env:n,use_dynamic:r});var a=Ns(e.cdr.car,l);a=Ds(a);function o(t,r,n){if(ma(t)){return t.then(function(e){return o(t,e,n)})}if(ma(r)){return r.then(function(e){return o(t,e,n)})}if(ma(n)){return n.then(function(e){return o(t,r,e)})}i.get("set-obj!").call(i,t,r,n);return n}if(e.car instanceof M&&L.is(e.car.car,".")){var h=e.car.cdr.car;var p=e.car.cdr.cdr.car;var _=Ns(h,{env:this,dynamic_env:n,use_dynamic:r,error:error});var d=Ns(p,{env:this,dynamic_env:n,use_dynamic:r,error:error});return o(_,d,a)}if(!(e.car instanceof L)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var s=e.car.valueOf();u=this.ref(e.car.__name__);return eu(a,function(e){if(!u){var t=s.split(".");if(t.length>1){var r=t.pop();var n=t.join(".");var i=c.get(n,{throwError:false});if(i){o(i,r,e);return}}throw new Error("Unbound variable `"+s+"'")}u.set(s,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 ta("set!",function(e){if(!(e.car instanceof L)){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){h("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){h("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"||e===U},"(empty? object)\n\n Function that returns #t if value is nil (an empty list) or undefined."),gensym:l("gensym",Ri,"(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){h("load",o,"string");var s=this;if(s.__name__==="__frame__"){s=s.__parent__}if(!(t instanceof Jo)){if(s===ns){t=s}else{t=this.get("**interaction-environment**")}}var c="**module-path**";var f=ns.get(c,{throwError:false});o=o.valueOf();if(!o.match(/.[^.]+$/)){o+=".scm"}var r=o.match(/\.xcb$/);function l(e){if(r){e=fc(e)}else{if(ws(e)==="buffer"){e=e.toString()}e=e.replace(/^#!.*/,"");if(e.match(/^\{/)){e=nc(e)}}return Ts(e,{env:t})}function n(e){return On.fetch(e).then(function(e){return r?e.arrayBuffer():e.text()}).then(function(e){if(r){e=new Uint8Array(e)}return e})}if(fs()){return new Promise(function(){var r=B(H.mark(function e(r,n){var i,u,a;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:i=Pn("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&&a!==U){process.cwd();o=i.join(i.dirname(a.car.valueOf()),o)}case 12:ns.set(c,i.dirname(o));Pn("fs").readFile(o,function(e,t){if(e){n(e);ns.set(c,f)}else{try{l(t).then(function(){r();ns.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){ns.set(c,o.replace(/\/[^/]*$/,""));return l(e)}).then(function(){})["finally"](function(){ns.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."),do:l(new ta("do",function(){var r=B(H.mark(function e(r,h){var p,n,i,u,o,s,a,c,f,l,_,d;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:p=h.use_dynamic,n=h.error;i=this;u=i;o=i.inherit("do");s=r.car;a=r.cdr.car;c=r.cdr.cdr;if(c!==U){c=new M(L("begin"),c)}f={env:i,dynamic_env:u,use_dynamic:p,error:n};l=s;case 10:if(!(l!==U)){t.next=21;break}_=l.car;t.t0=o;t.t1=_.car;t.next=16;return Ns(_.cdr.car,f);case 16:t.t2=t.sent;t.t0.set.call(t.t0,t.t1,t.t2);l=l.cdr;t.next=10;break;case 21:f={env:o,dynamic_env:u,error:n};d=H.mark(function e(){var r,n,i,u,a;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(!(c!==U)){t.next=3;break}t.next=3;return dc.evaluate(c,f);case 3:r=s;n={};case 5:if(!(r!==U)){t.next=15;break}i=r.car;if(!(i.cdr.cdr!==U)){t.next=12;break}t.next=10;return Ns(i.cdr.cdr.car,f);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);Object.keys(n).concat(a).forEach(function(e){o.set(e,n[e])});case 17:case"end":return t.stop()}}},e)});case 23:t.next=25;return Ns(a.car,f);case 25:t.t3=t.sent;if(!(t.t3===false)){t.next=30;break}return t.delegateYield(d(),"t4",28);case 28:t.next=23;break;case 30:if(!(a.cdr!==U)){t.next=34;break}t.next=33;return Ns(a.cdr.car,f);case 33:return t.abrupt("return",t.sent);case 34:case"end":return t.stop()}}},e,this)}));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 ta("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(t===false){return Ns(r.cdr.cdr.car,a)}else{return Ns(r.cdr.car,a)}};if(r===U){throw new Error("too few expressions for `if`")}var s=Ns(r.car,a);return eu(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 ta("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;h("let-env",t,"pair");var u=Ns(t.car,{env:this,dynamic_env:r,error:i,use_dynamic:n});return eu(u,function(e){h("let-env",e,"environment");return Ns(M(L("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(Ha("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())."),begin:l(new ta("begin",function(e,t){var n=Fn(Fn({},t),{},{env:this});var i=ns.get("list->array")(e);var u;return function t(){if(i.length){var e=i.shift();var r=Ns(e,n);return eu(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 ta("ignore",function(e,t){var r=Fn(Fn({},t),{},{env:this,dynamic_env:this});Ns(new M(new L("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(ta.defmacro("call/cc",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=Fn({env:this},t);return eu(Ns(e.car,r),function(e){if(la(e)){return e(new Is(null))}})}),"(call/cc proc)\n\n Call-with-current-continuation.\n\n NOT SUPPORTED BY LIPS RIGHT NOW"),parameterize:l(new ta("parameterize",function(t,e){var i=e.dynamic_env;var u=i.inherit("parameterize").new_frame(null,{});var a=Fn(Fn({},e),{},{env:this});var o=t.car;if(!da(o)){var r=ws(o);throw new Error("Invalid syntax for parameterize expecting pair got ".concat(r))}function s(){var e=new M(new L("begin"),t.cdr);return Ns(e,Fn(Fn({},a),{},{dynamic_env:u}))}return function r(){var e=o.car;var n=e.car.valueOf();return eu(Ns(e.cdr.car,a),function(e){var t=i.get(n,{throwError:false});if(!_a(t)){throw new Error("Unknown parameter ".concat(n))}u.set(n,t.inherit(e));if(!fa(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 ta("make-parameter",function(e,t){t.dynamic_env;var r=Ns(e.car,t);var n;if(e.cdr.car instanceof M){n=Ns(e.cdr.car,t)}return new Ss(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:l(ta.defmacro("define",function(r,e){var n=this;if(r.car instanceof M&&r.car.car instanceof L){var t=new M(new L("define"),new M(r.car.car,new M(new M(new L("lambda"),new M(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(i instanceof M){i=Ns(i,e);u=true}else if(i instanceof L){i=n.get(i)}h("define",r.car,"symbol");return eu(i,function(e){if(n.__name__===ua.__merge_env__){n=n.__parent__}if(u&&(la(e)&&za(e)||e instanceof ua||_a(e))){e.__name__=r.car.valueOf();if(e.__name__ instanceof oo){e.__name__=e.__name__.valueOf()}}var t;if(r.cdr.cdr instanceof M&&oo.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=d(e);if(fa(e)||i!=="object"&&i!=="function"){var u=ps("set-obj!",ws(e),["object","function"]);throw new Error(u)}h("set-obj!",t,["string","symbol","number"]);e=Aa(e);t=t.valueOf();if(arguments.length===2){delete e[t]}else if(Ku(e)&&la(r)){e[t]=Aa(r);e[t][La]=true}else if(la(r)||ys(r)||r===U){e[t]=r}else{e[t]=r&&!Ku(r)?r.valueOf():r}if(Pu){var a=e[t];Object.defineProperty(e,t,Fn(Fn({},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 ns.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]:{},v=e.use_dynamic,y=e.error;var m=this;var g;if(d.cdr instanceof M&&oo.isString(d.cdr.car)&&d.cdr.cdr!==U){g=d.cdr.car.valueOf()}function b(){var c=pa(this)?this:{dynamic_env:m},r=c.dynamic_env;var n=m.inherit("lambda");r=r.inherit("lambda");if(this&&!pa(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 e=arguments.length,t=new Array(e),i=0;i>> "+c.toString());if(c){o=c}var v=r.merge(t,ua.__merge_env__);if(l){return{expr:o,scope:v}}var y=Ns(o,Fn(Fn({},_),{},{env:v}));return sa(y,d)}i=i.cdr}}catch(e){e.message+=" in macro: ".concat(m.toString(true));throw e}throw new Error("Invalid Syntax ".concat(e.toString(true)))},w);r.__code__=m;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 ta("quote",function(e){return Ho(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:ta.defmacro("quasiquote",function(e,t){var o=t.use_dynamic,s=t.error;var c=this;var f=c;function a(e){return e instanceof M||Iu(e)||Array.isArray(e)}function h(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:a;if(e instanceof M){var n=e.car;var i=e.cdr;if(r(n)){n=t(n)}if(r(i)){i=t(i)}if(ma(n)||ma(i)){return Li([n,i]).then(function(e){var t=Y(e,2),r=t[0],n=t[1];return new M(r,n)})}else{return new M(n,i)}}return e}function u(e,t){if(e instanceof M){if(t!==U){e.append(t)}}else{e=new M(e,t)}return e}function r(e){return!!e.filter(function(e){return e instanceof M&&L.is(e.car,/^(unquote|unquote-splicing)$/)}).length}function p(e,n,i){return e.reduce(function(e,t){if(!(t instanceof M)){e.push(t);return e}if(L.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(!(i.cdr instanceof M&&r[0]===U)){return r[0]}}r=r.map(function(e){if(v.has(e)){return e.clone()}else{v.add(e);return e}});var n=l(i.cdr,0,1);if(n===U&&r[0]===U){return undefined}return eu(n,function(e){if(r[0]===U){return e}if(r.length===1){return u(r[0],e)}var t=r.reduce(function(e,t){return u(e,t)});return u(t,e)})})}(i.car.cdr)}var v=new Set;function l(e,t,r){if(e instanceof M){if(e.car instanceof M){if(L.is(e.car.car,"unquote-splicing")){return d(e,t+1,r)}if(L.is(e.car.car,"unquote")){if(t+2===r&&e.car.cdr instanceof M&&e.car.cdr.car instanceof M&&L.is(e.car.cdr.car.car,"unquote-splicing")){var n=e.car.cdr;return new M(new M(new L("unquote"),d(n,t+2,r)),U)}else if(e.car.cdr instanceof M&&e.car.cdr.cdr!==U){if(e.car.cdr.car instanceof M){var i=[];return function t(r){if(r===U){return M.fromArray(i)}return eu(Ns(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(L.is(e.car,"quasiquote")){var u=l(e.cdr,t,r+1);return new M(e.car,u)}if(L.is(e.car,"quote")){return new M(e.car,l(e.cdr,t,r))}if(L.is(e.car,"unquote")){t++;if(tr){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(e.cdr instanceof M){if(e.cdr.cdr!==U){if(e.cdr.car instanceof M){var a=[];return function t(r){if(r===U){return M.fromArray(a)}return eu(Ns(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 Ns(e.cdr.car,{env:c,dynamic_env:f,error:s})}}else{return e.cdr}}return h(e,function(e){return l(e,t,r)})}else if(Iu(e)){return _(e,t,r)}else if(e instanceof Array){return p(e,t,r)}return e}function n(e){if(e instanceof M){delete e[Ia];if(!e.haveCycles("car")){n(e.car)}if(!e.haveCycles("cdr")){n(e.cdr)}}}if(Iu(e.car)&&!r(Object.values(e.car))){return Ho(e.car)}if(Array.isArray(e.car)&&!r(e.car)){return Ho(e.car)}if(e.car instanceof M&&!e.car.find("unquote")&&!e.car.find("unquote-splicing")&&!e.car.find("quasiquote")){return Ho(e.car)}var i=l(e.car,0,1);return eu(i,function(e){n(e);return Ho(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){h("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 ns.get("array->list")(r)}else if(Array.isArray(t)){return t.reverse()}else{throw new Error(ps("reverse",ws(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){h("nth",t,"number");h("nth",r,["array","pair"]);if(r instanceof M){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){h("split",t,["regex","string"]);h("split",r,"string");return ns.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){h("replace",t,["regex","string"]);h("replace",r,["string","function"]);h("replace",n,"string");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){h("match",t,["regex","string"]);h("match",r,"string");var n=r.match(t);return n?ns.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){h("search",t,["regex","string"]);h("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 Ju(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){h("escape-regex",e,"string");return Ai(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(L);var r;if(t.length){r=M.fromArray(t)}else{r=U}if(e.__parent__ instanceof Jo){return ns.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]:qi.LITERAL;h("set-special!",e,"string",1);h("set-special!",t,"symbol",2);qi.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:Qo,".":Qo,unbind:l(Aa,"(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(ws,"(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 L||e instanceof oo||e instanceof y){e=e.valueOf()}return e in Da(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.'),instanceof:l("instanceof",function(e,t){return t instanceof Aa(e)},"(instanceof type obj)\n\n Predicate that tests if the obj is an instance of type."),"prototype?":l("prototype?",Ku,"(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 ta},"(macro? expression)\n\n Predicate that tests if value is a macro."),"function?":l("function?",la,"(function? expression)\n\n Predicate that tests if value is a callable function."),"real?":l("real?",function(e){if(ws(e)!=="number"){return false}if(e instanceof y){return e.isFloat()}return y.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)||y.isNumber(e)},"(number? expression)\n\n Predicate that tests if value is a number or NaN value."),"string?":l("string?",function(e){return oo.isString(e)},"(string? expression)\n\n Predicate that tests if value is a string."),"pair?":l("pair?",function(e){return e instanceof M},"(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 fa(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 L},"(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 e!==U&&e!==null&&!(e instanceof ao)&&!(e instanceof RegExp)&&!(e instanceof oo)&&!(e instanceof M)&&!(e instanceof y)&&d(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){h("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){h("array->list",e,"array");return M.fromArray(e)},"(array->list array)\n\n Function that converts a JavaScript array to a LIPS cons list."),"tree->array":l("tree->array",Bu("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",Bu("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,Fs(t,n))},"(apply fn list)\n\n Function that calls fn with the list of arguments."),length:l("length",function e(t){if(!t||t===U){return 0}if(t instanceof M){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;h("string->number",e,"string",1);h("string->number",t,"number",2);e=e.valueOf();t=t.valueOf();if(e.match(ai)||e.match(ni)){return li(e,t)}else if(e.match(oi)||e.match(ri)){return _i(e,t)}else{var r=t===10&&!e.match(/e/i)||t===16;if(e.match(ui)&&r||e.match(ii)){return hi(e,t)}if(e.match(Jn)){return yi(e)}}return false},"(string->number number [radix])\n\n Function that parses a string into a number."),try:l(new ta("try",function(t,e){var c=this;var r=e.use_dynamic,f=e.error;return new Promise(function(n,i){var u,a;if(L.is(t.cdr.car.car,"catch")){u=t.cdr.car;if(t.cdr.cdr instanceof M&&L.is(t.cdr.cdr.car.car,"finally")){a=t.cdr.cdr.car}}else if(L.is(t.cdr.car.car,"finally")){a=t.cdr.car}if(!(a||u)){throw new Error("try: invalid syntax")}var o=n;if(a){o=function e(t,r){o=i;eu(Ns(new M(new L("begin"),a.cdr),s),function(){r(t)})}}var s={env:c,use_dynamic:r,dynamic_env:c,error:function(t){function e(e){return t.apply(this,arguments)}e.toString=function(){return t.toString()};return e}(function(e){var t=c.inherit("try");if(u){t.set(u.cdr.car.car,e);var r={env:t,error:f};r.dynamic_env=c;eu(Ns(new M(new L("begin"),u.cdr.cdr),r),function(e){o(e,n)})}else{o(e,f)}})};var e=Ns(t.car,s);if(ma(e)){e.then(function(e){o(e,n)})["catch"](s.error)}else{o(e,n)}})}),"(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){h("find",r,["regex","function"]);h("find",n,["pair","nil"]);if(fa(n)){return U}var e=au("find",r);return eu(e(n.car),function(e){if(e&&e!==U){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;h("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=au("filter",t);return function t(r){function e(e){if(e&&e!==U){u.push(n)}return t(++r)}if(r===i.length){return M.fromArray(u)}var n=i[r];return eu(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(Za,"(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(Qa,"(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(io,"(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=Hu(s*r[a])/(u+o)}return y(u)},"(lcm n1 n2 ...)\n\n Function that returns the least common multiple of the arguments."),"odd?":l("odd?",to(function(e){return y(e).isOdd()}),"(odd? number)\n\n Checks if number is odd."),"even?":l("even?",to(function(e){return y(e).isEven()}),"(even? number)\n\n Checks if number is even."),"*":l("*",no(function(e,t){return y(e).mul(t)},y(1)),"(* . numbers)\n\n Multiplies all numbers passed as arguments. If single value is passed\n it will return that value."),"+":l("+",no(function(e,t){return y(e).add(t)},y(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,"number");return Wu(function(e,t){return y(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,"number");return Wu(function(e,t){return[0,1].includes(y(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?",Qu,"(eq? a b)\n\n Function that compares two values if they are identical."),or:l(new ta("or",function(e,t){var i=t.use_dynamic,u=t.error;var a=ns.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(c!==false){return c}else{return t()}}if(!a.length){if(c!==false){return c}else{return false}}else{var r=a.shift();var n=Ns(r,{env:o,dynamic_env:s,use_dynamic:i,error:u});return eu(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 ta("and",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=t.error;var i=ns.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(o===false){return false}else{return t()}}if(!i.length){if(o!==false){return o}else{return false}}else{var r=i.shift();return eu(Ns(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 y(e).or(t)},"(| a b)\n\n Function that calculates the bitwise or operation."),"&":l("&",function(e,t){return y(e).and(t)},"(& a b)\n\n Function that calculates the bitwise and operation."),"~":l("~",function(e){return y(e).neg()},"(~ number)\n\n Function that calculates the bitwise inverse (flip all the bits)."),">>":l(">>",function(e,t){return y(e).shr(t)},"(>> a b)\n\n Function that right shifts the value a by value b bits."),"<<":l("<<",function(e,t){return y(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(fa(t)){return true}return!t},"(not object)\n\n Function that returns the Boolean negation of its argument.")},undefined,"global");var is=ns.inherit("user-env");function us(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.");ns.set("**interaction-environment**",e)}us(is,es);ns.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(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(t){var r=e[t]?e[t]:t;ns.set(r,l(r,function(e){h(r,e,"number");if(e instanceof y){return e[t]()}},"(".concat(r," number)\n\n Function that calculates the ").concat(r," of a number.")))})})();function as(e){if(e.length===1){return e[0]}else{var t=[];var r=as(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(la(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{var a=r[r.length-1];r=r.slice(0,-1).join(", ")+" or "+a}}return"Expecting ".concat(r,", got ").concat(t).concat(i)}function _s(r,e,n){e.forEach(function(e,t){h(r,e,n,t+1)})}function ds(e,t,r){h(e,t,r);if(t.__type__===Mo){throw new Error(ps(e,"binary-port","textual-port"))}}function h(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;e=e.valueOf();var i=ws(t).toLowerCase();if(la(r)){if(!r(t)){throw new Error(ps(e,i,r,n))}return}var u=false;if(r instanceof M){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(ps(e,i,r,n))}}function vs(e){var t=d(e);return["string","function"].includes(t)||d(e)==="symbol"||e instanceof Ti||e instanceof L||e instanceof y||e instanceof oo||e instanceof RegExp}function ys(e){return e instanceof y||e instanceof oo||e instanceof ao}function ms(e,t){if(e===null){return false}return d(e)==="object"&&t in Object.getOwnPropertySymbols(e)}function gs(e,t){if(ms(e,t)||ms(e.__proto__,t)){return la(e[t])}}function bs(r){var n=new WeakMap;return function(e){var t=n.get(e);if(!t){t=r(e)}return t}}ws=bs(ws);function ws(e){var t=Bn.get(e);if(t){return t}if(d(e)==="object"){for(var r=0,n=Object.entries(Sn);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 Bs({env:a,use_dynamic:u,dynamic_env:o});return Ds(e.apply(s,t))}function Cs(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=Es(e,{env:i,dynamic_env:u,error:o,use_dynamic:a});return eu(e,function(e){if(Ja(n)){n=Aa(n)}e=Fs(n,e);var t=e.slice();var r=ks(n,t,{env:i,dynamic_env:u,use_dynamic:a});return eu(r,function(e){if(e instanceof M){e.markCycles();return Ho(e)}return ba(e)},o)})}var Os=new WeakMap;var Ss=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;j(this,n);q(this,"__value__",void 0);q(this,"__fn__",void 0);mn(this,Os,{writable:true,value:void 0});this.__value__=e;if(t){if(!la(t)){throw new Error("Section argument to Parameter need to be function "+"".concat(ws(t)," given"))}this.__fn__=t}if(r){a(this,Os,r)}}P(n,[{key:"__name__",get:function e(){return t(this,Os)},set:function e(t){a(this,Os,t);if(this.__fn__){this.__fn__.__name__="fn-".concat(t)}}},{key:"invoke",value:function e(){if(la(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 Bs=function(){function t(e){j(this,t);q(this,"env",void 0);q(this,"dynamic_env",void 0);q(this,"use_dynamic",void 0);Object.assign(this,e)}P(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 js(e,t){var r=e.get(t.__name__,{throwError:false});if(_a(r)&&r!==t){return r}var n=is.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(_a(r)&&r!==t){return r}}return t}var Is=function(){function t(e){j(this,t);q(this,"__value__",void 0);this.__value__=e}P(t,[{key:"invoke",value:function e(){if(this.__value__===null){throw new Error("Continuations are not implemented yet")}}}]);return t}();var Ps=function e(){};function Ns(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?Ps:t,r=R(e,yn);return function(e){try{if(!va(c)){c=s===true?is:s||is}if(f){s=c}else if(s===true){s=is}else{s=s||ns}var t={env:s,dynamic_env:c,use_dynamic:f,error:l};var r;if(fa(o)){return o}if(o instanceof L){return s.get(o)}if(!(o instanceof M)){return o}var n=o.car;var e=o.cdr;if(n instanceof M){r=Ds(Ns(n,t));if(ma(r)){return r.then(function(e){if(!ya(e)){throw new Error(ws(e)+" "+s.get("repr")(e)+" is not callable while evaluating "+o.toString())}return Ns(new M(e,o.cdr),t)})}else if(!ya(r)){throw new Error(ws(r)+" "+s.get("repr")(r)+" is not callable while evaluating "+o.toString())}}if(n instanceof L){r=s.get(n)}else if(la(n)){r=n}var i;if(r instanceof ua){i=As(r,o,t)}else if(r instanceof ta){i=xs(r,e,t)}else if(la(r)){i=Cs(r,e,t)}else if(_a(r)){var u=js(c,r);if(fa(o.cdr)){i=u.invoke()}else{return eu(Ns(o.cdr.car,t),function(e){u.__value__=e})}}else if(ha(r)){i=r.invoke()}else if(o instanceof M){r=n&&n.toString();throw new Error("".concat(ws(n)," ").concat(r," is not a function"))}else{return o}var a=s.get(Symbol["for"]("__promise__"),{throwError:false});if(a===true&&ma(i)){i=i.then(function(e){if(e instanceof M&&!r[Ia]){return Ns(e,t)}return e});return new Ti(i)}return i}catch(e){l&&l.call(s,e,o)}}(r)}var Rs=Ls(function(e){return e});var Ts=Ls(function(e,t){return t});function Ls(y){return function(){var t=B(H.mark(function e(r){var n,i,u,h,a,p,o,s,_,c,d,f,v,l=arguments;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:n=l.length>1&&l[1]!==undefined?l[1]:{},i=n.env,u=n.dynamic_env,h=n.use_dynamic;if(!va(u)){u=i===true?is:i||is}if(i===true){i=is}else{i=i||is}a=[];p=Array.isArray(r)?r:Zi(r);o=false;s=false;t.prev=7;c=kn(p);case 9:t.next=11;return c.next();case 11:if(!(o=!(d=t.sent).done)){t.next=25;break}f=d.value;v=Ns(f,{env:i,dynamic_env:u,use_dynamic:h,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))}}throw t}});t.t0=a;t.t1=y;t.t2=f;t.next=19;return v;case 19:t.t3=t.sent;t.t4=(0,t.t1)(t.t2,t.t3);t.t0.push.call(t.t0,t.t4);case 22:o=false;t.next=9;break;case 25:t.next=31;break;case 27:t.prev=27;t.t5=t["catch"](7);s=true;_=t.t5;case 31:t.prev=31;t.prev=32;if(!(o&&c["return"]!=null)){t.next=36;break}t.next=36;return c["return"]();case 36:t.prev=36;if(!s){t.next=39;break}throw _;case 39:return t.finish(36);case 40:return t.finish(31);case 41:return t.abrupt("return",a);case 42:case"end":return t.stop()}}},e,null,[[7,27,31,41],[32,,36,40]])}));function e(e){return t.apply(this,arguments)}return e}()}function Us(e){var t={"[":"]","(":")"};var r;if(typeof e==="string"){r=Bi(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 xi;var a=Dn(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 f=u.top();var c=t[f];if(s===c){u.pop()}else{throw new Error("Syntax error: missing closing ".concat(c))}}else{throw new Error("Syntax error: not matched closing ".concat(s))}}}catch(e){a.e(e)}finally{a.f()}return u.is_empty()}function Ms(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 On.Worker(r.createObjectURL(n))}function qs(){return dc.version.match(/^(\{\{VER\}\}|DEV)$/)}function Ys(){if(fs()){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 Vs=Ys();function zs(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"";var t="dist/std.xcb";if(e===""){if(Vs){e=Vs.replace(/[^/]*$/,"std.xcb")}else if(qs()){e="https://cdn.jsdelivr.net/gh/jcubic/lips@devel/".concat(t)}else{e="https://cdn.jsdelivr.net/npm/@jcubic/lips@".concat(dc.version,"/").concat(t)}}var r=ns.get("load");return r.call(is,e,ns)}function $s(e){this.url=e;var a=this.worker=Ms(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 dc.Interpreter("worker");o=zs(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 Js={pair:function e(t){var r=Y(t,2),n=r[0],i=r[1];return M(n,i)},number:function e(t){if(oo.isString(t)){return y([t,10])}return y(t)},regex:function e(t){var r=Y(t,2),n=r[0],i=r[1];return new RegExp(n,i)},nil:function e(){return U},symbol:function e(t){if(oo.isString(t)){return L(t)}else if(Array.isArray(t)){return L(Symbol["for"](t[0]))}},string:oo,character:ao};var Ks=Object.keys(Js);var Gs={};for(var Hs=0,Ws=Object.entries(Ks);Hs1){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 ac(){var e=1;var t=new TextEncoder("utf-8");return t.encode("LIPS".concat(e.toString().padStart(3," ")))}var oc=7;function sc(e){var t=new TextDecoder("utf-8");var r=t.decode(e.slice(0,oc));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 cc(e){var t=ac();var r=ic.encode(e);return uc(t,cn(r,{magic:false}))}function fc(e){var t=sc(e),r=t.type,n=t.version;if(r==="LIPS"&&n===1){var i=fn(e.slice(oc),{magic:false});return ic.decode(i)}else{throw new Error("Invalid file format ".concat(r))}}function lc(e){console.error(e.message||e);if(e.code){console.error(e.code.map(function(e,t){return"[".concat(t+1,"]: ").concat(e)}))}}function hc(){var a=["text/x-lips","text/x-scheme"];var o;function s(r){return new Promise(function(t){var e=r.getAttribute("src");if(e){return fetch(e).then(function(e){return e.text()}).then(Ts).then(t)["catch"](function(e){lc(e);t()})}else{return Ts(r.innerHTML).then(t)["catch"](function(e){lc(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=t.getAttribute("bootstrap");if(!o&&typeof n==="string"){return zs(n).then(function(){return s(t)}).then(e)}else{return s(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(pc){var t=pc;var r=t.getAttribute("bootstrap");if(typeof r==="string"){return zs(r).then(function(){o=true;return e()})}}return e()}var pc=typeof window!=="undefined"&&window.document&&document.currentScript;if(typeof window!=="undefined"){Rn(window,hc)}var _c=function(){var e=oo("Sun, 14 Jan 2024 00:09:28 +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}();nu(hu,"__class__","ahead");nu(M,"__class__","pair");nu(Su,"__class__","nil");nu(pu,"__class__","pattern");nu(lu,"__class__","formatter");nu(ta,"__class__","macro");nu(ua,"__class__","syntax");nu(Jo,"__class__","environment");nu(Oo,"__class__","input-port");nu(So,"__class__","output-port");nu(Bo,"__class__","output-port");nu(jo,"__class__","output-string-port");nu(Po,"__class__","input-string-port");nu(To,"__class__","input-file-port");nu(Io,"__class__","output-file-port");nu($o,"__class__","lips-error");[y,wo,ko,Do,Co].forEach(function(e){nu(e,"__class__","number")});nu(ao,"__class__","character");nu(L,"__class__","symbol");nu(oo,"__class__","string");nu(Ti,"__class__","promise");nu(Ss,"__class__","parameter");var dc={version:"DEV",banner:_c,date:"Sun, 14 Jan 2024 00:09:28 +0000",exec:Ts,parse:Za(iu,Zi),tokenize:Bi,evaluate:Ns,compile:Rs,serialize:rc,unserialize:nc,serialize_bin:cc,unserialize_bin:fc,bootstrap:zs,Environment:Jo,env:is,Worker:$s,Interpreter:zo,balanced_parenthesis:Us,balancedParenthesis:Us,balanced:Us,Macro:ta,Syntax:ua,Pair:M,Values:Go,QuotedPromise:Ti,Error:$o,quote:Ho,InputPort:Oo,OutputPort:So,BufferedOutputPort:Bo,InputFilePort:To,OutputFilePort:Io,InputStringPort:Po,OutputStringPort:jo,InputByteVectorPort:No,OutputByteVectorPort:Ro,InputBinaryFilePort:Lo,OutputBinaryFilePort:Uo,Formatter:lu,Parser:Wi,Lexer:Gi,specials:qi,repr:ju,nil:U,eof:Yo,LSymbol:L,LNumber:y,LFloat:Do,LComplex:wo,LRational:ko,LBigInteger:Co,LCharacter:ao,LString:oo,Parameter:Ss,rationalize:xo};ns.set("lips",dc);var vc={};var yc=Object.freeze({__proto__:null,default:vc});function mc(e,t){var r=0;for(var n=e.length-1;n>=0;n--){var i=e[n];if(i==="."){e.splice(n,1)}else if(i===".."){e.splice(n,1);r++}else if(r){e.splice(n,1);r--}}if(t){for(;r--;r){e.unshift("..")}}return e}var gc=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;var bc=function(e){return gc.exec(e).slice(1)};function wc(){var e="",t=false;for(var r=arguments.length-1;r>=-1&&!t;r--){var n=r>=0?arguments[r]:"/";if(typeof n!=="string"){throw new TypeError("Arguments to path.resolve must be strings")}else if(!n){continue}e=n+"/"+e;t=n.charAt(0)==="/"}e=mc(jc(e.split("/"),function(e){return!!e}),!t).join("/");return(t?"/":"")+e||"."}function Dc(e){var t=Ec(e),r=Ic(e,-1)==="/";e=mc(jc(e.split("/"),function(e){return!!e}),!t).join("/");if(!e&&!t){e="."}if(e&&r){e+="/"}return(t?"/":"")+e}function Ec(e){return e.charAt(0)==="/"}function Ac(){var e=Array.prototype.slice.call(arguments,0);return Dc(jc(e,function(e,t){if(typeof e!=="string"){throw new TypeError("Arguments to path.join must be strings")}return e}).join("/"))}function xc(e,t){e=wc(e).substr(1);t=wc(t).substr(1);function r(e){var t=0;for(;t=0;r--){if(e[r]!=="")break}if(t>r)return[];return e.slice(t,r-t+1)}var n=r(e.split("/"));var i=r(t.split("/"));var u=Math.min(n.length,i.length);var a=u;for(var o=0;o=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 En(e,t){if(!e)return;if(typeof e==="string")return An(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 An(e,t)}function An(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r1&&arguments[1]!==undefined?arguments[1]:null;var n=arguments[1]===true;function t(e){if(!Ln()){return}var t=is.get("repr")(e);if(r===null||r instanceof RegExp&&r.test(t)){console.log(is.get("type")(e)+": "+t)}if(n){console.log(e)}}if(ga(e)){e.then(t)}else{t(e)}return e}function Ln(){return us&&us.get("DEBUG",{throwError:false})}function Un(e){return e?"(?:#".concat(e,"(?:#[ie])?|#[ie]#").concat(e,")"):"(?:#[ie])?"}function Mn(e,t){return"".concat(Un(e),"[+-]?").concat(t,"+/").concat(t,"+")}function qn(e,t){return"".concat(Un(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 Yn(e,t){return"".concat(Un(e),"[+-]?").concat(t,"+")}var Vn=/^#\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimyus]*)$/;var zn="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)";var $n="(?:#[ie])?(?:[+-]?(?:[0-9]+/[0-9]+|nan.0|inf.0|".concat(zn,"|[+-]?[0-9]+))?(?:").concat(zn,"|[+-](?:[0-9]+/[0-9]+|[0-9]+|nan.0|inf.0))i");var Jn=new RegExp("^(#[ie])?".concat(zn,"$"),"i");function Kn(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 Gn=function(){var u={};[[10,"","[0-9]"],[16,"x","[0-9a-fA-F]"],[8,"o","[0-7]"],[2,"b","[01]"]].forEach(function(e){var t=Y(e,3),r=t[0],n=t[1],i=t[2];u[r]=Kn(n,i)});return u}();var Hn={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 Wn(e){var t=[];var r=0;var n=e.length;while(r=55296&&i<=56319&&r1&&arguments[1]!==undefined?arguments[1]:10;var r=fi(e);var n=r.number.split("/");var i=Co({num:y([n[0],r.radix||t]),denom:y([n[1],r.radix||t])});if(r.inexact){return i.valueOf()}else{return i}}function hi(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;var r=fi(e);if(r.inexact){return Eo(parseInt(r.number,r.radix||t))}return y([r.number,r.radix||t])}function pi(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(/#\\(.+)$/);if(t){r=t[1]}}if(r){return oo(r)}throw new Error("Parse: invalid character")}function _i(e){var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;function t(e){var t;if(e==="+"){t=y(1)}else if(e==="-"){t=y(-1)}else if(e.match(ui)){t=y([e,i])}else if(e.match(ai)){var r=e.split("/");t=Co({num:y([r[0],i]),denom:y([r[1],i])})}else if(e.match(Jn)){var n=yi(e);if(u.exact){return n.toRational()}return n}else if(e.match(/nan.0$/)){return y(NaN)}else if(e.match(/inf.0$/)){if(e[0]==="-"){return y(Number.NEGATIVE_INFINITY)}return y(Number.POSITIVE_INFINITY)}else{throw new Error("Internal Parser Error")}if(u.inexact){return Eo(t.valueOf())}return t}var u=fi(e);i=u.radix||i;var r;var n=u.number.match(si);if(i!==10&&n){r=n}else{r=u.number.match(Gn[i])}var a,o;o=t(r[2]);if(r[1]){a=t(r[1])}else{a=y(0)}if(o.cmp(0)===0&&o.__type__==="bigint"){return a}return Do({im:o,re:a})}function di(e){return parseInt(e.toString(),10)===e}function vi(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){return y(u).mul(o)}}}r=Eo(r);if(t.exact){return r.toRational()}return r}function mi(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{return so(JSON.parse(e))}catch(e){var r=e.message.replace(/in JSON /,"").replace(/.*Error: /,"");throw new Error("Invalid string literal: ".concat(r))}}function gi(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 L(e)}function bi(e){if(ns.hasOwnProperty(e)){return ns[e]}if(e.match(/^"[\s\S]*"$/)){return mi(e)}else if(e[0]==="#"){var t=e.match(Vn);if(t){return new RegExp(t[1],t[2])}else if(e.match(Xn)){return pi(e)}var r=e.match(/#\\(.+)/);if(r&&Wn(r[1]).length===1){return pi(e)}}if(e.match(/[0-9a-f]|[+-]i/i)){if(e.match(ii)){return hi(e)}else if(e.match(Jn)){return yi(e)}else if(e.match(ni)){return li(e)}else if(e.match(ri)){return _i(e)}}if(e.match(/^#[iexobd]/)){throw new Error("Invalid numeric constant: "+e)}return gi(e)}function wi(e){return!(["(",")","[","]"].includes(e)||qi.names().includes(e))}function Di(e){return wi(e)&&!(e.match(Vn)||e.match(/^"[\s\S]*"$/)||e.match(ii)||e.match(Jn)||e.match(ri)||e.match(ni)||e.match(Xn)||["#t","#f","nil","true","false"].includes(e))}var Ei=/"(?:\\[\S\s]|[^"])*"?/g;function Ai(e){if(typeof e==="string"){var t=/([-\\^$[\]()+{}?*.|])/g;return e.replace(t,"\\$1")}return e}function xi(){this.data=[]}xi.prototype.push=function(e){this.data.push(e)};xi.prototype.top=function(){return this.data[this.data.length-1]};xi.prototype.pop=function(){return this.data.pop()};xi.prototype.is_empty=function(){return!this.data.length};function Fi(e){if(e instanceof so){e=e.valueOf()}var t=new Gi(e,{whitespace:true});var r=[];while(true){var n=t.peek(true);if(n===Vo){break}r.push(n);t.skip()}return r}function ki(e){var t=e.token,r=R(e,hn);if(t.match(/^"[\s\S]*"$/)&&t.match(/\n/)){var n=new RegExp("^ {1,"+(e.col+1)+"}","mg");t=t.replace(n,"")}return Fn({token:t},r)}function Ci(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(){};this.fn=e;this.cont=t}Ci.prototype.toString=function(){return"#"};function Oi(n){return function(){for(var e=arguments.length,t=new Array(e),r=0;r1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof so){e=e.toString()}if(t){return Fi(e)}else{var r=Fi(e).map(function(e){if(e.token==="#\\ "){return e.token}return e.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return ji(r)}}function ji(e){var t=0;var r=null;var n=[];for(var i=0;i0&&arguments[0]!==undefined?arguments[0]:null;if(e instanceof L){if(e.is_gensym()){return e}e=e.valueOf()}if(Ni(e)){return L(e)}if(e!==null){return r(e,Symbol("#:".concat(e)))}t++;return r(t,Symbol("#:g".concat(t)))}}();function Ti(e){var r=this;var n={pending:true,rejected:false,fulfilled:false,reason:undefined,type:undefined};e=e.then(function(e){n.type=Ds(e);n.fulfilled=true;n.pending=false;return e});nu(this,"_promise",e,{hidden:true});if(ha(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]}})});nu(this,"__promise__",e);this.then=false}Ti.prototype.then=function(e){return new Ti(this.valueOf().then(e))};Ti.prototype["catch"]=function(e){return new Ti(this.valueOf()["catch"](e))};Ti.prototype.valueOf=function(){if(!this._promise){throw new Error("QuotedPromise: invalid promise created")}return this._promise};Ti.prototype.toString=function(){if(this.__pending__){return Ti.pending_str}if(this.__rejected__){return Ti.rejected_str}return"#")};Ti.pending_str="#";Ti.rejected_str="#";function Li(e){if(Array.isArray(e)){return Promise.all(Ui(e)).then(Mi)}return e}function Ui(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof Ti){t[r]=new Go(n)}else{t[r]=n}}return t}function Mi(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof Go){t[r]=n.valueOf()}else{t[r]=n}}return t}var qi={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 L("quote-promise"),qi.LITERAL]];var Ki=Ji.map(function(e){return e[0]});Object.freeze(Ki);Object.defineProperty(qi,"__builtins__",{writable:false,value:Ki});Ji.forEach(function(e){var t=Y(e,3),r=t[0],n=t[1],i=t[2];qi.append(r,n,i)});var Gi=function(){function p(e){var t=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=r.whitespace,i=n===void 0?false:n;j(this,p);nu(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=""}P(p,[{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 Vo}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 Vo}},{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 Vo}for(var r=this._i;r=r){return Vo}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 Vo}return oo(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]:{},r=t.prev_char,n=t["char"],i=t.next_char;var u=Y(e,4),a=u[0],o=u[1],s=u[2],f=u[3];if(e.length!==5){throw new Error("Lexer: Invalid rule of length ".concat(e.length))}if(!n.match(a)){return false}if(!Hi(o,r)){return false}if(!Hi(s,i)){return false}if(f!==this._state){return false}return true}},{key:"next_token",value:function f(){if(this._i>=this.__input__.length){return false}var e=true;e:for(var t=this._i,r=this.__input__.length;t2&&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?ki:u;j(this,o);if(e instanceof so){e=e.toString()}nu(this,"_formatter",a,{hidden:true});nu(this,"__lexer__",new Gi(e));nu(this,"__env__",r);nu(this,"_meta",i,{hidden:true});nu(this,"_refs",[],{hidden:true});nu(this,"_state",{parentheses:0},{hidden:true})}P(o,[{key:"resolve",value:function e(t){return this.__env__&&this.__env__.get(t,{throwError:false})}},{key:"peek",value:function(){var e=B(H.mark(function e(){var r;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:r=this.__lexer__.peek(true);if(!(r===Vo)){t.next=4;break}return t.abrupt("return",Vo);case 4:if(!this.is_comment(r.token)){t.next=7;break}this.skip();return t.abrupt("continue",0);case 7:if(!(r.token==="#;")){t.next=14;break}this.skip();if(!(this.__lexer__.peek()===Vo)){t.next=11;break}throw new Error("Lexer: syntax error eof found after comment");case 11:t.next=13;return this._read_object();case 13:return t.abrupt("continue",0);case 14:return t.abrupt("break",17);case 17:r=this._formatter(r);if(!this._meta){t.next=20;break}return t.abrupt("return",r);case 20:return t.abrupt("return",r.token);case 21: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=B(H.mark(function e(){var r;return H.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=B(H.mark(function e(){var r,n,i,u;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:r=U,n=r;case 1:t.next=4;return this.peek();case 4:i=t.sent;if(!(i===Vo)){t.next=7;break}return t.abrupt("break",27);case 7:if(!this.is_close(i)){t.next=10;break}this.skip();return t.abrupt("break",27);case 10:if(!(i==="."&&r!==U)){t.next=17;break}this.skip();t.next=14;return this._read_object();case 14:n.cdr=t.sent;t.next=25;break;case 17:t.t0=M;t.next=20;return this._read_object();case 20:t.t1=t.sent;t.t2=U;u=new t.t0(t.t1,t.t2);if(r===U){r=u}else{n.cdr=u}n=u;case 25:t.next=1;break;case 27:return t.abrupt("return",r);case 28:case"end":return t.stop()}}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"read_value",value:function(){var e=B(H.mark(function e(){var r;return H.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===Vo)){t.next=5;break}throw new Error("Parser: Expected token eof found");case 5:return t.abrupt("return",bi(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 Rs(t,{env:this.__env__,error:function e(t){throw t}})}},{key:"read_object",value:function(){var e=B(H.mark(function e(){var r;return H.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 Qi){r=r.valueOf()}if(!this._refs.length){t.next=7;break}return t.abrupt("return",this._resolve_object(r));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){var r=this._state.parentheses;var n=new Error("Parser: expected parenthesis but eof found");var i=new RegExp("\\){".concat(r,"}$"));n.__code__=[t.toString().replace(i,"")];throw n}},{key:"_resolve_object",value:function(){var t=B(H.mark(function e(r){var n=this;var i;return H.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(!Pu(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(!(r instanceof M)){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=B(H.mark(function e(r){return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(!(r instanceof M)){t.next=15;break}if(!(r.car instanceof Qi)){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 Qi)){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=B(H.mark(function e(){var r,n,h,i,u,a,o,s,c,f,l;return H.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===Vo)){t.next=5;break}return t.abrupt("return",r);case 5:if(!Yi(r)){t.next=38;break}n=qi.get(r);h=Vi(r);this.skip();u=$i(r);if(!u){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:a=t.t0;if(h){t.next=25;break}o=this.__env__.get(n.symbol);if(!(typeof o==="function")){t.next=25;break}if(zi(r)){s=[a]}else if(a===U){s=[]}else if(a instanceof M){s=a.to_array(false)}if(!(s||u)){t.next=24;break}return t.abrupt("return",Cs(o,u?[]:s,{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(zi(r)){i=new M(n.symbol,new M(a,U))}else{i=new M(n.symbol,a)}if(!h){t.next=28;break}return t.abrupt("return",i);case 28:if(!(o instanceof ra)){t.next=37;break}t.next=31;return this.evaluate(i);case 31:c=t.sent;if(!(c instanceof M||c instanceof L)){t.next=34;break}return t.abrupt("return",M.fromArray([L("quote"),c]));case 34:return t.abrupt("return",c);case 37:throw new Error("Parse Error: invalid parser extension: "+n.symbol);case 38:f=this.match_datum_ref(r);if(!(f!==null)){t.next=44;break}this.skip();if(!this._refs[f]){t.next=43;break}return t.abrupt("return",new Qi(f,this._refs[f]));case 43:throw new Error("Parse Error: invalid datum label #".concat(f,"#"));case 44:l=this.match_datum_label(r);if(!(l!==null)){t.next=51;break}this.skip();this._refs[l]=this._read_object();return t.abrupt("return",this._refs[l]);case 51:if(!this.is_open(r)){t.next=56;break}this.skip();return t.abrupt("return",this.read_list());case 56:return t.abrupt("return",this.read_value());case 57:case"end":return t.stop()}}},e,this)}));function t(){return e.apply(this,arguments)}return t}()}]);return o}();var Qi=function(){function r(e,t){j(this,r);this.name=e;this.data=t}P(r,[{key:"valueOf",value:function e(){return this.data}}]);return r}();function Zi(e,t){return Xi.apply(this,arguments)}function Xi(){Xi=e(H.mark(function e(r,n){var i,u;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(!n){if(is){n=is.get("**interaction-environment**",{throwError:false})}else{n=us}}i=new Wi(r,{env:n});case 3:t.next=6;return z(i.read_object());case 6:u=t.sent;if(!i.balanced()){i.ballancing_error(u)}if(!(u===Vo)){t.next=10;break}return t.abrupt("break",14);case 10:t.next=12;return u;case 12:t.next=3;break;case 14:case"end":return t.stop()}}},e)}));return Xi.apply(this,arguments)}function eu(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(ga(e)){var n=e.then(t);if(r===null){return n}else{return n["catch"](r)}}if(e instanceof Array){return tu(e,t,r)}if(Pu(e)){return ru(e,t,r)}return t(e)}function tu(t,r,e){if(t.find(ga)){return eu(Li(t),function(e){if(Object.isFrozen(t)){Object.freeze(e)}return r(e)},e)}return r(t)}function ru(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(ga(s)){u.push(s)}}if(u.length){return eu(Li(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 nu(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 iu(e){return uu.apply(this,arguments)}function uu(){uu=B(H.mark(function e(r){var n,i,u,a,o,s,c;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:n=[];i=false;u=false;t.prev=3;o=kn(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 uu.apply(this,arguments)}function au(e,t){if(t instanceof RegExp){return function(e){return String(e).match(t)}}else if(ha(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__=ou(r)}}if(e){t.__name__=e}else if(t.name&&!$a(t)){t.__name__=t.name}return t}function ou(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function su(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 cu(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 fu(e,t){return f(e,t)===t.length;function f(r,n){function e(e,t){var r=Dn(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")&&!Di(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 lu(e){this.__code__=e.replace(/\r/g,"")}lu.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|\*)?)$/],shift:{1:["&","#"]}}};lu.match=fu;lu.prototype._options=function e(t){var r=lu.defaults;if(typeof t==="undefined"){return Object.assign({},r)}var n=t&&t.exceptions||{};var i=n.specials||[];var u=n.shift||{1:[]};return Fn(Fn(Fn({},r),t),{},{exceptions:{specials:[].concat(C(r.exceptions.specials),C(i)),shift:Fn(Fn({},u),{},{1:[].concat(C(r.exceptions.shift[1]),C(u[1]))})}})};lu.prototype.indent=function e(t){var r=Bi(this.__code__,true);return this._indent(r,t)};lu.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=Dn(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){t.offset=0}if(n.toString()===e.toString()&&Ms(n)){return t.offset+n[0].col}else if(n.length===1){return t.offset+n[0].col+1}else{var u=-1;if(i){var a=lu.exception_shift(i.token,t);if(a!==-1){u=a}}if(u===-1){u=lu.exception_shift(n[1].token,t)}if(u!==-1){return t.offset+n[0].col+u}else if(n[0].line3&&n[1].line===n[3].line){if(n[1].token==="("||n[1].token==="["){return t.offset+n[1].col}return t.offset+n[3].col}else if(n[0].line===n[1].line){return t.offset+t.indent+n[0].col}else{var o=n.slice(2);for(var s=0;s")};hu.prototype.match=function(e){return e.match(this.pattern)};function pu(){for(var e=arguments.length,t=new Array(e),r=0;r")};lu.Pattern=pu;lu.Ahead=hu;var _u=/^[[(]$/;var du=/^[\])]$/;var vu=/[^()[\]]/;var yu=new hu(/[^)\]]/);var mu=Symbol["for"]("*");var gu=new pu([_u,mu,du],[vu],"+");var bu=new pu([_u,mu,du],"+");var wu=new pu([Symbol["for"]("symbol")],"?");var Du=new pu([Symbol["for"]("symbol")],"*");var Eu=[_u,Du,du];var Au=new pu([_u,Symbol["for"]("symbol"),mu,du],"+");var xu=Cu("define","lambda","define-macro","syntax-rules");var Fu=/^(?!.*\b(?:[()[\]]|define(?:-macro)?|let(?:\*|rec|-env|-syntax|)?|lambda|syntax-rules)\b).*$/;var ku=/^(?:#:)?(let(?:\*|rec|-env|-syntax)?)$/;function Cu(){for(var e=arguments.length,t=new Array(e),r=0;r0&&!i[e]){i[e]=su(n,e)}});var u=Dn(t),p;try{for(u.s();!(p=u.n()).done;){var a=Y(p.value,3),_=a[0],o=a[1],s=a[2];o=o.valueOf();var d=o>0?i[o]:n;var v=d.filter(function(e){return e.trim()&&!Yi(e)});var y=h(d);var m=fu(_,v);var g=e.slice(r).find(function(e){return e.trim()&&!Yi(e)});if(m&&(s instanceof hu&&s.match(g)||!s)){var c=r-y;if(e[c]!=="\n"){if(!e[c].trim()){e[c]="\n"}else{e.splice(c,0,"\n");r++}}r+=y;continue e}}}catch(e){u.e(e)}finally{u.f()}}this.__code__=e.join("");return this};lu.prototype._spaces=function(e){return new Array(e+1).join(" ")};lu.prototype.format=function c(e){var t=this.__code__.replace(/[ \t]*\n[ \t]*/g,"\n ");var r=Bi(t,true);var n=this._options(e);var i=0;var u=0;for(var a=0;a0){r=Math.floor(Math.random()*t);t--;var n=[e[r],e[t]];e[t]=n[0];e[r]=n[1]}return e}function Bu(){}Bu.prototype.toString=function(){return"()"};Bu.prototype.valueOf=function(){return undefined};Bu.prototype.serialize=function(){return 0};Bu.prototype.to_object=function(){return{}};Bu.prototype.append=function(e){return new M(e,U)};Bu.prototype.to_array=function(){return[]};var U=new Bu;function M(e,t){if(typeof this!=="undefined"&&this.constructor!==M||typeof this==="undefined"){return new M(e,t)}this.car=e;this.cdr=t}function ju(u,a){return function e(t){h(u,t,["pair","nil"]);if(t===U){return[]}var r=[];var n=t;while(true){if(n instanceof M){if(n.haveCycles("cdr")){break}var i=n.car;if(a&&i instanceof M){i=this.get(u).call(this,i)}r.push(i);n=n.cdr}else if(n===U){break}else{throw new Error("".concat(u,": can't convert improper list"))}}return r}}M.prototype.flatten=function(){return M.fromArray(Ou(this.to_array()))};M.prototype.length=function(){var e=0;var t=this;while(true){if(!t||t===U||!(t instanceof M)||t.haveCycles("cdr")){break}e++;t=t.cdr}return e};M.match=function(e,t){if(e instanceof L){return L.is(e,t)}else if(e instanceof M){return M.match(e.car,t)||M.match(e.cdr,t)}else if(Array.isArray(e)){return e.some(function(e){return M.match(e,t)})}else if(Pu(e)){return Object.values(e).some(function(e){return M.match(e,t)})}return false};M.prototype.find=function(e){return M.match(this,e)};M.prototype.clone=function(){var r=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var n=new Map;function i(e){if(e instanceof M){if(n.has(e)){return n.get(e)}var t=new M;n.set(e,t);if(r){t.car=i(e.car)}else{t.car=e.car}t.cdr=i(e.cdr);t[Ra]=e[Ra];return t}return e}return i(this)};M.prototype.last_pair=function(){var e=this;while(true){if(e.cdr===U){return e}e=e.cdr}};M.prototype.to_array=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var t=[];if(this.car instanceof M){if(e){t.push(this.car.to_array())}else{t.push(this.car)}}else{t.push(this.car.valueOf())}if(this.cdr instanceof M){t=t.concat(this.cdr.to_array(e))}return t};M.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(e instanceof M||r&&e instanceof Array&&e[Pa]){return e}if(t===false){var n=U;for(var i=e.length;i--;){n=new M(e[i],n)}return n}if(e.length&&!(e instanceof Array)){e=C(e)}var u=U;var a=e.length;while(a--){var o=e[a];if(o instanceof Array){o=M.fromArray(o,t,r)}else if(typeof o==="string"){o=so(o)}else if(typeof o==="number"&&!Number.isNaN(o)){o=y(o)}u=new M(o,u)}return u};M.prototype.to_object=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var t=this;var r={};while(true){if(t instanceof M&&t.car instanceof M){var n=t.car;var i=n.car;if(i instanceof L){i=i.__name__}if(i instanceof so){i=i.valueOf()}var u=n.cdr;if(u instanceof M){u=u.to_object(e)}if(ms(u)){if(!e){u=u.valueOf()}}r[i]=u;t=t.cdr}else{break}}return r};M.fromPairs=function(e){return e.reduce(function(e,t){return new M(new M(new L(t[0]),t[1]),e)},U)};M.fromObject=function(t){var e=Object.keys(t).map(function(e){return[e,t[e]]});return M.fromPairs(e)};M.prototype.reduce=function(e){var t=this;var r=U;while(true){if(t!==U){r=e(r,t.car);t=t.cdr}else{break}}return r};M.prototype.reverse=function(){if(this.haveCycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var t=U;while(e!==U){var r=e.cdr;e.cdr=t;t=e;e=r}return t};M.prototype.transform=function(n){function i(e){if(e instanceof M){if(e.replace){delete e.replace;return e}var t=n(e.car);if(t instanceof M){t=i(t)}var r=n(e.cdr);if(r instanceof M){r=i(r)}return new M(t,r)}return e}return i(this)};M.prototype.map=function(e){if(typeof this.car!=="undefined"){return new M(e(this.car),this.cdr===U?U:this.cdr.map(e))}else{return U}};var Iu=new Map;function Pu(e){return e&&d(e)==="object"&&e.constructor===Object}var Nu=Object.getOwnPropertyNames(Array.prototype);var Ru=[];Nu.forEach(function(e){Ru.push(Array[e],Array.prototype[e])});function Tu(e){e=xa(e);return Ru.includes(e)}function Lu(e){return ha(e)&&($a(e)||e.__doc__)}function Uu(r){var e=r.constructor||Object;var n=Pu(r);var i=ha(r[Symbol.asyncIterator])||ha(r[Symbol.iterator]);var u;if(Iu.has(e)){u=Iu.get(e)}else{Iu.forEach(function(e,t){t=xa(t);if(r.constructor===t&&(t===Object&&n&&!i||t!==Object)){u=e}})}return u}var Mu=new Map;[[true,"#t"],[false,"#f"],[null,"null"],[undefined,"#"]].forEach(function(e){var t=Y(e,2),r=t[0],n=t[1];Mu.set(r,n)});function qu(r){if(r&&d(r)==="object"){var n={};var e=Object.getOwnPropertySymbols(r);e.forEach(function(e){var t=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");n[t]=Ku(r[e])});var t=Object.getOwnPropertyNames(r);t.forEach(function(e){var t=r[e];if(t&&d(t)==="object"&&t.constructor===Object){n[e]=qu(t)}else{n[e]=Ku(t)}});return n}return r}function Yu(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function Vu(e,t){return e.hasOwnProperty(t)&&ha(e.toString)}function zu(e){if(Ga(e)){return"#"}var t=e.prototype&&e.prototype.constructor;if(ha(t)&&$a(t)){if(e[Ta]&&t.hasOwnProperty("__name__")){var r=t.__name__;if(so.isString(r)){r=r.toString();return"#")}return"#"}}if(e.hasOwnProperty("__name__")){var n=e.__name__;if(d(n)==="symbol"){n=Pi(n)}if(typeof n==="string"){return"#")}}if(Vu(e,"toString")){return e.toString()}else if(e.name&&!$a(e)){return"#")}else{return"#"}}var $u=new Map;[[Error,function(e){return e.message}],[M,function(e,t){var r=t.quote,n=t.skip_cycles,i=t.pair_args;if(!n){e.markCycles()}return e.toString.apply(e,[r].concat(C(i)))}],[oo,function(e,t){var r=t.quote;if(r){return e.toString()}return e.valueOf()}],[so,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=Y(e,2),r=t[0],n=t[1];$u.set(r,n)});var Ju=[L,y,ra,Ho,So,Bo,Ko,Ti];function Ku(e,t,c){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(Mu.has(e)){return Mu.get(e)}if(Gu(e)){return"#"}if(e){var r=e.constructor;if($u.has(r)){for(var n=arguments.length,f=new Array(n>3?n-3:0),i=3;i"}if(e===null){return"null"}if(d(e)==="object"){var a=e.constructor;if(!a){a=Object}var o;if(typeof a.__class__==="string"){o=a.__class__}else{var s=Uu(e);if(s){if(ha(s)){return s(e,t)}else{throw new Error("toString: Invalid repr value")}}o=a.name}if(ha(e.toString)&&$a(e.toString)){return e.toString().valueOf()}if(Ds(e)==="instance"){if($a(a)&&a.__name__){o=a.__name__.valueOf()}else if(!Ga(a)){o="instance"}}if(bs(e,Symbol.iterator)){if(o){return"#")}return"#"}if(bs(e,Symbol.asyncIterator)){if(o){return"#")}return"#"}if(o!==""){return"#<"+o+">"}return"#"}if(typeof e!=="string"){return e.toString()}return e}function Gu(e){return e&&d(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}M.prototype.markCycles=function(){Hu(this);return this};M.prototype.haveCycles=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(!e){return this.haveCycles("car")||this.haveCycles("cdr")}return!!(this[Ra]&&this[Ra][e])};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(r instanceof M){if(n.includes(r)){if(!u.includes(r)){u.push(r)}if(!e[Ra]){e[Ra]={}}e[Ra][t]=r;if(!i.includes(e)){i.push(e)}return true}}}var s=Oi(function e(t,r){if(t instanceof M){delete t.ref;delete t[Ra];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 Ci(function(){return e(t.cdr,r.slice())})}}});function r(e,t){if(e[Ra][t]instanceof M){var r=n.indexOf(e[Ra][t]);e[Ra][t]="#".concat(r,"#")}}s(e,[]);var n=t.filter(function(e){return u.includes(e)});n.forEach(function(e,t){e[Na]="#".concat(t,"=")});i.forEach(function(e){r(e,"car");r(e,"cdr")})}M.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[Na]){i.push(this[Na]+"(")}else if(!n){i.push("(")}var u;if(this[Ra]&&this[Ra].car){u=this[Ra].car}else{u=Ku(this.car,e,true)}if(u!==undefined){i.push(u)}if(this.cdr instanceof M){if(this[Ra]&&this[Ra].cdr){i.push(" . ");i.push(this[Ra].cdr)}else{if(this.cdr[Na]){i.push(" . ")}else{i.push(" ")}var a=this.cdr.toString(e,{nested:true});i.push(a)}}else if(this.cdr!==U){i=i.concat([" . ",Ku(this.cdr,e,true)])}if(!n||this[Na]){i.push(")")}return i.join("")};M.prototype.set=function(e,t){this[e]=t;if(t instanceof M){this.markCycles()}};M.prototype.append=function(e){if(e instanceof Array){return this.append(M.fromArray(e))}var t=this;if(t.car===undefined){if(e instanceof M){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(e!==U){while(true){if(t instanceof M&&t.cdr!==U){t=t.cdr}else{break}}t.cdr=e}return this};M.prototype.serialize=function(){return[this.car,this.cdr]};M.prototype[Symbol.iterator]=function(){var r=this;return{next:function e(){var t=r;r=t.cdr;if(t===U){return{value:undefined,done:true}}else{return{value:t.car,done:false}}}}};function Wu(e){return e<0?-e:e}function Qu(e,t){var r=A(t),n=r[0],i=r.slice(1);while(i.length>0){var u=i,a=Y(u,1),o=a[0];if(!e(n,o)){return false}var s=i;var c=A(s);n=c[0];i=c.slice(1)}return true}function Zu(e,t){if(ha(e)){return ha(t)&&xa(e)===xa(t)}else if(e instanceof y){if(!(t instanceof y)){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 Zu(y(e),y(t))}else if(e instanceof oo){if(!(t instanceof oo)){return false}return e.__char__===t.__char__}else{return e===t}}function Xu(e,t){if(Ds(e)!==Ds(t)){return false}if(!ea(e)){return false}if(e instanceof RegExp){return e.source===t.source}if(e instanceof so){return e.valueOf()===t.valueOf()}return Zu(e,t)}function ea(e){return e instanceof L||so.isString(e)||e===U||e===null||e instanceof oo||e instanceof y||e===true||e===false}var ta=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 ra(e,t,r,n){if(typeof this!=="undefined"&&this.constructor!==ra||typeof this==="undefined"){return new ra(e,t)}h("Macro",e,"string",1);h("Macro",t,"function",2);if(r){if(n){this.__doc__=r}else{this.__doc__=ou(r)}}this.__name__=e;this.__fn__=t}ra.defmacro=function(e,t,r,n){var i=new ra(e,t,r,n);i.__defmacro__=true;return i};ra.prototype.invoke=function(e,t,r){var n=t.env,i=R(t,pn);var u=Fn(Fn({},i),{},{macro_expand:r});var a=this.__fn__.call(n,e,u,this.__name__);return a};ra.prototype.toString=function(){return"#")};var na="define-macro";var ia=-1e4;function ua(c){return function(){var r=B(H.mark(function e(r,m){var u,g,n,i,s,D,E,A,x,F,k,b,a,w,o;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:o=function e(){o=B(H.mark(function e(r,n,i){var h,u,a,p,o,_,s,d,c,v,f,l,y;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(!(r instanceof M&&r.car instanceof L)){t.next=50;break}if(!r[Pa]){t.next=3;break}return t.abrupt("return",r);case 3:h=r.car.valueOf();u=i.get(r.car,{throwError:false});a=D(r.car);p=a||E(u,r)||A(u);if(!(p&&r.cdr.car instanceof M)){t.next=28;break}if(!a){t.next=15;break}g=F(r.cdr.car);t.next=12;return b(r.cdr.car,n);case 12:o=t.sent;t.next=17;break;case 15:g=x(r.cdr.car);o=r.cdr.car;case 17:t.t0=M;t.t1=r.car;t.t2=M;t.t3=o;t.next=23;return w(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(!k(h,u)){t.next=50;break}_=u instanceof aa?r:r.cdr;t.next=32;return u.invoke(_,Fn(Fn({},m),{},{env:i}),true);case 32:s=t.sent;if(!(u instanceof aa)){t.next=41;break}d=s,c=d.expr,v=d.scope;if(!(c instanceof M)){t.next=40;break}if(!(n!==-1&&n<=1||n")}return"#"};aa.className="syntax";var oa=function(e){_(r,e);var t=bn(r);function r(){j(this,r);return t.apply(this,arguments)}return P(r)}(aa);aa.Parameter=oa;function sa(e,t,w,D){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:{};var E={"...":{symbols:{},lists:[]},symbols:{}};var A=r.expansion,k=r.define;function x(e){if(Ln()){console.log(e)}}x(w);function F(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:false;x({code:t&&Ku(t,true),pattern:e&&Ku(e,true)});if(ea(e)&&!(e instanceof L)){return Xu(e,t)}if(e instanceof L&&w.includes(e.literal())){var c=A.ref(t);if(L.is(t,e)){if(typeof c==="undefined"){return true}return c===k||c===is}return false}if(e instanceof M&&e.car instanceof M&&e.car.cdr instanceof M&&L.is(e.car.cdr.car,D)){x(">> 0");if(t===U){x({pattern:e.toString()});if(e.car.car instanceof L){if(e.car.cdr instanceof M&&L.is(e.car.cdr.car,D)){var f=e.car.car.valueOf();var l=e.last_pair();if(L.is(l.car,D)){E["..."].symbols[f]=null;return true}else{return false}}var h=e.car.car.valueOf();if(E["..."].symbols[h]){throw new Error("syntax: named ellipsis can only "+"appear onces")}E["..."].symbols[h]=t}}}if(e instanceof M&&e.cdr instanceof M&&L.is(e.cdr.car,D)){if(e.cdr.cdr!==U){if(e.cdr.cdr instanceof M){var p=e.cdr.cdr.length();var _=t.length();var i=t;while(_-1>p){i=i.cdr;_--}var d=i.cdr;i.cdr=U;if(!F(e.cdr.cdr,d,r,n)){return false}}}if(e.car instanceof L){var u=e.car.__name__;if(E["..."].symbols[u]&&!r.includes(u)&&!n){throw new Error("syntax: named ellipsis can only appear onces")}x(">> 1");if(t===U){x(">> 2");if(n){x("NIL");E["..."].symbols[u]=U}else{x("NULL");E["..."].symbols[u]=null}}else if(t instanceof M&&(t.car instanceof M||t.car===U)){x(">> 3 "+n);if(n){if(E["..."].symbols[u]){var a=E["..."].symbols[u];if(a===U){a=new M(U,new M(t,U))}else{a=a.append(new M(t,U))}E["..."].symbols[u]=a}else{E["..."].symbols[u]=new M(t,U)}}else{x(">> 4");E["..."].symbols[u]=new M(t,U)}}else{x(">> 6");if(t instanceof M){x(">> 7 "+n);r.push(u);if(!E["..."].symbols[u]){E["..."].symbols[u]=new M(t,U)}else{var v=E["..."].symbols[u];E["..."].symbols[u]=v.append(new M(t,U))}x({IIIIII:E["..."].symbols[u].toString()})}else{x(">> 8");return false}}return true}else if(e.car instanceof M){var y=C(r);if(t===U){x(">> 9");E["..."].lists.push(U);return true}x(">> 10");var m=t;while(m instanceof M){if(!F(e.car,m.car,y,true)){return false}m=m.cdr}return true}return false}if(e instanceof L){if(L.is(e,D)){throw new Error("syntax: invalid usage of ellipsis")}x(">> 11");var o=e.__name__;if(w.includes(o)){return true}x({name:o,ellipsis:n});if(n){E["..."].symbols[o]=E["..."].symbols[o]||[];E["..."].symbols[o].push(t)}E.symbols[o]=t;if(!E.symbols[o]);return true}if(e instanceof M&&t instanceof M){x(">> 12");x({a:12,code:t&&t.toString(),pattern:e.toString()});if(t.cdr===U){var g=e.car instanceof L&&e.cdr instanceof L;if(g){if(!F(e.car,t.car,r,n)){return false}x(">> 12 | 1");var s=e.cdr.valueOf();if(!(s in E.symbols)){E.symbols[s]=U}s=e.car.valueOf();if(!(s in E.symbols)){E.symbols[s]=t.car}return true}}x({pattern:e.toString(),code:t.toString()});if(e.cdr instanceof M&&e.car instanceof L&&e.cdr.cdr instanceof M&&e.cdr.car instanceof L&&L.is(e.cdr.cdr.car,D)&&e.cdr.cdr.cdr instanceof M&&!L.is(e.cdr.cdr.cdr.car,D)&&F(e.car,t.car,r,n)&&F(e.cdr.cdr.cdr,t.cdr,r,n)){var b=e.cdr.car.__name__;x({pattern:e.car.toString(),code:t.car.toString(),name:b});if(w.includes(b)){return true}E["..."].symbols[b]=null;return true}x("recur");if(F(e.car,t.car,r,n)&&F(e.cdr,t.cdr,r,n)){return true}}else if(e===U&&(t===U||t===undefined)){return true}else if(e.car instanceof M&&L.is(e.car.car,D)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(F(e,t)){return E}}function ca(e,i){function u(t){if(t instanceof M){if(!i.length){return t}var e=u(t.car);var r=u(t.cdr);return new M(e,r)}else if(t instanceof L){var n=i.find(function(e){return e.gensym===t});if(n){return L(n.name)}return t}else{return t}}return u(e)}function fa(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var O=e.bindings,t=e.expr,S=e.scope,a=e.symbols,f=e.names,B=e.ellipsis;var c={};function o(e){if(e instanceof L){return true}return["string","symbol"].includes(d(e))}function j(e){if(!o(e)){var t=Ds(e);throw new Error("syntax: internal error, need symbol got ".concat(t))}var r=e.valueOf();if(r===B){throw new Error("syntax: internal error, ellipis not transformed")}var n=d(r);if(["string","symbol"].includes(n)){if(r in O.symbols){return O.symbols[r]}else if(n==="string"&&r.match(/\./)){var i=r.split(".");var u=i[0];if(u in O.symbols){return M.fromArray([L("."),O.symbols[u]].concat(i.slice(1).map(function(e){return so(e)})))}}}if(a.includes(r)){return L(r)}return s(r)}function I(e){if(Ln()){console.log(e)}}function s(e){if(!c[e]){var t=S.ref(e);var r=Ri(e);if(t){var n=S.get(e);S.set(r,n)}else{var i=S.get(e,{throwError:false});if(typeof i!=="undefined"){S.set(r,i)}}f.push({name:e,gensym:r});c[e]=r;if(typeof e==="string"&&e.match(/\./)){var u=e.split(".").filter(Boolean),a=A(u),o=a[0],s=a.slice(1);if(c[o]){Va(r,"__object__",[c[o]].concat(C(s)))}}}return c[e]}function P(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:function(){};var i=r.nested;I(" ==> "+e.toString(true));I(t);if(e instanceof L){var u=e.valueOf();I("[t 1");if(t[u]){if(t[u]instanceof M){var c=t[u],f=c.car,l=c.cdr;if(i){var h=f.car,p=f.cdr;if(p!==U){n(u,new M(p,U))}return h}if(l!==U){n(u,l)}return f}else if(t[u]instanceof Array){n(u,t[u].slice(1));return t[u][0]}}return j(u)}if(e instanceof M){if(e.car instanceof L&&e.cdr instanceof M&&L.is(e.cdr.car,B)){I("[t 2");var a=e.car.valueOf();var o=t[a];I({expr:e.toString(true),name:a,bindings:t,item:o});if(o===null){return}else if(o){I({b:t[a].toString()});if(o instanceof M){I("[t 2 Pair "+i);I({______:o.toString()});var s=o.car,_=o.cdr;if(i){if(_!==U){I("|| next 1");n(a,_)}I({car:s.toString()});return s}else{if(s.cdr!==U){I("|| next 2");n(a,new M(s.cdr,_))}I({car:s.car.toString()});return s.car}}else if(o instanceof Array){I("[t 2 Array "+i);if(i){n(a,o.slice(1));return M.fromArray(o)}else{var d=o.slice(1);if(d.length){n(a,d)}return o[0]}}else{return o}}}I("[t 3 recur "+e.toString());var v=P(e.car,t,r,n);var y=P(e.cdr,t,r,n);return new M(v,y)}return e}function R(t,r){var e=Object.values(t);var n=Object.getOwnPropertySymbols(t);if(n.length){e.push.apply(e,C(n.map(function(e){return t[e]})))}return e.length&&e.every(function(e){if(e===null){return!r}return e instanceof M||e===U||e instanceof Array&&e.length})}function T(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function N(i){var n=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},e=n.disabled;I("traverse>> "+Ku(i));if(i instanceof M){if(!e&&i.car instanceof M&&L.is(i.car.car,B)){return N(i.car.cdr,{disabled:true})}if(i.cdr instanceof M&&L.is(i.cdr.car,B)&&!e){I(">> 1");var t=O["..."].symbols;var f=Object.values(t);if(f.length&&f.every(function(e){return e===null})){return N(i.cdr.cdr,{disabled:e})}var l=T(t);var u=i.car instanceof L&&L.is(i.cdr.cdr.car,B);if(i.car instanceof M||u){if(O["..."].lists[0]===U){return U}var h=i.car;if(u){h=new M(i.car,new M(i.cdr.car,U))}I(">> 2");var a;if(l.length){I(">> 2 (a)");var o=Fn({},t);a=U;var p=function e(){if(!R(o)){return"break"}var n={};var t=function e(t,r){n[t]=r};var r=P(h,o,{nested:true},t);if(r!==undefined){if(u){if(a===U){a=r}else{a=a.append(r)}}else{a=new M(r,a)}}o=n};while(true){var _=p();if(_==="break")break}if(a!==U&&!u){a=a.reverse()}if(i.cdr.cdr!==U&&!L.is(i.cdr.cdr.car,B)){var d=N(i.cdr.cdr,{disabled:e});return a.append(d)}return a}else{I(">> 3");var v=P(i.car,t,{nested:true});if(v){return new M(v,U)}return U}}else if(i.car instanceof L){I(">> 4");if(L.is(i.cdr.cdr.car,B)){I(">> 4 (a)")}else{I(">> 4 (b)")}var y=i.car.__name__;var s=q({},y,t[y]);var m=t[y]===null;var c=U;var g=function e(){if(!R(s,true)){I({bind:s});return"break"}var n={};var t=function e(t,r){n[t]=r};var r=P(i,s,{nested:false},t);I({value:r.toString()});if(typeof r!=="undefined"){c=new M(r,c)}s=n};while(true){var b=g();if(b==="break")break}if(c!==U){c=c.reverse()}if(i.cdr instanceof M){if(i.cdr.cdr instanceof M||i.cdr.cdr instanceof L){var w=N(i.cdr.cdr,{disabled:e});if(m){return w}I("<<<< 1");c.append(w)}}I("<<<< 2");return c}}var D=N(i.car,{disabled:e});var r;var E;if(i.car instanceof L){var A=S.get(i.car,{throwError:false});E=A instanceof ra&&A.__name__==="syntax-rules"}if(E){if(i.cdr.car instanceof L){r=new M(N(i.cdr.car,{disabled:e}),new M(i.cdr.cdr.car,N(i.cdr.cdr.cdr,{disabled:e})))}else{r=new M(i.cdr.car,N(i.cdr.cdr,{disabled:e}))}I("REST >>>> "+r.toString())}else{r=N(i.cdr,{disabled:e})}I({a:true,car:Ku(i.car),cdr:Ku(i.cdr),head:Ku(D),rest:Ku(r)});return new M(D,r)}if(i instanceof L){if(e&&L.is(i,B)){return i}var x=Object.keys(O["..."].symbols);var F=i.literal();if(x.includes(F)){var k="missing ellipsis symbol next to name `".concat(F,"'");throw new Error("syntax-rules: ".concat(k))}var C=j(i);if(typeof C!=="undefined"){return C}}return i}return N(t,{})}function la(e){return ba(e)||e===U||e===null}function ha(e){return typeof e==="function"&&typeof e.bind==="function"}function pa(e){return e instanceof Ps}function _a(e){return e instanceof js}function da(e){return e instanceof Bs}function va(e){return e instanceof M}function ya(e){return e instanceof Ko}function ma(e){return ha(e)||pa(e)||da(e)}function ga(e){if(e instanceof Ti){return false}if(e instanceof Promise){return true}return e&&ha(e.then)}function ba(e){return typeof e==="undefined"}function wa(e){switch(d(e)){case"string":return so(e);case"bigint":return y(e);case"number":if(Number.isNaN(e)){return rs}else{return y(e)}}return e}function Da(n,i){var e=Object.getOwnPropertyNames(n);var t=Object.getOwnPropertySymbols(n);e.concat(t).forEach(function(e){var t=i(n[e]);var r=Object.getOwnPropertyDescriptor(n,e);if(!r||r.writable&&n[e]!==t){n[e]=t}});return n}function Ea(t){var e=[so,y].some(function(e){return t instanceof e});if(e){return t.valueOf()}if(t instanceof Array){return t.map(Ea)}if(t instanceof Ti){delete t.then}if(Pu(t)){return Da(t,Ea)}return t}function Aa(e,t){if(e instanceof M){e.markCycles();return Wo(e)}if(ha(e)){if(t){return Fa(e,t)}}return wa(e)}function xa(e){if(Ca(e)){return e[Ia]}return e}function Fa(e,t){if(e[Symbol["for"]("__bound__")]){return e}var r=e.bind(t);var n=Object.getOwnPropertyNames(e);var i=Dn(n),u;try{for(i.s();!(u=i.n()).done;){var a=u.value;if(Ya(a)){try{r[a]=e[a]}catch(e){}}}}catch(e){i.e(e)}finally{i.f()}Va(r,"__fn__",e);Va(r,"__context__",t);Va(r,"__bound__",true);if(Ga(e)){Va(r,"__native__",true)}if(Pu(t)&&$a(e)){Va(r,"__method__",true)}r.valueOf=function(){return e};return r}function ka(e){return Ca(e)&&e[Symbol["for"]("__context__")]===Object}function Ca(e){return!!(ha(e)&&e[Ia])}function Oa(e){if(ha(e)){var t=e[ja];if(t&&(t===vc||t.constructor&&t.constructor.__class__)){return true}}return false}function Sa(e){return e instanceof So||e instanceof Bo}function Ba(e){if(ha(e)){if(Sa(e[ja])){return true}}return false}var ja=Symbol["for"]("__context__");var Ia=Symbol["for"]("__fn__");var Pa=Symbol["for"]("__data__");var Na=Symbol["for"]("__ref__");var Ra=Symbol["for"]("__cycles__");var Ta=Symbol["for"]("__class__");var La=Symbol["for"]("__method__");var Ua=Symbol["for"]("__prototype__");var Ma=Symbol["for"]("__lambda__");var qa=["name","length","caller","callee","arguments","prototype"];function Ya(e){return!qa.includes(e)}function Va(e,t,r){Object.defineProperty(e,Symbol["for"](t),{get:function e(){return r},set:function e(){},configurable:false,enumerable:false})}function za(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 $a(e){return e&&e[Ma]}function Ja(e){return e&&e[La]}function Ka(e){return $a(e)&&!e[Ua]&&!Ja(e)&&!Ba(e)}function Ga(e){var t=Symbol["for"]("__native__");return ha(e)&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[t]===true||!e.name.match(/^bound /)&&!e[t])}function Ha(e){var b;switch(e){case Symbol["for"]("letrec"):b="letrec";break;case Symbol["for"]("let"):b="let";break;case Symbol["for"]("let*"):b="let*";break;default:throw new Error("Invalid let_macro value")}return ra.defmacro(b,function(t,e){var f=e.dynamic_env;var l=e.error,n=e.macro_expand,y=e.use_dynamic;var h;if(t.car instanceof L){if(!(t.cdr.car instanceof M||t.cdr.car===U)){throw new Error("let require list of pairs")}var r;if(t.cdr.car===U){h=U;r=U}else{r=t.cdr.car.map(function(e){return e.car});h=t.cdr.car.map(function(e){return e.cdr.car})}return M.fromArray([L("letrec"),[[t.car,M(L("lambda"),M(r,t.cdr.cdr))]],M(t.car,h)])}else if(n){return}var p=this;h=is.get("list->array")(t.car);var _=p.inherit(b);var d,v;if(b==="let*"){v=_}else if(b==="let"){d=[]}var m=0;function g(){var e=new M(new L("begin"),t.cdr);return Rs(e,{env:_,dynamic_env:_,use_dynamic:y,error:l})}return function t(){var r=h[m++];f=b==="let*"?_:p;if(!r){if(d&&d.length){var e=d.map(function(e){return e.value});var n=e.filter(ga);if(n.length){return Li(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(o instanceof M){a.push(Rs(o.car,{env:i,dynamic_env:u,use_dynamic:r,error:n}));o=o.cdr}var s=a.filter(ga).length;if(s){return Li(a).then(c.bind(this))}else{return c.call(this,a)}})}function Qa(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 ao(n,i){h("limit",i,"function",2);return function(){for(var e=arguments.length,t=new Array(e),r=0;r1){e=e.toLowerCase();if(oo.__names__[e]){t=e;e=oo.__names__[e]}else{throw new Error("Internal: Unknown named character")}}else{t=oo.__rev_names__[e]}Object.defineProperty(this,"__char__",{value:e,enumerable:true});if(t){Object.defineProperty(this,"__name__",{value:t,enumerable:true})}}oo.__names__=Hn;oo.__rev_names__={};Object.keys(oo.__names__).forEach(function(e){var t=oo.__names__[e];oo.__rev_names__[t]=e});oo.prototype.toUpperCase=function(){return oo(this.__char__.toUpperCase())};oo.prototype.toLowerCase=function(){return oo(this.__char__.toLowerCase())};oo.prototype.toString=function(){return"#\\"+(this.__name__||this.__char__)};oo.prototype.valueOf=oo.prototype.serialize=function(){return this.__char__};function so(e){if(typeof this!=="undefined"&&!(this instanceof so)||typeof this==="undefined"){return new so(e)}if(e instanceof Array){this.__string__=e.map(function(e,t){h("LString",e,"character",t+1);return e.toString()}).join("")}else{this.__string__=e.valueOf()}}{var co=["length","constructor"];var fo=Object.getOwnPropertyNames(String.prototype).filter(function(e){return!co.includes(e)});var lo=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 y){return e}if(typeof this!=="undefined"&&!(this instanceof y)||typeof this==="undefined"){return new y(e,t)}if(typeof e==="undefined"){throw new Error("Invalid LNumber constructor call")}var r=y.getType(e);if(y.types[r]){return y.types[r](e,t)}var n=e instanceof Array&&so.isString(e[0])&&y.isNumber(e[1]);if(e instanceof y){return y(e.value)}if(!y.isNumber(e)&&!n){throw new Error("You can't create LNumber from ".concat(Ds(e)))}if(e===null){e=0}var i;if(n){var c=e,u=Y(c,2),a=u[0],o=u[1];if(a instanceof so){a=a.valueOf()}if(o instanceof y){o=o.valueOf()}var f=a.match(/^([+-])/);var l=false;if(f){a=a.replace(/^[+-]/,"");if(f[1]==="-"){l=true}}}if(Number.isNaN(e)){return Eo(e)}else if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(n){var s;switch(o){case 8:s="0o";break;case 16:s="0x";break;case 2:s="0b";break;case 10:s="";break}if(typeof s==="undefined"){var h=BigInt(o);i=C(a).map(function(e,t){return BigInt(parseInt(e,o))*bo(h,BigInt(t))}).reduce(function(e,t){return e+t})}else{i=BigInt(s+a)}}else{i=BigInt(e)}if(l){i*=BigInt(-1)}}else{i=e}return Oo(i,true)}else if(typeof Nn!=="undefined"&&!(e instanceof Nn)){if(e instanceof Array){return Oo(p(Nn,C(e)))}return Oo(new Nn(e))}else if(n){this.constant(parseInt(a,o),"integer")}else{this.constant(e,"integer")}}y.prototype.constant=function(e,t){Object.defineProperty(this,"__value__",{value:e,enumerable:true});Object.defineProperty(this,"__type__",{value:t,enumerable:true})};y.types={float:function e(t){return new Eo(t)},complex:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!y.isComplex(t)){t={im:0,re:t}}return new Do(t,r)},rational:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!y.isRational(t)){t={num:t,denom:1}}return new Co(t,r)}};y.prototype.serialize=function(){return this.__value__};y.prototype.isNaN=function(){return Number.isNaN(this.__value__)};y.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}}};y.isFloat=function e(t){return t instanceof Eo||Number(t)===t&&t%1!==0};y.isNumber=function(e){return e instanceof y||y.isNative(e)||y.isBN(e)};y.isComplex=function(e){if(!e){return false}var t=e instanceof Do||(y.isNumber(e.im)||Number.isNaN(e.im))&&(y.isNumber(e.re)||Number.isNaN(e.re));return t};y.isRational=function(e){if(!e){return false}return e instanceof Co||y.isNumber(e.num)&&y.isNumber(e.denom)};y.isInteger=function(e){if(!(y.isNative(e)||e instanceof y)){return false}if(y.isFloat(e)){return false}if(y.isRational(e)){return false}if(y.isComplex(e)){return false}return true};y.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};y.isBigInteger=function(e){return e instanceof Oo||typeof e==="bigint"||y.isBN(e)};y.isBN=function(e){return typeof Nn!=="undefined"&&e instanceof Nn};y.getArgsType=function(e,t){if(e instanceof Eo||t instanceof Eo){return Eo}if(e instanceof Oo||t instanceof Oo){return Oo}return y};y.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()};y.prototype.asType=function(e){var t=y.getType(this);return y.types[t]?y.types[t](e):y(e)};y.prototype.isBigNumber=function(){return typeof this.__value__==="bigint"||typeof Nn!=="undefined"&&!(this.value instanceof Nn)};["floor","ceil","round"].forEach(function(e){y.prototype[e]=function(){if(this["float"]||y.isFloat(this.__value__)){return y(Math[e](this.__value__))}else{return y(Math[e](this.valueOf()))}}});y.prototype.valueOf=function(){if(y.isNative(this.__value__)){return Number(this.__value__)}else if(y.isBN(this.__value__)){return this.__value__.toNumber()}};var vo=function(){var e=function e(t,r){return[t,r]};return{bigint:{bigint:e,float:function e(t,r){return[Eo(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[Eo(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&&Eo(r.valueOf())]},integer:function e(t,r){return[t,r&&Eo(r.valueOf())]},float:e,rational:function e(t,r){return[t,r&&Eo(r.valueOf())]},complex:function e(t,r){return[{re:t,im:Eo(0)},r]}},complex:{bigint:t("bigint"),integer:t("integer"),float:t("float"),rational:t("rational"),complex:function f(e,t){var r=y.coerce(e.__re__,t.__re__),n=Y(r,2),i=n[0],u=n[1];var a=y.coerce(e.__im__,t.__im__),o=Y(a,2),s=o[0],c=o[1];return[{im:s,re:i},{im:c,re:u}]}},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[Eo(t.valueOf()),r]},rational:e,complex:function e(t,r){return[{im:yo(t.__type__,r.__im__.__type__,0)[0],re:yo(t.__type__,r.__re__.__type__,t)[0]},{im:yo(t.__type__,r.__im__.__type__,r.__im__)[0],re:yo(t.__type__,r.__re__.__type__,r.__re__)[0]}]}}};function t(r){return function(e,t){return[{im:yo(r,e.__im__.__type__,0,e.__im__)[1],re:yo(r,e.__re__.__type__,0,e.__re__)[1]},{im:yo(r,e.__im__.__type__,0,0)[1],re:yo(r,t.__type__,0,t)[1]}]}}}();function yo(e,t,r,n){return vo[e][t](r,n)}y.coerce=function(e,t){var r=y.getType(e);var n=y.getType(t);if(!vo[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!vo[r][n]){throw new Error("LNumber::coerce unknown rhs type ".concat(n))}var i=vo[r][n](e,t);return i.map(function(e){return y(e,true)})};y.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof y)){throw new Error("LNumber: you can't coerce ".concat(Ds(e)))}if(typeof e==="number"){e=y(e)}return y.coerce(this,e)};y.getType=function(e){if(e instanceof y){return e.__type__}if(y.isFloat(e)){return"float"}if(y.isComplex(e)){return"complex"}if(y.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof Nn!=="undefined"&&!(e instanceof Nn)){return"bigint"}};y.prototype.isFloat=function(){return!!(y.isFloat(this.__value__)||this["float"])};var mo={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var go={};Object.keys(mo).forEach(function(t){go[mo[t]]=t;y.prototype[t]=function(e){return this.op(mo[t],e)}});y._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 Do)||typeof this==="undefined"){return new Do(e,t)}if(e instanceof Do){return Do({im:e.__im__,re:e.__re__})}if(y.isNumber(e)&&t){if(!t){return Number(e)}}else if(!y.isComplex(e)){var r="Invalid constructor call for LComplex expect &(:im :re ) object but got ".concat(Ku(e));throw new Error(r)}var n=e.im instanceof y?e.im:y(e.im);var i=e.re instanceof y?e.re:y(e.re);this.constant(n,i)}Do.prototype=Object.create(y.prototype);Do.prototype.constructor=Do;Do.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})};Do.prototype.serialize=function(){return{re:this.__re__,im:this.__im__}};Do.prototype.toRational=function(e){if(y.isFloat(this.__im__)&&y.isFloat(this.__re__)){var t=Eo(this.__im__).toRational(e);var r=Eo(this.__re__).toRational(e);return Do({im:t,re:r})}return this};Do.prototype.pow=function(e){throw new Error("Not yet implemented")};Do.prototype.add=function(e){return this.complex_op("add",e,function(e,t,r,n){return{re:e.add(t),im:r.add(n)}})};Do.prototype.factor=function(){if(this.__im__ instanceof Eo||this.__im__ instanceof Eo){var e=this.__re__,t=this.__im__;var r,n;if(e instanceof Eo){r=e.toRational().mul(e.toRational())}else{r=e.mul(e)}if(t instanceof Eo){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__))}};Do.prototype.modulus=function(){return this.factor().sqrt()};Do.prototype.conjugate=function(){return Do({re:this.__re__,im:this.__im__.sub()})};Do.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=Eo(.5).mul(e.add(this.__re__)).sqrt();r=this.__im__.div(t).div(2)}else{r=Eo(.5).mul(e.sub(this.__re__)).sqrt();if(this.__im__.cmp(0)===-1){r=r.sub()}t=this.__im__.div(r).div(2)}return Do({im:r,re:t})};Do.prototype.div=function(e){if(y.isNumber(e)&&!y.isComplex(e)){if(!(e instanceof y)){e=y(e)}var t=this.__re__.div(e);var r=this.__im__.div(e);return Do({re:t,im:r})}else if(!y.isComplex(e)){throw new Error("[LComplex::div] Invalid value")}if(this.cmp(e)===0){var n=this.coerce(e),i=Y(n,2),f=i[0],u=i[1];var l=f.__im__.div(u.__im__);return l.coerce(u.__re__)[0]}var h=this.coerce(e),a=Y(h,2),p=a[0],o=a[1];var s=o.factor();var _=o.conjugate();var c=p.mul(_);if(!y.isComplex(c)){return c.div(s)}var d=c.__re__.op("/",s);var v=c.__im__.op("/",s);return Do({re:d,im:v})};Do.prototype.sub=function(e){return this.complex_op("sub",e,function(e,t,r,n){return{re:e.sub(t),im:r.sub(n)}})};Do.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})};Do.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 Do(n,true)}return n};if(typeof t==="undefined"){return r()}if(y.isNumber(t)&&!y.isComplex(t)){if(!(t instanceof y)){t=y(t)}var n=t.asType(0);t={__im__:n,__re__:t}}else if(!y.isComplex(t)){throw new Error("[LComplex::".concat(e,"] Invalid value"))}var a=t.__re__ instanceof y?t.__re__:this.__re__.asType(t.__re__);var o=t.__im__ instanceof y?t.__im__:this.__im__.asType(t.__im__);return r(a,o)};Do._op={"+":"add","-":"sub","*":"mul","/":"div"};Do.prototype._op=function(e,t){var r=Do._op[e];return this[r](t)};Do.prototype.cmp=function(e){var t=this.coerce(e),r=Y(t,2),n=r[0],i=r[1];var u=n.__re__.coerce(i.__re__),a=Y(u,2),o=a[0],f=a[1];var s=o.cmp(f);if(s!==0){return s}else{var l=n.__im__.coerce(i.__im__),c=Y(l,2),h=c[0],p=c[1];return h.cmp(p)}};Do.prototype.valueOf=function(){return[this.__re__,this.__im__].map(function(e){return e.valueOf()})};Do.prototype.toString=function(){var e;if(this.__re__.cmp(0)!==0){e=[Ku(this.__re__)]}else{e=[]}var t=this.__im__.valueOf();var r=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY].includes(t);var n=Ku(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 Eo(e){if(typeof this!=="undefined"&&!(this instanceof Eo)||typeof this==="undefined"){return new Eo(e)}if(!y.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof y){return Eo(e.valueOf())}if(typeof e==="number"){if(Object.is(e,-0)){Object.defineProperty(this,"_minus",{value:true})}this.constant(e,"float")}}Eo.prototype=Object.create(y.prototype);Eo.prototype.constructor=Eo;Eo.prototype.toString=function(){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"}var e=this.__value__.toString();if(!y.isFloat(this.__value__)&&!e.match(/e/i)){var t=e+".0";return this._minus?"-"+t:t}return e.replace(/^([0-9]+)e/,"$1.0e")};Eo.prototype._op=function(e,t){if(t instanceof y){t=t.__value__}var r=y._ops[e];if(e==="/"&&this.__value__===0&&t===0){return NaN}return Eo(r(this.__value__,t))};Eo.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){return Ao(this.__value__.valueOf())}return xo(e.valueOf())(this.__value__.valueOf())};Eo.prototype.sqrt=function(){var e=this.valueOf();if(this.cmp(0)<0){var t=Eo(Math.sqrt(-e));return Do({re:0,im:t})}return Eo(Math.sqrt(e))};Eo.prototype.abs=function(){var e=this.valueOf();if(e<0){e=-e}return Eo(e)};var Ao=xo(1e-10);function xo(n){return function(e){var t=function e(n,t,r){var i=function e(t,r){return r0){i=ko(n,r)}else if(n.cmp(r)<=0){i=r}else if(r.cmp(0)>0){i=ko(r,n)}else if(t.cmp(0)<0){i=y(ko(n.sub(),r.sub())).sub()}else{i=y(0)}if(y.isFloat(t)||y.isFloat(e)){return Eo(i)}return i}function ko(e,t){var r=y(e).floor();var n=y(t).floor();if(e.cmp(r)<1){return r}else if(r.cmp(n)===0){var i=y(1).div(t.sub(n));var u=y(1).div(e.sub(r));return r.add(y(1).div(ko(i,u)))}else{return r.add(y(1))}}function Co(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof Co)||typeof this==="undefined"){return new Co(e,t)}if(!y.isRational(e)){throw new Error("Invalid constructor call for LRational")}var r,n;if(e instanceof Co){r=y(e.__num__);n=y(e.__denom__)}else{r=y(e.num);n=y(e.denom)}if(!t&&n.cmp(0)!==0){var i=r.op("%",n).cmp(0)===0;if(i){return y(r.div(n))}}this.constant(r,n)}Co.prototype=Object.create(y.prototype);Co.prototype.constructor=Co;Co.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})};Co.prototype.serialize=function(){return{num:this.__num__,denom:this.__denom__}};Co.prototype.pow=function(e){var t=e.cmp(0);if(t===0){return y(1)}if(t===-1){e=e.sub();var r=this.__denom__.pow(e);var n=this.__num__.pow(e);return Co({num:r,denom:n})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};Co.prototype.sqrt=function(){var e=this.__num__.sqrt();var t=this.__denom__.sqrt();if(e instanceof Eo||t instanceof Eo){return e.div(t)}return Co({num:e,denom:t})};Co.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 Co({num:e,denom:t})};Co.prototype.cmp=function(e){return y(this.valueOf(),true).cmp(e)};Co.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 Co){t=y(t.valueOf(true))}r=this.__denom__.div(e);if(r instanceof Co){r=y(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()};Co.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 y._ops["/"](this.__num__.value,this.__denom__.value)}return Eo(this.__num__.valueOf()).div(this.__denom__.valueOf())};Co.prototype.mul=function(e){if(!(e instanceof y)){e=y(e)}if(y.isRational(e)){var t=this.__num__.mul(e.__num__);var r=this.__denom__.mul(e.__denom__);return Co({num:t,denom:r})}var n=y.coerce(this,e),i=Y(n,2),u=i[0],a=i[1];return u.mul(a)};Co.prototype.div=function(e){if(!(e instanceof y)){e=y(e)}if(y.isRational(e)){var t=this.__num__.mul(e.__denom__);var r=this.__denom__.mul(e.__num__);return Co({num:t,denom:r})}var n=y.coerce(this,e),i=Y(n,2),u=i[0],a=i[1];var o=u.div(a);return o};Co.prototype._op=function(e,t){return this[go[e]](t)};Co.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof y)){e=y(e)}if(y.isRational(e)){var t=e.__num__.sub();var r=e.__denom__;return this.add(Co({num:t,denom:r}))}if(!(e instanceof y)){e=y(e).sub()}else{e=e.sub()}var n=y.coerce(this,e),i=Y(n,2),u=i[0],a=i[1];return u.add(a)};Co.prototype.add=function(e){if(!(e instanceof y)){e=y(e)}if(y.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 Co({num:a,denom:u})}if(y.isFloat(e)){return Eo(this.valueOf()).add(e)}var o=y.coerce(this,e),s=Y(o,2),c=s[0],f=s[1];return c.add(f)};function Oo(e,t){if(typeof this!=="undefined"&&!(this instanceof Oo)||typeof this==="undefined"){return new Oo(e,t)}if(e instanceof Oo){return Oo(e.__value__,e._native)}if(!y.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.constant(e,"bigint");Object.defineProperty(this,"_native",{value:t})}Oo.prototype=Object.create(y.prototype);Oo.prototype.constructor=Oo;Oo.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};Oo.prototype.serialize=function(){return this.__value__.toString()};Oo.prototype._op=function(e,t){if(typeof t==="undefined"){if(y.isBN(this.__value__)){e=Oo.bn_op[e];return Oo(this.__value__.clone()[e](),false)}return Oo(y._ops[e](this.__value__),true)}if(y.isBN(this.__value__)&&y.isBN(t.__value__)){e=Oo.bn_op[e];return Oo(this.__value__.clone()[e](t),false)}var r=y._ops[e](this.__value__,t.__value__);if(e==="/"){var n=this.op("%",t).cmp(0)===0;if(n){return y(r)}return Co({num:this,denom:t})}return Oo(r,true)};Oo.prototype.sqrt=function(){var e;var t=this.cmp(0)<0;if(y.isNative(this.__value__)){e=y(Math.sqrt(t?-this.valueOf():this.valueOf()))}else if(y.isBN(this.__value__)){e=t?this.__value__.neg().sqrt():this.__value__.sqrt()}if(t){return Do({re:0,im:e})}return e};y.NaN=y(NaN);function So(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof So)||typeof this==="undefined"){return new So(e)}h("InputPort",e,"function");nu(this,"__type__",Yo);var i;Object.defineProperty(this,"__parser__",{enumerable:true,get:function e(){return i},set:function e(t){h("InputPort::__parser__",t,"parser");i=t}});this._read=e;this._with_parser=this._with_init_parser.bind(this,B(H.mark(function e(){var r;return H.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 Wi(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()!==Vo};this._make_defaults()}So.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(!y.isInteger(t)){var r=y.getType(t);_s("read-string",r,"integer")}return e.__lexer__.read_string(t.valueOf())});this.peek_char=this._with_parser(function(e){return e.__lexer__.peek_char()})};So.prototype._with_init_parser=function(o,s){var c=this;return B(H.mark(function e(){var r,n,i,u,a=arguments;return H.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 Bo(e){if(typeof this!=="undefined"&&!(this instanceof Bo)||typeof this==="undefined"){return new Bo(e)}h("OutputPort",e,"function");nu(this,"__type__",Yo);this.write=e}Bo.prototype.is_open=function(){return this._closed!==true};Bo.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")}};Bo.prototype.flush=function(){};Bo.prototype.toString=function(){return"#"};var jo=function(e){_(n,e);var r=bn(n);function n(e){var t;j(this,n);t=r.call(this,function(){var e;return(e=t)._write.apply(e,arguments)});h("BufferedOutputPort",e,"function");nu(o(t),"_fn",e,{hidden:true});nu(o(t),"_buffer",[],{hidden:true});return t}P(n,[{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"};Io.prototype.valueOf=function(){return this.__buffer__.map(function(e){return e.valueOf()}).join("")};function Po(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof Po)||typeof this==="undefined"){return new Po(e,t)}h("OutputFilePort",e,"string");nu(this,"__filename__",e);nu(this,"_fd",t.valueOf(),{hidden:true});nu(this,"__type__",Yo);this.write=function(e){if(!so.isString(e)){e=Ku(e)}else{e=e.valueOf()}r.fs().write(r._fd,e,function(e){if(e){throw e}})}}Po.prototype=Object.create(Bo.prototype);Po.prototype.constructor=Po;Po.prototype.fs=function(){if(!this._fs){this._fs=this.internal("fs")}return this._fs};Po.prototype.internal=function(e){return us.get("**internal-env**").get(e)};Po.prototype.close=function(){var n=this;return new Promise(function(t,r){n.fs().close(n._fd,function(e){if(e){r(e)}else{nu(n,"_fd",null,{hidden:true});Bo.prototype.close.call(n);t()}})})};Po.prototype.toString=function(){return"#")};function No(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof No)||typeof this==="undefined"){return new No(e)}h("InputStringPort",e,"string");t=t||is;e=e.valueOf();this._with_parser=this._with_init_parser.bind(this,function(){if(!r.__parser__){r.__parser__=new Wi(e,{env:t})}return r.__parser__});nu(this,"__type__",Yo);this._make_defaults()}No.prototype.char_ready=function(){return true};No.prototype=Object.create(So.prototype);No.prototype.constructor=No;No.prototype.toString=function(){return"#"};function Ro(e){if(typeof this!=="undefined"&&!(this instanceof Ro)||typeof this==="undefined"){return new Ro(e)}h("InputByteVectorPort",e,"uint8array");nu(this,"__vector__",e);nu(this,"__type__",qo);var r=0;Object.defineProperty(this,"__index__",{enumerable:true,get:function e(){return r},set:function e(t){h("InputByteVectorPort::__index__",t,"number");if(t instanceof y){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}})}Ro.prototype=Object.create(So.prototype);Ro.prototype.constructor=Ro;Ro.prototype.toString=function(){return"#"};Ro.prototype.close=function(){var t=this;nu(this,"__vector__",U);["read_u8","close","peek_u8","read_u8_vector"].forEach(function(e){t[e]=function(){throw new Error("Input-binary-port: port is closed")}});this.char_ready=function(){return false}};Ro.prototype.u8_ready=function(){return true};Ro.prototype.peek_u8=function(){if(this.__index__>=this.__vector__.length){return Vo}return this.__vector__[this.__index__]};Ro.prototype.skip=function(){if(this.__index__<=this.__vector__.length){++this.__index__}};Ro.prototype.read_u8=function(){var e=this.peek_u8();this.skip();return e};Ro.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()===Vo){return Vo}return this.__vector__.slice(this.__index__,e)};function To(){if(typeof this!=="undefined"&&!(this instanceof To)||typeof this==="undefined"){return new To}nu(this,"__type__",qo);nu(this,"_buffer",[],{hidden:true});this.write=function(e){h("write",e,["number","uint8array"]);if(y.isNumber(e)){this._buffer.push(e.valueOf())}else{var t;(t=this._buffer).push.apply(t,C(Array.from(e)))}};Object.defineProperty(this,"__buffer__",{enumerable:true,get:function e(){return Uint8Array.from(this._buffer)}})}To.prototype=Object.create(Bo.prototype);To.prototype.constructor=To;To.prototype.close=function(){Bo.prototype.close.call(this);nu(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){h("OutputByteVectorPort::write_u8",e,"number");this.write(e)};To.prototype.write_u8_vector=function(e){h("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};To.prototype.toString=function(){return"#"};To.prototype.valueOf=function(){return this.__buffer__};function Lo(e,t){if(typeof this!=="undefined"&&!(this instanceof Lo)||typeof this==="undefined"){return new Lo(e,t)}No.call(this,e);h("InputFilePort",t,"string");nu(this,"__filename__",t)}Lo.prototype=Object.create(No.prototype);Lo.prototype.constructor=Lo;Lo.prototype.toString=function(){return"#")};function Uo(e,t){if(typeof this!=="undefined"&&!(this instanceof Uo)||typeof this==="undefined"){return new Uo(e,t)}Ro.call(this,e);h("InputBinaryFilePort",t,"string");nu(this,"__filename__",t)}Uo.prototype=Object.create(Ro.prototype);Uo.prototype.constructor=Uo;Uo.prototype.toString=function(){return"#")};function Mo(e,t){if(typeof this!=="undefined"&&!(this instanceof Mo)||typeof this==="undefined"){return new Mo(e,t)}h("OutputBinaryFilePort",e,"string");nu(this,"__filename__",e);nu(this,"_fd",t.valueOf(),{hidden:true});nu(this,"__type__",qo);var u,r;this.write=function(e){var n=this;h("write",e,["number","uint8array"]);var i;if(!u){u=this.internal("fs")}if(!r){r=this.internal("Buffer")}if(y.isNumber(e)){i=r.from([e.valueOf()])}else{i=r.from(Array.from(e))}return new Promise(function(t,r){u.write(n._fd,i,function(e){if(e){r(e)}else{t()}})})}}Mo.prototype=Object.create(Po.prototype);Mo.prototype.constructor=Mo;Mo.prototype.write_u8=function(e){h("OutputByteVectorPort::write_u8",e,"number");this.write(e)};Mo.prototype.write_u8_vector=function(e){h("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};var qo=Symbol["for"]("binary");var Yo=Symbol["for"]("text");var Vo=new zo;function zo(){}zo.prototype.toString=function(){return"#"};function $o(e){var c=this;var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.stderr,n=t.stdin,i=t.stdout,u=t.command_line,a=u===void 0?null:u,o=R(t,_n);if(typeof this!=="undefined"&&!(this instanceof $o)||typeof this==="undefined"){return new $o(e,Fn({stdin:n,stdout:i,stderr:r,command_line:a},o))}if(typeof e==="undefined"){e="anonymous"}this.__env__=us.inherit(e,o);this.__env__.set("parent.frame",l("parent.frame",function(){return c.__env__},is.__env__["parent.frame"].__doc__));var f="**interaction-environment-defaults**";this.set(f,Yu(o).concat(f));var s=ts.inherit("internal-".concat(e));if(Sa(n)){s.set("stdin",n)}if(Sa(r)){s.set("stderr",r)}if(Sa(i)){s.set("stdout",i)}s.set("command-line",a);as(this.__env__,s)}$o.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;h("Interpreter::exec",e,["string","array"],1);h("Interpreter::exec",n,"boolean",2);if(!u){u=this.__env__}if(!i){i=u}is.set("**interaction-environment**",this.__env__);return Ls(e,{env:u,dynamic_env:i,use_dynamic:n})};$o.prototype.get=function(e){var t=this.__env__.get(e);if(ha(t)){return t.bind(this.__env__)}return t};$o.prototype.set=function(e,t){return this.__env__.set(e,t)};$o.prototype.constant=function(e,t){return this.__env__.constant(e,t)};function Jo(e,t){this.name="LipsError";this.message=e;this.args=t;this.stack=(new Error).stack}Jo.prototype=new Error;Jo.prototype.constructor=Jo;function Ko(e,t,r){if(arguments.length===1){if(d(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"}Ko.prototype.list=function(){return Yu(this.__env__)};Ko.prototype.fs=function(){return this.get("**fs**")};Ko.prototype.unset=function(e){if(e instanceof L){e=e.valueOf()}if(e instanceof so){e=e.valueOf()}delete this.__env__[e]};Ko.prototype.inherit=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(d(e)==="object"){t=e}if(!e||d(e)==="object"){e="child of "+(this.__name__||"unknown")}return new Ko(t||{},this,e)};Ko.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 L){e=e.__name__}if(e instanceof so){e=e.valueOf()}if(t){if(!r){t=ou(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)}};Ko.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(!ya(t)){return U}if(e<=0){return t}var r=t.get("parent.frame");return r(e-1)},is.__env__["parent.frame"].__doc__));t.callee=e;n.set("arguments",t);return n};Ko.prototype._lookup=function(e){if(e instanceof L){e=e.__name__}if(e instanceof so){e=e.valueOf()}if(this.__env__.hasOwnProperty(e)){return Go(this.__env__[e])}if(this.__parent__){return this.__parent__._lookup(e)}};Ko.prototype.toString=function(){return"#"};Ko.prototype.clone=function(){var t=this;var r={};Object.keys(this.__env__).forEach(function(e){r[e]=t.__env__[e]});return new Ko(r,this.__parent__,this.__name__)};Ko.prototype.merge=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"merge";h("Environment::merge",e,"environment");return this.inherit(t,e.__env__)};function Go(e){if(typeof this!=="undefined"&&!(this instanceof Go)||typeof this==="undefined"){return new Go(e)}this.value=e}Go.isUndefined=function(e){return e instanceof Go&&typeof e.value==="undefined"};Go.prototype.valueOf=function(){return this.value};function Ho(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof Ho)||typeof this==="undefined"){return new Ho(e)}this.__values__=e}Ho.prototype.toString=function(){return this.__values__.map(function(e){return Ku(e)}).join("\n")};Ho.prototype.valueOf=function(){return this.__values__};Ko.prototype.get=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};h("Environment::get",e,["symbol","string"]);var r=t.throwError,c=r===void 0?true:r;var n=e;if(n instanceof L||n instanceof so){n=n.valueOf()}var i=this._lookup(n);if(i instanceof Go){if(Go.isUndefined(i)){return undefined}return Aa(i.valueOf())}var u;if(e instanceof L&&e[L.object]){u=e[L.object]}else if(typeof n==="string"){u=n.split(".").filter(Boolean)}if(u&&u.length>0){var f=u,a=A(f),o=a[0],s=a.slice(1);i=this._lookup(o);if(s.length){try{if(i instanceof Go){i=i.valueOf()}else{i=Zo(On,o);if(ha(i)){i=xa(i)}}if(typeof i!=="undefined"){return Zo.apply(void 0,[i].concat(C(s)))}}catch(e){throw e}}else if(i instanceof Go){return Aa(i.valueOf())}i=Zo(On,n)}if(typeof i!=="undefined"){return i}if(c){throw new Error("Unbound variable `"+n.toString()+"'")}};Ko.prototype.set=function(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;h("Environment::set",e,["string","symbol"]);if(y.isNumber(t)){t=y(t)}if(e instanceof L){e=e.__name__}if(e instanceof so){e=e.valueOf()}this.__env__[e]=t;if(r){this.doc(e,r,true)}return this};Ko.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&&Pu(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};Ko.prototype.has=function(e){return this.__env__.hasOwnProperty(e)};Ko.prototype.ref=function(e){var t=this;while(true){if(!t){break}if(t.has(e)){return t}t=t.__parent__}};Ko.prototype.parents=function(){var e=this;var t=[];while(e){t.unshift(e);e=e.__parent__}return t};function Wo(e){if(ga(e)){return e.then(Wo)}if(e instanceof M||e instanceof L){e[Pa]=true}return e}var Qo=Zi(Bi('(lambda ()\n "[native code]"\n (throw "Invalid Invocation"))'))[0];var Zo=l("get",function c(e){var t;for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=Xo(this,"stdin")}vs("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=Xo(this,"stdin")}vs("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=Xo(this,"stdin")}vs("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=B(H.mark(function e(){var r,n,i,u,a,o,s,c,f,l=arguments;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:r=l.length>0&&l[0]!==undefined?l[0]:null;n=this.env;if(!so.isString(r)){t.next=31;break}i=false;u=false;t.prev=5;o=kn(Zi(r,n));case 7:t.next=9;return o.next();case 9:if(!(i=!(s=t.sent).done)){t.next=15;break}c=s.value;return t.abrupt("return",c);case 12:i=false;t.next=7;break;case 15:t.next=21;break;case 17:t.prev=17;t.t0=t["catch"](5);u=true;a=t.t0;case 21:t.prev=21;t.prev=22;if(!(i&&o["return"]!=null)){t.next=26;break}t.next=26;return o["return"]();case 26:t.prev=26;if(!u){t.next=29;break}throw a;case 29:return t.finish(26);case 30:return t.finish(21);case 31:if(r===null){f=Xo(n,"stdin")}else{f=r}vs("read",f,"input-port");return t.abrupt("return",f.read.call(n));case 34:case"end":return t.stop()}}},e,this,[[5,17,21,31],[22,,26,30]])}));function t(){return e.apply(this,arguments)}return t}(),"(read [string])\n\n This function, if used with a string, will parse it and\n return the LIPS code, if there is any. If called with a\n port, it will parse the next item from the port. If called\n without an input, it will read a string from standard input\n (using the browser's prompt or a user defined input method)\n and calls itself with that string. This function can be used\n together with `eval` to evaluate code from a string."),pprint:l("pprint",function e(t){if(t instanceof M){t=new vc.Formatter(t.toString(true))["break"]().format();is.get("display").call(is,t)}else{is.get("write").call(is,t)}is.get("newline").call(is)},"(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=is.get("display");var r=is.get("newline");var n=this.use_dynamic;var i=is;var u=is;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=is.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=Xo(this,"stdout")}else{h("display",r,"output-port")}var n=is.get("repr")(t);r.write.call(is,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=Xo(this,"stderr");var r=is.get("repr");for(var n=arguments.length,i=new Array(n),u=0;u1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,f=R(t,dn);var n=this;var i=this;var u;var l=Fn(Fn({},f),{},{env:this,dynamic_env:n,use_dynamic:r});var a=Rs(e.cdr.car,l);a=Es(a);function o(t,r,n){if(ga(t)){return t.then(function(e){return o(t,e,n)})}if(ga(r)){return r.then(function(e){return o(t,e,n)})}if(ga(n)){return n.then(function(e){return o(t,r,e)})}i.get("set-obj!").call(i,t,r,n);return n}if(e.car instanceof M&&L.is(e.car.car,".")){var h=e.car.cdr.car;var p=e.car.cdr.cdr.car;var _=Rs(h,{env:this,dynamic_env:n,use_dynamic:r,error:error});var d=Rs(p,{env:this,dynamic_env:n,use_dynamic:r,error:error});return o(_,d,a)}if(!(e.car instanceof L)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var s=e.car.valueOf();u=this.ref(e.car.__name__);return eu(a,function(e){if(!u){var t=s.split(".");if(t.length>1){var r=t.pop();var n=t.join(".");var i=c.get(n,{throwError:false});if(i){o(i,r,e);return}}throw new Error("Unbound variable `"+s+"'")}u.set(s,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 ra("set!",function(e){if(!(e.car instanceof L)){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){h("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){h("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"||e===U},"(empty? object)\n\n Function that returns #t if value is nil (an empty list) or undefined."),gensym:l("gensym",Ri,"(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){h("load",o,"string");var s=this;if(s.__name__==="__frame__"){s=s.__parent__}if(!(t instanceof Ko)){if(s===is){t=s}else{t=this.get("**interaction-environment**")}}var c="**module-path**";var f=is.get(c,{throwError:false});o=o.valueOf();if(!o.match(/.[^.]+$/)){o+=".scm"}var r=o.match(/\.xcb$/);function l(e){if(r){e=lc(e)}else{if(Ds(e)==="buffer"){e=e.toString()}e=e.replace(/^#!.*/,"");if(e.match(/^\{/)){e=ic(e)}}return Ls(e,{env:t})}function n(e){return On.fetch(e).then(function(e){return r?e.arrayBuffer():e.text()}).then(function(e){if(r){e=new Uint8Array(e)}return e})}if(ls()){return new Promise(function(){var r=B(H.mark(function e(r,n){var i,u,a;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:i=Pn("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&&a!==U){process.cwd();o=i.join(i.dirname(a.car.valueOf()),o)}case 12:is.set(c,i.dirname(o));Pn("fs").readFile(o,function(e,t){if(e){n(e);is.set(c,f)}else{try{l(t).then(function(){r();is.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){is.set(c,o.replace(/\/[^/]*$/,""));return l(e)}).then(function(){})["finally"](function(){is.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."),do:l(new ra("do",function(){var r=B(H.mark(function e(r,h){var p,n,i,u,o,s,a,c,f,l,_,d;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:p=h.use_dynamic,n=h.error;i=this;u=i;o=i.inherit("do");s=r.car;a=r.cdr.car;c=r.cdr.cdr;if(c!==U){c=new M(L("begin"),c)}f={env:i,dynamic_env:u,use_dynamic:p,error:n};l=s;case 10:if(!(l!==U)){t.next=21;break}_=l.car;t.t0=o;t.t1=_.car;t.next=16;return Rs(_.cdr.car,f);case 16:t.t2=t.sent;t.t0.set.call(t.t0,t.t1,t.t2);l=l.cdr;t.next=10;break;case 21:f={env:o,dynamic_env:u,error:n};d=H.mark(function e(){var r,n,i,u,a;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(!(c!==U)){t.next=3;break}t.next=3;return vc.evaluate(c,f);case 3:r=s;n={};case 5:if(!(r!==U)){t.next=15;break}i=r.car;if(!(i.cdr.cdr!==U)){t.next=12;break}t.next=10;return Rs(i.cdr.cdr.car,f);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);Object.keys(n).concat(a).forEach(function(e){o.set(e,n[e])});case 17:case"end":return t.stop()}}},e)});case 23:t.next=25;return Rs(a.car,f);case 25:t.t3=t.sent;if(!(t.t3===false)){t.next=30;break}return t.delegateYield(d(),"t4",28);case 28:t.next=23;break;case 30:if(!(a.cdr!==U)){t.next=34;break}t.next=33;return Rs(a.cdr.car,f);case 33:return t.abrupt("return",t.sent);case 34:case"end":return t.stop()}}},e,this)}));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 ra("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(t===false){return Rs(r.cdr.cdr.car,a)}else{return Rs(r.cdr.car,a)}};if(r===U){throw new Error("too few expressions for `if`")}var s=Rs(r.car,a);return eu(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 ra("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;h("let-env",t,"pair");var u=Rs(t.car,{env:this,dynamic_env:r,error:i,use_dynamic:n});return eu(u,function(e){h("let-env",e,"environment");return Rs(M(L("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(Ha(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(Ha(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(Ha(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(Ha(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(Wa("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(function(e){h("shuffle",e,["pair","nil","array"]);if(e===U){return U}if(Array.isArray(e)){return Su(e.slice())}var t=is.get("list->array")(e);t=Su(t);return is.get("array->list")(t)},"(shuffle obj)\n\n Order items in vector or list in random order."),begin:l(new ra("begin",function(e,t){var n=Fn(Fn({},t),{},{env:this});var i=is.get("list->array")(e);var u;return function t(){if(i.length){var e=i.shift();var r=Rs(e,n);return eu(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 ra("ignore",function(e,t){var r=Fn(Fn({},t),{},{env:this,dynamic_env:this});Rs(new M(new L("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(ra.defmacro("call/cc",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=Fn({env:this},t);return eu(Rs(e.car,r),function(e){if(ha(e)){return e(new Ps(null))}})}),"(call/cc proc)\n\n Call-with-current-continuation.\n\n NOT SUPPORTED BY LIPS RIGHT NOW"),parameterize:l(new ra("parameterize",function(t,e){var i=e.dynamic_env;var u=i.inherit("parameterize").new_frame(null,{});var a=Fn(Fn({},e),{},{env:this});var o=t.car;if(!va(o)){var r=Ds(o);throw new Error("Invalid syntax for parameterize expecting pair got ".concat(r))}function s(){var e=new M(new L("begin"),t.cdr);return Rs(e,Fn(Fn({},a),{},{dynamic_env:u}))}return function r(){var e=o.car;var n=e.car.valueOf();return eu(Rs(e.cdr.car,a),function(e){var t=i.get(n,{throwError:false});if(!da(t)){throw new Error("Unknown parameter ".concat(n))}u.set(n,t.inherit(e));if(!la(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 ra("make-parameter",function(e,t){t.dynamic_env;var r=Rs(e.car,t);var n;if(e.cdr.car instanceof M){n=Rs(e.cdr.car,t)}return new Bs(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:l(ra.defmacro("define",function(r,e){var n=this;if(r.car instanceof M&&r.car.car instanceof L){var t=new M(new L("define"),new M(r.car.car,new M(new M(new L("lambda"),new M(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(i instanceof M){i=Rs(i,e);u=true}else if(i instanceof L){i=n.get(i)}h("define",r.car,"symbol");return eu(i,function(e){if(n.__name__===aa.__merge_env__){n=n.__parent__}if(u&&(ha(e)&&$a(e)||e instanceof aa||da(e))){e.__name__=r.car.valueOf();if(e.__name__ instanceof so){e.__name__=e.__name__.valueOf()}}var t;if(r.cdr.cdr instanceof M&&so.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=d(e);if(la(e)||i!=="object"&&i!=="function"){var u=_s("set-obj!",Ds(e),["object","function"]);throw new Error(u)}h("set-obj!",t,["string","symbol","number"]);e=xa(e);t=t.valueOf();if(arguments.length===2){delete e[t]}else if(Gu(e)&&ha(r)){e[t]=xa(r);e[t][Ua]=true}else if(ha(r)||ms(r)||r===U){e[t]=r}else{e[t]=r&&!Gu(r)?r.valueOf():r}if(Nu){var a=e[t];Object.defineProperty(e,t,Fn(Fn({},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 is.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]:{},v=e.use_dynamic,y=e.error;var m=this;var g;if(d.cdr instanceof M&&so.isString(d.cdr.car)&&d.cdr.cdr!==U){g=d.cdr.car.valueOf()}function b(){var c=_a(this)?this:{dynamic_env:m},r=c.dynamic_env;var n=m.inherit("lambda");r=r.inherit("lambda");if(this&&!_a(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 e=arguments.length,t=new Array(e),i=0;i>> "+c.toString());if(c){o=c}var v=r.merge(t,aa.__merge_env__);if(l){return{expr:o,scope:v}}var y=Rs(o,Fn(Fn({},_),{},{env:v}));return ca(y,d)}i=i.cdr}}catch(e){e.message+=" in macro: ".concat(m.toString(true));throw e}throw new Error("Invalid Syntax ".concat(e.toString(true)))},w);r.__code__=m;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 ra("quote",function(e){return Wo(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:ra.defmacro("quasiquote",function(e,t){var o=t.use_dynamic,s=t.error;var c=this;var f=c;function a(e){return e instanceof M||Pu(e)||Array.isArray(e)}function h(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:a;if(e instanceof M){var n=e.car;var i=e.cdr;if(r(n)){n=t(n)}if(r(i)){i=t(i)}if(ga(n)||ga(i)){return Li([n,i]).then(function(e){var t=Y(e,2),r=t[0],n=t[1];return new M(r,n)})}else{return new M(n,i)}}return e}function u(e,t){if(e instanceof M){if(t!==U){e.append(t)}}else{e=new M(e,t)}return e}function r(e){return!!e.filter(function(e){return e instanceof M&&L.is(e.car,/^(unquote|unquote-splicing)$/)}).length}function p(e,n,i){return e.reduce(function(e,t){if(!(t instanceof M)){e.push(t);return e}if(L.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(!(i.cdr instanceof M&&r[0]===U)){return r[0]}}r=r.map(function(e){if(v.has(e)){return e.clone()}else{v.add(e);return e}});var n=l(i.cdr,0,1);if(n===U&&r[0]===U){return undefined}return eu(n,function(e){if(r[0]===U){return e}if(r.length===1){return u(r[0],e)}var t=r.reduce(function(e,t){return u(e,t)});return u(t,e)})})}(i.car.cdr)}var v=new Set;function l(e,t,r){if(e instanceof M){if(e.car instanceof M){if(L.is(e.car.car,"unquote-splicing")){return d(e,t+1,r)}if(L.is(e.car.car,"unquote")){if(t+2===r&&e.car.cdr instanceof M&&e.car.cdr.car instanceof M&&L.is(e.car.cdr.car.car,"unquote-splicing")){var n=e.car.cdr;return new M(new M(new L("unquote"),d(n,t+2,r)),U)}else if(e.car.cdr instanceof M&&e.car.cdr.cdr!==U){if(e.car.cdr.car instanceof M){var i=[];return function t(r){if(r===U){return M.fromArray(i)}return eu(Rs(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(L.is(e.car,"quasiquote")){var u=l(e.cdr,t,r+1);return new M(e.car,u)}if(L.is(e.car,"quote")){return new M(e.car,l(e.cdr,t,r))}if(L.is(e.car,"unquote")){t++;if(tr){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(e.cdr instanceof M){if(e.cdr.cdr!==U){if(e.cdr.car instanceof M){var a=[];return function t(r){if(r===U){return M.fromArray(a)}return eu(Rs(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 Rs(e.cdr.car,{env:c,dynamic_env:f,error:s})}}else{return e.cdr}}return h(e,function(e){return l(e,t,r)})}else if(Pu(e)){return _(e,t,r)}else if(e instanceof Array){return p(e,t,r)}return e}function n(e){if(e instanceof M){delete e[Pa];if(!e.haveCycles("car")){n(e.car)}if(!e.haveCycles("cdr")){n(e.cdr)}}}if(Pu(e.car)&&!r(Object.values(e.car))){return Wo(e.car)}if(Array.isArray(e.car)&&!r(e.car)){return Wo(e.car)}if(e.car instanceof M&&!e.car.find("unquote")&&!e.car.find("unquote-splicing")&&!e.car.find("quasiquote")){return Wo(e.car)}var i=l(e.car,0,1);return eu(i,function(e){n(e);return Wo(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){h("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 is.get("array->list")(r)}else if(Array.isArray(t)){return t.reverse()}else{throw new Error(_s("reverse",Ds(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){h("nth",t,"number");h("nth",r,["array","pair"]);if(r instanceof M){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){h("split",t,["regex","string"]);h("split",r,"string");return is.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){h("replace",t,["regex","string"]);h("replace",r,["string","function"]);h("replace",n,"string");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){h("match",t,["regex","string"]);h("match",r,"string");var n=r.match(t);return n?is.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){h("search",t,["regex","string"]);h("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 Ku(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){h("escape-regex",e,"string");return Ai(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(L);var r;if(t.length){r=M.fromArray(t)}else{r=U}if(e.__parent__ instanceof Ko){return is.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]:qi.LITERAL;h("set-special!",e,"string",1);h("set-special!",t,"symbol",2);qi.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:Zo,".":Zo,unbind:l(xa,"(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(Ds,"(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 L||e instanceof so||e instanceof y){e=e.valueOf()}return e in Ea(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.'),instanceof:l("instanceof",function(e,t){return t instanceof xa(e)},"(instanceof type obj)\n\n Predicate that tests if the obj is an instance of type."),"prototype?":l("prototype?",Gu,"(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 ra},"(macro? expression)\n\n Predicate that tests if value is a macro."),"function?":l("function?",ha,"(function? expression)\n\n Predicate that tests if value is a callable function."),"real?":l("real?",function(e){if(Ds(e)!=="number"){return false}if(e instanceof y){return e.isFloat()}return y.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)||y.isNumber(e)},"(number? expression)\n\n Predicate that tests if value is a number or NaN value."),"string?":l("string?",function(e){return so.isString(e)},"(string? expression)\n\n Predicate that tests if value is a string."),"pair?":l("pair?",function(e){return e instanceof M},"(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 la(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 L},"(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 e!==U&&e!==null&&!(e instanceof oo)&&!(e instanceof RegExp)&&!(e instanceof so)&&!(e instanceof M)&&!(e instanceof y)&&d(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){h("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){h("array->list",e,"array");return M.fromArray(e)},"(array->list array)\n\n Function that converts a JavaScript array to a LIPS cons list."),"tree->array":l("tree->array",ju("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",ju("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,ks(t,n))},"(apply fn list)\n\n Function that calls fn with the list of arguments."),length:l("length",function e(t){if(!t||t===U){return 0}if(t instanceof M){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;h("string->number",e,"string",1);h("string->number",t,"number",2);e=e.valueOf();t=t.valueOf();if(e.match(ai)||e.match(ni)){return li(e,t)}else if(e.match(oi)||e.match(ri)){return _i(e,t)}else{var r=t===10&&!e.match(/e/i)||t===16;if(e.match(ui)&&r||e.match(ii)){return hi(e,t)}if(e.match(Jn)){return yi(e)}}return false},"(string->number number [radix])\n\n Function that parses a string into a number."),try:l(new ra("try",function(t,e){var c=this;var r=e.use_dynamic,f=e.error;return new Promise(function(n,i){var u,a;if(L.is(t.cdr.car.car,"catch")){u=t.cdr.car;if(t.cdr.cdr instanceof M&&L.is(t.cdr.cdr.car.car,"finally")){a=t.cdr.cdr.car}}else if(L.is(t.cdr.car.car,"finally")){a=t.cdr.car}if(!(a||u)){throw new Error("try: invalid syntax")}var o=n;if(a){o=function e(t,r){o=i;eu(Rs(new M(new L("begin"),a.cdr),s),function(){r(t)})}}var s={env:c,use_dynamic:r,dynamic_env:c,error:function(t){function e(e){return t.apply(this,arguments)}e.toString=function(){return t.toString()};return e}(function(e){var t=c.inherit("try");if(u){t.set(u.cdr.car.car,e);var r={env:t,error:f};r.dynamic_env=c;eu(Rs(new M(new L("begin"),u.cdr.cdr),r),function(e){o(e,n)})}else{o(e,f)}})};var e=Rs(t.car,s);if(ga(e)){e.then(function(e){o(e,n)})["catch"](s.error)}else{o(e,n)}})}),"(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){h("find",r,["regex","function"]);h("find",n,["pair","nil"]);if(la(n)){return U}var e=au("find",r);return eu(e(n.car),function(e){if(e&&e!==U){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;h("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=au("filter",t);return function t(r){function e(e){if(e&&e!==U){u.push(n)}return t(++r)}if(r===i.length){return M.fromArray(u)}var n=i[r];return eu(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(Za,"(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(uo,"(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=Wu(s*r[a])/(u+o)}return y(u)},"(lcm n1 n2 ...)\n\n Function that returns the least common multiple of the arguments."),"odd?":l("odd?",ro(function(e){return y(e).isOdd()}),"(odd? number)\n\n Checks if number is odd."),"even?":l("even?",ro(function(e){return y(e).isEven()}),"(even? number)\n\n Checks if number is even."),"*":l("*",io(function(e,t){return y(e).mul(t)},y(1)),"(* . numbers)\n\n Multiplies all numbers passed as arguments. If single value is passed\n it will return that value."),"+":l("+",io(function(e,t){return y(e).add(t)},y(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,"number");return Qu(function(e,t){return y(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,"number");return Qu(function(e,t){return[0,1].includes(y(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?",Zu,"(eq? a b)\n\n Function that compares two values if they are identical."),or:l(new ra("or",function(e,t){var i=t.use_dynamic,u=t.error;var a=is.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(c!==false){return c}else{return t()}}if(!a.length){if(c!==false){return c}else{return false}}else{var r=a.shift();var n=Rs(r,{env:o,dynamic_env:s,use_dynamic:i,error:u});return eu(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 ra("and",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=t.error;var i=is.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(o===false){return false}else{return t()}}if(!i.length){if(o!==false){return o}else{return false}}else{var r=i.shift();return eu(Rs(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 y(e).or(t)},"(| a b)\n\n Function that calculates the bitwise or operation."),"&":l("&",function(e,t){return y(e).and(t)},"(& a b)\n\n Function that calculates the bitwise and operation."),"~":l("~",function(e){return y(e).neg()},"(~ number)\n\n Function that calculates the bitwise inverse (flip all the bits)."),">>":l(">>",function(e,t){return y(e).shr(t)},"(>> a b)\n\n Function that right shifts the value a by value b bits."),"<<":l("<<",function(e,t){return y(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(la(t)){return true}return!t},"(not object)\n\n Function that returns the Boolean negation of its argument.")},undefined,"global");var us=is.inherit("user-env");function as(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.");is.set("**interaction-environment**",e)}as(us,ts);is.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(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(t){var r=e[t]?e[t]:t;is.set(r,l(r,function(e){h(r,e,"number");if(e instanceof y){return e[t]()}},"(".concat(r," number)\n\n Function that calculates the ").concat(r," of a number.")))})})();function os(e){if(e.length===1){return e[0]}else{var t=[];var r=os(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(ha(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{var a=r[r.length-1];r=r.slice(0,-1).join(", ")+" or "+a}}return"Expecting ".concat(r,", got ").concat(t).concat(i)}function ds(r,e,n){e.forEach(function(e,t){h(r,e,n,t+1)})}function vs(e,t,r){h(e,t,r);if(t.__type__===qo){throw new Error(_s(e,"binary-port","textual-port"))}}function h(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;e=e.valueOf();var i=Ds(t).toLowerCase();if(ha(r)){if(!r(t)){throw new Error(_s(e,i,r,n))}return}var u=false;if(r instanceof M){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(_s(e,i,r,n))}}function ys(e){var t=d(e);return["string","function"].includes(t)||d(e)==="symbol"||e instanceof Ti||e instanceof L||e instanceof y||e instanceof so||e instanceof RegExp}function ms(e){return e instanceof y||e instanceof so||e instanceof oo}function gs(e,t){if(e===null){return false}return d(e)==="object"&&t in Object.getOwnPropertySymbols(e)}function bs(e,t){if(gs(e,t)||gs(e.__proto__,t)){return ha(e[t])}}function ws(r){var n=new WeakMap;return function(e){var t=n.get(e);if(!t){t=r(e)}return t}}Ds=ws(Ds);function Ds(e){var t=Bn.get(e);if(t){return t}if(d(e)==="object"){for(var r=0,n=Object.entries(Sn);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 js({env:a,use_dynamic:u,dynamic_env:o});return Es(e.apply(s,t))}function Os(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=As(e,{env:i,dynamic_env:u,error:o,use_dynamic:a});return eu(e,function(e){if(Ka(n)){n=xa(n)}e=ks(n,e);var t=e.slice();var r=Cs(n,t,{env:i,dynamic_env:u,use_dynamic:a});return eu(r,function(e){if(e instanceof M){e.markCycles();return Wo(e)}return wa(e)},o)})}var Ss=new WeakMap;var Bs=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;j(this,n);q(this,"__value__",void 0);q(this,"__fn__",void 0);mn(this,Ss,{writable:true,value:void 0});this.__value__=e;if(t){if(!ha(t)){throw new Error("Section argument to Parameter need to be function "+"".concat(Ds(t)," given"))}this.__fn__=t}if(r){a(this,Ss,r)}}P(n,[{key:"__name__",get:function e(){return t(this,Ss)},set:function e(t){a(this,Ss,t);if(this.__fn__){this.__fn__.__name__="fn-".concat(t)}}},{key:"invoke",value:function e(){if(ha(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 js=function(){function t(e){j(this,t);q(this,"env",void 0);q(this,"dynamic_env",void 0);q(this,"use_dynamic",void 0);Object.assign(this,e)}P(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 Is(e,t){var r=e.get(t.__name__,{throwError:false});if(da(r)&&r!==t){return r}var n=us.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(da(r)&&r!==t){return r}}return t}var Ps=function(){function t(e){j(this,t);q(this,"__value__",void 0);this.__value__=e}P(t,[{key:"invoke",value:function e(){if(this.__value__===null){throw new Error("Continuations are not implemented yet")}}}]);return t}();var Ns=function e(){};function Rs(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?Ns:t,r=R(e,yn);return function(e){try{if(!ya(c)){c=s===true?us:s||us}if(f){s=c}else if(s===true){s=us}else{s=s||is}var t={env:s,dynamic_env:c,use_dynamic:f,error:l};var r;if(la(o)){return o}if(o instanceof L){return s.get(o)}if(!(o instanceof M)){return o}var n=o.car;var e=o.cdr;if(n instanceof M){r=Es(Rs(n,t));if(ga(r)){return r.then(function(e){if(!ma(e)){throw new Error(Ds(e)+" "+s.get("repr")(e)+" is not callable while evaluating "+o.toString())}return Rs(new M(e,o.cdr),t)})}else if(!ma(r)){throw new Error(Ds(r)+" "+s.get("repr")(r)+" is not callable while evaluating "+o.toString())}}if(n instanceof L){r=s.get(n)}else if(ha(n)){r=n}var i;if(r instanceof aa){i=xs(r,o,t)}else if(r instanceof ra){i=Fs(r,e,t)}else if(ha(r)){i=Os(r,e,t)}else if(da(r)){var u=Is(c,r);if(la(o.cdr)){i=u.invoke()}else{return eu(Rs(o.cdr.car,t),function(e){u.__value__=e})}}else if(pa(r)){i=r.invoke()}else if(o instanceof M){r=n&&n.toString();throw new Error("".concat(Ds(n)," ").concat(r," is not a function"))}else{return o}var a=s.get(Symbol["for"]("__promise__"),{throwError:false});if(a===true&&ga(i)){i=i.then(function(e){if(e instanceof M&&!r[Pa]){return Rs(e,t)}return e});return new Ti(i)}return i}catch(e){l&&l.call(s,e,o)}}(r)}var Ts=Us(function(e){return e});var Ls=Us(function(e,t){return t});function Us(y){return function(){var t=B(H.mark(function e(r){var n,i,u,h,a,p,o,s,_,c,d,f,v,l=arguments;return H.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:n=l.length>1&&l[1]!==undefined?l[1]:{},i=n.env,u=n.dynamic_env,h=n.use_dynamic;if(!ya(u)){u=i===true?us:i||us}if(i===true){i=us}else{i=i||us}a=[];p=Array.isArray(r)?r:Zi(r);o=false;s=false;t.prev=7;c=kn(p);case 9:t.next=11;return c.next();case 11:if(!(o=!(d=t.sent).done)){t.next=25;break}f=d.value;v=Rs(f,{env:i,dynamic_env:u,use_dynamic:h,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))}}throw t}});t.t0=a;t.t1=y;t.t2=f;t.next=19;return v;case 19:t.t3=t.sent;t.t4=(0,t.t1)(t.t2,t.t3);t.t0.push.call(t.t0,t.t4);case 22:o=false;t.next=9;break;case 25:t.next=31;break;case 27:t.prev=27;t.t5=t["catch"](7);s=true;_=t.t5;case 31:t.prev=31;t.prev=32;if(!(o&&c["return"]!=null)){t.next=36;break}t.next=36;return c["return"]();case 36:t.prev=36;if(!s){t.next=39;break}throw _;case 39:return t.finish(36);case 40:return t.finish(31);case 41:return t.abrupt("return",a);case 42:case"end":return t.stop()}}},e,null,[[7,27,31,41],[32,,36,40]])}));function e(e){return t.apply(this,arguments)}return e}()}function Ms(e){var t={"[":"]","(":")"};var r;if(typeof e==="string"){r=Bi(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 xi;var a=Dn(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 f=u.top();var c=t[f];if(s===c){u.pop()}else{throw new Error("Syntax error: missing closing ".concat(c))}}else{throw new Error("Syntax error: not matched closing ".concat(s))}}}catch(e){a.e(e)}finally{a.f()}return u.is_empty()}function qs(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 On.Worker(r.createObjectURL(n))}function Ys(){return vc.version.match(/^(\{\{VER\}\}|DEV)$/)}function Vs(){if(ls()){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 zs=Vs();function $s(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"";var t="dist/std.xcb";if(e===""){if(zs){e=zs.replace(/[^/]*$/,"std.xcb")}else if(Ys()){e="https://cdn.jsdelivr.net/gh/jcubic/lips@devel/".concat(t)}else{e="https://cdn.jsdelivr.net/npm/@jcubic/lips@".concat(vc.version,"/").concat(t)}}var r=is.get("load");return r.call(us,e,is)}function Js(e){this.url=e;var a=this.worker=qs(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 vc.Interpreter("worker");o=$s(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 Ks={pair:function e(t){var r=Y(t,2),n=r[0],i=r[1];return M(n,i)},number:function e(t){if(so.isString(t)){return y([t,10])}return y(t)},regex:function e(t){var r=Y(t,2),n=r[0],i=r[1];return new RegExp(n,i)},nil:function e(){return U},symbol:function e(t){if(so.isString(t)){return L(t)}else if(Array.isArray(t)){return L(Symbol["for"](t[0]))}},string:so,character:oo};var Gs=Object.keys(Ks);var Hs={};for(var Ws=0,Qs=Object.entries(Gs);Ws1){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 oc(){var e=1;var t=new TextEncoder("utf-8");return t.encode("LIPS".concat(e.toString().padStart(3," ")))}var sc=7;function cc(e){var t=new TextDecoder("utf-8");var r=t.decode(e.slice(0,sc));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 fc(e){var t=oc();var r=uc.encode(e);return ac(t,cn(r,{magic:false}))}function lc(e){var t=cc(e),r=t.type,n=t.version;if(r==="LIPS"&&n===1){var i=fn(e.slice(sc),{magic:false});return uc.decode(i)}else{throw new Error("Invalid file format ".concat(r))}}function hc(e){console.error(e.message||e);if(e.code){console.error(e.code.map(function(e,t){return"[".concat(t+1,"]: ").concat(e)}))}}function pc(){var a=["text/x-lips","text/x-scheme"];var o;function s(r){return new Promise(function(t){var e=r.getAttribute("src");if(e){return fetch(e).then(function(e){return e.text()}).then(Ls).then(t)["catch"](function(e){hc(e);t()})}else{return Ls(r.innerHTML).then(t)["catch"](function(e){hc(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=t.getAttribute("bootstrap");if(!o&&typeof n==="string"){return $s(n).then(function(){return s(t)}).then(e)}else{return s(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(_c){var t=_c;var r=t.getAttribute("bootstrap");if(typeof r==="string"){return $s(r).then(function(){o=true;return e()})}}return e()}var _c=typeof window!=="undefined"&&window.document&&document.currentScript;if(typeof window!=="undefined"){Rn(window,pc)}var dc=function(){var e=so("Sun, 14 Jan 2024 12:42:38 +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}();nu(hu,"__class__","ahead");nu(M,"__class__","pair");nu(Bu,"__class__","nil");nu(pu,"__class__","pattern");nu(lu,"__class__","formatter");nu(ra,"__class__","macro");nu(aa,"__class__","syntax");nu(Ko,"__class__","environment");nu(So,"__class__","input-port");nu(Bo,"__class__","output-port");nu(jo,"__class__","output-port");nu(Io,"__class__","output-string-port");nu(No,"__class__","input-string-port");nu(Lo,"__class__","input-file-port");nu(Po,"__class__","output-file-port");nu(Jo,"__class__","lips-error");[y,Do,Co,Eo,Oo].forEach(function(e){nu(e,"__class__","number")});nu(oo,"__class__","character");nu(L,"__class__","symbol");nu(so,"__class__","string");nu(Ti,"__class__","promise");nu(Bs,"__class__","parameter");var vc={version:"DEV",banner:dc,date:"Sun, 14 Jan 2024 12:42:38 +0000",exec:Ls,parse:Xa(iu,Zi),tokenize:Bi,evaluate:Rs,compile:Ts,serialize:nc,unserialize:ic,serialize_bin:fc,unserialize_bin:lc,bootstrap:$s,Environment:Ko,env:us,Worker:Js,Interpreter:$o,balanced_parenthesis:Ms,balancedParenthesis:Ms,balanced:Ms,Macro:ra,Syntax:aa,Pair:M,Values:Ho,QuotedPromise:Ti,Error:Jo,quote:Wo,InputPort:So,OutputPort:Bo,BufferedOutputPort:jo,InputFilePort:Lo,OutputFilePort:Po,InputStringPort:No,OutputStringPort:Io,InputByteVectorPort:Ro,OutputByteVectorPort:To,InputBinaryFilePort:Uo,OutputBinaryFilePort:Mo,Formatter:lu,Parser:Wi,Lexer:Gi,specials:qi,repr:Iu,nil:U,eof:Vo,LSymbol:L,LNumber:y,LFloat:Eo,LComplex:Do,LRational:Co,LBigInteger:Oo,LCharacter:oo,LString:so,Parameter:Bs,rationalize:Fo};is.set("lips",vc);var yc={};var mc=Object.freeze({__proto__:null,default:yc});function gc(e,t){var r=0;for(var n=e.length-1;n>=0;n--){var i=e[n];if(i==="."){e.splice(n,1)}else if(i===".."){e.splice(n,1);r++}else if(r){e.splice(n,1);r--}}if(t){for(;r--;r){e.unshift("..")}}return e}var bc=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;var wc=function(e){return bc.exec(e).slice(1)};function Dc(){var e="",t=false;for(var r=arguments.length-1;r>=-1&&!t;r--){var n=r>=0?arguments[r]:"/";if(typeof n!=="string"){throw new TypeError("Arguments to path.resolve must be strings")}else if(!n){continue}e=n+"/"+e;t=n.charAt(0)==="/"}e=gc(Ic(e.split("/"),function(e){return!!e}),!t).join("/");return(t?"/":"")+e||"."}function Ec(e){var t=Ac(e),r=Pc(e,-1)==="/";e=gc(Ic(e.split("/"),function(e){return!!e}),!t).join("/");if(!e&&!t){e="."}if(e&&r){e+="/"}return(t?"/":"")+e}function Ac(e){return e.charAt(0)==="/"}function xc(){var e=Array.prototype.slice.call(arguments,0);return Ec(Ic(e,function(e,t){if(typeof e!=="string"){throw new TypeError("Arguments to path.join must be strings")}return e}).join("/"))}function Fc(e,t){e=Dc(e).substr(1);t=Dc(t).substr(1);function r(e){var t=0;for(;t=0;r--){if(e[r]!=="")break}if(t>r)return[];return e.slice(t,r-t+1)}var n=r(e.split("/"));var i=r(t.split("/"));var u=Math.min(n.length,i.length);var a=u;for(var o=0;o 0) { + + // Pick a remaining element. + randomIndex = Math.floor(Math.random() * currentIndex); + currentIndex--; + + // And swap it with the current element. + [array[currentIndex], array[randomIndex]] = [ + array[randomIndex], array[currentIndex]]; + } + + return array; +} +// ---------------------------------------------------------------------- // :: Nil constructor with only once instance // ---------------------------------------------------------------------- function Nil() {} @@ -7574,6 +7595,22 @@ var global_env = new Environment({ in the body and if it's a promise it will await it in parallel and return the value of the last expression (i.e. it uses Promise.all()).`), // ------------------------------------------------------------------ + shuffle: doc(function(arg) { + typecheck('shuffle', arg, ['pair', 'nil', 'array']); + if (arg === nil) { + return nil; + } + if (Array.isArray(arg)) { + return shuffle(arg.slice()); + } + let arr = global_env.get('list->array')(arg); + arr = shuffle(arr); + + return global_env.get('array->list')(arr); + }, `(shuffle obj) + + Order items in vector or list in random order.`), + // ------------------------------------------------------------------ begin: doc(new Macro('begin', function(code, options) { const eval_args = {...options, env: this }; const arr = global_env.get('list->array')(code); diff --git a/tests/core.scm b/tests/core.scm index 9286a499..4e4d2732 100644 --- a/tests/core.scm +++ b/tests/core.scm @@ -507,6 +507,12 @@ (t.is (split #/(:)/ "foo:bar:baz") '("foo" ":" "bar" ":" "baz")))) +(test "core: shuffle" + (lambda (t) + (t.is (list? (shuffle '(1 2 3))) #t) + (t.is (shuffle nil) nil) + (t.is (vector? (shuffle #(1 2 3))) #t))) + ;; TODO ;; begin* ;; set-obj! throws with null or boolean