diff --git a/CHANGELOG.md b/CHANGELOG.md index 9100e29a..942f0ce6 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ * fix `do` macro [#324](https://github.com/jcubic/lips/issues/324) * fix `string->number` that leads to NaN [#326](https://github.com/jcubic/lips/issues/326) * fix unintentional unboxing in `iterator->array` [#328](https://github.com/jcubic/lips/issues/328) +* fix `replace` with async `lambda` [#319](https://github.com/jcubic/lips/issues/319) ## 1.0.0-beta.18 ### Breaking diff --git a/README.md b/README.md index c8ca91c1..371b5e21 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.18.1-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) ![1.0.0 Complete](https://img.shields.io/github/milestones/progress-percent/jcubic/lips/1?label=1.0.0%20Complete) [![Build and test](https://github.com/jcubic/lips/actions/workflows/build.yaml/badge.svg?branch=devel&event=push)](https://github.com/jcubic/lips/actions/workflows/build.yaml) -[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&a520631e7f12f3eda2816e5633437fc8)](https://coveralls.io/github/jcubic/lips?branch=devel) +[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&6d6875155398b050c8cd14e1bcc09224)](https://coveralls.io/github/jcubic/lips?branch=devel) [![Join Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips) ![NPM Download Count](https://img.shields.io/npm/dm/@jcubic/lips) ![JSDelivr Download count](https://img.shields.io/jsdelivr/npm/hm/@jcubic/lips) @@ -354,7 +354,8 @@ I would also love to see if you use the library, I may even share the links of p * [StackOverlow](https://stackoverflow.com) code was used for functions: * [fworker](https://stackoverflow.com/a/10372280/387194), * [flatten](https://stackoverflow.com/a/27282907/387194), - * [allPossibleCases](https://stackoverflow.com/a/4331218/387194). + * [allPossibleCases](https://stackoverflow.com/a/4331218/387194), + * [async replace](https://stackoverflow.com/a/48032528/387194). * Code formatter is roughly based on [scheme-style](http://community.schemewiki.org/?scheme-style) and GNU Emacs scheme mode. * Some helpers in standard library are inspired by same functions from [RamdaJS library](https://ramdajs.com/). diff --git a/dist/lips.cjs b/dist/lips.cjs index cca84512..ee803448 100644 --- a/dist/lips.cjs +++ b/dist/lips.cjs @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Tue, 05 Mar 2024 13:03:01 +0000 + * build: Tue, 05 Mar 2024 15:58:24 +0000 */ 'use strict'; @@ -13301,6 +13301,18 @@ var global_env = new Environment({ typecheck('replace', pattern, ['regex', 'string']); typecheck('replace', replacement, ['string', 'function']); typecheck('replace', string, 'string'); + if (is_function(replacement)) { + // ref: https://stackoverflow.com/a/48032528/387194 + var replacements = []; + string.replace(pattern, function () { + replacements.push(replacement.apply(void 0, arguments)); + }); + return unpromise(replacements, function (replacements) { + return string.replace(pattern, function () { + return replacements.shift(); + }); + }); + } return string.replace(pattern, replacement); }, "(replace pattern replacement string)\n\n Function that changes pattern to replacement inside string. Pattern can be a\n string or regex and replacement can be function or string. See Javascript\n String.replace()."), // ------------------------------------------------------------------ @@ -15582,10 +15594,10 @@ if (typeof window !== 'undefined') { // ------------------------------------------------------------------------- var banner = function () { // Rollup tree-shaking is removing the variable if it's normal string because - // obviously 'Tue, 05 Mar 2024 13:03:01 +0000' == '{{' + 'DATE}}'; can be removed + // obviously 'Tue, 05 Mar 2024 15:58:24 +0000' == '{{' + 'DATE}}'; can be removed // but disabling Tree-shaking is adding lot of not used code so we use this // hack instead - var date = LString('Tue, 05 Mar 2024 13:03:01 +0000').valueOf(); + var date = LString('Tue, 05 Mar 2024 15:58:24 +0000').valueOf(); var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date); var _format = function _format(x) { return x.toString().padStart(2, '0'); @@ -15625,7 +15637,7 @@ read_only(QuotedPromise, '__class__', 'promise'); read_only(Parameter, '__class__', 'parameter'); // ------------------------------------------------------------------------- var version = 'DEV'; -var date = 'Tue, 05 Mar 2024 13:03:01 +0000'; +var date = 'Tue, 05 Mar 2024 15:58:24 +0000'; // unwrap async generator into Promise var parse = compose(uniterate_async, _parse); diff --git a/dist/lips.esm.js b/dist/lips.esm.js index de5dce9c..5a77261d 100644 --- a/dist/lips.esm.js +++ b/dist/lips.esm.js @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Tue, 05 Mar 2024 13:03:01 +0000 + * build: Tue, 05 Mar 2024 15:58:24 +0000 */ function _classApplyDescriptorGet(receiver, descriptor) { @@ -13298,6 +13298,18 @@ var global_env = new Environment({ typecheck('replace', pattern, ['regex', 'string']); typecheck('replace', replacement, ['string', 'function']); typecheck('replace', string, 'string'); + if (is_function(replacement)) { + // ref: https://stackoverflow.com/a/48032528/387194 + var replacements = []; + string.replace(pattern, function () { + replacements.push(replacement.apply(void 0, arguments)); + }); + return unpromise(replacements, function (replacements) { + return string.replace(pattern, function () { + return replacements.shift(); + }); + }); + } return string.replace(pattern, replacement); }, "(replace pattern replacement string)\n\n Function that changes pattern to replacement inside string. Pattern can be a\n string or regex and replacement can be function or string. See Javascript\n String.replace()."), // ------------------------------------------------------------------ @@ -15579,10 +15591,10 @@ if (typeof window !== 'undefined') { // ------------------------------------------------------------------------- var banner = function () { // Rollup tree-shaking is removing the variable if it's normal string because - // obviously 'Tue, 05 Mar 2024 13:03:01 +0000' == '{{' + 'DATE}}'; can be removed + // obviously 'Tue, 05 Mar 2024 15:58:24 +0000' == '{{' + 'DATE}}'; can be removed // but disabling Tree-shaking is adding lot of not used code so we use this // hack instead - var date = LString('Tue, 05 Mar 2024 13:03:01 +0000').valueOf(); + var date = LString('Tue, 05 Mar 2024 15:58:24 +0000').valueOf(); var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date); var _format = function _format(x) { return x.toString().padStart(2, '0'); @@ -15622,7 +15634,7 @@ read_only(QuotedPromise, '__class__', 'promise'); read_only(Parameter, '__class__', 'parameter'); // ------------------------------------------------------------------------- var version = 'DEV'; -var date = 'Tue, 05 Mar 2024 13:03:01 +0000'; +var date = 'Tue, 05 Mar 2024 15:58:24 +0000'; // unwrap async generator into Promise var parse = compose(uniterate_async, _parse); diff --git a/dist/lips.esm.min.js b/dist/lips.esm.min.js index 20ea59c4..c184e9f6 100644 --- a/dist/lips.esm.min.js +++ b/dist/lips.esm.min.js @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Tue, 05 Mar 2024 13:03:01 +0000 + * build: Tue, 05 Mar 2024 15:58:24 +0000 */ function _classApplyDescriptorGet(e,t){if(t.get){return t.get.call(e)}return t.value}function _classExtractFieldDescriptor(e,t,r){if(!t.has(e)){throw new TypeError("attempted to "+r+" private field on non-instance")}return t.get(e)}function _classPrivateFieldGet(e,t){var r=_classExtractFieldDescriptor(e,t,"get");return _classApplyDescriptorGet(e,r)}function _classApplyDescriptorSet(e,t,r){if(t.set){t.set.call(e,r)}else{if(!t.writable){throw new TypeError("attempted to set read only private field")}t.value=r}}function _classPrivateFieldSet(e,t,r){var n=_classExtractFieldDescriptor(e,t,"set");_classApplyDescriptorSet(e,n,r);return r}function _getPrototypeOf(e){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function e(t){return t.__proto__||Object.getPrototypeOf(t)};return _getPrototypeOf(e)}function _setPrototypeOf(e,t){_setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function e(t,r){t.__proto__=r;return t};return _setPrototypeOf(e,t)}function _isNativeFunction(t){try{return Function.toString.call(t).indexOf("[native code]")!==-1}catch(e){return typeof t==="function"}}function _isNativeReflectConstruct$1(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(_isNativeReflectConstruct$1=function e(){return!!t})()}function _construct(e,t,r){if(_isNativeReflectConstruct$1())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,t);var i=new(e.bind.apply(e,n));return r&&_setPrototypeOf(i,r.prototype),i}function _wrapNativeSuper(e){var n=typeof Map==="function"?new Map:undefined;_wrapNativeSuper=function e(t){if(t===null||!_isNativeFunction(t))return t;if(typeof t!=="function"){throw new TypeError("Super expression must either be null or a function")}if(typeof n!=="undefined"){if(n.has(t))return n.get(t);n.set(t,r)}function r(){return _construct(t,arguments,_getPrototypeOf(this).constructor)}r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:false,writable:true,configurable:true}});return _setPrototypeOf(r,t)};return _wrapNativeSuper(e)}function _typeof$1(e){"@babel/helpers - typeof";return _typeof$1="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof$1(e)}function _assertThisInitialized(e){if(e===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return e}function _possibleConstructorReturn(e,t){if(t&&(_typeof$1(t)==="object"||typeof t==="function")){return t}else if(t!==void 0){throw new TypeError("Derived constructors may only return object or undefined")}return _assertThisInitialized(e)}function _inherits(e,t){if(typeof t!=="function"&&t!==null){throw new TypeError("Super expression must either be null or a function")}e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:true,configurable:true}});Object.defineProperty(e,"prototype",{writable:false});if(t)_setPrototypeOf(e,t)}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArray(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function _arrayLikeToArray$1(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r=0)continue;r[i]=e[i]}return r}function _objectWithoutProperties(e,t){if(e==null)return{};var r=_objectWithoutPropertiesLoose(e,t);var n,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,n))continue;r[n]=e[n]}}return r}function _iterableToArrayLimit(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,a,o,u=[],s=!0,c=!1;try{if(a=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=a.call(r)).done)&&(u.push(n.value),u.length!==t);s=!0);}catch(e){c=!0,i=e}finally{try{if(!s&&null!=r["return"]&&(o=r["return"](),Object(o)!==o))return}finally{if(c)throw i}}return u}}function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_unsupportedIterableToArray$1(e,t)||_nonIterableRest()}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray$1(e)}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray$1(e)||_nonIterableSpread()}function _OverloadYield(e,t){this.v=e,this.k=t}function _awaitAsyncGenerator(e){return new _OverloadYield(e,0)}function AsyncGenerator(o){var a,u;function s(r,e){try{var n=o[r](e),i=n.value,a=i instanceof _OverloadYield;Promise.resolve(a?i.v:i).then(function(e){if(a){var t="return"===r?"return":"next";if(!i.k||e.done)return s(t,e);e=o[t](e).value}c(n.done?"return":"normal",e)},function(e){s("throw",e)})}catch(e){c("throw",e)}}function c(e,t){switch(e){case"return":a.resolve({value:t,done:!0});break;case"throw":a.reject(t);break;default:a.resolve({value:t,done:!1})}(a=a.next)?s(a.key,a.arg):u=null}this._invoke=function(n,i){return new Promise(function(e,t){var r={key:n,arg:i,resolve:e,reject:t,next:null};u?u=u.next=r:(a=u=r,s(n,i))})},"function"!=typeof o["return"]&&(this["return"]=void 0)}AsyncGenerator.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},AsyncGenerator.prototype.next=function(e){return this._invoke("next",e)},AsyncGenerator.prototype["throw"]=function(e){return this._invoke("throw",e)},AsyncGenerator.prototype["return"]=function(e){return this._invoke("return",e)};function _wrapAsyncGenerator(e){return function(){return new AsyncGenerator(e.apply(this,arguments))}}function getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e["default"]:e}var regeneratorRuntime$1={exports:{}};var _typeof={exports:{}};(function(t){function r(e){"@babel/helpers - typeof";return t.exports=r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t.exports.__esModule=true,t.exports["default"]=t.exports,r(e)}t.exports=r,t.exports.__esModule=true,t.exports["default"]=t.exports})(_typeof);var _typeofExports=_typeof.exports;(function(P){var N=_typeofExports["default"];function B(){P.exports=B=function e(){return o},P.exports.__esModule=true,P.exports["default"]=P.exports;var c,o={},e=Object.prototype,l=e.hasOwnProperty,f=Object.defineProperty||function(e,t,r){e[t]=r.value},t="function"==typeof Symbol?Symbol:{},i=t.iterator||"@@iterator",r=t.asyncIterator||"@@asyncIterator",n=t.toStringTag||"@@toStringTag";function a(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{a({},"")}catch(c){a=function e(t,r,n){return t[r]=n}}function u(e,t,r,n){var i=t&&t.prototype instanceof s?t:s,a=Object.create(i.prototype),o=new C(n||[]);return f(a,"_invoke",{value:S(e,r,o)}),a}function _(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}o.wrap=u;var p="suspendedStart",d="suspendedYield",h="executing",m="completed",y={};function s(){}function v(){}function b(){}var g={};a(g,i,function(){return this});var w=Object.getPrototypeOf,D=w&&w(w(O([])));D&&D!==e&&l.call(D,i)&&(g=D);var x=b.prototype=s.prototype=Object.create(g);function L(e){["next","throw","return"].forEach(function(t){a(e,t,function(e){return this._invoke(t,e)})})}function E(u,s){function c(e,t,r,n){var i=_(u[e],u,t);if("throw"!==i.type){var a=i.arg,o=a.value;return o&&"object"==N(o)&&l.call(o,"__await")?s.resolve(o.__await).then(function(e){c("next",e,r,n)},function(e){c("throw",e,r,n)}):s.resolve(o).then(function(e){a.value=e,r(a)},function(e){return c("throw",e,r,n)})}n(i.arg)}var i;f(this,"_invoke",{value:function e(r,n){function t(){return new s(function(e,t){c(r,n,e,t)})}return i=i?i.then(t,t):t()}})}function S(a,o,u){var s=p;return function(e,t){if(s===h)throw new Error("Generator is already running");if(s===m){if("throw"===e)throw t;return{value:c,done:!0}}for(u.method=e,u.arg=t;;){var r=u.delegate;if(r){var n=A(r,u);if(n){if(n===y)continue;return n}}if("next"===u.method)u.sent=u._sent=u.arg;else if("throw"===u.method){if(s===p)throw s=m,u.arg;u.dispatchException(u.arg)}else"return"===u.method&&u.abrupt("return",u.arg);s=h;var i=_(a,o,u);if("normal"===i.type){if(s=u.done?m:d,i.arg===y)continue;return{value:i.arg,done:u.done}}"throw"===i.type&&(s=m,u.method="throw",u.arg=i.arg)}}}function A(e,t){var r=t.method,n=e.iterator[r];if(n===c)return t.delegate=null,"throw"===r&&e.iterator["return"]&&(t.method="return",t.arg=c,A(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),y;var i=_(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,y;var a=i.arg;return a?a.done?(t[e.resultName]=a.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=c),t.delegate=null,y):a:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,y)}function F(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function k(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function C(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(F,this),this.reset(!0)}function O(t){if(t||""===t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,n=function e(){for(;++r=0;--i){var a=this.tryEntries[i],o=a.completion;if("root"===a.tryLoc)return t("end");if(a.tryLoc<=this.prev){var u=l.call(a,"catchLoc"),s=l.call(a,"finallyLoc");if(u&&s){if(this.prev=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&l.call(i,"finallyLoc")&&this.prev=0;--r){var n=this.tryEntries[r];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),k(n),y}},catch:function e(t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc===t){var i=n.completion;if("throw"===i.type){var a=i.arg;k(n)}return a}}throw new Error("illegal catch attempt")},delegateYield:function e(t,r,n){return this.delegate={iterator:O(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=c),y}},o}P.exports=B,P.exports.__esModule=true,P.exports["default"]=P.exports})(regeneratorRuntime$1);var regeneratorRuntimeExports=regeneratorRuntime$1.exports;var runtime=regeneratorRuntimeExports();var regenerator=runtime;try{regeneratorRuntime=runtime}catch(e){if(typeof globalThis==="object"){globalThis.regeneratorRuntime=runtime}else{Function("r","regeneratorRuntime = r")(runtime)}}var _regeneratorRuntime=getDefaultExportFromCjs(regenerator);let decoder;try{decoder=new TextDecoder}catch(e){}let src;let srcEnd;let position$1=0;const LEGACY_RECORD_INLINE_ID=105;const RECORD_DEFINITIONS_ID=57342;const RECORD_INLINE_ID=57343;const BUNDLED_STRINGS_ID=57337;const PACKED_REFERENCE_TAG_ID=6;const STOP_CODE={};let currentDecoder={};let currentStructures;let srcString;let srcStringStart=0;let srcStringEnd=0;let bundledStrings$1;let referenceMap;let currentExtensions=[];let currentExtensionRanges=[];let packedValues;let dataView;let restoreMapsAsObject;let defaultOptions={useRecords:false,mapsAsObjects:true};let sequentialMode=false;let inlineObjectReadThreshold=2;try{new Function("")}catch(e){inlineObjectReadThreshold=Infinity}class Decoder{constructor(r){if(r){if((r.keyMap||r._keyMap)&&!r.useRecords){r.useRecords=false;r.mapsAsObjects=true}if(r.useRecords===false&&r.mapsAsObjects===undefined)r.mapsAsObjects=true;if(r.getStructures)r.getShared=r.getStructures;if(r.getShared&&!r.structures)(r.structures=[]).uninitialized=true;if(r.keyMap){this.mapKey=new Map;for(let[e,t]of Object.entries(r.keyMap))this.mapKey.set(t,e)}}Object.assign(this,r)}decodeKey(e){return this.keyMap?this.mapKey.get(e)||e:e}encodeKey(e){return this.keyMap&&this.keyMap.hasOwnProperty(e)?this.keyMap[e]:e}encodeKeys(r){if(!this._keyMap)return r;let n=new Map;for(let[e,t]of Object.entries(r))n.set(this._keyMap.hasOwnProperty(e)?this._keyMap[e]:e,t);return n}decodeKeys(e){if(!this._keyMap||e.constructor.name!="Map")return e;if(!this._mapKey){this._mapKey=new Map;for(let[e,t]of Object.entries(this._keyMap))this._mapKey.set(t,e)}let r={};e.forEach((e,t)=>r[safeKey(this._mapKey.has(t)?this._mapKey.get(t):t)]=e);return r}mapDecode(e,t){let r=this.decode(e);if(this._keyMap){switch(r.constructor.name){case"Array":return r.map(e=>this.decodeKeys(e))}}return r}decode(t,e){if(src){return saveState(()=>{clearSource();return this?this.decode(t,e):Decoder.prototype.decode.call(defaultOptions,t,e)})}srcEnd=e>-1?e:t.length;position$1=0;srcStringEnd=0;srcString=null;bundledStrings$1=null;src=t;try{dataView=t.dataView||(t.dataView=new DataView(t.buffer,t.byteOffset,t.byteLength))}catch(e){src=null;if(t instanceof Uint8Array)throw e;throw new Error("Source must be a Uint8Array or Buffer but was a "+(t&&typeof t=="object"?t.constructor.name:typeof t))}if(this instanceof Decoder){currentDecoder=this;packedValues=this.sharedValues&&(this.pack?new Array(this.maxPrivatePackedValues||16).concat(this.sharedValues):this.sharedValues);if(this.structures){currentStructures=this.structures;return checkedRead()}else if(!currentStructures||currentStructures.length>0){currentStructures=[]}}else{currentDecoder=defaultOptions;if(!currentStructures||currentStructures.length>0)currentStructures=[];packedValues=null}return checkedRead()}decodeMultiple(r,n){let i,a=0;try{let e=r.length;sequentialMode=true;let t=this?this.decode(r,e):defaultDecoder.decode(r,e);if(n){if(n(t)===false){return}while(position$1=bundledStrings$1.postBundlePosition){let e=new Error("Unexpected bundle position");e.incomplete=true;throw e}position$1=bundledStrings$1.postBundlePosition;bundledStrings$1=null}if(position$1==srcEnd){currentStructures=null;src=null;if(referenceMap)referenceMap=null}else if(position$1>srcEnd){let e=new Error("Unexpected end of CBOR data");e.incomplete=true;throw e}else if(!sequentialMode){throw new Error("Data read, but end of buffer not reached")}return e}catch(e){clearSource();if(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer")){e.incomplete=true}throw e}}function read(){let n=src[position$1++];let i=n>>5;n=n&31;if(n>23){switch(n){case 24:n=src[position$1++];break;case 25:if(i==7){return getFloat16()}n=dataView.getUint16(position$1);position$1+=2;break;case 26:if(i==7){let t=dataView.getFloat32(position$1);if(currentDecoder.useFloat32>2){let e=mult10[(src[position$1]&127)<<1|src[position$1+1]>>7];position$1+=4;return(e*t+(t>0?.5:-.5)>>0)/e}position$1+=4;return t}n=dataView.getUint32(position$1);position$1+=4;break;case 27:if(i==7){let e=dataView.getFloat64(position$1);position$1+=8;return e}if(i>1){if(dataView.getUint32(position$1)>0)throw new Error("JavaScript does not support arrays, maps, or strings with length over 4294967295");n=dataView.getUint32(position$1+4)}else if(currentDecoder.int64AsNumber){n=dataView.getUint32(position$1)*4294967296;n+=dataView.getUint32(position$1+4)}else n=dataView.getBigUint64(position$1);position$1+=8;break;case 31:switch(i){case 2:case 3:throw new Error("Indefinite length not supported for byte or text strings");case 4:let e=[];let t,r=0;while((t=read())!=STOP_CODE){e[r++]=t}return i==4?e:i==3?e.join(""):Buffer.concat(e);case 5:let n;if(currentDecoder.mapsAsObjects){let e={};if(currentDecoder.keyMap)while((n=read())!=STOP_CODE)e[safeKey(currentDecoder.decodeKey(n))]=read();else while((n=read())!=STOP_CODE)e[safeKey(n)]=read();return e}else{if(restoreMapsAsObject){currentDecoder.mapsAsObjects=true;restoreMapsAsObject=false}let e=new Map;if(currentDecoder.keyMap)while((n=read())!=STOP_CODE)e.set(currentDecoder.decodeKey(n),read());else while((n=read())!=STOP_CODE)e.set(n,read());return e}case 7:return STOP_CODE;default:throw new Error("Invalid major type for indefinite length "+i)}default:throw new Error("Unknown token "+n)}}switch(i){case 0:return n;case 1:return~n;case 2:return readBin(n);case 3:if(srcStringEnd>=position$1){return srcString.slice(position$1-srcStringStart,(position$1+=n)-srcStringStart)}if(srcStringEnd==0&&srcEnd<140&&n<32){let e=n<16?shortStringInJS(n):longStringInJS(n);if(e!=null)return e}return readFixedString(n);case 4:let t=new Array(n);for(let e=0;e=BUNDLED_STRINGS_ID){let e=currentStructures[n&8191];if(e){if(!e.read)e.read=createStructureReader(e);return e.read()}if(n<65536){if(n==RECORD_INLINE_ID){let e=readJustLength();let t=read();let r=read();recordDefinition(t,r);let n={};if(currentDecoder.keyMap)for(let t=2;t23){switch(t){case 24:t=src[position$1++];break;case 25:t=dataView.getUint16(position$1);position$1+=2;break;case 26:t=dataView.getUint32(position$1);position$1+=4;break;default:throw new Error("Expected array header, but got "+src[position$1-1])}}let r=this.compiledReader;while(r){if(r.propertyCount===t)return r(read);r=r.next}if(this.slowReads++>=inlineObjectReadThreshold){let e=this.length==t?this:this.slice(0,t);r=currentDecoder.keyMap?new Function("r","return {"+e.map(e=>currentDecoder.decodeKey(e)).map(e=>validName.test(e)?safeKey(e)+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"}"):new Function("r","return {"+e.map(e=>validName.test(e)?safeKey(e)+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"}");if(this.compiledReader)r.next=this.compiledReader;r.propertyCount=t;this.compiledReader=r;return r(read)}let n={};if(currentDecoder.keyMap)for(let e=0;e64&&decoder)return decoder.decode(src.subarray(position$1,position$1+=e));const r=position$1+e;const n=[];t="";while(position$165535){e-=65536;n.push(e>>>10&1023|55296);e=56320|e&1023}n.push(e)}else{n.push(i)}if(n.length>=4096){t+=fromCharCode.apply(String,n);n.length=0}}if(n.length>0){t+=fromCharCode.apply(String,n)}return t}let fromCharCode=String.fromCharCode;function longStringInJS(t){let r=position$1;let n=new Array(t);for(let e=0;e0){position$1=r;return}n[e]=i}return fromCharCode.apply(String,n)}function shortStringInJS(h){if(h<4){if(h<2){if(h===0)return"";else{let e=src[position$1++];if((e&128)>1){position$1-=1;return}return fromCharCode(e)}}else{let e=src[position$1++];let t=src[position$1++];if((e&128)>0||(t&128)>0){position$1-=2;return}if(h<3)return fromCharCode(e,t);let r=src[position$1++];if((r&128)>0){position$1-=3;return}return fromCharCode(e,t,r)}}else{let f=src[position$1++];let _=src[position$1++];let p=src[position$1++];let d=src[position$1++];if((f&128)>0||(_&128)>0||(p&128)>0||(d&128)>0){position$1-=4;return}if(h<6){if(h===4)return fromCharCode(f,_,p,d);else{let e=src[position$1++];if((e&128)>0){position$1-=5;return}return fromCharCode(f,_,p,d,e)}}else if(h<8){let e=src[position$1++];let t=src[position$1++];if((e&128)>0||(t&128)>0){position$1-=6;return}if(h<7)return fromCharCode(f,_,p,d,e,t);let r=src[position$1++];if((r&128)>0){position$1-=7;return}return fromCharCode(f,_,p,d,e,t,r)}else{let u=src[position$1++];let s=src[position$1++];let c=src[position$1++];let l=src[position$1++];if((u&128)>0||(s&128)>0||(c&128)>0||(l&128)>0){position$1-=8;return}if(h<10){if(h===8)return fromCharCode(f,_,p,d,u,s,c,l);else{let e=src[position$1++];if((e&128)>0){position$1-=9;return}return fromCharCode(f,_,p,d,u,s,c,l,e)}}else if(h<12){let e=src[position$1++];let t=src[position$1++];if((e&128)>0||(t&128)>0){position$1-=10;return}if(h<11)return fromCharCode(f,_,p,d,u,s,c,l,e,t);let r=src[position$1++];if((r&128)>0){position$1-=11;return}return fromCharCode(f,_,p,d,u,s,c,l,e,t,r)}else{let n=src[position$1++];let i=src[position$1++];let a=src[position$1++];let o=src[position$1++];if((n&128)>0||(i&128)>0||(a&128)>0||(o&128)>0){position$1-=12;return}if(h<14){if(h===12)return fromCharCode(f,_,p,d,u,s,c,l,n,i,a,o);else{let e=src[position$1++];if((e&128)>0){position$1-=13;return}return fromCharCode(f,_,p,d,u,s,c,l,n,i,a,o,e)}}else{let e=src[position$1++];let t=src[position$1++];if((e&128)>0||(t&128)>0){position$1-=14;return}if(h<15)return fromCharCode(f,_,p,d,u,s,c,l,n,i,a,o,e,t);let r=src[position$1++];if((r&128)>0){position$1-=15;return}return fromCharCode(f,_,p,d,u,s,c,l,n,i,a,o,e,t,r)}}}}}function readBin(e){return currentDecoder.copyBuffers?Uint8Array.prototype.slice.call(src,position$1,position$1+=e):src.subarray(position$1,position$1+=e)}let f32Array=new Float32Array(1);let u8Array=new Uint8Array(f32Array.buffer,0,4);function getFloat16(){let t=src[position$1++];let r=src[position$1++];let e=(t&127)>>2;if(e===31){if(r||t&3)return NaN;return t&128?-Infinity:Infinity}if(e===0){let e=((t&3)<<8|r)/(1<<24);return t&128?-e:e}u8Array[3]=t&128|(e>>1)+56;u8Array[2]=(t&7)<<5|r>>3;u8Array[1]=r<<5;u8Array[0]=0;return f32Array[0]}new Array(4096);class Tag{constructor(e,t){this.value=e;this.tag=t}}currentExtensions[0]=e=>{return new Date(e)};currentExtensions[1]=e=>{return new Date(Math.round(e*1e3))};currentExtensions[2]=r=>{let n=BigInt(0);for(let e=0,t=r.byteLength;e{return BigInt(-1)-currentExtensions[2](e)};currentExtensions[4]=e=>{return+(e[1]+"e"+e[0])};currentExtensions[5]=e=>{return e[1]*Math.exp(e[0]*Math.log(2))};const recordDefinition=(e,t)=>{e=e-57344;let r=currentStructures[e];if(r&&r.isShared){(currentStructures.restoreStructures||(currentStructures.restoreStructures=[]))[e]=r}currentStructures[e]=t;t.read=createStructureReader(t)};currentExtensions[LEGACY_RECORD_INLINE_ID]=r=>{let e=r.length;let n=r[1];recordDefinition(r[0],n);let i={};for(let t=2;t{if(bundledStrings$1)return bundledStrings$1[0].slice(bundledStrings$1.position0,bundledStrings$1.position0+=e);return new Tag(e,14)};currentExtensions[15]=e=>{if(bundledStrings$1)return bundledStrings$1[1].slice(bundledStrings$1.position1,bundledStrings$1.position1+=e);return new Tag(e,15)};let glbl={Error:Error,RegExp:RegExp};currentExtensions[27]=e=>{return(glbl[e[0]]||Error)(e[1],e[2])};const packedTable=e=>{if(src[position$1++]!=132){let e=new Error("Packed values structure must be followed by a 4 element array");if(src.length{if(!packedValues){if(currentDecoder.getShared)loadShared();else return new Tag(e,PACKED_REFERENCE_TAG_ID)}if(typeof e=="number")return packedValues[16+(e>=0?2*e:-2*e-1)];let t=new Error("No support for non-integer packed references yet");if(e===undefined)t.incomplete=true;throw t};currentExtensions[28]=e=>{if(!referenceMap){referenceMap=new Map;referenceMap.id=0}let t=referenceMap.id++;let r=src[position$1];let n;if(r>>5==4)n=[];else n={};let i={target:n};referenceMap.set(t,i);let a=e();if(i.used)return Object.assign(n,a);i.target=a;return a};currentExtensions[28].handlesRead=true;currentExtensions[29]=e=>{let t=referenceMap.get(e);t.used=true;return t.target};currentExtensions[258]=e=>new Set(e);(currentExtensions[259]=e=>{if(currentDecoder.mapsAsObjects){currentDecoder.mapsAsObjects=false;restoreMapsAsObject=true}return e()}).handlesRead=true;function combine(e,t){if(typeof e==="string")return e+t;if(e instanceof Array)return e.concat(t);return Object.assign({},e,t)}function getPackedValues(){if(!packedValues){if(currentDecoder.getShared)loadShared();else throw new Error("No packed values available")}return packedValues}const SHARED_DATA_TAG_ID=1399353956;currentExtensionRanges.push((e,t)=>{if(e>=225&&e<=255)return combine(getPackedValues().prefixes[e-224],t);if(e>=28704&&e<=32767)return combine(getPackedValues().prefixes[e-28672],t);if(e>=1879052288&&e<=2147483647)return combine(getPackedValues().prefixes[e-1879048192],t);if(e>=216&&e<=223)return combine(t,getPackedValues().suffixes[e-216]);if(e>=27647&&e<=28671)return combine(t,getPackedValues().suffixes[e-27639]);if(e>=1811940352&&e<=1879048191)return combine(t,getPackedValues().suffixes[e-1811939328]);if(e==SHARED_DATA_TAG_ID){return{packedValues:packedValues,structures:currentStructures.slice(0),version:t}}if(e==55799)return t});const isLittleEndianMachine$1=new Uint8Array(new Uint16Array([1]).buffer)[0]==1;const typedArrays=[Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array=="undefined"?{name:"BigUint64Array"}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array=="undefined"?{name:"BigInt64Array"}:BigInt64Array,Float32Array,Float64Array];const typedArrayTags=[64,68,69,70,71,72,77,78,79,85,86];for(let e=0;e{if(!u)throw new Error("Could not find typed array for code "+s);if(!currentDecoder.copyBuffers){if(t===1||t===2&&!(e.byteOffset&1)||t===4&&!(e.byteOffset&3)||t===8&&!(e.byteOffset&7))return new u(e.buffer,e.byteOffset,e.byteLength)}return new u(Uint8Array.prototype.slice.call(e,0).buffer)}:e=>{if(!u)throw new Error("Could not find typed array for code "+s);let t=new DataView(e.buffer,e.byteOffset,e.byteLength);let r=e.length>>a;let n=new u(r);let i=t[c];for(let e=0;e23){switch(e){case 24:e=src[position$1++];break;case 25:e=dataView.getUint16(position$1);position$1+=2;break;case 26:e=dataView.getUint32(position$1);position$1+=4;break}}return e}function loadShared(){if(currentDecoder.getShared){let e=saveState(()=>{src=null;return currentDecoder.getShared()})||{};let t=e.structures||[];currentDecoder.sharedVersion=e.version;packedValues=currentDecoder.sharedValues=e.packedValues;if(currentStructures===true)currentDecoder.structures=currentStructures=t;else currentStructures.splice.apply(currentStructures,[0,t.length].concat(t))}}function saveState(e){let t=srcEnd;let r=position$1;let n=srcStringStart;let i=srcStringEnd;let a=srcString;let o=referenceMap;let u=bundledStrings$1;let s=new Uint8Array(src.slice(0,srcEnd));let c=currentStructures;let l=currentDecoder;let f=sequentialMode;let _=e();srcEnd=t;position$1=r;srcStringStart=n;srcStringEnd=i;srcString=a;referenceMap=o;bundledStrings$1=u;src=s;sequentialMode=f;currentStructures=c;currentDecoder=l;dataView=new DataView(src.buffer,src.byteOffset,src.byteLength);return _}function clearSource(){src=null;referenceMap=null;currentStructures=null}function addExtension$1(e){currentExtensions[e.tag]=e.decode}const mult10=new Array(147);for(let e=0;e<256;e++){mult10[e]=+("1e"+Math.floor(45.15-e*.30103))}let defaultDecoder=new Decoder({useRecords:false});defaultDecoder.decode;defaultDecoder.decodeMultiple;let textEncoder;try{textEncoder=new TextEncoder}catch(e){}let extensions,extensionClasses;const Buffer$1=typeof globalThis==="object"&&globalThis.Buffer;const hasNodeBuffer=typeof Buffer$1!=="undefined";const ByteArrayAllocate=hasNodeBuffer?Buffer$1.allocUnsafeSlow:Uint8Array;const ByteArray=hasNodeBuffer?Buffer$1:Uint8Array;const MAX_STRUCTURES=256;const MAX_BUFFER_SIZE=hasNodeBuffer?4294967296:2144337920;let throwOnIterable;let target;let targetView;let position=0;let safeEnd;let bundledStrings=null;const MAX_BUNDLE_SIZE=61440;const hasNonLatin=/[\u0080-\uFFFF]/;const RECORD_SYMBOL=Symbol("record-id");class Encoder extends Decoder{constructor(r){super(r);this.offset=0;let s;let o;let l;let f;let n;r=r||{};let c=ByteArray.prototype.utf8Write?function(e,t,r){return target.utf8Write(e,t,r)}:textEncoder&&textEncoder.encodeInto?function(e,t){return textEncoder.encodeInto(e,target.subarray(t)).written}:false;let a=this;let e=r.structures||r.saveStructures;let _=r.maxSharedStructures;if(_==null)_=e?128:0;if(_>8190)throw new Error("Maximum maxSharedStructure is 8190");let i=r.sequential;if(i){_=0}if(!this.structures)this.structures=[];if(this.saveStructures)this.saveShared=this.saveStructures;let p,d,u=r.sharedValues;let h;if(u){h=Object.create(null);for(let e=0,t=u.length;ethis.encodeKeys(e));break}}return this.encode(e,t)};this.encode=function(t,e){if(!target){target=new ByteArrayAllocate(8192);targetView=new DataView(target.buffer,0,8192);position=0}safeEnd=target.length-10;if(safeEnd-position<2048){target=new ByteArrayAllocate(target.length);targetView=new DataView(target.buffer,0,target.length);safeEnd=target.length-10;position=0}else if(e===REUSE_BUFFER_MODE)position=position+7&2147483640;s=position;if(a.useSelfDescribedHeader){targetView.setUint32(position,3654940416);position+=3}n=a.structuredClone?new Map:null;if(a.bundleStrings&&typeof t!=="string"){bundledStrings=[];bundledStrings.size=Infinity}else bundledStrings=null;o=a.structures;if(o){if(o.uninitialized){let e=a.getShared()||{};a.structures=o=e.structures||[];a.sharedVersion=e.version;let r=a.sharedValues=e.packedValues;if(r){h={};for(let e=0,t=r.length;e_&&!i)e=_;if(!o.transitions){o.transitions=Object.create(null);for(let a=0;a0){target[position++]=216;target[position++]=51;writeArrayHeader(4);let r=e.values;b(r);writeArrayHeader(0);writeArrayHeader(0);d=Object.create(h||null);for(let e=0,t=r.length;esafeEnd)w(position);a.offset=position;let e=insertIds(target.subarray(s,position),n.idsToInsert);n=null;return e}if(e&REUSE_BUFFER_MODE){target.start=s;target.end=position;return target}return target.subarray(s,position)}finally{if(o){if(v<10)v++;if(o.length>_)o.length=_;if(y>1e4){o.transitions=null;v=0;y=0;if(m.length>0)m=[]}else if(m.length>0&&!i){for(let e=0,t=m.length;e_){a.structures=a.structures.slice(0,_)}let e=target.subarray(s,position);if(a.updateSharedData()===false)return a.encode(t);return e}if(e&RESET_BUFFER_MODE)position=s}};this.findCommonStringsToPack=()=>{p=new Map;if(!h)h=Object.create(null);return e=>{let r=e&&e.threshold||4;let n=this.pack?e.maxPrivatePackedValues||16:0;if(!u)u=this.sharedValues=[];for(let[e,t]of p){if(t.count>r){h[e]=n++;u.push(e);l=true}}while(this.saveShared&&this.updateSharedData()===false){}p=null}};const b=o=>{if(position>safeEnd)target=w(position);var e=typeof o;var u;if(e==="string"){if(d){let e=d[o];if(e>=0){if(e<16)target[position++]=e+224;else{target[position++]=198;if(e&1)b(15-e>>1);else b(e-16>>1)}return}else if(p&&!r.pack){let e=p.get(o);if(e)e.count++;else p.set(o,{count:1})}}let i=o.length;if(bundledStrings&&i>=4&&i<1024){if((bundledStrings.size+=i)>MAX_BUNDLE_SIZE){let e;let t=(bundledStrings[0]?bundledStrings[0].length*3+bundledStrings[1].length:0)+10;if(position+t>safeEnd)target=w(position+t);target[position++]=217;target[position++]=223;target[position++]=249;target[position++]=bundledStrings.position?132:130;target[position++]=26;e=position-s;position+=4;if(bundledStrings.position){writeBundles(s,b)}bundledStrings=["",""];bundledStrings.size=0;bundledStrings.position=e}let e=hasNonLatin.test(o);bundledStrings[e?0:1]+=o;target[position++]=e?206:207;b(i);return}let a;if(i<32){a=1}else if(i<256){a=2}else if(i<65536){a=3}else{a=5}let e=i*3;if(position+e>safeEnd)target=w(position+e);if(i<64||!c){let e,t,r,n=position+a;for(e=0;e>6|192;target[n++]=t&63|128}else if((t&64512)===55296&&((r=o.charCodeAt(e+1))&64512)===56320){t=65536+((t&1023)<<10)+(r&1023);e++;target[n++]=t>>18|240;target[n++]=t>>12&63|128;target[n++]=t>>6&63|128;target[n++]=t&63|128}else{target[n++]=t>>12|224;target[n++]=t>>6&63|128;target[n++]=t&63|128}}u=n-position-a}else{u=c(o,position+a,e)}if(u<24){target[position++]=96|u}else if(u<256){if(a<2){target.copyWithin(position+2,position+1,position+1+u)}target[position++]=120;target[position++]=u}else if(u<65536){if(a<3){target.copyWithin(position+3,position+2,position+2+u)}target[position++]=121;target[position++]=u>>8;target[position++]=u&255}else{if(a<5){target.copyWithin(position+5,position+3,position+3+u)}target[position++]=122;targetView.setUint32(position,u);position+=4}position+=u}else if(e==="number"){if(!this.alwaysUseFloat&&o>>>0===o){if(o<24){target[position++]=o}else if(o<256){target[position++]=24;target[position++]=o}else if(o<65536){target[position++]=25;target[position++]=o>>8;target[position++]=o&255}else{target[position++]=26;targetView.setUint32(position,o);position+=4}}else if(!this.alwaysUseFloat&&o>>0===o){if(o>=-24){target[position++]=31-o}else if(o>=-256){target[position++]=56;target[position++]=~o}else if(o>=-65536){target[position++]=57;targetView.setUint16(position,~o);position+=2}else{target[position++]=58;targetView.setUint32(position,~o);position+=4}}else{let t;if((t=this.useFloat32)>0&&o<4294967296&&o>=-2147483648){target[position++]=250;targetView.setFloat32(position,o);let e;if(t<4||(e=o*mult10[(target[position]&127)<<1|target[position+1]>>7])>>0===e){position+=4;return}else position--}target[position++]=251;targetView.setFloat64(position,o);position+=8}}else if(e==="object"){if(!o)target[position++]=246;else{if(n){let t=n.get(o);if(t){target[position++]=216;target[position++]=29;target[position++]=25;if(!t.references){let e=n.idsToInsert||(n.idsToInsert=[]);t.references=[];e.push(t)}t.references.push(position-s);position+=2;return}else n.set(o,{offset:position-s})}let e=o.constructor;if(e===Object){g(o,true)}else if(e===Array){u=o.length;if(u<24){target[position++]=128|u}else{writeArrayHeader(u)}for(let e=0;e>8;target[position++]=u&255}else{target[position++]=186;targetView.setUint32(position,u);position+=4}if(a.keyMap){for(let[e,t]of o){b(a.encodeKey(e));b(t)}}else{for(let[e,t]of o){b(e);b(t)}}}else{for(let r=0,e=extensions.length;r>8;target[position++]=t&255}else if(t>-1){target[position++]=218;targetView.setUint32(position,t);position+=4}e.encode.call(this,o,b,w);return}}if(o[Symbol.iterator]){if(throwOnIterable){let e=new Error("Iterable should be serialized as iterator");e.iteratorNotHandled=true;throw e}target[position++]=159;for(let e of o){b(e)}target[position++]=255;return}if(o[Symbol.asyncIterator]||isBlob(o)){let e=new Error("Iterable/blob should be serialized as iterator");e.iteratorNotHandled=true;throw e}if(this.useToJSON&&o.toJSON){const t=o.toJSON();if(t!==o)return b(t)}g(o,!o.hasOwnProperty)}}}else if(e==="boolean"){target[position++]=o?245:244}else if(e==="bigint"){if(o=0){target[position++]=27;targetView.setBigUint64(position,o)}else if(o>-(BigInt(1)<{let t=Object.keys(e);let r=Object.values(e);let n=t.length;if(n<24){target[position++]=160|n}else if(n<256){target[position++]=184;target[position++]=n}else if(n<65536){target[position++]=185;target[position++]=n>>8;target[position++]=n&255}else{target[position++]=186;targetView.setUint32(position,n);position+=4}if(a.keyMap){for(let e=0;e{target[position++]=185;let e=position-s;position+=2;let n=0;if(a.keyMap){for(let e in t)if(r||t.hasOwnProperty(e)){b(a.encodeKey(e));b(t[e]);n++}}else{for(let e in t)if(r||t.hasOwnProperty(e)){b(e);b(t[e]);n++}}target[e+++s]=n>>8;target[e+s]=n&255}:(t,r)=>{let n,i=f.transitions||(f.transitions=Object.create(null));let a=0;let o=0;let u;let s;if(this.keyMap){s=Object.keys(t).map(e=>this.encodeKey(e));o=s.length;for(let t=0;t>8|224;target[position++]=c&255}else{if(!s)s=i.__keys__||(i.__keys__=Object.keys(t));if(u===undefined){c=f.nextId++;if(!c){c=0;f.nextId=1}if(c>=MAX_STRUCTURES){f.nextId=(c=_)+1}}else{c=u}f[c]=s;if(c<_){target[position++]=217;target[position++]=c>>8|224;target[position++]=c&255;i=f.transitions;for(let e=0;e=MAX_STRUCTURES-_)m.shift()[RECORD_SYMBOL]=undefined;m.push(i);writeArrayHeader(o+2);b(57344+c);b(s);if(r===null)return;for(let e in t)if(r||t.hasOwnProperty(e))b(t[e]);return}}if(o<24){target[position++]=128|o}else{writeArrayHeader(o)}if(r===null)return;for(let e in t)if(r||t.hasOwnProperty(e))b(t[e])};const w=e=>{let t;if(e>16777216){if(e-s>MAX_BUFFER_SIZE)throw new Error("Encoded buffer would be larger than maximum buffer size");t=Math.min(MAX_BUFFER_SIZE,Math.round(Math.max((e-s)*(e>67108864?1.25:2),4194304)/4096)*4096)}else t=(Math.max(e-s<<2,target.length-1)>>12)+1<<12;let r=new ByteArrayAllocate(t);targetView=new DataView(r.buffer,0,t);if(target.copy)target.copy(r,0,s,e);else r.set(target.slice(s,e));position-=s;s=0;safeEnd=r.length-10;return target=r};let D=100;let x=1e3;this.encodeAsIterable=function(e,t){return A(e,t,L)};this.encodeAsAsyncIterable=function(e,t){return A(e,t,F)};function*L(n,i,e){let t=n.constructor;if(t===Object){let r=a.useRecords!==false;if(r)g(n,null);else writeEntityLength(Object.keys(n).length,160);for(let t in n){let e=n[t];if(!r)b(t);if(e&&typeof e==="object"){if(i[t])yield*L(e,i[t]);else yield*E(e,i,t)}else b(e)}}else if(t===Array){let e=n.length;writeArrayHeader(e);for(let t=0;tD)){if(i.element)yield*L(e,i.element);else yield*E(e,i,"element")}else b(e)}}else if(n[Symbol.iterator]){target[position++]=159;for(let e of n){if(e&&(typeof e==="object"||position-s>D)){if(i.element)yield*L(e,i.element);else yield*E(e,i,"element")}else b(e)}target[position++]=255}else if(isBlob(n)){writeEntityLength(n.size,64);yield target.subarray(s,position);yield n;S()}else if(n[Symbol.asyncIterator]){target[position++]=159;yield target.subarray(s,position);yield n;S();target[position++]=255}else{b(n)}if(e&&position>s)yield target.subarray(s,position);else if(position-s>D){yield target.subarray(s,position);S()}}function*E(t,r,n){let i=position-s;try{b(t);if(position-s>D){yield target.subarray(s,position);S()}}catch(e){if(e.iteratorNotHandled){r[n]={};position=s+i;yield*L.call(this,t,r[n])}else throw e}}function S(){D=x;a.encode(null,THROW_ON_ITERABLE)}function A(e,t,r){if(t&&t.chunkThreshold)D=x=t.chunkThreshold;else D=100;if(e&&typeof e==="object"){a.encode(null,THROW_ON_ITERABLE);return r(e,a.iterateProperties||(a.iterateProperties={}),true)}return[a.encode(e)]}async function*F(e,t){for(let r of L(e,t,true)){let e=r.constructor;if(e===ByteArray||e===Uint8Array)yield r;else if(isBlob(r)){let e=r.stream().getReader();let t;while(!(t=await e.read()).done){yield t.value}}else if(r[Symbol.asyncIterator]){for await(let e of r){S();if(e)yield*F(e,t.async||(t.async={}));else yield a.encode(e)}}else{yield r}}}}useBuffer(e){target=e;targetView=new DataView(target.buffer,target.byteOffset,target.byteLength);position=0}clearSharedData(){if(this.structures)this.structures=[];if(this.sharedValues)this.sharedValues=undefined}updateSharedData(){let t=this.sharedVersion||0;this.sharedVersion=t+1;let e=this.structures.slice(0);let r=new SharedData(e,this.sharedValues,this.sharedVersion);let n=this.saveShared(r,e=>(e&&e.version||0)==t);if(n===false){r=this.getShared()||{};this.structures=r.structures||[];this.sharedValues=r.packedValues;this.sharedVersion=r.version;this.structures.nextId=this.structures.length}else{e.forEach((e,t)=>this.structures[t]=e)}return n}}function writeEntityLength(e,t){if(e<24)target[position++]=t|e;else if(e<256){target[position++]=t|24;target[position++]=e}else if(e<65536){target[position++]=t|25;target[position++]=e>>8;target[position++]=e&255}else{target[position++]=t|26;targetView.setUint32(position,e);position+=4}}class SharedData{constructor(e,t,r){this.structures=e;this.packedValues=t;this.version=r}}function writeArrayHeader(e){if(e<24)target[position++]=128|e;else if(e<256){target[position++]=152;target[position++]=e}else if(e<65536){target[position++]=153;target[position++]=e>>8;target[position++]=e&255}else{target[position++]=154;targetView.setUint32(position,e);position+=4}}const BlobConstructor=typeof Blob==="undefined"?function(){}:Blob;function isBlob(e){if(e instanceof BlobConstructor)return true;let t=e[Symbol.toStringTag];return t==="Blob"||t==="File"}function findRepetitiveStrings(r,n){switch(typeof r){case"string":if(r.length>3){if(n.objectMap[r]>-1||n.values.length>=n.maxValues)return;let e=n.get(r);if(e){if(++e.count==2){n.values.push(r)}}else{n.set(r,{count:1});if(n.samplingPackedValues){let e=n.samplingPackedValues.get(r);if(e)e.count++;else n.samplingPackedValues.set(r,{count:1})}}}break;case"object":if(r){if(r instanceof Array){for(let e=0,t=r.length;e=0&&r<4294967296){target[position++]=26;targetView.setUint32(position,r);position+=4}else{target[position++]=251;targetView.setFloat64(position,r);position+=8}}},{tag:258,encode(e,t){let r=Array.from(e);t(r)}},{tag:27,encode(e,t){t([e.name,e.message])}},{tag:27,encode(e,t){t(["RegExp",e.source,e.flags])}},{getTag(e){return e.tag},encode(e,t){t(e.value)}},{encode(e,t,r){writeBuffer(e,r)}},{getTag(e){if(e.constructor===Uint8Array){if(this.tagUint8Array||hasNodeBuffer&&this.tagUint8Array!==false)return 64}},encode(e,t,r){writeBuffer(e,r)}},typedArrayEncoder(68,1),typedArrayEncoder(69,2),typedArrayEncoder(70,4),typedArrayEncoder(71,8),typedArrayEncoder(72,1),typedArrayEncoder(77,2),typedArrayEncoder(78,4),typedArrayEncoder(79,8),typedArrayEncoder(85,4),typedArrayEncoder(86,8),{encode(t,n){let e=t.packedValues||[];let r=t.structures||[];if(e.values.length>0){target[position++]=216;target[position++]=51;writeArrayHeader(4);let r=e.values;n(r);writeArrayHeader(0);writeArrayHeader(0);packedObjectMap=Object.create(sharedPackedObjectMap||null);for(let e=0,t=r.length;e1)e-=4;return{tag:e,encode:function e(t,r){let n=t.byteLength;let i=t.byteOffset||0;let a=t.buffer||t;r(hasNodeBuffer?Buffer$1.from(a,i,n):new Uint8Array(a,i,n))}}}function writeBuffer(e,t){let r=e.byteLength;if(r<24){target[position++]=64+r}else if(r<256){target[position++]=88;target[position++]=r}else if(r<65536){target[position++]=89;target[position++]=r>>8;target[position++]=r&255}else{target[position++]=90;targetView.setUint32(position,r);position+=4}if(position+r>=target.length){t(position+r)}target.set(e.buffer?e:new Uint8Array(e),position);position+=r}function insertIds(n,e){let r;let i=e.length*2;let a=n.length-i;e.sort((e,t)=>e.offset>t.offset?1:-1);for(let r=0;r>8;n[e]=r&255}}while(r=e.pop()){let e=r.offset;n.copyWithin(e+i,e,a);i-=2;let t=e+i;n[t++]=216;n[t++]=28;a=e}return n}function writeBundles(e,t){targetView.setUint32(bundledStrings.position+e,position-bundledStrings.position-e+1);let r=bundledStrings;bundledStrings=null;t(r[0]);t(r[1])}function addExtension(e){if(e.Class){if(!e.encode)throw new Error("Extension has no encode function");extensionClasses.unshift(e.Class);extensions.unshift(e)}addExtension$1(e)}let defaultEncoder=new Encoder({useRecords:false});defaultEncoder.encode;defaultEncoder.encodeAsIterable;defaultEncoder.encodeAsAsyncIterable;const REUSE_BUFFER_MODE=512;const RESET_BUFFER_MODE=1024;const THROW_ON_ITERABLE=2048;var lzjbPack={}; /**@license @@ -42,4 +42,4 @@ function _classApplyDescriptorGet(e,t){if(t.get){return t.get.call(e)}return t.v * Released under BSD-3-Clause License * * build: Wed, 27 Oct 2021 10:43:10 GMT - */Object.defineProperty(lzjbPack,"__esModule",{value:true});const NBBY=8,MATCH_BITS=6,MATCH_MIN=3,MATCH_MAX=(1<r-MATCH_MAX){t[i++]=e[n++];continue}l=(e[n]+13^e[n+1]-13^e[n+2])&LEMPEL_SIZE-1;c=n-f[l]&OFFSET_MASK;f[l]=n;a=n-c;if(a>=0&&a!=n&&e[n]==e[a]&&e[n+1]==e[a+1]&&e[n+2]==e[a+2]){t[o]|=u;for(s=MATCH_MIN;s>NBBY;t[i++]=c;n+=s}else{t[i++]=e[n++]}}console.assert(e.length>=n);return i}function decompress(e,t,r){t=t|0;var n=0,i=0,a=0,o=0,u=1<<(NBBY-1|0),s=0,c=0;while(n>(NBBY-MATCH_BITS|0))+MATCH_MIN|0;c=(e[n]<4){r[i]=r[a];i=i+1|0;a=a+1|0;r[i]=r[a];i=i+1|0;a=a+1|0;r[i]=r[a];i=i+1|0;a=a+1|0;r[i]=r[a];i=i+1|0;a=a+1|0;s=s-4|0}while(s>0){r[i]=r[a];i=i+1|0;a=a+1|0;s=s-1|0}}}else{r[i]=e[n];i=i+1|0;n=n+1|0}}return i}function encode_magic$1(){const e=new TextEncoder("utf-8");return e.encode(MAGIC_STRING)}const MAGIC_STRING="@lzjb";const MAGIC=encode_magic$1();function merge_uint8_array$1(...e){if(e.length>1){const r=e.reduce((e,t)=>e+t.length,0);const n=new Uint8Array(r);let t=0;e.forEach(e=>{n.set(e,t);t+=e.length});return n}else if(e.length){return e[0]}}function number_to_bytes(t){const e=Math.ceil(Math.log2(t)/8);const r=new Uint8Array(e);for(let e=0;e=0;e--){r=r*256+t[e]}return r}function pack(e,{magic:t=true}={}){const r=new Uint8Array(Math.max(e.length*1.5|0,16*1024));const n=compress(e,r);const i=number_to_bytes(e.length);const a=[Uint8Array.of(i.length),i,r.slice(0,n)];if(t){a.unshift(MAGIC)}return merge_uint8_array$1(...a)}function unpack(t,{magic:e=true}={}){if(e){const e=new TextDecoder("utf-8");const s=e.decode(t.slice(0,MAGIC.length));if(s!==MAGIC_STRING){throw new Error("Invalid magic value")}}const r=e?MAGIC.length:0;const n=t[r];const i=r+1;const a=r+n+1;const o=bytes_to_number(t.slice(i,a));t=t.slice(a);const u=new Uint8Array(o);decompress(t,t.length,u);return u}var pack_1=lzjbPack.pack=pack;var unpack_1=lzjbPack.unpack=unpack;function unfetch(s,c){return c=c||{},new Promise(function(e,t){var r=new XMLHttpRequest,n=[],i=[],a={},o=function(){return{ok:2==(r.status/100|0),statusText:r.statusText,status:r.status,url:r.responseURL,text:function(){return Promise.resolve(r.responseText)},json:function(){return Promise.resolve(r.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([r.response]))},clone:o,headers:{keys:function(){return n},entries:function(){return i},get:function(e){return a[e.toLowerCase()]},has:function(e){return e.toLowerCase()in a}}}};for(var u in r.open(c.method||"get",s,!0),r.onload=function(){r.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,t,r){n.push(t=t.toLowerCase()),i.push([t,r]),a[t]=a[t]?a[t]+","+r:r}),e(o())},r.onerror=t,r.withCredentials="include"==c.credentials,c.headers)r.setRequestHeader(u,c.headers[u]);r.send(c.body||null)})}var _excluded=["token"],_excluded2=["env"],_excluded3=["stderr","stdin","stdout","command_line"],_excluded4=["use_dynamic"],_excluded5=["use_dynamic"],_excluded6=["env","dynamic_env","use_dynamic","error"];function _classPrivateFieldInitSpec(e,t,r){_checkPrivateRedeclaration(e,t);t.set(e,r)}function _checkPrivateRedeclaration(e,t){if(t.has(e)){throw new TypeError("Cannot initialize the same private elements twice on an object")}}function _callSuper(e,t,r){return t=_getPrototypeOf(t),_possibleConstructorReturn(e,_isNativeReflectConstruct()?Reflect.construct(t,r||[],_getPrototypeOf(e).constructor):t.apply(e,r))}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(_isNativeReflectConstruct=function e(){return!!t})()}function _createForOfIteratorHelper(t,e){var r=typeof Symbol!=="undefined"&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=_unsupportedIterableToArray(t))||e&&t&&typeof t.length==="number"){if(r)t=r;var n=0;var i=function e(){};return{s:i,n:function e(){if(n>=t.length)return{done:true};return{done:false,value:t[n++]}},e:function e(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a=true,o=false,u;return{s:function e(){r=r.call(t)},n:function e(){var t=r.next();a=t.done;return t},e:function e(t){o=true;u=t},f:function e(){try{if(!a&&r["return"]!=null)r["return"]()}finally{if(o)throw u}}}}function _unsupportedIterableToArray(e,t){if(!e)return;if(typeof e==="string")return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor)r=e.constructor.name;if(r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return _arrayLikeToArray(e,t)}function _arrayLikeToArray(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r1?r-1:0),i=1;i0&&arguments[0]!==undefined?arguments[0]:null;var t=user_env&&user_env.get("DEBUG",{throwError:false});if(e===null){return t===true}return(t===null||t===void 0?void 0:t.valueOf())===e.valueOf()}function num_mnemicic_re(e){return e?"(?:#".concat(e,"(?:#[ie])?|#[ie]#").concat(e,")"):"(?:#[ie])?"}function gen_rational_re(e,t){return"".concat(num_mnemicic_re(e),"[+-]?").concat(t,"+/").concat(t,"+")}function gen_complex_re(e,t){return"".concat(num_mnemicic_re(e),"(?:[+-]?(?:").concat(t,"+/").concat(t,"+|nan.0|inf.0|").concat(t,"+))?(?:[+-]i|[+-]?(?:").concat(t,"+/").concat(t,"+|").concat(t,"+|nan.0|inf.0)i)(?=[()[\\]\\s]|$)")}function gen_integer_re(e,t){return"".concat(num_mnemicic_re(e),"[+-]?").concat(t,"+")}var re_re=/^#\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimyus]*)$/;var float_stre="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)";var complex_float_stre="(?:#[ie])?(?:[+-]?(?:[0-9]+/[0-9]+|nan.0|inf.0|".concat(float_stre,"|[+-]?[0-9]+))?(?:").concat(float_stre,"|[+-](?:[0-9]+/[0-9]+|[0-9]+|nan.0|inf.0))i");var float_re=new RegExp("^(#[ie])?".concat(float_stre,"$"),"i");function make_complex_match_re(e,t){var r=e==="x"?"(?!\\+|".concat(t,")"):"(?!\\.|".concat(t,")");var n="";if(e===""){n="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+(?![0-9]))(?:[eE][-+]?[0-9]+)?))"}return new RegExp("^((?:(?:".concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(t,"+/").concat(t,"+(?!").concat(t,")|[+-]?").concat(t,"+)").concat(r,")?)(").concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(t,"+/").concat(t,"+|[+-]?").concat(t,"+|[+-])i$"),"i")}var complex_list_re=function(){var a={};[[10,"","[0-9]"],[16,"x","[0-9a-fA-F]"],[8,"o","[0-7]"],[2,"b","[01]"]].forEach(function(e){var t=_slicedToArray(e,3),r=t[0],n=t[1],i=t[2];a[r]=make_complex_match_re(n,i)});return a}();var characters={alarm:"",backspace:"\b",delete:"",escape:"",newline:"\n",null:"\0",return:"\r",space:" ",tab:"\t",dle:"",soh:"",dc1:"",stx:"",dc2:"",etx:"",dc3:"",eot:"",dc4:"",enq:"",nak:"",ack:"",syn:"",bel:"",etb:"",bs:"\b",can:"",ht:"\t",em:"",lf:"\n",sub:"",vt:"\v",esc:"",ff:"\f",fs:"",cr:"\r",gs:"",so:"",rs:"",si:"",us:"",del:""};function ucs2decode(e){var t=[];var r=0;var n=e.length;while(r=55296&&i<=56319&&r1&&arguments[1]!==undefined?arguments[1]:10;var r=num_pre_parse(e);var n=r.number.split("/");var i=LRational({num:LNumber([n[0],r.radix||t]),denom:LNumber([n[1],r.radix||t])});if(r.inexact){return i.valueOf()}else{return i}}function parse_integer(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;var r=num_pre_parse(e);if(r.inexact){return LFloat(parseInt(r.number,r.radix||t))}return LNumber([r.number,r.radix||t])}function parse_character(e){var t=e.match(/#\\x([0-9a-f]+)$/i);var r;if(t){var n=parseInt(t[1],16);r=String.fromCodePoint(n)}else{t=e.match(/#\\([\s\S]+)$/);if(t){r=t[1]}}if(r){return LCharacter(r)}throw new Error("Parse: invalid character")}function parse_complex(e){var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;function t(e){var t;if(e==="+"){t=LNumber(1)}else if(e==="-"){t=LNumber(-1)}else if(e.match(int_bare_re)){t=LNumber([e,i])}else if(e.match(rational_bare_re)){var r=e.split("/");t=LRational({num:LNumber([r[0],i]),denom:LNumber([r[1],i])})}else if(e.match(float_re)){var n=parse_float(e);if(a.exact){return n.toRational()}return n}else if(e.match(/nan.0$/)){return LNumber(NaN)}else if(e.match(/inf.0$/)){if(e[0]==="-"){return LNumber(Number.NEGATIVE_INFINITY)}return LNumber(Number.POSITIVE_INFINITY)}else{throw new Error("Internal Parser Error")}if(a.inexact){return LFloat(t.valueOf())}return t}var a=num_pre_parse(e);i=a.radix||i;var r;var n=a.number.match(complex_bare_match_re);if(i!==10&&n){r=n}else{r=a.number.match(complex_list_re[i])}var o,u;u=t(r[2]);if(r[1]){o=t(r[1])}else{o=LNumber(0)}if(u.cmp(0)===0&&u.__type__==="bigint"){return o}return LComplex({im:u,re:o})}function is_int(e){return parseInt(e.toString(),10)===e}function parse_big_int(e){var t=e.match(/^(([-+]?[0-9]*)(?:\.([0-9]+))?)e([-+]?[0-9]+)/i);if(t){var r=parseInt(t[4],10);var n;var i=t[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var a=t[3]&&t[3].length;if(i0&&(t.exact||!t.number.match(/\./))){return LNumber(a).mul(u)}}}r=LFloat(r);if(t.exact){return r.toRational()}return r}function parse_string(e){e=e.replace(/\\x([0-9a-f]+);/gi,function(e,t){return"\\u"+t.padStart(4,"0")}).replace(/\n/g,"\\n");var t=e.match(/(\\*)(\\x[0-9A-F])/i);if(t&&t[1].length%2===0){throw new Error("Invalid string literal, unclosed ".concat(t[2]))}try{var r=LString(JSON.parse(e));r.freeze();return r}catch(e){var n=e.message.replace(/in JSON /,"").replace(/.*Error: /,"");throw new Error("Invalid string literal: ".concat(n))}}function parse_symbol(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var r={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,t){return String.fromCharCode(parseInt("0"+t,16))}).replace(/\\(.)/g,function(e,t){return r[t]||t})}return new LSymbol(e)}function parse_argument(e){if(constants.hasOwnProperty(e)){return constants[e]}if(e.match(/^"[\s\S]*"$/)){return parse_string(e)}else if(e[0]==="#"){var t=e.match(re_re);if(t){return new RegExp(t[1],t[2])}else if(e.match(char_re)){return parse_character(e)}var r=e.match(/#\\(.+)/);if(r&&ucs2decode(r[1]).length===1){return parse_character(e)}}if(e.match(/[0-9a-f]|[+-]i/i)){if(e.match(int_re)){return parse_integer(e)}else if(e.match(float_re)){return parse_float(e)}else if(e.match(rational_re)){return parse_rational(e)}else if(e.match(complex_re)){return parse_complex(e)}}if(e.match(/^#[iexobd]/)){throw new Error("Invalid numeric constant: "+e)}return parse_symbol(e)}function is_atom_string(e){return!(["(",")","[","]"].includes(e)||specials.names().includes(e))}function is_symbol_string(e){return is_atom_string(e)&&!(e.match(re_re)||e.match(/^"[\s\S]*"$/)||e.match(int_re)||e.match(float_re)||e.match(complex_re)||e.match(rational_re)||e.match(char_re)||["#t","#f","nil"].includes(e))}var string_re=/"(?:\\[\S\s]|[^"])*"?/g;function escape_regex(e){if(typeof e==="string"){var t=/([-\\^$[\]()+{}?*.|])/g;return e.replace(t,"\\$1")}return e}function Stack(){this.data=[]}Stack.prototype.push=function(e){this.data.push(e)};Stack.prototype.top=function(){return this.data[this.data.length-1]};Stack.prototype.pop=function(){return this.data.pop()};Stack.prototype.is_empty=function(){return!this.data.length};function tokens(e){if(e instanceof LString){e=e.valueOf()}var t=new Lexer(e,{whitespace:true});var r=[];while(true){var n=t.peek(true);if(n===eof){break}r.push(n);t.skip()}return r}function multiline_formatter(e){var t=e.token,r=_objectWithoutProperties(e,_excluded);if(t.match(/^"[\s\S]*"$/)&&t.match(/\n/)){var n=new RegExp("^ {1,"+(e.col+1)+"}","mg");t=t.replace(n,"")}return _objectSpread({token:t},r)}function Thunk(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(){};this.fn=e;this.cont=t}Thunk.prototype.toString=function(){return"#"};function trampoline(n){return function(){for(var e=arguments.length,t=new Array(e),r=0;r1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof LString){e=e.toString()}if(t){return tokens(e)}else{var r=tokens(e).map(function(e){if(e.token==="#\\ "||e.token=="#\\\n"){return e.token}return e.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return strip_s_comments(r)}}function strip_s_comments(e){var t=0;var r=null;var n=[];for(var i=0;i0&&arguments[0]!==undefined?arguments[0]:null;if(e instanceof LSymbol){if(e.is_gensym()){return e}e=e.valueOf()}if(is_gensym(e)){return LSymbol(e)}if(e!==null){return r(e,Symbol("#:".concat(e)))}t++;return r(t,Symbol("#:g".concat(t)))}}();function QuotedPromise(e){var r=this;var n={pending:true,rejected:false,fulfilled:false,reason:undefined,type:undefined};e=e.then(function(e){n.type=type(e);n.fulfilled=true;n.pending=false;return e});read_only(this,"_promise",e,{hidden:true});if(is_function(e["catch"])){e=e["catch"](function(e){n.rejected=true;n.pending=false;n.reason=e})}Object.keys(n).forEach(function(t){Object.defineProperty(r,"__".concat(t,"__"),{enumerable:true,get:function e(){return n[t]}})});read_only(this,"__promise__",e);this.then=false}QuotedPromise.prototype.then=function(e){return new QuotedPromise(this.valueOf().then(e))};QuotedPromise.prototype["catch"]=function(e){return new QuotedPromise(this.valueOf()["catch"](e))};QuotedPromise.prototype.valueOf=function(){if(!this._promise){throw new Error("QuotedPromise: invalid promise created")}return this._promise};QuotedPromise.prototype.toString=function(){if(this.__pending__){return QuotedPromise.pending_str}if(this.__rejected__){return QuotedPromise.rejected_str}return"#")};QuotedPromise.pending_str="#";QuotedPromise.rejected_str="#";function promise_all(e){if(Array.isArray(e)){return Promise.all(escape_quoted_promises(e)).then(unescape_quoted_promises)}return e}function escape_quoted_promises(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof QuotedPromise){t[r]=new Value(n)}else{t[r]=n}}return t}function unescape_quoted_promises(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof Value){t[r]=n.valueOf()}else{t[r]=n}}return t}var specials={LITERAL:Symbol["for"]("literal"),SPLICE:Symbol["for"]("splice"),SYMBOL:Symbol["for"]("symbol"),names:function e(){return Object.keys(this.__list__)},type:function e(t){try{return this.get(t).type}catch(e){console.log({name:t});console.log(e);return null}},get:function e(t){return this.__list__[t]},off:function e(t){var r=this;var n=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(Array.isArray(t)){t.forEach(function(e){return r.off(e,n)})}else if(n===null){delete this.__events__[t]}else{this.__events__=this.__events__.filter(function(e){return e!==n})}},on:function e(t,r){var n=this;if(Array.isArray(t)){t.forEach(function(e){return n.on(e,r)})}else if(!this.__events__[t]){this.__events__[t]=[r]}else{this.__events__[t].push(r)}},trigger:function e(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i",new LSymbol("quote-promise"),specials.LITERAL]];var builtins=defined_specials.map(function(e){return e[0]});Object.freeze(builtins);Object.defineProperty(specials,"__builtins__",{writable:false,value:builtins});defined_specials.forEach(function(e){var t=_slicedToArray(e,3),r=t[0],n=t[1],i=t[2];specials.append(r,n,i)});var Lexer=function(){function p(e){var t=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=r.whitespace,i=n===void 0?false:n;_classCallCheck(this,p);read_only(this,"__input__",e.replace(/\r/g,""));var a={};["_i","_whitespace","_col","_newline","_line","_state","_next","_token","_prev_char"].forEach(function(r){Object.defineProperty(t,r,{configurable:false,enumerable:false,get:function e(){return a[r]},set:function e(t){a[r]=t}})});this._whitespace=i;this._i=this._line=this._col=this._newline=0;this._state=this._next=this._token=null;this._prev_char=""}_createClass(p,[{key:"get",value:function e(t){return this.__internal[t]}},{key:"set",value:function e(t,r){this.__internal[t]=r}},{key:"token",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(t){var r=this._line;if(this._whitespace&&this._token==="\n"){--r}return{token:this._token,col:this._col,offset:this._i,line:r}}return this._token}},{key:"peek",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(this._i>=this.__input__.length){return eof}if(this._token){return this.token(t)}var r=this.next_token();if(r){this._token=this.__input__.substring(this._i,this._next);return this.token(t)}return eof}},{key:"skip",value:function e(){if(this._next!==null){this._token=null;this._i=this._next}}},{key:"read_line",value:function e(){var t=this.__input__.length;if(this._i>=t){return eof}for(var r=this._i;r=r){return eof}if(t+this._i>=r){return this.read_rest()}var n=this._i+t;var i=this.__input__.substring(this._i,n);var a=i.match(/\n/g);if(a){this._line+=a.length}this._i=n;return i}},{key:"peek_char",value:function e(){if(this._i>=this.__input__.length){return eof}return LCharacter(this.__input__[this._i])}},{key:"read_char",value:function e(){var t=this.peek_char();this.skip_char();return t}},{key:"skip_char",value:function e(){if(this._i1&&arguments[1]!==undefined?arguments[1]:{},n=r.prev_char,i=r["char"],a=r.next_char;var o=_slicedToArray(t,4),u=o[0],s=o[1],c=o[2],l=o[3];if(t.length!==5){throw new Error("Lexer: Invalid rule of length ".concat(t.length))}if(is_string(u)){if(u!==i){return false}}else if(!i.match(u)){return false}if(!match_or_null(s,n)){return false}if(!match_or_null(c,a)){return false}if(l!==this._state){return false}return true}},{key:"next_token",value:function e(){if(this._i>=this.__input__.length){return false}var t=true;e:for(var r=this._i,n=this.__input__.length;r2&&arguments[2]!==undefined?arguments[2]:null;var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;if(t.length===0){throw new Error("Lexer: invalid literal rule")}if(t.length===1){return[[t,n,i,null,null]]}var a=[];for(var o=0,u=t.length;o1&&arguments[1]!==undefined?arguments[1]:{},r=t.env,n=t.meta,i=n===void 0?false:n,a=t.formatter,o=a===void 0?multiline_formatter:a;_classCallCheck(this,u);if(e instanceof LString){e=e.toString()}read_only(this,"_formatter",o,{hidden:true});read_only(this,"__lexer__",new Lexer(e));read_only(this,"__env__",r);read_only(this,"_meta",i,{hidden:true});read_only(this,"_refs",[],{hidden:true});read_only(this,"_state",{parentheses:0},{hidden:true})}_createClass(u,[{key:"resolve",value:function e(t){return this.__env__&&this.__env__.get(t,{throwError:false})}},{key:"peek",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var r;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=this.__lexer__.peek(true);if(!(r===eof)){t.next=4;break}return t.abrupt("return",eof);case 4:if(!this.is_comment(r.token)){t.next=7;break}this.skip();return t.abrupt("continue",0);case 7:if(!(r.token==="#;")){t.next=14;break}this.skip();if(!(this.__lexer__.peek()===eof)){t.next=11;break}throw new Error("Lexer: syntax error eof found after comment");case 11:t.next=13;return this._read_object();case 13:return t.abrupt("continue",0);case 14:return t.abrupt("break",17);case 17:r=this._formatter(r);if(!this._meta){t.next=20;break}return t.abrupt("return",r);case 20:return t.abrupt("return",r.token);case 21:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"reset",value:function e(){this._refs.length=0}},{key:"skip",value:function e(){this.__lexer__.skip()}},{key:"read",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var r;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return this.peek();case 2:r=t.sent;this.skip();return t.abrupt("return",r);case 5:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"match_datum_label",value:function e(t){var r=t.match(/^#([0-9]+)=$/);return r&&r[1]}},{key:"match_datum_ref",value:function e(t){var r=t.match(/^#([0-9]+)#$/);return r&&r[1]}},{key:"is_open",value:function e(t){var r=["(","["].includes(t);if(r){this._state.parentheses++}return r}},{key:"is_close",value:function e(t){var r=[")","]"].includes(t);if(r){this._state.parentheses--}return r}},{key:"read_list",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var r,n,i,a,o;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=_nil,n=r;case 1:t.next=4;return this.peek();case 4:a=t.sent;if(!(a===eof)){t.next=7;break}return t.abrupt("break",32);case 7:if(!this.is_close(a)){t.next=10;break}this.skip();return t.abrupt("break",32);case 10:if(!(a==="."&&!is_nil(r))){t.next=18;break}this.skip();t.next=14;return this._read_object();case 14:n.cdr=t.sent;i=true;t.next=30;break;case 18:if(!i){t.next=22;break}throw new Error("Parser: syntax error more than one element after dot");case 22:t.t0=Pair;t.next=25;return this._read_object();case 25:t.t1=t.sent;t.t2=_nil;o=new t.t0(t.t1,t.t2);if(is_nil(r)){r=o}else{n.cdr=o}n=o;case 30:t.next=1;break;case 32:return t.abrupt("return",r);case 33:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"read_value",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var r;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return this.read();case 2:r=t.sent;if(!(r===eof)){t.next=5;break}throw new Error("Parser: Expected token eof found");case 5:return t.abrupt("return",parse_argument(r));case 6:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"is_comment",value:function e(t){return t.match(/^;/)||t.match(/^#\|/)&&t.match(/\|#$/)}},{key:"evaluate",value:function e(t){return _evaluate(t,{env:this.__env__,error:function e(t){throw t}})}},{key:"read_object",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var r;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:this.reset();t.next=3;return this._read_object();case 3:r=t.sent;if(r instanceof DatumReference){r=r.valueOf()}if(!this._refs.length){t.next=7;break}return t.abrupt("return",unpromise(this._resolve_object(r),function(e){if(is_pair(e)){e.mark_cycles()}return e}));case 7:return t.abrupt("return",r);case 8:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"balanced",value:function e(){return this._state.parentheses===0}},{key:"ballancing_error",value:function e(t,r){var n=this._state.parentheses;var i;if(n<0){i=new Error("Parser: unexpected parenthesis");i.__code__=[r.toString()+")"]}else{i=new Error("Parser: expected parenthesis but eof found");var a=new RegExp("\\){".concat(n,"}$"));i.__code__=[t.toString().replace(a,"")]}throw i}},{key:"_resolve_object",value:function(){var t=_asyncToGenerator(_regeneratorRuntime.mark(function e(r){var n=this;var i;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!Array.isArray(r)){t.next=2;break}return t.abrupt("return",r.map(function(e){return n._resolve_object(e)}));case 2:if(!is_plain_object(r)){t.next=6;break}i={};Object.keys(r).forEach(function(e){i[e]=n._resolve_object(r[e])});return t.abrupt("return",i);case 6:if(!is_pair(r)){t.next=8;break}return t.abrupt("return",this._resolve_pair(r));case 8:return t.abrupt("return",r);case 9:case"end":return t.stop()}},e,this)}));function e(e){return t.apply(this,arguments)}return e}()},{key:"_resolve_pair",value:function(){var t=_asyncToGenerator(_regeneratorRuntime.mark(function e(r){return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!is_pair(r)){t.next=15;break}if(!(r.car instanceof DatumReference)){t.next=7;break}t.next=4;return r.car.valueOf();case 4:r.car=t.sent;t.next=8;break;case 7:this._resolve_pair(r.car);case 8:if(!(r.cdr instanceof DatumReference)){t.next=14;break}t.next=11;return r.cdr.valueOf();case 11:r.cdr=t.sent;t.next=15;break;case 14:this._resolve_pair(r.cdr);case 15:return t.abrupt("return",r);case 16:case"end":return t.stop()}},e,this)}));function e(e){return t.apply(this,arguments)}return e}()},{key:"_read_object",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var r,n,i,a,o,u,s,c,l,f,_;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return this.peek();case 2:r=t.sent;if(!(r===eof)){t.next=5;break}return t.abrupt("return",r);case 5:if(!is_special(r)){t.next=38;break}n=specials.get(r);i=is_builtin(r);this.skip();o=is_symbol_extension(r);if(!o){t.next=14;break}t.t0=undefined;t.next=17;break;case 14:t.next=16;return this._read_object();case 16:t.t0=t.sent;case 17:u=t.t0;if(i){t.next=25;break}s=this.__env__.get(n.symbol);if(!(typeof s==="function")){t.next=25;break}if(is_literal(r)){c=[u]}else if(is_nil(u)){c=[]}else if(is_pair(u)){c=u.to_array(false)}if(!(c||o)){t.next=24;break}return t.abrupt("return",call_function(s,o?[]:c,{env:this.__env__,dynamic_env:this.__env__,use_dynamic:false}));case 24:throw new Error("Parse Error: Invalid parser extension "+"invocation ".concat(n.symbol));case 25:if(is_literal(r)){a=new Pair(n.symbol,new Pair(u,_nil))}else{a=new Pair(n.symbol,u)}if(!i){t.next=28;break}return t.abrupt("return",a);case 28:if(!(s instanceof Macro)){t.next=37;break}t.next=31;return this.evaluate(a);case 31:l=t.sent;if(!(is_pair(l)||l instanceof LSymbol)){t.next=34;break}return t.abrupt("return",Pair.fromArray([LSymbol("quote"),l]));case 34:return t.abrupt("return",l);case 37:throw new Error("Parse Error: invalid parser extension: "+n.symbol);case 38:f=this.match_datum_ref(r);if(!(f!==null)){t.next=44;break}this.skip();if(!this._refs[f]){t.next=43;break}return t.abrupt("return",new DatumReference(f,this._refs[f]));case 43:throw new Error("Parse Error: invalid datum label #".concat(f,"#"));case 44:_=this.match_datum_label(r);if(!(_!==null)){t.next=51;break}this.skip();this._refs[_]=this._read_object();return t.abrupt("return",this._refs[_]);case 51:if(!this.is_close(r)){t.next=55;break}this.skip();t.next=61;break;case 55:if(!this.is_open(r)){t.next=60;break}this.skip();return t.abrupt("return",this.read_list());case 60:return t.abrupt("return",this.read_value());case 61:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()}]);return u}();var DatumReference=function(){function r(e,t){_classCallCheck(this,r);this.name=e;this.data=t}_createClass(r,[{key:"valueOf",value:function e(){return this.data}}]);return r}();function _parse(e,t){return _parse2.apply(this,arguments)}function _parse2(){_parse2=_wrapAsyncGenerator(_regeneratorRuntime.mark(function e(r,n){var i,a,o;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!n){if(global_env){n=global_env.get("**interaction-environment**",{throwError:false})}else{n=user_env}}i=new Parser(r,{env:n});case 3:t.next=6;return _awaitAsyncGenerator(i.read_object());case 6:o=t.sent;if(!i.balanced()){i.ballancing_error(o,a)}if(!(o===eof)){t.next=10;break}return t.abrupt("break",15);case 10:a=o;t.next=13;return o;case 13:t.next=3;break;case 15:case"end":return t.stop()}},e)}));return _parse2.apply(this,arguments)}function unpromise(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(e){return e};var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;if(is_promise(e)){var n=e.then(t);if(r===null){return n}else{return n["catch"](r)}}if(e instanceof Array){return unpromise_array(e,t,r)}if(is_plain_object(e)){return unpromise_object(e,t,r)}return t(e)}function unpromise_array(t,r,e){if(t.find(is_promise)){return unpromise(promise_all(t),function(e){if(Object.isFrozen(t)){Object.freeze(e)}return r(e)},e)}return r(t)}function unpromise_object(t,e,r){var i=Object.keys(t);var n=[],a=[];var o=i.length;while(o--){var u=i[o];var s=t[u];n[o]=s;if(is_promise(s)){a.push(s)}}if(a.length){return unpromise(promise_all(n),function(e){var n={};e.forEach(function(e,t){var r=i[t];n[r]=e});if(Object.isFrozen(t)){Object.freeze(n)}return n},r)}return e(t)}function read_only(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{},i=n.hidden,a=i===void 0?false:i;Object.defineProperty(e,t,{value:r,configurable:true,enumerable:!a})}function uniterate_async(e){return _uniterate_async.apply(this,arguments)}function _uniterate_async(){_uniterate_async=_asyncToGenerator(_regeneratorRuntime.mark(function e(r){var n,i,a,o,u,s,c;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:n=[];i=false;a=false;t.prev=3;u=_asyncIterator(r);case 5:t.next=7;return u.next();case 7:if(!(i=!(s=t.sent).done)){t.next=13;break}c=s.value;n.push(c);case 10:i=false;t.next=5;break;case 13:t.next=19;break;case 15:t.prev=15;t.t0=t["catch"](3);a=true;o=t.t0;case 19:t.prev=19;t.prev=20;if(!(i&&u["return"]!=null)){t.next=24;break}t.next=24;return u["return"]();case 24:t.prev=24;if(!a){t.next=27;break}throw o;case 27:return t.finish(24);case 28:return t.finish(19);case 29:return t.abrupt("return",n);case 30:case"end":return t.stop()}},e,null,[[3,15,19,29],[20,,24,28]])}));return _uniterate_async.apply(this,arguments)}function matcher(e,t){if(t instanceof RegExp){return function(e){return String(e).match(t)}}else if(is_function(t)){return t}throw new Error("Invalid matcher")}function doc(e,t,r,n){if(typeof e!=="string"){t=arguments[0];r=arguments[1];n=arguments[2];e=null}if(r){if(n){t.__doc__=r}else{t.__doc__=trim_lines(r)}}if(e){t.__name__=e}else if(t.name&&!is_lambda(t)){t.__name__=t.name}return t}function trim_lines(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function previousSexp(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var r=e.length;if(t<=0){throw Error("previousSexp: Invalid argument sexp = ".concat(t))}e:while(t--&&r>=0){var n=1;while(n>0){var i=e[--r];if(!i){break e}if(i==="("||i.token==="("){n--}else if(i===")"||i.token===")"){n++}}r--}return e.slice(r+1)}function lineIndent(e){if(!e||!e.length){return 0}var t=e.length;if(e[t-1].token==="\n"){return 0}while(--t){if(e[t].token==="\n"){var r=(e[t+1]||{}).token;if(r){return r.length}}}return 0}function match(e,t){return l(e,t)===t.length;function l(r,n){function e(e,t){var r=_createForOfIteratorHelper(e),n;try{for(r.s();!(n=r.n()).done;){var i=n.value;var a=l(i,t);if(a!==-1){return a}}}catch(e){r.e(e)}finally{r.f()}return-1}function t(){return r[a]===Symbol["for"]("symbol")&&!is_symbol_string(n[u])}function i(){var e=r[a+1];var t=n[u+1];if(e!==undefined&&t!==undefined){return l([e],[t])}}var a=0;var o={};for(var u=0;u0){continue}}else if(t()){return-1}}else if(r[a]instanceof Array){var c=l(r[a],n.slice(u));if(c===-1||c+u>n.length){return-1}u+=c-1;a++;continue}else{return-1}a++}if(r.length!==a){return-1}return n.length}}function Formatter(e){this.__code__=e.replace(/\r/g,"")}Formatter.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?(?:define(?:-values|-syntax|-macro|-class|-record-type)?|(?:call-with-(?:input-file|output-file|port))|lambda|let-env|try|catch|when|unless|while|syntax-rules|(let|letrec)(-syntax|\*?-values|\*)?)$/],shift:{1:["&","#"]}}};Formatter.match=match;Formatter.prototype._options=function e(t){var r=Formatter.defaults;if(typeof t==="undefined"){return Object.assign({},r)}var n=t&&t.exceptions||{};var i=n.specials||[];var a=n.shift||{1:[]};return _objectSpread(_objectSpread(_objectSpread({},r),t),{},{exceptions:{specials:[].concat(_toConsumableArray(r.exceptions.specials),_toConsumableArray(i)),shift:_objectSpread(_objectSpread({},a),{},{1:[].concat(_toConsumableArray(r.exceptions.shift[1]),_toConsumableArray(a[1]))})}})};Formatter.prototype.indent=function e(t){var r=tokenize(this.__code__,true);return this._indent(r,t)};Formatter.exception_shift=function(a,e){function t(e){if(!e.length){return false}if(e.indexOf(a)!==-1){return true}else{var t=e.filter(function(e){return e instanceof RegExp});if(!t.length){return false}var r=_createForOfIteratorHelper(t),n;try{for(r.s();!(n=r.n()).done;){var i=n.value;if(a.match(i)){return true}}}catch(e){r.e(e)}finally{r.f()}}return false}if(t(e.exceptions.specials)){return e.indent}var r=e.exceptions.shift;for(var n=0,i=Object.entries(r);n0){n.offset=0}if(a.toString()===t.toString()&&balanced(a)){return n.offset+a[0].col}else if(a.length===1){return n.offset+a[0].col+1}else{var s=-1;if(o){var c=Formatter.exception_shift(o.token,n);if(c!==-1){s=c}}if(s===-1){s=Formatter.exception_shift(a[1].token,n)}if(s!==-1){return n.offset+a[0].col+s}else if(a[0].line3&&a[1].line===a[3].line){if(a[1].token==="("||a[1].token==="["){return n.offset+a[1].col}return n.offset+a[3].col}else if(a[0].line===a[1].line){return n.offset+n.indent+a[0].col}else{var l=a.slice(2);for(var f=0;f")};Ahead.prototype.match=function(e){return e.match(this.pattern)};function Pattern(){for(var e=arguments.length,t=new Array(e),r=0;r")};Formatter.Pattern=Pattern;Formatter.Ahead=Ahead;var p_o=/^[[(]$/;var p_e=/^[\])]$/;var not_p=/[^()[\]]/;var not_close=new Ahead(/[^)\]]/);var glob=Symbol["for"]("*");var sexp_or_atom=new Pattern([p_o,glob,p_e],[not_p],"+");var sexp=new Pattern([p_o,glob,p_e],"+");var symbol=new Pattern([Symbol["for"]("symbol")],"?");var symbols=new Pattern([Symbol["for"]("symbol")],"*");var identifiers=[p_o,symbols,p_e];var let_value=new Pattern([p_o,Symbol["for"]("symbol"),glob,p_e],"+");var syntax_rules=keywords_re("syntax-rules");var def_lambda_re=keywords_re("define","lambda","define-macro","syntax-rules");var non_def=/^(?!.*\b(?:[()[\]]|define(?:-macro)?|let(?:\*|rec|-env|-syntax|)?|lambda|syntax-rules)\b).*$/;var let_re=/^(?:#:)?(let(?:\*|rec|-env|-syntax)?)$/;function keywords_re(){for(var e=arguments.length,t=new Array(e),r=0;r0&&!u[e]){u[e]=previousSexp(o,e)}});var s=_createForOfIteratorHelper(i),c;try{for(s.s();!(c=s.n()).done;){var l=_slicedToArray(c.value,3),f=l[0],_=l[1],p=l[2];_=_.valueOf();var d=_>0?u[_]:o;var h=d.filter(function(e){return e.trim()&&!is_special(e)});var m=r(d);var y=match(f,h);var v=n.slice(a).find(function(e){return e.trim()&&!is_special(e)});if(y&&(p instanceof Ahead&&p.match(v)||!p)){var b=a-m;if(n[b]!=="\n"){if(!n[b].trim()){n[b]="\n"}else{n.splice(b,0,"\n");a++}}a+=m;continue e}}}catch(e){s.e(e)}finally{s.f()}}this.__code__=n.join("");return this};Formatter.prototype._spaces=function(e){return" ".repeat(e)};Formatter.prototype.format=function e(t){var r=this.__code__.replace(/[ \t]*\n[ \t]*/g,"\n ");var n=tokenize(r,true);var i=this._options(t);var a=0;var o=0;for(var u=0;u0){n=Math.floor(t()*r);r--;var i=[e[n],e[r]];e[r]=i[0];e[n]=i[1]}return e}function Nil(){}Nil.prototype.toString=function(){return"()"};Nil.prototype.valueOf=function(){return undefined};Nil.prototype.serialize=function(){return 0};Nil.prototype.to_object=function(){return{}};Nil.prototype.append=function(e){return new Pair(e,_nil)};Nil.prototype.to_array=function(){return[]};var _nil=new Nil;function Pair(e,t){if(typeof this!=="undefined"&&this.constructor!==Pair||typeof this==="undefined"){return new Pair(e,t)}this.car=e;this.cdr=t}function to_array(a,o){return function e(t){typecheck(a,t,["pair","nil"]);if(is_nil(t)){return[]}var r=[];var n=t;while(true){if(is_pair(n)){if(n.have_cycles("cdr")){break}var i=n.car;if(o&&is_pair(i)){i=this.get(a).call(this,i)}r.push(i);n=n.cdr}else if(is_nil(n)){break}else{throw new Error("".concat(a,": can't convert improper list"))}}return r}}Pair.prototype.flatten=function(){return Pair.fromArray(flatten(this.to_array()))};Pair.prototype.length=function(){var e=0;var t=this;while(true){if(!t||is_nil(t)||!is_pair(t)||t.have_cycles("cdr")){break}e++;t=t.cdr}return e};Pair.match=function(e,t){if(e instanceof LSymbol){return LSymbol.is(e,t)}else if(is_pair(e)){return Pair.match(e.car,t)||Pair.match(e.cdr,t)}else if(Array.isArray(e)){return e.some(function(e){return Pair.match(e,t)})}else if(is_plain_object(e)){return Object.values(e).some(function(e){return Pair.match(e,t)})}return false};Pair.prototype.find=function(e){return Pair.match(this,e)};Pair.prototype.clone=function(){var r=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var n=new Map;function i(e){if(is_pair(e)){if(n.has(e)){return n.get(e)}var t=new Pair;n.set(e,t);if(r){t.car=i(e.car)}else{t.car=e.car}t.cdr=i(e.cdr);t[__cycles__]=e[__cycles__];return t}return e}return i(this)};Pair.prototype.last_pair=function(){var e=this;while(true){if(!is_pair(e.cdr)){return e}if(e.have_cycles("cdr")){break}e=e.cdr}};Pair.prototype.to_array=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var t=[];if(is_pair(this.car)){if(e){t.push(this.car.to_array())}else{t.push(this.car)}}else{t.push(this.car.valueOf())}if(is_pair(this.cdr)){t=t.concat(this.cdr.to_array(e))}return t};Pair.fromArray=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(is_pair(e)||r&&e instanceof Array&&e[__data__]){return e}if(t===false){var n=_nil;for(var i=e.length;i--;){n=new Pair(e[i],n)}return n}if(e.length&&!(e instanceof Array)){e=_toConsumableArray(e)}var a=_nil;var o=e.length;while(o--){var u=e[o];if(u instanceof Array){u=Pair.fromArray(u,t,r)}else if(typeof u==="string"){u=LString(u)}else if(typeof u==="number"&&!Number.isNaN(u)){u=LNumber(u)}a=new Pair(u,a)}return a};Pair.prototype.to_object=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var t=this;var r={};while(true){if(is_pair(t)&&is_pair(t.car)){var n=t.car;var i=n.car;if(i instanceof LSymbol){i=i.__name__}if(i instanceof LString){i=i.valueOf()}var a=n.cdr;if(is_pair(a)){a=a.to_object(e)}if(is_native(a)){if(!e){a=a.valueOf()}}r[i]=a;t=t.cdr}else{break}}return r};Pair.fromPairs=function(e){return e.reduce(function(e,t){return new Pair(new Pair(new LSymbol(t[0]),t[1]),e)},_nil)};Pair.fromObject=function(t){var e=Object.keys(t).map(function(e){return[e,t[e]]});return Pair.fromPairs(e)};Pair.prototype.reduce=function(e){var t=this;var r=_nil;while(true){if(!is_nil(t)){r=e(r,t.car);t=t.cdr}else{break}}return r};Pair.prototype.reverse=function(){if(this.have_cycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var t=_nil;while(!is_nil(e)){var r=e.cdr;e.cdr=t;t=e;e=r}return t};Pair.prototype.transform=function(n){function i(e){if(is_pair(e)){if(e.replace){delete e.replace;return e}var t=n(e.car);if(is_pair(t)){t=i(t)}var r=n(e.cdr);if(is_pair(r)){r=i(r)}return new Pair(t,r)}return e}return i(this)};Pair.prototype.map=function(e){if(typeof this.car!=="undefined"){return new Pair(e(this.car),is_nil(this.cdr)?_nil:this.cdr.map(e))}else{return _nil}};var repr=new Map;function is_plain_object(e){return e&&_typeof$1(e)==="object"&&e.constructor===Object}var props=Object.getOwnPropertyNames(Array.prototype);var array_methods=[];props.forEach(function(e){array_methods.push(Array[e],Array.prototype[e])});function is_array_method(e){e=unbind(e);return array_methods.includes(e)}function is_lips_function(e){return is_function(e)&&(is_lambda(e)||e.__doc__)}function user_repr(r){var e=r.constructor||Object;var n=is_plain_object(r);var i=is_function(r[Symbol.asyncIterator])||is_function(r[Symbol.iterator]);var a;if(repr.has(e)){a=repr.get(e)}else{repr.forEach(function(e,t){t=unbind(t);if(r instanceof t&&(t===Object&&n&&!i||t!==Object)){a=e}})}return a}var str_mapping=new Map;[[true,"#t"],[false,"#f"],[null,"null"],[undefined,"#"]].forEach(function(e){var t=_slicedToArray(e,2),r=t[0],n=t[1];str_mapping.set(r,n)});function symbolize(r){if(r&&_typeof$1(r)==="object"){var n={};var e=Object.getOwnPropertySymbols(r);e.forEach(function(e){var t=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");n[t]=toString(r[e])});var t=Object.getOwnPropertyNames(r);t.forEach(function(e){var t=r[e];if(t&&_typeof$1(t)==="object"&&t.constructor===Object){n[e]=symbolize(t)}else{n[e]=toString(t)}});return n}return r}function get_props(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function has_own_function(e,t){return e.hasOwnProperty(t)&&is_function(e.toString)}function function_to_string(e){if(is_native_function(e)){return"#"}var t=e.prototype&&e.prototype.constructor;if(is_function(t)&&is_lambda(t)){if(e[__class__]&&t.hasOwnProperty("__name__")){var r=t.__name__;if(LString.isString(r)){r=r.toString();return"#")}return"#"}}if(e.hasOwnProperty("__name__")){var n=e.__name__;if(_typeof$1(n)==="symbol"){n=symbol_to_string(n)}if(typeof n==="string"){return"#")}}if(has_own_function(e,"toString")){return e.toString()}else if(e.name&&!is_lambda(e)){return"#")}else{return"#"}}var instances=new Map;[[Error,function(e){return e.message}],[Pair,function(e,t){var r=t.quote,n=t.skip_cycles,i=t.pair_args;if(!n){e.mark_cycles()}return e.toString.apply(e,[r].concat(_toConsumableArray(i)))}],[LCharacter,function(e,t){var r=t.quote;if(r){return e.toString()}return e.valueOf()}],[LString,function(e,t){var r=t.quote;e=e.toString();if(r){return JSON.stringify(e).replace(/\\n/g,"\n")}return e}],[RegExp,function(e){return"#"+e.toString()}]].forEach(function(e){var t=_slicedToArray(e,2),r=t[0],n=t[1];instances.set(r,n)});var native_types=[LSymbol,Macro,Values,InputPort,OutputPort,Environment,QuotedPromise];function toString(e,t,r){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(str_mapping.has(e)){return str_mapping.get(e)}if(is_prototype(e)){return"#"}if(e){var n=e.constructor;if(instances.has(n)){for(var i=arguments.length,a=new Array(i>3?i-3:0),o=3;o"}if(e===null){return"null"}if(is_function(e)){if(is_function(e.toString)&&e.hasOwnProperty("toString")){return e.toString().valueOf()}return function_to_string(e)}if(_typeof$1(e)==="object"){var l=e.constructor;if(!l){l=Object}var f;if(typeof l.__class__==="string"){f=l.__class__}else{var _=user_repr(e);if(_){if(is_function(_)){return _(e,t)}else{throw new Error("toString: Invalid repr value")}}f=l.name}if(is_function(e.toString)&&e.hasOwnProperty("toString")){return e.toString().valueOf()}if(type(e)==="instance"){if(is_lambda(l)&&l.__name__){f=l.__name__.valueOf()}else if(!is_native_function(l)){f="instance"}}if(is_iterator(e,Symbol.iterator)){if(f){return"#")}return"#"}if(is_iterator(e,Symbol.asyncIterator)){if(f){return"#")}return"#"}if(f!==""){return"#<"+f+">"}return"#"}if(typeof e!=="string"){return e.toString()}return e}Pair.prototype.mark_cycles=function(){mark_cycles(this);return this};Pair.prototype.have_cycles=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(!e){return this.have_cycles("car")||this.have_cycles("cdr")}return!!(this[__cycles__]&&this[__cycles__][e])};Pair.prototype.is_cycle=function(){return is_cycle(this)};function is_cycle(e){if(!is_pair(e)){return false}if(e.have_cycles()){return true}return is_cycle(e.car,fn)||is_cycle(e.cdr,fn)}function mark_cycles(e){var t=[];var i=[];var a=[];function o(e){if(!t.includes(e)){t.push(e)}}function u(e,t,r,n){if(is_pair(r)){if(n.includes(r)){if(!a.includes(r)){a.push(r)}if(!e[__cycles__]){e[__cycles__]={}}e[__cycles__][t]=r;if(!i.includes(e)){i.push(e)}return true}}}var s=trampoline(function e(t,r){if(is_pair(t)){delete t.ref;delete t[__cycles__];o(t);r.push(t);var n=u(t,"car",t.car,r);var i=u(t,"cdr",t.cdr,r);if(!n){s(t.car,r.slice())}if(!i){return new Thunk(function(){return e(t.cdr,r.slice())})}}});function r(e,t){if(is_pair(e[__cycles__][t])){var r=n.indexOf(e[__cycles__][t]);e[__cycles__][t]="#".concat(r,"#")}}s(e,[]);var n=t.filter(function(e){return a.includes(e)});n.forEach(function(e,t){e[__ref__]="#".concat(t,"=")});i.forEach(function(e){r(e,"car");r(e,"cdr")})}Pair.prototype.toString=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.nested,n=r===void 0?false:r;var i=[];if(this[__ref__]){i.push(this[__ref__]+"(")}else if(!n){i.push("(")}var a;if(this[__cycles__]&&this[__cycles__].car){a=this[__cycles__].car}else{a=toString(this.car,e,true)}if(a!==undefined){i.push(a)}if(is_pair(this.cdr)){if(this[__cycles__]&&this[__cycles__].cdr){i.push(" . ");i.push(this[__cycles__].cdr)}else{if(this.cdr[__ref__]){i.push(" . ")}else{i.push(" ")}var o=this.cdr.toString(e,{nested:true});i.push(o)}}else if(!is_nil(this.cdr)){i=i.concat([" . ",toString(this.cdr,e,true)])}if(!n||this[__ref__]){i.push(")")}return i.join("")};Pair.prototype.set=function(e,t){this[e]=t;if(is_pair(t)){this.mark_cycles()}};Pair.prototype.append=function(e){if(e instanceof Array){return this.append(Pair.fromArray(e))}var t=this;if(t.car===undefined){if(is_pair(e)){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(!is_nil(e)){while(true){if(is_pair(t)&&!is_nil(t.cdr)){t=t.cdr}else{break}}t.cdr=e}return this};Pair.prototype.serialize=function(){return[this.car,this.cdr]};Pair.prototype[Symbol.iterator]=function(){var r=this;return{next:function e(){var t=r;r=t.cdr;if(is_nil(t)){return{value:undefined,done:true}}else{return{value:t.car,done:false}}}}};function abs(e){return e<0?-e:e}function seq_compare(e,t){var r=_toArray(t),n=r[0],i=r.slice(1);while(i.length>0){var a=i,o=_slicedToArray(a,1),u=o[0];if(!e(n,u)){return false}var s=i;var c=_toArray(s);n=c[0];i=c.slice(1)}return true}function equal(e,t){if(is_function(e)){return is_function(t)&&unbind(e)===unbind(t)}else if(e instanceof LNumber){if(!(t instanceof LNumber)){return false}var r;if(e.__type__===t.__type__){if(e.__type__==="complex"){r=e.__im__.__type__===t.__im__.__type__&&e.__re__.__type__===t.__re__.__type__}else{r=true}if(r&&e.cmp(t)===0){if(e.valueOf()===0){return Object.is(e.valueOf(),t.valueOf())}return true}}return false}else if(typeof e==="number"){if(typeof t!=="number"){return false}if(Number.isNaN(e)){return Number.isNaN(t)}if(e===Number.NEGATIVE_INFINITY){return t===Number.NEGATIVE_INFINITY}if(e===Number.POSITIVE_INFINITY){return t===Number.POSITIVE_INFINITY}return equal(LNumber(e),LNumber(t))}else if(e instanceof LCharacter){if(!(t instanceof LCharacter)){return false}return e.__char__===t.__char__}else{return e===t}}function same_atom(e,t){if(type(e)!==type(t)){return false}if(!is_atom(e)){return false}if(e instanceof RegExp){return e.source===t.source}if(e instanceof LString){return e.valueOf()===t.valueOf()}return equal(e,t)}function is_atom(e){return e instanceof LSymbol||LString.isString(e)||is_nil(e)||e===null||e instanceof LCharacter||e instanceof LNumber||e===true||e===false}var truncate=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e===0){return 0}else if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function Macro(e,t,r,n){if(typeof this!=="undefined"&&this.constructor!==Macro||typeof this==="undefined"){return new Macro(e,t)}typecheck("Macro",e,"string",1);typecheck("Macro",t,"function",2);if(r){if(n){this.__doc__=r}else{this.__doc__=trim_lines(r)}}this.__name__=e;this.__fn__=t}Macro.defmacro=function(e,t,r,n){var i=new Macro(e,t,r,n);i.__defmacro__=true;return i};Macro.prototype.invoke=function(e,t,r){var n=t.env,i=_objectWithoutProperties(t,_excluded2);var a=_objectSpread(_objectSpread({},i),{},{macro_expand:r});var o=this.__fn__.call(n,e,a,this.__name__);return o};Macro.prototype.toString=function(){return"#")};var macro="define-macro";var recur_guard=-1e4;function macro_expand(c){return function(){var r=_asyncToGenerator(_regeneratorRuntime.mark(function e(r,v){var a,b,n,i,o,g,w,D,x,L,E,S,u,A,s;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:s=function e(){s=_asyncToGenerator(_regeneratorRuntime.mark(function e(r,n,i){var a,o,u,s,c,l,f,_,p,d,h,m,y;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!(is_pair(r)&&r.car instanceof LSymbol)){t.next=50;break}if(!r[__data__]){t.next=3;break}return t.abrupt("return",r);case 3:a=r.car.valueOf();o=i.get(r.car,{throwError:false});u=g(r.car);s=u||w(o,r)||D(o);if(!(s&&is_pair(r.cdr.car))){t.next=28;break}if(!u){t.next=15;break}b=L(r.cdr.car);t.next=12;return S(r.cdr.car,n);case 12:c=t.sent;t.next=17;break;case 15:b=x(r.cdr.car);c=r.cdr.car;case 17:t.t0=Pair;t.t1=r.car;t.t2=Pair;t.t3=c;t.next=23;return A(r.cdr.cdr,n,i);case 23:t.t4=t.sent;t.t5=new t.t2(t.t3,t.t4);return t.abrupt("return",new t.t0(t.t1,t.t5));case 28:if(!E(a,o)){t.next=50;break}l=o instanceof Syntax?r:r.cdr;t.next=32;return o.invoke(l,_objectSpread(_objectSpread({},v),{},{env:i}),true);case 32:f=t.sent;if(!(o instanceof Syntax)){t.next=41;break}_=f,p=_.expr,d=_.scope;if(!is_pair(p)){t.next=40;break}if(!(n!==-1&&n<=1||n")}return"#"};var SyntaxParameter=_createClass(function e(t){_classCallCheck(this,e);read_only(this,"_syntax",t,{hidden:true});read_only(this._syntax,"_param",true,{hidden:true})});Syntax.Parameter=SyntaxParameter;function extract_patterns(e,t,B,I){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:{};var j={"...":{symbols:{},lists:[]},symbols:{}};var R=r.expansion,T=r.define;log(B);function M(t,e){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:false;log({code:e,pattern:t});if(is_atom(t)&&!(t instanceof LSymbol)){return same_atom(t,e)}if(t instanceof LSymbol&&B.includes(t.literal())){if(!LSymbol.is(e,t)){return false}var i=R.ref(t);return!i||i===T||i===global_env}if(Array.isArray(t)&&Array.isArray(e)){log("<<< a 1");if(t.length===0&&e.length===0){return true}if(LSymbol.is(t[1],I)){if(t[0]instanceof LSymbol){var a=t[0].valueOf();log("<<< a 2 "+n);if(n){var o=e.length-2;var u=o>0?e.slice(0,o):e;var s=Pair.fromArray(u,false);if(!j["..."].symbols[a]){j["..."].symbols[a]=new Pair(s,_nil)}else{j["..."].symbols[a].append(new Pair(s,_nil))}}else{j["..."].symbols[a]=Pair.fromArray(e,false)}}else if(Array.isArray(t[0])){log("<<< a 3");var c=_toConsumableArray(r);if(!e.every(function(e){return M(t[0],e,c,true)})){return false}}if(t.length>2){var l=t.slice(2);return M(l,e.slice(-l.length),r,n)}return true}var f=M(t[0],e[0],r,n);log({first:f,pattern:t[0],code:e[0]});var _=M(t.slice(1),e.slice(1),r,n);log({first:f,rest:_});return f&&_}if(is_pair(t)&&is_pair(t.car)&&is_pair(t.car.cdr)&&LSymbol.is(t.car.cdr.car,I)){log(">> 0");if(is_nil(e)){log({pattern:t});if(t.car.car instanceof LSymbol){var p=t.car.car.valueOf();if(j["..."].symbols[p]){throw new Error("syntax: named ellipsis can only "+"appear onces")}j["..."].symbols[p]=e}}}if(is_pair(t)&&is_pair(t.cdr)&&LSymbol.is(t.cdr.car,I)){if(!is_nil(t.cdr.cdr)){if(is_pair(t.cdr.cdr)){var d=t.cdr.cdr.length();if(!is_pair(e)){return false}var h=e.length();var m=e;while(h-1>d){m=m.cdr;h--}var y=m.cdr;m.cdr=_nil;if(!M(t.cdr.cdr,y,r,n)){return false}}}if(t.car instanceof LSymbol){var v=t.car.__name__;if(j["..."].symbols[v]&&!r.includes(v)&&!n){throw new Error("syntax: named ellipsis can only appear onces")}log(">> 1");if(is_nil(e)){log(">> 2");if(n){log("NIL");j["..."].symbols[v]=_nil}else{log("NULL");j["..."].symbols[v]=null}}else if(is_pair(e)&&(is_pair(e.car)||is_nil(e.car))){log(">> 3 "+n);if(n){if(j["..."].symbols[v]){var b=j["..."].symbols[v];if(is_nil(b)){b=new Pair(_nil,new Pair(e,_nil))}else{b=b.append(new Pair(e,_nil))}j["..."].symbols[v]=b}else{j["..."].symbols[v]=new Pair(e,_nil)}}else{log(">> 4");j["..."].symbols[v]=new Pair(e,_nil)}}else{log(">> 6");if(is_pair(e)){if(!is_pair(e.cdr)&&!is_nil(e.cdr)){log(">> 7 (b)");if(is_nil(t.cdr.cdr)){return false}else if(!j["..."].symbols[v]){j["..."].symbols[v]=new Pair(e.car,_nil);return M(t.cdr.cdr,e.cdr)}}var g=e.last_pair();if(!is_nil(g.cdr)){if(is_nil(t.cdr.cdr)){return false}else{var w=e.clone();w.last_pair().cdr=_nil;j["..."].symbols[v]=w;return M(t.cdr.cdr,g.cdr)}}log(">> 7 "+n);r.push(v);if(!j["..."].symbols[v]){j["..."].symbols[v]=new Pair(e,_nil)}else{var D=j["..."].symbols[v];j["..."].symbols[v]=D.append(new Pair(e,_nil))}log({IIIIII:j["..."].symbols[v]})}else if(t.car instanceof LSymbol&&is_pair(t.cdr)&&LSymbol.is(t.cdr.car,I)){log(">> 8");j["..."].symbols[v]=null;return M(t.cdr.cdr,e)}else{log(">> 9");return false}}return true}else if(is_pair(t.car)){var x=_toConsumableArray(r);if(is_nil(e)){log(">> 10");j["..."].lists.push(_nil);return true}log(">> 11");var L=e;while(is_pair(L)){if(!M(t.car,L.car,x,true)){return false}L=L.cdr}return true}if(Array.isArray(t.car)){var x=_toConsumableArray(r);var E=e;while(is_pair(E)){if(!M(t.car,E.car,x,true)){return false}E=E.cdr}return true}return false}if(t instanceof LSymbol){if(LSymbol.is(t,I)){throw new Error("syntax: invalid usage of ellipsis")}log(">> 12");var S=t.__name__;if(B.includes(S)){return true}if(n){var A,F;log(j["..."].symbols[S]);(F=(A=j["..."].symbols)[S])!==null&&F!==void 0?F:A[S]=[];j["..."].symbols[S].push(e)}else{j.symbols[S]=e}return true}if(is_pair(t)&&is_pair(e)){log(">> 13");log({a:13,code:e,pattern:t});if(is_nil(e.cdr)){var k=t.car instanceof LSymbol&&t.cdr instanceof LSymbol;if(k){if(!M(t.car,e.car,r,n)){return false}log(">> 14");var C=t.cdr.valueOf();if(!(C in j.symbols)){j.symbols[C]=_nil}C=t.car.valueOf();if(!(C in j.symbols)){j.symbols[C]=e.car}return true}}log({pattern:t,code:e});if(is_pair(t.cdr)&&is_pair(t.cdr.cdr)&&t.cdr.car instanceof LSymbol&&LSymbol.is(t.cdr.cdr.car,I)&&is_pair(t.cdr.cdr.cdr)&&!LSymbol.is(t.cdr.cdr.cdr.car,I)&&M(t.car,e.car,r,n)&&M(t.cdr.cdr.cdr,e.cdr,r,n)){var O=t.cdr.car.__name__;log({pattern:t,code:e,name:O});if(B.includes(O)){return true}j["..."].symbols[O]=null;return true}log("recur");log({pattern:t,code:e});var P=M(t.car,e.car,r,n);log({car:P,pattern:t.car,code:e.car});var N=M(t.cdr,e.cdr,r,n);log({car:P,cdr:N});if(P&&N){return true}}else if(is_nil(t)&&(is_nil(e)||e===undefined)){return true}else if(is_pair(t.car)&&LSymbol.is(t.car.car,I)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(M(e,t)){return j}}function clear_gensyms(e,i){function a(t){if(is_pair(t)){if(!i.length){return t}var e=a(t.car);var r=a(t.cdr);return new Pair(e,r)}else if(t instanceof LSymbol){var n=i.find(function(e){return e.gensym===t});if(n){return LSymbol(n.name)}return t}else{return t}}return a(e)}function transform_syntax(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var P=e.bindings,t=e.expr,N=e.scope,o=e.symbols,l=e.names,B=e.ellipsis;var f={};function u(e){if(e instanceof LSymbol){return true}return["string","symbol"].includes(_typeof$1(e))}function I(e){if(!u(e)){var t=type(e);throw new Error("syntax: internal error, need symbol got ".concat(t))}var r=e.valueOf();if(r===B){throw new Error("syntax: internal error, ellipis not transformed")}var n=_typeof$1(r);if(["string","symbol"].includes(n)){if(r in P.symbols){return P.symbols[r]}else if(n==="string"&&r.match(/\./)){var i=r.split(".");var a=i[0];if(a in P.symbols){return Pair.fromArray([LSymbol("."),P.symbols[a]].concat(i.slice(1).map(function(e){return LString(e)})))}}}if(o.includes(r)){return e}return s(r,e)}function s(e,t){if(!f[e]){var r=N.ref(e);if(_typeof$1(e)==="symbol"&&!r){e=t.literal()}if(f[e]){return f[e]}var n=gensym(e);if(r){var i=N.get(e);N.set(n,i)}else{var a=N.get(e,{throwError:false});if(typeof a!=="undefined"){N.set(n,a)}}l.push({name:e,gensym:n});f[e]=n;if(typeof e==="string"&&e.match(/\./)){var o=e.split(".").filter(Boolean),u=_toArray(o),s=u[0],c=u.slice(1);if(f[s]){hidden_prop(n,"__object__",[f[s]].concat(_toConsumableArray(c)))}}}return f[e]}function j(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:function(){};var i=r.nested;log({bindings:t,expr:e});if(Array.isArray(e)&&!e.length){return e}if(e instanceof LSymbol){var a=e.valueOf();if(is_gensym(e)&&!t[a]);log("[t 1");if(t[a]){if(is_pair(t[a])){var o=t[a],u=o.car,s=o.cdr;if(i){var c=u.car,l=u.cdr;if(!is_nil(l)){n(a,new Pair(l,_nil))}return c}if(!is_nil(s)){n(a,s)}return u}else if(t[a]instanceof Array){n(a,t[a].slice(1));return t[a][0]}}return I(e)}var f=Array.isArray(e);if(is_pair(e)||f){var _=f?e[0]:e.car;var p=f?e[1]:is_pair(e.cdr)&&e.cdr.car;if(_ instanceof LSymbol&&LSymbol.is(p,B)){f?e.slice(2):e.cdr.cdr;log("[t 2");var d=_.valueOf();var h=t[d];if(h===null){return}else if(h){log({name:d,binding:t[d]});if(is_pair(h)){log("[t 2 Pair "+i);var m=h.car,y=h.cdr;var v=f?e.slice(2):e.cdr.cdr;if(i){if(!is_nil(y)){log("|| next 1");n(d,y)}if(f&&v.length||!is_nil(v)&&!f){var b=j(v,t,r,n);if(f){return m.concat(b)}else if(is_pair(m)){return m.append(b)}else{log("UNKNOWN")}}return m}else if(is_pair(m)){if(!is_nil(m.cdr)){log("|| next 2");n(d,new Pair(m.cdr,y))}return m.car}else if(is_nil(y)){return m}else{var g=e.last_pair();if(g.cdr instanceof LSymbol){log("|| next 3");n(d,h.last_pair());return m}}}else if(h instanceof Array){log("[t 2 Array "+i);if(i){n(d,h.slice(1));return Pair.fromArray(h)}else{var w=h.slice(1);if(w.length){n(d,w)}return h[0]}}else{return h}}}log("[t 3 recur ",e);var D=f?e.slice(1):e.cdr;var x=j(_,t,r,n);var L=j(D,t,r,n);log({head:x,rest:L});if(f){return[x].concat(L)}return new Pair(x,L)}return e}function R(t,r){var e=Object.values(t);var n=Object.getOwnPropertySymbols(t);if(n.length){e.push.apply(e,_toConsumableArray(n.map(function(e){return t[e]})))}return e.length&&e.every(function(e){if(e===null){return!r}return is_pair(e)||is_nil(e)||Array.isArray(e)&&e.length})}function T(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function M(i){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},t=e.disabled;log("traverse>> ",i);var a=Array.isArray(i);if(a&&i.length===0){return i}if(is_pair(i)||a){var r=a?i[0]:i.car;var n,o;if(a){n=i[1];o=i.slice(2)}else if(is_pair(i.cdr)){n=i.cdr.car;o=i.cdr.cdr}log({first:r,second:n,rest_second:o});if(!t&&is_pair(r)&&LSymbol.is(r.car,B)){return M(r.cdr,{disabled:true})}if(n&&LSymbol.is(n,B)&&!t){log(">> 1");var u=P["..."].symbols;var s=Object.values(u);if(s.length&&s.every(function(e){return e===null})){log(">>> 1 (a)");return M(o,{disabled:t})}var c=T(u);var l=r instanceof LSymbol&&LSymbol.is(o.car,B);if(is_pair(r)||l){log(">>> 1 (b)");if(is_nil(P["..."].lists[0])){if(!l){return M(o,{disabled:t})}log(o);return _nil}var f=r;if(l){log(">>> 1 (c)");f=new Pair(r,new Pair(n,_nil))}log(">> 2");var _;if(c.length){log(">> 2 (a)");var p=_objectSpread({},u);_=a?[]:_nil;var d=function e(){log({bind:p});if(!R(p)){return 1}var n={};var t=function e(t,r){n[t]=r};var r=j(f,p,{nested:true},t);if(r!==undefined){if(l){if(a){if(Array.isArray(r)){var i;(i=_).push.apply(i,_toConsumableArray(r))}else{log("ZONK {1}")}}else{if(is_nil(_)){_=r}else{_=_.append(r)}}}else if(a){_.push(r)}else{_=new Pair(r,_)}}p=n};while(true){if(d())break}if(!is_nil(_)&&!l&&!a){_=_.reverse()}if(a){if(o){log({rest_second:o,expr:i});var h=M(o,{disabled:t});return _.concat(h)}return _}if(!is_nil(i.cdr.cdr)&&!LSymbol.is(i.cdr.cdr.car,B)){var m=M(i.cdr.cdr,{disabled:t});return _.append(m)}return _}else{log(">> 3");var y=j(r,u,{nested:true});if(y){return new Pair(y,_nil)}return _nil}}else if(r instanceof LSymbol){log(">> 4");if(LSymbol.is(o.car,B)){log(">> 4 (a)")}else{log(">> 4 (b)")}var v=r.__name__;var b=_defineProperty({},v,u[v]);log({bind:b});var g=u[v]===null;var w=a?[]:_nil;var D=function e(){if(!R(b,true)){log({bind:b});return 1}var n={};var t=function e(t,r){n[t]=r};var r=j(i,b,{nested:false},t);log({value:r});if(typeof r!=="undefined"){if(a){w.push(r)}else{w=new Pair(r,w)}}b=n};while(true){if(D())break}if(!is_nil(w)&&!a){w=w.reverse()}if(is_pair(i.cdr)){if(is_pair(i.cdr.cdr)||i.cdr.cdr instanceof LSymbol){var x=M(i.cdr.cdr,{disabled:t});log({node:x});if(g){return x}if(is_nil(w)){w=x}else{w.append(x)}log({result:w,node:x})}}log("<<<< 2");return w}}var L=M(r,{disabled:t});var E;var S;if(r instanceof LSymbol){var A=N.get(r,{throwError:false});S=A instanceof Macro&&A.__name__==="syntax-rules"}if(S){if(i.cdr.car instanceof LSymbol){E=new Pair(M(i.cdr.car,{disabled:t}),new Pair(i.cdr.cdr.car,M(i.cdr.cdr.cdr,{disabled:t})))}else{E=new Pair(i.cdr.car,M(i.cdr.cdr,{disabled:t}))}log("REST >>>> ",E)}else{E=M(i.cdr,{disabled:t})}log({a:true,car:toString(i.car),cdr:toString(i.cdr),head:toString(L),rest:toString(E)});return new Pair(L,E)}if(i instanceof LSymbol){if(t&&LSymbol.is(i,B)){return i}var F=Object.keys(P["..."].symbols);var k=i.literal();if(F.includes(k)){var C="missing ellipsis symbol next to name `".concat(k,"'");throw new Error("syntax-rules: ".concat(C))}var O=I(i);if(typeof O!=="undefined"){return O}}return i}return M(t,{})}function is_null(e){return is_undef(e)||is_nil(e)||e===null}function is_nil(e){return e===_nil}function is_function(e){return typeof e==="function"&&typeof e.bind==="function"}function is_string(e){return typeof e==="string"}function is_prototype(e){return e&&_typeof$1(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}function is_continuation(e){return e instanceof Continuation}function is_context(e){return e instanceof LambdaContext}function is_parameter(e){return e instanceof Parameter}function is_pair(e){return e instanceof Pair}function is_env(e){return e instanceof Environment}function is_callable(e){return is_function(e)||is_continuation(e)||is_parameter(e)||is_macro(e)}function is_macro(e){return e instanceof Macro||e instanceof SyntaxParameter}function is_promise(e){if(e instanceof QuotedPromise){return false}if(e instanceof Promise){return true}return!!e&&is_function(e.then)}function is_undef(e){return typeof e==="undefined"}function is_iterator(e,t){if(has_own_symbol(e,t)||has_own_symbol(e.__proto__,t)){return is_function(e[t])}}function is_instance(e){if(!e){return false}if(_typeof$1(e)!=="object"){return false}if(e.__instance__){e.__instance__=false;return e.__instance__}return false}function self_evaluated(e){var t=_typeof$1(e);return["string","function"].includes(t)||_typeof$1(e)==="symbol"||e instanceof QuotedPromise||e instanceof LSymbol||e instanceof LNumber||e instanceof LString||e instanceof RegExp}function is_native(e){return e instanceof LNumber||e instanceof LString||e instanceof LCharacter}function has_own_symbol(e,t){if(e===null){return false}return _typeof$1(e)==="object"&&t in Object.getOwnPropertySymbols(e)}function box(e){switch(_typeof$1(e)){case"string":return LString(e);case"bigint":return LNumber(e);case"number":if(Number.isNaN(e)){return nan}else{return LNumber(e)}}return e}function map_object(r,n){var e=Object.getOwnPropertyNames(r);var t=Object.getOwnPropertySymbols(r);var i={};e.concat(t).forEach(function(e){var t=n(r[e]);i[e]=t});return i}function unbox(t){var e=[LString,LNumber].some(function(e){return t instanceof e});if(e){return t.valueOf()}if(t instanceof Array){return t.map(unbox)}if(t instanceof QuotedPromise){delete t.then}if(is_plain_object(t)){return map_object(t,unbox)}return t}function patch_value(e,t){if(is_pair(e)){e.mark_cycles();return quote(e)}if(is_function(e)){if(t){return bind(e,t)}}return box(e)}function unbind(e){if(is_bound(e)){return e[__fn__]}return e}function bind(e,t){if(e[Symbol["for"]("__bound__")]){return e}var r=e.bind(t);var n=Object.getOwnPropertyNames(e);var i=_createForOfIteratorHelper(n),a;try{for(i.s();!(a=i.n()).done;){var o=a.value;if(filter_fn_names(o)){try{r[o]=e[o]}catch(e){}}}}catch(e){i.e(e)}finally{i.f()}hidden_prop(r,"__fn__",e);hidden_prop(r,"__context__",t);hidden_prop(r,"__bound__",true);if(is_native_function(e)){hidden_prop(r,"__native__",true)}if(is_plain_object(t)&&is_lambda(e)){hidden_prop(r,"__method__",true)}r.valueOf=function(){return e};return r}function is_object_bound(e){return is_bound(e)&&e[Symbol["for"]("__context__")]===Object}function is_bound(e){return!!(is_function(e)&&e[__fn__])}function lips_context(e){if(is_function(e)){var t=e[__context__];if(t&&(t===lips||t.constructor&&t.constructor.__class__)){return true}}return false}function is_port(e){return e instanceof InputPort||e instanceof OutputPort}function is_port_method(e){if(is_function(e)){if(is_port(e[__context__])){return true}}return false}var __context__=Symbol["for"]("__context__");var __fn__=Symbol["for"]("__fn__");var __data__=Symbol["for"]("__data__");var __ref__=Symbol["for"]("__ref__");var __cycles__=Symbol["for"]("__cycles__");var __class__=Symbol["for"]("__class__");var __method__=Symbol["for"]("__method__");var __prototype__=Symbol["for"]("__prototype__");var __lambda__=Symbol["for"]("__lambda__");var exluded_names=["name","length","caller","callee","arguments","prototype"];function filter_fn_names(e){return!exluded_names.includes(e)}function hidden_prop(e,t,r){Object.defineProperty(e,Symbol["for"](t),{get:function e(){return r},set:function e(){},configurable:false,enumerable:false})}function set_fn_length(t,r){try{Object.defineProperty(t,"length",{get:function e(){return r}});return t}catch(e){var n=new Array(r).fill(0).map(function(e,t){return"a"+t}).join(",");var i=new Function("f","return function(".concat(n,") {\n return f.apply(this, arguments);\n };"));return i(t)}}function is_lambda(e){return e&&e[__lambda__]}function is_method(e){return e&&e[__method__]}function is_raw_lambda(e){return is_lambda(e)&&!e[__prototype__]&&!is_method(e)&&!is_port_method(e)}function is_native_function(e){var t=Symbol["for"]("__native__");return is_function(e)&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[t]===true||!e.name.match(/^bound /)&&!e[t])}function let_macro(e){var g;switch(e){case Symbol["for"]("letrec"):g="letrec";break;case Symbol["for"]("let"):g="let";break;case Symbol["for"]("let*"):g="let*";break;default:throw new Error("Invalid let_macro value")}return Macro.defmacro(g,function(t,e){var l=e.dynamic_env;var f=e.error,r=e.macro_expand,_=e.use_dynamic;var p;if(t.car instanceof LSymbol){if(!(is_pair(t.cdr.car)||is_nil(t.cdr.car))){throw new Error("let require list of pairs")}var n;if(is_nil(t.cdr.car)){p=_nil;n=_nil}else{n=t.cdr.car.map(function(e){return e.car});p=t.cdr.car.map(function(e){return e.cdr.car})}return Pair.fromArray([LSymbol("letrec"),[[t.car,Pair(LSymbol("lambda"),Pair(n,t.cdr.cdr))]],Pair(t.car,p)])}else if(r){return}var d=this;p=global_env.get("list->array")(t.car);var h=d.inherit(g);var m,y;if(g==="let*"){y=h}else if(g==="let"){m=[]}var v=0;function b(){var e=new Pair(new LSymbol("begin"),t.cdr);return _evaluate(e,{env:h,dynamic_env:h,use_dynamic:_,error:f})}return function t(){var r=p[v++];l=g==="let*"?h:d;if(!r){if(m&&m.length){var e=m.map(function(e){return e.value});var n=e.filter(is_promise);if(n.length){return promise_all(e).then(function(e){for(var t=0,r=e.length;t1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=t.error;var i=this;var a=this;var o=[];var u=e;while(is_pair(u)){o.push(_evaluate(u.car,{env:i,dynamic_env:a,use_dynamic:r,error:n}));u=u.cdr}var s=o.filter(is_promise).length;if(s){return promise_all(o).then(c.bind(this))}else{return c.call(this,o)}})}function guard_math_call(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n2?n-2:0),a=2;a1&&arguments[1]!==undefined?arguments[1]:null;return function(){for(var e=arguments.length,t=new Array(e),r=0;r1?e-1:0),r=1;r=o){return a.apply(this,n)}else{return i}}return i.apply(this,arguments)}}function limit(n,i){typecheck("limit",i,"function",2);return function(){for(var e=arguments.length,t=new Array(e),r=0;r1){e=e.toLowerCase();if(LCharacter.__names__[e]){t=e;e=LCharacter.__names__[e]}else{throw new Error("Internal: Unknown named character")}}else{t=LCharacter.__rev_names__[e]}Object.defineProperty(this,"__char__",{value:e,enumerable:true});if(t){Object.defineProperty(this,"__name__",{value:t,enumerable:true})}}LCharacter.__names__=characters;LCharacter.__rev_names__={};Object.keys(LCharacter.__names__).forEach(function(e){var t=LCharacter.__names__[e];LCharacter.__rev_names__[t]=e});LCharacter.prototype.toUpperCase=function(){return LCharacter(this.__char__.toUpperCase())};LCharacter.prototype.toLowerCase=function(){return LCharacter(this.__char__.toLowerCase())};LCharacter.prototype.toString=function(){return"#\\"+(this.__name__||this.__char__)};LCharacter.prototype.valueOf=LCharacter.prototype.serialize=function(){return this.__char__};function LString(e){if(typeof this!=="undefined"&&!(this instanceof LString)||typeof this==="undefined"){return new LString(e)}if(e instanceof Array){this.__string__=e.map(function(e,t){typecheck("LString",e,"character",t+1);return e.toString()}).join("")}else{this.__string__=e.valueOf()}}{var ignore=["length","constructor"];var _keys=Object.getOwnPropertyNames(String.prototype).filter(function(e){return!ignore.includes(e)});var wrap=function e(n){return function(){for(var e=arguments.length,t=new Array(e),r=0;r0){r.push(this.__string__.substring(0,e))}r.push(t);if(e1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof LNumber){return e}if(typeof this!=="undefined"&&!(this instanceof LNumber)||typeof this==="undefined"){return new LNumber(e,t)}if(typeof e==="undefined"){throw new Error("Invalid LNumber constructor call")}var r=LNumber.getType(e);if(LNumber.types[r]){return LNumber.types[r](e,t)}var n=e instanceof Array&&LString.isString(e[0])&&LNumber.isNumber(e[1]);if(e instanceof LNumber){return LNumber(e.value)}if(!LNumber.isNumber(e)&&!n){throw new Error("You can't create LNumber from ".concat(type(e)))}if(e===null){e=0}var i;if(n){var a=e,o=_slicedToArray(a,2),u=o[0],s=o[1];if(u instanceof LString){u=u.valueOf()}if(s instanceof LNumber){s=s.valueOf()}var c=u.match(/^([+-])/);var l=false;if(c){u=u.replace(/^[+-]/,"");if(c[1]==="-"){l=true}}}if(Number.isNaN(e)){return LFloat(e)}else if(n&&Number.isNaN(parseInt(u,s))){return nan}else if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(n){var f;switch(s){case 8:f="0o";break;case 16:f="0x";break;case 2:f="0b";break;case 10:f="";break}if(typeof f==="undefined"){var _=BigInt(s);i=_toConsumableArray(u).map(function(e,t){return BigInt(parseInt(e,s))*pow(_,BigInt(t))}).reduce(function(e,t){return e+t})}else{i=BigInt(f+u)}}else{i=BigInt(e)}if(l){i*=BigInt(-1)}}else{i=e}return LBigInteger(i,true)}else if(typeof BN!=="undefined"&&!(e instanceof BN)){if(e instanceof Array){return LBigInteger(_construct(BN,_toConsumableArray(e)))}return LBigInteger(new BN(e))}else if(n){this.constant(parseInt(u,s),"integer")}else{this.constant(e,"integer")}}LNumber.prototype.constant=function(e,t){Object.defineProperty(this,"__value__",{value:e,enumerable:true});Object.defineProperty(this,"__type__",{value:t,enumerable:true})};LNumber.types={float:function e(t){return new LFloat(t)},complex:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!LNumber.isComplex(t)){t={im:0,re:t}}return new LComplex(t,r)},rational:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!LNumber.isRational(t)){t={num:t,denom:1}}return new LRational(t,r)}};LNumber.prototype.serialize=function(){return this.__value__};LNumber.prototype.isNaN=function(){return Number.isNaN(this.__value__)};LNumber.prototype.gcd=function(e){var t=this.abs();e=e.abs();if(e.cmp(t)===1){var r=t;t=e;e=r}while(true){t=t.rem(e);if(t.cmp(0)===0){return e}e=e.rem(t);if(e.cmp(0)===0){return t}}};LNumber.isFloat=function e(t){return t instanceof LFloat||Number(t)===t&&t%1!==0};LNumber.isNumber=function(e){return e instanceof LNumber||LNumber.isNative(e)||LNumber.isBN(e)};LNumber.isComplex=function(e){if(!e){return false}var t=e instanceof LComplex||(LNumber.isNumber(e.im)||LNumber.isRational(e.im)||Number.isNaN(e.im))&&(LNumber.isNumber(e.re)||LNumber.isRational(e.re)||Number.isNaN(e.re));return t};LNumber.isRational=function(e){if(!e){return false}return e instanceof LRational||LNumber.isNumber(e.num)&&LNumber.isNumber(e.denom)};LNumber.isInteger=function(e){if(!(LNumber.isNative(e)||e instanceof LNumber)){return false}if(LNumber.isFloat(e)){return false}if(LNumber.isRational(e)){return false}if(LNumber.isComplex(e)){return false}return true};LNumber.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};LNumber.isBigInteger=function(e){return e instanceof LBigInteger||typeof e==="bigint"||LNumber.isBN(e)};LNumber.isBN=function(e){return typeof BN!=="undefined"&&e instanceof BN};LNumber.getArgsType=function(e,t){if(e instanceof LFloat||t instanceof LFloat){return LFloat}if(e instanceof LBigInteger||t instanceof LBigInteger){return LBigInteger}return LNumber};LNumber.prototype.toString=function(e){if(Number.isNaN(this.__value__)){return"+nan.0"}if(e>=2&&e<36){return this.__value__.toString(e)}return this.__value__.toString()};LNumber.prototype.asType=function(e){var t=LNumber.getType(this);return LNumber.types[t]?LNumber.types[t](e):LNumber(e)};LNumber.prototype.isBigNumber=function(){return typeof this.__value__==="bigint"||typeof BN!=="undefined"&&!(this.value instanceof BN)};["floor","ceil","round"].forEach(function(e){LNumber.prototype[e]=function(){if(this["float"]||LNumber.isFloat(this.__value__)){return LNumber(Math[e](this.__value__))}else{return LNumber(Math[e](this.valueOf()))}}});LNumber.prototype.valueOf=function(){if(LNumber.isNative(this.__value__)){return Number(this.__value__)}else if(LNumber.isBN(this.__value__)){return this.__value__.toNumber()}};var matrix=function(){var e=function e(t,r){return[t,r]};return{bigint:{bigint:e,float:function e(t,r){return[LFloat(t.valueOf()),r]},rational:function e(t,r){return[{num:t,denom:1},r]},complex:function e(t,r){return[{im:0,re:t},r]}},integer:{integer:e,float:function e(t,r){return[LFloat(t.valueOf()),r]},rational:function e(t,r){return[{num:t,denom:1},r]},complex:function e(t,r){return[{im:0,re:t},r]}},float:{bigint:function e(t,r){return[t,r&&LFloat(r.valueOf())]},integer:function e(t,r){return[t,r&&LFloat(r.valueOf())]},float:e,rational:function e(t,r){return[t,r&&LFloat(r.valueOf())]},complex:function e(t,r){return[{re:t,im:LFloat(0)},r]}},complex:{bigint:t("bigint"),integer:t("integer"),float:t("float"),rational:t("rational"),complex:function e(t,r){var n=LNumber.coerce(t.__re__,r.__re__),i=_slicedToArray(n,2),a=i[0],o=i[1];var u=LNumber.coerce(t.__im__,r.__im__),s=_slicedToArray(u,2),c=s[0],l=s[1];return[{im:c,re:a},{im:l,re:o}]}},rational:{bigint:function e(t,r){return[t,r&&{num:r,denom:1}]},integer:function e(t,r){return[t,r&&{num:r,denom:1}]},float:function e(t,r){return[LFloat(t.valueOf()),r]},rational:e,complex:function e(t,r){return[{im:coerce(t.__type__,r.__im__.__type__,0)[0],re:coerce(t.__type__,r.__re__.__type__,t)[0]},{im:coerce(t.__type__,r.__im__.__type__,r.__im__)[0],re:coerce(t.__type__,r.__re__.__type__,r.__re__)[0]}]}}};function t(r){return function(e,t){return[{im:coerce(r,e.__im__.__type__,0,e.__im__)[1],re:coerce(r,e.__re__.__type__,0,e.__re__)[1]},{im:coerce(r,e.__im__.__type__,0,0)[1],re:coerce(r,t.__type__,0,t)[1]}]}}}();function coerce(e,t,r,n){return matrix[e][t](r,n)}LNumber.coerce=function(e,t){var r=LNumber.getType(e);var n=LNumber.getType(t);if(!matrix[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!matrix[r][n]){throw new Error("LNumber::coerce unknown rhs type ".concat(n))}var i=matrix[r][n](e,t);return i.map(function(e){return LNumber(e,true)})};LNumber.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof LNumber)){throw new Error("LNumber: you can't coerce ".concat(type(e)))}if(typeof e==="number"){e=LNumber(e)}return LNumber.coerce(this,e)};LNumber.getType=function(e){if(e instanceof LNumber){return e.__type__}if(LNumber.isFloat(e)){return"float"}if(LNumber.isComplex(e)){return"complex"}if(LNumber.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof BN!=="undefined"&&!(e instanceof BN)){return"bigint"}};LNumber.prototype.isFloat=function(){return!!(LNumber.isFloat(this.__value__)||this["float"])};var mapping={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var rev_mapping={};Object.keys(mapping).forEach(function(t){rev_mapping[mapping[t]]=t;LNumber.prototype[t]=function(e){return this.op(mapping[t],e)}});LNumber._ops={"*":function e(t,r){return t*r},"+":function e(t,r){return t+r},"-":function e(t,r){if(typeof r==="undefined"){return-t}return t-r},"/":function e(t,r){return t/r},"%":function e(t,r){return t%r},"|":function e(t,r){return t|r},"&":function e(t,r){return t&r},"~":function e(t){return~t},">>":function e(t,r){return t>>r},"<<":function e(t,r){return t<1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof LComplex)||typeof this==="undefined"){return new LComplex(e,t)}if(e instanceof LComplex){return LComplex({im:e.__im__,re:e.__re__})}if(LNumber.isNumber(e)&&t){if(!t){return Number(e)}}else if(!LNumber.isComplex(e)){var r="Invalid constructor call for LComplex expect &(:im :re ) object but got ".concat(toString(e));throw new Error(r)}var n=e.im instanceof LNumber?e.im:LNumber(e.im);var i=e.re instanceof LNumber?e.re:LNumber(e.re);this.constant(n,i)}LComplex.prototype=Object.create(LNumber.prototype);LComplex.prototype.constructor=LComplex;LComplex.prototype.constant=function(e,t){Object.defineProperty(this,"__im__",{value:e,enumerable:true});Object.defineProperty(this,"__re__",{value:t,enumerable:true});Object.defineProperty(this,"__type__",{value:"complex",enumerable:true})};LComplex.prototype.serialize=function(){return{re:this.__re__,im:this.__im__}};LComplex.prototype.toRational=function(e){if(LNumber.isFloat(this.__im__)&&LNumber.isFloat(this.__re__)){var t=LFloat(this.__im__).toRational(e);var r=LFloat(this.__re__).toRational(e);return LComplex({im:t,re:r})}return this};LComplex.prototype.pow=function(e){e.cmp(0);if(e===0){return LNumber(1)}var t=LNumber(Math.atan2(this.__im__.valueOf(),this.__re__.valueOf()));var r=LNumber(this.modulus());if(LNumber.isComplex(e)&&e.__im__.cmp(0)!==0){var n=e.mul(Math.log(r.valueOf())).add(LComplex.i.mul(t).mul(e));var i=LFloat(Math.E).pow(n.__re__.valueOf());return LComplex({re:i.mul(Math.cos(n.__im__.valueOf())),im:i.mul(Math.sin(n.__im__.valueOf()))})}var a=e.__re__.cmp(0)>0;e=e.__re__.valueOf();if(LNumber.isInteger(e)&&a){var o=this;while(--e){o=o.mul(this)}return o}var u=r.pow(e);var s=t.mul(e);return LComplex({re:u.mul(Math.cos(s)),im:u.mul(Math.sin(s))})};LComplex.prototype.add=function(e){return this.complex_op("add",e,function(e,t,r,n){return{re:e.add(t),im:r.add(n)}})};LComplex.prototype.factor=function(){if(this.__im__ instanceof LFloat||this.__im__ instanceof LFloat){var e=this.__re__,t=this.__im__;var r,n;if(e instanceof LFloat){r=e.toRational().mul(e.toRational())}else{r=e.mul(e)}if(t instanceof LFloat){n=t.toRational().mul(t.toRational())}else{n=t.mul(t)}return r.add(n)}else{return this.__re__.mul(this.__re__).add(this.__im__.mul(this.__im__))}};LComplex.prototype.modulus=function(){return this.factor().sqrt()};LComplex.prototype.conjugate=function(){return LComplex({re:this.__re__,im:this.__im__.sub()})};LComplex.prototype.sqrt=function(){var e=this.modulus();var t,r;if(e.cmp(0)===0){t=r=e}else if(this.__re__.cmp(0)===1){t=LFloat(.5).mul(e.add(this.__re__)).sqrt();r=this.__im__.div(t).div(2)}else{r=LFloat(.5).mul(e.sub(this.__re__)).sqrt();if(this.__im__.cmp(0)===-1){r=r.sub()}t=this.__im__.div(r).div(2)}return LComplex({im:r,re:t})};LComplex.prototype.div=function(e){if(LNumber.isNumber(e)&&!LNumber.isComplex(e)){if(!(e instanceof LNumber)){e=LNumber(e)}var t=this.__re__.div(e);var r=this.__im__.div(e);return LComplex({re:t,im:r})}else if(!LNumber.isComplex(e)){throw new Error("[LComplex::div] Invalid value")}if(this.cmp(e)===0){var n=this.coerce(e),i=_slicedToArray(n,2),a=i[0],o=i[1];var u=a.__im__.div(o.__im__);return u.coerce(o.__re__)[0]}var s=this.coerce(e),c=_slicedToArray(s,2),l=c[0],f=c[1];var _=f.factor();var p=f.conjugate();var d=l.mul(p);if(!LNumber.isComplex(d)){return d.div(_)}var h=d.__re__.op("/",_);var m=d.__im__.op("/",_);return LComplex({re:h,im:m})};LComplex.prototype.sub=function(e){return this.complex_op("sub",e,function(e,t,r,n){return{re:e.sub(t),im:r.sub(n)}})};LComplex.prototype.mul=function(e){return this.complex_op("mul",e,function(e,t,r,n){var i={re:e.mul(t).sub(r.mul(n)),im:e.mul(n).add(t.mul(r))};return i})};LComplex.prototype.complex_op=function(e,t,i){var a=this;var r=function e(t,r){var n=i(a.__re__,t,a.__im__,r);if("im"in n&&"re"in n){if(n.im.cmp(0)===0){return n.re}return LComplex(n,true)}return n};if(typeof t==="undefined"){return r()}if(LNumber.isNumber(t)&&!LNumber.isComplex(t)){if(!(t instanceof LNumber)){t=LNumber(t)}var n=t.asType(0);t={__im__:n,__re__:t}}else if(!LNumber.isComplex(t)){throw new Error("[LComplex::".concat(e,"] Invalid value"))}var o=t.__re__ instanceof LNumber?t.__re__:this.__re__.asType(t.__re__);var u=t.__im__ instanceof LNumber?t.__im__:this.__im__.asType(t.__im__);return r(o,u)};LComplex._op={"+":"add","-":"sub","*":"mul","/":"div"};LComplex.prototype._op=function(e,t){var r=LComplex._op[e];return this[r](t)};LComplex.prototype.cmp=function(e){var t=this.coerce(e),r=_slicedToArray(t,2),n=r[0],i=r[1];var a=n.__re__.coerce(i.__re__),o=_slicedToArray(a,2),u=o[0],s=o[1];var c=u.cmp(s);if(c!==0){return c}else{var l=n.__im__.coerce(i.__im__),f=_slicedToArray(l,2),_=f[0],p=f[1];return _.cmp(p)}};LComplex.prototype.valueOf=function(){return[this.__re__,this.__im__].map(function(e){return e.valueOf()})};LComplex.prototype.toString=function(){var e;if(this.__re__.cmp(0)!==0){e=[toString(this.__re__)]}else{e=[]}var t=this.__im__.valueOf();var r=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY].includes(t);var n=toString(this.__im__);if(!r&&!Number.isNaN(t)){var i=this.__im__.cmp(0);if(i<0||i===0&&this.__im__._minus){e.push("-")}else{e.push("+")}n=n.replace(/^-/,"")}e.push(n);e.push("i");return e.join("")};function LFloat(e){if(typeof this!=="undefined"&&!(this instanceof LFloat)||typeof this==="undefined"){return new LFloat(e)}if(!LNumber.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof LNumber){return LFloat(e.valueOf())}if(typeof e==="number"){if(Object.is(e,-0)){Object.defineProperty(this,"_minus",{value:true})}this.constant(e,"float")}}LFloat.prototype=Object.create(LNumber.prototype);LFloat.prototype.constructor=LFloat;LFloat.prototype.toString=function(e){if(this.__value__===Number.NEGATIVE_INFINITY){return"-inf.0"}if(this.__value__===Number.POSITIVE_INFINITY){return"+inf.0"}if(Number.isNaN(this.__value__)){return"+nan.0"}e&&(e=e.valueOf());var t=this.__value__.toString(e);if(!t.match(/e[+-]?[0-9]+$/i)){var r=t.replace(/^-/,"");var n=this.__value__<0?"-":"";if(t.match(/^-?0\.0{3}/)){var i=r.match(/^[.0]+/g)[0].length-1;var a=r.replace(/^[.0]+/,"").replace(/^([0-9a-f])/i,"$1.");return"".concat(n).concat(a,"e-").concat(i.toString(e))}if(t.match(/^-?[0-9a-f]{7,}\.?/i)){var o=r.match(/^[0-9a-f]+/gi)[0].length-1;var u=r.replace(/\./,"").replace(/^([0-9a-f])/i,"$1.").replace(/0+$/,"").replace(/\.$/,".0");return"".concat(n).concat(u,"e+").concat(o.toString(e))}if(!LNumber.isFloat(this.__value__)){var s=t+".0";return this._minus?"-"+s:s}}return t.replace(/^([0-9]+)e/,"$1.0e")};LFloat.prototype._op=function(e,t){if(t instanceof LNumber){t=t.__value__}var r=LNumber._ops[e];if(e==="/"&&this.__value__===0&&t===0){return NaN}return LFloat(r(this.__value__,t))};LFloat.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){return toRational(this.__value__.valueOf())}return approxRatio(e.valueOf())(this.__value__.valueOf())};LFloat.prototype.sqrt=function(){var e=this.valueOf();if(this.cmp(0)<0){var t=LFloat(Math.sqrt(-e));return LComplex({re:0,im:t})}return LFloat(Math.sqrt(e))};LFloat.prototype.abs=function(){var e=this.valueOf();if(e<0){e=-e}return LFloat(e)};var toRational=approxRatio(1e-10);function approxRatio(n){return function(e){var t=function e(n,t,r){var i=function e(t,r){return r0){i=simplest_rational2(n,r)}else if(n.cmp(r)<=0){i=r}else if(r.cmp(0)>0){i=simplest_rational2(r,n)}else if(t.cmp(0)<0){i=LNumber(simplest_rational2(n.sub(),r.sub())).sub()}else{i=LNumber(0)}if(LNumber.isFloat(t)||LNumber.isFloat(e)){return LFloat(i)}return i}function simplest_rational2(e,t){var r=LNumber(e).floor();var n=LNumber(t).floor();if(e.cmp(r)<1){return r}else if(r.cmp(n)===0){var i=LNumber(1).div(t.sub(n));var a=LNumber(1).div(e.sub(r));return r.add(LNumber(1).div(simplest_rational2(i,a)))}else{return r.add(LNumber(1))}}function LRational(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof LRational)||typeof this==="undefined"){return new LRational(e,t)}if(!LNumber.isRational(e)){throw new Error("Invalid constructor call for LRational")}var r,n;if(e instanceof LRational){r=LNumber(e.__num__);n=LNumber(e.__denom__)}else{r=LNumber(e.num);n=LNumber(e.denom)}if(!t&&n.cmp(0)!==0){var i=r.op("%",n).cmp(0)===0;if(i){return LNumber(r.div(n))}}this.constant(r,n)}LRational.prototype=Object.create(LNumber.prototype);LRational.prototype.constructor=LRational;LRational.prototype.constant=function(e,t){Object.defineProperty(this,"__num__",{value:e,enumerable:true});Object.defineProperty(this,"__denom__",{value:t,enumerable:true});Object.defineProperty(this,"__type__",{value:"rational",enumerable:true})};LRational.prototype.serialize=function(){return{num:this.__num__,denom:this.__denom__}};LRational.prototype.pow=function(e){if(LNumber.isRational(e)){return pow(this.valueOf(),e.valueOf())}var t=e.cmp(0);if(t===0){return LNumber(1)}if(t===-1){e=e.sub();var r=this.__denom__.pow(e);var n=this.__num__.pow(e);return LRational({num:r,denom:n})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};LRational.prototype.sqrt=function(){var e=this.__num__.sqrt();var t=this.__denom__.sqrt();if(e instanceof LFloat||t instanceof LFloat){return e.div(t)}return LRational({num:e,denom:t})};LRational.prototype.abs=function(){var e=this.__num__;var t=this.__denom__;if(e.cmp(0)===-1){e=e.sub()}if(t.cmp(0)!==1){t=t.sub()}return LRational({num:e,denom:t})};LRational.prototype.cmp=function(e){return LNumber(this.valueOf(),true).cmp(e)};LRational.prototype.toString=function(){var e=this.__num__.gcd(this.__denom__);var t,r;if(e.cmp(1)!==0){t=this.__num__.div(e);if(t instanceof LRational){t=LNumber(t.valueOf(true))}r=this.__denom__.div(e);if(r instanceof LRational){r=LNumber(r.valueOf(true))}}else{t=this.__num__;r=this.__denom__}var n=this.cmp(0)<0;if(n){if(t.abs().cmp(r.abs())===0){return t.toString()}}else if(t.cmp(r)===0){return t.toString()}return t.toString()+"/"+r.toString()};LRational.prototype.valueOf=function(e){if(this.__denom__.cmp(0)===0){if(this.__num__.cmp(0)<0){return Number.NEGATIVE_INFINITY}return Number.POSITIVE_INFINITY}if(e){return LNumber._ops["/"](this.__num__.value,this.__denom__.value)}return LFloat(this.__num__.valueOf()).div(this.__denom__.valueOf())};LRational.prototype.mul=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var t=this.__num__.mul(e.__num__);var r=this.__denom__.mul(e.__denom__);return LRational({num:t,denom:r})}var n=LNumber.coerce(this,e),i=_slicedToArray(n,2),a=i[0],o=i[1];return a.mul(o)};LRational.prototype.div=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var t=this.__num__.mul(e.__denom__);var r=this.__denom__.mul(e.__num__);return LRational({num:t,denom:r})}var n=LNumber.coerce(this,e),i=_slicedToArray(n,2),a=i[0],o=i[1];var u=a.div(o);return u};LRational.prototype._op=function(e,t){return this[rev_mapping[e]](t)};LRational.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var t=e.__num__.sub();var r=e.__denom__;return this.add(LRational({num:t,denom:r}))}if(!(e instanceof LNumber)){e=LNumber(e).sub()}else{e=e.sub()}var n=LNumber.coerce(this,e),i=_slicedToArray(n,2),a=i[0],o=i[1];return a.add(o)};LRational.prototype.add=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var t=this.__denom__;var r=e.__denom__;var n=this.__num__;var i=e.__num__;var a,o;if(t!==r){o=r.mul(n).add(i.mul(t));a=t.mul(r)}else{o=n.add(i);a=t}return LRational({num:o,denom:a})}if(LNumber.isFloat(e)){return LFloat(this.valueOf()).add(e)}var u=LNumber.coerce(this,e),s=_slicedToArray(u,2),c=s[0],l=s[1];return c.add(l)};function LBigInteger(e,t){if(typeof this!=="undefined"&&!(this instanceof LBigInteger)||typeof this==="undefined"){return new LBigInteger(e,t)}if(e instanceof LBigInteger){return LBigInteger(e.__value__,e._native)}if(!LNumber.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.constant(e,"bigint");Object.defineProperty(this,"_native",{value:t})}LBigInteger.prototype=Object.create(LNumber.prototype);LBigInteger.prototype.constructor=LBigInteger;LBigInteger.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};LBigInteger.prototype.serialize=function(){return this.__value__.toString()};LBigInteger.prototype._op=function(e,t){if(typeof t==="undefined"){if(LNumber.isBN(this.__value__)){e=LBigInteger.bn_op[e];return LBigInteger(this.__value__.clone()[e](),false)}return LBigInteger(LNumber._ops[e](this.__value__),true)}if(LNumber.isBN(this.__value__)&&LNumber.isBN(t.__value__)){e=LBigInteger.bn_op[e];return LBigInteger(this.__value__.clone()[e](t),false)}var r=LNumber._ops[e](this.__value__,t.__value__);if(e==="/"){var n=this.op("%",t).cmp(0)===0;if(n){return LNumber(r)}return LRational({num:this,denom:t})}return LBigInteger(r,true)};LBigInteger.prototype.sqrt=function(){var e;var t=this.cmp(0)<0;if(LNumber.isNative(this.__value__)){e=LNumber(Math.sqrt(t?-this.valueOf():this.valueOf()))}else if(LNumber.isBN(this.__value__)){e=t?this.__value__.neg().sqrt():this.__value__.sqrt()}if(t){return LComplex({re:0,im:e})}return e};LNumber.NaN=LNumber(NaN);LComplex.i=LComplex({im:1,re:0});function InputPort(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof InputPort)||typeof this==="undefined"){return new InputPort(e)}typecheck("InputPort",e,"function");read_only(this,"__type__",text_port);var i;Object.defineProperty(this,"__parser__",{enumerable:true,get:function e(){return i},set:function e(t){typecheck("InputPort::__parser__",t,"parser");i=t}});this._read=e;this._with_parser=this._with_init_parser.bind(this,_asyncToGenerator(_regeneratorRuntime.mark(function e(){var r;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(n.char_ready()){t.next=5;break}t.next=3;return n._read();case 3:r=t.sent;i=new Parser(r,{env:n});case 5:return t.abrupt("return",n.__parser__);case 6:case"end":return t.stop()}},e)})));this.char_ready=function(){return!!this.__parser__&&this.__parser__.__lexer__.peek()!==eof};this._make_defaults()}InputPort.prototype._make_defaults=function(){this.read=this._with_parser(function(e){return e.read_object()});this.read_line=this._with_parser(function(e){return e.__lexer__.read_line()});this.read_char=this._with_parser(function(e){return e.__lexer__.read_char()});this.read_string=this._with_parser(function(e,t){if(!LNumber.isInteger(t)){var r=LNumber.getType(t);typeErrorMessage("read-string",r,"integer")}return e.__lexer__.read_string(t.valueOf())});this.peek_char=this._with_parser(function(e){return e.__lexer__.peek_char()})};InputPort.prototype._with_init_parser=function(u,s){var c=this;return _asyncToGenerator(_regeneratorRuntime.mark(function e(){var r,n,i,a,o=arguments;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return u.call(c);case 2:r=t.sent;for(n=o.length,i=new Array(n),a=0;a"};function OutputPort(e){if(typeof this!=="undefined"&&!(this instanceof OutputPort)||typeof this==="undefined"){return new OutputPort(e)}typecheck("OutputPort",e,"function");read_only(this,"__type__",text_port);this.write=e}OutputPort.prototype.is_open=function(){return this._closed!==true};OutputPort.prototype.close=function(){Object.defineProperty(this,"_closed",{get:function e(){return true},set:function e(){},configurable:false,enumerable:false});this.write=function(){throw new Error("output-port: port is closed")}};OutputPort.prototype.flush=function(){};OutputPort.prototype.toString=function(){return"#"};var BufferedOutputPort=function(e){_inherits(r,e);function r(e){var t;_classCallCheck(this,r);t=_callSuper(this,r,[function(){var e;return(e=t)._write.apply(e,arguments)}]);typecheck("BufferedOutputPort",e,"function");read_only(_assertThisInitialized(t),"_fn",e,{hidden:true});read_only(_assertThisInitialized(t),"_buffer",[],{hidden:true});return t}_createClass(r,[{key:"flush",value:function e(){if(this._buffer.length){this._fn(this._buffer.join(""));this._buffer.length=0}}},{key:"_write",value:function e(){var t=this;for(var r=arguments.length,n=new Array(r),i=0;i"};OutputStringPort.prototype.valueOf=function(){return this.__buffer__.map(function(e){return e.valueOf()}).join("")};function OutputFilePort(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof OutputFilePort)||typeof this==="undefined"){return new OutputFilePort(e,t)}typecheck("OutputFilePort",e,"string");read_only(this,"__filename__",e);read_only(this,"_fd",t.valueOf(),{hidden:true});read_only(this,"__type__",text_port);this.write=function(e){if(!LString.isString(e)){e=toString(e)}else{e=e.valueOf()}r.fs().write(r._fd,e,function(e){if(e){throw e}})}}OutputFilePort.prototype=Object.create(OutputPort.prototype);OutputFilePort.prototype.constructor=OutputFilePort;OutputFilePort.prototype.fs=function(){if(!this._fs){this._fs=this.internal("fs")}return this._fs};OutputFilePort.prototype.internal=function(e){return user_env.get("**internal-env**").get(e)};OutputFilePort.prototype.close=function(){var n=this;return new Promise(function(t,r){n.fs().close(n._fd,function(e){if(e){r(e)}else{read_only(n,"_fd",null,{hidden:true});OutputPort.prototype.close.call(n);t()}})})};OutputFilePort.prototype.toString=function(){return"#")};function InputStringPort(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof InputStringPort)||typeof this==="undefined"){return new InputStringPort(e)}typecheck("InputStringPort",e,"string");t=t||global_env;e=e.valueOf();this._with_parser=this._with_init_parser.bind(this,function(){if(!r.__parser__){r.__parser__=new Parser(e,{env:t})}return r.__parser__});read_only(this,"__type__",text_port);this._make_defaults()}InputStringPort.prototype.char_ready=function(){return true};InputStringPort.prototype=Object.create(InputPort.prototype);InputStringPort.prototype.constructor=InputStringPort;InputStringPort.prototype.toString=function(){return"#"};function InputByteVectorPort(e){if(typeof this!=="undefined"&&!(this instanceof InputByteVectorPort)||typeof this==="undefined"){return new InputByteVectorPort(e)}typecheck("InputByteVectorPort",e,"uint8array");read_only(this,"__vector__",e);read_only(this,"__type__",binary_port);var r=0;Object.defineProperty(this,"__index__",{enumerable:true,get:function e(){return r},set:function e(t){typecheck("InputByteVectorPort::__index__",t,"number");if(t instanceof LNumber){t=t.valueOf()}if(typeof t==="bigint"){t=Number(t)}if(Math.floor(t)!==t){throw new Error("InputByteVectorPort::__index__ value is "+"not integer")}r=t}})}InputByteVectorPort.prototype=Object.create(InputPort.prototype);InputByteVectorPort.prototype.constructor=InputByteVectorPort;InputByteVectorPort.prototype.toString=function(){return"#"};InputByteVectorPort.prototype.close=function(){var t=this;read_only(this,"__vector__",_nil);var r=function e(){throw new Error("Input-binary-port: port is closed")};["read_u8","close","peek_u8","read_u8_vector"].forEach(function(e){t[e]=r});this.u8_ready=this.char_ready=function(){return false}};InputByteVectorPort.prototype.u8_ready=function(){return true};InputByteVectorPort.prototype.peek_u8=function(){if(this.__index__>=this.__vector__.length){return eof}return this.__vector__[this.__index__]};InputByteVectorPort.prototype.skip=function(){if(this.__index__<=this.__vector__.length){++this.__index__}};InputByteVectorPort.prototype.read_u8=function(){var e=this.peek_u8();this.skip();return e};InputByteVectorPort.prototype.read_u8_vector=function(e){if(typeof e==="undefined"){e=this.__vector__.length}else if(e>this.__index__+this.__vector__.length){e=this.__index__+this.__vector__.length}if(this.peek_u8()===eof){return eof}return this.__vector__.slice(this.__index__,e)};function OutputByteVectorPort(){if(typeof this!=="undefined"&&!(this instanceof OutputByteVectorPort)||typeof this==="undefined"){return new OutputByteVectorPort}read_only(this,"__type__",binary_port);read_only(this,"_buffer",[],{hidden:true});this.write=function(e){typecheck("write",e,["number","uint8array"]);if(LNumber.isNumber(e)){this._buffer.push(e.valueOf())}else{var t;(t=this._buffer).push.apply(t,_toConsumableArray(Array.from(e)))}};Object.defineProperty(this,"__buffer__",{enumerable:true,get:function e(){return Uint8Array.from(this._buffer)}})}OutputByteVectorPort.prototype=Object.create(OutputPort.prototype);OutputByteVectorPort.prototype.constructor=OutputByteVectorPort;OutputByteVectorPort.prototype.close=function(){OutputPort.prototype.close.call(this);read_only(this,"_buffer",null,{hidden:true})};OutputByteVectorPort.prototype._close_guard=function(){if(this._closed){throw new Error("output-port: binary port is closed")}};OutputByteVectorPort.prototype.write_u8=function(e){typecheck("OutputByteVectorPort::write_u8",e,"number");this.write(e)};OutputByteVectorPort.prototype.write_u8_vector=function(e){typecheck("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};OutputByteVectorPort.prototype.toString=function(){return"#"};OutputByteVectorPort.prototype.valueOf=function(){return this.__buffer__};function InputFilePort(e,t){if(typeof this!=="undefined"&&!(this instanceof InputFilePort)||typeof this==="undefined"){return new InputFilePort(e,t)}InputStringPort.call(this,e);typecheck("InputFilePort",t,"string");read_only(this,"__filename__",t)}InputFilePort.prototype=Object.create(InputStringPort.prototype);InputFilePort.prototype.constructor=InputFilePort;InputFilePort.prototype.toString=function(){return"#")};function InputBinaryFilePort(e,t){if(typeof this!=="undefined"&&!(this instanceof InputBinaryFilePort)||typeof this==="undefined"){return new InputBinaryFilePort(e,t)}InputByteVectorPort.call(this,e);typecheck("InputBinaryFilePort",t,"string");read_only(this,"__filename__",t)}InputBinaryFilePort.prototype=Object.create(InputByteVectorPort.prototype);InputBinaryFilePort.prototype.constructor=InputBinaryFilePort;InputBinaryFilePort.prototype.toString=function(){return"#")};function OutputBinaryFilePort(e,t){var i=this;if(typeof this!=="undefined"&&!(this instanceof OutputBinaryFilePort)||typeof this==="undefined"){return new OutputBinaryFilePort(e,t)}typecheck("OutputBinaryFilePort",e,"string");read_only(this,"__filename__",e);read_only(this,"_fd",t.valueOf(),{hidden:true});read_only(this,"__type__",binary_port);var a;this.write=function(e){typecheck("write",e,["number","uint8array"]);var n;if(!a){a=i.internal("fs")}if(LNumber.isNumber(e)){n=new Uint8Array([e.valueOf()])}else{n=new Uint8Array(Array.from(e))}return new Promise(function(t,r){a.write(i._fd,n,function(e){if(e){r(e)}else{t()}})})}}OutputBinaryFilePort.prototype=Object.create(OutputFilePort.prototype);OutputBinaryFilePort.prototype.constructor=OutputBinaryFilePort;OutputBinaryFilePort.prototype.write_u8=function(e){typecheck("OutputByteVectorPort::write_u8",e,"number");this.write(e)};OutputBinaryFilePort.prototype.write_u8_vector=function(e){typecheck("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};var binary_port=Symbol["for"]("binary");var text_port=Symbol["for"]("text");var eof=new EOF;function EOF(){}EOF.prototype.toString=function(){return"#"};function Interpreter(e){var t=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=r.stderr,i=r.stdin,a=r.stdout,o=r.command_line,u=o===void 0?null:o,s=_objectWithoutProperties(r,_excluded3);if(typeof this!=="undefined"&&!(this instanceof Interpreter)||typeof this==="undefined"){return new Interpreter(e,_objectSpread({stdin:i,stdout:a,stderr:n,command_line:u},s))}if(typeof e==="undefined"){e="anonymous"}this.__env__=user_env.inherit(e,s);this.__env__.set("parent.frame",doc("parent.frame",function(){return t.__env__},global_env.__env__["parent.frame"].__doc__));var c="**interaction-environment-defaults**";this.set(c,get_props(s).concat(c));var l=internal_env.inherit("internal-".concat(e));if(is_port(i)){l.set("stdin",i)}if(is_port(n)){l.set("stderr",n)}if(is_port(a)){l.set("stdout",a)}l.set("command-line",u);set_interaction_env(this.__env__,l)}Interpreter.prototype.exec=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=t.use_dynamic,n=r===void 0?false:r,i=t.dynamic_env,a=t.env;typecheck("Interpreter::exec",e,["string","array"],1);typecheck("Interpreter::exec",n,"boolean",2);if(!a){a=this.__env__}if(!i){i=a}global_env.set("**interaction-environment**",this.__env__);return exec(e,{env:a,dynamic_env:i,use_dynamic:n})};Interpreter.prototype.get=function(e){var t=this.__env__.get(e);if(is_function(t)){var r=new LambdaContext({env:this.__env__});return t.bind(r)}return t};Interpreter.prototype.set=function(e,t){return this.__env__.set(e,t)};Interpreter.prototype.constant=function(e,t){return this.__env__.constant(e,t)};function LipsError(e,t){this.name="LipsError";this.message=e;this.args=t;this.stack=(new Error).stack}LipsError.prototype=new Error;LipsError.prototype.constructor=LipsError;var IgnoreException=function(e){_inherits(t,e);function t(){_classCallCheck(this,t);return _callSuper(this,t,arguments)}return _createClass(t)}(_wrapNativeSuper(Error));function Environment(e,t,r){if(arguments.length===1){if(_typeof$1(arguments[0])==="object"){e=arguments[0];t=null}else if(typeof arguments[0]==="string"){e={};t=null;r=arguments[0]}}this.__docs__=new Map;this.__env__=e;this.__parent__=t;this.__name__=r||"anonymous"}Environment.prototype.list=function(){return get_props(this.__env__)};Environment.prototype.fs=function(){return this.get("**fs**")};Environment.prototype.unset=function(e){if(e instanceof LSymbol){e=e.valueOf()}if(e instanceof LString){e=e.valueOf()}delete this.__env__[e]};Environment.prototype.inherit=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(_typeof$1(e)==="object"){t=e}if(!e||_typeof$1(e)==="object"){e="child of "+(this.__name__||"unknown")}return new Environment(t||{},this,e)};Environment.prototype.doc=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}if(t){if(!r){t=trim_lines(t)}this.__docs__.set(e,t);return this}if(this.__docs__.has(e)){return this.__docs__.get(e)}if(this.__parent__){return this.__parent__.doc(e)}};Environment.prototype.new_frame=function(e,t){var n=this.inherit("__frame__");n.set("parent.frame",doc("parent.frame",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;e=e.valueOf();var t=n.__parent__;if(!is_env(t)){return _nil}if(e<=0){return t}var r=t.get("parent.frame");return r(e-1)},global_env.__env__["parent.frame"].__doc__));t.callee=e;n.set("arguments",t);return n};Environment.prototype._lookup=function(e){if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}if(this.__env__.hasOwnProperty(e)){return Value(this.__env__[e])}if(this.__parent__){return this.__parent__._lookup(e)}};Environment.prototype.toString=function(){return"#"};Environment.prototype.clone=function(){var t=this;var r={};Object.keys(this.__env__).forEach(function(e){r[e]=t.__env__[e]});return new Environment(r,this.__parent__,this.__name__)};Environment.prototype.merge=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"merge";typecheck("Environment::merge",e,"environment");return this.inherit(t,e.__env__)};function Value(e){if(typeof this!=="undefined"&&!(this instanceof Value)||typeof this==="undefined"){return new Value(e)}this.value=e}Value.isUndefined=function(e){return e instanceof Value&&typeof e.value==="undefined"};Value.prototype.valueOf=function(){return this.value};function Values(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof Values)||typeof this==="undefined"){return new Values(e)}this.__values__=e}Values.prototype.toString=function(){return this.__values__.map(function(e){return toString(e)}).join("\n")};Values.prototype.valueOf=function(){return this.__values__};Environment.prototype.get=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};typecheck("Environment::get",e,["symbol","string"]);var r=t.throwError,n=r===void 0?true:r;var i=e;if(i instanceof LSymbol||i instanceof LString){i=i.valueOf()}var a=this._lookup(i);if(a instanceof Value){if(Value.isUndefined(a)){return undefined}return patch_value(a.valueOf())}var o;if(e instanceof LSymbol&&e[LSymbol.object]){o=e[LSymbol.object]}else if(typeof i==="string"){o=i.split(".").filter(Boolean)}if(o&&o.length>0){var u=o,s=_toArray(u),c=s[0],l=s.slice(1);a=this._lookup(c);if(l.length){try{if(a instanceof Value){a=a.valueOf()}else{a=get(root,c);if(is_function(a)){a=unbind(a)}}if(typeof a!=="undefined"){return get.apply(void 0,[a].concat(_toConsumableArray(l)))}}catch(e){throw e}}else if(a instanceof Value){return patch_value(a.valueOf())}a=get(root,i)}if(typeof a!=="undefined"){return a}if(n){throw new Error("Unbound variable `"+i.toString()+"'")}};Environment.prototype.set=function(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;typecheck("Environment::set",e,["string","symbol"]);if(LNumber.isNumber(t)){t=LNumber(t)}if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}this.__env__[e]=t;if(r){this.doc(e,r,true)}return this};Environment.prototype.constant=function(t,e){var r=this;if(this.__env__.hasOwnProperty(t)){throw new Error("Environment::constant: ".concat(t," already exists"))}if(arguments.length===1&&is_plain_object(arguments[0])){var n=arguments[0];Object.keys(n).forEach(function(e){r.constant(t,n[e])})}else{Object.defineProperty(this.__env__,t,{value:e,enumerable:true})}return this};Environment.prototype.has=function(e){return this.__env__.hasOwnProperty(e)};Environment.prototype.ref=function(e){var t=this;while(true){if(!t){break}if(t.has(e)){return t}t=t.__parent__}};Environment.prototype.parents=function(){var e=this;var t=[];while(e){t.unshift(e);e=e.__parent__}return t};function quote(e){if(is_promise(e)){return e.then(quote)}if(is_pair(e)||e instanceof LSymbol){e[__data__]=true}return e}var native_lambda=_parse(tokenize('(lambda ()\n "[native code]"\n (throw "Invalid Invocation"))'))[0];var get=doc("get",function e(t){var r;for(var n=arguments.length,i=new Array(n>1?n-1:0),a=1;a0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=internal(this,"stdin")}typecheck_text_port("peek-char",e,"input-port");return e.peek_char()},"(peek-char port)\n\n This function reads and returns a character from the string\n port, or, if there is no more data in the string port, it\n returns an EOF."),"read-line":doc("read-line",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=internal(this,"stdin")}typecheck_text_port("read-line",e,"input-port");return e.read_line()},"(read-line port)\n\n This function reads and returns the next line from the input\n port."),"read-char":doc("read-char",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=internal(this,"stdin")}typecheck_text_port("read-char",e,"input-port");return e.read_char()},"(read-char port)\n\n This function reads and returns the next character from the\n input port."),read:doc("read",function(){var e=_asyncToGenerator(function(){var i=this;var a=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;return _regeneratorRuntime.mark(function e(){var r,n;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=i.env;if(a===null){n=internal(r,"stdin")}else{n=a}typecheck_text_port("read",n,"input-port");return t.abrupt("return",n.read.call(r));case 4:case"end":return t.stop()}},e)})()});function t(){return e.apply(this,arguments)}return t}(),"(read [port])\n\n This function, if called with a port, it will parse the next\n item from the port. If called without an input, it will read\n a string from standard input (using the browser's prompt or\n a user defined input method) and parse it. This function can be\n used together with `eval` to evaluate code from port."),pprint:doc("pprint",function e(t){if(is_pair(t)){t=new lips.Formatter(t.toString(true))["break"]().format();global_env.get("display").call(global_env,t)}else{global_env.get("write").call(global_env,t)}global_env.get("newline").call(global_env)},"(pprint expression)\n\n This function will pretty print its input to stdout. If it is called\n with a non-list, it will just call the print function on its\n input."),print:doc("print",function e(){var t=global_env.get("display");var r=global_env.get("newline");var n=this.use_dynamic;var i=global_env;var a=global_env;for(var o=arguments.length,u=new Array(o),s=0;s1?r-1:0),i=1;in.length){throw new Error("Not enough arguments")}var u=0;var s=global_env.get("repr");t=t.replace(a,function(e){var t=e[1];if(t==="~"){return"~"}else if(t==="%"){return"\n"}else{var r=n[u++];if(t==="a"){return s(r)}else{return s(r,true)}}});o=t.match(/~([\S])/);if(o){throw new Error("format: Unrecognized escape sequence ".concat(o[1]))}return t},"(format string n1 n2 ...)\n\n This function accepts a string template and replaces any\n escape sequences in its inputs:\n\n * ~a value as if printed with `display`\n * ~s value as if printed with `write`\n * ~% newline character\n * ~~ literal tilde '~'\n\n If there are missing inputs or other escape characters it\n will error."),display:doc("display",function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(r===null){r=internal(this,"stdout")}else{typecheck("display",r,"output-port")}var n=t;if(!(r instanceof OutputBinaryFilePort)){n=global_env.get("repr")(t)}r.write.call(global_env,n)},"(display string [port])\n\n This function outputs the string to the standard output or\n the port if given. No newline."),"display-error":doc("display-error",function e(){var t=internal(this,"stderr");var r=global_env.get("repr");for(var n=arguments.length,i=new Array(n),a=0;a1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=_objectWithoutProperties(t,_excluded4);var i=this;var o=this;var u;var s=_objectSpread(_objectSpread({},n),{},{env:this,dynamic_env:i,use_dynamic:r});var c=_evaluate(e.cdr.car,s);c=resolve_promises(c);function l(t,r,n){if(is_promise(t)){return t.then(function(e){return l(t,e,n)})}if(is_promise(r)){return r.then(function(e){return l(t,e,n)})}if(is_promise(n)){return n.then(function(e){return l(t,r,e)})}o.get("set-obj!").call(o,t,r,n);return n}if(is_pair(e.car)&&LSymbol.is(e.car.car,".")){var f=e.car.cdr.car;var _=e.car.cdr.cdr.car;var p=_evaluate(f,s);var d=_evaluate(_,s);return l(p,d,c)}if(!(e.car instanceof LSymbol)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var h=e.car.valueOf();u=this.ref(e.car.__name__);return unpromise(c,function(e){if(!u){var t=h.split(".");if(t.length>1){var r=t.pop();var n=t.join(".");var i=a.get(n,{throwError:false});if(i){l(i,r,e);return}}throw new Error("Unbound variable `"+h+"'")}u.set(h,e)})}),"(set! name value)\n\n Macro that can be used to set the value of the variable or slot (mutate it).\n set! searches the scope chain until it finds first non empty slot and sets it."),"unset!":doc(new Macro("set!",function(e){if(!(e.car instanceof LSymbol)){throw new Error("unset! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var t=e.car;var r=this.ref(t);if(r){delete r.__env__[t.__name__]}}),"(unset! name)\n\n Function to delete the specified name from environment.\n Trying to access the name afterwards will error."),"set-car!":doc("set-car!",function(e,t){typecheck("set-car!",e,"pair");e.car=t},"(set-car! obj value)\n\n Function that sets the car (first item) of the list/pair to specified value.\n The old value is lost."),"set-cdr!":doc("set-cdr!",function(e,t){typecheck("set-cdr!",e,"pair");e.cdr=t},"(set-cdr! obj value)\n\n Function that sets the cdr (tail) of the list/pair to specified value.\n It will destroy the list. The old tail is lost."),"empty?":doc("empty?",function(e){return typeof e==="undefined"||is_nil(e)},"(empty? object)\n\n Function that returns #t if value is nil (an empty list) or undefined."),gensym:doc("gensym",gensym,"(gensym)\n\n Generates a unique symbol that is not bound anywhere,\n to use with macros as meta name."),load:doc("load",function e(u,t){typecheck("load",u,"string");var s=this;if(s.__name__==="__frame__"){s=s.__parent__}if(!(t instanceof Environment)){if(s===global_env){t=s}else{t=this.get("**interaction-environment**")}}var c="**module-path**";var l=global_env.get(c,{throwError:false});u=u.valueOf();if(!u.match(/.[^.]+$/)){u+=".scm"}var r=u.match(/\.xcb$/);function f(e){if(r){e=unserialize_bin(e)}else{if(type(e)==="buffer"){e=e.toString()}e=e.replace(/^#!.*/,"");if(e.match(/^\{/)){e=unserialize(e)}}return exec(e,{env:t})}function n(e){return root.fetch(e).then(function(e){return r?e.arrayBuffer():e.text()}).then(function(e){if(r){e=new Uint8Array(e)}return e})}if(is_node()){return new Promise(function(){var r=_asyncToGenerator(_regeneratorRuntime.mark(function e(r,n){var i,a,o;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:i=nodeRequire("path");if(!l){t.next=6;break}l=l.valueOf();u=i.join(l,u);t.next=12;break;case 6:a=s.get("command-line",{throwError:false});if(!a){t.next=11;break}t.next=10;return a();case 10:o=t.sent;case 11:if(o&&!is_nil(o)){process.cwd();u=i.join(i.dirname(o.car.valueOf()),u)}case 12:global_env.set(c,i.dirname(u));nodeRequire("fs").readFile(u,function(e,t){if(e){n(e);global_env.set(c,l)}else{try{f(t).then(function(){r();global_env.set(c,l)})["catch"](n)}catch(e){n(e)}}});case 14:case"end":return t.stop()}},e)}));return function(e,t){return r.apply(this,arguments)}}())}if(l){l=l.valueOf();u=l+"/"+u.replace(/^\.?\/?/,"")}return n(u).then(function(e){global_env.set(c,u.replace(/\/[^/]*$/,""));return f(e)}).then(function(){})["finally"](function(){global_env.set(c,l)})},"(load filename)\n (load filename environment)\n\n Fetches the file (from disk or network) and evaluates its content as LIPS code.\n If the second argument is provided and it's an environment the evaluation\n will happen in that environment."),while:doc(new Macro("while",function(e,t){var r=e.car;var n=_objectSpread(_objectSpread({},t),{},{env:this});var i=new Pair(new LSymbol("begin"),e.cdr);return function t(){return unpromise(_evaluate(r,n),function(e){if(e){return unpromise(_evaluate(i,n),t)}})}()}),"(while cond body)\n\n Creates a loop, it executes cond and body until cond expression is false."),do:doc(new Macro("do",function(){var r=_asyncToGenerator(function(_,e){var p=this;var d=e.use_dynamic,h=e.error;return _regeneratorRuntime.mark(function e(){var u,r,s,c,n,l,f,i,a,o;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:u=p;r=u;s=u.inherit("do");c=_.car;n=_.cdr.car;l=_.cdr.cdr;if(!is_nil(l)){l=new Pair(LSymbol("begin"),l)}f={env:u,dynamic_env:r,use_dynamic:d,error:h};i=c;case 9:if(is_nil(i)){t.next=20;break}a=i.car;t.t0=s;t.t1=a.car;t.next=15;return _evaluate(a.cdr.car,f);case 15:t.t2=t.sent;t.t0.set.call(t.t0,t.t1,t.t2);i=i.cdr;t.next=9;break;case 20:f={env:s,dynamic_env:r,error:h};o=_regeneratorRuntime.mark(function e(){var r,n,i,a,o;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(is_nil(l)){t.next=3;break}t.next=3;return lips.evaluate(l,f);case 3:r=c;n={};case 5:if(is_nil(r)){t.next=15;break}i=r.car;if(is_nil(i.cdr.cdr)){t.next=12;break}t.next=10;return _evaluate(i.cdr.cdr.car,f);case 10:a=t.sent;n[i.car.valueOf()]=a;case 12:r=r.cdr;t.next=5;break;case 15:o=Object.getOwnPropertySymbols(n);f.env=s=u.inherit("do");Object.keys(n).concat(o).forEach(function(e){s.set(e,n[e])});case 18:case"end":return t.stop()}},e)});case 22:t.next=24;return _evaluate(n.car,f);case 24:t.t3=t.sent;if(!(t.t3===false)){t.next=29;break}return t.delegateYield(o(),"t4",27);case 27:t.next=22;break;case 29:if(is_nil(n.cdr)){t.next=33;break}t.next=32;return _evaluate(n.cdr.car,f);case 32:return t.abrupt("return",t.sent);case 33:case"end":return t.stop()}},e)})()});return function(e,t){return r.apply(this,arguments)}}()),"(do (( )) (test return) . body)\n\n Iteration macro that evaluates the expression body in scope of the variables.\n On each loop it changes the variables according to the expression and runs\n test to check if the loop should continue. If test is a single value, the macro\n will return undefined. If the test is a pair of expressions the macro will\n evaluate and return the second expression after the loop exits."),if:doc(new Macro("if",function(r,e){var t=e.error,n=e.use_dynamic;var i=this;var a=this;var o={env:a,dynamic_env:i,use_dynamic:n,error:t};var u=function e(t){if(t===false){return _evaluate(r.cdr.cdr.car,o)}else{return _evaluate(r.cdr.car,o)}};if(is_nil(r)){throw new Error("too few expressions for `if`")}var s=_evaluate(r.car,o);return unpromise(s,u)}),"(if cond true-expr false-expr)\n\n Macro that evaluates cond expression and if the value is true, it\n evaluates and returns true-expression, if not it evaluates and returns\n false-expression."),"let-env":new Macro("let-env",function(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=e.dynamic_env,n=e.use_dynamic,i=e.error;typecheck("let-env",t,"pair");var a=_evaluate(t.car,{env:this,dynamic_env:r,error:i,use_dynamic:n});return unpromise(a,function(e){typecheck("let-env",e,"environment");return _evaluate(Pair(LSymbol("begin"),t.cdr),{env:e,dynamic_env:r,error:i})})},"(let-env env . body)\n\n Special macro that evaluates body in context of given environment\n object."),letrec:doc(let_macro(Symbol["for"]("letrec")),"(letrec ((a value-a) (b value-b) ...) . body)\n\n Macro that creates a new environment, then evaluates and assigns values to\n names and then evaluates the body in context of that environment.\n Values are evaluated sequentially and the next value can access the\n previous values/names."),"letrec*":doc(let_macro(Symbol["for"]("letrec")),"(letrec* ((a value-a) (b value-b) ...) . body)\n\n Same as letrec but the order of execution of the binding is guaranteed,\n so you can use recursive code as well as referencing the previous binding.\n\n In LIPS both letrec and letrec* behave the same."),"let*":doc(let_macro(Symbol["for"]("let*")),"(let* ((a value-a) (b value-b) ...) . body)\n\n Macro similar to `let`, but the subsequent bindings after the first\n are evaluated in the environment including the previous let variables,\n so you can define one variable, and use it in the next's definition."),let:doc(let_macro(Symbol["for"]("let")),"(let ((a value-a) (b value-b) ...) . body)\n\n Macro that creates a new environment, then evaluates and assigns values to names,\n and then evaluates the body in context of that environment. Values are evaluated\n sequentially but you can't access previous values/names when the next are\n evaluated. You can only get them in the body of the let expression. (If you want\n to define multiple variables and use them in each other's definitions, use\n `let*`.)"),"begin*":doc(parallel("begin*",function(e){return e.pop()}),"(begin* . body)\n\n This macro is a parallel version of begin. It evaluates each expression\n in the body and if it's a promise it will await it in parallel and return\n the value of the last expression (i.e. it uses Promise.all())."),shuffle:doc("shuffle",function(e){typecheck("shuffle",e,["pair","nil","array"]);var t=global_env.get("random");if(is_nil(e)){return _nil}if(Array.isArray(e)){return shuffle(e.slice(),t)}var r=global_env.get("list->array")(e);r=shuffle(r,t);return global_env.get("array->list")(r)},"(shuffle obj)\n\n Order items in vector or list in random order."),begin:doc(new Macro("begin",function(e,t){var n=_objectSpread(_objectSpread({},t),{},{env:this});var i=global_env.get("list->array")(e);var a;return function t(){if(i.length){var e=i.shift();var r=_evaluate(e,n);return unpromise(r,function(e){a=e;return t()})}else{return a}}()}),"(begin . args)\n\n Macro that runs a list of expressions in order and returns the value\n of the last one. It can be used in places where you can only have a\n single expression, like (if)."),ignore:new Macro("ignore",function(e,t){var r=_objectSpread(_objectSpread({},t),{},{env:this,dynamic_env:this});_evaluate(new Pair(new LSymbol("begin"),e),r)},"(ignore . body)\n\n Macro that will evaluate the expression and swallow any promises that may\n be created. It will discard any value that may be returned by the last body\n expression. The code should have side effects and/or when it's promise\n it should resolve to undefined."),"call/cc":doc(Macro.defmacro("call/cc",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=_objectSpread({env:this},t);return unpromise(_evaluate(e.car,r),function(e){if(is_function(e)){return e(new Continuation(null))}})}),"(call/cc proc)\n\n Call-with-current-continuation.\n\n NOT SUPPORTED BY LIPS RIGHT NOW"),parameterize:doc(new Macro("parameterize",function(t,e){var i=e.dynamic_env;var a=i.inherit("parameterize").new_frame(null,{});var o=_objectSpread(_objectSpread({},e),{},{env:this});var u=t.car;if(!is_pair(u)){var r=type(u);throw new Error("Invalid syntax for parameterize expecting pair got ".concat(r))}function s(){var e=new Pair(new LSymbol("begin"),t.cdr);return _evaluate(e,_objectSpread(_objectSpread({},o),{},{dynamic_env:a}))}return function r(){var e=u.car;var n=e.car.valueOf();return unpromise(_evaluate(e.cdr.car,o),function(e){var t=i.get(n,{throwError:false});if(!is_parameter(t)){throw new Error("Unknown parameter ".concat(n))}a.set(n,t.inherit(e));if(!is_null(u.cdr)){u=u.cdr;return r()}else{return s()}})}()}),"(parameterize ((name value) ...)\n\n Macro that change the dynamic variable created by make-parameter."),"make-parameter":doc(new Macro("make-parameter",function(e,t){t.dynamic_env;var r=_evaluate(e.car,t);var n;if(is_pair(e.cdr.car)){n=_evaluate(e.cdr.car,t)}return new Parameter(r,n)}),"(make-parameter init converter)\n\n Function creates new dynamic variable that can be custimized with parameterize\n macro. The value should be assigned to a variable e.g.:\n\n (define radix (make-parameter 10))\n\n The result value is a procedure that return the value of dynamic variable."),"define-syntax-parameter":doc(new Macro("define-syntax-parameter",function(e,t){var r=e.car;var n=this;if(!(r instanceof LSymbol)){throw new Error("define-syntax-parameter: invalid syntax expecting symbol got ".concat(type(r)))}var i=_evaluate(e.cdr.car,_objectSpread({env:n},t));typecheck("define-syntax-parameter",i,"syntax",2);i.__name__=r.valueOf();if(i.__name__ instanceof LString){i.__name__=i.__name__.valueOf()}var a;if(is_pair(e.cdr.cdr)&&LString.isString(e.cdr.cdr.car)){a=e.cdr.cdr.car.valueOf()}n.set(e.car,new SyntaxParameter(i),a,true)}),"(define-syntax-parameter name syntax [__doc__])\n\n Binds to the transformer obtained by evaluating .\n The transformer provides the default expansion for the syntax parameter,\n and in the absence of syntax-parameterize, is functionally equivalent to\n define-syntax."),"syntax-parameterize":doc(new Macro("syntax-parameterize",function(e,t){var r=global_env.get("list->array")(e.car);var n=this.inherit("syntax-parameterize");while(r.length){var i=r.shift();if(!(is_pair(i)||i.car instanceof LSymbol)){var a="invalid syntax for syntax-parameterize: ".concat(repr(e,true));throw new Error("syntax-parameterize: ".concat(a))}var o=_evaluate(i.cdr.car,_objectSpread(_objectSpread({},t),{},{env:this}));var u=i.car;typecheck("syntax-parameterize",o,["syntax"]);typecheck("syntax-parameterize",u,"symbol");o.__name__=u.valueOf();if(o.__name__ instanceof LString){o.__name__=o.__name__.valueOf()}var s=new SyntaxParameter(o);if(u.is_gensym()){var c=u.literal();var l=this.get(c,{throwError:false});if(l instanceof SyntaxParameter){n.set(c,s)}}n.set(u,s)}var f=new Pair(new LSymbol("begin"),e.cdr);return _evaluate(f,_objectSpread(_objectSpread({},t),{},{env:n}))}),"(syntax-parameterize (bindings) body)\n\n Macro work similar to let-syntax but the the bindnds will be exposed to the user.\n With syntax-parameterize you can define anaphoric macros."),define:doc(Macro.defmacro("define",function(r,e){var n=this;if(is_pair(r.car)&&r.car.car instanceof LSymbol){var t=new Pair(new LSymbol("define"),new Pair(r.car.car,new Pair(new Pair(new LSymbol("lambda"),new Pair(r.car.cdr,r.cdr)))));return t}else if(e.macro_expand){return}e.dynamic_env=this;e.env=n;var i=r.cdr.car;var a;if(is_pair(i)){i=_evaluate(i,e);a=true}else if(i instanceof LSymbol){i=n.get(i)}typecheck("define",r.car,"symbol");return unpromise(i,function(e){if(n.__name__===Syntax.__merge_env__){n=n.__parent__}if(a&&(is_function(e)&&is_lambda(e)||e instanceof Syntax||is_parameter(e))){e.__name__=r.car.valueOf();if(e.__name__ instanceof LString){e.__name__=e.__name__.valueOf()}}var t;if(is_pair(r.cdr.cdr)&&LString.isString(r.cdr.cdr.car)){t=r.cdr.cdr.car.valueOf()}n.set(r.car,e,t,true)})}),'(define name expression)\n (define name expression "doc string")\n (define (function-name . args) . body)\n\n Macro for defining values. It can be used to define variables,\n or functions. If the first argument is list it will create a function\n with name being first element of the list. This form expands to\n `(define function-name (lambda args body))`'),"set-obj!":doc("set-obj!",function(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;var i=_typeof$1(e);if(is_null(e)||i!=="object"&&i!=="function"){var a=typeErrorMessage("set-obj!",type(e),["object","function"]);throw new Error(a)}typecheck("set-obj!",t,["string","symbol","number"]);e=unbind(e);t=t.valueOf();if(arguments.length===2){delete e[t]}else if(is_prototype(e)&&is_function(r)){e[t]=unbind(r);e[t][__prototype__]=true}else if(is_function(r)||is_native(r)||is_nil(r)){e[t]=r}else{e[t]=r&&!is_prototype(r)?r.valueOf():r}if(props){var o=e[t];Object.defineProperty(e,t,_objectSpread(_objectSpread({},n),{},{value:o}))}},"(set-obj! obj key value)\n (set-obj! obj key value props)\n\n Function set a property of a JavaScript object. props should be a vector of pairs,\n passed to Object.defineProperty."),"null-environment":doc("null-environment",function(){return global_env.inherit("null")},"(null-environment)\n\n Returns a clean environment with only the standard library."),values:doc("values",function e(){for(var t=arguments.length,r=new Array(t),n=0;n1&&arguments[1]!==undefined?arguments[1]:{},y=e.use_dynamic,v=e.error;var b=this;var g;if(is_pair(m.cdr)&&LString.isString(m.cdr.car)&&!is_nil(m.cdr.cdr)){g=m.cdr.car.valueOf()}function w(){var e=is_context(this)?this:{dynamic_env:b},r=e.dynamic_env;var n=b.inherit("lambda");r=r.inherit("lambda");if(this&&!is_context(this)){if(this&&!this.__instance__){Object.defineProperty(this,"__instance__",{enumerable:false,get:function e(){return true},set:function e(){},configurable:false})}n.set("this",this)}for(var t=arguments.length,i=new Array(t),a=0;a> SYNTAX");log(e);log(v);var n=w.inherit("syntax");var i=n;var a=this;if(a.__name__===Syntax.__merge_env__){var o=Object.getOwnPropertySymbols(a.__env__);o.forEach(function(e){a.__parent__.set(e,a.__env__[e])});a=a.__parent__}var u={env:n,dynamic_env:i,use_dynamic:b,error:g};var s,c,l;if(v.car instanceof LSymbol){s=v.car;l=D(v.cdr.car);c=v.cdr.cdr}else{s="...";l=D(v.car);c=v.cdr}try{while(!is_nil(c)){var f=c.car.car;var _=c.car.cdr.car;log("[[[ RULE");log(f);var p=extract_patterns(f,e,l,s,{expansion:this,define:w});if(p){if(is_debug()){console.log(JSON.stringify(symbolize(p),true,2));console.log("PATTERN: "+f.toString(true));console.log("MACRO: "+e.toString(true))}var d=[];var h=transform_syntax({bindings:p,expr:_,symbols:l,scope:n,lex_scope:a,names:d,ellipsis:s});log("OUPUT>>> ",h);if(h){_=h}var m=a.merge(n,Syntax.__merge_env__);if(r){return{expr:_,scope:m}}var y=_evaluate(_,_objectSpread(_objectSpread({},u),{},{env:m}));return clear_gensyms(y,d)}c=c.cdr}}catch(e){e.message+="\nin macro:\n ".concat(v.toString(true));throw e}throw new Error("syntax-rules: no matching syntax in macro ".concat(e.toString(true)))},w);r.__code__=v;return r},"(syntax-rules () (pattern expression) ...)\n\n Base of hygienic macros, it will return a new syntax expander\n that works like Lisp macros."),quote:doc(new Macro("quote",function(e){return quote(e.car)}),"(quote expression) or 'expression\n\n Macro that returns a single LIPS expression as data (it won't evaluate the\n argument). It will return a list if put in front of LIPS code.\n And if put in front of a symbol it will return the symbol itself, not the value\n bound to that name."),"unquote-splicing":doc("unquote-splicing",function(){throw new Error("You can't call `unquote-splicing` outside of quasiquote")},"(unquote-splicing code) or ,@code\n\n Special form used in the quasiquote macro. It evaluates the expression inside and\n splices the list into quasiquote's result. If it is not the last element of the\n expression, the computed value must be a pair."),unquote:doc("unquote",function(){throw new Error("You can't call `unquote` outside of quasiquote")},"(unquote code) or ,code\n\n Special form used in the quasiquote macro. It evaluates the expression inside and\n substitutes the value into quasiquote's result."),quasiquote:Macro.defmacro("quasiquote",function(e,t){var u=t.use_dynamic,s=t.error;var c=this;var l=c;function a(e){return is_pair(e)||is_plain_object(e)||Array.isArray(e)}function f(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:a;if(is_pair(e)){var n=e.car;var i=e.cdr;if(r(n)){n=t(n)}if(r(i)){i=t(i)}if(is_promise(n)||is_promise(i)){return promise_all([n,i]).then(function(e){var t=_slicedToArray(e,2),r=t[0],n=t[1];return new Pair(r,n)})}else{return new Pair(n,i)}}return e}function o(e,t){if(is_pair(e)){if(!is_nil(t)){e.append(t)}}else{e=new Pair(e,t)}return e}function r(e){return!!e.filter(function(e){return is_pair(e)&&LSymbol.is(e.car,/^(unquote|unquote-splicing)$/)}).length}function _(e,n,i){return e.reduce(function(e,t){if(!is_pair(t)){e.push(t);return e}if(LSymbol.is(t.car,"unquote-splicing")){var r;if(n+11){var t="You can't splice multiple atoms inside list";throw new Error(t)}if(!(is_pair(i.cdr)&&is_nil(r[0]))){return r[0]}}r=r.map(function(e){if(h.has(e)){return e.clone()}else{h.add(e);return e}});var n=m(i.cdr,0,1);if(is_nil(n)&&is_nil(r[0])){return undefined}return unpromise(n,function(e){if(is_nil(r[0])){return e}if(r.length===1){return o(r[0],e)}var t=r.reduce(function(e,t){return o(e,t)});return o(t,e)})})}(i.car.cdr)}var h=new Set;function m(e,t,r){if(is_pair(e)){if(is_pair(e.car)){if(LSymbol.is(e.car.car,"unquote-splicing")){return d(e,t+1,r)}if(LSymbol.is(e.car.car,"unquote")){if(t+2===r&&is_pair(e.car.cdr)&&is_pair(e.car.cdr.car)&&LSymbol.is(e.car.cdr.car.car,"unquote-splicing")){var n=e.car.cdr;return new Pair(new Pair(new LSymbol("unquote"),d(n,t+2,r)),_nil)}else if(is_pair(e.car.cdr)&&!is_nil(e.car.cdr.cdr)){if(is_pair(e.car.cdr.car)){var i=[];return function t(r){if(is_nil(r)){return Pair.fromArray(i)}return unpromise(_evaluate(r.car,{env:c,dynamic_env:l,use_dynamic:u,error:s}),function(e){i.push(e);return t(r.cdr)})}(e.car.cdr)}else{return e.car.cdr}}}}if(LSymbol.is(e.car,"quasiquote")){var a=m(e.cdr,t,r+1);return new Pair(e.car,a)}if(LSymbol.is(e.car,"quote")){return new Pair(e.car,m(e.cdr,t,r))}if(LSymbol.is(e.car,"unquote")){t++;if(tr){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(is_pair(e.cdr)){if(!is_nil(e.cdr.cdr)){if(is_pair(e.cdr.car)){var o=[];return function t(r){if(is_nil(r)){return Pair.fromArray(o)}return unpromise(_evaluate(r.car,{env:c,dynamic_env:l,use_dynamic:u,error:s}),function(e){o.push(e);return t(r.cdr)})}(e.cdr)}else{return e.cdr}}else{return _evaluate(e.cdr.car,{env:c,dynamic_env:l,error:s})}}else{return e.cdr}}return f(e,function(e){return m(e,t,r)})}else if(is_plain_object(e)){return p(e,t,r)}else if(e instanceof Array){return _(e,t,r)}return e}function n(e){if(is_pair(e)){delete e[__data__];if(!e.have_cycles("car")){n(e.car)}if(!e.have_cycles("cdr")){n(e.cdr)}}}if(is_plain_object(e.car)&&!r(Object.values(e.car))){return quote(e.car)}if(Array.isArray(e.car)&&!r(e.car)){return quote(e.car)}if(is_pair(e.car)&&!e.car.find("unquote")&&!e.car.find("unquote-splicing")&&!e.car.find("quasiquote")){return quote(e.car)}var i=m(e.car,0,1);return unpromise(i,function(e){n(e);return quote(e)})},"(quasiquote list)\n\n Similar macro to `quote` but inside it you can use special expressions (unquote\n x) abbreviated to ,x that will evaluate x and insert its value verbatim or\n (unquote-splicing x) abbreviated to ,@x that will evaluate x and splice the value\n into the result. Best used with macros but it can be used outside."),clone:doc("clone",function e(t){typecheck("clone",t,"pair");return t.clone()},"(clone list)\n\n Function that returns a clone of the list, that does not share any pairs with the\n original, so the clone can be safely mutated without affecting the original."),append:doc("append",function e(){var t;for(var r=arguments.length,n=new Array(r),i=0;iarray")(t).reverse();return global_env.get("array->list")(r)}else if(Array.isArray(t)){return t.reverse()}else{throw new Error(typeErrorMessage("reverse",type(t),"array or pair"))}},"(reverse list)\n\n Function that reverses the list or array. If value is not a list\n or array it will error."),nth:doc("nth",function e(t,r){typecheck("nth",t,"number");typecheck("nth",r,["array","pair"]);if(is_pair(r)){var n=r;var i=0;while(iarray")(r).join(t)},"(join separator list)\n\n Function that returns a string by joining elements of the list using separator."),split:doc("split",function e(t,r){typecheck("split",t,["regex","string"]);typecheck("split",r,"string");return global_env.get("array->list")(r.split(t))},"(split separator string)\n\n Function that creates a list by splitting string by separator which can\n be a string or regular expression."),replace:doc("replace",function e(t,r,n){typecheck("replace",t,["regex","string"]);typecheck("replace",r,["string","function"]);typecheck("replace",n,"string");return n.replace(t,r)},"(replace pattern replacement string)\n\n Function that changes pattern to replacement inside string. Pattern can be a\n string or regex and replacement can be function or string. See Javascript\n String.replace()."),match:doc("match",function e(t,r){typecheck("match",t,["regex","string"]);typecheck("match",r,"string");var n=r.match(t);return n?global_env.get("array->list")(n):false},"(match pattern string)\n\n Function that returns a match object from JavaScript as a list or #f if\n no match."),search:doc("search",function e(t,r){typecheck("search",t,["regex","string"]);typecheck("search",r,"string");return r.search(t)},"(search pattern string)\n\n Function that returns the first found index of the pattern inside a string."),repr:doc("repr",function e(t,r){return toString(t,r)},"(repr obj)\n\n Function that returns a LIPS code representation of the object as a string."),"escape-regex":doc("escape-regex",function(e){typecheck("escape-regex",e,"string");return escape_regex(e.valueOf())},"(escape-regex string)\n\n Function that returns a new string where all special operators used in regex,\n are escaped with backslashes so they can be used in the RegExp constructor\n to match a literal string."),env:doc("env",function e(e){e=e||this.env;var t=Object.keys(e.__env__).map(LSymbol);var r;if(t.length){r=Pair.fromArray(t)}else{r=_nil}if(e.__parent__ instanceof Environment){return global_env.get("env").call(this,e.__parent__).append(r)}return r},"(env)\n (env obj)\n\n Function that returns a list of names (functions, macros and variables)\n that are bound in the current environment or one of its parents."),new:doc("new",function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n2&&arguments[2]!==undefined?arguments[2]:specials.LITERAL;typecheck("set-special!",e,"string",1);typecheck("set-special!",t,"symbol",2);specials.append(e.valueOf(),t,r)},'(set-special! symbol name [type])\n\n Add a special symbol to the list of transforming operators by the parser.\n e.g.: `(add-special! "#" \'x)` will allow to use `#(1 2 3)` and it will be\n transformed into (x (1 2 3)) so you can write x macro that will process\n the list. 3rd argument is optional, and it can be one of two values:\n lips.specials.LITERAL, which is the default behavior, or\n lips.specials.SPLICE which causes the value to be unpacked into the expression.\n This can be used for e.g. to make `#(1 2 3)` into (x 1 2 3) that is needed\n by # that defines vectors.'),get:get,".":get,unbind:doc(unbind,"(unbind fn)\n\n Function that removes the weak 'this' binding from a function so you\n can get properties from the actual function object."),type:doc(type,"(type object)\n\n Function that returns the type of an object as string."),debugger:doc("debugger",function(){debugger},'(debugger)\n\n Function that triggers the JavaScript debugger (e.g. the browser devtools)\n using the "debugger;" statement. If a debugger is not running this\n function does nothing.'),in:doc("in",function(e,t){if(e instanceof LSymbol||e instanceof LString||e instanceof LNumber){e=e.valueOf()}return e in unbox(t)},'(in key value)\n\n Function that uses the Javascript "in" operator to check if key is\n a valid property in the value.'),"instance?":doc("instance?",function(e){return is_instance(e)},"(instance? obj)\n\n Checks if object is an instance, created with a new operator"),instanceof:doc("instanceof",function(e,t){return t instanceof unbind(e)},"(instanceof type obj)\n\n Predicate that tests if the obj is an instance of type."),"prototype?":doc("prototype?",is_prototype,"(prototype? obj)\n\n Predicate that tests if value is a valid JavaScript prototype,\n i.e. calling (new) with it will not throw ' is not a constructor'."),"macro?":doc("macro?",function(e){return e instanceof Macro},"(macro? expression)\n\n Predicate that tests if value is a macro."),"continuation?":doc("continuation?",is_continuation,"(continuation? expression)\n\n Predicate that tests if value is a callable continuation."),"function?":doc("function?",is_function,"(function? expression)\n\n Predicate that tests if value is a callable function."),"real?":doc("real?",function(e){if(type(e)!=="number"){return false}if(e instanceof LNumber){return e.isFloat()}return LNumber.isFloat(e)},"(real? number)\n\n Predicate that tests if value is a real number (not complex)."),"number?":doc("number?",function(e){return Number.isNaN(e)||LNumber.isNumber(e)},"(number? expression)\n\n Predicate that tests if value is a number or NaN value."),"string?":doc("string?",function(e){return LString.isString(e)},"(string? expression)\n\n Predicate that tests if value is a string."),"pair?":doc("pair?",is_pair,"(pair? expression)\n\n Predicate that tests if value is a pair or list structure."),"regex?":doc("regex?",function(e){return e instanceof RegExp},"(regex? expression)\n\n Predicate that tests if value is a regular expression."),"null?":doc("null?",function(e){return is_null(e)},"(null? expression)\n\n Predicate that tests if value is null-ish (i.e. undefined, nil, or\n Javascript null)."),"boolean?":doc("boolean?",function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Predicate that tests if value is a boolean (#t or #f)."),"symbol?":doc("symbol?",function(e){return e instanceof LSymbol},"(symbol? expression)\n\n Predicate that tests if value is a LIPS symbol."),"array?":doc("array?",function(e){return e instanceof Array},"(array? expression)\n\n Predicate that tests if value is an array."),"object?":doc("object?",function(e){return!is_nil(e)&&e!==null&&!(e instanceof LCharacter)&&!(e instanceof RegExp)&&!(e instanceof LString)&&!is_pair(e)&&!(e instanceof LNumber)&&_typeof$1(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Predicate that tests if value is an plain object (not another LIPS type)."),flatten:doc("flatten",function e(t){typecheck("flatten",t,"pair");return t.flatten()},"(flatten list)\n\n Returns a shallow list from tree structure (pairs)."),"array->list":doc("array->list",function(e){typecheck("array->list",e,"array");return Pair.fromArray(e)},"(array->list array)\n\n Function that converts a JavaScript array to a LIPS cons list."),"tree->array":doc("tree->array",to_array("tree->array",true),"(tree->array list)\n\n Function that converts a LIPS cons tree structure into a JavaScript array."),"list->array":doc("list->array",to_array("list->array"),"(list->array list)\n\n Function that converts a LIPS list into a JavaScript array."),apply:doc("apply",function e(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;iarray").call(this,a));return t.apply(this,prepare_fn_args(t,n))},"(apply fn list)\n\n Function that calls fn with the list of arguments."),length:doc("length",function e(t){if(!t||is_nil(t)){return 0}if(is_pair(t)){return t.length()}if("length"in t){return t.length}},'(length expression)\n\n Function that returns the length of the object. The object can be a LIPS\n list or any object that has a "length" property. Returns undefined if the\n length could not be found.'),"string->number":doc("string->number",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;typecheck("string->number",e,"string",1);typecheck("string->number",t,"number",2);e=e.valueOf();t=t.valueOf();if(e.match(rational_bare_re)||e.match(rational_re)){return parse_rational(e,t)}else if(e.match(complex_bare_re)||e.match(complex_re)){return parse_complex(e,t)}else{var r=t===10&&!e.match(/e/i)||t===16;if(e.match(int_bare_re)&&r||e.match(int_re)){return parse_integer(e,t)}if(e.match(float_re)){return parse_float(e)}}return false},"(string->number number [radix])\n\n Function that parses a string into a number."),try:doc(new Macro("try",function(r,e){var f=this;var _=e.use_dynamic;e.error;return new Promise(function(t,u){var s,n;if(LSymbol.is(r.cdr.car.car,"catch")){s=r.cdr.car;if(is_pair(r.cdr.cdr)&&LSymbol.is(r.cdr.cdr.car.car,"finally")){n=r.cdr.cdr.car}}else if(LSymbol.is(r.cdr.car.car,"finally")){n=r.cdr.car}if(!(n||s)){throw new Error("try: invalid syntax")}function c(e){t(e);throw new IgnoreException("[CATCH]")}var l=function e(t,r){r(t)};if(n){l=function e(t,r){l=u;i.error=function(e){throw e};unpromise(_evaluate(new Pair(new LSymbol("begin"),n.cdr),i),function(){r(t)})}}var i={env:f,use_dynamic:_,dynamic_env:f,error:function e(t){if(t instanceof IgnoreException){throw t}if(s){var r=f.inherit("try");var n=s.cdr.car.car;if(!(n instanceof LSymbol)){throw new Error("try: invalid syntax: catch require variable name")}r.set(n,t);var i;var a={env:r,use_dynamic:_,dynamic_env:f,error:function e(t){i=true;u(t);throw new IgnoreException("[CATCH]")}};var o=_evaluate(new Pair(new LSymbol("begin"),s.cdr.cdr),a);unpromise(o,function e(t){if(!i){l(t,c)}})}else{l(undefined,function(){u(t)})}}};var e=_evaluate(r.car,i);unpromise(e,function(e){l(e,t)},i.error)})}),"(try expr (catch (e) code))\n (try expr (catch (e) code) (finally code))\n (try expr (finally code))\n\n Macro that executes expr and catches any exceptions thrown. If catch is provided\n it's executed when an error is thrown. If finally is provided it's always\n executed at the end."),raise:doc("raise",function(e){throw e},"(raise obj)\n\n Throws the object verbatim (no wrapping an a new Error)."),throw:doc("throw",function(e){throw new Error(e)},"(throw string)\n\n Throws a new exception."),find:doc("find",function t(r,n){typecheck("find",r,["regex","function"]);typecheck("find",n,["pair","nil"]);if(is_null(n)){return _nil}var e=matcher("find",r);return unpromise(e(n.car),function(e){if(e&&!is_nil(e)){return n.car}return t(r,n.cdr)})},"(find fn list)\n (find regex list)\n\n Higher-order function that finds the first value for which fn return true.\n If called with a regex it will create a matcher function."),"for-each":doc("for-each",function(e){var t;typecheck("for-each",e,"function");for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i1?t-1:0),a=1;a3?n-3:0),a=3;a3?i-3:0),o=3;oarray")(r);var a=[];var o=matcher("filter",t);return function t(r){function e(e){if(e&&!is_nil(e)){a.push(n)}return t(++r)}if(r===i.length){return Pair.fromArray(a)}var n=i[r];return unpromise(o(n),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher-order function that calls `fn` for each element of the list\n and return a new list for only those elements for which fn returns\n a truthy value. If called with a regex it will create a matcher function."),compose:doc(compose,"(compose . fns)\n\n Higher-order function that creates a new function that applies all functions\n from right to left and returns the last value. Reverse of pipe.\n e.g.:\n ((compose (curry + 2) (curry * 3)) 10) --\x3e (+ 2 (* 3 10)) --\x3e 32"),pipe:doc(pipe,"(pipe . fns)\n\n Higher-order function that creates a new function that applies all functions\n from left to right and returns the last value. Reverse of compose.\n e.g.:\n ((pipe (curry + 2) (curry * 3)) 10) --\x3e (* 3 (+ 2 10)) --\x3e 36"),curry:doc(curry,"(curry fn . args)\n\n Higher-order function that creates a curried version of the function.\n The result function will have partially applied arguments and it\n will keep returning one-argument functions until all arguments are provided,\n then it calls the original function with the accumulated arguments.\n\n e.g.:\n (define (add a b c d) (+ a b c d))\n (define add1 (curry add 1))\n (define add12 (add 2))\n (display (add12 3 4))"),gcd:doc("gcd",function e(){for(var t=arguments.length,r=new Array(t),n=0;nu?a%=u:u%=a}a=abs(s*r[o])/(a+u)}return LNumber(a)},"(lcm n1 n2 ...)\n\n Function that returns the least common multiple of the arguments."),"odd?":doc("odd?",single_math_op(function(e){return LNumber(e).isOdd()}),"(odd? number)\n\n Checks if number is odd."),"even?":doc("even?",single_math_op(function(e){return LNumber(e).isEven()}),"(even? number)\n\n Checks if number is even."),"*":doc("*",reduce_math_op(function(e,t){return LNumber(e).mul(t)},LNumber(1)),"(* . numbers)\n\n Multiplies all numbers passed as arguments. If single value is passed\n it will return that value."),"+":doc("+",reduce_math_op(function(e,t){return LNumber(e).add(t)},LNumber(0)),"(+ . numbers)\n\n Sums all numbers passed as arguments. If single value is passed it will\n return that value."),"-":doc("-",function(){for(var e=arguments.length,t=new Array(e),r=0;r":doc(">",function(){for(var e=arguments.length,t=new Array(e),r=0;r",t,["bigint","float","rational"]);return seq_compare(function(e,t){return LNumber(e).cmp(t)===1},t)},"(> x1 x2 x3 ...)\n\n Function that compares its numerical arguments and checks if they are\n monotonically decreasing, i.e. x1 > x2 and x2 > x3 and so on."),"<":doc("<",function(){for(var e=arguments.length,t=new Array(e),r=0;r=":doc(">=",function(){for(var e=arguments.length,t=new Array(e),r=0;r=",t,["bigint","float","rational"]);return seq_compare(function(e,t){return[0,1].includes(LNumber(e).cmp(t))},t)},"(>= x1 x2 ...)\n\n Function that compares its numerical arguments and checks if they are\n monotonically nonincreasing, i.e. x1 >= x2 and x2 >= x3 and so on."),"eq?":doc("eq?",equal,"(eq? a b)\n\n Function that compares two values if they are identical."),or:doc(new Macro("or",function(e,t){var i=t.use_dynamic,a=t.error;var o=global_env.get("list->array")(e);var u=this;var s=u;if(!o.length){return false}var c;return function t(){function e(e){c=e;if(c!==false){return c}else{return t()}}if(!o.length){if(c!==false){return c}else{return false}}else{var r=o.shift();var n=_evaluate(r,{env:u,dynamic_env:s,use_dynamic:i,error:a});return unpromise(n,e)}}()}),"(or . expressions)\n\n Macro that executes the values one by one and returns the first that is\n a truthy value. If there are no expressions that evaluate to true it\n returns false."),and:doc(new Macro("and",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=t.error;var i=global_env.get("list->array")(e);var a=this;var o=a;if(!i.length){return true}var u;var s={env:a,dynamic_env:o,use_dynamic:r,error:n};return function t(){function e(e){u=e;if(u===false){return false}else{return t()}}if(!i.length){if(u!==false){return u}else{return false}}else{var r=i.shift();return unpromise(_evaluate(r,s),e)}}()}),"(and . expressions)\n\n Macro that evaluates each expression in sequence and if any value returns false\n it will stop and return false. If each value returns true it will return the\n last value. If it's called without arguments it will return true."),"|":doc("|",function(e,t){return LNumber(e).or(t)},"(| a b)\n\n Function that calculates the bitwise or operation."),"&":doc("&",function(e,t){return LNumber(e).and(t)},"(& a b)\n\n Function that calculates the bitwise and operation."),"~":doc("~",function(e){return LNumber(e).neg()},"(~ number)\n\n Function that calculates the bitwise inverse (flip all the bits)."),">>":doc(">>",function(e,t){return LNumber(e).shr(t)},"(>> a b)\n\n Function that right shifts the value a by value b bits."),"<<":doc("<<",function(e,t){return LNumber(e).shl(t)},"(<< a b)\n\n Function that left shifts the value a by value b bits."),not:doc("not",function e(t){if(is_null(t)){return true}return!t},"(not object)\n\n Function that returns the Boolean negation of its argument.")},undefined,"global");var user_env=global_env.inherit("user-env");function set_interaction_env(e,t){e.constant("**internal-env**",t);e.doc("**internal-env**","**internal-env**\n\n Constant used to hide stdin, stdout and stderr so they don't interfere\n with variables with the same name. Constants are an internal type\n of variable that can't be redefined, defining a variable with the same name\n will throw an error.");global_env.set("**interaction-environment**",e)}set_interaction_env(user_env,internal_env);global_env.doc("**interaction-environment**","**interaction-environment**\n\n Internal dynamic, global variable used to find interpreter environment.\n It's used so the read and write functions can locate **internal-env**\n that contains the references to stdin, stdout and stderr.");function set_fs(e){user_env.get("**internal-env**").set("fs",e)}(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(t){var r=e[t]?e[t]:t;global_env.set(r,doc(r,function(e){typecheck(r,e,"number");if(e instanceof LNumber){return e[t]()}},"(".concat(r," number)\n\n Function that calculates the ").concat(r," of a number.")))})})();function allPossibleCases(e){if(e.length===1){return e[0]}else{var t=[];var r=allPossibleCases(e.slice(1));for(var n=0;n3&&arguments[3]!==undefined?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(n!==null){i+=" (argument ".concat(n,")")}if(is_function(r)){return"Invalid type: got ".concat(t).concat(i)}if(r instanceof Array){if(r.length===1){var a=r[0].toLowerCase();r="a"+("aeiou".includes(a)?"n ":" ")+r[0]}else{r=new Intl.ListFormat("en",{style:"long",type:"disjunction"}).format(r)}}return"Expecting ".concat(r," got ").concat(t).concat(i)}function typecheck_number(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;typecheck(e,t,"number",n);var i=t.__type__;var a;if(is_pair(r)){r=r.to_array()}if(r instanceof Array){r=r.map(function(e){return e.valueOf()})}if(r instanceof Array){r=r.map(function(e){return e.valueOf().toLowerCase()});if(r.includes(i)){a=true}}else{r=r.valueOf().toLowerCase()}if(!a&&i!==r){throw new Error(typeErrorMessage(e,i,r,n))}}function typecheck_numbers(r,e,n){e.forEach(function(e,t){typecheck_number(r,e,n,t+1)})}function typecheck_args(r,e,n){e.forEach(function(e,t){typecheck(r,e,n,t+1)})}function typecheck_text_port(e,t,r){typecheck(e,t,r);if(t.__type__===binary_port){throw new Error(typeErrorMessage(e,"binary-port","textual-port"))}}function typecheck(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;e=e.valueOf();var i=type(t).toLowerCase();if(is_function(r)){if(!r(t)){throw new Error(typeErrorMessage(e,i,r,n))}return}var a=false;if(is_pair(r)){r=r.to_array()}if(r instanceof Array){r=r.map(function(e){return e.valueOf()})}if(r instanceof Array){r=r.map(function(e){return e.valueOf().toLowerCase()});if(r.includes(i)){a=true}}else{r=r.valueOf().toLowerCase()}if(!a&&i!==r){throw new Error(typeErrorMessage(e,i,r,n))}}function memoize(r){var n=new WeakMap;return function(e){var t=n.get(e);if(!t){t=r(e)}return t}}type=memoize(type);function type(e){var t=type_constants.get(e);if(t){return t}if(_typeof$1(e)==="object"){for(var r=0,n=Object.entries(type_mapping);r2&&arguments[2]!==undefined?arguments[2]:{},n=r.env,i=r.dynamic_env,a=r.use_dynamic;var o=n===null||n===void 0?void 0:n.new_frame(e,t);var u=i===null||i===void 0?void 0:i.new_frame(e,t);var s=new LambdaContext({env:o,use_dynamic:a,dynamic_env:u});return resolve_promises(e.apply(s,t))}function apply(n,e){var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},i=t.env,a=t.dynamic_env,o=t.use_dynamic,r=t.error,u=r===void 0?function(){}:r;e=evaluate_args(e,{env:i,dynamic_env:a,error:u,use_dynamic:o});return unpromise(e,function(e){if(is_raw_lambda(n)){n=unbind(n)}e=prepare_fn_args(n,e);var t=e.slice();var r=call_function(n,t,{env:i,dynamic_env:a,use_dynamic:o});return unpromise(r,function(e){if(is_pair(e)){e.mark_cycles();return quote(e)}return box(e)},u)})}var _p_name__=new WeakMap;var Parameter=function(){function n(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;_classCallCheck(this,n);_defineProperty(this,"__value__",void 0);_defineProperty(this,"__fn__",void 0);_classPrivateFieldInitSpec(this,_p_name__,{writable:true,value:void 0});this.__value__=e;if(t){if(!is_function(t)){throw new Error("Section argument to Parameter need to be function "+"".concat(type(t)," given"))}this.__fn__=t}if(r){_classPrivateFieldSet(this,_p_name__,r)}}_createClass(n,[{key:"__name__",get:function e(){return _classPrivateFieldGet(this,_p_name__)},set:function e(t){_classPrivateFieldSet(this,_p_name__,t);if(this.__fn__){this.__fn__.__name__="fn-".concat(t)}}},{key:"invoke",value:function e(){if(is_function(this.__fn__)){return this.__fn__(this.__value__)}return this.__value__}},{key:"inherit",value:function e(t){return new n(t,this.__fn__,this.__name__)}}]);return n}();var LambdaContext=function(){function t(e){_classCallCheck(this,t);_defineProperty(this,"env",void 0);_defineProperty(this,"dynamic_env",void 0);_defineProperty(this,"use_dynamic",void 0);Object.assign(this,e)}_createClass(t,[{key:"__name__",get:function e(){return this.env.__name__}},{key:"__parent__",get:function e(){return this.env.__parent__}},{key:"get",value:function e(){var t;return(t=this.env).get.apply(t,arguments)}}]);return t}();function search_param(e,t){var r=e.get(t.__name__,{throwError:false});if(is_parameter(r)&&r!==t){return r}var n=user_env.get("**interaction-environment**");while(true){var i=e.get("parent.frame",{throwError:false});e=i(0);if(e===n){break}r=e.get(t.__name__,{throwError:false});if(is_parameter(r)&&r!==t){return r}}return t}var Continuation=function(){function t(e){_classCallCheck(this,t);_defineProperty(this,"__value__",void 0);this.__value__=e}_createClass(t,[{key:"invoke",value:function e(){if(this.__value__===null){throw new Error("Continuations are not implemented yet")}}}]);return t}();function _evaluate(u){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},s=e.env,c=e.dynamic_env,l=e.use_dynamic,t=e.error,f=t===void 0?noop:t,r=_objectWithoutProperties(e,_excluded6);return function(e){try{if(!is_env(c)){c=s===true?user_env:s||user_env}if(l){s=c}else if(s===true){s=user_env}else{s=s||global_env}var t={env:s,dynamic_env:c,use_dynamic:l,error:f};var r;if(is_null(u)){return u}if(u instanceof LSymbol){return s.get(u)}if(!is_pair(u)){return u}var n=u.car;var e=u.cdr;if(is_pair(n)){r=resolve_promises(_evaluate(n,t));if(is_promise(r)){return r.then(function(e){if(!is_callable(e)){throw new Error(type(e)+" "+s.get("repr")(e)+" is not callable while evaluating "+u.toString())}return _evaluate(new Pair(e,u.cdr),t)})}else if(!is_callable(r)){throw new Error(type(r)+" "+s.get("repr")(r)+" is not callable while evaluating "+u.toString())}}if(n instanceof LSymbol){r=s.get(n)}else if(is_function(n)){r=n}var i;if(r instanceof Syntax){i=evaluate_syntax(r,u,t)}else if(r instanceof Macro){i=evaluate_macro(r,e,t)}else if(is_function(r)){i=apply(r,e,t)}else if(r instanceof SyntaxParameter){i=evaluate_syntax(r._syntax,u,t)}else if(is_parameter(r)){var a=search_param(c,r);if(is_null(u.cdr)){i=a.invoke()}else{return unpromise(_evaluate(u.cdr.car,t),function(e){a.__value__=e})}}else if(is_continuation(r)){i=r.invoke()}else if(is_pair(u)){r=n&&n.toString();throw new Error("".concat(type(n)," ").concat(r," is not a function"))}else{return u}var o=s.get(Symbol["for"]("__promise__"),{throwError:false});if(o===true&&is_promise(i)){i=i.then(function(e){if(is_pair(e)&&!r[__data__]){return _evaluate(e,t)}return e});return new QuotedPromise(i)}return i}catch(e){f&&f.call(s,e,u)}}(r)}var compile=exec_collect(function(e){return e});var exec=exec_collect(function(e,t){return t});function exec_with_stacktrace(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.env,n=t.dynamic_env,i=t.use_dynamic;return _evaluate(e,{env:r,dynamic_env:n,use_dynamic:i,error:function e(t,r){if(t&&t.message){if(t.message.match(/^Error:/)){var n=/^(Error:)\s*([^:]+:\s*)/;t.message=t.message.replace(n,"$1 $2")}if(r){if(!(t.__code__ instanceof Array)){t.__code__=[]}t.__code__.push(r.toString(true))}}if(!(t instanceof IgnoreException)){throw t}}})}function exec_collect(h){return function(){var t=_asyncToGenerator(function(f){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},_=e.env,p=e.dynamic_env,d=e.use_dynamic;return _regeneratorRuntime.mark(function e(){var r,n,i,a,o,u,s,c,l;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!is_env(p)){p=_===true?user_env:_||user_env}if(_===true){_=user_env}else{_=_||user_env}r=[];if(!is_pair(f)){t.next=8;break}t.next=6;return exec_with_stacktrace(code,{env:_,dynamic_env:p,use_dynamic:d});case 6:t.t0=t.sent;return t.abrupt("return",[t.t0]);case 8:n=Array.isArray(f)?f:_parse(f);i=false;a=false;t.prev=11;u=_asyncIterator(n);case 13:t.next=15;return u.next();case 15:if(!(i=!(s=t.sent).done)){t.next=31;break}c=s.value;t.next=19;return exec_with_stacktrace(c,{env:_,dynamic_env:p,use_dynamic:d});case 19:l=t.sent;t.t1=r;t.t2=h;t.t3=c;t.next=25;return l;case 25:t.t4=t.sent;t.t5=(0,t.t2)(t.t3,t.t4);t.t1.push.call(t.t1,t.t5);case 28:i=false;t.next=13;break;case 31:t.next=37;break;case 33:t.prev=33;t.t6=t["catch"](11);a=true;o=t.t6;case 37:t.prev=37;t.prev=38;if(!(i&&u["return"]!=null)){t.next=42;break}t.next=42;return u["return"]();case 42:t.prev=42;if(!a){t.next=45;break}throw o;case 45:return t.finish(42);case 46:return t.finish(37);case 47:return t.abrupt("return",r);case 48:case"end":return t.stop()}},e,null,[[11,33,37,47],[38,,42,46]])})()});function e(e){return t.apply(this,arguments)}return e}()}function balanced(e){var t={"[":"]","(":")"};var r;if(typeof e==="string"){r=tokenize(e)}else{r=e.map(function(e){return e&&e.token?e.token:e})}var n=Object.keys(t);var i=Object.values(t).concat(n);r=r.filter(function(e){return i.includes(e)});var a=new Stack;var o=_createForOfIteratorHelper(r),u;try{for(o.s();!(u=o.n()).done;){var s=u.value;if(n.includes(s)){a.push(s)}else if(!a.is_empty()){var c=a.top();var l=t[c];if(s===l){a.pop()}else{throw new Error("Syntax error: missing closing ".concat(l))}}else{throw new Error("Syntax error: not matched closing ".concat(s))}}}catch(e){o.e(e)}finally{o.f()}return a.is_empty()}function fworker(e){var t="("+e.toString()+")()";var r=window.URL||window.webkitURL;var n;try{n=new Blob([t],{type:"application/javascript"})}catch(e){var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;n=new i;n.append(t);n=n.getBlob()}return new root.Worker(r.createObjectURL(n))}function is_dev(){return lips.version.match(/^(\{\{VER\}\}|DEV)$/)}function get_current_script(){if(is_node()){return}var e;if(document.currentScript){e=document.currentScript}else{var t=document.querySelectorAll("script");if(!t.length){return}e=t[t.length-1]}var r=e.getAttribute("src");return r}var current_script=get_current_script();function bootstrap(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"";var t="dist/std.xcb";if(e===""){if(current_script){e=current_script.replace(/[^/]*$/,"std.xcb")}else if(is_dev()){e="https://cdn.jsdelivr.net/gh/jcubic/lips@devel/".concat(t)}else{e="https://cdn.jsdelivr.net/npm/@jcubic/lips@".concat(lips.version,"/").concat(t)}}var r=global_env.get("load");return r.call(user_env,e,global_env)}function Worker(e){this.url=e;var o=this.worker=fworker(function(){var o;var u;self.addEventListener("message",function(e){var r=e.data;var t=r.id;if(r.type!=="RPC"||t===null){return}function n(e){self.postMessage({id:t,type:"RPC",result:e})}function i(e){self.postMessage({id:t,type:"RPC",error:e})}if(r.method==="eval"){if(!u){i("Worker RPC: LIPS not initialized, call init first");return}u.then(function(){var e=r.params[0];var t=r.params[1];o.exec(e,{use_dynamic:t}).then(function(e){e=e.map(function(e){return e&&e.valueOf()});n(e)})["catch"](function(e){i(e)})})}else if(r.method==="init"){var a=r.params[0];if(typeof a!=="string"){i("Worker RPC: url is not a string")}else{importScripts("".concat(a,"/dist/lips.min.js"));o=new lips.Interpreter("worker");u=bootstrap(a);u.then(function(){n(true)})}}})});this.rpc=function(){var n=0;return function e(t,r){var a=++n;return new Promise(function(n,i){o.addEventListener("message",function e(t){var r=t.data;if(r&&r.type==="RPC"&&r.id===a){if(r.error){i(r.error)}else{n(r.result)}o.removeEventListener("message",e)}});o.postMessage({type:"RPC",method:t,id:a,params:r})})}}();this.rpc("init",[e])["catch"](function(e){console.error(e)});this.exec=function(e,t){var r=t.use_dynamic,n=r===void 0?false:r;return this.rpc("eval",[e,n])}}var serialization_map={pair:function e(t){var r=_slicedToArray(t,2),n=r[0],i=r[1];return Pair(n,i)},number:function e(t){if(LString.isString(t)){return LNumber([t,10])}return LNumber(t)},regex:function e(t){var r=_slicedToArray(t,2),n=r[0],i=r[1];return new RegExp(n,i)},nil:function e(){return _nil},symbol:function e(t){if(LString.isString(t)){return LSymbol(t)}else if(Array.isArray(t)){return LSymbol(Symbol["for"](t[0]))}},string:LString,character:LCharacter};var available_class=Object.keys(serialization_map);var class_map={};for(var _i6=0,_Object$entries3=Object.entries(available_class);_i6<_Object$entries3.length;_i6++){var _Object$entries3$_i=_slicedToArray(_Object$entries3[_i6],2),i=_Object$entries3$_i[0],cls=_Object$entries3$_i[1];class_map[cls]=+i}function mangle_name(e){return class_map[e]}function resolve_name(e){return available_class[e]}function serialize(e){return JSON.stringify(e,function(e,t){var r=this[e];if(r){if(r instanceof RegExp){return{"@":mangle_name("regex"),"#":[r.source,r.flags]}}var n=mangle_name(r.constructor.__class__);if(!is_undef(n)){return{"@":n,"#":r.serialize()}}}return t})}function unserialize(e){return JSON.parse(e,function(e,t){if(t&&_typeof$1(t)==="object"){if(!is_undef(t["@"])){var r=resolve_name(t["@"]);if(serialization_map[r]){return serialization_map[r](t["#"])}}}return t})}var cbor=function(){var e={pair:Pair,symbol:LSymbol,number:LNumber,string:LString,character:LCharacter,nil:_nil.constructor,regex:RegExp};function t(e,t){return{deserialize:t,Class:e}}var r=new Encoder;var a={};for(var n=0,i=Object.entries(serialization_map);n1){var n=t.reduce(function(e,t){return e+t.length},0);var i=new Uint8Array(n);var a=0;t.forEach(function(e){i.set(e,a);a+=e.length});return i}else if(t.length){return t[0]}}function encode_magic(){var e=1;var t=new TextEncoder("utf-8");return t.encode("LIPS".concat(e.toString().padStart(3," ")))}var MAGIC_LENGTH=7;function decode_magic(e){var t=new TextDecoder("utf-8");var r=t.decode(e.slice(0,MAGIC_LENGTH));var n=r.substring(0,4);if(n==="LIPS"){var i=r.match(/^(....).*([0-9]+)$/);if(i){return{type:i[1],version:Number(i[2])}}}return{type:"unknown"}}function serialize_bin(e){var t=encode_magic();var r=cbor.encode(e);return merge_uint8_array(t,pack_1(r,{magic:false}))}function unserialize_bin(e){var t=decode_magic(e),r=t.type,n=t.version;if(r==="LIPS"&&n===1){var i=unpack_1(e.slice(MAGIC_LENGTH),{magic:false});return cbor.decode(i)}else{throw new Error("Invalid file format ".concat(r))}}function execError(e){console.error(e.message||e);if(Array.isArray(e.code)){console.error(e.code.map(function(e,t){return"[".concat(t+1,"]: ").concat(e)}))}}function init(){var o=["text/x-lips","text/x-scheme"];var u;function s(e){var t;return(t=e.getAttribute("data-bootstrap"))!==null&&t!==void 0?t:e.getAttribute("bootstrap")}function c(r){return new Promise(function(t){var e=r.getAttribute("src");if(e){return fetch(e).then(function(e){return e.text()}).then(exec).then(t)["catch"](function(e){execError(e);t()})}else{return exec(r.innerHTML).then(t)["catch"](function(e){execError(e);t()})}})}function e(){return new Promise(function(i){var a=Array.from(document.querySelectorAll("script"));return function e(){var t=a.shift();if(!t){i()}else{var r=t.getAttribute("type");if(o.includes(r)){var n=s(t);if(!u&&typeof n==="string"){return bootstrap(n).then(function(){return c(t)}).then(e)}else{return c(t).then(e)}}else if(r&&r.match(/lips|lisp/)){console.warn("Expecting "+o.join(" or ")+" found "+r)}return e()}}()})}if(!window.document){return Promise.resolve()}else if(currentScript){var t=currentScript;var r=s(t);if(typeof r==="string"){return bootstrap(r).then(function(){u=true;return e()})}}return e()}var currentScript=typeof window!=="undefined"&&window.document&&document.currentScript;if(typeof window!=="undefined"){contentLoaded(window,init)}var banner=function(){var e=LString("Tue, 05 Mar 2024 13:03:01 +0000").valueOf();var t=e==="{{"+"DATE}}"?new Date:new Date(e);var r=function e(t){return t.toString().padStart(2,"0")};var n=t.getFullYear();var i=[n,r(t.getMonth()+1),r(t.getDate())].join("-");var a="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter DEV (".concat(i,") \nCopyright (c) 2018-").concat(n," Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables. You can also\nuse (help name) to display help for specific function or macro, (apropos name)\nto display list of matched names in environment and (dir object) to list\nproperties of an object.\n").replace(/^.*\n/,"");return a}();read_only(Ahead,"__class__","ahead");read_only(Pair,"__class__","pair");read_only(Nil,"__class__","nil");read_only(Pattern,"__class__","pattern");read_only(Formatter,"__class__","formatter");read_only(Macro,"__class__","macro");read_only(Syntax,"__class__","syntax");read_only(Syntax.Parameter,"__class__","syntax-parameter");read_only(Environment,"__class__","environment");read_only(InputPort,"__class__","input-port");read_only(OutputPort,"__class__","output-port");read_only(BufferedOutputPort,"__class__","output-port");read_only(OutputStringPort,"__class__","output-string-port");read_only(InputStringPort,"__class__","input-string-port");read_only(InputFilePort,"__class__","input-file-port");read_only(OutputFilePort,"__class__","output-file-port");read_only(LipsError,"__class__","lips-error");[LNumber,LComplex,LRational,LFloat,LBigInteger].forEach(function(e){read_only(e,"__class__","number")});read_only(LCharacter,"__class__","character");read_only(LSymbol,"__class__","symbol");read_only(LString,"__class__","string");read_only(QuotedPromise,"__class__","promise");read_only(Parameter,"__class__","parameter");var version="DEV";var date="Tue, 05 Mar 2024 13:03:01 +0000";var parse=compose(uniterate_async,_parse);var lips={version:version,banner:banner,date:date,exec:exec,parse:parse,tokenize:tokenize,evaluate:_evaluate,compile:compile,serialize:serialize,unserialize:unserialize,serialize_bin:serialize_bin,unserialize_bin:unserialize_bin,bootstrap:bootstrap,Environment:Environment,env:user_env,Worker:Worker,Interpreter:Interpreter,balanced_parenthesis:balanced,balancedParenthesis:balanced,balanced:balanced,Macro:Macro,Syntax:Syntax,Pair:Pair,Values:Values,QuotedPromise:QuotedPromise,Error:LipsError,quote:quote,InputPort:InputPort,OutputPort:OutputPort,BufferedOutputPort:BufferedOutputPort,InputFilePort:InputFilePort,OutputFilePort:OutputFilePort,InputStringPort:InputStringPort,OutputStringPort:OutputStringPort,InputByteVectorPort:InputByteVectorPort,OutputByteVectorPort:OutputByteVectorPort,InputBinaryFilePort:InputBinaryFilePort,OutputBinaryFilePort:OutputBinaryFilePort,set_fs:set_fs,Formatter:Formatter,Parser:Parser,Lexer:Lexer,specials:specials,repr:repr,nil:_nil,eof:eof,LSymbol:LSymbol,LNumber:LNumber,LFloat:LFloat,LComplex:LComplex,LRational:LRational,LBigInteger:LBigInteger,LCharacter:LCharacter,LString:LString,Parameter:Parameter,rationalize:rationalize};global_env.set("lips",lips);export{BufferedOutputPort,Environment,LipsError as Error,Formatter,InputBinaryFilePort,InputByteVectorPort,InputFilePort,InputPort,InputStringPort,Interpreter,LBigInteger,LCharacter,LComplex,LFloat,LNumber,LRational,LString,LSymbol,Lexer,Macro,OutputBinaryFilePort,OutputByteVectorPort,OutputFilePort,OutputPort,OutputStringPort,Pair,Parameter,Parser,QuotedPromise,Syntax,Values,Worker,balanced,balanced as balancedParenthesis,balanced as balanced_parenthesis,banner,bootstrap,compile,date,user_env as env,eof,_evaluate as evaluate,exec,_nil as nil,parse,quote,rationalize,repr,serialize,serialize_bin,set_fs,specials,tokenize,unserialize,unserialize_bin,version}; \ No newline at end of file + */Object.defineProperty(lzjbPack,"__esModule",{value:true});const NBBY=8,MATCH_BITS=6,MATCH_MIN=3,MATCH_MAX=(1<r-MATCH_MAX){t[i++]=e[n++];continue}l=(e[n]+13^e[n+1]-13^e[n+2])&LEMPEL_SIZE-1;c=n-f[l]&OFFSET_MASK;f[l]=n;a=n-c;if(a>=0&&a!=n&&e[n]==e[a]&&e[n+1]==e[a+1]&&e[n+2]==e[a+2]){t[o]|=u;for(s=MATCH_MIN;s>NBBY;t[i++]=c;n+=s}else{t[i++]=e[n++]}}console.assert(e.length>=n);return i}function decompress(e,t,r){t=t|0;var n=0,i=0,a=0,o=0,u=1<<(NBBY-1|0),s=0,c=0;while(n>(NBBY-MATCH_BITS|0))+MATCH_MIN|0;c=(e[n]<4){r[i]=r[a];i=i+1|0;a=a+1|0;r[i]=r[a];i=i+1|0;a=a+1|0;r[i]=r[a];i=i+1|0;a=a+1|0;r[i]=r[a];i=i+1|0;a=a+1|0;s=s-4|0}while(s>0){r[i]=r[a];i=i+1|0;a=a+1|0;s=s-1|0}}}else{r[i]=e[n];i=i+1|0;n=n+1|0}}return i}function encode_magic$1(){const e=new TextEncoder("utf-8");return e.encode(MAGIC_STRING)}const MAGIC_STRING="@lzjb";const MAGIC=encode_magic$1();function merge_uint8_array$1(...e){if(e.length>1){const r=e.reduce((e,t)=>e+t.length,0);const n=new Uint8Array(r);let t=0;e.forEach(e=>{n.set(e,t);t+=e.length});return n}else if(e.length){return e[0]}}function number_to_bytes(t){const e=Math.ceil(Math.log2(t)/8);const r=new Uint8Array(e);for(let e=0;e=0;e--){r=r*256+t[e]}return r}function pack(e,{magic:t=true}={}){const r=new Uint8Array(Math.max(e.length*1.5|0,16*1024));const n=compress(e,r);const i=number_to_bytes(e.length);const a=[Uint8Array.of(i.length),i,r.slice(0,n)];if(t){a.unshift(MAGIC)}return merge_uint8_array$1(...a)}function unpack(t,{magic:e=true}={}){if(e){const e=new TextDecoder("utf-8");const s=e.decode(t.slice(0,MAGIC.length));if(s!==MAGIC_STRING){throw new Error("Invalid magic value")}}const r=e?MAGIC.length:0;const n=t[r];const i=r+1;const a=r+n+1;const o=bytes_to_number(t.slice(i,a));t=t.slice(a);const u=new Uint8Array(o);decompress(t,t.length,u);return u}var pack_1=lzjbPack.pack=pack;var unpack_1=lzjbPack.unpack=unpack;function unfetch(s,c){return c=c||{},new Promise(function(e,t){var r=new XMLHttpRequest,n=[],i=[],a={},o=function(){return{ok:2==(r.status/100|0),statusText:r.statusText,status:r.status,url:r.responseURL,text:function(){return Promise.resolve(r.responseText)},json:function(){return Promise.resolve(r.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([r.response]))},clone:o,headers:{keys:function(){return n},entries:function(){return i},get:function(e){return a[e.toLowerCase()]},has:function(e){return e.toLowerCase()in a}}}};for(var u in r.open(c.method||"get",s,!0),r.onload=function(){r.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,t,r){n.push(t=t.toLowerCase()),i.push([t,r]),a[t]=a[t]?a[t]+","+r:r}),e(o())},r.onerror=t,r.withCredentials="include"==c.credentials,c.headers)r.setRequestHeader(u,c.headers[u]);r.send(c.body||null)})}var _excluded=["token"],_excluded2=["env"],_excluded3=["stderr","stdin","stdout","command_line"],_excluded4=["use_dynamic"],_excluded5=["use_dynamic"],_excluded6=["env","dynamic_env","use_dynamic","error"];function _classPrivateFieldInitSpec(e,t,r){_checkPrivateRedeclaration(e,t);t.set(e,r)}function _checkPrivateRedeclaration(e,t){if(t.has(e)){throw new TypeError("Cannot initialize the same private elements twice on an object")}}function _callSuper(e,t,r){return t=_getPrototypeOf(t),_possibleConstructorReturn(e,_isNativeReflectConstruct()?Reflect.construct(t,r||[],_getPrototypeOf(e).constructor):t.apply(e,r))}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(_isNativeReflectConstruct=function e(){return!!t})()}function _createForOfIteratorHelper(t,e){var r=typeof Symbol!=="undefined"&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=_unsupportedIterableToArray(t))||e&&t&&typeof t.length==="number"){if(r)t=r;var n=0;var i=function e(){};return{s:i,n:function e(){if(n>=t.length)return{done:true};return{done:false,value:t[n++]}},e:function e(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a=true,o=false,u;return{s:function e(){r=r.call(t)},n:function e(){var t=r.next();a=t.done;return t},e:function e(t){o=true;u=t},f:function e(){try{if(!a&&r["return"]!=null)r["return"]()}finally{if(o)throw u}}}}function _unsupportedIterableToArray(e,t){if(!e)return;if(typeof e==="string")return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor)r=e.constructor.name;if(r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return _arrayLikeToArray(e,t)}function _arrayLikeToArray(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r1?r-1:0),i=1;i0&&arguments[0]!==undefined?arguments[0]:null;var t=user_env&&user_env.get("DEBUG",{throwError:false});if(e===null){return t===true}return(t===null||t===void 0?void 0:t.valueOf())===e.valueOf()}function num_mnemicic_re(e){return e?"(?:#".concat(e,"(?:#[ie])?|#[ie]#").concat(e,")"):"(?:#[ie])?"}function gen_rational_re(e,t){return"".concat(num_mnemicic_re(e),"[+-]?").concat(t,"+/").concat(t,"+")}function gen_complex_re(e,t){return"".concat(num_mnemicic_re(e),"(?:[+-]?(?:").concat(t,"+/").concat(t,"+|nan.0|inf.0|").concat(t,"+))?(?:[+-]i|[+-]?(?:").concat(t,"+/").concat(t,"+|").concat(t,"+|nan.0|inf.0)i)(?=[()[\\]\\s]|$)")}function gen_integer_re(e,t){return"".concat(num_mnemicic_re(e),"[+-]?").concat(t,"+")}var re_re=/^#\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimyus]*)$/;var float_stre="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)";var complex_float_stre="(?:#[ie])?(?:[+-]?(?:[0-9]+/[0-9]+|nan.0|inf.0|".concat(float_stre,"|[+-]?[0-9]+))?(?:").concat(float_stre,"|[+-](?:[0-9]+/[0-9]+|[0-9]+|nan.0|inf.0))i");var float_re=new RegExp("^(#[ie])?".concat(float_stre,"$"),"i");function make_complex_match_re(e,t){var r=e==="x"?"(?!\\+|".concat(t,")"):"(?!\\.|".concat(t,")");var n="";if(e===""){n="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+(?![0-9]))(?:[eE][-+]?[0-9]+)?))"}return new RegExp("^((?:(?:".concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(t,"+/").concat(t,"+(?!").concat(t,")|[+-]?").concat(t,"+)").concat(r,")?)(").concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(t,"+/").concat(t,"+|[+-]?").concat(t,"+|[+-])i$"),"i")}var complex_list_re=function(){var a={};[[10,"","[0-9]"],[16,"x","[0-9a-fA-F]"],[8,"o","[0-7]"],[2,"b","[01]"]].forEach(function(e){var t=_slicedToArray(e,3),r=t[0],n=t[1],i=t[2];a[r]=make_complex_match_re(n,i)});return a}();var characters={alarm:"",backspace:"\b",delete:"",escape:"",newline:"\n",null:"\0",return:"\r",space:" ",tab:"\t",dle:"",soh:"",dc1:"",stx:"",dc2:"",etx:"",dc3:"",eot:"",dc4:"",enq:"",nak:"",ack:"",syn:"",bel:"",etb:"",bs:"\b",can:"",ht:"\t",em:"",lf:"\n",sub:"",vt:"\v",esc:"",ff:"\f",fs:"",cr:"\r",gs:"",so:"",rs:"",si:"",us:"",del:""};function ucs2decode(e){var t=[];var r=0;var n=e.length;while(r=55296&&i<=56319&&r1&&arguments[1]!==undefined?arguments[1]:10;var r=num_pre_parse(e);var n=r.number.split("/");var i=LRational({num:LNumber([n[0],r.radix||t]),denom:LNumber([n[1],r.radix||t])});if(r.inexact){return i.valueOf()}else{return i}}function parse_integer(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;var r=num_pre_parse(e);if(r.inexact){return LFloat(parseInt(r.number,r.radix||t))}return LNumber([r.number,r.radix||t])}function parse_character(e){var t=e.match(/#\\x([0-9a-f]+)$/i);var r;if(t){var n=parseInt(t[1],16);r=String.fromCodePoint(n)}else{t=e.match(/#\\([\s\S]+)$/);if(t){r=t[1]}}if(r){return LCharacter(r)}throw new Error("Parse: invalid character")}function parse_complex(e){var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;function t(e){var t;if(e==="+"){t=LNumber(1)}else if(e==="-"){t=LNumber(-1)}else if(e.match(int_bare_re)){t=LNumber([e,i])}else if(e.match(rational_bare_re)){var r=e.split("/");t=LRational({num:LNumber([r[0],i]),denom:LNumber([r[1],i])})}else if(e.match(float_re)){var n=parse_float(e);if(a.exact){return n.toRational()}return n}else if(e.match(/nan.0$/)){return LNumber(NaN)}else if(e.match(/inf.0$/)){if(e[0]==="-"){return LNumber(Number.NEGATIVE_INFINITY)}return LNumber(Number.POSITIVE_INFINITY)}else{throw new Error("Internal Parser Error")}if(a.inexact){return LFloat(t.valueOf())}return t}var a=num_pre_parse(e);i=a.radix||i;var r;var n=a.number.match(complex_bare_match_re);if(i!==10&&n){r=n}else{r=a.number.match(complex_list_re[i])}var o,u;u=t(r[2]);if(r[1]){o=t(r[1])}else{o=LNumber(0)}if(u.cmp(0)===0&&u.__type__==="bigint"){return o}return LComplex({im:u,re:o})}function is_int(e){return parseInt(e.toString(),10)===e}function parse_big_int(e){var t=e.match(/^(([-+]?[0-9]*)(?:\.([0-9]+))?)e([-+]?[0-9]+)/i);if(t){var r=parseInt(t[4],10);var n;var i=t[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var a=t[3]&&t[3].length;if(i0&&(t.exact||!t.number.match(/\./))){return LNumber(a).mul(u)}}}r=LFloat(r);if(t.exact){return r.toRational()}return r}function parse_string(e){e=e.replace(/\\x([0-9a-f]+);/gi,function(e,t){return"\\u"+t.padStart(4,"0")}).replace(/\n/g,"\\n");var t=e.match(/(\\*)(\\x[0-9A-F])/i);if(t&&t[1].length%2===0){throw new Error("Invalid string literal, unclosed ".concat(t[2]))}try{var r=LString(JSON.parse(e));r.freeze();return r}catch(e){var n=e.message.replace(/in JSON /,"").replace(/.*Error: /,"");throw new Error("Invalid string literal: ".concat(n))}}function parse_symbol(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var r={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,t){return String.fromCharCode(parseInt("0"+t,16))}).replace(/\\(.)/g,function(e,t){return r[t]||t})}return new LSymbol(e)}function parse_argument(e){if(constants.hasOwnProperty(e)){return constants[e]}if(e.match(/^"[\s\S]*"$/)){return parse_string(e)}else if(e[0]==="#"){var t=e.match(re_re);if(t){return new RegExp(t[1],t[2])}else if(e.match(char_re)){return parse_character(e)}var r=e.match(/#\\(.+)/);if(r&&ucs2decode(r[1]).length===1){return parse_character(e)}}if(e.match(/[0-9a-f]|[+-]i/i)){if(e.match(int_re)){return parse_integer(e)}else if(e.match(float_re)){return parse_float(e)}else if(e.match(rational_re)){return parse_rational(e)}else if(e.match(complex_re)){return parse_complex(e)}}if(e.match(/^#[iexobd]/)){throw new Error("Invalid numeric constant: "+e)}return parse_symbol(e)}function is_atom_string(e){return!(["(",")","[","]"].includes(e)||specials.names().includes(e))}function is_symbol_string(e){return is_atom_string(e)&&!(e.match(re_re)||e.match(/^"[\s\S]*"$/)||e.match(int_re)||e.match(float_re)||e.match(complex_re)||e.match(rational_re)||e.match(char_re)||["#t","#f","nil"].includes(e))}var string_re=/"(?:\\[\S\s]|[^"])*"?/g;function escape_regex(e){if(typeof e==="string"){var t=/([-\\^$[\]()+{}?*.|])/g;return e.replace(t,"\\$1")}return e}function Stack(){this.data=[]}Stack.prototype.push=function(e){this.data.push(e)};Stack.prototype.top=function(){return this.data[this.data.length-1]};Stack.prototype.pop=function(){return this.data.pop()};Stack.prototype.is_empty=function(){return!this.data.length};function tokens(e){if(e instanceof LString){e=e.valueOf()}var t=new Lexer(e,{whitespace:true});var r=[];while(true){var n=t.peek(true);if(n===eof){break}r.push(n);t.skip()}return r}function multiline_formatter(e){var t=e.token,r=_objectWithoutProperties(e,_excluded);if(t.match(/^"[\s\S]*"$/)&&t.match(/\n/)){var n=new RegExp("^ {1,"+(e.col+1)+"}","mg");t=t.replace(n,"")}return _objectSpread({token:t},r)}function Thunk(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(){};this.fn=e;this.cont=t}Thunk.prototype.toString=function(){return"#"};function trampoline(n){return function(){for(var e=arguments.length,t=new Array(e),r=0;r1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof LString){e=e.toString()}if(t){return tokens(e)}else{var r=tokens(e).map(function(e){if(e.token==="#\\ "||e.token=="#\\\n"){return e.token}return e.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return strip_s_comments(r)}}function strip_s_comments(e){var t=0;var r=null;var n=[];for(var i=0;i0&&arguments[0]!==undefined?arguments[0]:null;if(e instanceof LSymbol){if(e.is_gensym()){return e}e=e.valueOf()}if(is_gensym(e)){return LSymbol(e)}if(e!==null){return r(e,Symbol("#:".concat(e)))}t++;return r(t,Symbol("#:g".concat(t)))}}();function QuotedPromise(e){var r=this;var n={pending:true,rejected:false,fulfilled:false,reason:undefined,type:undefined};e=e.then(function(e){n.type=type(e);n.fulfilled=true;n.pending=false;return e});read_only(this,"_promise",e,{hidden:true});if(is_function(e["catch"])){e=e["catch"](function(e){n.rejected=true;n.pending=false;n.reason=e})}Object.keys(n).forEach(function(t){Object.defineProperty(r,"__".concat(t,"__"),{enumerable:true,get:function e(){return n[t]}})});read_only(this,"__promise__",e);this.then=false}QuotedPromise.prototype.then=function(e){return new QuotedPromise(this.valueOf().then(e))};QuotedPromise.prototype["catch"]=function(e){return new QuotedPromise(this.valueOf()["catch"](e))};QuotedPromise.prototype.valueOf=function(){if(!this._promise){throw new Error("QuotedPromise: invalid promise created")}return this._promise};QuotedPromise.prototype.toString=function(){if(this.__pending__){return QuotedPromise.pending_str}if(this.__rejected__){return QuotedPromise.rejected_str}return"#")};QuotedPromise.pending_str="#";QuotedPromise.rejected_str="#";function promise_all(e){if(Array.isArray(e)){return Promise.all(escape_quoted_promises(e)).then(unescape_quoted_promises)}return e}function escape_quoted_promises(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof QuotedPromise){t[r]=new Value(n)}else{t[r]=n}}return t}function unescape_quoted_promises(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof Value){t[r]=n.valueOf()}else{t[r]=n}}return t}var specials={LITERAL:Symbol["for"]("literal"),SPLICE:Symbol["for"]("splice"),SYMBOL:Symbol["for"]("symbol"),names:function e(){return Object.keys(this.__list__)},type:function e(t){try{return this.get(t).type}catch(e){console.log({name:t});console.log(e);return null}},get:function e(t){return this.__list__[t]},off:function e(t){var r=this;var n=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(Array.isArray(t)){t.forEach(function(e){return r.off(e,n)})}else if(n===null){delete this.__events__[t]}else{this.__events__=this.__events__.filter(function(e){return e!==n})}},on:function e(t,r){var n=this;if(Array.isArray(t)){t.forEach(function(e){return n.on(e,r)})}else if(!this.__events__[t]){this.__events__[t]=[r]}else{this.__events__[t].push(r)}},trigger:function e(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i",new LSymbol("quote-promise"),specials.LITERAL]];var builtins=defined_specials.map(function(e){return e[0]});Object.freeze(builtins);Object.defineProperty(specials,"__builtins__",{writable:false,value:builtins});defined_specials.forEach(function(e){var t=_slicedToArray(e,3),r=t[0],n=t[1],i=t[2];specials.append(r,n,i)});var Lexer=function(){function p(e){var t=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=r.whitespace,i=n===void 0?false:n;_classCallCheck(this,p);read_only(this,"__input__",e.replace(/\r/g,""));var a={};["_i","_whitespace","_col","_newline","_line","_state","_next","_token","_prev_char"].forEach(function(r){Object.defineProperty(t,r,{configurable:false,enumerable:false,get:function e(){return a[r]},set:function e(t){a[r]=t}})});this._whitespace=i;this._i=this._line=this._col=this._newline=0;this._state=this._next=this._token=null;this._prev_char=""}_createClass(p,[{key:"get",value:function e(t){return this.__internal[t]}},{key:"set",value:function e(t,r){this.__internal[t]=r}},{key:"token",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(t){var r=this._line;if(this._whitespace&&this._token==="\n"){--r}return{token:this._token,col:this._col,offset:this._i,line:r}}return this._token}},{key:"peek",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(this._i>=this.__input__.length){return eof}if(this._token){return this.token(t)}var r=this.next_token();if(r){this._token=this.__input__.substring(this._i,this._next);return this.token(t)}return eof}},{key:"skip",value:function e(){if(this._next!==null){this._token=null;this._i=this._next}}},{key:"read_line",value:function e(){var t=this.__input__.length;if(this._i>=t){return eof}for(var r=this._i;r=r){return eof}if(t+this._i>=r){return this.read_rest()}var n=this._i+t;var i=this.__input__.substring(this._i,n);var a=i.match(/\n/g);if(a){this._line+=a.length}this._i=n;return i}},{key:"peek_char",value:function e(){if(this._i>=this.__input__.length){return eof}return LCharacter(this.__input__[this._i])}},{key:"read_char",value:function e(){var t=this.peek_char();this.skip_char();return t}},{key:"skip_char",value:function e(){if(this._i1&&arguments[1]!==undefined?arguments[1]:{},n=r.prev_char,i=r["char"],a=r.next_char;var o=_slicedToArray(t,4),u=o[0],s=o[1],c=o[2],l=o[3];if(t.length!==5){throw new Error("Lexer: Invalid rule of length ".concat(t.length))}if(is_string(u)){if(u!==i){return false}}else if(!i.match(u)){return false}if(!match_or_null(s,n)){return false}if(!match_or_null(c,a)){return false}if(l!==this._state){return false}return true}},{key:"next_token",value:function e(){if(this._i>=this.__input__.length){return false}var t=true;e:for(var r=this._i,n=this.__input__.length;r2&&arguments[2]!==undefined?arguments[2]:null;var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;if(t.length===0){throw new Error("Lexer: invalid literal rule")}if(t.length===1){return[[t,n,i,null,null]]}var a=[];for(var o=0,u=t.length;o1&&arguments[1]!==undefined?arguments[1]:{},r=t.env,n=t.meta,i=n===void 0?false:n,a=t.formatter,o=a===void 0?multiline_formatter:a;_classCallCheck(this,u);if(e instanceof LString){e=e.toString()}read_only(this,"_formatter",o,{hidden:true});read_only(this,"__lexer__",new Lexer(e));read_only(this,"__env__",r);read_only(this,"_meta",i,{hidden:true});read_only(this,"_refs",[],{hidden:true});read_only(this,"_state",{parentheses:0},{hidden:true})}_createClass(u,[{key:"resolve",value:function e(t){return this.__env__&&this.__env__.get(t,{throwError:false})}},{key:"peek",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var r;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=this.__lexer__.peek(true);if(!(r===eof)){t.next=4;break}return t.abrupt("return",eof);case 4:if(!this.is_comment(r.token)){t.next=7;break}this.skip();return t.abrupt("continue",0);case 7:if(!(r.token==="#;")){t.next=14;break}this.skip();if(!(this.__lexer__.peek()===eof)){t.next=11;break}throw new Error("Lexer: syntax error eof found after comment");case 11:t.next=13;return this._read_object();case 13:return t.abrupt("continue",0);case 14:return t.abrupt("break",17);case 17:r=this._formatter(r);if(!this._meta){t.next=20;break}return t.abrupt("return",r);case 20:return t.abrupt("return",r.token);case 21:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"reset",value:function e(){this._refs.length=0}},{key:"skip",value:function e(){this.__lexer__.skip()}},{key:"read",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var r;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return this.peek();case 2:r=t.sent;this.skip();return t.abrupt("return",r);case 5:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"match_datum_label",value:function e(t){var r=t.match(/^#([0-9]+)=$/);return r&&r[1]}},{key:"match_datum_ref",value:function e(t){var r=t.match(/^#([0-9]+)#$/);return r&&r[1]}},{key:"is_open",value:function e(t){var r=["(","["].includes(t);if(r){this._state.parentheses++}return r}},{key:"is_close",value:function e(t){var r=[")","]"].includes(t);if(r){this._state.parentheses--}return r}},{key:"read_list",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var r,n,i,a,o;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=_nil,n=r;case 1:t.next=4;return this.peek();case 4:a=t.sent;if(!(a===eof)){t.next=7;break}return t.abrupt("break",32);case 7:if(!this.is_close(a)){t.next=10;break}this.skip();return t.abrupt("break",32);case 10:if(!(a==="."&&!is_nil(r))){t.next=18;break}this.skip();t.next=14;return this._read_object();case 14:n.cdr=t.sent;i=true;t.next=30;break;case 18:if(!i){t.next=22;break}throw new Error("Parser: syntax error more than one element after dot");case 22:t.t0=Pair;t.next=25;return this._read_object();case 25:t.t1=t.sent;t.t2=_nil;o=new t.t0(t.t1,t.t2);if(is_nil(r)){r=o}else{n.cdr=o}n=o;case 30:t.next=1;break;case 32:return t.abrupt("return",r);case 33:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"read_value",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var r;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return this.read();case 2:r=t.sent;if(!(r===eof)){t.next=5;break}throw new Error("Parser: Expected token eof found");case 5:return t.abrupt("return",parse_argument(r));case 6:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"is_comment",value:function e(t){return t.match(/^;/)||t.match(/^#\|/)&&t.match(/\|#$/)}},{key:"evaluate",value:function e(t){return _evaluate(t,{env:this.__env__,error:function e(t){throw t}})}},{key:"read_object",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var r;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:this.reset();t.next=3;return this._read_object();case 3:r=t.sent;if(r instanceof DatumReference){r=r.valueOf()}if(!this._refs.length){t.next=7;break}return t.abrupt("return",unpromise(this._resolve_object(r),function(e){if(is_pair(e)){e.mark_cycles()}return e}));case 7:return t.abrupt("return",r);case 8:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"balanced",value:function e(){return this._state.parentheses===0}},{key:"ballancing_error",value:function e(t,r){var n=this._state.parentheses;var i;if(n<0){i=new Error("Parser: unexpected parenthesis");i.__code__=[r.toString()+")"]}else{i=new Error("Parser: expected parenthesis but eof found");var a=new RegExp("\\){".concat(n,"}$"));i.__code__=[t.toString().replace(a,"")]}throw i}},{key:"_resolve_object",value:function(){var t=_asyncToGenerator(_regeneratorRuntime.mark(function e(r){var n=this;var i;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!Array.isArray(r)){t.next=2;break}return t.abrupt("return",r.map(function(e){return n._resolve_object(e)}));case 2:if(!is_plain_object(r)){t.next=6;break}i={};Object.keys(r).forEach(function(e){i[e]=n._resolve_object(r[e])});return t.abrupt("return",i);case 6:if(!is_pair(r)){t.next=8;break}return t.abrupt("return",this._resolve_pair(r));case 8:return t.abrupt("return",r);case 9:case"end":return t.stop()}},e,this)}));function e(e){return t.apply(this,arguments)}return e}()},{key:"_resolve_pair",value:function(){var t=_asyncToGenerator(_regeneratorRuntime.mark(function e(r){return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!is_pair(r)){t.next=15;break}if(!(r.car instanceof DatumReference)){t.next=7;break}t.next=4;return r.car.valueOf();case 4:r.car=t.sent;t.next=8;break;case 7:this._resolve_pair(r.car);case 8:if(!(r.cdr instanceof DatumReference)){t.next=14;break}t.next=11;return r.cdr.valueOf();case 11:r.cdr=t.sent;t.next=15;break;case 14:this._resolve_pair(r.cdr);case 15:return t.abrupt("return",r);case 16:case"end":return t.stop()}},e,this)}));function e(e){return t.apply(this,arguments)}return e}()},{key:"_read_object",value:function(){var e=_asyncToGenerator(_regeneratorRuntime.mark(function e(){var r,n,i,a,o,u,s,c,l,f,_;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return this.peek();case 2:r=t.sent;if(!(r===eof)){t.next=5;break}return t.abrupt("return",r);case 5:if(!is_special(r)){t.next=38;break}n=specials.get(r);i=is_builtin(r);this.skip();o=is_symbol_extension(r);if(!o){t.next=14;break}t.t0=undefined;t.next=17;break;case 14:t.next=16;return this._read_object();case 16:t.t0=t.sent;case 17:u=t.t0;if(i){t.next=25;break}s=this.__env__.get(n.symbol);if(!(typeof s==="function")){t.next=25;break}if(is_literal(r)){c=[u]}else if(is_nil(u)){c=[]}else if(is_pair(u)){c=u.to_array(false)}if(!(c||o)){t.next=24;break}return t.abrupt("return",call_function(s,o?[]:c,{env:this.__env__,dynamic_env:this.__env__,use_dynamic:false}));case 24:throw new Error("Parse Error: Invalid parser extension "+"invocation ".concat(n.symbol));case 25:if(is_literal(r)){a=new Pair(n.symbol,new Pair(u,_nil))}else{a=new Pair(n.symbol,u)}if(!i){t.next=28;break}return t.abrupt("return",a);case 28:if(!(s instanceof Macro)){t.next=37;break}t.next=31;return this.evaluate(a);case 31:l=t.sent;if(!(is_pair(l)||l instanceof LSymbol)){t.next=34;break}return t.abrupt("return",Pair.fromArray([LSymbol("quote"),l]));case 34:return t.abrupt("return",l);case 37:throw new Error("Parse Error: invalid parser extension: "+n.symbol);case 38:f=this.match_datum_ref(r);if(!(f!==null)){t.next=44;break}this.skip();if(!this._refs[f]){t.next=43;break}return t.abrupt("return",new DatumReference(f,this._refs[f]));case 43:throw new Error("Parse Error: invalid datum label #".concat(f,"#"));case 44:_=this.match_datum_label(r);if(!(_!==null)){t.next=51;break}this.skip();this._refs[_]=this._read_object();return t.abrupt("return",this._refs[_]);case 51:if(!this.is_close(r)){t.next=55;break}this.skip();t.next=61;break;case 55:if(!this.is_open(r)){t.next=60;break}this.skip();return t.abrupt("return",this.read_list());case 60:return t.abrupt("return",this.read_value());case 61:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()}]);return u}();var DatumReference=function(){function r(e,t){_classCallCheck(this,r);this.name=e;this.data=t}_createClass(r,[{key:"valueOf",value:function e(){return this.data}}]);return r}();function _parse(e,t){return _parse2.apply(this,arguments)}function _parse2(){_parse2=_wrapAsyncGenerator(_regeneratorRuntime.mark(function e(r,n){var i,a,o;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!n){if(global_env){n=global_env.get("**interaction-environment**",{throwError:false})}else{n=user_env}}i=new Parser(r,{env:n});case 3:t.next=6;return _awaitAsyncGenerator(i.read_object());case 6:o=t.sent;if(!i.balanced()){i.ballancing_error(o,a)}if(!(o===eof)){t.next=10;break}return t.abrupt("break",15);case 10:a=o;t.next=13;return o;case 13:t.next=3;break;case 15:case"end":return t.stop()}},e)}));return _parse2.apply(this,arguments)}function unpromise(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(e){return e};var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;if(is_promise(e)){var n=e.then(t);if(r===null){return n}else{return n["catch"](r)}}if(e instanceof Array){return unpromise_array(e,t,r)}if(is_plain_object(e)){return unpromise_object(e,t,r)}return t(e)}function unpromise_array(t,r,e){if(t.find(is_promise)){return unpromise(promise_all(t),function(e){if(Object.isFrozen(t)){Object.freeze(e)}return r(e)},e)}return r(t)}function unpromise_object(t,e,r){var i=Object.keys(t);var n=[],a=[];var o=i.length;while(o--){var u=i[o];var s=t[u];n[o]=s;if(is_promise(s)){a.push(s)}}if(a.length){return unpromise(promise_all(n),function(e){var n={};e.forEach(function(e,t){var r=i[t];n[r]=e});if(Object.isFrozen(t)){Object.freeze(n)}return n},r)}return e(t)}function read_only(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{},i=n.hidden,a=i===void 0?false:i;Object.defineProperty(e,t,{value:r,configurable:true,enumerable:!a})}function uniterate_async(e){return _uniterate_async.apply(this,arguments)}function _uniterate_async(){_uniterate_async=_asyncToGenerator(_regeneratorRuntime.mark(function e(r){var n,i,a,o,u,s,c;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:n=[];i=false;a=false;t.prev=3;u=_asyncIterator(r);case 5:t.next=7;return u.next();case 7:if(!(i=!(s=t.sent).done)){t.next=13;break}c=s.value;n.push(c);case 10:i=false;t.next=5;break;case 13:t.next=19;break;case 15:t.prev=15;t.t0=t["catch"](3);a=true;o=t.t0;case 19:t.prev=19;t.prev=20;if(!(i&&u["return"]!=null)){t.next=24;break}t.next=24;return u["return"]();case 24:t.prev=24;if(!a){t.next=27;break}throw o;case 27:return t.finish(24);case 28:return t.finish(19);case 29:return t.abrupt("return",n);case 30:case"end":return t.stop()}},e,null,[[3,15,19,29],[20,,24,28]])}));return _uniterate_async.apply(this,arguments)}function matcher(e,t){if(t instanceof RegExp){return function(e){return String(e).match(t)}}else if(is_function(t)){return t}throw new Error("Invalid matcher")}function doc(e,t,r,n){if(typeof e!=="string"){t=arguments[0];r=arguments[1];n=arguments[2];e=null}if(r){if(n){t.__doc__=r}else{t.__doc__=trim_lines(r)}}if(e){t.__name__=e}else if(t.name&&!is_lambda(t)){t.__name__=t.name}return t}function trim_lines(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function previousSexp(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var r=e.length;if(t<=0){throw Error("previousSexp: Invalid argument sexp = ".concat(t))}e:while(t--&&r>=0){var n=1;while(n>0){var i=e[--r];if(!i){break e}if(i==="("||i.token==="("){n--}else if(i===")"||i.token===")"){n++}}r--}return e.slice(r+1)}function lineIndent(e){if(!e||!e.length){return 0}var t=e.length;if(e[t-1].token==="\n"){return 0}while(--t){if(e[t].token==="\n"){var r=(e[t+1]||{}).token;if(r){return r.length}}}return 0}function match(e,t){return l(e,t)===t.length;function l(r,n){function e(e,t){var r=_createForOfIteratorHelper(e),n;try{for(r.s();!(n=r.n()).done;){var i=n.value;var a=l(i,t);if(a!==-1){return a}}}catch(e){r.e(e)}finally{r.f()}return-1}function t(){return r[a]===Symbol["for"]("symbol")&&!is_symbol_string(n[u])}function i(){var e=r[a+1];var t=n[u+1];if(e!==undefined&&t!==undefined){return l([e],[t])}}var a=0;var o={};for(var u=0;u0){continue}}else if(t()){return-1}}else if(r[a]instanceof Array){var c=l(r[a],n.slice(u));if(c===-1||c+u>n.length){return-1}u+=c-1;a++;continue}else{return-1}a++}if(r.length!==a){return-1}return n.length}}function Formatter(e){this.__code__=e.replace(/\r/g,"")}Formatter.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?(?:define(?:-values|-syntax|-macro|-class|-record-type)?|(?:call-with-(?:input-file|output-file|port))|lambda|let-env|try|catch|when|unless|while|syntax-rules|(let|letrec)(-syntax|\*?-values|\*)?)$/],shift:{1:["&","#"]}}};Formatter.match=match;Formatter.prototype._options=function e(t){var r=Formatter.defaults;if(typeof t==="undefined"){return Object.assign({},r)}var n=t&&t.exceptions||{};var i=n.specials||[];var a=n.shift||{1:[]};return _objectSpread(_objectSpread(_objectSpread({},r),t),{},{exceptions:{specials:[].concat(_toConsumableArray(r.exceptions.specials),_toConsumableArray(i)),shift:_objectSpread(_objectSpread({},a),{},{1:[].concat(_toConsumableArray(r.exceptions.shift[1]),_toConsumableArray(a[1]))})}})};Formatter.prototype.indent=function e(t){var r=tokenize(this.__code__,true);return this._indent(r,t)};Formatter.exception_shift=function(a,e){function t(e){if(!e.length){return false}if(e.indexOf(a)!==-1){return true}else{var t=e.filter(function(e){return e instanceof RegExp});if(!t.length){return false}var r=_createForOfIteratorHelper(t),n;try{for(r.s();!(n=r.n()).done;){var i=n.value;if(a.match(i)){return true}}}catch(e){r.e(e)}finally{r.f()}}return false}if(t(e.exceptions.specials)){return e.indent}var r=e.exceptions.shift;for(var n=0,i=Object.entries(r);n0){n.offset=0}if(a.toString()===t.toString()&&balanced(a)){return n.offset+a[0].col}else if(a.length===1){return n.offset+a[0].col+1}else{var s=-1;if(o){var c=Formatter.exception_shift(o.token,n);if(c!==-1){s=c}}if(s===-1){s=Formatter.exception_shift(a[1].token,n)}if(s!==-1){return n.offset+a[0].col+s}else if(a[0].line3&&a[1].line===a[3].line){if(a[1].token==="("||a[1].token==="["){return n.offset+a[1].col}return n.offset+a[3].col}else if(a[0].line===a[1].line){return n.offset+n.indent+a[0].col}else{var l=a.slice(2);for(var f=0;f")};Ahead.prototype.match=function(e){return e.match(this.pattern)};function Pattern(){for(var e=arguments.length,t=new Array(e),r=0;r")};Formatter.Pattern=Pattern;Formatter.Ahead=Ahead;var p_o=/^[[(]$/;var p_e=/^[\])]$/;var not_p=/[^()[\]]/;var not_close=new Ahead(/[^)\]]/);var glob=Symbol["for"]("*");var sexp_or_atom=new Pattern([p_o,glob,p_e],[not_p],"+");var sexp=new Pattern([p_o,glob,p_e],"+");var symbol=new Pattern([Symbol["for"]("symbol")],"?");var symbols=new Pattern([Symbol["for"]("symbol")],"*");var identifiers=[p_o,symbols,p_e];var let_value=new Pattern([p_o,Symbol["for"]("symbol"),glob,p_e],"+");var syntax_rules=keywords_re("syntax-rules");var def_lambda_re=keywords_re("define","lambda","define-macro","syntax-rules");var non_def=/^(?!.*\b(?:[()[\]]|define(?:-macro)?|let(?:\*|rec|-env|-syntax|)?|lambda|syntax-rules)\b).*$/;var let_re=/^(?:#:)?(let(?:\*|rec|-env|-syntax)?)$/;function keywords_re(){for(var e=arguments.length,t=new Array(e),r=0;r0&&!u[e]){u[e]=previousSexp(o,e)}});var s=_createForOfIteratorHelper(i),c;try{for(s.s();!(c=s.n()).done;){var l=_slicedToArray(c.value,3),f=l[0],_=l[1],p=l[2];_=_.valueOf();var d=_>0?u[_]:o;var h=d.filter(function(e){return e.trim()&&!is_special(e)});var m=r(d);var y=match(f,h);var v=n.slice(a).find(function(e){return e.trim()&&!is_special(e)});if(y&&(p instanceof Ahead&&p.match(v)||!p)){var b=a-m;if(n[b]!=="\n"){if(!n[b].trim()){n[b]="\n"}else{n.splice(b,0,"\n");a++}}a+=m;continue e}}}catch(e){s.e(e)}finally{s.f()}}this.__code__=n.join("");return this};Formatter.prototype._spaces=function(e){return" ".repeat(e)};Formatter.prototype.format=function e(t){var r=this.__code__.replace(/[ \t]*\n[ \t]*/g,"\n ");var n=tokenize(r,true);var i=this._options(t);var a=0;var o=0;for(var u=0;u0){n=Math.floor(t()*r);r--;var i=[e[n],e[r]];e[r]=i[0];e[n]=i[1]}return e}function Nil(){}Nil.prototype.toString=function(){return"()"};Nil.prototype.valueOf=function(){return undefined};Nil.prototype.serialize=function(){return 0};Nil.prototype.to_object=function(){return{}};Nil.prototype.append=function(e){return new Pair(e,_nil)};Nil.prototype.to_array=function(){return[]};var _nil=new Nil;function Pair(e,t){if(typeof this!=="undefined"&&this.constructor!==Pair||typeof this==="undefined"){return new Pair(e,t)}this.car=e;this.cdr=t}function to_array(a,o){return function e(t){typecheck(a,t,["pair","nil"]);if(is_nil(t)){return[]}var r=[];var n=t;while(true){if(is_pair(n)){if(n.have_cycles("cdr")){break}var i=n.car;if(o&&is_pair(i)){i=this.get(a).call(this,i)}r.push(i);n=n.cdr}else if(is_nil(n)){break}else{throw new Error("".concat(a,": can't convert improper list"))}}return r}}Pair.prototype.flatten=function(){return Pair.fromArray(flatten(this.to_array()))};Pair.prototype.length=function(){var e=0;var t=this;while(true){if(!t||is_nil(t)||!is_pair(t)||t.have_cycles("cdr")){break}e++;t=t.cdr}return e};Pair.match=function(e,t){if(e instanceof LSymbol){return LSymbol.is(e,t)}else if(is_pair(e)){return Pair.match(e.car,t)||Pair.match(e.cdr,t)}else if(Array.isArray(e)){return e.some(function(e){return Pair.match(e,t)})}else if(is_plain_object(e)){return Object.values(e).some(function(e){return Pair.match(e,t)})}return false};Pair.prototype.find=function(e){return Pair.match(this,e)};Pair.prototype.clone=function(){var r=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var n=new Map;function i(e){if(is_pair(e)){if(n.has(e)){return n.get(e)}var t=new Pair;n.set(e,t);if(r){t.car=i(e.car)}else{t.car=e.car}t.cdr=i(e.cdr);t[__cycles__]=e[__cycles__];return t}return e}return i(this)};Pair.prototype.last_pair=function(){var e=this;while(true){if(!is_pair(e.cdr)){return e}if(e.have_cycles("cdr")){break}e=e.cdr}};Pair.prototype.to_array=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var t=[];if(is_pair(this.car)){if(e){t.push(this.car.to_array())}else{t.push(this.car)}}else{t.push(this.car.valueOf())}if(is_pair(this.cdr)){t=t.concat(this.cdr.to_array(e))}return t};Pair.fromArray=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(is_pair(e)||r&&e instanceof Array&&e[__data__]){return e}if(t===false){var n=_nil;for(var i=e.length;i--;){n=new Pair(e[i],n)}return n}if(e.length&&!(e instanceof Array)){e=_toConsumableArray(e)}var a=_nil;var o=e.length;while(o--){var u=e[o];if(u instanceof Array){u=Pair.fromArray(u,t,r)}else if(typeof u==="string"){u=LString(u)}else if(typeof u==="number"&&!Number.isNaN(u)){u=LNumber(u)}a=new Pair(u,a)}return a};Pair.prototype.to_object=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var t=this;var r={};while(true){if(is_pair(t)&&is_pair(t.car)){var n=t.car;var i=n.car;if(i instanceof LSymbol){i=i.__name__}if(i instanceof LString){i=i.valueOf()}var a=n.cdr;if(is_pair(a)){a=a.to_object(e)}if(is_native(a)){if(!e){a=a.valueOf()}}r[i]=a;t=t.cdr}else{break}}return r};Pair.fromPairs=function(e){return e.reduce(function(e,t){return new Pair(new Pair(new LSymbol(t[0]),t[1]),e)},_nil)};Pair.fromObject=function(t){var e=Object.keys(t).map(function(e){return[e,t[e]]});return Pair.fromPairs(e)};Pair.prototype.reduce=function(e){var t=this;var r=_nil;while(true){if(!is_nil(t)){r=e(r,t.car);t=t.cdr}else{break}}return r};Pair.prototype.reverse=function(){if(this.have_cycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var t=_nil;while(!is_nil(e)){var r=e.cdr;e.cdr=t;t=e;e=r}return t};Pair.prototype.transform=function(n){function i(e){if(is_pair(e)){if(e.replace){delete e.replace;return e}var t=n(e.car);if(is_pair(t)){t=i(t)}var r=n(e.cdr);if(is_pair(r)){r=i(r)}return new Pair(t,r)}return e}return i(this)};Pair.prototype.map=function(e){if(typeof this.car!=="undefined"){return new Pair(e(this.car),is_nil(this.cdr)?_nil:this.cdr.map(e))}else{return _nil}};var repr=new Map;function is_plain_object(e){return e&&_typeof$1(e)==="object"&&e.constructor===Object}var props=Object.getOwnPropertyNames(Array.prototype);var array_methods=[];props.forEach(function(e){array_methods.push(Array[e],Array.prototype[e])});function is_array_method(e){e=unbind(e);return array_methods.includes(e)}function is_lips_function(e){return is_function(e)&&(is_lambda(e)||e.__doc__)}function user_repr(r){var e=r.constructor||Object;var n=is_plain_object(r);var i=is_function(r[Symbol.asyncIterator])||is_function(r[Symbol.iterator]);var a;if(repr.has(e)){a=repr.get(e)}else{repr.forEach(function(e,t){t=unbind(t);if(r instanceof t&&(t===Object&&n&&!i||t!==Object)){a=e}})}return a}var str_mapping=new Map;[[true,"#t"],[false,"#f"],[null,"null"],[undefined,"#"]].forEach(function(e){var t=_slicedToArray(e,2),r=t[0],n=t[1];str_mapping.set(r,n)});function symbolize(r){if(r&&_typeof$1(r)==="object"){var n={};var e=Object.getOwnPropertySymbols(r);e.forEach(function(e){var t=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");n[t]=toString(r[e])});var t=Object.getOwnPropertyNames(r);t.forEach(function(e){var t=r[e];if(t&&_typeof$1(t)==="object"&&t.constructor===Object){n[e]=symbolize(t)}else{n[e]=toString(t)}});return n}return r}function get_props(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function has_own_function(e,t){return e.hasOwnProperty(t)&&is_function(e.toString)}function function_to_string(e){if(is_native_function(e)){return"#"}var t=e.prototype&&e.prototype.constructor;if(is_function(t)&&is_lambda(t)){if(e[__class__]&&t.hasOwnProperty("__name__")){var r=t.__name__;if(LString.isString(r)){r=r.toString();return"#")}return"#"}}if(e.hasOwnProperty("__name__")){var n=e.__name__;if(_typeof$1(n)==="symbol"){n=symbol_to_string(n)}if(typeof n==="string"){return"#")}}if(has_own_function(e,"toString")){return e.toString()}else if(e.name&&!is_lambda(e)){return"#")}else{return"#"}}var instances=new Map;[[Error,function(e){return e.message}],[Pair,function(e,t){var r=t.quote,n=t.skip_cycles,i=t.pair_args;if(!n){e.mark_cycles()}return e.toString.apply(e,[r].concat(_toConsumableArray(i)))}],[LCharacter,function(e,t){var r=t.quote;if(r){return e.toString()}return e.valueOf()}],[LString,function(e,t){var r=t.quote;e=e.toString();if(r){return JSON.stringify(e).replace(/\\n/g,"\n")}return e}],[RegExp,function(e){return"#"+e.toString()}]].forEach(function(e){var t=_slicedToArray(e,2),r=t[0],n=t[1];instances.set(r,n)});var native_types=[LSymbol,Macro,Values,InputPort,OutputPort,Environment,QuotedPromise];function toString(e,t,r){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(str_mapping.has(e)){return str_mapping.get(e)}if(is_prototype(e)){return"#"}if(e){var n=e.constructor;if(instances.has(n)){for(var i=arguments.length,a=new Array(i>3?i-3:0),o=3;o"}if(e===null){return"null"}if(is_function(e)){if(is_function(e.toString)&&e.hasOwnProperty("toString")){return e.toString().valueOf()}return function_to_string(e)}if(_typeof$1(e)==="object"){var l=e.constructor;if(!l){l=Object}var f;if(typeof l.__class__==="string"){f=l.__class__}else{var _=user_repr(e);if(_){if(is_function(_)){return _(e,t)}else{throw new Error("toString: Invalid repr value")}}f=l.name}if(is_function(e.toString)&&e.hasOwnProperty("toString")){return e.toString().valueOf()}if(type(e)==="instance"){if(is_lambda(l)&&l.__name__){f=l.__name__.valueOf()}else if(!is_native_function(l)){f="instance"}}if(is_iterator(e,Symbol.iterator)){if(f){return"#")}return"#"}if(is_iterator(e,Symbol.asyncIterator)){if(f){return"#")}return"#"}if(f!==""){return"#<"+f+">"}return"#"}if(typeof e!=="string"){return e.toString()}return e}Pair.prototype.mark_cycles=function(){mark_cycles(this);return this};Pair.prototype.have_cycles=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(!e){return this.have_cycles("car")||this.have_cycles("cdr")}return!!(this[__cycles__]&&this[__cycles__][e])};Pair.prototype.is_cycle=function(){return is_cycle(this)};function is_cycle(e){if(!is_pair(e)){return false}if(e.have_cycles()){return true}return is_cycle(e.car,fn)||is_cycle(e.cdr,fn)}function mark_cycles(e){var t=[];var i=[];var a=[];function o(e){if(!t.includes(e)){t.push(e)}}function u(e,t,r,n){if(is_pair(r)){if(n.includes(r)){if(!a.includes(r)){a.push(r)}if(!e[__cycles__]){e[__cycles__]={}}e[__cycles__][t]=r;if(!i.includes(e)){i.push(e)}return true}}}var s=trampoline(function e(t,r){if(is_pair(t)){delete t.ref;delete t[__cycles__];o(t);r.push(t);var n=u(t,"car",t.car,r);var i=u(t,"cdr",t.cdr,r);if(!n){s(t.car,r.slice())}if(!i){return new Thunk(function(){return e(t.cdr,r.slice())})}}});function r(e,t){if(is_pair(e[__cycles__][t])){var r=n.indexOf(e[__cycles__][t]);e[__cycles__][t]="#".concat(r,"#")}}s(e,[]);var n=t.filter(function(e){return a.includes(e)});n.forEach(function(e,t){e[__ref__]="#".concat(t,"=")});i.forEach(function(e){r(e,"car");r(e,"cdr")})}Pair.prototype.toString=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.nested,n=r===void 0?false:r;var i=[];if(this[__ref__]){i.push(this[__ref__]+"(")}else if(!n){i.push("(")}var a;if(this[__cycles__]&&this[__cycles__].car){a=this[__cycles__].car}else{a=toString(this.car,e,true)}if(a!==undefined){i.push(a)}if(is_pair(this.cdr)){if(this[__cycles__]&&this[__cycles__].cdr){i.push(" . ");i.push(this[__cycles__].cdr)}else{if(this.cdr[__ref__]){i.push(" . ")}else{i.push(" ")}var o=this.cdr.toString(e,{nested:true});i.push(o)}}else if(!is_nil(this.cdr)){i=i.concat([" . ",toString(this.cdr,e,true)])}if(!n||this[__ref__]){i.push(")")}return i.join("")};Pair.prototype.set=function(e,t){this[e]=t;if(is_pair(t)){this.mark_cycles()}};Pair.prototype.append=function(e){if(e instanceof Array){return this.append(Pair.fromArray(e))}var t=this;if(t.car===undefined){if(is_pair(e)){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(!is_nil(e)){while(true){if(is_pair(t)&&!is_nil(t.cdr)){t=t.cdr}else{break}}t.cdr=e}return this};Pair.prototype.serialize=function(){return[this.car,this.cdr]};Pair.prototype[Symbol.iterator]=function(){var r=this;return{next:function e(){var t=r;r=t.cdr;if(is_nil(t)){return{value:undefined,done:true}}else{return{value:t.car,done:false}}}}};function abs(e){return e<0?-e:e}function seq_compare(e,t){var r=_toArray(t),n=r[0],i=r.slice(1);while(i.length>0){var a=i,o=_slicedToArray(a,1),u=o[0];if(!e(n,u)){return false}var s=i;var c=_toArray(s);n=c[0];i=c.slice(1)}return true}function equal(e,t){if(is_function(e)){return is_function(t)&&unbind(e)===unbind(t)}else if(e instanceof LNumber){if(!(t instanceof LNumber)){return false}var r;if(e.__type__===t.__type__){if(e.__type__==="complex"){r=e.__im__.__type__===t.__im__.__type__&&e.__re__.__type__===t.__re__.__type__}else{r=true}if(r&&e.cmp(t)===0){if(e.valueOf()===0){return Object.is(e.valueOf(),t.valueOf())}return true}}return false}else if(typeof e==="number"){if(typeof t!=="number"){return false}if(Number.isNaN(e)){return Number.isNaN(t)}if(e===Number.NEGATIVE_INFINITY){return t===Number.NEGATIVE_INFINITY}if(e===Number.POSITIVE_INFINITY){return t===Number.POSITIVE_INFINITY}return equal(LNumber(e),LNumber(t))}else if(e instanceof LCharacter){if(!(t instanceof LCharacter)){return false}return e.__char__===t.__char__}else{return e===t}}function same_atom(e,t){if(type(e)!==type(t)){return false}if(!is_atom(e)){return false}if(e instanceof RegExp){return e.source===t.source}if(e instanceof LString){return e.valueOf()===t.valueOf()}return equal(e,t)}function is_atom(e){return e instanceof LSymbol||LString.isString(e)||is_nil(e)||e===null||e instanceof LCharacter||e instanceof LNumber||e===true||e===false}var truncate=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e===0){return 0}else if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function Macro(e,t,r,n){if(typeof this!=="undefined"&&this.constructor!==Macro||typeof this==="undefined"){return new Macro(e,t)}typecheck("Macro",e,"string",1);typecheck("Macro",t,"function",2);if(r){if(n){this.__doc__=r}else{this.__doc__=trim_lines(r)}}this.__name__=e;this.__fn__=t}Macro.defmacro=function(e,t,r,n){var i=new Macro(e,t,r,n);i.__defmacro__=true;return i};Macro.prototype.invoke=function(e,t,r){var n=t.env,i=_objectWithoutProperties(t,_excluded2);var a=_objectSpread(_objectSpread({},i),{},{macro_expand:r});var o=this.__fn__.call(n,e,a,this.__name__);return o};Macro.prototype.toString=function(){return"#")};var macro="define-macro";var recur_guard=-1e4;function macro_expand(c){return function(){var r=_asyncToGenerator(_regeneratorRuntime.mark(function e(r,v){var a,b,n,i,o,g,w,D,x,L,E,S,u,A,s;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:s=function e(){s=_asyncToGenerator(_regeneratorRuntime.mark(function e(r,n,i){var a,o,u,s,c,l,f,_,p,d,h,m,y;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!(is_pair(r)&&r.car instanceof LSymbol)){t.next=50;break}if(!r[__data__]){t.next=3;break}return t.abrupt("return",r);case 3:a=r.car.valueOf();o=i.get(r.car,{throwError:false});u=g(r.car);s=u||w(o,r)||D(o);if(!(s&&is_pair(r.cdr.car))){t.next=28;break}if(!u){t.next=15;break}b=L(r.cdr.car);t.next=12;return S(r.cdr.car,n);case 12:c=t.sent;t.next=17;break;case 15:b=x(r.cdr.car);c=r.cdr.car;case 17:t.t0=Pair;t.t1=r.car;t.t2=Pair;t.t3=c;t.next=23;return A(r.cdr.cdr,n,i);case 23:t.t4=t.sent;t.t5=new t.t2(t.t3,t.t4);return t.abrupt("return",new t.t0(t.t1,t.t5));case 28:if(!E(a,o)){t.next=50;break}l=o instanceof Syntax?r:r.cdr;t.next=32;return o.invoke(l,_objectSpread(_objectSpread({},v),{},{env:i}),true);case 32:f=t.sent;if(!(o instanceof Syntax)){t.next=41;break}_=f,p=_.expr,d=_.scope;if(!is_pair(p)){t.next=40;break}if(!(n!==-1&&n<=1||n")}return"#"};var SyntaxParameter=_createClass(function e(t){_classCallCheck(this,e);read_only(this,"_syntax",t,{hidden:true});read_only(this._syntax,"_param",true,{hidden:true})});Syntax.Parameter=SyntaxParameter;function extract_patterns(e,t,B,I){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:{};var j={"...":{symbols:{},lists:[]},symbols:{}};var R=r.expansion,T=r.define;log(B);function M(t,e){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:false;log({code:e,pattern:t});if(is_atom(t)&&!(t instanceof LSymbol)){return same_atom(t,e)}if(t instanceof LSymbol&&B.includes(t.literal())){if(!LSymbol.is(e,t)){return false}var i=R.ref(t);return!i||i===T||i===global_env}if(Array.isArray(t)&&Array.isArray(e)){log("<<< a 1");if(t.length===0&&e.length===0){return true}if(LSymbol.is(t[1],I)){if(t[0]instanceof LSymbol){var a=t[0].valueOf();log("<<< a 2 "+n);if(n){var o=e.length-2;var u=o>0?e.slice(0,o):e;var s=Pair.fromArray(u,false);if(!j["..."].symbols[a]){j["..."].symbols[a]=new Pair(s,_nil)}else{j["..."].symbols[a].append(new Pair(s,_nil))}}else{j["..."].symbols[a]=Pair.fromArray(e,false)}}else if(Array.isArray(t[0])){log("<<< a 3");var c=_toConsumableArray(r);if(!e.every(function(e){return M(t[0],e,c,true)})){return false}}if(t.length>2){var l=t.slice(2);return M(l,e.slice(-l.length),r,n)}return true}var f=M(t[0],e[0],r,n);log({first:f,pattern:t[0],code:e[0]});var _=M(t.slice(1),e.slice(1),r,n);log({first:f,rest:_});return f&&_}if(is_pair(t)&&is_pair(t.car)&&is_pair(t.car.cdr)&&LSymbol.is(t.car.cdr.car,I)){log(">> 0");if(is_nil(e)){log({pattern:t});if(t.car.car instanceof LSymbol){var p=t.car.car.valueOf();if(j["..."].symbols[p]){throw new Error("syntax: named ellipsis can only "+"appear onces")}j["..."].symbols[p]=e}}}if(is_pair(t)&&is_pair(t.cdr)&&LSymbol.is(t.cdr.car,I)){if(!is_nil(t.cdr.cdr)){if(is_pair(t.cdr.cdr)){var d=t.cdr.cdr.length();if(!is_pair(e)){return false}var h=e.length();var m=e;while(h-1>d){m=m.cdr;h--}var y=m.cdr;m.cdr=_nil;if(!M(t.cdr.cdr,y,r,n)){return false}}}if(t.car instanceof LSymbol){var v=t.car.__name__;if(j["..."].symbols[v]&&!r.includes(v)&&!n){throw new Error("syntax: named ellipsis can only appear onces")}log(">> 1");if(is_nil(e)){log(">> 2");if(n){log("NIL");j["..."].symbols[v]=_nil}else{log("NULL");j["..."].symbols[v]=null}}else if(is_pair(e)&&(is_pair(e.car)||is_nil(e.car))){log(">> 3 "+n);if(n){if(j["..."].symbols[v]){var b=j["..."].symbols[v];if(is_nil(b)){b=new Pair(_nil,new Pair(e,_nil))}else{b=b.append(new Pair(e,_nil))}j["..."].symbols[v]=b}else{j["..."].symbols[v]=new Pair(e,_nil)}}else{log(">> 4");j["..."].symbols[v]=new Pair(e,_nil)}}else{log(">> 6");if(is_pair(e)){if(!is_pair(e.cdr)&&!is_nil(e.cdr)){log(">> 7 (b)");if(is_nil(t.cdr.cdr)){return false}else if(!j["..."].symbols[v]){j["..."].symbols[v]=new Pair(e.car,_nil);return M(t.cdr.cdr,e.cdr)}}var g=e.last_pair();if(!is_nil(g.cdr)){if(is_nil(t.cdr.cdr)){return false}else{var w=e.clone();w.last_pair().cdr=_nil;j["..."].symbols[v]=w;return M(t.cdr.cdr,g.cdr)}}log(">> 7 "+n);r.push(v);if(!j["..."].symbols[v]){j["..."].symbols[v]=new Pair(e,_nil)}else{var D=j["..."].symbols[v];j["..."].symbols[v]=D.append(new Pair(e,_nil))}log({IIIIII:j["..."].symbols[v]})}else if(t.car instanceof LSymbol&&is_pair(t.cdr)&&LSymbol.is(t.cdr.car,I)){log(">> 8");j["..."].symbols[v]=null;return M(t.cdr.cdr,e)}else{log(">> 9");return false}}return true}else if(is_pair(t.car)){var x=_toConsumableArray(r);if(is_nil(e)){log(">> 10");j["..."].lists.push(_nil);return true}log(">> 11");var L=e;while(is_pair(L)){if(!M(t.car,L.car,x,true)){return false}L=L.cdr}return true}if(Array.isArray(t.car)){var x=_toConsumableArray(r);var E=e;while(is_pair(E)){if(!M(t.car,E.car,x,true)){return false}E=E.cdr}return true}return false}if(t instanceof LSymbol){if(LSymbol.is(t,I)){throw new Error("syntax: invalid usage of ellipsis")}log(">> 12");var S=t.__name__;if(B.includes(S)){return true}if(n){var A,F;log(j["..."].symbols[S]);(F=(A=j["..."].symbols)[S])!==null&&F!==void 0?F:A[S]=[];j["..."].symbols[S].push(e)}else{j.symbols[S]=e}return true}if(is_pair(t)&&is_pair(e)){log(">> 13");log({a:13,code:e,pattern:t});if(is_nil(e.cdr)){var k=t.car instanceof LSymbol&&t.cdr instanceof LSymbol;if(k){if(!M(t.car,e.car,r,n)){return false}log(">> 14");var C=t.cdr.valueOf();if(!(C in j.symbols)){j.symbols[C]=_nil}C=t.car.valueOf();if(!(C in j.symbols)){j.symbols[C]=e.car}return true}}log({pattern:t,code:e});if(is_pair(t.cdr)&&is_pair(t.cdr.cdr)&&t.cdr.car instanceof LSymbol&&LSymbol.is(t.cdr.cdr.car,I)&&is_pair(t.cdr.cdr.cdr)&&!LSymbol.is(t.cdr.cdr.cdr.car,I)&&M(t.car,e.car,r,n)&&M(t.cdr.cdr.cdr,e.cdr,r,n)){var O=t.cdr.car.__name__;log({pattern:t,code:e,name:O});if(B.includes(O)){return true}j["..."].symbols[O]=null;return true}log("recur");log({pattern:t,code:e});var P=M(t.car,e.car,r,n);log({car:P,pattern:t.car,code:e.car});var N=M(t.cdr,e.cdr,r,n);log({car:P,cdr:N});if(P&&N){return true}}else if(is_nil(t)&&(is_nil(e)||e===undefined)){return true}else if(is_pair(t.car)&&LSymbol.is(t.car.car,I)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(M(e,t)){return j}}function clear_gensyms(e,i){function a(t){if(is_pair(t)){if(!i.length){return t}var e=a(t.car);var r=a(t.cdr);return new Pair(e,r)}else if(t instanceof LSymbol){var n=i.find(function(e){return e.gensym===t});if(n){return LSymbol(n.name)}return t}else{return t}}return a(e)}function transform_syntax(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var P=e.bindings,t=e.expr,N=e.scope,o=e.symbols,l=e.names,B=e.ellipsis;var f={};function u(e){if(e instanceof LSymbol){return true}return["string","symbol"].includes(_typeof$1(e))}function I(e){if(!u(e)){var t=type(e);throw new Error("syntax: internal error, need symbol got ".concat(t))}var r=e.valueOf();if(r===B){throw new Error("syntax: internal error, ellipis not transformed")}var n=_typeof$1(r);if(["string","symbol"].includes(n)){if(r in P.symbols){return P.symbols[r]}else if(n==="string"&&r.match(/\./)){var i=r.split(".");var a=i[0];if(a in P.symbols){return Pair.fromArray([LSymbol("."),P.symbols[a]].concat(i.slice(1).map(function(e){return LString(e)})))}}}if(o.includes(r)){return e}return s(r,e)}function s(e,t){if(!f[e]){var r=N.ref(e);if(_typeof$1(e)==="symbol"&&!r){e=t.literal()}if(f[e]){return f[e]}var n=gensym(e);if(r){var i=N.get(e);N.set(n,i)}else{var a=N.get(e,{throwError:false});if(typeof a!=="undefined"){N.set(n,a)}}l.push({name:e,gensym:n});f[e]=n;if(typeof e==="string"&&e.match(/\./)){var o=e.split(".").filter(Boolean),u=_toArray(o),s=u[0],c=u.slice(1);if(f[s]){hidden_prop(n,"__object__",[f[s]].concat(_toConsumableArray(c)))}}}return f[e]}function j(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:function(){};var i=r.nested;log({bindings:t,expr:e});if(Array.isArray(e)&&!e.length){return e}if(e instanceof LSymbol){var a=e.valueOf();if(is_gensym(e)&&!t[a]);log("[t 1");if(t[a]){if(is_pair(t[a])){var o=t[a],u=o.car,s=o.cdr;if(i){var c=u.car,l=u.cdr;if(!is_nil(l)){n(a,new Pair(l,_nil))}return c}if(!is_nil(s)){n(a,s)}return u}else if(t[a]instanceof Array){n(a,t[a].slice(1));return t[a][0]}}return I(e)}var f=Array.isArray(e);if(is_pair(e)||f){var _=f?e[0]:e.car;var p=f?e[1]:is_pair(e.cdr)&&e.cdr.car;if(_ instanceof LSymbol&&LSymbol.is(p,B)){f?e.slice(2):e.cdr.cdr;log("[t 2");var d=_.valueOf();var h=t[d];if(h===null){return}else if(h){log({name:d,binding:t[d]});if(is_pair(h)){log("[t 2 Pair "+i);var m=h.car,y=h.cdr;var v=f?e.slice(2):e.cdr.cdr;if(i){if(!is_nil(y)){log("|| next 1");n(d,y)}if(f&&v.length||!is_nil(v)&&!f){var b=j(v,t,r,n);if(f){return m.concat(b)}else if(is_pair(m)){return m.append(b)}else{log("UNKNOWN")}}return m}else if(is_pair(m)){if(!is_nil(m.cdr)){log("|| next 2");n(d,new Pair(m.cdr,y))}return m.car}else if(is_nil(y)){return m}else{var g=e.last_pair();if(g.cdr instanceof LSymbol){log("|| next 3");n(d,h.last_pair());return m}}}else if(h instanceof Array){log("[t 2 Array "+i);if(i){n(d,h.slice(1));return Pair.fromArray(h)}else{var w=h.slice(1);if(w.length){n(d,w)}return h[0]}}else{return h}}}log("[t 3 recur ",e);var D=f?e.slice(1):e.cdr;var x=j(_,t,r,n);var L=j(D,t,r,n);log({head:x,rest:L});if(f){return[x].concat(L)}return new Pair(x,L)}return e}function R(t,r){var e=Object.values(t);var n=Object.getOwnPropertySymbols(t);if(n.length){e.push.apply(e,_toConsumableArray(n.map(function(e){return t[e]})))}return e.length&&e.every(function(e){if(e===null){return!r}return is_pair(e)||is_nil(e)||Array.isArray(e)&&e.length})}function T(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function M(i){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},t=e.disabled;log("traverse>> ",i);var a=Array.isArray(i);if(a&&i.length===0){return i}if(is_pair(i)||a){var r=a?i[0]:i.car;var n,o;if(a){n=i[1];o=i.slice(2)}else if(is_pair(i.cdr)){n=i.cdr.car;o=i.cdr.cdr}log({first:r,second:n,rest_second:o});if(!t&&is_pair(r)&&LSymbol.is(r.car,B)){return M(r.cdr,{disabled:true})}if(n&&LSymbol.is(n,B)&&!t){log(">> 1");var u=P["..."].symbols;var s=Object.values(u);if(s.length&&s.every(function(e){return e===null})){log(">>> 1 (a)");return M(o,{disabled:t})}var c=T(u);var l=r instanceof LSymbol&&LSymbol.is(o.car,B);if(is_pair(r)||l){log(">>> 1 (b)");if(is_nil(P["..."].lists[0])){if(!l){return M(o,{disabled:t})}log(o);return _nil}var f=r;if(l){log(">>> 1 (c)");f=new Pair(r,new Pair(n,_nil))}log(">> 2");var _;if(c.length){log(">> 2 (a)");var p=_objectSpread({},u);_=a?[]:_nil;var d=function e(){log({bind:p});if(!R(p)){return 1}var n={};var t=function e(t,r){n[t]=r};var r=j(f,p,{nested:true},t);if(r!==undefined){if(l){if(a){if(Array.isArray(r)){var i;(i=_).push.apply(i,_toConsumableArray(r))}else{log("ZONK {1}")}}else{if(is_nil(_)){_=r}else{_=_.append(r)}}}else if(a){_.push(r)}else{_=new Pair(r,_)}}p=n};while(true){if(d())break}if(!is_nil(_)&&!l&&!a){_=_.reverse()}if(a){if(o){log({rest_second:o,expr:i});var h=M(o,{disabled:t});return _.concat(h)}return _}if(!is_nil(i.cdr.cdr)&&!LSymbol.is(i.cdr.cdr.car,B)){var m=M(i.cdr.cdr,{disabled:t});return _.append(m)}return _}else{log(">> 3");var y=j(r,u,{nested:true});if(y){return new Pair(y,_nil)}return _nil}}else if(r instanceof LSymbol){log(">> 4");if(LSymbol.is(o.car,B)){log(">> 4 (a)")}else{log(">> 4 (b)")}var v=r.__name__;var b=_defineProperty({},v,u[v]);log({bind:b});var g=u[v]===null;var w=a?[]:_nil;var D=function e(){if(!R(b,true)){log({bind:b});return 1}var n={};var t=function e(t,r){n[t]=r};var r=j(i,b,{nested:false},t);log({value:r});if(typeof r!=="undefined"){if(a){w.push(r)}else{w=new Pair(r,w)}}b=n};while(true){if(D())break}if(!is_nil(w)&&!a){w=w.reverse()}if(is_pair(i.cdr)){if(is_pair(i.cdr.cdr)||i.cdr.cdr instanceof LSymbol){var x=M(i.cdr.cdr,{disabled:t});log({node:x});if(g){return x}if(is_nil(w)){w=x}else{w.append(x)}log({result:w,node:x})}}log("<<<< 2");return w}}var L=M(r,{disabled:t});var E;var S;if(r instanceof LSymbol){var A=N.get(r,{throwError:false});S=A instanceof Macro&&A.__name__==="syntax-rules"}if(S){if(i.cdr.car instanceof LSymbol){E=new Pair(M(i.cdr.car,{disabled:t}),new Pair(i.cdr.cdr.car,M(i.cdr.cdr.cdr,{disabled:t})))}else{E=new Pair(i.cdr.car,M(i.cdr.cdr,{disabled:t}))}log("REST >>>> ",E)}else{E=M(i.cdr,{disabled:t})}log({a:true,car:toString(i.car),cdr:toString(i.cdr),head:toString(L),rest:toString(E)});return new Pair(L,E)}if(i instanceof LSymbol){if(t&&LSymbol.is(i,B)){return i}var F=Object.keys(P["..."].symbols);var k=i.literal();if(F.includes(k)){var C="missing ellipsis symbol next to name `".concat(k,"'");throw new Error("syntax-rules: ".concat(C))}var O=I(i);if(typeof O!=="undefined"){return O}}return i}return M(t,{})}function is_null(e){return is_undef(e)||is_nil(e)||e===null}function is_nil(e){return e===_nil}function is_function(e){return typeof e==="function"&&typeof e.bind==="function"}function is_string(e){return typeof e==="string"}function is_prototype(e){return e&&_typeof$1(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}function is_continuation(e){return e instanceof Continuation}function is_context(e){return e instanceof LambdaContext}function is_parameter(e){return e instanceof Parameter}function is_pair(e){return e instanceof Pair}function is_env(e){return e instanceof Environment}function is_callable(e){return is_function(e)||is_continuation(e)||is_parameter(e)||is_macro(e)}function is_macro(e){return e instanceof Macro||e instanceof SyntaxParameter}function is_promise(e){if(e instanceof QuotedPromise){return false}if(e instanceof Promise){return true}return!!e&&is_function(e.then)}function is_undef(e){return typeof e==="undefined"}function is_iterator(e,t){if(has_own_symbol(e,t)||has_own_symbol(e.__proto__,t)){return is_function(e[t])}}function is_instance(e){if(!e){return false}if(_typeof$1(e)!=="object"){return false}if(e.__instance__){e.__instance__=false;return e.__instance__}return false}function self_evaluated(e){var t=_typeof$1(e);return["string","function"].includes(t)||_typeof$1(e)==="symbol"||e instanceof QuotedPromise||e instanceof LSymbol||e instanceof LNumber||e instanceof LString||e instanceof RegExp}function is_native(e){return e instanceof LNumber||e instanceof LString||e instanceof LCharacter}function has_own_symbol(e,t){if(e===null){return false}return _typeof$1(e)==="object"&&t in Object.getOwnPropertySymbols(e)}function box(e){switch(_typeof$1(e)){case"string":return LString(e);case"bigint":return LNumber(e);case"number":if(Number.isNaN(e)){return nan}else{return LNumber(e)}}return e}function map_object(r,n){var e=Object.getOwnPropertyNames(r);var t=Object.getOwnPropertySymbols(r);var i={};e.concat(t).forEach(function(e){var t=n(r[e]);i[e]=t});return i}function unbox(t){var e=[LString,LNumber].some(function(e){return t instanceof e});if(e){return t.valueOf()}if(t instanceof Array){return t.map(unbox)}if(t instanceof QuotedPromise){delete t.then}if(is_plain_object(t)){return map_object(t,unbox)}return t}function patch_value(e,t){if(is_pair(e)){e.mark_cycles();return quote(e)}if(is_function(e)){if(t){return bind(e,t)}}return box(e)}function unbind(e){if(is_bound(e)){return e[__fn__]}return e}function bind(e,t){if(e[Symbol["for"]("__bound__")]){return e}var r=e.bind(t);var n=Object.getOwnPropertyNames(e);var i=_createForOfIteratorHelper(n),a;try{for(i.s();!(a=i.n()).done;){var o=a.value;if(filter_fn_names(o)){try{r[o]=e[o]}catch(e){}}}}catch(e){i.e(e)}finally{i.f()}hidden_prop(r,"__fn__",e);hidden_prop(r,"__context__",t);hidden_prop(r,"__bound__",true);if(is_native_function(e)){hidden_prop(r,"__native__",true)}if(is_plain_object(t)&&is_lambda(e)){hidden_prop(r,"__method__",true)}r.valueOf=function(){return e};return r}function is_object_bound(e){return is_bound(e)&&e[Symbol["for"]("__context__")]===Object}function is_bound(e){return!!(is_function(e)&&e[__fn__])}function lips_context(e){if(is_function(e)){var t=e[__context__];if(t&&(t===lips||t.constructor&&t.constructor.__class__)){return true}}return false}function is_port(e){return e instanceof InputPort||e instanceof OutputPort}function is_port_method(e){if(is_function(e)){if(is_port(e[__context__])){return true}}return false}var __context__=Symbol["for"]("__context__");var __fn__=Symbol["for"]("__fn__");var __data__=Symbol["for"]("__data__");var __ref__=Symbol["for"]("__ref__");var __cycles__=Symbol["for"]("__cycles__");var __class__=Symbol["for"]("__class__");var __method__=Symbol["for"]("__method__");var __prototype__=Symbol["for"]("__prototype__");var __lambda__=Symbol["for"]("__lambda__");var exluded_names=["name","length","caller","callee","arguments","prototype"];function filter_fn_names(e){return!exluded_names.includes(e)}function hidden_prop(e,t,r){Object.defineProperty(e,Symbol["for"](t),{get:function e(){return r},set:function e(){},configurable:false,enumerable:false})}function set_fn_length(t,r){try{Object.defineProperty(t,"length",{get:function e(){return r}});return t}catch(e){var n=new Array(r).fill(0).map(function(e,t){return"a"+t}).join(",");var i=new Function("f","return function(".concat(n,") {\n return f.apply(this, arguments);\n };"));return i(t)}}function is_lambda(e){return e&&e[__lambda__]}function is_method(e){return e&&e[__method__]}function is_raw_lambda(e){return is_lambda(e)&&!e[__prototype__]&&!is_method(e)&&!is_port_method(e)}function is_native_function(e){var t=Symbol["for"]("__native__");return is_function(e)&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[t]===true||!e.name.match(/^bound /)&&!e[t])}function let_macro(e){var g;switch(e){case Symbol["for"]("letrec"):g="letrec";break;case Symbol["for"]("let"):g="let";break;case Symbol["for"]("let*"):g="let*";break;default:throw new Error("Invalid let_macro value")}return Macro.defmacro(g,function(t,e){var l=e.dynamic_env;var f=e.error,r=e.macro_expand,_=e.use_dynamic;var p;if(t.car instanceof LSymbol){if(!(is_pair(t.cdr.car)||is_nil(t.cdr.car))){throw new Error("let require list of pairs")}var n;if(is_nil(t.cdr.car)){p=_nil;n=_nil}else{n=t.cdr.car.map(function(e){return e.car});p=t.cdr.car.map(function(e){return e.cdr.car})}return Pair.fromArray([LSymbol("letrec"),[[t.car,Pair(LSymbol("lambda"),Pair(n,t.cdr.cdr))]],Pair(t.car,p)])}else if(r){return}var d=this;p=global_env.get("list->array")(t.car);var h=d.inherit(g);var m,y;if(g==="let*"){y=h}else if(g==="let"){m=[]}var v=0;function b(){var e=new Pair(new LSymbol("begin"),t.cdr);return _evaluate(e,{env:h,dynamic_env:h,use_dynamic:_,error:f})}return function t(){var r=p[v++];l=g==="let*"?h:d;if(!r){if(m&&m.length){var e=m.map(function(e){return e.value});var n=e.filter(is_promise);if(n.length){return promise_all(e).then(function(e){for(var t=0,r=e.length;t1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=t.error;var i=this;var a=this;var o=[];var u=e;while(is_pair(u)){o.push(_evaluate(u.car,{env:i,dynamic_env:a,use_dynamic:r,error:n}));u=u.cdr}var s=o.filter(is_promise).length;if(s){return promise_all(o).then(c.bind(this))}else{return c.call(this,o)}})}function guard_math_call(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n2?n-2:0),a=2;a1&&arguments[1]!==undefined?arguments[1]:null;return function(){for(var e=arguments.length,t=new Array(e),r=0;r1?e-1:0),r=1;r=o){return a.apply(this,n)}else{return i}}return i.apply(this,arguments)}}function limit(n,i){typecheck("limit",i,"function",2);return function(){for(var e=arguments.length,t=new Array(e),r=0;r1){e=e.toLowerCase();if(LCharacter.__names__[e]){t=e;e=LCharacter.__names__[e]}else{throw new Error("Internal: Unknown named character")}}else{t=LCharacter.__rev_names__[e]}Object.defineProperty(this,"__char__",{value:e,enumerable:true});if(t){Object.defineProperty(this,"__name__",{value:t,enumerable:true})}}LCharacter.__names__=characters;LCharacter.__rev_names__={};Object.keys(LCharacter.__names__).forEach(function(e){var t=LCharacter.__names__[e];LCharacter.__rev_names__[t]=e});LCharacter.prototype.toUpperCase=function(){return LCharacter(this.__char__.toUpperCase())};LCharacter.prototype.toLowerCase=function(){return LCharacter(this.__char__.toLowerCase())};LCharacter.prototype.toString=function(){return"#\\"+(this.__name__||this.__char__)};LCharacter.prototype.valueOf=LCharacter.prototype.serialize=function(){return this.__char__};function LString(e){if(typeof this!=="undefined"&&!(this instanceof LString)||typeof this==="undefined"){return new LString(e)}if(e instanceof Array){this.__string__=e.map(function(e,t){typecheck("LString",e,"character",t+1);return e.toString()}).join("")}else{this.__string__=e.valueOf()}}{var ignore=["length","constructor"];var _keys=Object.getOwnPropertyNames(String.prototype).filter(function(e){return!ignore.includes(e)});var wrap=function e(n){return function(){for(var e=arguments.length,t=new Array(e),r=0;r0){r.push(this.__string__.substring(0,e))}r.push(t);if(e1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof LNumber){return e}if(typeof this!=="undefined"&&!(this instanceof LNumber)||typeof this==="undefined"){return new LNumber(e,t)}if(typeof e==="undefined"){throw new Error("Invalid LNumber constructor call")}var r=LNumber.getType(e);if(LNumber.types[r]){return LNumber.types[r](e,t)}var n=e instanceof Array&&LString.isString(e[0])&&LNumber.isNumber(e[1]);if(e instanceof LNumber){return LNumber(e.value)}if(!LNumber.isNumber(e)&&!n){throw new Error("You can't create LNumber from ".concat(type(e)))}if(e===null){e=0}var i;if(n){var a=e,o=_slicedToArray(a,2),u=o[0],s=o[1];if(u instanceof LString){u=u.valueOf()}if(s instanceof LNumber){s=s.valueOf()}var c=u.match(/^([+-])/);var l=false;if(c){u=u.replace(/^[+-]/,"");if(c[1]==="-"){l=true}}}if(Number.isNaN(e)){return LFloat(e)}else if(n&&Number.isNaN(parseInt(u,s))){return nan}else if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(n){var f;switch(s){case 8:f="0o";break;case 16:f="0x";break;case 2:f="0b";break;case 10:f="";break}if(typeof f==="undefined"){var _=BigInt(s);i=_toConsumableArray(u).map(function(e,t){return BigInt(parseInt(e,s))*pow(_,BigInt(t))}).reduce(function(e,t){return e+t})}else{i=BigInt(f+u)}}else{i=BigInt(e)}if(l){i*=BigInt(-1)}}else{i=e}return LBigInteger(i,true)}else if(typeof BN!=="undefined"&&!(e instanceof BN)){if(e instanceof Array){return LBigInteger(_construct(BN,_toConsumableArray(e)))}return LBigInteger(new BN(e))}else if(n){this.constant(parseInt(u,s),"integer")}else{this.constant(e,"integer")}}LNumber.prototype.constant=function(e,t){Object.defineProperty(this,"__value__",{value:e,enumerable:true});Object.defineProperty(this,"__type__",{value:t,enumerable:true})};LNumber.types={float:function e(t){return new LFloat(t)},complex:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!LNumber.isComplex(t)){t={im:0,re:t}}return new LComplex(t,r)},rational:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!LNumber.isRational(t)){t={num:t,denom:1}}return new LRational(t,r)}};LNumber.prototype.serialize=function(){return this.__value__};LNumber.prototype.isNaN=function(){return Number.isNaN(this.__value__)};LNumber.prototype.gcd=function(e){var t=this.abs();e=e.abs();if(e.cmp(t)===1){var r=t;t=e;e=r}while(true){t=t.rem(e);if(t.cmp(0)===0){return e}e=e.rem(t);if(e.cmp(0)===0){return t}}};LNumber.isFloat=function e(t){return t instanceof LFloat||Number(t)===t&&t%1!==0};LNumber.isNumber=function(e){return e instanceof LNumber||LNumber.isNative(e)||LNumber.isBN(e)};LNumber.isComplex=function(e){if(!e){return false}var t=e instanceof LComplex||(LNumber.isNumber(e.im)||LNumber.isRational(e.im)||Number.isNaN(e.im))&&(LNumber.isNumber(e.re)||LNumber.isRational(e.re)||Number.isNaN(e.re));return t};LNumber.isRational=function(e){if(!e){return false}return e instanceof LRational||LNumber.isNumber(e.num)&&LNumber.isNumber(e.denom)};LNumber.isInteger=function(e){if(!(LNumber.isNative(e)||e instanceof LNumber)){return false}if(LNumber.isFloat(e)){return false}if(LNumber.isRational(e)){return false}if(LNumber.isComplex(e)){return false}return true};LNumber.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};LNumber.isBigInteger=function(e){return e instanceof LBigInteger||typeof e==="bigint"||LNumber.isBN(e)};LNumber.isBN=function(e){return typeof BN!=="undefined"&&e instanceof BN};LNumber.getArgsType=function(e,t){if(e instanceof LFloat||t instanceof LFloat){return LFloat}if(e instanceof LBigInteger||t instanceof LBigInteger){return LBigInteger}return LNumber};LNumber.prototype.toString=function(e){if(Number.isNaN(this.__value__)){return"+nan.0"}if(e>=2&&e<36){return this.__value__.toString(e)}return this.__value__.toString()};LNumber.prototype.asType=function(e){var t=LNumber.getType(this);return LNumber.types[t]?LNumber.types[t](e):LNumber(e)};LNumber.prototype.isBigNumber=function(){return typeof this.__value__==="bigint"||typeof BN!=="undefined"&&!(this.value instanceof BN)};["floor","ceil","round"].forEach(function(e){LNumber.prototype[e]=function(){if(this["float"]||LNumber.isFloat(this.__value__)){return LNumber(Math[e](this.__value__))}else{return LNumber(Math[e](this.valueOf()))}}});LNumber.prototype.valueOf=function(){if(LNumber.isNative(this.__value__)){return Number(this.__value__)}else if(LNumber.isBN(this.__value__)){return this.__value__.toNumber()}};var matrix=function(){var e=function e(t,r){return[t,r]};return{bigint:{bigint:e,float:function e(t,r){return[LFloat(t.valueOf()),r]},rational:function e(t,r){return[{num:t,denom:1},r]},complex:function e(t,r){return[{im:0,re:t},r]}},integer:{integer:e,float:function e(t,r){return[LFloat(t.valueOf()),r]},rational:function e(t,r){return[{num:t,denom:1},r]},complex:function e(t,r){return[{im:0,re:t},r]}},float:{bigint:function e(t,r){return[t,r&&LFloat(r.valueOf())]},integer:function e(t,r){return[t,r&&LFloat(r.valueOf())]},float:e,rational:function e(t,r){return[t,r&&LFloat(r.valueOf())]},complex:function e(t,r){return[{re:t,im:LFloat(0)},r]}},complex:{bigint:t("bigint"),integer:t("integer"),float:t("float"),rational:t("rational"),complex:function e(t,r){var n=LNumber.coerce(t.__re__,r.__re__),i=_slicedToArray(n,2),a=i[0],o=i[1];var u=LNumber.coerce(t.__im__,r.__im__),s=_slicedToArray(u,2),c=s[0],l=s[1];return[{im:c,re:a},{im:l,re:o}]}},rational:{bigint:function e(t,r){return[t,r&&{num:r,denom:1}]},integer:function e(t,r){return[t,r&&{num:r,denom:1}]},float:function e(t,r){return[LFloat(t.valueOf()),r]},rational:e,complex:function e(t,r){return[{im:coerce(t.__type__,r.__im__.__type__,0)[0],re:coerce(t.__type__,r.__re__.__type__,t)[0]},{im:coerce(t.__type__,r.__im__.__type__,r.__im__)[0],re:coerce(t.__type__,r.__re__.__type__,r.__re__)[0]}]}}};function t(r){return function(e,t){return[{im:coerce(r,e.__im__.__type__,0,e.__im__)[1],re:coerce(r,e.__re__.__type__,0,e.__re__)[1]},{im:coerce(r,e.__im__.__type__,0,0)[1],re:coerce(r,t.__type__,0,t)[1]}]}}}();function coerce(e,t,r,n){return matrix[e][t](r,n)}LNumber.coerce=function(e,t){var r=LNumber.getType(e);var n=LNumber.getType(t);if(!matrix[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!matrix[r][n]){throw new Error("LNumber::coerce unknown rhs type ".concat(n))}var i=matrix[r][n](e,t);return i.map(function(e){return LNumber(e,true)})};LNumber.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof LNumber)){throw new Error("LNumber: you can't coerce ".concat(type(e)))}if(typeof e==="number"){e=LNumber(e)}return LNumber.coerce(this,e)};LNumber.getType=function(e){if(e instanceof LNumber){return e.__type__}if(LNumber.isFloat(e)){return"float"}if(LNumber.isComplex(e)){return"complex"}if(LNumber.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof BN!=="undefined"&&!(e instanceof BN)){return"bigint"}};LNumber.prototype.isFloat=function(){return!!(LNumber.isFloat(this.__value__)||this["float"])};var mapping={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var rev_mapping={};Object.keys(mapping).forEach(function(t){rev_mapping[mapping[t]]=t;LNumber.prototype[t]=function(e){return this.op(mapping[t],e)}});LNumber._ops={"*":function e(t,r){return t*r},"+":function e(t,r){return t+r},"-":function e(t,r){if(typeof r==="undefined"){return-t}return t-r},"/":function e(t,r){return t/r},"%":function e(t,r){return t%r},"|":function e(t,r){return t|r},"&":function e(t,r){return t&r},"~":function e(t){return~t},">>":function e(t,r){return t>>r},"<<":function e(t,r){return t<1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof LComplex)||typeof this==="undefined"){return new LComplex(e,t)}if(e instanceof LComplex){return LComplex({im:e.__im__,re:e.__re__})}if(LNumber.isNumber(e)&&t){if(!t){return Number(e)}}else if(!LNumber.isComplex(e)){var r="Invalid constructor call for LComplex expect &(:im :re ) object but got ".concat(toString(e));throw new Error(r)}var n=e.im instanceof LNumber?e.im:LNumber(e.im);var i=e.re instanceof LNumber?e.re:LNumber(e.re);this.constant(n,i)}LComplex.prototype=Object.create(LNumber.prototype);LComplex.prototype.constructor=LComplex;LComplex.prototype.constant=function(e,t){Object.defineProperty(this,"__im__",{value:e,enumerable:true});Object.defineProperty(this,"__re__",{value:t,enumerable:true});Object.defineProperty(this,"__type__",{value:"complex",enumerable:true})};LComplex.prototype.serialize=function(){return{re:this.__re__,im:this.__im__}};LComplex.prototype.toRational=function(e){if(LNumber.isFloat(this.__im__)&&LNumber.isFloat(this.__re__)){var t=LFloat(this.__im__).toRational(e);var r=LFloat(this.__re__).toRational(e);return LComplex({im:t,re:r})}return this};LComplex.prototype.pow=function(e){e.cmp(0);if(e===0){return LNumber(1)}var t=LNumber(Math.atan2(this.__im__.valueOf(),this.__re__.valueOf()));var r=LNumber(this.modulus());if(LNumber.isComplex(e)&&e.__im__.cmp(0)!==0){var n=e.mul(Math.log(r.valueOf())).add(LComplex.i.mul(t).mul(e));var i=LFloat(Math.E).pow(n.__re__.valueOf());return LComplex({re:i.mul(Math.cos(n.__im__.valueOf())),im:i.mul(Math.sin(n.__im__.valueOf()))})}var a=e.__re__.cmp(0)>0;e=e.__re__.valueOf();if(LNumber.isInteger(e)&&a){var o=this;while(--e){o=o.mul(this)}return o}var u=r.pow(e);var s=t.mul(e);return LComplex({re:u.mul(Math.cos(s)),im:u.mul(Math.sin(s))})};LComplex.prototype.add=function(e){return this.complex_op("add",e,function(e,t,r,n){return{re:e.add(t),im:r.add(n)}})};LComplex.prototype.factor=function(){if(this.__im__ instanceof LFloat||this.__im__ instanceof LFloat){var e=this.__re__,t=this.__im__;var r,n;if(e instanceof LFloat){r=e.toRational().mul(e.toRational())}else{r=e.mul(e)}if(t instanceof LFloat){n=t.toRational().mul(t.toRational())}else{n=t.mul(t)}return r.add(n)}else{return this.__re__.mul(this.__re__).add(this.__im__.mul(this.__im__))}};LComplex.prototype.modulus=function(){return this.factor().sqrt()};LComplex.prototype.conjugate=function(){return LComplex({re:this.__re__,im:this.__im__.sub()})};LComplex.prototype.sqrt=function(){var e=this.modulus();var t,r;if(e.cmp(0)===0){t=r=e}else if(this.__re__.cmp(0)===1){t=LFloat(.5).mul(e.add(this.__re__)).sqrt();r=this.__im__.div(t).div(2)}else{r=LFloat(.5).mul(e.sub(this.__re__)).sqrt();if(this.__im__.cmp(0)===-1){r=r.sub()}t=this.__im__.div(r).div(2)}return LComplex({im:r,re:t})};LComplex.prototype.div=function(e){if(LNumber.isNumber(e)&&!LNumber.isComplex(e)){if(!(e instanceof LNumber)){e=LNumber(e)}var t=this.__re__.div(e);var r=this.__im__.div(e);return LComplex({re:t,im:r})}else if(!LNumber.isComplex(e)){throw new Error("[LComplex::div] Invalid value")}if(this.cmp(e)===0){var n=this.coerce(e),i=_slicedToArray(n,2),a=i[0],o=i[1];var u=a.__im__.div(o.__im__);return u.coerce(o.__re__)[0]}var s=this.coerce(e),c=_slicedToArray(s,2),l=c[0],f=c[1];var _=f.factor();var p=f.conjugate();var d=l.mul(p);if(!LNumber.isComplex(d)){return d.div(_)}var h=d.__re__.op("/",_);var m=d.__im__.op("/",_);return LComplex({re:h,im:m})};LComplex.prototype.sub=function(e){return this.complex_op("sub",e,function(e,t,r,n){return{re:e.sub(t),im:r.sub(n)}})};LComplex.prototype.mul=function(e){return this.complex_op("mul",e,function(e,t,r,n){var i={re:e.mul(t).sub(r.mul(n)),im:e.mul(n).add(t.mul(r))};return i})};LComplex.prototype.complex_op=function(e,t,i){var a=this;var r=function e(t,r){var n=i(a.__re__,t,a.__im__,r);if("im"in n&&"re"in n){if(n.im.cmp(0)===0){return n.re}return LComplex(n,true)}return n};if(typeof t==="undefined"){return r()}if(LNumber.isNumber(t)&&!LNumber.isComplex(t)){if(!(t instanceof LNumber)){t=LNumber(t)}var n=t.asType(0);t={__im__:n,__re__:t}}else if(!LNumber.isComplex(t)){throw new Error("[LComplex::".concat(e,"] Invalid value"))}var o=t.__re__ instanceof LNumber?t.__re__:this.__re__.asType(t.__re__);var u=t.__im__ instanceof LNumber?t.__im__:this.__im__.asType(t.__im__);return r(o,u)};LComplex._op={"+":"add","-":"sub","*":"mul","/":"div"};LComplex.prototype._op=function(e,t){var r=LComplex._op[e];return this[r](t)};LComplex.prototype.cmp=function(e){var t=this.coerce(e),r=_slicedToArray(t,2),n=r[0],i=r[1];var a=n.__re__.coerce(i.__re__),o=_slicedToArray(a,2),u=o[0],s=o[1];var c=u.cmp(s);if(c!==0){return c}else{var l=n.__im__.coerce(i.__im__),f=_slicedToArray(l,2),_=f[0],p=f[1];return _.cmp(p)}};LComplex.prototype.valueOf=function(){return[this.__re__,this.__im__].map(function(e){return e.valueOf()})};LComplex.prototype.toString=function(){var e;if(this.__re__.cmp(0)!==0){e=[toString(this.__re__)]}else{e=[]}var t=this.__im__.valueOf();var r=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY].includes(t);var n=toString(this.__im__);if(!r&&!Number.isNaN(t)){var i=this.__im__.cmp(0);if(i<0||i===0&&this.__im__._minus){e.push("-")}else{e.push("+")}n=n.replace(/^-/,"")}e.push(n);e.push("i");return e.join("")};function LFloat(e){if(typeof this!=="undefined"&&!(this instanceof LFloat)||typeof this==="undefined"){return new LFloat(e)}if(!LNumber.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof LNumber){return LFloat(e.valueOf())}if(typeof e==="number"){if(Object.is(e,-0)){Object.defineProperty(this,"_minus",{value:true})}this.constant(e,"float")}}LFloat.prototype=Object.create(LNumber.prototype);LFloat.prototype.constructor=LFloat;LFloat.prototype.toString=function(e){if(this.__value__===Number.NEGATIVE_INFINITY){return"-inf.0"}if(this.__value__===Number.POSITIVE_INFINITY){return"+inf.0"}if(Number.isNaN(this.__value__)){return"+nan.0"}e&&(e=e.valueOf());var t=this.__value__.toString(e);if(!t.match(/e[+-]?[0-9]+$/i)){var r=t.replace(/^-/,"");var n=this.__value__<0?"-":"";if(t.match(/^-?0\.0{3}/)){var i=r.match(/^[.0]+/g)[0].length-1;var a=r.replace(/^[.0]+/,"").replace(/^([0-9a-f])/i,"$1.");return"".concat(n).concat(a,"e-").concat(i.toString(e))}if(t.match(/^-?[0-9a-f]{7,}\.?/i)){var o=r.match(/^[0-9a-f]+/gi)[0].length-1;var u=r.replace(/\./,"").replace(/^([0-9a-f])/i,"$1.").replace(/0+$/,"").replace(/\.$/,".0");return"".concat(n).concat(u,"e+").concat(o.toString(e))}if(!LNumber.isFloat(this.__value__)){var s=t+".0";return this._minus?"-"+s:s}}return t.replace(/^([0-9]+)e/,"$1.0e")};LFloat.prototype._op=function(e,t){if(t instanceof LNumber){t=t.__value__}var r=LNumber._ops[e];if(e==="/"&&this.__value__===0&&t===0){return NaN}return LFloat(r(this.__value__,t))};LFloat.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){return toRational(this.__value__.valueOf())}return approxRatio(e.valueOf())(this.__value__.valueOf())};LFloat.prototype.sqrt=function(){var e=this.valueOf();if(this.cmp(0)<0){var t=LFloat(Math.sqrt(-e));return LComplex({re:0,im:t})}return LFloat(Math.sqrt(e))};LFloat.prototype.abs=function(){var e=this.valueOf();if(e<0){e=-e}return LFloat(e)};var toRational=approxRatio(1e-10);function approxRatio(n){return function(e){var t=function e(n,t,r){var i=function e(t,r){return r0){i=simplest_rational2(n,r)}else if(n.cmp(r)<=0){i=r}else if(r.cmp(0)>0){i=simplest_rational2(r,n)}else if(t.cmp(0)<0){i=LNumber(simplest_rational2(n.sub(),r.sub())).sub()}else{i=LNumber(0)}if(LNumber.isFloat(t)||LNumber.isFloat(e)){return LFloat(i)}return i}function simplest_rational2(e,t){var r=LNumber(e).floor();var n=LNumber(t).floor();if(e.cmp(r)<1){return r}else if(r.cmp(n)===0){var i=LNumber(1).div(t.sub(n));var a=LNumber(1).div(e.sub(r));return r.add(LNumber(1).div(simplest_rational2(i,a)))}else{return r.add(LNumber(1))}}function LRational(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof LRational)||typeof this==="undefined"){return new LRational(e,t)}if(!LNumber.isRational(e)){throw new Error("Invalid constructor call for LRational")}var r,n;if(e instanceof LRational){r=LNumber(e.__num__);n=LNumber(e.__denom__)}else{r=LNumber(e.num);n=LNumber(e.denom)}if(!t&&n.cmp(0)!==0){var i=r.op("%",n).cmp(0)===0;if(i){return LNumber(r.div(n))}}this.constant(r,n)}LRational.prototype=Object.create(LNumber.prototype);LRational.prototype.constructor=LRational;LRational.prototype.constant=function(e,t){Object.defineProperty(this,"__num__",{value:e,enumerable:true});Object.defineProperty(this,"__denom__",{value:t,enumerable:true});Object.defineProperty(this,"__type__",{value:"rational",enumerable:true})};LRational.prototype.serialize=function(){return{num:this.__num__,denom:this.__denom__}};LRational.prototype.pow=function(e){if(LNumber.isRational(e)){return pow(this.valueOf(),e.valueOf())}var t=e.cmp(0);if(t===0){return LNumber(1)}if(t===-1){e=e.sub();var r=this.__denom__.pow(e);var n=this.__num__.pow(e);return LRational({num:r,denom:n})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};LRational.prototype.sqrt=function(){var e=this.__num__.sqrt();var t=this.__denom__.sqrt();if(e instanceof LFloat||t instanceof LFloat){return e.div(t)}return LRational({num:e,denom:t})};LRational.prototype.abs=function(){var e=this.__num__;var t=this.__denom__;if(e.cmp(0)===-1){e=e.sub()}if(t.cmp(0)!==1){t=t.sub()}return LRational({num:e,denom:t})};LRational.prototype.cmp=function(e){return LNumber(this.valueOf(),true).cmp(e)};LRational.prototype.toString=function(){var e=this.__num__.gcd(this.__denom__);var t,r;if(e.cmp(1)!==0){t=this.__num__.div(e);if(t instanceof LRational){t=LNumber(t.valueOf(true))}r=this.__denom__.div(e);if(r instanceof LRational){r=LNumber(r.valueOf(true))}}else{t=this.__num__;r=this.__denom__}var n=this.cmp(0)<0;if(n){if(t.abs().cmp(r.abs())===0){return t.toString()}}else if(t.cmp(r)===0){return t.toString()}return t.toString()+"/"+r.toString()};LRational.prototype.valueOf=function(e){if(this.__denom__.cmp(0)===0){if(this.__num__.cmp(0)<0){return Number.NEGATIVE_INFINITY}return Number.POSITIVE_INFINITY}if(e){return LNumber._ops["/"](this.__num__.value,this.__denom__.value)}return LFloat(this.__num__.valueOf()).div(this.__denom__.valueOf())};LRational.prototype.mul=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var t=this.__num__.mul(e.__num__);var r=this.__denom__.mul(e.__denom__);return LRational({num:t,denom:r})}var n=LNumber.coerce(this,e),i=_slicedToArray(n,2),a=i[0],o=i[1];return a.mul(o)};LRational.prototype.div=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var t=this.__num__.mul(e.__denom__);var r=this.__denom__.mul(e.__num__);return LRational({num:t,denom:r})}var n=LNumber.coerce(this,e),i=_slicedToArray(n,2),a=i[0],o=i[1];var u=a.div(o);return u};LRational.prototype._op=function(e,t){return this[rev_mapping[e]](t)};LRational.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var t=e.__num__.sub();var r=e.__denom__;return this.add(LRational({num:t,denom:r}))}if(!(e instanceof LNumber)){e=LNumber(e).sub()}else{e=e.sub()}var n=LNumber.coerce(this,e),i=_slicedToArray(n,2),a=i[0],o=i[1];return a.add(o)};LRational.prototype.add=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var t=this.__denom__;var r=e.__denom__;var n=this.__num__;var i=e.__num__;var a,o;if(t!==r){o=r.mul(n).add(i.mul(t));a=t.mul(r)}else{o=n.add(i);a=t}return LRational({num:o,denom:a})}if(LNumber.isFloat(e)){return LFloat(this.valueOf()).add(e)}var u=LNumber.coerce(this,e),s=_slicedToArray(u,2),c=s[0],l=s[1];return c.add(l)};function LBigInteger(e,t){if(typeof this!=="undefined"&&!(this instanceof LBigInteger)||typeof this==="undefined"){return new LBigInteger(e,t)}if(e instanceof LBigInteger){return LBigInteger(e.__value__,e._native)}if(!LNumber.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.constant(e,"bigint");Object.defineProperty(this,"_native",{value:t})}LBigInteger.prototype=Object.create(LNumber.prototype);LBigInteger.prototype.constructor=LBigInteger;LBigInteger.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};LBigInteger.prototype.serialize=function(){return this.__value__.toString()};LBigInteger.prototype._op=function(e,t){if(typeof t==="undefined"){if(LNumber.isBN(this.__value__)){e=LBigInteger.bn_op[e];return LBigInteger(this.__value__.clone()[e](),false)}return LBigInteger(LNumber._ops[e](this.__value__),true)}if(LNumber.isBN(this.__value__)&&LNumber.isBN(t.__value__)){e=LBigInteger.bn_op[e];return LBigInteger(this.__value__.clone()[e](t),false)}var r=LNumber._ops[e](this.__value__,t.__value__);if(e==="/"){var n=this.op("%",t).cmp(0)===0;if(n){return LNumber(r)}return LRational({num:this,denom:t})}return LBigInteger(r,true)};LBigInteger.prototype.sqrt=function(){var e;var t=this.cmp(0)<0;if(LNumber.isNative(this.__value__)){e=LNumber(Math.sqrt(t?-this.valueOf():this.valueOf()))}else if(LNumber.isBN(this.__value__)){e=t?this.__value__.neg().sqrt():this.__value__.sqrt()}if(t){return LComplex({re:0,im:e})}return e};LNumber.NaN=LNumber(NaN);LComplex.i=LComplex({im:1,re:0});function InputPort(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof InputPort)||typeof this==="undefined"){return new InputPort(e)}typecheck("InputPort",e,"function");read_only(this,"__type__",text_port);var i;Object.defineProperty(this,"__parser__",{enumerable:true,get:function e(){return i},set:function e(t){typecheck("InputPort::__parser__",t,"parser");i=t}});this._read=e;this._with_parser=this._with_init_parser.bind(this,_asyncToGenerator(_regeneratorRuntime.mark(function e(){var r;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(n.char_ready()){t.next=5;break}t.next=3;return n._read();case 3:r=t.sent;i=new Parser(r,{env:n});case 5:return t.abrupt("return",n.__parser__);case 6:case"end":return t.stop()}},e)})));this.char_ready=function(){return!!this.__parser__&&this.__parser__.__lexer__.peek()!==eof};this._make_defaults()}InputPort.prototype._make_defaults=function(){this.read=this._with_parser(function(e){return e.read_object()});this.read_line=this._with_parser(function(e){return e.__lexer__.read_line()});this.read_char=this._with_parser(function(e){return e.__lexer__.read_char()});this.read_string=this._with_parser(function(e,t){if(!LNumber.isInteger(t)){var r=LNumber.getType(t);typeErrorMessage("read-string",r,"integer")}return e.__lexer__.read_string(t.valueOf())});this.peek_char=this._with_parser(function(e){return e.__lexer__.peek_char()})};InputPort.prototype._with_init_parser=function(u,s){var c=this;return _asyncToGenerator(_regeneratorRuntime.mark(function e(){var r,n,i,a,o=arguments;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return u.call(c);case 2:r=t.sent;for(n=o.length,i=new Array(n),a=0;a"};function OutputPort(e){if(typeof this!=="undefined"&&!(this instanceof OutputPort)||typeof this==="undefined"){return new OutputPort(e)}typecheck("OutputPort",e,"function");read_only(this,"__type__",text_port);this.write=e}OutputPort.prototype.is_open=function(){return this._closed!==true};OutputPort.prototype.close=function(){Object.defineProperty(this,"_closed",{get:function e(){return true},set:function e(){},configurable:false,enumerable:false});this.write=function(){throw new Error("output-port: port is closed")}};OutputPort.prototype.flush=function(){};OutputPort.prototype.toString=function(){return"#"};var BufferedOutputPort=function(e){_inherits(r,e);function r(e){var t;_classCallCheck(this,r);t=_callSuper(this,r,[function(){var e;return(e=t)._write.apply(e,arguments)}]);typecheck("BufferedOutputPort",e,"function");read_only(_assertThisInitialized(t),"_fn",e,{hidden:true});read_only(_assertThisInitialized(t),"_buffer",[],{hidden:true});return t}_createClass(r,[{key:"flush",value:function e(){if(this._buffer.length){this._fn(this._buffer.join(""));this._buffer.length=0}}},{key:"_write",value:function e(){var t=this;for(var r=arguments.length,n=new Array(r),i=0;i"};OutputStringPort.prototype.valueOf=function(){return this.__buffer__.map(function(e){return e.valueOf()}).join("")};function OutputFilePort(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof OutputFilePort)||typeof this==="undefined"){return new OutputFilePort(e,t)}typecheck("OutputFilePort",e,"string");read_only(this,"__filename__",e);read_only(this,"_fd",t.valueOf(),{hidden:true});read_only(this,"__type__",text_port);this.write=function(e){if(!LString.isString(e)){e=toString(e)}else{e=e.valueOf()}r.fs().write(r._fd,e,function(e){if(e){throw e}})}}OutputFilePort.prototype=Object.create(OutputPort.prototype);OutputFilePort.prototype.constructor=OutputFilePort;OutputFilePort.prototype.fs=function(){if(!this._fs){this._fs=this.internal("fs")}return this._fs};OutputFilePort.prototype.internal=function(e){return user_env.get("**internal-env**").get(e)};OutputFilePort.prototype.close=function(){var n=this;return new Promise(function(t,r){n.fs().close(n._fd,function(e){if(e){r(e)}else{read_only(n,"_fd",null,{hidden:true});OutputPort.prototype.close.call(n);t()}})})};OutputFilePort.prototype.toString=function(){return"#")};function InputStringPort(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof InputStringPort)||typeof this==="undefined"){return new InputStringPort(e)}typecheck("InputStringPort",e,"string");t=t||global_env;e=e.valueOf();this._with_parser=this._with_init_parser.bind(this,function(){if(!r.__parser__){r.__parser__=new Parser(e,{env:t})}return r.__parser__});read_only(this,"__type__",text_port);this._make_defaults()}InputStringPort.prototype.char_ready=function(){return true};InputStringPort.prototype=Object.create(InputPort.prototype);InputStringPort.prototype.constructor=InputStringPort;InputStringPort.prototype.toString=function(){return"#"};function InputByteVectorPort(e){if(typeof this!=="undefined"&&!(this instanceof InputByteVectorPort)||typeof this==="undefined"){return new InputByteVectorPort(e)}typecheck("InputByteVectorPort",e,"uint8array");read_only(this,"__vector__",e);read_only(this,"__type__",binary_port);var r=0;Object.defineProperty(this,"__index__",{enumerable:true,get:function e(){return r},set:function e(t){typecheck("InputByteVectorPort::__index__",t,"number");if(t instanceof LNumber){t=t.valueOf()}if(typeof t==="bigint"){t=Number(t)}if(Math.floor(t)!==t){throw new Error("InputByteVectorPort::__index__ value is "+"not integer")}r=t}})}InputByteVectorPort.prototype=Object.create(InputPort.prototype);InputByteVectorPort.prototype.constructor=InputByteVectorPort;InputByteVectorPort.prototype.toString=function(){return"#"};InputByteVectorPort.prototype.close=function(){var t=this;read_only(this,"__vector__",_nil);var r=function e(){throw new Error("Input-binary-port: port is closed")};["read_u8","close","peek_u8","read_u8_vector"].forEach(function(e){t[e]=r});this.u8_ready=this.char_ready=function(){return false}};InputByteVectorPort.prototype.u8_ready=function(){return true};InputByteVectorPort.prototype.peek_u8=function(){if(this.__index__>=this.__vector__.length){return eof}return this.__vector__[this.__index__]};InputByteVectorPort.prototype.skip=function(){if(this.__index__<=this.__vector__.length){++this.__index__}};InputByteVectorPort.prototype.read_u8=function(){var e=this.peek_u8();this.skip();return e};InputByteVectorPort.prototype.read_u8_vector=function(e){if(typeof e==="undefined"){e=this.__vector__.length}else if(e>this.__index__+this.__vector__.length){e=this.__index__+this.__vector__.length}if(this.peek_u8()===eof){return eof}return this.__vector__.slice(this.__index__,e)};function OutputByteVectorPort(){if(typeof this!=="undefined"&&!(this instanceof OutputByteVectorPort)||typeof this==="undefined"){return new OutputByteVectorPort}read_only(this,"__type__",binary_port);read_only(this,"_buffer",[],{hidden:true});this.write=function(e){typecheck("write",e,["number","uint8array"]);if(LNumber.isNumber(e)){this._buffer.push(e.valueOf())}else{var t;(t=this._buffer).push.apply(t,_toConsumableArray(Array.from(e)))}};Object.defineProperty(this,"__buffer__",{enumerable:true,get:function e(){return Uint8Array.from(this._buffer)}})}OutputByteVectorPort.prototype=Object.create(OutputPort.prototype);OutputByteVectorPort.prototype.constructor=OutputByteVectorPort;OutputByteVectorPort.prototype.close=function(){OutputPort.prototype.close.call(this);read_only(this,"_buffer",null,{hidden:true})};OutputByteVectorPort.prototype._close_guard=function(){if(this._closed){throw new Error("output-port: binary port is closed")}};OutputByteVectorPort.prototype.write_u8=function(e){typecheck("OutputByteVectorPort::write_u8",e,"number");this.write(e)};OutputByteVectorPort.prototype.write_u8_vector=function(e){typecheck("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};OutputByteVectorPort.prototype.toString=function(){return"#"};OutputByteVectorPort.prototype.valueOf=function(){return this.__buffer__};function InputFilePort(e,t){if(typeof this!=="undefined"&&!(this instanceof InputFilePort)||typeof this==="undefined"){return new InputFilePort(e,t)}InputStringPort.call(this,e);typecheck("InputFilePort",t,"string");read_only(this,"__filename__",t)}InputFilePort.prototype=Object.create(InputStringPort.prototype);InputFilePort.prototype.constructor=InputFilePort;InputFilePort.prototype.toString=function(){return"#")};function InputBinaryFilePort(e,t){if(typeof this!=="undefined"&&!(this instanceof InputBinaryFilePort)||typeof this==="undefined"){return new InputBinaryFilePort(e,t)}InputByteVectorPort.call(this,e);typecheck("InputBinaryFilePort",t,"string");read_only(this,"__filename__",t)}InputBinaryFilePort.prototype=Object.create(InputByteVectorPort.prototype);InputBinaryFilePort.prototype.constructor=InputBinaryFilePort;InputBinaryFilePort.prototype.toString=function(){return"#")};function OutputBinaryFilePort(e,t){var i=this;if(typeof this!=="undefined"&&!(this instanceof OutputBinaryFilePort)||typeof this==="undefined"){return new OutputBinaryFilePort(e,t)}typecheck("OutputBinaryFilePort",e,"string");read_only(this,"__filename__",e);read_only(this,"_fd",t.valueOf(),{hidden:true});read_only(this,"__type__",binary_port);var a;this.write=function(e){typecheck("write",e,["number","uint8array"]);var n;if(!a){a=i.internal("fs")}if(LNumber.isNumber(e)){n=new Uint8Array([e.valueOf()])}else{n=new Uint8Array(Array.from(e))}return new Promise(function(t,r){a.write(i._fd,n,function(e){if(e){r(e)}else{t()}})})}}OutputBinaryFilePort.prototype=Object.create(OutputFilePort.prototype);OutputBinaryFilePort.prototype.constructor=OutputBinaryFilePort;OutputBinaryFilePort.prototype.write_u8=function(e){typecheck("OutputByteVectorPort::write_u8",e,"number");this.write(e)};OutputBinaryFilePort.prototype.write_u8_vector=function(e){typecheck("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};var binary_port=Symbol["for"]("binary");var text_port=Symbol["for"]("text");var eof=new EOF;function EOF(){}EOF.prototype.toString=function(){return"#"};function Interpreter(e){var t=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=r.stderr,i=r.stdin,a=r.stdout,o=r.command_line,u=o===void 0?null:o,s=_objectWithoutProperties(r,_excluded3);if(typeof this!=="undefined"&&!(this instanceof Interpreter)||typeof this==="undefined"){return new Interpreter(e,_objectSpread({stdin:i,stdout:a,stderr:n,command_line:u},s))}if(typeof e==="undefined"){e="anonymous"}this.__env__=user_env.inherit(e,s);this.__env__.set("parent.frame",doc("parent.frame",function(){return t.__env__},global_env.__env__["parent.frame"].__doc__));var c="**interaction-environment-defaults**";this.set(c,get_props(s).concat(c));var l=internal_env.inherit("internal-".concat(e));if(is_port(i)){l.set("stdin",i)}if(is_port(n)){l.set("stderr",n)}if(is_port(a)){l.set("stdout",a)}l.set("command-line",u);set_interaction_env(this.__env__,l)}Interpreter.prototype.exec=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=t.use_dynamic,n=r===void 0?false:r,i=t.dynamic_env,a=t.env;typecheck("Interpreter::exec",e,["string","array"],1);typecheck("Interpreter::exec",n,"boolean",2);if(!a){a=this.__env__}if(!i){i=a}global_env.set("**interaction-environment**",this.__env__);return exec(e,{env:a,dynamic_env:i,use_dynamic:n})};Interpreter.prototype.get=function(e){var t=this.__env__.get(e);if(is_function(t)){var r=new LambdaContext({env:this.__env__});return t.bind(r)}return t};Interpreter.prototype.set=function(e,t){return this.__env__.set(e,t)};Interpreter.prototype.constant=function(e,t){return this.__env__.constant(e,t)};function LipsError(e,t){this.name="LipsError";this.message=e;this.args=t;this.stack=(new Error).stack}LipsError.prototype=new Error;LipsError.prototype.constructor=LipsError;var IgnoreException=function(e){_inherits(t,e);function t(){_classCallCheck(this,t);return _callSuper(this,t,arguments)}return _createClass(t)}(_wrapNativeSuper(Error));function Environment(e,t,r){if(arguments.length===1){if(_typeof$1(arguments[0])==="object"){e=arguments[0];t=null}else if(typeof arguments[0]==="string"){e={};t=null;r=arguments[0]}}this.__docs__=new Map;this.__env__=e;this.__parent__=t;this.__name__=r||"anonymous"}Environment.prototype.list=function(){return get_props(this.__env__)};Environment.prototype.fs=function(){return this.get("**fs**")};Environment.prototype.unset=function(e){if(e instanceof LSymbol){e=e.valueOf()}if(e instanceof LString){e=e.valueOf()}delete this.__env__[e]};Environment.prototype.inherit=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(_typeof$1(e)==="object"){t=e}if(!e||_typeof$1(e)==="object"){e="child of "+(this.__name__||"unknown")}return new Environment(t||{},this,e)};Environment.prototype.doc=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}if(t){if(!r){t=trim_lines(t)}this.__docs__.set(e,t);return this}if(this.__docs__.has(e)){return this.__docs__.get(e)}if(this.__parent__){return this.__parent__.doc(e)}};Environment.prototype.new_frame=function(e,t){var n=this.inherit("__frame__");n.set("parent.frame",doc("parent.frame",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;e=e.valueOf();var t=n.__parent__;if(!is_env(t)){return _nil}if(e<=0){return t}var r=t.get("parent.frame");return r(e-1)},global_env.__env__["parent.frame"].__doc__));t.callee=e;n.set("arguments",t);return n};Environment.prototype._lookup=function(e){if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}if(this.__env__.hasOwnProperty(e)){return Value(this.__env__[e])}if(this.__parent__){return this.__parent__._lookup(e)}};Environment.prototype.toString=function(){return"#"};Environment.prototype.clone=function(){var t=this;var r={};Object.keys(this.__env__).forEach(function(e){r[e]=t.__env__[e]});return new Environment(r,this.__parent__,this.__name__)};Environment.prototype.merge=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"merge";typecheck("Environment::merge",e,"environment");return this.inherit(t,e.__env__)};function Value(e){if(typeof this!=="undefined"&&!(this instanceof Value)||typeof this==="undefined"){return new Value(e)}this.value=e}Value.isUndefined=function(e){return e instanceof Value&&typeof e.value==="undefined"};Value.prototype.valueOf=function(){return this.value};function Values(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof Values)||typeof this==="undefined"){return new Values(e)}this.__values__=e}Values.prototype.toString=function(){return this.__values__.map(function(e){return toString(e)}).join("\n")};Values.prototype.valueOf=function(){return this.__values__};Environment.prototype.get=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};typecheck("Environment::get",e,["symbol","string"]);var r=t.throwError,n=r===void 0?true:r;var i=e;if(i instanceof LSymbol||i instanceof LString){i=i.valueOf()}var a=this._lookup(i);if(a instanceof Value){if(Value.isUndefined(a)){return undefined}return patch_value(a.valueOf())}var o;if(e instanceof LSymbol&&e[LSymbol.object]){o=e[LSymbol.object]}else if(typeof i==="string"){o=i.split(".").filter(Boolean)}if(o&&o.length>0){var u=o,s=_toArray(u),c=s[0],l=s.slice(1);a=this._lookup(c);if(l.length){try{if(a instanceof Value){a=a.valueOf()}else{a=get(root,c);if(is_function(a)){a=unbind(a)}}if(typeof a!=="undefined"){return get.apply(void 0,[a].concat(_toConsumableArray(l)))}}catch(e){throw e}}else if(a instanceof Value){return patch_value(a.valueOf())}a=get(root,i)}if(typeof a!=="undefined"){return a}if(n){throw new Error("Unbound variable `"+i.toString()+"'")}};Environment.prototype.set=function(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;typecheck("Environment::set",e,["string","symbol"]);if(LNumber.isNumber(t)){t=LNumber(t)}if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}this.__env__[e]=t;if(r){this.doc(e,r,true)}return this};Environment.prototype.constant=function(t,e){var r=this;if(this.__env__.hasOwnProperty(t)){throw new Error("Environment::constant: ".concat(t," already exists"))}if(arguments.length===1&&is_plain_object(arguments[0])){var n=arguments[0];Object.keys(n).forEach(function(e){r.constant(t,n[e])})}else{Object.defineProperty(this.__env__,t,{value:e,enumerable:true})}return this};Environment.prototype.has=function(e){return this.__env__.hasOwnProperty(e)};Environment.prototype.ref=function(e){var t=this;while(true){if(!t){break}if(t.has(e)){return t}t=t.__parent__}};Environment.prototype.parents=function(){var e=this;var t=[];while(e){t.unshift(e);e=e.__parent__}return t};function quote(e){if(is_promise(e)){return e.then(quote)}if(is_pair(e)||e instanceof LSymbol){e[__data__]=true}return e}var native_lambda=_parse(tokenize('(lambda ()\n "[native code]"\n (throw "Invalid Invocation"))'))[0];var get=doc("get",function e(t){var r;for(var n=arguments.length,i=new Array(n>1?n-1:0),a=1;a0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=internal(this,"stdin")}typecheck_text_port("peek-char",e,"input-port");return e.peek_char()},"(peek-char port)\n\n This function reads and returns a character from the string\n port, or, if there is no more data in the string port, it\n returns an EOF."),"read-line":doc("read-line",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=internal(this,"stdin")}typecheck_text_port("read-line",e,"input-port");return e.read_line()},"(read-line port)\n\n This function reads and returns the next line from the input\n port."),"read-char":doc("read-char",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=internal(this,"stdin")}typecheck_text_port("read-char",e,"input-port");return e.read_char()},"(read-char port)\n\n This function reads and returns the next character from the\n input port."),read:doc("read",function(){var e=_asyncToGenerator(function(){var i=this;var a=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;return _regeneratorRuntime.mark(function e(){var r,n;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=i.env;if(a===null){n=internal(r,"stdin")}else{n=a}typecheck_text_port("read",n,"input-port");return t.abrupt("return",n.read.call(r));case 4:case"end":return t.stop()}},e)})()});function t(){return e.apply(this,arguments)}return t}(),"(read [port])\n\n This function, if called with a port, it will parse the next\n item from the port. If called without an input, it will read\n a string from standard input (using the browser's prompt or\n a user defined input method) and parse it. This function can be\n used together with `eval` to evaluate code from port."),pprint:doc("pprint",function e(t){if(is_pair(t)){t=new lips.Formatter(t.toString(true))["break"]().format();global_env.get("display").call(global_env,t)}else{global_env.get("write").call(global_env,t)}global_env.get("newline").call(global_env)},"(pprint expression)\n\n This function will pretty print its input to stdout. If it is called\n with a non-list, it will just call the print function on its\n input."),print:doc("print",function e(){var t=global_env.get("display");var r=global_env.get("newline");var n=this.use_dynamic;var i=global_env;var a=global_env;for(var o=arguments.length,u=new Array(o),s=0;s1?r-1:0),i=1;in.length){throw new Error("Not enough arguments")}var u=0;var s=global_env.get("repr");t=t.replace(a,function(e){var t=e[1];if(t==="~"){return"~"}else if(t==="%"){return"\n"}else{var r=n[u++];if(t==="a"){return s(r)}else{return s(r,true)}}});o=t.match(/~([\S])/);if(o){throw new Error("format: Unrecognized escape sequence ".concat(o[1]))}return t},"(format string n1 n2 ...)\n\n This function accepts a string template and replaces any\n escape sequences in its inputs:\n\n * ~a value as if printed with `display`\n * ~s value as if printed with `write`\n * ~% newline character\n * ~~ literal tilde '~'\n\n If there are missing inputs or other escape characters it\n will error."),display:doc("display",function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(r===null){r=internal(this,"stdout")}else{typecheck("display",r,"output-port")}var n=t;if(!(r instanceof OutputBinaryFilePort)){n=global_env.get("repr")(t)}r.write.call(global_env,n)},"(display string [port])\n\n This function outputs the string to the standard output or\n the port if given. No newline."),"display-error":doc("display-error",function e(){var t=internal(this,"stderr");var r=global_env.get("repr");for(var n=arguments.length,i=new Array(n),a=0;a1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=_objectWithoutProperties(t,_excluded4);var i=this;var o=this;var u;var s=_objectSpread(_objectSpread({},n),{},{env:this,dynamic_env:i,use_dynamic:r});var c=_evaluate(e.cdr.car,s);c=resolve_promises(c);function l(t,r,n){if(is_promise(t)){return t.then(function(e){return l(t,e,n)})}if(is_promise(r)){return r.then(function(e){return l(t,e,n)})}if(is_promise(n)){return n.then(function(e){return l(t,r,e)})}o.get("set-obj!").call(o,t,r,n);return n}if(is_pair(e.car)&&LSymbol.is(e.car.car,".")){var f=e.car.cdr.car;var _=e.car.cdr.cdr.car;var p=_evaluate(f,s);var d=_evaluate(_,s);return l(p,d,c)}if(!(e.car instanceof LSymbol)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var h=e.car.valueOf();u=this.ref(e.car.__name__);return unpromise(c,function(e){if(!u){var t=h.split(".");if(t.length>1){var r=t.pop();var n=t.join(".");var i=a.get(n,{throwError:false});if(i){l(i,r,e);return}}throw new Error("Unbound variable `"+h+"'")}u.set(h,e)})}),"(set! name value)\n\n Macro that can be used to set the value of the variable or slot (mutate it).\n set! searches the scope chain until it finds first non empty slot and sets it."),"unset!":doc(new Macro("set!",function(e){if(!(e.car instanceof LSymbol)){throw new Error("unset! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var t=e.car;var r=this.ref(t);if(r){delete r.__env__[t.__name__]}}),"(unset! name)\n\n Function to delete the specified name from environment.\n Trying to access the name afterwards will error."),"set-car!":doc("set-car!",function(e,t){typecheck("set-car!",e,"pair");e.car=t},"(set-car! obj value)\n\n Function that sets the car (first item) of the list/pair to specified value.\n The old value is lost."),"set-cdr!":doc("set-cdr!",function(e,t){typecheck("set-cdr!",e,"pair");e.cdr=t},"(set-cdr! obj value)\n\n Function that sets the cdr (tail) of the list/pair to specified value.\n It will destroy the list. The old tail is lost."),"empty?":doc("empty?",function(e){return typeof e==="undefined"||is_nil(e)},"(empty? object)\n\n Function that returns #t if value is nil (an empty list) or undefined."),gensym:doc("gensym",gensym,"(gensym)\n\n Generates a unique symbol that is not bound anywhere,\n to use with macros as meta name."),load:doc("load",function e(u,t){typecheck("load",u,"string");var s=this;if(s.__name__==="__frame__"){s=s.__parent__}if(!(t instanceof Environment)){if(s===global_env){t=s}else{t=this.get("**interaction-environment**")}}var c="**module-path**";var l=global_env.get(c,{throwError:false});u=u.valueOf();if(!u.match(/.[^.]+$/)){u+=".scm"}var r=u.match(/\.xcb$/);function f(e){if(r){e=unserialize_bin(e)}else{if(type(e)==="buffer"){e=e.toString()}e=e.replace(/^#!.*/,"");if(e.match(/^\{/)){e=unserialize(e)}}return exec(e,{env:t})}function n(e){return root.fetch(e).then(function(e){return r?e.arrayBuffer():e.text()}).then(function(e){if(r){e=new Uint8Array(e)}return e})}if(is_node()){return new Promise(function(){var r=_asyncToGenerator(_regeneratorRuntime.mark(function e(r,n){var i,a,o;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:i=nodeRequire("path");if(!l){t.next=6;break}l=l.valueOf();u=i.join(l,u);t.next=12;break;case 6:a=s.get("command-line",{throwError:false});if(!a){t.next=11;break}t.next=10;return a();case 10:o=t.sent;case 11:if(o&&!is_nil(o)){process.cwd();u=i.join(i.dirname(o.car.valueOf()),u)}case 12:global_env.set(c,i.dirname(u));nodeRequire("fs").readFile(u,function(e,t){if(e){n(e);global_env.set(c,l)}else{try{f(t).then(function(){r();global_env.set(c,l)})["catch"](n)}catch(e){n(e)}}});case 14:case"end":return t.stop()}},e)}));return function(e,t){return r.apply(this,arguments)}}())}if(l){l=l.valueOf();u=l+"/"+u.replace(/^\.?\/?/,"")}return n(u).then(function(e){global_env.set(c,u.replace(/\/[^/]*$/,""));return f(e)}).then(function(){})["finally"](function(){global_env.set(c,l)})},"(load filename)\n (load filename environment)\n\n Fetches the file (from disk or network) and evaluates its content as LIPS code.\n If the second argument is provided and it's an environment the evaluation\n will happen in that environment."),while:doc(new Macro("while",function(e,t){var r=e.car;var n=_objectSpread(_objectSpread({},t),{},{env:this});var i=new Pair(new LSymbol("begin"),e.cdr);return function t(){return unpromise(_evaluate(r,n),function(e){if(e){return unpromise(_evaluate(i,n),t)}})}()}),"(while cond body)\n\n Creates a loop, it executes cond and body until cond expression is false."),do:doc(new Macro("do",function(){var r=_asyncToGenerator(function(_,e){var p=this;var d=e.use_dynamic,h=e.error;return _regeneratorRuntime.mark(function e(){var u,r,s,c,n,l,f,i,a,o;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:u=p;r=u;s=u.inherit("do");c=_.car;n=_.cdr.car;l=_.cdr.cdr;if(!is_nil(l)){l=new Pair(LSymbol("begin"),l)}f={env:u,dynamic_env:r,use_dynamic:d,error:h};i=c;case 9:if(is_nil(i)){t.next=20;break}a=i.car;t.t0=s;t.t1=a.car;t.next=15;return _evaluate(a.cdr.car,f);case 15:t.t2=t.sent;t.t0.set.call(t.t0,t.t1,t.t2);i=i.cdr;t.next=9;break;case 20:f={env:s,dynamic_env:r,error:h};o=_regeneratorRuntime.mark(function e(){var r,n,i,a,o;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(is_nil(l)){t.next=3;break}t.next=3;return lips.evaluate(l,f);case 3:r=c;n={};case 5:if(is_nil(r)){t.next=15;break}i=r.car;if(is_nil(i.cdr.cdr)){t.next=12;break}t.next=10;return _evaluate(i.cdr.cdr.car,f);case 10:a=t.sent;n[i.car.valueOf()]=a;case 12:r=r.cdr;t.next=5;break;case 15:o=Object.getOwnPropertySymbols(n);f.env=s=u.inherit("do");Object.keys(n).concat(o).forEach(function(e){s.set(e,n[e])});case 18:case"end":return t.stop()}},e)});case 22:t.next=24;return _evaluate(n.car,f);case 24:t.t3=t.sent;if(!(t.t3===false)){t.next=29;break}return t.delegateYield(o(),"t4",27);case 27:t.next=22;break;case 29:if(is_nil(n.cdr)){t.next=33;break}t.next=32;return _evaluate(n.cdr.car,f);case 32:return t.abrupt("return",t.sent);case 33:case"end":return t.stop()}},e)})()});return function(e,t){return r.apply(this,arguments)}}()),"(do (( )) (test return) . body)\n\n Iteration macro that evaluates the expression body in scope of the variables.\n On each loop it changes the variables according to the expression and runs\n test to check if the loop should continue. If test is a single value, the macro\n will return undefined. If the test is a pair of expressions the macro will\n evaluate and return the second expression after the loop exits."),if:doc(new Macro("if",function(r,e){var t=e.error,n=e.use_dynamic;var i=this;var a=this;var o={env:a,dynamic_env:i,use_dynamic:n,error:t};var u=function e(t){if(t===false){return _evaluate(r.cdr.cdr.car,o)}else{return _evaluate(r.cdr.car,o)}};if(is_nil(r)){throw new Error("too few expressions for `if`")}var s=_evaluate(r.car,o);return unpromise(s,u)}),"(if cond true-expr false-expr)\n\n Macro that evaluates cond expression and if the value is true, it\n evaluates and returns true-expression, if not it evaluates and returns\n false-expression."),"let-env":new Macro("let-env",function(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=e.dynamic_env,n=e.use_dynamic,i=e.error;typecheck("let-env",t,"pair");var a=_evaluate(t.car,{env:this,dynamic_env:r,error:i,use_dynamic:n});return unpromise(a,function(e){typecheck("let-env",e,"environment");return _evaluate(Pair(LSymbol("begin"),t.cdr),{env:e,dynamic_env:r,error:i})})},"(let-env env . body)\n\n Special macro that evaluates body in context of given environment\n object."),letrec:doc(let_macro(Symbol["for"]("letrec")),"(letrec ((a value-a) (b value-b) ...) . body)\n\n Macro that creates a new environment, then evaluates and assigns values to\n names and then evaluates the body in context of that environment.\n Values are evaluated sequentially and the next value can access the\n previous values/names."),"letrec*":doc(let_macro(Symbol["for"]("letrec")),"(letrec* ((a value-a) (b value-b) ...) . body)\n\n Same as letrec but the order of execution of the binding is guaranteed,\n so you can use recursive code as well as referencing the previous binding.\n\n In LIPS both letrec and letrec* behave the same."),"let*":doc(let_macro(Symbol["for"]("let*")),"(let* ((a value-a) (b value-b) ...) . body)\n\n Macro similar to `let`, but the subsequent bindings after the first\n are evaluated in the environment including the previous let variables,\n so you can define one variable, and use it in the next's definition."),let:doc(let_macro(Symbol["for"]("let")),"(let ((a value-a) (b value-b) ...) . body)\n\n Macro that creates a new environment, then evaluates and assigns values to names,\n and then evaluates the body in context of that environment. Values are evaluated\n sequentially but you can't access previous values/names when the next are\n evaluated. You can only get them in the body of the let expression. (If you want\n to define multiple variables and use them in each other's definitions, use\n `let*`.)"),"begin*":doc(parallel("begin*",function(e){return e.pop()}),"(begin* . body)\n\n This macro is a parallel version of begin. It evaluates each expression\n in the body and if it's a promise it will await it in parallel and return\n the value of the last expression (i.e. it uses Promise.all())."),shuffle:doc("shuffle",function(e){typecheck("shuffle",e,["pair","nil","array"]);var t=global_env.get("random");if(is_nil(e)){return _nil}if(Array.isArray(e)){return shuffle(e.slice(),t)}var r=global_env.get("list->array")(e);r=shuffle(r,t);return global_env.get("array->list")(r)},"(shuffle obj)\n\n Order items in vector or list in random order."),begin:doc(new Macro("begin",function(e,t){var n=_objectSpread(_objectSpread({},t),{},{env:this});var i=global_env.get("list->array")(e);var a;return function t(){if(i.length){var e=i.shift();var r=_evaluate(e,n);return unpromise(r,function(e){a=e;return t()})}else{return a}}()}),"(begin . args)\n\n Macro that runs a list of expressions in order and returns the value\n of the last one. It can be used in places where you can only have a\n single expression, like (if)."),ignore:new Macro("ignore",function(e,t){var r=_objectSpread(_objectSpread({},t),{},{env:this,dynamic_env:this});_evaluate(new Pair(new LSymbol("begin"),e),r)},"(ignore . body)\n\n Macro that will evaluate the expression and swallow any promises that may\n be created. It will discard any value that may be returned by the last body\n expression. The code should have side effects and/or when it's promise\n it should resolve to undefined."),"call/cc":doc(Macro.defmacro("call/cc",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=_objectSpread({env:this},t);return unpromise(_evaluate(e.car,r),function(e){if(is_function(e)){return e(new Continuation(null))}})}),"(call/cc proc)\n\n Call-with-current-continuation.\n\n NOT SUPPORTED BY LIPS RIGHT NOW"),parameterize:doc(new Macro("parameterize",function(t,e){var i=e.dynamic_env;var a=i.inherit("parameterize").new_frame(null,{});var o=_objectSpread(_objectSpread({},e),{},{env:this});var u=t.car;if(!is_pair(u)){var r=type(u);throw new Error("Invalid syntax for parameterize expecting pair got ".concat(r))}function s(){var e=new Pair(new LSymbol("begin"),t.cdr);return _evaluate(e,_objectSpread(_objectSpread({},o),{},{dynamic_env:a}))}return function r(){var e=u.car;var n=e.car.valueOf();return unpromise(_evaluate(e.cdr.car,o),function(e){var t=i.get(n,{throwError:false});if(!is_parameter(t)){throw new Error("Unknown parameter ".concat(n))}a.set(n,t.inherit(e));if(!is_null(u.cdr)){u=u.cdr;return r()}else{return s()}})}()}),"(parameterize ((name value) ...)\n\n Macro that change the dynamic variable created by make-parameter."),"make-parameter":doc(new Macro("make-parameter",function(e,t){t.dynamic_env;var r=_evaluate(e.car,t);var n;if(is_pair(e.cdr.car)){n=_evaluate(e.cdr.car,t)}return new Parameter(r,n)}),"(make-parameter init converter)\n\n Function creates new dynamic variable that can be custimized with parameterize\n macro. The value should be assigned to a variable e.g.:\n\n (define radix (make-parameter 10))\n\n The result value is a procedure that return the value of dynamic variable."),"define-syntax-parameter":doc(new Macro("define-syntax-parameter",function(e,t){var r=e.car;var n=this;if(!(r instanceof LSymbol)){throw new Error("define-syntax-parameter: invalid syntax expecting symbol got ".concat(type(r)))}var i=_evaluate(e.cdr.car,_objectSpread({env:n},t));typecheck("define-syntax-parameter",i,"syntax",2);i.__name__=r.valueOf();if(i.__name__ instanceof LString){i.__name__=i.__name__.valueOf()}var a;if(is_pair(e.cdr.cdr)&&LString.isString(e.cdr.cdr.car)){a=e.cdr.cdr.car.valueOf()}n.set(e.car,new SyntaxParameter(i),a,true)}),"(define-syntax-parameter name syntax [__doc__])\n\n Binds to the transformer obtained by evaluating .\n The transformer provides the default expansion for the syntax parameter,\n and in the absence of syntax-parameterize, is functionally equivalent to\n define-syntax."),"syntax-parameterize":doc(new Macro("syntax-parameterize",function(e,t){var r=global_env.get("list->array")(e.car);var n=this.inherit("syntax-parameterize");while(r.length){var i=r.shift();if(!(is_pair(i)||i.car instanceof LSymbol)){var a="invalid syntax for syntax-parameterize: ".concat(repr(e,true));throw new Error("syntax-parameterize: ".concat(a))}var o=_evaluate(i.cdr.car,_objectSpread(_objectSpread({},t),{},{env:this}));var u=i.car;typecheck("syntax-parameterize",o,["syntax"]);typecheck("syntax-parameterize",u,"symbol");o.__name__=u.valueOf();if(o.__name__ instanceof LString){o.__name__=o.__name__.valueOf()}var s=new SyntaxParameter(o);if(u.is_gensym()){var c=u.literal();var l=this.get(c,{throwError:false});if(l instanceof SyntaxParameter){n.set(c,s)}}n.set(u,s)}var f=new Pair(new LSymbol("begin"),e.cdr);return _evaluate(f,_objectSpread(_objectSpread({},t),{},{env:n}))}),"(syntax-parameterize (bindings) body)\n\n Macro work similar to let-syntax but the the bindnds will be exposed to the user.\n With syntax-parameterize you can define anaphoric macros."),define:doc(Macro.defmacro("define",function(r,e){var n=this;if(is_pair(r.car)&&r.car.car instanceof LSymbol){var t=new Pair(new LSymbol("define"),new Pair(r.car.car,new Pair(new Pair(new LSymbol("lambda"),new Pair(r.car.cdr,r.cdr)))));return t}else if(e.macro_expand){return}e.dynamic_env=this;e.env=n;var i=r.cdr.car;var a;if(is_pair(i)){i=_evaluate(i,e);a=true}else if(i instanceof LSymbol){i=n.get(i)}typecheck("define",r.car,"symbol");return unpromise(i,function(e){if(n.__name__===Syntax.__merge_env__){n=n.__parent__}if(a&&(is_function(e)&&is_lambda(e)||e instanceof Syntax||is_parameter(e))){e.__name__=r.car.valueOf();if(e.__name__ instanceof LString){e.__name__=e.__name__.valueOf()}}var t;if(is_pair(r.cdr.cdr)&&LString.isString(r.cdr.cdr.car)){t=r.cdr.cdr.car.valueOf()}n.set(r.car,e,t,true)})}),'(define name expression)\n (define name expression "doc string")\n (define (function-name . args) . body)\n\n Macro for defining values. It can be used to define variables,\n or functions. If the first argument is list it will create a function\n with name being first element of the list. This form expands to\n `(define function-name (lambda args body))`'),"set-obj!":doc("set-obj!",function(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;var i=_typeof$1(e);if(is_null(e)||i!=="object"&&i!=="function"){var a=typeErrorMessage("set-obj!",type(e),["object","function"]);throw new Error(a)}typecheck("set-obj!",t,["string","symbol","number"]);e=unbind(e);t=t.valueOf();if(arguments.length===2){delete e[t]}else if(is_prototype(e)&&is_function(r)){e[t]=unbind(r);e[t][__prototype__]=true}else if(is_function(r)||is_native(r)||is_nil(r)){e[t]=r}else{e[t]=r&&!is_prototype(r)?r.valueOf():r}if(props){var o=e[t];Object.defineProperty(e,t,_objectSpread(_objectSpread({},n),{},{value:o}))}},"(set-obj! obj key value)\n (set-obj! obj key value props)\n\n Function set a property of a JavaScript object. props should be a vector of pairs,\n passed to Object.defineProperty."),"null-environment":doc("null-environment",function(){return global_env.inherit("null")},"(null-environment)\n\n Returns a clean environment with only the standard library."),values:doc("values",function e(){for(var t=arguments.length,r=new Array(t),n=0;n1&&arguments[1]!==undefined?arguments[1]:{},y=e.use_dynamic,v=e.error;var b=this;var g;if(is_pair(m.cdr)&&LString.isString(m.cdr.car)&&!is_nil(m.cdr.cdr)){g=m.cdr.car.valueOf()}function w(){var e=is_context(this)?this:{dynamic_env:b},r=e.dynamic_env;var n=b.inherit("lambda");r=r.inherit("lambda");if(this&&!is_context(this)){if(this&&!this.__instance__){Object.defineProperty(this,"__instance__",{enumerable:false,get:function e(){return true},set:function e(){},configurable:false})}n.set("this",this)}for(var t=arguments.length,i=new Array(t),a=0;a> SYNTAX");log(e);log(v);var n=w.inherit("syntax");var i=n;var a=this;if(a.__name__===Syntax.__merge_env__){var o=Object.getOwnPropertySymbols(a.__env__);o.forEach(function(e){a.__parent__.set(e,a.__env__[e])});a=a.__parent__}var u={env:n,dynamic_env:i,use_dynamic:b,error:g};var s,c,l;if(v.car instanceof LSymbol){s=v.car;l=D(v.cdr.car);c=v.cdr.cdr}else{s="...";l=D(v.car);c=v.cdr}try{while(!is_nil(c)){var f=c.car.car;var _=c.car.cdr.car;log("[[[ RULE");log(f);var p=extract_patterns(f,e,l,s,{expansion:this,define:w});if(p){if(is_debug()){console.log(JSON.stringify(symbolize(p),true,2));console.log("PATTERN: "+f.toString(true));console.log("MACRO: "+e.toString(true))}var d=[];var h=transform_syntax({bindings:p,expr:_,symbols:l,scope:n,lex_scope:a,names:d,ellipsis:s});log("OUPUT>>> ",h);if(h){_=h}var m=a.merge(n,Syntax.__merge_env__);if(r){return{expr:_,scope:m}}var y=_evaluate(_,_objectSpread(_objectSpread({},u),{},{env:m}));return clear_gensyms(y,d)}c=c.cdr}}catch(e){e.message+="\nin macro:\n ".concat(v.toString(true));throw e}throw new Error("syntax-rules: no matching syntax in macro ".concat(e.toString(true)))},w);r.__code__=v;return r},"(syntax-rules () (pattern expression) ...)\n\n Base of hygienic macros, it will return a new syntax expander\n that works like Lisp macros."),quote:doc(new Macro("quote",function(e){return quote(e.car)}),"(quote expression) or 'expression\n\n Macro that returns a single LIPS expression as data (it won't evaluate the\n argument). It will return a list if put in front of LIPS code.\n And if put in front of a symbol it will return the symbol itself, not the value\n bound to that name."),"unquote-splicing":doc("unquote-splicing",function(){throw new Error("You can't call `unquote-splicing` outside of quasiquote")},"(unquote-splicing code) or ,@code\n\n Special form used in the quasiquote macro. It evaluates the expression inside and\n splices the list into quasiquote's result. If it is not the last element of the\n expression, the computed value must be a pair."),unquote:doc("unquote",function(){throw new Error("You can't call `unquote` outside of quasiquote")},"(unquote code) or ,code\n\n Special form used in the quasiquote macro. It evaluates the expression inside and\n substitutes the value into quasiquote's result."),quasiquote:Macro.defmacro("quasiquote",function(e,t){var u=t.use_dynamic,s=t.error;var c=this;var l=c;function a(e){return is_pair(e)||is_plain_object(e)||Array.isArray(e)}function f(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:a;if(is_pair(e)){var n=e.car;var i=e.cdr;if(r(n)){n=t(n)}if(r(i)){i=t(i)}if(is_promise(n)||is_promise(i)){return promise_all([n,i]).then(function(e){var t=_slicedToArray(e,2),r=t[0],n=t[1];return new Pair(r,n)})}else{return new Pair(n,i)}}return e}function o(e,t){if(is_pair(e)){if(!is_nil(t)){e.append(t)}}else{e=new Pair(e,t)}return e}function r(e){return!!e.filter(function(e){return is_pair(e)&&LSymbol.is(e.car,/^(unquote|unquote-splicing)$/)}).length}function _(e,n,i){return e.reduce(function(e,t){if(!is_pair(t)){e.push(t);return e}if(LSymbol.is(t.car,"unquote-splicing")){var r;if(n+11){var t="You can't splice multiple atoms inside list";throw new Error(t)}if(!(is_pair(i.cdr)&&is_nil(r[0]))){return r[0]}}r=r.map(function(e){if(h.has(e)){return e.clone()}else{h.add(e);return e}});var n=m(i.cdr,0,1);if(is_nil(n)&&is_nil(r[0])){return undefined}return unpromise(n,function(e){if(is_nil(r[0])){return e}if(r.length===1){return o(r[0],e)}var t=r.reduce(function(e,t){return o(e,t)});return o(t,e)})})}(i.car.cdr)}var h=new Set;function m(e,t,r){if(is_pair(e)){if(is_pair(e.car)){if(LSymbol.is(e.car.car,"unquote-splicing")){return d(e,t+1,r)}if(LSymbol.is(e.car.car,"unquote")){if(t+2===r&&is_pair(e.car.cdr)&&is_pair(e.car.cdr.car)&&LSymbol.is(e.car.cdr.car.car,"unquote-splicing")){var n=e.car.cdr;return new Pair(new Pair(new LSymbol("unquote"),d(n,t+2,r)),_nil)}else if(is_pair(e.car.cdr)&&!is_nil(e.car.cdr.cdr)){if(is_pair(e.car.cdr.car)){var i=[];return function t(r){if(is_nil(r)){return Pair.fromArray(i)}return unpromise(_evaluate(r.car,{env:c,dynamic_env:l,use_dynamic:u,error:s}),function(e){i.push(e);return t(r.cdr)})}(e.car.cdr)}else{return e.car.cdr}}}}if(LSymbol.is(e.car,"quasiquote")){var a=m(e.cdr,t,r+1);return new Pair(e.car,a)}if(LSymbol.is(e.car,"quote")){return new Pair(e.car,m(e.cdr,t,r))}if(LSymbol.is(e.car,"unquote")){t++;if(tr){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(is_pair(e.cdr)){if(!is_nil(e.cdr.cdr)){if(is_pair(e.cdr.car)){var o=[];return function t(r){if(is_nil(r)){return Pair.fromArray(o)}return unpromise(_evaluate(r.car,{env:c,dynamic_env:l,use_dynamic:u,error:s}),function(e){o.push(e);return t(r.cdr)})}(e.cdr)}else{return e.cdr}}else{return _evaluate(e.cdr.car,{env:c,dynamic_env:l,error:s})}}else{return e.cdr}}return f(e,function(e){return m(e,t,r)})}else if(is_plain_object(e)){return p(e,t,r)}else if(e instanceof Array){return _(e,t,r)}return e}function n(e){if(is_pair(e)){delete e[__data__];if(!e.have_cycles("car")){n(e.car)}if(!e.have_cycles("cdr")){n(e.cdr)}}}if(is_plain_object(e.car)&&!r(Object.values(e.car))){return quote(e.car)}if(Array.isArray(e.car)&&!r(e.car)){return quote(e.car)}if(is_pair(e.car)&&!e.car.find("unquote")&&!e.car.find("unquote-splicing")&&!e.car.find("quasiquote")){return quote(e.car)}var i=m(e.car,0,1);return unpromise(i,function(e){n(e);return quote(e)})},"(quasiquote list)\n\n Similar macro to `quote` but inside it you can use special expressions (unquote\n x) abbreviated to ,x that will evaluate x and insert its value verbatim or\n (unquote-splicing x) abbreviated to ,@x that will evaluate x and splice the value\n into the result. Best used with macros but it can be used outside."),clone:doc("clone",function e(t){typecheck("clone",t,"pair");return t.clone()},"(clone list)\n\n Function that returns a clone of the list, that does not share any pairs with the\n original, so the clone can be safely mutated without affecting the original."),append:doc("append",function e(){var t;for(var r=arguments.length,n=new Array(r),i=0;iarray")(t).reverse();return global_env.get("array->list")(r)}else if(Array.isArray(t)){return t.reverse()}else{throw new Error(typeErrorMessage("reverse",type(t),"array or pair"))}},"(reverse list)\n\n Function that reverses the list or array. If value is not a list\n or array it will error."),nth:doc("nth",function e(t,r){typecheck("nth",t,"number");typecheck("nth",r,["array","pair"]);if(is_pair(r)){var n=r;var i=0;while(iarray")(r).join(t)},"(join separator list)\n\n Function that returns a string by joining elements of the list using separator."),split:doc("split",function e(t,r){typecheck("split",t,["regex","string"]);typecheck("split",r,"string");return global_env.get("array->list")(r.split(t))},"(split separator string)\n\n Function that creates a list by splitting string by separator which can\n be a string or regular expression."),replace:doc("replace",function e(t,r,n){typecheck("replace",t,["regex","string"]);typecheck("replace",r,["string","function"]);typecheck("replace",n,"string");if(is_function(r)){var i=[];n.replace(t,function(){i.push(r.apply(void 0,arguments))});return unpromise(i,function(e){return n.replace(t,function(){return e.shift()})})}return n.replace(t,r)},"(replace pattern replacement string)\n\n Function that changes pattern to replacement inside string. Pattern can be a\n string or regex and replacement can be function or string. See Javascript\n String.replace()."),match:doc("match",function e(t,r){typecheck("match",t,["regex","string"]);typecheck("match",r,"string");var n=r.match(t);return n?global_env.get("array->list")(n):false},"(match pattern string)\n\n Function that returns a match object from JavaScript as a list or #f if\n no match."),search:doc("search",function e(t,r){typecheck("search",t,["regex","string"]);typecheck("search",r,"string");return r.search(t)},"(search pattern string)\n\n Function that returns the first found index of the pattern inside a string."),repr:doc("repr",function e(t,r){return toString(t,r)},"(repr obj)\n\n Function that returns a LIPS code representation of the object as a string."),"escape-regex":doc("escape-regex",function(e){typecheck("escape-regex",e,"string");return escape_regex(e.valueOf())},"(escape-regex string)\n\n Function that returns a new string where all special operators used in regex,\n are escaped with backslashes so they can be used in the RegExp constructor\n to match a literal string."),env:doc("env",function e(e){e=e||this.env;var t=Object.keys(e.__env__).map(LSymbol);var r;if(t.length){r=Pair.fromArray(t)}else{r=_nil}if(e.__parent__ instanceof Environment){return global_env.get("env").call(this,e.__parent__).append(r)}return r},"(env)\n (env obj)\n\n Function that returns a list of names (functions, macros and variables)\n that are bound in the current environment or one of its parents."),new:doc("new",function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n2&&arguments[2]!==undefined?arguments[2]:specials.LITERAL;typecheck("set-special!",e,"string",1);typecheck("set-special!",t,"symbol",2);specials.append(e.valueOf(),t,r)},'(set-special! symbol name [type])\n\n Add a special symbol to the list of transforming operators by the parser.\n e.g.: `(add-special! "#" \'x)` will allow to use `#(1 2 3)` and it will be\n transformed into (x (1 2 3)) so you can write x macro that will process\n the list. 3rd argument is optional, and it can be one of two values:\n lips.specials.LITERAL, which is the default behavior, or\n lips.specials.SPLICE which causes the value to be unpacked into the expression.\n This can be used for e.g. to make `#(1 2 3)` into (x 1 2 3) that is needed\n by # that defines vectors.'),get:get,".":get,unbind:doc(unbind,"(unbind fn)\n\n Function that removes the weak 'this' binding from a function so you\n can get properties from the actual function object."),type:doc(type,"(type object)\n\n Function that returns the type of an object as string."),debugger:doc("debugger",function(){debugger},'(debugger)\n\n Function that triggers the JavaScript debugger (e.g. the browser devtools)\n using the "debugger;" statement. If a debugger is not running this\n function does nothing.'),in:doc("in",function(e,t){if(e instanceof LSymbol||e instanceof LString||e instanceof LNumber){e=e.valueOf()}return e in unbox(t)},'(in key value)\n\n Function that uses the Javascript "in" operator to check if key is\n a valid property in the value.'),"instance?":doc("instance?",function(e){return is_instance(e)},"(instance? obj)\n\n Checks if object is an instance, created with a new operator"),instanceof:doc("instanceof",function(e,t){return t instanceof unbind(e)},"(instanceof type obj)\n\n Predicate that tests if the obj is an instance of type."),"prototype?":doc("prototype?",is_prototype,"(prototype? obj)\n\n Predicate that tests if value is a valid JavaScript prototype,\n i.e. calling (new) with it will not throw ' is not a constructor'."),"macro?":doc("macro?",function(e){return e instanceof Macro},"(macro? expression)\n\n Predicate that tests if value is a macro."),"continuation?":doc("continuation?",is_continuation,"(continuation? expression)\n\n Predicate that tests if value is a callable continuation."),"function?":doc("function?",is_function,"(function? expression)\n\n Predicate that tests if value is a callable function."),"real?":doc("real?",function(e){if(type(e)!=="number"){return false}if(e instanceof LNumber){return e.isFloat()}return LNumber.isFloat(e)},"(real? number)\n\n Predicate that tests if value is a real number (not complex)."),"number?":doc("number?",function(e){return Number.isNaN(e)||LNumber.isNumber(e)},"(number? expression)\n\n Predicate that tests if value is a number or NaN value."),"string?":doc("string?",function(e){return LString.isString(e)},"(string? expression)\n\n Predicate that tests if value is a string."),"pair?":doc("pair?",is_pair,"(pair? expression)\n\n Predicate that tests if value is a pair or list structure."),"regex?":doc("regex?",function(e){return e instanceof RegExp},"(regex? expression)\n\n Predicate that tests if value is a regular expression."),"null?":doc("null?",function(e){return is_null(e)},"(null? expression)\n\n Predicate that tests if value is null-ish (i.e. undefined, nil, or\n Javascript null)."),"boolean?":doc("boolean?",function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Predicate that tests if value is a boolean (#t or #f)."),"symbol?":doc("symbol?",function(e){return e instanceof LSymbol},"(symbol? expression)\n\n Predicate that tests if value is a LIPS symbol."),"array?":doc("array?",function(e){return e instanceof Array},"(array? expression)\n\n Predicate that tests if value is an array."),"object?":doc("object?",function(e){return!is_nil(e)&&e!==null&&!(e instanceof LCharacter)&&!(e instanceof RegExp)&&!(e instanceof LString)&&!is_pair(e)&&!(e instanceof LNumber)&&_typeof$1(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Predicate that tests if value is an plain object (not another LIPS type)."),flatten:doc("flatten",function e(t){typecheck("flatten",t,"pair");return t.flatten()},"(flatten list)\n\n Returns a shallow list from tree structure (pairs)."),"array->list":doc("array->list",function(e){typecheck("array->list",e,"array");return Pair.fromArray(e)},"(array->list array)\n\n Function that converts a JavaScript array to a LIPS cons list."),"tree->array":doc("tree->array",to_array("tree->array",true),"(tree->array list)\n\n Function that converts a LIPS cons tree structure into a JavaScript array."),"list->array":doc("list->array",to_array("list->array"),"(list->array list)\n\n Function that converts a LIPS list into a JavaScript array."),apply:doc("apply",function e(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;iarray").call(this,a));return t.apply(this,prepare_fn_args(t,n))},"(apply fn list)\n\n Function that calls fn with the list of arguments."),length:doc("length",function e(t){if(!t||is_nil(t)){return 0}if(is_pair(t)){return t.length()}if("length"in t){return t.length}},'(length expression)\n\n Function that returns the length of the object. The object can be a LIPS\n list or any object that has a "length" property. Returns undefined if the\n length could not be found.'),"string->number":doc("string->number",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;typecheck("string->number",e,"string",1);typecheck("string->number",t,"number",2);e=e.valueOf();t=t.valueOf();if(e.match(rational_bare_re)||e.match(rational_re)){return parse_rational(e,t)}else if(e.match(complex_bare_re)||e.match(complex_re)){return parse_complex(e,t)}else{var r=t===10&&!e.match(/e/i)||t===16;if(e.match(int_bare_re)&&r||e.match(int_re)){return parse_integer(e,t)}if(e.match(float_re)){return parse_float(e)}}return false},"(string->number number [radix])\n\n Function that parses a string into a number."),try:doc(new Macro("try",function(r,e){var f=this;var _=e.use_dynamic;e.error;return new Promise(function(t,u){var s,n;if(LSymbol.is(r.cdr.car.car,"catch")){s=r.cdr.car;if(is_pair(r.cdr.cdr)&&LSymbol.is(r.cdr.cdr.car.car,"finally")){n=r.cdr.cdr.car}}else if(LSymbol.is(r.cdr.car.car,"finally")){n=r.cdr.car}if(!(n||s)){throw new Error("try: invalid syntax")}function c(e){t(e);throw new IgnoreException("[CATCH]")}var l=function e(t,r){r(t)};if(n){l=function e(t,r){l=u;i.error=function(e){throw e};unpromise(_evaluate(new Pair(new LSymbol("begin"),n.cdr),i),function(){r(t)})}}var i={env:f,use_dynamic:_,dynamic_env:f,error:function e(t){if(t instanceof IgnoreException){throw t}if(s){var r=f.inherit("try");var n=s.cdr.car.car;if(!(n instanceof LSymbol)){throw new Error("try: invalid syntax: catch require variable name")}r.set(n,t);var i;var a={env:r,use_dynamic:_,dynamic_env:f,error:function e(t){i=true;u(t);throw new IgnoreException("[CATCH]")}};var o=_evaluate(new Pair(new LSymbol("begin"),s.cdr.cdr),a);unpromise(o,function e(t){if(!i){l(t,c)}})}else{l(undefined,function(){u(t)})}}};var e=_evaluate(r.car,i);unpromise(e,function(e){l(e,t)},i.error)})}),"(try expr (catch (e) code))\n (try expr (catch (e) code) (finally code))\n (try expr (finally code))\n\n Macro that executes expr and catches any exceptions thrown. If catch is provided\n it's executed when an error is thrown. If finally is provided it's always\n executed at the end."),raise:doc("raise",function(e){throw e},"(raise obj)\n\n Throws the object verbatim (no wrapping an a new Error)."),throw:doc("throw",function(e){throw new Error(e)},"(throw string)\n\n Throws a new exception."),find:doc("find",function t(r,n){typecheck("find",r,["regex","function"]);typecheck("find",n,["pair","nil"]);if(is_null(n)){return _nil}var e=matcher("find",r);return unpromise(e(n.car),function(e){if(e&&!is_nil(e)){return n.car}return t(r,n.cdr)})},"(find fn list)\n (find regex list)\n\n Higher-order function that finds the first value for which fn return true.\n If called with a regex it will create a matcher function."),"for-each":doc("for-each",function(e){var t;typecheck("for-each",e,"function");for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i1?t-1:0),a=1;a3?n-3:0),a=3;a3?i-3:0),o=3;oarray")(r);var a=[];var o=matcher("filter",t);return function t(r){function e(e){if(e&&!is_nil(e)){a.push(n)}return t(++r)}if(r===i.length){return Pair.fromArray(a)}var n=i[r];return unpromise(o(n),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher-order function that calls `fn` for each element of the list\n and return a new list for only those elements for which fn returns\n a truthy value. If called with a regex it will create a matcher function."),compose:doc(compose,"(compose . fns)\n\n Higher-order function that creates a new function that applies all functions\n from right to left and returns the last value. Reverse of pipe.\n e.g.:\n ((compose (curry + 2) (curry * 3)) 10) --\x3e (+ 2 (* 3 10)) --\x3e 32"),pipe:doc(pipe,"(pipe . fns)\n\n Higher-order function that creates a new function that applies all functions\n from left to right and returns the last value. Reverse of compose.\n e.g.:\n ((pipe (curry + 2) (curry * 3)) 10) --\x3e (* 3 (+ 2 10)) --\x3e 36"),curry:doc(curry,"(curry fn . args)\n\n Higher-order function that creates a curried version of the function.\n The result function will have partially applied arguments and it\n will keep returning one-argument functions until all arguments are provided,\n then it calls the original function with the accumulated arguments.\n\n e.g.:\n (define (add a b c d) (+ a b c d))\n (define add1 (curry add 1))\n (define add12 (add 2))\n (display (add12 3 4))"),gcd:doc("gcd",function e(){for(var t=arguments.length,r=new Array(t),n=0;nu?a%=u:u%=a}a=abs(s*r[o])/(a+u)}return LNumber(a)},"(lcm n1 n2 ...)\n\n Function that returns the least common multiple of the arguments."),"odd?":doc("odd?",single_math_op(function(e){return LNumber(e).isOdd()}),"(odd? number)\n\n Checks if number is odd."),"even?":doc("even?",single_math_op(function(e){return LNumber(e).isEven()}),"(even? number)\n\n Checks if number is even."),"*":doc("*",reduce_math_op(function(e,t){return LNumber(e).mul(t)},LNumber(1)),"(* . numbers)\n\n Multiplies all numbers passed as arguments. If single value is passed\n it will return that value."),"+":doc("+",reduce_math_op(function(e,t){return LNumber(e).add(t)},LNumber(0)),"(+ . numbers)\n\n Sums all numbers passed as arguments. If single value is passed it will\n return that value."),"-":doc("-",function(){for(var e=arguments.length,t=new Array(e),r=0;r":doc(">",function(){for(var e=arguments.length,t=new Array(e),r=0;r",t,["bigint","float","rational"]);return seq_compare(function(e,t){return LNumber(e).cmp(t)===1},t)},"(> x1 x2 x3 ...)\n\n Function that compares its numerical arguments and checks if they are\n monotonically decreasing, i.e. x1 > x2 and x2 > x3 and so on."),"<":doc("<",function(){for(var e=arguments.length,t=new Array(e),r=0;r=":doc(">=",function(){for(var e=arguments.length,t=new Array(e),r=0;r=",t,["bigint","float","rational"]);return seq_compare(function(e,t){return[0,1].includes(LNumber(e).cmp(t))},t)},"(>= x1 x2 ...)\n\n Function that compares its numerical arguments and checks if they are\n monotonically nonincreasing, i.e. x1 >= x2 and x2 >= x3 and so on."),"eq?":doc("eq?",equal,"(eq? a b)\n\n Function that compares two values if they are identical."),or:doc(new Macro("or",function(e,t){var i=t.use_dynamic,a=t.error;var o=global_env.get("list->array")(e);var u=this;var s=u;if(!o.length){return false}var c;return function t(){function e(e){c=e;if(c!==false){return c}else{return t()}}if(!o.length){if(c!==false){return c}else{return false}}else{var r=o.shift();var n=_evaluate(r,{env:u,dynamic_env:s,use_dynamic:i,error:a});return unpromise(n,e)}}()}),"(or . expressions)\n\n Macro that executes the values one by one and returns the first that is\n a truthy value. If there are no expressions that evaluate to true it\n returns false."),and:doc(new Macro("and",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=t.error;var i=global_env.get("list->array")(e);var a=this;var o=a;if(!i.length){return true}var u;var s={env:a,dynamic_env:o,use_dynamic:r,error:n};return function t(){function e(e){u=e;if(u===false){return false}else{return t()}}if(!i.length){if(u!==false){return u}else{return false}}else{var r=i.shift();return unpromise(_evaluate(r,s),e)}}()}),"(and . expressions)\n\n Macro that evaluates each expression in sequence and if any value returns false\n it will stop and return false. If each value returns true it will return the\n last value. If it's called without arguments it will return true."),"|":doc("|",function(e,t){return LNumber(e).or(t)},"(| a b)\n\n Function that calculates the bitwise or operation."),"&":doc("&",function(e,t){return LNumber(e).and(t)},"(& a b)\n\n Function that calculates the bitwise and operation."),"~":doc("~",function(e){return LNumber(e).neg()},"(~ number)\n\n Function that calculates the bitwise inverse (flip all the bits)."),">>":doc(">>",function(e,t){return LNumber(e).shr(t)},"(>> a b)\n\n Function that right shifts the value a by value b bits."),"<<":doc("<<",function(e,t){return LNumber(e).shl(t)},"(<< a b)\n\n Function that left shifts the value a by value b bits."),not:doc("not",function e(t){if(is_null(t)){return true}return!t},"(not object)\n\n Function that returns the Boolean negation of its argument.")},undefined,"global");var user_env=global_env.inherit("user-env");function set_interaction_env(e,t){e.constant("**internal-env**",t);e.doc("**internal-env**","**internal-env**\n\n Constant used to hide stdin, stdout and stderr so they don't interfere\n with variables with the same name. Constants are an internal type\n of variable that can't be redefined, defining a variable with the same name\n will throw an error.");global_env.set("**interaction-environment**",e)}set_interaction_env(user_env,internal_env);global_env.doc("**interaction-environment**","**interaction-environment**\n\n Internal dynamic, global variable used to find interpreter environment.\n It's used so the read and write functions can locate **internal-env**\n that contains the references to stdin, stdout and stderr.");function set_fs(e){user_env.get("**internal-env**").set("fs",e)}(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(t){var r=e[t]?e[t]:t;global_env.set(r,doc(r,function(e){typecheck(r,e,"number");if(e instanceof LNumber){return e[t]()}},"(".concat(r," number)\n\n Function that calculates the ").concat(r," of a number.")))})})();function allPossibleCases(e){if(e.length===1){return e[0]}else{var t=[];var r=allPossibleCases(e.slice(1));for(var n=0;n3&&arguments[3]!==undefined?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(n!==null){i+=" (argument ".concat(n,")")}if(is_function(r)){return"Invalid type: got ".concat(t).concat(i)}if(r instanceof Array){if(r.length===1){var a=r[0].toLowerCase();r="a"+("aeiou".includes(a)?"n ":" ")+r[0]}else{r=new Intl.ListFormat("en",{style:"long",type:"disjunction"}).format(r)}}return"Expecting ".concat(r," got ").concat(t).concat(i)}function typecheck_number(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;typecheck(e,t,"number",n);var i=t.__type__;var a;if(is_pair(r)){r=r.to_array()}if(r instanceof Array){r=r.map(function(e){return e.valueOf()})}if(r instanceof Array){r=r.map(function(e){return e.valueOf().toLowerCase()});if(r.includes(i)){a=true}}else{r=r.valueOf().toLowerCase()}if(!a&&i!==r){throw new Error(typeErrorMessage(e,i,r,n))}}function typecheck_numbers(r,e,n){e.forEach(function(e,t){typecheck_number(r,e,n,t+1)})}function typecheck_args(r,e,n){e.forEach(function(e,t){typecheck(r,e,n,t+1)})}function typecheck_text_port(e,t,r){typecheck(e,t,r);if(t.__type__===binary_port){throw new Error(typeErrorMessage(e,"binary-port","textual-port"))}}function typecheck(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;e=e.valueOf();var i=type(t).toLowerCase();if(is_function(r)){if(!r(t)){throw new Error(typeErrorMessage(e,i,r,n))}return}var a=false;if(is_pair(r)){r=r.to_array()}if(r instanceof Array){r=r.map(function(e){return e.valueOf()})}if(r instanceof Array){r=r.map(function(e){return e.valueOf().toLowerCase()});if(r.includes(i)){a=true}}else{r=r.valueOf().toLowerCase()}if(!a&&i!==r){throw new Error(typeErrorMessage(e,i,r,n))}}function memoize(r){var n=new WeakMap;return function(e){var t=n.get(e);if(!t){t=r(e)}return t}}type=memoize(type);function type(e){var t=type_constants.get(e);if(t){return t}if(_typeof$1(e)==="object"){for(var r=0,n=Object.entries(type_mapping);r2&&arguments[2]!==undefined?arguments[2]:{},n=r.env,i=r.dynamic_env,a=r.use_dynamic;var o=n===null||n===void 0?void 0:n.new_frame(e,t);var u=i===null||i===void 0?void 0:i.new_frame(e,t);var s=new LambdaContext({env:o,use_dynamic:a,dynamic_env:u});return resolve_promises(e.apply(s,t))}function apply(n,e){var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},i=t.env,a=t.dynamic_env,o=t.use_dynamic,r=t.error,u=r===void 0?function(){}:r;e=evaluate_args(e,{env:i,dynamic_env:a,error:u,use_dynamic:o});return unpromise(e,function(e){if(is_raw_lambda(n)){n=unbind(n)}e=prepare_fn_args(n,e);var t=e.slice();var r=call_function(n,t,{env:i,dynamic_env:a,use_dynamic:o});return unpromise(r,function(e){if(is_pair(e)){e.mark_cycles();return quote(e)}return box(e)},u)})}var _p_name__=new WeakMap;var Parameter=function(){function n(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;_classCallCheck(this,n);_defineProperty(this,"__value__",void 0);_defineProperty(this,"__fn__",void 0);_classPrivateFieldInitSpec(this,_p_name__,{writable:true,value:void 0});this.__value__=e;if(t){if(!is_function(t)){throw new Error("Section argument to Parameter need to be function "+"".concat(type(t)," given"))}this.__fn__=t}if(r){_classPrivateFieldSet(this,_p_name__,r)}}_createClass(n,[{key:"__name__",get:function e(){return _classPrivateFieldGet(this,_p_name__)},set:function e(t){_classPrivateFieldSet(this,_p_name__,t);if(this.__fn__){this.__fn__.__name__="fn-".concat(t)}}},{key:"invoke",value:function e(){if(is_function(this.__fn__)){return this.__fn__(this.__value__)}return this.__value__}},{key:"inherit",value:function e(t){return new n(t,this.__fn__,this.__name__)}}]);return n}();var LambdaContext=function(){function t(e){_classCallCheck(this,t);_defineProperty(this,"env",void 0);_defineProperty(this,"dynamic_env",void 0);_defineProperty(this,"use_dynamic",void 0);Object.assign(this,e)}_createClass(t,[{key:"__name__",get:function e(){return this.env.__name__}},{key:"__parent__",get:function e(){return this.env.__parent__}},{key:"get",value:function e(){var t;return(t=this.env).get.apply(t,arguments)}}]);return t}();function search_param(e,t){var r=e.get(t.__name__,{throwError:false});if(is_parameter(r)&&r!==t){return r}var n=user_env.get("**interaction-environment**");while(true){var i=e.get("parent.frame",{throwError:false});e=i(0);if(e===n){break}r=e.get(t.__name__,{throwError:false});if(is_parameter(r)&&r!==t){return r}}return t}var Continuation=function(){function t(e){_classCallCheck(this,t);_defineProperty(this,"__value__",void 0);this.__value__=e}_createClass(t,[{key:"invoke",value:function e(){if(this.__value__===null){throw new Error("Continuations are not implemented yet")}}}]);return t}();function _evaluate(u){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},s=e.env,c=e.dynamic_env,l=e.use_dynamic,t=e.error,f=t===void 0?noop:t,r=_objectWithoutProperties(e,_excluded6);return function(e){try{if(!is_env(c)){c=s===true?user_env:s||user_env}if(l){s=c}else if(s===true){s=user_env}else{s=s||global_env}var t={env:s,dynamic_env:c,use_dynamic:l,error:f};var r;if(is_null(u)){return u}if(u instanceof LSymbol){return s.get(u)}if(!is_pair(u)){return u}var n=u.car;var e=u.cdr;if(is_pair(n)){r=resolve_promises(_evaluate(n,t));if(is_promise(r)){return r.then(function(e){if(!is_callable(e)){throw new Error(type(e)+" "+s.get("repr")(e)+" is not callable while evaluating "+u.toString())}return _evaluate(new Pair(e,u.cdr),t)})}else if(!is_callable(r)){throw new Error(type(r)+" "+s.get("repr")(r)+" is not callable while evaluating "+u.toString())}}if(n instanceof LSymbol){r=s.get(n)}else if(is_function(n)){r=n}var i;if(r instanceof Syntax){i=evaluate_syntax(r,u,t)}else if(r instanceof Macro){i=evaluate_macro(r,e,t)}else if(is_function(r)){i=apply(r,e,t)}else if(r instanceof SyntaxParameter){i=evaluate_syntax(r._syntax,u,t)}else if(is_parameter(r)){var a=search_param(c,r);if(is_null(u.cdr)){i=a.invoke()}else{return unpromise(_evaluate(u.cdr.car,t),function(e){a.__value__=e})}}else if(is_continuation(r)){i=r.invoke()}else if(is_pair(u)){r=n&&n.toString();throw new Error("".concat(type(n)," ").concat(r," is not a function"))}else{return u}var o=s.get(Symbol["for"]("__promise__"),{throwError:false});if(o===true&&is_promise(i)){i=i.then(function(e){if(is_pair(e)&&!r[__data__]){return _evaluate(e,t)}return e});return new QuotedPromise(i)}return i}catch(e){f&&f.call(s,e,u)}}(r)}var compile=exec_collect(function(e){return e});var exec=exec_collect(function(e,t){return t});function exec_with_stacktrace(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.env,n=t.dynamic_env,i=t.use_dynamic;return _evaluate(e,{env:r,dynamic_env:n,use_dynamic:i,error:function e(t,r){if(t&&t.message){if(t.message.match(/^Error:/)){var n=/^(Error:)\s*([^:]+:\s*)/;t.message=t.message.replace(n,"$1 $2")}if(r){if(!(t.__code__ instanceof Array)){t.__code__=[]}t.__code__.push(r.toString(true))}}if(!(t instanceof IgnoreException)){throw t}}})}function exec_collect(h){return function(){var t=_asyncToGenerator(function(f){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},_=e.env,p=e.dynamic_env,d=e.use_dynamic;return _regeneratorRuntime.mark(function e(){var r,n,i,a,o,u,s,c,l;return _regeneratorRuntime.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!is_env(p)){p=_===true?user_env:_||user_env}if(_===true){_=user_env}else{_=_||user_env}r=[];if(!is_pair(f)){t.next=8;break}t.next=6;return exec_with_stacktrace(code,{env:_,dynamic_env:p,use_dynamic:d});case 6:t.t0=t.sent;return t.abrupt("return",[t.t0]);case 8:n=Array.isArray(f)?f:_parse(f);i=false;a=false;t.prev=11;u=_asyncIterator(n);case 13:t.next=15;return u.next();case 15:if(!(i=!(s=t.sent).done)){t.next=31;break}c=s.value;t.next=19;return exec_with_stacktrace(c,{env:_,dynamic_env:p,use_dynamic:d});case 19:l=t.sent;t.t1=r;t.t2=h;t.t3=c;t.next=25;return l;case 25:t.t4=t.sent;t.t5=(0,t.t2)(t.t3,t.t4);t.t1.push.call(t.t1,t.t5);case 28:i=false;t.next=13;break;case 31:t.next=37;break;case 33:t.prev=33;t.t6=t["catch"](11);a=true;o=t.t6;case 37:t.prev=37;t.prev=38;if(!(i&&u["return"]!=null)){t.next=42;break}t.next=42;return u["return"]();case 42:t.prev=42;if(!a){t.next=45;break}throw o;case 45:return t.finish(42);case 46:return t.finish(37);case 47:return t.abrupt("return",r);case 48:case"end":return t.stop()}},e,null,[[11,33,37,47],[38,,42,46]])})()});function e(e){return t.apply(this,arguments)}return e}()}function balanced(e){var t={"[":"]","(":")"};var r;if(typeof e==="string"){r=tokenize(e)}else{r=e.map(function(e){return e&&e.token?e.token:e})}var n=Object.keys(t);var i=Object.values(t).concat(n);r=r.filter(function(e){return i.includes(e)});var a=new Stack;var o=_createForOfIteratorHelper(r),u;try{for(o.s();!(u=o.n()).done;){var s=u.value;if(n.includes(s)){a.push(s)}else if(!a.is_empty()){var c=a.top();var l=t[c];if(s===l){a.pop()}else{throw new Error("Syntax error: missing closing ".concat(l))}}else{throw new Error("Syntax error: not matched closing ".concat(s))}}}catch(e){o.e(e)}finally{o.f()}return a.is_empty()}function fworker(e){var t="("+e.toString()+")()";var r=window.URL||window.webkitURL;var n;try{n=new Blob([t],{type:"application/javascript"})}catch(e){var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;n=new i;n.append(t);n=n.getBlob()}return new root.Worker(r.createObjectURL(n))}function is_dev(){return lips.version.match(/^(\{\{VER\}\}|DEV)$/)}function get_current_script(){if(is_node()){return}var e;if(document.currentScript){e=document.currentScript}else{var t=document.querySelectorAll("script");if(!t.length){return}e=t[t.length-1]}var r=e.getAttribute("src");return r}var current_script=get_current_script();function bootstrap(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"";var t="dist/std.xcb";if(e===""){if(current_script){e=current_script.replace(/[^/]*$/,"std.xcb")}else if(is_dev()){e="https://cdn.jsdelivr.net/gh/jcubic/lips@devel/".concat(t)}else{e="https://cdn.jsdelivr.net/npm/@jcubic/lips@".concat(lips.version,"/").concat(t)}}var r=global_env.get("load");return r.call(user_env,e,global_env)}function Worker(e){this.url=e;var o=this.worker=fworker(function(){var o;var u;self.addEventListener("message",function(e){var r=e.data;var t=r.id;if(r.type!=="RPC"||t===null){return}function n(e){self.postMessage({id:t,type:"RPC",result:e})}function i(e){self.postMessage({id:t,type:"RPC",error:e})}if(r.method==="eval"){if(!u){i("Worker RPC: LIPS not initialized, call init first");return}u.then(function(){var e=r.params[0];var t=r.params[1];o.exec(e,{use_dynamic:t}).then(function(e){e=e.map(function(e){return e&&e.valueOf()});n(e)})["catch"](function(e){i(e)})})}else if(r.method==="init"){var a=r.params[0];if(typeof a!=="string"){i("Worker RPC: url is not a string")}else{importScripts("".concat(a,"/dist/lips.min.js"));o=new lips.Interpreter("worker");u=bootstrap(a);u.then(function(){n(true)})}}})});this.rpc=function(){var n=0;return function e(t,r){var a=++n;return new Promise(function(n,i){o.addEventListener("message",function e(t){var r=t.data;if(r&&r.type==="RPC"&&r.id===a){if(r.error){i(r.error)}else{n(r.result)}o.removeEventListener("message",e)}});o.postMessage({type:"RPC",method:t,id:a,params:r})})}}();this.rpc("init",[e])["catch"](function(e){console.error(e)});this.exec=function(e,t){var r=t.use_dynamic,n=r===void 0?false:r;return this.rpc("eval",[e,n])}}var serialization_map={pair:function e(t){var r=_slicedToArray(t,2),n=r[0],i=r[1];return Pair(n,i)},number:function e(t){if(LString.isString(t)){return LNumber([t,10])}return LNumber(t)},regex:function e(t){var r=_slicedToArray(t,2),n=r[0],i=r[1];return new RegExp(n,i)},nil:function e(){return _nil},symbol:function e(t){if(LString.isString(t)){return LSymbol(t)}else if(Array.isArray(t)){return LSymbol(Symbol["for"](t[0]))}},string:LString,character:LCharacter};var available_class=Object.keys(serialization_map);var class_map={};for(var _i6=0,_Object$entries3=Object.entries(available_class);_i6<_Object$entries3.length;_i6++){var _Object$entries3$_i=_slicedToArray(_Object$entries3[_i6],2),i=_Object$entries3$_i[0],cls=_Object$entries3$_i[1];class_map[cls]=+i}function mangle_name(e){return class_map[e]}function resolve_name(e){return available_class[e]}function serialize(e){return JSON.stringify(e,function(e,t){var r=this[e];if(r){if(r instanceof RegExp){return{"@":mangle_name("regex"),"#":[r.source,r.flags]}}var n=mangle_name(r.constructor.__class__);if(!is_undef(n)){return{"@":n,"#":r.serialize()}}}return t})}function unserialize(e){return JSON.parse(e,function(e,t){if(t&&_typeof$1(t)==="object"){if(!is_undef(t["@"])){var r=resolve_name(t["@"]);if(serialization_map[r]){return serialization_map[r](t["#"])}}}return t})}var cbor=function(){var e={pair:Pair,symbol:LSymbol,number:LNumber,string:LString,character:LCharacter,nil:_nil.constructor,regex:RegExp};function t(e,t){return{deserialize:t,Class:e}}var r=new Encoder;var a={};for(var n=0,i=Object.entries(serialization_map);n1){var n=t.reduce(function(e,t){return e+t.length},0);var i=new Uint8Array(n);var a=0;t.forEach(function(e){i.set(e,a);a+=e.length});return i}else if(t.length){return t[0]}}function encode_magic(){var e=1;var t=new TextEncoder("utf-8");return t.encode("LIPS".concat(e.toString().padStart(3," ")))}var MAGIC_LENGTH=7;function decode_magic(e){var t=new TextDecoder("utf-8");var r=t.decode(e.slice(0,MAGIC_LENGTH));var n=r.substring(0,4);if(n==="LIPS"){var i=r.match(/^(....).*([0-9]+)$/);if(i){return{type:i[1],version:Number(i[2])}}}return{type:"unknown"}}function serialize_bin(e){var t=encode_magic();var r=cbor.encode(e);return merge_uint8_array(t,pack_1(r,{magic:false}))}function unserialize_bin(e){var t=decode_magic(e),r=t.type,n=t.version;if(r==="LIPS"&&n===1){var i=unpack_1(e.slice(MAGIC_LENGTH),{magic:false});return cbor.decode(i)}else{throw new Error("Invalid file format ".concat(r))}}function execError(e){console.error(e.message||e);if(Array.isArray(e.code)){console.error(e.code.map(function(e,t){return"[".concat(t+1,"]: ").concat(e)}))}}function init(){var o=["text/x-lips","text/x-scheme"];var u;function s(e){var t;return(t=e.getAttribute("data-bootstrap"))!==null&&t!==void 0?t:e.getAttribute("bootstrap")}function c(r){return new Promise(function(t){var e=r.getAttribute("src");if(e){return fetch(e).then(function(e){return e.text()}).then(exec).then(t)["catch"](function(e){execError(e);t()})}else{return exec(r.innerHTML).then(t)["catch"](function(e){execError(e);t()})}})}function e(){return new Promise(function(i){var a=Array.from(document.querySelectorAll("script"));return function e(){var t=a.shift();if(!t){i()}else{var r=t.getAttribute("type");if(o.includes(r)){var n=s(t);if(!u&&typeof n==="string"){return bootstrap(n).then(function(){return c(t)}).then(e)}else{return c(t).then(e)}}else if(r&&r.match(/lips|lisp/)){console.warn("Expecting "+o.join(" or ")+" found "+r)}return e()}}()})}if(!window.document){return Promise.resolve()}else if(currentScript){var t=currentScript;var r=s(t);if(typeof r==="string"){return bootstrap(r).then(function(){u=true;return e()})}}return e()}var currentScript=typeof window!=="undefined"&&window.document&&document.currentScript;if(typeof window!=="undefined"){contentLoaded(window,init)}var banner=function(){var e=LString("Tue, 05 Mar 2024 15:58:24 +0000").valueOf();var t=e==="{{"+"DATE}}"?new Date:new Date(e);var r=function e(t){return t.toString().padStart(2,"0")};var n=t.getFullYear();var i=[n,r(t.getMonth()+1),r(t.getDate())].join("-");var a="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter DEV (".concat(i,") \nCopyright (c) 2018-").concat(n," Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables. You can also\nuse (help name) to display help for specific function or macro, (apropos name)\nto display list of matched names in environment and (dir object) to list\nproperties of an object.\n").replace(/^.*\n/,"");return a}();read_only(Ahead,"__class__","ahead");read_only(Pair,"__class__","pair");read_only(Nil,"__class__","nil");read_only(Pattern,"__class__","pattern");read_only(Formatter,"__class__","formatter");read_only(Macro,"__class__","macro");read_only(Syntax,"__class__","syntax");read_only(Syntax.Parameter,"__class__","syntax-parameter");read_only(Environment,"__class__","environment");read_only(InputPort,"__class__","input-port");read_only(OutputPort,"__class__","output-port");read_only(BufferedOutputPort,"__class__","output-port");read_only(OutputStringPort,"__class__","output-string-port");read_only(InputStringPort,"__class__","input-string-port");read_only(InputFilePort,"__class__","input-file-port");read_only(OutputFilePort,"__class__","output-file-port");read_only(LipsError,"__class__","lips-error");[LNumber,LComplex,LRational,LFloat,LBigInteger].forEach(function(e){read_only(e,"__class__","number")});read_only(LCharacter,"__class__","character");read_only(LSymbol,"__class__","symbol");read_only(LString,"__class__","string");read_only(QuotedPromise,"__class__","promise");read_only(Parameter,"__class__","parameter");var version="DEV";var date="Tue, 05 Mar 2024 15:58:24 +0000";var parse=compose(uniterate_async,_parse);var lips={version:version,banner:banner,date:date,exec:exec,parse:parse,tokenize:tokenize,evaluate:_evaluate,compile:compile,serialize:serialize,unserialize:unserialize,serialize_bin:serialize_bin,unserialize_bin:unserialize_bin,bootstrap:bootstrap,Environment:Environment,env:user_env,Worker:Worker,Interpreter:Interpreter,balanced_parenthesis:balanced,balancedParenthesis:balanced,balanced:balanced,Macro:Macro,Syntax:Syntax,Pair:Pair,Values:Values,QuotedPromise:QuotedPromise,Error:LipsError,quote:quote,InputPort:InputPort,OutputPort:OutputPort,BufferedOutputPort:BufferedOutputPort,InputFilePort:InputFilePort,OutputFilePort:OutputFilePort,InputStringPort:InputStringPort,OutputStringPort:OutputStringPort,InputByteVectorPort:InputByteVectorPort,OutputByteVectorPort:OutputByteVectorPort,InputBinaryFilePort:InputBinaryFilePort,OutputBinaryFilePort:OutputBinaryFilePort,set_fs:set_fs,Formatter:Formatter,Parser:Parser,Lexer:Lexer,specials:specials,repr:repr,nil:_nil,eof:eof,LSymbol:LSymbol,LNumber:LNumber,LFloat:LFloat,LComplex:LComplex,LRational:LRational,LBigInteger:LBigInteger,LCharacter:LCharacter,LString:LString,Parameter:Parameter,rationalize:rationalize};global_env.set("lips",lips);export{BufferedOutputPort,Environment,LipsError as Error,Formatter,InputBinaryFilePort,InputByteVectorPort,InputFilePort,InputPort,InputStringPort,Interpreter,LBigInteger,LCharacter,LComplex,LFloat,LNumber,LRational,LString,LSymbol,Lexer,Macro,OutputBinaryFilePort,OutputByteVectorPort,OutputFilePort,OutputPort,OutputStringPort,Pair,Parameter,Parser,QuotedPromise,Syntax,Values,Worker,balanced,balanced as balancedParenthesis,balanced as balanced_parenthesis,banner,bootstrap,compile,date,user_env as env,eof,_evaluate as evaluate,exec,_nil as nil,parse,quote,rationalize,repr,serialize,serialize_bin,set_fs,specials,tokenize,unserialize,unserialize_bin,version}; \ No newline at end of file diff --git a/dist/lips.js b/dist/lips.js index 2e77db57..33aa9802 100644 --- a/dist/lips.js +++ b/dist/lips.js @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Tue, 05 Mar 2024 13:03:01 +0000 + * build: Tue, 05 Mar 2024 15:58:24 +0000 */ (function (global, factory) { @@ -13305,6 +13305,18 @@ typecheck('replace', pattern, ['regex', 'string']); typecheck('replace', replacement, ['string', 'function']); typecheck('replace', string, 'string'); + if (is_function(replacement)) { + // ref: https://stackoverflow.com/a/48032528/387194 + var replacements = []; + string.replace(pattern, function () { + replacements.push(replacement.apply(void 0, arguments)); + }); + return unpromise(replacements, function (replacements) { + return string.replace(pattern, function () { + return replacements.shift(); + }); + }); + } return string.replace(pattern, replacement); }, "(replace pattern replacement string)\n\n Function that changes pattern to replacement inside string. Pattern can be a\n string or regex and replacement can be function or string. See Javascript\n String.replace()."), // ------------------------------------------------------------------ @@ -15586,10 +15598,10 @@ // ------------------------------------------------------------------------- var banner = function () { // Rollup tree-shaking is removing the variable if it's normal string because - // obviously 'Tue, 05 Mar 2024 13:03:01 +0000' == '{{' + 'DATE}}'; can be removed + // obviously 'Tue, 05 Mar 2024 15:58:24 +0000' == '{{' + 'DATE}}'; can be removed // but disabling Tree-shaking is adding lot of not used code so we use this // hack instead - var date = LString('Tue, 05 Mar 2024 13:03:01 +0000').valueOf(); + var date = LString('Tue, 05 Mar 2024 15:58:24 +0000').valueOf(); var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date); var _format = function _format(x) { return x.toString().padStart(2, '0'); @@ -15629,7 +15641,7 @@ read_only(Parameter, '__class__', 'parameter'); // ------------------------------------------------------------------------- var version = 'DEV'; - var date = 'Tue, 05 Mar 2024 13:03:01 +0000'; + var date = 'Tue, 05 Mar 2024 15:58:24 +0000'; // unwrap async generator into Promise var parse = compose(uniterate_async, _parse); diff --git a/dist/lips.min.js b/dist/lips.min.js index edbae71f..3bb1d7a6 100644 --- a/dist/lips.min.js +++ b/dist/lips.min.js @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Tue, 05 Mar 2024 13:03:01 +0000 + * build: Tue, 05 Mar 2024 15:58:24 +0000 */ (function(e,t){typeof exports==="object"&&typeof module!=="undefined"?t(exports):typeof define==="function"&&define.amd?define(["exports"],t):(e=typeof globalThis!=="undefined"?globalThis:e||self,t(e.lips={}))})(this,function(e){"use strict";var o=typeof document!=="undefined"?document.currentScript:null;function n(e,t){if(t.get){return t.get.call(e)}return t.value}function i(e,t,r){if(!t.has(e)){throw new TypeError("attempted to "+r+" private field on non-instance")}return t.get(e)}function t(e,t){var r=i(e,t,"get");return n(e,r)}function a(e,t,r){if(t.set){t.set.call(e,r)}else{if(!t.writable){throw new TypeError("attempted to set read only private field")}t.value=r}}function f(e,t,r){var n=i(e,t,"set");a(e,n,r);return r}function I(e){I=Object.setPrototypeOf?Object.getPrototypeOf.bind():function e(t){return t.__proto__||Object.getPrototypeOf(t)};return I(e)}function P(e,t){P=Object.setPrototypeOf?Object.setPrototypeOf.bind():function e(t,r){t.__proto__=r;return t};return P(e,t)}function N(t){try{return Function.toString.call(t).indexOf("[native code]")!==-1}catch(e){return typeof t==="function"}}function T(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(T=function e(){return!!t})()}function L(e,t,r){if(T())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,t);var i=new(e.bind.apply(e,n));return r&&P(i,r.prototype),i}function r(e){var n=typeof Map==="function"?new Map:undefined;r=function e(t){if(t===null||!N(t))return t;if(typeof t!=="function"){throw new TypeError("Super expression must either be null or a function")}if(typeof n!=="undefined"){if(n.has(t))return n.get(t);n.set(t,r)}function r(){return L(t,arguments,I(this).constructor)}r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:false,writable:true,configurable:true}});return P(r,t)};return r(e)}function _(e){"@babel/helpers - typeof";return _="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_(e)}function M(e){if(e===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return e}function R(e,t){if(t&&(_(t)==="object"||typeof t==="function")){return t}else if(t!==void 0){throw new TypeError("Derived constructors may only return object or undefined")}return M(e)}function W(e,t){if(typeof t!=="function"&&t!==null){throw new TypeError("Super expression must either be null or a function")}e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:true,configurable:true}});Object.defineProperty(e,"prototype",{writable:false});if(t)P(e,t)}function Q(e){if(Array.isArray(e))return e}function Z(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function X(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r=0)continue;r[i]=e[i]}return r}function he(e,t){if(e==null)return{};var r=le(e,t);var n,i;if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);for(i=0;i=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,n))continue;r[n]=e[n]}}return r}function _e(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,u,a,o=[],s=!0,c=!1;try{if(u=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=u.call(r)).done)&&(o.push(n.value),o.length!==t);s=!0);}catch(e){c=!0,i=e}finally{try{if(!s&&null!=r["return"]&&(a=r["return"](),Object(a)!==a))return}finally{if(c)throw i}}return o}}function b(e,t){return Q(e)||_e(e,t)||ee(e,t)||te()}function pe(e){if(Array.isArray(e))return X(e)}function de(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function q(e){return pe(e)||Z(e)||ee(e)||de()}function ve(e,t){this.v=e,this.k=t}function me(e){return new ve(e,0)}function ye(a){var u,o;function s(r,e){try{var n=a[r](e),i=n.value,u=i instanceof ve;Promise.resolve(u?i.v:i).then(function(e){if(u){var t="return"===r?"return":"next";if(!i.k||e.done)return s(t,e);e=a[t](e).value}c(n.done?"return":"normal",e)},function(e){s("throw",e)})}catch(e){c("throw",e)}}function c(e,t){switch(e){case"return":u.resolve({value:t,done:!0});break;case"throw":u.reject(t);break;default:u.resolve({value:t,done:!1})}(u=u.next)?s(u.key,u.arg):o=null}this._invoke=function(n,i){return new Promise(function(e,t){var r={key:n,arg:i,resolve:e,reject:t,next:null};o?o=o.next=r:(u=o=r,s(n,i))})},"function"!=typeof a["return"]&&(this["return"]=void 0)}ye.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},ye.prototype.next=function(e){return this._invoke("next",e)},ye.prototype["throw"]=function(e){return this._invoke("throw",e)},ye.prototype["return"]=function(e){return this._invoke("return",e)};function ge(e){return function(){return new ye(e.apply(this,arguments))}}function be(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e["default"]:e}var we={exports:{}};var De={exports:{}};(function(t){function r(e){"@babel/helpers - typeof";return t.exports=r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t.exports.__esModule=true,t.exports["default"]=t.exports,r(e)}t.exports=r,t.exports.__esModule=true,t.exports["default"]=t.exports})(De);var xe=De.exports;(function(B){var I=xe["default"];function P(){B.exports=P=function e(){return a},B.exports.__esModule=true,B.exports["default"]=B.exports;var c,a={},e=Object.prototype,f=e.hasOwnProperty,l=Object.defineProperty||function(e,t,r){e[t]=r.value},t="function"==typeof Symbol?Symbol:{},i=t.iterator||"@@iterator",r=t.asyncIterator||"@@asyncIterator",n=t.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(c){u=function e(t,r,n){return t[r]=n}}function o(e,t,r,n){var i=t&&t.prototype instanceof s?t:s,u=Object.create(i.prototype),a=new S(n||[]);return l(u,"_invoke",{value:A(e,r,a)}),u}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}a.wrap=o;var _="suspendedStart",p="suspendedYield",d="executing",v="completed",m={};function s(){}function y(){}function g(){}var b={};u(b,i,function(){return this});var w=Object.getPrototypeOf,D=w&&w(w(j([])));D&&D!==e&&f.call(D,i)&&(b=D);var x=g.prototype=s.prototype=Object.create(b);function E(e){["next","throw","return"].forEach(function(t){u(e,t,function(e){return this._invoke(t,e)})})}function F(o,s){function c(e,t,r,n){var i=h(o[e],o,t);if("throw"!==i.type){var u=i.arg,a=u.value;return a&&"object"==I(a)&&f.call(a,"__await")?s.resolve(a.__await).then(function(e){c("next",e,r,n)},function(e){c("throw",e,r,n)}):s.resolve(a).then(function(e){u.value=e,r(u)},function(e){return c("throw",e,r,n)})}n(i.arg)}var i;l(this,"_invoke",{value:function e(r,n){function t(){return new s(function(e,t){c(r,n,e,t)})}return i=i?i.then(t,t):t()}})}function A(u,a,o){var s=_;return function(e,t){if(s===d)throw new Error("Generator is already running");if(s===v){if("throw"===e)throw t;return{value:c,done:!0}}for(o.method=e,o.arg=t;;){var r=o.delegate;if(r){var n=k(r,o);if(n){if(n===m)continue;return n}}if("next"===o.method)o.sent=o._sent=o.arg;else if("throw"===o.method){if(s===_)throw s=v,o.arg;o.dispatchException(o.arg)}else"return"===o.method&&o.abrupt("return",o.arg);s=d;var i=h(u,a,o);if("normal"===i.type){if(s=o.done?v:p,i.arg===m)continue;return{value:i.arg,done:o.done}}"throw"===i.type&&(s=v,o.method="throw",o.arg=i.arg)}}}function k(e,t){var r=t.method,n=e.iterator[r];if(n===c)return t.delegate=null,"throw"===r&&e.iterator["return"]&&(t.method="return",t.arg=c,k(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),m;var i=h(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,m;var u=i.arg;return u?u.done?(t[e.resultName]=u.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=c),t.delegate=null,m):u:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,m)}function O(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function C(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function S(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function j(t){if(t||""===t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,n=function e(){for(;++r=0;--i){var u=this.tryEntries[i],a=u.completion;if("root"===u.tryLoc)return t("end");if(u.tryLoc<=this.prev){var o=f.call(u,"catchLoc"),s=f.call(u,"finallyLoc");if(o&&s){if(this.prev=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&f.call(i,"finallyLoc")&&this.prev=0;--r){var n=this.tryEntries[r];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),C(n),m}},catch:function e(t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc===t){var i=n.completion;if("throw"===i.type){var u=i.arg;C(n)}return u}}throw new Error("illegal catch attempt")},delegateYield:function e(t,r,n){return this.delegate={iterator:j(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=c),m}},a}B.exports=P,B.exports.__esModule=true,B.exports["default"]=B.exports})(we);var Ee=we.exports;var Fe=Ee();var Ae=Fe;try{regeneratorRuntime=Fe}catch(e){if(typeof globalThis==="object"){globalThis.regeneratorRuntime=Fe}else{Function("r","regeneratorRuntime = r")(Fe)}}var O=be(Ae);let ke;try{ke=new TextDecoder}catch(e){}let v;let Oe;let m=0;const Ce=105;const Se=57342;const je=57343;const Be=57337;const Ie=6;const Pe={};let p={};let Ne;let Te;let Le=0;let Me=0;let Re;let qe;let Ue=[];let ze=[];let Ve;let $e;let Ye;let Je={useRecords:false,mapsAsObjects:true};let Ke=false;let He=2;try{new Function("")}catch(e){He=Infinity}class Ge{constructor(r){if(r){if((r.keyMap||r._keyMap)&&!r.useRecords){r.useRecords=false;r.mapsAsObjects=true}if(r.useRecords===false&&r.mapsAsObjects===undefined)r.mapsAsObjects=true;if(r.getStructures)r.getShared=r.getStructures;if(r.getShared&&!r.structures)(r.structures=[]).uninitialized=true;if(r.keyMap){this.mapKey=new Map;for(let[e,t]of Object.entries(r.keyMap))this.mapKey.set(t,e)}}Object.assign(this,r)}decodeKey(e){return this.keyMap?this.mapKey.get(e)||e:e}encodeKey(e){return this.keyMap&&this.keyMap.hasOwnProperty(e)?this.keyMap[e]:e}encodeKeys(r){if(!this._keyMap)return r;let n=new Map;for(let[e,t]of Object.entries(r))n.set(this._keyMap.hasOwnProperty(e)?this._keyMap[e]:e,t);return n}decodeKeys(e){if(!this._keyMap||e.constructor.name!="Map")return e;if(!this._mapKey){this._mapKey=new Map;for(let[e,t]of Object.entries(this._keyMap))this._mapKey.set(t,e)}let r={};e.forEach((e,t)=>r[Xe(this._mapKey.has(t)?this._mapKey.get(t):t)]=e);return r}mapDecode(e,t){let r=this.decode(e);if(this._keyMap){switch(r.constructor.name){case"Array":return r.map(e=>this.decodeKeys(e))}}return r}decode(t,e){if(v){return xt(()=>{Et();return this?this.decode(t,e):Ge.prototype.decode.call(Je,t,e)})}Oe=e>-1?e:t.length;m=0;Me=0;Te=null;Re=null;v=t;try{$e=t.dataView||(t.dataView=new DataView(t.buffer,t.byteOffset,t.byteLength))}catch(e){v=null;if(t instanceof Uint8Array)throw e;throw new Error("Source must be a Uint8Array or Buffer but was a "+(t&&typeof t=="object"?t.constructor.name:typeof t))}if(this instanceof Ge){p=this;Ve=this.sharedValues&&(this.pack?new Array(this.maxPrivatePackedValues||16).concat(this.sharedValues):this.sharedValues);if(this.structures){Ne=this.structures;return We()}else if(!Ne||Ne.length>0){Ne=[]}}else{p=Je;if(!Ne||Ne.length>0)Ne=[];Ve=null}return We()}decodeMultiple(r,n){let i,u=0;try{let e=r.length;Ke=true;let t=this?this.decode(r,e):kt.decode(r,e);if(n){if(n(t)===false){return}while(m=Re.postBundlePosition){let e=new Error("Unexpected bundle position");e.incomplete=true;throw e}m=Re.postBundlePosition;Re=null}if(m==Oe){Ne=null;v=null;if(qe)qe=null}else if(m>Oe){let e=new Error("Unexpected end of CBOR data");e.incomplete=true;throw e}else if(!Ke){throw new Error("Data read, but end of buffer not reached")}return e}catch(e){Et();if(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer")){e.incomplete=true}throw e}}function u(){let n=v[m++];let i=n>>5;n=n&31;if(n>23){switch(n){case 24:n=v[m++];break;case 25:if(i==7){return st()}n=$e.getUint16(m);m+=2;break;case 26:if(i==7){let t=$e.getFloat32(m);if(p.useFloat32>2){let e=At[(v[m]&127)<<1|v[m+1]>>7];m+=4;return(e*t+(t>0?.5:-.5)>>0)/e}m+=4;return t}n=$e.getUint32(m);m+=4;break;case 27:if(i==7){let e=$e.getFloat64(m);m+=8;return e}if(i>1){if($e.getUint32(m)>0)throw new Error("JavaScript does not support arrays, maps, or strings with length over 4294967295");n=$e.getUint32(m+4)}else if(p.int64AsNumber){n=$e.getUint32(m)*4294967296;n+=$e.getUint32(m+4)}else n=$e.getBigUint64(m);m+=8;break;case 31:switch(i){case 2:case 3:throw new Error("Indefinite length not supported for byte or text strings");case 4:let e=[];let t,r=0;while((t=u())!=Pe){e[r++]=t}return i==4?e:i==3?e.join(""):Buffer.concat(e);case 5:let n;if(p.mapsAsObjects){let e={};if(p.keyMap)while((n=u())!=Pe)e[Xe(p.decodeKey(n))]=u();else while((n=u())!=Pe)e[Xe(n)]=u();return e}else{if(Ye){p.mapsAsObjects=true;Ye=false}let e=new Map;if(p.keyMap)while((n=u())!=Pe)e.set(p.decodeKey(n),u());else while((n=u())!=Pe)e.set(n,u());return e}case 7:return Pe;default:throw new Error("Invalid major type for indefinite length "+i)}default:throw new Error("Unknown token "+n)}}switch(i){case 0:return n;case 1:return~n;case 2:return ut(n);case 3:if(Me>=m){return Te.slice(m-Le,(m+=n)-Le)}if(Me==0&&Oe<140&&n<32){let e=n<16?it(n):nt(n);if(e!=null)return e}return et(n);case 4:let t=new Array(n);for(let e=0;e=Be){let e=Ne[n&8191];if(e){if(!e.read)e.read=Ze(e);return e.read()}if(n<65536){if(n==je){let e=wt();let t=u();let r=u();ft(t,r);let n={};if(p.keyMap)for(let t=2;t23){switch(t){case 24:t=v[m++];break;case 25:t=$e.getUint16(m);m+=2;break;case 26:t=$e.getUint32(m);m+=4;break;default:throw new Error("Expected array header, but got "+v[m-1])}}let r=this.compiledReader;while(r){if(r.propertyCount===t)return r(u);r=r.next}if(this.slowReads++>=He){let e=this.length==t?this:this.slice(0,t);r=p.keyMap?new Function("r","return {"+e.map(e=>p.decodeKey(e)).map(e=>Qe.test(e)?Xe(e)+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"}"):new Function("r","return {"+e.map(e=>Qe.test(e)?Xe(e)+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"}");if(this.compiledReader)r.next=this.compiledReader;r.propertyCount=t;this.compiledReader=r;return r(u)}let n={};if(p.keyMap)for(let e=0;e64&&ke)return ke.decode(v.subarray(m,m+=e));const r=m+e;const n=[];t="";while(m65535){e-=65536;n.push(e>>>10&1023|55296);e=56320|e&1023}n.push(e)}else{n.push(i)}if(n.length>=4096){t+=rt.apply(String,n);n.length=0}}if(n.length>0){t+=rt.apply(String,n)}return t}let rt=String.fromCharCode;function nt(t){let r=m;let n=new Array(t);for(let e=0;e0){m=r;return}n[e]=i}return rt.apply(String,n)}function it(d){if(d<4){if(d<2){if(d===0)return"";else{let e=v[m++];if((e&128)>1){m-=1;return}return rt(e)}}else{let e=v[m++];let t=v[m++];if((e&128)>0||(t&128)>0){m-=2;return}if(d<3)return rt(e,t);let r=v[m++];if((r&128)>0){m-=3;return}return rt(e,t,r)}}else{let l=v[m++];let h=v[m++];let _=v[m++];let p=v[m++];if((l&128)>0||(h&128)>0||(_&128)>0||(p&128)>0){m-=4;return}if(d<6){if(d===4)return rt(l,h,_,p);else{let e=v[m++];if((e&128)>0){m-=5;return}return rt(l,h,_,p,e)}}else if(d<8){let e=v[m++];let t=v[m++];if((e&128)>0||(t&128)>0){m-=6;return}if(d<7)return rt(l,h,_,p,e,t);let r=v[m++];if((r&128)>0){m-=7;return}return rt(l,h,_,p,e,t,r)}else{let o=v[m++];let s=v[m++];let c=v[m++];let f=v[m++];if((o&128)>0||(s&128)>0||(c&128)>0||(f&128)>0){m-=8;return}if(d<10){if(d===8)return rt(l,h,_,p,o,s,c,f);else{let e=v[m++];if((e&128)>0){m-=9;return}return rt(l,h,_,p,o,s,c,f,e)}}else if(d<12){let e=v[m++];let t=v[m++];if((e&128)>0||(t&128)>0){m-=10;return}if(d<11)return rt(l,h,_,p,o,s,c,f,e,t);let r=v[m++];if((r&128)>0){m-=11;return}return rt(l,h,_,p,o,s,c,f,e,t,r)}else{let n=v[m++];let i=v[m++];let u=v[m++];let a=v[m++];if((n&128)>0||(i&128)>0||(u&128)>0||(a&128)>0){m-=12;return}if(d<14){if(d===12)return rt(l,h,_,p,o,s,c,f,n,i,u,a);else{let e=v[m++];if((e&128)>0){m-=13;return}return rt(l,h,_,p,o,s,c,f,n,i,u,a,e)}}else{let e=v[m++];let t=v[m++];if((e&128)>0||(t&128)>0){m-=14;return}if(d<15)return rt(l,h,_,p,o,s,c,f,n,i,u,a,e,t);let r=v[m++];if((r&128)>0){m-=15;return}return rt(l,h,_,p,o,s,c,f,n,i,u,a,e,t,r)}}}}}function ut(e){return p.copyBuffers?Uint8Array.prototype.slice.call(v,m,m+=e):v.subarray(m,m+=e)}let at=new Float32Array(1);let ot=new Uint8Array(at.buffer,0,4);function st(){let t=v[m++];let r=v[m++];let e=(t&127)>>2;if(e===31){if(r||t&3)return NaN;return t&128?-Infinity:Infinity}if(e===0){let e=((t&3)<<8|r)/(1<<24);return t&128?-e:e}ot[3]=t&128|(e>>1)+56;ot[2]=(t&7)<<5|r>>3;ot[1]=r<<5;ot[0]=0;return at[0]}new Array(4096);class ct{constructor(e,t){this.value=e;this.tag=t}}Ue[0]=e=>{return new Date(e)};Ue[1]=e=>{return new Date(Math.round(e*1e3))};Ue[2]=r=>{let n=BigInt(0);for(let e=0,t=r.byteLength;e{return BigInt(-1)-Ue[2](e)};Ue[4]=e=>{return+(e[1]+"e"+e[0])};Ue[5]=e=>{return e[1]*Math.exp(e[0]*Math.log(2))};const ft=(e,t)=>{e=e-57344;let r=Ne[e];if(r&&r.isShared){(Ne.restoreStructures||(Ne.restoreStructures=[]))[e]=r}Ne[e]=t;t.read=Ze(t)};Ue[Ce]=r=>{let e=r.length;let n=r[1];ft(r[0],n);let i={};for(let t=2;t{if(Re)return Re[0].slice(Re.position0,Re.position0+=e);return new ct(e,14)};Ue[15]=e=>{if(Re)return Re[1].slice(Re.position1,Re.position1+=e);return new ct(e,15)};let lt={Error:Error,RegExp:RegExp};Ue[27]=e=>{return(lt[e[0]]||Error)(e[1],e[2])};const ht=e=>{if(v[m++]!=132){let e=new Error("Packed values structure must be followed by a 4 element array");if(v.length{if(!Ve){if(p.getShared)Dt();else return new ct(e,Ie)}if(typeof e=="number")return Ve[16+(e>=0?2*e:-2*e-1)];let t=new Error("No support for non-integer packed references yet");if(e===undefined)t.incomplete=true;throw t};Ue[28]=e=>{if(!qe){qe=new Map;qe.id=0}let t=qe.id++;let r=v[m];let n;if(r>>5==4)n=[];else n={};let i={target:n};qe.set(t,i);let u=e();if(i.used)return Object.assign(n,u);i.target=u;return u};Ue[28].handlesRead=true;Ue[29]=e=>{let t=qe.get(e);t.used=true;return t.target};Ue[258]=e=>new Set(e);(Ue[259]=e=>{if(p.mapsAsObjects){p.mapsAsObjects=false;Ye=true}return e()}).handlesRead=true;function _t(e,t){if(typeof e==="string")return e+t;if(e instanceof Array)return e.concat(t);return Object.assign({},e,t)}function pt(){if(!Ve){if(p.getShared)Dt();else throw new Error("No packed values available")}return Ve}const dt=1399353956;ze.push((e,t)=>{if(e>=225&&e<=255)return _t(pt().prefixes[e-224],t);if(e>=28704&&e<=32767)return _t(pt().prefixes[e-28672],t);if(e>=1879052288&&e<=2147483647)return _t(pt().prefixes[e-1879048192],t);if(e>=216&&e<=223)return _t(t,pt().suffixes[e-216]);if(e>=27647&&e<=28671)return _t(t,pt().suffixes[e-27639]);if(e>=1811940352&&e<=1879048191)return _t(t,pt().suffixes[e-1811939328]);if(e==dt){return{packedValues:Ve,structures:Ne.slice(0),version:t}}if(e==55799)return t});const vt=new Uint8Array(new Uint16Array([1]).buffer)[0]==1;const mt=[Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array=="undefined"?{name:"BigUint64Array"}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array=="undefined"?{name:"BigInt64Array"}:BigInt64Array,Float32Array,Float64Array];const yt=[64,68,69,70,71,72,77,78,79,85,86];for(let e=0;e{if(!o)throw new Error("Could not find typed array for code "+s);if(!p.copyBuffers){if(t===1||t===2&&!(e.byteOffset&1)||t===4&&!(e.byteOffset&3)||t===8&&!(e.byteOffset&7))return new o(e.buffer,e.byteOffset,e.byteLength)}return new o(Uint8Array.prototype.slice.call(e,0).buffer)}:e=>{if(!o)throw new Error("Could not find typed array for code "+s);let t=new DataView(e.buffer,e.byteOffset,e.byteLength);let r=e.length>>u;let n=new o(r);let i=t[c];for(let e=0;e23){switch(e){case 24:e=v[m++];break;case 25:e=$e.getUint16(m);m+=2;break;case 26:e=$e.getUint32(m);m+=4;break}}return e}function Dt(){if(p.getShared){let e=xt(()=>{v=null;return p.getShared()})||{};let t=e.structures||[];p.sharedVersion=e.version;Ve=p.sharedValues=e.packedValues;if(Ne===true)p.structures=Ne=t;else Ne.splice.apply(Ne,[0,t.length].concat(t))}}function xt(e){let t=Oe;let r=m;let n=Le;let i=Me;let u=Te;let a=qe;let o=Re;let s=new Uint8Array(v.slice(0,Oe));let c=Ne;let f=p;let l=Ke;let h=e();Oe=t;m=r;Le=n;Me=i;Te=u;qe=a;Re=o;v=s;Ke=l;Ne=c;p=f;$e=new DataView(v.buffer,v.byteOffset,v.byteLength);return h}function Et(){v=null;qe=null;Ne=null}function Ft(e){Ue[e.tag]=e.decode}const At=new Array(147);for(let e=0;e<256;e++){At[e]=+("1e"+Math.floor(45.15-e*.30103))}let kt=new Ge({useRecords:false});kt.decode;kt.decodeMultiple;let Ot;try{Ot=new TextEncoder}catch(e){}let Ct,St;const jt=typeof globalThis==="object"&&globalThis.Buffer;const Bt=typeof jt!=="undefined";const It=Bt?jt.allocUnsafeSlow:Uint8Array;const Pt=Bt?jt:Uint8Array;const Nt=256;const Tt=Bt?4294967296:2144337920;let Lt;let C;let S;let j=0;let Mt;let Rt=null;const qt=61440;const Ut=/[\u0080-\uFFFF]/;const zt=Symbol("record-id");class Vt extends Ge{constructor(r){super(r);this.offset=0;let s;let a;let f;let l;let n;r=r||{};let c=Pt.prototype.utf8Write?function(e,t,r){return C.utf8Write(e,t,r)}:Ot&&Ot.encodeInto?function(e,t){return Ot.encodeInto(e,C.subarray(t)).written}:false;let u=this;let e=r.structures||r.saveStructures;let h=r.maxSharedStructures;if(h==null)h=e?128:0;if(h>8190)throw new Error("Maximum maxSharedStructure is 8190");let i=r.sequential;if(i){h=0}if(!this.structures)this.structures=[];if(this.saveStructures)this.saveShared=this.saveStructures;let _,p,o=r.sharedValues;let d;if(o){d=Object.create(null);for(let e=0,t=o.length;ethis.encodeKeys(e));break}}return this.encode(e,t)};this.encode=function(t,e){if(!C){C=new It(8192);S=new DataView(C.buffer,0,8192);j=0}Mt=C.length-10;if(Mt-j<2048){C=new It(C.length);S=new DataView(C.buffer,0,C.length);Mt=C.length-10;j=0}else if(e===nr)j=j+7&2147483640;s=j;if(u.useSelfDescribedHeader){S.setUint32(j,3654940416);j+=3}n=u.structuredClone?new Map:null;if(u.bundleStrings&&typeof t!=="string"){Rt=[];Rt.size=Infinity}else Rt=null;a=u.structures;if(a){if(a.uninitialized){let e=u.getShared()||{};u.structures=a=e.structures||[];u.sharedVersion=e.version;let r=u.sharedValues=e.packedValues;if(r){d={};for(let e=0,t=r.length;eh&&!i)e=h;if(!a.transitions){a.transitions=Object.create(null);for(let u=0;u0){C[j++]=216;C[j++]=51;Jt(4);let r=e.values;g(r);Jt(0);Jt(0);p=Object.create(d||null);for(let e=0,t=r.length;eMt)w(j);u.offset=j;let e=Xt(C.subarray(s,j),n.idsToInsert);n=null;return e}if(e&nr){C.start=s;C.end=j;return C}return C.subarray(s,j)}finally{if(a){if(y<10)y++;if(a.length>h)a.length=h;if(m>1e4){a.transitions=null;y=0;m=0;if(v.length>0)v=[]}else if(v.length>0&&!i){for(let e=0,t=v.length;eh){u.structures=u.structures.slice(0,h)}let e=C.subarray(s,j);if(u.updateSharedData()===false)return u.encode(t);return e}if(e&ir)j=s}};this.findCommonStringsToPack=()=>{_=new Map;if(!d)d=Object.create(null);return e=>{let r=e&&e.threshold||4;let n=this.pack?e.maxPrivatePackedValues||16:0;if(!o)o=this.sharedValues=[];for(let[e,t]of _){if(t.count>r){d[e]=n++;o.push(e);f=true}}while(this.saveShared&&this.updateSharedData()===false){}_=null}};const g=a=>{if(j>Mt)C=w(j);var e=typeof a;var o;if(e==="string"){if(p){let e=p[a];if(e>=0){if(e<16)C[j++]=e+224;else{C[j++]=198;if(e&1)g(15-e>>1);else g(e-16>>1)}return}else if(_&&!r.pack){let e=_.get(a);if(e)e.count++;else _.set(a,{count:1})}}let i=a.length;if(Rt&&i>=4&&i<1024){if((Rt.size+=i)>qt){let e;let t=(Rt[0]?Rt[0].length*3+Rt[1].length:0)+10;if(j+t>Mt)C=w(j+t);C[j++]=217;C[j++]=223;C[j++]=249;C[j++]=Rt.position?132:130;C[j++]=26;e=j-s;j+=4;if(Rt.position){er(s,g)}Rt=["",""];Rt.size=0;Rt.position=e}let e=Ut.test(a);Rt[e?0:1]+=a;C[j++]=e?206:207;g(i);return}let u;if(i<32){u=1}else if(i<256){u=2}else if(i<65536){u=3}else{u=5}let e=i*3;if(j+e>Mt)C=w(j+e);if(i<64||!c){let e,t,r,n=j+u;for(e=0;e>6|192;C[n++]=t&63|128}else if((t&64512)===55296&&((r=a.charCodeAt(e+1))&64512)===56320){t=65536+((t&1023)<<10)+(r&1023);e++;C[n++]=t>>18|240;C[n++]=t>>12&63|128;C[n++]=t>>6&63|128;C[n++]=t&63|128}else{C[n++]=t>>12|224;C[n++]=t>>6&63|128;C[n++]=t&63|128}}o=n-j-u}else{o=c(a,j+u,e)}if(o<24){C[j++]=96|o}else if(o<256){if(u<2){C.copyWithin(j+2,j+1,j+1+o)}C[j++]=120;C[j++]=o}else if(o<65536){if(u<3){C.copyWithin(j+3,j+2,j+2+o)}C[j++]=121;C[j++]=o>>8;C[j++]=o&255}else{if(u<5){C.copyWithin(j+5,j+3,j+3+o)}C[j++]=122;S.setUint32(j,o);j+=4}j+=o}else if(e==="number"){if(!this.alwaysUseFloat&&a>>>0===a){if(a<24){C[j++]=a}else if(a<256){C[j++]=24;C[j++]=a}else if(a<65536){C[j++]=25;C[j++]=a>>8;C[j++]=a&255}else{C[j++]=26;S.setUint32(j,a);j+=4}}else if(!this.alwaysUseFloat&&a>>0===a){if(a>=-24){C[j++]=31-a}else if(a>=-256){C[j++]=56;C[j++]=~a}else if(a>=-65536){C[j++]=57;S.setUint16(j,~a);j+=2}else{C[j++]=58;S.setUint32(j,~a);j+=4}}else{let t;if((t=this.useFloat32)>0&&a<4294967296&&a>=-2147483648){C[j++]=250;S.setFloat32(j,a);let e;if(t<4||(e=a*At[(C[j]&127)<<1|C[j+1]>>7])>>0===e){j+=4;return}else j--}C[j++]=251;S.setFloat64(j,a);j+=8}}else if(e==="object"){if(!a)C[j++]=246;else{if(n){let t=n.get(a);if(t){C[j++]=216;C[j++]=29;C[j++]=25;if(!t.references){let e=n.idsToInsert||(n.idsToInsert=[]);t.references=[];e.push(t)}t.references.push(j-s);j+=2;return}else n.set(a,{offset:j-s})}let e=a.constructor;if(e===Object){b(a,true)}else if(e===Array){o=a.length;if(o<24){C[j++]=128|o}else{Jt(o)}for(let e=0;e>8;C[j++]=o&255}else{C[j++]=186;S.setUint32(j,o);j+=4}if(u.keyMap){for(let[e,t]of a){g(u.encodeKey(e));g(t)}}else{for(let[e,t]of a){g(e);g(t)}}}else{for(let r=0,e=Ct.length;r>8;C[j++]=t&255}else if(t>-1){C[j++]=218;S.setUint32(j,t);j+=4}e.encode.call(this,a,g,w);return}}if(a[Symbol.iterator]){if(Lt){let e=new Error("Iterable should be serialized as iterator");e.iteratorNotHandled=true;throw e}C[j++]=159;for(let e of a){g(e)}C[j++]=255;return}if(a[Symbol.asyncIterator]||Ht(a)){let e=new Error("Iterable/blob should be serialized as iterator");e.iteratorNotHandled=true;throw e}if(this.useToJSON&&a.toJSON){const t=a.toJSON();if(t!==a)return g(t)}b(a,!a.hasOwnProperty)}}}else if(e==="boolean"){C[j++]=a?245:244}else if(e==="bigint"){if(a=0){C[j++]=27;S.setBigUint64(j,a)}else if(a>-(BigInt(1)<{let t=Object.keys(e);let r=Object.values(e);let n=t.length;if(n<24){C[j++]=160|n}else if(n<256){C[j++]=184;C[j++]=n}else if(n<65536){C[j++]=185;C[j++]=n>>8;C[j++]=n&255}else{C[j++]=186;S.setUint32(j,n);j+=4}if(u.keyMap){for(let e=0;e{C[j++]=185;let e=j-s;j+=2;let n=0;if(u.keyMap){for(let e in t)if(r||t.hasOwnProperty(e)){g(u.encodeKey(e));g(t[e]);n++}}else{for(let e in t)if(r||t.hasOwnProperty(e)){g(e);g(t[e]);n++}}C[e+++s]=n>>8;C[e+s]=n&255}:(t,r)=>{let n,i=l.transitions||(l.transitions=Object.create(null));let u=0;let a=0;let o;let s;if(this.keyMap){s=Object.keys(t).map(e=>this.encodeKey(e));a=s.length;for(let t=0;t>8|224;C[j++]=c&255}else{if(!s)s=i.__keys__||(i.__keys__=Object.keys(t));if(o===undefined){c=l.nextId++;if(!c){c=0;l.nextId=1}if(c>=Nt){l.nextId=(c=h)+1}}else{c=o}l[c]=s;if(c>8|224;C[j++]=c&255;i=l.transitions;for(let e=0;e=Nt-h)v.shift()[zt]=undefined;v.push(i);Jt(a+2);g(57344+c);g(s);if(r===null)return;for(let e in t)if(r||t.hasOwnProperty(e))g(t[e]);return}}if(a<24){C[j++]=128|a}else{Jt(a)}if(r===null)return;for(let e in t)if(r||t.hasOwnProperty(e))g(t[e])};const w=e=>{let t;if(e>16777216){if(e-s>Tt)throw new Error("Encoded buffer would be larger than maximum buffer size");t=Math.min(Tt,Math.round(Math.max((e-s)*(e>67108864?1.25:2),4194304)/4096)*4096)}else t=(Math.max(e-s<<2,C.length-1)>>12)+1<<12;let r=new It(t);S=new DataView(r.buffer,0,t);if(C.copy)C.copy(r,0,s,e);else r.set(C.slice(s,e));j-=s;s=0;Mt=r.length-10;return C=r};let D=100;let x=1e3;this.encodeAsIterable=function(e,t){return k(e,t,E)};this.encodeAsAsyncIterable=function(e,t){return k(e,t,O)};function*E(n,i,e){let t=n.constructor;if(t===Object){let r=u.useRecords!==false;if(r)b(n,null);else $t(Object.keys(n).length,160);for(let t in n){let e=n[t];if(!r)g(t);if(e&&typeof e==="object"){if(i[t])yield*E(e,i[t]);else yield*F(e,i,t)}else g(e)}}else if(t===Array){let e=n.length;Jt(e);for(let t=0;tD)){if(i.element)yield*E(e,i.element);else yield*F(e,i,"element")}else g(e)}}else if(n[Symbol.iterator]){C[j++]=159;for(let e of n){if(e&&(typeof e==="object"||j-s>D)){if(i.element)yield*E(e,i.element);else yield*F(e,i,"element")}else g(e)}C[j++]=255}else if(Ht(n)){$t(n.size,64);yield C.subarray(s,j);yield n;A()}else if(n[Symbol.asyncIterator]){C[j++]=159;yield C.subarray(s,j);yield n;A();C[j++]=255}else{g(n)}if(e&&j>s)yield C.subarray(s,j);else if(j-s>D){yield C.subarray(s,j);A()}}function*F(t,r,n){let i=j-s;try{g(t);if(j-s>D){yield C.subarray(s,j);A()}}catch(e){if(e.iteratorNotHandled){r[n]={};j=s+i;yield*E.call(this,t,r[n])}else throw e}}function A(){D=x;u.encode(null,ur)}function k(e,t,r){if(t&&t.chunkThreshold)D=x=t.chunkThreshold;else D=100;if(e&&typeof e==="object"){u.encode(null,ur);return r(e,u.iterateProperties||(u.iterateProperties={}),true)}return[u.encode(e)]}async function*O(e,t){for(let r of E(e,t,true)){let e=r.constructor;if(e===Pt||e===Uint8Array)yield r;else if(Ht(r)){let e=r.stream().getReader();let t;while(!(t=await e.read()).done){yield t.value}}else if(r[Symbol.asyncIterator]){for await(let e of r){A();if(e)yield*O(e,t.async||(t.async={}));else yield u.encode(e)}}else{yield r}}}}useBuffer(e){C=e;S=new DataView(C.buffer,C.byteOffset,C.byteLength);j=0}clearSharedData(){if(this.structures)this.structures=[];if(this.sharedValues)this.sharedValues=undefined}updateSharedData(){let t=this.sharedVersion||0;this.sharedVersion=t+1;let e=this.structures.slice(0);let r=new Yt(e,this.sharedValues,this.sharedVersion);let n=this.saveShared(r,e=>(e&&e.version||0)==t);if(n===false){r=this.getShared()||{};this.structures=r.structures||[];this.sharedValues=r.packedValues;this.sharedVersion=r.version;this.structures.nextId=this.structures.length}else{e.forEach((e,t)=>this.structures[t]=e)}return n}}function $t(e,t){if(e<24)C[j++]=t|e;else if(e<256){C[j++]=t|24;C[j++]=e}else if(e<65536){C[j++]=t|25;C[j++]=e>>8;C[j++]=e&255}else{C[j++]=t|26;S.setUint32(j,e);j+=4}}class Yt{constructor(e,t,r){this.structures=e;this.packedValues=t;this.version=r}}function Jt(e){if(e<24)C[j++]=128|e;else if(e<256){C[j++]=152;C[j++]=e}else if(e<65536){C[j++]=153;C[j++]=e>>8;C[j++]=e&255}else{C[j++]=154;S.setUint32(j,e);j+=4}}const Kt=typeof Blob==="undefined"?function(){}:Blob;function Ht(e){if(e instanceof Kt)return true;let t=e[Symbol.toStringTag];return t==="Blob"||t==="File"}function Gt(r,n){switch(typeof r){case"string":if(r.length>3){if(n.objectMap[r]>-1||n.values.length>=n.maxValues)return;let e=n.get(r);if(e){if(++e.count==2){n.values.push(r)}}else{n.set(r,{count:1});if(n.samplingPackedValues){let e=n.samplingPackedValues.get(r);if(e)e.count++;else n.samplingPackedValues.set(r,{count:1})}}}break;case"object":if(r){if(r instanceof Array){for(let e=0,t=r.length;e=0&&r<4294967296){C[j++]=26;S.setUint32(j,r);j+=4}else{C[j++]=251;S.setFloat64(j,r);j+=8}}},{tag:258,encode(e,t){let r=Array.from(e);t(r)}},{tag:27,encode(e,t){t([e.name,e.message])}},{tag:27,encode(e,t){t(["RegExp",e.source,e.flags])}},{getTag(e){return e.tag},encode(e,t){t(e.value)}},{encode(e,t,r){Zt(e,r)}},{getTag(e){if(e.constructor===Uint8Array){if(this.tagUint8Array||Bt&&this.tagUint8Array!==false)return 64}},encode(e,t,r){Zt(e,r)}},Qt(68,1),Qt(69,2),Qt(70,4),Qt(71,8),Qt(72,1),Qt(77,2),Qt(78,4),Qt(79,8),Qt(85,4),Qt(86,8),{encode(t,n){let e=t.packedValues||[];let r=t.structures||[];if(e.values.length>0){C[j++]=216;C[j++]=51;Jt(4);let r=e.values;n(r);Jt(0);Jt(0);packedObjectMap=Object.create(sharedPackedObjectMap||null);for(let e=0,t=r.length;e1)e-=4;return{tag:e,encode:function e(t,r){let n=t.byteLength;let i=t.byteOffset||0;let u=t.buffer||t;r(Bt?jt.from(u,i,n):new Uint8Array(u,i,n))}}}function Zt(e,t){let r=e.byteLength;if(r<24){C[j++]=64+r}else if(r<256){C[j++]=88;C[j++]=r}else if(r<65536){C[j++]=89;C[j++]=r>>8;C[j++]=r&255}else{C[j++]=90;S.setUint32(j,r);j+=4}if(j+r>=C.length){t(j+r)}C.set(e.buffer?e:new Uint8Array(e),j);j+=r}function Xt(n,e){let r;let i=e.length*2;let u=n.length-i;e.sort((e,t)=>e.offset>t.offset?1:-1);for(let r=0;r>8;n[e]=r&255}}while(r=e.pop()){let e=r.offset;n.copyWithin(e+i,e,u);i-=2;let t=e+i;n[t++]=216;n[t++]=28;u=e}return n}function er(e,t){S.setUint32(Rt.position+e,j-Rt.position-e+1);let r=Rt;Rt=null;t(r[0]);t(r[1])}function tr(e){if(e.Class){if(!e.encode)throw new Error("Extension has no encode function");St.unshift(e.Class);Ct.unshift(e)}Ft(e)}let rr=new Vt({useRecords:false});rr.encode;rr.encodeAsIterable;rr.encodeAsAsyncIterable;const nr=512;const ir=1024;const ur=2048;var ar={}; /**@license @@ -42,4 +42,4 @@ * Released under BSD-3-Clause License * * build: Wed, 27 Oct 2021 10:43:10 GMT - */Object.defineProperty(ar,"__esModule",{value:true});const or=8,sr=6,cr=3,fr=(1<r-fr){t[i++]=e[n++];continue}f=(e[n]+13^e[n+1]-13^e[n+2])&hr-1;c=n-l[f]&lr;l[f]=n;u=n-c;if(u>=0&&u!=n&&e[n]==e[u]&&e[n+1]==e[u+1]&&e[n+2]==e[u+2]){t[a]|=o;for(s=cr;s>or;t[i++]=c;n+=s}else{t[i++]=e[n++]}}console.assert(e.length>=n);return i}function pr(e,t,r){t=t|0;var n=0,i=0,u=0,a=0,o=1<<(or-1|0),s=0,c=0;while(n>(or-sr|0))+cr|0;c=(e[n]<4){r[i]=r[u];i=i+1|0;u=u+1|0;r[i]=r[u];i=i+1|0;u=u+1|0;r[i]=r[u];i=i+1|0;u=u+1|0;r[i]=r[u];i=i+1|0;u=u+1|0;s=s-4|0}while(s>0){r[i]=r[u];i=i+1|0;u=u+1|0;s=s-1|0}}}else{r[i]=e[n];i=i+1|0;n=n+1|0}}return i}function dr(){const e=new TextEncoder("utf-8");return e.encode(vr)}const vr="@lzjb";const mr=dr();function yr(...e){if(e.length>1){const r=e.reduce((e,t)=>e+t.length,0);const n=new Uint8Array(r);let t=0;e.forEach(e=>{n.set(e,t);t+=e.length});return n}else if(e.length){return e[0]}}function gr(t){const e=Math.ceil(Math.log2(t)/8);const r=new Uint8Array(e);for(let e=0;e=0;e--){r=r*256+t[e]}return r}function wr(e,{magic:t=true}={}){const r=new Uint8Array(Math.max(e.length*1.5|0,16*1024));const n=_r(e,r);const i=gr(e.length);const u=[Uint8Array.of(i.length),i,r.slice(0,n)];if(t){u.unshift(mr)}return yr(...u)}function Dr(t,{magic:e=true}={}){if(e){const e=new TextDecoder("utf-8");const s=e.decode(t.slice(0,mr.length));if(s!==vr){throw new Error("Invalid magic value")}}const r=e?mr.length:0;const n=t[r];const i=r+1;const u=r+n+1;const a=br(t.slice(i,u));t=t.slice(u);const o=new Uint8Array(a);pr(t,t.length,o);return o}var xr=ar.pack=wr;var Er=ar.unpack=Dr;function Fr(s,c){return c=c||{},new Promise(function(e,t){var r=new XMLHttpRequest,n=[],i=[],u={},a=function(){return{ok:2==(r.status/100|0),statusText:r.statusText,status:r.status,url:r.responseURL,text:function(){return Promise.resolve(r.responseText)},json:function(){return Promise.resolve(r.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([r.response]))},clone:a,headers:{keys:function(){return n},entries:function(){return i},get:function(e){return u[e.toLowerCase()]},has:function(e){return e.toLowerCase()in u}}}};for(var o in r.open(c.method||"get",s,!0),r.onload=function(){r.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,t,r){n.push(t=t.toLowerCase()),i.push([t,r]),u[t]=u[t]?u[t]+","+r:r}),e(a())},r.onerror=t,r.withCredentials="include"==c.credentials,c.headers)r.setRequestHeader(o,c.headers[o]);r.send(c.body||null)})}var Ar=["token"],kr=["env"],Or=["stderr","stdin","stdout","command_line"],Cr=["use_dynamic"],Sr=["use_dynamic"],jr=["env","dynamic_env","use_dynamic","error"];function Br(e,t,r){Ir(e,t);t.set(e,r)}function Ir(e,t){if(t.has(e)){throw new TypeError("Cannot initialize the same private elements twice on an object")}}function Pr(e,t,r){return t=I(t),R(e,Nr()?Reflect.construct(t,r||[],I(e).constructor):t.apply(e,r))}function Nr(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Nr=function e(){return!!t})()}function Tr(t,e){var r=typeof Symbol!=="undefined"&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=Lr(t))||e&&t&&typeof t.length==="number"){if(r)t=r;var n=0;var i=function e(){};return{s:i,n:function e(){if(n>=t.length)return{done:true};return{done:false,value:t[n++]}},e:function e(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u=true,a=false,o;return{s:function e(){r=r.call(t)},n:function e(){var t=r.next();u=t.done;return t},e:function e(t){a=true;o=t},f:function e(){try{if(!u&&r["return"]!=null)r["return"]()}finally{if(a)throw o}}}}function Lr(e,t){if(!e)return;if(typeof e==="string")return Mr(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor)r=e.constructor.name;if(r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return Mr(e,t)}function Mr(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r1?r-1:0),i=1;i0&&arguments[0]!==undefined?arguments[0]:null;var t=vo&&vo.get("DEBUG",{throwError:false});if(e===null){return t===true}return(t===null||t===void 0?void 0:t.valueOf())===e.valueOf()}function Qr(e){return e?"(?:#".concat(e,"(?:#[ie])?|#[ie]#").concat(e,")"):"(?:#[ie])?"}function Zr(e,t){return"".concat(Qr(e),"[+-]?").concat(t,"+/").concat(t,"+")}function Xr(e,t){return"".concat(Qr(e),"(?:[+-]?(?:").concat(t,"+/").concat(t,"+|nan.0|inf.0|").concat(t,"+))?(?:[+-]i|[+-]?(?:").concat(t,"+/").concat(t,"+|").concat(t,"+|nan.0|inf.0)i)(?=[()[\\]\\s]|$)")}function en(e,t){return"".concat(Qr(e),"[+-]?").concat(t,"+")}var tn=/^#\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimyus]*)$/;var rn="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)";var nn="(?:#[ie])?(?:[+-]?(?:[0-9]+/[0-9]+|nan.0|inf.0|".concat(rn,"|[+-]?[0-9]+))?(?:").concat(rn,"|[+-](?:[0-9]+/[0-9]+|[0-9]+|nan.0|inf.0))i");var un=new RegExp("^(#[ie])?".concat(rn,"$"),"i");function an(e,t){var r=e==="x"?"(?!\\+|".concat(t,")"):"(?!\\.|".concat(t,")");var n="";if(e===""){n="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+(?![0-9]))(?:[eE][-+]?[0-9]+)?))"}return new RegExp("^((?:(?:".concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(t,"+/").concat(t,"+(?!").concat(t,")|[+-]?").concat(t,"+)").concat(r,")?)(").concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(t,"+/").concat(t,"+|[+-]?").concat(t,"+|[+-])i$"),"i")}var on=function(){var u={};[[10,"","[0-9]"],[16,"x","[0-9a-fA-F]"],[8,"o","[0-7]"],[2,"b","[01]"]].forEach(function(e){var t=b(e,3),r=t[0],n=t[1],i=t[2];u[r]=an(n,i)});return u}();var sn={alarm:"",backspace:"\b",delete:"",escape:"",newline:"\n",null:"\0",return:"\r",space:" ",tab:"\t",dle:"",soh:"",dc1:"",stx:"",dc2:"",etx:"",dc3:"",eot:"",dc4:"",enq:"",nak:"",ack:"",syn:"",bel:"",etb:"",bs:"\b",can:"",ht:"\t",em:"",lf:"\n",sub:"",vt:"\v",esc:"",ff:"\f",fs:"",cr:"\r",gs:"",so:"",rs:"",si:"",us:"",del:""};function cn(e){var t=[];var r=0;var n=e.length;while(r=55296&&i<=56319&&r1&&arguments[1]!==undefined?arguments[1]:10;var r=En(e);var n=r.number.split("/");var i=x({num:B([n[0],r.radix||t]),denom:B([n[1],r.radix||t])});if(r.inexact){return i.valueOf()}else{return i}}function An(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;var r=En(e);if(r.inexact){return g(parseInt(r.number,r.radix||t))}return B([r.number,r.radix||t])}function kn(e){var t=e.match(/#\\x([0-9a-f]+)$/i);var r;if(t){var n=parseInt(t[1],16);r=String.fromCodePoint(n)}else{t=e.match(/#\\([\s\S]+)$/);if(t){r=t[1]}}if(r){return h(r)}throw new Error("Parse: invalid character")}function On(e){var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;function t(e){var t;if(e==="+"){t=B(1)}else if(e==="-"){t=B(-1)}else if(e.match(gn)){t=B([e,i])}else if(e.match(bn)){var r=e.split("/");t=x({num:B([r[0],i]),denom:B([r[1],i])})}else if(e.match(un)){var n=Bn(e);if(u.exact){return n.toRational()}return n}else if(e.match(/nan.0$/)){return B(NaN)}else if(e.match(/inf.0$/)){if(e[0]==="-"){return B(Number.NEGATIVE_INFINITY)}return B(Number.POSITIVE_INFINITY)}else{throw new Error("Internal Parser Error")}if(u.inexact){return g(t.valueOf())}return t}var u=En(e);i=u.radix||i;var r;var n=u.number.match(Dn);if(i!==10&&n){r=n}else{r=u.number.match(on[i])}var a,o;o=t(r[2]);if(r[1]){a=t(r[1])}else{a=B(0)}if(o.cmp(0)===0&&o.__type__==="bigint"){return a}return y({im:o,re:a})}function Cn(e){return parseInt(e.toString(),10)===e}function Sn(e){var t=e.match(/^(([-+]?[0-9]*)(?:\.([0-9]+))?)e([-+]?[0-9]+)/i);if(t){var r=parseInt(t[4],10);var n;var i=t[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var u=t[3]&&t[3].length;if(i0&&(t.exact||!t.number.match(/\./))){return B(u).mul(o)}}}r=g(r);if(t.exact){return r.toRational()}return r}function In(e){e=e.replace(/\\x([0-9a-f]+);/gi,function(e,t){return"\\u"+t.padStart(4,"0")}).replace(/\n/g,"\\n");var t=e.match(/(\\*)(\\x[0-9A-F])/i);if(t&&t[1].length%2===0){throw new Error("Invalid string literal, unclosed ".concat(t[2]))}try{var r=D(JSON.parse(e));r.freeze();return r}catch(e){var n=e.message.replace(/in JSON /,"").replace(/.*Error: /,"");throw new Error("Invalid string literal: ".concat(n))}}function Pn(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var r={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,t){return String.fromCharCode(parseInt("0"+t,16))}).replace(/\\(.)/g,function(e,t){return r[t]||t})}return new V(e)}function Nn(e){if(po.hasOwnProperty(e)){return po[e]}if(e.match(/^"[\s\S]*"$/)){return In(e)}else if(e[0]==="#"){var t=e.match(tn);if(t){return new RegExp(t[1],t[2])}else if(e.match(_n)){return kn(e)}var r=e.match(/#\\(.+)/);if(r&&cn(r[1]).length===1){return kn(e)}}if(e.match(/[0-9a-f]|[+-]i/i)){if(e.match(yn)){return An(e)}else if(e.match(un)){return Bn(e)}else if(e.match(mn)){return Fn(e)}else if(e.match(vn)){return On(e)}}if(e.match(/^#[iexobd]/)){throw new Error("Invalid numeric constant: "+e)}return Pn(e)}function Tn(e){return!(["(",")","[","]"].includes(e)||ri.names().includes(e))}function Ln(e){return Tn(e)&&!(e.match(tn)||e.match(/^"[\s\S]*"$/)||e.match(yn)||e.match(un)||e.match(vn)||e.match(mn)||e.match(_n)||["#t","#f","nil"].includes(e))}var Mn=/"(?:\\[\S\s]|[^"])*"?/g;function Rn(e){if(typeof e==="string"){var t=/([-\\^$[\]()+{}?*.|])/g;return e.replace(t,"\\$1")}return e}function qn(){this.data=[]}qn.prototype.push=function(e){this.data.push(e)};qn.prototype.top=function(){return this.data[this.data.length-1]};qn.prototype.pop=function(){return this.data.pop()};qn.prototype.is_empty=function(){return!this.data.length};function Un(e){if(e instanceof D){e=e.valueOf()}var t=new s(e,{whitespace:true});var r=[];while(true){var n=t.peek(true);if(n===eo){break}r.push(n);t.skip()}return r}function zn(e){var t=e.token,r=he(e,Ar);if(t.match(/^"[\s\S]*"$/)&&t.match(/\n/)){var n=new RegExp("^ {1,"+(e.col+1)+"}","mg");t=t.replace(n,"")}return U({token:t},r)}function Vn(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(){};this.fn=e;this.cont=t}Vn.prototype.toString=function(){return"#"};function $n(n){return function(){for(var e=arguments.length,t=new Array(e),r=0;r1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof D){e=e.toString()}if(t){return Un(e)}else{var r=Un(e).map(function(e){if(e.token==="#\\ "||e.token=="#\\\n"){return e.token}return e.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return Kn(r)}}function Kn(e){var t=0;var r=null;var n=[];for(var i=0;i0&&arguments[0]!==undefined?arguments[0]:null;if(e instanceof V){if(e.is_gensym()){return e}e=e.valueOf()}if(Wn(e)){return V(e)}if(e!==null){return r(e,Symbol("#:".concat(e)))}t++;return r(t,Symbol("#:g".concat(t)))}}();function Zn(e){var r=this;var n={pending:true,rejected:false,fulfilled:false,reason:undefined,type:undefined};e=e.then(function(e){n.type=Io(e);n.fulfilled=true;n.pending=false;return e});c(this,"_promise",e,{hidden:true});if(d(e["catch"])){e=e["catch"](function(e){n.rejected=true;n.pending=false;n.reason=e})}Object.keys(n).forEach(function(t){Object.defineProperty(r,"__".concat(t,"__"),{enumerable:true,get:function e(){return n[t]}})});c(this,"__promise__",e);this.then=false}Zn.prototype.then=function(e){return new Zn(this.valueOf().then(e))};Zn.prototype["catch"]=function(e){return new Zn(this.valueOf()["catch"](e))};Zn.prototype.valueOf=function(){if(!this._promise){throw new Error("QuotedPromise: invalid promise created")}return this._promise};Zn.prototype.toString=function(){if(this.__pending__){return Zn.pending_str}if(this.__rejected__){return Zn.rejected_str}return"#")};Zn.pending_str="#";Zn.rejected_str="#";function Xn(e){if(Array.isArray(e)){return Promise.all(ei(e)).then(ti)}return e}function ei(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof Zn){t[r]=new uo(n)}else{t[r]=n}}return t}function ti(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof uo){t[r]=n.valueOf()}else{t[r]=n}}return t}var ri={LITERAL:Symbol["for"]("literal"),SPLICE:Symbol["for"]("splice"),SYMBOL:Symbol["for"]("symbol"),names:function e(){return Object.keys(this.__list__)},type:function e(t){try{return this.get(t).type}catch(e){console.log({name:t});console.log(e);return null}},get:function e(t){return this.__list__[t]},off:function e(t){var r=this;var n=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(Array.isArray(t)){t.forEach(function(e){return r.off(e,n)})}else if(n===null){delete this.__events__[t]}else{this.__events__=this.__events__.filter(function(e){return e!==n})}},on:function e(t,r){var n=this;if(Array.isArray(t)){t.forEach(function(e){return n.on(e,r)})}else if(!this.__events__[t]){this.__events__[t]=[r]}else{this.__events__[t].push(r)}},trigger:function e(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i",new V("quote-promise"),ri.LITERAL]];var si=oi.map(function(e){return e[0]});Object.freeze(si);Object.defineProperty(ri,"__builtins__",{writable:false,value:si});oi.forEach(function(e){var t=b(e,3),r=t[0],n=t[1],i=t[2];ri.append(r,n,i)});var s=function(){function _(e){var t=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=r.whitespace,i=n===void 0?false:n;ue(this,_);c(this,"__input__",e.replace(/\r/g,""));var u={};["_i","_whitespace","_col","_newline","_line","_state","_next","_token","_prev_char"].forEach(function(r){Object.defineProperty(t,r,{configurable:false,enumerable:false,get:function e(){return u[r]},set:function e(t){u[r]=t}})});this._whitespace=i;this._i=this._line=this._col=this._newline=0;this._state=this._next=this._token=null;this._prev_char=""}ce(_,[{key:"get",value:function e(t){return this.__internal[t]}},{key:"set",value:function e(t,r){this.__internal[t]=r}},{key:"token",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(t){var r=this._line;if(this._whitespace&&this._token==="\n"){--r}return{token:this._token,col:this._col,offset:this._i,line:r}}return this._token}},{key:"peek",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(this._i>=this.__input__.length){return eo}if(this._token){return this.token(t)}var r=this.next_token();if(r){this._token=this.__input__.substring(this._i,this._next);return this.token(t)}return eo}},{key:"skip",value:function e(){if(this._next!==null){this._token=null;this._i=this._next}}},{key:"read_line",value:function e(){var t=this.__input__.length;if(this._i>=t){return eo}for(var r=this._i;r=r){return eo}if(t+this._i>=r){return this.read_rest()}var n=this._i+t;var i=this.__input__.substring(this._i,n);var u=i.match(/\n/g);if(u){this._line+=u.length}this._i=n;return i}},{key:"peek_char",value:function e(){if(this._i>=this.__input__.length){return eo}return h(this.__input__[this._i])}},{key:"read_char",value:function e(){var t=this.peek_char();this.skip_char();return t}},{key:"skip_char",value:function e(){if(this._i1&&arguments[1]!==undefined?arguments[1]:{},n=r.prev_char,i=r["char"],u=r.next_char;var a=b(t,4),o=a[0],s=a[1],c=a[2],f=a[3];if(t.length!==5){throw new Error("Lexer: Invalid rule of length ".concat(t.length))}if(Eu(o)){if(o!==i){return false}}else if(!i.match(o)){return false}if(!ci(s,n)){return false}if(!ci(c,u)){return false}if(f!==this._state){return false}return true}},{key:"next_token",value:function e(){if(this._i>=this.__input__.length){return false}var t=true;e:for(var r=this._i,n=this.__input__.length;r2&&arguments[2]!==undefined?arguments[2]:null;var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;if(t.length===0){throw new Error("Lexer: invalid literal rule")}if(t.length===1){return[[t,n,i,null,null]]}var u=[];for(var a=0,o=t.length;a1&&arguments[1]!==undefined?arguments[1]:{},r=t.env,n=t.meta,i=n===void 0?false:n,u=t.formatter,a=u===void 0?zn:u;ue(this,o);if(e instanceof D){e=e.toString()}c(this,"_formatter",a,{hidden:true});c(this,"__lexer__",new s(e));c(this,"__env__",r);c(this,"_meta",i,{hidden:true});c(this,"_refs",[],{hidden:true});c(this,"_state",{parentheses:0},{hidden:true})}ce(o,[{key:"resolve",value:function e(t){return this.__env__&&this.__env__.get(t,{throwError:false})}},{key:"peek",value:function(){var e=ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=this.__lexer__.peek(true);if(!(r===eo)){t.next=4;break}return t.abrupt("return",eo);case 4:if(!this.is_comment(r.token)){t.next=7;break}this.skip();return t.abrupt("continue",0);case 7:if(!(r.token==="#;")){t.next=14;break}this.skip();if(!(this.__lexer__.peek()===eo)){t.next=11;break}throw new Error("Lexer: syntax error eof found after comment");case 11:t.next=13;return this._read_object();case 13:return t.abrupt("continue",0);case 14:return t.abrupt("break",17);case 17:r=this._formatter(r);if(!this._meta){t.next=20;break}return t.abrupt("return",r);case 20:return t.abrupt("return",r.token);case 21:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"reset",value:function e(){this._refs.length=0}},{key:"skip",value:function e(){this.__lexer__.skip()}},{key:"read",value:function(){var e=ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return this.peek();case 2:r=t.sent;this.skip();return t.abrupt("return",r);case 5:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"match_datum_label",value:function e(t){var r=t.match(/^#([0-9]+)=$/);return r&&r[1]}},{key:"match_datum_ref",value:function e(t){var r=t.match(/^#([0-9]+)#$/);return r&&r[1]}},{key:"is_open",value:function e(t){var r=["(","["].includes(t);if(r){this._state.parentheses++}return r}},{key:"is_close",value:function e(t){var r=[")","]"].includes(t);if(r){this._state.parentheses--}return r}},{key:"read_list",value:function(){var e=ie(O.mark(function e(){var r,n,i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=$,n=r;case 1:t.next=4;return this.peek();case 4:u=t.sent;if(!(u===eo)){t.next=7;break}return t.abrupt("break",32);case 7:if(!this.is_close(u)){t.next=10;break}this.skip();return t.abrupt("break",32);case 10:if(!(u==="."&&!K(r))){t.next=18;break}this.skip();t.next=14;return this._read_object();case 14:n.cdr=t.sent;i=true;t.next=30;break;case 18:if(!i){t.next=22;break}throw new Error("Parser: syntax error more than one element after dot");case 22:t.t0=Y;t.next=25;return this._read_object();case 25:t.t1=t.sent;t.t2=$;a=new t.t0(t.t1,t.t2);if(K(r)){r=a}else{n.cdr=a}n=a;case 30:t.next=1;break;case 32:return t.abrupt("return",r);case 33:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"read_value",value:function(){var e=ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return this.read();case 2:r=t.sent;if(!(r===eo)){t.next=5;break}throw new Error("Parser: Expected token eof found");case 5:return t.abrupt("return",Nn(r));case 6:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"is_comment",value:function e(t){return t.match(/^;/)||t.match(/^#\|/)&&t.match(/\|#$/)}},{key:"evaluate",value:function e(t){return k(t,{env:this.__env__,error:function e(t){throw t}})}},{key:"read_object",value:function(){var e=ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:this.reset();t.next=3;return this._read_object();case 3:r=t.sent;if(r instanceof li){r=r.valueOf()}if(!this._refs.length){t.next=7;break}return t.abrupt("return",w(this._resolve_object(r),function(e){if(H(e)){e.mark_cycles()}return e}));case 7:return t.abrupt("return",r);case 8:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"balanced",value:function e(){return this._state.parentheses===0}},{key:"ballancing_error",value:function e(t,r){var n=this._state.parentheses;var i;if(n<0){i=new Error("Parser: unexpected parenthesis");i.__code__=[r.toString()+")"]}else{i=new Error("Parser: expected parenthesis but eof found");var u=new RegExp("\\){".concat(n,"}$"));i.__code__=[t.toString().replace(u,"")]}throw i}},{key:"_resolve_object",value:function(){var t=ie(O.mark(function e(r){var n=this;var i;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!Array.isArray(r)){t.next=2;break}return t.abrupt("return",r.map(function(e){return n._resolve_object(e)}));case 2:if(!Ki(r)){t.next=6;break}i={};Object.keys(r).forEach(function(e){i[e]=n._resolve_object(r[e])});return t.abrupt("return",i);case 6:if(!H(r)){t.next=8;break}return t.abrupt("return",this._resolve_pair(r));case 8:return t.abrupt("return",r);case 9:case"end":return t.stop()}},e,this)}));function e(e){return t.apply(this,arguments)}return e}()},{key:"_resolve_pair",value:function(){var t=ie(O.mark(function e(r){return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!H(r)){t.next=15;break}if(!(r.car instanceof li)){t.next=7;break}t.next=4;return r.car.valueOf();case 4:r.car=t.sent;t.next=8;break;case 7:this._resolve_pair(r.car);case 8:if(!(r.cdr instanceof li)){t.next=14;break}t.next=11;return r.cdr.valueOf();case 11:r.cdr=t.sent;t.next=15;break;case 14:this._resolve_pair(r.cdr);case 15:return t.abrupt("return",r);case 16:case"end":return t.stop()}},e,this)}));function e(e){return t.apply(this,arguments)}return e}()},{key:"_read_object",value:function(){var e=ie(O.mark(function e(){var r,n,i,u,a,o,s,c,f,l,h;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return this.peek();case 2:r=t.sent;if(!(r===eo)){t.next=5;break}return t.abrupt("return",r);case 5:if(!ni(r)){t.next=38;break}n=ri.get(r);i=ii(r);this.skip();a=ai(r);if(!a){t.next=14;break}t.t0=undefined;t.next=17;break;case 14:t.next=16;return this._read_object();case 16:t.t0=t.sent;case 17:o=t.t0;if(i){t.next=25;break}s=this.__env__.get(n.symbol);if(!(typeof s==="function")){t.next=25;break}if(ui(r)){c=[o]}else if(K(o)){c=[]}else if(H(o)){c=o.to_array(false)}if(!(c||a)){t.next=24;break}return t.abrupt("return",Ro(s,a?[]:c,{env:this.__env__,dynamic_env:this.__env__,use_dynamic:false}));case 24:throw new Error("Parse Error: Invalid parser extension "+"invocation ".concat(n.symbol));case 25:if(ui(r)){u=new Y(n.symbol,new Y(o,$))}else{u=new Y(n.symbol,o)}if(!i){t.next=28;break}return t.abrupt("return",u);case 28:if(!(s instanceof J)){t.next=37;break}t.next=31;return this.evaluate(u);case 31:f=t.sent;if(!(H(f)||f instanceof V)){t.next=34;break}return t.abrupt("return",Y.fromArray([V("quote"),f]));case 34:return t.abrupt("return",f);case 37:throw new Error("Parse Error: invalid parser extension: "+n.symbol);case 38:l=this.match_datum_ref(r);if(!(l!==null)){t.next=44;break}this.skip();if(!this._refs[l]){t.next=43;break}return t.abrupt("return",new li(l,this._refs[l]));case 43:throw new Error("Parse Error: invalid datum label #".concat(l,"#"));case 44:h=this.match_datum_label(r);if(!(h!==null)){t.next=51;break}this.skip();this._refs[h]=this._read_object();return t.abrupt("return",this._refs[h]);case 51:if(!this.is_close(r)){t.next=55;break}this.skip();t.next=61;break;case 55:if(!this.is_open(r)){t.next=60;break}this.skip();return t.abrupt("return",this.read_list());case 60:return t.abrupt("return",this.read_value());case 61:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()}]);return o}();var li=function(){function r(e,t){ue(this,r);this.name=e;this.data=t}ce(r,[{key:"valueOf",value:function e(){return this.data}}]);return r}();function hi(e,t){return _i.apply(this,arguments)}function _i(){_i=ge(O.mark(function e(r,n){var i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!n){if(G){n=G.get("**interaction-environment**",{throwError:false})}else{n=vo}}i=new fi(r,{env:n});case 3:t.next=6;return me(i.read_object());case 6:a=t.sent;if(!i.balanced()){i.ballancing_error(a,u)}if(!(a===eo)){t.next=10;break}return t.abrupt("break",15);case 10:u=a;t.next=13;return a;case 13:t.next=3;break;case 15:case"end":return t.stop()}},e)}));return _i.apply(this,arguments)}function w(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(e){return e};var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;if(Bu(e)){var n=e.then(t);if(r===null){return n}else{return n["catch"](r)}}if(e instanceof Array){return pi(e,t,r)}if(Ki(e)){return di(e,t,r)}return t(e)}function pi(t,r,e){if(t.find(Bu)){return w(Xn(t),function(e){if(Object.isFrozen(t)){Object.freeze(e)}return r(e)},e)}return r(t)}function di(t,e,r){var i=Object.keys(t);var n=[],u=[];var a=i.length;while(a--){var o=i[a];var s=t[o];n[a]=s;if(Bu(s)){u.push(s)}}if(u.length){return w(Xn(n),function(e){var n={};e.forEach(function(e,t){var r=i[t];n[r]=e});if(Object.isFrozen(t)){Object.freeze(n)}return n},r)}return e(t)}function c(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{},i=n.hidden,u=i===void 0?false:i;Object.defineProperty(e,t,{value:r,configurable:true,enumerable:!u})}function vi(e){return mi.apply(this,arguments)}function mi(){mi=ie(O.mark(function e(r){var n,i,u,a,o,s,c;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:n=[];i=false;u=false;t.prev=3;o=qr(r);case 5:t.next=7;return o.next();case 7:if(!(i=!(s=t.sent).done)){t.next=13;break}c=s.value;n.push(c);case 10:i=false;t.next=5;break;case 13:t.next=19;break;case 15:t.prev=15;t.t0=t["catch"](3);u=true;a=t.t0;case 19:t.prev=19;t.prev=20;if(!(i&&o["return"]!=null)){t.next=24;break}t.next=24;return o["return"]();case 24:t.prev=24;if(!u){t.next=27;break}throw a;case 27:return t.finish(24);case 28:return t.finish(19);case 29:return t.abrupt("return",n);case 30:case"end":return t.stop()}},e,null,[[3,15,19,29],[20,,24,28]])}));return mi.apply(this,arguments)}function yi(e,t){if(t instanceof RegExp){return function(e){return String(e).match(t)}}else if(d(t)){return t}throw new Error("Invalid matcher")}function l(e,t,r,n){if(typeof e!=="string"){t=arguments[0];r=arguments[1];n=arguments[2];e=null}if(r){if(n){t.__doc__=r}else{t.__doc__=gi(r)}}if(e){t.__name__=e}else if(t.name&&!ca(t)){t.__name__=t.name}return t}function gi(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function bi(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var r=e.length;if(t<=0){throw Error("previousSexp: Invalid argument sexp = ".concat(t))}e:while(t--&&r>=0){var n=1;while(n>0){var i=e[--r];if(!i){break e}if(i==="("||i.token==="("){n--}else if(i===")"||i.token===")"){n++}}r--}return e.slice(r+1)}function wi(e){if(!e||!e.length){return 0}var t=e.length;if(e[t-1].token==="\n"){return 0}while(--t){if(e[t].token==="\n"){var r=(e[t+1]||{}).token;if(r){return r.length}}}return 0}function Di(e,t){return f(e,t)===t.length;function f(r,n){function e(e,t){var r=Tr(e),n;try{for(r.s();!(n=r.n()).done;){var i=n.value;var u=f(i,t);if(u!==-1){return u}}}catch(e){r.e(e)}finally{r.f()}return-1}function t(){return r[u]===Symbol["for"]("symbol")&&!Ln(n[o])}function i(){var e=r[u+1];var t=n[o+1];if(e!==undefined&&t!==undefined){return f([e],[t])}}var u=0;var a={};for(var o=0;o0){continue}}else if(t()){return-1}}else if(r[u]instanceof Array){var c=f(r[u],n.slice(o));if(c===-1||c+o>n.length){return-1}o+=c-1;u++;continue}else{return-1}u++}if(r.length!==u){return-1}return n.length}}function xi(e){this.__code__=e.replace(/\r/g,"")}xi.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?(?:define(?:-values|-syntax|-macro|-class|-record-type)?|(?:call-with-(?:input-file|output-file|port))|lambda|let-env|try|catch|when|unless|while|syntax-rules|(let|letrec)(-syntax|\*?-values|\*)?)$/],shift:{1:["&","#"]}}};xi.match=Di;xi.prototype._options=function e(t){var r=xi.defaults;if(typeof t==="undefined"){return Object.assign({},r)}var n=t&&t.exceptions||{};var i=n.specials||[];var u=n.shift||{1:[]};return U(U(U({},r),t),{},{exceptions:{specials:[].concat(q(r.exceptions.specials),q(i)),shift:U(U({},u),{},{1:[].concat(q(r.exceptions.shift[1]),q(u[1]))})}})};xi.prototype.indent=function e(t){var r=Jn(this.__code__,true);return this._indent(r,t)};xi.exception_shift=function(u,e){function t(e){if(!e.length){return false}if(e.indexOf(u)!==-1){return true}else{var t=e.filter(function(e){return e instanceof RegExp});if(!t.length){return false}var r=Tr(t),n;try{for(r.s();!(n=r.n()).done;){var i=n.value;if(u.match(i)){return true}}}catch(e){r.e(e)}finally{r.f()}}return false}if(t(e.exceptions.specials)){return e.indent}var r=e.exceptions.shift;for(var n=0,i=Object.entries(r);n0){n.offset=0}if(u.toString()===t.toString()&&Wo(u)){return n.offset+u[0].col}else if(u.length===1){return n.offset+u[0].col+1}else{var s=-1;if(a){var c=xi.exception_shift(a.token,n);if(c!==-1){s=c}}if(s===-1){s=xi.exception_shift(u[1].token,n)}if(s!==-1){return n.offset+u[0].col+s}else if(u[0].line3&&u[1].line===u[3].line){if(u[1].token==="("||u[1].token==="["){return n.offset+u[1].col}return n.offset+u[3].col}else if(u[0].line===u[1].line){return n.offset+n.indent+u[0].col}else{var f=u.slice(2);for(var l=0;l")};Ei.prototype.match=function(e){return e.match(this.pattern)};function Fi(){for(var e=arguments.length,t=new Array(e),r=0;r")};xi.Pattern=Fi;xi.Ahead=Ei;var Ai=/^[[(]$/;var ki=/^[\])]$/;var Oi=/[^()[\]]/;var Ci=new Ei(/[^)\]]/);var Si=Symbol["for"]("*");var ji=new Fi([Ai,Si,ki],[Oi],"+");var Bi=new Fi([Ai,Si,ki],"+");var Ii=new Fi([Symbol["for"]("symbol")],"?");var Pi=new Fi([Symbol["for"]("symbol")],"*");var Ni=[Ai,Pi,ki];var Ti=new Fi([Ai,Symbol["for"]("symbol"),Si,ki],"+");var Li=Ui("syntax-rules");var Mi=Ui("define","lambda","define-macro","syntax-rules");var Ri=/^(?!.*\b(?:[()[\]]|define(?:-macro)?|let(?:\*|rec|-env|-syntax|)?|lambda|syntax-rules)\b).*$/;var qi=/^(?:#:)?(let(?:\*|rec|-env|-syntax)?)$/;function Ui(){for(var e=arguments.length,t=new Array(e),r=0;r0&&!o[e]){o[e]=bi(a,e)}});var s=Tr(i),c;try{for(s.s();!(c=s.n()).done;){var f=b(c.value,3),l=f[0],h=f[1],_=f[2];h=h.valueOf();var p=h>0?o[h]:a;var d=p.filter(function(e){return e.trim()&&!ni(e)});var v=r(p);var m=Di(l,d);var y=n.slice(u).find(function(e){return e.trim()&&!ni(e)});if(m&&(_ instanceof Ei&&_.match(y)||!_)){var g=u-v;if(n[g]!=="\n"){if(!n[g].trim()){n[g]="\n"}else{n.splice(g,0,"\n");u++}}u+=v;continue e}}}catch(e){s.e(e)}finally{s.f()}}this.__code__=n.join("");return this};xi.prototype._spaces=function(e){return" ".repeat(e)};xi.prototype.format=function e(t){var r=this.__code__.replace(/[ \t]*\n[ \t]*/g,"\n ");var n=Jn(r,true);var i=this._options(t);var u=0;var a=0;for(var o=0;o0){n=Math.floor(t()*r);r--;var i=[e[n],e[r]];e[r]=i[0];e[n]=i[1]}return e}function $i(){}$i.prototype.toString=function(){return"()"};$i.prototype.valueOf=function(){return undefined};$i.prototype.serialize=function(){return 0};$i.prototype.to_object=function(){return{}};$i.prototype.append=function(e){return new Y(e,$)};$i.prototype.to_array=function(){return[]};var $=new $i;function Y(e,t){if(typeof this!=="undefined"&&this.constructor!==Y||typeof this==="undefined"){return new Y(e,t)}this.car=e;this.cdr=t}function Yi(u,a){return function e(t){A(u,t,["pair","nil"]);if(K(t)){return[]}var r=[];var n=t;while(true){if(H(n)){if(n.have_cycles("cdr")){break}var i=n.car;if(a&&H(i)){i=this.get(u).call(this,i)}r.push(i);n=n.cdr}else if(K(n)){break}else{throw new Error("".concat(u,": can't convert improper list"))}}return r}}Y.prototype.flatten=function(){return Y.fromArray(zi(this.to_array()))};Y.prototype.length=function(){var e=0;var t=this;while(true){if(!t||K(t)||!H(t)||t.have_cycles("cdr")){break}e++;t=t.cdr}return e};Y.match=function(e,t){if(e instanceof V){return V.is(e,t)}else if(H(e)){return Y.match(e.car,t)||Y.match(e.cdr,t)}else if(Array.isArray(e)){return e.some(function(e){return Y.match(e,t)})}else if(Ki(e)){return Object.values(e).some(function(e){return Y.match(e,t)})}return false};Y.prototype.find=function(e){return Y.match(this,e)};Y.prototype.clone=function(){var r=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var n=new Map;function i(e){if(H(e)){if(n.has(e)){return n.get(e)}var t=new Y;n.set(e,t);if(r){t.car=i(e.car)}else{t.car=e.car}t.cdr=i(e.cdr);t[ea]=e[ea];return t}return e}return i(this)};Y.prototype.last_pair=function(){var e=this;while(true){if(!H(e.cdr)){return e}if(e.have_cycles("cdr")){break}e=e.cdr}};Y.prototype.to_array=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var t=[];if(H(this.car)){if(e){t.push(this.car.to_array())}else{t.push(this.car)}}else{t.push(this.car.valueOf())}if(H(this.cdr)){t=t.concat(this.cdr.to_array(e))}return t};Y.fromArray=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(H(e)||r&&e instanceof Array&&e[Zu]){return e}if(t===false){var n=$;for(var i=e.length;i--;){n=new Y(e[i],n)}return n}if(e.length&&!(e instanceof Array)){e=q(e)}var u=$;var a=e.length;while(a--){var o=e[a];if(o instanceof Array){o=Y.fromArray(o,t,r)}else if(typeof o==="string"){o=D(o)}else if(typeof o==="number"&&!Number.isNaN(o)){o=B(o)}u=new Y(o,u)}return u};Y.prototype.to_object=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var t=this;var r={};while(true){if(H(t)&&H(t.car)){var n=t.car;var i=n.car;if(i instanceof V){i=i.__name__}if(i instanceof D){i=i.valueOf()}var u=n.cdr;if(H(u)){u=u.to_object(e)}if(Lu(u)){if(!e){u=u.valueOf()}}r[i]=u;t=t.cdr}else{break}}return r};Y.fromPairs=function(e){return e.reduce(function(e,t){return new Y(new Y(new V(t[0]),t[1]),e)},$)};Y.fromObject=function(t){var e=Object.keys(t).map(function(e){return[e,t[e]]});return Y.fromPairs(e)};Y.prototype.reduce=function(e){var t=this;var r=$;while(true){if(!K(t)){r=e(r,t.car);t=t.cdr}else{break}}return r};Y.prototype.reverse=function(){if(this.have_cycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var t=$;while(!K(e)){var r=e.cdr;e.cdr=t;t=e;e=r}return t};Y.prototype.transform=function(n){function i(e){if(H(e)){if(e.replace){delete e.replace;return e}var t=n(e.car);if(H(t)){t=i(t)}var r=n(e.cdr);if(H(r)){r=i(r)}return new Y(t,r)}return e}return i(this)};Y.prototype.map=function(e){if(typeof this.car!=="undefined"){return new Y(e(this.car),K(this.cdr)?$:this.cdr.map(e))}else{return $}};var Ji=new Map;function Ki(e){return e&&_(e)==="object"&&e.constructor===Object}var Hi=Object.getOwnPropertyNames(Array.prototype);var Gi=[];Hi.forEach(function(e){Gi.push(Array[e],Array.prototype[e])});function Wi(e){e=Vu(e);return Gi.includes(e)}function Qi(e){return d(e)&&(ca(e)||e.__doc__)}function Zi(r){var e=r.constructor||Object;var n=Ki(r);var i=d(r[Symbol.asyncIterator])||d(r[Symbol.iterator]);var u;if(Ji.has(e)){u=Ji.get(e)}else{Ji.forEach(function(e,t){t=Vu(t);if(r instanceof t&&(t===Object&&n&&!i||t!==Object)){u=e}})}return u}var Xi=new Map;[[true,"#t"],[false,"#f"],[null,"null"],[undefined,"#"]].forEach(function(e){var t=b(e,2),r=t[0],n=t[1];Xi.set(r,n)});function eu(r){if(r&&_(r)==="object"){var n={};var e=Object.getOwnPropertySymbols(r);e.forEach(function(e){var t=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");n[t]=au(r[e])});var t=Object.getOwnPropertyNames(r);t.forEach(function(e){var t=r[e];if(t&&_(t)==="object"&&t.constructor===Object){n[e]=eu(t)}else{n[e]=au(t)}});return n}return r}function tu(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function ru(e,t){return e.hasOwnProperty(t)&&d(e.toString)}function nu(e){if(ha(e)){return"#"}var t=e.prototype&&e.prototype.constructor;if(d(t)&&ca(t)){if(e[ta]&&t.hasOwnProperty("__name__")){var r=t.__name__;if(D.isString(r)){r=r.toString();return"#")}return"#"}}if(e.hasOwnProperty("__name__")){var n=e.__name__;if(_(n)==="symbol"){n=Gn(n)}if(typeof n==="string"){return"#")}}if(ru(e,"toString")){return e.toString()}else if(e.name&&!ca(e)){return"#")}else{return"#"}}var iu=new Map;[[Error,function(e){return e.message}],[Y,function(e,t){var r=t.quote,n=t.skip_cycles,i=t.pair_args;if(!n){e.mark_cycles()}return e.toString.apply(e,[r].concat(q(i)))}],[h,function(e,t){var r=t.quote;if(r){return e.toString()}return e.valueOf()}],[D,function(e,t){var r=t.quote;e=e.toString();if(r){return JSON.stringify(e).replace(/\\n/g,"\n")}return e}],[RegExp,function(e){return"#"+e.toString()}]].forEach(function(e){var t=b(e,2),r=t[0],n=t[1];iu.set(r,n)});var uu=[V,J,ao,Ua,za,F,Zn];function au(e,t,r){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(Xi.has(e)){return Xi.get(e)}if(Fu(e)){return"#"}if(e){var n=e.constructor;if(iu.has(n)){for(var i=arguments.length,u=new Array(i>3?i-3:0),a=3;a"}if(e===null){return"null"}if(d(e)){if(d(e.toString)&&e.hasOwnProperty("toString")){return e.toString().valueOf()}return nu(e)}if(_(e)==="object"){var f=e.constructor;if(!f){f=Object}var l;if(typeof f.__class__==="string"){l=f.__class__}else{var h=Zi(e);if(h){if(d(h)){return h(e,t)}else{throw new Error("toString: Invalid repr value")}}l=f.name}if(d(e.toString)&&e.hasOwnProperty("toString")){return e.toString().valueOf()}if(Io(e)==="instance"){if(ca(f)&&f.__name__){l=f.__name__.valueOf()}else if(!ha(f)){l="instance"}}if(Pu(e,Symbol.iterator)){if(l){return"#")}return"#"}if(Pu(e,Symbol.asyncIterator)){if(l){return"#")}return"#"}if(l!==""){return"#<"+l+">"}return"#"}if(typeof e!=="string"){return e.toString()}return e}Y.prototype.mark_cycles=function(){su(this);return this};Y.prototype.have_cycles=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(!e){return this.have_cycles("car")||this.have_cycles("cdr")}return!!(this[ea]&&this[ea][e])};Y.prototype.is_cycle=function(){return ou(this)};function ou(e){if(!H(e)){return false}if(e.have_cycles()){return true}return ou(e.car,fn)||ou(e.cdr,fn)}function su(e){var t=[];var i=[];var u=[];function a(e){if(!t.includes(e)){t.push(e)}}function o(e,t,r,n){if(H(r)){if(n.includes(r)){if(!u.includes(r)){u.push(r)}if(!e[ea]){e[ea]={}}e[ea][t]=r;if(!i.includes(e)){i.push(e)}return true}}}var s=$n(function e(t,r){if(H(t)){delete t.ref;delete t[ea];a(t);r.push(t);var n=o(t,"car",t.car,r);var i=o(t,"cdr",t.cdr,r);if(!n){s(t.car,r.slice())}if(!i){return new Vn(function(){return e(t.cdr,r.slice())})}}});function r(e,t){if(H(e[ea][t])){var r=n.indexOf(e[ea][t]);e[ea][t]="#".concat(r,"#")}}s(e,[]);var n=t.filter(function(e){return u.includes(e)});n.forEach(function(e,t){e[Xu]="#".concat(t,"=")});i.forEach(function(e){r(e,"car");r(e,"cdr")})}Y.prototype.toString=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.nested,n=r===void 0?false:r;var i=[];if(this[Xu]){i.push(this[Xu]+"(")}else if(!n){i.push("(")}var u;if(this[ea]&&this[ea].car){u=this[ea].car}else{u=au(this.car,e,true)}if(u!==undefined){i.push(u)}if(H(this.cdr)){if(this[ea]&&this[ea].cdr){i.push(" . ");i.push(this[ea].cdr)}else{if(this.cdr[Xu]){i.push(" . ")}else{i.push(" ")}var a=this.cdr.toString(e,{nested:true});i.push(a)}}else if(!K(this.cdr)){i=i.concat([" . ",au(this.cdr,e,true)])}if(!n||this[Xu]){i.push(")")}return i.join("")};Y.prototype.set=function(e,t){this[e]=t;if(H(t)){this.mark_cycles()}};Y.prototype.append=function(e){if(e instanceof Array){return this.append(Y.fromArray(e))}var t=this;if(t.car===undefined){if(H(e)){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(!K(e)){while(true){if(H(t)&&!K(t.cdr)){t=t.cdr}else{break}}t.cdr=e}return this};Y.prototype.serialize=function(){return[this.car,this.cdr]};Y.prototype[Symbol.iterator]=function(){var r=this;return{next:function e(){var t=r;r=t.cdr;if(K(t)){return{value:undefined,done:true}}else{return{value:t.car,done:false}}}}};function cu(e){return e<0?-e:e}function fu(e,t){var r=re(t),n=r[0],i=r.slice(1);while(i.length>0){var u=i,a=b(u,1),o=a[0];if(!e(n,o)){return false}var s=i;var c=re(s);n=c[0];i=c.slice(1)}return true}function lu(e,t){if(d(e)){return d(t)&&Vu(e)===Vu(t)}else if(e instanceof B){if(!(t instanceof B)){return false}var r;if(e.__type__===t.__type__){if(e.__type__==="complex"){r=e.__im__.__type__===t.__im__.__type__&&e.__re__.__type__===t.__re__.__type__}else{r=true}if(r&&e.cmp(t)===0){if(e.valueOf()===0){return Object.is(e.valueOf(),t.valueOf())}return true}}return false}else if(typeof e==="number"){if(typeof t!=="number"){return false}if(Number.isNaN(e)){return Number.isNaN(t)}if(e===Number.NEGATIVE_INFINITY){return t===Number.NEGATIVE_INFINITY}if(e===Number.POSITIVE_INFINITY){return t===Number.POSITIVE_INFINITY}return lu(B(e),B(t))}else if(e instanceof h){if(!(t instanceof h)){return false}return e.__char__===t.__char__}else{return e===t}}function hu(e,t){if(Io(e)!==Io(t)){return false}if(!_u(e)){return false}if(e instanceof RegExp){return e.source===t.source}if(e instanceof D){return e.valueOf()===t.valueOf()}return lu(e,t)}function _u(e){return e instanceof V||D.isString(e)||K(e)||e===null||e instanceof h||e instanceof B||e===true||e===false}var pu=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e===0){return 0}else if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function J(e,t,r,n){if(typeof this!=="undefined"&&this.constructor!==J||typeof this==="undefined"){return new J(e,t)}A("Macro",e,"string",1);A("Macro",t,"function",2);if(r){if(n){this.__doc__=r}else{this.__doc__=gi(r)}}this.__name__=e;this.__fn__=t}J.defmacro=function(e,t,r,n){var i=new J(e,t,r,n);i.__defmacro__=true;return i};J.prototype.invoke=function(e,t,r){var n=t.env,i=he(t,kr);var u=U(U({},i),{},{macro_expand:r});var a=this.__fn__.call(n,e,u,this.__name__);return a};J.prototype.toString=function(){return"#")};var du="define-macro";var vu=-1e4;function mu(c){return function(){var r=ie(O.mark(function e(r,y){var u,g,n,i,a,b,w,D,x,E,F,A,o,k,s;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:s=function e(){s=ie(O.mark(function e(r,n,i){var u,a,o,s,c,f,l,h,_,p,d,v,m;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!(H(r)&&r.car instanceof V)){t.next=50;break}if(!r[Zu]){t.next=3;break}return t.abrupt("return",r);case 3:u=r.car.valueOf();a=i.get(r.car,{throwError:false});o=b(r.car);s=o||w(a,r)||D(a);if(!(s&&H(r.cdr.car))){t.next=28;break}if(!o){t.next=15;break}g=E(r.cdr.car);t.next=12;return A(r.cdr.car,n);case 12:c=t.sent;t.next=17;break;case 15:g=x(r.cdr.car);c=r.cdr.car;case 17:t.t0=Y;t.t1=r.car;t.t2=Y;t.t3=c;t.next=23;return k(r.cdr.cdr,n,i);case 23:t.t4=t.sent;t.t5=new t.t2(t.t3,t.t4);return t.abrupt("return",new t.t0(t.t1,t.t5));case 28:if(!F(u,a)){t.next=50;break}f=a instanceof yu?r:r.cdr;t.next=32;return a.invoke(f,U(U({},y),{},{env:i}),true);case 32:l=t.sent;if(!(a instanceof yu)){t.next=41;break}h=l,_=h.expr,p=h.scope;if(!H(_)){t.next=40;break}if(!(n!==-1&&n<=1||n")}return"#"};var gu=ce(function e(t){ue(this,e);c(this,"_syntax",t,{hidden:true});c(this._syntax,"_param",true,{hidden:true})});yu.Parameter=gu;function bu(e,t,P,N){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:{};var T={"...":{symbols:{},lists:[]},symbols:{}};var L=r.expansion,M=r.define;z(P);function R(t,e){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:false;z({code:e,pattern:t});if(_u(t)&&!(t instanceof V)){return hu(t,e)}if(t instanceof V&&P.includes(t.literal())){if(!V.is(e,t)){return false}var i=L.ref(t);return!i||i===M||i===G}if(Array.isArray(t)&&Array.isArray(e)){z("<<< a 1");if(t.length===0&&e.length===0){return true}if(V.is(t[1],N)){if(t[0]instanceof V){var u=t[0].valueOf();z("<<< a 2 "+n);if(n){var a=e.length-2;var o=a>0?e.slice(0,a):e;var s=Y.fromArray(o,false);if(!T["..."].symbols[u]){T["..."].symbols[u]=new Y(s,$)}else{T["..."].symbols[u].append(new Y(s,$))}}else{T["..."].symbols[u]=Y.fromArray(e,false)}}else if(Array.isArray(t[0])){z("<<< a 3");var c=q(r);if(!e.every(function(e){return R(t[0],e,c,true)})){return false}}if(t.length>2){var f=t.slice(2);return R(f,e.slice(-f.length),r,n)}return true}var l=R(t[0],e[0],r,n);z({first:l,pattern:t[0],code:e[0]});var h=R(t.slice(1),e.slice(1),r,n);z({first:l,rest:h});return l&&h}if(H(t)&&H(t.car)&&H(t.car.cdr)&&V.is(t.car.cdr.car,N)){z(">> 0");if(K(e)){z({pattern:t});if(t.car.car instanceof V){var _=t.car.car.valueOf();if(T["..."].symbols[_]){throw new Error("syntax: named ellipsis can only "+"appear onces")}T["..."].symbols[_]=e}}}if(H(t)&&H(t.cdr)&&V.is(t.cdr.car,N)){if(!K(t.cdr.cdr)){if(H(t.cdr.cdr)){var p=t.cdr.cdr.length();if(!H(e)){return false}var d=e.length();var v=e;while(d-1>p){v=v.cdr;d--}var m=v.cdr;v.cdr=$;if(!R(t.cdr.cdr,m,r,n)){return false}}}if(t.car instanceof V){var y=t.car.__name__;if(T["..."].symbols[y]&&!r.includes(y)&&!n){throw new Error("syntax: named ellipsis can only appear onces")}z(">> 1");if(K(e)){z(">> 2");if(n){z("NIL");T["..."].symbols[y]=$}else{z("NULL");T["..."].symbols[y]=null}}else if(H(e)&&(H(e.car)||K(e.car))){z(">> 3 "+n);if(n){if(T["..."].symbols[y]){var g=T["..."].symbols[y];if(K(g)){g=new Y($,new Y(e,$))}else{g=g.append(new Y(e,$))}T["..."].symbols[y]=g}else{T["..."].symbols[y]=new Y(e,$)}}else{z(">> 4");T["..."].symbols[y]=new Y(e,$)}}else{z(">> 6");if(H(e)){if(!H(e.cdr)&&!K(e.cdr)){z(">> 7 (b)");if(K(t.cdr.cdr)){return false}else if(!T["..."].symbols[y]){T["..."].symbols[y]=new Y(e.car,$);return R(t.cdr.cdr,e.cdr)}}var b=e.last_pair();if(!K(b.cdr)){if(K(t.cdr.cdr)){return false}else{var w=e.clone();w.last_pair().cdr=$;T["..."].symbols[y]=w;return R(t.cdr.cdr,b.cdr)}}z(">> 7 "+n);r.push(y);if(!T["..."].symbols[y]){T["..."].symbols[y]=new Y(e,$)}else{var D=T["..."].symbols[y];T["..."].symbols[y]=D.append(new Y(e,$))}z({IIIIII:T["..."].symbols[y]})}else if(t.car instanceof V&&H(t.cdr)&&V.is(t.cdr.car,N)){z(">> 8");T["..."].symbols[y]=null;return R(t.cdr.cdr,e)}else{z(">> 9");return false}}return true}else if(H(t.car)){var x=q(r);if(K(e)){z(">> 10");T["..."].lists.push($);return true}z(">> 11");var E=e;while(H(E)){if(!R(t.car,E.car,x,true)){return false}E=E.cdr}return true}if(Array.isArray(t.car)){var x=q(r);var F=e;while(H(F)){if(!R(t.car,F.car,x,true)){return false}F=F.cdr}return true}return false}if(t instanceof V){if(V.is(t,N)){throw new Error("syntax: invalid usage of ellipsis")}z(">> 12");var A=t.__name__;if(P.includes(A)){return true}if(n){var k,O;z(T["..."].symbols[A]);(O=(k=T["..."].symbols)[A])!==null&&O!==void 0?O:k[A]=[];T["..."].symbols[A].push(e)}else{T.symbols[A]=e}return true}if(H(t)&&H(e)){z(">> 13");z({a:13,code:e,pattern:t});if(K(e.cdr)){var C=t.car instanceof V&&t.cdr instanceof V;if(C){if(!R(t.car,e.car,r,n)){return false}z(">> 14");var S=t.cdr.valueOf();if(!(S in T.symbols)){T.symbols[S]=$}S=t.car.valueOf();if(!(S in T.symbols)){T.symbols[S]=e.car}return true}}z({pattern:t,code:e});if(H(t.cdr)&&H(t.cdr.cdr)&&t.cdr.car instanceof V&&V.is(t.cdr.cdr.car,N)&&H(t.cdr.cdr.cdr)&&!V.is(t.cdr.cdr.cdr.car,N)&&R(t.car,e.car,r,n)&&R(t.cdr.cdr.cdr,e.cdr,r,n)){var j=t.cdr.car.__name__;z({pattern:t,code:e,name:j});if(P.includes(j)){return true}T["..."].symbols[j]=null;return true}z("recur");z({pattern:t,code:e});var B=R(t.car,e.car,r,n);z({car:B,pattern:t.car,code:e.car});var I=R(t.cdr,e.cdr,r,n);z({car:B,cdr:I});if(B&&I){return true}}else if(K(t)&&(K(e)||e===undefined)){return true}else if(H(t.car)&&V.is(t.car.car,N)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(R(e,t)){return T}}function wu(e,i){function u(t){if(H(t)){if(!i.length){return t}var e=u(t.car);var r=u(t.cdr);return new Y(e,r)}else if(t instanceof V){var n=i.find(function(e){return e.gensym===t});if(n){return V(n.name)}return t}else{return t}}return u(e)}function Du(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var B=e.bindings,t=e.expr,I=e.scope,a=e.symbols,f=e.names,P=e.ellipsis;var l={};function o(e){if(e instanceof V){return true}return["string","symbol"].includes(_(e))}function N(e){if(!o(e)){var t=Io(e);throw new Error("syntax: internal error, need symbol got ".concat(t))}var r=e.valueOf();if(r===P){throw new Error("syntax: internal error, ellipis not transformed")}var n=_(r);if(["string","symbol"].includes(n)){if(r in B.symbols){return B.symbols[r]}else if(n==="string"&&r.match(/\./)){var i=r.split(".");var u=i[0];if(u in B.symbols){return Y.fromArray([V("."),B.symbols[u]].concat(i.slice(1).map(function(e){return D(e)})))}}}if(a.includes(r)){return e}return s(r,e)}function s(e,t){if(!l[e]){var r=I.ref(e);if(_(e)==="symbol"&&!r){e=t.literal()}if(l[e]){return l[e]}var n=Qn(e);if(r){var i=I.get(e);I.set(n,i)}else{var u=I.get(e,{throwError:false});if(typeof u!=="undefined"){I.set(n,u)}}f.push({name:e,gensym:n});l[e]=n;if(typeof e==="string"&&e.match(/\./)){var a=e.split(".").filter(Boolean),o=re(a),s=o[0],c=o.slice(1);if(l[s]){oa(n,"__object__",[l[s]].concat(q(c)))}}}return l[e]}function T(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:function(){};var i=r.nested;z({bindings:t,expr:e});if(Array.isArray(e)&&!e.length){return e}if(e instanceof V){var u=e.valueOf();if(Wn(e)&&!t[u]);z("[t 1");if(t[u]){if(H(t[u])){var a=t[u],o=a.car,s=a.cdr;if(i){var c=o.car,f=o.cdr;if(!K(f)){n(u,new Y(f,$))}return c}if(!K(s)){n(u,s)}return o}else if(t[u]instanceof Array){n(u,t[u].slice(1));return t[u][0]}}return N(e)}var l=Array.isArray(e);if(H(e)||l){var h=l?e[0]:e.car;var _=l?e[1]:H(e.cdr)&&e.cdr.car;if(h instanceof V&&V.is(_,P)){l?e.slice(2):e.cdr.cdr;z("[t 2");var p=h.valueOf();var d=t[p];if(d===null){return}else if(d){z({name:p,binding:t[p]});if(H(d)){z("[t 2 Pair "+i);var v=d.car,m=d.cdr;var y=l?e.slice(2):e.cdr.cdr;if(i){if(!K(m)){z("|| next 1");n(p,m)}if(l&&y.length||!K(y)&&!l){var g=T(y,t,r,n);if(l){return v.concat(g)}else if(H(v)){return v.append(g)}else{z("UNKNOWN")}}return v}else if(H(v)){if(!K(v.cdr)){z("|| next 2");n(p,new Y(v.cdr,m))}return v.car}else if(K(m)){return v}else{var b=e.last_pair();if(b.cdr instanceof V){z("|| next 3");n(p,d.last_pair());return v}}}else if(d instanceof Array){z("[t 2 Array "+i);if(i){n(p,d.slice(1));return Y.fromArray(d)}else{var w=d.slice(1);if(w.length){n(p,w)}return d[0]}}else{return d}}}z("[t 3 recur ",e);var D=l?e.slice(1):e.cdr;var x=T(h,t,r,n);var E=T(D,t,r,n);z({head:x,rest:E});if(l){return[x].concat(E)}return new Y(x,E)}return e}function L(t,r){var e=Object.values(t);var n=Object.getOwnPropertySymbols(t);if(n.length){e.push.apply(e,q(n.map(function(e){return t[e]})))}return e.length&&e.every(function(e){if(e===null){return!r}return H(e)||K(e)||Array.isArray(e)&&e.length})}function M(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function R(i){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},t=e.disabled;z("traverse>> ",i);var u=Array.isArray(i);if(u&&i.length===0){return i}if(H(i)||u){var r=u?i[0]:i.car;var n,a;if(u){n=i[1];a=i.slice(2)}else if(H(i.cdr)){n=i.cdr.car;a=i.cdr.cdr}z({first:r,second:n,rest_second:a});if(!t&&H(r)&&V.is(r.car,P)){return R(r.cdr,{disabled:true})}if(n&&V.is(n,P)&&!t){z(">> 1");var o=B["..."].symbols;var s=Object.values(o);if(s.length&&s.every(function(e){return e===null})){z(">>> 1 (a)");return R(a,{disabled:t})}var c=M(o);var f=r instanceof V&&V.is(a.car,P);if(H(r)||f){z(">>> 1 (b)");if(K(B["..."].lists[0])){if(!f){return R(a,{disabled:t})}z(a);return $}var l=r;if(f){z(">>> 1 (c)");l=new Y(r,new Y(n,$))}z(">> 2");var h;if(c.length){z(">> 2 (a)");var _=U({},o);h=u?[]:$;var p=function e(){z({bind:_});if(!L(_)){return 1}var n={};var t=function e(t,r){n[t]=r};var r=T(l,_,{nested:true},t);if(r!==undefined){if(f){if(u){if(Array.isArray(r)){var i;(i=h).push.apply(i,q(r))}else{z("ZONK {1}")}}else{if(K(h)){h=r}else{h=h.append(r)}}}else if(u){h.push(r)}else{h=new Y(r,h)}}_=n};while(true){if(p())break}if(!K(h)&&!f&&!u){h=h.reverse()}if(u){if(a){z({rest_second:a,expr:i});var d=R(a,{disabled:t});return h.concat(d)}return h}if(!K(i.cdr.cdr)&&!V.is(i.cdr.cdr.car,P)){var v=R(i.cdr.cdr,{disabled:t});return h.append(v)}return h}else{z(">> 3");var m=T(r,o,{nested:true});if(m){return new Y(m,$)}return $}}else if(r instanceof V){z(">> 4");if(V.is(a.car,P)){z(">> 4 (a)")}else{z(">> 4 (b)")}var y=r.__name__;var g=fe({},y,o[y]);z({bind:g});var b=o[y]===null;var w=u?[]:$;var D=function e(){if(!L(g,true)){z({bind:g});return 1}var n={};var t=function e(t,r){n[t]=r};var r=T(i,g,{nested:false},t);z({value:r});if(typeof r!=="undefined"){if(u){w.push(r)}else{w=new Y(r,w)}}g=n};while(true){if(D())break}if(!K(w)&&!u){w=w.reverse()}if(H(i.cdr)){if(H(i.cdr.cdr)||i.cdr.cdr instanceof V){var x=R(i.cdr.cdr,{disabled:t});z({node:x});if(b){return x}if(K(w)){w=x}else{w.append(x)}z({result:w,node:x})}}z("<<<< 2");return w}}var E=R(r,{disabled:t});var F;var A;if(r instanceof V){var k=I.get(r,{throwError:false});A=k instanceof J&&k.__name__==="syntax-rules"}if(A){if(i.cdr.car instanceof V){F=new Y(R(i.cdr.car,{disabled:t}),new Y(i.cdr.cdr.car,R(i.cdr.cdr.cdr,{disabled:t})))}else{F=new Y(i.cdr.car,R(i.cdr.cdr,{disabled:t}))}z("REST >>>> ",F)}else{F=R(i.cdr,{disabled:t})}z({a:true,car:au(i.car),cdr:au(i.cdr),head:au(E),rest:au(F)});return new Y(E,F)}if(i instanceof V){if(t&&V.is(i,P)){return i}var O=Object.keys(B["..."].symbols);var C=i.literal();if(O.includes(C)){var S="missing ellipsis symbol next to name `".concat(C,"'");throw new Error("syntax-rules: ".concat(S))}var j=N(i);if(typeof j!=="undefined"){return j}}return i}return R(t,{})}function xu(e){return Iu(e)||K(e)||e===null}function K(e){return e===$}function d(e){return typeof e==="function"&&typeof e.bind==="function"}function Eu(e){return typeof e==="string"}function Fu(e){return e&&_(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}function Au(e){return e instanceof Yo}function ku(e){return e instanceof Vo}function Ou(e){return e instanceof zo}function H(e){return e instanceof Y}function Cu(e){return e instanceof F}function Su(e){return d(e)||Au(e)||Ou(e)||ju(e)}function ju(e){return e instanceof J||e instanceof gu}function Bu(e){if(e instanceof Zn){return false}if(e instanceof Promise){return true}return!!e&&d(e.then)}function Iu(e){return typeof e==="undefined"}function Pu(e,t){if(Mu(e,t)||Mu(e.__proto__,t)){return d(e[t])}}function Nu(e){if(!e){return false}if(_(e)!=="object"){return false}if(e.__instance__){e.__instance__=false;return e.__instance__}return false}function Tu(e){var t=_(e);return["string","function"].includes(t)||_(e)==="symbol"||e instanceof Zn||e instanceof V||e instanceof B||e instanceof D||e instanceof RegExp}function Lu(e){return e instanceof B||e instanceof D||e instanceof h}function Mu(e,t){if(e===null){return false}return _(e)==="object"&&t in Object.getOwnPropertySymbols(e)}function Ru(e){switch(_(e)){case"string":return D(e);case"bigint":return B(e);case"number":if(Number.isNaN(e)){return _o}else{return B(e)}}return e}function qu(r,n){var e=Object.getOwnPropertyNames(r);var t=Object.getOwnPropertySymbols(r);var i={};e.concat(t).forEach(function(e){var t=n(r[e]);i[e]=t});return i}function Uu(t){var e=[D,B].some(function(e){return t instanceof e});if(e){return t.valueOf()}if(t instanceof Array){return t.map(Uu)}if(t instanceof Zn){delete t.then}if(Ki(t)){return qu(t,Uu)}return t}function zu(e,t){if(H(e)){e.mark_cycles();return oo(e)}if(d(e)){if(t){return $u(e,t)}}return Ru(e)}function Vu(e){if(Ju(e)){return e[Qu]}return e}function $u(e,t){if(e[Symbol["for"]("__bound__")]){return e}var r=e.bind(t);var n=Object.getOwnPropertyNames(e);var i=Tr(n),u;try{for(i.s();!(u=i.n()).done;){var a=u.value;if(aa(a)){try{r[a]=e[a]}catch(e){}}}}catch(e){i.e(e)}finally{i.f()}oa(r,"__fn__",e);oa(r,"__context__",t);oa(r,"__bound__",true);if(ha(e)){oa(r,"__native__",true)}if(Ki(t)&&ca(e)){oa(r,"__method__",true)}r.valueOf=function(){return e};return r}function Yu(e){return Ju(e)&&e[Symbol["for"]("__context__")]===Object}function Ju(e){return!!(d(e)&&e[Qu])}function Ku(e){if(d(e)){var t=e[Wu];if(t&&(t===Cs||t.constructor&&t.constructor.__class__)){return true}}return false}function Hu(e){return e instanceof Ua||e instanceof za}function Gu(e){if(d(e)){if(Hu(e[Wu])){return true}}return false}var Wu=Symbol["for"]("__context__");var Qu=Symbol["for"]("__fn__");var Zu=Symbol["for"]("__data__");var Xu=Symbol["for"]("__ref__");var ea=Symbol["for"]("__cycles__");var ta=Symbol["for"]("__class__");var ra=Symbol["for"]("__method__");var na=Symbol["for"]("__prototype__");var ia=Symbol["for"]("__lambda__");var ua=["name","length","caller","callee","arguments","prototype"];function aa(e){return!ua.includes(e)}function oa(e,t,r){Object.defineProperty(e,Symbol["for"](t),{get:function e(){return r},set:function e(){},configurable:false,enumerable:false})}function sa(t,r){try{Object.defineProperty(t,"length",{get:function e(){return r}});return t}catch(e){var n=new Array(r).fill(0).map(function(e,t){return"a"+t}).join(",");var i=new Function("f","return function(".concat(n,") {\n return f.apply(this, arguments);\n };"));return i(t)}}function ca(e){return e&&e[ia]}function fa(e){return e&&e[ra]}function la(e){return ca(e)&&!e[na]&&!fa(e)&&!Gu(e)}function ha(e){var t=Symbol["for"]("__native__");return d(e)&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[t]===true||!e.name.match(/^bound /)&&!e[t])}function _a(e){var b;switch(e){case Symbol["for"]("letrec"):b="letrec";break;case Symbol["for"]("let"):b="let";break;case Symbol["for"]("let*"):b="let*";break;default:throw new Error("Invalid let_macro value")}return J.defmacro(b,function(t,e){var f=e.dynamic_env;var l=e.error,r=e.macro_expand,h=e.use_dynamic;var _;if(t.car instanceof V){if(!(H(t.cdr.car)||K(t.cdr.car))){throw new Error("let require list of pairs")}var n;if(K(t.cdr.car)){_=$;n=$}else{n=t.cdr.car.map(function(e){return e.car});_=t.cdr.car.map(function(e){return e.cdr.car})}return Y.fromArray([V("letrec"),[[t.car,Y(V("lambda"),Y(n,t.cdr.cdr))]],Y(t.car,_)])}else if(r){return}var p=this;_=G.get("list->array")(t.car);var d=p.inherit(b);var v,m;if(b==="let*"){m=d}else if(b==="let"){v=[]}var y=0;function g(){var e=new Y(new V("begin"),t.cdr);return k(e,{env:d,dynamic_env:d,use_dynamic:h,error:l})}return function t(){var r=_[y++];f=b==="let*"?d:p;if(!r){if(v&&v.length){var e=v.map(function(e){return e.value});var n=e.filter(Bu);if(n.length){return Xn(e).then(function(e){for(var t=0,r=e.length;t1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=t.error;var i=this;var u=this;var a=[];var o=e;while(H(o)){a.push(k(o.car,{env:i,dynamic_env:u,use_dynamic:r,error:n}));o=o.cdr}var s=a.filter(Bu).length;if(s){return Xn(a).then(c.bind(this))}else{return c.call(this,a)}})}function da(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n2?n-2:0),u=2;u1&&arguments[1]!==undefined?arguments[1]:null;return function(){for(var e=arguments.length,t=new Array(e),r=0;r1?e-1:0),r=1;r=a){return u.apply(this,n)}else{return i}}return i.apply(this,arguments)}}function Ea(n,i){A("limit",i,"function",2);return function(){for(var e=arguments.length,t=new Array(e),r=0;r1){e=e.toLowerCase();if(h.__names__[e]){t=e;e=h.__names__[e]}else{throw new Error("Internal: Unknown named character")}}else{t=h.__rev_names__[e]}Object.defineProperty(this,"__char__",{value:e,enumerable:true});if(t){Object.defineProperty(this,"__name__",{value:t,enumerable:true})}}h.__names__=sn;h.__rev_names__={};Object.keys(h.__names__).forEach(function(e){var t=h.__names__[e];h.__rev_names__[t]=e});h.prototype.toUpperCase=function(){return h(this.__char__.toUpperCase())};h.prototype.toLowerCase=function(){return h(this.__char__.toLowerCase())};h.prototype.toString=function(){return"#\\"+(this.__name__||this.__char__)};h.prototype.valueOf=h.prototype.serialize=function(){return this.__char__};function D(e){if(typeof this!=="undefined"&&!(this instanceof D)||typeof this==="undefined"){return new D(e)}if(e instanceof Array){this.__string__=e.map(function(e,t){A("LString",e,"character",t+1);return e.toString()}).join("")}else{this.__string__=e.valueOf()}}{var Fa=["length","constructor"];var Aa=Object.getOwnPropertyNames(String.prototype).filter(function(e){return!Fa.includes(e)});var ka=function e(n){return function(){for(var e=arguments.length,t=new Array(e),r=0;r0){r.push(this.__string__.substring(0,e))}r.push(t);if(e1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof B){return e}if(typeof this!=="undefined"&&!(this instanceof B)||typeof this==="undefined"){return new B(e,t)}if(typeof e==="undefined"){throw new Error("Invalid LNumber constructor call")}var r=B.getType(e);if(B.types[r]){return B.types[r](e,t)}var n=e instanceof Array&&D.isString(e[0])&&B.isNumber(e[1]);if(e instanceof B){return B(e.value)}if(!B.isNumber(e)&&!n){throw new Error("You can't create LNumber from ".concat(Io(e)))}if(e===null){e=0}var i;if(n){var u=e,a=b(u,2),o=a[0],s=a[1];if(o instanceof D){o=o.valueOf()}if(s instanceof B){s=s.valueOf()}var c=o.match(/^([+-])/);var f=false;if(c){o=o.replace(/^[+-]/,"");if(c[1]==="-"){f=true}}}if(Number.isNaN(e)){return g(e)}else if(n&&Number.isNaN(parseInt(o,s))){return _o}else if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(n){var l;switch(s){case 8:l="0o";break;case 16:l="0x";break;case 2:l="0b";break;case 10:l="";break}if(typeof l==="undefined"){var h=BigInt(s);i=q(o).map(function(e,t){return BigInt(parseInt(e,s))*Na(h,BigInt(t))}).reduce(function(e,t){return e+t})}else{i=BigInt(l+o)}}else{i=BigInt(e)}if(f){i*=BigInt(-1)}}else{i=e}return E(i,true)}else if(typeof Hr!=="undefined"&&!(e instanceof Hr)){if(e instanceof Array){return E(L(Hr,q(e)))}return E(new Hr(e))}else if(n){this.constant(parseInt(o,s),"integer")}else{this.constant(e,"integer")}}B.prototype.constant=function(e,t){Object.defineProperty(this,"__value__",{value:e,enumerable:true});Object.defineProperty(this,"__type__",{value:t,enumerable:true})};B.types={float:function e(t){return new g(t)},complex:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!B.isComplex(t)){t={im:0,re:t}}return new y(t,r)},rational:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!B.isRational(t)){t={num:t,denom:1}}return new x(t,r)}};B.prototype.serialize=function(){return this.__value__};B.prototype.isNaN=function(){return Number.isNaN(this.__value__)};B.prototype.gcd=function(e){var t=this.abs();e=e.abs();if(e.cmp(t)===1){var r=t;t=e;e=r}while(true){t=t.rem(e);if(t.cmp(0)===0){return e}e=e.rem(t);if(e.cmp(0)===0){return t}}};B.isFloat=function e(t){return t instanceof g||Number(t)===t&&t%1!==0};B.isNumber=function(e){return e instanceof B||B.isNative(e)||B.isBN(e)};B.isComplex=function(e){if(!e){return false}var t=e instanceof y||(B.isNumber(e.im)||B.isRational(e.im)||Number.isNaN(e.im))&&(B.isNumber(e.re)||B.isRational(e.re)||Number.isNaN(e.re));return t};B.isRational=function(e){if(!e){return false}return e instanceof x||B.isNumber(e.num)&&B.isNumber(e.denom)};B.isInteger=function(e){if(!(B.isNative(e)||e instanceof B)){return false}if(B.isFloat(e)){return false}if(B.isRational(e)){return false}if(B.isComplex(e)){return false}return true};B.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};B.isBigInteger=function(e){return e instanceof E||typeof e==="bigint"||B.isBN(e)};B.isBN=function(e){return typeof Hr!=="undefined"&&e instanceof Hr};B.getArgsType=function(e,t){if(e instanceof g||t instanceof g){return g}if(e instanceof E||t instanceof E){return E}return B};B.prototype.toString=function(e){if(Number.isNaN(this.__value__)){return"+nan.0"}if(e>=2&&e<36){return this.__value__.toString(e)}return this.__value__.toString()};B.prototype.asType=function(e){var t=B.getType(this);return B.types[t]?B.types[t](e):B(e)};B.prototype.isBigNumber=function(){return typeof this.__value__==="bigint"||typeof Hr!=="undefined"&&!(this.value instanceof Hr)};["floor","ceil","round"].forEach(function(e){B.prototype[e]=function(){if(this["float"]||B.isFloat(this.__value__)){return B(Math[e](this.__value__))}else{return B(Math[e](this.valueOf()))}}});B.prototype.valueOf=function(){if(B.isNative(this.__value__)){return Number(this.__value__)}else if(B.isBN(this.__value__)){return this.__value__.toNumber()}};var ja=function(){var e=function e(t,r){return[t,r]};return{bigint:{bigint:e,float:function e(t,r){return[g(t.valueOf()),r]},rational:function e(t,r){return[{num:t,denom:1},r]},complex:function e(t,r){return[{im:0,re:t},r]}},integer:{integer:e,float:function e(t,r){return[g(t.valueOf()),r]},rational:function e(t,r){return[{num:t,denom:1},r]},complex:function e(t,r){return[{im:0,re:t},r]}},float:{bigint:function e(t,r){return[t,r&&g(r.valueOf())]},integer:function e(t,r){return[t,r&&g(r.valueOf())]},float:e,rational:function e(t,r){return[t,r&&g(r.valueOf())]},complex:function e(t,r){return[{re:t,im:g(0)},r]}},complex:{bigint:t("bigint"),integer:t("integer"),float:t("float"),rational:t("rational"),complex:function e(t,r){var n=B.coerce(t.__re__,r.__re__),i=b(n,2),u=i[0],a=i[1];var o=B.coerce(t.__im__,r.__im__),s=b(o,2),c=s[0],f=s[1];return[{im:c,re:u},{im:f,re:a}]}},rational:{bigint:function e(t,r){return[t,r&&{num:r,denom:1}]},integer:function e(t,r){return[t,r&&{num:r,denom:1}]},float:function e(t,r){return[g(t.valueOf()),r]},rational:e,complex:function e(t,r){return[{im:Ba(t.__type__,r.__im__.__type__,0)[0],re:Ba(t.__type__,r.__re__.__type__,t)[0]},{im:Ba(t.__type__,r.__im__.__type__,r.__im__)[0],re:Ba(t.__type__,r.__re__.__type__,r.__re__)[0]}]}}};function t(r){return function(e,t){return[{im:Ba(r,e.__im__.__type__,0,e.__im__)[1],re:Ba(r,e.__re__.__type__,0,e.__re__)[1]},{im:Ba(r,e.__im__.__type__,0,0)[1],re:Ba(r,t.__type__,0,t)[1]}]}}}();function Ba(e,t,r,n){return ja[e][t](r,n)}B.coerce=function(e,t){var r=B.getType(e);var n=B.getType(t);if(!ja[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!ja[r][n]){throw new Error("LNumber::coerce unknown rhs type ".concat(n))}var i=ja[r][n](e,t);return i.map(function(e){return B(e,true)})};B.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof B)){throw new Error("LNumber: you can't coerce ".concat(Io(e)))}if(typeof e==="number"){e=B(e)}return B.coerce(this,e)};B.getType=function(e){if(e instanceof B){return e.__type__}if(B.isFloat(e)){return"float"}if(B.isComplex(e)){return"complex"}if(B.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof Hr!=="undefined"&&!(e instanceof Hr)){return"bigint"}};B.prototype.isFloat=function(){return!!(B.isFloat(this.__value__)||this["float"])};var Ia={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var Pa={};Object.keys(Ia).forEach(function(t){Pa[Ia[t]]=t;B.prototype[t]=function(e){return this.op(Ia[t],e)}});B._ops={"*":function e(t,r){return t*r},"+":function e(t,r){return t+r},"-":function e(t,r){if(typeof r==="undefined"){return-t}return t-r},"/":function e(t,r){return t/r},"%":function e(t,r){return t%r},"|":function e(t,r){return t|r},"&":function e(t,r){return t&r},"~":function e(t){return~t},">>":function e(t,r){return t>>r},"<<":function e(t,r){return t<1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof y)||typeof this==="undefined"){return new y(e,t)}if(e instanceof y){return y({im:e.__im__,re:e.__re__})}if(B.isNumber(e)&&t){if(!t){return Number(e)}}else if(!B.isComplex(e)){var r="Invalid constructor call for LComplex expect &(:im :re ) object but got ".concat(au(e));throw new Error(r)}var n=e.im instanceof B?e.im:B(e.im);var i=e.re instanceof B?e.re:B(e.re);this.constant(n,i)}y.prototype=Object.create(B.prototype);y.prototype.constructor=y;y.prototype.constant=function(e,t){Object.defineProperty(this,"__im__",{value:e,enumerable:true});Object.defineProperty(this,"__re__",{value:t,enumerable:true});Object.defineProperty(this,"__type__",{value:"complex",enumerable:true})};y.prototype.serialize=function(){return{re:this.__re__,im:this.__im__}};y.prototype.toRational=function(e){if(B.isFloat(this.__im__)&&B.isFloat(this.__re__)){var t=g(this.__im__).toRational(e);var r=g(this.__re__).toRational(e);return y({im:t,re:r})}return this};y.prototype.pow=function(e){e.cmp(0);if(e===0){return B(1)}var t=B(Math.atan2(this.__im__.valueOf(),this.__re__.valueOf()));var r=B(this.modulus());if(B.isComplex(e)&&e.__im__.cmp(0)!==0){var n=e.mul(Math.log(r.valueOf())).add(y.i.mul(t).mul(e));var i=g(Math.E).pow(n.__re__.valueOf());return y({re:i.mul(Math.cos(n.__im__.valueOf())),im:i.mul(Math.sin(n.__im__.valueOf()))})}var u=e.__re__.cmp(0)>0;e=e.__re__.valueOf();if(B.isInteger(e)&&u){var a=this;while(--e){a=a.mul(this)}return a}var o=r.pow(e);var s=t.mul(e);return y({re:o.mul(Math.cos(s)),im:o.mul(Math.sin(s))})};y.prototype.add=function(e){return this.complex_op("add",e,function(e,t,r,n){return{re:e.add(t),im:r.add(n)}})};y.prototype.factor=function(){if(this.__im__ instanceof g||this.__im__ instanceof g){var e=this.__re__,t=this.__im__;var r,n;if(e instanceof g){r=e.toRational().mul(e.toRational())}else{r=e.mul(e)}if(t instanceof g){n=t.toRational().mul(t.toRational())}else{n=t.mul(t)}return r.add(n)}else{return this.__re__.mul(this.__re__).add(this.__im__.mul(this.__im__))}};y.prototype.modulus=function(){return this.factor().sqrt()};y.prototype.conjugate=function(){return y({re:this.__re__,im:this.__im__.sub()})};y.prototype.sqrt=function(){var e=this.modulus();var t,r;if(e.cmp(0)===0){t=r=e}else if(this.__re__.cmp(0)===1){t=g(.5).mul(e.add(this.__re__)).sqrt();r=this.__im__.div(t).div(2)}else{r=g(.5).mul(e.sub(this.__re__)).sqrt();if(this.__im__.cmp(0)===-1){r=r.sub()}t=this.__im__.div(r).div(2)}return y({im:r,re:t})};y.prototype.div=function(e){if(B.isNumber(e)&&!B.isComplex(e)){if(!(e instanceof B)){e=B(e)}var t=this.__re__.div(e);var r=this.__im__.div(e);return y({re:t,im:r})}else if(!B.isComplex(e)){throw new Error("[LComplex::div] Invalid value")}if(this.cmp(e)===0){var n=this.coerce(e),i=b(n,2),u=i[0],a=i[1];var o=u.__im__.div(a.__im__);return o.coerce(a.__re__)[0]}var s=this.coerce(e),c=b(s,2),f=c[0],l=c[1];var h=l.factor();var _=l.conjugate();var p=f.mul(_);if(!B.isComplex(p)){return p.div(h)}var d=p.__re__.op("/",h);var v=p.__im__.op("/",h);return y({re:d,im:v})};y.prototype.sub=function(e){return this.complex_op("sub",e,function(e,t,r,n){return{re:e.sub(t),im:r.sub(n)}})};y.prototype.mul=function(e){return this.complex_op("mul",e,function(e,t,r,n){var i={re:e.mul(t).sub(r.mul(n)),im:e.mul(n).add(t.mul(r))};return i})};y.prototype.complex_op=function(e,t,i){var u=this;var r=function e(t,r){var n=i(u.__re__,t,u.__im__,r);if("im"in n&&"re"in n){if(n.im.cmp(0)===0){return n.re}return y(n,true)}return n};if(typeof t==="undefined"){return r()}if(B.isNumber(t)&&!B.isComplex(t)){if(!(t instanceof B)){t=B(t)}var n=t.asType(0);t={__im__:n,__re__:t}}else if(!B.isComplex(t)){throw new Error("[LComplex::".concat(e,"] Invalid value"))}var a=t.__re__ instanceof B?t.__re__:this.__re__.asType(t.__re__);var o=t.__im__ instanceof B?t.__im__:this.__im__.asType(t.__im__);return r(a,o)};y._op={"+":"add","-":"sub","*":"mul","/":"div"};y.prototype._op=function(e,t){var r=y._op[e];return this[r](t)};y.prototype.cmp=function(e){var t=this.coerce(e),r=b(t,2),n=r[0],i=r[1];var u=n.__re__.coerce(i.__re__),a=b(u,2),o=a[0],s=a[1];var c=o.cmp(s);if(c!==0){return c}else{var f=n.__im__.coerce(i.__im__),l=b(f,2),h=l[0],_=l[1];return h.cmp(_)}};y.prototype.valueOf=function(){return[this.__re__,this.__im__].map(function(e){return e.valueOf()})};y.prototype.toString=function(){var e;if(this.__re__.cmp(0)!==0){e=[au(this.__re__)]}else{e=[]}var t=this.__im__.valueOf();var r=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY].includes(t);var n=au(this.__im__);if(!r&&!Number.isNaN(t)){var i=this.__im__.cmp(0);if(i<0||i===0&&this.__im__._minus){e.push("-")}else{e.push("+")}n=n.replace(/^-/,"")}e.push(n);e.push("i");return e.join("")};function g(e){if(typeof this!=="undefined"&&!(this instanceof g)||typeof this==="undefined"){return new g(e)}if(!B.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof B){return g(e.valueOf())}if(typeof e==="number"){if(Object.is(e,-0)){Object.defineProperty(this,"_minus",{value:true})}this.constant(e,"float")}}g.prototype=Object.create(B.prototype);g.prototype.constructor=g;g.prototype.toString=function(e){if(this.__value__===Number.NEGATIVE_INFINITY){return"-inf.0"}if(this.__value__===Number.POSITIVE_INFINITY){return"+inf.0"}if(Number.isNaN(this.__value__)){return"+nan.0"}e&&(e=e.valueOf());var t=this.__value__.toString(e);if(!t.match(/e[+-]?[0-9]+$/i)){var r=t.replace(/^-/,"");var n=this.__value__<0?"-":"";if(t.match(/^-?0\.0{3}/)){var i=r.match(/^[.0]+/g)[0].length-1;var u=r.replace(/^[.0]+/,"").replace(/^([0-9a-f])/i,"$1.");return"".concat(n).concat(u,"e-").concat(i.toString(e))}if(t.match(/^-?[0-9a-f]{7,}\.?/i)){var a=r.match(/^[0-9a-f]+/gi)[0].length-1;var o=r.replace(/\./,"").replace(/^([0-9a-f])/i,"$1.").replace(/0+$/,"").replace(/\.$/,".0");return"".concat(n).concat(o,"e+").concat(a.toString(e))}if(!B.isFloat(this.__value__)){var s=t+".0";return this._minus?"-"+s:s}}return t.replace(/^([0-9]+)e/,"$1.0e")};g.prototype._op=function(e,t){if(t instanceof B){t=t.__value__}var r=B._ops[e];if(e==="/"&&this.__value__===0&&t===0){return NaN}return g(r(this.__value__,t))};g.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){return La(this.__value__.valueOf())}return Ma(e.valueOf())(this.__value__.valueOf())};g.prototype.sqrt=function(){var e=this.valueOf();if(this.cmp(0)<0){var t=g(Math.sqrt(-e));return y({re:0,im:t})}return g(Math.sqrt(e))};g.prototype.abs=function(){var e=this.valueOf();if(e<0){e=-e}return g(e)};var La=Ma(1e-10);function Ma(n){return function(e){var t=function e(n,t,r){var i=function e(t,r){return r0){i=qa(n,r)}else if(n.cmp(r)<=0){i=r}else if(r.cmp(0)>0){i=qa(r,n)}else if(t.cmp(0)<0){i=B(qa(n.sub(),r.sub())).sub()}else{i=B(0)}if(B.isFloat(t)||B.isFloat(e)){return g(i)}return i}function qa(e,t){var r=B(e).floor();var n=B(t).floor();if(e.cmp(r)<1){return r}else if(r.cmp(n)===0){var i=B(1).div(t.sub(n));var u=B(1).div(e.sub(r));return r.add(B(1).div(qa(i,u)))}else{return r.add(B(1))}}function x(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof x)||typeof this==="undefined"){return new x(e,t)}if(!B.isRational(e)){throw new Error("Invalid constructor call for LRational")}var r,n;if(e instanceof x){r=B(e.__num__);n=B(e.__denom__)}else{r=B(e.num);n=B(e.denom)}if(!t&&n.cmp(0)!==0){var i=r.op("%",n).cmp(0)===0;if(i){return B(r.div(n))}}this.constant(r,n)}x.prototype=Object.create(B.prototype);x.prototype.constructor=x;x.prototype.constant=function(e,t){Object.defineProperty(this,"__num__",{value:e,enumerable:true});Object.defineProperty(this,"__denom__",{value:t,enumerable:true});Object.defineProperty(this,"__type__",{value:"rational",enumerable:true})};x.prototype.serialize=function(){return{num:this.__num__,denom:this.__denom__}};x.prototype.pow=function(e){if(B.isRational(e)){return Na(this.valueOf(),e.valueOf())}var t=e.cmp(0);if(t===0){return B(1)}if(t===-1){e=e.sub();var r=this.__denom__.pow(e);var n=this.__num__.pow(e);return x({num:r,denom:n})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};x.prototype.sqrt=function(){var e=this.__num__.sqrt();var t=this.__denom__.sqrt();if(e instanceof g||t instanceof g){return e.div(t)}return x({num:e,denom:t})};x.prototype.abs=function(){var e=this.__num__;var t=this.__denom__;if(e.cmp(0)===-1){e=e.sub()}if(t.cmp(0)!==1){t=t.sub()}return x({num:e,denom:t})};x.prototype.cmp=function(e){return B(this.valueOf(),true).cmp(e)};x.prototype.toString=function(){var e=this.__num__.gcd(this.__denom__);var t,r;if(e.cmp(1)!==0){t=this.__num__.div(e);if(t instanceof x){t=B(t.valueOf(true))}r=this.__denom__.div(e);if(r instanceof x){r=B(r.valueOf(true))}}else{t=this.__num__;r=this.__denom__}var n=this.cmp(0)<0;if(n){if(t.abs().cmp(r.abs())===0){return t.toString()}}else if(t.cmp(r)===0){return t.toString()}return t.toString()+"/"+r.toString()};x.prototype.valueOf=function(e){if(this.__denom__.cmp(0)===0){if(this.__num__.cmp(0)<0){return Number.NEGATIVE_INFINITY}return Number.POSITIVE_INFINITY}if(e){return B._ops["/"](this.__num__.value,this.__denom__.value)}return g(this.__num__.valueOf()).div(this.__denom__.valueOf())};x.prototype.mul=function(e){if(!(e instanceof B)){e=B(e)}if(B.isRational(e)){var t=this.__num__.mul(e.__num__);var r=this.__denom__.mul(e.__denom__);return x({num:t,denom:r})}var n=B.coerce(this,e),i=b(n,2),u=i[0],a=i[1];return u.mul(a)};x.prototype.div=function(e){if(!(e instanceof B)){e=B(e)}if(B.isRational(e)){var t=this.__num__.mul(e.__denom__);var r=this.__denom__.mul(e.__num__);return x({num:t,denom:r})}var n=B.coerce(this,e),i=b(n,2),u=i[0],a=i[1];var o=u.div(a);return o};x.prototype._op=function(e,t){return this[Pa[e]](t)};x.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof B)){e=B(e)}if(B.isRational(e)){var t=e.__num__.sub();var r=e.__denom__;return this.add(x({num:t,denom:r}))}if(!(e instanceof B)){e=B(e).sub()}else{e=e.sub()}var n=B.coerce(this,e),i=b(n,2),u=i[0],a=i[1];return u.add(a)};x.prototype.add=function(e){if(!(e instanceof B)){e=B(e)}if(B.isRational(e)){var t=this.__denom__;var r=e.__denom__;var n=this.__num__;var i=e.__num__;var u,a;if(t!==r){a=r.mul(n).add(i.mul(t));u=t.mul(r)}else{a=n.add(i);u=t}return x({num:a,denom:u})}if(B.isFloat(e)){return g(this.valueOf()).add(e)}var o=B.coerce(this,e),s=b(o,2),c=s[0],f=s[1];return c.add(f)};function E(e,t){if(typeof this!=="undefined"&&!(this instanceof E)||typeof this==="undefined"){return new E(e,t)}if(e instanceof E){return E(e.__value__,e._native)}if(!B.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.constant(e,"bigint");Object.defineProperty(this,"_native",{value:t})}E.prototype=Object.create(B.prototype);E.prototype.constructor=E;E.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};E.prototype.serialize=function(){return this.__value__.toString()};E.prototype._op=function(e,t){if(typeof t==="undefined"){if(B.isBN(this.__value__)){e=E.bn_op[e];return E(this.__value__.clone()[e](),false)}return E(B._ops[e](this.__value__),true)}if(B.isBN(this.__value__)&&B.isBN(t.__value__)){e=E.bn_op[e];return E(this.__value__.clone()[e](t),false)}var r=B._ops[e](this.__value__,t.__value__);if(e==="/"){var n=this.op("%",t).cmp(0)===0;if(n){return B(r)}return x({num:this,denom:t})}return E(r,true)};E.prototype.sqrt=function(){var e;var t=this.cmp(0)<0;if(B.isNative(this.__value__)){e=B(Math.sqrt(t?-this.valueOf():this.valueOf()))}else if(B.isBN(this.__value__)){e=t?this.__value__.neg().sqrt():this.__value__.sqrt()}if(t){return y({re:0,im:e})}return e};B.NaN=B(NaN);y.i=y({im:1,re:0});function Ua(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof Ua)||typeof this==="undefined"){return new Ua(e)}A("InputPort",e,"function");c(this,"__type__",Xa);var i;Object.defineProperty(this,"__parser__",{enumerable:true,get:function e(){return i},set:function e(t){A("InputPort::__parser__",t,"parser");i=t}});this._read=e;this._with_parser=this._with_init_parser.bind(this,ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(n.char_ready()){t.next=5;break}t.next=3;return n._read();case 3:r=t.sent;i=new fi(r,{env:n});case 5:return t.abrupt("return",n.__parser__);case 6:case"end":return t.stop()}},e)})));this.char_ready=function(){return!!this.__parser__&&this.__parser__.__lexer__.peek()!==eo};this._make_defaults()}Ua.prototype._make_defaults=function(){this.read=this._with_parser(function(e){return e.read_object()});this.read_line=this._with_parser(function(e){return e.__lexer__.read_line()});this.read_char=this._with_parser(function(e){return e.__lexer__.read_char()});this.read_string=this._with_parser(function(e,t){if(!B.isInteger(t)){var r=B.getType(t);ko("read-string",r,"integer")}return e.__lexer__.read_string(t.valueOf())});this.peek_char=this._with_parser(function(e){return e.__lexer__.peek_char()})};Ua.prototype._with_init_parser=function(o,s){var c=this;return ie(O.mark(function e(){var r,n,i,u,a=arguments;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return o.call(c);case 2:r=t.sent;for(n=a.length,i=new Array(n),u=0;u"};function za(e){if(typeof this!=="undefined"&&!(this instanceof za)||typeof this==="undefined"){return new za(e)}A("OutputPort",e,"function");c(this,"__type__",Xa);this.write=e}za.prototype.is_open=function(){return this._closed!==true};za.prototype.close=function(){Object.defineProperty(this,"_closed",{get:function e(){return true},set:function e(){},configurable:false,enumerable:false});this.write=function(){throw new Error("output-port: port is closed")}};za.prototype.flush=function(){};za.prototype.toString=function(){return"#"};var Va=function(e){W(r,e);function r(e){var t;ue(this,r);t=Pr(this,r,[function(){var e;return(e=t)._write.apply(e,arguments)}]);A("BufferedOutputPort",e,"function");c(M(t),"_fn",e,{hidden:true});c(M(t),"_buffer",[],{hidden:true});return t}ce(r,[{key:"flush",value:function e(){if(this._buffer.length){this._fn(this._buffer.join(""));this._buffer.length=0}}},{key:"_write",value:function e(){var t=this;for(var r=arguments.length,n=new Array(r),i=0;i"};$a.prototype.valueOf=function(){return this.__buffer__.map(function(e){return e.valueOf()}).join("")};function Ya(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof Ya)||typeof this==="undefined"){return new Ya(e,t)}A("OutputFilePort",e,"string");c(this,"__filename__",e);c(this,"_fd",t.valueOf(),{hidden:true});c(this,"__type__",Xa);this.write=function(e){if(!D.isString(e)){e=au(e)}else{e=e.valueOf()}r.fs().write(r._fd,e,function(e){if(e){throw e}})}}Ya.prototype=Object.create(za.prototype);Ya.prototype.constructor=Ya;Ya.prototype.fs=function(){if(!this._fs){this._fs=this.internal("fs")}return this._fs};Ya.prototype.internal=function(e){return vo.get("**internal-env**").get(e)};Ya.prototype.close=function(){var n=this;return new Promise(function(t,r){n.fs().close(n._fd,function(e){if(e){r(e)}else{c(n,"_fd",null,{hidden:true});za.prototype.close.call(n);t()}})})};Ya.prototype.toString=function(){return"#")};function Ja(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof Ja)||typeof this==="undefined"){return new Ja(e)}A("InputStringPort",e,"string");t=t||G;e=e.valueOf();this._with_parser=this._with_init_parser.bind(this,function(){if(!r.__parser__){r.__parser__=new fi(e,{env:t})}return r.__parser__});c(this,"__type__",Xa);this._make_defaults()}Ja.prototype.char_ready=function(){return true};Ja.prototype=Object.create(Ua.prototype);Ja.prototype.constructor=Ja;Ja.prototype.toString=function(){return"#"};function Ka(e){if(typeof this!=="undefined"&&!(this instanceof Ka)||typeof this==="undefined"){return new Ka(e)}A("InputByteVectorPort",e,"uint8array");c(this,"__vector__",e);c(this,"__type__",Za);var r=0;Object.defineProperty(this,"__index__",{enumerable:true,get:function e(){return r},set:function e(t){A("InputByteVectorPort::__index__",t,"number");if(t instanceof B){t=t.valueOf()}if(typeof t==="bigint"){t=Number(t)}if(Math.floor(t)!==t){throw new Error("InputByteVectorPort::__index__ value is "+"not integer")}r=t}})}Ka.prototype=Object.create(Ua.prototype);Ka.prototype.constructor=Ka;Ka.prototype.toString=function(){return"#"};Ka.prototype.close=function(){var t=this;c(this,"__vector__",$);var r=function e(){throw new Error("Input-binary-port: port is closed")};["read_u8","close","peek_u8","read_u8_vector"].forEach(function(e){t[e]=r});this.u8_ready=this.char_ready=function(){return false}};Ka.prototype.u8_ready=function(){return true};Ka.prototype.peek_u8=function(){if(this.__index__>=this.__vector__.length){return eo}return this.__vector__[this.__index__]};Ka.prototype.skip=function(){if(this.__index__<=this.__vector__.length){++this.__index__}};Ka.prototype.read_u8=function(){var e=this.peek_u8();this.skip();return e};Ka.prototype.read_u8_vector=function(e){if(typeof e==="undefined"){e=this.__vector__.length}else if(e>this.__index__+this.__vector__.length){e=this.__index__+this.__vector__.length}if(this.peek_u8()===eo){return eo}return this.__vector__.slice(this.__index__,e)};function Ha(){if(typeof this!=="undefined"&&!(this instanceof Ha)||typeof this==="undefined"){return new Ha}c(this,"__type__",Za);c(this,"_buffer",[],{hidden:true});this.write=function(e){A("write",e,["number","uint8array"]);if(B.isNumber(e)){this._buffer.push(e.valueOf())}else{var t;(t=this._buffer).push.apply(t,q(Array.from(e)))}};Object.defineProperty(this,"__buffer__",{enumerable:true,get:function e(){return Uint8Array.from(this._buffer)}})}Ha.prototype=Object.create(za.prototype);Ha.prototype.constructor=Ha;Ha.prototype.close=function(){za.prototype.close.call(this);c(this,"_buffer",null,{hidden:true})};Ha.prototype._close_guard=function(){if(this._closed){throw new Error("output-port: binary port is closed")}};Ha.prototype.write_u8=function(e){A("OutputByteVectorPort::write_u8",e,"number");this.write(e)};Ha.prototype.write_u8_vector=function(e){A("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};Ha.prototype.toString=function(){return"#"};Ha.prototype.valueOf=function(){return this.__buffer__};function Ga(e,t){if(typeof this!=="undefined"&&!(this instanceof Ga)||typeof this==="undefined"){return new Ga(e,t)}Ja.call(this,e);A("InputFilePort",t,"string");c(this,"__filename__",t)}Ga.prototype=Object.create(Ja.prototype);Ga.prototype.constructor=Ga;Ga.prototype.toString=function(){return"#")};function Wa(e,t){if(typeof this!=="undefined"&&!(this instanceof Wa)||typeof this==="undefined"){return new Wa(e,t)}Ka.call(this,e);A("InputBinaryFilePort",t,"string");c(this,"__filename__",t)}Wa.prototype=Object.create(Ka.prototype);Wa.prototype.constructor=Wa;Wa.prototype.toString=function(){return"#")};function Qa(e,t){var i=this;if(typeof this!=="undefined"&&!(this instanceof Qa)||typeof this==="undefined"){return new Qa(e,t)}A("OutputBinaryFilePort",e,"string");c(this,"__filename__",e);c(this,"_fd",t.valueOf(),{hidden:true});c(this,"__type__",Za);var u;this.write=function(e){A("write",e,["number","uint8array"]);var n;if(!u){u=i.internal("fs")}if(B.isNumber(e)){n=new Uint8Array([e.valueOf()])}else{n=new Uint8Array(Array.from(e))}return new Promise(function(t,r){u.write(i._fd,n,function(e){if(e){r(e)}else{t()}})})}}Qa.prototype=Object.create(Ya.prototype);Qa.prototype.constructor=Qa;Qa.prototype.write_u8=function(e){A("OutputByteVectorPort::write_u8",e,"number");this.write(e)};Qa.prototype.write_u8_vector=function(e){A("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};var Za=Symbol["for"]("binary");var Xa=Symbol["for"]("text");var eo=new to;function to(){}to.prototype.toString=function(){return"#"};function ro(e){var t=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=r.stderr,i=r.stdin,u=r.stdout,a=r.command_line,o=a===void 0?null:a,s=he(r,Or);if(typeof this!=="undefined"&&!(this instanceof ro)||typeof this==="undefined"){return new ro(e,U({stdin:i,stdout:u,stderr:n,command_line:o},s))}if(typeof e==="undefined"){e="anonymous"}this.__env__=vo.inherit(e,s);this.__env__.set("parent.frame",l("parent.frame",function(){return t.__env__},G.__env__["parent.frame"].__doc__));var c="**interaction-environment-defaults**";this.set(c,tu(s).concat(c));var f=ho.inherit("internal-".concat(e));if(Hu(i)){f.set("stdin",i)}if(Hu(n)){f.set("stderr",n)}if(Hu(u)){f.set("stdout",u)}f.set("command-line",o);mo(this.__env__,f)}ro.prototype.exec=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=t.use_dynamic,n=r===void 0?false:r,i=t.dynamic_env,u=t.env;A("Interpreter::exec",e,["string","array"],1);A("Interpreter::exec",n,"boolean",2);if(!u){u=this.__env__}if(!i){i=u}G.set("**interaction-environment**",this.__env__);return Ko(e,{env:u,dynamic_env:i,use_dynamic:n})};ro.prototype.get=function(e){var t=this.__env__.get(e);if(d(t)){var r=new Vo({env:this.__env__});return t.bind(r)}return t};ro.prototype.set=function(e,t){return this.__env__.set(e,t)};ro.prototype.constant=function(e,t){return this.__env__.constant(e,t)};function no(e,t){this.name="LipsError";this.message=e;this.args=t;this.stack=(new Error).stack}no.prototype=new Error;no.prototype.constructor=no;var io=function(e){W(t,e);function t(){ue(this,t);return Pr(this,t,arguments)}return ce(t)}(r(Error));function F(e,t,r){if(arguments.length===1){if(_(arguments[0])==="object"){e=arguments[0];t=null}else if(typeof arguments[0]==="string"){e={};t=null;r=arguments[0]}}this.__docs__=new Map;this.__env__=e;this.__parent__=t;this.__name__=r||"anonymous"}F.prototype.list=function(){return tu(this.__env__)};F.prototype.fs=function(){return this.get("**fs**")};F.prototype.unset=function(e){if(e instanceof V){e=e.valueOf()}if(e instanceof D){e=e.valueOf()}delete this.__env__[e]};F.prototype.inherit=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(_(e)==="object"){t=e}if(!e||_(e)==="object"){e="child of "+(this.__name__||"unknown")}return new F(t||{},this,e)};F.prototype.doc=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(e instanceof V){e=e.__name__}if(e instanceof D){e=e.valueOf()}if(t){if(!r){t=gi(t)}this.__docs__.set(e,t);return this}if(this.__docs__.has(e)){return this.__docs__.get(e)}if(this.__parent__){return this.__parent__.doc(e)}};F.prototype.new_frame=function(e,t){var n=this.inherit("__frame__");n.set("parent.frame",l("parent.frame",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;e=e.valueOf();var t=n.__parent__;if(!Cu(t)){return $}if(e<=0){return t}var r=t.get("parent.frame");return r(e-1)},G.__env__["parent.frame"].__doc__));t.callee=e;n.set("arguments",t);return n};F.prototype._lookup=function(e){if(e instanceof V){e=e.__name__}if(e instanceof D){e=e.valueOf()}if(this.__env__.hasOwnProperty(e)){return uo(this.__env__[e])}if(this.__parent__){return this.__parent__._lookup(e)}};F.prototype.toString=function(){return"#"};F.prototype.clone=function(){var t=this;var r={};Object.keys(this.__env__).forEach(function(e){r[e]=t.__env__[e]});return new F(r,this.__parent__,this.__name__)};F.prototype.merge=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"merge";A("Environment::merge",e,"environment");return this.inherit(t,e.__env__)};function uo(e){if(typeof this!=="undefined"&&!(this instanceof uo)||typeof this==="undefined"){return new uo(e)}this.value=e}uo.isUndefined=function(e){return e instanceof uo&&typeof e.value==="undefined"};uo.prototype.valueOf=function(){return this.value};function ao(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof ao)||typeof this==="undefined"){return new ao(e)}this.__values__=e}ao.prototype.toString=function(){return this.__values__.map(function(e){return au(e)}).join("\n")};ao.prototype.valueOf=function(){return this.__values__};F.prototype.get=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};A("Environment::get",e,["symbol","string"]);var r=t.throwError,n=r===void 0?true:r;var i=e;if(i instanceof V||i instanceof D){i=i.valueOf()}var u=this._lookup(i);if(u instanceof uo){if(uo.isUndefined(u)){return undefined}return zu(u.valueOf())}var a;if(e instanceof V&&e[V.object]){a=e[V.object]}else if(typeof i==="string"){a=i.split(".").filter(Boolean)}if(a&&a.length>0){var o=a,s=re(o),c=s[0],f=s.slice(1);u=this._lookup(c);if(f.length){try{if(u instanceof uo){u=u.valueOf()}else{u=co(zr,c);if(d(u)){u=Vu(u)}}if(typeof u!=="undefined"){return co.apply(void 0,[u].concat(q(f)))}}catch(e){throw e}}else if(u instanceof uo){return zu(u.valueOf())}u=co(zr,i)}if(typeof u!=="undefined"){return u}if(n){throw new Error("Unbound variable `"+i.toString()+"'")}};F.prototype.set=function(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;A("Environment::set",e,["string","symbol"]);if(B.isNumber(t)){t=B(t)}if(e instanceof V){e=e.__name__}if(e instanceof D){e=e.valueOf()}this.__env__[e]=t;if(r){this.doc(e,r,true)}return this};F.prototype.constant=function(t,e){var r=this;if(this.__env__.hasOwnProperty(t)){throw new Error("Environment::constant: ".concat(t," already exists"))}if(arguments.length===1&&Ki(arguments[0])){var n=arguments[0];Object.keys(n).forEach(function(e){r.constant(t,n[e])})}else{Object.defineProperty(this.__env__,t,{value:e,enumerable:true})}return this};F.prototype.has=function(e){return this.__env__.hasOwnProperty(e)};F.prototype.ref=function(e){var t=this;while(true){if(!t){break}if(t.has(e)){return t}t=t.__parent__}};F.prototype.parents=function(){var e=this;var t=[];while(e){t.unshift(e);e=e.__parent__}return t};function oo(e){if(Bu(e)){return e.then(oo)}if(H(e)||e instanceof V){e[Zu]=true}return e}var so=hi(Jn('(lambda ()\n "[native code]"\n (throw "Invalid Invocation"))'))[0];var co=l("get",function e(t){var r;for(var n=arguments.length,i=new Array(n>1?n-1:0),u=1;u0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=fo(this,"stdin")}jo("peek-char",e,"input-port");return e.peek_char()},"(peek-char port)\n\n This function reads and returns a character from the string\n port, or, if there is no more data in the string port, it\n returns an EOF."),"read-line":l("read-line",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=fo(this,"stdin")}jo("read-line",e,"input-port");return e.read_line()},"(read-line port)\n\n This function reads and returns the next line from the input\n port."),"read-char":l("read-char",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=fo(this,"stdin")}jo("read-char",e,"input-port");return e.read_char()},"(read-char port)\n\n This function reads and returns the next character from the\n input port."),read:l("read",function(){var e=ie(function(){var i=this;var u=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;return O.mark(function e(){var r,n;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=i.env;if(u===null){n=fo(r,"stdin")}else{n=u}jo("read",n,"input-port");return t.abrupt("return",n.read.call(r));case 4:case"end":return t.stop()}},e)})()});function t(){return e.apply(this,arguments)}return t}(),"(read [port])\n\n This function, if called with a port, it will parse the next\n item from the port. If called without an input, it will read\n a string from standard input (using the browser's prompt or\n a user defined input method) and parse it. This function can be\n used together with `eval` to evaluate code from port."),pprint:l("pprint",function e(t){if(H(t)){t=new Cs.Formatter(t.toString(true))["break"]().format();G.get("display").call(G,t)}else{G.get("write").call(G,t)}G.get("newline").call(G)},"(pprint expression)\n\n This function will pretty print its input to stdout. If it is called\n with a non-list, it will just call the print function on its\n input."),print:l("print",function e(){var t=G.get("display");var r=G.get("newline");var n=this.use_dynamic;var i=G;var u=G;for(var a=arguments.length,o=new Array(a),s=0;s1?r-1:0),i=1;in.length){throw new Error("Not enough arguments")}var o=0;var s=G.get("repr");t=t.replace(u,function(e){var t=e[1];if(t==="~"){return"~"}else if(t==="%"){return"\n"}else{var r=n[o++];if(t==="a"){return s(r)}else{return s(r,true)}}});a=t.match(/~([\S])/);if(a){throw new Error("format: Unrecognized escape sequence ".concat(a[1]))}return t},"(format string n1 n2 ...)\n\n This function accepts a string template and replaces any\n escape sequences in its inputs:\n\n * ~a value as if printed with `display`\n * ~s value as if printed with `write`\n * ~% newline character\n * ~~ literal tilde '~'\n\n If there are missing inputs or other escape characters it\n will error."),display:l("display",function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(r===null){r=fo(this,"stdout")}else{A("display",r,"output-port")}var n=t;if(!(r instanceof Qa)){n=G.get("repr")(t)}r.write.call(G,n)},"(display string [port])\n\n This function outputs the string to the standard output or\n the port if given. No newline."),"display-error":l("display-error",function e(){var t=fo(this,"stderr");var r=G.get("repr");for(var n=arguments.length,i=new Array(n),u=0;u1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=he(t,Cr);var i=this;var a=this;var o;var s=U(U({},n),{},{env:this,dynamic_env:i,use_dynamic:r});var c=k(e.cdr.car,s);c=Po(c);function f(t,r,n){if(Bu(t)){return t.then(function(e){return f(t,e,n)})}if(Bu(r)){return r.then(function(e){return f(t,e,n)})}if(Bu(n)){return n.then(function(e){return f(t,r,e)})}a.get("set-obj!").call(a,t,r,n);return n}if(H(e.car)&&V.is(e.car.car,".")){var l=e.car.cdr.car;var h=e.car.cdr.cdr.car;var _=k(l,s);var p=k(h,s);return f(_,p,c)}if(!(e.car instanceof V)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var d=e.car.valueOf();o=this.ref(e.car.__name__);return w(c,function(e){if(!o){var t=d.split(".");if(t.length>1){var r=t.pop();var n=t.join(".");var i=u.get(n,{throwError:false});if(i){f(i,r,e);return}}throw new Error("Unbound variable `"+d+"'")}o.set(d,e)})}),"(set! name value)\n\n Macro that can be used to set the value of the variable or slot (mutate it).\n set! searches the scope chain until it finds first non empty slot and sets it."),"unset!":l(new J("set!",function(e){if(!(e.car instanceof V)){throw new Error("unset! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var t=e.car;var r=this.ref(t);if(r){delete r.__env__[t.__name__]}}),"(unset! name)\n\n Function to delete the specified name from environment.\n Trying to access the name afterwards will error."),"set-car!":l("set-car!",function(e,t){A("set-car!",e,"pair");e.car=t},"(set-car! obj value)\n\n Function that sets the car (first item) of the list/pair to specified value.\n The old value is lost."),"set-cdr!":l("set-cdr!",function(e,t){A("set-cdr!",e,"pair");e.cdr=t},"(set-cdr! obj value)\n\n Function that sets the cdr (tail) of the list/pair to specified value.\n It will destroy the list. The old tail is lost."),"empty?":l("empty?",function(e){return typeof e==="undefined"||K(e)},"(empty? object)\n\n Function that returns #t if value is nil (an empty list) or undefined."),gensym:l("gensym",Qn,"(gensym)\n\n Generates a unique symbol that is not bound anywhere,\n to use with macros as meta name."),load:l("load",function e(o,t){A("load",o,"string");var s=this;if(s.__name__==="__frame__"){s=s.__parent__}if(!(t instanceof F)){if(s===G){t=s}else{t=this.get("**interaction-environment**")}}var c="**module-path**";var f=G.get(c,{throwError:false});o=o.valueOf();if(!o.match(/.[^.]+$/)){o+=".scm"}var r=o.match(/\.xcb$/);function l(e){if(r){e=ws(e)}else{if(Io(e)==="buffer"){e=e.toString()}e=e.replace(/^#!.*/,"");if(e.match(/^\{/)){e=ps(e)}}return Ko(e,{env:t})}function n(e){return zr.fetch(e).then(function(e){return r?e.arrayBuffer():e.text()}).then(function(e){if(r){e=new Uint8Array(e)}return e})}if(xo()){return new Promise(function(){var r=ie(O.mark(function e(r,n){var i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:i=Kr("path");if(!f){t.next=6;break}f=f.valueOf();o=i.join(f,o);t.next=12;break;case 6:u=s.get("command-line",{throwError:false});if(!u){t.next=11;break}t.next=10;return u();case 10:a=t.sent;case 11:if(a&&!K(a)){process.cwd();o=i.join(i.dirname(a.car.valueOf()),o)}case 12:G.set(c,i.dirname(o));Kr("fs").readFile(o,function(e,t){if(e){n(e);G.set(c,f)}else{try{l(t).then(function(){r();G.set(c,f)})["catch"](n)}catch(e){n(e)}}});case 14:case"end":return t.stop()}},e)}));return function(e,t){return r.apply(this,arguments)}}())}if(f){f=f.valueOf();o=f+"/"+o.replace(/^\.?\/?/,"")}return n(o).then(function(e){G.set(c,o.replace(/\/[^/]*$/,""));return l(e)}).then(function(){})["finally"](function(){G.set(c,f)})},"(load filename)\n (load filename environment)\n\n Fetches the file (from disk or network) and evaluates its content as LIPS code.\n If the second argument is provided and it's an environment the evaluation\n will happen in that environment."),while:l(new J("while",function(e,t){var r=e.car;var n=U(U({},t),{},{env:this});var i=new Y(new V("begin"),e.cdr);return function t(){return w(k(r,n),function(e){if(e){return w(k(i,n),t)}})}()}),"(while cond body)\n\n Creates a loop, it executes cond and body until cond expression is false."),do:l(new J("do",function(){var r=ie(function(h,e){var _=this;var p=e.use_dynamic,d=e.error;return O.mark(function e(){var o,r,s,c,n,f,l,i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:o=_;r=o;s=o.inherit("do");c=h.car;n=h.cdr.car;f=h.cdr.cdr;if(!K(f)){f=new Y(V("begin"),f)}l={env:o,dynamic_env:r,use_dynamic:p,error:d};i=c;case 9:if(K(i)){t.next=20;break}u=i.car;t.t0=s;t.t1=u.car;t.next=15;return k(u.cdr.car,l);case 15:t.t2=t.sent;t.t0.set.call(t.t0,t.t1,t.t2);i=i.cdr;t.next=9;break;case 20:l={env:s,dynamic_env:r,error:d};a=O.mark(function e(){var r,n,i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(K(f)){t.next=3;break}t.next=3;return Cs.evaluate(f,l);case 3:r=c;n={};case 5:if(K(r)){t.next=15;break}i=r.car;if(K(i.cdr.cdr)){t.next=12;break}t.next=10;return k(i.cdr.cdr.car,l);case 10:u=t.sent;n[i.car.valueOf()]=u;case 12:r=r.cdr;t.next=5;break;case 15:a=Object.getOwnPropertySymbols(n);l.env=s=o.inherit("do");Object.keys(n).concat(a).forEach(function(e){s.set(e,n[e])});case 18:case"end":return t.stop()}},e)});case 22:t.next=24;return k(n.car,l);case 24:t.t3=t.sent;if(!(t.t3===false)){t.next=29;break}return t.delegateYield(a(),"t4",27);case 27:t.next=22;break;case 29:if(K(n.cdr)){t.next=33;break}t.next=32;return k(n.cdr.car,l);case 32:return t.abrupt("return",t.sent);case 33:case"end":return t.stop()}},e)})()});return function(e,t){return r.apply(this,arguments)}}()),"(do (( )) (test return) . body)\n\n Iteration macro that evaluates the expression body in scope of the variables.\n On each loop it changes the variables according to the expression and runs\n test to check if the loop should continue. If test is a single value, the macro\n will return undefined. If the test is a pair of expressions the macro will\n evaluate and return the second expression after the loop exits."),if:l(new J("if",function(r,e){var t=e.error,n=e.use_dynamic;var i=this;var u=this;var a={env:u,dynamic_env:i,use_dynamic:n,error:t};var o=function e(t){if(t===false){return k(r.cdr.cdr.car,a)}else{return k(r.cdr.car,a)}};if(K(r)){throw new Error("too few expressions for `if`")}var s=k(r.car,a);return w(s,o)}),"(if cond true-expr false-expr)\n\n Macro that evaluates cond expression and if the value is true, it\n evaluates and returns true-expression, if not it evaluates and returns\n false-expression."),"let-env":new J("let-env",function(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=e.dynamic_env,n=e.use_dynamic,i=e.error;A("let-env",t,"pair");var u=k(t.car,{env:this,dynamic_env:r,error:i,use_dynamic:n});return w(u,function(e){A("let-env",e,"environment");return k(Y(V("begin"),t.cdr),{env:e,dynamic_env:r,error:i})})},"(let-env env . body)\n\n Special macro that evaluates body in context of given environment\n object."),letrec:l(_a(Symbol["for"]("letrec")),"(letrec ((a value-a) (b value-b) ...) . body)\n\n Macro that creates a new environment, then evaluates and assigns values to\n names and then evaluates the body in context of that environment.\n Values are evaluated sequentially and the next value can access the\n previous values/names."),"letrec*":l(_a(Symbol["for"]("letrec")),"(letrec* ((a value-a) (b value-b) ...) . body)\n\n Same as letrec but the order of execution of the binding is guaranteed,\n so you can use recursive code as well as referencing the previous binding.\n\n In LIPS both letrec and letrec* behave the same."),"let*":l(_a(Symbol["for"]("let*")),"(let* ((a value-a) (b value-b) ...) . body)\n\n Macro similar to `let`, but the subsequent bindings after the first\n are evaluated in the environment including the previous let variables,\n so you can define one variable, and use it in the next's definition."),let:l(_a(Symbol["for"]("let")),"(let ((a value-a) (b value-b) ...) . body)\n\n Macro that creates a new environment, then evaluates and assigns values to names,\n and then evaluates the body in context of that environment. Values are evaluated\n sequentially but you can't access previous values/names when the next are\n evaluated. You can only get them in the body of the let expression. (If you want\n to define multiple variables and use them in each other's definitions, use\n `let*`.)"),"begin*":l(pa("begin*",function(e){return e.pop()}),"(begin* . body)\n\n This macro is a parallel version of begin. It evaluates each expression\n in the body and if it's a promise it will await it in parallel and return\n the value of the last expression (i.e. it uses Promise.all())."),shuffle:l("shuffle",function(e){A("shuffle",e,["pair","nil","array"]);var t=G.get("random");if(K(e)){return $}if(Array.isArray(e)){return Vi(e.slice(),t)}var r=G.get("list->array")(e);r=Vi(r,t);return G.get("array->list")(r)},"(shuffle obj)\n\n Order items in vector or list in random order."),begin:l(new J("begin",function(e,t){var n=U(U({},t),{},{env:this});var i=G.get("list->array")(e);var u;return function t(){if(i.length){var e=i.shift();var r=k(e,n);return w(r,function(e){u=e;return t()})}else{return u}}()}),"(begin . args)\n\n Macro that runs a list of expressions in order and returns the value\n of the last one. It can be used in places where you can only have a\n single expression, like (if)."),ignore:new J("ignore",function(e,t){var r=U(U({},t),{},{env:this,dynamic_env:this});k(new Y(new V("begin"),e),r)},"(ignore . body)\n\n Macro that will evaluate the expression and swallow any promises that may\n be created. It will discard any value that may be returned by the last body\n expression. The code should have side effects and/or when it's promise\n it should resolve to undefined."),"call/cc":l(J.defmacro("call/cc",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=U({env:this},t);return w(k(e.car,r),function(e){if(d(e)){return e(new Yo(null))}})}),"(call/cc proc)\n\n Call-with-current-continuation.\n\n NOT SUPPORTED BY LIPS RIGHT NOW"),parameterize:l(new J("parameterize",function(t,e){var i=e.dynamic_env;var u=i.inherit("parameterize").new_frame(null,{});var a=U(U({},e),{},{env:this});var o=t.car;if(!H(o)){var r=Io(o);throw new Error("Invalid syntax for parameterize expecting pair got ".concat(r))}function s(){var e=new Y(new V("begin"),t.cdr);return k(e,U(U({},a),{},{dynamic_env:u}))}return function r(){var e=o.car;var n=e.car.valueOf();return w(k(e.cdr.car,a),function(e){var t=i.get(n,{throwError:false});if(!Ou(t)){throw new Error("Unknown parameter ".concat(n))}u.set(n,t.inherit(e));if(!xu(o.cdr)){o=o.cdr;return r()}else{return s()}})}()}),"(parameterize ((name value) ...)\n\n Macro that change the dynamic variable created by make-parameter."),"make-parameter":l(new J("make-parameter",function(e,t){t.dynamic_env;var r=k(e.car,t);var n;if(H(e.cdr.car)){n=k(e.cdr.car,t)}return new zo(r,n)}),"(make-parameter init converter)\n\n Function creates new dynamic variable that can be custimized with parameterize\n macro. The value should be assigned to a variable e.g.:\n\n (define radix (make-parameter 10))\n\n The result value is a procedure that return the value of dynamic variable."),"define-syntax-parameter":l(new J("define-syntax-parameter",function(e,t){var r=e.car;var n=this;if(!(r instanceof V)){throw new Error("define-syntax-parameter: invalid syntax expecting symbol got ".concat(Io(r)))}var i=k(e.cdr.car,U({env:n},t));A("define-syntax-parameter",i,"syntax",2);i.__name__=r.valueOf();if(i.__name__ instanceof D){i.__name__=i.__name__.valueOf()}var u;if(H(e.cdr.cdr)&&D.isString(e.cdr.cdr.car)){u=e.cdr.cdr.car.valueOf()}n.set(e.car,new gu(i),u,true)}),"(define-syntax-parameter name syntax [__doc__])\n\n Binds to the transformer obtained by evaluating .\n The transformer provides the default expansion for the syntax parameter,\n and in the absence of syntax-parameterize, is functionally equivalent to\n define-syntax."),"syntax-parameterize":l(new J("syntax-parameterize",function(e,t){var r=G.get("list->array")(e.car);var n=this.inherit("syntax-parameterize");while(r.length){var i=r.shift();if(!(H(i)||i.car instanceof V)){var u="invalid syntax for syntax-parameterize: ".concat(Ji(e,true));throw new Error("syntax-parameterize: ".concat(u))}var a=k(i.cdr.car,U(U({},t),{},{env:this}));var o=i.car;A("syntax-parameterize",a,["syntax"]);A("syntax-parameterize",o,"symbol");a.__name__=o.valueOf();if(a.__name__ instanceof D){a.__name__=a.__name__.valueOf()}var s=new gu(a);if(o.is_gensym()){var c=o.literal();var f=this.get(c,{throwError:false});if(f instanceof gu){n.set(c,s)}}n.set(o,s)}var l=new Y(new V("begin"),e.cdr);return k(l,U(U({},t),{},{env:n}))}),"(syntax-parameterize (bindings) body)\n\n Macro work similar to let-syntax but the the bindnds will be exposed to the user.\n With syntax-parameterize you can define anaphoric macros."),define:l(J.defmacro("define",function(r,e){var n=this;if(H(r.car)&&r.car.car instanceof V){var t=new Y(new V("define"),new Y(r.car.car,new Y(new Y(new V("lambda"),new Y(r.car.cdr,r.cdr)))));return t}else if(e.macro_expand){return}e.dynamic_env=this;e.env=n;var i=r.cdr.car;var u;if(H(i)){i=k(i,e);u=true}else if(i instanceof V){i=n.get(i)}A("define",r.car,"symbol");return w(i,function(e){if(n.__name__===yu.__merge_env__){n=n.__parent__}if(u&&(d(e)&&ca(e)||e instanceof yu||Ou(e))){e.__name__=r.car.valueOf();if(e.__name__ instanceof D){e.__name__=e.__name__.valueOf()}}var t;if(H(r.cdr.cdr)&&D.isString(r.cdr.cdr.car)){t=r.cdr.cdr.car.valueOf()}n.set(r.car,e,t,true)})}),'(define name expression)\n (define name expression "doc string")\n (define (function-name . args) . body)\n\n Macro for defining values. It can be used to define variables,\n or functions. If the first argument is list it will create a function\n with name being first element of the list. This form expands to\n `(define function-name (lambda args body))`'),"set-obj!":l("set-obj!",function(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;var i=_(e);if(xu(e)||i!=="object"&&i!=="function"){var u=ko("set-obj!",Io(e),["object","function"]);throw new Error(u)}A("set-obj!",t,["string","symbol","number"]);e=Vu(e);t=t.valueOf();if(arguments.length===2){delete e[t]}else if(Fu(e)&&d(r)){e[t]=Vu(r);e[t][na]=true}else if(d(r)||Lu(r)||K(r)){e[t]=r}else{e[t]=r&&!Fu(r)?r.valueOf():r}if(Hi){var a=e[t];Object.defineProperty(e,t,U(U({},n),{},{value:a}))}},"(set-obj! obj key value)\n (set-obj! obj key value props)\n\n Function set a property of a JavaScript object. props should be a vector of pairs,\n passed to Object.defineProperty."),"null-environment":l("null-environment",function(){return G.inherit("null")},"(null-environment)\n\n Returns a clean environment with only the standard library."),values:l("values",function e(){for(var t=arguments.length,r=new Array(t),n=0;n1&&arguments[1]!==undefined?arguments[1]:{},m=e.use_dynamic,y=e.error;var g=this;var b;if(H(v.cdr)&&D.isString(v.cdr.car)&&!K(v.cdr.cdr)){b=v.cdr.car.valueOf()}function w(){var e=ku(this)?this:{dynamic_env:g},r=e.dynamic_env;var n=g.inherit("lambda");r=r.inherit("lambda");if(this&&!ku(this)){if(this&&!this.__instance__){Object.defineProperty(this,"__instance__",{enumerable:false,get:function e(){return true},set:function e(){},configurable:false})}n.set("this",this)}for(var t=arguments.length,i=new Array(t),u=0;u> SYNTAX");z(e);z(y);var n=w.inherit("syntax");var i=n;var u=this;if(u.__name__===yu.__merge_env__){var a=Object.getOwnPropertySymbols(u.__env__);a.forEach(function(e){u.__parent__.set(e,u.__env__[e])});u=u.__parent__}var o={env:n,dynamic_env:i,use_dynamic:g,error:b};var s,c,f;if(y.car instanceof V){s=y.car;f=D(y.cdr.car);c=y.cdr.cdr}else{s="...";f=D(y.car);c=y.cdr}try{while(!K(c)){var l=c.car.car;var h=c.car.cdr.car;z("[[[ RULE");z(l);var _=bu(l,e,f,s,{expansion:this,define:w});if(_){if(Wr()){console.log(JSON.stringify(eu(_),true,2));console.log("PATTERN: "+l.toString(true));console.log("MACRO: "+e.toString(true))}var p=[];var d=Du({bindings:_,expr:h,symbols:f,scope:n,lex_scope:u,names:p,ellipsis:s});z("OUPUT>>> ",d);if(d){h=d}var v=u.merge(n,yu.__merge_env__);if(r){return{expr:h,scope:v}}var m=k(h,U(U({},o),{},{env:v}));return wu(m,p)}c=c.cdr}}catch(e){e.message+="\nin macro:\n ".concat(y.toString(true));throw e}throw new Error("syntax-rules: no matching syntax in macro ".concat(e.toString(true)))},w);r.__code__=y;return r},"(syntax-rules () (pattern expression) ...)\n\n Base of hygienic macros, it will return a new syntax expander\n that works like Lisp macros."),quote:l(new J("quote",function(e){return oo(e.car)}),"(quote expression) or 'expression\n\n Macro that returns a single LIPS expression as data (it won't evaluate the\n argument). It will return a list if put in front of LIPS code.\n And if put in front of a symbol it will return the symbol itself, not the value\n bound to that name."),"unquote-splicing":l("unquote-splicing",function(){throw new Error("You can't call `unquote-splicing` outside of quasiquote")},"(unquote-splicing code) or ,@code\n\n Special form used in the quasiquote macro. It evaluates the expression inside and\n splices the list into quasiquote's result. If it is not the last element of the\n expression, the computed value must be a pair."),unquote:l("unquote",function(){throw new Error("You can't call `unquote` outside of quasiquote")},"(unquote code) or ,code\n\n Special form used in the quasiquote macro. It evaluates the expression inside and\n substitutes the value into quasiquote's result."),quasiquote:J.defmacro("quasiquote",function(e,t){var o=t.use_dynamic,s=t.error;var c=this;var f=c;function u(e){return H(e)||Ki(e)||Array.isArray(e)}function l(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:u;if(H(e)){var n=e.car;var i=e.cdr;if(r(n)){n=t(n)}if(r(i)){i=t(i)}if(Bu(n)||Bu(i)){return Xn([n,i]).then(function(e){var t=b(e,2),r=t[0],n=t[1];return new Y(r,n)})}else{return new Y(n,i)}}return e}function a(e,t){if(H(e)){if(!K(t)){e.append(t)}}else{e=new Y(e,t)}return e}function r(e){return!!e.filter(function(e){return H(e)&&V.is(e.car,/^(unquote|unquote-splicing)$/)}).length}function h(e,n,i){return e.reduce(function(e,t){if(!H(t)){e.push(t);return e}if(V.is(t.car,"unquote-splicing")){var r;if(n+11){var t="You can't splice multiple atoms inside list";throw new Error(t)}if(!(H(i.cdr)&&K(r[0]))){return r[0]}}r=r.map(function(e){if(d.has(e)){return e.clone()}else{d.add(e);return e}});var n=v(i.cdr,0,1);if(K(n)&&K(r[0])){return undefined}return w(n,function(e){if(K(r[0])){return e}if(r.length===1){return a(r[0],e)}var t=r.reduce(function(e,t){return a(e,t)});return a(t,e)})})}(i.car.cdr)}var d=new Set;function v(e,t,r){if(H(e)){if(H(e.car)){if(V.is(e.car.car,"unquote-splicing")){return p(e,t+1,r)}if(V.is(e.car.car,"unquote")){if(t+2===r&&H(e.car.cdr)&&H(e.car.cdr.car)&&V.is(e.car.cdr.car.car,"unquote-splicing")){var n=e.car.cdr;return new Y(new Y(new V("unquote"),p(n,t+2,r)),$)}else if(H(e.car.cdr)&&!K(e.car.cdr.cdr)){if(H(e.car.cdr.car)){var i=[];return function t(r){if(K(r)){return Y.fromArray(i)}return w(k(r.car,{env:c,dynamic_env:f,use_dynamic:o,error:s}),function(e){i.push(e);return t(r.cdr)})}(e.car.cdr)}else{return e.car.cdr}}}}if(V.is(e.car,"quasiquote")){var u=v(e.cdr,t,r+1);return new Y(e.car,u)}if(V.is(e.car,"quote")){return new Y(e.car,v(e.cdr,t,r))}if(V.is(e.car,"unquote")){t++;if(tr){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(H(e.cdr)){if(!K(e.cdr.cdr)){if(H(e.cdr.car)){var a=[];return function t(r){if(K(r)){return Y.fromArray(a)}return w(k(r.car,{env:c,dynamic_env:f,use_dynamic:o,error:s}),function(e){a.push(e);return t(r.cdr)})}(e.cdr)}else{return e.cdr}}else{return k(e.cdr.car,{env:c,dynamic_env:f,error:s})}}else{return e.cdr}}return l(e,function(e){return v(e,t,r)})}else if(Ki(e)){return _(e,t,r)}else if(e instanceof Array){return h(e,t,r)}return e}function n(e){if(H(e)){delete e[Zu];if(!e.have_cycles("car")){n(e.car)}if(!e.have_cycles("cdr")){n(e.cdr)}}}if(Ki(e.car)&&!r(Object.values(e.car))){return oo(e.car)}if(Array.isArray(e.car)&&!r(e.car)){return oo(e.car)}if(H(e.car)&&!e.car.find("unquote")&&!e.car.find("unquote-splicing")&&!e.car.find("quasiquote")){return oo(e.car)}var i=v(e.car,0,1);return w(i,function(e){n(e);return oo(e)})},"(quasiquote list)\n\n Similar macro to `quote` but inside it you can use special expressions (unquote\n x) abbreviated to ,x that will evaluate x and insert its value verbatim or\n (unquote-splicing x) abbreviated to ,@x that will evaluate x and splice the value\n into the result. Best used with macros but it can be used outside."),clone:l("clone",function e(t){A("clone",t,"pair");return t.clone()},"(clone list)\n\n Function that returns a clone of the list, that does not share any pairs with the\n original, so the clone can be safely mutated without affecting the original."),append:l("append",function e(){var t;for(var r=arguments.length,n=new Array(r),i=0;iarray")(t).reverse();return G.get("array->list")(r)}else if(Array.isArray(t)){return t.reverse()}else{throw new Error(ko("reverse",Io(t),"array or pair"))}},"(reverse list)\n\n Function that reverses the list or array. If value is not a list\n or array it will error."),nth:l("nth",function e(t,r){A("nth",t,"number");A("nth",r,["array","pair"]);if(H(r)){var n=r;var i=0;while(iarray")(r).join(t)},"(join separator list)\n\n Function that returns a string by joining elements of the list using separator."),split:l("split",function e(t,r){A("split",t,["regex","string"]);A("split",r,"string");return G.get("array->list")(r.split(t))},"(split separator string)\n\n Function that creates a list by splitting string by separator which can\n be a string or regular expression."),replace:l("replace",function e(t,r,n){A("replace",t,["regex","string"]);A("replace",r,["string","function"]);A("replace",n,"string");return n.replace(t,r)},"(replace pattern replacement string)\n\n Function that changes pattern to replacement inside string. Pattern can be a\n string or regex and replacement can be function or string. See Javascript\n String.replace()."),match:l("match",function e(t,r){A("match",t,["regex","string"]);A("match",r,"string");var n=r.match(t);return n?G.get("array->list")(n):false},"(match pattern string)\n\n Function that returns a match object from JavaScript as a list or #f if\n no match."),search:l("search",function e(t,r){A("search",t,["regex","string"]);A("search",r,"string");return r.search(t)},"(search pattern string)\n\n Function that returns the first found index of the pattern inside a string."),repr:l("repr",function e(t,r){return au(t,r)},"(repr obj)\n\n Function that returns a LIPS code representation of the object as a string."),"escape-regex":l("escape-regex",function(e){A("escape-regex",e,"string");return Rn(e.valueOf())},"(escape-regex string)\n\n Function that returns a new string where all special operators used in regex,\n are escaped with backslashes so they can be used in the RegExp constructor\n to match a literal string."),env:l("env",function e(e){e=e||this.env;var t=Object.keys(e.__env__).map(V);var r;if(t.length){r=Y.fromArray(t)}else{r=$}if(e.__parent__ instanceof F){return G.get("env").call(this,e.__parent__).append(r)}return r},"(env)\n (env obj)\n\n Function that returns a list of names (functions, macros and variables)\n that are bound in the current environment or one of its parents."),new:l("new",function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n2&&arguments[2]!==undefined?arguments[2]:ri.LITERAL;A("set-special!",e,"string",1);A("set-special!",t,"symbol",2);ri.append(e.valueOf(),t,r)},'(set-special! symbol name [type])\n\n Add a special symbol to the list of transforming operators by the parser.\n e.g.: `(add-special! "#" \'x)` will allow to use `#(1 2 3)` and it will be\n transformed into (x (1 2 3)) so you can write x macro that will process\n the list. 3rd argument is optional, and it can be one of two values:\n lips.specials.LITERAL, which is the default behavior, or\n lips.specials.SPLICE which causes the value to be unpacked into the expression.\n This can be used for e.g. to make `#(1 2 3)` into (x 1 2 3) that is needed\n by # that defines vectors.'),get:co,".":co,unbind:l(Vu,"(unbind fn)\n\n Function that removes the weak 'this' binding from a function so you\n can get properties from the actual function object."),type:l(Io,"(type object)\n\n Function that returns the type of an object as string."),debugger:l("debugger",function(){debugger},'(debugger)\n\n Function that triggers the JavaScript debugger (e.g. the browser devtools)\n using the "debugger;" statement. If a debugger is not running this\n function does nothing.'),in:l("in",function(e,t){if(e instanceof V||e instanceof D||e instanceof B){e=e.valueOf()}return e in Uu(t)},'(in key value)\n\n Function that uses the Javascript "in" operator to check if key is\n a valid property in the value.'),"instance?":l("instance?",function(e){return Nu(e)},"(instance? obj)\n\n Checks if object is an instance, created with a new operator"),instanceof:l("instanceof",function(e,t){return t instanceof Vu(e)},"(instanceof type obj)\n\n Predicate that tests if the obj is an instance of type."),"prototype?":l("prototype?",Fu,"(prototype? obj)\n\n Predicate that tests if value is a valid JavaScript prototype,\n i.e. calling (new) with it will not throw ' is not a constructor'."),"macro?":l("macro?",function(e){return e instanceof J},"(macro? expression)\n\n Predicate that tests if value is a macro."),"continuation?":l("continuation?",Au,"(continuation? expression)\n\n Predicate that tests if value is a callable continuation."),"function?":l("function?",d,"(function? expression)\n\n Predicate that tests if value is a callable function."),"real?":l("real?",function(e){if(Io(e)!=="number"){return false}if(e instanceof B){return e.isFloat()}return B.isFloat(e)},"(real? number)\n\n Predicate that tests if value is a real number (not complex)."),"number?":l("number?",function(e){return Number.isNaN(e)||B.isNumber(e)},"(number? expression)\n\n Predicate that tests if value is a number or NaN value."),"string?":l("string?",function(e){return D.isString(e)},"(string? expression)\n\n Predicate that tests if value is a string."),"pair?":l("pair?",H,"(pair? expression)\n\n Predicate that tests if value is a pair or list structure."),"regex?":l("regex?",function(e){return e instanceof RegExp},"(regex? expression)\n\n Predicate that tests if value is a regular expression."),"null?":l("null?",function(e){return xu(e)},"(null? expression)\n\n Predicate that tests if value is null-ish (i.e. undefined, nil, or\n Javascript null)."),"boolean?":l("boolean?",function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Predicate that tests if value is a boolean (#t or #f)."),"symbol?":l("symbol?",function(e){return e instanceof V},"(symbol? expression)\n\n Predicate that tests if value is a LIPS symbol."),"array?":l("array?",function(e){return e instanceof Array},"(array? expression)\n\n Predicate that tests if value is an array."),"object?":l("object?",function(e){return!K(e)&&e!==null&&!(e instanceof h)&&!(e instanceof RegExp)&&!(e instanceof D)&&!H(e)&&!(e instanceof B)&&_(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Predicate that tests if value is an plain object (not another LIPS type)."),flatten:l("flatten",function e(t){A("flatten",t,"pair");return t.flatten()},"(flatten list)\n\n Returns a shallow list from tree structure (pairs)."),"array->list":l("array->list",function(e){A("array->list",e,"array");return Y.fromArray(e)},"(array->list array)\n\n Function that converts a JavaScript array to a LIPS cons list."),"tree->array":l("tree->array",Yi("tree->array",true),"(tree->array list)\n\n Function that converts a LIPS cons tree structure into a JavaScript array."),"list->array":l("list->array",Yi("list->array"),"(list->array list)\n\n Function that converts a LIPS list into a JavaScript array."),apply:l("apply",function e(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;iarray").call(this,u));return t.apply(this,Mo(t,n))},"(apply fn list)\n\n Function that calls fn with the list of arguments."),length:l("length",function e(t){if(!t||K(t)){return 0}if(H(t)){return t.length()}if("length"in t){return t.length}},'(length expression)\n\n Function that returns the length of the object. The object can be a LIPS\n list or any object that has a "length" property. Returns undefined if the\n length could not be found.'),"string->number":l("string->number",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;A("string->number",e,"string",1);A("string->number",t,"number",2);e=e.valueOf();t=t.valueOf();if(e.match(bn)||e.match(mn)){return Fn(e,t)}else if(e.match(wn)||e.match(vn)){return On(e,t)}else{var r=t===10&&!e.match(/e/i)||t===16;if(e.match(gn)&&r||e.match(yn)){return An(e,t)}if(e.match(un)){return Bn(e)}}return false},"(string->number number [radix])\n\n Function that parses a string into a number."),try:l(new J("try",function(r,e){var l=this;var h=e.use_dynamic;e.error;return new Promise(function(t,o){var s,n;if(V.is(r.cdr.car.car,"catch")){s=r.cdr.car;if(H(r.cdr.cdr)&&V.is(r.cdr.cdr.car.car,"finally")){n=r.cdr.cdr.car}}else if(V.is(r.cdr.car.car,"finally")){n=r.cdr.car}if(!(n||s)){throw new Error("try: invalid syntax")}function c(e){t(e);throw new io("[CATCH]")}var f=function e(t,r){r(t)};if(n){f=function e(t,r){f=o;i.error=function(e){throw e};w(k(new Y(new V("begin"),n.cdr),i),function(){r(t)})}}var i={env:l,use_dynamic:h,dynamic_env:l,error:function e(t){if(t instanceof io){throw t}if(s){var r=l.inherit("try");var n=s.cdr.car.car;if(!(n instanceof V)){throw new Error("try: invalid syntax: catch require variable name")}r.set(n,t);var i;var u={env:r,use_dynamic:h,dynamic_env:l,error:function e(t){i=true;o(t);throw new io("[CATCH]")}};var a=k(new Y(new V("begin"),s.cdr.cdr),u);w(a,function e(t){if(!i){f(t,c)}})}else{f(undefined,function(){o(t)})}}};var e=k(r.car,i);w(e,function(e){f(e,t)},i.error)})}),"(try expr (catch (e) code))\n (try expr (catch (e) code) (finally code))\n (try expr (finally code))\n\n Macro that executes expr and catches any exceptions thrown. If catch is provided\n it's executed when an error is thrown. If finally is provided it's always\n executed at the end."),raise:l("raise",function(e){throw e},"(raise obj)\n\n Throws the object verbatim (no wrapping an a new Error)."),throw:l("throw",function(e){throw new Error(e)},"(throw string)\n\n Throws a new exception."),find:l("find",function t(r,n){A("find",r,["regex","function"]);A("find",n,["pair","nil"]);if(xu(n)){return $}var e=yi("find",r);return w(e(n.car),function(e){if(e&&!K(e)){return n.car}return t(r,n.cdr)})},"(find fn list)\n (find regex list)\n\n Higher-order function that finds the first value for which fn return true.\n If called with a regex it will create a matcher function."),"for-each":l("for-each",function(e){var t;A("for-each",e,"function");for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i1?t-1:0),u=1;u3?n-3:0),u=3;u3?i-3:0),a=3;aarray")(r);var u=[];var a=yi("filter",t);return function t(r){function e(e){if(e&&!K(e)){u.push(n)}return t(++r)}if(r===i.length){return Y.fromArray(u)}var n=i[r];return w(a(n),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher-order function that calls `fn` for each element of the list\n and return a new list for only those elements for which fn returns\n a truthy value. If called with a regex it will create a matcher function."),compose:l(ma,"(compose . fns)\n\n Higher-order function that creates a new function that applies all functions\n from right to left and returns the last value. Reverse of pipe.\n e.g.:\n ((compose (curry + 2) (curry * 3)) 10) --\x3e (+ 2 (* 3 10)) --\x3e 32"),pipe:l(va,"(pipe . fns)\n\n Higher-order function that creates a new function that applies all functions\n from left to right and returns the last value. Reverse of compose.\n e.g.:\n ((pipe (curry + 2) (curry * 3)) 10) --\x3e (* 3 (+ 2 10)) --\x3e 36"),curry:l(xa,"(curry fn . args)\n\n Higher-order function that creates a curried version of the function.\n The result function will have partially applied arguments and it\n will keep returning one-argument functions until all arguments are provided,\n then it calls the original function with the accumulated arguments.\n\n e.g.:\n (define (add a b c d) (+ a b c d))\n (define add1 (curry add 1))\n (define add12 (add 2))\n (display (add12 3 4))"),gcd:l("gcd",function e(){for(var t=arguments.length,r=new Array(t),n=0;no?u%=o:o%=u}u=cu(s*r[a])/(u+o)}return B(u)},"(lcm n1 n2 ...)\n\n Function that returns the least common multiple of the arguments."),"odd?":l("odd?",ba(function(e){return B(e).isOdd()}),"(odd? number)\n\n Checks if number is odd."),"even?":l("even?",ba(function(e){return B(e).isEven()}),"(even? number)\n\n Checks if number is even."),"*":l("*",Da(function(e,t){return B(e).mul(t)},B(1)),"(* . numbers)\n\n Multiplies all numbers passed as arguments. If single value is passed\n it will return that value."),"+":l("+",Da(function(e,t){return B(e).add(t)},B(0)),"(+ . numbers)\n\n Sums all numbers passed as arguments. If single value is passed it will\n return that value."),"-":l("-",function(){for(var e=arguments.length,t=new Array(e),r=0;r":l(">",function(){for(var e=arguments.length,t=new Array(e),r=0;r",t,["bigint","float","rational"]);return fu(function(e,t){return B(e).cmp(t)===1},t)},"(> x1 x2 x3 ...)\n\n Function that compares its numerical arguments and checks if they are\n monotonically decreasing, i.e. x1 > x2 and x2 > x3 and so on."),"<":l("<",function(){for(var e=arguments.length,t=new Array(e),r=0;r=":l(">=",function(){for(var e=arguments.length,t=new Array(e),r=0;r=",t,["bigint","float","rational"]);return fu(function(e,t){return[0,1].includes(B(e).cmp(t))},t)},"(>= x1 x2 ...)\n\n Function that compares its numerical arguments and checks if they are\n monotonically nonincreasing, i.e. x1 >= x2 and x2 >= x3 and so on."),"eq?":l("eq?",lu,"(eq? a b)\n\n Function that compares two values if they are identical."),or:l(new J("or",function(e,t){var i=t.use_dynamic,u=t.error;var a=G.get("list->array")(e);var o=this;var s=o;if(!a.length){return false}var c;return function t(){function e(e){c=e;if(c!==false){return c}else{return t()}}if(!a.length){if(c!==false){return c}else{return false}}else{var r=a.shift();var n=k(r,{env:o,dynamic_env:s,use_dynamic:i,error:u});return w(n,e)}}()}),"(or . expressions)\n\n Macro that executes the values one by one and returns the first that is\n a truthy value. If there are no expressions that evaluate to true it\n returns false."),and:l(new J("and",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=t.error;var i=G.get("list->array")(e);var u=this;var a=u;if(!i.length){return true}var o;var s={env:u,dynamic_env:a,use_dynamic:r,error:n};return function t(){function e(e){o=e;if(o===false){return false}else{return t()}}if(!i.length){if(o!==false){return o}else{return false}}else{var r=i.shift();return w(k(r,s),e)}}()}),"(and . expressions)\n\n Macro that evaluates each expression in sequence and if any value returns false\n it will stop and return false. If each value returns true it will return the\n last value. If it's called without arguments it will return true."),"|":l("|",function(e,t){return B(e).or(t)},"(| a b)\n\n Function that calculates the bitwise or operation."),"&":l("&",function(e,t){return B(e).and(t)},"(& a b)\n\n Function that calculates the bitwise and operation."),"~":l("~",function(e){return B(e).neg()},"(~ number)\n\n Function that calculates the bitwise inverse (flip all the bits)."),">>":l(">>",function(e,t){return B(e).shr(t)},"(>> a b)\n\n Function that right shifts the value a by value b bits."),"<<":l("<<",function(e,t){return B(e).shl(t)},"(<< a b)\n\n Function that left shifts the value a by value b bits."),not:l("not",function e(t){if(xu(t)){return true}return!t},"(not object)\n\n Function that returns the Boolean negation of its argument.")},undefined,"global");var vo=G.inherit("user-env");function mo(e,t){e.constant("**internal-env**",t);e.doc("**internal-env**","**internal-env**\n\n Constant used to hide stdin, stdout and stderr so they don't interfere\n with variables with the same name. Constants are an internal type\n of variable that can't be redefined, defining a variable with the same name\n will throw an error.");G.set("**interaction-environment**",e)}mo(vo,ho);G.doc("**interaction-environment**","**interaction-environment**\n\n Internal dynamic, global variable used to find interpreter environment.\n It's used so the read and write functions can locate **internal-env**\n that contains the references to stdin, stdout and stderr.");function yo(e){vo.get("**internal-env**").set("fs",e)}(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(t){var r=e[t]?e[t]:t;G.set(r,l(r,function(e){A(r,e,"number");if(e instanceof B){return e[t]()}},"(".concat(r," number)\n\n Function that calculates the ").concat(r," of a number.")))})})();function go(e){if(e.length===1){return e[0]}else{var t=[];var r=go(e.slice(1));for(var n=0;n3&&arguments[3]!==undefined?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(n!==null){i+=" (argument ".concat(n,")")}if(d(r)){return"Invalid type: got ".concat(t).concat(i)}if(r instanceof Array){if(r.length===1){var u=r[0].toLowerCase();r="a"+("aeiou".includes(u)?"n ":" ")+r[0]}else{r=new Intl.ListFormat("en",{style:"long",type:"disjunction"}).format(r)}}return"Expecting ".concat(r," got ").concat(t).concat(i)}function Oo(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;A(e,t,"number",n);var i=t.__type__;var u;if(H(r)){r=r.to_array()}if(r instanceof Array){r=r.map(function(e){return e.valueOf()})}if(r instanceof Array){r=r.map(function(e){return e.valueOf().toLowerCase()});if(r.includes(i)){u=true}}else{r=r.valueOf().toLowerCase()}if(!u&&i!==r){throw new Error(ko(e,i,r,n))}}function Co(r,e,n){e.forEach(function(e,t){Oo(r,e,n,t+1)})}function So(r,e,n){e.forEach(function(e,t){A(r,e,n,t+1)})}function jo(e,t,r){A(e,t,r);if(t.__type__===Za){throw new Error(ko(e,"binary-port","textual-port"))}}function A(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;e=e.valueOf();var i=Io(t).toLowerCase();if(d(r)){if(!r(t)){throw new Error(ko(e,i,r,n))}return}var u=false;if(H(r)){r=r.to_array()}if(r instanceof Array){r=r.map(function(e){return e.valueOf()})}if(r instanceof Array){r=r.map(function(e){return e.valueOf().toLowerCase()});if(r.includes(i)){u=true}}else{r=r.valueOf().toLowerCase()}if(!u&&i!==r){throw new Error(ko(e,i,r,n))}}function Bo(r){var n=new WeakMap;return function(e){var t=n.get(e);if(!t){t=r(e)}return t}}Io=Bo(Io);function Io(e){var t=$r.get(e);if(t){return t}if(_(e)==="object"){for(var r=0,n=Object.entries(Vr);r2&&arguments[2]!==undefined?arguments[2]:{},n=r.env,i=r.dynamic_env,u=r.use_dynamic;var a=n===null||n===void 0?void 0:n.new_frame(e,t);var o=i===null||i===void 0?void 0:i.new_frame(e,t);var s=new Vo({env:a,use_dynamic:u,dynamic_env:o});return Po(e.apply(s,t))}function qo(n,e){var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},i=t.env,u=t.dynamic_env,a=t.use_dynamic,r=t.error,o=r===void 0?function(){}:r;e=No(e,{env:i,dynamic_env:u,error:o,use_dynamic:a});return w(e,function(e){if(la(n)){n=Vu(n)}e=Mo(n,e);var t=e.slice();var r=Ro(n,t,{env:i,dynamic_env:u,use_dynamic:a});return w(r,function(e){if(H(e)){e.mark_cycles();return oo(e)}return Ru(e)},o)})}var Uo=new WeakMap;var zo=function(){function n(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;ue(this,n);fe(this,"__value__",void 0);fe(this,"__fn__",void 0);Br(this,Uo,{writable:true,value:void 0});this.__value__=e;if(t){if(!d(t)){throw new Error("Section argument to Parameter need to be function "+"".concat(Io(t)," given"))}this.__fn__=t}if(r){f(this,Uo,r)}}ce(n,[{key:"__name__",get:function e(){return t(this,Uo)},set:function e(t){f(this,Uo,t);if(this.__fn__){this.__fn__.__name__="fn-".concat(t)}}},{key:"invoke",value:function e(){if(d(this.__fn__)){return this.__fn__(this.__value__)}return this.__value__}},{key:"inherit",value:function e(t){return new n(t,this.__fn__,this.__name__)}}]);return n}();var Vo=function(){function t(e){ue(this,t);fe(this,"env",void 0);fe(this,"dynamic_env",void 0);fe(this,"use_dynamic",void 0);Object.assign(this,e)}ce(t,[{key:"__name__",get:function e(){return this.env.__name__}},{key:"__parent__",get:function e(){return this.env.__parent__}},{key:"get",value:function e(){var t;return(t=this.env).get.apply(t,arguments)}}]);return t}();function $o(e,t){var r=e.get(t.__name__,{throwError:false});if(Ou(r)&&r!==t){return r}var n=vo.get("**interaction-environment**");while(true){var i=e.get("parent.frame",{throwError:false});e=i(0);if(e===n){break}r=e.get(t.__name__,{throwError:false});if(Ou(r)&&r!==t){return r}}return t}var Yo=function(){function t(e){ue(this,t);fe(this,"__value__",void 0);this.__value__=e}ce(t,[{key:"invoke",value:function e(){if(this.__value__===null){throw new Error("Continuations are not implemented yet")}}}]);return t}();function k(o){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},s=e.env,c=e.dynamic_env,f=e.use_dynamic,t=e.error,l=t===void 0?Eo:t,r=he(e,jr);return function(e){try{if(!Cu(c)){c=s===true?vo:s||vo}if(f){s=c}else if(s===true){s=vo}else{s=s||G}var t={env:s,dynamic_env:c,use_dynamic:f,error:l};var r;if(xu(o)){return o}if(o instanceof V){return s.get(o)}if(!H(o)){return o}var n=o.car;var e=o.cdr;if(H(n)){r=Po(k(n,t));if(Bu(r)){return r.then(function(e){if(!Su(e)){throw new Error(Io(e)+" "+s.get("repr")(e)+" is not callable while evaluating "+o.toString())}return k(new Y(e,o.cdr),t)})}else if(!Su(r)){throw new Error(Io(r)+" "+s.get("repr")(r)+" is not callable while evaluating "+o.toString())}}if(n instanceof V){r=s.get(n)}else if(d(n)){r=n}var i;if(r instanceof yu){i=To(r,o,t)}else if(r instanceof J){i=Lo(r,e,t)}else if(d(r)){i=qo(r,e,t)}else if(r instanceof gu){i=To(r._syntax,o,t)}else if(Ou(r)){var u=$o(c,r);if(xu(o.cdr)){i=u.invoke()}else{return w(k(o.cdr.car,t),function(e){u.__value__=e})}}else if(Au(r)){i=r.invoke()}else if(H(o)){r=n&&n.toString();throw new Error("".concat(Io(n)," ").concat(r," is not a function"))}else{return o}var a=s.get(Symbol["for"]("__promise__"),{throwError:false});if(a===true&&Bu(i)){i=i.then(function(e){if(H(e)&&!r[Zu]){return k(e,t)}return e});return new Zn(i)}return i}catch(e){l&&l.call(s,e,o)}}(r)}var Jo=Go(function(e){return e});var Ko=Go(function(e,t){return t});function Ho(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.env,n=t.dynamic_env,i=t.use_dynamic;return k(e,{env:r,dynamic_env:n,use_dynamic:i,error:function e(t,r){if(t&&t.message){if(t.message.match(/^Error:/)){var n=/^(Error:)\s*([^:]+:\s*)/;t.message=t.message.replace(n,"$1 $2")}if(r){if(!(t.__code__ instanceof Array)){t.__code__=[]}t.__code__.push(r.toString(true))}}if(!(t instanceof io)){throw t}}})}function Go(d){return function(){var t=ie(function(l){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},h=e.env,_=e.dynamic_env,p=e.use_dynamic;return O.mark(function e(){var r,n,i,u,a,o,s,c,f;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!Cu(_)){_=h===true?vo:h||vo}if(h===true){h=vo}else{h=h||vo}r=[];if(!H(l)){t.next=8;break}t.next=6;return Ho(code,{env:h,dynamic_env:_,use_dynamic:p});case 6:t.t0=t.sent;return t.abrupt("return",[t.t0]);case 8:n=Array.isArray(l)?l:hi(l);i=false;u=false;t.prev=11;o=qr(n);case 13:t.next=15;return o.next();case 15:if(!(i=!(s=t.sent).done)){t.next=31;break}c=s.value;t.next=19;return Ho(c,{env:h,dynamic_env:_,use_dynamic:p});case 19:f=t.sent;t.t1=r;t.t2=d;t.t3=c;t.next=25;return f;case 25:t.t4=t.sent;t.t5=(0,t.t2)(t.t3,t.t4);t.t1.push.call(t.t1,t.t5);case 28:i=false;t.next=13;break;case 31:t.next=37;break;case 33:t.prev=33;t.t6=t["catch"](11);u=true;a=t.t6;case 37:t.prev=37;t.prev=38;if(!(i&&o["return"]!=null)){t.next=42;break}t.next=42;return o["return"]();case 42:t.prev=42;if(!u){t.next=45;break}throw a;case 45:return t.finish(42);case 46:return t.finish(37);case 47:return t.abrupt("return",r);case 48:case"end":return t.stop()}},e,null,[[11,33,37,47],[38,,42,46]])})()});function e(e){return t.apply(this,arguments)}return e}()}function Wo(e){var t={"[":"]","(":")"};var r;if(typeof e==="string"){r=Jn(e)}else{r=e.map(function(e){return e&&e.token?e.token:e})}var n=Object.keys(t);var i=Object.values(t).concat(n);r=r.filter(function(e){return i.includes(e)});var u=new qn;var a=Tr(r),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;if(n.includes(s)){u.push(s)}else if(!u.is_empty()){var c=u.top();var f=t[c];if(s===f){u.pop()}else{throw new Error("Syntax error: missing closing ".concat(f))}}else{throw new Error("Syntax error: not matched closing ".concat(s))}}}catch(e){a.e(e)}finally{a.f()}return u.is_empty()}function Qo(e){var t="("+e.toString()+")()";var r=window.URL||window.webkitURL;var n;try{n=new Blob([t],{type:"application/javascript"})}catch(e){var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;n=new i;n.append(t);n=n.getBlob()}return new zr.Worker(r.createObjectURL(n))}function Zo(){return Cs.version.match(/^(\{\{VER\}\}|DEV)$/)}function Xo(){if(xo()){return}var e;if(document.currentScript){e=document.currentScript}else{var t=document.querySelectorAll("script");if(!t.length){return}e=t[t.length-1]}var r=e.getAttribute("src");return r}var es=Xo();function ts(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"";var t="dist/std.xcb";if(e===""){if(es){e=es.replace(/[^/]*$/,"std.xcb")}else if(Zo()){e="https://cdn.jsdelivr.net/gh/jcubic/lips@devel/".concat(t)}else{e="https://cdn.jsdelivr.net/npm/@jcubic/lips@".concat(Cs.version,"/").concat(t)}}var r=G.get("load");return r.call(vo,e,G)}function rs(e){this.url=e;var a=this.worker=Qo(function(){var a;var o;self.addEventListener("message",function(e){var r=e.data;var t=r.id;if(r.type!=="RPC"||t===null){return}function n(e){self.postMessage({id:t,type:"RPC",result:e})}function i(e){self.postMessage({id:t,type:"RPC",error:e})}if(r.method==="eval"){if(!o){i("Worker RPC: LIPS not initialized, call init first");return}o.then(function(){var e=r.params[0];var t=r.params[1];a.exec(e,{use_dynamic:t}).then(function(e){e=e.map(function(e){return e&&e.valueOf()});n(e)})["catch"](function(e){i(e)})})}else if(r.method==="init"){var u=r.params[0];if(typeof u!=="string"){i("Worker RPC: url is not a string")}else{importScripts("".concat(u,"/dist/lips.min.js"));a=new Cs.Interpreter("worker");o=ts(u);o.then(function(){n(true)})}}})});this.rpc=function(){var n=0;return function e(t,r){var u=++n;return new Promise(function(n,i){a.addEventListener("message",function e(t){var r=t.data;if(r&&r.type==="RPC"&&r.id===u){if(r.error){i(r.error)}else{n(r.result)}a.removeEventListener("message",e)}});a.postMessage({type:"RPC",method:t,id:u,params:r})})}}();this.rpc("init",[e])["catch"](function(e){console.error(e)});this.exec=function(e,t){var r=t.use_dynamic,n=r===void 0?false:r;return this.rpc("eval",[e,n])}}var ns={pair:function e(t){var r=b(t,2),n=r[0],i=r[1];return Y(n,i)},number:function e(t){if(D.isString(t)){return B([t,10])}return B(t)},regex:function e(t){var r=b(t,2),n=r[0],i=r[1];return new RegExp(n,i)},nil:function e(){return $},symbol:function e(t){if(D.isString(t)){return V(t)}else if(Array.isArray(t)){return V(Symbol["for"](t[0]))}},string:D,character:h};var is=Object.keys(ns);var us={};for(var as=0,os=Object.entries(is);as1){var n=t.reduce(function(e,t){return e+t.length},0);var i=new Uint8Array(n);var u=0;t.forEach(function(e){i.set(e,u);u+=e.length});return i}else if(t.length){return t[0]}}function ms(){var e=1;var t=new TextEncoder("utf-8");return t.encode("LIPS".concat(e.toString().padStart(3," ")))}var ys=7;function gs(e){var t=new TextDecoder("utf-8");var r=t.decode(e.slice(0,ys));var n=r.substring(0,4);if(n==="LIPS"){var i=r.match(/^(....).*([0-9]+)$/);if(i){return{type:i[1],version:Number(i[2])}}}return{type:"unknown"}}function bs(e){var t=ms();var r=ds.encode(e);return vs(t,xr(r,{magic:false}))}function ws(e){var t=gs(e),r=t.type,n=t.version;if(r==="LIPS"&&n===1){var i=Er(e.slice(ys),{magic:false});return ds.decode(i)}else{throw new Error("Invalid file format ".concat(r))}}function Ds(e){console.error(e.message||e);if(Array.isArray(e.code)){console.error(e.code.map(function(e,t){return"[".concat(t+1,"]: ").concat(e)}))}}function xs(){var a=["text/x-lips","text/x-scheme"];var o;function s(e){var t;return(t=e.getAttribute("data-bootstrap"))!==null&&t!==void 0?t:e.getAttribute("bootstrap")}function c(r){return new Promise(function(t){var e=r.getAttribute("src");if(e){return fetch(e).then(function(e){return e.text()}).then(Ko).then(t)["catch"](function(e){Ds(e);t()})}else{return Ko(r.innerHTML).then(t)["catch"](function(e){Ds(e);t()})}})}function e(){return new Promise(function(i){var u=Array.from(document.querySelectorAll("script"));return function e(){var t=u.shift();if(!t){i()}else{var r=t.getAttribute("type");if(a.includes(r)){var n=s(t);if(!o&&typeof n==="string"){return ts(n).then(function(){return c(t)}).then(e)}else{return c(t).then(e)}}else if(r&&r.match(/lips|lisp/)){console.warn("Expecting "+a.join(" or ")+" found "+r)}return e()}}()})}if(!window.document){return Promise.resolve()}else if(Es){var t=Es;var r=s(t);if(typeof r==="string"){return ts(r).then(function(){o=true;return e()})}}return e()}var Es=typeof window!=="undefined"&&window.document&&document.currentScript;if(typeof window!=="undefined"){Gr(window,xs)}var Fs=function(){var e=D("Tue, 05 Mar 2024 13:03:01 +0000").valueOf();var t=e==="{{"+"DATE}}"?new Date:new Date(e);var r=function e(t){return t.toString().padStart(2,"0")};var n=t.getFullYear();var i=[n,r(t.getMonth()+1),r(t.getDate())].join("-");var u="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter DEV (".concat(i,") \nCopyright (c) 2018-").concat(n," Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables. You can also\nuse (help name) to display help for specific function or macro, (apropos name)\nto display list of matched names in environment and (dir object) to list\nproperties of an object.\n").replace(/^.*\n/,"");return u}();c(Ei,"__class__","ahead");c(Y,"__class__","pair");c($i,"__class__","nil");c(Fi,"__class__","pattern");c(xi,"__class__","formatter");c(J,"__class__","macro");c(yu,"__class__","syntax");c(yu.Parameter,"__class__","syntax-parameter");c(F,"__class__","environment");c(Ua,"__class__","input-port");c(za,"__class__","output-port");c(Va,"__class__","output-port");c($a,"__class__","output-string-port");c(Ja,"__class__","input-string-port");c(Ga,"__class__","input-file-port");c(Ya,"__class__","output-file-port");c(no,"__class__","lips-error");[B,y,x,g,E].forEach(function(e){c(e,"__class__","number")});c(h,"__class__","character");c(V,"__class__","symbol");c(D,"__class__","string");c(Zn,"__class__","promise");c(zo,"__class__","parameter");var As="DEV";var ks="Tue, 05 Mar 2024 13:03:01 +0000";var Os=ma(vi,hi);var Cs={version:As,banner:Fs,date:ks,exec:Ko,parse:Os,tokenize:Jn,evaluate:k,compile:Jo,serialize:_s,unserialize:ps,serialize_bin:bs,unserialize_bin:ws,bootstrap:ts,Environment:F,env:vo,Worker:rs,Interpreter:ro,balanced_parenthesis:Wo,balancedParenthesis:Wo,balanced:Wo,Macro:J,Syntax:yu,Pair:Y,Values:ao,QuotedPromise:Zn,Error:no,quote:oo,InputPort:Ua,OutputPort:za,BufferedOutputPort:Va,InputFilePort:Ga,OutputFilePort:Ya,InputStringPort:Ja,OutputStringPort:$a,InputByteVectorPort:Ka,OutputByteVectorPort:Ha,InputBinaryFilePort:Wa,OutputBinaryFilePort:Qa,set_fs:yo,Formatter:xi,Parser:fi,Lexer:s,specials:ri,repr:Ji,nil:$,eof:eo,LSymbol:V,LNumber:B,LFloat:g,LComplex:y,LRational:x,LBigInteger:E,LCharacter:h,LString:D,Parameter:zo,rationalize:Ra};G.set("lips",Cs);e.BufferedOutputPort=Va;e.Environment=F;e.Error=no;e.Formatter=xi;e.InputBinaryFilePort=Wa;e.InputByteVectorPort=Ka;e.InputFilePort=Ga;e.InputPort=Ua;e.InputStringPort=Ja;e.Interpreter=ro;e.LBigInteger=E;e.LCharacter=h;e.LComplex=y;e.LFloat=g;e.LNumber=B;e.LRational=x;e.LString=D;e.LSymbol=V;e.Lexer=s;e.Macro=J;e.OutputBinaryFilePort=Qa;e.OutputByteVectorPort=Ha;e.OutputFilePort=Ya;e.OutputPort=za;e.OutputStringPort=$a;e.Pair=Y;e.Parameter=zo;e.Parser=fi;e.QuotedPromise=Zn;e.Syntax=yu;e.Values=ao;e.Worker=rs;e.balanced=Wo;e.balancedParenthesis=Wo;e.balanced_parenthesis=Wo;e.banner=Fs;e.bootstrap=ts;e.compile=Jo;e.date=ks;e.env=vo;e.eof=eo;e.evaluate=k;e.exec=Ko;e.nil=$;e.parse=Os;e.quote=oo;e.rationalize=Ra;e.repr=Ji;e.serialize=_s;e.serialize_bin=bs;e.set_fs=yo;e.specials=ri;e.tokenize=Jn;e.unserialize=ps;e.unserialize_bin=ws;e.version=As}); \ No newline at end of file + */Object.defineProperty(ar,"__esModule",{value:true});const or=8,sr=6,cr=3,fr=(1<r-fr){t[i++]=e[n++];continue}f=(e[n]+13^e[n+1]-13^e[n+2])&hr-1;c=n-l[f]&lr;l[f]=n;u=n-c;if(u>=0&&u!=n&&e[n]==e[u]&&e[n+1]==e[u+1]&&e[n+2]==e[u+2]){t[a]|=o;for(s=cr;s>or;t[i++]=c;n+=s}else{t[i++]=e[n++]}}console.assert(e.length>=n);return i}function pr(e,t,r){t=t|0;var n=0,i=0,u=0,a=0,o=1<<(or-1|0),s=0,c=0;while(n>(or-sr|0))+cr|0;c=(e[n]<4){r[i]=r[u];i=i+1|0;u=u+1|0;r[i]=r[u];i=i+1|0;u=u+1|0;r[i]=r[u];i=i+1|0;u=u+1|0;r[i]=r[u];i=i+1|0;u=u+1|0;s=s-4|0}while(s>0){r[i]=r[u];i=i+1|0;u=u+1|0;s=s-1|0}}}else{r[i]=e[n];i=i+1|0;n=n+1|0}}return i}function dr(){const e=new TextEncoder("utf-8");return e.encode(vr)}const vr="@lzjb";const mr=dr();function yr(...e){if(e.length>1){const r=e.reduce((e,t)=>e+t.length,0);const n=new Uint8Array(r);let t=0;e.forEach(e=>{n.set(e,t);t+=e.length});return n}else if(e.length){return e[0]}}function gr(t){const e=Math.ceil(Math.log2(t)/8);const r=new Uint8Array(e);for(let e=0;e=0;e--){r=r*256+t[e]}return r}function wr(e,{magic:t=true}={}){const r=new Uint8Array(Math.max(e.length*1.5|0,16*1024));const n=_r(e,r);const i=gr(e.length);const u=[Uint8Array.of(i.length),i,r.slice(0,n)];if(t){u.unshift(mr)}return yr(...u)}function Dr(t,{magic:e=true}={}){if(e){const e=new TextDecoder("utf-8");const s=e.decode(t.slice(0,mr.length));if(s!==vr){throw new Error("Invalid magic value")}}const r=e?mr.length:0;const n=t[r];const i=r+1;const u=r+n+1;const a=br(t.slice(i,u));t=t.slice(u);const o=new Uint8Array(a);pr(t,t.length,o);return o}var xr=ar.pack=wr;var Er=ar.unpack=Dr;function Fr(s,c){return c=c||{},new Promise(function(e,t){var r=new XMLHttpRequest,n=[],i=[],u={},a=function(){return{ok:2==(r.status/100|0),statusText:r.statusText,status:r.status,url:r.responseURL,text:function(){return Promise.resolve(r.responseText)},json:function(){return Promise.resolve(r.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([r.response]))},clone:a,headers:{keys:function(){return n},entries:function(){return i},get:function(e){return u[e.toLowerCase()]},has:function(e){return e.toLowerCase()in u}}}};for(var o in r.open(c.method||"get",s,!0),r.onload=function(){r.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,t,r){n.push(t=t.toLowerCase()),i.push([t,r]),u[t]=u[t]?u[t]+","+r:r}),e(a())},r.onerror=t,r.withCredentials="include"==c.credentials,c.headers)r.setRequestHeader(o,c.headers[o]);r.send(c.body||null)})}var Ar=["token"],kr=["env"],Or=["stderr","stdin","stdout","command_line"],Cr=["use_dynamic"],Sr=["use_dynamic"],jr=["env","dynamic_env","use_dynamic","error"];function Br(e,t,r){Ir(e,t);t.set(e,r)}function Ir(e,t){if(t.has(e)){throw new TypeError("Cannot initialize the same private elements twice on an object")}}function Pr(e,t,r){return t=I(t),R(e,Nr()?Reflect.construct(t,r||[],I(e).constructor):t.apply(e,r))}function Nr(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Nr=function e(){return!!t})()}function Tr(t,e){var r=typeof Symbol!=="undefined"&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=Lr(t))||e&&t&&typeof t.length==="number"){if(r)t=r;var n=0;var i=function e(){};return{s:i,n:function e(){if(n>=t.length)return{done:true};return{done:false,value:t[n++]}},e:function e(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u=true,a=false,o;return{s:function e(){r=r.call(t)},n:function e(){var t=r.next();u=t.done;return t},e:function e(t){a=true;o=t},f:function e(){try{if(!u&&r["return"]!=null)r["return"]()}finally{if(a)throw o}}}}function Lr(e,t){if(!e)return;if(typeof e==="string")return Mr(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor)r=e.constructor.name;if(r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return Mr(e,t)}function Mr(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r1?r-1:0),i=1;i0&&arguments[0]!==undefined?arguments[0]:null;var t=vo&&vo.get("DEBUG",{throwError:false});if(e===null){return t===true}return(t===null||t===void 0?void 0:t.valueOf())===e.valueOf()}function Qr(e){return e?"(?:#".concat(e,"(?:#[ie])?|#[ie]#").concat(e,")"):"(?:#[ie])?"}function Zr(e,t){return"".concat(Qr(e),"[+-]?").concat(t,"+/").concat(t,"+")}function Xr(e,t){return"".concat(Qr(e),"(?:[+-]?(?:").concat(t,"+/").concat(t,"+|nan.0|inf.0|").concat(t,"+))?(?:[+-]i|[+-]?(?:").concat(t,"+/").concat(t,"+|").concat(t,"+|nan.0|inf.0)i)(?=[()[\\]\\s]|$)")}function en(e,t){return"".concat(Qr(e),"[+-]?").concat(t,"+")}var tn=/^#\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimyus]*)$/;var rn="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)";var nn="(?:#[ie])?(?:[+-]?(?:[0-9]+/[0-9]+|nan.0|inf.0|".concat(rn,"|[+-]?[0-9]+))?(?:").concat(rn,"|[+-](?:[0-9]+/[0-9]+|[0-9]+|nan.0|inf.0))i");var un=new RegExp("^(#[ie])?".concat(rn,"$"),"i");function an(e,t){var r=e==="x"?"(?!\\+|".concat(t,")"):"(?!\\.|".concat(t,")");var n="";if(e===""){n="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+(?![0-9]))(?:[eE][-+]?[0-9]+)?))"}return new RegExp("^((?:(?:".concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(t,"+/").concat(t,"+(?!").concat(t,")|[+-]?").concat(t,"+)").concat(r,")?)(").concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(t,"+/").concat(t,"+|[+-]?").concat(t,"+|[+-])i$"),"i")}var on=function(){var u={};[[10,"","[0-9]"],[16,"x","[0-9a-fA-F]"],[8,"o","[0-7]"],[2,"b","[01]"]].forEach(function(e){var t=b(e,3),r=t[0],n=t[1],i=t[2];u[r]=an(n,i)});return u}();var sn={alarm:"",backspace:"\b",delete:"",escape:"",newline:"\n",null:"\0",return:"\r",space:" ",tab:"\t",dle:"",soh:"",dc1:"",stx:"",dc2:"",etx:"",dc3:"",eot:"",dc4:"",enq:"",nak:"",ack:"",syn:"",bel:"",etb:"",bs:"\b",can:"",ht:"\t",em:"",lf:"\n",sub:"",vt:"\v",esc:"",ff:"\f",fs:"",cr:"\r",gs:"",so:"",rs:"",si:"",us:"",del:""};function cn(e){var t=[];var r=0;var n=e.length;while(r=55296&&i<=56319&&r1&&arguments[1]!==undefined?arguments[1]:10;var r=En(e);var n=r.number.split("/");var i=x({num:B([n[0],r.radix||t]),denom:B([n[1],r.radix||t])});if(r.inexact){return i.valueOf()}else{return i}}function An(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;var r=En(e);if(r.inexact){return g(parseInt(r.number,r.radix||t))}return B([r.number,r.radix||t])}function kn(e){var t=e.match(/#\\x([0-9a-f]+)$/i);var r;if(t){var n=parseInt(t[1],16);r=String.fromCodePoint(n)}else{t=e.match(/#\\([\s\S]+)$/);if(t){r=t[1]}}if(r){return h(r)}throw new Error("Parse: invalid character")}function On(e){var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;function t(e){var t;if(e==="+"){t=B(1)}else if(e==="-"){t=B(-1)}else if(e.match(gn)){t=B([e,i])}else if(e.match(bn)){var r=e.split("/");t=x({num:B([r[0],i]),denom:B([r[1],i])})}else if(e.match(un)){var n=Bn(e);if(u.exact){return n.toRational()}return n}else if(e.match(/nan.0$/)){return B(NaN)}else if(e.match(/inf.0$/)){if(e[0]==="-"){return B(Number.NEGATIVE_INFINITY)}return B(Number.POSITIVE_INFINITY)}else{throw new Error("Internal Parser Error")}if(u.inexact){return g(t.valueOf())}return t}var u=En(e);i=u.radix||i;var r;var n=u.number.match(Dn);if(i!==10&&n){r=n}else{r=u.number.match(on[i])}var a,o;o=t(r[2]);if(r[1]){a=t(r[1])}else{a=B(0)}if(o.cmp(0)===0&&o.__type__==="bigint"){return a}return y({im:o,re:a})}function Cn(e){return parseInt(e.toString(),10)===e}function Sn(e){var t=e.match(/^(([-+]?[0-9]*)(?:\.([0-9]+))?)e([-+]?[0-9]+)/i);if(t){var r=parseInt(t[4],10);var n;var i=t[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var u=t[3]&&t[3].length;if(i0&&(t.exact||!t.number.match(/\./))){return B(u).mul(o)}}}r=g(r);if(t.exact){return r.toRational()}return r}function In(e){e=e.replace(/\\x([0-9a-f]+);/gi,function(e,t){return"\\u"+t.padStart(4,"0")}).replace(/\n/g,"\\n");var t=e.match(/(\\*)(\\x[0-9A-F])/i);if(t&&t[1].length%2===0){throw new Error("Invalid string literal, unclosed ".concat(t[2]))}try{var r=D(JSON.parse(e));r.freeze();return r}catch(e){var n=e.message.replace(/in JSON /,"").replace(/.*Error: /,"");throw new Error("Invalid string literal: ".concat(n))}}function Pn(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var r={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,t){return String.fromCharCode(parseInt("0"+t,16))}).replace(/\\(.)/g,function(e,t){return r[t]||t})}return new V(e)}function Nn(e){if(po.hasOwnProperty(e)){return po[e]}if(e.match(/^"[\s\S]*"$/)){return In(e)}else if(e[0]==="#"){var t=e.match(tn);if(t){return new RegExp(t[1],t[2])}else if(e.match(_n)){return kn(e)}var r=e.match(/#\\(.+)/);if(r&&cn(r[1]).length===1){return kn(e)}}if(e.match(/[0-9a-f]|[+-]i/i)){if(e.match(yn)){return An(e)}else if(e.match(un)){return Bn(e)}else if(e.match(mn)){return Fn(e)}else if(e.match(vn)){return On(e)}}if(e.match(/^#[iexobd]/)){throw new Error("Invalid numeric constant: "+e)}return Pn(e)}function Tn(e){return!(["(",")","[","]"].includes(e)||ri.names().includes(e))}function Ln(e){return Tn(e)&&!(e.match(tn)||e.match(/^"[\s\S]*"$/)||e.match(yn)||e.match(un)||e.match(vn)||e.match(mn)||e.match(_n)||["#t","#f","nil"].includes(e))}var Mn=/"(?:\\[\S\s]|[^"])*"?/g;function Rn(e){if(typeof e==="string"){var t=/([-\\^$[\]()+{}?*.|])/g;return e.replace(t,"\\$1")}return e}function qn(){this.data=[]}qn.prototype.push=function(e){this.data.push(e)};qn.prototype.top=function(){return this.data[this.data.length-1]};qn.prototype.pop=function(){return this.data.pop()};qn.prototype.is_empty=function(){return!this.data.length};function Un(e){if(e instanceof D){e=e.valueOf()}var t=new s(e,{whitespace:true});var r=[];while(true){var n=t.peek(true);if(n===eo){break}r.push(n);t.skip()}return r}function zn(e){var t=e.token,r=he(e,Ar);if(t.match(/^"[\s\S]*"$/)&&t.match(/\n/)){var n=new RegExp("^ {1,"+(e.col+1)+"}","mg");t=t.replace(n,"")}return U({token:t},r)}function Vn(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(){};this.fn=e;this.cont=t}Vn.prototype.toString=function(){return"#"};function $n(n){return function(){for(var e=arguments.length,t=new Array(e),r=0;r1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof D){e=e.toString()}if(t){return Un(e)}else{var r=Un(e).map(function(e){if(e.token==="#\\ "||e.token=="#\\\n"){return e.token}return e.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return Kn(r)}}function Kn(e){var t=0;var r=null;var n=[];for(var i=0;i0&&arguments[0]!==undefined?arguments[0]:null;if(e instanceof V){if(e.is_gensym()){return e}e=e.valueOf()}if(Wn(e)){return V(e)}if(e!==null){return r(e,Symbol("#:".concat(e)))}t++;return r(t,Symbol("#:g".concat(t)))}}();function Zn(e){var r=this;var n={pending:true,rejected:false,fulfilled:false,reason:undefined,type:undefined};e=e.then(function(e){n.type=Io(e);n.fulfilled=true;n.pending=false;return e});c(this,"_promise",e,{hidden:true});if(d(e["catch"])){e=e["catch"](function(e){n.rejected=true;n.pending=false;n.reason=e})}Object.keys(n).forEach(function(t){Object.defineProperty(r,"__".concat(t,"__"),{enumerable:true,get:function e(){return n[t]}})});c(this,"__promise__",e);this.then=false}Zn.prototype.then=function(e){return new Zn(this.valueOf().then(e))};Zn.prototype["catch"]=function(e){return new Zn(this.valueOf()["catch"](e))};Zn.prototype.valueOf=function(){if(!this._promise){throw new Error("QuotedPromise: invalid promise created")}return this._promise};Zn.prototype.toString=function(){if(this.__pending__){return Zn.pending_str}if(this.__rejected__){return Zn.rejected_str}return"#")};Zn.pending_str="#";Zn.rejected_str="#";function Xn(e){if(Array.isArray(e)){return Promise.all(ei(e)).then(ti)}return e}function ei(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof Zn){t[r]=new uo(n)}else{t[r]=n}}return t}function ti(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof uo){t[r]=n.valueOf()}else{t[r]=n}}return t}var ri={LITERAL:Symbol["for"]("literal"),SPLICE:Symbol["for"]("splice"),SYMBOL:Symbol["for"]("symbol"),names:function e(){return Object.keys(this.__list__)},type:function e(t){try{return this.get(t).type}catch(e){console.log({name:t});console.log(e);return null}},get:function e(t){return this.__list__[t]},off:function e(t){var r=this;var n=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(Array.isArray(t)){t.forEach(function(e){return r.off(e,n)})}else if(n===null){delete this.__events__[t]}else{this.__events__=this.__events__.filter(function(e){return e!==n})}},on:function e(t,r){var n=this;if(Array.isArray(t)){t.forEach(function(e){return n.on(e,r)})}else if(!this.__events__[t]){this.__events__[t]=[r]}else{this.__events__[t].push(r)}},trigger:function e(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i",new V("quote-promise"),ri.LITERAL]];var si=oi.map(function(e){return e[0]});Object.freeze(si);Object.defineProperty(ri,"__builtins__",{writable:false,value:si});oi.forEach(function(e){var t=b(e,3),r=t[0],n=t[1],i=t[2];ri.append(r,n,i)});var s=function(){function _(e){var t=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=r.whitespace,i=n===void 0?false:n;ue(this,_);c(this,"__input__",e.replace(/\r/g,""));var u={};["_i","_whitespace","_col","_newline","_line","_state","_next","_token","_prev_char"].forEach(function(r){Object.defineProperty(t,r,{configurable:false,enumerable:false,get:function e(){return u[r]},set:function e(t){u[r]=t}})});this._whitespace=i;this._i=this._line=this._col=this._newline=0;this._state=this._next=this._token=null;this._prev_char=""}ce(_,[{key:"get",value:function e(t){return this.__internal[t]}},{key:"set",value:function e(t,r){this.__internal[t]=r}},{key:"token",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(t){var r=this._line;if(this._whitespace&&this._token==="\n"){--r}return{token:this._token,col:this._col,offset:this._i,line:r}}return this._token}},{key:"peek",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(this._i>=this.__input__.length){return eo}if(this._token){return this.token(t)}var r=this.next_token();if(r){this._token=this.__input__.substring(this._i,this._next);return this.token(t)}return eo}},{key:"skip",value:function e(){if(this._next!==null){this._token=null;this._i=this._next}}},{key:"read_line",value:function e(){var t=this.__input__.length;if(this._i>=t){return eo}for(var r=this._i;r=r){return eo}if(t+this._i>=r){return this.read_rest()}var n=this._i+t;var i=this.__input__.substring(this._i,n);var u=i.match(/\n/g);if(u){this._line+=u.length}this._i=n;return i}},{key:"peek_char",value:function e(){if(this._i>=this.__input__.length){return eo}return h(this.__input__[this._i])}},{key:"read_char",value:function e(){var t=this.peek_char();this.skip_char();return t}},{key:"skip_char",value:function e(){if(this._i1&&arguments[1]!==undefined?arguments[1]:{},n=r.prev_char,i=r["char"],u=r.next_char;var a=b(t,4),o=a[0],s=a[1],c=a[2],f=a[3];if(t.length!==5){throw new Error("Lexer: Invalid rule of length ".concat(t.length))}if(Eu(o)){if(o!==i){return false}}else if(!i.match(o)){return false}if(!ci(s,n)){return false}if(!ci(c,u)){return false}if(f!==this._state){return false}return true}},{key:"next_token",value:function e(){if(this._i>=this.__input__.length){return false}var t=true;e:for(var r=this._i,n=this.__input__.length;r2&&arguments[2]!==undefined?arguments[2]:null;var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;if(t.length===0){throw new Error("Lexer: invalid literal rule")}if(t.length===1){return[[t,n,i,null,null]]}var u=[];for(var a=0,o=t.length;a1&&arguments[1]!==undefined?arguments[1]:{},r=t.env,n=t.meta,i=n===void 0?false:n,u=t.formatter,a=u===void 0?zn:u;ue(this,o);if(e instanceof D){e=e.toString()}c(this,"_formatter",a,{hidden:true});c(this,"__lexer__",new s(e));c(this,"__env__",r);c(this,"_meta",i,{hidden:true});c(this,"_refs",[],{hidden:true});c(this,"_state",{parentheses:0},{hidden:true})}ce(o,[{key:"resolve",value:function e(t){return this.__env__&&this.__env__.get(t,{throwError:false})}},{key:"peek",value:function(){var e=ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=this.__lexer__.peek(true);if(!(r===eo)){t.next=4;break}return t.abrupt("return",eo);case 4:if(!this.is_comment(r.token)){t.next=7;break}this.skip();return t.abrupt("continue",0);case 7:if(!(r.token==="#;")){t.next=14;break}this.skip();if(!(this.__lexer__.peek()===eo)){t.next=11;break}throw new Error("Lexer: syntax error eof found after comment");case 11:t.next=13;return this._read_object();case 13:return t.abrupt("continue",0);case 14:return t.abrupt("break",17);case 17:r=this._formatter(r);if(!this._meta){t.next=20;break}return t.abrupt("return",r);case 20:return t.abrupt("return",r.token);case 21:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"reset",value:function e(){this._refs.length=0}},{key:"skip",value:function e(){this.__lexer__.skip()}},{key:"read",value:function(){var e=ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return this.peek();case 2:r=t.sent;this.skip();return t.abrupt("return",r);case 5:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"match_datum_label",value:function e(t){var r=t.match(/^#([0-9]+)=$/);return r&&r[1]}},{key:"match_datum_ref",value:function e(t){var r=t.match(/^#([0-9]+)#$/);return r&&r[1]}},{key:"is_open",value:function e(t){var r=["(","["].includes(t);if(r){this._state.parentheses++}return r}},{key:"is_close",value:function e(t){var r=[")","]"].includes(t);if(r){this._state.parentheses--}return r}},{key:"read_list",value:function(){var e=ie(O.mark(function e(){var r,n,i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=$,n=r;case 1:t.next=4;return this.peek();case 4:u=t.sent;if(!(u===eo)){t.next=7;break}return t.abrupt("break",32);case 7:if(!this.is_close(u)){t.next=10;break}this.skip();return t.abrupt("break",32);case 10:if(!(u==="."&&!K(r))){t.next=18;break}this.skip();t.next=14;return this._read_object();case 14:n.cdr=t.sent;i=true;t.next=30;break;case 18:if(!i){t.next=22;break}throw new Error("Parser: syntax error more than one element after dot");case 22:t.t0=Y;t.next=25;return this._read_object();case 25:t.t1=t.sent;t.t2=$;a=new t.t0(t.t1,t.t2);if(K(r)){r=a}else{n.cdr=a}n=a;case 30:t.next=1;break;case 32:return t.abrupt("return",r);case 33:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"read_value",value:function(){var e=ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return this.read();case 2:r=t.sent;if(!(r===eo)){t.next=5;break}throw new Error("Parser: Expected token eof found");case 5:return t.abrupt("return",Nn(r));case 6:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"is_comment",value:function e(t){return t.match(/^;/)||t.match(/^#\|/)&&t.match(/\|#$/)}},{key:"evaluate",value:function e(t){return k(t,{env:this.__env__,error:function e(t){throw t}})}},{key:"read_object",value:function(){var e=ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:this.reset();t.next=3;return this._read_object();case 3:r=t.sent;if(r instanceof li){r=r.valueOf()}if(!this._refs.length){t.next=7;break}return t.abrupt("return",w(this._resolve_object(r),function(e){if(H(e)){e.mark_cycles()}return e}));case 7:return t.abrupt("return",r);case 8:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"balanced",value:function e(){return this._state.parentheses===0}},{key:"ballancing_error",value:function e(t,r){var n=this._state.parentheses;var i;if(n<0){i=new Error("Parser: unexpected parenthesis");i.__code__=[r.toString()+")"]}else{i=new Error("Parser: expected parenthesis but eof found");var u=new RegExp("\\){".concat(n,"}$"));i.__code__=[t.toString().replace(u,"")]}throw i}},{key:"_resolve_object",value:function(){var t=ie(O.mark(function e(r){var n=this;var i;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!Array.isArray(r)){t.next=2;break}return t.abrupt("return",r.map(function(e){return n._resolve_object(e)}));case 2:if(!Ki(r)){t.next=6;break}i={};Object.keys(r).forEach(function(e){i[e]=n._resolve_object(r[e])});return t.abrupt("return",i);case 6:if(!H(r)){t.next=8;break}return t.abrupt("return",this._resolve_pair(r));case 8:return t.abrupt("return",r);case 9:case"end":return t.stop()}},e,this)}));function e(e){return t.apply(this,arguments)}return e}()},{key:"_resolve_pair",value:function(){var t=ie(O.mark(function e(r){return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!H(r)){t.next=15;break}if(!(r.car instanceof li)){t.next=7;break}t.next=4;return r.car.valueOf();case 4:r.car=t.sent;t.next=8;break;case 7:this._resolve_pair(r.car);case 8:if(!(r.cdr instanceof li)){t.next=14;break}t.next=11;return r.cdr.valueOf();case 11:r.cdr=t.sent;t.next=15;break;case 14:this._resolve_pair(r.cdr);case 15:return t.abrupt("return",r);case 16:case"end":return t.stop()}},e,this)}));function e(e){return t.apply(this,arguments)}return e}()},{key:"_read_object",value:function(){var e=ie(O.mark(function e(){var r,n,i,u,a,o,s,c,f,l,h;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return this.peek();case 2:r=t.sent;if(!(r===eo)){t.next=5;break}return t.abrupt("return",r);case 5:if(!ni(r)){t.next=38;break}n=ri.get(r);i=ii(r);this.skip();a=ai(r);if(!a){t.next=14;break}t.t0=undefined;t.next=17;break;case 14:t.next=16;return this._read_object();case 16:t.t0=t.sent;case 17:o=t.t0;if(i){t.next=25;break}s=this.__env__.get(n.symbol);if(!(typeof s==="function")){t.next=25;break}if(ui(r)){c=[o]}else if(K(o)){c=[]}else if(H(o)){c=o.to_array(false)}if(!(c||a)){t.next=24;break}return t.abrupt("return",Ro(s,a?[]:c,{env:this.__env__,dynamic_env:this.__env__,use_dynamic:false}));case 24:throw new Error("Parse Error: Invalid parser extension "+"invocation ".concat(n.symbol));case 25:if(ui(r)){u=new Y(n.symbol,new Y(o,$))}else{u=new Y(n.symbol,o)}if(!i){t.next=28;break}return t.abrupt("return",u);case 28:if(!(s instanceof J)){t.next=37;break}t.next=31;return this.evaluate(u);case 31:f=t.sent;if(!(H(f)||f instanceof V)){t.next=34;break}return t.abrupt("return",Y.fromArray([V("quote"),f]));case 34:return t.abrupt("return",f);case 37:throw new Error("Parse Error: invalid parser extension: "+n.symbol);case 38:l=this.match_datum_ref(r);if(!(l!==null)){t.next=44;break}this.skip();if(!this._refs[l]){t.next=43;break}return t.abrupt("return",new li(l,this._refs[l]));case 43:throw new Error("Parse Error: invalid datum label #".concat(l,"#"));case 44:h=this.match_datum_label(r);if(!(h!==null)){t.next=51;break}this.skip();this._refs[h]=this._read_object();return t.abrupt("return",this._refs[h]);case 51:if(!this.is_close(r)){t.next=55;break}this.skip();t.next=61;break;case 55:if(!this.is_open(r)){t.next=60;break}this.skip();return t.abrupt("return",this.read_list());case 60:return t.abrupt("return",this.read_value());case 61:case"end":return t.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()}]);return o}();var li=function(){function r(e,t){ue(this,r);this.name=e;this.data=t}ce(r,[{key:"valueOf",value:function e(){return this.data}}]);return r}();function hi(e,t){return _i.apply(this,arguments)}function _i(){_i=ge(O.mark(function e(r,n){var i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!n){if(G){n=G.get("**interaction-environment**",{throwError:false})}else{n=vo}}i=new fi(r,{env:n});case 3:t.next=6;return me(i.read_object());case 6:a=t.sent;if(!i.balanced()){i.ballancing_error(a,u)}if(!(a===eo)){t.next=10;break}return t.abrupt("break",15);case 10:u=a;t.next=13;return a;case 13:t.next=3;break;case 15:case"end":return t.stop()}},e)}));return _i.apply(this,arguments)}function w(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(e){return e};var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;if(Bu(e)){var n=e.then(t);if(r===null){return n}else{return n["catch"](r)}}if(e instanceof Array){return pi(e,t,r)}if(Ki(e)){return di(e,t,r)}return t(e)}function pi(t,r,e){if(t.find(Bu)){return w(Xn(t),function(e){if(Object.isFrozen(t)){Object.freeze(e)}return r(e)},e)}return r(t)}function di(t,e,r){var i=Object.keys(t);var n=[],u=[];var a=i.length;while(a--){var o=i[a];var s=t[o];n[a]=s;if(Bu(s)){u.push(s)}}if(u.length){return w(Xn(n),function(e){var n={};e.forEach(function(e,t){var r=i[t];n[r]=e});if(Object.isFrozen(t)){Object.freeze(n)}return n},r)}return e(t)}function c(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{},i=n.hidden,u=i===void 0?false:i;Object.defineProperty(e,t,{value:r,configurable:true,enumerable:!u})}function vi(e){return mi.apply(this,arguments)}function mi(){mi=ie(O.mark(function e(r){var n,i,u,a,o,s,c;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:n=[];i=false;u=false;t.prev=3;o=qr(r);case 5:t.next=7;return o.next();case 7:if(!(i=!(s=t.sent).done)){t.next=13;break}c=s.value;n.push(c);case 10:i=false;t.next=5;break;case 13:t.next=19;break;case 15:t.prev=15;t.t0=t["catch"](3);u=true;a=t.t0;case 19:t.prev=19;t.prev=20;if(!(i&&o["return"]!=null)){t.next=24;break}t.next=24;return o["return"]();case 24:t.prev=24;if(!u){t.next=27;break}throw a;case 27:return t.finish(24);case 28:return t.finish(19);case 29:return t.abrupt("return",n);case 30:case"end":return t.stop()}},e,null,[[3,15,19,29],[20,,24,28]])}));return mi.apply(this,arguments)}function yi(e,t){if(t instanceof RegExp){return function(e){return String(e).match(t)}}else if(d(t)){return t}throw new Error("Invalid matcher")}function l(e,t,r,n){if(typeof e!=="string"){t=arguments[0];r=arguments[1];n=arguments[2];e=null}if(r){if(n){t.__doc__=r}else{t.__doc__=gi(r)}}if(e){t.__name__=e}else if(t.name&&!ca(t)){t.__name__=t.name}return t}function gi(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function bi(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var r=e.length;if(t<=0){throw Error("previousSexp: Invalid argument sexp = ".concat(t))}e:while(t--&&r>=0){var n=1;while(n>0){var i=e[--r];if(!i){break e}if(i==="("||i.token==="("){n--}else if(i===")"||i.token===")"){n++}}r--}return e.slice(r+1)}function wi(e){if(!e||!e.length){return 0}var t=e.length;if(e[t-1].token==="\n"){return 0}while(--t){if(e[t].token==="\n"){var r=(e[t+1]||{}).token;if(r){return r.length}}}return 0}function Di(e,t){return f(e,t)===t.length;function f(r,n){function e(e,t){var r=Tr(e),n;try{for(r.s();!(n=r.n()).done;){var i=n.value;var u=f(i,t);if(u!==-1){return u}}}catch(e){r.e(e)}finally{r.f()}return-1}function t(){return r[u]===Symbol["for"]("symbol")&&!Ln(n[o])}function i(){var e=r[u+1];var t=n[o+1];if(e!==undefined&&t!==undefined){return f([e],[t])}}var u=0;var a={};for(var o=0;o0){continue}}else if(t()){return-1}}else if(r[u]instanceof Array){var c=f(r[u],n.slice(o));if(c===-1||c+o>n.length){return-1}o+=c-1;u++;continue}else{return-1}u++}if(r.length!==u){return-1}return n.length}}function xi(e){this.__code__=e.replace(/\r/g,"")}xi.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?(?:define(?:-values|-syntax|-macro|-class|-record-type)?|(?:call-with-(?:input-file|output-file|port))|lambda|let-env|try|catch|when|unless|while|syntax-rules|(let|letrec)(-syntax|\*?-values|\*)?)$/],shift:{1:["&","#"]}}};xi.match=Di;xi.prototype._options=function e(t){var r=xi.defaults;if(typeof t==="undefined"){return Object.assign({},r)}var n=t&&t.exceptions||{};var i=n.specials||[];var u=n.shift||{1:[]};return U(U(U({},r),t),{},{exceptions:{specials:[].concat(q(r.exceptions.specials),q(i)),shift:U(U({},u),{},{1:[].concat(q(r.exceptions.shift[1]),q(u[1]))})}})};xi.prototype.indent=function e(t){var r=Jn(this.__code__,true);return this._indent(r,t)};xi.exception_shift=function(u,e){function t(e){if(!e.length){return false}if(e.indexOf(u)!==-1){return true}else{var t=e.filter(function(e){return e instanceof RegExp});if(!t.length){return false}var r=Tr(t),n;try{for(r.s();!(n=r.n()).done;){var i=n.value;if(u.match(i)){return true}}}catch(e){r.e(e)}finally{r.f()}}return false}if(t(e.exceptions.specials)){return e.indent}var r=e.exceptions.shift;for(var n=0,i=Object.entries(r);n0){n.offset=0}if(u.toString()===t.toString()&&Wo(u)){return n.offset+u[0].col}else if(u.length===1){return n.offset+u[0].col+1}else{var s=-1;if(a){var c=xi.exception_shift(a.token,n);if(c!==-1){s=c}}if(s===-1){s=xi.exception_shift(u[1].token,n)}if(s!==-1){return n.offset+u[0].col+s}else if(u[0].line3&&u[1].line===u[3].line){if(u[1].token==="("||u[1].token==="["){return n.offset+u[1].col}return n.offset+u[3].col}else if(u[0].line===u[1].line){return n.offset+n.indent+u[0].col}else{var f=u.slice(2);for(var l=0;l")};Ei.prototype.match=function(e){return e.match(this.pattern)};function Fi(){for(var e=arguments.length,t=new Array(e),r=0;r")};xi.Pattern=Fi;xi.Ahead=Ei;var Ai=/^[[(]$/;var ki=/^[\])]$/;var Oi=/[^()[\]]/;var Ci=new Ei(/[^)\]]/);var Si=Symbol["for"]("*");var ji=new Fi([Ai,Si,ki],[Oi],"+");var Bi=new Fi([Ai,Si,ki],"+");var Ii=new Fi([Symbol["for"]("symbol")],"?");var Pi=new Fi([Symbol["for"]("symbol")],"*");var Ni=[Ai,Pi,ki];var Ti=new Fi([Ai,Symbol["for"]("symbol"),Si,ki],"+");var Li=Ui("syntax-rules");var Mi=Ui("define","lambda","define-macro","syntax-rules");var Ri=/^(?!.*\b(?:[()[\]]|define(?:-macro)?|let(?:\*|rec|-env|-syntax|)?|lambda|syntax-rules)\b).*$/;var qi=/^(?:#:)?(let(?:\*|rec|-env|-syntax)?)$/;function Ui(){for(var e=arguments.length,t=new Array(e),r=0;r0&&!o[e]){o[e]=bi(a,e)}});var s=Tr(i),c;try{for(s.s();!(c=s.n()).done;){var f=b(c.value,3),l=f[0],h=f[1],_=f[2];h=h.valueOf();var p=h>0?o[h]:a;var d=p.filter(function(e){return e.trim()&&!ni(e)});var v=r(p);var m=Di(l,d);var y=n.slice(u).find(function(e){return e.trim()&&!ni(e)});if(m&&(_ instanceof Ei&&_.match(y)||!_)){var g=u-v;if(n[g]!=="\n"){if(!n[g].trim()){n[g]="\n"}else{n.splice(g,0,"\n");u++}}u+=v;continue e}}}catch(e){s.e(e)}finally{s.f()}}this.__code__=n.join("");return this};xi.prototype._spaces=function(e){return" ".repeat(e)};xi.prototype.format=function e(t){var r=this.__code__.replace(/[ \t]*\n[ \t]*/g,"\n ");var n=Jn(r,true);var i=this._options(t);var u=0;var a=0;for(var o=0;o0){n=Math.floor(t()*r);r--;var i=[e[n],e[r]];e[r]=i[0];e[n]=i[1]}return e}function $i(){}$i.prototype.toString=function(){return"()"};$i.prototype.valueOf=function(){return undefined};$i.prototype.serialize=function(){return 0};$i.prototype.to_object=function(){return{}};$i.prototype.append=function(e){return new Y(e,$)};$i.prototype.to_array=function(){return[]};var $=new $i;function Y(e,t){if(typeof this!=="undefined"&&this.constructor!==Y||typeof this==="undefined"){return new Y(e,t)}this.car=e;this.cdr=t}function Yi(u,a){return function e(t){A(u,t,["pair","nil"]);if(K(t)){return[]}var r=[];var n=t;while(true){if(H(n)){if(n.have_cycles("cdr")){break}var i=n.car;if(a&&H(i)){i=this.get(u).call(this,i)}r.push(i);n=n.cdr}else if(K(n)){break}else{throw new Error("".concat(u,": can't convert improper list"))}}return r}}Y.prototype.flatten=function(){return Y.fromArray(zi(this.to_array()))};Y.prototype.length=function(){var e=0;var t=this;while(true){if(!t||K(t)||!H(t)||t.have_cycles("cdr")){break}e++;t=t.cdr}return e};Y.match=function(e,t){if(e instanceof V){return V.is(e,t)}else if(H(e)){return Y.match(e.car,t)||Y.match(e.cdr,t)}else if(Array.isArray(e)){return e.some(function(e){return Y.match(e,t)})}else if(Ki(e)){return Object.values(e).some(function(e){return Y.match(e,t)})}return false};Y.prototype.find=function(e){return Y.match(this,e)};Y.prototype.clone=function(){var r=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var n=new Map;function i(e){if(H(e)){if(n.has(e)){return n.get(e)}var t=new Y;n.set(e,t);if(r){t.car=i(e.car)}else{t.car=e.car}t.cdr=i(e.cdr);t[ea]=e[ea];return t}return e}return i(this)};Y.prototype.last_pair=function(){var e=this;while(true){if(!H(e.cdr)){return e}if(e.have_cycles("cdr")){break}e=e.cdr}};Y.prototype.to_array=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var t=[];if(H(this.car)){if(e){t.push(this.car.to_array())}else{t.push(this.car)}}else{t.push(this.car.valueOf())}if(H(this.cdr)){t=t.concat(this.cdr.to_array(e))}return t};Y.fromArray=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(H(e)||r&&e instanceof Array&&e[Zu]){return e}if(t===false){var n=$;for(var i=e.length;i--;){n=new Y(e[i],n)}return n}if(e.length&&!(e instanceof Array)){e=q(e)}var u=$;var a=e.length;while(a--){var o=e[a];if(o instanceof Array){o=Y.fromArray(o,t,r)}else if(typeof o==="string"){o=D(o)}else if(typeof o==="number"&&!Number.isNaN(o)){o=B(o)}u=new Y(o,u)}return u};Y.prototype.to_object=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var t=this;var r={};while(true){if(H(t)&&H(t.car)){var n=t.car;var i=n.car;if(i instanceof V){i=i.__name__}if(i instanceof D){i=i.valueOf()}var u=n.cdr;if(H(u)){u=u.to_object(e)}if(Lu(u)){if(!e){u=u.valueOf()}}r[i]=u;t=t.cdr}else{break}}return r};Y.fromPairs=function(e){return e.reduce(function(e,t){return new Y(new Y(new V(t[0]),t[1]),e)},$)};Y.fromObject=function(t){var e=Object.keys(t).map(function(e){return[e,t[e]]});return Y.fromPairs(e)};Y.prototype.reduce=function(e){var t=this;var r=$;while(true){if(!K(t)){r=e(r,t.car);t=t.cdr}else{break}}return r};Y.prototype.reverse=function(){if(this.have_cycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var t=$;while(!K(e)){var r=e.cdr;e.cdr=t;t=e;e=r}return t};Y.prototype.transform=function(n){function i(e){if(H(e)){if(e.replace){delete e.replace;return e}var t=n(e.car);if(H(t)){t=i(t)}var r=n(e.cdr);if(H(r)){r=i(r)}return new Y(t,r)}return e}return i(this)};Y.prototype.map=function(e){if(typeof this.car!=="undefined"){return new Y(e(this.car),K(this.cdr)?$:this.cdr.map(e))}else{return $}};var Ji=new Map;function Ki(e){return e&&_(e)==="object"&&e.constructor===Object}var Hi=Object.getOwnPropertyNames(Array.prototype);var Gi=[];Hi.forEach(function(e){Gi.push(Array[e],Array.prototype[e])});function Wi(e){e=Vu(e);return Gi.includes(e)}function Qi(e){return d(e)&&(ca(e)||e.__doc__)}function Zi(r){var e=r.constructor||Object;var n=Ki(r);var i=d(r[Symbol.asyncIterator])||d(r[Symbol.iterator]);var u;if(Ji.has(e)){u=Ji.get(e)}else{Ji.forEach(function(e,t){t=Vu(t);if(r instanceof t&&(t===Object&&n&&!i||t!==Object)){u=e}})}return u}var Xi=new Map;[[true,"#t"],[false,"#f"],[null,"null"],[undefined,"#"]].forEach(function(e){var t=b(e,2),r=t[0],n=t[1];Xi.set(r,n)});function eu(r){if(r&&_(r)==="object"){var n={};var e=Object.getOwnPropertySymbols(r);e.forEach(function(e){var t=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");n[t]=au(r[e])});var t=Object.getOwnPropertyNames(r);t.forEach(function(e){var t=r[e];if(t&&_(t)==="object"&&t.constructor===Object){n[e]=eu(t)}else{n[e]=au(t)}});return n}return r}function tu(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function ru(e,t){return e.hasOwnProperty(t)&&d(e.toString)}function nu(e){if(ha(e)){return"#"}var t=e.prototype&&e.prototype.constructor;if(d(t)&&ca(t)){if(e[ta]&&t.hasOwnProperty("__name__")){var r=t.__name__;if(D.isString(r)){r=r.toString();return"#")}return"#"}}if(e.hasOwnProperty("__name__")){var n=e.__name__;if(_(n)==="symbol"){n=Gn(n)}if(typeof n==="string"){return"#")}}if(ru(e,"toString")){return e.toString()}else if(e.name&&!ca(e)){return"#")}else{return"#"}}var iu=new Map;[[Error,function(e){return e.message}],[Y,function(e,t){var r=t.quote,n=t.skip_cycles,i=t.pair_args;if(!n){e.mark_cycles()}return e.toString.apply(e,[r].concat(q(i)))}],[h,function(e,t){var r=t.quote;if(r){return e.toString()}return e.valueOf()}],[D,function(e,t){var r=t.quote;e=e.toString();if(r){return JSON.stringify(e).replace(/\\n/g,"\n")}return e}],[RegExp,function(e){return"#"+e.toString()}]].forEach(function(e){var t=b(e,2),r=t[0],n=t[1];iu.set(r,n)});var uu=[V,J,ao,Ua,za,F,Zn];function au(e,t,r){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(Xi.has(e)){return Xi.get(e)}if(Fu(e)){return"#"}if(e){var n=e.constructor;if(iu.has(n)){for(var i=arguments.length,u=new Array(i>3?i-3:0),a=3;a"}if(e===null){return"null"}if(d(e)){if(d(e.toString)&&e.hasOwnProperty("toString")){return e.toString().valueOf()}return nu(e)}if(_(e)==="object"){var f=e.constructor;if(!f){f=Object}var l;if(typeof f.__class__==="string"){l=f.__class__}else{var h=Zi(e);if(h){if(d(h)){return h(e,t)}else{throw new Error("toString: Invalid repr value")}}l=f.name}if(d(e.toString)&&e.hasOwnProperty("toString")){return e.toString().valueOf()}if(Io(e)==="instance"){if(ca(f)&&f.__name__){l=f.__name__.valueOf()}else if(!ha(f)){l="instance"}}if(Pu(e,Symbol.iterator)){if(l){return"#")}return"#"}if(Pu(e,Symbol.asyncIterator)){if(l){return"#")}return"#"}if(l!==""){return"#<"+l+">"}return"#"}if(typeof e!=="string"){return e.toString()}return e}Y.prototype.mark_cycles=function(){su(this);return this};Y.prototype.have_cycles=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(!e){return this.have_cycles("car")||this.have_cycles("cdr")}return!!(this[ea]&&this[ea][e])};Y.prototype.is_cycle=function(){return ou(this)};function ou(e){if(!H(e)){return false}if(e.have_cycles()){return true}return ou(e.car,fn)||ou(e.cdr,fn)}function su(e){var t=[];var i=[];var u=[];function a(e){if(!t.includes(e)){t.push(e)}}function o(e,t,r,n){if(H(r)){if(n.includes(r)){if(!u.includes(r)){u.push(r)}if(!e[ea]){e[ea]={}}e[ea][t]=r;if(!i.includes(e)){i.push(e)}return true}}}var s=$n(function e(t,r){if(H(t)){delete t.ref;delete t[ea];a(t);r.push(t);var n=o(t,"car",t.car,r);var i=o(t,"cdr",t.cdr,r);if(!n){s(t.car,r.slice())}if(!i){return new Vn(function(){return e(t.cdr,r.slice())})}}});function r(e,t){if(H(e[ea][t])){var r=n.indexOf(e[ea][t]);e[ea][t]="#".concat(r,"#")}}s(e,[]);var n=t.filter(function(e){return u.includes(e)});n.forEach(function(e,t){e[Xu]="#".concat(t,"=")});i.forEach(function(e){r(e,"car");r(e,"cdr")})}Y.prototype.toString=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.nested,n=r===void 0?false:r;var i=[];if(this[Xu]){i.push(this[Xu]+"(")}else if(!n){i.push("(")}var u;if(this[ea]&&this[ea].car){u=this[ea].car}else{u=au(this.car,e,true)}if(u!==undefined){i.push(u)}if(H(this.cdr)){if(this[ea]&&this[ea].cdr){i.push(" . ");i.push(this[ea].cdr)}else{if(this.cdr[Xu]){i.push(" . ")}else{i.push(" ")}var a=this.cdr.toString(e,{nested:true});i.push(a)}}else if(!K(this.cdr)){i=i.concat([" . ",au(this.cdr,e,true)])}if(!n||this[Xu]){i.push(")")}return i.join("")};Y.prototype.set=function(e,t){this[e]=t;if(H(t)){this.mark_cycles()}};Y.prototype.append=function(e){if(e instanceof Array){return this.append(Y.fromArray(e))}var t=this;if(t.car===undefined){if(H(e)){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(!K(e)){while(true){if(H(t)&&!K(t.cdr)){t=t.cdr}else{break}}t.cdr=e}return this};Y.prototype.serialize=function(){return[this.car,this.cdr]};Y.prototype[Symbol.iterator]=function(){var r=this;return{next:function e(){var t=r;r=t.cdr;if(K(t)){return{value:undefined,done:true}}else{return{value:t.car,done:false}}}}};function cu(e){return e<0?-e:e}function fu(e,t){var r=re(t),n=r[0],i=r.slice(1);while(i.length>0){var u=i,a=b(u,1),o=a[0];if(!e(n,o)){return false}var s=i;var c=re(s);n=c[0];i=c.slice(1)}return true}function lu(e,t){if(d(e)){return d(t)&&Vu(e)===Vu(t)}else if(e instanceof B){if(!(t instanceof B)){return false}var r;if(e.__type__===t.__type__){if(e.__type__==="complex"){r=e.__im__.__type__===t.__im__.__type__&&e.__re__.__type__===t.__re__.__type__}else{r=true}if(r&&e.cmp(t)===0){if(e.valueOf()===0){return Object.is(e.valueOf(),t.valueOf())}return true}}return false}else if(typeof e==="number"){if(typeof t!=="number"){return false}if(Number.isNaN(e)){return Number.isNaN(t)}if(e===Number.NEGATIVE_INFINITY){return t===Number.NEGATIVE_INFINITY}if(e===Number.POSITIVE_INFINITY){return t===Number.POSITIVE_INFINITY}return lu(B(e),B(t))}else if(e instanceof h){if(!(t instanceof h)){return false}return e.__char__===t.__char__}else{return e===t}}function hu(e,t){if(Io(e)!==Io(t)){return false}if(!_u(e)){return false}if(e instanceof RegExp){return e.source===t.source}if(e instanceof D){return e.valueOf()===t.valueOf()}return lu(e,t)}function _u(e){return e instanceof V||D.isString(e)||K(e)||e===null||e instanceof h||e instanceof B||e===true||e===false}var pu=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e===0){return 0}else if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function J(e,t,r,n){if(typeof this!=="undefined"&&this.constructor!==J||typeof this==="undefined"){return new J(e,t)}A("Macro",e,"string",1);A("Macro",t,"function",2);if(r){if(n){this.__doc__=r}else{this.__doc__=gi(r)}}this.__name__=e;this.__fn__=t}J.defmacro=function(e,t,r,n){var i=new J(e,t,r,n);i.__defmacro__=true;return i};J.prototype.invoke=function(e,t,r){var n=t.env,i=he(t,kr);var u=U(U({},i),{},{macro_expand:r});var a=this.__fn__.call(n,e,u,this.__name__);return a};J.prototype.toString=function(){return"#")};var du="define-macro";var vu=-1e4;function mu(c){return function(){var r=ie(O.mark(function e(r,y){var u,g,n,i,a,b,w,D,x,E,F,A,o,k,s;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:s=function e(){s=ie(O.mark(function e(r,n,i){var u,a,o,s,c,f,l,h,_,p,d,v,m;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!(H(r)&&r.car instanceof V)){t.next=50;break}if(!r[Zu]){t.next=3;break}return t.abrupt("return",r);case 3:u=r.car.valueOf();a=i.get(r.car,{throwError:false});o=b(r.car);s=o||w(a,r)||D(a);if(!(s&&H(r.cdr.car))){t.next=28;break}if(!o){t.next=15;break}g=E(r.cdr.car);t.next=12;return A(r.cdr.car,n);case 12:c=t.sent;t.next=17;break;case 15:g=x(r.cdr.car);c=r.cdr.car;case 17:t.t0=Y;t.t1=r.car;t.t2=Y;t.t3=c;t.next=23;return k(r.cdr.cdr,n,i);case 23:t.t4=t.sent;t.t5=new t.t2(t.t3,t.t4);return t.abrupt("return",new t.t0(t.t1,t.t5));case 28:if(!F(u,a)){t.next=50;break}f=a instanceof yu?r:r.cdr;t.next=32;return a.invoke(f,U(U({},y),{},{env:i}),true);case 32:l=t.sent;if(!(a instanceof yu)){t.next=41;break}h=l,_=h.expr,p=h.scope;if(!H(_)){t.next=40;break}if(!(n!==-1&&n<=1||n")}return"#"};var gu=ce(function e(t){ue(this,e);c(this,"_syntax",t,{hidden:true});c(this._syntax,"_param",true,{hidden:true})});yu.Parameter=gu;function bu(e,t,P,N){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:{};var T={"...":{symbols:{},lists:[]},symbols:{}};var L=r.expansion,M=r.define;z(P);function R(t,e){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:false;z({code:e,pattern:t});if(_u(t)&&!(t instanceof V)){return hu(t,e)}if(t instanceof V&&P.includes(t.literal())){if(!V.is(e,t)){return false}var i=L.ref(t);return!i||i===M||i===G}if(Array.isArray(t)&&Array.isArray(e)){z("<<< a 1");if(t.length===0&&e.length===0){return true}if(V.is(t[1],N)){if(t[0]instanceof V){var u=t[0].valueOf();z("<<< a 2 "+n);if(n){var a=e.length-2;var o=a>0?e.slice(0,a):e;var s=Y.fromArray(o,false);if(!T["..."].symbols[u]){T["..."].symbols[u]=new Y(s,$)}else{T["..."].symbols[u].append(new Y(s,$))}}else{T["..."].symbols[u]=Y.fromArray(e,false)}}else if(Array.isArray(t[0])){z("<<< a 3");var c=q(r);if(!e.every(function(e){return R(t[0],e,c,true)})){return false}}if(t.length>2){var f=t.slice(2);return R(f,e.slice(-f.length),r,n)}return true}var l=R(t[0],e[0],r,n);z({first:l,pattern:t[0],code:e[0]});var h=R(t.slice(1),e.slice(1),r,n);z({first:l,rest:h});return l&&h}if(H(t)&&H(t.car)&&H(t.car.cdr)&&V.is(t.car.cdr.car,N)){z(">> 0");if(K(e)){z({pattern:t});if(t.car.car instanceof V){var _=t.car.car.valueOf();if(T["..."].symbols[_]){throw new Error("syntax: named ellipsis can only "+"appear onces")}T["..."].symbols[_]=e}}}if(H(t)&&H(t.cdr)&&V.is(t.cdr.car,N)){if(!K(t.cdr.cdr)){if(H(t.cdr.cdr)){var p=t.cdr.cdr.length();if(!H(e)){return false}var d=e.length();var v=e;while(d-1>p){v=v.cdr;d--}var m=v.cdr;v.cdr=$;if(!R(t.cdr.cdr,m,r,n)){return false}}}if(t.car instanceof V){var y=t.car.__name__;if(T["..."].symbols[y]&&!r.includes(y)&&!n){throw new Error("syntax: named ellipsis can only appear onces")}z(">> 1");if(K(e)){z(">> 2");if(n){z("NIL");T["..."].symbols[y]=$}else{z("NULL");T["..."].symbols[y]=null}}else if(H(e)&&(H(e.car)||K(e.car))){z(">> 3 "+n);if(n){if(T["..."].symbols[y]){var g=T["..."].symbols[y];if(K(g)){g=new Y($,new Y(e,$))}else{g=g.append(new Y(e,$))}T["..."].symbols[y]=g}else{T["..."].symbols[y]=new Y(e,$)}}else{z(">> 4");T["..."].symbols[y]=new Y(e,$)}}else{z(">> 6");if(H(e)){if(!H(e.cdr)&&!K(e.cdr)){z(">> 7 (b)");if(K(t.cdr.cdr)){return false}else if(!T["..."].symbols[y]){T["..."].symbols[y]=new Y(e.car,$);return R(t.cdr.cdr,e.cdr)}}var b=e.last_pair();if(!K(b.cdr)){if(K(t.cdr.cdr)){return false}else{var w=e.clone();w.last_pair().cdr=$;T["..."].symbols[y]=w;return R(t.cdr.cdr,b.cdr)}}z(">> 7 "+n);r.push(y);if(!T["..."].symbols[y]){T["..."].symbols[y]=new Y(e,$)}else{var D=T["..."].symbols[y];T["..."].symbols[y]=D.append(new Y(e,$))}z({IIIIII:T["..."].symbols[y]})}else if(t.car instanceof V&&H(t.cdr)&&V.is(t.cdr.car,N)){z(">> 8");T["..."].symbols[y]=null;return R(t.cdr.cdr,e)}else{z(">> 9");return false}}return true}else if(H(t.car)){var x=q(r);if(K(e)){z(">> 10");T["..."].lists.push($);return true}z(">> 11");var E=e;while(H(E)){if(!R(t.car,E.car,x,true)){return false}E=E.cdr}return true}if(Array.isArray(t.car)){var x=q(r);var F=e;while(H(F)){if(!R(t.car,F.car,x,true)){return false}F=F.cdr}return true}return false}if(t instanceof V){if(V.is(t,N)){throw new Error("syntax: invalid usage of ellipsis")}z(">> 12");var A=t.__name__;if(P.includes(A)){return true}if(n){var k,O;z(T["..."].symbols[A]);(O=(k=T["..."].symbols)[A])!==null&&O!==void 0?O:k[A]=[];T["..."].symbols[A].push(e)}else{T.symbols[A]=e}return true}if(H(t)&&H(e)){z(">> 13");z({a:13,code:e,pattern:t});if(K(e.cdr)){var C=t.car instanceof V&&t.cdr instanceof V;if(C){if(!R(t.car,e.car,r,n)){return false}z(">> 14");var S=t.cdr.valueOf();if(!(S in T.symbols)){T.symbols[S]=$}S=t.car.valueOf();if(!(S in T.symbols)){T.symbols[S]=e.car}return true}}z({pattern:t,code:e});if(H(t.cdr)&&H(t.cdr.cdr)&&t.cdr.car instanceof V&&V.is(t.cdr.cdr.car,N)&&H(t.cdr.cdr.cdr)&&!V.is(t.cdr.cdr.cdr.car,N)&&R(t.car,e.car,r,n)&&R(t.cdr.cdr.cdr,e.cdr,r,n)){var j=t.cdr.car.__name__;z({pattern:t,code:e,name:j});if(P.includes(j)){return true}T["..."].symbols[j]=null;return true}z("recur");z({pattern:t,code:e});var B=R(t.car,e.car,r,n);z({car:B,pattern:t.car,code:e.car});var I=R(t.cdr,e.cdr,r,n);z({car:B,cdr:I});if(B&&I){return true}}else if(K(t)&&(K(e)||e===undefined)){return true}else if(H(t.car)&&V.is(t.car.car,N)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(R(e,t)){return T}}function wu(e,i){function u(t){if(H(t)){if(!i.length){return t}var e=u(t.car);var r=u(t.cdr);return new Y(e,r)}else if(t instanceof V){var n=i.find(function(e){return e.gensym===t});if(n){return V(n.name)}return t}else{return t}}return u(e)}function Du(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var B=e.bindings,t=e.expr,I=e.scope,a=e.symbols,f=e.names,P=e.ellipsis;var l={};function o(e){if(e instanceof V){return true}return["string","symbol"].includes(_(e))}function N(e){if(!o(e)){var t=Io(e);throw new Error("syntax: internal error, need symbol got ".concat(t))}var r=e.valueOf();if(r===P){throw new Error("syntax: internal error, ellipis not transformed")}var n=_(r);if(["string","symbol"].includes(n)){if(r in B.symbols){return B.symbols[r]}else if(n==="string"&&r.match(/\./)){var i=r.split(".");var u=i[0];if(u in B.symbols){return Y.fromArray([V("."),B.symbols[u]].concat(i.slice(1).map(function(e){return D(e)})))}}}if(a.includes(r)){return e}return s(r,e)}function s(e,t){if(!l[e]){var r=I.ref(e);if(_(e)==="symbol"&&!r){e=t.literal()}if(l[e]){return l[e]}var n=Qn(e);if(r){var i=I.get(e);I.set(n,i)}else{var u=I.get(e,{throwError:false});if(typeof u!=="undefined"){I.set(n,u)}}f.push({name:e,gensym:n});l[e]=n;if(typeof e==="string"&&e.match(/\./)){var a=e.split(".").filter(Boolean),o=re(a),s=o[0],c=o.slice(1);if(l[s]){oa(n,"__object__",[l[s]].concat(q(c)))}}}return l[e]}function T(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:function(){};var i=r.nested;z({bindings:t,expr:e});if(Array.isArray(e)&&!e.length){return e}if(e instanceof V){var u=e.valueOf();if(Wn(e)&&!t[u]);z("[t 1");if(t[u]){if(H(t[u])){var a=t[u],o=a.car,s=a.cdr;if(i){var c=o.car,f=o.cdr;if(!K(f)){n(u,new Y(f,$))}return c}if(!K(s)){n(u,s)}return o}else if(t[u]instanceof Array){n(u,t[u].slice(1));return t[u][0]}}return N(e)}var l=Array.isArray(e);if(H(e)||l){var h=l?e[0]:e.car;var _=l?e[1]:H(e.cdr)&&e.cdr.car;if(h instanceof V&&V.is(_,P)){l?e.slice(2):e.cdr.cdr;z("[t 2");var p=h.valueOf();var d=t[p];if(d===null){return}else if(d){z({name:p,binding:t[p]});if(H(d)){z("[t 2 Pair "+i);var v=d.car,m=d.cdr;var y=l?e.slice(2):e.cdr.cdr;if(i){if(!K(m)){z("|| next 1");n(p,m)}if(l&&y.length||!K(y)&&!l){var g=T(y,t,r,n);if(l){return v.concat(g)}else if(H(v)){return v.append(g)}else{z("UNKNOWN")}}return v}else if(H(v)){if(!K(v.cdr)){z("|| next 2");n(p,new Y(v.cdr,m))}return v.car}else if(K(m)){return v}else{var b=e.last_pair();if(b.cdr instanceof V){z("|| next 3");n(p,d.last_pair());return v}}}else if(d instanceof Array){z("[t 2 Array "+i);if(i){n(p,d.slice(1));return Y.fromArray(d)}else{var w=d.slice(1);if(w.length){n(p,w)}return d[0]}}else{return d}}}z("[t 3 recur ",e);var D=l?e.slice(1):e.cdr;var x=T(h,t,r,n);var E=T(D,t,r,n);z({head:x,rest:E});if(l){return[x].concat(E)}return new Y(x,E)}return e}function L(t,r){var e=Object.values(t);var n=Object.getOwnPropertySymbols(t);if(n.length){e.push.apply(e,q(n.map(function(e){return t[e]})))}return e.length&&e.every(function(e){if(e===null){return!r}return H(e)||K(e)||Array.isArray(e)&&e.length})}function M(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function R(i){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},t=e.disabled;z("traverse>> ",i);var u=Array.isArray(i);if(u&&i.length===0){return i}if(H(i)||u){var r=u?i[0]:i.car;var n,a;if(u){n=i[1];a=i.slice(2)}else if(H(i.cdr)){n=i.cdr.car;a=i.cdr.cdr}z({first:r,second:n,rest_second:a});if(!t&&H(r)&&V.is(r.car,P)){return R(r.cdr,{disabled:true})}if(n&&V.is(n,P)&&!t){z(">> 1");var o=B["..."].symbols;var s=Object.values(o);if(s.length&&s.every(function(e){return e===null})){z(">>> 1 (a)");return R(a,{disabled:t})}var c=M(o);var f=r instanceof V&&V.is(a.car,P);if(H(r)||f){z(">>> 1 (b)");if(K(B["..."].lists[0])){if(!f){return R(a,{disabled:t})}z(a);return $}var l=r;if(f){z(">>> 1 (c)");l=new Y(r,new Y(n,$))}z(">> 2");var h;if(c.length){z(">> 2 (a)");var _=U({},o);h=u?[]:$;var p=function e(){z({bind:_});if(!L(_)){return 1}var n={};var t=function e(t,r){n[t]=r};var r=T(l,_,{nested:true},t);if(r!==undefined){if(f){if(u){if(Array.isArray(r)){var i;(i=h).push.apply(i,q(r))}else{z("ZONK {1}")}}else{if(K(h)){h=r}else{h=h.append(r)}}}else if(u){h.push(r)}else{h=new Y(r,h)}}_=n};while(true){if(p())break}if(!K(h)&&!f&&!u){h=h.reverse()}if(u){if(a){z({rest_second:a,expr:i});var d=R(a,{disabled:t});return h.concat(d)}return h}if(!K(i.cdr.cdr)&&!V.is(i.cdr.cdr.car,P)){var v=R(i.cdr.cdr,{disabled:t});return h.append(v)}return h}else{z(">> 3");var m=T(r,o,{nested:true});if(m){return new Y(m,$)}return $}}else if(r instanceof V){z(">> 4");if(V.is(a.car,P)){z(">> 4 (a)")}else{z(">> 4 (b)")}var y=r.__name__;var g=fe({},y,o[y]);z({bind:g});var b=o[y]===null;var w=u?[]:$;var D=function e(){if(!L(g,true)){z({bind:g});return 1}var n={};var t=function e(t,r){n[t]=r};var r=T(i,g,{nested:false},t);z({value:r});if(typeof r!=="undefined"){if(u){w.push(r)}else{w=new Y(r,w)}}g=n};while(true){if(D())break}if(!K(w)&&!u){w=w.reverse()}if(H(i.cdr)){if(H(i.cdr.cdr)||i.cdr.cdr instanceof V){var x=R(i.cdr.cdr,{disabled:t});z({node:x});if(b){return x}if(K(w)){w=x}else{w.append(x)}z({result:w,node:x})}}z("<<<< 2");return w}}var E=R(r,{disabled:t});var F;var A;if(r instanceof V){var k=I.get(r,{throwError:false});A=k instanceof J&&k.__name__==="syntax-rules"}if(A){if(i.cdr.car instanceof V){F=new Y(R(i.cdr.car,{disabled:t}),new Y(i.cdr.cdr.car,R(i.cdr.cdr.cdr,{disabled:t})))}else{F=new Y(i.cdr.car,R(i.cdr.cdr,{disabled:t}))}z("REST >>>> ",F)}else{F=R(i.cdr,{disabled:t})}z({a:true,car:au(i.car),cdr:au(i.cdr),head:au(E),rest:au(F)});return new Y(E,F)}if(i instanceof V){if(t&&V.is(i,P)){return i}var O=Object.keys(B["..."].symbols);var C=i.literal();if(O.includes(C)){var S="missing ellipsis symbol next to name `".concat(C,"'");throw new Error("syntax-rules: ".concat(S))}var j=N(i);if(typeof j!=="undefined"){return j}}return i}return R(t,{})}function xu(e){return Iu(e)||K(e)||e===null}function K(e){return e===$}function d(e){return typeof e==="function"&&typeof e.bind==="function"}function Eu(e){return typeof e==="string"}function Fu(e){return e&&_(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}function Au(e){return e instanceof Yo}function ku(e){return e instanceof Vo}function Ou(e){return e instanceof zo}function H(e){return e instanceof Y}function Cu(e){return e instanceof F}function Su(e){return d(e)||Au(e)||Ou(e)||ju(e)}function ju(e){return e instanceof J||e instanceof gu}function Bu(e){if(e instanceof Zn){return false}if(e instanceof Promise){return true}return!!e&&d(e.then)}function Iu(e){return typeof e==="undefined"}function Pu(e,t){if(Mu(e,t)||Mu(e.__proto__,t)){return d(e[t])}}function Nu(e){if(!e){return false}if(_(e)!=="object"){return false}if(e.__instance__){e.__instance__=false;return e.__instance__}return false}function Tu(e){var t=_(e);return["string","function"].includes(t)||_(e)==="symbol"||e instanceof Zn||e instanceof V||e instanceof B||e instanceof D||e instanceof RegExp}function Lu(e){return e instanceof B||e instanceof D||e instanceof h}function Mu(e,t){if(e===null){return false}return _(e)==="object"&&t in Object.getOwnPropertySymbols(e)}function Ru(e){switch(_(e)){case"string":return D(e);case"bigint":return B(e);case"number":if(Number.isNaN(e)){return _o}else{return B(e)}}return e}function qu(r,n){var e=Object.getOwnPropertyNames(r);var t=Object.getOwnPropertySymbols(r);var i={};e.concat(t).forEach(function(e){var t=n(r[e]);i[e]=t});return i}function Uu(t){var e=[D,B].some(function(e){return t instanceof e});if(e){return t.valueOf()}if(t instanceof Array){return t.map(Uu)}if(t instanceof Zn){delete t.then}if(Ki(t)){return qu(t,Uu)}return t}function zu(e,t){if(H(e)){e.mark_cycles();return oo(e)}if(d(e)){if(t){return $u(e,t)}}return Ru(e)}function Vu(e){if(Ju(e)){return e[Qu]}return e}function $u(e,t){if(e[Symbol["for"]("__bound__")]){return e}var r=e.bind(t);var n=Object.getOwnPropertyNames(e);var i=Tr(n),u;try{for(i.s();!(u=i.n()).done;){var a=u.value;if(aa(a)){try{r[a]=e[a]}catch(e){}}}}catch(e){i.e(e)}finally{i.f()}oa(r,"__fn__",e);oa(r,"__context__",t);oa(r,"__bound__",true);if(ha(e)){oa(r,"__native__",true)}if(Ki(t)&&ca(e)){oa(r,"__method__",true)}r.valueOf=function(){return e};return r}function Yu(e){return Ju(e)&&e[Symbol["for"]("__context__")]===Object}function Ju(e){return!!(d(e)&&e[Qu])}function Ku(e){if(d(e)){var t=e[Wu];if(t&&(t===Cs||t.constructor&&t.constructor.__class__)){return true}}return false}function Hu(e){return e instanceof Ua||e instanceof za}function Gu(e){if(d(e)){if(Hu(e[Wu])){return true}}return false}var Wu=Symbol["for"]("__context__");var Qu=Symbol["for"]("__fn__");var Zu=Symbol["for"]("__data__");var Xu=Symbol["for"]("__ref__");var ea=Symbol["for"]("__cycles__");var ta=Symbol["for"]("__class__");var ra=Symbol["for"]("__method__");var na=Symbol["for"]("__prototype__");var ia=Symbol["for"]("__lambda__");var ua=["name","length","caller","callee","arguments","prototype"];function aa(e){return!ua.includes(e)}function oa(e,t,r){Object.defineProperty(e,Symbol["for"](t),{get:function e(){return r},set:function e(){},configurable:false,enumerable:false})}function sa(t,r){try{Object.defineProperty(t,"length",{get:function e(){return r}});return t}catch(e){var n=new Array(r).fill(0).map(function(e,t){return"a"+t}).join(",");var i=new Function("f","return function(".concat(n,") {\n return f.apply(this, arguments);\n };"));return i(t)}}function ca(e){return e&&e[ia]}function fa(e){return e&&e[ra]}function la(e){return ca(e)&&!e[na]&&!fa(e)&&!Gu(e)}function ha(e){var t=Symbol["for"]("__native__");return d(e)&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[t]===true||!e.name.match(/^bound /)&&!e[t])}function _a(e){var b;switch(e){case Symbol["for"]("letrec"):b="letrec";break;case Symbol["for"]("let"):b="let";break;case Symbol["for"]("let*"):b="let*";break;default:throw new Error("Invalid let_macro value")}return J.defmacro(b,function(t,e){var f=e.dynamic_env;var l=e.error,r=e.macro_expand,h=e.use_dynamic;var _;if(t.car instanceof V){if(!(H(t.cdr.car)||K(t.cdr.car))){throw new Error("let require list of pairs")}var n;if(K(t.cdr.car)){_=$;n=$}else{n=t.cdr.car.map(function(e){return e.car});_=t.cdr.car.map(function(e){return e.cdr.car})}return Y.fromArray([V("letrec"),[[t.car,Y(V("lambda"),Y(n,t.cdr.cdr))]],Y(t.car,_)])}else if(r){return}var p=this;_=G.get("list->array")(t.car);var d=p.inherit(b);var v,m;if(b==="let*"){m=d}else if(b==="let"){v=[]}var y=0;function g(){var e=new Y(new V("begin"),t.cdr);return k(e,{env:d,dynamic_env:d,use_dynamic:h,error:l})}return function t(){var r=_[y++];f=b==="let*"?d:p;if(!r){if(v&&v.length){var e=v.map(function(e){return e.value});var n=e.filter(Bu);if(n.length){return Xn(e).then(function(e){for(var t=0,r=e.length;t1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=t.error;var i=this;var u=this;var a=[];var o=e;while(H(o)){a.push(k(o.car,{env:i,dynamic_env:u,use_dynamic:r,error:n}));o=o.cdr}var s=a.filter(Bu).length;if(s){return Xn(a).then(c.bind(this))}else{return c.call(this,a)}})}function da(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n2?n-2:0),u=2;u1&&arguments[1]!==undefined?arguments[1]:null;return function(){for(var e=arguments.length,t=new Array(e),r=0;r1?e-1:0),r=1;r=a){return u.apply(this,n)}else{return i}}return i.apply(this,arguments)}}function Ea(n,i){A("limit",i,"function",2);return function(){for(var e=arguments.length,t=new Array(e),r=0;r1){e=e.toLowerCase();if(h.__names__[e]){t=e;e=h.__names__[e]}else{throw new Error("Internal: Unknown named character")}}else{t=h.__rev_names__[e]}Object.defineProperty(this,"__char__",{value:e,enumerable:true});if(t){Object.defineProperty(this,"__name__",{value:t,enumerable:true})}}h.__names__=sn;h.__rev_names__={};Object.keys(h.__names__).forEach(function(e){var t=h.__names__[e];h.__rev_names__[t]=e});h.prototype.toUpperCase=function(){return h(this.__char__.toUpperCase())};h.prototype.toLowerCase=function(){return h(this.__char__.toLowerCase())};h.prototype.toString=function(){return"#\\"+(this.__name__||this.__char__)};h.prototype.valueOf=h.prototype.serialize=function(){return this.__char__};function D(e){if(typeof this!=="undefined"&&!(this instanceof D)||typeof this==="undefined"){return new D(e)}if(e instanceof Array){this.__string__=e.map(function(e,t){A("LString",e,"character",t+1);return e.toString()}).join("")}else{this.__string__=e.valueOf()}}{var Fa=["length","constructor"];var Aa=Object.getOwnPropertyNames(String.prototype).filter(function(e){return!Fa.includes(e)});var ka=function e(n){return function(){for(var e=arguments.length,t=new Array(e),r=0;r0){r.push(this.__string__.substring(0,e))}r.push(t);if(e1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof B){return e}if(typeof this!=="undefined"&&!(this instanceof B)||typeof this==="undefined"){return new B(e,t)}if(typeof e==="undefined"){throw new Error("Invalid LNumber constructor call")}var r=B.getType(e);if(B.types[r]){return B.types[r](e,t)}var n=e instanceof Array&&D.isString(e[0])&&B.isNumber(e[1]);if(e instanceof B){return B(e.value)}if(!B.isNumber(e)&&!n){throw new Error("You can't create LNumber from ".concat(Io(e)))}if(e===null){e=0}var i;if(n){var u=e,a=b(u,2),o=a[0],s=a[1];if(o instanceof D){o=o.valueOf()}if(s instanceof B){s=s.valueOf()}var c=o.match(/^([+-])/);var f=false;if(c){o=o.replace(/^[+-]/,"");if(c[1]==="-"){f=true}}}if(Number.isNaN(e)){return g(e)}else if(n&&Number.isNaN(parseInt(o,s))){return _o}else if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(n){var l;switch(s){case 8:l="0o";break;case 16:l="0x";break;case 2:l="0b";break;case 10:l="";break}if(typeof l==="undefined"){var h=BigInt(s);i=q(o).map(function(e,t){return BigInt(parseInt(e,s))*Na(h,BigInt(t))}).reduce(function(e,t){return e+t})}else{i=BigInt(l+o)}}else{i=BigInt(e)}if(f){i*=BigInt(-1)}}else{i=e}return E(i,true)}else if(typeof Hr!=="undefined"&&!(e instanceof Hr)){if(e instanceof Array){return E(L(Hr,q(e)))}return E(new Hr(e))}else if(n){this.constant(parseInt(o,s),"integer")}else{this.constant(e,"integer")}}B.prototype.constant=function(e,t){Object.defineProperty(this,"__value__",{value:e,enumerable:true});Object.defineProperty(this,"__type__",{value:t,enumerable:true})};B.types={float:function e(t){return new g(t)},complex:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!B.isComplex(t)){t={im:0,re:t}}return new y(t,r)},rational:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!B.isRational(t)){t={num:t,denom:1}}return new x(t,r)}};B.prototype.serialize=function(){return this.__value__};B.prototype.isNaN=function(){return Number.isNaN(this.__value__)};B.prototype.gcd=function(e){var t=this.abs();e=e.abs();if(e.cmp(t)===1){var r=t;t=e;e=r}while(true){t=t.rem(e);if(t.cmp(0)===0){return e}e=e.rem(t);if(e.cmp(0)===0){return t}}};B.isFloat=function e(t){return t instanceof g||Number(t)===t&&t%1!==0};B.isNumber=function(e){return e instanceof B||B.isNative(e)||B.isBN(e)};B.isComplex=function(e){if(!e){return false}var t=e instanceof y||(B.isNumber(e.im)||B.isRational(e.im)||Number.isNaN(e.im))&&(B.isNumber(e.re)||B.isRational(e.re)||Number.isNaN(e.re));return t};B.isRational=function(e){if(!e){return false}return e instanceof x||B.isNumber(e.num)&&B.isNumber(e.denom)};B.isInteger=function(e){if(!(B.isNative(e)||e instanceof B)){return false}if(B.isFloat(e)){return false}if(B.isRational(e)){return false}if(B.isComplex(e)){return false}return true};B.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};B.isBigInteger=function(e){return e instanceof E||typeof e==="bigint"||B.isBN(e)};B.isBN=function(e){return typeof Hr!=="undefined"&&e instanceof Hr};B.getArgsType=function(e,t){if(e instanceof g||t instanceof g){return g}if(e instanceof E||t instanceof E){return E}return B};B.prototype.toString=function(e){if(Number.isNaN(this.__value__)){return"+nan.0"}if(e>=2&&e<36){return this.__value__.toString(e)}return this.__value__.toString()};B.prototype.asType=function(e){var t=B.getType(this);return B.types[t]?B.types[t](e):B(e)};B.prototype.isBigNumber=function(){return typeof this.__value__==="bigint"||typeof Hr!=="undefined"&&!(this.value instanceof Hr)};["floor","ceil","round"].forEach(function(e){B.prototype[e]=function(){if(this["float"]||B.isFloat(this.__value__)){return B(Math[e](this.__value__))}else{return B(Math[e](this.valueOf()))}}});B.prototype.valueOf=function(){if(B.isNative(this.__value__)){return Number(this.__value__)}else if(B.isBN(this.__value__)){return this.__value__.toNumber()}};var ja=function(){var e=function e(t,r){return[t,r]};return{bigint:{bigint:e,float:function e(t,r){return[g(t.valueOf()),r]},rational:function e(t,r){return[{num:t,denom:1},r]},complex:function e(t,r){return[{im:0,re:t},r]}},integer:{integer:e,float:function e(t,r){return[g(t.valueOf()),r]},rational:function e(t,r){return[{num:t,denom:1},r]},complex:function e(t,r){return[{im:0,re:t},r]}},float:{bigint:function e(t,r){return[t,r&&g(r.valueOf())]},integer:function e(t,r){return[t,r&&g(r.valueOf())]},float:e,rational:function e(t,r){return[t,r&&g(r.valueOf())]},complex:function e(t,r){return[{re:t,im:g(0)},r]}},complex:{bigint:t("bigint"),integer:t("integer"),float:t("float"),rational:t("rational"),complex:function e(t,r){var n=B.coerce(t.__re__,r.__re__),i=b(n,2),u=i[0],a=i[1];var o=B.coerce(t.__im__,r.__im__),s=b(o,2),c=s[0],f=s[1];return[{im:c,re:u},{im:f,re:a}]}},rational:{bigint:function e(t,r){return[t,r&&{num:r,denom:1}]},integer:function e(t,r){return[t,r&&{num:r,denom:1}]},float:function e(t,r){return[g(t.valueOf()),r]},rational:e,complex:function e(t,r){return[{im:Ba(t.__type__,r.__im__.__type__,0)[0],re:Ba(t.__type__,r.__re__.__type__,t)[0]},{im:Ba(t.__type__,r.__im__.__type__,r.__im__)[0],re:Ba(t.__type__,r.__re__.__type__,r.__re__)[0]}]}}};function t(r){return function(e,t){return[{im:Ba(r,e.__im__.__type__,0,e.__im__)[1],re:Ba(r,e.__re__.__type__,0,e.__re__)[1]},{im:Ba(r,e.__im__.__type__,0,0)[1],re:Ba(r,t.__type__,0,t)[1]}]}}}();function Ba(e,t,r,n){return ja[e][t](r,n)}B.coerce=function(e,t){var r=B.getType(e);var n=B.getType(t);if(!ja[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!ja[r][n]){throw new Error("LNumber::coerce unknown rhs type ".concat(n))}var i=ja[r][n](e,t);return i.map(function(e){return B(e,true)})};B.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof B)){throw new Error("LNumber: you can't coerce ".concat(Io(e)))}if(typeof e==="number"){e=B(e)}return B.coerce(this,e)};B.getType=function(e){if(e instanceof B){return e.__type__}if(B.isFloat(e)){return"float"}if(B.isComplex(e)){return"complex"}if(B.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof Hr!=="undefined"&&!(e instanceof Hr)){return"bigint"}};B.prototype.isFloat=function(){return!!(B.isFloat(this.__value__)||this["float"])};var Ia={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var Pa={};Object.keys(Ia).forEach(function(t){Pa[Ia[t]]=t;B.prototype[t]=function(e){return this.op(Ia[t],e)}});B._ops={"*":function e(t,r){return t*r},"+":function e(t,r){return t+r},"-":function e(t,r){if(typeof r==="undefined"){return-t}return t-r},"/":function e(t,r){return t/r},"%":function e(t,r){return t%r},"|":function e(t,r){return t|r},"&":function e(t,r){return t&r},"~":function e(t){return~t},">>":function e(t,r){return t>>r},"<<":function e(t,r){return t<1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof y)||typeof this==="undefined"){return new y(e,t)}if(e instanceof y){return y({im:e.__im__,re:e.__re__})}if(B.isNumber(e)&&t){if(!t){return Number(e)}}else if(!B.isComplex(e)){var r="Invalid constructor call for LComplex expect &(:im :re ) object but got ".concat(au(e));throw new Error(r)}var n=e.im instanceof B?e.im:B(e.im);var i=e.re instanceof B?e.re:B(e.re);this.constant(n,i)}y.prototype=Object.create(B.prototype);y.prototype.constructor=y;y.prototype.constant=function(e,t){Object.defineProperty(this,"__im__",{value:e,enumerable:true});Object.defineProperty(this,"__re__",{value:t,enumerable:true});Object.defineProperty(this,"__type__",{value:"complex",enumerable:true})};y.prototype.serialize=function(){return{re:this.__re__,im:this.__im__}};y.prototype.toRational=function(e){if(B.isFloat(this.__im__)&&B.isFloat(this.__re__)){var t=g(this.__im__).toRational(e);var r=g(this.__re__).toRational(e);return y({im:t,re:r})}return this};y.prototype.pow=function(e){e.cmp(0);if(e===0){return B(1)}var t=B(Math.atan2(this.__im__.valueOf(),this.__re__.valueOf()));var r=B(this.modulus());if(B.isComplex(e)&&e.__im__.cmp(0)!==0){var n=e.mul(Math.log(r.valueOf())).add(y.i.mul(t).mul(e));var i=g(Math.E).pow(n.__re__.valueOf());return y({re:i.mul(Math.cos(n.__im__.valueOf())),im:i.mul(Math.sin(n.__im__.valueOf()))})}var u=e.__re__.cmp(0)>0;e=e.__re__.valueOf();if(B.isInteger(e)&&u){var a=this;while(--e){a=a.mul(this)}return a}var o=r.pow(e);var s=t.mul(e);return y({re:o.mul(Math.cos(s)),im:o.mul(Math.sin(s))})};y.prototype.add=function(e){return this.complex_op("add",e,function(e,t,r,n){return{re:e.add(t),im:r.add(n)}})};y.prototype.factor=function(){if(this.__im__ instanceof g||this.__im__ instanceof g){var e=this.__re__,t=this.__im__;var r,n;if(e instanceof g){r=e.toRational().mul(e.toRational())}else{r=e.mul(e)}if(t instanceof g){n=t.toRational().mul(t.toRational())}else{n=t.mul(t)}return r.add(n)}else{return this.__re__.mul(this.__re__).add(this.__im__.mul(this.__im__))}};y.prototype.modulus=function(){return this.factor().sqrt()};y.prototype.conjugate=function(){return y({re:this.__re__,im:this.__im__.sub()})};y.prototype.sqrt=function(){var e=this.modulus();var t,r;if(e.cmp(0)===0){t=r=e}else if(this.__re__.cmp(0)===1){t=g(.5).mul(e.add(this.__re__)).sqrt();r=this.__im__.div(t).div(2)}else{r=g(.5).mul(e.sub(this.__re__)).sqrt();if(this.__im__.cmp(0)===-1){r=r.sub()}t=this.__im__.div(r).div(2)}return y({im:r,re:t})};y.prototype.div=function(e){if(B.isNumber(e)&&!B.isComplex(e)){if(!(e instanceof B)){e=B(e)}var t=this.__re__.div(e);var r=this.__im__.div(e);return y({re:t,im:r})}else if(!B.isComplex(e)){throw new Error("[LComplex::div] Invalid value")}if(this.cmp(e)===0){var n=this.coerce(e),i=b(n,2),u=i[0],a=i[1];var o=u.__im__.div(a.__im__);return o.coerce(a.__re__)[0]}var s=this.coerce(e),c=b(s,2),f=c[0],l=c[1];var h=l.factor();var _=l.conjugate();var p=f.mul(_);if(!B.isComplex(p)){return p.div(h)}var d=p.__re__.op("/",h);var v=p.__im__.op("/",h);return y({re:d,im:v})};y.prototype.sub=function(e){return this.complex_op("sub",e,function(e,t,r,n){return{re:e.sub(t),im:r.sub(n)}})};y.prototype.mul=function(e){return this.complex_op("mul",e,function(e,t,r,n){var i={re:e.mul(t).sub(r.mul(n)),im:e.mul(n).add(t.mul(r))};return i})};y.prototype.complex_op=function(e,t,i){var u=this;var r=function e(t,r){var n=i(u.__re__,t,u.__im__,r);if("im"in n&&"re"in n){if(n.im.cmp(0)===0){return n.re}return y(n,true)}return n};if(typeof t==="undefined"){return r()}if(B.isNumber(t)&&!B.isComplex(t)){if(!(t instanceof B)){t=B(t)}var n=t.asType(0);t={__im__:n,__re__:t}}else if(!B.isComplex(t)){throw new Error("[LComplex::".concat(e,"] Invalid value"))}var a=t.__re__ instanceof B?t.__re__:this.__re__.asType(t.__re__);var o=t.__im__ instanceof B?t.__im__:this.__im__.asType(t.__im__);return r(a,o)};y._op={"+":"add","-":"sub","*":"mul","/":"div"};y.prototype._op=function(e,t){var r=y._op[e];return this[r](t)};y.prototype.cmp=function(e){var t=this.coerce(e),r=b(t,2),n=r[0],i=r[1];var u=n.__re__.coerce(i.__re__),a=b(u,2),o=a[0],s=a[1];var c=o.cmp(s);if(c!==0){return c}else{var f=n.__im__.coerce(i.__im__),l=b(f,2),h=l[0],_=l[1];return h.cmp(_)}};y.prototype.valueOf=function(){return[this.__re__,this.__im__].map(function(e){return e.valueOf()})};y.prototype.toString=function(){var e;if(this.__re__.cmp(0)!==0){e=[au(this.__re__)]}else{e=[]}var t=this.__im__.valueOf();var r=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY].includes(t);var n=au(this.__im__);if(!r&&!Number.isNaN(t)){var i=this.__im__.cmp(0);if(i<0||i===0&&this.__im__._minus){e.push("-")}else{e.push("+")}n=n.replace(/^-/,"")}e.push(n);e.push("i");return e.join("")};function g(e){if(typeof this!=="undefined"&&!(this instanceof g)||typeof this==="undefined"){return new g(e)}if(!B.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof B){return g(e.valueOf())}if(typeof e==="number"){if(Object.is(e,-0)){Object.defineProperty(this,"_minus",{value:true})}this.constant(e,"float")}}g.prototype=Object.create(B.prototype);g.prototype.constructor=g;g.prototype.toString=function(e){if(this.__value__===Number.NEGATIVE_INFINITY){return"-inf.0"}if(this.__value__===Number.POSITIVE_INFINITY){return"+inf.0"}if(Number.isNaN(this.__value__)){return"+nan.0"}e&&(e=e.valueOf());var t=this.__value__.toString(e);if(!t.match(/e[+-]?[0-9]+$/i)){var r=t.replace(/^-/,"");var n=this.__value__<0?"-":"";if(t.match(/^-?0\.0{3}/)){var i=r.match(/^[.0]+/g)[0].length-1;var u=r.replace(/^[.0]+/,"").replace(/^([0-9a-f])/i,"$1.");return"".concat(n).concat(u,"e-").concat(i.toString(e))}if(t.match(/^-?[0-9a-f]{7,}\.?/i)){var a=r.match(/^[0-9a-f]+/gi)[0].length-1;var o=r.replace(/\./,"").replace(/^([0-9a-f])/i,"$1.").replace(/0+$/,"").replace(/\.$/,".0");return"".concat(n).concat(o,"e+").concat(a.toString(e))}if(!B.isFloat(this.__value__)){var s=t+".0";return this._minus?"-"+s:s}}return t.replace(/^([0-9]+)e/,"$1.0e")};g.prototype._op=function(e,t){if(t instanceof B){t=t.__value__}var r=B._ops[e];if(e==="/"&&this.__value__===0&&t===0){return NaN}return g(r(this.__value__,t))};g.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){return La(this.__value__.valueOf())}return Ma(e.valueOf())(this.__value__.valueOf())};g.prototype.sqrt=function(){var e=this.valueOf();if(this.cmp(0)<0){var t=g(Math.sqrt(-e));return y({re:0,im:t})}return g(Math.sqrt(e))};g.prototype.abs=function(){var e=this.valueOf();if(e<0){e=-e}return g(e)};var La=Ma(1e-10);function Ma(n){return function(e){var t=function e(n,t,r){var i=function e(t,r){return r0){i=qa(n,r)}else if(n.cmp(r)<=0){i=r}else if(r.cmp(0)>0){i=qa(r,n)}else if(t.cmp(0)<0){i=B(qa(n.sub(),r.sub())).sub()}else{i=B(0)}if(B.isFloat(t)||B.isFloat(e)){return g(i)}return i}function qa(e,t){var r=B(e).floor();var n=B(t).floor();if(e.cmp(r)<1){return r}else if(r.cmp(n)===0){var i=B(1).div(t.sub(n));var u=B(1).div(e.sub(r));return r.add(B(1).div(qa(i,u)))}else{return r.add(B(1))}}function x(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof x)||typeof this==="undefined"){return new x(e,t)}if(!B.isRational(e)){throw new Error("Invalid constructor call for LRational")}var r,n;if(e instanceof x){r=B(e.__num__);n=B(e.__denom__)}else{r=B(e.num);n=B(e.denom)}if(!t&&n.cmp(0)!==0){var i=r.op("%",n).cmp(0)===0;if(i){return B(r.div(n))}}this.constant(r,n)}x.prototype=Object.create(B.prototype);x.prototype.constructor=x;x.prototype.constant=function(e,t){Object.defineProperty(this,"__num__",{value:e,enumerable:true});Object.defineProperty(this,"__denom__",{value:t,enumerable:true});Object.defineProperty(this,"__type__",{value:"rational",enumerable:true})};x.prototype.serialize=function(){return{num:this.__num__,denom:this.__denom__}};x.prototype.pow=function(e){if(B.isRational(e)){return Na(this.valueOf(),e.valueOf())}var t=e.cmp(0);if(t===0){return B(1)}if(t===-1){e=e.sub();var r=this.__denom__.pow(e);var n=this.__num__.pow(e);return x({num:r,denom:n})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};x.prototype.sqrt=function(){var e=this.__num__.sqrt();var t=this.__denom__.sqrt();if(e instanceof g||t instanceof g){return e.div(t)}return x({num:e,denom:t})};x.prototype.abs=function(){var e=this.__num__;var t=this.__denom__;if(e.cmp(0)===-1){e=e.sub()}if(t.cmp(0)!==1){t=t.sub()}return x({num:e,denom:t})};x.prototype.cmp=function(e){return B(this.valueOf(),true).cmp(e)};x.prototype.toString=function(){var e=this.__num__.gcd(this.__denom__);var t,r;if(e.cmp(1)!==0){t=this.__num__.div(e);if(t instanceof x){t=B(t.valueOf(true))}r=this.__denom__.div(e);if(r instanceof x){r=B(r.valueOf(true))}}else{t=this.__num__;r=this.__denom__}var n=this.cmp(0)<0;if(n){if(t.abs().cmp(r.abs())===0){return t.toString()}}else if(t.cmp(r)===0){return t.toString()}return t.toString()+"/"+r.toString()};x.prototype.valueOf=function(e){if(this.__denom__.cmp(0)===0){if(this.__num__.cmp(0)<0){return Number.NEGATIVE_INFINITY}return Number.POSITIVE_INFINITY}if(e){return B._ops["/"](this.__num__.value,this.__denom__.value)}return g(this.__num__.valueOf()).div(this.__denom__.valueOf())};x.prototype.mul=function(e){if(!(e instanceof B)){e=B(e)}if(B.isRational(e)){var t=this.__num__.mul(e.__num__);var r=this.__denom__.mul(e.__denom__);return x({num:t,denom:r})}var n=B.coerce(this,e),i=b(n,2),u=i[0],a=i[1];return u.mul(a)};x.prototype.div=function(e){if(!(e instanceof B)){e=B(e)}if(B.isRational(e)){var t=this.__num__.mul(e.__denom__);var r=this.__denom__.mul(e.__num__);return x({num:t,denom:r})}var n=B.coerce(this,e),i=b(n,2),u=i[0],a=i[1];var o=u.div(a);return o};x.prototype._op=function(e,t){return this[Pa[e]](t)};x.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof B)){e=B(e)}if(B.isRational(e)){var t=e.__num__.sub();var r=e.__denom__;return this.add(x({num:t,denom:r}))}if(!(e instanceof B)){e=B(e).sub()}else{e=e.sub()}var n=B.coerce(this,e),i=b(n,2),u=i[0],a=i[1];return u.add(a)};x.prototype.add=function(e){if(!(e instanceof B)){e=B(e)}if(B.isRational(e)){var t=this.__denom__;var r=e.__denom__;var n=this.__num__;var i=e.__num__;var u,a;if(t!==r){a=r.mul(n).add(i.mul(t));u=t.mul(r)}else{a=n.add(i);u=t}return x({num:a,denom:u})}if(B.isFloat(e)){return g(this.valueOf()).add(e)}var o=B.coerce(this,e),s=b(o,2),c=s[0],f=s[1];return c.add(f)};function E(e,t){if(typeof this!=="undefined"&&!(this instanceof E)||typeof this==="undefined"){return new E(e,t)}if(e instanceof E){return E(e.__value__,e._native)}if(!B.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.constant(e,"bigint");Object.defineProperty(this,"_native",{value:t})}E.prototype=Object.create(B.prototype);E.prototype.constructor=E;E.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};E.prototype.serialize=function(){return this.__value__.toString()};E.prototype._op=function(e,t){if(typeof t==="undefined"){if(B.isBN(this.__value__)){e=E.bn_op[e];return E(this.__value__.clone()[e](),false)}return E(B._ops[e](this.__value__),true)}if(B.isBN(this.__value__)&&B.isBN(t.__value__)){e=E.bn_op[e];return E(this.__value__.clone()[e](t),false)}var r=B._ops[e](this.__value__,t.__value__);if(e==="/"){var n=this.op("%",t).cmp(0)===0;if(n){return B(r)}return x({num:this,denom:t})}return E(r,true)};E.prototype.sqrt=function(){var e;var t=this.cmp(0)<0;if(B.isNative(this.__value__)){e=B(Math.sqrt(t?-this.valueOf():this.valueOf()))}else if(B.isBN(this.__value__)){e=t?this.__value__.neg().sqrt():this.__value__.sqrt()}if(t){return y({re:0,im:e})}return e};B.NaN=B(NaN);y.i=y({im:1,re:0});function Ua(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof Ua)||typeof this==="undefined"){return new Ua(e)}A("InputPort",e,"function");c(this,"__type__",Xa);var i;Object.defineProperty(this,"__parser__",{enumerable:true,get:function e(){return i},set:function e(t){A("InputPort::__parser__",t,"parser");i=t}});this._read=e;this._with_parser=this._with_init_parser.bind(this,ie(O.mark(function e(){var r;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(n.char_ready()){t.next=5;break}t.next=3;return n._read();case 3:r=t.sent;i=new fi(r,{env:n});case 5:return t.abrupt("return",n.__parser__);case 6:case"end":return t.stop()}},e)})));this.char_ready=function(){return!!this.__parser__&&this.__parser__.__lexer__.peek()!==eo};this._make_defaults()}Ua.prototype._make_defaults=function(){this.read=this._with_parser(function(e){return e.read_object()});this.read_line=this._with_parser(function(e){return e.__lexer__.read_line()});this.read_char=this._with_parser(function(e){return e.__lexer__.read_char()});this.read_string=this._with_parser(function(e,t){if(!B.isInteger(t)){var r=B.getType(t);ko("read-string",r,"integer")}return e.__lexer__.read_string(t.valueOf())});this.peek_char=this._with_parser(function(e){return e.__lexer__.peek_char()})};Ua.prototype._with_init_parser=function(o,s){var c=this;return ie(O.mark(function e(){var r,n,i,u,a=arguments;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:t.next=2;return o.call(c);case 2:r=t.sent;for(n=a.length,i=new Array(n),u=0;u"};function za(e){if(typeof this!=="undefined"&&!(this instanceof za)||typeof this==="undefined"){return new za(e)}A("OutputPort",e,"function");c(this,"__type__",Xa);this.write=e}za.prototype.is_open=function(){return this._closed!==true};za.prototype.close=function(){Object.defineProperty(this,"_closed",{get:function e(){return true},set:function e(){},configurable:false,enumerable:false});this.write=function(){throw new Error("output-port: port is closed")}};za.prototype.flush=function(){};za.prototype.toString=function(){return"#"};var Va=function(e){W(r,e);function r(e){var t;ue(this,r);t=Pr(this,r,[function(){var e;return(e=t)._write.apply(e,arguments)}]);A("BufferedOutputPort",e,"function");c(M(t),"_fn",e,{hidden:true});c(M(t),"_buffer",[],{hidden:true});return t}ce(r,[{key:"flush",value:function e(){if(this._buffer.length){this._fn(this._buffer.join(""));this._buffer.length=0}}},{key:"_write",value:function e(){var t=this;for(var r=arguments.length,n=new Array(r),i=0;i"};$a.prototype.valueOf=function(){return this.__buffer__.map(function(e){return e.valueOf()}).join("")};function Ya(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof Ya)||typeof this==="undefined"){return new Ya(e,t)}A("OutputFilePort",e,"string");c(this,"__filename__",e);c(this,"_fd",t.valueOf(),{hidden:true});c(this,"__type__",Xa);this.write=function(e){if(!D.isString(e)){e=au(e)}else{e=e.valueOf()}r.fs().write(r._fd,e,function(e){if(e){throw e}})}}Ya.prototype=Object.create(za.prototype);Ya.prototype.constructor=Ya;Ya.prototype.fs=function(){if(!this._fs){this._fs=this.internal("fs")}return this._fs};Ya.prototype.internal=function(e){return vo.get("**internal-env**").get(e)};Ya.prototype.close=function(){var n=this;return new Promise(function(t,r){n.fs().close(n._fd,function(e){if(e){r(e)}else{c(n,"_fd",null,{hidden:true});za.prototype.close.call(n);t()}})})};Ya.prototype.toString=function(){return"#")};function Ja(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof Ja)||typeof this==="undefined"){return new Ja(e)}A("InputStringPort",e,"string");t=t||G;e=e.valueOf();this._with_parser=this._with_init_parser.bind(this,function(){if(!r.__parser__){r.__parser__=new fi(e,{env:t})}return r.__parser__});c(this,"__type__",Xa);this._make_defaults()}Ja.prototype.char_ready=function(){return true};Ja.prototype=Object.create(Ua.prototype);Ja.prototype.constructor=Ja;Ja.prototype.toString=function(){return"#"};function Ka(e){if(typeof this!=="undefined"&&!(this instanceof Ka)||typeof this==="undefined"){return new Ka(e)}A("InputByteVectorPort",e,"uint8array");c(this,"__vector__",e);c(this,"__type__",Za);var r=0;Object.defineProperty(this,"__index__",{enumerable:true,get:function e(){return r},set:function e(t){A("InputByteVectorPort::__index__",t,"number");if(t instanceof B){t=t.valueOf()}if(typeof t==="bigint"){t=Number(t)}if(Math.floor(t)!==t){throw new Error("InputByteVectorPort::__index__ value is "+"not integer")}r=t}})}Ka.prototype=Object.create(Ua.prototype);Ka.prototype.constructor=Ka;Ka.prototype.toString=function(){return"#"};Ka.prototype.close=function(){var t=this;c(this,"__vector__",$);var r=function e(){throw new Error("Input-binary-port: port is closed")};["read_u8","close","peek_u8","read_u8_vector"].forEach(function(e){t[e]=r});this.u8_ready=this.char_ready=function(){return false}};Ka.prototype.u8_ready=function(){return true};Ka.prototype.peek_u8=function(){if(this.__index__>=this.__vector__.length){return eo}return this.__vector__[this.__index__]};Ka.prototype.skip=function(){if(this.__index__<=this.__vector__.length){++this.__index__}};Ka.prototype.read_u8=function(){var e=this.peek_u8();this.skip();return e};Ka.prototype.read_u8_vector=function(e){if(typeof e==="undefined"){e=this.__vector__.length}else if(e>this.__index__+this.__vector__.length){e=this.__index__+this.__vector__.length}if(this.peek_u8()===eo){return eo}return this.__vector__.slice(this.__index__,e)};function Ha(){if(typeof this!=="undefined"&&!(this instanceof Ha)||typeof this==="undefined"){return new Ha}c(this,"__type__",Za);c(this,"_buffer",[],{hidden:true});this.write=function(e){A("write",e,["number","uint8array"]);if(B.isNumber(e)){this._buffer.push(e.valueOf())}else{var t;(t=this._buffer).push.apply(t,q(Array.from(e)))}};Object.defineProperty(this,"__buffer__",{enumerable:true,get:function e(){return Uint8Array.from(this._buffer)}})}Ha.prototype=Object.create(za.prototype);Ha.prototype.constructor=Ha;Ha.prototype.close=function(){za.prototype.close.call(this);c(this,"_buffer",null,{hidden:true})};Ha.prototype._close_guard=function(){if(this._closed){throw new Error("output-port: binary port is closed")}};Ha.prototype.write_u8=function(e){A("OutputByteVectorPort::write_u8",e,"number");this.write(e)};Ha.prototype.write_u8_vector=function(e){A("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};Ha.prototype.toString=function(){return"#"};Ha.prototype.valueOf=function(){return this.__buffer__};function Ga(e,t){if(typeof this!=="undefined"&&!(this instanceof Ga)||typeof this==="undefined"){return new Ga(e,t)}Ja.call(this,e);A("InputFilePort",t,"string");c(this,"__filename__",t)}Ga.prototype=Object.create(Ja.prototype);Ga.prototype.constructor=Ga;Ga.prototype.toString=function(){return"#")};function Wa(e,t){if(typeof this!=="undefined"&&!(this instanceof Wa)||typeof this==="undefined"){return new Wa(e,t)}Ka.call(this,e);A("InputBinaryFilePort",t,"string");c(this,"__filename__",t)}Wa.prototype=Object.create(Ka.prototype);Wa.prototype.constructor=Wa;Wa.prototype.toString=function(){return"#")};function Qa(e,t){var i=this;if(typeof this!=="undefined"&&!(this instanceof Qa)||typeof this==="undefined"){return new Qa(e,t)}A("OutputBinaryFilePort",e,"string");c(this,"__filename__",e);c(this,"_fd",t.valueOf(),{hidden:true});c(this,"__type__",Za);var u;this.write=function(e){A("write",e,["number","uint8array"]);var n;if(!u){u=i.internal("fs")}if(B.isNumber(e)){n=new Uint8Array([e.valueOf()])}else{n=new Uint8Array(Array.from(e))}return new Promise(function(t,r){u.write(i._fd,n,function(e){if(e){r(e)}else{t()}})})}}Qa.prototype=Object.create(Ya.prototype);Qa.prototype.constructor=Qa;Qa.prototype.write_u8=function(e){A("OutputByteVectorPort::write_u8",e,"number");this.write(e)};Qa.prototype.write_u8_vector=function(e){A("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};var Za=Symbol["for"]("binary");var Xa=Symbol["for"]("text");var eo=new to;function to(){}to.prototype.toString=function(){return"#"};function ro(e){var t=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=r.stderr,i=r.stdin,u=r.stdout,a=r.command_line,o=a===void 0?null:a,s=he(r,Or);if(typeof this!=="undefined"&&!(this instanceof ro)||typeof this==="undefined"){return new ro(e,U({stdin:i,stdout:u,stderr:n,command_line:o},s))}if(typeof e==="undefined"){e="anonymous"}this.__env__=vo.inherit(e,s);this.__env__.set("parent.frame",l("parent.frame",function(){return t.__env__},G.__env__["parent.frame"].__doc__));var c="**interaction-environment-defaults**";this.set(c,tu(s).concat(c));var f=ho.inherit("internal-".concat(e));if(Hu(i)){f.set("stdin",i)}if(Hu(n)){f.set("stderr",n)}if(Hu(u)){f.set("stdout",u)}f.set("command-line",o);mo(this.__env__,f)}ro.prototype.exec=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=t.use_dynamic,n=r===void 0?false:r,i=t.dynamic_env,u=t.env;A("Interpreter::exec",e,["string","array"],1);A("Interpreter::exec",n,"boolean",2);if(!u){u=this.__env__}if(!i){i=u}G.set("**interaction-environment**",this.__env__);return Ko(e,{env:u,dynamic_env:i,use_dynamic:n})};ro.prototype.get=function(e){var t=this.__env__.get(e);if(d(t)){var r=new Vo({env:this.__env__});return t.bind(r)}return t};ro.prototype.set=function(e,t){return this.__env__.set(e,t)};ro.prototype.constant=function(e,t){return this.__env__.constant(e,t)};function no(e,t){this.name="LipsError";this.message=e;this.args=t;this.stack=(new Error).stack}no.prototype=new Error;no.prototype.constructor=no;var io=function(e){W(t,e);function t(){ue(this,t);return Pr(this,t,arguments)}return ce(t)}(r(Error));function F(e,t,r){if(arguments.length===1){if(_(arguments[0])==="object"){e=arguments[0];t=null}else if(typeof arguments[0]==="string"){e={};t=null;r=arguments[0]}}this.__docs__=new Map;this.__env__=e;this.__parent__=t;this.__name__=r||"anonymous"}F.prototype.list=function(){return tu(this.__env__)};F.prototype.fs=function(){return this.get("**fs**")};F.prototype.unset=function(e){if(e instanceof V){e=e.valueOf()}if(e instanceof D){e=e.valueOf()}delete this.__env__[e]};F.prototype.inherit=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(_(e)==="object"){t=e}if(!e||_(e)==="object"){e="child of "+(this.__name__||"unknown")}return new F(t||{},this,e)};F.prototype.doc=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(e instanceof V){e=e.__name__}if(e instanceof D){e=e.valueOf()}if(t){if(!r){t=gi(t)}this.__docs__.set(e,t);return this}if(this.__docs__.has(e)){return this.__docs__.get(e)}if(this.__parent__){return this.__parent__.doc(e)}};F.prototype.new_frame=function(e,t){var n=this.inherit("__frame__");n.set("parent.frame",l("parent.frame",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;e=e.valueOf();var t=n.__parent__;if(!Cu(t)){return $}if(e<=0){return t}var r=t.get("parent.frame");return r(e-1)},G.__env__["parent.frame"].__doc__));t.callee=e;n.set("arguments",t);return n};F.prototype._lookup=function(e){if(e instanceof V){e=e.__name__}if(e instanceof D){e=e.valueOf()}if(this.__env__.hasOwnProperty(e)){return uo(this.__env__[e])}if(this.__parent__){return this.__parent__._lookup(e)}};F.prototype.toString=function(){return"#"};F.prototype.clone=function(){var t=this;var r={};Object.keys(this.__env__).forEach(function(e){r[e]=t.__env__[e]});return new F(r,this.__parent__,this.__name__)};F.prototype.merge=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"merge";A("Environment::merge",e,"environment");return this.inherit(t,e.__env__)};function uo(e){if(typeof this!=="undefined"&&!(this instanceof uo)||typeof this==="undefined"){return new uo(e)}this.value=e}uo.isUndefined=function(e){return e instanceof uo&&typeof e.value==="undefined"};uo.prototype.valueOf=function(){return this.value};function ao(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof ao)||typeof this==="undefined"){return new ao(e)}this.__values__=e}ao.prototype.toString=function(){return this.__values__.map(function(e){return au(e)}).join("\n")};ao.prototype.valueOf=function(){return this.__values__};F.prototype.get=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};A("Environment::get",e,["symbol","string"]);var r=t.throwError,n=r===void 0?true:r;var i=e;if(i instanceof V||i instanceof D){i=i.valueOf()}var u=this._lookup(i);if(u instanceof uo){if(uo.isUndefined(u)){return undefined}return zu(u.valueOf())}var a;if(e instanceof V&&e[V.object]){a=e[V.object]}else if(typeof i==="string"){a=i.split(".").filter(Boolean)}if(a&&a.length>0){var o=a,s=re(o),c=s[0],f=s.slice(1);u=this._lookup(c);if(f.length){try{if(u instanceof uo){u=u.valueOf()}else{u=co(zr,c);if(d(u)){u=Vu(u)}}if(typeof u!=="undefined"){return co.apply(void 0,[u].concat(q(f)))}}catch(e){throw e}}else if(u instanceof uo){return zu(u.valueOf())}u=co(zr,i)}if(typeof u!=="undefined"){return u}if(n){throw new Error("Unbound variable `"+i.toString()+"'")}};F.prototype.set=function(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;A("Environment::set",e,["string","symbol"]);if(B.isNumber(t)){t=B(t)}if(e instanceof V){e=e.__name__}if(e instanceof D){e=e.valueOf()}this.__env__[e]=t;if(r){this.doc(e,r,true)}return this};F.prototype.constant=function(t,e){var r=this;if(this.__env__.hasOwnProperty(t)){throw new Error("Environment::constant: ".concat(t," already exists"))}if(arguments.length===1&&Ki(arguments[0])){var n=arguments[0];Object.keys(n).forEach(function(e){r.constant(t,n[e])})}else{Object.defineProperty(this.__env__,t,{value:e,enumerable:true})}return this};F.prototype.has=function(e){return this.__env__.hasOwnProperty(e)};F.prototype.ref=function(e){var t=this;while(true){if(!t){break}if(t.has(e)){return t}t=t.__parent__}};F.prototype.parents=function(){var e=this;var t=[];while(e){t.unshift(e);e=e.__parent__}return t};function oo(e){if(Bu(e)){return e.then(oo)}if(H(e)||e instanceof V){e[Zu]=true}return e}var so=hi(Jn('(lambda ()\n "[native code]"\n (throw "Invalid Invocation"))'))[0];var co=l("get",function e(t){var r;for(var n=arguments.length,i=new Array(n>1?n-1:0),u=1;u0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=fo(this,"stdin")}jo("peek-char",e,"input-port");return e.peek_char()},"(peek-char port)\n\n This function reads and returns a character from the string\n port, or, if there is no more data in the string port, it\n returns an EOF."),"read-line":l("read-line",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=fo(this,"stdin")}jo("read-line",e,"input-port");return e.read_line()},"(read-line port)\n\n This function reads and returns the next line from the input\n port."),"read-char":l("read-char",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=fo(this,"stdin")}jo("read-char",e,"input-port");return e.read_char()},"(read-char port)\n\n This function reads and returns the next character from the\n input port."),read:l("read",function(){var e=ie(function(){var i=this;var u=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;return O.mark(function e(){var r,n;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:r=i.env;if(u===null){n=fo(r,"stdin")}else{n=u}jo("read",n,"input-port");return t.abrupt("return",n.read.call(r));case 4:case"end":return t.stop()}},e)})()});function t(){return e.apply(this,arguments)}return t}(),"(read [port])\n\n This function, if called with a port, it will parse the next\n item from the port. If called without an input, it will read\n a string from standard input (using the browser's prompt or\n a user defined input method) and parse it. This function can be\n used together with `eval` to evaluate code from port."),pprint:l("pprint",function e(t){if(H(t)){t=new Cs.Formatter(t.toString(true))["break"]().format();G.get("display").call(G,t)}else{G.get("write").call(G,t)}G.get("newline").call(G)},"(pprint expression)\n\n This function will pretty print its input to stdout. If it is called\n with a non-list, it will just call the print function on its\n input."),print:l("print",function e(){var t=G.get("display");var r=G.get("newline");var n=this.use_dynamic;var i=G;var u=G;for(var a=arguments.length,o=new Array(a),s=0;s1?r-1:0),i=1;in.length){throw new Error("Not enough arguments")}var o=0;var s=G.get("repr");t=t.replace(u,function(e){var t=e[1];if(t==="~"){return"~"}else if(t==="%"){return"\n"}else{var r=n[o++];if(t==="a"){return s(r)}else{return s(r,true)}}});a=t.match(/~([\S])/);if(a){throw new Error("format: Unrecognized escape sequence ".concat(a[1]))}return t},"(format string n1 n2 ...)\n\n This function accepts a string template and replaces any\n escape sequences in its inputs:\n\n * ~a value as if printed with `display`\n * ~s value as if printed with `write`\n * ~% newline character\n * ~~ literal tilde '~'\n\n If there are missing inputs or other escape characters it\n will error."),display:l("display",function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(r===null){r=fo(this,"stdout")}else{A("display",r,"output-port")}var n=t;if(!(r instanceof Qa)){n=G.get("repr")(t)}r.write.call(G,n)},"(display string [port])\n\n This function outputs the string to the standard output or\n the port if given. No newline."),"display-error":l("display-error",function e(){var t=fo(this,"stderr");var r=G.get("repr");for(var n=arguments.length,i=new Array(n),u=0;u1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=he(t,Cr);var i=this;var a=this;var o;var s=U(U({},n),{},{env:this,dynamic_env:i,use_dynamic:r});var c=k(e.cdr.car,s);c=Po(c);function f(t,r,n){if(Bu(t)){return t.then(function(e){return f(t,e,n)})}if(Bu(r)){return r.then(function(e){return f(t,e,n)})}if(Bu(n)){return n.then(function(e){return f(t,r,e)})}a.get("set-obj!").call(a,t,r,n);return n}if(H(e.car)&&V.is(e.car.car,".")){var l=e.car.cdr.car;var h=e.car.cdr.cdr.car;var _=k(l,s);var p=k(h,s);return f(_,p,c)}if(!(e.car instanceof V)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var d=e.car.valueOf();o=this.ref(e.car.__name__);return w(c,function(e){if(!o){var t=d.split(".");if(t.length>1){var r=t.pop();var n=t.join(".");var i=u.get(n,{throwError:false});if(i){f(i,r,e);return}}throw new Error("Unbound variable `"+d+"'")}o.set(d,e)})}),"(set! name value)\n\n Macro that can be used to set the value of the variable or slot (mutate it).\n set! searches the scope chain until it finds first non empty slot and sets it."),"unset!":l(new J("set!",function(e){if(!(e.car instanceof V)){throw new Error("unset! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var t=e.car;var r=this.ref(t);if(r){delete r.__env__[t.__name__]}}),"(unset! name)\n\n Function to delete the specified name from environment.\n Trying to access the name afterwards will error."),"set-car!":l("set-car!",function(e,t){A("set-car!",e,"pair");e.car=t},"(set-car! obj value)\n\n Function that sets the car (first item) of the list/pair to specified value.\n The old value is lost."),"set-cdr!":l("set-cdr!",function(e,t){A("set-cdr!",e,"pair");e.cdr=t},"(set-cdr! obj value)\n\n Function that sets the cdr (tail) of the list/pair to specified value.\n It will destroy the list. The old tail is lost."),"empty?":l("empty?",function(e){return typeof e==="undefined"||K(e)},"(empty? object)\n\n Function that returns #t if value is nil (an empty list) or undefined."),gensym:l("gensym",Qn,"(gensym)\n\n Generates a unique symbol that is not bound anywhere,\n to use with macros as meta name."),load:l("load",function e(o,t){A("load",o,"string");var s=this;if(s.__name__==="__frame__"){s=s.__parent__}if(!(t instanceof F)){if(s===G){t=s}else{t=this.get("**interaction-environment**")}}var c="**module-path**";var f=G.get(c,{throwError:false});o=o.valueOf();if(!o.match(/.[^.]+$/)){o+=".scm"}var r=o.match(/\.xcb$/);function l(e){if(r){e=ws(e)}else{if(Io(e)==="buffer"){e=e.toString()}e=e.replace(/^#!.*/,"");if(e.match(/^\{/)){e=ps(e)}}return Ko(e,{env:t})}function n(e){return zr.fetch(e).then(function(e){return r?e.arrayBuffer():e.text()}).then(function(e){if(r){e=new Uint8Array(e)}return e})}if(xo()){return new Promise(function(){var r=ie(O.mark(function e(r,n){var i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:i=Kr("path");if(!f){t.next=6;break}f=f.valueOf();o=i.join(f,o);t.next=12;break;case 6:u=s.get("command-line",{throwError:false});if(!u){t.next=11;break}t.next=10;return u();case 10:a=t.sent;case 11:if(a&&!K(a)){process.cwd();o=i.join(i.dirname(a.car.valueOf()),o)}case 12:G.set(c,i.dirname(o));Kr("fs").readFile(o,function(e,t){if(e){n(e);G.set(c,f)}else{try{l(t).then(function(){r();G.set(c,f)})["catch"](n)}catch(e){n(e)}}});case 14:case"end":return t.stop()}},e)}));return function(e,t){return r.apply(this,arguments)}}())}if(f){f=f.valueOf();o=f+"/"+o.replace(/^\.?\/?/,"")}return n(o).then(function(e){G.set(c,o.replace(/\/[^/]*$/,""));return l(e)}).then(function(){})["finally"](function(){G.set(c,f)})},"(load filename)\n (load filename environment)\n\n Fetches the file (from disk or network) and evaluates its content as LIPS code.\n If the second argument is provided and it's an environment the evaluation\n will happen in that environment."),while:l(new J("while",function(e,t){var r=e.car;var n=U(U({},t),{},{env:this});var i=new Y(new V("begin"),e.cdr);return function t(){return w(k(r,n),function(e){if(e){return w(k(i,n),t)}})}()}),"(while cond body)\n\n Creates a loop, it executes cond and body until cond expression is false."),do:l(new J("do",function(){var r=ie(function(h,e){var _=this;var p=e.use_dynamic,d=e.error;return O.mark(function e(){var o,r,s,c,n,f,l,i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:o=_;r=o;s=o.inherit("do");c=h.car;n=h.cdr.car;f=h.cdr.cdr;if(!K(f)){f=new Y(V("begin"),f)}l={env:o,dynamic_env:r,use_dynamic:p,error:d};i=c;case 9:if(K(i)){t.next=20;break}u=i.car;t.t0=s;t.t1=u.car;t.next=15;return k(u.cdr.car,l);case 15:t.t2=t.sent;t.t0.set.call(t.t0,t.t1,t.t2);i=i.cdr;t.next=9;break;case 20:l={env:s,dynamic_env:r,error:d};a=O.mark(function e(){var r,n,i,u,a;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(K(f)){t.next=3;break}t.next=3;return Cs.evaluate(f,l);case 3:r=c;n={};case 5:if(K(r)){t.next=15;break}i=r.car;if(K(i.cdr.cdr)){t.next=12;break}t.next=10;return k(i.cdr.cdr.car,l);case 10:u=t.sent;n[i.car.valueOf()]=u;case 12:r=r.cdr;t.next=5;break;case 15:a=Object.getOwnPropertySymbols(n);l.env=s=o.inherit("do");Object.keys(n).concat(a).forEach(function(e){s.set(e,n[e])});case 18:case"end":return t.stop()}},e)});case 22:t.next=24;return k(n.car,l);case 24:t.t3=t.sent;if(!(t.t3===false)){t.next=29;break}return t.delegateYield(a(),"t4",27);case 27:t.next=22;break;case 29:if(K(n.cdr)){t.next=33;break}t.next=32;return k(n.cdr.car,l);case 32:return t.abrupt("return",t.sent);case 33:case"end":return t.stop()}},e)})()});return function(e,t){return r.apply(this,arguments)}}()),"(do (( )) (test return) . body)\n\n Iteration macro that evaluates the expression body in scope of the variables.\n On each loop it changes the variables according to the expression and runs\n test to check if the loop should continue. If test is a single value, the macro\n will return undefined. If the test is a pair of expressions the macro will\n evaluate and return the second expression after the loop exits."),if:l(new J("if",function(r,e){var t=e.error,n=e.use_dynamic;var i=this;var u=this;var a={env:u,dynamic_env:i,use_dynamic:n,error:t};var o=function e(t){if(t===false){return k(r.cdr.cdr.car,a)}else{return k(r.cdr.car,a)}};if(K(r)){throw new Error("too few expressions for `if`")}var s=k(r.car,a);return w(s,o)}),"(if cond true-expr false-expr)\n\n Macro that evaluates cond expression and if the value is true, it\n evaluates and returns true-expression, if not it evaluates and returns\n false-expression."),"let-env":new J("let-env",function(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=e.dynamic_env,n=e.use_dynamic,i=e.error;A("let-env",t,"pair");var u=k(t.car,{env:this,dynamic_env:r,error:i,use_dynamic:n});return w(u,function(e){A("let-env",e,"environment");return k(Y(V("begin"),t.cdr),{env:e,dynamic_env:r,error:i})})},"(let-env env . body)\n\n Special macro that evaluates body in context of given environment\n object."),letrec:l(_a(Symbol["for"]("letrec")),"(letrec ((a value-a) (b value-b) ...) . body)\n\n Macro that creates a new environment, then evaluates and assigns values to\n names and then evaluates the body in context of that environment.\n Values are evaluated sequentially and the next value can access the\n previous values/names."),"letrec*":l(_a(Symbol["for"]("letrec")),"(letrec* ((a value-a) (b value-b) ...) . body)\n\n Same as letrec but the order of execution of the binding is guaranteed,\n so you can use recursive code as well as referencing the previous binding.\n\n In LIPS both letrec and letrec* behave the same."),"let*":l(_a(Symbol["for"]("let*")),"(let* ((a value-a) (b value-b) ...) . body)\n\n Macro similar to `let`, but the subsequent bindings after the first\n are evaluated in the environment including the previous let variables,\n so you can define one variable, and use it in the next's definition."),let:l(_a(Symbol["for"]("let")),"(let ((a value-a) (b value-b) ...) . body)\n\n Macro that creates a new environment, then evaluates and assigns values to names,\n and then evaluates the body in context of that environment. Values are evaluated\n sequentially but you can't access previous values/names when the next are\n evaluated. You can only get them in the body of the let expression. (If you want\n to define multiple variables and use them in each other's definitions, use\n `let*`.)"),"begin*":l(pa("begin*",function(e){return e.pop()}),"(begin* . body)\n\n This macro is a parallel version of begin. It evaluates each expression\n in the body and if it's a promise it will await it in parallel and return\n the value of the last expression (i.e. it uses Promise.all())."),shuffle:l("shuffle",function(e){A("shuffle",e,["pair","nil","array"]);var t=G.get("random");if(K(e)){return $}if(Array.isArray(e)){return Vi(e.slice(),t)}var r=G.get("list->array")(e);r=Vi(r,t);return G.get("array->list")(r)},"(shuffle obj)\n\n Order items in vector or list in random order."),begin:l(new J("begin",function(e,t){var n=U(U({},t),{},{env:this});var i=G.get("list->array")(e);var u;return function t(){if(i.length){var e=i.shift();var r=k(e,n);return w(r,function(e){u=e;return t()})}else{return u}}()}),"(begin . args)\n\n Macro that runs a list of expressions in order and returns the value\n of the last one. It can be used in places where you can only have a\n single expression, like (if)."),ignore:new J("ignore",function(e,t){var r=U(U({},t),{},{env:this,dynamic_env:this});k(new Y(new V("begin"),e),r)},"(ignore . body)\n\n Macro that will evaluate the expression and swallow any promises that may\n be created. It will discard any value that may be returned by the last body\n expression. The code should have side effects and/or when it's promise\n it should resolve to undefined."),"call/cc":l(J.defmacro("call/cc",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=U({env:this},t);return w(k(e.car,r),function(e){if(d(e)){return e(new Yo(null))}})}),"(call/cc proc)\n\n Call-with-current-continuation.\n\n NOT SUPPORTED BY LIPS RIGHT NOW"),parameterize:l(new J("parameterize",function(t,e){var i=e.dynamic_env;var u=i.inherit("parameterize").new_frame(null,{});var a=U(U({},e),{},{env:this});var o=t.car;if(!H(o)){var r=Io(o);throw new Error("Invalid syntax for parameterize expecting pair got ".concat(r))}function s(){var e=new Y(new V("begin"),t.cdr);return k(e,U(U({},a),{},{dynamic_env:u}))}return function r(){var e=o.car;var n=e.car.valueOf();return w(k(e.cdr.car,a),function(e){var t=i.get(n,{throwError:false});if(!Ou(t)){throw new Error("Unknown parameter ".concat(n))}u.set(n,t.inherit(e));if(!xu(o.cdr)){o=o.cdr;return r()}else{return s()}})}()}),"(parameterize ((name value) ...)\n\n Macro that change the dynamic variable created by make-parameter."),"make-parameter":l(new J("make-parameter",function(e,t){t.dynamic_env;var r=k(e.car,t);var n;if(H(e.cdr.car)){n=k(e.cdr.car,t)}return new zo(r,n)}),"(make-parameter init converter)\n\n Function creates new dynamic variable that can be custimized with parameterize\n macro. The value should be assigned to a variable e.g.:\n\n (define radix (make-parameter 10))\n\n The result value is a procedure that return the value of dynamic variable."),"define-syntax-parameter":l(new J("define-syntax-parameter",function(e,t){var r=e.car;var n=this;if(!(r instanceof V)){throw new Error("define-syntax-parameter: invalid syntax expecting symbol got ".concat(Io(r)))}var i=k(e.cdr.car,U({env:n},t));A("define-syntax-parameter",i,"syntax",2);i.__name__=r.valueOf();if(i.__name__ instanceof D){i.__name__=i.__name__.valueOf()}var u;if(H(e.cdr.cdr)&&D.isString(e.cdr.cdr.car)){u=e.cdr.cdr.car.valueOf()}n.set(e.car,new gu(i),u,true)}),"(define-syntax-parameter name syntax [__doc__])\n\n Binds to the transformer obtained by evaluating .\n The transformer provides the default expansion for the syntax parameter,\n and in the absence of syntax-parameterize, is functionally equivalent to\n define-syntax."),"syntax-parameterize":l(new J("syntax-parameterize",function(e,t){var r=G.get("list->array")(e.car);var n=this.inherit("syntax-parameterize");while(r.length){var i=r.shift();if(!(H(i)||i.car instanceof V)){var u="invalid syntax for syntax-parameterize: ".concat(Ji(e,true));throw new Error("syntax-parameterize: ".concat(u))}var a=k(i.cdr.car,U(U({},t),{},{env:this}));var o=i.car;A("syntax-parameterize",a,["syntax"]);A("syntax-parameterize",o,"symbol");a.__name__=o.valueOf();if(a.__name__ instanceof D){a.__name__=a.__name__.valueOf()}var s=new gu(a);if(o.is_gensym()){var c=o.literal();var f=this.get(c,{throwError:false});if(f instanceof gu){n.set(c,s)}}n.set(o,s)}var l=new Y(new V("begin"),e.cdr);return k(l,U(U({},t),{},{env:n}))}),"(syntax-parameterize (bindings) body)\n\n Macro work similar to let-syntax but the the bindnds will be exposed to the user.\n With syntax-parameterize you can define anaphoric macros."),define:l(J.defmacro("define",function(r,e){var n=this;if(H(r.car)&&r.car.car instanceof V){var t=new Y(new V("define"),new Y(r.car.car,new Y(new Y(new V("lambda"),new Y(r.car.cdr,r.cdr)))));return t}else if(e.macro_expand){return}e.dynamic_env=this;e.env=n;var i=r.cdr.car;var u;if(H(i)){i=k(i,e);u=true}else if(i instanceof V){i=n.get(i)}A("define",r.car,"symbol");return w(i,function(e){if(n.__name__===yu.__merge_env__){n=n.__parent__}if(u&&(d(e)&&ca(e)||e instanceof yu||Ou(e))){e.__name__=r.car.valueOf();if(e.__name__ instanceof D){e.__name__=e.__name__.valueOf()}}var t;if(H(r.cdr.cdr)&&D.isString(r.cdr.cdr.car)){t=r.cdr.cdr.car.valueOf()}n.set(r.car,e,t,true)})}),'(define name expression)\n (define name expression "doc string")\n (define (function-name . args) . body)\n\n Macro for defining values. It can be used to define variables,\n or functions. If the first argument is list it will create a function\n with name being first element of the list. This form expands to\n `(define function-name (lambda args body))`'),"set-obj!":l("set-obj!",function(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;var i=_(e);if(xu(e)||i!=="object"&&i!=="function"){var u=ko("set-obj!",Io(e),["object","function"]);throw new Error(u)}A("set-obj!",t,["string","symbol","number"]);e=Vu(e);t=t.valueOf();if(arguments.length===2){delete e[t]}else if(Fu(e)&&d(r)){e[t]=Vu(r);e[t][na]=true}else if(d(r)||Lu(r)||K(r)){e[t]=r}else{e[t]=r&&!Fu(r)?r.valueOf():r}if(Hi){var a=e[t];Object.defineProperty(e,t,U(U({},n),{},{value:a}))}},"(set-obj! obj key value)\n (set-obj! obj key value props)\n\n Function set a property of a JavaScript object. props should be a vector of pairs,\n passed to Object.defineProperty."),"null-environment":l("null-environment",function(){return G.inherit("null")},"(null-environment)\n\n Returns a clean environment with only the standard library."),values:l("values",function e(){for(var t=arguments.length,r=new Array(t),n=0;n1&&arguments[1]!==undefined?arguments[1]:{},m=e.use_dynamic,y=e.error;var g=this;var b;if(H(v.cdr)&&D.isString(v.cdr.car)&&!K(v.cdr.cdr)){b=v.cdr.car.valueOf()}function w(){var e=ku(this)?this:{dynamic_env:g},r=e.dynamic_env;var n=g.inherit("lambda");r=r.inherit("lambda");if(this&&!ku(this)){if(this&&!this.__instance__){Object.defineProperty(this,"__instance__",{enumerable:false,get:function e(){return true},set:function e(){},configurable:false})}n.set("this",this)}for(var t=arguments.length,i=new Array(t),u=0;u> SYNTAX");z(e);z(y);var n=w.inherit("syntax");var i=n;var u=this;if(u.__name__===yu.__merge_env__){var a=Object.getOwnPropertySymbols(u.__env__);a.forEach(function(e){u.__parent__.set(e,u.__env__[e])});u=u.__parent__}var o={env:n,dynamic_env:i,use_dynamic:g,error:b};var s,c,f;if(y.car instanceof V){s=y.car;f=D(y.cdr.car);c=y.cdr.cdr}else{s="...";f=D(y.car);c=y.cdr}try{while(!K(c)){var l=c.car.car;var h=c.car.cdr.car;z("[[[ RULE");z(l);var _=bu(l,e,f,s,{expansion:this,define:w});if(_){if(Wr()){console.log(JSON.stringify(eu(_),true,2));console.log("PATTERN: "+l.toString(true));console.log("MACRO: "+e.toString(true))}var p=[];var d=Du({bindings:_,expr:h,symbols:f,scope:n,lex_scope:u,names:p,ellipsis:s});z("OUPUT>>> ",d);if(d){h=d}var v=u.merge(n,yu.__merge_env__);if(r){return{expr:h,scope:v}}var m=k(h,U(U({},o),{},{env:v}));return wu(m,p)}c=c.cdr}}catch(e){e.message+="\nin macro:\n ".concat(y.toString(true));throw e}throw new Error("syntax-rules: no matching syntax in macro ".concat(e.toString(true)))},w);r.__code__=y;return r},"(syntax-rules () (pattern expression) ...)\n\n Base of hygienic macros, it will return a new syntax expander\n that works like Lisp macros."),quote:l(new J("quote",function(e){return oo(e.car)}),"(quote expression) or 'expression\n\n Macro that returns a single LIPS expression as data (it won't evaluate the\n argument). It will return a list if put in front of LIPS code.\n And if put in front of a symbol it will return the symbol itself, not the value\n bound to that name."),"unquote-splicing":l("unquote-splicing",function(){throw new Error("You can't call `unquote-splicing` outside of quasiquote")},"(unquote-splicing code) or ,@code\n\n Special form used in the quasiquote macro. It evaluates the expression inside and\n splices the list into quasiquote's result. If it is not the last element of the\n expression, the computed value must be a pair."),unquote:l("unquote",function(){throw new Error("You can't call `unquote` outside of quasiquote")},"(unquote code) or ,code\n\n Special form used in the quasiquote macro. It evaluates the expression inside and\n substitutes the value into quasiquote's result."),quasiquote:J.defmacro("quasiquote",function(e,t){var o=t.use_dynamic,s=t.error;var c=this;var f=c;function u(e){return H(e)||Ki(e)||Array.isArray(e)}function l(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:u;if(H(e)){var n=e.car;var i=e.cdr;if(r(n)){n=t(n)}if(r(i)){i=t(i)}if(Bu(n)||Bu(i)){return Xn([n,i]).then(function(e){var t=b(e,2),r=t[0],n=t[1];return new Y(r,n)})}else{return new Y(n,i)}}return e}function a(e,t){if(H(e)){if(!K(t)){e.append(t)}}else{e=new Y(e,t)}return e}function r(e){return!!e.filter(function(e){return H(e)&&V.is(e.car,/^(unquote|unquote-splicing)$/)}).length}function h(e,n,i){return e.reduce(function(e,t){if(!H(t)){e.push(t);return e}if(V.is(t.car,"unquote-splicing")){var r;if(n+11){var t="You can't splice multiple atoms inside list";throw new Error(t)}if(!(H(i.cdr)&&K(r[0]))){return r[0]}}r=r.map(function(e){if(d.has(e)){return e.clone()}else{d.add(e);return e}});var n=v(i.cdr,0,1);if(K(n)&&K(r[0])){return undefined}return w(n,function(e){if(K(r[0])){return e}if(r.length===1){return a(r[0],e)}var t=r.reduce(function(e,t){return a(e,t)});return a(t,e)})})}(i.car.cdr)}var d=new Set;function v(e,t,r){if(H(e)){if(H(e.car)){if(V.is(e.car.car,"unquote-splicing")){return p(e,t+1,r)}if(V.is(e.car.car,"unquote")){if(t+2===r&&H(e.car.cdr)&&H(e.car.cdr.car)&&V.is(e.car.cdr.car.car,"unquote-splicing")){var n=e.car.cdr;return new Y(new Y(new V("unquote"),p(n,t+2,r)),$)}else if(H(e.car.cdr)&&!K(e.car.cdr.cdr)){if(H(e.car.cdr.car)){var i=[];return function t(r){if(K(r)){return Y.fromArray(i)}return w(k(r.car,{env:c,dynamic_env:f,use_dynamic:o,error:s}),function(e){i.push(e);return t(r.cdr)})}(e.car.cdr)}else{return e.car.cdr}}}}if(V.is(e.car,"quasiquote")){var u=v(e.cdr,t,r+1);return new Y(e.car,u)}if(V.is(e.car,"quote")){return new Y(e.car,v(e.cdr,t,r))}if(V.is(e.car,"unquote")){t++;if(tr){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(H(e.cdr)){if(!K(e.cdr.cdr)){if(H(e.cdr.car)){var a=[];return function t(r){if(K(r)){return Y.fromArray(a)}return w(k(r.car,{env:c,dynamic_env:f,use_dynamic:o,error:s}),function(e){a.push(e);return t(r.cdr)})}(e.cdr)}else{return e.cdr}}else{return k(e.cdr.car,{env:c,dynamic_env:f,error:s})}}else{return e.cdr}}return l(e,function(e){return v(e,t,r)})}else if(Ki(e)){return _(e,t,r)}else if(e instanceof Array){return h(e,t,r)}return e}function n(e){if(H(e)){delete e[Zu];if(!e.have_cycles("car")){n(e.car)}if(!e.have_cycles("cdr")){n(e.cdr)}}}if(Ki(e.car)&&!r(Object.values(e.car))){return oo(e.car)}if(Array.isArray(e.car)&&!r(e.car)){return oo(e.car)}if(H(e.car)&&!e.car.find("unquote")&&!e.car.find("unquote-splicing")&&!e.car.find("quasiquote")){return oo(e.car)}var i=v(e.car,0,1);return w(i,function(e){n(e);return oo(e)})},"(quasiquote list)\n\n Similar macro to `quote` but inside it you can use special expressions (unquote\n x) abbreviated to ,x that will evaluate x and insert its value verbatim or\n (unquote-splicing x) abbreviated to ,@x that will evaluate x and splice the value\n into the result. Best used with macros but it can be used outside."),clone:l("clone",function e(t){A("clone",t,"pair");return t.clone()},"(clone list)\n\n Function that returns a clone of the list, that does not share any pairs with the\n original, so the clone can be safely mutated without affecting the original."),append:l("append",function e(){var t;for(var r=arguments.length,n=new Array(r),i=0;iarray")(t).reverse();return G.get("array->list")(r)}else if(Array.isArray(t)){return t.reverse()}else{throw new Error(ko("reverse",Io(t),"array or pair"))}},"(reverse list)\n\n Function that reverses the list or array. If value is not a list\n or array it will error."),nth:l("nth",function e(t,r){A("nth",t,"number");A("nth",r,["array","pair"]);if(H(r)){var n=r;var i=0;while(iarray")(r).join(t)},"(join separator list)\n\n Function that returns a string by joining elements of the list using separator."),split:l("split",function e(t,r){A("split",t,["regex","string"]);A("split",r,"string");return G.get("array->list")(r.split(t))},"(split separator string)\n\n Function that creates a list by splitting string by separator which can\n be a string or regular expression."),replace:l("replace",function e(t,r,n){A("replace",t,["regex","string"]);A("replace",r,["string","function"]);A("replace",n,"string");if(d(r)){var i=[];n.replace(t,function(){i.push(r.apply(void 0,arguments))});return w(i,function(e){return n.replace(t,function(){return e.shift()})})}return n.replace(t,r)},"(replace pattern replacement string)\n\n Function that changes pattern to replacement inside string. Pattern can be a\n string or regex and replacement can be function or string. See Javascript\n String.replace()."),match:l("match",function e(t,r){A("match",t,["regex","string"]);A("match",r,"string");var n=r.match(t);return n?G.get("array->list")(n):false},"(match pattern string)\n\n Function that returns a match object from JavaScript as a list or #f if\n no match."),search:l("search",function e(t,r){A("search",t,["regex","string"]);A("search",r,"string");return r.search(t)},"(search pattern string)\n\n Function that returns the first found index of the pattern inside a string."),repr:l("repr",function e(t,r){return au(t,r)},"(repr obj)\n\n Function that returns a LIPS code representation of the object as a string."),"escape-regex":l("escape-regex",function(e){A("escape-regex",e,"string");return Rn(e.valueOf())},"(escape-regex string)\n\n Function that returns a new string where all special operators used in regex,\n are escaped with backslashes so they can be used in the RegExp constructor\n to match a literal string."),env:l("env",function e(e){e=e||this.env;var t=Object.keys(e.__env__).map(V);var r;if(t.length){r=Y.fromArray(t)}else{r=$}if(e.__parent__ instanceof F){return G.get("env").call(this,e.__parent__).append(r)}return r},"(env)\n (env obj)\n\n Function that returns a list of names (functions, macros and variables)\n that are bound in the current environment or one of its parents."),new:l("new",function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n2&&arguments[2]!==undefined?arguments[2]:ri.LITERAL;A("set-special!",e,"string",1);A("set-special!",t,"symbol",2);ri.append(e.valueOf(),t,r)},'(set-special! symbol name [type])\n\n Add a special symbol to the list of transforming operators by the parser.\n e.g.: `(add-special! "#" \'x)` will allow to use `#(1 2 3)` and it will be\n transformed into (x (1 2 3)) so you can write x macro that will process\n the list. 3rd argument is optional, and it can be one of two values:\n lips.specials.LITERAL, which is the default behavior, or\n lips.specials.SPLICE which causes the value to be unpacked into the expression.\n This can be used for e.g. to make `#(1 2 3)` into (x 1 2 3) that is needed\n by # that defines vectors.'),get:co,".":co,unbind:l(Vu,"(unbind fn)\n\n Function that removes the weak 'this' binding from a function so you\n can get properties from the actual function object."),type:l(Io,"(type object)\n\n Function that returns the type of an object as string."),debugger:l("debugger",function(){debugger},'(debugger)\n\n Function that triggers the JavaScript debugger (e.g. the browser devtools)\n using the "debugger;" statement. If a debugger is not running this\n function does nothing.'),in:l("in",function(e,t){if(e instanceof V||e instanceof D||e instanceof B){e=e.valueOf()}return e in Uu(t)},'(in key value)\n\n Function that uses the Javascript "in" operator to check if key is\n a valid property in the value.'),"instance?":l("instance?",function(e){return Nu(e)},"(instance? obj)\n\n Checks if object is an instance, created with a new operator"),instanceof:l("instanceof",function(e,t){return t instanceof Vu(e)},"(instanceof type obj)\n\n Predicate that tests if the obj is an instance of type."),"prototype?":l("prototype?",Fu,"(prototype? obj)\n\n Predicate that tests if value is a valid JavaScript prototype,\n i.e. calling (new) with it will not throw ' is not a constructor'."),"macro?":l("macro?",function(e){return e instanceof J},"(macro? expression)\n\n Predicate that tests if value is a macro."),"continuation?":l("continuation?",Au,"(continuation? expression)\n\n Predicate that tests if value is a callable continuation."),"function?":l("function?",d,"(function? expression)\n\n Predicate that tests if value is a callable function."),"real?":l("real?",function(e){if(Io(e)!=="number"){return false}if(e instanceof B){return e.isFloat()}return B.isFloat(e)},"(real? number)\n\n Predicate that tests if value is a real number (not complex)."),"number?":l("number?",function(e){return Number.isNaN(e)||B.isNumber(e)},"(number? expression)\n\n Predicate that tests if value is a number or NaN value."),"string?":l("string?",function(e){return D.isString(e)},"(string? expression)\n\n Predicate that tests if value is a string."),"pair?":l("pair?",H,"(pair? expression)\n\n Predicate that tests if value is a pair or list structure."),"regex?":l("regex?",function(e){return e instanceof RegExp},"(regex? expression)\n\n Predicate that tests if value is a regular expression."),"null?":l("null?",function(e){return xu(e)},"(null? expression)\n\n Predicate that tests if value is null-ish (i.e. undefined, nil, or\n Javascript null)."),"boolean?":l("boolean?",function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Predicate that tests if value is a boolean (#t or #f)."),"symbol?":l("symbol?",function(e){return e instanceof V},"(symbol? expression)\n\n Predicate that tests if value is a LIPS symbol."),"array?":l("array?",function(e){return e instanceof Array},"(array? expression)\n\n Predicate that tests if value is an array."),"object?":l("object?",function(e){return!K(e)&&e!==null&&!(e instanceof h)&&!(e instanceof RegExp)&&!(e instanceof D)&&!H(e)&&!(e instanceof B)&&_(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Predicate that tests if value is an plain object (not another LIPS type)."),flatten:l("flatten",function e(t){A("flatten",t,"pair");return t.flatten()},"(flatten list)\n\n Returns a shallow list from tree structure (pairs)."),"array->list":l("array->list",function(e){A("array->list",e,"array");return Y.fromArray(e)},"(array->list array)\n\n Function that converts a JavaScript array to a LIPS cons list."),"tree->array":l("tree->array",Yi("tree->array",true),"(tree->array list)\n\n Function that converts a LIPS cons tree structure into a JavaScript array."),"list->array":l("list->array",Yi("list->array"),"(list->array list)\n\n Function that converts a LIPS list into a JavaScript array."),apply:l("apply",function e(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;iarray").call(this,u));return t.apply(this,Mo(t,n))},"(apply fn list)\n\n Function that calls fn with the list of arguments."),length:l("length",function e(t){if(!t||K(t)){return 0}if(H(t)){return t.length()}if("length"in t){return t.length}},'(length expression)\n\n Function that returns the length of the object. The object can be a LIPS\n list or any object that has a "length" property. Returns undefined if the\n length could not be found.'),"string->number":l("string->number",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;A("string->number",e,"string",1);A("string->number",t,"number",2);e=e.valueOf();t=t.valueOf();if(e.match(bn)||e.match(mn)){return Fn(e,t)}else if(e.match(wn)||e.match(vn)){return On(e,t)}else{var r=t===10&&!e.match(/e/i)||t===16;if(e.match(gn)&&r||e.match(yn)){return An(e,t)}if(e.match(un)){return Bn(e)}}return false},"(string->number number [radix])\n\n Function that parses a string into a number."),try:l(new J("try",function(r,e){var l=this;var h=e.use_dynamic;e.error;return new Promise(function(t,o){var s,n;if(V.is(r.cdr.car.car,"catch")){s=r.cdr.car;if(H(r.cdr.cdr)&&V.is(r.cdr.cdr.car.car,"finally")){n=r.cdr.cdr.car}}else if(V.is(r.cdr.car.car,"finally")){n=r.cdr.car}if(!(n||s)){throw new Error("try: invalid syntax")}function c(e){t(e);throw new io("[CATCH]")}var f=function e(t,r){r(t)};if(n){f=function e(t,r){f=o;i.error=function(e){throw e};w(k(new Y(new V("begin"),n.cdr),i),function(){r(t)})}}var i={env:l,use_dynamic:h,dynamic_env:l,error:function e(t){if(t instanceof io){throw t}if(s){var r=l.inherit("try");var n=s.cdr.car.car;if(!(n instanceof V)){throw new Error("try: invalid syntax: catch require variable name")}r.set(n,t);var i;var u={env:r,use_dynamic:h,dynamic_env:l,error:function e(t){i=true;o(t);throw new io("[CATCH]")}};var a=k(new Y(new V("begin"),s.cdr.cdr),u);w(a,function e(t){if(!i){f(t,c)}})}else{f(undefined,function(){o(t)})}}};var e=k(r.car,i);w(e,function(e){f(e,t)},i.error)})}),"(try expr (catch (e) code))\n (try expr (catch (e) code) (finally code))\n (try expr (finally code))\n\n Macro that executes expr and catches any exceptions thrown. If catch is provided\n it's executed when an error is thrown. If finally is provided it's always\n executed at the end."),raise:l("raise",function(e){throw e},"(raise obj)\n\n Throws the object verbatim (no wrapping an a new Error)."),throw:l("throw",function(e){throw new Error(e)},"(throw string)\n\n Throws a new exception."),find:l("find",function t(r,n){A("find",r,["regex","function"]);A("find",n,["pair","nil"]);if(xu(n)){return $}var e=yi("find",r);return w(e(n.car),function(e){if(e&&!K(e)){return n.car}return t(r,n.cdr)})},"(find fn list)\n (find regex list)\n\n Higher-order function that finds the first value for which fn return true.\n If called with a regex it will create a matcher function."),"for-each":l("for-each",function(e){var t;A("for-each",e,"function");for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i1?t-1:0),u=1;u3?n-3:0),u=3;u3?i-3:0),a=3;aarray")(r);var u=[];var a=yi("filter",t);return function t(r){function e(e){if(e&&!K(e)){u.push(n)}return t(++r)}if(r===i.length){return Y.fromArray(u)}var n=i[r];return w(a(n),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher-order function that calls `fn` for each element of the list\n and return a new list for only those elements for which fn returns\n a truthy value. If called with a regex it will create a matcher function."),compose:l(ma,"(compose . fns)\n\n Higher-order function that creates a new function that applies all functions\n from right to left and returns the last value. Reverse of pipe.\n e.g.:\n ((compose (curry + 2) (curry * 3)) 10) --\x3e (+ 2 (* 3 10)) --\x3e 32"),pipe:l(va,"(pipe . fns)\n\n Higher-order function that creates a new function that applies all functions\n from left to right and returns the last value. Reverse of compose.\n e.g.:\n ((pipe (curry + 2) (curry * 3)) 10) --\x3e (* 3 (+ 2 10)) --\x3e 36"),curry:l(xa,"(curry fn . args)\n\n Higher-order function that creates a curried version of the function.\n The result function will have partially applied arguments and it\n will keep returning one-argument functions until all arguments are provided,\n then it calls the original function with the accumulated arguments.\n\n e.g.:\n (define (add a b c d) (+ a b c d))\n (define add1 (curry add 1))\n (define add12 (add 2))\n (display (add12 3 4))"),gcd:l("gcd",function e(){for(var t=arguments.length,r=new Array(t),n=0;no?u%=o:o%=u}u=cu(s*r[a])/(u+o)}return B(u)},"(lcm n1 n2 ...)\n\n Function that returns the least common multiple of the arguments."),"odd?":l("odd?",ba(function(e){return B(e).isOdd()}),"(odd? number)\n\n Checks if number is odd."),"even?":l("even?",ba(function(e){return B(e).isEven()}),"(even? number)\n\n Checks if number is even."),"*":l("*",Da(function(e,t){return B(e).mul(t)},B(1)),"(* . numbers)\n\n Multiplies all numbers passed as arguments. If single value is passed\n it will return that value."),"+":l("+",Da(function(e,t){return B(e).add(t)},B(0)),"(+ . numbers)\n\n Sums all numbers passed as arguments. If single value is passed it will\n return that value."),"-":l("-",function(){for(var e=arguments.length,t=new Array(e),r=0;r":l(">",function(){for(var e=arguments.length,t=new Array(e),r=0;r",t,["bigint","float","rational"]);return fu(function(e,t){return B(e).cmp(t)===1},t)},"(> x1 x2 x3 ...)\n\n Function that compares its numerical arguments and checks if they are\n monotonically decreasing, i.e. x1 > x2 and x2 > x3 and so on."),"<":l("<",function(){for(var e=arguments.length,t=new Array(e),r=0;r=":l(">=",function(){for(var e=arguments.length,t=new Array(e),r=0;r=",t,["bigint","float","rational"]);return fu(function(e,t){return[0,1].includes(B(e).cmp(t))},t)},"(>= x1 x2 ...)\n\n Function that compares its numerical arguments and checks if they are\n monotonically nonincreasing, i.e. x1 >= x2 and x2 >= x3 and so on."),"eq?":l("eq?",lu,"(eq? a b)\n\n Function that compares two values if they are identical."),or:l(new J("or",function(e,t){var i=t.use_dynamic,u=t.error;var a=G.get("list->array")(e);var o=this;var s=o;if(!a.length){return false}var c;return function t(){function e(e){c=e;if(c!==false){return c}else{return t()}}if(!a.length){if(c!==false){return c}else{return false}}else{var r=a.shift();var n=k(r,{env:o,dynamic_env:s,use_dynamic:i,error:u});return w(n,e)}}()}),"(or . expressions)\n\n Macro that executes the values one by one and returns the first that is\n a truthy value. If there are no expressions that evaluate to true it\n returns false."),and:l(new J("and",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.use_dynamic,n=t.error;var i=G.get("list->array")(e);var u=this;var a=u;if(!i.length){return true}var o;var s={env:u,dynamic_env:a,use_dynamic:r,error:n};return function t(){function e(e){o=e;if(o===false){return false}else{return t()}}if(!i.length){if(o!==false){return o}else{return false}}else{var r=i.shift();return w(k(r,s),e)}}()}),"(and . expressions)\n\n Macro that evaluates each expression in sequence and if any value returns false\n it will stop and return false. If each value returns true it will return the\n last value. If it's called without arguments it will return true."),"|":l("|",function(e,t){return B(e).or(t)},"(| a b)\n\n Function that calculates the bitwise or operation."),"&":l("&",function(e,t){return B(e).and(t)},"(& a b)\n\n Function that calculates the bitwise and operation."),"~":l("~",function(e){return B(e).neg()},"(~ number)\n\n Function that calculates the bitwise inverse (flip all the bits)."),">>":l(">>",function(e,t){return B(e).shr(t)},"(>> a b)\n\n Function that right shifts the value a by value b bits."),"<<":l("<<",function(e,t){return B(e).shl(t)},"(<< a b)\n\n Function that left shifts the value a by value b bits."),not:l("not",function e(t){if(xu(t)){return true}return!t},"(not object)\n\n Function that returns the Boolean negation of its argument.")},undefined,"global");var vo=G.inherit("user-env");function mo(e,t){e.constant("**internal-env**",t);e.doc("**internal-env**","**internal-env**\n\n Constant used to hide stdin, stdout and stderr so they don't interfere\n with variables with the same name. Constants are an internal type\n of variable that can't be redefined, defining a variable with the same name\n will throw an error.");G.set("**interaction-environment**",e)}mo(vo,ho);G.doc("**interaction-environment**","**interaction-environment**\n\n Internal dynamic, global variable used to find interpreter environment.\n It's used so the read and write functions can locate **internal-env**\n that contains the references to stdin, stdout and stderr.");function yo(e){vo.get("**internal-env**").set("fs",e)}(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(t){var r=e[t]?e[t]:t;G.set(r,l(r,function(e){A(r,e,"number");if(e instanceof B){return e[t]()}},"(".concat(r," number)\n\n Function that calculates the ").concat(r," of a number.")))})})();function go(e){if(e.length===1){return e[0]}else{var t=[];var r=go(e.slice(1));for(var n=0;n3&&arguments[3]!==undefined?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(n!==null){i+=" (argument ".concat(n,")")}if(d(r)){return"Invalid type: got ".concat(t).concat(i)}if(r instanceof Array){if(r.length===1){var u=r[0].toLowerCase();r="a"+("aeiou".includes(u)?"n ":" ")+r[0]}else{r=new Intl.ListFormat("en",{style:"long",type:"disjunction"}).format(r)}}return"Expecting ".concat(r," got ").concat(t).concat(i)}function Oo(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;A(e,t,"number",n);var i=t.__type__;var u;if(H(r)){r=r.to_array()}if(r instanceof Array){r=r.map(function(e){return e.valueOf()})}if(r instanceof Array){r=r.map(function(e){return e.valueOf().toLowerCase()});if(r.includes(i)){u=true}}else{r=r.valueOf().toLowerCase()}if(!u&&i!==r){throw new Error(ko(e,i,r,n))}}function Co(r,e,n){e.forEach(function(e,t){Oo(r,e,n,t+1)})}function So(r,e,n){e.forEach(function(e,t){A(r,e,n,t+1)})}function jo(e,t,r){A(e,t,r);if(t.__type__===Za){throw new Error(ko(e,"binary-port","textual-port"))}}function A(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;e=e.valueOf();var i=Io(t).toLowerCase();if(d(r)){if(!r(t)){throw new Error(ko(e,i,r,n))}return}var u=false;if(H(r)){r=r.to_array()}if(r instanceof Array){r=r.map(function(e){return e.valueOf()})}if(r instanceof Array){r=r.map(function(e){return e.valueOf().toLowerCase()});if(r.includes(i)){u=true}}else{r=r.valueOf().toLowerCase()}if(!u&&i!==r){throw new Error(ko(e,i,r,n))}}function Bo(r){var n=new WeakMap;return function(e){var t=n.get(e);if(!t){t=r(e)}return t}}Io=Bo(Io);function Io(e){var t=$r.get(e);if(t){return t}if(_(e)==="object"){for(var r=0,n=Object.entries(Vr);r2&&arguments[2]!==undefined?arguments[2]:{},n=r.env,i=r.dynamic_env,u=r.use_dynamic;var a=n===null||n===void 0?void 0:n.new_frame(e,t);var o=i===null||i===void 0?void 0:i.new_frame(e,t);var s=new Vo({env:a,use_dynamic:u,dynamic_env:o});return Po(e.apply(s,t))}function qo(n,e){var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},i=t.env,u=t.dynamic_env,a=t.use_dynamic,r=t.error,o=r===void 0?function(){}:r;e=No(e,{env:i,dynamic_env:u,error:o,use_dynamic:a});return w(e,function(e){if(la(n)){n=Vu(n)}e=Mo(n,e);var t=e.slice();var r=Ro(n,t,{env:i,dynamic_env:u,use_dynamic:a});return w(r,function(e){if(H(e)){e.mark_cycles();return oo(e)}return Ru(e)},o)})}var Uo=new WeakMap;var zo=function(){function n(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;ue(this,n);fe(this,"__value__",void 0);fe(this,"__fn__",void 0);Br(this,Uo,{writable:true,value:void 0});this.__value__=e;if(t){if(!d(t)){throw new Error("Section argument to Parameter need to be function "+"".concat(Io(t)," given"))}this.__fn__=t}if(r){f(this,Uo,r)}}ce(n,[{key:"__name__",get:function e(){return t(this,Uo)},set:function e(t){f(this,Uo,t);if(this.__fn__){this.__fn__.__name__="fn-".concat(t)}}},{key:"invoke",value:function e(){if(d(this.__fn__)){return this.__fn__(this.__value__)}return this.__value__}},{key:"inherit",value:function e(t){return new n(t,this.__fn__,this.__name__)}}]);return n}();var Vo=function(){function t(e){ue(this,t);fe(this,"env",void 0);fe(this,"dynamic_env",void 0);fe(this,"use_dynamic",void 0);Object.assign(this,e)}ce(t,[{key:"__name__",get:function e(){return this.env.__name__}},{key:"__parent__",get:function e(){return this.env.__parent__}},{key:"get",value:function e(){var t;return(t=this.env).get.apply(t,arguments)}}]);return t}();function $o(e,t){var r=e.get(t.__name__,{throwError:false});if(Ou(r)&&r!==t){return r}var n=vo.get("**interaction-environment**");while(true){var i=e.get("parent.frame",{throwError:false});e=i(0);if(e===n){break}r=e.get(t.__name__,{throwError:false});if(Ou(r)&&r!==t){return r}}return t}var Yo=function(){function t(e){ue(this,t);fe(this,"__value__",void 0);this.__value__=e}ce(t,[{key:"invoke",value:function e(){if(this.__value__===null){throw new Error("Continuations are not implemented yet")}}}]);return t}();function k(o){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},s=e.env,c=e.dynamic_env,f=e.use_dynamic,t=e.error,l=t===void 0?Eo:t,r=he(e,jr);return function(e){try{if(!Cu(c)){c=s===true?vo:s||vo}if(f){s=c}else if(s===true){s=vo}else{s=s||G}var t={env:s,dynamic_env:c,use_dynamic:f,error:l};var r;if(xu(o)){return o}if(o instanceof V){return s.get(o)}if(!H(o)){return o}var n=o.car;var e=o.cdr;if(H(n)){r=Po(k(n,t));if(Bu(r)){return r.then(function(e){if(!Su(e)){throw new Error(Io(e)+" "+s.get("repr")(e)+" is not callable while evaluating "+o.toString())}return k(new Y(e,o.cdr),t)})}else if(!Su(r)){throw new Error(Io(r)+" "+s.get("repr")(r)+" is not callable while evaluating "+o.toString())}}if(n instanceof V){r=s.get(n)}else if(d(n)){r=n}var i;if(r instanceof yu){i=To(r,o,t)}else if(r instanceof J){i=Lo(r,e,t)}else if(d(r)){i=qo(r,e,t)}else if(r instanceof gu){i=To(r._syntax,o,t)}else if(Ou(r)){var u=$o(c,r);if(xu(o.cdr)){i=u.invoke()}else{return w(k(o.cdr.car,t),function(e){u.__value__=e})}}else if(Au(r)){i=r.invoke()}else if(H(o)){r=n&&n.toString();throw new Error("".concat(Io(n)," ").concat(r," is not a function"))}else{return o}var a=s.get(Symbol["for"]("__promise__"),{throwError:false});if(a===true&&Bu(i)){i=i.then(function(e){if(H(e)&&!r[Zu]){return k(e,t)}return e});return new Zn(i)}return i}catch(e){l&&l.call(s,e,o)}}(r)}var Jo=Go(function(e){return e});var Ko=Go(function(e,t){return t});function Ho(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.env,n=t.dynamic_env,i=t.use_dynamic;return k(e,{env:r,dynamic_env:n,use_dynamic:i,error:function e(t,r){if(t&&t.message){if(t.message.match(/^Error:/)){var n=/^(Error:)\s*([^:]+:\s*)/;t.message=t.message.replace(n,"$1 $2")}if(r){if(!(t.__code__ instanceof Array)){t.__code__=[]}t.__code__.push(r.toString(true))}}if(!(t instanceof io)){throw t}}})}function Go(d){return function(){var t=ie(function(l){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},h=e.env,_=e.dynamic_env,p=e.use_dynamic;return O.mark(function e(){var r,n,i,u,a,o,s,c,f;return O.wrap(function e(t){while(1)switch(t.prev=t.next){case 0:if(!Cu(_)){_=h===true?vo:h||vo}if(h===true){h=vo}else{h=h||vo}r=[];if(!H(l)){t.next=8;break}t.next=6;return Ho(code,{env:h,dynamic_env:_,use_dynamic:p});case 6:t.t0=t.sent;return t.abrupt("return",[t.t0]);case 8:n=Array.isArray(l)?l:hi(l);i=false;u=false;t.prev=11;o=qr(n);case 13:t.next=15;return o.next();case 15:if(!(i=!(s=t.sent).done)){t.next=31;break}c=s.value;t.next=19;return Ho(c,{env:h,dynamic_env:_,use_dynamic:p});case 19:f=t.sent;t.t1=r;t.t2=d;t.t3=c;t.next=25;return f;case 25:t.t4=t.sent;t.t5=(0,t.t2)(t.t3,t.t4);t.t1.push.call(t.t1,t.t5);case 28:i=false;t.next=13;break;case 31:t.next=37;break;case 33:t.prev=33;t.t6=t["catch"](11);u=true;a=t.t6;case 37:t.prev=37;t.prev=38;if(!(i&&o["return"]!=null)){t.next=42;break}t.next=42;return o["return"]();case 42:t.prev=42;if(!u){t.next=45;break}throw a;case 45:return t.finish(42);case 46:return t.finish(37);case 47:return t.abrupt("return",r);case 48:case"end":return t.stop()}},e,null,[[11,33,37,47],[38,,42,46]])})()});function e(e){return t.apply(this,arguments)}return e}()}function Wo(e){var t={"[":"]","(":")"};var r;if(typeof e==="string"){r=Jn(e)}else{r=e.map(function(e){return e&&e.token?e.token:e})}var n=Object.keys(t);var i=Object.values(t).concat(n);r=r.filter(function(e){return i.includes(e)});var u=new qn;var a=Tr(r),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;if(n.includes(s)){u.push(s)}else if(!u.is_empty()){var c=u.top();var f=t[c];if(s===f){u.pop()}else{throw new Error("Syntax error: missing closing ".concat(f))}}else{throw new Error("Syntax error: not matched closing ".concat(s))}}}catch(e){a.e(e)}finally{a.f()}return u.is_empty()}function Qo(e){var t="("+e.toString()+")()";var r=window.URL||window.webkitURL;var n;try{n=new Blob([t],{type:"application/javascript"})}catch(e){var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;n=new i;n.append(t);n=n.getBlob()}return new zr.Worker(r.createObjectURL(n))}function Zo(){return Cs.version.match(/^(\{\{VER\}\}|DEV)$/)}function Xo(){if(xo()){return}var e;if(document.currentScript){e=document.currentScript}else{var t=document.querySelectorAll("script");if(!t.length){return}e=t[t.length-1]}var r=e.getAttribute("src");return r}var es=Xo();function ts(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"";var t="dist/std.xcb";if(e===""){if(es){e=es.replace(/[^/]*$/,"std.xcb")}else if(Zo()){e="https://cdn.jsdelivr.net/gh/jcubic/lips@devel/".concat(t)}else{e="https://cdn.jsdelivr.net/npm/@jcubic/lips@".concat(Cs.version,"/").concat(t)}}var r=G.get("load");return r.call(vo,e,G)}function rs(e){this.url=e;var a=this.worker=Qo(function(){var a;var o;self.addEventListener("message",function(e){var r=e.data;var t=r.id;if(r.type!=="RPC"||t===null){return}function n(e){self.postMessage({id:t,type:"RPC",result:e})}function i(e){self.postMessage({id:t,type:"RPC",error:e})}if(r.method==="eval"){if(!o){i("Worker RPC: LIPS not initialized, call init first");return}o.then(function(){var e=r.params[0];var t=r.params[1];a.exec(e,{use_dynamic:t}).then(function(e){e=e.map(function(e){return e&&e.valueOf()});n(e)})["catch"](function(e){i(e)})})}else if(r.method==="init"){var u=r.params[0];if(typeof u!=="string"){i("Worker RPC: url is not a string")}else{importScripts("".concat(u,"/dist/lips.min.js"));a=new Cs.Interpreter("worker");o=ts(u);o.then(function(){n(true)})}}})});this.rpc=function(){var n=0;return function e(t,r){var u=++n;return new Promise(function(n,i){a.addEventListener("message",function e(t){var r=t.data;if(r&&r.type==="RPC"&&r.id===u){if(r.error){i(r.error)}else{n(r.result)}a.removeEventListener("message",e)}});a.postMessage({type:"RPC",method:t,id:u,params:r})})}}();this.rpc("init",[e])["catch"](function(e){console.error(e)});this.exec=function(e,t){var r=t.use_dynamic,n=r===void 0?false:r;return this.rpc("eval",[e,n])}}var ns={pair:function e(t){var r=b(t,2),n=r[0],i=r[1];return Y(n,i)},number:function e(t){if(D.isString(t)){return B([t,10])}return B(t)},regex:function e(t){var r=b(t,2),n=r[0],i=r[1];return new RegExp(n,i)},nil:function e(){return $},symbol:function e(t){if(D.isString(t)){return V(t)}else if(Array.isArray(t)){return V(Symbol["for"](t[0]))}},string:D,character:h};var is=Object.keys(ns);var us={};for(var as=0,os=Object.entries(is);as1){var n=t.reduce(function(e,t){return e+t.length},0);var i=new Uint8Array(n);var u=0;t.forEach(function(e){i.set(e,u);u+=e.length});return i}else if(t.length){return t[0]}}function ms(){var e=1;var t=new TextEncoder("utf-8");return t.encode("LIPS".concat(e.toString().padStart(3," ")))}var ys=7;function gs(e){var t=new TextDecoder("utf-8");var r=t.decode(e.slice(0,ys));var n=r.substring(0,4);if(n==="LIPS"){var i=r.match(/^(....).*([0-9]+)$/);if(i){return{type:i[1],version:Number(i[2])}}}return{type:"unknown"}}function bs(e){var t=ms();var r=ds.encode(e);return vs(t,xr(r,{magic:false}))}function ws(e){var t=gs(e),r=t.type,n=t.version;if(r==="LIPS"&&n===1){var i=Er(e.slice(ys),{magic:false});return ds.decode(i)}else{throw new Error("Invalid file format ".concat(r))}}function Ds(e){console.error(e.message||e);if(Array.isArray(e.code)){console.error(e.code.map(function(e,t){return"[".concat(t+1,"]: ").concat(e)}))}}function xs(){var a=["text/x-lips","text/x-scheme"];var o;function s(e){var t;return(t=e.getAttribute("data-bootstrap"))!==null&&t!==void 0?t:e.getAttribute("bootstrap")}function c(r){return new Promise(function(t){var e=r.getAttribute("src");if(e){return fetch(e).then(function(e){return e.text()}).then(Ko).then(t)["catch"](function(e){Ds(e);t()})}else{return Ko(r.innerHTML).then(t)["catch"](function(e){Ds(e);t()})}})}function e(){return new Promise(function(i){var u=Array.from(document.querySelectorAll("script"));return function e(){var t=u.shift();if(!t){i()}else{var r=t.getAttribute("type");if(a.includes(r)){var n=s(t);if(!o&&typeof n==="string"){return ts(n).then(function(){return c(t)}).then(e)}else{return c(t).then(e)}}else if(r&&r.match(/lips|lisp/)){console.warn("Expecting "+a.join(" or ")+" found "+r)}return e()}}()})}if(!window.document){return Promise.resolve()}else if(Es){var t=Es;var r=s(t);if(typeof r==="string"){return ts(r).then(function(){o=true;return e()})}}return e()}var Es=typeof window!=="undefined"&&window.document&&document.currentScript;if(typeof window!=="undefined"){Gr(window,xs)}var Fs=function(){var e=D("Tue, 05 Mar 2024 15:58:24 +0000").valueOf();var t=e==="{{"+"DATE}}"?new Date:new Date(e);var r=function e(t){return t.toString().padStart(2,"0")};var n=t.getFullYear();var i=[n,r(t.getMonth()+1),r(t.getDate())].join("-");var u="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter DEV (".concat(i,") \nCopyright (c) 2018-").concat(n," Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables. You can also\nuse (help name) to display help for specific function or macro, (apropos name)\nto display list of matched names in environment and (dir object) to list\nproperties of an object.\n").replace(/^.*\n/,"");return u}();c(Ei,"__class__","ahead");c(Y,"__class__","pair");c($i,"__class__","nil");c(Fi,"__class__","pattern");c(xi,"__class__","formatter");c(J,"__class__","macro");c(yu,"__class__","syntax");c(yu.Parameter,"__class__","syntax-parameter");c(F,"__class__","environment");c(Ua,"__class__","input-port");c(za,"__class__","output-port");c(Va,"__class__","output-port");c($a,"__class__","output-string-port");c(Ja,"__class__","input-string-port");c(Ga,"__class__","input-file-port");c(Ya,"__class__","output-file-port");c(no,"__class__","lips-error");[B,y,x,g,E].forEach(function(e){c(e,"__class__","number")});c(h,"__class__","character");c(V,"__class__","symbol");c(D,"__class__","string");c(Zn,"__class__","promise");c(zo,"__class__","parameter");var As="DEV";var ks="Tue, 05 Mar 2024 15:58:24 +0000";var Os=ma(vi,hi);var Cs={version:As,banner:Fs,date:ks,exec:Ko,parse:Os,tokenize:Jn,evaluate:k,compile:Jo,serialize:_s,unserialize:ps,serialize_bin:bs,unserialize_bin:ws,bootstrap:ts,Environment:F,env:vo,Worker:rs,Interpreter:ro,balanced_parenthesis:Wo,balancedParenthesis:Wo,balanced:Wo,Macro:J,Syntax:yu,Pair:Y,Values:ao,QuotedPromise:Zn,Error:no,quote:oo,InputPort:Ua,OutputPort:za,BufferedOutputPort:Va,InputFilePort:Ga,OutputFilePort:Ya,InputStringPort:Ja,OutputStringPort:$a,InputByteVectorPort:Ka,OutputByteVectorPort:Ha,InputBinaryFilePort:Wa,OutputBinaryFilePort:Qa,set_fs:yo,Formatter:xi,Parser:fi,Lexer:s,specials:ri,repr:Ji,nil:$,eof:eo,LSymbol:V,LNumber:B,LFloat:g,LComplex:y,LRational:x,LBigInteger:E,LCharacter:h,LString:D,Parameter:zo,rationalize:Ra};G.set("lips",Cs);e.BufferedOutputPort=Va;e.Environment=F;e.Error=no;e.Formatter=xi;e.InputBinaryFilePort=Wa;e.InputByteVectorPort=Ka;e.InputFilePort=Ga;e.InputPort=Ua;e.InputStringPort=Ja;e.Interpreter=ro;e.LBigInteger=E;e.LCharacter=h;e.LComplex=y;e.LFloat=g;e.LNumber=B;e.LRational=x;e.LString=D;e.LSymbol=V;e.Lexer=s;e.Macro=J;e.OutputBinaryFilePort=Qa;e.OutputByteVectorPort=Ha;e.OutputFilePort=Ya;e.OutputPort=za;e.OutputStringPort=$a;e.Pair=Y;e.Parameter=zo;e.Parser=fi;e.QuotedPromise=Zn;e.Syntax=yu;e.Values=ao;e.Worker=rs;e.balanced=Wo;e.balancedParenthesis=Wo;e.balanced_parenthesis=Wo;e.banner=Fs;e.bootstrap=ts;e.compile=Jo;e.date=ks;e.env=vo;e.eof=eo;e.evaluate=k;e.exec=Ko;e.nil=$;e.parse=Os;e.quote=oo;e.rationalize=Ra;e.repr=Ji;e.serialize=_s;e.serialize_bin=bs;e.set_fs=yo;e.specials=ri;e.tokenize=Jn;e.unserialize=ps;e.unserialize_bin=ws;e.version=As}); \ No newline at end of file diff --git a/src/lips.js b/src/lips.js index 39a9cf94..97a4a2d1 100644 --- a/src/lips.js +++ b/src/lips.js @@ -9076,6 +9076,16 @@ var global_env = new Environment({ typecheck('replace', pattern, ['regex', 'string']); typecheck('replace', replacement, ['string', 'function']); typecheck('replace', string, 'string'); + if (is_function(replacement)) { + // ref: https://stackoverflow.com/a/48032528/387194 + const replacements = []; + string.replace(pattern, function(...args) { + replacements.push(replacement(...args)); + }); + return unpromise(replacements, replacements => { + return string.replace(pattern, () => replacements.shift()); + }); + } return string.replace(pattern, replacement); }, `(replace pattern replacement string) diff --git a/templates/README.md b/templates/README.md index 006c3a32..73e12043 100644 --- a/templates/README.md +++ b/templates/README.md @@ -354,7 +354,8 @@ I would also love to see if you use the library, I may even share the links of p * [StackOverlow](https://stackoverflow.com) code was used for functions: * [fworker](https://stackoverflow.com/a/10372280/387194), * [flatten](https://stackoverflow.com/a/27282907/387194), - * [allPossibleCases](https://stackoverflow.com/a/4331218/387194). + * [allPossibleCases](https://stackoverflow.com/a/4331218/387194), + * [async replace](https://stackoverflow.com/a/48032528/387194). * Code formatter is roughly based on [scheme-style](http://community.schemewiki.org/?scheme-style) and GNU Emacs scheme mode. * Some helpers in standard library are inspired by same functions from [RamdaJS library](https://ramdajs.com/). diff --git a/tests/core.scm b/tests/core.scm index c11193c9..440c4439 100644 --- a/tests/core.scm +++ b/tests/core.scm @@ -736,6 +736,10 @@ (t.is (number->string 1.0e+27 16) "3.3b2e3c9fd0804e+16") (t.is (number->string 1000000000000000000000000000 16) "33b2e3c9fd0803ce8000000"))) +(test "core: replace async" + (lambda (t) + (t.is (replace #/foo/ (lambda () (Promise.resolve "lips")) "foo bar") "lips bar"))) + ;; TODO ;; begin* ;; set-obj! throws with null or boolean