From f53ffd10debd5b32cc0bc0f62e945f3b5654fd4b Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Thu, 17 Sep 2020 12:00:12 +0200 Subject: [PATCH] fix syntax-rules #43 throw exception when invoking syntax that shadow literal identifier --- CHANGELOG.md | 1 + README.md | 2 +- bin/lips.js | 6 +++--- dist/lips.js | 24 ++++++++++++++++-------- dist/lips.min.js | 4 ++-- src/lips.js | 15 ++++++++++----- tests/syntax.scm | 19 ++++++++++++++----- 7 files changed, 47 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06494cbd7..b83610fe5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * fix parsing options in executable (fix for `alias lips="lips -q"`) * throw exception when evaluating `(if)` * fix `object?` and `plain-object?` +* throw exception when invoking syntax that shadow literal identifier ## 1.0.0-beta.5 ### Features diff --git a/README.md b/README.md index 28a136ae9..978d5a8ca 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ![LIPS - Scheme Based Powerful Lisp Language](https://github.com/jcubic/lips/blob/devel/assets/lips.svg?raw=true) [![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=devel&24be1a977f7c22fe2a04d439ab1e1e8a55964395)](https://travis-ci.org/jcubic/lips) +[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&82b9191f07e6b8bf3e6ad82841358385a11ed924)](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) [![Join Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips) diff --git a/bin/lips.js b/bin/lips.js index 72c0f2da4..fd084968b 100755 --- a/bin/lips.js +++ b/bin/lips.js @@ -93,11 +93,11 @@ function parse_options(arg, options) { } // ----------------------------------------------------------------------------- -function run(code, interpreter, dynamic = false) { +function run(code, interpreter, dynamic = false, env = null) { if (typeof code !== 'string') { code = code.toString(); } - return interpreter.exec(code, dynamic).catch(function(e) { + return interpreter.exec(code, dynamic, env).catch(function(e) { console.error(e.message); console.error('Call (stack-trace) to see the stack'); console.error('Thrown exception is in global exception variable, use ' + @@ -145,7 +145,7 @@ function boostrap(interpreter) { } } var data = fs.readFileSync(path); - return run(data, interpreter).then(next); + return run(data, interpreter, false, env.parent).then(next); } })(); } diff --git a/dist/lips.js b/dist/lips.js index f7a88d7cc..1f9d54666 100644 --- a/dist/lips.js +++ b/dist/lips.js @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Thu, 17 Sep 2020 09:21:02 +0000 + * build: Thu, 17 Sep 2020 09:54:40 +0000 */ (function () { 'use strict'; @@ -3841,7 +3841,7 @@ // :: TODO detect cycles // ---------------------------------------------------------------------- - function extract_patterns(pattern, code, symbols, ellipsis_symbol) { + function extract_patterns(pattern, code, symbols, ellipsis_symbol, scope) { var bindings = { '...': { symbols: {}, @@ -3878,7 +3878,9 @@ } if (pattern instanceof LSymbol && symbols.includes(pattern.valueOf())) { - return LSymbol.is(code, pattern); + var ref = scope.ref(code); + var valid_ref = typeof ref === 'undefined' || ref === global_env; + return LSymbol.is(code, pattern) && valid_ref; } // pattern (a b (x ...)) and (x ...) match nil @@ -6883,12 +6885,18 @@ Interpreter.prototype.exec = function (code) { var dynamic = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : false; + var env = arguments.length > 2 && arguments[2] !== undefined$1 ? arguments[2] : null; typecheck('Intepreter::exec', code, 'string', 1); typecheck('Intepreter::exec', dynamic, 'boolean', 2); // simple solution to overwrite this variable in each interpreter // before evaluation of user code global_env.set('**interaction-environment**', this.env); - return exec(code, this.env, dynamic ? this.env : false); + + if (env === null) { + env = this.env; + } + + return exec(code, env, dynamic ? env : false); }; // ------------------------------------------------------------------------- @@ -8316,7 +8324,7 @@ while (rules !== nil) { var rule = rules.car.car; var expr = rules.car.cdr.car; - var bindings = extract_patterns(rule, code, symbols, ellipsis); + var bindings = extract_patterns(rule, code, symbols, ellipsis, this); if (bindings) { /* istanbul ignore next */ @@ -10414,10 +10422,10 @@ var banner = function () { // Rollup tree-shaking is removing the variable if it's normal string because - // obviously 'Thu, 17 Sep 2020 09:21:02 +0000' == '{{' + 'DATE}}'; can be removed + // obviously 'Thu, 17 Sep 2020 09:54:40 +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('Thu, 17 Sep 2020 09:21:02 +0000').valueOf(); + var date = LString('Thu, 17 Sep 2020 09:54:40 +0000').valueOf(); var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date); @@ -10454,7 +10462,7 @@ var lips = { version: 'DEV', banner: banner, - date: 'Thu, 17 Sep 2020 09:21:02 +0000', + date: 'Thu, 17 Sep 2020 09:54:40 +0000', exec: exec, parse: parse, tokenize: tokenize, diff --git a/dist/lips.min.js b/dist/lips.min.js index e473608fc..6610193c0 100644 --- a/dist/lips.min.js +++ b/dist/lips.min.js @@ -31,6 +31,6 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Thu, 17 Sep 2020 09:21:02 +0000 + * build: Thu, 17 Sep 2020 09:54:40 +0000 */ -(function(){"use strict";function e(e){throw new Error('"'+e+'" is read-only')}var $t=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 Dt=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(I([])));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 A()}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 I(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:I(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 Ut=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 Jt=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 Vt=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 I=F;function A(e,n){return s(e)||I(e,n)||d(e,n)||y()}var zt=A;var Wt=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 Qt(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=Wn({num:Un([r[0],t.radix||n]),denom:Un([r[1],t.radix||n])});if(t.inexact){return i.valueOf()}else{return i}}function A(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:10;var t=E(e);if(t.inexact){return Hn(parseInt(t.number,t.radix||n))}return Un([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 Pn(t)}}function L(e){var i=arguments.length>1&&arguments[1]!==F?arguments[1]:10;function n(e){var n;if(e==="+"){n=Un(1)}else if(e==="-"){n=Un(-1)}else if(e.match(x)){n=Un([e,i])}else if(e.match(S)){var t=e.split("/");n=Wn({num:Un([t[0],i]),denom:Un([t[1],i])})}else if(e.match(c)){var r=Hn(parseFloat(e));if(a.exact){return r.toRational()}return r}else{throw new Error("Internal Parser Error")}if(a.inexact){return Hn(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 Hn){o=Hn(0)}else{o=Un(0)}return Jn({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 Un(a).mul(u)}}}t=Hn(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 Rn(JSON.parse(e))}catch(e){throw new Error("Invalid string literal")}}function T(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 Fe(e)}function M(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 I(e)}else if(e.match(b)){return L(e)}else if(e.match(_)){return A(e)}else if(e.match(c)){return R(e)}else if(e==="nil"){return Le}else if(["true","#t"].includes(e)){return true}else if(["false","#f"].includes(e)){return false}else{return T(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=Vt(e,["token"]);if(n.match(/^"[\s\S]+"$/)&&n.match(/\n/)){var r=new RegExp("^ {1,"+(e.col+1)+"}","mg");n=n.replace(r,"")}return Kt({token:n},t)}function W(e,n){var t=arguments.length>2&&arguments[2]!==F?arguments[2]:z;if(e instanceof Rn){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 Fe){c[c.length-1].push(e)}else if(c[c.length-1]instanceof qe){if(c[c.length-1].cdr instanceof qe){c[c.length-1]=new qe(c[c.length-1],qe.fromArray(e))}else{c[c.length-1].cdr=qe.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]=qe.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=Le}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(Le)}else if(i instanceof Array&&i[0]===g){var a;(a=n).push.apply(a,Yt(i.slice(1)))}else{n.push(i)}}else if(n instanceof qe){if(i.length===0){n.append(Le)}else{n.append(qe.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=M(e);if(f){while(y--){c[c.length-1].push(o);o=c.pop()}d.pop();y=0;f=false}else if(o instanceof Fe&&p.includes(o.name)){o.literal=true}n=c[c.length-1];if(n instanceof qe){var u=n;while(true){if(u.cdr===Le){if(o instanceof Array){u.cdr=qe.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 qe.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(rn);if(r.length){return ne(Promise.all(r),n,t)}return n(e)}if(rn(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"){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 Kt(Kt(Kt({},t),n),{},{exceptions:{specials:[].concat(Yt(t.exceptions.specials),Yt(i)),shift:Kt(Kt({},a),{},{1:[].concat(Yt(t.exceptions.shift[1]),Yt(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=Qt(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()&&qt(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=new se(/[([]/);var me=Symbol["for"]("*");var ye=new fe([le,me,pe],"+");var ge=new fe([Symbol["for"]("symbol")],"?");var be=new fe([Symbol["for"]("symbol")],"*");var we=[le,be,pe];var _e=new fe([le,Symbol["for"]("symbol"),me,pe],"+");var xe=ke("define","lambda","syntax-rules");var Se=/^(?!.*\b(?:[()[\]]|define|let(?:\*|rec|-env|-syntax)?|lambda|syntax-rules)\b).*$/;var Oe=/^(?:#:)?(let(?:\*|rec|-env|-syntax)?)$/;function ke(){for(var e=arguments.length,n=new Array(e),t=0;t0&&arguments[0]!==F?arguments[0]:null;if(e instanceof Fe){e=e.valueOf()}if(Ie(e)){return Fe(e)}if(e!==null){return new Fe(Symbol("#:".concat(e)))}n++;return new Fe(Symbol("#:g".concat(n)))}}();function Ne(){}Ne.prototype.toString=Ne.prototype.toJSON=function(){return"()"};Ne.prototype.valueOf=function(){return F};Ne.prototype.append=function(e){return new qe(e,Le)};Ne.prototype.toArray=function(){return[]};var Le=new Ne;function qe(e,n){if(typeof this!=="undefined"&&this.constructor!==qe||typeof this==="undefined"){return new qe(e,n)}this.car=e;this.cdr=n}function Pe(a,o){return function e(n){St(a,n,["pair","nil"]);if(n===Le){return[]}var t=[];var r=n;while(true){if(r instanceof qe){if(r.haveCycles("cdr")){break}var i=r.car;if(o&&i instanceof qe){i=this.get(a).call(this,i)}t.push(i);r=r.cdr}else{break}}return t}}qe.prototype.flatten=function(){return qe.fromArray(je(this.toArray()))};qe.prototype.length=function(){var e=0;var n=this;while(true){if(!n||n===Le||!(n instanceof qe)||n.haveCycles("cdr")){break}e++;n=n.cdr}return e};qe.prototype.clone=function(){var t=new Map;function r(e){if(e instanceof qe){if(t.has(e)){return t.get(e)}var n=new qe;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)};qe.prototype.lastPair=function(){var e=this;while(true){if(e.cdr===Le){return e}e=e.cdr}};qe.prototype.toArray=function(){var e=[];if(this.car instanceof qe){e.push(this.car.toArray())}else{e.push(this.car.valueOf())}if(this.cdr instanceof qe){e=e.concat(this.cdr.toArray())}return e};qe.fromArray=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:true;if(e instanceof qe){return e}if(n===false){var t=Le;for(var r=e.length;r--;){t=new qe(e[r],t)}return t}if(e.length&&!(e instanceof Array)){e=Yt(e)}if(e.length===0){return Le}else{var i;if(e[0]instanceof Array){i=qe.fromArray(e[0])}else{i=e[0]}if(typeof i==="string"){i=Rn(i)}if(e.length===1){return new qe(i,Le)}else{return new qe(i,qe.fromArray(e.slice(1)))}}};qe.prototype.toObject=function(){var e=arguments.length>0&&arguments[0]!==F?arguments[0]:false;var n=this;var t={};while(true){if(n instanceof qe&&n.car instanceof qe){var r=n.car;var i=r.car;if(i instanceof Fe){i=i.name}if(i instanceof String){i=i.valueOf()}var a=r.cdr;if(a instanceof qe){a=a.toObject(e)}if(a instanceof Un||a instanceof Rn||a instanceof Pn){if(!e){a=a.valueOf()}}t[i]=a;n=n.cdr}else{break}}return t};qe.fromPairs=function(e){return e.reduce(function(e,n){return new qe(new qe(new Fe(n[0]),n[1]),e)},Le)};qe.fromObject=function(n){var e=Object.keys(n).map(function(e){return[e,n[e]]});return qe.fromPairs(e)};qe.prototype.reduce=function(e){var n=this;var t=Le;while(true){if(n!==Le){t=e(t,n.car);n=n.cdr}else{break}}return t};qe.prototype.reverse=function(){if(this.haveCycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var n=Le;while(e!==Le){var t=e.cdr;e.cdr=n;n=e;e=t}return n};qe.prototype.transform=function(r){function i(e){if(e instanceof qe){if(e.replace){delete e.replace;return e}var n=r(e.car);if(n instanceof qe){n=i(n)}var t=r(e.cdr);if(t instanceof qe){t=i(t)}return new qe(n,t)}return e}return i(this)};qe.prototype.map=function(e){if(typeof this.car!=="undefined"){return new qe(e(this.car),this.cdr===Le?Le:this.cdr.map(e))}else{return Le}};var Re=new Map;function Ce(t){var e=t.constructor||Object;var r=Wt(t)==="object"&&e===Object;var i;if(Re.has(e)){i=Re.get(e)}else{Re.forEach(function(e,n){n=cn(n);if(t instanceof n&&(n===Object&&r||n!==Object)){i=e}})}return i}var Te=new Map;[[Number.NEGATIVE_INFINITY,"-inf.0"],[Number.POSITIVE_INFINITY,"+inf.0"],[true,"#t"],[false,"#f"],[null,"null"],[F,"#"]].forEach(function(e){var n=zt(e,2),t=n[0],r=n[1];Te.set(t,r)});function Me(t){if(t&&Wt(t)==="object"){var r={};var e=Object.getOwnPropertySymbols(t);e.forEach(function(e){var n=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");r[n]=Be(t[e])});var n=Object.getOwnPropertyNames(t);n.forEach(function(e){var n=t[e];if(Wt(n)==="object"&&n.constructor===Object){r[e]=Me(n)}else{r[e]=Be(n)}});return r}return t}function Be(e,n,t){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(Te.has(e)){return Te.get(e)}if(e instanceof qe){if(!t){e.markCycles()}return e.toString(n)}if(Number.isNaN(e)){return"+nan.0"}var r=[RegExp,Ne,Fe,Un,Pn,pt];for(var i=0,a=r;i"}if(bn(e.toString)){return"#"}else{return e.toString()}}if(e instanceof Rn){e=e.toString()}if(e===null||typeof e==="string"&&n){return JSON.stringify(e)}if(Wt(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($e(e)){return"#"}var s=Ce(e);if(s){if(typeof s==="function"){return s(e,n)}else{throw new Error("toString: Invalid repr value")}}c=u.name}if(kt(e)==="instance"&&!bn(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 $e(e){return e&&Wt(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}qe.prototype.markCycles=function(){De(this);return this};qe.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 De(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 qe){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 qe){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 qe){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")})}qe.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=Be(this.car,e,true)}if(r!==F){t.push(r)}if(this.cdr instanceof qe){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!==Le){t=t.concat([" . ",Be(this.cdr,e,true)])}if(!n||this.ref){t.push(")")}return t.join("")};qe.prototype.set=function(e,n){this[e]=n;if(n instanceof qe){this.markCycles()}};qe.prototype.append=function(e){if(e instanceof Array){return this.append(qe.fromArray(e))}var n=this;if(n.car===F){if(e instanceof qe){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(e!==Le){while(true){if(n instanceof qe&&n.cdr!==Le){n=n.cdr}else{break}}n.cdr=e}return this};function Ue(e){return e<0?-e:e}function Je(e,n){var t=Ht(n),r=t[0],i=t.slice(1);while(i.length>0){var a=i,o=zt(a,1),u=o[0];if(!e(r,u)){return false}var c=i;var s=Ht(c);r=s[0];i=s.slice(1)}return true}function He(e,n){if(typeof e==="function"&&typeof n==="function"){return cn(e)===cn(n)}else if(e instanceof Un&&n instanceof Un){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=Un(e);n=Un(n);return e.type===n.type&&e.cmp(n)===0}else if(e instanceof Pn&&n instanceof Pn){return e["char"]===n["char"]}else if(e instanceof Fe&&n instanceof Fe){return e.name===n.name}else{return e===n}}function Ye(e,n){if(kt(e)!==kt(n)){return false}if(!Ge(e)){return false}if(e instanceof RegExp){return e.source===n.source}if(e instanceof Rn){return e.valueOf()===n.valueOf()}return He(e,n)}function Ge(e){return e instanceof Fe||Rn.isString(e)||e instanceof Pn||e instanceof Un||e===true||e===false}var Ve=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function ze(e,n,t,r){if(typeof this!=="undefined"&&this.constructor!==ze||typeof this==="undefined"){return new ze(e,n)}St("Macro",e,"string",1);St("Macro",n,"function",2);if(t){if(r){this.__doc__=t}else{this.__doc__=ie(t)}}this.name=e;this.fn=n}ze.defmacro=function(e,n,t,r){var i=new ze(e,n,t,r);i.defmacro=true;return i};ze.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};ze.prototype.toString=function(){return"#"};var We="define-macro";var Qe=-1e4;function Ke(a){return function(){var t=Jt(Ut.mark(function e(t,v){var r,d,i;return Ut.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:i=function e(){i=Jt(Ut.mark(function e(t,r,i){var a,o,u,c,s,f,l,p,h;return Ut.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(!(t instanceof qe&&t.car instanceof Fe)){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 ze&&a.defmacro)){n.next=24;break}o=a instanceof Xe?t:t.cdr;n.next=8;return a.invoke(o,v,true);case 8:u=n.sent;if(!(a instanceof Xe)){n.next=17;break}c=u,s=c.expr,f=c.scope;if(!(s instanceof qe)){n.next=16;break}if(!(r!==-1&&r<=1||r"};Xe.className="syntax";function Ze(e,n,b,w){var _={"...":{symbols:{},lists:[]}};function x(e){if(dt.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&&Be(n,true),pattern:e&&Be(e,true)});if(Ge(e)&&!(e instanceof Fe)){return Ye(e,n)}if(e instanceof Fe&&b.includes(e.valueOf())){return Fe.is(n,e)}if(e instanceof qe&&e.car instanceof qe&&e.car.cdr instanceof qe&&Fe.is(e.car.cdr.car,w)){x(">> 0");if(n===Le){x({pattern:e.toString()});if(e.car.car instanceof Fe){if(e.car.cdr instanceof qe&&Fe.is(e.car.cdr.car,w)){var i=e.car.car.valueOf();var a=e.lastPair();if(Fe.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 qe&&e.cdr instanceof qe&&Fe.is(e.cdr.car,w)){if(e.cdr.cdr!==Le){if(e.cdr.cdr instanceof qe){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=Le;if(!S(e.cdr.cdr,f,t,r)){return false}}}if(e.car instanceof Fe){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===Le){x(">> 2");if(r){x("NIL");_["..."].symbols[l]=Le}else{x("NULL");_["..."].symbols[l]=null}}else if(n instanceof qe&&(n.car instanceof qe||n.car===Le)){x(">> 3 "+r);if(r){if(_["..."].symbols[l]){var p=_["..."].symbols[l];_["..."].symbols[l]=p.append(new qe(n,Le))}else{_["..."].symbols[l]=new qe(n,Le)}}else{x(">> 4");_["..."].symbols[l]=new qe(n,Le)}}else{x(">> 6");if(n instanceof qe){x(">> 7 "+r);t.push(l);if(!_["..."].symbols[l]){_["..."].symbols[l]=new qe(n,Le)}else{var h=_["..."].symbols[l];_["..."].symbols[l]=h.append(new qe(n,Le))}x({IIIIII:_["..."].symbols[l].toString()})}else{x(">> 8");return false}}return true}else if(e.car instanceof qe){var v=Yt(t);if(n===Le){x(">> 9");_["..."].lists.push(Le);return true}x(">> 10");var d=n;while(d instanceof qe){if(!S(e.car,d.car,v,true)){return false}d=d.cdr}return true}return false}if(e instanceof Fe){if(Fe.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 qe&&n instanceof qe){x(">> 12");x({a:12,code:n&&n.toString(),pattern:e.toString()});if(n.cdr===Le){var y=e.car instanceof Fe&&e.cdr instanceof Fe;if(y){x(">> 12 | 1");var g=e.cdr.valueOf();if(!_[g]){_[g]=Le}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===Le&&(n===Le||n===F)){return true}else if(e.car instanceof qe&&Fe.is(e.car.car,w)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(S(e,n)){return _}}function en(e,i){function a(n){if(n instanceof qe){if(!i.length){return n}var e=a(n.car);var t=a(n.cdr);return new qe(e,t)}else if(n instanceof Fe){var r=i.find(function(e){return e.gensym===n});if(r){return Fe(r.name)}return n}else{return n}}return a(e)}function nn(){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 Fe||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=Wt(n);if(["string","symbol"].includes(t)&&n in w){return w[n]}if(i.includes(n)){return Fe(n)}return u(n)}function S(e){if(dt.get("DEBUG",{throwError:false})){console.log(e)}}function u(e){if(!o[e]){var n=r.get(e,{throwError:false});var t=Ae(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 Fe){var a=e.valueOf();S("[t 1");if(n[a]){if(n[a]instanceof qe){var o=n[a],u=o.car,c=o.cdr;if(i){var s=u.car,f=u.cdr;if(f!==Le){r(a,new qe(f,Le))}return s}if(c!==Le){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 qe){if(e.car instanceof Fe&&e.cdr instanceof qe&&Fe.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 qe){S("[t 2 Pair "+i);S({______:p.toString()});var h=p.car,v=p.cdr;if(i){if(v!==Le){r(l,v)}return h}else{if(h.cdr!==Le){r(l,new qe(h.cdr,v))}return h.car}}else if(p instanceof Array){S("[t 2 Array "+i);if(i){r(l,p.slice(1));return qe.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 qe(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,Yt(r.map(function(e){return n[e]})))}return e.length&&e.every(function(e){if(e===null){return!t}return e instanceof qe||e===Le||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 qe){if(!n&&i.car instanceof qe&&Fe.is(i.car.car,_)){return E(i.car.cdr,{disabled:true})}if(i.cdr instanceof qe&&Fe.is(i.cdr.car,_)&&!n){S(">> 1");var t=w["..."].symbols;var r=j(t);if(i.car instanceof qe){if(w["..."].lists[0]===Le){return Le}S(">> 2");var a;if(r.length){S(">> 2 (a)");var o=Kt({},t);a=Le;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 qe(t,a)}o=r};while(true){var c=u();if(c==="break")break}if(a!==Le){a=a.reverse()}return a}else{S(">> 3");var s=O(i.car,t,{nested:true});if(s){return new qe(s,Le)}return Le}}else if(i.car instanceof Fe){S(">> 4");var f=i.car.name;var l=Gt({},f,t[f]);var p=t[f]===null;var h=Le;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 qe(t,h)}l=r};while(true){var d=v();if(d==="break")break}if(h!==Le){h=h.reverse()}if(i.cdr instanceof qe){if(i.cdr.cdr instanceof qe||i.cdr.cdr instanceof Fe){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 qe(y,g)}if(i instanceof Fe){if(n&&Fe.is(i,_)){return i}var b=x(i);if(typeof b!=="undefined"){return b}}return i}return E(n,{})}function tn(e){return typeof e==="undefined"||e===Le||e===null}function rn(e){return e instanceof Promise||e&&typeof e!=="undefined"&&typeof e.then==="function"}function an(e){switch(Wt(e)){case"string":return Rn(e);case"number":if(!Number.isNaN(e)){return Un(e)}}return e}function on(n){var e=[Rn,Pn,Un].some(function(e){return n instanceof e});if(e){return n.valueOf()}return n}function un(e,n){if(e instanceof qe){e.markCycles();return ht(e)}if(typeof e==="function"){if(n){return sn(e,n)}}return an(e)}function cn(e){if(fn(e)){return e[vn]}return e}function sn(n,e){if(n[Symbol["for"]("__bound__")]){return n}var t=n.bind(e);var r=Object.getOwnPropertyNames(n).filter(mn);r.forEach(function(e){try{t[e]=n[e]}catch(e){}});yn(t,"__fn__",n);yn(t,"__context__",e);yn(t,"__bound__",true);if(bn(n)){yn(t,"__native__",true)}t.valueOf=function(){return n};return t}function fn(e){return!!(typeof e==="function"&&e[vn])}function ln(e){if(typeof e==="function"){var n=e[hn];if(n&&(n===Bt||n.constructor&&n.constructor.__className)){return true}}return false}function pn(e){function n(e){return e instanceof rt||e instanceof it}if(typeof e==="function"){if(n(e)){return true}if(n(e[hn])){return true}}return false}var hn=Symbol["for"]("__context__");var vn=Symbol["for"]("__fn__");var dn=["name","length","caller","callee","arguments","prototype"];function mn(e){return!dn.includes(e)}function yn(e,n,t){Object.defineProperty(e,Symbol["for"](n),{get:function e(){return t},set:function e(){},configurable:false,enumerable:false})}function gn(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 bn(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 wn(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 ze.defmacro(v,function(n,e){var a=e.dynamic_scope,o=e.error,t=e.macro_expand;var u;if(n.car instanceof Fe){if(!(n.cdr.car instanceof qe||n.cdr.car===Le)){throw new Error("let require list of pairs")}var r;if(n.cdr.car===Le){u=Le;r=Le}else{r=n.cdr.car.map(function(e){return e.car});u=n.cdr.car.map(function(e){return e.cdr.car})}return qe.fromArray([Fe("letrec"),[[n.car,qe(Fe("lambda"),qe(r,n.cdr.cdr))]],qe(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 qe(new Fe("begin"),n.cdr);return At(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(rn);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 qe){o.push(At(a.car,{env:i,dynamic_scope:t,error:r}));a=a.cdr}var u=o.filter(rn).length;if(u){return Promise.all(o).then(c.bind(this))}else{return c.call(this,o)}})}function xn(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 Nn(r,i){St("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 Un){return e}if(typeof this!=="undefined"&&!(this instanceof Un)||typeof this==="undefined"){return new Un(e,n)}if(typeof e==="undefined"){throw new Error("Invlaid LNumber constructor call")}var t=Un.getType(e);if(Un.types[t]){return Un.types[t](e,n)}var r=e instanceof Array&&Rn.isString(e[0])&&Un.isNumber(e[1]);if(e instanceof Un){return Un(e.value)}if(!Un.isNumber(e)&&!r){throw new Error("You can't create LNumber from ".concat(kt(e)))}if(e===null){e=0}var i;if(r){var a=e,o=zt(a,2),u=o[0],c=o[1];if(u instanceof Rn){u=u.valueOf()}if(c instanceof Un){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=Yt(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 Qn(i,true)}else if(typeof h!=="undefined"&&!(e instanceof h)){if(e instanceof Array){return Qn(Dt(h,Yt(e)))}return Qn(new h(e))}else if(r){this.value=parseInt(u,c)}else{this.value=e}}Un.types={float:function e(n){var t=arguments.length>1&&arguments[1]!==F?arguments[1]:false;return new Hn(n,t)},complex:function e(n){var t=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(!Un.isComplex(n)){n={im:0,re:n}}return new Jn(n,t)},rational:function e(n){var t=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(!Un.isRational(n)){n={num:n,denom:1}}return new Wn(n,t)}};function Jn(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof Jn)||typeof this==="undefined"){return new Jn(e,n)}if(e instanceof Jn){return Jn({im:e.im,re:e.re})}if(Un.isNumber(e)&&n){e={im:0,re:e.valueOf()}}else if(!Un.isComplex(e)){throw new Error("Invalid constructor call for LComplex")}var t=e.im instanceof Un?e.im:Un(e.im);var r=e.re instanceof Un?e.re:Un(e.re);if(t.cmp(0)===0&&!n){return r}this.im=t;this.re=r;this.type="complex"}Jn.prototype=Object.create(Un.prototype);Jn.prototype.constructor=Jn;Jn.prototype.toRational=function(e){if(Un.isFloat(this.im)&&Un.isFloat(this.re)){var n=Hn(this.im).toRational(e);var t=Hn(this.re).toRational(e);return Jn({im:n,re:t})}return this};Jn.prototype.add=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.add(n),im:t.add(r)}})};Jn.prototype.factor=function(){if(this.im instanceof Hn||this.im instanceof Hn){var e=this.re,n=this.im;var t,r;if(e instanceof Hn){t=e.toRational().mul(e.toRational())}else{t=e.mul(e)}if(n instanceof Hn){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))}};Jn.prototype.modulus=function(){return this.factor().sqrt()};Jn.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=Hn(.5).mul(e.add(this.re)).sqrt();t=this.im.div(n).div(2)}else{t=Hn(.5).mul(e.sub(this.re)).sqrt();if(this.im.cmp(0)===-1){t=t.sub()}n=this.im.div(t).div(2)}return Jn({im:t,re:n})};Jn.prototype.div=function(e){if(Un.isNumber(e)&&!Un.isComplex(e)){e=Jn({im:0,re:e})}else if(!Un.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var n=this.coerce(e),t=zt(n,2),r=t[0],i=t[1];var a=Jn({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 Jn({re:c,im:s})};Jn.prototype.sub=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.sub(n),im:t.sum(r)}})};Jn.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})};Jn.prototype.complex_op=function(e,n){if(Un.isNumber(e)&&!Un.isComplex(e)){if(!(e instanceof Un)){e=Un(e)}var t=e.asType(0);e={im:t,re:e}}else if(!Un.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var r=e.re instanceof Un?e.re:this.re.asType(e.re);var i=e.im instanceof Un?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=Jn(a,true);return o}return a};Jn._op={"+":"add","-":"sub","*":"mul","/":"div"};Jn.prototype._op=function(e,n){var t=Jn._op[e];return this[t](n)};Jn.prototype.cmp=function(e){var n=this.coerce(e),t=zt(n,2),r=t[0],i=t[1];var a=r.re.coerce(i.re),o=zt(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=zt(f,2),p=l[0],h=l[1];return p.cmp(h)}};Jn.prototype.valueOf=function(){};Jn.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 Hn(e){if(typeof this!=="undefined"&&!(this instanceof Hn)||typeof this==="undefined"){return new Hn(e)}if(!Un.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof Un){return Hn(e.valueOf())}if(typeof e==="number"){this.value=e;this.type="float"}}Hn.prototype=Object.create(Un.prototype);Hn.prototype.constructor=Hn;Hn.prototype.toString=function(){var e=this.value.toString();if(!Un.isFloat(this.value)&&!e.match(/e/i)){return e+".0"}return e.replace(/^([0-9]+)e/,"$1.0e")};Hn.prototype._op=function(e,n){if(n instanceof Un){n=n.value}var t=Un._ops[e];if(e==="/"&&this.value===0&&n===0){return NaN}return Hn(t(this.value,n))};Hn.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==F?arguments[0]:null;if(e===null){return Yn(this.value.valueOf())}return Gn(e.valueOf())(this.value.valueOf())};var Yn=Gn(1e-10);function Gn(r){return function(e){var n=function e(r,n,t){var i=function e(n,t){return t0){i=zn(r,t)}else if(r.cmp(t)<=0){i=t}else if(t.cmp(0)>0){i=zn(t,r)}else if(n.cmp(0)<0){i=Un(zn(r.sub(),t.sub())).sub()}else{i=Un(0)}if(Un.isFloat(n)||Un.isFloat(e)){return Hn(i)}return i}function zn(e,n){var t=Un(e).floor();var r=Un(n).floor();if(e.cmp(t)<1){return t}else if(t.cmp(r)===0){var i=Un(1).div(n.sub(r));var a=Un(1).div(e.sub(t));return t.add(Un(1).div(zn(i,a)))}else{return t.add(Un(1))}}function Wn(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof Wn)||typeof this==="undefined"){return new Wn(e,n)}if(!Un.isRational(e)){throw new Error("Invalid constructor call for LRational")}var t=Un(e.num);var r=Un(e.denom);if(!n&&r.cmp(0)!==0){var i=t.op("%",r).cmp(0)===0;if(i){return Un(t.div(r))}}this.num=t;this.denom=r;this.type="rational"}Wn.prototype=Object.create(Un.prototype);Wn.prototype.constructor=Wn;Wn.prototype.pow=function(e){var n=e.cmp(0);if(n===0){return Un(1)}if(n===-1){e=e.sub();var t=this.denom.pow(e);var r=this.num.pow(e);return Wn({num:t,denom:r})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};Wn.prototype.sqrt=function(){var e=this.num.sqrt();var n=this.denom.sqrt();if(e instanceof Hn){e=($t("num"),e.toRational())}if(n instanceof Hn){n=($t("denom"),n.toRational())}return Wn({num:e,denom:n})};Wn.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 Wn({num:e,denom:n})};Wn.prototype.cmp=function(e){return Un(this.valueOf(),true).cmp(e)};Wn.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 Wn){n=Un(n.valueOf(true))}t=this.denom.div(e);if(t instanceof Wn){t=Un(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()};Wn.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 Un._ops["/"](this.num.value,this.denom.value)}return Hn(this.num.valueOf()).div(this.denom.valueOf())};Wn.prototype.mul=function(e){if(!(e instanceof Un)){e=Un(e)}if(Un.isRational(e)){var n=this.num.mul(e.num);var t=this.denom.mul(e.denom);return Wn({num:n,denom:t})}var r=Un.coerce(this,e),i=zt(r,2),a=i[0],o=i[1];return a.mul(o)};Wn.prototype.div=function(e){if(!(e instanceof Un)){e=Un(e)}if(Un.isRational(e)){var n=this.num.mul(e.denom);var t=this.denom.mul(e.num);return Wn({num:n,denom:t})}var r=Un.coerce(this,e),i=zt(r,2),a=i[0],o=i[1];var u=a.div(o);return u};Wn.prototype._op=function(e,n){return this[et[e]](n)};Wn.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof Un)){e=Un(e)}if(Un.isRational(e)){var n=e.num.sub();var t=e.denom;return this.add(Wn({num:n,denom:t}))}if(!(e instanceof Un)){e=Un(e).sub()}else{e=e.sub()}var r=Un.coerce(this,e),i=zt(r,2),a=i[0],o=i[1];return a.add(o)};Wn.prototype.add=function(e){if(!(e instanceof Un)){e=Un(e)}if(Un.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 Wn({num:o,denom:a})}if(Un.isFloat(e)){return Hn(this.valueOf()).add(e)}var u=Un.coerce(this,e),c=zt(u,2),s=c[0],f=c[1];return s.add(f)};function Qn(e,n){if(typeof this!=="undefined"&&!(this instanceof Qn)||typeof this==="undefined"){return new Qn(e,n)}if(e instanceof Qn){return Qn(e.value,e._native)}if(!Un.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.value=e;this._native=n;this.type="bigint"}Qn.prototype=Object.create(Un.prototype);Qn.prototype.constructor=Qn;Qn.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};Qn.prototype._op=function(e,n){if(typeof n==="undefined"){if(Un.isBN(this.value)){e=Qn.bn_op[e];return Qn(this.value.clone()[e](),false)}return Qn(Un._ops[e](this.value),true)}if(Un.isBN(this.value)&&Un.isBN(n.value)){e=Qn.bn_op[e];return Qn(this.value.clone()[e](n),false)}var t=Un._ops[e](this.value,n.value);if(e==="/"){var r=this.op("%",n).cmp(0)===0;if(r){return Un(t)}return Wn({num:this,denom:n})}return Qn(t,true)};Qn.prototype.sqrt=function(){var e;var n=this.cmp(0)<0;if(Un.isNative(this.value)){e=Un(Math.sqrt(n?-this.valueOf():this.valueOf()))}else if(Un.isBN(this.value)){e=n?this.value.neg().sqrt():this.value.sqrt()}if(n){return Jn({re:0,im:e})}return e};Un.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}}};Un.isFloat=function e(n){return n instanceof Hn||Number(n)===n&&n%1!==0};Un.isNumber=function(e){return e instanceof Un||!Number.isNaN(e)&&Un.isNative(e)||Un.isBN(e)};Un.isComplex=function(e){var n=e instanceof Jn||Un.isNumber(e.im)&&Un.isNumber(e.re);return n};Un.isRational=function(e){return e instanceof Wn||Un.isNumber(e.num)&&Un.isNumber(e.denom)};Un.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};Un.isBigInteger=function(e){return e instanceof Qn||typeof e==="bigint"||Un.isBN(e)};Un.isBN=function(e){return typeof h!=="undefined"&&e instanceof h};Un.getArgsType=function(e,n){if(e instanceof Hn||n instanceof Hn){return Hn}if(e instanceof Qn||n instanceof Qn){return Qn}return Un};Un.prototype.toString=Un.prototype.toJSON=function(e){if(e>2&&e<36){return this.value.toString(e)}return this.value.toString()};Un.prototype.asType=function(e){var n=Un.getType(this);return Un.types[n]?Un.types[n](e):Un(e)};Un.prototype.isBigNumber=function(){return typeof this.value==="bigint"||typeof h!=="undefined"&&!(this.value instanceof h)};["floor","ceil","round"].forEach(function(e){Un.prototype[e]=function(){if(this["float"]||Un.isFloat(this.value)){return Un(Math[e](this.value))}else{return Un(Math[e](this.valueOf()))}}});Un.prototype.valueOf=function(){if(Un.isNative(this.value)){return Number(this.value)}else if(Un.isBN(this.value)){return this.value.toNumber()}};var Kn=function(){var e=function e(n,t){return[n,t]};return{bigint:{bigint:e,float:function e(n,t){return[Hn(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&&Hn(t.valueOf())]},float:e,rational:function e(n,t){return[n,t&&Hn(t.valueOf())]},complex:function e(n,t){return[{re:n,im:Hn(0)},t]}},complex:{bigint:n("bigint"),float:n("float"),rational:n("rational"),complex:function e(n,t){var r=Un.coerce(n.re,t.re),i=zt(r,2),a=i[0],o=i[1];var u=Un.coerce(n.im,t.im),c=zt(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[Hn(n.valueOf()),t]},rational:e,complex:function e(n,t){return[{im:Xn(n.type,t.im.type,0),re:Xn(n.type,t.re.type,n)},{im:Xn(n.type,t.im.type,t.im),re:Xn(n.type,t.re.type,t.re)}]}}};function n(t){return function(e,n){return[{im:Xn(t,e.im.type,e.im),re:Xn(t,e.re.type,e.re)},{im:Xn(t,e.im.type,0),re:Xn(t,n.type,n)}]}}}();function Xn(e,n,t){return Kn[e][n](t)[0]}Un.coerce=function(e,n){function t(e){if(e==="integer"){return"bigint"}return e}var r=t(Un.getType(e));var i=t(Un.getType(n));if(!Kn[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!Kn[r][i]){throw new Error("LNumber::coerce unknown rhs type ".concat(i))}return Kn[r][i](e,n).map(function(e){return Un(e,true)})};Un.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof Un)){throw new Error("LNumber: you can't coerce ".concat(kt(e)))}if(typeof e==="number"){e=Un(e)}return Un.coerce(this,e)};Un.getType=function(e){if(e instanceof Un){return e.type}if(Un.isFloat(e)){return"float"}if(Un.isComplex(e)){return"complex"}if(Un.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"}};Un.prototype.isFloat=function(){return!!(Un.isFloat(this.value)||this["float"])};var Zn={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var et={};Object.keys(Zn).forEach(function(n){et[Zn[n]]=n;Un.prototype[n]=function(e){return this.op(Zn[n],e)}});Un._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 ut}return Pn(this._string[this._in_char])};function it(e){if(typeof this!=="undefined"&&!(this instanceof it)||typeof this==="undefined"){return new it(e)}St("OutputPort",e,"function");this.write=e}it.prototype.toString=function(){return"<#output-port>"};function at(n){var t=this;if(typeof this!=="undefined"&&!(this instanceof at)||typeof this==="undefined"){return new at(n)}St("OutputStringPort",n,"function");this._buffer=[];this.write=function(e){if(!Rn.isString(e)){e=n(e)}else{e=e.valueOf()}t._buffer.push(e)}}at.prototype=Object.create(it.prototype);at.prototype.getString=function(){return this._buffer.map(function(e){return e.valueOf()}).join("")};at.prototype.constructor=at;function ot(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof ot)||typeof this==="undefined"){return new ot(e)}St("InputStringPort",e,"string");this._string=e.valueOf();this._index=0;this._in_char=0;this.read=function(){return n.get_next_tokens()}}ot.prototype=Object.create(rt.prototype);ot.prototype.constructor=ot;ot.prototype.read_line=function(){var e=this._string.substring(this._in_char);if(!e){return ut}var n=e.match(/([^\n])(?:\n|$)/)[0];this._in_char+=n.length;return n};var ut=new ct;function ct(){}ct.prototype.toString=function(){return"<#eof>"};function st(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:{};if(typeof this!=="undefined"&&!(this instanceof st)||typeof this==="undefined"){return new st(e,n)}if(typeof e==="undefined"){e="anonymous"}this.env=dt.inherit(e,n)}st.prototype.exec=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;St("Intepreter::exec",e,"string",1);St("Intepreter::exec",n,"boolean",2);vt.set("**interaction-environment**",this.env);return Nt(e,this.env,n?this.env:false)};st.prototype.get=function(e){return this.env.get(e).bind(this.env)};st.prototype.set=function(e,n){return this.env.set(e,n)};function ft(e,n,t){if(arguments.length===1){if(Wt(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"}ft.prototype.inherit=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:{};if(Wt(e)==="object"){n=e}if(!e||Wt(e)==="object"){e="child of "+(this.name||"unknown")}return new ft(n||{},this,e)};ft.prototype.doc=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:null;if(e instanceof Fe){e=e.name}if(e instanceof Rn){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)}};ft.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 ft)){return Le}if(e<=0){return n}var t=n.get("parent.frame");return t(e-1)},vt.env["parent.frame"].__doc__));n.callee=e;r.set("arguments",n);return r};ft.prototype._lookup=function(e){if(e instanceof Fe){e=e.name}if(e instanceof Rn){e=e.valueOf()}if(this.env.hasOwnProperty(e)){return lt(this.env[e])}if(this.parent){return this.parent._lookup(e)}};ft.prototype.toString=function(){return"<#env:"+this.name+">"};ft.prototype.clone=function(){var n=this;var t={};Object.keys(this.env).forEach(function(e){t[e]=n.env[e]});return new ft(t,this.parent,this.name)};ft.prototype.merge=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:"merge";St("Environment::merge",e,"environment");return this.inherit(n,e.env)};function lt(e){if(typeof this!=="undefined"&&!(this instanceof lt)||typeof this==="undefined"){return new lt(e)}this.value=e}lt.isUndefined=function(e){return e instanceof lt&&typeof e.value==="undefined"};lt.prototype.valueOf=function(){return this.value};function pt(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof pt)||typeof this==="undefined"){return new pt(e)}this.values=e}pt.prototype.toString=function(){return this.values.map(function(e){return Be(e)}).join("\n")};pt.prototype.valueOf=function(){return this.values};ft.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 Fe||i instanceof Rn){i=i.valueOf()}var a=this._lookup(i);if(a instanceof lt){if(lt.isUndefined(a)){return F}return un(a.valueOf())}if(typeof i==="string"){var o=i.split(".").filter(Boolean);if(o.length>0){var u=Ht(o),c=u[0],s=u.slice(1);a=this._lookup(c);if(s.length){try{if(a instanceof lt){a=a.valueOf()}else{a=qn(f,c);if(typeof a==="function"){a=cn(a)}}return qn.apply(void 0,[a].concat(Yt(s)))}catch(e){}}else if(a instanceof lt){return un(a.valueOf())}}a=qn(f,i)}if(typeof a!=="undefined"){return a}if(r){throw new Error("Unbound variable `"+i.toString()+"'")}};ft.prototype.set=function(e,n){var t=arguments.length>2&&arguments[2]!==F?arguments[2]:null;if(Un.isNumber(n)){n=Un(n)}if(e instanceof Fe){e=e.name}if(e instanceof Rn){e=e.valueOf()}this.env[e]=n;if(t){this.doc(e,t)}return this};ft.prototype.has=function(e){return this.env.hasOwnProperty(e)};ft.prototype.ref=function(e){var n=this;while(true){if(!n){break}if(n.has(e)){return n}n=n.parent}};ft.prototype.parents=function(){var e=this;var n=[];while(e){n.unshift(e);e=e.parent}return n};function ht(e){if(rn(e)){return e.then(ht)}if(e instanceof qe||e instanceof Fe){e.data=true}return e}var vt=new ft({nil:Le,undefined:F,true:true,false:false,null:null,NaN:NaN,stdout:new it(function(){var e;(e=console).log.apply(e,arguments)}),stdin:rt(function(){return new Promise(function(e){e(prompt(""))})}),"open-input-string":re(function(e){St("open-input-string",e,"string");return ot(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 it},"(output-port? arg)\n\n Function return true if argument is output port."),"input-port?":re(function(e){return e instanceof rt},"(input-port? arg)\n\n Function return true if argument is input port."),"open-output-string":re(function(){return at(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){St("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===ut},"(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){St("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")}St("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")}St("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(Rn.isString(n)){return ee(W(n.valueOf()))[0]}var t;if(n instanceof rt){t=n}else{t=this.get("stdin")}return ne(t.read(),function(e){if(e===ut){return ut}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 qe){e=new Bt.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=At(e.cdr.car,{env:this,dynamic_scope:t,error:r});i=jt(i);function u(n,t){if(rn(n)){return n.then(function(e){return u(e,t)})}if(rn(t)){return t.then(function(e){return u(n,e)})}f[n]=t;return t}if(e.car instanceof qe&&Fe.is(e.car.car,".")){var c=e.car.cdr.car;var s=e.car.cdr.cdr.car;var f=At(c,{env:this,dynamic_scope:t,error:r});var l=At(s,{env:this,dynamic_scope:t,error:r});return u(l,i)}if(!(e.car instanceof Fe)){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 ze("set!",function(e){if(!(e.car instanceof Fe)){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){St("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){St("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===Le},"(empty? object)\n\n Function return true if value is undfined empty list."),assoc:re(function(e,n){if(e instanceof qe&&!(n instanceof qe)){throw new Error("First argument to assoc ned to be a key")}St("assoc",n,"pair");var t=n;while(true){if(!(t instanceof qe)||this.get("empty?")(t)){break}var r=t.car.car;if(He(r,e)){return t.car}else if(!t.haveCycles("cdr")){t=t.cdr}}return Le},"(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(Ae,"(gensym)\n\n Function generate unique symbol, to use with macros as meta name."),load:re(function(n){St("load",n,"string");var e=this;if(e.name==="__frame__"){e=e.parent}var i;if(e===vt){i=e}else{i=this.get("**interaction-environment**")}var a="**module-path**";var o=vt.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)}vt.set(a,e.dirname(n));require("fs").readFile(n,function(e,n){if(e){console.log(e);r(e);vt.set(a,o)}else{Nt(n.toString(),i).then(function(){t();vt.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){vt.set(a,n.replace(/\/[^/]*$/,""));return Nt(e,i)}).then(function(){})["finally"](function(){vt.set(a,o)})},"(load filename)\n\n Function fetch the file and evaluate its content as LIPS code."),do:re(new ze("do",function(){var t=Jt(Ut.mark(function e(t,r){var i,a,o,u,c,s,f,l,p,h,v,d,m,y;return Ut.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:i=r.dynamic_scope,a=r.error;o=this;if(i){i=o}u=o.inherit("do");c=t.car;s=t.cdr.car;f=t.cdr.cdr;if(f!==Le){f=new qe(Fe("begin"),f)}l={env:u,dynamic_scope:i,error:a};p=c;case 10:if(!(p!==Le)){n.next=21;break}h=p.car;n.t0=u;n.t1=h.car;n.next=16;return At(h.cdr.car,l);case 16:n.t2=n.sent;n.t0.set.call(n.t0,n.t1,n.t2);p=p.cdr;n.next=10;break;case 21:n.next=23;return At(s.car,l);case 23:if(n.sent){n.next=42;break}if(!(f!==Le)){n.next=27;break}n.next=27;return Bt.evaluate(f,l);case 27:v=c;d={};case 29:if(!(v!==Le)){n.next=39;break}m=v.car;if(!(m.cdr.cdr!==Le)){n.next=36;break}n.next=34;return At(m.cdr.cdr.car,l);case 34:y=n.sent;d[m.car.valueOf()]=y;case 36:v=v.cdr;n.next=29;break;case 39:Object.entries(d).forEach(function(e){var n=zt(e,2),t=n[0],r=n[1];u.set(t,r)});n.next=21;break;case 42:if(!(s.cdr!==Le)){n.next=46;break}n.next=45;return At(s.cdr.car,l);case 45:return n.abrupt("return",n.sent);case 46:case"end":return n.stop()}}},e,this)}));return function(e,n){return t.apply(this,arguments)}}()),"(do (( )) (test expression) . body)\n\n Iteration macro that evaluate the expression body in scope of the variables.\n On Eeach loop it increase the variables according to next expression and run\n test to check if the loop should continue. If test is signle call the macro\n will not return anything. If the test is pair of expression and value the\n macro will return that value after finish."),if:re(new ze("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 At(t.cdr.car,{env:a,dynamic_scope:r,error:i})}else{return At(t.cdr.cdr.car,{env:a,dynamic_scope:r,error:i})}};if(t===Le){throw new Error("too few expressions for `if`")}var o=At(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 ze("let-env",function(n){var e=arguments.length>1&&arguments[1]!==F?arguments[1]:{};var t=e.dynamic_scope,r=e.error;St("let-env",n,"pair");var i=At(n.car,{env:this,dynamic_scope:t,error:r});return ne(i,function(e){if(!(e instanceof ft)){throw new Error("let-env: First argument need to be "+"environment")}return At(qe(Fe("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(wn(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(wn(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(wn(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(_n("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 ze("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=At(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 ze("ignore",function(e,n){var t=n.dynamic_scope,r=n.error;var i={env:this,error:r};if(t){i.dynamic_scope=this}At(new qe(new Fe("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(ze.defmacro("define",function(t,e){var r=this;if(t.car instanceof qe&&t.car.car instanceof Fe){var n=new qe(new Fe("define"),new qe(t.car.car,new qe(new qe(new Fe("lambda"),new qe(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 qe){i=At(i,e)}else if(i instanceof Fe){i=r.get(i)}St("define",t.car,"symbol");return ne(i,function(e){if(r.name===Xe.merge_env){r=r.parent}var n;if(t.cdr.cdr instanceof qe&&Rn.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=Wt(e);if(tn(e)||r!=="object"&&r!=="function"){var i=xt("set-obj!",kt(e),["object","function"]);throw new Error(i)}e=cn(e);n=n.valueOf();if(arguments.length===2){delete e[n]}else if($e(e)&&typeof t==="function"){e[n]=cn(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 vt.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 qe&&Rn.isString(l.cdr.car)&&l.cdr.cdr!==Le){d=l.cdr.car.valueOf()}function m(){var e;if(p){if(!(this instanceof ft)){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 qe){var r=e.car;var i=e.cdr;if(t(r)){r=n(r)}if(t(i)){i=n(i)}if(rn(r)||rn(i)){return Promise.all([r,i]).then(function(e){var n=zt(e,2),t=n[0],r=n[1];return new qe(t,r)})}else{return new qe(r,i)}}return e}function i(e,n){if(e instanceof qe){if(n!==Le){e.append(n)}}else{e=new qe(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 qe){if(e.cdr.cdr!==Le){if(e.cdr.car instanceof qe){var i=Le;return function n(t){if(t===Le){return i}return ne(At(t.car,{env:u,dynamic_scope:a,error:o}),function(e){i=new qe(e,i);return n(t.cdr)})}(e.cdr)}else{return e.cdr}}else{return At(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 qe){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 ht(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){St("clone",e,"pair");return e.clone()},"(clone list)\n\n Function return clone of the list."),append:re(function(e,n){St("append",e,["nil","pair"]);if(e instanceof qe){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){St("append!",e,["pair","nil"]);if(!this.get("list?")(e)){throw new Error("append!: Invalid argument, value is not a list")}if(tn(n)){return e}if(e===Le){if(n===Le){return Le}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){St("reverse",e,["array","pair","nil"]);if(e===Le){return Le}if(e instanceof qe){var n=this.get("list->array")(e).reverse();return this.get("array->list")(n)}else if(!(e instanceof Array)){throw new Error(xt("reverse",kt(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){St("nth",e,"number");St("nth",n,["array","pair"]);if(n instanceof qe){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){St("split",e,["regex","string"]);St("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){St("replace",e,["regex","string"]);St("replace",n,["string","function"]);St("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){St("match",e,["regex","string"]);St("match",n,"string");var t=n.match(e);return t?this.get("array->list")(t):Le},"(match pattern string)\n\n function return match object from JavaScript as list."),search:re(function(e,n){St("search",e,["regex","string"]);St("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 Be(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=qe.fromArray(n)}else{t=Le}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;St("set-special!",e,"string",1);St("set-special!",n,"symbol",2);Bt.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:qn,".":qn,unbind:re(cn,"(unbind fn)\n\n Function remove bidning from function so you can get props from it."),type:re(kt,"(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 Fe||e instanceof Rn){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 cn(e)},"(instanceof type obj)\n\n Function check of object is instance of object."),"prototype?":re($e,"(prototype? obj)\n\n Function check if value is JavaScript Object prototype."),"macro?":re(function(e){return e instanceof ze},"(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(kt(e)!=="number"){return false}if(e instanceof Un){return e.isFloat()}return Un.isFloat(e)},"(real? number)\n\n Function check if value is real number."),"number?":re(Un.isNumber,"(number? expression)\n\n Function check if value is a number"),"string?":re(function(e){return Rn.isString(e)},"(string? expression)\n\n Function check if value is a string."),"pair?":re(function(e){return e instanceof qe},"(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 tn(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 Fe},"(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!==Le&&e!==null&&!(e instanceof Pn)&&!(e instanceof RegExp)&&!(e instanceof Rn)&&!(e instanceof qe)&&!(e instanceof Un)&&Wt(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Function check if value is an plain object."),flatten:re(function(e){St("flatten",e,"pair");return e.flatten()},"(flatten list)\n\n Return shallow list from tree structure (pairs)."),"array->list":re(function(e){St("array->list",e,"array");return qe.fromArray(e)},"(array->list array)\n\n Function convert JavaScript array to LIPS list."),"tree->array":re(Pe("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":re(Pe("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 Un(0)}if(e instanceof qe){return Un(e.length())}if("length"in e){return Un(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;St("string->number",e,"string",1);St("string->number",n,"number",2);e=e.valueOf();n=n.valueOf();if(e.match(S)||e.match(w)){return I(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 A(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 ze("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(At(new qe(new Fe("begin"),a.cdr.car.cdr.cdr),r),function(e){i(e)})}};if(u){e.dynamic_scope=o}var n=At(a.car,e);if(rn(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){St("find",t,["regex","function"]);St("find",r,["pair","nil"]);if(tn(r)){return Le}var e=te("find",t);return ne(e(r.car),function(e){if(e&&e!==Le){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;St("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!==Le){a.push(r)}return n(++t)}if(t===i.length){return qe.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){St("range",e,"number");if(e instanceof Un){e=e.valueOf()}var n=new Array(e).fill(0).map(function(e,n){return Un(n)});return qe.fromArray(n,false)},"(range n)\n\n Function return list of n numbers from 0 to n - 1"),compose:re(On,"(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(Sn,"(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(An,"(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=Ue(i*(t<0||arguments.length<=t?F:arguments[t]))/(n+r)}return Un(n)},"(lcm n1 n2 ...)\n\n Function return the least common multiple of their arguments."),"odd?":re(En(function(e){return Un(e).isOdd()}),"(odd? number)\n\n Function check if number os odd."),"even?":re(En(function(e){return Un(e).isEven()}),"(even? number)\n\n Function check if number is even."),"*":re(In(function(e,n){return Un(e).mul(n)},Un(1)),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":re(In(function(e,n){return Un(e).add(n)},Un(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(He,"(eq? a b)\n\n Function compare two values if they are identical."),or:re(new ze("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=At(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 ze("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=At(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 Un(e).or(n)},"(& a b)\n\n Function calculate or bit operation."),"&":re(function(e,n){return Un(e).and(n)},"(& a b)\n\n Function calculate and bit operation."),"~":re(function(e){return Un(e).neg()},"(~ number)\n\n Function negate the value."),">>":re(function(e,n){return Un(e).shr(n)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":re(function(e,n){return Un(e).shl(n)},"(<< a b)\n\n Function left shit the value a by value b."),not:re(function(e){if(tn(e)){return true}return!e},"(not object)\n\n Function return negation of the argument.")},F,"global");var dt=vt.inherit("user-env");vt.set("**interaction-environment**",dt);(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(n){var t=e[n]?e[n]:n;vt.set(t,re(function(e){St(t,e,"number");if(e instanceof Un){return e[n]()}},"(".concat(t," number)\n\n Function calculate ").concat(t," of a number.")))})})();function mt(e){if(e.length===1){return e[0]}else{var n=[];var t=mt(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){if(t.length===1){t=t[0]}else{var a=t[t.length-1];t=t.slice(0,-1).join(", ")+" or "+a}}return"Expecting ".concat(t,", got ").concat(n).concat(i)}function St(e,n,t){var r=arguments.length>3&&arguments[3]!==F?arguments[3]:null;e=e.valueOf();var i=kt(n).toLowerCase();var a=false;if(t instanceof qe){t=t.toArray()}if(t instanceof Array){t=t.map(function(e){return e.valueOf()})}if(t instanceof Array){t=t.map(function(e){return e.valueOf().toLowerCase()});if(t.includes(i)){a=true}}else{t=t.valueOf().toLowerCase()}if(!a&&i!==t){throw new Error(xt(e,i,t,r))}}function Ot(e){var n=Wt(e);return["string","function"].includes(n)||e instanceof Fe||e instanceof Un||e instanceof RegExp}function kt(e){var n={pair:qe,symbol:Fe,character:Pn,values:pt,macro:ze,string:Rn,array:Array,"native-symbol":Symbol};if(Number.isNaN(e)){return"NaN "}if(e===Le){return"nil"}if(e===null){return"null"}if(e instanceof Xe){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||vt}else if(i===true){i=a=vt}else{i=i||vt}var r={env:i,dynamic_scope:a,error:o};var u;if(tn(n)){return n}if(n instanceof Fe){return i.get(n)}var c=n.car;var s=n.cdr;if(c instanceof qe){u=jt(At(c,r));if(rn(u)){return u.then(function(e){return At(new qe(e,n.cdr),r)})}else if(typeof u!=="function"){throw new Error(kt(u)+" "+i.get("repr")(u)+" is not a function while evaluating "+n.toString())}}if(c instanceof Fe){u=i.get(c);if(u instanceof Xe){return Ft(u,n,r)}else if(u instanceof ze){return It(u,s,r)}else if(typeof u!=="function"){if(u){var f="".concat(kt(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=Et(s,r);return ne(l,function(e){if(fn(u)&&(!ln(u)||pn(u))){e=e.map(on)}if(u.__lambda__&&!u.__prototype__||pn(u)){u=cn(u)}var n=e.slice();var t=(a||i).newFrame(u,n);var r=jt(u.apply(t,e));return ne(r,function(e){if(e instanceof qe){e.markCycles();return ht(e)}if(Number.isNaN(e)){return e}if(typeof e==="number"){return Un(e)}if(typeof e==="string"){return Rn(e)}return e},o)})}else if(n instanceof Fe){u=i.get(n);if(u==="undefined"){throw new Error("Unbound variable `"+n.name+"'")}return u}else if(n instanceof qe){u=c&&c.toString();throw new Error("".concat(kt(c)," ").concat(u," is not a function"))}else{return n}}catch(e){o&&o.call(i,e,n)}}function Nt(e,n,t){return Lt.apply(this,arguments)}function Lt(){Lt=Jt(Ut.mark(function e(t,r,i){var a,o,u,c;return Ut.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(i===true){r=i=r||dt}else if(r===true){r=i=dt}else{r=r||dt}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 At(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 Lt.apply(this,arguments)}function qt(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=Qt(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 Pt(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 Rt(e){this.url=e;var o=this.worker=Pt(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=zt(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=zt(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 Bt.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])}}qe.unDry=function(e){return new qe(e.car,e.cdr)};qe.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};Ne.prototype.toDry=function(){return{value:null}};Ne.unDry=function(){return Le};Fe.prototype.toDry=function(){return{value:{name:this.name}}};Fe.unDry=function(e){return new Fe(e.name)};function Ct(e){console.error(e.message||e);if(e.code){console.error(e.code.map(function(e,n){return"[".concat(n+1,"]: ").concat(e)}))}}function Tt(){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(Nt).then(n)["catch"](function(e){Ct(e);n()})}else{return Nt(e.innerHTML).then(n)["catch"](function(e){Ct(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,Tt)}var Mt=function(){var e=Rn("Thu, 17 Sep 2020 09:21:02 +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";ze.__className="macro";Xe.__className="syntax";ft.__className="environment";rt.__className="input-port";it.__className="output-port";at.__className="output-string-port";ot.__className="input-string-port";Un.__className="number";Pn.__className="character";Rn.__className="string";var Bt={version:"DEV",banner:Mt,date:"Thu, 17 Sep 2020 09:21:02 +0000",exec:Nt,parse:ee,tokenize:W,evaluate:At,Environment:ft,env:dt,Worker:Rt,Interpreter:st,balanced_parenthesis:qt,balancedParenthesis:qt,balanced:qt,Macro:ze,Syntax:Xe,Pair:qe,quote:ht,InputPort:rt,OutputPort:it,InputStringPort:ot,OutputStringPort:at,Formatter:ce,specials:K,repr:Re,nil:Le,LSymbol:Fe,LNumber:Un,LFloat:Hn,LComplex:Jn,LRational:Wn,LBigInteger:Qn,LCharacter:Pn,LString:Rn,rationalize:Vn};vt.set("lips",Bt);return Bt})})(); \ No newline at end of file +(function(){"use strict";function e(e){throw new Error('"'+e+'" is read-only')}var $t=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 Dt=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(I([])));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 A()}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 I(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:I(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 Ut=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 Jt=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 Vt=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 I=F;function A(e,n){return s(e)||I(e,n)||d(e,n)||y()}var zt=A;var Wt=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 Qt(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=Wn({num:Un([r[0],t.radix||n]),denom:Un([r[1],t.radix||n])});if(t.inexact){return i.valueOf()}else{return i}}function A(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:10;var t=E(e);if(t.inexact){return Hn(parseInt(t.number,t.radix||n))}return Un([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 Pn(t)}}function L(e){var i=arguments.length>1&&arguments[1]!==F?arguments[1]:10;function n(e){var n;if(e==="+"){n=Un(1)}else if(e==="-"){n=Un(-1)}else if(e.match(x)){n=Un([e,i])}else if(e.match(S)){var t=e.split("/");n=Wn({num:Un([t[0],i]),denom:Un([t[1],i])})}else if(e.match(c)){var r=Hn(parseFloat(e));if(a.exact){return r.toRational()}return r}else{throw new Error("Internal Parser Error")}if(a.inexact){return Hn(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 Hn){o=Hn(0)}else{o=Un(0)}return Jn({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 Un(a).mul(u)}}}t=Hn(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 Rn(JSON.parse(e))}catch(e){throw new Error("Invalid string literal")}}function T(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 Fe(e)}function M(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 I(e)}else if(e.match(b)){return L(e)}else if(e.match(_)){return A(e)}else if(e.match(c)){return R(e)}else if(e==="nil"){return Le}else if(["true","#t"].includes(e)){return true}else if(["false","#f"].includes(e)){return false}else{return T(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=Vt(e,["token"]);if(n.match(/^"[\s\S]+"$/)&&n.match(/\n/)){var r=new RegExp("^ {1,"+(e.col+1)+"}","mg");n=n.replace(r,"")}return Kt({token:n},t)}function W(e,n){var t=arguments.length>2&&arguments[2]!==F?arguments[2]:z;if(e instanceof Rn){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 Fe){c[c.length-1].push(e)}else if(c[c.length-1]instanceof qe){if(c[c.length-1].cdr instanceof qe){c[c.length-1]=new qe(c[c.length-1],qe.fromArray(e))}else{c[c.length-1].cdr=qe.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]=qe.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=Le}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(Le)}else if(i instanceof Array&&i[0]===g){var a;(a=n).push.apply(a,Yt(i.slice(1)))}else{n.push(i)}}else if(n instanceof qe){if(i.length===0){n.append(Le)}else{n.append(qe.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=M(e);if(f){while(y--){c[c.length-1].push(o);o=c.pop()}d.pop();y=0;f=false}else if(o instanceof Fe&&p.includes(o.name)){o.literal=true}n=c[c.length-1];if(n instanceof qe){var u=n;while(true){if(u.cdr===Le){if(o instanceof Array){u.cdr=qe.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 qe.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(rn);if(r.length){return ne(Promise.all(r),n,t)}return n(e)}if(rn(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"){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 Kt(Kt(Kt({},t),n),{},{exceptions:{specials:[].concat(Yt(t.exceptions.specials),Yt(i)),shift:Kt(Kt({},a),{},{1:[].concat(Yt(t.exceptions.shift[1]),Yt(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=Qt(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()&&qt(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=new se(/[([]/);var me=Symbol["for"]("*");var ye=new fe([le,me,pe],"+");var ge=new fe([Symbol["for"]("symbol")],"?");var be=new fe([Symbol["for"]("symbol")],"*");var we=[le,be,pe];var _e=new fe([le,Symbol["for"]("symbol"),me,pe],"+");var xe=ke("define","lambda","syntax-rules");var Se=/^(?!.*\b(?:[()[\]]|define|let(?:\*|rec|-env|-syntax)?|lambda|syntax-rules)\b).*$/;var Oe=/^(?:#:)?(let(?:\*|rec|-env|-syntax)?)$/;function ke(){for(var e=arguments.length,n=new Array(e),t=0;t0&&arguments[0]!==F?arguments[0]:null;if(e instanceof Fe){e=e.valueOf()}if(Ie(e)){return Fe(e)}if(e!==null){return new Fe(Symbol("#:".concat(e)))}n++;return new Fe(Symbol("#:g".concat(n)))}}();function Ne(){}Ne.prototype.toString=Ne.prototype.toJSON=function(){return"()"};Ne.prototype.valueOf=function(){return F};Ne.prototype.append=function(e){return new qe(e,Le)};Ne.prototype.toArray=function(){return[]};var Le=new Ne;function qe(e,n){if(typeof this!=="undefined"&&this.constructor!==qe||typeof this==="undefined"){return new qe(e,n)}this.car=e;this.cdr=n}function Pe(a,o){return function e(n){St(a,n,["pair","nil"]);if(n===Le){return[]}var t=[];var r=n;while(true){if(r instanceof qe){if(r.haveCycles("cdr")){break}var i=r.car;if(o&&i instanceof qe){i=this.get(a).call(this,i)}t.push(i);r=r.cdr}else{break}}return t}}qe.prototype.flatten=function(){return qe.fromArray(je(this.toArray()))};qe.prototype.length=function(){var e=0;var n=this;while(true){if(!n||n===Le||!(n instanceof qe)||n.haveCycles("cdr")){break}e++;n=n.cdr}return e};qe.prototype.clone=function(){var t=new Map;function r(e){if(e instanceof qe){if(t.has(e)){return t.get(e)}var n=new qe;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)};qe.prototype.lastPair=function(){var e=this;while(true){if(e.cdr===Le){return e}e=e.cdr}};qe.prototype.toArray=function(){var e=[];if(this.car instanceof qe){e.push(this.car.toArray())}else{e.push(this.car.valueOf())}if(this.cdr instanceof qe){e=e.concat(this.cdr.toArray())}return e};qe.fromArray=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:true;if(e instanceof qe){return e}if(n===false){var t=Le;for(var r=e.length;r--;){t=new qe(e[r],t)}return t}if(e.length&&!(e instanceof Array)){e=Yt(e)}if(e.length===0){return Le}else{var i;if(e[0]instanceof Array){i=qe.fromArray(e[0])}else{i=e[0]}if(typeof i==="string"){i=Rn(i)}if(e.length===1){return new qe(i,Le)}else{return new qe(i,qe.fromArray(e.slice(1)))}}};qe.prototype.toObject=function(){var e=arguments.length>0&&arguments[0]!==F?arguments[0]:false;var n=this;var t={};while(true){if(n instanceof qe&&n.car instanceof qe){var r=n.car;var i=r.car;if(i instanceof Fe){i=i.name}if(i instanceof String){i=i.valueOf()}var a=r.cdr;if(a instanceof qe){a=a.toObject(e)}if(a instanceof Un||a instanceof Rn||a instanceof Pn){if(!e){a=a.valueOf()}}t[i]=a;n=n.cdr}else{break}}return t};qe.fromPairs=function(e){return e.reduce(function(e,n){return new qe(new qe(new Fe(n[0]),n[1]),e)},Le)};qe.fromObject=function(n){var e=Object.keys(n).map(function(e){return[e,n[e]]});return qe.fromPairs(e)};qe.prototype.reduce=function(e){var n=this;var t=Le;while(true){if(n!==Le){t=e(t,n.car);n=n.cdr}else{break}}return t};qe.prototype.reverse=function(){if(this.haveCycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var n=Le;while(e!==Le){var t=e.cdr;e.cdr=n;n=e;e=t}return n};qe.prototype.transform=function(r){function i(e){if(e instanceof qe){if(e.replace){delete e.replace;return e}var n=r(e.car);if(n instanceof qe){n=i(n)}var t=r(e.cdr);if(t instanceof qe){t=i(t)}return new qe(n,t)}return e}return i(this)};qe.prototype.map=function(e){if(typeof this.car!=="undefined"){return new qe(e(this.car),this.cdr===Le?Le:this.cdr.map(e))}else{return Le}};var Re=new Map;function Ce(t){var e=t.constructor||Object;var r=Wt(t)==="object"&&e===Object;var i;if(Re.has(e)){i=Re.get(e)}else{Re.forEach(function(e,n){n=cn(n);if(t instanceof n&&(n===Object&&r||n!==Object)){i=e}})}return i}var Te=new Map;[[Number.NEGATIVE_INFINITY,"-inf.0"],[Number.POSITIVE_INFINITY,"+inf.0"],[true,"#t"],[false,"#f"],[null,"null"],[F,"#"]].forEach(function(e){var n=zt(e,2),t=n[0],r=n[1];Te.set(t,r)});function Me(t){if(t&&Wt(t)==="object"){var r={};var e=Object.getOwnPropertySymbols(t);e.forEach(function(e){var n=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");r[n]=Be(t[e])});var n=Object.getOwnPropertyNames(t);n.forEach(function(e){var n=t[e];if(Wt(n)==="object"&&n.constructor===Object){r[e]=Me(n)}else{r[e]=Be(n)}});return r}return t}function Be(e,n,t){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(Te.has(e)){return Te.get(e)}if(e instanceof qe){if(!t){e.markCycles()}return e.toString(n)}if(Number.isNaN(e)){return"+nan.0"}var r=[RegExp,Ne,Fe,Un,Pn,pt];for(var i=0,a=r;i"}if(bn(e.toString)){return"#"}else{return e.toString()}}if(e instanceof Rn){e=e.toString()}if(e===null||typeof e==="string"&&n){return JSON.stringify(e)}if(Wt(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($e(e)){return"#"}var s=Ce(e);if(s){if(typeof s==="function"){return s(e,n)}else{throw new Error("toString: Invalid repr value")}}c=u.name}if(kt(e)==="instance"&&!bn(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 $e(e){return e&&Wt(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}qe.prototype.markCycles=function(){De(this);return this};qe.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 De(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 qe){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 qe){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 qe){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")})}qe.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=Be(this.car,e,true)}if(r!==F){t.push(r)}if(this.cdr instanceof qe){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!==Le){t=t.concat([" . ",Be(this.cdr,e,true)])}if(!n||this.ref){t.push(")")}return t.join("")};qe.prototype.set=function(e,n){this[e]=n;if(n instanceof qe){this.markCycles()}};qe.prototype.append=function(e){if(e instanceof Array){return this.append(qe.fromArray(e))}var n=this;if(n.car===F){if(e instanceof qe){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(e!==Le){while(true){if(n instanceof qe&&n.cdr!==Le){n=n.cdr}else{break}}n.cdr=e}return this};function Ue(e){return e<0?-e:e}function Je(e,n){var t=Ht(n),r=t[0],i=t.slice(1);while(i.length>0){var a=i,o=zt(a,1),u=o[0];if(!e(r,u)){return false}var c=i;var s=Ht(c);r=s[0];i=s.slice(1)}return true}function He(e,n){if(typeof e==="function"&&typeof n==="function"){return cn(e)===cn(n)}else if(e instanceof Un&&n instanceof Un){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=Un(e);n=Un(n);return e.type===n.type&&e.cmp(n)===0}else if(e instanceof Pn&&n instanceof Pn){return e["char"]===n["char"]}else if(e instanceof Fe&&n instanceof Fe){return e.name===n.name}else{return e===n}}function Ye(e,n){if(kt(e)!==kt(n)){return false}if(!Ge(e)){return false}if(e instanceof RegExp){return e.source===n.source}if(e instanceof Rn){return e.valueOf()===n.valueOf()}return He(e,n)}function Ge(e){return e instanceof Fe||Rn.isString(e)||e instanceof Pn||e instanceof Un||e===true||e===false}var Ve=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function ze(e,n,t,r){if(typeof this!=="undefined"&&this.constructor!==ze||typeof this==="undefined"){return new ze(e,n)}St("Macro",e,"string",1);St("Macro",n,"function",2);if(t){if(r){this.__doc__=t}else{this.__doc__=ie(t)}}this.name=e;this.fn=n}ze.defmacro=function(e,n,t,r){var i=new ze(e,n,t,r);i.defmacro=true;return i};ze.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};ze.prototype.toString=function(){return"#"};var We="define-macro";var Qe=-1e4;function Ke(a){return function(){var t=Jt(Ut.mark(function e(t,v){var r,d,i;return Ut.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:i=function e(){i=Jt(Ut.mark(function e(t,r,i){var a,o,u,c,s,f,l,p,h;return Ut.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(!(t instanceof qe&&t.car instanceof Fe)){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 ze&&a.defmacro)){n.next=24;break}o=a instanceof Xe?t:t.cdr;n.next=8;return a.invoke(o,v,true);case 8:u=n.sent;if(!(a instanceof Xe)){n.next=17;break}c=u,s=c.expr,f=c.scope;if(!(s instanceof qe)){n.next=16;break}if(!(r!==-1&&r<=1||r"};Xe.className="syntax";function Ze(e,n,_,x,S){var O={"...":{symbols:{},lists:[]}};function k(e){if(dt.get("DEBUG",{throwError:false})){console.log(e)}}k(_);function j(e,n){var t=arguments.length>2&&arguments[2]!==F?arguments[2]:[];var r=arguments.length>3&&arguments[3]!==F?arguments[3]:false;k({code:n&&Be(n,true),pattern:e&&Be(e,true)});if(Ge(e)&&!(e instanceof Fe)){return Ye(e,n)}if(e instanceof Fe&&_.includes(e.valueOf())){var i=S.ref(n);var a=typeof i==="undefined"||i===vt;return Fe.is(n,e)&&a}if(e instanceof qe&&e.car instanceof qe&&e.car.cdr instanceof qe&&Fe.is(e.car.cdr.car,x)){k(">> 0");if(n===Le){k({pattern:e.toString()});if(e.car.car instanceof Fe){if(e.car.cdr instanceof qe&&Fe.is(e.car.cdr.car,x)){var o=e.car.car.valueOf();var u=e.lastPair();if(Fe.is(u.car,x)){O["..."].symbols[o]=null;return true}else{return false}}var c=e.car.car.valueOf();if(O["..."].symbols[c]){throw new Error("syntax: named ellipsis can only "+"appear onces")}O["..."].symbols[c]=n}}}if(e instanceof qe&&e.cdr instanceof qe&&Fe.is(e.cdr.car,x)){if(e.cdr.cdr!==Le){if(e.cdr.cdr instanceof qe){var s=e.cdr.cdr.length();var f=n.length();var l=n;while(f-1>s){l=l.cdr;f--}var p=l.cdr;l.cdr=Le;if(!j(e.cdr.cdr,p,t,r)){return false}}}if(e.car instanceof Fe){var h=e.car.name;if(O["..."].symbols[h]&&!t.includes(h)&&!r){throw new Error("syntax: named ellipsis can only appear onces")}k(">> 1");if(n===Le){k(">> 2");if(r){k("NIL");O["..."].symbols[h]=Le}else{k("NULL");O["..."].symbols[h]=null}}else if(n instanceof qe&&(n.car instanceof qe||n.car===Le)){k(">> 3 "+r);if(r){if(O["..."].symbols[h]){var v=O["..."].symbols[h];O["..."].symbols[h]=v.append(new qe(n,Le))}else{O["..."].symbols[h]=new qe(n,Le)}}else{k(">> 4");O["..."].symbols[h]=new qe(n,Le)}}else{k(">> 6");if(n instanceof qe){k(">> 7 "+r);t.push(h);if(!O["..."].symbols[h]){O["..."].symbols[h]=new qe(n,Le)}else{var d=O["..."].symbols[h];O["..."].symbols[h]=d.append(new qe(n,Le))}k({IIIIII:O["..."].symbols[h].toString()})}else{k(">> 8");return false}}return true}else if(e.car instanceof qe){var m=Yt(t);if(n===Le){k(">> 9");O["..."].lists.push(Le);return true}k(">> 10");var y=n;while(y instanceof qe){if(!j(e.car,y.car,m,true)){return false}y=y.cdr}return true}return false}if(e instanceof Fe){if(Fe.is(e,x)){throw new Error("syntax: invalid usage of ellipsis")}k(">> 11");var g=e.name;if(_.includes(g)){return true}k({name:g,ellipsis:r});if(r){O["..."].symbols[g]=O["..."].symbols[g]||[];O["..."].symbols[g].push(n)}if(!O[g]){O[g]=n}return true}if(e instanceof qe&&n instanceof qe){k(">> 12");k({a:12,code:n&&n.toString(),pattern:e.toString()});if(n.cdr===Le){var b=e.car instanceof Fe&&e.cdr instanceof Fe;if(b){k(">> 12 | 1");var w=e.cdr.valueOf();if(!O[w]){O[w]=Le}w=e.car.valueOf();if(!O[w]){O[w]=n.car}return true}}k("recur");if(j(e.car,n.car,t,r)&&j(e.cdr,n.cdr,t,r)){return true}}else if(e===Le&&(n===Le||n===F)){return true}else if(e.car instanceof qe&&Fe.is(e.car.car,x)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(j(e,n)){return O}}function en(e,i){function a(n){if(n instanceof qe){if(!i.length){return n}var e=a(n.car);var t=a(n.cdr);return new qe(e,t)}else if(n instanceof Fe){var r=i.find(function(e){return e.gensym===n});if(r){return Fe(r.name)}return n}else{return n}}return a(e)}function nn(){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 Fe||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=Wt(n);if(["string","symbol"].includes(t)&&n in w){return w[n]}if(i.includes(n)){return Fe(n)}return u(n)}function S(e){if(dt.get("DEBUG",{throwError:false})){console.log(e)}}function u(e){if(!o[e]){var n=r.get(e,{throwError:false});var t=Ae(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 Fe){var a=e.valueOf();S("[t 1");if(n[a]){if(n[a]instanceof qe){var o=n[a],u=o.car,c=o.cdr;if(i){var s=u.car,f=u.cdr;if(f!==Le){r(a,new qe(f,Le))}return s}if(c!==Le){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 qe){if(e.car instanceof Fe&&e.cdr instanceof qe&&Fe.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 qe){S("[t 2 Pair "+i);S({______:p.toString()});var h=p.car,v=p.cdr;if(i){if(v!==Le){r(l,v)}return h}else{if(h.cdr!==Le){r(l,new qe(h.cdr,v))}return h.car}}else if(p instanceof Array){S("[t 2 Array "+i);if(i){r(l,p.slice(1));return qe.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 qe(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,Yt(r.map(function(e){return n[e]})))}return e.length&&e.every(function(e){if(e===null){return!t}return e instanceof qe||e===Le||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 qe){if(!n&&i.car instanceof qe&&Fe.is(i.car.car,_)){return E(i.car.cdr,{disabled:true})}if(i.cdr instanceof qe&&Fe.is(i.cdr.car,_)&&!n){S(">> 1");var t=w["..."].symbols;var r=j(t);if(i.car instanceof qe){if(w["..."].lists[0]===Le){return Le}S(">> 2");var a;if(r.length){S(">> 2 (a)");var o=Kt({},t);a=Le;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 qe(t,a)}o=r};while(true){var c=u();if(c==="break")break}if(a!==Le){a=a.reverse()}return a}else{S(">> 3");var s=O(i.car,t,{nested:true});if(s){return new qe(s,Le)}return Le}}else if(i.car instanceof Fe){S(">> 4");var f=i.car.name;var l=Gt({},f,t[f]);var p=t[f]===null;var h=Le;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 qe(t,h)}l=r};while(true){var d=v();if(d==="break")break}if(h!==Le){h=h.reverse()}if(i.cdr instanceof qe){if(i.cdr.cdr instanceof qe||i.cdr.cdr instanceof Fe){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 qe(y,g)}if(i instanceof Fe){if(n&&Fe.is(i,_)){return i}var b=x(i);if(typeof b!=="undefined"){return b}}return i}return E(n,{})}function tn(e){return typeof e==="undefined"||e===Le||e===null}function rn(e){return e instanceof Promise||e&&typeof e!=="undefined"&&typeof e.then==="function"}function an(e){switch(Wt(e)){case"string":return Rn(e);case"number":if(!Number.isNaN(e)){return Un(e)}}return e}function on(n){var e=[Rn,Pn,Un].some(function(e){return n instanceof e});if(e){return n.valueOf()}return n}function un(e,n){if(e instanceof qe){e.markCycles();return ht(e)}if(typeof e==="function"){if(n){return sn(e,n)}}return an(e)}function cn(e){if(fn(e)){return e[vn]}return e}function sn(n,e){if(n[Symbol["for"]("__bound__")]){return n}var t=n.bind(e);var r=Object.getOwnPropertyNames(n).filter(mn);r.forEach(function(e){try{t[e]=n[e]}catch(e){}});yn(t,"__fn__",n);yn(t,"__context__",e);yn(t,"__bound__",true);if(bn(n)){yn(t,"__native__",true)}t.valueOf=function(){return n};return t}function fn(e){return!!(typeof e==="function"&&e[vn])}function ln(e){if(typeof e==="function"){var n=e[hn];if(n&&(n===Bt||n.constructor&&n.constructor.__className)){return true}}return false}function pn(e){function n(e){return e instanceof rt||e instanceof it}if(typeof e==="function"){if(n(e)){return true}if(n(e[hn])){return true}}return false}var hn=Symbol["for"]("__context__");var vn=Symbol["for"]("__fn__");var dn=["name","length","caller","callee","arguments","prototype"];function mn(e){return!dn.includes(e)}function yn(e,n,t){Object.defineProperty(e,Symbol["for"](n),{get:function e(){return t},set:function e(){},configurable:false,enumerable:false})}function gn(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 bn(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 wn(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 ze.defmacro(v,function(n,e){var a=e.dynamic_scope,o=e.error,t=e.macro_expand;var u;if(n.car instanceof Fe){if(!(n.cdr.car instanceof qe||n.cdr.car===Le)){throw new Error("let require list of pairs")}var r;if(n.cdr.car===Le){u=Le;r=Le}else{r=n.cdr.car.map(function(e){return e.car});u=n.cdr.car.map(function(e){return e.cdr.car})}return qe.fromArray([Fe("letrec"),[[n.car,qe(Fe("lambda"),qe(r,n.cdr.cdr))]],qe(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 qe(new Fe("begin"),n.cdr);return At(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(rn);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 qe){o.push(At(a.car,{env:i,dynamic_scope:t,error:r}));a=a.cdr}var u=o.filter(rn).length;if(u){return Promise.all(o).then(c.bind(this))}else{return c.call(this,o)}})}function xn(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 Nn(r,i){St("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 Un){return e}if(typeof this!=="undefined"&&!(this instanceof Un)||typeof this==="undefined"){return new Un(e,n)}if(typeof e==="undefined"){throw new Error("Invlaid LNumber constructor call")}var t=Un.getType(e);if(Un.types[t]){return Un.types[t](e,n)}var r=e instanceof Array&&Rn.isString(e[0])&&Un.isNumber(e[1]);if(e instanceof Un){return Un(e.value)}if(!Un.isNumber(e)&&!r){throw new Error("You can't create LNumber from ".concat(kt(e)))}if(e===null){e=0}var i;if(r){var a=e,o=zt(a,2),u=o[0],c=o[1];if(u instanceof Rn){u=u.valueOf()}if(c instanceof Un){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=Yt(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 Qn(i,true)}else if(typeof h!=="undefined"&&!(e instanceof h)){if(e instanceof Array){return Qn(Dt(h,Yt(e)))}return Qn(new h(e))}else if(r){this.value=parseInt(u,c)}else{this.value=e}}Un.types={float:function e(n){var t=arguments.length>1&&arguments[1]!==F?arguments[1]:false;return new Hn(n,t)},complex:function e(n){var t=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(!Un.isComplex(n)){n={im:0,re:n}}return new Jn(n,t)},rational:function e(n){var t=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(!Un.isRational(n)){n={num:n,denom:1}}return new Wn(n,t)}};function Jn(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof Jn)||typeof this==="undefined"){return new Jn(e,n)}if(e instanceof Jn){return Jn({im:e.im,re:e.re})}if(Un.isNumber(e)&&n){e={im:0,re:e.valueOf()}}else if(!Un.isComplex(e)){throw new Error("Invalid constructor call for LComplex")}var t=e.im instanceof Un?e.im:Un(e.im);var r=e.re instanceof Un?e.re:Un(e.re);if(t.cmp(0)===0&&!n){return r}this.im=t;this.re=r;this.type="complex"}Jn.prototype=Object.create(Un.prototype);Jn.prototype.constructor=Jn;Jn.prototype.toRational=function(e){if(Un.isFloat(this.im)&&Un.isFloat(this.re)){var n=Hn(this.im).toRational(e);var t=Hn(this.re).toRational(e);return Jn({im:n,re:t})}return this};Jn.prototype.add=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.add(n),im:t.add(r)}})};Jn.prototype.factor=function(){if(this.im instanceof Hn||this.im instanceof Hn){var e=this.re,n=this.im;var t,r;if(e instanceof Hn){t=e.toRational().mul(e.toRational())}else{t=e.mul(e)}if(n instanceof Hn){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))}};Jn.prototype.modulus=function(){return this.factor().sqrt()};Jn.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=Hn(.5).mul(e.add(this.re)).sqrt();t=this.im.div(n).div(2)}else{t=Hn(.5).mul(e.sub(this.re)).sqrt();if(this.im.cmp(0)===-1){t=t.sub()}n=this.im.div(t).div(2)}return Jn({im:t,re:n})};Jn.prototype.div=function(e){if(Un.isNumber(e)&&!Un.isComplex(e)){e=Jn({im:0,re:e})}else if(!Un.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var n=this.coerce(e),t=zt(n,2),r=t[0],i=t[1];var a=Jn({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 Jn({re:c,im:s})};Jn.prototype.sub=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.sub(n),im:t.sum(r)}})};Jn.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})};Jn.prototype.complex_op=function(e,n){if(Un.isNumber(e)&&!Un.isComplex(e)){if(!(e instanceof Un)){e=Un(e)}var t=e.asType(0);e={im:t,re:e}}else if(!Un.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var r=e.re instanceof Un?e.re:this.re.asType(e.re);var i=e.im instanceof Un?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=Jn(a,true);return o}return a};Jn._op={"+":"add","-":"sub","*":"mul","/":"div"};Jn.prototype._op=function(e,n){var t=Jn._op[e];return this[t](n)};Jn.prototype.cmp=function(e){var n=this.coerce(e),t=zt(n,2),r=t[0],i=t[1];var a=r.re.coerce(i.re),o=zt(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=zt(f,2),p=l[0],h=l[1];return p.cmp(h)}};Jn.prototype.valueOf=function(){};Jn.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 Hn(e){if(typeof this!=="undefined"&&!(this instanceof Hn)||typeof this==="undefined"){return new Hn(e)}if(!Un.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof Un){return Hn(e.valueOf())}if(typeof e==="number"){this.value=e;this.type="float"}}Hn.prototype=Object.create(Un.prototype);Hn.prototype.constructor=Hn;Hn.prototype.toString=function(){var e=this.value.toString();if(!Un.isFloat(this.value)&&!e.match(/e/i)){return e+".0"}return e.replace(/^([0-9]+)e/,"$1.0e")};Hn.prototype._op=function(e,n){if(n instanceof Un){n=n.value}var t=Un._ops[e];if(e==="/"&&this.value===0&&n===0){return NaN}return Hn(t(this.value,n))};Hn.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==F?arguments[0]:null;if(e===null){return Yn(this.value.valueOf())}return Gn(e.valueOf())(this.value.valueOf())};var Yn=Gn(1e-10);function Gn(r){return function(e){var n=function e(r,n,t){var i=function e(n,t){return t0){i=zn(r,t)}else if(r.cmp(t)<=0){i=t}else if(t.cmp(0)>0){i=zn(t,r)}else if(n.cmp(0)<0){i=Un(zn(r.sub(),t.sub())).sub()}else{i=Un(0)}if(Un.isFloat(n)||Un.isFloat(e)){return Hn(i)}return i}function zn(e,n){var t=Un(e).floor();var r=Un(n).floor();if(e.cmp(t)<1){return t}else if(t.cmp(r)===0){var i=Un(1).div(n.sub(r));var a=Un(1).div(e.sub(t));return t.add(Un(1).div(zn(i,a)))}else{return t.add(Un(1))}}function Wn(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof Wn)||typeof this==="undefined"){return new Wn(e,n)}if(!Un.isRational(e)){throw new Error("Invalid constructor call for LRational")}var t=Un(e.num);var r=Un(e.denom);if(!n&&r.cmp(0)!==0){var i=t.op("%",r).cmp(0)===0;if(i){return Un(t.div(r))}}this.num=t;this.denom=r;this.type="rational"}Wn.prototype=Object.create(Un.prototype);Wn.prototype.constructor=Wn;Wn.prototype.pow=function(e){var n=e.cmp(0);if(n===0){return Un(1)}if(n===-1){e=e.sub();var t=this.denom.pow(e);var r=this.num.pow(e);return Wn({num:t,denom:r})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};Wn.prototype.sqrt=function(){var e=this.num.sqrt();var n=this.denom.sqrt();if(e instanceof Hn){e=($t("num"),e.toRational())}if(n instanceof Hn){n=($t("denom"),n.toRational())}return Wn({num:e,denom:n})};Wn.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 Wn({num:e,denom:n})};Wn.prototype.cmp=function(e){return Un(this.valueOf(),true).cmp(e)};Wn.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 Wn){n=Un(n.valueOf(true))}t=this.denom.div(e);if(t instanceof Wn){t=Un(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()};Wn.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 Un._ops["/"](this.num.value,this.denom.value)}return Hn(this.num.valueOf()).div(this.denom.valueOf())};Wn.prototype.mul=function(e){if(!(e instanceof Un)){e=Un(e)}if(Un.isRational(e)){var n=this.num.mul(e.num);var t=this.denom.mul(e.denom);return Wn({num:n,denom:t})}var r=Un.coerce(this,e),i=zt(r,2),a=i[0],o=i[1];return a.mul(o)};Wn.prototype.div=function(e){if(!(e instanceof Un)){e=Un(e)}if(Un.isRational(e)){var n=this.num.mul(e.denom);var t=this.denom.mul(e.num);return Wn({num:n,denom:t})}var r=Un.coerce(this,e),i=zt(r,2),a=i[0],o=i[1];var u=a.div(o);return u};Wn.prototype._op=function(e,n){return this[et[e]](n)};Wn.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof Un)){e=Un(e)}if(Un.isRational(e)){var n=e.num.sub();var t=e.denom;return this.add(Wn({num:n,denom:t}))}if(!(e instanceof Un)){e=Un(e).sub()}else{e=e.sub()}var r=Un.coerce(this,e),i=zt(r,2),a=i[0],o=i[1];return a.add(o)};Wn.prototype.add=function(e){if(!(e instanceof Un)){e=Un(e)}if(Un.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 Wn({num:o,denom:a})}if(Un.isFloat(e)){return Hn(this.valueOf()).add(e)}var u=Un.coerce(this,e),c=zt(u,2),s=c[0],f=c[1];return s.add(f)};function Qn(e,n){if(typeof this!=="undefined"&&!(this instanceof Qn)||typeof this==="undefined"){return new Qn(e,n)}if(e instanceof Qn){return Qn(e.value,e._native)}if(!Un.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.value=e;this._native=n;this.type="bigint"}Qn.prototype=Object.create(Un.prototype);Qn.prototype.constructor=Qn;Qn.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};Qn.prototype._op=function(e,n){if(typeof n==="undefined"){if(Un.isBN(this.value)){e=Qn.bn_op[e];return Qn(this.value.clone()[e](),false)}return Qn(Un._ops[e](this.value),true)}if(Un.isBN(this.value)&&Un.isBN(n.value)){e=Qn.bn_op[e];return Qn(this.value.clone()[e](n),false)}var t=Un._ops[e](this.value,n.value);if(e==="/"){var r=this.op("%",n).cmp(0)===0;if(r){return Un(t)}return Wn({num:this,denom:n})}return Qn(t,true)};Qn.prototype.sqrt=function(){var e;var n=this.cmp(0)<0;if(Un.isNative(this.value)){e=Un(Math.sqrt(n?-this.valueOf():this.valueOf()))}else if(Un.isBN(this.value)){e=n?this.value.neg().sqrt():this.value.sqrt()}if(n){return Jn({re:0,im:e})}return e};Un.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}}};Un.isFloat=function e(n){return n instanceof Hn||Number(n)===n&&n%1!==0};Un.isNumber=function(e){return e instanceof Un||!Number.isNaN(e)&&Un.isNative(e)||Un.isBN(e)};Un.isComplex=function(e){var n=e instanceof Jn||Un.isNumber(e.im)&&Un.isNumber(e.re);return n};Un.isRational=function(e){return e instanceof Wn||Un.isNumber(e.num)&&Un.isNumber(e.denom)};Un.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};Un.isBigInteger=function(e){return e instanceof Qn||typeof e==="bigint"||Un.isBN(e)};Un.isBN=function(e){return typeof h!=="undefined"&&e instanceof h};Un.getArgsType=function(e,n){if(e instanceof Hn||n instanceof Hn){return Hn}if(e instanceof Qn||n instanceof Qn){return Qn}return Un};Un.prototype.toString=Un.prototype.toJSON=function(e){if(e>2&&e<36){return this.value.toString(e)}return this.value.toString()};Un.prototype.asType=function(e){var n=Un.getType(this);return Un.types[n]?Un.types[n](e):Un(e)};Un.prototype.isBigNumber=function(){return typeof this.value==="bigint"||typeof h!=="undefined"&&!(this.value instanceof h)};["floor","ceil","round"].forEach(function(e){Un.prototype[e]=function(){if(this["float"]||Un.isFloat(this.value)){return Un(Math[e](this.value))}else{return Un(Math[e](this.valueOf()))}}});Un.prototype.valueOf=function(){if(Un.isNative(this.value)){return Number(this.value)}else if(Un.isBN(this.value)){return this.value.toNumber()}};var Kn=function(){var e=function e(n,t){return[n,t]};return{bigint:{bigint:e,float:function e(n,t){return[Hn(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&&Hn(t.valueOf())]},float:e,rational:function e(n,t){return[n,t&&Hn(t.valueOf())]},complex:function e(n,t){return[{re:n,im:Hn(0)},t]}},complex:{bigint:n("bigint"),float:n("float"),rational:n("rational"),complex:function e(n,t){var r=Un.coerce(n.re,t.re),i=zt(r,2),a=i[0],o=i[1];var u=Un.coerce(n.im,t.im),c=zt(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[Hn(n.valueOf()),t]},rational:e,complex:function e(n,t){return[{im:Xn(n.type,t.im.type,0),re:Xn(n.type,t.re.type,n)},{im:Xn(n.type,t.im.type,t.im),re:Xn(n.type,t.re.type,t.re)}]}}};function n(t){return function(e,n){return[{im:Xn(t,e.im.type,e.im),re:Xn(t,e.re.type,e.re)},{im:Xn(t,e.im.type,0),re:Xn(t,n.type,n)}]}}}();function Xn(e,n,t){return Kn[e][n](t)[0]}Un.coerce=function(e,n){function t(e){if(e==="integer"){return"bigint"}return e}var r=t(Un.getType(e));var i=t(Un.getType(n));if(!Kn[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!Kn[r][i]){throw new Error("LNumber::coerce unknown rhs type ".concat(i))}return Kn[r][i](e,n).map(function(e){return Un(e,true)})};Un.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof Un)){throw new Error("LNumber: you can't coerce ".concat(kt(e)))}if(typeof e==="number"){e=Un(e)}return Un.coerce(this,e)};Un.getType=function(e){if(e instanceof Un){return e.type}if(Un.isFloat(e)){return"float"}if(Un.isComplex(e)){return"complex"}if(Un.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"}};Un.prototype.isFloat=function(){return!!(Un.isFloat(this.value)||this["float"])};var Zn={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var et={};Object.keys(Zn).forEach(function(n){et[Zn[n]]=n;Un.prototype[n]=function(e){return this.op(Zn[n],e)}});Un._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 ut}return Pn(this._string[this._in_char])};function it(e){if(typeof this!=="undefined"&&!(this instanceof it)||typeof this==="undefined"){return new it(e)}St("OutputPort",e,"function");this.write=e}it.prototype.toString=function(){return"<#output-port>"};function at(n){var t=this;if(typeof this!=="undefined"&&!(this instanceof at)||typeof this==="undefined"){return new at(n)}St("OutputStringPort",n,"function");this._buffer=[];this.write=function(e){if(!Rn.isString(e)){e=n(e)}else{e=e.valueOf()}t._buffer.push(e)}}at.prototype=Object.create(it.prototype);at.prototype.getString=function(){return this._buffer.map(function(e){return e.valueOf()}).join("")};at.prototype.constructor=at;function ot(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof ot)||typeof this==="undefined"){return new ot(e)}St("InputStringPort",e,"string");this._string=e.valueOf();this._index=0;this._in_char=0;this.read=function(){return n.get_next_tokens()}}ot.prototype=Object.create(rt.prototype);ot.prototype.constructor=ot;ot.prototype.read_line=function(){var e=this._string.substring(this._in_char);if(!e){return ut}var n=e.match(/([^\n])(?:\n|$)/)[0];this._in_char+=n.length;return n};var ut=new ct;function ct(){}ct.prototype.toString=function(){return"<#eof>"};function st(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:{};if(typeof this!=="undefined"&&!(this instanceof st)||typeof this==="undefined"){return new st(e,n)}if(typeof e==="undefined"){e="anonymous"}this.env=dt.inherit(e,n)}st.prototype.exec=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;var t=arguments.length>2&&arguments[2]!==F?arguments[2]:null;St("Intepreter::exec",e,"string",1);St("Intepreter::exec",n,"boolean",2);vt.set("**interaction-environment**",this.env);if(t===null){t=this.env}return Nt(e,t,n?t:false)};st.prototype.get=function(e){return this.env.get(e).bind(this.env)};st.prototype.set=function(e,n){return this.env.set(e,n)};function ft(e,n,t){if(arguments.length===1){if(Wt(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"}ft.prototype.inherit=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:{};if(Wt(e)==="object"){n=e}if(!e||Wt(e)==="object"){e="child of "+(this.name||"unknown")}return new ft(n||{},this,e)};ft.prototype.doc=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:null;if(e instanceof Fe){e=e.name}if(e instanceof Rn){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)}};ft.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 ft)){return Le}if(e<=0){return n}var t=n.get("parent.frame");return t(e-1)},vt.env["parent.frame"].__doc__));n.callee=e;r.set("arguments",n);return r};ft.prototype._lookup=function(e){if(e instanceof Fe){e=e.name}if(e instanceof Rn){e=e.valueOf()}if(this.env.hasOwnProperty(e)){return lt(this.env[e])}if(this.parent){return this.parent._lookup(e)}};ft.prototype.toString=function(){return"<#env:"+this.name+">"};ft.prototype.clone=function(){var n=this;var t={};Object.keys(this.env).forEach(function(e){t[e]=n.env[e]});return new ft(t,this.parent,this.name)};ft.prototype.merge=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:"merge";St("Environment::merge",e,"environment");return this.inherit(n,e.env)};function lt(e){if(typeof this!=="undefined"&&!(this instanceof lt)||typeof this==="undefined"){return new lt(e)}this.value=e}lt.isUndefined=function(e){return e instanceof lt&&typeof e.value==="undefined"};lt.prototype.valueOf=function(){return this.value};function pt(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof pt)||typeof this==="undefined"){return new pt(e)}this.values=e}pt.prototype.toString=function(){return this.values.map(function(e){return Be(e)}).join("\n")};pt.prototype.valueOf=function(){return this.values};ft.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 Fe||i instanceof Rn){i=i.valueOf()}var a=this._lookup(i);if(a instanceof lt){if(lt.isUndefined(a)){return F}return un(a.valueOf())}if(typeof i==="string"){var o=i.split(".").filter(Boolean);if(o.length>0){var u=Ht(o),c=u[0],s=u.slice(1);a=this._lookup(c);if(s.length){try{if(a instanceof lt){a=a.valueOf()}else{a=qn(f,c);if(typeof a==="function"){a=cn(a)}}return qn.apply(void 0,[a].concat(Yt(s)))}catch(e){}}else if(a instanceof lt){return un(a.valueOf())}}a=qn(f,i)}if(typeof a!=="undefined"){return a}if(r){throw new Error("Unbound variable `"+i.toString()+"'")}};ft.prototype.set=function(e,n){var t=arguments.length>2&&arguments[2]!==F?arguments[2]:null;if(Un.isNumber(n)){n=Un(n)}if(e instanceof Fe){e=e.name}if(e instanceof Rn){e=e.valueOf()}this.env[e]=n;if(t){this.doc(e,t)}return this};ft.prototype.has=function(e){return this.env.hasOwnProperty(e)};ft.prototype.ref=function(e){var n=this;while(true){if(!n){break}if(n.has(e)){return n}n=n.parent}};ft.prototype.parents=function(){var e=this;var n=[];while(e){n.unshift(e);e=e.parent}return n};function ht(e){if(rn(e)){return e.then(ht)}if(e instanceof qe||e instanceof Fe){e.data=true}return e}var vt=new ft({nil:Le,undefined:F,true:true,false:false,null:null,NaN:NaN,stdout:new it(function(){var e;(e=console).log.apply(e,arguments)}),stdin:rt(function(){return new Promise(function(e){e(prompt(""))})}),"open-input-string":re(function(e){St("open-input-string",e,"string");return ot(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 it},"(output-port? arg)\n\n Function return true if argument is output port."),"input-port?":re(function(e){return e instanceof rt},"(input-port? arg)\n\n Function return true if argument is input port."),"open-output-string":re(function(){return at(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){St("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===ut},"(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){St("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")}St("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")}St("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(Rn.isString(n)){return ee(W(n.valueOf()))[0]}var t;if(n instanceof rt){t=n}else{t=this.get("stdin")}return ne(t.read(),function(e){if(e===ut){return ut}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 qe){e=new Bt.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=At(e.cdr.car,{env:this,dynamic_scope:t,error:r});i=jt(i);function u(n,t){if(rn(n)){return n.then(function(e){return u(e,t)})}if(rn(t)){return t.then(function(e){return u(n,e)})}f[n]=t;return t}if(e.car instanceof qe&&Fe.is(e.car.car,".")){var c=e.car.cdr.car;var s=e.car.cdr.cdr.car;var f=At(c,{env:this,dynamic_scope:t,error:r});var l=At(s,{env:this,dynamic_scope:t,error:r});return u(l,i)}if(!(e.car instanceof Fe)){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 ze("set!",function(e){if(!(e.car instanceof Fe)){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){St("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){St("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===Le},"(empty? object)\n\n Function return true if value is undfined empty list."),assoc:re(function(e,n){if(e instanceof qe&&!(n instanceof qe)){throw new Error("First argument to assoc ned to be a key")}St("assoc",n,"pair");var t=n;while(true){if(!(t instanceof qe)||this.get("empty?")(t)){break}var r=t.car.car;if(He(r,e)){return t.car}else if(!t.haveCycles("cdr")){t=t.cdr}}return Le},"(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(Ae,"(gensym)\n\n Function generate unique symbol, to use with macros as meta name."),load:re(function(n){St("load",n,"string");var e=this;if(e.name==="__frame__"){e=e.parent}var i;if(e===vt){i=e}else{i=this.get("**interaction-environment**")}var a="**module-path**";var o=vt.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)}vt.set(a,e.dirname(n));require("fs").readFile(n,function(e,n){if(e){console.log(e);r(e);vt.set(a,o)}else{Nt(n.toString(),i).then(function(){t();vt.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){vt.set(a,n.replace(/\/[^/]*$/,""));return Nt(e,i)}).then(function(){})["finally"](function(){vt.set(a,o)})},"(load filename)\n\n Function fetch the file and evaluate its content as LIPS code."),do:re(new ze("do",function(){var t=Jt(Ut.mark(function e(t,r){var i,a,o,u,c,s,f,l,p,h,v,d,m,y;return Ut.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:i=r.dynamic_scope,a=r.error;o=this;if(i){i=o}u=o.inherit("do");c=t.car;s=t.cdr.car;f=t.cdr.cdr;if(f!==Le){f=new qe(Fe("begin"),f)}l={env:u,dynamic_scope:i,error:a};p=c;case 10:if(!(p!==Le)){n.next=21;break}h=p.car;n.t0=u;n.t1=h.car;n.next=16;return At(h.cdr.car,l);case 16:n.t2=n.sent;n.t0.set.call(n.t0,n.t1,n.t2);p=p.cdr;n.next=10;break;case 21:n.next=23;return At(s.car,l);case 23:if(n.sent){n.next=42;break}if(!(f!==Le)){n.next=27;break}n.next=27;return Bt.evaluate(f,l);case 27:v=c;d={};case 29:if(!(v!==Le)){n.next=39;break}m=v.car;if(!(m.cdr.cdr!==Le)){n.next=36;break}n.next=34;return At(m.cdr.cdr.car,l);case 34:y=n.sent;d[m.car.valueOf()]=y;case 36:v=v.cdr;n.next=29;break;case 39:Object.entries(d).forEach(function(e){var n=zt(e,2),t=n[0],r=n[1];u.set(t,r)});n.next=21;break;case 42:if(!(s.cdr!==Le)){n.next=46;break}n.next=45;return At(s.cdr.car,l);case 45:return n.abrupt("return",n.sent);case 46:case"end":return n.stop()}}},e,this)}));return function(e,n){return t.apply(this,arguments)}}()),"(do (( )) (test expression) . body)\n\n Iteration macro that evaluate the expression body in scope of the variables.\n On Eeach loop it increase the variables according to next expression and run\n test to check if the loop should continue. If test is signle call the macro\n will not return anything. If the test is pair of expression and value the\n macro will return that value after finish."),if:re(new ze("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 At(t.cdr.car,{env:a,dynamic_scope:r,error:i})}else{return At(t.cdr.cdr.car,{env:a,dynamic_scope:r,error:i})}};if(t===Le){throw new Error("too few expressions for `if`")}var o=At(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 ze("let-env",function(n){var e=arguments.length>1&&arguments[1]!==F?arguments[1]:{};var t=e.dynamic_scope,r=e.error;St("let-env",n,"pair");var i=At(n.car,{env:this,dynamic_scope:t,error:r});return ne(i,function(e){if(!(e instanceof ft)){throw new Error("let-env: First argument need to be "+"environment")}return At(qe(Fe("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(wn(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(wn(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(wn(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(_n("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 ze("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=At(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 ze("ignore",function(e,n){var t=n.dynamic_scope,r=n.error;var i={env:this,error:r};if(t){i.dynamic_scope=this}At(new qe(new Fe("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(ze.defmacro("define",function(t,e){var r=this;if(t.car instanceof qe&&t.car.car instanceof Fe){var n=new qe(new Fe("define"),new qe(t.car.car,new qe(new qe(new Fe("lambda"),new qe(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 qe){i=At(i,e)}else if(i instanceof Fe){i=r.get(i)}St("define",t.car,"symbol");return ne(i,function(e){if(r.name===Xe.merge_env){r=r.parent}var n;if(t.cdr.cdr instanceof qe&&Rn.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=Wt(e);if(tn(e)||r!=="object"&&r!=="function"){var i=xt("set-obj!",kt(e),["object","function"]);throw new Error(i)}e=cn(e);n=n.valueOf();if(arguments.length===2){delete e[n]}else if($e(e)&&typeof t==="function"){e[n]=cn(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 vt.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 qe&&Rn.isString(l.cdr.car)&&l.cdr.cdr!==Le){d=l.cdr.car.valueOf()}function m(){var e;if(p){if(!(this instanceof ft)){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 qe){var r=e.car;var i=e.cdr;if(t(r)){r=n(r)}if(t(i)){i=n(i)}if(rn(r)||rn(i)){return Promise.all([r,i]).then(function(e){var n=zt(e,2),t=n[0],r=n[1];return new qe(t,r)})}else{return new qe(r,i)}}return e}function i(e,n){if(e instanceof qe){if(n!==Le){e.append(n)}}else{e=new qe(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 qe){if(e.cdr.cdr!==Le){if(e.cdr.car instanceof qe){var i=Le;return function n(t){if(t===Le){return i}return ne(At(t.car,{env:u,dynamic_scope:a,error:o}),function(e){i=new qe(e,i);return n(t.cdr)})}(e.cdr)}else{return e.cdr}}else{return At(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 qe){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 ht(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){St("clone",e,"pair");return e.clone()},"(clone list)\n\n Function return clone of the list."),append:re(function(e,n){St("append",e,["nil","pair"]);if(e instanceof qe){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){St("append!",e,["pair","nil"]);if(!this.get("list?")(e)){throw new Error("append!: Invalid argument, value is not a list")}if(tn(n)){return e}if(e===Le){if(n===Le){return Le}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){St("reverse",e,["array","pair","nil"]);if(e===Le){return Le}if(e instanceof qe){var n=this.get("list->array")(e).reverse();return this.get("array->list")(n)}else if(!(e instanceof Array)){throw new Error(xt("reverse",kt(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){St("nth",e,"number");St("nth",n,["array","pair"]);if(n instanceof qe){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){St("split",e,["regex","string"]);St("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){St("replace",e,["regex","string"]);St("replace",n,["string","function"]);St("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){St("match",e,["regex","string"]);St("match",n,"string");var t=n.match(e);return t?this.get("array->list")(t):Le},"(match pattern string)\n\n function return match object from JavaScript as list."),search:re(function(e,n){St("search",e,["regex","string"]);St("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 Be(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=qe.fromArray(n)}else{t=Le}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;St("set-special!",e,"string",1);St("set-special!",n,"symbol",2);Bt.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:qn,".":qn,unbind:re(cn,"(unbind fn)\n\n Function remove bidning from function so you can get props from it."),type:re(kt,"(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 Fe||e instanceof Rn){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 cn(e)},"(instanceof type obj)\n\n Function check of object is instance of object."),"prototype?":re($e,"(prototype? obj)\n\n Function check if value is JavaScript Object prototype."),"macro?":re(function(e){return e instanceof ze},"(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(kt(e)!=="number"){return false}if(e instanceof Un){return e.isFloat()}return Un.isFloat(e)},"(real? number)\n\n Function check if value is real number."),"number?":re(Un.isNumber,"(number? expression)\n\n Function check if value is a number"),"string?":re(function(e){return Rn.isString(e)},"(string? expression)\n\n Function check if value is a string."),"pair?":re(function(e){return e instanceof qe},"(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 tn(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 Fe},"(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!==Le&&e!==null&&!(e instanceof Pn)&&!(e instanceof RegExp)&&!(e instanceof Rn)&&!(e instanceof qe)&&!(e instanceof Un)&&Wt(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Function check if value is an plain object."),flatten:re(function(e){St("flatten",e,"pair");return e.flatten()},"(flatten list)\n\n Return shallow list from tree structure (pairs)."),"array->list":re(function(e){St("array->list",e,"array");return qe.fromArray(e)},"(array->list array)\n\n Function convert JavaScript array to LIPS list."),"tree->array":re(Pe("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":re(Pe("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 Un(0)}if(e instanceof qe){return Un(e.length())}if("length"in e){return Un(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;St("string->number",e,"string",1);St("string->number",n,"number",2);e=e.valueOf();n=n.valueOf();if(e.match(S)||e.match(w)){return I(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 A(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 ze("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(At(new qe(new Fe("begin"),a.cdr.car.cdr.cdr),r),function(e){i(e)})}};if(u){e.dynamic_scope=o}var n=At(a.car,e);if(rn(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){St("find",t,["regex","function"]);St("find",r,["pair","nil"]);if(tn(r)){return Le}var e=te("find",t);return ne(e(r.car),function(e){if(e&&e!==Le){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;St("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!==Le){a.push(r)}return n(++t)}if(t===i.length){return qe.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){St("range",e,"number");if(e instanceof Un){e=e.valueOf()}var n=new Array(e).fill(0).map(function(e,n){return Un(n)});return qe.fromArray(n,false)},"(range n)\n\n Function return list of n numbers from 0 to n - 1"),compose:re(On,"(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(Sn,"(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(An,"(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=Ue(i*(t<0||arguments.length<=t?F:arguments[t]))/(n+r)}return Un(n)},"(lcm n1 n2 ...)\n\n Function return the least common multiple of their arguments."),"odd?":re(En(function(e){return Un(e).isOdd()}),"(odd? number)\n\n Function check if number os odd."),"even?":re(En(function(e){return Un(e).isEven()}),"(even? number)\n\n Function check if number is even."),"*":re(In(function(e,n){return Un(e).mul(n)},Un(1)),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":re(In(function(e,n){return Un(e).add(n)},Un(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(He,"(eq? a b)\n\n Function compare two values if they are identical."),or:re(new ze("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=At(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 ze("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=At(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 Un(e).or(n)},"(& a b)\n\n Function calculate or bit operation."),"&":re(function(e,n){return Un(e).and(n)},"(& a b)\n\n Function calculate and bit operation."),"~":re(function(e){return Un(e).neg()},"(~ number)\n\n Function negate the value."),">>":re(function(e,n){return Un(e).shr(n)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":re(function(e,n){return Un(e).shl(n)},"(<< a b)\n\n Function left shit the value a by value b."),not:re(function(e){if(tn(e)){return true}return!e},"(not object)\n\n Function return negation of the argument.")},F,"global");var dt=vt.inherit("user-env");vt.set("**interaction-environment**",dt);(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(n){var t=e[n]?e[n]:n;vt.set(t,re(function(e){St(t,e,"number");if(e instanceof Un){return e[n]()}},"(".concat(t," number)\n\n Function calculate ").concat(t," of a number.")))})})();function mt(e){if(e.length===1){return e[0]}else{var n=[];var t=mt(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){if(t.length===1){t=t[0]}else{var a=t[t.length-1];t=t.slice(0,-1).join(", ")+" or "+a}}return"Expecting ".concat(t,", got ").concat(n).concat(i)}function St(e,n,t){var r=arguments.length>3&&arguments[3]!==F?arguments[3]:null;e=e.valueOf();var i=kt(n).toLowerCase();var a=false;if(t instanceof qe){t=t.toArray()}if(t instanceof Array){t=t.map(function(e){return e.valueOf()})}if(t instanceof Array){t=t.map(function(e){return e.valueOf().toLowerCase()});if(t.includes(i)){a=true}}else{t=t.valueOf().toLowerCase()}if(!a&&i!==t){throw new Error(xt(e,i,t,r))}}function Ot(e){var n=Wt(e);return["string","function"].includes(n)||e instanceof Fe||e instanceof Un||e instanceof RegExp}function kt(e){var n={pair:qe,symbol:Fe,character:Pn,values:pt,macro:ze,string:Rn,array:Array,"native-symbol":Symbol};if(Number.isNaN(e)){return"NaN "}if(e===Le){return"nil"}if(e===null){return"null"}if(e instanceof Xe){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||vt}else if(i===true){i=a=vt}else{i=i||vt}var r={env:i,dynamic_scope:a,error:o};var u;if(tn(n)){return n}if(n instanceof Fe){return i.get(n)}var c=n.car;var s=n.cdr;if(c instanceof qe){u=jt(At(c,r));if(rn(u)){return u.then(function(e){return At(new qe(e,n.cdr),r)})}else if(typeof u!=="function"){throw new Error(kt(u)+" "+i.get("repr")(u)+" is not a function while evaluating "+n.toString())}}if(c instanceof Fe){u=i.get(c);if(u instanceof Xe){return Ft(u,n,r)}else if(u instanceof ze){return It(u,s,r)}else if(typeof u!=="function"){if(u){var f="".concat(kt(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=Et(s,r);return ne(l,function(e){if(fn(u)&&(!ln(u)||pn(u))){e=e.map(on)}if(u.__lambda__&&!u.__prototype__||pn(u)){u=cn(u)}var n=e.slice();var t=(a||i).newFrame(u,n);var r=jt(u.apply(t,e));return ne(r,function(e){if(e instanceof qe){e.markCycles();return ht(e)}if(Number.isNaN(e)){return e}if(typeof e==="number"){return Un(e)}if(typeof e==="string"){return Rn(e)}return e},o)})}else if(n instanceof Fe){u=i.get(n);if(u==="undefined"){throw new Error("Unbound variable `"+n.name+"'")}return u}else if(n instanceof qe){u=c&&c.toString();throw new Error("".concat(kt(c)," ").concat(u," is not a function"))}else{return n}}catch(e){o&&o.call(i,e,n)}}function Nt(e,n,t){return Lt.apply(this,arguments)}function Lt(){Lt=Jt(Ut.mark(function e(t,r,i){var a,o,u,c;return Ut.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(i===true){r=i=r||dt}else if(r===true){r=i=dt}else{r=r||dt}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 At(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 Lt.apply(this,arguments)}function qt(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=Qt(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 Pt(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 Rt(e){this.url=e;var o=this.worker=Pt(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=zt(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=zt(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 Bt.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])}}qe.unDry=function(e){return new qe(e.car,e.cdr)};qe.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};Ne.prototype.toDry=function(){return{value:null}};Ne.unDry=function(){return Le};Fe.prototype.toDry=function(){return{value:{name:this.name}}};Fe.unDry=function(e){return new Fe(e.name)};function Ct(e){console.error(e.message||e);if(e.code){console.error(e.code.map(function(e,n){return"[".concat(n+1,"]: ").concat(e)}))}}function Tt(){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(Nt).then(n)["catch"](function(e){Ct(e);n()})}else{return Nt(e.innerHTML).then(n)["catch"](function(e){Ct(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,Tt)}var Mt=function(){var e=Rn("Thu, 17 Sep 2020 09:54:40 +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";ze.__className="macro";Xe.__className="syntax";ft.__className="environment";rt.__className="input-port";it.__className="output-port";at.__className="output-string-port";ot.__className="input-string-port";Un.__className="number";Pn.__className="character";Rn.__className="string";var Bt={version:"DEV",banner:Mt,date:"Thu, 17 Sep 2020 09:54:40 +0000",exec:Nt,parse:ee,tokenize:W,evaluate:At,Environment:ft,env:dt,Worker:Rt,Interpreter:st,balanced_parenthesis:qt,balancedParenthesis:qt,balanced:qt,Macro:ze,Syntax:Xe,Pair:qe,quote:ht,InputPort:rt,OutputPort:it,InputStringPort:ot,OutputStringPort:at,Formatter:ce,specials:K,repr:Re,nil:Le,LSymbol:Fe,LNumber:Un,LFloat:Hn,LComplex:Jn,LRational:Wn,LBigInteger:Qn,LCharacter:Pn,LString:Rn,rationalize:Vn};vt.set("lips",Bt);return Bt})})(); \ No newline at end of file diff --git a/src/lips.js b/src/lips.js index c196743dd..0d1fbbe95 100644 --- a/src/lips.js +++ b/src/lips.js @@ -2289,7 +2289,7 @@ // :: list of bindings from code that match the pattern // :: TODO detect cycles // ---------------------------------------------------------------------- - function extract_patterns(pattern, code, symbols, ellipsis_symbol) { + function extract_patterns(pattern, code, symbols, ellipsis_symbol, scope) { var bindings = { '...': { symbols: { }, // symbols ellipsis (x ...) @@ -2318,7 +2318,9 @@ } if (pattern instanceof LSymbol && symbols.includes(pattern.valueOf())) { - return LSymbol.is(code, pattern); + const ref = scope.ref(code); + const valid_ref = typeof ref === 'undefined' || ref === global_env; + return LSymbol.is(code, pattern) && valid_ref; } // pattern (a b (x ...)) and (x ...) match nil if (pattern instanceof Pair && @@ -4619,13 +4621,16 @@ this.env = user_env.inherit(name, obj); } // ------------------------------------------------------------------------- - Interpreter.prototype.exec = function(code, dynamic = false) { + Interpreter.prototype.exec = function(code, dynamic = false, env = null) { typecheck('Intepreter::exec', code, 'string', 1); typecheck('Intepreter::exec', dynamic, 'boolean', 2); // simple solution to overwrite this variable in each interpreter // before evaluation of user code global_env.set('**interaction-environment**', this.env); - return exec(code, this.env, dynamic ? this.env : false); + if (env === null) { + env = this.env; + } + return exec(code, env, dynamic ? env : false); }; // ------------------------------------------------------------------------- Interpreter.prototype.get = function(value) { @@ -5854,7 +5859,7 @@ while (rules !== nil) { var rule = rules.car.car; var expr = rules.car.cdr.car; - var bindings = extract_patterns(rule, code, symbols, ellipsis); + var bindings = extract_patterns(rule, code, symbols, ellipsis, this); if (bindings) { /* istanbul ignore next */ if (user_env.get('DEBUG', { throwError: false })) { diff --git a/tests/syntax.scm b/tests/syntax.scm index 784b52cd0..3583e0069 100644 --- a/tests/syntax.scm +++ b/tests/syntax.scm @@ -285,11 +285,10 @@ ((_ ((a ==> b) ...) . body) (let ((a b) ...) . body)))) - (t.is (let ((==> (lambda (x) (* x x)))) - (let+ ((a ==> 1) - (b ==> 2)) - (==> (+ a b)))) - 9))) + (t.is (let+ ((a ==> 1) + (b ==> 2)) + (+ a b)) + 3))) (test "syntax-rules: basic ellipsis (srfi-46)" (lambda (t) @@ -655,3 +654,13 @@ (+ x y)) 22))) +(test "syntax: scope + symbols" + (lambda (t) + + (define-syntax foo + (syntax-rules (++) + ((_ x ++ y) + (list x 1 1 y)))) + + (t.is (foo 1 ++ 2) (list 1 1 1 2)) + (t.is (to.throw (let ((++ 10)) (foo 1 ++ 2))) true)))