From a3df6de956114df03ab55fb490b0610098170330 Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Sat, 25 May 2019 09:33:39 +0200 Subject: [PATCH] version 0.15.2 --- Makefile | 2 +- README.md | 6 +++--- dist/lips.js | 6 +++--- dist/lips.min.js | 6 +++--- package.json | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index bc441c10..ed82db33 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: publish test coveralls lint -VERSION=0.15.1 +VERSION=0.15.2 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 7937bc83..73554eb2 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ ## LIPS is Pretty Simple -[![npm](https://img.shields.io/badge/npm-DEV-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) -[![travis](https://travis-ci.org/jcubic/jquery.terminal.svg?branch=devel&ea64715ecba42391c9e780432e67b9dc68ec4862)](https://travis-ci.org/jcubic/jquery.terminal) -[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&480eda5fa53ba24b965bdd65895d67cb)](https://coveralls.io/github/jcubic/lips?branch=devel) +[![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) +[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=master&c0db2af4d10e185d40b28d0fbe58d046)](https://coveralls.io/github/jcubic/lips?branch=master) LIPS is very simple Lisp, similar to Scheme written in JavaScript. diff --git a/dist/lips.js b/dist/lips.js index 7af9c136..2284bc5e 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. DEV + * LIPS is Pretty Simple - simple scheme like lisp in JavaScript - v. 0.15.2 * * 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: Thu, 23 May 2019 07:30:30 +0000 + * build: Sat, 25 May 2019 07:32:56 +0000 */ (function () { 'use strict'; @@ -5069,7 +5069,7 @@ Environment.__className = 'Environment'; // ------------------------------------------------------------------------- var lips = { - version: 'DEV', + version: '0.15.2', exec: exec, parse: parse, tokenize: tokenize, diff --git a/dist/lips.min.js b/dist/lips.min.js index 46ad0f60..b797fb22 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. DEV + * LIPS is Pretty Simple - simple scheme like lisp in JavaScript - v. 0.15.2 * * 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: Thu, 23 May 2019 07:30:30 +0000 + * build: Sat, 25 May 2019 07:32:56 +0000 */ (function(){"use strict";function Hn(n){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){Hn=function(n){return typeof n}}else{Hn=function(n){return n&&typeof Symbol==="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n}}return Hn(n)}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 Jn(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)})}}function u(n,e){u=Object.setPrototypeOf||function n(e,t){e.__proto__=t;return e};return u(n,e)}function r(){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 $n(n,e,t){if(r()){$n=Reflect.construct}else{$n=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 $n.apply(null,arguments)}function Dn(n,e){return t(n)||a(n,e)||s()}function Yn(n){return e(n)||i(n)||o()}function e(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=p(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 P("quote"),"`":new P("quasiquote"),",@":new P("unquote-splicing"),",":new P("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 P&&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 P){a[a.length-1].push(n)}else if(a[a.length-1]instanceof R){if(a[a.length-1].cdr instanceof R){a[a.length-1]=new R(a[a.length-1],R.fromArray(n))}else{a[a.length-1].cdr=R.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]=R.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 R){e.append(R.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 P&&s.includes(r.name)){r.literal=true}e=a[a.length-1];if(e instanceof R){var i=e;while(true){if(i.cdr===L){if(r instanceof Array){i.cdr=R.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 R.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(V(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__=v(e)}}return n}function v(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 k(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 j(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 F(n){this._code=n.replace(/\r/g,"")}F.defaults={offset:0,indent:2,specials:[/^define/,"lambda","let","let*"]};F.match=j;F.prototype._options=function n(e){var t=F.defaults;if(typeof e==="undefined"){return Object.assign({},t)}var r=e&&e.specials||[];return Object.assign({},t,e,{specials:t.specials.concat(r)})};F.prototype.indent=function n(e){var t=w(this._code,true);return this._indent(t,e)};F.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};F.prototype._indent=function n(e,t){var r=this._options(t);var i=k(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(F.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(V(n)){return"<#Promise>"}else if(n instanceof P||n instanceof vn||n instanceof RegExp||n instanceof R||n===L){return n.toString()}else if(n instanceof Array){return n.map(T)}else if(Hn(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}}R.prototype.markCycles=function(){H(this);return this};R.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 H(n){var i=[];var e=[];function a(n){if(n instanceof R){if(i.includes(n)){if(!e.includes(n)){e.push(n)}return"#".concat(e.length-1,"#")}}}function o(n){if(n instanceof R){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)}R.prototype.toString=function(){var n=["("];if(this.car!==g){var e;if(this.cycles&&this.cycles.car){e=this.cycles.car}else{e=T(this.car)}if(e){n.push(e)}if(this.cdr instanceof R){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!==L){n=n.concat([" . ",T(this.cdr)])}}n.push(")");return n.join("")};R.prototype.set=function(n,e){this[n]=e;if(e instanceof R){this.markCycles()}};R.prototype.append=function(n){if(n instanceof Array){return this.append(R.fromArray(n))}var e=this;if(e.car===g){if(n instanceof R){this.car=n.car;this.cdr=n.cdr}else{this.car=n}}else if(n!==L){while(true){if(e instanceof R&&e.cdr!==L){e=e.cdr}else{break}}e.cdr=n}return this};function J(n,e){if(n instanceof vn&&e instanceof vn){return n.cmp(e)===0}else if(typeof n==="number"||typeof e==="number"){return vn(n).cmp(vn(e))}else if(n instanceof P&&e instanceof P){return n.name===e.name}else{return n===e}}function $(n){return n instanceof R&&n.isEmptyList()||n===L}function D(n,e,t){if(typeof this!=="undefined"&&this.constructor!==D||typeof this==="undefined"){return new D(n,e)}Fn("Macro",n,"string",1);Fn("Macro",e,"function",2);if(t){this.__doc__=v(t)}this.name=n;this.fn=e}D.defmacro=function(n,e,t){var r=new D(n,e,t);r.defmacro=true;return r};D.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?gn(u):u};D.prototype.toString=function(){return"#"};var Y="define-macro";function U(a){return function(){var t=Jn(h.mark(function n(t,c){var s,f,r,i;return h.wrap(function n(e){while(1){switch(e.prev=e.next){case 0:r=function n(){r=Jn(h.mark(function n(t){var r,i,a,o,u;return h.wrap(function n(e){while(1){switch(e.prev=e.next){case 0:if(!(t instanceof R&&t.car instanceof P)){e.next=13;break}e.prev=1;r=s.get(t.car);if(!(r instanceof D&&r.defmacro)){e.next=9;break}e.next=6;return r.invoke(t.cdr,c,true);case 6:i=e.sent;if(!(i instanceof R)){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 R)){e.next=18;break}e.next=17;return f(a);case 17:a=e.sent;case 18:o=t.cdr;if(!(o instanceof R)){e.next=23;break}e.next=22;return f(o);case 22:o=e.sent;case 23:u=new R(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=gn;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",gn(i.car));case 22:case"end":return e.stop()}}},n,this)}));return function(n,e){return t.apply(this,arguments)}}()}function Q(n){return typeof n==="undefined"||n===L||n===null}function V(n){return n instanceof Promise||n&&typeof n!=="undefined"&&typeof n.then==="function"}function z(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(V(n)){return n.then(t)}else if(typeof n==="undefined"){f.set(e.car,L)}else{f.set(e.car,n)}}if(o){o=h?f:s}if(!e){var r=new R(new P("begin"),a.cdr);return In(r,{env:f,dynamic_scope:o,error:u})}else{var i=In(e.cdr.car,{env:h?f:s,dynamic_scope:o,error:u});return _(t(i),n)}}()})}function tn(n,c){return new D(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 R&&!$(a)){o.push(In(a.car,{env:i,dynamic_scope:t,error:r}));a=a.cdr}var u=o.filter(V).length;if(u){return Promise.all(o).then(c.bind(this))}else{return c.call(this,o)}})}function rn(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 pn(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 vn(this.value.clone()[n](e,r))}};var mn={"+":"add","-":"sub","*":"mul","/":"div","%":"mod","|":"or","&":"and","~":"neg","<<":"shl",">>":"shr"};Object.keys(mn).forEach(function(e){vn.prototype[mn[e]]=function(n){return this.op(e,n)}});vn.prototype.sqrt=function(){var n;if(vn.isNative(this.value)){n=Math.sqrt(this.value)}else if(vn.isBN(this.value)){n=this.value.sqrt()}return new vn(n)};vn.prototype.pow=function(n){n=this.coerce(n);if(vn.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(vn.isBN(this.value)){n.value=this.value.pow(n.value)}else{n.value=Math.pow(this.value,n.value)}return n};vn.prototype.neg=function(){var n=this.value;if(vn.isNative(n)){n=-n}else if(vn.isBN(n)){n=n.neg()}return new vn(n)};vn.prototype.abs=function(){var n=this.value;if(vn.isNative(this.value)){if(n<0){n=-n}}else if(vn.isBN(n)){n.iabs()}return new vn(n)};vn.prototype.isOdd=function(){if(vn.isNative(this.value)){if(this.isBigNumber()){return this.value%BigInt(2)===BigInt(1)}return this.value%2===1}else if(vn.isBN(this.value)){return this.value.isOdd()}};vn.prototype.isEven=function(){return!this.isOdd()};vn.prototype.cmp=function(n){n=this.coerce(n);if(vn.isNative(this.value)){if(this.value1&&arguments[1]!==g?arguments[1]:{};if(Hn(n)==="object"){e=n}if(!n||Hn(n)==="object"){n="child of "+(this.name||"unknown")}return new yn(e||{},this,n)};yn.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 P){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(vn.isNumber(u)){return vn(u)}if(u instanceof R){return u.markCycles()}if(typeof u==="function"){if(!u.name.match(/^bound /)){if(t){return z(u,i)}return W(u,i)}}return u}if(this.parent instanceof yn){return this.parent.get(n,{weak:t,context:i,throwError:o})}else{var s;if(n instanceof P){s=n.name}else if(typeof n==="string"){s=n}if(s){var f=Hn(l[s]);if(f==="function"){if(nn(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+"'")}};yn.prototype.set=function(n,e){if(vn.isNumber(e)){e=vn(e)}if(n instanceof P){n=n.name}this.env[n]=e};yn.prototype.has=function(n){return typeof this.env[n]!=="undefined"};yn.prototype.ref=function(n){var e=this;while(true){if(!e){break}if(e.has(n)){return e}e=e.parent}};yn.prototype.parents=function(){var n=this;var e=[];while(n){e.unshift(n);n=n.parent}return e};function gn(n){if(V(n)){return n.then(gn)}if(n instanceof R||n instanceof P){n.data=true}return n}function bn(n,e,t){this.value=n;this.count=e;this.max=t}bn.prototype.toString=function(){return"<#unquote["+this.count+"] "+this.value+">"};var wn=function(){var e=0;return function(){var n=arguments.length>0&&arguments[0]!==g?arguments[0]:null;if(n!==null){return new P(l.Symbol("#".concat(n)))}e++;return new P(l.Symbol("#gensym_".concat(e,"#")))}}();var _n=new yn({nil:L,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 D("help",function(n,e){var t=e.dynamic_scope,r=e.error;var i;if(n.car instanceof P){i=n.car}else if(n.car instanceof R&&n.car.car instanceof P){i=n.car.car}else{var a=this;if(t){t=this}var o=In(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($(e)){e=L}return new R(n,e)},"(cons left right)\n\n Function return new Pair out of two arguments."),car:d(function(n){if(n===L){return L}Fn("car",n,"pair");if($(n)){return L}return n.car},"(car pair)\n\n Function returns car (head) of the list/pair."),cdr:d(function(n){if(n===L){return L}Fn("cdr",n,"pair");if($(n)){return L}return n.cdr},"(cdr pair)\n\n Function returns cdr (tail) of the list/pair."),"set!":d(new D("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=In(e.cdr.car,{env:this,dynamic_scope:t,error:r});i=En(i);var a;function o(e,t){if(V(e)){return e.then(function(n){return o(n,t)})}if(V(t)){return t.then(function(n){return o(e,n)})}s[e]=t;return t}if(e.car instanceof R&&P.is(e.car.car,".")){var u=e.car.cdr.car;var c=e.car.cdr.cdr.car;var s=In(u,{env:this,dynamic_scope:t,error:r});var f=In(c,{env:this,dynamic_scope:t,error:r});return o(f,i)}if(!(e.car instanceof P)){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){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"||$(n)},"(empty? object)\n\n Function return true if value is undfined empty list."),assoc:d(function(n,e){if(n instanceof R&&!(e instanceof R)){throw new Error("First argument to assoc ned to be a key")}Fn("assoc",e,"pair");var t=e;while(true){if(!(t instanceof R)||this.get("empty?")(t)){break}var r=t.car.car;if(J(r,n)){return t.car}else if(!t.haveCycles("cdr")){t=t.cdr}}return L},"(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{On(e.toString(),i).then(function(){t()})}})})}return l.fetch(n).then(function(n){return n.text()}).then(function(n){return On(n,i)}).then(function(){})},"(load filename)\n\n Function fetch the file and evaluate its content as LIPS code."),while:d(new D("while",function(r,n){var i=n.dynamic_scope,a=n.error;var o=this;var u=new R(new P("begin"),r.cdr);var c;if(i){i=o}return function e(){var n=In(r.car,{env:o,dynamic_scope:i,error:a});function t(n){if(n&&!Q(n)&&!$(n)){c=In(u,{env:o,dynamic_scope:i,error:a});if(V(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 D("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 In(t.cdr.car,{env:a,dynamic_scope:r,error:i})}else{return In(t.cdr.cdr.car,{env:a,dynamic_scope:r,error:i})}};var o=In(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(en(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(en(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(tn("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 D("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=In(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 D("ignore",function(n,e){var t=e.dynamic_scope,r=e.error;var i={env:this,error:r};if(t){i.dynamic_scope=this}In(new R(new P("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 D("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(In(e.cdr.car,{env:i,dynamic_scope:t,error:r}))},e.car)}).then(gn)}),"(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(D.defmacro("define",function(e,n){var t=this;if(e.car instanceof R&&e.car.car instanceof P){var r=new R(new P("define"),new R(e.car.car,new R(new R(new P("lambda"),new R(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 R){i=In(i,n)}else if(i instanceof P){i=t.get(i)}if(e.car instanceof 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){if(Hn(n)!=="object"||Q(n)){throw new Error(jn("set-obj!",An(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;Fn("eval",n,["symbol","pair","array"]);t=t||this;if(n instanceof P){return t.get(n)}if(n instanceof R){return In(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 D("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 R&&typeof s.cdr.car==="string"&&s.cdr.cdr!==L){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 P||!$(e)){for(var i=arguments.length,a=new Array(i),o=0;o2&&arguments[2]!==g?arguments[2]:a;if(n instanceof R&&!$(n)){var r=n.car;var i=n.cdr;if(t(r)){r=e(r)}if(t(i)){i=e(i)}if(V(r)||V(i)){return Promise.all([r,i]).then(function(n){var e=Dn(n,2),t=e[0],r=e[1];return new R(t,r)})}else{return new R(r,i)}}return n}function p(n,e){if(n instanceof R){if($(n)&&e===L){return L}n.append(e)}else{n=new R(n,e)}return n}var d=new Set;function v(r,t,i){if(r instanceof R&&!$(r)){var n;if(P.is(r.car.car,"unquote-splicing")){n=In(r.car.cdr.car,{env:l,dynamic_scope:s,error:f});return _(n,function(e){if(!(e instanceof R)){if(r.cdr!==L){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===L&&e===L){return g}return _(t,function(n){return p(e,n)})})}if(P.is(r.car,"quasiquote")){var e=v(r.cdr,t,i+1);return new R(r.car,e)}if(P.is(r.car,"unquote")){var a=r.cdr;var o=a;var u=o;t++;while(o instanceof R&&o.car instanceof R&&P.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!==L){return _(v(r.cdr.cdr),function(n){var e=new bn(r.cdr.car,t,i);return new R(e,n)})}else{return new bn(r.cdr.car,t,i)}}else if(u.cdr.cdr!==L){var c=v(u.cdr.cdr,t,i);return _(c,function(n){u.car.cdr=new R(new bn(o,t,i),u.cdr===L?L:n);return a.car})}else{u.car.cdr=new bn(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 bn};function r(n){if(n instanceof bn){if(n.max===n.count){var e=In(n.value,{env:l,dynamic_scope:s,error:f});return e}else{return _(r(n.value),function(n){return new R(new P("unquote"),new R(n,L))})}}return h(n,r,t)}var i=v(n.car,0,1);return _(i,function(n){n=r(n);return _(n,function(n){return gn(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(Q(e)||$(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 R){var e=this.get("list->array")(n).reverse();return this.get("array->list")(e)}else if(!(n instanceof Array)){throw new Error(jn("reverse",An(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 R){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):L},"(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 vn){return n.value.toString()}if(typeof n==="undefined"){return"<#undefined>"}if(typeof n==="function"){if(nn(n)){return"<#function(native)>"}return"<#function>"}if(n instanceof RegExp){return n.toString()}if(n===L){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 R){return new Tn.Formatter(n.toString())["break"]().format()}if(n instanceof P){return n.toString()}if(l.HTMLElement&&n instanceof l.HTMLElement){return"<#HTMLElement(".concat(n.tagName.toLowerCase(),")>")}if(Hn(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=R.fromArray(e)}else{t=L}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 R.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,Yn(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 vn(0)}if(n instanceof R){return vn(n.length())}if("length"in n){return vn(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 D("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}_(In(new R(new P("begin"),a.cdr.car.cdr.cdr),r),function(n){i(n)})}};if(u){n.dynamic_scope=o}var e=In(a.car,n);if(V(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(Q(r)){return L}var n=c("find",t);return _(n(r.car),function(n){if(n&&n!==L){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=c("filter",n);return function e(t){function n(n){if(n&&n!==L){a.push(r)}return e(++t)}if(t===i.length){return R.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){Fn("range",n,"number");if(n instanceof vn){n=n.valueOf()}return R.fromArray(new Array(n).fill(0).map(function(n,e){return vn(e)}))},"(range n)\n\n Function return list of n numbers from 0 to n - 1"),compose:d(on,"(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(an,"(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(hn,"(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(sn(function(n){return vn(n).isOdd()}),"(odd number)\n Function check if number os odd."),even:d(sn(function(n){return vn(n).isEvent()}),"(even number)\n\n Function check if number is even."),"*":d(ln(function(n,e){return vn(n).mul(e)}),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":d(ln(function(n,e){return vn(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 vn(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 vn(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(vn(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(vn(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(J,"(eq? a b)\n\n Function compare two values if they are identical."),or:d(new D("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=In(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 D("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=In(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 vn(n).or(e)},"(& a b)\n\n Function calculate or bit operation."),"&":d(function(n,e){return vn(n).and(e)},"(& a b)\n\n Function calculate and bit operation."),"~":d(function(n){return vn(n).neg()},"(~ number)\n\n Function negate the value."),">>":d(function(n,e){return vn(n).shr(e)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":d(function(n,e){return vn(n).shl(e)},"(<< a b)\n\n Function left shit the value a by value b."),not:d(function(n){if($(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 vn){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=An(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=Hn(n);return["string","function"].includes(e)||n instanceof vn||n instanceof RegExp}function An(n){var e={pair:R,symbol:P,macro:D,array:Array,native_symbol:l.Symbol};if(n===L){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 u;if(Q(e)){return e}if($(e)){return B()}if(e instanceof P){return r.get(e,{weak:true})}var c=e.car;var s=e.cdr;if(c instanceof R){u=En(In(c,o));if(V(u)){return u.then(function(n){return In(new R(n,e.cdr),o)})}else if(typeof u!=="function"){throw new Error(An(u)+" "+r.get("string")(u)+" is not a function while evaluating "+e.toString())}}if(c instanceof P){u=r.get(c,{weak:true});if(u instanceof D){var f=Nn(u,s,o);return _(f,function(n){if(n instanceof R){return n.markCycles()}return n})}else if(typeof u!=="function"){if(u){var l="".concat(An(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=qn(s,o);return _(h,function(n){var e=i||r;var t=En(u.apply(e,n));return _(t,function(n){if(n instanceof R){return gn(n.markCycles())}return n},a)})}else if(e instanceof P){u=r.get(e);if(u==="undefined"){throw new Error("Unbound variable `"+e.name+"'")}return u}else if(e instanceof R){u=c&&c.toString();throw new Error("".concat(An(c)," ").concat(u," is not a function"))}else{return e}}catch(n){a&&a(n,e)}}function On(n,e,t){return Pn.apply(this,arguments)}function Pn(){Pn=Jn(h.mark(function n(t,r,i){var a,o,u,c;return h.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:u=a.shift();if(u){e.next=9;break}return e.abrupt("return",o);case 9:e.next=11;return In(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 Pn.apply(this,arguments)}function Mn(e){return function(n){if(!n){return false}return(n.token||n).match(e)}}var Ln=Mn(/[()]/);function Rn(n){var e=typeof n==="string"?w(n):n;var t=e.filter(Ln);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}R.unDry=function(n){return new R(n.car,n.cdr)};R.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};M.prototype.toDry=function(){return{value:null}};M.unDry=function(){return L};P.prototype.toDry=function(){return{value:{name:this.name}}};P.unDry=function(n){return new P(n.name)};function Bn(n){console.error(n.message||n);if(n.code){console.error(n.code.map(function(n,e){return"[".concat(e+1,"]: ").concat(n)}))}}function Cn(){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(On).then(e)["catch"](function(n){Bn(n);e()})}else{return On(n.innerHTML).then(e)["catch"](function(n){Bn(n);e()})}}else if(t&&t.match(/lips|lisp/)){console.warn("Expecting "+i+" found "+t)}return e()}}()}}if(typeof window!=="undefined"){n(window,Cn)}S.__className="Ahead";A.__className="Pattern";F.__className="Formatter";D.__className="Macro";yn.__className="Environment";var Tn={version:"DEV",exec:On,parse:s,tokenize:w,evaluate:In,Environment:yn,global_environment:_n,globalEnvironment:_n,env:_n,balanced_parenthesis:Rn,balancedParenthesis:Rn,Macro:D,quote:gn,Pair:R,Formatter:F,specials:y,nil:L,resolvePromises:En,Symbol:P,LNumber:vn};_n.set("lips",Tn);return Tn})})(); \ 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":Hn(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){if(typeof require==="undefined"){l.require=function(){}}var h=require("@babel/runtime/regenerator");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 vn(parseFloat(n))}else if(n.match(a)){return vn(parseFloat(n),true)}else if(n==="nil"){return L}else if(n==="true"){return true}else if(n==="false"){return false}else{return new P(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 p(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=p(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 P("quote"),"`":new P("quasiquote"),",@":new P("unquote-splicing"),",":new P("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 P&&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 P){a[a.length-1].push(n)}else if(a[a.length-1]instanceof R){if(a[a.length-1].cdr instanceof R){a[a.length-1]=new R(a[a.length-1],R.fromArray(n))}else{a[a.length-1].cdr=R.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]=R.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 R){e.append(R.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 P&&s.includes(r.name)){r.literal=true}e=a[a.length-1];if(e instanceof R){var i=e;while(true){if(i.cdr===L){if(r instanceof Array){i.cdr=R.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 R.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(z(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__=v(e)}}return n}function v(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 k(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 j(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 F(n){this._code=n.replace(/\r/g,"")}F.defaults={offset:0,indent:2,specials:[/^define/,"lambda","let","let*"]};F.match=j;F.prototype._options=function n(e){var t=F.defaults;if(typeof e==="undefined"){return Object.assign({},t)}var r=e&&e.specials||[];return Object.assign({},t,e,{specials:t.specials.concat(r)})};F.prototype.indent=function n(e){var t=w(this._code,true);return this._indent(t,e)};F.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};F.prototype._indent=function n(e,t){var r=this._options(t);var i=k(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(F.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(z(n)){return"<#Promise>"}else if(n instanceof P||n instanceof vn||n instanceof RegExp||n instanceof R||n===L){return n.toString()}else if(n instanceof Array){return n.map(T)}else if(Hn(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}}R.prototype.markCycles=function(){H(this);return this};R.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 H(n){var i=[];var e=[];function a(n){if(n instanceof R){if(i.includes(n)){if(!e.includes(n)){e.push(n)}return"#".concat(e.length-1,"#")}}}function o(n){if(n instanceof R){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)}R.prototype.toString=function(){var n=["("];if(this.car!==g){var e;if(this.cycles&&this.cycles.car){e=this.cycles.car}else{e=T(this.car)}if(e){n.push(e)}if(this.cdr instanceof R){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!==L){n=n.concat([" . ",T(this.cdr)])}}n.push(")");return n.join("")};R.prototype.set=function(n,e){this[n]=e;if(e instanceof R){this.markCycles()}};R.prototype.append=function(n){if(n instanceof Array){return this.append(R.fromArray(n))}var e=this;if(e.car===g){if(n instanceof R){this.car=n.car;this.cdr=n.cdr}else{this.car=n}}else if(n!==L){while(true){if(e instanceof R&&e.cdr!==L){e=e.cdr}else{break}}e.cdr=n}return this};function J(n,e){if(n instanceof vn&&e instanceof vn){return n.cmp(e)===0}else if(typeof n==="number"||typeof e==="number"){return vn(n).cmp(vn(e))}else if(n instanceof P&&e instanceof P){return n.name===e.name}else{return n===e}}function $(n){return n instanceof R&&n.isEmptyList()||n===L}function D(n,e,t){if(typeof this!=="undefined"&&this.constructor!==D||typeof this==="undefined"){return new D(n,e)}Fn("Macro",n,"string",1);Fn("Macro",e,"function",2);if(t){this.__doc__=v(t)}this.name=n;this.fn=e}D.defmacro=function(n,e,t){var r=new D(n,e,t);r.defmacro=true;return r};D.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?gn(u):u};D.prototype.toString=function(){return"#"};var Y="define-macro";function U(a){return function(){var t=Jn(h.mark(function n(t,c){var s,f,r,i;return h.wrap(function n(e){while(1){switch(e.prev=e.next){case 0:r=function n(){r=Jn(h.mark(function n(t){var r,i,a,o,u;return h.wrap(function n(e){while(1){switch(e.prev=e.next){case 0:if(!(t instanceof R&&t.car instanceof P)){e.next=13;break}e.prev=1;r=s.get(t.car);if(!(r instanceof D&&r.defmacro)){e.next=9;break}e.next=6;return r.invoke(t.cdr,c,true);case 6:i=e.sent;if(!(i instanceof R)){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 R)){e.next=18;break}e.next=17;return f(a);case 17:a=e.sent;case 18:o=t.cdr;if(!(o instanceof R)){e.next=23;break}e.next=22;return f(o);case 22:o=e.sent;case 23:u=new R(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=gn;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",gn(i.car));case 22:case"end":return e.stop()}}},n,this)}));return function(n,e){return t.apply(this,arguments)}}()}function Q(n){return typeof n==="undefined"||n===L||n===null}function z(n){return n instanceof Promise||n&&typeof n!=="undefined"&&typeof n.then==="function"}function V(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(z(n)){return n.then(t)}else if(typeof n==="undefined"){f.set(e.car,L)}else{f.set(e.car,n)}}if(o){o=h?f:s}if(!e){var r=new R(new P("begin"),a.cdr);return In(r,{env:f,dynamic_scope:o,error:u})}else{var i=In(e.cdr.car,{env:h?f:s,dynamic_scope:o,error:u});return _(t(i),n)}}()})}function tn(n,c){return new D(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 R&&!$(a)){o.push(In(a.car,{env:i,dynamic_scope:t,error:r}));a=a.cdr}var u=o.filter(z).length;if(u){return Promise.all(o).then(c.bind(this))}else{return c.call(this,o)}})}function rn(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 pn(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 vn(this.value.clone()[n](e,r))}};var mn={"+":"add","-":"sub","*":"mul","/":"div","%":"mod","|":"or","&":"and","~":"neg","<<":"shl",">>":"shr"};Object.keys(mn).forEach(function(e){vn.prototype[mn[e]]=function(n){return this.op(e,n)}});vn.prototype.sqrt=function(){var n;if(vn.isNative(this.value)){n=Math.sqrt(this.value)}else if(vn.isBN(this.value)){n=this.value.sqrt()}return new vn(n)};vn.prototype.pow=function(n){n=this.coerce(n);if(vn.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(vn.isBN(this.value)){n.value=this.value.pow(n.value)}else{n.value=Math.pow(this.value,n.value)}return n};vn.prototype.neg=function(){var n=this.value;if(vn.isNative(n)){n=-n}else if(vn.isBN(n)){n=n.neg()}return new vn(n)};vn.prototype.abs=function(){var n=this.value;if(vn.isNative(this.value)){if(n<0){n=-n}}else if(vn.isBN(n)){n.iabs()}return new vn(n)};vn.prototype.isOdd=function(){if(vn.isNative(this.value)){if(this.isBigNumber()){return this.value%BigInt(2)===BigInt(1)}return this.value%2===1}else if(vn.isBN(this.value)){return this.value.isOdd()}};vn.prototype.isEven=function(){return!this.isOdd()};vn.prototype.cmp=function(n){n=this.coerce(n);if(vn.isNative(this.value)){if(this.value1&&arguments[1]!==g?arguments[1]:{};if(Hn(n)==="object"){e=n}if(!n||Hn(n)==="object"){n="child of "+(this.name||"unknown")}return new yn(e||{},this,n)};yn.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 P){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(vn.isNumber(u)){return vn(u)}if(u instanceof R){return u.markCycles()}if(typeof u==="function"){if(!u.name.match(/^bound /)){if(t){return V(u,i)}return W(u,i)}}return u}if(this.parent instanceof yn){return this.parent.get(n,{weak:t,context:i,throwError:o})}else{var s;if(n instanceof P){s=n.name}else if(typeof n==="string"){s=n}if(s){var f=Hn(l[s]);if(f==="function"){if(nn(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+"'")}};yn.prototype.set=function(n,e){if(vn.isNumber(e)){e=vn(e)}if(n instanceof P){n=n.name}this.env[n]=e};yn.prototype.has=function(n){return typeof this.env[n]!=="undefined"};yn.prototype.ref=function(n){var e=this;while(true){if(!e){break}if(e.has(n)){return e}e=e.parent}};yn.prototype.parents=function(){var n=this;var e=[];while(n){e.unshift(n);n=n.parent}return e};function gn(n){if(z(n)){return n.then(gn)}if(n instanceof R||n instanceof P){n.data=true}return n}function bn(n,e,t){this.value=n;this.count=e;this.max=t}bn.prototype.toString=function(){return"<#unquote["+this.count+"] "+this.value+">"};var wn=function(){var e=0;return function(){var n=arguments.length>0&&arguments[0]!==g?arguments[0]:null;if(n!==null){return new P(l.Symbol("#".concat(n)))}e++;return new P(l.Symbol("#gensym_".concat(e,"#")))}}();var _n=new yn({nil:L,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 D("help",function(n,e){var t=e.dynamic_scope,r=e.error;var i;if(n.car instanceof P){i=n.car}else if(n.car instanceof R&&n.car.car instanceof P){i=n.car.car}else{var a=this;if(t){t=this}var o=In(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($(e)){e=L}return new R(n,e)},"(cons left right)\n\n Function return new Pair out of two arguments."),car:d(function(n){if(n===L){return L}Fn("car",n,"pair");if($(n)){return L}return n.car},"(car pair)\n\n Function returns car (head) of the list/pair."),cdr:d(function(n){if(n===L){return L}Fn("cdr",n,"pair");if($(n)){return L}return n.cdr},"(cdr pair)\n\n Function returns cdr (tail) of the list/pair."),"set!":d(new D("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=In(e.cdr.car,{env:this,dynamic_scope:t,error:r});i=En(i);var a;function o(e,t){if(z(e)){return e.then(function(n){return o(n,t)})}if(z(t)){return t.then(function(n){return o(e,n)})}s[e]=t;return t}if(e.car instanceof R&&P.is(e.car.car,".")){var u=e.car.cdr.car;var c=e.car.cdr.cdr.car;var s=In(u,{env:this,dynamic_scope:t,error:r});var f=In(c,{env:this,dynamic_scope:t,error:r});return o(f,i)}if(!(e.car instanceof P)){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){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"||$(n)},"(empty? object)\n\n Function return true if value is undfined empty list."),assoc:d(function(n,e){if(n instanceof R&&!(e instanceof R)){throw new Error("First argument to assoc ned to be a key")}Fn("assoc",e,"pair");var t=e;while(true){if(!(t instanceof R)||this.get("empty?")(t)){break}var r=t.car.car;if(J(r,n)){return t.car}else if(!t.haveCycles("cdr")){t=t.cdr}}return L},"(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{On(e.toString(),i).then(function(){t()})}})})}return l.fetch(n).then(function(n){return n.text()}).then(function(n){return On(n,i)}).then(function(){})},"(load filename)\n\n Function fetch the file and evaluate its content as LIPS code."),while:d(new D("while",function(r,n){var i=n.dynamic_scope,a=n.error;var o=this;var u=new R(new P("begin"),r.cdr);var c;if(i){i=o}return function e(){var n=In(r.car,{env:o,dynamic_scope:i,error:a});function t(n){if(n&&!Q(n)&&!$(n)){c=In(u,{env:o,dynamic_scope:i,error:a});if(z(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 D("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 In(t.cdr.car,{env:a,dynamic_scope:r,error:i})}else{return In(t.cdr.cdr.car,{env:a,dynamic_scope:r,error:i})}};var o=In(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(en(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(en(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(tn("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 D("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=In(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 D("ignore",function(n,e){var t=e.dynamic_scope,r=e.error;var i={env:this,error:r};if(t){i.dynamic_scope=this}In(new R(new P("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 D("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(In(e.cdr.car,{env:i,dynamic_scope:t,error:r}))},e.car)}).then(gn)}),"(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(D.defmacro("define",function(e,n){var t=this;if(e.car instanceof R&&e.car.car instanceof P){var r=new R(new P("define"),new R(e.car.car,new R(new R(new P("lambda"),new R(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 R){i=In(i,n)}else if(i instanceof P){i=t.get(i)}if(e.car instanceof 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){if(Hn(n)!=="object"||Q(n)){throw new Error(jn("set-obj!",An(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;Fn("eval",n,["symbol","pair","array"]);t=t||this;if(n instanceof P){return t.get(n)}if(n instanceof R){return In(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 D("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 R&&typeof s.cdr.car==="string"&&s.cdr.cdr!==L){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 P||!$(e)){for(var i=arguments.length,a=new Array(i),o=0;o2&&arguments[2]!==g?arguments[2]:a;if(n instanceof R&&!$(n)){var r=n.car;var i=n.cdr;if(t(r)){r=e(r)}if(t(i)){i=e(i)}if(z(r)||z(i)){return Promise.all([r,i]).then(function(n){var e=Dn(n,2),t=e[0],r=e[1];return new R(t,r)})}else{return new R(r,i)}}return n}function p(n,e){if(n instanceof R){if($(n)&&e===L){return L}n.append(e)}else{n=new R(n,e)}return n}var d=new Set;function v(r,t,i){if(r instanceof R&&!$(r)){var n;if(P.is(r.car.car,"unquote-splicing")){n=In(r.car.cdr.car,{env:l,dynamic_scope:s,error:f});return _(n,function(e){if(!(e instanceof R)){if(r.cdr!==L){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===L&&e===L){return g}return _(t,function(n){return p(e,n)})})}if(P.is(r.car,"quasiquote")){var e=v(r.cdr,t,i+1);return new R(r.car,e)}if(P.is(r.car,"unquote")){var a=r.cdr;var o=a;var u=o;t++;while(o instanceof R&&o.car instanceof R&&P.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!==L){return _(v(r.cdr.cdr),function(n){var e=new bn(r.cdr.car,t,i);return new R(e,n)})}else{return new bn(r.cdr.car,t,i)}}else if(u.cdr.cdr!==L){var c=v(u.cdr.cdr,t,i);return _(c,function(n){u.car.cdr=new R(new bn(o,t,i),u.cdr===L?L:n);return a.car})}else{u.car.cdr=new bn(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 bn};function r(n){if(n instanceof bn){if(n.max===n.count){var e=In(n.value,{env:l,dynamic_scope:s,error:f});return e}else{return _(r(n.value),function(n){return new R(new P("unquote"),new R(n,L))})}}return h(n,r,t)}var i=v(n.car,0,1);return _(i,function(n){n=r(n);return _(n,function(n){return gn(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(Q(e)||$(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 R){var e=this.get("list->array")(n).reverse();return this.get("array->list")(e)}else if(!(n instanceof Array)){throw new Error(jn("reverse",An(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 R){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):L},"(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 vn){return n.value.toString()}if(typeof n==="undefined"){return"<#undefined>"}if(typeof n==="function"){if(nn(n)){return"<#function(native)>"}return"<#function>"}if(n instanceof RegExp){return n.toString()}if(n===L){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 R){return new Tn.Formatter(n.toString())["break"]().format()}if(n instanceof P){return n.toString()}if(l.HTMLElement&&n instanceof l.HTMLElement){return"<#HTMLElement(".concat(n.tagName.toLowerCase(),")>")}if(Hn(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=R.fromArray(e)}else{t=L}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 R.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,Yn(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 vn(0)}if(n instanceof R){return vn(n.length())}if("length"in n){return vn(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 D("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}_(In(new R(new P("begin"),a.cdr.car.cdr.cdr),r),function(n){i(n)})}};if(u){n.dynamic_scope=o}var e=In(a.car,n);if(z(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(Q(r)){return L}var n=c("find",t);return _(n(r.car),function(n){if(n&&n!==L){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=c("filter",n);return function e(t){function n(n){if(n&&n!==L){a.push(r)}return e(++t)}if(t===i.length){return R.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){Fn("range",n,"number");if(n instanceof vn){n=n.valueOf()}return R.fromArray(new Array(n).fill(0).map(function(n,e){return vn(e)}))},"(range n)\n\n Function return list of n numbers from 0 to n - 1"),compose:d(on,"(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(an,"(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(hn,"(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(sn(function(n){return vn(n).isOdd()}),"(odd number)\n Function check if number os odd."),even:d(sn(function(n){return vn(n).isEvent()}),"(even number)\n\n Function check if number is even."),"*":d(ln(function(n,e){return vn(n).mul(e)}),"(* . numbers)\n\n Multiplicate all numbers passed as arguments. If single value is passed\n it will return that value."),"+":d(ln(function(n,e){return vn(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 vn(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 vn(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(vn(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(vn(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(J,"(eq? a b)\n\n Function compare two values if they are identical."),or:d(new D("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=In(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 D("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=In(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 vn(n).or(e)},"(& a b)\n\n Function calculate or bit operation."),"&":d(function(n,e){return vn(n).and(e)},"(& a b)\n\n Function calculate and bit operation."),"~":d(function(n){return vn(n).neg()},"(~ number)\n\n Function negate the value."),">>":d(function(n,e){return vn(n).shr(e)},"(>> a b)\n\n Function right shit the value a by value b."),"<<":d(function(n,e){return vn(n).shl(e)},"(<< a b)\n\n Function left shit the value a by value b."),not:d(function(n){if($(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 vn){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=An(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=Hn(n);return["string","function"].includes(e)||n instanceof vn||n instanceof RegExp}function An(n){var e={pair:R,symbol:P,macro:D,array:Array,native_symbol:l.Symbol};if(n===L){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 u;if(Q(e)){return e}if($(e)){return B()}if(e instanceof P){return r.get(e,{weak:true})}var c=e.car;var s=e.cdr;if(c instanceof R){u=En(In(c,o));if(z(u)){return u.then(function(n){return In(new R(n,e.cdr),o)})}else if(typeof u!=="function"){throw new Error(An(u)+" "+r.get("string")(u)+" is not a function while evaluating "+e.toString())}}if(c instanceof P){u=r.get(c,{weak:true});if(u instanceof D){var f=Nn(u,s,o);return _(f,function(n){if(n instanceof R){return n.markCycles()}return n})}else if(typeof u!=="function"){if(u){var l="".concat(An(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=qn(s,o);return _(h,function(n){var e=i||r;var t=En(u.apply(e,n));return _(t,function(n){if(n instanceof R){return gn(n.markCycles())}return n},a)})}else if(e instanceof P){u=r.get(e);if(u==="undefined"){throw new Error("Unbound variable `"+e.name+"'")}return u}else if(e instanceof R){u=c&&c.toString();throw new Error("".concat(An(c)," ").concat(u," is not a function"))}else{return e}}catch(n){a&&a(n,e)}}function On(n,e,t){return Pn.apply(this,arguments)}function Pn(){Pn=Jn(h.mark(function n(t,r,i){var a,o,u,c;return h.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:u=a.shift();if(u){e.next=9;break}return e.abrupt("return",o);case 9:e.next=11;return In(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 Pn.apply(this,arguments)}function Mn(e){return function(n){if(!n){return false}return(n.token||n).match(e)}}var Ln=Mn(/[()]/);function Rn(n){var e=typeof n==="string"?w(n):n;var t=e.filter(Ln);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}R.unDry=function(n){return new R(n.car,n.cdr)};R.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};M.prototype.toDry=function(){return{value:null}};M.unDry=function(){return L};P.prototype.toDry=function(){return{value:{name:this.name}}};P.unDry=function(n){return new P(n.name)};function Bn(n){console.error(n.message||n);if(n.code){console.error(n.code.map(function(n,e){return"[".concat(e+1,"]: ").concat(n)}))}}function Cn(){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(On).then(e)["catch"](function(n){Bn(n);e()})}else{return On(n.innerHTML).then(e)["catch"](function(n){Bn(n);e()})}}else if(t&&t.match(/lips|lisp/)){console.warn("Expecting "+i+" found "+t)}return e()}}()}}if(typeof window!=="undefined"){n(window,Cn)}S.__className="Ahead";A.__className="Pattern";F.__className="Formatter";D.__className="Macro";yn.__className="Environment";var Tn={version:"0.15.2",exec:On,parse:s,tokenize:w,evaluate:In,Environment:yn,global_environment:_n,globalEnvironment:_n,env:_n,balanced_parenthesis:Rn,balancedParenthesis:Rn,Macro:D,quote:gn,Pair:R,Formatter:F,specials:y,nil:L,resolvePromises:En,Symbol:P,LNumber:vn};_n.set("lips",Tn);return Tn})})(); \ No newline at end of file diff --git a/package.json b/package.json index 0ce03704..db9e8869 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jcubic/lips", - "version": "0.15.1", + "version": "0.15.2", "description": "Simple Scheme Like Lisp in JavaScript", "main": "src/lips.js", "unpkg": "dist/lips.min.js",