diff --git a/README.md b/README.md index 6a59b3b2..d7d86e8b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # [LIPS is Pretty Simple](https://jcubic.github.io/lips/) - Scheme based Powerful LISP [![npm](https://img.shields.io/badge/npm-DEV-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) -[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&502952e7fdce9a97a56dfe69a07f4db6bcd9d5c3)](https://travis-ci.org/jcubic/lips) +[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&66746060e1ccbd0b8c234a11783918f1f136b2c0)](https://travis-ci.org/jcubic/lips) [![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&2c48907438a7265935a7b21e6931008d)](https://coveralls.io/github/jcubic/lips?branch=devel) @@ -109,7 +109,7 @@ $ lips | | / ^ \ |___||_||_| <___/ | | \_\ /_/ \_\ /_/ -LIPS Scheme Interpreter DEV (2020-05-13) +LIPS Scheme Interpreter DEV (2020-05-16) Copyright (c) 2018-2020 Jakub T. Jankiewicz Type (env) to see environment with functions macros and variables. diff --git a/dist/lips.js b/dist/lips.js index 0a6475df..d6540655 100644 --- a/dist/lips.js +++ b/dist/lips.js @@ -24,7 +24,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Wed, 13 May 2020 09:37:06 +0000 + * build: Sat, 16 May 2020 21:13:32 +0000 */ (function () { 'use strict'; @@ -912,41 +912,6 @@ var toConsumableArray = _toConsumableArray; - function _iterableToArrayLimit(arr, i) { - if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; - var _arr = []; - var _n = true; - var _d = false; - var _e = undefined; - - try { - for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { - _arr.push(_s.value); - - if (i && _arr.length === i) break; - } - } catch (err) { - _d = true; - _e = err; - } finally { - try { - if (!_n && _i["return"] != null) _i["return"](); - } finally { - if (_d) throw _e; - } - } - - return _arr; - } - - var iterableToArrayLimit = _iterableToArrayLimit; - - function _slicedToArray(arr, i) { - return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest(); - } - - var slicedToArray = _slicedToArray; - function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { @@ -1002,6 +967,41 @@ var objectWithoutProperties = _objectWithoutProperties; + function _iterableToArrayLimit(arr, i) { + if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; + var _arr = []; + var _n = true; + var _d = false; + var _e = undefined; + + try { + for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { + _arr.push(_s.value); + + if (i && _arr.length === i) break; + } + } catch (err) { + _d = true; + _e = err; + } finally { + try { + if (!_n && _i["return"] != null) _i["return"](); + } finally { + if (_d) throw _e; + } + } + + return _arr; + } + + var iterableToArrayLimit = _iterableToArrayLimit; + + function _slicedToArray(arr, i) { + return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest(); + } + + var slicedToArray = _slicedToArray; + var _typeof_1 = createCommonjsModule(function (module) { function _typeof(obj) { "@babel/helpers - typeof"; @@ -1161,12 +1161,51 @@ } }); }; - } // parse_argument based on function from jQuery Terminal + } // functions generate regexes to match number rational, integer, complex, complex+ratioanl + + + function num_mnemicic_re(mnemonic) { + return mnemonic ? "(?:#".concat(mnemonic, "(?:#[ie])?|#[ie]#").concat(mnemonic, ")") : '(?:#[ie])?'; + } + + function gen_rational_re(mnemonic, range) { + return "".concat(num_mnemicic_re(mnemonic), "[+-]?").concat(range, "+/").concat(range, "+"); + } // TODO: float complex + function gen_complex_re(mnemonic, range) { + return "".concat(num_mnemicic_re(mnemonic), "(?:(?:[+-]?").concat(range, "+)?[+-]").concat(range, "+i|(?:[+-]?").concat(range, "+/").concat(range, "+)?[+-]").concat(range, "+/").concat(range, "+i)"); + } + + function gen_integer_re(mnemonic, range) { + return "".concat(num_mnemicic_re(mnemonic), "[+-]?").concat(range, "+"); + } + var re_re = /^\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimy]*)$/; - var int_re = /^(?:#x[-+]?[0-9a-f]+|#o[-+]?[0-7]+|#b[-+]?[01]+|[-+]?[0-9]+)$/i; - var float_re = /^([-+]?([0-9]+([eE][-+]?[0-9]+)|(\.[0-9]+|[0-9]+\.[0-9]+)([eE][-+]?[0-9]+)?)|[0-9]+\.)$/; + var float_stre = '(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)'; + var complex_float_stre = "(?:#[ie])?(?:".concat(float_stre, ")?").concat(float_stre, "i"); + var float_re = new RegExp("^(#[ie])?".concat(float_stre, "$")); + + function make_complex_match_re(mnemonic, range) { + // complex need special treatment of 10e+1i when it's hex or decimal + var neg = mnemonic === 'x' ? '(?![+])' : '(?!\\.)'; + var fl = mnemonic === '' ? float_stre + '|' : ''; + return new RegExp("((?:".concat(fl, "[+-]?").concat(range, "+/").concat(range, "+|[+-]?").concat(range, "+").concat(neg, ")?)(").concat(fl, "[+-]").concat(range, "+/").concat(range, "+|[+-]").concat(range, "+)i")); + } + + var complex_list_re = function () { + var result = {}; + [[10, '', '[0-9]'], [16, 'x', '[0-9a-fA-F]'], [8, 'o', '[0-7]'], [2, 'b', '[01]']].forEach(function (_ref) { + var _ref2 = slicedToArray(_ref, 3), + radix = _ref2[0], + mnemonic = _ref2[1], + range = _ref2[2]; + + result[radix] = make_complex_match_re(mnemonic, range); + }); + return result; + }(); + var characters = { 'alarm': '\x07', 'backspace': '\x08', @@ -1181,43 +1220,90 @@ var character_symbols = Object.keys(characters).join('|'); var char_re = new RegExp("^#\\\\(?:".concat(character_symbols, "|[\\s\\S])$"), 'i'); // complex with (int) (float) (rational) - var complex_re = /^((?:(?:[-+]?[0-9]+(?:[eE][-+]?[0-9]+)?)|(?:[-+]?[0-9]+\/[0-9]+|(?:(?:\.[0-9]+|[0-9]+\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\.))(?=[+-]|i))?((?:[-+]?[0-9]+(?:[eE][-+]?[0-9]+)?)|(?:[-+]?(?:[0-9]+\/[0-9]+|(?:\.[0-9]+|[0-9]+\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\.))i|-i$/; - var rational_re = /^[-+]?[0-9]+\/[0-9]+$/; + function make_num_stre(fn) { + var ranges = [['o', '[0-7]'], ['x', '[0-9a-fA-F]'], ['b', '[01]'], ['', '[0-9]']]; // float exception that don't accept mnemonics + + var result = ranges.map(function (_ref3) { + var _ref4 = slicedToArray(_ref3, 2), + m = _ref4[0], + range = _ref4[1]; + + return fn(m, range); + }).join('|'); + + if (fn === gen_complex_re) { + result = complex_float_stre + '|' + result; + } + + return result; + } + + function make_type_re(fn) { + return new RegExp('^(?:' + make_num_stre(fn) + ')$'); + } + + var complex_re = make_type_re(gen_complex_re); + var rational_re = make_type_re(gen_rational_re); + var int_re = make_type_re(gen_integer_re); /* eslint-enable */ - // ---------------------------------------------------------------------- + + function num_pre_parse(arg) { + var parts = arg.match(/((?:#[xobie]){0,2})(.*)/i); + var options = {}; + + if (parts[1]) { + var type = parts[1].replace(/#/g, '').split(''); + + if (type.includes('x')) { + options.radix = 16; + } else if (type.includes('o')) { + options.radix = 8; + } else if (type.includes('b')) { + options.radix = 2; + } else { + options.radix = 10; + } + + if (type.includes('i')) { + options.inexact = true; + } + + if (type.includes('e')) { + options.exact = true; + } + } else { + options.radix = 10; + } + + options.number = parts[2]; + return options; + } // ---------------------------------------------------------------------- + function parse_rational(arg) { - var parts = arg.split('/'); - return LRational({ - num: parseInt(parts[0], 10), - denom: parseInt(parts[1], 10) + var parse = num_pre_parse(arg); + var parts = parse.number.split('/'); + var num = LRational({ + num: LNumber([parts[0], parse.radix]), + denom: LNumber([parts[1], parse.radix]) }); + + if (parse.inexact) { + return num.valueOf(); + } else { + return num; + } } // ---------------------------------------------------------------------- function parse_integer(arg) { - var m = arg.match(/^(?:#([xbo]))?([+-]?[0-9a-f]+)$/i); - var radix; - - if (m && m[1]) { - switch (m[1]) { - case 'x': - radix = 16; - break; - - case 'o': - radix = 8; - break; + var parse = num_pre_parse(arg); - case 'b': - radix = 2; - break; - } - } else { - radix = 10; + if (parse.inexact) { + return LFloat(parseInt(parse.number, parse.radix)); } - return LNumber([m[2], radix]); + return LNumber([parse.number, parse.radix]); } // ---------------------------------------------------------------------- @@ -1230,17 +1316,6 @@ } // ---------------------------------------------------------------------- - function parse_number(arg) { - if (arg.match(rational_re)) { - return parse_rational(arg); - } else if (arg.match(int_re)) { - return parse_integer(arg); - } else if (arg.match(float_re)) { - return LFloat(parseFloat(arg)); - } - } // ---------------------------------------------------------------------- - - function parse_complex(arg) { if (arg === '-i') { return { @@ -1249,15 +1324,47 @@ }; } - var parts = arg.match(complex_re); + function parse_num(n) { + var value; + + if (n.match(int_re)) { + value = LNumber([n, parse.radix]); + } else if (n.match(rational_re)) { + var parts = n.split('/'); + value = LRational({ + num: LNumber([parts[0], parse.radix]), + denom: LNumber([parts[1], parse.radix]) + }); + } else if (n.match(float_re)) { + var _float = LFloat(parseFloat(n)); + + if (parse.exact) { + return _float.toRational(); + } + + return _float; + } + + if (parse.inexact) { + return LFloat(value.valueOf()); + } + + return value; + } + + var parse = num_pre_parse(arg); + var parts = parse.number.match(complex_list_re[parse.radix.toString()]); var re, im; + im = parse_num(parts[2]); - if (parts.length === 2) { - im = parse_number(parts[1]); - re = 0; + if (parts[1]) { + re = parse_num(parts[1]); } else { - re = parts[1] ? parse_number(parts[1]) : 0; - im = parse_number(parts[2]); + if (im instanceof LFloat) { + re = LFloat(0); + } else { + re = LNumber(0); + } } return LComplex({ @@ -1267,6 +1374,18 @@ } // ---------------------------------------------------------------------- + function parse_float(arg) { + var parse = num_pre_parse(arg); + var value = parseFloat(parse.number); + + if (parse.exact || !parse.number.match(/\./) && !parse.inexact) { + return LNumber(value); + } + + return LFloat(value); + } // ---------------------------------------------------------------------- + + function parse_string(string) { // handle non JSON escapes and skip unicode escape \u (even partial) var re = /([^\\\n])(\\(?:\\{2})*)(?!u[0-9AF]{1,4})(.)/gi; @@ -1303,7 +1422,7 @@ } else if (arg.match(int_re)) { return parse_integer(arg); } else if (arg.match(float_re)) { - return LFloat(parseFloat(arg)); + return parse_float(arg); } else if (arg === 'nil') { return nil; } else if (arg === 'true') { @@ -1324,13 +1443,15 @@ var pre_parse_re = /("(?:\\[\S\s]|[^"])*"?|\/(?! )[^\n\/\\]*(?:\\[\S\s][^\n\/\\]*)*\/[gimy]*(?=\s|\[|\]|\(|\)|$)|;.*)/g; - var string_re = /"(?:\\[\S\s]|[^"])*"?/g; + var string_re = /"(?:\\[\S\s]|[^"])*"?/g; // generate regex for all number literals + + var num_stre = complex_float_stre + '|' + [gen_complex_re, gen_rational_re, gen_integer_re].map(make_num_stre).join('|'); // ---------------------------------------------------------------------- function make_token_re() { var tokens = specials.names().sort(function (a, b) { return b.length - a.length || a.localeCompare(b); }).map(escape_regex).join('|'); - return new RegExp("(#\\\\(?:".concat(character_symbols, "|[\\s\\S])|#f|#t|#[xbo][0-9a-f]+(?=[\\s()]|$)|[0-9]+/[0-9]+(?:[-+][0-9]+/[0-9]+i)?|\\[|\\]|\\(|\\)|;.*|\\|[^|]+\\||(?:(?:[-+]?(?:(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)[0-9]i)|\\n|\\.{2,}|(?!#:)(?:").concat(tokens, ")|[^(\\s)[\\]]+)"), 'gim'); + return new RegExp("(#\\\\(?:".concat(character_symbols, "|[\\s\\S])|#f|#t|").concat(num_stre, "(?=[\\n\\s()])|\\[|\\]|\\(|\\)|;.*|\\|[^|]+\\||(?:#[ei])?").concat(float_stre, "|\\n|\\.{2,}|(?!#:)(?:").concat(tokens, ")|[^(\\s)[\\]]+)"), 'gim'); } /* eslint-enable */ // ---------------------------------------------------------------------- @@ -1508,11 +1629,11 @@ var defined_specials = [["'", new LSymbol('quote'), specials.LITERAL], ['`', new LSymbol('quasiquote'), specials.LITERAL], [',@', new LSymbol('unquote-splicing'), specials.LITERAL], [',', new LSymbol('unquote'), specials.LITERAL]]; - defined_specials.forEach(function (_ref) { - var _ref2 = slicedToArray(_ref, 3), - seq = _ref2[0], - symbol = _ref2[1], - type = _ref2[2]; + defined_specials.forEach(function (_ref5) { + var _ref6 = slicedToArray(_ref5, 3), + seq = _ref6[0], + symbol = _ref6[1], + type = _ref6[2]; specials.append(seq, symbol, type); }); // ---------------------------------------------------------------------- @@ -3035,10 +3156,10 @@ }; // ---------------------------------------------------------------------- - Macro.prototype.invoke = function (code, _ref3, macro_expand) { - var env = _ref3.env, - dynamic_scope = _ref3.dynamic_scope, - error = _ref3.error; + Macro.prototype.invoke = function (code, _ref7, macro_expand) { + var env = _ref7.env, + dynamic_scope = _ref7.dynamic_scope, + error = _ref7.error; var args = { dynamic_scope: dynamic_scope, error: error, @@ -3058,7 +3179,7 @@ function macro_expand(single) { return /*#__PURE__*/function () { - var _ref4 = asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(code, args) { + var _ref8 = asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(code, args) { var env, traverse, _traverse; return regenerator.wrap(function _callee2$(_context2) { @@ -3212,7 +3333,7 @@ })); return function (_x, _x2) { - return _ref4.apply(this, arguments); + return _ref8.apply(this, arguments); }; }(); } // ---------------------------------------------------------------------- @@ -3232,9 +3353,9 @@ Syntax.prototype = Object.create(Macro.prototype); - Syntax.prototype.invoke = function (code, _ref5, macro_expand) { - var error = _ref5.error, - env = _ref5.env; + Syntax.prototype.invoke = function (code, _ref9, macro_expand) { + var error = _ref9.error, + env = _ref9.env; var args = { error: error, env: env, @@ -4148,9 +4269,9 @@ } }).then(exec); } else { - values.forEach(function (_ref6) { - var name = _ref6.name, - value = _ref6.value; + values.forEach(function (_ref10) { + var name = _ref10.name, + value = _ref10.value; set(name, value); }); } @@ -4194,9 +4315,9 @@ function pararel(name, fn) { return new Macro(name, function (code) { - var _ref7 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, - dynamic_scope = _ref7.dynamic_scope, - error = _ref7.error; + var _ref11 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, + dynamic_scope = _ref11.dynamic_scope, + error = _ref11.error; var env = this; @@ -4609,22 +4730,35 @@ var value; - if (typeof BigInt !== 'undefined') { - if (typeof n !== 'bigint') { - if (parsable) { - var _n = n, - _n2 = slicedToArray(_n, 2), - str = _n2[0], - radix = _n2[1]; + if (parsable) { + var _n = n, + _n2 = slicedToArray(_n, 2), + str = _n2[0], + radix = _n2[1]; - if (str instanceof LString) { - str = str.valueOf(); - } + if (str instanceof LString) { + str = str.valueOf(); + } - if (radix instanceof LNumber) { - radix = radix.valueOf(); - } + if (radix instanceof LNumber) { + radix = radix.valueOf(); + } + var sign = str.match(/^([+-])/); + var minus = false; + + if (sign) { + str = str.replace(/^[+-]/, ''); + + if (sign[1] === '-') { + minus = true; + } + } + } + + if (typeof BigInt !== 'undefined') { + if (typeof n !== 'bigint') { + if (parsable) { var prefix; // default number base (radix) supported by BigInt constructor switch (radix) { @@ -4659,6 +4793,10 @@ } else { value = BigInt(n); } + + if (minus) { + value *= BigInt(-1); + } } else { value = n; } @@ -4671,20 +4809,7 @@ return LBigInteger(new BN(n)); } else if (parsable) { - var _n3 = n, - _n4 = slicedToArray(_n3, 2), - _str = _n4[0], - _radix = _n4[1]; - - if (_str instanceof LString) { - _str = _str.valueOf(); - } - - if (_radix instanceof LNumber) { - _radix = _radix.valueOf(); - } - - this.value = parseInt(_str, _radix); + this.value = parseInt(str, radix); } else { this.value = n; } @@ -4736,7 +4861,7 @@ im = _LNumber$coerce2[0], re = _LNumber$coerce2[1]; - if (im.cmp(0) === 0) { + if (im.cmp(0) === 0 && !force) { return re; } @@ -4834,7 +4959,8 @@ var ret = fn(this.re, re, this.im, im); if ('im' in ret && 're' in ret) { - return LComplex(ret); + var x = LComplex(ret, true); + return x; } return ret; @@ -5095,7 +5221,7 @@ LRational.prototype.cmp = function (n) { - return LNumber(this.valueOf()).cmp(n); + return LNumber(this.valueOf(), true).cmp(n); }; // ------------------------------------------------------------------------- @@ -5411,11 +5537,11 @@ }, "float": { 'bigint': function bigint(a, b) { - return [a, LFloat(b.valueOf())]; + return [a, b && LFloat(b.valueOf())]; }, 'float': i, 'rational': function rational(a, b) { - return [a, LFloat(b.valueOf())]; + return [a, b && LFloat(b.valueOf())]; }, 'complex': function complex(a, b) { return [{ @@ -5428,11 +5554,29 @@ bigint: complex('bigint'), "float": complex('float'), rational: complex('rational'), - complex: i + complex: function complex(a, b) { + var _LNumber$coerce3 = LNumber.coerce(a.re, b.re), + _LNumber$coerce4 = slicedToArray(_LNumber$coerce3, 2), + a_re = _LNumber$coerce4[0], + b_re = _LNumber$coerce4[1]; + + var _LNumber$coerce5 = LNumber.coerce(a.im, b.im), + _LNumber$coerce6 = slicedToArray(_LNumber$coerce5, 2), + a_im = _LNumber$coerce6[0], + b_im = _LNumber$coerce6[1]; + + return [{ + im: a_im, + re: a_re + }, { + im: b_im, + re: b_re + }]; + } }, rational: { bigint: function bigint(a, b) { - return [a, { + return [a, b || { num: b, denom: 1 }]; @@ -5451,7 +5595,7 @@ im: coerce(type, a.im.type, a.im), re: coerce(type, a.re.type, a.re) }, { - im: coerce(type, a.type, 0), + im: coerce(type, a.im.type, 0), re: coerce(type, b.type, b) }]; }; @@ -5854,7 +5998,7 @@ Interpreter.prototype.exec = /*#__PURE__*/function () { - var _ref8 = asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(code) { + var _ref12 = asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(code) { var dynamic, _args5 = arguments; return regenerator.wrap(function _callee3$(_context3) { @@ -5878,7 +6022,7 @@ })); return function (_x5) { - return _ref8.apply(this, arguments); + return _ref12.apply(this, arguments); }; }(); // ------------------------------------------------------------------------- @@ -6361,9 +6505,9 @@ return unbind(a) === unbind(b); }, "(%same-functions a b)\n\n Helper function that check if two bound functions are the same"), // ------------------------------------------------------------------ - help: doc(new Macro('help', function (code, _ref9) { - var dynamic_scope = _ref9.dynamic_scope, - error = _ref9.error; + help: doc(new Macro('help', function (code, _ref13) { + var dynamic_scope = _ref13.dynamic_scope, + error = _ref13.error; var symbol; if (code.car instanceof LSymbol) { @@ -6406,9 +6550,9 @@ }, "(cdr pair)\n\n Function returns cdr (tail) of the list/pair."), // ------------------------------------------------------------------ 'set!': doc(new Macro('set!', function (code) { - var _ref10 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, - dynamic_scope = _ref10.dynamic_scope, - error = _ref10.error; + var _ref14 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, + dynamic_scope = _ref14.dynamic_scope, + error = _ref14.error; if (dynamic_scope) { dynamic_scope = this; @@ -6552,9 +6696,9 @@ }).then(function () {}); }, "(load filename)\n\n Function fetch the file and evaluate its content as LIPS code."), // ------------------------------------------------------------------ - 'while': doc(new Macro('while', function (code, _ref11) { - var dynamic_scope = _ref11.dynamic_scope, - error = _ref11.error; + 'while': doc(new Macro('while', function (code, _ref15) { + var dynamic_scope = _ref15.dynamic_scope, + error = _ref15.error; var self = this; var begin = new Pair(new LSymbol('begin'), code.cdr); var result; @@ -6595,9 +6739,9 @@ }(); }), "(while cond . body)\n\n Macro that create a loop, it exectue body untill cond expression is false"), // ------------------------------------------------------------------ - 'if': doc(new Macro('if', function (code, _ref12) { - var dynamic_scope = _ref12.dynamic_scope, - error = _ref12.error; + 'if': doc(new Macro('if', function (code, _ref16) { + var dynamic_scope = _ref16.dynamic_scope, + error = _ref16.error; if (dynamic_scope) { dynamic_scope = this; @@ -6686,9 +6830,9 @@ }(); }), "(begin . args)\n\n Macro runs list of expression and return valuate of the list one.\n It can be used in place where you can only have single exression,\n like if expression."), // ------------------------------------------------------------------ - 'ignore': new Macro('ignore', function (code, _ref13) { - var dynamic_scope = _ref13.dynamic_scope, - error = _ref13.error; + 'ignore': new Macro('ignore', function (code, _ref17) { + var dynamic_scope = _ref17.dynamic_scope, + error = _ref17.error; var args = { env: this, error: error @@ -6827,9 +6971,9 @@ }, "(eval list)\n\n Function evalute LIPS code as list structure."), // ------------------------------------------------------------------ lambda: new Macro('lambda', function (code) { - var _ref14 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, - dynamic_scope = _ref14.dynamic_scope, - error = _ref14.error; + var _ref18 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, + dynamic_scope = _ref18.dynamic_scope, + error = _ref18.error; var self = this; @@ -6937,9 +7081,9 @@ 'macroexpand': new Macro('macroexpand', macro_expand()), 'macroexpand-1': new Macro('macroexpand-1', macro_expand(true)), // ------------------------------------------------------------------ - 'define-macro': doc(new Macro(macro, function (macro, _ref15) { - var dynamic_scope = _ref15.dynamic_scope, - error = _ref15.error; + 'define-macro': doc(new Macro(macro, function (macro, _ref19) { + var dynamic_scope = _ref19.dynamic_scope, + error = _ref19.error; if (macro.car instanceof Pair && macro.car.car instanceof LSymbol) { var name = macro.car.car.name; @@ -7038,8 +7182,8 @@ return symbols; } - return new Syntax(function (code, _ref16) { - var macro_expand = _ref16.macro_expand; + return new Syntax(function (code, _ref20) { + var macro_expand = _ref20.macro_expand; var scope = env.inherit('syntax'); if (dynamic_scope) { @@ -7151,10 +7295,10 @@ } if (isPromise(car) || isPromise(cdr)) { - return Promise.all([car, cdr]).then(function (_ref17) { - var _ref18 = slicedToArray(_ref17, 2), - car = _ref18[0], - cdr = _ref18[1]; + return Promise.all([car, cdr]).then(function (_ref21) { + var _ref22 = slicedToArray(_ref21, 2), + car = _ref22[0], + cdr = _ref22[1]; return new Pair(car, cdr); }); @@ -7649,11 +7793,11 @@ throw new Error('string->number: Invalid Syntax'); }, "(string->number number [radix])\n\n Function convert string to number."), // ------------------------------------------------------------------ - 'try': doc(new Macro('try', function (code, _ref19) { + 'try': doc(new Macro('try', function (code, _ref23) { var _this7 = this; - var dynamic_scope = _ref19.dynamic_scope, - _error = _ref19.error; + var dynamic_scope = _ref23.dynamic_scope, + _error = _ref23.error; return new Promise(function (resolve) { var args = { env: _this7, @@ -8097,9 +8241,9 @@ // ------------------------------------------------------------------ 'eq?': doc(equal, "(eq? a b)\n\n Function compare two values if they are identical."), // ------------------------------------------------------------------ - or: doc(new Macro('or', function (code, _ref20) { - var dynamic_scope = _ref20.dynamic_scope, - error = _ref20.error; + or: doc(new Macro('or', function (code, _ref24) { + var dynamic_scope = _ref24.dynamic_scope, + error = _ref24.error; var args = this.get('list->array')(code); var self = this; @@ -8139,9 +8283,9 @@ }), "(or . expressions)\n\n Macro execute the values one by one and return the one that is truthy value.\n If there are no expression that evaluate to true it return false."), // ------------------------------------------------------------------ and: doc(new Macro('and', function (code) { - var _ref21 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, - dynamic_scope = _ref21.dynamic_scope, - error = _ref21.error; + var _ref25 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, + dynamic_scope = _ref25.dynamic_scope, + error = _ref25.error; var args = this.get('list->array')(code); var self = this; @@ -8577,10 +8721,10 @@ } } - function getFunctionArgs(rest, _ref22) { - var env = _ref22.env, - dynamic_scope = _ref22.dynamic_scope, - error = _ref22.error; + function getFunctionArgs(rest, _ref26) { + var env = _ref26.env, + dynamic_scope = _ref26.dynamic_scope, + error = _ref26.error; var args = []; var node = rest; markCycles(node); @@ -8653,11 +8797,11 @@ function evaluate(code) { - var _ref23 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, - env = _ref23.env, - dynamic_scope = _ref23.dynamic_scope, - _ref23$error = _ref23.error, - error = _ref23$error === void 0 ? function () {} : _ref23$error; + var _ref27 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, + env = _ref27.env, + dynamic_scope = _ref27.dynamic_scope, + _ref27$error = _ref27.error, + error = _ref27$error === void 0 ? function () {} : _ref27$error; try { if (dynamic_scope === true) { @@ -8988,10 +9132,10 @@ var banner = function () { // Rollup tree-shaking is removing the variable if it's normal string because - // obviously 'Wed, 13 May 2020 09:37:06 +0000' == '{{' + 'DATE}}'; can be removed + // obviously 'Sat, 16 May 2020 21:13:32 +0000' == '{{' + 'DATE}}'; can be removed // but disablig Tree-shaking is adding lot of not used code so we use this // hack instead - var date = LString('Wed, 13 May 2020 09:37:06 +0000').valueOf(); + var date = LString('Sat, 16 May 2020 21:13:32 +0000').valueOf(); var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date); @@ -9024,7 +9168,7 @@ var lips = { version: 'DEV', banner: banner, - date: 'Wed, 13 May 2020 09:37:06 +0000', + date: 'Sat, 16 May 2020 21:13:32 +0000', exec: exec, parse: parse, tokenize: tokenize, diff --git a/dist/lips.min.js b/dist/lips.min.js index ce3591d7..f68faa65 100644 --- a/dist/lips.min.js +++ b/dist/lips.min.js @@ -24,6 +24,6 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Wed, 13 May 2020 09:37:06 +0000 + * build: Sat, 16 May 2020 21:13:32 +0000 */ -(function(){"use strict";function e(e,n){return n={exports:{}},e(n,n.exports),n.exports}var u=e(function(t){function r(e,n){t.exports=r=Object.setPrototypeOf||function e(n,t){n.__proto__=t;return n};return r(e,n)}t.exports=r});function n(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Date.prototype.toString.call(Reflect.construct(Date,[],function(){}));return true}catch(e){return false}}var a=n;var Kn=e(function(r){function i(e,n,t){if(a()){r.exports=i=Reflect.construct}else{r.exports=i=function e(n,t,r){var i=[null];i.push.apply(i,t);var a=Function.bind.apply(n,i);var o=new a;if(r)u(o,r.prototype);return o}}return i.apply(null,arguments)}r.exports=i});var t=e(function(e){var n=function(o){var e=Object.prototype;var f=e.hasOwnProperty;var c;var n=typeof Symbol==="function"?Symbol:{};var i=n.iterator||"@@iterator";var t=n.asyncIterator||"@@asyncIterator";var r=n.toStringTag||"@@toStringTag";function u(e,n,t,r){var i=n&&n.prototype instanceof s?n:s;var a=Object.create(i.prototype);var o=new F(r||[]);a._invoke=S(e,t,o);return a}o.wrap=u;function l(e,n,t){try{return{type:"normal",arg:e.call(n,t)}}catch(e){return{type:"throw",arg:e}}}var p="suspendedStart";var h="suspendedYield";var v="executing";var d="completed";var m={};function s(){}function a(){}function y(){}var g={};g[i]=function(){return this};var b=Object.getPrototypeOf;var w=b&&b(b(A([])));if(w&&w!==e&&f.call(w,i)){g=w}var _=y.prototype=s.prototype=Object.create(g);a.prototype=_.constructor=y;y.constructor=a;y[r]=a.displayName="GeneratorFunction";function x(e){["next","throw","return"].forEach(function(n){e[n]=function(e){return this._invoke(n,e)}})}o.isGeneratorFunction=function(e){var n=typeof e==="function"&&e.constructor;return n?n===a||(n.displayName||n.name)==="GeneratorFunction":false};o.mark=function(e){if(Object.setPrototypeOf){Object.setPrototypeOf(e,y)}else{e.__proto__=y;if(!(r in e)){e[r]="GeneratorFunction"}}e.prototype=Object.create(_);return e};o.awrap=function(e){return{__await:e}};function k(u,c){function s(e,n,t,r){var i=l(u[e],u,n);if(i.type==="throw"){r(i.arg)}else{var a=i.arg;var o=a.value;if(o&&typeof o==="object"&&f.call(o,"__await")){return c.resolve(o.__await).then(function(e){s("next",e,t,r)},function(e){s("throw",e,t,r)})}return c.resolve(o).then(function(e){a.value=e;t(a)},function(e){return s("throw",e,t,r)})}}var n;function e(t,r){function e(){return new c(function(e,n){s(t,r,e,n)})}return n=n?n.then(e,e):e()}this._invoke=e}x(k.prototype);k.prototype[t]=function(){return this};o.AsyncIterator=k;o.async=function(e,n,t,r,i){if(i===void 0)i=Promise;var a=new k(u(e,n,t,r),i);return o.isGeneratorFunction(n)?a:a.next().then(function(e){return e.done?e.value:a.next()})};function S(o,u,c){var s=p;return function e(n,t){if(s===v){throw new Error("Generator is already running")}if(s===d){if(n==="throw"){throw t}return I()}c.method=n;c.arg=t;while(true){var r=c.delegate;if(r){var i=O(r,c);if(i){if(i===m)continue;return i}}if(c.method==="next"){c.sent=c._sent=c.arg}else if(c.method==="throw"){if(s===p){s=d;throw c.arg}c.dispatchException(c.arg)}else if(c.method==="return"){c.abrupt("return",c.arg)}s=v;var a=l(o,u,c);if(a.type==="normal"){s=c.done?d:h;if(a.arg===m){continue}return{value:a.arg,done:c.done}}else if(a.type==="throw"){s=d;c.method="throw";c.arg=a.arg}}}}function O(e,n){var t=e.iterator[n.method];if(t===c){n.delegate=null;if(n.method==="throw"){if(e.iterator["return"]){n.method="return";n.arg=c;O(e,n);if(n.method==="throw"){return m}}n.method="throw";n.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var r=l(t,e.iterator,n.arg);if(r.type==="throw"){n.method="throw";n.arg=r.arg;n.delegate=null;return m}var i=r.arg;if(!i){n.method="throw";n.arg=new TypeError("iterator result is not an object");n.delegate=null;return m}if(i.done){n[e.resultName]=i.value;n.next=e.nextLoc;if(n.method!=="return"){n.method="next";n.arg=c}}else{return i}n.delegate=null;return m}x(_);_[r]="Generator";_[i]=function(){return this};_.toString=function(){return"[object Generator]"};function j(e){var n={tryLoc:e[0]};if(1 in e){n.catchLoc=e[1]}if(2 in e){n.finallyLoc=e[2];n.afterLoc=e[3]}this.tryEntries.push(n)}function E(e){var n=e.completion||{};n.type="normal";delete n.arg;e.completion=n}function F(e){this.tryEntries=[{tryLoc:"root"}];e.forEach(j,this);this.reset(true)}o.keys=function(t){var r=[];for(var e in t){r.push(e)}r.reverse();return function e(){while(r.length){var n=r.pop();if(n in t){e.value=n;e.done=false;return e}}e.done=true;return e}};function A(n){if(n){var e=n[i];if(e){return e.call(n)}if(typeof n.next==="function"){return n}if(!isNaN(n.length)){var t=-1,r=function e(){while(++t=0;--n){var i=this.tryEntries[n];var a=i.completion;if(i.tryLoc==="root"){return e("end")}if(i.tryLoc<=this.prev){var o=f.call(i,"catchLoc");var u=f.call(i,"finallyLoc");if(o&&u){if(this.prev=0;--t){var r=this.tryEntries[t];if(r.tryLoc<=this.prev&&f.call(r,"finallyLoc")&&this.prev=0;--n){var t=this.tryEntries[n];if(t.finallyLoc===e){this.complete(t.completion,t.afterLoc);E(t);return m}}},catch:function(e){for(var n=this.tryEntries.length-1;n>=0;--n){var t=this.tryEntries[n];if(t.tryLoc===e){var r=t.completion;if(r.type==="throw"){var i=r.arg;E(t)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,t){this.delegate={iterator:A(e),resultName:n,nextLoc:t};if(this.method==="next"){this.arg=c}return m}};return o}(e.exports);try{regeneratorRuntime=n}catch(e){Function("r","regeneratorRuntime = r")(n)}});var Zn=t;function c(e,n,t,r,i,a,o){try{var u=e[a](o);var c=u.value}catch(e){t(e);return}if(u.done){n(c)}else{Promise.resolve(c).then(r,i)}}function r(u){return function(){var e=this,o=arguments;return new Promise(function(n,t){var r=u.apply(e,o);function i(e){c(r,n,t,i,a,"next",e)}function a(e){c(r,n,t,i,a,"throw",e)}i(undefined)})}}var et=r;function i(e){if(Array.isArray(e))return e}var o=i;function s(e){if(typeof Symbol!=="undefined"&&Symbol.iterator in Object(e))return Array.from(e)}var f=s;function l(e,n){if(n==null||n>e.length)n=e.length;for(var t=0,r=new Array(n);t=0)continue;t[i]=e[i]}return t}var F=E;function A(e,n){if(e==null)return{};var t=F(e,n);var r,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,r))continue;t[r]=e[r]}}return t}var at=A;var ot=e(function(n){function t(e){"@babel/helpers - typeof";if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){n.exports=t=function e(n){return typeof n}}else{n.exports=t=function e(n){return n&&typeof Symbol==="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n}}return t(e)}n.exports=t});function ut(n){if(typeof Symbol==="undefined"||n[Symbol.iterator]==null){if(Array.isArray(n)||(n=I(n))){var t=0;var e=function e(){};return{s:e,n:function e(){if(t>=n.length)return{done:true};return{done:false,value:n[t++]}},e:function e(n){throw n},f:e}}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 r,i=true,a=false,o;return{s:function e(){r=n[Symbol.iterator]()},n:function e(){var n=r.next();i=n.done;return n},e:function e(n){a=true;o=n},f:function e(){try{if(!i&&r["return"]!=null)r["return"]()}finally{if(a)throw o}}}}function I(e,n){if(!e)return;if(typeof e==="string")return L(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);if(t==="Object"&&e.constructor)t=e.constructor.name;if(t==="Map"||t==="Set")return Array.from(e);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return L(e,n)}function L(e,n){if(n==null||n>e.length)n=e.length;for(var t=0,r=new Array(n);t1&&arguments[1]!==x?arguments[1]:1;return e[e.length-n]}function S(e){if(typeof e==="string"){var n=/([-\\^$[\]()+{}?*.|])/g;return e.replace(n,"\\$1")}}function O(){this.data=[]}O.prototype.push=function(e){this.data.push(e)};O.prototype.top=function(){return this.data[this.data.length-1]};O.prototype.pop=function(){return this.data.pop()};O.prototype.is_empty=function(){return!this.data.length};function j(e){var a=w();e=e.replace(/\n\r|\r/g,"\n");var o=0;var u=0;var c=[];var s=[];var f=0;e.split(g).filter(Boolean).forEach(function(e){if(e.match(g)){f=0;if(s.length){var n=_(s);if(n.token.match(/\n/)){var t=n.token.split("\n").pop();f+=t.length}else{f+=n.token.length}f+=n.col}var r={col:f,line:u,token:e,offset:o};c.push(r);s.push(r);o+=e.length;f+=e.length;u+=(e.match("\n")||[]).length;return}var i=e.split(a).filter(Boolean);i.forEach(function(e){var n={col:f,line:u,token:e,offset:o};f+=e.length;o+=e.length;c.push(n);s.push(n);if(e==="\n"){++u;s=[];f=0}})});return c}function E(e){var n=e.token,t=at(e,["token"]);if(n.match(/^"[\s\S]+"$/)&&n.match(/\n/)){var r=new RegExp("^ {1,"+(e.col+1)+"}","mg");n=n.replace(r,"")}return ct({token:n},t)}function F(e,n){var t=arguments.length>2&&arguments[2]!==x?arguments[2]:E;if(n){return j(e).map(t)}else{return j(e).map(function(e){var n=t(e);if(!n||typeof n.token!=="string"){throw new Error("[tokenize] Invalid formatter wrong return object")}if(n.token==="#\\ "){return n.token}return n.token.trim()}).filter(function(e){return e&&!e.match(/^;/)})}}var A={LITERAL:Symbol["for"]("literal"),SPLICE:Symbol["for"]("splice"),names:function e(){return Object.keys(this._specials)},type:function e(n){return this.get(n).type},get:function e(n){return this._specials[n]},append:function e(n,t,r){this._specials[n]={seq:n,symbol:t,type:r}},_specials:{}};function I(e){return A.type(e)===A.LITERAL}var L=[["'",new ne("quote"),A.LITERAL],["`",new ne("quasiquote"),A.LITERAL],[",@",new ne("unquote-splicing"),A.LITERAL],[",",new ne("unquote"),A.LITERAL]];L.forEach(function(e){var n=rt(e,3),t=n[0],r=n[1],i=n[2];A.append(t,r,i)});function N(e){if(typeof e==="string"){e=F(e)}var c=[];var s=[];var f=null;var l=A.names();var p=l.map(function(e){return A.get(e).symbol.name});var h=0;var v=false;var d=[];var m=[];var y=0;var g=ne(Symbol["for"]("__splice__"));function b(e){return e==="("||e==="["}function w(e){return e===")"||e==="]"}function _(){var e=c[c.length-1];if(e instanceof Array&&e[0]instanceof ne&&p.includes(e[0].name)&&c.length>1&&!e[0].literal){c.pop();if(c[c.length-1].length===1&&c[c.length-1][0]instanceof ne){c[c.length-1].push(e)}else if(c[c.length-1]instanceof ie){if(c[c.length-1].cdr instanceof ie){c[c.length-1]=new ie(c[c.length-1],ie.fromArray(e))}else{c[c.length-1].cdr=ie.fromArray(e)}}else{c[c.length-1].push(e)}}}e.forEach(function(e){var n=c[c.length-1];if(l.indexOf(e)!==-1){y++;f=e;c.push([A.get(f).symbol]);if(!f){m=[]}m.push(f)}else{if(f){d.push(m);m=[]}if(b(e)){v=true;h++;var t=[];if(f&&!I(f)){t.push(g)}c.push(t);f=null;y=0}else if(e==="."&&!v){c[c.length-1]=ie.fromArray(n)}else if(w(e)){h--;if(!c.length){throw new Error("Unbalanced parenthesis")}if(c.length===1){var r=c.pop();if(r instanceof Array&&r.length===0){r=re}s.push(r)}else if(c.length>1){var i=c.pop();n=c[c.length-1];if(n instanceof Array){if(i.length===0){n.push(re)}else if(i instanceof Array&&i[0]===g){var a;(a=n).push.apply(a,tt(i.slice(1)))}else{n.push(i)}}else if(n instanceof ie){if(i.length===0){n.append(re)}else{n.append(ie.fromArray(i))}}if(d.length){m=d.pop();while(m.length){_();m.pop()}}else{_()}}if(h===0&&c.length){s.push(c.pop())}}else{v=false;var o=k(e);if(f){while(y--){c[c.length-1].push(o);o=c.pop()}d.pop();y=0;f=false}else if(o instanceof ne&&p.includes(o.name)){o.literal=true}n=c[c.length-1];if(n instanceof ie){var u=n;while(true){if(u.cdr===re){if(o instanceof Array){u.cdr=ie.fromArray(o)}else{u.cdr=o}break}else{u=u.cdr}}}else if(!c.length){s.push(o)}else{n.push(o)}}}});if(!e.filter(function(e){return e.match(/^[[\]()]$/)}).length&&c.length){s=s.concat(c);c=[]}if(c.length){throw new Error("Unbalanced parenthesis 2")}return s.map(function(e){if(e instanceof Array){return ie.fromArray(e)}return e})}function q(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:function(e){return e};var t=arguments.length>2&&arguments[2]!==x?arguments[2]:null;if(e instanceof Array){var r=e.filter(we);if(r.length){return q(Promise.all(r),n,t)}return n(e)}if(we(e)){var i=e.then(n);if(t===null){return i}else{return i["catch"](t)}}return n(e)}function P(e,n){if(n instanceof RegExp){return function(e){return String(e).match(n)}}else if(typeof n!=="function"){throw new Error("".concat(e," argument need to be a function or RegExp"))}else{return n}}function C(e,n,t){if(n){if(t){e.__doc__=n}else{e.__doc__=M(n)}}return e}function M(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function R(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:1;var t=e.length;if(n<=0){throw Error("previousSexp: Invlaid argument sexp = ".concat(n))}e:while(n--&&t>=0){var r=1;while(r>0){var i=e[--t];if(!i){break e}if(i==="("||i.token==="("){r--}else if(i===")"||i.token===")"){r++}}t--}return e.slice(t+1)}function T(e){if(!e||!e.length){return 0}var n=e.length;if(e[n-1].token==="\n"){return 0}while(--n){if(e[n].token==="\n"){var t=(e[n+1]||{}).token;if(t){return t.length}}}return 0}function B(e,n){return s(e,n)===n.length;function s(e,n){function t(){return i>0&&o>0&&e[i-1]===n[o-1]&&e[i+1]===n[o]}function r(){return e[i]===Symbol["for"]("symbol")&&!y(n[o])}var i=0;var a={};for(var o=0;o0){continue}}else if(r()){return-1}}else if(e[i]instanceof Array){var c=s(e[i],n.slice(o));if(c===-1||c+o>n.length){return-1}o+=c-1;i++;continue}else{return-1}i++}if(e.length!==i){return-1}return n.length}}function D(e){this._code=e.replace(/\r/g,"")}D.defaults={offset:0,indent:2,exceptions:{specials:[/^define/,"lambda","let*",/^(let|letrec)(-syntax)?$/,"let-env","syntax-rules","try","catch"],shift:{1:["&","#"]}}};D.match=B;D.prototype._options=function e(n){var t=D.defaults;if(typeof n==="undefined"){return Object.assign({},t)}var r=n&&n.exceptions||{};var i=r.specials||[];var a=r.shift||{1:[]};return ct(ct(ct({},t),n),{},{exceptions:{specials:[].concat(tt(t.exceptions.specials),tt(i)),shift:ct(ct({},a),{},{1:[].concat(tt(t.exceptions.shift[1]),tt(a[1]))})}})};D.prototype.indent=function e(n){var t=F(this._code,true);return this._indent(t,n)};D.exception_shift=function(a,e){function n(e){if(!e.length){return false}if(e.indexOf(a)!==-1){return true}else{var n=e.filter(function(e){return e instanceof RegExp});if(!n.length){return false}var t=ut(n),r;try{for(t.s();!(r=t.n()).done;){var i=r.value;if(a.match(i)){return true}}}catch(e){t.e(e)}finally{t.f()}}return false}if(n(e.exceptions.specials)){return e.indent}var t=e.exceptions.shift;for(var r=0,i=Object.entries(t);r0){r.offset=0}if(a.toString()===n.toString()&&zn(a)){return r.offset+a[0].col}else if(a.length===1){return r.offset+a[0].col+1}else{var u=-1;if(o){var c=D.exception_shift(o.token,r);if(c!==-1){u=c}}if(u===-1){u=D.exception_shift(a[1].token,r)}if(u!==-1){return r.offset+a[0].col+u}else if(a[0].line3&&a[1].line===a[3].line){if(a[1].token==="("||a[1].token==="["){return r.offset+a[1].col}return r.offset+a[3].col}else if(a[0].line===a[1].line){return r.offset+r.indent+a[0].col}else{var s=a.slice(2);for(var f=0;f1&&arguments[1]!==x?arguments[1]:true;if(e instanceof ie){return e}if(n===false){var t=re;for(var r=e.length;r--;){t=new ie(e[r],t)}return t}if(e.length&&!(e instanceof Array)){e=tt(e)}if(e.length===0){return re}else{var i;if(e[0]instanceof Array){i=ie.fromArray(e[0])}else{i=e[0]}if(typeof i==="string"){i=Ve(i)}if(e.length===1){return new ie(i,re)}else{return new ie(i,ie.fromArray(e.slice(1)))}}};ie.prototype.toObject=function(){var e=arguments.length>0&&arguments[0]!==x?arguments[0]:false;var n=this;var t={};while(true){if(n instanceof ie&&n.car instanceof ie){var r=n.car;var i=r.car;if(i instanceof ne){i=i.name}if(i instanceof String){i=i.valueOf()}var a=r.cdr;if(a instanceof ie){a=a.toObject(e)}if(a instanceof nn||a instanceof Ve||a instanceof ze){if(!e){a=a.valueOf()}}t[i]=a;n=n.cdr}else{break}}return t};ie.fromPairs=function(e){return e.reduce(function(e,n){return new ie(new ie(new ne(n[0]),n[1]),e)},re)};ie.fromObject=function(n){var e=Object.keys(n).map(function(e){return[e,n[e]]});return ie.fromPairs(e)};ie.prototype.reduce=function(e){var n=this;var t=re;while(true){if(n!==re){t=e(t,n.car);n=n.cdr}else{break}}return t};ie.prototype.reverse=function(){if(this.haveCycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var n=re;while(e!==re){var t=e.cdr;e.cdr=n;n=e;e=t}return n};ie.prototype.transform=function(r){function i(e){if(e instanceof ie){if(e.replace){delete e.replace;return e}var n=r(e.car);if(n instanceof ie){n=i(n)}var t=r(e.cdr);if(t instanceof ie){t=i(t)}return new ie(n,t)}return e}return i(this)};ie.prototype.map=function(e){if(typeof this.car!=="undefined"){return new ie(e(this.car),this.cdr===re?re:this.cdr.map(e))}else{return re}};function oe(n,t){if(typeof jQuery!=="undefined"&&n instanceof jQuery.fn.init){return"#"}if(n===true){return"#t"}if(n===false){return"#f"}if(typeof n==="undefined"){return"#"}if(n instanceof ie){return n.toString(t)}var e=[RegExp,te,ne,nn,ze,On];for(var r=0,i=e;r"}return"#"}if(n instanceof Array){var o=[];for(var u=0,c=n.length;u")}else{o.push(oe(n[u],true))}}return"#("+o.join(" ")+")"}if(n instanceof Ve){n=n.toString()}if(n===null||typeof n==="string"&&t){return JSON.stringify(n).replace(/\\n/g,"\n")}if(p.HTMLElement&&n instanceof p.HTMLElement){return"#")}if(ot(n)==="object"){if(typeof n.toString==="function"&&n.toString.__lambda__){return n.toString().valueOf()}var s=n.constructor;var f=ot(n)==="object"&&s===Object;if(f){return"&("+Object.keys(n).map(function(e){return":".concat(e," ").concat(oe(n[e],t))}).join(" ")+")"}var l;if(typeof s.__className==="string"){l=s.__className}else if(Bn(n)==="instance"){l="instance"}else{l=s.name}if(l!==""){return"#<"+l+">"}return"#"}if(typeof n!=="string"){return n.toString()}return n}ie.prototype.markCycles=function(){ue(this);return this};ie.prototype.haveCycles=function(){var e=arguments.length>0&&arguments[0]!==x?arguments[0]:null;if(!e){return this.haveCycles("car")||this.haveCycles("cdr")}return!!(this.cycles&&this.cycles[e])};function ue(e){var i=[];var n=[];function a(e){if(e instanceof ie){if(i.includes(e)){if(!n.includes(e)){n.push(e)}return"#".concat(n.length-1,"#")}}}function o(e){if(e instanceof ie){i.push(e);var n={};var t=a(e.car);var r=a(e.cdr);if(t){n["car"]=t}else{o(e.car)}if(r){n["cdr"]=r}else{o(e.cdr)}if(t||r){e.cycles=n}else if(e.cycles){delete e.cycles}}}o(e)}ie.prototype.toString=function(e){var n=["("];if(this.car!==x){var t;if(this.cycles&&this.cycles.car){t=this.cycles.car}else{t=oe(this.car,e)}if(t!==x){n.push(t)}if(this.cdr instanceof ie){if(this.cycles&&this.cycles.cdr){n.push(" . ");n.push(this.cycles.cdr)}else{var r=this.cdr.toString(e).replace(/^\(|\)$/g,"");n.push(" ");n.push(r)}}else if(typeof this.cdr!=="undefined"&&this.cdr!==re){n=n.concat([" . ",oe(this.cdr,e)])}}n.push(")");return n.join("")};ie.prototype.set=function(e,n){this[e]=n;if(n instanceof ie){this.markCycles()}};ie.prototype.append=function(e){if(e instanceof Array){return this.append(ie.fromArray(e))}var n=this;if(n.car===x){if(e instanceof ie){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(e!==re){while(true){if(n instanceof ie&&n.cdr!==re){n=n.cdr}else{break}}n.cdr=e}return this};function ce(e){return e<0?-e:e}function se(e,n){var t=nt(n),r=t[0],i=t.slice(1);while(i.length>0){var a=i,o=rt(a,1),u=o[0];if(!e(r,u)){return false}var c=i;var s=nt(c);r=s[0];i=s.slice(1)}return true}function fe(e,n){if(typeof e==="function"&&typeof n==="function"){return Se(e)===Se(n)}else if(e instanceof nn&&n instanceof nn){return e.type===n.type&&e.cmp(n)===0}else if(typeof e==="number"||typeof n==="number"){e=nn(e);n=nn(n);return e.type===n.type&&e.cmp(n)===0}else if(e instanceof ze&&n instanceof ze){return e["char"]===n["char"]}else if(e instanceof ne&&n instanceof ne){return e.name===n.name}else{return e===n}}var le=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function pe(e,n,t,r){if(typeof this!=="undefined"&&this.constructor!==pe||typeof this==="undefined"){return new pe(e,n)}Rn("Macro",e,"string",1);Rn("Macro",n,"function",2);if(t){if(r){this.__doc__=t}else{this.__doc__=M(t)}}this.name=e;this.fn=n}pe.defmacro=function(e,n,t,r){var i=new pe(e,n,t,r);i.defmacro=true;return i};pe.prototype.invoke=function(e,n,t){var r=n.env,i=n.dynamic_scope,a=n.error;var o={dynamic_scope:i,error:a,macro_expand:t};var u=this.fn.call(r,e,o,this.name);return u};pe.prototype.toString=function(){return"#"};var he="define-macro";function ve(i){return function(){var t=et(Zn.mark(function e(t,f){var l,p,r;return Zn.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:r=function e(){r=et(Zn.mark(function e(t,r){var i,a,o,u,c,s;return Zn.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(!(t instanceof ie&&t.car instanceof ne)){n.next=17;break}if(!t.data){n.next=3;break}return n.abrupt("return",t);case 3:i=l.get(t.car,{throwError:false});if(!(i instanceof pe&&i.defmacro)){n.next=17;break}a=i instanceof de?t:t.cdr;n.next=8;return i.invoke(a,f,true);case 8:o=n.sent;if(!(o instanceof ne)){n.next=11;break}return n.abrupt("return",jn(o));case 11:if(!(o instanceof ie)){n.next=17;break}if(!(typeof r==="number")){n.next=16;break}if(!(r<=1)){n.next=15;break}return n.abrupt("return",o);case 15:r=r-1;case 16:return n.abrupt("return",p(o,r));case 17:u=t.car;if(!(u instanceof ie)){n.next=22;break}n.next=21;return p(u);case 21:u=n.sent;case 22:c=t.cdr;if(!(c instanceof ie)){n.next=27;break}n.next=26;return p(c);case 26:c=n.sent;case 27:s=new ie(u,c);return n.abrupt("return",s);case 29:case"end":return n.stop()}}},e)}));return r.apply(this,arguments)};p=function e(n,t){return r.apply(this,arguments)};l=f["env"]=this;if(!i){n.next=11;break}n.t0=jn;n.next=7;return p(t,1);case 7:n.t1=n.sent.car;return n.abrupt("return",(0,n.t0)(n.t1));case 11:n.t2=jn;n.next=14;return p(t,-1);case 14:n.t3=n.sent.car;return n.abrupt("return",(0,n.t2)(n.t3));case 16:case"end":return n.stop()}}},e,this)}));return function(e,n){return t.apply(this,arguments)}}()}function de(e,n){this.name="syntax";this.env=n;this.fn=e;this.defmacro=true}de.merge_env=Symbol["for"]("merge");de.prototype=Object.create(pe.prototype);de.prototype.invoke=function(e,n,t){var r=n.error,i=n.env;var a={error:r,env:i,dynamic_scope:this.env,macro_expand:t};return this.fn.call(i,e,a,this.name)};de.prototype.constructor=de;de.prototype.toString=function(){return"<#syntax>"};de.className="syntax";function me(e,n,d,m){var y={"...":{symbols:{},lists:[]}};function g(e){if(An.get("DEBUG",{throwError:false})){console.log(e)}}g(d);function b(e,n){var t=arguments.length>2&&arguments[2]!==x?arguments[2]:[];var r=arguments.length>3&&arguments[3]!==x?arguments[3]:false;g({code:n.toString(),pattern:e.toString()});if(e instanceof ie&&e.car instanceof ie&&e.car.cdr instanceof ie&&ne.is(e.car.cdr.car,m)){g(">> 0");if(n===re){g({pattern:e.toString()});if(e.car.car instanceof ne){if(e.car.cdr instanceof ie&&ne.is(e.car.cdr.car,m)){var i=e.car.car.valueOf();var a=e.lastPair();if(ne.is(a.car,m)){y["..."].symbols[i]=null;return true}else{return false}}var o=e.car.car.valueOf();if(y["..."].symbols[o]){throw new Error("syntax: named ellipsis can only "+"appear onces")}y["..."].symbols[o]=n}return true}}if(e instanceof ie&&e.cdr instanceof ie&&ne.is(e.cdr.car,m)){if(e.cdr.cdr!==re){throw new Error("syntax: invalid usage of ellipsis")}if(e.car instanceof ne){var u=e.car.name;if(y["..."].symbols[u]&&!t.includes(u)&&!r){throw new Error("syntax: named ellipsis can only appear onces")}g(">> 1");if(n===re){g(">> 2");if(r){y["..."].symbols[u]=re}else{return false}}else if(n instanceof ie&&(n.car instanceof ie||n.car===re)){g(">> 3 "+r);if(r){if(y["..."].symbols[u]){var c=y["..."].symbols[u];y["..."].symbols[u]=c.append(new ie(n,re))}else{y["..."].symbols[u]=new ie(n,re)}}else{g(">> 4");y["..."].symbols[u]=new ie(n,re)}}else{g(">> 6");if(n instanceof ie){g(">> 7 "+r);t.push(u);if(!y["..."].symbols[u]){y["..."].symbols[u]=new ie(n,re)}else{var s=y["..."].symbols[u];y["..."].symbols[u]=s.append(new ie(n,re))}g({IIIIII:y["..."].symbols[u].toString()})}else{g(">> 8");return false}}return true}else if(e.car instanceof ie){var f=tt(t);if(n===re){g(">> 9");y["..."].lists.push(re);return true}g(">> 10");var l=n;while(l instanceof ie){if(!b(e.car,l.car,f,true)){return false}l=l.cdr}return true}return false}if(e instanceof ne){if(ne.is(e,m)){throw new Error("syntax: invalid usage of ellipsis")}g(">> 11");var p=e.name;if(d.includes(p)){return true}g({name:p});if(r){y["..."].symbols[p]=y["..."].symbols[p]||[];y["..."].symbols[p].push(n)}if(!y[p]){y[p]=n}return true}if(e instanceof ie&&n instanceof ie){g(">> 12");g(n.toString());if(n.cdr===re){var h=e.car instanceof ne&&e.cdr instanceof ne;if(h){g(">> 12 | 1");var v=e.cdr.valueOf();if(!y[v]){y[v]=re}v=e.car.valueOf();if(!y[v]){y[v]=n.car}return true}}if(b(e.car,n.car,t,r)&&b(e.cdr,n.cdr,t,r)){return true}}else if(e===re&&n===re){return true}else if(e.car instanceof ie&&ne.is(e.car.car,m)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(b(e,n)){return y}}function ye(e,i){function a(n){if(n instanceof ie){if(!i.length){return n}var e=a(n.car);var t=a(n.cdr);return new ie(e,t)}else if(n instanceof ne){var r=i.find(function(e){return e.gensym===n});if(r){return ne(r.name)}return n}else{return n}}return a(e)}function ge(){var e=arguments.length>0&&arguments[0]!==x?arguments[0]:{};var v=e.bindings,n=e.expr,r=e.scope,i=e.names,d=e.ellipsis;var a={};function m(e){if(!(e instanceof ne||typeof e==="string")){throw new Error("syntax: internal error, rename neeed to be symbol")}var n=e.valueOf();if(n===d){throw new Error("syntax: internal error, ellipis not transformed")}if(typeof n==="string"&&n in v){return v[n]}return t(n)}function y(e){if(An.get("DEBUG",{throwError:false})){console.log(e)}}function t(e){if(!a[e]){var n=r.get(e,{throwError:false});var t=En(e);i.push({name:e,gensym:t});if(typeof n!=="undefined"){r.set(t,n)}a[e]=t}return a[e]}function g(e,n,t){var r=arguments.length>3&&arguments[3]!==x?arguments[3]:function(){};y(" ==> "+e.toString());if(e instanceof ne){var i=e.valueOf();y("[t 1");if(n[i]){if(n[i]instanceof ie){var a=n[i],o=a.car,u=a.cdr;if(t){var c=o.car,s=o.cdr;if(s!==re){r(i,new ie(s,re))}return c}if(u!==re){r(i,u)}return o}else if(n[i]instanceof Array){r(i,n[i].slice(1));return n[i][0]}}return m(i)}if(e instanceof ie){if(e.car instanceof ne&&e.cdr instanceof ie&&ne.is(e.cdr.car,d)){y("[t 2");var f=e.car.valueOf();var l=n[f];if(l){y({b:n[f]});if(l instanceof ie){y("[t 2 Pair "+t);y({______:l.toString()});var p=l.car,h=l.cdr;if(t){if(h!==re){r(f,h)}return p}else{if(p.cdr!==re){r(f,new ie(p.cdr,h))}return p.car}}else if(l instanceof Array){y("[t 2 Array "+t);if(t){r(f,l.slice(1));return ie.fromArray(l)}else{var v=l.slice(1);if(v.length){r(f,v)}return l[0]}}else{return l}}}y("[t 3 recur "+e.toString());return new ie(g(e.car,n,t,r),g(e.cdr,n,t,r))}}function b(n){var e=Object.values(n);var t=Object.getOwnPropertySymbols(n);if(t.length){e.push.apply(e,tt(t.map(function(e){return n[e]})))}return e.length&&e.every(function(e){return e instanceof ie||e===re||e instanceof Array&&e.length})}function w(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function _(i){if(i instanceof ie){if(i.cdr instanceof ie&&ne.is(i.cdr.car,d)){y(">> 1");var e=v["..."].symbols;var n=w(e);if(i.car instanceof ie){if(v["..."].lists[0]===re){return re}y(">> 2");var t;if(n.length){y(">> 2 (a)");var a=ct({},e);t=re;var r=function e(){if(!b(a)){return"break"}var r={};var n=function e(n,t){r[n]=t};t=new ie(g(i.car,a,true,n),t);a=r};while(true){var o=r();if(o==="break")break}if(t!==re){t=t.reverse()}return t}else{y(">> 3");var u=g(i.car,e,true);if(u){return new ie(u,re)}return re}}else if(i.car instanceof ne){y(">> 4");var c=i.car.name;var s=it({},c,e[c]);var f=re;var l=function e(){if(!b(s)){y({bind:s});return"break"}var r={};var n=function e(n,t){r[n]=t};y({EXPR:i.toString()});var t=g(i,s,false,n);f=new ie(t,f);s=r};while(true){var p=l();if(p==="break")break}if(f!==re){f=f.reverse()}if(i.cdr instanceof ie&&i.cdr.cdr instanceof ie){f.append(_(i.cdr.cdr))}return f}}return new ie(_(i.car),_(i.cdr))}if(i instanceof ne){var h=m(i);if(typeof h!=="undefined"){return h}}return i}return _(n)}function be(e){return typeof e==="undefined"||e===re||e===null}function we(e){return e instanceof Promise||e&&typeof e!=="undefined"&&typeof e.then==="function"}function _e(e){switch(ot(e)){case"string":return Ve(e);case"number":return nn(e)}return e}function xe(e){return e&&e.valueOf&&e.valueOf()||e}function ke(e,n){if(e instanceof ie){e.markCycles();return jn(e)}if(typeof e==="function"){if(n){return Oe(e,n)}}return _e(e)}function Se(e){if(je(e)){return e[Ee]}return e}function Oe(n,e){if(n[Symbol["for"]("__bound__")]){return n}var t=n.bind(e);var r=Object.getOwnPropertyNames(n).filter(Ae);r.forEach(function(e){try{t[e]=n[e]}catch(e){}});Ie(t,"__fn__",n);Ie(t,"__bound__",true);if(Ne(n)){Ie(t,"__native__",true)}t.valueOf=function(){return n};return t}function je(e){return typeof e==="function"&&e[Ee]}var Ee=Symbol["for"]("__fn__");var Fe=["name","length","caller","callee","arguments","prototype"];function Ae(e){return!Fe.includes(e)}function Ie(e,n,t){Object.defineProperty(e,Symbol["for"](n),{get:function e(){return t},set:function e(){},configurable:false,enumerable:false})}function Le(n,t){try{Object.defineProperty(n,"length",{get:function e(){return t}});return n}catch(e){var r=new Array(t).fill(0).map(function(e,n){return"a"+n}).join(",");var i=new Function("f","return function(".concat(r,") {\n return f.apply(this, arguments);\n };"));return i(n)}}function Ne(e){var n=Symbol["for"]("__native__");return typeof e==="function"&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[n]===true||!e.name.match(/^bound /)&&!e[n])}function qe(e){var d;switch(e){case Symbol["for"]("letrec"):d="letrec";break;case Symbol["for"]("let"):d="let";break;case Symbol["for"]("let*"):d="let*";break;default:throw new Error("Invalid let_macro value")}return pe.defmacro(d,function(n,e){var o=e.dynamic_scope,u=e.error,t=e.macro_expand;var c;if(n.car instanceof ne){if(!(n.cdr.car instanceof ie||n.cdr.car===re)){throw new Error("let require list of pairs")}var r;if(n.cdr.car===re){c=re;r=re}else{r=n.cdr.car.map(function(e){return e.car});c=n.cdr.car.map(function(e){return e.cdr.car})}return ie.fromArray([ne("letrec"),[[n.car,ie(ne("lambda"),ie(r,n.cdr.cdr))]],ie(n.car,c)])}else if(t){return}var s=this;c=this.get("list->array")(n.car);var f=s.inherit(d);var l,p;if(d==="let*"){p=f}else if(d==="let"){l=[]}var h=0;function v(){var e=new ie(new ne("begin"),n.cdr);return Un(e,{env:f,dynamic_scope:o,error:u})}return function n(){var t=c[h++];function r(e,n){if(typeof n==="undefined"){f.set(e,re)}else{f.set(e,n)}}if(o){o=d==="let*"?f:s}if(!t){if(l&&l.length){var e=l.map(function(e){return e.value});var i=e.filter(we);if(i.length){return Promise.all(e).then(function(e){for(var n=0,t=e.length;n1&&arguments[1]!==x?arguments[1]:{},t=n.dynamic_scope,r=n.error;var i=this;if(t){t=this}var a=e;var o=[];while(a instanceof ie){o.push(Un(a.car,{env:i,dynamic_scope:t,error:r}));a=a.cdr}var u=o.filter(we).length;if(u){return Promise.all(o).then(c.bind(this))}else{return c.call(this,o)}})}function Ce(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r2?r-2:0),a=2;a1&&arguments[1]!==x?arguments[1]:null;return function(){for(var e=arguments.length,n=new Array(e),t=0;t1?e-1:0),t=1;t=o){return a.apply(this,r)}else{return i}}return i.apply(this,arguments)}}function Ue(r,i){Rn("limit",i,"function",2);return function(){for(var e=arguments.length,n=new Array(e),t=0;t1?r-1:0),a=1;a0){t.push(this._string.substring(0,e))}t.push(n);if(e1&&arguments[1]!==x?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof nn)||typeof this==="undefined"){return new nn(e,n)}if(typeof e==="undefined"){throw new Error("Invlaid LNumber constructor call")}var t=nn.getType(e);if(nn.types[t]){return nn.types[t](e,n)}var r=e instanceof Array&&Ve.isString(e[0])&&nn.isNumber(e[1]);if(e instanceof nn){return nn(e.value)}if(!nn.isNumber(e)&&!r){throw new Error("You can't create LNumber from ".concat(Bn(e)))}if(e===null){e=0}var i;if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(r){var a=e,o=rt(a,2),u=o[0],c=o[1];if(u instanceof Ve){u=u.valueOf()}if(c instanceof nn){c=c.valueOf()}var s;switch(c){case 8:s="0o";break;case 16:s="0x";break;case 2:s="0b";break;case 10:s="";break}if(typeof s==="undefined"){var f=BigInt(c);i=tt(u).map(function(e,n){return BigInt(parseInt(e,c))*Math.pow(f,BigInt(n))}).reduce(function(e,n){return e+n})}else{i=BigInt(s+u)}}else{i=BigInt(e)}}else{i=e}return fn(i,true)}else if(typeof d!=="undefined"&&!(e instanceof d)){if(e instanceof Array){return fn(Kn(d,tt(e)))}return fn(new d(e))}else if(r){var l=e,p=rt(l,2),h=p[0],v=p[1];if(h instanceof Ve){h=h.valueOf()}if(v instanceof nn){v=v.valueOf()}this.value=parseInt(h,v)}else{this.value=e}}nn.types={float:function e(n){var t=arguments.length>1&&arguments[1]!==x?arguments[1]:false;return new rn(n,t)},complex:function e(n){var t=arguments.length>1&&arguments[1]!==x?arguments[1]:false;return new tn(n,t)},rational:function e(n){var t=arguments.length>1&&arguments[1]!==x?arguments[1]:false;return new sn(n,t)}};function tn(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof tn)||typeof this==="undefined"){return new tn(e,n)}if(e instanceof tn){return tn({im:e.im,re:e.re})}if(nn.isNumber(e)&&n){e={im:0,re:e.valueOf()}}else if(!nn.isComplex(e)){throw new Error("Invalid constructor call for LComplex")}var t=nn.coerce(e.im,e.re),r=rt(t,2),i=r[0],a=r[1];if(i.cmp(0)===0){return a}this.im=i;this.re=a;this.type="complex"}tn.prototype=Object.create(nn.prototype);tn.prototype.constructor=tn;tn.prototype.toRational=function(e){if(nn.isFloat(this.im)&&nn.isFloat(this.re)){var n=rn(this.im).toRational(e);var t=rn(this.re).toRational(e);return tn({im:n,re:t})}return this};tn.prototype.add=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.op("+",n),im:t.op("+",r)}})};tn.prototype.div=function(e){if(nn.isNumber(e)&&!nn.isComplex(e)){e=tn({im:0,re:e})}else if(!nn.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var n=tn({re:e.re,im:e.im.sub()});var t=e.re.mul(e.re).add(e.im.mul(e.im));var r=this.mul(n);var i=r.re.op("/",t);var a=r.im.op("/",t);return tn({re:i,im:a})};tn.prototype.sub=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.sub(n),im:t.sum(r)}})};tn.prototype.mul=function(e){return this.complex_op(e,function(e,n,t,r){var i={re:e.mul(n).sub(t.mul(r)),im:e.mul(r).add(n.mul(t))};return i})};tn.prototype.complex_op=function(e,n){if(nn.isNumber(e)&&!nn.isComplex(e)){e={im:0,re:e}}else if(!nn.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var t=e.re instanceof nn?e.re:nn(e.re);var r=e.im instanceof nn?e.im:nn(e.im);var i=n(this.re,t,this.im,r);if("im"in i&&"re"in i){return tn(i)}return i};tn._op={"+":"add","-":"sub","*":"mul","/":"div"};tn.prototype._op=function(e,n){var t=tn._op[e];return this[t](n)};tn.prototype.cmp=function(e){var n=this.coerce(e),t=rt(n,2),r=t[0],i=t[1];var a=r.re.coerce(i.re),o=rt(a,2),u=o[0],c=o[1];var s=u.cmp(c);if(s!==0){return s}else{var f=r.im.coerce(i.im),l=rt(f,2),p=l[0],h=l[1];return p.cmp(h)}};tn.prototype.valueOf=function(){};tn.prototype.toString=function(){var e;if(this.re.cmp(0)!==0){e=[this.re.toString()]}else{e=[]}e.push(this.im.cmp(0)<0?"-":"+");e.push(this.im.toString().replace(/^-/,""));e.push("i");return e.join("")};function rn(e){if(typeof this!=="undefined"&&!(this instanceof rn)||typeof this==="undefined"){return new rn(e)}if(!nn.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof nn){return rn(e.valueOf())}if(typeof e==="number"){this.value=e;this.type="float"}}rn.prototype=Object.create(nn.prototype);rn.prototype.constructor=rn;rn.prototype.toString=function(){if(!nn.isFloat(this.value)){return this.value+".0"}return this.value.toString()};rn.prototype._op=function(e,n){if(n instanceof nn){n=n.value}var t=nn._ops[e];return rn(t(this.value,n))};rn.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==x?arguments[0]:null;if(e===null){return an(this.value.valueOf())}return on(e.valueOf())(this.value.valueOf())};var an=on(1e-10);function on(r){return function(e){var n=function e(r,n,t){var i=function e(n,t){return t0){i=cn(r,t)}else if(r.cmp(t)<=0){i=t}else if(t.cmp(0)>0){i=cn(t,r)}else if(n.cmp(0)<0){i=nn(cn(r.sub(),t.sub())).sub()}else{i=nn(0)}if(nn.isFloat(n)||nn.isFloat(e)){return rn(i)}return i}function cn(e,n){var t=nn(e).floor();var r=nn(n).floor();if(e.cmp(t)<1){return t}else if(t.cmp(r)===0){var i=nn(1).div(n.sub(r));var a=nn(1).div(e.sub(t));return t.add(nn(1).div(cn(i,a)))}else{return t.add(nn(1))}}function sn(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof sn)||typeof this==="undefined"){return new sn(e,n)}if(!nn.isRational(e)){throw new Error("Invalid constructor call for LRational")}if(e.num%e.denom===0&&!n){return nn(e.num/e.denom)}this.num=nn(e.num);this.denom=nn(e.denom);this.type="rational"}sn.prototype=Object.create(nn.prototype);sn.prototype.constructor=sn;sn.prototype.pow=function(e){var n=e.cmp(0);if(n===0){return nn(1)}if(n===-1){e=e.sub();var t=this.denom.pow(e);var r=this.num.pow(e);return sn({num:t,denom:r})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};sn.prototype.abs=function(){var e=this.num;var n=this.denom;if(e.cmp(0)===-1){e=e.sub()}if(n.cmp(0)!==1){n=n.sub()}return sn({num:e,denom:n})};sn.prototype.cmp=function(e){return nn(this.valueOf()).cmp(e)};sn.prototype.toString=function(){var e=Fn.get("gdc")(this.num,this.denom);var n,t;if(e.cmp(1)!==0){e=nn(e);n=this.num.div(e);t=this.denom.div(e)}else{n=this.num;t=this.denom}var r=this.cmp(0)<0;if(r){if(n.abs().cmp(t.abs())===0){return n.toString()}}else if(n.cmp(t)===0){return n.toString()}return n+"/"+t};sn.prototype.valueOf=function(){return rn(this.num.valueOf()).div(this.denom.valueOf())};sn.prototype.mul=function(e){if(nn.isRational(e)){var n=this.num.mul(e.num);var t=this.denom.mul(e.denom);return sn({num:n,denom:t})}return nn(this.valueOf()).mul(e)};sn.prototype.div=function(e){if(nn.isRational(e)){var n=this.num.mul(e.denom);var t=this.denom.mul(e.num);return sn({num:n,denom:t})}return nn(this.valueOf()).div(e)};sn.prototype._op=function(e,n){return this[vn[e]](n)};sn.prototype.sub=function(e){if(nn.isRational(e)){var n=e.num.sub();var t=e.denom;return this.add(sn({num:n,denom:t}))}if(!(e instanceof nn)){e=nn(e).sub()}else{e=e.sub()}if(nn.isFloat(e)){return rn(this.valueOf()).add(e)}return this.add(e)};sn.prototype.add=function(e){if(nn.isRational(e)){var n=this.denom;var t=e.denom;var r=this.num;var i=e.num;var a,o;if(n!==t){o=t.mul(r).add(i.mul(n));a=n.mul(t)}else{o=r.add(i);a=n}return sn({num:o,denom:a})}if(nn.isFloat(e)){return rn(this.valueOf()).add(e)}return nn(this.valueOf()).add(e)};function fn(e,n){if(typeof this!=="undefined"&&!(this instanceof fn)||typeof this==="undefined"){return new fn(e,n)}if(e instanceof fn){return fn(e.value,e._native)}if(!nn.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.value=e;this._native=n;this.type="bigint"}fn.prototype=Object.create(nn.prototype);fn.prototype.constructor=fn;fn.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};fn.prototype._op=function(e,n){if(typeof n==="undefined"){if(nn.isBN(this.value)){e=fn.bn_op[e];return fn(this.value.clone()[e](),false)}return fn(nn._ops[e](this.value))}if(nn.isBN(this.value)&&nn.isBN(n.value)){e=fn.bn_op[e];return fn(this.value.clone()[e](n),false)}if(e==="/"){return sn({num:this,denom:n})}var t=nn._ops[e](this.value,n.value);return fn(t)};fn.prototype.sqrt=function(){var e;var n=this.cmp(0)<0;if(nn.isNative(this.value)){e=Math.sqrt(n?-this.valueOf():this.valueOf())}else if(nn.isBN(this.value)){e=n?this.value.neg().sqrt():this.value.sqrt()}if(n){return tn({re:0,im:e})}return e};nn.isFloat=function e(n){return n instanceof rn||Number(n)===n&&n%1!==0};nn.isNumber=function(e){return e instanceof nn||!Number.isNaN(e)&&nn.isNative(e)||nn.isBN(e)};nn.isComplex=function(e){var n=e instanceof tn||nn.isNumber(e.im)&&nn.isNumber(e.re);return n};nn.isRational=function(e){return e instanceof sn||nn.isNumber(e.num)&&nn.isNumber(e.denom)};nn.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};nn.isBigInteger=function(e){return e instanceof fn||typeof e==="bigint"||nn.isBN(e)};nn.isBN=function(e){return typeof d!=="undefined"&&e instanceof d};nn.getArgsType=function(e,n){if(e instanceof rn||n instanceof rn){return rn}if(e instanceof fn||n instanceof fn){return fn}return nn};nn.prototype.toString=nn.prototype.toJSON=function(e){if(e>2&&e<36){return this.value.toString(e)}return this.value.toString()};nn.prototype.isBigNumber=function(){return typeof this.value==="bigint"||typeof d!=="undefined"&&!(this.value instanceof d)};["floor","ceil","round"].forEach(function(e){nn.prototype[e]=function(){if(this["float"]||nn.isFloat(this.value)){return nn(Math[e](this.value))}else{return nn(Math[e](this.valueOf()))}}});nn.prototype.valueOf=function(){if(nn.isNative(this.value)){return Number(this.value)}else if(nn.isBN(this.value)){return this.value.toNumber()}};var ln=function(){var e=function e(n,t){return[n,t]};return{bigint:{bigint:e,float:function e(n,t){return[rn(n.valueOf()),t]},rational:function e(n,t){return[{num:n,denom:1},t]},complex:function e(n,t){return[{im:0,re:n},t]}},float:{bigint:function e(n,t){return[n,rn(t.valueOf())]},float:e,rational:function e(n,t){return[n,rn(t.valueOf())]},complex:function e(n,t){return[{re:n,im:rn(0)},t]}},complex:{bigint:n("bigint"),float:n("float"),rational:n("rational"),complex:e},rational:{bigint:function e(n,t){return[n,{num:t,denom:1}]},float:function e(n,t){return[rn(n.valueOf()),t]},rational:e,complex:n("rational")}};function n(t){return function(e,n){return[{im:pn(t,e.im.type,e.im),re:pn(t,e.re.type,e.re)},{im:pn(t,e.type,0),re:pn(t,n.type,n)}]}}}();function pn(e,n,t){return ln[e][n](t)[0]}nn.coerce=function(e,n){function t(e){if(e==="integer"){return"bigint"}return e}var r=t(nn.getType(e));var i=t(nn.getType(n));if(!ln[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!ln[r][i]){throw new Error("LNumber::coerce unknown rhs type ".concat(i))}return ln[r][i](e,n).map(function(e){return nn(e,true)})};nn.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof nn)){throw new Error("LNumber: you can't coerce ".concat(Bn(e)))}if(typeof e==="number"){e=nn(e)}return nn.coerce(this,e)};nn.getType=function(e){if(e instanceof nn){return e.type}if(nn.isFloat(e)){return"float"}if(nn.isComplex(e)){return"complex"}if(nn.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof d!=="undefined"&&!(e instanceof d)){return"bigint"}};nn.prototype.isFloat=function(){return!!(nn.isFloat(this.value)||this["float"])};var hn={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var vn={};Object.keys(hn).forEach(function(n){vn[hn[n]]=n;nn.prototype[n]=function(e){return this.op(hn[n],e)}});nn._ops={"*":function e(n,t){return n*t},"+":function e(n,t){return n+t},"-":function e(n,t){if(typeof t==="undefined"){return-n}return n-t},"/":function e(n,t){return n/t},"%":function e(n,t){return n%t},"|":function e(n,t){return n|t},"&":function e(n,t){return n&t},"~":function e(n){return~n},">>":function e(n,t){return n>>t},"<<":function e(n,t){return n<"};function yn(n){var t=this;if(typeof this!=="undefined"&&!(this instanceof yn)||typeof this==="undefined"){return new yn(n)}Rn("OutputStringPort",n,"function");this._buffer=[];this.write=function(e){if(!Ve.isString(e)){e=n(e)}else{e=e.valueOf()}t._buffer.push(e)}}yn.prototype=Object.create(mn.prototype);yn.prototype.getString=function(){return this._buffer.map(function(e){return e.valueOf()}).join("")};yn.prototype.constructor=yn;function gn(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof gn)||typeof this==="undefined"){return new gn(e)}Rn("InputStringPort",e,"string");this._tokens=F(e);this._index=0;this._in_char=0;this.read=function(){return n.getNextTokens()}}gn.prototype=Object.create(dn.prototype);gn.prototype.constructor=gn;gn.prototype.getNextTokens=function(){if(this.peekChar()===bn){return bn}var e=0;var n=[];var t=["(",")"];if(!t.includes(this._tokens[this._index])){return this._tokens[this._index++]}do{var r=this._tokens[this._index];n.push(this._tokens[this._index]);if(r===")"){e--}else if(r==="("){e++}this._index++}while(e!==0);return n};gn.prototype.peekChar=function(){if(this._index>this._tokens.length-1){return bn}if(this._index===this._tokens.length-1&&this.in_char>this._tokens[this._index].length){return bn}return this._tokens[this._index][this.in_char]};var bn=new wn;function wn(){}wn.prototype.toString=function(){return"<#eof>"};function _n(e){this.message=e}_n.prototype=Object.create(Error.prototype);function xn(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:{};if(typeof this!=="undefined"&&!(this instanceof xn)||typeof this==="undefined"){return new xn(e,n)}if(typeof e==="undefined"){e="anonymous"}this.env=An.inherit(e,n)}xn.prototype.exec=function(){var n=et(Zn.mark(function e(t){var r,i=arguments;return Zn.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:r=i.length>1&&i[1]!==x?i[1]:false;Rn("Intepreter::exec",t,"string",1);Rn("Intepreter::exec",r,"boolean",2);Fn.set("**interaction-environment**",this.env);return n.abrupt("return",Yn(t,this.env,r?this.env:false));case 5:case"end":return n.stop()}}},e,this)}));return function(e){return n.apply(this,arguments)}}();xn.prototype.get=function(e){return this.env.get(e).bind(this.env)};xn.prototype.set=function(e,n){return this.env.set(e,n)};function kn(e,n,t){if(arguments.length===1){if(ot(arguments[0])==="object"){e=arguments[0];this.parent=null}else if(typeof arguments[0]==="string"){e={};n={};t=arguments[0]}}this.env=e;this.parent=n;this.name=t||"anonymous"}kn.prototype.inherit=function(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:{};if(ot(e)==="object"){n=e}if(!e||ot(e)==="object"){e="child of "+(this.name||"unknown")}return new kn(n||{},this,e)};kn.prototype.newFrame=function(e,n){var r=this.inherit("__frame__");r.set("parent.frame",C(function(){var e=arguments.length>0&&arguments[0]!==x?arguments[0]:1;var n=r.parent;if(!(n instanceof kn)){return re}if(e<=0){return n}var t=n.get("parent.frame");return t(e-1)},Fn.env["parent.frame"].__doc__));n.callee=e;r.set("arguments",n);return r};kn.prototype._lookup=function(e){if(e instanceof ne){e=e.name}if(e instanceof Ve){e=e.valueOf()}if(e in this.env){return Sn(this.env[e])}if(this.parent){return this.parent._lookup(e)}};kn.prototype.toString=function(){return"<#env:"+this.name+">"};kn.prototype.clone=function(){var n=this;var t={};Object.keys(this.env).forEach(function(e){t[e]=n.env[e]});return new kn(t,this.parent,this.name)};kn.prototype.merge=function(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:"merge";Rn("Environment::merge",e,"environment");return this.inherit(n,e.env)};function Sn(e){if(typeof this!=="undefined"&&!(this instanceof Sn)||typeof this==="undefined"){return new Sn(e)}this.value=e}Sn.isUndefined=function(e){return e instanceof Sn&&typeof e.value==="undefined"};Sn.prototype.valueOf=function(){return this.value};function On(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof On)||typeof this==="undefined"){return new On(e)}this.values=e}On.prototype.toString=function(){return this.values.map(function(e){return oe(e)}).join("\n")};On.prototype.valueOf=function(){return this.values};kn.prototype.get=function(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:{};var t=n.throwError,r=t===void 0?true:t;var i=e;if(i instanceof ne||i instanceof Ve){i=i.valueOf()}var a=this._lookup(i);if(a instanceof Sn){if(Sn.isUndefined(a)){return x}return ke(a.valueOf())}if(typeof i==="string"){var o=i.split(".").filter(Boolean);if(o.length>0){var u=nt(o),c=u[0],s=u.slice(1);a=this._lookup(c);if(s.length){try{if(a instanceof Sn){a=a.valueOf();return Ge.apply(void 0,[a].concat(tt(s)))}else{return Ge.apply(void 0,[p].concat(tt(o)))}}catch(e){}}else if(a instanceof Sn){return ke(a.valueOf())}}a=Ge(p,i)}if(typeof a!=="undefined"){return a}if(r){throw new Error("Unbound variable `"+i.toString()+"'")}};kn.prototype.set=function(e,n){if(nn.isNumber(n)){n=nn(n)}if(e instanceof ne){e=e.name}else if(e instanceof Ve){e=e.valueOf()}this.env[e]=n};kn.prototype.has=function(e){return typeof this.env[e]!=="undefined"};kn.prototype.ref=function(e){var n=this;while(true){if(!n){break}if(n.has(e)){return n}n=n.parent}};kn.prototype.parents=function(){var e=this;var n=[];while(e){n.unshift(e);e=e.parent}return n};function jn(e){if(we(e)){return e.then(jn)}if(e instanceof ie||e instanceof ne){e.data=true}return e}var En=function(){var n=0;return function(){var e=arguments.length>0&&arguments[0]!==x?arguments[0]:null;if(e instanceof ne){e=e.valueOf()}if(e!==null){return new ne(Symbol("#:".concat(e)))}n++;return new ne(Symbol("#:g".concat(n)))}}();var Fn=new kn({nil:re,undefined:x,true:true,false:false,NaN:NaN,stdout:new mn(function(){var e;(e=console).log.apply(e,arguments)}),stdin:dn(function(){return new Promise(function(e){e(prompt(""))})}),"open-input-string":C(function(e){Rn("open-input-string",e,"string");return gn(e)},"(open-input-string string)\n\n Function create new string port as input that can be used to\n read S-exressions from this port using `read` function."),"output-port?":C(function(e){return e instanceof mn},"(output-port? arg)\n\n Function return true if argument is output port."),"input-port?":C(function(e){return e instanceof dn},"(input-port? arg)\n\n Function return true if argument is input port."),"open-output-string":C(function(){return yn(this.get("repr"))},"(open-output-string)\n\n Function create new output port that can used to write string into\n and after finish get the whole string using `get-output-string`"),"get-output-string":C(function(e){Rn("get-output-string",e,"output-string-port");return e.getString()},"(get-output-string port)\n\n Function get full string from string port. If nothing was wrote\n to given port it will return empty string."),"eof-object?":C(function(e){return e===bn},"(eof-object? arg)\n\n Function check if value is eof object, returned from input string\n port when there are no more data to read."),"peek-char":C(function(e){Rn("peek-char",e,["input-port","input-string-port"]);return e.peekChar()},"(peek-char port)\n\n Function get character from string port or EOF object if no more\n data in string port."),read:C(function n(e){var t=this;if(typeof e==="string"){return N(F(e))[0]}if(e instanceof gn){var r=e.read();if(r===bn){return bn}return N(r)[0]}var i;if(e instanceof dn){i=e}else{i=this.get("stdin")}return i.read().then(function(e){return n.call(t,e)})},"(read [string])\n\n Function if used with string will parse the string and return\n list structure of LIPS code. If called without an argument it\n will read string from standard input (using browser prompt or\n user defined way) and call itself with that string (parse is)\n function can be used together with eval to evaluate code from\n string"),pprint:C(function(e){if(e instanceof ie){e=new Xn.Formatter(e.toString(true))["break"]().format();this.get("stdout").write.call(this,e)}else{this.get("display").call(this,e)}},"(pprint expression)\n\n Pretty print list expression, if called with non-pair it just call\n print function with passed argument."),print:C(function(){var n=this;for(var e=arguments.length,t=new Array(e),r=0;r1?t-1:0),i=1;ir.length){throw new Error("Not enough arguments")}var u=0;var c=this.get("repr");n=n.replace(a,function(e){var n=e[1];if(n==="~"){return"~"}else if(n==="%"){return"\n"}else{var t=r[u++];if(n==="a"){return c(t)}else{return c(t,true)}}});o=n.match(/~([\S])/);if(o){throw new Error("format: Unrecognized escape seqence ".concat(o[1]))}return n},"(format string n1 n2 ...)\n\n Function accepts string template and replacing any escape sequences\n by arguments:\n\n * ~a value as if printed with display\n * ~s value as if printed with write\n * ~% newline character\n * ~~ literal tilde '~' is inserted\n\n if there missing arguments or other escape character it throw exception."),display:C(function(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:null;if(n===null){n=this.get("stdout")}n.write.call(this,this.get("repr")(e))},"(display arg [port])\n\n Function send string to standard output or provied port."),error:C(function(){for(var e=arguments.length,n=new Array(e),t=0;t1&&arguments[1]!==x?arguments[1]:{},t=e.dynamic_scope,r=e.error;if(t){t=this}var i=Un(n.cdr.car,{env:this,dynamic_scope:t,error:r});i=Dn(i);var a;function o(n,t){if(we(n)){return n.then(function(e){return o(e,t)})}if(we(t)){return t.then(function(e){return o(n,e)})}s[n]=t;return t}if(n.car instanceof ie&&ne.is(n.car.car,".")){var u=n.car.cdr.car;var c=n.car.cdr.cdr.car;var s=Un(u,{env:this,dynamic_scope:t,error:r});var f=Un(c,{env:this,dynamic_scope:t,error:r});return o(f,i)}if(!(n.car instanceof ne)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}a=this.ref(n.car.name);if(!a){a=this}return q(i,function(e){a.set(n.car,e)})}),"(set! name value)\n\n Macro that can be used to set the value of the variable (mutate)\n it search the scope chain until it finds first non emtpy slot and set it."),"set-car!":C(function(e,n){Rn("set-car!",e,"pair");e.car=n},"(set-car! obj value)\n\n Function that set car (head) of the list/pair to specified value.\n It can destroy the list. Old value is lost."),"set-cdr!":C(function(e,n){Rn("set-cdr!",e,"pair");e.cdr=n},"(set-cdr! obj value)\n\n Function that set cdr (tail) of the list/pair to specified value.\n It can destroy the list. Old value is lost."),"empty?":C(function(e){return typeof e==="undefined"||e===re},"(empty? object)\n\n Function return true if value is undfined empty list."),assoc:C(function(e,n){if(e instanceof ie&&!(n instanceof ie)){throw new Error("First argument to assoc ned to be a key")}Rn("assoc",n,"pair");var t=n;while(true){if(!(t instanceof ie)||this.get("empty?")(t)){break}var r=t.car.car;if(fe(r,e)){return t.car}else if(!t.haveCycles("cdr")){t=t.cdr}}return re},"(assoc key alist)\n\n Function search Alist (list of pairs) until it find the one that\n have head set equal to key, and return found pair."),gensym:C(En,"(gensym)\n\n Function generate unique symbol, to use with macros as meta name."),load:C(function(e){Rn("load",e,"string");var n=this;if(n.name==="__frame__"){n=n.parent}var i;if(n===Fn){i=n}else{i=this.get("**interaction-environment**")}if(typeof this.get("global",{throwError:false})!=="undefined"){return new Promise(function(t,r){require("fs").readFile(e.valueOf(),function(e,n){if(e){r(e)}else{Yn(n.toString(),i).then(function(){t()})}})})}return p.fetch(e).then(function(e){return e.text()}).then(function(e){return Yn(e,i)}).then(function(){})},"(load filename)\n\n Function fetch the file and evaluate its content as LIPS code."),while:C(new pe("while",function(r,e){var i=e.dynamic_scope,a=e.error;var o=this;var u=new ie(new ne("begin"),r.cdr);var c;if(i){i=o}return function n(){var e=Un(r.car,{env:o,dynamic_scope:i,error:a});function t(e){if(e&&!be(e)){c=Un(u,{env:o,dynamic_scope:i,error:a});if(we(c)){return c.then(function(e){c=e;return n()})}else{return n()}}else{return c}}return q(e,t)}()}),"(while cond . body)\n\n Macro that create a loop, it exectue body untill cond expression is false"),if:C(new pe("if",function(t,e){var r=e.dynamic_scope,i=e.error;if(r){r=this}var a=this;var n=function e(n){if(n){return Un(t.cdr.car,{env:a,dynamic_scope:r,error:i})}else{return Un(t.cdr.cdr.car,{env:a,dynamic_scope:r,error:i})}};var o=Un(t.car,{env:a,dynamic_scope:r,error:i});return q(o,n)}),"(if cond true-expr false-expr)\n\n Macro evaluate condition expression and if the value is true, it\n evaluate and return true expression if not it evaluate and return\n false expression"),"let-env":new pe("let-env",function(n){var e=arguments.length>1&&arguments[1]!==x?arguments[1]:{};var t=e.dynamic_scope,r=e.error;Rn("let-env",n,"pair");var i=Un(n.car,{env:this,dynamic_scope:t,error:r});return q(i,function(e){if(!(e instanceof kn)){throw new Error("let-env: First argument need to be "+"environment")}return Un(ie(ne("begin"),n.cdr),{env:e,dynamic_scope:t,error:r})})},"(let-env env . body)\n\n Special macro that evaluate body in context of given environment\n object."),letrec:C(qe(Symbol["for"]("letrec")),"(letrec ((a value-a) (b value-b)) body)\n\n Macro that creates new environment, then evaluate and assign values to\n names and then evaluate the body in context of that environment.\n Values are evaluated sequentialy and next value can access to\n previous values/names."),"let*":C(qe(Symbol["for"]("let*")),"(let* ((a value-a) (b value-b)) body)\n\n Macro similar to `let` but next argument get environment\n from previous let variable, so they you can define one variable,\n and use in next argument."),let:C(qe(Symbol["for"]("let")),"(let ((a value-a) (b value-b)) body)\n\n Macro that creates new environment, then evaluate and assign values to\n names and then evaluate the body in context of that environment.\n Values are evaluated sequentialy but you can't access\n previous values/names when next are evaluated. You can only get them\n from body of let expression."),"begin*":C(Pe("begin*",function(e){return e.pop()}),"(begin* . expr)\n\n This macro is parallel version of begin. It evaluate each expression and\n if it's a promise it will evaluate it in parallel and return value\n of last expression."),begin:C(new pe("begin",function(e,n){var r=Object.assign({},n);var i=this.get("list->array")(e);if(r.dynamic_scope){r.dynamic_scope=this}r.env=this;var a;return function n(){if(i.length){var e=i.shift();var t=Un(e,r);return q(t,function(e){a=e;return n()})}else{return a}}()}),"(begin . args)\n\n Macro runs list of expression and return valuate of the list one.\n It can be used in place where you can only have single exression,\n like if expression."),ignore:new pe("ignore",function(e,n){var t=n.dynamic_scope,r=n.error;var i={env:this,error:r};if(t){i.dynamic_scope=this}Un(new ie(new ne("begin"),e),i)},"(ignore expression)\n\n Macro that will evaluate expression and swallow any promises that may\n be created. It wil run and ignore any value that may be returned by\n expression. The code should have side effects and/or when it's promise\n it should resolve to undefined."),define:C(pe.defmacro("define",function(n,e){var t=this;if(n.car instanceof ie&&n.car.car instanceof ne){var r=new ie(new ne("define"),new ie(n.car.car,new ie(new ie(new ne("lambda"),new ie(n.car.cdr,n.cdr)))));return r}else if(e.macro_expand){return}if(e.dynamic_scope){e.dynamic_scope=this}e.env=t;var i=n.cdr.car;if(i instanceof ie){i=Un(i,e)}else if(i instanceof ne){i=t.get(i)}Rn("define",n.car,"symbol");return q(i,function(e){if(t.name===de.merge_env){t.parent.set(n.car,e)}else{t.set(n.car,e)}})}),"(define name expression)\n (define (function-name . args) body)\n\n Macro for defining values. It can be used to define variables,\n or function. If first argument is list it will create function\n with name beeing first element of the list. The macro evalute\n code `(define function (lambda args body))`"),"set-obj!":C(function(e,n,t){var r=ot(e);if(be(e)||r!=="object"&&r!=="function"){var i=Mn("set-obj!",Bn(e),["object","function"]);throw new Error(i)}e=Se(e);n=n.valueOf();if(typeof t==="undefined"){delete e[n]}else{e[n]=t.valueOf()}},"(set-obj! obj key value)\n\n Function set property of JavaScript object"),"null-environment":C(function(){return Fn.inherit("null")},"(null-environment)\n\n Function return new base environment with std lib."),values:C(function(){for(var e=arguments.length,n=new Array(e),t=0;t1&&arguments[1]!==x?arguments[1]:{},p=e.dynamic_scope,h=e.error;var v=this;var d;if(l.cdr instanceof ie&&Ve.isString(l.cdr.car)&&l.cdr.cdr!==re){d=l.cdr.car.valueOf()}function m(){var e;if(p){if(!(this instanceof kn)){e=v}else{e=this}}else{e=v}e=e.inherit("lambda");var n=l.car;var t=0;var r;if(typeof this!=="undefined"){e.set("this",this)}for(var i=arguments.length,a=new Array(i),o=0;o2&&arguments[2]!==x?arguments[2]:u;if(e instanceof ie){var r=e.car;var i=e.cdr;if(t(r)){r=n(r)}if(t(i)){i=n(i)}if(we(r)||we(i)){return Promise.all([r,i]).then(function(e){var n=rt(e,2),t=n[0],r=n[1];return new ie(t,r)})}else{return new ie(r,i)}}return e}function s(e,n){if(e instanceof ie){if(n!==re){e.append(n)}}else{e=new ie(e,n)}return e}function f(r,e,n){if(er){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(t.cdr instanceof ie){if(t.cdr.cdr!==re){if(t.cdr.car instanceof ie){return q(p(t.cdr.cdr,n,r),function(e){var n=Un(t.cdr.car,{env:o,dynamic_scope:i,error:a});return new ie(n,e)})}else{return t.cdr}}else{return Un(t.cdr.car,{env:o,dynamic_scope:i,error:a})}}else{return t.cdr}}return c(t,function(e){return p(e,n,r)})}return t}function t(e){if(e instanceof ie){delete e.data;if(!e.haveCycles("car")){t(e.car)}if(!e.haveCycles("cdr")){t(e.cdr)}}}var r=p(e.car,0,1);return q(r,function(e){t(e);return jn(e)})},"(quasiquote list ,value ,@value)\n\n Similar macro to `quote` but inside it you can use special\n expressions unquote abbreviated to , that will evaluate expresion inside\n and return its value or unquote-splicing abbreviated to ,@ that will\n evaluate expression but return value without parenthesis (it will join)\n the list with its value. Best used with macros but it can be used outside"),clone:C(function(e){Rn("clone",e,"pair");return e.clone()},"(clone list)\n\n Function return clone of the list."),append:C(function(e,n){Rn("append",e,["nil","pair"]);if(e instanceof ie){e=e.clone()}return this.get("append!").call(this,e,n)},"(append list item)\n\n Function will create new list with value appended to the end. It return\n New list."),"append!":C(function(e,n){Rn("append!",e,["pair","nil"]);if(!this.get("list?")(e)){throw new Error("append!: Invalid argument, value is not a list")}if(be(n)){return e}if(e===re){if(n===re){return re}return n}return e.append(n)},"(append! name expression)\n\n Destructive version of append, it modify the list in place. It return\n original list."),reverse:C(function(e){Rn("reverse",e,["array","pair"]);if(e instanceof ie){var n=this.get("list->array")(e).reverse();return this.get("array->list")(n)}else if(!(e instanceof Array)){throw new Error(Mn("reverse",Bn(e),"array or pair"))}else{return e.reverse()}},"(reverse list)\n\n Function will reverse the list or array. If value is not a list\n or array it will throw exception."),nth:C(function(e,n){Rn("nth",e,"number");Rn("nth",n,["array","pair"]);if(n instanceof ie){var t=n;var r=0;while(rarray")(n).join(e)},"(join separator list)\n\n Function return string by joining elements of the list"),split:C(function(e,n){Rn("split",e,["regex","string"]);Rn("split",n,"string");return this.get("array->list")(n.split(e))},"(split separator string)\n\n Function create list by splitting string by separatar that can\n be a string or regular expression."),replace:C(function(e,n,t){Rn("replace",e,["regex","string"]);Rn("replace",n,["string","function"]);Rn("replace",t,"string");return t.replace(e,n)},"(replace pattern replacement string)\n\n Function change pattern to replacement inside string. Pattern can be string\n or regex and replacement can be function or string."),match:C(function(e,n){Rn("match",e,["regex","string"]);Rn("match",n,"string");var t=n.match(e);return t?this.get("array->list")(t):re},"(match pattern string)\n\n function return match object from JavaScript as list."),search:C(function(e,n){Rn("search",e,["regex","string"]);Rn("search",n,"string");return n.search(e)},"(search pattern string)\n\n Function return first found index of the pattern inside a string"),repr:C(function e(n,t){return oe(n,t)},"(repr obj)\n\n Function return string LIPS representation of an object as string."),env:C(function(e){e=e||this;var n=Object.keys(e.env);var t;if(n.length){t=ie.fromArray(n)}else{t=re}if(e.parent!==x){return this.get("env").call(this,e.parent).append(t)}return t},"(env obj)\n\n Function return list values (functions and variables) inside environment."),new:C(function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r2&&arguments[2]!==x?arguments[2]:A.LITERAL;Rn("remove-special!",e,"string",1);Rn("remove-special!",n,"symbol",2);Xn.specials.append(e,n,t)},"(add-special! symbol name)\n\n Add special symbol to the list of transforming operators by the parser.\n e.g.: `(add-special! '#)` will allow to use `#(1 2 3)` and it will be\n transformed into (# (1 2 3)) so you can write # macro that will process\n the list. It's main purpose to to allow to use `define-symbol-macro`"),get:Ge,".":Ge,unbind:C(Se,"(unbind fn)\n\n Function remove bidning from function so you can get props from it."),type:C(Bn,"(type object)\n\n Function return type of an object as string."),debugger:C(function(){debugger},"(debugger)\n\n Function stop JavaScript code in debugger."),instanceof:C(function(e,n){return n instanceof Se(e)},"(instanceof type obj)\n\n Function check of object is instance of object."),"macro?":C(function(e){return e instanceof pe},"(macro? expression)\n\n Function check if value is a macro."),"function?":C(function(e){return typeof e==="function"},"(function? expression)\n\n Function check if value is a function."),"real?":C(function(e){if(Bn(e)!=="number"){return false}if(e instanceof nn){return e.isFloat()}return nn.isFloat(e)},"(real? number)\n\n Function check if value is real number."),"number?":C(nn.isNumber,"(number? expression)\n\n Function check if value is a number"),"string?":C(function(e){return Ve.isString(e)},"(string? expression)\n\n Function check if value is a string."),"pair?":C(function(e){return e instanceof ie},"(pair? expression)\n\n Function check if value is a pair or list structure."),"regex?":C(function(e){return e instanceof RegExp},"(regex? expression)\n\n Function check if value is regular expression."),"null?":C(function(e){return be(e)},"(null? expression)\n\n Function check if value is nulish."),"boolean?":C(function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Function check if value is boolean."),"symbol?":C(function(e){return e instanceof ne},"(symbol? expression)\n\n Function check if value is LIPS symbol"),"array?":C(function(e){return e instanceof Array},"(array? expression)\n\n Function check if value is an arrray."),"object?":C(function(e){return e!==re&&e!==null&&!(e instanceof nn)&&ot(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Function check if value is an object."),flatten:C(function(e){Rn("flatten",e,"pair");return e.flatten()},"(flatten list)\n\n Return shallow list from tree structure (pairs)."),"array->list":C(function(e){Rn("array->list",e,"array");return ie.fromArray(e)},"(array->list array)\n\n Function convert JavaScript array to LIPS list."),"tree->array":C(ae("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":C(ae("list->array"),"(list->array list)\n\n Function convert LIPS list into JavaScript array."),apply:C(function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;rarray")(i));return e.apply(void 0,tt(t))},"(apply fn list)\n\n Function that call function with list of arguments."),length:C(function(e){if(!e){return nn(0)}if(e instanceof ie){return nn(e.length())}if("length"in e){return nn(e.length)}},"(length expression)\n\n Function return length of the object, the object can be list\n or any object that have length property."),"string->number":C(function(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:10;Rn("string->number",e,"string",1);Rn("string->number",n,"number",2);if(e.match(c)){return s(e)}else if(e.match(u)){return v(e)}else if(e.match(r)){return f(e)}else if(e.match(i)){return rn(parseFloat(e))}throw new Error("string->number: Invalid Syntax")},"(string->number number [radix])\n\n Function convert string to number."),try:C(new pe("try",function(a,e){var o=this;var u=e.dynamic_scope,c=e.error;return new Promise(function(i){var e={env:o,error:function e(n){if(n instanceof _n){throw new _n(n.message)}var t=o.inherit("try");t.set(a.cdr.car.cdr.car.car,n);var r={env:t,error:c};if(u){r.dynamic_scope=o}q(Un(new ie(new ne("begin"),a.cdr.car.cdr.cdr),r),function(e){i(e)});throw new _n(n.message)}};if(u){e.dynamic_scope=o}var n=Un(a.car,e);if(we(n)){n["catch"](e.error).then(i)}else{i(n)}})}),"(try expr (catch (e) code)"),throw:C(function(e){throw new Error(e)},"(throw string)\n\n Throw new expection."),find:C(function n(t,r){Rn("find",t,["regex","function"]);Rn("find",r,"pair");if(be(r)){return re}var e=P("find",t);return q(e(r.car),function(e){if(e&&e!==re){return r.car}return n(t,r.cdr)})},"(find fn list)\n (find regex list)\n\n Higher order Function find first value for which function return true.\n If called with regex it will create matcher function."),"for-each":C(function(e){var n;Rn("for-each",e,"function");for(var t=arguments.length,r=new Array(t>1?t-1:0),i=1;i1?n-1:0),a=1;a3?r-3:0),a=3;a3?i-3:0),o=3;oarray")(n);var a=[];var o=P("filter",e);return function n(t){function e(e){if(e&&e!==re){a.push(r)}return n(++t)}if(t===i.length){return ie.fromArray(a)}var r=i[t];return q(o(r,t),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher order function that call `fn` for each element of the list\n and return list for only those elements for which funtion return\n true value. If called with regex it will create matcher function."),range:C(function(e){Rn("range",e,"number");if(e instanceof nn){e=e.valueOf()}return ie.fromArray(new Array(e).fill(0).map(function(e,n){return nn(n)}))},"(range n)\n\n Function return list of n numbers from 0 to n - 1"),compose:C(Re,"(compose . fns)\n\n Higher order function and create new function that apply all functions\n From right to left and return it's value. Reverse of compose.\n e.g.:\n ((compose (curry + 2) (curry * 3)) 3)\n 11\n "),pipe:C(Me,"(pipe . fns)\n\n Higher order function and create new function that apply all functions\n From left to right and return it's value. Reverse of compose.\n e.g.:\n ((pipe (curry + 2) (curry * 3)) 3)\n 15"),curry:C(Je,"(curry fn . args)\n\n Higher order function that create curried version of the function.\n The result function will have parially applied arguments and it\n will keep returning functions until all arguments are added\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))"),gdc:C(function e(){for(var n=arguments.length,t=new Array(n),r=0;ra?u%=a:a%=u}u+=a}return nn(u)},"(gdc n1 n2 ...)\n\n Function return the greatest common divisor of their arguments."),lcm:C(function(){var e=arguments.length,n=ce(arguments.length<=0?x:arguments[0]);for(var t=1;tr?n%=r:r%=n}n=ce(i*(t<0||arguments.length<=t?x:arguments[t]))/(n+r)}return nn(n)},"(lcm n1 n2 ...)\n\n Function return the least common multiple of their arguments."),"odd?":C(De(function(e){return nn(e).isOdd()}),"(odd? number)\n\n Function check if number os odd."),"even?":C(De(function(e){return nn(e).isEven()}),"(even? number)\n\n Function check if number is even."),"*":C(He(function(e,n){return nn(e).mul(n)},nn(1)),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":C(He(function(e,n){return nn(e).add(n)},nn(0)),"(+ . numbers)\n\n Sum all numbers passed as arguments. If single value is passed it will\n return that value."),"-":C(function(){for(var e=arguments.length,n=new Array(e),t=0;t":C(function(){for(var e=arguments.length,n=new Array(e),t=0;t x1 x2 x3 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically increasing"),"<":C(function(){for(var e=arguments.length,n=new Array(e),t=0;t=":C(function(){for(var e=arguments.length,n=new Array(e),t=0;t= x1 x2 x3 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically nondecreasing"),"eq?":C(fe,"(eq? a b)\n\n Function compare two values if they are identical."),or:C(new pe("or",function(e,n){var i=n.dynamic_scope,a=n.error;var o=this.get("list->array")(e);var u=this;if(i){i=u}var c;return function n(){function e(e){c=e;if(c){return c}else{return n()}}var t=o.shift();if(typeof t==="undefined"){if(c){return c}else{return false}}else{var r=Un(t,{env:u,dynamic_scope:i,error:a});return q(r,e)}}()}),"(or . expressions)\n\n Macro execute the values one by one and return the one that is truthy value.\n If there are no expression that evaluate to true it return false."),and:C(new pe("and",function(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:{},i=n.dynamic_scope,a=n.error;var o=this.get("list->array")(e);var u=this;if(i){i=u}if(!o.length){return true}var c;return function n(){function e(e){c=e;if(!c){return false}else{return n()}}var t=o.shift();if(typeof t==="undefined"){if(c){return c}else{return false}}else{var r=Un(t,{env:u,dynamic_scope:i,error:a});return q(r,e)}}()}),"(and . expressions)\n\n Macro evalute each expression in sequence if any value return false it will\n return false. If each value return true it will return the last value.\n If it's called without arguments it will return true."),"|":C(function(e,n){return nn(e).or(n)},"(& a b)\n\n Function calculate or bit operation."),"&":C(function(e,n){return nn(e).and(n)},"(& a b)\n\n Function calculate and bit operation."),"~":C(function(e){return nn(e).neg()},"(~ number)\n\n Function negate the value."),">>":C(function(e,n){return nn(e).shr(n)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":C(function(e,n){return nn(e).shl(n)},"(<< a b)\n\n Function left shit the value a by value b."),not:C(function(e){if(be(e)){return true}return!e},"(not object)\n\n Function return negation of the argument."),"->":C(function(e,n){for(var t=arguments.length,r=new Array(t>2?t-2:0),i=2;i obj name . args)\n\n Function get function from object and call it with arguments.")},x,"global");var An=Fn.inherit("user-env");Fn.set("**interaction-environment**",An);(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(n){var t=e[n]?e[n]:n;Fn.set(t,C(function(e){Rn(t,e,"number");if(e instanceof nn){return e[n]()}},"(".concat(t," number)\n\n Function calculate ").concat(t," of a number.")))})})();function In(e){if(e.length===1){return e[0]}else{var n=[];var t=In(e.slice(1));for(var r=0;r3&&arguments[3]!==x?arguments[3]:null;var i=e?" in function `".concat(e,"`"):"";if(r!==null){i+=" argument ".concat(r)}if(t instanceof Array){var a=t[t.length-1];t=t.slice(0,-1).join(", ")+" or "+a}return"Expecting ".concat(t," got ").concat(n).concat(i)}function Rn(e,n,t){var r=arguments.length>3&&arguments[3]!==x?arguments[3]:null;var i=Bn(n).toLowerCase();var a=false;if(t instanceof Array){t=t.map(function(e){return e.valueOf().toLowerCase()});if(t.includes(i)){a=true}}else{t=t.valueOf().toLowerCase()}if(!a&&i!==t){throw new Error(Mn(e,i,t,r))}}function Tn(e){var n=ot(e);return["string","function"].includes(n)||e instanceof ne||e instanceof nn||e instanceof RegExp}function Bn(e){var n={pair:ie,symbol:ne,character:ze,values:On,macro:pe,string:Ve,array:Array,"native-symbol":Symbol};if(Number.isNaN(e)){return"NaN"}if(e===re){return"nil"}if(e===null){return"null"}if(e instanceof de){return"syntax"}for(var t=0,r=Object.entries(n);t1&&arguments[1]!==x?arguments[1]:{},i=e.env,a=e.dynamic_scope,t=e.error,o=t===void 0?function(){}:t;try{if(a===true){i=a=i||Fn}else if(i===true){i=a=Fn}else{i=i||Fn}var r={env:i,dynamic_scope:a,error:o};var u;if(be(n)){return n}if(n instanceof ne){return i.get(n)}var c=n.car;var s=n.cdr;if(c instanceof ie){u=Dn(Un(c,r));if(we(u)){return u.then(function(e){return Un(new ie(e,n.cdr),r)})}else if(typeof u!=="function"){throw new Error(Bn(u)+" "+i.get("repr")(u)+" is not a function while evaluating "+n.toString())}}if(c instanceof ne){u=i.get(c);if(u instanceof de){return Hn(u,n,r)}else if(u instanceof pe){return Jn(u,s,r)}else if(typeof u!=="function"){if(u){var f="".concat(Bn(u)," `").concat(u,"' is not a function");throw new Error(f)}throw new Error("Unknown function `".concat(c.name,"'"))}}else if(typeof c==="function"){u=c}if(typeof u==="function"){var l=$n(s,r);return q(l,function(e){if(je(u)){e=e.map(xe)}if(u.__lambda__){u=Se(u)}var n=e.slice();var t=(a||i).newFrame(u,n);var r=Dn(u.apply(t,e));return q(r,function(e){if(e instanceof ie){e.markCycles();return jn(e)}if(typeof e==="number"){return nn(e)}if(typeof e==="string"){return Ve(e)}return e},o)})}else if(n instanceof ne){u=i.get(n);if(u==="undefined"){throw new Error("Unbound variable `"+n.name+"'")}return u}else if(n instanceof ie){u=c&&c.toString();throw new Error("".concat(Bn(c)," ").concat(u," is not a function"))}else{return n}}catch(e){o&&o.call(i,e,n)}}function Yn(e,n,t){return Gn.apply(this,arguments)}function Gn(){Gn=et(Zn.mark(function e(t,r,i){var a,o,u,c;return Zn.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(i===true){r=i=r||An}else if(r===true){r=i=An}else{r=r||An}a=N(t);o=[];case 3:u=a.shift();if(u){n.next=9;break}return n.abrupt("return",o);case 9:n.next=11;return Un(u,{env:r,dynamic_scope:i,error:function e(n,t){if(t){if(!(n.code instanceof Array)){n.code=[]}n.code.push(t.toString(true))}throw n}});case 11:c=n.sent;o.push(c);case 13:n.next=3;break;case 15:case"end":return n.stop()}}},e)}));return Gn.apply(this,arguments)}function zn(e){var n={"[":"]","(":")"};var t=typeof e==="string"?F(e):e;var r=Object.keys(n);var i=Object.values(n).concat(r);t=t.filter(function(e){return i.includes(e)});var a=new O;var o=ut(t),u;try{for(o.s();!(u=o.n()).done;){var c=u.value;if(r.includes(c)){a.push(c)}else if(!a.is_empty()){var s=a.top();var f=n[s];if(c===f){a.pop()}else{throw new Error("Syntax error: missing closing ".concat(f))}}else{throw new Error("Syntax error: not matched closing ".concat(c))}}}catch(e){o.e(e)}finally{o.f()}return a.is_empty()}ie.unDry=function(e){return new ie(e.car,e.cdr)};ie.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};te.prototype.toDry=function(){return{value:null}};te.unDry=function(){return re};ne.prototype.toDry=function(){return{value:{name:this.name}}};ne.unDry=function(e){return new ne(e.name)};function Vn(e){console.error(e.message||e);if(e.code){console.error(e.code.map(function(e,n){return"[".concat(n+1,"]: ").concat(e)}))}}function Qn(){var o=["text/x-lips","text/x-scheme"];if(!window.document){return Promise.resolve()}else{return new Promise(function(i){var a=Array.from(document.querySelectorAll("script"));return function n(){var e=a.shift();if(!e){i()}else{var t=e.getAttribute("type");if(o.includes(t)){var r=e.getAttribute("src");if(r){return p.fetch(r).then(function(e){return e.text()}).then(Yn).then(n)["catch"](function(e){Vn(e);n()})}else{return Yn(e.innerHTML).then(n)["catch"](function(e){Vn(e);n()})}}else if(t&&t.match(/lips|lisp/)){console.warn("Expecting "+o.join(" or ")+" found "+t)}return n()}}()})}}if(typeof window!=="undefined"){e(window,Qn)}var Wn=function(){var e=Ve("Wed, 13 May 2020 09:37:06 +0000").valueOf();var n=e==="{{"+"DATE}}"?new Date:new Date(e);var t=function e(n){return n.toString().padStart(2,"0")};var r=n.getFullYear();var i=[r,t(n.getMonth()+1),t(n.getDate())].join("-");var a="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Scheme Interpreter DEV (".concat(i,")\nCopyright (c) 2018-").concat(r," Jakub T. Jankiewicz \n\nType (env) to see environment with functions macros and variables.\nYou can also use (help name) to display help for specic function or macro.\n").replace(/^.*\n/,"");return a}();$.__className="ahead";H.__className="pattern";D.__className="formatter";pe.__className="macro";de.__className="syntax";kn.__className="environment";dn.__className="input-port";mn.__className="output-port";yn.__className="output-string-port";gn.__className="input-string-port";var Xn={version:"DEV",banner:Wn,date:"Wed, 13 May 2020 09:37:06 +0000",exec:Yn,parse:N,tokenize:F,evaluate:Un,Environment:kn,env:An,Interpreter:xn,balanced_parenthesis:zn,balancedParenthesis:zn,Macro:pe,Syntax:de,Pair:ie,quote:jn,InputPort:dn,OutputPort:mn,InputStringPort:gn,OutputStringPort:yn,Formatter:D,specials:A,nil:re,LSymbol:ne,LNumber:nn,LFloat:rn,LComplex:tn,LRational:sn,LBigInteger:fn,LCharacter:ze,LString:Ve,rationalize:un};Fn.set("lips",Xn);return Xn})})(); \ No newline at end of file +(function(){"use strict";function e(e,n){return n={exports:{}},e(n,n.exports),n.exports}var u=e(function(t){function r(e,n){t.exports=r=Object.setPrototypeOf||function e(n,t){n.__proto__=t;return n};return r(e,n)}t.exports=r});function n(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Date.prototype.toString.call(Reflect.construct(Date,[],function(){}));return true}catch(e){return false}}var a=n;var ft=e(function(r){function i(e,n,t){if(a()){r.exports=i=Reflect.construct}else{r.exports=i=function e(n,t,r){var i=[null];i.push.apply(i,t);var a=Function.bind.apply(n,i);var o=new a;if(r)u(o,r.prototype);return o}}return i.apply(null,arguments)}r.exports=i});var t=e(function(e){var n=function(o){var e=Object.prototype;var f=e.hasOwnProperty;var c;var n=typeof Symbol==="function"?Symbol:{};var i=n.iterator||"@@iterator";var t=n.asyncIterator||"@@asyncIterator";var r=n.toStringTag||"@@toStringTag";function u(e,n,t,r){var i=n&&n.prototype instanceof s?n:s;var a=Object.create(i.prototype);var o=new F(r||[]);a._invoke=S(e,t,o);return a}o.wrap=u;function l(e,n,t){try{return{type:"normal",arg:e.call(n,t)}}catch(e){return{type:"throw",arg:e}}}var p="suspendedStart";var h="suspendedYield";var v="executing";var d="completed";var m={};function s(){}function a(){}function y(){}var g={};g[i]=function(){return this};var b=Object.getPrototypeOf;var w=b&&b(b(A([])));if(w&&w!==e&&f.call(w,i)){g=w}var _=y.prototype=s.prototype=Object.create(g);a.prototype=_.constructor=y;y.constructor=a;y[r]=a.displayName="GeneratorFunction";function x(e){["next","throw","return"].forEach(function(n){e[n]=function(e){return this._invoke(n,e)}})}o.isGeneratorFunction=function(e){var n=typeof e==="function"&&e.constructor;return n?n===a||(n.displayName||n.name)==="GeneratorFunction":false};o.mark=function(e){if(Object.setPrototypeOf){Object.setPrototypeOf(e,y)}else{e.__proto__=y;if(!(r in e)){e[r]="GeneratorFunction"}}e.prototype=Object.create(_);return e};o.awrap=function(e){return{__await:e}};function k(u,c){function s(e,n,t,r){var i=l(u[e],u,n);if(i.type==="throw"){r(i.arg)}else{var a=i.arg;var o=a.value;if(o&&typeof o==="object"&&f.call(o,"__await")){return c.resolve(o.__await).then(function(e){s("next",e,t,r)},function(e){s("throw",e,t,r)})}return c.resolve(o).then(function(e){a.value=e;t(a)},function(e){return s("throw",e,t,r)})}}var n;function e(t,r){function e(){return new c(function(e,n){s(t,r,e,n)})}return n=n?n.then(e,e):e()}this._invoke=e}x(k.prototype);k.prototype[t]=function(){return this};o.AsyncIterator=k;o.async=function(e,n,t,r,i){if(i===void 0)i=Promise;var a=new k(u(e,n,t,r),i);return o.isGeneratorFunction(n)?a:a.next().then(function(e){return e.done?e.value:a.next()})};function S(o,u,c){var s=p;return function e(n,t){if(s===v){throw new Error("Generator is already running")}if(s===d){if(n==="throw"){throw t}return I()}c.method=n;c.arg=t;while(true){var r=c.delegate;if(r){var i=O(r,c);if(i){if(i===m)continue;return i}}if(c.method==="next"){c.sent=c._sent=c.arg}else if(c.method==="throw"){if(s===p){s=d;throw c.arg}c.dispatchException(c.arg)}else if(c.method==="return"){c.abrupt("return",c.arg)}s=v;var a=l(o,u,c);if(a.type==="normal"){s=c.done?d:h;if(a.arg===m){continue}return{value:a.arg,done:c.done}}else if(a.type==="throw"){s=d;c.method="throw";c.arg=a.arg}}}}function O(e,n){var t=e.iterator[n.method];if(t===c){n.delegate=null;if(n.method==="throw"){if(e.iterator["return"]){n.method="return";n.arg=c;O(e,n);if(n.method==="throw"){return m}}n.method="throw";n.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var r=l(t,e.iterator,n.arg);if(r.type==="throw"){n.method="throw";n.arg=r.arg;n.delegate=null;return m}var i=r.arg;if(!i){n.method="throw";n.arg=new TypeError("iterator result is not an object");n.delegate=null;return m}if(i.done){n[e.resultName]=i.value;n.next=e.nextLoc;if(n.method!=="return"){n.method="next";n.arg=c}}else{return i}n.delegate=null;return m}x(_);_[r]="Generator";_[i]=function(){return this};_.toString=function(){return"[object Generator]"};function j(e){var n={tryLoc:e[0]};if(1 in e){n.catchLoc=e[1]}if(2 in e){n.finallyLoc=e[2];n.afterLoc=e[3]}this.tryEntries.push(n)}function E(e){var n=e.completion||{};n.type="normal";delete n.arg;e.completion=n}function F(e){this.tryEntries=[{tryLoc:"root"}];e.forEach(j,this);this.reset(true)}o.keys=function(t){var r=[];for(var e in t){r.push(e)}r.reverse();return function e(){while(r.length){var n=r.pop();if(n in t){e.value=n;e.done=false;return e}}e.done=true;return e}};function A(n){if(n){var e=n[i];if(e){return e.call(n)}if(typeof n.next==="function"){return n}if(!isNaN(n.length)){var t=-1,r=function e(){while(++t=0;--n){var i=this.tryEntries[n];var a=i.completion;if(i.tryLoc==="root"){return e("end")}if(i.tryLoc<=this.prev){var o=f.call(i,"catchLoc");var u=f.call(i,"finallyLoc");if(o&&u){if(this.prev=0;--t){var r=this.tryEntries[t];if(r.tryLoc<=this.prev&&f.call(r,"finallyLoc")&&this.prev=0;--n){var t=this.tryEntries[n];if(t.finallyLoc===e){this.complete(t.completion,t.afterLoc);E(t);return m}}},catch:function(e){for(var n=this.tryEntries.length-1;n>=0;--n){var t=this.tryEntries[n];if(t.tryLoc===e){var r=t.completion;if(r.type==="throw"){var i=r.arg;E(t)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,t){this.delegate={iterator:A(e),resultName:n,nextLoc:t};if(this.method==="next"){this.arg=c}return m}};return o}(e.exports);try{regeneratorRuntime=n}catch(e){Function("r","regeneratorRuntime = r")(n)}});var lt=t;function c(e,n,t,r,i,a,o){try{var u=e[a](o);var c=u.value}catch(e){t(e);return}if(u.done){n(c)}else{Promise.resolve(c).then(r,i)}}function r(u){return function(){var e=this,o=arguments;return new Promise(function(n,t){var r=u.apply(e,o);function i(e){c(r,n,t,i,a,"next",e)}function a(e){c(r,n,t,i,a,"throw",e)}i(undefined)})}}var pt=r;function i(e){if(Array.isArray(e))return e}var o=i;function s(e){if(typeof Symbol!=="undefined"&&Symbol.iterator in Object(e))return Array.from(e)}var f=s;function l(e,n){if(n==null||n>e.length)n=e.length;for(var t=0,r=new Array(n);t=0)continue;t[i]=e[i]}return t}var O=S;function j(e,n){if(e==null)return{};var t=O(e,n);var r,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,r))continue;t[r]=e[r]}}return t}var mt=j;function E(e,n){if(typeof Symbol==="undefined"||!(Symbol.iterator in Object(e)))return;var t=[];var r=true;var i=false;var a=undefined;try{for(var o=e[Symbol.iterator](),u;!(r=(u=o.next()).done);r=true){t.push(u.value);if(n&&t.length===n)break}}catch(e){i=true;a=e}finally{try{if(!r&&o["return"]!=null)o["return"]()}finally{if(i)throw a}}return t}var F=E;function A(e,n){return o(e)||F(e,n)||v(e,n)||m()}var yt=A;var gt=e(function(n){function t(e){"@babel/helpers - typeof";if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){n.exports=t=function e(n){return typeof n}}else{n.exports=t=function e(n){return n&&typeof Symbol==="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n}}return t(e)}n.exports=t});function bt(n){if(typeof Symbol==="undefined"||n[Symbol.iterator]==null){if(Array.isArray(n)||(n=I(n))){var t=0;var e=function e(){};return{s:e,n:function e(){if(t>=n.length)return{done:true};return{done:false,value:n[t++]}},e:function e(n){throw n},f:e}}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 r,i=true,a=false,o;return{s:function e(){r=n[Symbol.iterator]()},n:function e(){var n=r.next();i=n.done;return n},e:function e(n){a=true;o=n},f:function e(){try{if(!i&&r["return"]!=null)r["return"]()}finally{if(a)throw o}}}}function I(e,n){if(!e)return;if(typeof e==="string")return L(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);if(t==="Object"&&e.constructor)t=e.constructor.name;if(t==="Map"||t==="Set")return Array.from(e);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return L(e,n)}function L(e,n){if(n==null||n>e.length)n=e.length;for(var t=0,r=new Array(n);t1&&arguments[1]!==x?arguments[1]:1;return e[e.length-n]}function R(e){if(typeof e==="string"){var n=/([-\\^$[\]()+{}?*.|])/g;return e.replace(n,"\\$1")}}function M(){this.data=[]}M.prototype.push=function(e){this.data.push(e)};M.prototype.top=function(){return this.data[this.data.length-1]};M.prototype.pop=function(){return this.data.pop()};M.prototype.is_empty=function(){return!this.data.length};function T(e){var a=P();e=e.replace(/\n\r|\r/g,"\n");var o=0;var u=0;var c=[];var s=[];var f=0;e.split(L).filter(Boolean).forEach(function(e){if(e.match(L)){f=0;if(s.length){var n=C(s);if(n.token.match(/\n/)){var t=n.token.split("\n").pop();f+=t.length}else{f+=n.token.length}f+=n.col}var r={col:f,line:u,token:e,offset:o};c.push(r);s.push(r);o+=e.length;f+=e.length;u+=(e.match("\n")||[]).length;return}var i=e.split(a).filter(Boolean);i.forEach(function(e){var n={col:f,line:u,token:e,offset:o};f+=e.length;o+=e.length;c.push(n);s.push(n);if(e==="\n"){++u;s=[];f=0}})});return c}function B(e){var n=e.token,t=mt(e,["token"]);if(n.match(/^"[\s\S]+"$/)&&n.match(/\n/)){var r=new RegExp("^ {1,"+(e.col+1)+"}","mg");n=n.replace(r,"")}return wt({token:n},t)}function D(e,n){var t=arguments.length>2&&arguments[2]!==x?arguments[2]:B;if(n){return T(e).map(t)}else{return T(e).map(function(e){var n=t(e);if(!n||typeof n.token!=="string"){throw new Error("[tokenize] Invalid formatter wrong return object")}if(n.token==="#\\ "){return n.token}return n.token.trim()}).filter(function(e){return e&&!e.match(/^;/)})}}var H={LITERAL:Symbol["for"]("literal"),SPLICE:Symbol["for"]("splice"),names:function e(){return Object.keys(this._specials)},type:function e(n){return this.get(n).type},get:function e(n){return this._specials[n]},append:function e(n,t,r){this._specials[n]={seq:n,symbol:t,type:r}},_specials:{}};function J(e){return H.type(e)===H.LITERAL}var U=[["'",new he("quote"),H.LITERAL],["`",new he("quasiquote"),H.LITERAL],[",@",new he("unquote-splicing"),H.LITERAL],[",",new he("unquote"),H.LITERAL]];U.forEach(function(e){var n=yt(e,3),t=n[0],r=n[1],i=n[2];H.append(t,r,i)});function $(e){if(typeof e==="string"){e=D(e)}var c=[];var s=[];var f=null;var l=H.names();var p=l.map(function(e){return H.get(e).symbol.name});var h=0;var v=false;var d=[];var m=[];var y=0;var g=he(Symbol["for"]("__splice__"));function b(e){return e==="("||e==="["}function w(e){return e===")"||e==="]"}function _(){var e=c[c.length-1];if(e instanceof Array&&e[0]instanceof he&&p.includes(e[0].name)&&c.length>1&&!e[0].literal){c.pop();if(c[c.length-1].length===1&&c[c.length-1][0]instanceof he){c[c.length-1].push(e)}else if(c[c.length-1]instanceof me){if(c[c.length-1].cdr instanceof me){c[c.length-1]=new me(c[c.length-1],me.fromArray(e))}else{c[c.length-1].cdr=me.fromArray(e)}}else{c[c.length-1].push(e)}}}e.forEach(function(e){var n=c[c.length-1];if(l.indexOf(e)!==-1){y++;f=e;c.push([H.get(f).symbol]);if(!f){m=[]}m.push(f)}else{if(f){d.push(m);m=[]}if(b(e)){v=true;h++;var t=[];if(f&&!J(f)){t.push(g)}c.push(t);f=null;y=0}else if(e==="."&&!v){c[c.length-1]=me.fromArray(n)}else if(w(e)){h--;if(!c.length){throw new Error("Unbalanced parenthesis")}if(c.length===1){var r=c.pop();if(r instanceof Array&&r.length===0){r=de}s.push(r)}else if(c.length>1){var i=c.pop();n=c[c.length-1];if(n instanceof Array){if(i.length===0){n.push(de)}else if(i instanceof Array&&i[0]===g){var a;(a=n).push.apply(a,vt(i.slice(1)))}else{n.push(i)}}else if(n instanceof me){if(i.length===0){n.append(de)}else{n.append(me.fromArray(i))}}if(d.length){m=d.pop();while(m.length){_();m.pop()}}else{_()}}if(h===0&&c.length){s.push(c.pop())}}else{v=false;var o=A(e);if(f){while(y--){c[c.length-1].push(o);o=c.pop()}d.pop();y=0;f=false}else if(o instanceof he&&p.includes(o.name)){o.literal=true}n=c[c.length-1];if(n instanceof me){var u=n;while(true){if(u.cdr===de){if(o instanceof Array){u.cdr=me.fromArray(o)}else{u.cdr=o}break}else{u=u.cdr}}}else if(!c.length){s.push(o)}else{n.push(o)}}}});if(!e.filter(function(e){return e.match(/^[[\]()]$/)}).length&&c.length){s=s.concat(c);c=[]}if(c.length){throw new Error("Unbalanced parenthesis 2")}return s.map(function(e){if(e instanceof Array){return me.fromArray(e)}return e})}function Y(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:function(e){return e};var t=arguments.length>2&&arguments[2]!==x?arguments[2]:null;if(e instanceof Array){var r=e.filter(Ne);if(r.length){return Y(Promise.all(r),n,t)}return n(e)}if(Ne(e)){var i=e.then(n);if(t===null){return i}else{return i["catch"](t)}}return n(e)}function G(e,n){if(n instanceof RegExp){return function(e){return String(e).match(n)}}else if(typeof n!=="function"){throw new Error("".concat(e," argument need to be a function or RegExp"))}else{return n}}function z(e,n,t){if(n){if(t){e.__doc__=n}else{e.__doc__=V(n)}}return e}function V(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function Q(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:1;var t=e.length;if(n<=0){throw Error("previousSexp: Invlaid argument sexp = ".concat(n))}e:while(n--&&t>=0){var r=1;while(r>0){var i=e[--t];if(!i){break e}if(i==="("||i.token==="("){r--}else if(i===")"||i.token===")"){r++}}t--}return e.slice(t+1)}function X(e){if(!e||!e.length){return 0}var n=e.length;if(e[n-1].token==="\n"){return 0}while(--n){if(e[n].token==="\n"){var t=(e[n+1]||{}).token;if(t){return t.length}}}return 0}function K(e,n){return s(e,n)===n.length;function s(e,n){function t(){return i>0&&o>0&&e[i-1]===n[o-1]&&e[i+1]===n[o]}function r(){return e[i]===Symbol["for"]("symbol")&&!I(n[o])}var i=0;var a={};for(var o=0;o0){continue}}else if(r()){return-1}}else if(e[i]instanceof Array){var c=s(e[i],n.slice(o));if(c===-1||c+o>n.length){return-1}o+=c-1;i++;continue}else{return-1}i++}if(e.length!==i){return-1}return n.length}}function W(e){this._code=e.replace(/\r/g,"")}W.defaults={offset:0,indent:2,exceptions:{specials:[/^define/,"lambda","let*",/^(let|letrec)(-syntax)?$/,"let-env","syntax-rules","try","catch"],shift:{1:["&","#"]}}};W.match=K;W.prototype._options=function e(n){var t=W.defaults;if(typeof n==="undefined"){return Object.assign({},t)}var r=n&&n.exceptions||{};var i=r.specials||[];var a=r.shift||{1:[]};return wt(wt(wt({},t),n),{},{exceptions:{specials:[].concat(vt(t.exceptions.specials),vt(i)),shift:wt(wt({},a),{},{1:[].concat(vt(t.exceptions.shift[1]),vt(a[1]))})}})};W.prototype.indent=function e(n){var t=D(this._code,true);return this._indent(t,n)};W.exception_shift=function(a,e){function n(e){if(!e.length){return false}if(e.indexOf(a)!==-1){return true}else{var n=e.filter(function(e){return e instanceof RegExp});if(!n.length){return false}var t=bt(n),r;try{for(t.s();!(r=t.n()).done;){var i=r.value;if(a.match(i)){return true}}}catch(e){t.e(e)}finally{t.f()}}return false}if(n(e.exceptions.specials)){return e.indent}var t=e.exceptions.shift;for(var r=0,i=Object.entries(t);r0){r.offset=0}if(a.toString()===n.toString()&&at(a)){return r.offset+a[0].col}else if(a.length===1){return r.offset+a[0].col+1}else{var u=-1;if(o){var c=W.exception_shift(o.token,r);if(c!==-1){u=c}}if(u===-1){u=W.exception_shift(a[1].token,r)}if(u!==-1){return r.offset+a[0].col+u}else if(a[0].line3&&a[1].line===a[3].line){if(a[1].token==="("||a[1].token==="["){return r.offset+a[1].col}return r.offset+a[3].col}else if(a[0].line===a[1].line){return r.offset+r.indent+a[0].col}else{var s=a.slice(2);for(var f=0;f1&&arguments[1]!==x?arguments[1]:true;if(e instanceof me){return e}if(n===false){var t=de;for(var r=e.length;r--;){t=new me(e[r],t)}return t}if(e.length&&!(e instanceof Array)){e=vt(e)}if(e.length===0){return de}else{var i;if(e[0]instanceof Array){i=me.fromArray(e[0])}else{i=e[0]}if(typeof i==="string"){i=un(i)}if(e.length===1){return new me(i,de)}else{return new me(i,me.fromArray(e.slice(1)))}}};me.prototype.toObject=function(){var e=arguments.length>0&&arguments[0]!==x?arguments[0]:false;var n=this;var t={};while(true){if(n instanceof me&&n.car instanceof me){var r=n.car;var i=r.car;if(i instanceof he){i=i.name}if(i instanceof String){i=i.valueOf()}var a=r.cdr;if(a instanceof me){a=a.toObject(e)}if(a instanceof vn||a instanceof un||a instanceof on){if(!e){a=a.valueOf()}}t[i]=a;n=n.cdr}else{break}}return t};me.fromPairs=function(e){return e.reduce(function(e,n){return new me(new me(new he(n[0]),n[1]),e)},de)};me.fromObject=function(n){var e=Object.keys(n).map(function(e){return[e,n[e]]});return me.fromPairs(e)};me.prototype.reduce=function(e){var n=this;var t=de;while(true){if(n!==de){t=e(t,n.car);n=n.cdr}else{break}}return t};me.prototype.reverse=function(){if(this.haveCycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var n=de;while(e!==de){var t=e.cdr;e.cdr=n;n=e;e=t}return n};me.prototype.transform=function(r){function i(e){if(e instanceof me){if(e.replace){delete e.replace;return e}var n=r(e.car);if(n instanceof me){n=i(n)}var t=r(e.cdr);if(t instanceof me){t=i(t)}return new me(n,t)}return e}return i(this)};me.prototype.map=function(e){if(typeof this.car!=="undefined"){return new me(e(this.car),this.cdr===de?de:this.cdr.map(e))}else{return de}};function ge(n,t){if(typeof jQuery!=="undefined"&&n instanceof jQuery.fn.init){return"#"}if(n===true){return"#t"}if(n===false){return"#f"}if(typeof n==="undefined"){return"#"}if(n instanceof me){return n.toString(t)}var e=[RegExp,ve,he,vn,on,Mn];for(var r=0,i=e;r"}return"#"}if(n instanceof Array){var o=[];for(var u=0,c=n.length;u")}else{o.push(ge(n[u],true))}}return"#("+o.join(" ")+")"}if(n instanceof un){n=n.toString()}if(n===null||typeof n==="string"&&t){return JSON.stringify(n).replace(/\\n/g,"\n")}if(p.HTMLElement&&n instanceof p.HTMLElement){return"#")}if(gt(n)==="object"){if(typeof n.toString==="function"&&n.toString.__lambda__){return n.toString().valueOf()}var s=n.constructor;var f=gt(n)==="object"&&s===Object;if(f){return"&("+Object.keys(n).map(function(e){return":".concat(e," ").concat(ge(n[e],t))}).join(" ")+")"}var l;if(typeof s.__className==="string"){l=s.__className}else if(Kn(n)==="instance"){l="instance"}else{l=s.name}if(l!==""){return"#<"+l+">"}return"#"}if(typeof n!=="string"){return n.toString()}return n}me.prototype.markCycles=function(){be(this);return this};me.prototype.haveCycles=function(){var e=arguments.length>0&&arguments[0]!==x?arguments[0]:null;if(!e){return this.haveCycles("car")||this.haveCycles("cdr")}return!!(this.cycles&&this.cycles[e])};function be(e){var i=[];var n=[];function a(e){if(e instanceof me){if(i.includes(e)){if(!n.includes(e)){n.push(e)}return"#".concat(n.length-1,"#")}}}function o(e){if(e instanceof me){i.push(e);var n={};var t=a(e.car);var r=a(e.cdr);if(t){n["car"]=t}else{o(e.car)}if(r){n["cdr"]=r}else{o(e.cdr)}if(t||r){e.cycles=n}else if(e.cycles){delete e.cycles}}}o(e)}me.prototype.toString=function(e){var n=["("];if(this.car!==x){var t;if(this.cycles&&this.cycles.car){t=this.cycles.car}else{t=ge(this.car,e)}if(t!==x){n.push(t)}if(this.cdr instanceof me){if(this.cycles&&this.cycles.cdr){n.push(" . ");n.push(this.cycles.cdr)}else{var r=this.cdr.toString(e).replace(/^\(|\)$/g,"");n.push(" ");n.push(r)}}else if(typeof this.cdr!=="undefined"&&this.cdr!==de){n=n.concat([" . ",ge(this.cdr,e)])}}n.push(")");return n.join("")};me.prototype.set=function(e,n){this[e]=n;if(n instanceof me){this.markCycles()}};me.prototype.append=function(e){if(e instanceof Array){return this.append(me.fromArray(e))}var n=this;if(n.car===x){if(e instanceof me){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(e!==de){while(true){if(n instanceof me&&n.cdr!==de){n=n.cdr}else{break}}n.cdr=e}return this};function we(e){return e<0?-e:e}function _e(e,n){var t=ht(n),r=t[0],i=t.slice(1);while(i.length>0){var a=i,o=yt(a,1),u=o[0];if(!e(r,u)){return false}var c=i;var s=ht(c);r=s[0];i=s.slice(1)}return true}function xe(e,n){if(typeof e==="function"&&typeof n==="function"){return Re(e)===Re(n)}else if(e instanceof vn&&n instanceof vn){return e.type===n.type&&e.cmp(n)===0}else if(typeof e==="number"||typeof n==="number"){e=vn(e);n=vn(n);return e.type===n.type&&e.cmp(n)===0}else if(e instanceof on&&n instanceof on){return e["char"]===n["char"]}else if(e instanceof he&&n instanceof he){return e.name===n.name}else{return e===n}}var ke=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function Se(e,n,t,r){if(typeof this!=="undefined"&&this.constructor!==Se||typeof this==="undefined"){return new Se(e,n)}Qn("Macro",e,"string",1);Qn("Macro",n,"function",2);if(t){if(r){this.__doc__=t}else{this.__doc__=V(t)}}this.name=e;this.fn=n}Se.defmacro=function(e,n,t,r){var i=new Se(e,n,t,r);i.defmacro=true;return i};Se.prototype.invoke=function(e,n,t){var r=n.env,i=n.dynamic_scope,a=n.error;var o={dynamic_scope:i,error:a,macro_expand:t};var u=this.fn.call(r,e,o,this.name);return u};Se.prototype.toString=function(){return"#"};var Oe="define-macro";function je(i){return function(){var t=pt(lt.mark(function e(t,f){var l,p,r;return lt.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:r=function e(){r=pt(lt.mark(function e(t,r){var i,a,o,u,c,s;return lt.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(!(t instanceof me&&t.car instanceof he)){n.next=17;break}if(!t.data){n.next=3;break}return n.abrupt("return",t);case 3:i=l.get(t.car,{throwError:false});if(!(i instanceof Se&&i.defmacro)){n.next=17;break}a=i instanceof Ee?t:t.cdr;n.next=8;return i.invoke(a,f,true);case 8:o=n.sent;if(!(o instanceof he)){n.next=11;break}return n.abrupt("return",Tn(o));case 11:if(!(o instanceof me)){n.next=17;break}if(!(typeof r==="number")){n.next=16;break}if(!(r<=1)){n.next=15;break}return n.abrupt("return",o);case 15:r=r-1;case 16:return n.abrupt("return",p(o,r));case 17:u=t.car;if(!(u instanceof me)){n.next=22;break}n.next=21;return p(u);case 21:u=n.sent;case 22:c=t.cdr;if(!(c instanceof me)){n.next=27;break}n.next=26;return p(c);case 26:c=n.sent;case 27:s=new me(u,c);return n.abrupt("return",s);case 29:case"end":return n.stop()}}},e)}));return r.apply(this,arguments)};p=function e(n,t){return r.apply(this,arguments)};l=f["env"]=this;if(!i){n.next=11;break}n.t0=Tn;n.next=7;return p(t,1);case 7:n.t1=n.sent.car;return n.abrupt("return",(0,n.t0)(n.t1));case 11:n.t2=Tn;n.next=14;return p(t,-1);case 14:n.t3=n.sent.car;return n.abrupt("return",(0,n.t2)(n.t3));case 16:case"end":return n.stop()}}},e,this)}));return function(e,n){return t.apply(this,arguments)}}()}function Ee(e,n){this.name="syntax";this.env=n;this.fn=e;this.defmacro=true}Ee.merge_env=Symbol["for"]("merge");Ee.prototype=Object.create(Se.prototype);Ee.prototype.invoke=function(e,n,t){var r=n.error,i=n.env;var a={error:r,env:i,dynamic_scope:this.env,macro_expand:t};return this.fn.call(i,e,a,this.name)};Ee.prototype.constructor=Ee;Ee.prototype.toString=function(){return"<#syntax>"};Ee.className="syntax";function Fe(e,n,d,m){var y={"...":{symbols:{},lists:[]}};function g(e){if(Hn.get("DEBUG",{throwError:false})){console.log(e)}}g(d);function b(e,n){var t=arguments.length>2&&arguments[2]!==x?arguments[2]:[];var r=arguments.length>3&&arguments[3]!==x?arguments[3]:false;g({code:n.toString(),pattern:e.toString()});if(e instanceof me&&e.car instanceof me&&e.car.cdr instanceof me&&he.is(e.car.cdr.car,m)){g(">> 0");if(n===de){g({pattern:e.toString()});if(e.car.car instanceof he){if(e.car.cdr instanceof me&&he.is(e.car.cdr.car,m)){var i=e.car.car.valueOf();var a=e.lastPair();if(he.is(a.car,m)){y["..."].symbols[i]=null;return true}else{return false}}var o=e.car.car.valueOf();if(y["..."].symbols[o]){throw new Error("syntax: named ellipsis can only "+"appear onces")}y["..."].symbols[o]=n}return true}}if(e instanceof me&&e.cdr instanceof me&&he.is(e.cdr.car,m)){if(e.cdr.cdr!==de){throw new Error("syntax: invalid usage of ellipsis")}if(e.car instanceof he){var u=e.car.name;if(y["..."].symbols[u]&&!t.includes(u)&&!r){throw new Error("syntax: named ellipsis can only appear onces")}g(">> 1");if(n===de){g(">> 2");if(r){y["..."].symbols[u]=de}else{return false}}else if(n instanceof me&&(n.car instanceof me||n.car===de)){g(">> 3 "+r);if(r){if(y["..."].symbols[u]){var c=y["..."].symbols[u];y["..."].symbols[u]=c.append(new me(n,de))}else{y["..."].symbols[u]=new me(n,de)}}else{g(">> 4");y["..."].symbols[u]=new me(n,de)}}else{g(">> 6");if(n instanceof me){g(">> 7 "+r);t.push(u);if(!y["..."].symbols[u]){y["..."].symbols[u]=new me(n,de)}else{var s=y["..."].symbols[u];y["..."].symbols[u]=s.append(new me(n,de))}g({IIIIII:y["..."].symbols[u].toString()})}else{g(">> 8");return false}}return true}else if(e.car instanceof me){var f=vt(t);if(n===de){g(">> 9");y["..."].lists.push(de);return true}g(">> 10");var l=n;while(l instanceof me){if(!b(e.car,l.car,f,true)){return false}l=l.cdr}return true}return false}if(e instanceof he){if(he.is(e,m)){throw new Error("syntax: invalid usage of ellipsis")}g(">> 11");var p=e.name;if(d.includes(p)){return true}g({name:p});if(r){y["..."].symbols[p]=y["..."].symbols[p]||[];y["..."].symbols[p].push(n)}if(!y[p]){y[p]=n}return true}if(e instanceof me&&n instanceof me){g(">> 12");g(n.toString());if(n.cdr===de){var h=e.car instanceof he&&e.cdr instanceof he;if(h){g(">> 12 | 1");var v=e.cdr.valueOf();if(!y[v]){y[v]=de}v=e.car.valueOf();if(!y[v]){y[v]=n.car}return true}}if(b(e.car,n.car,t,r)&&b(e.cdr,n.cdr,t,r)){return true}}else if(e===de&&n===de){return true}else if(e.car instanceof me&&he.is(e.car.car,m)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(b(e,n)){return y}}function Ae(e,i){function a(n){if(n instanceof me){if(!i.length){return n}var e=a(n.car);var t=a(n.cdr);return new me(e,t)}else if(n instanceof he){var r=i.find(function(e){return e.gensym===n});if(r){return he(r.name)}return n}else{return n}}return a(e)}function Ie(){var e=arguments.length>0&&arguments[0]!==x?arguments[0]:{};var v=e.bindings,n=e.expr,r=e.scope,i=e.names,d=e.ellipsis;var a={};function m(e){if(!(e instanceof he||typeof e==="string")){throw new Error("syntax: internal error, rename neeed to be symbol")}var n=e.valueOf();if(n===d){throw new Error("syntax: internal error, ellipis not transformed")}if(typeof n==="string"&&n in v){return v[n]}return t(n)}function y(e){if(Hn.get("DEBUG",{throwError:false})){console.log(e)}}function t(e){if(!a[e]){var n=r.get(e,{throwError:false});var t=Bn(e);i.push({name:e,gensym:t});if(typeof n!=="undefined"){r.set(t,n)}a[e]=t}return a[e]}function g(e,n,t){var r=arguments.length>3&&arguments[3]!==x?arguments[3]:function(){};y(" ==> "+e.toString());if(e instanceof he){var i=e.valueOf();y("[t 1");if(n[i]){if(n[i]instanceof me){var a=n[i],o=a.car,u=a.cdr;if(t){var c=o.car,s=o.cdr;if(s!==de){r(i,new me(s,de))}return c}if(u!==de){r(i,u)}return o}else if(n[i]instanceof Array){r(i,n[i].slice(1));return n[i][0]}}return m(i)}if(e instanceof me){if(e.car instanceof he&&e.cdr instanceof me&&he.is(e.cdr.car,d)){y("[t 2");var f=e.car.valueOf();var l=n[f];if(l){y({b:n[f]});if(l instanceof me){y("[t 2 Pair "+t);y({______:l.toString()});var p=l.car,h=l.cdr;if(t){if(h!==de){r(f,h)}return p}else{if(p.cdr!==de){r(f,new me(p.cdr,h))}return p.car}}else if(l instanceof Array){y("[t 2 Array "+t);if(t){r(f,l.slice(1));return me.fromArray(l)}else{var v=l.slice(1);if(v.length){r(f,v)}return l[0]}}else{return l}}}y("[t 3 recur "+e.toString());return new me(g(e.car,n,t,r),g(e.cdr,n,t,r))}}function b(n){var e=Object.values(n);var t=Object.getOwnPropertySymbols(n);if(t.length){e.push.apply(e,vt(t.map(function(e){return n[e]})))}return e.length&&e.every(function(e){return e instanceof me||e===de||e instanceof Array&&e.length})}function w(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function _(i){if(i instanceof me){if(i.cdr instanceof me&&he.is(i.cdr.car,d)){y(">> 1");var e=v["..."].symbols;var n=w(e);if(i.car instanceof me){if(v["..."].lists[0]===de){return de}y(">> 2");var t;if(n.length){y(">> 2 (a)");var a=wt({},e);t=de;var r=function e(){if(!b(a)){return"break"}var r={};var n=function e(n,t){r[n]=t};t=new me(g(i.car,a,true,n),t);a=r};while(true){var o=r();if(o==="break")break}if(t!==de){t=t.reverse()}return t}else{y(">> 3");var u=g(i.car,e,true);if(u){return new me(u,de)}return de}}else if(i.car instanceof he){y(">> 4");var c=i.car.name;var s=dt({},c,e[c]);var f=de;var l=function e(){if(!b(s)){y({bind:s});return"break"}var r={};var n=function e(n,t){r[n]=t};y({EXPR:i.toString()});var t=g(i,s,false,n);f=new me(t,f);s=r};while(true){var p=l();if(p==="break")break}if(f!==de){f=f.reverse()}if(i.cdr instanceof me&&i.cdr.cdr instanceof me){f.append(_(i.cdr.cdr))}return f}}return new me(_(i.car),_(i.cdr))}if(i instanceof he){var h=m(i);if(typeof h!=="undefined"){return h}}return i}return _(n)}function Le(e){return typeof e==="undefined"||e===de||e===null}function Ne(e){return e instanceof Promise||e&&typeof e!=="undefined"&&typeof e.then==="function"}function qe(e){switch(gt(e)){case"string":return un(e);case"number":return vn(e)}return e}function Pe(e){return e&&e.valueOf&&e.valueOf()||e}function Ce(e,n){if(e instanceof me){e.markCycles();return Tn(e)}if(typeof e==="function"){if(n){return Me(e,n)}}return qe(e)}function Re(e){if(Te(e)){return e[Be]}return e}function Me(n,e){if(n[Symbol["for"]("__bound__")]){return n}var t=n.bind(e);var r=Object.getOwnPropertyNames(n).filter(He);r.forEach(function(e){try{t[e]=n[e]}catch(e){}});Je(t,"__fn__",n);Je(t,"__bound__",true);if($e(n)){Je(t,"__native__",true)}t.valueOf=function(){return n};return t}function Te(e){return typeof e==="function"&&e[Be]}var Be=Symbol["for"]("__fn__");var De=["name","length","caller","callee","arguments","prototype"];function He(e){return!De.includes(e)}function Je(e,n,t){Object.defineProperty(e,Symbol["for"](n),{get:function e(){return t},set:function e(){},configurable:false,enumerable:false})}function Ue(n,t){try{Object.defineProperty(n,"length",{get:function e(){return t}});return n}catch(e){var r=new Array(t).fill(0).map(function(e,n){return"a"+n}).join(",");var i=new Function("f","return function(".concat(r,") {\n return f.apply(this, arguments);\n };"));return i(n)}}function $e(e){var n=Symbol["for"]("__native__");return typeof e==="function"&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[n]===true||!e.name.match(/^bound /)&&!e[n])}function Ye(e){var d;switch(e){case Symbol["for"]("letrec"):d="letrec";break;case Symbol["for"]("let"):d="let";break;case Symbol["for"]("let*"):d="let*";break;default:throw new Error("Invalid let_macro value")}return Se.defmacro(d,function(n,e){var o=e.dynamic_scope,u=e.error,t=e.macro_expand;var c;if(n.car instanceof he){if(!(n.cdr.car instanceof me||n.cdr.car===de)){throw new Error("let require list of pairs")}var r;if(n.cdr.car===de){c=de;r=de}else{r=n.cdr.car.map(function(e){return e.car});c=n.cdr.car.map(function(e){return e.cdr.car})}return me.fromArray([he("letrec"),[[n.car,me(he("lambda"),me(r,n.cdr.cdr))]],me(n.car,c)])}else if(t){return}var s=this;c=this.get("list->array")(n.car);var f=s.inherit(d);var l,p;if(d==="let*"){p=f}else if(d==="let"){l=[]}var h=0;function v(){var e=new me(new he("begin"),n.cdr);return tt(e,{env:f,dynamic_scope:o,error:u})}return function n(){var t=c[h++];function r(e,n){if(typeof n==="undefined"){f.set(e,de)}else{f.set(e,n)}}if(o){o=d==="let*"?f:s}if(!t){if(l&&l.length){var e=l.map(function(e){return e.value});var i=e.filter(Ne);if(i.length){return Promise.all(e).then(function(e){for(var n=0,t=e.length;n1&&arguments[1]!==x?arguments[1]:{},t=n.dynamic_scope,r=n.error;var i=this;if(t){t=this}var a=e;var o=[];while(a instanceof me){o.push(tt(a.car,{env:i,dynamic_scope:t,error:r}));a=a.cdr}var u=o.filter(Ne).length;if(u){return Promise.all(o).then(c.bind(this))}else{return c.call(this,o)}})}function ze(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r2?r-2:0),a=2;a1&&arguments[1]!==x?arguments[1]:null;return function(){for(var e=arguments.length,n=new Array(e),t=0;t1?e-1:0),t=1;t=o){return a.apply(this,r)}else{return i}}return i.apply(this,arguments)}}function tn(r,i){Qn("limit",i,"function",2);return function(){for(var e=arguments.length,n=new Array(e),t=0;t1?r-1:0),a=1;a0){t.push(this._string.substring(0,e))}t.push(n);if(e1&&arguments[1]!==x?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof vn)||typeof this==="undefined"){return new vn(e,n)}if(typeof e==="undefined"){throw new Error("Invlaid LNumber constructor call")}var t=vn.getType(e);if(vn.types[t]){return vn.types[t](e,n)}var r=e instanceof Array&&un.isString(e[0])&&vn.isNumber(e[1]);if(e instanceof vn){return vn(e.value)}if(!vn.isNumber(e)&&!r){throw new Error("You can't create LNumber from ".concat(Kn(e)))}if(e===null){e=0}var i;if(r){var a=e,o=yt(a,2),u=o[0],c=o[1];if(u instanceof un){u=u.valueOf()}if(c instanceof vn){c=c.valueOf()}var s=u.match(/^([+-])/);var f=false;if(s){u=u.replace(/^[+-]/,"");if(s[1]==="-"){f=true}}}if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(r){var l;switch(c){case 8:l="0o";break;case 16:l="0x";break;case 2:l="0b";break;case 10:l="";break}if(typeof l==="undefined"){var p=BigInt(c);i=vt(u).map(function(e,n){return BigInt(parseInt(e,c))*Math.pow(p,BigInt(n))}).reduce(function(e,n){return e+n})}else{i=BigInt(l+u)}}else{i=BigInt(e)}if(f){i*=BigInt(-1)}}else{i=e}return xn(i,true)}else if(typeof h!=="undefined"&&!(e instanceof h)){if(e instanceof Array){return xn(ft(h,vt(e)))}return xn(new h(e))}else if(r){this.value=parseInt(u,c)}else{this.value=e}}vn.types={float:function e(n){var t=arguments.length>1&&arguments[1]!==x?arguments[1]:false;return new mn(n,t)},complex:function e(n){var t=arguments.length>1&&arguments[1]!==x?arguments[1]:false;return new dn(n,t)},rational:function e(n){var t=arguments.length>1&&arguments[1]!==x?arguments[1]:false;return new _n(n,t)}};function dn(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof dn)||typeof this==="undefined"){return new dn(e,n)}if(e instanceof dn){return dn({im:e.im,re:e.re})}if(vn.isNumber(e)&&n){e={im:0,re:e.valueOf()}}else if(!vn.isComplex(e)){throw new Error("Invalid constructor call for LComplex")}var t=vn.coerce(e.im,e.re),r=yt(t,2),i=r[0],a=r[1];if(i.cmp(0)===0&&!n){return a}this.im=i;this.re=a;this.type="complex"}dn.prototype=Object.create(vn.prototype);dn.prototype.constructor=dn;dn.prototype.toRational=function(e){if(vn.isFloat(this.im)&&vn.isFloat(this.re)){var n=mn(this.im).toRational(e);var t=mn(this.re).toRational(e);return dn({im:n,re:t})}return this};dn.prototype.add=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.op("+",n),im:t.op("+",r)}})};dn.prototype.div=function(e){if(vn.isNumber(e)&&!vn.isComplex(e)){e=dn({im:0,re:e})}else if(!vn.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var n=dn({re:e.re,im:e.im.sub()});var t=e.re.mul(e.re).add(e.im.mul(e.im));var r=this.mul(n);var i=r.re.op("/",t);var a=r.im.op("/",t);return dn({re:i,im:a})};dn.prototype.sub=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.sub(n),im:t.sum(r)}})};dn.prototype.mul=function(e){return this.complex_op(e,function(e,n,t,r){var i={re:e.mul(n).sub(t.mul(r)),im:e.mul(r).add(n.mul(t))};return i})};dn.prototype.complex_op=function(e,n){if(vn.isNumber(e)&&!vn.isComplex(e)){e={im:0,re:e}}else if(!vn.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var t=e.re instanceof vn?e.re:vn(e.re);var r=e.im instanceof vn?e.im:vn(e.im);var i=n(this.re,t,this.im,r);if("im"in i&&"re"in i){var a=dn(i,true);return a}return i};dn._op={"+":"add","-":"sub","*":"mul","/":"div"};dn.prototype._op=function(e,n){var t=dn._op[e];return this[t](n)};dn.prototype.cmp=function(e){var n=this.coerce(e),t=yt(n,2),r=t[0],i=t[1];var a=r.re.coerce(i.re),o=yt(a,2),u=o[0],c=o[1];var s=u.cmp(c);if(s!==0){return s}else{var f=r.im.coerce(i.im),l=yt(f,2),p=l[0],h=l[1];return p.cmp(h)}};dn.prototype.valueOf=function(){};dn.prototype.toString=function(){var e;if(this.re.cmp(0)!==0){e=[this.re.toString()]}else{e=[]}e.push(this.im.cmp(0)<0?"-":"+");e.push(this.im.toString().replace(/^-/,""));e.push("i");return e.join("")};function mn(e){if(typeof this!=="undefined"&&!(this instanceof mn)||typeof this==="undefined"){return new mn(e)}if(!vn.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof vn){return mn(e.valueOf())}if(typeof e==="number"){this.value=e;this.type="float"}}mn.prototype=Object.create(vn.prototype);mn.prototype.constructor=mn;mn.prototype.toString=function(){if(!vn.isFloat(this.value)){return this.value+".0"}return this.value.toString()};mn.prototype._op=function(e,n){if(n instanceof vn){n=n.value}var t=vn._ops[e];return mn(t(this.value,n))};mn.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==x?arguments[0]:null;if(e===null){return yn(this.value.valueOf())}return gn(e.valueOf())(this.value.valueOf())};var yn=gn(1e-10);function gn(r){return function(e){var n=function e(r,n,t){var i=function e(n,t){return t0){i=wn(r,t)}else if(r.cmp(t)<=0){i=t}else if(t.cmp(0)>0){i=wn(t,r)}else if(n.cmp(0)<0){i=vn(wn(r.sub(),t.sub())).sub()}else{i=vn(0)}if(vn.isFloat(n)||vn.isFloat(e)){return mn(i)}return i}function wn(e,n){var t=vn(e).floor();var r=vn(n).floor();if(e.cmp(t)<1){return t}else if(t.cmp(r)===0){var i=vn(1).div(n.sub(r));var a=vn(1).div(e.sub(t));return t.add(vn(1).div(wn(i,a)))}else{return t.add(vn(1))}}function _n(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof _n)||typeof this==="undefined"){return new _n(e,n)}if(!vn.isRational(e)){throw new Error("Invalid constructor call for LRational")}if(e.num%e.denom===0&&!n){return vn(e.num/e.denom)}this.num=vn(e.num);this.denom=vn(e.denom);this.type="rational"}_n.prototype=Object.create(vn.prototype);_n.prototype.constructor=_n;_n.prototype.pow=function(e){var n=e.cmp(0);if(n===0){return vn(1)}if(n===-1){e=e.sub();var t=this.denom.pow(e);var r=this.num.pow(e);return _n({num:t,denom:r})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};_n.prototype.abs=function(){var e=this.num;var n=this.denom;if(e.cmp(0)===-1){e=e.sub()}if(n.cmp(0)!==1){n=n.sub()}return _n({num:e,denom:n})};_n.prototype.cmp=function(e){return vn(this.valueOf(),true).cmp(e)};_n.prototype.toString=function(){var e=Dn.get("gdc")(this.num,this.denom);var n,t;if(e.cmp(1)!==0){e=vn(e);n=this.num.div(e);t=this.denom.div(e)}else{n=this.num;t=this.denom}var r=this.cmp(0)<0;if(r){if(n.abs().cmp(t.abs())===0){return n.toString()}}else if(n.cmp(t)===0){return n.toString()}return n+"/"+t};_n.prototype.valueOf=function(){return mn(this.num.valueOf()).div(this.denom.valueOf())};_n.prototype.mul=function(e){if(vn.isRational(e)){var n=this.num.mul(e.num);var t=this.denom.mul(e.denom);return _n({num:n,denom:t})}return vn(this.valueOf()).mul(e)};_n.prototype.div=function(e){if(vn.isRational(e)){var n=this.num.mul(e.denom);var t=this.denom.mul(e.num);return _n({num:n,denom:t})}return vn(this.valueOf()).div(e)};_n.prototype._op=function(e,n){return this[jn[e]](n)};_n.prototype.sub=function(e){if(vn.isRational(e)){var n=e.num.sub();var t=e.denom;return this.add(_n({num:n,denom:t}))}if(!(e instanceof vn)){e=vn(e).sub()}else{e=e.sub()}if(vn.isFloat(e)){return mn(this.valueOf()).add(e)}return this.add(e)};_n.prototype.add=function(e){if(vn.isRational(e)){var n=this.denom;var t=e.denom;var r=this.num;var i=e.num;var a,o;if(n!==t){o=t.mul(r).add(i.mul(n));a=n.mul(t)}else{o=r.add(i);a=n}return _n({num:o,denom:a})}if(vn.isFloat(e)){return mn(this.valueOf()).add(e)}return vn(this.valueOf()).add(e)};function xn(e,n){if(typeof this!=="undefined"&&!(this instanceof xn)||typeof this==="undefined"){return new xn(e,n)}if(e instanceof xn){return xn(e.value,e._native)}if(!vn.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.value=e;this._native=n;this.type="bigint"}xn.prototype=Object.create(vn.prototype);xn.prototype.constructor=xn;xn.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};xn.prototype._op=function(e,n){if(typeof n==="undefined"){if(vn.isBN(this.value)){e=xn.bn_op[e];return xn(this.value.clone()[e](),false)}return xn(vn._ops[e](this.value))}if(vn.isBN(this.value)&&vn.isBN(n.value)){e=xn.bn_op[e];return xn(this.value.clone()[e](n),false)}if(e==="/"){return _n({num:this,denom:n})}var t=vn._ops[e](this.value,n.value);return xn(t)};xn.prototype.sqrt=function(){var e;var n=this.cmp(0)<0;if(vn.isNative(this.value)){e=Math.sqrt(n?-this.valueOf():this.valueOf())}else if(vn.isBN(this.value)){e=n?this.value.neg().sqrt():this.value.sqrt()}if(n){return dn({re:0,im:e})}return e};vn.isFloat=function e(n){return n instanceof mn||Number(n)===n&&n%1!==0};vn.isNumber=function(e){return e instanceof vn||!Number.isNaN(e)&&vn.isNative(e)||vn.isBN(e)};vn.isComplex=function(e){var n=e instanceof dn||vn.isNumber(e.im)&&vn.isNumber(e.re);return n};vn.isRational=function(e){return e instanceof _n||vn.isNumber(e.num)&&vn.isNumber(e.denom)};vn.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};vn.isBigInteger=function(e){return e instanceof xn||typeof e==="bigint"||vn.isBN(e)};vn.isBN=function(e){return typeof h!=="undefined"&&e instanceof h};vn.getArgsType=function(e,n){if(e instanceof mn||n instanceof mn){return mn}if(e instanceof xn||n instanceof xn){return xn}return vn};vn.prototype.toString=vn.prototype.toJSON=function(e){if(e>2&&e<36){return this.value.toString(e)}return this.value.toString()};vn.prototype.isBigNumber=function(){return typeof this.value==="bigint"||typeof h!=="undefined"&&!(this.value instanceof h)};["floor","ceil","round"].forEach(function(e){vn.prototype[e]=function(){if(this["float"]||vn.isFloat(this.value)){return vn(Math[e](this.value))}else{return vn(Math[e](this.valueOf()))}}});vn.prototype.valueOf=function(){if(vn.isNative(this.value)){return Number(this.value)}else if(vn.isBN(this.value)){return this.value.toNumber()}};var kn=function(){var e=function e(n,t){return[n,t]};return{bigint:{bigint:e,float:function e(n,t){return[mn(n.valueOf()),t]},rational:function e(n,t){return[{num:n,denom:1},t]},complex:function e(n,t){return[{im:0,re:n},t]}},float:{bigint:function e(n,t){return[n,t&&mn(t.valueOf())]},float:e,rational:function e(n,t){return[n,t&&mn(t.valueOf())]},complex:function e(n,t){return[{re:n,im:mn(0)},t]}},complex:{bigint:n("bigint"),float:n("float"),rational:n("rational"),complex:function e(n,t){var r=vn.coerce(n.re,t.re),i=yt(r,2),a=i[0],o=i[1];var u=vn.coerce(n.im,t.im),c=yt(u,2),s=c[0],f=c[1];return[{im:s,re:a},{im:f,re:o}]}},rational:{bigint:function e(n,t){return[n,t||{num:t,denom:1}]},float:function e(n,t){return[mn(n.valueOf()),t]},rational:e,complex:n("rational")}};function n(t){return function(e,n){return[{im:Sn(t,e.im.type,e.im),re:Sn(t,e.re.type,e.re)},{im:Sn(t,e.im.type,0),re:Sn(t,n.type,n)}]}}}();function Sn(e,n,t){return kn[e][n](t)[0]}vn.coerce=function(e,n){function t(e){if(e==="integer"){return"bigint"}return e}var r=t(vn.getType(e));var i=t(vn.getType(n));if(!kn[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!kn[r][i]){throw new Error("LNumber::coerce unknown rhs type ".concat(i))}return kn[r][i](e,n).map(function(e){return vn(e,true)})};vn.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof vn)){throw new Error("LNumber: you can't coerce ".concat(Kn(e)))}if(typeof e==="number"){e=vn(e)}return vn.coerce(this,e)};vn.getType=function(e){if(e instanceof vn){return e.type}if(vn.isFloat(e)){return"float"}if(vn.isComplex(e)){return"complex"}if(vn.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof h!=="undefined"&&!(e instanceof h)){return"bigint"}};vn.prototype.isFloat=function(){return!!(vn.isFloat(this.value)||this["float"])};var On={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var jn={};Object.keys(On).forEach(function(n){jn[On[n]]=n;vn.prototype[n]=function(e){return this.op(On[n],e)}});vn._ops={"*":function e(n,t){return n*t},"+":function e(n,t){return n+t},"-":function e(n,t){if(typeof t==="undefined"){return-n}return n-t},"/":function e(n,t){return n/t},"%":function e(n,t){return n%t},"|":function e(n,t){return n|t},"&":function e(n,t){return n&t},"~":function e(n){return~n},">>":function e(n,t){return n>>t},"<<":function e(n,t){return n<"};function An(n){var t=this;if(typeof this!=="undefined"&&!(this instanceof An)||typeof this==="undefined"){return new An(n)}Qn("OutputStringPort",n,"function");this._buffer=[];this.write=function(e){if(!un.isString(e)){e=n(e)}else{e=e.valueOf()}t._buffer.push(e)}}An.prototype=Object.create(Fn.prototype);An.prototype.getString=function(){return this._buffer.map(function(e){return e.valueOf()}).join("")};An.prototype.constructor=An;function In(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof In)||typeof this==="undefined"){return new In(e)}Qn("InputStringPort",e,"string");this._tokens=D(e);this._index=0;this._in_char=0;this.read=function(){return n.getNextTokens()}}In.prototype=Object.create(En.prototype);In.prototype.constructor=In;In.prototype.getNextTokens=function(){if(this.peekChar()===Ln){return Ln}var e=0;var n=[];var t=["(",")"];if(!t.includes(this._tokens[this._index])){return this._tokens[this._index++]}do{var r=this._tokens[this._index];n.push(this._tokens[this._index]);if(r===")"){e--}else if(r==="("){e++}this._index++}while(e!==0);return n};In.prototype.peekChar=function(){if(this._index>this._tokens.length-1){return Ln}if(this._index===this._tokens.length-1&&this.in_char>this._tokens[this._index].length){return Ln}return this._tokens[this._index][this.in_char]};var Ln=new Nn;function Nn(){}Nn.prototype.toString=function(){return"<#eof>"};function qn(e){this.message=e}qn.prototype=Object.create(Error.prototype);function Pn(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:{};if(typeof this!=="undefined"&&!(this instanceof Pn)||typeof this==="undefined"){return new Pn(e,n)}if(typeof e==="undefined"){e="anonymous"}this.env=Hn.inherit(e,n)}Pn.prototype.exec=function(){var n=pt(lt.mark(function e(t){var r,i=arguments;return lt.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:r=i.length>1&&i[1]!==x?i[1]:false;Qn("Intepreter::exec",t,"string",1);Qn("Intepreter::exec",r,"boolean",2);Dn.set("**interaction-environment**",this.env);return n.abrupt("return",rt(t,this.env,r?this.env:false));case 5:case"end":return n.stop()}}},e,this)}));return function(e){return n.apply(this,arguments)}}();Pn.prototype.get=function(e){return this.env.get(e).bind(this.env)};Pn.prototype.set=function(e,n){return this.env.set(e,n)};function Cn(e,n,t){if(arguments.length===1){if(gt(arguments[0])==="object"){e=arguments[0];this.parent=null}else if(typeof arguments[0]==="string"){e={};n={};t=arguments[0]}}this.env=e;this.parent=n;this.name=t||"anonymous"}Cn.prototype.inherit=function(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:{};if(gt(e)==="object"){n=e}if(!e||gt(e)==="object"){e="child of "+(this.name||"unknown")}return new Cn(n||{},this,e)};Cn.prototype.newFrame=function(e,n){var r=this.inherit("__frame__");r.set("parent.frame",z(function(){var e=arguments.length>0&&arguments[0]!==x?arguments[0]:1;var n=r.parent;if(!(n instanceof Cn)){return de}if(e<=0){return n}var t=n.get("parent.frame");return t(e-1)},Dn.env["parent.frame"].__doc__));n.callee=e;r.set("arguments",n);return r};Cn.prototype._lookup=function(e){if(e instanceof he){e=e.name}if(e instanceof un){e=e.valueOf()}if(e in this.env){return Rn(this.env[e])}if(this.parent){return this.parent._lookup(e)}};Cn.prototype.toString=function(){return"<#env:"+this.name+">"};Cn.prototype.clone=function(){var n=this;var t={};Object.keys(this.env).forEach(function(e){t[e]=n.env[e]});return new Cn(t,this.parent,this.name)};Cn.prototype.merge=function(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:"merge";Qn("Environment::merge",e,"environment");return this.inherit(n,e.env)};function Rn(e){if(typeof this!=="undefined"&&!(this instanceof Rn)||typeof this==="undefined"){return new Rn(e)}this.value=e}Rn.isUndefined=function(e){return e instanceof Rn&&typeof e.value==="undefined"};Rn.prototype.valueOf=function(){return this.value};function Mn(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof Mn)||typeof this==="undefined"){return new Mn(e)}this.values=e}Mn.prototype.toString=function(){return this.values.map(function(e){return ge(e)}).join("\n")};Mn.prototype.valueOf=function(){return this.values};Cn.prototype.get=function(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:{};var t=n.throwError,r=t===void 0?true:t;var i=e;if(i instanceof he||i instanceof un){i=i.valueOf()}var a=this._lookup(i);if(a instanceof Rn){if(Rn.isUndefined(a)){return x}return Ce(a.valueOf())}if(typeof i==="string"){var o=i.split(".").filter(Boolean);if(o.length>0){var u=ht(o),c=u[0],s=u.slice(1);a=this._lookup(c);if(s.length){try{if(a instanceof Rn){a=a.valueOf();return an.apply(void 0,[a].concat(vt(s)))}else{return an.apply(void 0,[p].concat(vt(o)))}}catch(e){}}else if(a instanceof Rn){return Ce(a.valueOf())}}a=an(p,i)}if(typeof a!=="undefined"){return a}if(r){throw new Error("Unbound variable `"+i.toString()+"'")}};Cn.prototype.set=function(e,n){if(vn.isNumber(n)){n=vn(n)}if(e instanceof he){e=e.name}else if(e instanceof un){e=e.valueOf()}this.env[e]=n};Cn.prototype.has=function(e){return typeof this.env[e]!=="undefined"};Cn.prototype.ref=function(e){var n=this;while(true){if(!n){break}if(n.has(e)){return n}n=n.parent}};Cn.prototype.parents=function(){var e=this;var n=[];while(e){n.unshift(e);e=e.parent}return n};function Tn(e){if(Ne(e)){return e.then(Tn)}if(e instanceof me||e instanceof he){e.data=true}return e}var Bn=function(){var n=0;return function(){var e=arguments.length>0&&arguments[0]!==x?arguments[0]:null;if(e instanceof he){e=e.valueOf()}if(e!==null){return new he(Symbol("#:".concat(e)))}n++;return new he(Symbol("#:g".concat(n)))}}();var Dn=new Cn({nil:de,undefined:x,true:true,false:false,NaN:NaN,stdout:new Fn(function(){var e;(e=console).log.apply(e,arguments)}),stdin:En(function(){return new Promise(function(e){e(prompt(""))})}),"open-input-string":z(function(e){Qn("open-input-string",e,"string");return In(e)},"(open-input-string string)\n\n Function create new string port as input that can be used to\n read S-exressions from this port using `read` function."),"output-port?":z(function(e){return e instanceof Fn},"(output-port? arg)\n\n Function return true if argument is output port."),"input-port?":z(function(e){return e instanceof En},"(input-port? arg)\n\n Function return true if argument is input port."),"open-output-string":z(function(){return An(this.get("repr"))},"(open-output-string)\n\n Function create new output port that can used to write string into\n and after finish get the whole string using `get-output-string`"),"get-output-string":z(function(e){Qn("get-output-string",e,"output-string-port");return e.getString()},"(get-output-string port)\n\n Function get full string from string port. If nothing was wrote\n to given port it will return empty string."),"eof-object?":z(function(e){return e===Ln},"(eof-object? arg)\n\n Function check if value is eof object, returned from input string\n port when there are no more data to read."),"peek-char":z(function(e){Qn("peek-char",e,["input-port","input-string-port"]);return e.peekChar()},"(peek-char port)\n\n Function get character from string port or EOF object if no more\n data in string port."),read:z(function n(e){var t=this;if(typeof e==="string"){return $(D(e))[0]}if(e instanceof In){var r=e.read();if(r===Ln){return Ln}return $(r)[0]}var i;if(e instanceof En){i=e}else{i=this.get("stdin")}return i.read().then(function(e){return n.call(t,e)})},"(read [string])\n\n Function if used with string will parse the string and return\n list structure of LIPS code. If called without an argument it\n will read string from standard input (using browser prompt or\n user defined way) and call itself with that string (parse is)\n function can be used together with eval to evaluate code from\n string"),pprint:z(function(e){if(e instanceof me){e=new st.Formatter(e.toString(true))["break"]().format();this.get("stdout").write.call(this,e)}else{this.get("display").call(this,e)}},"(pprint expression)\n\n Pretty print list expression, if called with non-pair it just call\n print function with passed argument."),print:z(function(){var n=this;for(var e=arguments.length,t=new Array(e),r=0;r1?t-1:0),i=1;ir.length){throw new Error("Not enough arguments")}var u=0;var c=this.get("repr");n=n.replace(a,function(e){var n=e[1];if(n==="~"){return"~"}else if(n==="%"){return"\n"}else{var t=r[u++];if(n==="a"){return c(t)}else{return c(t,true)}}});o=n.match(/~([\S])/);if(o){throw new Error("format: Unrecognized escape seqence ".concat(o[1]))}return n},"(format string n1 n2 ...)\n\n Function accepts string template and replacing any escape sequences\n by arguments:\n\n * ~a value as if printed with display\n * ~s value as if printed with write\n * ~% newline character\n * ~~ literal tilde '~' is inserted\n\n if there missing arguments or other escape character it throw exception."),display:z(function(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:null;if(n===null){n=this.get("stdout")}n.write.call(this,this.get("repr")(e))},"(display arg [port])\n\n Function send string to standard output or provied port."),error:z(function(){for(var e=arguments.length,n=new Array(e),t=0;t1&&arguments[1]!==x?arguments[1]:{},t=e.dynamic_scope,r=e.error;if(t){t=this}var i=tt(n.cdr.car,{env:this,dynamic_scope:t,error:r});i=Wn(i);var a;function o(n,t){if(Ne(n)){return n.then(function(e){return o(e,t)})}if(Ne(t)){return t.then(function(e){return o(n,e)})}s[n]=t;return t}if(n.car instanceof me&&he.is(n.car.car,".")){var u=n.car.cdr.car;var c=n.car.cdr.cdr.car;var s=tt(u,{env:this,dynamic_scope:t,error:r});var f=tt(c,{env:this,dynamic_scope:t,error:r});return o(f,i)}if(!(n.car instanceof he)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}a=this.ref(n.car.name);if(!a){a=this}return Y(i,function(e){a.set(n.car,e)})}),"(set! name value)\n\n Macro that can be used to set the value of the variable (mutate)\n it search the scope chain until it finds first non emtpy slot and set it."),"set-car!":z(function(e,n){Qn("set-car!",e,"pair");e.car=n},"(set-car! obj value)\n\n Function that set car (head) of the list/pair to specified value.\n It can destroy the list. Old value is lost."),"set-cdr!":z(function(e,n){Qn("set-cdr!",e,"pair");e.cdr=n},"(set-cdr! obj value)\n\n Function that set cdr (tail) of the list/pair to specified value.\n It can destroy the list. Old value is lost."),"empty?":z(function(e){return typeof e==="undefined"||e===de},"(empty? object)\n\n Function return true if value is undfined empty list."),assoc:z(function(e,n){if(e instanceof me&&!(n instanceof me)){throw new Error("First argument to assoc ned to be a key")}Qn("assoc",n,"pair");var t=n;while(true){if(!(t instanceof me)||this.get("empty?")(t)){break}var r=t.car.car;if(xe(r,e)){return t.car}else if(!t.haveCycles("cdr")){t=t.cdr}}return de},"(assoc key alist)\n\n Function search Alist (list of pairs) until it find the one that\n have head set equal to key, and return found pair."),gensym:z(Bn,"(gensym)\n\n Function generate unique symbol, to use with macros as meta name."),load:z(function(e){Qn("load",e,"string");var n=this;if(n.name==="__frame__"){n=n.parent}var i;if(n===Dn){i=n}else{i=this.get("**interaction-environment**")}if(typeof this.get("global",{throwError:false})!=="undefined"){return new Promise(function(t,r){require("fs").readFile(e.valueOf(),function(e,n){if(e){r(e)}else{rt(n.toString(),i).then(function(){t()})}})})}return p.fetch(e).then(function(e){return e.text()}).then(function(e){return rt(e,i)}).then(function(){})},"(load filename)\n\n Function fetch the file and evaluate its content as LIPS code."),while:z(new Se("while",function(r,e){var i=e.dynamic_scope,a=e.error;var o=this;var u=new me(new he("begin"),r.cdr);var c;if(i){i=o}return function n(){var e=tt(r.car,{env:o,dynamic_scope:i,error:a});function t(e){if(e&&!Le(e)){c=tt(u,{env:o,dynamic_scope:i,error:a});if(Ne(c)){return c.then(function(e){c=e;return n()})}else{return n()}}else{return c}}return Y(e,t)}()}),"(while cond . body)\n\n Macro that create a loop, it exectue body untill cond expression is false"),if:z(new Se("if",function(t,e){var r=e.dynamic_scope,i=e.error;if(r){r=this}var a=this;var n=function e(n){if(n){return tt(t.cdr.car,{env:a,dynamic_scope:r,error:i})}else{return tt(t.cdr.cdr.car,{env:a,dynamic_scope:r,error:i})}};var o=tt(t.car,{env:a,dynamic_scope:r,error:i});return Y(o,n)}),"(if cond true-expr false-expr)\n\n Macro evaluate condition expression and if the value is true, it\n evaluate and return true expression if not it evaluate and return\n false expression"),"let-env":new Se("let-env",function(n){var e=arguments.length>1&&arguments[1]!==x?arguments[1]:{};var t=e.dynamic_scope,r=e.error;Qn("let-env",n,"pair");var i=tt(n.car,{env:this,dynamic_scope:t,error:r});return Y(i,function(e){if(!(e instanceof Cn)){throw new Error("let-env: First argument need to be "+"environment")}return tt(me(he("begin"),n.cdr),{env:e,dynamic_scope:t,error:r})})},"(let-env env . body)\n\n Special macro that evaluate body in context of given environment\n object."),letrec:z(Ye(Symbol["for"]("letrec")),"(letrec ((a value-a) (b value-b)) body)\n\n Macro that creates new environment, then evaluate and assign values to\n names and then evaluate the body in context of that environment.\n Values are evaluated sequentialy and next value can access to\n previous values/names."),"let*":z(Ye(Symbol["for"]("let*")),"(let* ((a value-a) (b value-b)) body)\n\n Macro similar to `let` but next argument get environment\n from previous let variable, so they you can define one variable,\n and use in next argument."),let:z(Ye(Symbol["for"]("let")),"(let ((a value-a) (b value-b)) body)\n\n Macro that creates new environment, then evaluate and assign values to\n names and then evaluate the body in context of that environment.\n Values are evaluated sequentialy but you can't access\n previous values/names when next are evaluated. You can only get them\n from body of let expression."),"begin*":z(Ge("begin*",function(e){return e.pop()}),"(begin* . expr)\n\n This macro is parallel version of begin. It evaluate each expression and\n if it's a promise it will evaluate it in parallel and return value\n of last expression."),begin:z(new Se("begin",function(e,n){var r=Object.assign({},n);var i=this.get("list->array")(e);if(r.dynamic_scope){r.dynamic_scope=this}r.env=this;var a;return function n(){if(i.length){var e=i.shift();var t=tt(e,r);return Y(t,function(e){a=e;return n()})}else{return a}}()}),"(begin . args)\n\n Macro runs list of expression and return valuate of the list one.\n It can be used in place where you can only have single exression,\n like if expression."),ignore:new Se("ignore",function(e,n){var t=n.dynamic_scope,r=n.error;var i={env:this,error:r};if(t){i.dynamic_scope=this}tt(new me(new he("begin"),e),i)},"(ignore expression)\n\n Macro that will evaluate expression and swallow any promises that may\n be created. It wil run and ignore any value that may be returned by\n expression. The code should have side effects and/or when it's promise\n it should resolve to undefined."),define:z(Se.defmacro("define",function(n,e){var t=this;if(n.car instanceof me&&n.car.car instanceof he){var r=new me(new he("define"),new me(n.car.car,new me(new me(new he("lambda"),new me(n.car.cdr,n.cdr)))));return r}else if(e.macro_expand){return}if(e.dynamic_scope){e.dynamic_scope=this}e.env=t;var i=n.cdr.car;if(i instanceof me){i=tt(i,e)}else if(i instanceof he){i=t.get(i)}Qn("define",n.car,"symbol");return Y(i,function(e){if(t.name===Ee.merge_env){t.parent.set(n.car,e)}else{t.set(n.car,e)}})}),"(define name expression)\n (define (function-name . args) body)\n\n Macro for defining values. It can be used to define variables,\n or function. If first argument is list it will create function\n with name beeing first element of the list. The macro evalute\n code `(define function (lambda args body))`"),"set-obj!":z(function(e,n,t){var r=gt(e);if(Le(e)||r!=="object"&&r!=="function"){var i=Vn("set-obj!",Kn(e),["object","function"]);throw new Error(i)}e=Re(e);n=n.valueOf();if(typeof t==="undefined"){delete e[n]}else{e[n]=t.valueOf()}},"(set-obj! obj key value)\n\n Function set property of JavaScript object"),"null-environment":z(function(){return Dn.inherit("null")},"(null-environment)\n\n Function return new base environment with std lib."),values:z(function(){for(var e=arguments.length,n=new Array(e),t=0;t1&&arguments[1]!==x?arguments[1]:{},p=e.dynamic_scope,h=e.error;var v=this;var d;if(l.cdr instanceof me&&un.isString(l.cdr.car)&&l.cdr.cdr!==de){d=l.cdr.car.valueOf()}function m(){var e;if(p){if(!(this instanceof Cn)){e=v}else{e=this}}else{e=v}e=e.inherit("lambda");var n=l.car;var t=0;var r;if(typeof this!=="undefined"){e.set("this",this)}for(var i=arguments.length,a=new Array(i),o=0;o2&&arguments[2]!==x?arguments[2]:u;if(e instanceof me){var r=e.car;var i=e.cdr;if(t(r)){r=n(r)}if(t(i)){i=n(i)}if(Ne(r)||Ne(i)){return Promise.all([r,i]).then(function(e){var n=yt(e,2),t=n[0],r=n[1];return new me(t,r)})}else{return new me(r,i)}}return e}function s(e,n){if(e instanceof me){if(n!==de){e.append(n)}}else{e=new me(e,n)}return e}function f(r,e,n){if(er){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(t.cdr instanceof me){if(t.cdr.cdr!==de){if(t.cdr.car instanceof me){return Y(p(t.cdr.cdr,n,r),function(e){var n=tt(t.cdr.car,{env:o,dynamic_scope:i,error:a});return new me(n,e)})}else{return t.cdr}}else{return tt(t.cdr.car,{env:o,dynamic_scope:i,error:a})}}else{return t.cdr}}return c(t,function(e){return p(e,n,r)})}return t}function t(e){if(e instanceof me){delete e.data;if(!e.haveCycles("car")){t(e.car)}if(!e.haveCycles("cdr")){t(e.cdr)}}}var r=p(e.car,0,1);return Y(r,function(e){t(e);return Tn(e)})},"(quasiquote list ,value ,@value)\n\n Similar macro to `quote` but inside it you can use special\n expressions unquote abbreviated to , that will evaluate expresion inside\n and return its value or unquote-splicing abbreviated to ,@ that will\n evaluate expression but return value without parenthesis (it will join)\n the list with its value. Best used with macros but it can be used outside"),clone:z(function(e){Qn("clone",e,"pair");return e.clone()},"(clone list)\n\n Function return clone of the list."),append:z(function(e,n){Qn("append",e,["nil","pair"]);if(e instanceof me){e=e.clone()}return this.get("append!").call(this,e,n)},"(append list item)\n\n Function will create new list with value appended to the end. It return\n New list."),"append!":z(function(e,n){Qn("append!",e,["pair","nil"]);if(!this.get("list?")(e)){throw new Error("append!: Invalid argument, value is not a list")}if(Le(n)){return e}if(e===de){if(n===de){return de}return n}return e.append(n)},"(append! name expression)\n\n Destructive version of append, it modify the list in place. It return\n original list."),reverse:z(function(e){Qn("reverse",e,["array","pair"]);if(e instanceof me){var n=this.get("list->array")(e).reverse();return this.get("array->list")(n)}else if(!(e instanceof Array)){throw new Error(Vn("reverse",Kn(e),"array or pair"))}else{return e.reverse()}},"(reverse list)\n\n Function will reverse the list or array. If value is not a list\n or array it will throw exception."),nth:z(function(e,n){Qn("nth",e,"number");Qn("nth",n,["array","pair"]);if(n instanceof me){var t=n;var r=0;while(rarray")(n).join(e)},"(join separator list)\n\n Function return string by joining elements of the list"),split:z(function(e,n){Qn("split",e,["regex","string"]);Qn("split",n,"string");return this.get("array->list")(n.split(e))},"(split separator string)\n\n Function create list by splitting string by separatar that can\n be a string or regular expression."),replace:z(function(e,n,t){Qn("replace",e,["regex","string"]);Qn("replace",n,["string","function"]);Qn("replace",t,"string");return t.replace(e,n)},"(replace pattern replacement string)\n\n Function change pattern to replacement inside string. Pattern can be string\n or regex and replacement can be function or string."),match:z(function(e,n){Qn("match",e,["regex","string"]);Qn("match",n,"string");var t=n.match(e);return t?this.get("array->list")(t):de},"(match pattern string)\n\n function return match object from JavaScript as list."),search:z(function(e,n){Qn("search",e,["regex","string"]);Qn("search",n,"string");return n.search(e)},"(search pattern string)\n\n Function return first found index of the pattern inside a string"),repr:z(function e(n,t){return ge(n,t)},"(repr obj)\n\n Function return string LIPS representation of an object as string."),env:z(function(e){e=e||this;var n=Object.keys(e.env);var t;if(n.length){t=me.fromArray(n)}else{t=de}if(e.parent!==x){return this.get("env").call(this,e.parent).append(t)}return t},"(env obj)\n\n Function return list values (functions and variables) inside environment."),new:z(function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r2&&arguments[2]!==x?arguments[2]:H.LITERAL;Qn("remove-special!",e,"string",1);Qn("remove-special!",n,"symbol",2);st.specials.append(e,n,t)},"(add-special! symbol name)\n\n Add special symbol to the list of transforming operators by the parser.\n e.g.: `(add-special! '#)` will allow to use `#(1 2 3)` and it will be\n transformed into (# (1 2 3)) so you can write # macro that will process\n the list. It's main purpose to to allow to use `define-symbol-macro`"),get:an,".":an,unbind:z(Re,"(unbind fn)\n\n Function remove bidning from function so you can get props from it."),type:z(Kn,"(type object)\n\n Function return type of an object as string."),debugger:z(function(){debugger},"(debugger)\n\n Function stop JavaScript code in debugger."),instanceof:z(function(e,n){return n instanceof Re(e)},"(instanceof type obj)\n\n Function check of object is instance of object."),"macro?":z(function(e){return e instanceof Se},"(macro? expression)\n\n Function check if value is a macro."),"function?":z(function(e){return typeof e==="function"},"(function? expression)\n\n Function check if value is a function."),"real?":z(function(e){if(Kn(e)!=="number"){return false}if(e instanceof vn){return e.isFloat()}return vn.isFloat(e)},"(real? number)\n\n Function check if value is real number."),"number?":z(vn.isNumber,"(number? expression)\n\n Function check if value is a number"),"string?":z(function(e){return un.isString(e)},"(string? expression)\n\n Function check if value is a string."),"pair?":z(function(e){return e instanceof me},"(pair? expression)\n\n Function check if value is a pair or list structure."),"regex?":z(function(e){return e instanceof RegExp},"(regex? expression)\n\n Function check if value is regular expression."),"null?":z(function(e){return Le(e)},"(null? expression)\n\n Function check if value is nulish."),"boolean?":z(function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Function check if value is boolean."),"symbol?":z(function(e){return e instanceof he},"(symbol? expression)\n\n Function check if value is LIPS symbol"),"array?":z(function(e){return e instanceof Array},"(array? expression)\n\n Function check if value is an arrray."),"object?":z(function(e){return e!==de&&e!==null&&!(e instanceof vn)&>(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Function check if value is an object."),flatten:z(function(e){Qn("flatten",e,"pair");return e.flatten()},"(flatten list)\n\n Return shallow list from tree structure (pairs)."),"array->list":z(function(e){Qn("array->list",e,"array");return me.fromArray(e)},"(array->list array)\n\n Function convert JavaScript array to LIPS list."),"tree->array":z(ye("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":z(ye("list->array"),"(list->array list)\n\n Function convert LIPS list into JavaScript array."),apply:z(function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;rarray")(i));return e.apply(void 0,vt(t))},"(apply fn list)\n\n Function that call function with list of arguments."),length:z(function(e){if(!e){return vn(0)}if(e instanceof me){return vn(e.length())}if("length"in e){return vn(e.length)}},"(length expression)\n\n Function return length of the object, the object can be list\n or any object that have length property."),"string->number":z(function(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:10;Qn("string->number",e,"string",1);Qn("string->number",n,"number",2);if(e.match(b)){return k(e)}else if(e.match(g)){return j(e)}else if(e.match(w)){return S(e)}else if(e.match(c)){return mn(parseFloat(e))}throw new Error("string->number: Invalid Syntax")},"(string->number number [radix])\n\n Function convert string to number."),try:z(new Se("try",function(a,e){var o=this;var u=e.dynamic_scope,c=e.error;return new Promise(function(i){var e={env:o,error:function e(n){if(n instanceof qn){throw new qn(n.message)}var t=o.inherit("try");t.set(a.cdr.car.cdr.car.car,n);var r={env:t,error:c};if(u){r.dynamic_scope=o}Y(tt(new me(new he("begin"),a.cdr.car.cdr.cdr),r),function(e){i(e)});throw new qn(n.message)}};if(u){e.dynamic_scope=o}var n=tt(a.car,e);if(Ne(n)){n["catch"](e.error).then(i)}else{i(n)}})}),"(try expr (catch (e) code)"),throw:z(function(e){throw new Error(e)},"(throw string)\n\n Throw new expection."),find:z(function n(t,r){Qn("find",t,["regex","function"]);Qn("find",r,"pair");if(Le(r)){return de}var e=G("find",t);return Y(e(r.car),function(e){if(e&&e!==de){return r.car}return n(t,r.cdr)})},"(find fn list)\n (find regex list)\n\n Higher order Function find first value for which function return true.\n If called with regex it will create matcher function."),"for-each":z(function(e){var n;Qn("for-each",e,"function");for(var t=arguments.length,r=new Array(t>1?t-1:0),i=1;i1?n-1:0),a=1;a3?r-3:0),a=3;a3?i-3:0),o=3;oarray")(n);var a=[];var o=G("filter",e);return function n(t){function e(e){if(e&&e!==de){a.push(r)}return n(++t)}if(t===i.length){return me.fromArray(a)}var r=i[t];return Y(o(r,t),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher order function that call `fn` for each element of the list\n and return list for only those elements for which funtion return\n true value. If called with regex it will create matcher function."),range:z(function(e){Qn("range",e,"number");if(e instanceof vn){e=e.valueOf()}return me.fromArray(new Array(e).fill(0).map(function(e,n){return vn(n)}))},"(range n)\n\n Function return list of n numbers from 0 to n - 1"),compose:z(Qe,"(compose . fns)\n\n Higher order function and create new function that apply all functions\n From right to left and return it's value. Reverse of compose.\n e.g.:\n ((compose (curry + 2) (curry * 3)) 3)\n 11\n "),pipe:z(Ve,"(pipe . fns)\n\n Higher order function and create new function that apply all functions\n From left to right and return it's value. Reverse of compose.\n e.g.:\n ((pipe (curry + 2) (curry * 3)) 3)\n 15"),curry:z(nn,"(curry fn . args)\n\n Higher order function that create curried version of the function.\n The result function will have parially applied arguments and it\n will keep returning functions until all arguments are added\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))"),gdc:z(function e(){for(var n=arguments.length,t=new Array(n),r=0;ra?u%=a:a%=u}u+=a}return vn(u)},"(gdc n1 n2 ...)\n\n Function return the greatest common divisor of their arguments."),lcm:z(function(){var e=arguments.length,n=we(arguments.length<=0?x:arguments[0]);for(var t=1;tr?n%=r:r%=n}n=we(i*(t<0||arguments.length<=t?x:arguments[t]))/(n+r)}return vn(n)},"(lcm n1 n2 ...)\n\n Function return the least common multiple of their arguments."),"odd?":z(We(function(e){return vn(e).isOdd()}),"(odd? number)\n\n Function check if number os odd."),"even?":z(We(function(e){return vn(e).isEven()}),"(even? number)\n\n Function check if number is even."),"*":z(en(function(e,n){return vn(e).mul(n)},vn(1)),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":z(en(function(e,n){return vn(e).add(n)},vn(0)),"(+ . numbers)\n\n Sum all numbers passed as arguments. If single value is passed it will\n return that value."),"-":z(function(){for(var e=arguments.length,n=new Array(e),t=0;t":z(function(){for(var e=arguments.length,n=new Array(e),t=0;t x1 x2 x3 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically increasing"),"<":z(function(){for(var e=arguments.length,n=new Array(e),t=0;t=":z(function(){for(var e=arguments.length,n=new Array(e),t=0;t= x1 x2 x3 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically nondecreasing"),"eq?":z(xe,"(eq? a b)\n\n Function compare two values if they are identical."),or:z(new Se("or",function(e,n){var i=n.dynamic_scope,a=n.error;var o=this.get("list->array")(e);var u=this;if(i){i=u}var c;return function n(){function e(e){c=e;if(c){return c}else{return n()}}var t=o.shift();if(typeof t==="undefined"){if(c){return c}else{return false}}else{var r=tt(t,{env:u,dynamic_scope:i,error:a});return Y(r,e)}}()}),"(or . expressions)\n\n Macro execute the values one by one and return the one that is truthy value.\n If there are no expression that evaluate to true it return false."),and:z(new Se("and",function(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:{},i=n.dynamic_scope,a=n.error;var o=this.get("list->array")(e);var u=this;if(i){i=u}if(!o.length){return true}var c;return function n(){function e(e){c=e;if(!c){return false}else{return n()}}var t=o.shift();if(typeof t==="undefined"){if(c){return c}else{return false}}else{var r=tt(t,{env:u,dynamic_scope:i,error:a});return Y(r,e)}}()}),"(and . expressions)\n\n Macro evalute each expression in sequence if any value return false it will\n return false. If each value return true it will return the last value.\n If it's called without arguments it will return true."),"|":z(function(e,n){return vn(e).or(n)},"(& a b)\n\n Function calculate or bit operation."),"&":z(function(e,n){return vn(e).and(n)},"(& a b)\n\n Function calculate and bit operation."),"~":z(function(e){return vn(e).neg()},"(~ number)\n\n Function negate the value."),">>":z(function(e,n){return vn(e).shr(n)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":z(function(e,n){return vn(e).shl(n)},"(<< a b)\n\n Function left shit the value a by value b."),not:z(function(e){if(Le(e)){return true}return!e},"(not object)\n\n Function return negation of the argument."),"->":z(function(e,n){for(var t=arguments.length,r=new Array(t>2?t-2:0),i=2;i obj name . args)\n\n Function get function from object and call it with arguments.")},x,"global");var Hn=Dn.inherit("user-env");Dn.set("**interaction-environment**",Hn);(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(n){var t=e[n]?e[n]:n;Dn.set(t,z(function(e){Qn(t,e,"number");if(e instanceof vn){return e[n]()}},"(".concat(t," number)\n\n Function calculate ").concat(t," of a number.")))})})();function Jn(e){if(e.length===1){return e[0]}else{var n=[];var t=Jn(e.slice(1));for(var r=0;r3&&arguments[3]!==x?arguments[3]:null;var i=e?" in function `".concat(e,"`"):"";if(r!==null){i+=" argument ".concat(r)}if(t instanceof Array){var a=t[t.length-1];t=t.slice(0,-1).join(", ")+" or "+a}return"Expecting ".concat(t," got ").concat(n).concat(i)}function Qn(e,n,t){var r=arguments.length>3&&arguments[3]!==x?arguments[3]:null;var i=Kn(n).toLowerCase();var a=false;if(t instanceof Array){t=t.map(function(e){return e.valueOf().toLowerCase()});if(t.includes(i)){a=true}}else{t=t.valueOf().toLowerCase()}if(!a&&i!==t){throw new Error(Vn(e,i,t,r))}}function Xn(e){var n=gt(e);return["string","function"].includes(n)||e instanceof he||e instanceof vn||e instanceof RegExp}function Kn(e){var n={pair:me,symbol:he,character:on,values:Mn,macro:Se,string:un,array:Array,"native-symbol":Symbol};if(Number.isNaN(e)){return"NaN"}if(e===de){return"nil"}if(e===null){return"null"}if(e instanceof Ee){return"syntax"}for(var t=0,r=Object.entries(n);t1&&arguments[1]!==x?arguments[1]:{},i=e.env,a=e.dynamic_scope,t=e.error,o=t===void 0?function(){}:t;try{if(a===true){i=a=i||Dn}else if(i===true){i=a=Dn}else{i=i||Dn}var r={env:i,dynamic_scope:a,error:o};var u;if(Le(n)){return n}if(n instanceof he){return i.get(n)}var c=n.car;var s=n.cdr;if(c instanceof me){u=Wn(tt(c,r));if(Ne(u)){return u.then(function(e){return tt(new me(e,n.cdr),r)})}else if(typeof u!=="function"){throw new Error(Kn(u)+" "+i.get("repr")(u)+" is not a function while evaluating "+n.toString())}}if(c instanceof he){u=i.get(c);if(u instanceof Ee){return et(u,n,r)}else if(u instanceof Se){return nt(u,s,r)}else if(typeof u!=="function"){if(u){var f="".concat(Kn(u)," `").concat(u,"' is not a function");throw new Error(f)}throw new Error("Unknown function `".concat(c.name,"'"))}}else if(typeof c==="function"){u=c}if(typeof u==="function"){var l=Zn(s,r);return Y(l,function(e){if(Te(u)){e=e.map(Pe)}if(u.__lambda__){u=Re(u)}var n=e.slice();var t=(a||i).newFrame(u,n);var r=Wn(u.apply(t,e));return Y(r,function(e){if(e instanceof me){e.markCycles();return Tn(e)}if(typeof e==="number"){return vn(e)}if(typeof e==="string"){return un(e)}return e},o)})}else if(n instanceof he){u=i.get(n);if(u==="undefined"){throw new Error("Unbound variable `"+n.name+"'")}return u}else if(n instanceof me){u=c&&c.toString();throw new Error("".concat(Kn(c)," ").concat(u," is not a function"))}else{return n}}catch(e){o&&o.call(i,e,n)}}function rt(e,n,t){return it.apply(this,arguments)}function it(){it=pt(lt.mark(function e(t,r,i){var a,o,u,c;return lt.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(i===true){r=i=r||Hn}else if(r===true){r=i=Hn}else{r=r||Hn}a=$(t);o=[];case 3:u=a.shift();if(u){n.next=9;break}return n.abrupt("return",o);case 9:n.next=11;return tt(u,{env:r,dynamic_scope:i,error:function e(n,t){if(t){if(!(n.code instanceof Array)){n.code=[]}n.code.push(t.toString(true))}throw n}});case 11:c=n.sent;o.push(c);case 13:n.next=3;break;case 15:case"end":return n.stop()}}},e)}));return it.apply(this,arguments)}function at(e){var n={"[":"]","(":")"};var t=typeof e==="string"?D(e):e;var r=Object.keys(n);var i=Object.values(n).concat(r);t=t.filter(function(e){return i.includes(e)});var a=new M;var o=bt(t),u;try{for(o.s();!(u=o.n()).done;){var c=u.value;if(r.includes(c)){a.push(c)}else if(!a.is_empty()){var s=a.top();var f=n[s];if(c===f){a.pop()}else{throw new Error("Syntax error: missing closing ".concat(f))}}else{throw new Error("Syntax error: not matched closing ".concat(c))}}}catch(e){o.e(e)}finally{o.f()}return a.is_empty()}me.unDry=function(e){return new me(e.car,e.cdr)};me.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};ve.prototype.toDry=function(){return{value:null}};ve.unDry=function(){return de};he.prototype.toDry=function(){return{value:{name:this.name}}};he.unDry=function(e){return new he(e.name)};function ot(e){console.error(e.message||e);if(e.code){console.error(e.code.map(function(e,n){return"[".concat(n+1,"]: ").concat(e)}))}}function ut(){var o=["text/x-lips","text/x-scheme"];if(!window.document){return Promise.resolve()}else{return new Promise(function(i){var a=Array.from(document.querySelectorAll("script"));return function n(){var e=a.shift();if(!e){i()}else{var t=e.getAttribute("type");if(o.includes(t)){var r=e.getAttribute("src");if(r){return p.fetch(r).then(function(e){return e.text()}).then(rt).then(n)["catch"](function(e){ot(e);n()})}else{return rt(e.innerHTML).then(n)["catch"](function(e){ot(e);n()})}}else if(t&&t.match(/lips|lisp/)){console.warn("Expecting "+o.join(" or ")+" found "+t)}return n()}}()})}}if(typeof window!=="undefined"){e(window,ut)}var ct=function(){var e=un("Sat, 16 May 2020 21:13:32 +0000").valueOf();var n=e==="{{"+"DATE}}"?new Date:new Date(e);var t=function e(n){return n.toString().padStart(2,"0")};var r=n.getFullYear();var i=[r,t(n.getMonth()+1),t(n.getDate())].join("-");var a="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Scheme Interpreter DEV (".concat(i,")\nCopyright (c) 2018-").concat(r," Jakub T. Jankiewicz \n\nType (env) to see environment with functions macros and variables.\nYou can also use (help name) to display help for specic function or macro.\n").replace(/^.*\n/,"");return a}();Z.__className="ahead";ee.__className="pattern";W.__className="formatter";Se.__className="macro";Ee.__className="syntax";Cn.__className="environment";En.__className="input-port";Fn.__className="output-port";An.__className="output-string-port";In.__className="input-string-port";var st={version:"DEV",banner:ct,date:"Sat, 16 May 2020 21:13:32 +0000",exec:rt,parse:$,tokenize:D,evaluate:tt,Environment:Cn,env:Hn,Interpreter:Pn,balanced_parenthesis:at,balancedParenthesis:at,Macro:Se,Syntax:Ee,Pair:me,quote:Tn,InputPort:En,OutputPort:Fn,InputStringPort:In,OutputStringPort:An,Formatter:W,specials:H,nil:de,LSymbol:he,LNumber:vn,LFloat:mn,LComplex:dn,LRational:_n,LBigInteger:xn,LCharacter:on,LString:un,rationalize:bn};Dn.set("lips",st);return st})})(); \ No newline at end of file diff --git a/lib/R5RS.scm b/lib/R5RS.scm index 048783b7..501c50eb 100644 --- a/lib/R5RS.scm +++ b/lib/R5RS.scm @@ -306,8 +306,8 @@ (if (complex? n) ;; make-object (&) will use valueOf so it will be float even if it was rational (lips.LComplex &(:im (. n 'im) :re (. n 're))) - (if (rational? n) - (lips.LFloat (--> n (valueOf))) + (if (or (rational? n) (integer? n)) + (lips.LFloat (--> n (valueOf)) true) n))) ;; ----------------------------------------------------------------------------- diff --git a/src/lips.js b/src/lips.js index 226cb460..3b83d715 100644 --- a/src/lips.js +++ b/src/lips.js @@ -150,10 +150,37 @@ }); }; } - // parse_argument based on function from jQuery Terminal + // functions generate regexes to match number rational, integer, complex, complex+ratioanl + function num_mnemicic_re(mnemonic) { + return mnemonic ? `(?:#${mnemonic}(?:#[ie])?|#[ie]#${mnemonic})` : '(?:#[ie])?'; + } + function gen_rational_re(mnemonic, range) { + return `${num_mnemicic_re(mnemonic)}[+-]?${range}+/${range}+`; + } + // TODO: float complex + function gen_complex_re(mnemonic, range) { + return `${num_mnemicic_re(mnemonic)}(?:(?:[+-]?${range}+)?[+-]${range}+i|(?:[+-]?${range}+/${range}+)?[+-]${range}+/${range}+i)`; + } + function gen_integer_re(mnemonic, range) { + return `${num_mnemicic_re(mnemonic)}[+-]?${range}+`; + } var re_re = /^\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimy]*)$/; - var int_re = /^(?:#x[-+]?[0-9a-f]+|#o[-+]?[0-7]+|#b[-+]?[01]+|[-+]?[0-9]+)$/i; - var float_re = /^([-+]?([0-9]+([eE][-+]?[0-9]+)|(\.[0-9]+|[0-9]+\.[0-9]+)([eE][-+]?[0-9]+)?)|[0-9]+\.)$/; + var float_stre = '(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)'; + var complex_float_stre = `(?:#[ie])?(?:${float_stre})?${float_stre}i`; + var float_re = new RegExp(`^(#[ie])?${float_stre}$`); + function make_complex_match_re(mnemonic, range) { + // complex need special treatment of 10e+1i when it's hex or decimal + var neg = mnemonic === 'x' ? '(?![+])' : '(?!\\.)'; + var fl = mnemonic === '' ? float_stre + '|' : ''; + return new RegExp(`((?:${fl}[+-]?${range}+/${range}+|[+-]?${range}+${neg})?)(${fl}[+-]${range}+/${range}+|[+-]${range}+)i`); + } + var complex_list_re = (function() { + var result = {}; + [[10, '', '[0-9]'], [16, 'x', '[0-9a-fA-F]'], [8, 'o', '[0-7]'], [2, 'b', '[01]']].forEach(([radix, mnemonic, range]) => { + result[radix] = make_complex_match_re(mnemonic, range); + }); + return result; + })(); var characters = { 'alarm': '\x07', 'backspace': '\x08', @@ -168,37 +195,75 @@ var character_symbols = Object.keys(characters).join('|'); var char_re = new RegExp(`^#\\\\(?:${character_symbols}|[\\s\\S])$`, 'i'); // complex with (int) (float) (rational) - var complex_re = /^((?:(?:[-+]?[0-9]+(?:[eE][-+]?[0-9]+)?)|(?:[-+]?[0-9]+\/[0-9]+|(?:(?:\.[0-9]+|[0-9]+\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\.))(?=[+-]|i))?((?:[-+]?[0-9]+(?:[eE][-+]?[0-9]+)?)|(?:[-+]?(?:[0-9]+\/[0-9]+|(?:\.[0-9]+|[0-9]+\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\.))i|-i$/; - var rational_re = /^[-+]?[0-9]+\/[0-9]+$/; + function make_num_stre(fn) { + var ranges = [ + ['o', '[0-7]'], + ['x', '[0-9a-fA-F]'], + ['b', '[01]'], + ['', '[0-9]'] + ]; + // float exception that don't accept mnemonics + var result = ranges.map(([m, range]) => fn(m, range)).join('|'); + if (fn === gen_complex_re) { + result = complex_float_stre + '|' + result; + } + return result; + } + function make_type_re(fn) { + return new RegExp('^(?:' + make_num_stre(fn) + ')$'); + } + var complex_re = make_type_re(gen_complex_re); + var rational_re = make_type_re(gen_rational_re); + var int_re = make_type_re(gen_integer_re); /* eslint-enable */ + function num_pre_parse(arg) { + var parts = arg.match(/((?:#[xobie]){0,2})(.*)/i); + var options = {}; + if (parts[1]) { + var type = parts[1].replace(/#/g, '').split(''); + var radix; + if (type.includes('x')) { + options.radix = 16; + } else if (type.includes('o')) { + options.radix = 8; + } else if (type.includes('b')) { + options.radix = 2; + } else { + options.radix = 10; + } + if (type.includes('i')) { + options.inexact = true; + } + if (type.includes('e')) { + options.exact = true; + } + } else { + options.radix = 10; + } + options.number = parts[2]; + return options; + } // ---------------------------------------------------------------------- - function parse_rational(arg) { - var parts = arg.split('/'); - return LRational({ - num: parseInt(parts[0], 10), - denom: parseInt(parts[1], 10) + function parse_rational(arg, radix = null) { + var parse = num_pre_parse(arg); + var parts = parse.number.split('/'); + var num = LRational({ + num: LNumber([parts[0], parse.radix]), + denom: LNumber([parts[1], parse.radix]) }); + if (parse.inexact) { + return num.valueOf(); + } else { + return num; + } } // ---------------------------------------------------------------------- function parse_integer(arg) { - var m = arg.match(/^(?:#([xbo]))?([+-]?[0-9a-f]+)$/i); - var radix; - if (m && m[1]) { - switch (m[1]) { - case 'x': - radix = 16; - break; - case 'o': - radix = 8; - break; - case 'b': - radix = 2; - break; - } - } else { - radix = 10; + var parse = num_pre_parse(arg); + if (parse.inexact) { + return LFloat(parseInt(parse.number, parse.radix), true); } - return LNumber([m[2], radix]); + return LNumber([parse.number, parse.radix]); } // ---------------------------------------------------------------------- function parse_character(arg) { @@ -222,18 +287,53 @@ if (arg === '-i') { return { im: -1, re: 0 }; } - var parts = arg.match(complex_re); + function parse_num(n) { + var value; + if (n.match(int_re)) { + value = LNumber([n, parse.radix]); + } else if (n.match(rational_re)) { + var parts = n.split('/'); + value = LRational({ + num: LNumber([parts[0], parse.radix]), + denom: LNumber([parts[1], parse.radix]) + }); + } else if (n.match(float_re)) { + var float = LFloat(parseFloat(n)); + if (parse.exact) { + return float.toRational(); + } + return float; + } + if (parse.inexact) { + return LFloat(value.valueOf(), true); + } + return value; + } + var parse = num_pre_parse(arg); + var parts = parse.number.match(complex_list_re[parse.radix.toString()]); var re, im; - if (parts.length === 2) { - im = parse_number(parts[1]); - re = 0; + im = parse_num(parts[2]); + if (parts[1]) { + re = parse_num(parts[1]); } else { - re = parts[1] ? parse_number(parts[1]) : 0; - im = parse_number(parts[2]); + if (im instanceof LFloat) { + re = LFloat(0, true); + } else { + re = LNumber(0); + } } return LComplex({ im, re }); } // ---------------------------------------------------------------------- + function parse_float(arg) { + var parse = num_pre_parse(arg); + var value = parseFloat(parse.number); + if (parse.exact || !parse.number.match(/\./) && !parse.inexact) { + return LNumber(value); + } + return LFloat(value, true); + } + // ---------------------------------------------------------------------- function parse_string(string) { // handle non JSON escapes and skip unicode escape \u (even partial) var re = /([^\\\n])(\\(?:\\{2})*)(?!u[0-9AF]{1,4})(.)/gi; @@ -266,7 +366,7 @@ } else if (arg.match(int_re)) { return parse_integer(arg); } else if (arg.match(float_re)) { - return LFloat(parseFloat(arg)); + return parse_float(arg); } else if (arg === 'nil') { return nil; } else if (arg === 'true') { @@ -287,13 +387,18 @@ /* eslint-disable */ var pre_parse_re = /("(?:\\[\S\s]|[^"])*"?|\/(?! )[^\n\/\\]*(?:\\[\S\s][^\n\/\\]*)*\/[gimy]*(?=\s|\[|\]|\(|\)|$)|;.*)/g; var string_re = /"(?:\\[\S\s]|[^"])*"?/g; - var number_parital = ''; + // generate regex for all number literals + var num_stre = complex_float_stre + '|' + [ + gen_complex_re, + gen_rational_re, + gen_integer_re + ].map(make_num_stre).join('|'); // ---------------------------------------------------------------------- function make_token_re() { var tokens = specials.names() .sort((a, b) => b.length - a.length || a.localeCompare(b)) .map(escape_regex).join('|'); - return new RegExp(`(#\\\\(?:${character_symbols}|[\\s\\S])|#f|#t|#[xbo][0-9a-f]+(?=[\\s()]|$)|[0-9]+/[0-9]+(?:[-+][0-9]+/[0-9]+i)?|\\[|\\]|\\(|\\)|;.*|\\|[^|]+\\||(?:(?:[-+]?(?:(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)[0-9]i)|\\n|\\.{2,}|(?!#:)(?:${tokens})|[^(\\s)[\\]]+)`, 'gim'); + return new RegExp(`(#\\\\(?:${character_symbols}|[\\s\\S])|#f|#t|${num_stre}(?=[\\n\\s()])|\\[|\\]|\\(|\\)|;.*|\\|[^|]+\\||(?:#[ei])?${float_stre}|\\n|\\.{2,}|(?!#:)(?:${tokens})|[^(\\s)[\\]]+)`, 'gim'); } /* eslint-enable */ // ---------------------------------------------------------------------- @@ -2883,16 +2988,26 @@ n = 0; } var value; + if (parsable) { + var [str, radix] = n; + if (str instanceof LString) { + str = str.valueOf(); + } + if (radix instanceof LNumber) { + radix = radix.valueOf(); + } + var sign = str.match(/^([+-])/); + var minus = false; + if (sign) { + str = str.replace(/^[+-]/, ''); + if (sign[1] === '-') { + minus = true; + } + } + } if (typeof BigInt !== 'undefined') { if (typeof n !== 'bigint') { if (parsable) { - let [str, radix] = n; - if (str instanceof LString) { - str = str.valueOf(); - } - if (radix instanceof LNumber) { - radix = radix.valueOf(); - } let prefix; // default number base (radix) supported by BigInt constructor switch (radix) { @@ -2921,6 +3036,9 @@ } else { value = BigInt(n); } + if (minus) { + value *= BigInt(-1); + } } else { value = n; } @@ -2931,13 +3049,6 @@ } return LBigInteger(new BN(n)); } else if (parsable) { - let [str, radix] = n; - if (str instanceof LString) { - str = str.valueOf(); - } - if (radix instanceof LNumber) { - radix = radix.valueOf(); - } this.value = parseInt(str, radix); } else { this.value = n; @@ -2972,7 +3083,7 @@ throw new Error('Invalid constructor call for LComplex'); } const [im, re] = LNumber.coerce(n.im, n.re); - if (im.cmp(0) === 0) { + if (im.cmp(0) === 0 && !force) { return re; } this.im = im; @@ -3044,7 +3155,8 @@ var im = n.im instanceof LNumber ? n.im : LNumber(n.im); var ret = fn(this.re, re, this.im, im); if ('im' in ret && 're' in ret) { - return LComplex(ret); + var x = LComplex(ret, true); + return x; } return ret; }; @@ -3238,7 +3350,7 @@ }; // ------------------------------------------------------------------------- LRational.prototype.cmp = function(n) { - return LNumber(this.valueOf()).cmp(n); + return LNumber(this.valueOf(), true).cmp(n); }; // ------------------------------------------------------------------------- LRational.prototype.toString = function() { @@ -3472,24 +3584,31 @@ return { bigint: { 'bigint': i, - 'float': (a, b) => [LFloat(a.valueOf()), b], + 'float': (a, b) => [LFloat(a.valueOf(), true), b], 'rational': (a, b) => [{ num: a, denom: 1 }, b], 'complex': (a, b) => [{ im: 0, re: a }, b] }, float: { - 'bigint': (a, b) => [a, LFloat(b.valueOf())], + 'bigint': (a, b) => [a, b && LFloat(b.valueOf(), true)], 'float': i, - 'rational': (a, b) => [a, LFloat(b.valueOf())], + 'rational': (a, b) => [a, b && LFloat(b.valueOf(), true)], 'complex': (a, b) => [{ re: a, im: LFloat(0, true) }, b] }, complex: { bigint: complex('bigint'), float: complex('float'), rational: complex('rational'), - complex: i + complex: (a, b) => { + const [a_re, b_re] = LNumber.coerce(a.re, b.re); + const [a_im, b_im] = LNumber.coerce(a.im, b.im); + return [ + { im: a_im, re: a_re }, + { im: b_im, re: b_re } + ]; + } }, rational: { - bigint: (a, b) => [a, { num: b, denom: 1 }], + bigint: (a, b) => [a, b || { num: b, denom: 1 }], float: (a, b) => [LFloat(a.valueOf()), b], rational: i, complex: complex('rational') @@ -3503,7 +3622,7 @@ re: coerce(type, a.re.type, a.re) }, { - im: coerce(type, a.type, 0), + im: coerce(type, a.im.type, 0), re: coerce(type, b.type, b) } ]; diff --git a/tests/numbers.scm b/tests/numbers.scm index f4f5a2e2..26e27260 100644 --- a/tests/numbers.scm +++ b/tests/numbers.scm @@ -19,6 +19,77 @@ (t.is (/ (make-rectangular 1 2) (make-rectangular 2 10)) (/ 1+2i 2+10i)))) +(test "numbers: literals" + (lambda (t) + (t.is #b100+100i 4+4i) + (t.is (number->string 100) "100") + (t.is (number->string -100) "-100") + (t.is (number->string #i100) "100.0") + (t.is (number->string #i-100) "-100.0") + + (t.is (number->string #o#i100) "64.0") + (t.is (number->string #i#o100) "64.0") + (t.is (number->string #i#o-100) "-64.0") + + (t.is (number->string #x100) "256") + (t.is (number->string #x#i100) "256.0") + (t.is (number->string #x#i-100) "-256.0") + (t.is (number->string #i#x100) "256.0") + (t.is (number->string #i#x-100) "-256.0") + + (t.is (number->string #b100) "4") + (t.is (number->string #b#i100) "4.0") + (t.is (number->string #i#b100) "4.0") + (t.is (number->string #i#b-100) "-4.0") + + (t.is (number->string 1/100) "1/100") + (t.is (number->string -1/100) "-1/100") + (t.is (number->string #i1/100) "0.01") + (t.is (number->string #i-1/100) "-0.01") + + (t.is (number->string #o1/100) "1/64") + (t.is (number->string #o-1/100) "-1/64") + (t.is (number->string #o#i1/100) "0.015625") + (t.is (number->string #o#i-1/100) "-0.015625") + (t.is (number->string #i#o1/100) "0.015625") + (t.is (number->string #i#o-1/100) "-0.015625") + + (t.is (number->string #b1/100) "1/4") + (t.is (number->string #b-1/100) "-1/4") + (t.is (number->string #b#i1/100) "0.25") + (t.is (number->string #b#i-1/100) "-0.25") + (t.is (number->string #i#b1/100) "0.25") + (t.is (number->string #i#b-1/100) "-0.25") + + (t.is (number->string #x1/100) "1/256") + (t.is (number->string #x-1/100) "-1/256") + (t.is (number->string #x#i1/F) "0.06666666666666667") + (t.is (number->string #x#i-1/F) "-0.06666666666666667") + (t.is (number->string #i#x1/F) "0.06666666666666667") + (t.is (number->string #i#x-1/F) "-0.06666666666666667") + + (t.is (number->string 10e+1) "100") + (t.is (number->string -10e+1) "-100") + (t.is (number->string #i10e+1) "100.0") + (t.is (number->string #i-10e+1) "-100.0") + + (t.is (number->string 1.0i) "+1.0i") + (t.is (number->string -1.0i) "-1.0i") + (t.is (number->string #e-1.0i) "-1i") + (t.is (number->string #e0.1+0.1i) "1/10+1/10i") + (t.is (number->string #b100+100i) "4+4i") + (t.is (number->string #b#i100+100i) "4.0+4.0i") + (t.is (number->string #i#b100+100i) "4.0+4.0i") + (t.is (number->string #i#b-100-100i) "-4.0-4.0i") + (t.is (number->string #b#i-100-100i) "-4.0-4.0i") + (t.is (number->string #b-100i) "-4i") + (t.is (number->string #i#b+100i) "+4.0i") + (t.is (number->string #b#i-100i) "-4.0i") + (t.is (number->string #i#b1/100+1/100i) "0.25+0.25i") + (t.is (number->string #i#b-1/100+1/100i) "-0.25+0.25i") + (t.is (number->string #b#i1/100+1/100i) "0.25+0.25i") + (t.is (number->string #b#i-1/100+1/100i) "-0.25+0.25i"))) + (test "numbers: complex" (lambda (t) (t.is (sqrt -1) +1.0i)