From 844723ae594dfa4c923b8cc4e3fc8bc8b19950f5 Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Sat, 22 Aug 2020 18:20:31 +0200 Subject: [PATCH] fix ellipsis tail from SRFI-46 #43 --- README.md | 2 +- dist/lips.js | 29 +++++++++++++++++++++++------ dist/lips.min.js | 4 ++-- src/lips.js | 18 ++++++++++++++++-- tests/syntax.scm | 11 +++++++++-- 5 files changed, 51 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index af3d281d0..0627ca5fd 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.3-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) -[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&f2a5a5623bf3a3610ae946274aeaa01cfd91754e)](https://travis-ci.org/jcubic/lips) +[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&b66acbb057dad33253820b9e649039581579dc31)](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/dist/lips.js b/dist/lips.js index c5324b8e6..ca433a9c4 100644 --- a/dist/lips.js +++ b/dist/lips.js @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Sat, 22 Aug 2020 14:06:34 +0000 + * build: Sat, 22 Aug 2020 16:08:48 +0000 */ (function () { 'use strict'; @@ -3886,9 +3886,26 @@ } if (pattern instanceof Pair && pattern.cdr instanceof Pair && LSymbol.is(pattern.cdr.car, ellipsis_symbol)) { - // pattern (... ???) + // pattern (... ???) - SRFI-46 if (pattern.cdr.cdr !== nil) { - throw new Error('syntax: invalid usage of ellipsis'); + if (pattern.cdr.cdr instanceof Pair) { + // if we have (x ... a b) we need to remove two from the end + var list_len = pattern.cdr.cdr.length(); + var code_len = code.length(); + var list = code; + + while (code_len - 1 > list_len) { + list = list.cdr; + code_len--; + } + + var rest = list.cdr; + list.cdr = nil; + + if (!traverse(pattern.cdr.cdr, rest, pattern_names, ellipsis)) { + return false; + } + } } if (pattern.car instanceof LSymbol) { @@ -10271,10 +10288,10 @@ var banner = function () { // Rollup tree-shaking is removing the variable if it's normal string because - // obviously 'Sat, 22 Aug 2020 14:06:34 +0000' == '{{' + 'DATE}}'; can be removed + // obviously 'Sat, 22 Aug 2020 16:08:48 +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('Sat, 22 Aug 2020 14:06:34 +0000').valueOf(); + var date = LString('Sat, 22 Aug 2020 16:08:48 +0000').valueOf(); var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date); @@ -10311,7 +10328,7 @@ var lips = { version: 'DEV', banner: banner, - date: 'Sat, 22 Aug 2020 14:06:34 +0000', + date: 'Sat, 22 Aug 2020 16:08:48 +0000', exec: exec, parse: parse, tokenize: tokenize, diff --git a/dist/lips.min.js b/dist/lips.min.js index d101d43ab..1a234c0d1 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: Sat, 22 Aug 2020 14:06:34 +0000 + * build: Sat, 22 Aug 2020 16:08:48 +0000 */ -(function(){"use strict";function e(e){throw new Error('"'+e+'" is read-only')}var Ct=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 Mt=n(function(r){function i(e,n,t){if(a()){r.exports=i=Reflect.construct}else{r.exports=i=function e(n,t,r){var i=[null];i.push.apply(i,t);var a=Function.bind.apply(n,i);var o=new a;if(r)u(o,r.prototype);return o}}return i.apply(null,arguments)}r.exports=i});var r=n(function(e){var n=function(o){var e=Object.prototype;var f=e.hasOwnProperty;var c;var n=typeof Symbol==="function"?Symbol:{};var i=n.iterator||"@@iterator";var t=n.asyncIterator||"@@asyncIterator";var r=n.toStringTag||"@@toStringTag";function u(e,n,t,r){var i=n&&n.prototype instanceof s?n:s;var a=Object.create(i.prototype);var o=new F(r||[]);a._invoke=O(e,t,o);return a}o.wrap=u;function l(e,n,t){try{return{type:"normal",arg:e.call(n,t)}}catch(e){return{type:"throw",arg:e}}}var p="suspendedStart";var h="suspendedYield";var v="executing";var d="completed";var m={};function s(){}function a(){}function y(){}var g={};g[i]=function(){return this};var b=Object.getPrototypeOf;var w=b&&b(b(A([])));if(w&&w!==e&&f.call(w,i)){g=w}var _=y.prototype=s.prototype=Object.create(g);a.prototype=_.constructor=y;y.constructor=a;y[r]=a.displayName="GeneratorFunction";function x(e){["next","throw","return"].forEach(function(n){e[n]=function(e){return this._invoke(n,e)}})}o.isGeneratorFunction=function(e){var n=typeof e==="function"&&e.constructor;return n?n===a||(n.displayName||n.name)==="GeneratorFunction":false};o.mark=function(e){if(Object.setPrototypeOf){Object.setPrototypeOf(e,y)}else{e.__proto__=y;if(!(r in e)){e[r]="GeneratorFunction"}}e.prototype=Object.create(_);return e};o.awrap=function(e){return{__await:e}};function S(u,c){function s(e,n,t,r){var i=l(u[e],u,n);if(i.type==="throw"){r(i.arg)}else{var a=i.arg;var o=a.value;if(o&&typeof o==="object"&&f.call(o,"__await")){return c.resolve(o.__await).then(function(e){s("next",e,t,r)},function(e){s("throw",e,t,r)})}return c.resolve(o).then(function(e){a.value=e;t(a)},function(e){return s("throw",e,t,r)})}}var n;function e(t,r){function e(){return new c(function(e,n){s(t,r,e,n)})}return n=n?n.then(e,e):e()}this._invoke=e}x(S.prototype);S.prototype[t]=function(){return this};o.AsyncIterator=S;o.async=function(e,n,t,r,i){if(i===void 0)i=Promise;var a=new S(u(e,n,t,r),i);return o.isGeneratorFunction(n)?a:a.next().then(function(e){return e.done?e.value:a.next()})};function O(o,u,c){var s=p;return function e(n,t){if(s===v){throw new Error("Generator is already running")}if(s===d){if(n==="throw"){throw t}return I()}c.method=n;c.arg=t;while(true){var r=c.delegate;if(r){var i=k(r,c);if(i){if(i===m)continue;return i}}if(c.method==="next"){c.sent=c._sent=c.arg}else if(c.method==="throw"){if(s===p){s=d;throw c.arg}c.dispatchException(c.arg)}else if(c.method==="return"){c.abrupt("return",c.arg)}s=v;var a=l(o,u,c);if(a.type==="normal"){s=c.done?d:h;if(a.arg===m){continue}return{value:a.arg,done:c.done}}else if(a.type==="throw"){s=d;c.method="throw";c.arg=a.arg}}}}function k(e,n){var t=e.iterator[n.method];if(t===c){n.delegate=null;if(n.method==="throw"){if(e.iterator["return"]){n.method="return";n.arg=c;k(e,n);if(n.method==="throw"){return m}}n.method="throw";n.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var r=l(t,e.iterator,n.arg);if(r.type==="throw"){n.method="throw";n.arg=r.arg;n.delegate=null;return m}var i=r.arg;if(!i){n.method="throw";n.arg=new TypeError("iterator result is not an object");n.delegate=null;return m}if(i.done){n[e.resultName]=i.value;n.next=e.nextLoc;if(n.method!=="return"){n.method="next";n.arg=c}}else{return i}n.delegate=null;return m}x(_);_[r]="Generator";_[i]=function(){return this};_.toString=function(){return"[object Generator]"};function E(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 j(e){var n=e.completion||{};n.type="normal";delete n.arg;e.completion=n}function F(e){this.tryEntries=[{tryLoc:"root"}];e.forEach(E,this);this.reset(true)}o.keys=function(t){var r=[];for(var e in t){r.push(e)}r.reverse();return function e(){while(r.length){var n=r.pop();if(n in t){e.value=n;e.done=false;return e}}e.done=true;return e}};function A(n){if(n){var e=n[i];if(e){return e.call(n)}if(typeof n.next==="function"){return n}if(!isNaN(n.length)){var t=-1,r=function e(){while(++t=0;--n){var i=this.tryEntries[n];var a=i.completion;if(i.tryLoc==="root"){return e("end")}if(i.tryLoc<=this.prev){var o=f.call(i,"catchLoc");var u=f.call(i,"finallyLoc");if(o&&u){if(this.prev=0;--t){var r=this.tryEntries[t];if(r.tryLoc<=this.prev&&f.call(r,"finallyLoc")&&this.prev=0;--n){var t=this.tryEntries[n];if(t.finallyLoc===e){this.complete(t.completion,t.afterLoc);j(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;j(t)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,t){this.delegate={iterator:A(e),resultName:n,nextLoc:t};if(this.method==="next"){this.arg=c}return m}};return o}(e.exports);try{regeneratorRuntime=n}catch(e){Function("r","regeneratorRuntime = r")(n)}});var Tt=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 Bt=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 E=k;function j(e,n){if(e==null)return{};var t=E(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 Ht=j;function F(e,n){if(typeof Symbol==="undefined"||!(Symbol.iterator in Object(e)))return;var t=[];var r=true;var i=false;var a=undefined;try{for(var o=e[Symbol.iterator](),u;!(r=(u=o.next()).done);r=true){t.push(u.value);if(n&&t.length===n)break}}catch(e){i=true;a=e}finally{try{if(!r&&o["return"]!=null)o["return"]()}finally{if(i)throw a}}return t}var A=F;function I(e,n){return s(e)||A(e,n)||d(e,n)||y()}var Jt=I;var Yt=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 Gt(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=j(e);var r=t.number.split("/");var i=Yn({num:Tn([r[0],t.radix||n]),denom:Tn([r[1],t.radix||n])});if(t.inexact){return i.valueOf()}else{return i}}function I(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:10;var t=j(e);if(t.inexact){return $n(parseInt(t.number,t.radix||n))}return Tn([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 In(t)}}function L(e){var i=arguments.length>1&&arguments[1]!==F?arguments[1]:10;function n(e){var n;if(e==="+"){n=Tn(1)}else if(e==="-"){n=Tn(-1)}else if(e.match(x)){n=Tn([e,i])}else if(e.match(S)){var t=e.split("/");n=Yn({num:Tn([t[0],i]),denom:Tn([t[1],i])})}else if(e.match(c)){var r=$n(parseFloat(e));if(a.exact){return r.toRational()}return r}else{throw new Error("Internal Parser Error")}if(a.inexact){return $n(n.valueOf())}return n}var a=j(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 $n){o=$n(0)}else{o=Tn(0)}return Bn({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 Tn(a).mul(u)}}}t=$n(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 Nn(JSON.parse(e))}catch(e){throw new Error("Invalid string literal")}}function M(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var t={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,n){return String.fromCharCode(parseInt("0"+n,16))}).replace(/\\(.)/g,function(e,n){return t[n]||n})}return new Oe(e)}function T(e){var n=e.match(a);if(n){return new RegExp(n[1],n[2])}else if(e.match(/^"/)){return C(e)}else if(e.match(m)){return N(e)}else if(e.match(w)){return A(e)}else if(e.match(b)){return L(e)}else if(e.match(_)){return I(e)}else if(e.match(c)){return R(e)}else if(e==="nil"){return Fe}else if(["true","#t"].includes(e)){return true}else if(["false","#f"].includes(e)){return false}else{return M(e)}}function B(e){return!(["(",")"].includes(e)||e.match(a)||e.match(/^"[\s\S]+"$/)||e.match(_)||e.match(c)||e.match(b)||e.match(w)||["#t","#f","nil","true","false"].includes(e))}var $=/("(?:\\[\S\s]|[^"])*"?|\/(?! )[^\n\/\\]*(?:\\[\S\s][^\n\/\\]*)*\/[gimy]*(?=[\s[\]()]|$)|\|[^|\s\n]+\||#;|;.*|#\|(?!\|#)[\s\S]*\|#)/g;var D=/"(?:\\[\S\s]|[^"])*"?/g;var U=[r,n,i].map(y).join("|");function H(){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 J(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=H();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=J(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=Ht(e,["token"]);if(n.match(/^"[\s\S]+"$/)&&n.match(/\n/)){var r=new RegExp("^ {1,"+(e.col+1)+"}","mg");n=n.replace(r,"")}return Vt({token:n},t)}function W(e,n){var t=arguments.length>2&&arguments[2]!==F?arguments[2]:z;if(e instanceof Nn){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 Oe){c[c.length-1].push(e)}else if(c[c.length-1]instanceof Ae){if(c[c.length-1].cdr instanceof Ae){c[c.length-1]=new Ae(c[c.length-1],Ae.fromArray(e))}else{c[c.length-1].cdr=Ae.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]=Ae.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=Fe}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(Fe)}else if(i instanceof Array&&i[0]===g){var a;(a=n).push.apply(a,Dt(i.slice(1)))}else{n.push(i)}}else if(n instanceof Ae){if(i.length===0){n.append(Fe)}else{n.append(Ae.fromArray(i))}}if(d.length){m=d.pop();while(m.length){_();m.pop()}}else{_()}}if(h===0&&c.length){s.push(c.pop())}}else{v=false;var o=T(e);if(f){while(y--){c[c.length-1].push(o);o=c.pop()}d.pop();y=0;f=false}else if(o instanceof Oe&&p.includes(o.name)){o.literal=true}n=c[c.length-1];if(n instanceof Ae){var u=n;while(true){if(u.cdr===Fe){if(o instanceof Array){u.cdr=Ae.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 Ae.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(Ze);if(r.length){return ne(Promise.all(r),n,t)}return n(e)}if(Ze(e)){var i=e.then(n);if(t===null){return i}else{return i["catch"](t)}}return n(e)}function te(e,n){if(n instanceof RegExp){return function(e){return String(e).match(n)}}else if(typeof n!=="function"){throw new Error("".concat(e," argument need to be a function or RegExp"))}else{return n}}function re(e,n,t){if(n){if(t){e.__doc__=n}else{e.__doc__=ie(n)}}return e}function ie(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function ae(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:1;var t=e.length;if(n<=0){throw Error("previousSexp: Invlaid argument sexp = ".concat(n))}e:while(n--&&t>=0){var r=1;while(r>0){var i=e[--t];if(!i){break e}if(i==="("||i.token==="("){r--}else if(i===")"||i.token===")"){r++}}t--}return e.slice(t+1)}function oe(e){if(!e||!e.length){return 0}var n=e.length;if(e[n-1].token==="\n"){return 0}while(--n){if(e[n].token==="\n"){var t=(e[n+1]||{}).token;if(t){return t.length}}}return 0}function ue(e,n){return f(e,n)===n.length;function f(t,r){function e(){return a>0&&u>0&&t[a-1]===r[u-1]&&t[a+1]===r[u]}function n(){return t[a]===Symbol["for"]("symbol")&&!B(r[u])}function i(){var e=t[a+1];var n=r[u+1];if(e!==F&&n!==F){return f([e],[n])}}var a=0;var o={};for(var u=0;u0){continue}}else if(n()){return-1}}else if(t[a]instanceof Array){var s=f(t[a],r.slice(u));if(s===-1||s+u>r.length){return-1}u+=s-1;a++;continue}else{return-1}a++}if(t.length!==a){return-1}return r.length}}function ce(e){this._code=e.replace(/\r/g,"")}ce.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?define/,/^(?:#:)?lambda/,/^(?:#:)?let*/,/^(?:#:)?(let|letrec)(-syntax)?$/,/(?:#:)?let-env/,/(?:#:)?syntax-rules/,/(?:#:)?try/,/(?:#:)?catch/,/(?:#:)?while/],shift:{1:["&","#"]}}};ce.match=ue;ce.prototype._options=function e(n){var t=ce.defaults;if(typeof n==="undefined"){return Object.assign({},t)}var r=n&&n.exceptions||{};var i=r.specials||[];var a=r.shift||{1:[]};return Vt(Vt(Vt({},t),n),{},{exceptions:{specials:[].concat(Dt(t.exceptions.specials),Dt(i)),shift:Vt(Vt({},a),{},{1:[].concat(Dt(t.exceptions.shift[1]),Dt(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=Gt(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()&&At(a)){return r.offset+a[0].col}else if(a.length===1){return r.offset+a[0].col+1}else{var u=-1;if(o){var c=ce.exception_shift(o.token,r);if(c!==-1){u=c}}if(u===-1){u=ce.exception_shift(a[1].token,r)}if(u!==-1){return r.offset+a[0].col+u}else if(a[0].line3&&a[1].line===a[3].line){if(a[1].token==="("||a[1].token==="["){return r.offset+a[1].col}return r.offset+a[3].col}else if(a[0].line===a[1].line){return r.offset+r.indent+a[0].col}else{var s=a.slice(2);for(var f=0;f")};se.prototype.match=function(e){return e.match(this.pattern)};function fe(e,n){this.pattern=e;this.flag=n}fe.prototype.toString=function(){return"#")};ce.Pattern=fe;ce.Ahead=se;var le=/[[(]/;var pe=/[\])]/;var he=/[^()[\]]/;var ve=new se(/[^)\]]/);var de=Symbol["for"]("*");var me=new fe([le,de,pe],"+");var ye=new fe([Symbol["for"]("symbol")],"?");var ge=new fe([le,Symbol["for"]("symbol"),de,pe],"+");var be=_e("define","lambda","syntax-rules");var we=/^(?:#:)?(let|let\*|letrec|let-env)(:?-syntax)?$/;function _e(){for(var e=arguments.length,n=new Array(e),t=0;t0&&arguments[0]!==F?arguments[0]:null;if(e instanceof Oe){e=e.valueOf()}if(ke(e)){return Oe(e)}if(e!==null){return new Oe(Symbol("#:".concat(e)))}n++;return new Oe(Symbol("#:g".concat(n)))}}();function je(){}je.prototype.toString=je.prototype.toJSON=function(){return"()"};je.prototype.valueOf=function(){return F};je.prototype.append=function(e){return new Ae(e,Fe)};je.prototype.toArray=function(){return[]};var Fe=new je;function Ae(e,n){if(typeof this!=="undefined"&&this.constructor!==Ae||typeof this==="undefined"){return new Ae(e,n)}this.car=e;this.cdr=n}function Ie(a,o){return function e(n){bt(a,n,["pair","nil"]);if(n===Fe){return[]}var t=[];var r=n;while(true){if(r instanceof Ae){if(r.haveCycles("cdr")){break}var i=r.car;if(o&&i instanceof Ae){i=this.get(a).call(this,i)}t.push(i);r=r.cdr}else{break}}return t}}Ae.prototype.flatten=function(){return Ae.fromArray(xe(this.toArray()))};Ae.prototype.length=function(){var e=0;var n=this;while(true){if(!n||n===Fe||!(n instanceof Ae)||n.haveCycles("cdr")){break}e++;n=n.cdr}return e};Ae.prototype.clone=function(){var t=new Map;function r(e){if(e instanceof Ae){if(t.has(e)){return t.get(e)}var n=new Ae;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)};Ae.prototype.lastPair=function(){var e=this;while(true){if(e.cdr===Fe){return e}e=e.cdr}};Ae.prototype.toArray=function(){var e=[];if(this.car instanceof Ae){e.push(this.car.toArray())}else{e.push(this.car.valueOf())}if(this.cdr instanceof Ae){e=e.concat(this.cdr.toArray())}return e};Ae.fromArray=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:true;if(e instanceof Ae){return e}if(n===false){var t=Fe;for(var r=e.length;r--;){t=new Ae(e[r],t)}return t}if(e.length&&!(e instanceof Array)){e=Dt(e)}if(e.length===0){return Fe}else{var i;if(e[0]instanceof Array){i=Ae.fromArray(e[0])}else{i=e[0]}if(typeof i==="string"){i=Nn(i)}if(e.length===1){return new Ae(i,Fe)}else{return new Ae(i,Ae.fromArray(e.slice(1)))}}};Ae.prototype.toObject=function(){var e=arguments.length>0&&arguments[0]!==F?arguments[0]:false;var n=this;var t={};while(true){if(n instanceof Ae&&n.car instanceof Ae){var r=n.car;var i=r.car;if(i instanceof Oe){i=i.name}if(i instanceof String){i=i.valueOf()}var a=r.cdr;if(a instanceof Ae){a=a.toObject(e)}if(a instanceof Tn||a instanceof Nn||a instanceof In){if(!e){a=a.valueOf()}}t[i]=a;n=n.cdr}else{break}}return t};Ae.fromPairs=function(e){return e.reduce(function(e,n){return new Ae(new Ae(new Oe(n[0]),n[1]),e)},Fe)};Ae.fromObject=function(n){var e=Object.keys(n).map(function(e){return[e,n[e]]});return Ae.fromPairs(e)};Ae.prototype.reduce=function(e){var n=this;var t=Fe;while(true){if(n!==Fe){t=e(t,n.car);n=n.cdr}else{break}}return t};Ae.prototype.reverse=function(){if(this.haveCycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var n=Fe;while(e!==Fe){var t=e.cdr;e.cdr=n;n=e;e=t}return n};Ae.prototype.transform=function(r){function i(e){if(e instanceof Ae){if(e.replace){delete e.replace;return e}var n=r(e.car);if(n instanceof Ae){n=i(n)}var t=r(e.cdr);if(t instanceof Ae){t=i(t)}return new Ae(n,t)}return e}return i(this)};Ae.prototype.map=function(e){if(typeof this.car!=="undefined"){return new Ae(e(this.car),this.cdr===Fe?Fe:this.cdr.map(e))}else{return Fe}};var Ne=new Map;function Le(t){var e=t.constructor||Object;var r=Yt(t)==="object"&&e===Object;var i;if(Ne.has(e)){i=Ne.get(e)}else{Ne.forEach(function(e,n){if(t instanceof n&&(n===Object&&r||n!==Object)){i=e}})}return i}var qe=new Map;[[Number.NEGATIVE_INFINITY,"-inf.0"],[Number.POSITIVE_INFINITY,"+inf.0"],[true,"#t"],[false,"#f"],[null,"null"],[F,"#"]].forEach(function(e){var n=Jt(e,2),t=n[0],r=n[1];qe.set(t,r)});function Pe(t){if(t&&Yt(t)==="object"){var r={};var e=Object.getOwnPropertySymbols(t);e.forEach(function(e){var n=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");r[n]=Re(t[e])});var n=Object.getOwnPropertyNames(t);n.forEach(function(e){var n=t[e];if(Yt(n)==="object"&&n.constructor===Object){r[e]=Pe(n)}else{r[e]=Re(n)}});return r}return t}function Re(e,n,t){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(qe.has(e)){return qe.get(e)}if(e instanceof Ae){if(!t){e.markCycles()}return e.toString(n)}if(Number.isNaN(e)){return"+nan.0"}var r=[RegExp,je,Oe,Tn,In,ct];for(var i=0,a=r;i"}if(dn(e.toString)){return"#"}else{return e.toString()}}if(e instanceof Nn){e=e.toString()}if(e===null||typeof e==="string"&&n){return JSON.stringify(e)}if(Yt(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(Ce(e)){return"#"}var s=Le(e);if(s){if(typeof s==="function"){return s(e,n)}else{throw new Error("toString: Invalid repr value")}}c=u.name}if(_t(e)==="instance"&&!dn(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 Ce(e){return e&&Yt(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}Ae.prototype.markCycles=function(){Me(this);return this};Ae.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 Me(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 Ae){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 Ae){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 Ae){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")})}Ae.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=Re(this.car,e,true)}if(r!==F){t.push(r)}if(this.cdr instanceof Ae){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!==Fe){t=t.concat([" . ",Re(this.cdr,e,true)])}if(!n||this.ref){t.push(")")}return t.join("")};Ae.prototype.set=function(e,n){this[e]=n;if(n instanceof Ae){this.markCycles()}};Ae.prototype.append=function(e){if(e instanceof Array){return this.append(Ae.fromArray(e))}var n=this;if(n.car===F){if(e instanceof Ae){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(e!==Fe){while(true){if(n instanceof Ae&&n.cdr!==Fe){n=n.cdr}else{break}}n.cdr=e}return this};function Te(e){return e<0?-e:e}function Be(e,n){var t=$t(n),r=t[0],i=t.slice(1);while(i.length>0){var a=i,o=Jt(a,1),u=o[0];if(!e(r,u)){return false}var c=i;var s=$t(c);r=s[0];i=s.slice(1)}return true}function $e(e,n){if(typeof e==="function"&&typeof n==="function"){return rn(e)===rn(n)}else if(e instanceof Tn&&n instanceof Tn){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=Tn(e);n=Tn(n);return e.type===n.type&&e.cmp(n)===0}else if(e instanceof In&&n instanceof In){return e["char"]===n["char"]}else if(e instanceof Oe&&n instanceof Oe){return e.name===n.name}else{return e===n}}function De(e,n){if(_t(e)!==_t(n)){return false}if(!Ue(e)){return false}if(e instanceof RegExp){return e.source===n.source}if(e instanceof Nn){return e.valueOf()===n.valueOf()}return $e(e,n)}function Ue(e){return e instanceof Oe||Nn.isString(e)||e instanceof In||e instanceof Tn||e===true||e===false}var He=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function Je(e,n,t,r){if(typeof this!=="undefined"&&this.constructor!==Je||typeof this==="undefined"){return new Je(e,n)}bt("Macro",e,"string",1);bt("Macro",n,"function",2);if(t){if(r){this.__doc__=t}else{this.__doc__=ie(t)}}this.name=e;this.fn=n}Je.defmacro=function(e,n,t,r){var i=new Je(e,n,t,r);i.defmacro=true;return i};Je.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};Je.prototype.toString=function(){return"#"};var Ye="define-macro";var Ge=-1e4;function Ve(a){return function(){var t=Bt(Tt.mark(function e(t,v){var r,d,i;return Tt.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:i=function e(){i=Bt(Tt.mark(function e(t,r,i){var a,o,u,c,s,f,l,p,h;return Tt.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(!(t instanceof Ae&&t.car instanceof Oe)){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 Je&&a.defmacro)){n.next=24;break}o=a instanceof ze?t:t.cdr;n.next=8;return a.invoke(o,v,true);case 8:u=n.sent;if(!(a instanceof ze)){n.next=17;break}c=u,s=c.expr,f=c.scope;if(!(s instanceof Ae)){n.next=16;break}if(!(r!==-1&&r<=1||r"};ze.className="syntax";function We(e,n,d,m){var y={"...":{symbols:{},lists:[]}};function g(e){if(lt.get("DEBUG",{throwError:false})){console.log(e)}}g(d);function b(e,n){var t=arguments.length>2&&arguments[2]!==F?arguments[2]:[];var r=arguments.length>3&&arguments[3]!==F?arguments[3]:false;g({code:n&&Re(n,true),pattern:e&&Re(e,true)});if(Ue(e)&&!(e instanceof Oe)){return De(e,n)}if(e instanceof Oe&&d.includes(e.valueOf())){return Oe.is(n,e)}if(e instanceof Ae&&e.car instanceof Ae&&e.car.cdr instanceof Ae&&Oe.is(e.car.cdr.car,m)){g(">> 0");if(n===Fe){g({pattern:e.toString()});if(e.car.car instanceof Oe){if(e.car.cdr instanceof Ae&&Oe.is(e.car.cdr.car,m)){var i=e.car.car.valueOf();var a=e.lastPair();if(Oe.is(a.car,m)){y["..."].symbols[i]=null;return true}else{return false}}var o=e.car.car.valueOf();if(y["..."].symbols[o]){throw new Error("syntax: named ellipsis can only "+"appear onces")}y["..."].symbols[o]=n}}}if(e instanceof Ae&&e.cdr instanceof Ae&&Oe.is(e.cdr.car,m)){if(e.cdr.cdr!==Fe){throw new Error("syntax: invalid usage of ellipsis")}if(e.car instanceof Oe){var u=e.car.name;if(y["..."].symbols[u]&&!t.includes(u)&&!r){throw new Error("syntax: named ellipsis can only appear onces")}g(">> 1");if(n===Fe){g(">> 2");if(r){g("NIL");y["..."].symbols[u]=Fe}else{g("NULL");y["..."].symbols[u]=null}}else if(n instanceof Ae&&(n.car instanceof Ae||n.car===Fe)){g(">> 3 "+r);if(r){if(y["..."].symbols[u]){var c=y["..."].symbols[u];y["..."].symbols[u]=c.append(new Ae(n,Fe))}else{y["..."].symbols[u]=new Ae(n,Fe)}}else{g(">> 4");y["..."].symbols[u]=new Ae(n,Fe)}}else{g(">> 6");if(n instanceof Ae){g(">> 7 "+r);t.push(u);if(!y["..."].symbols[u]){y["..."].symbols[u]=new Ae(n,Fe)}else{var s=y["..."].symbols[u];y["..."].symbols[u]=s.append(new Ae(n,Fe))}g({IIIIII:y["..."].symbols[u].toString()})}else{g(">> 8");return false}}return true}else if(e.car instanceof Ae){var f=Dt(t);if(n===Fe){g(">> 9");y["..."].lists.push(Fe);return true}g(">> 10");var l=n;while(l instanceof Ae){if(!b(e.car,l.car,f,true)){return false}l=l.cdr}return true}return false}if(e instanceof Oe){if(Oe.is(e,m)){throw new Error("syntax: invalid usage of ellipsis")}g(">> 11");var p=e.name;if(d.includes(p)){return true}g({name:p,ellipsis:r});if(r){y["..."].symbols[p]=y["..."].symbols[p]||[];y["..."].symbols[p].push(n)}if(!y[p]){y[p]=n}return true}if(e instanceof Ae&&n instanceof Ae){g(">> 12");g({a:12,code:n&&n.toString(),pattern:e.toString()});if(n.cdr===Fe){var h=e.car instanceof Oe&&e.cdr instanceof Oe;if(h){g(">> 12 | 1");var v=e.cdr.valueOf();if(!y[v]){y[v]=Fe}v=e.car.valueOf();if(!y[v]){y[v]=n.car}return true}}g("recur");if(b(e.car,n.car,t,r)&&b(e.cdr,n.cdr,t,r)){return true}}else if(e===Fe&&(n===Fe||n===F)){return true}else if(e.car instanceof Ae&&Oe.is(e.car.car,m)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(b(e,n)){return y}}function Qe(e,i){function a(n){if(n instanceof Ae){if(!i.length){return n}var e=a(n.car);var t=a(n.cdr);return new Ae(e,t)}else if(n instanceof Oe){var r=i.find(function(e){return e.gensym===n});if(r){return Oe(r.name)}return n}else{return n}}return a(e)}function Ke(){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 Oe||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=Yt(n);if(["string","symbol"].includes(t)&&n in w){return w[n]}if(i.includes(n)){return Oe(n)}return u(n)}function S(e){if(lt.get("DEBUG",{throwError:false})){console.log(e)}}function u(e){if(!o[e]){var n=r.get(e,{throwError:false});var t=Ee(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 Oe){var a=e.valueOf();S("[t 1");if(n[a]){if(n[a]instanceof Ae){var o=n[a],u=o.car,c=o.cdr;if(i){var s=u.car,f=u.cdr;if(f!==Fe){r(a,new Ae(f,Fe))}return s}if(c!==Fe){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 Ae){if(e.car instanceof Oe&&e.cdr instanceof Ae&&Oe.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 Ae){S("[t 2 Pair "+i);S({______:p.toString()});var h=p.car,v=p.cdr;if(i){if(v!==Fe){r(l,v)}return h}else{if(h.cdr!==Fe){r(l,new Ae(h.cdr,v))}return h.car}}else if(p instanceof Array){S("[t 2 Array "+i);if(i){r(l,p.slice(1));return Ae.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 Ae(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,Dt(r.map(function(e){return n[e]})))}return e.length&&e.every(function(e){if(e===null){return!t}return e instanceof Ae||e===Fe||e instanceof Array&&e.length})}function E(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function j(i){var e=arguments.length>1&&arguments[1]!==F?arguments[1]:{},n=e.disabled;S(">> "+i.toString());if(i instanceof Ae){if(!n&&i.car instanceof Ae&&Oe.is(i.car.car,_)){return j(i.car.cdr,{disabled:true})}if(i.cdr instanceof Ae&&Oe.is(i.cdr.car,_)&&!n){S(">> 1");var t=w["..."].symbols;var r=E(t);if(i.car instanceof Ae){if(w["..."].lists[0]===Fe){return Fe}S(">> 2");var a;if(r.length){S(">> 2 (a)");var o=Vt({},t);a=Fe;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 Ae(t,a)}o=r};while(true){var c=u();if(c==="break")break}if(a!==Fe){a=a.reverse()}return a}else{S(">> 3");var s=O(i.car,t,{nested:true});if(s){return new Ae(s,Fe)}return Fe}}else if(i.car instanceof Oe){S(">> 4");var f=i.car.name;var l=Ut({},f,t[f]);var p=t[f]===null;var h=Fe;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 Ae(t,h)}l=r};while(true){var d=v();if(d==="break")break}if(h!==Fe){h=h.reverse()}if(i.cdr instanceof Ae){if(i.cdr.cdr instanceof Ae||i.cdr.cdr instanceof Oe){var m=j(i.cdr.cdr,{disabled:n});if(p){return m}h.append(m)}}return h}}var y=j(i.car,{disabled:n});var g=j(i.cdr,{disabled:n});S({a:true,head:y&&y.toString(),rest:g&&g.toString()});return new Ae(y,g)}if(i instanceof Oe){if(n&&Oe.is(i,_)){return i}var b=x(i);if(typeof b!=="undefined"){return b}}return i}return j(n,{})}function Xe(e){return typeof e==="undefined"||e===Fe||e===null}function Ze(e){return e instanceof Promise||e&&typeof e!=="undefined"&&typeof e.then==="function"}function en(e){switch(Yt(e)){case"string":return Nn(e);case"number":if(!Number.isNaN(e)){return Tn(e)}}return e}function nn(e){if(e&&e.valueOf){return e.valueOf()}return e}function tn(e,n){if(e instanceof Ae){e.markCycles();return st(e)}if(typeof e==="function"){if(n){return an(e,n)}}return en(e)}function rn(e){if(on(e)){return e[fn]}return e}function an(n,e){if(n[Symbol["for"]("__bound__")]){return n}var t=n.bind(e);var r=Object.getOwnPropertyNames(n).filter(pn);r.forEach(function(e){try{t[e]=n[e]}catch(e){}});hn(t,"__fn__",n);hn(t,"__context__",e);hn(t,"__bound__",true);if(dn(n)){hn(t,"__native__",true)}t.valueOf=function(){return n};return t}function on(e){return!!(typeof e==="function"&&e[fn])}function un(e){if(typeof e==="function"){var n=e[sn];if(n&&(n===Rt||n.constructor&&n.constructor.__className)){return true}}return false}function cn(e){function n(e){return e instanceof Zn||e instanceof et}if(typeof e==="function"){if(n(e)){return true}if(n(e[sn])){return true}}return false}var sn=Symbol["for"]("__context__");var fn=Symbol["for"]("__fn__");var ln=["name","length","caller","callee","arguments","prototype"];function pn(e){return!ln.includes(e)}function hn(e,n,t){Object.defineProperty(e,Symbol["for"](n),{get:function e(){return t},set:function e(){},configurable:false,enumerable:false})}function vn(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 dn(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 mn(e){var d;switch(e){case Symbol["for"]("letrec"):d="letrec";break;case Symbol["for"]("let"):d="let";break;case Symbol["for"]("let*"):d="let*";break;default:throw new Error("Invalid let_macro value")}return Je.defmacro(d,function(n,e){var o=e.dynamic_scope,u=e.error,t=e.macro_expand;var c;if(n.car instanceof Oe){if(!(n.cdr.car instanceof Ae||n.cdr.car===Fe)){throw new Error("let require list of pairs")}var r;if(n.cdr.car===Fe){c=Fe;r=Fe}else{r=n.cdr.car.map(function(e){return e.car});c=n.cdr.car.map(function(e){return e.cdr.car})}return Ae.fromArray([Oe("letrec"),[[n.car,Ae(Oe("lambda"),Ae(r,n.cdr.cdr))]],Ae(n.car,c)])}else if(t){return}var s=this;c=this.get("list->array")(n.car);var f=s.inherit(d);var l,p;if(d==="let*"){p=f}else if(d==="let"){l=[]}var h=0;function v(){var e=new Ae(new Oe("begin"),n.cdr);return Et(e,{env:f,dynamic_scope:o,error:u})}return function n(){var t=c[h++];function r(e,n){if(typeof n==="undefined"){f.set(e,Fe)}else{f.set(e,n)}}if(o){o=d==="let*"?f:s}if(!t){if(l&&l.length){var e=l.map(function(e){return e.value});var i=e.filter(Ze);if(i.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 Ae){o.push(Et(a.car,{env:i,dynamic_scope:t,error:r}));a=a.cdr}var u=o.filter(Ze).length;if(u){return Promise.all(o).then(c.bind(this))}else{return c.call(this,o)}})}function gn(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 jn(r,i){bt("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 Tn){return e}if(typeof this!=="undefined"&&!(this instanceof Tn)||typeof this==="undefined"){return new Tn(e,n)}if(typeof e==="undefined"){throw new Error("Invlaid LNumber constructor call")}var t=Tn.getType(e);if(Tn.types[t]){return Tn.types[t](e,n)}var r=e instanceof Array&&Nn.isString(e[0])&&Tn.isNumber(e[1]);if(e instanceof Tn){return Tn(e.value)}if(!Tn.isNumber(e)&&!r){throw new Error("You can't create LNumber from ".concat(_t(e)))}if(e===null){e=0}var i;if(r){var a=e,o=Jt(a,2),u=o[0],c=o[1];if(u instanceof Nn){u=u.valueOf()}if(c instanceof Tn){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=Dt(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 Gn(i,true)}else if(typeof h!=="undefined"&&!(e instanceof h)){if(e instanceof Array){return Gn(Mt(h,Dt(e)))}return Gn(new h(e))}else if(r){this.value=parseInt(u,c)}else{this.value=e}}Tn.types={float:function e(n){var t=arguments.length>1&&arguments[1]!==F?arguments[1]:false;return new $n(n,t)},complex:function e(n){var t=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(!Tn.isComplex(n)){n={im:0,re:n}}return new Bn(n,t)},rational:function e(n){var t=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(!Tn.isRational(n)){n={num:n,denom:1}}return new Yn(n,t)}};function Bn(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof Bn)||typeof this==="undefined"){return new Bn(e,n)}if(e instanceof Bn){return Bn({im:e.im,re:e.re})}if(Tn.isNumber(e)&&n){e={im:0,re:e.valueOf()}}else if(!Tn.isComplex(e)){throw new Error("Invalid constructor call for LComplex")}var t=e.im instanceof Tn?e.im:Tn(e.im);var r=e.re instanceof Tn?e.re:Tn(e.re);if(t.cmp(0)===0&&!n){return r}this.im=t;this.re=r;this.type="complex"}Bn.prototype=Object.create(Tn.prototype);Bn.prototype.constructor=Bn;Bn.prototype.toRational=function(e){if(Tn.isFloat(this.im)&&Tn.isFloat(this.re)){var n=$n(this.im).toRational(e);var t=$n(this.re).toRational(e);return Bn({im:n,re:t})}return this};Bn.prototype.add=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.add(n),im:t.add(r)}})};Bn.prototype.factor=function(){if(this.im instanceof $n||this.im instanceof $n){var e=this.re,n=this.im;var t,r;if(e instanceof $n){t=e.toRational().mul(e.toRational())}else{t=e.mul(e)}if(n instanceof $n){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))}};Bn.prototype.modulus=function(){return this.factor().sqrt()};Bn.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=$n(.5).mul(e.add(this.re)).sqrt();t=this.im.div(n).div(2)}else{t=$n(.5).mul(e.sub(this.re)).sqrt();if(this.im.cmp(0)===-1){t=t.sub()}n=this.im.div(t).div(2)}return Bn({im:t,re:n})};Bn.prototype.div=function(e){if(Tn.isNumber(e)&&!Tn.isComplex(e)){e=Bn({im:0,re:e})}else if(!Tn.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var n=this.coerce(e),t=Jt(n,2),r=t[0],i=t[1];var a=Bn({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 Bn({re:c,im:s})};Bn.prototype.sub=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.sub(n),im:t.sum(r)}})};Bn.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})};Bn.prototype.complex_op=function(e,n){if(Tn.isNumber(e)&&!Tn.isComplex(e)){if(!(e instanceof Tn)){e=Tn(e)}var t=e.asType(0);e={im:t,re:e}}else if(!Tn.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var r=e.re instanceof Tn?e.re:this.re.asType(e.re);var i=e.im instanceof Tn?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=Bn(a,true);return o}return a};Bn._op={"+":"add","-":"sub","*":"mul","/":"div"};Bn.prototype._op=function(e,n){var t=Bn._op[e];return this[t](n)};Bn.prototype.cmp=function(e){var n=this.coerce(e),t=Jt(n,2),r=t[0],i=t[1];var a=r.re.coerce(i.re),o=Jt(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=Jt(f,2),p=l[0],h=l[1];return p.cmp(h)}};Bn.prototype.valueOf=function(){};Bn.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 $n(e){if(typeof this!=="undefined"&&!(this instanceof $n)||typeof this==="undefined"){return new $n(e)}if(!Tn.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof Tn){return $n(e.valueOf())}if(typeof e==="number"){this.value=e;this.type="float"}}$n.prototype=Object.create(Tn.prototype);$n.prototype.constructor=$n;$n.prototype.toString=function(){var e=this.value.toString();if(!Tn.isFloat(this.value)&&!e.match(/e/i)){return e+".0"}return e.replace(/^([0-9]+)e/,"$1.0e")};$n.prototype._op=function(e,n){if(n instanceof Tn){n=n.value}var t=Tn._ops[e];return $n(t(this.value,n))};$n.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==F?arguments[0]:null;if(e===null){return Dn(this.value.valueOf())}return Un(e.valueOf())(this.value.valueOf())};var Dn=Un(1e-10);function Un(r){return function(e){var n=function e(r,n,t){var i=function e(n,t){return t0){i=Jn(r,t)}else if(r.cmp(t)<=0){i=t}else if(t.cmp(0)>0){i=Jn(t,r)}else if(n.cmp(0)<0){i=Tn(Jn(r.sub(),t.sub())).sub()}else{i=Tn(0)}if(Tn.isFloat(n)||Tn.isFloat(e)){return $n(i)}return i}function Jn(e,n){var t=Tn(e).floor();var r=Tn(n).floor();if(e.cmp(t)<1){return t}else if(t.cmp(r)===0){var i=Tn(1).div(n.sub(r));var a=Tn(1).div(e.sub(t));return t.add(Tn(1).div(Jn(i,a)))}else{return t.add(Tn(1))}}function Yn(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof Yn)||typeof this==="undefined"){return new Yn(e,n)}if(!Tn.isRational(e)){throw new Error("Invalid constructor call for LRational")}var t=Tn(e.num);var r=Tn(e.denom);if(!n&&r.cmp(0)!==0){var i=t.op("%",r).cmp(0)===0;if(i){return Tn(t.div(r))}}this.num=t;this.denom=r;this.type="rational"}Yn.prototype=Object.create(Tn.prototype);Yn.prototype.constructor=Yn;Yn.prototype.pow=function(e){var n=e.cmp(0);if(n===0){return Tn(1)}if(n===-1){e=e.sub();var t=this.denom.pow(e);var r=this.num.pow(e);return Yn({num:t,denom:r})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};Yn.prototype.sqrt=function(){var e=this.num.sqrt();var n=this.denom.sqrt();if(e instanceof $n){e=(Ct("num"),e.toRational())}if(n instanceof $n){n=(Ct("denom"),n.toRational())}return Yn({num:e,denom:n})};Yn.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 Yn({num:e,denom:n})};Yn.prototype.cmp=function(e){return Tn(this.valueOf(),true).cmp(e)};Yn.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 Yn){n=Tn(n.valueOf(true))}t=this.denom.div(e);if(t instanceof Yn){t=Tn(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()};Yn.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 Tn._ops["/"](this.num.value,this.denom.value)}return $n(this.num.valueOf()).div(this.denom.valueOf())};Yn.prototype.mul=function(e){if(!(e instanceof Tn)){e=Tn(e)}if(Tn.isRational(e)){var n=this.num.mul(e.num);var t=this.denom.mul(e.denom);return Yn({num:n,denom:t})}var r=Tn.coerce(this,e),i=Jt(r,2),a=i[0],o=i[1];return a.mul(o)};Yn.prototype.div=function(e){if(!(e instanceof Tn)){e=Tn(e)}if(Tn.isRational(e)){var n=this.num.mul(e.denom);var t=this.denom.mul(e.num);return Yn({num:n,denom:t})}var r=Tn.coerce(this,e),i=Jt(r,2),a=i[0],o=i[1];var u=a.div(o);return u};Yn.prototype._op=function(e,n){return this[Qn[e]](n)};Yn.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof Tn)){e=Tn(e)}if(Tn.isRational(e)){var n=e.num.sub();var t=e.denom;return this.add(Yn({num:n,denom:t}))}if(!(e instanceof Tn)){e=Tn(e).sub()}else{e=e.sub()}var r=Tn.coerce(this,e),i=Jt(r,2),a=i[0],o=i[1];return a.add(o)};Yn.prototype.add=function(e){if(!(e instanceof Tn)){e=Tn(e)}if(Tn.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 Yn({num:o,denom:a})}if(Tn.isFloat(e)){return $n(this.valueOf()).add(e)}var u=Tn.coerce(this,e),c=Jt(u,2),s=c[0],f=c[1];return s.add(f)};function Gn(e,n){if(typeof this!=="undefined"&&!(this instanceof Gn)||typeof this==="undefined"){return new Gn(e,n)}if(e instanceof Gn){return Gn(e.value,e._native)}if(!Tn.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.value=e;this._native=n;this.type="bigint"}Gn.prototype=Object.create(Tn.prototype);Gn.prototype.constructor=Gn;Gn.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};Gn.prototype._op=function(e,n){if(typeof n==="undefined"){if(Tn.isBN(this.value)){e=Gn.bn_op[e];return Gn(this.value.clone()[e](),false)}return Gn(Tn._ops[e](this.value),true)}if(Tn.isBN(this.value)&&Tn.isBN(n.value)){e=Gn.bn_op[e];return Gn(this.value.clone()[e](n),false)}var t=Tn._ops[e](this.value,n.value);if(e==="/"){var r=this.op("%",n).cmp(0)===0;if(r){return Tn(t)}return Yn({num:this,denom:n})}return Gn(t,true)};Gn.prototype.sqrt=function(){var e;var n=this.cmp(0)<0;if(Tn.isNative(this.value)){e=Tn(Math.sqrt(n?-this.valueOf():this.valueOf()))}else if(Tn.isBN(this.value)){e=n?this.value.neg().sqrt():this.value.sqrt()}if(n){return Bn({re:0,im:e})}return e};Tn.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}}};Tn.isFloat=function e(n){return n instanceof $n||Number(n)===n&&n%1!==0};Tn.isNumber=function(e){return e instanceof Tn||!Number.isNaN(e)&&Tn.isNative(e)||Tn.isBN(e)};Tn.isComplex=function(e){var n=e instanceof Bn||Tn.isNumber(e.im)&&Tn.isNumber(e.re);return n};Tn.isRational=function(e){return e instanceof Yn||Tn.isNumber(e.num)&&Tn.isNumber(e.denom)};Tn.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};Tn.isBigInteger=function(e){return e instanceof Gn||typeof e==="bigint"||Tn.isBN(e)};Tn.isBN=function(e){return typeof h!=="undefined"&&e instanceof h};Tn.getArgsType=function(e,n){if(e instanceof $n||n instanceof $n){return $n}if(e instanceof Gn||n instanceof Gn){return Gn}return Tn};Tn.prototype.toString=Tn.prototype.toJSON=function(e){if(e>2&&e<36){return this.value.toString(e)}return this.value.toString()};Tn.prototype.asType=function(e){var n=Tn.getType(this);return Tn.types[n]?Tn.types[n](e):Tn(e)};Tn.prototype.isBigNumber=function(){return typeof this.value==="bigint"||typeof h!=="undefined"&&!(this.value instanceof h)};["floor","ceil","round"].forEach(function(e){Tn.prototype[e]=function(){if(this["float"]||Tn.isFloat(this.value)){return Tn(Math[e](this.value))}else{return Tn(Math[e](this.valueOf()))}}});Tn.prototype.valueOf=function(){if(Tn.isNative(this.value)){return Number(this.value)}else if(Tn.isBN(this.value)){return this.value.toNumber()}};var Vn=function(){var e=function e(n,t){return[n,t]};return{bigint:{bigint:e,float:function e(n,t){return[$n(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&&$n(t.valueOf())]},float:e,rational:function e(n,t){return[n,t&&$n(t.valueOf())]},complex:function e(n,t){return[{re:n,im:$n(0)},t]}},complex:{bigint:n("bigint"),float:n("float"),rational:n("rational"),complex:function e(n,t){var r=Tn.coerce(n.re,t.re),i=Jt(r,2),a=i[0],o=i[1];var u=Tn.coerce(n.im,t.im),c=Jt(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[$n(n.valueOf()),t]},rational:e,complex:function e(n,t){return[{im:zn(n.type,t.im.type,0),re:zn(n.type,t.re.type,n)},{im:zn(n.type,t.im.type,t.im),re:zn(n.type,t.re.type,t.re)}]}}};function n(t){return function(e,n){return[{im:zn(t,e.im.type,e.im),re:zn(t,e.re.type,e.re)},{im:zn(t,e.im.type,0),re:zn(t,n.type,n)}]}}}();function zn(e,n,t){return Vn[e][n](t)[0]}Tn.coerce=function(e,n){function t(e){if(e==="integer"){return"bigint"}return e}var r=t(Tn.getType(e));var i=t(Tn.getType(n));if(!Vn[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!Vn[r][i]){throw new Error("LNumber::coerce unknown rhs type ".concat(i))}return Vn[r][i](e,n).map(function(e){return Tn(e,true)})};Tn.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof Tn)){throw new Error("LNumber: you can't coerce ".concat(_t(e)))}if(typeof e==="number"){e=Tn(e)}return Tn.coerce(this,e)};Tn.getType=function(e){if(e instanceof Tn){return e.type}if(Tn.isFloat(e)){return"float"}if(Tn.isComplex(e)){return"complex"}if(Tn.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"}};Tn.prototype.isFloat=function(){return!!(Tn.isFloat(this.value)||this["float"])};var Wn={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var Qn={};Object.keys(Wn).forEach(function(n){Qn[Wn[n]]=n;Tn.prototype[n]=function(e){return this.op(Wn[n],e)}});Tn._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 rt}return In(this._string[this._in_char])};function et(e){if(typeof this!=="undefined"&&!(this instanceof et)||typeof this==="undefined"){return new et(e)}bt("OutputPort",e,"function");this.write=e}et.prototype.toString=function(){return"<#output-port>"};function nt(n){var t=this;if(typeof this!=="undefined"&&!(this instanceof nt)||typeof this==="undefined"){return new nt(n)}bt("OutputStringPort",n,"function");this._buffer=[];this.write=function(e){if(!Nn.isString(e)){e=n(e)}else{e=e.valueOf()}t._buffer.push(e)}}nt.prototype=Object.create(et.prototype);nt.prototype.getString=function(){return this._buffer.map(function(e){return e.valueOf()}).join("")};nt.prototype.constructor=nt;function tt(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof tt)||typeof this==="undefined"){return new tt(e)}bt("InputStringPort",e,"string");this._string=e.valueOf();this._index=0;this._in_char=0;this.read=function(){return n.get_next_tokens()}}tt.prototype=Object.create(Zn.prototype);tt.prototype.constructor=tt;tt.prototype.read_line=function(){var e=this._string.substring(this._in_char);if(!e){return rt}var n=e.match(/([^\n])(?:\n|$)/)[0];this._in_char+=n.length;return n};var rt=new it;function it(){}it.prototype.toString=function(){return"<#eof>"};function at(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:{};if(typeof this!=="undefined"&&!(this instanceof at)||typeof this==="undefined"){return new at(e,n)}if(typeof e==="undefined"){e="anonymous"}this.env=lt.inherit(e,n)}at.prototype.exec=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;bt("Intepreter::exec",e,"string",1);bt("Intepreter::exec",n,"boolean",2);ft.set("**interaction-environment**",this.env);return jt(e,this.env,n?this.env:false)};at.prototype.get=function(e){return this.env.get(e).bind(this.env)};at.prototype.set=function(e,n){return this.env.set(e,n)};function ot(e,n,t){if(arguments.length===1){if(Yt(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"}ot.prototype.inherit=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:{};if(Yt(e)==="object"){n=e}if(!e||Yt(e)==="object"){e="child of "+(this.name||"unknown")}return new ot(n||{},this,e)};ot.prototype.doc=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:null;if(e instanceof Oe){e=e.name}if(e instanceof Nn){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)}};ot.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 ot)){return Fe}if(e<=0){return n}var t=n.get("parent.frame");return t(e-1)},ft.env["parent.frame"].__doc__));n.callee=e;r.set("arguments",n);return r};ot.prototype._lookup=function(e){if(e instanceof Oe){e=e.name}if(e instanceof Nn){e=e.valueOf()}if(this.env.hasOwnProperty(e)){return ut(this.env[e])}if(this.parent){return this.parent._lookup(e)}};ot.prototype.toString=function(){return"<#env:"+this.name+">"};ot.prototype.clone=function(){var n=this;var t={};Object.keys(this.env).forEach(function(e){t[e]=n.env[e]});return new ot(t,this.parent,this.name)};ot.prototype.merge=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:"merge";bt("Environment::merge",e,"environment");return this.inherit(n,e.env)};function ut(e){if(typeof this!=="undefined"&&!(this instanceof ut)||typeof this==="undefined"){return new ut(e)}this.value=e}ut.isUndefined=function(e){return e instanceof ut&&typeof e.value==="undefined"};ut.prototype.valueOf=function(){return this.value};function ct(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof ct)||typeof this==="undefined"){return new ct(e)}this.values=e}ct.prototype.toString=function(){return this.values.map(function(e){return Re(e)}).join("\n")};ct.prototype.valueOf=function(){return this.values};ot.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 Oe||i instanceof Nn){i=i.valueOf()}var a=this._lookup(i);if(a instanceof ut){if(ut.isUndefined(a)){return F}return tn(a.valueOf())}if(typeof i==="string"){var o=i.split(".").filter(Boolean);if(o.length>0){var u=$t(o),c=u[0],s=u.slice(1);a=this._lookup(c);if(s.length){try{if(a instanceof ut){a=a.valueOf()}else{a=An(f,c);if(typeof a==="function"){a=rn(a)}}return An.apply(void 0,[a].concat(Dt(s)))}catch(e){}}else if(a instanceof ut){return tn(a.valueOf())}}a=An(f,i)}if(typeof a!=="undefined"){return a}if(r){throw new Error("Unbound variable `"+i.toString()+"'")}};ot.prototype.set=function(e,n){var t=arguments.length>2&&arguments[2]!==F?arguments[2]:null;if(Tn.isNumber(n)){n=Tn(n)}if(e instanceof Oe){e=e.name}if(e instanceof Nn){e=e.valueOf()}this.env[e]=n;if(t){this.doc(e,t)}return this};ot.prototype.has=function(e){return this.env.hasOwnProperty(e)};ot.prototype.ref=function(e){var n=this;while(true){if(!n){break}if(n.has(e)){return n}n=n.parent}};ot.prototype.parents=function(){var e=this;var n=[];while(e){n.unshift(e);e=e.parent}return n};function st(e){if(Ze(e)){return e.then(st)}if(e instanceof Ae||e instanceof Oe){e.data=true}return e}var ft=new ot({nil:Fe,undefined:F,true:true,false:false,null:null,NaN:NaN,stdout:new et(function(){var e;(e=console).log.apply(e,arguments)}),stdin:Zn(function(){return new Promise(function(e){e(prompt(""))})}),"open-input-string":re(function(e){bt("open-input-string",e,"string");return tt(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 et},"(output-port? arg)\n\n Function return true if argument is output port."),"input-port?":re(function(e){return e instanceof Zn},"(input-port? arg)\n\n Function return true if argument is input port."),"open-output-string":re(function(){return nt(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){bt("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===rt},"(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){bt("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")}bt("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")}bt("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(Nn.isString(n)){return ee(W(n.valueOf()))[0]}var t;if(n instanceof Zn){t=n}else{t=this.get("stdin")}return ne(t.read(),function(e){if(e===rt){return rt}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 Ae){e=new Rt.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=Et(e.cdr.car,{env:this,dynamic_scope:t,error:r});i=xt(i);function u(n,t){if(Ze(n)){return n.then(function(e){return u(e,t)})}if(Ze(t)){return t.then(function(e){return u(n,e)})}f[n]=t;return t}if(e.car instanceof Ae&&Oe.is(e.car.car,".")){var c=e.car.cdr.car;var s=e.car.cdr.cdr.car;var f=Et(c,{env:this,dynamic_scope:t,error:r});var l=Et(s,{env:this,dynamic_scope:t,error:r});return u(l,i)}if(!(e.car instanceof Oe)){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 Je("set!",function(e){if(!(e.car instanceof Oe)){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){bt("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){bt("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===Fe},"(empty? object)\n\n Function return true if value is undfined empty list."),assoc:re(function(e,n){if(e instanceof Ae&&!(n instanceof Ae)){throw new Error("First argument to assoc ned to be a key")}bt("assoc",n,"pair");var t=n;while(true){if(!(t instanceof Ae)||this.get("empty?")(t)){break}var r=t.car.car;if($e(r,e)){return t.car}else if(!t.haveCycles("cdr")){t=t.cdr}}return Fe},"(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(Ee,"(gensym)\n\n Function generate unique symbol, to use with macros as meta name."),load:re(function(n){bt("load",n,"string");var e=this;if(e.name==="__frame__"){e=e.parent}var i;if(e===ft){i=e}else{i=this.get("**interaction-environment**")}var a="**module-path**";var o=ft.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)}ft.set(a,e.dirname(n));require("fs").readFile(n,function(e,n){if(e){console.log(e);r(e);ft.set(a,o)}else{jt(n.toString(),i).then(function(){t();ft.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){ft.set(a,n.replace(/\/[^/]*$/,""));return jt(e,i)}).then(function(){})["finally"](function(){ft.set(a,o)})},"(load filename)\n\n Function fetch the file and evaluate its content as LIPS code."),while:re(new Je("while",function(r,e){var i=e.dynamic_scope,a=e.error;var o=this;var u=new Ae(new Oe("begin"),r.cdr);var c;if(i){i=o}return function n(){var e=Et(r.car,{env:o,dynamic_scope:i,error:a});function t(e){if(e&&!Xe(e)){c=Et(u,{env:o,dynamic_scope:i,error:a});if(Ze(c)){return c.then(function(e){c=e;return n()})}else{return n()}}else{return c}}return ne(e,t)}()}),"(while cond . body)\n\n Macro that create a loop, it exectue body untill cond expression is false"),if:re(new Je("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 Et(t.cdr.car,{env:a,dynamic_scope:r,error:i})}else{return Et(t.cdr.cdr.car,{env:a,dynamic_scope:r,error:i})}};var o=Et(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 Je("let-env",function(n){var e=arguments.length>1&&arguments[1]!==F?arguments[1]:{};var t=e.dynamic_scope,r=e.error;bt("let-env",n,"pair");var i=Et(n.car,{env:this,dynamic_scope:t,error:r});return ne(i,function(e){if(!(e instanceof ot)){throw new Error("let-env: First argument need to be "+"environment")}return Et(Ae(Oe("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(mn(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(mn(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(mn(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(yn("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 Je("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=Et(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 Je("ignore",function(e,n){var t=n.dynamic_scope,r=n.error;var i={env:this,error:r};if(t){i.dynamic_scope=this}Et(new Ae(new Oe("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(Je.defmacro("define",function(t,e){var r=this;if(t.car instanceof Ae&&t.car.car instanceof Oe){var n=new Ae(new Oe("define"),new Ae(t.car.car,new Ae(new Ae(new Oe("lambda"),new Ae(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 Ae){i=Et(i,e)}else if(i instanceof Oe){i=r.get(i)}bt("define",t.car,"symbol");return ne(i,function(e){if(r.name===ze.merge_env){r=r.parent}var n;if(t.cdr.cdr instanceof Ae&&Nn.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=Yt(e);if(Xe(e)||r!=="object"&&r!=="function"){var i=gt("set-obj!",_t(e),["object","function"]);throw new Error(i)}e=rn(e);n=n.valueOf();if(arguments.length===2){delete e[n]}else if(Ce(e)&&typeof t==="function"){e[n]=rn(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 ft.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 Ae&&Nn.isString(l.cdr.car)&&l.cdr.cdr!==Fe){d=l.cdr.car.valueOf()}function m(){var e;if(p){if(!(this instanceof ot)){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 Ae){var r=e.car;var i=e.cdr;if(t(r)){r=n(r)}if(t(i)){i=n(i)}if(Ze(r)||Ze(i)){return Promise.all([r,i]).then(function(e){var n=Jt(e,2),t=n[0],r=n[1];return new Ae(t,r)})}else{return new Ae(r,i)}}return e}function i(e,n){if(e instanceof Ae){if(n!==Fe){e.append(n)}}else{e=new Ae(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 Ae){if(e.cdr.cdr!==Fe){if(e.cdr.car instanceof Ae){var i=Fe;return function n(t){if(t===Fe){return i}return ne(Et(t.car,{env:u,dynamic_scope:a,error:o}),function(e){i=new Ae(e,i);return n(t.cdr)})}(e.cdr)}else{return e.cdr}}else{return Et(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 Ae){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 st(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){bt("clone",e,"pair");return e.clone()},"(clone list)\n\n Function return clone of the list."),append:re(function(e,n){bt("append",e,["nil","pair"]);if(e instanceof Ae){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){bt("append!",e,["pair","nil"]);if(!this.get("list?")(e)){throw new Error("append!: Invalid argument, value is not a list")}if(Xe(n)){return e}if(e===Fe){if(n===Fe){return Fe}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){bt("reverse",e,["array","pair","nil"]);if(e===Fe){return Fe}if(e instanceof Ae){var n=this.get("list->array")(e).reverse();return this.get("array->list")(n)}else if(!(e instanceof Array)){throw new Error(gt("reverse",_t(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){bt("nth",e,"number");bt("nth",n,["array","pair"]);if(n instanceof Ae){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){bt("split",e,["regex","string"]);bt("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){bt("replace",e,["regex","string"]);bt("replace",n,["string","function"]);bt("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){bt("match",e,["regex","string"]);bt("match",n,"string");var t=n.match(e);return t?this.get("array->list")(t):Fe},"(match pattern string)\n\n function return match object from JavaScript as list."),search:re(function(e,n){bt("search",e,["regex","string"]);bt("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 Re(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=Ae.fromArray(n)}else{t=Fe}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;bt("set-special!",e,"string",1);bt("set-special!",n,"symbol",2);Rt.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:An,".":An,unbind:re(rn,"(unbind fn)\n\n Function remove bidning from function so you can get props from it."),type:re(_t,"(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 Oe||e instanceof Nn){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 rn(e)},"(instanceof type obj)\n\n Function check of object is instance of object."),"macro?":re(function(e){return e instanceof Je},"(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(_t(e)!=="number"){return false}if(e instanceof Tn){return e.isFloat()}return Tn.isFloat(e)},"(real? number)\n\n Function check if value is real number."),"number?":re(Tn.isNumber,"(number? expression)\n\n Function check if value is a number"),"string?":re(function(e){return Nn.isString(e)},"(string? expression)\n\n Function check if value is a string."),"pair?":re(function(e){return e instanceof Ae},"(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 Xe(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 Oe},"(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!==Fe&&e!==null&&!(e instanceof Tn)&&Yt(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Function check if value is an object."),flatten:re(function(e){bt("flatten",e,"pair");return e.flatten()},"(flatten list)\n\n Return shallow list from tree structure (pairs)."),"array->list":re(function(e){bt("array->list",e,"array");return Ae.fromArray(e)},"(array->list array)\n\n Function convert JavaScript array to LIPS list."),"tree->array":re(Ie("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":re(Ie("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 Tn(0)}if(e instanceof Ae){return Tn(e.length())}if("length"in e){return Tn(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;bt("string->number",e,"string",1);bt("string->number",n,"number",2);e=e.valueOf();n=n.valueOf();if(e.match(S)||e.match(w)){return A(e,n)}else if(e.match(O)||e.match(b)){return L(e,n)}else{var t=n===10&&!e.match(/e/i)||n===16;if(e.match(x)&&t||e.match(_)){return I(e,n)}if(e.match(c)){return R(e)}}return false},"(string->number number [radix])\n\n Function convert string to number."),try:re(new Je("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(Et(new Ae(new Oe("begin"),a.cdr.car.cdr.cdr),r),function(e){i(e)})}};if(u){e.dynamic_scope=o}var n=Et(a.car,e);if(Ze(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){bt("find",t,["regex","function"]);bt("find",r,"pair");if(Xe(r)){return Fe}var e=te("find",t);return ne(e(r.car),function(e){if(e&&e!==Fe){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;bt("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!==Fe){a.push(r)}return n(++t)}if(t===i.length){return Ae.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){bt("range",e,"number");if(e instanceof Tn){e=e.valueOf()}return Ae.fromArray(new Array(e).fill(0).map(function(e,n){return Tn(n)}))},"(range n)\n\n Function return list of n numbers from 0 to n - 1"),compose:re(wn,"(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(bn,"(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(En,"(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=Te(i*(t<0||arguments.length<=t?F:arguments[t]))/(n+r)}return Tn(n)},"(lcm n1 n2 ...)\n\n Function return the least common multiple of their arguments."),"odd?":re(Sn(function(e){return Tn(e).isOdd()}),"(odd? number)\n\n Function check if number os odd."),"even?":re(Sn(function(e){return Tn(e).isEven()}),"(even? number)\n\n Function check if number is even."),"*":re(kn(function(e,n){return Tn(e).mul(n)},Tn(1)),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":re(kn(function(e,n){return Tn(e).add(n)},Tn(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($e,"(eq? a b)\n\n Function compare two values if they are identical."),or:re(new Je("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=Et(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 Je("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=Et(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 Tn(e).or(n)},"(& a b)\n\n Function calculate or bit operation."),"&":re(function(e,n){return Tn(e).and(n)},"(& a b)\n\n Function calculate and bit operation."),"~":re(function(e){return Tn(e).neg()},"(~ number)\n\n Function negate the value."),">>":re(function(e,n){return Tn(e).shr(n)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":re(function(e,n){return Tn(e).shl(n)},"(<< a b)\n\n Function left shit the value a by value b."),not:re(function(e){if(Xe(e)){return true}return!e},"(not object)\n\n Function return negation of the argument.")},F,"global");var lt=ft.inherit("user-env");ft.set("**interaction-environment**",lt);(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(n){var t=e[n]?e[n]:n;ft.set(t,re(function(e){bt(t,e,"number");if(e instanceof Tn){return e[n]()}},"(".concat(t," number)\n\n Function calculate ").concat(t," of a number.")))})})();function pt(e){if(e.length===1){return e[0]}else{var n=[];var t=pt(e.slice(1));for(var r=0;r3&&arguments[3]!==F?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(r!==null){i+=" argument ".concat(r)}if(t instanceof Array){var a=t[t.length-1];t=t.slice(0,-1).join(", ")+" or "+a}return"Expecting ".concat(t," got ").concat(n).concat(i)}function bt(e,n,t){var r=arguments.length>3&&arguments[3]!==F?arguments[3]:null;e=e.valueOf();var i=_t(n).toLowerCase();var a=false;if(t instanceof Ae){t=t.toArray()}if(t instanceof Array){t=t.map(function(e){return e.valueOf().toLowerCase()});if(t.includes(i)){a=true}}else{t=t.valueOf().toLowerCase()}if(!a&&i!==t){throw new Error(gt(e,i,t,r))}}function wt(e){var n=Yt(e);return["string","function"].includes(n)||e instanceof Oe||e instanceof Tn||e instanceof RegExp}function _t(e){var n={pair:Ae,symbol:Oe,character:In,values:ct,macro:Je,string:Nn,array:Array,"native-symbol":Symbol};if(Number.isNaN(e)){return"NaN "}if(e===Fe){return"nil"}if(e===null){return"null"}if(e instanceof ze){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||ft}else if(i===true){i=a=ft}else{i=i||ft}var r={env:i,dynamic_scope:a,error:o};var u;if(Xe(n)){return n}if(n instanceof Oe){return i.get(n)}var c=n.car;var s=n.cdr;if(c instanceof Ae){u=xt(Et(c,r));if(Ze(u)){return u.then(function(e){return Et(new Ae(e,n.cdr),r)})}else if(typeof u!=="function"){throw new Error(_t(u)+" "+i.get("repr")(u)+" is not a function while evaluating "+n.toString())}}if(c instanceof Oe){u=i.get(c);if(u instanceof ze){return Ot(u,n,r)}else if(u instanceof Je){return kt(u,s,r)}else if(typeof u!=="function"){if(u){var f="".concat(_t(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=St(s,r);return ne(l,function(e){if(on(u)&&(!un(u)||cn(u))){e=e.map(nn)}if(u.__lambda__&&!u.__prototype__||cn(u)){u=rn(u)}var n=e.slice();var t=(a||i).newFrame(u,n);var r=xt(u.apply(t,e));return ne(r,function(e){if(e instanceof Ae){e.markCycles();return st(e)}if(typeof e==="number"){return Tn(e)}if(typeof e==="string"){return Nn(e)}return e},o)})}else if(n instanceof Oe){u=i.get(n);if(u==="undefined"){throw new Error("Unbound variable `"+n.name+"'")}return u}else if(n instanceof Ae){u=c&&c.toString();throw new Error("".concat(_t(c)," ").concat(u," is not a function"))}else{return n}}catch(e){o&&o.call(i,e,n)}}function jt(e,n,t){return Ft.apply(this,arguments)}function Ft(){Ft=Bt(Tt.mark(function e(t,r,i){var a,o,u,c;return Tt.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(i===true){r=i=r||lt}else if(r===true){r=i=lt}else{r=r||lt}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 Et(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 Ft.apply(this,arguments)}function At(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=Gt(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 It(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 Nt(e){this.url=e;var o=this.worker=It(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=Jt(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=Jt(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 Rt.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])}}Ae.unDry=function(e){return new Ae(e.car,e.cdr)};Ae.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};je.prototype.toDry=function(){return{value:null}};je.unDry=function(){return Fe};Oe.prototype.toDry=function(){return{value:{name:this.name}}};Oe.unDry=function(e){return new Oe(e.name)};function Lt(e){console.error(e.message||e);if(e.code){console.error(e.code.map(function(e,n){return"[".concat(n+1,"]: ").concat(e)}))}}function qt(){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(jt).then(n)["catch"](function(e){Lt(e);n()})}else{return jt(e.innerHTML).then(n)["catch"](function(e){Lt(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,qt)}var Pt=function(){var e=Nn("Sat, 22 Aug 2020 14:06:34 +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";Je.__className="macro";ze.__className="syntax";ot.__className="environment";Zn.__className="input-port";et.__className="output-port";nt.__className="output-string-port";tt.__className="input-string-port";Tn.__className="number";In.__className="character";Nn.__className="string";var Rt={version:"DEV",banner:Pt,date:"Sat, 22 Aug 2020 14:06:34 +0000",exec:jt,parse:ee,tokenize:W,evaluate:Et,Environment:ot,env:lt,Worker:Nt,Interpreter:at,balanced_parenthesis:At,balancedParenthesis:At,balanced:At,Macro:Je,Syntax:ze,Pair:Ae,quote:st,InputPort:Zn,OutputPort:et,InputStringPort:tt,OutputStringPort:nt,Formatter:ce,specials:K,repr:Ne,nil:Fe,LSymbol:Oe,LNumber:Tn,LFloat:$n,LComplex:Bn,LRational:Yn,LBigInteger:Gn,LCharacter:In,LString:Nn,rationalize:Hn};ft.set("lips",Rt);return Rt})})(); \ No newline at end of file +(function(){"use strict";function e(e){throw new Error('"'+e+'" is read-only')}var Ct=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 Mt=n(function(r){function i(e,n,t){if(a()){r.exports=i=Reflect.construct}else{r.exports=i=function e(n,t,r){var i=[null];i.push.apply(i,t);var a=Function.bind.apply(n,i);var o=new a;if(r)u(o,r.prototype);return o}}return i.apply(null,arguments)}r.exports=i});var r=n(function(e){var n=function(o){var e=Object.prototype;var f=e.hasOwnProperty;var c;var n=typeof Symbol==="function"?Symbol:{};var i=n.iterator||"@@iterator";var t=n.asyncIterator||"@@asyncIterator";var r=n.toStringTag||"@@toStringTag";function u(e,n,t,r){var i=n&&n.prototype instanceof s?n:s;var a=Object.create(i.prototype);var o=new F(r||[]);a._invoke=O(e,t,o);return a}o.wrap=u;function l(e,n,t){try{return{type:"normal",arg:e.call(n,t)}}catch(e){return{type:"throw",arg:e}}}var p="suspendedStart";var h="suspendedYield";var v="executing";var d="completed";var m={};function s(){}function a(){}function y(){}var g={};g[i]=function(){return this};var b=Object.getPrototypeOf;var w=b&&b(b(A([])));if(w&&w!==e&&f.call(w,i)){g=w}var _=y.prototype=s.prototype=Object.create(g);a.prototype=_.constructor=y;y.constructor=a;y[r]=a.displayName="GeneratorFunction";function x(e){["next","throw","return"].forEach(function(n){e[n]=function(e){return this._invoke(n,e)}})}o.isGeneratorFunction=function(e){var n=typeof e==="function"&&e.constructor;return n?n===a||(n.displayName||n.name)==="GeneratorFunction":false};o.mark=function(e){if(Object.setPrototypeOf){Object.setPrototypeOf(e,y)}else{e.__proto__=y;if(!(r in e)){e[r]="GeneratorFunction"}}e.prototype=Object.create(_);return e};o.awrap=function(e){return{__await:e}};function S(u,c){function s(e,n,t,r){var i=l(u[e],u,n);if(i.type==="throw"){r(i.arg)}else{var a=i.arg;var o=a.value;if(o&&typeof o==="object"&&f.call(o,"__await")){return c.resolve(o.__await).then(function(e){s("next",e,t,r)},function(e){s("throw",e,t,r)})}return c.resolve(o).then(function(e){a.value=e;t(a)},function(e){return s("throw",e,t,r)})}}var n;function e(t,r){function e(){return new c(function(e,n){s(t,r,e,n)})}return n=n?n.then(e,e):e()}this._invoke=e}x(S.prototype);S.prototype[t]=function(){return this};o.AsyncIterator=S;o.async=function(e,n,t,r,i){if(i===void 0)i=Promise;var a=new S(u(e,n,t,r),i);return o.isGeneratorFunction(n)?a:a.next().then(function(e){return e.done?e.value:a.next()})};function O(o,u,c){var s=p;return function e(n,t){if(s===v){throw new Error("Generator is already running")}if(s===d){if(n==="throw"){throw t}return I()}c.method=n;c.arg=t;while(true){var r=c.delegate;if(r){var i=k(r,c);if(i){if(i===m)continue;return i}}if(c.method==="next"){c.sent=c._sent=c.arg}else if(c.method==="throw"){if(s===p){s=d;throw c.arg}c.dispatchException(c.arg)}else if(c.method==="return"){c.abrupt("return",c.arg)}s=v;var a=l(o,u,c);if(a.type==="normal"){s=c.done?d:h;if(a.arg===m){continue}return{value:a.arg,done:c.done}}else if(a.type==="throw"){s=d;c.method="throw";c.arg=a.arg}}}}function k(e,n){var t=e.iterator[n.method];if(t===c){n.delegate=null;if(n.method==="throw"){if(e.iterator["return"]){n.method="return";n.arg=c;k(e,n);if(n.method==="throw"){return m}}n.method="throw";n.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var r=l(t,e.iterator,n.arg);if(r.type==="throw"){n.method="throw";n.arg=r.arg;n.delegate=null;return m}var i=r.arg;if(!i){n.method="throw";n.arg=new TypeError("iterator result is not an object");n.delegate=null;return m}if(i.done){n[e.resultName]=i.value;n.next=e.nextLoc;if(n.method!=="return"){n.method="next";n.arg=c}}else{return i}n.delegate=null;return m}x(_);_[r]="Generator";_[i]=function(){return this};_.toString=function(){return"[object Generator]"};function j(e){var n={tryLoc:e[0]};if(1 in e){n.catchLoc=e[1]}if(2 in e){n.finallyLoc=e[2];n.afterLoc=e[3]}this.tryEntries.push(n)}function E(e){var n=e.completion||{};n.type="normal";delete n.arg;e.completion=n}function F(e){this.tryEntries=[{tryLoc:"root"}];e.forEach(j,this);this.reset(true)}o.keys=function(t){var r=[];for(var e in t){r.push(e)}r.reverse();return function e(){while(r.length){var n=r.pop();if(n in t){e.value=n;e.done=false;return e}}e.done=true;return e}};function A(n){if(n){var e=n[i];if(e){return e.call(n)}if(typeof n.next==="function"){return n}if(!isNaN(n.length)){var t=-1,r=function e(){while(++t=0;--n){var i=this.tryEntries[n];var a=i.completion;if(i.tryLoc==="root"){return e("end")}if(i.tryLoc<=this.prev){var o=f.call(i,"catchLoc");var u=f.call(i,"finallyLoc");if(o&&u){if(this.prev=0;--t){var r=this.tryEntries[t];if(r.tryLoc<=this.prev&&f.call(r,"finallyLoc")&&this.prev=0;--n){var t=this.tryEntries[n];if(t.finallyLoc===e){this.complete(t.completion,t.afterLoc);E(t);return m}}},catch:function(e){for(var n=this.tryEntries.length-1;n>=0;--n){var t=this.tryEntries[n];if(t.tryLoc===e){var r=t.completion;if(r.type==="throw"){var i=r.arg;E(t)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,t){this.delegate={iterator:A(e),resultName:n,nextLoc:t};if(this.method==="next"){this.arg=c}return m}};return o}(e.exports);try{regeneratorRuntime=n}catch(e){Function("r","regeneratorRuntime = r")(n)}});var Tt=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 Bt=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 Ht=E;function F(e,n){if(typeof Symbol==="undefined"||!(Symbol.iterator in Object(e)))return;var t=[];var r=true;var i=false;var a=undefined;try{for(var o=e[Symbol.iterator](),u;!(r=(u=o.next()).done);r=true){t.push(u.value);if(n&&t.length===n)break}}catch(e){i=true;a=e}finally{try{if(!r&&o["return"]!=null)o["return"]()}finally{if(i)throw a}}return t}var A=F;function I(e,n){return s(e)||A(e,n)||d(e,n)||y()}var Jt=I;var Yt=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 Gt(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=Yn({num:Tn([r[0],t.radix||n]),denom:Tn([r[1],t.radix||n])});if(t.inexact){return i.valueOf()}else{return i}}function I(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:10;var t=E(e);if(t.inexact){return $n(parseInt(t.number,t.radix||n))}return Tn([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 In(t)}}function L(e){var i=arguments.length>1&&arguments[1]!==F?arguments[1]:10;function n(e){var n;if(e==="+"){n=Tn(1)}else if(e==="-"){n=Tn(-1)}else if(e.match(x)){n=Tn([e,i])}else if(e.match(S)){var t=e.split("/");n=Yn({num:Tn([t[0],i]),denom:Tn([t[1],i])})}else if(e.match(c)){var r=$n(parseFloat(e));if(a.exact){return r.toRational()}return r}else{throw new Error("Internal Parser Error")}if(a.inexact){return $n(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 $n){o=$n(0)}else{o=Tn(0)}return Bn({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 Tn(a).mul(u)}}}t=$n(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 Nn(JSON.parse(e))}catch(e){throw new Error("Invalid string literal")}}function M(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var t={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,n){return String.fromCharCode(parseInt("0"+n,16))}).replace(/\\(.)/g,function(e,n){return t[n]||n})}return new Oe(e)}function T(e){var n=e.match(a);if(n){return new RegExp(n[1],n[2])}else if(e.match(/^"/)){return C(e)}else if(e.match(m)){return N(e)}else if(e.match(w)){return A(e)}else if(e.match(b)){return L(e)}else if(e.match(_)){return I(e)}else if(e.match(c)){return R(e)}else if(e==="nil"){return Fe}else if(["true","#t"].includes(e)){return true}else if(["false","#f"].includes(e)){return false}else{return M(e)}}function B(e){return!(["(",")"].includes(e)||e.match(a)||e.match(/^"[\s\S]+"$/)||e.match(_)||e.match(c)||e.match(b)||e.match(w)||["#t","#f","nil","true","false"].includes(e))}var $=/("(?:\\[\S\s]|[^"])*"?|\/(?! )[^\n\/\\]*(?:\\[\S\s][^\n\/\\]*)*\/[gimy]*(?=[\s[\]()]|$)|\|[^|\s\n]+\||#;|;.*|#\|(?!\|#)[\s\S]*\|#)/g;var D=/"(?:\\[\S\s]|[^"])*"?/g;var U=[r,n,i].map(y).join("|");function H(){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 J(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=H();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=J(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=Ht(e,["token"]);if(n.match(/^"[\s\S]+"$/)&&n.match(/\n/)){var r=new RegExp("^ {1,"+(e.col+1)+"}","mg");n=n.replace(r,"")}return Vt({token:n},t)}function W(e,n){var t=arguments.length>2&&arguments[2]!==F?arguments[2]:z;if(e instanceof Nn){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 Oe){c[c.length-1].push(e)}else if(c[c.length-1]instanceof Ae){if(c[c.length-1].cdr instanceof Ae){c[c.length-1]=new Ae(c[c.length-1],Ae.fromArray(e))}else{c[c.length-1].cdr=Ae.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]=Ae.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=Fe}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(Fe)}else if(i instanceof Array&&i[0]===g){var a;(a=n).push.apply(a,Dt(i.slice(1)))}else{n.push(i)}}else if(n instanceof Ae){if(i.length===0){n.append(Fe)}else{n.append(Ae.fromArray(i))}}if(d.length){m=d.pop();while(m.length){_();m.pop()}}else{_()}}if(h===0&&c.length){s.push(c.pop())}}else{v=false;var o=T(e);if(f){while(y--){c[c.length-1].push(o);o=c.pop()}d.pop();y=0;f=false}else if(o instanceof Oe&&p.includes(o.name)){o.literal=true}n=c[c.length-1];if(n instanceof Ae){var u=n;while(true){if(u.cdr===Fe){if(o instanceof Array){u.cdr=Ae.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 Ae.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(Ze);if(r.length){return ne(Promise.all(r),n,t)}return n(e)}if(Ze(e)){var i=e.then(n);if(t===null){return i}else{return i["catch"](t)}}return n(e)}function te(e,n){if(n instanceof RegExp){return function(e){return String(e).match(n)}}else if(typeof n!=="function"){throw new Error("".concat(e," argument need to be a function or RegExp"))}else{return n}}function re(e,n,t){if(n){if(t){e.__doc__=n}else{e.__doc__=ie(n)}}return e}function ie(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function ae(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:1;var t=e.length;if(n<=0){throw Error("previousSexp: Invlaid argument sexp = ".concat(n))}e:while(n--&&t>=0){var r=1;while(r>0){var i=e[--t];if(!i){break e}if(i==="("||i.token==="("){r--}else if(i===")"||i.token===")"){r++}}t--}return e.slice(t+1)}function oe(e){if(!e||!e.length){return 0}var n=e.length;if(e[n-1].token==="\n"){return 0}while(--n){if(e[n].token==="\n"){var t=(e[n+1]||{}).token;if(t){return t.length}}}return 0}function ue(e,n){return f(e,n)===n.length;function f(t,r){function e(){return a>0&&u>0&&t[a-1]===r[u-1]&&t[a+1]===r[u]}function n(){return t[a]===Symbol["for"]("symbol")&&!B(r[u])}function i(){var e=t[a+1];var n=r[u+1];if(e!==F&&n!==F){return f([e],[n])}}var a=0;var o={};for(var u=0;u0){continue}}else if(n()){return-1}}else if(t[a]instanceof Array){var s=f(t[a],r.slice(u));if(s===-1||s+u>r.length){return-1}u+=s-1;a++;continue}else{return-1}a++}if(t.length!==a){return-1}return r.length}}function ce(e){this._code=e.replace(/\r/g,"")}ce.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?define/,/^(?:#:)?lambda/,/^(?:#:)?let*/,/^(?:#:)?(let|letrec)(-syntax)?$/,/(?:#:)?let-env/,/(?:#:)?syntax-rules/,/(?:#:)?try/,/(?:#:)?catch/,/(?:#:)?while/],shift:{1:["&","#"]}}};ce.match=ue;ce.prototype._options=function e(n){var t=ce.defaults;if(typeof n==="undefined"){return Object.assign({},t)}var r=n&&n.exceptions||{};var i=r.specials||[];var a=r.shift||{1:[]};return Vt(Vt(Vt({},t),n),{},{exceptions:{specials:[].concat(Dt(t.exceptions.specials),Dt(i)),shift:Vt(Vt({},a),{},{1:[].concat(Dt(t.exceptions.shift[1]),Dt(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=Gt(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()&&At(a)){return r.offset+a[0].col}else if(a.length===1){return r.offset+a[0].col+1}else{var u=-1;if(o){var c=ce.exception_shift(o.token,r);if(c!==-1){u=c}}if(u===-1){u=ce.exception_shift(a[1].token,r)}if(u!==-1){return r.offset+a[0].col+u}else if(a[0].line3&&a[1].line===a[3].line){if(a[1].token==="("||a[1].token==="["){return r.offset+a[1].col}return r.offset+a[3].col}else if(a[0].line===a[1].line){return r.offset+r.indent+a[0].col}else{var s=a.slice(2);for(var f=0;f")};se.prototype.match=function(e){return e.match(this.pattern)};function fe(e,n){this.pattern=e;this.flag=n}fe.prototype.toString=function(){return"#")};ce.Pattern=fe;ce.Ahead=se;var le=/[[(]/;var pe=/[\])]/;var he=/[^()[\]]/;var ve=new se(/[^)\]]/);var de=Symbol["for"]("*");var me=new fe([le,de,pe],"+");var ye=new fe([Symbol["for"]("symbol")],"?");var ge=new fe([le,Symbol["for"]("symbol"),de,pe],"+");var be=_e("define","lambda","syntax-rules");var we=/^(?:#:)?(let|let\*|letrec|let-env)(:?-syntax)?$/;function _e(){for(var e=arguments.length,n=new Array(e),t=0;t0&&arguments[0]!==F?arguments[0]:null;if(e instanceof Oe){e=e.valueOf()}if(ke(e)){return Oe(e)}if(e!==null){return new Oe(Symbol("#:".concat(e)))}n++;return new Oe(Symbol("#:g".concat(n)))}}();function Ee(){}Ee.prototype.toString=Ee.prototype.toJSON=function(){return"()"};Ee.prototype.valueOf=function(){return F};Ee.prototype.append=function(e){return new Ae(e,Fe)};Ee.prototype.toArray=function(){return[]};var Fe=new Ee;function Ae(e,n){if(typeof this!=="undefined"&&this.constructor!==Ae||typeof this==="undefined"){return new Ae(e,n)}this.car=e;this.cdr=n}function Ie(a,o){return function e(n){bt(a,n,["pair","nil"]);if(n===Fe){return[]}var t=[];var r=n;while(true){if(r instanceof Ae){if(r.haveCycles("cdr")){break}var i=r.car;if(o&&i instanceof Ae){i=this.get(a).call(this,i)}t.push(i);r=r.cdr}else{break}}return t}}Ae.prototype.flatten=function(){return Ae.fromArray(xe(this.toArray()))};Ae.prototype.length=function(){var e=0;var n=this;while(true){if(!n||n===Fe||!(n instanceof Ae)||n.haveCycles("cdr")){break}e++;n=n.cdr}return e};Ae.prototype.clone=function(){var t=new Map;function r(e){if(e instanceof Ae){if(t.has(e)){return t.get(e)}var n=new Ae;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)};Ae.prototype.lastPair=function(){var e=this;while(true){if(e.cdr===Fe){return e}e=e.cdr}};Ae.prototype.toArray=function(){var e=[];if(this.car instanceof Ae){e.push(this.car.toArray())}else{e.push(this.car.valueOf())}if(this.cdr instanceof Ae){e=e.concat(this.cdr.toArray())}return e};Ae.fromArray=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:true;if(e instanceof Ae){return e}if(n===false){var t=Fe;for(var r=e.length;r--;){t=new Ae(e[r],t)}return t}if(e.length&&!(e instanceof Array)){e=Dt(e)}if(e.length===0){return Fe}else{var i;if(e[0]instanceof Array){i=Ae.fromArray(e[0])}else{i=e[0]}if(typeof i==="string"){i=Nn(i)}if(e.length===1){return new Ae(i,Fe)}else{return new Ae(i,Ae.fromArray(e.slice(1)))}}};Ae.prototype.toObject=function(){var e=arguments.length>0&&arguments[0]!==F?arguments[0]:false;var n=this;var t={};while(true){if(n instanceof Ae&&n.car instanceof Ae){var r=n.car;var i=r.car;if(i instanceof Oe){i=i.name}if(i instanceof String){i=i.valueOf()}var a=r.cdr;if(a instanceof Ae){a=a.toObject(e)}if(a instanceof Tn||a instanceof Nn||a instanceof In){if(!e){a=a.valueOf()}}t[i]=a;n=n.cdr}else{break}}return t};Ae.fromPairs=function(e){return e.reduce(function(e,n){return new Ae(new Ae(new Oe(n[0]),n[1]),e)},Fe)};Ae.fromObject=function(n){var e=Object.keys(n).map(function(e){return[e,n[e]]});return Ae.fromPairs(e)};Ae.prototype.reduce=function(e){var n=this;var t=Fe;while(true){if(n!==Fe){t=e(t,n.car);n=n.cdr}else{break}}return t};Ae.prototype.reverse=function(){if(this.haveCycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var n=Fe;while(e!==Fe){var t=e.cdr;e.cdr=n;n=e;e=t}return n};Ae.prototype.transform=function(r){function i(e){if(e instanceof Ae){if(e.replace){delete e.replace;return e}var n=r(e.car);if(n instanceof Ae){n=i(n)}var t=r(e.cdr);if(t instanceof Ae){t=i(t)}return new Ae(n,t)}return e}return i(this)};Ae.prototype.map=function(e){if(typeof this.car!=="undefined"){return new Ae(e(this.car),this.cdr===Fe?Fe:this.cdr.map(e))}else{return Fe}};var Ne=new Map;function Le(t){var e=t.constructor||Object;var r=Yt(t)==="object"&&e===Object;var i;if(Ne.has(e)){i=Ne.get(e)}else{Ne.forEach(function(e,n){if(t instanceof n&&(n===Object&&r||n!==Object)){i=e}})}return i}var qe=new Map;[[Number.NEGATIVE_INFINITY,"-inf.0"],[Number.POSITIVE_INFINITY,"+inf.0"],[true,"#t"],[false,"#f"],[null,"null"],[F,"#"]].forEach(function(e){var n=Jt(e,2),t=n[0],r=n[1];qe.set(t,r)});function Pe(t){if(t&&Yt(t)==="object"){var r={};var e=Object.getOwnPropertySymbols(t);e.forEach(function(e){var n=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");r[n]=Re(t[e])});var n=Object.getOwnPropertyNames(t);n.forEach(function(e){var n=t[e];if(Yt(n)==="object"&&n.constructor===Object){r[e]=Pe(n)}else{r[e]=Re(n)}});return r}return t}function Re(e,n,t){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(qe.has(e)){return qe.get(e)}if(e instanceof Ae){if(!t){e.markCycles()}return e.toString(n)}if(Number.isNaN(e)){return"+nan.0"}var r=[RegExp,Ee,Oe,Tn,In,ct];for(var i=0,a=r;i"}if(dn(e.toString)){return"#"}else{return e.toString()}}if(e instanceof Nn){e=e.toString()}if(e===null||typeof e==="string"&&n){return JSON.stringify(e)}if(Yt(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(Ce(e)){return"#"}var s=Le(e);if(s){if(typeof s==="function"){return s(e,n)}else{throw new Error("toString: Invalid repr value")}}c=u.name}if(_t(e)==="instance"&&!dn(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 Ce(e){return e&&Yt(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}Ae.prototype.markCycles=function(){Me(this);return this};Ae.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 Me(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 Ae){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 Ae){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 Ae){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")})}Ae.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=Re(this.car,e,true)}if(r!==F){t.push(r)}if(this.cdr instanceof Ae){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!==Fe){t=t.concat([" . ",Re(this.cdr,e,true)])}if(!n||this.ref){t.push(")")}return t.join("")};Ae.prototype.set=function(e,n){this[e]=n;if(n instanceof Ae){this.markCycles()}};Ae.prototype.append=function(e){if(e instanceof Array){return this.append(Ae.fromArray(e))}var n=this;if(n.car===F){if(e instanceof Ae){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(e!==Fe){while(true){if(n instanceof Ae&&n.cdr!==Fe){n=n.cdr}else{break}}n.cdr=e}return this};function Te(e){return e<0?-e:e}function Be(e,n){var t=$t(n),r=t[0],i=t.slice(1);while(i.length>0){var a=i,o=Jt(a,1),u=o[0];if(!e(r,u)){return false}var c=i;var s=$t(c);r=s[0];i=s.slice(1)}return true}function $e(e,n){if(typeof e==="function"&&typeof n==="function"){return rn(e)===rn(n)}else if(e instanceof Tn&&n instanceof Tn){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=Tn(e);n=Tn(n);return e.type===n.type&&e.cmp(n)===0}else if(e instanceof In&&n instanceof In){return e["char"]===n["char"]}else if(e instanceof Oe&&n instanceof Oe){return e.name===n.name}else{return e===n}}function De(e,n){if(_t(e)!==_t(n)){return false}if(!Ue(e)){return false}if(e instanceof RegExp){return e.source===n.source}if(e instanceof Nn){return e.valueOf()===n.valueOf()}return $e(e,n)}function Ue(e){return e instanceof Oe||Nn.isString(e)||e instanceof In||e instanceof Tn||e===true||e===false}var He=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function Je(e,n,t,r){if(typeof this!=="undefined"&&this.constructor!==Je||typeof this==="undefined"){return new Je(e,n)}bt("Macro",e,"string",1);bt("Macro",n,"function",2);if(t){if(r){this.__doc__=t}else{this.__doc__=ie(t)}}this.name=e;this.fn=n}Je.defmacro=function(e,n,t,r){var i=new Je(e,n,t,r);i.defmacro=true;return i};Je.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};Je.prototype.toString=function(){return"#"};var Ye="define-macro";var Ge=-1e4;function Ve(a){return function(){var t=Bt(Tt.mark(function e(t,v){var r,d,i;return Tt.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:i=function e(){i=Bt(Tt.mark(function e(t,r,i){var a,o,u,c,s,f,l,p,h;return Tt.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(!(t instanceof Ae&&t.car instanceof Oe)){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 Je&&a.defmacro)){n.next=24;break}o=a instanceof ze?t:t.cdr;n.next=8;return a.invoke(o,v,true);case 8:u=n.sent;if(!(a instanceof ze)){n.next=17;break}c=u,s=c.expr,f=c.scope;if(!(s instanceof Ae)){n.next=16;break}if(!(r!==-1&&r<=1||r"};ze.className="syntax";function We(e,n,b,w){var _={"...":{symbols:{},lists:[]}};function x(e){if(lt.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&&Re(n,true),pattern:e&&Re(e,true)});if(Ue(e)&&!(e instanceof Oe)){return De(e,n)}if(e instanceof Oe&&b.includes(e.valueOf())){return Oe.is(n,e)}if(e instanceof Ae&&e.car instanceof Ae&&e.car.cdr instanceof Ae&&Oe.is(e.car.cdr.car,w)){x(">> 0");if(n===Fe){x({pattern:e.toString()});if(e.car.car instanceof Oe){if(e.car.cdr instanceof Ae&&Oe.is(e.car.cdr.car,w)){var i=e.car.car.valueOf();var a=e.lastPair();if(Oe.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 Ae&&e.cdr instanceof Ae&&Oe.is(e.cdr.car,w)){if(e.cdr.cdr!==Fe){if(e.cdr.cdr instanceof Ae){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=Fe;if(!S(e.cdr.cdr,f,t,r)){return false}}}if(e.car instanceof Oe){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===Fe){x(">> 2");if(r){x("NIL");_["..."].symbols[l]=Fe}else{x("NULL");_["..."].symbols[l]=null}}else if(n instanceof Ae&&(n.car instanceof Ae||n.car===Fe)){x(">> 3 "+r);if(r){if(_["..."].symbols[l]){var p=_["..."].symbols[l];_["..."].symbols[l]=p.append(new Ae(n,Fe))}else{_["..."].symbols[l]=new Ae(n,Fe)}}else{x(">> 4");_["..."].symbols[l]=new Ae(n,Fe)}}else{x(">> 6");if(n instanceof Ae){x(">> 7 "+r);t.push(l);if(!_["..."].symbols[l]){_["..."].symbols[l]=new Ae(n,Fe)}else{var h=_["..."].symbols[l];_["..."].symbols[l]=h.append(new Ae(n,Fe))}x({IIIIII:_["..."].symbols[l].toString()})}else{x(">> 8");return false}}return true}else if(e.car instanceof Ae){var v=Dt(t);if(n===Fe){x(">> 9");_["..."].lists.push(Fe);return true}x(">> 10");var d=n;while(d instanceof Ae){if(!S(e.car,d.car,v,true)){return false}d=d.cdr}return true}return false}if(e instanceof Oe){if(Oe.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 Ae&&n instanceof Ae){x(">> 12");x({a:12,code:n&&n.toString(),pattern:e.toString()});if(n.cdr===Fe){var y=e.car instanceof Oe&&e.cdr instanceof Oe;if(y){x(">> 12 | 1");var g=e.cdr.valueOf();if(!_[g]){_[g]=Fe}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===Fe&&(n===Fe||n===F)){return true}else if(e.car instanceof Ae&&Oe.is(e.car.car,w)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(S(e,n)){return _}}function Qe(e,i){function a(n){if(n instanceof Ae){if(!i.length){return n}var e=a(n.car);var t=a(n.cdr);return new Ae(e,t)}else if(n instanceof Oe){var r=i.find(function(e){return e.gensym===n});if(r){return Oe(r.name)}return n}else{return n}}return a(e)}function Ke(){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 Oe||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=Yt(n);if(["string","symbol"].includes(t)&&n in w){return w[n]}if(i.includes(n)){return Oe(n)}return u(n)}function S(e){if(lt.get("DEBUG",{throwError:false})){console.log(e)}}function u(e){if(!o[e]){var n=r.get(e,{throwError:false});var t=je(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 Oe){var a=e.valueOf();S("[t 1");if(n[a]){if(n[a]instanceof Ae){var o=n[a],u=o.car,c=o.cdr;if(i){var s=u.car,f=u.cdr;if(f!==Fe){r(a,new Ae(f,Fe))}return s}if(c!==Fe){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 Ae){if(e.car instanceof Oe&&e.cdr instanceof Ae&&Oe.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 Ae){S("[t 2 Pair "+i);S({______:p.toString()});var h=p.car,v=p.cdr;if(i){if(v!==Fe){r(l,v)}return h}else{if(h.cdr!==Fe){r(l,new Ae(h.cdr,v))}return h.car}}else if(p instanceof Array){S("[t 2 Array "+i);if(i){r(l,p.slice(1));return Ae.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 Ae(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,Dt(r.map(function(e){return n[e]})))}return e.length&&e.every(function(e){if(e===null){return!t}return e instanceof Ae||e===Fe||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 Ae){if(!n&&i.car instanceof Ae&&Oe.is(i.car.car,_)){return E(i.car.cdr,{disabled:true})}if(i.cdr instanceof Ae&&Oe.is(i.cdr.car,_)&&!n){S(">> 1");var t=w["..."].symbols;var r=j(t);if(i.car instanceof Ae){if(w["..."].lists[0]===Fe){return Fe}S(">> 2");var a;if(r.length){S(">> 2 (a)");var o=Vt({},t);a=Fe;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 Ae(t,a)}o=r};while(true){var c=u();if(c==="break")break}if(a!==Fe){a=a.reverse()}return a}else{S(">> 3");var s=O(i.car,t,{nested:true});if(s){return new Ae(s,Fe)}return Fe}}else if(i.car instanceof Oe){S(">> 4");var f=i.car.name;var l=Ut({},f,t[f]);var p=t[f]===null;var h=Fe;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 Ae(t,h)}l=r};while(true){var d=v();if(d==="break")break}if(h!==Fe){h=h.reverse()}if(i.cdr instanceof Ae){if(i.cdr.cdr instanceof Ae||i.cdr.cdr instanceof Oe){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 Ae(y,g)}if(i instanceof Oe){if(n&&Oe.is(i,_)){return i}var b=x(i);if(typeof b!=="undefined"){return b}}return i}return E(n,{})}function Xe(e){return typeof e==="undefined"||e===Fe||e===null}function Ze(e){return e instanceof Promise||e&&typeof e!=="undefined"&&typeof e.then==="function"}function en(e){switch(Yt(e)){case"string":return Nn(e);case"number":if(!Number.isNaN(e)){return Tn(e)}}return e}function nn(e){if(e&&e.valueOf){return e.valueOf()}return e}function tn(e,n){if(e instanceof Ae){e.markCycles();return st(e)}if(typeof e==="function"){if(n){return an(e,n)}}return en(e)}function rn(e){if(on(e)){return e[fn]}return e}function an(n,e){if(n[Symbol["for"]("__bound__")]){return n}var t=n.bind(e);var r=Object.getOwnPropertyNames(n).filter(pn);r.forEach(function(e){try{t[e]=n[e]}catch(e){}});hn(t,"__fn__",n);hn(t,"__context__",e);hn(t,"__bound__",true);if(dn(n)){hn(t,"__native__",true)}t.valueOf=function(){return n};return t}function on(e){return!!(typeof e==="function"&&e[fn])}function un(e){if(typeof e==="function"){var n=e[sn];if(n&&(n===Rt||n.constructor&&n.constructor.__className)){return true}}return false}function cn(e){function n(e){return e instanceof Zn||e instanceof et}if(typeof e==="function"){if(n(e)){return true}if(n(e[sn])){return true}}return false}var sn=Symbol["for"]("__context__");var fn=Symbol["for"]("__fn__");var ln=["name","length","caller","callee","arguments","prototype"];function pn(e){return!ln.includes(e)}function hn(e,n,t){Object.defineProperty(e,Symbol["for"](n),{get:function e(){return t},set:function e(){},configurable:false,enumerable:false})}function vn(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 dn(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 mn(e){var d;switch(e){case Symbol["for"]("letrec"):d="letrec";break;case Symbol["for"]("let"):d="let";break;case Symbol["for"]("let*"):d="let*";break;default:throw new Error("Invalid let_macro value")}return Je.defmacro(d,function(n,e){var o=e.dynamic_scope,u=e.error,t=e.macro_expand;var c;if(n.car instanceof Oe){if(!(n.cdr.car instanceof Ae||n.cdr.car===Fe)){throw new Error("let require list of pairs")}var r;if(n.cdr.car===Fe){c=Fe;r=Fe}else{r=n.cdr.car.map(function(e){return e.car});c=n.cdr.car.map(function(e){return e.cdr.car})}return Ae.fromArray([Oe("letrec"),[[n.car,Ae(Oe("lambda"),Ae(r,n.cdr.cdr))]],Ae(n.car,c)])}else if(t){return}var s=this;c=this.get("list->array")(n.car);var f=s.inherit(d);var l,p;if(d==="let*"){p=f}else if(d==="let"){l=[]}var h=0;function v(){var e=new Ae(new Oe("begin"),n.cdr);return jt(e,{env:f,dynamic_scope:o,error:u})}return function n(){var t=c[h++];function r(e,n){if(typeof n==="undefined"){f.set(e,Fe)}else{f.set(e,n)}}if(o){o=d==="let*"?f:s}if(!t){if(l&&l.length){var e=l.map(function(e){return e.value});var i=e.filter(Ze);if(i.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 Ae){o.push(jt(a.car,{env:i,dynamic_scope:t,error:r}));a=a.cdr}var u=o.filter(Ze).length;if(u){return Promise.all(o).then(c.bind(this))}else{return c.call(this,o)}})}function gn(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 En(r,i){bt("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 Tn){return e}if(typeof this!=="undefined"&&!(this instanceof Tn)||typeof this==="undefined"){return new Tn(e,n)}if(typeof e==="undefined"){throw new Error("Invlaid LNumber constructor call")}var t=Tn.getType(e);if(Tn.types[t]){return Tn.types[t](e,n)}var r=e instanceof Array&&Nn.isString(e[0])&&Tn.isNumber(e[1]);if(e instanceof Tn){return Tn(e.value)}if(!Tn.isNumber(e)&&!r){throw new Error("You can't create LNumber from ".concat(_t(e)))}if(e===null){e=0}var i;if(r){var a=e,o=Jt(a,2),u=o[0],c=o[1];if(u instanceof Nn){u=u.valueOf()}if(c instanceof Tn){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=Dt(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 Gn(i,true)}else if(typeof h!=="undefined"&&!(e instanceof h)){if(e instanceof Array){return Gn(Mt(h,Dt(e)))}return Gn(new h(e))}else if(r){this.value=parseInt(u,c)}else{this.value=e}}Tn.types={float:function e(n){var t=arguments.length>1&&arguments[1]!==F?arguments[1]:false;return new $n(n,t)},complex:function e(n){var t=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(!Tn.isComplex(n)){n={im:0,re:n}}return new Bn(n,t)},rational:function e(n){var t=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(!Tn.isRational(n)){n={num:n,denom:1}}return new Yn(n,t)}};function Bn(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof Bn)||typeof this==="undefined"){return new Bn(e,n)}if(e instanceof Bn){return Bn({im:e.im,re:e.re})}if(Tn.isNumber(e)&&n){e={im:0,re:e.valueOf()}}else if(!Tn.isComplex(e)){throw new Error("Invalid constructor call for LComplex")}var t=e.im instanceof Tn?e.im:Tn(e.im);var r=e.re instanceof Tn?e.re:Tn(e.re);if(t.cmp(0)===0&&!n){return r}this.im=t;this.re=r;this.type="complex"}Bn.prototype=Object.create(Tn.prototype);Bn.prototype.constructor=Bn;Bn.prototype.toRational=function(e){if(Tn.isFloat(this.im)&&Tn.isFloat(this.re)){var n=$n(this.im).toRational(e);var t=$n(this.re).toRational(e);return Bn({im:n,re:t})}return this};Bn.prototype.add=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.add(n),im:t.add(r)}})};Bn.prototype.factor=function(){if(this.im instanceof $n||this.im instanceof $n){var e=this.re,n=this.im;var t,r;if(e instanceof $n){t=e.toRational().mul(e.toRational())}else{t=e.mul(e)}if(n instanceof $n){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))}};Bn.prototype.modulus=function(){return this.factor().sqrt()};Bn.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=$n(.5).mul(e.add(this.re)).sqrt();t=this.im.div(n).div(2)}else{t=$n(.5).mul(e.sub(this.re)).sqrt();if(this.im.cmp(0)===-1){t=t.sub()}n=this.im.div(t).div(2)}return Bn({im:t,re:n})};Bn.prototype.div=function(e){if(Tn.isNumber(e)&&!Tn.isComplex(e)){e=Bn({im:0,re:e})}else if(!Tn.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var n=this.coerce(e),t=Jt(n,2),r=t[0],i=t[1];var a=Bn({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 Bn({re:c,im:s})};Bn.prototype.sub=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.sub(n),im:t.sum(r)}})};Bn.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})};Bn.prototype.complex_op=function(e,n){if(Tn.isNumber(e)&&!Tn.isComplex(e)){if(!(e instanceof Tn)){e=Tn(e)}var t=e.asType(0);e={im:t,re:e}}else if(!Tn.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var r=e.re instanceof Tn?e.re:this.re.asType(e.re);var i=e.im instanceof Tn?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=Bn(a,true);return o}return a};Bn._op={"+":"add","-":"sub","*":"mul","/":"div"};Bn.prototype._op=function(e,n){var t=Bn._op[e];return this[t](n)};Bn.prototype.cmp=function(e){var n=this.coerce(e),t=Jt(n,2),r=t[0],i=t[1];var a=r.re.coerce(i.re),o=Jt(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=Jt(f,2),p=l[0],h=l[1];return p.cmp(h)}};Bn.prototype.valueOf=function(){};Bn.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 $n(e){if(typeof this!=="undefined"&&!(this instanceof $n)||typeof this==="undefined"){return new $n(e)}if(!Tn.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof Tn){return $n(e.valueOf())}if(typeof e==="number"){this.value=e;this.type="float"}}$n.prototype=Object.create(Tn.prototype);$n.prototype.constructor=$n;$n.prototype.toString=function(){var e=this.value.toString();if(!Tn.isFloat(this.value)&&!e.match(/e/i)){return e+".0"}return e.replace(/^([0-9]+)e/,"$1.0e")};$n.prototype._op=function(e,n){if(n instanceof Tn){n=n.value}var t=Tn._ops[e];return $n(t(this.value,n))};$n.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==F?arguments[0]:null;if(e===null){return Dn(this.value.valueOf())}return Un(e.valueOf())(this.value.valueOf())};var Dn=Un(1e-10);function Un(r){return function(e){var n=function e(r,n,t){var i=function e(n,t){return t0){i=Jn(r,t)}else if(r.cmp(t)<=0){i=t}else if(t.cmp(0)>0){i=Jn(t,r)}else if(n.cmp(0)<0){i=Tn(Jn(r.sub(),t.sub())).sub()}else{i=Tn(0)}if(Tn.isFloat(n)||Tn.isFloat(e)){return $n(i)}return i}function Jn(e,n){var t=Tn(e).floor();var r=Tn(n).floor();if(e.cmp(t)<1){return t}else if(t.cmp(r)===0){var i=Tn(1).div(n.sub(r));var a=Tn(1).div(e.sub(t));return t.add(Tn(1).div(Jn(i,a)))}else{return t.add(Tn(1))}}function Yn(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof Yn)||typeof this==="undefined"){return new Yn(e,n)}if(!Tn.isRational(e)){throw new Error("Invalid constructor call for LRational")}var t=Tn(e.num);var r=Tn(e.denom);if(!n&&r.cmp(0)!==0){var i=t.op("%",r).cmp(0)===0;if(i){return Tn(t.div(r))}}this.num=t;this.denom=r;this.type="rational"}Yn.prototype=Object.create(Tn.prototype);Yn.prototype.constructor=Yn;Yn.prototype.pow=function(e){var n=e.cmp(0);if(n===0){return Tn(1)}if(n===-1){e=e.sub();var t=this.denom.pow(e);var r=this.num.pow(e);return Yn({num:t,denom:r})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};Yn.prototype.sqrt=function(){var e=this.num.sqrt();var n=this.denom.sqrt();if(e instanceof $n){e=(Ct("num"),e.toRational())}if(n instanceof $n){n=(Ct("denom"),n.toRational())}return Yn({num:e,denom:n})};Yn.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 Yn({num:e,denom:n})};Yn.prototype.cmp=function(e){return Tn(this.valueOf(),true).cmp(e)};Yn.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 Yn){n=Tn(n.valueOf(true))}t=this.denom.div(e);if(t instanceof Yn){t=Tn(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()};Yn.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 Tn._ops["/"](this.num.value,this.denom.value)}return $n(this.num.valueOf()).div(this.denom.valueOf())};Yn.prototype.mul=function(e){if(!(e instanceof Tn)){e=Tn(e)}if(Tn.isRational(e)){var n=this.num.mul(e.num);var t=this.denom.mul(e.denom);return Yn({num:n,denom:t})}var r=Tn.coerce(this,e),i=Jt(r,2),a=i[0],o=i[1];return a.mul(o)};Yn.prototype.div=function(e){if(!(e instanceof Tn)){e=Tn(e)}if(Tn.isRational(e)){var n=this.num.mul(e.denom);var t=this.denom.mul(e.num);return Yn({num:n,denom:t})}var r=Tn.coerce(this,e),i=Jt(r,2),a=i[0],o=i[1];var u=a.div(o);return u};Yn.prototype._op=function(e,n){return this[Qn[e]](n)};Yn.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof Tn)){e=Tn(e)}if(Tn.isRational(e)){var n=e.num.sub();var t=e.denom;return this.add(Yn({num:n,denom:t}))}if(!(e instanceof Tn)){e=Tn(e).sub()}else{e=e.sub()}var r=Tn.coerce(this,e),i=Jt(r,2),a=i[0],o=i[1];return a.add(o)};Yn.prototype.add=function(e){if(!(e instanceof Tn)){e=Tn(e)}if(Tn.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 Yn({num:o,denom:a})}if(Tn.isFloat(e)){return $n(this.valueOf()).add(e)}var u=Tn.coerce(this,e),c=Jt(u,2),s=c[0],f=c[1];return s.add(f)};function Gn(e,n){if(typeof this!=="undefined"&&!(this instanceof Gn)||typeof this==="undefined"){return new Gn(e,n)}if(e instanceof Gn){return Gn(e.value,e._native)}if(!Tn.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.value=e;this._native=n;this.type="bigint"}Gn.prototype=Object.create(Tn.prototype);Gn.prototype.constructor=Gn;Gn.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};Gn.prototype._op=function(e,n){if(typeof n==="undefined"){if(Tn.isBN(this.value)){e=Gn.bn_op[e];return Gn(this.value.clone()[e](),false)}return Gn(Tn._ops[e](this.value),true)}if(Tn.isBN(this.value)&&Tn.isBN(n.value)){e=Gn.bn_op[e];return Gn(this.value.clone()[e](n),false)}var t=Tn._ops[e](this.value,n.value);if(e==="/"){var r=this.op("%",n).cmp(0)===0;if(r){return Tn(t)}return Yn({num:this,denom:n})}return Gn(t,true)};Gn.prototype.sqrt=function(){var e;var n=this.cmp(0)<0;if(Tn.isNative(this.value)){e=Tn(Math.sqrt(n?-this.valueOf():this.valueOf()))}else if(Tn.isBN(this.value)){e=n?this.value.neg().sqrt():this.value.sqrt()}if(n){return Bn({re:0,im:e})}return e};Tn.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}}};Tn.isFloat=function e(n){return n instanceof $n||Number(n)===n&&n%1!==0};Tn.isNumber=function(e){return e instanceof Tn||!Number.isNaN(e)&&Tn.isNative(e)||Tn.isBN(e)};Tn.isComplex=function(e){var n=e instanceof Bn||Tn.isNumber(e.im)&&Tn.isNumber(e.re);return n};Tn.isRational=function(e){return e instanceof Yn||Tn.isNumber(e.num)&&Tn.isNumber(e.denom)};Tn.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};Tn.isBigInteger=function(e){return e instanceof Gn||typeof e==="bigint"||Tn.isBN(e)};Tn.isBN=function(e){return typeof h!=="undefined"&&e instanceof h};Tn.getArgsType=function(e,n){if(e instanceof $n||n instanceof $n){return $n}if(e instanceof Gn||n instanceof Gn){return Gn}return Tn};Tn.prototype.toString=Tn.prototype.toJSON=function(e){if(e>2&&e<36){return this.value.toString(e)}return this.value.toString()};Tn.prototype.asType=function(e){var n=Tn.getType(this);return Tn.types[n]?Tn.types[n](e):Tn(e)};Tn.prototype.isBigNumber=function(){return typeof this.value==="bigint"||typeof h!=="undefined"&&!(this.value instanceof h)};["floor","ceil","round"].forEach(function(e){Tn.prototype[e]=function(){if(this["float"]||Tn.isFloat(this.value)){return Tn(Math[e](this.value))}else{return Tn(Math[e](this.valueOf()))}}});Tn.prototype.valueOf=function(){if(Tn.isNative(this.value)){return Number(this.value)}else if(Tn.isBN(this.value)){return this.value.toNumber()}};var Vn=function(){var e=function e(n,t){return[n,t]};return{bigint:{bigint:e,float:function e(n,t){return[$n(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&&$n(t.valueOf())]},float:e,rational:function e(n,t){return[n,t&&$n(t.valueOf())]},complex:function e(n,t){return[{re:n,im:$n(0)},t]}},complex:{bigint:n("bigint"),float:n("float"),rational:n("rational"),complex:function e(n,t){var r=Tn.coerce(n.re,t.re),i=Jt(r,2),a=i[0],o=i[1];var u=Tn.coerce(n.im,t.im),c=Jt(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[$n(n.valueOf()),t]},rational:e,complex:function e(n,t){return[{im:zn(n.type,t.im.type,0),re:zn(n.type,t.re.type,n)},{im:zn(n.type,t.im.type,t.im),re:zn(n.type,t.re.type,t.re)}]}}};function n(t){return function(e,n){return[{im:zn(t,e.im.type,e.im),re:zn(t,e.re.type,e.re)},{im:zn(t,e.im.type,0),re:zn(t,n.type,n)}]}}}();function zn(e,n,t){return Vn[e][n](t)[0]}Tn.coerce=function(e,n){function t(e){if(e==="integer"){return"bigint"}return e}var r=t(Tn.getType(e));var i=t(Tn.getType(n));if(!Vn[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!Vn[r][i]){throw new Error("LNumber::coerce unknown rhs type ".concat(i))}return Vn[r][i](e,n).map(function(e){return Tn(e,true)})};Tn.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof Tn)){throw new Error("LNumber: you can't coerce ".concat(_t(e)))}if(typeof e==="number"){e=Tn(e)}return Tn.coerce(this,e)};Tn.getType=function(e){if(e instanceof Tn){return e.type}if(Tn.isFloat(e)){return"float"}if(Tn.isComplex(e)){return"complex"}if(Tn.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"}};Tn.prototype.isFloat=function(){return!!(Tn.isFloat(this.value)||this["float"])};var Wn={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var Qn={};Object.keys(Wn).forEach(function(n){Qn[Wn[n]]=n;Tn.prototype[n]=function(e){return this.op(Wn[n],e)}});Tn._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 rt}return In(this._string[this._in_char])};function et(e){if(typeof this!=="undefined"&&!(this instanceof et)||typeof this==="undefined"){return new et(e)}bt("OutputPort",e,"function");this.write=e}et.prototype.toString=function(){return"<#output-port>"};function nt(n){var t=this;if(typeof this!=="undefined"&&!(this instanceof nt)||typeof this==="undefined"){return new nt(n)}bt("OutputStringPort",n,"function");this._buffer=[];this.write=function(e){if(!Nn.isString(e)){e=n(e)}else{e=e.valueOf()}t._buffer.push(e)}}nt.prototype=Object.create(et.prototype);nt.prototype.getString=function(){return this._buffer.map(function(e){return e.valueOf()}).join("")};nt.prototype.constructor=nt;function tt(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof tt)||typeof this==="undefined"){return new tt(e)}bt("InputStringPort",e,"string");this._string=e.valueOf();this._index=0;this._in_char=0;this.read=function(){return n.get_next_tokens()}}tt.prototype=Object.create(Zn.prototype);tt.prototype.constructor=tt;tt.prototype.read_line=function(){var e=this._string.substring(this._in_char);if(!e){return rt}var n=e.match(/([^\n])(?:\n|$)/)[0];this._in_char+=n.length;return n};var rt=new it;function it(){}it.prototype.toString=function(){return"<#eof>"};function at(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:{};if(typeof this!=="undefined"&&!(this instanceof at)||typeof this==="undefined"){return new at(e,n)}if(typeof e==="undefined"){e="anonymous"}this.env=lt.inherit(e,n)}at.prototype.exec=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:false;bt("Intepreter::exec",e,"string",1);bt("Intepreter::exec",n,"boolean",2);ft.set("**interaction-environment**",this.env);return Et(e,this.env,n?this.env:false)};at.prototype.get=function(e){return this.env.get(e).bind(this.env)};at.prototype.set=function(e,n){return this.env.set(e,n)};function ot(e,n,t){if(arguments.length===1){if(Yt(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"}ot.prototype.inherit=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:{};if(Yt(e)==="object"){n=e}if(!e||Yt(e)==="object"){e="child of "+(this.name||"unknown")}return new ot(n||{},this,e)};ot.prototype.doc=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:null;if(e instanceof Oe){e=e.name}if(e instanceof Nn){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)}};ot.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 ot)){return Fe}if(e<=0){return n}var t=n.get("parent.frame");return t(e-1)},ft.env["parent.frame"].__doc__));n.callee=e;r.set("arguments",n);return r};ot.prototype._lookup=function(e){if(e instanceof Oe){e=e.name}if(e instanceof Nn){e=e.valueOf()}if(this.env.hasOwnProperty(e)){return ut(this.env[e])}if(this.parent){return this.parent._lookup(e)}};ot.prototype.toString=function(){return"<#env:"+this.name+">"};ot.prototype.clone=function(){var n=this;var t={};Object.keys(this.env).forEach(function(e){t[e]=n.env[e]});return new ot(t,this.parent,this.name)};ot.prototype.merge=function(e){var n=arguments.length>1&&arguments[1]!==F?arguments[1]:"merge";bt("Environment::merge",e,"environment");return this.inherit(n,e.env)};function ut(e){if(typeof this!=="undefined"&&!(this instanceof ut)||typeof this==="undefined"){return new ut(e)}this.value=e}ut.isUndefined=function(e){return e instanceof ut&&typeof e.value==="undefined"};ut.prototype.valueOf=function(){return this.value};function ct(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof ct)||typeof this==="undefined"){return new ct(e)}this.values=e}ct.prototype.toString=function(){return this.values.map(function(e){return Re(e)}).join("\n")};ct.prototype.valueOf=function(){return this.values};ot.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 Oe||i instanceof Nn){i=i.valueOf()}var a=this._lookup(i);if(a instanceof ut){if(ut.isUndefined(a)){return F}return tn(a.valueOf())}if(typeof i==="string"){var o=i.split(".").filter(Boolean);if(o.length>0){var u=$t(o),c=u[0],s=u.slice(1);a=this._lookup(c);if(s.length){try{if(a instanceof ut){a=a.valueOf()}else{a=An(f,c);if(typeof a==="function"){a=rn(a)}}return An.apply(void 0,[a].concat(Dt(s)))}catch(e){}}else if(a instanceof ut){return tn(a.valueOf())}}a=An(f,i)}if(typeof a!=="undefined"){return a}if(r){throw new Error("Unbound variable `"+i.toString()+"'")}};ot.prototype.set=function(e,n){var t=arguments.length>2&&arguments[2]!==F?arguments[2]:null;if(Tn.isNumber(n)){n=Tn(n)}if(e instanceof Oe){e=e.name}if(e instanceof Nn){e=e.valueOf()}this.env[e]=n;if(t){this.doc(e,t)}return this};ot.prototype.has=function(e){return this.env.hasOwnProperty(e)};ot.prototype.ref=function(e){var n=this;while(true){if(!n){break}if(n.has(e)){return n}n=n.parent}};ot.prototype.parents=function(){var e=this;var n=[];while(e){n.unshift(e);e=e.parent}return n};function st(e){if(Ze(e)){return e.then(st)}if(e instanceof Ae||e instanceof Oe){e.data=true}return e}var ft=new ot({nil:Fe,undefined:F,true:true,false:false,null:null,NaN:NaN,stdout:new et(function(){var e;(e=console).log.apply(e,arguments)}),stdin:Zn(function(){return new Promise(function(e){e(prompt(""))})}),"open-input-string":re(function(e){bt("open-input-string",e,"string");return tt(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 et},"(output-port? arg)\n\n Function return true if argument is output port."),"input-port?":re(function(e){return e instanceof Zn},"(input-port? arg)\n\n Function return true if argument is input port."),"open-output-string":re(function(){return nt(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){bt("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===rt},"(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){bt("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")}bt("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")}bt("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(Nn.isString(n)){return ee(W(n.valueOf()))[0]}var t;if(n instanceof Zn){t=n}else{t=this.get("stdin")}return ne(t.read(),function(e){if(e===rt){return rt}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 Ae){e=new Rt.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=jt(e.cdr.car,{env:this,dynamic_scope:t,error:r});i=xt(i);function u(n,t){if(Ze(n)){return n.then(function(e){return u(e,t)})}if(Ze(t)){return t.then(function(e){return u(n,e)})}f[n]=t;return t}if(e.car instanceof Ae&&Oe.is(e.car.car,".")){var c=e.car.cdr.car;var s=e.car.cdr.cdr.car;var f=jt(c,{env:this,dynamic_scope:t,error:r});var l=jt(s,{env:this,dynamic_scope:t,error:r});return u(l,i)}if(!(e.car instanceof Oe)){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 Je("set!",function(e){if(!(e.car instanceof Oe)){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){bt("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){bt("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===Fe},"(empty? object)\n\n Function return true if value is undfined empty list."),assoc:re(function(e,n){if(e instanceof Ae&&!(n instanceof Ae)){throw new Error("First argument to assoc ned to be a key")}bt("assoc",n,"pair");var t=n;while(true){if(!(t instanceof Ae)||this.get("empty?")(t)){break}var r=t.car.car;if($e(r,e)){return t.car}else if(!t.haveCycles("cdr")){t=t.cdr}}return Fe},"(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(je,"(gensym)\n\n Function generate unique symbol, to use with macros as meta name."),load:re(function(n){bt("load",n,"string");var e=this;if(e.name==="__frame__"){e=e.parent}var i;if(e===ft){i=e}else{i=this.get("**interaction-environment**")}var a="**module-path**";var o=ft.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)}ft.set(a,e.dirname(n));require("fs").readFile(n,function(e,n){if(e){console.log(e);r(e);ft.set(a,o)}else{Et(n.toString(),i).then(function(){t();ft.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){ft.set(a,n.replace(/\/[^/]*$/,""));return Et(e,i)}).then(function(){})["finally"](function(){ft.set(a,o)})},"(load filename)\n\n Function fetch the file and evaluate its content as LIPS code."),while:re(new Je("while",function(r,e){var i=e.dynamic_scope,a=e.error;var o=this;var u=new Ae(new Oe("begin"),r.cdr);var c;if(i){i=o}return function n(){var e=jt(r.car,{env:o,dynamic_scope:i,error:a});function t(e){if(e&&!Xe(e)){c=jt(u,{env:o,dynamic_scope:i,error:a});if(Ze(c)){return c.then(function(e){c=e;return n()})}else{return n()}}else{return c}}return ne(e,t)}()}),"(while cond . body)\n\n Macro that create a loop, it exectue body untill cond expression is false"),if:re(new Je("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 jt(t.cdr.car,{env:a,dynamic_scope:r,error:i})}else{return jt(t.cdr.cdr.car,{env:a,dynamic_scope:r,error:i})}};var o=jt(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 Je("let-env",function(n){var e=arguments.length>1&&arguments[1]!==F?arguments[1]:{};var t=e.dynamic_scope,r=e.error;bt("let-env",n,"pair");var i=jt(n.car,{env:this,dynamic_scope:t,error:r});return ne(i,function(e){if(!(e instanceof ot)){throw new Error("let-env: First argument need to be "+"environment")}return jt(Ae(Oe("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(mn(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(mn(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(mn(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(yn("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 Je("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=jt(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 Je("ignore",function(e,n){var t=n.dynamic_scope,r=n.error;var i={env:this,error:r};if(t){i.dynamic_scope=this}jt(new Ae(new Oe("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(Je.defmacro("define",function(t,e){var r=this;if(t.car instanceof Ae&&t.car.car instanceof Oe){var n=new Ae(new Oe("define"),new Ae(t.car.car,new Ae(new Ae(new Oe("lambda"),new Ae(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 Ae){i=jt(i,e)}else if(i instanceof Oe){i=r.get(i)}bt("define",t.car,"symbol");return ne(i,function(e){if(r.name===ze.merge_env){r=r.parent}var n;if(t.cdr.cdr instanceof Ae&&Nn.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=Yt(e);if(Xe(e)||r!=="object"&&r!=="function"){var i=gt("set-obj!",_t(e),["object","function"]);throw new Error(i)}e=rn(e);n=n.valueOf();if(arguments.length===2){delete e[n]}else if(Ce(e)&&typeof t==="function"){e[n]=rn(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 ft.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 Ae&&Nn.isString(l.cdr.car)&&l.cdr.cdr!==Fe){d=l.cdr.car.valueOf()}function m(){var e;if(p){if(!(this instanceof ot)){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 Ae){var r=e.car;var i=e.cdr;if(t(r)){r=n(r)}if(t(i)){i=n(i)}if(Ze(r)||Ze(i)){return Promise.all([r,i]).then(function(e){var n=Jt(e,2),t=n[0],r=n[1];return new Ae(t,r)})}else{return new Ae(r,i)}}return e}function i(e,n){if(e instanceof Ae){if(n!==Fe){e.append(n)}}else{e=new Ae(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 Ae){if(e.cdr.cdr!==Fe){if(e.cdr.car instanceof Ae){var i=Fe;return function n(t){if(t===Fe){return i}return ne(jt(t.car,{env:u,dynamic_scope:a,error:o}),function(e){i=new Ae(e,i);return n(t.cdr)})}(e.cdr)}else{return e.cdr}}else{return jt(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 Ae){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 st(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){bt("clone",e,"pair");return e.clone()},"(clone list)\n\n Function return clone of the list."),append:re(function(e,n){bt("append",e,["nil","pair"]);if(e instanceof Ae){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){bt("append!",e,["pair","nil"]);if(!this.get("list?")(e)){throw new Error("append!: Invalid argument, value is not a list")}if(Xe(n)){return e}if(e===Fe){if(n===Fe){return Fe}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){bt("reverse",e,["array","pair","nil"]);if(e===Fe){return Fe}if(e instanceof Ae){var n=this.get("list->array")(e).reverse();return this.get("array->list")(n)}else if(!(e instanceof Array)){throw new Error(gt("reverse",_t(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){bt("nth",e,"number");bt("nth",n,["array","pair"]);if(n instanceof Ae){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){bt("split",e,["regex","string"]);bt("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){bt("replace",e,["regex","string"]);bt("replace",n,["string","function"]);bt("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){bt("match",e,["regex","string"]);bt("match",n,"string");var t=n.match(e);return t?this.get("array->list")(t):Fe},"(match pattern string)\n\n function return match object from JavaScript as list."),search:re(function(e,n){bt("search",e,["regex","string"]);bt("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 Re(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=Ae.fromArray(n)}else{t=Fe}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;bt("set-special!",e,"string",1);bt("set-special!",n,"symbol",2);Rt.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:An,".":An,unbind:re(rn,"(unbind fn)\n\n Function remove bidning from function so you can get props from it."),type:re(_t,"(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 Oe||e instanceof Nn){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 rn(e)},"(instanceof type obj)\n\n Function check of object is instance of object."),"macro?":re(function(e){return e instanceof Je},"(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(_t(e)!=="number"){return false}if(e instanceof Tn){return e.isFloat()}return Tn.isFloat(e)},"(real? number)\n\n Function check if value is real number."),"number?":re(Tn.isNumber,"(number? expression)\n\n Function check if value is a number"),"string?":re(function(e){return Nn.isString(e)},"(string? expression)\n\n Function check if value is a string."),"pair?":re(function(e){return e instanceof Ae},"(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 Xe(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 Oe},"(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!==Fe&&e!==null&&!(e instanceof Tn)&&Yt(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Function check if value is an object."),flatten:re(function(e){bt("flatten",e,"pair");return e.flatten()},"(flatten list)\n\n Return shallow list from tree structure (pairs)."),"array->list":re(function(e){bt("array->list",e,"array");return Ae.fromArray(e)},"(array->list array)\n\n Function convert JavaScript array to LIPS list."),"tree->array":re(Ie("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":re(Ie("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 Tn(0)}if(e instanceof Ae){return Tn(e.length())}if("length"in e){return Tn(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;bt("string->number",e,"string",1);bt("string->number",n,"number",2);e=e.valueOf();n=n.valueOf();if(e.match(S)||e.match(w)){return A(e,n)}else if(e.match(O)||e.match(b)){return L(e,n)}else{var t=n===10&&!e.match(/e/i)||n===16;if(e.match(x)&&t||e.match(_)){return I(e,n)}if(e.match(c)){return R(e)}}return false},"(string->number number [radix])\n\n Function convert string to number."),try:re(new Je("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(jt(new Ae(new Oe("begin"),a.cdr.car.cdr.cdr),r),function(e){i(e)})}};if(u){e.dynamic_scope=o}var n=jt(a.car,e);if(Ze(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){bt("find",t,["regex","function"]);bt("find",r,"pair");if(Xe(r)){return Fe}var e=te("find",t);return ne(e(r.car),function(e){if(e&&e!==Fe){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;bt("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!==Fe){a.push(r)}return n(++t)}if(t===i.length){return Ae.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){bt("range",e,"number");if(e instanceof Tn){e=e.valueOf()}return Ae.fromArray(new Array(e).fill(0).map(function(e,n){return Tn(n)}))},"(range n)\n\n Function return list of n numbers from 0 to n - 1"),compose:re(wn,"(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(bn,"(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(jn,"(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=Te(i*(t<0||arguments.length<=t?F:arguments[t]))/(n+r)}return Tn(n)},"(lcm n1 n2 ...)\n\n Function return the least common multiple of their arguments."),"odd?":re(Sn(function(e){return Tn(e).isOdd()}),"(odd? number)\n\n Function check if number os odd."),"even?":re(Sn(function(e){return Tn(e).isEven()}),"(even? number)\n\n Function check if number is even."),"*":re(kn(function(e,n){return Tn(e).mul(n)},Tn(1)),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":re(kn(function(e,n){return Tn(e).add(n)},Tn(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($e,"(eq? a b)\n\n Function compare two values if they are identical."),or:re(new Je("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=jt(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 Je("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=jt(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 Tn(e).or(n)},"(& a b)\n\n Function calculate or bit operation."),"&":re(function(e,n){return Tn(e).and(n)},"(& a b)\n\n Function calculate and bit operation."),"~":re(function(e){return Tn(e).neg()},"(~ number)\n\n Function negate the value."),">>":re(function(e,n){return Tn(e).shr(n)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":re(function(e,n){return Tn(e).shl(n)},"(<< a b)\n\n Function left shit the value a by value b."),not:re(function(e){if(Xe(e)){return true}return!e},"(not object)\n\n Function return negation of the argument.")},F,"global");var lt=ft.inherit("user-env");ft.set("**interaction-environment**",lt);(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(n){var t=e[n]?e[n]:n;ft.set(t,re(function(e){bt(t,e,"number");if(e instanceof Tn){return e[n]()}},"(".concat(t," number)\n\n Function calculate ").concat(t," of a number.")))})})();function pt(e){if(e.length===1){return e[0]}else{var n=[];var t=pt(e.slice(1));for(var r=0;r3&&arguments[3]!==F?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(r!==null){i+=" argument ".concat(r)}if(t instanceof Array){var a=t[t.length-1];t=t.slice(0,-1).join(", ")+" or "+a}return"Expecting ".concat(t," got ").concat(n).concat(i)}function bt(e,n,t){var r=arguments.length>3&&arguments[3]!==F?arguments[3]:null;e=e.valueOf();var i=_t(n).toLowerCase();var a=false;if(t instanceof Ae){t=t.toArray()}if(t instanceof Array){t=t.map(function(e){return e.valueOf().toLowerCase()});if(t.includes(i)){a=true}}else{t=t.valueOf().toLowerCase()}if(!a&&i!==t){throw new Error(gt(e,i,t,r))}}function wt(e){var n=Yt(e);return["string","function"].includes(n)||e instanceof Oe||e instanceof Tn||e instanceof RegExp}function _t(e){var n={pair:Ae,symbol:Oe,character:In,values:ct,macro:Je,string:Nn,array:Array,"native-symbol":Symbol};if(Number.isNaN(e)){return"NaN "}if(e===Fe){return"nil"}if(e===null){return"null"}if(e instanceof ze){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||ft}else if(i===true){i=a=ft}else{i=i||ft}var r={env:i,dynamic_scope:a,error:o};var u;if(Xe(n)){return n}if(n instanceof Oe){return i.get(n)}var c=n.car;var s=n.cdr;if(c instanceof Ae){u=xt(jt(c,r));if(Ze(u)){return u.then(function(e){return jt(new Ae(e,n.cdr),r)})}else if(typeof u!=="function"){throw new Error(_t(u)+" "+i.get("repr")(u)+" is not a function while evaluating "+n.toString())}}if(c instanceof Oe){u=i.get(c);if(u instanceof ze){return Ot(u,n,r)}else if(u instanceof Je){return kt(u,s,r)}else if(typeof u!=="function"){if(u){var f="".concat(_t(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=St(s,r);return ne(l,function(e){if(on(u)&&(!un(u)||cn(u))){e=e.map(nn)}if(u.__lambda__&&!u.__prototype__||cn(u)){u=rn(u)}var n=e.slice();var t=(a||i).newFrame(u,n);var r=xt(u.apply(t,e));return ne(r,function(e){if(e instanceof Ae){e.markCycles();return st(e)}if(typeof e==="number"){return Tn(e)}if(typeof e==="string"){return Nn(e)}return e},o)})}else if(n instanceof Oe){u=i.get(n);if(u==="undefined"){throw new Error("Unbound variable `"+n.name+"'")}return u}else if(n instanceof Ae){u=c&&c.toString();throw new Error("".concat(_t(c)," ").concat(u," is not a function"))}else{return n}}catch(e){o&&o.call(i,e,n)}}function Et(e,n,t){return Ft.apply(this,arguments)}function Ft(){Ft=Bt(Tt.mark(function e(t,r,i){var a,o,u,c;return Tt.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(i===true){r=i=r||lt}else if(r===true){r=i=lt}else{r=r||lt}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 jt(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 Ft.apply(this,arguments)}function At(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=Gt(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 It(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 Nt(e){this.url=e;var o=this.worker=It(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=Jt(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=Jt(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 Rt.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])}}Ae.unDry=function(e){return new Ae(e.car,e.cdr)};Ae.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};Ee.prototype.toDry=function(){return{value:null}};Ee.unDry=function(){return Fe};Oe.prototype.toDry=function(){return{value:{name:this.name}}};Oe.unDry=function(e){return new Oe(e.name)};function Lt(e){console.error(e.message||e);if(e.code){console.error(e.code.map(function(e,n){return"[".concat(n+1,"]: ").concat(e)}))}}function qt(){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(Et).then(n)["catch"](function(e){Lt(e);n()})}else{return Et(e.innerHTML).then(n)["catch"](function(e){Lt(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,qt)}var Pt=function(){var e=Nn("Sat, 22 Aug 2020 16:08:48 +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";Je.__className="macro";ze.__className="syntax";ot.__className="environment";Zn.__className="input-port";et.__className="output-port";nt.__className="output-string-port";tt.__className="input-string-port";Tn.__className="number";In.__className="character";Nn.__className="string";var Rt={version:"DEV",banner:Pt,date:"Sat, 22 Aug 2020 16:08:48 +0000",exec:Et,parse:ee,tokenize:W,evaluate:jt,Environment:ot,env:lt,Worker:Nt,Interpreter:at,balanced_parenthesis:At,balancedParenthesis:At,balanced:At,Macro:Je,Syntax:ze,Pair:Ae,quote:st,InputPort:Zn,OutputPort:et,InputStringPort:tt,OutputStringPort:nt,Formatter:ce,specials:K,repr:Ne,nil:Fe,LSymbol:Oe,LNumber:Tn,LFloat:$n,LComplex:Bn,LRational:Yn,LBigInteger:Gn,LCharacter:In,LString:Nn,rationalize:Hn};ft.set("lips",Rt);return Rt})})(); \ No newline at end of file diff --git a/src/lips.js b/src/lips.js index 47519a3da..8309eabcf 100644 --- a/src/lips.js +++ b/src/lips.js @@ -2330,9 +2330,23 @@ if (pattern instanceof Pair && pattern.cdr instanceof Pair && LSymbol.is(pattern.cdr.car, ellipsis_symbol)) { - // pattern (... ???) + // pattern (... ???) - SRFI-46 if (pattern.cdr.cdr !== nil) { - throw new Error('syntax: invalid usage of ellipsis'); + if (pattern.cdr.cdr instanceof Pair) { + // if we have (x ... a b) we need to remove two from the end + const list_len = pattern.cdr.cdr.length(); + let code_len = code.length(); + let list = code; + while (code_len - 1 > list_len) { + list = list.cdr; + code_len--; + } + const rest = list.cdr; + list.cdr = nil; + if (!traverse(pattern.cdr.cdr, rest, pattern_names, ellipsis)) { + return false; + } + } } if (pattern.car instanceof LSymbol) { let name = pattern.car.name; diff --git a/tests/syntax.scm b/tests/syntax.scm index 485378cae..6e23fbb9f 100644 --- a/tests/syntax.scm +++ b/tests/syntax.scm @@ -360,7 +360,7 @@ (f :::))) (t.is result '((1) 2 (3) (4))))) -(test_ "syntax-rules: elipsis in middle of pattern (srfi-46)" +(test "syntax-rules: tail of ellipsis (srfi-46)" (lambda (t) (define result (let-syntax @@ -369,8 +369,15 @@ (list ?x (list ?y ...) ?z))))) (foo 1 2 3 4 5))) - (t.is result '(1 (2 3 4) 5)))) + (t.is result '(1 (2 3 4) 5)) + (define result (let-syntax + ((foo (syntax-rules () + ((foo ?a ?b ... ?c ?d) + (list ?a (list ?b ...) ?c ?d))))) + (foo 1 2 3 4 5))) + + (t.is result '(1 (2 3) 4 5)))) (test "syntax-rules: rec macro (srfi-31)" (lambda (t)