From 1f2c0c340b4384abab74c967b8a1269ae601b172 Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Wed, 11 Nov 2020 18:57:04 +0100 Subject: [PATCH] add `define-values` + fix syntax-rules so it work #43 --- CHANGELOG.md | 2 +- README.md | 2 +- dist/lips.js | 120 ++++++++++++++++++++++++++++++++++++++++------- dist/lips.min.js | 4 +- lib/R7RS.scm | 45 +++++++++++++++++- src/lips.js | 48 ++++++++++++++++++- tests/syntax.scm | 17 +++++++ todo.lips | 2 +- 8 files changed, 216 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d107b27e..c4dea5049 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### Breaking * throw exception when calling `(-)` ### Features -* `let-values` and `let*-values` syntax macros +* add `let-values`, `let*-values` and `define-values` syntax macros ### Bugfix * fix empty vector literal * fix edge case in nested syntax-rules when variable in parent got expanded into identifier diff --git a/README.md b/README.md index d40e02a40..53cd5cb12 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ![LIPS - Scheme Based Powerful Lisp Language](https://github.com/jcubic/lips/blob/devel/assets/lips.svg?raw=true) [![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.8-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) -[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&5ec03ebb4622bef2dcb6107c4e56aecccbbaf916)](https://travis-ci.org/jcubic/lips) +[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&41b65348aee0699fac5306ede2fb630edf630ecb)](https://travis-ci.org/jcubic/lips) [![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&2c48907438a7265935a7b21e6931008d)](https://coveralls.io/github/jcubic/lips?branch=devel) [![Join Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips) diff --git a/dist/lips.js b/dist/lips.js index 91ec02e20..9dda77b40 100644 --- a/dist/lips.js +++ b/dist/lips.js @@ -31,7 +31,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Wed, 11 Nov 2020 11:37:22 +0000 + * build: Wed, 11 Nov 2020 17:52:59 +0000 */ (function () { 'use strict'; @@ -1153,6 +1153,40 @@ } } // ------------------------------------------------------------------------- + /* eslint-disable */ + + /* istanbul ignore next */ + + + function log(x) { + var regex = arguments.length > 1 && arguments[1] !== undefined$1 ? arguments[1] : null; + var literal = arguments[1] === true; + + function msg(x) { + if (!is_debug()) { + return; + } + + var value = global_env.get('repr')(x); + + if (regex === null || regex instanceof RegExp && regex.test(value)) { + console.log(global_env.get('type')(x) + ": " + value); + } + + if (literal) { + console.log(x); + } + } + + if (isPromise(x)) { + x.then(msg); + } else { + msg(x); + } + + return x; + } // ---------------------------------------------------------------------- + /* istanbul ignore next */ @@ -4482,9 +4516,9 @@ bindings['...'].symbols[_name3].push(code); } - if (!bindings.symbols[_name3]) { - bindings.symbols[_name3] = code; - } + bindings.symbols[_name3] = code; + + if (!bindings.symbols[_name3]) ; return true; } @@ -4528,6 +4562,27 @@ } } + log({ + pattern: pattern.toString(), + code: code.toString() + }); // case (x y) ===> (var0 var1 ... varn) where var1 match nil + + if (pattern.cdr instanceof Pair && pattern.car instanceof LSymbol && pattern.cdr.cdr instanceof Pair && pattern.cdr.car instanceof LSymbol && LSymbol.is(pattern.cdr.cdr.car, ellipsis_symbol) && pattern.cdr.cdr.cdr instanceof Pair && !LSymbol.is(pattern.cdr.cdr.cdr.car, ellipsis_symbol) && traverse(pattern.car, code.car, pattern_names, ellipsis) && traverse(pattern.cdr.cdr.cdr, code.cdr, pattern_names, ellipsis)) { + var _name5 = pattern.cdr.car.__name__; + log({ + pattern: pattern.car.toString(), + code: code.car.toString(), + name: _name5 + }); + + if (symbols.includes(_name5)) { + return true; + } + + bindings['...'].symbols[_name5] = null; + return true; + } + log('recur'); if (traverse(pattern.car, code.car, pattern_names, ellipsis) && traverse(pattern.cdr, code.cdr, pattern_names, ellipsis)) { @@ -4764,11 +4819,11 @@ if (expr.car instanceof LSymbol && expr.cdr instanceof Pair && LSymbol.is(expr.cdr.car, ellipsis_symbol)) { log('[t 2'); - var _name5 = expr.car.valueOf(); + var _name6 = expr.car.valueOf(); - var item = bindings[_name5]; + var item = bindings[_name6]; log({ - name: _name5, + name: _name6, bindings: bindings, item: item }); @@ -4777,7 +4832,7 @@ return; } else if (item) { log({ - b: bindings[_name5].toString() + b: bindings[_name6].toString() }); if (item instanceof Pair) { @@ -4791,7 +4846,7 @@ if (nested) { if (_cdr !== nil) { log('|| next 1'); - next(_name5, _cdr); + next(_name6, _cdr); } log({ @@ -4801,7 +4856,7 @@ } else { if (_car.cdr !== nil) { log('|| next 2'); - next(_name5, new Pair(_car.cdr, _cdr)); + next(_name6, new Pair(_car.cdr, _cdr)); } log({ @@ -4813,13 +4868,13 @@ log('[t 2 Array ' + nested); if (nested) { - next(_name5, item.slice(1)); + next(_name6, item.slice(1)); return Pair.fromArray(item); } else { var _rest5 = item.slice(1); if (_rest5.length) { - next(_name5, _rest5); + next(_name6, _rest5); } return item[0]; @@ -4880,7 +4935,19 @@ if (expr.cdr instanceof Pair && LSymbol.is(expr.cdr.car, ellipsis_symbol) && !disabled) { log('>> 1'); - var _symbols2 = bindings['...'].symbols; + var _symbols2 = bindings['...'].symbols; // skip expand list of pattern was (x y ... z) + // and code was (x z) so y == null + + var values = Object.values(_symbols2); + + if (values.length && values.every(function (x) { + return x === null; + })) { + return traverse(expr.cdr.cdr, { + disabled: disabled + }); + } + var keys = get_names(_symbols2); // case of list as first argument ((x . y) ...) or (x ... ...) // we need to recursively process the list // if we have pattern (_ (x y z ...) ...) and code (foo (1 2) (1 2)) @@ -4955,6 +5022,15 @@ if (result !== nil && !is_spread) { result = result.reverse(); + } // case of (list) ... (rest code) + + + if (expr.cdr.cdr !== nil && !LSymbol.is(expr.cdr.cdr.car, ellipsis_symbol)) { + var _rest6 = traverse(expr.cdr.cdr, { + disabled: disabled + }); + + return result.append(_rest6); } return result; @@ -5011,6 +5087,9 @@ var value = transform_ellipsis_expr(expr, _bind2, { nested: false }, next); + log({ + value: value.toString() + }); if (typeof value !== 'undefined') { _result2 = new Pair(value, _result2); @@ -5042,10 +5121,13 @@ return node; } + log('<<<< 1'); + _result2.append(node); } } + log('<<<< 2'); return _result2; } } @@ -8984,6 +9066,12 @@ while (rules !== nil) { var rule = rules.car.car; var expr = rules.car.cdr.car; + + if (is_debug()) { + console.log('--------------------------------'); + } + + log(rule); var bindings = extract_patterns(rule, code, symbols, ellipsis, { expansion: this, define: env @@ -11156,10 +11244,10 @@ var banner = function () { // Rollup tree-shaking is removing the variable if it's normal string because - // obviously 'Wed, 11 Nov 2020 11:37:22 +0000' == '{{' + 'DATE}}'; can be removed + // obviously 'Wed, 11 Nov 2020 17:52:59 +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('Wed, 11 Nov 2020 11:37:22 +0000').valueOf(); + var date = LString('Wed, 11 Nov 2020 17:52:59 +0000').valueOf(); var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date); @@ -11196,7 +11284,7 @@ var lips = { version: 'DEV', banner: banner, - date: 'Wed, 11 Nov 2020 11:37:22 +0000', + date: 'Wed, 11 Nov 2020 17:52:59 +0000', exec: exec, parse: parse, tokenize: tokenize, diff --git a/dist/lips.min.js b/dist/lips.min.js index 4eb00ef93..a0e927369 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: Wed, 11 Nov 2020 11:37:22 +0000 + * build: Wed, 11 Nov 2020 17:52:59 +0000 */ -(function(){"use strict";function _readOnlyError(e){throw new Error('"'+e+'" is read-only')}var readOnlyError=_readOnlyError;function createCommonjsModule(e,r){return r={exports:{}},e(r,r.exports),r.exports}var setPrototypeOf=createCommonjsModule(function(n){function t(e,r){n.exports=t=Object.setPrototypeOf||function e(r,n){r.__proto__=n;return r};return t(e,r)}n.exports=t});function _isNativeReflectConstruct(){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 isNativeReflectConstruct=_isNativeReflectConstruct;var construct=createCommonjsModule(function(t){function i(e,r,n){if(isNativeReflectConstruct()){t.exports=i=Reflect.construct}else{t.exports=i=function e(r,n,t){var i=[null];i.push.apply(i,n);var a=Function.bind.apply(r,i);var o=new a;if(t)setPrototypeOf(o,t.prototype);return o}}return i.apply(null,arguments)}t.exports=i});function _arrayWithHoles(e){if(Array.isArray(e))return e}var arrayWithHoles=_arrayWithHoles;function _iterableToArray(e){if(typeof Symbol!=="undefined"&&Symbol.iterator in Object(e))return Array.from(e)}var iterableToArray=_iterableToArray;function _arrayLikeToArray(e,r){if(r==null||r>e.length)r=e.length;for(var n=0,t=new Array(r);n=0;--r){var i=this.tryEntries[r];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;--n){var t=this.tryEntries[n];if(t.tryLoc<=this.prev&&f.call(t,"finallyLoc")&&this.prev=0;--r){var n=this.tryEntries[r];if(n.finallyLoc===e){this.complete(n.completion,n.afterLoc);O(n);return v}}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc===e){var t=n.completion;if(t.type==="throw"){var i=t.arg;O(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){this.delegate={iterator:E(e),resultName:r,nextLoc:n};if(this.method==="next"){this.arg=c}return v}};return o}(e.exports);try{regeneratorRuntime=r}catch(e){Function("r","regeneratorRuntime = r")(r)}});var regenerator=runtime_1;function asyncGeneratorStep(e,r,n,t,i,a,o){try{var u=e[a](o);var c=u.value}catch(e){n(e);return}if(u.done){r(c)}else{Promise.resolve(c).then(t,i)}}function _asyncToGenerator(u){return function(){var e=this,o=arguments;return new Promise(function(r,n){var t=u.apply(e,o);function i(e){asyncGeneratorStep(t,r,n,i,a,"next",e)}function a(e){asyncGeneratorStep(t,r,n,i,a,"throw",e)}i(undefined)})}}var asyncToGenerator=_asyncToGenerator;function _classCallCheck(e,r){if(!(e instanceof r)){throw new TypeError("Cannot call a class as a function")}}var classCallCheck=_classCallCheck;function _defineProperties(e,r){for(var n=0;n=0)continue;n[i]=e[i]}return n}var objectWithoutPropertiesLoose=_objectWithoutPropertiesLoose;function _objectWithoutProperties(e,r){if(e==null)return{};var n=objectWithoutPropertiesLoose(e,r);var t,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,t))continue;n[t]=e[t]}}return n}var objectWithoutProperties=_objectWithoutProperties;function _iterableToArrayLimit(e,r){if(typeof Symbol==="undefined"||!(Symbol.iterator in Object(e)))return;var n=[];var t=true;var i=false;var a=undefined;try{for(var o=e[Symbol.iterator](),u;!(t=(u=o.next()).done);t=true){n.push(u.value);if(r&&n.length===r)break}}catch(e){i=true;a=e}finally{try{if(!t&&o["return"]!=null)o["return"]()}finally{if(i)throw a}}return n}var iterableToArrayLimit=_iterableToArrayLimit;function _slicedToArray(e,r){return arrayWithHoles(e)||iterableToArrayLimit(e,r)||unsupportedIterableToArray(e,r)||nonIterableRest()}var slicedToArray=_slicedToArray;var _typeof_1=createCommonjsModule(function(r){function n(e){"@babel/helpers - typeof";if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){r.exports=n=function e(r){return typeof r}}else{r.exports=n=function e(r){return r&&typeof Symbol==="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r}}return n(e)}r.exports=n});function _createForOfIteratorHelper(r,e){var n;if(typeof Symbol==="undefined"||r[Symbol.iterator]==null){if(Array.isArray(r)||(n=_unsupportedIterableToArray$1(r))||e&&r&&typeof r.length==="number"){if(n)r=n;var t=0;var i=function e(){};return{s:i,n:function e(){if(t>=r.length)return{done:true};return{done:false,value:r[t++]}},e:function e(r){throw r},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a=true,o=false,u;return{s:function e(){n=r[Symbol.iterator]()},n:function e(){var r=n.next();a=r.done;return r},e:function e(r){o=true;u=r},f:function e(){try{if(!a&&n["return"]!=null)n["return"]()}finally{if(o)throw u}}}}function _unsupportedIterableToArray$1(e,r){if(!e)return;if(typeof e==="string")return _arrayLikeToArray$1(e,r);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor)n=e.constructor.name;if(n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray$1(e,r)}function _arrayLikeToArray$1(e,r){if(r==null||r>e.length)r=e.length;for(var n=0,t=new Array(r);n1&&arguments[1]!==undefined$1?arguments[1]:10;var n=num_pre_parse(e);var t=n.number.split("/");var i=LRational({num:LNumber([t[0],n.radix||r]),denom:LNumber([t[1],n.radix||r])});if(n.inexact){return i.valueOf()}else{return i}}function parse_integer(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:10;var n=num_pre_parse(e);if(n.inexact){return LFloat(parseInt(n.number,n.radix||r))}return LNumber([n.number,n.radix||r])}function parse_character(e){var r=e.match(/#\\x([0-9a-f]+)$/i);var n;if(r){var t=parseInt(r[1],16);n=String.fromCodePoint(t)}else{r=e.match(/#\\(.+)$/);if(r){n=r[1]}}if(n){return LCharacter(n)}}function parse_complex(e){var i=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:10;function r(e){var r;if(e==="+"){r=LNumber(1)}else if(e==="-"){r=LNumber(-1)}else if(e.match(int_bare_re)){r=LNumber([e,i])}else if(e.match(rational_bare_re)){var n=e.split("/");r=LRational({num:LNumber([n[0],i]),denom:LNumber([n[1],i])})}else if(e.match(float_re)){var t=LFloat(parseFloat(e));if(a.exact){return t.toRational()}return t}else{throw new Error("Internal Parser Error")}if(a.inexact){return LFloat(r.valueOf())}return r}var a=num_pre_parse(e);i=a.radix||i;var n;var t=a.number.match(complex_bare_match_re);if(i!==10&&t){n=t}else{n=a.number.match(complex_list_re[i])}var o,u;u=r(n[2]);if(n[1]){o=r(n[1])}else if(u instanceof LFloat){o=LFloat(0)}else{o=LNumber(0)}return LComplex({im:u,re:o})}function is_int(e){return parseInt(e.toString(),10)===e}function parse_big_int(e){var r=e.match(/^(([-+]?[0-9]*)(?:\.([0-9]+))?)e([-+]?[0-9]+)/i);if(r){var n=parseInt(r[4],10);var t;var i=r[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var a=r[3]&&r[3].length;if(i0){return LNumber(a).mul(u)}}}n=LFloat(n);if(r.exact){return n.toRational()}return n}function parse_string(e){var r=/([^\\\n])(\\(?:\\{2})*)(?!x[0-9A-F]+)(?!u[0-9A-F]{2,4})(.)/gi;e=e.replace(r,function(e,r,n,t){if(!['"',"/","b","f","n","\\","r","t","x"].includes(t)){n=n.substring(1).replace(/\\\\/,"\\")}return e}).replace(/\\x([0-9a-f]+);/gi,function(e,r){return"\\u"+r.padStart(4,"0")}).replace(/\n/g,"\\n");var n=e.match(/(\\*)(\\x[0-9A-F])/i);if(n&&n[1].length%2===0){throw new Error("Invalid string literal, unclosed ".concat(n[2]))}try{return LString(JSON.parse(e))}catch(e){throw new Error("Invalid string literal")}}function parse_symbol(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var n={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,r){return String.fromCharCode(parseInt("0"+r,16))}).replace(/\\(.)/g,function(e,r){return n[r]||r})}return new LSymbol(e)}function parse_argument(e){var r=e.match(re_re);if(r){return new RegExp(r[1],r[2])}else if(e.match(/^"/)){return parse_string(e)}else if(e.match(char_re)){return parse_character(e)}else if(e.match(rational_re)){return parse_rational(e)}else if(e.match(complex_re)){return parse_complex(e)}else if(e.match(int_re)){return parse_integer(e)}else if(e.match(float_re)){return parse_float(e)}else if(e==="nil"){return nil}else if(["true","#t"].includes(e)){return true}else if(["false","#f"].includes(e)){return false}else{return parse_symbol(e)}}function is_symbol_string(e){return!(["(",")"].includes(e)||e.match(re_re)||e.match(/^"[\s\S]+"$/)||e.match(int_re)||e.match(float_re)||e.match(complex_re)||e.match(rational_re)||["#t","#f","nil","true","false"].includes(e))}var pre_parse_re=/("(?:\\[\S\s]|[^"])*"?|\/(?! )[^\n\/\\]*(?:\\[\S\s][^\n\/\\]*)*\/[gimy]*(?=[\s[\]()]|$)|\|[^|\s\n]+\||#;|;.*|#\|(?!\|#)[\s\S]*\|#)/g;var string_re=/"(?:\\[\S\s]|[^"])*"?/g;var num_stre=[gen_complex_re,gen_rational_re,gen_integer_re].map(make_num_stre).join("|");function make_tokens_re(){var e=specials.names().sort(function(e,r){return r.length-e.length||e.localeCompare(r)}).map(escape_regex).join("|");return new RegExp("(".concat(char_sre_re,"|#f|#t|#;|(?:").concat(num_stre,")(?=$|[\\n\\s()[\\]])|\\[|\\]|\\(|\\)|\\|[^|]+\\||;.*|(?:#[ei])?").concat(float_stre,"(?=$|[\\n\\s()[\\]])|\\n|\\.{2,}|'(?=#[ft]|(?:#[xiobe]){1,2}|#\\\\)|(?!#:)(?:").concat(e,")|[^(\\s)[\\]]+)"),"gim")}function last_item(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:1;return e[e.length-r]}function escape_regex(e){if(typeof e==="string"){var r=/([-\\^$[\]()+{}?*.|])/g;return e.replace(r,"\\$1")}}function Stack(){this.data=[]}Stack.prototype.push=function(e){this.data.push(e)};Stack.prototype.top=function(){return this.data[this.data.length-1]};Stack.prototype.pop=function(){return this.data.pop()};Stack.prototype.is_empty=function(){return!this.data.length};function tokens(e){var a=make_tokens_re();e=e.replace(/\n\r|\r/g,"\n");var o=0;var u=0;var c=[];var s=[];var f=0;e.split(pre_parse_re).filter(Boolean).forEach(function(e){if(e.match(pre_parse_re)){f=0;if(s.length){var r=last_item(s);if(r.token.match(/\n/)){var n=r.token.split("\n").pop();f+=n.length}else{f+=r.token.length}f+=r.col}var t={col:f,line:u,token:e,offset:o};c.push(t);s.push(t);o+=e.length;f+=e.length;u+=(e.match("\n")||[]).length;return}var i=e.split(a).filter(Boolean);i.forEach(function(e){var r={col:f,line:u,token:e,offset:o};f+=e.length;o+=e.length;c.push(r);s.push(r);if(e==="\n"){++u;s=[];f=0}})});return c}function multiline_formatter(e){var r=e.token,n=objectWithoutProperties(e,["token"]);if(r.match(/^"[\s\S]+"$/)&&r.match(/\n/)){var t=new RegExp("^ {1,"+(e.col+1)+"}","mg");r=r.replace(t,"")}return _objectSpread({token:r},n)}function Thunk(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:function(){};this.fn=e;this.cont=r}Thunk.prototype.toString=function(){return"#"};function trampoline(t){return function(){for(var e=arguments.length,r=new Array(e),n=0;n2&&arguments[2]!==undefined$1?arguments[2]:multiline_formatter;if(e instanceof LString){e=e.toString()}if(r){return tokens(e).map(n)}else{var t=tokens(e).map(function(e){var r=n(e);if(!r||typeof r.token!=="string"){throw new Error("[tokenize] Invalid formatter wrong return object")}if(r.token==="#\\ "){return r.token}return r.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return strip_s_comments(t)}}function strip_s_comments(e){var r=0;var n=null;var t=[];for(var i=0;i1&&arguments[1]!==undefined$1?arguments[1]:function(e){return e};var n=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:null;if(e instanceof Array){var t=e.filter(isPromise);if(t.length){return unpromise(Promise.all(t),r,n)}return r(e)}if(isPromise(e)){var i=e.then(r);if(n===null){return i}else{return i["catch"](n)}}return r(e)}function matcher(e,r){if(r instanceof RegExp){return function(e){return String(e).match(r)}}else if(typeof r==="function"){return r}}function doc(e,r,n,t){if(typeof e!=="string"){r=arguments[0];n=arguments[1];t=arguments[2];e=null}if(n){if(t){r.__doc__=n}else{r.__doc__=trim_lines(n)}}if(e){r.__name__=e}else if(r.name){r.__name__=r.name}return r}function trim_lines(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function previousSexp(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:1;var n=e.length;if(r<=0){throw Error("previousSexp: Invalid argument sexp = ".concat(r))}e:while(r--&&n>=0){var t=1;while(t>0){var i=e[--n];if(!i){break e}if(i==="("||i.token==="("){t--}else if(i===")"||i.token===")"){t++}}n--}return e.slice(n+1)}function lineIndent(e){if(!e||!e.length){return 0}var r=e.length;if(e[r-1].token==="\n"){return 0}while(--r){if(e[r].token==="\n"){var n=(e[r+1]||{}).token;if(n){return n.length}}}return 0}function match(e,r){return f(e,r)===r.length;function f(n,t){function e(){return a>0&&u>0&&n[a-1]===t[u-1]&&n[a+1]===t[u]}function r(){return n[a]===Symbol["for"]("symbol")&&!is_symbol_string(t[u])}function i(){var e=n[a+1];var r=t[u+1];if(e!==undefined$1&&r!==undefined$1){return f([e],[r])}}var a=0;var o={};for(var u=0;u0){continue}}else if(r()){return-1}}else if(n[a]instanceof Array){var s=f(n[a],t.slice(u));if(s===-1||s+u>t.length){return-1}u+=s-1;a++;continue}else{return-1}a++}if(n.length!==a){return-1}return t.length}}function Formatter(e){this._code=e.replace(/\r/g,"")}Formatter.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?define/,/^(?:#:)?lambda/,/^(?:#:)?let*/,/^(?:#:)?(let|letrec)(-syntax)?$/,/(?:#:)?let-env/,/(?:#:)?syntax-rules/,/(?:#:)?try/,/(?:#:)?catch/,/(?:#:)?while/],shift:{1:["&","#"]}}};Formatter.match=match;Formatter.prototype._options=function e(r){var n=Formatter.defaults;if(typeof r==="undefined"){return Object.assign({},n)}var t=r&&r.exceptions||{};var i=t.specials||[];var a=t.shift||{1:[]};return _objectSpread(_objectSpread(_objectSpread({},n),r),{},{exceptions:{specials:[].concat(toConsumableArray(n.exceptions.specials),toConsumableArray(i)),shift:_objectSpread(_objectSpread({},a),{},{1:[].concat(toConsumableArray(n.exceptions.shift[1]),toConsumableArray(a[1]))})}})};Formatter.prototype.indent=function e(r){var n=tokenize(this._code,true);return this._indent(n,r)};Formatter.exception_shift=function(a,e){function r(e){if(!e.length){return false}if(e.indexOf(a)!==-1){return true}else{var r=e.filter(function(e){return e instanceof RegExp});if(!r.length){return false}var n=_createForOfIteratorHelper(r),t;try{for(n.s();!(t=n.n()).done;){var i=t.value;if(a.match(i)){return true}}}catch(e){n.e(e)}finally{n.f()}}return false}if(r(e.exceptions.specials)){return e.indent}var n=e.exceptions.shift;for(var t=0,i=Object.entries(n);t0){t.offset=0}if(a.toString()===r.toString()&&balanced(a)){return t.offset+a[0].col}else if(a.length===1){return t.offset+a[0].col+1}else{var u=-1;if(o){var c=Formatter.exception_shift(o.token,t);if(c!==-1){u=c}}if(u===-1){u=Formatter.exception_shift(a[1].token,t)}if(u!==-1){return t.offset+a[0].col+u}else if(a[0].line3&&a[1].line===a[3].line){if(a[1].token==="("||a[1].token==="["){return t.offset+a[1].col}return t.offset+a[3].col}else if(a[0].line===a[1].line){return t.offset+t.indent+a[0].col}else{var s=a.slice(2);for(var f=0;f")};Ahead.prototype.match=function(e){return e.match(this.pattern)};function Pattern(e,r){this.pattern=e;this.flag=r}Pattern.prototype.toString=function(){return"#")};Formatter.Pattern=Pattern;Formatter.Ahead=Ahead;var p_o=/[[(]/;var p_e=/[\])]/;var not_p=/[^()[\]]/;var not_close=new Ahead(/[^)\]]/);var open=new Ahead(/[([]/);var glob=Symbol["for"]("*");var sexp=new Pattern([p_o,glob,p_e],"+");var symbol=new Pattern([Symbol["for"]("symbol")],"?");var symbols=new Pattern([Symbol["for"]("symbol")],"*");var identifiers=[p_o,symbols,p_e];var let_value=new Pattern([p_o,Symbol["for"]("symbol"),glob,p_e],"+");var def_lambda_re=keywords_re("define","lambda","syntax-rules");var non_def=/^(?!.*\b(?:[()[\]]|define|let(?:\*|rec|-env|-syntax)?|lambda|syntax-rules)\b).*$/;var let_re=/^(?:#:)?(let(?:\*|rec|-env|-syntax)?)$/;function keywords_re(){for(var e=arguments.length,r=new Array(e),n=0;n0&&arguments[0]!==undefined$1?arguments[0]:null;if(e instanceof LSymbol){e=e.valueOf()}if(is_gensym(e)){return LSymbol(e)}if(e!==null){return new LSymbol(Symbol("#:".concat(e)))}r++;return new LSymbol(Symbol("#:g".concat(r)))}}();function Nil(){}Nil.prototype.toString=Nil.prototype.toJSON=function(){return"()"};Nil.prototype.valueOf=function(){return undefined$1};Nil.prototype.toObject=function(){return{}};Nil.prototype.append=function(e){return new Pair(e,nil)};Nil.prototype.toArray=function(){return[]};var nil=new Nil;function Pair(e,r){if(typeof this!=="undefined"&&this.constructor!==Pair||typeof this==="undefined"){return new Pair(e,r)}this.car=e;this.cdr=r}function toArray$1(a,o){return function e(r){typecheck(a,r,["pair","nil"]);if(r===nil){return[]}var n=[];var t=r;while(true){if(t instanceof Pair){if(t.haveCycles("cdr")){break}var i=t.car;if(o&&i instanceof Pair){i=this.get(a).call(this,i)}n.push(i);t=t.cdr}else{break}}return n}}Pair.prototype.flatten=function(){return Pair.fromArray(flatten(this.toArray()))};Pair.prototype.length=function(){var e=0;var r=this;while(true){if(!r||r===nil||!(r instanceof Pair)||r.haveCycles("cdr")){break}e++;r=r.cdr}return e};Pair.prototype.clone=function(){var n=new Map;function t(e){if(e instanceof Pair){if(n.has(e)){return n.get(e)}var r=new Pair;n.set(e,r);r.car=t(e.car);r.cdr=t(e.cdr);r.cycles=e.cycles;return r}return e}return t(this)};Pair.prototype.lastPair=function(){var e=this;while(true){if(e.cdr===nil){return e}e=e.cdr}};Pair.prototype.toArray=function(){var e=[];if(this.car instanceof Pair){e.push(this.car.toArray())}else{e.push(this.car.valueOf())}if(this.cdr instanceof Pair){e=e.concat(this.cdr.toArray())}return e};Pair.fromArray=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:true;var n=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:false;if(e instanceof Pair||n&&e instanceof Array&&e.data){return e}if(r===false){var t=nil;for(var i=e.length;i--;){t=new Pair(e[i],t)}return t}if(e.length&&!(e instanceof Array)){e=toConsumableArray(e)}var a=nil;var o=e.length;while(o--){var u=e[o];if(u instanceof Array){u=Pair.fromArray(u,r,n)}else if(typeof u==="string"){u=LString(u)}else if(typeof u==="number"&&!Number.isNaN(u)){u=LNumber(u)}a=new Pair(u,a)}return a};Pair.prototype.toObject=function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:false;var r=this;var n={};while(true){if(r instanceof Pair&&r.car instanceof Pair){var t=r.car;var i=t.car;if(i instanceof LSymbol){i=i.__name__}if(i instanceof LString){i=i.valueOf()}var a=t.cdr;if(a instanceof Pair){a=a.toObject(e)}if(is_native(a)){if(!e){a=a.valueOf()}}n[i]=a;r=r.cdr}else{break}}return n};Pair.fromPairs=function(e){return e.reduce(function(e,r){return new Pair(new Pair(new LSymbol(r[0]),r[1]),e)},nil)};Pair.fromObject=function(r){var e=Object.keys(r).map(function(e){return[e,r[e]]});return Pair.fromPairs(e)};Pair.prototype.reduce=function(e){var r=this;var n=nil;while(true){if(r!==nil){n=e(n,r.car);r=r.cdr}else{break}}return n};Pair.prototype.reverse=function(){if(this.haveCycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var r=nil;while(e!==nil){var n=e.cdr;e.cdr=r;r=e;e=n}return r};Pair.prototype.transform=function(t){function i(e){if(e instanceof Pair){if(e.replace){delete e.replace;return e}var r=t(e.car);if(r instanceof Pair){r=i(r)}var n=t(e.cdr);if(n instanceof Pair){n=i(n)}return new Pair(r,n)}return e}return i(this)};Pair.prototype.map=function(e){if(typeof this.car!=="undefined"){return new Pair(e(this.car),this.cdr===nil?nil:this.cdr.map(e))}else{return nil}};var repr=new Map;function is_plain_object(e){return e&&_typeof_1(e)==="object"&&e.constructor===Object}var props=Object.getOwnPropertyNames(Array.prototype);var array_methods=[];props.forEach(function(e){array_methods.push(Array[e],Array.prototype[e])});function is_array_method(e){e=unbind(e);return array_methods.includes(e)}function lips_function(e){return typeof e==="function"&&(e.__lambda__||e.__doc__)}function user_repr(n){var e=n.constructor||Object;var t=is_plain_object(n);var i;if(repr.has(e)){i=repr.get(e)}else{repr.forEach(function(e,r){r=unbind(r);if(n instanceof r&&(r===Object&&t||r!==Object)){i=e}})}return i}var str_mapping=new Map;[[Number.NEGATIVE_INFINITY,"-inf.0"],[Number.POSITIVE_INFINITY,"+inf.0"],[true,"#t"],[false,"#f"],[null,"null"],[undefined$1,"#"]].forEach(function(e){var r=slicedToArray(e,2),n=r[0],t=r[1];str_mapping.set(n,t)});function symbolize(n){if(n&&_typeof_1(n)==="object"){var t={};var e=Object.getOwnPropertySymbols(n);e.forEach(function(e){var r=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");t[r]=toString(n[e])});var r=Object.getOwnPropertyNames(n);r.forEach(function(e){var r=n[e];if(r&&_typeof_1(r)==="object"&&r.constructor===Object){t[e]=symbolize(r)}else{t[e]=toString(r)}});return t}return n}function get_props(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function toString(e,r,n){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(str_mapping.has(e)){return str_mapping.get(e)}if(e instanceof Error){return e.message}if(e instanceof Pair){var t;if(!n){e.markCycles()}for(var i=arguments.length,a=new Array(i>3?i-3:0),o=3;o"}if(isNativeFunction(e.toString)){if(typeof e.__name__==="string"){return"#")}return"#"}else{return e.toString()}}if(e instanceof LString){e=e.toString()}if(e===null||typeof e==="string"&&r){return JSON.stringify(e)}if(_typeof_1(e)==="object"){if(typeof e.toString==="function"&&e.toString.__lambda__){return e.toString().valueOf()}var l=e.constructor;if(!l){l=Object}var p;if(typeof l.__class__==="string"){p=l.__class__}else{if(is_prototype(e)){return"#"}var d=user_repr(e);if(d){if(typeof d==="function"){return d(e,r)}else{throw new Error("toString: Invalid repr value")}}p=l.name}if(type(e)==="instance"&&!isNativeFunction(l)){p="instance"}if(root.HTMLElement&&e instanceof root.HTMLElement){return"#")}if(p!==""){return"#<"+p+">"}if(typeof e[Symbol.iterator]==="function"){return"#"}return"#"}if(typeof e!=="string"){return e.toString()}return e}function is_prototype(e){return e&&_typeof_1(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}Pair.prototype.markCycles=function(){markCycles(this);return this};Pair.prototype.haveCycles=function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:null;if(!e){return this.haveCycles("car")||this.haveCycles("cdr")}return!!(this.cycles&&this.cycles[e])};function markCycles(e){var r=[];var i=[];var a=[];function o(e){if(!r.includes(e)){r.push(e)}}function u(e,r,n,t){if(n instanceof Pair){if(t.includes(n)){if(!a.includes(n)){a.push(n)}if(!e.cycles){e.cycles={}}e.cycles[r]=n;if(!i.includes(e)){i.push(e)}return true}}}var c=trampoline(function e(r,n){if(r instanceof Pair){delete r.ref;delete r.cycles;o(r);n.push(r);var t=u(r,"car",r.car,n);var i=u(r,"cdr",r.cdr,n);if(!t){c(r.car,n.slice())}if(!i){return new Thunk(function(){return e(r.cdr,n.slice())})}}});function n(e,r){if(e.cycles[r]instanceof Pair){var n=t.indexOf(e.cycles[r]);e.cycles[r]="#".concat(n,"#")}}c(e,[]);var t=r.filter(function(e){return a.includes(e)});t.forEach(function(e,r){e.ref="#".concat(r,"=")});i.forEach(function(e){n(e,"car");n(e,"cdr")})}var pair_to_string=function(){var l=function e(r,n){var t=[];if(r.ref){t.push(r.ref+"(")}else if(!n){t.push("(")}return t};var p=function e(r,n){if(is_debug());if(!n||r.ref){return[")"]}return[]};return trampoline(function e(r,n){var t=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:{};var i=t.nested,a=i===void 0?false:i,o=t.result,u=o===void 0?[]:o,c=t.cont,s=c===void 0?function(){u.push.apply(u,toConsumableArray(p(r,a)))}:c;u.push.apply(u,toConsumableArray(l(r,a)));var f;if(r.cycles&&r.cycles.car){f=r.cycles.car}else{f=toString(r.car,n,true,{result:u,cont:s})}if(f!==undefined$1){u.push(f)}return new Thunk(function(){if(r.cdr instanceof Pair){if(r.cycles&&r.cycles.cdr){u.push(" . ");u.push(r.cycles.cdr)}else{if(r.cdr.ref){u.push(" . ")}else{u.push(" ")}return e(r.cdr,n,{nested:true,result:u,cont:s})}}else if(r.cdr!==nil){u.push(" . ");u.push(toString(r.cdr,n))}},s)})}();Pair.prototype.toString=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},n=r.nested,t=n===void 0?false:n;if(is_debug()){var i=[];pair_to_string(this,e,{result:i});return i.join("")}var a=[];if(this.ref){a.push(this.ref+"(")}else if(!t){a.push("(")}var o;if(this.cycles&&this.cycles.car){o=this.cycles.car}else{o=toString(this.car,e,true)}if(o!==undefined$1){a.push(o)}if(this.cdr instanceof Pair){if(this.cycles&&this.cycles.cdr){a.push(" . ");a.push(this.cycles.cdr)}else{if(this.cdr.ref){a.push(" . ")}else{a.push(" ")}var u=this.cdr.toString(e,{nested:true});a.push(u)}}else if(this.cdr!==nil){a=a.concat([" . ",toString(this.cdr,e,true)])}if(!t||this.ref){a.push(")")}return a.join("")};Pair.prototype.set=function(e,r){this[e]=r;if(r instanceof Pair){this.markCycles()}};Pair.prototype.append=function(e){if(e instanceof Array){return this.append(Pair.fromArray(e))}var r=this;if(r.car===undefined$1){if(e instanceof Pair){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(e!==nil){while(true){if(r instanceof Pair&&r.cdr!==nil){r=r.cdr}else{break}}r.cdr=e}return this};function abs(e){return e<0?-e:e}function seq_compare(e,r){var n=toArray(r),t=n[0],i=n.slice(1);while(i.length>0){var a=i,o=slicedToArray(a,1),u=o[0];if(!e(t,u)){return false}var c=i;var s=toArray(c);t=s[0];i=s.slice(1)}return true}function equal(e,r){if(typeof e==="function"&&typeof r==="function"){return unbind(e)===unbind(r)}else if(e instanceof LNumber&&r instanceof LNumber){var n;if(e.__type__===r.__type__){if(e.__type__==="complex"){n=e.im.__type__===r.im.__type__&&e.re.__type__===r.re.__type__}else{n=true}return n&&e.cmp(r)===0}return false}else if(typeof e==="number"||typeof r==="number"){e=LNumber(e);r=LNumber(r);return e.__type__===r.__type__&&e.cmp(r)===0}else if(e instanceof LCharacter&&r instanceof LCharacter){return e.__char__===r.__char__}else if(e instanceof LSymbol&&r instanceof LSymbol){return e.__name__===r.__name__}else{return e===r}}function same_atom(e,r){if(type(e)!==type(r)){return false}if(!is_atom(e)){return false}if(e instanceof RegExp){return e.source===r.source}if(e instanceof LString){return e.valueOf()===r.valueOf()}return equal(e,r)}function is_atom(e){return e instanceof LSymbol||LString.isString(e)||e instanceof LCharacter||e instanceof LNumber||e===true||e===false}var truncate=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function Macro(e,r,n,t){if(typeof this!=="undefined"&&this.constructor!==Macro||typeof this==="undefined"){return new Macro(e,r)}typecheck("Macro",e,"string",1);typecheck("Macro",r,"function",2);if(n){if(t){this.__doc__=n}else{this.__doc__=trim_lines(n)}}this.__name__=e;this.__fn__=r}Macro.defmacro=function(e,r,n,t){var i=new Macro(e,r,n,t);i.__defmacro__=true;return i};Macro.prototype.invoke=function(e,r,n){var t=r.env,i=r.dynamic_scope,a=r.error;var o={dynamic_scope:i,error:a,macro_expand:n};var u=this.__fn__.call(t,e,o,this.__name__);return u};Macro.prototype.toString=function(){return"#")};var macro="define-macro";var recur_guard=-1e4;function macro_expand(a){return function(){var n=asyncToGenerator(regenerator.mark(function e(n,m){var t,h,i;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:i=function e(){i=asyncToGenerator(regenerator.mark(function e(n,t,i){var a,o,u,c,s,f,l,p,d;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!(n instanceof Pair&&n.car instanceof LSymbol)){r.next=24;break}if(!n.data){r.next=3;break}return r.abrupt("return",n);case 3:a=i.get(n.car,{throwError:false});if(!(a instanceof Macro&&a.__defmacro__)){r.next=24;break}o=a instanceof Syntax?n:n.cdr;r.next=8;return a.invoke(o,_objectSpread(_objectSpread({},m),{},{env:i}),true);case 8:u=r.sent;if(!(a instanceof Syntax)){r.next=17;break}c=u,s=c.expr,f=c.scope;if(!(s instanceof Pair)){r.next=16;break}if(!(t!==-1&&t<=1||t")}return"#"};Syntax.className="syntax";function extract_patterns(e,r,g,w){var n=arguments.length>4&&arguments[4]!==undefined$1?arguments[4]:{};var L={"...":{symbols:{},lists:[]},symbols:{}};var x=n.expansion,S=n.define;function k(e){if(is_debug()){console.log(e)}}k(g);function P(e,r){var n=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:[];var t=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:false;k({code:r&&toString(r,true),pattern:e&&toString(e,true)});if(is_atom(e)&&!(e instanceof LSymbol)){return same_atom(e,r)}if(e instanceof LSymbol&&g.includes(e.valueOf())){var i=x.ref(r);if(LSymbol.is(r,e)){if(typeof i==="undefined"){return true}return i===S||i===global_env}return false}if(e instanceof Pair&&e.car instanceof Pair&&e.car.cdr instanceof Pair&&LSymbol.is(e.car.cdr.car,w)){k(">> 0");if(r===nil){k({pattern:e.toString()});if(e.car.car instanceof LSymbol){if(e.car.cdr instanceof Pair&&LSymbol.is(e.car.cdr.car,w)){var a=e.car.car.valueOf();var o=e.lastPair();if(LSymbol.is(o.car,w)){L["..."].symbols[a]=null;return true}else{return false}}var u=e.car.car.valueOf();if(L["..."].symbols[u]){throw new Error("syntax: named ellipsis can only "+"appear onces")}L["..."].symbols[u]=r}}}if(e instanceof Pair&&e.cdr instanceof Pair&&LSymbol.is(e.cdr.car,w)){if(e.cdr.cdr!==nil){if(e.cdr.cdr instanceof Pair){var c=e.cdr.cdr.length();var s=r.length();var f=r;while(s-1>c){f=f.cdr;s--}var l=f.cdr;f.cdr=nil;if(!P(e.cdr.cdr,l,n,t)){return false}}}if(e.car instanceof LSymbol){var p=e.car.__name__;if(L["..."].symbols[p]&&!n.includes(p)&&!t){throw new Error("syntax: named ellipsis can only appear onces")}k(">> 1");if(r===nil){k(">> 2");if(t){k("NIL");L["..."].symbols[p]=nil}else{k("NULL");L["..."].symbols[p]=null}}else if(r instanceof Pair&&(r.car instanceof Pair||r.car===nil)){k(">> 3 "+t);if(t){if(L["..."].symbols[p]){var d=L["..."].symbols[p];L["..."].symbols[p]=d.append(new Pair(r,nil))}else{L["..."].symbols[p]=new Pair(r,nil)}}else{k(">> 4");L["..."].symbols[p]=new Pair(r,nil)}}else{k(">> 6");if(r instanceof Pair){k(">> 7 "+t);n.push(p);if(!L["..."].symbols[p]){L["..."].symbols[p]=new Pair(r,nil)}else{var m=L["..."].symbols[p];L["..."].symbols[p]=m.append(new Pair(r,nil))}k({IIIIII:L["..."].symbols[p].toString()})}else{k(">> 8");return false}}return true}else if(e.car instanceof Pair){var h=toConsumableArray(n);if(r===nil){k(">> 9");L["..."].lists.push(nil);return true}k(">> 10");var v=r;while(v instanceof Pair){if(!P(e.car,v.car,h,true)){return false}v=v.cdr}return true}return false}if(e instanceof LSymbol){if(LSymbol.is(e,w)){throw new Error("syntax: invalid usage of ellipsis")}k(">> 11");var _=e.__name__;if(g.includes(_)){return true}k({name:_,ellipsis:t});if(t){L["..."].symbols[_]=L["..."].symbols[_]||[];L["..."].symbols[_].push(r)}if(!L.symbols[_]){L.symbols[_]=r}return true}if(e instanceof Pair&&r instanceof Pair){k(">> 12");k({a:12,code:r&&r.toString(),pattern:e.toString()});if(r.cdr===nil){var y=e.car instanceof LSymbol&&e.cdr instanceof LSymbol;if(y){if(!P(e.car,r.car,n,t)){return false}k(">> 12 | 1");var b=e.cdr.valueOf();if(!(b in L.symbols)){L.symbols[b]=nil}b=e.car.valueOf();if(!(b in L.symbols)){L.symbols[b]=r.car}return true}}k("recur");if(P(e.car,r.car,n,t)&&P(e.cdr,r.cdr,n,t)){return true}}else if(e===nil&&(r===nil||r===undefined$1)){return true}else if(e.car instanceof Pair&&LSymbol.is(e.car.car,w)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(P(e,r)){return L}}function clear_gensyms(e,i){function a(r){if(r instanceof Pair){if(!i.length){return r}var e=a(r.car);var n=a(r.cdr);return new Pair(e,n)}else if(r instanceof LSymbol){var t=i.find(function(e){return e.gensym===r});if(t){return LSymbol(t.name)}return r}else{return r}}return a(e)}function transform_syntax(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:{};var S=e.bindings,r=e.expr,k=e.scope,i=e.symbols,a=e.names,P=e.ellipsis;var o={};function u(e){if(e instanceof LSymbol){return true}return["string","symbol"].includes(_typeof_1(e))}function N(e){if(!u(e)){var r=type(e);throw new Error("syntax: internal error, need symbol got ".concat(r))}var n=e.valueOf();if(n===P){throw new Error("syntax: internal error, ellipis not transformed")}var t=_typeof_1(n);if(["string","symbol"].includes(t)&&n in S.symbols){return S.symbols[n]}if(i.includes(n)){return LSymbol(n)}return c(n)}function O(e){if(is_debug()){console.log(e)}}function c(e){if(!o[e]){var r=k.ref(e);var n=gensym(e);if(r){var t=k.get(e);k.set(n,t)}a.push({name:e,gensym:n});o[e]=n}return o[e]}function j(e,r,n){var t=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:function(){};var i=n.nested;O(" ==> "+e.toString());O(r);if(e instanceof LSymbol){var a=e.valueOf();O("[t 1");if(r[a]){if(r[a]instanceof Pair){var o=r[a],u=o.car,c=o.cdr;if(i){var s=u.car,f=u.cdr;if(f!==nil){t(a,new Pair(f,nil))}return s}if(c!==nil){t(a,c)}return u}else if(r[a]instanceof Array){t(a,r[a].slice(1));return r[a][0]}}return N(a)}if(e instanceof Pair){if(e.car instanceof LSymbol&&e.cdr instanceof Pair&&LSymbol.is(e.cdr.car,P)){O("[t 2");var l=e.car.valueOf();var p=r[l];O({name:l,bindings:r,item:p});if(p===null){return}else if(p){O({b:r[l].toString()});if(p instanceof Pair){O("[t 2 Pair "+i);O({______:p.toString()});var d=p.car,m=p.cdr;if(i){if(m!==nil){O("|| next 1");t(l,m)}O({car:d.toString()});return d}else{if(d.cdr!==nil){O("|| next 2");t(l,new Pair(d.cdr,m))}O({car:d.car.toString()});return d.car}}else if(p instanceof Array){O("[t 2 Array "+i);if(i){t(l,p.slice(1));return Pair.fromArray(p)}else{var h=p.slice(1);if(h.length){t(l,h)}return p[0]}}else{return p}}}O("[t 3 recur "+e.toString());var v=j(e.car,r,n,t);var _=j(e.cdr,r,n,t);return new Pair(v,_)}return e}function E(r,n){var e=Object.values(r);var t=Object.getOwnPropertySymbols(r);if(t.length){e.push.apply(e,toConsumableArray(t.map(function(e){return r[e]})))}return e.length&&e.every(function(e){if(e===null){return!n}return e instanceof Pair||e===nil||e instanceof Array&&e.length})}function A(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function F(i){var e=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},r=e.disabled;O("traverse>> "+i.toString());if(i instanceof Pair){if(!r&&i.car instanceof Pair&&LSymbol.is(i.car.car,P)){return F(i.car.cdr,{disabled:true})}if(i.cdr instanceof Pair&&LSymbol.is(i.cdr.car,P)&&!r){O(">> 1");var n=S["..."].symbols;var t=A(n);var a=i.car instanceof LSymbol&&LSymbol.is(i.cdr.cdr.car,P);if(i.car instanceof Pair||a){if(S["..."].lists[0]===nil){return nil}var o=i.car;if(a){o=new Pair(i.car,new Pair(i.cdr.car,nil))}O(">> 2");var u;if(t.length){O(">> 2 (a)");var c=_objectSpread({},n);u=nil;var s=function e(){if(!E(c)){return"break"}var t={};var r=function e(r,n){t[r]=n};var n=j(o,c,{nested:true},r);if(n!==undefined$1){if(a){if(u===nil){u=n}else{u=u.append(n)}}else{u=new Pair(n,u)}}c=t};while(true){var f=s();if(f==="break")break}if(u!==nil&&!a){u=u.reverse()}return u}else{O(">> 3");var l=j(i.car,n,{nested:true});if(l){return new Pair(l,nil)}return nil}}else if(i.car instanceof LSymbol){O(">> 4");if(LSymbol.is(i.cdr.cdr.car,P)){O(">> 4 (a)")}else{O(">> 4 (b)")}var p=i.car.__name__;var d=defineProperty({},p,n[p]);var m=n[p]===null;var h=nil;var v=function e(){if(!E(d,true)){O({bind:d});return"break"}var t={};var r=function e(r,n){t[r]=n;if(is_debug()){console.log({NEWBIND:t[r].toString()})}};var n=j(i,d,{nested:false},r);if(typeof n!=="undefined"){h=new Pair(n,h)}d=t};while(true){var _=v();if(_==="break")break}if(h!==nil){h=h.reverse()}if(i.cdr instanceof Pair){if(i.cdr.cdr instanceof Pair||i.cdr.cdr instanceof LSymbol){var y=F(i.cdr.cdr,{disabled:r});if(m){return y}h.append(y)}}return h}}var b=k.get(i.car,{throwError:false});var g=b instanceof Macro&&b.__name__==="syntax-rules";var w=F(i.car,{disabled:r});var L;if(g){if(i.cdr.car instanceof LSymbol){L=new Pair(F(i.cdr.car,{disabled:r}),new Pair(i.cdr.cdr.car,F(i.cdr.cdr.cdr,{disabled:r})))}else{L=new Pair(i.cdr.car,F(i.cdr.cdr,{disabled:r}))}}else{L=F(i.cdr,{disabled:r})}O({a:true,car:i.car.toString(),cdr:i.cdr.toString(),head:w&&w.toString(),rest:L&&L.toString()});return new Pair(w,L)}if(i instanceof LSymbol){if(r&&LSymbol.is(i,P)){return i}var x=N(i);if(typeof x!=="undefined"){return x}}return i}return F(r,{})}function isNull(e){return typeof e==="undefined"||e===nil||e===null}function isPromise(e){return e instanceof Promise||e&&typeof e!=="undefined"&&typeof e.then==="function"}function box(e){switch(_typeof_1(e)){case"string":return LString(e);case"number":if(!Number.isNaN(e)){return LNumber(e)}}return e}function map_object(t,i){var e=Object.getOwnPropertyNames(t);var r=Object.getOwnPropertySymbols(t);e.concat(r).forEach(function(e){var r=i(t[e]);var n=Object.getOwnPropertyDescriptor(t,e);if(!n||n.writable&&t[e]!==r){t[e]=r}});return t}function unbox(r){var e=[LString,LCharacter,LNumber].some(function(e){return r instanceof e});if(e){return r.valueOf()}if(r instanceof Array){return r.map(unbox)}if(is_plain_object(r)){return map_object(r,unbox)}return r}function patchValue(e,r){if(e instanceof Pair){e.markCycles();return quote(e)}if(typeof e==="function"){if(r){return bind(e,r)}}return box(e)}function unbind(e){if(is_bound(e)){return e[__fn__]}return e}function bind(r,e){if(r[Symbol["for"]("__bound__")]){return r}var n=r.bind(e);var t=Object.getOwnPropertyNames(r).filter(filter_fn_names);t.forEach(function(e){try{n[e]=r[e]}catch(e){}});hidden_prop(n,"__fn__",r);hidden_prop(n,"__context__",e);hidden_prop(n,"__bound__",true);if(isNativeFunction(r)){hidden_prop(n,"__native__",true)}n.valueOf=function(){return r};return n}function is_object_bound(e){return is_bound(e)&&e[Symbol["for"]("__context__")]===Object}function is_bound(e){return!!(typeof e==="function"&&e[__fn__])}function lips_context(e){if(typeof e==="function"){var r=e[__context__];if(r&&(r===lips||r.constructor&&r.constructor.__class__)){return true}}return false}function is_port(e){function r(e){return e instanceof InputPort||e instanceof OutputPort}if(typeof e==="function"){if(r(e)){return true}if(r(e[__context__])){return true}}return false}var __context__=Symbol["for"]("__context__");var __fn__=Symbol["for"]("__fn__");var exluded_names=["name","length","caller","callee","arguments","prototype"];function filter_fn_names(e){return!exluded_names.includes(e)}function hidden_prop(e,r,n){Object.defineProperty(e,Symbol["for"](r),{get:function e(){return n},set:function e(){},configurable:false,enumerable:false})}function setFnLength(r,n){try{Object.defineProperty(r,"length",{get:function e(){return n}});return r}catch(e){var t=new Array(n).fill(0).map(function(e,r){return"a"+r}).join(",");var i=new Function("f","return function(".concat(t,") {\n return f.apply(this, arguments);\n };"));return i(r)}}function isNativeFunction(e){var r=Symbol["for"]("__native__");return typeof e==="function"&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[r]===true||!e.name.match(/^bound /)&&!e[r])}function let_macro(e){var m;switch(e){case Symbol["for"]("letrec"):m="letrec";break;case Symbol["for"]("let"):m="let";break;case Symbol["for"]("let*"):m="let*";break;default:throw new Error("Invalid let_macro value")}return Macro.defmacro(m,function(r,e){var a=e.dynamic_scope,o=e.error,n=e.macro_expand;var u;if(r.car instanceof LSymbol){if(!(r.cdr.car instanceof Pair||r.cdr.car===nil)){throw new Error("let require list of pairs")}var t;if(r.cdr.car===nil){u=nil;t=nil}else{t=r.cdr.car.map(function(e){return e.car});u=r.cdr.car.map(function(e){return e.cdr.car})}return Pair.fromArray([LSymbol("letrec"),[[r.car,Pair(LSymbol("lambda"),Pair(t,r.cdr.cdr))]],Pair(r.car,u)])}else if(n){return}var c=this;u=this.get("list->array")(r.car);var s=c.inherit(m);var f,l;if(m==="let*"){l=s}else if(m==="let"){f=[]}var p=0;function d(){var e=new Pair(new LSymbol("begin"),r.cdr);return evaluate(e,{env:s,dynamic_scope:a,error:o})}return function r(){var n=u[p++];if(a){a=m==="let*"?s:c}if(!n){if(f&&f.length){var e=f.map(function(e){return e.value});var t=e.filter(isPromise);if(t.length){return Promise.all(e).then(function(e){for(var r=0,n=e.length;r1&&arguments[1]!==undefined$1?arguments[1]:{},n=r.dynamic_scope,t=r.error;var i=this;if(n){n=this}var a=e;var o=[];while(a instanceof Pair){o.push(evaluate(a.car,{env:i,dynamic_scope:n,error:t}));a=a.cdr}var u=o.filter(isPromise).length;if(u){return Promise.all(o).then(c.bind(this))}else{return c.call(this,o)}})}function guardMathCall(e){for(var r=arguments.length,n=new Array(r>1?r-1:0),t=1;t2?t-2:0),a=2;a1&&arguments[1]!==undefined$1?arguments[1]:null;return function(){for(var e=arguments.length,r=new Array(e),n=0;n1?e-1:0),n=1;n=o){return a.apply(this,t)}else{return i}}return i.apply(this,arguments)}}function limit(t,i){typecheck("limit",i,"function",2);return function(){for(var e=arguments.length,r=new Array(e),n=0;n1?t-1:0),a=1;a1){e=e.toLowerCase();if(LCharacter.__names__[e]){this.__name__=e;this.__char__=LCharacter.__names__[e]}else{throw new Error("Internal: Unknown named character")}}else{this.__char__=e;var r=LCharacter.__rev_names__[e];if(r){this.__name__=r}}}LCharacter.__names__=characters;LCharacter.__rev_names__={};Object.keys(LCharacter.__names__).forEach(function(e){var r=LCharacter.__names__[e];LCharacter.__rev_names__[r]=e});LCharacter.prototype.toUpperCase=function(){return LCharacter(this.__char__.toUpperCase())};LCharacter.prototype.toLowerCase=function(){return LCharacter(this.__char__.toLowerCase())};LCharacter.prototype.toString=function(){return"#\\"+(this.__name__||this.__char__)};LCharacter.prototype.valueOf=function(){return this.__char__};function LString(e){if(typeof this!=="undefined"&&!(this instanceof LString)||typeof this==="undefined"){return new LString(e)}if(e instanceof Array){this._string=e.map(function(e,r){typecheck("LString",e,"character",r+1);return e.toString()}).join("")}else{this._string=e.valueOf()}}{var ignore=["length","constructor"];var _keys=Object.getOwnPropertyNames(String.prototype).filter(function(e){return!ignore.includes(e)});var wrap=function e(t){return function(){for(var e=arguments.length,r=new Array(e),n=0;n0){n.push(this._string.substring(0,e))}n.push(r);if(e1&&arguments[1]!==undefined$1?arguments[1]:false;if(e instanceof LNumber){return e}if(typeof this!=="undefined"&&!(this instanceof LNumber)||typeof this==="undefined"){return new LNumber(e,r)}if(typeof e==="undefined"){throw new Error("Invalid LNumber constructor call")}var n=LNumber.getType(e);if(LNumber.types[n]){return LNumber.types[n](e,r)}var t=e instanceof Array&&LString.isString(e[0])&&LNumber.isNumber(e[1]);if(e instanceof LNumber){return LNumber(e.value)}if(!LNumber.isNumber(e)&&!t){throw new Error("You can't create LNumber from ".concat(type(e)))}if(e===null){e=0}var i;if(t){var a=e,o=slicedToArray(a,2),u=o[0],c=o[1];if(u instanceof LString){u=u.valueOf()}if(c instanceof LNumber){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(t){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=toConsumableArray(u).map(function(e,r){return BigInt(parseInt(e,c))*Math.pow(p,BigInt(r))}).reduce(function(e,r){return e+r})}else{i=BigInt(l+u)}}else{i=BigInt(e)}if(f){i*=BigInt(-1)}}else{i=e}return LBigInteger(i,true)}else if(typeof BN!=="undefined"&&!(e instanceof BN)){if(e instanceof Array){return LBigInteger(construct(BN,toConsumableArray(e)))}return LBigInteger(new BN(e))}else if(t){this.value=parseInt(u,c)}else{this.value=e}}LNumber.types={float:function e(r){var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;return new LFloat(r,n)},complex:function e(r){var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;if(!LNumber.isComplex(r)){r={im:0,re:r}}return new LComplex(r,n)},rational:function e(r){var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;if(!LNumber.isRational(r)){r={num:r,denom:1}}return new LRational(r,n)}};function LComplex(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof LComplex)||typeof this==="undefined"){return new LComplex(e,r)}if(e instanceof LComplex){return LComplex({im:e.im,re:e.re})}if(LNumber.isNumber(e)&&r){e={im:0,re:e.valueOf()}}else if(!LNumber.isComplex(e)){throw new Error("Invalid constructor call for LComplex")}var n=e.im instanceof LNumber?e.im:LNumber(e.im);var t=e.re instanceof LNumber?e.re:LNumber(e.re);if(n.cmp(0)===0&&!r){return t}this.im=n;this.re=t;this.__type__="complex"}LComplex.prototype=Object.create(LNumber.prototype);LComplex.prototype.constructor=LComplex;LComplex.prototype.toRational=function(e){if(LNumber.isFloat(this.im)&&LNumber.isFloat(this.re)){var r=LFloat(this.im).toRational(e);var n=LFloat(this.re).toRational(e);return LComplex({im:r,re:n})}return this};LComplex.prototype.add=function(e){return this.complex_op(e,function(e,r,n,t){return{re:e.add(r),im:n.add(t)}})};LComplex.prototype.factor=function(){if(this.im instanceof LFloat||this.im instanceof LFloat){var e=this.re,r=this.im;var n,t;if(e instanceof LFloat){n=e.toRational().mul(e.toRational())}else{n=e.mul(e)}if(r instanceof LFloat){t=r.toRational().mul(r.toRational())}else{t=r.mul(r)}return n.add(t)}else{return this.re.mul(this.re).add(this.im.mul(this.im))}};LComplex.prototype.modulus=function(){return this.factor().sqrt()};LComplex.prototype.sqrt=function(){var e=this.modulus();var r,n;if(e.cmp(0)===0){r=n=e}else if(this.re.cmp(0)===1){r=LFloat(.5).mul(e.add(this.re)).sqrt();n=this.im.div(r).div(2)}else{n=LFloat(.5).mul(e.sub(this.re)).sqrt();if(this.im.cmp(0)===-1){n=n.sub()}r=this.im.div(n).div(2)}return LComplex({im:n,re:r})};LComplex.prototype.div=function(e){if(LNumber.isNumber(e)&&!LNumber.isComplex(e)){e=LComplex({im:0,re:e})}else if(!LNumber.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var r=this.coerce(e),n=slicedToArray(r,2),t=n[0],i=n[1];var a=LComplex({re:i.re,im:i.im.sub()});var o=i.factor().valueOf();var u=t.mul(a);var c=u.re.op("/",o);var s=u.im.op("/",o);return LComplex({re:c,im:s})};LComplex.prototype.sub=function(e){return this.complex_op(e,function(e,r,n,t){return{re:e.sub(r),im:n.sum(t)}})};LComplex.prototype.mul=function(e){return this.complex_op(e,function(e,r,n,t){var i={re:e.mul(r).sub(n.mul(t)),im:e.mul(t).add(r.mul(n))};return i})};LComplex.prototype.complex_op=function(e,r){if(LNumber.isNumber(e)&&!LNumber.isComplex(e)){if(!(e instanceof LNumber)){e=LNumber(e)}var n=e.asType(0);e={im:n,re:e}}else if(!LNumber.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var t=e.re instanceof LNumber?e.re:this.re.asType(e.re);var i=e.im instanceof LNumber?e.im:this.im.asType(e.im);var a=r(this.re,t,this.im,i);if("im"in a&&"re"in a){var o=LComplex(a,true);return o}return a};LComplex._op={"+":"add","-":"sub","*":"mul","/":"div"};LComplex.prototype._op=function(e,r){var n=LComplex._op[e];return this[n](r)};LComplex.prototype.cmp=function(e){var r=this.coerce(e),n=slicedToArray(r,2),t=n[0],i=n[1];var a=t.re.coerce(i.re),o=slicedToArray(a,2),u=o[0],c=o[1];var s=u.cmp(c);if(s!==0){return s}else{var f=t.im.coerce(i.im),l=slicedToArray(f,2),p=l[0],d=l[1];return p.cmp(d)}};LComplex.prototype.valueOf=function(){};LComplex.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 LFloat(e){if(typeof this!=="undefined"&&!(this instanceof LFloat)||typeof this==="undefined"){return new LFloat(e)}if(!LNumber.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof LNumber){return LFloat(e.valueOf())}if(typeof e==="number"){this.value=e;this.__type__="float"}}LFloat.prototype=Object.create(LNumber.prototype);LFloat.prototype.constructor=LFloat;LFloat.prototype.toString=function(){var e=this.value.toString();if(!LNumber.isFloat(this.value)&&!e.match(/e/i)){return e+".0"}return e.replace(/^([0-9]+)e/,"$1.0e")};LFloat.prototype._op=function(e,r){if(r instanceof LNumber){r=r.value}var n=LNumber._ops[e];if(e==="/"&&this.value===0&&r===0){return NaN}return LFloat(n(this.value,r))};LFloat.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:null;if(e===null){return toRational(this.value.valueOf())}return approxRatio(e.valueOf())(this.value.valueOf())};var toRational=approxRatio(1e-10);function approxRatio(t){return function(e){var r=function e(t,r,n){var i=function e(r,n){return n0){i=simplest_rational2(t,n)}else if(t.cmp(n)<=0){i=n}else if(n.cmp(0)>0){i=simplest_rational2(n,t)}else if(r.cmp(0)<0){i=LNumber(simplest_rational2(t.sub(),n.sub())).sub()}else{i=LNumber(0)}if(LNumber.isFloat(r)||LNumber.isFloat(e)){return LFloat(i)}return i}function simplest_rational2(e,r){var n=LNumber(e).floor();var t=LNumber(r).floor();if(e.cmp(n)<1){return n}else if(n.cmp(t)===0){var i=LNumber(1).div(r.sub(t));var a=LNumber(1).div(e.sub(n));return n.add(LNumber(1).div(simplest_rational2(i,a)))}else{return n.add(LNumber(1))}}function LRational(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof LRational)||typeof this==="undefined"){return new LRational(e,r)}if(!LNumber.isRational(e)){throw new Error("Invalid constructor call for LRational")}var n=LNumber(e.num);var t=LNumber(e.denom);if(!r&&t.cmp(0)!==0){var i=n.op("%",t).cmp(0)===0;if(i){return LNumber(n.div(t))}}this.num=n;this.denom=t;this.__type__="rational"}LRational.prototype=Object.create(LNumber.prototype);LRational.prototype.constructor=LRational;LRational.prototype.pow=function(e){var r=e.cmp(0);if(r===0){return LNumber(1)}if(r===-1){e=e.sub();var n=this.denom.pow(e);var t=this.num.pow(e);return LRational({num:n,denom:t})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};LRational.prototype.sqrt=function(){var e=this.num.sqrt();var r=this.denom.sqrt();if(e instanceof LFloat){e=(readOnlyError("num"),e.toRational())}if(r instanceof LFloat){r=(readOnlyError("denom"),r.toRational())}return LRational({num:e,denom:r})};LRational.prototype.abs=function(){var e=this.num;var r=this.denom;if(e.cmp(0)===-1){e=e.sub()}if(r.cmp(0)!==1){r=r.sub()}return LRational({num:e,denom:r})};LRational.prototype.cmp=function(e){return LNumber(this.valueOf(),true).cmp(e)};LRational.prototype.toString=function(){var e=this.num.gcd(this.denom);var r,n;if(e.cmp(1)!==0){r=this.num.div(e);if(r instanceof LRational){r=LNumber(r.valueOf(true))}n=this.denom.div(e);if(n instanceof LRational){n=LNumber(n.valueOf(true))}}else{r=this.num;n=this.denom}var t=this.cmp(0)<0;if(t){if(r.abs().cmp(n.abs())===0){return r.toString()}}else if(r.cmp(n)===0){return r.toString()}return r.toString()+"/"+n.toString()};LRational.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 LNumber._ops["/"](this.num.value,this.denom.value)}return LFloat(this.num.valueOf()).div(this.denom.valueOf())};LRational.prototype.mul=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=this.num.mul(e.num);var n=this.denom.mul(e.denom);return LRational({num:r,denom:n})}var t=LNumber.coerce(this,e),i=slicedToArray(t,2),a=i[0],o=i[1];return a.mul(o)};LRational.prototype.div=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=this.num.mul(e.denom);var n=this.denom.mul(e.num);return LRational({num:r,denom:n})}var t=LNumber.coerce(this,e),i=slicedToArray(t,2),a=i[0],o=i[1];var u=a.div(o);return u};LRational.prototype._op=function(e,r){return this[rev_mapping[e]](r)};LRational.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=e.num.sub();var n=e.denom;return this.add(LRational({num:r,denom:n}))}if(!(e instanceof LNumber)){e=LNumber(e).sub()}else{e=e.sub()}var t=LNumber.coerce(this,e),i=slicedToArray(t,2),a=i[0],o=i[1];return a.add(o)};LRational.prototype.add=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=this.denom;var n=e.denom;var t=this.num;var i=e.num;var a,o;if(r!==n){o=n.mul(t).add(i.mul(r));a=r.mul(n)}else{o=t.add(i);a=r}return LRational({num:o,denom:a})}if(LNumber.isFloat(e)){return LFloat(this.valueOf()).add(e)}var u=LNumber.coerce(this,e),c=slicedToArray(u,2),s=c[0],f=c[1];return s.add(f)};function LBigInteger(e,r){if(typeof this!=="undefined"&&!(this instanceof LBigInteger)||typeof this==="undefined"){return new LBigInteger(e,r)}if(e instanceof LBigInteger){return LBigInteger(e.value,e._native)}if(!LNumber.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.value=e;this._native=r;this.__type__="bigint"}LBigInteger.prototype=Object.create(LNumber.prototype);LBigInteger.prototype.constructor=LBigInteger;LBigInteger.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};LBigInteger.prototype._op=function(e,r){if(typeof r==="undefined"){if(LNumber.isBN(this.value)){e=LBigInteger.bn_op[e];return LBigInteger(this.value.clone()[e](),false)}return LBigInteger(LNumber._ops[e](this.value),true)}if(LNumber.isBN(this.value)&&LNumber.isBN(r.value)){e=LBigInteger.bn_op[e];return LBigInteger(this.value.clone()[e](r),false)}var n=LNumber._ops[e](this.value,r.value);if(e==="/"){var t=this.op("%",r).cmp(0)===0;if(t){return LNumber(n)}return LRational({num:this,denom:r})}return LBigInteger(n,true)};LBigInteger.prototype.sqrt=function(){var e;var r=this.cmp(0)<0;if(LNumber.isNative(this.value)){e=LNumber(Math.sqrt(r?-this.valueOf():this.valueOf()))}else if(LNumber.isBN(this.value)){e=r?this.value.neg().sqrt():this.value.sqrt()}if(r){return LComplex({re:0,im:e})}return e};LNumber.prototype.gcd=function(e){var r=this.abs();e=e.abs();if(e.cmp(r)===1){var n=r;r=e;e=n}while(true){r=r.rem(e);if(r.cmp(0)===0){return e}e=e.rem(r);if(e.cmp(0)===0){return r}}};LNumber.isFloat=function e(r){return r instanceof LFloat||Number(r)===r&&r%1!==0};LNumber.isNumber=function(e){return e instanceof LNumber||!Number.isNaN(e)&&LNumber.isNative(e)||LNumber.isBN(e)};LNumber.isComplex=function(e){var r=e instanceof LComplex||LNumber.isNumber(e.im)&&LNumber.isNumber(e.re);return r};LNumber.isRational=function(e){return e instanceof LRational||LNumber.isNumber(e.num)&&LNumber.isNumber(e.denom)};LNumber.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};LNumber.isBigInteger=function(e){return e instanceof LBigInteger||typeof e==="bigint"||LNumber.isBN(e)};LNumber.isBN=function(e){return typeof BN!=="undefined"&&e instanceof BN};LNumber.getArgsType=function(e,r){if(e instanceof LFloat||r instanceof LFloat){return LFloat}if(e instanceof LBigInteger||r instanceof LBigInteger){return LBigInteger}return LNumber};LNumber.prototype.toString=LNumber.prototype.toJSON=function(e){if(e>2&&e<36){return this.value.toString(e)}return this.value.toString()};LNumber.prototype.asType=function(e){var r=LNumber.getType(this);return LNumber.types[r]?LNumber.types[r](e):LNumber(e)};LNumber.prototype.isBigNumber=function(){return typeof this.value==="bigint"||typeof BN!=="undefined"&&!(this.value instanceof BN)};["floor","ceil","round"].forEach(function(e){LNumber.prototype[e]=function(){if(this["float"]||LNumber.isFloat(this.value)){return LNumber(Math[e](this.value))}else{return LNumber(Math[e](this.valueOf()))}}});LNumber.prototype.valueOf=function(){if(LNumber.isNative(this.value)){return Number(this.value)}else if(LNumber.isBN(this.value)){return this.value.toNumber()}};var matrix=function(){var e=function e(r,n){return[r,n]};return{bigint:{bigint:e,float:function e(r,n){return[LFloat(r.valueOf()),n]},rational:function e(r,n){return[{num:r,denom:1},n]},complex:function e(r,n){return[{im:0,re:r},n]}},float:{bigint:function e(r,n){return[r,n&&LFloat(n.valueOf())]},float:e,rational:function e(r,n){return[r,n&&LFloat(n.valueOf())]},complex:function e(r,n){return[{re:r,im:LFloat(0)},n]}},complex:{bigint:r("bigint"),float:r("float"),rational:r("rational"),complex:function e(r,n){var t=LNumber.coerce(r.re,n.re),i=slicedToArray(t,2),a=i[0],o=i[1];var u=LNumber.coerce(r.im,n.im),c=slicedToArray(u,2),s=c[0],f=c[1];return[{im:s,re:a},{im:f,re:o}]}},rational:{bigint:function e(r,n){return[r,n&&{num:n,denom:1}]},float:function e(r,n){return[LFloat(r.valueOf()),n]},rational:e,complex:function e(r,n){return[{im:coerce(r.__type__,n.im.__type__,0),re:coerce(r.__type__,n.re.__type__,r)},{im:coerce(r.__type__,n.im.__type__,n.im),re:coerce(r.__type__,n.re.__type__,n.re)}]}}};function r(n){return function(e,r){return[{im:coerce(n,e.im.__type__,e.im),re:coerce(n,e.re.__type__,e.re)},{im:coerce(n,e.im.__type__,0),re:coerce(n,r.__type__,r)}]}}}();function coerce(e,r,n){return matrix[e][r](n)[0]}LNumber.coerce=function(e,r){function n(e){if(e==="integer"){return"bigint"}return e}var t=n(LNumber.getType(e));var i=n(LNumber.getType(r));if(!matrix[t]){throw new Error("LNumber::coerce unknown lhs type ".concat(t))}else if(!matrix[t][i]){throw new Error("LNumber::coerce unknown rhs type ".concat(i))}return matrix[t][i](e,r).map(function(e){return LNumber(e,true)})};LNumber.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof LNumber)){throw new Error("LNumber: you can't coerce ".concat(type(e)))}if(typeof e==="number"){e=LNumber(e)}return LNumber.coerce(this,e)};LNumber.getType=function(e){if(e instanceof LNumber){return e.__type__}if(LNumber.isFloat(e)){return"float"}if(LNumber.isComplex(e)){return"complex"}if(LNumber.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof BN!=="undefined"&&!(e instanceof BN)){return"bigint"}};LNumber.prototype.isFloat=function(){return!!(LNumber.isFloat(this.value)||this["float"])};var mapping={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var rev_mapping={};Object.keys(mapping).forEach(function(r){rev_mapping[mapping[r]]=r;LNumber.prototype[r]=function(e){return this.op(mapping[r],e)}});LNumber._ops={"*":function e(r,n){return r*n},"+":function e(r,n){return r+n},"-":function e(r,n){if(typeof n==="undefined"){return-r}return r-n},"/":function e(r,n){return r/n},"%":function e(r,n){return r%n},"|":function e(r,n){return r|n},"&":function e(r,n){return r&n},"~":function e(r){return~r},">>":function e(r,n){return r>>n},"<<":function e(r,n){return r<=this._string.length){return eof}return LCharacter(this._string[this._in_char])};function OutputPort(e){if(typeof this!=="undefined"&&!(this instanceof OutputPort)||typeof this==="undefined"){return new OutputPort(e)}typecheck("OutputPort",e,"function");this.write=e}OutputPort.prototype.toString=function(){return"#"};function OutputStringPort(r){var n=this;if(typeof this!=="undefined"&&!(this instanceof OutputStringPort)||typeof this==="undefined"){return new OutputStringPort(r)}typecheck("OutputStringPort",r,"function");this._buffer=[];this.write=function(e){if(!LString.isString(e)){e=r(e)}else{e=e.valueOf()}n._buffer.push(e)}}OutputStringPort.prototype=Object.create(OutputPort.prototype);OutputStringPort.prototype.getString=function(){return this._buffer.map(function(e){return e.valueOf()}).join("")};OutputStringPort.prototype.constructor=OutputStringPort;function InputStringPort(e){var r=this;if(typeof this!=="undefined"&&!(this instanceof InputStringPort)||typeof this==="undefined"){return new InputStringPort(e)}typecheck("InputStringPort",e,"string");this._string=e.valueOf();this._index=0;this._in_char=0;this.read=function(){return r.get_next_tokens()}}InputStringPort.prototype=Object.create(InputPort.prototype);InputStringPort.prototype.constructor=InputStringPort;InputStringPort.prototype.read_line=function(){var e=this._string.substring(this._in_char);if(!e){return eof}var r=e.match(/([^\n])(?:\n|$)/)[0];this._in_char+=r.length;return r};var eof=new EOF;function EOF(){}EOF.prototype.toString=function(){return"#"};function Interpreter(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{};if(typeof this!=="undefined"&&!(this instanceof Interpreter)||typeof this==="undefined"){return new Interpreter(e,r)}if(typeof e==="undefined"){e="anonymous"}this.__env__=user_env.inherit(e,r);var n="**interaction-environment-defaults**";this.__env__.set(n,get_props(r).concat(n))}Interpreter.prototype.exec=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;var n=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:null;typecheck("Intepreter::exec",e,"string",1);typecheck("Intepreter::exec",r,"boolean",2);global_env.set("**interaction-environment**",this.__env__);if(n===null){n=this.__env__}return exec(e,n,r?n:false)};Interpreter.prototype.get=function(e){var r=this.__env__.get(e);if(typeof r==="function"){return r.bind(this.__env__)}return r};Interpreter.prototype.set=function(e,r){return this.__env__.set(e,r)};function Environment(e,r,n){if(arguments.length===1){if(_typeof_1(arguments[0])==="object"){e=arguments[0];r=null}else if(typeof arguments[0]==="string"){e={};r={};n=arguments[0]}}this.__docs__=new Map;this.__env__=e;this.__parent__=r;this.__name__=n||"anonymous"}Environment.prototype.list=function(){return get_props(this.__env__)};Environment.prototype.unset=function(e){if(e instanceof LSymbol){e=e.valueOf()}if(e instanceof LString){e=e.valueOf()}delete this.__env__[e]};Environment.prototype.inherit=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{};if(_typeof_1(e)==="object"){r=e}if(!e||_typeof_1(e)==="object"){e="child of "+(this.__name__||"unknown")}return new Environment(r||{},this,e)};Environment.prototype.doc=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:null;if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}if(r){this.__docs__.set(e,r);return this}if(this.__docs__.has(e)){return this.__docs__.get(e)}if(this.__parent__){return this.__parent__.doc(e)}};Environment.prototype.newFrame=function(e,r){var t=this.inherit("__frame__");t.set("parent.frame",doc("parent.frame",function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:1;e=e.valueOf();var r=t.__parent__;if(!(r instanceof Environment)){return nil}if(e<=0){return r}var n=r.get("parent.frame");return n(e-1)},global_env.__env__["parent.frame"].__doc__));r.callee=e;t.set("arguments",r);return t};Environment.prototype._lookup=function(e){if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}if(this.__env__.hasOwnProperty(e)){return Value(this.__env__[e])}if(this.__parent__){return this.__parent__._lookup(e)}};Environment.prototype.toString=function(){return"#"};Environment.prototype.clone=function(){var r=this;var n={};Object.keys(this.__env__).forEach(function(e){n[e]=r.__env__[e]});return new Environment(n,this.__parent__,this.__name__)};Environment.prototype.merge=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:"merge";typecheck("Environment::merge",e,"environment");return this.inherit(r,e.__env__)};function Value(e){if(typeof this!=="undefined"&&!(this instanceof Value)||typeof this==="undefined"){return new Value(e)}this.value=e}Value.isUndefined=function(e){return e instanceof Value&&typeof e.value==="undefined"};Value.prototype.valueOf=function(){return this.value};function Values(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof Values)||typeof this==="undefined"){return new Values(e)}this.__values__=e}Values.prototype.toString=function(){return this.__values__.map(function(e){return toString(e)}).join("\n")};Values.prototype.valueOf=function(){return this.__values__};Environment.prototype.get=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{};var n=r.throwError,t=n===void 0?true:n;var i=e;if(i instanceof LSymbol||i instanceof LString){i=i.valueOf()}var a=this._lookup(i);if(a instanceof Value){if(Value.isUndefined(a)){return undefined$1}return patchValue(a.valueOf())}if(typeof i==="string"){var o=i.split(".").filter(Boolean);if(o.length>0){var u=toArray(o),c=u[0],s=u.slice(1);a=this._lookup(c);if(s.length){try{if(a instanceof Value){a=a.valueOf()}else{a=get(root,c);if(typeof a==="function"){a=unbind(a)}}return get.apply(void 0,[a].concat(toConsumableArray(s)))}catch(e){}}else if(a instanceof Value){return patchValue(a.valueOf())}}a=get(root,i)}if(typeof a!=="undefined"){return a}if(t){throw new Error("Unbound variable `"+i.toString()+"'")}};Environment.prototype.set=function(e,r){var n=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:null;if(LNumber.isNumber(r)){r=LNumber(r)}if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}this.__env__[e]=r;if(n){this.doc(e,n)}return this};Environment.prototype.has=function(e){return this.__env__.hasOwnProperty(e)};Environment.prototype.ref=function(e){var r=this;while(true){if(!r){break}if(r.has(e)){return r}r=r.__parent__}};Environment.prototype.parents=function(){var e=this;var r=[];while(e){r.unshift(e);e=e.__parent__}return r};function quote(e){if(isPromise(e)){return e.then(quote)}if(e instanceof Pair||e instanceof LSymbol){e.data=true}return e}var global_env=new Environment({nil:nil,undefined:undefined$1,true:true,false:false,null:null,NaN:NaN,stdout:new OutputPort(function(){var e;(e=console).log.apply(e,arguments)}),stdin:InputPort(function(){return new Promise(function(e){e(prompt(""))})}),"open-input-string":doc("open-input-string",function(e){typecheck("open-input-string",e,"string");return InputStringPort(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?":doc("output-port?",function(e){return e instanceof OutputPort},"(output-port? arg)\n\n Function return true if argument is output port."),"input-port?":doc("input-port?",function(e){return e instanceof InputPort},"(input-port? arg)\n\n Function return true if argument is input port."),"open-output-string":doc("open-output-string",function(){return OutputStringPort(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":doc("get-output-string",function(e){typecheck("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?":doc("eof-object?",function(e){return e===eof},"(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":doc("peek-char",function(e){typecheck("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":doc("read-line",function(e){if(typeof e==="undefined"){e=this.get("stdin")}typecheck("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":doc("read-char",function(e){if(typeof e==="undefined"){e=this.get("stdin")}typecheck("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:doc(function(){var r=asyncToGenerator(regenerator.mark(function e(n){var t,i;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!LString.isString(n)){r.next=4;break}r.next=3;return parse(n,this);case 3:return r.abrupt("return",r.sent[0]);case 4:if(n instanceof InputPort){t=n}else{t=this.get("stdin")}r.next=7;return t.read();case 7:i=r.sent;console.log(i);if(!(i===eof)){r.next=11;break}return r.abrupt("return",eof);case 11:r.next=13;return parse(i,this);case 13:return r.abrupt("return",r.sent[0]);case 14:case"end":return r.stop()}}},e,this)}));function e(e){return r.apply(this,arguments)}return e}(),"(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:doc(function e(r){if(r instanceof Pair){r=new lips.Formatter(r.toString(true))["break"]().format();this.get("display").call(this,r)}else{this.get("write").call(this,r)}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:doc(function e(){var r=this;var n=this.get("display");var t=this.get("newline");for(var i=arguments.length,a=new Array(i),o=0;o1?n-1:0),i=1;it.length){throw new Error("Not enough arguments")}var u=0;var c=this.get("repr");r=r.replace(a,function(e){var r=e[1];if(r==="~"){return"~"}else if(r==="%"){return"\n"}else{var n=t[u++];if(r==="a"){return c(n)}else{return c(n,true)}}});o=r.match(/~([\S])/);if(o){throw new Error("format: Unrecognized escape seqence ".concat(o[1]))}return r},"(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:doc(function e(r){var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:null;if(n===null){n=this.get("stdout")}var t=this.get("repr")(r);n.write.call(this,t)},"(display arg [port])\n\n Function send string to standard output or provied port."),error:doc(function e(){for(var r=arguments.length,n=new Array(r),t=0;t1&&arguments[1]!==undefined$1?arguments[1]:{},n=r.dynamic_scope,t=r.error;if(n){n=this}var i=this;var o;var u=evaluate(e.cdr.car,{env:this,dynamic_scope:n,error:t});u=resolvePromises(u);function c(r,n,t){if(isPromise(r)){return r.then(function(e){return c(r,e,t)})}if(isPromise(n)){return n.then(function(e){return c(r,e,t)})}if(isPromise(t)){return t.then(function(e){return c(r,n,e)})}i.get("set-obj!").call(i,r,n,t);return t}if(e.car instanceof Pair&&LSymbol.is(e.car.car,".")){var s=e.car.cdr.car;var f=e.car.cdr.cdr.car;var l=evaluate(s,{env:this,dynamic_scope:n,error:t});var p=evaluate(f,{env:this,dynamic_scope:n,error:t});return c(l,p,u)}if(!(e.car instanceof LSymbol)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var d=e.car.valueOf();o=this.ref(e.car.__name__);return unpromise(u,function(e){if(!o){var r=d.split(".");if(r.length>1){var n=r.pop();var t=r.join(".");var i=a.get(t,{throwError:false});if(i){c(i,n,e);return}}throw new Error("Unbound variable `"+d+"'")}o.set(d,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!":doc(new Macro("set!",function(e){if(!(e.car instanceof LSymbol)){throw new Error("unset! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var r=e.car;var n=this.ref(r);if(n){delete n.__env__[r.__name__]}}),"(unset! name)\n\n Function delete specified name from environment."),"set-car!":doc("set-car!",function(e,r){typecheck("set-car!",e,"pair");e.car=r},"(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!":doc("set-cdr!",function(e,r){typecheck("set-cdr!",e,"pair");e.cdr=r},"(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?":doc("empty?",function(e){return typeof e==="undefined"||e===nil},"(empty? object)\n\n Function return true if value is undfined empty list."),gensym:doc("gensym",gensym,"(gensym)\n\n Function generate unique symbol, to use with macros as meta name."),load:doc(function e(r){typecheck("load",r,"string");var n=this;if(n.__name__==="__frame__"){n=n.__parent__}var i;if(n===global_env){i=n}else{i=this.get("**interaction-environment**")}var a="**module-path**";var o=global_env.get(a,{throwError:false});r=r.valueOf();if(!r.match(/.[^.]+$/)){r+=".scm"}if(typeof this.get("global",{throwError:false})!=="undefined"){return new Promise(function(n,t){var e=nodeRequire("path");if(o){o=o.valueOf();r=e.join(o,r)}global_env.set(a,e.dirname(r));nodeRequire("fs").readFile(r,function(e,r){if(e){console.log(e);t(e);global_env.set(a,o)}else{exec(r.toString(),i).then(function(){n();global_env.set(a,o)})["catch"](t)}})})}if(o){o=o.valueOf();r=o+"/"+r.replace(/^\.?\/?/,"")}return root.fetch(r).then(function(e){return e.text()}).then(function(e){global_env.set(a,r.replace(/\/[^/]*$/,""));return exec(e,i)}).then(function(){})["finally"](function(){global_env.set(a,o)})},"(load filename)\n\n Function fetch the file and evaluate its content as LIPS code."),do:doc(new Macro("do",function(){var n=asyncToGenerator(regenerator.mark(function e(n,t){var i,a,o,u,c,s,f,l,p,d,m;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:i=t.dynamic_scope,a=t.error;o=this;if(i){i=o}u=o.inherit("do");c=n.car;s=n.cdr.car;f=n.cdr.cdr;if(f!==nil){f=new Pair(LSymbol("begin"),f)}l={env:o,dynamic_scope:i,error:a};p=c;case 10:if(!(p!==nil)){r.next=21;break}d=p.car;r.t0=u;r.t1=d.car;r.next=16;return evaluate(d.cdr.car,l);case 16:r.t2=r.sent;r.t0.set.call(r.t0,r.t1,r.t2);p=p.cdr;r.next=10;break;case 21:l={env:u,dynamic_scope:i,error:a};m=regenerator.mark(function e(){var n,t,i,a,o;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!(f!==nil)){r.next=3;break}r.next=3;return lips.evaluate(f,l);case 3:n=c;t={};case 5:if(!(n!==nil)){r.next=15;break}i=n.car;if(!(i.cdr.cdr!==nil)){r.next=12;break}r.next=10;return evaluate(i.cdr.cdr.car,l);case 10:a=r.sent;t[i.car.valueOf()]=a;case 12:n=n.cdr;r.next=5;break;case 15:o=Object.getOwnPropertySymbols(t);Object.keys(t).concat(o).forEach(function(e){u.set(e,t[e])});case 17:case"end":return r.stop()}}},e)});case 23:r.next=25;return evaluate(s.car,l);case 25:if(r.sent){r.next=29;break}return r.delegateYield(m(),"t3",27);case 27:r.next=23;break;case 29:if(!(s.cdr!==nil)){r.next=33;break}r.next=32;return evaluate(s.cdr.car,l);case 32:return r.abrupt("return",r.sent);case 33:case"end":return r.stop()}}},e,this)}));return function(e,r){return n.apply(this,arguments)}}()),"(do (( )) (test expression) . body)\n\n Iteration macro that evaluate the expression body in scope of the variables.\n On Eeach loop it increase the variables according to next expression and run\n test to check if the loop should continue. If test is signle call the macro\n will not return anything. If the test is pair of expression and value the\n macro will return that value after finish."),if:doc(new Macro("if",function(n,e){var t=e.dynamic_scope,i=e.error;if(t){t=this}var a=this;var r=function e(r){if(r){return evaluate(n.cdr.car,{env:a,dynamic_scope:t,error:i})}else{return evaluate(n.cdr.cdr.car,{env:a,dynamic_scope:t,error:i})}};if(n===nil){throw new Error("too few expressions for `if`")}var o=evaluate(n.car,{env:a,dynamic_scope:t,error:i});return unpromise(o,r)}),"(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 Macro("let-env",function(r){var e=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{};var n=e.dynamic_scope,t=e.error;typecheck("let-env",r,"pair");var i=evaluate(r.car,{env:this,dynamic_scope:n,error:t});return unpromise(i,function(e){if(!(e instanceof Environment)){throw new Error("let-env: First argument need to be "+"environment")}return evaluate(Pair(LSymbol("begin"),r.cdr),{env:e,dynamic_scope:n,error:t})})},"(let-env env . body)\n\n Special macro that evaluate body in context of given environment\n object."),letrec:doc(let_macro(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*":doc(let_macro(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:doc(let_macro(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*":doc(pararel("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:doc(new Macro("begin",function(e,r){var t=Object.assign({},r);var i=this.get("list->array")(e);if(t.dynamic_scope){t.dynamic_scope=this}t.env=this;var a;return function r(){if(i.length){var e=i.shift();var n=evaluate(e,t);return unpromise(n,function(e){a=e;return r()})}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 Macro("ignore",function(e,r){var n=r.dynamic_scope,t=r.error;var i={env:this,error:t};if(n){i.dynamic_scope=this}evaluate(new Pair(new LSymbol("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:doc(Macro.defmacro("define",function(n,e){var t=this;if(n.car instanceof Pair&&n.car.car instanceof LSymbol){var r=new Pair(new LSymbol("define"),new Pair(n.car.car,new Pair(new Pair(new LSymbol("lambda"),new Pair(n.car.cdr,n.cdr)))));return r}else if(e.macro_expand){return}if(e.dynamic_scope){e.dynamic_scope=this}e.env=t;var i=n.cdr.car;var a;if(i instanceof Pair){i=evaluate(i,e);a=true}else if(i instanceof LSymbol){i=t.get(i)}typecheck("define",n.car,"symbol");return unpromise(i,function(e){if(t.__name__===Syntax.__merge_env__){t=t.__parent__}if(a&&(typeof e==="function"&&e.__lambda__||e instanceof Syntax)){e.__name__=n.car.valueOf();if(e.__name__ instanceof LString){e.__name__=e.__name__.valueOf()}}var r;if(n.cdr.cdr instanceof Pair&&LString.isString(n.cdr.cdr.car)){r=n.cdr.cdr.car.valueOf()}t.set(n.car,e,r)})}),"(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!":doc("set-obj!",function(e,r,n){var t=_typeof_1(e);if(isNull(e)||t!=="object"&&t!=="function"){var i=typeErrorMessage("set-obj!",type(e),["object","function"]);throw new Error(i)}e=unbind(e);r=r.valueOf();if(arguments.length===2){delete e[r]}else if(is_prototype(e)&&typeof n==="function"){e[r]=unbind(n);e[r].__prototype__=true}else if(typeof n==="function"||is_native(n)){e[r]=n}else{e[r]=n?n.valueOf():n}},"(set-obj! obj key value)\n\n Function set property of JavaScript object"),"null-environment":doc("null-environment",function(){return global_env.inherit("null")},"(null-environment)\n\n Function return new base environment with std lib."),values:doc(function e(){for(var r=arguments.length,n=new Array(r),t=0;t1&&arguments[1]!==undefined$1?arguments[1]:{},p=e.dynamic_scope,d=e.error;var m=this;var h;if(l.cdr instanceof Pair&&LString.isString(l.cdr.car)&&l.cdr.cdr!==nil){h=l.cdr.car.valueOf()}function v(){var e;if(p){if(!(this instanceof Environment)){e=m}else{e=this}}else{e=m}e=e.inherit("lambda");var r=l.car;var n=0;var t;if(typeof this!=="undefined"){e.set("this",this)}for(var i=arguments.length,a=new Array(i),o=0;o2&&arguments[2]!==undefined$1?arguments[2]:a;if(e instanceof Pair){var t=e.car;var i=e.cdr;if(n(t)){t=r(t)}if(n(i)){i=r(i)}if(isPromise(t)||isPromise(i)){return Promise.all([t,i]).then(function(e){var r=slicedToArray(e,2),n=r[0],t=r[1];return new Pair(n,t)})}else{return new Pair(t,i)}}return e}function o(e,r){if(e instanceof Pair){if(r!==nil){e.append(r)}}else{e=new Pair(e,r)}return e}function l(i,e,r){if(e1){var r="You can't splice multiple atoms inside list";throw new Error(r)}if(!(i.cdr instanceof Pair&&n[0]===nil)){return n[0]}}n=n.map(function(e){if(p.has(e)){return e.clone()}else{p.add(e);return e}});var t=d(i.cdr,0,1);if(t===nil&&n[0]===nil){return undefined$1}return unpromise(t,function(e){if(n[0]===nil){return e}if(n.length===1){return o(n[0],e)}var r=n.reduce(function(e,r){return o(e,r)});return o(r,e)})})}(i.car.cdr)}var p=new Set;function d(e,r,n){if(e instanceof Pair){if(LSymbol.is(e.car.car,"unquote-splicing")){return l(e,r+1,n)}if(LSymbol.is(e.car,"quasiquote")){var t=d(e.cdr,r,n+1);return new Pair(e.car,t)}if(LSymbol.is(e.car.car,"unquote")){if(r+2===n&&e.car.cdr instanceof Pair&&e.car.cdr.car instanceof Pair&&LSymbol.is(e.car.cdr.car.car,"unquote-splicing")){var i=e.car.cdr;return new Pair(new Pair(new LSymbol("unquote"),l(i,r+2,n)),nil)}else if(e.car.cdr instanceof Pair&&e.car.cdr.cdr!==nil){if(e.car.cdr.car instanceof Pair){var a=[];return function r(n){if(n===nil){return Pair.fromArray(a)}return unpromise(evaluate(n.car,{env:s,dynamic_scope:u,error:c}),function(e){a.push(e);return r(n.cdr)})}(e.car.cdr)}else{return e.car.cdr}}}if(LSymbol.is(e.car,"quote")){return new Pair(e.car,d(e.cdr,r,n))}if(LSymbol.is(e.car,"unquote")){r++;if(rn){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(e.cdr instanceof Pair){if(e.cdr.cdr!==nil){if(e.cdr.car instanceof Pair){var o=[];return function r(n){if(n===nil){return Pair.fromArray(o)}return unpromise(evaluate(n.car,{env:s,dynamic_scope:u,error:c}),function(e){o.push(e);return r(n.cdr)})}(e.cdr)}else{return e.cdr}}else{return evaluate(e.cdr.car,{env:s,dynamic_scope:u,error:c})}}else{return e.cdr}}return f(e,function(e){return d(e,r,n)})}return e}function n(e){if(e instanceof Pair){delete e.data;if(!e.haveCycles("car")){n(e.car)}if(!e.haveCycles("cdr")){n(e.cdr)}}}var t=d(e.car,0,1);return unpromise(t,function(e){n(e);return quote(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:doc(function e(r){typecheck("clone",r,"pair");return r.clone()},"(clone list)\n\n Function return clone of the list."),append:doc(function e(r,n){typecheck("append",r,["nil","pair"]);if(r instanceof Pair){r=r.clone()}return this.get("append!").call(this,r,n)},"(append list item)\n\n Function will create new list with value appended to the end. It return\n New list."),"append!":doc("append!",function(e,r){typecheck("append!",e,["pair","nil"]);if(!this.get("list?")(e)){throw new Error("append!: Invalid argument, value is not a list")}if(isNull(r)){return e}if(e===nil){if(r===nil){return nil}return r}return e.append(r)},"(append! name expression)\n\n Destructive version of append, it modify the list in place. It return\n original list."),reverse:doc(function e(r){typecheck("reverse",r,["array","pair","nil"]);if(r===nil){return nil}if(r instanceof Pair){var n=this.get("list->array")(r).reverse();return this.get("array->list")(n)}else if(!(r instanceof Array)){throw new Error(typeErrorMessage("reverse",type(r),"array or pair"))}else{return r.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:doc(function e(r,n){typecheck("nth",r,"number");typecheck("nth",n,["array","pair"]);if(n instanceof Pair){var t=n;var i=0;while(iarray")(n).join(r)},"(join separator list)\n\n Function return string by joining elements of the list"),split:doc(function e(r,n){typecheck("split",r,["regex","string"]);typecheck("split",n,"string");return this.get("array->list")(n.split(r))},"(split separator string)\n\n Function create list by splitting string by separatar that can\n be a string or regular expression."),replace:doc(function e(r,n,t){typecheck("replace",r,["regex","string"]);typecheck("replace",n,["string","function"]);typecheck("replace",t,"string");return t.replace(r,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:doc(function e(r,n){typecheck("match",r,["regex","string"]);typecheck("match",n,"string");var t=n.match(r);return t?this.get("array->list")(t):nil},"(match pattern string)\n\n function return match object from JavaScript as list."),search:doc(function e(r,n){typecheck("search",r,["regex","string"]);typecheck("search",n,"string");return n.search(r)},"(search pattern string)\n\n Function return first found index of the pattern inside a string"),repr:doc(function e(r,n){return toString(r,n)},"(repr obj)\n\n Function return string LIPS representation of an object as string."),env:doc(function e(e){e=e||this;var r=Object.keys(e.__env__);var n;if(r.length){n=Pair.fromArray(r)}else{n=nil}if(e.__parent__!==undefined$1){return this.get("env").call(this,e.__parent__).append(n)}return n},"(env obj)\n\n Function return list values (functions and variables) inside environment."),new:doc("new",function(e){for(var r=arguments.length,n=new Array(r>1?r-1:0),t=1;t2&&arguments[2]!==undefined$1?arguments[2]:specials.LITERAL;typecheck("set-special!",e,"string",1);typecheck("set-special!",r,"symbol",2);lips.specials.append(e.valueOf(),r,n)},'(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:get,".":get,unbind:doc(unbind,"(unbind fn)\n\n Function remove bidning from function so you can get props from it."),type:doc(type,"(type object)\n\n Function return type of an object as string."),debugger:doc("debugger",function(){debugger},"(debugger)\n\n Function stop JavaScript code in debugger."),in:doc("in",function(e,r){if(e instanceof LSymbol||e instanceof LString){e=e.valueOf()}return e in r},"(in key value)\n\n Function use is in operator to check if value is in object."),instanceof:doc("instanceof",function(e,r){return r instanceof unbind(e)},"(instanceof type obj)\n\n Function check of object is instance of object."),"prototype?":doc("prototype?",is_prototype,"(prototype? obj)\n\n Function check if value is JavaScript Object prototype."),"macro?":doc("macro?",function(e){return e instanceof Macro},"(macro? expression)\n\n Function check if value is a macro."),"function?":doc("function?",function(e){return typeof e==="function"},"(function? expression)\n\n Function check if value is a function."),"real?":doc("real?",function(e){if(type(e)!=="number"){return false}if(e instanceof LNumber){return e.isFloat()}return LNumber.isFloat(e)},"(real? number)\n\n Function check if value is real number."),"number?":doc("number?",LNumber.isNumber,"(number? expression)\n\n Function check if value is a number"),"string?":doc("string?",function(e){return LString.isString(e)},"(string? expression)\n\n Function check if value is a string."),"pair?":doc("pair?",function(e){return e instanceof Pair},"(pair? expression)\n\n Function check if value is a pair or list structure."),"regex?":doc(function(e){return e instanceof RegExp},"(regex? expression)\n\n Function check if value is regular expression."),"null?":doc("null?",function(e){return isNull(e)},"(null? expression)\n\n Function check if value is nulish."),"boolean?":doc("boolean?",function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Function check if value is boolean."),"symbol?":doc("symbol?",function(e){return e instanceof LSymbol},"(symbol? expression)\n\n Function check if value is LIPS symbol"),"array?":doc("array?",function(e){return e instanceof Array},"(array? expression)\n\n Function check if value is an arrray."),"object?":doc("object?",function(e){return e!==nil&&e!==null&&!(e instanceof LCharacter)&&!(e instanceof RegExp)&&!(e instanceof LString)&&!(e instanceof Pair)&&!(e instanceof LNumber)&&_typeof_1(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Function check if value is an plain object."),flatten:doc(function e(r){typecheck("flatten",r,"pair");return r.flatten()},"(flatten list)\n\n Return shallow list from tree structure (pairs)."),"array->list":doc("array->list",function(e){typecheck("array->list",e,"array");return Pair.fromArray(e)},"(array->list array)\n\n Function convert JavaScript array to LIPS list."),"tree->array":doc("tree->array",toArray$1("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":doc("list->array",toArray$1("list->array"),"(list->array list)\n\n Function convert LIPS list into JavaScript array."),apply:doc(function e(r){for(var n=arguments.length,t=new Array(n>1?n-1:0),i=1;iarray").call(this,a));return r.apply(this,t)},"(apply fn list)\n\n Function that call function with list of arguments."),length:doc(function e(r){if(!r){return LNumber(0)}if(r instanceof Pair){return LNumber(r.length())}if("length"in r){return LNumber(r.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":doc("string->number",function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:10;typecheck("string->number",e,"string",1);typecheck("string->number",r,"number",2);e=e.valueOf();r=r.valueOf();if(e.match(rational_bare_re)||e.match(rational_re)){return parse_rational(e,r)}else if(e.match(complex_bare_re)||e.match(complex_re)){return parse_complex(e,r)}else{var n=r===10&&!e.match(/e/i)||r===16;if(e.match(int_bare_re)&&n||e.match(int_re)){return parse_integer(e,r)}if(e.match(float_re)){return parse_float(e)}}return false},"(string->number number [radix])\n\n Function convert string to number."),try:doc(new Macro("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(r){var n=o.inherit("try");n.set(a.cdr.car.cdr.car.car,r);var t={env:n,error:c};if(u){t.dynamic_scope=o}unpromise(evaluate(new Pair(new LSymbol("begin"),a.cdr.car.cdr.cdr),t),function(e){i(e)})}};if(u){e.dynamic_scope=o}var r=evaluate(a.car,e);if(isPromise(r)){r.then(i)["catch"](e.error)}else{i(r)}})}),"(try expr (catch (e) code)"),throw:doc("throw",function(e){throw new Error(e)},"(throw string)\n\n Throw new expection."),find:doc(function r(n,t){typecheck("find",n,["regex","function"]);typecheck("find",t,["pair","nil"]);if(isNull(t)){return nil}var e=matcher("find",n);return unpromise(e(t.car),function(e){if(e&&e!==nil){return t.car}return r(n,t.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":doc("for-each",function(e){var r;typecheck("for-each",e,"function");for(var n=arguments.length,t=new Array(n>1?n-1:0),i=1;i1?r-1:0),a=1;a3?t-3:0),a=3;a3?i-3:0),o=3;oarray")(n);var a=[];var o=matcher("filter",r);return function r(n){function e(e){if(e&&e!==nil){a.push(t)}return r(++n)}if(n===i.length){return Pair.fromArray(a)}var t=i[n];return unpromise(o(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."),compose:doc(compose,"(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:doc(pipe,"(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:doc(curry,"(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:doc(function e(){for(var r=arguments.length,n=new Array(r),t=0;ti?n%=i:i%=n}n=abs(a*(t<0||arguments.length<=t?undefined$1:arguments[t]))/(n+i)}return LNumber(n)},"(lcm n1 n2 ...)\n\n Function return the least common multiple of their arguments."),"odd?":doc("odd?",singleMathOp(function(e){return LNumber(e).isOdd()}),"(odd? number)\n\n Function check if number os odd."),"even?":doc("even?",singleMathOp(function(e){return LNumber(e).isEven()}),"(even? number)\n\n Function check if number is even."),"*":doc("*",reduceMathOp(function(e,r){return LNumber(e).mul(r)},LNumber(1)),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":doc("+",reduceMathOp(function(e,r){return LNumber(e).add(r)},LNumber(0)),"(+ . numbers)\n\n Sum all numbers passed as arguments. If single value is passed it will\n return that value."),"-":doc("-",function(){for(var e=arguments.length,r=new Array(e),n=0;n":doc(">",function(){for(var e=arguments.length,r=new Array(e),n=0;n x1 x2 x3 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically increasing"),"<":doc("<",function(){for(var e=arguments.length,r=new Array(e),n=0;n=":doc(">=",function(){for(var e=arguments.length,r=new Array(e),n=0;n= x1 x2 x3 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically nondecreasing"),"eq?":doc("eq?",equal,"(eq? a b)\n\n Function compare two values if they are identical."),or:doc(new Macro("or",function(e,r){var i=r.dynamic_scope,a=r.error;var o=this.get("list->array")(e);var u=this;if(i){i=u}var c;return function r(){function e(e){c=e;if(c){return c}else{return r()}}var n=o.shift();if(typeof n==="undefined"){if(c){return c}else{return false}}else{var t=evaluate(n,{env:u,dynamic_scope:i,error:a});return unpromise(t,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:doc(new Macro("and",function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},i=r.dynamic_scope,a=r.error;var o=this.get("list->array")(e);var u=this;if(i){i=u}if(!o.length){return true}var c;return function r(){function e(e){c=e;if(!c){return false}else{return r()}}var n=o.shift();if(typeof n==="undefined"){if(c){return c}else{return false}}else{var t=evaluate(n,{env:u,dynamic_scope:i,error:a});return unpromise(t,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."),"|":doc("|",function(e,r){return LNumber(e).or(r)},"(& a b)\n\n Function calculate or bit operation."),"&":doc("&",function(e,r){return LNumber(e).and(r)},"(& a b)\n\n Function calculate and bit operation."),"~":doc("~",function(e){return LNumber(e).neg()},"(~ number)\n\n Function negate the value."),">>":doc(">>",function(e,r){return LNumber(e).shr(r)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":doc(function(e,r){return LNumber(e).shl(r)},"(<< a b)\n\n Function left shit the value a by value b."),not:doc(function e(r){if(isNull(r)){return true}return!r},"(not object)\n\n Function return negation of the argument.")},undefined$1,"global");var user_env=global_env.inherit("user-env");global_env.set("**interaction-environment**",user_env);(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(r){var n=e[r]?e[r]:r;global_env.set(n,doc(n,function(e){typecheck(n,e,"number");if(e instanceof LNumber){return e[r]()}},"(".concat(n," number)\n\n Function calculate ").concat(n," of a number.")))})})();function allPossibleCases(e){if(e.length===1){return e[0]}else{var r=[];var n=allPossibleCases(e.slice(1));for(var t=0;t3&&arguments[3]!==undefined$1?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(t!==null){i+=" (argument ".concat(t,")")}if(n instanceof Array){if(n.length===1){n=n[0]}else{var a=n[n.length-1];n=n.slice(0,-1).join(", ")+" or "+a}}return"Expecting ".concat(n,", got ").concat(r).concat(i)}function typecheck(e,r,n){var t=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:null;e=e.valueOf();var i=type(r).toLowerCase();var a=false;if(n instanceof Pair){n=n.toArray()}if(n instanceof Array){n=n.map(function(e){return e.valueOf()})}if(n instanceof Array){n=n.map(function(e){return e.valueOf().toLowerCase()});if(n.includes(i)){a=true}}else{n=n.valueOf().toLowerCase()}if(!a&&i!==n){throw new Error(typeErrorMessage(e,i,n,t))}}function self_evaluated(e){var r=_typeof_1(e);return["string","function"].includes(r)||e instanceof LSymbol||e instanceof LNumber||e instanceof LString||e instanceof RegExp}function is_native(e){return e instanceof LNumber||e instanceof LString||e instanceof LCharacter}function type(e){var r={pair:Pair,symbol:LSymbol,character:LCharacter,values:Values,macro:Macro,string:LString,array:Array,"native-symbol":Symbol};if(Number.isNaN(e)){return"NaN "}if(e===nil){return"nil"}if(e===null){return"null"}if(e instanceof Syntax){return"syntax"}for(var n=0,t=Object.entries(r);n1&&arguments[1]!==undefined$1?arguments[1]:{},i=e.env,a=e.dynamic_scope,n=e.error,o=n===void 0?function(){}:n;try{if(a===true){i=a=i||global_env}else if(i===true){i=a=global_env}else{i=i||global_env}var t={env:i,dynamic_scope:a,error:o};var u;if(isNull(r)){return r}if(r instanceof LSymbol){return i.get(r)}var c=r.car;var s=r.cdr;if(c instanceof Pair){u=resolvePromises(evaluate(c,t));if(isPromise(u)){return u.then(function(e){return evaluate(new Pair(e,r.cdr),t)})}else if(typeof u!=="function"){throw new Error(type(u)+" "+i.get("repr")(u)+" is not a function while evaluating "+r.toString())}}if(c instanceof LSymbol){u=i.get(c);if(u instanceof Syntax){return evaluateSyntax(u,r,t)}else if(u instanceof Macro){return evaluateMacro(u,s,t)}else if(typeof u!=="function"){if(u){var f="".concat(type(u)," `").concat(u,"' is not a function");throw new Error(f)}throw new Error("Unknown function `".concat(c.toString(),"'"))}}else if(typeof c==="function"){u=c}if(typeof u==="function"){var l=getFunctionArgs(s,t);return unpromise(l,function(e){if(is_bound(u)&&!is_object_bound(u)&&(!lips_context(u)||is_port(u))){e=e.map(unbox)}if(u.__lambda__&&!u.__prototype__||is_port(u)){u=unbind(u)}else if(e.some(lips_function)&&!lips_function(u)&&!is_array_method(u)){e=e.map(function(t){if(lips_function(t)){return function(){for(var e=arguments.length,r=new Array(e),n=0;n1&&arguments[1]!==undefined$1?arguments[1]:false;return this.rpc("eval",[e,r])}}Pair.unDry=function(e){return new Pair(e.car,e.cdr)};Pair.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};Nil.prototype.toDry=function(){return{value:null}};Nil.unDry=function(){return nil};LSymbol.prototype.toDry=function(){return{value:{name:this.__name__}}};LSymbol.unDry=function(e){return new LSymbol(e.__name__)};function execError(e){console.error(e.message||e);if(e.code){console.error(e.code.map(function(e,r){return"[".concat(r+1,"]: ").concat(e)}))}}function init(){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 r(){var e=a.shift();if(!e){i()}else{var n=e.getAttribute("type");if(o.includes(n)){var t=e.getAttribute("src");if(t){return root.fetch(t).then(function(e){return e.text()}).then(exec).then(r)["catch"](function(e){execError(e);r()})}else{return exec(e.innerHTML).then(r)["catch"](function(e){execError(e);r()})}}else if(n&&n.match(/lips|lisp/)){console.warn("Expecting "+o.join(" or ")+" found "+n)}return r()}}()})}}if(typeof window!=="undefined"){contentLoaded(window,init)}var banner=function(){var e=LString("Wed, 11 Nov 2020 11:37:22 +0000").valueOf();var r=e==="{{"+"DATE}}"?new Date:new Date(e);var n=function e(r){return r.toString().padStart(2,"0")};var t=r.getFullYear();var i=[t,n(r.getMonth()+1),n(r.getDate())].join("-");var a="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter DEV (".concat(i,") \nCopyright (c) 2018-").concat(t," 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}();Ahead.__class__="ahead";Pattern.__class__="pattern";Formatter.__class__="formatter";Macro.__class__="macro";Syntax.__class__="syntax";Environment.__class__="environment";InputPort.__class__="input-port";OutputPort.__class__="output-port";OutputStringPort.__class__="output-string-port";InputStringPort.__class__="input-string-port";LNumber.__class__="number";LCharacter.__class__="character";LString.__class__="string";var lips={version:"DEV",banner:banner,date:"Wed, 11 Nov 2020 11:37:22 +0000",exec:exec,parse:parse,tokenize:tokenize,evaluate:evaluate,Environment:Environment,env:user_env,Worker:Worker,Interpreter:Interpreter,balanced_parenthesis:balanced,balancedParenthesis:balanced,balanced:balanced,Macro:Macro,Syntax:Syntax,Pair:Pair,Values:Values,quote:quote,InputPort:InputPort,OutputPort:OutputPort,InputStringPort:InputStringPort,OutputStringPort:OutputStringPort,Formatter:Formatter,specials:specials,repr:repr,nil:nil,LSymbol:LSymbol,LNumber:LNumber,LFloat:LFloat,LComplex:LComplex,LRational:LRational,LBigInteger:LBigInteger,LCharacter:LCharacter,LString:LString,rationalize:rationalize};global_env.set("lips",lips);return lips})})(); \ No newline at end of file +(function(){"use strict";function _readOnlyError(e){throw new Error('"'+e+'" is read-only')}var readOnlyError=_readOnlyError;function createCommonjsModule(e,r){return r={exports:{}},e(r,r.exports),r.exports}var setPrototypeOf=createCommonjsModule(function(n){function t(e,r){n.exports=t=Object.setPrototypeOf||function e(r,n){r.__proto__=n;return r};return t(e,r)}n.exports=t});function _isNativeReflectConstruct(){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 isNativeReflectConstruct=_isNativeReflectConstruct;var construct=createCommonjsModule(function(t){function i(e,r,n){if(isNativeReflectConstruct()){t.exports=i=Reflect.construct}else{t.exports=i=function e(r,n,t){var i=[null];i.push.apply(i,n);var a=Function.bind.apply(r,i);var o=new a;if(t)setPrototypeOf(o,t.prototype);return o}}return i.apply(null,arguments)}t.exports=i});function _arrayWithHoles(e){if(Array.isArray(e))return e}var arrayWithHoles=_arrayWithHoles;function _iterableToArray(e){if(typeof Symbol!=="undefined"&&Symbol.iterator in Object(e))return Array.from(e)}var iterableToArray=_iterableToArray;function _arrayLikeToArray(e,r){if(r==null||r>e.length)r=e.length;for(var n=0,t=new Array(r);n=0;--r){var i=this.tryEntries[r];var a=i.completion;if(i.tryLoc==="root"){return e("end")}if(i.tryLoc<=this.prev){var o=l.call(i,"catchLoc");var c=l.call(i,"finallyLoc");if(o&&c){if(this.prev=0;--n){var t=this.tryEntries[n];if(t.tryLoc<=this.prev&&l.call(t,"finallyLoc")&&this.prev=0;--r){var n=this.tryEntries[r];if(n.finallyLoc===e){this.complete(n.completion,n.afterLoc);O(n);return v}}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc===e){var t=n.completion;if(t.type==="throw"){var i=t.arg;O(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){this.delegate={iterator:E(e),resultName:r,nextLoc:n};if(this.method==="next"){this.arg=u}return v}};return o}(e.exports);try{regeneratorRuntime=r}catch(e){Function("r","regeneratorRuntime = r")(r)}});var regenerator=runtime_1;function asyncGeneratorStep(e,r,n,t,i,a,o){try{var c=e[a](o);var u=c.value}catch(e){n(e);return}if(c.done){r(u)}else{Promise.resolve(u).then(t,i)}}function _asyncToGenerator(c){return function(){var e=this,o=arguments;return new Promise(function(r,n){var t=c.apply(e,o);function i(e){asyncGeneratorStep(t,r,n,i,a,"next",e)}function a(e){asyncGeneratorStep(t,r,n,i,a,"throw",e)}i(undefined)})}}var asyncToGenerator=_asyncToGenerator;function _classCallCheck(e,r){if(!(e instanceof r)){throw new TypeError("Cannot call a class as a function")}}var classCallCheck=_classCallCheck;function _defineProperties(e,r){for(var n=0;n=0)continue;n[i]=e[i]}return n}var objectWithoutPropertiesLoose=_objectWithoutPropertiesLoose;function _objectWithoutProperties(e,r){if(e==null)return{};var n=objectWithoutPropertiesLoose(e,r);var t,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,t))continue;n[t]=e[t]}}return n}var objectWithoutProperties=_objectWithoutProperties;function _iterableToArrayLimit(e,r){if(typeof Symbol==="undefined"||!(Symbol.iterator in Object(e)))return;var n=[];var t=true;var i=false;var a=undefined;try{for(var o=e[Symbol.iterator](),c;!(t=(c=o.next()).done);t=true){n.push(c.value);if(r&&n.length===r)break}}catch(e){i=true;a=e}finally{try{if(!t&&o["return"]!=null)o["return"]()}finally{if(i)throw a}}return n}var iterableToArrayLimit=_iterableToArrayLimit;function _slicedToArray(e,r){return arrayWithHoles(e)||iterableToArrayLimit(e,r)||unsupportedIterableToArray(e,r)||nonIterableRest()}var slicedToArray=_slicedToArray;var _typeof_1=createCommonjsModule(function(r){function n(e){"@babel/helpers - typeof";if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){r.exports=n=function e(r){return typeof r}}else{r.exports=n=function e(r){return r&&typeof Symbol==="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r}}return n(e)}r.exports=n});function _createForOfIteratorHelper(r,e){var n;if(typeof Symbol==="undefined"||r[Symbol.iterator]==null){if(Array.isArray(r)||(n=_unsupportedIterableToArray$1(r))||e&&r&&typeof r.length==="number"){if(n)r=n;var t=0;var i=function e(){};return{s:i,n:function e(){if(t>=r.length)return{done:true};return{done:false,value:r[t++]}},e:function e(r){throw r},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a=true,o=false,c;return{s:function e(){n=r[Symbol.iterator]()},n:function e(){var r=n.next();a=r.done;return r},e:function e(r){o=true;c=r},f:function e(){try{if(!a&&n["return"]!=null)n["return"]()}finally{if(o)throw c}}}}function _unsupportedIterableToArray$1(e,r){if(!e)return;if(typeof e==="string")return _arrayLikeToArray$1(e,r);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor)n=e.constructor.name;if(n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray$1(e,r)}function _arrayLikeToArray$1(e,r){if(r==null||r>e.length)r=e.length;for(var n=0,t=new Array(r);n1&&arguments[1]!==undefined$1?arguments[1]:null;var t=arguments[1]===true;function r(e){if(!is_debug()){return}var r=global_env.get("repr")(e);if(n===null||n instanceof RegExp&&n.test(r)){console.log(global_env.get("type")(e)+": "+r)}if(t){console.log(e)}}if(isPromise(e)){e.then(r)}else{r(e)}return e}function is_debug(){return user_env.get("DEBUG",{throwError:false})}if(!root.fetch){root.fetch=function(i,a){a=a||{};return new Promise(function(e,r){var n=new XMLHttpRequest;n.open(a.method||"get",i,true);for(var t in a.headers){n.setRequestHeader(t,a.headers[t])}n.withCredentials=a.credentials=="include";n.onload=function(){e(c())};n.onerror=r;n.send(a.body||null);function c(){var t=[],i=[],a={},o;n.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,r,n){t.push(r=r.toLowerCase());i.push([r,n]);o=a[r];a[r]=o?"".concat(o,",").concat(n):n});return{ok:(n.status/100|0)==2,status:n.status,statusText:n.statusText,url:n.responseURL,clone:c,text:function e(){return Promise.resolve(n.responseText)},json:function e(){return Promise.resolve(n.responseText).then(JSON.parse)},blob:function e(){return Promise.resolve(new Blob([n.response]))},headers:{keys:function e(){return t},entries:function e(){return i},get:function e(r){return a[r.toLowerCase()]},has:function e(r){return r.toLowerCase()in a}}}}})}}function num_mnemicic_re(e){return e?"(?:#".concat(e,"(?:#[ie])?|#[ie]#").concat(e,")"):"(?:#[ie])?"}function gen_rational_re(e,r){return"".concat(num_mnemicic_re(e),"[+-]?").concat(r,"+/").concat(r,"+")}function gen_complex_re(e,r){return"".concat(num_mnemicic_re(e),"(?:[+-]?(?:").concat(r,"+/").concat(r,"+|").concat(r,"+))?(?:[+-]i|[+-]?(?:").concat(r,"+/").concat(r,"+|").concat(r,"+)i)(?=[()[\\]\\s]|$)")}function gen_integer_re(e,r){return"".concat(num_mnemicic_re(e),"[+-]?").concat(r,"+")}var re_re=/^\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimy]*)$/;var float_stre="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)";var complex_float_stre="(?:#[ie])?(?:[+-]?(?:[0-9]+/[0-9]+|".concat(float_stre,"|[+-]?[0-9]+))?(?:").concat(float_stre,"|[+-](?:[0-9]+/[0-9]+|[0-9]+))i");var float_re=new RegExp("^(#[ie])?".concat(float_stre,"$"),"i");function make_complex_match_re(e,r){var n=e==="x"?"(?!\\+|".concat(r,")"):"(?!\\.|".concat(r,")");var t="";if(e===""){t="(?:[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)|(?:\\.[0-9]+|[0-9]+\\.[0-9]+(?![0-9]))(?:[eE][-+]?[0-9]+)?))"}return new RegExp("^((?:".concat(t,"|[+-]?").concat(r,"+/").concat(r,"+(?!").concat(r,")|[+-]?").concat(r,"+").concat(n,")?)(").concat(t,"|[+-]?").concat(r,"+/").concat(r,"+|[+-]?").concat(r,"+|[+-])i$"),"i")}var complex_list_re=function(){var a={};[[10,"","[0-9]"],[16,"x","[0-9a-fA-F]"],[8,"o","[0-7]"],[2,"b","[01]"]].forEach(function(e){var r=slicedToArray(e,3),n=r[0],t=r[1],i=r[2];a[n]=make_complex_match_re(t,i)});return a}();var characters={alarm:"",backspace:"\b",delete:"",escape:"",newline:"\n",null:"\0",return:"\r",space:" ",tab:"\t",dle:"",soh:"",dc1:"",stx:"",dc2:"",etx:"",dc3:"",eot:"",dc4:"",enq:"",nak:"",ack:"",syn:"",bel:"",etb:"",bs:"\b",can:"",ht:"\t",em:"",lf:"\n",sub:"",vt:"\v",esc:"",ff:"\f",fs:"",cr:"\r",gs:"",so:"",rs:"",si:"",us:"",del:""};var character_symbols=Object.keys(characters).join("|");var char_sre_re="#\\\\(?:x[0-9a-f]+|".concat(character_symbols,"|[\\s\\S])");var char_re=new RegExp("^".concat(char_sre_re,"$"),"i");function make_num_stre(i){var e=[["o","[0-7]"],["x","[0-9a-fA-F]"],["b","[01]"],["","[0-9]"]];var r=e.map(function(e){var r=slicedToArray(e,2),n=r[0],t=r[1];return i(n,t)}).join("|");if(i===gen_complex_re){r=complex_float_stre+"|"+r}return r}function make_type_re(e){return new RegExp("^(?:"+make_num_stre(e)+")$","i")}var complex_re=make_type_re(gen_complex_re);var rational_re=make_type_re(gen_rational_re);var int_re=make_type_re(gen_integer_re);var int_bare_re=new RegExp("^(?:"+gen_integer_re("","[0-9a-f]")+")$","i");var rational_bare_re=new RegExp("^(?:"+gen_rational_re("","[0-9a-f]")+")$","i");var complex_bare_re=new RegExp("^(?:"+gen_complex_re("","[0-9a-f]")+")$","i");var complex_bare_match_re=make_complex_match_re("","[0-9a-fA-F]");var pre_num_parse_re=/((?:#[xobie]){0,2})(.*)/i;function num_pre_parse(e){var r=e.match(pre_num_parse_re);var n={};if(r[1]){var t=r[1].replace(/#/g,"").toLowerCase().split("");if(t.includes("x")){n.radix=16}else if(t.includes("o")){n.radix=8}else if(t.includes("b")){n.radix=2}if(t.includes("i")){n.inexact=true}if(t.includes("e")){n.exact=true}}n.number=r[2];return n}function parse_rational(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:10;var n=num_pre_parse(e);var t=n.number.split("/");var i=LRational({num:LNumber([t[0],n.radix||r]),denom:LNumber([t[1],n.radix||r])});if(n.inexact){return i.valueOf()}else{return i}}function parse_integer(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:10;var n=num_pre_parse(e);if(n.inexact){return LFloat(parseInt(n.number,n.radix||r))}return LNumber([n.number,n.radix||r])}function parse_character(e){var r=e.match(/#\\x([0-9a-f]+)$/i);var n;if(r){var t=parseInt(r[1],16);n=String.fromCodePoint(t)}else{r=e.match(/#\\(.+)$/);if(r){n=r[1]}}if(n){return LCharacter(n)}}function parse_complex(e){var i=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:10;function r(e){var r;if(e==="+"){r=LNumber(1)}else if(e==="-"){r=LNumber(-1)}else if(e.match(int_bare_re)){r=LNumber([e,i])}else if(e.match(rational_bare_re)){var n=e.split("/");r=LRational({num:LNumber([n[0],i]),denom:LNumber([n[1],i])})}else if(e.match(float_re)){var t=LFloat(parseFloat(e));if(a.exact){return t.toRational()}return t}else{throw new Error("Internal Parser Error")}if(a.inexact){return LFloat(r.valueOf())}return r}var a=num_pre_parse(e);i=a.radix||i;var n;var t=a.number.match(complex_bare_match_re);if(i!==10&&t){n=t}else{n=a.number.match(complex_list_re[i])}var o,c;c=r(n[2]);if(n[1]){o=r(n[1])}else if(c instanceof LFloat){o=LFloat(0)}else{o=LNumber(0)}return LComplex({im:c,re:o})}function is_int(e){return parseInt(e.toString(),10)===e}function parse_big_int(e){var r=e.match(/^(([-+]?[0-9]*)(?:\.([0-9]+))?)e([-+]?[0-9]+)/i);if(r){var n=parseInt(r[4],10);var t;var i=r[1].replace(/[-+]?([0-9]*)\..+$/,"$1").length;var a=r[3]&&r[3].length;if(i0){return LNumber(a).mul(c)}}}n=LFloat(n);if(r.exact){return n.toRational()}return n}function parse_string(e){var r=/([^\\\n])(\\(?:\\{2})*)(?!x[0-9A-F]+)(?!u[0-9A-F]{2,4})(.)/gi;e=e.replace(r,function(e,r,n,t){if(!['"',"/","b","f","n","\\","r","t","x"].includes(t)){n=n.substring(1).replace(/\\\\/,"\\")}return e}).replace(/\\x([0-9a-f]+);/gi,function(e,r){return"\\u"+r.padStart(4,"0")}).replace(/\n/g,"\\n");var n=e.match(/(\\*)(\\x[0-9A-F])/i);if(n&&n[1].length%2===0){throw new Error("Invalid string literal, unclosed ".concat(n[2]))}try{return LString(JSON.parse(e))}catch(e){throw new Error("Invalid string literal")}}function parse_symbol(e){if(e.match(/^\|.*\|$/)){e=e.replace(/(^\|)|(\|$)/g,"");var n={t:"\t",r:"\r",n:"\n"};e=e.replace(/\\(x[^;]+);/g,function(e,r){return String.fromCharCode(parseInt("0"+r,16))}).replace(/\\(.)/g,function(e,r){return n[r]||r})}return new LSymbol(e)}function parse_argument(e){var r=e.match(re_re);if(r){return new RegExp(r[1],r[2])}else if(e.match(/^"/)){return parse_string(e)}else if(e.match(char_re)){return parse_character(e)}else if(e.match(rational_re)){return parse_rational(e)}else if(e.match(complex_re)){return parse_complex(e)}else if(e.match(int_re)){return parse_integer(e)}else if(e.match(float_re)){return parse_float(e)}else if(e==="nil"){return nil}else if(["true","#t"].includes(e)){return true}else if(["false","#f"].includes(e)){return false}else{return parse_symbol(e)}}function is_symbol_string(e){return!(["(",")"].includes(e)||e.match(re_re)||e.match(/^"[\s\S]+"$/)||e.match(int_re)||e.match(float_re)||e.match(complex_re)||e.match(rational_re)||["#t","#f","nil","true","false"].includes(e))}var pre_parse_re=/("(?:\\[\S\s]|[^"])*"?|\/(?! )[^\n\/\\]*(?:\\[\S\s][^\n\/\\]*)*\/[gimy]*(?=[\s[\]()]|$)|\|[^|\s\n]+\||#;|;.*|#\|(?!\|#)[\s\S]*\|#)/g;var string_re=/"(?:\\[\S\s]|[^"])*"?/g;var num_stre=[gen_complex_re,gen_rational_re,gen_integer_re].map(make_num_stre).join("|");function make_tokens_re(){var e=specials.names().sort(function(e,r){return r.length-e.length||e.localeCompare(r)}).map(escape_regex).join("|");return new RegExp("(".concat(char_sre_re,"|#f|#t|#;|(?:").concat(num_stre,")(?=$|[\\n\\s()[\\]])|\\[|\\]|\\(|\\)|\\|[^|]+\\||;.*|(?:#[ei])?").concat(float_stre,"(?=$|[\\n\\s()[\\]])|\\n|\\.{2,}|'(?=#[ft]|(?:#[xiobe]){1,2}|#\\\\)|(?!#:)(?:").concat(e,")|[^(\\s)[\\]]+)"),"gim")}function last_item(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:1;return e[e.length-r]}function escape_regex(e){if(typeof e==="string"){var r=/([-\\^$[\]()+{}?*.|])/g;return e.replace(r,"\\$1")}}function Stack(){this.data=[]}Stack.prototype.push=function(e){this.data.push(e)};Stack.prototype.top=function(){return this.data[this.data.length-1]};Stack.prototype.pop=function(){return this.data.pop()};Stack.prototype.is_empty=function(){return!this.data.length};function tokens(e){var a=make_tokens_re();e=e.replace(/\n\r|\r/g,"\n");var o=0;var c=0;var u=[];var s=[];var l=0;e.split(pre_parse_re).filter(Boolean).forEach(function(e){if(e.match(pre_parse_re)){l=0;if(s.length){var r=last_item(s);if(r.token.match(/\n/)){var n=r.token.split("\n").pop();l+=n.length}else{l+=r.token.length}l+=r.col}var t={col:l,line:c,token:e,offset:o};u.push(t);s.push(t);o+=e.length;l+=e.length;c+=(e.match("\n")||[]).length;return}var i=e.split(a).filter(Boolean);i.forEach(function(e){var r={col:l,line:c,token:e,offset:o};l+=e.length;o+=e.length;u.push(r);s.push(r);if(e==="\n"){++c;s=[];l=0}})});return u}function multiline_formatter(e){var r=e.token,n=objectWithoutProperties(e,["token"]);if(r.match(/^"[\s\S]+"$/)&&r.match(/\n/)){var t=new RegExp("^ {1,"+(e.col+1)+"}","mg");r=r.replace(t,"")}return _objectSpread({token:r},n)}function Thunk(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:function(){};this.fn=e;this.cont=r}Thunk.prototype.toString=function(){return"#"};function trampoline(t){return function(){for(var e=arguments.length,r=new Array(e),n=0;n2&&arguments[2]!==undefined$1?arguments[2]:multiline_formatter;if(e instanceof LString){e=e.toString()}if(r){return tokens(e).map(n)}else{var t=tokens(e).map(function(e){var r=n(e);if(!r||typeof r.token!=="string"){throw new Error("[tokenize] Invalid formatter wrong return object")}if(r.token==="#\\ "){return r.token}return r.token.trim()}).filter(function(e){return e&&!e.match(/^;/)&&!e.match(/^#\|[\s\S]*\|#$/)});return strip_s_comments(t)}}function strip_s_comments(e){var r=0;var n=null;var t=[];for(var i=0;i1&&arguments[1]!==undefined$1?arguments[1]:function(e){return e};var n=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:null;if(e instanceof Array){var t=e.filter(isPromise);if(t.length){return unpromise(Promise.all(t),r,n)}return r(e)}if(isPromise(e)){var i=e.then(r);if(n===null){return i}else{return i["catch"](n)}}return r(e)}function matcher(e,r){if(r instanceof RegExp){return function(e){return String(e).match(r)}}else if(typeof r==="function"){return r}}function doc(e,r,n,t){if(typeof e!=="string"){r=arguments[0];n=arguments[1];t=arguments[2];e=null}if(n){if(t){r.__doc__=n}else{r.__doc__=trim_lines(n)}}if(e){r.__name__=e}else if(r.name){r.__name__=r.name}return r}function trim_lines(e){return e.split("\n").map(function(e){return e.trim()}).join("\n")}function previousSexp(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:1;var n=e.length;if(r<=0){throw Error("previousSexp: Invalid argument sexp = ".concat(r))}e:while(r--&&n>=0){var t=1;while(t>0){var i=e[--n];if(!i){break e}if(i==="("||i.token==="("){t--}else if(i===")"||i.token===")"){t++}}n--}return e.slice(n+1)}function lineIndent(e){if(!e||!e.length){return 0}var r=e.length;if(e[r-1].token==="\n"){return 0}while(--r){if(e[r].token==="\n"){var n=(e[r+1]||{}).token;if(n){return n.length}}}return 0}function match(e,r){return l(e,r)===r.length;function l(n,t){function e(){return a>0&&c>0&&n[a-1]===t[c-1]&&n[a+1]===t[c]}function r(){return n[a]===Symbol["for"]("symbol")&&!is_symbol_string(t[c])}function i(){var e=n[a+1];var r=t[c+1];if(e!==undefined$1&&r!==undefined$1){return l([e],[r])}}var a=0;var o={};for(var c=0;c0){continue}}else if(r()){return-1}}else if(n[a]instanceof Array){var s=l(n[a],t.slice(c));if(s===-1||s+c>t.length){return-1}c+=s-1;a++;continue}else{return-1}a++}if(n.length!==a){return-1}return t.length}}function Formatter(e){this._code=e.replace(/\r/g,"")}Formatter.defaults={offset:0,indent:2,exceptions:{specials:[/^(?:#:)?define/,/^(?:#:)?lambda/,/^(?:#:)?let*/,/^(?:#:)?(let|letrec)(-syntax)?$/,/(?:#:)?let-env/,/(?:#:)?syntax-rules/,/(?:#:)?try/,/(?:#:)?catch/,/(?:#:)?while/],shift:{1:["&","#"]}}};Formatter.match=match;Formatter.prototype._options=function e(r){var n=Formatter.defaults;if(typeof r==="undefined"){return Object.assign({},n)}var t=r&&r.exceptions||{};var i=t.specials||[];var a=t.shift||{1:[]};return _objectSpread(_objectSpread(_objectSpread({},n),r),{},{exceptions:{specials:[].concat(toConsumableArray(n.exceptions.specials),toConsumableArray(i)),shift:_objectSpread(_objectSpread({},a),{},{1:[].concat(toConsumableArray(n.exceptions.shift[1]),toConsumableArray(a[1]))})}})};Formatter.prototype.indent=function e(r){var n=tokenize(this._code,true);return this._indent(n,r)};Formatter.exception_shift=function(a,e){function r(e){if(!e.length){return false}if(e.indexOf(a)!==-1){return true}else{var r=e.filter(function(e){return e instanceof RegExp});if(!r.length){return false}var n=_createForOfIteratorHelper(r),t;try{for(n.s();!(t=n.n()).done;){var i=t.value;if(a.match(i)){return true}}}catch(e){n.e(e)}finally{n.f()}}return false}if(r(e.exceptions.specials)){return e.indent}var n=e.exceptions.shift;for(var t=0,i=Object.entries(n);t0){t.offset=0}if(a.toString()===r.toString()&&balanced(a)){return t.offset+a[0].col}else if(a.length===1){return t.offset+a[0].col+1}else{var c=-1;if(o){var u=Formatter.exception_shift(o.token,t);if(u!==-1){c=u}}if(c===-1){c=Formatter.exception_shift(a[1].token,t)}if(c!==-1){return t.offset+a[0].col+c}else if(a[0].line3&&a[1].line===a[3].line){if(a[1].token==="("||a[1].token==="["){return t.offset+a[1].col}return t.offset+a[3].col}else if(a[0].line===a[1].line){return t.offset+t.indent+a[0].col}else{var s=a.slice(2);for(var l=0;l")};Ahead.prototype.match=function(e){return e.match(this.pattern)};function Pattern(e,r){this.pattern=e;this.flag=r}Pattern.prototype.toString=function(){return"#")};Formatter.Pattern=Pattern;Formatter.Ahead=Ahead;var p_o=/[[(]/;var p_e=/[\])]/;var not_p=/[^()[\]]/;var not_close=new Ahead(/[^)\]]/);var open=new Ahead(/[([]/);var glob=Symbol["for"]("*");var sexp=new Pattern([p_o,glob,p_e],"+");var symbol=new Pattern([Symbol["for"]("symbol")],"?");var symbols=new Pattern([Symbol["for"]("symbol")],"*");var identifiers=[p_o,symbols,p_e];var let_value=new Pattern([p_o,Symbol["for"]("symbol"),glob,p_e],"+");var def_lambda_re=keywords_re("define","lambda","syntax-rules");var non_def=/^(?!.*\b(?:[()[\]]|define|let(?:\*|rec|-env|-syntax)?|lambda|syntax-rules)\b).*$/;var let_re=/^(?:#:)?(let(?:\*|rec|-env|-syntax)?)$/;function keywords_re(){for(var e=arguments.length,r=new Array(e),n=0;n0&&arguments[0]!==undefined$1?arguments[0]:null;if(e instanceof LSymbol){e=e.valueOf()}if(is_gensym(e)){return LSymbol(e)}if(e!==null){return new LSymbol(Symbol("#:".concat(e)))}r++;return new LSymbol(Symbol("#:g".concat(r)))}}();function Nil(){}Nil.prototype.toString=Nil.prototype.toJSON=function(){return"()"};Nil.prototype.valueOf=function(){return undefined$1};Nil.prototype.toObject=function(){return{}};Nil.prototype.append=function(e){return new Pair(e,nil)};Nil.prototype.toArray=function(){return[]};var nil=new Nil;function Pair(e,r){if(typeof this!=="undefined"&&this.constructor!==Pair||typeof this==="undefined"){return new Pair(e,r)}this.car=e;this.cdr=r}function toArray$1(a,o){return function e(r){typecheck(a,r,["pair","nil"]);if(r===nil){return[]}var n=[];var t=r;while(true){if(t instanceof Pair){if(t.haveCycles("cdr")){break}var i=t.car;if(o&&i instanceof Pair){i=this.get(a).call(this,i)}n.push(i);t=t.cdr}else{break}}return n}}Pair.prototype.flatten=function(){return Pair.fromArray(flatten(this.toArray()))};Pair.prototype.length=function(){var e=0;var r=this;while(true){if(!r||r===nil||!(r instanceof Pair)||r.haveCycles("cdr")){break}e++;r=r.cdr}return e};Pair.prototype.clone=function(){var n=new Map;function t(e){if(e instanceof Pair){if(n.has(e)){return n.get(e)}var r=new Pair;n.set(e,r);r.car=t(e.car);r.cdr=t(e.cdr);r.cycles=e.cycles;return r}return e}return t(this)};Pair.prototype.lastPair=function(){var e=this;while(true){if(e.cdr===nil){return e}e=e.cdr}};Pair.prototype.toArray=function(){var e=[];if(this.car instanceof Pair){e.push(this.car.toArray())}else{e.push(this.car.valueOf())}if(this.cdr instanceof Pair){e=e.concat(this.cdr.toArray())}return e};Pair.fromArray=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:true;var n=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:false;if(e instanceof Pair||n&&e instanceof Array&&e.data){return e}if(r===false){var t=nil;for(var i=e.length;i--;){t=new Pair(e[i],t)}return t}if(e.length&&!(e instanceof Array)){e=toConsumableArray(e)}var a=nil;var o=e.length;while(o--){var c=e[o];if(c instanceof Array){c=Pair.fromArray(c,r,n)}else if(typeof c==="string"){c=LString(c)}else if(typeof c==="number"&&!Number.isNaN(c)){c=LNumber(c)}a=new Pair(c,a)}return a};Pair.prototype.toObject=function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:false;var r=this;var n={};while(true){if(r instanceof Pair&&r.car instanceof Pair){var t=r.car;var i=t.car;if(i instanceof LSymbol){i=i.__name__}if(i instanceof LString){i=i.valueOf()}var a=t.cdr;if(a instanceof Pair){a=a.toObject(e)}if(is_native(a)){if(!e){a=a.valueOf()}}n[i]=a;r=r.cdr}else{break}}return n};Pair.fromPairs=function(e){return e.reduce(function(e,r){return new Pair(new Pair(new LSymbol(r[0]),r[1]),e)},nil)};Pair.fromObject=function(r){var e=Object.keys(r).map(function(e){return[e,r[e]]});return Pair.fromPairs(e)};Pair.prototype.reduce=function(e){var r=this;var n=nil;while(true){if(r!==nil){n=e(n,r.car);r=r.cdr}else{break}}return n};Pair.prototype.reverse=function(){if(this.haveCycles()){throw new Error("You can't reverse list that have cycles")}var e=this;var r=nil;while(e!==nil){var n=e.cdr;e.cdr=r;r=e;e=n}return r};Pair.prototype.transform=function(t){function i(e){if(e instanceof Pair){if(e.replace){delete e.replace;return e}var r=t(e.car);if(r instanceof Pair){r=i(r)}var n=t(e.cdr);if(n instanceof Pair){n=i(n)}return new Pair(r,n)}return e}return i(this)};Pair.prototype.map=function(e){if(typeof this.car!=="undefined"){return new Pair(e(this.car),this.cdr===nil?nil:this.cdr.map(e))}else{return nil}};var repr=new Map;function is_plain_object(e){return e&&_typeof_1(e)==="object"&&e.constructor===Object}var props=Object.getOwnPropertyNames(Array.prototype);var array_methods=[];props.forEach(function(e){array_methods.push(Array[e],Array.prototype[e])});function is_array_method(e){e=unbind(e);return array_methods.includes(e)}function lips_function(e){return typeof e==="function"&&(e.__lambda__||e.__doc__)}function user_repr(n){var e=n.constructor||Object;var t=is_plain_object(n);var i;if(repr.has(e)){i=repr.get(e)}else{repr.forEach(function(e,r){r=unbind(r);if(n instanceof r&&(r===Object&&t||r!==Object)){i=e}})}return i}var str_mapping=new Map;[[Number.NEGATIVE_INFINITY,"-inf.0"],[Number.POSITIVE_INFINITY,"+inf.0"],[true,"#t"],[false,"#f"],[null,"null"],[undefined$1,"#"]].forEach(function(e){var r=slicedToArray(e,2),n=r[0],t=r[1];str_mapping.set(n,t)});function symbolize(n){if(n&&_typeof_1(n)==="object"){var t={};var e=Object.getOwnPropertySymbols(n);e.forEach(function(e){var r=e.toString().replace(/Symbol\(([^)]+)\)/,"$1");t[r]=toString(n[e])});var r=Object.getOwnPropertyNames(n);r.forEach(function(e){var r=n[e];if(r&&_typeof_1(r)==="object"&&r.constructor===Object){t[e]=symbolize(r)}else{t[e]=toString(r)}});return t}return n}function get_props(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function toString(e,r,n){if(typeof jQuery!=="undefined"&&e instanceof jQuery.fn.init){return"#"}if(str_mapping.has(e)){return str_mapping.get(e)}if(e instanceof Error){return e.message}if(e instanceof Pair){var t;if(!n){e.markCycles()}for(var i=arguments.length,a=new Array(i>3?i-3:0),o=3;o"}if(isNativeFunction(e.toString)){if(typeof e.__name__==="string"){return"#")}return"#"}else{return e.toString()}}if(e instanceof LString){e=e.toString()}if(e===null||typeof e==="string"&&r){return JSON.stringify(e)}if(_typeof_1(e)==="object"){if(typeof e.toString==="function"&&e.toString.__lambda__){return e.toString().valueOf()}var f=e.constructor;if(!f){f=Object}var p;if(typeof f.__class__==="string"){p=f.__class__}else{if(is_prototype(e)){return"#"}var d=user_repr(e);if(d){if(typeof d==="function"){return d(e,r)}else{throw new Error("toString: Invalid repr value")}}p=f.name}if(type(e)==="instance"&&!isNativeFunction(f)){p="instance"}if(root.HTMLElement&&e instanceof root.HTMLElement){return"#")}if(p!==""){return"#<"+p+">"}if(typeof e[Symbol.iterator]==="function"){return"#"}return"#"}if(typeof e!=="string"){return e.toString()}return e}function is_prototype(e){return e&&_typeof_1(e)==="object"&&e.hasOwnProperty&&e.hasOwnProperty("constructor")&&typeof e.constructor==="function"&&e.constructor.prototype===e}Pair.prototype.markCycles=function(){markCycles(this);return this};Pair.prototype.haveCycles=function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:null;if(!e){return this.haveCycles("car")||this.haveCycles("cdr")}return!!(this.cycles&&this.cycles[e])};function markCycles(e){var r=[];var i=[];var a=[];function o(e){if(!r.includes(e)){r.push(e)}}function c(e,r,n,t){if(n instanceof Pair){if(t.includes(n)){if(!a.includes(n)){a.push(n)}if(!e.cycles){e.cycles={}}e.cycles[r]=n;if(!i.includes(e)){i.push(e)}return true}}}var u=trampoline(function e(r,n){if(r instanceof Pair){delete r.ref;delete r.cycles;o(r);n.push(r);var t=c(r,"car",r.car,n);var i=c(r,"cdr",r.cdr,n);if(!t){u(r.car,n.slice())}if(!i){return new Thunk(function(){return e(r.cdr,n.slice())})}}});function n(e,r){if(e.cycles[r]instanceof Pair){var n=t.indexOf(e.cycles[r]);e.cycles[r]="#".concat(n,"#")}}u(e,[]);var t=r.filter(function(e){return a.includes(e)});t.forEach(function(e,r){e.ref="#".concat(r,"=")});i.forEach(function(e){n(e,"car");n(e,"cdr")})}var pair_to_string=function(){var f=function e(r,n){var t=[];if(r.ref){t.push(r.ref+"(")}else if(!n){t.push("(")}return t};var p=function e(r,n){if(is_debug());if(!n||r.ref){return[")"]}return[]};return trampoline(function e(r,n){var t=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:{};var i=t.nested,a=i===void 0?false:i,o=t.result,c=o===void 0?[]:o,u=t.cont,s=u===void 0?function(){c.push.apply(c,toConsumableArray(p(r,a)))}:u;c.push.apply(c,toConsumableArray(f(r,a)));var l;if(r.cycles&&r.cycles.car){l=r.cycles.car}else{l=toString(r.car,n,true,{result:c,cont:s})}if(l!==undefined$1){c.push(l)}return new Thunk(function(){if(r.cdr instanceof Pair){if(r.cycles&&r.cycles.cdr){c.push(" . ");c.push(r.cycles.cdr)}else{if(r.cdr.ref){c.push(" . ")}else{c.push(" ")}return e(r.cdr,n,{nested:true,result:c,cont:s})}}else if(r.cdr!==nil){c.push(" . ");c.push(toString(r.cdr,n))}},s)})}();Pair.prototype.toString=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},n=r.nested,t=n===void 0?false:n;if(is_debug()){var i=[];pair_to_string(this,e,{result:i});return i.join("")}var a=[];if(this.ref){a.push(this.ref+"(")}else if(!t){a.push("(")}var o;if(this.cycles&&this.cycles.car){o=this.cycles.car}else{o=toString(this.car,e,true)}if(o!==undefined$1){a.push(o)}if(this.cdr instanceof Pair){if(this.cycles&&this.cycles.cdr){a.push(" . ");a.push(this.cycles.cdr)}else{if(this.cdr.ref){a.push(" . ")}else{a.push(" ")}var c=this.cdr.toString(e,{nested:true});a.push(c)}}else if(this.cdr!==nil){a=a.concat([" . ",toString(this.cdr,e,true)])}if(!t||this.ref){a.push(")")}return a.join("")};Pair.prototype.set=function(e,r){this[e]=r;if(r instanceof Pair){this.markCycles()}};Pair.prototype.append=function(e){if(e instanceof Array){return this.append(Pair.fromArray(e))}var r=this;if(r.car===undefined$1){if(e instanceof Pair){this.car=e.car;this.cdr=e.cdr}else{this.car=e}}else if(e!==nil){while(true){if(r instanceof Pair&&r.cdr!==nil){r=r.cdr}else{break}}r.cdr=e}return this};function abs(e){return e<0?-e:e}function seq_compare(e,r){var n=toArray(r),t=n[0],i=n.slice(1);while(i.length>0){var a=i,o=slicedToArray(a,1),c=o[0];if(!e(t,c)){return false}var u=i;var s=toArray(u);t=s[0];i=s.slice(1)}return true}function equal(e,r){if(typeof e==="function"&&typeof r==="function"){return unbind(e)===unbind(r)}else if(e instanceof LNumber&&r instanceof LNumber){var n;if(e.__type__===r.__type__){if(e.__type__==="complex"){n=e.im.__type__===r.im.__type__&&e.re.__type__===r.re.__type__}else{n=true}return n&&e.cmp(r)===0}return false}else if(typeof e==="number"||typeof r==="number"){e=LNumber(e);r=LNumber(r);return e.__type__===r.__type__&&e.cmp(r)===0}else if(e instanceof LCharacter&&r instanceof LCharacter){return e.__char__===r.__char__}else if(e instanceof LSymbol&&r instanceof LSymbol){return e.__name__===r.__name__}else{return e===r}}function same_atom(e,r){if(type(e)!==type(r)){return false}if(!is_atom(e)){return false}if(e instanceof RegExp){return e.source===r.source}if(e instanceof LString){return e.valueOf()===r.valueOf()}return equal(e,r)}function is_atom(e){return e instanceof LSymbol||LString.isString(e)||e instanceof LCharacter||e instanceof LNumber||e===true||e===false}var truncate=function(){if(Math.trunc){return Math.trunc}else{return function(e){if(e<0){return Math.ceil(e)}else{return Math.floor(e)}}}}();function Macro(e,r,n,t){if(typeof this!=="undefined"&&this.constructor!==Macro||typeof this==="undefined"){return new Macro(e,r)}typecheck("Macro",e,"string",1);typecheck("Macro",r,"function",2);if(n){if(t){this.__doc__=n}else{this.__doc__=trim_lines(n)}}this.__name__=e;this.__fn__=r}Macro.defmacro=function(e,r,n,t){var i=new Macro(e,r,n,t);i.__defmacro__=true;return i};Macro.prototype.invoke=function(e,r,n){var t=r.env,i=r.dynamic_scope,a=r.error;var o={dynamic_scope:i,error:a,macro_expand:n};var c=this.__fn__.call(t,e,o,this.__name__);return c};Macro.prototype.toString=function(){return"#")};var macro="define-macro";var recur_guard=-1e4;function macro_expand(a){return function(){var n=asyncToGenerator(regenerator.mark(function e(n,m){var t,h,i;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:i=function e(){i=asyncToGenerator(regenerator.mark(function e(n,t,i){var a,o,c,u,s,l,f,p,d;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!(n instanceof Pair&&n.car instanceof LSymbol)){r.next=24;break}if(!n.data){r.next=3;break}return r.abrupt("return",n);case 3:a=i.get(n.car,{throwError:false});if(!(a instanceof Macro&&a.__defmacro__)){r.next=24;break}o=a instanceof Syntax?n:n.cdr;r.next=8;return a.invoke(o,_objectSpread(_objectSpread({},m),{},{env:i}),true);case 8:c=r.sent;if(!(a instanceof Syntax)){r.next=17;break}u=c,s=u.expr,l=u.scope;if(!(s instanceof Pair)){r.next=16;break}if(!(t!==-1&&t<=1||t")}return"#"};Syntax.className="syntax";function extract_patterns(e,r,w,L){var n=arguments.length>4&&arguments[4]!==undefined$1?arguments[4]:{};var x={"...":{symbols:{},lists:[]},symbols:{}};var S=n.expansion,k=n.define;function P(e){if(is_debug()){console.log(e)}}P(w);function N(e,r){var n=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:[];var t=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:false;P({code:r&&toString(r,true),pattern:e&&toString(e,true)});if(is_atom(e)&&!(e instanceof LSymbol)){return same_atom(e,r)}if(e instanceof LSymbol&&w.includes(e.valueOf())){var i=S.ref(r);if(LSymbol.is(r,e)){if(typeof i==="undefined"){return true}return i===k||i===global_env}return false}if(e instanceof Pair&&e.car instanceof Pair&&e.car.cdr instanceof Pair&&LSymbol.is(e.car.cdr.car,L)){P(">> 0");if(r===nil){P({pattern:e.toString()});if(e.car.car instanceof LSymbol){if(e.car.cdr instanceof Pair&&LSymbol.is(e.car.cdr.car,L)){var a=e.car.car.valueOf();var o=e.lastPair();if(LSymbol.is(o.car,L)){x["..."].symbols[a]=null;return true}else{return false}}var c=e.car.car.valueOf();if(x["..."].symbols[c]){throw new Error("syntax: named ellipsis can only "+"appear onces")}x["..."].symbols[c]=r}}}if(e instanceof Pair&&e.cdr instanceof Pair&&LSymbol.is(e.cdr.car,L)){if(e.cdr.cdr!==nil){if(e.cdr.cdr instanceof Pair){var u=e.cdr.cdr.length();var s=r.length();var l=r;while(s-1>u){l=l.cdr;s--}var f=l.cdr;l.cdr=nil;if(!N(e.cdr.cdr,f,n,t)){return false}}}if(e.car instanceof LSymbol){var p=e.car.__name__;if(x["..."].symbols[p]&&!n.includes(p)&&!t){throw new Error("syntax: named ellipsis can only appear onces")}P(">> 1");if(r===nil){P(">> 2");if(t){P("NIL");x["..."].symbols[p]=nil}else{P("NULL");x["..."].symbols[p]=null}}else if(r instanceof Pair&&(r.car instanceof Pair||r.car===nil)){P(">> 3 "+t);if(t){if(x["..."].symbols[p]){var d=x["..."].symbols[p];x["..."].symbols[p]=d.append(new Pair(r,nil))}else{x["..."].symbols[p]=new Pair(r,nil)}}else{P(">> 4");x["..."].symbols[p]=new Pair(r,nil)}}else{P(">> 6");if(r instanceof Pair){P(">> 7 "+t);n.push(p);if(!x["..."].symbols[p]){x["..."].symbols[p]=new Pair(r,nil)}else{var m=x["..."].symbols[p];x["..."].symbols[p]=m.append(new Pair(r,nil))}P({IIIIII:x["..."].symbols[p].toString()})}else{P(">> 8");return false}}return true}else if(e.car instanceof Pair){var h=toConsumableArray(n);if(r===nil){P(">> 9");x["..."].lists.push(nil);return true}P(">> 10");var v=r;while(v instanceof Pair){if(!N(e.car,v.car,h,true)){return false}v=v.cdr}return true}return false}if(e instanceof LSymbol){if(LSymbol.is(e,L)){throw new Error("syntax: invalid usage of ellipsis")}P(">> 11");var _=e.__name__;if(w.includes(_)){return true}P({name:_,ellipsis:t});if(t){x["..."].symbols[_]=x["..."].symbols[_]||[];x["..."].symbols[_].push(r)}x.symbols[_]=r;if(!x.symbols[_]);return true}if(e instanceof Pair&&r instanceof Pair){P(">> 12");P({a:12,code:r&&r.toString(),pattern:e.toString()});if(r.cdr===nil){var y=e.car instanceof LSymbol&&e.cdr instanceof LSymbol;if(y){if(!N(e.car,r.car,n,t)){return false}P(">> 12 | 1");var b=e.cdr.valueOf();if(!(b in x.symbols)){x.symbols[b]=nil}b=e.car.valueOf();if(!(b in x.symbols)){x.symbols[b]=r.car}return true}}P({pattern:e.toString(),code:r.toString()});if(e.cdr instanceof Pair&&e.car instanceof LSymbol&&e.cdr.cdr instanceof Pair&&e.cdr.car instanceof LSymbol&&LSymbol.is(e.cdr.cdr.car,L)&&e.cdr.cdr.cdr instanceof Pair&&!LSymbol.is(e.cdr.cdr.cdr.car,L)&&N(e.car,r.car,n,t)&&N(e.cdr.cdr.cdr,r.cdr,n,t)){var g=e.cdr.car.__name__;P({pattern:e.car.toString(),code:r.car.toString(),name:g});if(w.includes(g)){return true}x["..."].symbols[g]=null;return true}P("recur");if(N(e.car,r.car,n,t)&&N(e.cdr,r.cdr,n,t)){return true}}else if(e===nil&&(r===nil||r===undefined$1)){return true}else if(e.car instanceof Pair&&LSymbol.is(e.car.car,L)){throw new Error("syntax: invalid usage of ellipsis")}else{return false}}if(N(e,r)){return x}}function clear_gensyms(e,i){function a(r){if(r instanceof Pair){if(!i.length){return r}var e=a(r.car);var n=a(r.cdr);return new Pair(e,n)}else if(r instanceof LSymbol){var t=i.find(function(e){return e.gensym===r});if(t){return LSymbol(t.name)}return r}else{return r}}return a(e)}function transform_syntax(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:{};var P=e.bindings,r=e.expr,N=e.scope,i=e.symbols,a=e.names,O=e.ellipsis;var o={};function c(e){if(e instanceof LSymbol){return true}return["string","symbol"].includes(_typeof_1(e))}function j(e){if(!c(e)){var r=type(e);throw new Error("syntax: internal error, need symbol got ".concat(r))}var n=e.valueOf();if(n===O){throw new Error("syntax: internal error, ellipis not transformed")}var t=_typeof_1(n);if(["string","symbol"].includes(t)&&n in P.symbols){return P.symbols[n]}if(i.includes(n)){return LSymbol(n)}return u(n)}function E(e){if(is_debug()){console.log(e)}}function u(e){if(!o[e]){var r=N.ref(e);var n=gensym(e);if(r){var t=N.get(e);N.set(n,t)}a.push({name:e,gensym:n});o[e]=n}return o[e]}function A(e,r,n){var t=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:function(){};var i=n.nested;E(" ==> "+e.toString());E(r);if(e instanceof LSymbol){var a=e.valueOf();E("[t 1");if(r[a]){if(r[a]instanceof Pair){var o=r[a],c=o.car,u=o.cdr;if(i){var s=c.car,l=c.cdr;if(l!==nil){t(a,new Pair(l,nil))}return s}if(u!==nil){t(a,u)}return c}else if(r[a]instanceof Array){t(a,r[a].slice(1));return r[a][0]}}return j(a)}if(e instanceof Pair){if(e.car instanceof LSymbol&&e.cdr instanceof Pair&&LSymbol.is(e.cdr.car,O)){E("[t 2");var f=e.car.valueOf();var p=r[f];E({name:f,bindings:r,item:p});if(p===null){return}else if(p){E({b:r[f].toString()});if(p instanceof Pair){E("[t 2 Pair "+i);E({______:p.toString()});var d=p.car,m=p.cdr;if(i){if(m!==nil){E("|| next 1");t(f,m)}E({car:d.toString()});return d}else{if(d.cdr!==nil){E("|| next 2");t(f,new Pair(d.cdr,m))}E({car:d.car.toString()});return d.car}}else if(p instanceof Array){E("[t 2 Array "+i);if(i){t(f,p.slice(1));return Pair.fromArray(p)}else{var h=p.slice(1);if(h.length){t(f,h)}return p[0]}}else{return p}}}E("[t 3 recur "+e.toString());var v=A(e.car,r,n,t);var _=A(e.cdr,r,n,t);return new Pair(v,_)}return e}function F(r,n){var e=Object.values(r);var t=Object.getOwnPropertySymbols(r);if(t.length){e.push.apply(e,toConsumableArray(t.map(function(e){return r[e]})))}return e.length&&e.every(function(e){if(e===null){return!n}return e instanceof Pair||e===nil||e instanceof Array&&e.length})}function I(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}function C(i){var e=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},r=e.disabled;E("traverse>> "+i.toString());if(i instanceof Pair){if(!r&&i.car instanceof Pair&&LSymbol.is(i.car.car,O)){return C(i.car.cdr,{disabled:true})}if(i.cdr instanceof Pair&&LSymbol.is(i.cdr.car,O)&&!r){E(">> 1");var n=P["..."].symbols;var t=Object.values(n);if(t.length&&t.every(function(e){return e===null})){return C(i.cdr.cdr,{disabled:r})}var a=I(n);var o=i.car instanceof LSymbol&&LSymbol.is(i.cdr.cdr.car,O);if(i.car instanceof Pair||o){if(P["..."].lists[0]===nil){return nil}var c=i.car;if(o){c=new Pair(i.car,new Pair(i.cdr.car,nil))}E(">> 2");var u;if(a.length){E(">> 2 (a)");var s=_objectSpread({},n);u=nil;var l=function e(){if(!F(s)){return"break"}var t={};var r=function e(r,n){t[r]=n};var n=A(c,s,{nested:true},r);if(n!==undefined$1){if(o){if(u===nil){u=n}else{u=u.append(n)}}else{u=new Pair(n,u)}}s=t};while(true){var f=l();if(f==="break")break}if(u!==nil&&!o){u=u.reverse()}if(i.cdr.cdr!==nil&&!LSymbol.is(i.cdr.cdr.car,O)){var p=C(i.cdr.cdr,{disabled:r});return u.append(p)}return u}else{E(">> 3");var d=A(i.car,n,{nested:true});if(d){return new Pair(d,nil)}return nil}}else if(i.car instanceof LSymbol){E(">> 4");if(LSymbol.is(i.cdr.cdr.car,O)){E(">> 4 (a)")}else{E(">> 4 (b)")}var m=i.car.__name__;var h=defineProperty({},m,n[m]);var v=n[m]===null;var _=nil;var y=function e(){if(!F(h,true)){E({bind:h});return"break"}var t={};var r=function e(r,n){t[r]=n;if(is_debug()){console.log({NEWBIND:t[r].toString()})}};var n=A(i,h,{nested:false},r);E({value:n.toString()});if(typeof n!=="undefined"){_=new Pair(n,_)}h=t};while(true){var b=y();if(b==="break")break}if(_!==nil){_=_.reverse()}if(i.cdr instanceof Pair){if(i.cdr.cdr instanceof Pair||i.cdr.cdr instanceof LSymbol){var g=C(i.cdr.cdr,{disabled:r});if(v){return g}E("<<<< 1");_.append(g)}}E("<<<< 2");return _}}var w=N.get(i.car,{throwError:false});var L=w instanceof Macro&&w.__name__==="syntax-rules";var x=C(i.car,{disabled:r});var S;if(L){if(i.cdr.car instanceof LSymbol){S=new Pair(C(i.cdr.car,{disabled:r}),new Pair(i.cdr.cdr.car,C(i.cdr.cdr.cdr,{disabled:r})))}else{S=new Pair(i.cdr.car,C(i.cdr.cdr,{disabled:r}))}}else{S=C(i.cdr,{disabled:r})}E({a:true,car:i.car.toString(),cdr:i.cdr.toString(),head:x&&x.toString(),rest:S&&S.toString()});return new Pair(x,S)}if(i instanceof LSymbol){if(r&&LSymbol.is(i,O)){return i}var k=j(i);if(typeof k!=="undefined"){return k}}return i}return C(r,{})}function isNull(e){return typeof e==="undefined"||e===nil||e===null}function isPromise(e){return e instanceof Promise||e&&typeof e!=="undefined"&&typeof e.then==="function"}function box(e){switch(_typeof_1(e)){case"string":return LString(e);case"number":if(!Number.isNaN(e)){return LNumber(e)}}return e}function map_object(t,i){var e=Object.getOwnPropertyNames(t);var r=Object.getOwnPropertySymbols(t);e.concat(r).forEach(function(e){var r=i(t[e]);var n=Object.getOwnPropertyDescriptor(t,e);if(!n||n.writable&&t[e]!==r){t[e]=r}});return t}function unbox(r){var e=[LString,LCharacter,LNumber].some(function(e){return r instanceof e});if(e){return r.valueOf()}if(r instanceof Array){return r.map(unbox)}if(is_plain_object(r)){return map_object(r,unbox)}return r}function patchValue(e,r){if(e instanceof Pair){e.markCycles();return quote(e)}if(typeof e==="function"){if(r){return bind(e,r)}}return box(e)}function unbind(e){if(is_bound(e)){return e[__fn__]}return e}function bind(r,e){if(r[Symbol["for"]("__bound__")]){return r}var n=r.bind(e);var t=Object.getOwnPropertyNames(r).filter(filter_fn_names);t.forEach(function(e){try{n[e]=r[e]}catch(e){}});hidden_prop(n,"__fn__",r);hidden_prop(n,"__context__",e);hidden_prop(n,"__bound__",true);if(isNativeFunction(r)){hidden_prop(n,"__native__",true)}n.valueOf=function(){return r};return n}function is_object_bound(e){return is_bound(e)&&e[Symbol["for"]("__context__")]===Object}function is_bound(e){return!!(typeof e==="function"&&e[__fn__])}function lips_context(e){if(typeof e==="function"){var r=e[__context__];if(r&&(r===lips||r.constructor&&r.constructor.__class__)){return true}}return false}function is_port(e){function r(e){return e instanceof InputPort||e instanceof OutputPort}if(typeof e==="function"){if(r(e)){return true}if(r(e[__context__])){return true}}return false}var __context__=Symbol["for"]("__context__");var __fn__=Symbol["for"]("__fn__");var exluded_names=["name","length","caller","callee","arguments","prototype"];function filter_fn_names(e){return!exluded_names.includes(e)}function hidden_prop(e,r,n){Object.defineProperty(e,Symbol["for"](r),{get:function e(){return n},set:function e(){},configurable:false,enumerable:false})}function setFnLength(r,n){try{Object.defineProperty(r,"length",{get:function e(){return n}});return r}catch(e){var t=new Array(n).fill(0).map(function(e,r){return"a"+r}).join(",");var i=new Function("f","return function(".concat(t,") {\n return f.apply(this, arguments);\n };"));return i(r)}}function isNativeFunction(e){var r=Symbol["for"]("__native__");return typeof e==="function"&&e.toString().match(/\{\s*\[native code\]\s*\}/)&&(e.name.match(/^bound /)&&e[r]===true||!e.name.match(/^bound /)&&!e[r])}function let_macro(e){var m;switch(e){case Symbol["for"]("letrec"):m="letrec";break;case Symbol["for"]("let"):m="let";break;case Symbol["for"]("let*"):m="let*";break;default:throw new Error("Invalid let_macro value")}return Macro.defmacro(m,function(r,e){var a=e.dynamic_scope,o=e.error,n=e.macro_expand;var c;if(r.car instanceof LSymbol){if(!(r.cdr.car instanceof Pair||r.cdr.car===nil)){throw new Error("let require list of pairs")}var t;if(r.cdr.car===nil){c=nil;t=nil}else{t=r.cdr.car.map(function(e){return e.car});c=r.cdr.car.map(function(e){return e.cdr.car})}return Pair.fromArray([LSymbol("letrec"),[[r.car,Pair(LSymbol("lambda"),Pair(t,r.cdr.cdr))]],Pair(r.car,c)])}else if(n){return}var u=this;c=this.get("list->array")(r.car);var s=u.inherit(m);var l,f;if(m==="let*"){f=s}else if(m==="let"){l=[]}var p=0;function d(){var e=new Pair(new LSymbol("begin"),r.cdr);return evaluate(e,{env:s,dynamic_scope:a,error:o})}return function r(){var n=c[p++];if(a){a=m==="let*"?s:u}if(!n){if(l&&l.length){var e=l.map(function(e){return e.value});var t=e.filter(isPromise);if(t.length){return Promise.all(e).then(function(e){for(var r=0,n=e.length;r1&&arguments[1]!==undefined$1?arguments[1]:{},n=r.dynamic_scope,t=r.error;var i=this;if(n){n=this}var a=e;var o=[];while(a instanceof Pair){o.push(evaluate(a.car,{env:i,dynamic_scope:n,error:t}));a=a.cdr}var c=o.filter(isPromise).length;if(c){return Promise.all(o).then(u.bind(this))}else{return u.call(this,o)}})}function guardMathCall(e){for(var r=arguments.length,n=new Array(r>1?r-1:0),t=1;t2?t-2:0),a=2;a1&&arguments[1]!==undefined$1?arguments[1]:null;return function(){for(var e=arguments.length,r=new Array(e),n=0;n1?e-1:0),n=1;n=o){return a.apply(this,t)}else{return i}}return i.apply(this,arguments)}}function limit(t,i){typecheck("limit",i,"function",2);return function(){for(var e=arguments.length,r=new Array(e),n=0;n1?t-1:0),a=1;a1){e=e.toLowerCase();if(LCharacter.__names__[e]){this.__name__=e;this.__char__=LCharacter.__names__[e]}else{throw new Error("Internal: Unknown named character")}}else{this.__char__=e;var r=LCharacter.__rev_names__[e];if(r){this.__name__=r}}}LCharacter.__names__=characters;LCharacter.__rev_names__={};Object.keys(LCharacter.__names__).forEach(function(e){var r=LCharacter.__names__[e];LCharacter.__rev_names__[r]=e});LCharacter.prototype.toUpperCase=function(){return LCharacter(this.__char__.toUpperCase())};LCharacter.prototype.toLowerCase=function(){return LCharacter(this.__char__.toLowerCase())};LCharacter.prototype.toString=function(){return"#\\"+(this.__name__||this.__char__)};LCharacter.prototype.valueOf=function(){return this.__char__};function LString(e){if(typeof this!=="undefined"&&!(this instanceof LString)||typeof this==="undefined"){return new LString(e)}if(e instanceof Array){this._string=e.map(function(e,r){typecheck("LString",e,"character",r+1);return e.toString()}).join("")}else{this._string=e.valueOf()}}{var ignore=["length","constructor"];var _keys=Object.getOwnPropertyNames(String.prototype).filter(function(e){return!ignore.includes(e)});var wrap=function e(t){return function(){for(var e=arguments.length,r=new Array(e),n=0;n0){n.push(this._string.substring(0,e))}n.push(r);if(e1&&arguments[1]!==undefined$1?arguments[1]:false;if(e instanceof LNumber){return e}if(typeof this!=="undefined"&&!(this instanceof LNumber)||typeof this==="undefined"){return new LNumber(e,r)}if(typeof e==="undefined"){throw new Error("Invalid LNumber constructor call")}var n=LNumber.getType(e);if(LNumber.types[n]){return LNumber.types[n](e,r)}var t=e instanceof Array&&LString.isString(e[0])&&LNumber.isNumber(e[1]);if(e instanceof LNumber){return LNumber(e.value)}if(!LNumber.isNumber(e)&&!t){throw new Error("You can't create LNumber from ".concat(type(e)))}if(e===null){e=0}var i;if(t){var a=e,o=slicedToArray(a,2),c=o[0],u=o[1];if(c instanceof LString){c=c.valueOf()}if(u instanceof LNumber){u=u.valueOf()}var s=c.match(/^([+-])/);var l=false;if(s){c=c.replace(/^[+-]/,"");if(s[1]==="-"){l=true}}}if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){if(t){var f;switch(u){case 8:f="0o";break;case 16:f="0x";break;case 2:f="0b";break;case 10:f="";break}if(typeof f==="undefined"){var p=BigInt(u);i=toConsumableArray(c).map(function(e,r){return BigInt(parseInt(e,u))*Math.pow(p,BigInt(r))}).reduce(function(e,r){return e+r})}else{i=BigInt(f+c)}}else{i=BigInt(e)}if(l){i*=BigInt(-1)}}else{i=e}return LBigInteger(i,true)}else if(typeof BN!=="undefined"&&!(e instanceof BN)){if(e instanceof Array){return LBigInteger(construct(BN,toConsumableArray(e)))}return LBigInteger(new BN(e))}else if(t){this.value=parseInt(c,u)}else{this.value=e}}LNumber.types={float:function e(r){var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;return new LFloat(r,n)},complex:function e(r){var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;if(!LNumber.isComplex(r)){r={im:0,re:r}}return new LComplex(r,n)},rational:function e(r){var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;if(!LNumber.isRational(r)){r={num:r,denom:1}}return new LRational(r,n)}};function LComplex(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof LComplex)||typeof this==="undefined"){return new LComplex(e,r)}if(e instanceof LComplex){return LComplex({im:e.im,re:e.re})}if(LNumber.isNumber(e)&&r){e={im:0,re:e.valueOf()}}else if(!LNumber.isComplex(e)){throw new Error("Invalid constructor call for LComplex")}var n=e.im instanceof LNumber?e.im:LNumber(e.im);var t=e.re instanceof LNumber?e.re:LNumber(e.re);if(n.cmp(0)===0&&!r){return t}this.im=n;this.re=t;this.__type__="complex"}LComplex.prototype=Object.create(LNumber.prototype);LComplex.prototype.constructor=LComplex;LComplex.prototype.toRational=function(e){if(LNumber.isFloat(this.im)&&LNumber.isFloat(this.re)){var r=LFloat(this.im).toRational(e);var n=LFloat(this.re).toRational(e);return LComplex({im:r,re:n})}return this};LComplex.prototype.add=function(e){return this.complex_op(e,function(e,r,n,t){return{re:e.add(r),im:n.add(t)}})};LComplex.prototype.factor=function(){if(this.im instanceof LFloat||this.im instanceof LFloat){var e=this.re,r=this.im;var n,t;if(e instanceof LFloat){n=e.toRational().mul(e.toRational())}else{n=e.mul(e)}if(r instanceof LFloat){t=r.toRational().mul(r.toRational())}else{t=r.mul(r)}return n.add(t)}else{return this.re.mul(this.re).add(this.im.mul(this.im))}};LComplex.prototype.modulus=function(){return this.factor().sqrt()};LComplex.prototype.sqrt=function(){var e=this.modulus();var r,n;if(e.cmp(0)===0){r=n=e}else if(this.re.cmp(0)===1){r=LFloat(.5).mul(e.add(this.re)).sqrt();n=this.im.div(r).div(2)}else{n=LFloat(.5).mul(e.sub(this.re)).sqrt();if(this.im.cmp(0)===-1){n=n.sub()}r=this.im.div(n).div(2)}return LComplex({im:n,re:r})};LComplex.prototype.div=function(e){if(LNumber.isNumber(e)&&!LNumber.isComplex(e)){e=LComplex({im:0,re:e})}else if(!LNumber.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var r=this.coerce(e),n=slicedToArray(r,2),t=n[0],i=n[1];var a=LComplex({re:i.re,im:i.im.sub()});var o=i.factor().valueOf();var c=t.mul(a);var u=c.re.op("/",o);var s=c.im.op("/",o);return LComplex({re:u,im:s})};LComplex.prototype.sub=function(e){return this.complex_op(e,function(e,r,n,t){return{re:e.sub(r),im:n.sum(t)}})};LComplex.prototype.mul=function(e){return this.complex_op(e,function(e,r,n,t){var i={re:e.mul(r).sub(n.mul(t)),im:e.mul(t).add(r.mul(n))};return i})};LComplex.prototype.complex_op=function(e,r){if(LNumber.isNumber(e)&&!LNumber.isComplex(e)){if(!(e instanceof LNumber)){e=LNumber(e)}var n=e.asType(0);e={im:n,re:e}}else if(!LNumber.isComplex(e)){throw new Error("[LComplex::add] Invalid value")}var t=e.re instanceof LNumber?e.re:this.re.asType(e.re);var i=e.im instanceof LNumber?e.im:this.im.asType(e.im);var a=r(this.re,t,this.im,i);if("im"in a&&"re"in a){var o=LComplex(a,true);return o}return a};LComplex._op={"+":"add","-":"sub","*":"mul","/":"div"};LComplex.prototype._op=function(e,r){var n=LComplex._op[e];return this[n](r)};LComplex.prototype.cmp=function(e){var r=this.coerce(e),n=slicedToArray(r,2),t=n[0],i=n[1];var a=t.re.coerce(i.re),o=slicedToArray(a,2),c=o[0],u=o[1];var s=c.cmp(u);if(s!==0){return s}else{var l=t.im.coerce(i.im),f=slicedToArray(l,2),p=f[0],d=f[1];return p.cmp(d)}};LComplex.prototype.valueOf=function(){};LComplex.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 LFloat(e){if(typeof this!=="undefined"&&!(this instanceof LFloat)||typeof this==="undefined"){return new LFloat(e)}if(!LNumber.isNumber(e)){throw new Error("Invalid constructor call for LFloat")}if(e instanceof LNumber){return LFloat(e.valueOf())}if(typeof e==="number"){this.value=e;this.__type__="float"}}LFloat.prototype=Object.create(LNumber.prototype);LFloat.prototype.constructor=LFloat;LFloat.prototype.toString=function(){var e=this.value.toString();if(!LNumber.isFloat(this.value)&&!e.match(/e/i)){return e+".0"}return e.replace(/^([0-9]+)e/,"$1.0e")};LFloat.prototype._op=function(e,r){if(r instanceof LNumber){r=r.value}var n=LNumber._ops[e];if(e==="/"&&this.value===0&&r===0){return NaN}return LFloat(n(this.value,r))};LFloat.prototype.toRational=function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:null;if(e===null){return toRational(this.value.valueOf())}return approxRatio(e.valueOf())(this.value.valueOf())};var toRational=approxRatio(1e-10);function approxRatio(t){return function(e){var r=function e(t,r,n){var i=function e(r,n){return n0){i=simplest_rational2(t,n)}else if(t.cmp(n)<=0){i=n}else if(n.cmp(0)>0){i=simplest_rational2(n,t)}else if(r.cmp(0)<0){i=LNumber(simplest_rational2(t.sub(),n.sub())).sub()}else{i=LNumber(0)}if(LNumber.isFloat(r)||LNumber.isFloat(e)){return LFloat(i)}return i}function simplest_rational2(e,r){var n=LNumber(e).floor();var t=LNumber(r).floor();if(e.cmp(n)<1){return n}else if(n.cmp(t)===0){var i=LNumber(1).div(r.sub(t));var a=LNumber(1).div(e.sub(n));return n.add(LNumber(1).div(simplest_rational2(i,a)))}else{return n.add(LNumber(1))}}function LRational(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;if(typeof this!=="undefined"&&!(this instanceof LRational)||typeof this==="undefined"){return new LRational(e,r)}if(!LNumber.isRational(e)){throw new Error("Invalid constructor call for LRational")}var n=LNumber(e.num);var t=LNumber(e.denom);if(!r&&t.cmp(0)!==0){var i=n.op("%",t).cmp(0)===0;if(i){return LNumber(n.div(t))}}this.num=n;this.denom=t;this.__type__="rational"}LRational.prototype=Object.create(LNumber.prototype);LRational.prototype.constructor=LRational;LRational.prototype.pow=function(e){var r=e.cmp(0);if(r===0){return LNumber(1)}if(r===-1){e=e.sub();var n=this.denom.pow(e);var t=this.num.pow(e);return LRational({num:n,denom:t})}var i=this;e=e.valueOf();while(e>1){i=i.mul(this);e--}return i};LRational.prototype.sqrt=function(){var e=this.num.sqrt();var r=this.denom.sqrt();if(e instanceof LFloat){e=(readOnlyError("num"),e.toRational())}if(r instanceof LFloat){r=(readOnlyError("denom"),r.toRational())}return LRational({num:e,denom:r})};LRational.prototype.abs=function(){var e=this.num;var r=this.denom;if(e.cmp(0)===-1){e=e.sub()}if(r.cmp(0)!==1){r=r.sub()}return LRational({num:e,denom:r})};LRational.prototype.cmp=function(e){return LNumber(this.valueOf(),true).cmp(e)};LRational.prototype.toString=function(){var e=this.num.gcd(this.denom);var r,n;if(e.cmp(1)!==0){r=this.num.div(e);if(r instanceof LRational){r=LNumber(r.valueOf(true))}n=this.denom.div(e);if(n instanceof LRational){n=LNumber(n.valueOf(true))}}else{r=this.num;n=this.denom}var t=this.cmp(0)<0;if(t){if(r.abs().cmp(n.abs())===0){return r.toString()}}else if(r.cmp(n)===0){return r.toString()}return r.toString()+"/"+n.toString()};LRational.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 LNumber._ops["/"](this.num.value,this.denom.value)}return LFloat(this.num.valueOf()).div(this.denom.valueOf())};LRational.prototype.mul=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=this.num.mul(e.num);var n=this.denom.mul(e.denom);return LRational({num:r,denom:n})}var t=LNumber.coerce(this,e),i=slicedToArray(t,2),a=i[0],o=i[1];return a.mul(o)};LRational.prototype.div=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=this.num.mul(e.denom);var n=this.denom.mul(e.num);return LRational({num:r,denom:n})}var t=LNumber.coerce(this,e),i=slicedToArray(t,2),a=i[0],o=i[1];var c=a.div(o);return c};LRational.prototype._op=function(e,r){return this[rev_mapping[e]](r)};LRational.prototype.sub=function(e){if(typeof e==="undefined"){return this.mul(-1)}if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=e.num.sub();var n=e.denom;return this.add(LRational({num:r,denom:n}))}if(!(e instanceof LNumber)){e=LNumber(e).sub()}else{e=e.sub()}var t=LNumber.coerce(this,e),i=slicedToArray(t,2),a=i[0],o=i[1];return a.add(o)};LRational.prototype.add=function(e){if(!(e instanceof LNumber)){e=LNumber(e)}if(LNumber.isRational(e)){var r=this.denom;var n=e.denom;var t=this.num;var i=e.num;var a,o;if(r!==n){o=n.mul(t).add(i.mul(r));a=r.mul(n)}else{o=t.add(i);a=r}return LRational({num:o,denom:a})}if(LNumber.isFloat(e)){return LFloat(this.valueOf()).add(e)}var c=LNumber.coerce(this,e),u=slicedToArray(c,2),s=u[0],l=u[1];return s.add(l)};function LBigInteger(e,r){if(typeof this!=="undefined"&&!(this instanceof LBigInteger)||typeof this==="undefined"){return new LBigInteger(e,r)}if(e instanceof LBigInteger){return LBigInteger(e.value,e._native)}if(!LNumber.isBigInteger(e)){throw new Error("Invalid constructor call for LBigInteger")}this.value=e;this._native=r;this.__type__="bigint"}LBigInteger.prototype=Object.create(LNumber.prototype);LBigInteger.prototype.constructor=LBigInteger;LBigInteger.bn_op={"+":"iadd","-":"isub","*":"imul","/":"idiv","%":"imod","|":"ior","&":"iand","~":"inot","<<":"ishrn",">>":"ishln"};LBigInteger.prototype._op=function(e,r){if(typeof r==="undefined"){if(LNumber.isBN(this.value)){e=LBigInteger.bn_op[e];return LBigInteger(this.value.clone()[e](),false)}return LBigInteger(LNumber._ops[e](this.value),true)}if(LNumber.isBN(this.value)&&LNumber.isBN(r.value)){e=LBigInteger.bn_op[e];return LBigInteger(this.value.clone()[e](r),false)}var n=LNumber._ops[e](this.value,r.value);if(e==="/"){var t=this.op("%",r).cmp(0)===0;if(t){return LNumber(n)}return LRational({num:this,denom:r})}return LBigInteger(n,true)};LBigInteger.prototype.sqrt=function(){var e;var r=this.cmp(0)<0;if(LNumber.isNative(this.value)){e=LNumber(Math.sqrt(r?-this.valueOf():this.valueOf()))}else if(LNumber.isBN(this.value)){e=r?this.value.neg().sqrt():this.value.sqrt()}if(r){return LComplex({re:0,im:e})}return e};LNumber.prototype.gcd=function(e){var r=this.abs();e=e.abs();if(e.cmp(r)===1){var n=r;r=e;e=n}while(true){r=r.rem(e);if(r.cmp(0)===0){return e}e=e.rem(r);if(e.cmp(0)===0){return r}}};LNumber.isFloat=function e(r){return r instanceof LFloat||Number(r)===r&&r%1!==0};LNumber.isNumber=function(e){return e instanceof LNumber||!Number.isNaN(e)&&LNumber.isNative(e)||LNumber.isBN(e)};LNumber.isComplex=function(e){var r=e instanceof LComplex||LNumber.isNumber(e.im)&&LNumber.isNumber(e.re);return r};LNumber.isRational=function(e){return e instanceof LRational||LNumber.isNumber(e.num)&&LNumber.isNumber(e.denom)};LNumber.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};LNumber.isBigInteger=function(e){return e instanceof LBigInteger||typeof e==="bigint"||LNumber.isBN(e)};LNumber.isBN=function(e){return typeof BN!=="undefined"&&e instanceof BN};LNumber.getArgsType=function(e,r){if(e instanceof LFloat||r instanceof LFloat){return LFloat}if(e instanceof LBigInteger||r instanceof LBigInteger){return LBigInteger}return LNumber};LNumber.prototype.toString=LNumber.prototype.toJSON=function(e){if(e>2&&e<36){return this.value.toString(e)}return this.value.toString()};LNumber.prototype.asType=function(e){var r=LNumber.getType(this);return LNumber.types[r]?LNumber.types[r](e):LNumber(e)};LNumber.prototype.isBigNumber=function(){return typeof this.value==="bigint"||typeof BN!=="undefined"&&!(this.value instanceof BN)};["floor","ceil","round"].forEach(function(e){LNumber.prototype[e]=function(){if(this["float"]||LNumber.isFloat(this.value)){return LNumber(Math[e](this.value))}else{return LNumber(Math[e](this.valueOf()))}}});LNumber.prototype.valueOf=function(){if(LNumber.isNative(this.value)){return Number(this.value)}else if(LNumber.isBN(this.value)){return this.value.toNumber()}};var matrix=function(){var e=function e(r,n){return[r,n]};return{bigint:{bigint:e,float:function e(r,n){return[LFloat(r.valueOf()),n]},rational:function e(r,n){return[{num:r,denom:1},n]},complex:function e(r,n){return[{im:0,re:r},n]}},float:{bigint:function e(r,n){return[r,n&&LFloat(n.valueOf())]},float:e,rational:function e(r,n){return[r,n&&LFloat(n.valueOf())]},complex:function e(r,n){return[{re:r,im:LFloat(0)},n]}},complex:{bigint:r("bigint"),float:r("float"),rational:r("rational"),complex:function e(r,n){var t=LNumber.coerce(r.re,n.re),i=slicedToArray(t,2),a=i[0],o=i[1];var c=LNumber.coerce(r.im,n.im),u=slicedToArray(c,2),s=u[0],l=u[1];return[{im:s,re:a},{im:l,re:o}]}},rational:{bigint:function e(r,n){return[r,n&&{num:n,denom:1}]},float:function e(r,n){return[LFloat(r.valueOf()),n]},rational:e,complex:function e(r,n){return[{im:coerce(r.__type__,n.im.__type__,0),re:coerce(r.__type__,n.re.__type__,r)},{im:coerce(r.__type__,n.im.__type__,n.im),re:coerce(r.__type__,n.re.__type__,n.re)}]}}};function r(n){return function(e,r){return[{im:coerce(n,e.im.__type__,e.im),re:coerce(n,e.re.__type__,e.re)},{im:coerce(n,e.im.__type__,0),re:coerce(n,r.__type__,r)}]}}}();function coerce(e,r,n){return matrix[e][r](n)[0]}LNumber.coerce=function(e,r){function n(e){if(e==="integer"){return"bigint"}return e}var t=n(LNumber.getType(e));var i=n(LNumber.getType(r));if(!matrix[t]){throw new Error("LNumber::coerce unknown lhs type ".concat(t))}else if(!matrix[t][i]){throw new Error("LNumber::coerce unknown rhs type ".concat(i))}return matrix[t][i](e,r).map(function(e){return LNumber(e,true)})};LNumber.prototype.coerce=function(e){if(!(typeof e==="number"||e instanceof LNumber)){throw new Error("LNumber: you can't coerce ".concat(type(e)))}if(typeof e==="number"){e=LNumber(e)}return LNumber.coerce(this,e)};LNumber.getType=function(e){if(e instanceof LNumber){return e.__type__}if(LNumber.isFloat(e)){return"float"}if(LNumber.isComplex(e)){return"complex"}if(LNumber.isRational(e)){return"rational"}if(typeof e==="number"){return"integer"}if(typeof BigInt!=="undefined"&&typeof e!=="bigint"||typeof BN!=="undefined"&&!(e instanceof BN)){return"bigint"}};LNumber.prototype.isFloat=function(){return!!(LNumber.isFloat(this.value)||this["float"])};var mapping={add:"+",sub:"-",mul:"*",div:"/",rem:"%",or:"|",and:"&",neg:"~",shl:">>",shr:"<<"};var rev_mapping={};Object.keys(mapping).forEach(function(r){rev_mapping[mapping[r]]=r;LNumber.prototype[r]=function(e){return this.op(mapping[r],e)}});LNumber._ops={"*":function e(r,n){return r*n},"+":function e(r,n){return r+n},"-":function e(r,n){if(typeof n==="undefined"){return-r}return r-n},"/":function e(r,n){return r/n},"%":function e(r,n){return r%n},"|":function e(r,n){return r|n},"&":function e(r,n){return r&n},"~":function e(r){return~r},">>":function e(r,n){return r>>n},"<<":function e(r,n){return r<=this._string.length){return eof}return LCharacter(this._string[this._in_char])};function OutputPort(e){if(typeof this!=="undefined"&&!(this instanceof OutputPort)||typeof this==="undefined"){return new OutputPort(e)}typecheck("OutputPort",e,"function");this.write=e}OutputPort.prototype.toString=function(){return"#"};function OutputStringPort(r){var n=this;if(typeof this!=="undefined"&&!(this instanceof OutputStringPort)||typeof this==="undefined"){return new OutputStringPort(r)}typecheck("OutputStringPort",r,"function");this._buffer=[];this.write=function(e){if(!LString.isString(e)){e=r(e)}else{e=e.valueOf()}n._buffer.push(e)}}OutputStringPort.prototype=Object.create(OutputPort.prototype);OutputStringPort.prototype.getString=function(){return this._buffer.map(function(e){return e.valueOf()}).join("")};OutputStringPort.prototype.constructor=OutputStringPort;function InputStringPort(e){var r=this;if(typeof this!=="undefined"&&!(this instanceof InputStringPort)||typeof this==="undefined"){return new InputStringPort(e)}typecheck("InputStringPort",e,"string");this._string=e.valueOf();this._index=0;this._in_char=0;this.read=function(){return r.get_next_tokens()}}InputStringPort.prototype=Object.create(InputPort.prototype);InputStringPort.prototype.constructor=InputStringPort;InputStringPort.prototype.read_line=function(){var e=this._string.substring(this._in_char);if(!e){return eof}var r=e.match(/([^\n])(?:\n|$)/)[0];this._in_char+=r.length;return r};var eof=new EOF;function EOF(){}EOF.prototype.toString=function(){return"#"};function Interpreter(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{};if(typeof this!=="undefined"&&!(this instanceof Interpreter)||typeof this==="undefined"){return new Interpreter(e,r)}if(typeof e==="undefined"){e="anonymous"}this.__env__=user_env.inherit(e,r);var n="**interaction-environment-defaults**";this.__env__.set(n,get_props(r).concat(n))}Interpreter.prototype.exec=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:false;var n=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:null;typecheck("Intepreter::exec",e,"string",1);typecheck("Intepreter::exec",r,"boolean",2);global_env.set("**interaction-environment**",this.__env__);if(n===null){n=this.__env__}return exec(e,n,r?n:false)};Interpreter.prototype.get=function(e){var r=this.__env__.get(e);if(typeof r==="function"){return r.bind(this.__env__)}return r};Interpreter.prototype.set=function(e,r){return this.__env__.set(e,r)};function Environment(e,r,n){if(arguments.length===1){if(_typeof_1(arguments[0])==="object"){e=arguments[0];r=null}else if(typeof arguments[0]==="string"){e={};r={};n=arguments[0]}}this.__docs__=new Map;this.__env__=e;this.__parent__=r;this.__name__=n||"anonymous"}Environment.prototype.list=function(){return get_props(this.__env__)};Environment.prototype.unset=function(e){if(e instanceof LSymbol){e=e.valueOf()}if(e instanceof LString){e=e.valueOf()}delete this.__env__[e]};Environment.prototype.inherit=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{};if(_typeof_1(e)==="object"){r=e}if(!e||_typeof_1(e)==="object"){e="child of "+(this.__name__||"unknown")}return new Environment(r||{},this,e)};Environment.prototype.doc=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:null;if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}if(r){this.__docs__.set(e,r);return this}if(this.__docs__.has(e)){return this.__docs__.get(e)}if(this.__parent__){return this.__parent__.doc(e)}};Environment.prototype.newFrame=function(e,r){var t=this.inherit("__frame__");t.set("parent.frame",doc("parent.frame",function(){var e=arguments.length>0&&arguments[0]!==undefined$1?arguments[0]:1;e=e.valueOf();var r=t.__parent__;if(!(r instanceof Environment)){return nil}if(e<=0){return r}var n=r.get("parent.frame");return n(e-1)},global_env.__env__["parent.frame"].__doc__));r.callee=e;t.set("arguments",r);return t};Environment.prototype._lookup=function(e){if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}if(this.__env__.hasOwnProperty(e)){return Value(this.__env__[e])}if(this.__parent__){return this.__parent__._lookup(e)}};Environment.prototype.toString=function(){return"#"};Environment.prototype.clone=function(){var r=this;var n={};Object.keys(this.__env__).forEach(function(e){n[e]=r.__env__[e]});return new Environment(n,this.__parent__,this.__name__)};Environment.prototype.merge=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:"merge";typecheck("Environment::merge",e,"environment");return this.inherit(r,e.__env__)};function Value(e){if(typeof this!=="undefined"&&!(this instanceof Value)||typeof this==="undefined"){return new Value(e)}this.value=e}Value.isUndefined=function(e){return e instanceof Value&&typeof e.value==="undefined"};Value.prototype.valueOf=function(){return this.value};function Values(e){if(e.length){if(e.length===1){return e[0]}}if(typeof this!=="undefined"&&!(this instanceof Values)||typeof this==="undefined"){return new Values(e)}this.__values__=e}Values.prototype.toString=function(){return this.__values__.map(function(e){return toString(e)}).join("\n")};Values.prototype.valueOf=function(){return this.__values__};Environment.prototype.get=function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{};var n=r.throwError,t=n===void 0?true:n;var i=e;if(i instanceof LSymbol||i instanceof LString){i=i.valueOf()}var a=this._lookup(i);if(a instanceof Value){if(Value.isUndefined(a)){return undefined$1}return patchValue(a.valueOf())}if(typeof i==="string"){var o=i.split(".").filter(Boolean);if(o.length>0){var c=toArray(o),u=c[0],s=c.slice(1);a=this._lookup(u);if(s.length){try{if(a instanceof Value){a=a.valueOf()}else{a=get(root,u);if(typeof a==="function"){a=unbind(a)}}return get.apply(void 0,[a].concat(toConsumableArray(s)))}catch(e){}}else if(a instanceof Value){return patchValue(a.valueOf())}}a=get(root,i)}if(typeof a!=="undefined"){return a}if(t){throw new Error("Unbound variable `"+i.toString()+"'")}};Environment.prototype.set=function(e,r){var n=arguments.length>2&&arguments[2]!==undefined$1?arguments[2]:null;if(LNumber.isNumber(r)){r=LNumber(r)}if(e instanceof LSymbol){e=e.__name__}if(e instanceof LString){e=e.valueOf()}this.__env__[e]=r;if(n){this.doc(e,n)}return this};Environment.prototype.has=function(e){return this.__env__.hasOwnProperty(e)};Environment.prototype.ref=function(e){var r=this;while(true){if(!r){break}if(r.has(e)){return r}r=r.__parent__}};Environment.prototype.parents=function(){var e=this;var r=[];while(e){r.unshift(e);e=e.__parent__}return r};function quote(e){if(isPromise(e)){return e.then(quote)}if(e instanceof Pair||e instanceof LSymbol){e.data=true}return e}var global_env=new Environment({nil:nil,undefined:undefined$1,true:true,false:false,null:null,NaN:NaN,stdout:new OutputPort(function(){var e;(e=console).log.apply(e,arguments)}),stdin:InputPort(function(){return new Promise(function(e){e(prompt(""))})}),"open-input-string":doc("open-input-string",function(e){typecheck("open-input-string",e,"string");return InputStringPort(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?":doc("output-port?",function(e){return e instanceof OutputPort},"(output-port? arg)\n\n Function return true if argument is output port."),"input-port?":doc("input-port?",function(e){return e instanceof InputPort},"(input-port? arg)\n\n Function return true if argument is input port."),"open-output-string":doc("open-output-string",function(){return OutputStringPort(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":doc("get-output-string",function(e){typecheck("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?":doc("eof-object?",function(e){return e===eof},"(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":doc("peek-char",function(e){typecheck("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":doc("read-line",function(e){if(typeof e==="undefined"){e=this.get("stdin")}typecheck("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":doc("read-char",function(e){if(typeof e==="undefined"){e=this.get("stdin")}typecheck("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:doc(function(){var r=asyncToGenerator(regenerator.mark(function e(n){var t,i;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!LString.isString(n)){r.next=4;break}r.next=3;return parse(n,this);case 3:return r.abrupt("return",r.sent[0]);case 4:if(n instanceof InputPort){t=n}else{t=this.get("stdin")}r.next=7;return t.read();case 7:i=r.sent;console.log(i);if(!(i===eof)){r.next=11;break}return r.abrupt("return",eof);case 11:r.next=13;return parse(i,this);case 13:return r.abrupt("return",r.sent[0]);case 14:case"end":return r.stop()}}},e,this)}));function e(e){return r.apply(this,arguments)}return e}(),"(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:doc(function e(r){if(r instanceof Pair){r=new lips.Formatter(r.toString(true))["break"]().format();this.get("display").call(this,r)}else{this.get("write").call(this,r)}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:doc(function e(){var r=this;var n=this.get("display");var t=this.get("newline");for(var i=arguments.length,a=new Array(i),o=0;o1?n-1:0),i=1;it.length){throw new Error("Not enough arguments")}var c=0;var u=this.get("repr");r=r.replace(a,function(e){var r=e[1];if(r==="~"){return"~"}else if(r==="%"){return"\n"}else{var n=t[c++];if(r==="a"){return u(n)}else{return u(n,true)}}});o=r.match(/~([\S])/);if(o){throw new Error("format: Unrecognized escape seqence ".concat(o[1]))}return r},"(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:doc(function e(r){var n=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:null;if(n===null){n=this.get("stdout")}var t=this.get("repr")(r);n.write.call(this,t)},"(display arg [port])\n\n Function send string to standard output or provied port."),error:doc(function e(){for(var r=arguments.length,n=new Array(r),t=0;t1&&arguments[1]!==undefined$1?arguments[1]:{},n=r.dynamic_scope,t=r.error;if(n){n=this}var i=this;var o;var c=evaluate(e.cdr.car,{env:this,dynamic_scope:n,error:t});c=resolvePromises(c);function u(r,n,t){if(isPromise(r)){return r.then(function(e){return u(r,e,t)})}if(isPromise(n)){return n.then(function(e){return u(r,e,t)})}if(isPromise(t)){return t.then(function(e){return u(r,n,e)})}i.get("set-obj!").call(i,r,n,t);return t}if(e.car instanceof Pair&&LSymbol.is(e.car.car,".")){var s=e.car.cdr.car;var l=e.car.cdr.cdr.car;var f=evaluate(s,{env:this,dynamic_scope:n,error:t});var p=evaluate(l,{env:this,dynamic_scope:n,error:t});return u(f,p,c)}if(!(e.car instanceof LSymbol)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var d=e.car.valueOf();o=this.ref(e.car.__name__);return unpromise(c,function(e){if(!o){var r=d.split(".");if(r.length>1){var n=r.pop();var t=r.join(".");var i=a.get(t,{throwError:false});if(i){u(i,n,e);return}}throw new Error("Unbound variable `"+d+"'")}o.set(d,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!":doc(new Macro("set!",function(e){if(!(e.car instanceof LSymbol)){throw new Error("unset! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}var r=e.car;var n=this.ref(r);if(n){delete n.__env__[r.__name__]}}),"(unset! name)\n\n Function delete specified name from environment."),"set-car!":doc("set-car!",function(e,r){typecheck("set-car!",e,"pair");e.car=r},"(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!":doc("set-cdr!",function(e,r){typecheck("set-cdr!",e,"pair");e.cdr=r},"(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?":doc("empty?",function(e){return typeof e==="undefined"||e===nil},"(empty? object)\n\n Function return true if value is undfined empty list."),gensym:doc("gensym",gensym,"(gensym)\n\n Function generate unique symbol, to use with macros as meta name."),load:doc(function e(r){typecheck("load",r,"string");var n=this;if(n.__name__==="__frame__"){n=n.__parent__}var i;if(n===global_env){i=n}else{i=this.get("**interaction-environment**")}var a="**module-path**";var o=global_env.get(a,{throwError:false});r=r.valueOf();if(!r.match(/.[^.]+$/)){r+=".scm"}if(typeof this.get("global",{throwError:false})!=="undefined"){return new Promise(function(n,t){var e=nodeRequire("path");if(o){o=o.valueOf();r=e.join(o,r)}global_env.set(a,e.dirname(r));nodeRequire("fs").readFile(r,function(e,r){if(e){console.log(e);t(e);global_env.set(a,o)}else{exec(r.toString(),i).then(function(){n();global_env.set(a,o)})["catch"](t)}})})}if(o){o=o.valueOf();r=o+"/"+r.replace(/^\.?\/?/,"")}return root.fetch(r).then(function(e){return e.text()}).then(function(e){global_env.set(a,r.replace(/\/[^/]*$/,""));return exec(e,i)}).then(function(){})["finally"](function(){global_env.set(a,o)})},"(load filename)\n\n Function fetch the file and evaluate its content as LIPS code."),do:doc(new Macro("do",function(){var n=asyncToGenerator(regenerator.mark(function e(n,t){var i,a,o,c,u,s,l,f,p,d,m;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:i=t.dynamic_scope,a=t.error;o=this;if(i){i=o}c=o.inherit("do");u=n.car;s=n.cdr.car;l=n.cdr.cdr;if(l!==nil){l=new Pair(LSymbol("begin"),l)}f={env:o,dynamic_scope:i,error:a};p=u;case 10:if(!(p!==nil)){r.next=21;break}d=p.car;r.t0=c;r.t1=d.car;r.next=16;return evaluate(d.cdr.car,f);case 16:r.t2=r.sent;r.t0.set.call(r.t0,r.t1,r.t2);p=p.cdr;r.next=10;break;case 21:f={env:c,dynamic_scope:i,error:a};m=regenerator.mark(function e(){var n,t,i,a,o;return regenerator.wrap(function e(r){while(1){switch(r.prev=r.next){case 0:if(!(l!==nil)){r.next=3;break}r.next=3;return lips.evaluate(l,f);case 3:n=u;t={};case 5:if(!(n!==nil)){r.next=15;break}i=n.car;if(!(i.cdr.cdr!==nil)){r.next=12;break}r.next=10;return evaluate(i.cdr.cdr.car,f);case 10:a=r.sent;t[i.car.valueOf()]=a;case 12:n=n.cdr;r.next=5;break;case 15:o=Object.getOwnPropertySymbols(t);Object.keys(t).concat(o).forEach(function(e){c.set(e,t[e])});case 17:case"end":return r.stop()}}},e)});case 23:r.next=25;return evaluate(s.car,f);case 25:if(r.sent){r.next=29;break}return r.delegateYield(m(),"t3",27);case 27:r.next=23;break;case 29:if(!(s.cdr!==nil)){r.next=33;break}r.next=32;return evaluate(s.cdr.car,f);case 32:return r.abrupt("return",r.sent);case 33:case"end":return r.stop()}}},e,this)}));return function(e,r){return n.apply(this,arguments)}}()),"(do (( )) (test expression) . body)\n\n Iteration macro that evaluate the expression body in scope of the variables.\n On Eeach loop it increase the variables according to next expression and run\n test to check if the loop should continue. If test is signle call the macro\n will not return anything. If the test is pair of expression and value the\n macro will return that value after finish."),if:doc(new Macro("if",function(n,e){var t=e.dynamic_scope,i=e.error;if(t){t=this}var a=this;var r=function e(r){if(r){return evaluate(n.cdr.car,{env:a,dynamic_scope:t,error:i})}else{return evaluate(n.cdr.cdr.car,{env:a,dynamic_scope:t,error:i})}};if(n===nil){throw new Error("too few expressions for `if`")}var o=evaluate(n.car,{env:a,dynamic_scope:t,error:i});return unpromise(o,r)}),"(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 Macro("let-env",function(r){var e=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{};var n=e.dynamic_scope,t=e.error;typecheck("let-env",r,"pair");var i=evaluate(r.car,{env:this,dynamic_scope:n,error:t});return unpromise(i,function(e){if(!(e instanceof Environment)){throw new Error("let-env: First argument need to be "+"environment")}return evaluate(Pair(LSymbol("begin"),r.cdr),{env:e,dynamic_scope:n,error:t})})},"(let-env env . body)\n\n Special macro that evaluate body in context of given environment\n object."),letrec:doc(let_macro(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*":doc(let_macro(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:doc(let_macro(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*":doc(pararel("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:doc(new Macro("begin",function(e,r){var t=Object.assign({},r);var i=this.get("list->array")(e);if(t.dynamic_scope){t.dynamic_scope=this}t.env=this;var a;return function r(){if(i.length){var e=i.shift();var n=evaluate(e,t);return unpromise(n,function(e){a=e;return r()})}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 Macro("ignore",function(e,r){var n=r.dynamic_scope,t=r.error;var i={env:this,error:t};if(n){i.dynamic_scope=this}evaluate(new Pair(new LSymbol("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:doc(Macro.defmacro("define",function(n,e){var t=this;if(n.car instanceof Pair&&n.car.car instanceof LSymbol){var r=new Pair(new LSymbol("define"),new Pair(n.car.car,new Pair(new Pair(new LSymbol("lambda"),new Pair(n.car.cdr,n.cdr)))));return r}else if(e.macro_expand){return}if(e.dynamic_scope){e.dynamic_scope=this}e.env=t;var i=n.cdr.car;var a;if(i instanceof Pair){i=evaluate(i,e);a=true}else if(i instanceof LSymbol){i=t.get(i)}typecheck("define",n.car,"symbol");return unpromise(i,function(e){if(t.__name__===Syntax.__merge_env__){t=t.__parent__}if(a&&(typeof e==="function"&&e.__lambda__||e instanceof Syntax)){e.__name__=n.car.valueOf();if(e.__name__ instanceof LString){e.__name__=e.__name__.valueOf()}}var r;if(n.cdr.cdr instanceof Pair&&LString.isString(n.cdr.cdr.car)){r=n.cdr.cdr.car.valueOf()}t.set(n.car,e,r)})}),"(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!":doc("set-obj!",function(e,r,n){var t=_typeof_1(e);if(isNull(e)||t!=="object"&&t!=="function"){var i=typeErrorMessage("set-obj!",type(e),["object","function"]);throw new Error(i)}e=unbind(e);r=r.valueOf();if(arguments.length===2){delete e[r]}else if(is_prototype(e)&&typeof n==="function"){e[r]=unbind(n);e[r].__prototype__=true}else if(typeof n==="function"||is_native(n)){e[r]=n}else{e[r]=n?n.valueOf():n}},"(set-obj! obj key value)\n\n Function set property of JavaScript object"),"null-environment":doc("null-environment",function(){return global_env.inherit("null")},"(null-environment)\n\n Function return new base environment with std lib."),values:doc(function e(){for(var r=arguments.length,n=new Array(r),t=0;t1&&arguments[1]!==undefined$1?arguments[1]:{},p=e.dynamic_scope,d=e.error;var m=this;var h;if(f.cdr instanceof Pair&&LString.isString(f.cdr.car)&&f.cdr.cdr!==nil){h=f.cdr.car.valueOf()}function v(){var e;if(p){if(!(this instanceof Environment)){e=m}else{e=this}}else{e=m}e=e.inherit("lambda");var r=f.car;var n=0;var t;if(typeof this!=="undefined"){e.set("this",this)}for(var i=arguments.length,a=new Array(i),o=0;o2&&arguments[2]!==undefined$1?arguments[2]:a;if(e instanceof Pair){var t=e.car;var i=e.cdr;if(n(t)){t=r(t)}if(n(i)){i=r(i)}if(isPromise(t)||isPromise(i)){return Promise.all([t,i]).then(function(e){var r=slicedToArray(e,2),n=r[0],t=r[1];return new Pair(n,t)})}else{return new Pair(t,i)}}return e}function o(e,r){if(e instanceof Pair){if(r!==nil){e.append(r)}}else{e=new Pair(e,r)}return e}function f(i,e,r){if(e1){var r="You can't splice multiple atoms inside list";throw new Error(r)}if(!(i.cdr instanceof Pair&&n[0]===nil)){return n[0]}}n=n.map(function(e){if(p.has(e)){return e.clone()}else{p.add(e);return e}});var t=d(i.cdr,0,1);if(t===nil&&n[0]===nil){return undefined$1}return unpromise(t,function(e){if(n[0]===nil){return e}if(n.length===1){return o(n[0],e)}var r=n.reduce(function(e,r){return o(e,r)});return o(r,e)})})}(i.car.cdr)}var p=new Set;function d(e,r,n){if(e instanceof Pair){if(LSymbol.is(e.car.car,"unquote-splicing")){return f(e,r+1,n)}if(LSymbol.is(e.car,"quasiquote")){var t=d(e.cdr,r,n+1);return new Pair(e.car,t)}if(LSymbol.is(e.car.car,"unquote")){if(r+2===n&&e.car.cdr instanceof Pair&&e.car.cdr.car instanceof Pair&&LSymbol.is(e.car.cdr.car.car,"unquote-splicing")){var i=e.car.cdr;return new Pair(new Pair(new LSymbol("unquote"),f(i,r+2,n)),nil)}else if(e.car.cdr instanceof Pair&&e.car.cdr.cdr!==nil){if(e.car.cdr.car instanceof Pair){var a=[];return function r(n){if(n===nil){return Pair.fromArray(a)}return unpromise(evaluate(n.car,{env:s,dynamic_scope:c,error:u}),function(e){a.push(e);return r(n.cdr)})}(e.car.cdr)}else{return e.car.cdr}}}if(LSymbol.is(e.car,"quote")){return new Pair(e.car,d(e.cdr,r,n))}if(LSymbol.is(e.car,"unquote")){r++;if(rn){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(e.cdr instanceof Pair){if(e.cdr.cdr!==nil){if(e.cdr.car instanceof Pair){var o=[];return function r(n){if(n===nil){return Pair.fromArray(o)}return unpromise(evaluate(n.car,{env:s,dynamic_scope:c,error:u}),function(e){o.push(e);return r(n.cdr)})}(e.cdr)}else{return e.cdr}}else{return evaluate(e.cdr.car,{env:s,dynamic_scope:c,error:u})}}else{return e.cdr}}return l(e,function(e){return d(e,r,n)})}return e}function n(e){if(e instanceof Pair){delete e.data;if(!e.haveCycles("car")){n(e.car)}if(!e.haveCycles("cdr")){n(e.cdr)}}}var t=d(e.car,0,1);return unpromise(t,function(e){n(e);return quote(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:doc(function e(r){typecheck("clone",r,"pair");return r.clone()},"(clone list)\n\n Function return clone of the list."),append:doc(function e(r,n){typecheck("append",r,["nil","pair"]);if(r instanceof Pair){r=r.clone()}return this.get("append!").call(this,r,n)},"(append list item)\n\n Function will create new list with value appended to the end. It return\n New list."),"append!":doc("append!",function(e,r){typecheck("append!",e,["pair","nil"]);if(!this.get("list?")(e)){throw new Error("append!: Invalid argument, value is not a list")}if(isNull(r)){return e}if(e===nil){if(r===nil){return nil}return r}return e.append(r)},"(append! name expression)\n\n Destructive version of append, it modify the list in place. It return\n original list."),reverse:doc(function e(r){typecheck("reverse",r,["array","pair","nil"]);if(r===nil){return nil}if(r instanceof Pair){var n=this.get("list->array")(r).reverse();return this.get("array->list")(n)}else if(!(r instanceof Array)){throw new Error(typeErrorMessage("reverse",type(r),"array or pair"))}else{return r.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:doc(function e(r,n){typecheck("nth",r,"number");typecheck("nth",n,["array","pair"]);if(n instanceof Pair){var t=n;var i=0;while(iarray")(n).join(r)},"(join separator list)\n\n Function return string by joining elements of the list"),split:doc(function e(r,n){typecheck("split",r,["regex","string"]);typecheck("split",n,"string");return this.get("array->list")(n.split(r))},"(split separator string)\n\n Function create list by splitting string by separatar that can\n be a string or regular expression."),replace:doc(function e(r,n,t){typecheck("replace",r,["regex","string"]);typecheck("replace",n,["string","function"]);typecheck("replace",t,"string");return t.replace(r,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:doc(function e(r,n){typecheck("match",r,["regex","string"]);typecheck("match",n,"string");var t=n.match(r);return t?this.get("array->list")(t):nil},"(match pattern string)\n\n function return match object from JavaScript as list."),search:doc(function e(r,n){typecheck("search",r,["regex","string"]);typecheck("search",n,"string");return n.search(r)},"(search pattern string)\n\n Function return first found index of the pattern inside a string"),repr:doc(function e(r,n){return toString(r,n)},"(repr obj)\n\n Function return string LIPS representation of an object as string."),env:doc(function e(e){e=e||this;var r=Object.keys(e.__env__);var n;if(r.length){n=Pair.fromArray(r)}else{n=nil}if(e.__parent__!==undefined$1){return this.get("env").call(this,e.__parent__).append(n)}return n},"(env obj)\n\n Function return list values (functions and variables) inside environment."),new:doc("new",function(e){for(var r=arguments.length,n=new Array(r>1?r-1:0),t=1;t2&&arguments[2]!==undefined$1?arguments[2]:specials.LITERAL;typecheck("set-special!",e,"string",1);typecheck("set-special!",r,"symbol",2);lips.specials.append(e.valueOf(),r,n)},'(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:get,".":get,unbind:doc(unbind,"(unbind fn)\n\n Function remove bidning from function so you can get props from it."),type:doc(type,"(type object)\n\n Function return type of an object as string."),debugger:doc("debugger",function(){debugger},"(debugger)\n\n Function stop JavaScript code in debugger."),in:doc("in",function(e,r){if(e instanceof LSymbol||e instanceof LString){e=e.valueOf()}return e in r},"(in key value)\n\n Function use is in operator to check if value is in object."),instanceof:doc("instanceof",function(e,r){return r instanceof unbind(e)},"(instanceof type obj)\n\n Function check of object is instance of object."),"prototype?":doc("prototype?",is_prototype,"(prototype? obj)\n\n Function check if value is JavaScript Object prototype."),"macro?":doc("macro?",function(e){return e instanceof Macro},"(macro? expression)\n\n Function check if value is a macro."),"function?":doc("function?",function(e){return typeof e==="function"},"(function? expression)\n\n Function check if value is a function."),"real?":doc("real?",function(e){if(type(e)!=="number"){return false}if(e instanceof LNumber){return e.isFloat()}return LNumber.isFloat(e)},"(real? number)\n\n Function check if value is real number."),"number?":doc("number?",LNumber.isNumber,"(number? expression)\n\n Function check if value is a number"),"string?":doc("string?",function(e){return LString.isString(e)},"(string? expression)\n\n Function check if value is a string."),"pair?":doc("pair?",function(e){return e instanceof Pair},"(pair? expression)\n\n Function check if value is a pair or list structure."),"regex?":doc(function(e){return e instanceof RegExp},"(regex? expression)\n\n Function check if value is regular expression."),"null?":doc("null?",function(e){return isNull(e)},"(null? expression)\n\n Function check if value is nulish."),"boolean?":doc("boolean?",function(e){return typeof e==="boolean"},"(boolean? expression)\n\n Function check if value is boolean."),"symbol?":doc("symbol?",function(e){return e instanceof LSymbol},"(symbol? expression)\n\n Function check if value is LIPS symbol"),"array?":doc("array?",function(e){return e instanceof Array},"(array? expression)\n\n Function check if value is an arrray."),"object?":doc("object?",function(e){return e!==nil&&e!==null&&!(e instanceof LCharacter)&&!(e instanceof RegExp)&&!(e instanceof LString)&&!(e instanceof Pair)&&!(e instanceof LNumber)&&_typeof_1(e)==="object"&&!(e instanceof Array)},"(object? expression)\n\n Function check if value is an plain object."),flatten:doc(function e(r){typecheck("flatten",r,"pair");return r.flatten()},"(flatten list)\n\n Return shallow list from tree structure (pairs)."),"array->list":doc("array->list",function(e){typecheck("array->list",e,"array");return Pair.fromArray(e)},"(array->list array)\n\n Function convert JavaScript array to LIPS list."),"tree->array":doc("tree->array",toArray$1("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":doc("list->array",toArray$1("list->array"),"(list->array list)\n\n Function convert LIPS list into JavaScript array."),apply:doc(function e(r){for(var n=arguments.length,t=new Array(n>1?n-1:0),i=1;iarray").call(this,a));return r.apply(this,t)},"(apply fn list)\n\n Function that call function with list of arguments."),length:doc(function e(r){if(!r){return LNumber(0)}if(r instanceof Pair){return LNumber(r.length())}if("length"in r){return LNumber(r.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":doc("string->number",function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:10;typecheck("string->number",e,"string",1);typecheck("string->number",r,"number",2);e=e.valueOf();r=r.valueOf();if(e.match(rational_bare_re)||e.match(rational_re)){return parse_rational(e,r)}else if(e.match(complex_bare_re)||e.match(complex_re)){return parse_complex(e,r)}else{var n=r===10&&!e.match(/e/i)||r===16;if(e.match(int_bare_re)&&n||e.match(int_re)){return parse_integer(e,r)}if(e.match(float_re)){return parse_float(e)}}return false},"(string->number number [radix])\n\n Function convert string to number."),try:doc(new Macro("try",function(a,e){var o=this;var c=e.dynamic_scope,u=e.error;return new Promise(function(i){var e={env:o,error:function e(r){var n=o.inherit("try");n.set(a.cdr.car.cdr.car.car,r);var t={env:n,error:u};if(c){t.dynamic_scope=o}unpromise(evaluate(new Pair(new LSymbol("begin"),a.cdr.car.cdr.cdr),t),function(e){i(e)})}};if(c){e.dynamic_scope=o}var r=evaluate(a.car,e);if(isPromise(r)){r.then(i)["catch"](e.error)}else{i(r)}})}),"(try expr (catch (e) code)"),throw:doc("throw",function(e){throw new Error(e)},"(throw string)\n\n Throw new expection."),find:doc(function r(n,t){typecheck("find",n,["regex","function"]);typecheck("find",t,["pair","nil"]);if(isNull(t)){return nil}var e=matcher("find",n);return unpromise(e(t.car),function(e){if(e&&e!==nil){return t.car}return r(n,t.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":doc("for-each",function(e){var r;typecheck("for-each",e,"function");for(var n=arguments.length,t=new Array(n>1?n-1:0),i=1;i1?r-1:0),a=1;a3?t-3:0),a=3;a3?i-3:0),o=3;oarray")(n);var a=[];var o=matcher("filter",r);return function r(n){function e(e){if(e&&e!==nil){a.push(t)}return r(++n)}if(n===i.length){return Pair.fromArray(a)}var t=i[n];return unpromise(o(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."),compose:doc(compose,"(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:doc(pipe,"(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:doc(curry,"(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:doc(function e(){for(var r=arguments.length,n=new Array(r),t=0;ti?n%=i:i%=n}n=abs(a*(t<0||arguments.length<=t?undefined$1:arguments[t]))/(n+i)}return LNumber(n)},"(lcm n1 n2 ...)\n\n Function return the least common multiple of their arguments."),"odd?":doc("odd?",singleMathOp(function(e){return LNumber(e).isOdd()}),"(odd? number)\n\n Function check if number os odd."),"even?":doc("even?",singleMathOp(function(e){return LNumber(e).isEven()}),"(even? number)\n\n Function check if number is even."),"*":doc("*",reduceMathOp(function(e,r){return LNumber(e).mul(r)},LNumber(1)),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":doc("+",reduceMathOp(function(e,r){return LNumber(e).add(r)},LNumber(0)),"(+ . numbers)\n\n Sum all numbers passed as arguments. If single value is passed it will\n return that value."),"-":doc("-",function(){for(var e=arguments.length,r=new Array(e),n=0;n":doc(">",function(){for(var e=arguments.length,r=new Array(e),n=0;n x1 x2 x3 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically increasing"),"<":doc("<",function(){for(var e=arguments.length,r=new Array(e),n=0;n=":doc(">=",function(){for(var e=arguments.length,r=new Array(e),n=0;n= x1 x2 x3 ...)\n\n Function compare its numerical arguments and check if they are\n monotonically nondecreasing"),"eq?":doc("eq?",equal,"(eq? a b)\n\n Function compare two values if they are identical."),or:doc(new Macro("or",function(e,r){var i=r.dynamic_scope,a=r.error;var o=this.get("list->array")(e);var c=this;if(i){i=c}var u;return function r(){function e(e){u=e;if(u){return u}else{return r()}}var n=o.shift();if(typeof n==="undefined"){if(u){return u}else{return false}}else{var t=evaluate(n,{env:c,dynamic_scope:i,error:a});return unpromise(t,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:doc(new Macro("and",function(e){var r=arguments.length>1&&arguments[1]!==undefined$1?arguments[1]:{},i=r.dynamic_scope,a=r.error;var o=this.get("list->array")(e);var c=this;if(i){i=c}if(!o.length){return true}var u;return function r(){function e(e){u=e;if(!u){return false}else{return r()}}var n=o.shift();if(typeof n==="undefined"){if(u){return u}else{return false}}else{var t=evaluate(n,{env:c,dynamic_scope:i,error:a});return unpromise(t,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."),"|":doc("|",function(e,r){return LNumber(e).or(r)},"(& a b)\n\n Function calculate or bit operation."),"&":doc("&",function(e,r){return LNumber(e).and(r)},"(& a b)\n\n Function calculate and bit operation."),"~":doc("~",function(e){return LNumber(e).neg()},"(~ number)\n\n Function negate the value."),">>":doc(">>",function(e,r){return LNumber(e).shr(r)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":doc(function(e,r){return LNumber(e).shl(r)},"(<< a b)\n\n Function left shit the value a by value b."),not:doc(function e(r){if(isNull(r)){return true}return!r},"(not object)\n\n Function return negation of the argument.")},undefined$1,"global");var user_env=global_env.inherit("user-env");global_env.set("**interaction-environment**",user_env);(function(){var e={ceil:"ceiling"};["floor","round","ceil"].forEach(function(r){var n=e[r]?e[r]:r;global_env.set(n,doc(n,function(e){typecheck(n,e,"number");if(e instanceof LNumber){return e[r]()}},"(".concat(n," number)\n\n Function calculate ").concat(n," of a number.")))})})();function allPossibleCases(e){if(e.length===1){return e[0]}else{var r=[];var n=allPossibleCases(e.slice(1));for(var t=0;t3&&arguments[3]!==undefined$1?arguments[3]:null;var i=e?" in expression `".concat(e,"`"):"";if(t!==null){i+=" (argument ".concat(t,")")}if(n instanceof Array){if(n.length===1){n=n[0]}else{var a=n[n.length-1];n=n.slice(0,-1).join(", ")+" or "+a}}return"Expecting ".concat(n,", got ").concat(r).concat(i)}function typecheck(e,r,n){var t=arguments.length>3&&arguments[3]!==undefined$1?arguments[3]:null;e=e.valueOf();var i=type(r).toLowerCase();var a=false;if(n instanceof Pair){n=n.toArray()}if(n instanceof Array){n=n.map(function(e){return e.valueOf()})}if(n instanceof Array){n=n.map(function(e){return e.valueOf().toLowerCase()});if(n.includes(i)){a=true}}else{n=n.valueOf().toLowerCase()}if(!a&&i!==n){throw new Error(typeErrorMessage(e,i,n,t))}}function self_evaluated(e){var r=_typeof_1(e);return["string","function"].includes(r)||e instanceof LSymbol||e instanceof LNumber||e instanceof LString||e instanceof RegExp}function is_native(e){return e instanceof LNumber||e instanceof LString||e instanceof LCharacter}function type(e){var r={pair:Pair,symbol:LSymbol,character:LCharacter,values:Values,macro:Macro,string:LString,array:Array,"native-symbol":Symbol};if(Number.isNaN(e)){return"NaN "}if(e===nil){return"nil"}if(e===null){return"null"}if(e instanceof Syntax){return"syntax"}for(var n=0,t=Object.entries(r);n1&&arguments[1]!==undefined$1?arguments[1]:{},i=e.env,a=e.dynamic_scope,n=e.error,o=n===void 0?function(){}:n;try{if(a===true){i=a=i||global_env}else if(i===true){i=a=global_env}else{i=i||global_env}var t={env:i,dynamic_scope:a,error:o};var c;if(isNull(r)){return r}if(r instanceof LSymbol){return i.get(r)}var u=r.car;var s=r.cdr;if(u instanceof Pair){c=resolvePromises(evaluate(u,t));if(isPromise(c)){return c.then(function(e){return evaluate(new Pair(e,r.cdr),t)})}else if(typeof c!=="function"){throw new Error(type(c)+" "+i.get("repr")(c)+" is not a function while evaluating "+r.toString())}}if(u instanceof LSymbol){c=i.get(u);if(c instanceof Syntax){return evaluateSyntax(c,r,t)}else if(c instanceof Macro){return evaluateMacro(c,s,t)}else if(typeof c!=="function"){if(c){var l="".concat(type(c)," `").concat(c,"' is not a function");throw new Error(l)}throw new Error("Unknown function `".concat(u.toString(),"'"))}}else if(typeof u==="function"){c=u}if(typeof c==="function"){var f=getFunctionArgs(s,t);return unpromise(f,function(e){if(is_bound(c)&&!is_object_bound(c)&&(!lips_context(c)||is_port(c))){e=e.map(unbox)}if(c.__lambda__&&!c.__prototype__||is_port(c)){c=unbind(c)}else if(e.some(lips_function)&&!lips_function(c)&&!is_array_method(c)){e=e.map(function(t){if(lips_function(t)){return function(){for(var e=arguments.length,r=new Array(e),n=0;n1&&arguments[1]!==undefined$1?arguments[1]:false;return this.rpc("eval",[e,r])}}Pair.unDry=function(e){return new Pair(e.car,e.cdr)};Pair.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};Nil.prototype.toDry=function(){return{value:null}};Nil.unDry=function(){return nil};LSymbol.prototype.toDry=function(){return{value:{name:this.__name__}}};LSymbol.unDry=function(e){return new LSymbol(e.__name__)};function execError(e){console.error(e.message||e);if(e.code){console.error(e.code.map(function(e,r){return"[".concat(r+1,"]: ").concat(e)}))}}function init(){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 r(){var e=a.shift();if(!e){i()}else{var n=e.getAttribute("type");if(o.includes(n)){var t=e.getAttribute("src");if(t){return root.fetch(t).then(function(e){return e.text()}).then(exec).then(r)["catch"](function(e){execError(e);r()})}else{return exec(e.innerHTML).then(r)["catch"](function(e){execError(e);r()})}}else if(n&&n.match(/lips|lisp/)){console.warn("Expecting "+o.join(" or ")+" found "+n)}return r()}}()})}}if(typeof window!=="undefined"){contentLoaded(window,init)}var banner=function(){var e=LString("Wed, 11 Nov 2020 17:52:59 +0000").valueOf();var r=e==="{{"+"DATE}}"?new Date:new Date(e);var n=function e(r){return r.toString().padStart(2,"0")};var t=r.getFullYear();var i=[t,n(r.getMonth()+1),n(r.getDate())].join("-");var a="\n __ __ __\n / / \\ \\ _ _ ___ ___ \\ \\\n| | \\ \\ | | | || . \\/ __> | |\n| | > \\ | |_ | || _/\\__ \\ | |\n| | / ^ \\ |___||_||_| <___/ | |\n \\_\\ /_/ \\_\\ /_/\n\nLIPS Interpreter DEV (".concat(i,") \nCopyright (c) 2018-").concat(t," 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}();Ahead.__class__="ahead";Pattern.__class__="pattern";Formatter.__class__="formatter";Macro.__class__="macro";Syntax.__class__="syntax";Environment.__class__="environment";InputPort.__class__="input-port";OutputPort.__class__="output-port";OutputStringPort.__class__="output-string-port";InputStringPort.__class__="input-string-port";LNumber.__class__="number";LCharacter.__class__="character";LString.__class__="string";var lips={version:"DEV",banner:banner,date:"Wed, 11 Nov 2020 17:52:59 +0000",exec:exec,parse:parse,tokenize:tokenize,evaluate:evaluate,Environment:Environment,env:user_env,Worker:Worker,Interpreter:Interpreter,balanced_parenthesis:balanced,balancedParenthesis:balanced,balanced:balanced,Macro:Macro,Syntax:Syntax,Pair:Pair,Values:Values,quote:quote,InputPort:InputPort,OutputPort:OutputPort,InputStringPort:InputStringPort,OutputStringPort:OutputStringPort,Formatter:Formatter,specials:specials,repr:repr,nil:nil,LSymbol:LSymbol,LNumber:LNumber,LFloat:LFloat,LComplex:LComplex,LRational:LRational,LBigInteger:LBigInteger,LCharacter:LCharacter,LString:LString,rationalize:rationalize};global_env.set("lips",lips);return lips})})(); \ No newline at end of file diff --git a/lib/R7RS.scm b/lib/R7RS.scm index f33d1a098..ed5f7c945 100644 --- a/lib/R7RS.scm +++ b/lib/R7RS.scm @@ -274,4 +274,47 @@ (define raise throw) ;; ----------------------------------------------------------------------------- - +;; macro definition taken from R7RS spec +;; ----------------------------------------------------------------------------- +(define-syntax define-values + (syntax-rules () + ((define-values () expr) + (define dummy + (call-with-values (lambda () expr) + (lambda args #f)))) + ((define-values (var) expr) + (define var expr)) + ((define-values (var0 var1 ... varn) expr) + (begin + (define var0 + (call-with-values (lambda () expr) + list)) + (define var1 + (let ((v (cadr var0))) + (set-cdr! var0 (cddr var0)) + v)) ... + (define varn + (let ((v (cadr var0))) + (set! var0 (car var0)) + v)))) + ((define-values (var0 var1 ... . varn) expr) + (begin + (define var0 + (call-with-values (lambda () expr) + list)) + (define var1 + (let ((v (cadr var0))) + (set-cdr! var0 (cddr var0)) + v)) ... + (define varn + (let ((v (cdr var0))) + (set! var0 (car var0)) + v)))) + ((define-values var expr) + (define var + (call-with-values (lambda () expr) + list)))) + "(define-values (a b ...) expr) + + Function evaluate expression expr and if it evaluates to result of values + then it will defined each value as variable like with define.") diff --git a/src/lips.js b/src/lips.js index 1e0ffcea5..2031a1245 100644 --- a/src/lips.js +++ b/src/lips.js @@ -2626,8 +2626,8 @@ bindings['...'].symbols[name] = bindings['...'].symbols[name] || []; bindings['...'].symbols[name].push(code); } + bindings.symbols[name] = code; if (!bindings.symbols[name]) { - bindings.symbols[name] = code; } return true; } @@ -2662,6 +2662,32 @@ return true; } } + log({ + pattern: pattern.toString(), + code: code.toString() + }); + // case (x y) ===> (var0 var1 ... varn) where var1 match nil + if (pattern.cdr instanceof Pair && + pattern.car instanceof LSymbol && + pattern.cdr.cdr instanceof Pair && + pattern.cdr.car instanceof LSymbol && + LSymbol.is(pattern.cdr.cdr.car, ellipsis_symbol) && + pattern.cdr.cdr.cdr instanceof Pair && + !LSymbol.is(pattern.cdr.cdr.cdr.car, ellipsis_symbol) && + traverse(pattern.car, code.car, pattern_names, ellipsis) && + traverse(pattern.cdr.cdr.cdr, code.cdr, pattern_names, ellipsis)) { + const name = pattern.cdr.car.__name__; + log({ + pattern: pattern.car.toString(), + code: code.car.toString(), + name + }); + if (symbols.includes(name)) { + return true; + } + bindings['...'].symbols[name] = null; + return true; + } log('recur'); if (traverse(pattern.car, code.car, pattern_names, ellipsis) && traverse(pattern.cdr, code.cdr, pattern_names, ellipsis)) { @@ -2945,6 +2971,12 @@ LSymbol.is(expr.cdr.car, ellipsis_symbol) && !disabled) { log('>> 1'); const symbols = bindings['...'].symbols; + // skip expand list of pattern was (x y ... z) + // and code was (x z) so y == null + const values = Object.values(symbols); + if (values.length && values.every(x => x === null)) { + return traverse(expr.cdr.cdr, { disabled }); + } var keys = get_names(symbols); // case of list as first argument ((x . y) ...) or (x ... ...) // we need to recursively process the list @@ -3012,6 +3044,12 @@ if (result !== nil && !is_spread) { result = result.reverse(); } + // case of (list) ... (rest code) + if (expr.cdr.cdr !== nil && + !LSymbol.is(expr.cdr.cdr.car, ellipsis_symbol)) { + const rest = traverse(expr.cdr.cdr, { disabled }); + return result.append(rest); + } return result; } else { log('>> 3'); @@ -3057,6 +3095,7 @@ { nested: false }, next ); + log({ value: value.toString() }); if (typeof value !== 'undefined') { result = new Pair( value, @@ -3078,9 +3117,11 @@ if (is_null) { return node; } + log('<<<< 1'); result.append(node); } } + log('<<<< 2'); return result; } } @@ -6160,7 +6201,10 @@ while (rules !== nil) { var rule = rules.car.car; var expr = rules.car.cdr.car; - + if (is_debug()) { + console.log('--------------------------------'); + } + log(rule); var bindings = extract_patterns(rule, code, symbols, ellipsis, { expansion: this, define: env }); diff --git a/tests/syntax.scm b/tests/syntax.scm index a42b2d433..73b032d11 100644 --- a/tests/syntax.scm +++ b/tests/syntax.scm @@ -852,3 +852,20 @@ (foo 1 2 3))))) (t.is (foo) '((1) (2) (3))))) + +(test "syntax-rules: it should ignore ellipsis in middle for 2 elements" + (lambda (t) + ;; code for define-values from R7RS spec + ;; macro defined in lib/R7RS.scm + + (let () + (define-values (x y) (values 1 2)) + (t.is (+ x y) 3)) + + (let () + (define-values (x y z) (values 1 2 3)) + (t.is (+ x y z) 6)) + + (let () + (define-values (x) (values 1)) + (t.is x 1)))) diff --git a/todo.lips b/todo.lips index c89000534..359321a7c 100644 --- a/todo.lips +++ b/todo.lips @@ -1,6 +1,6 @@ ;; -*- scheme -*- ;; -;; TODO app using LIPS - Scheme based Powerful LISP in JavaScript +;; TODO app using LIPS - Scheme based Powerful lips in JavaScript ;; Copyright (C) 2018-2020 Jakub T. Jankiewicz ;; Released under the MIT license ;;