diff --git a/Makefile b/Makefile index 91974171..1c25c64a 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .PHONY: publish test coveralls lint zero -VERSION=1.0.0-beta.10 -VERSION_DASH=`echo -n "1.0.0-beta.10" | sed "s/-/%E2%80%93/"` +VERSION=1.0.0-beta.11 +VERSION_DASH=`echo -n "1.0.0-beta.11" | sed "s/-/%E2%80%93/"` BRANCH=`git branch | grep '^*' | sed 's/* //'` DATE=`date -uR` YEAR=`date +%Y` diff --git a/README.md b/README.md index 0846f595..19afdd4f 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ -![LIPS - Scheme Based Powerful Lisp Language](https://github.com/jcubic/lips/blob/devel/assets/lips.svg?raw=true) +![LIPS - Scheme Based Powerful Lisp Language](https://github.com/jcubic/lips/blob/master/assets/lips.svg?raw=true) -[![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.10-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) +[![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.11-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=devel&592e2c94549a753d0ccd154aaaa27dc1ca901d17)](https://travis-ci.org/jcubic/lips) -[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&9c6e0aba32c2372d70056c5f57c2311a)](https://coveralls.io/github/jcubic/lips?branch=devel) +[![travis](https://travis-ci.org/jcubic/lips.svg?branch=master&e90dcac3b5fcfcd4c1fade75f9cf3aded52bacd5)](https://travis-ci.org/jcubic/lips) +[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=master&83772d306416614a34e010475a6264c0)](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) [![GitHub stars](https://img.shields.io/github/stars/jcubic/lips.svg?style=social&label=Star&maxAge=2592000)](https://GitHub.com/jcubic/lips/stargazers/) - Tweet + Tweet ![NPM Download Count](https://img.shields.io/npm/dm/@jcubic/lips) ![JSDelivr Download count](https://img.shields.io/jsdelivr/npm/hm/@jcubic/lips) @@ -196,7 +196,7 @@ npm install -g @jcubic/lips you can run the interpreter from the terminal: -![LIPS: Scheme interactive terminal](https://github.com/jcubic/lips/blob/devel/assets/screencast.gif?raw=true) +![LIPS: Scheme interactive terminal](https://github.com/jcubic/lips/blob/master/assets/screencast.gif?raw=true) You can also run code in a string with: diff --git a/dist/lips.js b/dist/lips.js index 77f75a89..6e909ba0 100644 --- a/dist/lips.js +++ b/dist/lips.js @@ -4,7 +4,7 @@ * | | \ \ | | | || . \/ __> | | * | | > \ | |_ | || _/\__ \ | | * | | / ^ \ |___||_||_| <___/ | | - * \_\ /_/ \_\ /_/ v. DEV + * \_\ /_/ \_\ /_/ v. 1.0.0-beta.11 * * LIPS is Pretty Simple - Scheme based Powerful LISP in JavaScript * @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Mon, 18 Jan 2021 14:58:43 +0000 + * build: Sun, 31 Jan 2021 11:47:57 +0000 */ (function () { 'use strict'; @@ -13034,10 +13034,10 @@ var banner = function () { // Rollup tree-shaking is removing the variable if it's normal string because - // obviously 'Mon, 18 Jan 2021 14:58:43 +0000' == '{{' + 'DATE}}'; can be removed + // obviously 'Sun, 31 Jan 2021 11:47:57 +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('Mon, 18 Jan 2021 14:58:43 +0000').valueOf(); + var date = LString('Sun, 31 Jan 2021 11:47:57 +0000').valueOf(); var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date); @@ -13049,7 +13049,7 @@ var _build = [_year, _format(_date.getMonth() + 1), _format(_date.getDate())].join('-'); - var banner = "\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter DEV (".concat(_build, ") \nCopyright (c) 2018-").concat(_year, " Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables.\nYou can also use (help name) to display help for specic function or macro and\n(apropos name) to display list of matched names in environment.\n").replace(/^.*\n/, ''); + var banner = "\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter 1.0.0-beta.11 (".concat(_build, ") \nCopyright (c) 2018-").concat(_year, " Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables.\nYou can also use (help name) to display help for specic function or macro and\n(apropos name) to display list of matched names in environment.\n").replace(/^.*\n/, ''); return banner; }(); // ------------------------------------------------------------------------- // to be used with string function when code is minified @@ -13072,9 +13072,9 @@ LString.__class__ = 'string'; // ------------------------------------------------------------------------- var lips = { - version: 'DEV', + version: '1.0.0-beta.11', banner: banner, - date: 'Mon, 18 Jan 2021 14:58:43 +0000', + date: 'Sun, 31 Jan 2021 11:47:57 +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 213c2e56..c776a015 100644 --- a/dist/lips.min.js +++ b/dist/lips.min.js @@ -4,7 +4,7 @@ * | | \ \ | | | || . \/ __> | | * | | > \ | |_ | || _/\__ \ | | * | | / ^ \ |___||_||_| <___/ | | - * \_\ /_/ \_\ /_/ v. DEV + * \_\ /_/ \_\ /_/ v. 1.0.0-beta.11 * * LIPS is Pretty Simple - Scheme based Powerful LISP in JavaScript * @@ -31,6 +31,6 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Mon, 18 Jan 2021 14:58:43 +0000 + * build: Sun, 31 Jan 2021 11:47:57 +0000 */ -(function(){"use strict";function _readOnlyError(e){throw new Error('"'+e+'" is read-only')}var readOnlyError=_readOnlyError;function createCommonjsModule(e,r){return r={exports:{}},e(r,r.exports),r.exports}var setPrototypeOf=createCommonjsModule(function(n){function t(e,r){n.exports=t=Object.setPrototypeOf||function e(r,n){r.__proto__=n;return r};return t(e,r)}n.exports=t});function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Date.prototype.toString.call(Reflect.construct(Date,[],function(){}));return true}catch(e){return false}}var isNativeReflectConstruct=_isNativeReflectConstruct;var construct=createCommonjsModule(function(t){function i(e,r,n){if(isNativeReflectConstruct()){t.exports=i=Reflect.construct}else{t.exports=i=function e(r,n,t){var i=[null];i.push.apply(i,n);var a=Function.bind.apply(r,i);var u=new a;if(t)setPrototypeOf(u,t.prototype);return u}}return i.apply(null,arguments)}t.exports=i});function _arrayWithHoles(e){if(Array.isArray(e))return e}var arrayWithHoles=_arrayWithHoles;function _iterableToArray(e){if(typeof Symbol!=="undefined"&&Symbol.iterator in Object(e))return Array.from(e)}var iterableToArray=_iterableToArray;function _arrayLikeToArray(e,r){if(r==null||r>e.length)r=e.length;for(var n=0,t=new Array(r);n=0;--r){var i=this.tryEntries[r];var a=i.completion;if(i.tryLoc==="root"){return e("end")}if(i.tryLoc<=this.prev){var u=l.call(i,"catchLoc");var o=l.call(i,"finallyLoc");if(u&&o){if(this.prev=0;--n){var t=this.tryEntries[n];if(t.tryLoc<=this.prev&&l.call(t,"finallyLoc")&&this.prev=0;--r){var n=this.tryEntries[r];if(n.finallyLoc===e){this.complete(n.completion,n.afterLoc);S(n);return m}}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc===e){var t=n.completion;if(t.type==="throw"){var i=t.arg;S(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){this.delegate={iterator:k(e),resultName:r,nextLoc:n};if(this.method==="next"){this.arg=c}return m}};return u}(e.exports);try{regeneratorRuntime=r}catch(e){Function("r","regeneratorRuntime = r")(r)}});var regenerator=runtime_1;function asyncGeneratorStep(e,r,n,t,i,a,u){try{var o=e[a](u);var c=o.value}catch(e){n(e);return}if(o.done){r(c)}else{Promise.resolve(c).then(t,i)}}function _asyncToGenerator(o){return function(){var e=this,u=arguments;return new Promise(function(r,n){var t=o.apply(e,u);function i(e){asyncGeneratorStep(t,r,n,i,a,"next",e)}function a(e){asyncGeneratorStep(t,r,n,i,a,"throw",e)}i(undefined)})}}var asyncToGenerator=_asyncToGenerator;function _classCallCheck(e,r){if(!(e instanceof r)){throw new TypeError("Cannot call a class as a function")}}var classCallCheck=_classCallCheck;function _defineProperties(e,r){for(var n=0;n=0)continue;n[i]=e[i]}return n}var objectWithoutPropertiesLoose=_objectWithoutPropertiesLoose;function _objectWithoutProperties(e,r){if(e==null)return{};var n=objectWithoutPropertiesLoose(e,r);var t,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,t))continue;n[t]=e[t]}}return n}var objectWithoutProperties=_objectWithoutProperties;function _iterableToArrayLimit(e,r){if(typeof Symbol==="undefined"||!(Symbol.iterator in Object(e)))return;var n=[];var t=true;var i=false;var a=undefined;try{for(var u=e[Symbol.iterator](),o;!(t=(o=u.next()).done);t=true){n.push(o.value);if(r&&n.length===r)break}}catch(e){i=true;a=e}finally{try{if(!t&&u["return"]!=null)u["return"]()}finally{if(i)throw a}}return n}var iterableToArrayLimit=_iterableToArrayLimit;function _slicedToArray(e,r){return arrayWithHoles(e)||iterableToArrayLimit(e,r)||unsupportedIterableToArray(e,r)||nonIterableRest()}var slicedToArray=_slicedToArray;var _typeof_1=createCommonjsModule(function(r){function n(e){"@babel/helpers - typeof";if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){r.exports=n=function e(r){return typeof r}}else{r.exports=n=function e(r){return r&&typeof Symbol==="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r}}return n(e)}r.exports=n});function _asyncIterator(e){var r;if(typeof Symbol!=="undefined"){if(Symbol.asyncIterator){r=e[Symbol.asyncIterator];if(r!=null)return r.call(e)}if(Symbol.iterator){r=e[Symbol.iterator];if(r!=null)return r.call(e)}}throw new TypeError("Object is not async iterable")}var asyncIterator=_asyncIterator;function _AwaitValue(e){this.wrapped=e}var AwaitValue=_AwaitValue;function _awaitAsyncGenerator(e){return new AwaitValue(e)}var awaitAsyncGenerator=_awaitAsyncGenerator;function AsyncGenerator(a){var u,o;function e(t,i){return new Promise(function(e,r){var n={key:t,arg:i,resolve:e,reject:r,next:null};if(o){o=o.next=n}else{u=o=n;c(t,i)}})}function c(r,e){try{var n=a[r](e);var t=n.value;var i=t instanceof AwaitValue;Promise.resolve(i?t.wrapped:t).then(function(e){if(i){c(r==="return"?"return":"next",e);return}s(n.done?"return":"normal",e)},function(e){c("throw",e)})}catch(e){s("throw",e)}}function s(e,r){switch(e){case"return":u.resolve({value:r,done:true});break;case"throw":u.reject(r);break;default:u.resolve({value:r,done:false});break}u=u.next;if(u){c(u.key,u.arg)}else{o=null}}this._invoke=e;if(typeof a["return"]!=="function"){this["return"]=undefined}}if(typeof Symbol==="function"&&Symbol.asyncIterator){AsyncGenerator.prototype[Symbol.asyncIterator]=function(){return this}}AsyncGenerator.prototype.next=function(e){return this._invoke("next",e)};AsyncGenerator.prototype["throw"]=function(e){return this._invoke("throw",e)};AsyncGenerator.prototype["return"]=function(e){return this._invoke("return",e)};var AsyncGenerator_1=AsyncGenerator;function _wrapAsyncGenerator(e){return function(){return new AsyncGenerator_1(e.apply(this,arguments))}}var wrapAsyncGenerator=_wrapAsyncGenerator;function _createForOfIteratorHelper(r,e){var n;if(typeof Symbol==="undefined"||r[Symbol.iterator]==null){if(Array.isArray(r)||(n=_unsupportedIterableToArray$1(r))||e&&r&&typeof r.length==="number"){if(n)r=n;var t=0;var i=function e(){};return{s:i,n:function e(){if(t>=r.length)return{done:true};return{done:false,value:r[t++]}},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,u=false,o;return{s:function e(){n=r[Symbol.iterator]()},n:function e(){var r=n.next();a=r.done;return r},e:function e(r){u=true;o=r},f:function e(){try{if(!a&&n["return"]!=null)n["return"]()}finally{if(u)throw o}}}}function _unsupportedIterableToArray$1(e,r){if(!e)return;if(typeof e==="string")return _arrayLikeToArray$1(e,r);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor)n=e.constructor.name;if(n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray$1(e,r)}function _arrayLikeToArray$1(e,r){if(r==null||r>e.length)r=e.length;for(var n=0,t=new Array(r);n1&&arguments[1]!==undefined$1?arguments[1]:null;var t=arguments[1]===true;function r(e){if(!is_debug()){return}var r=global_env.get("repr")(e);if(n===null||n instanceof RegExp&&n.test(r)){console.log(global_env.get("type")(e)+": "+r)}if(t){console.log(e)}}if(is_promise(e)){e.then(r)}else{r(e)}return e}function is_debug(){return user_env.get("DEBUG",{throwError:false})}if(!root.fetch){root.fetch=function(i,a){a=a||{};return new Promise(function(e,r){var n=new XMLHttpRequest;n.open(a.method||"get",i,true);for(var t in a.headers){n.setRequestHeader(t,a.headers[t])}n.withCredentials=a.credentials=="include";n.onload=function(){e(o())};n.onerror=r;n.send(a.body||null);function o(){var t=[],i=[],a={},u;n.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,r,n){t.push(r=r.toLowerCase());i.push([r,n]);u=a[r];a[r]=u?"".concat(u,",").concat(n):n});return{ok:(n.status/100|0)==2,status:n.status,statusText:n.statusText,url:n.responseURL,clone:o,text:function e(){return Promise.resolve(n.responseText)},json:function e(){return Promise.resolve(n.responseText).then(JSON.parse)},blob:function e(){return Promise.resolve(new Blob([n.response]))},headers:{keys:function e(){return t},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,"+|").concat(r,"+))?(?:[+-]i|[+-]?(?:").concat(r,"+/").concat(r,"+|").concat(r,"+)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]+|".concat(float_stre,"|[+-]?[0-9]+))?(?:").concat(float_stre,"|[+-](?:[0-9]+/[0-9]+|[0-9]+))i");var float_re=new RegExp("^(#[ie])?".concat(float_stre,"$"),"i");function make_complex_match_re(e,r){var n=e==="x"?"(?!\\+|".concat(r,")"):"(?!\\.|".concat(r,")");var t="";if(e===""){t="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+(?![0-9]))(?:[eE][-+]?[0-9]+)?))"}return new RegExp("^((?:(?:".concat(t,"|[+-]?").concat(r,"+/").concat(r,"+(?!").concat(r,")|[+-]?").concat(r,"+)").concat(n,")?)(").concat(t,"|[+-]?").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),n=r[0],t=r[1],i=r[2];a[n]=make_complex_match_re(t,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 n=0;var t=e.length;while(n=55296&&i<=56319&&n1&&arguments[1]!==undefined$1?arguments[1]:10;var n=num_pre_parse(e);var t=n.number.split("/");var i=LRational({num:LNumber([t[0],n.radix||r]),denom:LNumber([t[1],n.radix||r])});if(n.inexact){return i.valueOf()}else{return i}}function parse_integer(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:10;var n=num_pre_parse(e);if(n.inexact){return LFloat(parseInt(n.number,n.radix||r))}return LNumber([n.number,n.radix||r])}function parse_character(e){var r=e.match(/#\\x([0-9a-f]+)$/i);var n;if(r){var t=parseInt(r[1],16);n=String.fromCodePoint(t)}else{r=e.match(/#\\(.+)$/);if(r){n=r[1]}}if(n){return LCharacter(n)}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 n=e.split("/");r=LRational({num:LNumber([n[0],i]),denom:LNumber([n[1],i])})}else if(e.match(float_re)){var t=parse_float(e);if(a.exact){return t.toRational()}return t}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 n;var t=a.number.match(complex_bare_match_re);if(i!==10&&t){n=t}else{n=a.number.match(complex_list_re[i])}var u,o;o=r(n[2]);if(n[1]){u=r(n[1])}else if(o instanceof LFloat){u=LFloat(0)}else{u=LNumber(0)}return LComplex({im:o,re:u})}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 n=parseInt(r[4],10);var t;var i=r[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var a=r[3]&&r[3].length;if(i0){return LNumber(a).mul(o)}}}n=LFloat(n);if(r.exact){return n.toRational()}return n}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 n={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 n[r]||r})}return new LSymbol(e)}function parse_argument(e){var r=e.match(re_re);if(r){return new RegExp(r[1],r[2])}else if(e.match(/^"[\s\S]*"$/)){return parse_string(e)}else if(e.match(char_re)){return parse_character(e)}else if(e.match(rational_re)){return parse_rational(e)}else if(e.match(complex_re)){return parse_complex(e)}else if(e.match(int_re)){return parse_integer(e)}else if(e.match(float_re)){return parse_float(e)}else if(e==="nil"){return nil}else if(["true","#t","#true"].includes(e)){return true}else if(["false","#f","#false"].includes(e)){return false}else if(e.match(/^#[iexobd]/)){throw new Error("Invalid numeric constant")}else{var n=e.match(/#\\(.+)/);if(n&&ucs2decode(n[1]).length===1){return parse_character(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 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 n=[];while(true){var t=r.peek(true);if(t===eof){break}n.push(t);r.skip()}return n}function multiline_formatter(e){var r=e.token,n=objectWithoutProperties(e,["token"]);if(r.match(/^"[\s\S]*"$/)&&r.match(/\n/)){var t=new RegExp("^ {1,"+(e.col+1)+"}","mg");r=r.replace(t,"")}return _objectSpread({token:r},n)}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(t){return function(){for(var e=arguments.length,r=new Array(e),n=0;n1&&arguments[1]!==undefined$1?arguments[1]:false;if(e instanceof LString){e=e.toString()}if(r){return tokens(e)}else{var n=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(n)}}function strip_s_comments(e){var r=0;var n=null;var t=[];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){e["catch"](function(){});this.__promise__=e}QuotedPromise.prototype.then=function(e){return new QuotedPromise(this.__promise__.then(e))};QuotedPromise.prototype["catch"]=function(e){return new QuotedPromise(this.__promise__["catch"](e))};QuotedPromise.prototype.valueOf=function(){return this.__promise__};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 n=this;var t=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:null;if(Array.isArray(r)){r.forEach(function(e){return n.off(e,t)})}else if(t===null){delete this._events[r]}else{this._events=this._events.filter(function(e){return e!==t})}},on:function e(r,n){var t=this;if(Array.isArray(r)){r.forEach(function(e){return t.on(e,n)})}else if(!this._events[r]){this._events[r]=[n]}else{this._events[r].push(n)}},trigger:function e(r){for(var n=arguments.length,t=new Array(n>1?n-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),n=r[0],t=r[1],i=r[2];specials.append(n,t,i)});var Lexer=function(){function _(e){var r=this;var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},t=n.whitespace,i=t===void 0?false:t;classCallCheck(this,_);Object.defineProperty(this,"__input__",{value:e.replace(/\r/g,""),enumerable:true});var a={};["_i","_whitespace","_col","_newline","_line","_state","_next","_token","_prev_char"].forEach(function(n){Object.defineProperty(r,n,{configurable:false,enumerable:false,get:function e(){return a[n]},set:function e(r){a[n]=r}})});this._whitespace=i;this._i=this._line=this._col=this._newline=0;this._state=this._next=this._token=null;this._prev_char=""}createClass(_,[{key:"get",value:function e(r){return this.__internal[r]}},{key:"set",value:function e(r,n){this.__internal[r]=n}},{key:"token",value:function e(){var r=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:false;if(r){var n=this._line;if(this._whitespace&&this._token==="\n"){--n}return{token:this._token,col:this._col,offset:this._i,line:n}}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 n=this.next_token();if(n){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 n=this._i;n=n){return eof}if(r+this._i>=n){return this.read_rest()}var t=this._i+r;var i=this.__input__.substring(this._i,t);var a=i.match(/\n/g);if(a){this._line+=a.length}this._i=t;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]:{},t=n.prev_char,i=n["char"],a=n.next_char;var u=slicedToArray(r,4),o=u[0],c=u[1],s=u[2],l=u[3];if(r.length!==5){throw new Error("Lexer: Invald rule of length ".concat(r.length))}if(!i.match(o)){return false}if(!match_or_null(c,t)){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 n=this._i,t=this.__input__.length;n2&&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,t,i,null,null]]}var a=[];for(var u=0,o=r.length;u1&&arguments[1]!==undefined$1?arguments[1]:{},n=r.env,t=r.meta,i=t===void 0?false:t,a=r.formatter,u=a===void 0?multiline_formatter:a;classCallCheck(this,o);if(e instanceof LString){e=e.toString()}this._formatter=u;this._meta=i;this.__lexer__=new Lexer(e);this.__env__=n}createClass(o,[{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 n;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:n=this.__lexer__.peek(true);if(!(n===eof)){r.next=4;break}return r.abrupt("return",eof);case 4:if(!this.is_comment(n.token)){r.next=7;break}this.skip();return r.abrupt("continue",0);case 7:if(!(n.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:n=this._formatter(n);if(!this._meta){r.next=20;break}return r.abrupt("return",n);case 20:return r.abrupt("return",n.token);case 21:case"end":return r.stop()}}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"skip",value:function e(){this.__lexer__.skip()}},{key:"special",value:function e(r){return specials.names().includes(r)}},{key:"builtin",value:function e(r){return specials.builtin.includes(r)}},{key:"read",value:function(){var e=asyncToGenerator(regenerator.mark(function e(){var n;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:r.next=2;return this.peek();case 2:n=r.sent;this.skip();return r.abrupt("return",n);case 5:case"end":return r.stop()}}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{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 n,t,i,a;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:n=nil,t=n;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==="."&&n!==nil)){r.next=17;break}this.skip();r.next=14;return this.read_object();case 14:t.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(n===nil){n=a}else{t.cdr=a}t=a;case 25:r.next=1;break;case 27:return r.abrupt("return",n);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 n;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:r.next=2;return this.read();case 2:n=r.sent;if(!(n===eof)){r.next=5;break}throw new Error("Parser: Expected token eof found");case 5:return r.abrupt("return",parse_argument(n));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:"_eval",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 n,t,i,a,u,o,c;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:r.next=2;return this.peek();case 2:n=r.sent;if(!(n===eof)){r.next=5;break}return r.abrupt("return",n);case 5:if(!this.special(n)){r.next=35;break}t=specials.get(n);i=this.builtin(n);this.skip();r.next=11;return this.read_object();case 11:u=r.sent;if(i){r.next=22;break}o=this.__env__.get(t.symbol);if(!(typeof o==="function")){r.next=22;break}if(!is_literal(n)){r.next=19;break}return r.abrupt("return",o.call(this.__env__,u));case 19:if(!(u instanceof Pair)){r.next=21;break}return r.abrupt("return",o.apply(this.__env__,u.toArray(false)));case 21:throw new Error("Parser: Invalid parser extension "+"invocation ".concat(t.symbol));case 22:if(is_literal(n)){a=new Pair(t.symbol,new Pair(u,nil))}else{a=new Pair(t.symbol,u)}if(!i){r.next=25;break}return r.abrupt("return",a);case 25:if(!(o instanceof Macro)){r.next=34;break}r.next=28;return this._eval(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("Parser: invlid parser extension: ".concat(t.symbol));case 35:if(!this.is_open(n)){r.next=42;break}this.skip();r.next=39;return this.read_list();case 39:return r.abrupt("return",r.sent);case 42:r.next=44;return this.read_value();case 44:return r.abrupt("return",r.sent);case 45:case"end":return r.stop()}}},e,this)}));function r(){return e.apply(this,arguments)}return r}()}]);return o}();function parse(e,r){return _parse.apply(this,arguments)}function _parse(){_parse=wrapAsyncGenerator(regenerator.mark(function e(n,t){var i,a;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!t){if(global_env){t=global_env.get("**interaction-environment**",{throwError:false})}else{t=user_env}}i=new Parser(n,{env:t});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(r){var e=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:function(e){return e};var n=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:null;if(r instanceof Array){var t=r.filter(is_promise);if(t.length){return unpromise(Promise.all(r),function(e){if(Object.isFrozen(r)){Object.freeze(e)}return e},n)}return e(r)}if(is_plain_object(r)){var i=Object.keys(r);var a=i.map(function(e){return r[e]});var u=a.filter(is_promise);if(u.length){return unpromise(Promise.all(a),function(e){var t={};e.forEach(function(e,r){var n=i[r];t[n]=e});if(Object.isFrozen(r)){Object.freeze(t)}return t},n)}}if(is_promise(r)){var o=r.then(e);if(n===null){return o}else{return o["catch"](n)}}return e(r)}function uniterate_async(e){return _uniterate_async.apply(this,arguments)}function _uniterate_async(){_uniterate_async=asyncToGenerator(regenerator.mark(function e(n){var t,i,a,u,o,c,s,l;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:t=[];i=true;a=false;r.prev=3;o=asyncIterator(n);case 5:r.next=7;return o.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;t.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;u=r.t0;case 24:r.prev=24;r.prev=25;if(!(!i&&o["return"]!=null)){r.next=29;break}r.next=29;return o["return"]();case 29:r.prev=29;if(!a){r.next=32;break}throw u;case 32:return r.finish(29);case 33:return r.finish(24);case 34:return r.abrupt("return",t);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}}function doc(e,r,n,t){if(typeof e!=="string"){r=arguments[0];n=arguments[1];t=arguments[2];e=null}if(n){if(t){r.__doc__=n}else{r.__doc__=trim_lines(n)}}if(e){r.__name__=e}else if(r.name&&!r[__lambda__]){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 n=e.length;if(r<=0){throw Error("previousSexp: Invalid argument sexp = ".concat(r))}e:while(r--&&n>=0){var t=1;while(t>0){var i=e[--n];if(!i){break e}if(i==="("||i.token==="("){t--}else if(i===")"||i.token===")"){t++}}n--}return e.slice(n+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 n=(e[r+1]||{}).token;if(n){return n.length}}}return 0}function nested_pattern(e){return e instanceof Array||e instanceof Pattern}function match(e,r){return f(e,r)===r.length;function f(n,t){function e(){if(a<=0&&o<=0){return false}var e=n[a-1];if(!nested_pattern(e)){e=[e]}var r=n[a+1];if(r&&!nested_pattern(r)){r=[r]}return match(e,[t[o-1]])&&(!r||match(r,[t[o]]))}function r(){return n[a]===Symbol["for"]("symbol")&&!is_symbol_string(t[o])}function i(){var e=n[a+1];var r=t[o+1];if(e!==undefined$1&&r!==undefined$1){return f([e],[r])}}var a=0;var u={};for(var o=0;o0){continue}}else if(r()){return-1}}else if(n[a]instanceof Array){var l=f(n[a],t.slice(o));if(l===-1||l+o>t.length){return-1}o+=l-1;a++;continue}else{return-1}a++}if(n.length!==a){return-1}return t.length}}function Formatter(e){this.__code__=e.replace(/\r/g,"")}Formatter.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?(?:define(?:-values|-syntax|-macro)?|lambda|let*|let-env|try|catch|when|unless|while|syntax-rules|(let|letrec)(-syntax))$/],shift:{1:["&","#"]}}};Formatter.match=match;Formatter.prototype._options=function e(r){var n=Formatter.defaults;if(typeof r==="undefined"){return Object.assign({},n)}var t=r&&r.exceptions||{};var i=t.specials||[];var a=t.shift||{1:[]};return _objectSpread(_objectSpread(_objectSpread({},n),r),{},{exceptions:{specials:[].concat(toConsumableArray(n.exceptions.specials),toConsumableArray(i)),shift:_objectSpread(_objectSpread({},a),{},{1:[].concat(toConsumableArray(n.exceptions.shift[1]),toConsumableArray(a[1]))})}})};Formatter.prototype.indent=function e(r){var n=tokenize(this.__code__,true);return this._indent(n,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 n=_createForOfIteratorHelper(r),t;try{for(n.s();!(t=n.n()).done;){var i=t.value;if(a.match(i)){return true}}}catch(e){n.e(e)}finally{n.f()}}return false}if(r(e.exceptions.specials)){return e.indent}var n=e.exceptions.shift;for(var t=0,i=Object.entries(n);t0){t.offset=0}if(a.toString()===r.toString()&&balanced(a)){return t.offset+a[0].col}else if(a.length===1){return t.offset+a[0].col+1}else{var c=-1;if(u){var s=Formatter.exception_shift(u.token,t);if(s!==-1){c=s}}if(c===-1){c=Formatter.exception_shift(a[1].token,t)}if(c!==-1){return t.offset+a[0].col+c}else if(a[0].line3&&a[1].line===a[3].line){if(a[1].token==="("||a[1].token==="["){return t.offset+a[1].col}return t.offset+a[3].col}else if(a[0].line===a[1].line){return t.offset+t.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(e,r){this.pattern=e;this.flag=r}Pattern.prototype.toString=function(){return"#")};Formatter.Pattern=Pattern;Formatter.Ahead=Ahead;var p_o=/[[(]/;var p_e=/[\])]/;var not_p=/[^()[\]]/;var not_close=new Ahead(/[^)\]]/);var open=new Ahead(/[([]/);var glob=Symbol["for"]("*");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","syntax-rules");var non_def=/^(?!.*\b(?:[()[\]]|define|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),n=0;n0&&arguments[0]!==undefined$1?arguments[0]:true;var r=[];if(this.car instanceof Pair){if(e){r.push(this.car.toArray())}else{r.push(this.car)}}else{r.push(this.car.valueOf())}if(this.cdr instanceof Pair){r=r.concat(this.cdr.toArray())}return r};Pair.fromArray=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:true;var n=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:false;if(e instanceof Pair||n&&e instanceof Array&&e[__data__]){return e}if(r===false){var t=nil;for(var i=e.length;i--;){t=new Pair(e[i],t)}return t}if(e.length&&!(e instanceof Array)){e=toConsumableArray(e)}var a=nil;var u=e.length;while(u--){var o=e[u];if(o instanceof Array){o=Pair.fromArray(o,r,n)}else if(typeof o==="string"){o=LString(o)}else if(typeof o==="number"&&!Number.isNaN(o)){o=LNumber(o)}a=new Pair(o,a)}return a};Pair.prototype.toObject=function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:false;var r=this;var n={};while(true){if(r instanceof Pair&&r.car instanceof Pair){var t=r.car;var i=t.car;if(i instanceof LSymbol){i=i.__name__}if(i instanceof LString){i=i.valueOf()}var a=t.cdr;if(a instanceof Pair){a=a.toObject(e)}if(is_native(a)){if(!e){a=a.valueOf()}}n[i]=a;r=r.cdr}else{break}}return n};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 n=nil;while(true){if(r!==nil){n=e(n,r.car);r=r.cdr}else{break}}return n};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 n=e.cdr;e.cdr=r;r=e;e=n}return r};Pair.prototype.transform=function(t){function i(e){if(e instanceof Pair){if(e.replace){delete e.replace;return e}var r=t(e.car);if(r instanceof Pair){r=i(r)}var n=t(e.cdr);if(n instanceof Pair){n=i(n)}return new Pair(r,n)}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_1(e)==="object"&&e.constructor===Object}var props=Object.getOwnPropertyNames(Array.prototype);var array_methods=[];props.forEach(function(e){array_methods.push(Array[e],Array.prototype[e])});function is_array_method(e){e=unbind(e);return array_methods.includes(e)}function is_lips_function(e){return is_function(e)&&(e[__lambda__]||e.__doc__)}function user_repr(n){var e=n.constructor||Object;var t=is_plain_object(n);var i=is_function(n[Symbol.asyncIterator])||is_function(n[Symbol.iterator]);var a;if(repr.has(e)){a=repr.get(e)}else{repr.forEach(function(e,r){r=unbind(r);if(n.constructor===r&&(r===Object&&t&&!i||r!==Object)){a=e}})}return a}var str_mapping=new Map;[[Number.NEGATIVE_INFINITY,"-inf.0"],[Number.POSITIVE_INFINITY,"+inf.0"],[true,"#t"],[false,"#f"],[null,"null"],[undefined$1,"#"]].forEach(function(e){var r=slicedToArray(e,2),n=r[0],t=r[1];str_mapping.set(n,t)});function symbolize(n){if(n&&_typeof_1(n)==="object"){var t={};var e=Object.getOwnPropertySymbols(n);e.forEach(function(e){var r=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");t[r]=toString(n[e])});var r=Object.getOwnPropertyNames(n);r.forEach(function(e){var r=n[e];if(r&&_typeof_1(r)==="object"&&r.constructor===Object){t[e]=symbolize(r)}else{t[e]=toString(r)}});return t}return n}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)&&r[__lambda__]){if(e[__class__]&&r.hasOwnProperty("__name__")){var n=r.__name__;if(LString.isString(n)){n=n.toString();return"#")}return"#"}}if(e.hasOwnProperty("__name__")){var t=e.__name__;if(_typeof_1(t)==="symbol"){t=symbol_to_string(t)}if(typeof t==="string"){return"#")}}if(has_own_function(e,"toString")){return e.toString()}else if(e.name&&!e[__lambda__]){return"#")}else{return"#"}}function toString(e,r,n){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(str_mapping.has(e)){return str_mapping.get(e)}if(e instanceof Error){return e.message}if(e instanceof Pair){var t;if(!n){e.markCycles()}for(var i=arguments.length,a=new Array(i>3?i-3:0),u=3;u"}if(e===null){return"null"}if(_typeof_1(e)==="object"){if(is_function(e.toString)&&e.toString[__lambda__]){return e.toString().valueOf()}var f=e.constructor;if(!f){f=Object}var p;if(typeof f.__class__==="string"){p=f.__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")}}p=f.name}if(type(e)==="instance"&&!is_native_function(f)){p="instance"}if(is_iterator(e,Symbol.iterator)){if(p){return"#")}return"#"}if(is_iterator(e,Symbol.asyncIterator)){if(p){return"#")}return"#"}if(p!==""){return"#<"+p+">"}return"#"}if(typeof e!=="string"){return e.toString()}return e}function is_prototype(e){return e&&_typeof_1(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 u(e){if(!r.includes(e)){r.push(e)}}function o(e,r,n,t){if(n instanceof Pair){if(t.includes(n)){if(!a.includes(n)){a.push(n)}if(!e[__cycles__]){e[__cycles__]={}}e[__cycles__][r]=n;if(!i.includes(e)){i.push(e)}return true}}}var c=trampoline(function e(r,n){if(r instanceof Pair){delete r.ref;delete r[__cycles__];u(r);n.push(r);var t=o(r,"car",r.car,n);var i=o(r,"cdr",r.cdr,n);if(!t){c(r.car,n.slice())}if(!i){return new Thunk(function(){return e(r.cdr,n.slice())})}}});function n(e,r){if(e[__cycles__][r]instanceof Pair){var n=t.indexOf(e[__cycles__][r]);e[__cycles__][r]="#".concat(n,"#")}}c(e,[]);var t=r.filter(function(e){return a.includes(e)});t.forEach(function(e,r){e[__ref__]="#".concat(r,"=")});i.forEach(function(e){n(e,"car");n(e,"cdr")})}var pair_to_string=function(){var f=function e(r,n){var t=[];if(r[__ref__]){t.push(r[__ref__]+"(")}else if(!n){t.push("(")}return t};var p=function e(r,n){if(is_debug());if(!n||r[__ref__]){return[")"]}return[]};return trampoline(function e(r,n){var t=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:{};var i=t.nested,a=i===void 0?false:i,u=t.result,o=u===void 0?[]:u,c=t.cont,s=c===void 0?function(){o.push.apply(o,toConsumableArray(p(r,a)))}:c;o.push.apply(o,toConsumableArray(f(r,a)));var l;if(r[__cycles__]&&r[__cycles__].car){l=r[__cycles__].car}else{l=toString(r.car,n,true,{result:o,cont:s})}if(l!==undefined$1){o.push(l)}return new Thunk(function(){if(r.cdr instanceof Pair){if(r[__cycles__]&&r[__cycles__].cdr){o.push(" . ");o.push(r[__cycles__].cdr)}else{if(r.cdr[__ref__]){o.push(" . ")}else{o.push(" ")}return e(r.cdr,n,{nested:true,result:o,cont:s})}}else if(r.cdr!==nil){o.push(" . ");o.push(toString(r.cdr,n))}},s)})}();Pair.prototype.toString=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},n=r.nested,t=n===void 0?false:n;if(is_debug()){var i=[];pair_to_string(this,e,{result:i});return i.join("")}var a=[];if(this[__ref__]){a.push(this[__ref__]+"(")}else if(!t){a.push("(")}var u;if(this[__cycles__]&&this[__cycles__].car){u=this[__cycles__].car}else{u=toString(this.car,e,true)}if(u!==undefined$1){a.push(u)}if(this.cdr instanceof Pair){if(this[__cycles__]&&this[__cycles__].cdr){a.push(" . ");a.push(this[__cycles__].cdr)}else{if(this.cdr[__ref__]){a.push(" . ")}else{a.push(" ")}var o=this.cdr.toString(e,{nested:true});a.push(o)}}else if(this.cdr!==nil){a=a.concat([" . ",toString(this.cdr,e,true)])}if(!t||this[__ref__]){a.push(")")}return a.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};function abs(e){return e<0?-e:e}function seq_compare(e,r){var n=toArray(r),t=n[0],i=n.slice(1);while(i.length>0){var a=i,u=slicedToArray(a,1),o=u[0];if(!e(t,o)){return false}var c=i;var s=toArray(c);t=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 n;if(e.__type__===r.__type__){if(e.__type__==="complex"){n=e.__im__.__type__===r.__im__.__type__&&e.__re__.__type__===r.__re__.__type__}else{n=true}return n&&e.cmp(r)===0}return false}else if(typeof e==="number"){if(typeof r!=="number"){return false}e=LNumber(e);r=LNumber(r);return e.__type__===r.__type__&&e.cmp(r)===0}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 Math.ceil(e)}else{return Math.floor(e)}}}}();function Macro(e,r,n,t){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(n){if(t){this.__doc__=n}else{this.__doc__=trim_lines(n)}}this.__name__=e;this.__fn__=r}Macro.defmacro=function(e,r,n,t){var i=new Macro(e,r,n,t);i.__defmacro__=true;return i};Macro.prototype.invoke=function(e,r,n){var t=r.env,i=r.dynamic_scope,a=r.error;var u={dynamic_scope:i,error:a,macro_expand:n};var o=this.__fn__.call(t,e,u,this.__name__);return o};Macro.prototype.toString=function(){return"#")};var macro="define-macro";var recur_guard=-1e4;function macro_expand(a){return function(){var n=asyncToGenerator(regenerator.mark(function e(n,h){var t,d,i;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:i=function e(){i=asyncToGenerator(regenerator.mark(function e(n,t,i){var a,u,o,c,s,l,f,p,_;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!(n instanceof Pair&&n.car instanceof LSymbol)){r.next=26;break}if(!n[__data__]){r.next=3;break}return r.abrupt("return",n);case 3:a=i.get(n.car,{throwError:false});if(!(a instanceof Macro&&a.__defmacro__)){r.next=26;break}u=a instanceof Syntax?n:n.cdr;r.next=8;return a.invoke(u,_objectSpread(_objectSpread({},h),{},{env:i}),true);case 8:o=r.sent;if(!(a instanceof Syntax)){r.next=17;break}c=o,s=c.expr,l=c.scope;if(!(s instanceof Pair)){r.next=16;break}if(!(t!==-1&&t<=1||t")}return"#"};Syntax.className="syntax";function extract_patterns(e,r,D,w){var n=arguments.length>4&&arguments[4]!==undefined$1?arguments[4]:{};var L={"...":{symbols:{},lists:[]},symbols:{}};var x=n.expansion,F=n.define;function A(e){if(is_debug()){console.log(e)}}A(D);function E(e,r){var n=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:[];var t=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:false;A({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&&D.includes(e.valueOf())){var i=x.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,w)){A(">> 0");if(r===nil){A({pattern:e.toString()});if(e.car.car instanceof LSymbol){if(e.car.cdr instanceof Pair&&LSymbol.is(e.car.cdr.car,w)){var a=e.car.car.valueOf();var u=e.lastPair();if(LSymbol.is(u.car,w)){L["..."].symbols[a]=null;return true}else{return false}}var o=e.car.car.valueOf();if(L["..."].symbols[o]){throw new Error("syntax: named ellipsis can only "+"appear onces")}L["..."].symbols[o]=r}}}if(e instanceof Pair&&e.cdr instanceof Pair&&LSymbol.is(e.cdr.car,w)){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(!E(e.cdr.cdr,f,n,t)){return false}}}if(e.car instanceof LSymbol){var p=e.car.__name__;if(L["..."].symbols[p]&&!n.includes(p)&&!t){throw new Error("syntax: named ellipsis can only appear onces")}A(">> 1");if(r===nil){A(">> 2");if(t){A("NIL");L["..."].symbols[p]=nil}else{A("NULL");L["..."].symbols[p]=null}}else if(r instanceof Pair&&(r.car instanceof Pair||r.car===nil)){A(">> 3 "+t);if(t){if(L["..."].symbols[p]){var _=L["..."].symbols[p];if(_===nil){_=new Pair(nil,new Pair(r,nil))}else{_=_.append(new Pair(r,nil))}L["..."].symbols[p]=_}else{L["..."].symbols[p]=new Pair(r,nil)}}else{A(">> 4");L["..."].symbols[p]=new Pair(r,nil)}}else{A(">> 6");if(r instanceof Pair){A(">> 7 "+t);n.push(p);if(!L["..."].symbols[p]){L["..."].symbols[p]=new Pair(r,nil)}else{var h=L["..."].symbols[p];L["..."].symbols[p]=h.append(new Pair(r,nil))}A({IIIIII:L["..."].symbols[p].toString()})}else{A(">> 8");return false}}return true}else if(e.car instanceof Pair){var d=toConsumableArray(n);if(r===nil){A(">> 9");L["..."].lists.push(nil);return true}A(">> 10");var m=r;while(m instanceof Pair){if(!E(e.car,m.car,d,true)){return false}m=m.cdr}return true}return false}if(e instanceof LSymbol){if(LSymbol.is(e,w)){throw new Error("syntax: invalid usage of ellipsis")}A(">> 11");var v=e.__name__;if(D.includes(v)){return true}A({name:v,ellipsis:t});if(t){L["..."].symbols[v]=L["..."].symbols[v]||[];L["..."].symbols[v].push(r)}L.symbols[v]=r;if(!L.symbols[v]);return true}if(e instanceof Pair&&r instanceof Pair){A(">> 12");A({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(!E(e.car,r.car,n,t)){return false}A(">> 12 | 1");var b=e.cdr.valueOf();if(!(b in L.symbols)){L.symbols[b]=nil}b=e.car.valueOf();if(!(b in L.symbols)){L.symbols[b]=r.car}return true}}A({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,w)&&e.cdr.cdr.cdr instanceof Pair&&!LSymbol.is(e.cdr.cdr.cdr.car,w)&&E(e.car,r.car,n,t)&&E(e.cdr.cdr.cdr,r.cdr,n,t)){var g=e.cdr.car.__name__;A({pattern:e.car.toString(),code:r.car.toString(),name:g});if(D.includes(g)){return true}L["..."].symbols[g]=null;return true}A("recur");if(E(e.car,r.car,n,t)&&E(e.cdr,r.cdr,n,t)){return true}}else if(e===nil&&(r===nil||r===undefined$1)){return true}else if(e.car instanceof Pair&&LSymbol.is(e.car.car,w)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(E(e,r)){return L}}function clear_gensyms(e,i){function a(r){if(r instanceof Pair){if(!i.length){return r}var e=a(r.car);var n=a(r.cdr);return new Pair(e,n)}else if(r instanceof LSymbol){var t=i.find(function(e){return e.gensym===r});if(t){return LSymbol(t.name)}return r}else{return r}}return a(e)}function transform_syntax(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:{};var A=e.bindings,r=e.expr,E=e.scope,u=e.symbols,a=e.names,S=e.ellipsis;var o={};function c(e){if(e instanceof LSymbol){return true}return["string","symbol"].includes(_typeof_1(e))}function C(e){if(!c(e)){var r=type(e);throw new Error("syntax: internal error, need symbol got ".concat(r))}var n=e.valueOf();if(n===S){throw new Error("syntax: internal error, ellipis not transformed")}var t=_typeof_1(n);if(["string","symbol"].includes(t)){if(n in A.symbols){return A.symbols[n]}else if(t==="string"&&n.match(/\./)){var i=n.split(".");var a=i[0];if(a in A.symbols){return Pair.fromArray([LSymbol("."),A.symbols[a]].concat(i.slice(1).map(function(e){return LString(e)})))}}}if(u.includes(n)){return LSymbol(n)}return s(n)}function k(e){if(is_debug()){console.log(e)}}function s(e){if(!o[e]){var r=E.ref(e);var n=gensym(e);if(r){var t=E.get(e);E.set(n,t)}else{var i=E.get(e,{throwError:false});if(typeof i!=="undefined"){E.set(n,i)}}a.push({name:e,gensym:n});o[e]=n}return o[e]}function P(e,r,n){var t=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:function(){};var i=n.nested;k(" ==> "+e.toString(true));k(r);if(e instanceof LSymbol){var a=e.valueOf();k("[t 1");if(r[a]){if(r[a]instanceof Pair){var u=r[a],o=u.car,c=u.cdr;if(i){var s=o.car,l=o.cdr;if(l!==nil){t(a,new Pair(l,nil))}return s}if(c!==nil){t(a,c)}return o}else if(r[a]instanceof Array){t(a,r[a].slice(1));return r[a][0]}}return C(a)}if(e instanceof Pair){if(e.car instanceof LSymbol&&e.cdr instanceof Pair&&LSymbol.is(e.cdr.car,S)){k("[t 2");var f=e.car.valueOf();var p=r[f];k({expr:e.toString(true),name:f,bindings:r,item:p});if(p===null){return}else if(p){k({b:r[f].toString()});if(p instanceof Pair){k("[t 2 Pair "+i);k({______:p.toString()});var _=p.car,h=p.cdr;if(i){if(h!==nil){k("|| next 1");t(f,h)}k({car:_.toString()});return _}else{if(_.cdr!==nil){k("|| next 2");t(f,new Pair(_.cdr,h))}k({car:_.car.toString()});return _.car}}else if(p instanceof Array){k("[t 2 Array "+i);if(i){t(f,p.slice(1));return Pair.fromArray(p)}else{var d=p.slice(1);if(d.length){t(f,d)}return p[0]}}else{return p}}}k("[t 3 recur "+e.toString());var m=P(e.car,r,n,t);var v=P(e.cdr,r,n,t);return new Pair(m,v)}return e}function N(r,n){var e=Object.values(r);var t=Object.getOwnPropertySymbols(r);if(t.length){e.push.apply(e,toConsumableArray(t.map(function(e){return r[e]})))}return e.length&&e.every(function(e){if(e===null){return!n}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;k("traverse>> "+i.toString());if(i instanceof Pair){if(!r&&i.car instanceof Pair&&LSymbol.is(i.car.car,S)){return B(i.car.cdr,{disabled:true})}if(i.cdr instanceof Pair&&LSymbol.is(i.cdr.car,S)&&!r){k(">> 1");var n=A["..."].symbols;var t=Object.values(n);if(t.length&&t.every(function(e){return e===null})){return B(i.cdr.cdr,{disabled:r})}var a=O(n);var u=i.car instanceof LSymbol&&LSymbol.is(i.cdr.cdr.car,S);if(i.car instanceof Pair||u){if(A["..."].lists[0]===nil){return nil}var o=i.car;if(u){o=new Pair(i.car,new Pair(i.cdr.car,nil))}k(">> 2");var c;if(a.length){k(">> 2 (a)");var s=_objectSpread({},n);c=nil;var l=function e(){if(!N(s)){return"break"}var t={};var r=function e(r,n){t[r]=n};var n=P(o,s,{nested:true},r);if(n!==undefined$1){if(u){if(c===nil){c=n}else{c=c.append(n)}}else{c=new Pair(n,c)}}s=t};while(true){var f=l();if(f==="break")break}if(c!==nil&&!u){c=c.reverse()}if(i.cdr.cdr!==nil&&!LSymbol.is(i.cdr.cdr.car,S)){var p=B(i.cdr.cdr,{disabled:r});return c.append(p)}return c}else{k(">> 3");var _=P(i.car,n,{nested:true});if(_){return new Pair(_,nil)}return nil}}else if(i.car instanceof LSymbol){k(">> 4");if(LSymbol.is(i.cdr.cdr.car,S)){k(">> 4 (a)")}else{k(">> 4 (b)")}var h=i.car.__name__;var d=defineProperty({},h,n[h]);var m=n[h]===null;var v=nil;var y=function e(){if(!N(d,true)){k({bind:d});return"break"}var t={};var r=function e(r,n){t[r]=n;if(is_debug()){console.log({NEWBIND:t[r].toString()})}};var n=P(i,d,{nested:false},r);k({value:n.toString()});if(typeof n!=="undefined"){v=new Pair(n,v)}d=t};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}k("<<<< 1");v.append(g)}}k("<<<< 2");return v}}var D=B(i.car,{disabled:r});var w;var L;if(i.car instanceof LSymbol){var x=E.get(i.car,{throwError:false});L=x instanceof Macro&&x.__name__==="syntax-rules"}if(L){if(i.cdr.car instanceof LSymbol){w=new Pair(B(i.cdr.car,{disabled:r}),new Pair(i.cdr.cdr.car,B(i.cdr.cdr.cdr,{disabled:r})))}else{w=new Pair(i.cdr.car,B(i.cdr.cdr,{disabled:r}))}}else{w=B(i.cdr,{disabled:r})}k({a:true,car:toString(i.car),cdr:toString(i.cdr),head:toString(D),rest:toString(w)});return new Pair(D,w)}if(i instanceof LSymbol){if(r&&LSymbol.is(i,S)){return i}var F=C(i);if(typeof F!=="undefined"){return F}}return i}return B(r,{})}function is_null(e){return typeof e==="undefined"||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&&typeof e!=="undefined"&&is_function(e.then)}function box(e){switch(_typeof_1(e)){case"string":return LString(e);case"number":if(!Number.isNaN(e)){return LNumber(e)}}return e}function map_object(t,i){var e=Object.getOwnPropertyNames(t);var r=Object.getOwnPropertySymbols(t);e.concat(r).forEach(function(e){var r=i(t[e]);var n=Object.getOwnPropertyDescriptor(t,e);if(!n||n.writable&&t[e]!==r){t[e]=r}});return t}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(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(r,e){if(r[Symbol["for"]("__bound__")]){return r}var n=r.bind(e);var t=Object.getOwnPropertyNames(r).filter(filter_fn_names);t.forEach(function(e){try{n[e]=r[e]}catch(e){}});hidden_prop(n,"__fn__",r);hidden_prop(n,"__context__",e);hidden_prop(n,"__bound__",true);if(is_native_function(r)){hidden_prop(n,"__native__",true)}if(is_plain_object(e)&&r[__lambda__]){hidden_prop(n,"__method__",true)}n.valueOf=function(){return r};return n}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,n){Object.defineProperty(e,Symbol["for"](r),{get:function e(){return n},set:function e(){},configurable:false,enumerable:false})}function setFnLength(r,n){try{Object.defineProperty(r,"length",{get:function e(){return n}});return r}catch(e){var t=new Array(n).fill(0).map(function(e,r){return"a"+r}).join(",");var i=new Function("f","return function(".concat(t,") {\n return f.apply(this, arguments);\n };"));return i(r)}}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 h;switch(e){case Symbol["for"]("letrec"):h="letrec";break;case Symbol["for"]("let"):h="let";break;case Symbol["for"]("let*"):h="let*";break;default:throw new Error("Invalid let_macro value")}return Macro.defmacro(h,function(r,e){var a=e.dynamic_scope,u=e.error,n=e.macro_expand;var o;if(r.car instanceof LSymbol){if(!(r.cdr.car instanceof Pair||r.cdr.car===nil)){throw new Error("let require list of pairs")}var t;if(r.cdr.car===nil){o=nil;t=nil}else{t=r.cdr.car.map(function(e){return e.car});o=r.cdr.car.map(function(e){return e.cdr.car})}return Pair.fromArray([LSymbol("letrec"),[[r.car,Pair(LSymbol("lambda"),Pair(t,r.cdr.cdr))]],Pair(r.car,o)])}else if(n){return}var c=this;o=global_env.get("list->array")(r.car);var s=c.inherit(h);var l,f;if(h==="let*"){f=s}else if(h==="let"){l=[]}var p=0;function _(){var e=new Pair(new LSymbol("begin"),r.cdr);return evaluate(e,{env:s,dynamic_scope:a,error:u})}return function r(){var n=o[p++];if(a){a=h==="let*"?s:c}if(!n){if(l&&l.length){var e=l.map(function(e){return e.value});var t=e.filter(is_promise);if(t.length){return Promise.all(e).then(function(e){for(var r=0,n=e.length;r1&&arguments[1]!==undefined$1?arguments[1]:{},n=r.dynamic_scope,t=r.error;var i=this;if(n){n=this}var a=e;var u=[];while(a instanceof Pair){u.push(evaluate(a.car,{env:i,dynamic_scope:n,error:t}));a=a.cdr}var o=u.filter(is_promise).length;if(o){return Promise.all(u).then(c.bind(this))}else{return c.call(this,u)}})}function guardMathCall(e){for(var r=arguments.length,n=new Array(r>1?r-1:0),t=1;t2?t-2:0),a=2;a1&&arguments[1]!==undefined$1?arguments[1]:null;return function(){for(var e=arguments.length,r=new Array(e),n=0;n1?e-1:0),n=1;n=u){return a.apply(this,t)}else{return i}}return i.apply(this,arguments)}}function limit(t,i){typecheck("limit",i,"function",2);return function(){for(var e=arguments.length,r=new Array(e),n=0;n1){e=e.toLowerCase();if(LCharacter.__names__[e]){this.__name__=e;this.__char__=LCharacter.__names__[e]}else{throw new Error("Internal: Unknown named character")}}else{this.__char__=e;var r=LCharacter.__rev_names__[e];if(r){this.__name__=r}}}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=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(t){return function(){for(var e=arguments.length,r=new Array(e),n=0;n0){n.push(this.__string__.substring(0,e))}n.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 n=LNumber.getType(e);if(LNumber.types[n]){return LNumber.types[n](e,r)}var t=e instanceof Array&&LString.isString(e[0])&&LNumber.isNumber(e[1]);if(e instanceof LNumber){return LNumber(e.value)}if(!LNumber.isNumber(e)&&!t){throw new Error("You can't create LNumber from ".concat(type(e)))}if(e===null){e=0}var i;if(t){var a=e,u=slicedToArray(a,2),o=u[0],c=u[1];if(o instanceof LString){o=o.valueOf()}if(c instanceof LNumber){c=c.valueOf()}var s=o.match(/^([+-])/);var l=false;if(s){o=o.replace(/^[+-]/,"");if(s[1]==="-"){l=true}}}if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(t){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 p=BigInt(c);i=toConsumableArray(o).map(function(e,r){return BigInt(parseInt(e,c))*Math.pow(p,BigInt(r))}).reduce(function(e,r){return e+r})}else{i=BigInt(f+o)}}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(t){this.value=parseInt(o,c)}else{this.value=e}}LNumber.types={float:function e(r){var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;return new LFloat(r,n)},complex:function e(r){var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;if(!LNumber.isComplex(r)){r={im:0,re:r}}return new LComplex(r,n)},rational:function e(r){var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;if(!LNumber.isRational(r)){r={num:r,denom:1}}return new LRational(r,n)}};LNumber.prototype.gcd=function(e){var r=this.abs();e=e.abs();if(e.cmp(r)===1){var n=r;r=e;e=n}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||!Number.isNaN(e)&&LNumber.isNative(e)||LNumber.isBN(e)};LNumber.isComplex=function(e){var r=e instanceof LComplex||LNumber.isNumber(e.im)&&LNumber.isNumber(e.re);return r};LNumber.isRational=function(e){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=LNumber.prototype.toJSON=function(e){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,n){return[r,n]};return{bigint:{bigint:e,float:function e(r,n){return[LFloat(r.valueOf()),n]},rational:function e(r,n){return[{num:r,denom:1},n]},complex:function e(r,n){return[{im:0,re:r},n]}},float:{bigint:function e(r,n){return[r,n&&LFloat(n.valueOf())]},float:e,rational:function e(r,n){return[r,n&&LFloat(n.valueOf())]},complex:function e(r,n){return[{re:r,im:LFloat(0)},n]}},complex:{bigint:r("bigint"),float:r("float"),rational:r("rational"),complex:function e(r,n){var t=LNumber.coerce(r.__re__,n.__re__),i=slicedToArray(t,2),a=i[0],u=i[1];var o=LNumber.coerce(r.__im__,n.__im__),c=slicedToArray(o,2),s=c[0],l=c[1];return[{im:s,re:a},{im:l,re:u}]}},rational:{bigint:function e(r,n){return[r,n&&{num:n,denom:1}]},float:function e(r,n){return[LFloat(r.valueOf()),n]},rational:e,complex:function e(r,n){return[{im:coerce(r.__type__,n.__im__.__type__,0),re:coerce(r.__type__,n.__re__.__type__,r)},{im:coerce(r.__type__,n.__im__.__type__,n.__im__),re:coerce(r.__type__,n.__re__.__type__,n.__re__)}]}}};function r(n){return function(e,r){return[{im:coerce(n,e.__im__.__type__,e.__im__),re:coerce(n,e.__re__.__type__,e.__re__)},{im:coerce(n,e.__im__.__type__,0),re:coerce(n,r.__type__,r)}]}}}();function coerce(e,r,n){return matrix[e][r](n)[0]}LNumber.coerce=function(e,r){function n(e){if(e==="integer"){return"bigint"}return e}var t=n(LNumber.getType(e));var i=n(LNumber.getType(r));if(!matrix[t]){throw new Error("LNumber::coerce unknown lhs type ".concat(t))}else if(!matrix[t][i]){throw new Error("LNumber::coerce unknown rhs type ".concat(i))}return matrix[t][i](e,r).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,n){return r*n},"+":function e(r,n){return r+n},"-":function e(r,n){if(typeof n==="undefined"){return-r}return r-n},"/":function e(r,n){return r/n},"%":function e(r,n){return r%n},"|":function e(r,n){return r|n},"&":function e(r,n){return r&n},"~":function e(r){return~r},">>":function e(r,n){return r>>n},"<<":function e(r,n){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 n=e.im instanceof LNumber?e.im:LNumber(e.im);var t=e.re instanceof LNumber?e.re:LNumber(e.re);this.__im__=n;this.__re__=t;this.__type__="complex"}LComplex.prototype=Object.create(LNumber.prototype);LComplex.prototype.constructor=LComplex;LComplex.prototype.toRational=function(e){if(LNumber.isFloat(this.__im__)&&LNumber.isFloat(this.__re__)){var r=LFloat(this.__im__).toRational(e);var n=LFloat(this.__re__).toRational(e);return LComplex({im:r,re:n})}return this};LComplex.prototype.add=function(e){return this.complex_op(e,function(e,r,n,t){return{re:e.add(r),im:n.add(t)}})};LComplex.prototype.factor=function(){if(this.__im__ instanceof LFloat||this.__im__ instanceof LFloat){var e=this.__re__,r=this.__im__;var n,t;if(e instanceof LFloat){n=e.toRational().mul(e.toRational())}else{n=e.mul(e)}if(r instanceof LFloat){t=r.toRational().mul(r.toRational())}else{t=r.mul(r)}return n.add(t)}else{return this.__re__.mul(this.__re__).add(this.__im__.mul(this.__im__))}};LComplex.prototype.modulus=function(){return this.factor().sqrt()};LComplex.prototype.sqrt=function(){var e=this.modulus();var r,n;if(e.cmp(0)===0){r=n=e}else if(this.__re__.cmp(0)===1){r=LFloat(.5).mul(e.add(this.__re__)).sqrt();n=this.__im__.div(r).div(2)}else{n=LFloat(.5).mul(e.sub(this.__re__)).sqrt();if(this.__im__.cmp(0)===-1){n=n.sub()}r=this.__im__.div(n).div(2)}return LComplex({im:n,re:r})};LComplex.prototype.div=function(e){if(LNumber.isNumber(e)&&!LNumber.isComplex(e)){e=LComplex({im:0,re:e})}else if(!LNumber.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var r=this.coerce(e),n=slicedToArray(r,2),t=n[0],i=n[1];var a=LComplex({re:i.__re__,im:i.__im__.sub()});var u=i.factor().valueOf();var o=t.mul(a);var c=o.__re__.op("/",u);var s=o.__im__.op("/",u);return LComplex({re:c,im:s})};LComplex.prototype.sub=function(e){return this.complex_op(e,function(e,r,n,t){return{re:e.sub(r),im:n.add(t)}})};LComplex.prototype.mul=function(e){return this.complex_op(e,function(e,r,n,t){var i={re:e.mul(r).sub(n.mul(t)),im:e.mul(t).add(r.mul(n))};return i})};LComplex.prototype.complex_op=function(e,r){if(LNumber.isNumber(e)&&!LNumber.isComplex(e)){if(!(e instanceof LNumber)){e=LNumber(e)}var n=e.asType(0);e={__im__:n,__re__:e}}else if(!LNumber.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var t=e.__re__ instanceof LNumber?e.__re__:this.__re__.asType(e.__re__);var i=e.__im__ instanceof LNumber?e.__im__:this.__im__.asType(e.__im__);var a=r(this.__re__,t,this.__im__,i);if("im"in a&&"re"in a){var u=LComplex(a,true);return u}return a};LComplex._op={"+":"add","-":"sub","*":"mul","/":"div"};LComplex.prototype._op=function(e,r){var n=LComplex._op[e];return this[n](r)};LComplex.prototype.cmp=function(e){var r=this.coerce(e),n=slicedToArray(r,2),t=n[0],i=n[1];var a=t.__re__.coerce(i.__re__),u=slicedToArray(a,2),o=u[0],c=u[1];var s=o.cmp(c);if(s!==0){return s}else{var l=t.__im__.coerce(i.__im__),f=slicedToArray(l,2),p=f[0],_=f[1];return p.cmp(_)}};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=[this.__re__.toString()]}else{e=[]}e.push(this.__im__.cmp(0)<0?"-":"+");e.push(this.__im__.toString().replace(/^-/,""));e.push("i");return e.join("")};function 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"){this.value=e;this.__type__="float"}}LFloat.prototype=Object.create(LNumber.prototype);LFloat.prototype.constructor=LFloat;LFloat.prototype.toString=function(){var e=this.value.toString();if(!LNumber.isFloat(this.value)&&!e.match(/e/i)){return e+".0"}return e.replace(/^([0-9]+)e/,"$1.0e")};LFloat.prototype._op=function(e,r){if(r instanceof LNumber){r=r.value}var n=LNumber._ops[e];if(e==="/"&&this.value===0&&r===0){return NaN}return LFloat(n(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(t){return function(e){var r=function e(t,r,n){var i=function e(r,n){return n0){i=simplest_rational2(t,n)}else if(t.cmp(n)<=0){i=n}else if(n.cmp(0)>0){i=simplest_rational2(n,t)}else if(r.cmp(0)<0){i=LNumber(simplest_rational2(t.sub(),n.sub())).sub()}else{i=LNumber(0)}if(LNumber.isFloat(r)||LNumber.isFloat(e)){return LFloat(i)}return i}function simplest_rational2(e,r){var n=LNumber(e).floor();var t=LNumber(r).floor();if(e.cmp(n)<1){return n}else if(n.cmp(t)===0){var i=LNumber(1).div(r.sub(t));var a=LNumber(1).div(e.sub(n));return n.add(LNumber(1).div(simplest_rational2(i,a)))}else{return n.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 n=LNumber(e.num);var t=LNumber(e.denom);if(!r&&t.cmp(0)!==0){var i=n.op("%",t).cmp(0)===0;if(i){return LNumber(n.div(t))}}this.num=n;this.denom=t;this.__type__="rational"}LRational.prototype=Object.create(LNumber.prototype);LRational.prototype.constructor=LRational;LRational.prototype.pow=function(e){var r=e.cmp(0);if(r===0){return LNumber(1)}if(r===-1){e=e.sub();var n=this.denom.pow(e);var t=this.num.pow(e);return LRational({num:n,denom:t})}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=(readOnlyError("num"),e.toRational())}if(r instanceof LFloat){r=(readOnlyError("denom"),r.toRational())}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,n;if(e.cmp(1)!==0){r=this.num.div(e);if(r instanceof LRational){r=LNumber(r.valueOf(true))}n=this.denom.div(e);if(n instanceof LRational){n=LNumber(n.valueOf(true))}}else{r=this.num;n=this.denom}var t=this.cmp(0)<0;if(t){if(r.abs().cmp(n.abs())===0){return r.toString()}}else if(r.cmp(n)===0){return r.toString()}return r.toString()+"/"+n.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 n=this.denom.mul(e.denom);return LRational({num:r,denom:n})}var t=LNumber.coerce(this,e),i=slicedToArray(t,2),a=i[0],u=i[1];return a.mul(u)};LRational.prototype.div=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=this.num.mul(e.denom);var n=this.denom.mul(e.num);return LRational({num:r,denom:n})}var t=LNumber.coerce(this,e),i=slicedToArray(t,2),a=i[0],u=i[1];var o=a.div(u);return o};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 n=e.denom;return this.add(LRational({num:r,denom:n}))}if(!(e instanceof LNumber)){e=LNumber(e).sub()}else{e=e.sub()}var t=LNumber.coerce(this,e),i=slicedToArray(t,2),a=i[0],u=i[1];return a.add(u)};LRational.prototype.add=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=this.denom;var n=e.denom;var t=this.num;var i=e.num;var a,u;if(r!==n){u=n.mul(t).add(i.mul(r));a=r.mul(n)}else{u=t.add(i);a=r}return LRational({num:u,denom:a})}if(LNumber.isFloat(e)){return LFloat(this.valueOf()).add(e)}var o=LNumber.coerce(this,e),c=slicedToArray(o,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.value=e;this._native=r;this.__type__="bigint"}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._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 n=LNumber._ops[e](this.value,r.value);if(e==="/"){var t=this.op("%",r).cmp(0)===0;if(t){return LNumber(n)}return LRational({num:this,denom:r})}return LBigInteger(n,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};function InputPort(e){var t=this;if(typeof this!=="undefined"&&!(this instanceof InputPort)||typeof this==="undefined"){return new InputPort(e)}typecheck("InputPort",e,"function");this._read=e;this._with_parser=this._with_init_parser.bind(this,asyncToGenerator(regenerator.mark(function e(){var n;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(t.char_ready()){r.next=5;break}r.next=3;return t._read();case 3:n=r.sent;t.__parser__=new Parser(n,{env:t});case 5:return r.abrupt("return",t.__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 n=LNumber.getType(r);typeErrorMessage("read-string",n,"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(o,c){var s=this;return function(){var e=asyncToGenerator(regenerator.mark(function e(){var n,t,i,a,u=arguments;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:r.next=2;return o.call(s);case 2:n=r.sent;for(t=u.length,i=new Array(t),a=0;a"};function OutputPort(e){if(typeof this!=="undefined"&&!(this instanceof OutputPort)||typeof this==="undefined"){return new OutputPort(e)}typecheck("OutputPort",e,"function");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 n=this;if(typeof this!=="undefined"&&!(this instanceof OutputStringPort)||typeof this==="undefined"){return new OutputStringPort(r)}typecheck("OutputStringPort",r,"function");this._buffer=[];this.write=function(e){if(!LString.isString(e)){e=r(e)}else{e=e.valueOf()}n._buffer.push(e)}}OutputStringPort.prototype=Object.create(OutputPort.prototype);OutputStringPort.prototype.toString=function(){return"#>"};OutputStringPort.prototype.getString=function(){return this._buffer.map(function(e){return e.valueOf()}).join("")};OutputStringPort.prototype.constructor=OutputStringPort;function OutputFilePort(e,r){var n=this;if(typeof this!=="undefined"&&!(this instanceof OutputFilePort)||typeof this==="undefined"){return new OutputFilePort(e,r)}typecheck("OutputFilePort",e,"string");this._filename=e;this._fd=r.valueOf();this.write=function(e){if(!LString.isString(e)){e=toString(e)}else{e=e.valueOf()}root.fs.write(n._fd,e,function(){})}}OutputFilePort.prototype=Object.create(OutputPort.prototype);OutputFilePort.prototype.constructor=OutputFilePort;OutputFilePort.prototype.close=function(){var t=this;return new Promise(function(r,n){root.fs.close(t._fd,function(e){if(e){n(e)}else{t._fd=null;OutputPort.prototype.close.call(t);r()}})})};OutputFilePort.prototype.toString=function(){return"#")};function InputStringPort(e,r){var n=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(!n.__parser__){n.__parser__=new Parser(e,{env:r})}return n.__parser__});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 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");this.__filename__=r}InputFilePort.prototype=Object.create(InputStringPort.prototype);InputFilePort.prototype.constructor=InputFilePort;InputFilePort.prototype.toString=function(){return"#")};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]:{},n=r.stderr,t=r.stdin,i=r.stdout,a=objectWithoutProperties(r,["stderr","stdin","stdout"]);if(typeof this!=="undefined"&&!(this instanceof Interpreter)||typeof this==="undefined"){return new Interpreter(e,_objectSpread({stdin:t,stdout:i,stderr:n},a))}if(typeof e==="undefined"){e="anonymous"}this.__env__=user_env.inherit(e,a);var u="**interaction-environment-defaults**";this.set(u,get_props(a).concat(u));var o=internal_env.inherit("internal-".concat(e));if(is_port(t)){o.set("stdin",t)}if(is_port(n)){o.set("stderr",n)}if(is_port(i)){o.set("stdout",i)}this.constant("**internal-env**",o);global_env.set("**interaction-environment**",this.__env__)}Interpreter.prototype.exec=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;var n=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:null;typecheck("Interpreter::exec",e,"string",1);typecheck("Interpreter::exec",r,"boolean",2);global_env.set("**interaction-environment**",this.__env__);if(n===null){n=this.__env__}return exec(e,n,r?n: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 Environment(e,r,n){if(arguments.length===1){if(_typeof_1(arguments[0])==="object"){e=arguments[0];r=null}else if(typeof arguments[0]==="string"){e={};r={};n=arguments[0]}}this.__docs__=new Map;this.__env__=e;this.__parent__=r;this.__name__=n||"anonymous"}Environment.prototype.list=function(){return get_props(this.__env__)};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_1(e)==="object"){r=e}if(!e||_typeof_1(e)==="object"){e="child of "+(this.__name__||"unknown")}return new Environment(r||{},this,e)};Environment.prototype.doc=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:null;if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}if(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 t=this.inherit("__frame__");t.set("parent.frame",doc("parent.frame",function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:1;e=e.valueOf();var r=t.__parent__;if(!(r instanceof Environment)){return nil}if(e<=0){return r}var n=r.get("parent.frame");return n(e-1)},global_env.__env__["parent.frame"].__doc__));r.callee=e;t.set("arguments",r);return t};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 n={};Object.keys(this.__env__).forEach(function(e){n[e]=r.__env__[e]});return new Environment(n,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 n=r.throwError,t=n===void 0?true:n;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 u=i.split(".").filter(Boolean);if(u.length>0){var o=toArray(u),c=o[0],s=o.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(t){throw new Error("Unbound variable `"+i.toString()+"'")}};Environment.prototype.set=function(e,r){var n=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(n){this.doc(e,n)}return this};Environment.prototype.constant=function(r,e){var n=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 t=arguments[0];Object.keys(t).forEach(function(e){n.constant(r,t[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(function e(r){for(var n=arguments.length,t=new Array(n>1?n-1:0),i=1;i1?n-1:0),i=1;it.length){throw new Error("Not enough arguments")}var o=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 n=t[o++];if(r==="a"){return c(n)}else{return c(n,true)}}});u=r.match(/~([\S])/);if(u){throw new Error("format: Unrecognized escape seqence ".concat(u[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(function e(r){var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:null;if(n===null){n=internal(this,"stdout")}var t=global_env.get("repr")(r);n.write.call(global_env,t)},"(display arg [port])\n\n Function send string to standard output or provied port."),error:doc(function e(){var r=internal(this,"stderr");var n=global_env.get("repr");for(var t=arguments.length,i=new Array(t),a=0;a1&&arguments[1]!==undefined$1?arguments[1]:{},n=r.dynamic_scope,t=r.error;if(n){n=this}var i=this;var u;var o=evaluate(e.cdr.car,{env:this,dynamic_scope:n,error:t});o=resolve_promises(o);function c(r,n,t){if(is_promise(r)){return r.then(function(e){return c(r,e,t)})}if(is_promise(n)){return n.then(function(e){return c(r,e,t)})}if(is_promise(t)){return t.then(function(e){return c(r,n,e)})}i.get("set-obj!").call(i,r,n,t);return t}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:n,error:t});var p=evaluate(l,{env:this,dynamic_scope:n,error:t});return c(f,p,o)}if(!(e.car instanceof LSymbol)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var _=e.car.valueOf();u=this.ref(e.car.__name__);return unpromise(o,function(e){if(!u){var r=_.split(".");if(r.length>1){var n=r.pop();var t=r.join(".");var i=a.get(t,{throwError:false});if(i){c(i,n,e);return}}throw new Error("Unbound variable `"+_+"'")}u.set(_,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 n=this.ref(r);if(n){delete n.__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(function e(r,n){typecheck("load",r,"string");var t=this;if(t.__name__==="__frame__"){t=t.__parent__}if(!(n instanceof Environment)){if(t===global_env){n=t}else{n=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 u(e){if(type(e)==="buffer"){e=e.toString()}return exec(e.replace(/^#!.*/,""),n)}if(is_node()){return new Promise(function(n,t){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){t(e);global_env.set(i,a)}else{try{u(r).then(function(){n();global_env.set(i,a)})["catch"](t)}catch(e){t(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 u(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 n=asyncToGenerator(regenerator.mark(function e(n,t){var i,a,u,o,c,s,l,f,p,_,h;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:i=t.dynamic_scope,a=t.error;u=this;if(i){i=u}o=u.inherit("do");c=n.car;s=n.cdr.car;l=n.cdr.cdr;if(l!==nil){l=new Pair(LSymbol("begin"),l)}f={env:u,dynamic_scope:i,error:a};p=c;case 10:if(!(p!==nil)){r.next=21;break}_=p.car;r.t0=o;r.t1=_.car;r.next=16;return evaluate(_.cdr.car,f);case 16:r.t2=r.sent;r.t0.set.call(r.t0,r.t1,r.t2);p=p.cdr;r.next=10;break;case 21:f={env:o,dynamic_scope:i,error:a};h=regenerator.mark(function e(){var n,t,i,a,u;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:n=c;t={};case 5:if(!(n!==nil)){r.next=15;break}i=n.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;t[i.car.valueOf()]=a;case 12:n=n.cdr;r.next=5;break;case 15:u=Object.getOwnPropertySymbols(t);Object.keys(t).concat(u).forEach(function(e){o.set(e,t[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 n.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(n,e){var t=e.dynamic_scope,i=e.error;if(t){t=this}var a=this;var r=function e(r){if(r===false){return evaluate(n.cdr.cdr.car,{env:a,dynamic_scope:t,error:i})}else{return evaluate(n.cdr.car,{env:a,dynamic_scope:t,error:i})}};if(n===nil){throw new Error("too few expressions for `if`")}var u=evaluate(n.car,{env:a,dynamic_scope:t,error:i});return unpromise(u,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 n=e.dynamic_scope,t=e.error;typecheck("let-env",r,"pair");var i=evaluate(r.car,{env:this,dynamic_scope:n,error:t});return unpromise(i,function(e){typecheck("let-env",e,"environment");return evaluate(Pair(LSymbol("begin"),r.cdr),{env:e,dynamic_scope:n,error:t})})},"(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."),"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 t=Object.assign({},r);var i=global_env.get("list->array")(e);if(t.dynamic_scope){t.dynamic_scope=this}t.env=this;var a;return function r(){if(i.length){var e=i.shift();var n=evaluate(e,t);return unpromise(n,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 n=r.dynamic_scope,t=r.error;var i={env:this,error:t};if(n){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(n,e){var t=this;if(n.car instanceof Pair&&n.car.car instanceof LSymbol){var r=new Pair(new LSymbol("define"),new Pair(n.car.car,new Pair(new Pair(new LSymbol("lambda"),new Pair(n.car.cdr,n.cdr)))));return r}else if(e.macro_expand){return}if(e.dynamic_scope){e.dynamic_scope=this}e.env=t;var i=n.cdr.car;var a;if(i instanceof Pair){i=evaluate(i,e);a=true}else if(i instanceof LSymbol){i=t.get(i)}typecheck("define",n.car,"symbol");return unpromise(i,function(e){if(t.__name__===Syntax.__merge_env__){t=t.__parent__}if(a&&(is_function(e)&&e[__lambda__]||e instanceof Syntax)){e.__name__=n.car.valueOf();if(e.__name__ instanceof LString){e.__name__=e.__name__.valueOf()}}var r;if(n.cdr.cdr instanceof Pair&&LString.isString(n.cdr.cdr.car)){r=n.cdr.cdr.car.valueOf()}t.set(n.car,e,r)})}),"(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,n){var t=_typeof_1(e);if(is_null(e)||t!=="object"&&t!=="function"){var i=typeErrorMessage("set-obj!",type(e),["object","function"]);throw new Error(i)}e=unbind(e);r=r.valueOf();if(arguments.length===2){delete e[r]}else if(is_prototype(e)&&is_function(n)){e[r]=unbind(n);e[r][__prototype__]=true}else if(is_function(n)||is_native(n)||n===nil){e[r]=n}else{e[r]=n?n.valueOf():n}},"(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(function e(){for(var r=arguments.length,n=new Array(r),t=0;t1&&arguments[1]!==undefined$1?arguments[1]:{},p=e.dynamic_scope,_=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(p){if(!(this instanceof Environment)){e=h}else{e=this}}else{e=h}e=e.inherit("lambda");var r=f.car;var n=0;var t;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),u=0;u2&&arguments[2]!==undefined$1?arguments[2]:a;if(e instanceof Pair){var t=e.car;var i=e.cdr;if(n(t)){t=r(t)}if(n(i)){i=r(i)}if(is_promise(t)||is_promise(i)){return Promise.all([t,i]).then(function(e){var r=slicedToArray(e,2),n=r[0],t=r[1];return new Pair(n,t)})}else{return new Pair(t,i)}}return e}function u(e,r){if(e instanceof Pair){if(r!==nil){e.append(r)}}else{e=new Pair(e,r)}return e}function n(e){return!!e.filter(function(e){return e instanceof Pair&&LSymbol.is(e.car,"unquote")}).length}function f(e,t,i){return e.reduce(function(e,r){if(!(r instanceof Pair)){e.push(r);return e}if(LSymbol.is(r.car,"unquote-splicing")){var n;if(t+11){var r="You can't splice multiple atoms inside list";throw new Error(r)}if(!(i.cdr instanceof Pair&&n[0]===nil)){return n[0]}}n=n.map(function(e){if(h.has(e)){return e.clone()}else{h.add(e);return e}});var t=d(i.cdr,0,1);if(t===nil&&n[0]===nil){return undefined$1}return unpromise(t,function(e){if(n[0]===nil){return e}if(n.length===1){return u(n[0],e)}var r=n.reduce(function(e,r){return u(e,r)});return u(r,e)})})}(i.car.cdr)}var h=new Set;function d(e,r,n){if(e instanceof Pair){if(LSymbol.is(e.car.car,"unquote-splicing")){return _(e,r+1,n)}if(LSymbol.is(e.car,"quasiquote")){var t=d(e.cdr,r,n+1);return new Pair(e.car,t)}if(LSymbol.is(e.car.car,"unquote")){if(r+2===n&&e.car.cdr instanceof Pair&&e.car.cdr.car instanceof Pair&&LSymbol.is(e.car.cdr.car.car,"unquote-splicing")){var i=e.car.cdr;return new Pair(new Pair(new LSymbol("unquote"),_(i,r+2,n)),nil)}else if(e.car.cdr instanceof Pair&&e.car.cdr.cdr!==nil){if(e.car.cdr.car instanceof Pair){var a=[];return function r(n){if(n===nil){return Pair.fromArray(a)}return unpromise(evaluate(n.car,{env:s,dynamic_scope:o,error:c}),function(e){a.push(e);return r(n.cdr)})}(e.car.cdr)}else{return e.car.cdr}}}if(LSymbol.is(e.car,"quote")){return new Pair(e.car,d(e.cdr,r,n))}if(LSymbol.is(e.car,"unquote")){r++;if(rn){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 u=[];return function r(n){if(n===nil){return Pair.fromArray(u)}return unpromise(evaluate(n.car,{env:s,dynamic_scope:o,error:c}),function(e){u.push(e);return r(n.cdr)})}(e.cdr)}else{return e.cdr}}else{return evaluate(e.cdr.car,{env:s,dynamic_scope:o,error:c})}}else{return e.cdr}}return l(e,function(e){return d(e,r,n)})}else if(is_plain_object(e)){return p(e,r,n)}else if(e instanceof Array){return f(e,r,n)}return e}function t(e){if(e instanceof Pair){delete e[__data__];if(!e.haveCycles("car")){t(e.car)}if(!e.haveCycles("cdr")){t(e.cdr)}}}if(is_plain_object(e.car)&&!n(Object.values(e.car))){return quote(e.car)}if(Array.isArray(e.car)&&!n(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){t(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(function e(r){typecheck("clone",r,"pair");return r.clone()},"(clone list)\n\n Function return clone of the list."),append:doc(function e(){var r;for(var n=arguments.length,t=new Array(n),i=0;iarray")(r).reverse();return global_env.get("array->list")(n)}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(function e(r,n){typecheck("nth",r,"number");typecheck("nth",n,["array","pair"]);if(n instanceof Pair){var t=n;var i=0;while(iarray")(n).join(r)},"(join separator list)\n\n Function return string by joining elements of the list"),split:doc(function e(r,n){typecheck("split",r,["regex","string"]);typecheck("split",n,"string");return global_env.get("array->list")(n.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(function e(r,n,t){typecheck("replace",r,["regex","string"]);typecheck("replace",n,["string","function"]);typecheck("replace",t,"string");return t.replace(r,n)},"(replace pattern replacement string)\n\n Function change pattern to replacement inside string. Pattern can be string\n or regex and replacement can be function or string."),match:doc(function e(r,n){typecheck("match",r,["regex","string"]);typecheck("match",n,"string");var t=n.match(r);return t?global_env.get("array->list")(t):nil},"(match pattern string)\n\n function return match object from JavaScript as list."),search:doc(function e(r,n){typecheck("search",r,["regex","string"]);typecheck("search",n,"string");return n.search(r)},"(search pattern string)\n\n Function return first found index of the pattern inside a string"),repr:doc(function e(r,n){return toString(r,n)},"(repr obj)\n\n Function return string LIPS representation of an object as string."),env:doc(function e(e){e=e||this;var r=Object.keys(e.__env__);var n;if(r.length){n=Pair.fromArray(r)}else{n=nil}if(e.__parent__!==undefined$1){return global_env.get("env")(e.__parent__).append(n)}return n},"(env obj)\n\n Function return list values (functions and variables) inside environment."),new:doc("new",function(e){for(var r=arguments.length,n=new Array(r>1?r-1:0),t=1;t2&&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,n)},'(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=e.valueOf()}return e in 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?",LNumber.isNumber,"(number? expression)\n\n Function check if value is a number"),"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(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_1(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Function check if value is an plain object."),flatten:doc(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",toArray$1("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":doc("list->array",toArray$1("list->array"),"(list->array list)\n\n Function convert LIPS list into JavaScript array."),apply:doc(function e(r){for(var n=arguments.length,t=new Array(n>1?n-1:0),i=1;iarray").call(this,a));return r.apply(this,prepare_fn_args(r,t))},"(apply fn list)\n\n Function that call function with list of arguments."),length:doc(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 n=r===10&&!e.match(/e/i)||r===16;if(e.match(int_bare_re)&&n||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,t){var a,u;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")){u=r.cdr.cdr.car}}else if(LSymbol.is(r.cdr.car.car,"finally")){u=r.cdr.car}if(!(u||a)){throw new Error("try: invalid syntax")}var o=i;if(u){o=function e(r,n){o=t;unpromise(evaluate(new Pair(new LSymbol("begin"),u.cdr),c),function(){n(r)})}}var c={env:s,error:function e(r){var n=s.inherit("try");if(a){n.set(a.cdr.car.car,r);var t={env:n,error:f};if(l){t.dynamic_scope=s}unpromise(evaluate(new Pair(new LSymbol("begin"),a.cdr.cdr),t),function(e){o(e,i)})}else{o(r,f)}}};if(l){c.dynamic_scope=s}var e=evaluate(r.car,c);if(is_promise(e)){e.then(function(e){o(e,i)})["catch"](c.error)}else{o(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."),throw:doc("throw",function(e){throw new Error(e)},"(throw string)\n\n Throw new expection."),find:doc(function r(n,t){typecheck("find",n,["regex","function"]);typecheck("find",t,["pair","nil"]);if(is_null(t)){return nil}var e=matcher("find",n);return unpromise(e(t.car),function(e){if(e&&e!==nil){return t.car}return r(n,t.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 n=arguments.length,t=new Array(n>1?n-1:0),i=1;i1?r-1:0),a=1;a3?t-3:0),a=3;a3?i-3:0),u=3;uarray")(n);var a=[];var u=matcher("filter",r);return function r(n){function e(e){if(e&&e!==nil){a.push(t)}return r(++n)}if(n===i.length){return Pair.fromArray(a)}var t=i[n];return unpromise(u(t),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher order function that call `fn` for each element of the list\n and return list for only those elements for which funtion return\n true value. If called with regex it will create matcher function."),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(function e(){for(var r=arguments.length,n=new Array(r),t=0;ti?n%=i:i%=n}n=abs(a*(t<0||arguments.length<=t?undefined$1:arguments[t]))/(n+i)}return LNumber(n)},"(lcm n1 n2 ...)\n\n Function return the least common multiple of their arguments."),"odd?":doc("odd?",singleMathOp(function(e){return LNumber(e).isOdd()}),"(odd? number)\n\n Function check if number os odd."),"even?":doc("even?",singleMathOp(function(e){return LNumber(e).isEven()}),"(even? number)\n\n Function check if number is even."),"*":doc("*",reduceMathOp(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("+",reduceMathOp(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),n=0;n":doc(">",function(){for(var e=arguments.length,r=new Array(e),n=0;n x1 x2 x3 ...)\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),n=0;n=":doc(">=",function(){for(var e=arguments.length,r=new Array(e),n=0;n= x1 x2 x3 ...)\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 u=global_env.get("list->array")(e);var o=this;if(i){i=o}if(!u.length){return false}var c;return function r(){function e(e){c=e;if(c!==false){return c}else{return r()}}if(!u.length){if(c!==false){return c}else{return false}}else{var n=u.shift();var t=evaluate(n,{env:o,dynamic_scope:i,error:a});return unpromise(t,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 u=global_env.get("list->array")(e);var o=this;if(i){i=o}if(!u.length){return true}var c;return function r(){function e(e){c=e;if(c===false){return false}else{return r()}}var n=u.shift();if(typeof n==="undefined"){if(c!==false){return c}else{return false}}else{var t=evaluate(n,{env:o,dynamic_scope:i,error:a});return unpromise(t,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(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");global_env.set("**interaction-environment**",user_env);global_env.constant("**internal-env**",internal_env);(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(r){var n=e[r]?e[r]:r;global_env.set(n,doc(n,function(e){typecheck(n,e,"number");if(e instanceof LNumber){return e[r]()}},"(".concat(n," number)\n\n Function calculate ").concat(n," of a number.")))})})();function allPossibleCases(e){if(e.length===1){return e[0]}else{var r=[];var n=allPossibleCases(e.slice(1));for(var t=0;t3&&arguments[3]!==undefined$1?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(t!==null){i+=" (argument ".concat(t,")")}if(n instanceof Array){if(n.length===1){n=n[0]}else{var a=n[n.length-1];n=n.slice(0,-1).join(", ")+" or "+a}}return"Expecting ".concat(n,", got ").concat(r).concat(i)}function typecheck(e,r,n){var t=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:null;e=e.valueOf();var i=type(r).toLowerCase();var a=false;if(n instanceof Pair){n=n.toArray()}if(n instanceof Array){n=n.map(function(e){return e.valueOf()})}if(n instanceof Array){n=n.map(function(e){return e.valueOf().toLowerCase()});if(n.includes(i)){a=true}}else{n=n.valueOf().toLowerCase()}if(!a&&i!==n){throw new Error(typeErrorMessage(e,i,n,t))}}function self_evaluated(e){var r=_typeof_1(e);return["string","function"].includes(r)||_typeof_1(e)==="symbol"||e instanceof LSymbol||e instanceof LNumber||e instanceof LString||e instanceof RegExp}function is_native(e){return e instanceof LNumber||e instanceof LString||e instanceof LCharacter}function has_own_symbol(e,r){if(e===null){return false}return _typeof_1(e)==="object"&&r in Object.getOwnPropertySymbols(e)}function 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 n=0,t=Object.entries(r);n2&&arguments[2]!==undefined$1?arguments[2]:{},a=r.env,u=r.dynamic_scope,n=r.error,o=n===void 0?function(){}:n;e=evaluate_args(e,{env:a,dynamic_scope:u,error:o});return unpromise(e,function(e){if(is_raw_lambda(i)){i=unbind(i)}e=prepare_fn_args(i,e);var r=e.slice();var n=(u||a).newFrame(i,r);var t=resolve_promises(i.apply(n,e));return unpromise(t,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},o)})}function evaluate(r){var e=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},n=e.env,t=e.dynamic_scope,i=e.error,a=i===void 0?function(){}:i;try{if(t===true){n=t=n||global_env}else if(n===true){n=t=global_env}else{n=n||global_env}var u={env:n,dynamic_scope:t,error:a};var o;if(is_null(r)){return r}if(r instanceof LSymbol){return n.get(r)}if(!(r instanceof Pair)){return r}var c=r.car;var s=r.cdr;if(c instanceof Pair){o=resolve_promises(evaluate(c,u));if(is_promise(o)){return o.then(function(e){return evaluate(new Pair(e,r.cdr),u)})}else if(!is_function(o)){throw new Error(type(o)+" "+n.get("repr")(o)+" is not a function while evaluating "+r.toString())}}if(c instanceof LSymbol){o=n.get(c)}else if(is_function(c)){o=c}var l;if(o instanceof Syntax){l=evaluate_syntax(o,r,u)}else if(o instanceof Macro){l=evaluate_macro(o,s,u)}else if(is_function(o)){l=apply(o,s,u)}else if(r instanceof Pair){o=c&&c.toString();throw new Error("".concat(type(c)," ").concat(o," is not a function"))}else if(!is_function(o)){if(o){var f="".concat(type(o)," `").concat(o,"' is not a function");throw new Error(f)}throw new Error("Unknown function `".concat(c.toString(),"'"))}else{return r}var p=n.get(Symbol["for"]("__promise__"),{throwError:false});if(p===true&&is_promise(l)){return new QuotedPromise(l)}return l}catch(e){a&&a.call(n,e,r)}}function exec(e,r,n){return _exec.apply(this,arguments)}function _exec(){_exec=asyncToGenerator(regenerator.mark(function e(n,t,i){var a,u,o,c,s,l,f,p,_;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(i===true){t=i=t||user_env}else if(t===true){t=i=user_env}else{t=t||user_env}a=[];u=true;o=false;r.prev=4;s=asyncIterator(parse(n));case 6:r.next=8;return s.next();case 8:l=r.sent;u=l.done;r.next=12;return l.value;case 12:f=r.sent;if(u){r.next=28;break}p=f;_=evaluate(p,{env:t,dynamic_scope:i,error:function e(r,n){if(r&&r.message){r.message=r.message.replace(/.*:\s*([^:]+:\s*)/,"$1");if(n){if(!(r.__code__ instanceof Array)){r.__code__=[]}r.__code__.push(n.toString(true))}}throw r}});if(is_promise(_)){r.next=20;break}a.push(_);r.next=25;break;case 20:r.t0=a;r.next=23;return _;case 23:r.t1=r.sent;r.t0.push.call(r.t0,r.t1);case 25:u=true;r.next=6;break;case 28:r.next=34;break;case 30:r.prev=30;r.t2=r["catch"](4);o=true;c=r.t2;case 34:r.prev=34;r.prev=35;if(!(!u&&s["return"]!=null)){r.next=39;break}r.next=39;return s["return"]();case 39:r.prev=39;if(!o){r.next=42;break}throw c;case 42:return r.finish(39);case 43:return r.finish(34);case 44:return r.abrupt("return",a);case 45:case"end":return r.stop()}}},e,null,[[4,30,34,44],[35,,39,43]])}));return _exec.apply(this,arguments)}function balanced(e){var r={"[":"]","(":")"};var n;if(typeof e==="string"){n=tokenize(e)}else{n=e.map(function(e){return e&&e.token?e.token:e})}var t=Object.keys(r);var i=Object.values(r).concat(t);n=n.filter(function(e){return i.includes(e)});var a=new Stack;var u=_createForOfIteratorHelper(n),o;try{for(u.s();!(o=u.n()).done;){var c=o.value;if(t.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){u.e(e)}finally{u.f()}return a.is_empty()}function fworker(e){var r="("+e.toString()+")()";var n=window.URL||window.webkitURL;var t;try{t=new Blob([r],{type:"application/javascript"})}catch(e){var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;t=new i;t.append(r);t=t.getBlob()}return new root.Worker(n.createObjectURL(t))}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 u=this.worker=fworker(function(){var u;var o;self.addEventListener("message",function(e){var n=e.data;var r=n.id;if(n.type!=="RPC"||r===null){return}function t(e){self.postMessage({id:r,type:"RPC",result:e})}function i(e){self.postMessage({id:r,type:"RPC",error:e})}if(n.method==="eval"){if(!o){i("Worker RPC: LIPS not initilized, call init first");return}o.then(function(){var e=n.params[0];var r=n.params[1];u.exec(e,r).then(function(e){e=e.map(function(e){return e&&e.valueOf()});t(e)})["catch"](function(e){i(e)})})}else if(n.method==="init"){var a=n.params[0];if(typeof a!=="string"){i("Worker RPC: url is not a string")}else{importScripts("".concat(a,"/dist/lips.min.js"));u=new lips.Interpreter("worker");o=bootstrap(a);o.then(function(){t(true)})}}})});this.rpc=function(){var t=0;return function e(r,n){var a=++t;return new Promise(function(t,i){u.addEventListener("message",function e(r){var n=r.data;if(n&&n.type==="RPC"&&n.id===a){if(n.error){i(n.error)}else{t(n.result)}u.removeEventListener("message",e)}});u.postMessage({type:"RPC",method:r,id:a,params:n})})}}();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])}}Pair.unDry=function(e){return new Pair(e.car,e.cdr)};Pair.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};Nil.prototype.toDry=function(){return{value:null}};Nil.unDry=function(){return nil};LSymbol.prototype.toDry=function(){return{value:{name:this.__name__}}};LSymbol.unDry=function(e){return new LSymbol(e.__name__)};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 u=["text/x-lips","text/x-scheme"];var o;function c(n){return new Promise(function(r){var e=n.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(n.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 n=r.getAttribute("type");if(u.includes(n)){var t=r.getAttribute("bootstrap");if(!o&&typeof t==="string"){bootstrap(t).then(function(){return c(r)}).then(e)}else{c(r).then(e)}}else if(n&&n.match(/lips|lisp/)){console.warn("Expecting "+u.join(" or ")+" found "+n)}return e()}}()})}if(!window.document){return Promise.resolve()}else if(currentScript){var r=currentScript;var n=r.getAttribute("bootstrap");if(typeof n==="string"){return bootstrap(n).then(function(){o=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("Mon, 18 Jan 2021 14:58:43 +0000").valueOf();var r=e==="{{"+"DATE}}"?new Date:new Date(e);var n=function e(r){return r.toString().padStart(2,"0")};var t=r.getFullYear();var i=[t,n(r.getMonth()+1),n(r.getDate())].join("-");var a="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter DEV (".concat(i,") \nCopyright (c) 2018-").concat(t," Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables.\nYou can also use (help name) to display help for specic function or macro and\n(apropos name) to display list of matched names in environment.\n").replace(/^.*\n/,"");return a}();Ahead.__class__="ahead";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";LNumber.__class__="number";LCharacter.__class__="character";LString.__class__="string";var lips={version:"DEV",banner:banner,date:"Mon, 18 Jan 2021 14:58:43 +0000",exec:exec,parse:compose(uniterate_async,parse),tokenize:tokenize,evaluate:evaluate,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,quote:quote,InputPort:InputPort,OutputPort:OutputPort,InputFilePort:InputFilePort,OutputFilePort:OutputFilePort,InputStringPort:InputStringPort,OutputStringPort:OutputStringPort,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 _readOnlyError(e){throw new Error('"'+e+'" is read-only')}var readOnlyError=_readOnlyError;function createCommonjsModule(e,r){return r={exports:{}},e(r,r.exports),r.exports}var setPrototypeOf=createCommonjsModule(function(n){function t(e,r){n.exports=t=Object.setPrototypeOf||function e(r,n){r.__proto__=n;return r};return t(e,r)}n.exports=t});function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Date.prototype.toString.call(Reflect.construct(Date,[],function(){}));return true}catch(e){return false}}var isNativeReflectConstruct=_isNativeReflectConstruct;var construct=createCommonjsModule(function(t){function i(e,r,n){if(isNativeReflectConstruct()){t.exports=i=Reflect.construct}else{t.exports=i=function e(r,n,t){var i=[null];i.push.apply(i,n);var a=Function.bind.apply(r,i);var u=new a;if(t)setPrototypeOf(u,t.prototype);return u}}return i.apply(null,arguments)}t.exports=i});function _arrayWithHoles(e){if(Array.isArray(e))return e}var arrayWithHoles=_arrayWithHoles;function _iterableToArray(e){if(typeof Symbol!=="undefined"&&Symbol.iterator in Object(e))return Array.from(e)}var iterableToArray=_iterableToArray;function _arrayLikeToArray(e,r){if(r==null||r>e.length)r=e.length;for(var n=0,t=new Array(r);n=0;--r){var i=this.tryEntries[r];var a=i.completion;if(i.tryLoc==="root"){return e("end")}if(i.tryLoc<=this.prev){var u=l.call(i,"catchLoc");var o=l.call(i,"finallyLoc");if(u&&o){if(this.prev=0;--n){var t=this.tryEntries[n];if(t.tryLoc<=this.prev&&l.call(t,"finallyLoc")&&this.prev=0;--r){var n=this.tryEntries[r];if(n.finallyLoc===e){this.complete(n.completion,n.afterLoc);S(n);return m}}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc===e){var t=n.completion;if(t.type==="throw"){var i=t.arg;S(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){this.delegate={iterator:k(e),resultName:r,nextLoc:n};if(this.method==="next"){this.arg=c}return m}};return u}(e.exports);try{regeneratorRuntime=r}catch(e){Function("r","regeneratorRuntime = r")(r)}});var regenerator=runtime_1;function asyncGeneratorStep(e,r,n,t,i,a,u){try{var o=e[a](u);var c=o.value}catch(e){n(e);return}if(o.done){r(c)}else{Promise.resolve(c).then(t,i)}}function _asyncToGenerator(o){return function(){var e=this,u=arguments;return new Promise(function(r,n){var t=o.apply(e,u);function i(e){asyncGeneratorStep(t,r,n,i,a,"next",e)}function a(e){asyncGeneratorStep(t,r,n,i,a,"throw",e)}i(undefined)})}}var asyncToGenerator=_asyncToGenerator;function _classCallCheck(e,r){if(!(e instanceof r)){throw new TypeError("Cannot call a class as a function")}}var classCallCheck=_classCallCheck;function _defineProperties(e,r){for(var n=0;n=0)continue;n[i]=e[i]}return n}var objectWithoutPropertiesLoose=_objectWithoutPropertiesLoose;function _objectWithoutProperties(e,r){if(e==null)return{};var n=objectWithoutPropertiesLoose(e,r);var t,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,t))continue;n[t]=e[t]}}return n}var objectWithoutProperties=_objectWithoutProperties;function _iterableToArrayLimit(e,r){if(typeof Symbol==="undefined"||!(Symbol.iterator in Object(e)))return;var n=[];var t=true;var i=false;var a=undefined;try{for(var u=e[Symbol.iterator](),o;!(t=(o=u.next()).done);t=true){n.push(o.value);if(r&&n.length===r)break}}catch(e){i=true;a=e}finally{try{if(!t&&u["return"]!=null)u["return"]()}finally{if(i)throw a}}return n}var iterableToArrayLimit=_iterableToArrayLimit;function _slicedToArray(e,r){return arrayWithHoles(e)||iterableToArrayLimit(e,r)||unsupportedIterableToArray(e,r)||nonIterableRest()}var slicedToArray=_slicedToArray;var _typeof_1=createCommonjsModule(function(r){function n(e){"@babel/helpers - typeof";if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){r.exports=n=function e(r){return typeof r}}else{r.exports=n=function e(r){return r&&typeof Symbol==="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r}}return n(e)}r.exports=n});function _asyncIterator(e){var r;if(typeof Symbol!=="undefined"){if(Symbol.asyncIterator){r=e[Symbol.asyncIterator];if(r!=null)return r.call(e)}if(Symbol.iterator){r=e[Symbol.iterator];if(r!=null)return r.call(e)}}throw new TypeError("Object is not async iterable")}var asyncIterator=_asyncIterator;function _AwaitValue(e){this.wrapped=e}var AwaitValue=_AwaitValue;function _awaitAsyncGenerator(e){return new AwaitValue(e)}var awaitAsyncGenerator=_awaitAsyncGenerator;function AsyncGenerator(a){var u,o;function e(t,i){return new Promise(function(e,r){var n={key:t,arg:i,resolve:e,reject:r,next:null};if(o){o=o.next=n}else{u=o=n;c(t,i)}})}function c(r,e){try{var n=a[r](e);var t=n.value;var i=t instanceof AwaitValue;Promise.resolve(i?t.wrapped:t).then(function(e){if(i){c(r==="return"?"return":"next",e);return}s(n.done?"return":"normal",e)},function(e){c("throw",e)})}catch(e){s("throw",e)}}function s(e,r){switch(e){case"return":u.resolve({value:r,done:true});break;case"throw":u.reject(r);break;default:u.resolve({value:r,done:false});break}u=u.next;if(u){c(u.key,u.arg)}else{o=null}}this._invoke=e;if(typeof a["return"]!=="function"){this["return"]=undefined}}if(typeof Symbol==="function"&&Symbol.asyncIterator){AsyncGenerator.prototype[Symbol.asyncIterator]=function(){return this}}AsyncGenerator.prototype.next=function(e){return this._invoke("next",e)};AsyncGenerator.prototype["throw"]=function(e){return this._invoke("throw",e)};AsyncGenerator.prototype["return"]=function(e){return this._invoke("return",e)};var AsyncGenerator_1=AsyncGenerator;function _wrapAsyncGenerator(e){return function(){return new AsyncGenerator_1(e.apply(this,arguments))}}var wrapAsyncGenerator=_wrapAsyncGenerator;function _createForOfIteratorHelper(r,e){var n;if(typeof Symbol==="undefined"||r[Symbol.iterator]==null){if(Array.isArray(r)||(n=_unsupportedIterableToArray$1(r))||e&&r&&typeof r.length==="number"){if(n)r=n;var t=0;var i=function e(){};return{s:i,n:function e(){if(t>=r.length)return{done:true};return{done:false,value:r[t++]}},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,u=false,o;return{s:function e(){n=r[Symbol.iterator]()},n:function e(){var r=n.next();a=r.done;return r},e:function e(r){u=true;o=r},f:function e(){try{if(!a&&n["return"]!=null)n["return"]()}finally{if(u)throw o}}}}function _unsupportedIterableToArray$1(e,r){if(!e)return;if(typeof e==="string")return _arrayLikeToArray$1(e,r);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor)n=e.constructor.name;if(n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray$1(e,r)}function _arrayLikeToArray$1(e,r){if(r==null||r>e.length)r=e.length;for(var n=0,t=new Array(r);n1&&arguments[1]!==undefined$1?arguments[1]:null;var t=arguments[1]===true;function r(e){if(!is_debug()){return}var r=global_env.get("repr")(e);if(n===null||n instanceof RegExp&&n.test(r)){console.log(global_env.get("type")(e)+": "+r)}if(t){console.log(e)}}if(is_promise(e)){e.then(r)}else{r(e)}return e}function is_debug(){return user_env.get("DEBUG",{throwError:false})}if(!root.fetch){root.fetch=function(i,a){a=a||{};return new Promise(function(e,r){var n=new XMLHttpRequest;n.open(a.method||"get",i,true);for(var t in a.headers){n.setRequestHeader(t,a.headers[t])}n.withCredentials=a.credentials=="include";n.onload=function(){e(o())};n.onerror=r;n.send(a.body||null);function o(){var t=[],i=[],a={},u;n.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,r,n){t.push(r=r.toLowerCase());i.push([r,n]);u=a[r];a[r]=u?"".concat(u,",").concat(n):n});return{ok:(n.status/100|0)==2,status:n.status,statusText:n.statusText,url:n.responseURL,clone:o,text:function e(){return Promise.resolve(n.responseText)},json:function e(){return Promise.resolve(n.responseText).then(JSON.parse)},blob:function e(){return Promise.resolve(new Blob([n.response]))},headers:{keys:function e(){return t},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,"+|").concat(r,"+))?(?:[+-]i|[+-]?(?:").concat(r,"+/").concat(r,"+|").concat(r,"+)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]+|".concat(float_stre,"|[+-]?[0-9]+))?(?:").concat(float_stre,"|[+-](?:[0-9]+/[0-9]+|[0-9]+))i");var float_re=new RegExp("^(#[ie])?".concat(float_stre,"$"),"i");function make_complex_match_re(e,r){var n=e==="x"?"(?!\\+|".concat(r,")"):"(?!\\.|".concat(r,")");var t="";if(e===""){t="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+(?![0-9]))(?:[eE][-+]?[0-9]+)?))"}return new RegExp("^((?:(?:".concat(t,"|[+-]?").concat(r,"+/").concat(r,"+(?!").concat(r,")|[+-]?").concat(r,"+)").concat(n,")?)(").concat(t,"|[+-]?").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),n=r[0],t=r[1],i=r[2];a[n]=make_complex_match_re(t,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 n=0;var t=e.length;while(n=55296&&i<=56319&&n1&&arguments[1]!==undefined$1?arguments[1]:10;var n=num_pre_parse(e);var t=n.number.split("/");var i=LRational({num:LNumber([t[0],n.radix||r]),denom:LNumber([t[1],n.radix||r])});if(n.inexact){return i.valueOf()}else{return i}}function parse_integer(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:10;var n=num_pre_parse(e);if(n.inexact){return LFloat(parseInt(n.number,n.radix||r))}return LNumber([n.number,n.radix||r])}function parse_character(e){var r=e.match(/#\\x([0-9a-f]+)$/i);var n;if(r){var t=parseInt(r[1],16);n=String.fromCodePoint(t)}else{r=e.match(/#\\(.+)$/);if(r){n=r[1]}}if(n){return LCharacter(n)}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 n=e.split("/");r=LRational({num:LNumber([n[0],i]),denom:LNumber([n[1],i])})}else if(e.match(float_re)){var t=parse_float(e);if(a.exact){return t.toRational()}return t}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 n;var t=a.number.match(complex_bare_match_re);if(i!==10&&t){n=t}else{n=a.number.match(complex_list_re[i])}var u,o;o=r(n[2]);if(n[1]){u=r(n[1])}else if(o instanceof LFloat){u=LFloat(0)}else{u=LNumber(0)}return LComplex({im:o,re:u})}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 n=parseInt(r[4],10);var t;var i=r[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var a=r[3]&&r[3].length;if(i0){return LNumber(a).mul(o)}}}n=LFloat(n);if(r.exact){return n.toRational()}return n}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 n={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 n[r]||r})}return new LSymbol(e)}function parse_argument(e){var r=e.match(re_re);if(r){return new RegExp(r[1],r[2])}else if(e.match(/^"[\s\S]*"$/)){return parse_string(e)}else if(e.match(char_re)){return parse_character(e)}else if(e.match(rational_re)){return parse_rational(e)}else if(e.match(complex_re)){return parse_complex(e)}else if(e.match(int_re)){return parse_integer(e)}else if(e.match(float_re)){return parse_float(e)}else if(e==="nil"){return nil}else if(["true","#t","#true"].includes(e)){return true}else if(["false","#f","#false"].includes(e)){return false}else if(e.match(/^#[iexobd]/)){throw new Error("Invalid numeric constant")}else{var n=e.match(/#\\(.+)/);if(n&&ucs2decode(n[1]).length===1){return parse_character(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 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 n=[];while(true){var t=r.peek(true);if(t===eof){break}n.push(t);r.skip()}return n}function multiline_formatter(e){var r=e.token,n=objectWithoutProperties(e,["token"]);if(r.match(/^"[\s\S]*"$/)&&r.match(/\n/)){var t=new RegExp("^ {1,"+(e.col+1)+"}","mg");r=r.replace(t,"")}return _objectSpread({token:r},n)}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(t){return function(){for(var e=arguments.length,r=new Array(e),n=0;n1&&arguments[1]!==undefined$1?arguments[1]:false;if(e instanceof LString){e=e.toString()}if(r){return tokens(e)}else{var n=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(n)}}function strip_s_comments(e){var r=0;var n=null;var t=[];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){e["catch"](function(){});this.__promise__=e}QuotedPromise.prototype.then=function(e){return new QuotedPromise(this.__promise__.then(e))};QuotedPromise.prototype["catch"]=function(e){return new QuotedPromise(this.__promise__["catch"](e))};QuotedPromise.prototype.valueOf=function(){return this.__promise__};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 n=this;var t=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:null;if(Array.isArray(r)){r.forEach(function(e){return n.off(e,t)})}else if(t===null){delete this._events[r]}else{this._events=this._events.filter(function(e){return e!==t})}},on:function e(r,n){var t=this;if(Array.isArray(r)){r.forEach(function(e){return t.on(e,n)})}else if(!this._events[r]){this._events[r]=[n]}else{this._events[r].push(n)}},trigger:function e(r){for(var n=arguments.length,t=new Array(n>1?n-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),n=r[0],t=r[1],i=r[2];specials.append(n,t,i)});var Lexer=function(){function _(e){var r=this;var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},t=n.whitespace,i=t===void 0?false:t;classCallCheck(this,_);Object.defineProperty(this,"__input__",{value:e.replace(/\r/g,""),enumerable:true});var a={};["_i","_whitespace","_col","_newline","_line","_state","_next","_token","_prev_char"].forEach(function(n){Object.defineProperty(r,n,{configurable:false,enumerable:false,get:function e(){return a[n]},set:function e(r){a[n]=r}})});this._whitespace=i;this._i=this._line=this._col=this._newline=0;this._state=this._next=this._token=null;this._prev_char=""}createClass(_,[{key:"get",value:function e(r){return this.__internal[r]}},{key:"set",value:function e(r,n){this.__internal[r]=n}},{key:"token",value:function e(){var r=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:false;if(r){var n=this._line;if(this._whitespace&&this._token==="\n"){--n}return{token:this._token,col:this._col,offset:this._i,line:n}}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 n=this.next_token();if(n){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 n=this._i;n=n){return eof}if(r+this._i>=n){return this.read_rest()}var t=this._i+r;var i=this.__input__.substring(this._i,t);var a=i.match(/\n/g);if(a){this._line+=a.length}this._i=t;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]:{},t=n.prev_char,i=n["char"],a=n.next_char;var u=slicedToArray(r,4),o=u[0],c=u[1],s=u[2],l=u[3];if(r.length!==5){throw new Error("Lexer: Invald rule of length ".concat(r.length))}if(!i.match(o)){return false}if(!match_or_null(c,t)){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 n=this._i,t=this.__input__.length;n2&&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,t,i,null,null]]}var a=[];for(var u=0,o=r.length;u1&&arguments[1]!==undefined$1?arguments[1]:{},n=r.env,t=r.meta,i=t===void 0?false:t,a=r.formatter,u=a===void 0?multiline_formatter:a;classCallCheck(this,o);if(e instanceof LString){e=e.toString()}this._formatter=u;this._meta=i;this.__lexer__=new Lexer(e);this.__env__=n}createClass(o,[{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 n;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:n=this.__lexer__.peek(true);if(!(n===eof)){r.next=4;break}return r.abrupt("return",eof);case 4:if(!this.is_comment(n.token)){r.next=7;break}this.skip();return r.abrupt("continue",0);case 7:if(!(n.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:n=this._formatter(n);if(!this._meta){r.next=20;break}return r.abrupt("return",n);case 20:return r.abrupt("return",n.token);case 21:case"end":return r.stop()}}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{key:"skip",value:function e(){this.__lexer__.skip()}},{key:"special",value:function e(r){return specials.names().includes(r)}},{key:"builtin",value:function e(r){return specials.builtin.includes(r)}},{key:"read",value:function(){var e=asyncToGenerator(regenerator.mark(function e(){var n;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:r.next=2;return this.peek();case 2:n=r.sent;this.skip();return r.abrupt("return",n);case 5:case"end":return r.stop()}}},e,this)}));function r(){return e.apply(this,arguments)}return r}()},{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 n,t,i,a;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:n=nil,t=n;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==="."&&n!==nil)){r.next=17;break}this.skip();r.next=14;return this.read_object();case 14:t.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(n===nil){n=a}else{t.cdr=a}t=a;case 25:r.next=1;break;case 27:return r.abrupt("return",n);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 n;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:r.next=2;return this.read();case 2:n=r.sent;if(!(n===eof)){r.next=5;break}throw new Error("Parser: Expected token eof found");case 5:return r.abrupt("return",parse_argument(n));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:"_eval",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 n,t,i,a,u,o,c;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:r.next=2;return this.peek();case 2:n=r.sent;if(!(n===eof)){r.next=5;break}return r.abrupt("return",n);case 5:if(!this.special(n)){r.next=35;break}t=specials.get(n);i=this.builtin(n);this.skip();r.next=11;return this.read_object();case 11:u=r.sent;if(i){r.next=22;break}o=this.__env__.get(t.symbol);if(!(typeof o==="function")){r.next=22;break}if(!is_literal(n)){r.next=19;break}return r.abrupt("return",o.call(this.__env__,u));case 19:if(!(u instanceof Pair)){r.next=21;break}return r.abrupt("return",o.apply(this.__env__,u.toArray(false)));case 21:throw new Error("Parser: Invalid parser extension "+"invocation ".concat(t.symbol));case 22:if(is_literal(n)){a=new Pair(t.symbol,new Pair(u,nil))}else{a=new Pair(t.symbol,u)}if(!i){r.next=25;break}return r.abrupt("return",a);case 25:if(!(o instanceof Macro)){r.next=34;break}r.next=28;return this._eval(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("Parser: invlid parser extension: ".concat(t.symbol));case 35:if(!this.is_open(n)){r.next=42;break}this.skip();r.next=39;return this.read_list();case 39:return r.abrupt("return",r.sent);case 42:r.next=44;return this.read_value();case 44:return r.abrupt("return",r.sent);case 45:case"end":return r.stop()}}},e,this)}));function r(){return e.apply(this,arguments)}return r}()}]);return o}();function parse(e,r){return _parse.apply(this,arguments)}function _parse(){_parse=wrapAsyncGenerator(regenerator.mark(function e(n,t){var i,a;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!t){if(global_env){t=global_env.get("**interaction-environment**",{throwError:false})}else{t=user_env}}i=new Parser(n,{env:t});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(r){var e=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:function(e){return e};var n=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:null;if(r instanceof Array){var t=r.filter(is_promise);if(t.length){return unpromise(Promise.all(r),function(e){if(Object.isFrozen(r)){Object.freeze(e)}return e},n)}return e(r)}if(is_plain_object(r)){var i=Object.keys(r);var a=i.map(function(e){return r[e]});var u=a.filter(is_promise);if(u.length){return unpromise(Promise.all(a),function(e){var t={};e.forEach(function(e,r){var n=i[r];t[n]=e});if(Object.isFrozen(r)){Object.freeze(t)}return t},n)}}if(is_promise(r)){var o=r.then(e);if(n===null){return o}else{return o["catch"](n)}}return e(r)}function uniterate_async(e){return _uniterate_async.apply(this,arguments)}function _uniterate_async(){_uniterate_async=asyncToGenerator(regenerator.mark(function e(n){var t,i,a,u,o,c,s,l;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:t=[];i=true;a=false;r.prev=3;o=asyncIterator(n);case 5:r.next=7;return o.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;t.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;u=r.t0;case 24:r.prev=24;r.prev=25;if(!(!i&&o["return"]!=null)){r.next=29;break}r.next=29;return o["return"]();case 29:r.prev=29;if(!a){r.next=32;break}throw u;case 32:return r.finish(29);case 33:return r.finish(24);case 34:return r.abrupt("return",t);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}}function doc(e,r,n,t){if(typeof e!=="string"){r=arguments[0];n=arguments[1];t=arguments[2];e=null}if(n){if(t){r.__doc__=n}else{r.__doc__=trim_lines(n)}}if(e){r.__name__=e}else if(r.name&&!r[__lambda__]){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 n=e.length;if(r<=0){throw Error("previousSexp: Invalid argument sexp = ".concat(r))}e:while(r--&&n>=0){var t=1;while(t>0){var i=e[--n];if(!i){break e}if(i==="("||i.token==="("){t--}else if(i===")"||i.token===")"){t++}}n--}return e.slice(n+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 n=(e[r+1]||{}).token;if(n){return n.length}}}return 0}function nested_pattern(e){return e instanceof Array||e instanceof Pattern}function match(e,r){return f(e,r)===r.length;function f(n,t){function e(){if(a<=0&&o<=0){return false}var e=n[a-1];if(!nested_pattern(e)){e=[e]}var r=n[a+1];if(r&&!nested_pattern(r)){r=[r]}return match(e,[t[o-1]])&&(!r||match(r,[t[o]]))}function r(){return n[a]===Symbol["for"]("symbol")&&!is_symbol_string(t[o])}function i(){var e=n[a+1];var r=t[o+1];if(e!==undefined$1&&r!==undefined$1){return f([e],[r])}}var a=0;var u={};for(var o=0;o0){continue}}else if(r()){return-1}}else if(n[a]instanceof Array){var l=f(n[a],t.slice(o));if(l===-1||l+o>t.length){return-1}o+=l-1;a++;continue}else{return-1}a++}if(n.length!==a){return-1}return t.length}}function Formatter(e){this.__code__=e.replace(/\r/g,"")}Formatter.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?(?:define(?:-values|-syntax|-macro)?|lambda|let*|let-env|try|catch|when|unless|while|syntax-rules|(let|letrec)(-syntax))$/],shift:{1:["&","#"]}}};Formatter.match=match;Formatter.prototype._options=function e(r){var n=Formatter.defaults;if(typeof r==="undefined"){return Object.assign({},n)}var t=r&&r.exceptions||{};var i=t.specials||[];var a=t.shift||{1:[]};return _objectSpread(_objectSpread(_objectSpread({},n),r),{},{exceptions:{specials:[].concat(toConsumableArray(n.exceptions.specials),toConsumableArray(i)),shift:_objectSpread(_objectSpread({},a),{},{1:[].concat(toConsumableArray(n.exceptions.shift[1]),toConsumableArray(a[1]))})}})};Formatter.prototype.indent=function e(r){var n=tokenize(this.__code__,true);return this._indent(n,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 n=_createForOfIteratorHelper(r),t;try{for(n.s();!(t=n.n()).done;){var i=t.value;if(a.match(i)){return true}}}catch(e){n.e(e)}finally{n.f()}}return false}if(r(e.exceptions.specials)){return e.indent}var n=e.exceptions.shift;for(var t=0,i=Object.entries(n);t0){t.offset=0}if(a.toString()===r.toString()&&balanced(a)){return t.offset+a[0].col}else if(a.length===1){return t.offset+a[0].col+1}else{var c=-1;if(u){var s=Formatter.exception_shift(u.token,t);if(s!==-1){c=s}}if(c===-1){c=Formatter.exception_shift(a[1].token,t)}if(c!==-1){return t.offset+a[0].col+c}else if(a[0].line3&&a[1].line===a[3].line){if(a[1].token==="("||a[1].token==="["){return t.offset+a[1].col}return t.offset+a[3].col}else if(a[0].line===a[1].line){return t.offset+t.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(e,r){this.pattern=e;this.flag=r}Pattern.prototype.toString=function(){return"#")};Formatter.Pattern=Pattern;Formatter.Ahead=Ahead;var p_o=/[[(]/;var p_e=/[\])]/;var not_p=/[^()[\]]/;var not_close=new Ahead(/[^)\]]/);var open=new Ahead(/[([]/);var glob=Symbol["for"]("*");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","syntax-rules");var non_def=/^(?!.*\b(?:[()[\]]|define|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),n=0;n0&&arguments[0]!==undefined$1?arguments[0]:true;var r=[];if(this.car instanceof Pair){if(e){r.push(this.car.toArray())}else{r.push(this.car)}}else{r.push(this.car.valueOf())}if(this.cdr instanceof Pair){r=r.concat(this.cdr.toArray())}return r};Pair.fromArray=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:true;var n=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:false;if(e instanceof Pair||n&&e instanceof Array&&e[__data__]){return e}if(r===false){var t=nil;for(var i=e.length;i--;){t=new Pair(e[i],t)}return t}if(e.length&&!(e instanceof Array)){e=toConsumableArray(e)}var a=nil;var u=e.length;while(u--){var o=e[u];if(o instanceof Array){o=Pair.fromArray(o,r,n)}else if(typeof o==="string"){o=LString(o)}else if(typeof o==="number"&&!Number.isNaN(o)){o=LNumber(o)}a=new Pair(o,a)}return a};Pair.prototype.toObject=function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:false;var r=this;var n={};while(true){if(r instanceof Pair&&r.car instanceof Pair){var t=r.car;var i=t.car;if(i instanceof LSymbol){i=i.__name__}if(i instanceof LString){i=i.valueOf()}var a=t.cdr;if(a instanceof Pair){a=a.toObject(e)}if(is_native(a)){if(!e){a=a.valueOf()}}n[i]=a;r=r.cdr}else{break}}return n};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 n=nil;while(true){if(r!==nil){n=e(n,r.car);r=r.cdr}else{break}}return n};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 n=e.cdr;e.cdr=r;r=e;e=n}return r};Pair.prototype.transform=function(t){function i(e){if(e instanceof Pair){if(e.replace){delete e.replace;return e}var r=t(e.car);if(r instanceof Pair){r=i(r)}var n=t(e.cdr);if(n instanceof Pair){n=i(n)}return new Pair(r,n)}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_1(e)==="object"&&e.constructor===Object}var props=Object.getOwnPropertyNames(Array.prototype);var array_methods=[];props.forEach(function(e){array_methods.push(Array[e],Array.prototype[e])});function is_array_method(e){e=unbind(e);return array_methods.includes(e)}function is_lips_function(e){return is_function(e)&&(e[__lambda__]||e.__doc__)}function user_repr(n){var e=n.constructor||Object;var t=is_plain_object(n);var i=is_function(n[Symbol.asyncIterator])||is_function(n[Symbol.iterator]);var a;if(repr.has(e)){a=repr.get(e)}else{repr.forEach(function(e,r){r=unbind(r);if(n.constructor===r&&(r===Object&&t&&!i||r!==Object)){a=e}})}return a}var str_mapping=new Map;[[Number.NEGATIVE_INFINITY,"-inf.0"],[Number.POSITIVE_INFINITY,"+inf.0"],[true,"#t"],[false,"#f"],[null,"null"],[undefined$1,"#"]].forEach(function(e){var r=slicedToArray(e,2),n=r[0],t=r[1];str_mapping.set(n,t)});function symbolize(n){if(n&&_typeof_1(n)==="object"){var t={};var e=Object.getOwnPropertySymbols(n);e.forEach(function(e){var r=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");t[r]=toString(n[e])});var r=Object.getOwnPropertyNames(n);r.forEach(function(e){var r=n[e];if(r&&_typeof_1(r)==="object"&&r.constructor===Object){t[e]=symbolize(r)}else{t[e]=toString(r)}});return t}return n}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)&&r[__lambda__]){if(e[__class__]&&r.hasOwnProperty("__name__")){var n=r.__name__;if(LString.isString(n)){n=n.toString();return"#")}return"#"}}if(e.hasOwnProperty("__name__")){var t=e.__name__;if(_typeof_1(t)==="symbol"){t=symbol_to_string(t)}if(typeof t==="string"){return"#")}}if(has_own_function(e,"toString")){return e.toString()}else if(e.name&&!e[__lambda__]){return"#")}else{return"#"}}function toString(e,r,n){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(str_mapping.has(e)){return str_mapping.get(e)}if(e instanceof Error){return e.message}if(e instanceof Pair){var t;if(!n){e.markCycles()}for(var i=arguments.length,a=new Array(i>3?i-3:0),u=3;u"}if(e===null){return"null"}if(_typeof_1(e)==="object"){if(is_function(e.toString)&&e.toString[__lambda__]){return e.toString().valueOf()}var f=e.constructor;if(!f){f=Object}var p;if(typeof f.__class__==="string"){p=f.__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")}}p=f.name}if(type(e)==="instance"&&!is_native_function(f)){p="instance"}if(is_iterator(e,Symbol.iterator)){if(p){return"#")}return"#"}if(is_iterator(e,Symbol.asyncIterator)){if(p){return"#")}return"#"}if(p!==""){return"#<"+p+">"}return"#"}if(typeof e!=="string"){return e.toString()}return e}function is_prototype(e){return e&&_typeof_1(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 u(e){if(!r.includes(e)){r.push(e)}}function o(e,r,n,t){if(n instanceof Pair){if(t.includes(n)){if(!a.includes(n)){a.push(n)}if(!e[__cycles__]){e[__cycles__]={}}e[__cycles__][r]=n;if(!i.includes(e)){i.push(e)}return true}}}var c=trampoline(function e(r,n){if(r instanceof Pair){delete r.ref;delete r[__cycles__];u(r);n.push(r);var t=o(r,"car",r.car,n);var i=o(r,"cdr",r.cdr,n);if(!t){c(r.car,n.slice())}if(!i){return new Thunk(function(){return e(r.cdr,n.slice())})}}});function n(e,r){if(e[__cycles__][r]instanceof Pair){var n=t.indexOf(e[__cycles__][r]);e[__cycles__][r]="#".concat(n,"#")}}c(e,[]);var t=r.filter(function(e){return a.includes(e)});t.forEach(function(e,r){e[__ref__]="#".concat(r,"=")});i.forEach(function(e){n(e,"car");n(e,"cdr")})}var pair_to_string=function(){var f=function e(r,n){var t=[];if(r[__ref__]){t.push(r[__ref__]+"(")}else if(!n){t.push("(")}return t};var p=function e(r,n){if(is_debug());if(!n||r[__ref__]){return[")"]}return[]};return trampoline(function e(r,n){var t=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:{};var i=t.nested,a=i===void 0?false:i,u=t.result,o=u===void 0?[]:u,c=t.cont,s=c===void 0?function(){o.push.apply(o,toConsumableArray(p(r,a)))}:c;o.push.apply(o,toConsumableArray(f(r,a)));var l;if(r[__cycles__]&&r[__cycles__].car){l=r[__cycles__].car}else{l=toString(r.car,n,true,{result:o,cont:s})}if(l!==undefined$1){o.push(l)}return new Thunk(function(){if(r.cdr instanceof Pair){if(r[__cycles__]&&r[__cycles__].cdr){o.push(" . ");o.push(r[__cycles__].cdr)}else{if(r.cdr[__ref__]){o.push(" . ")}else{o.push(" ")}return e(r.cdr,n,{nested:true,result:o,cont:s})}}else if(r.cdr!==nil){o.push(" . ");o.push(toString(r.cdr,n))}},s)})}();Pair.prototype.toString=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},n=r.nested,t=n===void 0?false:n;if(is_debug()){var i=[];pair_to_string(this,e,{result:i});return i.join("")}var a=[];if(this[__ref__]){a.push(this[__ref__]+"(")}else if(!t){a.push("(")}var u;if(this[__cycles__]&&this[__cycles__].car){u=this[__cycles__].car}else{u=toString(this.car,e,true)}if(u!==undefined$1){a.push(u)}if(this.cdr instanceof Pair){if(this[__cycles__]&&this[__cycles__].cdr){a.push(" . ");a.push(this[__cycles__].cdr)}else{if(this.cdr[__ref__]){a.push(" . ")}else{a.push(" ")}var o=this.cdr.toString(e,{nested:true});a.push(o)}}else if(this.cdr!==nil){a=a.concat([" . ",toString(this.cdr,e,true)])}if(!t||this[__ref__]){a.push(")")}return a.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};function abs(e){return e<0?-e:e}function seq_compare(e,r){var n=toArray(r),t=n[0],i=n.slice(1);while(i.length>0){var a=i,u=slicedToArray(a,1),o=u[0];if(!e(t,o)){return false}var c=i;var s=toArray(c);t=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 n;if(e.__type__===r.__type__){if(e.__type__==="complex"){n=e.__im__.__type__===r.__im__.__type__&&e.__re__.__type__===r.__re__.__type__}else{n=true}return n&&e.cmp(r)===0}return false}else if(typeof e==="number"){if(typeof r!=="number"){return false}e=LNumber(e);r=LNumber(r);return e.__type__===r.__type__&&e.cmp(r)===0}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 Math.ceil(e)}else{return Math.floor(e)}}}}();function Macro(e,r,n,t){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(n){if(t){this.__doc__=n}else{this.__doc__=trim_lines(n)}}this.__name__=e;this.__fn__=r}Macro.defmacro=function(e,r,n,t){var i=new Macro(e,r,n,t);i.__defmacro__=true;return i};Macro.prototype.invoke=function(e,r,n){var t=r.env,i=r.dynamic_scope,a=r.error;var u={dynamic_scope:i,error:a,macro_expand:n};var o=this.__fn__.call(t,e,u,this.__name__);return o};Macro.prototype.toString=function(){return"#")};var macro="define-macro";var recur_guard=-1e4;function macro_expand(a){return function(){var n=asyncToGenerator(regenerator.mark(function e(n,h){var t,d,i;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:i=function e(){i=asyncToGenerator(regenerator.mark(function e(n,t,i){var a,u,o,c,s,l,f,p,_;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!(n instanceof Pair&&n.car instanceof LSymbol)){r.next=26;break}if(!n[__data__]){r.next=3;break}return r.abrupt("return",n);case 3:a=i.get(n.car,{throwError:false});if(!(a instanceof Macro&&a.__defmacro__)){r.next=26;break}u=a instanceof Syntax?n:n.cdr;r.next=8;return a.invoke(u,_objectSpread(_objectSpread({},h),{},{env:i}),true);case 8:o=r.sent;if(!(a instanceof Syntax)){r.next=17;break}c=o,s=c.expr,l=c.scope;if(!(s instanceof Pair)){r.next=16;break}if(!(t!==-1&&t<=1||t")}return"#"};Syntax.className="syntax";function extract_patterns(e,r,D,w){var n=arguments.length>4&&arguments[4]!==undefined$1?arguments[4]:{};var L={"...":{symbols:{},lists:[]},symbols:{}};var x=n.expansion,F=n.define;function A(e){if(is_debug()){console.log(e)}}A(D);function E(e,r){var n=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:[];var t=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:false;A({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&&D.includes(e.valueOf())){var i=x.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,w)){A(">> 0");if(r===nil){A({pattern:e.toString()});if(e.car.car instanceof LSymbol){if(e.car.cdr instanceof Pair&&LSymbol.is(e.car.cdr.car,w)){var a=e.car.car.valueOf();var u=e.lastPair();if(LSymbol.is(u.car,w)){L["..."].symbols[a]=null;return true}else{return false}}var o=e.car.car.valueOf();if(L["..."].symbols[o]){throw new Error("syntax: named ellipsis can only "+"appear onces")}L["..."].symbols[o]=r}}}if(e instanceof Pair&&e.cdr instanceof Pair&&LSymbol.is(e.cdr.car,w)){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(!E(e.cdr.cdr,f,n,t)){return false}}}if(e.car instanceof LSymbol){var p=e.car.__name__;if(L["..."].symbols[p]&&!n.includes(p)&&!t){throw new Error("syntax: named ellipsis can only appear onces")}A(">> 1");if(r===nil){A(">> 2");if(t){A("NIL");L["..."].symbols[p]=nil}else{A("NULL");L["..."].symbols[p]=null}}else if(r instanceof Pair&&(r.car instanceof Pair||r.car===nil)){A(">> 3 "+t);if(t){if(L["..."].symbols[p]){var _=L["..."].symbols[p];if(_===nil){_=new Pair(nil,new Pair(r,nil))}else{_=_.append(new Pair(r,nil))}L["..."].symbols[p]=_}else{L["..."].symbols[p]=new Pair(r,nil)}}else{A(">> 4");L["..."].symbols[p]=new Pair(r,nil)}}else{A(">> 6");if(r instanceof Pair){A(">> 7 "+t);n.push(p);if(!L["..."].symbols[p]){L["..."].symbols[p]=new Pair(r,nil)}else{var h=L["..."].symbols[p];L["..."].symbols[p]=h.append(new Pair(r,nil))}A({IIIIII:L["..."].symbols[p].toString()})}else{A(">> 8");return false}}return true}else if(e.car instanceof Pair){var d=toConsumableArray(n);if(r===nil){A(">> 9");L["..."].lists.push(nil);return true}A(">> 10");var m=r;while(m instanceof Pair){if(!E(e.car,m.car,d,true)){return false}m=m.cdr}return true}return false}if(e instanceof LSymbol){if(LSymbol.is(e,w)){throw new Error("syntax: invalid usage of ellipsis")}A(">> 11");var v=e.__name__;if(D.includes(v)){return true}A({name:v,ellipsis:t});if(t){L["..."].symbols[v]=L["..."].symbols[v]||[];L["..."].symbols[v].push(r)}L.symbols[v]=r;if(!L.symbols[v]);return true}if(e instanceof Pair&&r instanceof Pair){A(">> 12");A({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(!E(e.car,r.car,n,t)){return false}A(">> 12 | 1");var b=e.cdr.valueOf();if(!(b in L.symbols)){L.symbols[b]=nil}b=e.car.valueOf();if(!(b in L.symbols)){L.symbols[b]=r.car}return true}}A({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,w)&&e.cdr.cdr.cdr instanceof Pair&&!LSymbol.is(e.cdr.cdr.cdr.car,w)&&E(e.car,r.car,n,t)&&E(e.cdr.cdr.cdr,r.cdr,n,t)){var g=e.cdr.car.__name__;A({pattern:e.car.toString(),code:r.car.toString(),name:g});if(D.includes(g)){return true}L["..."].symbols[g]=null;return true}A("recur");if(E(e.car,r.car,n,t)&&E(e.cdr,r.cdr,n,t)){return true}}else if(e===nil&&(r===nil||r===undefined$1)){return true}else if(e.car instanceof Pair&&LSymbol.is(e.car.car,w)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(E(e,r)){return L}}function clear_gensyms(e,i){function a(r){if(r instanceof Pair){if(!i.length){return r}var e=a(r.car);var n=a(r.cdr);return new Pair(e,n)}else if(r instanceof LSymbol){var t=i.find(function(e){return e.gensym===r});if(t){return LSymbol(t.name)}return r}else{return r}}return a(e)}function transform_syntax(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:{};var A=e.bindings,r=e.expr,E=e.scope,u=e.symbols,a=e.names,S=e.ellipsis;var o={};function c(e){if(e instanceof LSymbol){return true}return["string","symbol"].includes(_typeof_1(e))}function C(e){if(!c(e)){var r=type(e);throw new Error("syntax: internal error, need symbol got ".concat(r))}var n=e.valueOf();if(n===S){throw new Error("syntax: internal error, ellipis not transformed")}var t=_typeof_1(n);if(["string","symbol"].includes(t)){if(n in A.symbols){return A.symbols[n]}else if(t==="string"&&n.match(/\./)){var i=n.split(".");var a=i[0];if(a in A.symbols){return Pair.fromArray([LSymbol("."),A.symbols[a]].concat(i.slice(1).map(function(e){return LString(e)})))}}}if(u.includes(n)){return LSymbol(n)}return s(n)}function k(e){if(is_debug()){console.log(e)}}function s(e){if(!o[e]){var r=E.ref(e);var n=gensym(e);if(r){var t=E.get(e);E.set(n,t)}else{var i=E.get(e,{throwError:false});if(typeof i!=="undefined"){E.set(n,i)}}a.push({name:e,gensym:n});o[e]=n}return o[e]}function P(e,r,n){var t=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:function(){};var i=n.nested;k(" ==> "+e.toString(true));k(r);if(e instanceof LSymbol){var a=e.valueOf();k("[t 1");if(r[a]){if(r[a]instanceof Pair){var u=r[a],o=u.car,c=u.cdr;if(i){var s=o.car,l=o.cdr;if(l!==nil){t(a,new Pair(l,nil))}return s}if(c!==nil){t(a,c)}return o}else if(r[a]instanceof Array){t(a,r[a].slice(1));return r[a][0]}}return C(a)}if(e instanceof Pair){if(e.car instanceof LSymbol&&e.cdr instanceof Pair&&LSymbol.is(e.cdr.car,S)){k("[t 2");var f=e.car.valueOf();var p=r[f];k({expr:e.toString(true),name:f,bindings:r,item:p});if(p===null){return}else if(p){k({b:r[f].toString()});if(p instanceof Pair){k("[t 2 Pair "+i);k({______:p.toString()});var _=p.car,h=p.cdr;if(i){if(h!==nil){k("|| next 1");t(f,h)}k({car:_.toString()});return _}else{if(_.cdr!==nil){k("|| next 2");t(f,new Pair(_.cdr,h))}k({car:_.car.toString()});return _.car}}else if(p instanceof Array){k("[t 2 Array "+i);if(i){t(f,p.slice(1));return Pair.fromArray(p)}else{var d=p.slice(1);if(d.length){t(f,d)}return p[0]}}else{return p}}}k("[t 3 recur "+e.toString());var m=P(e.car,r,n,t);var v=P(e.cdr,r,n,t);return new Pair(m,v)}return e}function N(r,n){var e=Object.values(r);var t=Object.getOwnPropertySymbols(r);if(t.length){e.push.apply(e,toConsumableArray(t.map(function(e){return r[e]})))}return e.length&&e.every(function(e){if(e===null){return!n}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;k("traverse>> "+i.toString());if(i instanceof Pair){if(!r&&i.car instanceof Pair&&LSymbol.is(i.car.car,S)){return B(i.car.cdr,{disabled:true})}if(i.cdr instanceof Pair&&LSymbol.is(i.cdr.car,S)&&!r){k(">> 1");var n=A["..."].symbols;var t=Object.values(n);if(t.length&&t.every(function(e){return e===null})){return B(i.cdr.cdr,{disabled:r})}var a=O(n);var u=i.car instanceof LSymbol&&LSymbol.is(i.cdr.cdr.car,S);if(i.car instanceof Pair||u){if(A["..."].lists[0]===nil){return nil}var o=i.car;if(u){o=new Pair(i.car,new Pair(i.cdr.car,nil))}k(">> 2");var c;if(a.length){k(">> 2 (a)");var s=_objectSpread({},n);c=nil;var l=function e(){if(!N(s)){return"break"}var t={};var r=function e(r,n){t[r]=n};var n=P(o,s,{nested:true},r);if(n!==undefined$1){if(u){if(c===nil){c=n}else{c=c.append(n)}}else{c=new Pair(n,c)}}s=t};while(true){var f=l();if(f==="break")break}if(c!==nil&&!u){c=c.reverse()}if(i.cdr.cdr!==nil&&!LSymbol.is(i.cdr.cdr.car,S)){var p=B(i.cdr.cdr,{disabled:r});return c.append(p)}return c}else{k(">> 3");var _=P(i.car,n,{nested:true});if(_){return new Pair(_,nil)}return nil}}else if(i.car instanceof LSymbol){k(">> 4");if(LSymbol.is(i.cdr.cdr.car,S)){k(">> 4 (a)")}else{k(">> 4 (b)")}var h=i.car.__name__;var d=defineProperty({},h,n[h]);var m=n[h]===null;var v=nil;var y=function e(){if(!N(d,true)){k({bind:d});return"break"}var t={};var r=function e(r,n){t[r]=n;if(is_debug()){console.log({NEWBIND:t[r].toString()})}};var n=P(i,d,{nested:false},r);k({value:n.toString()});if(typeof n!=="undefined"){v=new Pair(n,v)}d=t};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}k("<<<< 1");v.append(g)}}k("<<<< 2");return v}}var D=B(i.car,{disabled:r});var w;var L;if(i.car instanceof LSymbol){var x=E.get(i.car,{throwError:false});L=x instanceof Macro&&x.__name__==="syntax-rules"}if(L){if(i.cdr.car instanceof LSymbol){w=new Pair(B(i.cdr.car,{disabled:r}),new Pair(i.cdr.cdr.car,B(i.cdr.cdr.cdr,{disabled:r})))}else{w=new Pair(i.cdr.car,B(i.cdr.cdr,{disabled:r}))}}else{w=B(i.cdr,{disabled:r})}k({a:true,car:toString(i.car),cdr:toString(i.cdr),head:toString(D),rest:toString(w)});return new Pair(D,w)}if(i instanceof LSymbol){if(r&&LSymbol.is(i,S)){return i}var F=C(i);if(typeof F!=="undefined"){return F}}return i}return B(r,{})}function is_null(e){return typeof e==="undefined"||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&&typeof e!=="undefined"&&is_function(e.then)}function box(e){switch(_typeof_1(e)){case"string":return LString(e);case"number":if(!Number.isNaN(e)){return LNumber(e)}}return e}function map_object(t,i){var e=Object.getOwnPropertyNames(t);var r=Object.getOwnPropertySymbols(t);e.concat(r).forEach(function(e){var r=i(t[e]);var n=Object.getOwnPropertyDescriptor(t,e);if(!n||n.writable&&t[e]!==r){t[e]=r}});return t}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(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(r,e){if(r[Symbol["for"]("__bound__")]){return r}var n=r.bind(e);var t=Object.getOwnPropertyNames(r).filter(filter_fn_names);t.forEach(function(e){try{n[e]=r[e]}catch(e){}});hidden_prop(n,"__fn__",r);hidden_prop(n,"__context__",e);hidden_prop(n,"__bound__",true);if(is_native_function(r)){hidden_prop(n,"__native__",true)}if(is_plain_object(e)&&r[__lambda__]){hidden_prop(n,"__method__",true)}n.valueOf=function(){return r};return n}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,n){Object.defineProperty(e,Symbol["for"](r),{get:function e(){return n},set:function e(){},configurable:false,enumerable:false})}function setFnLength(r,n){try{Object.defineProperty(r,"length",{get:function e(){return n}});return r}catch(e){var t=new Array(n).fill(0).map(function(e,r){return"a"+r}).join(",");var i=new Function("f","return function(".concat(t,") {\n return f.apply(this, arguments);\n };"));return i(r)}}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 h;switch(e){case Symbol["for"]("letrec"):h="letrec";break;case Symbol["for"]("let"):h="let";break;case Symbol["for"]("let*"):h="let*";break;default:throw new Error("Invalid let_macro value")}return Macro.defmacro(h,function(r,e){var a=e.dynamic_scope,u=e.error,n=e.macro_expand;var o;if(r.car instanceof LSymbol){if(!(r.cdr.car instanceof Pair||r.cdr.car===nil)){throw new Error("let require list of pairs")}var t;if(r.cdr.car===nil){o=nil;t=nil}else{t=r.cdr.car.map(function(e){return e.car});o=r.cdr.car.map(function(e){return e.cdr.car})}return Pair.fromArray([LSymbol("letrec"),[[r.car,Pair(LSymbol("lambda"),Pair(t,r.cdr.cdr))]],Pair(r.car,o)])}else if(n){return}var c=this;o=global_env.get("list->array")(r.car);var s=c.inherit(h);var l,f;if(h==="let*"){f=s}else if(h==="let"){l=[]}var p=0;function _(){var e=new Pair(new LSymbol("begin"),r.cdr);return evaluate(e,{env:s,dynamic_scope:a,error:u})}return function r(){var n=o[p++];if(a){a=h==="let*"?s:c}if(!n){if(l&&l.length){var e=l.map(function(e){return e.value});var t=e.filter(is_promise);if(t.length){return Promise.all(e).then(function(e){for(var r=0,n=e.length;r1&&arguments[1]!==undefined$1?arguments[1]:{},n=r.dynamic_scope,t=r.error;var i=this;if(n){n=this}var a=e;var u=[];while(a instanceof Pair){u.push(evaluate(a.car,{env:i,dynamic_scope:n,error:t}));a=a.cdr}var o=u.filter(is_promise).length;if(o){return Promise.all(u).then(c.bind(this))}else{return c.call(this,u)}})}function guardMathCall(e){for(var r=arguments.length,n=new Array(r>1?r-1:0),t=1;t2?t-2:0),a=2;a1&&arguments[1]!==undefined$1?arguments[1]:null;return function(){for(var e=arguments.length,r=new Array(e),n=0;n1?e-1:0),n=1;n=u){return a.apply(this,t)}else{return i}}return i.apply(this,arguments)}}function limit(t,i){typecheck("limit",i,"function",2);return function(){for(var e=arguments.length,r=new Array(e),n=0;n1){e=e.toLowerCase();if(LCharacter.__names__[e]){this.__name__=e;this.__char__=LCharacter.__names__[e]}else{throw new Error("Internal: Unknown named character")}}else{this.__char__=e;var r=LCharacter.__rev_names__[e];if(r){this.__name__=r}}}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=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(t){return function(){for(var e=arguments.length,r=new Array(e),n=0;n0){n.push(this.__string__.substring(0,e))}n.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 n=LNumber.getType(e);if(LNumber.types[n]){return LNumber.types[n](e,r)}var t=e instanceof Array&&LString.isString(e[0])&&LNumber.isNumber(e[1]);if(e instanceof LNumber){return LNumber(e.value)}if(!LNumber.isNumber(e)&&!t){throw new Error("You can't create LNumber from ".concat(type(e)))}if(e===null){e=0}var i;if(t){var a=e,u=slicedToArray(a,2),o=u[0],c=u[1];if(o instanceof LString){o=o.valueOf()}if(c instanceof LNumber){c=c.valueOf()}var s=o.match(/^([+-])/);var l=false;if(s){o=o.replace(/^[+-]/,"");if(s[1]==="-"){l=true}}}if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(t){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 p=BigInt(c);i=toConsumableArray(o).map(function(e,r){return BigInt(parseInt(e,c))*Math.pow(p,BigInt(r))}).reduce(function(e,r){return e+r})}else{i=BigInt(f+o)}}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(t){this.value=parseInt(o,c)}else{this.value=e}}LNumber.types={float:function e(r){var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;return new LFloat(r,n)},complex:function e(r){var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;if(!LNumber.isComplex(r)){r={im:0,re:r}}return new LComplex(r,n)},rational:function e(r){var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;if(!LNumber.isRational(r)){r={num:r,denom:1}}return new LRational(r,n)}};LNumber.prototype.gcd=function(e){var r=this.abs();e=e.abs();if(e.cmp(r)===1){var n=r;r=e;e=n}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||!Number.isNaN(e)&&LNumber.isNative(e)||LNumber.isBN(e)};LNumber.isComplex=function(e){var r=e instanceof LComplex||LNumber.isNumber(e.im)&&LNumber.isNumber(e.re);return r};LNumber.isRational=function(e){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=LNumber.prototype.toJSON=function(e){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,n){return[r,n]};return{bigint:{bigint:e,float:function e(r,n){return[LFloat(r.valueOf()),n]},rational:function e(r,n){return[{num:r,denom:1},n]},complex:function e(r,n){return[{im:0,re:r},n]}},float:{bigint:function e(r,n){return[r,n&&LFloat(n.valueOf())]},float:e,rational:function e(r,n){return[r,n&&LFloat(n.valueOf())]},complex:function e(r,n){return[{re:r,im:LFloat(0)},n]}},complex:{bigint:r("bigint"),float:r("float"),rational:r("rational"),complex:function e(r,n){var t=LNumber.coerce(r.__re__,n.__re__),i=slicedToArray(t,2),a=i[0],u=i[1];var o=LNumber.coerce(r.__im__,n.__im__),c=slicedToArray(o,2),s=c[0],l=c[1];return[{im:s,re:a},{im:l,re:u}]}},rational:{bigint:function e(r,n){return[r,n&&{num:n,denom:1}]},float:function e(r,n){return[LFloat(r.valueOf()),n]},rational:e,complex:function e(r,n){return[{im:coerce(r.__type__,n.__im__.__type__,0),re:coerce(r.__type__,n.__re__.__type__,r)},{im:coerce(r.__type__,n.__im__.__type__,n.__im__),re:coerce(r.__type__,n.__re__.__type__,n.__re__)}]}}};function r(n){return function(e,r){return[{im:coerce(n,e.__im__.__type__,e.__im__),re:coerce(n,e.__re__.__type__,e.__re__)},{im:coerce(n,e.__im__.__type__,0),re:coerce(n,r.__type__,r)}]}}}();function coerce(e,r,n){return matrix[e][r](n)[0]}LNumber.coerce=function(e,r){function n(e){if(e==="integer"){return"bigint"}return e}var t=n(LNumber.getType(e));var i=n(LNumber.getType(r));if(!matrix[t]){throw new Error("LNumber::coerce unknown lhs type ".concat(t))}else if(!matrix[t][i]){throw new Error("LNumber::coerce unknown rhs type ".concat(i))}return matrix[t][i](e,r).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,n){return r*n},"+":function e(r,n){return r+n},"-":function e(r,n){if(typeof n==="undefined"){return-r}return r-n},"/":function e(r,n){return r/n},"%":function e(r,n){return r%n},"|":function e(r,n){return r|n},"&":function e(r,n){return r&n},"~":function e(r){return~r},">>":function e(r,n){return r>>n},"<<":function e(r,n){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 n=e.im instanceof LNumber?e.im:LNumber(e.im);var t=e.re instanceof LNumber?e.re:LNumber(e.re);this.__im__=n;this.__re__=t;this.__type__="complex"}LComplex.prototype=Object.create(LNumber.prototype);LComplex.prototype.constructor=LComplex;LComplex.prototype.toRational=function(e){if(LNumber.isFloat(this.__im__)&&LNumber.isFloat(this.__re__)){var r=LFloat(this.__im__).toRational(e);var n=LFloat(this.__re__).toRational(e);return LComplex({im:r,re:n})}return this};LComplex.prototype.add=function(e){return this.complex_op(e,function(e,r,n,t){return{re:e.add(r),im:n.add(t)}})};LComplex.prototype.factor=function(){if(this.__im__ instanceof LFloat||this.__im__ instanceof LFloat){var e=this.__re__,r=this.__im__;var n,t;if(e instanceof LFloat){n=e.toRational().mul(e.toRational())}else{n=e.mul(e)}if(r instanceof LFloat){t=r.toRational().mul(r.toRational())}else{t=r.mul(r)}return n.add(t)}else{return this.__re__.mul(this.__re__).add(this.__im__.mul(this.__im__))}};LComplex.prototype.modulus=function(){return this.factor().sqrt()};LComplex.prototype.sqrt=function(){var e=this.modulus();var r,n;if(e.cmp(0)===0){r=n=e}else if(this.__re__.cmp(0)===1){r=LFloat(.5).mul(e.add(this.__re__)).sqrt();n=this.__im__.div(r).div(2)}else{n=LFloat(.5).mul(e.sub(this.__re__)).sqrt();if(this.__im__.cmp(0)===-1){n=n.sub()}r=this.__im__.div(n).div(2)}return LComplex({im:n,re:r})};LComplex.prototype.div=function(e){if(LNumber.isNumber(e)&&!LNumber.isComplex(e)){e=LComplex({im:0,re:e})}else if(!LNumber.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var r=this.coerce(e),n=slicedToArray(r,2),t=n[0],i=n[1];var a=LComplex({re:i.__re__,im:i.__im__.sub()});var u=i.factor().valueOf();var o=t.mul(a);var c=o.__re__.op("/",u);var s=o.__im__.op("/",u);return LComplex({re:c,im:s})};LComplex.prototype.sub=function(e){return this.complex_op(e,function(e,r,n,t){return{re:e.sub(r),im:n.add(t)}})};LComplex.prototype.mul=function(e){return this.complex_op(e,function(e,r,n,t){var i={re:e.mul(r).sub(n.mul(t)),im:e.mul(t).add(r.mul(n))};return i})};LComplex.prototype.complex_op=function(e,r){if(LNumber.isNumber(e)&&!LNumber.isComplex(e)){if(!(e instanceof LNumber)){e=LNumber(e)}var n=e.asType(0);e={__im__:n,__re__:e}}else if(!LNumber.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var t=e.__re__ instanceof LNumber?e.__re__:this.__re__.asType(e.__re__);var i=e.__im__ instanceof LNumber?e.__im__:this.__im__.asType(e.__im__);var a=r(this.__re__,t,this.__im__,i);if("im"in a&&"re"in a){var u=LComplex(a,true);return u}return a};LComplex._op={"+":"add","-":"sub","*":"mul","/":"div"};LComplex.prototype._op=function(e,r){var n=LComplex._op[e];return this[n](r)};LComplex.prototype.cmp=function(e){var r=this.coerce(e),n=slicedToArray(r,2),t=n[0],i=n[1];var a=t.__re__.coerce(i.__re__),u=slicedToArray(a,2),o=u[0],c=u[1];var s=o.cmp(c);if(s!==0){return s}else{var l=t.__im__.coerce(i.__im__),f=slicedToArray(l,2),p=f[0],_=f[1];return p.cmp(_)}};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=[this.__re__.toString()]}else{e=[]}e.push(this.__im__.cmp(0)<0?"-":"+");e.push(this.__im__.toString().replace(/^-/,""));e.push("i");return e.join("")};function 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"){this.value=e;this.__type__="float"}}LFloat.prototype=Object.create(LNumber.prototype);LFloat.prototype.constructor=LFloat;LFloat.prototype.toString=function(){var e=this.value.toString();if(!LNumber.isFloat(this.value)&&!e.match(/e/i)){return e+".0"}return e.replace(/^([0-9]+)e/,"$1.0e")};LFloat.prototype._op=function(e,r){if(r instanceof LNumber){r=r.value}var n=LNumber._ops[e];if(e==="/"&&this.value===0&&r===0){return NaN}return LFloat(n(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(t){return function(e){var r=function e(t,r,n){var i=function e(r,n){return n0){i=simplest_rational2(t,n)}else if(t.cmp(n)<=0){i=n}else if(n.cmp(0)>0){i=simplest_rational2(n,t)}else if(r.cmp(0)<0){i=LNumber(simplest_rational2(t.sub(),n.sub())).sub()}else{i=LNumber(0)}if(LNumber.isFloat(r)||LNumber.isFloat(e)){return LFloat(i)}return i}function simplest_rational2(e,r){var n=LNumber(e).floor();var t=LNumber(r).floor();if(e.cmp(n)<1){return n}else if(n.cmp(t)===0){var i=LNumber(1).div(r.sub(t));var a=LNumber(1).div(e.sub(n));return n.add(LNumber(1).div(simplest_rational2(i,a)))}else{return n.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 n=LNumber(e.num);var t=LNumber(e.denom);if(!r&&t.cmp(0)!==0){var i=n.op("%",t).cmp(0)===0;if(i){return LNumber(n.div(t))}}this.num=n;this.denom=t;this.__type__="rational"}LRational.prototype=Object.create(LNumber.prototype);LRational.prototype.constructor=LRational;LRational.prototype.pow=function(e){var r=e.cmp(0);if(r===0){return LNumber(1)}if(r===-1){e=e.sub();var n=this.denom.pow(e);var t=this.num.pow(e);return LRational({num:n,denom:t})}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=(readOnlyError("num"),e.toRational())}if(r instanceof LFloat){r=(readOnlyError("denom"),r.toRational())}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,n;if(e.cmp(1)!==0){r=this.num.div(e);if(r instanceof LRational){r=LNumber(r.valueOf(true))}n=this.denom.div(e);if(n instanceof LRational){n=LNumber(n.valueOf(true))}}else{r=this.num;n=this.denom}var t=this.cmp(0)<0;if(t){if(r.abs().cmp(n.abs())===0){return r.toString()}}else if(r.cmp(n)===0){return r.toString()}return r.toString()+"/"+n.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 n=this.denom.mul(e.denom);return LRational({num:r,denom:n})}var t=LNumber.coerce(this,e),i=slicedToArray(t,2),a=i[0],u=i[1];return a.mul(u)};LRational.prototype.div=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=this.num.mul(e.denom);var n=this.denom.mul(e.num);return LRational({num:r,denom:n})}var t=LNumber.coerce(this,e),i=slicedToArray(t,2),a=i[0],u=i[1];var o=a.div(u);return o};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 n=e.denom;return this.add(LRational({num:r,denom:n}))}if(!(e instanceof LNumber)){e=LNumber(e).sub()}else{e=e.sub()}var t=LNumber.coerce(this,e),i=slicedToArray(t,2),a=i[0],u=i[1];return a.add(u)};LRational.prototype.add=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=this.denom;var n=e.denom;var t=this.num;var i=e.num;var a,u;if(r!==n){u=n.mul(t).add(i.mul(r));a=r.mul(n)}else{u=t.add(i);a=r}return LRational({num:u,denom:a})}if(LNumber.isFloat(e)){return LFloat(this.valueOf()).add(e)}var o=LNumber.coerce(this,e),c=slicedToArray(o,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.value=e;this._native=r;this.__type__="bigint"}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._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 n=LNumber._ops[e](this.value,r.value);if(e==="/"){var t=this.op("%",r).cmp(0)===0;if(t){return LNumber(n)}return LRational({num:this,denom:r})}return LBigInteger(n,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};function InputPort(e){var t=this;if(typeof this!=="undefined"&&!(this instanceof InputPort)||typeof this==="undefined"){return new InputPort(e)}typecheck("InputPort",e,"function");this._read=e;this._with_parser=this._with_init_parser.bind(this,asyncToGenerator(regenerator.mark(function e(){var n;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(t.char_ready()){r.next=5;break}r.next=3;return t._read();case 3:n=r.sent;t.__parser__=new Parser(n,{env:t});case 5:return r.abrupt("return",t.__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 n=LNumber.getType(r);typeErrorMessage("read-string",n,"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(o,c){var s=this;return function(){var e=asyncToGenerator(regenerator.mark(function e(){var n,t,i,a,u=arguments;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:r.next=2;return o.call(s);case 2:n=r.sent;for(t=u.length,i=new Array(t),a=0;a"};function OutputPort(e){if(typeof this!=="undefined"&&!(this instanceof OutputPort)||typeof this==="undefined"){return new OutputPort(e)}typecheck("OutputPort",e,"function");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 n=this;if(typeof this!=="undefined"&&!(this instanceof OutputStringPort)||typeof this==="undefined"){return new OutputStringPort(r)}typecheck("OutputStringPort",r,"function");this._buffer=[];this.write=function(e){if(!LString.isString(e)){e=r(e)}else{e=e.valueOf()}n._buffer.push(e)}}OutputStringPort.prototype=Object.create(OutputPort.prototype);OutputStringPort.prototype.toString=function(){return"#>"};OutputStringPort.prototype.getString=function(){return this._buffer.map(function(e){return e.valueOf()}).join("")};OutputStringPort.prototype.constructor=OutputStringPort;function OutputFilePort(e,r){var n=this;if(typeof this!=="undefined"&&!(this instanceof OutputFilePort)||typeof this==="undefined"){return new OutputFilePort(e,r)}typecheck("OutputFilePort",e,"string");this._filename=e;this._fd=r.valueOf();this.write=function(e){if(!LString.isString(e)){e=toString(e)}else{e=e.valueOf()}root.fs.write(n._fd,e,function(){})}}OutputFilePort.prototype=Object.create(OutputPort.prototype);OutputFilePort.prototype.constructor=OutputFilePort;OutputFilePort.prototype.close=function(){var t=this;return new Promise(function(r,n){root.fs.close(t._fd,function(e){if(e){n(e)}else{t._fd=null;OutputPort.prototype.close.call(t);r()}})})};OutputFilePort.prototype.toString=function(){return"#")};function InputStringPort(e,r){var n=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(!n.__parser__){n.__parser__=new Parser(e,{env:r})}return n.__parser__});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 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");this.__filename__=r}InputFilePort.prototype=Object.create(InputStringPort.prototype);InputFilePort.prototype.constructor=InputFilePort;InputFilePort.prototype.toString=function(){return"#")};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]:{},n=r.stderr,t=r.stdin,i=r.stdout,a=objectWithoutProperties(r,["stderr","stdin","stdout"]);if(typeof this!=="undefined"&&!(this instanceof Interpreter)||typeof this==="undefined"){return new Interpreter(e,_objectSpread({stdin:t,stdout:i,stderr:n},a))}if(typeof e==="undefined"){e="anonymous"}this.__env__=user_env.inherit(e,a);var u="**interaction-environment-defaults**";this.set(u,get_props(a).concat(u));var o=internal_env.inherit("internal-".concat(e));if(is_port(t)){o.set("stdin",t)}if(is_port(n)){o.set("stderr",n)}if(is_port(i)){o.set("stdout",i)}this.constant("**internal-env**",o);global_env.set("**interaction-environment**",this.__env__)}Interpreter.prototype.exec=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;var n=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:null;typecheck("Interpreter::exec",e,"string",1);typecheck("Interpreter::exec",r,"boolean",2);global_env.set("**interaction-environment**",this.__env__);if(n===null){n=this.__env__}return exec(e,n,r?n: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 Environment(e,r,n){if(arguments.length===1){if(_typeof_1(arguments[0])==="object"){e=arguments[0];r=null}else if(typeof arguments[0]==="string"){e={};r={};n=arguments[0]}}this.__docs__=new Map;this.__env__=e;this.__parent__=r;this.__name__=n||"anonymous"}Environment.prototype.list=function(){return get_props(this.__env__)};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_1(e)==="object"){r=e}if(!e||_typeof_1(e)==="object"){e="child of "+(this.__name__||"unknown")}return new Environment(r||{},this,e)};Environment.prototype.doc=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:null;if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}if(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 t=this.inherit("__frame__");t.set("parent.frame",doc("parent.frame",function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:1;e=e.valueOf();var r=t.__parent__;if(!(r instanceof Environment)){return nil}if(e<=0){return r}var n=r.get("parent.frame");return n(e-1)},global_env.__env__["parent.frame"].__doc__));r.callee=e;t.set("arguments",r);return t};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 n={};Object.keys(this.__env__).forEach(function(e){n[e]=r.__env__[e]});return new Environment(n,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 n=r.throwError,t=n===void 0?true:n;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 u=i.split(".").filter(Boolean);if(u.length>0){var o=toArray(u),c=o[0],s=o.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(t){throw new Error("Unbound variable `"+i.toString()+"'")}};Environment.prototype.set=function(e,r){var n=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(n){this.doc(e,n)}return this};Environment.prototype.constant=function(r,e){var n=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 t=arguments[0];Object.keys(t).forEach(function(e){n.constant(r,t[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(function e(r){for(var n=arguments.length,t=new Array(n>1?n-1:0),i=1;i1?n-1:0),i=1;it.length){throw new Error("Not enough arguments")}var o=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 n=t[o++];if(r==="a"){return c(n)}else{return c(n,true)}}});u=r.match(/~([\S])/);if(u){throw new Error("format: Unrecognized escape seqence ".concat(u[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(function e(r){var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:null;if(n===null){n=internal(this,"stdout")}var t=global_env.get("repr")(r);n.write.call(global_env,t)},"(display arg [port])\n\n Function send string to standard output or provied port."),error:doc(function e(){var r=internal(this,"stderr");var n=global_env.get("repr");for(var t=arguments.length,i=new Array(t),a=0;a1&&arguments[1]!==undefined$1?arguments[1]:{},n=r.dynamic_scope,t=r.error;if(n){n=this}var i=this;var u;var o=evaluate(e.cdr.car,{env:this,dynamic_scope:n,error:t});o=resolve_promises(o);function c(r,n,t){if(is_promise(r)){return r.then(function(e){return c(r,e,t)})}if(is_promise(n)){return n.then(function(e){return c(r,e,t)})}if(is_promise(t)){return t.then(function(e){return c(r,n,e)})}i.get("set-obj!").call(i,r,n,t);return t}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:n,error:t});var p=evaluate(l,{env:this,dynamic_scope:n,error:t});return c(f,p,o)}if(!(e.car instanceof LSymbol)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var _=e.car.valueOf();u=this.ref(e.car.__name__);return unpromise(o,function(e){if(!u){var r=_.split(".");if(r.length>1){var n=r.pop();var t=r.join(".");var i=a.get(t,{throwError:false});if(i){c(i,n,e);return}}throw new Error("Unbound variable `"+_+"'")}u.set(_,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 n=this.ref(r);if(n){delete n.__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(function e(r,n){typecheck("load",r,"string");var t=this;if(t.__name__==="__frame__"){t=t.__parent__}if(!(n instanceof Environment)){if(t===global_env){n=t}else{n=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 u(e){if(type(e)==="buffer"){e=e.toString()}return exec(e.replace(/^#!.*/,""),n)}if(is_node()){return new Promise(function(n,t){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){t(e);global_env.set(i,a)}else{try{u(r).then(function(){n();global_env.set(i,a)})["catch"](t)}catch(e){t(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 u(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 n=asyncToGenerator(regenerator.mark(function e(n,t){var i,a,u,o,c,s,l,f,p,_,h;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:i=t.dynamic_scope,a=t.error;u=this;if(i){i=u}o=u.inherit("do");c=n.car;s=n.cdr.car;l=n.cdr.cdr;if(l!==nil){l=new Pair(LSymbol("begin"),l)}f={env:u,dynamic_scope:i,error:a};p=c;case 10:if(!(p!==nil)){r.next=21;break}_=p.car;r.t0=o;r.t1=_.car;r.next=16;return evaluate(_.cdr.car,f);case 16:r.t2=r.sent;r.t0.set.call(r.t0,r.t1,r.t2);p=p.cdr;r.next=10;break;case 21:f={env:o,dynamic_scope:i,error:a};h=regenerator.mark(function e(){var n,t,i,a,u;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:n=c;t={};case 5:if(!(n!==nil)){r.next=15;break}i=n.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;t[i.car.valueOf()]=a;case 12:n=n.cdr;r.next=5;break;case 15:u=Object.getOwnPropertySymbols(t);Object.keys(t).concat(u).forEach(function(e){o.set(e,t[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 n.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(n,e){var t=e.dynamic_scope,i=e.error;if(t){t=this}var a=this;var r=function e(r){if(r===false){return evaluate(n.cdr.cdr.car,{env:a,dynamic_scope:t,error:i})}else{return evaluate(n.cdr.car,{env:a,dynamic_scope:t,error:i})}};if(n===nil){throw new Error("too few expressions for `if`")}var u=evaluate(n.car,{env:a,dynamic_scope:t,error:i});return unpromise(u,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 n=e.dynamic_scope,t=e.error;typecheck("let-env",r,"pair");var i=evaluate(r.car,{env:this,dynamic_scope:n,error:t});return unpromise(i,function(e){typecheck("let-env",e,"environment");return evaluate(Pair(LSymbol("begin"),r.cdr),{env:e,dynamic_scope:n,error:t})})},"(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."),"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 t=Object.assign({},r);var i=global_env.get("list->array")(e);if(t.dynamic_scope){t.dynamic_scope=this}t.env=this;var a;return function r(){if(i.length){var e=i.shift();var n=evaluate(e,t);return unpromise(n,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 n=r.dynamic_scope,t=r.error;var i={env:this,error:t};if(n){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(n,e){var t=this;if(n.car instanceof Pair&&n.car.car instanceof LSymbol){var r=new Pair(new LSymbol("define"),new Pair(n.car.car,new Pair(new Pair(new LSymbol("lambda"),new Pair(n.car.cdr,n.cdr)))));return r}else if(e.macro_expand){return}if(e.dynamic_scope){e.dynamic_scope=this}e.env=t;var i=n.cdr.car;var a;if(i instanceof Pair){i=evaluate(i,e);a=true}else if(i instanceof LSymbol){i=t.get(i)}typecheck("define",n.car,"symbol");return unpromise(i,function(e){if(t.__name__===Syntax.__merge_env__){t=t.__parent__}if(a&&(is_function(e)&&e[__lambda__]||e instanceof Syntax)){e.__name__=n.car.valueOf();if(e.__name__ instanceof LString){e.__name__=e.__name__.valueOf()}}var r;if(n.cdr.cdr instanceof Pair&&LString.isString(n.cdr.cdr.car)){r=n.cdr.cdr.car.valueOf()}t.set(n.car,e,r)})}),"(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,n){var t=_typeof_1(e);if(is_null(e)||t!=="object"&&t!=="function"){var i=typeErrorMessage("set-obj!",type(e),["object","function"]);throw new Error(i)}e=unbind(e);r=r.valueOf();if(arguments.length===2){delete e[r]}else if(is_prototype(e)&&is_function(n)){e[r]=unbind(n);e[r][__prototype__]=true}else if(is_function(n)||is_native(n)||n===nil){e[r]=n}else{e[r]=n?n.valueOf():n}},"(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(function e(){for(var r=arguments.length,n=new Array(r),t=0;t1&&arguments[1]!==undefined$1?arguments[1]:{},p=e.dynamic_scope,_=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(p){if(!(this instanceof Environment)){e=h}else{e=this}}else{e=h}e=e.inherit("lambda");var r=f.car;var n=0;var t;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),u=0;u2&&arguments[2]!==undefined$1?arguments[2]:a;if(e instanceof Pair){var t=e.car;var i=e.cdr;if(n(t)){t=r(t)}if(n(i)){i=r(i)}if(is_promise(t)||is_promise(i)){return Promise.all([t,i]).then(function(e){var r=slicedToArray(e,2),n=r[0],t=r[1];return new Pair(n,t)})}else{return new Pair(t,i)}}return e}function u(e,r){if(e instanceof Pair){if(r!==nil){e.append(r)}}else{e=new Pair(e,r)}return e}function n(e){return!!e.filter(function(e){return e instanceof Pair&&LSymbol.is(e.car,"unquote")}).length}function f(e,t,i){return e.reduce(function(e,r){if(!(r instanceof Pair)){e.push(r);return e}if(LSymbol.is(r.car,"unquote-splicing")){var n;if(t+11){var r="You can't splice multiple atoms inside list";throw new Error(r)}if(!(i.cdr instanceof Pair&&n[0]===nil)){return n[0]}}n=n.map(function(e){if(h.has(e)){return e.clone()}else{h.add(e);return e}});var t=d(i.cdr,0,1);if(t===nil&&n[0]===nil){return undefined$1}return unpromise(t,function(e){if(n[0]===nil){return e}if(n.length===1){return u(n[0],e)}var r=n.reduce(function(e,r){return u(e,r)});return u(r,e)})})}(i.car.cdr)}var h=new Set;function d(e,r,n){if(e instanceof Pair){if(LSymbol.is(e.car.car,"unquote-splicing")){return _(e,r+1,n)}if(LSymbol.is(e.car,"quasiquote")){var t=d(e.cdr,r,n+1);return new Pair(e.car,t)}if(LSymbol.is(e.car.car,"unquote")){if(r+2===n&&e.car.cdr instanceof Pair&&e.car.cdr.car instanceof Pair&&LSymbol.is(e.car.cdr.car.car,"unquote-splicing")){var i=e.car.cdr;return new Pair(new Pair(new LSymbol("unquote"),_(i,r+2,n)),nil)}else if(e.car.cdr instanceof Pair&&e.car.cdr.cdr!==nil){if(e.car.cdr.car instanceof Pair){var a=[];return function r(n){if(n===nil){return Pair.fromArray(a)}return unpromise(evaluate(n.car,{env:s,dynamic_scope:o,error:c}),function(e){a.push(e);return r(n.cdr)})}(e.car.cdr)}else{return e.car.cdr}}}if(LSymbol.is(e.car,"quote")){return new Pair(e.car,d(e.cdr,r,n))}if(LSymbol.is(e.car,"unquote")){r++;if(rn){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 u=[];return function r(n){if(n===nil){return Pair.fromArray(u)}return unpromise(evaluate(n.car,{env:s,dynamic_scope:o,error:c}),function(e){u.push(e);return r(n.cdr)})}(e.cdr)}else{return e.cdr}}else{return evaluate(e.cdr.car,{env:s,dynamic_scope:o,error:c})}}else{return e.cdr}}return l(e,function(e){return d(e,r,n)})}else if(is_plain_object(e)){return p(e,r,n)}else if(e instanceof Array){return f(e,r,n)}return e}function t(e){if(e instanceof Pair){delete e[__data__];if(!e.haveCycles("car")){t(e.car)}if(!e.haveCycles("cdr")){t(e.cdr)}}}if(is_plain_object(e.car)&&!n(Object.values(e.car))){return quote(e.car)}if(Array.isArray(e.car)&&!n(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){t(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(function e(r){typecheck("clone",r,"pair");return r.clone()},"(clone list)\n\n Function return clone of the list."),append:doc(function e(){var r;for(var n=arguments.length,t=new Array(n),i=0;iarray")(r).reverse();return global_env.get("array->list")(n)}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(function e(r,n){typecheck("nth",r,"number");typecheck("nth",n,["array","pair"]);if(n instanceof Pair){var t=n;var i=0;while(iarray")(n).join(r)},"(join separator list)\n\n Function return string by joining elements of the list"),split:doc(function e(r,n){typecheck("split",r,["regex","string"]);typecheck("split",n,"string");return global_env.get("array->list")(n.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(function e(r,n,t){typecheck("replace",r,["regex","string"]);typecheck("replace",n,["string","function"]);typecheck("replace",t,"string");return t.replace(r,n)},"(replace pattern replacement string)\n\n Function change pattern to replacement inside string. Pattern can be string\n or regex and replacement can be function or string."),match:doc(function e(r,n){typecheck("match",r,["regex","string"]);typecheck("match",n,"string");var t=n.match(r);return t?global_env.get("array->list")(t):nil},"(match pattern string)\n\n function return match object from JavaScript as list."),search:doc(function e(r,n){typecheck("search",r,["regex","string"]);typecheck("search",n,"string");return n.search(r)},"(search pattern string)\n\n Function return first found index of the pattern inside a string"),repr:doc(function e(r,n){return toString(r,n)},"(repr obj)\n\n Function return string LIPS representation of an object as string."),env:doc(function e(e){e=e||this;var r=Object.keys(e.__env__);var n;if(r.length){n=Pair.fromArray(r)}else{n=nil}if(e.__parent__!==undefined$1){return global_env.get("env")(e.__parent__).append(n)}return n},"(env obj)\n\n Function return list values (functions and variables) inside environment."),new:doc("new",function(e){for(var r=arguments.length,n=new Array(r>1?r-1:0),t=1;t2&&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,n)},'(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=e.valueOf()}return e in 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?",LNumber.isNumber,"(number? expression)\n\n Function check if value is a number"),"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(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_1(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Function check if value is an plain object."),flatten:doc(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",toArray$1("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":doc("list->array",toArray$1("list->array"),"(list->array list)\n\n Function convert LIPS list into JavaScript array."),apply:doc(function e(r){for(var n=arguments.length,t=new Array(n>1?n-1:0),i=1;iarray").call(this,a));return r.apply(this,prepare_fn_args(r,t))},"(apply fn list)\n\n Function that call function with list of arguments."),length:doc(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 n=r===10&&!e.match(/e/i)||r===16;if(e.match(int_bare_re)&&n||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,t){var a,u;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")){u=r.cdr.cdr.car}}else if(LSymbol.is(r.cdr.car.car,"finally")){u=r.cdr.car}if(!(u||a)){throw new Error("try: invalid syntax")}var o=i;if(u){o=function e(r,n){o=t;unpromise(evaluate(new Pair(new LSymbol("begin"),u.cdr),c),function(){n(r)})}}var c={env:s,error:function e(r){var n=s.inherit("try");if(a){n.set(a.cdr.car.car,r);var t={env:n,error:f};if(l){t.dynamic_scope=s}unpromise(evaluate(new Pair(new LSymbol("begin"),a.cdr.cdr),t),function(e){o(e,i)})}else{o(r,f)}}};if(l){c.dynamic_scope=s}var e=evaluate(r.car,c);if(is_promise(e)){e.then(function(e){o(e,i)})["catch"](c.error)}else{o(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."),throw:doc("throw",function(e){throw new Error(e)},"(throw string)\n\n Throw new expection."),find:doc(function r(n,t){typecheck("find",n,["regex","function"]);typecheck("find",t,["pair","nil"]);if(is_null(t)){return nil}var e=matcher("find",n);return unpromise(e(t.car),function(e){if(e&&e!==nil){return t.car}return r(n,t.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 n=arguments.length,t=new Array(n>1?n-1:0),i=1;i1?r-1:0),a=1;a3?t-3:0),a=3;a3?i-3:0),u=3;uarray")(n);var a=[];var u=matcher("filter",r);return function r(n){function e(e){if(e&&e!==nil){a.push(t)}return r(++n)}if(n===i.length){return Pair.fromArray(a)}var t=i[n];return unpromise(u(t),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher order function that call `fn` for each element of the list\n and return list for only those elements for which funtion return\n true value. If called with regex it will create matcher function."),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(function e(){for(var r=arguments.length,n=new Array(r),t=0;ti?n%=i:i%=n}n=abs(a*(t<0||arguments.length<=t?undefined$1:arguments[t]))/(n+i)}return LNumber(n)},"(lcm n1 n2 ...)\n\n Function return the least common multiple of their arguments."),"odd?":doc("odd?",singleMathOp(function(e){return LNumber(e).isOdd()}),"(odd? number)\n\n Function check if number os odd."),"even?":doc("even?",singleMathOp(function(e){return LNumber(e).isEven()}),"(even? number)\n\n Function check if number is even."),"*":doc("*",reduceMathOp(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("+",reduceMathOp(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),n=0;n":doc(">",function(){for(var e=arguments.length,r=new Array(e),n=0;n x1 x2 x3 ...)\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),n=0;n=":doc(">=",function(){for(var e=arguments.length,r=new Array(e),n=0;n= x1 x2 x3 ...)\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 u=global_env.get("list->array")(e);var o=this;if(i){i=o}if(!u.length){return false}var c;return function r(){function e(e){c=e;if(c!==false){return c}else{return r()}}if(!u.length){if(c!==false){return c}else{return false}}else{var n=u.shift();var t=evaluate(n,{env:o,dynamic_scope:i,error:a});return unpromise(t,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 u=global_env.get("list->array")(e);var o=this;if(i){i=o}if(!u.length){return true}var c;return function r(){function e(e){c=e;if(c===false){return false}else{return r()}}var n=u.shift();if(typeof n==="undefined"){if(c!==false){return c}else{return false}}else{var t=evaluate(n,{env:o,dynamic_scope:i,error:a});return unpromise(t,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(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");global_env.set("**interaction-environment**",user_env);global_env.constant("**internal-env**",internal_env);(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(r){var n=e[r]?e[r]:r;global_env.set(n,doc(n,function(e){typecheck(n,e,"number");if(e instanceof LNumber){return e[r]()}},"(".concat(n," number)\n\n Function calculate ").concat(n," of a number.")))})})();function allPossibleCases(e){if(e.length===1){return e[0]}else{var r=[];var n=allPossibleCases(e.slice(1));for(var t=0;t3&&arguments[3]!==undefined$1?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(t!==null){i+=" (argument ".concat(t,")")}if(n instanceof Array){if(n.length===1){n=n[0]}else{var a=n[n.length-1];n=n.slice(0,-1).join(", ")+" or "+a}}return"Expecting ".concat(n,", got ").concat(r).concat(i)}function typecheck(e,r,n){var t=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:null;e=e.valueOf();var i=type(r).toLowerCase();var a=false;if(n instanceof Pair){n=n.toArray()}if(n instanceof Array){n=n.map(function(e){return e.valueOf()})}if(n instanceof Array){n=n.map(function(e){return e.valueOf().toLowerCase()});if(n.includes(i)){a=true}}else{n=n.valueOf().toLowerCase()}if(!a&&i!==n){throw new Error(typeErrorMessage(e,i,n,t))}}function self_evaluated(e){var r=_typeof_1(e);return["string","function"].includes(r)||_typeof_1(e)==="symbol"||e instanceof LSymbol||e instanceof LNumber||e instanceof LString||e instanceof RegExp}function is_native(e){return e instanceof LNumber||e instanceof LString||e instanceof LCharacter}function has_own_symbol(e,r){if(e===null){return false}return _typeof_1(e)==="object"&&r in Object.getOwnPropertySymbols(e)}function 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 n=0,t=Object.entries(r);n2&&arguments[2]!==undefined$1?arguments[2]:{},a=r.env,u=r.dynamic_scope,n=r.error,o=n===void 0?function(){}:n;e=evaluate_args(e,{env:a,dynamic_scope:u,error:o});return unpromise(e,function(e){if(is_raw_lambda(i)){i=unbind(i)}e=prepare_fn_args(i,e);var r=e.slice();var n=(u||a).newFrame(i,r);var t=resolve_promises(i.apply(n,e));return unpromise(t,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},o)})}function evaluate(r){var e=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},n=e.env,t=e.dynamic_scope,i=e.error,a=i===void 0?function(){}:i;try{if(t===true){n=t=n||global_env}else if(n===true){n=t=global_env}else{n=n||global_env}var u={env:n,dynamic_scope:t,error:a};var o;if(is_null(r)){return r}if(r instanceof LSymbol){return n.get(r)}if(!(r instanceof Pair)){return r}var c=r.car;var s=r.cdr;if(c instanceof Pair){o=resolve_promises(evaluate(c,u));if(is_promise(o)){return o.then(function(e){return evaluate(new Pair(e,r.cdr),u)})}else if(!is_function(o)){throw new Error(type(o)+" "+n.get("repr")(o)+" is not a function while evaluating "+r.toString())}}if(c instanceof LSymbol){o=n.get(c)}else if(is_function(c)){o=c}var l;if(o instanceof Syntax){l=evaluate_syntax(o,r,u)}else if(o instanceof Macro){l=evaluate_macro(o,s,u)}else if(is_function(o)){l=apply(o,s,u)}else if(r instanceof Pair){o=c&&c.toString();throw new Error("".concat(type(c)," ").concat(o," is not a function"))}else if(!is_function(o)){if(o){var f="".concat(type(o)," `").concat(o,"' is not a function");throw new Error(f)}throw new Error("Unknown function `".concat(c.toString(),"'"))}else{return r}var p=n.get(Symbol["for"]("__promise__"),{throwError:false});if(p===true&&is_promise(l)){return new QuotedPromise(l)}return l}catch(e){a&&a.call(n,e,r)}}function exec(e,r,n){return _exec.apply(this,arguments)}function _exec(){_exec=asyncToGenerator(regenerator.mark(function e(n,t,i){var a,u,o,c,s,l,f,p,_;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(i===true){t=i=t||user_env}else if(t===true){t=i=user_env}else{t=t||user_env}a=[];u=true;o=false;r.prev=4;s=asyncIterator(parse(n));case 6:r.next=8;return s.next();case 8:l=r.sent;u=l.done;r.next=12;return l.value;case 12:f=r.sent;if(u){r.next=28;break}p=f;_=evaluate(p,{env:t,dynamic_scope:i,error:function e(r,n){if(r&&r.message){r.message=r.message.replace(/.*:\s*([^:]+:\s*)/,"$1");if(n){if(!(r.__code__ instanceof Array)){r.__code__=[]}r.__code__.push(n.toString(true))}}throw r}});if(is_promise(_)){r.next=20;break}a.push(_);r.next=25;break;case 20:r.t0=a;r.next=23;return _;case 23:r.t1=r.sent;r.t0.push.call(r.t0,r.t1);case 25:u=true;r.next=6;break;case 28:r.next=34;break;case 30:r.prev=30;r.t2=r["catch"](4);o=true;c=r.t2;case 34:r.prev=34;r.prev=35;if(!(!u&&s["return"]!=null)){r.next=39;break}r.next=39;return s["return"]();case 39:r.prev=39;if(!o){r.next=42;break}throw c;case 42:return r.finish(39);case 43:return r.finish(34);case 44:return r.abrupt("return",a);case 45:case"end":return r.stop()}}},e,null,[[4,30,34,44],[35,,39,43]])}));return _exec.apply(this,arguments)}function balanced(e){var r={"[":"]","(":")"};var n;if(typeof e==="string"){n=tokenize(e)}else{n=e.map(function(e){return e&&e.token?e.token:e})}var t=Object.keys(r);var i=Object.values(r).concat(t);n=n.filter(function(e){return i.includes(e)});var a=new Stack;var u=_createForOfIteratorHelper(n),o;try{for(u.s();!(o=u.n()).done;){var c=o.value;if(t.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){u.e(e)}finally{u.f()}return a.is_empty()}function fworker(e){var r="("+e.toString()+")()";var n=window.URL||window.webkitURL;var t;try{t=new Blob([r],{type:"application/javascript"})}catch(e){var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;t=new i;t.append(r);t=t.getBlob()}return new root.Worker(n.createObjectURL(t))}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 u=this.worker=fworker(function(){var u;var o;self.addEventListener("message",function(e){var n=e.data;var r=n.id;if(n.type!=="RPC"||r===null){return}function t(e){self.postMessage({id:r,type:"RPC",result:e})}function i(e){self.postMessage({id:r,type:"RPC",error:e})}if(n.method==="eval"){if(!o){i("Worker RPC: LIPS not initilized, call init first");return}o.then(function(){var e=n.params[0];var r=n.params[1];u.exec(e,r).then(function(e){e=e.map(function(e){return e&&e.valueOf()});t(e)})["catch"](function(e){i(e)})})}else if(n.method==="init"){var a=n.params[0];if(typeof a!=="string"){i("Worker RPC: url is not a string")}else{importScripts("".concat(a,"/dist/lips.min.js"));u=new lips.Interpreter("worker");o=bootstrap(a);o.then(function(){t(true)})}}})});this.rpc=function(){var t=0;return function e(r,n){var a=++t;return new Promise(function(t,i){u.addEventListener("message",function e(r){var n=r.data;if(n&&n.type==="RPC"&&n.id===a){if(n.error){i(n.error)}else{t(n.result)}u.removeEventListener("message",e)}});u.postMessage({type:"RPC",method:r,id:a,params:n})})}}();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])}}Pair.unDry=function(e){return new Pair(e.car,e.cdr)};Pair.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};Nil.prototype.toDry=function(){return{value:null}};Nil.unDry=function(){return nil};LSymbol.prototype.toDry=function(){return{value:{name:this.__name__}}};LSymbol.unDry=function(e){return new LSymbol(e.__name__)};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 u=["text/x-lips","text/x-scheme"];var o;function c(n){return new Promise(function(r){var e=n.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(n.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 n=r.getAttribute("type");if(u.includes(n)){var t=r.getAttribute("bootstrap");if(!o&&typeof t==="string"){bootstrap(t).then(function(){return c(r)}).then(e)}else{c(r).then(e)}}else if(n&&n.match(/lips|lisp/)){console.warn("Expecting "+u.join(" or ")+" found "+n)}return e()}}()})}if(!window.document){return Promise.resolve()}else if(currentScript){var r=currentScript;var n=r.getAttribute("bootstrap");if(typeof n==="string"){return bootstrap(n).then(function(){o=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("Sun, 31 Jan 2021 11:47:57 +0000").valueOf();var r=e==="{{"+"DATE}}"?new Date:new Date(e);var n=function e(r){return r.toString().padStart(2,"0")};var t=r.getFullYear();var i=[t,n(r.getMonth()+1),n(r.getDate())].join("-");var a="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter 1.0.0-beta.11 (".concat(i,") \nCopyright (c) 2018-").concat(t," Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables.\nYou can also use (help name) to display help for specic function or macro and\n(apropos name) to display list of matched names in environment.\n").replace(/^.*\n/,"");return a}();Ahead.__class__="ahead";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";LNumber.__class__="number";LCharacter.__class__="character";LString.__class__="string";var lips={version:"1.0.0-beta.11",banner:banner,date:"Sun, 31 Jan 2021 11:47:57 +0000",exec:exec,parse:compose(uniterate_async,parse),tokenize:tokenize,evaluate:evaluate,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,quote:quote,InputPort:InputPort,OutputPort:OutputPort,InputFilePort:InputFilePort,OutputFilePort:OutputFilePort,InputStringPort:InputStringPort,OutputStringPort:OutputStringPort,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/package.json b/package.json index c4b8964d..d7284640 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jcubic/lips", - "version": "1.0.0-beta.10", + "version": "1.0.0-beta.11", "description": "Simple Scheme Like Lisp in JavaScript", "main": "src/lips.js", "unpkg": "dist/lips.min.js", @@ -169,9 +169,9 @@ "space-before-function-paren": [ "error", { - "anonymous": "never", - "named": "never", - "asyncArrow": "always" + "anonymous": "never", + "named": "never", + "asyncArrow": "always" } ], "complexity": [