diff --git a/CHANGELOG.md b/CHANGELOG.md index 44680f5ba..ac1381e25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * persistent history in executable REPL * repr of promises (from `delay` function) * allow `set!` with doted JS notation +* new function `gensym?` ### Bugfix * fix Environment::has (ref) on variable that are undefined * fix macroexpand with pprint on syntax macros @@ -23,6 +24,7 @@ * fix identifiers in syntax-rules * fix byte vectors * make print and pprint always call newline +* fix escape ellipsis from R7RS ## 1.0.0-beta.3 ## Bugfix diff --git a/README.md b/README.md index b62c16e3d..832dc90a4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Join the chat at https://gitter.im/jcubic/lips](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips) [![npm](https://img.shields.io/badge/npm-DEV-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) -[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&29e6364a2bdde7c67a1b0d9c62d8c705b1cbbadf)](https://travis-ci.org/jcubic/lips) +[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&e0d5a0cd8916f268bddf42ee7efd6554b8cb5ff0)](https://travis-ci.org/jcubic/lips) [![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&2c48907438a7265935a7b21e6931008d)](https://coveralls.io/github/jcubic/lips?branch=devel) diff --git a/dist/lips.js b/dist/lips.js index ff8105540..e25c5103d 100644 --- a/dist/lips.js +++ b/dist/lips.js @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Thu, 20 Aug 2020 19:59:43 +0000 + * build: Fri, 21 Aug 2020 07:44:49 +0000 */ (function () { 'use strict'; @@ -2710,7 +2710,46 @@ LSymbol.prototype.valueOf = function () { return this.name.valueOf(); - }; // ---------------------------------------------------------------------- + }; // ------------------------------------------------------------------------- + + + LSymbol.prototype.is_gensym = function () { + return is_gensym(this.name); + }; // ------------------------------------------------------------------------- + + + function is_gensym(symbol) { + if (_typeof_1(symbol) === 'symbol') { + return !!symbol.toString().match(/^Symbol\(#:/); + } + + return false; + } // ------------------------------------------------------------------------- + + + var gensym = function () { + var count = 0; + return function () { + var name = arguments.length > 0 && arguments[0] !== undefined$1 ? arguments[0] : null; + + if (name instanceof LSymbol) { + name = name.valueOf(); + } + + if (is_gensym(name)) { + // don't do double gynsyms in nested syntax-rules + return LSymbol(name); + } // use ES6 symbol as name for lips symbol (they are unique) + + + if (name !== null) { + return new LSymbol(Symbol("#:".concat(name))); + } + + count++; + return new LSymbol(Symbol("#:g".concat(count))); + }; + }(); // ---------------------------------------------------------------------- // :: Nil constructor with only once instance // ---------------------------------------------------------------------- @@ -4121,8 +4160,9 @@ return gensyms[name]; } - function transform_ellipsis_expr(expr, bindings, nested) { + function transform_ellipsis_expr(expr, bindings, state) { var next = arguments.length > 3 && arguments[3] !== undefined$1 ? arguments[3] : function () {}; + var nested = state.nested; log(' ==> ' + expr.toString()); if (expr instanceof LSymbol) { @@ -4223,8 +4263,11 @@ } log('[t 3 recur ' + expr.toString()); - var head = transform_ellipsis_expr(expr.car, bindings, nested, next); - var rest = transform_ellipsis_expr(expr.cdr, bindings, nested, next); + var new_state = { + nested: nested + }; + var head = transform_ellipsis_expr(expr.car, bindings, new_state, next); + var rest = transform_ellipsis_expr(expr.cdr, bindings, new_state, next); log({ b: true, head: head && head.toString(), @@ -4254,10 +4297,20 @@ } function traverse(expr) { + var _ref12 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, + disabled = _ref12.disabled; + log('>> ' + expr.toString()); if (expr instanceof Pair) { - if (expr.cdr instanceof Pair && LSymbol.is(expr.cdr.car, ellipsis_symbol)) { + // escape ellispsis from R7RS e.g. (... ...) + if (!disabled && expr.car instanceof Pair && LSymbol.is(expr.car.car, ellipsis_symbol)) { + return traverse(expr.car.cdr, { + disabled: true + }); + } + + if (expr.cdr instanceof Pair && LSymbol.is(expr.cdr.car, ellipsis_symbol) && !disabled) { log('>> 1'); var _symbols = bindings['...'].symbols; var keys = get_names(_symbols); // case of list as first argument ((x . y) ...) @@ -4298,7 +4351,9 @@ new_bind[key] = value; }; - var car = transform_ellipsis_expr(expr.car, _bind, true, next); // undefined can be null caused by null binding + var car = transform_ellipsis_expr(expr.car, _bind, { + nested: true + }, next); // undefined can be null caused by null binding // on empty ellipsis if (car !== undefined$1) { @@ -4321,7 +4376,9 @@ return result; } else { log('>> 3'); - var car = transform_ellipsis_expr(expr.car, _symbols, true); + var car = transform_ellipsis_expr(expr.car, _symbols, { + nested: true + }); if (car) { return new Pair(car, nil); @@ -4374,15 +4431,21 @@ if (expr.cdr instanceof Pair && expr.cdr.cdr instanceof Pair) { - _result2.append(traverse(expr.cdr.cdr)); + _result2.append(traverse(expr.cdr.cdr, { + disabled: disabled + })); } return _result2; } } - var head = traverse(expr.car); - var rest = traverse(expr.cdr); + var head = traverse(expr.car, { + disabled: disabled + }); + var rest = traverse(expr.cdr, { + disabled: disabled + }); log({ a: true, head: head && head.toString(), @@ -4392,6 +4455,10 @@ } if (expr instanceof LSymbol) { + if (disabled && LSymbol.is(expr, ellipsis_symbol)) { + return expr; + } + var value = transform(expr); if (typeof value !== 'undefined') { @@ -4402,7 +4469,7 @@ return expr; } - return traverse(expr); + return traverse(expr, {}); } // ---------------------------------------------------------------------- // :: check for nullish values // ---------------------------------------------------------------------- @@ -4705,9 +4772,9 @@ } }).then(exec); } else { - values.forEach(function (_ref12) { - var name = _ref12.name, - value = _ref12.value; + values.forEach(function (_ref13) { + var name = _ref13.name, + value = _ref13.value; set(name, value); }); } @@ -4751,9 +4818,9 @@ function pararel(name, fn) { return new Macro(name, function (code) { - var _ref13 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, - dynamic_scope = _ref13.dynamic_scope, - error = _ref13.error; + var _ref14 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, + dynamic_scope = _ref14.dynamic_scope, + error = _ref14.error; var env = this; @@ -7034,26 +7101,6 @@ } // ------------------------------------------------------------------------- - var gensym = function () { - var count = 0; - return function () { - var name = arguments.length > 0 && arguments[0] !== undefined$1 ? arguments[0] : null; - - if (name instanceof LSymbol) { - name = name.valueOf(); - } // use ES6 symbol as name for lips symbol (they are unique) - - - if (name !== null) { - return new LSymbol(Symbol("#:".concat(name))); - } - - count++; - return new LSymbol(Symbol("#:g".concat(count))); - }; - }(); // ------------------------------------------------------------------------- - - var global_env = new Environment({ nil: nil, 'undefined': undefined$1, @@ -7243,9 +7290,9 @@ return unbind(a) === unbind(b); }, "(%same-functions a b)\n\n Helper function that check if two bound functions are the same"), // ------------------------------------------------------------------ - help: doc(new Macro('help', function (code, _ref14) { - var dynamic_scope = _ref14.dynamic_scope, - error = _ref14.error; + help: doc(new Macro('help', function (code, _ref15) { + var dynamic_scope = _ref15.dynamic_scope, + error = _ref15.error; var symbol; if (code.car instanceof LSymbol) { @@ -7311,9 +7358,9 @@ 'set!': doc(new Macro('set!', function (code) { var _this5 = this; - var _ref15 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, - dynamic_scope = _ref15.dynamic_scope, - error = _ref15.error; + var _ref16 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, + dynamic_scope = _ref16.dynamic_scope, + error = _ref16.error; if (dynamic_scope) { dynamic_scope = this; @@ -7518,9 +7565,9 @@ }); }, "(load filename)\n\n Function fetch the file and evaluate its content as LIPS code."), // ------------------------------------------------------------------ - 'while': doc(new Macro('while', function (code, _ref16) { - var dynamic_scope = _ref16.dynamic_scope, - error = _ref16.error; + 'while': doc(new Macro('while', function (code, _ref17) { + var dynamic_scope = _ref17.dynamic_scope, + error = _ref17.error; var self = this; var begin = new Pair(new LSymbol('begin'), code.cdr); var result; @@ -7561,9 +7608,9 @@ }(); }), "(while cond . body)\n\n Macro that create a loop, it exectue body untill cond expression is false"), // ------------------------------------------------------------------ - 'if': doc(new Macro('if', function (code, _ref17) { - var dynamic_scope = _ref17.dynamic_scope, - error = _ref17.error; + 'if': doc(new Macro('if', function (code, _ref18) { + var dynamic_scope = _ref18.dynamic_scope, + error = _ref18.error; if (dynamic_scope) { dynamic_scope = this; @@ -7652,9 +7699,9 @@ }(); }), "(begin . args)\n\n Macro runs list of expression and return valuate of the list one.\n It can be used in place where you can only have single exression,\n like if expression."), // ------------------------------------------------------------------ - 'ignore': new Macro('ignore', function (code, _ref18) { - var dynamic_scope = _ref18.dynamic_scope, - error = _ref18.error; + 'ignore': new Macro('ignore', function (code, _ref19) { + var dynamic_scope = _ref19.dynamic_scope, + error = _ref19.error; var args = { env: this, error: error @@ -7804,9 +7851,9 @@ }, "(eval list)\n\n Function evalute LIPS code as list structure."), // ------------------------------------------------------------------ lambda: new Macro('lambda', function (code) { - var _ref19 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, - dynamic_scope = _ref19.dynamic_scope, - error = _ref19.error; + var _ref20 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, + dynamic_scope = _ref20.dynamic_scope, + error = _ref20.error; var self = this; @@ -7909,9 +7956,9 @@ 'macroexpand': new Macro('macroexpand', macro_expand()), 'macroexpand-1': new Macro('macroexpand-1', macro_expand(true)), // ------------------------------------------------------------------ - 'define-macro': doc(new Macro(macro, function (macro, _ref20) { - var dynamic_scope = _ref20.dynamic_scope, - error = _ref20.error; + 'define-macro': doc(new Macro(macro, function (macro, _ref21) { + var dynamic_scope = _ref21.dynamic_scope, + error = _ref21.error; if (macro.car instanceof Pair && macro.car.car instanceof LSymbol) { var name = macro.car.car.name; @@ -8023,8 +8070,8 @@ validate_identifiers(macro.car); } - var syntax = new Syntax(function (code, _ref21) { - var macro_expand = _ref21.macro_expand; + var syntax = new Syntax(function (code, _ref22) { + var macro_expand = _ref22.macro_expand; var scope = env.inherit('syntax'); if (dynamic_scope) { @@ -8145,10 +8192,10 @@ } if (isPromise(car) || isPromise(cdr)) { - return Promise.all([car, cdr]).then(function (_ref22) { - var _ref23 = slicedToArray(_ref22, 2), - car = _ref23[0], - cdr = _ref23[1]; + return Promise.all([car, cdr]).then(function (_ref23) { + var _ref24 = slicedToArray(_ref23, 2), + car = _ref24[0], + cdr = _ref24[1]; return new Pair(car, cdr); }); @@ -8672,11 +8719,11 @@ return false; }, "(string->number number [radix])\n\n Function convert string to number."), // ------------------------------------------------------------------ - 'try': doc(new Macro('try', function (code, _ref24) { + 'try': doc(new Macro('try', function (code, _ref25) { var _this7 = this; - var dynamic_scope = _ref24.dynamic_scope, - _error = _ref24.error; + var dynamic_scope = _ref25.dynamic_scope, + _error = _ref25.error; return new Promise(function (resolve) { var args = { env: _this7, @@ -9122,9 +9169,9 @@ // ------------------------------------------------------------------ 'eq?': doc(equal, "(eq? a b)\n\n Function compare two values if they are identical."), // ------------------------------------------------------------------ - or: doc(new Macro('or', function (code, _ref25) { - var dynamic_scope = _ref25.dynamic_scope, - error = _ref25.error; + or: doc(new Macro('or', function (code, _ref26) { + var dynamic_scope = _ref26.dynamic_scope, + error = _ref26.error; var args = this.get('list->array')(code); var self = this; @@ -9164,9 +9211,9 @@ }), "(or . expressions)\n\n Macro execute the values one by one and return the one that is truthy value.\n If there are no expression that evaluate to true it return false."), // ------------------------------------------------------------------ and: doc(new Macro('and', function (code) { - var _ref26 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, - dynamic_scope = _ref26.dynamic_scope, - error = _ref26.error; + var _ref27 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, + dynamic_scope = _ref27.dynamic_scope, + error = _ref27.error; var args = this.get('list->array')(code); var self = this; @@ -9606,10 +9653,10 @@ } } - function getFunctionArgs(rest, _ref27) { - var env = _ref27.env, - dynamic_scope = _ref27.dynamic_scope, - error = _ref27.error; + function getFunctionArgs(rest, _ref28) { + var env = _ref28.env, + dynamic_scope = _ref28.dynamic_scope, + error = _ref28.error; var args = []; var node = rest; markCycles(node); @@ -9682,11 +9729,11 @@ function evaluate(code) { - var _ref28 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, - env = _ref28.env, - dynamic_scope = _ref28.dynamic_scope, - _ref28$error = _ref28.error, - error = _ref28$error === void 0 ? function () {} : _ref28$error; + var _ref29 = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : {}, + env = _ref29.env, + dynamic_scope = _ref29.dynamic_scope, + _ref29$error = _ref29.error, + error = _ref29$error === void 0 ? function () {} : _ref29$error; try { if (dynamic_scope === true) { @@ -10155,10 +10202,10 @@ var banner = function () { // Rollup tree-shaking is removing the variable if it's normal string because - // obviously 'Thu, 20 Aug 2020 19:59:43 +0000' == '{{' + 'DATE}}'; can be removed + // obviously 'Fri, 21 Aug 2020 07:44:49 +0000' == '{{' + 'DATE}}'; can be removed // but disablig Tree-shaking is adding lot of not used code so we use this // hack instead - var date = LString('Thu, 20 Aug 2020 19:59:43 +0000').valueOf(); + var date = LString('Fri, 21 Aug 2020 07:44:49 +0000').valueOf(); var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date); @@ -10195,7 +10242,7 @@ var lips = { version: 'DEV', banner: banner, - date: 'Thu, 20 Aug 2020 19:59:43 +0000', + date: 'Fri, 21 Aug 2020 07:44:49 +0000', exec: exec, parse: parse, tokenize: tokenize, diff --git a/dist/lips.min.js b/dist/lips.min.js index 4cc024e9d..220f1b92d 100644 --- a/dist/lips.min.js +++ b/dist/lips.min.js @@ -31,6 +31,6 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Thu, 20 Aug 2020 19:59:43 +0000 + * build: Fri, 21 Aug 2020 07:44:49 +0000 */ -(function(){"use strict";function e(e){throw new Error('"'+e+'" is read-only')}var Lt=e;function n(e,n){return n={exports:{}},e(n,n.exports),n.exports}var u=n(function(t){function r(e,n){t.exports=r=Object.setPrototypeOf||function e(n,t){n.__proto__=t;return n};return r(e,n)}t.exports=r});function t(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Date.prototype.toString.call(Reflect.construct(Date,[],function(){}));return true}catch(e){return false}}var a=t;var qt=n(function(r){function i(e,n,t){if(a()){r.exports=i=Reflect.construct}else{r.exports=i=function e(n,t,r){var i=[null];i.push.apply(i,t);var a=Function.bind.apply(n,i);var o=new a;if(r)u(o,r.prototype);return o}}return i.apply(null,arguments)}r.exports=i});var r=n(function(e){var n=function(o){var e=Object.prototype;var f=e.hasOwnProperty;var c;var n=typeof Symbol==="function"?Symbol:{};var i=n.iterator||"@@iterator";var t=n.asyncIterator||"@@asyncIterator";var r=n.toStringTag||"@@toStringTag";function u(e,n,t,r){var i=n&&n.prototype instanceof s?n:s;var a=Object.create(i.prototype);var o=new F(r||[]);a._invoke=O(e,t,o);return a}o.wrap=u;function l(e,n,t){try{return{type:"normal",arg:e.call(n,t)}}catch(e){return{type:"throw",arg:e}}}var p="suspendedStart";var h="suspendedYield";var v="executing";var d="completed";var m={};function s(){}function a(){}function y(){}var g={};g[i]=function(){return this};var b=Object.getPrototypeOf;var w=b&&b(b(A([])));if(w&&w!==e&&f.call(w,i)){g=w}var _=y.prototype=s.prototype=Object.create(g);a.prototype=_.constructor=y;y.constructor=a;y[r]=a.displayName="GeneratorFunction";function x(e){["next","throw","return"].forEach(function(n){e[n]=function(e){return this._invoke(n,e)}})}o.isGeneratorFunction=function(e){var n=typeof e==="function"&&e.constructor;return n?n===a||(n.displayName||n.name)==="GeneratorFunction":false};o.mark=function(e){if(Object.setPrototypeOf){Object.setPrototypeOf(e,y)}else{e.__proto__=y;if(!(r in e)){e[r]="GeneratorFunction"}}e.prototype=Object.create(_);return e};o.awrap=function(e){return{__await:e}};function S(u,c){function s(e,n,t,r){var i=l(u[e],u,n);if(i.type==="throw"){r(i.arg)}else{var a=i.arg;var o=a.value;if(o&&typeof o==="object"&&f.call(o,"__await")){return c.resolve(o.__await).then(function(e){s("next",e,t,r)},function(e){s("throw",e,t,r)})}return c.resolve(o).then(function(e){a.value=e;t(a)},function(e){return s("throw",e,t,r)})}}var n;function e(t,r){function e(){return new c(function(e,n){s(t,r,e,n)})}return n=n?n.then(e,e):e()}this._invoke=e}x(S.prototype);S.prototype[t]=function(){return this};o.AsyncIterator=S;o.async=function(e,n,t,r,i){if(i===void 0)i=Promise;var a=new S(u(e,n,t,r),i);return o.isGeneratorFunction(n)?a:a.next().then(function(e){return e.done?e.value:a.next()})};function O(o,u,c){var s=p;return function e(n,t){if(s===v){throw new Error("Generator is already running")}if(s===d){if(n==="throw"){throw t}return I()}c.method=n;c.arg=t;while(true){var r=c.delegate;if(r){var i=k(r,c);if(i){if(i===m)continue;return i}}if(c.method==="next"){c.sent=c._sent=c.arg}else if(c.method==="throw"){if(s===p){s=d;throw c.arg}c.dispatchException(c.arg)}else if(c.method==="return"){c.abrupt("return",c.arg)}s=v;var a=l(o,u,c);if(a.type==="normal"){s=c.done?d:h;if(a.arg===m){continue}return{value:a.arg,done:c.done}}else if(a.type==="throw"){s=d;c.method="throw";c.arg=a.arg}}}}function k(e,n){var t=e.iterator[n.method];if(t===c){n.delegate=null;if(n.method==="throw"){if(e.iterator["return"]){n.method="return";n.arg=c;k(e,n);if(n.method==="throw"){return m}}n.method="throw";n.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var r=l(t,e.iterator,n.arg);if(r.type==="throw"){n.method="throw";n.arg=r.arg;n.delegate=null;return m}var i=r.arg;if(!i){n.method="throw";n.arg=new TypeError("iterator result is not an object");n.delegate=null;return m}if(i.done){n[e.resultName]=i.value;n.next=e.nextLoc;if(n.method!=="return"){n.method="next";n.arg=c}}else{return i}n.delegate=null;return m}x(_);_[r]="Generator";_[i]=function(){return this};_.toString=function(){return"[object Generator]"};function E(e){var n={tryLoc:e[0]};if(1 in e){n.catchLoc=e[1]}if(2 in e){n.finallyLoc=e[2];n.afterLoc=e[3]}this.tryEntries.push(n)}function j(e){var n=e.completion||{};n.type="normal";delete n.arg;e.completion=n}function F(e){this.tryEntries=[{tryLoc:"root"}];e.forEach(E,this);this.reset(true)}o.keys=function(t){var r=[];for(var e in t){r.push(e)}r.reverse();return function e(){while(r.length){var n=r.pop();if(n in t){e.value=n;e.done=false;return e}}e.done=true;return e}};function A(n){if(n){var e=n[i];if(e){return e.call(n)}if(typeof n.next==="function"){return n}if(!isNaN(n.length)){var t=-1,r=function e(){while(++t=0;--n){var i=this.tryEntries[n];var a=i.completion;if(i.tryLoc==="root"){return e("end")}if(i.tryLoc<=this.prev){var o=f.call(i,"catchLoc");var u=f.call(i,"finallyLoc");if(o&&u){if(this.prev=0;--t){var r=this.tryEntries[t];if(r.tryLoc<=this.prev&&f.call(r,"finallyLoc")&&this.prev=0;--n){var t=this.tryEntries[n];if(t.finallyLoc===e){this.complete(t.completion,t.afterLoc);j(t);return m}}},catch:function(e){for(var n=this.tryEntries.length-1;n>=0;--n){var t=this.tryEntries[n];if(t.tryLoc===e){var r=t.completion;if(r.type==="throw"){var i=r.arg;j(t)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,t){this.delegate={iterator:A(e),resultName:n,nextLoc:t};if(this.method==="next"){this.arg=c}return m}};return o}(e.exports);try{regeneratorRuntime=n}catch(e){Function("r","regeneratorRuntime = r")(n)}});var Pt=r;function c(e,n,t,r,i,a,o){try{var u=e[a](o);var c=u.value}catch(e){t(e);return}if(u.done){n(c)}else{Promise.resolve(c).then(r,i)}}function i(u){return function(){var e=this,o=arguments;return new Promise(function(n,t){var r=u.apply(e,o);function i(e){c(r,n,t,i,a,"next",e)}function a(e){c(r,n,t,i,a,"throw",e)}i(undefined)})}}var Rt=i;function o(e){if(Array.isArray(e))return e}var s=o;function f(e){if(typeof Symbol!=="undefined"&&Symbol.iterator in Object(e))return Array.from(e)}var l=f;function p(e,n){if(n==null||n>e.length)n=e.length;for(var t=0,r=new Array(n);t=0)continue;t[i]=e[i]}return t}var E=k;function j(e,n){if(e==null)return{};var t=E(e,n);var r,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,r))continue;t[r]=e[r]}}return t}var Bt=j;function F(e,n){if(typeof Symbol==="undefined"||!(Symbol.iterator in Object(e)))return;var t=[];var r=true;var i=false;var a=undefined;try{for(var o=e[Symbol.iterator](),u;!(r=(u=o.next()).done);r=true){t.push(u.value);if(n&&t.length===n)break}}catch(e){i=true;a=e}finally{try{if(!r&&o["return"]!=null)o["return"]()}finally{if(i)throw a}}return t}var A=F;function I(e,n){return s(e)||A(e,n)||d(e,n)||y()}var $t=I;var Dt=n(function(n){function t(e){"@babel/helpers - typeof";if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){n.exports=t=function e(n){return typeof n}}else{n.exports=t=function e(n){return n&&typeof Symbol==="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n}}return t(e)}n.exports=t});function Ut(n){if(typeof Symbol==="undefined"||n[Symbol.iterator]==null){if(Array.isArray(n)||(n=N(n))){var t=0;var e=function e(){};return{s:e,n:function e(){if(t>=n.length)return{done:true};return{done:false,value:n[t++]}},e:function e(n){throw n},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,i=true,a=false,o;return{s:function e(){r=n[Symbol.iterator]()},n:function e(){var n=r.next();i=n.done;return n},e:function e(n){a=true;o=n},f:function e(){try{if(!i&&r["return"]!=null)r["return"]()}finally{if(a)throw o}}}}function N(e,n){if(!e)return;if(typeof e==="string")return L(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);if(t==="Object"&&e.constructor)t=e.constructor.name;if(t==="Map"||t==="Set")return Array.from(e);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return L(e,n)}function L(e,n){if(n==null||n>e.length)n=e.length;for(var t=0,r=new Array(n);t1&&arguments[1]!==O?arguments[1]:10;var t=F(e);var r=t.number.split("/");var i=$n({num:qn([r[0],t.radix||n]),denom:qn([r[1],t.radix||n])});if(t.inexact){return i.valueOf()}else{return i}}function I(e){var n=arguments.length>1&&arguments[1]!==O?arguments[1]:10;var t=F(e);if(t.inexact){return Rn(parseInt(t.number,t.radix||n))}return qn([t.number,t.radix||n])}function N(e){var n=e.match(/#\\x([0-9a-f]+)$/i);var t;if(n){var r=parseInt(n[1],16);t=String.fromCodePoint(r)}else{n=e.match(/#\\(.+)$/);if(n){t=n[1]}}if(t){return kn(t)}}function L(e){var i=arguments.length>1&&arguments[1]!==O?arguments[1]:10;function n(e){var n;if(e==="+"){n=qn(1)}else if(e==="-"){n=qn(-1)}else if(e.match(x)){n=qn([e,i])}else if(e.match(S)){var t=e.split("/");n=$n({num:qn([t[0],i]),denom:qn([t[1],i])})}else if(e.match(c)){var r=Rn(parseFloat(e));if(a.exact){return r.toRational()}return r}else{throw new Error("Internal Parser Error")}if(a.inexact){return Rn(n.valueOf())}return n}var a=F(e);i=a.radix||i;var t;var r=a.number.match(E);if(i!==10&&r){t=r}else{t=a.number.match(l[i])}var o,u;u=n(t[2]);if(t[1]){o=n(t[1])}else if(u instanceof Rn){o=Rn(0)}else{o=qn(0)}return Pn({im:u,re:o})}function q(e){return parseInt(e.toString(),10)===e}function P(e){var n=e.match(/^(([-+]?[0-9]*)(?:\.([0-9]+))?)e([-+]?[0-9]+)/i);if(n){var t=parseInt(n[4],10);var r;var i=n[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var a=n[3]&&n[3].length;if(i0){return qn(a).mul(u)}}}t=Rn(t);if(n.exact){return t.toRational()}return t}function C(e){var n=/([^\\\n])(\\(?:\\{2})*)(?!x[0-9A-F]+)(?!u[0-9A-F]{2,4})(.)/gi;e=e.replace(n,function(e,n,t,r){if(!['"',"/","b","f","n","\\","r","t","x"].includes(r)){t=t.substring(1).replace(/\\\\/,"\\")}return e}).replace(/\\x([0-9a-f]+);/gi,function(e,n){return"\\u"+n.padStart(4,"0")}).replace(/\n/g,"\\n");var t=e.match(/(\\*)(\\x[0-9A-F])/i);if(t&&t[1].length%2===0){throw new Error("Invalid string literal, unclosed ".concat(t[2]))}try{return En(JSON.parse(e))}catch(e){throw new Error("Invalid string literal")}}function M(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var t={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,n){return String.fromCharCode(parseInt("0"+n,16))}).replace(/\\(.)/g,function(e,n){return t[n]||n})}return new Oe(e)}function T(e){var n=e.match(a);if(n){return new RegExp(n[1],n[2])}else if(e.match(/^"/)){return C(e)}else if(e.match(m)){return N(e)}else if(e.match(w)){return A(e)}else if(e.match(b)){return L(e)}else if(e.match(_)){return I(e)}else if(e.match(c)){return R(e)}else if(e==="nil"){return Ee}else if(["true","#t"].includes(e)){return true}else if(["false","#f"].includes(e)){return false}else{return M(e)}}function B(e){return!(["(",")"].includes(e)||e.match(a)||e.match(/^"[\s\S]+"$/)||e.match(_)||e.match(c)||e.match(b)||e.match(w)||["#t","#f","nil","true","false"].includes(e))}var $=/("(?:\\[\S\s]|[^"])*"?|\/(?! )[^\n\/\\]*(?:\\[\S\s][^\n\/\\]*)*\/[gimy]*(?=[\s[\]()]|$)|\|[^|\s\n]+\||#;|;.*|#\|(?!\|#)[\s\S]*\|#)/g;var D=/"(?:\\[\S\s]|[^"])*"?/g;var U=[r,n,i].map(y).join("|");function H(){var e=K.names().sort(function(e,n){return n.length-e.length||e.localeCompare(n)}).map(Y).join("|");return new RegExp("(".concat(d,"|#f|#t|#;|(?:").concat(U,")(?=$|[\\n\\s()[\\]])|\\[|\\]|\\(|\\)|\\|[^|]+\\||;.*|(?:#[ei])?").concat(o,"(?=$|[\\n\\s()[\\]])|\\n|\\.{2,}|'(?=#[ft]|(?:#[xiobe]){1,2}|#\\\\)|(?!#:)(?:").concat(e,")|[^(\\s)[\\]]+)"),"gim")}function J(e){var n=arguments.length>1&&arguments[1]!==O?arguments[1]:1;return e[e.length-n]}function Y(e){if(typeof e==="string"){var n=/([-\\^$[\]()+{}?*.|])/g;return e.replace(n,"\\$1")}}function G(){this.data=[]}G.prototype.push=function(e){this.data.push(e)};G.prototype.top=function(){return this.data[this.data.length-1]};G.prototype.pop=function(){return this.data.pop()};G.prototype.is_empty=function(){return!this.data.length};function V(e){var a=H();e=e.replace(/\n\r|\r/g,"\n");var o=0;var u=0;var c=[];var s=[];var f=0;e.split($).filter(Boolean).forEach(function(e){if(e.match($)){f=0;if(s.length){var n=J(s);if(n.token.match(/\n/)){var t=n.token.split("\n").pop();f+=t.length}else{f+=n.token.length}f+=n.col}var r={col:f,line:u,token:e,offset:o};c.push(r);s.push(r);o+=e.length;f+=e.length;u+=(e.match("\n")||[]).length;return}var i=e.split(a).filter(Boolean);i.forEach(function(e){var n={col:f,line:u,token:e,offset:o};f+=e.length;o+=e.length;c.push(n);s.push(n);if(e==="\n"){++u;s=[];f=0}})});return c}function z(e){var n=e.token,t=Bt(e,["token"]);if(n.match(/^"[\s\S]+"$/)&&n.match(/\n/)){var r=new RegExp("^ {1,"+(e.col+1)+"}","mg");n=n.replace(r,"")}return Ht({token:n},t)}function W(e,n){var t=arguments.length>2&&arguments[2]!==O?arguments[2]:z;if(e instanceof En){e=e.toString()}if(n){return V(e).map(t)}else{var r=V(e).map(function(e){var n=t(e);if(!n||typeof n.token!=="string"){throw new Error("[tokenize] Invalid formatter wrong return object")}if(n.token==="#\\ "){return n.token}return n.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return Q(r)}}function Q(e){var n=0;var t=null;var r=[];for(var i=0;i1&&!e[0].literal){c.pop();if(c[c.length-1].length===1&&c[c.length-1][0]instanceof Oe){c[c.length-1].push(e)}else if(c[c.length-1]instanceof je){if(c[c.length-1].cdr instanceof je){c[c.length-1]=new je(c[c.length-1],je.fromArray(e))}else{c[c.length-1].cdr=je.fromArray(e)}}else{c[c.length-1].push(e)}}}e.forEach(function(e){var n=c[c.length-1];if(l.indexOf(e)!==-1){y++;f=e;c.push([K.get(f).symbol]);if(!f){m=[]}m.push(f)}else{if(f){d.push(m);m=[]}if(b(e)){v=true;h++;var t=[];if(f&&!X(f)){t.push(g)}c.push(t);f=null;y=0}else if(e==="."&&!v){c[c.length-1]=je.fromArray(n)}else if(w(e)){h--;if(!c.length){throw new Error("Unbalanced parenthesis")}if(c.length===1){var r=c.pop();if(r instanceof Array&&r.length===0){r=Ee}s.push(r)}else if(c.length>1){var i=c.pop();n=c[c.length-1];if(n instanceof Array){if(i.length===0){n.push(Ee)}else if(i instanceof Array&&i[0]===g){var a;(a=n).push.apply(a,Mt(i.slice(1)))}else{n.push(i)}}else if(n instanceof je){if(i.length===0){n.append(Ee)}else{n.append(je.fromArray(i))}}if(d.length){m=d.pop();while(m.length){_();m.pop()}}else{_()}}if(h===0&&c.length){s.push(c.pop())}}else{v=false;var o=T(e);if(f){while(y--){c[c.length-1].push(o);o=c.pop()}d.pop();y=0;f=false}else if(o instanceof Oe&&p.includes(o.name)){o.literal=true}n=c[c.length-1];if(n instanceof je){var u=n;while(true){if(u.cdr===Ee){if(o instanceof Array){u.cdr=je.fromArray(o)}else{u.cdr=o}break}else{u=u.cdr}}}else if(!c.length){s.push(o)}else{n.push(o)}}}});if(!e.filter(function(e){return e.match(/^[[\]()]$/)}).length&&c.length){s=s.concat(c);c=[]}if(c.length){throw new Error("Unbalanced parenthesis 2")}return s.map(function(e){if(e instanceof Array){return je.fromArray(e)}return e})}function ne(e){var n=arguments.length>1&&arguments[1]!==O?arguments[1]:function(e){return e};var t=arguments.length>2&&arguments[2]!==O?arguments[2]:null;if(e instanceof Array){var r=e.filter(ze);if(r.length){return ne(Promise.all(r),n,t)}return n(e)}if(ze(e)){var i=e.then(n);if(t===null){return i}else{return i["catch"](t)}}return n(e)}function te(e,n){if(n instanceof RegExp){return function(e){return String(e).match(n)}}else if(typeof n!=="function"){throw new Error("".concat(e," argument need to be a function or RegExp"))}else{return n}}function re(e,n,t){if(n){if(t){e.__doc__=n}else{e.__doc__=ie(n)}}return e}function ie(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function ae(e){var n=arguments.length>1&&arguments[1]!==O?arguments[1]:1;var t=e.length;if(n<=0){throw Error("previousSexp: Invlaid argument sexp = ".concat(n))}e:while(n--&&t>=0){var r=1;while(r>0){var i=e[--t];if(!i){break e}if(i==="("||i.token==="("){r--}else if(i===")"||i.token===")"){r++}}t--}return e.slice(t+1)}function oe(e){if(!e||!e.length){return 0}var n=e.length;if(e[n-1].token==="\n"){return 0}while(--n){if(e[n].token==="\n"){var t=(e[n+1]||{}).token;if(t){return t.length}}}return 0}function ue(e,n){return f(e,n)===n.length;function f(t,r){function e(){return a>0&&u>0&&t[a-1]===r[u-1]&&t[a+1]===r[u]}function n(){return t[a]===Symbol["for"]("symbol")&&!B(r[u])}function i(){var e=t[a+1];var n=r[u+1];if(e!==O&&n!==O){return f([e],[n])}}var a=0;var o={};for(var u=0;u0){continue}}else if(n()){return-1}}else if(t[a]instanceof Array){var s=f(t[a],r.slice(u));if(s===-1||s+u>r.length){return-1}u+=s-1;a++;continue}else{return-1}a++}if(t.length!==a){return-1}return r.length}}function ce(e){this._code=e.replace(/\r/g,"")}ce.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?define/,/^(?:#:)?lambda/,/^(?:#:)?let*/,/^(?:#:)?(let|letrec)(-syntax)?$/,/(?:#:)?let-env/,/(?:#:)?syntax-rules/,/(?:#:)?try/,/(?:#:)?catch/,/(?:#:)?while/],shift:{1:["&","#"]}}};ce.match=ue;ce.prototype._options=function e(n){var t=ce.defaults;if(typeof n==="undefined"){return Object.assign({},t)}var r=n&&n.exceptions||{};var i=r.specials||[];var a=r.shift||{1:[]};return Ht(Ht(Ht({},t),n),{},{exceptions:{specials:[].concat(Mt(t.exceptions.specials),Mt(i)),shift:Ht(Ht({},a),{},{1:[].concat(Mt(t.exceptions.shift[1]),Mt(a[1]))})}})};ce.prototype.indent=function e(n){var t=W(this._code,true);return this._indent(t,n)};ce.exception_shift=function(a,e){function n(e){if(!e.length){return false}if(e.indexOf(a)!==-1){return true}else{var n=e.filter(function(e){return e instanceof RegExp});if(!n.length){return false}var t=Ut(n),r;try{for(t.s();!(r=t.n()).done;){var i=r.value;if(a.match(i)){return true}}}catch(e){t.e(e)}finally{t.f()}}return false}if(n(e.exceptions.specials)){return e.indent}var t=e.exceptions.shift;for(var r=0,i=Object.entries(t);r0){r.offset=0}if(a.toString()===n.toString()&&kt(a)){return r.offset+a[0].col}else if(a.length===1){return r.offset+a[0].col+1}else{var u=-1;if(o){var c=ce.exception_shift(o.token,r);if(c!==-1){u=c}}if(u===-1){u=ce.exception_shift(a[1].token,r)}if(u!==-1){return r.offset+a[0].col+u}else if(a[0].line3&&a[1].line===a[3].line){if(a[1].token==="("||a[1].token==="["){return r.offset+a[1].col}return r.offset+a[3].col}else if(a[0].line===a[1].line){return r.offset+r.indent+a[0].col}else{var s=a.slice(2);for(var f=0;f")};se.prototype.match=function(e){return e.match(this.pattern)};function fe(e,n){this.pattern=e;this.flag=n}fe.prototype.toString=function(){return"#")};ce.Pattern=fe;ce.Ahead=se;var le=/[[(]/;var pe=/[\])]/;var he=/[^()[\]]/;var ve=new se(/[^)\]]/);var de=Symbol["for"]("*");var me=new fe([le,de,pe],"+");var ye=new fe([Symbol["for"]("symbol")],"?");var ge=new fe([le,Symbol["for"]("symbol"),de,pe],"+");var be=_e("define","lambda","syntax-rules");var we=/^(?:#:)?(let|let\*|letrec|let-env)(:?-syntax)?$/;function _e(){for(var e=arguments.length,n=new Array(e),t=0;t1&&arguments[1]!==O?arguments[1]:true;if(e instanceof je){return e}if(n===false){var t=Ee;for(var r=e.length;r--;){t=new je(e[r],t)}return t}if(e.length&&!(e instanceof Array)){e=Mt(e)}if(e.length===0){return Ee}else{var i;if(e[0]instanceof Array){i=je.fromArray(e[0])}else{i=e[0]}if(typeof i==="string"){i=En(i)}if(e.length===1){return new je(i,Ee)}else{return new je(i,je.fromArray(e.slice(1)))}}};je.prototype.toObject=function(){var e=arguments.length>0&&arguments[0]!==O?arguments[0]:false;var n=this;var t={};while(true){if(n instanceof je&&n.car instanceof je){var r=n.car;var i=r.car;if(i instanceof Oe){i=i.name}if(i instanceof String){i=i.valueOf()}var a=r.cdr;if(a instanceof je){a=a.toObject(e)}if(a instanceof qn||a instanceof En||a instanceof kn){if(!e){a=a.valueOf()}}t[i]=a;n=n.cdr}else{break}}return t};je.fromPairs=function(e){return e.reduce(function(e,n){return new je(new je(new Oe(n[0]),n[1]),e)},Ee)};je.fromObject=function(n){var e=Object.keys(n).map(function(e){return[e,n[e]]});return je.fromPairs(e)};je.prototype.reduce=function(e){var n=this;var t=Ee;while(true){if(n!==Ee){t=e(t,n.car);n=n.cdr}else{break}}return t};je.prototype.reverse=function(){if(this.haveCycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var n=Ee;while(e!==Ee){var t=e.cdr;e.cdr=n;n=e;e=t}return n};je.prototype.transform=function(r){function i(e){if(e instanceof je){if(e.replace){delete e.replace;return e}var n=r(e.car);if(n instanceof je){n=i(n)}var t=r(e.cdr);if(t instanceof je){t=i(t)}return new je(n,t)}return e}return i(this)};je.prototype.map=function(e){if(typeof this.car!=="undefined"){return new je(e(this.car),this.cdr===Ee?Ee:this.cdr.map(e))}else{return Ee}};var Ae=new Map;function Ie(t){var e=t.constructor||Object;var r=Dt(t)==="object"&&e===Object;var i;if(Ae.has(e)){i=Ae.get(e)}else{Ae.forEach(function(e,n){if(t instanceof n&&(n===Object&&r||n!==Object)){i=e}})}return i}var Ne=new Map;[[Number.NEGATIVE_INFINITY,"-inf.0"],[Number.POSITIVE_INFINITY,"+inf.0"],[true,"#t"],[false,"#f"],[null,"null"],[O,"#"]].forEach(function(e){var n=$t(e,2),t=n[0],r=n[1];Ne.set(t,r)});function Le(e,n,t){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(Ne.has(e)){return Ne.get(e)}if(e instanceof je){if(!t){e.markCycles()}return e.toString(n)}if(Number.isNaN(e)){return"+nan.0"}var r=[RegExp,ke,Oe,qn,kn,rt];for(var i=0,a=r;i"}if(fn(e.toString)){return"#"}else{return e.toString()}}if(e instanceof En){e=e.toString()}if(e===null||typeof e==="string"&&n){return JSON.stringify(e)}if(Dt(e)==="object"){if(typeof e.toString==="function"&&e.toString.__lambda__){return e.toString().valueOf()}var u=e.constructor;if(!u){u=Object}var c;if(typeof u.__className==="string"){c=u.__className}else{if(qe(e)){return"#"}var s=Ie(e);if(s){if(typeof s==="function"){return s(e,n)}else{throw new Error("toString: Invalid repr value")}}c=u.name}if(yt(e)==="instance"&&!fn(u)){c="instance"}if(f.HTMLElement&&e instanceof f.HTMLElement){return"#")}if(c!==""){return"#<"+c+">"}if(typeof e[Symbol.iterator]==="function"){return"#"}return"#"}if(typeof e!=="string"){return e.toString()}return e}function qe(e){return e&&Dt(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}je.prototype.markCycles=function(){Pe(this);return this};je.prototype.haveCycles=function(){var e=arguments.length>0&&arguments[0]!==O?arguments[0]:null;if(!e){return this.haveCycles("car")||this.haveCycles("cdr")}return!!(this.cycles&&this.cycles[e])};function Pe(e){var n=[];var i=[];var a=[];function o(e){if(!n.includes(e)){n.push(e)}}function u(e,n,t,r){if(t instanceof je){if(r.includes(t)){if(!a.includes(t)){a.push(t)}if(!e.cycles){e.cycles={}}e.cycles[n]=t;if(!i.includes(e)){i.push(e)}return true}}}function c(e,n){if(e instanceof je){delete e.ref;delete e.cycles;o(e);n.push(e);var t=u(e,"car",e.car,n);var r=u(e,"cdr",e.cdr,n);if(!t){c(e.car,n.slice())}if(!r){c(e.cdr,n.slice())}}}function t(e,n){if(e.cycles[n]instanceof je){var t=r.indexOf(e.cycles[n]);e.cycles[n]="#".concat(t,"#")}}c(e,[]);var r=n.filter(function(e){return a.includes(e)});r.forEach(function(e,n){e.ref="#".concat(n,"=")});i.forEach(function(e){t(e,"car");t(e,"cdr")})}je.prototype.toString=function(e,n){var t=[];if(this.ref){t.push(this.ref+"(")}else if(!n){t.push("(")}var r;if(this.cycles&&this.cycles.car){r=this.cycles.car}else{r=Le(this.car,e,true)}if(r!==O){t.push(r)}if(this.cdr instanceof je){if(this.cycles&&this.cycles.cdr){t.push(" . ");t.push(this.cycles.cdr)}else{if(this.cdr.ref){t.push(" . ")}else{t.push(" ")}var i=this.cdr.toString(e,true);t.push(i)}}else if(typeof this.cdr!=="undefined"&&this.cdr!==Ee){t=t.concat([" . ",Le(this.cdr,e,true)])}if(!n||this.ref){t.push(")")}return t.join("")};je.prototype.set=function(e,n){this[e]=n;if(n instanceof je){this.markCycles()}};je.prototype.append=function(e){if(e instanceof Array){return this.append(je.fromArray(e))}var n=this;if(n.car===O){if(e instanceof je){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(e!==Ee){while(true){if(n instanceof je&&n.cdr!==Ee){n=n.cdr}else{break}}n.cdr=e}return this};function Re(e){return e<0?-e:e}function Ce(e,n){var t=Ct(n),r=t[0],i=t.slice(1);while(i.length>0){var a=i,o=$t(a,1),u=o[0];if(!e(r,u)){return false}var c=i;var s=Ct(c);r=s[0];i=s.slice(1)}return true}function Me(e,n){if(typeof e==="function"&&typeof n==="function"){return Xe(e)===Xe(n)}else if(e instanceof qn&&n instanceof qn){var t;if(e.type===n.type){if(e.type==="complex"){t=e.im.type===n.im.type&&e.re.type===n.re.type}else{t=true}return t&&e.cmp(n)===0}return false}else if(typeof e==="number"||typeof n==="number"){e=qn(e);n=qn(n);return e.type===n.type&&e.cmp(n)===0}else if(e instanceof kn&&n instanceof kn){return e["char"]===n["char"]}else if(e instanceof Oe&&n instanceof Oe){return e.name===n.name}else{return e===n}}var Te=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function Be(e,n,t,r){if(typeof this!=="undefined"&&this.constructor!==Be||typeof this==="undefined"){return new Be(e,n)}dt("Macro",e,"string",1);dt("Macro",n,"function",2);if(t){if(r){this.__doc__=t}else{this.__doc__=ie(t)}}this.name=e;this.fn=n}Be.defmacro=function(e,n,t,r){var i=new Be(e,n,t,r);i.defmacro=true;return i};Be.prototype.invoke=function(e,n,t){var r=n.env,i=n.dynamic_scope,a=n.error;var o={dynamic_scope:i,error:a,macro_expand:t};var u=this.fn.call(r,e,o,this.name);return u};Be.prototype.toString=function(){return"#"};var $e="define-macro";var De=-1e4;function Ue(a){return function(){var t=Rt(Pt.mark(function e(t,v){var r,d,i;return Pt.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:i=function e(){i=Rt(Pt.mark(function e(t,r,i){var a,o,u,c,s,f,l,p,h;return Pt.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(!(t instanceof je&&t.car instanceof Oe)){n.next=24;break}if(!t.data){n.next=3;break}return n.abrupt("return",t);case 3:a=i.get(t.car,{throwError:false});if(!(a instanceof Be&&a.defmacro)){n.next=24;break}o=a instanceof He?t:t.cdr;n.next=8;return a.invoke(o,v,true);case 8:u=n.sent;if(!(a instanceof He)){n.next=17;break}c=u,s=c.expr,f=c.scope;if(!(s instanceof je)){n.next=16;break}if(!(r!==-1&&r<=1||r"};He.className="syntax";function Je(e,n,d,m){var y={"...":{symbols:{},lists:[]}};function g(e){if(ut.get("DEBUG",{throwError:false})){console.log(e)}}g(d);function b(e,n){var t=arguments.length>2&&arguments[2]!==O?arguments[2]:[];var r=arguments.length>3&&arguments[3]!==O?arguments[3]:false;g({code:n&&n.toString(),pattern:e&&e.toString()});if(e instanceof Oe&&d.includes(e.valueOf())){return Oe.is(n,e)}if(e instanceof je&&e.car instanceof je&&e.car.cdr instanceof je&&Oe.is(e.car.cdr.car,m)){g(">> 0");if(n===Ee){g({pattern:e.toString()});if(e.car.car instanceof Oe){if(e.car.cdr instanceof je&&Oe.is(e.car.cdr.car,m)){var i=e.car.car.valueOf();var a=e.lastPair();if(Oe.is(a.car,m)){y["..."].symbols[i]=null;return true}else{return false}}var o=e.car.car.valueOf();if(y["..."].symbols[o]){throw new Error("syntax: named ellipsis can only "+"appear onces")}y["..."].symbols[o]=n}}}if(e instanceof je&&e.cdr instanceof je&&Oe.is(e.cdr.car,m)){if(e.cdr.cdr!==Ee){throw new Error("syntax: invalid usage of ellipsis")}if(e.car instanceof Oe){var u=e.car.name;if(y["..."].symbols[u]&&!t.includes(u)&&!r){throw new Error("syntax: named ellipsis can only appear onces")}g(">> 1");if(n===Ee){g(">> 2");if(r){g("NIL");y["..."].symbols[u]=Ee}else{g("NULL");y["..."].symbols[u]=null}}else if(n instanceof je&&(n.car instanceof je||n.car===Ee)){g(">> 3 "+r);if(r){if(y["..."].symbols[u]){var c=y["..."].symbols[u];y["..."].symbols[u]=c.append(new je(n,Ee))}else{y["..."].symbols[u]=new je(n,Ee)}}else{g(">> 4");y["..."].symbols[u]=new je(n,Ee)}}else{g(">> 6");if(n instanceof je){g(">> 7 "+r);t.push(u);if(!y["..."].symbols[u]){y["..."].symbols[u]=new je(n,Ee)}else{var s=y["..."].symbols[u];y["..."].symbols[u]=s.append(new je(n,Ee))}g({IIIIII:y["..."].symbols[u].toString()})}else{g(">> 8");return false}}return true}else if(e.car instanceof je){var f=Mt(t);if(n===Ee){g(">> 9");y["..."].lists.push(Ee);return true}g(">> 10");var l=n;while(l instanceof je){if(!b(e.car,l.car,f,true)){return false}l=l.cdr}return true}return false}if(e instanceof Oe){if(Oe.is(e,m)){throw new Error("syntax: invalid usage of ellipsis")}g(">> 11");var p=e.name;if(d.includes(p)){return true}g({name:p,ellipsis:r});if(r){y["..."].symbols[p]=y["..."].symbols[p]||[];y["..."].symbols[p].push(n)}if(!y[p]){y[p]=n}return true}if(e instanceof je&&n instanceof je){g(">> 12");g({a:12,code:n&&n.toString(),pattern:e.toString()});if(n.cdr===Ee){var h=e.car instanceof Oe&&e.cdr instanceof Oe;if(h){g(">> 12 | 1");var v=e.cdr.valueOf();if(!y[v]){y[v]=Ee}v=e.car.valueOf();if(!y[v]){y[v]=n.car}return true}}g("recur");if(b(e.car,n.car,t,r)&&b(e.cdr,n.cdr,t,r)){return true}}else if(e===Ee&&(n===Ee||n===O)){return true}else if(e.car instanceof je&&Oe.is(e.car.car,m)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(b(e,n)){return y}}function Ye(e,i){function a(n){if(n instanceof je){if(!i.length){return n}var e=a(n.car);var t=a(n.cdr);return new je(e,t)}else if(n instanceof Oe){var r=i.find(function(e){return e.gensym===n});if(r){return Oe(r.name)}return n}else{return n}}return a(e)}function Ge(){var e=arguments.length>0&&arguments[0]!==O?arguments[0]:{};var m=e.bindings,n=e.expr,r=e.scope,t=e.symbols,i=e.names,y=e.ellipsis;var a={};function g(e){if(!(e instanceof Oe||typeof e==="string")){throw new Error("syntax: internal error, rename neeed to be symbol")}var n=e.valueOf();if(n===y){throw new Error("syntax: internal error, ellipis not transformed")}if(typeof n==="string"&&n in m){return m[n]}if(t.includes(n)){return Oe(n)}return o(n)}function b(e){if(ut.get("DEBUG",{throwError:false})){console.log(e)}}function o(e){if(!a[e]){var n=r.get(e,{throwError:false});var t=at(e);i.push({name:e,gensym:t});if(typeof n!=="undefined"){r.set(t,n)}a[e]=t}return a[e]}function w(e,n,t){var r=arguments.length>3&&arguments[3]!==O?arguments[3]:function(){};b(" ==> "+e.toString());if(e instanceof Oe){var i=e.valueOf();b("[t 1");if(n[i]){if(n[i]instanceof je){var a=n[i],o=a.car,u=a.cdr;if(t){var c=o.car,s=o.cdr;if(s!==Ee){r(i,new je(s,Ee))}return c}if(u!==Ee){r(i,u)}return o}else if(n[i]instanceof Array){r(i,n[i].slice(1));return n[i][0]}}return g(i)}if(e instanceof je){if(e.car instanceof Oe&&e.cdr instanceof je&&Oe.is(e.cdr.car,y)){b("[t 2");var f=e.car.valueOf();var l=n[f];if(l===null){b({name:f});return}if(l){b({b:n[f]});if(l instanceof je){b("[t 2 Pair "+t);b({______:l.toString()});var p=l.car,h=l.cdr;if(t){if(h!==Ee){r(f,h)}return p}else{if(p.cdr!==Ee){r(f,new je(p.cdr,h))}return p.car}}else if(l instanceof Array){b("[t 2 Array "+t);if(t){r(f,l.slice(1));return je.fromArray(l)}else{var v=l.slice(1);if(v.length){r(f,v)}return l[0]}}else{return l}}}b("[t 3 recur "+e.toString());var d=w(e.car,n,t,r);var m=w(e.cdr,n,t,r);b({b:true,head:d&&d.toString(),rest:m&&m.toString()});return new je(d,m)}}function _(n){var e=Object.values(n);var t=Object.getOwnPropertySymbols(n);if(t.length){e.push.apply(e,Mt(t.map(function(e){return n[e]})))}return e.length&&e.every(function(e){return e instanceof je||e===null||e===Ee||e instanceof Array&&e.length})}function x(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function S(i){b(">> "+i.toString());if(i instanceof je){if(i.cdr instanceof je&&Oe.is(i.cdr.car,y)){b(">> 1");var e=m["..."].symbols;var n=x(e);if(i.car instanceof je){if(m["..."].lists[0]===Ee){return Ee}b(">> 2");var a;if(n.length){b(">> 2 (a)");var o=Ht({},e);a=Ee;var t=function e(){if(!_(o)){return"break"}var r={};var n=function e(n,t){r[n]=t};var t=w(i.car,o,true,n);if(t!==O){a=new je(t,a)}o=r};while(true){var r=t();if(r==="break")break}if(a!==Ee){a=a.reverse()}return a}else{b(">> 3");var u=w(i.car,e,true);if(u){return new je(u,Ee)}return Ee}}else if(i.car instanceof Oe){b(">> 4");var c=i.car.name;var s=Tt({},c,e[c]);var f=Ee;var l=function e(){if(!_(s)){b({bind:s});return"break"}var r={};var n=function e(n,t){r[n]=t};var t=w(i,s,false,n);if(typeof t!=="undefined"){f=new je(t,f)}s=r};while(true){var p=l();if(p==="break")break}if(f!==Ee){f=f.reverse()}if(i.cdr instanceof je&&i.cdr.cdr instanceof je){f.append(S(i.cdr.cdr))}return f}}var h=S(i.car);var v=S(i.cdr);b({a:true,head:h&&h.toString(),rest:v&&v.toString()});return new je(h,v)}if(i instanceof Oe){var d=g(i);if(typeof d!=="undefined"){return d}}return i}return S(n)}function Ve(e){return typeof e==="undefined"||e===Ee||e===null}function ze(e){return e instanceof Promise||e&&typeof e!=="undefined"&&typeof e.then==="function"}function We(e){switch(Dt(e)){case"string":return En(e);case"number":if(!Number.isNaN(e)){return qn(e)}}return e}function Qe(e){if(e&&e.valueOf){return e.valueOf()}return e}function Ke(e,n){if(e instanceof je){e.markCycles();return it(e)}if(typeof e==="function"){if(n){return Ze(e,n)}}return We(e)}function Xe(e){if(en(e)){return e[an]}return e}function Ze(n,e){if(n[Symbol["for"]("__bound__")]){return n}var t=n.bind(e);var r=Object.getOwnPropertyNames(n).filter(un);r.forEach(function(e){try{t[e]=n[e]}catch(e){}});cn(t,"__fn__",n);cn(t,"__context__",e);cn(t,"__bound__",true);if(fn(n)){cn(t,"__native__",true)}t.valueOf=function(){return n};return t}function en(e){return!!(typeof e==="function"&&e[an])}function nn(e){if(typeof e==="function"){var n=e[rn];if(n&&(n===Nt||n.constructor&&n.constructor.__className)){return true}}return false}function tn(e){function n(e){return e instanceof zn||e instanceof Wn}if(typeof e==="function"){if(n(e)){return true}if(n(e[rn])){return true}}return false}var rn=Symbol["for"]("__context__");var an=Symbol["for"]("__fn__");var on=["name","length","caller","callee","arguments","prototype"];function un(e){return!on.includes(e)}function cn(e,n,t){Object.defineProperty(e,Symbol["for"](n),{get:function e(){return t},set:function e(){},configurable:false,enumerable:false})}function sn(n,t){try{Object.defineProperty(n,"length",{get:function e(){return t}});return n}catch(e){var r=new Array(t).fill(0).map(function(e,n){return"a"+n}).join(",");var i=new Function("f","return function(".concat(r,") {\n return f.apply(this, arguments);\n };"));return i(n)}}function fn(e){var n=Symbol["for"]("__native__");return typeof e==="function"&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[n]===true||!e.name.match(/^bound /)&&!e[n])}function ln(e){var d;switch(e){case Symbol["for"]("letrec"):d="letrec";break;case Symbol["for"]("let"):d="let";break;case Symbol["for"]("let*"):d="let*";break;default:throw new Error("Invalid let_macro value")}return Be.defmacro(d,function(n,e){var o=e.dynamic_scope,u=e.error,t=e.macro_expand;var c;if(n.car instanceof Oe){if(!(n.cdr.car instanceof je||n.cdr.car===Ee)){throw new Error("let require list of pairs")}var r;if(n.cdr.car===Ee){c=Ee;r=Ee}else{r=n.cdr.car.map(function(e){return e.car});c=n.cdr.car.map(function(e){return e.cdr.car})}return je.fromArray([Oe("letrec"),[[n.car,je(Oe("lambda"),je(r,n.cdr.cdr))]],je(n.car,c)])}else if(t){return}var s=this;c=this.get("list->array")(n.car);var f=s.inherit(d);var l,p;if(d==="let*"){p=f}else if(d==="let"){l=[]}var h=0;function v(){var e=new je(new Oe("begin"),n.cdr);return xt(e,{env:f,dynamic_scope:o,error:u})}return function n(){var t=c[h++];function r(e,n){if(typeof n==="undefined"){f.set(e,Ee)}else{f.set(e,n)}}if(o){o=d==="let*"?f:s}if(!t){if(l&&l.length){var e=l.map(function(e){return e.value});var i=e.filter(ze);if(i.length){return Promise.all(e).then(function(e){for(var n=0,t=e.length;n1&&arguments[1]!==O?arguments[1]:{},t=n.dynamic_scope,r=n.error;var i=this;if(t){t=this}var a=e;var o=[];while(a instanceof je){o.push(xt(a.car,{env:i,dynamic_scope:t,error:r}));a=a.cdr}var u=o.filter(ze).length;if(u){return Promise.all(o).then(c.bind(this))}else{return c.call(this,o)}})}function hn(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r2?r-2:0),a=2;a1&&arguments[1]!==O?arguments[1]:null;return function(){for(var e=arguments.length,n=new Array(e),t=0;t1?e-1:0),t=1;t=o){return a.apply(this,r)}else{return i}}return i.apply(this,arguments)}}function xn(r,i){dt("limit",i,"function",2);return function(){for(var e=arguments.length,n=new Array(e),t=0;t1?r-1:0),a=1;a0){t.push(this._string.substring(0,e))}t.push(n);if(e1&&arguments[1]!==O?arguments[1]:false;if(e instanceof qn){return e}if(typeof this!=="undefined"&&!(this instanceof qn)||typeof this==="undefined"){return new qn(e,n)}if(typeof e==="undefined"){throw new Error("Invlaid LNumber constructor call")}var t=qn.getType(e);if(qn.types[t]){return qn.types[t](e,n)}var r=e instanceof Array&&En.isString(e[0])&&qn.isNumber(e[1]);if(e instanceof qn){return qn(e.value)}if(!qn.isNumber(e)&&!r){throw new Error("You can't create LNumber from ".concat(yt(e)))}if(e===null){e=0}var i;if(r){var a=e,o=$t(a,2),u=o[0],c=o[1];if(u instanceof En){u=u.valueOf()}if(c instanceof qn){c=c.valueOf()}var s=u.match(/^([+-])/);var f=false;if(s){u=u.replace(/^[+-]/,"");if(s[1]==="-"){f=true}}}if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(r){var l;switch(c){case 8:l="0o";break;case 16:l="0x";break;case 2:l="0b";break;case 10:l="";break}if(typeof l==="undefined"){var p=BigInt(c);i=Mt(u).map(function(e,n){return BigInt(parseInt(e,c))*Math.pow(p,BigInt(n))}).reduce(function(e,n){return e+n})}else{i=BigInt(l+u)}}else{i=BigInt(e)}if(f){i*=BigInt(-1)}}else{i=e}return Dn(i,true)}else if(typeof h!=="undefined"&&!(e instanceof h)){if(e instanceof Array){return Dn(qt(h,Mt(e)))}return Dn(new h(e))}else if(r){this.value=parseInt(u,c)}else{this.value=e}}qn.types={float:function e(n){var t=arguments.length>1&&arguments[1]!==O?arguments[1]:false;return new Rn(n,t)},complex:function e(n){var t=arguments.length>1&&arguments[1]!==O?arguments[1]:false;if(!qn.isComplex(n)){n={im:0,re:n}}return new Pn(n,t)},rational:function e(n){var t=arguments.length>1&&arguments[1]!==O?arguments[1]:false;if(!qn.isRational(n)){n={num:n,denom:1}}return new $n(n,t)}};function Pn(e){var n=arguments.length>1&&arguments[1]!==O?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof Pn)||typeof this==="undefined"){return new Pn(e,n)}if(e instanceof Pn){return Pn({im:e.im,re:e.re})}if(qn.isNumber(e)&&n){e={im:0,re:e.valueOf()}}else if(!qn.isComplex(e)){throw new Error("Invalid constructor call for LComplex")}var t=e.im instanceof qn?e.im:qn(e.im);var r=e.re instanceof qn?e.re:qn(e.re);if(t.cmp(0)===0&&!n){return r}this.im=t;this.re=r;this.type="complex"}Pn.prototype=Object.create(qn.prototype);Pn.prototype.constructor=Pn;Pn.prototype.toRational=function(e){if(qn.isFloat(this.im)&&qn.isFloat(this.re)){var n=Rn(this.im).toRational(e);var t=Rn(this.re).toRational(e);return Pn({im:n,re:t})}return this};Pn.prototype.add=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.add(n),im:t.add(r)}})};Pn.prototype.factor=function(){if(this.im instanceof Rn||this.im instanceof Rn){var e=this.re,n=this.im;var t,r;if(e instanceof Rn){t=e.toRational().mul(e.toRational())}else{t=e.mul(e)}if(n instanceof Rn){r=n.toRational().mul(n.toRational())}else{r=n.mul(n)}return t.add(r)}else{return this.re.mul(this.re).add(this.im.mul(this.im))}};Pn.prototype.modulus=function(){return this.factor().sqrt()};Pn.prototype.sqrt=function(){var e=this.modulus();var n,t;if(e.cmp(0)===0){n=t=e}else if(this.re.cmp(0)===1){n=Rn(.5).mul(e.add(this.re)).sqrt();t=this.im.div(n).div(2)}else{t=Rn(.5).mul(e.sub(this.re)).sqrt();if(this.im.cmp(0)===-1){t=t.sub()}n=this.im.div(t).div(2)}return Pn({im:t,re:n})};Pn.prototype.div=function(e){if(qn.isNumber(e)&&!qn.isComplex(e)){e=Pn({im:0,re:e})}else if(!qn.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var n=this.coerce(e),t=$t(n,2),r=t[0],i=t[1];var a=Pn({re:i.re,im:i.im.sub()});var o=i.factor().valueOf();var u=r.mul(a);var c=u.re.op("/",o);var s=u.im.op("/",o);return Pn({re:c,im:s})};Pn.prototype.sub=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.sub(n),im:t.sum(r)}})};Pn.prototype.mul=function(e){return this.complex_op(e,function(e,n,t,r){var i={re:e.mul(n).sub(t.mul(r)),im:e.mul(r).add(n.mul(t))};return i})};Pn.prototype.complex_op=function(e,n){if(qn.isNumber(e)&&!qn.isComplex(e)){if(!(e instanceof qn)){e=qn(e)}var t=e.asType(0);e={im:t,re:e}}else if(!qn.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var r=e.re instanceof qn?e.re:this.re.asType(e.re);var i=e.im instanceof qn?e.im:this.im.asType(e.im);var a=n(this.re,r,this.im,i);if("im"in a&&"re"in a){var o=Pn(a,true);return o}return a};Pn._op={"+":"add","-":"sub","*":"mul","/":"div"};Pn.prototype._op=function(e,n){var t=Pn._op[e];return this[t](n)};Pn.prototype.cmp=function(e){var n=this.coerce(e),t=$t(n,2),r=t[0],i=t[1];var a=r.re.coerce(i.re),o=$t(a,2),u=o[0],c=o[1];var s=u.cmp(c);if(s!==0){return s}else{var f=r.im.coerce(i.im),l=$t(f,2),p=l[0],h=l[1];return p.cmp(h)}};Pn.prototype.valueOf=function(){};Pn.prototype.toString=function(){var e;if(this.re.cmp(0)!==0){e=[this.re.toString()]}else{e=[]}e.push(this.im.cmp(0)<0?"-":"+");e.push(this.im.toString().replace(/^-/,""));e.push("i");return e.join("")};function Rn(e){if(typeof this!=="undefined"&&!(this instanceof Rn)||typeof this==="undefined"){return new Rn(e)}if(!qn.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof qn){return Rn(e.valueOf())}if(typeof e==="number"){this.value=e;this.type="float"}}Rn.prototype=Object.create(qn.prototype);Rn.prototype.constructor=Rn;Rn.prototype.toString=function(){var e=this.value.toString();if(!qn.isFloat(this.value)&&!e.match(/e/i)){return e+".0"}return e.replace(/^([0-9]+)e/,"$1.0e")};Rn.prototype._op=function(e,n){if(n instanceof qn){n=n.value}var t=qn._ops[e];return Rn(t(this.value,n))};Rn.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==O?arguments[0]:null;if(e===null){return Cn(this.value.valueOf())}return Mn(e.valueOf())(this.value.valueOf())};var Cn=Mn(1e-10);function Mn(r){return function(e){var n=function e(r,n,t){var i=function e(n,t){return t0){i=Bn(r,t)}else if(r.cmp(t)<=0){i=t}else if(t.cmp(0)>0){i=Bn(t,r)}else if(n.cmp(0)<0){i=qn(Bn(r.sub(),t.sub())).sub()}else{i=qn(0)}if(qn.isFloat(n)||qn.isFloat(e)){return Rn(i)}return i}function Bn(e,n){var t=qn(e).floor();var r=qn(n).floor();if(e.cmp(t)<1){return t}else if(t.cmp(r)===0){var i=qn(1).div(n.sub(r));var a=qn(1).div(e.sub(t));return t.add(qn(1).div(Bn(i,a)))}else{return t.add(qn(1))}}function $n(e){var n=arguments.length>1&&arguments[1]!==O?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof $n)||typeof this==="undefined"){return new $n(e,n)}if(!qn.isRational(e)){throw new Error("Invalid constructor call for LRational")}var t=qn(e.num);var r=qn(e.denom);if(!n&&r.cmp(0)!==0){var i=t.op("%",r).cmp(0)===0;if(i){return qn(t.div(r))}}this.num=t;this.denom=r;this.type="rational"}$n.prototype=Object.create(qn.prototype);$n.prototype.constructor=$n;$n.prototype.pow=function(e){var n=e.cmp(0);if(n===0){return qn(1)}if(n===-1){e=e.sub();var t=this.denom.pow(e);var r=this.num.pow(e);return $n({num:t,denom:r})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};$n.prototype.sqrt=function(){var e=this.num.sqrt();var n=this.denom.sqrt();if(e instanceof Rn){e=(Lt("num"),e.toRational())}if(n instanceof Rn){n=(Lt("denom"),n.toRational())}return $n({num:e,denom:n})};$n.prototype.abs=function(){var e=this.num;var n=this.denom;if(e.cmp(0)===-1){e=e.sub()}if(n.cmp(0)!==1){n=n.sub()}return $n({num:e,denom:n})};$n.prototype.cmp=function(e){return qn(this.valueOf(),true).cmp(e)};$n.prototype.toString=function(){var e=this.num.gcd(this.denom);var n,t;if(e.cmp(1)!==0){n=this.num.div(e);if(n instanceof $n){n=qn(n.valueOf(true))}t=this.denom.div(e);if(t instanceof $n){t=qn(t.valueOf(true))}}else{n=this.num;t=this.denom}var r=this.cmp(0)<0;if(r){if(n.abs().cmp(t.abs())===0){return n.toString()}}else if(n.cmp(t)===0){return n.toString()}return n.toString()+"/"+t.toString()};$n.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 qn._ops["/"](this.num.value,this.denom.value)}return Rn(this.num.valueOf()).div(this.denom.valueOf())};$n.prototype.mul=function(e){if(!(e instanceof qn)){e=qn(e)}if(qn.isRational(e)){var n=this.num.mul(e.num);var t=this.denom.mul(e.denom);return $n({num:n,denom:t})}var r=qn.coerce(this,e),i=$t(r,2),a=i[0],o=i[1];return a.mul(o)};$n.prototype.div=function(e){if(!(e instanceof qn)){e=qn(e)}if(qn.isRational(e)){var n=this.num.mul(e.denom);var t=this.denom.mul(e.num);return $n({num:n,denom:t})}var r=qn.coerce(this,e),i=$t(r,2),a=i[0],o=i[1];var u=a.div(o);return u};$n.prototype._op=function(e,n){return this[Yn[e]](n)};$n.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof qn)){e=qn(e)}if(qn.isRational(e)){var n=e.num.sub();var t=e.denom;return this.add($n({num:n,denom:t}))}if(!(e instanceof qn)){e=qn(e).sub()}else{e=e.sub()}var r=qn.coerce(this,e),i=$t(r,2),a=i[0],o=i[1];return a.add(o)};$n.prototype.add=function(e){if(!(e instanceof qn)){e=qn(e)}if(qn.isRational(e)){var n=this.denom;var t=e.denom;var r=this.num;var i=e.num;var a,o;if(n!==t){o=t.mul(r).add(i.mul(n));a=n.mul(t)}else{o=r.add(i);a=n}return $n({num:o,denom:a})}if(qn.isFloat(e)){return Rn(this.valueOf()).add(e)}var u=qn.coerce(this,e),c=$t(u,2),s=c[0],f=c[1];return s.add(f)};function Dn(e,n){if(typeof this!=="undefined"&&!(this instanceof Dn)||typeof this==="undefined"){return new Dn(e,n)}if(e instanceof Dn){return Dn(e.value,e._native)}if(!qn.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.value=e;this._native=n;this.type="bigint"}Dn.prototype=Object.create(qn.prototype);Dn.prototype.constructor=Dn;Dn.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};Dn.prototype._op=function(e,n){if(typeof n==="undefined"){if(qn.isBN(this.value)){e=Dn.bn_op[e];return Dn(this.value.clone()[e](),false)}return Dn(qn._ops[e](this.value),true)}if(qn.isBN(this.value)&&qn.isBN(n.value)){e=Dn.bn_op[e];return Dn(this.value.clone()[e](n),false)}var t=qn._ops[e](this.value,n.value);if(e==="/"){var r=this.op("%",n).cmp(0)===0;if(r){return qn(t)}return $n({num:this,denom:n})}return Dn(t,true)};Dn.prototype.sqrt=function(){var e;var n=this.cmp(0)<0;if(qn.isNative(this.value)){e=qn(Math.sqrt(n?-this.valueOf():this.valueOf()))}else if(qn.isBN(this.value)){e=n?this.value.neg().sqrt():this.value.sqrt()}if(n){return Pn({re:0,im:e})}return e};qn.prototype.gcd=function(e){var n=this.abs();e=e.abs();if(e.cmp(n)===1){var t=n;n=e;e=t}while(true){n=n.rem(e);if(n.cmp(0)===0){return e}e=e.rem(n);if(e.cmp(0)===0){return n}}};qn.isFloat=function e(n){return n instanceof Rn||Number(n)===n&&n%1!==0};qn.isNumber=function(e){return e instanceof qn||!Number.isNaN(e)&&qn.isNative(e)||qn.isBN(e)};qn.isComplex=function(e){var n=e instanceof Pn||qn.isNumber(e.im)&&qn.isNumber(e.re);return n};qn.isRational=function(e){return e instanceof $n||qn.isNumber(e.num)&&qn.isNumber(e.denom)};qn.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};qn.isBigInteger=function(e){return e instanceof Dn||typeof e==="bigint"||qn.isBN(e)};qn.isBN=function(e){return typeof h!=="undefined"&&e instanceof h};qn.getArgsType=function(e,n){if(e instanceof Rn||n instanceof Rn){return Rn}if(e instanceof Dn||n instanceof Dn){return Dn}return qn};qn.prototype.toString=qn.prototype.toJSON=function(e){if(e>2&&e<36){return this.value.toString(e)}return this.value.toString()};qn.prototype.asType=function(e){var n=qn.getType(this);return qn.types[n]?qn.types[n](e):qn(e)};qn.prototype.isBigNumber=function(){return typeof this.value==="bigint"||typeof h!=="undefined"&&!(this.value instanceof h)};["floor","ceil","round"].forEach(function(e){qn.prototype[e]=function(){if(this["float"]||qn.isFloat(this.value)){return qn(Math[e](this.value))}else{return qn(Math[e](this.valueOf()))}}});qn.prototype.valueOf=function(){if(qn.isNative(this.value)){return Number(this.value)}else if(qn.isBN(this.value)){return this.value.toNumber()}};var Un=function(){var e=function e(n,t){return[n,t]};return{bigint:{bigint:e,float:function e(n,t){return[Rn(n.valueOf()),t]},rational:function e(n,t){return[{num:n,denom:1},t]},complex:function e(n,t){return[{im:0,re:n},t]}},float:{bigint:function e(n,t){return[n,t&&Rn(t.valueOf())]},float:e,rational:function e(n,t){return[n,t&&Rn(t.valueOf())]},complex:function e(n,t){return[{re:n,im:Rn(0)},t]}},complex:{bigint:n("bigint"),float:n("float"),rational:n("rational"),complex:function e(n,t){var r=qn.coerce(n.re,t.re),i=$t(r,2),a=i[0],o=i[1];var u=qn.coerce(n.im,t.im),c=$t(u,2),s=c[0],f=c[1];return[{im:s,re:a},{im:f,re:o}]}},rational:{bigint:function e(n,t){return[n,t&&{num:t,denom:1}]},float:function e(n,t){return[Rn(n.valueOf()),t]},rational:e,complex:function e(n,t){return[{im:Hn(n.type,t.im.type,0),re:Hn(n.type,t.re.type,n)},{im:Hn(n.type,t.im.type,t.im),re:Hn(n.type,t.re.type,t.re)}]}}};function n(t){return function(e,n){return[{im:Hn(t,e.im.type,e.im),re:Hn(t,e.re.type,e.re)},{im:Hn(t,e.im.type,0),re:Hn(t,n.type,n)}]}}}();function Hn(e,n,t){return Un[e][n](t)[0]}qn.coerce=function(e,n){function t(e){if(e==="integer"){return"bigint"}return e}var r=t(qn.getType(e));var i=t(qn.getType(n));if(!Un[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!Un[r][i]){throw new Error("LNumber::coerce unknown rhs type ".concat(i))}return Un[r][i](e,n).map(function(e){return qn(e,true)})};qn.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof qn)){throw new Error("LNumber: you can't coerce ".concat(yt(e)))}if(typeof e==="number"){e=qn(e)}return qn.coerce(this,e)};qn.getType=function(e){if(e instanceof qn){return e.type}if(qn.isFloat(e)){return"float"}if(qn.isComplex(e)){return"complex"}if(qn.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof h!=="undefined"&&!(e instanceof h)){return"bigint"}};qn.prototype.isFloat=function(){return!!(qn.isFloat(this.value)||this["float"])};var Jn={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var Yn={};Object.keys(Jn).forEach(function(n){Yn[Jn[n]]=n;qn.prototype[n]=function(e){return this.op(Jn[n],e)}});qn._ops={"*":function e(n,t){return n*t},"+":function e(n,t){return n+t},"-":function e(n,t){if(typeof t==="undefined"){return-n}return n-t},"/":function e(n,t){return n/t},"%":function e(n,t){return n%t},"|":function e(n,t){return n|t},"&":function e(n,t){return n&t},"~":function e(n){return~n},">>":function e(n,t){return n>>t},"<<":function e(n,t){return n<=this._string.length){return Xn}return kn(this._string[this._in_char])};function Wn(e){if(typeof this!=="undefined"&&!(this instanceof Wn)||typeof this==="undefined"){return new Wn(e)}dt("OutputPort",e,"function");this.write=e}Wn.prototype.toString=function(){return"<#output-port>"};function Qn(n){var t=this;if(typeof this!=="undefined"&&!(this instanceof Qn)||typeof this==="undefined"){return new Qn(n)}dt("OutputStringPort",n,"function");this._buffer=[];this.write=function(e){if(!En.isString(e)){e=n(e)}else{e=e.valueOf()}t._buffer.push(e)}}Qn.prototype=Object.create(Wn.prototype);Qn.prototype.getString=function(){return this._buffer.map(function(e){return e.valueOf()}).join("")};Qn.prototype.constructor=Qn;function Kn(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof Kn)||typeof this==="undefined"){return new Kn(e)}dt("InputStringPort",e,"string");this._string=e.valueOf();this._index=0;this._in_char=0;this.read=function(){return n.get_next_tokens()}}Kn.prototype=Object.create(zn.prototype);Kn.prototype.constructor=Kn;Kn.prototype.read_line=function(){var e=this._string.substring(this._in_char);if(!e){return Xn}var n=e.match(/([^\n])(?:\n|$)/)[0];this._in_char+=n.length;return n};var Xn=new Zn;function Zn(){}Zn.prototype.toString=function(){return"<#eof>"};function et(e){var n=arguments.length>1&&arguments[1]!==O?arguments[1]:{};if(typeof this!=="undefined"&&!(this instanceof et)||typeof this==="undefined"){return new et(e,n)}if(typeof e==="undefined"){e="anonymous"}this.env=ut.inherit(e,n)}et.prototype.exec=function(e){var n=arguments.length>1&&arguments[1]!==O?arguments[1]:false;dt("Intepreter::exec",e,"string",1);dt("Intepreter::exec",n,"boolean",2);ot.set("**interaction-environment**",this.env);return St(e,this.env,n?this.env:false)};et.prototype.get=function(e){return this.env.get(e).bind(this.env)};et.prototype.set=function(e,n){return this.env.set(e,n)};function nt(e,n,t){if(arguments.length===1){if(Dt(arguments[0])==="object"){e=arguments[0];this.parent=null}else if(typeof arguments[0]==="string"){e={};n={};t=arguments[0]}}this.docs=new Map;this.env=e;this.parent=n;this.name=t||"anonymous"}nt.prototype.inherit=function(e){var n=arguments.length>1&&arguments[1]!==O?arguments[1]:{};if(Dt(e)==="object"){n=e}if(!e||Dt(e)==="object"){e="child of "+(this.name||"unknown")}return new nt(n||{},this,e)};nt.prototype.doc=function(e){var n=arguments.length>1&&arguments[1]!==O?arguments[1]:null;if(e instanceof Oe){e=e.name}if(e instanceof En){e=e.valueOf()}if(n){this.docs.set(e,n);return this}if(this.docs.has(e)){return this.docs.get(e)}if(this.parent){return this.parent.doc(e)}};nt.prototype.newFrame=function(e,n){var r=this.inherit("__frame__");r.set("parent.frame",re(function(){var e=arguments.length>0&&arguments[0]!==O?arguments[0]:1;var n=r.parent;if(!(n instanceof nt)){return Ee}if(e<=0){return n}var t=n.get("parent.frame");return t(e-1)},ot.env["parent.frame"].__doc__));n.callee=e;r.set("arguments",n);return r};nt.prototype._lookup=function(e){if(e instanceof Oe){e=e.name}if(e instanceof En){e=e.valueOf()}if(this.env.hasOwnProperty(e)){return tt(this.env[e])}if(this.parent){return this.parent._lookup(e)}};nt.prototype.toString=function(){return"<#env:"+this.name+">"};nt.prototype.clone=function(){var n=this;var t={};Object.keys(this.env).forEach(function(e){t[e]=n.env[e]});return new nt(t,this.parent,this.name)};nt.prototype.merge=function(e){var n=arguments.length>1&&arguments[1]!==O?arguments[1]:"merge";dt("Environment::merge",e,"environment");return this.inherit(n,e.env)};function tt(e){if(typeof this!=="undefined"&&!(this instanceof tt)||typeof this==="undefined"){return new tt(e)}this.value=e}tt.isUndefined=function(e){return e instanceof tt&&typeof e.value==="undefined"};tt.prototype.valueOf=function(){return this.value};function rt(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof rt)||typeof this==="undefined"){return new rt(e)}this.values=e}rt.prototype.toString=function(){return this.values.map(function(e){return Le(e)}).join("\n")};rt.prototype.valueOf=function(){return this.values};nt.prototype.get=function(e){var n=arguments.length>1&&arguments[1]!==O?arguments[1]:{};var t=n.throwError,r=t===void 0?true:t;var i=e;if(i instanceof Oe||i instanceof En){i=i.valueOf()}var a=this._lookup(i);if(a instanceof tt){if(tt.isUndefined(a)){return O}return Ke(a.valueOf())}if(typeof i==="string"){var o=i.split(".").filter(Boolean);if(o.length>0){var u=Ct(o),c=u[0],s=u.slice(1);a=this._lookup(c);if(s.length){try{if(a instanceof tt){a=a.valueOf()}else{a=On(f,c);if(typeof a==="function"){a=Xe(a)}}return On.apply(void 0,[a].concat(Mt(s)))}catch(e){}}else if(a instanceof tt){return Ke(a.valueOf())}}a=On(f,i)}if(typeof a!=="undefined"){return a}if(r){throw new Error("Unbound variable `"+i.toString()+"'")}};nt.prototype.set=function(e,n){var t=arguments.length>2&&arguments[2]!==O?arguments[2]:null;if(qn.isNumber(n)){n=qn(n)}if(e instanceof Oe){e=e.name}else if(e instanceof En){e=e.valueOf()}this.env[e]=n;if(t){this.doc(e,t)}return this};nt.prototype.has=function(e){return this.env.hasOwnProperty(e)};nt.prototype.ref=function(e){var n=this;while(true){if(!n){break}if(n.has(e)){return n}n=n.parent}};nt.prototype.parents=function(){var e=this;var n=[];while(e){n.unshift(e);e=e.parent}return n};function it(e){if(ze(e)){return e.then(it)}if(e instanceof je||e instanceof Oe){e.data=true}return e}var at=function(){var n=0;return function(){var e=arguments.length>0&&arguments[0]!==O?arguments[0]:null;if(e instanceof Oe){e=e.valueOf()}if(e!==null){return new Oe(Symbol("#:".concat(e)))}n++;return new Oe(Symbol("#:g".concat(n)))}}();var ot=new nt({nil:Ee,undefined:O,true:true,false:false,null:null,NaN:NaN,stdout:new Wn(function(){var e;(e=console).log.apply(e,arguments)}),stdin:zn(function(){return new Promise(function(e){e(prompt(""))})}),"open-input-string":re(function(e){dt("open-input-string",e,"string");return Kn(e)},"(open-input-string string)\n\n Function create new string port as input that can be used to\n read S-exressions from this port using `read` function."),"output-port?":re(function(e){return e instanceof Wn},"(output-port? arg)\n\n Function return true if argument is output port."),"input-port?":re(function(e){return e instanceof zn},"(input-port? arg)\n\n Function return true if argument is input port."),"open-output-string":re(function(){return Qn(this.get("repr"))},"(open-output-string)\n\n Function create new output port that can used to write string into\n and after finish get the whole string using `get-output-string`"),"get-output-string":re(function(e){dt("get-output-string",e,"output-string-port");return e.getString()},"(get-output-string port)\n\n Function get full string from string port. If nothing was wrote\n to given port it will return empty string."),"eof-object?":re(function(e){return e===Xn},"(eof-object? arg)\n\n Function check if value is eof object, returned from input string\n port when there are no more data to read."),"peek-char":re(function(e){dt("peek-char",e,["input-port","input-string-port"]);return e.peek_char()},"(peek-char port)\n\n Function get character from string port or EOF object if no more\n data in string port."),"read-line":re(function(e){if(typeof e==="undefined"){e=this.get("stdin")}dt("read-line",e,["input-port","input-string-port"]);return e.read_line()},"(read-char port)\n\n Function read next character from input port."),"read-char":re(function(e){if(typeof e==="undefined"){e=this.get("stdin")}dt("read-char",e,["input-port","input-string-port"]);return e.read_char()},"(read-char port)\n\n Function read next character from input port."),read:re(function e(n){if(En.isString(n)){return ee(W(n.valueOf()))[0]}var t;if(n instanceof zn){t=n}else{t=this.get("stdin")}return ne(t.read(),function(e){if(e===Xn){return Xn}return ee(e)[0]})},"(read [string])\n\n Function if used with string will parse the string and return\n list structure of LIPS code. If called without an argument it\n will read string from standard input (using browser prompt or\n user defined way) and call itself with that string (parse is)\n function can be used together with eval to evaluate code from\n string"),pprint:re(function(e){if(e instanceof je){e=new Nt.Formatter(e.toString(true))["break"]().format();this.get("stdout").write.call(this,e)}else{this.get("display").call(this,e)}this.get("newline").call(this)},"(pprint expression)\n\n Pretty print list expression, if called with non-pair it just call\n print function with passed argument."),print:re(function(){var n=this;var t=this.get("display");var r=this.get("newline");for(var e=arguments.length,i=new Array(e),a=0;a1?t-1:0),i=1;ir.length){throw new Error("Not enough arguments")}var u=0;var c=this.get("repr");n=n.replace(a,function(e){var n=e[1];if(n==="~"){return"~"}else if(n==="%"){return"\n"}else{var t=r[u++];if(n==="a"){return c(t)}else{return c(t,true)}}});o=n.match(/~([\S])/);if(o){throw new Error("format: Unrecognized escape seqence ".concat(o[1]))}return n},"(format string n1 n2 ...)\n\n Function accepts string template and replacing any escape sequences\n by arguments:\n\n * ~a value as if printed with display\n * ~s value as if printed with write\n * ~% newline character\n * ~~ literal tilde '~' is inserted\n\n if there missing arguments or other escape character it throw exception."),display:re(function(e){var n=arguments.length>1&&arguments[1]!==O?arguments[1]:null;if(n===null){n=this.get("stdout")}n.write.call(this,this.get("repr")(e))},"(display arg [port])\n\n Function send string to standard output or provied port."),error:re(function(){for(var e=arguments.length,n=new Array(e),t=0;t1&&arguments[1]!==O?arguments[1]:{},t=n.dynamic_scope,r=n.error;if(t){t=this}var o;var i=xt(e.cdr.car,{env:this,dynamic_scope:t,error:r});i=gt(i);function u(n,t){if(ze(n)){return n.then(function(e){return u(e,t)})}if(ze(t)){return t.then(function(e){return u(n,e)})}f[n]=t;return t}if(e.car instanceof je&&Oe.is(e.car.car,".")){var c=e.car.cdr.car;var s=e.car.cdr.cdr.car;var f=xt(c,{env:this,dynamic_scope:t,error:r});var l=xt(s,{env:this,dynamic_scope:t,error:r});return u(l,i)}if(!(e.car instanceof Oe)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var p=e.car.valueOf();o=this.ref(e.car.name);return ne(i,function(e){if(!o){var n=p.split(".");if(n.length>1){var t=n.pop();var r=n.join(".");var i=a.get(r,{throwError:false});if(i){a.get("set-obj!").call(a,i,t,e);return}}o=a}o.set(p,e)})}),"(set! name value)\n\n Macro that can be used to set the value of the variable (mutate)\n it search the scope chain until it finds first non emtpy slot and set it."),"unset!":re(new Be("set!",function(e){if(!(e.car instanceof Oe)){throw new Error("unset! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var n=e.car;var t=this.ref(n);if(t){delete t.env[n.name]}}),"(unset! name)\n\n Function delete specified name from environment."),"set-car!":re(function(e,n){dt("set-car!",e,"pair");e.car=n},"(set-car! obj value)\n\n Function that set car (head) of the list/pair to specified value.\n It can destroy the list. Old value is lost."),"set-cdr!":re(function(e,n){dt("set-cdr!",e,"pair");e.cdr=n},"(set-cdr! obj value)\n\n Function that set cdr (tail) of the list/pair to specified value.\n It can destroy the list. Old value is lost."),"empty?":re(function(e){return typeof e==="undefined"||e===Ee},"(empty? object)\n\n Function return true if value is undfined empty list."),assoc:re(function(e,n){if(e instanceof je&&!(n instanceof je)){throw new Error("First argument to assoc ned to be a key")}dt("assoc",n,"pair");var t=n;while(true){if(!(t instanceof je)||this.get("empty?")(t)){break}var r=t.car.car;if(Me(r,e)){return t.car}else if(!t.haveCycles("cdr")){t=t.cdr}}return Ee},"(assoc key alist)\n\n Function search Alist (list of pairs) until it find the one that\n have head set equal to key, and return found pair."),gensym:re(at,"(gensym)\n\n Function generate unique symbol, to use with macros as meta name."),load:re(function(n){dt("load",n,"string");var e=this;if(e.name==="__frame__"){e=e.parent}var i;if(e===ot){i=e}else{i=this.get("**interaction-environment**")}var a="**module-path**";var o=ot.get(a,{throwError:false});n=n.valueOf();if(!n.match(/.[^.]+$/)){n+=".scm"}if(typeof this.get("global",{throwError:false})!=="undefined"){return new Promise(function(t,r){var e=require("path");if(o){o=o.valueOf();n=e.join(o,n)}ot.set(a,e.dirname(n));require("fs").readFile(n,function(e,n){if(e){console.log(e);r(e);ot.set(a,o)}else{St(n.toString(),i).then(function(){t();ot.set(a,o)})["catch"](r)}})})}if(o){o=o.valueOf();n=o+"/"+n.replace(/^\.?\/?/,"")}return f.fetch(n).then(function(e){return e.text()}).then(function(e){ot.set(a,n.replace(/\/[^/]*$/,""));return St(e,i)}).then(function(){})["finally"](function(){ot.set(a,o)})},"(load filename)\n\n Function fetch the file and evaluate its content as LIPS code."),while:re(new Be("while",function(r,e){var i=e.dynamic_scope,a=e.error;var o=this;var u=new je(new Oe("begin"),r.cdr);var c;if(i){i=o}return function n(){var e=xt(r.car,{env:o,dynamic_scope:i,error:a});function t(e){if(e&&!Ve(e)){c=xt(u,{env:o,dynamic_scope:i,error:a});if(ze(c)){return c.then(function(e){c=e;return n()})}else{return n()}}else{return c}}return ne(e,t)}()}),"(while cond . body)\n\n Macro that create a loop, it exectue body untill cond expression is false"),if:re(new Be("if",function(t,e){var r=e.dynamic_scope,i=e.error;if(r){r=this}var a=this;var n=function e(n){if(n){return xt(t.cdr.car,{env:a,dynamic_scope:r,error:i})}else{return xt(t.cdr.cdr.car,{env:a,dynamic_scope:r,error:i})}};var o=xt(t.car,{env:a,dynamic_scope:r,error:i});return ne(o,n)}),"(if cond true-expr false-expr)\n\n Macro evaluate condition expression and if the value is true, it\n evaluate and return true expression if not it evaluate and return\n false expression"),"let-env":new Be("let-env",function(n){var e=arguments.length>1&&arguments[1]!==O?arguments[1]:{};var t=e.dynamic_scope,r=e.error;dt("let-env",n,"pair");var i=xt(n.car,{env:this,dynamic_scope:t,error:r});return ne(i,function(e){if(!(e instanceof nt)){throw new Error("let-env: First argument need to be "+"environment")}return xt(je(Oe("begin"),n.cdr),{env:e,dynamic_scope:t,error:r})})},"(let-env env . body)\n\n Special macro that evaluate body in context of given environment\n object."),letrec:re(ln(Symbol["for"]("letrec")),"(letrec ((a value-a) (b value-b)) body)\n\n Macro that creates new environment, then evaluate and assign values to\n names and then evaluate the body in context of that environment.\n Values are evaluated sequentialy and next value can access to\n previous values/names."),"let*":re(ln(Symbol["for"]("let*")),"(let* ((a value-a) (b value-b)) body)\n\n Macro similar to `let` but next argument get environment\n from previous let variable, so they you can define one variable,\n and use in next argument."),let:re(ln(Symbol["for"]("let")),"(let ((a value-a) (b value-b)) body)\n\n Macro that creates new environment, then evaluate and assign values to\n names and then evaluate the body in context of that environment.\n Values are evaluated sequentialy but you can't access\n previous values/names when next are evaluated. You can only get them\n from body of let expression."),"begin*":re(pn("begin*",function(e){return e.pop()}),"(begin* . expr)\n\n This macro is parallel version of begin. It evaluate each expression and\n if it's a promise it will evaluate it in parallel and return value\n of last expression."),begin:re(new Be("begin",function(e,n){var r=Object.assign({},n);var i=this.get("list->array")(e);if(r.dynamic_scope){r.dynamic_scope=this}r.env=this;var a;return function n(){if(i.length){var e=i.shift();var t=xt(e,r);return ne(t,function(e){a=e;return n()})}else{return a}}()}),"(begin . args)\n\n Macro runs list of expression and return valuate of the list one.\n It can be used in place where you can only have single exression,\n like if expression."),ignore:new Be("ignore",function(e,n){var t=n.dynamic_scope,r=n.error;var i={env:this,error:r};if(t){i.dynamic_scope=this}xt(new je(new Oe("begin"),e),i)},"(ignore expression)\n\n Macro that will evaluate expression and swallow any promises that may\n be created. It wil run and ignore any value that may be returned by\n expression. The code should have side effects and/or when it's promise\n it should resolve to undefined."),define:re(Be.defmacro("define",function(t,e){var r=this;if(t.car instanceof je&&t.car.car instanceof Oe){var n=new je(new Oe("define"),new je(t.car.car,new je(new je(new Oe("lambda"),new je(t.car.cdr,t.cdr)))));return n}else if(e.macro_expand){return}if(e.dynamic_scope){e.dynamic_scope=this}e.env=r;var i=t.cdr.car;if(i instanceof je){i=xt(i,e)}else if(i instanceof Oe){i=r.get(i)}dt("define",t.car,"symbol");return ne(i,function(e){if(r.name===He.merge_env){r=r.parent}var n;if(t.cdr.cdr instanceof je&&En.isString(t.cdr.cdr.car)){n=t.cdr.cdr.car.valueOf()}r.set(t.car,e,n)})}),"(define name expression)\n (define (function-name . args) body)\n\n Macro for defining values. It can be used to define variables,\n or function. If first argument is list it will create function\n with name beeing first element of the list. The macro evalute\n code `(define function (lambda args body))`"),"set-obj!":re(function(e,n,t){var r=Dt(e);if(Ve(e)||r!=="object"&&r!=="function"){var i=vt("set-obj!",yt(e),["object","function"]);throw new Error(i)}e=Xe(e);n=n.valueOf();if(arguments.length===2){delete e[n]}else if(qe(e)&&typeof t==="function"){e[n]=Xe(t);e[n].__prototype__=true}else if(typeof t==="function"){e[n]=t}else{e[n]=t?t.valueOf():t}},"(set-obj! obj key value)\n\n Function set property of JavaScript object"),"null-environment":re(function(){return ot.inherit("null")},"(null-environment)\n\n Function return new base environment with std lib."),values:re(function(){for(var e=arguments.length,n=new Array(e),t=0;t1&&arguments[1]!==O?arguments[1]:{},p=e.dynamic_scope,h=e.error;var v=this;var d;if(l.cdr instanceof je&&En.isString(l.cdr.car)&&l.cdr.cdr!==Ee){d=l.cdr.car.valueOf()}function m(){var e;if(p){if(!(this instanceof nt)){e=v}else{e=this}}else{e=v}e=e.inherit("lambda");var n=l.car;var t=0;var r;if(typeof this!=="undefined"){e.set("this",this)}for(var i=arguments.length,a=new Array(i),o=0;o2&&arguments[2]!==O?arguments[2]:c;if(e instanceof je){var r=e.car;var i=e.cdr;if(t(r)){r=n(r)}if(t(i)){i=n(i)}if(ze(r)||ze(i)){return Promise.all([r,i]).then(function(e){var n=$t(e,2),t=n[0],r=n[1];return new je(t,r)})}else{return new je(r,i)}}return e}function i(e,n){if(e instanceof je){if(n!==Ee){e.append(n)}}else{e=new je(e,n)}return e}function f(r,e,n){if(et){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(e.cdr instanceof je){if(e.cdr.cdr!==Ee){if(e.cdr.car instanceof je){var i=Ee;return function n(t){if(t===Ee){return i}return ne(xt(t.car,{env:u,dynamic_scope:a,error:o}),function(e){i=new je(e,i);return n(t.cdr)})}(e.cdr)}else{return e.cdr}}else{return xt(e.cdr.car,{env:u,dynamic_scope:a,error:o})}}else{return e.cdr}}return s(e,function(e){return p(e,n,t)})}return e}function t(e){if(e instanceof je){delete e.data;if(!e.haveCycles("car")){t(e.car)}if(!e.haveCycles("cdr")){t(e.cdr)}}}var r=p(e.car,0,1);return ne(r,function(e){t(e);return it(e)})},"(quasiquote list ,value ,@value)\n\n Similar macro to `quote` but inside it you can use special\n expressions unquote abbreviated to , that will evaluate expresion inside\n and return its value or unquote-splicing abbreviated to ,@ that will\n evaluate expression but return value without parenthesis (it will join)\n the list with its value. Best used with macros but it can be used outside"),clone:re(function(e){dt("clone",e,"pair");return e.clone()},"(clone list)\n\n Function return clone of the list."),append:re(function(e,n){dt("append",e,["nil","pair"]);if(e instanceof je){e=e.clone()}return this.get("append!").call(this,e,n)},"(append list item)\n\n Function will create new list with value appended to the end. It return\n New list."),"append!":re(function(e,n){dt("append!",e,["pair","nil"]);if(!this.get("list?")(e)){throw new Error("append!: Invalid argument, value is not a list")}if(Ve(n)){return e}if(e===Ee){if(n===Ee){return Ee}return n}return e.append(n)},"(append! name expression)\n\n Destructive version of append, it modify the list in place. It return\n original list."),reverse:re(function(e){dt("reverse",e,["array","pair","nil"]);if(e===Ee){return Ee}if(e instanceof je){var n=this.get("list->array")(e).reverse();return this.get("array->list")(n)}else if(!(e instanceof Array)){throw new Error(vt("reverse",yt(e),"array or pair"))}else{return e.reverse()}},"(reverse list)\n\n Function will reverse the list or array. If value is not a list\n or array it will throw exception."),nth:re(function(e,n){dt("nth",e,"number");dt("nth",n,["array","pair"]);if(n instanceof je){var t=n;var r=0;while(rarray")(n).join(e)},"(join separator list)\n\n Function return string by joining elements of the list"),split:re(function(e,n){dt("split",e,["regex","string"]);dt("split",n,"string");return this.get("array->list")(n.split(e))},"(split separator string)\n\n Function create list by splitting string by separatar that can\n be a string or regular expression."),replace:re(function(e,n,t){dt("replace",e,["regex","string"]);dt("replace",n,["string","function"]);dt("replace",t,"string");return t.replace(e,n)},"(replace pattern replacement string)\n\n Function change pattern to replacement inside string. Pattern can be string\n or regex and replacement can be function or string."),match:re(function(e,n){dt("match",e,["regex","string"]);dt("match",n,"string");var t=n.match(e);return t?this.get("array->list")(t):Ee},"(match pattern string)\n\n function return match object from JavaScript as list."),search:re(function(e,n){dt("search",e,["regex","string"]);dt("search",n,"string");return n.search(e)},"(search pattern string)\n\n Function return first found index of the pattern inside a string"),repr:re(function e(n,t){return Le(n,t)},"(repr obj)\n\n Function return string LIPS representation of an object as string."),env:re(function(e){e=e||this;var n=Object.keys(e.env);var t;if(n.length){t=je.fromArray(n)}else{t=Ee}if(e.parent!==O){return this.get("env").call(this,e.parent).append(t)}return t},"(env obj)\n\n Function return list values (functions and variables) inside environment."),new:re(function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r2&&arguments[2]!==O?arguments[2]:K.LITERAL;dt("set-special!",e,"string",1);dt("set-special!",n,"symbol",2);Nt.specials.append(e.valueOf(),n,t)},'(set-special! symbol name [type])\n\n Add special symbol to the list of transforming operators by the parser.\n e.g.: `(add-special! "#" \'x)` will allow to use `#(1 2 3)` and it will be\n transformed into (x (1 2 3)) so you can write x macro that will process\n the list. 3rd argument is optional and it can be constant value\n lips.specials.SPLICE if this constant is used it will transform\n `#(1 2 3)` into (x 1 2 3) that is required by # that define vectors.'),get:On,".":On,unbind:re(Xe,"(unbind fn)\n\n Function remove bidning from function so you can get props from it."),type:re(yt,"(type object)\n\n Function return type of an object as string."),debugger:re(function(){debugger},"(debugger)\n\n Function stop JavaScript code in debugger."),in:re(function(e,n){if(e instanceof Oe||e instanceof En){e=e.valueOf()}return e in n},"(in key value)\n\n Function use is in operator to check if value is in object."),instanceof:re(function(e,n){return n instanceof Xe(e)},"(instanceof type obj)\n\n Function check of object is instance of object."),"macro?":re(function(e){return e instanceof Be},"(macro? expression)\n\n Function check if value is a macro."),"function?":re(function(e){return typeof e==="function"},"(function? expression)\n\n Function check if value is a function."),"real?":re(function(e){if(yt(e)!=="number"){return false}if(e instanceof qn){return e.isFloat()}return qn.isFloat(e)},"(real? number)\n\n Function check if value is real number."),"number?":re(qn.isNumber,"(number? expression)\n\n Function check if value is a number"),"string?":re(function(e){return En.isString(e)},"(string? expression)\n\n Function check if value is a string."),"pair?":re(function(e){return e instanceof je},"(pair? expression)\n\n Function check if value is a pair or list structure."),"regex?":re(function(e){return e instanceof RegExp},"(regex? expression)\n\n Function check if value is regular expression."),"null?":re(function(e){return Ve(e)},"(null? expression)\n\n Function check if value is nulish."),"boolean?":re(function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Function check if value is boolean."),"symbol?":re(function(e){return e instanceof Oe},"(symbol? expression)\n\n Function check if value is LIPS symbol"),"array?":re(function(e){return e instanceof Array},"(array? expression)\n\n Function check if value is an arrray."),"object?":re(function(e){return e!==Ee&&e!==null&&!(e instanceof qn)&&Dt(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Function check if value is an object."),flatten:re(function(e){dt("flatten",e,"pair");return e.flatten()},"(flatten list)\n\n Return shallow list from tree structure (pairs)."),"array->list":re(function(e){dt("array->list",e,"array");return je.fromArray(e)},"(array->list array)\n\n Function convert JavaScript array to LIPS list."),"tree->array":re(Fe("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":re(Fe("list->array"),"(list->array list)\n\n Function convert LIPS list into JavaScript array."),apply:re(function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;rarray").call(this,i));return e.apply(this,t)},"(apply fn list)\n\n Function that call function with list of arguments."),length:re(function(e){if(!e){return qn(0)}if(e instanceof je){return qn(e.length())}if("length"in e){return qn(e.length)}},"(length expression)\n\n Function return length of the object, the object can be list\n or any object that have length property."),"string->number":re(function(e){var n=arguments.length>1&&arguments[1]!==O?arguments[1]:10;dt("string->number",e,"string",1);dt("string->number",n,"number",2);e=e.valueOf();n=n.valueOf();if(e.match(S)||e.match(w)){return A(e,n)}else if(e.match(k)||e.match(b)){return L(e,n)}else{var t=n===10&&!e.match(/e/i)||n===16;if(e.match(x)&&t||e.match(_)){return I(e,n)}if(e.match(c)){return R(e)}}return false},"(string->number number [radix])\n\n Function convert string to number."),try:re(new Be("try",function(a,e){var o=this;var u=e.dynamic_scope,c=e.error;return new Promise(function(i){var e={env:o,error:function e(n){var t=o.inherit("try");t.set(a.cdr.car.cdr.car.car,n);var r={env:t,error:c};if(u){r.dynamic_scope=o}ne(xt(new je(new Oe("begin"),a.cdr.car.cdr.cdr),r),function(e){i(e)})}};if(u){e.dynamic_scope=o}var n=xt(a.car,e);if(ze(n)){n.then(i)["catch"](e.error)}else{i(n)}})}),"(try expr (catch (e) code)"),throw:re(function(e){throw new Error(e)},"(throw string)\n\n Throw new expection."),find:re(function n(t,r){dt("find",t,["regex","function"]);dt("find",r,"pair");if(Ve(r)){return Ee}var e=te("find",t);return ne(e(r.car),function(e){if(e&&e!==Ee){return r.car}return n(t,r.cdr)})},"(find fn list)\n (find regex list)\n\n Higher order Function find first value for which function return true.\n If called with regex it will create matcher function."),"for-each":re(function(e){var n;dt("for-each",e,"function");for(var t=arguments.length,r=new Array(t>1?t-1:0),i=1;i1?n-1:0),a=1;a3?r-3:0),a=3;a3?i-3:0),o=3;oarray")(n);var a=[];var o=te("filter",e);return function n(t){function e(e){if(e&&e!==Ee){a.push(r)}return n(++t)}if(t===i.length){return je.fromArray(a)}var r=i[t];return ne(o(r,t),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher order function that call `fn` for each element of the list\n and return list for only those elements for which funtion return\n true value. If called with regex it will create matcher function."),range:re(function(e){dt("range",e,"number");if(e instanceof qn){e=e.valueOf()}return je.fromArray(new Array(e).fill(0).map(function(e,n){return qn(n)}))},"(range n)\n\n Function return list of n numbers from 0 to n - 1"),compose:re(dn,"(compose . fns)\n\n Higher order function and create new function that apply all functions\n From right to left and return it's value. Reverse of compose.\n e.g.:\n ((compose (curry + 2) (curry * 3)) 3)\n 11\n "),pipe:re(vn,"(pipe . fns)\n\n Higher order function and create new function that apply all functions\n From left to right and return it's value. Reverse of compose.\n e.g.:\n ((pipe (curry + 2) (curry * 3)) 3)\n 15"),curry:re(_n,"(curry fn . args)\n\n Higher order function that create curried version of the function.\n The result function will have parially applied arguments and it\n will keep returning functions until all arguments are added\n\n e.g.:\n (define (add a b c d) (+ a b c d))\n (define add1 (curry add 1))\n (define add12 (add 2))\n (display (add12 3 4))"),gcd:re(function e(){for(var n=arguments.length,t=new Array(n),r=0;rr?n%=r:r%=n}n=Re(i*(t<0||arguments.length<=t?O:arguments[t]))/(n+r)}return qn(n)},"(lcm n1 n2 ...)\n\n Function return the least common multiple of their arguments."),"odd?":re(gn(function(e){return qn(e).isOdd()}),"(odd? number)\n\n Function check if number os odd."),"even?":re(gn(function(e){return qn(e).isEven()}),"(even? number)\n\n Function check if number is even."),"*":re(wn(function(e,n){return qn(e).mul(n)},qn(1)),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":re(wn(function(e,n){return qn(e).add(n)},qn(0)),"(+ . numbers)\n\n Sum all numbers passed as arguments. If single value is passed it will\n return that value."),"-":re(function(){for(var e=arguments.length,n=new Array(e),t=0;t":re(function(){for(var e=arguments.length,n=new Array(e),t=0;t x1 x2 x3 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically increasing"),"<":re(function(){for(var e=arguments.length,n=new Array(e),t=0;t=":re(function(){for(var e=arguments.length,n=new Array(e),t=0;t= x1 x2 x3 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically nondecreasing"),"eq?":re(Me,"(eq? a b)\n\n Function compare two values if they are identical."),or:re(new Be("or",function(e,n){var i=n.dynamic_scope,a=n.error;var o=this.get("list->array")(e);var u=this;if(i){i=u}var c;return function n(){function e(e){c=e;if(c){return c}else{return n()}}var t=o.shift();if(typeof t==="undefined"){if(c){return c}else{return false}}else{var r=xt(t,{env:u,dynamic_scope:i,error:a});return ne(r,e)}}()}),"(or . expressions)\n\n Macro execute the values one by one and return the one that is truthy value.\n If there are no expression that evaluate to true it return false."),and:re(new Be("and",function(e){var n=arguments.length>1&&arguments[1]!==O?arguments[1]:{},i=n.dynamic_scope,a=n.error;var o=this.get("list->array")(e);var u=this;if(i){i=u}if(!o.length){return true}var c;return function n(){function e(e){c=e;if(!c){return false}else{return n()}}var t=o.shift();if(typeof t==="undefined"){if(c){return c}else{return false}}else{var r=xt(t,{env:u,dynamic_scope:i,error:a});return ne(r,e)}}()}),"(and . expressions)\n\n Macro evalute each expression in sequence if any value return false it will\n return false. If each value return true it will return the last value.\n If it's called without arguments it will return true."),"|":re(function(e,n){return qn(e).or(n)},"(& a b)\n\n Function calculate or bit operation."),"&":re(function(e,n){return qn(e).and(n)},"(& a b)\n\n Function calculate and bit operation."),"~":re(function(e){return qn(e).neg()},"(~ number)\n\n Function negate the value."),">>":re(function(e,n){return qn(e).shr(n)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":re(function(e,n){return qn(e).shl(n)},"(<< a b)\n\n Function left shit the value a by value b."),not:re(function(e){if(Ve(e)){return true}return!e},"(not object)\n\n Function return negation of the argument.")},O,"global");var ut=ot.inherit("user-env");ot.set("**interaction-environment**",ut);(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(n){var t=e[n]?e[n]:n;ot.set(t,re(function(e){dt(t,e,"number");if(e instanceof qn){return e[n]()}},"(".concat(t," number)\n\n Function calculate ").concat(t," of a number.")))})})();function ct(e){if(e.length===1){return e[0]}else{var n=[];var t=ct(e.slice(1));for(var r=0;r3&&arguments[3]!==O?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(r!==null){i+=" argument ".concat(r)}if(t instanceof Array){var a=t[t.length-1];t=t.slice(0,-1).join(", ")+" or "+a}return"Expecting ".concat(t," got ").concat(n).concat(i)}function dt(e,n,t){var r=arguments.length>3&&arguments[3]!==O?arguments[3]:null;e=e.valueOf();var i=yt(n).toLowerCase();var a=false;if(t instanceof je){t=t.toArray()}if(t instanceof Array){t=t.map(function(e){return e.valueOf().toLowerCase()});if(t.includes(i)){a=true}}else{t=t.valueOf().toLowerCase()}if(!a&&i!==t){throw new Error(vt(e,i,t,r))}}function mt(e){var n=Dt(e);return["string","function"].includes(n)||e instanceof Oe||e instanceof qn||e instanceof RegExp}function yt(e){var n={pair:je,symbol:Oe,character:kn,values:rt,macro:Be,string:En,array:Array,"native-symbol":Symbol};if(Number.isNaN(e)){return"NaN "}if(e===Ee){return"nil"}if(e===null){return"null"}if(e instanceof He){return"syntax"}for(var t=0,r=Object.entries(n);t1&&arguments[1]!==O?arguments[1]:{},i=e.env,a=e.dynamic_scope,t=e.error,o=t===void 0?function(){}:t;try{if(a===true){i=a=i||ot}else if(i===true){i=a=ot}else{i=i||ot}var r={env:i,dynamic_scope:a,error:o};var u;if(Ve(n)){return n}if(n instanceof Oe){return i.get(n)}var c=n.car;var s=n.cdr;if(c instanceof je){u=gt(xt(c,r));if(ze(u)){return u.then(function(e){return xt(new je(e,n.cdr),r)})}else if(typeof u!=="function"){throw new Error(yt(u)+" "+i.get("repr")(u)+" is not a function while evaluating "+n.toString())}}if(c instanceof Oe){u=i.get(c);if(u instanceof He){return wt(u,n,r)}else if(u instanceof Be){return _t(u,s,r)}else if(typeof u!=="function"){if(u){var f="".concat(yt(u)," `").concat(u,"' is not a function");throw new Error(f)}throw new Error("Unknown function `".concat(c.name,"'"))}}else if(typeof c==="function"){u=c}if(typeof u==="function"){var l=bt(s,r);return ne(l,function(e){if(en(u)&&(!nn(u)||tn(u))){e=e.map(Qe)}if(u.__lambda__&&!u.__prototype__||tn(u)){u=Xe(u)}var n=e.slice();var t=(a||i).newFrame(u,n);var r=gt(u.apply(t,e));return ne(r,function(e){if(e instanceof je){e.markCycles();return it(e)}if(typeof e==="number"){return qn(e)}if(typeof e==="string"){return En(e)}return e},o)})}else if(n instanceof Oe){u=i.get(n);if(u==="undefined"){throw new Error("Unbound variable `"+n.name+"'")}return u}else if(n instanceof je){u=c&&c.toString();throw new Error("".concat(yt(c)," ").concat(u," is not a function"))}else{return n}}catch(e){o&&o.call(i,e,n)}}function St(e,n,t){return Ot.apply(this,arguments)}function Ot(){Ot=Rt(Pt.mark(function e(t,r,i){var a,o,u,c;return Pt.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(i===true){r=i=r||ut}else if(r===true){r=i=ut}else{r=r||ut}a=ee(t);o=[];case 3:if(a.length){n.next=8;break}return n.abrupt("return",o);case 8:u=a.shift();n.next=11;return xt(u,{env:r,dynamic_scope:i,error:function e(n,t){if(t){if(!(n.code instanceof Array)){n.code=[]}n.code.push(t.toString(true))}throw n}});case 11:c=n.sent;o.push(c);case 13:n.next=3;break;case 15:case"end":return n.stop()}}},e)}));return Ot.apply(this,arguments)}function kt(e){var n={"[":"]","(":")"};var t;if(typeof e==="string"){t=W(e)}else{t=e.map(function(e){return e&&e.token?e.token:e})}var r=Object.keys(n);var i=Object.values(n).concat(r);t=t.filter(function(e){return i.includes(e)});var a=new G;var o=Ut(t),u;try{for(o.s();!(u=o.n()).done;){var c=u.value;if(r.includes(c)){a.push(c)}else if(!a.is_empty()){var s=a.top();var f=n[s];if(c===f){a.pop()}else{throw new Error("Syntax error: missing closing ".concat(f))}}else{throw new Error("Syntax error: not matched closing ".concat(c))}}}catch(e){o.e(e)}finally{o.f()}return a.is_empty()}function Et(e){var n="("+e.toString()+")()";var t=window.URL||window.webkitURL;var r;try{r=new Blob([n],{type:"application/javascript"})}catch(e){var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;r=new i;r.append(n);r=r.getBlob()}return new f.Worker(t.createObjectURL(r))}function jt(e){this.url=e;var o=this.worker=Et(function(){var u;var c;self.addEventListener("message",function(e){var r=e.data;var n=r.id;if(r.type!=="RPC"||n===null){return}function i(e){self.postMessage({id:n,type:"RPC",result:e})}function a(e){self.postMessage({id:n,type:"RPC",error:e})}if(r.method==="eval"){if(!c){a("Worker RPC: LIPS not initilized, call init first");return}c.then(function(){var e=$t(r.params,2),n=e[0],t=e[1];u.exec(n,t).then(function(e){e=e.map(function(e){return e&&e.valueOf()});i(e)})["catch"](function(e){a(e)})})}else if(r.method==="init"){var t=$t(r.params,1),o=t[0];if(typeof o!=="string"){a("Worker RPC: url is not a string")}else{importScripts("".concat(o,"/dist/lips.min.js"));u=new Nt.Interpreter("worker");c=u.exec('(let-env lips.env.parent\n (load "'.concat(o,'/lib/bootstrap.scm")\n (load "').concat(o,'/lib/R5RS.scm")\n (load "').concat(o,'/lib/R7RS.scm"))'));c.then(function(){i(true)})}}})});this.rpc=function(){var r=0;return function e(n,t){var a=++r;return new Promise(function(r,i){o.addEventListener("message",function e(n){var t=n.data;if(t&&t.type==="RPC"&&t.id===a){if(t.error){i(t.error)}else{r(t.result)}o.removeEventListener("message",e)}});o.postMessage({type:"RPC",method:n,id:a,params:t})})}}();this.rpc("init",[e])["catch"](function(e){console.error(e)});this.exec=function(e){var n=arguments.length>1&&arguments[1]!==O?arguments[1]:false;return this.rpc("eval",[e,n])}}je.unDry=function(e){return new je(e.car,e.cdr)};je.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};ke.prototype.toDry=function(){return{value:null}};ke.unDry=function(){return Ee};Oe.prototype.toDry=function(){return{value:{name:this.name}}};Oe.unDry=function(e){return new Oe(e.name)};function Ft(e){console.error(e.message||e);if(e.code){console.error(e.code.map(function(e,n){return"[".concat(n+1,"]: ").concat(e)}))}}function At(){var o=["text/x-lips","text/x-scheme"];if(!window.document){return Promise.resolve()}else{return new Promise(function(i){var a=Array.from(document.querySelectorAll("script"));return function n(){var e=a.shift();if(!e){i()}else{var t=e.getAttribute("type");if(o.includes(t)){var r=e.getAttribute("src");if(r){return f.fetch(r).then(function(e){return e.text()}).then(St).then(n)["catch"](function(e){Ft(e);n()})}else{return St(e.innerHTML).then(n)["catch"](function(e){Ft(e);n()})}}else if(t&&t.match(/lips|lisp/)){console.warn("Expecting "+o.join(" or ")+" found "+t)}return n()}}()})}}if(typeof window!=="undefined"){e(window,At)}var It=function(){var e=En("Thu, 20 Aug 2020 19:59:43 +0000").valueOf();var n=e==="{{"+"DATE}}"?new Date:new Date(e);var t=function e(n){return n.toString().padStart(2,"0")};var r=n.getFullYear();var i=[r,t(n.getMonth()+1),t(n.getDate())].join("-");var a="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter DEV (".concat(i,") \nCopyright (c) 2018-").concat(r," Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables.\nYou can also use (help name) to display help for specic function or macro.\n").replace(/^.*\n/,"");return a}();se.__className="ahead";fe.__className="pattern";ce.__className="formatter";Be.__className="macro";He.__className="syntax";nt.__className="environment";zn.__className="input-port";Wn.__className="output-port";Qn.__className="output-string-port";Kn.__className="input-string-port";qn.__className="number";kn.__className="character";En.__className="string";var Nt={version:"DEV",banner:It,date:"Thu, 20 Aug 2020 19:59:43 +0000",exec:St,parse:ee,tokenize:W,evaluate:xt,Environment:nt,env:ut,Worker:jt,Interpreter:et,balanced_parenthesis:kt,balancedParenthesis:kt,balanced:kt,Macro:Be,Syntax:He,Pair:je,quote:it,InputPort:zn,OutputPort:Wn,InputStringPort:Kn,OutputStringPort:Qn,Formatter:ce,specials:K,repr:Ae,nil:Ee,LSymbol:Oe,LNumber:qn,LFloat:Rn,LComplex:Pn,LRational:$n,LBigInteger:Dn,LCharacter:kn,LString:En,rationalize:Tn};ot.set("lips",Nt);return Nt})})(); \ No newline at end of file +(function(){"use strict";function e(e){throw new Error('"'+e+'" is read-only')}var qt=e;function n(e,n){return n={exports:{}},e(n,n.exports),n.exports}var u=n(function(t){function r(e,n){t.exports=r=Object.setPrototypeOf||function e(n,t){n.__proto__=t;return n};return r(e,n)}t.exports=r});function t(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Date.prototype.toString.call(Reflect.construct(Date,[],function(){}));return true}catch(e){return false}}var a=t;var Pt=n(function(r){function i(e,n,t){if(a()){r.exports=i=Reflect.construct}else{r.exports=i=function e(n,t,r){var i=[null];i.push.apply(i,t);var a=Function.bind.apply(n,i);var o=new a;if(r)u(o,r.prototype);return o}}return i.apply(null,arguments)}r.exports=i});var r=n(function(e){var n=function(o){var e=Object.prototype;var f=e.hasOwnProperty;var c;var n=typeof Symbol==="function"?Symbol:{};var i=n.iterator||"@@iterator";var t=n.asyncIterator||"@@asyncIterator";var r=n.toStringTag||"@@toStringTag";function u(e,n,t,r){var i=n&&n.prototype instanceof s?n:s;var a=Object.create(i.prototype);var o=new F(r||[]);a._invoke=O(e,t,o);return a}o.wrap=u;function l(e,n,t){try{return{type:"normal",arg:e.call(n,t)}}catch(e){return{type:"throw",arg:e}}}var p="suspendedStart";var h="suspendedYield";var v="executing";var d="completed";var m={};function s(){}function a(){}function y(){}var g={};g[i]=function(){return this};var b=Object.getPrototypeOf;var w=b&&b(b(A([])));if(w&&w!==e&&f.call(w,i)){g=w}var _=y.prototype=s.prototype=Object.create(g);a.prototype=_.constructor=y;y.constructor=a;y[r]=a.displayName="GeneratorFunction";function x(e){["next","throw","return"].forEach(function(n){e[n]=function(e){return this._invoke(n,e)}})}o.isGeneratorFunction=function(e){var n=typeof e==="function"&&e.constructor;return n?n===a||(n.displayName||n.name)==="GeneratorFunction":false};o.mark=function(e){if(Object.setPrototypeOf){Object.setPrototypeOf(e,y)}else{e.__proto__=y;if(!(r in e)){e[r]="GeneratorFunction"}}e.prototype=Object.create(_);return e};o.awrap=function(e){return{__await:e}};function S(u,c){function s(e,n,t,r){var i=l(u[e],u,n);if(i.type==="throw"){r(i.arg)}else{var a=i.arg;var o=a.value;if(o&&typeof o==="object"&&f.call(o,"__await")){return c.resolve(o.__await).then(function(e){s("next",e,t,r)},function(e){s("throw",e,t,r)})}return c.resolve(o).then(function(e){a.value=e;t(a)},function(e){return s("throw",e,t,r)})}}var n;function e(t,r){function e(){return new c(function(e,n){s(t,r,e,n)})}return n=n?n.then(e,e):e()}this._invoke=e}x(S.prototype);S.prototype[t]=function(){return this};o.AsyncIterator=S;o.async=function(e,n,t,r,i){if(i===void 0)i=Promise;var a=new S(u(e,n,t,r),i);return o.isGeneratorFunction(n)?a:a.next().then(function(e){return e.done?e.value:a.next()})};function O(o,u,c){var s=p;return function e(n,t){if(s===v){throw new Error("Generator is already running")}if(s===d){if(n==="throw"){throw t}return I()}c.method=n;c.arg=t;while(true){var r=c.delegate;if(r){var i=k(r,c);if(i){if(i===m)continue;return i}}if(c.method==="next"){c.sent=c._sent=c.arg}else if(c.method==="throw"){if(s===p){s=d;throw c.arg}c.dispatchException(c.arg)}else if(c.method==="return"){c.abrupt("return",c.arg)}s=v;var a=l(o,u,c);if(a.type==="normal"){s=c.done?d:h;if(a.arg===m){continue}return{value:a.arg,done:c.done}}else if(a.type==="throw"){s=d;c.method="throw";c.arg=a.arg}}}}function k(e,n){var t=e.iterator[n.method];if(t===c){n.delegate=null;if(n.method==="throw"){if(e.iterator["return"]){n.method="return";n.arg=c;k(e,n);if(n.method==="throw"){return m}}n.method="throw";n.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var r=l(t,e.iterator,n.arg);if(r.type==="throw"){n.method="throw";n.arg=r.arg;n.delegate=null;return m}var i=r.arg;if(!i){n.method="throw";n.arg=new TypeError("iterator result is not an object");n.delegate=null;return m}if(i.done){n[e.resultName]=i.value;n.next=e.nextLoc;if(n.method!=="return"){n.method="next";n.arg=c}}else{return i}n.delegate=null;return m}x(_);_[r]="Generator";_[i]=function(){return this};_.toString=function(){return"[object Generator]"};function E(e){var n={tryLoc:e[0]};if(1 in e){n.catchLoc=e[1]}if(2 in e){n.finallyLoc=e[2];n.afterLoc=e[3]}this.tryEntries.push(n)}function j(e){var n=e.completion||{};n.type="normal";delete n.arg;e.completion=n}function F(e){this.tryEntries=[{tryLoc:"root"}];e.forEach(E,this);this.reset(true)}o.keys=function(t){var r=[];for(var e in t){r.push(e)}r.reverse();return function e(){while(r.length){var n=r.pop();if(n in t){e.value=n;e.done=false;return e}}e.done=true;return e}};function A(n){if(n){var e=n[i];if(e){return e.call(n)}if(typeof n.next==="function"){return n}if(!isNaN(n.length)){var t=-1,r=function e(){while(++t=0;--n){var i=this.tryEntries[n];var a=i.completion;if(i.tryLoc==="root"){return e("end")}if(i.tryLoc<=this.prev){var o=f.call(i,"catchLoc");var u=f.call(i,"finallyLoc");if(o&&u){if(this.prev=0;--t){var r=this.tryEntries[t];if(r.tryLoc<=this.prev&&f.call(r,"finallyLoc")&&this.prev=0;--n){var t=this.tryEntries[n];if(t.finallyLoc===e){this.complete(t.completion,t.afterLoc);j(t);return m}}},catch:function(e){for(var n=this.tryEntries.length-1;n>=0;--n){var t=this.tryEntries[n];if(t.tryLoc===e){var r=t.completion;if(r.type==="throw"){var i=r.arg;j(t)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,t){this.delegate={iterator:A(e),resultName:n,nextLoc:t};if(this.method==="next"){this.arg=c}return m}};return o}(e.exports);try{regeneratorRuntime=n}catch(e){Function("r","regeneratorRuntime = r")(n)}});var Rt=r;function c(e,n,t,r,i,a,o){try{var u=e[a](o);var c=u.value}catch(e){t(e);return}if(u.done){n(c)}else{Promise.resolve(c).then(r,i)}}function i(u){return function(){var e=this,o=arguments;return new Promise(function(n,t){var r=u.apply(e,o);function i(e){c(r,n,t,i,a,"next",e)}function a(e){c(r,n,t,i,a,"throw",e)}i(undefined)})}}var Ct=i;function o(e){if(Array.isArray(e))return e}var s=o;function f(e){if(typeof Symbol!=="undefined"&&Symbol.iterator in Object(e))return Array.from(e)}var l=f;function p(e,n){if(n==null||n>e.length)n=e.length;for(var t=0,r=new Array(n);t=0)continue;t[i]=e[i]}return t}var E=k;function j(e,n){if(e==null)return{};var t=E(e,n);var r,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,r))continue;t[r]=e[r]}}return t}var $t=j;function F(e,n){if(typeof Symbol==="undefined"||!(Symbol.iterator in Object(e)))return;var t=[];var r=true;var i=false;var a=undefined;try{for(var o=e[Symbol.iterator](),u;!(r=(u=o.next()).done);r=true){t.push(u.value);if(n&&t.length===n)break}}catch(e){i=true;a=e}finally{try{if(!r&&o["return"]!=null)o["return"]()}finally{if(i)throw a}}return t}var A=F;function I(e,n){return s(e)||A(e,n)||d(e,n)||y()}var Dt=I;var Ut=n(function(n){function t(e){"@babel/helpers - typeof";if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){n.exports=t=function e(n){return typeof n}}else{n.exports=t=function e(n){return n&&typeof Symbol==="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n}}return t(e)}n.exports=t});function Ht(n){if(typeof Symbol==="undefined"||n[Symbol.iterator]==null){if(Array.isArray(n)||(n=N(n))){var t=0;var e=function e(){};return{s:e,n:function e(){if(t>=n.length)return{done:true};return{done:false,value:n[t++]}},e:function e(n){throw n},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,i=true,a=false,o;return{s:function e(){r=n[Symbol.iterator]()},n:function e(){var n=r.next();i=n.done;return n},e:function e(n){a=true;o=n},f:function e(){try{if(!i&&r["return"]!=null)r["return"]()}finally{if(a)throw o}}}}function N(e,n){if(!e)return;if(typeof e==="string")return L(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);if(t==="Object"&&e.constructor)t=e.constructor.name;if(t==="Map"||t==="Set")return Array.from(e);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return L(e,n)}function L(e,n){if(n==null||n>e.length)n=e.length;for(var t=0,r=new Array(n);t1&&arguments[1]!==E?arguments[1]:10;var t=F(e);var r=t.number.split("/");var i=Un({num:Rn([r[0],t.radix||n]),denom:Rn([r[1],t.radix||n])});if(t.inexact){return i.valueOf()}else{return i}}function I(e){var n=arguments.length>1&&arguments[1]!==E?arguments[1]:10;var t=F(e);if(t.inexact){return Mn(parseInt(t.number,t.radix||n))}return Rn([t.number,t.radix||n])}function N(e){var n=e.match(/#\\x([0-9a-f]+)$/i);var t;if(n){var r=parseInt(n[1],16);t=String.fromCodePoint(r)}else{n=e.match(/#\\(.+)$/);if(n){t=n[1]}}if(t){return jn(t)}}function L(e){var i=arguments.length>1&&arguments[1]!==E?arguments[1]:10;function n(e){var n;if(e==="+"){n=Rn(1)}else if(e==="-"){n=Rn(-1)}else if(e.match(x)){n=Rn([e,i])}else if(e.match(S)){var t=e.split("/");n=Un({num:Rn([t[0],i]),denom:Rn([t[1],i])})}else if(e.match(c)){var r=Mn(parseFloat(e));if(a.exact){return r.toRational()}return r}else{throw new Error("Internal Parser Error")}if(a.inexact){return Mn(n.valueOf())}return n}var a=F(e);i=a.radix||i;var t;var r=a.number.match(k);if(i!==10&&r){t=r}else{t=a.number.match(l[i])}var o,u;u=n(t[2]);if(t[1]){o=n(t[1])}else if(u instanceof Mn){o=Mn(0)}else{o=Rn(0)}return Cn({im:u,re:o})}function q(e){return parseInt(e.toString(),10)===e}function P(e){var n=e.match(/^(([-+]?[0-9]*)(?:\.([0-9]+))?)e([-+]?[0-9]+)/i);if(n){var t=parseInt(n[4],10);var r;var i=n[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var a=n[3]&&n[3].length;if(i0){return Rn(a).mul(u)}}}t=Mn(t);if(n.exact){return t.toRational()}return t}function C(e){var n=/([^\\\n])(\\(?:\\{2})*)(?!x[0-9A-F]+)(?!u[0-9A-F]{2,4})(.)/gi;e=e.replace(n,function(e,n,t,r){if(!['"',"/","b","f","n","\\","r","t","x"].includes(r)){t=t.substring(1).replace(/\\\\/,"\\")}return e}).replace(/\\x([0-9a-f]+);/gi,function(e,n){return"\\u"+n.padStart(4,"0")}).replace(/\n/g,"\\n");var t=e.match(/(\\*)(\\x[0-9A-F])/i);if(t&&t[1].length%2===0){throw new Error("Invalid string literal, unclosed ".concat(t[2]))}try{return Fn(JSON.parse(e))}catch(e){throw new Error("Invalid string literal")}}function M(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var t={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,n){return String.fromCharCode(parseInt("0"+n,16))}).replace(/\\(.)/g,function(e,n){return t[n]||n})}return new Oe(e)}function T(e){var n=e.match(a);if(n){return new RegExp(n[1],n[2])}else if(e.match(/^"/)){return C(e)}else if(e.match(m)){return N(e)}else if(e.match(w)){return A(e)}else if(e.match(b)){return L(e)}else if(e.match(_)){return I(e)}else if(e.match(c)){return R(e)}else if(e==="nil"){return Fe}else if(["true","#t"].includes(e)){return true}else if(["false","#f"].includes(e)){return false}else{return M(e)}}function B(e){return!(["(",")"].includes(e)||e.match(a)||e.match(/^"[\s\S]+"$/)||e.match(_)||e.match(c)||e.match(b)||e.match(w)||["#t","#f","nil","true","false"].includes(e))}var $=/("(?:\\[\S\s]|[^"])*"?|\/(?! )[^\n\/\\]*(?:\\[\S\s][^\n\/\\]*)*\/[gimy]*(?=[\s[\]()]|$)|\|[^|\s\n]+\||#;|;.*|#\|(?!\|#)[\s\S]*\|#)/g;var D=/"(?:\\[\S\s]|[^"])*"?/g;var U=[r,n,i].map(y).join("|");function H(){var e=K.names().sort(function(e,n){return n.length-e.length||e.localeCompare(n)}).map(Y).join("|");return new RegExp("(".concat(d,"|#f|#t|#;|(?:").concat(U,")(?=$|[\\n\\s()[\\]])|\\[|\\]|\\(|\\)|\\|[^|]+\\||;.*|(?:#[ei])?").concat(o,"(?=$|[\\n\\s()[\\]])|\\n|\\.{2,}|'(?=#[ft]|(?:#[xiobe]){1,2}|#\\\\)|(?!#:)(?:").concat(e,")|[^(\\s)[\\]]+)"),"gim")}function J(e){var n=arguments.length>1&&arguments[1]!==E?arguments[1]:1;return e[e.length-n]}function Y(e){if(typeof e==="string"){var n=/([-\\^$[\]()+{}?*.|])/g;return e.replace(n,"\\$1")}}function G(){this.data=[]}G.prototype.push=function(e){this.data.push(e)};G.prototype.top=function(){return this.data[this.data.length-1]};G.prototype.pop=function(){return this.data.pop()};G.prototype.is_empty=function(){return!this.data.length};function V(e){var a=H();e=e.replace(/\n\r|\r/g,"\n");var o=0;var u=0;var c=[];var s=[];var f=0;e.split($).filter(Boolean).forEach(function(e){if(e.match($)){f=0;if(s.length){var n=J(s);if(n.token.match(/\n/)){var t=n.token.split("\n").pop();f+=t.length}else{f+=n.token.length}f+=n.col}var r={col:f,line:u,token:e,offset:o};c.push(r);s.push(r);o+=e.length;f+=e.length;u+=(e.match("\n")||[]).length;return}var i=e.split(a).filter(Boolean);i.forEach(function(e){var n={col:f,line:u,token:e,offset:o};f+=e.length;o+=e.length;c.push(n);s.push(n);if(e==="\n"){++u;s=[];f=0}})});return c}function z(e){var n=e.token,t=$t(e,["token"]);if(n.match(/^"[\s\S]+"$/)&&n.match(/\n/)){var r=new RegExp("^ {1,"+(e.col+1)+"}","mg");n=n.replace(r,"")}return Jt({token:n},t)}function W(e,n){var t=arguments.length>2&&arguments[2]!==E?arguments[2]:z;if(e instanceof Fn){e=e.toString()}if(n){return V(e).map(t)}else{var r=V(e).map(function(e){var n=t(e);if(!n||typeof n.token!=="string"){throw new Error("[tokenize] Invalid formatter wrong return object")}if(n.token==="#\\ "){return n.token}return n.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return Q(r)}}function Q(e){var n=0;var t=null;var r=[];for(var i=0;i1&&!e[0].literal){c.pop();if(c[c.length-1].length===1&&c[c.length-1][0]instanceof Oe){c[c.length-1].push(e)}else if(c[c.length-1]instanceof Ae){if(c[c.length-1].cdr instanceof Ae){c[c.length-1]=new Ae(c[c.length-1],Ae.fromArray(e))}else{c[c.length-1].cdr=Ae.fromArray(e)}}else{c[c.length-1].push(e)}}}e.forEach(function(e){var n=c[c.length-1];if(l.indexOf(e)!==-1){y++;f=e;c.push([K.get(f).symbol]);if(!f){m=[]}m.push(f)}else{if(f){d.push(m);m=[]}if(b(e)){v=true;h++;var t=[];if(f&&!X(f)){t.push(g)}c.push(t);f=null;y=0}else if(e==="."&&!v){c[c.length-1]=Ae.fromArray(n)}else if(w(e)){h--;if(!c.length){throw new Error("Unbalanced parenthesis")}if(c.length===1){var r=c.pop();if(r instanceof Array&&r.length===0){r=Fe}s.push(r)}else if(c.length>1){var i=c.pop();n=c[c.length-1];if(n instanceof Array){if(i.length===0){n.push(Fe)}else if(i instanceof Array&&i[0]===g){var a;(a=n).push.apply(a,Tt(i.slice(1)))}else{n.push(i)}}else if(n instanceof Ae){if(i.length===0){n.append(Fe)}else{n.append(Ae.fromArray(i))}}if(d.length){m=d.pop();while(m.length){_();m.pop()}}else{_()}}if(h===0&&c.length){s.push(c.pop())}}else{v=false;var o=T(e);if(f){while(y--){c[c.length-1].push(o);o=c.pop()}d.pop();y=0;f=false}else if(o instanceof Oe&&p.includes(o.name)){o.literal=true}n=c[c.length-1];if(n instanceof Ae){var u=n;while(true){if(u.cdr===Fe){if(o instanceof Array){u.cdr=Ae.fromArray(o)}else{u.cdr=o}break}else{u=u.cdr}}}else if(!c.length){s.push(o)}else{n.push(o)}}}});if(!e.filter(function(e){return e.match(/^[[\]()]$/)}).length&&c.length){s=s.concat(c);c=[]}if(c.length){throw new Error("Unbalanced parenthesis 2")}return s.map(function(e){if(e instanceof Array){return Ae.fromArray(e)}return e})}function ne(e){var n=arguments.length>1&&arguments[1]!==E?arguments[1]:function(e){return e};var t=arguments.length>2&&arguments[2]!==E?arguments[2]:null;if(e instanceof Array){var r=e.filter(Qe);if(r.length){return ne(Promise.all(r),n,t)}return n(e)}if(Qe(e)){var i=e.then(n);if(t===null){return i}else{return i["catch"](t)}}return n(e)}function te(e,n){if(n instanceof RegExp){return function(e){return String(e).match(n)}}else if(typeof n!=="function"){throw new Error("".concat(e," argument need to be a function or RegExp"))}else{return n}}function re(e,n,t){if(n){if(t){e.__doc__=n}else{e.__doc__=ie(n)}}return e}function ie(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function ae(e){var n=arguments.length>1&&arguments[1]!==E?arguments[1]:1;var t=e.length;if(n<=0){throw Error("previousSexp: Invlaid argument sexp = ".concat(n))}e:while(n--&&t>=0){var r=1;while(r>0){var i=e[--t];if(!i){break e}if(i==="("||i.token==="("){r--}else if(i===")"||i.token===")"){r++}}t--}return e.slice(t+1)}function oe(e){if(!e||!e.length){return 0}var n=e.length;if(e[n-1].token==="\n"){return 0}while(--n){if(e[n].token==="\n"){var t=(e[n+1]||{}).token;if(t){return t.length}}}return 0}function ue(e,n){return f(e,n)===n.length;function f(t,r){function e(){return a>0&&u>0&&t[a-1]===r[u-1]&&t[a+1]===r[u]}function n(){return t[a]===Symbol["for"]("symbol")&&!B(r[u])}function i(){var e=t[a+1];var n=r[u+1];if(e!==E&&n!==E){return f([e],[n])}}var a=0;var o={};for(var u=0;u0){continue}}else if(n()){return-1}}else if(t[a]instanceof Array){var s=f(t[a],r.slice(u));if(s===-1||s+u>r.length){return-1}u+=s-1;a++;continue}else{return-1}a++}if(t.length!==a){return-1}return r.length}}function ce(e){this._code=e.replace(/\r/g,"")}ce.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?define/,/^(?:#:)?lambda/,/^(?:#:)?let*/,/^(?:#:)?(let|letrec)(-syntax)?$/,/(?:#:)?let-env/,/(?:#:)?syntax-rules/,/(?:#:)?try/,/(?:#:)?catch/,/(?:#:)?while/],shift:{1:["&","#"]}}};ce.match=ue;ce.prototype._options=function e(n){var t=ce.defaults;if(typeof n==="undefined"){return Object.assign({},t)}var r=n&&n.exceptions||{};var i=r.specials||[];var a=r.shift||{1:[]};return Jt(Jt(Jt({},t),n),{},{exceptions:{specials:[].concat(Tt(t.exceptions.specials),Tt(i)),shift:Jt(Jt({},a),{},{1:[].concat(Tt(t.exceptions.shift[1]),Tt(a[1]))})}})};ce.prototype.indent=function e(n){var t=W(this._code,true);return this._indent(t,n)};ce.exception_shift=function(a,e){function n(e){if(!e.length){return false}if(e.indexOf(a)!==-1){return true}else{var n=e.filter(function(e){return e instanceof RegExp});if(!n.length){return false}var t=Ht(n),r;try{for(t.s();!(r=t.n()).done;){var i=r.value;if(a.match(i)){return true}}}catch(e){t.e(e)}finally{t.f()}}return false}if(n(e.exceptions.specials)){return e.indent}var t=e.exceptions.shift;for(var r=0,i=Object.entries(t);r0){r.offset=0}if(a.toString()===n.toString()&&Et(a)){return r.offset+a[0].col}else if(a.length===1){return r.offset+a[0].col+1}else{var u=-1;if(o){var c=ce.exception_shift(o.token,r);if(c!==-1){u=c}}if(u===-1){u=ce.exception_shift(a[1].token,r)}if(u!==-1){return r.offset+a[0].col+u}else if(a[0].line3&&a[1].line===a[3].line){if(a[1].token==="("||a[1].token==="["){return r.offset+a[1].col}return r.offset+a[3].col}else if(a[0].line===a[1].line){return r.offset+r.indent+a[0].col}else{var s=a.slice(2);for(var f=0;f")};se.prototype.match=function(e){return e.match(this.pattern)};function fe(e,n){this.pattern=e;this.flag=n}fe.prototype.toString=function(){return"#")};ce.Pattern=fe;ce.Ahead=se;var le=/[[(]/;var pe=/[\])]/;var he=/[^()[\]]/;var ve=new se(/[^)\]]/);var de=Symbol["for"]("*");var me=new fe([le,de,pe],"+");var ye=new fe([Symbol["for"]("symbol")],"?");var ge=new fe([le,Symbol["for"]("symbol"),de,pe],"+");var be=_e("define","lambda","syntax-rules");var we=/^(?:#:)?(let|let\*|letrec|let-env)(:?-syntax)?$/;function _e(){for(var e=arguments.length,n=new Array(e),t=0;t0&&arguments[0]!==E?arguments[0]:null;if(e instanceof Oe){e=e.valueOf()}if(ke(e)){return Oe(e)}if(e!==null){return new Oe(Symbol("#:".concat(e)))}n++;return new Oe(Symbol("#:g".concat(n)))}}();function je(){}je.prototype.toString=je.prototype.toJSON=function(){return"()"};je.prototype.valueOf=function(){return E};je.prototype.append=function(e){return new Ae(e,Fe)};je.prototype.toArray=function(){return[]};var Fe=new je;function Ae(e,n){if(typeof this!=="undefined"&&this.constructor!==Ae||typeof this==="undefined"){return new Ae(e,n)}this.car=e;this.cdr=n}function Ie(a,o){return function e(n){mt(a,n,["pair","nil"]);if(n===Fe){return[]}var t=[];var r=n;while(true){if(r instanceof Ae){if(r.haveCycles("cdr")){break}var i=r.car;if(o&&i instanceof Ae){i=this.get(a).call(this,i)}t.push(i);r=r.cdr}else{break}}return t}}Ae.prototype.flatten=function(){return Ae.fromArray(xe(this.toArray()))};Ae.prototype.length=function(){var e=0;var n=this;while(true){if(!n||n===Fe||!(n instanceof Ae)||n.haveCycles("cdr")){break}e++;n=n.cdr}return e};Ae.prototype.clone=function(){var t=new Map;function r(e){if(e instanceof Ae){if(t.has(e)){return t.get(e)}var n=new Ae;t.set(e,n);n.car=r(e.car);n.cdr=r(e.cdr);n.cycles=e.cycles;return n}return e}return r(this)};Ae.prototype.lastPair=function(){var e=this;while(true){if(e.cdr===Fe){return e}e=e.cdr}};Ae.prototype.toArray=function(){var e=[];if(this.car instanceof Ae){e.push(this.car.toArray())}else{e.push(this.car.valueOf())}if(this.cdr instanceof Ae){e=e.concat(this.cdr.toArray())}return e};Ae.fromArray=function(e){var n=arguments.length>1&&arguments[1]!==E?arguments[1]:true;if(e instanceof Ae){return e}if(n===false){var t=Fe;for(var r=e.length;r--;){t=new Ae(e[r],t)}return t}if(e.length&&!(e instanceof Array)){e=Tt(e)}if(e.length===0){return Fe}else{var i;if(e[0]instanceof Array){i=Ae.fromArray(e[0])}else{i=e[0]}if(typeof i==="string"){i=Fn(i)}if(e.length===1){return new Ae(i,Fe)}else{return new Ae(i,Ae.fromArray(e.slice(1)))}}};Ae.prototype.toObject=function(){var e=arguments.length>0&&arguments[0]!==E?arguments[0]:false;var n=this;var t={};while(true){if(n instanceof Ae&&n.car instanceof Ae){var r=n.car;var i=r.car;if(i instanceof Oe){i=i.name}if(i instanceof String){i=i.valueOf()}var a=r.cdr;if(a instanceof Ae){a=a.toObject(e)}if(a instanceof Rn||a instanceof Fn||a instanceof jn){if(!e){a=a.valueOf()}}t[i]=a;n=n.cdr}else{break}}return t};Ae.fromPairs=function(e){return e.reduce(function(e,n){return new Ae(new Ae(new Oe(n[0]),n[1]),e)},Fe)};Ae.fromObject=function(n){var e=Object.keys(n).map(function(e){return[e,n[e]]});return Ae.fromPairs(e)};Ae.prototype.reduce=function(e){var n=this;var t=Fe;while(true){if(n!==Fe){t=e(t,n.car);n=n.cdr}else{break}}return t};Ae.prototype.reverse=function(){if(this.haveCycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var n=Fe;while(e!==Fe){var t=e.cdr;e.cdr=n;n=e;e=t}return n};Ae.prototype.transform=function(r){function i(e){if(e instanceof Ae){if(e.replace){delete e.replace;return e}var n=r(e.car);if(n instanceof Ae){n=i(n)}var t=r(e.cdr);if(t instanceof Ae){t=i(t)}return new Ae(n,t)}return e}return i(this)};Ae.prototype.map=function(e){if(typeof this.car!=="undefined"){return new Ae(e(this.car),this.cdr===Fe?Fe:this.cdr.map(e))}else{return Fe}};var Ne=new Map;function Le(t){var e=t.constructor||Object;var r=Ut(t)==="object"&&e===Object;var i;if(Ne.has(e)){i=Ne.get(e)}else{Ne.forEach(function(e,n){if(t instanceof n&&(n===Object&&r||n!==Object)){i=e}})}return i}var qe=new Map;[[Number.NEGATIVE_INFINITY,"-inf.0"],[Number.POSITIVE_INFINITY,"+inf.0"],[true,"#t"],[false,"#f"],[null,"null"],[E,"#"]].forEach(function(e){var n=Dt(e,2),t=n[0],r=n[1];qe.set(t,r)});function Pe(e,n,t){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(qe.has(e)){return qe.get(e)}if(e instanceof Ae){if(!t){e.markCycles()}return e.toString(n)}if(Number.isNaN(e)){return"+nan.0"}var r=[RegExp,je,Oe,Rn,jn,at];for(var i=0,a=r;i"}if(pn(e.toString)){return"#"}else{return e.toString()}}if(e instanceof Fn){e=e.toString()}if(e===null||typeof e==="string"&&n){return JSON.stringify(e)}if(Ut(e)==="object"){if(typeof e.toString==="function"&&e.toString.__lambda__){return e.toString().valueOf()}var u=e.constructor;if(!u){u=Object}var c;if(typeof u.__className==="string"){c=u.__className}else{if(Re(e)){return"#"}var s=Le(e);if(s){if(typeof s==="function"){return s(e,n)}else{throw new Error("toString: Invalid repr value")}}c=u.name}if(gt(e)==="instance"&&!pn(u)){c="instance"}if(f.HTMLElement&&e instanceof f.HTMLElement){return"#")}if(c!==""){return"#<"+c+">"}if(typeof e[Symbol.iterator]==="function"){return"#"}return"#"}if(typeof e!=="string"){return e.toString()}return e}function Re(e){return e&&Ut(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}Ae.prototype.markCycles=function(){Ce(this);return this};Ae.prototype.haveCycles=function(){var e=arguments.length>0&&arguments[0]!==E?arguments[0]:null;if(!e){return this.haveCycles("car")||this.haveCycles("cdr")}return!!(this.cycles&&this.cycles[e])};function Ce(e){var n=[];var i=[];var a=[];function o(e){if(!n.includes(e)){n.push(e)}}function u(e,n,t,r){if(t instanceof Ae){if(r.includes(t)){if(!a.includes(t)){a.push(t)}if(!e.cycles){e.cycles={}}e.cycles[n]=t;if(!i.includes(e)){i.push(e)}return true}}}function c(e,n){if(e instanceof Ae){delete e.ref;delete e.cycles;o(e);n.push(e);var t=u(e,"car",e.car,n);var r=u(e,"cdr",e.cdr,n);if(!t){c(e.car,n.slice())}if(!r){c(e.cdr,n.slice())}}}function t(e,n){if(e.cycles[n]instanceof Ae){var t=r.indexOf(e.cycles[n]);e.cycles[n]="#".concat(t,"#")}}c(e,[]);var r=n.filter(function(e){return a.includes(e)});r.forEach(function(e,n){e.ref="#".concat(n,"=")});i.forEach(function(e){t(e,"car");t(e,"cdr")})}Ae.prototype.toString=function(e,n){var t=[];if(this.ref){t.push(this.ref+"(")}else if(!n){t.push("(")}var r;if(this.cycles&&this.cycles.car){r=this.cycles.car}else{r=Pe(this.car,e,true)}if(r!==E){t.push(r)}if(this.cdr instanceof Ae){if(this.cycles&&this.cycles.cdr){t.push(" . ");t.push(this.cycles.cdr)}else{if(this.cdr.ref){t.push(" . ")}else{t.push(" ")}var i=this.cdr.toString(e,true);t.push(i)}}else if(typeof this.cdr!=="undefined"&&this.cdr!==Fe){t=t.concat([" . ",Pe(this.cdr,e,true)])}if(!n||this.ref){t.push(")")}return t.join("")};Ae.prototype.set=function(e,n){this[e]=n;if(n instanceof Ae){this.markCycles()}};Ae.prototype.append=function(e){if(e instanceof Array){return this.append(Ae.fromArray(e))}var n=this;if(n.car===E){if(e instanceof Ae){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(e!==Fe){while(true){if(n instanceof Ae&&n.cdr!==Fe){n=n.cdr}else{break}}n.cdr=e}return this};function Me(e){return e<0?-e:e}function Te(e,n){var t=Mt(n),r=t[0],i=t.slice(1);while(i.length>0){var a=i,o=Dt(a,1),u=o[0];if(!e(r,u)){return false}var c=i;var s=Mt(c);r=s[0];i=s.slice(1)}return true}function Be(e,n){if(typeof e==="function"&&typeof n==="function"){return en(e)===en(n)}else if(e instanceof Rn&&n instanceof Rn){var t;if(e.type===n.type){if(e.type==="complex"){t=e.im.type===n.im.type&&e.re.type===n.re.type}else{t=true}return t&&e.cmp(n)===0}return false}else if(typeof e==="number"||typeof n==="number"){e=Rn(e);n=Rn(n);return e.type===n.type&&e.cmp(n)===0}else if(e instanceof jn&&n instanceof jn){return e["char"]===n["char"]}else if(e instanceof Oe&&n instanceof Oe){return e.name===n.name}else{return e===n}}var $e=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function De(e,n,t,r){if(typeof this!=="undefined"&&this.constructor!==De||typeof this==="undefined"){return new De(e,n)}mt("Macro",e,"string",1);mt("Macro",n,"function",2);if(t){if(r){this.__doc__=t}else{this.__doc__=ie(t)}}this.name=e;this.fn=n}De.defmacro=function(e,n,t,r){var i=new De(e,n,t,r);i.defmacro=true;return i};De.prototype.invoke=function(e,n,t){var r=n.env,i=n.dynamic_scope,a=n.error;var o={dynamic_scope:i,error:a,macro_expand:t};var u=this.fn.call(r,e,o,this.name);return u};De.prototype.toString=function(){return"#"};var Ue="define-macro";var He=-1e4;function Je(a){return function(){var t=Ct(Rt.mark(function e(t,v){var r,d,i;return Rt.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:i=function e(){i=Ct(Rt.mark(function e(t,r,i){var a,o,u,c,s,f,l,p,h;return Rt.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(!(t instanceof Ae&&t.car instanceof Oe)){n.next=24;break}if(!t.data){n.next=3;break}return n.abrupt("return",t);case 3:a=i.get(t.car,{throwError:false});if(!(a instanceof De&&a.defmacro)){n.next=24;break}o=a instanceof Ye?t:t.cdr;n.next=8;return a.invoke(o,v,true);case 8:u=n.sent;if(!(a instanceof Ye)){n.next=17;break}c=u,s=c.expr,f=c.scope;if(!(s instanceof Ae)){n.next=16;break}if(!(r!==-1&&r<=1||r"};Ye.className="syntax";function Ge(e,n,d,m){var y={"...":{symbols:{},lists:[]}};function g(e){if(ct.get("DEBUG",{throwError:false})){console.log(e)}}g(d);function b(e,n){var t=arguments.length>2&&arguments[2]!==E?arguments[2]:[];var r=arguments.length>3&&arguments[3]!==E?arguments[3]:false;g({code:n&&n.toString(),pattern:e&&e.toString()});if(e instanceof Oe&&d.includes(e.valueOf())){return Oe.is(n,e)}if(e instanceof Ae&&e.car instanceof Ae&&e.car.cdr instanceof Ae&&Oe.is(e.car.cdr.car,m)){g(">> 0");if(n===Fe){g({pattern:e.toString()});if(e.car.car instanceof Oe){if(e.car.cdr instanceof Ae&&Oe.is(e.car.cdr.car,m)){var i=e.car.car.valueOf();var a=e.lastPair();if(Oe.is(a.car,m)){y["..."].symbols[i]=null;return true}else{return false}}var o=e.car.car.valueOf();if(y["..."].symbols[o]){throw new Error("syntax: named ellipsis can only "+"appear onces")}y["..."].symbols[o]=n}}}if(e instanceof Ae&&e.cdr instanceof Ae&&Oe.is(e.cdr.car,m)){if(e.cdr.cdr!==Fe){throw new Error("syntax: invalid usage of ellipsis")}if(e.car instanceof Oe){var u=e.car.name;if(y["..."].symbols[u]&&!t.includes(u)&&!r){throw new Error("syntax: named ellipsis can only appear onces")}g(">> 1");if(n===Fe){g(">> 2");if(r){g("NIL");y["..."].symbols[u]=Fe}else{g("NULL");y["..."].symbols[u]=null}}else if(n instanceof Ae&&(n.car instanceof Ae||n.car===Fe)){g(">> 3 "+r);if(r){if(y["..."].symbols[u]){var c=y["..."].symbols[u];y["..."].symbols[u]=c.append(new Ae(n,Fe))}else{y["..."].symbols[u]=new Ae(n,Fe)}}else{g(">> 4");y["..."].symbols[u]=new Ae(n,Fe)}}else{g(">> 6");if(n instanceof Ae){g(">> 7 "+r);t.push(u);if(!y["..."].symbols[u]){y["..."].symbols[u]=new Ae(n,Fe)}else{var s=y["..."].symbols[u];y["..."].symbols[u]=s.append(new Ae(n,Fe))}g({IIIIII:y["..."].symbols[u].toString()})}else{g(">> 8");return false}}return true}else if(e.car instanceof Ae){var f=Tt(t);if(n===Fe){g(">> 9");y["..."].lists.push(Fe);return true}g(">> 10");var l=n;while(l instanceof Ae){if(!b(e.car,l.car,f,true)){return false}l=l.cdr}return true}return false}if(e instanceof Oe){if(Oe.is(e,m)){throw new Error("syntax: invalid usage of ellipsis")}g(">> 11");var p=e.name;if(d.includes(p)){return true}g({name:p,ellipsis:r});if(r){y["..."].symbols[p]=y["..."].symbols[p]||[];y["..."].symbols[p].push(n)}if(!y[p]){y[p]=n}return true}if(e instanceof Ae&&n instanceof Ae){g(">> 12");g({a:12,code:n&&n.toString(),pattern:e.toString()});if(n.cdr===Fe){var h=e.car instanceof Oe&&e.cdr instanceof Oe;if(h){g(">> 12 | 1");var v=e.cdr.valueOf();if(!y[v]){y[v]=Fe}v=e.car.valueOf();if(!y[v]){y[v]=n.car}return true}}g("recur");if(b(e.car,n.car,t,r)&&b(e.cdr,n.cdr,t,r)){return true}}else if(e===Fe&&(n===Fe||n===E)){return true}else if(e.car instanceof Ae&&Oe.is(e.car.car,m)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(b(e,n)){return y}}function Ve(e,i){function a(n){if(n instanceof Ae){if(!i.length){return n}var e=a(n.car);var t=a(n.cdr);return new Ae(e,t)}else if(n instanceof Oe){var r=i.find(function(e){return e.gensym===n});if(r){return Oe(r.name)}return n}else{return n}}return a(e)}function ze(){var e=arguments.length>0&&arguments[0]!==E?arguments[0]:{};var g=e.bindings,n=e.expr,r=e.scope,t=e.symbols,i=e.names,b=e.ellipsis;var a={};function w(e){if(!(e instanceof Oe||typeof e==="string")){throw new Error("syntax: internal error, rename neeed to be symbol")}var n=e.valueOf();if(n===b){throw new Error("syntax: internal error, ellipis not transformed")}if(typeof n==="string"&&n in g){return g[n]}if(t.includes(n)){return Oe(n)}return o(n)}function _(e){if(ct.get("DEBUG",{throwError:false})){console.log(e)}}function o(e){if(!a[e]){var n=r.get(e,{throwError:false});var t=Ee(e);i.push({name:e,gensym:t});if(typeof n!=="undefined"){r.set(t,n)}a[e]=t}return a[e]}function x(e,n,t){var r=arguments.length>3&&arguments[3]!==E?arguments[3]:function(){};var i=t.nested;_(" ==> "+e.toString());if(e instanceof Oe){var a=e.valueOf();_("[t 1");if(n[a]){if(n[a]instanceof Ae){var o=n[a],u=o.car,c=o.cdr;if(i){var s=u.car,f=u.cdr;if(f!==Fe){r(a,new Ae(f,Fe))}return s}if(c!==Fe){r(a,c)}return u}else if(n[a]instanceof Array){r(a,n[a].slice(1));return n[a][0]}}return w(a)}if(e instanceof Ae){if(e.car instanceof Oe&&e.cdr instanceof Ae&&Oe.is(e.cdr.car,b)){_("[t 2");var l=e.car.valueOf();var p=n[l];if(p===null){_({name:l});return}if(p){_({b:n[l]});if(p instanceof Ae){_("[t 2 Pair "+i);_({______:p.toString()});var h=p.car,v=p.cdr;if(i){if(v!==Fe){r(l,v)}return h}else{if(h.cdr!==Fe){r(l,new Ae(h.cdr,v))}return h.car}}else if(p instanceof Array){_("[t 2 Array "+i);if(i){r(l,p.slice(1));return Ae.fromArray(p)}else{var d=p.slice(1);if(d.length){r(l,d)}return p[0]}}else{return p}}}_("[t 3 recur "+e.toString());var m={nested:i};var y=x(e.car,n,m,r);var g=x(e.cdr,n,m,r);_({b:true,head:y&&y.toString(),rest:g&&g.toString()});return new Ae(y,g)}}function S(n){var e=Object.values(n);var t=Object.getOwnPropertySymbols(n);if(t.length){e.push.apply(e,Tt(t.map(function(e){return n[e]})))}return e.length&&e.every(function(e){return e instanceof Ae||e===null||e===Fe||e instanceof Array&&e.length})}function O(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function k(i){var e=arguments.length>1&&arguments[1]!==E?arguments[1]:{},n=e.disabled;_(">> "+i.toString());if(i instanceof Ae){if(!n&&i.car instanceof Ae&&Oe.is(i.car.car,b)){return k(i.car.cdr,{disabled:true})}if(i.cdr instanceof Ae&&Oe.is(i.cdr.car,b)&&!n){_(">> 1");var t=g["..."].symbols;var r=O(t);if(i.car instanceof Ae){if(g["..."].lists[0]===Fe){return Fe}_(">> 2");var a;if(r.length){_(">> 2 (a)");var o=Jt({},t);a=Fe;var u=function e(){if(!S(o)){return"break"}var r={};var n=function e(n,t){r[n]=t};var t=x(i.car,o,{nested:true},n);if(t!==E){a=new Ae(t,a)}o=r};while(true){var c=u();if(c==="break")break}if(a!==Fe){a=a.reverse()}return a}else{_(">> 3");var s=x(i.car,t,{nested:true});if(s){return new Ae(s,Fe)}return Fe}}else if(i.car instanceof Oe){_(">> 4");var f=i.car.name;var l=Bt({},f,t[f]);var p=Fe;var h=function e(){if(!S(l)){_({bind:l});return"break"}var r={};var n=function e(n,t){r[n]=t};var t=x(i,l,false,n);if(typeof t!=="undefined"){p=new Ae(t,p)}l=r};while(true){var v=h();if(v==="break")break}if(p!==Fe){p=p.reverse()}if(i.cdr instanceof Ae&&i.cdr.cdr instanceof Ae){p.append(k(i.cdr.cdr,{disabled:n}))}return p}}var d=k(i.car,{disabled:n});var m=k(i.cdr,{disabled:n});_({a:true,head:d&&d.toString(),rest:m&&m.toString()});return new Ae(d,m)}if(i instanceof Oe){if(n&&Oe.is(i,b)){return i}var y=w(i);if(typeof y!=="undefined"){return y}}return i}return k(n,{})}function We(e){return typeof e==="undefined"||e===Fe||e===null}function Qe(e){return e instanceof Promise||e&&typeof e!=="undefined"&&typeof e.then==="function"}function Ke(e){switch(Ut(e)){case"string":return Fn(e);case"number":if(!Number.isNaN(e)){return Rn(e)}}return e}function Xe(e){if(e&&e.valueOf){return e.valueOf()}return e}function Ze(e,n){if(e instanceof Ae){e.markCycles();return ot(e)}if(typeof e==="function"){if(n){return nn(e,n)}}return Ke(e)}function en(e){if(tn(e)){return e[un]}return e}function nn(n,e){if(n[Symbol["for"]("__bound__")]){return n}var t=n.bind(e);var r=Object.getOwnPropertyNames(n).filter(sn);r.forEach(function(e){try{t[e]=n[e]}catch(e){}});fn(t,"__fn__",n);fn(t,"__context__",e);fn(t,"__bound__",true);if(pn(n)){fn(t,"__native__",true)}t.valueOf=function(){return n};return t}function tn(e){return!!(typeof e==="function"&&e[un])}function rn(e){if(typeof e==="function"){var n=e[on];if(n&&(n===Lt||n.constructor&&n.constructor.__className)){return true}}return false}function an(e){function n(e){return e instanceof Qn||e instanceof Kn}if(typeof e==="function"){if(n(e)){return true}if(n(e[on])){return true}}return false}var on=Symbol["for"]("__context__");var un=Symbol["for"]("__fn__");var cn=["name","length","caller","callee","arguments","prototype"];function sn(e){return!cn.includes(e)}function fn(e,n,t){Object.defineProperty(e,Symbol["for"](n),{get:function e(){return t},set:function e(){},configurable:false,enumerable:false})}function ln(n,t){try{Object.defineProperty(n,"length",{get:function e(){return t}});return n}catch(e){var r=new Array(t).fill(0).map(function(e,n){return"a"+n}).join(",");var i=new Function("f","return function(".concat(r,") {\n return f.apply(this, arguments);\n };"));return i(n)}}function pn(e){var n=Symbol["for"]("__native__");return typeof e==="function"&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[n]===true||!e.name.match(/^bound /)&&!e[n])}function hn(e){var d;switch(e){case Symbol["for"]("letrec"):d="letrec";break;case Symbol["for"]("let"):d="let";break;case Symbol["for"]("let*"):d="let*";break;default:throw new Error("Invalid let_macro value")}return De.defmacro(d,function(n,e){var o=e.dynamic_scope,u=e.error,t=e.macro_expand;var c;if(n.car instanceof Oe){if(!(n.cdr.car instanceof Ae||n.cdr.car===Fe)){throw new Error("let require list of pairs")}var r;if(n.cdr.car===Fe){c=Fe;r=Fe}else{r=n.cdr.car.map(function(e){return e.car});c=n.cdr.car.map(function(e){return e.cdr.car})}return Ae.fromArray([Oe("letrec"),[[n.car,Ae(Oe("lambda"),Ae(r,n.cdr.cdr))]],Ae(n.car,c)])}else if(t){return}var s=this;c=this.get("list->array")(n.car);var f=s.inherit(d);var l,p;if(d==="let*"){p=f}else if(d==="let"){l=[]}var h=0;function v(){var e=new Ae(new Oe("begin"),n.cdr);return St(e,{env:f,dynamic_scope:o,error:u})}return function n(){var t=c[h++];function r(e,n){if(typeof n==="undefined"){f.set(e,Fe)}else{f.set(e,n)}}if(o){o=d==="let*"?f:s}if(!t){if(l&&l.length){var e=l.map(function(e){return e.value});var i=e.filter(Qe);if(i.length){return Promise.all(e).then(function(e){for(var n=0,t=e.length;n1&&arguments[1]!==E?arguments[1]:{},t=n.dynamic_scope,r=n.error;var i=this;if(t){t=this}var a=e;var o=[];while(a instanceof Ae){o.push(St(a.car,{env:i,dynamic_scope:t,error:r}));a=a.cdr}var u=o.filter(Qe).length;if(u){return Promise.all(o).then(c.bind(this))}else{return c.call(this,o)}})}function dn(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r2?r-2:0),a=2;a1&&arguments[1]!==E?arguments[1]:null;return function(){for(var e=arguments.length,n=new Array(e),t=0;t1?e-1:0),t=1;t=o){return a.apply(this,r)}else{return i}}return i.apply(this,arguments)}}function On(r,i){mt("limit",i,"function",2);return function(){for(var e=arguments.length,n=new Array(e),t=0;t1?r-1:0),a=1;a0){t.push(this._string.substring(0,e))}t.push(n);if(e1&&arguments[1]!==E?arguments[1]:false;if(e instanceof Rn){return e}if(typeof this!=="undefined"&&!(this instanceof Rn)||typeof this==="undefined"){return new Rn(e,n)}if(typeof e==="undefined"){throw new Error("Invlaid LNumber constructor call")}var t=Rn.getType(e);if(Rn.types[t]){return Rn.types[t](e,n)}var r=e instanceof Array&&Fn.isString(e[0])&&Rn.isNumber(e[1]);if(e instanceof Rn){return Rn(e.value)}if(!Rn.isNumber(e)&&!r){throw new Error("You can't create LNumber from ".concat(gt(e)))}if(e===null){e=0}var i;if(r){var a=e,o=Dt(a,2),u=o[0],c=o[1];if(u instanceof Fn){u=u.valueOf()}if(c instanceof Rn){c=c.valueOf()}var s=u.match(/^([+-])/);var f=false;if(s){u=u.replace(/^[+-]/,"");if(s[1]==="-"){f=true}}}if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(r){var l;switch(c){case 8:l="0o";break;case 16:l="0x";break;case 2:l="0b";break;case 10:l="";break}if(typeof l==="undefined"){var p=BigInt(c);i=Tt(u).map(function(e,n){return BigInt(parseInt(e,c))*Math.pow(p,BigInt(n))}).reduce(function(e,n){return e+n})}else{i=BigInt(l+u)}}else{i=BigInt(e)}if(f){i*=BigInt(-1)}}else{i=e}return Hn(i,true)}else if(typeof h!=="undefined"&&!(e instanceof h)){if(e instanceof Array){return Hn(Pt(h,Tt(e)))}return Hn(new h(e))}else if(r){this.value=parseInt(u,c)}else{this.value=e}}Rn.types={float:function e(n){var t=arguments.length>1&&arguments[1]!==E?arguments[1]:false;return new Mn(n,t)},complex:function e(n){var t=arguments.length>1&&arguments[1]!==E?arguments[1]:false;if(!Rn.isComplex(n)){n={im:0,re:n}}return new Cn(n,t)},rational:function e(n){var t=arguments.length>1&&arguments[1]!==E?arguments[1]:false;if(!Rn.isRational(n)){n={num:n,denom:1}}return new Un(n,t)}};function Cn(e){var n=arguments.length>1&&arguments[1]!==E?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof Cn)||typeof this==="undefined"){return new Cn(e,n)}if(e instanceof Cn){return Cn({im:e.im,re:e.re})}if(Rn.isNumber(e)&&n){e={im:0,re:e.valueOf()}}else if(!Rn.isComplex(e)){throw new Error("Invalid constructor call for LComplex")}var t=e.im instanceof Rn?e.im:Rn(e.im);var r=e.re instanceof Rn?e.re:Rn(e.re);if(t.cmp(0)===0&&!n){return r}this.im=t;this.re=r;this.type="complex"}Cn.prototype=Object.create(Rn.prototype);Cn.prototype.constructor=Cn;Cn.prototype.toRational=function(e){if(Rn.isFloat(this.im)&&Rn.isFloat(this.re)){var n=Mn(this.im).toRational(e);var t=Mn(this.re).toRational(e);return Cn({im:n,re:t})}return this};Cn.prototype.add=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.add(n),im:t.add(r)}})};Cn.prototype.factor=function(){if(this.im instanceof Mn||this.im instanceof Mn){var e=this.re,n=this.im;var t,r;if(e instanceof Mn){t=e.toRational().mul(e.toRational())}else{t=e.mul(e)}if(n instanceof Mn){r=n.toRational().mul(n.toRational())}else{r=n.mul(n)}return t.add(r)}else{return this.re.mul(this.re).add(this.im.mul(this.im))}};Cn.prototype.modulus=function(){return this.factor().sqrt()};Cn.prototype.sqrt=function(){var e=this.modulus();var n,t;if(e.cmp(0)===0){n=t=e}else if(this.re.cmp(0)===1){n=Mn(.5).mul(e.add(this.re)).sqrt();t=this.im.div(n).div(2)}else{t=Mn(.5).mul(e.sub(this.re)).sqrt();if(this.im.cmp(0)===-1){t=t.sub()}n=this.im.div(t).div(2)}return Cn({im:t,re:n})};Cn.prototype.div=function(e){if(Rn.isNumber(e)&&!Rn.isComplex(e)){e=Cn({im:0,re:e})}else if(!Rn.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var n=this.coerce(e),t=Dt(n,2),r=t[0],i=t[1];var a=Cn({re:i.re,im:i.im.sub()});var o=i.factor().valueOf();var u=r.mul(a);var c=u.re.op("/",o);var s=u.im.op("/",o);return Cn({re:c,im:s})};Cn.prototype.sub=function(e){return this.complex_op(e,function(e,n,t,r){return{re:e.sub(n),im:t.sum(r)}})};Cn.prototype.mul=function(e){return this.complex_op(e,function(e,n,t,r){var i={re:e.mul(n).sub(t.mul(r)),im:e.mul(r).add(n.mul(t))};return i})};Cn.prototype.complex_op=function(e,n){if(Rn.isNumber(e)&&!Rn.isComplex(e)){if(!(e instanceof Rn)){e=Rn(e)}var t=e.asType(0);e={im:t,re:e}}else if(!Rn.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var r=e.re instanceof Rn?e.re:this.re.asType(e.re);var i=e.im instanceof Rn?e.im:this.im.asType(e.im);var a=n(this.re,r,this.im,i);if("im"in a&&"re"in a){var o=Cn(a,true);return o}return a};Cn._op={"+":"add","-":"sub","*":"mul","/":"div"};Cn.prototype._op=function(e,n){var t=Cn._op[e];return this[t](n)};Cn.prototype.cmp=function(e){var n=this.coerce(e),t=Dt(n,2),r=t[0],i=t[1];var a=r.re.coerce(i.re),o=Dt(a,2),u=o[0],c=o[1];var s=u.cmp(c);if(s!==0){return s}else{var f=r.im.coerce(i.im),l=Dt(f,2),p=l[0],h=l[1];return p.cmp(h)}};Cn.prototype.valueOf=function(){};Cn.prototype.toString=function(){var e;if(this.re.cmp(0)!==0){e=[this.re.toString()]}else{e=[]}e.push(this.im.cmp(0)<0?"-":"+");e.push(this.im.toString().replace(/^-/,""));e.push("i");return e.join("")};function Mn(e){if(typeof this!=="undefined"&&!(this instanceof Mn)||typeof this==="undefined"){return new Mn(e)}if(!Rn.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof Rn){return Mn(e.valueOf())}if(typeof e==="number"){this.value=e;this.type="float"}}Mn.prototype=Object.create(Rn.prototype);Mn.prototype.constructor=Mn;Mn.prototype.toString=function(){var e=this.value.toString();if(!Rn.isFloat(this.value)&&!e.match(/e/i)){return e+".0"}return e.replace(/^([0-9]+)e/,"$1.0e")};Mn.prototype._op=function(e,n){if(n instanceof Rn){n=n.value}var t=Rn._ops[e];return Mn(t(this.value,n))};Mn.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==E?arguments[0]:null;if(e===null){return Tn(this.value.valueOf())}return Bn(e.valueOf())(this.value.valueOf())};var Tn=Bn(1e-10);function Bn(r){return function(e){var n=function e(r,n,t){var i=function e(n,t){return t0){i=Dn(r,t)}else if(r.cmp(t)<=0){i=t}else if(t.cmp(0)>0){i=Dn(t,r)}else if(n.cmp(0)<0){i=Rn(Dn(r.sub(),t.sub())).sub()}else{i=Rn(0)}if(Rn.isFloat(n)||Rn.isFloat(e)){return Mn(i)}return i}function Dn(e,n){var t=Rn(e).floor();var r=Rn(n).floor();if(e.cmp(t)<1){return t}else if(t.cmp(r)===0){var i=Rn(1).div(n.sub(r));var a=Rn(1).div(e.sub(t));return t.add(Rn(1).div(Dn(i,a)))}else{return t.add(Rn(1))}}function Un(e){var n=arguments.length>1&&arguments[1]!==E?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof Un)||typeof this==="undefined"){return new Un(e,n)}if(!Rn.isRational(e)){throw new Error("Invalid constructor call for LRational")}var t=Rn(e.num);var r=Rn(e.denom);if(!n&&r.cmp(0)!==0){var i=t.op("%",r).cmp(0)===0;if(i){return Rn(t.div(r))}}this.num=t;this.denom=r;this.type="rational"}Un.prototype=Object.create(Rn.prototype);Un.prototype.constructor=Un;Un.prototype.pow=function(e){var n=e.cmp(0);if(n===0){return Rn(1)}if(n===-1){e=e.sub();var t=this.denom.pow(e);var r=this.num.pow(e);return Un({num:t,denom:r})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};Un.prototype.sqrt=function(){var e=this.num.sqrt();var n=this.denom.sqrt();if(e instanceof Mn){e=(qt("num"),e.toRational())}if(n instanceof Mn){n=(qt("denom"),n.toRational())}return Un({num:e,denom:n})};Un.prototype.abs=function(){var e=this.num;var n=this.denom;if(e.cmp(0)===-1){e=e.sub()}if(n.cmp(0)!==1){n=n.sub()}return Un({num:e,denom:n})};Un.prototype.cmp=function(e){return Rn(this.valueOf(),true).cmp(e)};Un.prototype.toString=function(){var e=this.num.gcd(this.denom);var n,t;if(e.cmp(1)!==0){n=this.num.div(e);if(n instanceof Un){n=Rn(n.valueOf(true))}t=this.denom.div(e);if(t instanceof Un){t=Rn(t.valueOf(true))}}else{n=this.num;t=this.denom}var r=this.cmp(0)<0;if(r){if(n.abs().cmp(t.abs())===0){return n.toString()}}else if(n.cmp(t)===0){return n.toString()}return n.toString()+"/"+t.toString()};Un.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 Rn._ops["/"](this.num.value,this.denom.value)}return Mn(this.num.valueOf()).div(this.denom.valueOf())};Un.prototype.mul=function(e){if(!(e instanceof Rn)){e=Rn(e)}if(Rn.isRational(e)){var n=this.num.mul(e.num);var t=this.denom.mul(e.denom);return Un({num:n,denom:t})}var r=Rn.coerce(this,e),i=Dt(r,2),a=i[0],o=i[1];return a.mul(o)};Un.prototype.div=function(e){if(!(e instanceof Rn)){e=Rn(e)}if(Rn.isRational(e)){var n=this.num.mul(e.denom);var t=this.denom.mul(e.num);return Un({num:n,denom:t})}var r=Rn.coerce(this,e),i=Dt(r,2),a=i[0],o=i[1];var u=a.div(o);return u};Un.prototype._op=function(e,n){return this[Vn[e]](n)};Un.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof Rn)){e=Rn(e)}if(Rn.isRational(e)){var n=e.num.sub();var t=e.denom;return this.add(Un({num:n,denom:t}))}if(!(e instanceof Rn)){e=Rn(e).sub()}else{e=e.sub()}var r=Rn.coerce(this,e),i=Dt(r,2),a=i[0],o=i[1];return a.add(o)};Un.prototype.add=function(e){if(!(e instanceof Rn)){e=Rn(e)}if(Rn.isRational(e)){var n=this.denom;var t=e.denom;var r=this.num;var i=e.num;var a,o;if(n!==t){o=t.mul(r).add(i.mul(n));a=n.mul(t)}else{o=r.add(i);a=n}return Un({num:o,denom:a})}if(Rn.isFloat(e)){return Mn(this.valueOf()).add(e)}var u=Rn.coerce(this,e),c=Dt(u,2),s=c[0],f=c[1];return s.add(f)};function Hn(e,n){if(typeof this!=="undefined"&&!(this instanceof Hn)||typeof this==="undefined"){return new Hn(e,n)}if(e instanceof Hn){return Hn(e.value,e._native)}if(!Rn.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.value=e;this._native=n;this.type="bigint"}Hn.prototype=Object.create(Rn.prototype);Hn.prototype.constructor=Hn;Hn.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};Hn.prototype._op=function(e,n){if(typeof n==="undefined"){if(Rn.isBN(this.value)){e=Hn.bn_op[e];return Hn(this.value.clone()[e](),false)}return Hn(Rn._ops[e](this.value),true)}if(Rn.isBN(this.value)&&Rn.isBN(n.value)){e=Hn.bn_op[e];return Hn(this.value.clone()[e](n),false)}var t=Rn._ops[e](this.value,n.value);if(e==="/"){var r=this.op("%",n).cmp(0)===0;if(r){return Rn(t)}return Un({num:this,denom:n})}return Hn(t,true)};Hn.prototype.sqrt=function(){var e;var n=this.cmp(0)<0;if(Rn.isNative(this.value)){e=Rn(Math.sqrt(n?-this.valueOf():this.valueOf()))}else if(Rn.isBN(this.value)){e=n?this.value.neg().sqrt():this.value.sqrt()}if(n){return Cn({re:0,im:e})}return e};Rn.prototype.gcd=function(e){var n=this.abs();e=e.abs();if(e.cmp(n)===1){var t=n;n=e;e=t}while(true){n=n.rem(e);if(n.cmp(0)===0){return e}e=e.rem(n);if(e.cmp(0)===0){return n}}};Rn.isFloat=function e(n){return n instanceof Mn||Number(n)===n&&n%1!==0};Rn.isNumber=function(e){return e instanceof Rn||!Number.isNaN(e)&&Rn.isNative(e)||Rn.isBN(e)};Rn.isComplex=function(e){var n=e instanceof Cn||Rn.isNumber(e.im)&&Rn.isNumber(e.re);return n};Rn.isRational=function(e){return e instanceof Un||Rn.isNumber(e.num)&&Rn.isNumber(e.denom)};Rn.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};Rn.isBigInteger=function(e){return e instanceof Hn||typeof e==="bigint"||Rn.isBN(e)};Rn.isBN=function(e){return typeof h!=="undefined"&&e instanceof h};Rn.getArgsType=function(e,n){if(e instanceof Mn||n instanceof Mn){return Mn}if(e instanceof Hn||n instanceof Hn){return Hn}return Rn};Rn.prototype.toString=Rn.prototype.toJSON=function(e){if(e>2&&e<36){return this.value.toString(e)}return this.value.toString()};Rn.prototype.asType=function(e){var n=Rn.getType(this);return Rn.types[n]?Rn.types[n](e):Rn(e)};Rn.prototype.isBigNumber=function(){return typeof this.value==="bigint"||typeof h!=="undefined"&&!(this.value instanceof h)};["floor","ceil","round"].forEach(function(e){Rn.prototype[e]=function(){if(this["float"]||Rn.isFloat(this.value)){return Rn(Math[e](this.value))}else{return Rn(Math[e](this.valueOf()))}}});Rn.prototype.valueOf=function(){if(Rn.isNative(this.value)){return Number(this.value)}else if(Rn.isBN(this.value)){return this.value.toNumber()}};var Jn=function(){var e=function e(n,t){return[n,t]};return{bigint:{bigint:e,float:function e(n,t){return[Mn(n.valueOf()),t]},rational:function e(n,t){return[{num:n,denom:1},t]},complex:function e(n,t){return[{im:0,re:n},t]}},float:{bigint:function e(n,t){return[n,t&&Mn(t.valueOf())]},float:e,rational:function e(n,t){return[n,t&&Mn(t.valueOf())]},complex:function e(n,t){return[{re:n,im:Mn(0)},t]}},complex:{bigint:n("bigint"),float:n("float"),rational:n("rational"),complex:function e(n,t){var r=Rn.coerce(n.re,t.re),i=Dt(r,2),a=i[0],o=i[1];var u=Rn.coerce(n.im,t.im),c=Dt(u,2),s=c[0],f=c[1];return[{im:s,re:a},{im:f,re:o}]}},rational:{bigint:function e(n,t){return[n,t&&{num:t,denom:1}]},float:function e(n,t){return[Mn(n.valueOf()),t]},rational:e,complex:function e(n,t){return[{im:Yn(n.type,t.im.type,0),re:Yn(n.type,t.re.type,n)},{im:Yn(n.type,t.im.type,t.im),re:Yn(n.type,t.re.type,t.re)}]}}};function n(t){return function(e,n){return[{im:Yn(t,e.im.type,e.im),re:Yn(t,e.re.type,e.re)},{im:Yn(t,e.im.type,0),re:Yn(t,n.type,n)}]}}}();function Yn(e,n,t){return Jn[e][n](t)[0]}Rn.coerce=function(e,n){function t(e){if(e==="integer"){return"bigint"}return e}var r=t(Rn.getType(e));var i=t(Rn.getType(n));if(!Jn[r]){throw new Error("LNumber::coerce unknown lhs type ".concat(r))}else if(!Jn[r][i]){throw new Error("LNumber::coerce unknown rhs type ".concat(i))}return Jn[r][i](e,n).map(function(e){return Rn(e,true)})};Rn.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof Rn)){throw new Error("LNumber: you can't coerce ".concat(gt(e)))}if(typeof e==="number"){e=Rn(e)}return Rn.coerce(this,e)};Rn.getType=function(e){if(e instanceof Rn){return e.type}if(Rn.isFloat(e)){return"float"}if(Rn.isComplex(e)){return"complex"}if(Rn.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof h!=="undefined"&&!(e instanceof h)){return"bigint"}};Rn.prototype.isFloat=function(){return!!(Rn.isFloat(this.value)||this["float"])};var Gn={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var Vn={};Object.keys(Gn).forEach(function(n){Vn[Gn[n]]=n;Rn.prototype[n]=function(e){return this.op(Gn[n],e)}});Rn._ops={"*":function e(n,t){return n*t},"+":function e(n,t){return n+t},"-":function e(n,t){if(typeof t==="undefined"){return-n}return n-t},"/":function e(n,t){return n/t},"%":function e(n,t){return n%t},"|":function e(n,t){return n|t},"&":function e(n,t){return n&t},"~":function e(n){return~n},">>":function e(n,t){return n>>t},"<<":function e(n,t){return n<=this._string.length){return et}return jn(this._string[this._in_char])};function Kn(e){if(typeof this!=="undefined"&&!(this instanceof Kn)||typeof this==="undefined"){return new Kn(e)}mt("OutputPort",e,"function");this.write=e}Kn.prototype.toString=function(){return"<#output-port>"};function Xn(n){var t=this;if(typeof this!=="undefined"&&!(this instanceof Xn)||typeof this==="undefined"){return new Xn(n)}mt("OutputStringPort",n,"function");this._buffer=[];this.write=function(e){if(!Fn.isString(e)){e=n(e)}else{e=e.valueOf()}t._buffer.push(e)}}Xn.prototype=Object.create(Kn.prototype);Xn.prototype.getString=function(){return this._buffer.map(function(e){return e.valueOf()}).join("")};Xn.prototype.constructor=Xn;function Zn(e){var n=this;if(typeof this!=="undefined"&&!(this instanceof Zn)||typeof this==="undefined"){return new Zn(e)}mt("InputStringPort",e,"string");this._string=e.valueOf();this._index=0;this._in_char=0;this.read=function(){return n.get_next_tokens()}}Zn.prototype=Object.create(Qn.prototype);Zn.prototype.constructor=Zn;Zn.prototype.read_line=function(){var e=this._string.substring(this._in_char);if(!e){return et}var n=e.match(/([^\n])(?:\n|$)/)[0];this._in_char+=n.length;return n};var et=new nt;function nt(){}nt.prototype.toString=function(){return"<#eof>"};function tt(e){var n=arguments.length>1&&arguments[1]!==E?arguments[1]:{};if(typeof this!=="undefined"&&!(this instanceof tt)||typeof this==="undefined"){return new tt(e,n)}if(typeof e==="undefined"){e="anonymous"}this.env=ct.inherit(e,n)}tt.prototype.exec=function(e){var n=arguments.length>1&&arguments[1]!==E?arguments[1]:false;mt("Intepreter::exec",e,"string",1);mt("Intepreter::exec",n,"boolean",2);ut.set("**interaction-environment**",this.env);return Ot(e,this.env,n?this.env:false)};tt.prototype.get=function(e){return this.env.get(e).bind(this.env)};tt.prototype.set=function(e,n){return this.env.set(e,n)};function rt(e,n,t){if(arguments.length===1){if(Ut(arguments[0])==="object"){e=arguments[0];this.parent=null}else if(typeof arguments[0]==="string"){e={};n={};t=arguments[0]}}this.docs=new Map;this.env=e;this.parent=n;this.name=t||"anonymous"}rt.prototype.inherit=function(e){var n=arguments.length>1&&arguments[1]!==E?arguments[1]:{};if(Ut(e)==="object"){n=e}if(!e||Ut(e)==="object"){e="child of "+(this.name||"unknown")}return new rt(n||{},this,e)};rt.prototype.doc=function(e){var n=arguments.length>1&&arguments[1]!==E?arguments[1]:null;if(e instanceof Oe){e=e.name}if(e instanceof Fn){e=e.valueOf()}if(n){this.docs.set(e,n);return this}if(this.docs.has(e)){return this.docs.get(e)}if(this.parent){return this.parent.doc(e)}};rt.prototype.newFrame=function(e,n){var r=this.inherit("__frame__");r.set("parent.frame",re(function(){var e=arguments.length>0&&arguments[0]!==E?arguments[0]:1;var n=r.parent;if(!(n instanceof rt)){return Fe}if(e<=0){return n}var t=n.get("parent.frame");return t(e-1)},ut.env["parent.frame"].__doc__));n.callee=e;r.set("arguments",n);return r};rt.prototype._lookup=function(e){if(e instanceof Oe){e=e.name}if(e instanceof Fn){e=e.valueOf()}if(this.env.hasOwnProperty(e)){return it(this.env[e])}if(this.parent){return this.parent._lookup(e)}};rt.prototype.toString=function(){return"<#env:"+this.name+">"};rt.prototype.clone=function(){var n=this;var t={};Object.keys(this.env).forEach(function(e){t[e]=n.env[e]});return new rt(t,this.parent,this.name)};rt.prototype.merge=function(e){var n=arguments.length>1&&arguments[1]!==E?arguments[1]:"merge";mt("Environment::merge",e,"environment");return this.inherit(n,e.env)};function it(e){if(typeof this!=="undefined"&&!(this instanceof it)||typeof this==="undefined"){return new it(e)}this.value=e}it.isUndefined=function(e){return e instanceof it&&typeof e.value==="undefined"};it.prototype.valueOf=function(){return this.value};function at(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof at)||typeof this==="undefined"){return new at(e)}this.values=e}at.prototype.toString=function(){return this.values.map(function(e){return Pe(e)}).join("\n")};at.prototype.valueOf=function(){return this.values};rt.prototype.get=function(e){var n=arguments.length>1&&arguments[1]!==E?arguments[1]:{};var t=n.throwError,r=t===void 0?true:t;var i=e;if(i instanceof Oe||i instanceof Fn){i=i.valueOf()}var a=this._lookup(i);if(a instanceof it){if(it.isUndefined(a)){return E}return Ze(a.valueOf())}if(typeof i==="string"){var o=i.split(".").filter(Boolean);if(o.length>0){var u=Mt(o),c=u[0],s=u.slice(1);a=this._lookup(c);if(s.length){try{if(a instanceof it){a=a.valueOf()}else{a=En(f,c);if(typeof a==="function"){a=en(a)}}return En.apply(void 0,[a].concat(Tt(s)))}catch(e){}}else if(a instanceof it){return Ze(a.valueOf())}}a=En(f,i)}if(typeof a!=="undefined"){return a}if(r){throw new Error("Unbound variable `"+i.toString()+"'")}};rt.prototype.set=function(e,n){var t=arguments.length>2&&arguments[2]!==E?arguments[2]:null;if(Rn.isNumber(n)){n=Rn(n)}if(e instanceof Oe){e=e.name}else if(e instanceof Fn){e=e.valueOf()}this.env[e]=n;if(t){this.doc(e,t)}return this};rt.prototype.has=function(e){return this.env.hasOwnProperty(e)};rt.prototype.ref=function(e){var n=this;while(true){if(!n){break}if(n.has(e)){return n}n=n.parent}};rt.prototype.parents=function(){var e=this;var n=[];while(e){n.unshift(e);e=e.parent}return n};function ot(e){if(Qe(e)){return e.then(ot)}if(e instanceof Ae||e instanceof Oe){e.data=true}return e}var ut=new rt({nil:Fe,undefined:E,true:true,false:false,null:null,NaN:NaN,stdout:new Kn(function(){var e;(e=console).log.apply(e,arguments)}),stdin:Qn(function(){return new Promise(function(e){e(prompt(""))})}),"open-input-string":re(function(e){mt("open-input-string",e,"string");return Zn(e)},"(open-input-string string)\n\n Function create new string port as input that can be used to\n read S-exressions from this port using `read` function."),"output-port?":re(function(e){return e instanceof Kn},"(output-port? arg)\n\n Function return true if argument is output port."),"input-port?":re(function(e){return e instanceof Qn},"(input-port? arg)\n\n Function return true if argument is input port."),"open-output-string":re(function(){return Xn(this.get("repr"))},"(open-output-string)\n\n Function create new output port that can used to write string into\n and after finish get the whole string using `get-output-string`"),"get-output-string":re(function(e){mt("get-output-string",e,"output-string-port");return e.getString()},"(get-output-string port)\n\n Function get full string from string port. If nothing was wrote\n to given port it will return empty string."),"eof-object?":re(function(e){return e===et},"(eof-object? arg)\n\n Function check if value is eof object, returned from input string\n port when there are no more data to read."),"peek-char":re(function(e){mt("peek-char",e,["input-port","input-string-port"]);return e.peek_char()},"(peek-char port)\n\n Function get character from string port or EOF object if no more\n data in string port."),"read-line":re(function(e){if(typeof e==="undefined"){e=this.get("stdin")}mt("read-line",e,["input-port","input-string-port"]);return e.read_line()},"(read-char port)\n\n Function read next character from input port."),"read-char":re(function(e){if(typeof e==="undefined"){e=this.get("stdin")}mt("read-char",e,["input-port","input-string-port"]);return e.read_char()},"(read-char port)\n\n Function read next character from input port."),read:re(function e(n){if(Fn.isString(n)){return ee(W(n.valueOf()))[0]}var t;if(n instanceof Qn){t=n}else{t=this.get("stdin")}return ne(t.read(),function(e){if(e===et){return et}return ee(e)[0]})},"(read [string])\n\n Function if used with string will parse the string and return\n list structure of LIPS code. If called without an argument it\n will read string from standard input (using browser prompt or\n user defined way) and call itself with that string (parse is)\n function can be used together with eval to evaluate code from\n string"),pprint:re(function(e){if(e instanceof Ae){e=new Lt.Formatter(e.toString(true))["break"]().format();this.get("stdout").write.call(this,e)}else{this.get("display").call(this,e)}this.get("newline").call(this)},"(pprint expression)\n\n Pretty print list expression, if called with non-pair it just call\n print function with passed argument."),print:re(function(){var n=this;var t=this.get("display");var r=this.get("newline");for(var e=arguments.length,i=new Array(e),a=0;a1?t-1:0),i=1;ir.length){throw new Error("Not enough arguments")}var u=0;var c=this.get("repr");n=n.replace(a,function(e){var n=e[1];if(n==="~"){return"~"}else if(n==="%"){return"\n"}else{var t=r[u++];if(n==="a"){return c(t)}else{return c(t,true)}}});o=n.match(/~([\S])/);if(o){throw new Error("format: Unrecognized escape seqence ".concat(o[1]))}return n},"(format string n1 n2 ...)\n\n Function accepts string template and replacing any escape sequences\n by arguments:\n\n * ~a value as if printed with display\n * ~s value as if printed with write\n * ~% newline character\n * ~~ literal tilde '~' is inserted\n\n if there missing arguments or other escape character it throw exception."),display:re(function(e){var n=arguments.length>1&&arguments[1]!==E?arguments[1]:null;if(n===null){n=this.get("stdout")}n.write.call(this,this.get("repr")(e))},"(display arg [port])\n\n Function send string to standard output or provied port."),error:re(function(){for(var e=arguments.length,n=new Array(e),t=0;t1&&arguments[1]!==E?arguments[1]:{},t=n.dynamic_scope,r=n.error;if(t){t=this}var o;var i=St(e.cdr.car,{env:this,dynamic_scope:t,error:r});i=bt(i);function u(n,t){if(Qe(n)){return n.then(function(e){return u(e,t)})}if(Qe(t)){return t.then(function(e){return u(n,e)})}f[n]=t;return t}if(e.car instanceof Ae&&Oe.is(e.car.car,".")){var c=e.car.cdr.car;var s=e.car.cdr.cdr.car;var f=St(c,{env:this,dynamic_scope:t,error:r});var l=St(s,{env:this,dynamic_scope:t,error:r});return u(l,i)}if(!(e.car instanceof Oe)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var p=e.car.valueOf();o=this.ref(e.car.name);return ne(i,function(e){if(!o){var n=p.split(".");if(n.length>1){var t=n.pop();var r=n.join(".");var i=a.get(r,{throwError:false});if(i){a.get("set-obj!").call(a,i,t,e);return}}o=a}o.set(p,e)})}),"(set! name value)\n\n Macro that can be used to set the value of the variable (mutate)\n it search the scope chain until it finds first non emtpy slot and set it."),"unset!":re(new De("set!",function(e){if(!(e.car instanceof Oe)){throw new Error("unset! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var n=e.car;var t=this.ref(n);if(t){delete t.env[n.name]}}),"(unset! name)\n\n Function delete specified name from environment."),"set-car!":re(function(e,n){mt("set-car!",e,"pair");e.car=n},"(set-car! obj value)\n\n Function that set car (head) of the list/pair to specified value.\n It can destroy the list. Old value is lost."),"set-cdr!":re(function(e,n){mt("set-cdr!",e,"pair");e.cdr=n},"(set-cdr! obj value)\n\n Function that set cdr (tail) of the list/pair to specified value.\n It can destroy the list. Old value is lost."),"empty?":re(function(e){return typeof e==="undefined"||e===Fe},"(empty? object)\n\n Function return true if value is undfined empty list."),assoc:re(function(e,n){if(e instanceof Ae&&!(n instanceof Ae)){throw new Error("First argument to assoc ned to be a key")}mt("assoc",n,"pair");var t=n;while(true){if(!(t instanceof Ae)||this.get("empty?")(t)){break}var r=t.car.car;if(Be(r,e)){return t.car}else if(!t.haveCycles("cdr")){t=t.cdr}}return Fe},"(assoc key alist)\n\n Function search Alist (list of pairs) until it find the one that\n have head set equal to key, and return found pair."),gensym:re(Ee,"(gensym)\n\n Function generate unique symbol, to use with macros as meta name."),load:re(function(n){mt("load",n,"string");var e=this;if(e.name==="__frame__"){e=e.parent}var i;if(e===ut){i=e}else{i=this.get("**interaction-environment**")}var a="**module-path**";var o=ut.get(a,{throwError:false});n=n.valueOf();if(!n.match(/.[^.]+$/)){n+=".scm"}if(typeof this.get("global",{throwError:false})!=="undefined"){return new Promise(function(t,r){var e=require("path");if(o){o=o.valueOf();n=e.join(o,n)}ut.set(a,e.dirname(n));require("fs").readFile(n,function(e,n){if(e){console.log(e);r(e);ut.set(a,o)}else{Ot(n.toString(),i).then(function(){t();ut.set(a,o)})["catch"](r)}})})}if(o){o=o.valueOf();n=o+"/"+n.replace(/^\.?\/?/,"")}return f.fetch(n).then(function(e){return e.text()}).then(function(e){ut.set(a,n.replace(/\/[^/]*$/,""));return Ot(e,i)}).then(function(){})["finally"](function(){ut.set(a,o)})},"(load filename)\n\n Function fetch the file and evaluate its content as LIPS code."),while:re(new De("while",function(r,e){var i=e.dynamic_scope,a=e.error;var o=this;var u=new Ae(new Oe("begin"),r.cdr);var c;if(i){i=o}return function n(){var e=St(r.car,{env:o,dynamic_scope:i,error:a});function t(e){if(e&&!We(e)){c=St(u,{env:o,dynamic_scope:i,error:a});if(Qe(c)){return c.then(function(e){c=e;return n()})}else{return n()}}else{return c}}return ne(e,t)}()}),"(while cond . body)\n\n Macro that create a loop, it exectue body untill cond expression is false"),if:re(new De("if",function(t,e){var r=e.dynamic_scope,i=e.error;if(r){r=this}var a=this;var n=function e(n){if(n){return St(t.cdr.car,{env:a,dynamic_scope:r,error:i})}else{return St(t.cdr.cdr.car,{env:a,dynamic_scope:r,error:i})}};var o=St(t.car,{env:a,dynamic_scope:r,error:i});return ne(o,n)}),"(if cond true-expr false-expr)\n\n Macro evaluate condition expression and if the value is true, it\n evaluate and return true expression if not it evaluate and return\n false expression"),"let-env":new De("let-env",function(n){var e=arguments.length>1&&arguments[1]!==E?arguments[1]:{};var t=e.dynamic_scope,r=e.error;mt("let-env",n,"pair");var i=St(n.car,{env:this,dynamic_scope:t,error:r});return ne(i,function(e){if(!(e instanceof rt)){throw new Error("let-env: First argument need to be "+"environment")}return St(Ae(Oe("begin"),n.cdr),{env:e,dynamic_scope:t,error:r})})},"(let-env env . body)\n\n Special macro that evaluate body in context of given environment\n object."),letrec:re(hn(Symbol["for"]("letrec")),"(letrec ((a value-a) (b value-b)) body)\n\n Macro that creates new environment, then evaluate and assign values to\n names and then evaluate the body in context of that environment.\n Values are evaluated sequentialy and next value can access to\n previous values/names."),"let*":re(hn(Symbol["for"]("let*")),"(let* ((a value-a) (b value-b)) body)\n\n Macro similar to `let` but next argument get environment\n from previous let variable, so they you can define one variable,\n and use in next argument."),let:re(hn(Symbol["for"]("let")),"(let ((a value-a) (b value-b)) body)\n\n Macro that creates new environment, then evaluate and assign values to\n names and then evaluate the body in context of that environment.\n Values are evaluated sequentialy but you can't access\n previous values/names when next are evaluated. You can only get them\n from body of let expression."),"begin*":re(vn("begin*",function(e){return e.pop()}),"(begin* . expr)\n\n This macro is parallel version of begin. It evaluate each expression and\n if it's a promise it will evaluate it in parallel and return value\n of last expression."),begin:re(new De("begin",function(e,n){var r=Object.assign({},n);var i=this.get("list->array")(e);if(r.dynamic_scope){r.dynamic_scope=this}r.env=this;var a;return function n(){if(i.length){var e=i.shift();var t=St(e,r);return ne(t,function(e){a=e;return n()})}else{return a}}()}),"(begin . args)\n\n Macro runs list of expression and return valuate of the list one.\n It can be used in place where you can only have single exression,\n like if expression."),ignore:new De("ignore",function(e,n){var t=n.dynamic_scope,r=n.error;var i={env:this,error:r};if(t){i.dynamic_scope=this}St(new Ae(new Oe("begin"),e),i)},"(ignore expression)\n\n Macro that will evaluate expression and swallow any promises that may\n be created. It wil run and ignore any value that may be returned by\n expression. The code should have side effects and/or when it's promise\n it should resolve to undefined."),define:re(De.defmacro("define",function(t,e){var r=this;if(t.car instanceof Ae&&t.car.car instanceof Oe){var n=new Ae(new Oe("define"),new Ae(t.car.car,new Ae(new Ae(new Oe("lambda"),new Ae(t.car.cdr,t.cdr)))));return n}else if(e.macro_expand){return}if(e.dynamic_scope){e.dynamic_scope=this}e.env=r;var i=t.cdr.car;if(i instanceof Ae){i=St(i,e)}else if(i instanceof Oe){i=r.get(i)}mt("define",t.car,"symbol");return ne(i,function(e){if(r.name===Ye.merge_env){r=r.parent}var n;if(t.cdr.cdr instanceof Ae&&Fn.isString(t.cdr.cdr.car)){n=t.cdr.cdr.car.valueOf()}r.set(t.car,e,n)})}),"(define name expression)\n (define (function-name . args) body)\n\n Macro for defining values. It can be used to define variables,\n or function. If first argument is list it will create function\n with name beeing first element of the list. The macro evalute\n code `(define function (lambda args body))`"),"set-obj!":re(function(e,n,t){var r=Ut(e);if(We(e)||r!=="object"&&r!=="function"){var i=dt("set-obj!",gt(e),["object","function"]);throw new Error(i)}e=en(e);n=n.valueOf();if(arguments.length===2){delete e[n]}else if(Re(e)&&typeof t==="function"){e[n]=en(t);e[n].__prototype__=true}else if(typeof t==="function"){e[n]=t}else{e[n]=t?t.valueOf():t}},"(set-obj! obj key value)\n\n Function set property of JavaScript object"),"null-environment":re(function(){return ut.inherit("null")},"(null-environment)\n\n Function return new base environment with std lib."),values:re(function(){for(var e=arguments.length,n=new Array(e),t=0;t1&&arguments[1]!==E?arguments[1]:{},p=e.dynamic_scope,h=e.error;var v=this;var d;if(l.cdr instanceof Ae&&Fn.isString(l.cdr.car)&&l.cdr.cdr!==Fe){d=l.cdr.car.valueOf()}function m(){var e;if(p){if(!(this instanceof rt)){e=v}else{e=this}}else{e=v}e=e.inherit("lambda");var n=l.car;var t=0;var r;if(typeof this!=="undefined"){e.set("this",this)}for(var i=arguments.length,a=new Array(i),o=0;o2&&arguments[2]!==E?arguments[2]:c;if(e instanceof Ae){var r=e.car;var i=e.cdr;if(t(r)){r=n(r)}if(t(i)){i=n(i)}if(Qe(r)||Qe(i)){return Promise.all([r,i]).then(function(e){var n=Dt(e,2),t=n[0],r=n[1];return new Ae(t,r)})}else{return new Ae(r,i)}}return e}function i(e,n){if(e instanceof Ae){if(n!==Fe){e.append(n)}}else{e=new Ae(e,n)}return e}function f(r,e,n){if(et){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(e.cdr instanceof Ae){if(e.cdr.cdr!==Fe){if(e.cdr.car instanceof Ae){var i=Fe;return function n(t){if(t===Fe){return i}return ne(St(t.car,{env:u,dynamic_scope:a,error:o}),function(e){i=new Ae(e,i);return n(t.cdr)})}(e.cdr)}else{return e.cdr}}else{return St(e.cdr.car,{env:u,dynamic_scope:a,error:o})}}else{return e.cdr}}return s(e,function(e){return p(e,n,t)})}return e}function t(e){if(e instanceof Ae){delete e.data;if(!e.haveCycles("car")){t(e.car)}if(!e.haveCycles("cdr")){t(e.cdr)}}}var r=p(e.car,0,1);return ne(r,function(e){t(e);return ot(e)})},"(quasiquote list ,value ,@value)\n\n Similar macro to `quote` but inside it you can use special\n expressions unquote abbreviated to , that will evaluate expresion inside\n and return its value or unquote-splicing abbreviated to ,@ that will\n evaluate expression but return value without parenthesis (it will join)\n the list with its value. Best used with macros but it can be used outside"),clone:re(function(e){mt("clone",e,"pair");return e.clone()},"(clone list)\n\n Function return clone of the list."),append:re(function(e,n){mt("append",e,["nil","pair"]);if(e instanceof Ae){e=e.clone()}return this.get("append!").call(this,e,n)},"(append list item)\n\n Function will create new list with value appended to the end. It return\n New list."),"append!":re(function(e,n){mt("append!",e,["pair","nil"]);if(!this.get("list?")(e)){throw new Error("append!: Invalid argument, value is not a list")}if(We(n)){return e}if(e===Fe){if(n===Fe){return Fe}return n}return e.append(n)},"(append! name expression)\n\n Destructive version of append, it modify the list in place. It return\n original list."),reverse:re(function(e){mt("reverse",e,["array","pair","nil"]);if(e===Fe){return Fe}if(e instanceof Ae){var n=this.get("list->array")(e).reverse();return this.get("array->list")(n)}else if(!(e instanceof Array)){throw new Error(dt("reverse",gt(e),"array or pair"))}else{return e.reverse()}},"(reverse list)\n\n Function will reverse the list or array. If value is not a list\n or array it will throw exception."),nth:re(function(e,n){mt("nth",e,"number");mt("nth",n,["array","pair"]);if(n instanceof Ae){var t=n;var r=0;while(rarray")(n).join(e)},"(join separator list)\n\n Function return string by joining elements of the list"),split:re(function(e,n){mt("split",e,["regex","string"]);mt("split",n,"string");return this.get("array->list")(n.split(e))},"(split separator string)\n\n Function create list by splitting string by separatar that can\n be a string or regular expression."),replace:re(function(e,n,t){mt("replace",e,["regex","string"]);mt("replace",n,["string","function"]);mt("replace",t,"string");return t.replace(e,n)},"(replace pattern replacement string)\n\n Function change pattern to replacement inside string. Pattern can be string\n or regex and replacement can be function or string."),match:re(function(e,n){mt("match",e,["regex","string"]);mt("match",n,"string");var t=n.match(e);return t?this.get("array->list")(t):Fe},"(match pattern string)\n\n function return match object from JavaScript as list."),search:re(function(e,n){mt("search",e,["regex","string"]);mt("search",n,"string");return n.search(e)},"(search pattern string)\n\n Function return first found index of the pattern inside a string"),repr:re(function e(n,t){return Pe(n,t)},"(repr obj)\n\n Function return string LIPS representation of an object as string."),env:re(function(e){e=e||this;var n=Object.keys(e.env);var t;if(n.length){t=Ae.fromArray(n)}else{t=Fe}if(e.parent!==E){return this.get("env").call(this,e.parent).append(t)}return t},"(env obj)\n\n Function return list values (functions and variables) inside environment."),new:re(function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r2&&arguments[2]!==E?arguments[2]:K.LITERAL;mt("set-special!",e,"string",1);mt("set-special!",n,"symbol",2);Lt.specials.append(e.valueOf(),n,t)},'(set-special! symbol name [type])\n\n Add special symbol to the list of transforming operators by the parser.\n e.g.: `(add-special! "#" \'x)` will allow to use `#(1 2 3)` and it will be\n transformed into (x (1 2 3)) so you can write x macro that will process\n the list. 3rd argument is optional and it can be constant value\n lips.specials.SPLICE if this constant is used it will transform\n `#(1 2 3)` into (x 1 2 3) that is required by # that define vectors.'),get:En,".":En,unbind:re(en,"(unbind fn)\n\n Function remove bidning from function so you can get props from it."),type:re(gt,"(type object)\n\n Function return type of an object as string."),debugger:re(function(){debugger},"(debugger)\n\n Function stop JavaScript code in debugger."),in:re(function(e,n){if(e instanceof Oe||e instanceof Fn){e=e.valueOf()}return e in n},"(in key value)\n\n Function use is in operator to check if value is in object."),instanceof:re(function(e,n){return n instanceof en(e)},"(instanceof type obj)\n\n Function check of object is instance of object."),"macro?":re(function(e){return e instanceof De},"(macro? expression)\n\n Function check if value is a macro."),"function?":re(function(e){return typeof e==="function"},"(function? expression)\n\n Function check if value is a function."),"real?":re(function(e){if(gt(e)!=="number"){return false}if(e instanceof Rn){return e.isFloat()}return Rn.isFloat(e)},"(real? number)\n\n Function check if value is real number."),"number?":re(Rn.isNumber,"(number? expression)\n\n Function check if value is a number"),"string?":re(function(e){return Fn.isString(e)},"(string? expression)\n\n Function check if value is a string."),"pair?":re(function(e){return e instanceof Ae},"(pair? expression)\n\n Function check if value is a pair or list structure."),"regex?":re(function(e){return e instanceof RegExp},"(regex? expression)\n\n Function check if value is regular expression."),"null?":re(function(e){return We(e)},"(null? expression)\n\n Function check if value is nulish."),"boolean?":re(function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Function check if value is boolean."),"symbol?":re(function(e){return e instanceof Oe},"(symbol? expression)\n\n Function check if value is LIPS symbol"),"array?":re(function(e){return e instanceof Array},"(array? expression)\n\n Function check if value is an arrray."),"object?":re(function(e){return e!==Fe&&e!==null&&!(e instanceof Rn)&&Ut(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Function check if value is an object."),flatten:re(function(e){mt("flatten",e,"pair");return e.flatten()},"(flatten list)\n\n Return shallow list from tree structure (pairs)."),"array->list":re(function(e){mt("array->list",e,"array");return Ae.fromArray(e)},"(array->list array)\n\n Function convert JavaScript array to LIPS list."),"tree->array":re(Ie("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":re(Ie("list->array"),"(list->array list)\n\n Function convert LIPS list into JavaScript array."),apply:re(function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;rarray").call(this,i));return e.apply(this,t)},"(apply fn list)\n\n Function that call function with list of arguments."),length:re(function(e){if(!e){return Rn(0)}if(e instanceof Ae){return Rn(e.length())}if("length"in e){return Rn(e.length)}},"(length expression)\n\n Function return length of the object, the object can be list\n or any object that have length property."),"string->number":re(function(e){var n=arguments.length>1&&arguments[1]!==E?arguments[1]:10;mt("string->number",e,"string",1);mt("string->number",n,"number",2);e=e.valueOf();n=n.valueOf();if(e.match(S)||e.match(w)){return A(e,n)}else if(e.match(O)||e.match(b)){return L(e,n)}else{var t=n===10&&!e.match(/e/i)||n===16;if(e.match(x)&&t||e.match(_)){return I(e,n)}if(e.match(c)){return R(e)}}return false},"(string->number number [radix])\n\n Function convert string to number."),try:re(new De("try",function(a,e){var o=this;var u=e.dynamic_scope,c=e.error;return new Promise(function(i){var e={env:o,error:function e(n){var t=o.inherit("try");t.set(a.cdr.car.cdr.car.car,n);var r={env:t,error:c};if(u){r.dynamic_scope=o}ne(St(new Ae(new Oe("begin"),a.cdr.car.cdr.cdr),r),function(e){i(e)})}};if(u){e.dynamic_scope=o}var n=St(a.car,e);if(Qe(n)){n.then(i)["catch"](e.error)}else{i(n)}})}),"(try expr (catch (e) code)"),throw:re(function(e){throw new Error(e)},"(throw string)\n\n Throw new expection."),find:re(function n(t,r){mt("find",t,["regex","function"]);mt("find",r,"pair");if(We(r)){return Fe}var e=te("find",t);return ne(e(r.car),function(e){if(e&&e!==Fe){return r.car}return n(t,r.cdr)})},"(find fn list)\n (find regex list)\n\n Higher order Function find first value for which function return true.\n If called with regex it will create matcher function."),"for-each":re(function(e){var n;mt("for-each",e,"function");for(var t=arguments.length,r=new Array(t>1?t-1:0),i=1;i1?n-1:0),a=1;a3?r-3:0),a=3;a3?i-3:0),o=3;oarray")(n);var a=[];var o=te("filter",e);return function n(t){function e(e){if(e&&e!==Fe){a.push(r)}return n(++t)}if(t===i.length){return Ae.fromArray(a)}var r=i[t];return ne(o(r,t),e)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher order function that call `fn` for each element of the list\n and return list for only those elements for which funtion return\n true value. If called with regex it will create matcher function."),range:re(function(e){mt("range",e,"number");if(e instanceof Rn){e=e.valueOf()}return Ae.fromArray(new Array(e).fill(0).map(function(e,n){return Rn(n)}))},"(range n)\n\n Function return list of n numbers from 0 to n - 1"),compose:re(yn,"(compose . fns)\n\n Higher order function and create new function that apply all functions\n From right to left and return it's value. Reverse of compose.\n e.g.:\n ((compose (curry + 2) (curry * 3)) 3)\n 11\n "),pipe:re(mn,"(pipe . fns)\n\n Higher order function and create new function that apply all functions\n From left to right and return it's value. Reverse of compose.\n e.g.:\n ((pipe (curry + 2) (curry * 3)) 3)\n 15"),curry:re(Sn,"(curry fn . args)\n\n Higher order function that create curried version of the function.\n The result function will have parially applied arguments and it\n will keep returning functions until all arguments are added\n\n e.g.:\n (define (add a b c d) (+ a b c d))\n (define add1 (curry add 1))\n (define add12 (add 2))\n (display (add12 3 4))"),gcd:re(function e(){for(var n=arguments.length,t=new Array(n),r=0;rr?n%=r:r%=n}n=Me(i*(t<0||arguments.length<=t?E:arguments[t]))/(n+r)}return Rn(n)},"(lcm n1 n2 ...)\n\n Function return the least common multiple of their arguments."),"odd?":re(wn(function(e){return Rn(e).isOdd()}),"(odd? number)\n\n Function check if number os odd."),"even?":re(wn(function(e){return Rn(e).isEven()}),"(even? number)\n\n Function check if number is even."),"*":re(xn(function(e,n){return Rn(e).mul(n)},Rn(1)),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":re(xn(function(e,n){return Rn(e).add(n)},Rn(0)),"(+ . numbers)\n\n Sum all numbers passed as arguments. If single value is passed it will\n return that value."),"-":re(function(){for(var e=arguments.length,n=new Array(e),t=0;t":re(function(){for(var e=arguments.length,n=new Array(e),t=0;t x1 x2 x3 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically increasing"),"<":re(function(){for(var e=arguments.length,n=new Array(e),t=0;t=":re(function(){for(var e=arguments.length,n=new Array(e),t=0;t= x1 x2 x3 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically nondecreasing"),"eq?":re(Be,"(eq? a b)\n\n Function compare two values if they are identical."),or:re(new De("or",function(e,n){var i=n.dynamic_scope,a=n.error;var o=this.get("list->array")(e);var u=this;if(i){i=u}var c;return function n(){function e(e){c=e;if(c){return c}else{return n()}}var t=o.shift();if(typeof t==="undefined"){if(c){return c}else{return false}}else{var r=St(t,{env:u,dynamic_scope:i,error:a});return ne(r,e)}}()}),"(or . expressions)\n\n Macro execute the values one by one and return the one that is truthy value.\n If there are no expression that evaluate to true it return false."),and:re(new De("and",function(e){var n=arguments.length>1&&arguments[1]!==E?arguments[1]:{},i=n.dynamic_scope,a=n.error;var o=this.get("list->array")(e);var u=this;if(i){i=u}if(!o.length){return true}var c;return function n(){function e(e){c=e;if(!c){return false}else{return n()}}var t=o.shift();if(typeof t==="undefined"){if(c){return c}else{return false}}else{var r=St(t,{env:u,dynamic_scope:i,error:a});return ne(r,e)}}()}),"(and . expressions)\n\n Macro evalute each expression in sequence if any value return false it will\n return false. If each value return true it will return the last value.\n If it's called without arguments it will return true."),"|":re(function(e,n){return Rn(e).or(n)},"(& a b)\n\n Function calculate or bit operation."),"&":re(function(e,n){return Rn(e).and(n)},"(& a b)\n\n Function calculate and bit operation."),"~":re(function(e){return Rn(e).neg()},"(~ number)\n\n Function negate the value."),">>":re(function(e,n){return Rn(e).shr(n)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":re(function(e,n){return Rn(e).shl(n)},"(<< a b)\n\n Function left shit the value a by value b."),not:re(function(e){if(We(e)){return true}return!e},"(not object)\n\n Function return negation of the argument.")},E,"global");var ct=ut.inherit("user-env");ut.set("**interaction-environment**",ct);(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(n){var t=e[n]?e[n]:n;ut.set(t,re(function(e){mt(t,e,"number");if(e instanceof Rn){return e[n]()}},"(".concat(t," number)\n\n Function calculate ").concat(t," of a number.")))})})();function st(e){if(e.length===1){return e[0]}else{var n=[];var t=st(e.slice(1));for(var r=0;r3&&arguments[3]!==E?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(r!==null){i+=" argument ".concat(r)}if(t instanceof Array){var a=t[t.length-1];t=t.slice(0,-1).join(", ")+" or "+a}return"Expecting ".concat(t," got ").concat(n).concat(i)}function mt(e,n,t){var r=arguments.length>3&&arguments[3]!==E?arguments[3]:null;e=e.valueOf();var i=gt(n).toLowerCase();var a=false;if(t instanceof Ae){t=t.toArray()}if(t instanceof Array){t=t.map(function(e){return e.valueOf().toLowerCase()});if(t.includes(i)){a=true}}else{t=t.valueOf().toLowerCase()}if(!a&&i!==t){throw new Error(dt(e,i,t,r))}}function yt(e){var n=Ut(e);return["string","function"].includes(n)||e instanceof Oe||e instanceof Rn||e instanceof RegExp}function gt(e){var n={pair:Ae,symbol:Oe,character:jn,values:at,macro:De,string:Fn,array:Array,"native-symbol":Symbol};if(Number.isNaN(e)){return"NaN "}if(e===Fe){return"nil"}if(e===null){return"null"}if(e instanceof Ye){return"syntax"}for(var t=0,r=Object.entries(n);t1&&arguments[1]!==E?arguments[1]:{},i=e.env,a=e.dynamic_scope,t=e.error,o=t===void 0?function(){}:t;try{if(a===true){i=a=i||ut}else if(i===true){i=a=ut}else{i=i||ut}var r={env:i,dynamic_scope:a,error:o};var u;if(We(n)){return n}if(n instanceof Oe){return i.get(n)}var c=n.car;var s=n.cdr;if(c instanceof Ae){u=bt(St(c,r));if(Qe(u)){return u.then(function(e){return St(new Ae(e,n.cdr),r)})}else if(typeof u!=="function"){throw new Error(gt(u)+" "+i.get("repr")(u)+" is not a function while evaluating "+n.toString())}}if(c instanceof Oe){u=i.get(c);if(u instanceof Ye){return _t(u,n,r)}else if(u instanceof De){return xt(u,s,r)}else if(typeof u!=="function"){if(u){var f="".concat(gt(u)," `").concat(u,"' is not a function");throw new Error(f)}throw new Error("Unknown function `".concat(c.name,"'"))}}else if(typeof c==="function"){u=c}if(typeof u==="function"){var l=wt(s,r);return ne(l,function(e){if(tn(u)&&(!rn(u)||an(u))){e=e.map(Xe)}if(u.__lambda__&&!u.__prototype__||an(u)){u=en(u)}var n=e.slice();var t=(a||i).newFrame(u,n);var r=bt(u.apply(t,e));return ne(r,function(e){if(e instanceof Ae){e.markCycles();return ot(e)}if(typeof e==="number"){return Rn(e)}if(typeof e==="string"){return Fn(e)}return e},o)})}else if(n instanceof Oe){u=i.get(n);if(u==="undefined"){throw new Error("Unbound variable `"+n.name+"'")}return u}else if(n instanceof Ae){u=c&&c.toString();throw new Error("".concat(gt(c)," ").concat(u," is not a function"))}else{return n}}catch(e){o&&o.call(i,e,n)}}function Ot(e,n,t){return kt.apply(this,arguments)}function kt(){kt=Ct(Rt.mark(function e(t,r,i){var a,o,u,c;return Rt.wrap(function e(n){while(1){switch(n.prev=n.next){case 0:if(i===true){r=i=r||ct}else if(r===true){r=i=ct}else{r=r||ct}a=ee(t);o=[];case 3:if(a.length){n.next=8;break}return n.abrupt("return",o);case 8:u=a.shift();n.next=11;return St(u,{env:r,dynamic_scope:i,error:function e(n,t){if(t){if(!(n.code instanceof Array)){n.code=[]}n.code.push(t.toString(true))}throw n}});case 11:c=n.sent;o.push(c);case 13:n.next=3;break;case 15:case"end":return n.stop()}}},e)}));return kt.apply(this,arguments)}function Et(e){var n={"[":"]","(":")"};var t;if(typeof e==="string"){t=W(e)}else{t=e.map(function(e){return e&&e.token?e.token:e})}var r=Object.keys(n);var i=Object.values(n).concat(r);t=t.filter(function(e){return i.includes(e)});var a=new G;var o=Ht(t),u;try{for(o.s();!(u=o.n()).done;){var c=u.value;if(r.includes(c)){a.push(c)}else if(!a.is_empty()){var s=a.top();var f=n[s];if(c===f){a.pop()}else{throw new Error("Syntax error: missing closing ".concat(f))}}else{throw new Error("Syntax error: not matched closing ".concat(c))}}}catch(e){o.e(e)}finally{o.f()}return a.is_empty()}function jt(e){var n="("+e.toString()+")()";var t=window.URL||window.webkitURL;var r;try{r=new Blob([n],{type:"application/javascript"})}catch(e){var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;r=new i;r.append(n);r=r.getBlob()}return new f.Worker(t.createObjectURL(r))}function Ft(e){this.url=e;var o=this.worker=jt(function(){var u;var c;self.addEventListener("message",function(e){var r=e.data;var n=r.id;if(r.type!=="RPC"||n===null){return}function i(e){self.postMessage({id:n,type:"RPC",result:e})}function a(e){self.postMessage({id:n,type:"RPC",error:e})}if(r.method==="eval"){if(!c){a("Worker RPC: LIPS not initilized, call init first");return}c.then(function(){var e=Dt(r.params,2),n=e[0],t=e[1];u.exec(n,t).then(function(e){e=e.map(function(e){return e&&e.valueOf()});i(e)})["catch"](function(e){a(e)})})}else if(r.method==="init"){var t=Dt(r.params,1),o=t[0];if(typeof o!=="string"){a("Worker RPC: url is not a string")}else{importScripts("".concat(o,"/dist/lips.min.js"));u=new Lt.Interpreter("worker");c=u.exec('(let-env lips.env.parent\n (load "'.concat(o,'/lib/bootstrap.scm")\n (load "').concat(o,'/lib/R5RS.scm")\n (load "').concat(o,'/lib/R7RS.scm"))'));c.then(function(){i(true)})}}})});this.rpc=function(){var r=0;return function e(n,t){var a=++r;return new Promise(function(r,i){o.addEventListener("message",function e(n){var t=n.data;if(t&&t.type==="RPC"&&t.id===a){if(t.error){i(t.error)}else{r(t.result)}o.removeEventListener("message",e)}});o.postMessage({type:"RPC",method:n,id:a,params:t})})}}();this.rpc("init",[e])["catch"](function(e){console.error(e)});this.exec=function(e){var n=arguments.length>1&&arguments[1]!==E?arguments[1]:false;return this.rpc("eval",[e,n])}}Ae.unDry=function(e){return new Ae(e.car,e.cdr)};Ae.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};je.prototype.toDry=function(){return{value:null}};je.unDry=function(){return Fe};Oe.prototype.toDry=function(){return{value:{name:this.name}}};Oe.unDry=function(e){return new Oe(e.name)};function At(e){console.error(e.message||e);if(e.code){console.error(e.code.map(function(e,n){return"[".concat(n+1,"]: ").concat(e)}))}}function It(){var o=["text/x-lips","text/x-scheme"];if(!window.document){return Promise.resolve()}else{return new Promise(function(i){var a=Array.from(document.querySelectorAll("script"));return function n(){var e=a.shift();if(!e){i()}else{var t=e.getAttribute("type");if(o.includes(t)){var r=e.getAttribute("src");if(r){return f.fetch(r).then(function(e){return e.text()}).then(Ot).then(n)["catch"](function(e){At(e);n()})}else{return Ot(e.innerHTML).then(n)["catch"](function(e){At(e);n()})}}else if(t&&t.match(/lips|lisp/)){console.warn("Expecting "+o.join(" or ")+" found "+t)}return n()}}()})}}if(typeof window!=="undefined"){e(window,It)}var Nt=function(){var e=Fn("Fri, 21 Aug 2020 07:44:49 +0000").valueOf();var n=e==="{{"+"DATE}}"?new Date:new Date(e);var t=function e(n){return n.toString().padStart(2,"0")};var r=n.getFullYear();var i=[r,t(n.getMonth()+1),t(n.getDate())].join("-");var a="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter DEV (".concat(i,") \nCopyright (c) 2018-").concat(r," Jakub T. Jankiewicz\n\nType (env) to see environment with functions macros and variables.\nYou can also use (help name) to display help for specic function or macro.\n").replace(/^.*\n/,"");return a}();se.__className="ahead";fe.__className="pattern";ce.__className="formatter";De.__className="macro";Ye.__className="syntax";rt.__className="environment";Qn.__className="input-port";Kn.__className="output-port";Xn.__className="output-string-port";Zn.__className="input-string-port";Rn.__className="number";jn.__className="character";Fn.__className="string";var Lt={version:"DEV",banner:Nt,date:"Fri, 21 Aug 2020 07:44:49 +0000",exec:Ot,parse:ee,tokenize:W,evaluate:St,Environment:rt,env:ct,Worker:Ft,Interpreter:tt,balanced_parenthesis:Et,balancedParenthesis:Et,balanced:Et,Macro:De,Syntax:Ye,Pair:Ae,quote:ot,InputPort:Qn,OutputPort:Kn,InputStringPort:Zn,OutputStringPort:Xn,Formatter:ce,specials:K,repr:Ne,nil:Fe,LSymbol:Oe,LNumber:Rn,LFloat:Mn,LComplex:Cn,LRational:Un,LBigInteger:Hn,LCharacter:jn,LString:Fn,rationalize:$n};ut.set("lips",Lt);return Lt})})(); \ No newline at end of file diff --git a/lib/bootstrap.scm b/lib/bootstrap.scm index 797687d51..f3d41a190 100644 --- a/lib/bootstrap.scm +++ b/lib/bootstrap.scm @@ -678,7 +678,6 @@ (make-tags expr)) ;; --------------------------------------------------------------------------------------- - (define (get-script url) "(get-script url) @@ -694,3 +693,10 @@ (reject "get-script: Failed to load"))) (if document.head (document.head.appendChild script))))))) + +;; --------------------------------------------------------------------------------------- +(define (gensym? value) + "(gensym? value) + + Function return #t if value is symbol and it's gensym it return #f otherwise." + (and (symbol? value) (--> value (is_gensym)))) diff --git a/src/lips.js b/src/lips.js index 46b7f484a..422e26b88 100644 --- a/src/lips.js +++ b/src/lips.js @@ -1442,6 +1442,36 @@ LSymbol.prototype.valueOf = function() { return this.name.valueOf(); }; + // ------------------------------------------------------------------------- + LSymbol.prototype.is_gensym = function() { + return is_gensym(this.name); + }; + // ------------------------------------------------------------------------- + function is_gensym(symbol) { + if (typeof symbol === 'symbol') { + return !!symbol.toString().match(/^Symbol\(#:/); + } + return false; + } + // ------------------------------------------------------------------------- + var gensym = (function() { + var count = 0; + return function(name = null) { + if (name instanceof LSymbol) { + name = name.valueOf(); + } + if (is_gensym(name)) { + // don't do double gynsyms in nested syntax-rules + return LSymbol(name); + } + // use ES6 symbol as name for lips symbol (they are unique) + if (name !== null) { + return new LSymbol(Symbol(`#:${name}`)); + } + count++; + return new LSymbol(Symbol(`#:g${count}`)); + }; + })(); // ---------------------------------------------------------------------- // :: Nil constructor with only once instance // ---------------------------------------------------------------------- @@ -2529,7 +2559,8 @@ } return gensyms[name]; } - function transform_ellipsis_expr(expr, bindings, nested, next = () => {}) { + function transform_ellipsis_expr(expr, bindings, state, next = () => {}) { + const { nested } = state; log(' ==> ' + expr.toString()); if (expr instanceof LSymbol) { const name = expr.valueOf(); @@ -2601,8 +2632,9 @@ } } log('[t 3 recur ' + expr.toString()); - const head = transform_ellipsis_expr(expr.car, bindings, nested, next); - const rest = transform_ellipsis_expr(expr.cdr, bindings, nested, next); + var new_state = { nested }; + const head = transform_ellipsis_expr(expr.car, bindings, new_state, next); + const rest = transform_ellipsis_expr(expr.cdr, bindings, new_state, next); log({ b: true, head: head && head.toString(), @@ -2628,11 +2660,16 @@ function get_names(object) { return Object.keys(object).concat(Object.getOwnPropertySymbols(object)); } - function traverse(expr) { + function traverse(expr, { disabled } = {}) { log('>> ' + expr.toString()); if (expr instanceof Pair) { + // escape ellispsis from R7RS e.g. (... ...) + if (!disabled && expr.car instanceof Pair && + LSymbol.is(expr.car.car, ellipsis_symbol)) { + return traverse(expr.car.cdr, { disabled: true }); + } if (expr.cdr instanceof Pair && - LSymbol.is(expr.cdr.car, ellipsis_symbol)) { + LSymbol.is(expr.cdr.car, ellipsis_symbol) && !disabled) { log('>> 1'); const symbols = bindings['...'].symbols; var keys = get_names(symbols); @@ -2668,7 +2705,7 @@ const car = transform_ellipsis_expr( expr.car, bind, - true, + { nested: true }, next ); // undefined can be null caused by null binding @@ -2687,7 +2724,9 @@ return result; } else { log('>> 3'); - const car = transform_ellipsis_expr(expr.car, symbols, true); + const car = transform_ellipsis_expr(expr.car, symbols, { + nested: true + }); if (car) { return new Pair( car, @@ -2732,13 +2771,13 @@ // by ellipsis transformation if (expr.cdr instanceof Pair && expr.cdr.cdr instanceof Pair) { - result.append(traverse(expr.cdr.cdr)); + result.append(traverse(expr.cdr.cdr, { disabled })); } return result; } } - const head = traverse(expr.car); - const rest = traverse(expr.cdr); + const head = traverse(expr.car, { disabled }); + const rest = traverse(expr.cdr, { disabled }); log({ a: true, head: head && head.toString(), @@ -2750,14 +2789,17 @@ ); } if (expr instanceof LSymbol) { - const value = transform(expr); + if (disabled && LSymbol.is(expr, ellipsis_symbol)) { + return expr; + } + const value = transform(expr, { disabled }); if (typeof value !== 'undefined') { return value; } } return expr; } - return traverse(expr); + return traverse(expr, {}); } // ---------------------------------------------------------------------- // :: check for nullish values @@ -4753,21 +4795,6 @@ return '<#unquote[' + this.count + '] ' + this.value + '>'; }; // ------------------------------------------------------------------------- - var gensym = (function() { - var count = 0; - return function(name = null) { - if (name instanceof LSymbol) { - name = name.valueOf(); - } - // use ES6 symbol as name for lips symbol (they are unique) - if (name !== null) { - return new LSymbol(Symbol(`#:${name}`)); - } - count++; - return new LSymbol(Symbol(`#:g${count}`)); - }; - })(); - // ------------------------------------------------------------------------- var global_env = new Environment({ nil: nil, 'undefined': undefined, diff --git a/tests/syntax.scm b/tests/syntax.scm index ad1a8238e..d0b0d0e7f 100644 --- a/tests/syntax.scm +++ b/tests/syntax.scm @@ -533,7 +533,7 @@ '(1 2 3 4 5 6 7 8 9 10)))) -(test_ "syntax-rules: it should define nested syntax-rules" +(test "syntax-rules: it should define nested syntax-rules" (lambda (t) (define-syntax be-like-begin (syntax-rules () @@ -549,7 +549,7 @@ (be-like-begin progn) (t.is (let* ((x 10) (expr `(,x . ,x))) - (prgn + (progn x x expr)) @@ -570,7 +570,7 @@ (define-syntax test (syntax-rules () - ((_) (... '(...))))) + ((_) (... '...)))) (t.is (test) '(...))