diff --git a/Makefile b/Makefile index ed82db33..e05fbff4 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: publish test coveralls lint -VERSION=0.15.2 +VERSION=0.15.3 BRANCH=`git branch | grep '^*' | sed 's/* //'` DATE=`date -uR` SPEC_CHECKSUM=`md5sum spec/lips.spec.js | cut -d' ' -f 1` diff --git a/README.md b/README.md index 73554eb2..4c2c8280 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ## LIPS is Pretty Simple -[![npm](https://img.shields.io/badge/npm-0.15.2-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) -[![travis](https://travis-ci.org/jcubic/jquery.terminal.svg?branch=master&4bdf269495960b071b32fa1a9d83d04d8ad97fa5)](https://travis-ci.org/jcubic/jquery.terminal) +[![npm](https://img.shields.io/badge/npm-0.15.3-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) +[![travis](https://travis-ci.org/jcubic/jquery.terminal.svg?branch=master&626c660e2f679156e08cd1adefeefce68e461c16)](https://travis-ci.org/jcubic/jquery.terminal) [![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=master&c0db2af4d10e185d40b28d0fbe58d046)](https://coveralls.io/github/jcubic/lips?branch=master) diff --git a/dist/lips.js b/dist/lips.js index d6409461..2df80cf6 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.15.2 + * LIPS is Pretty Simple - simple scheme like lisp in JavaScript - v. 0.15.3 * * Copyright (c) 2018-2019 Jakub T. Jankiewicz * Released under the MIT license @@ -21,7 +21,7 @@ * http://javascript.nwbox.com/ContentLoaded/ * http://javascript.nwbox.com/ContentLoaded/MIT-LICENSE * - * build: Sat, 25 May 2019 09:40:32 +0000 + * build: Sat, 25 May 2019 09:41:16 +0000 */ (function () { 'use strict'; @@ -5831,7 +5831,7 @@ Environment.__className = 'Environment'; // ------------------------------------------------------------------------- var lips = { - version: '0.15.2', + version: '0.15.3', exec: exec, parse: parse, tokenize: tokenize, diff --git a/dist/lips.min.js b/dist/lips.min.js index bb3fb806..dc7fe0d8 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.15.2 + * LIPS is Pretty Simple - simple scheme like lisp in JavaScript - v. 0.15.3 * * Copyright (c) 2018-2019 Jakub T. Jankiewicz * Released under the MIT license @@ -21,7 +21,7 @@ * http://javascript.nwbox.com/ContentLoaded/ * http://javascript.nwbox.com/ContentLoaded/MIT-LICENSE * - * build: Sat, 25 May 2019 09:40:32 +0000 + * build: Sat, 25 May 2019 09:41:16 +0000 */ (function(){"use strict";function n(n,e){return e={exports:{}},n(e,e.exports),e.exports}var u=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 Tn=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)u(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 c;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 u?e:u;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 u(){}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=u.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(u){function c(n,e,t,r){var i=f(u[n],u,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){c("next",n,t,r)},function(n){c("throw",n,t,r)})}return Promise.resolve(o).then(function(n){a.value=n;t(a)},function(n){return c("throw",n,t,r)})}}var e;function n(t,r){function n(){return new Promise(function(n,e){c(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,u,c){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()}c.method=e;c.arg=t;while(true){var r=c.delegate;if(r){var i=F(r,c);if(i){if(i===v)continue;return i}}if(c.method==="next"){c.sent=c._sent=c.arg}else if(c.method==="throw"){if(s===l){s=d;throw c.arg}c.dispatchException(c.arg)}else if(c.method==="return"){c.abrupt("return",c.arg)}s=p;var a=f(o,u,c);if(a.type==="normal"){s=c.done?d:h;if(a.arg===v){continue}return{value:a.arg,done:c.done}}else if(a.type==="throw"){s=d;c.method="throw";c.arg=a.arg}}}}function F(n,e){var t=n.iterator[e.method];if(t===c){e.delegate=null;if(e.method==="throw"){if(n.iterator["return"]){e.method="return";e.arg=c;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=c}}else{return i}e.delegate=null;return v}x(_);_[r]="Generator";_[i]=function(){return this};_.toString=function(){return"[object Generator]"};function E(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(E,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 u=s.call(i,"finallyLoc");if(o&&u){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=c}return v}};return a}(n.exports);try{regeneratorRuntime=e}catch(n){Function("r","regeneratorRuntime = r")(e)}});var Hn=e;function c(n,e,t,r,i,a,o){try{var u=n[a](o);var c=u.value}catch(n){t(n);return}if(u.done){e(c)}else{Promise.resolve(c).then(r,i)}}function t(u){return function(){var n=this,o=arguments;return new Promise(function(e,t){var r=u.apply(n,o);function i(n){c(r,e,t,i,a,"next",n)}function a(n){c(r,e,t,i,a,"throw",n)}i(undefined)})}}var Jn=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 u(n){var i=e();n=n.replace(/\n\r|\r/g,"\n");var a=0;var o=0;var u=[];var c=[];var s=0;n.split(f).filter(Boolean).forEach(function(n){if(n.match(f)){s=0;if(c.length){var e=h(c);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};u.push(r);c.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;u.push(e);c.push(e);if(n==="\n"){++o;c=[];s=0}})});return u}function w(n,e){if(e){return u(n)}else{return u(n).map(function(n){return n.token.trim()}).filter(function(n){return n&&!n.match(/^;/)})}}var y={"'":new O("quote"),"`":new O("quasiquote"),",@":new O("unquote-splicing"),",":new O("unquote")};function s(n){if(typeof n==="string"){n=w(n)}var a=[];var o=[];var u=null;var c=Object.keys(y);var s=c.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 O&&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 O){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(c.indexOf(n)!==-1){d++;u=n;a.push([y[u]]);if(!u){p=[]}p.push(u)}else{if(u){h.push(p);p=[]}if(n==="("){l=true;f++;a.push([]);u=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(u){while(d--){a[a.length-1].push(r);r=a.pop()}h.pop();d=0;u=false}else if(r instanceof O&&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 _(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 c(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__=p(e)}}return n}function p(n){return n.split("\n").map(function(n){return n.trim()}).join("\n")}function x(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 v(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 u(n,e)===e.length;function u(n,e){var t=0;var r={};for(var i=0;i0){continue}}}else if(n[t]instanceof Array){var o=u(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 u=r[Symbol.iterator](),c;!(i=(c=u.next()).done);i=true){var s=c.value;if(n.match(s)){return true}}}catch(n){a=true;o=n}finally{try{if(!i&&u["return"]!=null){u["return"]()}}finally{if(a){throw o}}}}return false};j.prototype._indent=function n(e,t){var r=this._options(t);var i=v(e);var a=x(e);if(a){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 u=0;u"}else if(typeof n==="string"){return JSON.stringify(n).replace(/\\n/g,"\n")}else if(U(n)){return"<#Promise>"}else if(n instanceof O||n instanceof dn||n instanceof RegExp||n instanceof M||n===P){return n.toString()}else if(n instanceof Array){return n.map(C)}else if(Yn(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=C(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([" . ",C(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 dn&&e instanceof dn){return n.cmp(e)===0}else if(typeof n==="number"||typeof e==="number"){return dn(n).cmp(dn(e))}else if(n instanceof O&&e instanceof O){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)}jn("Macro",n,"string",1);jn("Macro",e,"function",2);if(t){this.__doc__=p(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 u=this.fn.call(r,n,o,this.name);return t?yn(u):u};$.prototype.toString=function(){return"#"};var D="define-macro";function Y(a){return function(){var t=Jn(Hn.mark(function n(t,c){var s,f,r,i;return Hn.wrap(function n(e){while(1){switch(e.prev=e.next){case 0:r=function n(){r=Jn(Hn.mark(function n(t){var r,i,a,o,u;return Hn.wrap(function n(e){while(1){switch(e.prev=e.next){case 0:if(!(t instanceof M&&t.car instanceof O)){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,c,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:u=new M(a,o);return e.abrupt("return",u);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=c["env"]=this;i=t;if(!a){e.next=12;break}e.t0=yn;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",yn(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=c[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 O("begin"),a.cdr);return Nn(r,{env:f,dynamic_scope:o,error:u})}else{var i=Nn(e.cdr.car,{env:h?f:s,dynamic_scope:o,error:u});return _(t(i),n)}}()})}function en(n,c){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(Nn(a.car,{env:i,dynamic_scope:t,error:r}));a=a.cdr}var u=o.filter(U).length;if(u){return Promise.all(o).then(c.bind(this))}else{return c.call(this,o)}})}function tn(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 hn(r,i){jn("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 dn(this.value.clone()[n](e,r))}};var vn={"+":"add","-":"sub","*":"mul","/":"div","%":"mod","|":"or","&":"and","~":"neg","<<":"shl",">>":"shr"};Object.keys(vn).forEach(function(e){dn.prototype[vn[e]]=function(n){return this.op(e,n)}});dn.prototype.sqrt=function(){var n;if(dn.isNative(this.value)){n=Math.sqrt(this.value)}else if(dn.isBN(this.value)){n=this.value.sqrt()}return new dn(n)};dn.prototype.pow=function(n){n=this.coerce(n);if(dn.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(dn.isBN(this.value)){n.value=this.value.pow(n.value)}else{n.value=Math.pow(this.value,n.value)}return n};dn.prototype.neg=function(){var n=this.value;if(dn.isNative(n)){n=-n}else if(dn.isBN(n)){n=n.neg()}return new dn(n)};dn.prototype.abs=function(){var n=this.value;if(dn.isNative(this.value)){if(n<0){n=-n}}else if(dn.isBN(n)){n.iabs()}return new dn(n)};dn.prototype.isOdd=function(){if(dn.isNative(this.value)){if(this.isBigNumber()){return this.value%BigInt(2)===BigInt(1)}return this.value%2===1}else if(dn.isBN(this.value)){return this.value.isOdd()}};dn.prototype.isEven=function(){return!this.isOdd()};dn.prototype.cmp=function(n){n=this.coerce(n);if(dn.isNative(this.value)){if(this.value1&&arguments[1]!==g?arguments[1]:{};if(Yn(n)==="object"){e=n}if(!n||Yn(n)==="object"){n="child of "+(this.name||"unknown")}return new mn(e||{},this,n)};mn.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 u;var c=false;if(n instanceof O){if(n.name in this.env){u=this.env[n.name];c=true}}else if(typeof n==="string"){if(typeof this.env[n]!=="undefined"){u=this.env[n];c=true}}if(c){if(dn.isNumber(u)){return dn(u)}if(u instanceof M){return u.markCycles()}if(typeof u==="function"){if(!u.name.match(/^bound /)){if(t){return Q(u,i)}return K(u,i)}}return u}if(this.parent instanceof mn){return this.parent.get(n,{weak:t,context:i,throwError:o})}else{var s;if(n instanceof O){s=n.name}else if(typeof n==="string"){s=n}if(s){var f=Yn(l[s]);if(f==="function"){if(Z(l[s])){return K(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+"'")}};mn.prototype.set=function(n,e){if(dn.isNumber(e)){e=dn(e)}if(n instanceof O){n=n.name}this.env[n]=e};mn.prototype.has=function(n){return typeof this.env[n]!=="undefined"};mn.prototype.ref=function(n){var e=this;while(true){if(!e){break}if(e.has(n)){return e}e=e.parent}};mn.prototype.parents=function(){var n=this;var e=[];while(n){e.unshift(n);n=n.parent}return e};function yn(n){if(U(n)){return n.then(yn)}if(n instanceof M||n instanceof O){n.data=true}return n}function gn(n,e,t){this.value=n;this.count=e;this.max=t}gn.prototype.toString=function(){return"<#unquote["+this.count+"] "+this.value+">"};var bn=function(){var e=0;return function(){var n=arguments.length>0&&arguments[0]!==g?arguments[0]:null;if(n!==null){return new O(l.Symbol("#".concat(n)))}e++;return new O(l.Symbol("#gensym_".concat(e,"#")))}}();var wn=new mn({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 O){i=n.car}else if(n.car instanceof M&&n.car.car instanceof O){i=n.car.car}else{var a=this;if(t){t=this}var o=Nn(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}jn("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}jn("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=Nn(e.cdr.car,{env:this,dynamic_scope:t,error:r});i=Sn(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&&O.is(e.car.car,".")){var u=e.car.cdr.car;var c=e.car.cdr.cdr.car;var s=Nn(u,{env:this,dynamic_scope:t,error:r});var f=Nn(c,{env:this,dynamic_scope:t,error:r});return o(f,i)}if(!(e.car instanceof O)){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 _(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){jn("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){jn("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")}jn("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(bn,"(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){jn("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 u=new M(new O("begin"),r.cdr);var c;if(i){i=o}return function e(){var n=Nn(r.car,{env:o,dynamic_scope:i,error:a});function t(n){if(n&&!G(n)&&!J(n)){c=Nn(u,{env:o,dynamic_scope:i,error:a});if(U(c)){return c.then(function(n){c=n;return e()})}else{return e()}}else{return c}}return _(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){jn("if",e,"boolean");if(e){return Nn(t.cdr.car,{env:a,dynamic_scope:r,error:i})}else{return Nn(t.cdr.cdr.car,{env:a,dynamic_scope:r,error:i})}};var o=Nn(t.car,{env:a,dynamic_scope:r,error:i});return _(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(nn(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(nn(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(en("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=Nn(n,r);return _(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}Nn(new M(new O("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;jn("timer",e.car,"number");var i=this;if(t){t=this}return new Promise(function(n){setTimeout(function(){n(Nn(e.cdr.car,{env:i,dynamic_scope:t,error:r}))},e.car)}).then(yn)}),"(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 O){var r=new M(new O("define"),new M(e.car.car,new M(new M(new O("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=Nn(i,n)}else if(i instanceof O){i=t.get(i)}if(e.car instanceof O){_(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){if(Yn(n)!=="object"||G(n)){throw new Error(kn("set-obj!",En(n),"object"))}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;jn("eval",n,["symbol","pair","array"]);t=t||this;if(n instanceof O){return t.get(n)}if(n instanceof M){return Nn(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(e instanceof O||!J(e)){for(var i=arguments.length,a=new Array(i),o=0;o2&&arguments[2]!==g?arguments[2]:a;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=Dn(n,2),t=e[0],r=e[1];return new M(t,r)})}else{return new M(r,i)}}return n}function p(n,e){if(n instanceof M){if(J(n)&&e===P){return P}n.append(e)}else{n=new M(n,e)}return n}var d=new Set;function v(r,t,i){if(r instanceof M&&!J(r)){var n;if(O.is(r.car.car,"unquote-splicing")){n=Nn(r.car.cdr.car,{env:l,dynamic_scope:s,error:f});return _(n,function(e){if(!(e instanceof M)){if(r.cdr!==P){var n="You can't splice atom inside list";throw new Error(n)}return e}if(d.has(e)){e=e.clone()}else{d.add(e)}var t=v(r.cdr,0,1);if(t===P&&e===P){return g}return _(t,function(n){return p(e,n)})})}if(O.is(r.car,"quasiquote")){var e=v(r.cdr,t,i+1);return new M(r.car,e)}if(O.is(r.car,"unquote")){var a=r.cdr;var o=a;var u=o;t++;while(o instanceof M&&o.car instanceof M&&O.is(o.car.car,"unquote")){u=o;t++;o=o.car.cdr.car}if(t>i){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(u===o){if(r.cdr.cdr!==P){return _(v(r.cdr.cdr),function(n){var e=new gn(r.cdr.car,t,i);return new M(e,n)})}else{return new gn(r.cdr.car,t,i)}}else if(u.cdr.cdr!==P){var c=v(u.cdr.cdr,t,i);return _(c,function(n){u.car.cdr=new M(new gn(o,t,i),u.cdr===P?P:n);return a.car})}else{u.car.cdr=new gn(o,t,i)}return a.car}return h(r,function(n){return v(n,t,i)})}return r}var t=function n(e){return a(e)||e instanceof gn};function r(n){if(n instanceof gn){if(n.max===n.count){var e=Nn(n.value,{env:l,dynamic_scope:s,error:f});return e}else{return _(r(n.value),function(n){return new M(new O("unquote"),new M(n,P))})}}return h(n,r,t)}var i=v(n.car,0,1);return _(i,function(n){n=r(n);return _(n,function(n){return yn(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){jn("clone",n,"pair");return n.clone()},"(clone list)\n\n Function return clone of the list."),append:d(function(n,e){jn("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){jn("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){jn("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(kn("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){jn("nth",n,"number");jn("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){jn("split",n,["regex","string"]);jn("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){jn("replace",n,["regex","string"]);jn("replace",e,["string","function"]);jn("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){jn("match",n,["regex","string"]);jn("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){jn("search",n,["regex","string"]);jn("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 dn){return n.value.toString()}if(typeof n==="undefined"){return"<#undefined>"}if(typeof n==="function"){if(Z(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 new Cn.Formatter(n.toString())["break"]().format()}if(n instanceof O){return n.toString()}if(l.HTMLElement&&n instanceof l.HTMLElement){return"<#HTMLElement(".concat(n.tagName.toLowerCase(),")>")}if(Yn(n)==="object"){var r=n.constructor;var i;if(typeof r.__className==="string"){i=r.__className}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){jn("array->list",n,"array");return M.fromArray(n)},"(array->list array)\n\n Function convert JavaScript array to LIPS list."),"tree->array":d(B("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":d(B("list->array"),"(list->array list)\n\n Function convert LIPS list into JavaScript array."),apply:d(function(n,e){jn("call",n,"function",1);jn("call",e,"pair",2);return n.apply(void 0,$n(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 dn(0)}if(n instanceof M){return dn(n.length())}if("length"in n){return dn(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 u=n.dynamic_scope,c=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:c};if(u){r.dynamic_scope=o}_(Nn(new M(new O("begin"),a.cdr.car.cdr.cdr),r),function(n){i(n)})}};if(u){n.dynamic_scope=o}var e=Nn(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){jn("find",t,["regex","function"]);jn("find",r,"pair");if(G(r)){return P}var n=c("find",t);return _(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){jn("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=c("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 _(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){jn("range",n,"number");if(n instanceof dn){n=n.valueOf()}return M.fromArray(new Array(n).fill(0).map(function(n,e){return dn(e)}))},"(range n)\n\n Function return list of n numbers from 0 to n - 1"),compose:d(an,"(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(rn,"(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(ln,"(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(cn(function(n){return dn(n).isOdd()}),"(odd number)\n Function check if number os odd."),even:d(cn(function(n){return dn(n).isEvent()}),"(even number)\n\n Function check if number is even."),"*":d(fn(function(n,e){return dn(n).mul(e)}),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":d(fn(function(n,e){return dn(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 dn(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 dn(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(dn(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(dn(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 u=this;if(i){i=u}var c;return function e(){function n(n){c=n;if(c){return c}else{return e()}}var t=o.shift();if(typeof t==="undefined"){if(c){return c}else{return false}}else{var r=Nn(t,{env:u,dynamic_scope:i,error:a});return _(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 u=this;if(i){i=u}if(!o.length){return true}var c;return function e(){function n(n){c=n;if(!c){return false}else{return e()}}var t=o.shift();if(typeof t==="undefined"){if(c){return c}else{return false}}else{var r=Nn(t,{env:u,dynamic_scope:i,error:a});return _(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 dn(n).or(e)},"(& a b)\n\n Function calculate or bit operation."),"&":d(function(n,e){return dn(n).and(e)},"(& a b)\n\n Function calculate and bit operation."),"~":d(function(n){return dn(n).neg()},"(~ number)\n\n Function negate the value."),">>":d(function(n,e){return dn(n).shr(e)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":d(function(n,e){return dn(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){wn.set(e,d(function(n){jn(e,n,"number");if(n instanceof dn){return n[e]()}},"(".concat(e," number)\n\n Function calculate ").concat(e," of a number.")))});function _n(n){if(n.length===1){return n[0]}else{var e=[];var t=_n(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 jn(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(kn(n,i,t,r))}}function Fn(n){var e=Yn(n);return["string","function"].includes(e)||n instanceof dn||n instanceof RegExp}function En(n){var e={pair:M,symbol:O,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||wn}else if(r===true){r=i=wn}else{r=r||wn}var o={env:r,dynamic_scope:i,error:a};var u;if(G(e)){return e}if(J(e)){return R()}if(e instanceof O){return r.get(e,{weak:true})}var c=e.car;var s=e.cdr;if(c instanceof M){u=Sn(Nn(c,o));if(U(u)){return u.then(function(n){return Nn(new M(n,e.cdr),o)})}else if(typeof u!=="function"){throw new Error(En(u)+" "+r.get("string")(u)+" is not a function while evaluating "+e.toString())}}if(c instanceof O){u=r.get(c,{weak:true});if(u instanceof $){var f=qn(u,s,o);return _(f,function(n){if(n instanceof M){return n.markCycles()}return n})}else if(typeof u!=="function"){if(u){var l="".concat(En(u)," `").concat(u,"' is not a function");throw new Error(l)}throw new Error("Unknown function `".concat(c.name,"'"))}}else if(typeof c==="function"){u=c}if(typeof u==="function"){var h=An(s,o);return _(h,function(n){var e=i||r;var t=Sn(u.apply(e,n));return _(t,function(n){if(n instanceof M){return yn(n.markCycles())}return n},a)})}else if(e instanceof O){u=r.get(e);if(u==="undefined"){throw new Error("Unbound variable `"+e.name+"'")}return u}else if(e instanceof M){u=c&&c.toString();throw new Error("".concat(En(c)," ").concat(u," is not a function"))}else{return e}}catch(n){a&&a(n,e)}}function Ln(n,e,t){return On.apply(this,arguments)}function On(){On=Jn(Hn.mark(function n(t,r,i){var a,o,u,c;return Hn.wrap(function n(e){while(1){switch(e.prev=e.next){case 0:if(i===true){r=i=r||wn}else if(r===true){r=i=wn}else{r=r||wn}a=s(t);o=[];case 3:u=a.shift();if(u){e.next=9;break}return e.abrupt("return",o);case 9:e.next=11;return Nn(u,{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:c=e.sent;o.push(c);case 13:e.next=3;break;case 15:case"end":return e.stop()}}},n)}));return On.apply(this,arguments)}function In(e){return function(n){if(!n){return false}return(n.token||n).match(e)}}var Pn=In(/[()]/);function Mn(n){var e=typeof n==="string"?w(n):n;var t=e.filter(Pn);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};O.prototype.toDry=function(){return{value:{name:this.name}}};O.unDry=function(n){return new O(n.name)};function Rn(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){Rn(n);e()})}else{return Ln(n.innerHTML).then(e)["catch"](function(n){Rn(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";E.__className="Pattern";j.__className="Formatter";$.__className="Macro";mn.__className="Environment";var Cn={version:"0.15.2",exec:Ln,parse:s,tokenize:w,evaluate:Nn,Environment:mn,global_environment:wn,globalEnvironment:wn,env:wn,balanced_parenthesis:Mn,balancedParenthesis:Mn,Macro:$,quote:yn,Pair:M,Formatter:j,specials:y,nil:P,resolvePromises:Sn,Symbol:O,LNumber:dn};wn.set("lips",Cn);return Cn})})(); \ No newline at end of file +(function(e,t){if(typeof define==="function"&&define.amd){define(["bn.js"],function(n){return e.lips=t(e,n)})}else if((typeof module==="undefined"?"undefined":Yn(module))==="object"&&module.exports){module.exports=t(e,require("bn.js"))}else{e.lips=t(e,e.BN)}})(typeof global!=="undefined"?global:window,function(l,t,g){function n(t,r){var i=false,n=true,a=t.document,o=a.documentElement,e=a.addEventListener,u=e?"addEventListener":"attachEvent",c=e?"removeEventListener":"detachEvent",s=e?"":"on",f=function n(e){if(e.type=="readystatechange"&&a.readyState!="complete")return;(e.type=="load"?t:a)[c](s+e.type,n,false);if(!i&&(i=true))r.call(t,e.type||e)},l=function e(){try{o.doScroll("left")}catch(n){setTimeout(e,50);return}f("poll")};if(a.readyState=="complete")r.call(t,"lazy");else{if(!e&&o.doScroll){try{n=!t.frameElement}catch(n){}if(n)l()}a[u](s+"DOMContentLoaded",f,false);a[u](s+"readystatechange",f,false);t[u](s+"load",f,false)}}if(!l.fetch){l.fetch=function(i,a){a=a||{};return new Promise(function(n,e){var t=new XMLHttpRequest;t.open(a.method||"get",i,true);for(var r in a.headers){t.setRequestHeader(r,a.headers[r])}t.withCredentials=a.credentials=="include";t.onload=function(){n(u())};t.onerror=e;t.send(a.body||null);function u(){var r=[],i=[],a={},o;t.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(n,e,t){r.push(e=e.toLowerCase());i.push([e,t]);o=a[e];a[e]=o?"".concat(o,",").concat(t):t});return{ok:(t.status/100|0)==2,status:t.status,statusText:t.statusText,url:t.responseURL,clone:u,text:function n(){return Promise.resolve(t.responseText)},json:function n(){return Promise.resolve(t.responseText).then(JSON.parse)},blob:function n(){return Promise.resolve(new Blob([t.response]))},headers:{keys:function n(){return r},entries:function n(){return i},get:function n(e){return a[e.toLowerCase()]},has:function n(e){return e.toLowerCase()in a}}}}})}}var r=/^\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimy]*)$/;var i=/^[-+]?[0-9]+([eE][-+]?[0-9]+)?$/;var a=/^([-+]?((\.[0-9]+|[0-9]+\.[0-9]+)([eE][-+]?[0-9]+)?)|[0-9]+\.)$/;function m(n){function e(n){if(n.match(/^['"]/)){if(n==='""'||n==="''"){return""}var e=n[0];var t=new RegExp("((^|[^\\\\])(?:\\\\\\\\)*)"+e,"g");n=n.replace(t,"$1")}return JSON.parse('"'+n.replace(/\n/g,"\\n")+'"')}var t=n.match(r);if(t){return new RegExp(t[1],t[2])}else if(n.match(/['"]/)){return e(n)}else if(n.match(i)){return dn(parseFloat(n))}else if(n.match(a)){return dn(parseFloat(n),true)}else if(n==="nil"){return P}else if(n==="true"){return true}else if(n==="false"){return false}else{return new O(n)}}var f=/("(?:\\[\S\s]|[^"])*"|\/(?! )[^\/\\]*(?:\\[\S\s][^\/\\]*)*\/[gimy]*(?=\s|\(|\)|$)|;.*)/g;var b=/"(?:\\[\S\s]|[^"])*"/g;function e(){var n=Object.keys(y).map(o).join("|");return new RegExp('("(?:\\\\[\\S\\s]|[^"])*"|\\/(?! )[^\\/\\\\]*(?:\\\\[\\S\\s][^\\/\\\\]*)*\\/[gimy]*(?=\\s|\\(|\\)|$)|\\(|\\)|\'|"(?:\\\\[\\S\\s]|[^"])+|\\n|(?:\\\\[\\S\\s]|[^"])*"|;.*|(?:[-+]?(?:(?:\\.[0-9]+|[0-9]+\\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\\.)[0-9]|\\.{2,}|'.concat(n,"|[^(\\s)]+)"),"gim")}function h(n){var e=arguments.length>1&&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 u(n){var i=e();n=n.replace(/\n\r|\r/g,"\n");var a=0;var o=0;var u=[];var c=[];var s=0;n.split(f).filter(Boolean).forEach(function(n){if(n.match(f)){s=0;if(c.length){var e=h(c);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};u.push(r);c.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;u.push(e);c.push(e);if(n==="\n"){++o;c=[];s=0}})});return u}function w(n,e){if(e){return u(n)}else{return u(n).map(function(n){return n.token.trim()}).filter(function(n){return n&&!n.match(/^;/)})}}var y={"'":new O("quote"),"`":new O("quasiquote"),",@":new O("unquote-splicing"),",":new O("unquote")};function s(n){if(typeof n==="string"){n=w(n)}var a=[];var o=[];var u=null;var c=Object.keys(y);var s=c.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 O&&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 O){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(c.indexOf(n)!==-1){d++;u=n;a.push([y[u]]);if(!u){p=[]}p.push(u)}else{if(u){h.push(p);p=[]}if(n==="("){l=true;f++;a.push([]);u=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(u){while(d--){a[a.length-1].push(r);r=a.pop()}h.pop();d=0;u=false}else if(r instanceof O&&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 _(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 c(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__=p(e)}}return n}function p(n){return n.split("\n").map(function(n){return n.trim()}).join("\n")}function x(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 v(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 u(n,e)===e.length;function u(n,e){var t=0;var r={};for(var i=0;i0){continue}}}else if(n[t]instanceof Array){var o=u(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 u=r[Symbol.iterator](),c;!(i=(c=u.next()).done);i=true){var s=c.value;if(n.match(s)){return true}}}catch(n){a=true;o=n}finally{try{if(!i&&u["return"]!=null){u["return"]()}}finally{if(a){throw o}}}}return false};j.prototype._indent=function n(e,t){var r=this._options(t);var i=v(e);var a=x(e);if(a){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 u=0;u"}else if(typeof n==="string"){return JSON.stringify(n).replace(/\\n/g,"\n")}else if(U(n)){return"<#Promise>"}else if(n instanceof O||n instanceof dn||n instanceof RegExp||n instanceof M||n===P){return n.toString()}else if(n instanceof Array){return n.map(C)}else if(Yn(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=C(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([" . ",C(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 dn&&e instanceof dn){return n.cmp(e)===0}else if(typeof n==="number"||typeof e==="number"){return dn(n).cmp(dn(e))}else if(n instanceof O&&e instanceof O){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)}jn("Macro",n,"string",1);jn("Macro",e,"function",2);if(t){this.__doc__=p(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 u=this.fn.call(r,n,o,this.name);return t?yn(u):u};$.prototype.toString=function(){return"#"};var D="define-macro";function Y(a){return function(){var t=Jn(Hn.mark(function n(t,c){var s,f,r,i;return Hn.wrap(function n(e){while(1){switch(e.prev=e.next){case 0:r=function n(){r=Jn(Hn.mark(function n(t){var r,i,a,o,u;return Hn.wrap(function n(e){while(1){switch(e.prev=e.next){case 0:if(!(t instanceof M&&t.car instanceof O)){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,c,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:u=new M(a,o);return e.abrupt("return",u);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=c["env"]=this;i=t;if(!a){e.next=12;break}e.t0=yn;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",yn(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=c[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 O("begin"),a.cdr);return Nn(r,{env:f,dynamic_scope:o,error:u})}else{var i=Nn(e.cdr.car,{env:h?f:s,dynamic_scope:o,error:u});return _(t(i),n)}}()})}function en(n,c){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(Nn(a.car,{env:i,dynamic_scope:t,error:r}));a=a.cdr}var u=o.filter(U).length;if(u){return Promise.all(o).then(c.bind(this))}else{return c.call(this,o)}})}function tn(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 hn(r,i){jn("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 dn(this.value.clone()[n](e,r))}};var vn={"+":"add","-":"sub","*":"mul","/":"div","%":"mod","|":"or","&":"and","~":"neg","<<":"shl",">>":"shr"};Object.keys(vn).forEach(function(e){dn.prototype[vn[e]]=function(n){return this.op(e,n)}});dn.prototype.sqrt=function(){var n;if(dn.isNative(this.value)){n=Math.sqrt(this.value)}else if(dn.isBN(this.value)){n=this.value.sqrt()}return new dn(n)};dn.prototype.pow=function(n){n=this.coerce(n);if(dn.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(dn.isBN(this.value)){n.value=this.value.pow(n.value)}else{n.value=Math.pow(this.value,n.value)}return n};dn.prototype.neg=function(){var n=this.value;if(dn.isNative(n)){n=-n}else if(dn.isBN(n)){n=n.neg()}return new dn(n)};dn.prototype.abs=function(){var n=this.value;if(dn.isNative(this.value)){if(n<0){n=-n}}else if(dn.isBN(n)){n.iabs()}return new dn(n)};dn.prototype.isOdd=function(){if(dn.isNative(this.value)){if(this.isBigNumber()){return this.value%BigInt(2)===BigInt(1)}return this.value%2===1}else if(dn.isBN(this.value)){return this.value.isOdd()}};dn.prototype.isEven=function(){return!this.isOdd()};dn.prototype.cmp=function(n){n=this.coerce(n);if(dn.isNative(this.value)){if(this.value1&&arguments[1]!==g?arguments[1]:{};if(Yn(n)==="object"){e=n}if(!n||Yn(n)==="object"){n="child of "+(this.name||"unknown")}return new mn(e||{},this,n)};mn.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 u;var c=false;if(n instanceof O){if(n.name in this.env){u=this.env[n.name];c=true}}else if(typeof n==="string"){if(typeof this.env[n]!=="undefined"){u=this.env[n];c=true}}if(c){if(dn.isNumber(u)){return dn(u)}if(u instanceof M){return u.markCycles()}if(typeof u==="function"){if(!u.name.match(/^bound /)){if(t){return Q(u,i)}return K(u,i)}}return u}if(this.parent instanceof mn){return this.parent.get(n,{weak:t,context:i,throwError:o})}else{var s;if(n instanceof O){s=n.name}else if(typeof n==="string"){s=n}if(s){var f=Yn(l[s]);if(f==="function"){if(Z(l[s])){return K(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+"'")}};mn.prototype.set=function(n,e){if(dn.isNumber(e)){e=dn(e)}if(n instanceof O){n=n.name}this.env[n]=e};mn.prototype.has=function(n){return typeof this.env[n]!=="undefined"};mn.prototype.ref=function(n){var e=this;while(true){if(!e){break}if(e.has(n)){return e}e=e.parent}};mn.prototype.parents=function(){var n=this;var e=[];while(n){e.unshift(n);n=n.parent}return e};function yn(n){if(U(n)){return n.then(yn)}if(n instanceof M||n instanceof O){n.data=true}return n}function gn(n,e,t){this.value=n;this.count=e;this.max=t}gn.prototype.toString=function(){return"<#unquote["+this.count+"] "+this.value+">"};var bn=function(){var e=0;return function(){var n=arguments.length>0&&arguments[0]!==g?arguments[0]:null;if(n!==null){return new O(l.Symbol("#".concat(n)))}e++;return new O(l.Symbol("#gensym_".concat(e,"#")))}}();var wn=new mn({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 O){i=n.car}else if(n.car instanceof M&&n.car.car instanceof O){i=n.car.car}else{var a=this;if(t){t=this}var o=Nn(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}jn("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}jn("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=Nn(e.cdr.car,{env:this,dynamic_scope:t,error:r});i=Sn(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&&O.is(e.car.car,".")){var u=e.car.cdr.car;var c=e.car.cdr.cdr.car;var s=Nn(u,{env:this,dynamic_scope:t,error:r});var f=Nn(c,{env:this,dynamic_scope:t,error:r});return o(f,i)}if(!(e.car instanceof O)){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 _(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){jn("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){jn("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")}jn("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(bn,"(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){jn("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 u=new M(new O("begin"),r.cdr);var c;if(i){i=o}return function e(){var n=Nn(r.car,{env:o,dynamic_scope:i,error:a});function t(n){if(n&&!G(n)&&!J(n)){c=Nn(u,{env:o,dynamic_scope:i,error:a});if(U(c)){return c.then(function(n){c=n;return e()})}else{return e()}}else{return c}}return _(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){jn("if",e,"boolean");if(e){return Nn(t.cdr.car,{env:a,dynamic_scope:r,error:i})}else{return Nn(t.cdr.cdr.car,{env:a,dynamic_scope:r,error:i})}};var o=Nn(t.car,{env:a,dynamic_scope:r,error:i});return _(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(nn(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(nn(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(en("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=Nn(n,r);return _(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}Nn(new M(new O("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;jn("timer",e.car,"number");var i=this;if(t){t=this}return new Promise(function(n){setTimeout(function(){n(Nn(e.cdr.car,{env:i,dynamic_scope:t,error:r}))},e.car)}).then(yn)}),"(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 O){var r=new M(new O("define"),new M(e.car.car,new M(new M(new O("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=Nn(i,n)}else if(i instanceof O){i=t.get(i)}if(e.car instanceof O){_(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){if(Yn(n)!=="object"||G(n)){throw new Error(kn("set-obj!",En(n),"object"))}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;jn("eval",n,["symbol","pair","array"]);t=t||this;if(n instanceof O){return t.get(n)}if(n instanceof M){return Nn(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(e instanceof O||!J(e)){for(var i=arguments.length,a=new Array(i),o=0;o2&&arguments[2]!==g?arguments[2]:a;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=Dn(n,2),t=e[0],r=e[1];return new M(t,r)})}else{return new M(r,i)}}return n}function p(n,e){if(n instanceof M){if(J(n)&&e===P){return P}n.append(e)}else{n=new M(n,e)}return n}var d=new Set;function v(r,t,i){if(r instanceof M&&!J(r)){var n;if(O.is(r.car.car,"unquote-splicing")){n=Nn(r.car.cdr.car,{env:l,dynamic_scope:s,error:f});return _(n,function(e){if(!(e instanceof M)){if(r.cdr!==P){var n="You can't splice atom inside list";throw new Error(n)}return e}if(d.has(e)){e=e.clone()}else{d.add(e)}var t=v(r.cdr,0,1);if(t===P&&e===P){return g}return _(t,function(n){return p(e,n)})})}if(O.is(r.car,"quasiquote")){var e=v(r.cdr,t,i+1);return new M(r.car,e)}if(O.is(r.car,"unquote")){var a=r.cdr;var o=a;var u=o;t++;while(o instanceof M&&o.car instanceof M&&O.is(o.car.car,"unquote")){u=o;t++;o=o.car.cdr.car}if(t>i){throw new Error("You can't call `unquote` outside "+"of quasiquote")}if(u===o){if(r.cdr.cdr!==P){return _(v(r.cdr.cdr),function(n){var e=new gn(r.cdr.car,t,i);return new M(e,n)})}else{return new gn(r.cdr.car,t,i)}}else if(u.cdr.cdr!==P){var c=v(u.cdr.cdr,t,i);return _(c,function(n){u.car.cdr=new M(new gn(o,t,i),u.cdr===P?P:n);return a.car})}else{u.car.cdr=new gn(o,t,i)}return a.car}return h(r,function(n){return v(n,t,i)})}return r}var t=function n(e){return a(e)||e instanceof gn};function r(n){if(n instanceof gn){if(n.max===n.count){var e=Nn(n.value,{env:l,dynamic_scope:s,error:f});return e}else{return _(r(n.value),function(n){return new M(new O("unquote"),new M(n,P))})}}return h(n,r,t)}var i=v(n.car,0,1);return _(i,function(n){n=r(n);return _(n,function(n){return yn(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){jn("clone",n,"pair");return n.clone()},"(clone list)\n\n Function return clone of the list."),append:d(function(n,e){jn("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){jn("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){jn("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(kn("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){jn("nth",n,"number");jn("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){jn("split",n,["regex","string"]);jn("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){jn("replace",n,["regex","string"]);jn("replace",e,["string","function"]);jn("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){jn("match",n,["regex","string"]);jn("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){jn("search",n,["regex","string"]);jn("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 dn){return n.value.toString()}if(typeof n==="undefined"){return"<#undefined>"}if(typeof n==="function"){if(Z(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 new Cn.Formatter(n.toString())["break"]().format()}if(n instanceof O){return n.toString()}if(l.HTMLElement&&n instanceof l.HTMLElement){return"<#HTMLElement(".concat(n.tagName.toLowerCase(),")>")}if(Yn(n)==="object"){var r=n.constructor;var i;if(typeof r.__className==="string"){i=r.__className}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){jn("array->list",n,"array");return M.fromArray(n)},"(array->list array)\n\n Function convert JavaScript array to LIPS list."),"tree->array":d(B("tree->array",true),"(tree->array list)\n\n Function convert LIPS list structure into JavaScript array."),"list->array":d(B("list->array"),"(list->array list)\n\n Function convert LIPS list into JavaScript array."),apply:d(function(n,e){jn("call",n,"function",1);jn("call",e,"pair",2);return n.apply(void 0,$n(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 dn(0)}if(n instanceof M){return dn(n.length())}if("length"in n){return dn(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 u=n.dynamic_scope,c=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:c};if(u){r.dynamic_scope=o}_(Nn(new M(new O("begin"),a.cdr.car.cdr.cdr),r),function(n){i(n)})}};if(u){n.dynamic_scope=o}var e=Nn(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){jn("find",t,["regex","function"]);jn("find",r,"pair");if(G(r)){return P}var n=c("find",t);return _(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){jn("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=c("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 _(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){jn("range",n,"number");if(n instanceof dn){n=n.valueOf()}return M.fromArray(new Array(n).fill(0).map(function(n,e){return dn(e)}))},"(range n)\n\n Function return list of n numbers from 0 to n - 1"),compose:d(an,"(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(rn,"(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(ln,"(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(cn(function(n){return dn(n).isOdd()}),"(odd number)\n Function check if number os odd."),even:d(cn(function(n){return dn(n).isEvent()}),"(even number)\n\n Function check if number is even."),"*":d(fn(function(n,e){return dn(n).mul(e)}),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":d(fn(function(n,e){return dn(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 dn(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 dn(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(dn(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(dn(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 u=this;if(i){i=u}var c;return function e(){function n(n){c=n;if(c){return c}else{return e()}}var t=o.shift();if(typeof t==="undefined"){if(c){return c}else{return false}}else{var r=Nn(t,{env:u,dynamic_scope:i,error:a});return _(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 u=this;if(i){i=u}if(!o.length){return true}var c;return function e(){function n(n){c=n;if(!c){return false}else{return e()}}var t=o.shift();if(typeof t==="undefined"){if(c){return c}else{return false}}else{var r=Nn(t,{env:u,dynamic_scope:i,error:a});return _(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 dn(n).or(e)},"(& a b)\n\n Function calculate or bit operation."),"&":d(function(n,e){return dn(n).and(e)},"(& a b)\n\n Function calculate and bit operation."),"~":d(function(n){return dn(n).neg()},"(~ number)\n\n Function negate the value."),">>":d(function(n,e){return dn(n).shr(e)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":d(function(n,e){return dn(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){wn.set(e,d(function(n){jn(e,n,"number");if(n instanceof dn){return n[e]()}},"(".concat(e," number)\n\n Function calculate ").concat(e," of a number.")))});function _n(n){if(n.length===1){return n[0]}else{var e=[];var t=_n(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 jn(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(kn(n,i,t,r))}}function Fn(n){var e=Yn(n);return["string","function"].includes(e)||n instanceof dn||n instanceof RegExp}function En(n){var e={pair:M,symbol:O,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||wn}else if(r===true){r=i=wn}else{r=r||wn}var o={env:r,dynamic_scope:i,error:a};var u;if(G(e)){return e}if(J(e)){return R()}if(e instanceof O){return r.get(e,{weak:true})}var c=e.car;var s=e.cdr;if(c instanceof M){u=Sn(Nn(c,o));if(U(u)){return u.then(function(n){return Nn(new M(n,e.cdr),o)})}else if(typeof u!=="function"){throw new Error(En(u)+" "+r.get("string")(u)+" is not a function while evaluating "+e.toString())}}if(c instanceof O){u=r.get(c,{weak:true});if(u instanceof $){var f=qn(u,s,o);return _(f,function(n){if(n instanceof M){return n.markCycles()}return n})}else if(typeof u!=="function"){if(u){var l="".concat(En(u)," `").concat(u,"' is not a function");throw new Error(l)}throw new Error("Unknown function `".concat(c.name,"'"))}}else if(typeof c==="function"){u=c}if(typeof u==="function"){var h=An(s,o);return _(h,function(n){var e=i||r;var t=Sn(u.apply(e,n));return _(t,function(n){if(n instanceof M){return yn(n.markCycles())}return n},a)})}else if(e instanceof O){u=r.get(e);if(u==="undefined"){throw new Error("Unbound variable `"+e.name+"'")}return u}else if(e instanceof M){u=c&&c.toString();throw new Error("".concat(En(c)," ").concat(u," is not a function"))}else{return e}}catch(n){a&&a(n,e)}}function Ln(n,e,t){return On.apply(this,arguments)}function On(){On=Jn(Hn.mark(function n(t,r,i){var a,o,u,c;return Hn.wrap(function n(e){while(1){switch(e.prev=e.next){case 0:if(i===true){r=i=r||wn}else if(r===true){r=i=wn}else{r=r||wn}a=s(t);o=[];case 3:u=a.shift();if(u){e.next=9;break}return e.abrupt("return",o);case 9:e.next=11;return Nn(u,{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:c=e.sent;o.push(c);case 13:e.next=3;break;case 15:case"end":return e.stop()}}},n)}));return On.apply(this,arguments)}function In(e){return function(n){if(!n){return false}return(n.token||n).match(e)}}var Pn=In(/[()]/);function Mn(n){var e=typeof n==="string"?w(n):n;var t=e.filter(Pn);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};O.prototype.toDry=function(){return{value:{name:this.name}}};O.unDry=function(n){return new O(n.name)};function Rn(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){Rn(n);e()})}else{return Ln(n.innerHTML).then(e)["catch"](function(n){Rn(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";E.__className="Pattern";j.__className="Formatter";$.__className="Macro";mn.__className="Environment";var Cn={version:"0.15.3",exec:Ln,parse:s,tokenize:w,evaluate:Nn,Environment:mn,global_environment:wn,globalEnvironment:wn,env:wn,balanced_parenthesis:Mn,balancedParenthesis:Mn,Macro:$,quote:yn,Pair:M,Formatter:j,specials:y,nil:P,resolvePromises:Sn,Symbol:O,LNumber:dn};wn.set("lips",Cn);return Cn})})(); \ No newline at end of file diff --git a/package.json b/package.json index db9e8869..11dd23b0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jcubic/lips", - "version": "0.15.2", + "version": "0.15.3", "description": "Simple Scheme Like Lisp in JavaScript", "main": "src/lips.js", "unpkg": "dist/lips.min.js",