diff --git a/Makefile b/Makefile index 57e1b332..f201bed5 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .PHONY: publish test coveralls lint zero -VERSION=1.0.0-beta.15 -VERSION_DASH=`echo -n "1.0.0-beta.15" | sed "s/-/%E2%80%93/"` +VERSION=1.0.0-beta.16 +VERSION_DASH=`echo -n "1.0.0-beta.16" | sed "s/-/%E2%80%93/"` BRANCH=`git branch | grep '^*' | sed 's/* //'` DATE=`date -uR` YEAR=`date +%Y` diff --git a/README.md b/README.md index dcdef71f..26db7978 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@

- LIPS - Scheme Based Powerful Lisp Language

-[![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.15-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) +[![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.16-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) ![1.0.0 Complete](https://img.shields.io/github/milestones/progress-percent/jcubic/lips/1?label=1.0.0%20Complete) -[![travis](https://travis-ci.com/jcubic/lips.svg?branch=devel&1eec8b962e54e4acd16206ac4e5cf9609e281fbd)](https://travis-ci.com/github/jcubic/lips) -[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&17423cfd6c8eebb2ada372b7a12083bd)](https://coveralls.io/github/jcubic/lips?branch=devel) +[![travis](https://travis-ci.com/jcubic/lips.svg?branch=master&3dd32fccc26732d8149810e51027b525647c5579)](https://travis-ci.com/github/jcubic/lips) +[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=master&17423cfd6c8eebb2ada372b7a12083bd)](https://coveralls.io/github/jcubic/lips?branch=master) [![Join Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips) ![NPM Download Count](https://img.shields.io/npm/dm/@jcubic/lips) ![JSDelivr Download count](https://img.shields.io/jsdelivr/npm/hm/@jcubic/lips) @@ -159,7 +159,7 @@ npm install -g @jcubic/lips@beta you can run the interpreter from the terminal: -![LIPS: Scheme interactive terminal](https://github.com/jcubic/lips/blob/devel/assets/screencast.gif?raw=true) +![LIPS: Scheme interactive terminal](https://github.com/jcubic/lips/blob/master/assets/screencast.gif?raw=true) You can also run code in a string with: @@ -201,7 +201,7 @@ Because LIPS is tree walking interpreter sometimes it may be slow. Especially if process long arrays and use callback function. If the array is quite large each pice of code inside the callback may slow down the processing. For example see: -script [reference.scm](https://github.com/jcubic/lips/blob/devel/scripts/reference.scm) +script [reference.scm](https://github.com/jcubic/lips/blob/master/scripts/reference.scm) That generates reference documentation for all builtin functions and macros. The slow part is `(names.sort name-compare)` (`Array::sort`) that take quite time to calculate, diff --git a/dist/lips.js b/dist/lips.js index 4349c676..d07dfe15 100644 --- a/dist/lips.js +++ b/dist/lips.js @@ -4,7 +4,7 @@ * | | \ \ | | | || . \/ __> | | * | | > \ | |_ | || _/\__ \ | | * | | / ^ \ |___||_||_| <___/ | | - * \_\ /_/ \_\ /_/ v. DEV + * \_\ /_/ \_\ /_/ v. 1.0.0-beta.16 * * LIPS is Pretty Simple - Scheme based Powerful LISP in JavaScript * @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Fri, 12 Nov 2021 08:35:50 +0000 + * build: Mon, 15 Nov 2021 19:33:52 +0000 */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : @@ -5003,7 +5003,7 @@ * The rationalize algorithm is by Per M.A. Bothner, Alan Bawden and Marc Feeley. * source: Kawa, C-Gambit * - * Build time: Fri, 12 Nov 2021 08:35:50 +0000 + * Build time: Mon, 15 Nov 2021 19:33:52 +0000 */ var _excluded = ["token"], _excluded2 = ["stderr", "stdin", "stdout", "command_line"]; @@ -18694,10 +18694,10 @@ var banner = function () { // Rollup tree-shaking is removing the variable if it's normal string because - // obviously 'Fri, 12 Nov 2021 08:35:50 +0000' == '{{' + 'DATE}}'; can be removed + // obviously 'Mon, 15 Nov 2021 19:33:52 +0000' == '{{' + 'DATE}}'; can be removed // but disablig Tree-shaking is adding lot of not used code so we use this // hack instead - var date = LString('Fri, 12 Nov 2021 08:35:50 +0000').valueOf(); + var date = LString('Mon, 15 Nov 2021 19:33:52 +0000').valueOf(); var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date); @@ -18709,7 +18709,7 @@ var _build = [_year, _format(_date.getMonth() + 1), _format(_date.getDate())].join('-'); - var banner = "\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter DEV (".concat(_build, ") \nCopyright (c) 2018-").concat(_year, " Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables. You can also\nuse (help name) to display help for specic function or macro, (apropos name)\nto display list of matched names in environment and (dir object) to list\nproperties of an object.\n").replace(/^.*\n/, ''); + var banner = "\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter 1.0.0-beta.16 (".concat(_build, ") \nCopyright (c) 2018-").concat(_year, " Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables. You can also\nuse (help name) to display help for specic function or macro, (apropos name)\nto display list of matched names in environment and (dir object) to list\nproperties of an object.\n").replace(/^.*\n/, ''); return banner; }(); // ------------------------------------------------------------------------- // to be used with string function when code is minified @@ -18741,9 +18741,9 @@ read_only(QuotedPromise, '__class__', 'promise'); // ------------------------------------------------------------------------- var lips = { - version: 'DEV', + version: '1.0.0-beta.16', banner: banner, - date: 'Fri, 12 Nov 2021 08:35:50 +0000', + date: 'Mon, 15 Nov 2021 19:33:52 +0000', exec: exec, // unwrap async generator into Promise parse: compose(uniterate_async, parse), diff --git a/dist/lips.min.js b/dist/lips.min.js index 6104c926..af6e3c04 100644 --- a/dist/lips.min.js +++ b/dist/lips.min.js @@ -4,7 +4,7 @@ * | | \ \ | | | || . \/ __> | | * | | > \ | |_ | || _/\__ \ | | * | | / ^ \ |___||_||_| <___/ | | - * \_\ /_/ \_\ /_/ v. DEV + * \_\ /_/ \_\ /_/ v. 1.0.0-beta.16 * * LIPS is Pretty Simple - Scheme based Powerful LISP in JavaScript * @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Fri, 12 Nov 2021 08:35:50 +0000 + * build: Mon, 15 Nov 2021 19:33:52 +0000 */ (function(e,t){typeof exports==="object"&&typeof module!=="undefined"?module.exports=t():typeof define==="function"&&define.amd?define(t):(e=typeof globalThis!=="undefined"?globalThis:e||self,e.lips=t())})(this,function(){"use strict";function i(e){if(e===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return e}function o(e,t){o=Object.setPrototypeOf||function e(t,r){t.__proto__=r;return t};return o(e,t)}function n(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true}catch(e){return false}}function p(e,t,r){if(n()){p=Reflect.construct}else{p=function e(t,r,n){var i=[null];i.push.apply(i,r);var u=Function.bind.apply(t,i);var a=new u;if(n)o(a,n.prototype);return a}}return p.apply(null,arguments)}function u(e,t){if(typeof t!=="function"&&t!==null){throw new TypeError("Super expression must either be null or a function")}e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:true,configurable:true}});if(t)o(e,t)}function _(e){"@babel/helpers - typeof";if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_=function e(t){return typeof t}}else{_=function e(t){return t&&typeof Symbol==="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t}}return _(e)}function a(e,t){if(t&&(_(t)==="object"||typeof t==="function")){return t}else if(t!==void 0){throw new TypeError("Derived constructors may only return object or undefined")}return i(e)}function s(e){s=Object.setPrototypeOf?Object.getPrototypeOf:function e(t){return t.__proto__||Object.getPrototypeOf(t)};return s(e)}function r(e){if(Array.isArray(e))return e}function t(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function c(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r=0)continue;r[i]=e[i]}return r}function D(e,t){if(e==null)return{};var r=w(e,t);var n,i;if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);for(i=0;i=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,n))continue;r[n]=e[n]}}return r}function E(e,t){var r=e==null?null:typeof Symbol!=="undefined"&&e[Symbol.iterator]||e["@@iterator"];if(r==null)return;var n=[];var i=true;var u=false;var a,o;try{for(r=r.call(e);!(i=(a=r.next()).done);i=true){n.push(a.value);if(t&&n.length===t)break}}catch(e){u=true;o=e}finally{try{if(!i&&r["return"]!=null)r["return"]()}finally{if(u)throw o}}return n}function A(e,t){return r(e)||E(e,t)||f(e,t)||l()}function F(e){var t;if(typeof Symbol!=="undefined"){if(Symbol.asyncIterator)t=e[Symbol.asyncIterator];if(t==null&&Symbol.iterator)t=e[Symbol.iterator]}if(t==null)t=e["@@asyncIterator"];if(t==null)t=e["@@iterator"];if(t==null)throw new TypeError("Object is not async iterable");return t.call(e)}function x(e){this.wrapped=e}function C(e){return new x(e)}function S(u){var a,o;function e(n,i){return new Promise(function(e,t){var r={key:n,arg:i,resolve:e,reject:t,next:null};if(o){o=o.next=r}else{a=o=r;s(n,i)}})}function s(t,e){try{var r=u[t](e);var n=r.value;var i=n instanceof x;Promise.resolve(i?n.wrapped:n).then(function(e){if(i){s(t==="return"?"return":"next",e);return}c(r.done?"return":"normal",e)},function(e){s("throw",e)})}catch(e){c("throw",e)}}function c(e,t){switch(e){case"return":a.resolve({value:t,done:true});break;case"throw":a.reject(t);break;default:a.resolve({value:t,done:false});break}a=a.next;if(a){s(a.key,a.arg)}else{o=null}}this._invoke=e;if(typeof u["return"]!=="function"){this["return"]=undefined}}S.prototype[typeof Symbol==="function"&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this};S.prototype.next=function(e){return this._invoke("next",e)};S.prototype["throw"]=function(e){return this._invoke("throw",e)};S.prototype["return"]=function(e){return this._invoke("return",e)};function e(e){return function(){return new S(e.apply(this,arguments))}}var B={exports:{}};(function(e){var t=function(a){var e=Object.prototype;var f=e.hasOwnProperty;var s;var t=typeof Symbol==="function"?Symbol:{};var i=t.iterator||"@@iterator";var r=t.asyncIterator||"@@asyncIterator";var n=t.toStringTag||"@@toStringTag";function u(e,t,r){Object.defineProperty(e,t,{value:r,enumerable:true,configurable:true,writable:true});return e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function o(e,t,r,n){var i=t&&t.prototype instanceof c?t:c;var u=Object.create(i.prototype);var a=new O(n||[]);u._invoke=F(e,r,a);return u}a.wrap=o;function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}var h="suspendedStart";var p="suspendedYield";var _="executing";var d="completed";var v={};function c(){}function m(){}function y(){}var g={};u(g,i,function(){return this});var b=Object.getPrototypeOf;var w=b&&b(b(S([])));if(w&&w!==e&&f.call(w,i)){g=w}var D=y.prototype=c.prototype=Object.create(g);m.prototype=y;u(D,"constructor",y);u(y,"constructor",m);m.displayName=u(y,n,"GeneratorFunction");function E(e){["next","throw","return"].forEach(function(t){u(e,t,function(e){return this._invoke(t,e)})})}a.isGeneratorFunction=function(e){var t=typeof e==="function"&&e.constructor;return t?t===m||(t.displayName||t.name)==="GeneratorFunction":false};a.mark=function(e){if(Object.setPrototypeOf){Object.setPrototypeOf(e,y)}else{e.__proto__=y;u(e,n,"GeneratorFunction")}e.prototype=Object.create(D);return e};a.awrap=function(e){return{__await:e}};function A(o,s){function c(e,t,r,n){var i=l(o[e],o,t);if(i.type==="throw"){n(i.arg)}else{var u=i.arg;var a=u.value;if(a&&typeof a==="object"&&f.call(a,"__await")){return s.resolve(a.__await).then(function(e){c("next",e,r,n)},function(e){c("throw",e,r,n)})}return s.resolve(a).then(function(e){u.value=e;r(u)},function(e){return c("throw",e,r,n)})}}var t;function e(r,n){function e(){return new s(function(e,t){c(r,n,e,t)})}return t=t?t.then(e,e):e()}this._invoke=e}E(A.prototype);u(A.prototype,r,function(){return this});a.AsyncIterator=A;a.async=function(e,t,r,n,i){if(i===void 0)i=Promise;var u=new A(o(e,t,r,n),i);return a.isGeneratorFunction(t)?u:u.next().then(function(e){return e.done?e.value:u.next()})};function F(a,o,s){var c=h;return function e(t,r){if(c===_){throw new Error("Generator is already running")}if(c===d){if(t==="throw"){throw r}return B()}s.method=t;s.arg=r;while(true){var n=s.delegate;if(n){var i=x(n,s);if(i){if(i===v)continue;return i}}if(s.method==="next"){s.sent=s._sent=s.arg}else if(s.method==="throw"){if(c===h){c=d;throw s.arg}s.dispatchException(s.arg)}else if(s.method==="return"){s.abrupt("return",s.arg)}c=_;var u=l(a,o,s);if(u.type==="normal"){c=s.done?d:p;if(u.arg===v){continue}return{value:u.arg,done:s.done}}else if(u.type==="throw"){c=d;s.method="throw";s.arg=u.arg}}}}function x(e,t){var r=e.iterator[t.method];if(r===s){t.delegate=null;if(t.method==="throw"){if(e.iterator["return"]){t.method="return";t.arg=s;x(e,t);if(t.method==="throw"){return v}}t.method="throw";t.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var n=l(r,e.iterator,t.arg);if(n.type==="throw"){t.method="throw";t.arg=n.arg;t.delegate=null;return v}var i=n.arg;if(!i){t.method="throw";t.arg=new TypeError("iterator result is not an object");t.delegate=null;return v}if(i.done){t[e.resultName]=i.value;t.next=e.nextLoc;if(t.method!=="return"){t.method="next";t.arg=s}}else{return i}t.delegate=null;return v}E(D);u(D,n,"Generator");u(D,i,function(){return this});u(D,"toString",function(){return"[object Generator]"});function C(e){var t={tryLoc:e[0]};if(1 in e){t.catchLoc=e[1]}if(2 in e){t.finallyLoc=e[2];t.afterLoc=e[3]}this.tryEntries.push(t)}function k(e){var t=e.completion||{};t.type="normal";delete t.arg;e.completion=t}function O(e){this.tryEntries=[{tryLoc:"root"}];e.forEach(C,this);this.reset(true)}a.keys=function(r){var n=[];for(var e in r){n.push(e)}n.reverse();return function e(){while(n.length){var t=n.pop();if(t in r){e.value=t;e.done=false;return e}}e.done=true;return e}};function S(t){if(t){var e=t[i];if(e){return e.call(t)}if(typeof t.next==="function"){return t}if(!isNaN(t.length)){var r=-1,n=function e(){while(++r=0;--t){var i=this.tryEntries[t];var u=i.completion;if(i.tryLoc==="root"){return e("end")}if(i.tryLoc<=this.prev){var a=f.call(i,"catchLoc");var o=f.call(i,"finallyLoc");if(a&&o){if(this.prev=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&f.call(n,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e){this.complete(r.completion,r.afterLoc);k(r);return v}}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if(n.type==="throw"){var i=n.arg;k(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){this.delegate={iterator:S(e),resultName:t,nextLoc:r};if(this.method==="next"){this.arg=s}return v}};return a}(e.exports);try{regeneratorRuntime=t}catch(e){if(typeof globalThis==="object"){globalThis.regeneratorRuntime=t}else{Function("r","regeneratorRuntime = r")(t)}}})(B);var j=B.exports;var I=typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{};var P=[];var N=[];var R=typeof Uint8Array!=="undefined"?Uint8Array:Array;var T=false;function U(){T=true;var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var t=0,r=e.length;t0){throw new Error("Invalid string. Length must be a multiple of 4")}u=e[o-2]==="="?2:e[o-1]==="="?1:0;a=new R(o*3/4-u);n=u>0?o-4:o;var s=0;for(t=0,r=0;t>16&255;a[s++]=i>>8&255;a[s++]=i&255}if(u===2){i=N[e.charCodeAt(t)]<<2|N[e.charCodeAt(t+1)]>>4;a[s++]=i&255}else if(u===1){i=N[e.charCodeAt(t)]<<10|N[e.charCodeAt(t+1)]<<4|N[e.charCodeAt(t+2)]>>2;a[s++]=i>>8&255;a[s++]=i&255}return a}function M(e){return P[e>>18&63]+P[e>>12&63]+P[e>>6&63]+P[e&63]}function Y(e,t,r){var n;var i=[];for(var u=t;us?s:o+a))}if(n===1){t=e[r-1];i+=P[t>>2];i+=P[t<<4&63];i+="=="}else if(n===2){t=(e[r-2]<<8)+e[r-1];i+=P[t>>10];i+=P[t>>4&63];i+=P[t<<2&63];i+="="}u.push(i);return u.join("")}function z(e,t,r,n,i){var u,a;var o=i*8-n-1;var s=(1<>1;var f=-7;var l=r?i-1:0;var h=r?-1:1;var p=e[t+l];l+=h;u=p&(1<<-f)-1;p>>=-f;f+=o;for(;f>0;u=u*256+e[t+l],l+=h,f-=8){}a=u&(1<<-f)-1;u>>=-f;f+=n;for(;f>0;a=a*256+e[t+l],l+=h,f-=8){}if(u===0){u=1-c}else if(u===s){return a?NaN:(p?-1:1)*Infinity}else{a=a+Math.pow(2,n);u=u-c}return(p?-1:1)*a*Math.pow(2,u-n)}function V(e,t,r,n,i,u){var a,o,s;var c=u*8-i-1;var f=(1<>1;var h=i===23?Math.pow(2,-24)-Math.pow(2,-77):0;var p=n?0:u-1;var _=n?1:-1;var d=t<0||t===0&&1/t<0?1:0;t=Math.abs(t);if(isNaN(t)||t===Infinity){o=isNaN(t)?1:0;a=f}else{a=Math.floor(Math.log(t)/Math.LN2);if(t*(s=Math.pow(2,-a))<1){a--;s*=2}if(a+l>=1){t+=h/s}else{t+=h*Math.pow(2,1-l)}if(t*s>=2){a++;s/=2}if(a+l>=f){o=0;a=f}else if(a+l>=1){o=(t*s-1)*Math.pow(2,i);a=a+l}else{o=t*Math.pow(2,l-1)*Math.pow(2,i);a=0}}for(;i>=8;e[r+p]=o&255,p+=_,o/=256,i-=8){}a=a<0;e[r+p]=a&255,p+=_,a/=256,c-=8){}e[r+p-_]|=d*128}var J={}.toString;var G=Array.isArray||function(e){return J.call(e)=="[object Array]"}; /*! @@ -83,5 +83,5 @@ * The rationalize algorithm is by Per M.A. Bothner, Alan Bawden and Marc Feeley. * source: Kawa, C-Gambit * - * Build time: Fri, 12 Nov 2021 08:35:50 +0000 - */var Er=["token"],Ar=["stderr","stdin","stdout","command_line"];function Fr(i){var u=xr();return function e(){var t=s(i),r;if(u){var n=s(this).constructor;r=Reflect.construct(t,arguments,n)}else{r=t.apply(this,arguments)}return a(this,r)}}function xr(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true}catch(e){return false}}function Cr(t,e){var r=typeof Symbol!=="undefined"&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=kr(t))||e&&t&&typeof t.length==="number"){if(r)t=r;var n=0;var i=function e(){};return{s:i,n:function e(){if(n>=t.length)return{done:true};return{done:false,value:t[n++]}},e:function e(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u=true,a=false,o;return{s:function e(){r=r.call(t)},n:function e(){var t=r.next();u=t.done;return t},e:function e(t){a=true;o=t},f:function e(){try{if(!u&&r["return"]!=null)r["return"]()}finally{if(a)throw o}}}}function kr(e,t){if(!e)return;if(typeof e==="string")return Or(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor)r=e.constructor.name;if(r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return Or(e,t)}function Or(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r1&&arguments[1]!==undefined?arguments[1]:null;var n=arguments[1]===true;function t(e){if(!Mr()){return}var t=io.get("repr")(e);if(r===null||r instanceof RegExp&&r.test(t)){console.log(io.get("type")(e)+": "+t)}if(n){console.log(e)}}if(gu(e)){e.then(t)}else{t(e)}return e}function Mr(){return uo&&uo.get("DEBUG",{throwError:false})}function Yr(e){return e?"(?:#".concat(e,"(?:#[ie])?|#[ie]#").concat(e,")"):"(?:#[ie])?"}function $r(e,t){return"".concat(Yr(e),"[+-]?").concat(t,"+/").concat(t,"+")}function zr(e,t){return"".concat(Yr(e),"(?:[+-]?(?:").concat(t,"+/").concat(t,"+|nan.0|inf.0|").concat(t,"+))?(?:[+-]i|[+-]?(?:").concat(t,"+/").concat(t,"+|").concat(t,"+|nan.0|inf.0)i)(?=[()[\\]\\s]|$)")}function Vr(e,t){return"".concat(Yr(e),"[+-]?").concat(t,"+")}var Jr=/^#\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimyus]*)$/;var Gr="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)";var Hr="(?:#[ie])?(?:[+-]?(?:[0-9]+/[0-9]+|nan.0|inf.0|".concat(Gr,"|[+-]?[0-9]+))?(?:").concat(Gr,"|[+-](?:[0-9]+/[0-9]+|[0-9]+|nan.0|inf.0))i");var Wr=new RegExp("^(#[ie])?".concat(Gr,"$"),"i");function Qr(e,t){var r=e==="x"?"(?!\\+|".concat(t,")"):"(?!\\.|".concat(t,")");var n="";if(e===""){n="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+(?![0-9]))(?:[eE][-+]?[0-9]+)?))"}return new RegExp("^((?:(?:".concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(t,"+/").concat(t,"+(?!").concat(t,")|[+-]?").concat(t,"+)").concat(r,")?)(").concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(t,"+/").concat(t,"+|[+-]?").concat(t,"+|[+-])i$"),"i")}var Zr=function(){var u={};[[10,"","[0-9]"],[16,"x","[0-9a-fA-F]"],[8,"o","[0-7]"],[2,"b","[01]"]].forEach(function(e){var t=A(e,3),r=t[0],n=t[1],i=t[2];u[r]=Qr(n,i)});return u}();var Kr={alarm:"",backspace:"\b",delete:"",escape:"",newline:"\n",null:"\0",return:"\r",space:" ",tab:"\t",dle:"",soh:"",dc1:"",stx:"",dc2:"",etx:"",dc3:"",eot:"",dc4:"",enq:"",nak:"",ack:"",syn:"",bel:"",etb:"",bs:"\b",can:"",ht:"\t",em:"",lf:"\n",sub:"",vt:"\v",esc:"",ff:"\f",fs:"",cr:"\r",gs:"",so:"",rs:"",si:"",us:"",del:""};function Xr(e){var t=[];var r=0;var n=e.length;while(r=55296&&i<=56319&&r1&&arguments[1]!==undefined?arguments[1]:10;var r=_n(e);var n=r.number.split("/");var i=ka({num:da([n[0],r.radix||t]),denom:da([n[1],r.radix||t])});if(r.inexact){return i.valueOf()}else{return i}}function vn(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;var r=_n(e);if(r.inexact){return Ea(parseInt(r.number,r.radix||t))}return da([r.number,r.radix||t])}function mn(e){var t=e.match(/#\\x([0-9a-f]+)$/i);var r;if(t){var n=parseInt(t[1],16);r=String.fromCodePoint(n)}else{t=e.match(/#\\(.+)$/);if(t){r=t[1]}}if(r){return oa(r)}throw new Error("Parse: invalid character")}function yn(e){var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;function t(e){var t;if(e==="+"){t=da(1)}else if(e==="-"){t=da(-1)}else if(e.match(cn)){t=da([e,i])}else if(e.match(fn)){var r=e.split("/");t=ka({num:da([r[0],i]),denom:da([r[1],i])})}else if(e.match(Wr)){var n=wn(e);if(u.exact){return n.toRational()}return n}else if(e.match(/nan.0$/)){return da(NaN)}else if(e.match(/inf.0$/)){if(e[0]==="-"){return da(Number.NEGATIVE_INFINITY)}return da(Number.POSITIVE_INFINITY)}else{throw new Error("Internal Parser Error")}if(u.inexact){return Ea(t.valueOf())}return t}var u=_n(e);i=u.radix||i;var r;var n=u.number.match(hn);if(i!==10&&n){r=n}else{r=u.number.match(Zr[i])}var a,o;o=t(r[2]);if(r[1]){a=t(r[1])}else{a=da(0)}if(o.cmp(0)===0&&o.__type__==="bigint"){return a}return Da({im:o,re:a})}function gn(e){return parseInt(e.toString(),10)===e}function bn(e){var t=e.match(/^(([-+]?[0-9]*)(?:\.([0-9]+))?)e([-+]?[0-9]+)/i);if(t){var r=parseInt(t[4],10);var n;var i=t[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var u=t[3]&&t[3].length;if(i0){return da(u).mul(o)}}}r=Ea(r);if(t.exact){return r.toRational()}return r}function Dn(e){e=e.replace(/\\x([0-9a-f]+);/gi,function(e,t){return"\\u"+t.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 sa(JSON.parse(e))}catch(e){throw new Error("Invalid string literal")}}function En(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var r={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,t){return String.fromCharCode(parseInt("0"+t,16))}).replace(/\\(.)/g,function(e,t){return r[t]||t})}return new Ln(e)}function An(e){if(no.hasOwnProperty(e)){return no[e]}if(e.match(/^"[\s\S]*"$/)){return Dn(e)}else if(e[0]==="#"){var t=e.match(Jr);if(t){return new RegExp(t[1],t[2])}else if(e.match(rn)){return mn(e)}var r=e.match(/#\\(.+)/);if(r&&Xr(r[1]).length===1){return mn(e)}}if(e.match(/[0-9a-f]|[+-]i/i)){if(e.match(sn)){return vn(e)}else if(e.match(Wr)){return wn(e)}else if(e.match(on)){return dn(e)}else if(e.match(an)){return yn(e)}}if(e.match(/^#[iexobd]/)){throw new Error("Invalid numeric constant: "+e)}return En(e)}function Fn(e){return!(["(",")","[","]"].includes(e)||Jn.names().includes(e))}function xn(e){return Fn(e)&&!(e.match(Jr)||e.match(/^"[\s\S]*"$/)||e.match(sn)||e.match(Wr)||e.match(an)||e.match(on)||e.match(rn)||["#t","#f","nil","true","false"].includes(e))}var Cn=/"(?:\\[\S\s]|[^"])*"?/g;function kn(e){if(typeof e==="string"){var t=/([-\\^$[\]()+{}?*.|])/g;return e.replace(t,"\\$1")}return e}function On(){this.data=[]}On.prototype.push=function(e){this.data.push(e)};On.prototype.top=function(){return this.data[this.data.length-1]};On.prototype.pop=function(){return this.data.pop()};On.prototype.is_empty=function(){return!this.data.length};function Sn(e){if(e instanceof sa){e=e.valueOf()}var t=new Zn(e,{whitespace:true});var r=[];while(true){var n=t.peek(true);if(n===$a){break}r.push(n);t.skip()}return r}function Bn(e){var t=e.token,r=D(e,Er);if(t.match(/^"[\s\S]*"$/)&&t.match(/\n/)){var n=new RegExp("^ {1,"+(e.col+1)+"}","mg");t=t.replace(n,"")}return Br({token:t},r)}function jn(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(){};this.fn=e;this.cont=t}jn.prototype.toString=function(){return"#"};function In(n){return function(){for(var e=arguments.length,t=new Array(e),r=0;r1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof sa){e=e.toString()}if(t){return Sn(e)}else{var r=Sn(e).map(function(e){if(e.token==="#\\ "){return e.token}return e.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return Rn(r)}}function Rn(e){var t=0;var r=null;var n=[];for(var i=0;i0&&arguments[0]!==undefined?arguments[0]:null;if(e instanceof Ln){if(e.is_gensym()){return e}e=e.valueOf()}if(qn(e)){return Ln(e)}if(e!==null){return r(e,Symbol("#:".concat(e)))}t++;return r(t,Symbol("#:g".concat(t)))}}();function Yn(e){var r=this;var n={pending:true,rejected:false,fulfilled:false,reason:undefined,type:undefined};e=e.then(function(e){n.type=Ao(e);n.fulfilled=true;n.pending=false;return e});ai(this,"_promise",e,{hidden:true});if(vu(e["catch"])){e=e["catch"](function(e){n.rejected=true;n.pending=false;n.reason=e})}Object.keys(n).forEach(function(t){Object.defineProperty(r,"__".concat(t,"__"),{enumerable:true,get:function e(){return n[t]}})});ai(this,"__promise__",e);this.then=false}Yn.prototype.then=function(e){return new Yn(this.valueOf().then(e))};Yn.prototype["catch"]=function(e){return new Yn(this.valueOf()["catch"](e))};Yn.prototype.valueOf=function(){if(!this._promise){throw new Error("QuotedPromise: invalid promise created")}return this._promise};Yn.prototype.toString=function(){if(this.__pending__){return Yn.pending_str}if(this.__rejected__){return Yn.rejected_str}return"#")};Yn.pending_str="#";Yn.rejected_str="#";function $n(e){if(Array.isArray(e)){return Promise.all(zn(e)).then(Vn)}return e}function zn(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof Yn){t[r]=new Ha(n)}else{t[r]=n}}return t}function Vn(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof Ha){t[r]=n.valueOf()}else{t[r]=n}}return t}var Jn={LITERAL:Symbol["for"]("literal"),SPLICE:Symbol["for"]("splice"),SYMBOL:Symbol["for"]("symbol"),names:function e(){return Object.keys(this._specials)},type:function e(t){return this.get(t).type},get:function e(t){return this._specials[t]},off:function e(t){var r=this;var n=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(Array.isArray(t)){t.forEach(function(e){return r.off(e,n)})}else if(n===null){delete this._events[t]}else{this._events=this._events.filter(function(e){return e!==n})}},on:function e(t,r){var n=this;if(Array.isArray(t)){t.forEach(function(e){return n.on(e,r)})}else if(!this._events[t]){this._events[t]=[r]}else{this._events[t].push(r)}},trigger:function e(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i",new Ln("quote-promise"),Jn.LITERAL]];Object.defineProperty(Jn,"builtin",{writable:false,value:Qn.map(function(e){return e[0]})});Qn.forEach(function(e){var t=A(e,3),r=t[0],n=t[1],i=t[2];Jn.append(r,n,i)});var Zn=function(){function p(e){var t=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=r.whitespace,i=n===void 0?false:n;y(this,p);ai(this,"__input__",e.replace(/\r/g,""));var u={};["_i","_whitespace","_col","_newline","_line","_state","_next","_token","_prev_char"].forEach(function(r){Object.defineProperty(t,r,{configurable:false,enumerable:false,get:function e(){return u[r]},set:function e(t){u[r]=t}})});this._whitespace=i;this._i=this._line=this._col=this._newline=0;this._state=this._next=this._token=null;this._prev_char=""}b(p,[{key:"get",value:function e(t){return this.__internal[t]}},{key:"set",value:function e(t,r){this.__internal[t]=r}},{key:"token",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(t){var r=this._line;if(this._whitespace&&this._token==="\n"){--r}return{token:this._token,col:this._col,offset:this._i,line:r}}return this._token}},{key:"peek",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(this._i>=this.__input__.length){return $a}if(this._token){return this.token(t)}var r=this.next_token();if(r){this._token=this.__input__.substring(this._i,this._next);return this.token(t)}return $a}},{key:"skip",value:function e(){if(this._next!==null){this._token=null;this._i=this._next}}},{key:"read_line",value:function e(){var t=this.__input__.length;if(this._i>=t){return $a}for(var r=this._i;r=r){return $a}if(t+this._i>=r){return this.read_rest()}var n=this._i+t;var i=this.__input__.substring(this._i,n);var u=i.match(/\n/g);if(u){this._line+=u.length}this._i=n;return i}},{key:"peek_char",value:function e(){if(this._i>=this.__input__.length){return $a}return oa(this.__input__[this._i])}},{key:"read_char",value:function e(){var t=this.peek_char();this.skip_char();return t}},{key:"skip_char",value:function e(){if(this._i1&&arguments[1]!==undefined?arguments[1]:{},n=r.prev_char,i=r["char"],u=r.next_char;var a=A(t,4),o=a[0],s=a[1],c=a[2],f=a[3];if(t.length!==5){throw new Error("Lexer: Invald rule of length ".concat(t.length))}if(!i.match(o)){return false}if(!Kn(s,n)){return false}if(!Kn(c,u)){return false}if(f!==this._state){return false}return true}},{key:"next_token",value:function e(){if(this._i>=this.__input__.length){return false}var t=true;e:for(var r=this._i,n=this.__input__.length;r2&&arguments[2]!==undefined?arguments[2]:null;var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;if(t.length===0){throw new Error("Lexer: invalid literal rule")}if(t.length===1){return[[t,n,i,null,null]]}var u=[];for(var a=0,o=t.length;a1&&arguments[1]!==undefined?arguments[1]:{},r=t.env,n=t.meta,i=n===void 0?false:n,u=t.formatter,a=u===void 0?Bn:u;y(this,o);if(e instanceof sa){e=e.toString()}ai(this,"_formatter",a,{hidden:true});ai(this,"__lexer__",new Zn(e));ai(this,"__env__",r);ai(this,"_meta",i,{hidden:true});ai(this,"_refs",[],{hidden:true});ai(this,"_state",{parentheses:0},{hidden:true})}b(o,[{key:"resolve",value:function e(t){return this.__env__&&this.__env__.get(t,{throwError:false})}},{key:"peek",value:function(){var e=O(j.mark(function e(){var r;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:r=this.__lexer__.peek(true);if(!(r===$a)){t.next=4;break}return t.abrupt("return",$a);case 4:if(!this.is_comment(r.token)){t.next=7;break}this.skip();return t.abrupt("continue",0);case 7:if(!(r.token==="#;")){t.next=14;break}this.skip();if(!(this.__lexer__.peek()===$a)){t.next=11;break}throw new Error("Lexer: syntax error eof found after comment");case 11:t.next=13;return this._read_object();case 13:return t.abrupt("continue",0);case 14:return t.abrupt("break",17);case 17:r=this._formatter(r);if(!this._meta){t.next=20;break}return t.abrupt("return",r);case 20:return t.abrupt("return",r.token);case 21:case"end":return t.stop()}}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"reset",value:function e(){this._refs.length=0}},{key:"skip",value:function e(){this.__lexer__.skip()}},{key:"read",value:function(){var e=O(j.mark(function e(){var r;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:t.next=2;return this.peek();case 2:r=t.sent;this.skip();return t.abrupt("return",r);case 5:case"end":return t.stop()}}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"match_datum_label",value:function e(t){var r=t.match(/^#([0-9]+)=$/);return r&&r[1]}},{key:"match_datum_ref",value:function e(t){var r=t.match(/^#([0-9]+)#$/);return r&&r[1]}},{key:"is_open",value:function e(t){var r=["(","["].includes(t);if(r){this._state.parentheses++}return r}},{key:"is_close",value:function e(t){var r=[")","]"].includes(t);if(r){this._state.parentheses--}return r}},{key:"read_list",value:function(){var e=O(j.mark(function e(){var r,n,i,u;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:r=Pi,n=r;case 1:t.next=4;return this.peek();case 4:i=t.sent;if(!(i===$a)){t.next=7;break}return t.abrupt("break",27);case 7:if(!this.is_close(i)){t.next=10;break}this.skip();return t.abrupt("break",27);case 10:if(!(i==="."&&r!==Pi)){t.next=17;break}this.skip();t.next=14;return this._read_object();case 14:n.cdr=t.sent;t.next=25;break;case 17:t.t0=Ni;t.next=20;return this._read_object();case 20:t.t1=t.sent;t.t2=Pi;u=new t.t0(t.t1,t.t2);if(r===Pi){r=u}else{n.cdr=u}n=u;case 25:t.next=1;break;case 27:return t.abrupt("return",r);case 28:case"end":return t.stop()}}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"read_value",value:function(){var e=O(j.mark(function e(){var r;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:t.next=2;return this.read();case 2:r=t.sent;if(!(r===$a)){t.next=5;break}throw new Error("Parser: Expected token eof found");case 5:return t.abrupt("return",An(r));case 6:case"end":return t.stop()}}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"is_comment",value:function e(t){return t.match(/^;/)||t.match(/^#\|/)&&t.match(/\|#$/)}},{key:"evaluate",value:function e(t){return Io(t,{env:this.__env__,error:function e(t){throw t}})}},{key:"read_object",value:function(){var e=O(j.mark(function e(){var r;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:this.reset();t.next=3;return this._read_object();case 3:r=t.sent;if(r instanceof ei){r=r.valueOf()}if(!this._refs.length){t.next=7;break}return t.abrupt("return",this._resolve_object(r));case 7:return t.abrupt("return",r);case 8:case"end":return t.stop()}}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"ballanced",value:function e(){return this._state.parentheses===0}},{key:"ballancing_error",value:function e(t){var r=this._state.parentheses;var n=new Error("Parser: expected parenthesis but eof found");var i=new RegExp("\\){".concat(r,"}$"));n.__code__=[t.toString().replace(i,"")];throw n}},{key:"_resolve_object",value:function(){var t=O(j.mark(function e(r){var n=this;var i;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(!Array.isArray(r)){t.next=2;break}return t.abrupt("return",r.map(function(e){return n._resolve_object(e)}));case 2:if(!Li(r)){t.next=6;break}i={};Object.keys(r).forEach(function(e){i[e]=n._resolve_object(r[e])});return t.abrupt("return",i);case 6:if(!(r instanceof Ni)){t.next=8;break}return t.abrupt("return",this._resolve_pair(r));case 8:return t.abrupt("return",r);case 9:case"end":return t.stop()}}},e,this)}));function e(e){return t.apply(this,arguments)}return e}()},{key:"_resolve_pair",value:function(){var t=O(j.mark(function e(r){return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(!(r instanceof Ni)){t.next=15;break}if(!(r.car instanceof ei)){t.next=7;break}t.next=4;return r.car.valueOf();case 4:r.car=t.sent;t.next=8;break;case 7:this._resolve_pair(r.car);case 8:if(!(r.cdr instanceof ei)){t.next=14;break}t.next=11;return r.cdr.valueOf();case 11:r.cdr=t.sent;t.next=15;break;case 14:this._resolve_pair(r.cdr);case 15:return t.abrupt("return",r);case 16:case"end":return t.stop()}}},e,this)}));function e(e){return t.apply(this,arguments)}return e}()},{key:"_read_object",value:function(){var e=O(j.mark(function e(){var r,n,i,u,a,o,s,c,f;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:t.next=2;return this.peek();case 2:r=t.sent;if(!(r===$a)){t.next=5;break}return t.abrupt("return",r);case 5:if(!Gn(r)){t.next=35;break}n=Jn.get(r);i=Hn(r);this.skip();t.next=11;return this._read_object();case 11:a=t.sent;if(i){t.next=22;break}o=this.__env__.get(n.symbol);if(!(typeof o==="function")){t.next=22;break}if(!Wn(r)){t.next=19;break}return t.abrupt("return",o.call(this.__env__,a));case 19:if(!(a instanceof Ni)){t.next=21;break}return t.abrupt("return",o.apply(this.__env__,a.to_array(false)));case 21:throw new Error("Parse Error: Invalid parser extension "+"invocation ".concat(n.symbol));case 22:if(Wn(r)){u=new Ni(n.symbol,new Ni(a,Pi))}else{u=new Ni(n.symbol,a)}if(!i){t.next=25;break}return t.abrupt("return",u);case 25:if(!(o instanceof au)){t.next=34;break}t.next=28;return this.evaluate(u);case 28:s=t.sent;if(!(s instanceof Ni||s instanceof Ln)){t.next=31;break}return t.abrupt("return",Ni.fromArray([Ln("quote"),s]));case 31:return t.abrupt("return",s);case 34:throw new Error("Parse Error: invlid parser extension: "+n.symbol);case 35:c=this.match_datum_ref(r);if(!(c!==null)){t.next=41;break}this.skip();if(!this._refs[c]){t.next=40;break}return t.abrupt("return",new ei(c,this._refs[c]));case 40:throw new Error("Parse Error: invalid datum label #".concat(c,"#"));case 41:f=this.match_datum_label(r);if(!(f!==null)){t.next=48;break}this.skip();this._refs[f]=this._read_object();return t.abrupt("return",this._refs[f]);case 48:if(!this.is_open(r)){t.next=53;break}this.skip();return t.abrupt("return",this.read_list());case 53:return t.abrupt("return",this.read_value());case 54:case"end":return t.stop()}}},e,this)}));function t(){return e.apply(this,arguments)}return t}()}]);return o}();var ei=function(){function r(e,t){y(this,r);this.name=e;this.data=t}b(r,[{key:"valueOf",value:function e(){return this.data}}]);return r}();function ti(e,t){return ri.apply(this,arguments)}function ri(){ri=e(j.mark(function e(r,n){var i,u;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(!n){if(io){n=io.get("**interaction-environment**",{throwError:false})}else{n=uo}}i=new Xn(r,{env:n});case 2:t.next=5;return C(i.read_object());case 5:u=t.sent;if(!i.ballanced()){i.ballancing_error(u)}if(!(u===$a)){t.next=9;break}return t.abrupt("break",13);case 9:t.next=11;return u;case 11:t.next=2;break;case 13:case"end":return t.stop()}}},e)}));return ri.apply(this,arguments)}function ni(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(e){return e};var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;if(gu(e)){var n=e.then(t);if(r===null){return n}else{return n["catch"](r)}}if(e instanceof Array){return ii(e,t,r)}if(Li(e)){return ui(e,t,r)}return t(e)}function ii(t,r,e){if(t.find(gu)){return ni($n(t),function(e){if(Object.isFrozen(t)){Object.freeze(e)}return r(e)},e)}return r(t)}function ui(t,e,r){var i=Object.keys(t);var n=[],u=[];var a=i.length;while(a--){var o=i[a];var s=t[o];n[a]=s;if(gu(s)){u.push(s)}}if(u.length){return ni($n(n),function(e){var n={};e.forEach(function(e,t){var r=i[t];n[r]=e});if(Object.isFrozen(t)){Object.freeze(n)}return n},r)}return e(t)}function ai(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{},i=n.hidden,u=i===void 0?false:i;Object.defineProperty(e,t,{value:r,configurable:true,enumerable:!u})}function oi(r){var n,i,u,a,o,s,c;return j.async(function e(t){while(1){switch(t.prev=t.next){case 0:n=[];i=false;u=false;t.prev=3;o=F(r);case 5:t.next=7;return j.awrap(o.next());case 7:if(!(i=!(s=t.sent).done)){t.next=13;break}c=s.value;n.push(c);case 10:i=false;t.next=5;break;case 13:t.next=19;break;case 15:t.prev=15;t.t0=t["catch"](3);u=true;a=t.t0;case 19:t.prev=19;t.prev=20;if(!(i&&o["return"]!=null)){t.next=24;break}t.next=24;return j.awrap(o["return"]());case 24:t.prev=24;if(!u){t.next=27;break}throw a;case 27:return t.finish(24);case 28:return t.finish(19);case 29:return t.abrupt("return",n);case 30:case"end":return t.stop()}}},null,null,[[3,15,19,29],[20,,24,28]],Promise)}function si(e,t){if(t instanceof RegExp){return function(e){return String(e).match(t)}}else if(vu(t)){return t}throw new Error("Invalid matcher")}function ci(e,t,r,n){if(typeof e!=="string"){t=arguments[0];r=arguments[1];n=arguments[2];e=null}if(r){if(n){t.__doc__=r}else{t.__doc__=fi(r)}}if(e){t.__name__=e}else if(t.name&&!Vu(t)){t.__name__=t.name}return t}function fi(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function li(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var r=e.length;if(t<=0){throw Error("previousSexp: Invalid argument sexp = ".concat(t))}e:while(t--&&r>=0){var n=1;while(n>0){var i=e[--r];if(!i){break e}if(i==="("||i.token==="("){n--}else if(i===")"||i.token===")"){n++}}r--}return e.slice(r+1)}function hi(e){if(!e||!e.length){return 0}var t=e.length;if(e[t-1].token==="\n"){return 0}while(--t){if(e[t].token==="\n"){var r=(e[t+1]||{}).token;if(r){return r.length}}}return 0}function pi(e,t){return f(e,t)===t.length;function f(r,n){function e(e,t){var r=Cr(e),n;try{for(r.s();!(n=r.n()).done;){var i=n.value;var u=f(i,t);if(u!==-1){return u}}}catch(e){r.e(e)}finally{r.f()}return-1}function t(){return r[u]===Symbol["for"]("symbol")&&!xn(n[o])}function i(){var e=r[u+1];var t=n[o+1];if(e!==undefined&&t!==undefined){return f([e],[t])}}var u=0;var a={};for(var o=0;o0){continue}}else if(t()){return-1}}else if(r[u]instanceof Array){var c=f(r[u],n.slice(o));if(c===-1||c+o>n.length){return-1}o+=c-1;u++;continue}else{return-1}u++}if(r.length!==u){return-1}return n.length}}function _i(e){this.__code__=e.replace(/\r/g,"")}_i.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?(?:define(?:-values|-syntax|-macro|-class|-record-type)?|(?:call-with-(?:input-file|output-file|port))|lambda|let-env|try|catch|when|unless|while|syntax-rules|(let|letrec)(-syntax|\*)?)$/],shift:{1:["&","#"]}}};_i.match=pi;_i.prototype._options=function e(t){var r=_i.defaults;if(typeof t==="undefined"){return Object.assign({},r)}var n=t&&t.exceptions||{};var i=n.specials||[];var u=n.shift||{1:[]};return Br(Br(Br({},r),t),{},{exceptions:{specials:[].concat(k(r.exceptions.specials),k(i)),shift:Br(Br({},u),{},{1:[].concat(k(r.exceptions.shift[1]),k(u[1]))})}})};_i.prototype.indent=function e(t){var r=Nn(this.__code__,true);return this._indent(r,t)};_i.exception_shift=function(u,e){function t(e){if(!e.length){return false}if(e.indexOf(u)!==-1){return true}else{var t=e.filter(function(e){return e instanceof RegExp});if(!t.length){return false}var r=Cr(t),n;try{for(r.s();!(n=r.n()).done;){var i=n.value;if(u.match(i)){return true}}}catch(e){r.e(e)}finally{r.f()}}return false}if(t(e.exceptions.specials)){return e.indent}var r=e.exceptions.shift;for(var n=0,i=Object.entries(r);n0){n.offset=0}if(u.toString()===t.toString()&&To(u)){return n.offset+u[0].col}else if(u.length===1){return n.offset+u[0].col+1}else{var s=-1;if(a){var c=_i.exception_shift(a.token,n);if(c!==-1){s=c}}if(s===-1){s=_i.exception_shift(u[1].token,n)}if(s!==-1){return n.offset+u[0].col+s}else if(u[0].line3&&u[1].line===u[3].line){if(u[1].token==="("||u[1].token==="["){return n.offset+u[1].col}return n.offset+u[3].col}else if(u[0].line===u[1].line){return n.offset+n.indent+u[0].col}else{var f=u.slice(2);for(var l=0;l")};di.prototype.match=function(e){return e.match(this.pattern)};function vi(){for(var e=arguments.length,t=new Array(e),r=0;r")};_i.Pattern=vi;_i.Ahead=di;var mi=/^[[(]$/;var yi=/^[\])]$/;var gi=/[^()[\]]/;var bi=new di(/[^)\]]/);var wi=Symbol["for"]("*");var Di=new vi([mi,wi,yi],[gi],"+");var Ei=new vi([mi,wi,yi],"+");var Ai=new vi([Symbol["for"]("symbol")],"?");var Fi=new vi([Symbol["for"]("symbol")],"*");var xi=[mi,Fi,yi];var Ci=new vi([mi,Symbol["for"]("symbol"),wi,yi],"+");var ki=Bi("define","lambda","define-macro","syntax-rules");var Oi=/^(?!.*\b(?:[()[\]]|define(?:-macro)?|let(?:\*|rec|-env|-syntax|)?|lambda|syntax-rules)\b).*$/;var Si=/^(?:#:)?(let(?:\*|rec|-env|-syntax)?)$/;function Bi(){for(var e=arguments.length,t=new Array(e),r=0;r0&&!o[e]){o[e]=li(a,e)}});var s=Cr(i),c;try{for(s.s();!(c=s.n()).done;){var f=A(c.value,3),l=f[0],h=f[1],p=f[2];h=h.valueOf();var _=h>0?o[h]:a;var d=_.filter(function(e){return e.trim()&&!Gn(e)});var v=r(_);var m=pi(l,d);var y=n.slice(u).find(function(e){return e.trim()&&!Gn(e)});if(m&&(p instanceof di&&p.match(y)||!p)){var g=u-v;if(n[g]!=="\n"){if(!n[g].trim()){n[g]="\n"}else{n.splice(g,0,"\n");u++}}u+=v;continue e}}}catch(e){s.e(e)}finally{s.f()}}this.__code__=n.join("");return this};_i.prototype._spaces=function(e){return new Array(e+1).join(" ")};_i.prototype.format=function e(t){var r=this.__code__.replace(/[ \t]*\n[ \t]*/g,"\n ");var n=Nn(r,true);var i=this._options(t);var u=0;var a=0;for(var o=0;o0&&arguments[0]!==undefined?arguments[0]:true;var n=new Map;function i(e){if(e instanceof Ni){if(n.has(e)){return n.get(e)}var t=new Ni;n.set(e,t);if(r){t.car=i(e.car)}else{t.car=e.car}t.cdr=i(e.cdr);t[Ru]=e[Ru];return t}return e}return i(this)};Ni.prototype.last_pair=function(){var e=this;while(true){if(e.cdr===Pi){return e}e=e.cdr}};Ni.prototype.to_array=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var t=[];if(this.car instanceof Ni){if(e){t.push(this.car.to_array())}else{t.push(this.car)}}else{t.push(this.car.valueOf())}if(this.cdr instanceof Ni){t=t.concat(this.cdr.to_array())}return t};Ni.fromArray=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(e instanceof Ni||r&&e instanceof Array&&e[Pu]){return e}if(t===false){var n=Pi;for(var i=e.length;i--;){n=new Ni(e[i],n)}return n}if(e.length&&!(e instanceof Array)){e=k(e)}var u=Pi;var a=e.length;while(a--){var o=e[a];if(o instanceof Array){o=Ni.fromArray(o,t,r)}else if(typeof o==="string"){o=sa(o)}else if(typeof o==="number"&&!Number.isNaN(o)){o=da(o)}u=new Ni(o,u)}return u};Ni.prototype.to_object=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var t=this;var r={};while(true){if(t instanceof Ni&&t.car instanceof Ni){var n=t.car;var i=n.car;if(i instanceof Ln){i=i.__name__}if(i instanceof sa){i=i.valueOf()}var u=n.cdr;if(u instanceof Ni){u=u.to_object(e)}if(bo(u)){if(!e){u=u.valueOf()}}r[i]=u;t=t.cdr}else{break}}return r};Ni.fromPairs=function(e){return e.reduce(function(e,t){return new Ni(new Ni(new Ln(t[0]),t[1]),e)},Pi)};Ni.fromObject=function(t){var e=Object.keys(t).map(function(e){return[e,t[e]]});return Ni.fromPairs(e)};Ni.prototype.reduce=function(e){var t=this;var r=Pi;while(true){if(t!==Pi){r=e(r,t.car);t=t.cdr}else{break}}return r};Ni.prototype.reverse=function(){if(this.haveCycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var t=Pi;while(e!==Pi){var r=e.cdr;e.cdr=t;t=e;e=r}return t};Ni.prototype.transform=function(n){function i(e){if(e instanceof Ni){if(e.replace){delete e.replace;return e}var t=n(e.car);if(t instanceof Ni){t=i(t)}var r=n(e.cdr);if(r instanceof Ni){r=i(r)}return new Ni(t,r)}return e}return i(this)};Ni.prototype.map=function(e){if(typeof this.car!=="undefined"){return new Ni(e(this.car),this.cdr===Pi?Pi:this.cdr.map(e))}else{return Pi}};var Ti=new Map;function Li(e){return e&&_(e)==="object"&&e.constructor===Object}var Ui=Object.getOwnPropertyNames(Array.prototype);var qi=[];Ui.forEach(function(e){qi.push(Array[e],Array.prototype[e])});function Mi(e){e=Fu(e);return qi.includes(e)}function Yi(e){return vu(e)&&(Vu(e)||e.__doc__)}function $i(r){var e=r.constructor||Object;var n=Li(r);var i=vu(r[Symbol.asyncIterator])||vu(r[Symbol.iterator]);var u;if(Ti.has(e)){u=Ti.get(e)}else{Ti.forEach(function(e,t){t=Fu(t);if(r.constructor===t&&(t===Object&&n&&!i||t!==Object)){u=e}})}return u}var zi=new Map;[[true,"#t"],[false,"#f"],[null,"null"],[undefined,"#"]].forEach(function(e){var t=A(e,2),r=t[0],n=t[1];zi.set(r,n)});function Vi(r){if(r&&_(r)==="object"){var n={};var e=Object.getOwnPropertySymbols(r);e.forEach(function(e){var t=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");n[t]=Zi(r[e])});var t=Object.getOwnPropertyNames(r);t.forEach(function(e){var t=r[e];if(t&&_(t)==="object"&&t.constructor===Object){n[e]=Vi(t)}else{n[e]=Zi(t)}});return n}return r}function Ji(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function Gi(e,t){return e.hasOwnProperty(t)&&vu(e.toString)}function Hi(e){if(Hu(e)){return"#"}var t=e.prototype&&e.prototype.constructor;if(vu(t)&&Vu(t)){if(e[Tu]&&t.hasOwnProperty("__name__")){var r=t.__name__;if(sa.isString(r)){r=r.toString();return"#")}return"#"}}if(e.hasOwnProperty("__name__")){var n=e.__name__;if(_(n)==="symbol"){n=Un(n)}if(typeof n==="string"){return"#")}}if(Gi(e,"toString")){return e.toString()}else if(e.name&&!Vu(e)){return"#")}else{return"#"}}var Wi=new Map;[[Error,function(e){return e.message}],[Ni,function(e,t){var r=t.quote,n=t.skip_cycles,i=t.pair_args;if(!n){e.markCycles()}return e.toString.apply(e,[r].concat(k(i)))}],[oa,function(e,t){var r=t.quote;if(r){return e.toString()}return e.valueOf()}],[sa,function(e,t){var r=t.quote;e=e.toString();if(r){return JSON.stringify(e).replace(/\\n/g,"\n")}return e}],[RegExp,function(e){return"#"+e.toString()}]].forEach(function(e){var t=A(e,2),r=t[0],n=t[1];Wi.set(r,n)});var Qi=[Ln,da,au,Wa,Sa,Ba,Ga,Yn];function Zi(e,t,r){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(zi.has(e)){return zi.get(e)}if(Ki(e)){return"#"}if(e){var n=e.constructor;if(Wi.has(n)){for(var i=arguments.length,u=new Array(i>3?i-3:0),a=3;a"}if(e===null){return"null"}if(_(e)==="object"){var f=e.constructor;if(!f){f=Object}var l;if(typeof f.__class__==="string"){l=f.__class__}else{var h=$i(e);if(h){if(vu(h)){return h(e,t)}else{throw new Error("toString: Invalid repr value")}}l=f.name}if(vu(e.toString)&&Vu(e.toString)){return e.toString().valueOf()}if(Ao(e)==="instance"){if(Vu(f)&&f.__name__){l=f.__name__.valueOf()}else if(!Hu(f)){l="instance"}}if(Do(e,Symbol.iterator)){if(l){return"#")}return"#"}if(Do(e,Symbol.asyncIterator)){if(l){return"#")}return"#"}if(l!==""){return"#<"+l+">"}return"#"}if(typeof e!=="string"){return e.toString()}return e}function Ki(e){return e&&_(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}Ni.prototype.markCycles=function(){Xi(this);return this};Ni.prototype.haveCycles=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(!e){return this.haveCycles("car")||this.haveCycles("cdr")}return!!(this[Ru]&&this[Ru][e])};function Xi(e){var t=[];var i=[];var u=[];function a(e){if(!t.includes(e)){t.push(e)}}function o(e,t,r,n){if(r instanceof Ni){if(n.includes(r)){if(!u.includes(r)){u.push(r)}if(!e[Ru]){e[Ru]={}}e[Ru][t]=r;if(!i.includes(e)){i.push(e)}return true}}}var s=In(function e(t,r){if(t instanceof Ni){delete t.ref;delete t[Ru];a(t);r.push(t);var n=o(t,"car",t.car,r);var i=o(t,"cdr",t.cdr,r);if(!n){s(t.car,r.slice())}if(!i){return new jn(function(){return e(t.cdr,r.slice())})}}});function r(e,t){if(e[Ru][t]instanceof Ni){var r=n.indexOf(e[Ru][t]);e[Ru][t]="#".concat(r,"#")}}s(e,[]);var n=t.filter(function(e){return u.includes(e)});n.forEach(function(e,t){e[Nu]="#".concat(t,"=")});i.forEach(function(e){r(e,"car");r(e,"cdr")})}Ni.prototype.toString=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.nested,n=r===void 0?false:r;var i=[];if(this[Nu]){i.push(this[Nu]+"(")}else if(!n){i.push("(")}var u;if(this[Ru]&&this[Ru].car){u=this[Ru].car}else{u=Zi(this.car,e,true)}if(u!==undefined){i.push(u)}if(this.cdr instanceof Ni){if(this[Ru]&&this[Ru].cdr){i.push(" . ");i.push(this[Ru].cdr)}else{if(this.cdr[Nu]){i.push(" . ")}else{i.push(" ")}var a=this.cdr.toString(e,{nested:true});i.push(a)}}else if(this.cdr!==Pi){i=i.concat([" . ",Zi(this.cdr,e,true)])}if(!n||this[Nu]){i.push(")")}return i.join("")};Ni.prototype.set=function(e,t){this[e]=t;if(t instanceof Ni){this.markCycles()}};Ni.prototype.append=function(e){if(e instanceof Array){return this.append(Ni.fromArray(e))}var t=this;if(t.car===undefined){if(e instanceof Ni){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(e!==Pi){while(true){if(t instanceof Ni&&t.cdr!==Pi){t=t.cdr}else{break}}t.cdr=e}return this};Ni.prototype.serialize=function(){return[this.car,this.cdr]};Ni.prototype[Symbol.iterator]=function(){var r=this;return{next:function e(){var t=r;r=t.cdr;if(t===Pi){return{value:undefined,done:true}}else{return{value:t.car,done:false}}}}};function eu(e){return e<0?-e:e}function tu(e,t){var r=h(t),n=r[0],i=r.slice(1);while(i.length>0){var u=i,a=A(u,1),o=a[0];if(!e(n,o)){return false}var s=i;var c=h(s);n=c[0];i=c.slice(1)}return true}function ru(e,t){if(vu(e)){return vu(t)&&Fu(e)===Fu(t)}else if(e instanceof da){if(!(t instanceof da)){return false}var r;if(e.__type__===t.__type__){if(e.__type__==="complex"){r=e.__im__.__type__===t.__im__.__type__&&e.__re__.__type__===t.__re__.__type__}else{r=true}if(r&&e.cmp(t)===0){if(e.valueOf()===0){return Object.is(e.valueOf(),t.valueOf())}return true}}return false}else if(typeof e==="number"){if(typeof t!=="number"){return false}if(Number.isNaN(e)){return Number.isNaN(t)}if(e===Number.NEGATIVE_INFINITY){return t===Number.NEGATIVE_INFINITY}if(e===Number.POSITIVE_INFINITY){return t===Number.POSITIVE_INFINITY}return ru(da(e),da(t))}else if(e instanceof oa){if(!(t instanceof oa)){return false}return e.__char__===t.__char__}else{return e===t}}function nu(e,t){if(Ao(e)!==Ao(t)){return false}if(!iu(e)){return false}if(e instanceof RegExp){return e.source===t.source}if(e instanceof sa){return e.valueOf()===t.valueOf()}return ru(e,t)}function iu(e){return e instanceof Ln||sa.isString(e)||e===Pi||e===null||e instanceof oa||e instanceof da||e===true||e===false}var uu=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e===0){return 0}else if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function au(e,t,r,n){if(typeof this!=="undefined"&&this.constructor!==au||typeof this==="undefined"){return new au(e,t)}yo("Macro",e,"string",1);yo("Macro",t,"function",2);if(r){if(n){this.__doc__=r}else{this.__doc__=fi(r)}}this.__name__=e;this.__fn__=t}au.defmacro=function(e,t,r,n){var i=new au(e,t,r,n);i.__defmacro__=true;return i};au.prototype.invoke=function(e,t,r){var n=t.env,i=t.dynamic_scope,u=t.error;var a={dynamic_scope:i,error:u,macro_expand:r};var o=this.__fn__.call(n,e,a,this.__name__);return o};au.prototype.toString=function(){return"#")};var ou="define-macro";var su=-1e4;function cu(c){return function(){var r=O(j.mark(function e(r,y){var u,g,n,i,a,b,w,D,E,A,F,x,o,C,s;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:s=function e(){s=O(j.mark(function e(r,n,i){var u,a,o,s,c,f,l,h,p,_,d,v,m;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(!(r instanceof Ni&&r.car instanceof Ln)){t.next=50;break}if(!r[Pu]){t.next=3;break}return t.abrupt("return",r);case 3:u=r.car.valueOf();a=i.get(r.car,{throwError:false});o=b(r.car);s=o||w(a,r)||D(a);if(!(s&&r.cdr.car instanceof Ni)){t.next=28;break}if(!o){t.next=15;break}g=A(r.cdr.car);t.next=12;return x(r.cdr.car,n);case 12:c=t.sent;t.next=17;break;case 15:g=E(r.cdr.car);c=r.cdr.car;case 17:t.t0=Ni;t.t1=r.car;t.t2=Ni;t.t3=c;t.next=23;return C(r.cdr.cdr,n,i);case 23:t.t4=t.sent;t.t5=new t.t2(t.t3,t.t4);return t.abrupt("return",new t.t0(t.t1,t.t5));case 28:if(!F(u,a)){t.next=50;break}f=a instanceof fu?r:r.cdr;t.next=32;return a.invoke(f,Br(Br({},y),{},{env:i}),true);case 32:l=t.sent;if(!(a instanceof fu)){t.next=41;break}h=l,p=h.expr,_=h.scope;if(!(p instanceof Ni)){t.next=40;break}if(!(n!==-1&&n<=1||n")}return"#"};fu.className="syntax";var lu=function(e){u(r,e);var t=Fr(r);function r(){y(this,r);return t.apply(this,arguments)}return r}(fu);fu.Parameter=lu;function hu(e,t,w,D){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:{};var E={"...":{symbols:{},lists:[]},symbols:{}};var A=r.expansion,F=r.define;function x(e){if(Mr()){console.log(e)}}x(w);function C(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:false;x({code:t&&Zi(t,true),pattern:e&&Zi(e,true)});if(iu(e)&&!(e instanceof Ln)){return nu(e,t)}if(e instanceof Ln&&w.includes(e.literal())){var i=A.ref(t);if(Ln.is(t,e)){if(typeof i==="undefined"){return true}return i===F||i===io}return false}if(e instanceof Ni&&e.car instanceof Ni&&e.car.cdr instanceof Ni&&Ln.is(e.car.cdr.car,D)){x(">> 0");if(t===Pi){x({pattern:e.toString()});if(e.car.car instanceof Ln){if(e.car.cdr instanceof Ni&&Ln.is(e.car.cdr.car,D)){var u=e.car.car.valueOf();var a=e.last_pair();if(Ln.is(a.car,D)){E["..."].symbols[u]=null;return true}else{return false}}var o=e.car.car.valueOf();if(E["..."].symbols[o]){throw new Error("syntax: named ellipsis can only "+"appear onces")}E["..."].symbols[o]=t}}}if(e instanceof Ni&&e.cdr instanceof Ni&&Ln.is(e.cdr.car,D)){if(e.cdr.cdr!==Pi){if(e.cdr.cdr instanceof Ni){var s=e.cdr.cdr.length();var c=t.length();var f=t;while(c-1>s){f=f.cdr;c--}var l=f.cdr;f.cdr=Pi;if(!C(e.cdr.cdr,l,r,n)){return false}}}if(e.car instanceof Ln){var h=e.car.__name__;if(E["..."].symbols[h]&&!r.includes(h)&&!n){throw new Error("syntax: named ellipsis can only appear onces")}x(">> 1");if(t===Pi){x(">> 2");if(n){x("NIL");E["..."].symbols[h]=Pi}else{x("NULL");E["..."].symbols[h]=null}}else if(t instanceof Ni&&(t.car instanceof Ni||t.car===Pi)){x(">> 3 "+n);if(n){if(E["..."].symbols[h]){var p=E["..."].symbols[h];if(p===Pi){p=new Ni(Pi,new Ni(t,Pi))}else{p=p.append(new Ni(t,Pi))}E["..."].symbols[h]=p}else{E["..."].symbols[h]=new Ni(t,Pi)}}else{x(">> 4");E["..."].symbols[h]=new Ni(t,Pi)}}else{x(">> 6");if(t instanceof Ni){x(">> 7 "+n);r.push(h);if(!E["..."].symbols[h]){E["..."].symbols[h]=new Ni(t,Pi)}else{var _=E["..."].symbols[h];E["..."].symbols[h]=_.append(new Ni(t,Pi))}x({IIIIII:E["..."].symbols[h].toString()})}else{x(">> 8");return false}}return true}else if(e.car instanceof Ni){var d=k(r);if(t===Pi){x(">> 9");E["..."].lists.push(Pi);return true}x(">> 10");var v=t;while(v instanceof Ni){if(!C(e.car,v.car,d,true)){return false}v=v.cdr}return true}return false}if(e instanceof Ln){if(Ln.is(e,D)){throw new Error("syntax: invalid usage of ellipsis")}x(">> 11");var m=e.__name__;if(w.includes(m)){return true}x({name:m,ellipsis:n});if(n){E["..."].symbols[m]=E["..."].symbols[m]||[];E["..."].symbols[m].push(t)}E.symbols[m]=t;if(!E.symbols[m]);return true}if(e instanceof Ni&&t instanceof Ni){x(">> 12");x({a:12,code:t&&t.toString(),pattern:e.toString()});if(t.cdr===Pi){var y=e.car instanceof Ln&&e.cdr instanceof Ln;if(y){if(!C(e.car,t.car,r,n)){return false}x(">> 12 | 1");var g=e.cdr.valueOf();if(!(g in E.symbols)){E.symbols[g]=Pi}g=e.car.valueOf();if(!(g in E.symbols)){E.symbols[g]=t.car}return true}}x({pattern:e.toString(),code:t.toString()});if(e.cdr instanceof Ni&&e.car instanceof Ln&&e.cdr.cdr instanceof Ni&&e.cdr.car instanceof Ln&&Ln.is(e.cdr.cdr.car,D)&&e.cdr.cdr.cdr instanceof Ni&&!Ln.is(e.cdr.cdr.cdr.car,D)&&C(e.car,t.car,r,n)&&C(e.cdr.cdr.cdr,t.cdr,r,n)){var b=e.cdr.car.__name__;x({pattern:e.car.toString(),code:t.car.toString(),name:b});if(w.includes(b)){return true}E["..."].symbols[b]=null;return true}x("recur");if(C(e.car,t.car,r,n)&&C(e.cdr,t.cdr,r,n)){return true}}else if(e===Pi&&(t===Pi||t===undefined)){return true}else if(e.car instanceof Ni&&Ln.is(e.car.car,D)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(C(e,t)){return E}}function pu(e,i){function u(t){if(t instanceof Ni){if(!i.length){return t}var e=u(t.car);var r=u(t.cdr);return new Ni(e,r)}else if(t instanceof Ln){var n=i.find(function(e){return e.gensym===t});if(n){return Ln(n.name)}return t}else{return t}}return u(e)}function _u(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var O=e.bindings,t=e.expr,S=e.scope,a=e.symbols,c=e.names,B=e.ellipsis;var f={};function o(e){if(e instanceof Ln){return true}return["string","symbol"].includes(_(e))}function j(e){if(!o(e)){var t=Ao(e);throw new Error("syntax: internal error, need symbol got ".concat(t))}var r=e.valueOf();if(r===B){throw new Error("syntax: internal error, ellipis not transformed")}var n=_(r);if(["string","symbol"].includes(n)){if(r in O.symbols){return O.symbols[r]}else if(n==="string"&&r.match(/\./)){var i=r.split(".");var u=i[0];if(u in O.symbols){return Ni.fromArray([Ln("."),O.symbols[u]].concat(i.slice(1).map(function(e){return sa(e)})))}}}if(a.includes(r)){return Ln(r)}return s(r)}function I(e){if(Mr()){console.log(e)}}function s(e){if(!f[e]){var t=S.ref(e);var r=Mn(e);if(t){var n=S.get(e);S.set(r,n)}else{var i=S.get(e,{throwError:false});if(typeof i!=="undefined"){S.set(r,i)}}c.push({name:e,gensym:r});f[e]=r;if(typeof e==="string"&&e.match(/\./)){var u=e.split(".").filter(Boolean),a=h(u),o=a[0],s=a.slice(1);if(f[o]){$u(r,"__object__",[f[o]].concat(k(s)))}}}return f[e]}function P(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:function(){};var i=r.nested;I(" ==> "+e.toString(true));I(t);if(e instanceof Ln){var u=e.valueOf();I("[t 1");if(t[u]){if(t[u]instanceof Ni){var a=t[u],o=a.car,s=a.cdr;if(i){var c=o.car,f=o.cdr;if(f!==Pi){n(u,new Ni(f,Pi))}return c}if(s!==Pi){n(u,s)}return o}else if(t[u]instanceof Array){n(u,t[u].slice(1));return t[u][0]}}return j(u)}if(e instanceof Ni){if(e.car instanceof Ln&&e.cdr instanceof Ni&&Ln.is(e.cdr.car,B)){I("[t 2");var l=e.car.valueOf();var h=t[l];I({expr:e.toString(true),name:l,bindings:t,item:h});if(h===null){return}else if(h){I({b:t[l].toString()});if(h instanceof Ni){I("[t 2 Pair "+i);I({______:h.toString()});var p=h.car,_=h.cdr;if(i){if(_!==Pi){I("|| next 1");n(l,_)}I({car:p.toString()});return p}else{if(p.cdr!==Pi){I("|| next 2");n(l,new Ni(p.cdr,_))}I({car:p.car.toString()});return p.car}}else if(h instanceof Array){I("[t 2 Array "+i);if(i){n(l,h.slice(1));return Ni.fromArray(h)}else{var d=h.slice(1);if(d.length){n(l,d)}return h[0]}}else{return h}}}I("[t 3 recur "+e.toString());var v=P(e.car,t,r,n);var m=P(e.cdr,t,r,n);return new Ni(v,m)}return e}function N(t,r){var e=Object.values(t);var n=Object.getOwnPropertySymbols(t);if(n.length){e.push.apply(e,k(n.map(function(e){return t[e]})))}return e.length&&e.every(function(e){if(e===null){return!r}return e instanceof Ni||e===Pi||e instanceof Array&&e.length})}function R(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function T(i){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},t=e.disabled;I("traverse>> "+i.toString());if(i instanceof Ni){if(!t&&i.car instanceof Ni&&Ln.is(i.car.car,B)){return T(i.car.cdr,{disabled:true})}if(i.cdr instanceof Ni&&Ln.is(i.cdr.car,B)&&!t){I(">> 1");var r=O["..."].symbols;var n=Object.values(r);if(n.length&&n.every(function(e){return e===null})){return T(i.cdr.cdr,{disabled:t})}var u=R(r);var a=i.car instanceof Ln&&Ln.is(i.cdr.cdr.car,B);if(i.car instanceof Ni||a){if(O["..."].lists[0]===Pi){return Pi}var o=i.car;if(a){o=new Ni(i.car,new Ni(i.cdr.car,Pi))}I(">> 2");var s;if(u.length){I(">> 2 (a)");var c=Br({},r);s=Pi;var f=function e(){if(!N(c)){return"break"}var n={};var t=function e(t,r){n[t]=r};var r=P(o,c,{nested:true},t);if(r!==undefined){if(a){if(s===Pi){s=r}else{s=s.append(r)}}else{s=new Ni(r,s)}}c=n};while(true){var l=f();if(l==="break")break}if(s!==Pi&&!a){s=s.reverse()}if(i.cdr.cdr!==Pi&&!Ln.is(i.cdr.cdr.car,B)){var h=T(i.cdr.cdr,{disabled:t});return s.append(h)}return s}else{I(">> 3");var p=P(i.car,r,{nested:true});if(p){return new Ni(p,Pi)}return Pi}}else if(i.car instanceof Ln){I(">> 4");if(Ln.is(i.cdr.cdr.car,B)){I(">> 4 (a)")}else{I(">> 4 (b)")}var _=i.car.__name__;var d=L({},_,r[_]);var v=r[_]===null;var m=Pi;var y=function e(){if(!N(d,true)){I({bind:d});return"break"}var n={};var t=function e(t,r){n[t]=r};var r=P(i,d,{nested:false},t);I({value:r.toString()});if(typeof r!=="undefined"){m=new Ni(r,m)}d=n};while(true){var g=y();if(g==="break")break}if(m!==Pi){m=m.reverse()}if(i.cdr instanceof Ni){if(i.cdr.cdr instanceof Ni||i.cdr.cdr instanceof Ln){var b=T(i.cdr.cdr,{disabled:t});if(v){return b}I("<<<< 1");m.append(b)}}I("<<<< 2");return m}}var w=T(i.car,{disabled:t});var D;var E;if(i.car instanceof Ln){var A=S.get(i.car,{throwError:false});E=A instanceof au&&A.__name__==="syntax-rules"}if(E){if(i.cdr.car instanceof Ln){D=new Ni(T(i.cdr.car,{disabled:t}),new Ni(i.cdr.cdr.car,T(i.cdr.cdr.cdr,{disabled:t})))}else{D=new Ni(i.cdr.car,T(i.cdr.cdr,{disabled:t}))}I("REST >>>> "+D.toString())}else{D=T(i.cdr,{disabled:t})}I({a:true,car:Zi(i.car),cdr:Zi(i.cdr),head:Zi(w),rest:Zi(D)});return new Ni(w,D)}if(i instanceof Ln){if(t&&Ln.is(i,B)){return i}var F=Object.keys(O["..."].symbols);var x=i.literal();if(F.includes(x)){var C="missing ellipsis symbol next to name `".concat(x,"'");throw new Error("syntax-rules: ".concat(C))}var k=j(i);if(typeof k!=="undefined"){return k}}return i}return T(t,{})}function du(e){return bu(e)||e===Pi||e===null}function vu(e){return typeof e==="function"&&typeof e.bind==="function"}function mu(e){return e instanceof Bo}function yu(e){return vu(e)||mu(e)}function gu(e){if(e instanceof Yn){return false}if(e instanceof Promise){return true}return e&&vu(e.then)}function bu(e){return typeof e==="undefined"}function wu(e){switch(_(e)){case"string":return sa(e);case"bigint":return da(e);case"number":if(Number.isNaN(e)){return ro}else{return da(e)}}return e}function Du(n,i){var e=Object.getOwnPropertyNames(n);var t=Object.getOwnPropertySymbols(n);e.concat(t).forEach(function(e){var t=i(n[e]);var r=Object.getOwnPropertyDescriptor(n,e);if(!r||r.writable&&n[e]!==t){n[e]=t}});return n}function Eu(t){var e=[sa,oa,da].some(function(e){return t instanceof e});if(e){return t.valueOf()}if(t instanceof Array){return t.map(Eu)}if(t instanceof Yn){delete t.then}if(Li(t)){return Du(t,Eu)}return t}function Au(e,t){if(e instanceof Ni){e.markCycles();return Qa(e)}if(vu(e)){if(t){return xu(e,t)}}return wu(e)}function Fu(e){if(ku(e)){return e[Iu]}return e}function xu(e,t){if(e[Symbol["for"]("__bound__")]){return e}var r=e.bind(t);var n=Object.getOwnPropertyNames(e);var i=Cr(n),u;try{for(i.s();!(u=i.n()).done;){var a=u.value;if(Yu(a)){try{r[a]=e[a]}catch(e){}}}}catch(e){i.e(e)}finally{i.f()}$u(r,"__fn__",e);$u(r,"__context__",t);$u(r,"__bound__",true);if(Hu(e)){$u(r,"__native__",true)}if(Li(t)&&Vu(e)){$u(r,"__method__",true)}r.valueOf=function(){return e};return r}function Cu(e){return ku(e)&&e[Symbol["for"]("__context__")]===Object}function ku(e){return!!(vu(e)&&e[Iu])}function Ou(e){if(vu(e)){var t=e[ju];if(t&&(t===ps||t.constructor&&t.constructor.__class__)){return true}}return false}function Su(e){return e instanceof Sa||e instanceof Ba}function Bu(e){if(vu(e)){if(Su(e[ju])){return true}}return false}var ju=Symbol["for"]("__context__");var Iu=Symbol["for"]("__fn__");var Pu=Symbol["for"]("__data__");var Nu=Symbol["for"]("__ref__");var Ru=Symbol["for"]("__cycles__");var Tu=Symbol["for"]("__class__");var Lu=Symbol["for"]("__method__");var Uu=Symbol["for"]("__prototype__");var qu=Symbol["for"]("__lambda__");var Mu=["name","length","caller","callee","arguments","prototype"];function Yu(e){return!Mu.includes(e)}function $u(e,t,r){Object.defineProperty(e,Symbol["for"](t),{get:function e(){return r},set:function e(){},configurable:false,enumerable:false})}function zu(t,r){try{Object.defineProperty(t,"length",{get:function e(){return r}});return t}catch(e){var n=new Array(r).fill(0).map(function(e,t){return"a"+t}).join(",");var i=new Function("f","return function(".concat(n,") {\n return f.apply(this, arguments);\n };"));return i(t)}}function Vu(e){return e&&e[qu]}function Ju(e){return e&&e[Lu]}function Gu(e){return Vu(e)&&!e[Uu]&&!Ju(e)&&!Bu(e)}function Hu(e){var t=Symbol["for"]("__native__");return vu(e)&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[t]===true||!e.name.match(/^bound /)&&!e[t])}function Wu(e){var g;switch(e){case Symbol["for"]("letrec"):g="letrec";break;case Symbol["for"]("let"):g="let";break;case Symbol["for"]("let*"):g="let*";break;default:throw new Error("Invalid let_macro value")}return au.defmacro(g,function(t,e){var f=e.dynamic_scope,l=e.error,r=e.macro_expand;var h;if(t.car instanceof Ln){if(!(t.cdr.car instanceof Ni||t.cdr.car===Pi)){throw new Error("let require list of pairs")}var n;if(t.cdr.car===Pi){h=Pi;n=Pi}else{n=t.cdr.car.map(function(e){return e.car});h=t.cdr.car.map(function(e){return e.cdr.car})}return Ni.fromArray([Ln("letrec"),[[t.car,Ni(Ln("lambda"),Ni(n,t.cdr.cdr))]],Ni(t.car,h)])}else if(r){return}var p=this;h=io.get("list->array")(t.car);var _=p.inherit(g);var d,v;if(g==="let*"){v=_}else if(g==="let"){d=[]}var m=0;function y(){var e=new Ni(new Ln("begin"),t.cdr);return Io(e,{env:_,dynamic_scope:f,error:l})}return function t(){var r=h[m++];if(f){f=g==="let*"?_:p}if(!r){if(d&&d.length){var e=d.map(function(e){return e.value});var n=e.filter(gu);if(n.length){return $n(e).then(function(e){for(var t=0,r=e.length;t1&&arguments[1]!==undefined?arguments[1]:{},r=t.dynamic_scope,n=t.error;var i=this;if(r){r=this}var u=e;var a=[];while(u instanceof Ni){a.push(Io(u.car,{env:i,dynamic_scope:r,error:n}));u=u.cdr}var o=a.filter(gu).length;if(o){return $n(a).then(s.bind(this))}else{return s.call(this,a)}})}function Zu(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n2?n-2:0),u=2;u1&&arguments[1]!==undefined?arguments[1]:null;return function(){for(var e=arguments.length,t=new Array(e),r=0;r1?e-1:0),r=1;r=a){return u.apply(this,n)}else{return i}}return i.apply(this,arguments)}}function aa(n,i){yo("limit",i,"function",2);return function(){for(var e=arguments.length,t=new Array(e),r=0;r1){e=e.toLowerCase();if(oa.__names__[e]){t=e;e=oa.__names__[e]}else{throw new Error("Internal: Unknown named character")}}else{t=oa.__rev_names__[e]}Object.defineProperty(this,"__char__",{value:e,enumerable:true});if(t){Object.defineProperty(this,"__name__",{value:t,enumerable:true})}}oa.__names__=Kr;oa.__rev_names__={};Object.keys(oa.__names__).forEach(function(e){var t=oa.__names__[e];oa.__rev_names__[t]=e});oa.prototype.toUpperCase=function(){return oa(this.__char__.toUpperCase())};oa.prototype.toLowerCase=function(){return oa(this.__char__.toLowerCase())};oa.prototype.toString=function(){return"#\\"+(this.__name__||this.__char__)};oa.prototype.valueOf=oa.prototype.serialize=function(){return this.__char__};function sa(e){if(typeof this!=="undefined"&&!(this instanceof sa)||typeof this==="undefined"){return new sa(e)}if(e instanceof Array){this.__string__=e.map(function(e,t){yo("LString",e,"character",t+1);return e.toString()}).join("")}else{this.__string__=e.valueOf()}}{var ca=["length","constructor"];var fa=Object.getOwnPropertyNames(String.prototype).filter(function(e){return!ca.includes(e)});var la=function e(n){return function(){for(var e=arguments.length,t=new Array(e),r=0;r0){r.push(this.__string__.substring(0,e))}r.push(t);if(e1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof da){return e}if(typeof this!=="undefined"&&!(this instanceof da)||typeof this==="undefined"){return new da(e,t)}if(typeof e==="undefined"){throw new Error("Invalid LNumber constructor call")}var r=da.getType(e);if(da.types[r]){return da.types[r](e,t)}var n=e instanceof Array&&sa.isString(e[0])&&da.isNumber(e[1]);if(e instanceof da){return da(e.value)}if(!da.isNumber(e)&&!n){throw new Error("You can't create LNumber from ".concat(Ao(e)))}if(e===null){e=0}var i;if(n){var u=e,a=A(u,2),o=a[0],s=a[1];if(o instanceof sa){o=o.valueOf()}if(s instanceof da){s=s.valueOf()}var c=o.match(/^([+-])/);var f=false;if(c){o=o.replace(/^[+-]/,"");if(c[1]==="-"){f=true}}}if(Number.isNaN(e)){return Ea(e)}else if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(n){var l;switch(s){case 8:l="0o";break;case 16:l="0x";break;case 2:l="0b";break;case 10:l="";break}if(typeof l==="undefined"){var h=BigInt(s);i=k(o).map(function(e,t){return BigInt(parseInt(e,s))*ba(h,BigInt(t))}).reduce(function(e,t){return e+t})}else{i=BigInt(l+o)}}else{i=BigInt(e)}if(f){i*=BigInt(-1)}}else{i=e}return Oa(i,true)}else if(typeof Lr!=="undefined"&&!(e instanceof Lr)){if(e instanceof Array){return Oa(p(Lr,k(e)))}return Oa(new Lr(e))}else if(n){this.constant(parseInt(o,s),"integer")}else{this.constant(e,"integer")}}da.prototype.constant=function(e,t){Object.defineProperty(this,"__value__",{value:e,enumerable:true});Object.defineProperty(this,"__type__",{value:t,enumerable:true})};da.types={float:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return new Ea(t,r)},complex:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!da.isComplex(t)){t={im:0,re:t}}return new Da(t,r)},rational:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!da.isRational(t)){t={num:t,denom:1}}return new ka(t,r)}};da.prototype.serialize=function(){return this.__value__};da.prototype.isNaN=function(){return Number.isNaN(this.__value__)};da.prototype.gcd=function(e){var t=this.abs();e=e.abs();if(e.cmp(t)===1){var r=t;t=e;e=r}while(true){t=t.rem(e);if(t.cmp(0)===0){return e}e=e.rem(t);if(e.cmp(0)===0){return t}}};da.isFloat=function e(t){return t instanceof Ea||Number(t)===t&&t%1!==0};da.isNumber=function(e){return e instanceof da||da.isNative(e)||da.isBN(e)};da.isComplex=function(e){if(!e){return false}var t=e instanceof Da||(da.isNumber(e.im)||Number.isNaN(e.im))&&(da.isNumber(e.re)||Number.isNaN(e.re));return t};da.isRational=function(e){if(!e){return false}return e instanceof ka||da.isNumber(e.num)&&da.isNumber(e.denom)};da.isInteger=function(e){if(!(da.isNative(e)||e instanceof da)){return false}if(da.isFloat(e)){return false}if(da.isRational(e)){return false}if(da.isComplex(e)){return false}return true};da.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};da.isBigInteger=function(e){return e instanceof Oa||typeof e==="bigint"||da.isBN(e)};da.isBN=function(e){return typeof Lr!=="undefined"&&e instanceof Lr};da.getArgsType=function(e,t){if(e instanceof Ea||t instanceof Ea){return Ea}if(e instanceof Oa||t instanceof Oa){return Oa}return da};da.prototype.toString=function(e){if(Number.isNaN(this.__value__)){return"+nan.0"}if(e>2&&e<36){return this.__value__.toString(e)}return this.__value__.toString()};da.prototype.asType=function(e){var t=da.getType(this);return da.types[t]?da.types[t](e):da(e)};da.prototype.isBigNumber=function(){return typeof this.__value__==="bigint"||typeof Lr!=="undefined"&&!(this.value instanceof Lr)};["floor","ceil","round"].forEach(function(e){da.prototype[e]=function(){if(this["float"]||da.isFloat(this.__value__)){return da(Math[e](this.__value__))}else{return da(Math[e](this.valueOf()))}}});da.prototype.valueOf=function(){if(da.isNative(this.__value__)){return Number(this.__value__)}else if(da.isBN(this.__value__)){return this.__value__.toNumber()}};var va=function(){var e=function e(t,r){return[t,r]};return{bigint:{bigint:e,float:function e(t,r){return[Ea(t.valueOf()),r]},rational:function e(t,r){return[{num:t,denom:1},r]},complex:function e(t,r){return[{im:0,re:t},r]}},integer:{integer:e,float:function e(t,r){return[Ea(t.valueOf()),r]},rational:function e(t,r){return[{num:t,denom:1},r]},complex:function e(t,r){return[{im:0,re:t},r]}},float:{bigint:function e(t,r){return[t,r&&Ea(r.valueOf())]},integer:function e(t,r){return[t,r&&Ea(r.valueOf())]},float:e,rational:function e(t,r){return[t,r&&Ea(r.valueOf())]},complex:function e(t,r){return[{re:t,im:Ea(0)},r]}},complex:{bigint:t("bigint"),integer:t("integer"),float:t("float"),rational:t("rational"),complex:function e(t,r){var n=da.coerce(t.__re__,r.__re__),i=A(n,2),u=i[0],a=i[1];var o=da.coerce(t.__im__,r.__im__),s=A(o,2),c=s[0],f=s[1];return[{im:c,re:u},{im:f,re:a}]}},rational:{bigint:function e(t,r){return[t,r&&{num:r,denom:1}]},integer:function e(t,r){return[t,r&&{num:r,denom:1}]},float:function e(t,r){return[Ea(t.valueOf()),r]},rational:e,complex:function e(t,r){return[{im:ma(t.__type__,r.__im__.__type__,0)[0],re:ma(t.__type__,r.__re__.__type__,t)[0]},{im:ma(t.__type__,r.__im__.__type__,r.__im__)[0],re:ma(t.__type__,r.__re__.__type__,r.__re__)[0]}]}}};function t(r){return function(e,t){return[{im:ma(r,e.__im__.__type__,0,e.__im__)[1],re:ma(r,e.__re__.__type__,0,e.__re__)[1]},{im:ma(r,e.__im__.__type__,0,0)[1],re:ma(r,t.__type__,0,t)[1]}]}}}();function ma(e,t,r,n){return va[e][t](r,n)}da.coerce=function(e,t){var r=da.getType(e);var n=da.getType(t);if(!va[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!va[r][n]){throw new Error("LNumber::coerce unknown rhs type ".concat(n))}var i=va[r][n](e,t);return i.map(function(e){return da(e,true)})};da.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof da)){throw new Error("LNumber: you can't coerce ".concat(Ao(e)))}if(typeof e==="number"){e=da(e)}return da.coerce(this,e)};da.getType=function(e){if(e instanceof da){return e.__type__}if(da.isFloat(e)){return"float"}if(da.isComplex(e)){return"complex"}if(da.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof Lr!=="undefined"&&!(e instanceof Lr)){return"bigint"}};da.prototype.isFloat=function(){return!!(da.isFloat(this.__value__)||this["float"])};var ya={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var ga={};Object.keys(ya).forEach(function(t){ga[ya[t]]=t;da.prototype[t]=function(e){return this.op(ya[t],e)}});da._ops={"*":function e(t,r){return t*r},"+":function e(t,r){return t+r},"-":function e(t,r){if(typeof r==="undefined"){return-t}return t-r},"/":function e(t,r){return t/r},"%":function e(t,r){return t%r},"|":function e(t,r){return t|r},"&":function e(t,r){return t&r},"~":function e(t){return~t},">>":function e(t,r){return t>>r},"<<":function e(t,r){return t<1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof Da)||typeof this==="undefined"){return new Da(e,t)}if(e instanceof Da){return Da({im:e.__im__,re:e.__re__})}if(da.isNumber(e)&&t){if(!t){return Number(e)}}else if(!da.isComplex(e)){throw new Error("Invalid constructor call for LComplex")}var r=e.im instanceof da?e.im:da(e.im);var n=e.re instanceof da?e.re:da(e.re);this.constant(r,n)}Da.prototype=Object.create(da.prototype);Da.prototype.constructor=Da;Da.prototype.constant=function(e,t){Object.defineProperty(this,"__im__",{value:e,enumerable:true});Object.defineProperty(this,"__re__",{value:t,enumerable:true});Object.defineProperty(this,"__type__",{value:"complex",enumerable:true})};Da.prototype.serialize=function(){return{re:this.__re__,im:this.__im__}};Da.prototype.toRational=function(e){if(da.isFloat(this.__im__)&&da.isFloat(this.__re__)){var t=Ea(this.__im__).toRational(e);var r=Ea(this.__re__).toRational(e);return Da({im:t,re:r})}return this};Da.prototype.add=function(e){return this.complex_op("add",e,function(e,t,r,n){return{re:e.add(t),im:r.add(n)}})};Da.prototype.factor=function(){if(this.__im__ instanceof Ea||this.__im__ instanceof Ea){var e=this.__re__,t=this.__im__;var r,n;if(e instanceof Ea){r=e.toRational().mul(e.toRational())}else{r=e.mul(e)}if(t instanceof Ea){n=t.toRational().mul(t.toRational())}else{n=t.mul(t)}return r.add(n)}else{return this.__re__.mul(this.__re__).add(this.__im__.mul(this.__im__))}};Da.prototype.modulus=function(){return this.factor().sqrt()};Da.prototype.conjugate=function(){return Da({re:this.__re__,im:this.__im__.sub()})};Da.prototype.sqrt=function(){var e=this.modulus();var t,r;if(e.cmp(0)===0){t=r=e}else if(this.__re__.cmp(0)===1){t=Ea(.5).mul(e.add(this.__re__)).sqrt();r=this.__im__.div(t).div(2)}else{r=Ea(.5).mul(e.sub(this.__re__)).sqrt();if(this.__im__.cmp(0)===-1){r=r.sub()}t=this.__im__.div(r).div(2)}return Da({im:r,re:t})};Da.prototype.div=function(e){if(da.isNumber(e)&&!da.isComplex(e)){if(!(e instanceof da)){e=da(e)}var t=this.__re__.div(e);var r=this.__im__.div(e);return Da({re:t,im:r})}else if(!da.isComplex(e)){throw new Error("[LComplex::div] Invalid value")}var n=this.coerce(e),i=A(n,2),u=i[0],a=i[1];var o=a.factor();var s=u.mul(a.conjugate());var c=s.__re__.op("/",o);var f=s.__im__.op("/",o);return Da({re:c,im:f})};Da.prototype.sub=function(e){return this.complex_op("sub",e,function(e,t,r,n){return{re:e.sub(t),im:r.sub(n)}})};Da.prototype.mul=function(e){return this.complex_op("mul",e,function(e,t,r,n){var i={re:e.mul(t).sub(r.mul(n)),im:e.mul(n).add(t.mul(r))};return i})};Da.prototype.complex_op=function(e,t,i){var u=this;var r=function e(t,r){var n=i(u.__re__,t,u.__im__,r);if("im"in n&&"re"in n){if(n.im.cmp(0)===0&&!da.isFloat(n.im)){return n.re}return Da(n,true)}return n};if(typeof t==="undefined"){return r()}if(da.isNumber(t)&&!da.isComplex(t)){if(!(t instanceof da)){t=da(t)}var n=t.asType(0);t={__im__:n,__re__:t}}else if(!da.isComplex(t)){throw new Error("[LComplex::".concat(e,"] Invalid value"))}var a=t.__re__ instanceof da?t.__re__:this.__re__.asType(t.__re__);var o=t.__im__ instanceof da?t.__im__:this.__im__.asType(t.__im__);return r(a,o)};Da._op={"+":"add","-":"sub","*":"mul","/":"div"};Da.prototype._op=function(e,t){var r=Da._op[e];return this[r](t)};Da.prototype.cmp=function(e){var t=this.coerce(e),r=A(t,2),n=r[0],i=r[1];var u=n.__re__.coerce(i.__re__),a=A(u,2),o=a[0],s=a[1];var c=o.cmp(s);if(c!==0){return c}else{var f=n.__im__.coerce(i.__im__),l=A(f,2),h=l[0],p=l[1];return h.cmp(p)}};Da.prototype.valueOf=function(){return[this.__re__,this.__im__].map(function(e){return e.valueOf()})};Da.prototype.toString=function(){var e;if(this.__re__.cmp(0)!==0){e=[Zi(this.__re__)]}else{e=[]}var t=this.__im__.valueOf();var r=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY].includes(t);var n=Zi(this.__im__);if(!r&&!Number.isNaN(t)){var i=this.__im__.cmp(0);if(i<0||i===0&&this.__im__._minus){e.push("-")}else{e.push("+")}n=n.replace(/^-/,"")}e.push(n);e.push("i");return e.join("")};function Ea(e){if(typeof this!=="undefined"&&!(this instanceof Ea)||typeof this==="undefined"){return new Ea(e)}if(!da.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof da){return Ea(e.valueOf())}if(typeof e==="number"){if(Object.is(e,-0)){Object.defineProperty(this,"_minus",{value:true})}this.constant(e,"float")}}Ea.prototype=Object.create(da.prototype);Ea.prototype.constructor=Ea;Ea.prototype.toString=function(){if(this.__value__===Number.NEGATIVE_INFINITY){return"-inf.0"}if(this.__value__===Number.POSITIVE_INFINITY){return"+inf.0"}if(Number.isNaN(this.__value__)){return"+nan.0"}var e=this.__value__.toString();if(!da.isFloat(this.__value__)&&!e.match(/e/i)){var t=e+".0";return this._minus?"-"+t:t}return e.replace(/^([0-9]+)e/,"$1.0e")};Ea.prototype._op=function(e,t){if(t instanceof da){t=t.__value__}var r=da._ops[e];if(e==="/"&&this.__value__===0&&t===0){return NaN}return Ea(r(this.__value__,t))};Ea.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){return Aa(this.__value__.valueOf())}return Fa(e.valueOf())(this.__value__.valueOf())};Ea.prototype.sqrt=function(){var e=this.valueOf();if(this.cmp(0)<0){var t=Ea(Math.sqrt(-e));return Da({re:0,im:t})}return Ea(Math.sqrt(e))};Ea.prototype.abs=function(){var e=this.valueOf();if(e<0){e=-e}return Ea(e)};var Aa=Fa(1e-10);function Fa(n){return function(e){var t=function e(n,t,r){var i=function e(t,r){return r0){i=Ca(n,r)}else if(n.cmp(r)<=0){i=r}else if(r.cmp(0)>0){i=Ca(r,n)}else if(t.cmp(0)<0){i=da(Ca(n.sub(),r.sub())).sub()}else{i=da(0)}if(da.isFloat(t)||da.isFloat(e)){return Ea(i)}return i}function Ca(e,t){var r=da(e).floor();var n=da(t).floor();if(e.cmp(r)<1){return r}else if(r.cmp(n)===0){var i=da(1).div(t.sub(n));var u=da(1).div(e.sub(r));return r.add(da(1).div(Ca(i,u)))}else{return r.add(da(1))}}function ka(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof ka)||typeof this==="undefined"){return new ka(e,t)}if(!da.isRational(e)){throw new Error("Invalid constructor call for LRational")}var r,n;if(e instanceof ka){r=da(e.__num__);n=da(e.__denom__)}else{r=da(e.num);n=da(e.denom)}if(!t&&n.cmp(0)!==0){var i=r.op("%",n).cmp(0)===0;if(i){return da(r.div(n))}}this.constant(r,n)}ka.prototype=Object.create(da.prototype);ka.prototype.constructor=ka;ka.prototype.constant=function(e,t){Object.defineProperty(this,"__num__",{value:e,enumerable:true});Object.defineProperty(this,"__denom__",{value:t,enumerable:true});Object.defineProperty(this,"__type__",{value:"rational",enumerable:true})};ka.prototype.serialize=function(){return{num:this.__num__,denom:this.__denom__}};ka.prototype.pow=function(e){var t=e.cmp(0);if(t===0){return da(1)}if(t===-1){e=e.sub();var r=this.__denom__.pow(e);var n=this.__num__.pow(e);return ka({num:r,denom:n})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};ka.prototype.sqrt=function(){var e=this.__num__.sqrt();var t=this.__denom__.sqrt();if(e instanceof Ea||t instanceof Ea){return e.div(t)}return ka({num:e,denom:t})};ka.prototype.abs=function(){var e=this.__num__;var t=this.__denom__;if(e.cmp(0)===-1){e=e.sub()}if(t.cmp(0)!==1){t=t.sub()}return ka({num:e,denom:t})};ka.prototype.cmp=function(e){return da(this.valueOf(),true).cmp(e)};ka.prototype.toString=function(){var e=this.__num__.gcd(this.__denom__);var t,r;if(e.cmp(1)!==0){t=this.__num__.div(e);if(t instanceof ka){t=da(t.valueOf(true))}r=this.__denom__.div(e);if(r instanceof ka){r=da(r.valueOf(true))}}else{t=this.__num__;r=this.__denom__}var n=this.cmp(0)<0;if(n){if(t.abs().cmp(r.abs())===0){return t.toString()}}else if(t.cmp(r)===0){return t.toString()}return t.toString()+"/"+r.toString()};ka.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 da._ops["/"](this.__num__.value,this.__denom__.value)}return Ea(this.__num__.valueOf()).div(this.__denom__.valueOf())};ka.prototype.mul=function(e){if(!(e instanceof da)){e=da(e)}if(da.isRational(e)){var t=this.__num__.mul(e.__num__);var r=this.__denom__.mul(e.__denom__);return ka({num:t,denom:r})}var n=da.coerce(this,e),i=A(n,2),u=i[0],a=i[1];return u.mul(a)};ka.prototype.div=function(e){if(!(e instanceof da)){e=da(e)}if(da.isRational(e)){var t=this.__num__.mul(e.__denom__);var r=this.__denom__.mul(e.__num__);return ka({num:t,denom:r})}var n=da.coerce(this,e),i=A(n,2),u=i[0],a=i[1];var o=u.div(a);return o};ka.prototype._op=function(e,t){return this[ga[e]](t)};ka.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof da)){e=da(e)}if(da.isRational(e)){var t=e.__num__.sub();var r=e.__denom__;return this.add(ka({num:t,denom:r}))}if(!(e instanceof da)){e=da(e).sub()}else{e=e.sub()}var n=da.coerce(this,e),i=A(n,2),u=i[0],a=i[1];return u.add(a)};ka.prototype.add=function(e){if(!(e instanceof da)){e=da(e)}if(da.isRational(e)){var t=this.__denom__;var r=e.__denom__;var n=this.__num__;var i=e.__num__;var u,a;if(t!==r){a=r.mul(n).add(i.mul(t));u=t.mul(r)}else{a=n.add(i);u=t}return ka({num:a,denom:u})}if(da.isFloat(e)){return Ea(this.valueOf()).add(e)}var o=da.coerce(this,e),s=A(o,2),c=s[0],f=s[1];return c.add(f)};function Oa(e,t){if(typeof this!=="undefined"&&!(this instanceof Oa)||typeof this==="undefined"){return new Oa(e,t)}if(e instanceof Oa){return Oa(e.__value__,e._native)}if(!da.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.constant(e,"bigint");Object.defineProperty(this,"_native",{value:t})}Oa.prototype=Object.create(da.prototype);Oa.prototype.constructor=Oa;Oa.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};Oa.prototype.serialize=function(){return this.__value__.toString()};Oa.prototype._op=function(e,t){if(typeof t==="undefined"){if(da.isBN(this.__value__)){e=Oa.bn_op[e];return Oa(this.__value__.clone()[e](),false)}return Oa(da._ops[e](this.__value__),true)}if(da.isBN(this.__value__)&&da.isBN(t.__value__)){e=Oa.bn_op[e];return Oa(this.__value__.clone()[e](t),false)}var r=da._ops[e](this.__value__,t.__value__);if(e==="/"){var n=this.op("%",t).cmp(0)===0;if(n){return da(r)}return ka({num:this,denom:t})}return Oa(r,true)};Oa.prototype.sqrt=function(){var e;var t=this.cmp(0)<0;if(da.isNative(this.__value__)){e=da(Math.sqrt(t?-this.valueOf():this.valueOf()))}else if(da.isBN(this.__value__)){e=t?this.__value__.neg().sqrt():this.__value__.sqrt()}if(t){return Da({re:0,im:e})}return e};da.NaN=da(NaN);function Sa(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof Sa)||typeof this==="undefined"){return new Sa(e)}yo("InputPort",e,"function");ai(this,"__type__",Ya);var i;Object.defineProperty(this,"__parser__",{enumerable:true,get:function e(){return i},set:function e(t){yo("InputPort::__parser__",t,"parser");i=t}});this._read=e;this._with_parser=this._with_init_parser.bind(this,O(j.mark(function e(){var r;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(n.char_ready()){t.next=5;break}t.next=3;return n._read();case 3:r=t.sent;i=new Xn(r,{env:n});case 5:return t.abrupt("return",n.__parser__);case 6:case"end":return t.stop()}}},e)})));this.char_ready=function(){return!!this.__parser__&&this.__parser__.__lexer__.peek()!==$a};this._make_defaults()}Sa.prototype._make_defaults=function(){this.read=this._with_parser(function(e){return e.read_object()});this.read_line=this._with_parser(function(e){return e.__lexer__.read_line()});this.read_char=this._with_parser(function(e){return e.__lexer__.read_char()});this.read_string=this._with_parser(function(e,t){if(!da.isInteger(t)){var r=da.getType(t);_o("read-string",r,"integer")}return e.__lexer__.read_string(t.valueOf())});this.peek_char=this._with_parser(function(e){return e.__lexer__.peek_char()})};Sa.prototype._with_init_parser=function(o,s){var c=this;return function(){var e=O(j.mark(function e(){var r,n,i,u,a=arguments;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:t.next=2;return o.call(c);case 2:r=t.sent;for(n=a.length,i=new Array(n),u=0;u"};function Ba(e){if(typeof this!=="undefined"&&!(this instanceof Ba)||typeof this==="undefined"){return new Ba(e)}yo("OutputPort",e,"function");ai(this,"__type__",Ya);this.write=e}Ba.prototype.is_open=function(){return this._closed!==true};Ba.prototype.close=function(){Object.defineProperty(this,"_closed",{get:function e(){return true},set:function e(){},configurable:false,enumerable:false});this.write=function(){throw new Error("output-port: port is closed")}};Ba.prototype.flush=function(){};Ba.prototype.toString=function(){return"#"};var ja=function(e){u(n,e);var r=Fr(n);function n(e){var t;y(this,n);t=r.call(this,function(){var e;return(e=t)._write.apply(e,arguments)});yo("BufferedOutputPort",e,"function");ai(i(t),"_fn",e,{hidden:true});ai(i(t),"_buffer",[],{hidden:true});return t}b(n,[{key:"flush",value:function e(){if(this._buffer.length){this._fn(this._buffer.join(""));this._buffer.length=0}}},{key:"_write",value:function e(){var t=this;for(var r=arguments.length,n=new Array(r),i=0;i"};Ia.prototype.valueOf=function(){return this.__buffer__.map(function(e){return e.valueOf()}).join("")};function Pa(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof Pa)||typeof this==="undefined"){return new Pa(e,t)}yo("OutputFilePort",e,"string");ai(this,"__filename__",e);ai(this,"_fd",t.valueOf(),{hidden:true});ai(this,"__type__",Ya);this.write=function(e){if(!sa.isString(e)){e=Zi(e)}else{e=e.valueOf()}r.fs().write(r._fd,e,function(e){if(e){throw e}})}}Pa.prototype=Object.create(Ba.prototype);Pa.prototype.constructor=Pa;Pa.prototype.fs=function(){if(!this._fs){this._fs=this.internal("fs")}return this._fs};Pa.prototype.internal=function(e){return uo.get("**internal-env**").get(e)};Pa.prototype.close=function(){var n=this;return new Promise(function(t,r){n.fs().close(n._fd,function(e){if(e){r(e)}else{ai(n,"_fd",null,{hidden:true});Ba.prototype.close.call(n);t()}})})};Pa.prototype.toString=function(){return"#")};function Na(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof Na)||typeof this==="undefined"){return new Na(e)}yo("InputStringPort",e,"string");t=t||io;e=e.valueOf();this._with_parser=this._with_init_parser.bind(this,function(){if(!r.__parser__){r.__parser__=new Xn(e,{env:t})}return r.__parser__});ai(this,"__type__",Ya);this._make_defaults()}Na.prototype.char_ready=function(){return true};Na.prototype=Object.create(Sa.prototype);Na.prototype.constructor=Na;Na.prototype.toString=function(){return"#"};function Ra(e){if(typeof this!=="undefined"&&!(this instanceof Ra)||typeof this==="undefined"){return new Ra(e)}yo("InputByteVectorPort",e,"uint8array");ai(this,"__vector__",e);ai(this,"__type__",Ma);var r=0;Object.defineProperty(this,"__index__",{enumerable:true,get:function e(){return r},set:function e(t){yo("InputByteVectorPort::__index__",t,"number");if(t instanceof da){t=t.valueOf()}if(typeof t==="bigint"){t=Number(t)}if(Math.floor(t)!==t){throw new Error("InputByteVectorPort::__index__ value is "+"not integer")}r=t}})}Ra.prototype=Object.create(Sa.prototype);Ra.prototype.constructor=Ra;Ra.prototype.toString=function(){return"#"};Ra.prototype.close=function(){var t=this;ai(this,"__vector__",Pi);["read_u8","close","peek_u8","read_u8_vector"].forEach(function(e){t[e]=function(){throw new Error("Input-binary-port: port is closed")}});this.char_ready=function(){return false}};Ra.prototype.u8_ready=function(){return true};Ra.prototype.peek_u8=function(){if(this.__index__>=this.__vector__.length){return $a}return this.__vector__[this.__index__]};Ra.prototype.skip=function(){if(this.__index__<=this.__vector__.length){++this.__index__}};Ra.prototype.read_u8=function(){var e=this.peek_u8();this.skip();return e};Ra.prototype.read_u8_vector=function(e){if(typeof e==="undefined"){e=this.__vector__.length}else if(e>this.__index__+this.__vector__.length){e=this.__index__+this.__vector__.length}if(this.peek_u8()===$a){return $a}return this.__vector__.slice(this.__index__,e)};function Ta(){if(typeof this!=="undefined"&&!(this instanceof Ta)||typeof this==="undefined"){return new Ta}ai(this,"__type__",Ma);ai(this,"_buffer",[],{hidden:true});this.write=function(e){yo("write",e,["number","uint8array"]);if(da.isNumber(e)){this._buffer.push(e.valueOf())}else{var t;(t=this._buffer).push.apply(t,k(Array.from(e)))}};Object.defineProperty(this,"__buffer__",{enumerable:true,get:function e(){return Uint8Array.from(this._buffer)}})}Ta.prototype=Object.create(Ba.prototype);Ta.prototype.constructor=Ta;Ta.prototype.close=function(){Ba.prototype.close.call(this);ai(this,"_buffer",null,{hidden:true})};Ta.prototype._close_guard=function(){if(this._closed){throw new Error("output-port: binary port is closed")}};Ta.prototype.write_u8=function(e){yo("OutputByteVectorPort::write_u8",e,"number");this.write(e)};Ta.prototype.write_u8_vector=function(e){yo("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};Ta.prototype.toString=function(){return"#"};Ta.prototype.valueOf=function(){return this.__buffer__};function La(e,t){if(typeof this!=="undefined"&&!(this instanceof La)||typeof this==="undefined"){return new La(e,t)}Na.call(this,e);yo("InputFilePort",t,"string");ai(this,"__filename__",t)}La.prototype=Object.create(Na.prototype);La.prototype.constructor=La;La.prototype.toString=function(){return"#")};function Ua(e,t){if(typeof this!=="undefined"&&!(this instanceof Ua)||typeof this==="undefined"){return new Ua(e,t)}Ra.call(this,e);yo("InputBinaryFilePort",t,"string");ai(this,"__filename__",t)}Ua.prototype=Object.create(Ra.prototype);Ua.prototype.constructor=Ua;Ua.prototype.toString=function(){return"#")};function qa(e,t){if(typeof this!=="undefined"&&!(this instanceof qa)||typeof this==="undefined"){return new qa(e,t)}yo("OutputBinaryFilePort",e,"string");ai(this,"__filename__",e);ai(this,"_fd",t.valueOf(),{hidden:true});ai(this,"__type__",Ma);var u,r;this.write=function(e){var n=this;yo("write",e,["number","uint8array"]);var i;if(!u){u=this.internal("fs")}if(!r){r=this.internal("Buffer")}if(da.isNumber(e)){i=r.from([e.valueOf()])}else{i=r.from(Array.from(e))}return new Promise(function(t,r){u.write(n._fd,i,function(e){if(e){r(e)}else{t()}})})}}qa.prototype=Object.create(Pa.prototype);qa.prototype.constructor=qa;qa.prototype.write_u8=function(e){yo("OutputByteVectorPort::write_u8",e,"number");this.write(e)};qa.prototype.write_u8_vector=function(e){yo("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};var Ma=Symbol["for"]("binary");var Ya=Symbol["for"]("text");var $a=new za;function za(){}za.prototype.toString=function(){return"#"};function Va(e){var t=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=r.stderr,i=r.stdin,u=r.stdout,a=r.command_line,o=a===void 0?null:a,s=D(r,Ar);if(typeof this!=="undefined"&&!(this instanceof Va)||typeof this==="undefined"){return new Va(e,Br({stdin:i,stdout:u,stderr:n,command_line:o},s))}if(typeof e==="undefined"){e="anonymous"}this.__env__=uo.inherit(e,s);this.__env__.set("parent.frame",ci("parent.frame",function(){return t.__env__},io.__env__["parent.frame"].__doc__));var c="**interaction-environment-defaults**";this.set(c,Ji(s).concat(c));var f=to.inherit("internal-".concat(e));if(Su(i)){f.set("stdin",i)}if(Su(n)){f.set("stderr",n)}if(Su(u)){f.set("stdout",u)}f.set("command-line",o);ao(this.__env__,f)}Va.prototype.exec=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;yo("Interpreter::exec",e,["string","array"],1);yo("Interpreter::exec",t,"boolean",2);io.set("**interaction-environment**",this.__env__);if(r===null){r=this.__env__}return No(e,r,t?r:false)};Va.prototype.get=function(e){var t=this.__env__.get(e);if(vu(t)){return t.bind(this.__env__)}return t};Va.prototype.set=function(e,t){return this.__env__.set(e,t)};Va.prototype.constant=function(e,t){return this.__env__.constant(e,t)};function Ja(e,t){this.name="LipsError";this.message=e;this.args=t;this.stack=(new Error).stack}Ja.prototype=new Error;Ja.prototype.constructor=Ja;function Ga(e,t,r){if(arguments.length===1){if(_(arguments[0])==="object"){e=arguments[0];t=null}else if(typeof arguments[0]==="string"){e={};t=null;r=arguments[0]}}this.__docs__=new Map;this.__env__=e;this.__parent__=t;this.__name__=r||"anonymous"}Ga.prototype.list=function(){return Ji(this.__env__)};Ga.prototype.fs=function(){return this.get("**fs**")};Ga.prototype.unset=function(e){if(e instanceof Ln){e=e.valueOf()}if(e instanceof sa){e=e.valueOf()}delete this.__env__[e]};Ga.prototype.inherit=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(_(e)==="object"){t=e}if(!e||_(e)==="object"){e="child of "+(this.__name__||"unknown")}return new Ga(t||{},this,e)};Ga.prototype.doc=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(e instanceof Ln){e=e.__name__}if(e instanceof sa){e=e.valueOf()}if(t){if(!r){t=fi(t)}this.__docs__.set(e,t);return this}if(this.__docs__.has(e)){return this.__docs__.get(e)}if(this.__parent__){return this.__parent__.doc(e)}};Ga.prototype.newFrame=function(e,t){var n=this.inherit("__frame__");n.set("parent.frame",ci("parent.frame",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;e=e.valueOf();var t=n.__parent__;if(!(t instanceof Ga)){return Pi}if(e<=0){return t}var r=t.get("parent.frame");return r(e-1)},io.__env__["parent.frame"].__doc__));t.callee=e;n.set("arguments",t);return n};Ga.prototype._lookup=function(e){if(e instanceof Ln){e=e.__name__}if(e instanceof sa){e=e.valueOf()}if(this.__env__.hasOwnProperty(e)){return Ha(this.__env__[e])}if(this.__parent__){return this.__parent__._lookup(e)}};Ga.prototype.toString=function(){return"#"};Ga.prototype.clone=function(){var t=this;var r={};Object.keys(this.__env__).forEach(function(e){r[e]=t.__env__[e]});return new Ga(r,this.__parent__,this.__name__)};Ga.prototype.merge=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"merge";yo("Environment::merge",e,"environment");return this.inherit(t,e.__env__)};function Ha(e){if(typeof this!=="undefined"&&!(this instanceof Ha)||typeof this==="undefined"){return new Ha(e)}this.value=e}Ha.isUndefined=function(e){return e instanceof Ha&&typeof e.value==="undefined"};Ha.prototype.valueOf=function(){return this.value};function Wa(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof Wa)||typeof this==="undefined"){return new Wa(e)}this.__values__=e}Wa.prototype.toString=function(){return this.__values__.map(function(e){return Zi(e)}).join("\n")};Wa.prototype.valueOf=function(){return this.__values__};Ga.prototype.get=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};yo("Environment::get",e,["symbol","string"]);var r=t.throwError,n=r===void 0?true:r;var i=e;if(i instanceof Ln||i instanceof sa){i=i.valueOf()}var u=this._lookup(i);if(u instanceof Ha){if(Ha.isUndefined(u)){return undefined}return Au(u.valueOf())}var a;if(e instanceof Ln&&e[Ln.object]){a=e[Ln.object]}else if(typeof i==="string"){a=i.split(".").filter(Boolean)}if(a&&a.length>0){var o=a,s=h(o),c=s[0],f=s.slice(1);u=this._lookup(c);if(f.length){try{if(u instanceof Ha){u=u.valueOf()}else{u=Ka(jr,c);if(vu(u)){u=Fu(u)}}if(typeof u!=="undefined"){return Ka.apply(void 0,[u].concat(k(f)))}}catch(e){throw e}}else if(u instanceof Ha){return Au(u.valueOf())}u=Ka(jr,i)}if(typeof u!=="undefined"){return u}if(n){throw new Error("Unbound variable `"+i.toString()+"'")}};Ga.prototype.set=function(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;yo("Environment::set",e,["string","symbol"]);if(da.isNumber(t)){t=da(t)}if(e instanceof Ln){e=e.__name__}if(e instanceof sa){e=e.valueOf()}this.__env__[e]=t;if(r){this.doc(e,r,true)}return this};Ga.prototype.constant=function(t,e){var r=this;if(this.__env__.hasOwnProperty(t)){throw new Error("Environment::constant: ".concat(t," already exists"))}if(arguments.length===1&&Li(arguments[0])){var n=arguments[0];Object.keys(n).forEach(function(e){r.constant(t,n[e])})}else{Object.defineProperty(this.__env__,t,{value:e,enumerable:true})}return this};Ga.prototype.has=function(e){return this.__env__.hasOwnProperty(e)};Ga.prototype.ref=function(e){var t=this;while(true){if(!t){break}if(t.has(e)){return t}t=t.__parent__}};Ga.prototype.parents=function(){var e=this;var t=[];while(e){t.unshift(e);e=e.__parent__}return t};function Qa(e){if(gu(e)){return e.then(Qa)}if(e instanceof Ni||e instanceof Ln){e[Pu]=true}return e}var Za=ti(Nn('(lambda ()\n "[native code]"\n (throw "Invalid Invocation"))'))[0];var Ka=ci("get",function e(t){var r;for(var n=arguments.length,i=new Array(n>1?n-1:0),u=1;u0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=Xa(this,"stdin")}mo("peek-char",e,"input-port");return e.peek_char()},"(peek-char port)\n\n Function get character from string port or EOF object if no more\n data in string port."),"read-line":ci("read-line",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=Xa(this,"stdin")}mo("read-line",e,"input-port");return e.read_line()},"(read-char port)\n\n Function read next character from input port."),"read-char":ci("read-char",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=Xa(this,"stdin")}mo("read-char",e,"input-port");return e.read_char()},"(read-char port)\n\n Function read next character from input port."),read:ci("read",function(){var e=O(j.mark(function e(){var r,n,i,u,a,o,s,c,f=arguments;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:r=f.length>0&&f[0]!==undefined?f[0]:null;if(!sa.isString(r)){t.next=30;break}n=false;i=false;t.prev=4;a=F(ti(r,this));case 6:t.next=8;return a.next();case 8:if(!(n=!(o=t.sent).done)){t.next=14;break}s=o.value;return t.abrupt("return",s);case 11:n=false;t.next=6;break;case 14:t.next=20;break;case 16:t.prev=16;t.t0=t["catch"](4);i=true;u=t.t0;case 20:t.prev=20;t.prev=21;if(!(n&&a["return"]!=null)){t.next=25;break}t.next=25;return a["return"]();case 25:t.prev=25;if(!i){t.next=28;break}throw u;case 28:return t.finish(25);case 29:return t.finish(20);case 30:if(r===null){c=Xa(this,"stdin")}else{c=r}mo("read",c,"input-port");return t.abrupt("return",c.read.call(this));case 33:case"end":return t.stop()}}},e,this,[[4,16,20,30],[21,,25,29]])}));function t(){return e.apply(this,arguments)}return t}(),"(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:ci("pprint",function e(t){if(t instanceof Ni){t=new ps.Formatter(t.toString(true))["break"]().format();io.get("display").call(io,t)}else{io.get("write").call(io,t)}io.get("newline").call(io)},"(pprint expression)\n\n Pretty print list expression, if called with non-pair it just call\n print function with passed argument."),print:ci("print",function e(){var t=io.get("display");var r=io.get("newline");for(var n=arguments.length,i=new Array(n),u=0;u1?r-1:0),i=1;in.length){throw new Error("Not enough arguments")}var o=0;var s=io.get("repr");t=t.replace(u,function(e){var t=e[1];if(t==="~"){return"~"}else if(t==="%"){return"\n"}else{var r=n[o++];if(t==="a"){return s(r)}else{return s(r,true)}}});a=t.match(/~([\S])/);if(a){throw new Error("format: Unrecognized escape seqence ".concat(a[1]))}return t},"(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:ci("display",function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(r===null){r=Xa(this,"stdout")}else{yo("display",r,"output-port")}var n=io.get("repr")(t);r.write.call(io,n)},"(display arg [port])\n\n Function send string to standard output or provied port."),"display-error":ci("display-error",function e(){var t=Xa(this,"stderr");var r=io.get("repr");for(var n=arguments.length,i=new Array(n),u=0;u1&&arguments[1]!==undefined?arguments[1]:{},r=t.dynamic_scope,n=t.error;if(r){r=this}var i=this;var a;var o=Io(e.cdr.car,{env:this,dynamic_scope:r,error:n});o=Fo(o);function s(t,r,n){if(gu(t)){return t.then(function(e){return s(t,e,n)})}if(gu(r)){return r.then(function(e){return s(t,e,n)})}if(gu(n)){return n.then(function(e){return s(t,r,e)})}i.get("set-obj!").call(i,t,r,n);return n}if(e.car instanceof Ni&&Ln.is(e.car.car,".")){var c=e.car.cdr.car;var f=e.car.cdr.cdr.car;var l=Io(c,{env:this,dynamic_scope:r,error:n});var h=Io(f,{env:this,dynamic_scope:r,error:n});return s(l,h,o)}if(!(e.car instanceof Ln)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var p=e.car.valueOf();a=this.ref(e.car.__name__);return ni(o,function(e){if(!a){var t=p.split(".");if(t.length>1){var r=t.pop();var n=t.join(".");var i=u.get(n,{throwError:false});if(i){s(i,r,e);return}}throw new Error("Unbound variable `"+p+"'")}a.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!":ci(new au("set!",function(e){if(!(e.car instanceof Ln)){throw new Error("unset! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var t=e.car;var r=this.ref(t);if(r){delete r.__env__[t.__name__]}}),"(unset! name)\n\n Function delete specified name from environment."),"set-car!":ci("set-car!",function(e,t){yo("set-car!",e,"pair");e.car=t},"(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!":ci("set-cdr!",function(e,t){yo("set-cdr!",e,"pair");e.cdr=t},"(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?":ci("empty?",function(e){return typeof e==="undefined"||e===Pi},"(empty? object)\n\n Function return true if value is undfined empty list."),gensym:ci("gensym",Mn,"(gensym)\n\n Function generate unique symbol, to use with macros as meta name."),load:ci("load",function e(o,t){yo("load",o,"string");var s=this;if(s.__name__==="__frame__"){s=s.__parent__}if(!(t instanceof Ga)){if(s===io){t=s}else{t=this.get("**interaction-environment**")}}var c="**module-path**";var f=io.get(c,{throwError:false});o=o.valueOf();if(!o.match(/.[^.]+$/)){o+=".scm"}var r=o.match(/\.xcb$/);function l(e){if(r){e=ss(e)}else{if(Ao(e)==="buffer"){e=e.toString()}e=e.replace(/^#!.*/,"");if(e.match(/^\{/)){e=ts(e)}}return No(e,t)}function n(e){return jr.fetch(e).then(function(e){return r?e.arrayBuffer():e.text()}).then(function(e){if(r){e=new Uint8Array(e)}return e})}if(lo()){return new Promise(function(){var r=O(j.mark(function e(r,n){var i,u,a;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:i=Tr("path");if(!f){t.next=6;break}f=f.valueOf();o=i.join(f,o);t.next=12;break;case 6:u=s.get("command-line",{throwError:false});if(!u){t.next=11;break}t.next=10;return u();case 10:a=t.sent;case 11:if(a&&a!==Pi){process.cwd();o=i.join(i.dirname(a.car.valueOf()),o)}case 12:io.set(c,i.dirname(o));Tr("fs").readFile(o,function(e,t){if(e){n(e);io.set(c,f)}else{try{l(t).then(function(){r();io.set(c,f)})["catch"](n)}catch(e){n(e)}}});case 14:case"end":return t.stop()}}},e)}));return function(e,t){return r.apply(this,arguments)}}())}if(f){f=f.valueOf();o=f+"/"+o.replace(/^\.?\/?/,"")}return n(o).then(function(e){io.set(c,o.replace(/\/[^/]*$/,""));return l(e)}).then(function(){})["finally"](function(){io.set(c,f)})},"(load filename)\n (load filename environment)\n\n Function fetch the file and evaluate its content as LIPS code,\n If second argument is provided and it's environment the evaluation\n will happen in that environment."),do:ci(new au("do",function(){var r=O(j.mark(function e(r,n){var i,u,a,o,s,c,f,l,h,p,_;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:i=n.dynamic_scope,u=n.error;a=this;if(i){i=a}o=a.inherit("do");s=r.car;c=r.cdr.car;f=r.cdr.cdr;if(f!==Pi){f=new Ni(Ln("begin"),f)}l={env:a,dynamic_scope:i,error:u};h=s;case 10:if(!(h!==Pi)){t.next=21;break}p=h.car;t.t0=o;t.t1=p.car;t.next=16;return Io(p.cdr.car,l);case 16:t.t2=t.sent;t.t0.set.call(t.t0,t.t1,t.t2);h=h.cdr;t.next=10;break;case 21:l={env:o,dynamic_scope:i,error:u};_=j.mark(function e(){var r,n,i,u,a;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(!(f!==Pi)){t.next=3;break}t.next=3;return ps.evaluate(f,l);case 3:r=s;n={};case 5:if(!(r!==Pi)){t.next=15;break}i=r.car;if(!(i.cdr.cdr!==Pi)){t.next=12;break}t.next=10;return Io(i.cdr.cdr.car,l);case 10:u=t.sent;n[i.car.valueOf()]=u;case 12:r=r.cdr;t.next=5;break;case 15:a=Object.getOwnPropertySymbols(n);Object.keys(n).concat(a).forEach(function(e){o.set(e,n[e])});case 17:case"end":return t.stop()}}},e)});case 23:t.next=25;return Io(c.car,l);case 25:t.t3=t.sent;if(!(t.t3===false)){t.next=30;break}return t.delegateYield(_(),"t4",28);case 28:t.next=23;break;case 30:if(!(c.cdr!==Pi)){t.next=34;break}t.next=33;return Io(c.cdr.car,l);case 33:return t.abrupt("return",t.sent);case 34:case"end":return t.stop()}}},e,this)}));return function(e,t){return r.apply(this,arguments)}}()),"(do (( )) (test expression) . body)\n\n Iteration macro that evaluate the expression body in scope of the variables.\n On Eeach loop it increase the variables according to next expression and run\n test to check if the loop should continue. If test is signle call the macro\n will not return anything. If the test is pair of expression and value the\n macro will return that value after finish."),if:ci(new au("if",function(r,e){var n=e.dynamic_scope,i=e.error;if(n){n=this}var u=this;var t=function e(t){if(t===false){return Io(r.cdr.cdr.car,{env:u,dynamic_scope:n,error:i})}else{return Io(r.cdr.car,{env:u,dynamic_scope:n,error:i})}};if(r===Pi){throw new Error("too few expressions for `if`")}var a=Io(r.car,{env:u,dynamic_scope:n,error:i});return ni(a,t)}),"(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 au("let-env",function(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=e.dynamic_scope,n=e.error;yo("let-env",t,"pair");var i=Io(t.car,{env:this,dynamic_scope:r,error:n});return ni(i,function(e){yo("let-env",e,"environment");return Io(Ni(Ln("begin"),t.cdr),{env:e,dynamic_scope:r,error:n})})},"(let-env env . body)\n\n Special macro that evaluate body in context of given environment\n object."),letrec:ci(Wu(Symbol["for"]("letrec")),"(letrec ((a value-a) (b value-b)) body)\n\n Macro that creates new environment, then evaluate and assign values to\n names and then evaluate the body in context of that environment.\n Values are evaluated sequentialy and next value can access to\n previous values/names."),"letrec*":ci(Wu(Symbol["for"]("letrec")),"(letrec* ((a value-a) (b value-b)) body)\n\n Same as letrec but the order of execution of the binding is guaranteed,\n so use can use recursive code as well as reference previous binding.\n In LIPS both letrec and letrec* behave the same."),"let*":ci(Wu(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:ci(Wu(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*":ci(Qu("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:ci(new au("begin",function(e,t){var n=Object.assign({},t);var i=io.get("list->array")(e);if(n.dynamic_scope){n.dynamic_scope=this}n.env=this;var u;return function t(){if(i.length){var e=i.shift();var r=Io(e,n);return ni(r,function(e){u=e;return t()})}else{return u}}()}),"(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 au("ignore",function(e,t){var r=t.dynamic_scope,n=t.error;var i={env:this,error:n};if(r){i.dynamic_scope=this}Io(new Ni(new Ln("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."),"call/cc":ci(au.defmacro("call/cc",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=Br({env:this},t);return ni(Io(e.car,r),function(e){if(vu(e)){return e(new Bo(null))}})}),"(call/cc proc)\n\n TODO"),define:ci(au.defmacro("define",function(r,e){var n=this;if(r.car instanceof Ni&&r.car.car instanceof Ln){var t=new Ni(new Ln("define"),new Ni(r.car.car,new Ni(new Ni(new Ln("lambda"),new Ni(r.car.cdr,r.cdr)))));return t}else if(e.macro_expand){return}if(e.dynamic_scope){e.dynamic_scope=this}e.env=n;var i=r.cdr.car;var u;if(i instanceof Ni){i=Io(i,e);u=true}else if(i instanceof Ln){i=n.get(i)}yo("define",r.car,"symbol");return ni(i,function(e){if(n.__name__===fu.__merge_env__){n=n.__parent__}if(u&&(vu(e)&&Vu(e)||e instanceof fu)){e.__name__=r.car.valueOf();if(e.__name__ instanceof sa){e.__name__=e.__name__.valueOf()}}var t;if(r.cdr.cdr instanceof Ni&&sa.isString(r.cdr.cdr.car)){t=r.cdr.cdr.car.valueOf()}n.set(r.car,e,t,true)})}),'(define name expression)\n (define name expression "doc string")\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!":ci("set-obj!",function(e,t,r){var n=_(e);if(du(e)||n!=="object"&&n!=="function"){var i=_o("set-obj!",Ao(e),["object","function"]);throw new Error(i)}yo("set-obj!",t,["string","symbol","number"]);e=Fu(e);t=t.valueOf();if(arguments.length===2){delete e[t]}else if(Ki(e)&&vu(r)){e[t]=Fu(r);e[t][Uu]=true}else if(vu(r)||bo(r)||r===Pi){e[t]=r}else{e[t]=r&&!Ki(r)?r.valueOf():r}},"(set-obj! obj key value)\n\n Function set property of JavaScript object"),"null-environment":ci("null-environment",function(){return io.inherit("null")},"(null-environment)\n\n Function return new base environment with std lib."),values:ci("values",function e(){for(var t=arguments.length,r=new Array(t),n=0;n1&&arguments[1]!==undefined?arguments[1]:{},h=e.dynamic_scope,p=e.error;var _=this;var d;if(l.cdr instanceof Ni&&sa.isString(l.cdr.car)&&l.cdr.cdr!==Pi){d=l.cdr.car.valueOf()}function v(){var e;if(h){if(!(this instanceof Ga)){e=_}else{e=this}}else{e=_}e=e.inherit("lambda");var t=l.car;var r=0;var n;if(typeof this!=="undefined"&&!(this instanceof Ga)){if(this&&!this.__instance__){Object.defineProperty(this,"__instance__",{enumerable:false,get:function e(){return true},set:function e(){},configurable:false})}e.set("this",this)}for(var i=arguments.length,u=new Array(i),a=0;a>> "+_.toString());if(_){l=_}var d=i.merge(n,fu.__merge_env__);if(r){return{expr:l,scope:d}}var v=Io(l,Br(Br({},a),{},{env:d}));return pu(v,p)}s=s.cdr}}catch(e){e.message+=" in macro: ".concat(m.toString(true));throw e}throw new Error("Invalid Syntax ".concat(e.toString(true)))},b);r.__code__=m;return r},"(syntax-rules () (pattern expression) ...)\n\n Base of Hygienic macro, it will return new syntax expander\n that works like lisp macros."),quote:ci(new au("quote",function(e){return Qa(e.car)}),"(quote expression)\n\n Macro that return single lips expression as data (it don't evaluate its\n argument). It will return list of pairs if put in front of lips code.\n And if put in fron of symbol it will return that symbol not value\n associated with that name."),"unquote-splicing":ci("unquote-splicing",function(){throw new Error("You can't call `unquote-splicing` outside of quasiquote")},"(unquote-splicing code)\n\n Special form to be used in quasiquote macro, parser is processing special\n characters ,@ and create call to this pseudo function. It can be used\n to evalute expression inside and return the value without parenthesis.\n the value will be joined to the output list structure."),unquote:ci("unquote",function(){throw new Error("You can't call `unquote` outside of quasiquote")},"(unquote code)\n\n Special form to be used in quasiquote macro, parser is processing special\n characters , and create call to this pseudo function. It can be used\n to evalute expression inside and return the value, the output is inserted\n into list structure created by queasiquote."),quasiquote:au.defmacro("quasiquote",function(e,t){var o=t.dynamic_scope,s=t.error;var c=this;if(o){o=c}function u(e){return e instanceof Ni||Li(e)||Array.isArray(e)}function f(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:u;if(e instanceof Ni){var n=e.car;var i=e.cdr;if(r(n)){n=t(n)}if(r(i)){i=t(i)}if(gu(n)||gu(i)){return $n([n,i]).then(function(e){var t=A(e,2),r=t[0],n=t[1];return new Ni(r,n)})}else{return new Ni(n,i)}}return e}function a(e,t){if(e instanceof Ni){if(t!==Pi){e.append(t)}}else{e=new Ni(e,t)}return e}function r(e){return!!e.filter(function(e){return e instanceof Ni&&Ln.is(e.car,/^(unquote|unquote-splicing)$/)}).length}function l(e,n,i){return e.reduce(function(e,t){if(!(t instanceof Ni)){e.push(t);return e}if(Ln.is(t.car,"unquote-splicing")){var r;if(n+11){var t="You can't splice multiple atoms inside list";throw new Error(t)}if(!(i.cdr instanceof Ni&&r[0]===Pi)){return r[0]}}r=r.map(function(e){if(_.has(e)){return e.clone()}else{_.add(e);return e}});var n=d(i.cdr,0,1);if(n===Pi&&r[0]===Pi){return undefined}return ni(n,function(e){if(r[0]===Pi){return e}if(r.length===1){return a(r[0],e)}var t=r.reduce(function(e,t){return a(e,t)});return a(t,e)})})}(i.car.cdr)}var _=new Set;function d(e,t,r){if(e instanceof Ni){if(e.car instanceof Ni){if(Ln.is(e.car.car,"unquote-splicing")){return p(e,t+1,r)}if(Ln.is(e.car.car,"unquote")){if(t+2===r&&e.car.cdr instanceof Ni&&e.car.cdr.car instanceof Ni&&Ln.is(e.car.cdr.car.car,"unquote-splicing")){var n=e.car.cdr;return new Ni(new Ni(new Ln("unquote"),p(n,t+2,r)),Pi)}else if(e.car.cdr instanceof Ni&&e.car.cdr.cdr!==Pi){if(e.car.cdr.car instanceof Ni){var i=[];return function t(r){if(r===Pi){return Ni.fromArray(i)}return ni(Io(r.car,{env:c,dynamic_scope:o,error:s}),function(e){i.push(e);return t(r.cdr)})}(e.car.cdr)}else{return e.car.cdr}}}}if(Ln.is(e.car,"quasiquote")){var u=d(e.cdr,t,r+1);return new Ni(e.car,u)}if(Ln.is(e.car,"quote")){return new Ni(e.car,d(e.cdr,t,r))}if(Ln.is(e.car,"unquote")){t++;if(tr){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(e.cdr instanceof Ni){if(e.cdr.cdr!==Pi){if(e.cdr.car instanceof Ni){var a=[];return function t(r){if(r===Pi){return Ni.fromArray(a)}return ni(Io(r.car,{env:c,dynamic_scope:o,error:s}),function(e){a.push(e);return t(r.cdr)})}(e.cdr)}else{return e.cdr}}else{return Io(e.cdr.car,{env:c,dynamic_scope:o,error:s})}}else{return e.cdr}}return f(e,function(e){return d(e,t,r)})}else if(Li(e)){return h(e,t,r)}else if(e instanceof Array){return l(e,t,r)}return e}function n(e){if(e instanceof Ni){delete e[Pu];if(!e.haveCycles("car")){n(e.car)}if(!e.haveCycles("cdr")){n(e.cdr)}}}if(Li(e.car)&&!r(Object.values(e.car))){return Qa(e.car)}if(Array.isArray(e.car)&&!r(e.car)){return Qa(e.car)}if(e.car instanceof Ni&&!e.car.find("unquote")&&!e.car.find("unquote-splicing")&&!e.car.find("quasiquote")){return Qa(e.car)}var i=d(e.car,0,1);return ni(i,function(e){n(e);return Qa(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:ci("clone",function e(t){yo("clone",t,"pair");return t.clone()},"(clone list)\n\n Function return clone of the list."),append:ci("append",function e(){var t;for(var r=arguments.length,n=new Array(r),i=0;iarray")(t).reverse();return io.get("array->list")(r)}else if(!(t instanceof Array)){throw new Error(_o("reverse",Ao(t),"array or pair"))}else{return t.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:ci("nth",function e(t,r){yo("nth",t,"number");yo("nth",r,["array","pair"]);if(r instanceof Ni){var n=r;var i=0;while(iarray")(r).join(t)},"(join separator list)\n\n Function return string by joining elements of the list"),split:ci("split",function e(t,r){yo("split",t,["regex","string"]);yo("split",r,"string");return io.get("array->list")(r.split(t))},"(split separator string)\n\n Function create list by splitting string by separatar that can\n be a string or regular expression."),replace:ci("replace",function e(t,r,n){yo("replace",t,["regex","string"]);yo("replace",r,["string","function"]);yo("replace",n,"string");return n.replace(t,r)},"(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:ci("match",function e(t,r){yo("match",t,["regex","string"]);yo("match",r,"string");var n=r.match(t);return n?io.get("array->list")(n):false},"(match pattern string)\n\n function return match object from JavaScript as list or #f if not match."),search:ci("search",function e(t,r){yo("search",t,["regex","string"]);yo("search",r,"string");return r.search(t)},"(search pattern string)\n\n Function return first found index of the pattern inside a string"),repr:ci("repr",function e(t,r){return Zi(t,r)},"(repr obj)\n\n Function return string LIPS representation of an object as string."),"escape-regex":ci("escape-regex",function(e){yo("escape-regex",e,"string");return kn(e.valueOf())},"(escape-regex string)\n\n Function return new string where all special operators used in regex,\n are escaped with slash so they can be used in RegExp constructor\n to match literal string"),env:ci("env",function e(e){e=e||this;var t=Object.keys(e.__env__).map(Ln);var r;if(t.length){r=Ni.fromArray(t)}else{r=Pi}if(e.__parent__ instanceof Ga){return io.get("env")(e.__parent__).append(r)}return r},"(env)\n (env obj)\n\n Function return list of values (functions, macros and variables)\n inside environment and it's parents."),new:ci("new",function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n2&&arguments[2]!==undefined?arguments[2]:Jn.LITERAL;yo("set-special!",e,"string",1);yo("set-special!",t,"symbol",2);Jn.append(e.valueOf(),t,r)},'(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:Ka,".":Ka,unbind:ci(Fu,"(unbind fn)\n\n Function remove bidning from function so you can get props from it."),type:ci(Ao,"(type object)\n\n Function return type of an object as string."),debugger:ci("debugger",function(){debugger},"(debugger)\n\n Function stop JavaScript code in debugger."),in:ci("in",function(e,t){if(e instanceof Ln||e instanceof sa||e instanceof da){e=e.valueOf()}return e in Eu(t)},"(in key value)\n\n Function use is in operator to check if value is in object."),instanceof:ci("instanceof",function(e,t){return t instanceof Fu(e)},"(instanceof type obj)\n\n Function check of object is instance of object."),"prototype?":ci("prototype?",Ki,"(prototype? obj)\n\n Function check if value is JavaScript Object prototype."),"macro?":ci("macro?",function(e){return e instanceof au},"(macro? expression)\n\n Function check if value is a macro."),"function?":ci("function?",vu,"(function? expression)\n\n Function check if value is a function."),"real?":ci("real?",function(e){if(Ao(e)!=="number"){return false}if(e instanceof da){return e.isFloat()}return da.isFloat(e)},"(real? number)\n\n Function check if value is real number."),"number?":ci("number?",function(e){return Number.isNaN(e)||da.isNumber(e)},"(number? expression)\n\n Function check if value is a number or NaN value."),"string?":ci("string?",function(e){return sa.isString(e)},"(string? expression)\n\n Function check if value is a string."),"pair?":ci("pair?",function(e){return e instanceof Ni},"(pair? expression)\n\n Function check if value is a pair or list structure."),"regex?":ci("regex?",function(e){return e instanceof RegExp},"(regex? expression)\n\n Function check if value is regular expression."),"null?":ci("null?",function(e){return du(e)},"(null? expression)\n\n Function check if value is nulish."),"boolean?":ci("boolean?",function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Function check if value is boolean."),"symbol?":ci("symbol?",function(e){return e instanceof Ln},"(symbol? expression)\n\n Function check if value is LIPS symbol"),"array?":ci("array?",function(e){return e instanceof Array},"(array? expression)\n\n Function check if value is an arrray."),"object?":ci("object?",function(e){return e!==Pi&&e!==null&&!(e instanceof oa)&&!(e instanceof RegExp)&&!(e instanceof sa)&&!(e instanceof Ni)&&!(e instanceof da)&&_(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Function check if value is an plain object."),flatten:ci("flatten",function e(t){yo("flatten",t,"pair");return t.flatten()},"(flatten list)\n\n Return shallow list from tree structure (pairs)."),"array->list":ci("array->list",function(e){yo("array->list",e,"array");return Ni.fromArray(e)},"(array->list array)\n\n Function convert JavaScript array to LIPS list."),"tree->array":ci("tree->array",Ri("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":ci("list->array",Ri("list->array"),"(list->array list)\n\n Function convert LIPS list into JavaScript array."),apply:ci("apply",function e(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;iarray").call(this,u));return t.apply(this,Oo(t,n))},"(apply fn list)\n\n Function that call function with list of arguments."),length:ci("length",function e(t){if(!t||t===Pi){return 0}if(t instanceof Ni){return t.length()}if("length"in t){return t.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":ci("string->number",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;yo("string->number",e,"string",1);yo("string->number",t,"number",2);e=e.valueOf();t=t.valueOf();if(e.match(fn)||e.match(on)){return dn(e,t)}else if(e.match(ln)||e.match(an)){return yn(e,t)}else{var r=t===10&&!e.match(/e/i)||t===16;if(e.match(cn)&&r||e.match(sn)){return vn(e,t)}if(e.match(Wr)){return wn(e)}}return false},"(string->number number [radix])\n\n Function convert string to number."),try:ci(new au("try",function(t,e){var c=this;var f=e.dynamic_scope,l=e.error;return new Promise(function(i,n){var u,a;if(Ln.is(t.cdr.car.car,"catch")){u=t.cdr.car;if(t.cdr.cdr instanceof Ni&&Ln.is(t.cdr.cdr.car.car,"finally")){a=t.cdr.cdr.car}}else if(Ln.is(t.cdr.car.car,"finally")){a=t.cdr.car}if(!(a||u)){throw new Error("try: invalid syntax")}var o=i;if(a){o=function e(t,r){o=n;ni(Io(new Ni(new Ln("begin"),a.cdr),s),function(){r(t)})}}var s={env:c,error:function e(t){var r=c.inherit("try");if(u){r.set(u.cdr.car.car,t);var n={env:r,error:l};if(f){n.dynamic_scope=c}ni(Io(new Ni(new Ln("begin"),u.cdr.cdr),n),function(e){o(e,i)})}else{o(t,l)}}};if(f){s.dynamic_scope=c}var e=Io(t.car,s);if(gu(e)){e.then(function(e){o(e,i)})["catch"](s.error)}else{o(e,i)}})}),"(try expr (catch (e) code))\n (try expr (catch (e) code) (finally code))\n (try expr (finally code))\n\n Macro execute user code and catch exception. If catch is provided\n it's executed when expression expr throw error. If finally is provide\n it's always executed at the end."),raise:ci("raise",function(e){throw e},"(raise obj)\n\n Throws new exception with given object."),throw:ci("throw",function(e){throw new Error(e)},"(throw string)\n\n Throws new expection."),find:ci("find",function t(r,n){yo("find",r,["regex","function"]);yo("find",n,["pair","nil"]);if(du(n)){return Pi}var e=si("find",r);return ni(e(n.car),function(e){if(e&&e!==Pi){return n.car}return t(r,n.cdr)})},"(find fn list)\n (find regex list)\n\n Higher order Function find first value for which function return true.\n If called with regex it will create matcher function."),"for-each":ci("for-each",function(e){var t;yo("for-each",e,"function");for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i1?t-1:0),u=1;u3?n-3:0),u=3;u3?i-3:0),a=3;aarray")(r);var u=[];var a=si("filter",t);return function t(r){function e(e){if(e&&e!==Pi){u.push(n)}return t(++r)}if(r===i.length){return Ni.fromArray(u)}var n=i[r];return ni(a(n),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher order function that call `fn` for each element of the list\n and return list for only those elements for which funtion return\n true value. If called with regex it will create matcher function."),compose:ci(Xu,"(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:ci(Ku,"(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:ci(ua,"(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:ci("gcd",function e(){for(var t=arguments.length,r=new Array(t),n=0;no?u%=o:o%=u}u=eu(s*r[a])/(u+o)}return da(u)},"(lcm n1 n2 ...)\n\n Function return the least common multiple of their arguments."),"odd?":ci("odd?",ra(function(e){return da(e).isOdd()}),"(odd? number)\n\n Function check if number os odd."),"even?":ci("even?",ra(function(e){return da(e).isEven()}),"(even? number)\n\n Function check if number is even."),"*":ci("*",ia(function(e,t){return da(e).mul(t)},da(1)),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":ci("+",ia(function(e,t){return da(e).add(t)},da(0)),"(+ . numbers)\n\n Sum all numbers passed as arguments. If single value is passed it will\n return that value."),"-":ci("-",function(){for(var e=arguments.length,t=new Array(e),r=0;r":ci(">",function(){for(var e=arguments.length,t=new Array(e),r=0;r",t,"number");return tu(function(e,t){return da(e).cmp(t)===1},t)},"(> x1 x2 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically increasing"),"<":ci("<",function(){for(var e=arguments.length,t=new Array(e),r=0;r=":ci(">=",function(){for(var e=arguments.length,t=new Array(e),r=0;r=",t,"number");return tu(function(e,t){return[0,1].includes(da(e).cmp(t))},t)},"(>= x1 x2 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically nondecreasing"),"eq?":ci("eq?",ru,"(eq? a b)\n\n Function compare two values if they are identical."),or:ci(new au("or",function(e,t){var i=t.dynamic_scope,u=t.error;var a=io.get("list->array")(e);var o=this;if(i){i=o}if(!a.length){return false}var s;return function t(){function e(e){s=e;if(s!==false){return s}else{return t()}}if(!a.length){if(s!==false){return s}else{return false}}else{var r=a.shift();var n=Io(r,{env:o,dynamic_scope:i,error:u});return ni(n,e)}}()}),"(or . expressions)\n\n Macro execute the values one by one and return the one that is truthy value.\n If there are no expression that evaluate to true it return false."),and:ci(new au("and",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},i=t.dynamic_scope,u=t.error;var a=io.get("list->array")(e);var o=this;if(i){i=o}if(!a.length){return true}var s;return function t(){function e(e){s=e;if(s===false){return false}else{return t()}}if(!a.length){if(s!==false){return s}else{return false}}else{var r=a.shift();var n=Io(r,{env:o,dynamic_scope:i,error:u});return ni(n,e)}}()}),"(and . expressions)\n\n Macro evalute each expression in sequence if any value return false it will\n return false. If each value return true it will return the last value.\n If it's called without arguments it will return true."),"|":ci("|",function(e,t){return da(e).or(t)},"(| a b)\n\n Function calculate or bit operation."),"&":ci("&",function(e,t){return da(e).and(t)},"(& a b)\n\n Function calculate and bit operation."),"~":ci("~",function(e){return da(e).neg()},"(~ number)\n\n Function negate the value."),">>":ci(">>",function(e,t){return da(e).shr(t)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":ci("<<",function(e,t){return da(e).shl(t)},"(<< a b)\n\n Function left shit the value a by value b."),not:ci("not",function e(t){if(du(t)){return true}return!t},"(not object)\n\n Function return negation of the argument.")},undefined,"global");var uo=io.inherit("user-env");function ao(e,t){e.constant("**internal-env**",t);e.doc("**internal-env**","**internal-env**\n\n Constant used to hide stdin, stdout and stderr so they don't interfere\n with variables with the same name. Constants are internal type\n of variables that can't be redefined, defining variable with same name\n will throw an error.");io.set("**interaction-environment**",e)}ao(uo,to);io.doc("**interaction-environment**","**interaction-environment**\n\n Internal dynamic, global variable used to find interpreter environment.\n It's used so the read and write functions can locate **internal-env**\n that contain references to stdin, stdout and stderr.");(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(t){var r=e[t]?e[t]:t;io.set(r,ci(r,function(e){yo(r,e,"number");if(e instanceof da){return e[t]()}},"(".concat(r," number)\n\n Function calculate ").concat(r," of a number.")))})})();function oo(e){if(e.length===1){return e[0]}else{var t=[];var r=oo(e.slice(1));for(var n=0;n3&&arguments[3]!==undefined?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(n!==null){i+=" (argument ".concat(n,")")}if(vu(r)){return"Invalid type got ".concat(t).concat(i)}if(r instanceof Array){if(r.length===1){r=r[0]}else{var u=r[r.length-1];r=r.slice(0,-1).join(", ")+" or "+u}}return"Expecting ".concat(r,", got ").concat(t).concat(i)}function vo(r,e,n){e.forEach(function(e,t){yo(r,e,n,t+1)})}function mo(e,t,r){yo(e,t,r);if(t.__type__===Ma){throw new Error(_o(e,"binary-port","textual-port"))}}function yo(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;e=e.valueOf();var i=Ao(t).toLowerCase();if(vu(r)){if(!r(t)){throw new Error(_o(e,i,r,n))}return}var u=false;if(r instanceof Ni){r=r.to_array()}if(r instanceof Array){r=r.map(function(e){return e.valueOf()})}if(r instanceof Array){r=r.map(function(e){return e.valueOf().toLowerCase()});if(r.includes(i)){u=true}}else{r=r.valueOf().toLowerCase()}if(!u&&i!==r){throw new Error(_o(e,i,r,n))}}function go(e){var t=_(e);return["string","function"].includes(t)||_(e)==="symbol"||e instanceof Yn||e instanceof Ln||e instanceof da||e instanceof sa||e instanceof RegExp}function bo(e){return e instanceof da||e instanceof sa||e instanceof oa}function wo(e,t){if(e===null){return false}return _(e)==="object"&&t in Object.getOwnPropertySymbols(e)}function Do(e,t){if(wo(e,t)||wo(e.__proto__,t)){return vu(e[t])}}function Eo(r){var n=new WeakMap;return function(e){var t=n.get(e);if(!t){t=r(e)}return t}}Ao=Eo(Ao);function Ao(e){var t=Pr.get(e);if(t){return t}if(_(e)==="object"){for(var r=0,n=Object.entries(Ir);r2&&arguments[2]!==undefined?arguments[2]:{},u=t.env,a=t.dynamic_scope,r=t.error,o=r===void 0?function(){}:r;e=xo(e,{env:u,dynamic_scope:a,error:o});return ni(e,function(e){if(Gu(i)){i=Fu(i)}e=Oo(i,e);var t=e.slice();var r=(a||u).newFrame(i,t);var n=Fo(i.apply(r,e));return ni(n,function(e){if(e instanceof Ni){e.markCycles();return Qa(e)}return wu(e)},o)})}var Bo=function(){function t(e){y(this,t);this.__value__=e}b(t,[{key:"invoke",value:function e(){if(this.__value__===null){throw new Error("Continuations are not implemented yet")}}},{key:"toString",value:function e(){return"#"}}]);return t}();var jo=function e(){};function Io(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=e.env,n=e.dynamic_scope,i=e.error,u=i===void 0?jo:i;try{if(n===true){r=n=r||io}else if(r===true){r=n=io}else{r=r||io}var a={env:r,dynamic_scope:n,error:u};var o;if(du(t)){return t}if(t instanceof Ln){return r.get(t)}if(!(t instanceof Ni)){return t}var s=t.car;var c=t.cdr;if(s instanceof Ni){o=Fo(Io(s,a));if(gu(o)){return o.then(function(e){return Io(new Ni(e,t.cdr),a)})}else if(!yu(o)){throw new Error(Ao(o)+" "+r.get("repr")(o)+" is not callable while evaluating "+t.toString())}}if(s instanceof Ln){o=r.get(s)}else if(vu(s)){o=s}var f;if(o instanceof fu){f=Co(o,t,a)}else if(o instanceof au){f=ko(o,c,a)}else if(vu(o)){f=So(o,c,a)}else if(mu(o)){f=o.invoke()}else if(t instanceof Ni){o=s&&s.toString();throw new Error("".concat(Ao(s)," ").concat(o," is not a function"))}else{return t}var l=r.get(Symbol["for"]("__promise__"),{throwError:false});if(l===true&&gu(f)){f=f.then(function(e){if(e instanceof Ni&&!o[Pu]){return Io(e,a)}return e});return new Yn(f)}return f}catch(e){u&&u.call(r,e,t)}}var Po=Ro(function(e){return e});var No=Ro(function(e,t){return t});function Ro(_){return function(){var n=O(j.mark(function e(r,n,i){var u,a,o,s,c,f,l,h,p;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(i===true){n=i=n||uo}else if(n===true){n=i=uo}else{n=n||uo}u=[];a=Array.isArray(r)?r:ti(r);o=false;s=false;t.prev=5;f=F(a);case 7:t.next=9;return f.next();case 9:if(!(o=!(l=t.sent).done)){t.next=27;break}h=l.value;p=Io(h,{env:n,dynamic_scope:i,error:function e(t,r){if(t&&t.message){if(t.message.match(/^Error:/)){var n=/^(Error:)\s*([^:]+:\s*)/;t.message=t.message.replace(n,"$1 $2")}if(r){if(!(t.__code__ instanceof Array)){t.__code__=[]}t.__code__.push(r.toString(true))}}throw t}});if(gu(p)){t.next=16;break}u.push(_(h,p));t.next=24;break;case 16:t.t0=u;t.t1=_;t.t2=h;t.next=21;return p;case 21:t.t3=t.sent;t.t4=(0,t.t1)(t.t2,t.t3);t.t0.push.call(t.t0,t.t4);case 24:o=false;t.next=7;break;case 27:t.next=33;break;case 29:t.prev=29;t.t5=t["catch"](5);s=true;c=t.t5;case 33:t.prev=33;t.prev=34;if(!(o&&f["return"]!=null)){t.next=38;break}t.next=38;return f["return"]();case 38:t.prev=38;if(!s){t.next=41;break}throw c;case 41:return t.finish(38);case 42:return t.finish(33);case 43:return t.abrupt("return",u);case 44:case"end":return t.stop()}}},e,null,[[5,29,33,43],[34,,38,42]])}));function e(e,t,r){return n.apply(this,arguments)}return e}()}function To(e){var t={"[":"]","(":")"};var r;if(typeof e==="string"){r=Nn(e)}else{r=e.map(function(e){return e&&e.token?e.token:e})}var n=Object.keys(t);var i=Object.values(t).concat(n);r=r.filter(function(e){return i.includes(e)});var u=new On;var a=Cr(r),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;if(n.includes(s)){u.push(s)}else if(!u.is_empty()){var c=u.top();var f=t[c];if(s===f){u.pop()}else{throw new Error("Syntax error: missing closing ".concat(f))}}else{throw new Error("Syntax error: not matched closing ".concat(s))}}}catch(e){a.e(e)}finally{a.f()}return u.is_empty()}function Lo(e){var t="("+e.toString()+")()";var r=window.URL||window.webkitURL;var n;try{n=new Blob([t],{type:"application/javascript"})}catch(e){var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;n=new i;n.append(t);n=n.getBlob()}return new jr.Worker(r.createObjectURL(n))}function Uo(){return ps.version.match(/^(\{\{VER\}\}|DEV)$/)}function qo(){if(lo()){return}var e;if(document.currentScript){e=document.currentScript}else{var t=document.querySelectorAll("script");if(!t.length){return}e=t[t.length-1]}var r=e.getAttribute("src");return r}var Mo=qo();function Yo(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"";var t="dist/std.xcb";if(e===""){if(Mo){e=Mo.replace(/[^/]*$/,"std.xcb")}else if(Uo()){e="https://cdn.jsdelivr.net/gh/jcubic/lips@devel/".concat(t)}else{e="https://cdn.jsdelivr.net/npm/@jcubic/lips@".concat(ps.version,"/").concat(t)}}var r=io.get("load");return r.call(uo,e,io)}function $o(e){this.url=e;var a=this.worker=Lo(function(){var a;var o;self.addEventListener("message",function(e){var r=e.data;var t=r.id;if(r.type!=="RPC"||t===null){return}function n(e){self.postMessage({id:t,type:"RPC",result:e})}function i(e){self.postMessage({id:t,type:"RPC",error:e})}if(r.method==="eval"){if(!o){i("Worker RPC: LIPS not initilized, call init first");return}o.then(function(){var e=r.params[0];var t=r.params[1];a.exec(e,t).then(function(e){e=e.map(function(e){return e&&e.valueOf()});n(e)})["catch"](function(e){i(e)})})}else if(r.method==="init"){var u=r.params[0];if(typeof u!=="string"){i("Worker RPC: url is not a string")}else{importScripts("".concat(u,"/dist/lips.min.js"));a=new ps.Interpreter("worker");o=Yo(u);o.then(function(){n(true)})}}})});this.rpc=function(){var n=0;return function e(t,r){var u=++n;return new Promise(function(n,i){a.addEventListener("message",function e(t){var r=t.data;if(r&&r.type==="RPC"&&r.id===u){if(r.error){i(r.error)}else{n(r.result)}a.removeEventListener("message",e)}});a.postMessage({type:"RPC",method:t,id:u,params:r})})}}();this.rpc("init",[e])["catch"](function(e){console.error(e)});this.exec=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return this.rpc("eval",[e,t])}}var zo={pair:function e(t){var r=A(t,2),n=r[0],i=r[1];return Ni(n,i)},number:function e(t){if(sa.isString(t)){return da([t,10])}return da(t)},regex:function e(t){var r=A(t,2),n=r[0],i=r[1];return new RegExp(n,i)},nil:function e(){return Pi},symbol:function e(t){if(sa.isString(t)){return Ln(t)}else if(Array.isArray(t)){return Ln(Symbol["for"](t[0]))}},string:sa,character:oa};var Vo=Object.keys(zo);var Jo={};for(var Go=0,Ho=Object.entries(Vo);Go1){var n=t.reduce(function(e,t){return e+t.length},0);var i=new Uint8Array(n);var u=0;t.forEach(function(e){i.set(e,u);u+=e.length});return i}else if(t.length){return t[0]}}function is(){var e=1;var t=new TextEncoder("utf-8");return t.encode("LIPS".concat(e.toString().padStart(3," ")))}var us=7;function as(e){var t=new TextDecoder("utf-8");var r=t.decode(e.slice(0,us));var n=r.substring(0,4);if(n==="LIPS"){var i=r.match(/^(....).*([0-9]+)$/);if(i){return{type:i[1],version:Number(i[2])}}}return{type:"unknown"}}function os(e){var t=is();var r=rs.encode(e);return ns(t,br(r,{magic:false}))}function ss(e){var t=as(e),r=t.type,n=t.version;if(r==="LIPS"&&n===1){var i=wr(e.slice(us),{magic:false});return rs.decode(i)}else{throw new Error("Invalid file format ".concat(r))}}function cs(e){console.error(e.message||e);if(e.code){console.error(e.code.map(function(e,t){return"[".concat(t+1,"]: ").concat(e)}))}}function fs(){var a=["text/x-lips","text/x-scheme"];var o;function s(r){return new Promise(function(t){var e=r.getAttribute("src");if(e){return fetch(e).then(function(e){return e.text()}).then(No).then(t)["catch"](function(e){cs(e);t()})}else{return No(r.innerHTML).then(t)["catch"](function(e){cs(e);t()})}})}function e(){return new Promise(function(i){var u=Array.from(document.querySelectorAll("script"));return function e(){var t=u.shift();if(!t){i()}else{var r=t.getAttribute("type");if(a.includes(r)){var n=t.getAttribute("bootstrap");if(!o&&typeof n==="string"){return Yo(n).then(function(){return s(t)}).then(e)}else{return s(t).then(e)}}else if(r&&r.match(/lips|lisp/)){console.warn("Expecting "+a.join(" or ")+" found "+r)}return e()}}()})}if(!window.document){return Promise.resolve()}else if(ls){var t=ls;var r=t.getAttribute("bootstrap");if(typeof r==="string"){return Yo(r).then(function(){o=true;return e()})}}return e()}var ls=typeof window!=="undefined"&&window.document&&document.currentScript;if(typeof window!=="undefined"){Ur(window,fs)}var hs=function(){var e=sa("Fri, 12 Nov 2021 08:35:50 +0000").valueOf();var t=e==="{{"+"DATE}}"?new Date:new Date(e);var r=function e(t){return t.toString().padStart(2,"0")};var n=t.getFullYear();var i=[n,r(t.getMonth()+1),r(t.getDate())].join("-");var u="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter DEV (".concat(i,") \nCopyright (c) 2018-").concat(n," Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables. You can also\nuse (help name) to display help for specic function or macro, (apropos name)\nto display list of matched names in environment and (dir object) to list\nproperties of an object.\n").replace(/^.*\n/,"");return u}();ai(di,"__class__","ahead");ai(Ni,"__class__","pair");ai(Ii,"__class__","nil");ai(vi,"__class__","pattern");ai(_i,"__class__","formatter");ai(au,"__class__","macro");ai(fu,"__class__","syntax");ai(Ga,"__class__","environment");ai(Sa,"__class__","input-port");ai(Ba,"__class__","output-port");ai(ja,"__class__","output-port");ai(Ia,"__class__","output-string-port");ai(Na,"__class__","input-string-port");ai(La,"__class__","input-file-port");ai(Pa,"__class__","output-file-port");ai(Ja,"__class__","lips-error");[da,Da,ka,Ea,Oa].forEach(function(e){ai(e,"__class__","number")});ai(oa,"__class__","character");ai(Ln,"__class__","symbol");ai(sa,"__class__","string");ai(Yn,"__class__","promise");var ps={version:"DEV",banner:hs,date:"Fri, 12 Nov 2021 08:35:50 +0000",exec:No,parse:Xu(oi,ti),tokenize:Nn,evaluate:Io,compile:Po,serialize:es,unserialize:ts,serialize_bin:os,unserialize_bin:ss,bootstrap:Yo,Environment:Ga,env:uo,Worker:$o,Interpreter:Va,balanced_parenthesis:To,balancedParenthesis:To,balanced:To,Macro:au,Syntax:fu,Pair:Ni,Values:Wa,QuotedPromise:Yn,Error:Ja,quote:Qa,InputPort:Sa,OutputPort:Ba,BufferedOutputPort:ja,InputFilePort:La,OutputFilePort:Pa,InputStringPort:Na,OutputStringPort:Ia,InputByteVectorPort:Ra,OutputByteVectorPort:Ta,InputBinaryFilePort:Ua,OutputBinaryFilePort:qa,Formatter:_i,Parser:Xn,Lexer:Zn,specials:Jn,repr:Ti,nil:Pi,eof:$a,LSymbol:Ln,LNumber:da,LFloat:Ea,LComplex:Da,LRational:ka,LBigInteger:Oa,LCharacter:oa,LString:sa,rationalize:xa};io.set("lips",ps);var _s={};var ds=Object.freeze({__proto__:null,default:_s});function vs(e,t){var r=0;for(var n=e.length-1;n>=0;n--){var i=e[n];if(i==="."){e.splice(n,1)}else if(i===".."){e.splice(n,1);r++}else if(r){e.splice(n,1);r--}}if(t){for(;r--;r){e.unshift("..")}}return e}var ms=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;var ys=function(e){return ms.exec(e).slice(1)};function gs(){var e="",t=false;for(var r=arguments.length-1;r>=-1&&!t;r--){var n=r>=0?arguments[r]:"/";if(typeof n!=="string"){throw new TypeError("Arguments to path.resolve must be strings")}else if(!n){continue}e=n+"/"+e;t=n.charAt(0)==="/"}e=vs(Ss(e.split("/"),function(e){return!!e}),!t).join("/");return(t?"/":"")+e||"."}function bs(e){var t=ws(e),r=Bs(e,-1)==="/";e=vs(Ss(e.split("/"),function(e){return!!e}),!t).join("/");if(!e&&!t){e="."}if(e&&r){e+="/"}return(t?"/":"")+e}function ws(e){return e.charAt(0)==="/"}function Ds(){var e=Array.prototype.slice.call(arguments,0);return bs(Ss(e,function(e,t){if(typeof e!=="string"){throw new TypeError("Arguments to path.join must be strings")}return e}).join("/"))}function Es(e,t){e=gs(e).substr(1);t=gs(t).substr(1);function r(e){var t=0;for(;t=0;r--){if(e[r]!=="")break}if(t>r)return[];return e.slice(t,r-t+1)}var n=r(e.split("/"));var i=r(t.split("/"));var u=Math.min(n.length,i.length);var a=u;for(var o=0;o=t.length)return{done:true};return{done:false,value:t[n++]}},e:function e(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u=true,a=false,o;return{s:function e(){r=r.call(t)},n:function e(){var t=r.next();u=t.done;return t},e:function e(t){a=true;o=t},f:function e(){try{if(!u&&r["return"]!=null)r["return"]()}finally{if(a)throw o}}}}function kr(e,t){if(!e)return;if(typeof e==="string")return Or(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor)r=e.constructor.name;if(r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return Or(e,t)}function Or(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r1&&arguments[1]!==undefined?arguments[1]:null;var n=arguments[1]===true;function t(e){if(!Mr()){return}var t=io.get("repr")(e);if(r===null||r instanceof RegExp&&r.test(t)){console.log(io.get("type")(e)+": "+t)}if(n){console.log(e)}}if(gu(e)){e.then(t)}else{t(e)}return e}function Mr(){return uo&&uo.get("DEBUG",{throwError:false})}function Yr(e){return e?"(?:#".concat(e,"(?:#[ie])?|#[ie]#").concat(e,")"):"(?:#[ie])?"}function $r(e,t){return"".concat(Yr(e),"[+-]?").concat(t,"+/").concat(t,"+")}function zr(e,t){return"".concat(Yr(e),"(?:[+-]?(?:").concat(t,"+/").concat(t,"+|nan.0|inf.0|").concat(t,"+))?(?:[+-]i|[+-]?(?:").concat(t,"+/").concat(t,"+|").concat(t,"+|nan.0|inf.0)i)(?=[()[\\]\\s]|$)")}function Vr(e,t){return"".concat(Yr(e),"[+-]?").concat(t,"+")}var Jr=/^#\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimyus]*)$/;var Gr="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)";var Hr="(?:#[ie])?(?:[+-]?(?:[0-9]+/[0-9]+|nan.0|inf.0|".concat(Gr,"|[+-]?[0-9]+))?(?:").concat(Gr,"|[+-](?:[0-9]+/[0-9]+|[0-9]+|nan.0|inf.0))i");var Wr=new RegExp("^(#[ie])?".concat(Gr,"$"),"i");function Qr(e,t){var r=e==="x"?"(?!\\+|".concat(t,")"):"(?!\\.|".concat(t,")");var n="";if(e===""){n="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+(?![0-9]))(?:[eE][-+]?[0-9]+)?))"}return new RegExp("^((?:(?:".concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(t,"+/").concat(t,"+(?!").concat(t,")|[+-]?").concat(t,"+)").concat(r,")?)(").concat(n,"|[-+]?inf.0|[-+]?nan.0|[+-]?").concat(t,"+/").concat(t,"+|[+-]?").concat(t,"+|[+-])i$"),"i")}var Zr=function(){var u={};[[10,"","[0-9]"],[16,"x","[0-9a-fA-F]"],[8,"o","[0-7]"],[2,"b","[01]"]].forEach(function(e){var t=A(e,3),r=t[0],n=t[1],i=t[2];u[r]=Qr(n,i)});return u}();var Kr={alarm:"",backspace:"\b",delete:"",escape:"",newline:"\n",null:"\0",return:"\r",space:" ",tab:"\t",dle:"",soh:"",dc1:"",stx:"",dc2:"",etx:"",dc3:"",eot:"",dc4:"",enq:"",nak:"",ack:"",syn:"",bel:"",etb:"",bs:"\b",can:"",ht:"\t",em:"",lf:"\n",sub:"",vt:"\v",esc:"",ff:"\f",fs:"",cr:"\r",gs:"",so:"",rs:"",si:"",us:"",del:""};function Xr(e){var t=[];var r=0;var n=e.length;while(r=55296&&i<=56319&&r1&&arguments[1]!==undefined?arguments[1]:10;var r=_n(e);var n=r.number.split("/");var i=ka({num:da([n[0],r.radix||t]),denom:da([n[1],r.radix||t])});if(r.inexact){return i.valueOf()}else{return i}}function vn(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;var r=_n(e);if(r.inexact){return Ea(parseInt(r.number,r.radix||t))}return da([r.number,r.radix||t])}function mn(e){var t=e.match(/#\\x([0-9a-f]+)$/i);var r;if(t){var n=parseInt(t[1],16);r=String.fromCodePoint(n)}else{t=e.match(/#\\(.+)$/);if(t){r=t[1]}}if(r){return oa(r)}throw new Error("Parse: invalid character")}function yn(e){var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;function t(e){var t;if(e==="+"){t=da(1)}else if(e==="-"){t=da(-1)}else if(e.match(cn)){t=da([e,i])}else if(e.match(fn)){var r=e.split("/");t=ka({num:da([r[0],i]),denom:da([r[1],i])})}else if(e.match(Wr)){var n=wn(e);if(u.exact){return n.toRational()}return n}else if(e.match(/nan.0$/)){return da(NaN)}else if(e.match(/inf.0$/)){if(e[0]==="-"){return da(Number.NEGATIVE_INFINITY)}return da(Number.POSITIVE_INFINITY)}else{throw new Error("Internal Parser Error")}if(u.inexact){return Ea(t.valueOf())}return t}var u=_n(e);i=u.radix||i;var r;var n=u.number.match(hn);if(i!==10&&n){r=n}else{r=u.number.match(Zr[i])}var a,o;o=t(r[2]);if(r[1]){a=t(r[1])}else{a=da(0)}if(o.cmp(0)===0&&o.__type__==="bigint"){return a}return Da({im:o,re:a})}function gn(e){return parseInt(e.toString(),10)===e}function bn(e){var t=e.match(/^(([-+]?[0-9]*)(?:\.([0-9]+))?)e([-+]?[0-9]+)/i);if(t){var r=parseInt(t[4],10);var n;var i=t[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var u=t[3]&&t[3].length;if(i0){return da(u).mul(o)}}}r=Ea(r);if(t.exact){return r.toRational()}return r}function Dn(e){e=e.replace(/\\x([0-9a-f]+);/gi,function(e,t){return"\\u"+t.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 sa(JSON.parse(e))}catch(e){throw new Error("Invalid string literal")}}function En(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var r={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,t){return String.fromCharCode(parseInt("0"+t,16))}).replace(/\\(.)/g,function(e,t){return r[t]||t})}return new Ln(e)}function An(e){if(no.hasOwnProperty(e)){return no[e]}if(e.match(/^"[\s\S]*"$/)){return Dn(e)}else if(e[0]==="#"){var t=e.match(Jr);if(t){return new RegExp(t[1],t[2])}else if(e.match(rn)){return mn(e)}var r=e.match(/#\\(.+)/);if(r&&Xr(r[1]).length===1){return mn(e)}}if(e.match(/[0-9a-f]|[+-]i/i)){if(e.match(sn)){return vn(e)}else if(e.match(Wr)){return wn(e)}else if(e.match(on)){return dn(e)}else if(e.match(an)){return yn(e)}}if(e.match(/^#[iexobd]/)){throw new Error("Invalid numeric constant: "+e)}return En(e)}function Fn(e){return!(["(",")","[","]"].includes(e)||Jn.names().includes(e))}function xn(e){return Fn(e)&&!(e.match(Jr)||e.match(/^"[\s\S]*"$/)||e.match(sn)||e.match(Wr)||e.match(an)||e.match(on)||e.match(rn)||["#t","#f","nil","true","false"].includes(e))}var Cn=/"(?:\\[\S\s]|[^"])*"?/g;function kn(e){if(typeof e==="string"){var t=/([-\\^$[\]()+{}?*.|])/g;return e.replace(t,"\\$1")}return e}function On(){this.data=[]}On.prototype.push=function(e){this.data.push(e)};On.prototype.top=function(){return this.data[this.data.length-1]};On.prototype.pop=function(){return this.data.pop()};On.prototype.is_empty=function(){return!this.data.length};function Sn(e){if(e instanceof sa){e=e.valueOf()}var t=new Zn(e,{whitespace:true});var r=[];while(true){var n=t.peek(true);if(n===$a){break}r.push(n);t.skip()}return r}function Bn(e){var t=e.token,r=D(e,Er);if(t.match(/^"[\s\S]*"$/)&&t.match(/\n/)){var n=new RegExp("^ {1,"+(e.col+1)+"}","mg");t=t.replace(n,"")}return Br({token:t},r)}function jn(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(){};this.fn=e;this.cont=t}jn.prototype.toString=function(){return"#"};function In(n){return function(){for(var e=arguments.length,t=new Array(e),r=0;r1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof sa){e=e.toString()}if(t){return Sn(e)}else{var r=Sn(e).map(function(e){if(e.token==="#\\ "){return e.token}return e.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return Rn(r)}}function Rn(e){var t=0;var r=null;var n=[];for(var i=0;i0&&arguments[0]!==undefined?arguments[0]:null;if(e instanceof Ln){if(e.is_gensym()){return e}e=e.valueOf()}if(qn(e)){return Ln(e)}if(e!==null){return r(e,Symbol("#:".concat(e)))}t++;return r(t,Symbol("#:g".concat(t)))}}();function Yn(e){var r=this;var n={pending:true,rejected:false,fulfilled:false,reason:undefined,type:undefined};e=e.then(function(e){n.type=Ao(e);n.fulfilled=true;n.pending=false;return e});ai(this,"_promise",e,{hidden:true});if(vu(e["catch"])){e=e["catch"](function(e){n.rejected=true;n.pending=false;n.reason=e})}Object.keys(n).forEach(function(t){Object.defineProperty(r,"__".concat(t,"__"),{enumerable:true,get:function e(){return n[t]}})});ai(this,"__promise__",e);this.then=false}Yn.prototype.then=function(e){return new Yn(this.valueOf().then(e))};Yn.prototype["catch"]=function(e){return new Yn(this.valueOf()["catch"](e))};Yn.prototype.valueOf=function(){if(!this._promise){throw new Error("QuotedPromise: invalid promise created")}return this._promise};Yn.prototype.toString=function(){if(this.__pending__){return Yn.pending_str}if(this.__rejected__){return Yn.rejected_str}return"#")};Yn.pending_str="#";Yn.rejected_str="#";function $n(e){if(Array.isArray(e)){return Promise.all(zn(e)).then(Vn)}return e}function zn(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof Yn){t[r]=new Ha(n)}else{t[r]=n}}return t}function Vn(e){var t=new Array(e.length),r=e.length;while(r--){var n=e[r];if(n instanceof Ha){t[r]=n.valueOf()}else{t[r]=n}}return t}var Jn={LITERAL:Symbol["for"]("literal"),SPLICE:Symbol["for"]("splice"),SYMBOL:Symbol["for"]("symbol"),names:function e(){return Object.keys(this._specials)},type:function e(t){return this.get(t).type},get:function e(t){return this._specials[t]},off:function e(t){var r=this;var n=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(Array.isArray(t)){t.forEach(function(e){return r.off(e,n)})}else if(n===null){delete this._events[t]}else{this._events=this._events.filter(function(e){return e!==n})}},on:function e(t,r){var n=this;if(Array.isArray(t)){t.forEach(function(e){return n.on(e,r)})}else if(!this._events[t]){this._events[t]=[r]}else{this._events[t].push(r)}},trigger:function e(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i",new Ln("quote-promise"),Jn.LITERAL]];Object.defineProperty(Jn,"builtin",{writable:false,value:Qn.map(function(e){return e[0]})});Qn.forEach(function(e){var t=A(e,3),r=t[0],n=t[1],i=t[2];Jn.append(r,n,i)});var Zn=function(){function p(e){var t=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=r.whitespace,i=n===void 0?false:n;y(this,p);ai(this,"__input__",e.replace(/\r/g,""));var u={};["_i","_whitespace","_col","_newline","_line","_state","_next","_token","_prev_char"].forEach(function(r){Object.defineProperty(t,r,{configurable:false,enumerable:false,get:function e(){return u[r]},set:function e(t){u[r]=t}})});this._whitespace=i;this._i=this._line=this._col=this._newline=0;this._state=this._next=this._token=null;this._prev_char=""}b(p,[{key:"get",value:function e(t){return this.__internal[t]}},{key:"set",value:function e(t,r){this.__internal[t]=r}},{key:"token",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(t){var r=this._line;if(this._whitespace&&this._token==="\n"){--r}return{token:this._token,col:this._col,offset:this._i,line:r}}return this._token}},{key:"peek",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(this._i>=this.__input__.length){return $a}if(this._token){return this.token(t)}var r=this.next_token();if(r){this._token=this.__input__.substring(this._i,this._next);return this.token(t)}return $a}},{key:"skip",value:function e(){if(this._next!==null){this._token=null;this._i=this._next}}},{key:"read_line",value:function e(){var t=this.__input__.length;if(this._i>=t){return $a}for(var r=this._i;r=r){return $a}if(t+this._i>=r){return this.read_rest()}var n=this._i+t;var i=this.__input__.substring(this._i,n);var u=i.match(/\n/g);if(u){this._line+=u.length}this._i=n;return i}},{key:"peek_char",value:function e(){if(this._i>=this.__input__.length){return $a}return oa(this.__input__[this._i])}},{key:"read_char",value:function e(){var t=this.peek_char();this.skip_char();return t}},{key:"skip_char",value:function e(){if(this._i1&&arguments[1]!==undefined?arguments[1]:{},n=r.prev_char,i=r["char"],u=r.next_char;var a=A(t,4),o=a[0],s=a[1],c=a[2],f=a[3];if(t.length!==5){throw new Error("Lexer: Invald rule of length ".concat(t.length))}if(!i.match(o)){return false}if(!Kn(s,n)){return false}if(!Kn(c,u)){return false}if(f!==this._state){return false}return true}},{key:"next_token",value:function e(){if(this._i>=this.__input__.length){return false}var t=true;e:for(var r=this._i,n=this.__input__.length;r2&&arguments[2]!==undefined?arguments[2]:null;var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;if(t.length===0){throw new Error("Lexer: invalid literal rule")}if(t.length===1){return[[t,n,i,null,null]]}var u=[];for(var a=0,o=t.length;a1&&arguments[1]!==undefined?arguments[1]:{},r=t.env,n=t.meta,i=n===void 0?false:n,u=t.formatter,a=u===void 0?Bn:u;y(this,o);if(e instanceof sa){e=e.toString()}ai(this,"_formatter",a,{hidden:true});ai(this,"__lexer__",new Zn(e));ai(this,"__env__",r);ai(this,"_meta",i,{hidden:true});ai(this,"_refs",[],{hidden:true});ai(this,"_state",{parentheses:0},{hidden:true})}b(o,[{key:"resolve",value:function e(t){return this.__env__&&this.__env__.get(t,{throwError:false})}},{key:"peek",value:function(){var e=O(j.mark(function e(){var r;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:r=this.__lexer__.peek(true);if(!(r===$a)){t.next=4;break}return t.abrupt("return",$a);case 4:if(!this.is_comment(r.token)){t.next=7;break}this.skip();return t.abrupt("continue",0);case 7:if(!(r.token==="#;")){t.next=14;break}this.skip();if(!(this.__lexer__.peek()===$a)){t.next=11;break}throw new Error("Lexer: syntax error eof found after comment");case 11:t.next=13;return this._read_object();case 13:return t.abrupt("continue",0);case 14:return t.abrupt("break",17);case 17:r=this._formatter(r);if(!this._meta){t.next=20;break}return t.abrupt("return",r);case 20:return t.abrupt("return",r.token);case 21:case"end":return t.stop()}}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"reset",value:function e(){this._refs.length=0}},{key:"skip",value:function e(){this.__lexer__.skip()}},{key:"read",value:function(){var e=O(j.mark(function e(){var r;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:t.next=2;return this.peek();case 2:r=t.sent;this.skip();return t.abrupt("return",r);case 5:case"end":return t.stop()}}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"match_datum_label",value:function e(t){var r=t.match(/^#([0-9]+)=$/);return r&&r[1]}},{key:"match_datum_ref",value:function e(t){var r=t.match(/^#([0-9]+)#$/);return r&&r[1]}},{key:"is_open",value:function e(t){var r=["(","["].includes(t);if(r){this._state.parentheses++}return r}},{key:"is_close",value:function e(t){var r=[")","]"].includes(t);if(r){this._state.parentheses--}return r}},{key:"read_list",value:function(){var e=O(j.mark(function e(){var r,n,i,u;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:r=Pi,n=r;case 1:t.next=4;return this.peek();case 4:i=t.sent;if(!(i===$a)){t.next=7;break}return t.abrupt("break",27);case 7:if(!this.is_close(i)){t.next=10;break}this.skip();return t.abrupt("break",27);case 10:if(!(i==="."&&r!==Pi)){t.next=17;break}this.skip();t.next=14;return this._read_object();case 14:n.cdr=t.sent;t.next=25;break;case 17:t.t0=Ni;t.next=20;return this._read_object();case 20:t.t1=t.sent;t.t2=Pi;u=new t.t0(t.t1,t.t2);if(r===Pi){r=u}else{n.cdr=u}n=u;case 25:t.next=1;break;case 27:return t.abrupt("return",r);case 28:case"end":return t.stop()}}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"read_value",value:function(){var e=O(j.mark(function e(){var r;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:t.next=2;return this.read();case 2:r=t.sent;if(!(r===$a)){t.next=5;break}throw new Error("Parser: Expected token eof found");case 5:return t.abrupt("return",An(r));case 6:case"end":return t.stop()}}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"is_comment",value:function e(t){return t.match(/^;/)||t.match(/^#\|/)&&t.match(/\|#$/)}},{key:"evaluate",value:function e(t){return Io(t,{env:this.__env__,error:function e(t){throw t}})}},{key:"read_object",value:function(){var e=O(j.mark(function e(){var r;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:this.reset();t.next=3;return this._read_object();case 3:r=t.sent;if(r instanceof ei){r=r.valueOf()}if(!this._refs.length){t.next=7;break}return t.abrupt("return",this._resolve_object(r));case 7:return t.abrupt("return",r);case 8:case"end":return t.stop()}}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},{key:"ballanced",value:function e(){return this._state.parentheses===0}},{key:"ballancing_error",value:function e(t){var r=this._state.parentheses;var n=new Error("Parser: expected parenthesis but eof found");var i=new RegExp("\\){".concat(r,"}$"));n.__code__=[t.toString().replace(i,"")];throw n}},{key:"_resolve_object",value:function(){var t=O(j.mark(function e(r){var n=this;var i;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(!Array.isArray(r)){t.next=2;break}return t.abrupt("return",r.map(function(e){return n._resolve_object(e)}));case 2:if(!Li(r)){t.next=6;break}i={};Object.keys(r).forEach(function(e){i[e]=n._resolve_object(r[e])});return t.abrupt("return",i);case 6:if(!(r instanceof Ni)){t.next=8;break}return t.abrupt("return",this._resolve_pair(r));case 8:return t.abrupt("return",r);case 9:case"end":return t.stop()}}},e,this)}));function e(e){return t.apply(this,arguments)}return e}()},{key:"_resolve_pair",value:function(){var t=O(j.mark(function e(r){return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(!(r instanceof Ni)){t.next=15;break}if(!(r.car instanceof ei)){t.next=7;break}t.next=4;return r.car.valueOf();case 4:r.car=t.sent;t.next=8;break;case 7:this._resolve_pair(r.car);case 8:if(!(r.cdr instanceof ei)){t.next=14;break}t.next=11;return r.cdr.valueOf();case 11:r.cdr=t.sent;t.next=15;break;case 14:this._resolve_pair(r.cdr);case 15:return t.abrupt("return",r);case 16:case"end":return t.stop()}}},e,this)}));function e(e){return t.apply(this,arguments)}return e}()},{key:"_read_object",value:function(){var e=O(j.mark(function e(){var r,n,i,u,a,o,s,c,f;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:t.next=2;return this.peek();case 2:r=t.sent;if(!(r===$a)){t.next=5;break}return t.abrupt("return",r);case 5:if(!Gn(r)){t.next=35;break}n=Jn.get(r);i=Hn(r);this.skip();t.next=11;return this._read_object();case 11:a=t.sent;if(i){t.next=22;break}o=this.__env__.get(n.symbol);if(!(typeof o==="function")){t.next=22;break}if(!Wn(r)){t.next=19;break}return t.abrupt("return",o.call(this.__env__,a));case 19:if(!(a instanceof Ni)){t.next=21;break}return t.abrupt("return",o.apply(this.__env__,a.to_array(false)));case 21:throw new Error("Parse Error: Invalid parser extension "+"invocation ".concat(n.symbol));case 22:if(Wn(r)){u=new Ni(n.symbol,new Ni(a,Pi))}else{u=new Ni(n.symbol,a)}if(!i){t.next=25;break}return t.abrupt("return",u);case 25:if(!(o instanceof au)){t.next=34;break}t.next=28;return this.evaluate(u);case 28:s=t.sent;if(!(s instanceof Ni||s instanceof Ln)){t.next=31;break}return t.abrupt("return",Ni.fromArray([Ln("quote"),s]));case 31:return t.abrupt("return",s);case 34:throw new Error("Parse Error: invlid parser extension: "+n.symbol);case 35:c=this.match_datum_ref(r);if(!(c!==null)){t.next=41;break}this.skip();if(!this._refs[c]){t.next=40;break}return t.abrupt("return",new ei(c,this._refs[c]));case 40:throw new Error("Parse Error: invalid datum label #".concat(c,"#"));case 41:f=this.match_datum_label(r);if(!(f!==null)){t.next=48;break}this.skip();this._refs[f]=this._read_object();return t.abrupt("return",this._refs[f]);case 48:if(!this.is_open(r)){t.next=53;break}this.skip();return t.abrupt("return",this.read_list());case 53:return t.abrupt("return",this.read_value());case 54:case"end":return t.stop()}}},e,this)}));function t(){return e.apply(this,arguments)}return t}()}]);return o}();var ei=function(){function r(e,t){y(this,r);this.name=e;this.data=t}b(r,[{key:"valueOf",value:function e(){return this.data}}]);return r}();function ti(e,t){return ri.apply(this,arguments)}function ri(){ri=e(j.mark(function e(r,n){var i,u;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(!n){if(io){n=io.get("**interaction-environment**",{throwError:false})}else{n=uo}}i=new Xn(r,{env:n});case 2:t.next=5;return C(i.read_object());case 5:u=t.sent;if(!i.ballanced()){i.ballancing_error(u)}if(!(u===$a)){t.next=9;break}return t.abrupt("break",13);case 9:t.next=11;return u;case 11:t.next=2;break;case 13:case"end":return t.stop()}}},e)}));return ri.apply(this,arguments)}function ni(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(e){return e};var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;if(gu(e)){var n=e.then(t);if(r===null){return n}else{return n["catch"](r)}}if(e instanceof Array){return ii(e,t,r)}if(Li(e)){return ui(e,t,r)}return t(e)}function ii(t,r,e){if(t.find(gu)){return ni($n(t),function(e){if(Object.isFrozen(t)){Object.freeze(e)}return r(e)},e)}return r(t)}function ui(t,e,r){var i=Object.keys(t);var n=[],u=[];var a=i.length;while(a--){var o=i[a];var s=t[o];n[a]=s;if(gu(s)){u.push(s)}}if(u.length){return ni($n(n),function(e){var n={};e.forEach(function(e,t){var r=i[t];n[r]=e});if(Object.isFrozen(t)){Object.freeze(n)}return n},r)}return e(t)}function ai(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{},i=n.hidden,u=i===void 0?false:i;Object.defineProperty(e,t,{value:r,configurable:true,enumerable:!u})}function oi(r){var n,i,u,a,o,s,c;return j.async(function e(t){while(1){switch(t.prev=t.next){case 0:n=[];i=false;u=false;t.prev=3;o=F(r);case 5:t.next=7;return j.awrap(o.next());case 7:if(!(i=!(s=t.sent).done)){t.next=13;break}c=s.value;n.push(c);case 10:i=false;t.next=5;break;case 13:t.next=19;break;case 15:t.prev=15;t.t0=t["catch"](3);u=true;a=t.t0;case 19:t.prev=19;t.prev=20;if(!(i&&o["return"]!=null)){t.next=24;break}t.next=24;return j.awrap(o["return"]());case 24:t.prev=24;if(!u){t.next=27;break}throw a;case 27:return t.finish(24);case 28:return t.finish(19);case 29:return t.abrupt("return",n);case 30:case"end":return t.stop()}}},null,null,[[3,15,19,29],[20,,24,28]],Promise)}function si(e,t){if(t instanceof RegExp){return function(e){return String(e).match(t)}}else if(vu(t)){return t}throw new Error("Invalid matcher")}function ci(e,t,r,n){if(typeof e!=="string"){t=arguments[0];r=arguments[1];n=arguments[2];e=null}if(r){if(n){t.__doc__=r}else{t.__doc__=fi(r)}}if(e){t.__name__=e}else if(t.name&&!Vu(t)){t.__name__=t.name}return t}function fi(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function li(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var r=e.length;if(t<=0){throw Error("previousSexp: Invalid argument sexp = ".concat(t))}e:while(t--&&r>=0){var n=1;while(n>0){var i=e[--r];if(!i){break e}if(i==="("||i.token==="("){n--}else if(i===")"||i.token===")"){n++}}r--}return e.slice(r+1)}function hi(e){if(!e||!e.length){return 0}var t=e.length;if(e[t-1].token==="\n"){return 0}while(--t){if(e[t].token==="\n"){var r=(e[t+1]||{}).token;if(r){return r.length}}}return 0}function pi(e,t){return f(e,t)===t.length;function f(r,n){function e(e,t){var r=Cr(e),n;try{for(r.s();!(n=r.n()).done;){var i=n.value;var u=f(i,t);if(u!==-1){return u}}}catch(e){r.e(e)}finally{r.f()}return-1}function t(){return r[u]===Symbol["for"]("symbol")&&!xn(n[o])}function i(){var e=r[u+1];var t=n[o+1];if(e!==undefined&&t!==undefined){return f([e],[t])}}var u=0;var a={};for(var o=0;o0){continue}}else if(t()){return-1}}else if(r[u]instanceof Array){var c=f(r[u],n.slice(o));if(c===-1||c+o>n.length){return-1}o+=c-1;u++;continue}else{return-1}u++}if(r.length!==u){return-1}return n.length}}function _i(e){this.__code__=e.replace(/\r/g,"")}_i.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?(?:define(?:-values|-syntax|-macro|-class|-record-type)?|(?:call-with-(?:input-file|output-file|port))|lambda|let-env|try|catch|when|unless|while|syntax-rules|(let|letrec)(-syntax|\*)?)$/],shift:{1:["&","#"]}}};_i.match=pi;_i.prototype._options=function e(t){var r=_i.defaults;if(typeof t==="undefined"){return Object.assign({},r)}var n=t&&t.exceptions||{};var i=n.specials||[];var u=n.shift||{1:[]};return Br(Br(Br({},r),t),{},{exceptions:{specials:[].concat(k(r.exceptions.specials),k(i)),shift:Br(Br({},u),{},{1:[].concat(k(r.exceptions.shift[1]),k(u[1]))})}})};_i.prototype.indent=function e(t){var r=Nn(this.__code__,true);return this._indent(r,t)};_i.exception_shift=function(u,e){function t(e){if(!e.length){return false}if(e.indexOf(u)!==-1){return true}else{var t=e.filter(function(e){return e instanceof RegExp});if(!t.length){return false}var r=Cr(t),n;try{for(r.s();!(n=r.n()).done;){var i=n.value;if(u.match(i)){return true}}}catch(e){r.e(e)}finally{r.f()}}return false}if(t(e.exceptions.specials)){return e.indent}var r=e.exceptions.shift;for(var n=0,i=Object.entries(r);n0){n.offset=0}if(u.toString()===t.toString()&&To(u)){return n.offset+u[0].col}else if(u.length===1){return n.offset+u[0].col+1}else{var s=-1;if(a){var c=_i.exception_shift(a.token,n);if(c!==-1){s=c}}if(s===-1){s=_i.exception_shift(u[1].token,n)}if(s!==-1){return n.offset+u[0].col+s}else if(u[0].line3&&u[1].line===u[3].line){if(u[1].token==="("||u[1].token==="["){return n.offset+u[1].col}return n.offset+u[3].col}else if(u[0].line===u[1].line){return n.offset+n.indent+u[0].col}else{var f=u.slice(2);for(var l=0;l")};di.prototype.match=function(e){return e.match(this.pattern)};function vi(){for(var e=arguments.length,t=new Array(e),r=0;r")};_i.Pattern=vi;_i.Ahead=di;var mi=/^[[(]$/;var yi=/^[\])]$/;var gi=/[^()[\]]/;var bi=new di(/[^)\]]/);var wi=Symbol["for"]("*");var Di=new vi([mi,wi,yi],[gi],"+");var Ei=new vi([mi,wi,yi],"+");var Ai=new vi([Symbol["for"]("symbol")],"?");var Fi=new vi([Symbol["for"]("symbol")],"*");var xi=[mi,Fi,yi];var Ci=new vi([mi,Symbol["for"]("symbol"),wi,yi],"+");var ki=Bi("define","lambda","define-macro","syntax-rules");var Oi=/^(?!.*\b(?:[()[\]]|define(?:-macro)?|let(?:\*|rec|-env|-syntax|)?|lambda|syntax-rules)\b).*$/;var Si=/^(?:#:)?(let(?:\*|rec|-env|-syntax)?)$/;function Bi(){for(var e=arguments.length,t=new Array(e),r=0;r0&&!o[e]){o[e]=li(a,e)}});var s=Cr(i),c;try{for(s.s();!(c=s.n()).done;){var f=A(c.value,3),l=f[0],h=f[1],p=f[2];h=h.valueOf();var _=h>0?o[h]:a;var d=_.filter(function(e){return e.trim()&&!Gn(e)});var v=r(_);var m=pi(l,d);var y=n.slice(u).find(function(e){return e.trim()&&!Gn(e)});if(m&&(p instanceof di&&p.match(y)||!p)){var g=u-v;if(n[g]!=="\n"){if(!n[g].trim()){n[g]="\n"}else{n.splice(g,0,"\n");u++}}u+=v;continue e}}}catch(e){s.e(e)}finally{s.f()}}this.__code__=n.join("");return this};_i.prototype._spaces=function(e){return new Array(e+1).join(" ")};_i.prototype.format=function e(t){var r=this.__code__.replace(/[ \t]*\n[ \t]*/g,"\n ");var n=Nn(r,true);var i=this._options(t);var u=0;var a=0;for(var o=0;o0&&arguments[0]!==undefined?arguments[0]:true;var n=new Map;function i(e){if(e instanceof Ni){if(n.has(e)){return n.get(e)}var t=new Ni;n.set(e,t);if(r){t.car=i(e.car)}else{t.car=e.car}t.cdr=i(e.cdr);t[Ru]=e[Ru];return t}return e}return i(this)};Ni.prototype.last_pair=function(){var e=this;while(true){if(e.cdr===Pi){return e}e=e.cdr}};Ni.prototype.to_array=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var t=[];if(this.car instanceof Ni){if(e){t.push(this.car.to_array())}else{t.push(this.car)}}else{t.push(this.car.valueOf())}if(this.cdr instanceof Ni){t=t.concat(this.cdr.to_array())}return t};Ni.fromArray=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(e instanceof Ni||r&&e instanceof Array&&e[Pu]){return e}if(t===false){var n=Pi;for(var i=e.length;i--;){n=new Ni(e[i],n)}return n}if(e.length&&!(e instanceof Array)){e=k(e)}var u=Pi;var a=e.length;while(a--){var o=e[a];if(o instanceof Array){o=Ni.fromArray(o,t,r)}else if(typeof o==="string"){o=sa(o)}else if(typeof o==="number"&&!Number.isNaN(o)){o=da(o)}u=new Ni(o,u)}return u};Ni.prototype.to_object=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var t=this;var r={};while(true){if(t instanceof Ni&&t.car instanceof Ni){var n=t.car;var i=n.car;if(i instanceof Ln){i=i.__name__}if(i instanceof sa){i=i.valueOf()}var u=n.cdr;if(u instanceof Ni){u=u.to_object(e)}if(bo(u)){if(!e){u=u.valueOf()}}r[i]=u;t=t.cdr}else{break}}return r};Ni.fromPairs=function(e){return e.reduce(function(e,t){return new Ni(new Ni(new Ln(t[0]),t[1]),e)},Pi)};Ni.fromObject=function(t){var e=Object.keys(t).map(function(e){return[e,t[e]]});return Ni.fromPairs(e)};Ni.prototype.reduce=function(e){var t=this;var r=Pi;while(true){if(t!==Pi){r=e(r,t.car);t=t.cdr}else{break}}return r};Ni.prototype.reverse=function(){if(this.haveCycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var t=Pi;while(e!==Pi){var r=e.cdr;e.cdr=t;t=e;e=r}return t};Ni.prototype.transform=function(n){function i(e){if(e instanceof Ni){if(e.replace){delete e.replace;return e}var t=n(e.car);if(t instanceof Ni){t=i(t)}var r=n(e.cdr);if(r instanceof Ni){r=i(r)}return new Ni(t,r)}return e}return i(this)};Ni.prototype.map=function(e){if(typeof this.car!=="undefined"){return new Ni(e(this.car),this.cdr===Pi?Pi:this.cdr.map(e))}else{return Pi}};var Ti=new Map;function Li(e){return e&&_(e)==="object"&&e.constructor===Object}var Ui=Object.getOwnPropertyNames(Array.prototype);var qi=[];Ui.forEach(function(e){qi.push(Array[e],Array.prototype[e])});function Mi(e){e=Fu(e);return qi.includes(e)}function Yi(e){return vu(e)&&(Vu(e)||e.__doc__)}function $i(r){var e=r.constructor||Object;var n=Li(r);var i=vu(r[Symbol.asyncIterator])||vu(r[Symbol.iterator]);var u;if(Ti.has(e)){u=Ti.get(e)}else{Ti.forEach(function(e,t){t=Fu(t);if(r.constructor===t&&(t===Object&&n&&!i||t!==Object)){u=e}})}return u}var zi=new Map;[[true,"#t"],[false,"#f"],[null,"null"],[undefined,"#"]].forEach(function(e){var t=A(e,2),r=t[0],n=t[1];zi.set(r,n)});function Vi(r){if(r&&_(r)==="object"){var n={};var e=Object.getOwnPropertySymbols(r);e.forEach(function(e){var t=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");n[t]=Zi(r[e])});var t=Object.getOwnPropertyNames(r);t.forEach(function(e){var t=r[e];if(t&&_(t)==="object"&&t.constructor===Object){n[e]=Vi(t)}else{n[e]=Zi(t)}});return n}return r}function Ji(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function Gi(e,t){return e.hasOwnProperty(t)&&vu(e.toString)}function Hi(e){if(Hu(e)){return"#"}var t=e.prototype&&e.prototype.constructor;if(vu(t)&&Vu(t)){if(e[Tu]&&t.hasOwnProperty("__name__")){var r=t.__name__;if(sa.isString(r)){r=r.toString();return"#")}return"#"}}if(e.hasOwnProperty("__name__")){var n=e.__name__;if(_(n)==="symbol"){n=Un(n)}if(typeof n==="string"){return"#")}}if(Gi(e,"toString")){return e.toString()}else if(e.name&&!Vu(e)){return"#")}else{return"#"}}var Wi=new Map;[[Error,function(e){return e.message}],[Ni,function(e,t){var r=t.quote,n=t.skip_cycles,i=t.pair_args;if(!n){e.markCycles()}return e.toString.apply(e,[r].concat(k(i)))}],[oa,function(e,t){var r=t.quote;if(r){return e.toString()}return e.valueOf()}],[sa,function(e,t){var r=t.quote;e=e.toString();if(r){return JSON.stringify(e).replace(/\\n/g,"\n")}return e}],[RegExp,function(e){return"#"+e.toString()}]].forEach(function(e){var t=A(e,2),r=t[0],n=t[1];Wi.set(r,n)});var Qi=[Ln,da,au,Wa,Sa,Ba,Ga,Yn];function Zi(e,t,r){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(zi.has(e)){return zi.get(e)}if(Ki(e)){return"#"}if(e){var n=e.constructor;if(Wi.has(n)){for(var i=arguments.length,u=new Array(i>3?i-3:0),a=3;a"}if(e===null){return"null"}if(_(e)==="object"){var f=e.constructor;if(!f){f=Object}var l;if(typeof f.__class__==="string"){l=f.__class__}else{var h=$i(e);if(h){if(vu(h)){return h(e,t)}else{throw new Error("toString: Invalid repr value")}}l=f.name}if(vu(e.toString)&&Vu(e.toString)){return e.toString().valueOf()}if(Ao(e)==="instance"){if(Vu(f)&&f.__name__){l=f.__name__.valueOf()}else if(!Hu(f)){l="instance"}}if(Do(e,Symbol.iterator)){if(l){return"#")}return"#"}if(Do(e,Symbol.asyncIterator)){if(l){return"#")}return"#"}if(l!==""){return"#<"+l+">"}return"#"}if(typeof e!=="string"){return e.toString()}return e}function Ki(e){return e&&_(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}Ni.prototype.markCycles=function(){Xi(this);return this};Ni.prototype.haveCycles=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(!e){return this.haveCycles("car")||this.haveCycles("cdr")}return!!(this[Ru]&&this[Ru][e])};function Xi(e){var t=[];var i=[];var u=[];function a(e){if(!t.includes(e)){t.push(e)}}function o(e,t,r,n){if(r instanceof Ni){if(n.includes(r)){if(!u.includes(r)){u.push(r)}if(!e[Ru]){e[Ru]={}}e[Ru][t]=r;if(!i.includes(e)){i.push(e)}return true}}}var s=In(function e(t,r){if(t instanceof Ni){delete t.ref;delete t[Ru];a(t);r.push(t);var n=o(t,"car",t.car,r);var i=o(t,"cdr",t.cdr,r);if(!n){s(t.car,r.slice())}if(!i){return new jn(function(){return e(t.cdr,r.slice())})}}});function r(e,t){if(e[Ru][t]instanceof Ni){var r=n.indexOf(e[Ru][t]);e[Ru][t]="#".concat(r,"#")}}s(e,[]);var n=t.filter(function(e){return u.includes(e)});n.forEach(function(e,t){e[Nu]="#".concat(t,"=")});i.forEach(function(e){r(e,"car");r(e,"cdr")})}Ni.prototype.toString=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.nested,n=r===void 0?false:r;var i=[];if(this[Nu]){i.push(this[Nu]+"(")}else if(!n){i.push("(")}var u;if(this[Ru]&&this[Ru].car){u=this[Ru].car}else{u=Zi(this.car,e,true)}if(u!==undefined){i.push(u)}if(this.cdr instanceof Ni){if(this[Ru]&&this[Ru].cdr){i.push(" . ");i.push(this[Ru].cdr)}else{if(this.cdr[Nu]){i.push(" . ")}else{i.push(" ")}var a=this.cdr.toString(e,{nested:true});i.push(a)}}else if(this.cdr!==Pi){i=i.concat([" . ",Zi(this.cdr,e,true)])}if(!n||this[Nu]){i.push(")")}return i.join("")};Ni.prototype.set=function(e,t){this[e]=t;if(t instanceof Ni){this.markCycles()}};Ni.prototype.append=function(e){if(e instanceof Array){return this.append(Ni.fromArray(e))}var t=this;if(t.car===undefined){if(e instanceof Ni){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(e!==Pi){while(true){if(t instanceof Ni&&t.cdr!==Pi){t=t.cdr}else{break}}t.cdr=e}return this};Ni.prototype.serialize=function(){return[this.car,this.cdr]};Ni.prototype[Symbol.iterator]=function(){var r=this;return{next:function e(){var t=r;r=t.cdr;if(t===Pi){return{value:undefined,done:true}}else{return{value:t.car,done:false}}}}};function eu(e){return e<0?-e:e}function tu(e,t){var r=h(t),n=r[0],i=r.slice(1);while(i.length>0){var u=i,a=A(u,1),o=a[0];if(!e(n,o)){return false}var s=i;var c=h(s);n=c[0];i=c.slice(1)}return true}function ru(e,t){if(vu(e)){return vu(t)&&Fu(e)===Fu(t)}else if(e instanceof da){if(!(t instanceof da)){return false}var r;if(e.__type__===t.__type__){if(e.__type__==="complex"){r=e.__im__.__type__===t.__im__.__type__&&e.__re__.__type__===t.__re__.__type__}else{r=true}if(r&&e.cmp(t)===0){if(e.valueOf()===0){return Object.is(e.valueOf(),t.valueOf())}return true}}return false}else if(typeof e==="number"){if(typeof t!=="number"){return false}if(Number.isNaN(e)){return Number.isNaN(t)}if(e===Number.NEGATIVE_INFINITY){return t===Number.NEGATIVE_INFINITY}if(e===Number.POSITIVE_INFINITY){return t===Number.POSITIVE_INFINITY}return ru(da(e),da(t))}else if(e instanceof oa){if(!(t instanceof oa)){return false}return e.__char__===t.__char__}else{return e===t}}function nu(e,t){if(Ao(e)!==Ao(t)){return false}if(!iu(e)){return false}if(e instanceof RegExp){return e.source===t.source}if(e instanceof sa){return e.valueOf()===t.valueOf()}return ru(e,t)}function iu(e){return e instanceof Ln||sa.isString(e)||e===Pi||e===null||e instanceof oa||e instanceof da||e===true||e===false}var uu=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e===0){return 0}else if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function au(e,t,r,n){if(typeof this!=="undefined"&&this.constructor!==au||typeof this==="undefined"){return new au(e,t)}yo("Macro",e,"string",1);yo("Macro",t,"function",2);if(r){if(n){this.__doc__=r}else{this.__doc__=fi(r)}}this.__name__=e;this.__fn__=t}au.defmacro=function(e,t,r,n){var i=new au(e,t,r,n);i.__defmacro__=true;return i};au.prototype.invoke=function(e,t,r){var n=t.env,i=t.dynamic_scope,u=t.error;var a={dynamic_scope:i,error:u,macro_expand:r};var o=this.__fn__.call(n,e,a,this.__name__);return o};au.prototype.toString=function(){return"#")};var ou="define-macro";var su=-1e4;function cu(c){return function(){var r=O(j.mark(function e(r,y){var u,g,n,i,a,b,w,D,E,A,F,x,o,C,s;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:s=function e(){s=O(j.mark(function e(r,n,i){var u,a,o,s,c,f,l,h,p,_,d,v,m;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(!(r instanceof Ni&&r.car instanceof Ln)){t.next=50;break}if(!r[Pu]){t.next=3;break}return t.abrupt("return",r);case 3:u=r.car.valueOf();a=i.get(r.car,{throwError:false});o=b(r.car);s=o||w(a,r)||D(a);if(!(s&&r.cdr.car instanceof Ni)){t.next=28;break}if(!o){t.next=15;break}g=A(r.cdr.car);t.next=12;return x(r.cdr.car,n);case 12:c=t.sent;t.next=17;break;case 15:g=E(r.cdr.car);c=r.cdr.car;case 17:t.t0=Ni;t.t1=r.car;t.t2=Ni;t.t3=c;t.next=23;return C(r.cdr.cdr,n,i);case 23:t.t4=t.sent;t.t5=new t.t2(t.t3,t.t4);return t.abrupt("return",new t.t0(t.t1,t.t5));case 28:if(!F(u,a)){t.next=50;break}f=a instanceof fu?r:r.cdr;t.next=32;return a.invoke(f,Br(Br({},y),{},{env:i}),true);case 32:l=t.sent;if(!(a instanceof fu)){t.next=41;break}h=l,p=h.expr,_=h.scope;if(!(p instanceof Ni)){t.next=40;break}if(!(n!==-1&&n<=1||n")}return"#"};fu.className="syntax";var lu=function(e){u(r,e);var t=Fr(r);function r(){y(this,r);return t.apply(this,arguments)}return r}(fu);fu.Parameter=lu;function hu(e,t,w,D){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:{};var E={"...":{symbols:{},lists:[]},symbols:{}};var A=r.expansion,F=r.define;function x(e){if(Mr()){console.log(e)}}x(w);function C(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:false;x({code:t&&Zi(t,true),pattern:e&&Zi(e,true)});if(iu(e)&&!(e instanceof Ln)){return nu(e,t)}if(e instanceof Ln&&w.includes(e.literal())){var i=A.ref(t);if(Ln.is(t,e)){if(typeof i==="undefined"){return true}return i===F||i===io}return false}if(e instanceof Ni&&e.car instanceof Ni&&e.car.cdr instanceof Ni&&Ln.is(e.car.cdr.car,D)){x(">> 0");if(t===Pi){x({pattern:e.toString()});if(e.car.car instanceof Ln){if(e.car.cdr instanceof Ni&&Ln.is(e.car.cdr.car,D)){var u=e.car.car.valueOf();var a=e.last_pair();if(Ln.is(a.car,D)){E["..."].symbols[u]=null;return true}else{return false}}var o=e.car.car.valueOf();if(E["..."].symbols[o]){throw new Error("syntax: named ellipsis can only "+"appear onces")}E["..."].symbols[o]=t}}}if(e instanceof Ni&&e.cdr instanceof Ni&&Ln.is(e.cdr.car,D)){if(e.cdr.cdr!==Pi){if(e.cdr.cdr instanceof Ni){var s=e.cdr.cdr.length();var c=t.length();var f=t;while(c-1>s){f=f.cdr;c--}var l=f.cdr;f.cdr=Pi;if(!C(e.cdr.cdr,l,r,n)){return false}}}if(e.car instanceof Ln){var h=e.car.__name__;if(E["..."].symbols[h]&&!r.includes(h)&&!n){throw new Error("syntax: named ellipsis can only appear onces")}x(">> 1");if(t===Pi){x(">> 2");if(n){x("NIL");E["..."].symbols[h]=Pi}else{x("NULL");E["..."].symbols[h]=null}}else if(t instanceof Ni&&(t.car instanceof Ni||t.car===Pi)){x(">> 3 "+n);if(n){if(E["..."].symbols[h]){var p=E["..."].symbols[h];if(p===Pi){p=new Ni(Pi,new Ni(t,Pi))}else{p=p.append(new Ni(t,Pi))}E["..."].symbols[h]=p}else{E["..."].symbols[h]=new Ni(t,Pi)}}else{x(">> 4");E["..."].symbols[h]=new Ni(t,Pi)}}else{x(">> 6");if(t instanceof Ni){x(">> 7 "+n);r.push(h);if(!E["..."].symbols[h]){E["..."].symbols[h]=new Ni(t,Pi)}else{var _=E["..."].symbols[h];E["..."].symbols[h]=_.append(new Ni(t,Pi))}x({IIIIII:E["..."].symbols[h].toString()})}else{x(">> 8");return false}}return true}else if(e.car instanceof Ni){var d=k(r);if(t===Pi){x(">> 9");E["..."].lists.push(Pi);return true}x(">> 10");var v=t;while(v instanceof Ni){if(!C(e.car,v.car,d,true)){return false}v=v.cdr}return true}return false}if(e instanceof Ln){if(Ln.is(e,D)){throw new Error("syntax: invalid usage of ellipsis")}x(">> 11");var m=e.__name__;if(w.includes(m)){return true}x({name:m,ellipsis:n});if(n){E["..."].symbols[m]=E["..."].symbols[m]||[];E["..."].symbols[m].push(t)}E.symbols[m]=t;if(!E.symbols[m]);return true}if(e instanceof Ni&&t instanceof Ni){x(">> 12");x({a:12,code:t&&t.toString(),pattern:e.toString()});if(t.cdr===Pi){var y=e.car instanceof Ln&&e.cdr instanceof Ln;if(y){if(!C(e.car,t.car,r,n)){return false}x(">> 12 | 1");var g=e.cdr.valueOf();if(!(g in E.symbols)){E.symbols[g]=Pi}g=e.car.valueOf();if(!(g in E.symbols)){E.symbols[g]=t.car}return true}}x({pattern:e.toString(),code:t.toString()});if(e.cdr instanceof Ni&&e.car instanceof Ln&&e.cdr.cdr instanceof Ni&&e.cdr.car instanceof Ln&&Ln.is(e.cdr.cdr.car,D)&&e.cdr.cdr.cdr instanceof Ni&&!Ln.is(e.cdr.cdr.cdr.car,D)&&C(e.car,t.car,r,n)&&C(e.cdr.cdr.cdr,t.cdr,r,n)){var b=e.cdr.car.__name__;x({pattern:e.car.toString(),code:t.car.toString(),name:b});if(w.includes(b)){return true}E["..."].symbols[b]=null;return true}x("recur");if(C(e.car,t.car,r,n)&&C(e.cdr,t.cdr,r,n)){return true}}else if(e===Pi&&(t===Pi||t===undefined)){return true}else if(e.car instanceof Ni&&Ln.is(e.car.car,D)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(C(e,t)){return E}}function pu(e,i){function u(t){if(t instanceof Ni){if(!i.length){return t}var e=u(t.car);var r=u(t.cdr);return new Ni(e,r)}else if(t instanceof Ln){var n=i.find(function(e){return e.gensym===t});if(n){return Ln(n.name)}return t}else{return t}}return u(e)}function _u(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var O=e.bindings,t=e.expr,S=e.scope,a=e.symbols,c=e.names,B=e.ellipsis;var f={};function o(e){if(e instanceof Ln){return true}return["string","symbol"].includes(_(e))}function j(e){if(!o(e)){var t=Ao(e);throw new Error("syntax: internal error, need symbol got ".concat(t))}var r=e.valueOf();if(r===B){throw new Error("syntax: internal error, ellipis not transformed")}var n=_(r);if(["string","symbol"].includes(n)){if(r in O.symbols){return O.symbols[r]}else if(n==="string"&&r.match(/\./)){var i=r.split(".");var u=i[0];if(u in O.symbols){return Ni.fromArray([Ln("."),O.symbols[u]].concat(i.slice(1).map(function(e){return sa(e)})))}}}if(a.includes(r)){return Ln(r)}return s(r)}function I(e){if(Mr()){console.log(e)}}function s(e){if(!f[e]){var t=S.ref(e);var r=Mn(e);if(t){var n=S.get(e);S.set(r,n)}else{var i=S.get(e,{throwError:false});if(typeof i!=="undefined"){S.set(r,i)}}c.push({name:e,gensym:r});f[e]=r;if(typeof e==="string"&&e.match(/\./)){var u=e.split(".").filter(Boolean),a=h(u),o=a[0],s=a.slice(1);if(f[o]){$u(r,"__object__",[f[o]].concat(k(s)))}}}return f[e]}function P(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:function(){};var i=r.nested;I(" ==> "+e.toString(true));I(t);if(e instanceof Ln){var u=e.valueOf();I("[t 1");if(t[u]){if(t[u]instanceof Ni){var a=t[u],o=a.car,s=a.cdr;if(i){var c=o.car,f=o.cdr;if(f!==Pi){n(u,new Ni(f,Pi))}return c}if(s!==Pi){n(u,s)}return o}else if(t[u]instanceof Array){n(u,t[u].slice(1));return t[u][0]}}return j(u)}if(e instanceof Ni){if(e.car instanceof Ln&&e.cdr instanceof Ni&&Ln.is(e.cdr.car,B)){I("[t 2");var l=e.car.valueOf();var h=t[l];I({expr:e.toString(true),name:l,bindings:t,item:h});if(h===null){return}else if(h){I({b:t[l].toString()});if(h instanceof Ni){I("[t 2 Pair "+i);I({______:h.toString()});var p=h.car,_=h.cdr;if(i){if(_!==Pi){I("|| next 1");n(l,_)}I({car:p.toString()});return p}else{if(p.cdr!==Pi){I("|| next 2");n(l,new Ni(p.cdr,_))}I({car:p.car.toString()});return p.car}}else if(h instanceof Array){I("[t 2 Array "+i);if(i){n(l,h.slice(1));return Ni.fromArray(h)}else{var d=h.slice(1);if(d.length){n(l,d)}return h[0]}}else{return h}}}I("[t 3 recur "+e.toString());var v=P(e.car,t,r,n);var m=P(e.cdr,t,r,n);return new Ni(v,m)}return e}function N(t,r){var e=Object.values(t);var n=Object.getOwnPropertySymbols(t);if(n.length){e.push.apply(e,k(n.map(function(e){return t[e]})))}return e.length&&e.every(function(e){if(e===null){return!r}return e instanceof Ni||e===Pi||e instanceof Array&&e.length})}function R(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function T(i){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},t=e.disabled;I("traverse>> "+i.toString());if(i instanceof Ni){if(!t&&i.car instanceof Ni&&Ln.is(i.car.car,B)){return T(i.car.cdr,{disabled:true})}if(i.cdr instanceof Ni&&Ln.is(i.cdr.car,B)&&!t){I(">> 1");var r=O["..."].symbols;var n=Object.values(r);if(n.length&&n.every(function(e){return e===null})){return T(i.cdr.cdr,{disabled:t})}var u=R(r);var a=i.car instanceof Ln&&Ln.is(i.cdr.cdr.car,B);if(i.car instanceof Ni||a){if(O["..."].lists[0]===Pi){return Pi}var o=i.car;if(a){o=new Ni(i.car,new Ni(i.cdr.car,Pi))}I(">> 2");var s;if(u.length){I(">> 2 (a)");var c=Br({},r);s=Pi;var f=function e(){if(!N(c)){return"break"}var n={};var t=function e(t,r){n[t]=r};var r=P(o,c,{nested:true},t);if(r!==undefined){if(a){if(s===Pi){s=r}else{s=s.append(r)}}else{s=new Ni(r,s)}}c=n};while(true){var l=f();if(l==="break")break}if(s!==Pi&&!a){s=s.reverse()}if(i.cdr.cdr!==Pi&&!Ln.is(i.cdr.cdr.car,B)){var h=T(i.cdr.cdr,{disabled:t});return s.append(h)}return s}else{I(">> 3");var p=P(i.car,r,{nested:true});if(p){return new Ni(p,Pi)}return Pi}}else if(i.car instanceof Ln){I(">> 4");if(Ln.is(i.cdr.cdr.car,B)){I(">> 4 (a)")}else{I(">> 4 (b)")}var _=i.car.__name__;var d=L({},_,r[_]);var v=r[_]===null;var m=Pi;var y=function e(){if(!N(d,true)){I({bind:d});return"break"}var n={};var t=function e(t,r){n[t]=r};var r=P(i,d,{nested:false},t);I({value:r.toString()});if(typeof r!=="undefined"){m=new Ni(r,m)}d=n};while(true){var g=y();if(g==="break")break}if(m!==Pi){m=m.reverse()}if(i.cdr instanceof Ni){if(i.cdr.cdr instanceof Ni||i.cdr.cdr instanceof Ln){var b=T(i.cdr.cdr,{disabled:t});if(v){return b}I("<<<< 1");m.append(b)}}I("<<<< 2");return m}}var w=T(i.car,{disabled:t});var D;var E;if(i.car instanceof Ln){var A=S.get(i.car,{throwError:false});E=A instanceof au&&A.__name__==="syntax-rules"}if(E){if(i.cdr.car instanceof Ln){D=new Ni(T(i.cdr.car,{disabled:t}),new Ni(i.cdr.cdr.car,T(i.cdr.cdr.cdr,{disabled:t})))}else{D=new Ni(i.cdr.car,T(i.cdr.cdr,{disabled:t}))}I("REST >>>> "+D.toString())}else{D=T(i.cdr,{disabled:t})}I({a:true,car:Zi(i.car),cdr:Zi(i.cdr),head:Zi(w),rest:Zi(D)});return new Ni(w,D)}if(i instanceof Ln){if(t&&Ln.is(i,B)){return i}var F=Object.keys(O["..."].symbols);var x=i.literal();if(F.includes(x)){var C="missing ellipsis symbol next to name `".concat(x,"'");throw new Error("syntax-rules: ".concat(C))}var k=j(i);if(typeof k!=="undefined"){return k}}return i}return T(t,{})}function du(e){return bu(e)||e===Pi||e===null}function vu(e){return typeof e==="function"&&typeof e.bind==="function"}function mu(e){return e instanceof Bo}function yu(e){return vu(e)||mu(e)}function gu(e){if(e instanceof Yn){return false}if(e instanceof Promise){return true}return e&&vu(e.then)}function bu(e){return typeof e==="undefined"}function wu(e){switch(_(e)){case"string":return sa(e);case"bigint":return da(e);case"number":if(Number.isNaN(e)){return ro}else{return da(e)}}return e}function Du(n,i){var e=Object.getOwnPropertyNames(n);var t=Object.getOwnPropertySymbols(n);e.concat(t).forEach(function(e){var t=i(n[e]);var r=Object.getOwnPropertyDescriptor(n,e);if(!r||r.writable&&n[e]!==t){n[e]=t}});return n}function Eu(t){var e=[sa,oa,da].some(function(e){return t instanceof e});if(e){return t.valueOf()}if(t instanceof Array){return t.map(Eu)}if(t instanceof Yn){delete t.then}if(Li(t)){return Du(t,Eu)}return t}function Au(e,t){if(e instanceof Ni){e.markCycles();return Qa(e)}if(vu(e)){if(t){return xu(e,t)}}return wu(e)}function Fu(e){if(ku(e)){return e[Iu]}return e}function xu(e,t){if(e[Symbol["for"]("__bound__")]){return e}var r=e.bind(t);var n=Object.getOwnPropertyNames(e);var i=Cr(n),u;try{for(i.s();!(u=i.n()).done;){var a=u.value;if(Yu(a)){try{r[a]=e[a]}catch(e){}}}}catch(e){i.e(e)}finally{i.f()}$u(r,"__fn__",e);$u(r,"__context__",t);$u(r,"__bound__",true);if(Hu(e)){$u(r,"__native__",true)}if(Li(t)&&Vu(e)){$u(r,"__method__",true)}r.valueOf=function(){return e};return r}function Cu(e){return ku(e)&&e[Symbol["for"]("__context__")]===Object}function ku(e){return!!(vu(e)&&e[Iu])}function Ou(e){if(vu(e)){var t=e[ju];if(t&&(t===ps||t.constructor&&t.constructor.__class__)){return true}}return false}function Su(e){return e instanceof Sa||e instanceof Ba}function Bu(e){if(vu(e)){if(Su(e[ju])){return true}}return false}var ju=Symbol["for"]("__context__");var Iu=Symbol["for"]("__fn__");var Pu=Symbol["for"]("__data__");var Nu=Symbol["for"]("__ref__");var Ru=Symbol["for"]("__cycles__");var Tu=Symbol["for"]("__class__");var Lu=Symbol["for"]("__method__");var Uu=Symbol["for"]("__prototype__");var qu=Symbol["for"]("__lambda__");var Mu=["name","length","caller","callee","arguments","prototype"];function Yu(e){return!Mu.includes(e)}function $u(e,t,r){Object.defineProperty(e,Symbol["for"](t),{get:function e(){return r},set:function e(){},configurable:false,enumerable:false})}function zu(t,r){try{Object.defineProperty(t,"length",{get:function e(){return r}});return t}catch(e){var n=new Array(r).fill(0).map(function(e,t){return"a"+t}).join(",");var i=new Function("f","return function(".concat(n,") {\n return f.apply(this, arguments);\n };"));return i(t)}}function Vu(e){return e&&e[qu]}function Ju(e){return e&&e[Lu]}function Gu(e){return Vu(e)&&!e[Uu]&&!Ju(e)&&!Bu(e)}function Hu(e){var t=Symbol["for"]("__native__");return vu(e)&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[t]===true||!e.name.match(/^bound /)&&!e[t])}function Wu(e){var g;switch(e){case Symbol["for"]("letrec"):g="letrec";break;case Symbol["for"]("let"):g="let";break;case Symbol["for"]("let*"):g="let*";break;default:throw new Error("Invalid let_macro value")}return au.defmacro(g,function(t,e){var f=e.dynamic_scope,l=e.error,r=e.macro_expand;var h;if(t.car instanceof Ln){if(!(t.cdr.car instanceof Ni||t.cdr.car===Pi)){throw new Error("let require list of pairs")}var n;if(t.cdr.car===Pi){h=Pi;n=Pi}else{n=t.cdr.car.map(function(e){return e.car});h=t.cdr.car.map(function(e){return e.cdr.car})}return Ni.fromArray([Ln("letrec"),[[t.car,Ni(Ln("lambda"),Ni(n,t.cdr.cdr))]],Ni(t.car,h)])}else if(r){return}var p=this;h=io.get("list->array")(t.car);var _=p.inherit(g);var d,v;if(g==="let*"){v=_}else if(g==="let"){d=[]}var m=0;function y(){var e=new Ni(new Ln("begin"),t.cdr);return Io(e,{env:_,dynamic_scope:f,error:l})}return function t(){var r=h[m++];if(f){f=g==="let*"?_:p}if(!r){if(d&&d.length){var e=d.map(function(e){return e.value});var n=e.filter(gu);if(n.length){return $n(e).then(function(e){for(var t=0,r=e.length;t1&&arguments[1]!==undefined?arguments[1]:{},r=t.dynamic_scope,n=t.error;var i=this;if(r){r=this}var u=e;var a=[];while(u instanceof Ni){a.push(Io(u.car,{env:i,dynamic_scope:r,error:n}));u=u.cdr}var o=a.filter(gu).length;if(o){return $n(a).then(s.bind(this))}else{return s.call(this,a)}})}function Zu(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n2?n-2:0),u=2;u1&&arguments[1]!==undefined?arguments[1]:null;return function(){for(var e=arguments.length,t=new Array(e),r=0;r1?e-1:0),r=1;r=a){return u.apply(this,n)}else{return i}}return i.apply(this,arguments)}}function aa(n,i){yo("limit",i,"function",2);return function(){for(var e=arguments.length,t=new Array(e),r=0;r1){e=e.toLowerCase();if(oa.__names__[e]){t=e;e=oa.__names__[e]}else{throw new Error("Internal: Unknown named character")}}else{t=oa.__rev_names__[e]}Object.defineProperty(this,"__char__",{value:e,enumerable:true});if(t){Object.defineProperty(this,"__name__",{value:t,enumerable:true})}}oa.__names__=Kr;oa.__rev_names__={};Object.keys(oa.__names__).forEach(function(e){var t=oa.__names__[e];oa.__rev_names__[t]=e});oa.prototype.toUpperCase=function(){return oa(this.__char__.toUpperCase())};oa.prototype.toLowerCase=function(){return oa(this.__char__.toLowerCase())};oa.prototype.toString=function(){return"#\\"+(this.__name__||this.__char__)};oa.prototype.valueOf=oa.prototype.serialize=function(){return this.__char__};function sa(e){if(typeof this!=="undefined"&&!(this instanceof sa)||typeof this==="undefined"){return new sa(e)}if(e instanceof Array){this.__string__=e.map(function(e,t){yo("LString",e,"character",t+1);return e.toString()}).join("")}else{this.__string__=e.valueOf()}}{var ca=["length","constructor"];var fa=Object.getOwnPropertyNames(String.prototype).filter(function(e){return!ca.includes(e)});var la=function e(n){return function(){for(var e=arguments.length,t=new Array(e),r=0;r0){r.push(this.__string__.substring(0,e))}r.push(t);if(e1&&arguments[1]!==undefined?arguments[1]:false;if(e instanceof da){return e}if(typeof this!=="undefined"&&!(this instanceof da)||typeof this==="undefined"){return new da(e,t)}if(typeof e==="undefined"){throw new Error("Invalid LNumber constructor call")}var r=da.getType(e);if(da.types[r]){return da.types[r](e,t)}var n=e instanceof Array&&sa.isString(e[0])&&da.isNumber(e[1]);if(e instanceof da){return da(e.value)}if(!da.isNumber(e)&&!n){throw new Error("You can't create LNumber from ".concat(Ao(e)))}if(e===null){e=0}var i;if(n){var u=e,a=A(u,2),o=a[0],s=a[1];if(o instanceof sa){o=o.valueOf()}if(s instanceof da){s=s.valueOf()}var c=o.match(/^([+-])/);var f=false;if(c){o=o.replace(/^[+-]/,"");if(c[1]==="-"){f=true}}}if(Number.isNaN(e)){return Ea(e)}else if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(n){var l;switch(s){case 8:l="0o";break;case 16:l="0x";break;case 2:l="0b";break;case 10:l="";break}if(typeof l==="undefined"){var h=BigInt(s);i=k(o).map(function(e,t){return BigInt(parseInt(e,s))*ba(h,BigInt(t))}).reduce(function(e,t){return e+t})}else{i=BigInt(l+o)}}else{i=BigInt(e)}if(f){i*=BigInt(-1)}}else{i=e}return Oa(i,true)}else if(typeof Lr!=="undefined"&&!(e instanceof Lr)){if(e instanceof Array){return Oa(p(Lr,k(e)))}return Oa(new Lr(e))}else if(n){this.constant(parseInt(o,s),"integer")}else{this.constant(e,"integer")}}da.prototype.constant=function(e,t){Object.defineProperty(this,"__value__",{value:e,enumerable:true});Object.defineProperty(this,"__type__",{value:t,enumerable:true})};da.types={float:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return new Ea(t,r)},complex:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!da.isComplex(t)){t={im:0,re:t}}return new Da(t,r)},rational:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!da.isRational(t)){t={num:t,denom:1}}return new ka(t,r)}};da.prototype.serialize=function(){return this.__value__};da.prototype.isNaN=function(){return Number.isNaN(this.__value__)};da.prototype.gcd=function(e){var t=this.abs();e=e.abs();if(e.cmp(t)===1){var r=t;t=e;e=r}while(true){t=t.rem(e);if(t.cmp(0)===0){return e}e=e.rem(t);if(e.cmp(0)===0){return t}}};da.isFloat=function e(t){return t instanceof Ea||Number(t)===t&&t%1!==0};da.isNumber=function(e){return e instanceof da||da.isNative(e)||da.isBN(e)};da.isComplex=function(e){if(!e){return false}var t=e instanceof Da||(da.isNumber(e.im)||Number.isNaN(e.im))&&(da.isNumber(e.re)||Number.isNaN(e.re));return t};da.isRational=function(e){if(!e){return false}return e instanceof ka||da.isNumber(e.num)&&da.isNumber(e.denom)};da.isInteger=function(e){if(!(da.isNative(e)||e instanceof da)){return false}if(da.isFloat(e)){return false}if(da.isRational(e)){return false}if(da.isComplex(e)){return false}return true};da.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};da.isBigInteger=function(e){return e instanceof Oa||typeof e==="bigint"||da.isBN(e)};da.isBN=function(e){return typeof Lr!=="undefined"&&e instanceof Lr};da.getArgsType=function(e,t){if(e instanceof Ea||t instanceof Ea){return Ea}if(e instanceof Oa||t instanceof Oa){return Oa}return da};da.prototype.toString=function(e){if(Number.isNaN(this.__value__)){return"+nan.0"}if(e>2&&e<36){return this.__value__.toString(e)}return this.__value__.toString()};da.prototype.asType=function(e){var t=da.getType(this);return da.types[t]?da.types[t](e):da(e)};da.prototype.isBigNumber=function(){return typeof this.__value__==="bigint"||typeof Lr!=="undefined"&&!(this.value instanceof Lr)};["floor","ceil","round"].forEach(function(e){da.prototype[e]=function(){if(this["float"]||da.isFloat(this.__value__)){return da(Math[e](this.__value__))}else{return da(Math[e](this.valueOf()))}}});da.prototype.valueOf=function(){if(da.isNative(this.__value__)){return Number(this.__value__)}else if(da.isBN(this.__value__)){return this.__value__.toNumber()}};var va=function(){var e=function e(t,r){return[t,r]};return{bigint:{bigint:e,float:function e(t,r){return[Ea(t.valueOf()),r]},rational:function e(t,r){return[{num:t,denom:1},r]},complex:function e(t,r){return[{im:0,re:t},r]}},integer:{integer:e,float:function e(t,r){return[Ea(t.valueOf()),r]},rational:function e(t,r){return[{num:t,denom:1},r]},complex:function e(t,r){return[{im:0,re:t},r]}},float:{bigint:function e(t,r){return[t,r&&Ea(r.valueOf())]},integer:function e(t,r){return[t,r&&Ea(r.valueOf())]},float:e,rational:function e(t,r){return[t,r&&Ea(r.valueOf())]},complex:function e(t,r){return[{re:t,im:Ea(0)},r]}},complex:{bigint:t("bigint"),integer:t("integer"),float:t("float"),rational:t("rational"),complex:function e(t,r){var n=da.coerce(t.__re__,r.__re__),i=A(n,2),u=i[0],a=i[1];var o=da.coerce(t.__im__,r.__im__),s=A(o,2),c=s[0],f=s[1];return[{im:c,re:u},{im:f,re:a}]}},rational:{bigint:function e(t,r){return[t,r&&{num:r,denom:1}]},integer:function e(t,r){return[t,r&&{num:r,denom:1}]},float:function e(t,r){return[Ea(t.valueOf()),r]},rational:e,complex:function e(t,r){return[{im:ma(t.__type__,r.__im__.__type__,0)[0],re:ma(t.__type__,r.__re__.__type__,t)[0]},{im:ma(t.__type__,r.__im__.__type__,r.__im__)[0],re:ma(t.__type__,r.__re__.__type__,r.__re__)[0]}]}}};function t(r){return function(e,t){return[{im:ma(r,e.__im__.__type__,0,e.__im__)[1],re:ma(r,e.__re__.__type__,0,e.__re__)[1]},{im:ma(r,e.__im__.__type__,0,0)[1],re:ma(r,t.__type__,0,t)[1]}]}}}();function ma(e,t,r,n){return va[e][t](r,n)}da.coerce=function(e,t){var r=da.getType(e);var n=da.getType(t);if(!va[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!va[r][n]){throw new Error("LNumber::coerce unknown rhs type ".concat(n))}var i=va[r][n](e,t);return i.map(function(e){return da(e,true)})};da.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof da)){throw new Error("LNumber: you can't coerce ".concat(Ao(e)))}if(typeof e==="number"){e=da(e)}return da.coerce(this,e)};da.getType=function(e){if(e instanceof da){return e.__type__}if(da.isFloat(e)){return"float"}if(da.isComplex(e)){return"complex"}if(da.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof Lr!=="undefined"&&!(e instanceof Lr)){return"bigint"}};da.prototype.isFloat=function(){return!!(da.isFloat(this.__value__)||this["float"])};var ya={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var ga={};Object.keys(ya).forEach(function(t){ga[ya[t]]=t;da.prototype[t]=function(e){return this.op(ya[t],e)}});da._ops={"*":function e(t,r){return t*r},"+":function e(t,r){return t+r},"-":function e(t,r){if(typeof r==="undefined"){return-t}return t-r},"/":function e(t,r){return t/r},"%":function e(t,r){return t%r},"|":function e(t,r){return t|r},"&":function e(t,r){return t&r},"~":function e(t){return~t},">>":function e(t,r){return t>>r},"<<":function e(t,r){return t<1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof Da)||typeof this==="undefined"){return new Da(e,t)}if(e instanceof Da){return Da({im:e.__im__,re:e.__re__})}if(da.isNumber(e)&&t){if(!t){return Number(e)}}else if(!da.isComplex(e)){throw new Error("Invalid constructor call for LComplex")}var r=e.im instanceof da?e.im:da(e.im);var n=e.re instanceof da?e.re:da(e.re);this.constant(r,n)}Da.prototype=Object.create(da.prototype);Da.prototype.constructor=Da;Da.prototype.constant=function(e,t){Object.defineProperty(this,"__im__",{value:e,enumerable:true});Object.defineProperty(this,"__re__",{value:t,enumerable:true});Object.defineProperty(this,"__type__",{value:"complex",enumerable:true})};Da.prototype.serialize=function(){return{re:this.__re__,im:this.__im__}};Da.prototype.toRational=function(e){if(da.isFloat(this.__im__)&&da.isFloat(this.__re__)){var t=Ea(this.__im__).toRational(e);var r=Ea(this.__re__).toRational(e);return Da({im:t,re:r})}return this};Da.prototype.add=function(e){return this.complex_op("add",e,function(e,t,r,n){return{re:e.add(t),im:r.add(n)}})};Da.prototype.factor=function(){if(this.__im__ instanceof Ea||this.__im__ instanceof Ea){var e=this.__re__,t=this.__im__;var r,n;if(e instanceof Ea){r=e.toRational().mul(e.toRational())}else{r=e.mul(e)}if(t instanceof Ea){n=t.toRational().mul(t.toRational())}else{n=t.mul(t)}return r.add(n)}else{return this.__re__.mul(this.__re__).add(this.__im__.mul(this.__im__))}};Da.prototype.modulus=function(){return this.factor().sqrt()};Da.prototype.conjugate=function(){return Da({re:this.__re__,im:this.__im__.sub()})};Da.prototype.sqrt=function(){var e=this.modulus();var t,r;if(e.cmp(0)===0){t=r=e}else if(this.__re__.cmp(0)===1){t=Ea(.5).mul(e.add(this.__re__)).sqrt();r=this.__im__.div(t).div(2)}else{r=Ea(.5).mul(e.sub(this.__re__)).sqrt();if(this.__im__.cmp(0)===-1){r=r.sub()}t=this.__im__.div(r).div(2)}return Da({im:r,re:t})};Da.prototype.div=function(e){if(da.isNumber(e)&&!da.isComplex(e)){if(!(e instanceof da)){e=da(e)}var t=this.__re__.div(e);var r=this.__im__.div(e);return Da({re:t,im:r})}else if(!da.isComplex(e)){throw new Error("[LComplex::div] Invalid value")}var n=this.coerce(e),i=A(n,2),u=i[0],a=i[1];var o=a.factor();var s=u.mul(a.conjugate());var c=s.__re__.op("/",o);var f=s.__im__.op("/",o);return Da({re:c,im:f})};Da.prototype.sub=function(e){return this.complex_op("sub",e,function(e,t,r,n){return{re:e.sub(t),im:r.sub(n)}})};Da.prototype.mul=function(e){return this.complex_op("mul",e,function(e,t,r,n){var i={re:e.mul(t).sub(r.mul(n)),im:e.mul(n).add(t.mul(r))};return i})};Da.prototype.complex_op=function(e,t,i){var u=this;var r=function e(t,r){var n=i(u.__re__,t,u.__im__,r);if("im"in n&&"re"in n){if(n.im.cmp(0)===0&&!da.isFloat(n.im)){return n.re}return Da(n,true)}return n};if(typeof t==="undefined"){return r()}if(da.isNumber(t)&&!da.isComplex(t)){if(!(t instanceof da)){t=da(t)}var n=t.asType(0);t={__im__:n,__re__:t}}else if(!da.isComplex(t)){throw new Error("[LComplex::".concat(e,"] Invalid value"))}var a=t.__re__ instanceof da?t.__re__:this.__re__.asType(t.__re__);var o=t.__im__ instanceof da?t.__im__:this.__im__.asType(t.__im__);return r(a,o)};Da._op={"+":"add","-":"sub","*":"mul","/":"div"};Da.prototype._op=function(e,t){var r=Da._op[e];return this[r](t)};Da.prototype.cmp=function(e){var t=this.coerce(e),r=A(t,2),n=r[0],i=r[1];var u=n.__re__.coerce(i.__re__),a=A(u,2),o=a[0],s=a[1];var c=o.cmp(s);if(c!==0){return c}else{var f=n.__im__.coerce(i.__im__),l=A(f,2),h=l[0],p=l[1];return h.cmp(p)}};Da.prototype.valueOf=function(){return[this.__re__,this.__im__].map(function(e){return e.valueOf()})};Da.prototype.toString=function(){var e;if(this.__re__.cmp(0)!==0){e=[Zi(this.__re__)]}else{e=[]}var t=this.__im__.valueOf();var r=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY].includes(t);var n=Zi(this.__im__);if(!r&&!Number.isNaN(t)){var i=this.__im__.cmp(0);if(i<0||i===0&&this.__im__._minus){e.push("-")}else{e.push("+")}n=n.replace(/^-/,"")}e.push(n);e.push("i");return e.join("")};function Ea(e){if(typeof this!=="undefined"&&!(this instanceof Ea)||typeof this==="undefined"){return new Ea(e)}if(!da.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof da){return Ea(e.valueOf())}if(typeof e==="number"){if(Object.is(e,-0)){Object.defineProperty(this,"_minus",{value:true})}this.constant(e,"float")}}Ea.prototype=Object.create(da.prototype);Ea.prototype.constructor=Ea;Ea.prototype.toString=function(){if(this.__value__===Number.NEGATIVE_INFINITY){return"-inf.0"}if(this.__value__===Number.POSITIVE_INFINITY){return"+inf.0"}if(Number.isNaN(this.__value__)){return"+nan.0"}var e=this.__value__.toString();if(!da.isFloat(this.__value__)&&!e.match(/e/i)){var t=e+".0";return this._minus?"-"+t:t}return e.replace(/^([0-9]+)e/,"$1.0e")};Ea.prototype._op=function(e,t){if(t instanceof da){t=t.__value__}var r=da._ops[e];if(e==="/"&&this.__value__===0&&t===0){return NaN}return Ea(r(this.__value__,t))};Ea.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){return Aa(this.__value__.valueOf())}return Fa(e.valueOf())(this.__value__.valueOf())};Ea.prototype.sqrt=function(){var e=this.valueOf();if(this.cmp(0)<0){var t=Ea(Math.sqrt(-e));return Da({re:0,im:t})}return Ea(Math.sqrt(e))};Ea.prototype.abs=function(){var e=this.valueOf();if(e<0){e=-e}return Ea(e)};var Aa=Fa(1e-10);function Fa(n){return function(e){var t=function e(n,t,r){var i=function e(t,r){return r0){i=Ca(n,r)}else if(n.cmp(r)<=0){i=r}else if(r.cmp(0)>0){i=Ca(r,n)}else if(t.cmp(0)<0){i=da(Ca(n.sub(),r.sub())).sub()}else{i=da(0)}if(da.isFloat(t)||da.isFloat(e)){return Ea(i)}return i}function Ca(e,t){var r=da(e).floor();var n=da(t).floor();if(e.cmp(r)<1){return r}else if(r.cmp(n)===0){var i=da(1).div(t.sub(n));var u=da(1).div(e.sub(r));return r.add(da(1).div(Ca(i,u)))}else{return r.add(da(1))}}function ka(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof ka)||typeof this==="undefined"){return new ka(e,t)}if(!da.isRational(e)){throw new Error("Invalid constructor call for LRational")}var r,n;if(e instanceof ka){r=da(e.__num__);n=da(e.__denom__)}else{r=da(e.num);n=da(e.denom)}if(!t&&n.cmp(0)!==0){var i=r.op("%",n).cmp(0)===0;if(i){return da(r.div(n))}}this.constant(r,n)}ka.prototype=Object.create(da.prototype);ka.prototype.constructor=ka;ka.prototype.constant=function(e,t){Object.defineProperty(this,"__num__",{value:e,enumerable:true});Object.defineProperty(this,"__denom__",{value:t,enumerable:true});Object.defineProperty(this,"__type__",{value:"rational",enumerable:true})};ka.prototype.serialize=function(){return{num:this.__num__,denom:this.__denom__}};ka.prototype.pow=function(e){var t=e.cmp(0);if(t===0){return da(1)}if(t===-1){e=e.sub();var r=this.__denom__.pow(e);var n=this.__num__.pow(e);return ka({num:r,denom:n})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};ka.prototype.sqrt=function(){var e=this.__num__.sqrt();var t=this.__denom__.sqrt();if(e instanceof Ea||t instanceof Ea){return e.div(t)}return ka({num:e,denom:t})};ka.prototype.abs=function(){var e=this.__num__;var t=this.__denom__;if(e.cmp(0)===-1){e=e.sub()}if(t.cmp(0)!==1){t=t.sub()}return ka({num:e,denom:t})};ka.prototype.cmp=function(e){return da(this.valueOf(),true).cmp(e)};ka.prototype.toString=function(){var e=this.__num__.gcd(this.__denom__);var t,r;if(e.cmp(1)!==0){t=this.__num__.div(e);if(t instanceof ka){t=da(t.valueOf(true))}r=this.__denom__.div(e);if(r instanceof ka){r=da(r.valueOf(true))}}else{t=this.__num__;r=this.__denom__}var n=this.cmp(0)<0;if(n){if(t.abs().cmp(r.abs())===0){return t.toString()}}else if(t.cmp(r)===0){return t.toString()}return t.toString()+"/"+r.toString()};ka.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 da._ops["/"](this.__num__.value,this.__denom__.value)}return Ea(this.__num__.valueOf()).div(this.__denom__.valueOf())};ka.prototype.mul=function(e){if(!(e instanceof da)){e=da(e)}if(da.isRational(e)){var t=this.__num__.mul(e.__num__);var r=this.__denom__.mul(e.__denom__);return ka({num:t,denom:r})}var n=da.coerce(this,e),i=A(n,2),u=i[0],a=i[1];return u.mul(a)};ka.prototype.div=function(e){if(!(e instanceof da)){e=da(e)}if(da.isRational(e)){var t=this.__num__.mul(e.__denom__);var r=this.__denom__.mul(e.__num__);return ka({num:t,denom:r})}var n=da.coerce(this,e),i=A(n,2),u=i[0],a=i[1];var o=u.div(a);return o};ka.prototype._op=function(e,t){return this[ga[e]](t)};ka.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof da)){e=da(e)}if(da.isRational(e)){var t=e.__num__.sub();var r=e.__denom__;return this.add(ka({num:t,denom:r}))}if(!(e instanceof da)){e=da(e).sub()}else{e=e.sub()}var n=da.coerce(this,e),i=A(n,2),u=i[0],a=i[1];return u.add(a)};ka.prototype.add=function(e){if(!(e instanceof da)){e=da(e)}if(da.isRational(e)){var t=this.__denom__;var r=e.__denom__;var n=this.__num__;var i=e.__num__;var u,a;if(t!==r){a=r.mul(n).add(i.mul(t));u=t.mul(r)}else{a=n.add(i);u=t}return ka({num:a,denom:u})}if(da.isFloat(e)){return Ea(this.valueOf()).add(e)}var o=da.coerce(this,e),s=A(o,2),c=s[0],f=s[1];return c.add(f)};function Oa(e,t){if(typeof this!=="undefined"&&!(this instanceof Oa)||typeof this==="undefined"){return new Oa(e,t)}if(e instanceof Oa){return Oa(e.__value__,e._native)}if(!da.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.constant(e,"bigint");Object.defineProperty(this,"_native",{value:t})}Oa.prototype=Object.create(da.prototype);Oa.prototype.constructor=Oa;Oa.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};Oa.prototype.serialize=function(){return this.__value__.toString()};Oa.prototype._op=function(e,t){if(typeof t==="undefined"){if(da.isBN(this.__value__)){e=Oa.bn_op[e];return Oa(this.__value__.clone()[e](),false)}return Oa(da._ops[e](this.__value__),true)}if(da.isBN(this.__value__)&&da.isBN(t.__value__)){e=Oa.bn_op[e];return Oa(this.__value__.clone()[e](t),false)}var r=da._ops[e](this.__value__,t.__value__);if(e==="/"){var n=this.op("%",t).cmp(0)===0;if(n){return da(r)}return ka({num:this,denom:t})}return Oa(r,true)};Oa.prototype.sqrt=function(){var e;var t=this.cmp(0)<0;if(da.isNative(this.__value__)){e=da(Math.sqrt(t?-this.valueOf():this.valueOf()))}else if(da.isBN(this.__value__)){e=t?this.__value__.neg().sqrt():this.__value__.sqrt()}if(t){return Da({re:0,im:e})}return e};da.NaN=da(NaN);function Sa(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof Sa)||typeof this==="undefined"){return new Sa(e)}yo("InputPort",e,"function");ai(this,"__type__",Ya);var i;Object.defineProperty(this,"__parser__",{enumerable:true,get:function e(){return i},set:function e(t){yo("InputPort::__parser__",t,"parser");i=t}});this._read=e;this._with_parser=this._with_init_parser.bind(this,O(j.mark(function e(){var r;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(n.char_ready()){t.next=5;break}t.next=3;return n._read();case 3:r=t.sent;i=new Xn(r,{env:n});case 5:return t.abrupt("return",n.__parser__);case 6:case"end":return t.stop()}}},e)})));this.char_ready=function(){return!!this.__parser__&&this.__parser__.__lexer__.peek()!==$a};this._make_defaults()}Sa.prototype._make_defaults=function(){this.read=this._with_parser(function(e){return e.read_object()});this.read_line=this._with_parser(function(e){return e.__lexer__.read_line()});this.read_char=this._with_parser(function(e){return e.__lexer__.read_char()});this.read_string=this._with_parser(function(e,t){if(!da.isInteger(t)){var r=da.getType(t);_o("read-string",r,"integer")}return e.__lexer__.read_string(t.valueOf())});this.peek_char=this._with_parser(function(e){return e.__lexer__.peek_char()})};Sa.prototype._with_init_parser=function(o,s){var c=this;return function(){var e=O(j.mark(function e(){var r,n,i,u,a=arguments;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:t.next=2;return o.call(c);case 2:r=t.sent;for(n=a.length,i=new Array(n),u=0;u"};function Ba(e){if(typeof this!=="undefined"&&!(this instanceof Ba)||typeof this==="undefined"){return new Ba(e)}yo("OutputPort",e,"function");ai(this,"__type__",Ya);this.write=e}Ba.prototype.is_open=function(){return this._closed!==true};Ba.prototype.close=function(){Object.defineProperty(this,"_closed",{get:function e(){return true},set:function e(){},configurable:false,enumerable:false});this.write=function(){throw new Error("output-port: port is closed")}};Ba.prototype.flush=function(){};Ba.prototype.toString=function(){return"#"};var ja=function(e){u(n,e);var r=Fr(n);function n(e){var t;y(this,n);t=r.call(this,function(){var e;return(e=t)._write.apply(e,arguments)});yo("BufferedOutputPort",e,"function");ai(i(t),"_fn",e,{hidden:true});ai(i(t),"_buffer",[],{hidden:true});return t}b(n,[{key:"flush",value:function e(){if(this._buffer.length){this._fn(this._buffer.join(""));this._buffer.length=0}}},{key:"_write",value:function e(){var t=this;for(var r=arguments.length,n=new Array(r),i=0;i"};Ia.prototype.valueOf=function(){return this.__buffer__.map(function(e){return e.valueOf()}).join("")};function Pa(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof Pa)||typeof this==="undefined"){return new Pa(e,t)}yo("OutputFilePort",e,"string");ai(this,"__filename__",e);ai(this,"_fd",t.valueOf(),{hidden:true});ai(this,"__type__",Ya);this.write=function(e){if(!sa.isString(e)){e=Zi(e)}else{e=e.valueOf()}r.fs().write(r._fd,e,function(e){if(e){throw e}})}}Pa.prototype=Object.create(Ba.prototype);Pa.prototype.constructor=Pa;Pa.prototype.fs=function(){if(!this._fs){this._fs=this.internal("fs")}return this._fs};Pa.prototype.internal=function(e){return uo.get("**internal-env**").get(e)};Pa.prototype.close=function(){var n=this;return new Promise(function(t,r){n.fs().close(n._fd,function(e){if(e){r(e)}else{ai(n,"_fd",null,{hidden:true});Ba.prototype.close.call(n);t()}})})};Pa.prototype.toString=function(){return"#")};function Na(e,t){var r=this;if(typeof this!=="undefined"&&!(this instanceof Na)||typeof this==="undefined"){return new Na(e)}yo("InputStringPort",e,"string");t=t||io;e=e.valueOf();this._with_parser=this._with_init_parser.bind(this,function(){if(!r.__parser__){r.__parser__=new Xn(e,{env:t})}return r.__parser__});ai(this,"__type__",Ya);this._make_defaults()}Na.prototype.char_ready=function(){return true};Na.prototype=Object.create(Sa.prototype);Na.prototype.constructor=Na;Na.prototype.toString=function(){return"#"};function Ra(e){if(typeof this!=="undefined"&&!(this instanceof Ra)||typeof this==="undefined"){return new Ra(e)}yo("InputByteVectorPort",e,"uint8array");ai(this,"__vector__",e);ai(this,"__type__",Ma);var r=0;Object.defineProperty(this,"__index__",{enumerable:true,get:function e(){return r},set:function e(t){yo("InputByteVectorPort::__index__",t,"number");if(t instanceof da){t=t.valueOf()}if(typeof t==="bigint"){t=Number(t)}if(Math.floor(t)!==t){throw new Error("InputByteVectorPort::__index__ value is "+"not integer")}r=t}})}Ra.prototype=Object.create(Sa.prototype);Ra.prototype.constructor=Ra;Ra.prototype.toString=function(){return"#"};Ra.prototype.close=function(){var t=this;ai(this,"__vector__",Pi);["read_u8","close","peek_u8","read_u8_vector"].forEach(function(e){t[e]=function(){throw new Error("Input-binary-port: port is closed")}});this.char_ready=function(){return false}};Ra.prototype.u8_ready=function(){return true};Ra.prototype.peek_u8=function(){if(this.__index__>=this.__vector__.length){return $a}return this.__vector__[this.__index__]};Ra.prototype.skip=function(){if(this.__index__<=this.__vector__.length){++this.__index__}};Ra.prototype.read_u8=function(){var e=this.peek_u8();this.skip();return e};Ra.prototype.read_u8_vector=function(e){if(typeof e==="undefined"){e=this.__vector__.length}else if(e>this.__index__+this.__vector__.length){e=this.__index__+this.__vector__.length}if(this.peek_u8()===$a){return $a}return this.__vector__.slice(this.__index__,e)};function Ta(){if(typeof this!=="undefined"&&!(this instanceof Ta)||typeof this==="undefined"){return new Ta}ai(this,"__type__",Ma);ai(this,"_buffer",[],{hidden:true});this.write=function(e){yo("write",e,["number","uint8array"]);if(da.isNumber(e)){this._buffer.push(e.valueOf())}else{var t;(t=this._buffer).push.apply(t,k(Array.from(e)))}};Object.defineProperty(this,"__buffer__",{enumerable:true,get:function e(){return Uint8Array.from(this._buffer)}})}Ta.prototype=Object.create(Ba.prototype);Ta.prototype.constructor=Ta;Ta.prototype.close=function(){Ba.prototype.close.call(this);ai(this,"_buffer",null,{hidden:true})};Ta.prototype._close_guard=function(){if(this._closed){throw new Error("output-port: binary port is closed")}};Ta.prototype.write_u8=function(e){yo("OutputByteVectorPort::write_u8",e,"number");this.write(e)};Ta.prototype.write_u8_vector=function(e){yo("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};Ta.prototype.toString=function(){return"#"};Ta.prototype.valueOf=function(){return this.__buffer__};function La(e,t){if(typeof this!=="undefined"&&!(this instanceof La)||typeof this==="undefined"){return new La(e,t)}Na.call(this,e);yo("InputFilePort",t,"string");ai(this,"__filename__",t)}La.prototype=Object.create(Na.prototype);La.prototype.constructor=La;La.prototype.toString=function(){return"#")};function Ua(e,t){if(typeof this!=="undefined"&&!(this instanceof Ua)||typeof this==="undefined"){return new Ua(e,t)}Ra.call(this,e);yo("InputBinaryFilePort",t,"string");ai(this,"__filename__",t)}Ua.prototype=Object.create(Ra.prototype);Ua.prototype.constructor=Ua;Ua.prototype.toString=function(){return"#")};function qa(e,t){if(typeof this!=="undefined"&&!(this instanceof qa)||typeof this==="undefined"){return new qa(e,t)}yo("OutputBinaryFilePort",e,"string");ai(this,"__filename__",e);ai(this,"_fd",t.valueOf(),{hidden:true});ai(this,"__type__",Ma);var u,r;this.write=function(e){var n=this;yo("write",e,["number","uint8array"]);var i;if(!u){u=this.internal("fs")}if(!r){r=this.internal("Buffer")}if(da.isNumber(e)){i=r.from([e.valueOf()])}else{i=r.from(Array.from(e))}return new Promise(function(t,r){u.write(n._fd,i,function(e){if(e){r(e)}else{t()}})})}}qa.prototype=Object.create(Pa.prototype);qa.prototype.constructor=qa;qa.prototype.write_u8=function(e){yo("OutputByteVectorPort::write_u8",e,"number");this.write(e)};qa.prototype.write_u8_vector=function(e){yo("OutputByteVectorPort::write_u8_vector",e,"uint8array");this.write(e)};var Ma=Symbol["for"]("binary");var Ya=Symbol["for"]("text");var $a=new za;function za(){}za.prototype.toString=function(){return"#"};function Va(e){var t=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},n=r.stderr,i=r.stdin,u=r.stdout,a=r.command_line,o=a===void 0?null:a,s=D(r,Ar);if(typeof this!=="undefined"&&!(this instanceof Va)||typeof this==="undefined"){return new Va(e,Br({stdin:i,stdout:u,stderr:n,command_line:o},s))}if(typeof e==="undefined"){e="anonymous"}this.__env__=uo.inherit(e,s);this.__env__.set("parent.frame",ci("parent.frame",function(){return t.__env__},io.__env__["parent.frame"].__doc__));var c="**interaction-environment-defaults**";this.set(c,Ji(s).concat(c));var f=to.inherit("internal-".concat(e));if(Su(i)){f.set("stdin",i)}if(Su(n)){f.set("stderr",n)}if(Su(u)){f.set("stdout",u)}f.set("command-line",o);ao(this.__env__,f)}Va.prototype.exec=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;yo("Interpreter::exec",e,["string","array"],1);yo("Interpreter::exec",t,"boolean",2);io.set("**interaction-environment**",this.__env__);if(r===null){r=this.__env__}return No(e,r,t?r:false)};Va.prototype.get=function(e){var t=this.__env__.get(e);if(vu(t)){return t.bind(this.__env__)}return t};Va.prototype.set=function(e,t){return this.__env__.set(e,t)};Va.prototype.constant=function(e,t){return this.__env__.constant(e,t)};function Ja(e,t){this.name="LipsError";this.message=e;this.args=t;this.stack=(new Error).stack}Ja.prototype=new Error;Ja.prototype.constructor=Ja;function Ga(e,t,r){if(arguments.length===1){if(_(arguments[0])==="object"){e=arguments[0];t=null}else if(typeof arguments[0]==="string"){e={};t=null;r=arguments[0]}}this.__docs__=new Map;this.__env__=e;this.__parent__=t;this.__name__=r||"anonymous"}Ga.prototype.list=function(){return Ji(this.__env__)};Ga.prototype.fs=function(){return this.get("**fs**")};Ga.prototype.unset=function(e){if(e instanceof Ln){e=e.valueOf()}if(e instanceof sa){e=e.valueOf()}delete this.__env__[e]};Ga.prototype.inherit=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(_(e)==="object"){t=e}if(!e||_(e)==="object"){e="child of "+(this.__name__||"unknown")}return new Ga(t||{},this,e)};Ga.prototype.doc=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(e instanceof Ln){e=e.__name__}if(e instanceof sa){e=e.valueOf()}if(t){if(!r){t=fi(t)}this.__docs__.set(e,t);return this}if(this.__docs__.has(e)){return this.__docs__.get(e)}if(this.__parent__){return this.__parent__.doc(e)}};Ga.prototype.newFrame=function(e,t){var n=this.inherit("__frame__");n.set("parent.frame",ci("parent.frame",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;e=e.valueOf();var t=n.__parent__;if(!(t instanceof Ga)){return Pi}if(e<=0){return t}var r=t.get("parent.frame");return r(e-1)},io.__env__["parent.frame"].__doc__));t.callee=e;n.set("arguments",t);return n};Ga.prototype._lookup=function(e){if(e instanceof Ln){e=e.__name__}if(e instanceof sa){e=e.valueOf()}if(this.__env__.hasOwnProperty(e)){return Ha(this.__env__[e])}if(this.__parent__){return this.__parent__._lookup(e)}};Ga.prototype.toString=function(){return"#"};Ga.prototype.clone=function(){var t=this;var r={};Object.keys(this.__env__).forEach(function(e){r[e]=t.__env__[e]});return new Ga(r,this.__parent__,this.__name__)};Ga.prototype.merge=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"merge";yo("Environment::merge",e,"environment");return this.inherit(t,e.__env__)};function Ha(e){if(typeof this!=="undefined"&&!(this instanceof Ha)||typeof this==="undefined"){return new Ha(e)}this.value=e}Ha.isUndefined=function(e){return e instanceof Ha&&typeof e.value==="undefined"};Ha.prototype.valueOf=function(){return this.value};function Wa(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof Wa)||typeof this==="undefined"){return new Wa(e)}this.__values__=e}Wa.prototype.toString=function(){return this.__values__.map(function(e){return Zi(e)}).join("\n")};Wa.prototype.valueOf=function(){return this.__values__};Ga.prototype.get=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};yo("Environment::get",e,["symbol","string"]);var r=t.throwError,n=r===void 0?true:r;var i=e;if(i instanceof Ln||i instanceof sa){i=i.valueOf()}var u=this._lookup(i);if(u instanceof Ha){if(Ha.isUndefined(u)){return undefined}return Au(u.valueOf())}var a;if(e instanceof Ln&&e[Ln.object]){a=e[Ln.object]}else if(typeof i==="string"){a=i.split(".").filter(Boolean)}if(a&&a.length>0){var o=a,s=h(o),c=s[0],f=s.slice(1);u=this._lookup(c);if(f.length){try{if(u instanceof Ha){u=u.valueOf()}else{u=Ka(jr,c);if(vu(u)){u=Fu(u)}}if(typeof u!=="undefined"){return Ka.apply(void 0,[u].concat(k(f)))}}catch(e){throw e}}else if(u instanceof Ha){return Au(u.valueOf())}u=Ka(jr,i)}if(typeof u!=="undefined"){return u}if(n){throw new Error("Unbound variable `"+i.toString()+"'")}};Ga.prototype.set=function(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;yo("Environment::set",e,["string","symbol"]);if(da.isNumber(t)){t=da(t)}if(e instanceof Ln){e=e.__name__}if(e instanceof sa){e=e.valueOf()}this.__env__[e]=t;if(r){this.doc(e,r,true)}return this};Ga.prototype.constant=function(t,e){var r=this;if(this.__env__.hasOwnProperty(t)){throw new Error("Environment::constant: ".concat(t," already exists"))}if(arguments.length===1&&Li(arguments[0])){var n=arguments[0];Object.keys(n).forEach(function(e){r.constant(t,n[e])})}else{Object.defineProperty(this.__env__,t,{value:e,enumerable:true})}return this};Ga.prototype.has=function(e){return this.__env__.hasOwnProperty(e)};Ga.prototype.ref=function(e){var t=this;while(true){if(!t){break}if(t.has(e)){return t}t=t.__parent__}};Ga.prototype.parents=function(){var e=this;var t=[];while(e){t.unshift(e);e=e.__parent__}return t};function Qa(e){if(gu(e)){return e.then(Qa)}if(e instanceof Ni||e instanceof Ln){e[Pu]=true}return e}var Za=ti(Nn('(lambda ()\n "[native code]"\n (throw "Invalid Invocation"))'))[0];var Ka=ci("get",function e(t){var r;for(var n=arguments.length,i=new Array(n>1?n-1:0),u=1;u0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=Xa(this,"stdin")}mo("peek-char",e,"input-port");return e.peek_char()},"(peek-char port)\n\n Function get character from string port or EOF object if no more\n data in string port."),"read-line":ci("read-line",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=Xa(this,"stdin")}mo("read-line",e,"input-port");return e.read_line()},"(read-char port)\n\n Function read next character from input port."),"read-char":ci("read-char",function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(e===null){e=Xa(this,"stdin")}mo("read-char",e,"input-port");return e.read_char()},"(read-char port)\n\n Function read next character from input port."),read:ci("read",function(){var e=O(j.mark(function e(){var r,n,i,u,a,o,s,c,f=arguments;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:r=f.length>0&&f[0]!==undefined?f[0]:null;if(!sa.isString(r)){t.next=30;break}n=false;i=false;t.prev=4;a=F(ti(r,this));case 6:t.next=8;return a.next();case 8:if(!(n=!(o=t.sent).done)){t.next=14;break}s=o.value;return t.abrupt("return",s);case 11:n=false;t.next=6;break;case 14:t.next=20;break;case 16:t.prev=16;t.t0=t["catch"](4);i=true;u=t.t0;case 20:t.prev=20;t.prev=21;if(!(n&&a["return"]!=null)){t.next=25;break}t.next=25;return a["return"]();case 25:t.prev=25;if(!i){t.next=28;break}throw u;case 28:return t.finish(25);case 29:return t.finish(20);case 30:if(r===null){c=Xa(this,"stdin")}else{c=r}mo("read",c,"input-port");return t.abrupt("return",c.read.call(this));case 33:case"end":return t.stop()}}},e,this,[[4,16,20,30],[21,,25,29]])}));function t(){return e.apply(this,arguments)}return t}(),"(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:ci("pprint",function e(t){if(t instanceof Ni){t=new ps.Formatter(t.toString(true))["break"]().format();io.get("display").call(io,t)}else{io.get("write").call(io,t)}io.get("newline").call(io)},"(pprint expression)\n\n Pretty print list expression, if called with non-pair it just call\n print function with passed argument."),print:ci("print",function e(){var t=io.get("display");var r=io.get("newline");for(var n=arguments.length,i=new Array(n),u=0;u1?r-1:0),i=1;in.length){throw new Error("Not enough arguments")}var o=0;var s=io.get("repr");t=t.replace(u,function(e){var t=e[1];if(t==="~"){return"~"}else if(t==="%"){return"\n"}else{var r=n[o++];if(t==="a"){return s(r)}else{return s(r,true)}}});a=t.match(/~([\S])/);if(a){throw new Error("format: Unrecognized escape seqence ".concat(a[1]))}return t},"(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:ci("display",function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(r===null){r=Xa(this,"stdout")}else{yo("display",r,"output-port")}var n=io.get("repr")(t);r.write.call(io,n)},"(display arg [port])\n\n Function send string to standard output or provied port."),"display-error":ci("display-error",function e(){var t=Xa(this,"stderr");var r=io.get("repr");for(var n=arguments.length,i=new Array(n),u=0;u1&&arguments[1]!==undefined?arguments[1]:{},r=t.dynamic_scope,n=t.error;if(r){r=this}var i=this;var a;var o=Io(e.cdr.car,{env:this,dynamic_scope:r,error:n});o=Fo(o);function s(t,r,n){if(gu(t)){return t.then(function(e){return s(t,e,n)})}if(gu(r)){return r.then(function(e){return s(t,e,n)})}if(gu(n)){return n.then(function(e){return s(t,r,e)})}i.get("set-obj!").call(i,t,r,n);return n}if(e.car instanceof Ni&&Ln.is(e.car.car,".")){var c=e.car.cdr.car;var f=e.car.cdr.cdr.car;var l=Io(c,{env:this,dynamic_scope:r,error:n});var h=Io(f,{env:this,dynamic_scope:r,error:n});return s(l,h,o)}if(!(e.car instanceof Ln)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var p=e.car.valueOf();a=this.ref(e.car.__name__);return ni(o,function(e){if(!a){var t=p.split(".");if(t.length>1){var r=t.pop();var n=t.join(".");var i=u.get(n,{throwError:false});if(i){s(i,r,e);return}}throw new Error("Unbound variable `"+p+"'")}a.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!":ci(new au("set!",function(e){if(!(e.car instanceof Ln)){throw new Error("unset! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var t=e.car;var r=this.ref(t);if(r){delete r.__env__[t.__name__]}}),"(unset! name)\n\n Function delete specified name from environment."),"set-car!":ci("set-car!",function(e,t){yo("set-car!",e,"pair");e.car=t},"(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!":ci("set-cdr!",function(e,t){yo("set-cdr!",e,"pair");e.cdr=t},"(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?":ci("empty?",function(e){return typeof e==="undefined"||e===Pi},"(empty? object)\n\n Function return true if value is undfined empty list."),gensym:ci("gensym",Mn,"(gensym)\n\n Function generate unique symbol, to use with macros as meta name."),load:ci("load",function e(o,t){yo("load",o,"string");var s=this;if(s.__name__==="__frame__"){s=s.__parent__}if(!(t instanceof Ga)){if(s===io){t=s}else{t=this.get("**interaction-environment**")}}var c="**module-path**";var f=io.get(c,{throwError:false});o=o.valueOf();if(!o.match(/.[^.]+$/)){o+=".scm"}var r=o.match(/\.xcb$/);function l(e){if(r){e=ss(e)}else{if(Ao(e)==="buffer"){e=e.toString()}e=e.replace(/^#!.*/,"");if(e.match(/^\{/)){e=ts(e)}}return No(e,t)}function n(e){return jr.fetch(e).then(function(e){return r?e.arrayBuffer():e.text()}).then(function(e){if(r){e=new Uint8Array(e)}return e})}if(lo()){return new Promise(function(){var r=O(j.mark(function e(r,n){var i,u,a;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:i=Tr("path");if(!f){t.next=6;break}f=f.valueOf();o=i.join(f,o);t.next=12;break;case 6:u=s.get("command-line",{throwError:false});if(!u){t.next=11;break}t.next=10;return u();case 10:a=t.sent;case 11:if(a&&a!==Pi){process.cwd();o=i.join(i.dirname(a.car.valueOf()),o)}case 12:io.set(c,i.dirname(o));Tr("fs").readFile(o,function(e,t){if(e){n(e);io.set(c,f)}else{try{l(t).then(function(){r();io.set(c,f)})["catch"](n)}catch(e){n(e)}}});case 14:case"end":return t.stop()}}},e)}));return function(e,t){return r.apply(this,arguments)}}())}if(f){f=f.valueOf();o=f+"/"+o.replace(/^\.?\/?/,"")}return n(o).then(function(e){io.set(c,o.replace(/\/[^/]*$/,""));return l(e)}).then(function(){})["finally"](function(){io.set(c,f)})},"(load filename)\n (load filename environment)\n\n Function fetch the file and evaluate its content as LIPS code,\n If second argument is provided and it's environment the evaluation\n will happen in that environment."),do:ci(new au("do",function(){var r=O(j.mark(function e(r,n){var i,u,a,o,s,c,f,l,h,p,_;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:i=n.dynamic_scope,u=n.error;a=this;if(i){i=a}o=a.inherit("do");s=r.car;c=r.cdr.car;f=r.cdr.cdr;if(f!==Pi){f=new Ni(Ln("begin"),f)}l={env:a,dynamic_scope:i,error:u};h=s;case 10:if(!(h!==Pi)){t.next=21;break}p=h.car;t.t0=o;t.t1=p.car;t.next=16;return Io(p.cdr.car,l);case 16:t.t2=t.sent;t.t0.set.call(t.t0,t.t1,t.t2);h=h.cdr;t.next=10;break;case 21:l={env:o,dynamic_scope:i,error:u};_=j.mark(function e(){var r,n,i,u,a;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(!(f!==Pi)){t.next=3;break}t.next=3;return ps.evaluate(f,l);case 3:r=s;n={};case 5:if(!(r!==Pi)){t.next=15;break}i=r.car;if(!(i.cdr.cdr!==Pi)){t.next=12;break}t.next=10;return Io(i.cdr.cdr.car,l);case 10:u=t.sent;n[i.car.valueOf()]=u;case 12:r=r.cdr;t.next=5;break;case 15:a=Object.getOwnPropertySymbols(n);Object.keys(n).concat(a).forEach(function(e){o.set(e,n[e])});case 17:case"end":return t.stop()}}},e)});case 23:t.next=25;return Io(c.car,l);case 25:t.t3=t.sent;if(!(t.t3===false)){t.next=30;break}return t.delegateYield(_(),"t4",28);case 28:t.next=23;break;case 30:if(!(c.cdr!==Pi)){t.next=34;break}t.next=33;return Io(c.cdr.car,l);case 33:return t.abrupt("return",t.sent);case 34:case"end":return t.stop()}}},e,this)}));return function(e,t){return r.apply(this,arguments)}}()),"(do (( )) (test expression) . body)\n\n Iteration macro that evaluate the expression body in scope of the variables.\n On Eeach loop it increase the variables according to next expression and run\n test to check if the loop should continue. If test is signle call the macro\n will not return anything. If the test is pair of expression and value the\n macro will return that value after finish."),if:ci(new au("if",function(r,e){var n=e.dynamic_scope,i=e.error;if(n){n=this}var u=this;var t=function e(t){if(t===false){return Io(r.cdr.cdr.car,{env:u,dynamic_scope:n,error:i})}else{return Io(r.cdr.car,{env:u,dynamic_scope:n,error:i})}};if(r===Pi){throw new Error("too few expressions for `if`")}var a=Io(r.car,{env:u,dynamic_scope:n,error:i});return ni(a,t)}),"(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 au("let-env",function(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=e.dynamic_scope,n=e.error;yo("let-env",t,"pair");var i=Io(t.car,{env:this,dynamic_scope:r,error:n});return ni(i,function(e){yo("let-env",e,"environment");return Io(Ni(Ln("begin"),t.cdr),{env:e,dynamic_scope:r,error:n})})},"(let-env env . body)\n\n Special macro that evaluate body in context of given environment\n object."),letrec:ci(Wu(Symbol["for"]("letrec")),"(letrec ((a value-a) (b value-b)) body)\n\n Macro that creates new environment, then evaluate and assign values to\n names and then evaluate the body in context of that environment.\n Values are evaluated sequentialy and next value can access to\n previous values/names."),"letrec*":ci(Wu(Symbol["for"]("letrec")),"(letrec* ((a value-a) (b value-b)) body)\n\n Same as letrec but the order of execution of the binding is guaranteed,\n so use can use recursive code as well as reference previous binding.\n In LIPS both letrec and letrec* behave the same."),"let*":ci(Wu(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:ci(Wu(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*":ci(Qu("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:ci(new au("begin",function(e,t){var n=Object.assign({},t);var i=io.get("list->array")(e);if(n.dynamic_scope){n.dynamic_scope=this}n.env=this;var u;return function t(){if(i.length){var e=i.shift();var r=Io(e,n);return ni(r,function(e){u=e;return t()})}else{return u}}()}),"(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 au("ignore",function(e,t){var r=t.dynamic_scope,n=t.error;var i={env:this,error:n};if(r){i.dynamic_scope=this}Io(new Ni(new Ln("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."),"call/cc":ci(au.defmacro("call/cc",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=Br({env:this},t);return ni(Io(e.car,r),function(e){if(vu(e)){return e(new Bo(null))}})}),"(call/cc proc)\n\n TODO"),define:ci(au.defmacro("define",function(r,e){var n=this;if(r.car instanceof Ni&&r.car.car instanceof Ln){var t=new Ni(new Ln("define"),new Ni(r.car.car,new Ni(new Ni(new Ln("lambda"),new Ni(r.car.cdr,r.cdr)))));return t}else if(e.macro_expand){return}if(e.dynamic_scope){e.dynamic_scope=this}e.env=n;var i=r.cdr.car;var u;if(i instanceof Ni){i=Io(i,e);u=true}else if(i instanceof Ln){i=n.get(i)}yo("define",r.car,"symbol");return ni(i,function(e){if(n.__name__===fu.__merge_env__){n=n.__parent__}if(u&&(vu(e)&&Vu(e)||e instanceof fu)){e.__name__=r.car.valueOf();if(e.__name__ instanceof sa){e.__name__=e.__name__.valueOf()}}var t;if(r.cdr.cdr instanceof Ni&&sa.isString(r.cdr.cdr.car)){t=r.cdr.cdr.car.valueOf()}n.set(r.car,e,t,true)})}),'(define name expression)\n (define name expression "doc string")\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!":ci("set-obj!",function(e,t,r){var n=_(e);if(du(e)||n!=="object"&&n!=="function"){var i=_o("set-obj!",Ao(e),["object","function"]);throw new Error(i)}yo("set-obj!",t,["string","symbol","number"]);e=Fu(e);t=t.valueOf();if(arguments.length===2){delete e[t]}else if(Ki(e)&&vu(r)){e[t]=Fu(r);e[t][Uu]=true}else if(vu(r)||bo(r)||r===Pi){e[t]=r}else{e[t]=r&&!Ki(r)?r.valueOf():r}},"(set-obj! obj key value)\n\n Function set property of JavaScript object"),"null-environment":ci("null-environment",function(){return io.inherit("null")},"(null-environment)\n\n Function return new base environment with std lib."),values:ci("values",function e(){for(var t=arguments.length,r=new Array(t),n=0;n1&&arguments[1]!==undefined?arguments[1]:{},h=e.dynamic_scope,p=e.error;var _=this;var d;if(l.cdr instanceof Ni&&sa.isString(l.cdr.car)&&l.cdr.cdr!==Pi){d=l.cdr.car.valueOf()}function v(){var e;if(h){if(!(this instanceof Ga)){e=_}else{e=this}}else{e=_}e=e.inherit("lambda");var t=l.car;var r=0;var n;if(typeof this!=="undefined"&&!(this instanceof Ga)){if(this&&!this.__instance__){Object.defineProperty(this,"__instance__",{enumerable:false,get:function e(){return true},set:function e(){},configurable:false})}e.set("this",this)}for(var i=arguments.length,u=new Array(i),a=0;a>> "+_.toString());if(_){l=_}var d=i.merge(n,fu.__merge_env__);if(r){return{expr:l,scope:d}}var v=Io(l,Br(Br({},a),{},{env:d}));return pu(v,p)}s=s.cdr}}catch(e){e.message+=" in macro: ".concat(m.toString(true));throw e}throw new Error("Invalid Syntax ".concat(e.toString(true)))},b);r.__code__=m;return r},"(syntax-rules () (pattern expression) ...)\n\n Base of Hygienic macro, it will return new syntax expander\n that works like lisp macros."),quote:ci(new au("quote",function(e){return Qa(e.car)}),"(quote expression)\n\n Macro that return single lips expression as data (it don't evaluate its\n argument). It will return list of pairs if put in front of lips code.\n And if put in fron of symbol it will return that symbol not value\n associated with that name."),"unquote-splicing":ci("unquote-splicing",function(){throw new Error("You can't call `unquote-splicing` outside of quasiquote")},"(unquote-splicing code)\n\n Special form to be used in quasiquote macro, parser is processing special\n characters ,@ and create call to this pseudo function. It can be used\n to evalute expression inside and return the value without parenthesis.\n the value will be joined to the output list structure."),unquote:ci("unquote",function(){throw new Error("You can't call `unquote` outside of quasiquote")},"(unquote code)\n\n Special form to be used in quasiquote macro, parser is processing special\n characters , and create call to this pseudo function. It can be used\n to evalute expression inside and return the value, the output is inserted\n into list structure created by queasiquote."),quasiquote:au.defmacro("quasiquote",function(e,t){var o=t.dynamic_scope,s=t.error;var c=this;if(o){o=c}function u(e){return e instanceof Ni||Li(e)||Array.isArray(e)}function f(e,t){var r=arguments.length>2&&arguments[2]!==undefined?arguments[2]:u;if(e instanceof Ni){var n=e.car;var i=e.cdr;if(r(n)){n=t(n)}if(r(i)){i=t(i)}if(gu(n)||gu(i)){return $n([n,i]).then(function(e){var t=A(e,2),r=t[0],n=t[1];return new Ni(r,n)})}else{return new Ni(n,i)}}return e}function a(e,t){if(e instanceof Ni){if(t!==Pi){e.append(t)}}else{e=new Ni(e,t)}return e}function r(e){return!!e.filter(function(e){return e instanceof Ni&&Ln.is(e.car,/^(unquote|unquote-splicing)$/)}).length}function l(e,n,i){return e.reduce(function(e,t){if(!(t instanceof Ni)){e.push(t);return e}if(Ln.is(t.car,"unquote-splicing")){var r;if(n+11){var t="You can't splice multiple atoms inside list";throw new Error(t)}if(!(i.cdr instanceof Ni&&r[0]===Pi)){return r[0]}}r=r.map(function(e){if(_.has(e)){return e.clone()}else{_.add(e);return e}});var n=d(i.cdr,0,1);if(n===Pi&&r[0]===Pi){return undefined}return ni(n,function(e){if(r[0]===Pi){return e}if(r.length===1){return a(r[0],e)}var t=r.reduce(function(e,t){return a(e,t)});return a(t,e)})})}(i.car.cdr)}var _=new Set;function d(e,t,r){if(e instanceof Ni){if(e.car instanceof Ni){if(Ln.is(e.car.car,"unquote-splicing")){return p(e,t+1,r)}if(Ln.is(e.car.car,"unquote")){if(t+2===r&&e.car.cdr instanceof Ni&&e.car.cdr.car instanceof Ni&&Ln.is(e.car.cdr.car.car,"unquote-splicing")){var n=e.car.cdr;return new Ni(new Ni(new Ln("unquote"),p(n,t+2,r)),Pi)}else if(e.car.cdr instanceof Ni&&e.car.cdr.cdr!==Pi){if(e.car.cdr.car instanceof Ni){var i=[];return function t(r){if(r===Pi){return Ni.fromArray(i)}return ni(Io(r.car,{env:c,dynamic_scope:o,error:s}),function(e){i.push(e);return t(r.cdr)})}(e.car.cdr)}else{return e.car.cdr}}}}if(Ln.is(e.car,"quasiquote")){var u=d(e.cdr,t,r+1);return new Ni(e.car,u)}if(Ln.is(e.car,"quote")){return new Ni(e.car,d(e.cdr,t,r))}if(Ln.is(e.car,"unquote")){t++;if(tr){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(e.cdr instanceof Ni){if(e.cdr.cdr!==Pi){if(e.cdr.car instanceof Ni){var a=[];return function t(r){if(r===Pi){return Ni.fromArray(a)}return ni(Io(r.car,{env:c,dynamic_scope:o,error:s}),function(e){a.push(e);return t(r.cdr)})}(e.cdr)}else{return e.cdr}}else{return Io(e.cdr.car,{env:c,dynamic_scope:o,error:s})}}else{return e.cdr}}return f(e,function(e){return d(e,t,r)})}else if(Li(e)){return h(e,t,r)}else if(e instanceof Array){return l(e,t,r)}return e}function n(e){if(e instanceof Ni){delete e[Pu];if(!e.haveCycles("car")){n(e.car)}if(!e.haveCycles("cdr")){n(e.cdr)}}}if(Li(e.car)&&!r(Object.values(e.car))){return Qa(e.car)}if(Array.isArray(e.car)&&!r(e.car)){return Qa(e.car)}if(e.car instanceof Ni&&!e.car.find("unquote")&&!e.car.find("unquote-splicing")&&!e.car.find("quasiquote")){return Qa(e.car)}var i=d(e.car,0,1);return ni(i,function(e){n(e);return Qa(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:ci("clone",function e(t){yo("clone",t,"pair");return t.clone()},"(clone list)\n\n Function return clone of the list."),append:ci("append",function e(){var t;for(var r=arguments.length,n=new Array(r),i=0;iarray")(t).reverse();return io.get("array->list")(r)}else if(!(t instanceof Array)){throw new Error(_o("reverse",Ao(t),"array or pair"))}else{return t.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:ci("nth",function e(t,r){yo("nth",t,"number");yo("nth",r,["array","pair"]);if(r instanceof Ni){var n=r;var i=0;while(iarray")(r).join(t)},"(join separator list)\n\n Function return string by joining elements of the list"),split:ci("split",function e(t,r){yo("split",t,["regex","string"]);yo("split",r,"string");return io.get("array->list")(r.split(t))},"(split separator string)\n\n Function create list by splitting string by separatar that can\n be a string or regular expression."),replace:ci("replace",function e(t,r,n){yo("replace",t,["regex","string"]);yo("replace",r,["string","function"]);yo("replace",n,"string");return n.replace(t,r)},"(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:ci("match",function e(t,r){yo("match",t,["regex","string"]);yo("match",r,"string");var n=r.match(t);return n?io.get("array->list")(n):false},"(match pattern string)\n\n function return match object from JavaScript as list or #f if not match."),search:ci("search",function e(t,r){yo("search",t,["regex","string"]);yo("search",r,"string");return r.search(t)},"(search pattern string)\n\n Function return first found index of the pattern inside a string"),repr:ci("repr",function e(t,r){return Zi(t,r)},"(repr obj)\n\n Function return string LIPS representation of an object as string."),"escape-regex":ci("escape-regex",function(e){yo("escape-regex",e,"string");return kn(e.valueOf())},"(escape-regex string)\n\n Function return new string where all special operators used in regex,\n are escaped with slash so they can be used in RegExp constructor\n to match literal string"),env:ci("env",function e(e){e=e||this;var t=Object.keys(e.__env__).map(Ln);var r;if(t.length){r=Ni.fromArray(t)}else{r=Pi}if(e.__parent__ instanceof Ga){return io.get("env")(e.__parent__).append(r)}return r},"(env)\n (env obj)\n\n Function return list of values (functions, macros and variables)\n inside environment and it's parents."),new:ci("new",function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n2&&arguments[2]!==undefined?arguments[2]:Jn.LITERAL;yo("set-special!",e,"string",1);yo("set-special!",t,"symbol",2);Jn.append(e.valueOf(),t,r)},'(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:Ka,".":Ka,unbind:ci(Fu,"(unbind fn)\n\n Function remove bidning from function so you can get props from it."),type:ci(Ao,"(type object)\n\n Function return type of an object as string."),debugger:ci("debugger",function(){debugger},"(debugger)\n\n Function stop JavaScript code in debugger."),in:ci("in",function(e,t){if(e instanceof Ln||e instanceof sa||e instanceof da){e=e.valueOf()}return e in Eu(t)},"(in key value)\n\n Function use is in operator to check if value is in object."),instanceof:ci("instanceof",function(e,t){return t instanceof Fu(e)},"(instanceof type obj)\n\n Function check of object is instance of object."),"prototype?":ci("prototype?",Ki,"(prototype? obj)\n\n Function check if value is JavaScript Object prototype."),"macro?":ci("macro?",function(e){return e instanceof au},"(macro? expression)\n\n Function check if value is a macro."),"function?":ci("function?",vu,"(function? expression)\n\n Function check if value is a function."),"real?":ci("real?",function(e){if(Ao(e)!=="number"){return false}if(e instanceof da){return e.isFloat()}return da.isFloat(e)},"(real? number)\n\n Function check if value is real number."),"number?":ci("number?",function(e){return Number.isNaN(e)||da.isNumber(e)},"(number? expression)\n\n Function check if value is a number or NaN value."),"string?":ci("string?",function(e){return sa.isString(e)},"(string? expression)\n\n Function check if value is a string."),"pair?":ci("pair?",function(e){return e instanceof Ni},"(pair? expression)\n\n Function check if value is a pair or list structure."),"regex?":ci("regex?",function(e){return e instanceof RegExp},"(regex? expression)\n\n Function check if value is regular expression."),"null?":ci("null?",function(e){return du(e)},"(null? expression)\n\n Function check if value is nulish."),"boolean?":ci("boolean?",function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Function check if value is boolean."),"symbol?":ci("symbol?",function(e){return e instanceof Ln},"(symbol? expression)\n\n Function check if value is LIPS symbol"),"array?":ci("array?",function(e){return e instanceof Array},"(array? expression)\n\n Function check if value is an arrray."),"object?":ci("object?",function(e){return e!==Pi&&e!==null&&!(e instanceof oa)&&!(e instanceof RegExp)&&!(e instanceof sa)&&!(e instanceof Ni)&&!(e instanceof da)&&_(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Function check if value is an plain object."),flatten:ci("flatten",function e(t){yo("flatten",t,"pair");return t.flatten()},"(flatten list)\n\n Return shallow list from tree structure (pairs)."),"array->list":ci("array->list",function(e){yo("array->list",e,"array");return Ni.fromArray(e)},"(array->list array)\n\n Function convert JavaScript array to LIPS list."),"tree->array":ci("tree->array",Ri("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":ci("list->array",Ri("list->array"),"(list->array list)\n\n Function convert LIPS list into JavaScript array."),apply:ci("apply",function e(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;iarray").call(this,u));return t.apply(this,Oo(t,n))},"(apply fn list)\n\n Function that call function with list of arguments."),length:ci("length",function e(t){if(!t||t===Pi){return 0}if(t instanceof Ni){return t.length()}if("length"in t){return t.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":ci("string->number",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;yo("string->number",e,"string",1);yo("string->number",t,"number",2);e=e.valueOf();t=t.valueOf();if(e.match(fn)||e.match(on)){return dn(e,t)}else if(e.match(ln)||e.match(an)){return yn(e,t)}else{var r=t===10&&!e.match(/e/i)||t===16;if(e.match(cn)&&r||e.match(sn)){return vn(e,t)}if(e.match(Wr)){return wn(e)}}return false},"(string->number number [radix])\n\n Function convert string to number."),try:ci(new au("try",function(t,e){var c=this;var f=e.dynamic_scope,l=e.error;return new Promise(function(i,n){var u,a;if(Ln.is(t.cdr.car.car,"catch")){u=t.cdr.car;if(t.cdr.cdr instanceof Ni&&Ln.is(t.cdr.cdr.car.car,"finally")){a=t.cdr.cdr.car}}else if(Ln.is(t.cdr.car.car,"finally")){a=t.cdr.car}if(!(a||u)){throw new Error("try: invalid syntax")}var o=i;if(a){o=function e(t,r){o=n;ni(Io(new Ni(new Ln("begin"),a.cdr),s),function(){r(t)})}}var s={env:c,error:function e(t){var r=c.inherit("try");if(u){r.set(u.cdr.car.car,t);var n={env:r,error:l};if(f){n.dynamic_scope=c}ni(Io(new Ni(new Ln("begin"),u.cdr.cdr),n),function(e){o(e,i)})}else{o(t,l)}}};if(f){s.dynamic_scope=c}var e=Io(t.car,s);if(gu(e)){e.then(function(e){o(e,i)})["catch"](s.error)}else{o(e,i)}})}),"(try expr (catch (e) code))\n (try expr (catch (e) code) (finally code))\n (try expr (finally code))\n\n Macro execute user code and catch exception. If catch is provided\n it's executed when expression expr throw error. If finally is provide\n it's always executed at the end."),raise:ci("raise",function(e){throw e},"(raise obj)\n\n Throws new exception with given object."),throw:ci("throw",function(e){throw new Error(e)},"(throw string)\n\n Throws new expection."),find:ci("find",function t(r,n){yo("find",r,["regex","function"]);yo("find",n,["pair","nil"]);if(du(n)){return Pi}var e=si("find",r);return ni(e(n.car),function(e){if(e&&e!==Pi){return n.car}return t(r,n.cdr)})},"(find fn list)\n (find regex list)\n\n Higher order Function find first value for which function return true.\n If called with regex it will create matcher function."),"for-each":ci("for-each",function(e){var t;yo("for-each",e,"function");for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i1?t-1:0),u=1;u3?n-3:0),u=3;u3?i-3:0),a=3;aarray")(r);var u=[];var a=si("filter",t);return function t(r){function e(e){if(e&&e!==Pi){u.push(n)}return t(++r)}if(r===i.length){return Ni.fromArray(u)}var n=i[r];return ni(a(n),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher order function that call `fn` for each element of the list\n and return list for only those elements for which funtion return\n true value. If called with regex it will create matcher function."),compose:ci(Xu,"(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:ci(Ku,"(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:ci(ua,"(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:ci("gcd",function e(){for(var t=arguments.length,r=new Array(t),n=0;no?u%=o:o%=u}u=eu(s*r[a])/(u+o)}return da(u)},"(lcm n1 n2 ...)\n\n Function return the least common multiple of their arguments."),"odd?":ci("odd?",ra(function(e){return da(e).isOdd()}),"(odd? number)\n\n Function check if number os odd."),"even?":ci("even?",ra(function(e){return da(e).isEven()}),"(even? number)\n\n Function check if number is even."),"*":ci("*",ia(function(e,t){return da(e).mul(t)},da(1)),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":ci("+",ia(function(e,t){return da(e).add(t)},da(0)),"(+ . numbers)\n\n Sum all numbers passed as arguments. If single value is passed it will\n return that value."),"-":ci("-",function(){for(var e=arguments.length,t=new Array(e),r=0;r":ci(">",function(){for(var e=arguments.length,t=new Array(e),r=0;r",t,"number");return tu(function(e,t){return da(e).cmp(t)===1},t)},"(> x1 x2 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically increasing"),"<":ci("<",function(){for(var e=arguments.length,t=new Array(e),r=0;r=":ci(">=",function(){for(var e=arguments.length,t=new Array(e),r=0;r=",t,"number");return tu(function(e,t){return[0,1].includes(da(e).cmp(t))},t)},"(>= x1 x2 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically nondecreasing"),"eq?":ci("eq?",ru,"(eq? a b)\n\n Function compare two values if they are identical."),or:ci(new au("or",function(e,t){var i=t.dynamic_scope,u=t.error;var a=io.get("list->array")(e);var o=this;if(i){i=o}if(!a.length){return false}var s;return function t(){function e(e){s=e;if(s!==false){return s}else{return t()}}if(!a.length){if(s!==false){return s}else{return false}}else{var r=a.shift();var n=Io(r,{env:o,dynamic_scope:i,error:u});return ni(n,e)}}()}),"(or . expressions)\n\n Macro execute the values one by one and return the one that is truthy value.\n If there are no expression that evaluate to true it return false."),and:ci(new au("and",function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},i=t.dynamic_scope,u=t.error;var a=io.get("list->array")(e);var o=this;if(i){i=o}if(!a.length){return true}var s;return function t(){function e(e){s=e;if(s===false){return false}else{return t()}}if(!a.length){if(s!==false){return s}else{return false}}else{var r=a.shift();var n=Io(r,{env:o,dynamic_scope:i,error:u});return ni(n,e)}}()}),"(and . expressions)\n\n Macro evalute each expression in sequence if any value return false it will\n return false. If each value return true it will return the last value.\n If it's called without arguments it will return true."),"|":ci("|",function(e,t){return da(e).or(t)},"(| a b)\n\n Function calculate or bit operation."),"&":ci("&",function(e,t){return da(e).and(t)},"(& a b)\n\n Function calculate and bit operation."),"~":ci("~",function(e){return da(e).neg()},"(~ number)\n\n Function negate the value."),">>":ci(">>",function(e,t){return da(e).shr(t)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":ci("<<",function(e,t){return da(e).shl(t)},"(<< a b)\n\n Function left shit the value a by value b."),not:ci("not",function e(t){if(du(t)){return true}return!t},"(not object)\n\n Function return negation of the argument.")},undefined,"global");var uo=io.inherit("user-env");function ao(e,t){e.constant("**internal-env**",t);e.doc("**internal-env**","**internal-env**\n\n Constant used to hide stdin, stdout and stderr so they don't interfere\n with variables with the same name. Constants are internal type\n of variables that can't be redefined, defining variable with same name\n will throw an error.");io.set("**interaction-environment**",e)}ao(uo,to);io.doc("**interaction-environment**","**interaction-environment**\n\n Internal dynamic, global variable used to find interpreter environment.\n It's used so the read and write functions can locate **internal-env**\n that contain references to stdin, stdout and stderr.");(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(t){var r=e[t]?e[t]:t;io.set(r,ci(r,function(e){yo(r,e,"number");if(e instanceof da){return e[t]()}},"(".concat(r," number)\n\n Function calculate ").concat(r," of a number.")))})})();function oo(e){if(e.length===1){return e[0]}else{var t=[];var r=oo(e.slice(1));for(var n=0;n3&&arguments[3]!==undefined?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(n!==null){i+=" (argument ".concat(n,")")}if(vu(r)){return"Invalid type got ".concat(t).concat(i)}if(r instanceof Array){if(r.length===1){r=r[0]}else{var u=r[r.length-1];r=r.slice(0,-1).join(", ")+" or "+u}}return"Expecting ".concat(r,", got ").concat(t).concat(i)}function vo(r,e,n){e.forEach(function(e,t){yo(r,e,n,t+1)})}function mo(e,t,r){yo(e,t,r);if(t.__type__===Ma){throw new Error(_o(e,"binary-port","textual-port"))}}function yo(e,t,r){var n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;e=e.valueOf();var i=Ao(t).toLowerCase();if(vu(r)){if(!r(t)){throw new Error(_o(e,i,r,n))}return}var u=false;if(r instanceof Ni){r=r.to_array()}if(r instanceof Array){r=r.map(function(e){return e.valueOf()})}if(r instanceof Array){r=r.map(function(e){return e.valueOf().toLowerCase()});if(r.includes(i)){u=true}}else{r=r.valueOf().toLowerCase()}if(!u&&i!==r){throw new Error(_o(e,i,r,n))}}function go(e){var t=_(e);return["string","function"].includes(t)||_(e)==="symbol"||e instanceof Yn||e instanceof Ln||e instanceof da||e instanceof sa||e instanceof RegExp}function bo(e){return e instanceof da||e instanceof sa||e instanceof oa}function wo(e,t){if(e===null){return false}return _(e)==="object"&&t in Object.getOwnPropertySymbols(e)}function Do(e,t){if(wo(e,t)||wo(e.__proto__,t)){return vu(e[t])}}function Eo(r){var n=new WeakMap;return function(e){var t=n.get(e);if(!t){t=r(e)}return t}}Ao=Eo(Ao);function Ao(e){var t=Pr.get(e);if(t){return t}if(_(e)==="object"){for(var r=0,n=Object.entries(Ir);r2&&arguments[2]!==undefined?arguments[2]:{},u=t.env,a=t.dynamic_scope,r=t.error,o=r===void 0?function(){}:r;e=xo(e,{env:u,dynamic_scope:a,error:o});return ni(e,function(e){if(Gu(i)){i=Fu(i)}e=Oo(i,e);var t=e.slice();var r=(a||u).newFrame(i,t);var n=Fo(i.apply(r,e));return ni(n,function(e){if(e instanceof Ni){e.markCycles();return Qa(e)}return wu(e)},o)})}var Bo=function(){function t(e){y(this,t);this.__value__=e}b(t,[{key:"invoke",value:function e(){if(this.__value__===null){throw new Error("Continuations are not implemented yet")}}},{key:"toString",value:function e(){return"#"}}]);return t}();var jo=function e(){};function Io(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=e.env,n=e.dynamic_scope,i=e.error,u=i===void 0?jo:i;try{if(n===true){r=n=r||io}else if(r===true){r=n=io}else{r=r||io}var a={env:r,dynamic_scope:n,error:u};var o;if(du(t)){return t}if(t instanceof Ln){return r.get(t)}if(!(t instanceof Ni)){return t}var s=t.car;var c=t.cdr;if(s instanceof Ni){o=Fo(Io(s,a));if(gu(o)){return o.then(function(e){return Io(new Ni(e,t.cdr),a)})}else if(!yu(o)){throw new Error(Ao(o)+" "+r.get("repr")(o)+" is not callable while evaluating "+t.toString())}}if(s instanceof Ln){o=r.get(s)}else if(vu(s)){o=s}var f;if(o instanceof fu){f=Co(o,t,a)}else if(o instanceof au){f=ko(o,c,a)}else if(vu(o)){f=So(o,c,a)}else if(mu(o)){f=o.invoke()}else if(t instanceof Ni){o=s&&s.toString();throw new Error("".concat(Ao(s)," ").concat(o," is not a function"))}else{return t}var l=r.get(Symbol["for"]("__promise__"),{throwError:false});if(l===true&&gu(f)){f=f.then(function(e){if(e instanceof Ni&&!o[Pu]){return Io(e,a)}return e});return new Yn(f)}return f}catch(e){u&&u.call(r,e,t)}}var Po=Ro(function(e){return e});var No=Ro(function(e,t){return t});function Ro(_){return function(){var n=O(j.mark(function e(r,n,i){var u,a,o,s,c,f,l,h,p;return j.wrap(function e(t){while(1){switch(t.prev=t.next){case 0:if(i===true){n=i=n||uo}else if(n===true){n=i=uo}else{n=n||uo}u=[];a=Array.isArray(r)?r:ti(r);o=false;s=false;t.prev=5;f=F(a);case 7:t.next=9;return f.next();case 9:if(!(o=!(l=t.sent).done)){t.next=27;break}h=l.value;p=Io(h,{env:n,dynamic_scope:i,error:function e(t,r){if(t&&t.message){if(t.message.match(/^Error:/)){var n=/^(Error:)\s*([^:]+:\s*)/;t.message=t.message.replace(n,"$1 $2")}if(r){if(!(t.__code__ instanceof Array)){t.__code__=[]}t.__code__.push(r.toString(true))}}throw t}});if(gu(p)){t.next=16;break}u.push(_(h,p));t.next=24;break;case 16:t.t0=u;t.t1=_;t.t2=h;t.next=21;return p;case 21:t.t3=t.sent;t.t4=(0,t.t1)(t.t2,t.t3);t.t0.push.call(t.t0,t.t4);case 24:o=false;t.next=7;break;case 27:t.next=33;break;case 29:t.prev=29;t.t5=t["catch"](5);s=true;c=t.t5;case 33:t.prev=33;t.prev=34;if(!(o&&f["return"]!=null)){t.next=38;break}t.next=38;return f["return"]();case 38:t.prev=38;if(!s){t.next=41;break}throw c;case 41:return t.finish(38);case 42:return t.finish(33);case 43:return t.abrupt("return",u);case 44:case"end":return t.stop()}}},e,null,[[5,29,33,43],[34,,38,42]])}));function e(e,t,r){return n.apply(this,arguments)}return e}()}function To(e){var t={"[":"]","(":")"};var r;if(typeof e==="string"){r=Nn(e)}else{r=e.map(function(e){return e&&e.token?e.token:e})}var n=Object.keys(t);var i=Object.values(t).concat(n);r=r.filter(function(e){return i.includes(e)});var u=new On;var a=Cr(r),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;if(n.includes(s)){u.push(s)}else if(!u.is_empty()){var c=u.top();var f=t[c];if(s===f){u.pop()}else{throw new Error("Syntax error: missing closing ".concat(f))}}else{throw new Error("Syntax error: not matched closing ".concat(s))}}}catch(e){a.e(e)}finally{a.f()}return u.is_empty()}function Lo(e){var t="("+e.toString()+")()";var r=window.URL||window.webkitURL;var n;try{n=new Blob([t],{type:"application/javascript"})}catch(e){var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;n=new i;n.append(t);n=n.getBlob()}return new jr.Worker(r.createObjectURL(n))}function Uo(){return ps.version.match(/^(\{\{VER\}\}|DEV)$/)}function qo(){if(lo()){return}var e;if(document.currentScript){e=document.currentScript}else{var t=document.querySelectorAll("script");if(!t.length){return}e=t[t.length-1]}var r=e.getAttribute("src");return r}var Mo=qo();function Yo(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"";var t="dist/std.xcb";if(e===""){if(Mo){e=Mo.replace(/[^/]*$/,"std.xcb")}else if(Uo()){e="https://cdn.jsdelivr.net/gh/jcubic/lips@devel/".concat(t)}else{e="https://cdn.jsdelivr.net/npm/@jcubic/lips@".concat(ps.version,"/").concat(t)}}var r=io.get("load");return r.call(uo,e,io)}function $o(e){this.url=e;var a=this.worker=Lo(function(){var a;var o;self.addEventListener("message",function(e){var r=e.data;var t=r.id;if(r.type!=="RPC"||t===null){return}function n(e){self.postMessage({id:t,type:"RPC",result:e})}function i(e){self.postMessage({id:t,type:"RPC",error:e})}if(r.method==="eval"){if(!o){i("Worker RPC: LIPS not initilized, call init first");return}o.then(function(){var e=r.params[0];var t=r.params[1];a.exec(e,t).then(function(e){e=e.map(function(e){return e&&e.valueOf()});n(e)})["catch"](function(e){i(e)})})}else if(r.method==="init"){var u=r.params[0];if(typeof u!=="string"){i("Worker RPC: url is not a string")}else{importScripts("".concat(u,"/dist/lips.min.js"));a=new ps.Interpreter("worker");o=Yo(u);o.then(function(){n(true)})}}})});this.rpc=function(){var n=0;return function e(t,r){var u=++n;return new Promise(function(n,i){a.addEventListener("message",function e(t){var r=t.data;if(r&&r.type==="RPC"&&r.id===u){if(r.error){i(r.error)}else{n(r.result)}a.removeEventListener("message",e)}});a.postMessage({type:"RPC",method:t,id:u,params:r})})}}();this.rpc("init",[e])["catch"](function(e){console.error(e)});this.exec=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return this.rpc("eval",[e,t])}}var zo={pair:function e(t){var r=A(t,2),n=r[0],i=r[1];return Ni(n,i)},number:function e(t){if(sa.isString(t)){return da([t,10])}return da(t)},regex:function e(t){var r=A(t,2),n=r[0],i=r[1];return new RegExp(n,i)},nil:function e(){return Pi},symbol:function e(t){if(sa.isString(t)){return Ln(t)}else if(Array.isArray(t)){return Ln(Symbol["for"](t[0]))}},string:sa,character:oa};var Vo=Object.keys(zo);var Jo={};for(var Go=0,Ho=Object.entries(Vo);Go1){var n=t.reduce(function(e,t){return e+t.length},0);var i=new Uint8Array(n);var u=0;t.forEach(function(e){i.set(e,u);u+=e.length});return i}else if(t.length){return t[0]}}function is(){var e=1;var t=new TextEncoder("utf-8");return t.encode("LIPS".concat(e.toString().padStart(3," ")))}var us=7;function as(e){var t=new TextDecoder("utf-8");var r=t.decode(e.slice(0,us));var n=r.substring(0,4);if(n==="LIPS"){var i=r.match(/^(....).*([0-9]+)$/);if(i){return{type:i[1],version:Number(i[2])}}}return{type:"unknown"}}function os(e){var t=is();var r=rs.encode(e);return ns(t,br(r,{magic:false}))}function ss(e){var t=as(e),r=t.type,n=t.version;if(r==="LIPS"&&n===1){var i=wr(e.slice(us),{magic:false});return rs.decode(i)}else{throw new Error("Invalid file format ".concat(r))}}function cs(e){console.error(e.message||e);if(e.code){console.error(e.code.map(function(e,t){return"[".concat(t+1,"]: ").concat(e)}))}}function fs(){var a=["text/x-lips","text/x-scheme"];var o;function s(r){return new Promise(function(t){var e=r.getAttribute("src");if(e){return fetch(e).then(function(e){return e.text()}).then(No).then(t)["catch"](function(e){cs(e);t()})}else{return No(r.innerHTML).then(t)["catch"](function(e){cs(e);t()})}})}function e(){return new Promise(function(i){var u=Array.from(document.querySelectorAll("script"));return function e(){var t=u.shift();if(!t){i()}else{var r=t.getAttribute("type");if(a.includes(r)){var n=t.getAttribute("bootstrap");if(!o&&typeof n==="string"){return Yo(n).then(function(){return s(t)}).then(e)}else{return s(t).then(e)}}else if(r&&r.match(/lips|lisp/)){console.warn("Expecting "+a.join(" or ")+" found "+r)}return e()}}()})}if(!window.document){return Promise.resolve()}else if(ls){var t=ls;var r=t.getAttribute("bootstrap");if(typeof r==="string"){return Yo(r).then(function(){o=true;return e()})}}return e()}var ls=typeof window!=="undefined"&&window.document&&document.currentScript;if(typeof window!=="undefined"){Ur(window,fs)}var hs=function(){var e=sa("Mon, 15 Nov 2021 19:33:52 +0000").valueOf();var t=e==="{{"+"DATE}}"?new Date:new Date(e);var r=function e(t){return t.toString().padStart(2,"0")};var n=t.getFullYear();var i=[n,r(t.getMonth()+1),r(t.getDate())].join("-");var u="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter 1.0.0-beta.16 (".concat(i,") \nCopyright (c) 2018-").concat(n," Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables. You can also\nuse (help name) to display help for specic function or macro, (apropos name)\nto display list of matched names in environment and (dir object) to list\nproperties of an object.\n").replace(/^.*\n/,"");return u}();ai(di,"__class__","ahead");ai(Ni,"__class__","pair");ai(Ii,"__class__","nil");ai(vi,"__class__","pattern");ai(_i,"__class__","formatter");ai(au,"__class__","macro");ai(fu,"__class__","syntax");ai(Ga,"__class__","environment");ai(Sa,"__class__","input-port");ai(Ba,"__class__","output-port");ai(ja,"__class__","output-port");ai(Ia,"__class__","output-string-port");ai(Na,"__class__","input-string-port");ai(La,"__class__","input-file-port");ai(Pa,"__class__","output-file-port");ai(Ja,"__class__","lips-error");[da,Da,ka,Ea,Oa].forEach(function(e){ai(e,"__class__","number")});ai(oa,"__class__","character");ai(Ln,"__class__","symbol");ai(sa,"__class__","string");ai(Yn,"__class__","promise");var ps={version:"1.0.0-beta.16",banner:hs,date:"Mon, 15 Nov 2021 19:33:52 +0000",exec:No,parse:Xu(oi,ti),tokenize:Nn,evaluate:Io,compile:Po,serialize:es,unserialize:ts,serialize_bin:os,unserialize_bin:ss,bootstrap:Yo,Environment:Ga,env:uo,Worker:$o,Interpreter:Va,balanced_parenthesis:To,balancedParenthesis:To,balanced:To,Macro:au,Syntax:fu,Pair:Ni,Values:Wa,QuotedPromise:Yn,Error:Ja,quote:Qa,InputPort:Sa,OutputPort:Ba,BufferedOutputPort:ja,InputFilePort:La,OutputFilePort:Pa,InputStringPort:Na,OutputStringPort:Ia,InputByteVectorPort:Ra,OutputByteVectorPort:Ta,InputBinaryFilePort:Ua,OutputBinaryFilePort:qa,Formatter:_i,Parser:Xn,Lexer:Zn,specials:Jn,repr:Ti,nil:Pi,eof:$a,LSymbol:Ln,LNumber:da,LFloat:Ea,LComplex:Da,LRational:ka,LBigInteger:Oa,LCharacter:oa,LString:sa,rationalize:xa};io.set("lips",ps);var _s={};var ds=Object.freeze({__proto__:null,default:_s});function vs(e,t){var r=0;for(var n=e.length-1;n>=0;n--){var i=e[n];if(i==="."){e.splice(n,1)}else if(i===".."){e.splice(n,1);r++}else if(r){e.splice(n,1);r--}}if(t){for(;r--;r){e.unshift("..")}}return e}var ms=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;var ys=function(e){return ms.exec(e).slice(1)};function gs(){var e="",t=false;for(var r=arguments.length-1;r>=-1&&!t;r--){var n=r>=0?arguments[r]:"/";if(typeof n!=="string"){throw new TypeError("Arguments to path.resolve must be strings")}else if(!n){continue}e=n+"/"+e;t=n.charAt(0)==="/"}e=vs(Ss(e.split("/"),function(e){return!!e}),!t).join("/");return(t?"/":"")+e||"."}function bs(e){var t=ws(e),r=Bs(e,-1)==="/";e=vs(Ss(e.split("/"),function(e){return!!e}),!t).join("/");if(!e&&!t){e="."}if(e&&r){e+="/"}return(t?"/":"")+e}function ws(e){return e.charAt(0)==="/"}function Ds(){var e=Array.prototype.slice.call(arguments,0);return bs(Ss(e,function(e,t){if(typeof e!=="string"){throw new TypeError("Arguments to path.join must be strings")}return e}).join("/"))}function Es(e,t){e=gs(e).substr(1);t=gs(t).substr(1);function r(e){var t=0;for(;t=0;r--){if(e[r]!=="")break}if(t>r)return[];return e.slice(t,r-t+1)}var n=r(e.split("/"));var i=r(t.split("/"));var u=Math.min(n.length,i.length);var a=u;for(var o=0;o expr . code) "Helper macro that simplify calling methods on objects. It work with chaining\u000Ausage: (--> ($ \"body\")\u000A (css \"color\" \"red\")\u000A (on \"click\" (lambda () (display \"click\"))))\u000A (--> document (querySelectorAll \"div\"))\u000A (--> (fetch \"https://jcubic.pl\")\u000A (text)\u000A (match #/([^<]+)<\\/title>/)\u000A 1)\u000A (--> document\u000A (querySelectorAll \".cmd-prompt\")\u000A 0\u000A 'innerHTML\u000A (replace #/<(\"[^\"]+\"|[^>])+>/g \"\"))\u000A (--> document.body\u000A (style.setProperty \"--color\" \"red\"))" (let ((obj (gensym "obj"))) (quasiquote (let* (((unquote obj) (unquote expr))) (unquote-splicing (map (lambda (code) (let ((value (gensym "value"))) (quasiquote (let* (((unquote value) (unquote (let ((name (cond ((quoted-symbol? code) (symbol->string (cadr code))) ((pair? code) (symbol->string (car code))) (#t code)))) (if (string? name) (quasiquote (. (unquote obj) (unquote-splicing (split "." name)))) (quasiquote (. (unquote obj) (unquote name)))))))) (unquote (if (and (pair? code) (not (quoted-symbol? code))) (quasiquote (set! (unquote obj) ((unquote value) (unquote-splicing (cdr code))))) (quasiquote (set! (unquote obj) (unquote value))))))))) code)) (unquote obj))))) +(define-macro (--> expr . body) "Helper macro that simplify calling methods on objects. It work with chaining\u000Ausage: (--> ($ \"body\")\u000A (css \"color\" \"red\")\u000A (on \"click\" (lambda () (display \"click\"))))\u000A (--> document (querySelectorAll \"div\"))\u000A (--> (fetch \"https://jcubic.pl\")\u000A (text)\u000A (match #/<title>([^<]+)<\\/title>/)\u000A 1)\u000A (--> document\u000A (querySelectorAll \".cmd-prompt\")\u000A 0\u000A 'innerHTML\u000A (replace #/<(\"[^\"]+\"|[^>])+>/g \"\"))\u000A (--> document.body\u000A (style.setProperty \"--color\" \"red\"))" (let ((obj (gensym "obj"))) (quasiquote (let* (((unquote obj) (unquote expr))) (unquote-splicing (map (lambda (code) (let ((value (gensym "value"))) (quasiquote (let* (((unquote value) (unquote (let ((name (cond ((quoted-symbol? code) (symbol->string (cadr code))) ((pair? code) (symbol->string (car code))) (#t code)))) (if (string? name) (quasiquote (. (unquote obj) (unquote-splicing (split "." name)))) (quasiquote (. (unquote obj) (unquote name)))))))) (unquote (if (and (pair? code) (not (quoted-symbol? code))) (quasiquote (set! (unquote obj) ((unquote value) (unquote-splicing (cdr code))))) (quasiquote (set! (unquote obj) (unquote value))))))))) body)) (unquote obj))))) (define-macro (define-global first . rest) "(define-global var value)\u000A(define-global (name . args) body)\u000A\u000AMacro that define functions or variables in global context, so they can be used\u000Ainside let and get let variables in closure, Useful for universal macros." (if (pair? first) (let ((name (car first))) (quasiquote (--> lips.env (set (unquote (symbol->string name)) (lambda (unquote (cdr first)) (unquote-splicing rest)))))) (quasiquote (--> lips.env (set (unquote (symbol->string first)) (unquote (car rest))))))) (define-macro (globalize expr . rest) "(globalize expr)\u000A\u000A Macro will get the value of the expression and add each method as function to global\u000A scope." (let* ((env (current-environment)) (obj (eval expr env)) (name (gensym "name")) (env-name (gensym "env-name")) (make-name (if (pair? rest) (let ((pre (symbol->string (car rest)))) (lambda (name) (string->symbol (concat pre name)))) string->symbol))) (quasiquote (let (((unquote name) (unquote expr))) (unquote-splicing (filter pair? (map (lambda (key) (if (and (not (match #/^_/ key)) (function? (. obj key))) (let* ((args (gensym "args"))) (quasiquote (define-global ((unquote (make-name key)) unquote args) (apply (. (unquote name) (unquote key)) (unquote args))))))) (array->list (--> Object (keys obj)))))))))) (define (single list) "(single list)\u000A\u000AFunction check if argument is list with single element" (and (pair? list) (not (cdr list)))) diff --git a/dist/std.scm b/dist/std.scm index 00bf9ead..2367357f 100644 --- a/dist/std.scm +++ b/dist/std.scm @@ -74,7 +74,7 @@ (and (pair? x) (eq? (car x) 'quote) (symbol? (cadr x)) (null? (cddr x)))) ;; ----------------------------------------------------------------------------- -(define-macro (--> expr . code) +(define-macro (--> expr . body) "Helper macro that simplify calling methods on objects. It work with chaining usage: (--> ($ \"body\") (css \"color\" \"red\") @@ -104,7 +104,7 @@ ,(if (and (pair? code) (not (quoted-symbol? code))) `(set! ,obj (,value ,@(cdr code))) `(set! ,obj ,value))))) - code) + body) ,obj))) diff --git a/dist/std.xcb b/dist/std.xcb index 5fbca5ce..e2da5d0e 100644 Binary files a/dist/std.xcb and b/dist/std.xcb differ diff --git a/package.json b/package.json index a073c4d7..2fdd4361 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jcubic/lips", - "version": "1.0.0-beta.15", + "version": "1.0.0-beta.16", "description": "Simple Scheme Like Lisp in JavaScript", "main": "src/lips.js", "type": "module",