From 5e4c8ce1804f1da23c9c574e0049faeccc99db3c Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Tue, 8 Sep 2020 11:44:45 +0200 Subject: [PATCH] version 1.0.0-beta.5 --- Makefile | 4 ++-- README.md | 10 +++++----- dist/lips.js | 14 +++++++------- dist/lips.min.js | 6 +++--- package.json | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index ebc08168e..631ab4f5b 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .PHONY: publish test coveralls lint -VERSION=1.0.0-beta.4 -VERSION_DASH=`echo -n "1.0.0-beta.4" | sed "s/-/%E2%80%93/"` +VERSION=1.0.0-beta.5 +VERSION_DASH=`echo -n "1.0.0-beta.5" | 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 d37a2d260..7509ad518 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -![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.4-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) -[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&ed355b02f13ec997c52bd86eee6593c92ffcd4e1)](https://travis-ci.org/jcubic/lips) -[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&2c48907438a7265935a7b21e6931008d)](https://coveralls.io/github/jcubic/lips?branch=devel) +[![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.5-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) +[![travis](https://travis-ci.org/jcubic/lips.svg?branch=master&dec6d0cb5bcb1d93f517c1498e2c906adea74c58)](https://travis-ci.org/jcubic/lips) +[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=master&2c48907438a7265935a7b21e6931008d)](https://coveralls.io/github/jcubic/lips?branch=master) [![Join Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips) LIPS is Powerful Lisp based language. It's based on Scheme dialect and R5RS @@ -130,7 +130,7 @@ npm install -g @jcubic/lips you can run interpreter from 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 as string with: diff --git a/dist/lips.js b/dist/lips.js index df3e0a5b5..e9559002b 100644 --- a/dist/lips.js +++ b/dist/lips.js @@ -4,7 +4,7 @@ * | | \ \ | | | || . \/ __> | | * | | > \ | |_ | || _/\__ \ | | * | | / ^ \ |___||_||_| <___/ | | - * \_\ /_/ \_\ /_/ v. DEV + * \_\ /_/ \_\ /_/ v. 1.0.0-beta.5 * * 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: Tue, 08 Sep 2020 08:31:43 +0000 + * build: Tue, 08 Sep 2020 09:44:35 +0000 */ (function () { 'use strict'; @@ -10309,10 +10309,10 @@ var banner = function () { // Rollup tree-shaking is removing the variable if it's normal string because - // obviously 'Tue, 08 Sep 2020 08:31:43 +0000' == '{{' + 'DATE}}'; can be removed + // obviously 'Tue, 08 Sep 2020 09:44:35 +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('Tue, 08 Sep 2020 08:31:43 +0000').valueOf(); + var date = LString('Tue, 08 Sep 2020 09:44:35 +0000').valueOf(); var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date); @@ -10324,7 +10324,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.\n").replace(/^.*\n/, ''); + var banner = "\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter 1.0.0-beta.5 (".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.\n").replace(/^.*\n/, ''); return banner; }(); // ------------------------------------------------------------------------- // to be used with string function when code is minified @@ -10347,9 +10347,9 @@ LString.__className = 'string'; // ------------------------------------------------------------------------- var lips = { - version: 'DEV', + version: '1.0.0-beta.5', banner: banner, - date: 'Tue, 08 Sep 2020 08:31:43 +0000', + date: 'Tue, 08 Sep 2020 09:44:35 +0000', exec: exec, parse: parse, tokenize: tokenize, diff --git a/dist/lips.min.js b/dist/lips.min.js index 4923ab158..dde330bfe 100644 --- a/dist/lips.min.js +++ b/dist/lips.min.js @@ -4,7 +4,7 @@ * | | \ \ | | | || . \/ __> | | * | | > \ | |_ | || _/\__ \ | | * | | / ^ \ |___||_||_| <___/ | | - * \_\ /_/ \_\ /_/ v. DEV + * \_\ /_/ \_\ /_/ v. 1.0.0-beta.5 * * 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: Tue, 08 Sep 2020 08:31:43 +0000 + * build: Tue, 08 Sep 2020 09:44:35 +0000 */ -(function(){"use strict";function e(e){throw new Error('"'+e+'" is read-only')}var Tt=e;function n(e,n){return n={exports:{}},e(n,n.exports),n.exports}var u=n(function(t){function r(e,n){t.exports=r=Object.setPrototypeOf||function e(n,t){n.__proto__=t;return n};return r(e,n)}t.exports=r});function t(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Date.prototype.toString.call(Reflect.construct(Date,[],function(){}));return true}catch(e){return false}}var a=t;var Bt=n(function(r){function i(e,n,t){if(a()){r.exports=i=Reflect.construct}else{r.exports=i=function e(n,t,r){var i=[null];i.push.apply(i,t);var a=Function.bind.apply(n,i);var o=new a;if(r)u(o,r.prototype);return o}}return i.apply(null,arguments)}r.exports=i});var r=n(function(e){var n=function(o){var e=Object.prototype;var f=e.hasOwnProperty;var c;var n=typeof Symbol==="function"?Symbol:{};var i=n.iterator||"@@iterator";var t=n.asyncIterator||"@@asyncIterator";var r=n.toStringTag||"@@toStringTag";function u(e,n,t,r){var i=n&&n.prototype instanceof s?n:s;var a=Object.create(i.prototype);var o=new F(r||[]);a._invoke=O(e,t,o);return a}o.wrap=u;function l(e,n,t){try{return{type:"normal",arg:e.call(n,t)}}catch(e){return{type:"throw",arg:e}}}var p="suspendedStart";var h="suspendedYield";var v="executing";var d="completed";var m={};function s(){}function a(){}function y(){}var g={};g[i]=function(){return this};var b=Object.getPrototypeOf;var w=b&&b(b(A([])));if(w&&w!==e&&f.call(w,i)){g=w}var _=y.prototype=s.prototype=Object.create(g);a.prototype=_.constructor=y;y.constructor=a;y[r]=a.displayName="GeneratorFunction";function x(e){["next","throw","return"].forEach(function(n){e[n]=function(e){return this._invoke(n,e)}})}o.isGeneratorFunction=function(e){var n=typeof e==="function"&&e.constructor;return n?n===a||(n.displayName||n.name)==="GeneratorFunction":false};o.mark=function(e){if(Object.setPrototypeOf){Object.setPrototypeOf(e,y)}else{e.__proto__=y;if(!(r in e)){e[r]="GeneratorFunction"}}e.prototype=Object.create(_);return e};o.awrap=function(e){return{__await:e}};function S(u,c){function s(e,n,t,r){var i=l(u[e],u,n);if(i.type==="throw"){r(i.arg)}else{var a=i.arg;var o=a.value;if(o&&typeof o==="object"&&f.call(o,"__await")){return c.resolve(o.__await).then(function(e){s("next",e,t,r)},function(e){s("throw",e,t,r)})}return c.resolve(o).then(function(e){a.value=e;t(a)},function(e){return s("throw",e,t,r)})}}var n;function e(t,r){function e(){return new c(function(e,n){s(t,r,e,n)})}return n=n?n.then(e,e):e()}this._invoke=e}x(S.prototype);S.prototype[t]=function(){return this};o.AsyncIterator=S;o.async=function(e,n,t,r,i){if(i===void 0)i=Promise;var a=new S(u(e,n,t,r),i);return o.isGeneratorFunction(n)?a:a.next().then(function(e){return e.done?e.value:a.next()})};function O(o,u,c){var s=p;return function e(n,t){if(s===v){throw new Error("Generator is already running")}if(s===d){if(n==="throw"){throw t}return I()}c.method=n;c.arg=t;while(true){var r=c.delegate;if(r){var i=k(r,c);if(i){if(i===m)continue;return i}}if(c.method==="next"){c.sent=c._sent=c.arg}else if(c.method==="throw"){if(s===p){s=d;throw c.arg}c.dispatchException(c.arg)}else if(c.method==="return"){c.abrupt("return",c.arg)}s=v;var a=l(o,u,c);if(a.type==="normal"){s=c.done?d:h;if(a.arg===m){continue}return{value:a.arg,done:c.done}}else if(a.type==="throw"){s=d;c.method="throw";c.arg=a.arg}}}}function k(e,n){var t=e.iterator[n.method];if(t===c){n.delegate=null;if(n.method==="throw"){if(e.iterator["return"]){n.method="return";n.arg=c;k(e,n);if(n.method==="throw"){return m}}n.method="throw";n.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var r=l(t,e.iterator,n.arg);if(r.type==="throw"){n.method="throw";n.arg=r.arg;n.delegate=null;return m}var i=r.arg;if(!i){n.method="throw";n.arg=new TypeError("iterator result is not an object");n.delegate=null;return m}if(i.done){n[e.resultName]=i.value;n.next=e.nextLoc;if(n.method!=="return"){n.method="next";n.arg=c}}else{return i}n.delegate=null;return m}x(_);_[r]="Generator";_[i]=function(){return this};_.toString=function(){return"[object Generator]"};function j(e){var n={tryLoc:e[0]};if(1 in e){n.catchLoc=e[1]}if(2 in e){n.finallyLoc=e[2];n.afterLoc=e[3]}this.tryEntries.push(n)}function E(e){var n=e.completion||{};n.type="normal";delete n.arg;e.completion=n}function F(e){this.tryEntries=[{tryLoc:"root"}];e.forEach(j,this);this.reset(true)}o.keys=function(t){var r=[];for(var e in t){r.push(e)}r.reverse();return function e(){while(r.length){var n=r.pop();if(n in t){e.value=n;e.done=false;return e}}e.done=true;return e}};function A(n){if(n){var e=n[i];if(e){return e.call(n)}if(typeof n.next==="function"){return n}if(!isNaN(n.length)){var t=-1,r=function e(){while(++t=0;--n){var i=this.tryEntries[n];var a=i.completion;if(i.tryLoc==="root"){return e("end")}if(i.tryLoc<=this.prev){var o=f.call(i,"catchLoc");var u=f.call(i,"finallyLoc");if(o&&u){if(this.prev=0;--t){var r=this.tryEntries[t];if(r.tryLoc<=this.prev&&f.call(r,"finallyLoc")&&this.prev=0;--n){var t=this.tryEntries[n];if(t.finallyLoc===e){this.complete(t.completion,t.afterLoc);E(t);return m}}},catch:function(e){for(var n=this.tryEntries.length-1;n>=0;--n){var t=this.tryEntries[n];if(t.tryLoc===e){var r=t.completion;if(r.type==="throw"){var i=r.arg;E(t)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,t){this.delegate={iterator:A(e),resultName:n,nextLoc:t};if(this.method==="next"){this.arg=c}return m}};return o}(e.exports);try{regeneratorRuntime=n}catch(e){Function("r","regeneratorRuntime = r")(n)}});var $t=r;function c(e,n,t,r,i,a,o){try{var u=e[a](o);var c=u.value}catch(e){t(e);return}if(u.done){n(c)}else{Promise.resolve(c).then(r,i)}}function i(u){return function(){var e=this,o=arguments;return new Promise(function(n,t){var r=u.apply(e,o);function i(e){c(r,n,t,i,a,"next",e)}function a(e){c(r,n,t,i,a,"throw",e)}i(undefined)})}}var Dt=i;function o(e){if(Array.isArray(e))return e}var s=o;function f(e){if(typeof Symbol!=="undefined"&&Symbol.iterator in Object(e))return Array.from(e)}var l=f;function p(e,n){if(n==null||n>e.length)n=e.length;for(var t=0,r=new Array(n);t=0)continue;t[i]=e[i]}return t}var j=k;function E(e,n){if(e==null)return{};var t=j(e,n);var r,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,r))continue;t[r]=e[r]}}return t}var Yt=E;function F(e,n){if(typeof Symbol==="undefined"||!(Symbol.iterator in Object(e)))return;var t=[];var r=true;var i=false;var a=undefined;try{for(var o=e[Symbol.iterator](),u;!(r=(u=o.next()).done);r=true){t.push(u.value);if(n&&t.length===n)break}}catch(e){i=true;a=e}finally{try{if(!r&&o["return"]!=null)o["return"]()}finally{if(i)throw a}}return t}var A=F;function I(e,n){return s(e)||A(e,n)||d(e,n)||y()}var Gt=I;var Vt=n(function(n){function t(e){"@babel/helpers - typeof";if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){n.exports=t=function e(n){return typeof n}}else{n.exports=t=function e(n){return n&&typeof Symbol==="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n}}return t(e)}n.exports=t});function zt(n){if(typeof Symbol==="undefined"||n[Symbol.iterator]==null){if(Array.isArray(n)||(n=N(n))){var t=0;var e=function e(){};return{s:e,n:function e(){if(t>=n.length)return{done:true};return{done:false,value:n[t++]}},e:function e(n){throw n},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,i=true,a=false,o;return{s:function e(){r=n[Symbol.iterator]()},n:function e(){var n=r.next();i=n.done;return n},e:function e(n){a=true;o=n},f:function e(){try{if(!i&&r["return"]!=null)r["return"]()}finally{if(a)throw o}}}}function N(e,n){if(!e)return;if(typeof e==="string")return L(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);if(t==="Object"&&e.constructor)t=e.constructor.name;if(t==="Map"||t==="Set")return Array.from(e);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return L(e,n)}function L(e,n){if(n==null||n>e.length)n=e.length;for(var t=0,r=new Array(n);t1&&arguments[1]!==F?arguments[1]:10;var t=E(e);var r=t.number.split("/");var i=Vn({num:$n([r[0],t.radix||n]),denom:$n([r[1],t.radix||n])});if(t.inexact){return i.valueOf()}else{return i}}function I(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:10;var t=E(e);if(t.inexact){return Un(parseInt(t.number,t.radix||n))}return $n([t.number,t.radix||n])}function N(e){var n=e.match(/#\\x([0-9a-f]+)$/i);var t;if(n){var r=parseInt(n[1],16);t=String.fromCodePoint(r)}else{n=e.match(/#\\(.+)$/);if(n){t=n[1]}}if(t){return Ln(t)}}function L(e){var i=arguments.length>1&&arguments[1]!==F?arguments[1]:10;function n(e){var n;if(e==="+"){n=$n(1)}else if(e==="-"){n=$n(-1)}else if(e.match(x)){n=$n([e,i])}else if(e.match(S)){var t=e.split("/");n=Vn({num:$n([t[0],i]),denom:$n([t[1],i])})}else if(e.match(c)){var r=Un(parseFloat(e));if(a.exact){return r.toRational()}return r}else{throw new Error("Internal Parser Error")}if(a.inexact){return Un(n.valueOf())}return n}var a=E(e);i=a.radix||i;var t;var r=a.number.match(k);if(i!==10&&r){t=r}else{t=a.number.match(l[i])}var o,u;u=n(t[2]);if(t[1]){o=n(t[1])}else if(u instanceof Un){o=Un(0)}else{o=$n(0)}return Dn({im:u,re:o})}function q(e){return parseInt(e.toString(),10)===e}function P(e){var n=e.match(/^(([-+]?[0-9]*)(?:\.([0-9]+))?)e([-+]?[0-9]+)/i);if(n){var t=parseInt(n[4],10);var r;var i=n[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var a=n[3]&&n[3].length;if(i0){return $n(a).mul(u)}}}t=Un(t);if(n.exact){return t.toRational()}return t}function C(e){var n=/([^\\\n])(\\(?:\\{2})*)(?!x[0-9A-F]+)(?!u[0-9A-F]{2,4})(.)/gi;e=e.replace(n,function(e,n,t,r){if(!['"',"/","b","f","n","\\","r","t","x"].includes(r)){t=t.substring(1).replace(/\\\\/,"\\")}return e}).replace(/\\x([0-9a-f]+);/gi,function(e,n){return"\\u"+n.padStart(4,"0")}).replace(/\n/g,"\\n");var t=e.match(/(\\*)(\\x[0-9A-F])/i);if(t&&t[1].length%2===0){throw new Error("Invalid string literal, unclosed ".concat(t[2]))}try{return qn(JSON.parse(e))}catch(e){throw new Error("Invalid string literal")}}function M(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var t={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,n){return String.fromCharCode(parseInt("0"+n,16))}).replace(/\\(.)/g,function(e,n){return t[n]||n})}return new je(e)}function T(e){var n=e.match(a);if(n){return new RegExp(n[1],n[2])}else if(e.match(/^"/)){return C(e)}else if(e.match(m)){return N(e)}else if(e.match(w)){return A(e)}else if(e.match(b)){return L(e)}else if(e.match(_)){return I(e)}else if(e.match(c)){return R(e)}else if(e==="nil"){return Ie}else if(["true","#t"].includes(e)){return true}else if(["false","#f"].includes(e)){return false}else{return M(e)}}function B(e){return!(["(",")"].includes(e)||e.match(a)||e.match(/^"[\s\S]+"$/)||e.match(_)||e.match(c)||e.match(b)||e.match(w)||["#t","#f","nil","true","false"].includes(e))}var $=/("(?:\\[\S\s]|[^"])*"?|\/(?! )[^\n\/\\]*(?:\\[\S\s][^\n\/\\]*)*\/[gimy]*(?=[\s[\]()]|$)|\|[^|\s\n]+\||#;|;.*|#\|(?!\|#)[\s\S]*\|#)/g;var D=/"(?:\\[\S\s]|[^"])*"?/g;var U=[r,n,i].map(y).join("|");function J(){var e=K.names().sort(function(e,n){return n.length-e.length||e.localeCompare(n)}).map(Y).join("|");return new RegExp("(".concat(d,"|#f|#t|#;|(?:").concat(U,")(?=$|[\\n\\s()[\\]])|\\[|\\]|\\(|\\)|\\|[^|]+\\||;.*|(?:#[ei])?").concat(o,"(?=$|[\\n\\s()[\\]])|\\n|\\.{2,}|'(?=#[ft]|(?:#[xiobe]){1,2}|#\\\\)|(?!#:)(?:").concat(e,")|[^(\\s)[\\]]+)"),"gim")}function H(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:1;return e[e.length-n]}function Y(e){if(typeof e==="string"){var n=/([-\\^$[\]()+{}?*.|])/g;return e.replace(n,"\\$1")}}function G(){this.data=[]}G.prototype.push=function(e){this.data.push(e)};G.prototype.top=function(){return this.data[this.data.length-1]};G.prototype.pop=function(){return this.data.pop()};G.prototype.is_empty=function(){return!this.data.length};function V(e){var a=J();e=e.replace(/\n\r|\r/g,"\n");var o=0;var u=0;var c=[];var s=[];var f=0;e.split($).filter(Boolean).forEach(function(e){if(e.match($)){f=0;if(s.length){var n=H(s);if(n.token.match(/\n/)){var t=n.token.split("\n").pop();f+=t.length}else{f+=n.token.length}f+=n.col}var r={col:f,line:u,token:e,offset:o};c.push(r);s.push(r);o+=e.length;f+=e.length;u+=(e.match("\n")||[]).length;return}var i=e.split(a).filter(Boolean);i.forEach(function(e){var n={col:f,line:u,token:e,offset:o};f+=e.length;o+=e.length;c.push(n);s.push(n);if(e==="\n"){++u;s=[];f=0}})});return c}function z(e){var n=e.token,t=Yt(e,["token"]);if(n.match(/^"[\s\S]+"$/)&&n.match(/\n/)){var r=new RegExp("^ {1,"+(e.col+1)+"}","mg");n=n.replace(r,"")}return Wt({token:n},t)}function W(e,n){var t=arguments.length>2&&arguments[2]!==F?arguments[2]:z;if(e instanceof qn){e=e.toString()}if(n){return V(e).map(t)}else{var r=V(e).map(function(e){var n=t(e);if(!n||typeof n.token!=="string"){throw new Error("[tokenize] Invalid formatter wrong return object")}if(n.token==="#\\ "){return n.token}return n.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return Q(r)}}function Q(e){var n=0;var t=null;var r=[];for(var i=0;i1&&!e[0].literal){c.pop();if(c[c.length-1].length===1&&c[c.length-1][0]instanceof je){c[c.length-1].push(e)}else if(c[c.length-1]instanceof Ne){if(c[c.length-1].cdr instanceof Ne){c[c.length-1]=new Ne(c[c.length-1],Ne.fromArray(e))}else{c[c.length-1].cdr=Ne.fromArray(e)}}else{c[c.length-1].push(e)}}}e.forEach(function(e){var n=c[c.length-1];if(l.indexOf(e)!==-1){y++;f=e;c.push([K.get(f).symbol]);if(!f){m=[]}m.push(f)}else{if(f){d.push(m);m=[]}if(b(e)){v=true;h++;var t=[];if(f&&!X(f)){t.push(g)}c.push(t);f=null;y=0}else if(e==="."&&!v){c[c.length-1]=Ne.fromArray(n)}else if(w(e)){h--;if(!c.length){throw new Error("Unbalanced parenthesis")}if(c.length===1){var r=c.pop();if(r instanceof Array&&r.length===0){r=Ie}s.push(r)}else if(c.length>1){var i=c.pop();n=c[c.length-1];if(n instanceof Array){if(i.length===0){n.push(Ie)}else if(i instanceof Array&&i[0]===g){var a;(a=n).push.apply(a,Jt(i.slice(1)))}else{n.push(i)}}else if(n instanceof Ne){if(i.length===0){n.append(Ie)}else{n.append(Ne.fromArray(i))}}if(d.length){m=d.pop();while(m.length){_();m.pop()}}else{_()}}if(h===0&&c.length){s.push(c.pop())}}else{v=false;var o=T(e);if(f){while(y--){c[c.length-1].push(o);o=c.pop()}d.pop();y=0;f=false}else if(o instanceof je&&p.includes(o.name)){o.literal=true}n=c[c.length-1];if(n instanceof Ne){var u=n;while(true){if(u.cdr===Ie){if(o instanceof Array){u.cdr=Ne.fromArray(o)}else{u.cdr=o}break}else{u=u.cdr}}}else if(!c.length){s.push(o)}else{n.push(o)}}}});if(!e.filter(function(e){return e.match(/^[[\]()]$/)}).length&&c.length){s=s.concat(c);c=[]}if(c.length){throw new Error("Unbalanced parenthesis 2")}return s.map(function(e){if(e instanceof Array){return Ne.fromArray(e)}return e})}function ne(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:function(e){return e};var t=arguments.length>2&&arguments[2]!==F?arguments[2]:null;if(e instanceof Array){var r=e.filter(nn);if(r.length){return ne(Promise.all(r),n,t)}return n(e)}if(nn(e)){var i=e.then(n);if(t===null){return i}else{return i["catch"](t)}}return n(e)}function te(e,n){if(n instanceof RegExp){return function(e){return String(e).match(n)}}else if(typeof n!=="function"){throw new Error("".concat(e," argument need to be a function or RegExp"))}else{return n}}function re(e,n,t){if(n){if(t){e.__doc__=n}else{e.__doc__=ie(n)}}return e}function ie(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function ae(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:1;var t=e.length;if(n<=0){throw Error("previousSexp: Invlaid argument sexp = ".concat(n))}e:while(n--&&t>=0){var r=1;while(r>0){var i=e[--t];if(!i){break e}if(i==="("||i.token==="("){r--}else if(i===")"||i.token===")"){r++}}t--}return e.slice(t+1)}function oe(e){if(!e||!e.length){return 0}var n=e.length;if(e[n-1].token==="\n"){return 0}while(--n){if(e[n].token==="\n"){var t=(e[n+1]||{}).token;if(t){return t.length}}}return 0}function ue(e,n){return f(e,n)===n.length;function f(t,r){function e(){return a>0&&u>0&&t[a-1]===r[u-1]&&t[a+1]===r[u]}function n(){return t[a]===Symbol["for"]("symbol")&&!B(r[u])}function i(){var e=t[a+1];var n=r[u+1];if(e!==F&&n!==F){return f([e],[n])}}var a=0;var o={};for(var u=0;u0){continue}}else if(n()){return-1}}else if(t[a]instanceof Array){var s=f(t[a],r.slice(u));if(s===-1||s+u>r.length){return-1}u+=s-1;a++;continue}else{return-1}a++}if(t.length!==a){return-1}return r.length}}function ce(e){this._code=e.replace(/\r/g,"")}ce.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?define/,/^(?:#:)?lambda/,/^(?:#:)?let*/,/^(?:#:)?(let|letrec)(-syntax)?$/,/(?:#:)?let-env/,/(?:#:)?syntax-rules/,/(?:#:)?try/,/(?:#:)?catch/,/(?:#:)?while/],shift:{1:["&","#"]}}};ce.match=ue;ce.prototype._options=function e(n){var t=ce.defaults;if(typeof n==="undefined"){return Object.assign({},t)}var r=n&&n.exceptions||{};var i=r.specials||[];var a=r.shift||{1:[]};return Wt(Wt(Wt({},t),n),{},{exceptions:{specials:[].concat(Jt(t.exceptions.specials),Jt(i)),shift:Wt(Wt({},a),{},{1:[].concat(Jt(t.exceptions.shift[1]),Jt(a[1]))})}})};ce.prototype.indent=function e(n){var t=W(this._code,true);return this._indent(t,n)};ce.exception_shift=function(a,e){function n(e){if(!e.length){return false}if(e.indexOf(a)!==-1){return true}else{var n=e.filter(function(e){return e instanceof RegExp});if(!n.length){return false}var t=zt(n),r;try{for(t.s();!(r=t.n()).done;){var i=r.value;if(a.match(i)){return true}}}catch(e){t.e(e)}finally{t.f()}}return false}if(n(e.exceptions.specials)){return e.indent}var t=e.exceptions.shift;for(var r=0,i=Object.entries(t);r0){r.offset=0}if(a.toString()===n.toString()&&Nt(a)){return r.offset+a[0].col}else if(a.length===1){return r.offset+a[0].col+1}else{var u=-1;if(o){var c=ce.exception_shift(o.token,r);if(c!==-1){u=c}}if(u===-1){u=ce.exception_shift(a[1].token,r)}if(u!==-1){return r.offset+a[0].col+u}else if(a[0].line3&&a[1].line===a[3].line){if(a[1].token==="("||a[1].token==="["){return r.offset+a[1].col}return r.offset+a[3].col}else if(a[0].line===a[1].line){return r.offset+r.indent+a[0].col}else{var s=a.slice(2);for(var f=0;f")};se.prototype.match=function(e){return e.match(this.pattern)};function fe(e,n){this.pattern=e;this.flag=n}fe.prototype.toString=function(){return"#")};ce.Pattern=fe;ce.Ahead=se;var le=/[[(]/;var pe=/[\])]/;var he=/[^()[\]]/;var ve=new se(/[^)\]]/);var de=Symbol["for"]("*");var me=new fe([le,de,pe],"+");var ye=new fe([Symbol["for"]("symbol")],"?");var ge=new fe([Symbol["for"]("symbol")],"*");var be=[le,ge,pe];var we=new fe([le,Symbol["for"]("symbol"),de,pe],"+");var _e=Se("define","lambda","syntax-rules");var xe=/^(?:#:)?(let|let\*|letrec|let-env)(:?-syntax)?$/;function Se(){for(var e=arguments.length,n=new Array(e),t=0;t0&&arguments[0]!==F?arguments[0]:null;if(e instanceof je){e=e.valueOf()}if(Ee(e)){return je(e)}if(e!==null){return new je(Symbol("#:".concat(e)))}n++;return new je(Symbol("#:g".concat(n)))}}();function Ae(){}Ae.prototype.toString=Ae.prototype.toJSON=function(){return"()"};Ae.prototype.valueOf=function(){return F};Ae.prototype.append=function(e){return new Ne(e,Ie)};Ae.prototype.toArray=function(){return[]};var Ie=new Ae;function Ne(e,n){if(typeof this!=="undefined"&&this.constructor!==Ne||typeof this==="undefined"){return new Ne(e,n)}this.car=e;this.cdr=n}function Le(a,o){return function e(n){_t(a,n,["pair","nil"]);if(n===Ie){return[]}var t=[];var r=n;while(true){if(r instanceof Ne){if(r.haveCycles("cdr")){break}var i=r.car;if(o&&i instanceof Ne){i=this.get(a).call(this,i)}t.push(i);r=r.cdr}else{break}}return t}}Ne.prototype.flatten=function(){return Ne.fromArray(Oe(this.toArray()))};Ne.prototype.length=function(){var e=0;var n=this;while(true){if(!n||n===Ie||!(n instanceof Ne)||n.haveCycles("cdr")){break}e++;n=n.cdr}return e};Ne.prototype.clone=function(){var t=new Map;function r(e){if(e instanceof Ne){if(t.has(e)){return t.get(e)}var n=new Ne;t.set(e,n);n.car=r(e.car);n.cdr=r(e.cdr);n.cycles=e.cycles;return n}return e}return r(this)};Ne.prototype.lastPair=function(){var e=this;while(true){if(e.cdr===Ie){return e}e=e.cdr}};Ne.prototype.toArray=function(){var e=[];if(this.car instanceof Ne){e.push(this.car.toArray())}else{e.push(this.car.valueOf())}if(this.cdr instanceof Ne){e=e.concat(this.cdr.toArray())}return e};Ne.fromArray=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:true;if(e instanceof Ne){return e}if(n===false){var t=Ie;for(var r=e.length;r--;){t=new Ne(e[r],t)}return t}if(e.length&&!(e instanceof Array)){e=Jt(e)}if(e.length===0){return Ie}else{var i;if(e[0]instanceof Array){i=Ne.fromArray(e[0])}else{i=e[0]}if(typeof i==="string"){i=qn(i)}if(e.length===1){return new Ne(i,Ie)}else{return new Ne(i,Ne.fromArray(e.slice(1)))}}};Ne.prototype.toObject=function(){var e=arguments.length>0&&arguments[0]!==F?arguments[0]:false;var n=this;var t={};while(true){if(n instanceof Ne&&n.car instanceof Ne){var r=n.car;var i=r.car;if(i instanceof je){i=i.name}if(i instanceof String){i=i.valueOf()}var a=r.cdr;if(a instanceof Ne){a=a.toObject(e)}if(a instanceof $n||a instanceof qn||a instanceof Ln){if(!e){a=a.valueOf()}}t[i]=a;n=n.cdr}else{break}}return t};Ne.fromPairs=function(e){return e.reduce(function(e,n){return new Ne(new Ne(new je(n[0]),n[1]),e)},Ie)};Ne.fromObject=function(n){var e=Object.keys(n).map(function(e){return[e,n[e]]});return Ne.fromPairs(e)};Ne.prototype.reduce=function(e){var n=this;var t=Ie;while(true){if(n!==Ie){t=e(t,n.car);n=n.cdr}else{break}}return t};Ne.prototype.reverse=function(){if(this.haveCycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var n=Ie;while(e!==Ie){var t=e.cdr;e.cdr=n;n=e;e=t}return n};Ne.prototype.transform=function(r){function i(e){if(e instanceof Ne){if(e.replace){delete e.replace;return e}var n=r(e.car);if(n instanceof Ne){n=i(n)}var t=r(e.cdr);if(t instanceof Ne){t=i(t)}return new Ne(n,t)}return e}return i(this)};Ne.prototype.map=function(e){if(typeof this.car!=="undefined"){return new Ne(e(this.car),this.cdr===Ie?Ie:this.cdr.map(e))}else{return Ie}};var qe=new Map;function Pe(t){var e=t.constructor||Object;var r=Vt(t)==="object"&&e===Object;var i;if(qe.has(e)){i=qe.get(e)}else{qe.forEach(function(e,n){if(t instanceof n&&(n===Object&&r||n!==Object)){i=e}})}return i}var Re=new Map;[[Number.NEGATIVE_INFINITY,"-inf.0"],[Number.POSITIVE_INFINITY,"+inf.0"],[true,"#t"],[false,"#f"],[null,"null"],[F,"#"]].forEach(function(e){var n=Gt(e,2),t=n[0],r=n[1];Re.set(t,r)});function Ce(t){if(t&&Vt(t)==="object"){var r={};var e=Object.getOwnPropertySymbols(t);e.forEach(function(e){var n=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");r[n]=Me(t[e])});var n=Object.getOwnPropertyNames(t);n.forEach(function(e){var n=t[e];if(Vt(n)==="object"&&n.constructor===Object){r[e]=Ce(n)}else{r[e]=Me(n)}});return r}return t}function Me(e,n,t){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(Re.has(e)){return Re.get(e)}if(e instanceof Ne){if(!t){e.markCycles()}return e.toString(n)}if(Number.isNaN(e)){return"+nan.0"}var r=[RegExp,Ae,je,$n,Ln,ft];for(var i=0,a=r;i"}if(yn(e.toString)){return"#"}else{return e.toString()}}if(e instanceof qn){e=e.toString()}if(e===null||typeof e==="string"&&n){return JSON.stringify(e)}if(Vt(e)==="object"){if(typeof e.toString==="function"&&e.toString.__lambda__){return e.toString().valueOf()}var u=e.constructor;if(!u){u=Object}var c;if(typeof u.__className==="string"){c=u.__className}else{if(Te(e)){return"#"}var s=Pe(e);if(s){if(typeof s==="function"){return s(e,n)}else{throw new Error("toString: Invalid repr value")}}c=u.name}if(St(e)==="instance"&&!yn(u)){c="instance"}if(f.HTMLElement&&e instanceof f.HTMLElement){return"#")}if(c!==""){return"#<"+c+">"}if(typeof e[Symbol.iterator]==="function"){return"#"}return"#"}if(typeof e!=="string"){return e.toString()}return e}function Te(e){return e&&Vt(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}Ne.prototype.markCycles=function(){Be(this);return this};Ne.prototype.haveCycles=function(){var e=arguments.length>0&&arguments[0]!==F?arguments[0]:null;if(!e){return this.haveCycles("car")||this.haveCycles("cdr")}return!!(this.cycles&&this.cycles[e])};function Be(e){var n=[];var i=[];var a=[];function o(e){if(!n.includes(e)){n.push(e)}}function u(e,n,t,r){if(t instanceof Ne){if(r.includes(t)){if(!a.includes(t)){a.push(t)}if(!e.cycles){e.cycles={}}e.cycles[n]=t;if(!i.includes(e)){i.push(e)}return true}}}function c(e,n){if(e instanceof Ne){delete e.ref;delete e.cycles;o(e);n.push(e);var t=u(e,"car",e.car,n);var r=u(e,"cdr",e.cdr,n);if(!t){c(e.car,n.slice())}if(!r){c(e.cdr,n.slice())}}}function t(e,n){if(e.cycles[n]instanceof Ne){var t=r.indexOf(e.cycles[n]);e.cycles[n]="#".concat(t,"#")}}c(e,[]);var r=n.filter(function(e){return a.includes(e)});r.forEach(function(e,n){e.ref="#".concat(n,"=")});i.forEach(function(e){t(e,"car");t(e,"cdr")})}Ne.prototype.toString=function(e,n){var t=[];if(this.ref){t.push(this.ref+"(")}else if(!n){t.push("(")}var r;if(this.cycles&&this.cycles.car){r=this.cycles.car}else{r=Me(this.car,e,true)}if(r!==F){t.push(r)}if(this.cdr instanceof Ne){if(this.cycles&&this.cycles.cdr){t.push(" . ");t.push(this.cycles.cdr)}else{if(this.cdr.ref){t.push(" . ")}else{t.push(" ")}var i=this.cdr.toString(e,true);t.push(i)}}else if(this.cdr!==Ie){t=t.concat([" . ",Me(this.cdr,e,true)])}if(!n||this.ref){t.push(")")}return t.join("")};Ne.prototype.set=function(e,n){this[e]=n;if(n instanceof Ne){this.markCycles()}};Ne.prototype.append=function(e){if(e instanceof Array){return this.append(Ne.fromArray(e))}var n=this;if(n.car===F){if(e instanceof Ne){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(e!==Ie){while(true){if(n instanceof Ne&&n.cdr!==Ie){n=n.cdr}else{break}}n.cdr=e}return this};function $e(e){return e<0?-e:e}function De(e,n){var t=Ut(n),r=t[0],i=t.slice(1);while(i.length>0){var a=i,o=Gt(a,1),u=o[0];if(!e(r,u)){return false}var c=i;var s=Ut(c);r=s[0];i=s.slice(1)}return true}function Ue(e,n){if(typeof e==="function"&&typeof n==="function"){return on(e)===on(n)}else if(e instanceof $n&&n instanceof $n){var t;if(e.type===n.type){if(e.type==="complex"){t=e.im.type===n.im.type&&e.re.type===n.re.type}else{t=true}return t&&e.cmp(n)===0}return false}else if(typeof e==="number"||typeof n==="number"){e=$n(e);n=$n(n);return e.type===n.type&&e.cmp(n)===0}else if(e instanceof Ln&&n instanceof Ln){return e["char"]===n["char"]}else if(e instanceof je&&n instanceof je){return e.name===n.name}else{return e===n}}function Je(e,n){if(St(e)!==St(n)){return false}if(!He(e)){return false}if(e instanceof RegExp){return e.source===n.source}if(e instanceof qn){return e.valueOf()===n.valueOf()}return Ue(e,n)}function He(e){return e instanceof je||qn.isString(e)||e instanceof Ln||e instanceof $n||e===true||e===false}var Ye=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function Ge(e,n,t,r){if(typeof this!=="undefined"&&this.constructor!==Ge||typeof this==="undefined"){return new Ge(e,n)}_t("Macro",e,"string",1);_t("Macro",n,"function",2);if(t){if(r){this.__doc__=t}else{this.__doc__=ie(t)}}this.name=e;this.fn=n}Ge.defmacro=function(e,n,t,r){var i=new Ge(e,n,t,r);i.defmacro=true;return i};Ge.prototype.invoke=function(e,n,t){var r=n.env,i=n.dynamic_scope,a=n.error;var o={dynamic_scope:i,error:a,macro_expand:t};var u=this.fn.call(r,e,o,this.name);return u};Ge.prototype.toString=function(){return"#"};var Ve="define-macro";var ze=-1e4;function We(a){return function(){var t=Dt($t.mark(function e(t,v){var r,d,i;return $t.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:i=function e(){i=Dt($t.mark(function e(t,r,i){var a,o,u,c,s,f,l,p,h;return $t.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(!(t instanceof Ne&&t.car instanceof je)){n.next=24;break}if(!t.data){n.next=3;break}return n.abrupt("return",t);case 3:a=i.get(t.car,{throwError:false});if(!(a instanceof Ge&&a.defmacro)){n.next=24;break}o=a instanceof Qe?t:t.cdr;n.next=8;return a.invoke(o,v,true);case 8:u=n.sent;if(!(a instanceof Qe)){n.next=17;break}c=u,s=c.expr,f=c.scope;if(!(s instanceof Ne)){n.next=16;break}if(!(r!==-1&&r<=1||r"};Qe.className="syntax";function Ke(e,n,b,w){var _={"...":{symbols:{},lists:[]}};function x(e){if(ht.get("DEBUG",{throwError:false})){console.log(e)}}x(b);function S(e,n){var t=arguments.length>2&&arguments[2]!==F?arguments[2]:[];var r=arguments.length>3&&arguments[3]!==F?arguments[3]:false;x({code:n&&Me(n,true),pattern:e&&Me(e,true)});if(He(e)&&!(e instanceof je)){return Je(e,n)}if(e instanceof je&&b.includes(e.valueOf())){return je.is(n,e)}if(e instanceof Ne&&e.car instanceof Ne&&e.car.cdr instanceof Ne&&je.is(e.car.cdr.car,w)){x(">> 0");if(n===Ie){x({pattern:e.toString()});if(e.car.car instanceof je){if(e.car.cdr instanceof Ne&&je.is(e.car.cdr.car,w)){var i=e.car.car.valueOf();var a=e.lastPair();if(je.is(a.car,w)){_["..."].symbols[i]=null;return true}else{return false}}var o=e.car.car.valueOf();if(_["..."].symbols[o]){throw new Error("syntax: named ellipsis can only "+"appear onces")}_["..."].symbols[o]=n}}}if(e instanceof Ne&&e.cdr instanceof Ne&&je.is(e.cdr.car,w)){if(e.cdr.cdr!==Ie){if(e.cdr.cdr instanceof Ne){var u=e.cdr.cdr.length();var c=n.length();var s=n;while(c-1>u){s=s.cdr;c--}var f=s.cdr;s.cdr=Ie;if(!S(e.cdr.cdr,f,t,r)){return false}}}if(e.car instanceof je){var l=e.car.name;if(_["..."].symbols[l]&&!t.includes(l)&&!r){throw new Error("syntax: named ellipsis can only appear onces")}x(">> 1");if(n===Ie){x(">> 2");if(r){x("NIL");_["..."].symbols[l]=Ie}else{x("NULL");_["..."].symbols[l]=null}}else if(n instanceof Ne&&(n.car instanceof Ne||n.car===Ie)){x(">> 3 "+r);if(r){if(_["..."].symbols[l]){var p=_["..."].symbols[l];_["..."].symbols[l]=p.append(new Ne(n,Ie))}else{_["..."].symbols[l]=new Ne(n,Ie)}}else{x(">> 4");_["..."].symbols[l]=new Ne(n,Ie)}}else{x(">> 6");if(n instanceof Ne){x(">> 7 "+r);t.push(l);if(!_["..."].symbols[l]){_["..."].symbols[l]=new Ne(n,Ie)}else{var h=_["..."].symbols[l];_["..."].symbols[l]=h.append(new Ne(n,Ie))}x({IIIIII:_["..."].symbols[l].toString()})}else{x(">> 8");return false}}return true}else if(e.car instanceof Ne){var v=Jt(t);if(n===Ie){x(">> 9");_["..."].lists.push(Ie);return true}x(">> 10");var d=n;while(d instanceof Ne){if(!S(e.car,d.car,v,true)){return false}d=d.cdr}return true}return false}if(e instanceof je){if(je.is(e,w)){throw new Error("syntax: invalid usage of ellipsis")}x(">> 11");var m=e.name;if(b.includes(m)){return true}x({name:m,ellipsis:r});if(r){_["..."].symbols[m]=_["..."].symbols[m]||[];_["..."].symbols[m].push(n)}if(!_[m]){_[m]=n}return true}if(e instanceof Ne&&n instanceof Ne){x(">> 12");x({a:12,code:n&&n.toString(),pattern:e.toString()});if(n.cdr===Ie){var y=e.car instanceof je&&e.cdr instanceof je;if(y){x(">> 12 | 1");var g=e.cdr.valueOf();if(!_[g]){_[g]=Ie}g=e.car.valueOf();if(!_[g]){_[g]=n.car}return true}}x("recur");if(S(e.car,n.car,t,r)&&S(e.cdr,n.cdr,t,r)){return true}}else if(e===Ie&&(n===Ie||n===F)){return true}else if(e.car instanceof Ne&&je.is(e.car.car,w)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(S(e,n)){return _}}function Xe(e,i){function a(n){if(n instanceof Ne){if(!i.length){return n}var e=a(n.car);var t=a(n.cdr);return new Ne(e,t)}else if(n instanceof je){var r=i.find(function(e){return e.gensym===n});if(r){return je(r.name)}return n}else{return n}}return a(e)}function Ze(){var e=arguments.length>0&&arguments[0]!==F?arguments[0]:{};var w=e.bindings,n=e.expr,r=e.scope,i=e.symbols,a=e.names,_=e.ellipsis;var o={};function x(e){if(!(e instanceof je||typeof e==="string")){throw new Error("syntax: internal error, rename neeed to be symbol")}var n=e.valueOf();if(n===_){throw new Error("syntax: internal error, ellipis not transformed")}var t=Vt(n);if(["string","symbol"].includes(t)&&n in w){return w[n]}if(i.includes(n)){return je(n)}return u(n)}function S(e){if(ht.get("DEBUG",{throwError:false})){console.log(e)}}function u(e){if(!o[e]){var n=r.get(e,{throwError:false});var t=Fe(e);a.push({name:e,gensym:t});if(typeof n!=="undefined"){r.set(t,n)}o[e]=t}return o[e]}function O(e,n,t){var r=arguments.length>3&&arguments[3]!==F?arguments[3]:function(){};var i=t.nested;S(" ==> "+e.toString());if(e instanceof je){var a=e.valueOf();S("[t 1");if(n[a]){if(n[a]instanceof Ne){var o=n[a],u=o.car,c=o.cdr;if(i){var s=u.car,f=u.cdr;if(f!==Ie){r(a,new Ne(f,Ie))}return s}if(c!==Ie){r(a,c)}return u}else if(n[a]instanceof Array){r(a,n[a].slice(1));return n[a][0]}}return x(a)}if(e instanceof Ne){if(e.car instanceof je&&e.cdr instanceof Ne&&je.is(e.cdr.car,_)){S("[t 2");var l=e.car.valueOf();var p=n[l];if(p===null){return}else if(p){S({b:n[l].toString()});if(p instanceof Ne){S("[t 2 Pair "+i);S({______:p.toString()});var h=p.car,v=p.cdr;if(i){if(v!==Ie){r(l,v)}return h}else{if(h.cdr!==Ie){r(l,new Ne(h.cdr,v))}return h.car}}else if(p instanceof Array){S("[t 2 Array "+i);if(i){r(l,p.slice(1));return Ne.fromArray(p)}else{var d=p.slice(1);if(d.length){r(l,d)}return p[0]}}else{return p}}}S("[t 3 recur "+e.toString());var m=O(e.car,n,t,r);var y=O(e.cdr,n,t,r);return new Ne(m,y)}return e}function k(n,t){var e=Object.values(n);var r=Object.getOwnPropertySymbols(n);if(r.length){e.push.apply(e,Jt(r.map(function(e){return n[e]})))}return e.length&&e.every(function(e){if(e===null){return!t}return e instanceof Ne||e===Ie||e instanceof Array&&e.length})}function j(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function E(i){var e=arguments.length>1&&arguments[1]!==F?arguments[1]:{},n=e.disabled;S(">> "+i.toString());if(i instanceof Ne){if(!n&&i.car instanceof Ne&&je.is(i.car.car,_)){return E(i.car.cdr,{disabled:true})}if(i.cdr instanceof Ne&&je.is(i.cdr.car,_)&&!n){S(">> 1");var t=w["..."].symbols;var r=j(t);if(i.car instanceof Ne){if(w["..."].lists[0]===Ie){return Ie}S(">> 2");var a;if(r.length){S(">> 2 (a)");var o=Wt({},t);a=Ie;var u=function e(){if(!k(o)){return"break"}var r={};var n=function e(n,t){r[n]=t};var t=O(i.car,o,{nested:true},n);if(t!==F){a=new Ne(t,a)}o=r};while(true){var c=u();if(c==="break")break}if(a!==Ie){a=a.reverse()}return a}else{S(">> 3");var s=O(i.car,t,{nested:true});if(s){return new Ne(s,Ie)}return Ie}}else if(i.car instanceof je){S(">> 4");var f=i.car.name;var l=Ht({},f,t[f]);var p=t[f]===null;var h=Ie;var v=function e(){if(!k(l,true)){S({bind:l});return"break"}var r={};var n=function e(n,t){r[n]=t};var t=O(i,l,{nested:false},n);if(typeof t!=="undefined"){h=new Ne(t,h)}l=r};while(true){var d=v();if(d==="break")break}if(h!==Ie){h=h.reverse()}if(i.cdr instanceof Ne){if(i.cdr.cdr instanceof Ne||i.cdr.cdr instanceof je){var m=E(i.cdr.cdr,{disabled:n});if(p){return m}h.append(m)}}return h}}var y=E(i.car,{disabled:n});var g=E(i.cdr,{disabled:n});S({a:true,head:y&&y.toString(),rest:g&&g.toString()});return new Ne(y,g)}if(i instanceof je){if(n&&je.is(i,_)){return i}var b=x(i);if(typeof b!=="undefined"){return b}}return i}return E(n,{})}function en(e){return typeof e==="undefined"||e===Ie||e===null}function nn(e){return e instanceof Promise||e&&typeof e!=="undefined"&&typeof e.then==="function"}function tn(e){switch(Vt(e)){case"string":return qn(e);case"number":if(!Number.isNaN(e)){return $n(e)}}return e}function rn(n){var e=[qn,Ln,$n].some(function(e){return n instanceof e});if(e){return n.valueOf()}return n}function an(e,n){if(e instanceof Ne){e.markCycles();return lt(e)}if(typeof e==="function"){if(n){return un(e,n)}}return tn(e)}function on(e){if(cn(e)){return e[pn]}return e}function un(n,e){if(n[Symbol["for"]("__bound__")]){return n}var t=n.bind(e);var r=Object.getOwnPropertyNames(n).filter(vn);r.forEach(function(e){try{t[e]=n[e]}catch(e){}});dn(t,"__fn__",n);dn(t,"__context__",e);dn(t,"__bound__",true);if(yn(n)){dn(t,"__native__",true)}t.valueOf=function(){return n};return t}function cn(e){return!!(typeof e==="function"&&e[pn])}function sn(e){if(typeof e==="function"){var n=e[ln];if(n&&(n===Mt||n.constructor&&n.constructor.__className)){return true}}return false}function fn(e){function n(e){return e instanceof nt||e instanceof tt}if(typeof e==="function"){if(n(e)){return true}if(n(e[ln])){return true}}return false}var ln=Symbol["for"]("__context__");var pn=Symbol["for"]("__fn__");var hn=["name","length","caller","callee","arguments","prototype"];function vn(e){return!hn.includes(e)}function dn(e,n,t){Object.defineProperty(e,Symbol["for"](n),{get:function e(){return t},set:function e(){},configurable:false,enumerable:false})}function mn(n,t){try{Object.defineProperty(n,"length",{get:function e(){return t}});return n}catch(e){var r=new Array(t).fill(0).map(function(e,n){return"a"+n}).join(",");var i=new Function("f","return function(".concat(r,") {\n return f.apply(this, arguments);\n };"));return i(n)}}function yn(e){var n=Symbol["for"]("__native__");return typeof e==="function"&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[n]===true||!e.name.match(/^bound /)&&!e[n])}function gn(e){var v;switch(e){case Symbol["for"]("letrec"):v="letrec";break;case Symbol["for"]("let"):v="let";break;case Symbol["for"]("let*"):v="let*";break;default:throw new Error("Invalid let_macro value")}return Ge.defmacro(v,function(n,e){var a=e.dynamic_scope,o=e.error,t=e.macro_expand;var u;if(n.car instanceof je){if(!(n.cdr.car instanceof Ne||n.cdr.car===Ie)){throw new Error("let require list of pairs")}var r;if(n.cdr.car===Ie){u=Ie;r=Ie}else{r=n.cdr.car.map(function(e){return e.car});u=n.cdr.car.map(function(e){return e.cdr.car})}return Ne.fromArray([je("letrec"),[[n.car,Ne(je("lambda"),Ne(r,n.cdr.cdr))]],Ne(n.car,u)])}else if(t){return}var c=this;u=this.get("list->array")(n.car);var s=c.inherit(v);var f,l;if(v==="let*"){l=s}else if(v==="let"){f=[]}var p=0;function h(){var e=new Ne(new je("begin"),n.cdr);return Ft(e,{env:s,dynamic_scope:a,error:o})}return function n(){var t=u[p++];if(a){a=v==="let*"?s:c}if(!t){if(f&&f.length){var e=f.map(function(e){return e.value});var r=e.filter(nn);if(r.length){return Promise.all(e).then(function(e){for(var n=0,t=e.length;n1&&arguments[1]!==F?arguments[1]:{},t=n.dynamic_scope,r=n.error;var i=this;if(t){t=this}var a=e;var o=[];while(a instanceof Ne){o.push(Ft(a.car,{env:i,dynamic_scope:t,error:r}));a=a.cdr}var u=o.filter(nn).length;if(u){return Promise.all(o).then(c.bind(this))}else{return c.call(this,o)}})}function wn(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r2?r-2:0),a=2;a1&&arguments[1]!==F?arguments[1]:null;return function(){for(var e=arguments.length,n=new Array(e),t=0;t1?e-1:0),t=1;t=o){return a.apply(this,r)}else{return i}}return i.apply(this,arguments)}}function An(r,i){_t("limit",i,"function",2);return function(){for(var e=arguments.length,n=new Array(e),t=0;t1?r-1:0),a=1;a0){t.push(this._string.substring(0,e))}t.push(n);if(e1&&arguments[1]!==F?arguments[1]:false;if(e instanceof $n){return e}if(typeof this!=="undefined"&&!(this instanceof $n)||typeof this==="undefined"){return new $n(e,n)}if(typeof e==="undefined"){throw new Error("Invlaid LNumber constructor call")}var t=$n.getType(e);if($n.types[t]){return $n.types[t](e,n)}var r=e instanceof Array&&qn.isString(e[0])&&$n.isNumber(e[1]);if(e instanceof $n){return $n(e.value)}if(!$n.isNumber(e)&&!r){throw new Error("You can't create LNumber from ".concat(St(e)))}if(e===null){e=0}var i;if(r){var a=e,o=Gt(a,2),u=o[0],c=o[1];if(u instanceof qn){u=u.valueOf()}if(c instanceof $n){c=c.valueOf()}var s=u.match(/^([+-])/);var f=false;if(s){u=u.replace(/^[+-]/,"");if(s[1]==="-"){f=true}}}if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(r){var l;switch(c){case 8:l="0o";break;case 16:l="0x";break;case 2:l="0b";break;case 10:l="";break}if(typeof l==="undefined"){var p=BigInt(c);i=Jt(u).map(function(e,n){return BigInt(parseInt(e,c))*Math.pow(p,BigInt(n))}).reduce(function(e,n){return e+n})}else{i=BigInt(l+u)}}else{i=BigInt(e)}if(f){i*=BigInt(-1)}}else{i=e}return zn(i,true)}else if(typeof h!=="undefined"&&!(e instanceof h)){if(e instanceof Array){return zn(Bt(h,Jt(e)))}return zn(new h(e))}else if(r){this.value=parseInt(u,c)}else{this.value=e}}$n.types={float:function e(n){var t=arguments.length>1&&arguments[1]!==F?arguments[1]:false;return new Un(n,t)},complex:function e(n){var t=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(!$n.isComplex(n)){n={im:0,re:n}}return new Dn(n,t)},rational:function e(n){var t=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(!$n.isRational(n)){n={num:n,denom:1}}return new Vn(n,t)}};function Dn(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof Dn)||typeof this==="undefined"){return new Dn(e,n)}if(e instanceof Dn){return Dn({im:e.im,re:e.re})}if($n.isNumber(e)&&n){e={im:0,re:e.valueOf()}}else if(!$n.isComplex(e)){throw new Error("Invalid constructor call for LComplex")}var t=e.im instanceof $n?e.im:$n(e.im);var r=e.re instanceof $n?e.re:$n(e.re);if(t.cmp(0)===0&&!n){return r}this.im=t;this.re=r;this.type="complex"}Dn.prototype=Object.create($n.prototype);Dn.prototype.constructor=Dn;Dn.prototype.toRational=function(e){if($n.isFloat(this.im)&&$n.isFloat(this.re)){var n=Un(this.im).toRational(e);var t=Un(this.re).toRational(e);return Dn({im:n,re:t})}return this};Dn.prototype.add=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.add(n),im:t.add(r)}})};Dn.prototype.factor=function(){if(this.im instanceof Un||this.im instanceof Un){var e=this.re,n=this.im;var t,r;if(e instanceof Un){t=e.toRational().mul(e.toRational())}else{t=e.mul(e)}if(n instanceof Un){r=n.toRational().mul(n.toRational())}else{r=n.mul(n)}return t.add(r)}else{return this.re.mul(this.re).add(this.im.mul(this.im))}};Dn.prototype.modulus=function(){return this.factor().sqrt()};Dn.prototype.sqrt=function(){var e=this.modulus();var n,t;if(e.cmp(0)===0){n=t=e}else if(this.re.cmp(0)===1){n=Un(.5).mul(e.add(this.re)).sqrt();t=this.im.div(n).div(2)}else{t=Un(.5).mul(e.sub(this.re)).sqrt();if(this.im.cmp(0)===-1){t=t.sub()}n=this.im.div(t).div(2)}return Dn({im:t,re:n})};Dn.prototype.div=function(e){if($n.isNumber(e)&&!$n.isComplex(e)){e=Dn({im:0,re:e})}else if(!$n.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var n=this.coerce(e),t=Gt(n,2),r=t[0],i=t[1];var a=Dn({re:i.re,im:i.im.sub()});var o=i.factor().valueOf();var u=r.mul(a);var c=u.re.op("/",o);var s=u.im.op("/",o);return Dn({re:c,im:s})};Dn.prototype.sub=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.sub(n),im:t.sum(r)}})};Dn.prototype.mul=function(e){return this.complex_op(e,function(e,n,t,r){var i={re:e.mul(n).sub(t.mul(r)),im:e.mul(r).add(n.mul(t))};return i})};Dn.prototype.complex_op=function(e,n){if($n.isNumber(e)&&!$n.isComplex(e)){if(!(e instanceof $n)){e=$n(e)}var t=e.asType(0);e={im:t,re:e}}else if(!$n.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var r=e.re instanceof $n?e.re:this.re.asType(e.re);var i=e.im instanceof $n?e.im:this.im.asType(e.im);var a=n(this.re,r,this.im,i);if("im"in a&&"re"in a){var o=Dn(a,true);return o}return a};Dn._op={"+":"add","-":"sub","*":"mul","/":"div"};Dn.prototype._op=function(e,n){var t=Dn._op[e];return this[t](n)};Dn.prototype.cmp=function(e){var n=this.coerce(e),t=Gt(n,2),r=t[0],i=t[1];var a=r.re.coerce(i.re),o=Gt(a,2),u=o[0],c=o[1];var s=u.cmp(c);if(s!==0){return s}else{var f=r.im.coerce(i.im),l=Gt(f,2),p=l[0],h=l[1];return p.cmp(h)}};Dn.prototype.valueOf=function(){};Dn.prototype.toString=function(){var e;if(this.re.cmp(0)!==0){e=[this.re.toString()]}else{e=[]}e.push(this.im.cmp(0)<0?"-":"+");e.push(this.im.toString().replace(/^-/,""));e.push("i");return e.join("")};function Un(e){if(typeof this!=="undefined"&&!(this instanceof Un)||typeof this==="undefined"){return new Un(e)}if(!$n.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof $n){return Un(e.valueOf())}if(typeof e==="number"){this.value=e;this.type="float"}}Un.prototype=Object.create($n.prototype);Un.prototype.constructor=Un;Un.prototype.toString=function(){var e=this.value.toString();if(!$n.isFloat(this.value)&&!e.match(/e/i)){return e+".0"}return e.replace(/^([0-9]+)e/,"$1.0e")};Un.prototype._op=function(e,n){if(n instanceof $n){n=n.value}var t=$n._ops[e];if(e==="/"&&this.value===0&&n===0){return NaN}return Un(t(this.value,n))};Un.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==F?arguments[0]:null;if(e===null){return Jn(this.value.valueOf())}return Hn(e.valueOf())(this.value.valueOf())};var Jn=Hn(1e-10);function Hn(r){return function(e){var n=function e(r,n,t){var i=function e(n,t){return t0){i=Gn(r,t)}else if(r.cmp(t)<=0){i=t}else if(t.cmp(0)>0){i=Gn(t,r)}else if(n.cmp(0)<0){i=$n(Gn(r.sub(),t.sub())).sub()}else{i=$n(0)}if($n.isFloat(n)||$n.isFloat(e)){return Un(i)}return i}function Gn(e,n){var t=$n(e).floor();var r=$n(n).floor();if(e.cmp(t)<1){return t}else if(t.cmp(r)===0){var i=$n(1).div(n.sub(r));var a=$n(1).div(e.sub(t));return t.add($n(1).div(Gn(i,a)))}else{return t.add($n(1))}}function Vn(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof Vn)||typeof this==="undefined"){return new Vn(e,n)}if(!$n.isRational(e)){throw new Error("Invalid constructor call for LRational")}var t=$n(e.num);var r=$n(e.denom);if(!n&&r.cmp(0)!==0){var i=t.op("%",r).cmp(0)===0;if(i){return $n(t.div(r))}}this.num=t;this.denom=r;this.type="rational"}Vn.prototype=Object.create($n.prototype);Vn.prototype.constructor=Vn;Vn.prototype.pow=function(e){var n=e.cmp(0);if(n===0){return $n(1)}if(n===-1){e=e.sub();var t=this.denom.pow(e);var r=this.num.pow(e);return Vn({num:t,denom:r})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};Vn.prototype.sqrt=function(){var e=this.num.sqrt();var n=this.denom.sqrt();if(e instanceof Un){e=(Tt("num"),e.toRational())}if(n instanceof Un){n=(Tt("denom"),n.toRational())}return Vn({num:e,denom:n})};Vn.prototype.abs=function(){var e=this.num;var n=this.denom;if(e.cmp(0)===-1){e=e.sub()}if(n.cmp(0)!==1){n=n.sub()}return Vn({num:e,denom:n})};Vn.prototype.cmp=function(e){return $n(this.valueOf(),true).cmp(e)};Vn.prototype.toString=function(){var e=this.num.gcd(this.denom);var n,t;if(e.cmp(1)!==0){n=this.num.div(e);if(n instanceof Vn){n=$n(n.valueOf(true))}t=this.denom.div(e);if(t instanceof Vn){t=$n(t.valueOf(true))}}else{n=this.num;t=this.denom}var r=this.cmp(0)<0;if(r){if(n.abs().cmp(t.abs())===0){return n.toString()}}else if(n.cmp(t)===0){return n.toString()}return n.toString()+"/"+t.toString()};Vn.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 $n._ops["/"](this.num.value,this.denom.value)}return Un(this.num.valueOf()).div(this.denom.valueOf())};Vn.prototype.mul=function(e){if(!(e instanceof $n)){e=$n(e)}if($n.isRational(e)){var n=this.num.mul(e.num);var t=this.denom.mul(e.denom);return Vn({num:n,denom:t})}var r=$n.coerce(this,e),i=Gt(r,2),a=i[0],o=i[1];return a.mul(o)};Vn.prototype.div=function(e){if(!(e instanceof $n)){e=$n(e)}if($n.isRational(e)){var n=this.num.mul(e.denom);var t=this.denom.mul(e.num);return Vn({num:n,denom:t})}var r=$n.coerce(this,e),i=Gt(r,2),a=i[0],o=i[1];var u=a.div(o);return u};Vn.prototype._op=function(e,n){return this[Xn[e]](n)};Vn.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof $n)){e=$n(e)}if($n.isRational(e)){var n=e.num.sub();var t=e.denom;return this.add(Vn({num:n,denom:t}))}if(!(e instanceof $n)){e=$n(e).sub()}else{e=e.sub()}var r=$n.coerce(this,e),i=Gt(r,2),a=i[0],o=i[1];return a.add(o)};Vn.prototype.add=function(e){if(!(e instanceof $n)){e=$n(e)}if($n.isRational(e)){var n=this.denom;var t=e.denom;var r=this.num;var i=e.num;var a,o;if(n!==t){o=t.mul(r).add(i.mul(n));a=n.mul(t)}else{o=r.add(i);a=n}return Vn({num:o,denom:a})}if($n.isFloat(e)){return Un(this.valueOf()).add(e)}var u=$n.coerce(this,e),c=Gt(u,2),s=c[0],f=c[1];return s.add(f)};function zn(e,n){if(typeof this!=="undefined"&&!(this instanceof zn)||typeof this==="undefined"){return new zn(e,n)}if(e instanceof zn){return zn(e.value,e._native)}if(!$n.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.value=e;this._native=n;this.type="bigint"}zn.prototype=Object.create($n.prototype);zn.prototype.constructor=zn;zn.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};zn.prototype._op=function(e,n){if(typeof n==="undefined"){if($n.isBN(this.value)){e=zn.bn_op[e];return zn(this.value.clone()[e](),false)}return zn($n._ops[e](this.value),true)}if($n.isBN(this.value)&&$n.isBN(n.value)){e=zn.bn_op[e];return zn(this.value.clone()[e](n),false)}var t=$n._ops[e](this.value,n.value);if(e==="/"){var r=this.op("%",n).cmp(0)===0;if(r){return $n(t)}return Vn({num:this,denom:n})}return zn(t,true)};zn.prototype.sqrt=function(){var e;var n=this.cmp(0)<0;if($n.isNative(this.value)){e=$n(Math.sqrt(n?-this.valueOf():this.valueOf()))}else if($n.isBN(this.value)){e=n?this.value.neg().sqrt():this.value.sqrt()}if(n){return Dn({re:0,im:e})}return e};$n.prototype.gcd=function(e){var n=this.abs();e=e.abs();if(e.cmp(n)===1){var t=n;n=e;e=t}while(true){n=n.rem(e);if(n.cmp(0)===0){return e}e=e.rem(n);if(e.cmp(0)===0){return n}}};$n.isFloat=function e(n){return n instanceof Un||Number(n)===n&&n%1!==0};$n.isNumber=function(e){return e instanceof $n||!Number.isNaN(e)&&$n.isNative(e)||$n.isBN(e)};$n.isComplex=function(e){var n=e instanceof Dn||$n.isNumber(e.im)&&$n.isNumber(e.re);return n};$n.isRational=function(e){return e instanceof Vn||$n.isNumber(e.num)&&$n.isNumber(e.denom)};$n.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};$n.isBigInteger=function(e){return e instanceof zn||typeof e==="bigint"||$n.isBN(e)};$n.isBN=function(e){return typeof h!=="undefined"&&e instanceof h};$n.getArgsType=function(e,n){if(e instanceof Un||n instanceof Un){return Un}if(e instanceof zn||n instanceof zn){return zn}return $n};$n.prototype.toString=$n.prototype.toJSON=function(e){if(e>2&&e<36){return this.value.toString(e)}return this.value.toString()};$n.prototype.asType=function(e){var n=$n.getType(this);return $n.types[n]?$n.types[n](e):$n(e)};$n.prototype.isBigNumber=function(){return typeof this.value==="bigint"||typeof h!=="undefined"&&!(this.value instanceof h)};["floor","ceil","round"].forEach(function(e){$n.prototype[e]=function(){if(this["float"]||$n.isFloat(this.value)){return $n(Math[e](this.value))}else{return $n(Math[e](this.valueOf()))}}});$n.prototype.valueOf=function(){if($n.isNative(this.value)){return Number(this.value)}else if($n.isBN(this.value)){return this.value.toNumber()}};var Wn=function(){var e=function e(n,t){return[n,t]};return{bigint:{bigint:e,float:function e(n,t){return[Un(n.valueOf()),t]},rational:function e(n,t){return[{num:n,denom:1},t]},complex:function e(n,t){return[{im:0,re:n},t]}},float:{bigint:function e(n,t){return[n,t&&Un(t.valueOf())]},float:e,rational:function e(n,t){return[n,t&&Un(t.valueOf())]},complex:function e(n,t){return[{re:n,im:Un(0)},t]}},complex:{bigint:n("bigint"),float:n("float"),rational:n("rational"),complex:function e(n,t){var r=$n.coerce(n.re,t.re),i=Gt(r,2),a=i[0],o=i[1];var u=$n.coerce(n.im,t.im),c=Gt(u,2),s=c[0],f=c[1];return[{im:s,re:a},{im:f,re:o}]}},rational:{bigint:function e(n,t){return[n,t&&{num:t,denom:1}]},float:function e(n,t){return[Un(n.valueOf()),t]},rational:e,complex:function e(n,t){return[{im:Qn(n.type,t.im.type,0),re:Qn(n.type,t.re.type,n)},{im:Qn(n.type,t.im.type,t.im),re:Qn(n.type,t.re.type,t.re)}]}}};function n(t){return function(e,n){return[{im:Qn(t,e.im.type,e.im),re:Qn(t,e.re.type,e.re)},{im:Qn(t,e.im.type,0),re:Qn(t,n.type,n)}]}}}();function Qn(e,n,t){return Wn[e][n](t)[0]}$n.coerce=function(e,n){function t(e){if(e==="integer"){return"bigint"}return e}var r=t($n.getType(e));var i=t($n.getType(n));if(!Wn[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!Wn[r][i]){throw new Error("LNumber::coerce unknown rhs type ".concat(i))}return Wn[r][i](e,n).map(function(e){return $n(e,true)})};$n.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof $n)){throw new Error("LNumber: you can't coerce ".concat(St(e)))}if(typeof e==="number"){e=$n(e)}return $n.coerce(this,e)};$n.getType=function(e){if(e instanceof $n){return e.type}if($n.isFloat(e)){return"float"}if($n.isComplex(e)){return"complex"}if($n.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof h!=="undefined"&&!(e instanceof h)){return"bigint"}};$n.prototype.isFloat=function(){return!!($n.isFloat(this.value)||this["float"])};var Kn={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var Xn={};Object.keys(Kn).forEach(function(n){Xn[Kn[n]]=n;$n.prototype[n]=function(e){return this.op(Kn[n],e)}});$n._ops={"*":function e(n,t){return n*t},"+":function e(n,t){return n+t},"-":function e(n,t){if(typeof t==="undefined"){return-n}return n-t},"/":function e(n,t){return n/t},"%":function e(n,t){return n%t},"|":function e(n,t){return n|t},"&":function e(n,t){return n&t},"~":function e(n){return~n},">>":function e(n,t){return n>>t},"<<":function e(n,t){return n<=this._string.length){return at}return Ln(this._string[this._in_char])};function tt(e){if(typeof this!=="undefined"&&!(this instanceof tt)||typeof this==="undefined"){return new tt(e)}_t("OutputPort",e,"function");this.write=e}tt.prototype.toString=function(){return"<#output-port>"};function rt(n){var t=this;if(typeof this!=="undefined"&&!(this instanceof rt)||typeof this==="undefined"){return new rt(n)}_t("OutputStringPort",n,"function");this._buffer=[];this.write=function(e){if(!qn.isString(e)){e=n(e)}else{e=e.valueOf()}t._buffer.push(e)}}rt.prototype=Object.create(tt.prototype);rt.prototype.getString=function(){return this._buffer.map(function(e){return e.valueOf()}).join("")};rt.prototype.constructor=rt;function it(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof it)||typeof this==="undefined"){return new it(e)}_t("InputStringPort",e,"string");this._string=e.valueOf();this._index=0;this._in_char=0;this.read=function(){return n.get_next_tokens()}}it.prototype=Object.create(nt.prototype);it.prototype.constructor=it;it.prototype.read_line=function(){var e=this._string.substring(this._in_char);if(!e){return at}var n=e.match(/([^\n])(?:\n|$)/)[0];this._in_char+=n.length;return n};var at=new ot;function ot(){}ot.prototype.toString=function(){return"<#eof>"};function ut(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:{};if(typeof this!=="undefined"&&!(this instanceof ut)||typeof this==="undefined"){return new ut(e,n)}if(typeof e==="undefined"){e="anonymous"}this.env=ht.inherit(e,n)}ut.prototype.exec=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;_t("Intepreter::exec",e,"string",1);_t("Intepreter::exec",n,"boolean",2);pt.set("**interaction-environment**",this.env);return At(e,this.env,n?this.env:false)};ut.prototype.get=function(e){return this.env.get(e).bind(this.env)};ut.prototype.set=function(e,n){return this.env.set(e,n)};function ct(e,n,t){if(arguments.length===1){if(Vt(arguments[0])==="object"){e=arguments[0];this.parent=null}else if(typeof arguments[0]==="string"){e={};n={};t=arguments[0]}}this.docs=new Map;this.env=e;this.parent=n;this.name=t||"anonymous"}ct.prototype.inherit=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:{};if(Vt(e)==="object"){n=e}if(!e||Vt(e)==="object"){e="child of "+(this.name||"unknown")}return new ct(n||{},this,e)};ct.prototype.doc=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:null;if(e instanceof je){e=e.name}if(e instanceof qn){e=e.valueOf()}if(n){this.docs.set(e,n);return this}if(this.docs.has(e)){return this.docs.get(e)}if(this.parent){return this.parent.doc(e)}};ct.prototype.newFrame=function(e,n){var r=this.inherit("__frame__");r.set("parent.frame",re(function(){var e=arguments.length>0&&arguments[0]!==F?arguments[0]:1;var n=r.parent;if(!(n instanceof ct)){return Ie}if(e<=0){return n}var t=n.get("parent.frame");return t(e-1)},pt.env["parent.frame"].__doc__));n.callee=e;r.set("arguments",n);return r};ct.prototype._lookup=function(e){if(e instanceof je){e=e.name}if(e instanceof qn){e=e.valueOf()}if(this.env.hasOwnProperty(e)){return st(this.env[e])}if(this.parent){return this.parent._lookup(e)}};ct.prototype.toString=function(){return"<#env:"+this.name+">"};ct.prototype.clone=function(){var n=this;var t={};Object.keys(this.env).forEach(function(e){t[e]=n.env[e]});return new ct(t,this.parent,this.name)};ct.prototype.merge=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:"merge";_t("Environment::merge",e,"environment");return this.inherit(n,e.env)};function st(e){if(typeof this!=="undefined"&&!(this instanceof st)||typeof this==="undefined"){return new st(e)}this.value=e}st.isUndefined=function(e){return e instanceof st&&typeof e.value==="undefined"};st.prototype.valueOf=function(){return this.value};function ft(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof ft)||typeof this==="undefined"){return new ft(e)}this.values=e}ft.prototype.toString=function(){return this.values.map(function(e){return Me(e)}).join("\n")};ft.prototype.valueOf=function(){return this.values};ct.prototype.get=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:{};var t=n.throwError,r=t===void 0?true:t;var i=e;if(i instanceof je||i instanceof qn){i=i.valueOf()}var a=this._lookup(i);if(a instanceof st){if(st.isUndefined(a)){return F}return an(a.valueOf())}if(typeof i==="string"){var o=i.split(".").filter(Boolean);if(o.length>0){var u=Ut(o),c=u[0],s=u.slice(1);a=this._lookup(c);if(s.length){try{if(a instanceof st){a=a.valueOf()}else{a=Nn(f,c);if(typeof a==="function"){a=on(a)}}return Nn.apply(void 0,[a].concat(Jt(s)))}catch(e){}}else if(a instanceof st){return an(a.valueOf())}}a=Nn(f,i)}if(typeof a!=="undefined"){return a}if(r){throw new Error("Unbound variable `"+i.toString()+"'")}};ct.prototype.set=function(e,n){var t=arguments.length>2&&arguments[2]!==F?arguments[2]:null;if($n.isNumber(n)){n=$n(n)}if(e instanceof je){e=e.name}if(e instanceof qn){e=e.valueOf()}this.env[e]=n;if(t){this.doc(e,t)}return this};ct.prototype.has=function(e){return this.env.hasOwnProperty(e)};ct.prototype.ref=function(e){var n=this;while(true){if(!n){break}if(n.has(e)){return n}n=n.parent}};ct.prototype.parents=function(){var e=this;var n=[];while(e){n.unshift(e);e=e.parent}return n};function lt(e){if(nn(e)){return e.then(lt)}if(e instanceof Ne||e instanceof je){e.data=true}return e}var pt=new ct({nil:Ie,undefined:F,true:true,false:false,null:null,NaN:NaN,stdout:new tt(function(){var e;(e=console).log.apply(e,arguments)}),stdin:nt(function(){return new Promise(function(e){e(prompt(""))})}),"open-input-string":re(function(e){_t("open-input-string",e,"string");return it(e)},"(open-input-string string)\n\n Function create new string port as input that can be used to\n read S-exressions from this port using `read` function."),"output-port?":re(function(e){return e instanceof tt},"(output-port? arg)\n\n Function return true if argument is output port."),"input-port?":re(function(e){return e instanceof nt},"(input-port? arg)\n\n Function return true if argument is input port."),"open-output-string":re(function(){return rt(this.get("repr"))},"(open-output-string)\n\n Function create new output port that can used to write string into\n and after finish get the whole string using `get-output-string`"),"get-output-string":re(function(e){_t("get-output-string",e,"output-string-port");return e.getString()},"(get-output-string port)\n\n Function get full string from string port. If nothing was wrote\n to given port it will return empty string."),"eof-object?":re(function(e){return e===at},"(eof-object? arg)\n\n Function check if value is eof object, returned from input string\n port when there are no more data to read."),"peek-char":re(function(e){_t("peek-char",e,["input-port","input-string-port"]);return e.peek_char()},"(peek-char port)\n\n Function get character from string port or EOF object if no more\n data in string port."),"read-line":re(function(e){if(typeof e==="undefined"){e=this.get("stdin")}_t("read-line",e,["input-port","input-string-port"]);return e.read_line()},"(read-char port)\n\n Function read next character from input port."),"read-char":re(function(e){if(typeof e==="undefined"){e=this.get("stdin")}_t("read-char",e,["input-port","input-string-port"]);return e.read_char()},"(read-char port)\n\n Function read next character from input port."),read:re(function e(n){if(qn.isString(n)){return ee(W(n.valueOf()))[0]}var t;if(n instanceof nt){t=n}else{t=this.get("stdin")}return ne(t.read(),function(e){if(e===at){return at}return ee(e)[0]})},"(read [string])\n\n Function if used with string will parse the string and return\n list structure of LIPS code. If called without an argument it\n will read string from standard input (using browser prompt or\n user defined way) and call itself with that string (parse is)\n function can be used together with eval to evaluate code from\n string"),pprint:re(function(e){if(e instanceof Ne){e=new Mt.Formatter(e.toString(true))["break"]().format();this.get("display").call(this,e)}else{this.get("write").call(this,e)}this.get("newline").call(this)},"(pprint expression)\n\n Pretty print list expression, if called with non-pair it just call\n print function with passed argument."),print:re(function(){var n=this;var t=this.get("display");var r=this.get("newline");for(var e=arguments.length,i=new Array(e),a=0;a1?t-1:0),i=1;ir.length){throw new Error("Not enough arguments")}var u=0;var c=this.get("repr");n=n.replace(a,function(e){var n=e[1];if(n==="~"){return"~"}else if(n==="%"){return"\n"}else{var t=r[u++];if(n==="a"){return c(t)}else{return c(t,true)}}});o=n.match(/~([\S])/);if(o){throw new Error("format: Unrecognized escape seqence ".concat(o[1]))}return n},"(format string n1 n2 ...)\n\n Function accepts string template and replacing any escape sequences\n by arguments:\n\n * ~a value as if printed with display\n * ~s value as if printed with write\n * ~% newline character\n * ~~ literal tilde '~' is inserted\n\n if there missing arguments or other escape character it throw exception."),display:re(function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:null;if(n===null){n=this.get("stdout")}n.write.call(this,this.get("repr")(e))},"(display arg [port])\n\n Function send string to standard output or provied port."),error:re(function(){for(var e=arguments.length,n=new Array(e),t=0;t1&&arguments[1]!==F?arguments[1]:{},t=n.dynamic_scope,r=n.error;if(t){t=this}var o;var i=Ft(e.cdr.car,{env:this,dynamic_scope:t,error:r});i=Ot(i);function u(n,t){if(nn(n)){return n.then(function(e){return u(e,t)})}if(nn(t)){return t.then(function(e){return u(n,e)})}f[n]=t;return t}if(e.car instanceof Ne&&je.is(e.car.car,".")){var c=e.car.cdr.car;var s=e.car.cdr.cdr.car;var f=Ft(c,{env:this,dynamic_scope:t,error:r});var l=Ft(s,{env:this,dynamic_scope:t,error:r});return u(l,i)}if(!(e.car instanceof je)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var p=e.car.valueOf();o=this.ref(e.car.name);return ne(i,function(e){if(!o){var n=p.split(".");if(n.length>1){var t=n.pop();var r=n.join(".");var i=a.get(r,{throwError:false});if(i){a.get("set-obj!").call(a,i,t,e);return}}o=a}o.set(p,e)})}),"(set! name value)\n\n Macro that can be used to set the value of the variable (mutate)\n it search the scope chain until it finds first non emtpy slot and set it."),"unset!":re(new Ge("set!",function(e){if(!(e.car instanceof je)){throw new Error("unset! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var n=e.car;var t=this.ref(n);if(t){delete t.env[n.name]}}),"(unset! name)\n\n Function delete specified name from environment."),"set-car!":re(function(e,n){_t("set-car!",e,"pair");e.car=n},"(set-car! obj value)\n\n Function that set car (head) of the list/pair to specified value.\n It can destroy the list. Old value is lost."),"set-cdr!":re(function(e,n){_t("set-cdr!",e,"pair");e.cdr=n},"(set-cdr! obj value)\n\n Function that set cdr (tail) of the list/pair to specified value.\n It can destroy the list. Old value is lost."),"empty?":re(function(e){return typeof e==="undefined"||e===Ie},"(empty? object)\n\n Function return true if value is undfined empty list."),assoc:re(function(e,n){if(e instanceof Ne&&!(n instanceof Ne)){throw new Error("First argument to assoc ned to be a key")}_t("assoc",n,"pair");var t=n;while(true){if(!(t instanceof Ne)||this.get("empty?")(t)){break}var r=t.car.car;if(Ue(r,e)){return t.car}else if(!t.haveCycles("cdr")){t=t.cdr}}return Ie},"(assoc key alist)\n\n Function search Alist (list of pairs) until it find the one that\n have head set equal to key, and return found pair."),gensym:re(Fe,"(gensym)\n\n Function generate unique symbol, to use with macros as meta name."),load:re(function(n){_t("load",n,"string");var e=this;if(e.name==="__frame__"){e=e.parent}var i;if(e===pt){i=e}else{i=this.get("**interaction-environment**")}var a="**module-path**";var o=pt.get(a,{throwError:false});n=n.valueOf();if(!n.match(/.[^.]+$/)){n+=".scm"}if(typeof this.get("global",{throwError:false})!=="undefined"){return new Promise(function(t,r){var e=require("path");if(o){o=o.valueOf();n=e.join(o,n)}pt.set(a,e.dirname(n));require("fs").readFile(n,function(e,n){if(e){console.log(e);r(e);pt.set(a,o)}else{At(n.toString(),i).then(function(){t();pt.set(a,o)})["catch"](r)}})})}if(o){o=o.valueOf();n=o+"/"+n.replace(/^\.?\/?/,"")}return f.fetch(n).then(function(e){return e.text()}).then(function(e){pt.set(a,n.replace(/\/[^/]*$/,""));return At(e,i)}).then(function(){})["finally"](function(){pt.set(a,o)})},"(load filename)\n\n Function fetch the file and evaluate its content as LIPS code."),while:re(new Ge("while",function(r,e){var i=e.dynamic_scope,a=e.error;var o=this;var u=new Ne(new je("begin"),r.cdr);var c;if(i){i=o}return function n(){var e=Ft(r.car,{env:o,dynamic_scope:i,error:a});function t(e){if(e&&!en(e)){c=Ft(u,{env:o,dynamic_scope:i,error:a});if(nn(c)){return c.then(function(e){c=e;return n()})}else{return n()}}else{return c}}return ne(e,t)}()}),"(while cond . body)\n\n Macro that create a loop, it exectue body untill cond expression is false"),if:re(new Ge("if",function(t,e){var r=e.dynamic_scope,i=e.error;if(r){r=this}var a=this;var n=function e(n){if(n){return Ft(t.cdr.car,{env:a,dynamic_scope:r,error:i})}else{return Ft(t.cdr.cdr.car,{env:a,dynamic_scope:r,error:i})}};var o=Ft(t.car,{env:a,dynamic_scope:r,error:i});return ne(o,n)}),"(if cond true-expr false-expr)\n\n Macro evaluate condition expression and if the value is true, it\n evaluate and return true expression if not it evaluate and return\n false expression"),"let-env":new Ge("let-env",function(n){var e=arguments.length>1&&arguments[1]!==F?arguments[1]:{};var t=e.dynamic_scope,r=e.error;_t("let-env",n,"pair");var i=Ft(n.car,{env:this,dynamic_scope:t,error:r});return ne(i,function(e){if(!(e instanceof ct)){throw new Error("let-env: First argument need to be "+"environment")}return Ft(Ne(je("begin"),n.cdr),{env:e,dynamic_scope:t,error:r})})},"(let-env env . body)\n\n Special macro that evaluate body in context of given environment\n object."),letrec:re(gn(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*":re(gn(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:re(gn(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*":re(bn("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:re(new Ge("begin",function(e,n){var r=Object.assign({},n);var i=this.get("list->array")(e);if(r.dynamic_scope){r.dynamic_scope=this}r.env=this;var a;return function n(){if(i.length){var e=i.shift();var t=Ft(e,r);return ne(t,function(e){a=e;return n()})}else{return a}}()}),"(begin . args)\n\n Macro runs list of expression and return valuate of the list one.\n It can be used in place where you can only have single exression,\n like if expression."),ignore:new Ge("ignore",function(e,n){var t=n.dynamic_scope,r=n.error;var i={env:this,error:r};if(t){i.dynamic_scope=this}Ft(new Ne(new je("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:re(Ge.defmacro("define",function(t,e){var r=this;if(t.car instanceof Ne&&t.car.car instanceof je){var n=new Ne(new je("define"),new Ne(t.car.car,new Ne(new Ne(new je("lambda"),new Ne(t.car.cdr,t.cdr)))));return n}else if(e.macro_expand){return}if(e.dynamic_scope){e.dynamic_scope=this}e.env=r;var i=t.cdr.car;if(i instanceof Ne){i=Ft(i,e)}else if(i instanceof je){i=r.get(i)}_t("define",t.car,"symbol");return ne(i,function(e){if(r.name===Qe.merge_env){r=r.parent}var n;if(t.cdr.cdr instanceof Ne&&qn.isString(t.cdr.cdr.car)){n=t.cdr.cdr.car.valueOf()}r.set(t.car,e,n)})}),"(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!":re(function(e,n,t){var r=Vt(e);if(en(e)||r!=="object"&&r!=="function"){var i=wt("set-obj!",St(e),["object","function"]);throw new Error(i)}e=on(e);n=n.valueOf();if(arguments.length===2){delete e[n]}else if(Te(e)&&typeof t==="function"){e[n]=on(t);e[n].__prototype__=true}else if(typeof t==="function"){e[n]=t}else{e[n]=t?t.valueOf():t}},"(set-obj! obj key value)\n\n Function set property of JavaScript object"),"null-environment":re(function(){return pt.inherit("null")},"(null-environment)\n\n Function return new base environment with std lib."),values:re(function(){for(var e=arguments.length,n=new Array(e),t=0;t1&&arguments[1]!==F?arguments[1]:{},p=e.dynamic_scope,h=e.error;var v=this;var d;if(l.cdr instanceof Ne&&qn.isString(l.cdr.car)&&l.cdr.cdr!==Ie){d=l.cdr.car.valueOf()}function m(){var e;if(p){if(!(this instanceof ct)){e=v}else{e=this}}else{e=v}e=e.inherit("lambda");var n=l.car;var t=0;var r;if(typeof this!=="undefined"){e.set("this",this)}for(var i=arguments.length,a=new Array(i),o=0;o2&&arguments[2]!==F?arguments[2]:c;if(e instanceof Ne){var r=e.car;var i=e.cdr;if(t(r)){r=n(r)}if(t(i)){i=n(i)}if(nn(r)||nn(i)){return Promise.all([r,i]).then(function(e){var n=Gt(e,2),t=n[0],r=n[1];return new Ne(t,r)})}else{return new Ne(r,i)}}return e}function i(e,n){if(e instanceof Ne){if(n!==Ie){e.append(n)}}else{e=new Ne(e,n)}return e}function f(r,e,n){if(et){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(e.cdr instanceof Ne){if(e.cdr.cdr!==Ie){if(e.cdr.car instanceof Ne){var i=Ie;return function n(t){if(t===Ie){return i}return ne(Ft(t.car,{env:u,dynamic_scope:a,error:o}),function(e){i=new Ne(e,i);return n(t.cdr)})}(e.cdr)}else{return e.cdr}}else{return Ft(e.cdr.car,{env:u,dynamic_scope:a,error:o})}}else{return e.cdr}}return s(e,function(e){return p(e,n,t)})}return e}function t(e){if(e instanceof Ne){delete e.data;if(!e.haveCycles("car")){t(e.car)}if(!e.haveCycles("cdr")){t(e.cdr)}}}var r=p(e.car,0,1);return ne(r,function(e){t(e);return lt(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:re(function(e){_t("clone",e,"pair");return e.clone()},"(clone list)\n\n Function return clone of the list."),append:re(function(e,n){_t("append",e,["nil","pair"]);if(e instanceof Ne){e=e.clone()}return this.get("append!").call(this,e,n)},"(append list item)\n\n Function will create new list with value appended to the end. It return\n New list."),"append!":re(function(e,n){_t("append!",e,["pair","nil"]);if(!this.get("list?")(e)){throw new Error("append!: Invalid argument, value is not a list")}if(en(n)){return e}if(e===Ie){if(n===Ie){return Ie}return n}return e.append(n)},"(append! name expression)\n\n Destructive version of append, it modify the list in place. It return\n original list."),reverse:re(function(e){_t("reverse",e,["array","pair","nil"]);if(e===Ie){return Ie}if(e instanceof Ne){var n=this.get("list->array")(e).reverse();return this.get("array->list")(n)}else if(!(e instanceof Array)){throw new Error(wt("reverse",St(e),"array or pair"))}else{return e.reverse()}},"(reverse list)\n\n Function will reverse the list or array. If value is not a list\n or array it will throw exception."),nth:re(function(e,n){_t("nth",e,"number");_t("nth",n,["array","pair"]);if(n instanceof Ne){var t=n;var r=0;while(rarray")(n).join(e)},"(join separator list)\n\n Function return string by joining elements of the list"),split:re(function(e,n){_t("split",e,["regex","string"]);_t("split",n,"string");return this.get("array->list")(n.split(e))},"(split separator string)\n\n Function create list by splitting string by separatar that can\n be a string or regular expression."),replace:re(function(e,n,t){_t("replace",e,["regex","string"]);_t("replace",n,["string","function"]);_t("replace",t,"string");return t.replace(e,n)},"(replace pattern replacement string)\n\n Function change pattern to replacement inside string. Pattern can be string\n or regex and replacement can be function or string."),match:re(function(e,n){_t("match",e,["regex","string"]);_t("match",n,"string");var t=n.match(e);return t?this.get("array->list")(t):Ie},"(match pattern string)\n\n function return match object from JavaScript as list."),search:re(function(e,n){_t("search",e,["regex","string"]);_t("search",n,"string");return n.search(e)},"(search pattern string)\n\n Function return first found index of the pattern inside a string"),repr:re(function e(n,t){return Me(n,t)},"(repr obj)\n\n Function return string LIPS representation of an object as string."),env:re(function(e){e=e||this;var n=Object.keys(e.env);var t;if(n.length){t=Ne.fromArray(n)}else{t=Ie}if(e.parent!==F){return this.get("env").call(this,e.parent).append(t)}return t},"(env obj)\n\n Function return list values (functions and variables) inside environment."),new:re(function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r2&&arguments[2]!==F?arguments[2]:K.LITERAL;_t("set-special!",e,"string",1);_t("set-special!",n,"symbol",2);Mt.specials.append(e.valueOf(),n,t)},'(set-special! symbol name [type])\n\n Add special symbol to the list of transforming operators by the parser.\n e.g.: `(add-special! "#" \'x)` will allow to use `#(1 2 3)` and it will be\n transformed into (x (1 2 3)) so you can write x macro that will process\n the list. 3rd argument is optional and it can be constant value\n lips.specials.SPLICE if this constant is used it will transform\n `#(1 2 3)` into (x 1 2 3) that is required by # that define vectors.'),get:Nn,".":Nn,unbind:re(on,"(unbind fn)\n\n Function remove bidning from function so you can get props from it."),type:re(St,"(type object)\n\n Function return type of an object as string."),debugger:re(function(){debugger},"(debugger)\n\n Function stop JavaScript code in debugger."),in:re(function(e,n){if(e instanceof je||e instanceof qn){e=e.valueOf()}return e in n},"(in key value)\n\n Function use is in operator to check if value is in object."),instanceof:re(function(e,n){return n instanceof on(e)},"(instanceof type obj)\n\n Function check of object is instance of object."),"prototype?":re(Te,"(prototype? obj)\n\n Function check if value is JavaScript Object prototype."),"macro?":re(function(e){return e instanceof Ge},"(macro? expression)\n\n Function check if value is a macro."),"function?":re(function(e){return typeof e==="function"},"(function? expression)\n\n Function check if value is a function."),"real?":re(function(e){if(St(e)!=="number"){return false}if(e instanceof $n){return e.isFloat()}return $n.isFloat(e)},"(real? number)\n\n Function check if value is real number."),"number?":re($n.isNumber,"(number? expression)\n\n Function check if value is a number"),"string?":re(function(e){return qn.isString(e)},"(string? expression)\n\n Function check if value is a string."),"pair?":re(function(e){return e instanceof Ne},"(pair? expression)\n\n Function check if value is a pair or list structure."),"regex?":re(function(e){return e instanceof RegExp},"(regex? expression)\n\n Function check if value is regular expression."),"null?":re(function(e){return en(e)},"(null? expression)\n\n Function check if value is nulish."),"boolean?":re(function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Function check if value is boolean."),"symbol?":re(function(e){return e instanceof je},"(symbol? expression)\n\n Function check if value is LIPS symbol"),"array?":re(function(e){return e instanceof Array},"(array? expression)\n\n Function check if value is an arrray."),"object?":re(function(e){return e!==Ie&&e!==null&&!(e instanceof $n)&&Vt(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Function check if value is an object."),flatten:re(function(e){_t("flatten",e,"pair");return e.flatten()},"(flatten list)\n\n Return shallow list from tree structure (pairs)."),"array->list":re(function(e){_t("array->list",e,"array");return Ne.fromArray(e)},"(array->list array)\n\n Function convert JavaScript array to LIPS list."),"tree->array":re(Le("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":re(Le("list->array"),"(list->array list)\n\n Function convert LIPS list into JavaScript array."),apply:re(function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;rarray").call(this,i));return e.apply(this,t)},"(apply fn list)\n\n Function that call function with list of arguments."),length:re(function(e){if(!e){return $n(0)}if(e instanceof Ne){return $n(e.length())}if("length"in e){return $n(e.length)}},"(length expression)\n\n Function return length of the object, the object can be list\n or any object that have length property."),"string->number":re(function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:10;_t("string->number",e,"string",1);_t("string->number",n,"number",2);e=e.valueOf();n=n.valueOf();if(e.match(S)||e.match(w)){return A(e,n)}else if(e.match(O)||e.match(b)){return L(e,n)}else{var t=n===10&&!e.match(/e/i)||n===16;if(e.match(x)&&t||e.match(_)){return I(e,n)}if(e.match(c)){return R(e)}}return false},"(string->number number [radix])\n\n Function convert string to number."),try:re(new Ge("try",function(a,e){var o=this;var u=e.dynamic_scope,c=e.error;return new Promise(function(i){var e={env:o,error:function e(n){var t=o.inherit("try");t.set(a.cdr.car.cdr.car.car,n);var r={env:t,error:c};if(u){r.dynamic_scope=o}ne(Ft(new Ne(new je("begin"),a.cdr.car.cdr.cdr),r),function(e){i(e)})}};if(u){e.dynamic_scope=o}var n=Ft(a.car,e);if(nn(n)){n.then(i)["catch"](e.error)}else{i(n)}})}),"(try expr (catch (e) code)"),throw:re(function(e){throw new Error(e)},"(throw string)\n\n Throw new expection."),find:re(function n(t,r){_t("find",t,["regex","function"]);_t("find",r,"pair");if(en(r)){return Ie}var e=te("find",t);return ne(e(r.car),function(e){if(e&&e!==Ie){return r.car}return n(t,r.cdr)})},"(find fn list)\n (find regex list)\n\n Higher order Function find first value for which function return true.\n If called with regex it will create matcher function."),"for-each":re(function(e){var n;_t("for-each",e,"function");for(var t=arguments.length,r=new Array(t>1?t-1:0),i=1;i1?n-1:0),a=1;a3?r-3:0),a=3;a3?i-3:0),o=3;oarray")(n);var a=[];var o=te("filter",e);return function n(t){function e(e){if(e&&e!==Ie){a.push(r)}return n(++t)}if(t===i.length){return Ne.fromArray(a)}var r=i[t];return ne(o(r,t),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher order function that call `fn` for each element of the list\n and return list for only those elements for which funtion return\n true value. If called with regex it will create matcher function."),range:re(function(e){_t("range",e,"number");if(e instanceof $n){e=e.valueOf()}return Ne.fromArray(new Array(e).fill(0).map(function(e,n){return $n(n)}))},"(range n)\n\n Function return list of n numbers from 0 to n - 1"),compose:re(xn,"(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:re(_n,"(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:re(Fn,"(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:re(function e(){for(var n=arguments.length,t=new Array(n),r=0;rr?n%=r:r%=n}n=$e(i*(t<0||arguments.length<=t?F:arguments[t]))/(n+r)}return $n(n)},"(lcm n1 n2 ...)\n\n Function return the least common multiple of their arguments."),"odd?":re(kn(function(e){return $n(e).isOdd()}),"(odd? number)\n\n Function check if number os odd."),"even?":re(kn(function(e){return $n(e).isEven()}),"(even? number)\n\n Function check if number is even."),"*":re(En(function(e,n){return $n(e).mul(n)},$n(1)),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":re(En(function(e,n){return $n(e).add(n)},$n(0)),"(+ . numbers)\n\n Sum all numbers passed as arguments. If single value is passed it will\n return that value."),"-":re(function(){for(var e=arguments.length,n=new Array(e),t=0;t":re(function(){for(var e=arguments.length,n=new Array(e),t=0;t x1 x2 x3 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically increasing"),"<":re(function(){for(var e=arguments.length,n=new Array(e),t=0;t=":re(function(){for(var e=arguments.length,n=new Array(e),t=0;t= x1 x2 x3 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically nondecreasing"),"eq?":re(Ue,"(eq? a b)\n\n Function compare two values if they are identical."),or:re(new Ge("or",function(e,n){var i=n.dynamic_scope,a=n.error;var o=this.get("list->array")(e);var u=this;if(i){i=u}var c;return function n(){function e(e){c=e;if(c){return c}else{return n()}}var t=o.shift();if(typeof t==="undefined"){if(c){return c}else{return false}}else{var r=Ft(t,{env:u,dynamic_scope:i,error:a});return ne(r,e)}}()}),"(or . expressions)\n\n Macro execute the values one by one and return the one that is truthy value.\n If there are no expression that evaluate to true it return false."),and:re(new Ge("and",function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:{},i=n.dynamic_scope,a=n.error;var o=this.get("list->array")(e);var u=this;if(i){i=u}if(!o.length){return true}var c;return function n(){function e(e){c=e;if(!c){return false}else{return n()}}var t=o.shift();if(typeof t==="undefined"){if(c){return c}else{return false}}else{var r=Ft(t,{env:u,dynamic_scope:i,error:a});return ne(r,e)}}()}),"(and . expressions)\n\n Macro evalute each expression in sequence if any value return false it will\n return false. If each value return true it will return the last value.\n If it's called without arguments it will return true."),"|":re(function(e,n){return $n(e).or(n)},"(& a b)\n\n Function calculate or bit operation."),"&":re(function(e,n){return $n(e).and(n)},"(& a b)\n\n Function calculate and bit operation."),"~":re(function(e){return $n(e).neg()},"(~ number)\n\n Function negate the value."),">>":re(function(e,n){return $n(e).shr(n)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":re(function(e,n){return $n(e).shl(n)},"(<< a b)\n\n Function left shit the value a by value b."),not:re(function(e){if(en(e)){return true}return!e},"(not object)\n\n Function return negation of the argument.")},F,"global");var ht=pt.inherit("user-env");pt.set("**interaction-environment**",ht);(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(n){var t=e[n]?e[n]:n;pt.set(t,re(function(e){_t(t,e,"number");if(e instanceof $n){return e[n]()}},"(".concat(t," number)\n\n Function calculate ").concat(t," of a number.")))})})();function vt(e){if(e.length===1){return e[0]}else{var n=[];var t=vt(e.slice(1));for(var r=0;r3&&arguments[3]!==F?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(r!==null){i+=" argument ".concat(r)}if(t instanceof Array){var a=t[t.length-1];t=t.slice(0,-1).join(", ")+" or "+a}return"Expecting ".concat(t," got ").concat(n).concat(i)}function _t(e,n,t){var r=arguments.length>3&&arguments[3]!==F?arguments[3]:null;e=e.valueOf();var i=St(n).toLowerCase();var a=false;if(t instanceof Ne){t=t.toArray()}if(t instanceof Array){t=t.map(function(e){return e.valueOf().toLowerCase()});if(t.includes(i)){a=true}}else{t=t.valueOf().toLowerCase()}if(!a&&i!==t){throw new Error(wt(e,i,t,r))}}function xt(e){var n=Vt(e);return["string","function"].includes(n)||e instanceof je||e instanceof $n||e instanceof RegExp}function St(e){var n={pair:Ne,symbol:je,character:Ln,values:ft,macro:Ge,string:qn,array:Array,"native-symbol":Symbol};if(Number.isNaN(e)){return"NaN "}if(e===Ie){return"nil"}if(e===null){return"null"}if(e instanceof Qe){return"syntax"}for(var t=0,r=Object.entries(n);t1&&arguments[1]!==F?arguments[1]:{},i=e.env,a=e.dynamic_scope,t=e.error,o=t===void 0?function(){}:t;try{if(a===true){i=a=i||pt}else if(i===true){i=a=pt}else{i=i||pt}var r={env:i,dynamic_scope:a,error:o};var u;if(en(n)){return n}if(n instanceof je){return i.get(n)}var c=n.car;var s=n.cdr;if(c instanceof Ne){u=Ot(Ft(c,r));if(nn(u)){return u.then(function(e){return Ft(new Ne(e,n.cdr),r)})}else if(typeof u!=="function"){throw new Error(St(u)+" "+i.get("repr")(u)+" is not a function while evaluating "+n.toString())}}if(c instanceof je){u=i.get(c);if(u instanceof Qe){return jt(u,n,r)}else if(u instanceof Ge){return Et(u,s,r)}else if(typeof u!=="function"){if(u){var f="".concat(St(u)," `").concat(u,"' is not a function");throw new Error(f)}throw new Error("Unknown function `".concat(c.name,"'"))}}else if(typeof c==="function"){u=c}if(typeof u==="function"){var l=kt(s,r);return ne(l,function(e){if(cn(u)&&(!sn(u)||fn(u))){e=e.map(rn)}if(u.__lambda__&&!u.__prototype__||fn(u)){u=on(u)}var n=e.slice();var t=(a||i).newFrame(u,n);var r=Ot(u.apply(t,e));return ne(r,function(e){if(e instanceof Ne){e.markCycles();return lt(e)}if(Number.isNaN(e)){return e}if(typeof e==="number"){return $n(e)}if(typeof e==="string"){return qn(e)}return e},o)})}else if(n instanceof je){u=i.get(n);if(u==="undefined"){throw new Error("Unbound variable `"+n.name+"'")}return u}else if(n instanceof Ne){u=c&&c.toString();throw new Error("".concat(St(c)," ").concat(u," is not a function"))}else{return n}}catch(e){o&&o.call(i,e,n)}}function At(e,n,t){return It.apply(this,arguments)}function It(){It=Dt($t.mark(function e(t,r,i){var a,o,u,c;return $t.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(i===true){r=i=r||ht}else if(r===true){r=i=ht}else{r=r||ht}a=ee(t);o=[];case 3:if(a.length){n.next=8;break}return n.abrupt("return",o);case 8:u=a.shift();n.next=11;return Ft(u,{env:r,dynamic_scope:i,error:function e(n,t){if(t){if(!(n.code instanceof Array)){n.code=[]}n.code.push(t.toString(true))}throw n}});case 11:c=n.sent;o.push(c);case 13:n.next=3;break;case 15:case"end":return n.stop()}}},e)}));return It.apply(this,arguments)}function Nt(e){var n={"[":"]","(":")"};var t;if(typeof e==="string"){t=W(e)}else{t=e.map(function(e){return e&&e.token?e.token:e})}var r=Object.keys(n);var i=Object.values(n).concat(r);t=t.filter(function(e){return i.includes(e)});var a=new G;var o=zt(t),u;try{for(o.s();!(u=o.n()).done;){var c=u.value;if(r.includes(c)){a.push(c)}else if(!a.is_empty()){var s=a.top();var f=n[s];if(c===f){a.pop()}else{throw new Error("Syntax error: missing closing ".concat(f))}}else{throw new Error("Syntax error: not matched closing ".concat(c))}}}catch(e){o.e(e)}finally{o.f()}return a.is_empty()}function Lt(e){var n="("+e.toString()+")()";var t=window.URL||window.webkitURL;var r;try{r=new Blob([n],{type:"application/javascript"})}catch(e){var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;r=new i;r.append(n);r=r.getBlob()}return new f.Worker(t.createObjectURL(r))}function qt(e){this.url=e;var o=this.worker=Lt(function(){var u;var c;self.addEventListener("message",function(e){var r=e.data;var n=r.id;if(r.type!=="RPC"||n===null){return}function i(e){self.postMessage({id:n,type:"RPC",result:e})}function a(e){self.postMessage({id:n,type:"RPC",error:e})}if(r.method==="eval"){if(!c){a("Worker RPC: LIPS not initilized, call init first");return}c.then(function(){var e=Gt(r.params,2),n=e[0],t=e[1];u.exec(n,t).then(function(e){e=e.map(function(e){return e&&e.valueOf()});i(e)})["catch"](function(e){a(e)})})}else if(r.method==="init"){var t=Gt(r.params,1),o=t[0];if(typeof o!=="string"){a("Worker RPC: url is not a string")}else{importScripts("".concat(o,"/dist/lips.min.js"));u=new Mt.Interpreter("worker");c=u.exec('(let-env lips.env.parent\n (load "'.concat(o,'/lib/bootstrap.scm")\n (load "').concat(o,'/lib/R5RS.scm")\n (load "').concat(o,'/lib/R7RS.scm"))'));c.then(function(){i(true)})}}})});this.rpc=function(){var r=0;return function e(n,t){var a=++r;return new Promise(function(r,i){o.addEventListener("message",function e(n){var t=n.data;if(t&&t.type==="RPC"&&t.id===a){if(t.error){i(t.error)}else{r(t.result)}o.removeEventListener("message",e)}});o.postMessage({type:"RPC",method:n,id:a,params:t})})}}();this.rpc("init",[e])["catch"](function(e){console.error(e)});this.exec=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;return this.rpc("eval",[e,n])}}Ne.unDry=function(e){return new Ne(e.car,e.cdr)};Ne.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};Ae.prototype.toDry=function(){return{value:null}};Ae.unDry=function(){return Ie};je.prototype.toDry=function(){return{value:{name:this.name}}};je.unDry=function(e){return new je(e.name)};function Pt(e){console.error(e.message||e);if(e.code){console.error(e.code.map(function(e,n){return"[".concat(n+1,"]: ").concat(e)}))}}function Rt(){var o=["text/x-lips","text/x-scheme"];if(!window.document){return Promise.resolve()}else{return new Promise(function(i){var a=Array.from(document.querySelectorAll("script"));return function n(){var e=a.shift();if(!e){i()}else{var t=e.getAttribute("type");if(o.includes(t)){var r=e.getAttribute("src");if(r){return f.fetch(r).then(function(e){return e.text()}).then(At).then(n)["catch"](function(e){Pt(e);n()})}else{return At(e.innerHTML).then(n)["catch"](function(e){Pt(e);n()})}}else if(t&&t.match(/lips|lisp/)){console.warn("Expecting "+o.join(" or ")+" found "+t)}return n()}}()})}}if(typeof window!=="undefined"){e(window,Rt)}var Ct=function(){var e=qn("Tue, 08 Sep 2020 08:31:43 +0000").valueOf();var n=e==="{{"+"DATE}}"?new Date:new Date(e);var t=function e(n){return n.toString().padStart(2,"0")};var r=n.getFullYear();var i=[r,t(n.getMonth()+1),t(n.getDate())].join("-");var a="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter DEV (".concat(i,") \nCopyright (c) 2018-").concat(r," Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables.\nYou can also use (help name) to display help for specic function or macro.\n").replace(/^.*\n/,"");return a}();se.__className="ahead";fe.__className="pattern";ce.__className="formatter";Ge.__className="macro";Qe.__className="syntax";ct.__className="environment";nt.__className="input-port";tt.__className="output-port";rt.__className="output-string-port";it.__className="input-string-port";$n.__className="number";Ln.__className="character";qn.__className="string";var Mt={version:"DEV",banner:Ct,date:"Tue, 08 Sep 2020 08:31:43 +0000",exec:At,parse:ee,tokenize:W,evaluate:Ft,Environment:ct,env:ht,Worker:qt,Interpreter:ut,balanced_parenthesis:Nt,balancedParenthesis:Nt,balanced:Nt,Macro:Ge,Syntax:Qe,Pair:Ne,quote:lt,InputPort:nt,OutputPort:tt,InputStringPort:it,OutputStringPort:rt,Formatter:ce,specials:K,repr:qe,nil:Ie,LSymbol:je,LNumber:$n,LFloat:Un,LComplex:Dn,LRational:Vn,LBigInteger:zn,LCharacter:Ln,LString:qn,rationalize:Yn};pt.set("lips",Mt);return Mt})})(); \ No newline at end of file +(function(){"use strict";function e(e){throw new Error('"'+e+'" is read-only')}var Tt=e;function n(e,n){return n={exports:{}},e(n,n.exports),n.exports}var u=n(function(t){function r(e,n){t.exports=r=Object.setPrototypeOf||function e(n,t){n.__proto__=t;return n};return r(e,n)}t.exports=r});function t(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Date.prototype.toString.call(Reflect.construct(Date,[],function(){}));return true}catch(e){return false}}var a=t;var Bt=n(function(r){function i(e,n,t){if(a()){r.exports=i=Reflect.construct}else{r.exports=i=function e(n,t,r){var i=[null];i.push.apply(i,t);var a=Function.bind.apply(n,i);var o=new a;if(r)u(o,r.prototype);return o}}return i.apply(null,arguments)}r.exports=i});var r=n(function(e){var n=function(o){var e=Object.prototype;var f=e.hasOwnProperty;var c;var n=typeof Symbol==="function"?Symbol:{};var i=n.iterator||"@@iterator";var t=n.asyncIterator||"@@asyncIterator";var r=n.toStringTag||"@@toStringTag";function u(e,n,t,r){var i=n&&n.prototype instanceof s?n:s;var a=Object.create(i.prototype);var o=new F(r||[]);a._invoke=O(e,t,o);return a}o.wrap=u;function l(e,n,t){try{return{type:"normal",arg:e.call(n,t)}}catch(e){return{type:"throw",arg:e}}}var p="suspendedStart";var h="suspendedYield";var v="executing";var d="completed";var m={};function s(){}function a(){}function y(){}var g={};g[i]=function(){return this};var b=Object.getPrototypeOf;var w=b&&b(b(A([])));if(w&&w!==e&&f.call(w,i)){g=w}var _=y.prototype=s.prototype=Object.create(g);a.prototype=_.constructor=y;y.constructor=a;y[r]=a.displayName="GeneratorFunction";function x(e){["next","throw","return"].forEach(function(n){e[n]=function(e){return this._invoke(n,e)}})}o.isGeneratorFunction=function(e){var n=typeof e==="function"&&e.constructor;return n?n===a||(n.displayName||n.name)==="GeneratorFunction":false};o.mark=function(e){if(Object.setPrototypeOf){Object.setPrototypeOf(e,y)}else{e.__proto__=y;if(!(r in e)){e[r]="GeneratorFunction"}}e.prototype=Object.create(_);return e};o.awrap=function(e){return{__await:e}};function S(u,c){function s(e,n,t,r){var i=l(u[e],u,n);if(i.type==="throw"){r(i.arg)}else{var a=i.arg;var o=a.value;if(o&&typeof o==="object"&&f.call(o,"__await")){return c.resolve(o.__await).then(function(e){s("next",e,t,r)},function(e){s("throw",e,t,r)})}return c.resolve(o).then(function(e){a.value=e;t(a)},function(e){return s("throw",e,t,r)})}}var n;function e(t,r){function e(){return new c(function(e,n){s(t,r,e,n)})}return n=n?n.then(e,e):e()}this._invoke=e}x(S.prototype);S.prototype[t]=function(){return this};o.AsyncIterator=S;o.async=function(e,n,t,r,i){if(i===void 0)i=Promise;var a=new S(u(e,n,t,r),i);return o.isGeneratorFunction(n)?a:a.next().then(function(e){return e.done?e.value:a.next()})};function O(o,u,c){var s=p;return function e(n,t){if(s===v){throw new Error("Generator is already running")}if(s===d){if(n==="throw"){throw t}return I()}c.method=n;c.arg=t;while(true){var r=c.delegate;if(r){var i=k(r,c);if(i){if(i===m)continue;return i}}if(c.method==="next"){c.sent=c._sent=c.arg}else if(c.method==="throw"){if(s===p){s=d;throw c.arg}c.dispatchException(c.arg)}else if(c.method==="return"){c.abrupt("return",c.arg)}s=v;var a=l(o,u,c);if(a.type==="normal"){s=c.done?d:h;if(a.arg===m){continue}return{value:a.arg,done:c.done}}else if(a.type==="throw"){s=d;c.method="throw";c.arg=a.arg}}}}function k(e,n){var t=e.iterator[n.method];if(t===c){n.delegate=null;if(n.method==="throw"){if(e.iterator["return"]){n.method="return";n.arg=c;k(e,n);if(n.method==="throw"){return m}}n.method="throw";n.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var r=l(t,e.iterator,n.arg);if(r.type==="throw"){n.method="throw";n.arg=r.arg;n.delegate=null;return m}var i=r.arg;if(!i){n.method="throw";n.arg=new TypeError("iterator result is not an object");n.delegate=null;return m}if(i.done){n[e.resultName]=i.value;n.next=e.nextLoc;if(n.method!=="return"){n.method="next";n.arg=c}}else{return i}n.delegate=null;return m}x(_);_[r]="Generator";_[i]=function(){return this};_.toString=function(){return"[object Generator]"};function j(e){var n={tryLoc:e[0]};if(1 in e){n.catchLoc=e[1]}if(2 in e){n.finallyLoc=e[2];n.afterLoc=e[3]}this.tryEntries.push(n)}function E(e){var n=e.completion||{};n.type="normal";delete n.arg;e.completion=n}function F(e){this.tryEntries=[{tryLoc:"root"}];e.forEach(j,this);this.reset(true)}o.keys=function(t){var r=[];for(var e in t){r.push(e)}r.reverse();return function e(){while(r.length){var n=r.pop();if(n in t){e.value=n;e.done=false;return e}}e.done=true;return e}};function A(n){if(n){var e=n[i];if(e){return e.call(n)}if(typeof n.next==="function"){return n}if(!isNaN(n.length)){var t=-1,r=function e(){while(++t=0;--n){var i=this.tryEntries[n];var a=i.completion;if(i.tryLoc==="root"){return e("end")}if(i.tryLoc<=this.prev){var o=f.call(i,"catchLoc");var u=f.call(i,"finallyLoc");if(o&&u){if(this.prev=0;--t){var r=this.tryEntries[t];if(r.tryLoc<=this.prev&&f.call(r,"finallyLoc")&&this.prev=0;--n){var t=this.tryEntries[n];if(t.finallyLoc===e){this.complete(t.completion,t.afterLoc);E(t);return m}}},catch:function(e){for(var n=this.tryEntries.length-1;n>=0;--n){var t=this.tryEntries[n];if(t.tryLoc===e){var r=t.completion;if(r.type==="throw"){var i=r.arg;E(t)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,t){this.delegate={iterator:A(e),resultName:n,nextLoc:t};if(this.method==="next"){this.arg=c}return m}};return o}(e.exports);try{regeneratorRuntime=n}catch(e){Function("r","regeneratorRuntime = r")(n)}});var $t=r;function c(e,n,t,r,i,a,o){try{var u=e[a](o);var c=u.value}catch(e){t(e);return}if(u.done){n(c)}else{Promise.resolve(c).then(r,i)}}function i(u){return function(){var e=this,o=arguments;return new Promise(function(n,t){var r=u.apply(e,o);function i(e){c(r,n,t,i,a,"next",e)}function a(e){c(r,n,t,i,a,"throw",e)}i(undefined)})}}var Dt=i;function o(e){if(Array.isArray(e))return e}var s=o;function f(e){if(typeof Symbol!=="undefined"&&Symbol.iterator in Object(e))return Array.from(e)}var l=f;function p(e,n){if(n==null||n>e.length)n=e.length;for(var t=0,r=new Array(n);t=0)continue;t[i]=e[i]}return t}var j=k;function E(e,n){if(e==null)return{};var t=j(e,n);var r,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,r))continue;t[r]=e[r]}}return t}var Yt=E;function F(e,n){if(typeof Symbol==="undefined"||!(Symbol.iterator in Object(e)))return;var t=[];var r=true;var i=false;var a=undefined;try{for(var o=e[Symbol.iterator](),u;!(r=(u=o.next()).done);r=true){t.push(u.value);if(n&&t.length===n)break}}catch(e){i=true;a=e}finally{try{if(!r&&o["return"]!=null)o["return"]()}finally{if(i)throw a}}return t}var A=F;function I(e,n){return s(e)||A(e,n)||d(e,n)||y()}var Gt=I;var zt=n(function(n){function t(e){"@babel/helpers - typeof";if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){n.exports=t=function e(n){return typeof n}}else{n.exports=t=function e(n){return n&&typeof Symbol==="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n}}return t(e)}n.exports=t});function Vt(n){if(typeof Symbol==="undefined"||n[Symbol.iterator]==null){if(Array.isArray(n)||(n=N(n))){var t=0;var e=function e(){};return{s:e,n:function e(){if(t>=n.length)return{done:true};return{done:false,value:n[t++]}},e:function e(n){throw n},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,i=true,a=false,o;return{s:function e(){r=n[Symbol.iterator]()},n:function e(){var n=r.next();i=n.done;return n},e:function e(n){a=true;o=n},f:function e(){try{if(!i&&r["return"]!=null)r["return"]()}finally{if(a)throw o}}}}function N(e,n){if(!e)return;if(typeof e==="string")return L(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);if(t==="Object"&&e.constructor)t=e.constructor.name;if(t==="Map"||t==="Set")return Array.from(e);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return L(e,n)}function L(e,n){if(n==null||n>e.length)n=e.length;for(var t=0,r=new Array(n);t1&&arguments[1]!==F?arguments[1]:10;var t=E(e);var r=t.number.split("/");var i=zn({num:$n([r[0],t.radix||n]),denom:$n([r[1],t.radix||n])});if(t.inexact){return i.valueOf()}else{return i}}function I(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:10;var t=E(e);if(t.inexact){return Un(parseInt(t.number,t.radix||n))}return $n([t.number,t.radix||n])}function N(e){var n=e.match(/#\\x([0-9a-f]+)$/i);var t;if(n){var r=parseInt(n[1],16);t=String.fromCodePoint(r)}else{n=e.match(/#\\(.+)$/);if(n){t=n[1]}}if(t){return Ln(t)}}function L(e){var i=arguments.length>1&&arguments[1]!==F?arguments[1]:10;function n(e){var n;if(e==="+"){n=$n(1)}else if(e==="-"){n=$n(-1)}else if(e.match(x)){n=$n([e,i])}else if(e.match(S)){var t=e.split("/");n=zn({num:$n([t[0],i]),denom:$n([t[1],i])})}else if(e.match(c)){var r=Un(parseFloat(e));if(a.exact){return r.toRational()}return r}else{throw new Error("Internal Parser Error")}if(a.inexact){return Un(n.valueOf())}return n}var a=E(e);i=a.radix||i;var t;var r=a.number.match(k);if(i!==10&&r){t=r}else{t=a.number.match(l[i])}var o,u;u=n(t[2]);if(t[1]){o=n(t[1])}else if(u instanceof Un){o=Un(0)}else{o=$n(0)}return Dn({im:u,re:o})}function q(e){return parseInt(e.toString(),10)===e}function P(e){var n=e.match(/^(([-+]?[0-9]*)(?:\.([0-9]+))?)e([-+]?[0-9]+)/i);if(n){var t=parseInt(n[4],10);var r;var i=n[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var a=n[3]&&n[3].length;if(i0){return $n(a).mul(u)}}}t=Un(t);if(n.exact){return t.toRational()}return t}function C(e){var n=/([^\\\n])(\\(?:\\{2})*)(?!x[0-9A-F]+)(?!u[0-9A-F]{2,4})(.)/gi;e=e.replace(n,function(e,n,t,r){if(!['"',"/","b","f","n","\\","r","t","x"].includes(r)){t=t.substring(1).replace(/\\\\/,"\\")}return e}).replace(/\\x([0-9a-f]+);/gi,function(e,n){return"\\u"+n.padStart(4,"0")}).replace(/\n/g,"\\n");var t=e.match(/(\\*)(\\x[0-9A-F])/i);if(t&&t[1].length%2===0){throw new Error("Invalid string literal, unclosed ".concat(t[2]))}try{return qn(JSON.parse(e))}catch(e){throw new Error("Invalid string literal")}}function M(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var t={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,n){return String.fromCharCode(parseInt("0"+n,16))}).replace(/\\(.)/g,function(e,n){return t[n]||n})}return new je(e)}function T(e){var n=e.match(a);if(n){return new RegExp(n[1],n[2])}else if(e.match(/^"/)){return C(e)}else if(e.match(m)){return N(e)}else if(e.match(w)){return A(e)}else if(e.match(b)){return L(e)}else if(e.match(_)){return I(e)}else if(e.match(c)){return R(e)}else if(e==="nil"){return Ie}else if(["true","#t"].includes(e)){return true}else if(["false","#f"].includes(e)){return false}else{return M(e)}}function B(e){return!(["(",")"].includes(e)||e.match(a)||e.match(/^"[\s\S]+"$/)||e.match(_)||e.match(c)||e.match(b)||e.match(w)||["#t","#f","nil","true","false"].includes(e))}var $=/("(?:\\[\S\s]|[^"])*"?|\/(?! )[^\n\/\\]*(?:\\[\S\s][^\n\/\\]*)*\/[gimy]*(?=[\s[\]()]|$)|\|[^|\s\n]+\||#;|;.*|#\|(?!\|#)[\s\S]*\|#)/g;var D=/"(?:\\[\S\s]|[^"])*"?/g;var U=[r,n,i].map(y).join("|");function J(){var e=K.names().sort(function(e,n){return n.length-e.length||e.localeCompare(n)}).map(Y).join("|");return new RegExp("(".concat(d,"|#f|#t|#;|(?:").concat(U,")(?=$|[\\n\\s()[\\]])|\\[|\\]|\\(|\\)|\\|[^|]+\\||;.*|(?:#[ei])?").concat(o,"(?=$|[\\n\\s()[\\]])|\\n|\\.{2,}|'(?=#[ft]|(?:#[xiobe]){1,2}|#\\\\)|(?!#:)(?:").concat(e,")|[^(\\s)[\\]]+)"),"gim")}function H(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:1;return e[e.length-n]}function Y(e){if(typeof e==="string"){var n=/([-\\^$[\]()+{}?*.|])/g;return e.replace(n,"\\$1")}}function G(){this.data=[]}G.prototype.push=function(e){this.data.push(e)};G.prototype.top=function(){return this.data[this.data.length-1]};G.prototype.pop=function(){return this.data.pop()};G.prototype.is_empty=function(){return!this.data.length};function z(e){var a=J();e=e.replace(/\n\r|\r/g,"\n");var o=0;var u=0;var c=[];var s=[];var f=0;e.split($).filter(Boolean).forEach(function(e){if(e.match($)){f=0;if(s.length){var n=H(s);if(n.token.match(/\n/)){var t=n.token.split("\n").pop();f+=t.length}else{f+=n.token.length}f+=n.col}var r={col:f,line:u,token:e,offset:o};c.push(r);s.push(r);o+=e.length;f+=e.length;u+=(e.match("\n")||[]).length;return}var i=e.split(a).filter(Boolean);i.forEach(function(e){var n={col:f,line:u,token:e,offset:o};f+=e.length;o+=e.length;c.push(n);s.push(n);if(e==="\n"){++u;s=[];f=0}})});return c}function V(e){var n=e.token,t=Yt(e,["token"]);if(n.match(/^"[\s\S]+"$/)&&n.match(/\n/)){var r=new RegExp("^ {1,"+(e.col+1)+"}","mg");n=n.replace(r,"")}return Wt({token:n},t)}function W(e,n){var t=arguments.length>2&&arguments[2]!==F?arguments[2]:V;if(e instanceof qn){e=e.toString()}if(n){return z(e).map(t)}else{var r=z(e).map(function(e){var n=t(e);if(!n||typeof n.token!=="string"){throw new Error("[tokenize] Invalid formatter wrong return object")}if(n.token==="#\\ "){return n.token}return n.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return Q(r)}}function Q(e){var n=0;var t=null;var r=[];for(var i=0;i1&&!e[0].literal){c.pop();if(c[c.length-1].length===1&&c[c.length-1][0]instanceof je){c[c.length-1].push(e)}else if(c[c.length-1]instanceof Ne){if(c[c.length-1].cdr instanceof Ne){c[c.length-1]=new Ne(c[c.length-1],Ne.fromArray(e))}else{c[c.length-1].cdr=Ne.fromArray(e)}}else{c[c.length-1].push(e)}}}e.forEach(function(e){var n=c[c.length-1];if(l.indexOf(e)!==-1){y++;f=e;c.push([K.get(f).symbol]);if(!f){m=[]}m.push(f)}else{if(f){d.push(m);m=[]}if(b(e)){v=true;h++;var t=[];if(f&&!X(f)){t.push(g)}c.push(t);f=null;y=0}else if(e==="."&&!v){c[c.length-1]=Ne.fromArray(n)}else if(w(e)){h--;if(!c.length){throw new Error("Unbalanced parenthesis")}if(c.length===1){var r=c.pop();if(r instanceof Array&&r.length===0){r=Ie}s.push(r)}else if(c.length>1){var i=c.pop();n=c[c.length-1];if(n instanceof Array){if(i.length===0){n.push(Ie)}else if(i instanceof Array&&i[0]===g){var a;(a=n).push.apply(a,Jt(i.slice(1)))}else{n.push(i)}}else if(n instanceof Ne){if(i.length===0){n.append(Ie)}else{n.append(Ne.fromArray(i))}}if(d.length){m=d.pop();while(m.length){_();m.pop()}}else{_()}}if(h===0&&c.length){s.push(c.pop())}}else{v=false;var o=T(e);if(f){while(y--){c[c.length-1].push(o);o=c.pop()}d.pop();y=0;f=false}else if(o instanceof je&&p.includes(o.name)){o.literal=true}n=c[c.length-1];if(n instanceof Ne){var u=n;while(true){if(u.cdr===Ie){if(o instanceof Array){u.cdr=Ne.fromArray(o)}else{u.cdr=o}break}else{u=u.cdr}}}else if(!c.length){s.push(o)}else{n.push(o)}}}});if(!e.filter(function(e){return e.match(/^[[\]()]$/)}).length&&c.length){s=s.concat(c);c=[]}if(c.length){throw new Error("Unbalanced parenthesis 2")}return s.map(function(e){if(e instanceof Array){return Ne.fromArray(e)}return e})}function ne(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:function(e){return e};var t=arguments.length>2&&arguments[2]!==F?arguments[2]:null;if(e instanceof Array){var r=e.filter(nn);if(r.length){return ne(Promise.all(r),n,t)}return n(e)}if(nn(e)){var i=e.then(n);if(t===null){return i}else{return i["catch"](t)}}return n(e)}function te(e,n){if(n instanceof RegExp){return function(e){return String(e).match(n)}}else if(typeof n!=="function"){throw new Error("".concat(e," argument need to be a function or RegExp"))}else{return n}}function re(e,n,t){if(n){if(t){e.__doc__=n}else{e.__doc__=ie(n)}}return e}function ie(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function ae(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:1;var t=e.length;if(n<=0){throw Error("previousSexp: Invlaid argument sexp = ".concat(n))}e:while(n--&&t>=0){var r=1;while(r>0){var i=e[--t];if(!i){break e}if(i==="("||i.token==="("){r--}else if(i===")"||i.token===")"){r++}}t--}return e.slice(t+1)}function oe(e){if(!e||!e.length){return 0}var n=e.length;if(e[n-1].token==="\n"){return 0}while(--n){if(e[n].token==="\n"){var t=(e[n+1]||{}).token;if(t){return t.length}}}return 0}function ue(e,n){return f(e,n)===n.length;function f(t,r){function e(){return a>0&&u>0&&t[a-1]===r[u-1]&&t[a+1]===r[u]}function n(){return t[a]===Symbol["for"]("symbol")&&!B(r[u])}function i(){var e=t[a+1];var n=r[u+1];if(e!==F&&n!==F){return f([e],[n])}}var a=0;var o={};for(var u=0;u0){continue}}else if(n()){return-1}}else if(t[a]instanceof Array){var s=f(t[a],r.slice(u));if(s===-1||s+u>r.length){return-1}u+=s-1;a++;continue}else{return-1}a++}if(t.length!==a){return-1}return r.length}}function ce(e){this._code=e.replace(/\r/g,"")}ce.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?define/,/^(?:#:)?lambda/,/^(?:#:)?let*/,/^(?:#:)?(let|letrec)(-syntax)?$/,/(?:#:)?let-env/,/(?:#:)?syntax-rules/,/(?:#:)?try/,/(?:#:)?catch/,/(?:#:)?while/],shift:{1:["&","#"]}}};ce.match=ue;ce.prototype._options=function e(n){var t=ce.defaults;if(typeof n==="undefined"){return Object.assign({},t)}var r=n&&n.exceptions||{};var i=r.specials||[];var a=r.shift||{1:[]};return Wt(Wt(Wt({},t),n),{},{exceptions:{specials:[].concat(Jt(t.exceptions.specials),Jt(i)),shift:Wt(Wt({},a),{},{1:[].concat(Jt(t.exceptions.shift[1]),Jt(a[1]))})}})};ce.prototype.indent=function e(n){var t=W(this._code,true);return this._indent(t,n)};ce.exception_shift=function(a,e){function n(e){if(!e.length){return false}if(e.indexOf(a)!==-1){return true}else{var n=e.filter(function(e){return e instanceof RegExp});if(!n.length){return false}var t=Vt(n),r;try{for(t.s();!(r=t.n()).done;){var i=r.value;if(a.match(i)){return true}}}catch(e){t.e(e)}finally{t.f()}}return false}if(n(e.exceptions.specials)){return e.indent}var t=e.exceptions.shift;for(var r=0,i=Object.entries(t);r0){r.offset=0}if(a.toString()===n.toString()&&Nt(a)){return r.offset+a[0].col}else if(a.length===1){return r.offset+a[0].col+1}else{var u=-1;if(o){var c=ce.exception_shift(o.token,r);if(c!==-1){u=c}}if(u===-1){u=ce.exception_shift(a[1].token,r)}if(u!==-1){return r.offset+a[0].col+u}else if(a[0].line3&&a[1].line===a[3].line){if(a[1].token==="("||a[1].token==="["){return r.offset+a[1].col}return r.offset+a[3].col}else if(a[0].line===a[1].line){return r.offset+r.indent+a[0].col}else{var s=a.slice(2);for(var f=0;f")};se.prototype.match=function(e){return e.match(this.pattern)};function fe(e,n){this.pattern=e;this.flag=n}fe.prototype.toString=function(){return"#")};ce.Pattern=fe;ce.Ahead=se;var le=/[[(]/;var pe=/[\])]/;var he=/[^()[\]]/;var ve=new se(/[^)\]]/);var de=Symbol["for"]("*");var me=new fe([le,de,pe],"+");var ye=new fe([Symbol["for"]("symbol")],"?");var ge=new fe([Symbol["for"]("symbol")],"*");var be=[le,ge,pe];var we=new fe([le,Symbol["for"]("symbol"),de,pe],"+");var _e=Se("define","lambda","syntax-rules");var xe=/^(?:#:)?(let|let\*|letrec|let-env)(:?-syntax)?$/;function Se(){for(var e=arguments.length,n=new Array(e),t=0;t0&&arguments[0]!==F?arguments[0]:null;if(e instanceof je){e=e.valueOf()}if(Ee(e)){return je(e)}if(e!==null){return new je(Symbol("#:".concat(e)))}n++;return new je(Symbol("#:g".concat(n)))}}();function Ae(){}Ae.prototype.toString=Ae.prototype.toJSON=function(){return"()"};Ae.prototype.valueOf=function(){return F};Ae.prototype.append=function(e){return new Ne(e,Ie)};Ae.prototype.toArray=function(){return[]};var Ie=new Ae;function Ne(e,n){if(typeof this!=="undefined"&&this.constructor!==Ne||typeof this==="undefined"){return new Ne(e,n)}this.car=e;this.cdr=n}function Le(a,o){return function e(n){_t(a,n,["pair","nil"]);if(n===Ie){return[]}var t=[];var r=n;while(true){if(r instanceof Ne){if(r.haveCycles("cdr")){break}var i=r.car;if(o&&i instanceof Ne){i=this.get(a).call(this,i)}t.push(i);r=r.cdr}else{break}}return t}}Ne.prototype.flatten=function(){return Ne.fromArray(Oe(this.toArray()))};Ne.prototype.length=function(){var e=0;var n=this;while(true){if(!n||n===Ie||!(n instanceof Ne)||n.haveCycles("cdr")){break}e++;n=n.cdr}return e};Ne.prototype.clone=function(){var t=new Map;function r(e){if(e instanceof Ne){if(t.has(e)){return t.get(e)}var n=new Ne;t.set(e,n);n.car=r(e.car);n.cdr=r(e.cdr);n.cycles=e.cycles;return n}return e}return r(this)};Ne.prototype.lastPair=function(){var e=this;while(true){if(e.cdr===Ie){return e}e=e.cdr}};Ne.prototype.toArray=function(){var e=[];if(this.car instanceof Ne){e.push(this.car.toArray())}else{e.push(this.car.valueOf())}if(this.cdr instanceof Ne){e=e.concat(this.cdr.toArray())}return e};Ne.fromArray=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:true;if(e instanceof Ne){return e}if(n===false){var t=Ie;for(var r=e.length;r--;){t=new Ne(e[r],t)}return t}if(e.length&&!(e instanceof Array)){e=Jt(e)}if(e.length===0){return Ie}else{var i;if(e[0]instanceof Array){i=Ne.fromArray(e[0])}else{i=e[0]}if(typeof i==="string"){i=qn(i)}if(e.length===1){return new Ne(i,Ie)}else{return new Ne(i,Ne.fromArray(e.slice(1)))}}};Ne.prototype.toObject=function(){var e=arguments.length>0&&arguments[0]!==F?arguments[0]:false;var n=this;var t={};while(true){if(n instanceof Ne&&n.car instanceof Ne){var r=n.car;var i=r.car;if(i instanceof je){i=i.name}if(i instanceof String){i=i.valueOf()}var a=r.cdr;if(a instanceof Ne){a=a.toObject(e)}if(a instanceof $n||a instanceof qn||a instanceof Ln){if(!e){a=a.valueOf()}}t[i]=a;n=n.cdr}else{break}}return t};Ne.fromPairs=function(e){return e.reduce(function(e,n){return new Ne(new Ne(new je(n[0]),n[1]),e)},Ie)};Ne.fromObject=function(n){var e=Object.keys(n).map(function(e){return[e,n[e]]});return Ne.fromPairs(e)};Ne.prototype.reduce=function(e){var n=this;var t=Ie;while(true){if(n!==Ie){t=e(t,n.car);n=n.cdr}else{break}}return t};Ne.prototype.reverse=function(){if(this.haveCycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var n=Ie;while(e!==Ie){var t=e.cdr;e.cdr=n;n=e;e=t}return n};Ne.prototype.transform=function(r){function i(e){if(e instanceof Ne){if(e.replace){delete e.replace;return e}var n=r(e.car);if(n instanceof Ne){n=i(n)}var t=r(e.cdr);if(t instanceof Ne){t=i(t)}return new Ne(n,t)}return e}return i(this)};Ne.prototype.map=function(e){if(typeof this.car!=="undefined"){return new Ne(e(this.car),this.cdr===Ie?Ie:this.cdr.map(e))}else{return Ie}};var qe=new Map;function Pe(t){var e=t.constructor||Object;var r=zt(t)==="object"&&e===Object;var i;if(qe.has(e)){i=qe.get(e)}else{qe.forEach(function(e,n){if(t instanceof n&&(n===Object&&r||n!==Object)){i=e}})}return i}var Re=new Map;[[Number.NEGATIVE_INFINITY,"-inf.0"],[Number.POSITIVE_INFINITY,"+inf.0"],[true,"#t"],[false,"#f"],[null,"null"],[F,"#"]].forEach(function(e){var n=Gt(e,2),t=n[0],r=n[1];Re.set(t,r)});function Ce(t){if(t&&zt(t)==="object"){var r={};var e=Object.getOwnPropertySymbols(t);e.forEach(function(e){var n=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");r[n]=Me(t[e])});var n=Object.getOwnPropertyNames(t);n.forEach(function(e){var n=t[e];if(zt(n)==="object"&&n.constructor===Object){r[e]=Ce(n)}else{r[e]=Me(n)}});return r}return t}function Me(e,n,t){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(Re.has(e)){return Re.get(e)}if(e instanceof Ne){if(!t){e.markCycles()}return e.toString(n)}if(Number.isNaN(e)){return"+nan.0"}var r=[RegExp,Ae,je,$n,Ln,ft];for(var i=0,a=r;i"}if(yn(e.toString)){return"#"}else{return e.toString()}}if(e instanceof qn){e=e.toString()}if(e===null||typeof e==="string"&&n){return JSON.stringify(e)}if(zt(e)==="object"){if(typeof e.toString==="function"&&e.toString.__lambda__){return e.toString().valueOf()}var u=e.constructor;if(!u){u=Object}var c;if(typeof u.__className==="string"){c=u.__className}else{if(Te(e)){return"#"}var s=Pe(e);if(s){if(typeof s==="function"){return s(e,n)}else{throw new Error("toString: Invalid repr value")}}c=u.name}if(St(e)==="instance"&&!yn(u)){c="instance"}if(f.HTMLElement&&e instanceof f.HTMLElement){return"#")}if(c!==""){return"#<"+c+">"}if(typeof e[Symbol.iterator]==="function"){return"#"}return"#"}if(typeof e!=="string"){return e.toString()}return e}function Te(e){return e&&zt(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}Ne.prototype.markCycles=function(){Be(this);return this};Ne.prototype.haveCycles=function(){var e=arguments.length>0&&arguments[0]!==F?arguments[0]:null;if(!e){return this.haveCycles("car")||this.haveCycles("cdr")}return!!(this.cycles&&this.cycles[e])};function Be(e){var n=[];var i=[];var a=[];function o(e){if(!n.includes(e)){n.push(e)}}function u(e,n,t,r){if(t instanceof Ne){if(r.includes(t)){if(!a.includes(t)){a.push(t)}if(!e.cycles){e.cycles={}}e.cycles[n]=t;if(!i.includes(e)){i.push(e)}return true}}}function c(e,n){if(e instanceof Ne){delete e.ref;delete e.cycles;o(e);n.push(e);var t=u(e,"car",e.car,n);var r=u(e,"cdr",e.cdr,n);if(!t){c(e.car,n.slice())}if(!r){c(e.cdr,n.slice())}}}function t(e,n){if(e.cycles[n]instanceof Ne){var t=r.indexOf(e.cycles[n]);e.cycles[n]="#".concat(t,"#")}}c(e,[]);var r=n.filter(function(e){return a.includes(e)});r.forEach(function(e,n){e.ref="#".concat(n,"=")});i.forEach(function(e){t(e,"car");t(e,"cdr")})}Ne.prototype.toString=function(e,n){var t=[];if(this.ref){t.push(this.ref+"(")}else if(!n){t.push("(")}var r;if(this.cycles&&this.cycles.car){r=this.cycles.car}else{r=Me(this.car,e,true)}if(r!==F){t.push(r)}if(this.cdr instanceof Ne){if(this.cycles&&this.cycles.cdr){t.push(" . ");t.push(this.cycles.cdr)}else{if(this.cdr.ref){t.push(" . ")}else{t.push(" ")}var i=this.cdr.toString(e,true);t.push(i)}}else if(this.cdr!==Ie){t=t.concat([" . ",Me(this.cdr,e,true)])}if(!n||this.ref){t.push(")")}return t.join("")};Ne.prototype.set=function(e,n){this[e]=n;if(n instanceof Ne){this.markCycles()}};Ne.prototype.append=function(e){if(e instanceof Array){return this.append(Ne.fromArray(e))}var n=this;if(n.car===F){if(e instanceof Ne){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(e!==Ie){while(true){if(n instanceof Ne&&n.cdr!==Ie){n=n.cdr}else{break}}n.cdr=e}return this};function $e(e){return e<0?-e:e}function De(e,n){var t=Ut(n),r=t[0],i=t.slice(1);while(i.length>0){var a=i,o=Gt(a,1),u=o[0];if(!e(r,u)){return false}var c=i;var s=Ut(c);r=s[0];i=s.slice(1)}return true}function Ue(e,n){if(typeof e==="function"&&typeof n==="function"){return on(e)===on(n)}else if(e instanceof $n&&n instanceof $n){var t;if(e.type===n.type){if(e.type==="complex"){t=e.im.type===n.im.type&&e.re.type===n.re.type}else{t=true}return t&&e.cmp(n)===0}return false}else if(typeof e==="number"||typeof n==="number"){e=$n(e);n=$n(n);return e.type===n.type&&e.cmp(n)===0}else if(e instanceof Ln&&n instanceof Ln){return e["char"]===n["char"]}else if(e instanceof je&&n instanceof je){return e.name===n.name}else{return e===n}}function Je(e,n){if(St(e)!==St(n)){return false}if(!He(e)){return false}if(e instanceof RegExp){return e.source===n.source}if(e instanceof qn){return e.valueOf()===n.valueOf()}return Ue(e,n)}function He(e){return e instanceof je||qn.isString(e)||e instanceof Ln||e instanceof $n||e===true||e===false}var Ye=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function Ge(e,n,t,r){if(typeof this!=="undefined"&&this.constructor!==Ge||typeof this==="undefined"){return new Ge(e,n)}_t("Macro",e,"string",1);_t("Macro",n,"function",2);if(t){if(r){this.__doc__=t}else{this.__doc__=ie(t)}}this.name=e;this.fn=n}Ge.defmacro=function(e,n,t,r){var i=new Ge(e,n,t,r);i.defmacro=true;return i};Ge.prototype.invoke=function(e,n,t){var r=n.env,i=n.dynamic_scope,a=n.error;var o={dynamic_scope:i,error:a,macro_expand:t};var u=this.fn.call(r,e,o,this.name);return u};Ge.prototype.toString=function(){return"#"};var ze="define-macro";var Ve=-1e4;function We(a){return function(){var t=Dt($t.mark(function e(t,v){var r,d,i;return $t.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:i=function e(){i=Dt($t.mark(function e(t,r,i){var a,o,u,c,s,f,l,p,h;return $t.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(!(t instanceof Ne&&t.car instanceof je)){n.next=24;break}if(!t.data){n.next=3;break}return n.abrupt("return",t);case 3:a=i.get(t.car,{throwError:false});if(!(a instanceof Ge&&a.defmacro)){n.next=24;break}o=a instanceof Qe?t:t.cdr;n.next=8;return a.invoke(o,v,true);case 8:u=n.sent;if(!(a instanceof Qe)){n.next=17;break}c=u,s=c.expr,f=c.scope;if(!(s instanceof Ne)){n.next=16;break}if(!(r!==-1&&r<=1||r"};Qe.className="syntax";function Ke(e,n,b,w){var _={"...":{symbols:{},lists:[]}};function x(e){if(ht.get("DEBUG",{throwError:false})){console.log(e)}}x(b);function S(e,n){var t=arguments.length>2&&arguments[2]!==F?arguments[2]:[];var r=arguments.length>3&&arguments[3]!==F?arguments[3]:false;x({code:n&&Me(n,true),pattern:e&&Me(e,true)});if(He(e)&&!(e instanceof je)){return Je(e,n)}if(e instanceof je&&b.includes(e.valueOf())){return je.is(n,e)}if(e instanceof Ne&&e.car instanceof Ne&&e.car.cdr instanceof Ne&&je.is(e.car.cdr.car,w)){x(">> 0");if(n===Ie){x({pattern:e.toString()});if(e.car.car instanceof je){if(e.car.cdr instanceof Ne&&je.is(e.car.cdr.car,w)){var i=e.car.car.valueOf();var a=e.lastPair();if(je.is(a.car,w)){_["..."].symbols[i]=null;return true}else{return false}}var o=e.car.car.valueOf();if(_["..."].symbols[o]){throw new Error("syntax: named ellipsis can only "+"appear onces")}_["..."].symbols[o]=n}}}if(e instanceof Ne&&e.cdr instanceof Ne&&je.is(e.cdr.car,w)){if(e.cdr.cdr!==Ie){if(e.cdr.cdr instanceof Ne){var u=e.cdr.cdr.length();var c=n.length();var s=n;while(c-1>u){s=s.cdr;c--}var f=s.cdr;s.cdr=Ie;if(!S(e.cdr.cdr,f,t,r)){return false}}}if(e.car instanceof je){var l=e.car.name;if(_["..."].symbols[l]&&!t.includes(l)&&!r){throw new Error("syntax: named ellipsis can only appear onces")}x(">> 1");if(n===Ie){x(">> 2");if(r){x("NIL");_["..."].symbols[l]=Ie}else{x("NULL");_["..."].symbols[l]=null}}else if(n instanceof Ne&&(n.car instanceof Ne||n.car===Ie)){x(">> 3 "+r);if(r){if(_["..."].symbols[l]){var p=_["..."].symbols[l];_["..."].symbols[l]=p.append(new Ne(n,Ie))}else{_["..."].symbols[l]=new Ne(n,Ie)}}else{x(">> 4");_["..."].symbols[l]=new Ne(n,Ie)}}else{x(">> 6");if(n instanceof Ne){x(">> 7 "+r);t.push(l);if(!_["..."].symbols[l]){_["..."].symbols[l]=new Ne(n,Ie)}else{var h=_["..."].symbols[l];_["..."].symbols[l]=h.append(new Ne(n,Ie))}x({IIIIII:_["..."].symbols[l].toString()})}else{x(">> 8");return false}}return true}else if(e.car instanceof Ne){var v=Jt(t);if(n===Ie){x(">> 9");_["..."].lists.push(Ie);return true}x(">> 10");var d=n;while(d instanceof Ne){if(!S(e.car,d.car,v,true)){return false}d=d.cdr}return true}return false}if(e instanceof je){if(je.is(e,w)){throw new Error("syntax: invalid usage of ellipsis")}x(">> 11");var m=e.name;if(b.includes(m)){return true}x({name:m,ellipsis:r});if(r){_["..."].symbols[m]=_["..."].symbols[m]||[];_["..."].symbols[m].push(n)}if(!_[m]){_[m]=n}return true}if(e instanceof Ne&&n instanceof Ne){x(">> 12");x({a:12,code:n&&n.toString(),pattern:e.toString()});if(n.cdr===Ie){var y=e.car instanceof je&&e.cdr instanceof je;if(y){x(">> 12 | 1");var g=e.cdr.valueOf();if(!_[g]){_[g]=Ie}g=e.car.valueOf();if(!_[g]){_[g]=n.car}return true}}x("recur");if(S(e.car,n.car,t,r)&&S(e.cdr,n.cdr,t,r)){return true}}else if(e===Ie&&(n===Ie||n===F)){return true}else if(e.car instanceof Ne&&je.is(e.car.car,w)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(S(e,n)){return _}}function Xe(e,i){function a(n){if(n instanceof Ne){if(!i.length){return n}var e=a(n.car);var t=a(n.cdr);return new Ne(e,t)}else if(n instanceof je){var r=i.find(function(e){return e.gensym===n});if(r){return je(r.name)}return n}else{return n}}return a(e)}function Ze(){var e=arguments.length>0&&arguments[0]!==F?arguments[0]:{};var w=e.bindings,n=e.expr,r=e.scope,i=e.symbols,a=e.names,_=e.ellipsis;var o={};function x(e){if(!(e instanceof je||typeof e==="string")){throw new Error("syntax: internal error, rename neeed to be symbol")}var n=e.valueOf();if(n===_){throw new Error("syntax: internal error, ellipis not transformed")}var t=zt(n);if(["string","symbol"].includes(t)&&n in w){return w[n]}if(i.includes(n)){return je(n)}return u(n)}function S(e){if(ht.get("DEBUG",{throwError:false})){console.log(e)}}function u(e){if(!o[e]){var n=r.get(e,{throwError:false});var t=Fe(e);a.push({name:e,gensym:t});if(typeof n!=="undefined"){r.set(t,n)}o[e]=t}return o[e]}function O(e,n,t){var r=arguments.length>3&&arguments[3]!==F?arguments[3]:function(){};var i=t.nested;S(" ==> "+e.toString());if(e instanceof je){var a=e.valueOf();S("[t 1");if(n[a]){if(n[a]instanceof Ne){var o=n[a],u=o.car,c=o.cdr;if(i){var s=u.car,f=u.cdr;if(f!==Ie){r(a,new Ne(f,Ie))}return s}if(c!==Ie){r(a,c)}return u}else if(n[a]instanceof Array){r(a,n[a].slice(1));return n[a][0]}}return x(a)}if(e instanceof Ne){if(e.car instanceof je&&e.cdr instanceof Ne&&je.is(e.cdr.car,_)){S("[t 2");var l=e.car.valueOf();var p=n[l];if(p===null){return}else if(p){S({b:n[l].toString()});if(p instanceof Ne){S("[t 2 Pair "+i);S({______:p.toString()});var h=p.car,v=p.cdr;if(i){if(v!==Ie){r(l,v)}return h}else{if(h.cdr!==Ie){r(l,new Ne(h.cdr,v))}return h.car}}else if(p instanceof Array){S("[t 2 Array "+i);if(i){r(l,p.slice(1));return Ne.fromArray(p)}else{var d=p.slice(1);if(d.length){r(l,d)}return p[0]}}else{return p}}}S("[t 3 recur "+e.toString());var m=O(e.car,n,t,r);var y=O(e.cdr,n,t,r);return new Ne(m,y)}return e}function k(n,t){var e=Object.values(n);var r=Object.getOwnPropertySymbols(n);if(r.length){e.push.apply(e,Jt(r.map(function(e){return n[e]})))}return e.length&&e.every(function(e){if(e===null){return!t}return e instanceof Ne||e===Ie||e instanceof Array&&e.length})}function j(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function E(i){var e=arguments.length>1&&arguments[1]!==F?arguments[1]:{},n=e.disabled;S(">> "+i.toString());if(i instanceof Ne){if(!n&&i.car instanceof Ne&&je.is(i.car.car,_)){return E(i.car.cdr,{disabled:true})}if(i.cdr instanceof Ne&&je.is(i.cdr.car,_)&&!n){S(">> 1");var t=w["..."].symbols;var r=j(t);if(i.car instanceof Ne){if(w["..."].lists[0]===Ie){return Ie}S(">> 2");var a;if(r.length){S(">> 2 (a)");var o=Wt({},t);a=Ie;var u=function e(){if(!k(o)){return"break"}var r={};var n=function e(n,t){r[n]=t};var t=O(i.car,o,{nested:true},n);if(t!==F){a=new Ne(t,a)}o=r};while(true){var c=u();if(c==="break")break}if(a!==Ie){a=a.reverse()}return a}else{S(">> 3");var s=O(i.car,t,{nested:true});if(s){return new Ne(s,Ie)}return Ie}}else if(i.car instanceof je){S(">> 4");var f=i.car.name;var l=Ht({},f,t[f]);var p=t[f]===null;var h=Ie;var v=function e(){if(!k(l,true)){S({bind:l});return"break"}var r={};var n=function e(n,t){r[n]=t};var t=O(i,l,{nested:false},n);if(typeof t!=="undefined"){h=new Ne(t,h)}l=r};while(true){var d=v();if(d==="break")break}if(h!==Ie){h=h.reverse()}if(i.cdr instanceof Ne){if(i.cdr.cdr instanceof Ne||i.cdr.cdr instanceof je){var m=E(i.cdr.cdr,{disabled:n});if(p){return m}h.append(m)}}return h}}var y=E(i.car,{disabled:n});var g=E(i.cdr,{disabled:n});S({a:true,head:y&&y.toString(),rest:g&&g.toString()});return new Ne(y,g)}if(i instanceof je){if(n&&je.is(i,_)){return i}var b=x(i);if(typeof b!=="undefined"){return b}}return i}return E(n,{})}function en(e){return typeof e==="undefined"||e===Ie||e===null}function nn(e){return e instanceof Promise||e&&typeof e!=="undefined"&&typeof e.then==="function"}function tn(e){switch(zt(e)){case"string":return qn(e);case"number":if(!Number.isNaN(e)){return $n(e)}}return e}function rn(n){var e=[qn,Ln,$n].some(function(e){return n instanceof e});if(e){return n.valueOf()}return n}function an(e,n){if(e instanceof Ne){e.markCycles();return lt(e)}if(typeof e==="function"){if(n){return un(e,n)}}return tn(e)}function on(e){if(cn(e)){return e[pn]}return e}function un(n,e){if(n[Symbol["for"]("__bound__")]){return n}var t=n.bind(e);var r=Object.getOwnPropertyNames(n).filter(vn);r.forEach(function(e){try{t[e]=n[e]}catch(e){}});dn(t,"__fn__",n);dn(t,"__context__",e);dn(t,"__bound__",true);if(yn(n)){dn(t,"__native__",true)}t.valueOf=function(){return n};return t}function cn(e){return!!(typeof e==="function"&&e[pn])}function sn(e){if(typeof e==="function"){var n=e[ln];if(n&&(n===Mt||n.constructor&&n.constructor.__className)){return true}}return false}function fn(e){function n(e){return e instanceof nt||e instanceof tt}if(typeof e==="function"){if(n(e)){return true}if(n(e[ln])){return true}}return false}var ln=Symbol["for"]("__context__");var pn=Symbol["for"]("__fn__");var hn=["name","length","caller","callee","arguments","prototype"];function vn(e){return!hn.includes(e)}function dn(e,n,t){Object.defineProperty(e,Symbol["for"](n),{get:function e(){return t},set:function e(){},configurable:false,enumerable:false})}function mn(n,t){try{Object.defineProperty(n,"length",{get:function e(){return t}});return n}catch(e){var r=new Array(t).fill(0).map(function(e,n){return"a"+n}).join(",");var i=new Function("f","return function(".concat(r,") {\n return f.apply(this, arguments);\n };"));return i(n)}}function yn(e){var n=Symbol["for"]("__native__");return typeof e==="function"&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[n]===true||!e.name.match(/^bound /)&&!e[n])}function gn(e){var v;switch(e){case Symbol["for"]("letrec"):v="letrec";break;case Symbol["for"]("let"):v="let";break;case Symbol["for"]("let*"):v="let*";break;default:throw new Error("Invalid let_macro value")}return Ge.defmacro(v,function(n,e){var a=e.dynamic_scope,o=e.error,t=e.macro_expand;var u;if(n.car instanceof je){if(!(n.cdr.car instanceof Ne||n.cdr.car===Ie)){throw new Error("let require list of pairs")}var r;if(n.cdr.car===Ie){u=Ie;r=Ie}else{r=n.cdr.car.map(function(e){return e.car});u=n.cdr.car.map(function(e){return e.cdr.car})}return Ne.fromArray([je("letrec"),[[n.car,Ne(je("lambda"),Ne(r,n.cdr.cdr))]],Ne(n.car,u)])}else if(t){return}var c=this;u=this.get("list->array")(n.car);var s=c.inherit(v);var f,l;if(v==="let*"){l=s}else if(v==="let"){f=[]}var p=0;function h(){var e=new Ne(new je("begin"),n.cdr);return Ft(e,{env:s,dynamic_scope:a,error:o})}return function n(){var t=u[p++];if(a){a=v==="let*"?s:c}if(!t){if(f&&f.length){var e=f.map(function(e){return e.value});var r=e.filter(nn);if(r.length){return Promise.all(e).then(function(e){for(var n=0,t=e.length;n1&&arguments[1]!==F?arguments[1]:{},t=n.dynamic_scope,r=n.error;var i=this;if(t){t=this}var a=e;var o=[];while(a instanceof Ne){o.push(Ft(a.car,{env:i,dynamic_scope:t,error:r}));a=a.cdr}var u=o.filter(nn).length;if(u){return Promise.all(o).then(c.bind(this))}else{return c.call(this,o)}})}function wn(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r2?r-2:0),a=2;a1&&arguments[1]!==F?arguments[1]:null;return function(){for(var e=arguments.length,n=new Array(e),t=0;t1?e-1:0),t=1;t=o){return a.apply(this,r)}else{return i}}return i.apply(this,arguments)}}function An(r,i){_t("limit",i,"function",2);return function(){for(var e=arguments.length,n=new Array(e),t=0;t1?r-1:0),a=1;a0){t.push(this._string.substring(0,e))}t.push(n);if(e1&&arguments[1]!==F?arguments[1]:false;if(e instanceof $n){return e}if(typeof this!=="undefined"&&!(this instanceof $n)||typeof this==="undefined"){return new $n(e,n)}if(typeof e==="undefined"){throw new Error("Invlaid LNumber constructor call")}var t=$n.getType(e);if($n.types[t]){return $n.types[t](e,n)}var r=e instanceof Array&&qn.isString(e[0])&&$n.isNumber(e[1]);if(e instanceof $n){return $n(e.value)}if(!$n.isNumber(e)&&!r){throw new Error("You can't create LNumber from ".concat(St(e)))}if(e===null){e=0}var i;if(r){var a=e,o=Gt(a,2),u=o[0],c=o[1];if(u instanceof qn){u=u.valueOf()}if(c instanceof $n){c=c.valueOf()}var s=u.match(/^([+-])/);var f=false;if(s){u=u.replace(/^[+-]/,"");if(s[1]==="-"){f=true}}}if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(r){var l;switch(c){case 8:l="0o";break;case 16:l="0x";break;case 2:l="0b";break;case 10:l="";break}if(typeof l==="undefined"){var p=BigInt(c);i=Jt(u).map(function(e,n){return BigInt(parseInt(e,c))*Math.pow(p,BigInt(n))}).reduce(function(e,n){return e+n})}else{i=BigInt(l+u)}}else{i=BigInt(e)}if(f){i*=BigInt(-1)}}else{i=e}return Vn(i,true)}else if(typeof h!=="undefined"&&!(e instanceof h)){if(e instanceof Array){return Vn(Bt(h,Jt(e)))}return Vn(new h(e))}else if(r){this.value=parseInt(u,c)}else{this.value=e}}$n.types={float:function e(n){var t=arguments.length>1&&arguments[1]!==F?arguments[1]:false;return new Un(n,t)},complex:function e(n){var t=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(!$n.isComplex(n)){n={im:0,re:n}}return new Dn(n,t)},rational:function e(n){var t=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(!$n.isRational(n)){n={num:n,denom:1}}return new zn(n,t)}};function Dn(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof Dn)||typeof this==="undefined"){return new Dn(e,n)}if(e instanceof Dn){return Dn({im:e.im,re:e.re})}if($n.isNumber(e)&&n){e={im:0,re:e.valueOf()}}else if(!$n.isComplex(e)){throw new Error("Invalid constructor call for LComplex")}var t=e.im instanceof $n?e.im:$n(e.im);var r=e.re instanceof $n?e.re:$n(e.re);if(t.cmp(0)===0&&!n){return r}this.im=t;this.re=r;this.type="complex"}Dn.prototype=Object.create($n.prototype);Dn.prototype.constructor=Dn;Dn.prototype.toRational=function(e){if($n.isFloat(this.im)&&$n.isFloat(this.re)){var n=Un(this.im).toRational(e);var t=Un(this.re).toRational(e);return Dn({im:n,re:t})}return this};Dn.prototype.add=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.add(n),im:t.add(r)}})};Dn.prototype.factor=function(){if(this.im instanceof Un||this.im instanceof Un){var e=this.re,n=this.im;var t,r;if(e instanceof Un){t=e.toRational().mul(e.toRational())}else{t=e.mul(e)}if(n instanceof Un){r=n.toRational().mul(n.toRational())}else{r=n.mul(n)}return t.add(r)}else{return this.re.mul(this.re).add(this.im.mul(this.im))}};Dn.prototype.modulus=function(){return this.factor().sqrt()};Dn.prototype.sqrt=function(){var e=this.modulus();var n,t;if(e.cmp(0)===0){n=t=e}else if(this.re.cmp(0)===1){n=Un(.5).mul(e.add(this.re)).sqrt();t=this.im.div(n).div(2)}else{t=Un(.5).mul(e.sub(this.re)).sqrt();if(this.im.cmp(0)===-1){t=t.sub()}n=this.im.div(t).div(2)}return Dn({im:t,re:n})};Dn.prototype.div=function(e){if($n.isNumber(e)&&!$n.isComplex(e)){e=Dn({im:0,re:e})}else if(!$n.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var n=this.coerce(e),t=Gt(n,2),r=t[0],i=t[1];var a=Dn({re:i.re,im:i.im.sub()});var o=i.factor().valueOf();var u=r.mul(a);var c=u.re.op("/",o);var s=u.im.op("/",o);return Dn({re:c,im:s})};Dn.prototype.sub=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.sub(n),im:t.sum(r)}})};Dn.prototype.mul=function(e){return this.complex_op(e,function(e,n,t,r){var i={re:e.mul(n).sub(t.mul(r)),im:e.mul(r).add(n.mul(t))};return i})};Dn.prototype.complex_op=function(e,n){if($n.isNumber(e)&&!$n.isComplex(e)){if(!(e instanceof $n)){e=$n(e)}var t=e.asType(0);e={im:t,re:e}}else if(!$n.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var r=e.re instanceof $n?e.re:this.re.asType(e.re);var i=e.im instanceof $n?e.im:this.im.asType(e.im);var a=n(this.re,r,this.im,i);if("im"in a&&"re"in a){var o=Dn(a,true);return o}return a};Dn._op={"+":"add","-":"sub","*":"mul","/":"div"};Dn.prototype._op=function(e,n){var t=Dn._op[e];return this[t](n)};Dn.prototype.cmp=function(e){var n=this.coerce(e),t=Gt(n,2),r=t[0],i=t[1];var a=r.re.coerce(i.re),o=Gt(a,2),u=o[0],c=o[1];var s=u.cmp(c);if(s!==0){return s}else{var f=r.im.coerce(i.im),l=Gt(f,2),p=l[0],h=l[1];return p.cmp(h)}};Dn.prototype.valueOf=function(){};Dn.prototype.toString=function(){var e;if(this.re.cmp(0)!==0){e=[this.re.toString()]}else{e=[]}e.push(this.im.cmp(0)<0?"-":"+");e.push(this.im.toString().replace(/^-/,""));e.push("i");return e.join("")};function Un(e){if(typeof this!=="undefined"&&!(this instanceof Un)||typeof this==="undefined"){return new Un(e)}if(!$n.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof $n){return Un(e.valueOf())}if(typeof e==="number"){this.value=e;this.type="float"}}Un.prototype=Object.create($n.prototype);Un.prototype.constructor=Un;Un.prototype.toString=function(){var e=this.value.toString();if(!$n.isFloat(this.value)&&!e.match(/e/i)){return e+".0"}return e.replace(/^([0-9]+)e/,"$1.0e")};Un.prototype._op=function(e,n){if(n instanceof $n){n=n.value}var t=$n._ops[e];if(e==="/"&&this.value===0&&n===0){return NaN}return Un(t(this.value,n))};Un.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==F?arguments[0]:null;if(e===null){return Jn(this.value.valueOf())}return Hn(e.valueOf())(this.value.valueOf())};var Jn=Hn(1e-10);function Hn(r){return function(e){var n=function e(r,n,t){var i=function e(n,t){return t0){i=Gn(r,t)}else if(r.cmp(t)<=0){i=t}else if(t.cmp(0)>0){i=Gn(t,r)}else if(n.cmp(0)<0){i=$n(Gn(r.sub(),t.sub())).sub()}else{i=$n(0)}if($n.isFloat(n)||$n.isFloat(e)){return Un(i)}return i}function Gn(e,n){var t=$n(e).floor();var r=$n(n).floor();if(e.cmp(t)<1){return t}else if(t.cmp(r)===0){var i=$n(1).div(n.sub(r));var a=$n(1).div(e.sub(t));return t.add($n(1).div(Gn(i,a)))}else{return t.add($n(1))}}function zn(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof zn)||typeof this==="undefined"){return new zn(e,n)}if(!$n.isRational(e)){throw new Error("Invalid constructor call for LRational")}var t=$n(e.num);var r=$n(e.denom);if(!n&&r.cmp(0)!==0){var i=t.op("%",r).cmp(0)===0;if(i){return $n(t.div(r))}}this.num=t;this.denom=r;this.type="rational"}zn.prototype=Object.create($n.prototype);zn.prototype.constructor=zn;zn.prototype.pow=function(e){var n=e.cmp(0);if(n===0){return $n(1)}if(n===-1){e=e.sub();var t=this.denom.pow(e);var r=this.num.pow(e);return zn({num:t,denom:r})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};zn.prototype.sqrt=function(){var e=this.num.sqrt();var n=this.denom.sqrt();if(e instanceof Un){e=(Tt("num"),e.toRational())}if(n instanceof Un){n=(Tt("denom"),n.toRational())}return zn({num:e,denom:n})};zn.prototype.abs=function(){var e=this.num;var n=this.denom;if(e.cmp(0)===-1){e=e.sub()}if(n.cmp(0)!==1){n=n.sub()}return zn({num:e,denom:n})};zn.prototype.cmp=function(e){return $n(this.valueOf(),true).cmp(e)};zn.prototype.toString=function(){var e=this.num.gcd(this.denom);var n,t;if(e.cmp(1)!==0){n=this.num.div(e);if(n instanceof zn){n=$n(n.valueOf(true))}t=this.denom.div(e);if(t instanceof zn){t=$n(t.valueOf(true))}}else{n=this.num;t=this.denom}var r=this.cmp(0)<0;if(r){if(n.abs().cmp(t.abs())===0){return n.toString()}}else if(n.cmp(t)===0){return n.toString()}return n.toString()+"/"+t.toString()};zn.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 $n._ops["/"](this.num.value,this.denom.value)}return Un(this.num.valueOf()).div(this.denom.valueOf())};zn.prototype.mul=function(e){if(!(e instanceof $n)){e=$n(e)}if($n.isRational(e)){var n=this.num.mul(e.num);var t=this.denom.mul(e.denom);return zn({num:n,denom:t})}var r=$n.coerce(this,e),i=Gt(r,2),a=i[0],o=i[1];return a.mul(o)};zn.prototype.div=function(e){if(!(e instanceof $n)){e=$n(e)}if($n.isRational(e)){var n=this.num.mul(e.denom);var t=this.denom.mul(e.num);return zn({num:n,denom:t})}var r=$n.coerce(this,e),i=Gt(r,2),a=i[0],o=i[1];var u=a.div(o);return u};zn.prototype._op=function(e,n){return this[Xn[e]](n)};zn.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof $n)){e=$n(e)}if($n.isRational(e)){var n=e.num.sub();var t=e.denom;return this.add(zn({num:n,denom:t}))}if(!(e instanceof $n)){e=$n(e).sub()}else{e=e.sub()}var r=$n.coerce(this,e),i=Gt(r,2),a=i[0],o=i[1];return a.add(o)};zn.prototype.add=function(e){if(!(e instanceof $n)){e=$n(e)}if($n.isRational(e)){var n=this.denom;var t=e.denom;var r=this.num;var i=e.num;var a,o;if(n!==t){o=t.mul(r).add(i.mul(n));a=n.mul(t)}else{o=r.add(i);a=n}return zn({num:o,denom:a})}if($n.isFloat(e)){return Un(this.valueOf()).add(e)}var u=$n.coerce(this,e),c=Gt(u,2),s=c[0],f=c[1];return s.add(f)};function Vn(e,n){if(typeof this!=="undefined"&&!(this instanceof Vn)||typeof this==="undefined"){return new Vn(e,n)}if(e instanceof Vn){return Vn(e.value,e._native)}if(!$n.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.value=e;this._native=n;this.type="bigint"}Vn.prototype=Object.create($n.prototype);Vn.prototype.constructor=Vn;Vn.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};Vn.prototype._op=function(e,n){if(typeof n==="undefined"){if($n.isBN(this.value)){e=Vn.bn_op[e];return Vn(this.value.clone()[e](),false)}return Vn($n._ops[e](this.value),true)}if($n.isBN(this.value)&&$n.isBN(n.value)){e=Vn.bn_op[e];return Vn(this.value.clone()[e](n),false)}var t=$n._ops[e](this.value,n.value);if(e==="/"){var r=this.op("%",n).cmp(0)===0;if(r){return $n(t)}return zn({num:this,denom:n})}return Vn(t,true)};Vn.prototype.sqrt=function(){var e;var n=this.cmp(0)<0;if($n.isNative(this.value)){e=$n(Math.sqrt(n?-this.valueOf():this.valueOf()))}else if($n.isBN(this.value)){e=n?this.value.neg().sqrt():this.value.sqrt()}if(n){return Dn({re:0,im:e})}return e};$n.prototype.gcd=function(e){var n=this.abs();e=e.abs();if(e.cmp(n)===1){var t=n;n=e;e=t}while(true){n=n.rem(e);if(n.cmp(0)===0){return e}e=e.rem(n);if(e.cmp(0)===0){return n}}};$n.isFloat=function e(n){return n instanceof Un||Number(n)===n&&n%1!==0};$n.isNumber=function(e){return e instanceof $n||!Number.isNaN(e)&&$n.isNative(e)||$n.isBN(e)};$n.isComplex=function(e){var n=e instanceof Dn||$n.isNumber(e.im)&&$n.isNumber(e.re);return n};$n.isRational=function(e){return e instanceof zn||$n.isNumber(e.num)&&$n.isNumber(e.denom)};$n.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};$n.isBigInteger=function(e){return e instanceof Vn||typeof e==="bigint"||$n.isBN(e)};$n.isBN=function(e){return typeof h!=="undefined"&&e instanceof h};$n.getArgsType=function(e,n){if(e instanceof Un||n instanceof Un){return Un}if(e instanceof Vn||n instanceof Vn){return Vn}return $n};$n.prototype.toString=$n.prototype.toJSON=function(e){if(e>2&&e<36){return this.value.toString(e)}return this.value.toString()};$n.prototype.asType=function(e){var n=$n.getType(this);return $n.types[n]?$n.types[n](e):$n(e)};$n.prototype.isBigNumber=function(){return typeof this.value==="bigint"||typeof h!=="undefined"&&!(this.value instanceof h)};["floor","ceil","round"].forEach(function(e){$n.prototype[e]=function(){if(this["float"]||$n.isFloat(this.value)){return $n(Math[e](this.value))}else{return $n(Math[e](this.valueOf()))}}});$n.prototype.valueOf=function(){if($n.isNative(this.value)){return Number(this.value)}else if($n.isBN(this.value)){return this.value.toNumber()}};var Wn=function(){var e=function e(n,t){return[n,t]};return{bigint:{bigint:e,float:function e(n,t){return[Un(n.valueOf()),t]},rational:function e(n,t){return[{num:n,denom:1},t]},complex:function e(n,t){return[{im:0,re:n},t]}},float:{bigint:function e(n,t){return[n,t&&Un(t.valueOf())]},float:e,rational:function e(n,t){return[n,t&&Un(t.valueOf())]},complex:function e(n,t){return[{re:n,im:Un(0)},t]}},complex:{bigint:n("bigint"),float:n("float"),rational:n("rational"),complex:function e(n,t){var r=$n.coerce(n.re,t.re),i=Gt(r,2),a=i[0],o=i[1];var u=$n.coerce(n.im,t.im),c=Gt(u,2),s=c[0],f=c[1];return[{im:s,re:a},{im:f,re:o}]}},rational:{bigint:function e(n,t){return[n,t&&{num:t,denom:1}]},float:function e(n,t){return[Un(n.valueOf()),t]},rational:e,complex:function e(n,t){return[{im:Qn(n.type,t.im.type,0),re:Qn(n.type,t.re.type,n)},{im:Qn(n.type,t.im.type,t.im),re:Qn(n.type,t.re.type,t.re)}]}}};function n(t){return function(e,n){return[{im:Qn(t,e.im.type,e.im),re:Qn(t,e.re.type,e.re)},{im:Qn(t,e.im.type,0),re:Qn(t,n.type,n)}]}}}();function Qn(e,n,t){return Wn[e][n](t)[0]}$n.coerce=function(e,n){function t(e){if(e==="integer"){return"bigint"}return e}var r=t($n.getType(e));var i=t($n.getType(n));if(!Wn[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!Wn[r][i]){throw new Error("LNumber::coerce unknown rhs type ".concat(i))}return Wn[r][i](e,n).map(function(e){return $n(e,true)})};$n.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof $n)){throw new Error("LNumber: you can't coerce ".concat(St(e)))}if(typeof e==="number"){e=$n(e)}return $n.coerce(this,e)};$n.getType=function(e){if(e instanceof $n){return e.type}if($n.isFloat(e)){return"float"}if($n.isComplex(e)){return"complex"}if($n.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof h!=="undefined"&&!(e instanceof h)){return"bigint"}};$n.prototype.isFloat=function(){return!!($n.isFloat(this.value)||this["float"])};var Kn={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var Xn={};Object.keys(Kn).forEach(function(n){Xn[Kn[n]]=n;$n.prototype[n]=function(e){return this.op(Kn[n],e)}});$n._ops={"*":function e(n,t){return n*t},"+":function e(n,t){return n+t},"-":function e(n,t){if(typeof t==="undefined"){return-n}return n-t},"/":function e(n,t){return n/t},"%":function e(n,t){return n%t},"|":function e(n,t){return n|t},"&":function e(n,t){return n&t},"~":function e(n){return~n},">>":function e(n,t){return n>>t},"<<":function e(n,t){return n<=this._string.length){return at}return Ln(this._string[this._in_char])};function tt(e){if(typeof this!=="undefined"&&!(this instanceof tt)||typeof this==="undefined"){return new tt(e)}_t("OutputPort",e,"function");this.write=e}tt.prototype.toString=function(){return"<#output-port>"};function rt(n){var t=this;if(typeof this!=="undefined"&&!(this instanceof rt)||typeof this==="undefined"){return new rt(n)}_t("OutputStringPort",n,"function");this._buffer=[];this.write=function(e){if(!qn.isString(e)){e=n(e)}else{e=e.valueOf()}t._buffer.push(e)}}rt.prototype=Object.create(tt.prototype);rt.prototype.getString=function(){return this._buffer.map(function(e){return e.valueOf()}).join("")};rt.prototype.constructor=rt;function it(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof it)||typeof this==="undefined"){return new it(e)}_t("InputStringPort",e,"string");this._string=e.valueOf();this._index=0;this._in_char=0;this.read=function(){return n.get_next_tokens()}}it.prototype=Object.create(nt.prototype);it.prototype.constructor=it;it.prototype.read_line=function(){var e=this._string.substring(this._in_char);if(!e){return at}var n=e.match(/([^\n])(?:\n|$)/)[0];this._in_char+=n.length;return n};var at=new ot;function ot(){}ot.prototype.toString=function(){return"<#eof>"};function ut(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:{};if(typeof this!=="undefined"&&!(this instanceof ut)||typeof this==="undefined"){return new ut(e,n)}if(typeof e==="undefined"){e="anonymous"}this.env=ht.inherit(e,n)}ut.prototype.exec=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;_t("Intepreter::exec",e,"string",1);_t("Intepreter::exec",n,"boolean",2);pt.set("**interaction-environment**",this.env);return At(e,this.env,n?this.env:false)};ut.prototype.get=function(e){return this.env.get(e).bind(this.env)};ut.prototype.set=function(e,n){return this.env.set(e,n)};function ct(e,n,t){if(arguments.length===1){if(zt(arguments[0])==="object"){e=arguments[0];this.parent=null}else if(typeof arguments[0]==="string"){e={};n={};t=arguments[0]}}this.docs=new Map;this.env=e;this.parent=n;this.name=t||"anonymous"}ct.prototype.inherit=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:{};if(zt(e)==="object"){n=e}if(!e||zt(e)==="object"){e="child of "+(this.name||"unknown")}return new ct(n||{},this,e)};ct.prototype.doc=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:null;if(e instanceof je){e=e.name}if(e instanceof qn){e=e.valueOf()}if(n){this.docs.set(e,n);return this}if(this.docs.has(e)){return this.docs.get(e)}if(this.parent){return this.parent.doc(e)}};ct.prototype.newFrame=function(e,n){var r=this.inherit("__frame__");r.set("parent.frame",re(function(){var e=arguments.length>0&&arguments[0]!==F?arguments[0]:1;var n=r.parent;if(!(n instanceof ct)){return Ie}if(e<=0){return n}var t=n.get("parent.frame");return t(e-1)},pt.env["parent.frame"].__doc__));n.callee=e;r.set("arguments",n);return r};ct.prototype._lookup=function(e){if(e instanceof je){e=e.name}if(e instanceof qn){e=e.valueOf()}if(this.env.hasOwnProperty(e)){return st(this.env[e])}if(this.parent){return this.parent._lookup(e)}};ct.prototype.toString=function(){return"<#env:"+this.name+">"};ct.prototype.clone=function(){var n=this;var t={};Object.keys(this.env).forEach(function(e){t[e]=n.env[e]});return new ct(t,this.parent,this.name)};ct.prototype.merge=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:"merge";_t("Environment::merge",e,"environment");return this.inherit(n,e.env)};function st(e){if(typeof this!=="undefined"&&!(this instanceof st)||typeof this==="undefined"){return new st(e)}this.value=e}st.isUndefined=function(e){return e instanceof st&&typeof e.value==="undefined"};st.prototype.valueOf=function(){return this.value};function ft(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof ft)||typeof this==="undefined"){return new ft(e)}this.values=e}ft.prototype.toString=function(){return this.values.map(function(e){return Me(e)}).join("\n")};ft.prototype.valueOf=function(){return this.values};ct.prototype.get=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:{};var t=n.throwError,r=t===void 0?true:t;var i=e;if(i instanceof je||i instanceof qn){i=i.valueOf()}var a=this._lookup(i);if(a instanceof st){if(st.isUndefined(a)){return F}return an(a.valueOf())}if(typeof i==="string"){var o=i.split(".").filter(Boolean);if(o.length>0){var u=Ut(o),c=u[0],s=u.slice(1);a=this._lookup(c);if(s.length){try{if(a instanceof st){a=a.valueOf()}else{a=Nn(f,c);if(typeof a==="function"){a=on(a)}}return Nn.apply(void 0,[a].concat(Jt(s)))}catch(e){}}else if(a instanceof st){return an(a.valueOf())}}a=Nn(f,i)}if(typeof a!=="undefined"){return a}if(r){throw new Error("Unbound variable `"+i.toString()+"'")}};ct.prototype.set=function(e,n){var t=arguments.length>2&&arguments[2]!==F?arguments[2]:null;if($n.isNumber(n)){n=$n(n)}if(e instanceof je){e=e.name}if(e instanceof qn){e=e.valueOf()}this.env[e]=n;if(t){this.doc(e,t)}return this};ct.prototype.has=function(e){return this.env.hasOwnProperty(e)};ct.prototype.ref=function(e){var n=this;while(true){if(!n){break}if(n.has(e)){return n}n=n.parent}};ct.prototype.parents=function(){var e=this;var n=[];while(e){n.unshift(e);e=e.parent}return n};function lt(e){if(nn(e)){return e.then(lt)}if(e instanceof Ne||e instanceof je){e.data=true}return e}var pt=new ct({nil:Ie,undefined:F,true:true,false:false,null:null,NaN:NaN,stdout:new tt(function(){var e;(e=console).log.apply(e,arguments)}),stdin:nt(function(){return new Promise(function(e){e(prompt(""))})}),"open-input-string":re(function(e){_t("open-input-string",e,"string");return it(e)},"(open-input-string string)\n\n Function create new string port as input that can be used to\n read S-exressions from this port using `read` function."),"output-port?":re(function(e){return e instanceof tt},"(output-port? arg)\n\n Function return true if argument is output port."),"input-port?":re(function(e){return e instanceof nt},"(input-port? arg)\n\n Function return true if argument is input port."),"open-output-string":re(function(){return rt(this.get("repr"))},"(open-output-string)\n\n Function create new output port that can used to write string into\n and after finish get the whole string using `get-output-string`"),"get-output-string":re(function(e){_t("get-output-string",e,"output-string-port");return e.getString()},"(get-output-string port)\n\n Function get full string from string port. If nothing was wrote\n to given port it will return empty string."),"eof-object?":re(function(e){return e===at},"(eof-object? arg)\n\n Function check if value is eof object, returned from input string\n port when there are no more data to read."),"peek-char":re(function(e){_t("peek-char",e,["input-port","input-string-port"]);return e.peek_char()},"(peek-char port)\n\n Function get character from string port or EOF object if no more\n data in string port."),"read-line":re(function(e){if(typeof e==="undefined"){e=this.get("stdin")}_t("read-line",e,["input-port","input-string-port"]);return e.read_line()},"(read-char port)\n\n Function read next character from input port."),"read-char":re(function(e){if(typeof e==="undefined"){e=this.get("stdin")}_t("read-char",e,["input-port","input-string-port"]);return e.read_char()},"(read-char port)\n\n Function read next character from input port."),read:re(function e(n){if(qn.isString(n)){return ee(W(n.valueOf()))[0]}var t;if(n instanceof nt){t=n}else{t=this.get("stdin")}return ne(t.read(),function(e){if(e===at){return at}return ee(e)[0]})},"(read [string])\n\n Function if used with string will parse the string and return\n list structure of LIPS code. If called without an argument it\n will read string from standard input (using browser prompt or\n user defined way) and call itself with that string (parse is)\n function can be used together with eval to evaluate code from\n string"),pprint:re(function(e){if(e instanceof Ne){e=new Mt.Formatter(e.toString(true))["break"]().format();this.get("display").call(this,e)}else{this.get("write").call(this,e)}this.get("newline").call(this)},"(pprint expression)\n\n Pretty print list expression, if called with non-pair it just call\n print function with passed argument."),print:re(function(){var n=this;var t=this.get("display");var r=this.get("newline");for(var e=arguments.length,i=new Array(e),a=0;a1?t-1:0),i=1;ir.length){throw new Error("Not enough arguments")}var u=0;var c=this.get("repr");n=n.replace(a,function(e){var n=e[1];if(n==="~"){return"~"}else if(n==="%"){return"\n"}else{var t=r[u++];if(n==="a"){return c(t)}else{return c(t,true)}}});o=n.match(/~([\S])/);if(o){throw new Error("format: Unrecognized escape seqence ".concat(o[1]))}return n},"(format string n1 n2 ...)\n\n Function accepts string template and replacing any escape sequences\n by arguments:\n\n * ~a value as if printed with display\n * ~s value as if printed with write\n * ~% newline character\n * ~~ literal tilde '~' is inserted\n\n if there missing arguments or other escape character it throw exception."),display:re(function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:null;if(n===null){n=this.get("stdout")}n.write.call(this,this.get("repr")(e))},"(display arg [port])\n\n Function send string to standard output or provied port."),error:re(function(){for(var e=arguments.length,n=new Array(e),t=0;t1&&arguments[1]!==F?arguments[1]:{},t=n.dynamic_scope,r=n.error;if(t){t=this}var o;var i=Ft(e.cdr.car,{env:this,dynamic_scope:t,error:r});i=Ot(i);function u(n,t){if(nn(n)){return n.then(function(e){return u(e,t)})}if(nn(t)){return t.then(function(e){return u(n,e)})}f[n]=t;return t}if(e.car instanceof Ne&&je.is(e.car.car,".")){var c=e.car.cdr.car;var s=e.car.cdr.cdr.car;var f=Ft(c,{env:this,dynamic_scope:t,error:r});var l=Ft(s,{env:this,dynamic_scope:t,error:r});return u(l,i)}if(!(e.car instanceof je)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var p=e.car.valueOf();o=this.ref(e.car.name);return ne(i,function(e){if(!o){var n=p.split(".");if(n.length>1){var t=n.pop();var r=n.join(".");var i=a.get(r,{throwError:false});if(i){a.get("set-obj!").call(a,i,t,e);return}}o=a}o.set(p,e)})}),"(set! name value)\n\n Macro that can be used to set the value of the variable (mutate)\n it search the scope chain until it finds first non emtpy slot and set it."),"unset!":re(new Ge("set!",function(e){if(!(e.car instanceof je)){throw new Error("unset! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var n=e.car;var t=this.ref(n);if(t){delete t.env[n.name]}}),"(unset! name)\n\n Function delete specified name from environment."),"set-car!":re(function(e,n){_t("set-car!",e,"pair");e.car=n},"(set-car! obj value)\n\n Function that set car (head) of the list/pair to specified value.\n It can destroy the list. Old value is lost."),"set-cdr!":re(function(e,n){_t("set-cdr!",e,"pair");e.cdr=n},"(set-cdr! obj value)\n\n Function that set cdr (tail) of the list/pair to specified value.\n It can destroy the list. Old value is lost."),"empty?":re(function(e){return typeof e==="undefined"||e===Ie},"(empty? object)\n\n Function return true if value is undfined empty list."),assoc:re(function(e,n){if(e instanceof Ne&&!(n instanceof Ne)){throw new Error("First argument to assoc ned to be a key")}_t("assoc",n,"pair");var t=n;while(true){if(!(t instanceof Ne)||this.get("empty?")(t)){break}var r=t.car.car;if(Ue(r,e)){return t.car}else if(!t.haveCycles("cdr")){t=t.cdr}}return Ie},"(assoc key alist)\n\n Function search Alist (list of pairs) until it find the one that\n have head set equal to key, and return found pair."),gensym:re(Fe,"(gensym)\n\n Function generate unique symbol, to use with macros as meta name."),load:re(function(n){_t("load",n,"string");var e=this;if(e.name==="__frame__"){e=e.parent}var i;if(e===pt){i=e}else{i=this.get("**interaction-environment**")}var a="**module-path**";var o=pt.get(a,{throwError:false});n=n.valueOf();if(!n.match(/.[^.]+$/)){n+=".scm"}if(typeof this.get("global",{throwError:false})!=="undefined"){return new Promise(function(t,r){var e=require("path");if(o){o=o.valueOf();n=e.join(o,n)}pt.set(a,e.dirname(n));require("fs").readFile(n,function(e,n){if(e){console.log(e);r(e);pt.set(a,o)}else{At(n.toString(),i).then(function(){t();pt.set(a,o)})["catch"](r)}})})}if(o){o=o.valueOf();n=o+"/"+n.replace(/^\.?\/?/,"")}return f.fetch(n).then(function(e){return e.text()}).then(function(e){pt.set(a,n.replace(/\/[^/]*$/,""));return At(e,i)}).then(function(){})["finally"](function(){pt.set(a,o)})},"(load filename)\n\n Function fetch the file and evaluate its content as LIPS code."),while:re(new Ge("while",function(r,e){var i=e.dynamic_scope,a=e.error;var o=this;var u=new Ne(new je("begin"),r.cdr);var c;if(i){i=o}return function n(){var e=Ft(r.car,{env:o,dynamic_scope:i,error:a});function t(e){if(e&&!en(e)){c=Ft(u,{env:o,dynamic_scope:i,error:a});if(nn(c)){return c.then(function(e){c=e;return n()})}else{return n()}}else{return c}}return ne(e,t)}()}),"(while cond . body)\n\n Macro that create a loop, it exectue body untill cond expression is false"),if:re(new Ge("if",function(t,e){var r=e.dynamic_scope,i=e.error;if(r){r=this}var a=this;var n=function e(n){if(n){return Ft(t.cdr.car,{env:a,dynamic_scope:r,error:i})}else{return Ft(t.cdr.cdr.car,{env:a,dynamic_scope:r,error:i})}};var o=Ft(t.car,{env:a,dynamic_scope:r,error:i});return ne(o,n)}),"(if cond true-expr false-expr)\n\n Macro evaluate condition expression and if the value is true, it\n evaluate and return true expression if not it evaluate and return\n false expression"),"let-env":new Ge("let-env",function(n){var e=arguments.length>1&&arguments[1]!==F?arguments[1]:{};var t=e.dynamic_scope,r=e.error;_t("let-env",n,"pair");var i=Ft(n.car,{env:this,dynamic_scope:t,error:r});return ne(i,function(e){if(!(e instanceof ct)){throw new Error("let-env: First argument need to be "+"environment")}return Ft(Ne(je("begin"),n.cdr),{env:e,dynamic_scope:t,error:r})})},"(let-env env . body)\n\n Special macro that evaluate body in context of given environment\n object."),letrec:re(gn(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*":re(gn(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:re(gn(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*":re(bn("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:re(new Ge("begin",function(e,n){var r=Object.assign({},n);var i=this.get("list->array")(e);if(r.dynamic_scope){r.dynamic_scope=this}r.env=this;var a;return function n(){if(i.length){var e=i.shift();var t=Ft(e,r);return ne(t,function(e){a=e;return n()})}else{return a}}()}),"(begin . args)\n\n Macro runs list of expression and return valuate of the list one.\n It can be used in place where you can only have single exression,\n like if expression."),ignore:new Ge("ignore",function(e,n){var t=n.dynamic_scope,r=n.error;var i={env:this,error:r};if(t){i.dynamic_scope=this}Ft(new Ne(new je("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:re(Ge.defmacro("define",function(t,e){var r=this;if(t.car instanceof Ne&&t.car.car instanceof je){var n=new Ne(new je("define"),new Ne(t.car.car,new Ne(new Ne(new je("lambda"),new Ne(t.car.cdr,t.cdr)))));return n}else if(e.macro_expand){return}if(e.dynamic_scope){e.dynamic_scope=this}e.env=r;var i=t.cdr.car;if(i instanceof Ne){i=Ft(i,e)}else if(i instanceof je){i=r.get(i)}_t("define",t.car,"symbol");return ne(i,function(e){if(r.name===Qe.merge_env){r=r.parent}var n;if(t.cdr.cdr instanceof Ne&&qn.isString(t.cdr.cdr.car)){n=t.cdr.cdr.car.valueOf()}r.set(t.car,e,n)})}),"(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!":re(function(e,n,t){var r=zt(e);if(en(e)||r!=="object"&&r!=="function"){var i=wt("set-obj!",St(e),["object","function"]);throw new Error(i)}e=on(e);n=n.valueOf();if(arguments.length===2){delete e[n]}else if(Te(e)&&typeof t==="function"){e[n]=on(t);e[n].__prototype__=true}else if(typeof t==="function"){e[n]=t}else{e[n]=t?t.valueOf():t}},"(set-obj! obj key value)\n\n Function set property of JavaScript object"),"null-environment":re(function(){return pt.inherit("null")},"(null-environment)\n\n Function return new base environment with std lib."),values:re(function(){for(var e=arguments.length,n=new Array(e),t=0;t1&&arguments[1]!==F?arguments[1]:{},p=e.dynamic_scope,h=e.error;var v=this;var d;if(l.cdr instanceof Ne&&qn.isString(l.cdr.car)&&l.cdr.cdr!==Ie){d=l.cdr.car.valueOf()}function m(){var e;if(p){if(!(this instanceof ct)){e=v}else{e=this}}else{e=v}e=e.inherit("lambda");var n=l.car;var t=0;var r;if(typeof this!=="undefined"){e.set("this",this)}for(var i=arguments.length,a=new Array(i),o=0;o2&&arguments[2]!==F?arguments[2]:c;if(e instanceof Ne){var r=e.car;var i=e.cdr;if(t(r)){r=n(r)}if(t(i)){i=n(i)}if(nn(r)||nn(i)){return Promise.all([r,i]).then(function(e){var n=Gt(e,2),t=n[0],r=n[1];return new Ne(t,r)})}else{return new Ne(r,i)}}return e}function i(e,n){if(e instanceof Ne){if(n!==Ie){e.append(n)}}else{e=new Ne(e,n)}return e}function f(r,e,n){if(et){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(e.cdr instanceof Ne){if(e.cdr.cdr!==Ie){if(e.cdr.car instanceof Ne){var i=Ie;return function n(t){if(t===Ie){return i}return ne(Ft(t.car,{env:u,dynamic_scope:a,error:o}),function(e){i=new Ne(e,i);return n(t.cdr)})}(e.cdr)}else{return e.cdr}}else{return Ft(e.cdr.car,{env:u,dynamic_scope:a,error:o})}}else{return e.cdr}}return s(e,function(e){return p(e,n,t)})}return e}function t(e){if(e instanceof Ne){delete e.data;if(!e.haveCycles("car")){t(e.car)}if(!e.haveCycles("cdr")){t(e.cdr)}}}var r=p(e.car,0,1);return ne(r,function(e){t(e);return lt(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:re(function(e){_t("clone",e,"pair");return e.clone()},"(clone list)\n\n Function return clone of the list."),append:re(function(e,n){_t("append",e,["nil","pair"]);if(e instanceof Ne){e=e.clone()}return this.get("append!").call(this,e,n)},"(append list item)\n\n Function will create new list with value appended to the end. It return\n New list."),"append!":re(function(e,n){_t("append!",e,["pair","nil"]);if(!this.get("list?")(e)){throw new Error("append!: Invalid argument, value is not a list")}if(en(n)){return e}if(e===Ie){if(n===Ie){return Ie}return n}return e.append(n)},"(append! name expression)\n\n Destructive version of append, it modify the list in place. It return\n original list."),reverse:re(function(e){_t("reverse",e,["array","pair","nil"]);if(e===Ie){return Ie}if(e instanceof Ne){var n=this.get("list->array")(e).reverse();return this.get("array->list")(n)}else if(!(e instanceof Array)){throw new Error(wt("reverse",St(e),"array or pair"))}else{return e.reverse()}},"(reverse list)\n\n Function will reverse the list or array. If value is not a list\n or array it will throw exception."),nth:re(function(e,n){_t("nth",e,"number");_t("nth",n,["array","pair"]);if(n instanceof Ne){var t=n;var r=0;while(rarray")(n).join(e)},"(join separator list)\n\n Function return string by joining elements of the list"),split:re(function(e,n){_t("split",e,["regex","string"]);_t("split",n,"string");return this.get("array->list")(n.split(e))},"(split separator string)\n\n Function create list by splitting string by separatar that can\n be a string or regular expression."),replace:re(function(e,n,t){_t("replace",e,["regex","string"]);_t("replace",n,["string","function"]);_t("replace",t,"string");return t.replace(e,n)},"(replace pattern replacement string)\n\n Function change pattern to replacement inside string. Pattern can be string\n or regex and replacement can be function or string."),match:re(function(e,n){_t("match",e,["regex","string"]);_t("match",n,"string");var t=n.match(e);return t?this.get("array->list")(t):Ie},"(match pattern string)\n\n function return match object from JavaScript as list."),search:re(function(e,n){_t("search",e,["regex","string"]);_t("search",n,"string");return n.search(e)},"(search pattern string)\n\n Function return first found index of the pattern inside a string"),repr:re(function e(n,t){return Me(n,t)},"(repr obj)\n\n Function return string LIPS representation of an object as string."),env:re(function(e){e=e||this;var n=Object.keys(e.env);var t;if(n.length){t=Ne.fromArray(n)}else{t=Ie}if(e.parent!==F){return this.get("env").call(this,e.parent).append(t)}return t},"(env obj)\n\n Function return list values (functions and variables) inside environment."),new:re(function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r2&&arguments[2]!==F?arguments[2]:K.LITERAL;_t("set-special!",e,"string",1);_t("set-special!",n,"symbol",2);Mt.specials.append(e.valueOf(),n,t)},'(set-special! symbol name [type])\n\n Add special symbol to the list of transforming operators by the parser.\n e.g.: `(add-special! "#" \'x)` will allow to use `#(1 2 3)` and it will be\n transformed into (x (1 2 3)) so you can write x macro that will process\n the list. 3rd argument is optional and it can be constant value\n lips.specials.SPLICE if this constant is used it will transform\n `#(1 2 3)` into (x 1 2 3) that is required by # that define vectors.'),get:Nn,".":Nn,unbind:re(on,"(unbind fn)\n\n Function remove bidning from function so you can get props from it."),type:re(St,"(type object)\n\n Function return type of an object as string."),debugger:re(function(){debugger},"(debugger)\n\n Function stop JavaScript code in debugger."),in:re(function(e,n){if(e instanceof je||e instanceof qn){e=e.valueOf()}return e in n},"(in key value)\n\n Function use is in operator to check if value is in object."),instanceof:re(function(e,n){return n instanceof on(e)},"(instanceof type obj)\n\n Function check of object is instance of object."),"prototype?":re(Te,"(prototype? obj)\n\n Function check if value is JavaScript Object prototype."),"macro?":re(function(e){return e instanceof Ge},"(macro? expression)\n\n Function check if value is a macro."),"function?":re(function(e){return typeof e==="function"},"(function? expression)\n\n Function check if value is a function."),"real?":re(function(e){if(St(e)!=="number"){return false}if(e instanceof $n){return e.isFloat()}return $n.isFloat(e)},"(real? number)\n\n Function check if value is real number."),"number?":re($n.isNumber,"(number? expression)\n\n Function check if value is a number"),"string?":re(function(e){return qn.isString(e)},"(string? expression)\n\n Function check if value is a string."),"pair?":re(function(e){return e instanceof Ne},"(pair? expression)\n\n Function check if value is a pair or list structure."),"regex?":re(function(e){return e instanceof RegExp},"(regex? expression)\n\n Function check if value is regular expression."),"null?":re(function(e){return en(e)},"(null? expression)\n\n Function check if value is nulish."),"boolean?":re(function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Function check if value is boolean."),"symbol?":re(function(e){return e instanceof je},"(symbol? expression)\n\n Function check if value is LIPS symbol"),"array?":re(function(e){return e instanceof Array},"(array? expression)\n\n Function check if value is an arrray."),"object?":re(function(e){return e!==Ie&&e!==null&&!(e instanceof $n)&&zt(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Function check if value is an object."),flatten:re(function(e){_t("flatten",e,"pair");return e.flatten()},"(flatten list)\n\n Return shallow list from tree structure (pairs)."),"array->list":re(function(e){_t("array->list",e,"array");return Ne.fromArray(e)},"(array->list array)\n\n Function convert JavaScript array to LIPS list."),"tree->array":re(Le("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":re(Le("list->array"),"(list->array list)\n\n Function convert LIPS list into JavaScript array."),apply:re(function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;rarray").call(this,i));return e.apply(this,t)},"(apply fn list)\n\n Function that call function with list of arguments."),length:re(function(e){if(!e){return $n(0)}if(e instanceof Ne){return $n(e.length())}if("length"in e){return $n(e.length)}},"(length expression)\n\n Function return length of the object, the object can be list\n or any object that have length property."),"string->number":re(function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:10;_t("string->number",e,"string",1);_t("string->number",n,"number",2);e=e.valueOf();n=n.valueOf();if(e.match(S)||e.match(w)){return A(e,n)}else if(e.match(O)||e.match(b)){return L(e,n)}else{var t=n===10&&!e.match(/e/i)||n===16;if(e.match(x)&&t||e.match(_)){return I(e,n)}if(e.match(c)){return R(e)}}return false},"(string->number number [radix])\n\n Function convert string to number."),try:re(new Ge("try",function(a,e){var o=this;var u=e.dynamic_scope,c=e.error;return new Promise(function(i){var e={env:o,error:function e(n){var t=o.inherit("try");t.set(a.cdr.car.cdr.car.car,n);var r={env:t,error:c};if(u){r.dynamic_scope=o}ne(Ft(new Ne(new je("begin"),a.cdr.car.cdr.cdr),r),function(e){i(e)})}};if(u){e.dynamic_scope=o}var n=Ft(a.car,e);if(nn(n)){n.then(i)["catch"](e.error)}else{i(n)}})}),"(try expr (catch (e) code)"),throw:re(function(e){throw new Error(e)},"(throw string)\n\n Throw new expection."),find:re(function n(t,r){_t("find",t,["regex","function"]);_t("find",r,"pair");if(en(r)){return Ie}var e=te("find",t);return ne(e(r.car),function(e){if(e&&e!==Ie){return r.car}return n(t,r.cdr)})},"(find fn list)\n (find regex list)\n\n Higher order Function find first value for which function return true.\n If called with regex it will create matcher function."),"for-each":re(function(e){var n;_t("for-each",e,"function");for(var t=arguments.length,r=new Array(t>1?t-1:0),i=1;i1?n-1:0),a=1;a3?r-3:0),a=3;a3?i-3:0),o=3;oarray")(n);var a=[];var o=te("filter",e);return function n(t){function e(e){if(e&&e!==Ie){a.push(r)}return n(++t)}if(t===i.length){return Ne.fromArray(a)}var r=i[t];return ne(o(r,t),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher order function that call `fn` for each element of the list\n and return list for only those elements for which funtion return\n true value. If called with regex it will create matcher function."),range:re(function(e){_t("range",e,"number");if(e instanceof $n){e=e.valueOf()}return Ne.fromArray(new Array(e).fill(0).map(function(e,n){return $n(n)}))},"(range n)\n\n Function return list of n numbers from 0 to n - 1"),compose:re(xn,"(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:re(_n,"(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:re(Fn,"(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:re(function e(){for(var n=arguments.length,t=new Array(n),r=0;rr?n%=r:r%=n}n=$e(i*(t<0||arguments.length<=t?F:arguments[t]))/(n+r)}return $n(n)},"(lcm n1 n2 ...)\n\n Function return the least common multiple of their arguments."),"odd?":re(kn(function(e){return $n(e).isOdd()}),"(odd? number)\n\n Function check if number os odd."),"even?":re(kn(function(e){return $n(e).isEven()}),"(even? number)\n\n Function check if number is even."),"*":re(En(function(e,n){return $n(e).mul(n)},$n(1)),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":re(En(function(e,n){return $n(e).add(n)},$n(0)),"(+ . numbers)\n\n Sum all numbers passed as arguments. If single value is passed it will\n return that value."),"-":re(function(){for(var e=arguments.length,n=new Array(e),t=0;t":re(function(){for(var e=arguments.length,n=new Array(e),t=0;t x1 x2 x3 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically increasing"),"<":re(function(){for(var e=arguments.length,n=new Array(e),t=0;t=":re(function(){for(var e=arguments.length,n=new Array(e),t=0;t= x1 x2 x3 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically nondecreasing"),"eq?":re(Ue,"(eq? a b)\n\n Function compare two values if they are identical."),or:re(new Ge("or",function(e,n){var i=n.dynamic_scope,a=n.error;var o=this.get("list->array")(e);var u=this;if(i){i=u}var c;return function n(){function e(e){c=e;if(c){return c}else{return n()}}var t=o.shift();if(typeof t==="undefined"){if(c){return c}else{return false}}else{var r=Ft(t,{env:u,dynamic_scope:i,error:a});return ne(r,e)}}()}),"(or . expressions)\n\n Macro execute the values one by one and return the one that is truthy value.\n If there are no expression that evaluate to true it return false."),and:re(new Ge("and",function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:{},i=n.dynamic_scope,a=n.error;var o=this.get("list->array")(e);var u=this;if(i){i=u}if(!o.length){return true}var c;return function n(){function e(e){c=e;if(!c){return false}else{return n()}}var t=o.shift();if(typeof t==="undefined"){if(c){return c}else{return false}}else{var r=Ft(t,{env:u,dynamic_scope:i,error:a});return ne(r,e)}}()}),"(and . expressions)\n\n Macro evalute each expression in sequence if any value return false it will\n return false. If each value return true it will return the last value.\n If it's called without arguments it will return true."),"|":re(function(e,n){return $n(e).or(n)},"(& a b)\n\n Function calculate or bit operation."),"&":re(function(e,n){return $n(e).and(n)},"(& a b)\n\n Function calculate and bit operation."),"~":re(function(e){return $n(e).neg()},"(~ number)\n\n Function negate the value."),">>":re(function(e,n){return $n(e).shr(n)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":re(function(e,n){return $n(e).shl(n)},"(<< a b)\n\n Function left shit the value a by value b."),not:re(function(e){if(en(e)){return true}return!e},"(not object)\n\n Function return negation of the argument.")},F,"global");var ht=pt.inherit("user-env");pt.set("**interaction-environment**",ht);(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(n){var t=e[n]?e[n]:n;pt.set(t,re(function(e){_t(t,e,"number");if(e instanceof $n){return e[n]()}},"(".concat(t," number)\n\n Function calculate ").concat(t," of a number.")))})})();function vt(e){if(e.length===1){return e[0]}else{var n=[];var t=vt(e.slice(1));for(var r=0;r3&&arguments[3]!==F?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(r!==null){i+=" argument ".concat(r)}if(t instanceof Array){var a=t[t.length-1];t=t.slice(0,-1).join(", ")+" or "+a}return"Expecting ".concat(t," got ").concat(n).concat(i)}function _t(e,n,t){var r=arguments.length>3&&arguments[3]!==F?arguments[3]:null;e=e.valueOf();var i=St(n).toLowerCase();var a=false;if(t instanceof Ne){t=t.toArray()}if(t instanceof Array){t=t.map(function(e){return e.valueOf().toLowerCase()});if(t.includes(i)){a=true}}else{t=t.valueOf().toLowerCase()}if(!a&&i!==t){throw new Error(wt(e,i,t,r))}}function xt(e){var n=zt(e);return["string","function"].includes(n)||e instanceof je||e instanceof $n||e instanceof RegExp}function St(e){var n={pair:Ne,symbol:je,character:Ln,values:ft,macro:Ge,string:qn,array:Array,"native-symbol":Symbol};if(Number.isNaN(e)){return"NaN "}if(e===Ie){return"nil"}if(e===null){return"null"}if(e instanceof Qe){return"syntax"}for(var t=0,r=Object.entries(n);t1&&arguments[1]!==F?arguments[1]:{},i=e.env,a=e.dynamic_scope,t=e.error,o=t===void 0?function(){}:t;try{if(a===true){i=a=i||pt}else if(i===true){i=a=pt}else{i=i||pt}var r={env:i,dynamic_scope:a,error:o};var u;if(en(n)){return n}if(n instanceof je){return i.get(n)}var c=n.car;var s=n.cdr;if(c instanceof Ne){u=Ot(Ft(c,r));if(nn(u)){return u.then(function(e){return Ft(new Ne(e,n.cdr),r)})}else if(typeof u!=="function"){throw new Error(St(u)+" "+i.get("repr")(u)+" is not a function while evaluating "+n.toString())}}if(c instanceof je){u=i.get(c);if(u instanceof Qe){return jt(u,n,r)}else if(u instanceof Ge){return Et(u,s,r)}else if(typeof u!=="function"){if(u){var f="".concat(St(u)," `").concat(u,"' is not a function");throw new Error(f)}throw new Error("Unknown function `".concat(c.name,"'"))}}else if(typeof c==="function"){u=c}if(typeof u==="function"){var l=kt(s,r);return ne(l,function(e){if(cn(u)&&(!sn(u)||fn(u))){e=e.map(rn)}if(u.__lambda__&&!u.__prototype__||fn(u)){u=on(u)}var n=e.slice();var t=(a||i).newFrame(u,n);var r=Ot(u.apply(t,e));return ne(r,function(e){if(e instanceof Ne){e.markCycles();return lt(e)}if(Number.isNaN(e)){return e}if(typeof e==="number"){return $n(e)}if(typeof e==="string"){return qn(e)}return e},o)})}else if(n instanceof je){u=i.get(n);if(u==="undefined"){throw new Error("Unbound variable `"+n.name+"'")}return u}else if(n instanceof Ne){u=c&&c.toString();throw new Error("".concat(St(c)," ").concat(u," is not a function"))}else{return n}}catch(e){o&&o.call(i,e,n)}}function At(e,n,t){return It.apply(this,arguments)}function It(){It=Dt($t.mark(function e(t,r,i){var a,o,u,c;return $t.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(i===true){r=i=r||ht}else if(r===true){r=i=ht}else{r=r||ht}a=ee(t);o=[];case 3:if(a.length){n.next=8;break}return n.abrupt("return",o);case 8:u=a.shift();n.next=11;return Ft(u,{env:r,dynamic_scope:i,error:function e(n,t){if(t){if(!(n.code instanceof Array)){n.code=[]}n.code.push(t.toString(true))}throw n}});case 11:c=n.sent;o.push(c);case 13:n.next=3;break;case 15:case"end":return n.stop()}}},e)}));return It.apply(this,arguments)}function Nt(e){var n={"[":"]","(":")"};var t;if(typeof e==="string"){t=W(e)}else{t=e.map(function(e){return e&&e.token?e.token:e})}var r=Object.keys(n);var i=Object.values(n).concat(r);t=t.filter(function(e){return i.includes(e)});var a=new G;var o=Vt(t),u;try{for(o.s();!(u=o.n()).done;){var c=u.value;if(r.includes(c)){a.push(c)}else if(!a.is_empty()){var s=a.top();var f=n[s];if(c===f){a.pop()}else{throw new Error("Syntax error: missing closing ".concat(f))}}else{throw new Error("Syntax error: not matched closing ".concat(c))}}}catch(e){o.e(e)}finally{o.f()}return a.is_empty()}function Lt(e){var n="("+e.toString()+")()";var t=window.URL||window.webkitURL;var r;try{r=new Blob([n],{type:"application/javascript"})}catch(e){var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;r=new i;r.append(n);r=r.getBlob()}return new f.Worker(t.createObjectURL(r))}function qt(e){this.url=e;var o=this.worker=Lt(function(){var u;var c;self.addEventListener("message",function(e){var r=e.data;var n=r.id;if(r.type!=="RPC"||n===null){return}function i(e){self.postMessage({id:n,type:"RPC",result:e})}function a(e){self.postMessage({id:n,type:"RPC",error:e})}if(r.method==="eval"){if(!c){a("Worker RPC: LIPS not initilized, call init first");return}c.then(function(){var e=Gt(r.params,2),n=e[0],t=e[1];u.exec(n,t).then(function(e){e=e.map(function(e){return e&&e.valueOf()});i(e)})["catch"](function(e){a(e)})})}else if(r.method==="init"){var t=Gt(r.params,1),o=t[0];if(typeof o!=="string"){a("Worker RPC: url is not a string")}else{importScripts("".concat(o,"/dist/lips.min.js"));u=new Mt.Interpreter("worker");c=u.exec('(let-env lips.env.parent\n (load "'.concat(o,'/lib/bootstrap.scm")\n (load "').concat(o,'/lib/R5RS.scm")\n (load "').concat(o,'/lib/R7RS.scm"))'));c.then(function(){i(true)})}}})});this.rpc=function(){var r=0;return function e(n,t){var a=++r;return new Promise(function(r,i){o.addEventListener("message",function e(n){var t=n.data;if(t&&t.type==="RPC"&&t.id===a){if(t.error){i(t.error)}else{r(t.result)}o.removeEventListener("message",e)}});o.postMessage({type:"RPC",method:n,id:a,params:t})})}}();this.rpc("init",[e])["catch"](function(e){console.error(e)});this.exec=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;return this.rpc("eval",[e,n])}}Ne.unDry=function(e){return new Ne(e.car,e.cdr)};Ne.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};Ae.prototype.toDry=function(){return{value:null}};Ae.unDry=function(){return Ie};je.prototype.toDry=function(){return{value:{name:this.name}}};je.unDry=function(e){return new je(e.name)};function Pt(e){console.error(e.message||e);if(e.code){console.error(e.code.map(function(e,n){return"[".concat(n+1,"]: ").concat(e)}))}}function Rt(){var o=["text/x-lips","text/x-scheme"];if(!window.document){return Promise.resolve()}else{return new Promise(function(i){var a=Array.from(document.querySelectorAll("script"));return function n(){var e=a.shift();if(!e){i()}else{var t=e.getAttribute("type");if(o.includes(t)){var r=e.getAttribute("src");if(r){return f.fetch(r).then(function(e){return e.text()}).then(At).then(n)["catch"](function(e){Pt(e);n()})}else{return At(e.innerHTML).then(n)["catch"](function(e){Pt(e);n()})}}else if(t&&t.match(/lips|lisp/)){console.warn("Expecting "+o.join(" or ")+" found "+t)}return n()}}()})}}if(typeof window!=="undefined"){e(window,Rt)}var Ct=function(){var e=qn("Tue, 08 Sep 2020 09:44:35 +0000").valueOf();var n=e==="{{"+"DATE}}"?new Date:new Date(e);var t=function e(n){return n.toString().padStart(2,"0")};var r=n.getFullYear();var i=[r,t(n.getMonth()+1),t(n.getDate())].join("-");var a="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter 1.0.0-beta.5 (".concat(i,") \nCopyright (c) 2018-").concat(r," Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables.\nYou can also use (help name) to display help for specic function or macro.\n").replace(/^.*\n/,"");return a}();se.__className="ahead";fe.__className="pattern";ce.__className="formatter";Ge.__className="macro";Qe.__className="syntax";ct.__className="environment";nt.__className="input-port";tt.__className="output-port";rt.__className="output-string-port";it.__className="input-string-port";$n.__className="number";Ln.__className="character";qn.__className="string";var Mt={version:"1.0.0-beta.5",banner:Ct,date:"Tue, 08 Sep 2020 09:44:35 +0000",exec:At,parse:ee,tokenize:W,evaluate:Ft,Environment:ct,env:ht,Worker:qt,Interpreter:ut,balanced_parenthesis:Nt,balancedParenthesis:Nt,balanced:Nt,Macro:Ge,Syntax:Qe,Pair:Ne,quote:lt,InputPort:nt,OutputPort:tt,InputStringPort:it,OutputStringPort:rt,Formatter:ce,specials:K,repr:qe,nil:Ie,LSymbol:je,LNumber:$n,LFloat:Un,LComplex:Dn,LRational:zn,LBigInteger:Vn,LCharacter:Ln,LString:qn,rationalize:Yn};pt.set("lips",Mt);return Mt})})(); \ No newline at end of file diff --git a/package.json b/package.json index 7f91e8026..828fc3a29 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jcubic/lips", - "version": "1.0.0-beta.4", + "version": "1.0.0-beta.5", "description": "Simple Scheme Like Lisp in JavaScript", "main": "src/lips.js", "unpkg": "dist/lips.min.js",