diff --git a/README.md b/README.md index e6ef412b..52b0f5c3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.14-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) -[![travis](https://travis-ci.org/jcubic/lips.svg?branch=master&da387aecaed52cc2e496570e97336a90be03d425)](https://travis-ci.org/jcubic/lips) +[![travis](https://travis-ci.org/jcubic/lips.svg?branch=master&f87942006cf306934091c9f7d2f42ff1602208bd)](https://travis-ci.org/jcubic/lips) [![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=master&25a417d0b61dd73dde71da232355132a)](https://coveralls.io/github/jcubic/lips?branch=master) [![Join Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips) [![GitHub license](https://img.shields.io/github/license/jcubic/lips.svg)](https://github.com/jcubic/lips/blob/master/LICENSE) diff --git a/dist/lips.js b/dist/lips.js index 3b0547ad..88a42796 100644 --- a/dist/lips.js +++ b/dist/lips.js @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Fri, 04 Jun 2021 11:25:19 +0000 + * build: Fri, 04 Jun 2021 12:09:05 +0000 */ (function () { 'use strict'; @@ -10590,7 +10590,6 @@ '#t': true, '#f': false, nil: _nil, - eof: eof, 'null': null, 'NaN': nan, '+nan.0': nan, @@ -10598,6 +10597,7 @@ }; // ------------------------------------------------------------------------- var global_env = new Environment({ + eof: eof, undefined: undefined$1, // undefined as parser constant breaks most of the unit tests // --------------------------------------------------------------------- @@ -14200,7 +14200,7 @@ } var load = global_env.get('load'); - return load.call(lips.env, "".concat(url, "dist/std.scm"), global_env); + return load.call(lips.env, "".concat(url, "dist/std.min.scm"), global_env); } // ------------------------------------------------------------------------- @@ -14506,10 +14506,10 @@ var banner = function () { // Rollup tree-shaking is removing the variable if it's normal string because - // obviously 'Fri, 04 Jun 2021 11:25:19 +0000' == '{{' + 'DATE}}'; can be removed + // obviously 'Fri, 04 Jun 2021 12:09:05 +0000' == '{{' + 'DATE}}'; can be removed // but disablig Tree-shaking is adding lot of not used code so we use this // hack instead - var date = LString('Fri, 04 Jun 2021 11:25:19 +0000').valueOf(); + var date = LString('Fri, 04 Jun 2021 12:09:05 +0000').valueOf(); var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date); @@ -14554,7 +14554,7 @@ var lips = { version: '1.0.0-beta.14', banner: banner, - date: 'Fri, 04 Jun 2021 11:25:19 +0000', + date: 'Fri, 04 Jun 2021 12:09:05 +0000', exec: exec, // unwrap async generator into Promise parse: compose(uniterate_async, parse), diff --git a/dist/lips.min.js b/dist/lips.min.js index be2f58d1..dbd0dfc7 100644 --- a/dist/lips.min.js +++ b/dist/lips.min.js @@ -31,6 +31,6 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Fri, 04 Jun 2021 11:25:19 +0000 + * build: Fri, 04 Jun 2021 12:09:05 +0000 */ -(function(){"use strict";function unwrapExports(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e["default"]:e}function createCommonjsModule(e,r){return r={exports:{}},e(r,r.exports),r.exports}var readOnlyError=createCommonjsModule(function(e){function r(e){throw new TypeError('"'+e+'" is read-only')}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});var _readOnlyError=unwrapExports(readOnlyError);var setPrototypeOf=createCommonjsModule(function(t){function n(e,r){t.exports=n=Object.setPrototypeOf||function e(r,t){r.__proto__=t;return r};t.exports["default"]=t.exports,t.exports.__esModule=true;return n(e,r)}t.exports=n;t.exports["default"]=t.exports,t.exports.__esModule=true});unwrapExports(setPrototypeOf);var isNativeReflectConstruct=createCommonjsModule(function(e){function r(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true}catch(e){return false}}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});unwrapExports(isNativeReflectConstruct);var construct=createCommonjsModule(function(n){function i(e,r,t){if(isNativeReflectConstruct()){n.exports=i=Reflect.construct;n.exports["default"]=n.exports,n.exports.__esModule=true}else{n.exports=i=function e(r,t,n){var i=[null];i.push.apply(i,t);var a=Function.bind.apply(r,i);var o=new a;if(n)setPrototypeOf(o,n.prototype);return o};n.exports["default"]=n.exports,n.exports.__esModule=true}return i.apply(null,arguments)}n.exports=i;n.exports["default"]=n.exports,n.exports.__esModule=true});var _construct=unwrapExports(construct);var arrayWithHoles=createCommonjsModule(function(e){function r(e){if(Array.isArray(e))return e}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});unwrapExports(arrayWithHoles);var iterableToArray=createCommonjsModule(function(e){function r(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});unwrapExports(iterableToArray);var arrayLikeToArray=createCommonjsModule(function(e){function r(e,r){if(r==null||r>e.length)r=e.length;for(var t=0,n=new Array(r);t=0)continue;t[i]=e[i]}return t}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});unwrapExports(objectWithoutPropertiesLoose);var objectWithoutProperties=createCommonjsModule(function(e){function r(e,r){if(e==null)return{};var t=objectWithoutPropertiesLoose(e,r);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;t[n]=e[n]}}return t}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});var _objectWithoutProperties=unwrapExports(objectWithoutProperties);var iterableToArrayLimit=createCommonjsModule(function(e){function r(e,r){var t=e&&(typeof Symbol!=="undefined"&&e[Symbol.iterator]||e["@@iterator"]);if(t==null)return;var n=[];var i=true;var a=false;var o,u;try{for(t=t.call(e);!(i=(o=t.next()).done);i=true){n.push(o.value);if(r&&n.length===r)break}}catch(e){a=true;u=e}finally{try{if(!i&&t["return"]!=null)t["return"]()}finally{if(a)throw u}}return n}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});unwrapExports(iterableToArrayLimit);var slicedToArray=createCommonjsModule(function(e){function r(e,r){return arrayWithHoles(e)||iterableToArrayLimit(e,r)||unsupportedIterableToArray(e,r)||nonIterableRest()}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});var _slicedToArray=unwrapExports(slicedToArray);var _typeof_1=createCommonjsModule(function(r){function t(e){"@babel/helpers - typeof";if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){r.exports=t=function e(r){return typeof r};r.exports["default"]=r.exports,r.exports.__esModule=true}else{r.exports=t=function e(r){return r&&typeof Symbol==="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r};r.exports["default"]=r.exports,r.exports.__esModule=true}return t(e)}r.exports=t;r.exports["default"]=r.exports,r.exports.__esModule=true});var _typeof=unwrapExports(_typeof_1);var asyncIterator=createCommonjsModule(function(e){function r(e){var r;if(typeof Symbol!=="undefined"){if(Symbol.asyncIterator)r=e[Symbol.asyncIterator];if(r==null&&Symbol.iterator)r=e[Symbol.iterator]}if(r==null)r=e["@@asyncIterator"];if(r==null)r=e["@@iterator"];if(r==null)throw new TypeError("Object is not async iterable");return r.call(e)}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});var _asyncIterator=unwrapExports(asyncIterator);var AwaitValue=createCommonjsModule(function(e){function r(e){this.wrapped=e}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});unwrapExports(AwaitValue);var awaitAsyncGenerator=createCommonjsModule(function(e){function r(e){return new AwaitValue(e)}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});var _awaitAsyncGenerator=unwrapExports(awaitAsyncGenerator);var AsyncGenerator_1=createCommonjsModule(function(e){function r(a){var o,u;function e(n,i){return new Promise(function(e,r){var t={key:n,arg:i,resolve:e,reject:r,next:null};if(u){u=u.next=t}else{o=u=t;c(n,i)}})}function c(r,e){try{var t=a[r](e);var n=t.value;var i=n instanceof AwaitValue;Promise.resolve(i?n.wrapped:n).then(function(e){if(i){c(r==="return"?"return":"next",e);return}s(t.done?"return":"normal",e)},function(e){c("throw",e)})}catch(e){s("throw",e)}}function s(e,r){switch(e){case"return":o.resolve({value:r,done:true});break;case"throw":o.reject(r);break;default:o.resolve({value:r,done:false});break}o=o.next;if(o){c(o.key,o.arg)}else{u=null}}this._invoke=e;if(typeof a["return"]!=="function"){this["return"]=undefined}}r.prototype[typeof Symbol==="function"&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this};r.prototype.next=function(e){return this._invoke("next",e)};r.prototype["throw"]=function(e){return this._invoke("throw",e)};r.prototype["return"]=function(e){return this._invoke("return",e)};e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});unwrapExports(AsyncGenerator_1);var wrapAsyncGenerator=createCommonjsModule(function(e){function r(e){return function(){return new AsyncGenerator_1(e.apply(this,arguments))}}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});var _wrapAsyncGenerator=unwrapExports(wrapAsyncGenerator);var runtime_1=createCommonjsModule(function(e){var r=function(o){var e=Object.prototype;var l=e.hasOwnProperty;var c;var r=typeof Symbol==="function"?Symbol:{};var i=r.iterator||"@@iterator";var t=r.asyncIterator||"@@asyncIterator";var n=r.toStringTag||"@@toStringTag";function a(e,r,t){Object.defineProperty(e,r,{value:t,enumerable:true,configurable:true,writable:true});return e[r]}try{a({},"")}catch(e){a=function(e,r,t){return e[r]=t}}function u(e,r,t,n){var i=r&&r.prototype instanceof s?r:s;var a=Object.create(i.prototype);var o=new S(n||[]);a._invoke=F(e,t,o);return a}o.wrap=u;function f(e,r,t){try{return{type:"normal",arg:e.call(r,t)}}catch(e){return{type:"throw",arg:e}}}var _="suspendedStart";var p="suspendedYield";var h="executing";var d="completed";var m={};function s(){}function v(){}function y(){}var b={};b[i]=function(){return this};var g=Object.getPrototypeOf;var w=g&&g(g(P([])));if(w&&w!==e&&l.call(w,i)){b=w}var D=y.prototype=s.prototype=Object.create(b);v.prototype=D.constructor=y;y.constructor=v;v.displayName=a(y,n,"GeneratorFunction");function x(e){["next","throw","return"].forEach(function(r){a(e,r,function(e){return this._invoke(r,e)})})}o.isGeneratorFunction=function(e){var r=typeof e==="function"&&e.constructor;return r?r===v||(r.displayName||r.name)==="GeneratorFunction":false};o.mark=function(e){if(Object.setPrototypeOf){Object.setPrototypeOf(e,y)}else{e.__proto__=y;a(e,n,"GeneratorFunction")}e.prototype=Object.create(D);return e};o.awrap=function(e){return{__await:e}};function L(u,c){function s(e,r,t,n){var i=f(u[e],u,r);if(i.type==="throw"){n(i.arg)}else{var a=i.arg;var o=a.value;if(o&&typeof o==="object"&&l.call(o,"__await")){return c.resolve(o.__await).then(function(e){s("next",e,t,n)},function(e){s("throw",e,t,n)})}return c.resolve(o).then(function(e){a.value=e;t(a)},function(e){return s("throw",e,t,n)})}}var r;function e(t,n){function e(){return new c(function(e,r){s(t,n,e,r)})}return r=r?r.then(e,e):e()}this._invoke=e}x(L.prototype);L.prototype[t]=function(){return this};o.AsyncIterator=L;o.async=function(e,r,t,n,i){if(i===void 0)i=Promise;var a=new L(u(e,r,t,n),i);return o.isGeneratorFunction(r)?a:a.next().then(function(e){return e.done?e.value:a.next()})};function F(o,u,c){var s=_;return function e(r,t){if(s===h){throw new Error("Generator is already running")}if(s===d){if(r==="throw"){throw t}return k()}c.method=r;c.arg=t;while(true){var n=c.delegate;if(n){var i=E(n,c);if(i){if(i===m)continue;return i}}if(c.method==="next"){c.sent=c._sent=c.arg}else if(c.method==="throw"){if(s===_){s=d;throw c.arg}c.dispatchException(c.arg)}else if(c.method==="return"){c.abrupt("return",c.arg)}s=h;var a=f(o,u,c);if(a.type==="normal"){s=c.done?d:p;if(a.arg===m){continue}return{value:a.arg,done:c.done}}else if(a.type==="throw"){s=d;c.method="throw";c.arg=a.arg}}}}function E(e,r){var t=e.iterator[r.method];if(t===c){r.delegate=null;if(r.method==="throw"){if(e.iterator["return"]){r.method="return";r.arg=c;E(e,r);if(r.method==="throw"){return m}}r.method="throw";r.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var n=f(t,e.iterator,r.arg);if(n.type==="throw"){r.method="throw";r.arg=n.arg;r.delegate=null;return m}var i=n.arg;if(!i){r.method="throw";r.arg=new TypeError("iterator result is not an object");r.delegate=null;return m}if(i.done){r[e.resultName]=i.value;r.next=e.nextLoc;if(r.method!=="return"){r.method="next";r.arg=c}}else{return i}r.delegate=null;return m}x(D);a(D,n,"Generator");D[i]=function(){return this};D.toString=function(){return"[object Generator]"};function A(e){var r={tryLoc:e[0]};if(1 in e){r.catchLoc=e[1]}if(2 in e){r.finallyLoc=e[2];r.afterLoc=e[3]}this.tryEntries.push(r)}function C(e){var r=e.completion||{};r.type="normal";delete r.arg;e.completion=r}function S(e){this.tryEntries=[{tryLoc:"root"}];e.forEach(A,this);this.reset(true)}o.keys=function(t){var n=[];for(var e in t){n.push(e)}n.reverse();return function e(){while(n.length){var r=n.pop();if(r in t){e.value=r;e.done=false;return e}}e.done=true;return e}};function P(r){if(r){var e=r[i];if(e){return e.call(r)}if(typeof r.next==="function"){return r}if(!isNaN(r.length)){var t=-1,n=function e(){while(++t=0;--r){var i=this.tryEntries[r];var a=i.completion;if(i.tryLoc==="root"){return e("end")}if(i.tryLoc<=this.prev){var o=l.call(i,"catchLoc");var u=l.call(i,"finallyLoc");if(o&&u){if(this.prev=0;--t){var n=this.tryEntries[t];if(n.tryLoc<=this.prev&&l.call(n,"finallyLoc")&&this.prev=0;--r){var t=this.tryEntries[r];if(t.finallyLoc===e){this.complete(t.completion,t.afterLoc);C(t);return m}}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.tryLoc===e){var n=t.completion;if(n.type==="throw"){var i=n.arg;C(t)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,t){this.delegate={iterator:P(e),resultName:r,nextLoc:t};if(this.method==="next"){this.arg=c}return m}};return o}(e.exports);try{regeneratorRuntime=r}catch(e){Function("r","regeneratorRuntime = r")(r)}});var regenerator=runtime_1;var _excluded=["token"],_excluded2=["stderr","stdin","stdout"];function _createForOfIteratorHelper(r,e){var t=typeof Symbol!=="undefined"&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&typeof r.length==="number"){if(t)r=t;var n=0;var i=function e(){};return{s:i,n:function e(){if(n>=r.length)return{done:true};return{done:false,value:r[n++]}},e:function e(r){throw r},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a=true,o=false,u;return{s:function e(){t=t.call(r)},n:function e(){var r=t.next();a=r.done;return r},e:function e(r){o=true;u=r},f:function e(){try{if(!a&&t["return"]!=null)t["return"]()}finally{if(o)throw u}}}}function _unsupportedIterableToArray(e,r){if(!e)return;if(typeof e==="string")return _arrayLikeToArray(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);if(t==="Object"&&e.constructor)t=e.constructor.name;if(t==="Map"||t==="Set")return Array.from(e);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return _arrayLikeToArray(e,r)}function _arrayLikeToArray(e,r){if(r==null||r>e.length)r=e.length;for(var t=0,n=new Array(r);t1&&arguments[1]!==undefined$1?arguments[1]:null;var n=arguments[1]===true;function r(e){if(!is_debug()){return}var r=global_env.get("repr")(e);if(t===null||t instanceof RegExp&&t.test(r)){console.log(global_env.get("type")(e)+": "+r)}if(n){console.log(e)}}if(is_promise(e)){e.then(r)}else{r(e)}return e}function is_debug(){return user_env&&user_env.get("DEBUG",{throwError:false})}if(!root.fetch){root.fetch=function(i,a){a=a||{};return new Promise(function(e,r){var t=new XMLHttpRequest;t.open(a.method||"get",i,true);for(var n in a.headers){t.setRequestHeader(n,a.headers[n])}t.withCredentials=a.credentials=="include";t.onload=function(){e(u())};t.onerror=r;t.send(a.body||null);function u(){var n=[],i=[],a={},o;t.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,r,t){n.push(r=r.toLowerCase());i.push([r,t]);o=a[r];a[r]=o?"".concat(o,",").concat(t):t});return{ok:(t.status/100|0)==2,status:t.status,statusText:t.statusText,url:t.responseURL,clone:u,text:function e(){return Promise.resolve(t.responseText)},json:function e(){return Promise.resolve(t.responseText).then(JSON.parse)},blob:function e(){return Promise.resolve(new Blob([t.response]))},headers:{keys:function e(){return n},entries:function e(){return i},get:function e(r){return a[r.toLowerCase()]},has:function e(r){return r.toLowerCase()in a}}}}})}}function num_mnemicic_re(e){return e?"(?:#".concat(e,"(?:#[ie])?|#[ie]#").concat(e,")"):"(?:#[ie])?"}function gen_rational_re(e,r){return"".concat(num_mnemicic_re(e),"[+-]?").concat(r,"+/").concat(r,"+")}function gen_complex_re(e,r){return"".concat(num_mnemicic_re(e),"(?:[+-]?(?:").concat(r,"+/").concat(r,"+|nan.0|inf.0|").concat(r,"+))?(?:[+-]i|[+-]?(?:").concat(r,"+/").concat(r,"+|").concat(r,"+|nan.0|inf.0)i)(?=[()[\\]\\s]|$)")}function gen_integer_re(e,r){return"".concat(num_mnemicic_re(e),"[+-]?").concat(r,"+")}var re_re=/^#\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimyus]*)$/;var float_stre="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)";var complex_float_stre="(?:#[ie])?(?:[+-]?(?:[0-9]+/[0-9]+|nan.0|inf.0|".concat(float_stre,"|[+-]?[0-9]+))?(?:").concat(float_stre,"|[+-](?:[0-9]+/[0-9]+|[0-9]+|nan.0|inf.0))i");var float_re=new RegExp("^(#[ie])?".concat(float_stre,"$"),"i");function make_complex_match_re(e,r){var t=e==="x"?"(?!\\+|".concat(r,")"):"(?!\\.|".concat(r,")");var n="";if(e===""){n="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+(?![0-9]))(?:[eE][-+]?[0-9]+)?))"}return new RegExp("^((?:(?:".concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(r,"+/").concat(r,"+(?!").concat(r,")|[+-]?").concat(r,"+)").concat(t,")?)(").concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(r,"+/").concat(r,"+|[+-]?").concat(r,"+|[+-])i$"),"i")}var complex_list_re=function(){var a={};[[10,"","[0-9]"],[16,"x","[0-9a-fA-F]"],[8,"o","[0-7]"],[2,"b","[01]"]].forEach(function(e){var r=_slicedToArray(e,3),t=r[0],n=r[1],i=r[2];a[t]=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 r=[];var t=0;var n=e.length;while(t=55296&&i<=56319&&t1&&arguments[1]!==undefined$1?arguments[1]:10;var t=num_pre_parse(e);var n=t.number.split("/");var i=LRational({num:LNumber([n[0],t.radix||r]),denom:LNumber([n[1],t.radix||r])});if(t.inexact){return i.valueOf()}else{return i}}function parse_integer(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:10;var t=num_pre_parse(e);if(t.inexact){return LFloat(parseInt(t.number,t.radix||r))}return LNumber([t.number,t.radix||r])}function parse_character(e){var r=e.match(/#\\x([0-9a-f]+)$/i);var t;if(r){var n=parseInt(r[1],16);t=String.fromCodePoint(n)}else{r=e.match(/#\\(.+)$/);if(r){t=r[1]}}if(t){return LCharacter(t)}throw new Error("Parse: invalid character")}function parse_complex(e){var i=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:10;function r(e){var r;if(e==="+"){r=LNumber(1)}else if(e==="-"){r=LNumber(-1)}else if(e.match(int_bare_re)){r=LNumber([e,i])}else if(e.match(rational_bare_re)){var t=e.split("/");r=LRational({num:LNumber([t[0],i]),denom:LNumber([t[1],i])})}else if(e.match(float_re)){var n=parse_float(e);if(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(r.valueOf())}return r}var a=num_pre_parse(e);i=a.radix||i;var t;var n=a.number.match(complex_bare_match_re);if(i!==10&&n){t=n}else{t=a.number.match(complex_list_re[i])}var o,u;u=r(t[2]);if(t[1]){o=r(t[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 r=e.match(/^(([-+]?[0-9]*)(?:\.([0-9]+))?)e([-+]?[0-9]+)/i);if(r){var t=parseInt(r[4],10);var n;var i=r[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var a=r[3]&&r[3].length;if(i0){return LNumber(a).mul(u)}}}t=LFloat(t);if(r.exact){return t.toRational()}return t}function parse_string(e){e=e.replace(/\\x([0-9a-f]+);/gi,function(e,r){return"\\u"+r.padStart(4,"0")}).replace(/\n/g,"\\n");var r=e.match(/(\\*)(\\x[0-9A-F])/i);if(r&&r[1].length%2===0){throw new Error("Invalid string literal, unclosed ".concat(r[2]))}try{return LString(JSON.parse(e))}catch(e){throw new Error("Invalid string literal")}}function parse_symbol(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var t={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,r){return String.fromCharCode(parseInt("0"+r,16))}).replace(/\\(.)/g,function(e,r){return t[r]||r})}return new LSymbol(e)}function parse_argument(e){if(constants.hasOwnProperty(e)){return constants[e]}if(e.match(/^"[\s\S]*"$/)){return parse_string(e)}else if(e[0]==="#"){var r=e.match(re_re);if(r){return new RegExp(r[1],r[2])}else if(e.match(char_re)){return parse_character(e)}var t=e.match(/#\\(.+)/);if(t&&ucs2decode(t[1]).length===1){return parse_character(e)}}if(e.match(/[0-9a-f]|[+-]i/i)){if(e.match(int_re)){return parse_integer(e)}else if(e.match(float_re)){return parse_float(e)}else if(e.match(rational_re)){return parse_rational(e)}else if(e.match(complex_re)){return parse_complex(e)}}if(e.match(/^#[iexobd]/)){throw new Error("Invalid numeric constant: "+e)}return parse_symbol(e)}function is_symbol_string(e){return!(["(",")","[","]"].includes(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","true","false"].includes(e))}var string_re=/"(?:\\[\S\s]|[^"])*"?/g;function escape_regex(e){if(typeof e==="string"){var r=/([-\\^$[\]()+{}?*.|])/g;return e.replace(r,"\\$1")}return e}function Stack(){this.data=[]}Stack.prototype.push=function(e){this.data.push(e)};Stack.prototype.top=function(){return this.data[this.data.length-1]};Stack.prototype.pop=function(){return this.data.pop()};Stack.prototype.is_empty=function(){return!this.data.length};function tokens(e){if(e instanceof LString){e=e.valueOf()}var r=new Lexer(e,{whitespace:true});var t=[];while(true){var n=r.peek(true);if(n===eof){break}t.push(n);r.skip()}return t}function multiline_formatter(e){var r=e.token,t=_objectWithoutProperties(e,_excluded);if(r.match(/^"[\s\S]*"$/)&&r.match(/\n/)){var n=new RegExp("^ {1,"+(e.col+1)+"}","mg");r=r.replace(n,"")}return _objectSpread({token:r},t)}function Thunk(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:function(){};this.fn=e;this.cont=r}Thunk.prototype.toString=function(){return"#"};function trampoline(n){return function(){for(var e=arguments.length,r=new Array(e),t=0;t1&&arguments[1]!==undefined$1?arguments[1]:false;if(e instanceof LString){e=e.toString()}if(r){return tokens(e)}else{var t=tokens(e).map(function(e){if(e.token==="#\\ "){return e.token}return e.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return strip_s_comments(t)}}function strip_s_comments(e){var r=0;var t=null;var n=[];for(var i=0;i0&&arguments[0]!==undefined$1?arguments[0]:null;if(e instanceof LSymbol){e=e.valueOf()}if(is_gensym(e)){return LSymbol(e)}if(e!==null){return new LSymbol(Symbol("#:".concat(e)))}r++;return new LSymbol(Symbol("#:g".concat(r)))}}();function QuotedPromise(e){var t=this;var n={pending:true,rejected:false,fulfilled:false,reason:undefined$1,type:undefined$1};e=e.then(function(e){n.type=type(e);n.fulfilled=true;n.pending=false;return e});read_only(this,"_promise",e,{hidden:true});if(is_function(e["catch"])){e=e["catch"](function(e){n.rejected=true;n.pending=false;n.reason=e})}Object.keys(n).forEach(function(r){Object.defineProperty(t,"__".concat(r,"__"),{enumerable:true,get:function e(){return n[r]}})});read_only(this,"__promise__",e);this.then=false}QuotedPromise.prototype.then=function(e){return new QuotedPromise(this.valueOf().then(e))};QuotedPromise.prototype["catch"]=function(e){return new QuotedPromise(this.valueOf()["catch"](e))};QuotedPromise.prototype.valueOf=function(){if(!this._promise){throw new Error("QuotedPromise: invalid promise created")}return this._promise};QuotedPromise.prototype.toString=function(){if(this.__pending__){return QuotedPromise.pending_str}if(this.__rejected__){return QuotedPromise.rejected_str}return"#")};QuotedPromise.pending_str="#";QuotedPromise.rejected_str="#";function promise_all(e){if(Array.isArray(e)){return Promise.all(escape_quoted_promises(e)).then(unescape_quoted_promises)}return e}function escape_quoted_promises(e){var r=new Array(e.length),t=e.length;while(t--){var n=e[t];if(n instanceof QuotedPromise){r[t]=new Value(n)}else{r[t]=n}}return r}function unescape_quoted_promises(e){var r=new Array(e.length),t=e.length;while(t--){var n=e[t];if(n instanceof Value){r[t]=n.valueOf()}else{r[t]=n}}return r}var specials={LITERAL:Symbol["for"]("literal"),SPLICE:Symbol["for"]("splice"),SYMBOL:Symbol["for"]("symbol"),names:function e(){return Object.keys(this._specials)},type:function e(r){return this.get(r).type},get:function e(r){return this._specials[r]},off:function e(r){var t=this;var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:null;if(Array.isArray(r)){r.forEach(function(e){return t.off(e,n)})}else if(n===null){delete this._events[r]}else{this._events=this._events.filter(function(e){return e!==n})}},on:function e(r,t){var n=this;if(Array.isArray(r)){r.forEach(function(e){return n.on(e,t)})}else if(!this._events[r]){this._events[r]=[t]}else{this._events[r].push(t)}},trigger:function e(r){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i",new LSymbol("quote-promise"),specials.LITERAL]];Object.defineProperty(specials,"builtin",{writable:false,value:defined_specials.map(function(e){return e[0]})});defined_specials.forEach(function(e){var r=_slicedToArray(e,3),t=r[0],n=r[1],i=r[2];specials.append(t,n,i)});var Lexer=function(){function p(e){var r=this;var t=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},n=t.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(t){Object.defineProperty(r,t,{configurable:false,enumerable:false,get:function e(){return a[t]},set:function e(r){a[t]=r}})});this._whitespace=i;this._i=this._line=this._col=this._newline=0;this._state=this._next=this._token=null;this._prev_char=""}_createClass(p,[{key:"get",value:function e(r){return this.__internal[r]}},{key:"set",value:function e(r,t){this.__internal[r]=t}},{key:"token",value:function e(){var r=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:false;if(r){var t=this._line;if(this._whitespace&&this._token==="\n"){--t}return{token:this._token,col:this._col,offset:this._i,line:t}}return this._token}},{key:"peek",value:function e(){var r=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:false;if(this._i>=this.__input__.length){return eof}if(this._token){return this.token(r)}var t=this.next_token();if(t){this._token=this.__input__.substring(this._i,this._next);return this.token(r)}return eof}},{key:"skip",value:function e(){if(this._next!==null){this._token=null;this._i=this._next}}},{key:"read_line",value:function e(){var r=this.__input__.length;if(this._i>=r){return eof}for(var t=this._i;t=t){return eof}if(r+this._i>=t){return this.read_rest()}var n=this._i+r;var i=this.__input__.substring(this._i,n);var 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 r=this.peek_char();this.skip_char();return r}},{key:"skip_char",value:function e(){if(this._i1&&arguments[1]!==undefined$1?arguments[1]:{},n=t.prev_char,i=t["char"],a=t.next_char;var o=_slicedToArray(r,4),u=o[0],c=o[1],s=o[2],l=o[3];if(r.length!==5){throw new Error("Lexer: Invald rule of length ".concat(r.length))}if(!i.match(u)){return false}if(!match_or_null(c,n)){return false}if(!match_or_null(s,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 r=true;e:for(var t=this._i,n=this.__input__.length;t2&&arguments[2]!==undefined$1?arguments[2]:null;var i=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:null;if(r.length===0){throw new Error("Lexer: invalid literal rule")}if(r.length===1){return[[r,n,i,null,null]]}var a=[];for(var o=0,u=r.length;o1&&arguments[1]!==undefined$1?arguments[1]:{},t=r.env,n=r.meta,i=n===void 0?false:n,a=r.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__",t);read_only(this,"_meta",i,{hidden:true});read_only(this,"_refs",[],{hidden:true})}_createClass(u,[{key:"resolve",value:function e(r){return this.__env__&&this.__env__.get(r,{throwError:false})}},{key:"peek",value:function(){var e=_asyncToGenerator(regenerator.mark(function e(){var t;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:t=this.__lexer__.peek(true);if(!(t===eof)){r.next=4;break}return r.abrupt("return",eof);case 4:if(!this.is_comment(t.token)){r.next=7;break}this.skip();return r.abrupt("continue",0);case 7:if(!(t.token==="#;")){r.next=14;break}this.skip();if(!(this.__lexer__.peek()===eof)){r.next=11;break}throw new Error("Lexer: syntax error eof found after comment");case 11:r.next=13;return this._read_object();case 13:return r.abrupt("continue",0);case 14:return r.abrupt("break",17);case 17:t=this._formatter(t);if(!this._meta){r.next=20;break}return r.abrupt("return",t);case 20:return r.abrupt("return",t.token);case 21:case"end":return r.stop()}}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"reset",value:function e(){this._refs.length=0}},{key:"skip",value:function e(){this.__lexer__.skip()}},{key:"is_special",value:function e(r){return specials.names().includes(r)}},{key:"is_builtin",value:function e(r){return specials.builtin.includes(r)}},{key:"read",value:function(){var e=_asyncToGenerator(regenerator.mark(function e(){var t;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:r.next=2;return this.peek();case 2:t=r.sent;this.skip();return r.abrupt("return",t);case 5:case"end":return r.stop()}}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"match_datum_label",value:function e(r){var t=r.match(/^#([0-9]+)=$/);return t&&t[1]}},{key:"match_datum_ref",value:function e(r){var t=r.match(/^#([0-9]+)#$/);return t&&t[1]}},{key:"is_open",value:function e(r){return["(","["].includes(r)}},{key:"is_close",value:function e(r){return[")","]"].includes(r)}},{key:"read_list",value:function(){var e=_asyncToGenerator(regenerator.mark(function e(){var t,n,i,a;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:t=_nil,n=t;case 1:r.next=4;return this.peek();case 4:i=r.sent;if(!(i===eof)){r.next=7;break}return r.abrupt("break",27);case 7:if(!this.is_close(i)){r.next=10;break}this.skip();return r.abrupt("break",27);case 10:if(!(i==="."&&t!==_nil)){r.next=17;break}this.skip();r.next=14;return this._read_object();case 14:n.cdr=r.sent;r.next=25;break;case 17:r.t0=Pair;r.next=20;return this._read_object();case 20:r.t1=r.sent;r.t2=_nil;a=new r.t0(r.t1,r.t2);if(t===_nil){t=a}else{n.cdr=a}n=a;case 25:r.next=1;break;case 27:return r.abrupt("return",t);case 28:case"end":return r.stop()}}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"read_value",value:function(){var e=_asyncToGenerator(regenerator.mark(function e(){var t;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:r.next=2;return this.read();case 2:t=r.sent;if(!(t===eof)){r.next=5;break}throw new Error("Parser: Expected token eof found");case 5:return r.abrupt("return",parse_argument(t));case 6:case"end":return r.stop()}}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"is_comment",value:function e(r){return r.match(/^;/)||r.match(/^#\|/)&&r.match(/\|#$/)}},{key:"evaluate",value:function e(r){return _evaluate(r,{env:this.__env__,error:function e(r){throw r}})}},{key:"read_object",value:function(){var e=_asyncToGenerator(regenerator.mark(function e(){var t;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:this.reset();r.next=3;return this._read_object();case 3:t=r.sent;if(t instanceof DatumReference){t=t.valueOf()}if(!this._refs.length){r.next=7;break}return r.abrupt("return",this._resolve_object(t));case 7:return r.abrupt("return",t);case 8:case"end":return r.stop()}}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"_resolve_object",value:function(){var r=_asyncToGenerator(regenerator.mark(function e(t){var n=this;var i;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!Array.isArray(t)){r.next=2;break}return r.abrupt("return",t.map(function(e){return n._resolve_object(e)}));case 2:if(!is_plain_object(t)){r.next=6;break}i={};Object.keys(t).forEach(function(e){i[e]=n._resolve_object(t[e])});return r.abrupt("return",i);case 6:if(!(t instanceof Pair)){r.next=8;break}return r.abrupt("return",this._resolve_pair(t));case 8:return r.abrupt("return",t);case 9:case"end":return r.stop()}}},e,this)}));function e(e){return r.apply(this,arguments)}return e}()},{key:"_resolve_pair",value:function(){var r=_asyncToGenerator(regenerator.mark(function e(t){return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!(t instanceof Pair)){r.next=15;break}if(!(t.car instanceof DatumReference)){r.next=7;break}r.next=4;return t.car.valueOf();case 4:t.car=r.sent;r.next=8;break;case 7:this._resolve_pair(t.car);case 8:if(!(t.cdr instanceof DatumReference)){r.next=14;break}r.next=11;return t.cdr.valueOf();case 11:t.cdr=r.sent;r.next=15;break;case 14:this._resolve_pair(t.cdr);case 15:return r.abrupt("return",t);case 16:case"end":return r.stop()}}},e,this)}));function e(e){return r.apply(this,arguments)}return e}()},{key:"_read_object",value:function(){var e=_asyncToGenerator(regenerator.mark(function e(){var t,n,i,a,o,u,c,s,l;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:r.next=2;return this.peek();case 2:t=r.sent;if(!(t===eof)){r.next=5;break}return r.abrupt("return",t);case 5:if(!this.is_special(t)){r.next=35;break}n=specials.get(t);i=this.is_builtin(t);this.skip();r.next=11;return this._read_object();case 11:o=r.sent;if(i){r.next=22;break}u=this.__env__.get(n.symbol);if(!(typeof u==="function")){r.next=22;break}if(!is_literal(t)){r.next=19;break}return r.abrupt("return",u.call(this.__env__,o));case 19:if(!(o instanceof Pair)){r.next=21;break}return r.abrupt("return",u.apply(this.__env__,o.to_array(false)));case 21:throw new Error("Parse Error: Invalid parser extension "+"invocation ".concat(n.symbol));case 22:if(is_literal(t)){a=new Pair(n.symbol,new Pair(o,_nil))}else{a=new Pair(n.symbol,o)}if(!i){r.next=25;break}return r.abrupt("return",a);case 25:if(!(u instanceof Macro)){r.next=34;break}r.next=28;return this.evaluate(a);case 28:c=r.sent;if(!(c instanceof Pair||c instanceof LSymbol)){r.next=31;break}return r.abrupt("return",Pair.fromArray([LSymbol("quote"),c]));case 31:return r.abrupt("return",c);case 34:throw new Error("Parse Error: invlid parser extension: "+n.symbol);case 35:s=this.match_datum_ref(t);if(!(s!==null)){r.next=41;break}this.skip();if(!this._refs[s]){r.next=40;break}return r.abrupt("return",new DatumReference(s,this._refs[s]));case 40:throw new Error("Parse Error: invalid datum label #".concat(s,"#"));case 41:l=this.match_datum_label(t);if(!(l!==null)){r.next=48;break}this.skip();this._refs[l]=this._read_object();return r.abrupt("return",this._refs[l]);case 48:if(!this.is_open(t)){r.next=53;break}this.skip();return r.abrupt("return",this.read_list());case 53:return r.abrupt("return",this.read_value());case 54:case"end":return r.stop()}}},e,this)}));function r(){return e.apply(this,arguments)}return r}()}]);return u}();var DatumReference=function(){function t(e,r){_classCallCheck(this,t);this.name=e;this.data=r}_createClass(t,[{key:"valueOf",value:function e(){return this.data}}]);return t}();function parse(e,r){return _parse.apply(this,arguments)}function _parse(){_parse=_wrapAsyncGenerator(regenerator.mark(function e(t,n){var i,a;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!n){if(global_env){n=global_env.get("**interaction-environment**",{throwError:false})}else{n=user_env}}i=new Parser(t,{env:n});case 2:r.next=5;return _awaitAsyncGenerator(i.read_object());case 5:a=r.sent;if(!(a===eof)){r.next=8;break}return r.abrupt("break",12);case 8:r.next=10;return a;case 10:r.next=2;break;case 12:case"end":return r.stop()}}},e)}));return _parse.apply(this,arguments)}function unpromise(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:function(e){return e};var t=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:null;if(is_promise(e)){var n=e.then(r);if(t===null){return n}else{return n["catch"](t)}}if(e instanceof Array){return unpromise_array(e,r,t)}if(is_plain_object(e)){return unpromise_object(e,r,t)}return r(e)}function unpromise_array(r,e,t){if(r.find(is_promise)){return unpromise(promise_all(r),function(e){if(Object.isFrozen(r)){Object.freeze(e)}return e},t)}return e(r)}function unpromise_object(r,e,t){var i=Object.keys(r);var n=[],a=[];var o=i.length;while(o--){var u=i[o];var c=r[u];n[o]=c;if(is_promise(c)){a.push(c)}}if(a.length){return unpromise(promise_all(n),function(e){var n={};e.forEach(function(e,r){var t=i[r];n[t]=e});if(Object.isFrozen(r)){Object.freeze(n)}return n},t)}return e(r)}function read_only(e,r,t){var n=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:{},i=n.hidden,a=i===void 0?false:i;Object.defineProperty(e,r,{value:t,configurable:true,enumerable:!a})}function uniterate_async(e){return _uniterate_async.apply(this,arguments)}function _uniterate_async(){_uniterate_async=_asyncToGenerator(regenerator.mark(function e(t){var n,i,a,o,u,c,s,l;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:n=[];i=true;a=false;r.prev=3;u=_asyncIterator(t);case 5:r.next=7;return u.next();case 7:c=r.sent;i=c.done;r.next=11;return c.value;case 11:s=r.sent;if(i){r.next=18;break}l=s;n.push(l);case 15:i=true;r.next=5;break;case 18:r.next=24;break;case 20:r.prev=20;r.t0=r["catch"](3);a=true;o=r.t0;case 24:r.prev=24;r.prev=25;if(!(!i&&u["return"]!=null)){r.next=29;break}r.next=29;return u["return"]();case 29:r.prev=29;if(!a){r.next=32;break}throw o;case 32:return r.finish(29);case 33:return r.finish(24);case 34:return r.abrupt("return",n);case 35:case"end":return r.stop()}}},e,null,[[3,20,24,34],[25,,29,33]])}));return _uniterate_async.apply(this,arguments)}function matcher(e,r){if(r instanceof RegExp){return function(e){return String(e).match(r)}}else if(is_function(r)){return r}throw new Error("Invalid matcher")}function doc(e,r,t,n){if(typeof e!=="string"){r=arguments[0];t=arguments[1];n=arguments[2];e=null}if(t){if(n){r.__doc__=t}else{r.__doc__=trim_lines(t)}}if(e){r.__name__=e}else if(r.name&&!is_lambda(r)){r.__name__=r.name}return r}function trim_lines(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function previousSexp(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:1;var t=e.length;if(r<=0){throw Error("previousSexp: Invalid argument sexp = ".concat(r))}e:while(r--&&t>=0){var n=1;while(n>0){var i=e[--t];if(!i){break e}if(i==="("||i.token==="("){n--}else if(i===")"||i.token===")"){n++}}t--}return e.slice(t+1)}function lineIndent(e){if(!e||!e.length){return 0}var r=e.length;if(e[r-1].token==="\n"){return 0}while(--r){if(e[r].token==="\n"){var t=(e[r+1]||{}).token;if(t){return t.length}}}return 0}function match(e,r){return l(e,r)===r.length;function l(t,n){function e(e,r){var t=_createForOfIteratorHelper(e),n;try{for(t.s();!(n=t.n()).done;){var i=n.value;var a=l(i,r);if(a!==-1){return a}}}catch(e){t.e(e)}finally{t.f()}return-1}function r(){return t[a]===Symbol["for"]("symbol")&&!is_symbol_string(n[u])}function i(){var e=t[a+1];var r=n[u+1];if(e!==undefined$1&&r!==undefined$1){return l([e],[r])}}var a=0;var o={};for(var u=0;u0){continue}}else if(r()){return-1}}else if(t[a]instanceof Array){var s=l(t[a],n.slice(u));if(s===-1||s+u>n.length){return-1}u+=s-1;a++;continue}else{return-1}a++}if(t.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|\*)?)$/],shift:{1:["&","#"]}}};Formatter.match=match;Formatter.prototype._options=function e(r){var t=Formatter.defaults;if(typeof r==="undefined"){return Object.assign({},t)}var n=r&&r.exceptions||{};var i=n.specials||[];var a=n.shift||{1:[]};return _objectSpread(_objectSpread(_objectSpread({},t),r),{},{exceptions:{specials:[].concat(_toConsumableArray(t.exceptions.specials),_toConsumableArray(i)),shift:_objectSpread(_objectSpread({},a),{},{1:[].concat(_toConsumableArray(t.exceptions.shift[1]),_toConsumableArray(a[1]))})}})};Formatter.prototype.indent=function e(r){var t=tokenize(this.__code__,true);return this._indent(t,r)};Formatter.exception_shift=function(a,e){function r(e){if(!e.length){return false}if(e.indexOf(a)!==-1){return true}else{var r=e.filter(function(e){return e instanceof RegExp});if(!r.length){return false}var t=_createForOfIteratorHelper(r),n;try{for(t.s();!(n=t.n()).done;){var i=n.value;if(a.match(i)){return true}}}catch(e){t.e(e)}finally{t.f()}}return false}if(r(e.exceptions.specials)){return e.indent}var t=e.exceptions.shift;for(var n=0,i=Object.entries(t);n0){n.offset=0}if(a.toString()===r.toString()&&balanced(a)){return n.offset+a[0].col}else if(a.length===1){return n.offset+a[0].col+1}else{var c=-1;if(o){var s=Formatter.exception_shift(o.token,n);if(s!==-1){c=s}}if(c===-1){c=Formatter.exception_shift(a[1].token,n)}if(c!==-1){return n.offset+a[0].col+c}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,r=new Array(e),t=0;t")};Formatter.Pattern=Pattern;Formatter.Ahead=Ahead;var p_o=/^[[(]$/;var p_e=/^[\])]$/;var not_p=/[^()[\]]/;var not_close=new Ahead(/[^)\]]/);var glob=Symbol["for"]("*");var sexp_or_atom=new Pattern([p_o,glob,p_e],[not_p],"+");var sexp=new Pattern([p_o,glob,p_e],"+");var symbol=new Pattern([Symbol["for"]("symbol")],"?");var symbols=new Pattern([Symbol["for"]("symbol")],"*");var identifiers=[p_o,symbols,p_e];var let_value=new Pattern([p_o,Symbol["for"]("symbol"),glob,p_e],"+");var def_lambda_re=keywords_re("define","lambda","define-macro","syntax-rules");var non_def=/^(?!.*\b(?:[()[\]]|define(?:-macro)?|let(?:\*|rec|-env|-syntax|)?|lambda|syntax-rules)\b).*$/;var let_re=/^(?:#:)?(let(?:\*|rec|-env|-syntax)?)$/;function keywords_re(){for(var e=arguments.length,r=new Array(e),t=0;t0&&!o[e]){o[e]=previousSexp(a,e)}});var u=_createForOfIteratorHelper(n),c;try{for(u.s();!(c=u.n()).done;){var s=_slicedToArray(c.value,3),l=s[0],f=s[1],_=s[2];f=f.valueOf();var p=f>0?o[f]:a;var h=match(l,p.filter(function(e){return e.trim()}));var d=t.slice(i).find(function(e){return e.trim()});if(h&&(_ instanceof Ahead&&_.match(d)||!_)){if(!t[i-1].trim()){t[i-1]="\n"}else{t.splice(i,0,"\n");i++}continue}}}catch(e){u.e(e)}finally{u.f()}}this.__code__=t.join("");return this};Formatter.prototype._spaces=function(e){return new Array(e+1).join(" ")};Formatter.prototype.format=function e(r){var t=this.__code__.replace(/[ \t]*\n[ \t]*/g,"\n ");var n=tokenize(t,true);var i=this._options(r);var a=0;var o=0;for(var u=0;u0&&arguments[0]!==undefined$1?arguments[0]:true;var n=new Map;function i(e){if(e instanceof Pair){if(n.has(e)){return n.get(e)}var r=new Pair;n.set(e,r);if(t){r.car=i(e.car)}else{r.car=e.car}r.cdr=i(e.cdr);r[__cycles__]=e[__cycles__];return r}return e}return i(this)};Pair.prototype.last_pair=function(){var e=this;while(true){if(e.cdr===_nil){return e}e=e.cdr}};Pair.prototype.to_array=function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:true;var r=[];if(this.car instanceof Pair){if(e){r.push(this.car.to_array())}else{r.push(this.car)}}else{r.push(this.car.valueOf())}if(this.cdr instanceof Pair){r=r.concat(this.cdr.to_array())}return r};Pair.fromArray=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:true;var t=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:false;if(e instanceof Pair||t&&e instanceof Array&&e[__data__]){return e}if(r===false){var n=_nil;for(var i=e.length;i--;){n=new Pair(e[i],n)}return n}if(e.length&&!(e instanceof Array)){e=_toConsumableArray(e)}var a=_nil;var o=e.length;while(o--){var u=e[o];if(u instanceof Array){u=Pair.fromArray(u,r,t)}else if(typeof u==="string"){u=LString(u)}else if(typeof u==="number"&&!Number.isNaN(u)){u=LNumber(u)}a=new Pair(u,a)}return a};Pair.prototype.to_object=function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:false;var r=this;var t={};while(true){if(r instanceof Pair&&r.car instanceof Pair){var n=r.car;var i=n.car;if(i instanceof LSymbol){i=i.__name__}if(i instanceof LString){i=i.valueOf()}var a=n.cdr;if(a instanceof Pair){a=a.to_object(e)}if(is_native(a)){if(!e){a=a.valueOf()}}t[i]=a;r=r.cdr}else{break}}return t};Pair.fromPairs=function(e){return e.reduce(function(e,r){return new Pair(new Pair(new LSymbol(r[0]),r[1]),e)},_nil)};Pair.fromObject=function(r){var e=Object.keys(r).map(function(e){return[e,r[e]]});return Pair.fromPairs(e)};Pair.prototype.reduce=function(e){var r=this;var t=_nil;while(true){if(r!==_nil){t=e(t,r.car);r=r.cdr}else{break}}return t};Pair.prototype.reverse=function(){if(this.haveCycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var r=_nil;while(e!==_nil){var t=e.cdr;e.cdr=r;r=e;e=t}return r};Pair.prototype.transform=function(n){function i(e){if(e instanceof Pair){if(e.replace){delete e.replace;return e}var r=n(e.car);if(r instanceof Pair){r=i(r)}var t=n(e.cdr);if(t instanceof Pair){t=i(t)}return new Pair(r,t)}return e}return i(this)};Pair.prototype.map=function(e){if(typeof this.car!=="undefined"){return new Pair(e(this.car),this.cdr===_nil?_nil:this.cdr.map(e))}else{return _nil}};var repr=new Map;function is_plain_object(e){return e&&_typeof(e)==="object"&&e.constructor===Object}var props=Object.getOwnPropertyNames(Array.prototype);var array_methods=[];props.forEach(function(e){array_methods.push(Array[e],Array.prototype[e])});function is_array_method(e){e=unbind(e);return array_methods.includes(e)}function is_lips_function(e){return is_function(e)&&(is_lambda(e)||e.__doc__)}function user_repr(t){var e=t.constructor||Object;var n=is_plain_object(t);var i=is_function(t[Symbol.asyncIterator])||is_function(t[Symbol.iterator]);var a;if(repr.has(e)){a=repr.get(e)}else{repr.forEach(function(e,r){r=unbind(r);if(t.constructor===r&&(r===Object&&n&&!i||r!==Object)){a=e}})}return a}var str_mapping=new Map;[[true,"#t"],[false,"#f"],[null,"null"],[undefined$1,"#"]].forEach(function(e){var r=_slicedToArray(e,2),t=r[0],n=r[1];str_mapping.set(t,n)});function symbolize(t){if(t&&_typeof(t)==="object"){var n={};var e=Object.getOwnPropertySymbols(t);e.forEach(function(e){var r=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");n[r]=toString(t[e])});var r=Object.getOwnPropertyNames(t);r.forEach(function(e){var r=t[e];if(r&&_typeof(r)==="object"&&r.constructor===Object){n[e]=symbolize(r)}else{n[e]=toString(r)}});return n}return t}function get_props(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function has_own_function(e,r){return e.hasOwnProperty(r)&&is_function(e.toString)}function function_to_string(e){if(is_native_function(e)){return"#"}var r=e.prototype&&e.prototype.constructor;if(is_function(r)&&is_lambda(r)){if(e[__class__]&&r.hasOwnProperty("__name__")){var t=r.__name__;if(LString.isString(t)){t=t.toString();return"#")}return"#"}}if(e.hasOwnProperty("__name__")){var n=e.__name__;if(_typeof(n)==="symbol"){n=symbol_to_string(n)}if(typeof n==="string"){return"#")}}if(has_own_function(e,"toString")){return e.toString()}else if(e.name&&!is_lambda(e)){return"#")}else{return"#"}}var instances=new Map;[[Error,function(e){return e.message}],[Pair,function(e,r){var t=r.quote,n=r.skip_cycles,i=r.pair_args;if(!n){e.markCycles()}return e.toString.apply(e,[t].concat(_toConsumableArray(i)))}],[LCharacter,function(e,r){var t=r.quote;if(t){return e.toString()}return e.valueOf()}],[LString,function(e,r){var t=r.quote;e=e.toString();if(t){return JSON.stringify(e).replace(/\\n/g,"\n")}return e}],[RegExp,function(e){return"#"+e.toString()}]].forEach(function(e){var r=_slicedToArray(e,2),t=r[0],n=r[1];instances.set(t,n)});var native_types=[LSymbol,LNumber,Macro,Values,InputPort,OutputPort,Environment,QuotedPromise];function toString(e,r,t){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(str_mapping.has(e)){return str_mapping.get(e)}if(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(_typeof(e)==="object"){var l=e.constructor;if(!l){l=Object}var f;if(typeof l.__class__==="string"){f=l.__class__}else{if(is_prototype(e)){return"#"}var _=user_repr(e);if(_){if(is_function(_)){return _(e,r)}else{throw new Error("toString: Invalid repr value")}}f=l.name}if(is_function(e.toString)&&is_lambda(e.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}function is_prototype(e){return e&&_typeof(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}Pair.prototype.markCycles=function(){markCycles(this);return this};Pair.prototype.haveCycles=function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:null;if(!e){return this.haveCycles("car")||this.haveCycles("cdr")}return!!(this[__cycles__]&&this[__cycles__][e])};function markCycles(e){var r=[];var i=[];var a=[];function o(e){if(!r.includes(e)){r.push(e)}}function u(e,r,t,n){if(t instanceof Pair){if(n.includes(t)){if(!a.includes(t)){a.push(t)}if(!e[__cycles__]){e[__cycles__]={}}e[__cycles__][r]=t;if(!i.includes(e)){i.push(e)}return true}}}var c=trampoline(function e(r,t){if(r instanceof Pair){delete r.ref;delete r[__cycles__];o(r);t.push(r);var n=u(r,"car",r.car,t);var i=u(r,"cdr",r.cdr,t);if(!n){c(r.car,t.slice())}if(!i){return new Thunk(function(){return e(r.cdr,t.slice())})}}});function t(e,r){if(e[__cycles__][r]instanceof Pair){var t=n.indexOf(e[__cycles__][r]);e[__cycles__][r]="#".concat(t,"#")}}c(e,[]);var n=r.filter(function(e){return a.includes(e)});n.forEach(function(e,r){e[__ref__]="#".concat(r,"=")});i.forEach(function(e){t(e,"car");t(e,"cdr")})}Pair.prototype.toString=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},t=r.nested,n=t===void 0?false:t;var i=[];if(this[__ref__]){i.push(this[__ref__]+"(")}else if(!n){i.push("(")}var a;if(this[__cycles__]&&this[__cycles__].car){a=this[__cycles__].car}else{a=toString(this.car,e,true)}if(a!==undefined$1){i.push(a)}if(this.cdr instanceof Pair){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(this.cdr!==_nil){i=i.concat([" . ",toString(this.cdr,e,true)])}if(!n||this[__ref__]){i.push(")")}return i.join("")};Pair.prototype.set=function(e,r){this[e]=r;if(r instanceof Pair){this.markCycles()}};Pair.prototype.append=function(e){if(e instanceof Array){return this.append(Pair.fromArray(e))}var r=this;if(r.car===undefined$1){if(e instanceof Pair){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(e!==_nil){while(true){if(r instanceof Pair&&r.cdr!==_nil){r=r.cdr}else{break}}r.cdr=e}return this};Pair.prototype.serialize=function(){return[this.car,this.cdr]};function abs(e){return e<0?-e:e}function seq_compare(e,r){var t=_toArray(r),n=t[0],i=t.slice(1);while(i.length>0){var a=i,o=_slicedToArray(a,1),u=o[0];if(!e(n,u)){return false}var c=i;var s=_toArray(c);n=s[0];i=s.slice(1)}return true}function equal(e,r){if(is_function(e)){return is_function(r)&&unbind(e)===unbind(r)}else if(e instanceof LNumber){if(!(r instanceof LNumber)){return false}var t;if(e.__type__===r.__type__){if(e.__type__==="complex"){t=e.__im__.__type__===r.__im__.__type__&&e.__re__.__type__===r.__re__.__type__}else{t=true}if(t&&e.cmp(r)===0){if(e.valueOf()===0){return Object.is(e.valueOf(),r.valueOf())}return true}}return false}else if(typeof e==="number"){if(typeof r!=="number"){return false}if(Number.isNaN(e)){return Number.isNaN(r)}if(e===Number.NEGATIVE_INFINITY){return r===Number.NEGATIVE_INFINITY}if(e===Number.POSITIVE_INFINITY){return r===Number.POSITIVE_INFINITY}return equal(LNumber(e),LNumber(r))}else if(e instanceof LCharacter){if(!(r instanceof LCharacter)){return false}return e.__char__===r.__char__}else{return e===r}}function same_atom(e,r){if(type(e)!==type(r)){return false}if(!is_atom(e)){return false}if(e instanceof RegExp){return e.source===r.source}if(e instanceof LString){return e.valueOf()===r.valueOf()}return equal(e,r)}function is_atom(e){return e instanceof LSymbol||LString.isString(e)||e===_nil||e===null||e instanceof LCharacter||e instanceof LNumber||e===true||e===false}var truncate=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e===0){return 0}else if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function Macro(e,r,t,n){if(typeof this!=="undefined"&&this.constructor!==Macro||typeof this==="undefined"){return new Macro(e,r)}typecheck("Macro",e,"string",1);typecheck("Macro",r,"function",2);if(t){if(n){this.__doc__=t}else{this.__doc__=trim_lines(t)}}this.__name__=e;this.__fn__=r}Macro.defmacro=function(e,r,t,n){var i=new Macro(e,r,t,n);i.__defmacro__=true;return i};Macro.prototype.invoke=function(e,r,t){var n=r.env,i=r.dynamic_scope,a=r.error;var o={dynamic_scope:i,error:a,macro_expand:t};var u=this.__fn__.call(n,e,o,this.__name__);return u};Macro.prototype.toString=function(){return"#")};var macro="define-macro";var recur_guard=-1e4;function macro_expand(s){return function(){var t=_asyncToGenerator(regenerator.mark(function e(t,y){var a,b,n,i,o,g,w,D,x,L,F,E,u,A,c;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:c=function e(){c=_asyncToGenerator(regenerator.mark(function e(t,n,i){var a,o,u,c,s,l,f,_,p,h,d,m,v;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!(t instanceof Pair&&t.car instanceof LSymbol)){r.next=50;break}if(!t[__data__]){r.next=3;break}return r.abrupt("return",t);case 3:a=t.car.valueOf();o=i.get(t.car,{throwError:false});u=g(t.car);c=u||w(o,t)||D(o);if(!(c&&t.cdr.car instanceof Pair)){r.next=28;break}if(!u){r.next=15;break}b=L(t.cdr.car);r.next=12;return E(t.cdr.car,n);case 12:s=r.sent;r.next=17;break;case 15:b=x(t.cdr.car);s=t.cdr.car;case 17:r.t0=Pair;r.t1=t.car;r.t2=Pair;r.t3=s;r.next=23;return A(t.cdr.cdr,n,i);case 23:r.t4=r.sent;r.t5=new r.t2(r.t3,r.t4);return r.abrupt("return",new r.t0(r.t1,r.t5));case 28:if(!F(a,o)){r.next=50;break}l=o instanceof Syntax?t:t.cdr;r.next=32;return o.invoke(l,_objectSpread(_objectSpread({},y),{},{env:i}),true);case 32:f=r.sent;if(!(o instanceof Syntax)){r.next=41;break}_=f,p=_.expr,h=_.scope;if(!(p instanceof Pair)){r.next=40;break}if(!(n!==-1&&n<=1||n")}return"#"};Syntax.className="syntax";function extract_patterns(e,r,w,D){var t=arguments.length>4&&arguments[4]!==undefined$1?arguments[4]:{};var x={"...":{symbols:{},lists:[]},symbols:{}};var L=t.expansion,F=t.define;function E(e){if(is_debug()){console.log(e)}}E(w);function A(e,r){var t=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:[];var n=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:false;E({code:r&&toString(r,true),pattern:e&&toString(e,true)});if(is_atom(e)&&!(e instanceof LSymbol)){return same_atom(e,r)}if(e instanceof LSymbol&&w.includes(e.valueOf())){var i=L.ref(r);if(LSymbol.is(r,e)){if(typeof i==="undefined"){return true}return i===F||i===global_env}return false}if(e instanceof Pair&&e.car instanceof Pair&&e.car.cdr instanceof Pair&&LSymbol.is(e.car.cdr.car,D)){E(">> 0");if(r===_nil){E({pattern:e.toString()});if(e.car.car instanceof LSymbol){if(e.car.cdr instanceof Pair&&LSymbol.is(e.car.cdr.car,D)){var a=e.car.car.valueOf();var o=e.last_pair();if(LSymbol.is(o.car,D)){x["..."].symbols[a]=null;return true}else{return false}}var u=e.car.car.valueOf();if(x["..."].symbols[u]){throw new Error("syntax: named ellipsis can only "+"appear onces")}x["..."].symbols[u]=r}}}if(e instanceof Pair&&e.cdr instanceof Pair&&LSymbol.is(e.cdr.car,D)){if(e.cdr.cdr!==_nil){if(e.cdr.cdr instanceof Pair){var c=e.cdr.cdr.length();var s=r.length();var l=r;while(s-1>c){l=l.cdr;s--}var f=l.cdr;l.cdr=_nil;if(!A(e.cdr.cdr,f,t,n)){return false}}}if(e.car instanceof LSymbol){var _=e.car.__name__;if(x["..."].symbols[_]&&!t.includes(_)&&!n){throw new Error("syntax: named ellipsis can only appear onces")}E(">> 1");if(r===_nil){E(">> 2");if(n){E("NIL");x["..."].symbols[_]=_nil}else{E("NULL");x["..."].symbols[_]=null}}else if(r instanceof Pair&&(r.car instanceof Pair||r.car===_nil)){E(">> 3 "+n);if(n){if(x["..."].symbols[_]){var p=x["..."].symbols[_];if(p===_nil){p=new Pair(_nil,new Pair(r,_nil))}else{p=p.append(new Pair(r,_nil))}x["..."].symbols[_]=p}else{x["..."].symbols[_]=new Pair(r,_nil)}}else{E(">> 4");x["..."].symbols[_]=new Pair(r,_nil)}}else{E(">> 6");if(r instanceof Pair){E(">> 7 "+n);t.push(_);if(!x["..."].symbols[_]){x["..."].symbols[_]=new Pair(r,_nil)}else{var h=x["..."].symbols[_];x["..."].symbols[_]=h.append(new Pair(r,_nil))}E({IIIIII:x["..."].symbols[_].toString()})}else{E(">> 8");return false}}return true}else if(e.car instanceof Pair){var d=_toConsumableArray(t);if(r===_nil){E(">> 9");x["..."].lists.push(_nil);return true}E(">> 10");var m=r;while(m instanceof Pair){if(!A(e.car,m.car,d,true)){return false}m=m.cdr}return true}return false}if(e instanceof LSymbol){if(LSymbol.is(e,D)){throw new Error("syntax: invalid usage of ellipsis")}E(">> 11");var v=e.__name__;if(w.includes(v)){return true}E({name:v,ellipsis:n});if(n){x["..."].symbols[v]=x["..."].symbols[v]||[];x["..."].symbols[v].push(r)}x.symbols[v]=r;if(!x.symbols[v]);return true}if(e instanceof Pair&&r instanceof Pair){E(">> 12");E({a:12,code:r&&r.toString(),pattern:e.toString()});if(r.cdr===_nil){var y=e.car instanceof LSymbol&&e.cdr instanceof LSymbol;if(y){if(!A(e.car,r.car,t,n)){return false}E(">> 12 | 1");var b=e.cdr.valueOf();if(!(b in x.symbols)){x.symbols[b]=_nil}b=e.car.valueOf();if(!(b in x.symbols)){x.symbols[b]=r.car}return true}}E({pattern:e.toString(),code:r.toString()});if(e.cdr instanceof Pair&&e.car instanceof LSymbol&&e.cdr.cdr instanceof Pair&&e.cdr.car instanceof LSymbol&&LSymbol.is(e.cdr.cdr.car,D)&&e.cdr.cdr.cdr instanceof Pair&&!LSymbol.is(e.cdr.cdr.cdr.car,D)&&A(e.car,r.car,t,n)&&A(e.cdr.cdr.cdr,r.cdr,t,n)){var g=e.cdr.car.__name__;E({pattern:e.car.toString(),code:r.car.toString(),name:g});if(w.includes(g)){return true}x["..."].symbols[g]=null;return true}E("recur");if(A(e.car,r.car,t,n)&&A(e.cdr,r.cdr,t,n)){return true}}else if(e===_nil&&(r===_nil||r===undefined$1)){return true}else if(e.car instanceof Pair&&LSymbol.is(e.car.car,D)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(A(e,r)){return x}}function clear_gensyms(e,i){function a(r){if(r instanceof Pair){if(!i.length){return r}var e=a(r.car);var t=a(r.cdr);return new Pair(e,t)}else if(r instanceof LSymbol){var n=i.find(function(e){return e.gensym===r});if(n){return LSymbol(n.name)}return r}else{return r}}return a(e)}function transform_syntax(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:{};var E=e.bindings,r=e.expr,A=e.scope,o=e.symbols,a=e.names,C=e.ellipsis;var u={};function c(e){if(e instanceof LSymbol){return true}return["string","symbol"].includes(_typeof(e))}function S(e){if(!c(e)){var r=type(e);throw new Error("syntax: internal error, need symbol got ".concat(r))}var t=e.valueOf();if(t===C){throw new Error("syntax: internal error, ellipis not transformed")}var n=_typeof(t);if(["string","symbol"].includes(n)){if(t in E.symbols){return E.symbols[t]}else if(n==="string"&&t.match(/\./)){var i=t.split(".");var a=i[0];if(a in E.symbols){return Pair.fromArray([LSymbol("."),E.symbols[a]].concat(i.slice(1).map(function(e){return LString(e)})))}}}if(o.includes(t)){return LSymbol(t)}return s(t)}function P(e){if(is_debug()){console.log(e)}}function s(e){if(!u[e]){var r=A.ref(e);var t=gensym(e);if(r){var n=A.get(e);A.set(t,n)}else{var i=A.get(e,{throwError:false});if(typeof i!=="undefined"){A.set(t,i)}}a.push({name:e,gensym:t});u[e]=t}return u[e]}function k(e,r,t){var n=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:function(){};var i=t.nested;P(" ==> "+e.toString(true));P(r);if(e instanceof LSymbol){var a=e.valueOf();P("[t 1");if(r[a]){if(r[a]instanceof Pair){var o=r[a],u=o.car,c=o.cdr;if(i){var s=u.car,l=u.cdr;if(l!==_nil){n(a,new Pair(l,_nil))}return s}if(c!==_nil){n(a,c)}return u}else if(r[a]instanceof Array){n(a,r[a].slice(1));return r[a][0]}}return S(a)}if(e instanceof Pair){if(e.car instanceof LSymbol&&e.cdr instanceof Pair&&LSymbol.is(e.cdr.car,C)){P("[t 2");var f=e.car.valueOf();var _=r[f];P({expr:e.toString(true),name:f,bindings:r,item:_});if(_===null){return}else if(_){P({b:r[f].toString()});if(_ instanceof Pair){P("[t 2 Pair "+i);P({______:_.toString()});var p=_.car,h=_.cdr;if(i){if(h!==_nil){P("|| next 1");n(f,h)}P({car:p.toString()});return p}else{if(p.cdr!==_nil){P("|| next 2");n(f,new Pair(p.cdr,h))}P({car:p.car.toString()});return p.car}}else if(_ instanceof Array){P("[t 2 Array "+i);if(i){n(f,_.slice(1));return Pair.fromArray(_)}else{var d=_.slice(1);if(d.length){n(f,d)}return _[0]}}else{return _}}}P("[t 3 recur "+e.toString());var m=k(e.car,r,t,n);var v=k(e.cdr,r,t,n);return new Pair(m,v)}return e}function N(r,t){var e=Object.values(r);var n=Object.getOwnPropertySymbols(r);if(n.length){e.push.apply(e,_toConsumableArray(n.map(function(e){return r[e]})))}return e.length&&e.every(function(e){if(e===null){return!t}return e instanceof Pair||e===_nil||e instanceof Array&&e.length})}function O(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function B(i){var e=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},r=e.disabled;P("traverse>> "+i.toString());if(i instanceof Pair){if(!r&&i.car instanceof Pair&&LSymbol.is(i.car.car,C)){return B(i.car.cdr,{disabled:true})}if(i.cdr instanceof Pair&&LSymbol.is(i.cdr.car,C)&&!r){P(">> 1");var t=E["..."].symbols;var n=Object.values(t);if(n.length&&n.every(function(e){return e===null})){return B(i.cdr.cdr,{disabled:r})}var a=O(t);var o=i.car instanceof LSymbol&&LSymbol.is(i.cdr.cdr.car,C);if(i.car instanceof Pair||o){if(E["..."].lists[0]===_nil){return _nil}var u=i.car;if(o){u=new Pair(i.car,new Pair(i.cdr.car,_nil))}P(">> 2");var c;if(a.length){P(">> 2 (a)");var s=_objectSpread({},t);c=_nil;var l=function e(){if(!N(s)){return"break"}var n={};var r=function e(r,t){n[r]=t};var t=k(u,s,{nested:true},r);if(t!==undefined$1){if(o){if(c===_nil){c=t}else{c=c.append(t)}}else{c=new Pair(t,c)}}s=n};while(true){var f=l();if(f==="break")break}if(c!==_nil&&!o){c=c.reverse()}if(i.cdr.cdr!==_nil&&!LSymbol.is(i.cdr.cdr.car,C)){var _=B(i.cdr.cdr,{disabled:r});return c.append(_)}return c}else{P(">> 3");var p=k(i.car,t,{nested:true});if(p){return new Pair(p,_nil)}return _nil}}else if(i.car instanceof LSymbol){P(">> 4");if(LSymbol.is(i.cdr.cdr.car,C)){P(">> 4 (a)")}else{P(">> 4 (b)")}var h=i.car.__name__;var d=_defineProperty({},h,t[h]);var m=t[h]===null;var v=_nil;var y=function e(){if(!N(d,true)){P({bind:d});return"break"}var n={};var r=function e(r,t){n[r]=t};var t=k(i,d,{nested:false},r);P({value:t.toString()});if(typeof t!=="undefined"){v=new Pair(t,v)}d=n};while(true){var b=y();if(b==="break")break}if(v!==_nil){v=v.reverse()}if(i.cdr instanceof Pair){if(i.cdr.cdr instanceof Pair||i.cdr.cdr instanceof LSymbol){var g=B(i.cdr.cdr,{disabled:r});if(m){return g}P("<<<< 1");v.append(g)}}P("<<<< 2");return v}}var w=B(i.car,{disabled:r});var D;var x;if(i.car instanceof LSymbol){var L=A.get(i.car,{throwError:false});x=L instanceof Macro&&L.__name__==="syntax-rules"}if(x){if(i.cdr.car instanceof LSymbol){D=new Pair(B(i.cdr.car,{disabled:r}),new Pair(i.cdr.cdr.car,B(i.cdr.cdr.cdr,{disabled:r})))}else{D=new Pair(i.cdr.car,B(i.cdr.cdr,{disabled:r}))}}else{D=B(i.cdr,{disabled:r})}P({a:true,car:toString(i.car),cdr:toString(i.cdr),head:toString(w),rest:toString(D)});return new Pair(w,D)}if(i instanceof LSymbol){if(r&&LSymbol.is(i,C)){return i}var F=S(i);if(typeof F!=="undefined"){return F}}return i}return B(r,{})}function is_null(e){return is_undef(e)||e===_nil||e===null}function is_function(e){return typeof e==="function"&&typeof e.bind==="function"}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 box(e){switch(_typeof(e)){case"string":return LString(e);case"number":if(!Number.isNaN(e)){return LNumber(e)}}return e}function map_object(n,i){var e=Object.getOwnPropertyNames(n);var r=Object.getOwnPropertySymbols(n);e.concat(r).forEach(function(e){var r=i(n[e]);var t=Object.getOwnPropertyDescriptor(n,e);if(!t||t.writable&&n[e]!==r){n[e]=r}});return n}function unbox(r){var e=[LString,LCharacter,LNumber].some(function(e){return r instanceof e});if(e){return r.valueOf()}if(r instanceof Array){return r.map(unbox)}if(r instanceof QuotedPromise){delete r.then}if(is_plain_object(r)){return map_object(r,unbox)}return r}function patch_value(e,r){if(e instanceof Pair){e.markCycles();return quote(e)}if(is_function(e)){if(r){return bind(e,r)}}return box(e)}function unbind(e){if(is_bound(e)){return e[__fn__]}return e}function bind(e,r){if(e[Symbol["for"]("__bound__")]){return e}var t=e.bind(r);var n=Object.getOwnPropertyNames(e);var i=_createForOfIteratorHelper(n),a;try{for(i.s();!(a=i.n()).done;){var o=a.value;if(filter_fn_names(o)){try{t[o]=e[o]}catch(e){}}}}catch(e){i.e(e)}finally{i.f()}hidden_prop(t,"__fn__",e);hidden_prop(t,"__context__",r);hidden_prop(t,"__bound__",true);if(is_native_function(e)){hidden_prop(t,"__native__",true)}if(is_plain_object(r)&&is_lambda(e)){hidden_prop(t,"__method__",true)}t.valueOf=function(){return e};return t}function is_object_bound(e){return is_bound(e)&&e[Symbol["for"]("__context__")]===Object}function is_bound(e){return!!(is_function(e)&&e[__fn__])}function lips_context(e){if(is_function(e)){var r=e[__context__];if(r&&(r===lips||r.constructor&&r.constructor.__class__)){return true}}return false}function is_port(e){return e instanceof InputPort||e instanceof OutputPort}function is_port_method(e){if(is_function(e)){if(is_port(e[__context__])){return true}}return false}var __context__=Symbol["for"]("__context__");var __fn__=Symbol["for"]("__fn__");var __data__=Symbol["for"]("__data__");var __ref__=Symbol["for"]("__ref__");var __cycles__=Symbol["for"]("__cycles__");var __class__=Symbol["for"]("__class__");var __method__=Symbol["for"]("__method__");var __prototype__=Symbol["for"]("__prototype__");var __lambda__=Symbol["for"]("__lambda__");var exluded_names=["name","length","caller","callee","arguments","prototype"];function filter_fn_names(e){return!exluded_names.includes(e)}function hidden_prop(e,r,t){Object.defineProperty(e,Symbol["for"](r),{get:function e(){return t},set:function e(){},configurable:false,enumerable:false})}function set_fn_length(r,t){try{Object.defineProperty(r,"length",{get:function e(){return t}});return r}catch(e){var n=new Array(t).fill(0).map(function(e,r){return"a"+r}).join(",");var i=new Function("f","return function(".concat(n,") {\n return f.apply(this, arguments);\n };"));return i(r)}}function is_lambda(e){return e&&e[__lambda__]}function is_method(e){return e&&e[__method__]}function is_raw_lambda(e){return is_lambda(e)&&!e[__prototype__]&&!is_method(e)&&!is_port_method(e)}function is_native_function(e){var r=Symbol["for"]("__native__");return is_function(e)&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[r]===true||!e.name.match(/^bound /)&&!e[r])}function let_macro(e){var 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 Macro.defmacro(b,function(r,e){var l=e.dynamic_scope,f=e.error,t=e.macro_expand;var _;if(r.car instanceof LSymbol){if(!(r.cdr.car instanceof Pair||r.cdr.car===_nil)){throw new Error("let require list of pairs")}var n;if(r.cdr.car===_nil){_=_nil;n=_nil}else{n=r.cdr.car.map(function(e){return e.car});_=r.cdr.car.map(function(e){return e.cdr.car})}return Pair.fromArray([LSymbol("letrec"),[[r.car,Pair(LSymbol("lambda"),Pair(n,r.cdr.cdr))]],Pair(r.car,_)])}else if(t){return}var p=this;_=global_env.get("list->array")(r.car);var h=p.inherit(b);var d,m;if(b==="let*"){m=h}else if(b==="let"){d=[]}var v=0;function y(){var e=new Pair(new LSymbol("begin"),r.cdr);return _evaluate(e,{env:h,dynamic_scope:l,error:f})}return function r(){var t=_[v++];if(l){l=b==="let*"?h:p}if(!t){if(d&&d.length){var e=d.map(function(e){return e.value});var n=e.filter(is_promise);if(n.length){return promise_all(e).then(function(e){for(var r=0,t=e.length;r1&&arguments[1]!==undefined$1?arguments[1]:{},t=r.dynamic_scope,n=r.error;var i=this;if(t){t=this}var a=e;var o=[];while(a instanceof Pair){o.push(_evaluate(a.car,{env:i,dynamic_scope:t,error:n}));a=a.cdr}var u=o.filter(is_promise).length;if(u){return promise_all(o).then(c.bind(this))}else{return c.call(this,o)}})}function guard_math_call(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n2?n-2:0),a=2;a1&&arguments[1]!==undefined$1?arguments[1]:null;return function(){for(var e=arguments.length,r=new Array(e),t=0;t1?e-1:0),t=1;t=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,r=new Array(e),t=0;t1){e=e.toLowerCase();if(LCharacter.__names__[e]){r=e;e=LCharacter.__names__[e]}else{throw new Error("Internal: Unknown named character")}}else{r=LCharacter.__rev_names__[e]}Object.defineProperty(this,"__char__",{value:e,enumerable:true});if(r){Object.defineProperty(this,"__name__",{value:r,enumerable:true})}}LCharacter.__names__=characters;LCharacter.__rev_names__={};Object.keys(LCharacter.__names__).forEach(function(e){var r=LCharacter.__names__[e];LCharacter.__rev_names__[r]=e});LCharacter.prototype.toUpperCase=function(){return LCharacter(this.__char__.toUpperCase())};LCharacter.prototype.toLowerCase=function(){return LCharacter(this.__char__.toLowerCase())};LCharacter.prototype.toString=function(){return"#\\"+(this.__name__||this.__char__)};LCharacter.prototype.valueOf=LCharacter.prototype.serialize=function(){return this.__char__};function LString(e){if(typeof this!=="undefined"&&!(this instanceof LString)||typeof this==="undefined"){return new LString(e)}if(e instanceof Array){this.__string__=e.map(function(e,r){typecheck("LString",e,"character",r+1);return e.toString()}).join("")}else{this.__string__=e.valueOf()}}{var ignore=["length","constructor"];var _keys=Object.getOwnPropertyNames(String.prototype).filter(function(e){return!ignore.includes(e)});var wrap=function e(n){return function(){for(var e=arguments.length,r=new Array(e),t=0;t0){t.push(this.__string__.substring(0,e))}t.push(r);if(e1&&arguments[1]!==undefined$1?arguments[1]:false;if(e instanceof LNumber){return e}if(typeof this!=="undefined"&&!(this instanceof LNumber)||typeof this==="undefined"){return new LNumber(e,r)}if(typeof e==="undefined"){throw new Error("Invalid LNumber constructor call")}var t=LNumber.getType(e);if(LNumber.types[t]){return LNumber.types[t](e,r)}var n=e instanceof Array&&LString.isString(e[0])&&LNumber.isNumber(e[1]);if(e instanceof LNumber){return LNumber(e.value)}if(!LNumber.isNumber(e)&&!n){throw new Error("You can't create LNumber from ".concat(type(e)))}if(e===null){e=0}var i;if(n){var a=e,o=_slicedToArray(a,2),u=o[0],c=o[1];if(u instanceof LString){u=u.valueOf()}if(c instanceof LNumber){c=c.valueOf()}var s=u.match(/^([+-])/);var l=false;if(s){u=u.replace(/^[+-]/,"");if(s[1]==="-"){l=true}}}if(Number.isNaN(e)){return LFloat(e)}else if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(n){var f;switch(c){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(c);i=_toConsumableArray(u).map(function(e,r){return BigInt(parseInt(e,c))*Math.pow(_,BigInt(r))}).reduce(function(e,r){return e+r})}else{i=BigInt(f+u)}}else{i=BigInt(e)}if(l){i*=BigInt(-1)}}else{i=e}return LBigInteger(i,true)}else if(typeof BN!=="undefined"&&!(e instanceof BN)){if(e instanceof Array){return LBigInteger(_construct(BN,_toConsumableArray(e)))}return LBigInteger(new BN(e))}else if(n){this.constant(parseInt(u,c),"integer")}else{this.constant(e,"integer")}}LNumber.prototype.constant=function(e,r){Object.defineProperty(this,"__value__",{value:e,enumerable:true});Object.defineProperty(this,"__type__",{value:r,enumerable:true})};LNumber.types={float:function e(r){var t=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;return new LFloat(r,t)},complex:function e(r){var t=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;if(!LNumber.isComplex(r)){r={im:0,re:r}}return new LComplex(r,t)},rational:function e(r){var t=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;if(!LNumber.isRational(r)){r={num:r,denom:1}}return new LRational(r,t)}};LNumber.prototype.serialize=function(){return this.__value__};LNumber.prototype.isNaN=function(){return Number.isNaN(this.__value__)};LNumber.prototype.gcd=function(e){var r=this.abs();e=e.abs();if(e.cmp(r)===1){var t=r;r=e;e=t}while(true){r=r.rem(e);if(r.cmp(0)===0){return e}e=e.rem(r);if(e.cmp(0)===0){return r}}};LNumber.isFloat=function e(r){return r instanceof LFloat||Number(r)===r&&r%1!==0};LNumber.isNumber=function(e){return e instanceof LNumber||LNumber.isNative(e)||LNumber.isBN(e)};LNumber.isComplex=function(e){if(!e){return false}var r=e instanceof LComplex||(LNumber.isNumber(e.im)||Number.isNaN(e.im))&&(LNumber.isNumber(e.re)||Number.isNaN(e.re));return r};LNumber.isRational=function(e){if(!e){return false}return e instanceof LRational||LNumber.isNumber(e.num)&&LNumber.isNumber(e.denom)};LNumber.isInteger=function(e){if(!(LNumber.isNative(e)||e instanceof LNumber)){return false}if(LNumber.isFloat(e)){return false}if(LNumber.isRational(e)){return false}if(LNumber.isComplex(e)){return false}return true};LNumber.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};LNumber.isBigInteger=function(e){return e instanceof LBigInteger||typeof e==="bigint"||LNumber.isBN(e)};LNumber.isBN=function(e){return typeof BN!=="undefined"&&e instanceof BN};LNumber.getArgsType=function(e,r){if(e instanceof LFloat||r instanceof LFloat){return LFloat}if(e instanceof LBigInteger||r instanceof LBigInteger){return LBigInteger}return LNumber};LNumber.prototype.toString=function(e){if(Number.isNaN(this.__value__)){return"+nan.0"}if(e>2&&e<36){return this.__value__.toString(e)}return this.__value__.toString()};LNumber.prototype.asType=function(e){var r=LNumber.getType(this);return LNumber.types[r]?LNumber.types[r](e):LNumber(e)};LNumber.prototype.isBigNumber=function(){return typeof this.__value__==="bigint"||typeof BN!=="undefined"&&!(this.value instanceof BN)};["floor","ceil","round"].forEach(function(e){LNumber.prototype[e]=function(){if(this["float"]||LNumber.isFloat(this.__value__)){return LNumber(Math[e](this.__value__))}else{return LNumber(Math[e](this.valueOf()))}}});LNumber.prototype.valueOf=function(){if(LNumber.isNative(this.__value__)){return Number(this.__value__)}else if(LNumber.isBN(this.__value__)){return this.__value__.toNumber()}};var matrix=function(){var e=function e(r,t){return[r,t]};return{bigint:{bigint:e,float:function e(r,t){return[LFloat(r.valueOf()),t]},rational:function e(r,t){return[{num:r,denom:1},t]},complex:function e(r,t){return[{im:0,re:r},t]}},integer:{integer:e,float:function e(r,t){return[LFloat(r.valueOf()),t]},rational:function e(r,t){return[{num:r,denom:1},t]},complex:function e(r,t){return[{im:0,re:r},t]}},float:{bigint:function e(r,t){return[r,t&&LFloat(t.valueOf())]},integer:function e(r,t){return[r,t&&LFloat(t.valueOf())]},float:e,rational:function e(r,t){return[r,t&&LFloat(t.valueOf())]},complex:function e(r,t){return[{re:r,im:LFloat(0)},t]}},complex:{bigint:r("bigint"),integer:r("integer"),float:r("float"),rational:r("rational"),complex:function e(r,t){var n=LNumber.coerce(r.__re__,t.__re__),i=_slicedToArray(n,2),a=i[0],o=i[1];var u=LNumber.coerce(r.__im__,t.__im__),c=_slicedToArray(u,2),s=c[0],l=c[1];return[{im:s,re:a},{im:l,re:o}]}},rational:{bigint:function e(r,t){return[r,t&&{num:t,denom:1}]},integer:function e(r,t){return[r,t&&{num:t,denom:1}]},float:function e(r,t){return[LFloat(r.valueOf()),t]},rational:e,complex:function e(r,t){return[{im:coerce(r.__type__,t.__im__.__type__,0)[0],re:coerce(r.__type__,t.__re__.__type__,r)[0]},{im:coerce(r.__type__,t.__im__.__type__,t.__im__)[0],re:coerce(r.__type__,t.__re__.__type__,t.__re__)[0]}]}}};function r(t){return function(e,r){return[{im:coerce(t,e.__im__.__type__,0,e.__im__)[1],re:coerce(t,e.__re__.__type__,0,e.__re__)[1]},{im:coerce(t,e.__im__.__type__,0,0)[1],re:coerce(t,r.__type__,0,r)[1]}]}}}();function coerce(e,r,t,n){return matrix[e][r](t,n)}LNumber.coerce=function(e,r){var t=LNumber.getType(e);var n=LNumber.getType(r);if(!matrix[t]){throw new Error("LNumber::coerce unknown lhs type ".concat(t))}else if(!matrix[t][n]){throw new Error("LNumber::coerce unknown rhs type ".concat(n))}var i=matrix[t][n](e,r);return i.map(function(e){return LNumber(e,true)})};LNumber.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof LNumber)){throw new Error("LNumber: you can't coerce ".concat(type(e)))}if(typeof e==="number"){e=LNumber(e)}return LNumber.coerce(this,e)};LNumber.getType=function(e){if(e instanceof LNumber){return e.__type__}if(LNumber.isFloat(e)){return"float"}if(LNumber.isComplex(e)){return"complex"}if(LNumber.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof BN!=="undefined"&&!(e instanceof BN)){return"bigint"}};LNumber.prototype.isFloat=function(){return!!(LNumber.isFloat(this.__value__)||this["float"])};var mapping={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var rev_mapping={};Object.keys(mapping).forEach(function(r){rev_mapping[mapping[r]]=r;LNumber.prototype[r]=function(e){return this.op(mapping[r],e)}});LNumber._ops={"*":function e(r,t){return r*t},"+":function e(r,t){return r+t},"-":function e(r,t){if(typeof t==="undefined"){return-r}return r-t},"/":function e(r,t){return r/t},"%":function e(r,t){return r%t},"|":function e(r,t){return r|t},"&":function e(r,t){return r&t},"~":function e(r){return~r},">>":function e(r,t){return r>>t},"<<":function e(r,t){return r<1&&arguments[1]!==undefined$1?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof LComplex)||typeof this==="undefined"){return new LComplex(e,r)}if(e instanceof LComplex){return LComplex({im:e.__im__,re:e.__re__})}if(LNumber.isNumber(e)&&r){if(!r){return Number(e)}}else if(!LNumber.isComplex(e)){throw new Error("Invalid constructor call for LComplex")}var t=e.im instanceof LNumber?e.im:LNumber(e.im);var n=e.re instanceof LNumber?e.re:LNumber(e.re);this.constant(t,n)}LComplex.prototype=Object.create(LNumber.prototype);LComplex.prototype.constructor=LComplex;LComplex.prototype.constant=function(e,r){Object.defineProperty(this,"__im__",{value:e,enumerable:true});Object.defineProperty(this,"__re__",{value:r,enumerable:true});Object.defineProperty(this,"__type__",{value:"complex",enumerable:true})};LComplex.prototype.serialize=function(){return{re:this.__re__,im:this.__im__}};LComplex.prototype.toRational=function(e){if(LNumber.isFloat(this.__im__)&&LNumber.isFloat(this.__re__)){var r=LFloat(this.__im__).toRational(e);var t=LFloat(this.__re__).toRational(e);return LComplex({im:r,re:t})}return this};LComplex.prototype.add=function(e){return this.complex_op("add",e,function(e,r,t,n){return{re:e.add(r),im:t.add(n)}})};LComplex.prototype.factor=function(){if(this.__im__ instanceof LFloat||this.__im__ instanceof LFloat){var e=this.__re__,r=this.__im__;var t,n;if(e instanceof LFloat){t=e.toRational().mul(e.toRational())}else{t=e.mul(e)}if(r instanceof LFloat){n=r.toRational().mul(r.toRational())}else{n=r.mul(r)}return t.add(n)}else{return this.__re__.mul(this.__re__).add(this.__im__.mul(this.__im__))}};LComplex.prototype.modulus=function(){return this.factor().sqrt()};LComplex.prototype.conjugate=function(){return LComplex({re:this.__re__,im:this.__im__.sub()})};LComplex.prototype.sqrt=function(){var e=this.modulus();var r,t;if(e.cmp(0)===0){r=t=e}else if(this.__re__.cmp(0)===1){r=LFloat(.5).mul(e.add(this.__re__)).sqrt();t=this.__im__.div(r).div(2)}else{t=LFloat(.5).mul(e.sub(this.__re__)).sqrt();if(this.__im__.cmp(0)===-1){t=t.sub()}r=this.__im__.div(t).div(2)}return LComplex({im:t,re:r})};LComplex.prototype.div=function(e){if(LNumber.isNumber(e)&&!LNumber.isComplex(e)){if(!(e instanceof LNumber)){e=LNumber(e)}var r=this.__re__.div(e);var t=this.__im__.div(e);return LComplex({re:r,im:t})}else if(!LNumber.isComplex(e)){throw new Error("[LComplex::div] Invalid value")}var n=this.coerce(e),i=_slicedToArray(n,2),a=i[0],o=i[1];var u=o.factor();var c=a.mul(o.conjugate());var s=c.__re__.op("/",u);var l=c.__im__.op("/",u);return LComplex({re:s,im:l})};LComplex.prototype.sub=function(e){return this.complex_op("sub",e,function(e,r,t,n){return{re:e.sub(r),im:t.sub(n)}})};LComplex.prototype.mul=function(e){return this.complex_op("mul",e,function(e,r,t,n){var i={re:e.mul(r).sub(t.mul(n)),im:e.mul(n).add(r.mul(t))};return i})};LComplex.prototype.complex_op=function(e,r,i){var a=this;var t=function e(r,t){var n=i(a.__re__,r,a.__im__,t);if("im"in n&&"re"in n){if(n.im.cmp(0)===0&&!LNumber.isFloat(n.im)){return n.re}return LComplex(n,true)}return n};if(typeof r==="undefined"){return t()}if(LNumber.isNumber(r)&&!LNumber.isComplex(r)){if(!(r instanceof LNumber)){r=LNumber(r)}var n=r.asType(0);r={__im__:n,__re__:r}}else if(!LNumber.isComplex(r)){throw new Error("[LComplex::".concat(e,"] Invalid value"))}var o=r.__re__ instanceof LNumber?r.__re__:this.__re__.asType(r.__re__);var u=r.__im__ instanceof LNumber?r.__im__:this.__im__.asType(r.__im__);return t(o,u)};LComplex._op={"+":"add","-":"sub","*":"mul","/":"div"};LComplex.prototype._op=function(e,r){var t=LComplex._op[e];return this[t](r)};LComplex.prototype.cmp=function(e){var r=this.coerce(e),t=_slicedToArray(r,2),n=t[0],i=t[1];var a=n.__re__.coerce(i.__re__),o=_slicedToArray(a,2),u=o[0],c=o[1];var s=u.cmp(c);if(s!==0){return s}else{var l=n.__im__.coerce(i.__im__),f=_slicedToArray(l,2),_=f[0],p=f[1];return _.cmp(p)}};LComplex.prototype.valueOf=function(){return[this.__re__,this.__im__].map(function(e){return e.valueOf()})};LComplex.prototype.toString=function(){var e;if(this.__re__.cmp(0)!==0){e=[toString(this.__re__)]}else{e=[]}var r=this.__im__.valueOf();var t=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY].includes(r);var n=toString(this.__im__);if(!t&&!Number.isNaN(r)){var i=this.__im__.cmp(0);if(i<0||i===0&&this.__im__._minus){e.push("-")}else{e.push("+")}n=n.replace(/^-/,"")}e.push(n);e.push("i");return e.join("")};function LFloat(e){if(typeof this!=="undefined"&&!(this instanceof LFloat)||typeof this==="undefined"){return new LFloat(e)}if(!LNumber.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof LNumber){return LFloat(e.valueOf())}if(typeof e==="number"){if(Object.is(e,-0)){Object.defineProperty(this,"_minus",{value:true})}this.constant(e,"float")}}LFloat.prototype=Object.create(LNumber.prototype);LFloat.prototype.constructor=LFloat;LFloat.prototype.toString=function(){if(this.__value__===Number.NEGATIVE_INFINITY){return"-inf.0"}if(this.__value__===Number.POSITIVE_INFINITY){return"+inf.0"}if(Number.isNaN(this.__value__)){return"+nan.0"}var e=this.__value__.toString();if(!LNumber.isFloat(this.__value__)&&!e.match(/e/i)){var r=e+".0";return this._minus?"-"+r:r}return e.replace(/^([0-9]+)e/,"$1.0e")};LFloat.prototype._op=function(e,r){if(r instanceof LNumber){r=r.__value__}var t=LNumber._ops[e];if(e==="/"&&this.__value__===0&&r===0){return NaN}return LFloat(t(this.__value__,r))};LFloat.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:null;if(e===null){return toRational(this.__value__.valueOf())}return approxRatio(e.valueOf())(this.__value__.valueOf())};var toRational=approxRatio(1e-10);function approxRatio(n){return function(e){var r=function e(n,r,t){var i=function e(r,t){return t0){i=simplest_rational2(n,t)}else if(n.cmp(t)<=0){i=t}else if(t.cmp(0)>0){i=simplest_rational2(t,n)}else if(r.cmp(0)<0){i=LNumber(simplest_rational2(n.sub(),t.sub())).sub()}else{i=LNumber(0)}if(LNumber.isFloat(r)||LNumber.isFloat(e)){return LFloat(i)}return i}function simplest_rational2(e,r){var t=LNumber(e).floor();var n=LNumber(r).floor();if(e.cmp(t)<1){return t}else if(t.cmp(n)===0){var i=LNumber(1).div(r.sub(n));var a=LNumber(1).div(e.sub(t));return t.add(LNumber(1).div(simplest_rational2(i,a)))}else{return t.add(LNumber(1))}}function LRational(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof LRational)||typeof this==="undefined"){return new LRational(e,r)}if(!LNumber.isRational(e)){throw new Error("Invalid constructor call for LRational")}var t,n;if(e instanceof LRational){t=LNumber(e.__num__);n=LNumber(e.__denom__)}else{t=LNumber(e.num);n=LNumber(e.denom)}if(!r&&n.cmp(0)!==0){var i=t.op("%",n).cmp(0)===0;if(i){return LNumber(t.div(n))}}this.constant(t,n)}LRational.prototype=Object.create(LNumber.prototype);LRational.prototype.constructor=LRational;LRational.prototype.constant=function(e,r){Object.defineProperty(this,"__num__",{value:e,enumerable:true});Object.defineProperty(this,"__denom__",{value:r,enumerable:true});Object.defineProperty(this,"__type__",{value:"rational",enumerable:true})};LRational.prototype.serialize=function(){return{num:this.__num__,denom:this.__denom__}};LRational.prototype.pow=function(e){var r=e.cmp(0);if(r===0){return LNumber(1)}if(r===-1){e=e.sub();var t=this.__denom__.pow(e);var n=this.__num__.pow(e);return LRational({num:t,denom:n})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};LRational.prototype.sqrt=function(){var e=this.__num__.sqrt();var r=this.__denom__.sqrt();if(e instanceof LFloat){e.toRational(),_readOnlyError("num")}if(r instanceof LFloat){r.toRational(),_readOnlyError("denom")}return LRational({num:e,denom:r})};LRational.prototype.abs=function(){var e=this.__num__;var r=this.__denom__;if(e.cmp(0)===-1){e=e.sub()}if(r.cmp(0)!==1){r=r.sub()}return LRational({num:e,denom:r})};LRational.prototype.cmp=function(e){return LNumber(this.valueOf(),true).cmp(e)};LRational.prototype.toString=function(){var e=this.__num__.gcd(this.__denom__);var r,t;if(e.cmp(1)!==0){r=this.__num__.div(e);if(r instanceof LRational){r=LNumber(r.valueOf(true))}t=this.__denom__.div(e);if(t instanceof LRational){t=LNumber(t.valueOf(true))}}else{r=this.__num__;t=this.__denom__}var n=this.cmp(0)<0;if(n){if(r.abs().cmp(t.abs())===0){return r.toString()}}else if(r.cmp(t)===0){return r.toString()}return r.toString()+"/"+t.toString()};LRational.prototype.valueOf=function(e){if(this.__denom__.cmp(0)===0){if(this.__num__.cmp(0)<0){return Number.NEGATIVE_INFINITY}return Number.POSITIVE_INFINITY}if(e){return LNumber._ops["/"](this.__num__.value,this.__denom__.value)}return LFloat(this.__num__.valueOf()).div(this.__denom__.valueOf())};LRational.prototype.mul=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=this.__num__.mul(e.__num__);var t=this.__denom__.mul(e.__denom__);return LRational({num:r,denom:t})}var n=LNumber.coerce(this,e),i=_slicedToArray(n,2),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 r=this.__num__.mul(e.__denom__);var t=this.__denom__.mul(e.__num__);return LRational({num:r,denom:t})}var n=LNumber.coerce(this,e),i=_slicedToArray(n,2),a=i[0],o=i[1];var u=a.div(o);return u};LRational.prototype._op=function(e,r){return this[rev_mapping[e]](r)};LRational.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=e.__num__.sub();var t=e.__denom__;return this.add(LRational({num:r,denom:t}))}if(!(e instanceof LNumber)){e=LNumber(e).sub()}else{e=e.sub()}var n=LNumber.coerce(this,e),i=_slicedToArray(n,2),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 r=this.__denom__;var t=e.__denom__;var n=this.__num__;var i=e.__num__;var a,o;if(r!==t){o=t.mul(n).add(i.mul(r));a=r.mul(t)}else{o=n.add(i);a=r}return LRational({num:o,denom:a})}if(LNumber.isFloat(e)){return LFloat(this.valueOf()).add(e)}var u=LNumber.coerce(this,e),c=_slicedToArray(u,2),s=c[0],l=c[1];return s.add(l)};function LBigInteger(e,r){if(typeof this!=="undefined"&&!(this instanceof LBigInteger)||typeof this==="undefined"){return new LBigInteger(e,r)}if(e instanceof LBigInteger){return LBigInteger(e.__value__,e._native)}if(!LNumber.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.constant(e,"bigint");Object.defineProperty(this,"_native",{value:r})}LBigInteger.prototype=Object.create(LNumber.prototype);LBigInteger.prototype.constructor=LBigInteger;LBigInteger.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};LBigInteger.prototype.serialize=function(){return this.__value__.toString()};LBigInteger.prototype._op=function(e,r){if(typeof r==="undefined"){if(LNumber.isBN(this.__value__)){e=LBigInteger.bn_op[e];return LBigInteger(this.__value__.clone()[e](),false)}return LBigInteger(LNumber._ops[e](this.__value__),true)}if(LNumber.isBN(this.__value__)&&LNumber.isBN(r.__value__)){e=LBigInteger.bn_op[e];return LBigInteger(this.__value__.clone()[e](r),false)}var t=LNumber._ops[e](this.__value__,r.__value__);if(e==="/"){var n=this.op("%",r).cmp(0)===0;if(n){return LNumber(t)}return LRational({num:this,denom:r})}return LBigInteger(t,true)};LBigInteger.prototype.sqrt=function(){var e;var r=this.cmp(0)<0;if(LNumber.isNative(this.__value__)){e=LNumber(Math.sqrt(r?-this.valueOf():this.valueOf()))}else if(LNumber.isBN(this.__value__)){e=r?this.__value__.neg().sqrt():this.__value__.sqrt()}if(r){return LComplex({re:0,im:e})}return e};LNumber.NaN=LNumber(NaN);function InputPort(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof InputPort)||typeof this==="undefined"){return new InputPort(e)}typecheck("InputPort",e,"function");read_only(this,"__type__",text_port);var i;Object.defineProperty(this,"__parser__",{enumerable:true,get:function e(){return i},set:function e(r){typecheck("InputPort::__parser__",r,"parser");i=r}});this._read=e;this._with_parser=this._with_init_parser.bind(this,_asyncToGenerator(regenerator.mark(function e(){var t;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(n.char_ready()){r.next=5;break}r.next=3;return n._read();case 3:t=r.sent;i=new Parser(t,{env:n});case 5:return r.abrupt("return",n.__parser__);case 6:case"end":return r.stop()}}},e)})));this.char_ready=function(){return!!this.__parser__&&this.__parser__.__lexer__.peek()!==eof};this._make_defaults()}InputPort.prototype._make_defaults=function(){this.read=this._with_parser(function(e){return e.read_object()});this.read_line=this._with_parser(function(e){return e.__lexer__.read_line()});this.read_char=this._with_parser(function(e){return e.__lexer__.read_char()});this.read_string=this._with_parser(function(e,r){if(!LNumber.isInteger(r)){var t=LNumber.getType(r);typeErrorMessage("read-string",t,"integer")}return e.__lexer__.read_string(r.valueOf())});this.peek_char=this._with_parser(function(e){return e.__lexer__.peek_char()})};InputPort.prototype._with_init_parser=function(u,c){var s=this;return function(){var e=_asyncToGenerator(regenerator.mark(function e(){var t,n,i,a,o=arguments;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:r.next=2;return u.call(s);case 2:t=r.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.toString=function(){return"#"};function OutputStringPort(r){var t=this;if(typeof this!=="undefined"&&!(this instanceof OutputStringPort)||typeof this==="undefined"){return new OutputStringPort(r)}typecheck("OutputStringPort",r,"function");read_only(this,"__type__",text_port);read_only(this,"__buffer__",[]);this.write=function(e){if(!LString.isString(e)){e=r(e)}else{e=e.valueOf()}t.__buffer__.push(e)}}OutputStringPort.prototype=Object.create(OutputPort.prototype);OutputStringPort.prototype.constructor=OutputStringPort;OutputStringPort.prototype.toString=function(){return"#"};OutputStringPort.prototype.valueOf=function(){return this.__buffer__.map(function(e){return e.valueOf()}).join("")};function OutputFilePort(e,r){var t=this;if(typeof this!=="undefined"&&!(this instanceof OutputFilePort)||typeof this==="undefined"){return new OutputFilePort(e,r)}typecheck("OutputFilePort",e,"string");read_only(this,"__filename__",e);read_only(this,"_fd",r.valueOf(),{hidden:true});read_only(this,"__type__",text_port);this.write=function(e){if(!LString.isString(e)){e=toString(e)}else{e=e.valueOf()}t.fs().write(t._fd,e,function(e){if(e){throw e}})}}OutputFilePort.prototype=Object.create(OutputPort.prototype);OutputFilePort.prototype.constructor=OutputFilePort;OutputFilePort.prototype.fs=function(){if(!this._fs){this._fs=this.internal("fs")}return this._fs};OutputFilePort.prototype.internal=function(e){return user_env.get("**internal-env**").get(e)};OutputFilePort.prototype.close=function(){var n=this;return new Promise(function(r,t){n.fs().close(n._fd,function(e){if(e){t(e)}else{read_only(n,"_fd",null,{hidden:true});OutputPort.prototype.close.call(n);r()}})})};OutputFilePort.prototype.toString=function(){return"#")};function InputStringPort(e,r){var t=this;if(typeof this!=="undefined"&&!(this instanceof InputStringPort)||typeof this==="undefined"){return new InputStringPort(e)}typecheck("InputStringPort",e,"string");r=r||global_env;e=e.valueOf();this._with_parser=this._with_init_parser.bind(this,function(){if(!t.__parser__){t.__parser__=new Parser(e,{env:r})}return t.__parser__});read_only(this,"__type__",text_port);this._make_defaults()}InputStringPort.prototype.char_ready=function(){return true};InputStringPort.prototype=Object.create(InputPort.prototype);InputStringPort.prototype.constructor=InputStringPort;InputStringPort.prototype.toString=function(){return"#"};function InputByteVectorPort(e){if(typeof this!=="undefined"&&!(this instanceof InputByteVectorPort)||typeof this==="undefined"){return new InputByteVectorPort(e)}typecheck("InputByteVectorPort",e,"uint8array");read_only(this,"__vector__",e);read_only(this,"__type__",binary_port);var t=0;Object.defineProperty(this,"__index__",{enumerable:true,get:function e(){return t},set:function e(r){typecheck("InputByteVectorPort::__index__",r,"number");if(r instanceof LNumber){r=r.valueOf()}if(typeof r==="bigint"){r=Number(r)}if(Math.floor(r)!==r){throw new Error("InputByteVectorPort::__index__ value is "+"not integer")}t=r}})}InputByteVectorPort.prototype=Object.create(InputPort.prototype);InputByteVectorPort.prototype.constructor=InputByteVectorPort;InputByteVectorPort.prototype.toString=function(){return"#"};InputByteVectorPort.prototype.close=function(){var r=this;read_only(this,"__vector__",_nil);["read_u8","close","peek_u8","read_u8_vector"].forEach(function(e){r[e]=function(){throw new Error("Input-binary-port: port is closed")}});this.char_ready=function(){return false}};InputByteVectorPort.prototype.u8_ready=function(){return true};InputByteVectorPort.prototype.peek_u8=function(){if(this.__index__>=this.__vector__.length){return eof}return this.__vector__[this.__index__]};InputByteVectorPort.prototype.skip=function(){if(this.__index__<=this.__vector__.length){++this.__index__}};InputByteVectorPort.prototype.read_u8=function(){var e=this.peek_u8();this.skip();return e};InputByteVectorPort.prototype.read_u8_vector=function(e){if(typeof e==="undefined"){e=this.__vector__.length}else if(e>this.__index__+this.__vector__.length){e=this.__index__+this.__vector__.length}if(this.peek_u8()===eof){return eof}return this.__vector__.slice(this.__index__,e)};function OutputByteVectorPort(){if(typeof this!=="undefined"&&!(this instanceof OutputByteVectorPort)||typeof this==="undefined"){return new OutputByteVectorPort}read_only(this,"__type__",binary_port);read_only(this,"_buffer",[],{hidden:true});this.write=function(e){typecheck("write",e,["number","uint8array"]);if(LNumber.isNumber(e)){this._buffer.push(e.valueOf())}else{var r;(r=this._buffer).push.apply(r,_toConsumableArray(Array.from(e)))}};Object.defineProperty(this,"__buffer__",{enumerable:true,get:function e(){return Uint8Array.from(this._buffer)}})}OutputByteVectorPort.prototype=Object.create(OutputPort.prototype);OutputByteVectorPort.prototype.constructor=OutputByteVectorPort;OutputByteVectorPort.prototype.close=function(){OutputPort.prototype.close.call(this);read_only(this,"_buffer",null,{hidden:true})};OutputByteVectorPort.prototype._close_guard=function(){if(this._closed){throw new Error("output-port: binary port is closed")}};OutputByteVectorPort.prototype.write_u8=function(e){typecheck("OutputByteVectorPort::write_u8",e,"number");this.write(e)};OutputByteVectorPort.prototype.write_u8_vector=function(e){typecheck("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};OutputByteVectorPort.prototype.toString=function(){return"#"};OutputByteVectorPort.prototype.valueOf=function(){return this.__buffer__};function InputFilePort(e,r){if(typeof this!=="undefined"&&!(this instanceof InputFilePort)||typeof this==="undefined"){return new InputFilePort(e,r)}InputStringPort.call(this,e);typecheck("InputFilePort",r,"string");read_only(this,"__filename__",r)}InputFilePort.prototype=Object.create(InputStringPort.prototype);InputFilePort.prototype.constructor=InputFilePort;InputFilePort.prototype.toString=function(){return"#")};function InputBinaryFilePort(e,r){if(typeof this!=="undefined"&&!(this instanceof InputBinaryFilePort)||typeof this==="undefined"){return new InputBinaryFilePort(e,r)}InputByteVectorPort.call(this,e);typecheck("InputBinaryFilePort",r,"string");read_only(this,"__filename__",r)}InputBinaryFilePort.prototype=Object.create(InputByteVectorPort.prototype);InputBinaryFilePort.prototype.constructor=InputBinaryFilePort;InputBinaryFilePort.prototype.toString=function(){return"#")};function OutputBinaryFilePort(e,r){if(typeof this!=="undefined"&&!(this instanceof OutputBinaryFilePort)||typeof this==="undefined"){return new OutputBinaryFilePort(e,r)}typecheck("OutputBinaryFilePort",e,"string");read_only(this,"__filename__",e);read_only(this,"_fd",r.valueOf(),{hidden:true});read_only(this,"__type__",binary_port);var a,t;this.write=function(e){var n=this;typecheck("write",e,["number","uint8array"]);var i;if(!a){a=this.internal("fs")}if(!t){t=this.internal("Buffer")}if(LNumber.isNumber(e)){i=t.from([e.valueOf()])}else{i=t.from(Array.from(e))}return new Promise(function(r,t){a.write(n._fd,i,function(e){if(e){t(e)}else{r()}})})}}OutputBinaryFilePort.prototype=Object.create(OutputFilePort.prototype);OutputBinaryFilePort.prototype.constructor=OutputBinaryFilePort;OutputBinaryFilePort.prototype.write_u8=function(e){typecheck("OutputByteVectorPort::write_u8",e,"number");this.write(e)};OutputBinaryFilePort.prototype.write_u8_vector=function(e){typecheck("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};var binary_port=Symbol["for"]("binary");var text_port=Symbol["for"]("text");var eof=new EOF;function EOF(){}EOF.prototype.toString=function(){return"#"};function Interpreter(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},t=r.stderr,n=r.stdin,i=r.stdout,a=_objectWithoutProperties(r,_excluded2);if(typeof this!=="undefined"&&!(this instanceof Interpreter)||typeof this==="undefined"){return new Interpreter(e,_objectSpread({stdin:n,stdout:i,stderr:t},a))}if(typeof e==="undefined"){e="anonymous"}this.__env__=user_env.inherit(e,a);var o="**interaction-environment-defaults**";this.set(o,get_props(a).concat(o));var u=internal_env.inherit("internal-".concat(e));if(is_port(n)){u.set("stdin",n)}if(is_port(t)){u.set("stderr",t)}if(is_port(i)){u.set("stdout",i)}set_interaction_env(this.__env__,u)}Interpreter.prototype.exec=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;var t=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:null;typecheck("Interpreter::exec",e,["string","array"],1);typecheck("Interpreter::exec",r,"boolean",2);global_env.set("**interaction-environment**",this.__env__);if(t===null){t=this.__env__}return exec(e,t,r?t:false)};Interpreter.prototype.get=function(e){var r=this.__env__.get(e);if(is_function(r)){return r.bind(this.__env__)}return r};Interpreter.prototype.set=function(e,r){return this.__env__.set(e,r)};Interpreter.prototype.constant=function(e,r){return this.__env__.constant(e,r)};function LipsError(e,r){this.name="LipsError";this.message=e;this.args=r;this.stack=(new Error).stack}LipsError.prototype=new Error;LipsError.prototype.constructor=LipsError;function Environment(e,r,t){if(arguments.length===1){if(_typeof(arguments[0])==="object"){e=arguments[0];r=null}else if(typeof arguments[0]==="string"){e={};r=null;t=arguments[0]}}this.__docs__=new Map;this.__env__=e;this.__parent__=r;this.__name__=t||"anonymous"}Environment.prototype.list=function(){return get_props(this.__env__)};Environment.prototype.fs=function(){return this.get("**fs**")};Environment.prototype.unset=function(e){if(e instanceof LSymbol){e=e.valueOf()}if(e instanceof LString){e=e.valueOf()}delete this.__env__[e]};Environment.prototype.inherit=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{};if(_typeof(e)==="object"){r=e}if(!e||_typeof(e)==="object"){e="child of "+(this.__name__||"unknown")}return new Environment(r||{},this,e)};Environment.prototype.doc=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:null;var t=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:false;if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}if(r){if(!t){r=trim_lines(r)}this.__docs__.set(e,r);return this}if(this.__docs__.has(e)){return this.__docs__.get(e)}if(this.__parent__){return this.__parent__.doc(e)}};Environment.prototype.newFrame=function(e,r){var n=this.inherit("__frame__");n.set("parent.frame",doc("parent.frame",function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:1;e=e.valueOf();var r=n.__parent__;if(!(r instanceof Environment)){return _nil}if(e<=0){return r}var t=r.get("parent.frame");return t(e-1)},global_env.__env__["parent.frame"].__doc__));r.callee=e;n.set("arguments",r);return n};Environment.prototype._lookup=function(e){if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}if(this.__env__.hasOwnProperty(e)){return Value(this.__env__[e])}if(this.__parent__){return this.__parent__._lookup(e)}};Environment.prototype.toString=function(){return"#"};Environment.prototype.clone=function(){var r=this;var t={};Object.keys(this.__env__).forEach(function(e){t[e]=r.__env__[e]});return new Environment(t,this.__parent__,this.__name__)};Environment.prototype.merge=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:"merge";typecheck("Environment::merge",e,"environment");return this.inherit(r,e.__env__)};function Value(e){if(typeof this!=="undefined"&&!(this instanceof Value)||typeof this==="undefined"){return new Value(e)}this.value=e}Value.isUndefined=function(e){return e instanceof Value&&typeof e.value==="undefined"};Value.prototype.valueOf=function(){return this.value};function Values(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof Values)||typeof this==="undefined"){return new Values(e)}this.__values__=e}Values.prototype.toString=function(){return this.__values__.map(function(e){return toString(e)}).join("\n")};Values.prototype.valueOf=function(){return this.__values__};Environment.prototype.get=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{};typecheck("Environment::get",e,["symbol","string"]);var t=r.throwError,n=t===void 0?true:t;var i=e;if(i instanceof LSymbol||i instanceof LString){i=i.valueOf()}var a=this._lookup(i);if(a instanceof Value){if(Value.isUndefined(a)){return undefined$1}return patch_value(a.valueOf())}if(typeof i==="string"){var o=i.split(".").filter(Boolean);if(o.length>0){var u=_toArray(o),c=u[0],s=u.slice(1);a=this._lookup(c);if(s.length){try{if(a instanceof Value){a=a.valueOf()}else{a=get(root,c);if(is_function(a)){a=unbind(a)}}return get.apply(void 0,[a].concat(_toConsumableArray(s)))}catch(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,r){var t=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:null;typecheck("Environment::set",e,["string","symbol"]);if(LNumber.isNumber(r)){r=LNumber(r)}if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}this.__env__[e]=r;if(t){this.doc(e,t)}return this};Environment.prototype.constant=function(r,e){var t=this;if(this.__env__.hasOwnProperty(r)){throw new Error("Environment::constant: ".concat(r," already exists"))}if(arguments.length===1&&is_plain_object(arguments[0])){var n=arguments[0];Object.keys(n).forEach(function(e){t.constant(r,n[e])})}else{Object.defineProperty(this.__env__,r,{value:e,enumerable:true})}return this};Environment.prototype.has=function(e){return this.__env__.hasOwnProperty(e)};Environment.prototype.ref=function(e){var r=this;while(true){if(!r){break}if(r.has(e)){return r}r=r.__parent__}};Environment.prototype.parents=function(){var e=this;var r=[];while(e){r.unshift(e);e=e.__parent__}return r};function quote(e){if(is_promise(e)){return e.then(quote)}if(e instanceof Pair||e instanceof LSymbol){e[__data__]=true}return e}var native_lambda=parse(tokenize('(lambda ()\n "[native code]"\n (throw "Invalid Invocation"))'))[0];var get=doc("get",function e(r){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i0&&arguments[0]!==undefined$1?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 Function get character from string port or EOF object if no more\n data in string port."),"read-line":doc("read-line",function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:null;if(e===null){e=internal(this,"stdin")}typecheck_text_port("read-line",e,"input-port");return e.read_line()},"(read-char port)\n\n Function read next character from input port."),"read-char":doc("read-char",function(){var e=arguments.length>0&&arguments[0]!==undefined$1?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 Function read next character from input port."),read:doc("read",function(){var e=_asyncToGenerator(regenerator.mark(function e(){var t,n,i,a,o,u,c,s,l,f=arguments;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:t=f.length>0&&f[0]!==undefined$1?f[0]:null;if(!LString.isString(t)){r.next=35;break}n=true;i=false;r.prev=4;o=_asyncIterator(parse(t,this));case 6:r.next=8;return o.next();case 8:u=r.sent;n=u.done;r.next=12;return u.value;case 12:c=r.sent;if(n){r.next=19;break}s=c;return r.abrupt("return",s);case 16:n=true;r.next=6;break;case 19:r.next=25;break;case 21:r.prev=21;r.t0=r["catch"](4);i=true;a=r.t0;case 25:r.prev=25;r.prev=26;if(!(!n&&o["return"]!=null)){r.next=30;break}r.next=30;return o["return"]();case 30:r.prev=30;if(!i){r.next=33;break}throw a;case 33:return r.finish(30);case 34:return r.finish(25);case 35:if(t===null){l=internal(this,"stdin")}else{l=t}typecheck_text_port("read",l,"input-port");return r.abrupt("return",l.read.call(this));case 38:case"end":return r.stop()}}},e,this,[[4,21,25,35],[26,,30,34]])}));function r(){return e.apply(this,arguments)}return r}(),"(read [string])\n\n Function if used with string will parse the string and return\n list structure of LIPS code. If called without an argument it\n will read string from standard input (using browser prompt or\n user defined way) and call itself with that string (parse is)\n function can be used together with eval to evaluate code from\n string"),pprint:doc("pprint",function e(r){if(r instanceof Pair){r=new lips.Formatter(r.toString(true))["break"]().format();global_env.get("display").call(global_env,r)}else{global_env.get("write").call(global_env,r)}global_env.get("newline").call(global_env)},"(pprint expression)\n\n Pretty print list expression, if called with non-pair it just call\n print function with passed argument."),print:doc("print",function e(){var r=global_env.get("display");var t=global_env.get("newline");for(var n=arguments.length,i=new Array(n),a=0;a1?t-1:0),i=1;in.length){throw new Error("Not enough arguments")}var u=0;var c=global_env.get("repr");r=r.replace(a,function(e){var r=e[1];if(r==="~"){return"~"}else if(r==="%"){return"\n"}else{var t=n[u++];if(r==="a"){return c(t)}else{return c(t,true)}}});o=r.match(/~([\S])/);if(o){throw new Error("format: Unrecognized escape seqence ".concat(o[1]))}return r},"(format string n1 n2 ...)\n\n Function accepts string template and replacing any escape sequences\n by arguments:\n\n * ~a value as if printed with display\n * ~s value as if printed with write\n * ~% newline character\n * ~~ literal tilde '~' is inserted\n\n if there missing arguments or other escape character it throw exception."),display:doc("display",function e(r){var t=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:null;if(t===null){t=internal(this,"stdout")}else{typecheck("display",t,"output-port")}var n=global_env.get("repr")(r);t.write.call(global_env,n)},"(display arg [port])\n\n Function send string to standard output or provied port."),"display-error":doc("display-error",function e(){var r=internal(this,"stderr");var t=global_env.get("repr");for(var n=arguments.length,i=new Array(n),a=0;a1&&arguments[1]!==undefined$1?arguments[1]:{},t=r.dynamic_scope,n=r.error;if(t){t=this}var i=this;var o;var u=_evaluate(e.cdr.car,{env:this,dynamic_scope:t,error:n});u=resolve_promises(u);function c(r,t,n){if(is_promise(r)){return r.then(function(e){return c(r,e,n)})}if(is_promise(t)){return t.then(function(e){return c(r,e,n)})}if(is_promise(n)){return n.then(function(e){return c(r,t,e)})}i.get("set-obj!").call(i,r,t,n);return n}if(e.car instanceof Pair&&LSymbol.is(e.car.car,".")){var s=e.car.cdr.car;var l=e.car.cdr.cdr.car;var f=_evaluate(s,{env:this,dynamic_scope:t,error:n});var _=_evaluate(l,{env:this,dynamic_scope:t,error:n});return c(f,_,u)}if(!(e.car instanceof LSymbol)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var p=e.car.valueOf();o=this.ref(e.car.__name__);return unpromise(u,function(e){if(!o){var r=p.split(".");if(r.length>1){var t=r.pop();var n=r.join(".");var i=a.get(n,{throwError:false});if(i){c(i,t,e);return}}throw new Error("Unbound variable `"+p+"'")}o.set(p,e)})}),"(set! name value)\n\n Macro that can be used to set the value of the variable (mutate)\n it search the scope chain until it finds first non emtpy slot and set it."),"unset!":doc(new Macro("set!",function(e){if(!(e.car instanceof LSymbol)){throw new Error("unset! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var r=e.car;var t=this.ref(r);if(t){delete t.__env__[r.__name__]}}),"(unset! name)\n\n Function delete specified name from environment."),"set-car!":doc("set-car!",function(e,r){typecheck("set-car!",e,"pair");e.car=r},"(set-car! obj value)\n\n Function that set car (head) of the list/pair to specified value.\n It can destroy the list. Old value is lost."),"set-cdr!":doc("set-cdr!",function(e,r){typecheck("set-cdr!",e,"pair");e.cdr=r},"(set-cdr! obj value)\n\n Function that set cdr (tail) of the list/pair to specified value.\n It can destroy the list. Old value is lost."),"empty?":doc("empty?",function(e){return typeof e==="undefined"||e===_nil},"(empty? object)\n\n Function return true if value is undfined empty list."),gensym:doc("gensym",gensym,"(gensym)\n\n Function generate unique symbol, to use with macros as meta name."),load:doc("load",function e(r,t){typecheck("load",r,"string");var n=this;if(n.__name__==="__frame__"){n=n.__parent__}if(!(t instanceof Environment)){if(n===global_env){t=n}else{t=this.get("**interaction-environment**")}}var i="**module-path**";var a=global_env.get(i,{throwError:false});r=r.valueOf();if(!r.match(/.[^.]+$/)){r+=".scm"}function o(e){if(type(e)==="buffer"){e=e.toString()}e=e.replace(/^#!.*/,"");if(e.match(/\{/)){e=unserialize(e)}return exec(e,t)}if(is_node()){return new Promise(function(t,n){var e=nodeRequire("path");if(a){a=a.valueOf();r=e.join(a,r)}global_env.set(i,e.dirname(r));nodeRequire("fs").readFile(r,function(e,r){if(e){n(e);global_env.set(i,a)}else{try{o(r).then(function(){t();global_env.set(i,a)})["catch"](n)}catch(e){n(e)}}})})}if(a){a=a.valueOf();r=a+"/"+r.replace(/^\.?\/?/,"")}return root.fetch(r).then(function(e){return e.text()}).then(function(e){global_env.set(i,r.replace(/\/[^/]*$/,""));return o(e)}).then(function(){})["finally"](function(){global_env.set(i,a)})},"(load filename)\n (load filename environment)\n\n Function fetch the file and evaluate its content as LIPS code,\n If second argument is provided and it's environment the evaluation\n will happen in that environment."),do:doc(new Macro("do",function(){var t=_asyncToGenerator(regenerator.mark(function e(t,n){var i,a,o,u,c,s,l,f,_,p,h;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:i=n.dynamic_scope,a=n.error;o=this;if(i){i=o}u=o.inherit("do");c=t.car;s=t.cdr.car;l=t.cdr.cdr;if(l!==_nil){l=new Pair(LSymbol("begin"),l)}f={env:o,dynamic_scope:i,error:a};_=c;case 10:if(!(_!==_nil)){r.next=21;break}p=_.car;r.t0=u;r.t1=p.car;r.next=16;return _evaluate(p.cdr.car,f);case 16:r.t2=r.sent;r.t0.set.call(r.t0,r.t1,r.t2);_=_.cdr;r.next=10;break;case 21:f={env:u,dynamic_scope:i,error:a};h=regenerator.mark(function e(){var t,n,i,a,o;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!(l!==_nil)){r.next=3;break}r.next=3;return lips.evaluate(l,f);case 3:t=c;n={};case 5:if(!(t!==_nil)){r.next=15;break}i=t.car;if(!(i.cdr.cdr!==_nil)){r.next=12;break}r.next=10;return _evaluate(i.cdr.cdr.car,f);case 10:a=r.sent;n[i.car.valueOf()]=a;case 12:t=t.cdr;r.next=5;break;case 15:o=Object.getOwnPropertySymbols(n);Object.keys(n).concat(o).forEach(function(e){u.set(e,n[e])});case 17:case"end":return r.stop()}}},e)});case 23:r.next=25;return _evaluate(s.car,f);case 25:r.t3=r.sent;if(!(r.t3===false)){r.next=30;break}return r.delegateYield(h(),"t4",28);case 28:r.next=23;break;case 30:if(!(s.cdr!==_nil)){r.next=34;break}r.next=33;return _evaluate(s.cdr.car,f);case 33:return r.abrupt("return",r.sent);case 34:case"end":return r.stop()}}},e,this)}));return function(e,r){return t.apply(this,arguments)}}()),"(do (( )) (test expression) . body)\n\n Iteration macro that evaluate the expression body in scope of the variables.\n On Eeach loop it increase the variables according to next expression and run\n test to check if the loop should continue. If test is signle call the macro\n will not return anything. If the test is pair of expression and value the\n macro will return that value after finish."),if:doc(new Macro("if",function(t,e){var n=e.dynamic_scope,i=e.error;if(n){n=this}var a=this;var r=function e(r){if(r===false){return _evaluate(t.cdr.cdr.car,{env:a,dynamic_scope:n,error:i})}else{return _evaluate(t.cdr.car,{env:a,dynamic_scope:n,error:i})}};if(t===_nil){throw new Error("too few expressions for `if`")}var o=_evaluate(t.car,{env:a,dynamic_scope:n,error:i});return unpromise(o,r)}),"(if cond true-expr false-expr)\n\n Macro evaluate condition expression and if the value is true, it\n evaluate and return true expression if not it evaluate and return\n false expression"),"let-env":new Macro("let-env",function(r){var e=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{};var t=e.dynamic_scope,n=e.error;typecheck("let-env",r,"pair");var i=_evaluate(r.car,{env:this,dynamic_scope:t,error:n});return unpromise(i,function(e){typecheck("let-env",e,"environment");return _evaluate(Pair(LSymbol("begin"),r.cdr),{env:e,dynamic_scope:t,error:n})})},"(let-env env . body)\n\n Special macro that evaluate 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 new environment, then evaluate and assign values to\n names and then evaluate the body in context of that environment.\n Values are evaluated sequentialy and next value can access to\n previous values/names."),"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 use can use recursive code as well as reference previous binding.\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 next argument get environment\n from previous let variable, so they you can define one variable,\n and use in next argument."),let:doc(let_macro(Symbol["for"]("let")),"(let ((a value-a) (b value-b)) body)\n\n Macro that creates new environment, then evaluate and assign values to\n names and then evaluate the body in context of that environment.\n Values are evaluated sequentialy but you can't access\n previous values/names when next are evaluated. You can only get them\n from body of let expression."),"begin*":doc(pararel("begin*",function(e){return e.pop()}),"(begin* . expr)\n\n This macro is parallel version of begin. It evaluate each expression and\n if it's a promise it will evaluate it in parallel and return value\n of last expression."),begin:doc(new Macro("begin",function(e,r){var n=Object.assign({},r);var i=global_env.get("list->array")(e);if(n.dynamic_scope){n.dynamic_scope=this}n.env=this;var a;return function r(){if(i.length){var e=i.shift();var t=_evaluate(e,n);return unpromise(t,function(e){a=e;return r()})}else{return a}}()}),"(begin . args)\n\n Macro runs list of expression and return valuate of the list one.\n It can be used in place where you can only have single exression,\n like if expression."),ignore:new Macro("ignore",function(e,r){var t=r.dynamic_scope,n=r.error;var i={env:this,error:n};if(t){i.dynamic_scope=this}_evaluate(new Pair(new LSymbol("begin"),e),i)},"(ignore expression)\n\n Macro that will evaluate expression and swallow any promises that may\n be created. It wil run and ignore any value that may be returned by\n expression. The code should have side effects and/or when it's promise\n it should resolve to undefined."),define:doc(Macro.defmacro("define",function(t,e){var n=this;if(t.car instanceof Pair&&t.car.car instanceof LSymbol){var r=new Pair(new LSymbol("define"),new Pair(t.car.car,new Pair(new Pair(new LSymbol("lambda"),new Pair(t.car.cdr,t.cdr)))));return r}else if(e.macro_expand){return}if(e.dynamic_scope){e.dynamic_scope=this}e.env=n;var i=t.cdr.car;var a;if(i instanceof Pair){i=_evaluate(i,e);a=true}else if(i instanceof LSymbol){i=n.get(i)}typecheck("define",t.car,"symbol");return unpromise(i,function(e){if(n.__name__===Syntax.__merge_env__){n=n.__parent__}if(a&&(is_function(e)&&is_lambda(e)||e instanceof Syntax)){e.__name__=t.car.valueOf();if(e.__name__ instanceof LString){e.__name__=e.__name__.valueOf()}}var r;if(t.cdr.cdr instanceof Pair&&LString.isString(t.cdr.cdr.car)){r=t.cdr.cdr.car.valueOf()}n.set(t.car,e,r,true)})}),"(define name expression)\n (define (function-name . args) body)\n\n Macro for defining values. It can be used to define variables,\n or function. If first argument is list it will create function\n with name beeing first element of the list. The macro evalute\n code `(define function (lambda args body))`"),"set-obj!":doc("set-obj!",function(e,r,t){var n=_typeof(e);if(is_null(e)||n!=="object"&&n!=="function"){var i=typeErrorMessage("set-obj!",type(e),["object","function"]);throw new Error(i)}typecheck("set-obj!",r,["string","symbol","number"]);e=unbind(e);r=r.valueOf();if(arguments.length===2){delete e[r]}else if(is_prototype(e)&&is_function(t)){e[r]=unbind(t);e[r][__prototype__]=true}else if(is_function(t)||is_native(t)||t===_nil){e[r]=t}else{e[r]=t?t.valueOf():t}},"(set-obj! obj key value)\n\n Function set property of JavaScript object"),"null-environment":doc("null-environment",function(){return global_env.inherit("null")},"(null-environment)\n\n Function return new base environment with std lib."),values:doc("values",function e(){for(var r=arguments.length,t=new Array(r),n=0;n1&&arguments[1]!==undefined$1?arguments[1]:{},_=e.dynamic_scope,p=e.error;var h=this;var d;if(f.cdr instanceof Pair&&LString.isString(f.cdr.car)&&f.cdr.cdr!==_nil){d=f.cdr.car.valueOf()}function m(){var e;if(_){if(!(this instanceof Environment)){e=h}else{e=this}}else{e=h}e=e.inherit("lambda");var r=f.car;var t=0;var n;if(typeof this!=="undefined"&&!(this instanceof Environment)){if(this&&!this.__instance__){Object.defineProperty(this,"__instance__",{enumerable:false,get:function e(){return true},set:function e(){},configurable:false})}e.set("this",this)}for(var i=arguments.length,a=new Array(i),o=0;o2&&arguments[2]!==undefined$1?arguments[2]:a;if(e instanceof Pair){var n=e.car;var i=e.cdr;if(t(n)){n=r(n)}if(t(i)){i=r(i)}if(is_promise(n)||is_promise(i)){return promise_all([n,i]).then(function(e){var r=_slicedToArray(e,2),t=r[0],n=r[1];return new Pair(t,n)})}else{return new Pair(n,i)}}return e}function o(e,r){if(e instanceof Pair){if(r!==_nil){e.append(r)}}else{e=new Pair(e,r)}return e}function t(e){return!!e.filter(function(e){return e instanceof Pair&&LSymbol.is(e.car,/^(unquote|unquote-splicing)$/)}).length}function f(e,n,i){return e.reduce(function(e,r){if(!(r instanceof Pair)){e.push(r);return e}if(LSymbol.is(r.car,"unquote-splicing")){var t;if(n+11){var r="You can't splice multiple atoms inside list";throw new Error(r)}if(!(i.cdr instanceof Pair&&t[0]===_nil)){return t[0]}}t=t.map(function(e){if(h.has(e)){return e.clone()}else{h.add(e);return e}});var n=d(i.cdr,0,1);if(n===_nil&&t[0]===_nil){return undefined$1}return unpromise(n,function(e){if(t[0]===_nil){return e}if(t.length===1){return o(t[0],e)}var r=t.reduce(function(e,r){return o(e,r)});return o(r,e)})})}(i.car.cdr)}var h=new Set;function d(e,r,t){if(e instanceof Pair){if(e.car instanceof Pair){if(LSymbol.is(e.car.car,"unquote-splicing")){return p(e,r+1,t)}if(LSymbol.is(e.car.car,"unquote")){if(r+2===t&&e.car.cdr instanceof Pair&&e.car.cdr.car instanceof Pair&&LSymbol.is(e.car.cdr.car.car,"unquote-splicing")){var n=e.car.cdr;return new Pair(new Pair(new LSymbol("unquote"),p(n,r+2,t)),_nil)}else if(e.car.cdr instanceof Pair&&e.car.cdr.cdr!==_nil){if(e.car.cdr.car instanceof Pair){var i=[];return function r(t){if(t===_nil){return Pair.fromArray(i)}return unpromise(_evaluate(t.car,{env:s,dynamic_scope:u,error:c}),function(e){i.push(e);return r(t.cdr)})}(e.car.cdr)}else{return e.car.cdr}}}}if(LSymbol.is(e.car,"quasiquote")){var a=d(e.cdr,r,t+1);return new Pair(e.car,a)}if(LSymbol.is(e.car,"quote")){return new Pair(e.car,d(e.cdr,r,t))}if(LSymbol.is(e.car,"unquote")){r++;if(rt){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(e.cdr instanceof Pair){if(e.cdr.cdr!==_nil){if(e.cdr.car instanceof Pair){var o=[];return function r(t){if(t===_nil){return Pair.fromArray(o)}return unpromise(_evaluate(t.car,{env:s,dynamic_scope:u,error:c}),function(e){o.push(e);return r(t.cdr)})}(e.cdr)}else{return e.cdr}}else{return _evaluate(e.cdr.car,{env:s,dynamic_scope:u,error:c})}}else{return e.cdr}}return l(e,function(e){return d(e,r,t)})}else if(is_plain_object(e)){return _(e,r,t)}else if(e instanceof Array){return f(e,r,t)}return e}function n(e){if(e instanceof Pair){delete e[__data__];if(!e.haveCycles("car")){n(e.car)}if(!e.haveCycles("cdr")){n(e.cdr)}}}if(is_plain_object(e.car)&&!t(Object.values(e.car))){return quote(e.car)}if(Array.isArray(e.car)&&!t(e.car)){return quote(e.car)}if(e.car instanceof Pair&&!e.car.find("unquote")&&!e.car.find("unquote-splicing")&&!e.car.find("quasiquote")){return quote(e.car)}var i=d(e.car,0,1);return unpromise(i,function(e){n(e);return quote(e)})},"(quasiquote list ,value ,@value)\n\n Similar macro to `quote` but inside it you can use special\n expressions unquote abbreviated to , that will evaluate expresion inside\n and return its value or unquote-splicing abbreviated to ,@ that will\n evaluate expression but return value without parenthesis (it will join)\n the list with its value. Best used with macros but it can be used outside"),clone:doc("clone",function e(r){typecheck("clone",r,"pair");return r.clone()},"(clone list)\n\n Function return clone of the list."),append:doc("append",function e(){var r;for(var t=arguments.length,n=new Array(t),i=0;iarray")(r).reverse();return global_env.get("array->list")(t)}else if(!(r instanceof Array)){throw new Error(typeErrorMessage("reverse",type(r),"array or pair"))}else{return r.reverse()}},"(reverse list)\n\n Function will reverse the list or array. If value is not a list\n or array it will throw exception."),nth:doc("nth",function e(r,t){typecheck("nth",r,"number");typecheck("nth",t,["array","pair"]);if(t instanceof Pair){var n=t;var i=0;while(iarray")(t).join(r)},"(join separator list)\n\n Function return string by joining elements of the list"),split:doc("split",function e(r,t){typecheck("split",r,["regex","string"]);typecheck("split",t,"string");return global_env.get("array->list")(t.split(r))},"(split separator string)\n\n Function create list by splitting string by separatar that can\n be a string or regular expression."),replace:doc("replace",function e(r,t,n){typecheck("replace",r,["regex","string"]);typecheck("replace",t,["string","function"]);typecheck("replace",n,"string");return n.replace(r,t)},"(replace pattern replacement string)\n\n Function change pattern to replacement inside string. Pattern can be string\n or regex and replacement can be function or string."),match:doc("match",function e(r,t){typecheck("match",r,["regex","string"]);typecheck("match",t,"string");var n=t.match(r);return n?global_env.get("array->list")(n):false},"(match pattern string)\n\n function return match object from JavaScript as list or #f if not match."),search:doc("search",function e(r,t){typecheck("search",r,["regex","string"]);typecheck("search",t,"string");return t.search(r)},"(search pattern string)\n\n Function return first found index of the pattern inside a string"),repr:doc("repr",function e(r,t){return toString(r,t)},"(repr obj)\n\n Function return string LIPS representation of an object as string."),"escape-regex":doc("escape-regex",function(e){typecheck("escape-regex",e,"string");return escape_regex(e.valueOf())},"(escape-regex string)\n\n Function return new string where all special operators used in regex,\n are escaped with slash so they can be used in RegExp constructor\n to match literal string"),env:doc("env",function e(e){e=e||this;var r=Object.keys(e.__env__).map(LSymbol);var t;if(r.length){t=Pair.fromArray(r)}else{t=_nil}if(e.__parent__ instanceof Environment){return global_env.get("env")(e.__parent__).append(t)}return t},"(env)\n (env obj)\n\n Function return list of values (functions, macros and variables)\n inside environment and it's parents."),new:doc("new",function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n2&&arguments[2]!==undefined$1?arguments[2]:specials.LITERAL;typecheck("set-special!",e,"string",1);typecheck("set-special!",r,"symbol",2);specials.append(e.valueOf(),r,t)},'(set-special! symbol name [type])\n\n Add 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 constant value\n lips.specials.SPLICE if this constant is used it will transform\n `#(1 2 3)` into (x 1 2 3) that is required by # that define vectors.'),get:get,".":get,unbind:doc(unbind,"(unbind fn)\n\n Function remove bidning from function so you can get props from it."),type:doc(type,"(type object)\n\n Function return type of an object as string."),debugger:doc("debugger",function(){debugger},"(debugger)\n\n Function stop JavaScript code in debugger."),in:doc("in",function(e,r){if(e instanceof LSymbol||e instanceof LString||e instanceof LNumber){e=e.valueOf()}return e in unbox(r)},"(in key value)\n\n Function use is in operator to check if value is in object."),instanceof:doc("instanceof",function(e,r){return r instanceof unbind(e)},"(instanceof type obj)\n\n Function check of object is instance of object."),"prototype?":doc("prototype?",is_prototype,"(prototype? obj)\n\n Function check if value is JavaScript Object prototype."),"macro?":doc("macro?",function(e){return e instanceof Macro},"(macro? expression)\n\n Function check if value is a macro."),"function?":doc("function?",is_function,"(function? expression)\n\n Function check if value is a 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 Function check if value is real number."),"number?":doc("number?",function(e){return Number.isNaN(e)||LNumber.isNumber(e)},"(number? expression)\n\n Function check if value is a number or NaN value."),"string?":doc("string?",function(e){return LString.isString(e)},"(string? expression)\n\n Function check if value is a string."),"pair?":doc("pair?",function(e){return e instanceof Pair},"(pair? expression)\n\n Function check if value is a pair or list structure."),"regex?":doc("regex?",function(e){return e instanceof RegExp},"(regex? expression)\n\n Function check if value is regular expression."),"null?":doc("null?",function(e){return is_null(e)},"(null? expression)\n\n Function check if value is nulish."),"boolean?":doc("boolean?",function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Function check if value is boolean."),"symbol?":doc("symbol?",function(e){return e instanceof LSymbol},"(symbol? expression)\n\n Function check if value is LIPS symbol"),"array?":doc("array?",function(e){return e instanceof Array},"(array? expression)\n\n Function check if value is an arrray."),"object?":doc("object?",function(e){return e!==_nil&&e!==null&&!(e instanceof LCharacter)&&!(e instanceof RegExp)&&!(e instanceof LString)&&!(e instanceof Pair)&&!(e instanceof LNumber)&&_typeof(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Function check if value is an plain object."),flatten:doc("flatten",function e(r){typecheck("flatten",r,"pair");return r.flatten()},"(flatten list)\n\n Return 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 convert JavaScript array to LIPS list."),"tree->array":doc("tree->array",to_array("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":doc("list->array",to_array("list->array"),"(list->array list)\n\n Function convert LIPS list into JavaScript array."),apply:doc("apply",function e(r){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;iarray").call(this,a));return r.apply(this,prepare_fn_args(r,n))},"(apply fn list)\n\n Function that call function with list of arguments."),length:doc("length",function e(r){if(!r){return LNumber(0)}if(r instanceof Pair){return LNumber(r.length())}if("length"in r){return LNumber(r.length)}},"(length expression)\n\n Function return length of the object, the object can be list\n or any object that have length property."),"string->number":doc("string->number",function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:10;typecheck("string->number",e,"string",1);typecheck("string->number",r,"number",2);e=e.valueOf();r=r.valueOf();if(e.match(rational_bare_re)||e.match(rational_re)){return parse_rational(e,r)}else if(e.match(complex_bare_re)||e.match(complex_re)){return parse_complex(e,r)}else{var t=r===10&&!e.match(/e/i)||r===16;if(e.match(int_bare_re)&&t||e.match(int_re)){return parse_integer(e,r)}if(e.match(float_re)){return parse_float(e)}}return false},"(string->number number [radix])\n\n Function convert string to number."),try:doc(new Macro("try",function(r,e){var s=this;var l=e.dynamic_scope,f=e.error;return new Promise(function(i,n){var a,o;if(LSymbol.is(r.cdr.car.car,"catch")){a=r.cdr.car;if(r.cdr.cdr instanceof Pair&&LSymbol.is(r.cdr.cdr.car.car,"finally")){o=r.cdr.cdr.car}}else if(LSymbol.is(r.cdr.car.car,"finally")){o=r.cdr.car}if(!(o||a)){throw new Error("try: invalid syntax")}var u=i;if(o){u=function e(r,t){u=n;unpromise(_evaluate(new Pair(new LSymbol("begin"),o.cdr),c),function(){t(r)})}}var c={env:s,error:function e(r){var t=s.inherit("try");if(a){t.set(a.cdr.car.car,r);var n={env:t,error:f};if(l){n.dynamic_scope=s}unpromise(_evaluate(new Pair(new LSymbol("begin"),a.cdr.cdr),n),function(e){u(e,i)})}else{u(r,f)}}};if(l){c.dynamic_scope=s}var e=_evaluate(r.car,c);if(is_promise(e)){e.then(function(e){u(e,i)})["catch"](c.error)}else{u(e,i)}})}),"(try expr (catch (e) code))\n (try expr (catch (e) code) (finally code))\n (try expr (finally code))\n\n Macro execute user code and catch exception. If catch is provided\n it's executed when expression expr throw error. If finally is provide\n it's always executed at the end."),raise:doc("raise",function(e){throw e},"(raise obj)\n\n Throws new exception with given object."),throw:doc("throw",function(e){throw new Error(e)},"(throw string)\n\n Throws new expection."),find:doc("find",function r(t,n){typecheck("find",t,["regex","function"]);typecheck("find",n,["pair","nil"]);if(is_null(n)){return _nil}var e=matcher("find",t);return unpromise(e(n.car),function(e){if(e&&e!==_nil){return n.car}return r(t,n.cdr)})},"(find fn list)\n (find regex list)\n\n Higher order Function find first value for which function return true.\n If called with regex it will create matcher function."),"for-each":doc("for-each",function(e){var r;typecheck("for-each",e,"function");for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i1?r-1:0),a=1;a3?n-3:0),a=3;a3?i-3:0),o=3;oarray")(t);var a=[];var o=matcher("filter",r);return function r(t){function e(e){if(e&&e!==_nil){a.push(n)}return r(++t)}if(t===i.length){return Pair.fromArray(a)}var n=i[t];return unpromise(o(n),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher order function that call `fn` for each element of the list\n and return list for only those elements for which funtion return\n true value. If called with regex it will create matcher function."),compose:doc(compose,"(compose . fns)\n\n Higher order function and create new function that apply all functions\n From right to left and return it's value. Reverse of compose.\n e.g.:\n ((compose (curry + 2) (curry * 3)) 3)\n 11\n "),pipe:doc(pipe,"(pipe . fns)\n\n Higher order function and create new function that apply all functions\n From left to right and return it's value. Reverse of compose.\n e.g.:\n ((pipe (curry + 2) (curry * 3)) 3)\n 15"),curry:doc(curry,"(curry fn . args)\n\n Higher order function that create curried version of the function.\n The result function will have parially applied arguments and it\n will keep returning functions until all arguments are added\n\n e.g.:\n (define (add a b c d) (+ a b c d))\n (define add1 (curry add 1))\n (define add12 (add 2))\n (display (add12 3 4))"),gcd:doc("gcd",function e(){for(var r=arguments.length,t=new Array(r),n=0;nu?a%=u:u%=a}a=abs(c*t[o])/(a+u)}return LNumber(a)},"(lcm n1 n2 ...)\n\n Function return the least common multiple of their arguments."),"odd?":doc("odd?",single_math_op(function(e){return LNumber(e).isOdd()}),"(odd? number)\n\n Function check if number os odd."),"even?":doc("even?",single_math_op(function(e){return LNumber(e).isEven()}),"(even? number)\n\n Function check if number is even."),"*":doc("*",reduce_math_op(function(e,r){return LNumber(e).mul(r)},LNumber(1)),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":doc("+",reduce_math_op(function(e,r){return LNumber(e).add(r)},LNumber(0)),"(+ . numbers)\n\n Sum all numbers passed as arguments. If single value is passed it will\n return that value."),"-":doc("-",function(){for(var e=arguments.length,r=new Array(e),t=0;t":doc(">",function(){for(var e=arguments.length,r=new Array(e),t=0;t",r,"number");return seq_compare(function(e,r){return LNumber(e).cmp(r)===1},r)},"(> x1 x2 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically increasing"),"<":doc("<",function(){for(var e=arguments.length,r=new Array(e),t=0;t=":doc(">=",function(){for(var e=arguments.length,r=new Array(e),t=0;t=",r,"number");return seq_compare(function(e,r){return[0,1].includes(LNumber(e).cmp(r))},r)},"(>= x1 x2 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically nondecreasing"),"eq?":doc("eq?",equal,"(eq? a b)\n\n Function compare two values if they are identical."),or:doc(new Macro("or",function(e,r){var i=r.dynamic_scope,a=r.error;var o=global_env.get("list->array")(e);var u=this;if(i){i=u}if(!o.length){return false}var c;return function r(){function e(e){c=e;if(c!==false){return c}else{return r()}}if(!o.length){if(c!==false){return c}else{return false}}else{var t=o.shift();var n=_evaluate(t,{env:u,dynamic_scope:i,error:a});return unpromise(n,e)}}()}),"(or . expressions)\n\n Macro execute the values one by one and return the one that is truthy value.\n If there are no expression that evaluate to true it return false."),and:doc(new Macro("and",function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},i=r.dynamic_scope,a=r.error;var o=global_env.get("list->array")(e);var u=this;if(i){i=u}if(!o.length){return true}var c;return function r(){function e(e){c=e;if(c===false){return false}else{return r()}}var t=o.shift();if(typeof t==="undefined"){if(c!==false){return c}else{return false}}else{var n=_evaluate(t,{env:u,dynamic_scope:i,error:a});return unpromise(n,e)}}()}),"(and . expressions)\n\n Macro evalute each expression in sequence if any value return false it will\n return false. If each value return true it will return the last value.\n If it's called without arguments it will return true."),"|":doc("|",function(e,r){return LNumber(e).or(r)},"(& a b)\n\n Function calculate or bit operation."),"&":doc("&",function(e,r){return LNumber(e).and(r)},"(& a b)\n\n Function calculate and bit operation."),"~":doc("~",function(e){return LNumber(e).neg()},"(~ number)\n\n Function negate the value."),">>":doc(">>",function(e,r){return LNumber(e).shr(r)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":doc("<<",function(e,r){return LNumber(e).shl(r)},"(<< a b)\n\n Function left shit the value a by value b."),not:doc("not",function e(r){if(is_null(r)){return true}return!r},"(not object)\n\n Function return negation of the argument.")},undefined$1,"global");var user_env=global_env.inherit("user-env");function set_interaction_env(e,r){e.constant("**internal-env**",r);e.doc("**internal-env**","**internal-env**\n\n Constant used to hide stdin, stdout and stderr so they don't interfere\n with variables with the same name. Constants are internal type\n of variables that can't be redefined, defining variable with 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 contain references to stdin, stdout and stderr.");(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(r){var t=e[r]?e[r]:r;global_env.set(t,doc(t,function(e){typecheck(t,e,"number");if(e instanceof LNumber){return e[r]()}},"(".concat(t," number)\n\n Function calculate ").concat(t," of a number.")))})})();function allPossibleCases(e){if(e.length===1){return e[0]}else{var r=[];var t=allPossibleCases(e.slice(1));for(var n=0;n3&&arguments[3]!==undefined$1?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(n!==null){i+=" (argument ".concat(n,")")}if(t instanceof Array){if(t.length===1){t=t[0]}else{var a=t[t.length-1];t=t.slice(0,-1).join(", ")+" or "+a}}return"Expecting ".concat(t,", got ").concat(r).concat(i)}function typecheck_args(t,e,n){e.forEach(function(e,r){typecheck(t,e,n,r+1)})}function typecheck_text_port(e,r,t){typecheck(e,r,t);if(r.__type__===binary_port){throw new Error(typeErrorMessage(e,"binary-port","textual-port"))}}function typecheck(e,r,t){var n=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:null;e=e.valueOf();var i=type(r).toLowerCase();var a=false;if(t instanceof Pair){t=t.to_array()}if(t instanceof Array){t=t.map(function(e){return e.valueOf()})}if(t instanceof Array){t=t.map(function(e){return e.valueOf().toLowerCase()});if(t.includes(i)){a=true}}else{t=t.valueOf().toLowerCase()}if(!a&&i!==t){throw new Error(typeErrorMessage(e,i,t,n))}}function self_evaluated(e){var r=_typeof(e);return["string","function"].includes(r)||_typeof(e)==="symbol"||e instanceof QuotedPromise||e instanceof LSymbol||e instanceof LNumber||e instanceof LString||e instanceof RegExp}function is_native(e){return e instanceof LNumber||e instanceof LString||e instanceof LCharacter}function has_own_symbol(e,r){if(e===null){return false}return _typeof(e)==="object"&&r in Object.getOwnPropertySymbols(e)}function is_iterator(e,r){if(has_own_symbol(e,r)||has_own_symbol(e.__proto__,r)){return is_function(e[r])}}function type(e){var r={pair:Pair,symbol:LSymbol,character:LCharacter,values:Values,"input-port":InputPort,"output-port":OutputPort,number:LNumber,regex:RegExp,syntax:Syntax,macro:Macro,string:LString,array:Array,"native-symbol":Symbol};if(Number.isNaN(e)){return"NaN"}if(e===_nil){return"nil"}if(e===null){return"null"}for(var t=0,n=Object.entries(r);t2&&arguments[2]!==undefined$1?arguments[2]:{},a=r.env,o=r.dynamic_scope,t=r.error,u=t===void 0?function(){}:t;e=evaluate_args(e,{env:a,dynamic_scope:o,error:u});return unpromise(e,function(e){if(is_raw_lambda(i)){i=unbind(i)}e=prepare_fn_args(i,e);var r=e.slice();var t=(o||a).newFrame(i,r);var n=resolve_promises(i.apply(t,e));return unpromise(n,function(e){if(e instanceof Pair){e.markCycles();return quote(e)}if(Number.isNaN(e)){return e}if(typeof e==="number"){return LNumber(e)}if(typeof e==="string"){return LString(e)}return e},u)})}function _evaluate(r){var e=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},t=e.env,n=e.dynamic_scope,i=e.error,a=i===void 0?function(){}:i;try{if(n===true){t=n=t||global_env}else if(t===true){t=n=global_env}else{t=t||global_env}var o={env:t,dynamic_scope:n,error:a};var u;if(is_null(r)){return r}if(r instanceof LSymbol){return t.get(r)}if(!(r instanceof Pair)){return r}var c=r.car;var s=r.cdr;if(c instanceof Pair){u=resolve_promises(_evaluate(c,o));if(is_promise(u)){return u.then(function(e){return _evaluate(new Pair(e,r.cdr),o)})}else if(!is_function(u)){throw new Error(type(u)+" "+t.get("repr")(u)+" is not a function while evaluating "+r.toString())}}if(c instanceof LSymbol){u=t.get(c)}else if(is_function(c)){u=c}var l;if(u instanceof Syntax){l=evaluate_syntax(u,r,o)}else if(u instanceof Macro){l=evaluate_macro(u,s,o)}else if(is_function(u)){l=apply(u,s,o)}else if(r instanceof Pair){u=c&&c.toString();throw new Error("".concat(type(c)," ").concat(u," is not a function"))}else if(!is_function(u)){if(u){var f="".concat(type(u)," `").concat(u,"' is not a function");throw new Error(f)}throw new Error("Unknown function `".concat(c.toString(),"'"))}else{return r}var _=t.get(Symbol["for"]("__promise__"),{throwError:false});if(_===true&&is_promise(l)){l=l.then(function(e){if(e instanceof Pair&&!u[__data__]){return _evaluate(e,o)}return e});return new QuotedPromise(l)}return l}catch(e){a&&a.call(t,e,r)}}function exec(e,r,t){return _exec.apply(this,arguments)}function _exec(){_exec=_asyncToGenerator(regenerator.mark(function e(t,n,i){var a,o,u,c,s,l,f,_,p,h;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(i===true){n=i=n||user_env}else if(n===true){n=i=user_env}else{n=n||user_env}a=[];o=Array.isArray(t)?t:parse(t);u=true;c=false;r.prev=5;l=_asyncIterator(o);case 7:r.next=9;return l.next();case 9:f=r.sent;u=f.done;r.next=13;return f.value;case 13:_=r.sent;if(u){r.next=29;break}p=_;h=_evaluate(p,{env:n,dynamic_scope:i,error:function e(r,t){if(r&&r.message){if(r.message.match(/^Error:/)){var n=/^(Error:)\s*([^:]+:\s*)/;r.message=r.message.replace(n,"$1 $2")}if(t){if(!(r.__code__ instanceof Array)){r.__code__=[]}r.__code__.push(t.toString(true))}}throw r}});if(is_promise(h)){r.next=21;break}a.push(h);r.next=26;break;case 21:r.t0=a;r.next=24;return h;case 24:r.t1=r.sent;r.t0.push.call(r.t0,r.t1);case 26:u=true;r.next=7;break;case 29:r.next=35;break;case 31:r.prev=31;r.t2=r["catch"](5);c=true;s=r.t2;case 35:r.prev=35;r.prev=36;if(!(!u&&l["return"]!=null)){r.next=40;break}r.next=40;return l["return"]();case 40:r.prev=40;if(!c){r.next=43;break}throw s;case 43:return r.finish(40);case 44:return r.finish(35);case 45:return r.abrupt("return",a);case 46:case"end":return r.stop()}}},e,null,[[5,31,35,45],[36,,40,44]])}));return _exec.apply(this,arguments)}function balanced(e){var r={"[":"]","(":")"};var t;if(typeof e==="string"){t=tokenize(e)}else{t=e.map(function(e){return e&&e.token?e.token:e})}var n=Object.keys(r);var i=Object.values(r).concat(n);t=t.filter(function(e){return i.includes(e)});var a=new Stack;var o=_createForOfIteratorHelper(t),u;try{for(o.s();!(u=o.n()).done;){var c=u.value;if(n.includes(c)){a.push(c)}else if(!a.is_empty()){var s=a.top();var l=r[s];if(c===l){a.pop()}else{throw new Error("Syntax error: missing closing ".concat(l))}}else{throw new Error("Syntax error: not matched closing ".concat(c))}}}catch(e){o.e(e)}finally{o.f()}return a.is_empty()}function fworker(e){var r="("+e.toString()+")()";var t=window.URL||window.webkitURL;var n;try{n=new Blob([r],{type:"application/javascript"})}catch(e){var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;n=new i;n.append(r);n=n.getBlob()}return new root.Worker(t.createObjectURL(n))}function is_dev(){return lips.version.match(/^(\{\{VER\}\}|DEV)$/)}function bootstrap(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:"";if(e===""){if(is_dev()){e="https://cdn.jsdelivr.net/gh/jcubic/lips@devel/"}else{e="https://cdn.jsdelivr.net/npm/@jcubic/lips@".concat(lips.version,"/")}}else if(!e.match(/\/$/)){e+="/"}var r=global_env.get("load");return r.call(lips.env,"".concat(e,"dist/std.scm"),global_env)}function Worker(e){this.url=e;var o=this.worker=fworker(function(){var o;var u;self.addEventListener("message",function(e){var t=e.data;var r=t.id;if(t.type!=="RPC"||r===null){return}function n(e){self.postMessage({id:r,type:"RPC",result:e})}function i(e){self.postMessage({id:r,type:"RPC",error:e})}if(t.method==="eval"){if(!u){i("Worker RPC: LIPS not initilized, call init first");return}u.then(function(){var e=t.params[0];var r=t.params[1];o.exec(e,r).then(function(e){e=e.map(function(e){return e&&e.valueOf()});n(e)})["catch"](function(e){i(e)})})}else if(t.method==="init"){var a=t.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(r,t){var a=++n;return new Promise(function(n,i){o.addEventListener("message",function e(r){var t=r.data;if(t&&t.type==="RPC"&&t.id===a){if(t.error){i(t.error)}else{n(t.result)}o.removeEventListener("message",e)}});o.postMessage({type:"RPC",method:r,id:a,params:t})})}}();this.rpc("init",[e])["catch"](function(e){console.error(e)});this.exec=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;return this.rpc("eval",[e,r])}}var serialization_map={pair:function e(r){var t=_slicedToArray(r,2),n=t[0],i=t[1];return Pair(n,i)},number:function e(r){if(LString.isString(r)){return LNumber([r,10])}return LNumber(r)},regex:function e(r){var t=_slicedToArray(r,2),n=t[0],i=t[1];return new RegExp(n,i)},nil:function e(){return _nil},symbol:function e(r){if(LString.isString(r)){return LSymbol(r)}else if(Array.isArray(r)){return LSymbol(Symbol["for"](r[0]))}},string:LString,character:LCharacter};var available_class=Object.keys(serialization_map);var class_map={};for(var _i5=0,_Object$entries3=Object.entries(available_class);_i5<_Object$entries3.length;_i5++){var _Object$entries3$_i=_slicedToArray(_Object$entries3[_i5],2),i=_Object$entries3$_i[0],cls=_Object$entries3$_i[1];class_map[cls]=+i}function mangle_name(e){return class_map[e]}function resolve_name(e){return available_class[e]}function serialize(e){return JSON.stringify(e,function(e,r){var t=this[e];if(t){if(t instanceof RegExp){return{"@":mangle_name("regex"),"#":[t.source,t.flags]}}var n=mangle_name(t.constructor.__class__);if(!is_undef(n)){return{"@":n,"#":t.serialize()}}}return r})}function unserialize(e){return JSON.parse(e,function(e,r){if(r&&_typeof(r)==="object"){if(!is_undef(r["@"])){var t=resolve_name(r["@"]);if(serialization_map[t]){return serialization_map[t](r["#"])}}}return r})}function execError(e){console.error(e.message||e);if(e.code){console.error(e.code.map(function(e,r){return"[".concat(r+1,"]: ").concat(e)}))}}function init(){var o=["text/x-lips","text/x-scheme"];var u;function c(t){return new Promise(function(r){var e=t.getAttribute("src");if(e){return fetch(e).then(function(e){return e.text()}).then(exec).then(r)["catch"](function(e){execError(e);r()})}else{return exec(t.innerHTML).then(r)["catch"](function(e){execError(e);r()})}})}function e(){return new Promise(function(i){var a=Array.from(document.querySelectorAll("script"));return function e(){var r=a.shift();if(!r){i()}else{var t=r.getAttribute("type");if(o.includes(t)){var n=r.getAttribute("bootstrap");if(!u&&typeof n==="string"){bootstrap(n).then(function(){return c(r)}).then(e)}else{c(r).then(e)}}else if(t&&t.match(/lips|lisp/)){console.warn("Expecting "+o.join(" or ")+" found "+t)}return e()}}()})}if(!window.document){return Promise.resolve()}else if(currentScript){var r=currentScript;var t=r.getAttribute("bootstrap");if(typeof t==="string"){return bootstrap(t).then(function(){u=true;return e()})}}return e()}var currentScript=typeof window!=="undefined"&&window.document&&document.currentScript;if(typeof window!=="undefined"){contentLoaded(window,init)}var banner=function(){var e=LString("Fri, 04 Jun 2021 11:25:19 +0000").valueOf();var r=e==="{{"+"DATE}}"?new Date:new Date(e);var t=function e(r){return r.toString().padStart(2,"0")};var n=r.getFullYear();var i=[n,t(r.getMonth()+1),t(r.getDate())].join("-");var a="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter 1.0.0-beta.14 (".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 specic 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}();Ahead.__class__="ahead";Pair.__class__="pair";Nil.__class__="nil";Pattern.__class__="pattern";Formatter.__class__="formatter";Macro.__class__="macro";Syntax.__class__="syntax";Environment.__class__="environment";InputPort.__class__="input-port";OutputPort.__class__="output-port";OutputStringPort.__class__="output-string-port";InputStringPort.__class__="input-string-port";InputFilePort.__class__="input-file-port";OutputFilePort.__class__="output-file-port";LipsError.__class__="lips-error";[LNumber,LComplex,LRational,LFloat,LBigInteger].forEach(function(e){e.__class__="number"});LCharacter.__class__="character";LSymbol.__class__="symbol";LString.__class__="string";QuotedPromise.__class__="promise";var lips={version:"1.0.0-beta.14",banner:banner,date:"Fri, 04 Jun 2021 11:25:19 +0000",exec:exec,parse:compose(uniterate_async,parse),tokenize:tokenize,evaluate:_evaluate,serialize:serialize,unserialize:unserialize,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,InputFilePort:InputFilePort,OutputFilePort:OutputFilePort,InputStringPort:InputStringPort,OutputStringPort:OutputStringPort,InputByteVectorPort:InputByteVectorPort,OutputByteVectorPort:OutputByteVectorPort,InputBinaryFilePort:InputBinaryFilePort,OutputBinaryFilePort:OutputBinaryFilePort,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,rationalize:rationalize};global_env.set("lips",lips);return lips})})(); \ No newline at end of file +(function(){"use strict";function unwrapExports(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e["default"]:e}function createCommonjsModule(e,r){return r={exports:{}},e(r,r.exports),r.exports}var readOnlyError=createCommonjsModule(function(e){function r(e){throw new TypeError('"'+e+'" is read-only')}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});var _readOnlyError=unwrapExports(readOnlyError);var setPrototypeOf=createCommonjsModule(function(t){function n(e,r){t.exports=n=Object.setPrototypeOf||function e(r,t){r.__proto__=t;return r};t.exports["default"]=t.exports,t.exports.__esModule=true;return n(e,r)}t.exports=n;t.exports["default"]=t.exports,t.exports.__esModule=true});unwrapExports(setPrototypeOf);var isNativeReflectConstruct=createCommonjsModule(function(e){function r(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true}catch(e){return false}}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});unwrapExports(isNativeReflectConstruct);var construct=createCommonjsModule(function(n){function i(e,r,t){if(isNativeReflectConstruct()){n.exports=i=Reflect.construct;n.exports["default"]=n.exports,n.exports.__esModule=true}else{n.exports=i=function e(r,t,n){var i=[null];i.push.apply(i,t);var a=Function.bind.apply(r,i);var o=new a;if(n)setPrototypeOf(o,n.prototype);return o};n.exports["default"]=n.exports,n.exports.__esModule=true}return i.apply(null,arguments)}n.exports=i;n.exports["default"]=n.exports,n.exports.__esModule=true});var _construct=unwrapExports(construct);var arrayWithHoles=createCommonjsModule(function(e){function r(e){if(Array.isArray(e))return e}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});unwrapExports(arrayWithHoles);var iterableToArray=createCommonjsModule(function(e){function r(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});unwrapExports(iterableToArray);var arrayLikeToArray=createCommonjsModule(function(e){function r(e,r){if(r==null||r>e.length)r=e.length;for(var t=0,n=new Array(r);t=0)continue;t[i]=e[i]}return t}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});unwrapExports(objectWithoutPropertiesLoose);var objectWithoutProperties=createCommonjsModule(function(e){function r(e,r){if(e==null)return{};var t=objectWithoutPropertiesLoose(e,r);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;t[n]=e[n]}}return t}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});var _objectWithoutProperties=unwrapExports(objectWithoutProperties);var iterableToArrayLimit=createCommonjsModule(function(e){function r(e,r){var t=e&&(typeof Symbol!=="undefined"&&e[Symbol.iterator]||e["@@iterator"]);if(t==null)return;var n=[];var i=true;var a=false;var o,u;try{for(t=t.call(e);!(i=(o=t.next()).done);i=true){n.push(o.value);if(r&&n.length===r)break}}catch(e){a=true;u=e}finally{try{if(!i&&t["return"]!=null)t["return"]()}finally{if(a)throw u}}return n}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});unwrapExports(iterableToArrayLimit);var slicedToArray=createCommonjsModule(function(e){function r(e,r){return arrayWithHoles(e)||iterableToArrayLimit(e,r)||unsupportedIterableToArray(e,r)||nonIterableRest()}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});var _slicedToArray=unwrapExports(slicedToArray);var _typeof_1=createCommonjsModule(function(r){function t(e){"@babel/helpers - typeof";if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){r.exports=t=function e(r){return typeof r};r.exports["default"]=r.exports,r.exports.__esModule=true}else{r.exports=t=function e(r){return r&&typeof Symbol==="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r};r.exports["default"]=r.exports,r.exports.__esModule=true}return t(e)}r.exports=t;r.exports["default"]=r.exports,r.exports.__esModule=true});var _typeof=unwrapExports(_typeof_1);var asyncIterator=createCommonjsModule(function(e){function r(e){var r;if(typeof Symbol!=="undefined"){if(Symbol.asyncIterator)r=e[Symbol.asyncIterator];if(r==null&&Symbol.iterator)r=e[Symbol.iterator]}if(r==null)r=e["@@asyncIterator"];if(r==null)r=e["@@iterator"];if(r==null)throw new TypeError("Object is not async iterable");return r.call(e)}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});var _asyncIterator=unwrapExports(asyncIterator);var AwaitValue=createCommonjsModule(function(e){function r(e){this.wrapped=e}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});unwrapExports(AwaitValue);var awaitAsyncGenerator=createCommonjsModule(function(e){function r(e){return new AwaitValue(e)}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});var _awaitAsyncGenerator=unwrapExports(awaitAsyncGenerator);var AsyncGenerator_1=createCommonjsModule(function(e){function r(a){var o,u;function e(n,i){return new Promise(function(e,r){var t={key:n,arg:i,resolve:e,reject:r,next:null};if(u){u=u.next=t}else{o=u=t;c(n,i)}})}function c(r,e){try{var t=a[r](e);var n=t.value;var i=n instanceof AwaitValue;Promise.resolve(i?n.wrapped:n).then(function(e){if(i){c(r==="return"?"return":"next",e);return}s(t.done?"return":"normal",e)},function(e){c("throw",e)})}catch(e){s("throw",e)}}function s(e,r){switch(e){case"return":o.resolve({value:r,done:true});break;case"throw":o.reject(r);break;default:o.resolve({value:r,done:false});break}o=o.next;if(o){c(o.key,o.arg)}else{u=null}}this._invoke=e;if(typeof a["return"]!=="function"){this["return"]=undefined}}r.prototype[typeof Symbol==="function"&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this};r.prototype.next=function(e){return this._invoke("next",e)};r.prototype["throw"]=function(e){return this._invoke("throw",e)};r.prototype["return"]=function(e){return this._invoke("return",e)};e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});unwrapExports(AsyncGenerator_1);var wrapAsyncGenerator=createCommonjsModule(function(e){function r(e){return function(){return new AsyncGenerator_1(e.apply(this,arguments))}}e.exports=r;e.exports["default"]=e.exports,e.exports.__esModule=true});var _wrapAsyncGenerator=unwrapExports(wrapAsyncGenerator);var runtime_1=createCommonjsModule(function(e){var r=function(o){var e=Object.prototype;var l=e.hasOwnProperty;var c;var r=typeof Symbol==="function"?Symbol:{};var i=r.iterator||"@@iterator";var t=r.asyncIterator||"@@asyncIterator";var n=r.toStringTag||"@@toStringTag";function a(e,r,t){Object.defineProperty(e,r,{value:t,enumerable:true,configurable:true,writable:true});return e[r]}try{a({},"")}catch(e){a=function(e,r,t){return e[r]=t}}function u(e,r,t,n){var i=r&&r.prototype instanceof s?r:s;var a=Object.create(i.prototype);var o=new S(n||[]);a._invoke=F(e,t,o);return a}o.wrap=u;function f(e,r,t){try{return{type:"normal",arg:e.call(r,t)}}catch(e){return{type:"throw",arg:e}}}var _="suspendedStart";var p="suspendedYield";var h="executing";var d="completed";var m={};function s(){}function v(){}function y(){}var b={};b[i]=function(){return this};var g=Object.getPrototypeOf;var w=g&&g(g(P([])));if(w&&w!==e&&l.call(w,i)){b=w}var D=y.prototype=s.prototype=Object.create(b);v.prototype=D.constructor=y;y.constructor=v;v.displayName=a(y,n,"GeneratorFunction");function x(e){["next","throw","return"].forEach(function(r){a(e,r,function(e){return this._invoke(r,e)})})}o.isGeneratorFunction=function(e){var r=typeof e==="function"&&e.constructor;return r?r===v||(r.displayName||r.name)==="GeneratorFunction":false};o.mark=function(e){if(Object.setPrototypeOf){Object.setPrototypeOf(e,y)}else{e.__proto__=y;a(e,n,"GeneratorFunction")}e.prototype=Object.create(D);return e};o.awrap=function(e){return{__await:e}};function L(u,c){function s(e,r,t,n){var i=f(u[e],u,r);if(i.type==="throw"){n(i.arg)}else{var a=i.arg;var o=a.value;if(o&&typeof o==="object"&&l.call(o,"__await")){return c.resolve(o.__await).then(function(e){s("next",e,t,n)},function(e){s("throw",e,t,n)})}return c.resolve(o).then(function(e){a.value=e;t(a)},function(e){return s("throw",e,t,n)})}}var r;function e(t,n){function e(){return new c(function(e,r){s(t,n,e,r)})}return r=r?r.then(e,e):e()}this._invoke=e}x(L.prototype);L.prototype[t]=function(){return this};o.AsyncIterator=L;o.async=function(e,r,t,n,i){if(i===void 0)i=Promise;var a=new L(u(e,r,t,n),i);return o.isGeneratorFunction(r)?a:a.next().then(function(e){return e.done?e.value:a.next()})};function F(o,u,c){var s=_;return function e(r,t){if(s===h){throw new Error("Generator is already running")}if(s===d){if(r==="throw"){throw t}return k()}c.method=r;c.arg=t;while(true){var n=c.delegate;if(n){var i=E(n,c);if(i){if(i===m)continue;return i}}if(c.method==="next"){c.sent=c._sent=c.arg}else if(c.method==="throw"){if(s===_){s=d;throw c.arg}c.dispatchException(c.arg)}else if(c.method==="return"){c.abrupt("return",c.arg)}s=h;var a=f(o,u,c);if(a.type==="normal"){s=c.done?d:p;if(a.arg===m){continue}return{value:a.arg,done:c.done}}else if(a.type==="throw"){s=d;c.method="throw";c.arg=a.arg}}}}function E(e,r){var t=e.iterator[r.method];if(t===c){r.delegate=null;if(r.method==="throw"){if(e.iterator["return"]){r.method="return";r.arg=c;E(e,r);if(r.method==="throw"){return m}}r.method="throw";r.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var n=f(t,e.iterator,r.arg);if(n.type==="throw"){r.method="throw";r.arg=n.arg;r.delegate=null;return m}var i=n.arg;if(!i){r.method="throw";r.arg=new TypeError("iterator result is not an object");r.delegate=null;return m}if(i.done){r[e.resultName]=i.value;r.next=e.nextLoc;if(r.method!=="return"){r.method="next";r.arg=c}}else{return i}r.delegate=null;return m}x(D);a(D,n,"Generator");D[i]=function(){return this};D.toString=function(){return"[object Generator]"};function A(e){var r={tryLoc:e[0]};if(1 in e){r.catchLoc=e[1]}if(2 in e){r.finallyLoc=e[2];r.afterLoc=e[3]}this.tryEntries.push(r)}function C(e){var r=e.completion||{};r.type="normal";delete r.arg;e.completion=r}function S(e){this.tryEntries=[{tryLoc:"root"}];e.forEach(A,this);this.reset(true)}o.keys=function(t){var n=[];for(var e in t){n.push(e)}n.reverse();return function e(){while(n.length){var r=n.pop();if(r in t){e.value=r;e.done=false;return e}}e.done=true;return e}};function P(r){if(r){var e=r[i];if(e){return e.call(r)}if(typeof r.next==="function"){return r}if(!isNaN(r.length)){var t=-1,n=function e(){while(++t=0;--r){var i=this.tryEntries[r];var a=i.completion;if(i.tryLoc==="root"){return e("end")}if(i.tryLoc<=this.prev){var o=l.call(i,"catchLoc");var u=l.call(i,"finallyLoc");if(o&&u){if(this.prev=0;--t){var n=this.tryEntries[t];if(n.tryLoc<=this.prev&&l.call(n,"finallyLoc")&&this.prev=0;--r){var t=this.tryEntries[r];if(t.finallyLoc===e){this.complete(t.completion,t.afterLoc);C(t);return m}}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.tryLoc===e){var n=t.completion;if(n.type==="throw"){var i=n.arg;C(t)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,t){this.delegate={iterator:P(e),resultName:r,nextLoc:t};if(this.method==="next"){this.arg=c}return m}};return o}(e.exports);try{regeneratorRuntime=r}catch(e){Function("r","regeneratorRuntime = r")(r)}});var regenerator=runtime_1;var _excluded=["token"],_excluded2=["stderr","stdin","stdout"];function _createForOfIteratorHelper(r,e){var t=typeof Symbol!=="undefined"&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&typeof r.length==="number"){if(t)r=t;var n=0;var i=function e(){};return{s:i,n:function e(){if(n>=r.length)return{done:true};return{done:false,value:r[n++]}},e:function e(r){throw r},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a=true,o=false,u;return{s:function e(){t=t.call(r)},n:function e(){var r=t.next();a=r.done;return r},e:function e(r){o=true;u=r},f:function e(){try{if(!a&&t["return"]!=null)t["return"]()}finally{if(o)throw u}}}}function _unsupportedIterableToArray(e,r){if(!e)return;if(typeof e==="string")return _arrayLikeToArray(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);if(t==="Object"&&e.constructor)t=e.constructor.name;if(t==="Map"||t==="Set")return Array.from(e);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return _arrayLikeToArray(e,r)}function _arrayLikeToArray(e,r){if(r==null||r>e.length)r=e.length;for(var t=0,n=new Array(r);t1&&arguments[1]!==undefined$1?arguments[1]:null;var n=arguments[1]===true;function r(e){if(!is_debug()){return}var r=global_env.get("repr")(e);if(t===null||t instanceof RegExp&&t.test(r)){console.log(global_env.get("type")(e)+": "+r)}if(n){console.log(e)}}if(is_promise(e)){e.then(r)}else{r(e)}return e}function is_debug(){return user_env&&user_env.get("DEBUG",{throwError:false})}if(!root.fetch){root.fetch=function(i,a){a=a||{};return new Promise(function(e,r){var t=new XMLHttpRequest;t.open(a.method||"get",i,true);for(var n in a.headers){t.setRequestHeader(n,a.headers[n])}t.withCredentials=a.credentials=="include";t.onload=function(){e(u())};t.onerror=r;t.send(a.body||null);function u(){var n=[],i=[],a={},o;t.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,r,t){n.push(r=r.toLowerCase());i.push([r,t]);o=a[r];a[r]=o?"".concat(o,",").concat(t):t});return{ok:(t.status/100|0)==2,status:t.status,statusText:t.statusText,url:t.responseURL,clone:u,text:function e(){return Promise.resolve(t.responseText)},json:function e(){return Promise.resolve(t.responseText).then(JSON.parse)},blob:function e(){return Promise.resolve(new Blob([t.response]))},headers:{keys:function e(){return n},entries:function e(){return i},get:function e(r){return a[r.toLowerCase()]},has:function e(r){return r.toLowerCase()in a}}}}})}}function num_mnemicic_re(e){return e?"(?:#".concat(e,"(?:#[ie])?|#[ie]#").concat(e,")"):"(?:#[ie])?"}function gen_rational_re(e,r){return"".concat(num_mnemicic_re(e),"[+-]?").concat(r,"+/").concat(r,"+")}function gen_complex_re(e,r){return"".concat(num_mnemicic_re(e),"(?:[+-]?(?:").concat(r,"+/").concat(r,"+|nan.0|inf.0|").concat(r,"+))?(?:[+-]i|[+-]?(?:").concat(r,"+/").concat(r,"+|").concat(r,"+|nan.0|inf.0)i)(?=[()[\\]\\s]|$)")}function gen_integer_re(e,r){return"".concat(num_mnemicic_re(e),"[+-]?").concat(r,"+")}var re_re=/^#\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimyus]*)$/;var float_stre="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)";var complex_float_stre="(?:#[ie])?(?:[+-]?(?:[0-9]+/[0-9]+|nan.0|inf.0|".concat(float_stre,"|[+-]?[0-9]+))?(?:").concat(float_stre,"|[+-](?:[0-9]+/[0-9]+|[0-9]+|nan.0|inf.0))i");var float_re=new RegExp("^(#[ie])?".concat(float_stre,"$"),"i");function make_complex_match_re(e,r){var t=e==="x"?"(?!\\+|".concat(r,")"):"(?!\\.|".concat(r,")");var n="";if(e===""){n="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+(?![0-9]))(?:[eE][-+]?[0-9]+)?))"}return new RegExp("^((?:(?:".concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(r,"+/").concat(r,"+(?!").concat(r,")|[+-]?").concat(r,"+)").concat(t,")?)(").concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(r,"+/").concat(r,"+|[+-]?").concat(r,"+|[+-])i$"),"i")}var complex_list_re=function(){var a={};[[10,"","[0-9]"],[16,"x","[0-9a-fA-F]"],[8,"o","[0-7]"],[2,"b","[01]"]].forEach(function(e){var r=_slicedToArray(e,3),t=r[0],n=r[1],i=r[2];a[t]=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 r=[];var t=0;var n=e.length;while(t=55296&&i<=56319&&t1&&arguments[1]!==undefined$1?arguments[1]:10;var t=num_pre_parse(e);var n=t.number.split("/");var i=LRational({num:LNumber([n[0],t.radix||r]),denom:LNumber([n[1],t.radix||r])});if(t.inexact){return i.valueOf()}else{return i}}function parse_integer(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:10;var t=num_pre_parse(e);if(t.inexact){return LFloat(parseInt(t.number,t.radix||r))}return LNumber([t.number,t.radix||r])}function parse_character(e){var r=e.match(/#\\x([0-9a-f]+)$/i);var t;if(r){var n=parseInt(r[1],16);t=String.fromCodePoint(n)}else{r=e.match(/#\\(.+)$/);if(r){t=r[1]}}if(t){return LCharacter(t)}throw new Error("Parse: invalid character")}function parse_complex(e){var i=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:10;function r(e){var r;if(e==="+"){r=LNumber(1)}else if(e==="-"){r=LNumber(-1)}else if(e.match(int_bare_re)){r=LNumber([e,i])}else if(e.match(rational_bare_re)){var t=e.split("/");r=LRational({num:LNumber([t[0],i]),denom:LNumber([t[1],i])})}else if(e.match(float_re)){var n=parse_float(e);if(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(r.valueOf())}return r}var a=num_pre_parse(e);i=a.radix||i;var t;var n=a.number.match(complex_bare_match_re);if(i!==10&&n){t=n}else{t=a.number.match(complex_list_re[i])}var o,u;u=r(t[2]);if(t[1]){o=r(t[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 r=e.match(/^(([-+]?[0-9]*)(?:\.([0-9]+))?)e([-+]?[0-9]+)/i);if(r){var t=parseInt(r[4],10);var n;var i=r[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var a=r[3]&&r[3].length;if(i0){return LNumber(a).mul(u)}}}t=LFloat(t);if(r.exact){return t.toRational()}return t}function parse_string(e){e=e.replace(/\\x([0-9a-f]+);/gi,function(e,r){return"\\u"+r.padStart(4,"0")}).replace(/\n/g,"\\n");var r=e.match(/(\\*)(\\x[0-9A-F])/i);if(r&&r[1].length%2===0){throw new Error("Invalid string literal, unclosed ".concat(r[2]))}try{return LString(JSON.parse(e))}catch(e){throw new Error("Invalid string literal")}}function parse_symbol(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var t={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,r){return String.fromCharCode(parseInt("0"+r,16))}).replace(/\\(.)/g,function(e,r){return t[r]||r})}return new LSymbol(e)}function parse_argument(e){if(constants.hasOwnProperty(e)){return constants[e]}if(e.match(/^"[\s\S]*"$/)){return parse_string(e)}else if(e[0]==="#"){var r=e.match(re_re);if(r){return new RegExp(r[1],r[2])}else if(e.match(char_re)){return parse_character(e)}var t=e.match(/#\\(.+)/);if(t&&ucs2decode(t[1]).length===1){return parse_character(e)}}if(e.match(/[0-9a-f]|[+-]i/i)){if(e.match(int_re)){return parse_integer(e)}else if(e.match(float_re)){return parse_float(e)}else if(e.match(rational_re)){return parse_rational(e)}else if(e.match(complex_re)){return parse_complex(e)}}if(e.match(/^#[iexobd]/)){throw new Error("Invalid numeric constant: "+e)}return parse_symbol(e)}function is_symbol_string(e){return!(["(",")","[","]"].includes(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","true","false"].includes(e))}var string_re=/"(?:\\[\S\s]|[^"])*"?/g;function escape_regex(e){if(typeof e==="string"){var r=/([-\\^$[\]()+{}?*.|])/g;return e.replace(r,"\\$1")}return e}function Stack(){this.data=[]}Stack.prototype.push=function(e){this.data.push(e)};Stack.prototype.top=function(){return this.data[this.data.length-1]};Stack.prototype.pop=function(){return this.data.pop()};Stack.prototype.is_empty=function(){return!this.data.length};function tokens(e){if(e instanceof LString){e=e.valueOf()}var r=new Lexer(e,{whitespace:true});var t=[];while(true){var n=r.peek(true);if(n===eof){break}t.push(n);r.skip()}return t}function multiline_formatter(e){var r=e.token,t=_objectWithoutProperties(e,_excluded);if(r.match(/^"[\s\S]*"$/)&&r.match(/\n/)){var n=new RegExp("^ {1,"+(e.col+1)+"}","mg");r=r.replace(n,"")}return _objectSpread({token:r},t)}function Thunk(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:function(){};this.fn=e;this.cont=r}Thunk.prototype.toString=function(){return"#"};function trampoline(n){return function(){for(var e=arguments.length,r=new Array(e),t=0;t1&&arguments[1]!==undefined$1?arguments[1]:false;if(e instanceof LString){e=e.toString()}if(r){return tokens(e)}else{var t=tokens(e).map(function(e){if(e.token==="#\\ "){return e.token}return e.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return strip_s_comments(t)}}function strip_s_comments(e){var r=0;var t=null;var n=[];for(var i=0;i0&&arguments[0]!==undefined$1?arguments[0]:null;if(e instanceof LSymbol){e=e.valueOf()}if(is_gensym(e)){return LSymbol(e)}if(e!==null){return new LSymbol(Symbol("#:".concat(e)))}r++;return new LSymbol(Symbol("#:g".concat(r)))}}();function QuotedPromise(e){var t=this;var n={pending:true,rejected:false,fulfilled:false,reason:undefined$1,type:undefined$1};e=e.then(function(e){n.type=type(e);n.fulfilled=true;n.pending=false;return e});read_only(this,"_promise",e,{hidden:true});if(is_function(e["catch"])){e=e["catch"](function(e){n.rejected=true;n.pending=false;n.reason=e})}Object.keys(n).forEach(function(r){Object.defineProperty(t,"__".concat(r,"__"),{enumerable:true,get:function e(){return n[r]}})});read_only(this,"__promise__",e);this.then=false}QuotedPromise.prototype.then=function(e){return new QuotedPromise(this.valueOf().then(e))};QuotedPromise.prototype["catch"]=function(e){return new QuotedPromise(this.valueOf()["catch"](e))};QuotedPromise.prototype.valueOf=function(){if(!this._promise){throw new Error("QuotedPromise: invalid promise created")}return this._promise};QuotedPromise.prototype.toString=function(){if(this.__pending__){return QuotedPromise.pending_str}if(this.__rejected__){return QuotedPromise.rejected_str}return"#")};QuotedPromise.pending_str="#";QuotedPromise.rejected_str="#";function promise_all(e){if(Array.isArray(e)){return Promise.all(escape_quoted_promises(e)).then(unescape_quoted_promises)}return e}function escape_quoted_promises(e){var r=new Array(e.length),t=e.length;while(t--){var n=e[t];if(n instanceof QuotedPromise){r[t]=new Value(n)}else{r[t]=n}}return r}function unescape_quoted_promises(e){var r=new Array(e.length),t=e.length;while(t--){var n=e[t];if(n instanceof Value){r[t]=n.valueOf()}else{r[t]=n}}return r}var specials={LITERAL:Symbol["for"]("literal"),SPLICE:Symbol["for"]("splice"),SYMBOL:Symbol["for"]("symbol"),names:function e(){return Object.keys(this._specials)},type:function e(r){return this.get(r).type},get:function e(r){return this._specials[r]},off:function e(r){var t=this;var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:null;if(Array.isArray(r)){r.forEach(function(e){return t.off(e,n)})}else if(n===null){delete this._events[r]}else{this._events=this._events.filter(function(e){return e!==n})}},on:function e(r,t){var n=this;if(Array.isArray(r)){r.forEach(function(e){return n.on(e,t)})}else if(!this._events[r]){this._events[r]=[t]}else{this._events[r].push(t)}},trigger:function e(r){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i",new LSymbol("quote-promise"),specials.LITERAL]];Object.defineProperty(specials,"builtin",{writable:false,value:defined_specials.map(function(e){return e[0]})});defined_specials.forEach(function(e){var r=_slicedToArray(e,3),t=r[0],n=r[1],i=r[2];specials.append(t,n,i)});var Lexer=function(){function p(e){var r=this;var t=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},n=t.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(t){Object.defineProperty(r,t,{configurable:false,enumerable:false,get:function e(){return a[t]},set:function e(r){a[t]=r}})});this._whitespace=i;this._i=this._line=this._col=this._newline=0;this._state=this._next=this._token=null;this._prev_char=""}_createClass(p,[{key:"get",value:function e(r){return this.__internal[r]}},{key:"set",value:function e(r,t){this.__internal[r]=t}},{key:"token",value:function e(){var r=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:false;if(r){var t=this._line;if(this._whitespace&&this._token==="\n"){--t}return{token:this._token,col:this._col,offset:this._i,line:t}}return this._token}},{key:"peek",value:function e(){var r=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:false;if(this._i>=this.__input__.length){return eof}if(this._token){return this.token(r)}var t=this.next_token();if(t){this._token=this.__input__.substring(this._i,this._next);return this.token(r)}return eof}},{key:"skip",value:function e(){if(this._next!==null){this._token=null;this._i=this._next}}},{key:"read_line",value:function e(){var r=this.__input__.length;if(this._i>=r){return eof}for(var t=this._i;t=t){return eof}if(r+this._i>=t){return this.read_rest()}var n=this._i+r;var i=this.__input__.substring(this._i,n);var 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 r=this.peek_char();this.skip_char();return r}},{key:"skip_char",value:function e(){if(this._i1&&arguments[1]!==undefined$1?arguments[1]:{},n=t.prev_char,i=t["char"],a=t.next_char;var o=_slicedToArray(r,4),u=o[0],c=o[1],s=o[2],l=o[3];if(r.length!==5){throw new Error("Lexer: Invald rule of length ".concat(r.length))}if(!i.match(u)){return false}if(!match_or_null(c,n)){return false}if(!match_or_null(s,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 r=true;e:for(var t=this._i,n=this.__input__.length;t2&&arguments[2]!==undefined$1?arguments[2]:null;var i=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:null;if(r.length===0){throw new Error("Lexer: invalid literal rule")}if(r.length===1){return[[r,n,i,null,null]]}var a=[];for(var o=0,u=r.length;o1&&arguments[1]!==undefined$1?arguments[1]:{},t=r.env,n=r.meta,i=n===void 0?false:n,a=r.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__",t);read_only(this,"_meta",i,{hidden:true});read_only(this,"_refs",[],{hidden:true})}_createClass(u,[{key:"resolve",value:function e(r){return this.__env__&&this.__env__.get(r,{throwError:false})}},{key:"peek",value:function(){var e=_asyncToGenerator(regenerator.mark(function e(){var t;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:t=this.__lexer__.peek(true);if(!(t===eof)){r.next=4;break}return r.abrupt("return",eof);case 4:if(!this.is_comment(t.token)){r.next=7;break}this.skip();return r.abrupt("continue",0);case 7:if(!(t.token==="#;")){r.next=14;break}this.skip();if(!(this.__lexer__.peek()===eof)){r.next=11;break}throw new Error("Lexer: syntax error eof found after comment");case 11:r.next=13;return this._read_object();case 13:return r.abrupt("continue",0);case 14:return r.abrupt("break",17);case 17:t=this._formatter(t);if(!this._meta){r.next=20;break}return r.abrupt("return",t);case 20:return r.abrupt("return",t.token);case 21:case"end":return r.stop()}}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"reset",value:function e(){this._refs.length=0}},{key:"skip",value:function e(){this.__lexer__.skip()}},{key:"is_special",value:function e(r){return specials.names().includes(r)}},{key:"is_builtin",value:function e(r){return specials.builtin.includes(r)}},{key:"read",value:function(){var e=_asyncToGenerator(regenerator.mark(function e(){var t;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:r.next=2;return this.peek();case 2:t=r.sent;this.skip();return r.abrupt("return",t);case 5:case"end":return r.stop()}}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"match_datum_label",value:function e(r){var t=r.match(/^#([0-9]+)=$/);return t&&t[1]}},{key:"match_datum_ref",value:function e(r){var t=r.match(/^#([0-9]+)#$/);return t&&t[1]}},{key:"is_open",value:function e(r){return["(","["].includes(r)}},{key:"is_close",value:function e(r){return[")","]"].includes(r)}},{key:"read_list",value:function(){var e=_asyncToGenerator(regenerator.mark(function e(){var t,n,i,a;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:t=_nil,n=t;case 1:r.next=4;return this.peek();case 4:i=r.sent;if(!(i===eof)){r.next=7;break}return r.abrupt("break",27);case 7:if(!this.is_close(i)){r.next=10;break}this.skip();return r.abrupt("break",27);case 10:if(!(i==="."&&t!==_nil)){r.next=17;break}this.skip();r.next=14;return this._read_object();case 14:n.cdr=r.sent;r.next=25;break;case 17:r.t0=Pair;r.next=20;return this._read_object();case 20:r.t1=r.sent;r.t2=_nil;a=new r.t0(r.t1,r.t2);if(t===_nil){t=a}else{n.cdr=a}n=a;case 25:r.next=1;break;case 27:return r.abrupt("return",t);case 28:case"end":return r.stop()}}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"read_value",value:function(){var e=_asyncToGenerator(regenerator.mark(function e(){var t;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:r.next=2;return this.read();case 2:t=r.sent;if(!(t===eof)){r.next=5;break}throw new Error("Parser: Expected token eof found");case 5:return r.abrupt("return",parse_argument(t));case 6:case"end":return r.stop()}}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"is_comment",value:function e(r){return r.match(/^;/)||r.match(/^#\|/)&&r.match(/\|#$/)}},{key:"evaluate",value:function e(r){return _evaluate(r,{env:this.__env__,error:function e(r){throw r}})}},{key:"read_object",value:function(){var e=_asyncToGenerator(regenerator.mark(function e(){var t;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:this.reset();r.next=3;return this._read_object();case 3:t=r.sent;if(t instanceof DatumReference){t=t.valueOf()}if(!this._refs.length){r.next=7;break}return r.abrupt("return",this._resolve_object(t));case 7:return r.abrupt("return",t);case 8:case"end":return r.stop()}}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"_resolve_object",value:function(){var r=_asyncToGenerator(regenerator.mark(function e(t){var n=this;var i;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!Array.isArray(t)){r.next=2;break}return r.abrupt("return",t.map(function(e){return n._resolve_object(e)}));case 2:if(!is_plain_object(t)){r.next=6;break}i={};Object.keys(t).forEach(function(e){i[e]=n._resolve_object(t[e])});return r.abrupt("return",i);case 6:if(!(t instanceof Pair)){r.next=8;break}return r.abrupt("return",this._resolve_pair(t));case 8:return r.abrupt("return",t);case 9:case"end":return r.stop()}}},e,this)}));function e(e){return r.apply(this,arguments)}return e}()},{key:"_resolve_pair",value:function(){var r=_asyncToGenerator(regenerator.mark(function e(t){return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!(t instanceof Pair)){r.next=15;break}if(!(t.car instanceof DatumReference)){r.next=7;break}r.next=4;return t.car.valueOf();case 4:t.car=r.sent;r.next=8;break;case 7:this._resolve_pair(t.car);case 8:if(!(t.cdr instanceof DatumReference)){r.next=14;break}r.next=11;return t.cdr.valueOf();case 11:t.cdr=r.sent;r.next=15;break;case 14:this._resolve_pair(t.cdr);case 15:return r.abrupt("return",t);case 16:case"end":return r.stop()}}},e,this)}));function e(e){return r.apply(this,arguments)}return e}()},{key:"_read_object",value:function(){var e=_asyncToGenerator(regenerator.mark(function e(){var t,n,i,a,o,u,c,s,l;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:r.next=2;return this.peek();case 2:t=r.sent;if(!(t===eof)){r.next=5;break}return r.abrupt("return",t);case 5:if(!this.is_special(t)){r.next=35;break}n=specials.get(t);i=this.is_builtin(t);this.skip();r.next=11;return this._read_object();case 11:o=r.sent;if(i){r.next=22;break}u=this.__env__.get(n.symbol);if(!(typeof u==="function")){r.next=22;break}if(!is_literal(t)){r.next=19;break}return r.abrupt("return",u.call(this.__env__,o));case 19:if(!(o instanceof Pair)){r.next=21;break}return r.abrupt("return",u.apply(this.__env__,o.to_array(false)));case 21:throw new Error("Parse Error: Invalid parser extension "+"invocation ".concat(n.symbol));case 22:if(is_literal(t)){a=new Pair(n.symbol,new Pair(o,_nil))}else{a=new Pair(n.symbol,o)}if(!i){r.next=25;break}return r.abrupt("return",a);case 25:if(!(u instanceof Macro)){r.next=34;break}r.next=28;return this.evaluate(a);case 28:c=r.sent;if(!(c instanceof Pair||c instanceof LSymbol)){r.next=31;break}return r.abrupt("return",Pair.fromArray([LSymbol("quote"),c]));case 31:return r.abrupt("return",c);case 34:throw new Error("Parse Error: invlid parser extension: "+n.symbol);case 35:s=this.match_datum_ref(t);if(!(s!==null)){r.next=41;break}this.skip();if(!this._refs[s]){r.next=40;break}return r.abrupt("return",new DatumReference(s,this._refs[s]));case 40:throw new Error("Parse Error: invalid datum label #".concat(s,"#"));case 41:l=this.match_datum_label(t);if(!(l!==null)){r.next=48;break}this.skip();this._refs[l]=this._read_object();return r.abrupt("return",this._refs[l]);case 48:if(!this.is_open(t)){r.next=53;break}this.skip();return r.abrupt("return",this.read_list());case 53:return r.abrupt("return",this.read_value());case 54:case"end":return r.stop()}}},e,this)}));function r(){return e.apply(this,arguments)}return r}()}]);return u}();var DatumReference=function(){function t(e,r){_classCallCheck(this,t);this.name=e;this.data=r}_createClass(t,[{key:"valueOf",value:function e(){return this.data}}]);return t}();function parse(e,r){return _parse.apply(this,arguments)}function _parse(){_parse=_wrapAsyncGenerator(regenerator.mark(function e(t,n){var i,a;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!n){if(global_env){n=global_env.get("**interaction-environment**",{throwError:false})}else{n=user_env}}i=new Parser(t,{env:n});case 2:r.next=5;return _awaitAsyncGenerator(i.read_object());case 5:a=r.sent;if(!(a===eof)){r.next=8;break}return r.abrupt("break",12);case 8:r.next=10;return a;case 10:r.next=2;break;case 12:case"end":return r.stop()}}},e)}));return _parse.apply(this,arguments)}function unpromise(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:function(e){return e};var t=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:null;if(is_promise(e)){var n=e.then(r);if(t===null){return n}else{return n["catch"](t)}}if(e instanceof Array){return unpromise_array(e,r,t)}if(is_plain_object(e)){return unpromise_object(e,r,t)}return r(e)}function unpromise_array(r,e,t){if(r.find(is_promise)){return unpromise(promise_all(r),function(e){if(Object.isFrozen(r)){Object.freeze(e)}return e},t)}return e(r)}function unpromise_object(r,e,t){var i=Object.keys(r);var n=[],a=[];var o=i.length;while(o--){var u=i[o];var c=r[u];n[o]=c;if(is_promise(c)){a.push(c)}}if(a.length){return unpromise(promise_all(n),function(e){var n={};e.forEach(function(e,r){var t=i[r];n[t]=e});if(Object.isFrozen(r)){Object.freeze(n)}return n},t)}return e(r)}function read_only(e,r,t){var n=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:{},i=n.hidden,a=i===void 0?false:i;Object.defineProperty(e,r,{value:t,configurable:true,enumerable:!a})}function uniterate_async(e){return _uniterate_async.apply(this,arguments)}function _uniterate_async(){_uniterate_async=_asyncToGenerator(regenerator.mark(function e(t){var n,i,a,o,u,c,s,l;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:n=[];i=true;a=false;r.prev=3;u=_asyncIterator(t);case 5:r.next=7;return u.next();case 7:c=r.sent;i=c.done;r.next=11;return c.value;case 11:s=r.sent;if(i){r.next=18;break}l=s;n.push(l);case 15:i=true;r.next=5;break;case 18:r.next=24;break;case 20:r.prev=20;r.t0=r["catch"](3);a=true;o=r.t0;case 24:r.prev=24;r.prev=25;if(!(!i&&u["return"]!=null)){r.next=29;break}r.next=29;return u["return"]();case 29:r.prev=29;if(!a){r.next=32;break}throw o;case 32:return r.finish(29);case 33:return r.finish(24);case 34:return r.abrupt("return",n);case 35:case"end":return r.stop()}}},e,null,[[3,20,24,34],[25,,29,33]])}));return _uniterate_async.apply(this,arguments)}function matcher(e,r){if(r instanceof RegExp){return function(e){return String(e).match(r)}}else if(is_function(r)){return r}throw new Error("Invalid matcher")}function doc(e,r,t,n){if(typeof e!=="string"){r=arguments[0];t=arguments[1];n=arguments[2];e=null}if(t){if(n){r.__doc__=t}else{r.__doc__=trim_lines(t)}}if(e){r.__name__=e}else if(r.name&&!is_lambda(r)){r.__name__=r.name}return r}function trim_lines(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function previousSexp(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:1;var t=e.length;if(r<=0){throw Error("previousSexp: Invalid argument sexp = ".concat(r))}e:while(r--&&t>=0){var n=1;while(n>0){var i=e[--t];if(!i){break e}if(i==="("||i.token==="("){n--}else if(i===")"||i.token===")"){n++}}t--}return e.slice(t+1)}function lineIndent(e){if(!e||!e.length){return 0}var r=e.length;if(e[r-1].token==="\n"){return 0}while(--r){if(e[r].token==="\n"){var t=(e[r+1]||{}).token;if(t){return t.length}}}return 0}function match(e,r){return l(e,r)===r.length;function l(t,n){function e(e,r){var t=_createForOfIteratorHelper(e),n;try{for(t.s();!(n=t.n()).done;){var i=n.value;var a=l(i,r);if(a!==-1){return a}}}catch(e){t.e(e)}finally{t.f()}return-1}function r(){return t[a]===Symbol["for"]("symbol")&&!is_symbol_string(n[u])}function i(){var e=t[a+1];var r=n[u+1];if(e!==undefined$1&&r!==undefined$1){return l([e],[r])}}var a=0;var o={};for(var u=0;u0){continue}}else if(r()){return-1}}else if(t[a]instanceof Array){var s=l(t[a],n.slice(u));if(s===-1||s+u>n.length){return-1}u+=s-1;a++;continue}else{return-1}a++}if(t.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|\*)?)$/],shift:{1:["&","#"]}}};Formatter.match=match;Formatter.prototype._options=function e(r){var t=Formatter.defaults;if(typeof r==="undefined"){return Object.assign({},t)}var n=r&&r.exceptions||{};var i=n.specials||[];var a=n.shift||{1:[]};return _objectSpread(_objectSpread(_objectSpread({},t),r),{},{exceptions:{specials:[].concat(_toConsumableArray(t.exceptions.specials),_toConsumableArray(i)),shift:_objectSpread(_objectSpread({},a),{},{1:[].concat(_toConsumableArray(t.exceptions.shift[1]),_toConsumableArray(a[1]))})}})};Formatter.prototype.indent=function e(r){var t=tokenize(this.__code__,true);return this._indent(t,r)};Formatter.exception_shift=function(a,e){function r(e){if(!e.length){return false}if(e.indexOf(a)!==-1){return true}else{var r=e.filter(function(e){return e instanceof RegExp});if(!r.length){return false}var t=_createForOfIteratorHelper(r),n;try{for(t.s();!(n=t.n()).done;){var i=n.value;if(a.match(i)){return true}}}catch(e){t.e(e)}finally{t.f()}}return false}if(r(e.exceptions.specials)){return e.indent}var t=e.exceptions.shift;for(var n=0,i=Object.entries(t);n0){n.offset=0}if(a.toString()===r.toString()&&balanced(a)){return n.offset+a[0].col}else if(a.length===1){return n.offset+a[0].col+1}else{var c=-1;if(o){var s=Formatter.exception_shift(o.token,n);if(s!==-1){c=s}}if(c===-1){c=Formatter.exception_shift(a[1].token,n)}if(c!==-1){return n.offset+a[0].col+c}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,r=new Array(e),t=0;t")};Formatter.Pattern=Pattern;Formatter.Ahead=Ahead;var p_o=/^[[(]$/;var p_e=/^[\])]$/;var not_p=/[^()[\]]/;var not_close=new Ahead(/[^)\]]/);var glob=Symbol["for"]("*");var sexp_or_atom=new Pattern([p_o,glob,p_e],[not_p],"+");var sexp=new Pattern([p_o,glob,p_e],"+");var symbol=new Pattern([Symbol["for"]("symbol")],"?");var symbols=new Pattern([Symbol["for"]("symbol")],"*");var identifiers=[p_o,symbols,p_e];var let_value=new Pattern([p_o,Symbol["for"]("symbol"),glob,p_e],"+");var def_lambda_re=keywords_re("define","lambda","define-macro","syntax-rules");var non_def=/^(?!.*\b(?:[()[\]]|define(?:-macro)?|let(?:\*|rec|-env|-syntax|)?|lambda|syntax-rules)\b).*$/;var let_re=/^(?:#:)?(let(?:\*|rec|-env|-syntax)?)$/;function keywords_re(){for(var e=arguments.length,r=new Array(e),t=0;t0&&!o[e]){o[e]=previousSexp(a,e)}});var u=_createForOfIteratorHelper(n),c;try{for(u.s();!(c=u.n()).done;){var s=_slicedToArray(c.value,3),l=s[0],f=s[1],_=s[2];f=f.valueOf();var p=f>0?o[f]:a;var h=match(l,p.filter(function(e){return e.trim()}));var d=t.slice(i).find(function(e){return e.trim()});if(h&&(_ instanceof Ahead&&_.match(d)||!_)){if(!t[i-1].trim()){t[i-1]="\n"}else{t.splice(i,0,"\n");i++}continue}}}catch(e){u.e(e)}finally{u.f()}}this.__code__=t.join("");return this};Formatter.prototype._spaces=function(e){return new Array(e+1).join(" ")};Formatter.prototype.format=function e(r){var t=this.__code__.replace(/[ \t]*\n[ \t]*/g,"\n ");var n=tokenize(t,true);var i=this._options(r);var a=0;var o=0;for(var u=0;u0&&arguments[0]!==undefined$1?arguments[0]:true;var n=new Map;function i(e){if(e instanceof Pair){if(n.has(e)){return n.get(e)}var r=new Pair;n.set(e,r);if(t){r.car=i(e.car)}else{r.car=e.car}r.cdr=i(e.cdr);r[__cycles__]=e[__cycles__];return r}return e}return i(this)};Pair.prototype.last_pair=function(){var e=this;while(true){if(e.cdr===_nil){return e}e=e.cdr}};Pair.prototype.to_array=function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:true;var r=[];if(this.car instanceof Pair){if(e){r.push(this.car.to_array())}else{r.push(this.car)}}else{r.push(this.car.valueOf())}if(this.cdr instanceof Pair){r=r.concat(this.cdr.to_array())}return r};Pair.fromArray=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:true;var t=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:false;if(e instanceof Pair||t&&e instanceof Array&&e[__data__]){return e}if(r===false){var n=_nil;for(var i=e.length;i--;){n=new Pair(e[i],n)}return n}if(e.length&&!(e instanceof Array)){e=_toConsumableArray(e)}var a=_nil;var o=e.length;while(o--){var u=e[o];if(u instanceof Array){u=Pair.fromArray(u,r,t)}else if(typeof u==="string"){u=LString(u)}else if(typeof u==="number"&&!Number.isNaN(u)){u=LNumber(u)}a=new Pair(u,a)}return a};Pair.prototype.to_object=function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:false;var r=this;var t={};while(true){if(r instanceof Pair&&r.car instanceof Pair){var n=r.car;var i=n.car;if(i instanceof LSymbol){i=i.__name__}if(i instanceof LString){i=i.valueOf()}var a=n.cdr;if(a instanceof Pair){a=a.to_object(e)}if(is_native(a)){if(!e){a=a.valueOf()}}t[i]=a;r=r.cdr}else{break}}return t};Pair.fromPairs=function(e){return e.reduce(function(e,r){return new Pair(new Pair(new LSymbol(r[0]),r[1]),e)},_nil)};Pair.fromObject=function(r){var e=Object.keys(r).map(function(e){return[e,r[e]]});return Pair.fromPairs(e)};Pair.prototype.reduce=function(e){var r=this;var t=_nil;while(true){if(r!==_nil){t=e(t,r.car);r=r.cdr}else{break}}return t};Pair.prototype.reverse=function(){if(this.haveCycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var r=_nil;while(e!==_nil){var t=e.cdr;e.cdr=r;r=e;e=t}return r};Pair.prototype.transform=function(n){function i(e){if(e instanceof Pair){if(e.replace){delete e.replace;return e}var r=n(e.car);if(r instanceof Pair){r=i(r)}var t=n(e.cdr);if(t instanceof Pair){t=i(t)}return new Pair(r,t)}return e}return i(this)};Pair.prototype.map=function(e){if(typeof this.car!=="undefined"){return new Pair(e(this.car),this.cdr===_nil?_nil:this.cdr.map(e))}else{return _nil}};var repr=new Map;function is_plain_object(e){return e&&_typeof(e)==="object"&&e.constructor===Object}var props=Object.getOwnPropertyNames(Array.prototype);var array_methods=[];props.forEach(function(e){array_methods.push(Array[e],Array.prototype[e])});function is_array_method(e){e=unbind(e);return array_methods.includes(e)}function is_lips_function(e){return is_function(e)&&(is_lambda(e)||e.__doc__)}function user_repr(t){var e=t.constructor||Object;var n=is_plain_object(t);var i=is_function(t[Symbol.asyncIterator])||is_function(t[Symbol.iterator]);var a;if(repr.has(e)){a=repr.get(e)}else{repr.forEach(function(e,r){r=unbind(r);if(t.constructor===r&&(r===Object&&n&&!i||r!==Object)){a=e}})}return a}var str_mapping=new Map;[[true,"#t"],[false,"#f"],[null,"null"],[undefined$1,"#"]].forEach(function(e){var r=_slicedToArray(e,2),t=r[0],n=r[1];str_mapping.set(t,n)});function symbolize(t){if(t&&_typeof(t)==="object"){var n={};var e=Object.getOwnPropertySymbols(t);e.forEach(function(e){var r=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");n[r]=toString(t[e])});var r=Object.getOwnPropertyNames(t);r.forEach(function(e){var r=t[e];if(r&&_typeof(r)==="object"&&r.constructor===Object){n[e]=symbolize(r)}else{n[e]=toString(r)}});return n}return t}function get_props(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function has_own_function(e,r){return e.hasOwnProperty(r)&&is_function(e.toString)}function function_to_string(e){if(is_native_function(e)){return"#"}var r=e.prototype&&e.prototype.constructor;if(is_function(r)&&is_lambda(r)){if(e[__class__]&&r.hasOwnProperty("__name__")){var t=r.__name__;if(LString.isString(t)){t=t.toString();return"#")}return"#"}}if(e.hasOwnProperty("__name__")){var n=e.__name__;if(_typeof(n)==="symbol"){n=symbol_to_string(n)}if(typeof n==="string"){return"#")}}if(has_own_function(e,"toString")){return e.toString()}else if(e.name&&!is_lambda(e)){return"#")}else{return"#"}}var instances=new Map;[[Error,function(e){return e.message}],[Pair,function(e,r){var t=r.quote,n=r.skip_cycles,i=r.pair_args;if(!n){e.markCycles()}return e.toString.apply(e,[t].concat(_toConsumableArray(i)))}],[LCharacter,function(e,r){var t=r.quote;if(t){return e.toString()}return e.valueOf()}],[LString,function(e,r){var t=r.quote;e=e.toString();if(t){return JSON.stringify(e).replace(/\\n/g,"\n")}return e}],[RegExp,function(e){return"#"+e.toString()}]].forEach(function(e){var r=_slicedToArray(e,2),t=r[0],n=r[1];instances.set(t,n)});var native_types=[LSymbol,LNumber,Macro,Values,InputPort,OutputPort,Environment,QuotedPromise];function toString(e,r,t){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(str_mapping.has(e)){return str_mapping.get(e)}if(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(_typeof(e)==="object"){var l=e.constructor;if(!l){l=Object}var f;if(typeof l.__class__==="string"){f=l.__class__}else{if(is_prototype(e)){return"#"}var _=user_repr(e);if(_){if(is_function(_)){return _(e,r)}else{throw new Error("toString: Invalid repr value")}}f=l.name}if(is_function(e.toString)&&is_lambda(e.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}function is_prototype(e){return e&&_typeof(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}Pair.prototype.markCycles=function(){markCycles(this);return this};Pair.prototype.haveCycles=function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:null;if(!e){return this.haveCycles("car")||this.haveCycles("cdr")}return!!(this[__cycles__]&&this[__cycles__][e])};function markCycles(e){var r=[];var i=[];var a=[];function o(e){if(!r.includes(e)){r.push(e)}}function u(e,r,t,n){if(t instanceof Pair){if(n.includes(t)){if(!a.includes(t)){a.push(t)}if(!e[__cycles__]){e[__cycles__]={}}e[__cycles__][r]=t;if(!i.includes(e)){i.push(e)}return true}}}var c=trampoline(function e(r,t){if(r instanceof Pair){delete r.ref;delete r[__cycles__];o(r);t.push(r);var n=u(r,"car",r.car,t);var i=u(r,"cdr",r.cdr,t);if(!n){c(r.car,t.slice())}if(!i){return new Thunk(function(){return e(r.cdr,t.slice())})}}});function t(e,r){if(e[__cycles__][r]instanceof Pair){var t=n.indexOf(e[__cycles__][r]);e[__cycles__][r]="#".concat(t,"#")}}c(e,[]);var n=r.filter(function(e){return a.includes(e)});n.forEach(function(e,r){e[__ref__]="#".concat(r,"=")});i.forEach(function(e){t(e,"car");t(e,"cdr")})}Pair.prototype.toString=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},t=r.nested,n=t===void 0?false:t;var i=[];if(this[__ref__]){i.push(this[__ref__]+"(")}else if(!n){i.push("(")}var a;if(this[__cycles__]&&this[__cycles__].car){a=this[__cycles__].car}else{a=toString(this.car,e,true)}if(a!==undefined$1){i.push(a)}if(this.cdr instanceof Pair){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(this.cdr!==_nil){i=i.concat([" . ",toString(this.cdr,e,true)])}if(!n||this[__ref__]){i.push(")")}return i.join("")};Pair.prototype.set=function(e,r){this[e]=r;if(r instanceof Pair){this.markCycles()}};Pair.prototype.append=function(e){if(e instanceof Array){return this.append(Pair.fromArray(e))}var r=this;if(r.car===undefined$1){if(e instanceof Pair){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(e!==_nil){while(true){if(r instanceof Pair&&r.cdr!==_nil){r=r.cdr}else{break}}r.cdr=e}return this};Pair.prototype.serialize=function(){return[this.car,this.cdr]};function abs(e){return e<0?-e:e}function seq_compare(e,r){var t=_toArray(r),n=t[0],i=t.slice(1);while(i.length>0){var a=i,o=_slicedToArray(a,1),u=o[0];if(!e(n,u)){return false}var c=i;var s=_toArray(c);n=s[0];i=s.slice(1)}return true}function equal(e,r){if(is_function(e)){return is_function(r)&&unbind(e)===unbind(r)}else if(e instanceof LNumber){if(!(r instanceof LNumber)){return false}var t;if(e.__type__===r.__type__){if(e.__type__==="complex"){t=e.__im__.__type__===r.__im__.__type__&&e.__re__.__type__===r.__re__.__type__}else{t=true}if(t&&e.cmp(r)===0){if(e.valueOf()===0){return Object.is(e.valueOf(),r.valueOf())}return true}}return false}else if(typeof e==="number"){if(typeof r!=="number"){return false}if(Number.isNaN(e)){return Number.isNaN(r)}if(e===Number.NEGATIVE_INFINITY){return r===Number.NEGATIVE_INFINITY}if(e===Number.POSITIVE_INFINITY){return r===Number.POSITIVE_INFINITY}return equal(LNumber(e),LNumber(r))}else if(e instanceof LCharacter){if(!(r instanceof LCharacter)){return false}return e.__char__===r.__char__}else{return e===r}}function same_atom(e,r){if(type(e)!==type(r)){return false}if(!is_atom(e)){return false}if(e instanceof RegExp){return e.source===r.source}if(e instanceof LString){return e.valueOf()===r.valueOf()}return equal(e,r)}function is_atom(e){return e instanceof LSymbol||LString.isString(e)||e===_nil||e===null||e instanceof LCharacter||e instanceof LNumber||e===true||e===false}var truncate=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e===0){return 0}else if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function Macro(e,r,t,n){if(typeof this!=="undefined"&&this.constructor!==Macro||typeof this==="undefined"){return new Macro(e,r)}typecheck("Macro",e,"string",1);typecheck("Macro",r,"function",2);if(t){if(n){this.__doc__=t}else{this.__doc__=trim_lines(t)}}this.__name__=e;this.__fn__=r}Macro.defmacro=function(e,r,t,n){var i=new Macro(e,r,t,n);i.__defmacro__=true;return i};Macro.prototype.invoke=function(e,r,t){var n=r.env,i=r.dynamic_scope,a=r.error;var o={dynamic_scope:i,error:a,macro_expand:t};var u=this.__fn__.call(n,e,o,this.__name__);return u};Macro.prototype.toString=function(){return"#")};var macro="define-macro";var recur_guard=-1e4;function macro_expand(s){return function(){var t=_asyncToGenerator(regenerator.mark(function e(t,y){var a,b,n,i,o,g,w,D,x,L,F,E,u,A,c;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:c=function e(){c=_asyncToGenerator(regenerator.mark(function e(t,n,i){var a,o,u,c,s,l,f,_,p,h,d,m,v;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!(t instanceof Pair&&t.car instanceof LSymbol)){r.next=50;break}if(!t[__data__]){r.next=3;break}return r.abrupt("return",t);case 3:a=t.car.valueOf();o=i.get(t.car,{throwError:false});u=g(t.car);c=u||w(o,t)||D(o);if(!(c&&t.cdr.car instanceof Pair)){r.next=28;break}if(!u){r.next=15;break}b=L(t.cdr.car);r.next=12;return E(t.cdr.car,n);case 12:s=r.sent;r.next=17;break;case 15:b=x(t.cdr.car);s=t.cdr.car;case 17:r.t0=Pair;r.t1=t.car;r.t2=Pair;r.t3=s;r.next=23;return A(t.cdr.cdr,n,i);case 23:r.t4=r.sent;r.t5=new r.t2(r.t3,r.t4);return r.abrupt("return",new r.t0(r.t1,r.t5));case 28:if(!F(a,o)){r.next=50;break}l=o instanceof Syntax?t:t.cdr;r.next=32;return o.invoke(l,_objectSpread(_objectSpread({},y),{},{env:i}),true);case 32:f=r.sent;if(!(o instanceof Syntax)){r.next=41;break}_=f,p=_.expr,h=_.scope;if(!(p instanceof Pair)){r.next=40;break}if(!(n!==-1&&n<=1||n")}return"#"};Syntax.className="syntax";function extract_patterns(e,r,w,D){var t=arguments.length>4&&arguments[4]!==undefined$1?arguments[4]:{};var x={"...":{symbols:{},lists:[]},symbols:{}};var L=t.expansion,F=t.define;function E(e){if(is_debug()){console.log(e)}}E(w);function A(e,r){var t=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:[];var n=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:false;E({code:r&&toString(r,true),pattern:e&&toString(e,true)});if(is_atom(e)&&!(e instanceof LSymbol)){return same_atom(e,r)}if(e instanceof LSymbol&&w.includes(e.valueOf())){var i=L.ref(r);if(LSymbol.is(r,e)){if(typeof i==="undefined"){return true}return i===F||i===global_env}return false}if(e instanceof Pair&&e.car instanceof Pair&&e.car.cdr instanceof Pair&&LSymbol.is(e.car.cdr.car,D)){E(">> 0");if(r===_nil){E({pattern:e.toString()});if(e.car.car instanceof LSymbol){if(e.car.cdr instanceof Pair&&LSymbol.is(e.car.cdr.car,D)){var a=e.car.car.valueOf();var o=e.last_pair();if(LSymbol.is(o.car,D)){x["..."].symbols[a]=null;return true}else{return false}}var u=e.car.car.valueOf();if(x["..."].symbols[u]){throw new Error("syntax: named ellipsis can only "+"appear onces")}x["..."].symbols[u]=r}}}if(e instanceof Pair&&e.cdr instanceof Pair&&LSymbol.is(e.cdr.car,D)){if(e.cdr.cdr!==_nil){if(e.cdr.cdr instanceof Pair){var c=e.cdr.cdr.length();var s=r.length();var l=r;while(s-1>c){l=l.cdr;s--}var f=l.cdr;l.cdr=_nil;if(!A(e.cdr.cdr,f,t,n)){return false}}}if(e.car instanceof LSymbol){var _=e.car.__name__;if(x["..."].symbols[_]&&!t.includes(_)&&!n){throw new Error("syntax: named ellipsis can only appear onces")}E(">> 1");if(r===_nil){E(">> 2");if(n){E("NIL");x["..."].symbols[_]=_nil}else{E("NULL");x["..."].symbols[_]=null}}else if(r instanceof Pair&&(r.car instanceof Pair||r.car===_nil)){E(">> 3 "+n);if(n){if(x["..."].symbols[_]){var p=x["..."].symbols[_];if(p===_nil){p=new Pair(_nil,new Pair(r,_nil))}else{p=p.append(new Pair(r,_nil))}x["..."].symbols[_]=p}else{x["..."].symbols[_]=new Pair(r,_nil)}}else{E(">> 4");x["..."].symbols[_]=new Pair(r,_nil)}}else{E(">> 6");if(r instanceof Pair){E(">> 7 "+n);t.push(_);if(!x["..."].symbols[_]){x["..."].symbols[_]=new Pair(r,_nil)}else{var h=x["..."].symbols[_];x["..."].symbols[_]=h.append(new Pair(r,_nil))}E({IIIIII:x["..."].symbols[_].toString()})}else{E(">> 8");return false}}return true}else if(e.car instanceof Pair){var d=_toConsumableArray(t);if(r===_nil){E(">> 9");x["..."].lists.push(_nil);return true}E(">> 10");var m=r;while(m instanceof Pair){if(!A(e.car,m.car,d,true)){return false}m=m.cdr}return true}return false}if(e instanceof LSymbol){if(LSymbol.is(e,D)){throw new Error("syntax: invalid usage of ellipsis")}E(">> 11");var v=e.__name__;if(w.includes(v)){return true}E({name:v,ellipsis:n});if(n){x["..."].symbols[v]=x["..."].symbols[v]||[];x["..."].symbols[v].push(r)}x.symbols[v]=r;if(!x.symbols[v]);return true}if(e instanceof Pair&&r instanceof Pair){E(">> 12");E({a:12,code:r&&r.toString(),pattern:e.toString()});if(r.cdr===_nil){var y=e.car instanceof LSymbol&&e.cdr instanceof LSymbol;if(y){if(!A(e.car,r.car,t,n)){return false}E(">> 12 | 1");var b=e.cdr.valueOf();if(!(b in x.symbols)){x.symbols[b]=_nil}b=e.car.valueOf();if(!(b in x.symbols)){x.symbols[b]=r.car}return true}}E({pattern:e.toString(),code:r.toString()});if(e.cdr instanceof Pair&&e.car instanceof LSymbol&&e.cdr.cdr instanceof Pair&&e.cdr.car instanceof LSymbol&&LSymbol.is(e.cdr.cdr.car,D)&&e.cdr.cdr.cdr instanceof Pair&&!LSymbol.is(e.cdr.cdr.cdr.car,D)&&A(e.car,r.car,t,n)&&A(e.cdr.cdr.cdr,r.cdr,t,n)){var g=e.cdr.car.__name__;E({pattern:e.car.toString(),code:r.car.toString(),name:g});if(w.includes(g)){return true}x["..."].symbols[g]=null;return true}E("recur");if(A(e.car,r.car,t,n)&&A(e.cdr,r.cdr,t,n)){return true}}else if(e===_nil&&(r===_nil||r===undefined$1)){return true}else if(e.car instanceof Pair&&LSymbol.is(e.car.car,D)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(A(e,r)){return x}}function clear_gensyms(e,i){function a(r){if(r instanceof Pair){if(!i.length){return r}var e=a(r.car);var t=a(r.cdr);return new Pair(e,t)}else if(r instanceof LSymbol){var n=i.find(function(e){return e.gensym===r});if(n){return LSymbol(n.name)}return r}else{return r}}return a(e)}function transform_syntax(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:{};var E=e.bindings,r=e.expr,A=e.scope,o=e.symbols,a=e.names,C=e.ellipsis;var u={};function c(e){if(e instanceof LSymbol){return true}return["string","symbol"].includes(_typeof(e))}function S(e){if(!c(e)){var r=type(e);throw new Error("syntax: internal error, need symbol got ".concat(r))}var t=e.valueOf();if(t===C){throw new Error("syntax: internal error, ellipis not transformed")}var n=_typeof(t);if(["string","symbol"].includes(n)){if(t in E.symbols){return E.symbols[t]}else if(n==="string"&&t.match(/\./)){var i=t.split(".");var a=i[0];if(a in E.symbols){return Pair.fromArray([LSymbol("."),E.symbols[a]].concat(i.slice(1).map(function(e){return LString(e)})))}}}if(o.includes(t)){return LSymbol(t)}return s(t)}function P(e){if(is_debug()){console.log(e)}}function s(e){if(!u[e]){var r=A.ref(e);var t=gensym(e);if(r){var n=A.get(e);A.set(t,n)}else{var i=A.get(e,{throwError:false});if(typeof i!=="undefined"){A.set(t,i)}}a.push({name:e,gensym:t});u[e]=t}return u[e]}function k(e,r,t){var n=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:function(){};var i=t.nested;P(" ==> "+e.toString(true));P(r);if(e instanceof LSymbol){var a=e.valueOf();P("[t 1");if(r[a]){if(r[a]instanceof Pair){var o=r[a],u=o.car,c=o.cdr;if(i){var s=u.car,l=u.cdr;if(l!==_nil){n(a,new Pair(l,_nil))}return s}if(c!==_nil){n(a,c)}return u}else if(r[a]instanceof Array){n(a,r[a].slice(1));return r[a][0]}}return S(a)}if(e instanceof Pair){if(e.car instanceof LSymbol&&e.cdr instanceof Pair&&LSymbol.is(e.cdr.car,C)){P("[t 2");var f=e.car.valueOf();var _=r[f];P({expr:e.toString(true),name:f,bindings:r,item:_});if(_===null){return}else if(_){P({b:r[f].toString()});if(_ instanceof Pair){P("[t 2 Pair "+i);P({______:_.toString()});var p=_.car,h=_.cdr;if(i){if(h!==_nil){P("|| next 1");n(f,h)}P({car:p.toString()});return p}else{if(p.cdr!==_nil){P("|| next 2");n(f,new Pair(p.cdr,h))}P({car:p.car.toString()});return p.car}}else if(_ instanceof Array){P("[t 2 Array "+i);if(i){n(f,_.slice(1));return Pair.fromArray(_)}else{var d=_.slice(1);if(d.length){n(f,d)}return _[0]}}else{return _}}}P("[t 3 recur "+e.toString());var m=k(e.car,r,t,n);var v=k(e.cdr,r,t,n);return new Pair(m,v)}return e}function N(r,t){var e=Object.values(r);var n=Object.getOwnPropertySymbols(r);if(n.length){e.push.apply(e,_toConsumableArray(n.map(function(e){return r[e]})))}return e.length&&e.every(function(e){if(e===null){return!t}return e instanceof Pair||e===_nil||e instanceof Array&&e.length})}function O(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function B(i){var e=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},r=e.disabled;P("traverse>> "+i.toString());if(i instanceof Pair){if(!r&&i.car instanceof Pair&&LSymbol.is(i.car.car,C)){return B(i.car.cdr,{disabled:true})}if(i.cdr instanceof Pair&&LSymbol.is(i.cdr.car,C)&&!r){P(">> 1");var t=E["..."].symbols;var n=Object.values(t);if(n.length&&n.every(function(e){return e===null})){return B(i.cdr.cdr,{disabled:r})}var a=O(t);var o=i.car instanceof LSymbol&&LSymbol.is(i.cdr.cdr.car,C);if(i.car instanceof Pair||o){if(E["..."].lists[0]===_nil){return _nil}var u=i.car;if(o){u=new Pair(i.car,new Pair(i.cdr.car,_nil))}P(">> 2");var c;if(a.length){P(">> 2 (a)");var s=_objectSpread({},t);c=_nil;var l=function e(){if(!N(s)){return"break"}var n={};var r=function e(r,t){n[r]=t};var t=k(u,s,{nested:true},r);if(t!==undefined$1){if(o){if(c===_nil){c=t}else{c=c.append(t)}}else{c=new Pair(t,c)}}s=n};while(true){var f=l();if(f==="break")break}if(c!==_nil&&!o){c=c.reverse()}if(i.cdr.cdr!==_nil&&!LSymbol.is(i.cdr.cdr.car,C)){var _=B(i.cdr.cdr,{disabled:r});return c.append(_)}return c}else{P(">> 3");var p=k(i.car,t,{nested:true});if(p){return new Pair(p,_nil)}return _nil}}else if(i.car instanceof LSymbol){P(">> 4");if(LSymbol.is(i.cdr.cdr.car,C)){P(">> 4 (a)")}else{P(">> 4 (b)")}var h=i.car.__name__;var d=_defineProperty({},h,t[h]);var m=t[h]===null;var v=_nil;var y=function e(){if(!N(d,true)){P({bind:d});return"break"}var n={};var r=function e(r,t){n[r]=t};var t=k(i,d,{nested:false},r);P({value:t.toString()});if(typeof t!=="undefined"){v=new Pair(t,v)}d=n};while(true){var b=y();if(b==="break")break}if(v!==_nil){v=v.reverse()}if(i.cdr instanceof Pair){if(i.cdr.cdr instanceof Pair||i.cdr.cdr instanceof LSymbol){var g=B(i.cdr.cdr,{disabled:r});if(m){return g}P("<<<< 1");v.append(g)}}P("<<<< 2");return v}}var w=B(i.car,{disabled:r});var D;var x;if(i.car instanceof LSymbol){var L=A.get(i.car,{throwError:false});x=L instanceof Macro&&L.__name__==="syntax-rules"}if(x){if(i.cdr.car instanceof LSymbol){D=new Pair(B(i.cdr.car,{disabled:r}),new Pair(i.cdr.cdr.car,B(i.cdr.cdr.cdr,{disabled:r})))}else{D=new Pair(i.cdr.car,B(i.cdr.cdr,{disabled:r}))}}else{D=B(i.cdr,{disabled:r})}P({a:true,car:toString(i.car),cdr:toString(i.cdr),head:toString(w),rest:toString(D)});return new Pair(w,D)}if(i instanceof LSymbol){if(r&&LSymbol.is(i,C)){return i}var F=S(i);if(typeof F!=="undefined"){return F}}return i}return B(r,{})}function is_null(e){return is_undef(e)||e===_nil||e===null}function is_function(e){return typeof e==="function"&&typeof e.bind==="function"}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 box(e){switch(_typeof(e)){case"string":return LString(e);case"number":if(!Number.isNaN(e)){return LNumber(e)}}return e}function map_object(n,i){var e=Object.getOwnPropertyNames(n);var r=Object.getOwnPropertySymbols(n);e.concat(r).forEach(function(e){var r=i(n[e]);var t=Object.getOwnPropertyDescriptor(n,e);if(!t||t.writable&&n[e]!==r){n[e]=r}});return n}function unbox(r){var e=[LString,LCharacter,LNumber].some(function(e){return r instanceof e});if(e){return r.valueOf()}if(r instanceof Array){return r.map(unbox)}if(r instanceof QuotedPromise){delete r.then}if(is_plain_object(r)){return map_object(r,unbox)}return r}function patch_value(e,r){if(e instanceof Pair){e.markCycles();return quote(e)}if(is_function(e)){if(r){return bind(e,r)}}return box(e)}function unbind(e){if(is_bound(e)){return e[__fn__]}return e}function bind(e,r){if(e[Symbol["for"]("__bound__")]){return e}var t=e.bind(r);var n=Object.getOwnPropertyNames(e);var i=_createForOfIteratorHelper(n),a;try{for(i.s();!(a=i.n()).done;){var o=a.value;if(filter_fn_names(o)){try{t[o]=e[o]}catch(e){}}}}catch(e){i.e(e)}finally{i.f()}hidden_prop(t,"__fn__",e);hidden_prop(t,"__context__",r);hidden_prop(t,"__bound__",true);if(is_native_function(e)){hidden_prop(t,"__native__",true)}if(is_plain_object(r)&&is_lambda(e)){hidden_prop(t,"__method__",true)}t.valueOf=function(){return e};return t}function is_object_bound(e){return is_bound(e)&&e[Symbol["for"]("__context__")]===Object}function is_bound(e){return!!(is_function(e)&&e[__fn__])}function lips_context(e){if(is_function(e)){var r=e[__context__];if(r&&(r===lips||r.constructor&&r.constructor.__class__)){return true}}return false}function is_port(e){return e instanceof InputPort||e instanceof OutputPort}function is_port_method(e){if(is_function(e)){if(is_port(e[__context__])){return true}}return false}var __context__=Symbol["for"]("__context__");var __fn__=Symbol["for"]("__fn__");var __data__=Symbol["for"]("__data__");var __ref__=Symbol["for"]("__ref__");var __cycles__=Symbol["for"]("__cycles__");var __class__=Symbol["for"]("__class__");var __method__=Symbol["for"]("__method__");var __prototype__=Symbol["for"]("__prototype__");var __lambda__=Symbol["for"]("__lambda__");var exluded_names=["name","length","caller","callee","arguments","prototype"];function filter_fn_names(e){return!exluded_names.includes(e)}function hidden_prop(e,r,t){Object.defineProperty(e,Symbol["for"](r),{get:function e(){return t},set:function e(){},configurable:false,enumerable:false})}function set_fn_length(r,t){try{Object.defineProperty(r,"length",{get:function e(){return t}});return r}catch(e){var n=new Array(t).fill(0).map(function(e,r){return"a"+r}).join(",");var i=new Function("f","return function(".concat(n,") {\n return f.apply(this, arguments);\n };"));return i(r)}}function is_lambda(e){return e&&e[__lambda__]}function is_method(e){return e&&e[__method__]}function is_raw_lambda(e){return is_lambda(e)&&!e[__prototype__]&&!is_method(e)&&!is_port_method(e)}function is_native_function(e){var r=Symbol["for"]("__native__");return is_function(e)&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[r]===true||!e.name.match(/^bound /)&&!e[r])}function let_macro(e){var 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 Macro.defmacro(b,function(r,e){var l=e.dynamic_scope,f=e.error,t=e.macro_expand;var _;if(r.car instanceof LSymbol){if(!(r.cdr.car instanceof Pair||r.cdr.car===_nil)){throw new Error("let require list of pairs")}var n;if(r.cdr.car===_nil){_=_nil;n=_nil}else{n=r.cdr.car.map(function(e){return e.car});_=r.cdr.car.map(function(e){return e.cdr.car})}return Pair.fromArray([LSymbol("letrec"),[[r.car,Pair(LSymbol("lambda"),Pair(n,r.cdr.cdr))]],Pair(r.car,_)])}else if(t){return}var p=this;_=global_env.get("list->array")(r.car);var h=p.inherit(b);var d,m;if(b==="let*"){m=h}else if(b==="let"){d=[]}var v=0;function y(){var e=new Pair(new LSymbol("begin"),r.cdr);return _evaluate(e,{env:h,dynamic_scope:l,error:f})}return function r(){var t=_[v++];if(l){l=b==="let*"?h:p}if(!t){if(d&&d.length){var e=d.map(function(e){return e.value});var n=e.filter(is_promise);if(n.length){return promise_all(e).then(function(e){for(var r=0,t=e.length;r1&&arguments[1]!==undefined$1?arguments[1]:{},t=r.dynamic_scope,n=r.error;var i=this;if(t){t=this}var a=e;var o=[];while(a instanceof Pair){o.push(_evaluate(a.car,{env:i,dynamic_scope:t,error:n}));a=a.cdr}var u=o.filter(is_promise).length;if(u){return promise_all(o).then(c.bind(this))}else{return c.call(this,o)}})}function guard_math_call(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n2?n-2:0),a=2;a1&&arguments[1]!==undefined$1?arguments[1]:null;return function(){for(var e=arguments.length,r=new Array(e),t=0;t1?e-1:0),t=1;t=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,r=new Array(e),t=0;t1){e=e.toLowerCase();if(LCharacter.__names__[e]){r=e;e=LCharacter.__names__[e]}else{throw new Error("Internal: Unknown named character")}}else{r=LCharacter.__rev_names__[e]}Object.defineProperty(this,"__char__",{value:e,enumerable:true});if(r){Object.defineProperty(this,"__name__",{value:r,enumerable:true})}}LCharacter.__names__=characters;LCharacter.__rev_names__={};Object.keys(LCharacter.__names__).forEach(function(e){var r=LCharacter.__names__[e];LCharacter.__rev_names__[r]=e});LCharacter.prototype.toUpperCase=function(){return LCharacter(this.__char__.toUpperCase())};LCharacter.prototype.toLowerCase=function(){return LCharacter(this.__char__.toLowerCase())};LCharacter.prototype.toString=function(){return"#\\"+(this.__name__||this.__char__)};LCharacter.prototype.valueOf=LCharacter.prototype.serialize=function(){return this.__char__};function LString(e){if(typeof this!=="undefined"&&!(this instanceof LString)||typeof this==="undefined"){return new LString(e)}if(e instanceof Array){this.__string__=e.map(function(e,r){typecheck("LString",e,"character",r+1);return e.toString()}).join("")}else{this.__string__=e.valueOf()}}{var ignore=["length","constructor"];var _keys=Object.getOwnPropertyNames(String.prototype).filter(function(e){return!ignore.includes(e)});var wrap=function e(n){return function(){for(var e=arguments.length,r=new Array(e),t=0;t0){t.push(this.__string__.substring(0,e))}t.push(r);if(e1&&arguments[1]!==undefined$1?arguments[1]:false;if(e instanceof LNumber){return e}if(typeof this!=="undefined"&&!(this instanceof LNumber)||typeof this==="undefined"){return new LNumber(e,r)}if(typeof e==="undefined"){throw new Error("Invalid LNumber constructor call")}var t=LNumber.getType(e);if(LNumber.types[t]){return LNumber.types[t](e,r)}var n=e instanceof Array&&LString.isString(e[0])&&LNumber.isNumber(e[1]);if(e instanceof LNumber){return LNumber(e.value)}if(!LNumber.isNumber(e)&&!n){throw new Error("You can't create LNumber from ".concat(type(e)))}if(e===null){e=0}var i;if(n){var a=e,o=_slicedToArray(a,2),u=o[0],c=o[1];if(u instanceof LString){u=u.valueOf()}if(c instanceof LNumber){c=c.valueOf()}var s=u.match(/^([+-])/);var l=false;if(s){u=u.replace(/^[+-]/,"");if(s[1]==="-"){l=true}}}if(Number.isNaN(e)){return LFloat(e)}else if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(n){var f;switch(c){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(c);i=_toConsumableArray(u).map(function(e,r){return BigInt(parseInt(e,c))*Math.pow(_,BigInt(r))}).reduce(function(e,r){return e+r})}else{i=BigInt(f+u)}}else{i=BigInt(e)}if(l){i*=BigInt(-1)}}else{i=e}return LBigInteger(i,true)}else if(typeof BN!=="undefined"&&!(e instanceof BN)){if(e instanceof Array){return LBigInteger(_construct(BN,_toConsumableArray(e)))}return LBigInteger(new BN(e))}else if(n){this.constant(parseInt(u,c),"integer")}else{this.constant(e,"integer")}}LNumber.prototype.constant=function(e,r){Object.defineProperty(this,"__value__",{value:e,enumerable:true});Object.defineProperty(this,"__type__",{value:r,enumerable:true})};LNumber.types={float:function e(r){var t=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;return new LFloat(r,t)},complex:function e(r){var t=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;if(!LNumber.isComplex(r)){r={im:0,re:r}}return new LComplex(r,t)},rational:function e(r){var t=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;if(!LNumber.isRational(r)){r={num:r,denom:1}}return new LRational(r,t)}};LNumber.prototype.serialize=function(){return this.__value__};LNumber.prototype.isNaN=function(){return Number.isNaN(this.__value__)};LNumber.prototype.gcd=function(e){var r=this.abs();e=e.abs();if(e.cmp(r)===1){var t=r;r=e;e=t}while(true){r=r.rem(e);if(r.cmp(0)===0){return e}e=e.rem(r);if(e.cmp(0)===0){return r}}};LNumber.isFloat=function e(r){return r instanceof LFloat||Number(r)===r&&r%1!==0};LNumber.isNumber=function(e){return e instanceof LNumber||LNumber.isNative(e)||LNumber.isBN(e)};LNumber.isComplex=function(e){if(!e){return false}var r=e instanceof LComplex||(LNumber.isNumber(e.im)||Number.isNaN(e.im))&&(LNumber.isNumber(e.re)||Number.isNaN(e.re));return r};LNumber.isRational=function(e){if(!e){return false}return e instanceof LRational||LNumber.isNumber(e.num)&&LNumber.isNumber(e.denom)};LNumber.isInteger=function(e){if(!(LNumber.isNative(e)||e instanceof LNumber)){return false}if(LNumber.isFloat(e)){return false}if(LNumber.isRational(e)){return false}if(LNumber.isComplex(e)){return false}return true};LNumber.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};LNumber.isBigInteger=function(e){return e instanceof LBigInteger||typeof e==="bigint"||LNumber.isBN(e)};LNumber.isBN=function(e){return typeof BN!=="undefined"&&e instanceof BN};LNumber.getArgsType=function(e,r){if(e instanceof LFloat||r instanceof LFloat){return LFloat}if(e instanceof LBigInteger||r instanceof LBigInteger){return LBigInteger}return LNumber};LNumber.prototype.toString=function(e){if(Number.isNaN(this.__value__)){return"+nan.0"}if(e>2&&e<36){return this.__value__.toString(e)}return this.__value__.toString()};LNumber.prototype.asType=function(e){var r=LNumber.getType(this);return LNumber.types[r]?LNumber.types[r](e):LNumber(e)};LNumber.prototype.isBigNumber=function(){return typeof this.__value__==="bigint"||typeof BN!=="undefined"&&!(this.value instanceof BN)};["floor","ceil","round"].forEach(function(e){LNumber.prototype[e]=function(){if(this["float"]||LNumber.isFloat(this.__value__)){return LNumber(Math[e](this.__value__))}else{return LNumber(Math[e](this.valueOf()))}}});LNumber.prototype.valueOf=function(){if(LNumber.isNative(this.__value__)){return Number(this.__value__)}else if(LNumber.isBN(this.__value__)){return this.__value__.toNumber()}};var matrix=function(){var e=function e(r,t){return[r,t]};return{bigint:{bigint:e,float:function e(r,t){return[LFloat(r.valueOf()),t]},rational:function e(r,t){return[{num:r,denom:1},t]},complex:function e(r,t){return[{im:0,re:r},t]}},integer:{integer:e,float:function e(r,t){return[LFloat(r.valueOf()),t]},rational:function e(r,t){return[{num:r,denom:1},t]},complex:function e(r,t){return[{im:0,re:r},t]}},float:{bigint:function e(r,t){return[r,t&&LFloat(t.valueOf())]},integer:function e(r,t){return[r,t&&LFloat(t.valueOf())]},float:e,rational:function e(r,t){return[r,t&&LFloat(t.valueOf())]},complex:function e(r,t){return[{re:r,im:LFloat(0)},t]}},complex:{bigint:r("bigint"),integer:r("integer"),float:r("float"),rational:r("rational"),complex:function e(r,t){var n=LNumber.coerce(r.__re__,t.__re__),i=_slicedToArray(n,2),a=i[0],o=i[1];var u=LNumber.coerce(r.__im__,t.__im__),c=_slicedToArray(u,2),s=c[0],l=c[1];return[{im:s,re:a},{im:l,re:o}]}},rational:{bigint:function e(r,t){return[r,t&&{num:t,denom:1}]},integer:function e(r,t){return[r,t&&{num:t,denom:1}]},float:function e(r,t){return[LFloat(r.valueOf()),t]},rational:e,complex:function e(r,t){return[{im:coerce(r.__type__,t.__im__.__type__,0)[0],re:coerce(r.__type__,t.__re__.__type__,r)[0]},{im:coerce(r.__type__,t.__im__.__type__,t.__im__)[0],re:coerce(r.__type__,t.__re__.__type__,t.__re__)[0]}]}}};function r(t){return function(e,r){return[{im:coerce(t,e.__im__.__type__,0,e.__im__)[1],re:coerce(t,e.__re__.__type__,0,e.__re__)[1]},{im:coerce(t,e.__im__.__type__,0,0)[1],re:coerce(t,r.__type__,0,r)[1]}]}}}();function coerce(e,r,t,n){return matrix[e][r](t,n)}LNumber.coerce=function(e,r){var t=LNumber.getType(e);var n=LNumber.getType(r);if(!matrix[t]){throw new Error("LNumber::coerce unknown lhs type ".concat(t))}else if(!matrix[t][n]){throw new Error("LNumber::coerce unknown rhs type ".concat(n))}var i=matrix[t][n](e,r);return i.map(function(e){return LNumber(e,true)})};LNumber.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof LNumber)){throw new Error("LNumber: you can't coerce ".concat(type(e)))}if(typeof e==="number"){e=LNumber(e)}return LNumber.coerce(this,e)};LNumber.getType=function(e){if(e instanceof LNumber){return e.__type__}if(LNumber.isFloat(e)){return"float"}if(LNumber.isComplex(e)){return"complex"}if(LNumber.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof BN!=="undefined"&&!(e instanceof BN)){return"bigint"}};LNumber.prototype.isFloat=function(){return!!(LNumber.isFloat(this.__value__)||this["float"])};var mapping={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var rev_mapping={};Object.keys(mapping).forEach(function(r){rev_mapping[mapping[r]]=r;LNumber.prototype[r]=function(e){return this.op(mapping[r],e)}});LNumber._ops={"*":function e(r,t){return r*t},"+":function e(r,t){return r+t},"-":function e(r,t){if(typeof t==="undefined"){return-r}return r-t},"/":function e(r,t){return r/t},"%":function e(r,t){return r%t},"|":function e(r,t){return r|t},"&":function e(r,t){return r&t},"~":function e(r){return~r},">>":function e(r,t){return r>>t},"<<":function e(r,t){return r<1&&arguments[1]!==undefined$1?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof LComplex)||typeof this==="undefined"){return new LComplex(e,r)}if(e instanceof LComplex){return LComplex({im:e.__im__,re:e.__re__})}if(LNumber.isNumber(e)&&r){if(!r){return Number(e)}}else if(!LNumber.isComplex(e)){throw new Error("Invalid constructor call for LComplex")}var t=e.im instanceof LNumber?e.im:LNumber(e.im);var n=e.re instanceof LNumber?e.re:LNumber(e.re);this.constant(t,n)}LComplex.prototype=Object.create(LNumber.prototype);LComplex.prototype.constructor=LComplex;LComplex.prototype.constant=function(e,r){Object.defineProperty(this,"__im__",{value:e,enumerable:true});Object.defineProperty(this,"__re__",{value:r,enumerable:true});Object.defineProperty(this,"__type__",{value:"complex",enumerable:true})};LComplex.prototype.serialize=function(){return{re:this.__re__,im:this.__im__}};LComplex.prototype.toRational=function(e){if(LNumber.isFloat(this.__im__)&&LNumber.isFloat(this.__re__)){var r=LFloat(this.__im__).toRational(e);var t=LFloat(this.__re__).toRational(e);return LComplex({im:r,re:t})}return this};LComplex.prototype.add=function(e){return this.complex_op("add",e,function(e,r,t,n){return{re:e.add(r),im:t.add(n)}})};LComplex.prototype.factor=function(){if(this.__im__ instanceof LFloat||this.__im__ instanceof LFloat){var e=this.__re__,r=this.__im__;var t,n;if(e instanceof LFloat){t=e.toRational().mul(e.toRational())}else{t=e.mul(e)}if(r instanceof LFloat){n=r.toRational().mul(r.toRational())}else{n=r.mul(r)}return t.add(n)}else{return this.__re__.mul(this.__re__).add(this.__im__.mul(this.__im__))}};LComplex.prototype.modulus=function(){return this.factor().sqrt()};LComplex.prototype.conjugate=function(){return LComplex({re:this.__re__,im:this.__im__.sub()})};LComplex.prototype.sqrt=function(){var e=this.modulus();var r,t;if(e.cmp(0)===0){r=t=e}else if(this.__re__.cmp(0)===1){r=LFloat(.5).mul(e.add(this.__re__)).sqrt();t=this.__im__.div(r).div(2)}else{t=LFloat(.5).mul(e.sub(this.__re__)).sqrt();if(this.__im__.cmp(0)===-1){t=t.sub()}r=this.__im__.div(t).div(2)}return LComplex({im:t,re:r})};LComplex.prototype.div=function(e){if(LNumber.isNumber(e)&&!LNumber.isComplex(e)){if(!(e instanceof LNumber)){e=LNumber(e)}var r=this.__re__.div(e);var t=this.__im__.div(e);return LComplex({re:r,im:t})}else if(!LNumber.isComplex(e)){throw new Error("[LComplex::div] Invalid value")}var n=this.coerce(e),i=_slicedToArray(n,2),a=i[0],o=i[1];var u=o.factor();var c=a.mul(o.conjugate());var s=c.__re__.op("/",u);var l=c.__im__.op("/",u);return LComplex({re:s,im:l})};LComplex.prototype.sub=function(e){return this.complex_op("sub",e,function(e,r,t,n){return{re:e.sub(r),im:t.sub(n)}})};LComplex.prototype.mul=function(e){return this.complex_op("mul",e,function(e,r,t,n){var i={re:e.mul(r).sub(t.mul(n)),im:e.mul(n).add(r.mul(t))};return i})};LComplex.prototype.complex_op=function(e,r,i){var a=this;var t=function e(r,t){var n=i(a.__re__,r,a.__im__,t);if("im"in n&&"re"in n){if(n.im.cmp(0)===0&&!LNumber.isFloat(n.im)){return n.re}return LComplex(n,true)}return n};if(typeof r==="undefined"){return t()}if(LNumber.isNumber(r)&&!LNumber.isComplex(r)){if(!(r instanceof LNumber)){r=LNumber(r)}var n=r.asType(0);r={__im__:n,__re__:r}}else if(!LNumber.isComplex(r)){throw new Error("[LComplex::".concat(e,"] Invalid value"))}var o=r.__re__ instanceof LNumber?r.__re__:this.__re__.asType(r.__re__);var u=r.__im__ instanceof LNumber?r.__im__:this.__im__.asType(r.__im__);return t(o,u)};LComplex._op={"+":"add","-":"sub","*":"mul","/":"div"};LComplex.prototype._op=function(e,r){var t=LComplex._op[e];return this[t](r)};LComplex.prototype.cmp=function(e){var r=this.coerce(e),t=_slicedToArray(r,2),n=t[0],i=t[1];var a=n.__re__.coerce(i.__re__),o=_slicedToArray(a,2),u=o[0],c=o[1];var s=u.cmp(c);if(s!==0){return s}else{var l=n.__im__.coerce(i.__im__),f=_slicedToArray(l,2),_=f[0],p=f[1];return _.cmp(p)}};LComplex.prototype.valueOf=function(){return[this.__re__,this.__im__].map(function(e){return e.valueOf()})};LComplex.prototype.toString=function(){var e;if(this.__re__.cmp(0)!==0){e=[toString(this.__re__)]}else{e=[]}var r=this.__im__.valueOf();var t=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY].includes(r);var n=toString(this.__im__);if(!t&&!Number.isNaN(r)){var i=this.__im__.cmp(0);if(i<0||i===0&&this.__im__._minus){e.push("-")}else{e.push("+")}n=n.replace(/^-/,"")}e.push(n);e.push("i");return e.join("")};function LFloat(e){if(typeof this!=="undefined"&&!(this instanceof LFloat)||typeof this==="undefined"){return new LFloat(e)}if(!LNumber.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof LNumber){return LFloat(e.valueOf())}if(typeof e==="number"){if(Object.is(e,-0)){Object.defineProperty(this,"_minus",{value:true})}this.constant(e,"float")}}LFloat.prototype=Object.create(LNumber.prototype);LFloat.prototype.constructor=LFloat;LFloat.prototype.toString=function(){if(this.__value__===Number.NEGATIVE_INFINITY){return"-inf.0"}if(this.__value__===Number.POSITIVE_INFINITY){return"+inf.0"}if(Number.isNaN(this.__value__)){return"+nan.0"}var e=this.__value__.toString();if(!LNumber.isFloat(this.__value__)&&!e.match(/e/i)){var r=e+".0";return this._minus?"-"+r:r}return e.replace(/^([0-9]+)e/,"$1.0e")};LFloat.prototype._op=function(e,r){if(r instanceof LNumber){r=r.__value__}var t=LNumber._ops[e];if(e==="/"&&this.__value__===0&&r===0){return NaN}return LFloat(t(this.__value__,r))};LFloat.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:null;if(e===null){return toRational(this.__value__.valueOf())}return approxRatio(e.valueOf())(this.__value__.valueOf())};var toRational=approxRatio(1e-10);function approxRatio(n){return function(e){var r=function e(n,r,t){var i=function e(r,t){return t0){i=simplest_rational2(n,t)}else if(n.cmp(t)<=0){i=t}else if(t.cmp(0)>0){i=simplest_rational2(t,n)}else if(r.cmp(0)<0){i=LNumber(simplest_rational2(n.sub(),t.sub())).sub()}else{i=LNumber(0)}if(LNumber.isFloat(r)||LNumber.isFloat(e)){return LFloat(i)}return i}function simplest_rational2(e,r){var t=LNumber(e).floor();var n=LNumber(r).floor();if(e.cmp(t)<1){return t}else if(t.cmp(n)===0){var i=LNumber(1).div(r.sub(n));var a=LNumber(1).div(e.sub(t));return t.add(LNumber(1).div(simplest_rational2(i,a)))}else{return t.add(LNumber(1))}}function LRational(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof LRational)||typeof this==="undefined"){return new LRational(e,r)}if(!LNumber.isRational(e)){throw new Error("Invalid constructor call for LRational")}var t,n;if(e instanceof LRational){t=LNumber(e.__num__);n=LNumber(e.__denom__)}else{t=LNumber(e.num);n=LNumber(e.denom)}if(!r&&n.cmp(0)!==0){var i=t.op("%",n).cmp(0)===0;if(i){return LNumber(t.div(n))}}this.constant(t,n)}LRational.prototype=Object.create(LNumber.prototype);LRational.prototype.constructor=LRational;LRational.prototype.constant=function(e,r){Object.defineProperty(this,"__num__",{value:e,enumerable:true});Object.defineProperty(this,"__denom__",{value:r,enumerable:true});Object.defineProperty(this,"__type__",{value:"rational",enumerable:true})};LRational.prototype.serialize=function(){return{num:this.__num__,denom:this.__denom__}};LRational.prototype.pow=function(e){var r=e.cmp(0);if(r===0){return LNumber(1)}if(r===-1){e=e.sub();var t=this.__denom__.pow(e);var n=this.__num__.pow(e);return LRational({num:t,denom:n})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};LRational.prototype.sqrt=function(){var e=this.__num__.sqrt();var r=this.__denom__.sqrt();if(e instanceof LFloat){e.toRational(),_readOnlyError("num")}if(r instanceof LFloat){r.toRational(),_readOnlyError("denom")}return LRational({num:e,denom:r})};LRational.prototype.abs=function(){var e=this.__num__;var r=this.__denom__;if(e.cmp(0)===-1){e=e.sub()}if(r.cmp(0)!==1){r=r.sub()}return LRational({num:e,denom:r})};LRational.prototype.cmp=function(e){return LNumber(this.valueOf(),true).cmp(e)};LRational.prototype.toString=function(){var e=this.__num__.gcd(this.__denom__);var r,t;if(e.cmp(1)!==0){r=this.__num__.div(e);if(r instanceof LRational){r=LNumber(r.valueOf(true))}t=this.__denom__.div(e);if(t instanceof LRational){t=LNumber(t.valueOf(true))}}else{r=this.__num__;t=this.__denom__}var n=this.cmp(0)<0;if(n){if(r.abs().cmp(t.abs())===0){return r.toString()}}else if(r.cmp(t)===0){return r.toString()}return r.toString()+"/"+t.toString()};LRational.prototype.valueOf=function(e){if(this.__denom__.cmp(0)===0){if(this.__num__.cmp(0)<0){return Number.NEGATIVE_INFINITY}return Number.POSITIVE_INFINITY}if(e){return LNumber._ops["/"](this.__num__.value,this.__denom__.value)}return LFloat(this.__num__.valueOf()).div(this.__denom__.valueOf())};LRational.prototype.mul=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=this.__num__.mul(e.__num__);var t=this.__denom__.mul(e.__denom__);return LRational({num:r,denom:t})}var n=LNumber.coerce(this,e),i=_slicedToArray(n,2),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 r=this.__num__.mul(e.__denom__);var t=this.__denom__.mul(e.__num__);return LRational({num:r,denom:t})}var n=LNumber.coerce(this,e),i=_slicedToArray(n,2),a=i[0],o=i[1];var u=a.div(o);return u};LRational.prototype._op=function(e,r){return this[rev_mapping[e]](r)};LRational.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=e.__num__.sub();var t=e.__denom__;return this.add(LRational({num:r,denom:t}))}if(!(e instanceof LNumber)){e=LNumber(e).sub()}else{e=e.sub()}var n=LNumber.coerce(this,e),i=_slicedToArray(n,2),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 r=this.__denom__;var t=e.__denom__;var n=this.__num__;var i=e.__num__;var a,o;if(r!==t){o=t.mul(n).add(i.mul(r));a=r.mul(t)}else{o=n.add(i);a=r}return LRational({num:o,denom:a})}if(LNumber.isFloat(e)){return LFloat(this.valueOf()).add(e)}var u=LNumber.coerce(this,e),c=_slicedToArray(u,2),s=c[0],l=c[1];return s.add(l)};function LBigInteger(e,r){if(typeof this!=="undefined"&&!(this instanceof LBigInteger)||typeof this==="undefined"){return new LBigInteger(e,r)}if(e instanceof LBigInteger){return LBigInteger(e.__value__,e._native)}if(!LNumber.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.constant(e,"bigint");Object.defineProperty(this,"_native",{value:r})}LBigInteger.prototype=Object.create(LNumber.prototype);LBigInteger.prototype.constructor=LBigInteger;LBigInteger.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};LBigInteger.prototype.serialize=function(){return this.__value__.toString()};LBigInteger.prototype._op=function(e,r){if(typeof r==="undefined"){if(LNumber.isBN(this.__value__)){e=LBigInteger.bn_op[e];return LBigInteger(this.__value__.clone()[e](),false)}return LBigInteger(LNumber._ops[e](this.__value__),true)}if(LNumber.isBN(this.__value__)&&LNumber.isBN(r.__value__)){e=LBigInteger.bn_op[e];return LBigInteger(this.__value__.clone()[e](r),false)}var t=LNumber._ops[e](this.__value__,r.__value__);if(e==="/"){var n=this.op("%",r).cmp(0)===0;if(n){return LNumber(t)}return LRational({num:this,denom:r})}return LBigInteger(t,true)};LBigInteger.prototype.sqrt=function(){var e;var r=this.cmp(0)<0;if(LNumber.isNative(this.__value__)){e=LNumber(Math.sqrt(r?-this.valueOf():this.valueOf()))}else if(LNumber.isBN(this.__value__)){e=r?this.__value__.neg().sqrt():this.__value__.sqrt()}if(r){return LComplex({re:0,im:e})}return e};LNumber.NaN=LNumber(NaN);function InputPort(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof InputPort)||typeof this==="undefined"){return new InputPort(e)}typecheck("InputPort",e,"function");read_only(this,"__type__",text_port);var i;Object.defineProperty(this,"__parser__",{enumerable:true,get:function e(){return i},set:function e(r){typecheck("InputPort::__parser__",r,"parser");i=r}});this._read=e;this._with_parser=this._with_init_parser.bind(this,_asyncToGenerator(regenerator.mark(function e(){var t;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(n.char_ready()){r.next=5;break}r.next=3;return n._read();case 3:t=r.sent;i=new Parser(t,{env:n});case 5:return r.abrupt("return",n.__parser__);case 6:case"end":return r.stop()}}},e)})));this.char_ready=function(){return!!this.__parser__&&this.__parser__.__lexer__.peek()!==eof};this._make_defaults()}InputPort.prototype._make_defaults=function(){this.read=this._with_parser(function(e){return e.read_object()});this.read_line=this._with_parser(function(e){return e.__lexer__.read_line()});this.read_char=this._with_parser(function(e){return e.__lexer__.read_char()});this.read_string=this._with_parser(function(e,r){if(!LNumber.isInteger(r)){var t=LNumber.getType(r);typeErrorMessage("read-string",t,"integer")}return e.__lexer__.read_string(r.valueOf())});this.peek_char=this._with_parser(function(e){return e.__lexer__.peek_char()})};InputPort.prototype._with_init_parser=function(u,c){var s=this;return function(){var e=_asyncToGenerator(regenerator.mark(function e(){var t,n,i,a,o=arguments;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:r.next=2;return u.call(s);case 2:t=r.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.toString=function(){return"#"};function OutputStringPort(r){var t=this;if(typeof this!=="undefined"&&!(this instanceof OutputStringPort)||typeof this==="undefined"){return new OutputStringPort(r)}typecheck("OutputStringPort",r,"function");read_only(this,"__type__",text_port);read_only(this,"__buffer__",[]);this.write=function(e){if(!LString.isString(e)){e=r(e)}else{e=e.valueOf()}t.__buffer__.push(e)}}OutputStringPort.prototype=Object.create(OutputPort.prototype);OutputStringPort.prototype.constructor=OutputStringPort;OutputStringPort.prototype.toString=function(){return"#"};OutputStringPort.prototype.valueOf=function(){return this.__buffer__.map(function(e){return e.valueOf()}).join("")};function OutputFilePort(e,r){var t=this;if(typeof this!=="undefined"&&!(this instanceof OutputFilePort)||typeof this==="undefined"){return new OutputFilePort(e,r)}typecheck("OutputFilePort",e,"string");read_only(this,"__filename__",e);read_only(this,"_fd",r.valueOf(),{hidden:true});read_only(this,"__type__",text_port);this.write=function(e){if(!LString.isString(e)){e=toString(e)}else{e=e.valueOf()}t.fs().write(t._fd,e,function(e){if(e){throw e}})}}OutputFilePort.prototype=Object.create(OutputPort.prototype);OutputFilePort.prototype.constructor=OutputFilePort;OutputFilePort.prototype.fs=function(){if(!this._fs){this._fs=this.internal("fs")}return this._fs};OutputFilePort.prototype.internal=function(e){return user_env.get("**internal-env**").get(e)};OutputFilePort.prototype.close=function(){var n=this;return new Promise(function(r,t){n.fs().close(n._fd,function(e){if(e){t(e)}else{read_only(n,"_fd",null,{hidden:true});OutputPort.prototype.close.call(n);r()}})})};OutputFilePort.prototype.toString=function(){return"#")};function InputStringPort(e,r){var t=this;if(typeof this!=="undefined"&&!(this instanceof InputStringPort)||typeof this==="undefined"){return new InputStringPort(e)}typecheck("InputStringPort",e,"string");r=r||global_env;e=e.valueOf();this._with_parser=this._with_init_parser.bind(this,function(){if(!t.__parser__){t.__parser__=new Parser(e,{env:r})}return t.__parser__});read_only(this,"__type__",text_port);this._make_defaults()}InputStringPort.prototype.char_ready=function(){return true};InputStringPort.prototype=Object.create(InputPort.prototype);InputStringPort.prototype.constructor=InputStringPort;InputStringPort.prototype.toString=function(){return"#"};function InputByteVectorPort(e){if(typeof this!=="undefined"&&!(this instanceof InputByteVectorPort)||typeof this==="undefined"){return new InputByteVectorPort(e)}typecheck("InputByteVectorPort",e,"uint8array");read_only(this,"__vector__",e);read_only(this,"__type__",binary_port);var t=0;Object.defineProperty(this,"__index__",{enumerable:true,get:function e(){return t},set:function e(r){typecheck("InputByteVectorPort::__index__",r,"number");if(r instanceof LNumber){r=r.valueOf()}if(typeof r==="bigint"){r=Number(r)}if(Math.floor(r)!==r){throw new Error("InputByteVectorPort::__index__ value is "+"not integer")}t=r}})}InputByteVectorPort.prototype=Object.create(InputPort.prototype);InputByteVectorPort.prototype.constructor=InputByteVectorPort;InputByteVectorPort.prototype.toString=function(){return"#"};InputByteVectorPort.prototype.close=function(){var r=this;read_only(this,"__vector__",_nil);["read_u8","close","peek_u8","read_u8_vector"].forEach(function(e){r[e]=function(){throw new Error("Input-binary-port: port is closed")}});this.char_ready=function(){return false}};InputByteVectorPort.prototype.u8_ready=function(){return true};InputByteVectorPort.prototype.peek_u8=function(){if(this.__index__>=this.__vector__.length){return eof}return this.__vector__[this.__index__]};InputByteVectorPort.prototype.skip=function(){if(this.__index__<=this.__vector__.length){++this.__index__}};InputByteVectorPort.prototype.read_u8=function(){var e=this.peek_u8();this.skip();return e};InputByteVectorPort.prototype.read_u8_vector=function(e){if(typeof e==="undefined"){e=this.__vector__.length}else if(e>this.__index__+this.__vector__.length){e=this.__index__+this.__vector__.length}if(this.peek_u8()===eof){return eof}return this.__vector__.slice(this.__index__,e)};function OutputByteVectorPort(){if(typeof this!=="undefined"&&!(this instanceof OutputByteVectorPort)||typeof this==="undefined"){return new OutputByteVectorPort}read_only(this,"__type__",binary_port);read_only(this,"_buffer",[],{hidden:true});this.write=function(e){typecheck("write",e,["number","uint8array"]);if(LNumber.isNumber(e)){this._buffer.push(e.valueOf())}else{var r;(r=this._buffer).push.apply(r,_toConsumableArray(Array.from(e)))}};Object.defineProperty(this,"__buffer__",{enumerable:true,get:function e(){return Uint8Array.from(this._buffer)}})}OutputByteVectorPort.prototype=Object.create(OutputPort.prototype);OutputByteVectorPort.prototype.constructor=OutputByteVectorPort;OutputByteVectorPort.prototype.close=function(){OutputPort.prototype.close.call(this);read_only(this,"_buffer",null,{hidden:true})};OutputByteVectorPort.prototype._close_guard=function(){if(this._closed){throw new Error("output-port: binary port is closed")}};OutputByteVectorPort.prototype.write_u8=function(e){typecheck("OutputByteVectorPort::write_u8",e,"number");this.write(e)};OutputByteVectorPort.prototype.write_u8_vector=function(e){typecheck("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};OutputByteVectorPort.prototype.toString=function(){return"#"};OutputByteVectorPort.prototype.valueOf=function(){return this.__buffer__};function InputFilePort(e,r){if(typeof this!=="undefined"&&!(this instanceof InputFilePort)||typeof this==="undefined"){return new InputFilePort(e,r)}InputStringPort.call(this,e);typecheck("InputFilePort",r,"string");read_only(this,"__filename__",r)}InputFilePort.prototype=Object.create(InputStringPort.prototype);InputFilePort.prototype.constructor=InputFilePort;InputFilePort.prototype.toString=function(){return"#")};function InputBinaryFilePort(e,r){if(typeof this!=="undefined"&&!(this instanceof InputBinaryFilePort)||typeof this==="undefined"){return new InputBinaryFilePort(e,r)}InputByteVectorPort.call(this,e);typecheck("InputBinaryFilePort",r,"string");read_only(this,"__filename__",r)}InputBinaryFilePort.prototype=Object.create(InputByteVectorPort.prototype);InputBinaryFilePort.prototype.constructor=InputBinaryFilePort;InputBinaryFilePort.prototype.toString=function(){return"#")};function OutputBinaryFilePort(e,r){if(typeof this!=="undefined"&&!(this instanceof OutputBinaryFilePort)||typeof this==="undefined"){return new OutputBinaryFilePort(e,r)}typecheck("OutputBinaryFilePort",e,"string");read_only(this,"__filename__",e);read_only(this,"_fd",r.valueOf(),{hidden:true});read_only(this,"__type__",binary_port);var a,t;this.write=function(e){var n=this;typecheck("write",e,["number","uint8array"]);var i;if(!a){a=this.internal("fs")}if(!t){t=this.internal("Buffer")}if(LNumber.isNumber(e)){i=t.from([e.valueOf()])}else{i=t.from(Array.from(e))}return new Promise(function(r,t){a.write(n._fd,i,function(e){if(e){t(e)}else{r()}})})}}OutputBinaryFilePort.prototype=Object.create(OutputFilePort.prototype);OutputBinaryFilePort.prototype.constructor=OutputBinaryFilePort;OutputBinaryFilePort.prototype.write_u8=function(e){typecheck("OutputByteVectorPort::write_u8",e,"number");this.write(e)};OutputBinaryFilePort.prototype.write_u8_vector=function(e){typecheck("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};var binary_port=Symbol["for"]("binary");var text_port=Symbol["for"]("text");var eof=new EOF;function EOF(){}EOF.prototype.toString=function(){return"#"};function Interpreter(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},t=r.stderr,n=r.stdin,i=r.stdout,a=_objectWithoutProperties(r,_excluded2);if(typeof this!=="undefined"&&!(this instanceof Interpreter)||typeof this==="undefined"){return new Interpreter(e,_objectSpread({stdin:n,stdout:i,stderr:t},a))}if(typeof e==="undefined"){e="anonymous"}this.__env__=user_env.inherit(e,a);var o="**interaction-environment-defaults**";this.set(o,get_props(a).concat(o));var u=internal_env.inherit("internal-".concat(e));if(is_port(n)){u.set("stdin",n)}if(is_port(t)){u.set("stderr",t)}if(is_port(i)){u.set("stdout",i)}set_interaction_env(this.__env__,u)}Interpreter.prototype.exec=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;var t=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:null;typecheck("Interpreter::exec",e,["string","array"],1);typecheck("Interpreter::exec",r,"boolean",2);global_env.set("**interaction-environment**",this.__env__);if(t===null){t=this.__env__}return exec(e,t,r?t:false)};Interpreter.prototype.get=function(e){var r=this.__env__.get(e);if(is_function(r)){return r.bind(this.__env__)}return r};Interpreter.prototype.set=function(e,r){return this.__env__.set(e,r)};Interpreter.prototype.constant=function(e,r){return this.__env__.constant(e,r)};function LipsError(e,r){this.name="LipsError";this.message=e;this.args=r;this.stack=(new Error).stack}LipsError.prototype=new Error;LipsError.prototype.constructor=LipsError;function Environment(e,r,t){if(arguments.length===1){if(_typeof(arguments[0])==="object"){e=arguments[0];r=null}else if(typeof arguments[0]==="string"){e={};r=null;t=arguments[0]}}this.__docs__=new Map;this.__env__=e;this.__parent__=r;this.__name__=t||"anonymous"}Environment.prototype.list=function(){return get_props(this.__env__)};Environment.prototype.fs=function(){return this.get("**fs**")};Environment.prototype.unset=function(e){if(e instanceof LSymbol){e=e.valueOf()}if(e instanceof LString){e=e.valueOf()}delete this.__env__[e]};Environment.prototype.inherit=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{};if(_typeof(e)==="object"){r=e}if(!e||_typeof(e)==="object"){e="child of "+(this.__name__||"unknown")}return new Environment(r||{},this,e)};Environment.prototype.doc=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:null;var t=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:false;if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}if(r){if(!t){r=trim_lines(r)}this.__docs__.set(e,r);return this}if(this.__docs__.has(e)){return this.__docs__.get(e)}if(this.__parent__){return this.__parent__.doc(e)}};Environment.prototype.newFrame=function(e,r){var n=this.inherit("__frame__");n.set("parent.frame",doc("parent.frame",function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:1;e=e.valueOf();var r=n.__parent__;if(!(r instanceof Environment)){return _nil}if(e<=0){return r}var t=r.get("parent.frame");return t(e-1)},global_env.__env__["parent.frame"].__doc__));r.callee=e;n.set("arguments",r);return n};Environment.prototype._lookup=function(e){if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}if(this.__env__.hasOwnProperty(e)){return Value(this.__env__[e])}if(this.__parent__){return this.__parent__._lookup(e)}};Environment.prototype.toString=function(){return"#"};Environment.prototype.clone=function(){var r=this;var t={};Object.keys(this.__env__).forEach(function(e){t[e]=r.__env__[e]});return new Environment(t,this.__parent__,this.__name__)};Environment.prototype.merge=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:"merge";typecheck("Environment::merge",e,"environment");return this.inherit(r,e.__env__)};function Value(e){if(typeof this!=="undefined"&&!(this instanceof Value)||typeof this==="undefined"){return new Value(e)}this.value=e}Value.isUndefined=function(e){return e instanceof Value&&typeof e.value==="undefined"};Value.prototype.valueOf=function(){return this.value};function Values(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof Values)||typeof this==="undefined"){return new Values(e)}this.__values__=e}Values.prototype.toString=function(){return this.__values__.map(function(e){return toString(e)}).join("\n")};Values.prototype.valueOf=function(){return this.__values__};Environment.prototype.get=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{};typecheck("Environment::get",e,["symbol","string"]);var t=r.throwError,n=t===void 0?true:t;var i=e;if(i instanceof LSymbol||i instanceof LString){i=i.valueOf()}var a=this._lookup(i);if(a instanceof Value){if(Value.isUndefined(a)){return undefined$1}return patch_value(a.valueOf())}if(typeof i==="string"){var o=i.split(".").filter(Boolean);if(o.length>0){var u=_toArray(o),c=u[0],s=u.slice(1);a=this._lookup(c);if(s.length){try{if(a instanceof Value){a=a.valueOf()}else{a=get(root,c);if(is_function(a)){a=unbind(a)}}return get.apply(void 0,[a].concat(_toConsumableArray(s)))}catch(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,r){var t=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:null;typecheck("Environment::set",e,["string","symbol"]);if(LNumber.isNumber(r)){r=LNumber(r)}if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}this.__env__[e]=r;if(t){this.doc(e,t)}return this};Environment.prototype.constant=function(r,e){var t=this;if(this.__env__.hasOwnProperty(r)){throw new Error("Environment::constant: ".concat(r," already exists"))}if(arguments.length===1&&is_plain_object(arguments[0])){var n=arguments[0];Object.keys(n).forEach(function(e){t.constant(r,n[e])})}else{Object.defineProperty(this.__env__,r,{value:e,enumerable:true})}return this};Environment.prototype.has=function(e){return this.__env__.hasOwnProperty(e)};Environment.prototype.ref=function(e){var r=this;while(true){if(!r){break}if(r.has(e)){return r}r=r.__parent__}};Environment.prototype.parents=function(){var e=this;var r=[];while(e){r.unshift(e);e=e.__parent__}return r};function quote(e){if(is_promise(e)){return e.then(quote)}if(e instanceof Pair||e instanceof LSymbol){e[__data__]=true}return e}var native_lambda=parse(tokenize('(lambda ()\n "[native code]"\n (throw "Invalid Invocation"))'))[0];var get=doc("get",function e(r){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i0&&arguments[0]!==undefined$1?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 Function get character from string port or EOF object if no more\n data in string port."),"read-line":doc("read-line",function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:null;if(e===null){e=internal(this,"stdin")}typecheck_text_port("read-line",e,"input-port");return e.read_line()},"(read-char port)\n\n Function read next character from input port."),"read-char":doc("read-char",function(){var e=arguments.length>0&&arguments[0]!==undefined$1?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 Function read next character from input port."),read:doc("read",function(){var e=_asyncToGenerator(regenerator.mark(function e(){var t,n,i,a,o,u,c,s,l,f=arguments;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:t=f.length>0&&f[0]!==undefined$1?f[0]:null;if(!LString.isString(t)){r.next=35;break}n=true;i=false;r.prev=4;o=_asyncIterator(parse(t,this));case 6:r.next=8;return o.next();case 8:u=r.sent;n=u.done;r.next=12;return u.value;case 12:c=r.sent;if(n){r.next=19;break}s=c;return r.abrupt("return",s);case 16:n=true;r.next=6;break;case 19:r.next=25;break;case 21:r.prev=21;r.t0=r["catch"](4);i=true;a=r.t0;case 25:r.prev=25;r.prev=26;if(!(!n&&o["return"]!=null)){r.next=30;break}r.next=30;return o["return"]();case 30:r.prev=30;if(!i){r.next=33;break}throw a;case 33:return r.finish(30);case 34:return r.finish(25);case 35:if(t===null){l=internal(this,"stdin")}else{l=t}typecheck_text_port("read",l,"input-port");return r.abrupt("return",l.read.call(this));case 38:case"end":return r.stop()}}},e,this,[[4,21,25,35],[26,,30,34]])}));function r(){return e.apply(this,arguments)}return r}(),"(read [string])\n\n Function if used with string will parse the string and return\n list structure of LIPS code. If called without an argument it\n will read string from standard input (using browser prompt or\n user defined way) and call itself with that string (parse is)\n function can be used together with eval to evaluate code from\n string"),pprint:doc("pprint",function e(r){if(r instanceof Pair){r=new lips.Formatter(r.toString(true))["break"]().format();global_env.get("display").call(global_env,r)}else{global_env.get("write").call(global_env,r)}global_env.get("newline").call(global_env)},"(pprint expression)\n\n Pretty print list expression, if called with non-pair it just call\n print function with passed argument."),print:doc("print",function e(){var r=global_env.get("display");var t=global_env.get("newline");for(var n=arguments.length,i=new Array(n),a=0;a1?t-1:0),i=1;in.length){throw new Error("Not enough arguments")}var u=0;var c=global_env.get("repr");r=r.replace(a,function(e){var r=e[1];if(r==="~"){return"~"}else if(r==="%"){return"\n"}else{var t=n[u++];if(r==="a"){return c(t)}else{return c(t,true)}}});o=r.match(/~([\S])/);if(o){throw new Error("format: Unrecognized escape seqence ".concat(o[1]))}return r},"(format string n1 n2 ...)\n\n Function accepts string template and replacing any escape sequences\n by arguments:\n\n * ~a value as if printed with display\n * ~s value as if printed with write\n * ~% newline character\n * ~~ literal tilde '~' is inserted\n\n if there missing arguments or other escape character it throw exception."),display:doc("display",function e(r){var t=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:null;if(t===null){t=internal(this,"stdout")}else{typecheck("display",t,"output-port")}var n=global_env.get("repr")(r);t.write.call(global_env,n)},"(display arg [port])\n\n Function send string to standard output or provied port."),"display-error":doc("display-error",function e(){var r=internal(this,"stderr");var t=global_env.get("repr");for(var n=arguments.length,i=new Array(n),a=0;a1&&arguments[1]!==undefined$1?arguments[1]:{},t=r.dynamic_scope,n=r.error;if(t){t=this}var i=this;var o;var u=_evaluate(e.cdr.car,{env:this,dynamic_scope:t,error:n});u=resolve_promises(u);function c(r,t,n){if(is_promise(r)){return r.then(function(e){return c(r,e,n)})}if(is_promise(t)){return t.then(function(e){return c(r,e,n)})}if(is_promise(n)){return n.then(function(e){return c(r,t,e)})}i.get("set-obj!").call(i,r,t,n);return n}if(e.car instanceof Pair&&LSymbol.is(e.car.car,".")){var s=e.car.cdr.car;var l=e.car.cdr.cdr.car;var f=_evaluate(s,{env:this,dynamic_scope:t,error:n});var _=_evaluate(l,{env:this,dynamic_scope:t,error:n});return c(f,_,u)}if(!(e.car instanceof LSymbol)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var p=e.car.valueOf();o=this.ref(e.car.__name__);return unpromise(u,function(e){if(!o){var r=p.split(".");if(r.length>1){var t=r.pop();var n=r.join(".");var i=a.get(n,{throwError:false});if(i){c(i,t,e);return}}throw new Error("Unbound variable `"+p+"'")}o.set(p,e)})}),"(set! name value)\n\n Macro that can be used to set the value of the variable (mutate)\n it search the scope chain until it finds first non emtpy slot and set it."),"unset!":doc(new Macro("set!",function(e){if(!(e.car instanceof LSymbol)){throw new Error("unset! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var r=e.car;var t=this.ref(r);if(t){delete t.__env__[r.__name__]}}),"(unset! name)\n\n Function delete specified name from environment."),"set-car!":doc("set-car!",function(e,r){typecheck("set-car!",e,"pair");e.car=r},"(set-car! obj value)\n\n Function that set car (head) of the list/pair to specified value.\n It can destroy the list. Old value is lost."),"set-cdr!":doc("set-cdr!",function(e,r){typecheck("set-cdr!",e,"pair");e.cdr=r},"(set-cdr! obj value)\n\n Function that set cdr (tail) of the list/pair to specified value.\n It can destroy the list. Old value is lost."),"empty?":doc("empty?",function(e){return typeof e==="undefined"||e===_nil},"(empty? object)\n\n Function return true if value is undfined empty list."),gensym:doc("gensym",gensym,"(gensym)\n\n Function generate unique symbol, to use with macros as meta name."),load:doc("load",function e(r,t){typecheck("load",r,"string");var n=this;if(n.__name__==="__frame__"){n=n.__parent__}if(!(t instanceof Environment)){if(n===global_env){t=n}else{t=this.get("**interaction-environment**")}}var i="**module-path**";var a=global_env.get(i,{throwError:false});r=r.valueOf();if(!r.match(/.[^.]+$/)){r+=".scm"}function o(e){if(type(e)==="buffer"){e=e.toString()}e=e.replace(/^#!.*/,"");if(e.match(/\{/)){e=unserialize(e)}return exec(e,t)}if(is_node()){return new Promise(function(t,n){var e=nodeRequire("path");if(a){a=a.valueOf();r=e.join(a,r)}global_env.set(i,e.dirname(r));nodeRequire("fs").readFile(r,function(e,r){if(e){n(e);global_env.set(i,a)}else{try{o(r).then(function(){t();global_env.set(i,a)})["catch"](n)}catch(e){n(e)}}})})}if(a){a=a.valueOf();r=a+"/"+r.replace(/^\.?\/?/,"")}return root.fetch(r).then(function(e){return e.text()}).then(function(e){global_env.set(i,r.replace(/\/[^/]*$/,""));return o(e)}).then(function(){})["finally"](function(){global_env.set(i,a)})},"(load filename)\n (load filename environment)\n\n Function fetch the file and evaluate its content as LIPS code,\n If second argument is provided and it's environment the evaluation\n will happen in that environment."),do:doc(new Macro("do",function(){var t=_asyncToGenerator(regenerator.mark(function e(t,n){var i,a,o,u,c,s,l,f,_,p,h;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:i=n.dynamic_scope,a=n.error;o=this;if(i){i=o}u=o.inherit("do");c=t.car;s=t.cdr.car;l=t.cdr.cdr;if(l!==_nil){l=new Pair(LSymbol("begin"),l)}f={env:o,dynamic_scope:i,error:a};_=c;case 10:if(!(_!==_nil)){r.next=21;break}p=_.car;r.t0=u;r.t1=p.car;r.next=16;return _evaluate(p.cdr.car,f);case 16:r.t2=r.sent;r.t0.set.call(r.t0,r.t1,r.t2);_=_.cdr;r.next=10;break;case 21:f={env:u,dynamic_scope:i,error:a};h=regenerator.mark(function e(){var t,n,i,a,o;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!(l!==_nil)){r.next=3;break}r.next=3;return lips.evaluate(l,f);case 3:t=c;n={};case 5:if(!(t!==_nil)){r.next=15;break}i=t.car;if(!(i.cdr.cdr!==_nil)){r.next=12;break}r.next=10;return _evaluate(i.cdr.cdr.car,f);case 10:a=r.sent;n[i.car.valueOf()]=a;case 12:t=t.cdr;r.next=5;break;case 15:o=Object.getOwnPropertySymbols(n);Object.keys(n).concat(o).forEach(function(e){u.set(e,n[e])});case 17:case"end":return r.stop()}}},e)});case 23:r.next=25;return _evaluate(s.car,f);case 25:r.t3=r.sent;if(!(r.t3===false)){r.next=30;break}return r.delegateYield(h(),"t4",28);case 28:r.next=23;break;case 30:if(!(s.cdr!==_nil)){r.next=34;break}r.next=33;return _evaluate(s.cdr.car,f);case 33:return r.abrupt("return",r.sent);case 34:case"end":return r.stop()}}},e,this)}));return function(e,r){return t.apply(this,arguments)}}()),"(do (( )) (test expression) . body)\n\n Iteration macro that evaluate the expression body in scope of the variables.\n On Eeach loop it increase the variables according to next expression and run\n test to check if the loop should continue. If test is signle call the macro\n will not return anything. If the test is pair of expression and value the\n macro will return that value after finish."),if:doc(new Macro("if",function(t,e){var n=e.dynamic_scope,i=e.error;if(n){n=this}var a=this;var r=function e(r){if(r===false){return _evaluate(t.cdr.cdr.car,{env:a,dynamic_scope:n,error:i})}else{return _evaluate(t.cdr.car,{env:a,dynamic_scope:n,error:i})}};if(t===_nil){throw new Error("too few expressions for `if`")}var o=_evaluate(t.car,{env:a,dynamic_scope:n,error:i});return unpromise(o,r)}),"(if cond true-expr false-expr)\n\n Macro evaluate condition expression and if the value is true, it\n evaluate and return true expression if not it evaluate and return\n false expression"),"let-env":new Macro("let-env",function(r){var e=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{};var t=e.dynamic_scope,n=e.error;typecheck("let-env",r,"pair");var i=_evaluate(r.car,{env:this,dynamic_scope:t,error:n});return unpromise(i,function(e){typecheck("let-env",e,"environment");return _evaluate(Pair(LSymbol("begin"),r.cdr),{env:e,dynamic_scope:t,error:n})})},"(let-env env . body)\n\n Special macro that evaluate 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 new environment, then evaluate and assign values to\n names and then evaluate the body in context of that environment.\n Values are evaluated sequentialy and next value can access to\n previous values/names."),"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 use can use recursive code as well as reference previous binding.\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 next argument get environment\n from previous let variable, so they you can define one variable,\n and use in next argument."),let:doc(let_macro(Symbol["for"]("let")),"(let ((a value-a) (b value-b)) body)\n\n Macro that creates new environment, then evaluate and assign values to\n names and then evaluate the body in context of that environment.\n Values are evaluated sequentialy but you can't access\n previous values/names when next are evaluated. You can only get them\n from body of let expression."),"begin*":doc(pararel("begin*",function(e){return e.pop()}),"(begin* . expr)\n\n This macro is parallel version of begin. It evaluate each expression and\n if it's a promise it will evaluate it in parallel and return value\n of last expression."),begin:doc(new Macro("begin",function(e,r){var n=Object.assign({},r);var i=global_env.get("list->array")(e);if(n.dynamic_scope){n.dynamic_scope=this}n.env=this;var a;return function r(){if(i.length){var e=i.shift();var t=_evaluate(e,n);return unpromise(t,function(e){a=e;return r()})}else{return a}}()}),"(begin . args)\n\n Macro runs list of expression and return valuate of the list one.\n It can be used in place where you can only have single exression,\n like if expression."),ignore:new Macro("ignore",function(e,r){var t=r.dynamic_scope,n=r.error;var i={env:this,error:n};if(t){i.dynamic_scope=this}_evaluate(new Pair(new LSymbol("begin"),e),i)},"(ignore expression)\n\n Macro that will evaluate expression and swallow any promises that may\n be created. It wil run and ignore any value that may be returned by\n expression. The code should have side effects and/or when it's promise\n it should resolve to undefined."),define:doc(Macro.defmacro("define",function(t,e){var n=this;if(t.car instanceof Pair&&t.car.car instanceof LSymbol){var r=new Pair(new LSymbol("define"),new Pair(t.car.car,new Pair(new Pair(new LSymbol("lambda"),new Pair(t.car.cdr,t.cdr)))));return r}else if(e.macro_expand){return}if(e.dynamic_scope){e.dynamic_scope=this}e.env=n;var i=t.cdr.car;var a;if(i instanceof Pair){i=_evaluate(i,e);a=true}else if(i instanceof LSymbol){i=n.get(i)}typecheck("define",t.car,"symbol");return unpromise(i,function(e){if(n.__name__===Syntax.__merge_env__){n=n.__parent__}if(a&&(is_function(e)&&is_lambda(e)||e instanceof Syntax)){e.__name__=t.car.valueOf();if(e.__name__ instanceof LString){e.__name__=e.__name__.valueOf()}}var r;if(t.cdr.cdr instanceof Pair&&LString.isString(t.cdr.cdr.car)){r=t.cdr.cdr.car.valueOf()}n.set(t.car,e,r,true)})}),"(define name expression)\n (define (function-name . args) body)\n\n Macro for defining values. It can be used to define variables,\n or function. If first argument is list it will create function\n with name beeing first element of the list. The macro evalute\n code `(define function (lambda args body))`"),"set-obj!":doc("set-obj!",function(e,r,t){var n=_typeof(e);if(is_null(e)||n!=="object"&&n!=="function"){var i=typeErrorMessage("set-obj!",type(e),["object","function"]);throw new Error(i)}typecheck("set-obj!",r,["string","symbol","number"]);e=unbind(e);r=r.valueOf();if(arguments.length===2){delete e[r]}else if(is_prototype(e)&&is_function(t)){e[r]=unbind(t);e[r][__prototype__]=true}else if(is_function(t)||is_native(t)||t===_nil){e[r]=t}else{e[r]=t?t.valueOf():t}},"(set-obj! obj key value)\n\n Function set property of JavaScript object"),"null-environment":doc("null-environment",function(){return global_env.inherit("null")},"(null-environment)\n\n Function return new base environment with std lib."),values:doc("values",function e(){for(var r=arguments.length,t=new Array(r),n=0;n1&&arguments[1]!==undefined$1?arguments[1]:{},_=e.dynamic_scope,p=e.error;var h=this;var d;if(f.cdr instanceof Pair&&LString.isString(f.cdr.car)&&f.cdr.cdr!==_nil){d=f.cdr.car.valueOf()}function m(){var e;if(_){if(!(this instanceof Environment)){e=h}else{e=this}}else{e=h}e=e.inherit("lambda");var r=f.car;var t=0;var n;if(typeof this!=="undefined"&&!(this instanceof Environment)){if(this&&!this.__instance__){Object.defineProperty(this,"__instance__",{enumerable:false,get:function e(){return true},set:function e(){},configurable:false})}e.set("this",this)}for(var i=arguments.length,a=new Array(i),o=0;o2&&arguments[2]!==undefined$1?arguments[2]:a;if(e instanceof Pair){var n=e.car;var i=e.cdr;if(t(n)){n=r(n)}if(t(i)){i=r(i)}if(is_promise(n)||is_promise(i)){return promise_all([n,i]).then(function(e){var r=_slicedToArray(e,2),t=r[0],n=r[1];return new Pair(t,n)})}else{return new Pair(n,i)}}return e}function o(e,r){if(e instanceof Pair){if(r!==_nil){e.append(r)}}else{e=new Pair(e,r)}return e}function t(e){return!!e.filter(function(e){return e instanceof Pair&&LSymbol.is(e.car,/^(unquote|unquote-splicing)$/)}).length}function f(e,n,i){return e.reduce(function(e,r){if(!(r instanceof Pair)){e.push(r);return e}if(LSymbol.is(r.car,"unquote-splicing")){var t;if(n+11){var r="You can't splice multiple atoms inside list";throw new Error(r)}if(!(i.cdr instanceof Pair&&t[0]===_nil)){return t[0]}}t=t.map(function(e){if(h.has(e)){return e.clone()}else{h.add(e);return e}});var n=d(i.cdr,0,1);if(n===_nil&&t[0]===_nil){return undefined$1}return unpromise(n,function(e){if(t[0]===_nil){return e}if(t.length===1){return o(t[0],e)}var r=t.reduce(function(e,r){return o(e,r)});return o(r,e)})})}(i.car.cdr)}var h=new Set;function d(e,r,t){if(e instanceof Pair){if(e.car instanceof Pair){if(LSymbol.is(e.car.car,"unquote-splicing")){return p(e,r+1,t)}if(LSymbol.is(e.car.car,"unquote")){if(r+2===t&&e.car.cdr instanceof Pair&&e.car.cdr.car instanceof Pair&&LSymbol.is(e.car.cdr.car.car,"unquote-splicing")){var n=e.car.cdr;return new Pair(new Pair(new LSymbol("unquote"),p(n,r+2,t)),_nil)}else if(e.car.cdr instanceof Pair&&e.car.cdr.cdr!==_nil){if(e.car.cdr.car instanceof Pair){var i=[];return function r(t){if(t===_nil){return Pair.fromArray(i)}return unpromise(_evaluate(t.car,{env:s,dynamic_scope:u,error:c}),function(e){i.push(e);return r(t.cdr)})}(e.car.cdr)}else{return e.car.cdr}}}}if(LSymbol.is(e.car,"quasiquote")){var a=d(e.cdr,r,t+1);return new Pair(e.car,a)}if(LSymbol.is(e.car,"quote")){return new Pair(e.car,d(e.cdr,r,t))}if(LSymbol.is(e.car,"unquote")){r++;if(rt){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(e.cdr instanceof Pair){if(e.cdr.cdr!==_nil){if(e.cdr.car instanceof Pair){var o=[];return function r(t){if(t===_nil){return Pair.fromArray(o)}return unpromise(_evaluate(t.car,{env:s,dynamic_scope:u,error:c}),function(e){o.push(e);return r(t.cdr)})}(e.cdr)}else{return e.cdr}}else{return _evaluate(e.cdr.car,{env:s,dynamic_scope:u,error:c})}}else{return e.cdr}}return l(e,function(e){return d(e,r,t)})}else if(is_plain_object(e)){return _(e,r,t)}else if(e instanceof Array){return f(e,r,t)}return e}function n(e){if(e instanceof Pair){delete e[__data__];if(!e.haveCycles("car")){n(e.car)}if(!e.haveCycles("cdr")){n(e.cdr)}}}if(is_plain_object(e.car)&&!t(Object.values(e.car))){return quote(e.car)}if(Array.isArray(e.car)&&!t(e.car)){return quote(e.car)}if(e.car instanceof Pair&&!e.car.find("unquote")&&!e.car.find("unquote-splicing")&&!e.car.find("quasiquote")){return quote(e.car)}var i=d(e.car,0,1);return unpromise(i,function(e){n(e);return quote(e)})},"(quasiquote list ,value ,@value)\n\n Similar macro to `quote` but inside it you can use special\n expressions unquote abbreviated to , that will evaluate expresion inside\n and return its value or unquote-splicing abbreviated to ,@ that will\n evaluate expression but return value without parenthesis (it will join)\n the list with its value. Best used with macros but it can be used outside"),clone:doc("clone",function e(r){typecheck("clone",r,"pair");return r.clone()},"(clone list)\n\n Function return clone of the list."),append:doc("append",function e(){var r;for(var t=arguments.length,n=new Array(t),i=0;iarray")(r).reverse();return global_env.get("array->list")(t)}else if(!(r instanceof Array)){throw new Error(typeErrorMessage("reverse",type(r),"array or pair"))}else{return r.reverse()}},"(reverse list)\n\n Function will reverse the list or array. If value is not a list\n or array it will throw exception."),nth:doc("nth",function e(r,t){typecheck("nth",r,"number");typecheck("nth",t,["array","pair"]);if(t instanceof Pair){var n=t;var i=0;while(iarray")(t).join(r)},"(join separator list)\n\n Function return string by joining elements of the list"),split:doc("split",function e(r,t){typecheck("split",r,["regex","string"]);typecheck("split",t,"string");return global_env.get("array->list")(t.split(r))},"(split separator string)\n\n Function create list by splitting string by separatar that can\n be a string or regular expression."),replace:doc("replace",function e(r,t,n){typecheck("replace",r,["regex","string"]);typecheck("replace",t,["string","function"]);typecheck("replace",n,"string");return n.replace(r,t)},"(replace pattern replacement string)\n\n Function change pattern to replacement inside string. Pattern can be string\n or regex and replacement can be function or string."),match:doc("match",function e(r,t){typecheck("match",r,["regex","string"]);typecheck("match",t,"string");var n=t.match(r);return n?global_env.get("array->list")(n):false},"(match pattern string)\n\n function return match object from JavaScript as list or #f if not match."),search:doc("search",function e(r,t){typecheck("search",r,["regex","string"]);typecheck("search",t,"string");return t.search(r)},"(search pattern string)\n\n Function return first found index of the pattern inside a string"),repr:doc("repr",function e(r,t){return toString(r,t)},"(repr obj)\n\n Function return string LIPS representation of an object as string."),"escape-regex":doc("escape-regex",function(e){typecheck("escape-regex",e,"string");return escape_regex(e.valueOf())},"(escape-regex string)\n\n Function return new string where all special operators used in regex,\n are escaped with slash so they can be used in RegExp constructor\n to match literal string"),env:doc("env",function e(e){e=e||this;var r=Object.keys(e.__env__).map(LSymbol);var t;if(r.length){t=Pair.fromArray(r)}else{t=_nil}if(e.__parent__ instanceof Environment){return global_env.get("env")(e.__parent__).append(t)}return t},"(env)\n (env obj)\n\n Function return list of values (functions, macros and variables)\n inside environment and it's parents."),new:doc("new",function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n2&&arguments[2]!==undefined$1?arguments[2]:specials.LITERAL;typecheck("set-special!",e,"string",1);typecheck("set-special!",r,"symbol",2);specials.append(e.valueOf(),r,t)},'(set-special! symbol name [type])\n\n Add 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 constant value\n lips.specials.SPLICE if this constant is used it will transform\n `#(1 2 3)` into (x 1 2 3) that is required by # that define vectors.'),get:get,".":get,unbind:doc(unbind,"(unbind fn)\n\n Function remove bidning from function so you can get props from it."),type:doc(type,"(type object)\n\n Function return type of an object as string."),debugger:doc("debugger",function(){debugger},"(debugger)\n\n Function stop JavaScript code in debugger."),in:doc("in",function(e,r){if(e instanceof LSymbol||e instanceof LString||e instanceof LNumber){e=e.valueOf()}return e in unbox(r)},"(in key value)\n\n Function use is in operator to check if value is in object."),instanceof:doc("instanceof",function(e,r){return r instanceof unbind(e)},"(instanceof type obj)\n\n Function check of object is instance of object."),"prototype?":doc("prototype?",is_prototype,"(prototype? obj)\n\n Function check if value is JavaScript Object prototype."),"macro?":doc("macro?",function(e){return e instanceof Macro},"(macro? expression)\n\n Function check if value is a macro."),"function?":doc("function?",is_function,"(function? expression)\n\n Function check if value is a 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 Function check if value is real number."),"number?":doc("number?",function(e){return Number.isNaN(e)||LNumber.isNumber(e)},"(number? expression)\n\n Function check if value is a number or NaN value."),"string?":doc("string?",function(e){return LString.isString(e)},"(string? expression)\n\n Function check if value is a string."),"pair?":doc("pair?",function(e){return e instanceof Pair},"(pair? expression)\n\n Function check if value is a pair or list structure."),"regex?":doc("regex?",function(e){return e instanceof RegExp},"(regex? expression)\n\n Function check if value is regular expression."),"null?":doc("null?",function(e){return is_null(e)},"(null? expression)\n\n Function check if value is nulish."),"boolean?":doc("boolean?",function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Function check if value is boolean."),"symbol?":doc("symbol?",function(e){return e instanceof LSymbol},"(symbol? expression)\n\n Function check if value is LIPS symbol"),"array?":doc("array?",function(e){return e instanceof Array},"(array? expression)\n\n Function check if value is an arrray."),"object?":doc("object?",function(e){return e!==_nil&&e!==null&&!(e instanceof LCharacter)&&!(e instanceof RegExp)&&!(e instanceof LString)&&!(e instanceof Pair)&&!(e instanceof LNumber)&&_typeof(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Function check if value is an plain object."),flatten:doc("flatten",function e(r){typecheck("flatten",r,"pair");return r.flatten()},"(flatten list)\n\n Return 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 convert JavaScript array to LIPS list."),"tree->array":doc("tree->array",to_array("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":doc("list->array",to_array("list->array"),"(list->array list)\n\n Function convert LIPS list into JavaScript array."),apply:doc("apply",function e(r){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;iarray").call(this,a));return r.apply(this,prepare_fn_args(r,n))},"(apply fn list)\n\n Function that call function with list of arguments."),length:doc("length",function e(r){if(!r){return LNumber(0)}if(r instanceof Pair){return LNumber(r.length())}if("length"in r){return LNumber(r.length)}},"(length expression)\n\n Function return length of the object, the object can be list\n or any object that have length property."),"string->number":doc("string->number",function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:10;typecheck("string->number",e,"string",1);typecheck("string->number",r,"number",2);e=e.valueOf();r=r.valueOf();if(e.match(rational_bare_re)||e.match(rational_re)){return parse_rational(e,r)}else if(e.match(complex_bare_re)||e.match(complex_re)){return parse_complex(e,r)}else{var t=r===10&&!e.match(/e/i)||r===16;if(e.match(int_bare_re)&&t||e.match(int_re)){return parse_integer(e,r)}if(e.match(float_re)){return parse_float(e)}}return false},"(string->number number [radix])\n\n Function convert string to number."),try:doc(new Macro("try",function(r,e){var s=this;var l=e.dynamic_scope,f=e.error;return new Promise(function(i,n){var a,o;if(LSymbol.is(r.cdr.car.car,"catch")){a=r.cdr.car;if(r.cdr.cdr instanceof Pair&&LSymbol.is(r.cdr.cdr.car.car,"finally")){o=r.cdr.cdr.car}}else if(LSymbol.is(r.cdr.car.car,"finally")){o=r.cdr.car}if(!(o||a)){throw new Error("try: invalid syntax")}var u=i;if(o){u=function e(r,t){u=n;unpromise(_evaluate(new Pair(new LSymbol("begin"),o.cdr),c),function(){t(r)})}}var c={env:s,error:function e(r){var t=s.inherit("try");if(a){t.set(a.cdr.car.car,r);var n={env:t,error:f};if(l){n.dynamic_scope=s}unpromise(_evaluate(new Pair(new LSymbol("begin"),a.cdr.cdr),n),function(e){u(e,i)})}else{u(r,f)}}};if(l){c.dynamic_scope=s}var e=_evaluate(r.car,c);if(is_promise(e)){e.then(function(e){u(e,i)})["catch"](c.error)}else{u(e,i)}})}),"(try expr (catch (e) code))\n (try expr (catch (e) code) (finally code))\n (try expr (finally code))\n\n Macro execute user code and catch exception. If catch is provided\n it's executed when expression expr throw error. If finally is provide\n it's always executed at the end."),raise:doc("raise",function(e){throw e},"(raise obj)\n\n Throws new exception with given object."),throw:doc("throw",function(e){throw new Error(e)},"(throw string)\n\n Throws new expection."),find:doc("find",function r(t,n){typecheck("find",t,["regex","function"]);typecheck("find",n,["pair","nil"]);if(is_null(n)){return _nil}var e=matcher("find",t);return unpromise(e(n.car),function(e){if(e&&e!==_nil){return n.car}return r(t,n.cdr)})},"(find fn list)\n (find regex list)\n\n Higher order Function find first value for which function return true.\n If called with regex it will create matcher function."),"for-each":doc("for-each",function(e){var r;typecheck("for-each",e,"function");for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i1?r-1:0),a=1;a3?n-3:0),a=3;a3?i-3:0),o=3;oarray")(t);var a=[];var o=matcher("filter",r);return function r(t){function e(e){if(e&&e!==_nil){a.push(n)}return r(++t)}if(t===i.length){return Pair.fromArray(a)}var n=i[t];return unpromise(o(n),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher order function that call `fn` for each element of the list\n and return list for only those elements for which funtion return\n true value. If called with regex it will create matcher function."),compose:doc(compose,"(compose . fns)\n\n Higher order function and create new function that apply all functions\n From right to left and return it's value. Reverse of compose.\n e.g.:\n ((compose (curry + 2) (curry * 3)) 3)\n 11\n "),pipe:doc(pipe,"(pipe . fns)\n\n Higher order function and create new function that apply all functions\n From left to right and return it's value. Reverse of compose.\n e.g.:\n ((pipe (curry + 2) (curry * 3)) 3)\n 15"),curry:doc(curry,"(curry fn . args)\n\n Higher order function that create curried version of the function.\n The result function will have parially applied arguments and it\n will keep returning functions until all arguments are added\n\n e.g.:\n (define (add a b c d) (+ a b c d))\n (define add1 (curry add 1))\n (define add12 (add 2))\n (display (add12 3 4))"),gcd:doc("gcd",function e(){for(var r=arguments.length,t=new Array(r),n=0;nu?a%=u:u%=a}a=abs(c*t[o])/(a+u)}return LNumber(a)},"(lcm n1 n2 ...)\n\n Function return the least common multiple of their arguments."),"odd?":doc("odd?",single_math_op(function(e){return LNumber(e).isOdd()}),"(odd? number)\n\n Function check if number os odd."),"even?":doc("even?",single_math_op(function(e){return LNumber(e).isEven()}),"(even? number)\n\n Function check if number is even."),"*":doc("*",reduce_math_op(function(e,r){return LNumber(e).mul(r)},LNumber(1)),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":doc("+",reduce_math_op(function(e,r){return LNumber(e).add(r)},LNumber(0)),"(+ . numbers)\n\n Sum all numbers passed as arguments. If single value is passed it will\n return that value."),"-":doc("-",function(){for(var e=arguments.length,r=new Array(e),t=0;t":doc(">",function(){for(var e=arguments.length,r=new Array(e),t=0;t",r,"number");return seq_compare(function(e,r){return LNumber(e).cmp(r)===1},r)},"(> x1 x2 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically increasing"),"<":doc("<",function(){for(var e=arguments.length,r=new Array(e),t=0;t=":doc(">=",function(){for(var e=arguments.length,r=new Array(e),t=0;t=",r,"number");return seq_compare(function(e,r){return[0,1].includes(LNumber(e).cmp(r))},r)},"(>= x1 x2 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically nondecreasing"),"eq?":doc("eq?",equal,"(eq? a b)\n\n Function compare two values if they are identical."),or:doc(new Macro("or",function(e,r){var i=r.dynamic_scope,a=r.error;var o=global_env.get("list->array")(e);var u=this;if(i){i=u}if(!o.length){return false}var c;return function r(){function e(e){c=e;if(c!==false){return c}else{return r()}}if(!o.length){if(c!==false){return c}else{return false}}else{var t=o.shift();var n=_evaluate(t,{env:u,dynamic_scope:i,error:a});return unpromise(n,e)}}()}),"(or . expressions)\n\n Macro execute the values one by one and return the one that is truthy value.\n If there are no expression that evaluate to true it return false."),and:doc(new Macro("and",function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},i=r.dynamic_scope,a=r.error;var o=global_env.get("list->array")(e);var u=this;if(i){i=u}if(!o.length){return true}var c;return function r(){function e(e){c=e;if(c===false){return false}else{return r()}}var t=o.shift();if(typeof t==="undefined"){if(c!==false){return c}else{return false}}else{var n=_evaluate(t,{env:u,dynamic_scope:i,error:a});return unpromise(n,e)}}()}),"(and . expressions)\n\n Macro evalute each expression in sequence if any value return false it will\n return false. If each value return true it will return the last value.\n If it's called without arguments it will return true."),"|":doc("|",function(e,r){return LNumber(e).or(r)},"(& a b)\n\n Function calculate or bit operation."),"&":doc("&",function(e,r){return LNumber(e).and(r)},"(& a b)\n\n Function calculate and bit operation."),"~":doc("~",function(e){return LNumber(e).neg()},"(~ number)\n\n Function negate the value."),">>":doc(">>",function(e,r){return LNumber(e).shr(r)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":doc("<<",function(e,r){return LNumber(e).shl(r)},"(<< a b)\n\n Function left shit the value a by value b."),not:doc("not",function e(r){if(is_null(r)){return true}return!r},"(not object)\n\n Function return negation of the argument.")},undefined$1,"global");var user_env=global_env.inherit("user-env");function set_interaction_env(e,r){e.constant("**internal-env**",r);e.doc("**internal-env**","**internal-env**\n\n Constant used to hide stdin, stdout and stderr so they don't interfere\n with variables with the same name. Constants are internal type\n of variables that can't be redefined, defining variable with 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 contain references to stdin, stdout and stderr.");(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(r){var t=e[r]?e[r]:r;global_env.set(t,doc(t,function(e){typecheck(t,e,"number");if(e instanceof LNumber){return e[r]()}},"(".concat(t," number)\n\n Function calculate ").concat(t," of a number.")))})})();function allPossibleCases(e){if(e.length===1){return e[0]}else{var r=[];var t=allPossibleCases(e.slice(1));for(var n=0;n3&&arguments[3]!==undefined$1?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(n!==null){i+=" (argument ".concat(n,")")}if(t instanceof Array){if(t.length===1){t=t[0]}else{var a=t[t.length-1];t=t.slice(0,-1).join(", ")+" or "+a}}return"Expecting ".concat(t,", got ").concat(r).concat(i)}function typecheck_args(t,e,n){e.forEach(function(e,r){typecheck(t,e,n,r+1)})}function typecheck_text_port(e,r,t){typecheck(e,r,t);if(r.__type__===binary_port){throw new Error(typeErrorMessage(e,"binary-port","textual-port"))}}function typecheck(e,r,t){var n=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:null;e=e.valueOf();var i=type(r).toLowerCase();var a=false;if(t instanceof Pair){t=t.to_array()}if(t instanceof Array){t=t.map(function(e){return e.valueOf()})}if(t instanceof Array){t=t.map(function(e){return e.valueOf().toLowerCase()});if(t.includes(i)){a=true}}else{t=t.valueOf().toLowerCase()}if(!a&&i!==t){throw new Error(typeErrorMessage(e,i,t,n))}}function self_evaluated(e){var r=_typeof(e);return["string","function"].includes(r)||_typeof(e)==="symbol"||e instanceof QuotedPromise||e instanceof LSymbol||e instanceof LNumber||e instanceof LString||e instanceof RegExp}function is_native(e){return e instanceof LNumber||e instanceof LString||e instanceof LCharacter}function has_own_symbol(e,r){if(e===null){return false}return _typeof(e)==="object"&&r in Object.getOwnPropertySymbols(e)}function is_iterator(e,r){if(has_own_symbol(e,r)||has_own_symbol(e.__proto__,r)){return is_function(e[r])}}function type(e){var r={pair:Pair,symbol:LSymbol,character:LCharacter,values:Values,"input-port":InputPort,"output-port":OutputPort,number:LNumber,regex:RegExp,syntax:Syntax,macro:Macro,string:LString,array:Array,"native-symbol":Symbol};if(Number.isNaN(e)){return"NaN"}if(e===_nil){return"nil"}if(e===null){return"null"}for(var t=0,n=Object.entries(r);t2&&arguments[2]!==undefined$1?arguments[2]:{},a=r.env,o=r.dynamic_scope,t=r.error,u=t===void 0?function(){}:t;e=evaluate_args(e,{env:a,dynamic_scope:o,error:u});return unpromise(e,function(e){if(is_raw_lambda(i)){i=unbind(i)}e=prepare_fn_args(i,e);var r=e.slice();var t=(o||a).newFrame(i,r);var n=resolve_promises(i.apply(t,e));return unpromise(n,function(e){if(e instanceof Pair){e.markCycles();return quote(e)}if(Number.isNaN(e)){return e}if(typeof e==="number"){return LNumber(e)}if(typeof e==="string"){return LString(e)}return e},u)})}function _evaluate(r){var e=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},t=e.env,n=e.dynamic_scope,i=e.error,a=i===void 0?function(){}:i;try{if(n===true){t=n=t||global_env}else if(t===true){t=n=global_env}else{t=t||global_env}var o={env:t,dynamic_scope:n,error:a};var u;if(is_null(r)){return r}if(r instanceof LSymbol){return t.get(r)}if(!(r instanceof Pair)){return r}var c=r.car;var s=r.cdr;if(c instanceof Pair){u=resolve_promises(_evaluate(c,o));if(is_promise(u)){return u.then(function(e){return _evaluate(new Pair(e,r.cdr),o)})}else if(!is_function(u)){throw new Error(type(u)+" "+t.get("repr")(u)+" is not a function while evaluating "+r.toString())}}if(c instanceof LSymbol){u=t.get(c)}else if(is_function(c)){u=c}var l;if(u instanceof Syntax){l=evaluate_syntax(u,r,o)}else if(u instanceof Macro){l=evaluate_macro(u,s,o)}else if(is_function(u)){l=apply(u,s,o)}else if(r instanceof Pair){u=c&&c.toString();throw new Error("".concat(type(c)," ").concat(u," is not a function"))}else if(!is_function(u)){if(u){var f="".concat(type(u)," `").concat(u,"' is not a function");throw new Error(f)}throw new Error("Unknown function `".concat(c.toString(),"'"))}else{return r}var _=t.get(Symbol["for"]("__promise__"),{throwError:false});if(_===true&&is_promise(l)){l=l.then(function(e){if(e instanceof Pair&&!u[__data__]){return _evaluate(e,o)}return e});return new QuotedPromise(l)}return l}catch(e){a&&a.call(t,e,r)}}function exec(e,r,t){return _exec.apply(this,arguments)}function _exec(){_exec=_asyncToGenerator(regenerator.mark(function e(t,n,i){var a,o,u,c,s,l,f,_,p,h;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(i===true){n=i=n||user_env}else if(n===true){n=i=user_env}else{n=n||user_env}a=[];o=Array.isArray(t)?t:parse(t);u=true;c=false;r.prev=5;l=_asyncIterator(o);case 7:r.next=9;return l.next();case 9:f=r.sent;u=f.done;r.next=13;return f.value;case 13:_=r.sent;if(u){r.next=29;break}p=_;h=_evaluate(p,{env:n,dynamic_scope:i,error:function e(r,t){if(r&&r.message){if(r.message.match(/^Error:/)){var n=/^(Error:)\s*([^:]+:\s*)/;r.message=r.message.replace(n,"$1 $2")}if(t){if(!(r.__code__ instanceof Array)){r.__code__=[]}r.__code__.push(t.toString(true))}}throw r}});if(is_promise(h)){r.next=21;break}a.push(h);r.next=26;break;case 21:r.t0=a;r.next=24;return h;case 24:r.t1=r.sent;r.t0.push.call(r.t0,r.t1);case 26:u=true;r.next=7;break;case 29:r.next=35;break;case 31:r.prev=31;r.t2=r["catch"](5);c=true;s=r.t2;case 35:r.prev=35;r.prev=36;if(!(!u&&l["return"]!=null)){r.next=40;break}r.next=40;return l["return"]();case 40:r.prev=40;if(!c){r.next=43;break}throw s;case 43:return r.finish(40);case 44:return r.finish(35);case 45:return r.abrupt("return",a);case 46:case"end":return r.stop()}}},e,null,[[5,31,35,45],[36,,40,44]])}));return _exec.apply(this,arguments)}function balanced(e){var r={"[":"]","(":")"};var t;if(typeof e==="string"){t=tokenize(e)}else{t=e.map(function(e){return e&&e.token?e.token:e})}var n=Object.keys(r);var i=Object.values(r).concat(n);t=t.filter(function(e){return i.includes(e)});var a=new Stack;var o=_createForOfIteratorHelper(t),u;try{for(o.s();!(u=o.n()).done;){var c=u.value;if(n.includes(c)){a.push(c)}else if(!a.is_empty()){var s=a.top();var l=r[s];if(c===l){a.pop()}else{throw new Error("Syntax error: missing closing ".concat(l))}}else{throw new Error("Syntax error: not matched closing ".concat(c))}}}catch(e){o.e(e)}finally{o.f()}return a.is_empty()}function fworker(e){var r="("+e.toString()+")()";var t=window.URL||window.webkitURL;var n;try{n=new Blob([r],{type:"application/javascript"})}catch(e){var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;n=new i;n.append(r);n=n.getBlob()}return new root.Worker(t.createObjectURL(n))}function is_dev(){return lips.version.match(/^(\{\{VER\}\}|DEV)$/)}function bootstrap(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:"";if(e===""){if(is_dev()){e="https://cdn.jsdelivr.net/gh/jcubic/lips@devel/"}else{e="https://cdn.jsdelivr.net/npm/@jcubic/lips@".concat(lips.version,"/")}}else if(!e.match(/\/$/)){e+="/"}var r=global_env.get("load");return r.call(lips.env,"".concat(e,"dist/std.min.scm"),global_env)}function Worker(e){this.url=e;var o=this.worker=fworker(function(){var o;var u;self.addEventListener("message",function(e){var t=e.data;var r=t.id;if(t.type!=="RPC"||r===null){return}function n(e){self.postMessage({id:r,type:"RPC",result:e})}function i(e){self.postMessage({id:r,type:"RPC",error:e})}if(t.method==="eval"){if(!u){i("Worker RPC: LIPS not initilized, call init first");return}u.then(function(){var e=t.params[0];var r=t.params[1];o.exec(e,r).then(function(e){e=e.map(function(e){return e&&e.valueOf()});n(e)})["catch"](function(e){i(e)})})}else if(t.method==="init"){var a=t.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(r,t){var a=++n;return new Promise(function(n,i){o.addEventListener("message",function e(r){var t=r.data;if(t&&t.type==="RPC"&&t.id===a){if(t.error){i(t.error)}else{n(t.result)}o.removeEventListener("message",e)}});o.postMessage({type:"RPC",method:r,id:a,params:t})})}}();this.rpc("init",[e])["catch"](function(e){console.error(e)});this.exec=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;return this.rpc("eval",[e,r])}}var serialization_map={pair:function e(r){var t=_slicedToArray(r,2),n=t[0],i=t[1];return Pair(n,i)},number:function e(r){if(LString.isString(r)){return LNumber([r,10])}return LNumber(r)},regex:function e(r){var t=_slicedToArray(r,2),n=t[0],i=t[1];return new RegExp(n,i)},nil:function e(){return _nil},symbol:function e(r){if(LString.isString(r)){return LSymbol(r)}else if(Array.isArray(r)){return LSymbol(Symbol["for"](r[0]))}},string:LString,character:LCharacter};var available_class=Object.keys(serialization_map);var class_map={};for(var _i5=0,_Object$entries3=Object.entries(available_class);_i5<_Object$entries3.length;_i5++){var _Object$entries3$_i=_slicedToArray(_Object$entries3[_i5],2),i=_Object$entries3$_i[0],cls=_Object$entries3$_i[1];class_map[cls]=+i}function mangle_name(e){return class_map[e]}function resolve_name(e){return available_class[e]}function serialize(e){return JSON.stringify(e,function(e,r){var t=this[e];if(t){if(t instanceof RegExp){return{"@":mangle_name("regex"),"#":[t.source,t.flags]}}var n=mangle_name(t.constructor.__class__);if(!is_undef(n)){return{"@":n,"#":t.serialize()}}}return r})}function unserialize(e){return JSON.parse(e,function(e,r){if(r&&_typeof(r)==="object"){if(!is_undef(r["@"])){var t=resolve_name(r["@"]);if(serialization_map[t]){return serialization_map[t](r["#"])}}}return r})}function execError(e){console.error(e.message||e);if(e.code){console.error(e.code.map(function(e,r){return"[".concat(r+1,"]: ").concat(e)}))}}function init(){var o=["text/x-lips","text/x-scheme"];var u;function c(t){return new Promise(function(r){var e=t.getAttribute("src");if(e){return fetch(e).then(function(e){return e.text()}).then(exec).then(r)["catch"](function(e){execError(e);r()})}else{return exec(t.innerHTML).then(r)["catch"](function(e){execError(e);r()})}})}function e(){return new Promise(function(i){var a=Array.from(document.querySelectorAll("script"));return function e(){var r=a.shift();if(!r){i()}else{var t=r.getAttribute("type");if(o.includes(t)){var n=r.getAttribute("bootstrap");if(!u&&typeof n==="string"){bootstrap(n).then(function(){return c(r)}).then(e)}else{c(r).then(e)}}else if(t&&t.match(/lips|lisp/)){console.warn("Expecting "+o.join(" or ")+" found "+t)}return e()}}()})}if(!window.document){return Promise.resolve()}else if(currentScript){var r=currentScript;var t=r.getAttribute("bootstrap");if(typeof t==="string"){return bootstrap(t).then(function(){u=true;return e()})}}return e()}var currentScript=typeof window!=="undefined"&&window.document&&document.currentScript;if(typeof window!=="undefined"){contentLoaded(window,init)}var banner=function(){var e=LString("Fri, 04 Jun 2021 12:09:05 +0000").valueOf();var r=e==="{{"+"DATE}}"?new Date:new Date(e);var t=function e(r){return r.toString().padStart(2,"0")};var n=r.getFullYear();var i=[n,t(r.getMonth()+1),t(r.getDate())].join("-");var a="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter 1.0.0-beta.14 (".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 specic 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}();Ahead.__class__="ahead";Pair.__class__="pair";Nil.__class__="nil";Pattern.__class__="pattern";Formatter.__class__="formatter";Macro.__class__="macro";Syntax.__class__="syntax";Environment.__class__="environment";InputPort.__class__="input-port";OutputPort.__class__="output-port";OutputStringPort.__class__="output-string-port";InputStringPort.__class__="input-string-port";InputFilePort.__class__="input-file-port";OutputFilePort.__class__="output-file-port";LipsError.__class__="lips-error";[LNumber,LComplex,LRational,LFloat,LBigInteger].forEach(function(e){e.__class__="number"});LCharacter.__class__="character";LSymbol.__class__="symbol";LString.__class__="string";QuotedPromise.__class__="promise";var lips={version:"1.0.0-beta.14",banner:banner,date:"Fri, 04 Jun 2021 12:09:05 +0000",exec:exec,parse:compose(uniterate_async,parse),tokenize:tokenize,evaluate:_evaluate,serialize:serialize,unserialize:unserialize,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,InputFilePort:InputFilePort,OutputFilePort:OutputFilePort,InputStringPort:InputStringPort,OutputStringPort:OutputStringPort,InputByteVectorPort:InputByteVectorPort,OutputByteVectorPort:OutputByteVectorPort,InputBinaryFilePort:InputBinaryFilePort,OutputBinaryFilePort:OutputBinaryFilePort,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,rationalize:rationalize};global_env.set("lips",lips);return lips})})(); \ No newline at end of file diff --git a/dist/std.min.scm b/dist/std.min.scm index 8f8a0bd4..9971dd9b 100644 --- a/dist/std.min.scm +++ b/dist/std.min.scm @@ -236,7 +236,7 @@ (define (angle x) "(angle x)\u000A\u000AReturns angle of the complex number in polar coordinate system." (if (not (%number-type "complex" x)) (error "angle: number need to be complex") (Math.atan2 x.__im__ x.__re__))) (define (magnitude x) "(magnitude x)\u000A\u000AReturns magnitude of the complex number in polar coordinate system." (if (not (%number-type "complex" x)) (error "magnitude: number need to be complex") (sqrt (+ (* x.__im__ x.__im__) (* x.__re__ x.__re__))))) (define random (let ((a 69069) (c 1) (m (expt 2 32)) (seed 19380110)) (lambda new-seed "(random)\u000A(random seed)\u000A\u000AFunction generate new random real number using Knuth algorithm." (if (pair? new-seed) (set! seed (car new-seed)) (set! seed (modulo (+ (* seed a) c) m))) (exact->inexact (/ seed m))))) -(define (eof-object? obj) "(eof-object? arg)\u000A\u000AFunction check if value is eof object, returned from input string\u000Aport when there are no more data to read." (eq? obj #)) +(define (eof-object? obj) "(eof-object? arg)\u000A\u000AFunction check if value is eof object, returned from input string\u000Aport when there are no more data to read." (eq? obj eof)) (define (output-port? obj) "(output-port? arg)\u000A\u000AFunction return true if argument is output port." (instanceof lips.OutputPort obj)) (define (input-port? obj) "(input-port? arg)\u000A\u000AFunction return true if argument is input port." (instanceof lips.InputPort obj)) (define (char-ready? . rest) "(char-ready?)\u000A(char-ready? port)\u000A\u000AFunction check it characters is ready in input port. This is usefull mostly\u000Afor interactive ports that return false if it would wait for user input.\u000AIt return false if port is closed." (let ((port (if (null? rest) (current-input-port) (car rest)))) (typecheck "char-ready?" port "input-port") (port.char_ready))) diff --git a/src/lips.js b/src/lips.js index 83374250..0902523a 100644 --- a/src/lips.js +++ b/src/lips.js @@ -6780,7 +6780,6 @@ '#t': true, '#f': false, nil, - eof, 'null': null, 'NaN': nan, '+nan.0': nan, @@ -6788,6 +6787,7 @@ }; // ------------------------------------------------------------------------- var global_env = new Environment({ + eof, undefined, // undefined as parser constant breaks most of the unit tests // --------------------------------------------------------------------- 'peek-char': doc('peek-char', function(port = null) { @@ -9859,7 +9859,7 @@ url += '/'; } var load = global_env.get('load'); - return load.call(lips.env, `${url}dist/std.scm`, global_env); + return load.call(lips.env, `${url}dist/std.min.scm`, global_env); } // ------------------------------------------------------------------------- function Worker(url) {