From c980210109385c1339978488183696b84c6f7947 Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Sun, 1 Dec 2019 21:22:11 +0100 Subject: [PATCH] fix map #21 + refactor read function in node REPL --- CHANGELOG.md | 4 ++++ README.md | 6 +++--- bin/lips.js | 52 ++++++++++++++++++------------------------------ dist/lips.js | 12 +++++++---- dist/lips.min.js | 6 +++--- src/lips.js | 5 ++++- 6 files changed, 41 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aca86810..25fc1cd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.17.1 +### Bug fixes +* fix map last value [#21](https://github.com/jcubic/lips/issues/21) + ## 0.17.0 ### Features * revert breaking change of read to return Array diff --git a/README.md b/README.md index 3ddabd6c..638d123e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ ## LIPS is Pretty Simple -[![npm](https://img.shields.io/badge/npm-0.17.0-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) -[![travis](https://travis-ci.org/jcubic/lips.svg?branch=master&095cfbd62a0b195e609d12d598047aa67bcd4723)](https://travis-ci.org/jcubic/lips) -[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=master&8710db161df0ca3500520bda08815b5e)](https://coveralls.io/github/jcubic/lips?branch=master) +[![npm](https://img.shields.io/badge/npm-DEV-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) +[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&9f22a2615145274042e35c5e2ecec2d0338980f4)](https://travis-ci.org/jcubic/lips) +[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&8710db161df0ca3500520bda08815b5e)](https://coveralls.io/github/jcubic/lips?branch=devel) LIPS is very simple Lisp, similar to Scheme written in JavaScript. diff --git a/bin/lips.js b/bin/lips.js index e5b45101..e5fc5e65 100755 --- a/bin/lips.js +++ b/bin/lips.js @@ -108,18 +108,8 @@ if (options.c) { var e = env.inherit('name', { stdin: { read: function() { - return new Promise(function(done) { - rl.resume(); - code = ''; - if (process.stdin.isTTY) { - rl.setPrompt(''); - } - resolve = function() { - done(code); - code = ''; - rl.setPrompt(prompt); - resolve = null; - }; + return new Promise(function(resolve) { + rl.question('', resolve); }); } } @@ -128,29 +118,25 @@ if (options.c) { code += line; if (balanced_parenthesis(code)) { rl.pause(); - if (resolve) { - resolve(); - } else { - run(code, e).then(function(result) { - if (process.stdin.isTTY) { - print(result); - if (multiline) { - rl.setPrompt(prompt); - } - code = ''; - rl.prompt(); - } - rl.resume(); - }).catch(function() { - if (process.stdin.isTTY) { - if (multiline) { - rl.setPrompt(prompt); - } - rl.prompt(); + run(code, e).then(function(result) { + if (process.stdin.isTTY) { + print(result); + if (multiline) { + rl.setPrompt(prompt); } code = ''; - }); - } + rl.prompt(); + } + rl.resume(); + }).catch(function() { + if (process.stdin.isTTY) { + if (multiline) { + rl.setPrompt(prompt); + } + rl.prompt(); + } + code = ''; + }); } else { multiline = true; var i = indent(code, 2, prompt.length - continuePrompt.length); diff --git a/dist/lips.js b/dist/lips.js index cb2d378c..1ea0af52 100644 --- a/dist/lips.js +++ b/dist/lips.js @@ -1,5 +1,5 @@ /**@license - * LIPS is Pretty Simple - simple scheme like lisp in JavaScript - v. 0.17.0 + * LIPS is Pretty Simple - simple scheme like lisp in JavaScript - v. DEV * * Copyright (c) 2018-2019 Jakub T. Jankiewicz * Released under the MIT license @@ -24,7 +24,7 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Sun, 01 Dec 2019 19:31:34 +0000 + * build: Sun, 01 Dec 2019 20:21:46 +0000 */ (function () { 'use strict'; @@ -4859,8 +4859,12 @@ }); if (lists.some(function (x) { - return isEmptyList(x); + return x === nil; })) { + return nil; + } + + if (lists.some(isEmptyList)) { return emptyList(); } @@ -5867,7 +5871,7 @@ Environment.__className = 'Environment'; // ------------------------------------------------------------------------- var lips = { - version: '0.17.0', + version: 'DEV', exec: exec, parse: parse, tokenize: tokenize, diff --git a/dist/lips.min.js b/dist/lips.min.js index 318a784b..d4e44c80 100644 --- a/dist/lips.min.js +++ b/dist/lips.min.js @@ -1,5 +1,5 @@ /**@license - * LIPS is Pretty Simple - simple scheme like lisp in JavaScript - v. 0.17.0 + * LIPS is Pretty Simple - simple scheme like lisp in JavaScript - v. DEV * * Copyright (c) 2018-2019 Jakub T. Jankiewicz * Released under the MIT license @@ -24,6 +24,6 @@ * Copyright (c) 2014-present, Facebook, Inc. * released under MIT license * - * build: Sun, 01 Dec 2019 19:31:34 +0000 + * build: Sun, 01 Dec 2019 20:21:46 +0000 */ -(function(){"use strict";function n(n,e){return e={exports:{}},n(e,e.exports),e.exports}var c=n(function(t){function r(n,e){t.exports=r=Object.setPrototypeOf||function n(e,t){e.__proto__=t;return e};return r(n,e)}t.exports=r});var Hn=n(function(r){function i(){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(n){return false}}function a(n,e,t){if(i()){r.exports=a=Reflect.construct}else{r.exports=a=function n(e,t,r){var i=[null];i.push.apply(i,t);var a=Function.bind.apply(e,i);var o=new a;if(r)c(o,r.prototype);return o}}return a.apply(null,arguments)}r.exports=a});var e=n(function(n){var e=function(a){var n=Object.prototype;var s=n.hasOwnProperty;var u;var e=typeof Symbol==="function"?Symbol:{};var i=e.iterator||"@@iterator";var t=e.asyncIterator||"@@asyncIterator";var r=e.toStringTag||"@@toStringTag";function o(n,e,t,r){var i=e&&e.prototype instanceof c?e:c;var a=Object.create(i.prototype);var o=new A(r||[]);a._invoke=j(n,t,o);return a}a.wrap=o;function f(n,e,t){try{return{type:"normal",arg:n.call(e,t)}}catch(n){return{type:"throw",arg:n}}}var l="suspendedStart";var h="suspendedYield";var p="executing";var d="completed";var v={};function c(){}function m(){}function y(){}var g={};g[i]=function(){return this};var b=Object.getPrototypeOf;var w=b&&b(b(q([])));if(w&&w!==n&&s.call(w,i)){g=w}var _=y.prototype=c.prototype=Object.create(g);m.prototype=_.constructor=y;y.constructor=m;y[r]=m.displayName="GeneratorFunction";function x(n){["next","throw","return"].forEach(function(e){n[e]=function(n){return this._invoke(e,n)}})}a.isGeneratorFunction=function(n){var e=typeof n==="function"&&n.constructor;return e?e===m||(e.displayName||e.name)==="GeneratorFunction":false};a.mark=function(n){if(Object.setPrototypeOf){Object.setPrototypeOf(n,y)}else{n.__proto__=y;if(!(r in n)){n[r]="GeneratorFunction"}}n.prototype=Object.create(_);return n};a.awrap=function(n){return{__await:n}};function k(c){function u(n,e,t,r){var i=f(c[n],c,e);if(i.type==="throw"){r(i.arg)}else{var a=i.arg;var o=a.value;if(o&&typeof o==="object"&&s.call(o,"__await")){return Promise.resolve(o.__await).then(function(n){u("next",n,t,r)},function(n){u("throw",n,t,r)})}return Promise.resolve(o).then(function(n){a.value=n;t(a)},function(n){return u("throw",n,t,r)})}}var e;function n(t,r){function n(){return new Promise(function(n,e){u(t,r,n,e)})}return e=e?e.then(n,n):n()}this._invoke=n}x(k.prototype);k.prototype[t]=function(){return this};a.AsyncIterator=k;a.async=function(n,e,t,r){var i=new k(o(n,e,t,r));return a.isGeneratorFunction(e)?i:i.next().then(function(n){return n.done?n.value:i.next()})};function j(o,c,u){var s=l;return function n(e,t){if(s===p){throw new Error("Generator is already running")}if(s===d){if(e==="throw"){throw t}return N()}u.method=e;u.arg=t;while(true){var r=u.delegate;if(r){var i=F(r,u);if(i){if(i===v)continue;return i}}if(u.method==="next"){u.sent=u._sent=u.arg}else if(u.method==="throw"){if(s===l){s=d;throw u.arg}u.dispatchException(u.arg)}else if(u.method==="return"){u.abrupt("return",u.arg)}s=p;var a=f(o,c,u);if(a.type==="normal"){s=u.done?d:h;if(a.arg===v){continue}return{value:a.arg,done:u.done}}else if(a.type==="throw"){s=d;u.method="throw";u.arg=a.arg}}}}function F(n,e){var t=n.iterator[e.method];if(t===u){e.delegate=null;if(e.method==="throw"){if(n.iterator["return"]){e.method="return";e.arg=u;F(n,e);if(e.method==="throw"){return v}}e.method="throw";e.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var r=f(t,n.iterator,e.arg);if(r.type==="throw"){e.method="throw";e.arg=r.arg;e.delegate=null;return v}var i=r.arg;if(!i){e.method="throw";e.arg=new TypeError("iterator result is not an object");e.delegate=null;return v}if(i.done){e[n.resultName]=i.value;e.next=n.nextLoc;if(e.method!=="return"){e.method="next";e.arg=u}}else{return i}e.delegate=null;return v}x(_);_[r]="Generator";_[i]=function(){return this};_.toString=function(){return"[object Generator]"};function S(n){var e={tryLoc:n[0]};if(1 in n){e.catchLoc=n[1]}if(2 in n){e.finallyLoc=n[2];e.afterLoc=n[3]}this.tryEntries.push(e)}function E(n){var e=n.completion||{};e.type="normal";delete e.arg;n.completion=e}function A(n){this.tryEntries=[{tryLoc:"root"}];n.forEach(S,this);this.reset(true)}a.keys=function(t){var r=[];for(var n in t){r.push(n)}r.reverse();return function n(){while(r.length){var e=r.pop();if(e in t){n.value=e;n.done=false;return n}}n.done=true;return n}};function q(e){if(e){var n=e[i];if(n){return n.call(e)}if(typeof e.next==="function"){return e}if(!isNaN(e.length)){var t=-1,r=function n(){while(++t=0;--e){var i=this.tryEntries[e];var a=i.completion;if(i.tryLoc==="root"){return n("end")}if(i.tryLoc<=this.prev){var o=s.call(i,"catchLoc");var c=s.call(i,"finallyLoc");if(o&&c){if(this.prev=0;--t){var r=this.tryEntries[t];if(r.tryLoc<=this.prev&&s.call(r,"finallyLoc")&&this.prev=0;--e){var t=this.tryEntries[e];if(t.finallyLoc===n){this.complete(t.completion,t.afterLoc);E(t);return v}}},catch:function(n){for(var e=this.tryEntries.length-1;e>=0;--e){var t=this.tryEntries[e];if(t.tryLoc===n){var r=t.completion;if(r.type==="throw"){var i=r.arg;E(t)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(n,e,t){this.delegate={iterator:q(n),resultName:e,nextLoc:t};if(this.method==="next"){this.arg=u}return v}};return a}(n.exports);try{regeneratorRuntime=e}catch(n){Function("r","regeneratorRuntime = r")(e)}});var Jn=e;function u(n,e,t,r,i,a,o){try{var c=n[a](o);var u=c.value}catch(n){t(n);return}if(c.done){e(u)}else{Promise.resolve(u).then(r,i)}}function t(c){return function(){var n=this,o=arguments;return new Promise(function(e,t){var r=c.apply(n,o);function i(n){u(r,e,t,i,a,"next",n)}function a(n){u(r,e,t,i,a,"throw",n)}i(undefined)})}}var $n=t;function r(n){if(Array.isArray(n)){for(var e=0,t=new Array(n.length);e1&&arguments[1]!==g?arguments[1]:1;return n[n.length-e]}function o(n){if(typeof n==="string"){var e=/([-\\^$[\]()+{}?*.|])/g;return n.replace(e,"\\$1")}}function c(n){var i=e();n=n.replace(/\n\r|\r/g,"\n");var a=0;var o=0;var c=[];var u=[];var s=0;n.split(f).filter(Boolean).forEach(function(n){if(n.match(f)){s=0;if(u.length){var e=h(u);if(e.token.match(/\n/)){var t=e.token.split("\n").pop();s+=t.length}else{s+=e.token.length}s+=e.col}var r={col:s,line:o,token:n,offset:a};c.push(r);u.push(r);a+=n.length;s+=n.length;o+=(n.match("\n")||[]).length;return}n.split(i).filter(Boolean).forEach(function(n){var e={col:s,line:o,token:n,offset:a};s+=n.length;a+=n.length;c.push(e);u.push(e);if(n==="\n"){++o;u=[];s=0}})});return c}function w(n,e){if(e){return c(n)}else{return c(n).map(function(n){return n.token.trim()}).filter(function(n){return n&&!n.match(/^;/)})}}var y={"'":new L("quote"),"`":new L("quasiquote"),",@":new L("unquote-splicing"),",":new L("unquote")};function s(n){if(typeof n==="string"){n=w(n)}var a=[];var o=[];var c=null;var u=Object.keys(y);var s=u.map(function(n){return y[n].name});var f=0;var l=false;var h=[];var p=[];var d=0;function v(){var n=a[a.length-1];if(n instanceof Array&&n[0]instanceof L&&s.includes(n[0].name)&&a.length>1&&!n[0].literal){a.pop();if(a[a.length-1].length===1&&a[a.length-1][0]instanceof L){a[a.length-1].push(n)}else if(a[a.length-1]instanceof M){if(a[a.length-1].cdr instanceof M){a[a.length-1]=new M(a[a.length-1],M.fromArray(n))}else{a[a.length-1].cdr=M.fromArray(n)}}else{a[a.length-1].push(n)}}}n.forEach(function(n){var e=a[a.length-1];if(u.indexOf(n)!==-1){d++;c=n;a.push([y[c]]);if(!c){p=[]}p.push(c)}else{if(c){h.push(p);p=[]}if(n==="("){l=true;f++;a.push([]);c=null;d=0}else if(n==="."&&!l){a[a.length-1]=M.fromArray(e)}else if(n===")"){f--;if(!a.length){throw new Error("Unbalanced parenthesis")}if(a.length===1){o.push(a.pop())}else if(a.length>1){var t=a.pop();e=a[a.length-1];if(e instanceof Array){e.push(t)}else if(e instanceof M){e.append(M.fromArray(t))}if(h.length){p=h.pop();while(p.length){v();p.pop()}}else{v()}}if(f===0&&a.length){o.push(a.pop())}}else{l=false;var r=m(n);if(c){while(d--){a[a.length-1].push(r);r=a.pop()}h.pop();d=0;c=false}else if(r instanceof L&&s.includes(r.name)){r.literal=true}e=a[a.length-1];if(e instanceof M){var i=e;while(true){if(i.cdr===P){if(r instanceof Array){i.cdr=M.fromArray(r)}else{i.cdr=r}break}else{i=i.cdr}}}else if(!a.length){o.push(r)}else{e.push(r)}}}});if(!n.filter(function(n){return n.match(/^[()]$/)}).length&&a.length){o=o.concat(a);a=[]}if(a.length){throw new Error("Unbalanced parenthesis 2")}return o.map(function(n){if(n instanceof Array){return M.fromArray(n)}return n})}function p(n){var e=arguments.length>1&&arguments[1]!==g?arguments[1]:function(n){return n};var t=arguments.length>2&&arguments[2]!==g?arguments[2]:null;if(U(n)){var r=n.then(e);if(t===null){return r}else{return r["catch"](t)}}return e(n)}function u(n,e){if(e instanceof RegExp){return function(n){return String(n).match(e)}}else if(typeof e!=="function"){throw new Error("".concat(n," argument need to be a function or RegExp"))}else{return e}}function d(n,e,t){if(e){if(t){n.__doc__=e}else{n.__doc__=v(e)}}return n}function v(n){return n.split("\n").map(function(n){return n.trim()}).join("\n")}function _(n){var e=arguments.length>1&&arguments[1]!==g?arguments[1]:1;var t=n.length;if(e<=0){throw Error("previousSexp: Invlaid argument sexp = ".concat(e))}n:while(e--&&t>=0){var r=1;while(r>0){var i=n[--t];if(!i){break n}if(i==="("||i.token==="("){r--}else if(i===")"||i.token===")"){r++}}t--}return n.slice(t+1)}function x(n){if(!n||!n.length){return 0}var e=n.length;if(n[e-1].token==="\n"){return 0}while(--e){if(n[e].token==="\n"){var t=(n[e+1]||{}).token;if(t){return t.length}}}return 0}function k(n,e){return c(n,e)===e.length;function c(n,e){var t=0;var r={};for(var i=0;i0){continue}}}else if(n[t]instanceof Array){var o=c(n[t],e.slice(i));if(o===-1||o+i>e.length){return-1}i+=o-1;t++;continue}else{return-1}t++}if(n.length!==t){return-1}return e.length}}function j(n){this._code=n.replace(/\r/g,"")}j.defaults={offset:0,indent:2,specials:[/^define/,"lambda","let","let*"]};j.match=k;j.prototype._options=function n(e){var t=j.defaults;if(typeof e==="undefined"){return Object.assign({},t)}var r=e&&e.specials||[];return Object.assign({},t,e,{specials:t.specials.concat(r)})};j.prototype.indent=function n(e){var t=w(this._code,true);return this._indent(t,e)};j.matchSpecial=function(n,e){var t=e.specials;if(t.indexOf(n)!==-1){return true}else{var r=t.filter(function(n){return n instanceof RegExp});var i=true;var a=false;var o=g;try{for(var c=r[Symbol.iterator](),u;!(i=(u=c.next()).done);i=true){var s=u.value;if(n.match(s)){return true}}}catch(n){a=true;o=n}finally{try{if(!i&&c["return"]!=null){c["return"]()}}finally{if(a){throw o}}}}return false};j.prototype._indent=function n(e,t){var r=this._options(t);var i=x(e);var a=_(e);if(a&&a.length){if(a[0].line>0){r.offset=0}if(a.length===1){return r.offset+a[0].col+1}else if(j.matchSpecial(a[1].token,r)){return r.offset+a[0].col+r.indent}else if(a[0].line3&&a[1].line===a[3].line){if(a[1].token==="("){return r.offset+a[1].col}return r.offset+a[3].col}else if(a[0].line===a[1].line){return r.offset+r.indent+a[0].col}else{var o=a.slice(2);for(var c=0;c"}else if(typeof n==="string"){return JSON.stringify(n).replace(/\\n/g,"\n")}else if(U(n)){return"<#Promise>"}else if(n instanceof L||n instanceof mn||n instanceof RegExp||n instanceof M||n===P){return n.toString()}else if(n instanceof Array){return n.map(B)}else if(Gn(n)==="object"){if(n===null){return"null"}var e=n.constructor.name;if(e==="Object"){return JSON.stringify(n)}return"<#object("+n.constructor.name+")>"}else if(typeof n!=="undefined"){return n}}M.prototype.markCycles=function(){T(this);return this};M.prototype.haveCycles=function(){var n=arguments.length>0&&arguments[0]!==g?arguments[0]:null;if(!n){return this.haveCycles("car")||this.haveCycles("cdr")}return!!(this.cycles&&this.cycles[n])};function T(n){var i=[];var e=[];function a(n){if(n instanceof M){if(i.includes(n)){if(!e.includes(n)){e.push(n)}return"#".concat(e.length-1,"#")}}}function o(n){if(n instanceof M){i.push(n);var e={};var t=a(n.car);var r=a(n.cdr);if(t){e["car"]=t}else{o(n.car)}if(r){e["cdr"]=r}else{o(n.cdr)}if(t||r){n.cycles=e}else if(n.cycles){delete n.cycles}}}o(n)}M.prototype.toString=function(){var n=["("];if(this.car!==g){var e;if(this.cycles&&this.cycles.car){e=this.cycles.car}else{e=B(this.car)}if(e){n.push(e)}if(this.cdr instanceof M){if(this.cycles&&this.cycles.cdr){n.push(" . ");n.push(this.cycles.cdr)}else{var t;if(this.cycles&&this.cycles.cdr){t=this.cycles.cdr}var r=this.cdr.toString(t).replace(/^\(|\)$/g,"");n.push(" ");n.push(r)}}else if(typeof this.cdr!=="undefined"&&this.cdr!==P){n=n.concat([" . ",B(this.cdr)])}}n.push(")");return n.join("")};M.prototype.set=function(n,e){this[n]=e;if(e instanceof M){this.markCycles()}};M.prototype.append=function(n){if(n instanceof Array){return this.append(M.fromArray(n))}var e=this;if(e.car===g){if(n instanceof M){this.car=n.car;this.cdr=n.cdr}else{this.car=n}}else if(n!==P){while(true){if(e instanceof M&&e.cdr!==P){e=e.cdr}else{break}}e.cdr=n}return this};function H(n,e){if(n instanceof mn&&e instanceof mn){return n.cmp(e)===0}else if(typeof n==="number"||typeof e==="number"){return mn(n).cmp(mn(e))}else if(n instanceof L&&e instanceof L){return n.name===e.name}else{return n===e}}function J(n){return n instanceof M&&n.isEmptyList()||n===P}function $(n,e,t){if(typeof this!=="undefined"&&this.constructor!==$||typeof this==="undefined"){return new $(n,e)}Fn("Macro",n,"string",1);Fn("Macro",e,"function",2);if(t){this.__doc__=v(t)}this.name=n;this.fn=e}$.defmacro=function(n,e,t){var r=new $(n,e,t);r.defmacro=true;return r};$.prototype.invoke=function(n,e,t){var r=e.env,i=e.dynamic_scope,a=e.error;var o={dynamic_scope:i,error:a,macro_expand:t};var c=this.fn.call(r,n,o,this.name);return t?bn(c):c};$.prototype.toString=function(){return"#"};var D="define-macro";function Y(a){return function(){var t=$n(Jn.mark(function n(t,u){var s,f,r,i;return Jn.wrap(function n(e){while(1){switch(e.prev=e.next){case 0:r=function n(){r=$n(Jn.mark(function n(t){var r,i,a,o,c;return Jn.wrap(function n(e){while(1){switch(e.prev=e.next){case 0:if(!(t instanceof M&&t.car instanceof L)){e.next=13;break}e.prev=1;r=s.get(t.car);if(!(r instanceof $&&r.defmacro)){e.next=9;break}e.next=6;return r.invoke(t.cdr,u,true);case 6:i=e.sent;if(!(i instanceof M)){e.next=9;break}return e.abrupt("return",i);case 9:e.next=13;break;case 11:e.prev=11;e.t0=e["catch"](1);case 13:a=t.car;if(!(a instanceof M)){e.next=18;break}e.next=17;return f(a);case 17:a=e.sent;case 18:o=t.cdr;if(!(o instanceof M)){e.next=23;break}e.next=22;return f(o);case 22:o=e.sent;case 23:c=new M(a,o);return e.abrupt("return",c);case 25:case"end":return e.stop()}}},n,null,[[1,11]])}));return r.apply(this,arguments)};f=function n(e){return r.apply(this,arguments)};s=u["env"]=this;i=t;if(!a){e.next=12;break}e.t0=bn;e.next=8;return f(t);case 8:e.t1=e.sent.car;return e.abrupt("return",(0,e.t0)(e.t1));case 12:e.next=15;return f(t);case 15:i=e.sent;if(!(t.toString()===i.toString())){e.next=18;break}return e.abrupt("break",21);case 18:t=i;e.next=12;break;case 21:return e.abrupt("return",bn(i.car));case 22:case"end":return e.stop()}}},n,this)}));return function(n,e){return t.apply(this,arguments)}}()}function G(n){return typeof n==="undefined"||n===P||n===null}function U(n){return n instanceof Promise||n&&typeof n!=="undefined"&&typeof n.then==="function"}function Q(n,a){var o=function n(){for(var e=arguments.length,t=new Array(e),r=0;r2?e-2:0),r=2;r1?t-1:0),i=1;i1?e-1:0),r=1;rarray")(a.car);var f=s.inherit("let");var l=0;return function n(){var e=u[l++];function t(n){if(U(n)){return n.then(t)}else if(typeof n==="undefined"){f.set(e.car,P)}else{f.set(e.car,n)}}if(o){o=h?f:s}if(!e){var r=new M(new L("begin"),a.cdr);return On(r,{env:f,dynamic_scope:o,error:c})}else{var i=On(e.cdr.car,{env:h?f:s,dynamic_scope:o,error:c});return p(t(i),n)}}()})}function rn(n,u){return new $(n,function(n){var e=arguments.length>1&&arguments[1]!==g?arguments[1]:{},t=e.dynamic_scope,r=e.error;var i=this;if(t){t=this}var a=n;var o=[];while(a instanceof M&&!J(a)){o.push(On(a.car,{env:i,dynamic_scope:t,error:r}));a=a.cdr}var c=o.filter(U).length;if(c){return Promise.all(o).then(u.bind(this))}else{return u.call(this,o)}})}function an(n){for(var e=arguments.length,t=new Array(e>1?e-1:0),r=1;r2?r-2:0),a=2;a1?n-1:0),t=1;t=o){return a.apply(this,r)}else{return i}}return i.apply(this,arguments)}}function dn(r,i){Fn("limit",i,"function",2);return function(){for(var n=arguments.length,e=new Array(n),t=0;t1?t-1:0),i=1;i>":function n(e,t){return e>>t},"<<":function n(e,t){return e<>":"ishln"};n=i[n];return mn(this.value.clone()[n](e,r))}};var yn={"+":"add","-":"sub","*":"mul","/":"div","%":"mod","|":"or","&":"and","~":"neg","<<":"shl",">>":"shr"};Object.keys(yn).forEach(function(e){mn.prototype[yn[e]]=function(n){return this.op(e,n)}});mn.prototype.sqrt=function(){var n;if(mn.isNative(this.value)){n=Math.sqrt(this.value)}else if(mn.isBN(this.value)){n=this.value.sqrt()}return new mn(n)};mn.prototype.pow=function(n){n=this.coerce(n);if(mn.isNative(this.value)){try{var e=new Function("a,b","return a**b;");n.value=e(this.value,n.value)}catch(n){throw new Error("Power operator not supported")}}else if(mn.isBN(this.value)){n.value=this.value.pow(n.value)}else{n.value=Math.pow(this.value,n.value)}return n};mn.prototype.neg=function(){var n=this.value;if(mn.isNative(n)){n=-n}else if(mn.isBN(n)){n=n.neg()}return new mn(n)};mn.prototype.abs=function(){var n=this.value;if(mn.isNative(this.value)){if(n<0){n=-n}}else if(mn.isBN(n)){n.iabs()}return new mn(n)};mn.prototype.isOdd=function(){if(mn.isNative(this.value)){if(this.isBigNumber()){return this.value%BigInt(2)===BigInt(1)}return this.value%2===1}else if(mn.isBN(this.value)){return this.value.isOdd()}};mn.prototype.isEven=function(){return!this.isOdd()};mn.prototype.cmp=function(n){n=this.coerce(n);if(mn.isNative(this.value)){if(this.value1&&arguments[1]!==g?arguments[1]:{};if(Gn(n)==="object"){e=n}if(!n||Gn(n)==="object"){n="child of "+(this.name||"unknown")}return new gn(e||{},this,n)};gn.prototype.get=function(n){var e=arguments.length>1&&arguments[1]!==g?arguments[1]:{};var t=e.weak,r=e.context,i=r===void 0?this:r,a=e.throwError,o=a===void 0?true:a;var c;var u=false;if(n instanceof L){if(n.name in this.env){c=this.env[n.name];u=true}}else if(typeof n==="string"){if(typeof this.env[n]!=="undefined"){c=this.env[n];u=true}}if(u){if(mn.isNumber(c)){return mn(c)}if(c instanceof M){return c.markCycles()}if(typeof c==="function"){if(Z(c)){if(t){return Q(c,i)}return W(c,i)}}return c}if(this.parent instanceof gn){return this.parent.get(n,{weak:t,context:i,throwError:o})}else{var s;if(n instanceof L){s=n.name}else if(typeof n==="string"){s=n}if(s){var f=Gn(l[s]);if(f==="function"){if(en(l[s])){return W(l[s],l)}return l[s]}else if(f!=="undefined"){return l[s]}}}if(o){s=(s.name||s).toString();throw new Error("Unbound variable `"+s+"'")}};gn.prototype.set=function(n,e){if(mn.isNumber(e)){e=mn(e)}if(n instanceof L){n=n.name}this.env[n]=e};gn.prototype.has=function(n){return typeof this.env[n]!=="undefined"};gn.prototype.ref=function(n){var e=this;while(true){if(!e){break}if(e.has(n)){return e}e=e.parent}};gn.prototype.parents=function(){var n=this;var e=[];while(n){e.unshift(n);n=n.parent}return e};function bn(n){if(U(n)){return n.then(bn)}if(n instanceof M||n instanceof L){n.data=true}return n}var wn=function(){var e=0;return function(){var n=arguments.length>0&&arguments[0]!==g?arguments[0]:null;if(n!==null){return new L(l.Symbol("#:".concat(n)))}e++;return new L(l.Symbol("#:g".concat(e)))}}();var _n=new gn({nil:P,undefined:g,true:true,NaN:NaN,false:false,stdout:{write:function n(){var e;(e=console).log.apply(e,arguments)}},stdin:{read:function n(){return new Promise(function(n){n(prompt(""))})}},help:d(new $("help",function(n,e){var t=e.dynamic_scope,r=e.error;var i;if(n.car instanceof L){i=n.car}else if(n.car instanceof M&&n.car.car instanceof L){i=n.car.car}else{var a=this;if(t){t=this}var o=On(n.car,{env:a,error:r,dynamic_scope:t});if(o&&o.__doc__){return o.__doc__}}return this.get(i).__doc__}),"(help object)\n\n Macro returns documentation for function or macros including parser\n macros but only if called with parser macro symbol like (help `).\n For normal functions and macros you can save the function in variable."),cons:d(function(n,e){if(J(e)){e=P}return new M(n,e)},"(cons left right)\n\n Function return new Pair out of two arguments."),car:d(function(n){if(n===P){return P}Fn("car",n,"pair");if(J(n)){return P}return n.car},"(car pair)\n\n Function returns car (head) of the list/pair."),cdr:d(function(n){if(n===P){return P}Fn("cdr",n,"pair");if(J(n)){return P}return n.cdr},"(cdr pair)\n\n Function returns cdr (tail) of the list/pair."),"set!":d(new $("set!",function(e){var n=arguments.length>1&&arguments[1]!==g?arguments[1]:{},t=n.dynamic_scope,r=n.error;if(t){t=this}var i=On(e.cdr.car,{env:this,dynamic_scope:t,error:r});i=An(i);var a;function o(e,t){if(U(e)){return e.then(function(n){return o(n,t)})}if(U(t)){return t.then(function(n){return o(e,n)})}s[e]=t;return t}if(e.car instanceof M&&L.is(e.car.car,".")){var c=e.car.cdr.car;var u=e.car.cdr.cdr.car;var s=On(c,{env:this,dynamic_scope:t,error:r});var f=On(u,{env:this,dynamic_scope:t,error:r});return o(f,i)}if(!(e.car instanceof L)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}a=this.ref(e.car.name);if(!a){a=this}return p(i,function(n){a.set(e.car,n)})}),"(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."),"set-car!":d(function(n,e){Fn("set-car!",n,"pair");n.car=e},"(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!":d(function(n,e){Fn("set-cdr!",n,"pair");n.cdr=e},"(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?":d(function(n){return typeof n==="undefined"||J(n)},"(empty? object)\n\n Function return true if value is undfined empty list."),assoc:d(function(n,e){if(n instanceof M&&!(e instanceof M)){throw new Error("First argument to assoc ned to be a key")}Fn("assoc",e,"pair");var t=e;while(true){if(!(t instanceof M)||this.get("empty?")(t)){break}var r=t.car.car;if(H(r,n)){return t.car}else if(!t.haveCycles("cdr")){t=t.cdr}}return P},"(assoc key alist)\n\n Function search Alist (list of pairs) until it find the one that\n have head set equal to key, and return found pair."),gensym:d(wn,"(gensym)\n\n Function generate unique symbol, to use with macros as meta name."),require:d(function(n){return require(n)},"(require module)\n\n Function to be used inside Node.js to import the module."),load:d(function(n){Fn("load",n,"string");var i=this;if(typeof this.get("global",{throwError:false})!=="undefined"){return new Promise(function(t,r){require("fs").readFile(n,function(n,e){if(n){r(n)}else{Ln(e.toString(),i).then(function(){t()})}})})}return l.fetch(n).then(function(n){return n.text()}).then(function(n){return Ln(n,i)}).then(function(){})},"(load filename)\n\n Function fetch the file and evaluate its content as LIPS code."),while:d(new $("while",function(r,n){var i=n.dynamic_scope,a=n.error;var o=this;var c=new M(new L("begin"),r.cdr);var u;if(i){i=o}return function e(){var n=On(r.car,{env:o,dynamic_scope:i,error:a});function t(n){if(n&&!G(n)&&!J(n)){u=On(c,{env:o,dynamic_scope:i,error:a});if(U(u)){return u.then(function(n){u=n;return e()})}else{return e()}}else{return u}}return p(n,t)}()}),"(while cond . body)\n\n Macro that create a loop, it exectue body untill cond expression is false"),if:d(new $("if",function(t,n){var r=n.dynamic_scope,i=n.error;if(r){r=this}var a=this;var e=function n(e){Fn("if",e,"boolean");if(e){return On(t.cdr.car,{env:a,dynamic_scope:r,error:i})}else{return On(t.cdr.cdr.car,{env:a,dynamic_scope:r,error:i})}};var o=On(t.car,{env:a,dynamic_scope:r,error:i});return p(o,e)}),"(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*":d(tn(true),"(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 and next value can access to\n previous values/names."),let:d(tn(false),"(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*":d(rn("begin*",function(n){return n.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:d(new $("begin",function(n,e){var r=Object.assign({},e);var i=this.get("list->array")(n);if(r.dynamic_scope){r.dynamic_scope=this}r.env=this;var a;return function e(){if(i.length){var n=i.shift();var t=On(n,r);return p(t,function(n){a=n;return e()})}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 $("ignore",function(n,e){var t=e.dynamic_scope,r=e.error;var i={env:this,error:r};if(t){i.dynamic_scope=this}On(new M(new L("begin"),n),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."),timer:d(new $("timer",function(e){var n=arguments.length>1&&arguments[1]!==g?arguments[1]:{},t=n.dynamic_scope,r=n.error;Fn("timer",e.car,"number");var i=this;if(t){t=this}return new Promise(function(n){setTimeout(function(){n(On(e.cdr.car,{env:i,dynamic_scope:t,error:r}))},e.car)}).then(bn)}),"(timer time expression)\n\n Function return a promise, and it will be automatically evaluated\n after specific time passes. The return value of the function\n will be value of the timer exprssion. If you want to do side effect\n only expression you can wrap your expression in nol call."),define:d($.defmacro("define",function(e,n){var t=this;if(e.car instanceof M&&e.car.car instanceof L){var r=new M(new L("define"),new M(e.car.car,new M(new M(new L("lambda"),new M(e.car.cdr,e.cdr)))));return r}else if(n.macro_expand){return}if(n.dynamic_scope){n.dynamic_scope=this}n.env=t;var i=e.cdr.car;if(i instanceof M){i=On(i,n)}else if(i instanceof L){i=t.get(i)}if(e.car instanceof L){p(i,function(n){t.set(e.car,n)})}}),"(define name expression)\n (define (function-name . args) body)\n\n Macro for defining values. It can be used to define variables,\n or function. If first argument is list it will create function\n with name beeing first element of the list. The macro evalute\n code `(define function (lambda args body))`"),"set-obj!":d(function(n,e,t){var r=Gn(n);if(G(n)||r!=="object"&&r!=="function"){var i=jn("set-obj!",En(n),["object","function"]);throw new Error(i)}z(n)[e]=t},"(set-obj! obj key value)\n\n Function set property of JavaScript object"),"current-environment":d(function(){return this},"(current-environment)\n\n Function return current environement."),eval:d(function(n,t){var r=this;Fn("eval",n,["symbol","pair","array"]);t=t||this;if(n instanceof L){return t.get(n)}if(n instanceof M){return On(n,{env:t,error:function n(e){r.get("error")(e.message);if(e.code){var t=e.code.map(function(n,e){return"[".concat(e+1,"]: ").concat(n)}).join("\n");r.get("error")(t)}}})}if(n instanceof Array){var i=this.get("eval");return n.reduce(function(n,e){return i(e,t)})}},"(eval list)\n\n Function evalute LIPS code as list structure."),lambda:new $("lambda",function(s){var n=arguments.length>1&&arguments[1]!==g?arguments[1]:{},f=n.dynamic_scope,l=n.error;var h=this;var p;if(s.cdr instanceof M&&typeof s.cdr.car==="string"&&s.cdr.cdr!==P){p=s.cdr.car}function e(){var n=(f?this:h).inherit("lambda");var e=s.car;var t=0;var r;if(typeof this!=="undefined"){n.set("this",this)}if(e instanceof L||!J(e)){for(var i=arguments.length,a=new Array(i),o=0;o2&&arguments[2]!==g?arguments[2]:c;if(n instanceof M&&!J(n)){var r=n.car;var i=n.cdr;if(t(r)){r=e(r)}if(t(i)){i=e(i)}if(U(r)||U(i)){return Promise.all([r,i]).then(function(n){var e=Yn(n,2),t=e[0],r=e[1];return new M(t,r)})}else{return new M(r,i)}}return n}function s(n,e){if(n instanceof M){if(J(n)&&e===P){return P}n.append(e)}else{n=new M(n,e)}return n}function f(r,n,e){if(nr){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(t.cdr instanceof M){if(t.cdr.cdr!==P){if(t.cdr.car instanceof M){return p(h(t.cdr.cdr,e,r),function(n){var e=On(t.cdr.car,{env:o,dynamic_scope:i,error:a});return new M(e,n)})}else{return t.cdr}}else{return On(t.cdr.car,{env:o,dynamic_scope:i,error:a})}}else{return t.cdr}}return u(t,function(n){return h(n,e,r)})}return t}function t(n){if(n instanceof M){delete n.data;if(!n.haveCycles("car")){t(n.car)}if(!n.haveCycles("cdr")){t(n.cdr)}}}var r=h(n.car,0,1);return p(r,function(n){t(n);return bn(n)})},"(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:d(function(n){Fn("clone",n,"pair");return n.clone()},"(clone list)\n\n Function return clone of the list."),append:d(function(n,e){Fn("append",n,"pair");return this.get("append!")(n.clone(),e)},"(append list item)\n\n Function will create new list with value appended to the end. It return\n New list."),"append!":d(function(n,e){Fn("append!",n,"pair");if(G(e)||J(e)){return n}return n.append(e)},"(append! name expression)\n\n Destructive version of append, it modify the list in place. It return\n original list."),reverse:d(function(n){Fn("reverse",n,["array","pair"]);if(n instanceof M){var e=this.get("list->array")(n).reverse();return this.get("array->list")(e)}else if(!(n instanceof Array)){throw new Error(jn("reverse",En(n),"array or pair"))}else{return n.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:d(function(n,e){Fn("nth",n,"number");Fn("nth",e,["array","pair"]);if(e instanceof M){var t=e;var r=0;while(rarray")(e).join(n)},"(join separator list)\n\n Function return string by joining elements of the list"),split:d(function(n,e){Fn("split",n,["regex","string"]);Fn("split",e,"string");return this.get("array->list")(e.split(n))},"(split separator string)\n\n Function create list by splitting string by separatar that can\n be a string or regular expression."),replace:d(function(n,e,t){Fn("replace",n,["regex","string"]);Fn("replace",e,["string","function"]);Fn("replace",t,"string");return t.replace(n,e)},"(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:d(function(n,e){Fn("match",n,["regex","string"]);Fn("match",e,"string");var t=e.match(n);return t?this.get("array->list")(t):P},"(match pattern string)\n\n function return match object from JavaScript as list."),search:d(function(n,e){Fn("search",n,["regex","string"]);Fn("search",e,"string");return e.search(n)},"(search pattern string)\n\n Function return first found index of the pattern inside a string"),string:d(function e(n,t){if(typeof jQuery!=="undefined"&&n instanceof jQuery.fn.init){return"<#jQuery("+n.length+")>"}if(n instanceof mn){return n.value.toString()}if(typeof n==="undefined"){return"<#undefined>"}if(typeof n==="function"){if(en(n)){return"<#function(native)>"}return"<#function>"}if(n instanceof RegExp){return n.toString()}if(n===P){return"nil"}if(n instanceof Array){return"["+n.map(function(n){return e(n,true)}).join(", ")+"]"}if(n===null||typeof n==="string"&&t){return JSON.stringify(n).replace(/\\n/g,"\n")}if(n instanceof M){return n.toString()}if(n instanceof L){return n.toString()}if(l.HTMLElement&&n instanceof l.HTMLElement){return"<#HTMLElement(".concat(n.tagName.toLowerCase(),")>")}if(Gn(n)==="object"){var r=n.constructor;var i;if(typeof r.__className==="string"){i=r.__className}else if(En(n)==="instance"){i="instance"}else{i=r.name}if(i!==""){return"<#"+i+">"}return"<#Object>"}if(typeof n!=="string"){return n.toString()}return n},"(string obj)\n\n Function return string LIPS representation of an object as string."),env:d(function(n){n=n||this;var e=Object.keys(n.env);var t;if(e.length){t=M.fromArray(e)}else{t=P}if(n.parent!==g){return this.get("env").call(this,n.parent).append(t)}return t},"(env obj)\n\n Function return list values (functions and variables) inside environment."),new:d(function(n){for(var e=arguments.length,t=new Array(e>1?e-1:0),r=1;rlist":d(function(n){Fn("array->list",n,"array");return M.fromArray(n)},"(array->list array)\n\n Function convert JavaScript array to LIPS list."),"tree->array":d(C("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":d(C("list->array"),"(list->array list)\n\n Function convert LIPS list into JavaScript array."),apply:d(function(n,e){Fn("call",n,"function",1);Fn("call",e,"pair",2);return n.apply(void 0,Dn(this.get("list->array")(e)))},"(apply fn list)\n\n Function that call function with list of arguments."),length:d(function(n){if(!n){return mn(0)}if(n instanceof M){return mn(n.length())}if("length"in n){return mn(n.length)}},"(length expression)\n\n Function return length of the object, the object can be list\n or any object that have length property."),try:d(new $("try",function(a,n){var o=this;var c=n.dynamic_scope,u=n.error;return new Promise(function(i){var n={env:o,error:function n(e){var t=o.inherit("try");t.set(a.cdr.car.cdr.car.car,e);var r={env:t,error:u};if(c){r.dynamic_scope=o}p(On(new M(new L("begin"),a.cdr.car.cdr.cdr),r),function(n){i(n)})}};if(c){n.dynamic_scope=o}var e=On(a.car,n);if(U(e)){e["catch"](n.error).then(i)}else{i(e)}})}),"(try expr (catch (e) code)"),find:d(function e(t,r){Fn("find",t,["regex","function"]);Fn("find",r,"pair");if(G(r)){return P}var n=u("find",t);return p(n(r.car),function(n){if(n&&n!==P){return r.car}return e(t,r.cdr)})},"(find fn list)\n (find regex list)\n\n Higher order Function find first value for which function return true.\n If called with regex it will create matcher function."),"for-each":d(function(n){Fn("for-each",n,"function");for(var e=arguments.length,t=new Array(e>1?e-1:0),r=1;r1?e-1:0),a=1;a3?r-3:0),a=3;a3?i-3:0),o=3;oarray")(e);var a=[];var o=u("filter",n);return function e(t){function n(n){if(n&&n!==P){a.push(r)}return e(++t)}if(t===i.length){return M.fromArray(a)}var r=i[t];return p(o(r,t),n)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher order function that call `fn` for each element of the list\n and return list for only those elements for which funtion return\n true value. If called with regex it will create matcher function."),range:d(function(n){Fn("range",n,"number");if(n instanceof mn){n=n.valueOf()}return M.fromArray(new Array(n).fill(0).map(function(n,e){return mn(e)}))},"(range n)\n\n Function return list of n numbers from 0 to n - 1"),compose:d(cn,"(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:d(on,"(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:d(pn,"(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 (print (add12 3 4))"),odd:d(fn(function(n){return mn(n).isOdd()}),"(odd number)\n Function check if number os odd."),even:d(fn(function(n){return mn(n).isEvent()}),"(even number)\n\n Function check if number is even."),"*":d(hn(function(n,e){return mn(n).mul(e)}),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":d(hn(function(n,e){return mn(n).add(e)}),"(+ . numbers)\n\n Sum all numbers passed as arguments. If single value is passed it will\n return that value."),"-":d(function(){for(var n=arguments.length,e=new Array(n),t=0;t":d(function(n,e){return mn(n).cmp(e)===1},"(> a b)\n\n Function compare two numbers and check if first argument is greater\n than the second one"),"<":d(function(n,e){return mn(n).cmp(e)===-1},"(< a b)\n\n Function compare two numbers and check if first argument is less\n than the second one"),"<=":d(function(n,e){return[0,-1].includes(mn(n).cmp(e))},"(<= a b)\n\n Function compare two numbers and check if first argument is less or\n equal to the second one"),">=":d(function(n,e){return[0,1].includes(mn(n).cmp(e))},"(>= a b)\n\n Function compare two numbers and check if first argument is less or\n equal to the second one"),"eq?":d(H,"(eq? a b)\n\n Function compare two values if they are identical."),or:d(new $("or",function(n,e){var i=e.dynamic_scope,a=e.error;var o=this.get("list->array")(n);var c=this;if(i){i=c}var u;return function e(){function n(n){u=n;if(u){return u}else{return e()}}var t=o.shift();if(typeof t==="undefined"){if(u){return u}else{return false}}else{var r=On(t,{env:c,dynamic_scope:i,error:a});return p(r,n)}}()}),"(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:d(new $("and",function(n){var e=arguments.length>1&&arguments[1]!==g?arguments[1]:{},i=e.dynamic_scope,a=e.error;var o=this.get("list->array")(n);var c=this;if(i){i=c}if(!o.length){return true}var u;return function e(){function n(n){u=n;if(!u){return false}else{return e()}}var t=o.shift();if(typeof t==="undefined"){if(u){return u}else{return false}}else{var r=On(t,{env:c,dynamic_scope:i,error:a});return p(r,n)}}()}),"(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."),"|":d(function(n,e){return mn(n).or(e)},"(& a b)\n\n Function calculate or bit operation."),"&":d(function(n,e){return mn(n).and(e)},"(& a b)\n\n Function calculate and bit operation."),"~":d(function(n){return mn(n).neg()},"(~ number)\n\n Function negate the value."),">>":d(function(n,e){return mn(n).shr(e)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":d(function(n,e){return mn(n).shl(e)},"(<< a b)\n\n Function left shit the value a by value b."),not:d(function(n){if(J(n)){return true}return!n},"(not object)\n\n Function return negation of the argument."),"->":d(function(n,e){for(var t=arguments.length,r=new Array(t>2?t-2:0),i=2;i obj name . args)\n\n Function get function from object and call it with arguments.")},g,"global");["floor","round","ceil"].forEach(function(e){_n.set(e,d(function(n){Fn(e,n,"number");if(n instanceof mn){return n[e]()}},"(".concat(e," number)\n\n Function calculate ").concat(e," of a number.")))});function xn(n){if(n.length===1){return n[0]}else{var e=[];var t=xn(n.slice(1));for(var r=0;r3&&arguments[3]!==g?arguments[3]:null;var i=n?" in function `".concat(n,"`"):"";if(r!==null){i+=" argument ".concat(r)}if(t instanceof Array){var a=t[t.length-1];t=t.slice(0,-1).join(", ")+" or "+a}return"Expecting ".concat(t," got ").concat(e).concat(i)}function Fn(n,e,t){var r=arguments.length>3&&arguments[3]!==g?arguments[3]:null;var i=En(e);var a=false;if(t instanceof Array&&t.includes(i)){a=true}if(!a&&i!==t){throw new Error(jn(n,i,t,r))}}function Sn(n){var e=Gn(n);return["string","function"].includes(e)||n instanceof mn||n instanceof RegExp}function En(n){var e={pair:M,symbol:L,macro:$,array:Array,native_symbol:l.Symbol};if(n===P){return"nil"}if(n===null){return"null"}for(var t=0,r=Object.entries(e);t1&&arguments[1]!==g?arguments[1]:{},r=n.env,i=n.dynamic_scope,t=n.error,a=t===void 0?function(){}:t;try{if(i===true){r=i=r||_n}else if(r===true){r=i=_n}else{r=r||_n}var o={env:r,dynamic_scope:i,error:a};var c;if(G(e)){return e}if(J(e)){return R()}if(e instanceof L){return r.get(e,{weak:true})}var u=e.car;var s=e.cdr;if(u instanceof M){c=An(On(u,o));if(U(c)){return c.then(function(n){return On(new M(n,e.cdr),o)})}else if(typeof c!=="function"){throw new Error(En(c)+" "+r.get("string")(c)+" is not a function while evaluating "+e.toString())}}if(u instanceof L){c=r.get(u,{weak:true});if(c instanceof $){var f=Nn(c,s,o);return p(f,function(n){if(n instanceof M){return n.markCycles()}return n})}else if(typeof c!=="function"){if(c){var l="".concat(En(c)," `").concat(c,"' is not a function");throw new Error(l)}throw new Error("Unknown function `".concat(u.name,"'"))}}else if(typeof u==="function"){c=u}if(typeof c==="function"){var h=qn(s,o);return p(h,function(n){var e=i||r;var t=An(c.apply(e,n));return p(t,function(n){if(n instanceof M){return bn(n.markCycles())}return n},a)})}else if(e instanceof L){c=r.get(e);if(c==="undefined"){throw new Error("Unbound variable `"+e.name+"'")}return c}else if(e instanceof M){c=u&&u.toString();throw new Error("".concat(En(u)," ").concat(c," is not a function"))}else{return e}}catch(n){a&&a(n,e)}}function Ln(n,e,t){return In.apply(this,arguments)}function In(){In=$n(Jn.mark(function n(t,r,i){var a,o,c,u;return Jn.wrap(function n(e){while(1){switch(e.prev=e.next){case 0:if(i===true){r=i=r||_n}else if(r===true){r=i=_n}else{r=r||_n}a=s(t);o=[];case 3:c=a.shift();if(c){e.next=9;break}return e.abrupt("return",o);case 9:e.next=11;return On(c,{env:r,dynamic_scope:i,error:function n(e,t){if(t){e.code=e.code||[];e.code.push(t.toString())}throw e}});case 11:u=e.sent;o.push(u);case 13:e.next=3;break;case 15:case"end":return e.stop()}}},n)}));return In.apply(this,arguments)}function Pn(e){return function(n){if(!n){return false}return(n.token||n).match(e)}}var Mn=Pn(/[()]/);function Rn(n){var e=typeof n==="string"?w(n):n;var t=e.filter(Mn);var r=t.filter(function(n){return(n.token||n)===")"});var i=t.filter(function(n){return(n.token||n)==="("});return r.length===i.length}M.unDry=function(n){return new M(n.car,n.cdr)};M.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};I.prototype.toDry=function(){return{value:null}};I.unDry=function(){return P};L.prototype.toDry=function(){return{value:{name:this.name}}};L.unDry=function(n){return new L(n.name)};function Cn(n){console.error(n.message||n);if(n.code){console.error(n.code.map(function(n,e){return"[".concat(e+1,"]: ").concat(n)}))}}function Bn(){var i="text/x-lips";if(window.document){var a=Array.from(document.querySelectorAll("script"));return function e(){var n=a.shift();if(n){var t=n.getAttribute("type");if(t===i){var r=n.getAttribute("src");if(r){return l.fetch(r).then(function(n){return n.text()}).then(Ln).then(e)["catch"](function(n){Cn(n);e()})}else{return Ln(n.innerHTML).then(e)["catch"](function(n){Cn(n);e()})}}else if(t&&t.match(/lips|lisp/)){console.warn("Expecting "+i+" found "+t)}return e()}}()}}if(typeof window!=="undefined"){n(window,Bn)}F.__className="Ahead";S.__className="Pattern";j.__className="Formatter";$.__className="Macro";gn.__className="Environment";var Tn={version:"0.17.0",exec:Ln,parse:s,tokenize:w,evaluate:On,Environment:gn,global_environment:_n,globalEnvironment:_n,env:_n,balanced_parenthesis:Rn,balancedParenthesis:Rn,Macro:$,quote:bn,Pair:M,Formatter:j,specials:y,nil:P,resolvePromises:An,Symbol:L,LNumber:mn};_n.set("lips",Tn);return Tn})})(); \ No newline at end of file +(function(){"use strict";function n(n,e){return e={exports:{}},n(e,e.exports),e.exports}var c=n(function(t){function r(n,e){t.exports=r=Object.setPrototypeOf||function n(e,t){e.__proto__=t;return e};return r(n,e)}t.exports=r});var Hn=n(function(r){function i(){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(n){return false}}function a(n,e,t){if(i()){r.exports=a=Reflect.construct}else{r.exports=a=function n(e,t,r){var i=[null];i.push.apply(i,t);var a=Function.bind.apply(e,i);var o=new a;if(r)c(o,r.prototype);return o}}return a.apply(null,arguments)}r.exports=a});var e=n(function(n){var e=function(a){var n=Object.prototype;var s=n.hasOwnProperty;var u;var e=typeof Symbol==="function"?Symbol:{};var i=e.iterator||"@@iterator";var t=e.asyncIterator||"@@asyncIterator";var r=e.toStringTag||"@@toStringTag";function o(n,e,t,r){var i=e&&e.prototype instanceof c?e:c;var a=Object.create(i.prototype);var o=new A(r||[]);a._invoke=j(n,t,o);return a}a.wrap=o;function f(n,e,t){try{return{type:"normal",arg:n.call(e,t)}}catch(n){return{type:"throw",arg:n}}}var l="suspendedStart";var h="suspendedYield";var p="executing";var d="completed";var v={};function c(){}function m(){}function y(){}var g={};g[i]=function(){return this};var b=Object.getPrototypeOf;var w=b&&b(b(q([])));if(w&&w!==n&&s.call(w,i)){g=w}var _=y.prototype=c.prototype=Object.create(g);m.prototype=_.constructor=y;y.constructor=m;y[r]=m.displayName="GeneratorFunction";function x(n){["next","throw","return"].forEach(function(e){n[e]=function(n){return this._invoke(e,n)}})}a.isGeneratorFunction=function(n){var e=typeof n==="function"&&n.constructor;return e?e===m||(e.displayName||e.name)==="GeneratorFunction":false};a.mark=function(n){if(Object.setPrototypeOf){Object.setPrototypeOf(n,y)}else{n.__proto__=y;if(!(r in n)){n[r]="GeneratorFunction"}}n.prototype=Object.create(_);return n};a.awrap=function(n){return{__await:n}};function k(c){function u(n,e,t,r){var i=f(c[n],c,e);if(i.type==="throw"){r(i.arg)}else{var a=i.arg;var o=a.value;if(o&&typeof o==="object"&&s.call(o,"__await")){return Promise.resolve(o.__await).then(function(n){u("next",n,t,r)},function(n){u("throw",n,t,r)})}return Promise.resolve(o).then(function(n){a.value=n;t(a)},function(n){return u("throw",n,t,r)})}}var e;function n(t,r){function n(){return new Promise(function(n,e){u(t,r,n,e)})}return e=e?e.then(n,n):n()}this._invoke=n}x(k.prototype);k.prototype[t]=function(){return this};a.AsyncIterator=k;a.async=function(n,e,t,r){var i=new k(o(n,e,t,r));return a.isGeneratorFunction(e)?i:i.next().then(function(n){return n.done?n.value:i.next()})};function j(o,c,u){var s=l;return function n(e,t){if(s===p){throw new Error("Generator is already running")}if(s===d){if(e==="throw"){throw t}return N()}u.method=e;u.arg=t;while(true){var r=u.delegate;if(r){var i=E(r,u);if(i){if(i===v)continue;return i}}if(u.method==="next"){u.sent=u._sent=u.arg}else if(u.method==="throw"){if(s===l){s=d;throw u.arg}u.dispatchException(u.arg)}else if(u.method==="return"){u.abrupt("return",u.arg)}s=p;var a=f(o,c,u);if(a.type==="normal"){s=u.done?d:h;if(a.arg===v){continue}return{value:a.arg,done:u.done}}else if(a.type==="throw"){s=d;u.method="throw";u.arg=a.arg}}}}function E(n,e){var t=n.iterator[e.method];if(t===u){e.delegate=null;if(e.method==="throw"){if(n.iterator["return"]){e.method="return";e.arg=u;E(n,e);if(e.method==="throw"){return v}}e.method="throw";e.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var r=f(t,n.iterator,e.arg);if(r.type==="throw"){e.method="throw";e.arg=r.arg;e.delegate=null;return v}var i=r.arg;if(!i){e.method="throw";e.arg=new TypeError("iterator result is not an object");e.delegate=null;return v}if(i.done){e[n.resultName]=i.value;e.next=n.nextLoc;if(e.method!=="return"){e.method="next";e.arg=u}}else{return i}e.delegate=null;return v}x(_);_[r]="Generator";_[i]=function(){return this};_.toString=function(){return"[object Generator]"};function F(n){var e={tryLoc:n[0]};if(1 in n){e.catchLoc=n[1]}if(2 in n){e.finallyLoc=n[2];e.afterLoc=n[3]}this.tryEntries.push(e)}function S(n){var e=n.completion||{};e.type="normal";delete e.arg;n.completion=e}function A(n){this.tryEntries=[{tryLoc:"root"}];n.forEach(F,this);this.reset(true)}a.keys=function(t){var r=[];for(var n in t){r.push(n)}r.reverse();return function n(){while(r.length){var e=r.pop();if(e in t){n.value=e;n.done=false;return n}}n.done=true;return n}};function q(e){if(e){var n=e[i];if(n){return n.call(e)}if(typeof e.next==="function"){return e}if(!isNaN(e.length)){var t=-1,r=function n(){while(++t=0;--e){var i=this.tryEntries[e];var a=i.completion;if(i.tryLoc==="root"){return n("end")}if(i.tryLoc<=this.prev){var o=s.call(i,"catchLoc");var c=s.call(i,"finallyLoc");if(o&&c){if(this.prev=0;--t){var r=this.tryEntries[t];if(r.tryLoc<=this.prev&&s.call(r,"finallyLoc")&&this.prev=0;--e){var t=this.tryEntries[e];if(t.finallyLoc===n){this.complete(t.completion,t.afterLoc);S(t);return v}}},catch:function(n){for(var e=this.tryEntries.length-1;e>=0;--e){var t=this.tryEntries[e];if(t.tryLoc===n){var r=t.completion;if(r.type==="throw"){var i=r.arg;S(t)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(n,e,t){this.delegate={iterator:q(n),resultName:e,nextLoc:t};if(this.method==="next"){this.arg=u}return v}};return a}(n.exports);try{regeneratorRuntime=e}catch(n){Function("r","regeneratorRuntime = r")(e)}});var Jn=e;function u(n,e,t,r,i,a,o){try{var c=n[a](o);var u=c.value}catch(n){t(n);return}if(c.done){e(u)}else{Promise.resolve(u).then(r,i)}}function t(c){return function(){var n=this,o=arguments;return new Promise(function(e,t){var r=c.apply(n,o);function i(n){u(r,e,t,i,a,"next",n)}function a(n){u(r,e,t,i,a,"throw",n)}i(undefined)})}}var $n=t;function r(n){if(Array.isArray(n)){for(var e=0,t=new Array(n.length);e1&&arguments[1]!==g?arguments[1]:1;return n[n.length-e]}function o(n){if(typeof n==="string"){var e=/([-\\^$[\]()+{}?*.|])/g;return n.replace(e,"\\$1")}}function c(n){var i=e();n=n.replace(/\n\r|\r/g,"\n");var a=0;var o=0;var c=[];var u=[];var s=0;n.split(f).filter(Boolean).forEach(function(n){if(n.match(f)){s=0;if(u.length){var e=h(u);if(e.token.match(/\n/)){var t=e.token.split("\n").pop();s+=t.length}else{s+=e.token.length}s+=e.col}var r={col:s,line:o,token:n,offset:a};c.push(r);u.push(r);a+=n.length;s+=n.length;o+=(n.match("\n")||[]).length;return}n.split(i).filter(Boolean).forEach(function(n){var e={col:s,line:o,token:n,offset:a};s+=n.length;a+=n.length;c.push(e);u.push(e);if(n==="\n"){++o;u=[];s=0}})});return c}function w(n,e){if(e){return c(n)}else{return c(n).map(function(n){return n.token.trim()}).filter(function(n){return n&&!n.match(/^;/)})}}var y={"'":new L("quote"),"`":new L("quasiquote"),",@":new L("unquote-splicing"),",":new L("unquote")};function s(n){if(typeof n==="string"){n=w(n)}var a=[];var o=[];var c=null;var u=Object.keys(y);var s=u.map(function(n){return y[n].name});var f=0;var l=false;var h=[];var p=[];var d=0;function v(){var n=a[a.length-1];if(n instanceof Array&&n[0]instanceof L&&s.includes(n[0].name)&&a.length>1&&!n[0].literal){a.pop();if(a[a.length-1].length===1&&a[a.length-1][0]instanceof L){a[a.length-1].push(n)}else if(a[a.length-1]instanceof M){if(a[a.length-1].cdr instanceof M){a[a.length-1]=new M(a[a.length-1],M.fromArray(n))}else{a[a.length-1].cdr=M.fromArray(n)}}else{a[a.length-1].push(n)}}}n.forEach(function(n){var e=a[a.length-1];if(u.indexOf(n)!==-1){d++;c=n;a.push([y[c]]);if(!c){p=[]}p.push(c)}else{if(c){h.push(p);p=[]}if(n==="("){l=true;f++;a.push([]);c=null;d=0}else if(n==="."&&!l){a[a.length-1]=M.fromArray(e)}else if(n===")"){f--;if(!a.length){throw new Error("Unbalanced parenthesis")}if(a.length===1){o.push(a.pop())}else if(a.length>1){var t=a.pop();e=a[a.length-1];if(e instanceof Array){e.push(t)}else if(e instanceof M){e.append(M.fromArray(t))}if(h.length){p=h.pop();while(p.length){v();p.pop()}}else{v()}}if(f===0&&a.length){o.push(a.pop())}}else{l=false;var r=m(n);if(c){while(d--){a[a.length-1].push(r);r=a.pop()}h.pop();d=0;c=false}else if(r instanceof L&&s.includes(r.name)){r.literal=true}e=a[a.length-1];if(e instanceof M){var i=e;while(true){if(i.cdr===P){if(r instanceof Array){i.cdr=M.fromArray(r)}else{i.cdr=r}break}else{i=i.cdr}}}else if(!a.length){o.push(r)}else{e.push(r)}}}});if(!n.filter(function(n){return n.match(/^[()]$/)}).length&&a.length){o=o.concat(a);a=[]}if(a.length){throw new Error("Unbalanced parenthesis 2")}return o.map(function(n){if(n instanceof Array){return M.fromArray(n)}return n})}function p(n){var e=arguments.length>1&&arguments[1]!==g?arguments[1]:function(n){return n};var t=arguments.length>2&&arguments[2]!==g?arguments[2]:null;if(U(n)){var r=n.then(e);if(t===null){return r}else{return r["catch"](t)}}return e(n)}function u(n,e){if(e instanceof RegExp){return function(n){return String(n).match(e)}}else if(typeof e!=="function"){throw new Error("".concat(n," argument need to be a function or RegExp"))}else{return e}}function d(n,e,t){if(e){if(t){n.__doc__=e}else{n.__doc__=v(e)}}return n}function v(n){return n.split("\n").map(function(n){return n.trim()}).join("\n")}function _(n){var e=arguments.length>1&&arguments[1]!==g?arguments[1]:1;var t=n.length;if(e<=0){throw Error("previousSexp: Invlaid argument sexp = ".concat(e))}n:while(e--&&t>=0){var r=1;while(r>0){var i=n[--t];if(!i){break n}if(i==="("||i.token==="("){r--}else if(i===")"||i.token===")"){r++}}t--}return n.slice(t+1)}function x(n){if(!n||!n.length){return 0}var e=n.length;if(n[e-1].token==="\n"){return 0}while(--e){if(n[e].token==="\n"){var t=(n[e+1]||{}).token;if(t){return t.length}}}return 0}function k(n,e){return c(n,e)===e.length;function c(n,e){var t=0;var r={};for(var i=0;i0){continue}}}else if(n[t]instanceof Array){var o=c(n[t],e.slice(i));if(o===-1||o+i>e.length){return-1}i+=o-1;t++;continue}else{return-1}t++}if(n.length!==t){return-1}return e.length}}function j(n){this._code=n.replace(/\r/g,"")}j.defaults={offset:0,indent:2,specials:[/^define/,"lambda","let","let*"]};j.match=k;j.prototype._options=function n(e){var t=j.defaults;if(typeof e==="undefined"){return Object.assign({},t)}var r=e&&e.specials||[];return Object.assign({},t,e,{specials:t.specials.concat(r)})};j.prototype.indent=function n(e){var t=w(this._code,true);return this._indent(t,e)};j.matchSpecial=function(n,e){var t=e.specials;if(t.indexOf(n)!==-1){return true}else{var r=t.filter(function(n){return n instanceof RegExp});var i=true;var a=false;var o=g;try{for(var c=r[Symbol.iterator](),u;!(i=(u=c.next()).done);i=true){var s=u.value;if(n.match(s)){return true}}}catch(n){a=true;o=n}finally{try{if(!i&&c["return"]!=null){c["return"]()}}finally{if(a){throw o}}}}return false};j.prototype._indent=function n(e,t){var r=this._options(t);var i=x(e);var a=_(e);if(a&&a.length){if(a[0].line>0){r.offset=0}if(a.length===1){return r.offset+a[0].col+1}else if(j.matchSpecial(a[1].token,r)){return r.offset+a[0].col+r.indent}else if(a[0].line3&&a[1].line===a[3].line){if(a[1].token==="("){return r.offset+a[1].col}return r.offset+a[3].col}else if(a[0].line===a[1].line){return r.offset+r.indent+a[0].col}else{var o=a.slice(2);for(var c=0;c"}else if(typeof n==="string"){return JSON.stringify(n).replace(/\\n/g,"\n")}else if(U(n)){return"<#Promise>"}else if(n instanceof L||n instanceof mn||n instanceof RegExp||n instanceof M||n===P){return n.toString()}else if(n instanceof Array){return n.map(B)}else if(Gn(n)==="object"){if(n===null){return"null"}var e=n.constructor.name;if(e==="Object"){return JSON.stringify(n)}return"<#object("+n.constructor.name+")>"}else if(typeof n!=="undefined"){return n}}M.prototype.markCycles=function(){T(this);return this};M.prototype.haveCycles=function(){var n=arguments.length>0&&arguments[0]!==g?arguments[0]:null;if(!n){return this.haveCycles("car")||this.haveCycles("cdr")}return!!(this.cycles&&this.cycles[n])};function T(n){var i=[];var e=[];function a(n){if(n instanceof M){if(i.includes(n)){if(!e.includes(n)){e.push(n)}return"#".concat(e.length-1,"#")}}}function o(n){if(n instanceof M){i.push(n);var e={};var t=a(n.car);var r=a(n.cdr);if(t){e["car"]=t}else{o(n.car)}if(r){e["cdr"]=r}else{o(n.cdr)}if(t||r){n.cycles=e}else if(n.cycles){delete n.cycles}}}o(n)}M.prototype.toString=function(){var n=["("];if(this.car!==g){var e;if(this.cycles&&this.cycles.car){e=this.cycles.car}else{e=B(this.car)}if(e){n.push(e)}if(this.cdr instanceof M){if(this.cycles&&this.cycles.cdr){n.push(" . ");n.push(this.cycles.cdr)}else{var t;if(this.cycles&&this.cycles.cdr){t=this.cycles.cdr}var r=this.cdr.toString(t).replace(/^\(|\)$/g,"");n.push(" ");n.push(r)}}else if(typeof this.cdr!=="undefined"&&this.cdr!==P){n=n.concat([" . ",B(this.cdr)])}}n.push(")");return n.join("")};M.prototype.set=function(n,e){this[n]=e;if(e instanceof M){this.markCycles()}};M.prototype.append=function(n){if(n instanceof Array){return this.append(M.fromArray(n))}var e=this;if(e.car===g){if(n instanceof M){this.car=n.car;this.cdr=n.cdr}else{this.car=n}}else if(n!==P){while(true){if(e instanceof M&&e.cdr!==P){e=e.cdr}else{break}}e.cdr=n}return this};function H(n,e){if(n instanceof mn&&e instanceof mn){return n.cmp(e)===0}else if(typeof n==="number"||typeof e==="number"){return mn(n).cmp(mn(e))}else if(n instanceof L&&e instanceof L){return n.name===e.name}else{return n===e}}function J(n){return n instanceof M&&n.isEmptyList()||n===P}function $(n,e,t){if(typeof this!=="undefined"&&this.constructor!==$||typeof this==="undefined"){return new $(n,e)}En("Macro",n,"string",1);En("Macro",e,"function",2);if(t){this.__doc__=v(t)}this.name=n;this.fn=e}$.defmacro=function(n,e,t){var r=new $(n,e,t);r.defmacro=true;return r};$.prototype.invoke=function(n,e,t){var r=e.env,i=e.dynamic_scope,a=e.error;var o={dynamic_scope:i,error:a,macro_expand:t};var c=this.fn.call(r,n,o,this.name);return t?bn(c):c};$.prototype.toString=function(){return"#"};var D="define-macro";function Y(a){return function(){var t=$n(Jn.mark(function n(t,u){var s,f,r,i;return Jn.wrap(function n(e){while(1){switch(e.prev=e.next){case 0:r=function n(){r=$n(Jn.mark(function n(t){var r,i,a,o,c;return Jn.wrap(function n(e){while(1){switch(e.prev=e.next){case 0:if(!(t instanceof M&&t.car instanceof L)){e.next=13;break}e.prev=1;r=s.get(t.car);if(!(r instanceof $&&r.defmacro)){e.next=9;break}e.next=6;return r.invoke(t.cdr,u,true);case 6:i=e.sent;if(!(i instanceof M)){e.next=9;break}return e.abrupt("return",i);case 9:e.next=13;break;case 11:e.prev=11;e.t0=e["catch"](1);case 13:a=t.car;if(!(a instanceof M)){e.next=18;break}e.next=17;return f(a);case 17:a=e.sent;case 18:o=t.cdr;if(!(o instanceof M)){e.next=23;break}e.next=22;return f(o);case 22:o=e.sent;case 23:c=new M(a,o);return e.abrupt("return",c);case 25:case"end":return e.stop()}}},n,null,[[1,11]])}));return r.apply(this,arguments)};f=function n(e){return r.apply(this,arguments)};s=u["env"]=this;i=t;if(!a){e.next=12;break}e.t0=bn;e.next=8;return f(t);case 8:e.t1=e.sent.car;return e.abrupt("return",(0,e.t0)(e.t1));case 12:e.next=15;return f(t);case 15:i=e.sent;if(!(t.toString()===i.toString())){e.next=18;break}return e.abrupt("break",21);case 18:t=i;e.next=12;break;case 21:return e.abrupt("return",bn(i.car));case 22:case"end":return e.stop()}}},n,this)}));return function(n,e){return t.apply(this,arguments)}}()}function G(n){return typeof n==="undefined"||n===P||n===null}function U(n){return n instanceof Promise||n&&typeof n!=="undefined"&&typeof n.then==="function"}function Q(n,a){var o=function n(){for(var e=arguments.length,t=new Array(e),r=0;r2?e-2:0),r=2;r1?t-1:0),i=1;i1?e-1:0),r=1;rarray")(a.car);var f=s.inherit("let");var l=0;return function n(){var e=u[l++];function t(n){if(U(n)){return n.then(t)}else if(typeof n==="undefined"){f.set(e.car,P)}else{f.set(e.car,n)}}if(o){o=h?f:s}if(!e){var r=new M(new L("begin"),a.cdr);return On(r,{env:f,dynamic_scope:o,error:c})}else{var i=On(e.cdr.car,{env:h?f:s,dynamic_scope:o,error:c});return p(t(i),n)}}()})}function rn(n,u){return new $(n,function(n){var e=arguments.length>1&&arguments[1]!==g?arguments[1]:{},t=e.dynamic_scope,r=e.error;var i=this;if(t){t=this}var a=n;var o=[];while(a instanceof M&&!J(a)){o.push(On(a.car,{env:i,dynamic_scope:t,error:r}));a=a.cdr}var c=o.filter(U).length;if(c){return Promise.all(o).then(u.bind(this))}else{return u.call(this,o)}})}function an(n){for(var e=arguments.length,t=new Array(e>1?e-1:0),r=1;r2?r-2:0),a=2;a1?n-1:0),t=1;t=o){return a.apply(this,r)}else{return i}}return i.apply(this,arguments)}}function dn(r,i){En("limit",i,"function",2);return function(){for(var n=arguments.length,e=new Array(n),t=0;t1?t-1:0),i=1;i>":function n(e,t){return e>>t},"<<":function n(e,t){return e<>":"ishln"};n=i[n];return mn(this.value.clone()[n](e,r))}};var yn={"+":"add","-":"sub","*":"mul","/":"div","%":"mod","|":"or","&":"and","~":"neg","<<":"shl",">>":"shr"};Object.keys(yn).forEach(function(e){mn.prototype[yn[e]]=function(n){return this.op(e,n)}});mn.prototype.sqrt=function(){var n;if(mn.isNative(this.value)){n=Math.sqrt(this.value)}else if(mn.isBN(this.value)){n=this.value.sqrt()}return new mn(n)};mn.prototype.pow=function(n){n=this.coerce(n);if(mn.isNative(this.value)){try{var e=new Function("a,b","return a**b;");n.value=e(this.value,n.value)}catch(n){throw new Error("Power operator not supported")}}else if(mn.isBN(this.value)){n.value=this.value.pow(n.value)}else{n.value=Math.pow(this.value,n.value)}return n};mn.prototype.neg=function(){var n=this.value;if(mn.isNative(n)){n=-n}else if(mn.isBN(n)){n=n.neg()}return new mn(n)};mn.prototype.abs=function(){var n=this.value;if(mn.isNative(this.value)){if(n<0){n=-n}}else if(mn.isBN(n)){n.iabs()}return new mn(n)};mn.prototype.isOdd=function(){if(mn.isNative(this.value)){if(this.isBigNumber()){return this.value%BigInt(2)===BigInt(1)}return this.value%2===1}else if(mn.isBN(this.value)){return this.value.isOdd()}};mn.prototype.isEven=function(){return!this.isOdd()};mn.prototype.cmp=function(n){n=this.coerce(n);if(mn.isNative(this.value)){if(this.value1&&arguments[1]!==g?arguments[1]:{};if(Gn(n)==="object"){e=n}if(!n||Gn(n)==="object"){n="child of "+(this.name||"unknown")}return new gn(e||{},this,n)};gn.prototype.get=function(n){var e=arguments.length>1&&arguments[1]!==g?arguments[1]:{};var t=e.weak,r=e.context,i=r===void 0?this:r,a=e.throwError,o=a===void 0?true:a;var c;var u=false;if(n instanceof L){if(n.name in this.env){c=this.env[n.name];u=true}}else if(typeof n==="string"){if(typeof this.env[n]!=="undefined"){c=this.env[n];u=true}}if(u){if(mn.isNumber(c)){return mn(c)}if(c instanceof M){return c.markCycles()}if(typeof c==="function"){if(Z(c)){if(t){return Q(c,i)}return W(c,i)}}return c}if(this.parent instanceof gn){return this.parent.get(n,{weak:t,context:i,throwError:o})}else{var s;if(n instanceof L){s=n.name}else if(typeof n==="string"){s=n}if(s){var f=Gn(l[s]);if(f==="function"){if(en(l[s])){return W(l[s],l)}return l[s]}else if(f!=="undefined"){return l[s]}}}if(o){s=(s.name||s).toString();throw new Error("Unbound variable `"+s+"'")}};gn.prototype.set=function(n,e){if(mn.isNumber(e)){e=mn(e)}if(n instanceof L){n=n.name}this.env[n]=e};gn.prototype.has=function(n){return typeof this.env[n]!=="undefined"};gn.prototype.ref=function(n){var e=this;while(true){if(!e){break}if(e.has(n)){return e}e=e.parent}};gn.prototype.parents=function(){var n=this;var e=[];while(n){e.unshift(n);n=n.parent}return e};function bn(n){if(U(n)){return n.then(bn)}if(n instanceof M||n instanceof L){n.data=true}return n}var wn=function(){var e=0;return function(){var n=arguments.length>0&&arguments[0]!==g?arguments[0]:null;if(n!==null){return new L(l.Symbol("#:".concat(n)))}e++;return new L(l.Symbol("#:g".concat(e)))}}();var _n=new gn({nil:P,undefined:g,true:true,NaN:NaN,false:false,stdout:{write:function n(){var e;(e=console).log.apply(e,arguments)}},stdin:{read:function n(){return new Promise(function(n){n(prompt(""))})}},help:d(new $("help",function(n,e){var t=e.dynamic_scope,r=e.error;var i;if(n.car instanceof L){i=n.car}else if(n.car instanceof M&&n.car.car instanceof L){i=n.car.car}else{var a=this;if(t){t=this}var o=On(n.car,{env:a,error:r,dynamic_scope:t});if(o&&o.__doc__){return o.__doc__}}return this.get(i).__doc__}),"(help object)\n\n Macro returns documentation for function or macros including parser\n macros but only if called with parser macro symbol like (help `).\n For normal functions and macros you can save the function in variable."),cons:d(function(n,e){if(J(e)){e=P}return new M(n,e)},"(cons left right)\n\n Function return new Pair out of two arguments."),car:d(function(n){if(n===P){return P}En("car",n,"pair");if(J(n)){return P}return n.car},"(car pair)\n\n Function returns car (head) of the list/pair."),cdr:d(function(n){if(n===P){return P}En("cdr",n,"pair");if(J(n)){return P}return n.cdr},"(cdr pair)\n\n Function returns cdr (tail) of the list/pair."),"set!":d(new $("set!",function(e){var n=arguments.length>1&&arguments[1]!==g?arguments[1]:{},t=n.dynamic_scope,r=n.error;if(t){t=this}var i=On(e.cdr.car,{env:this,dynamic_scope:t,error:r});i=An(i);var a;function o(e,t){if(U(e)){return e.then(function(n){return o(n,t)})}if(U(t)){return t.then(function(n){return o(e,n)})}s[e]=t;return t}if(e.car instanceof M&&L.is(e.car.car,".")){var c=e.car.cdr.car;var u=e.car.cdr.cdr.car;var s=On(c,{env:this,dynamic_scope:t,error:r});var f=On(u,{env:this,dynamic_scope:t,error:r});return o(f,i)}if(!(e.car instanceof L)){throw new Error("set! first argument need to be a symbol or "+"dot accessor that evaluate to object.")}a=this.ref(e.car.name);if(!a){a=this}return p(i,function(n){a.set(e.car,n)})}),"(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."),"set-car!":d(function(n,e){En("set-car!",n,"pair");n.car=e},"(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!":d(function(n,e){En("set-cdr!",n,"pair");n.cdr=e},"(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?":d(function(n){return typeof n==="undefined"||J(n)},"(empty? object)\n\n Function return true if value is undfined empty list."),assoc:d(function(n,e){if(n instanceof M&&!(e instanceof M)){throw new Error("First argument to assoc ned to be a key")}En("assoc",e,"pair");var t=e;while(true){if(!(t instanceof M)||this.get("empty?")(t)){break}var r=t.car.car;if(H(r,n)){return t.car}else if(!t.haveCycles("cdr")){t=t.cdr}}return P},"(assoc key alist)\n\n Function search Alist (list of pairs) until it find the one that\n have head set equal to key, and return found pair."),gensym:d(wn,"(gensym)\n\n Function generate unique symbol, to use with macros as meta name."),require:d(function(n){return require(n)},"(require module)\n\n Function to be used inside Node.js to import the module."),load:d(function(n){En("load",n,"string");var i=this;if(typeof this.get("global",{throwError:false})!=="undefined"){return new Promise(function(t,r){require("fs").readFile(n,function(n,e){if(n){r(n)}else{Ln(e.toString(),i).then(function(){t()})}})})}return l.fetch(n).then(function(n){return n.text()}).then(function(n){return Ln(n,i)}).then(function(){})},"(load filename)\n\n Function fetch the file and evaluate its content as LIPS code."),while:d(new $("while",function(r,n){var i=n.dynamic_scope,a=n.error;var o=this;var c=new M(new L("begin"),r.cdr);var u;if(i){i=o}return function e(){var n=On(r.car,{env:o,dynamic_scope:i,error:a});function t(n){if(n&&!G(n)&&!J(n)){u=On(c,{env:o,dynamic_scope:i,error:a});if(U(u)){return u.then(function(n){u=n;return e()})}else{return e()}}else{return u}}return p(n,t)}()}),"(while cond . body)\n\n Macro that create a loop, it exectue body untill cond expression is false"),if:d(new $("if",function(t,n){var r=n.dynamic_scope,i=n.error;if(r){r=this}var a=this;var e=function n(e){En("if",e,"boolean");if(e){return On(t.cdr.car,{env:a,dynamic_scope:r,error:i})}else{return On(t.cdr.cdr.car,{env:a,dynamic_scope:r,error:i})}};var o=On(t.car,{env:a,dynamic_scope:r,error:i});return p(o,e)}),"(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*":d(tn(true),"(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 and next value can access to\n previous values/names."),let:d(tn(false),"(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*":d(rn("begin*",function(n){return n.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:d(new $("begin",function(n,e){var r=Object.assign({},e);var i=this.get("list->array")(n);if(r.dynamic_scope){r.dynamic_scope=this}r.env=this;var a;return function e(){if(i.length){var n=i.shift();var t=On(n,r);return p(t,function(n){a=n;return e()})}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 $("ignore",function(n,e){var t=e.dynamic_scope,r=e.error;var i={env:this,error:r};if(t){i.dynamic_scope=this}On(new M(new L("begin"),n),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."),timer:d(new $("timer",function(e){var n=arguments.length>1&&arguments[1]!==g?arguments[1]:{},t=n.dynamic_scope,r=n.error;En("timer",e.car,"number");var i=this;if(t){t=this}return new Promise(function(n){setTimeout(function(){n(On(e.cdr.car,{env:i,dynamic_scope:t,error:r}))},e.car)}).then(bn)}),"(timer time expression)\n\n Function return a promise, and it will be automatically evaluated\n after specific time passes. The return value of the function\n will be value of the timer exprssion. If you want to do side effect\n only expression you can wrap your expression in nol call."),define:d($.defmacro("define",function(e,n){var t=this;if(e.car instanceof M&&e.car.car instanceof L){var r=new M(new L("define"),new M(e.car.car,new M(new M(new L("lambda"),new M(e.car.cdr,e.cdr)))));return r}else if(n.macro_expand){return}if(n.dynamic_scope){n.dynamic_scope=this}n.env=t;var i=e.cdr.car;if(i instanceof M){i=On(i,n)}else if(i instanceof L){i=t.get(i)}if(e.car instanceof L){p(i,function(n){t.set(e.car,n)})}}),"(define name expression)\n (define (function-name . args) body)\n\n Macro for defining values. It can be used to define variables,\n or function. If first argument is list it will create function\n with name beeing first element of the list. The macro evalute\n code `(define function (lambda args body))`"),"set-obj!":d(function(n,e,t){var r=Gn(n);if(G(n)||r!=="object"&&r!=="function"){var i=jn("set-obj!",Sn(n),["object","function"]);throw new Error(i)}V(n)[e]=t},"(set-obj! obj key value)\n\n Function set property of JavaScript object"),"current-environment":d(function(){return this},"(current-environment)\n\n Function return current environement."),eval:d(function(n,t){var r=this;En("eval",n,["symbol","pair","array"]);t=t||this;if(n instanceof L){return t.get(n)}if(n instanceof M){return On(n,{env:t,error:function n(e){r.get("error")(e.message);if(e.code){var t=e.code.map(function(n,e){return"[".concat(e+1,"]: ").concat(n)}).join("\n");r.get("error")(t)}}})}if(n instanceof Array){var i=this.get("eval");return n.reduce(function(n,e){return i(e,t)})}},"(eval list)\n\n Function evalute LIPS code as list structure."),lambda:new $("lambda",function(s){var n=arguments.length>1&&arguments[1]!==g?arguments[1]:{},f=n.dynamic_scope,l=n.error;var h=this;var p;if(s.cdr instanceof M&&typeof s.cdr.car==="string"&&s.cdr.cdr!==P){p=s.cdr.car}function e(){var n=(f?this:h).inherit("lambda");var e=s.car;var t=0;var r;if(typeof this!=="undefined"){n.set("this",this)}if(e instanceof L||!J(e)){for(var i=arguments.length,a=new Array(i),o=0;o2&&arguments[2]!==g?arguments[2]:c;if(n instanceof M&&!J(n)){var r=n.car;var i=n.cdr;if(t(r)){r=e(r)}if(t(i)){i=e(i)}if(U(r)||U(i)){return Promise.all([r,i]).then(function(n){var e=Yn(n,2),t=e[0],r=e[1];return new M(t,r)})}else{return new M(r,i)}}return n}function s(n,e){if(n instanceof M){if(J(n)&&e===P){return P}n.append(e)}else{n=new M(n,e)}return n}function f(r,n,e){if(nr){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(t.cdr instanceof M){if(t.cdr.cdr!==P){if(t.cdr.car instanceof M){return p(h(t.cdr.cdr,e,r),function(n){var e=On(t.cdr.car,{env:o,dynamic_scope:i,error:a});return new M(e,n)})}else{return t.cdr}}else{return On(t.cdr.car,{env:o,dynamic_scope:i,error:a})}}else{return t.cdr}}return u(t,function(n){return h(n,e,r)})}return t}function t(n){if(n instanceof M){delete n.data;if(!n.haveCycles("car")){t(n.car)}if(!n.haveCycles("cdr")){t(n.cdr)}}}var r=h(n.car,0,1);return p(r,function(n){t(n);return bn(n)})},"(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:d(function(n){En("clone",n,"pair");return n.clone()},"(clone list)\n\n Function return clone of the list."),append:d(function(n,e){En("append",n,"pair");return this.get("append!")(n.clone(),e)},"(append list item)\n\n Function will create new list with value appended to the end. It return\n New list."),"append!":d(function(n,e){En("append!",n,"pair");if(G(e)||J(e)){return n}return n.append(e)},"(append! name expression)\n\n Destructive version of append, it modify the list in place. It return\n original list."),reverse:d(function(n){En("reverse",n,["array","pair"]);if(n instanceof M){var e=this.get("list->array")(n).reverse();return this.get("array->list")(e)}else if(!(n instanceof Array)){throw new Error(jn("reverse",Sn(n),"array or pair"))}else{return n.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:d(function(n,e){En("nth",n,"number");En("nth",e,["array","pair"]);if(e instanceof M){var t=e;var r=0;while(rarray")(e).join(n)},"(join separator list)\n\n Function return string by joining elements of the list"),split:d(function(n,e){En("split",n,["regex","string"]);En("split",e,"string");return this.get("array->list")(e.split(n))},"(split separator string)\n\n Function create list by splitting string by separatar that can\n be a string or regular expression."),replace:d(function(n,e,t){En("replace",n,["regex","string"]);En("replace",e,["string","function"]);En("replace",t,"string");return t.replace(n,e)},"(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:d(function(n,e){En("match",n,["regex","string"]);En("match",e,"string");var t=e.match(n);return t?this.get("array->list")(t):P},"(match pattern string)\n\n function return match object from JavaScript as list."),search:d(function(n,e){En("search",n,["regex","string"]);En("search",e,"string");return e.search(n)},"(search pattern string)\n\n Function return first found index of the pattern inside a string"),string:d(function e(n,t){if(typeof jQuery!=="undefined"&&n instanceof jQuery.fn.init){return"<#jQuery("+n.length+")>"}if(n instanceof mn){return n.value.toString()}if(typeof n==="undefined"){return"<#undefined>"}if(typeof n==="function"){if(en(n)){return"<#function(native)>"}return"<#function>"}if(n instanceof RegExp){return n.toString()}if(n===P){return"nil"}if(n instanceof Array){return"["+n.map(function(n){return e(n,true)}).join(", ")+"]"}if(n===null||typeof n==="string"&&t){return JSON.stringify(n).replace(/\\n/g,"\n")}if(n instanceof M){return n.toString()}if(n instanceof L){return n.toString()}if(l.HTMLElement&&n instanceof l.HTMLElement){return"<#HTMLElement(".concat(n.tagName.toLowerCase(),")>")}if(Gn(n)==="object"){var r=n.constructor;var i;if(typeof r.__className==="string"){i=r.__className}else if(Sn(n)==="instance"){i="instance"}else{i=r.name}if(i!==""){return"<#"+i+">"}return"<#Object>"}if(typeof n!=="string"){return n.toString()}return n},"(string obj)\n\n Function return string LIPS representation of an object as string."),env:d(function(n){n=n||this;var e=Object.keys(n.env);var t;if(e.length){t=M.fromArray(e)}else{t=P}if(n.parent!==g){return this.get("env").call(this,n.parent).append(t)}return t},"(env obj)\n\n Function return list values (functions and variables) inside environment."),new:d(function(n){for(var e=arguments.length,t=new Array(e>1?e-1:0),r=1;rlist":d(function(n){En("array->list",n,"array");return M.fromArray(n)},"(array->list array)\n\n Function convert JavaScript array to LIPS list."),"tree->array":d(C("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":d(C("list->array"),"(list->array list)\n\n Function convert LIPS list into JavaScript array."),apply:d(function(n,e){En("call",n,"function",1);En("call",e,"pair",2);return n.apply(void 0,Dn(this.get("list->array")(e)))},"(apply fn list)\n\n Function that call function with list of arguments."),length:d(function(n){if(!n){return mn(0)}if(n instanceof M){return mn(n.length())}if("length"in n){return mn(n.length)}},"(length expression)\n\n Function return length of the object, the object can be list\n or any object that have length property."),try:d(new $("try",function(a,n){var o=this;var c=n.dynamic_scope,u=n.error;return new Promise(function(i){var n={env:o,error:function n(e){var t=o.inherit("try");t.set(a.cdr.car.cdr.car.car,e);var r={env:t,error:u};if(c){r.dynamic_scope=o}p(On(new M(new L("begin"),a.cdr.car.cdr.cdr),r),function(n){i(n)})}};if(c){n.dynamic_scope=o}var e=On(a.car,n);if(U(e)){e["catch"](n.error).then(i)}else{i(e)}})}),"(try expr (catch (e) code)"),find:d(function e(t,r){En("find",t,["regex","function"]);En("find",r,"pair");if(G(r)){return P}var n=u("find",t);return p(n(r.car),function(n){if(n&&n!==P){return r.car}return e(t,r.cdr)})},"(find fn list)\n (find regex list)\n\n Higher order Function find first value for which function return true.\n If called with regex it will create matcher function."),"for-each":d(function(n){En("for-each",n,"function");for(var e=arguments.length,t=new Array(e>1?e-1:0),r=1;r1?e-1:0),a=1;a3?r-3:0),a=3;a3?i-3:0),o=3;oarray")(e);var a=[];var o=u("filter",n);return function e(t){function n(n){if(n&&n!==P){a.push(r)}return e(++t)}if(t===i.length){return M.fromArray(a)}var r=i[t];return p(o(r,t),n)}(0)},"(filter fn list)\n (filter regex list)\n\n Higher order function that call `fn` for each element of the list\n and return list for only those elements for which funtion return\n true value. If called with regex it will create matcher function."),range:d(function(n){En("range",n,"number");if(n instanceof mn){n=n.valueOf()}return M.fromArray(new Array(n).fill(0).map(function(n,e){return mn(e)}))},"(range n)\n\n Function return list of n numbers from 0 to n - 1"),compose:d(cn,"(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:d(on,"(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:d(pn,"(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 (print (add12 3 4))"),odd:d(fn(function(n){return mn(n).isOdd()}),"(odd number)\n Function check if number os odd."),even:d(fn(function(n){return mn(n).isEvent()}),"(even number)\n\n Function check if number is even."),"*":d(hn(function(n,e){return mn(n).mul(e)}),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":d(hn(function(n,e){return mn(n).add(e)}),"(+ . numbers)\n\n Sum all numbers passed as arguments. If single value is passed it will\n return that value."),"-":d(function(){for(var n=arguments.length,e=new Array(n),t=0;t":d(function(n,e){return mn(n).cmp(e)===1},"(> a b)\n\n Function compare two numbers and check if first argument is greater\n than the second one"),"<":d(function(n,e){return mn(n).cmp(e)===-1},"(< a b)\n\n Function compare two numbers and check if first argument is less\n than the second one"),"<=":d(function(n,e){return[0,-1].includes(mn(n).cmp(e))},"(<= a b)\n\n Function compare two numbers and check if first argument is less or\n equal to the second one"),">=":d(function(n,e){return[0,1].includes(mn(n).cmp(e))},"(>= a b)\n\n Function compare two numbers and check if first argument is less or\n equal to the second one"),"eq?":d(H,"(eq? a b)\n\n Function compare two values if they are identical."),or:d(new $("or",function(n,e){var i=e.dynamic_scope,a=e.error;var o=this.get("list->array")(n);var c=this;if(i){i=c}var u;return function e(){function n(n){u=n;if(u){return u}else{return e()}}var t=o.shift();if(typeof t==="undefined"){if(u){return u}else{return false}}else{var r=On(t,{env:c,dynamic_scope:i,error:a});return p(r,n)}}()}),"(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:d(new $("and",function(n){var e=arguments.length>1&&arguments[1]!==g?arguments[1]:{},i=e.dynamic_scope,a=e.error;var o=this.get("list->array")(n);var c=this;if(i){i=c}if(!o.length){return true}var u;return function e(){function n(n){u=n;if(!u){return false}else{return e()}}var t=o.shift();if(typeof t==="undefined"){if(u){return u}else{return false}}else{var r=On(t,{env:c,dynamic_scope:i,error:a});return p(r,n)}}()}),"(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."),"|":d(function(n,e){return mn(n).or(e)},"(& a b)\n\n Function calculate or bit operation."),"&":d(function(n,e){return mn(n).and(e)},"(& a b)\n\n Function calculate and bit operation."),"~":d(function(n){return mn(n).neg()},"(~ number)\n\n Function negate the value."),">>":d(function(n,e){return mn(n).shr(e)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":d(function(n,e){return mn(n).shl(e)},"(<< a b)\n\n Function left shit the value a by value b."),not:d(function(n){if(J(n)){return true}return!n},"(not object)\n\n Function return negation of the argument."),"->":d(function(n,e){for(var t=arguments.length,r=new Array(t>2?t-2:0),i=2;i obj name . args)\n\n Function get function from object and call it with arguments.")},g,"global");["floor","round","ceil"].forEach(function(e){_n.set(e,d(function(n){En(e,n,"number");if(n instanceof mn){return n[e]()}},"(".concat(e," number)\n\n Function calculate ").concat(e," of a number.")))});function xn(n){if(n.length===1){return n[0]}else{var e=[];var t=xn(n.slice(1));for(var r=0;r3&&arguments[3]!==g?arguments[3]:null;var i=n?" in function `".concat(n,"`"):"";if(r!==null){i+=" argument ".concat(r)}if(t instanceof Array){var a=t[t.length-1];t=t.slice(0,-1).join(", ")+" or "+a}return"Expecting ".concat(t," got ").concat(e).concat(i)}function En(n,e,t){var r=arguments.length>3&&arguments[3]!==g?arguments[3]:null;var i=Sn(e);var a=false;if(t instanceof Array&&t.includes(i)){a=true}if(!a&&i!==t){throw new Error(jn(n,i,t,r))}}function Fn(n){var e=Gn(n);return["string","function"].includes(e)||n instanceof mn||n instanceof RegExp}function Sn(n){var e={pair:M,symbol:L,macro:$,array:Array,native_symbol:l.Symbol};if(n===P){return"nil"}if(n===null){return"null"}for(var t=0,r=Object.entries(e);t1&&arguments[1]!==g?arguments[1]:{},r=n.env,i=n.dynamic_scope,t=n.error,a=t===void 0?function(){}:t;try{if(i===true){r=i=r||_n}else if(r===true){r=i=_n}else{r=r||_n}var o={env:r,dynamic_scope:i,error:a};var c;if(G(e)){return e}if(J(e)){return R()}if(e instanceof L){return r.get(e,{weak:true})}var u=e.car;var s=e.cdr;if(u instanceof M){c=An(On(u,o));if(U(c)){return c.then(function(n){return On(new M(n,e.cdr),o)})}else if(typeof c!=="function"){throw new Error(Sn(c)+" "+r.get("string")(c)+" is not a function while evaluating "+e.toString())}}if(u instanceof L){c=r.get(u,{weak:true});if(c instanceof $){var f=Nn(c,s,o);return p(f,function(n){if(n instanceof M){return n.markCycles()}return n})}else if(typeof c!=="function"){if(c){var l="".concat(Sn(c)," `").concat(c,"' is not a function");throw new Error(l)}throw new Error("Unknown function `".concat(u.name,"'"))}}else if(typeof u==="function"){c=u}if(typeof c==="function"){var h=qn(s,o);return p(h,function(n){var e=i||r;var t=An(c.apply(e,n));return p(t,function(n){if(n instanceof M){return bn(n.markCycles())}return n},a)})}else if(e instanceof L){c=r.get(e);if(c==="undefined"){throw new Error("Unbound variable `"+e.name+"'")}return c}else if(e instanceof M){c=u&&u.toString();throw new Error("".concat(Sn(u)," ").concat(c," is not a function"))}else{return e}}catch(n){a&&a(n,e)}}function Ln(n,e,t){return In.apply(this,arguments)}function In(){In=$n(Jn.mark(function n(t,r,i){var a,o,c,u;return Jn.wrap(function n(e){while(1){switch(e.prev=e.next){case 0:if(i===true){r=i=r||_n}else if(r===true){r=i=_n}else{r=r||_n}a=s(t);o=[];case 3:c=a.shift();if(c){e.next=9;break}return e.abrupt("return",o);case 9:e.next=11;return On(c,{env:r,dynamic_scope:i,error:function n(e,t){if(t){e.code=e.code||[];e.code.push(t.toString())}throw e}});case 11:u=e.sent;o.push(u);case 13:e.next=3;break;case 15:case"end":return e.stop()}}},n)}));return In.apply(this,arguments)}function Pn(e){return function(n){if(!n){return false}return(n.token||n).match(e)}}var Mn=Pn(/[()]/);function Rn(n){var e=typeof n==="string"?w(n):n;var t=e.filter(Mn);var r=t.filter(function(n){return(n.token||n)===")"});var i=t.filter(function(n){return(n.token||n)==="("});return r.length===i.length}M.unDry=function(n){return new M(n.car,n.cdr)};M.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};I.prototype.toDry=function(){return{value:null}};I.unDry=function(){return P};L.prototype.toDry=function(){return{value:{name:this.name}}};L.unDry=function(n){return new L(n.name)};function Cn(n){console.error(n.message||n);if(n.code){console.error(n.code.map(function(n,e){return"[".concat(e+1,"]: ").concat(n)}))}}function Bn(){var i="text/x-lips";if(window.document){var a=Array.from(document.querySelectorAll("script"));return function e(){var n=a.shift();if(n){var t=n.getAttribute("type");if(t===i){var r=n.getAttribute("src");if(r){return l.fetch(r).then(function(n){return n.text()}).then(Ln).then(e)["catch"](function(n){Cn(n);e()})}else{return Ln(n.innerHTML).then(e)["catch"](function(n){Cn(n);e()})}}else if(t&&t.match(/lips|lisp/)){console.warn("Expecting "+i+" found "+t)}return e()}}()}}if(typeof window!=="undefined"){n(window,Bn)}E.__className="Ahead";F.__className="Pattern";j.__className="Formatter";$.__className="Macro";gn.__className="Environment";var Tn={version:"DEV",exec:Ln,parse:s,tokenize:w,evaluate:On,Environment:gn,global_environment:_n,globalEnvironment:_n,env:_n,balanced_parenthesis:Rn,balancedParenthesis:Rn,Macro:$,quote:bn,Pair:M,Formatter:j,specials:y,nil:P,resolvePromises:An,Symbol:L,LNumber:mn};_n.set("lips",Tn);return Tn})})(); \ No newline at end of file diff --git a/src/lips.js b/src/lips.js index 2aa775fd..b439f02e 100644 --- a/src/lips.js +++ b/src/lips.js @@ -3433,7 +3433,10 @@ lists.forEach((arg, i) => { typecheck('map', arg, ['pair', 'nil'], i + 1); }); - if (lists.some((x) => isEmptyList(x))) { + if (lists.some(x => x === nil)) { + return nil; + } + if (lists.some(isEmptyList)) { return emptyList(); } return unpromise(fn.call(this, ...lists.map(l => l.car)), (head) => {