diff --git a/CHANGELOG.md b/CHANGELOG.md index 655c80de..22323067 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.8.1 +### Bugfix +* use exception.code for code that triggered exception + ## 0.8.0 ### Features * new nth and reverse functions diff --git a/Makefile b/Makefile index 36b2240f..b98d18ff 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: publish test coveralls lint -VERSION=0.8.0 +VERSION=0.8.1 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 cace6b4e..d0829a6d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ ## LIPS is Pretty Simple -[![npm](https://img.shields.io/badge/npm-0.8.0-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) -[![travis](https://travis-ci.org/jcubic/jquery.terminal.svg?branch=master&24989f84cb1e8d5b431a8368e79a8f47ef021a4e)](https://travis-ci.org/jcubic/jquery.terminal) -[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=master&2565a767972a64e2959f434e12e8fcf1)](https://coveralls.io/github/jcubic/lips?branch=master) +[![npm](https://img.shields.io/badge/npm-0.8.1-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) +[![travis](https://travis-ci.org/jcubic/jquery.terminal.svg?branch=master&627e7bc615eae8dc657320600d1185076849735f)](https://travis-ci.org/jcubic/jquery.terminal) +[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=master&66ae96f244da4bd63c74f953f57cfcf3)](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 902f3fd3..6452f266 100644 --- a/dist/lips.js +++ b/dist/lips.js @@ -1,12 +1,12 @@ /**@license - * LIPS is Pretty Simple - simple scheme like lisp in JavaScript - v. 0.8.0 + * LIPS is Pretty Simple - simple scheme like lisp in JavaScript - v. 0.8.1 * * Copyright (c) 2018-2019 Jakub T. Jankiewicz * Released under the MIT license * * includes unfetch by Jason Miller (@developit) MIT License * - * build: Tue, 08 Jan 2019 21:43:44 +0000 + * build: Tue, 08 Jan 2019 22:26:13 +0000 */ (function () { 'use strict'; @@ -4326,7 +4326,7 @@ function _typeof(obj) { env: env, dynamic_scope: dynamic_scope, error: function error(e, code) { - e.message += '\nin code: ' + code.toString(); + e.code = code.toString(); throw e; } }); @@ -4450,7 +4450,7 @@ function _typeof(obj) { }); // -------------------------------------- return { - version: '0.8.0', + version: '0.8.1', exec: exec, parse: parse, tokenize: tokenize, diff --git a/dist/lips.min.js b/dist/lips.min.js index 37efe966..056f63b1 100644 --- a/dist/lips.min.js +++ b/dist/lips.min.js @@ -1,12 +1,12 @@ /**@license - * LIPS is Pretty Simple - simple scheme like lisp in JavaScript - v. 0.8.0 + * LIPS is Pretty Simple - simple scheme like lisp in JavaScript - v. 0.8.1 * * Copyright (c) 2018-2019 Jakub T. Jankiewicz * Released under the MIT license * * includes unfetch by Jason Miller (@developit) MIT License * - * build: Tue, 08 Jan 2019 21:43:44 +0000 + * build: Tue, 08 Jan 2019 22:26:13 +0000 */ (function(){"use strict";function e(e){if(Array.isArray(e))return e}function r(e,r){var n=[];var t=true;var i=false;var o=undefined;try{for(var a=e[Symbol.iterator](),c;!(t=(c=a.next()).done);t=true){n.push(c.value);if(r&&n.length===r)break}}catch(e){i=true;o=e}finally{try{if(!t&&a["return"]!=null)a["return"]()}finally{if(i)throw o}}return n}function n(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function t(t,i){return e(t)||r(t,i)||n()}function i(e,r){i=Object.setPrototypeOf||function e(r,n){r.__proto__=n;return r};return i(e,r)}function o(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Date.prototype.toString.call(Reflect.construct(Date,[],function(){}));return true}catch(e){return false}}function a(e,r,n){if(o()){a=Reflect.construct}else{a=function e(r,n,t){var i=[null];i.push.apply(i,n);var o=Function.bind.apply(r,i);var a=new o;if(t)setPrototypeOf(a,t.prototype);return a}}return a.apply(null,arguments)}function c(e,r){return r={exports:{}},e(r,r.exports),r.exports}var u=c(function(e){!function(r){var n=Object.prototype;var t=n.hasOwnProperty;var i;var o=typeof Symbol==="function"?Symbol:{};var a=o.iterator||"@@iterator";var c=o.asyncIterator||"@@asyncIterator";var u=o.toStringTag||"@@toStringTag";var f="object"==="object";var s=r.regeneratorRuntime;if(s){if(f){e.exports=s}return}s=r.regeneratorRuntime=f?e.exports:{};function l(e,r,n,t){var i=r&&r.prototype instanceof w?r:w;var o=Object.create(i.prototype);var a=new L(t||[]);o._invoke=j(e,n,a);return o}s.wrap=l;function h(e,r,n){try{return{type:"normal",arg:e.call(r,n)}}catch(e){return{type:"throw",arg:e}}}var p="suspendedStart";var v="suspendedYield";var d="executing";var y="completed";var m={};function w(){}function g(){}function b(){}var x={};x[a]=function(){return this};var k=Object.getPrototypeOf;var E=k&&k(k(q([])));if(E&&E!==n&&t.call(E,a)){x=E}var _=b.prototype=w.prototype=Object.create(x);g.prototype=_.constructor=b;b.constructor=g;b[u]=g.displayName="GeneratorFunction";function A(e){["next","throw","return"].forEach(function(r){e[r]=function(e){return this._invoke(r,e)}})}s.isGeneratorFunction=function(e){var r=typeof e==="function"&&e.constructor;return r?r===g||(r.displayName||r.name)==="GeneratorFunction":false};s.mark=function(e){if(Object.setPrototypeOf){Object.setPrototypeOf(e,b)}else{e.__proto__=b;if(!(u in e)){e[u]="GeneratorFunction"}}e.prototype=Object.create(_);return e};s.awrap=function(e){return{__await:e}};function S(e){function r(n,i,o,a){var c=h(e[n],e,i);if(c.type==="throw"){a(c.arg)}else{var u=c.arg;var f=u.value;if(f&&typeof f==="object"&&t.call(f,"__await")){return Promise.resolve(f.__await).then(function(e){r("next",e,o,a)},function(e){r("throw",e,o,a)})}return Promise.resolve(f).then(function(e){u.value=e;o(u)},function(e){return r("throw",e,o,a)})}}var n;function i(e,t){function i(){return new Promise(function(n,i){r(e,t,n,i)})}return n=n?n.then(i,i):i()}this._invoke=i}A(S.prototype);S.prototype[c]=function(){return this};s.AsyncIterator=S;s.async=function(e,r,n,t){var i=new S(l(e,r,n,t));return s.isGeneratorFunction(r)?i:i.next().then(function(e){return e.done?e.value:i.next()})};function j(e,r,n){var t=p;return function i(o,a){if(t===d){throw new Error("Generator is already running")}if(t===y){if(o==="throw"){throw a}return R()}n.method=o;n.arg=a;while(true){var c=n.delegate;if(c){var u=N(c,n);if(u){if(u===m)continue;return u}}if(n.method==="next"){n.sent=n._sent=n.arg}else if(n.method==="throw"){if(t===p){t=y;throw n.arg}n.dispatchException(n.arg)}else if(n.method==="return"){n.abrupt("return",n.arg)}t=d;var f=h(e,r,n);if(f.type==="normal"){t=n.done?y:v;if(f.arg===m){continue}return{value:f.arg,done:n.done}}else if(f.type==="throw"){t=y;n.method="throw";n.arg=f.arg}}}}function N(e,r){var n=e.iterator[r.method];if(n===i){r.delegate=null;if(r.method==="throw"){if(e.iterator.return){r.method="return";r.arg=i;N(e,r);if(r.method==="throw"){return m}}r.method="throw";r.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var t=h(n,e.iterator,r.arg);if(t.type==="throw"){r.method="throw";r.arg=t.arg;r.delegate=null;return m}var o=t.arg;if(!o){r.method="throw";r.arg=new TypeError("iterator result is not an object");r.delegate=null;return m}if(o.done){r[e.resultName]=o.value;r.next=e.nextLoc;if(r.method!=="return"){r.method="next";r.arg=i}}else{return o}r.delegate=null;return m}A(_);_[u]="Generator";_[a]=function(){return this};_.toString=function(){return"[object Generator]"};function P(e){var r={tryLoc:e[0]};if(1 in e){r.catchLoc=e[1]}if(2 in e){r.finallyLoc=e[2];r.afterLoc=e[3]}this.tryEntries.push(r)}function O(e){var r=e.completion||{};r.type="normal";delete r.arg;e.completion=r}function L(e){this.tryEntries=[{tryLoc:"root"}];e.forEach(P,this);this.reset(true)}s.keys=function(e){var r=[];for(var n in e){r.push(n)}r.reverse();return function n(){while(r.length){var t=r.pop();if(t in e){n.value=t;n.done=false;return n}}n.done=true;return n}};function q(e){if(e){var r=e[a];if(r){return r.call(e)}if(typeof e.next==="function"){return e}if(!isNaN(e.length)){var n=-1,o=function r(){while(++n=0;--o){var a=this.tryEntries[o];var c=a.completion;if(a.tryLoc==="root"){return n("end")}if(a.tryLoc<=this.prev){var u=t.call(a,"catchLoc");var f=t.call(a,"finallyLoc");if(u&&f){if(this.prev=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&t.call(i,"finallyLoc")&&this.prev=0;--r){var n=this.tryEntries[r];if(n.finallyLoc===e){this.complete(n.completion,n.afterLoc);O(n);return m}}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc===e){var t=n.completion;if(t.type==="throw"){var i=t.arg;O(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){this.delegate={iterator:q(e),resultName:r,nextLoc:n};if(this.method==="next"){this.arg=i}return m}}}(function(){return this||typeof self==="object"&&self}()||Function("return this")())});var f=function(){return this||typeof self==="object"&&self}()||Function("return this")();var s=f.regeneratorRuntime&&Object.getOwnPropertyNames(f).indexOf("regeneratorRuntime")>=0;var l=s&&f.regeneratorRuntime;f.regeneratorRuntime=undefined;var h=u;if(s){f.regeneratorRuntime=l}else{try{delete f.regeneratorRuntime}catch(e){f.regeneratorRuntime=undefined}}var p=h;function v(e,r,n,t,i,o,a){try{var c=e[o](a);var u=c.value}catch(e){n(e);return}if(c.done){r(u)}else{Promise.resolve(u).then(t,i)}}function d(e){return function(){var r=this,n=arguments;return new Promise(function(t,i){var o=e.apply(r,n);function a(e){v(o,t,i,a,c,"next",e)}function c(e){v(o,t,i,a,c,"throw",e)}a(undefined)})}}function y(e){if(Array.isArray(e)){for(var r=0,n=new Array(e.length);r1){r.pop();if(r[r.length-1].length===1&&r[r.length-1][0]instanceof b){r[r.length-1].push(e)}else if(r[r.length-1].length===0){r[r.length-1]=e}else if(r[r.length-1]instanceof _){if(r[r.length-1].cdr instanceof _){r[r.length-1]=new _(r[r.length-1],_.fromArray(e))}else{r[r.length-1].cdr=_.fromArray(e)}}else{r[r.length-1].push(e)}}}e.forEach(function(e){var o=r[r.length-1];if(i.indexOf(e)!==-1){l++;t=e;r.push([v[t]]);if(!t){s=[]}s.push(t)}else if(e==="("){c=true;a++;if(t){f.push(s);s=[]}r.push([]);t=null;l=0}else if(e==="."&&!c){r[r.length-1]=_.fromArray(o)}else if(e===")"){a--;if(!r.length){throw new Error("Unbalanced parenthesis 1")}if(r.length===1){n.push(r.pop())}else if(r.length>1){var p=r.pop();o=r[r.length-1];if(o instanceof Array){o.push(p)}else if(o instanceof _){o.append(_.fromArray(p))}if(f.length){s=f.pop();while(s.length){h();s.pop()}}else{h()}}if(a===0&&r.length){n.push(r.pop())}}else{c=false;var d=u(e);if(t){while(l--){r[r.length-1][1]=d;d=r.pop()}l=0;t=false}o=r[r.length-1];if(o instanceof _){var y=o;while(true){if(y.cdr===E){if(d instanceof Array){y.cdr=_.fromArray(d)}else{y.cdr=d}break}else{y=y.cdr}}}else if(!r.length){n.push(d)}else{o.push(d)}}});if(r.length){console.log({end:r.slice()});throw new Error("Unbalanced parenthesis 2")}return n.map(function(e){if(e instanceof Array){return _.fromArray(e)}return e})}function m(e,r){var t=Object.prototype.toString;var i="[object Array]";var o=[];var a=r&&e||e.slice();var c;if(!e.length){return o}c=a.pop();do{if(t.call(c)===i){a.push.apply(a,c)}else{o.push(c)}}while(a.length&&(c=a.pop())!==n);o.reverse();return o}function w(e){return x(e)==="symbol"||x(e)==="object"&&Object.prototype.toString.call(e)==="[object Symbol]"}function b(e){if(typeof this!=="undefined"&&this.constructor!==b||typeof this==="undefined"){return new b(e)}this.name=e}b.is=function(e,r){return e instanceof b&&typeof r==="string"&&e.name===r};b.prototype.toJSON=b.prototype.toString=function(){if(w(this.name)){return this.name.toString()}return this.name};function k(){}k.prototype.toString=function(){return"nil"};var E=new k;function _(e,r){if(typeof this!=="undefined"&&this.constructor!==_||typeof this==="undefined"){return new _(e,r)}this.car=e;this.cdr=r}function A(){return new _(n,E)}_.prototype.flatten=function(){return _.fromArray(m(this.toArray()))};_.prototype.length=function(){if(j(this)){return 0}var e=0;var r=this;while(true){if(!r||r===E||!(r instanceof _)){break}e++;r=r.cdr}return e};_.prototype.clone=function(){var e=this.cdr;var r=this.car;if(r instanceof _){r=r.clone()}if(e instanceof _){e=this.cdr.clone()}return new _(r,e)};_.prototype.toArray=function(){if(this.isEmptyList()){return[]}var e=[];if(this.car instanceof _){e.push(this.car.toArray())}else{e.push(this.car)}if(this.cdr instanceof _){e=e.concat(this.cdr.toArray())}return e};_.prototype.isEmptyList=function(){return typeof this.car==="undefined"&&this.cdr===E};_.fromArray=function(e){if(e instanceof _){return e}if(e.length&&!(e instanceof Array)){e=g(e)}if(e.length===0){return A()}else{var r;if(e[0]instanceof Array){r=_.fromArray(e[0])}else{r=e[0]}if(e.length===1){return new _(r,E)}else{return new _(r,_.fromArray(e.slice(1)))}}};_.prototype.toObject=function(){var e=this;var r={};while(true){if(e instanceof _&&e.car instanceof _){var n=e.car;var t=n.car;if(t instanceof b){t=t.name}var i=n.cdr;if(i instanceof _){i=i.toObject()}r[t]=i;e=e.cdr}else{break}}return r};_.fromPairs=function(e){return e.reduce(function(e,r){return new _(new _(new b(r[0]),r[1]),e)},E)};_.fromObject=function(e){var r=Object.keys(e).map(function(r){return[r,e[r]]});return _.fromPairs(r)};_.prototype.reduce=function(e){var r=this;var n=E;while(true){if(r!==E){n=e(n,r.car);r=r.cdr}else{break}}return n};_.prototype.reverse=function(){var e=this;var r=E;while(e!==E){var n=e.cdr;e.cdr=r;r=e;e=n}return r};_.prototype.transform=function(e){function r(n){if(n instanceof _){if(n.replace){delete n.replace;return n}var t=e(n.car);if(t instanceof _){t=r(t)}var i=e(n.cdr);if(i instanceof _){i=r(i)}return new _(t,i)}return n}return r(this)};_.prototype.map=function(e){if(typeof this.car!=="undefined"){return new _(e(this.car),j(this.cdr)?E:this.cdr.map(e))}else{return E}};_.prototype.toString=function(){var e=["("];if(this.car!==n){if(typeof this.car==="function"){e.push("<#function "+(this.car.name||"anonymous")+">")}else if(typeof this.car==="string"){e.push(JSON.stringify(this.car))}else if(this.car instanceof b){e.push(this.car.toString())}else if(typeof this.car!=="undefined"){e.push(this.car)}if(this.cdr instanceof _){e.push(" ");e.push(this.cdr.toString().replace(/^\(|\)$/g,""))}else if(typeof this.cdr!=="undefined"&&this.cdr!==E){if(typeof this.cdr==="string"){e=e.concat([" . ",JSON.stringify(this.cdr)])}else{e=e.concat([" . ",this.cdr])}}}e.push(")");return e.join("")};_.prototype.append=function(e){if(e instanceof Array){return this.append(_.fromArray(e))}var r=this;if(r.car===n){if(e instanceof _){this.car=e.car;this.cdr=e.cdr}else{return e}}else{while(true){if(r instanceof _&&r.cdr!==E){r=r.cdr}else{break}}r.cdr=e}return this};function S(e,r){if(e instanceof R&&r instanceof R){return e.cmp(r)===0}else if(typeof e==="number"||typeof r==="number"){return R(e).cmp(R(r))}else if(e instanceof b&&r instanceof b){return e.name===r.name}else{return e===r}}function j(e){return e instanceof _&&e.isEmptyList()||e===E}function N(e,r){if(typeof this!=="undefined"&&this.constructor!==N||typeof this==="undefined"){return new N(e,r)}this.name=e;this.fn=r}N.defmacro=function(e,r){var n=new N(e,r);n.defmacro=true;return n};N.prototype.invoke=function(e,r,n){var t=r.env,i=r.dynamic_scope,o=r.error;var a={dynamic_scope:i,error:o,macro_expand:n};var c=this.fn.call(t,e,a,this.name);return n?T(c):c};N.prototype.toString=function(){return"#"};var P="define-macro";function O(e){return function(){var r=d(p.mark(function r(n,t){var i,o,a,c;return p.wrap(function r(u){while(1){switch(u.prev=u.next){case 0:a=function e(){a=d(p.mark(function e(r){var n,a,c,u,f;return p.wrap(function e(s){while(1){switch(s.prev=s.next){case 0:if(!(r instanceof _&&r.car instanceof b)){s.next=13;break}s.prev=1;n=i.get(r.car);if(!(n instanceof N&&n.defmacro)){s.next=9;break}s.next=6;return n.invoke(r.cdr,t,true);case 6:a=s.sent;if(!(a instanceof _)){s.next=9;break}return s.abrupt("return",a);case 9:s.next=13;break;case 11:s.prev=11;s.t0=s["catch"](1);case 13:c=r.car;if(!(c instanceof _)){s.next=18;break}s.next=17;return o(c);case 17:c=s.sent;case 18:u=r.cdr;if(!(u instanceof _)){s.next=23;break}s.next=22;return o(u);case 22:u=s.sent;case 23:f=new _(c,u);return s.abrupt("return",f);case 25:case"end":return s.stop()}}},e,this,[[1,11]])}));return a.apply(this,arguments)};o=function e(r){return a.apply(this,arguments)};i=t["env"]=this;c=n;if(!e){u.next=12;break}u.t0=T;u.next=8;return o(n);case 8:u.t1=u.sent.car;return u.abrupt("return",(0,u.t0)(u.t1));case 12:u.next=15;return o(n);case 15:c=u.sent;if(!(n.toString()===c.toString())){u.next=18;break}return u.abrupt("break",21);case 18:n=c;u.next=12;break;case 21:return u.abrupt("return",T(c.car));case 22:case"end":return u.stop()}}},r,this)}));return function(e,n){return r.apply(this,arguments)}}()}function L(e){return typeof e==="undefined"||e===E||e===null}function q(e){var r="let"+(e?"*":"");return N.defmacro(r,function(r,n){var t=n.dynamic_scope,i=n.error,o=n.macro_expand;var a;if(r.car instanceof b){if(!(r.cdr.car instanceof _)){throw new Error("let require list of pairs")}var c=r.cdr.car.map(function(e){return e.car});a=r.cdr.car.map(function(e){return e.cdr.car});return _.fromArray([b("let*"),[[r.car,_(b("lambda"),_(c,r.cdr.cdr))]],_(r.car,a)])}else if(o){return}var u=this;a=this.get("list->array")(r.car);var f=u.inherit("let");return new Promise(function(n){var o=[];var c=0;(function s(){var l=a[c++];function h(e){if(e instanceof Promise){o.push(e);return e.then(h)}else if(typeof e==="undefined"){f.set(l.car,E)}else{f.set(l.car,e)}}if(t){t=e?f:u}if(!l){var p=new _(new b("begin"),r.cdr);Q(p,{env:f,dynamic_scope:t,error:i}).then(function(e){n(e)})}else{var v=Q(l.cdr.car,{env:e?f:u,dynamic_scope:t,error:i});var d=h(v);if(d instanceof Promise){d.then(function(){Promise.all(o).then(s)})}else{s()}}})()})})}function R(e,t){if(e instanceof R){return e}if(typeof this!=="undefined"&&this.constructor!==R||typeof this==="undefined"){return new R(e,t===true?true:n)}if(!R.isNumber(e)){throw new Error("You can't create LNumber from "+x(e))}if(e===null){e=0}if(R.isFloat(e)){this.value=e}else if(t){this.value=e;this.float=true}else if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){this.value=BigInt(e)}else{this.value=e}}else if(typeof r!=="undefined"&&!(e instanceof r)){this.value=new r(e)}else{this.value=e}}R.isFloat=function e(r){return Number(r)===r&&r%1!==0};R.isNumber=function(e){return e instanceof R||R.isNative(e)||R.isBN(e)};R.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};R.isBN=function(e){return typeof r!=="undefined"&&e instanceof r};R.prototype.toString=R.prototype.toJSON=function(){return this.value.toString()};["floor","ceil","round"].forEach(function(e){R.prototype[e]=function(){if(this.float||R.isFloat(this.value)){return R(Math[e](this.value))}else{return R(this.value)}}});R.prototype.valueOf=function(){if(R.isNative(this.value)){return Number(this.value)}else if(R.isBN(this.value)){return this.value.toNumber()}};R.prototype.coerce=function(e){if(e===null){e=0}var n;if(e instanceof R){n=e.value}else{n=e}if(R.isFloat(n)){}else if(typeof this.value==="bigint"&&typeof n!=="bigint"){n=BigInt(n)}else if(typeof r!=="undefined"&&this.value instanceof r&&!n instanceof r){n=new r(n)}return R(n)};R.prototype.op=function(e,r){var n={"*":function e(r,n){return r*n},"+":function e(r,n){return r+n},"-":function e(r,n){return r-n},"/":function e(r,n){return r/n},"%":function e(r,n){return r%n},"|":function e(r,n){return r|n},"&":function e(r,n){return r&n},"~":function e(r){return~r},">>":function e(r,n){return r>>n},"<<":function e(r,n){return r<>":"ishln"};e=i[e];return this.value.clone()[e](r,t)}};var F={"+":"add","-":"sub","*":"mul","/":"div","%":"mod","|":"or","&":"and","~":"neg","<<":"shl",">>":"shr"};Object.keys(F).forEach(function(e){R.prototype[F[e]]=function(r){return this.op(e,r)}});R.prototype.sqrt=function(){var e;if(R.isNative(this.value)){e=Math.sqrt(this.value)}else if(R.isBN(this.value)){e=this.value.sqrt()}return new R(e)};R.prototype.pow=function(e){e=this.coerce(e);if(R.isNative(this.value)){try{var r=new Function("a,b","return a**b;");e.value=r(this.value,e.value)}catch(e){throw new Error("Power operator not supported")}}else if(R.isBN(this.value)){e.value=this.value.pow(e.value)}else{e.value=Math.pow(this.value,e.value)}return e};R.prototype.neg=function(){var e=this.value;if(R.isNative(e)){e=-e}else if(R.isBN(e)){e=e.neg()}return new R(e)};R.prototype.abs=function(){var e=this.value;if(R.isNative(this.value)){if(e<0){e=-e}}else if(R.isBN(e)){e.iabs()}return new R(e)};R.prototype.isOdd=function(){if(R.isNative(this.value)){return this.value%2===1}else if(R.isBN(this.value)){return this.value.isOdd()}};R.prototype.isEven=function(){return!this.isOdd()};R.prototype.cmp=function(e){e=this.coerce(e);if(R.isNative(this.value)){if(this.value1&&arguments[1]!==n?arguments[1]:{};if(x(e)==="object"){r=e}if(!e||x(e)==="object"){e="child of "+(this.name||"unknown")}return new B(r||{},this,e)};B.prototype.get=function(r){var n;var t=false;if(r instanceof b){if(r.name in this.env){n=this.env[r.name];t=true}}else if(typeof r==="string"){if(typeof this.env[r]!=="undefined"){n=this.env[r];t=true}}if(t){if(R.isNumber(n)){return R(n)}return n}if(this.parent instanceof B){return this.parent.get(r)}else{var i;if(r instanceof b){i=r.name}else if(typeof r==="string"){i=r}if(i){var o=x(e[i]);if(o==="function"){return e[i].bind(e)}else if(o!=="undefined"){return e[i]}}}i=(i.name||i).toString();throw new Error("Unbound variable `"+i+"'")};B.prototype.set=function(e,r){if(R.isNumber(r)){r=R(r)}if(e instanceof b){e=e.name}this.env[e]=r};B.prototype.has=function(e){return typeof this.env[e]!=="undefined"};B.prototype.ref=function(e){var r=this;while(true){if(!r){break}if(r.has(e)){return r}r=r.parent}};function T(e){if(e instanceof Promise){return e.then(T)}if(e instanceof _||e instanceof b){e.data=true}return e}function I(e,r){this.value=e;this.count=r}I.prototype.toString=function(){return"<#unquote["+this.count+"] "+this.value+">"};var M=function(){var r=0;return function(){var t=arguments.length>0&&arguments[0]!==n?arguments[0]:null;if(t!==null){return new b(e.Symbol("#"+t))}r++;return new b(e.Symbol("#"+r))}}();var D=new B({nil:E,true:true,false:false,stdout:{write:function e(){var r;(r=console).log.apply(r,arguments)}},stdin:{read:function e(){return new Promise(function(e){e(prompt(""))})}},test:function e(){return Promise.resolve(n)},cons:function e(r,n){if(j(n)){n=E}return new _(r,n)},car:function e(r){if(r instanceof _){return r.car}else{throw new Error("argument to car need to be a list")}},cdr:function e(r){if(r instanceof _){return r.cdr}else{throw new Error("argument to cdr need to be a list")}},"set!":new N("set!",function(e){var r=arguments.length>1&&arguments[1]!==n?arguments[1]:{},t=r.dynamic_scope,i=r.error;if(t){t=this}var o=Q(e.cdr.car,{env:this,dynamic_scope:t,error:i});o=U(o);var a;if(e.car instanceof _&&b.is(e.car.car,".")){var c=e.car.cdr.car;var u=e.car.cdr.cdr.car;var f=Q(c,{env:this,dynamic_scope:t,error:i});var s=Q(u,{env:this,dynamic_scope:t,error:i});if(o instanceof Promise){return o.then(function(e){f[s]=e})}else{f[s]=o;return o}}if(!(e.car instanceof b)){throw new Error("set! first argument need to be a symbol")}a=this.ref(e.car.name);if(!a){a=this}if(o instanceof Promise){return o.then(function(r){return a.set(e.car,r)})}else{a.set(e.car,o)}}),"set-car!":function e(r,n){r.car=n},"set-cdr!":function e(r,n){r.cdr=n},"empty?":function e(r){return typeof r==="undefined"||j(r)},assoc:function e(r,n){if(r instanceof _&&!(n instanceof _)){throw new Error("First argument to assoc new to a key")}var t=n;while(true){if(!(t instanceof _)||this.get("empty?")(t)){break}var i=t.car.car;if(S(i,r)){return t.car}else{t=t.cdr}}return E},gensym:M,load:function r(n){var t=this;e.fetch(n).then(function(e){return e.text()}).then(function(e){t.get("eval")(t.get("read")(e))})},while:new N("while",function(){var e=d(p.mark(function e(r,n){var t,i,o,a,c,u;return p.wrap(function e(f){while(1){switch(f.prev=f.next){case 0:t=n.dynamic_scope,i=n.error;o=this;a=new _(new b("begin"),r.cdr);if(t){t=o}case 4:f.next=7;return Q(r.car,{env:o,dynamic_scope:t,error:i});case 7:u=f.sent;if(!(u&&!j(u))){f.next=14;break}f.next=11;return Q(a,{env:o,dynamic_scope:t,error:i});case 11:c=f.sent;f.next=15;break;case 14:return f.abrupt("return",c);case 15:f.next=4;break;case 17:case"end":return f.stop()}}},e,this)}));return function(r,n){return e.apply(this,arguments)}}()),if:new N("if",function(e,r){var n=r.dynamic_scope,t=r.error;if(n){n=this}var i=this;var o=function r(o){if(typeof o!=="boolean"){throw new Error("if: value need to be boolean")}if(o){var a=Q(e.cdr.car,{env:i,dynamic_scope:n,error:t});if(typeof a==="undefined"){return}return a}else{var c=Q(e.cdr.cdr.car,{env:i,dynamic_scope:n,error:t});if(typeof c==="undefined"){return false}return c}};var a=Q(e.car,{env:i,dynamic_scope:n,error:t});if(a instanceof Promise){return a.then(o)}else{return o(a)}}),"let*":q(true),let:q(false),begin:new N("begin",function(){var e=d(p.mark(function e(r,n){var t,i,o,a;return p.wrap(function e(c){while(1){switch(c.prev=c.next){case 0:t=n.dynamic_scope,i=n.error;o=this.get("list->array")(r);if(t){t=this}case 3:if(!o.length){c.next=11;break}r=o.shift();c.next=8;return Q(r,{env:this,dynamic_scope:t,error:i});case 8:a=c.sent;c.next=12;break;case 11:return c.abrupt("return",a);case 12:c.next=3;break;case 14:case"end":return c.stop()}}},e,this)}));return function(r,n){return e.apply(this,arguments)}}()),timer:new N("timer",function(e){var r=arguments.length>1&&arguments[1]!==n?arguments[1]:{},t=r.dynamic_scope,i=r.error;var o=this;if(t){t=this}return new Promise(function(r){setTimeout(function(){r(Q(e.cdr,{env:o,dynamic_scope:t,error:i}))},e.car)})}),define:N.defmacro("define",function(e,r){var n=this;if(e.car instanceof _&&e.car.car instanceof b){var t=new _(new b("define"),new _(e.car.car,new _(new _(new b("lambda"),new _(e.car.cdr,e.cdr)))));return t}else if(r.macro_expand){return}if(r.dynamic_scope){r.dynamic_scope=this}r.env=n;var i=e.cdr.car;if(i instanceof _){i=Q(i,r)}if(e.car instanceof b){if(i instanceof Promise){return i.then(function(r){n.set(e.car,r)})}else{n.set(e.car,i)}}}),"set-obj":function e(r,n,t){r[n]=t},eval:function e(r){var n=this;if(r instanceof _){return Q(r,{env:this,dynamic_scope:this,error:function e(r){return n.get("print")(r.message)}})}if(r instanceof Array){var t;r.forEach(function(e){t=Q(e,{env:n,dynamic_scope:n,error:function e(r){return n.get("print")(r.message)}})});return t}},lambda:new N("lambda",function(e){var r=arguments.length>1&&arguments[1]!==n?arguments[1]:{},t=r.dynamic_scope,i=r.error;var o=this;function a(){var r=(t?this:o).inherit("lambda");var n=e.car;var a=0;var c;if(n instanceof b||!j(n)){for(var u=arguments.length,f=new Array(u),s=0;so){o=s}if(f===u){if(e.cdr.cdr!==E){return new _(new I(e.cdr.car,s),e.cdr.cdr)}else{return new I(e.cdr.car,s)}}else if(f.cdr.cdr!==E){f.car.cdr=new _(new I(u,s),f.cdr===E?E:f.cdr.cdr)}else{f.car.cdr=new I(u,s)}return c.car}var l=e.car;if(l instanceof _){l=a(l)}var h=e.cdr;if(h instanceof _){h=a(h)}return new _(l,h)}return e}function c(e){if(e instanceof I){if(o===e.count){return Q(e.value,{env:i,dynamic_scope:n,error:t})}else{return new _(new b("unquote"),new _(c(e.value),E))}}if(e instanceof _){var r=e.car;if(r instanceof _||r instanceof I){r=c(r)}var a=e.cdr;if(a instanceof _||a instanceof I){a=c(a)}return new _(r,a)}return e}return T(c(a(e.car)))}),clone:function e(r){return r.clone()},append:function e(r,n){return r.clone().append([n])},reverse:function e(r){if(r instanceof _){var n=this.get("list->array")(r).reverse();return this.get("array->list")(n)}else if(!(r instanceof Array)){throw new Error("Invlid value for reverse")}else{return r.reverse()}},nth:function e(r,n){if(n instanceof _){var t=n;var i=0;while(iarray")(n).join(r)},split:function e(r,n){return this.get("array->list")(r.split(n))},replace:function e(r,n,t){return r.replace(n,t)},match:function e(r,n){return this.get("array->list")(r.match(n))},search:function e(r,n){return r.search(n)},string:function e(r,n){if(typeof jQuery!=="undefined"&&r instanceof jQuery.fn.init){return"<#jQuery("+r.length+")>"}if(r instanceof R){return r.value.toString()}if(typeof r==="undefined"){return"<#undefined>"}if(typeof r==="function"){if(r.toString().match(/\{\s*\[native code\]\s*\}/)){return"<#function(native)>"}return"<#function>"}if(r===E){return"nil"}if(r instanceof Array){return"["+r.map(function(r){return e(r,true)}).join(", ")+"]"}if(r===null||typeof r==="string"&&n){return JSON.stringify(r)}if(r instanceof _){return r.toString()}if(x(r)==="object"){var t=r.constructor.name;if(t!==""){return"<#"+t+">"}return"<#Object>"}if(typeof r!=="string"){return r.toString()}return r},env:function e(r){r=r||this;var t=Object.keys(r.env);var i;if(t.length){i=_.fromArray(t)}else{i=E}if(r.parent!==n){return this.get("env").call(this,r.parent).append(i)}return i},new:function e(r){for(var n=arguments.length,t=new Array(n>1?n-1:0),i=1;ilist":function e(r){return _.fromArray(r)},"list->array":function e(r){if(r instanceof _&&r.isEmptyList()){return[]}var n=[];var t=r;while(true){if(t instanceof _){n.push(t.car);t=t.cdr}else{break}}return n},apply:new N("apply",function(e){var r=this;var t=arguments.length>1&&arguments[1]!==n?arguments[1]:{},i=t.dynamic_scope,o=t.error;if(i){i=this}function a(r){if(typeof r!=="function"){var n;if(e.car instanceof b){n="Variable `"+e.car.name+"' is not a function"}else{n="Expression `"+e.car.toString()+"' is not a function"}throw new Error(n)}}var c=function n(t){a(t);var c=Q(e.cdr.car,{env:r,dynamic_scope:i,error:o});c=r.get("list->array")(c);if(c.filter(function(e){return e instanceof Promise}).length){return Promise.all(c).then(function(e){return t.apply(r,e)})}else{return t.apply(r,c)}};var u=Q(e.car,{env:this,dynamic_scope:i,error:o});if(u instanceof Promise){return u.then(c)}else{return c(u)}}),length:function e(r){if(!r){return R(0)}if(r instanceof _){return R(r.length())}if("length"in r){return R(r.length)}},find:function(){var e=d(p.mark(function e(r,n){var t,i;return p.wrap(function e(o){while(1){switch(o.prev=o.next){case 0:t=this.get("list->array")(n);i=0;case 2:if(!(iarray")(n);i=0;case 2:if(!(iarray")(n);i=[];o=0;case 3:if(!(o2&&f[2]!==n?f[2]:null;o=this.get("list->array")(t);if(!(t.length===0)){s.next=4;break}return s.abrupt("return",E);case 4:a=i;if(i===null){a=o.unshift()}c=0;case 7:if(!(carray")(n);i=[];o=0;case 3:if(!(o1?n-1:0),i=1;i=o){return r.apply(this,e)}else{return n}}return n.apply(this,arguments)}},odd:function e(r){return R(r).isOdd()},even:function e(r){return R(r).isEvent()},"*":function e(){for(var r=arguments.length,n=new Array(r),t=0;t":function e(r,n){return R(r).cmp(n)===1},"<":function e(r,n){return R(r).cmp(n)===-1},"<=":function e(r,n){return[0,-1].includes(R(r).cmp(n))},">=":function e(r,n){return[0,1].includes(R(r).cmp(n))},"eq?":S,or:new N("or",function(e,r){var n=r.dynamic_scope,t=r.error;var i=this.get("list->array")(e);var o=this;if(n){n=o}return new Promise(function(e){var r;(function a(){function c(n){r=n;if(r){e(n)}a()}var u=i.shift();if(typeof u==="undefined"){if(r){e(r)}else{e(false)}}else{var f=Q(u,{env:o,dynamic_scope:n,error:t});if(f instanceof Promise){f.then(c)}else{c(f)}}})()})}),and:new N("and",function(e){var r=arguments.length>1&&arguments[1]!==n?arguments[1]:{},t=r.dynamic_scope,i=r.error;var o=this.get("list->array")(e);var a=this;if(t){t=a}return new Promise(function(e){var r;(function n(){function c(t){r=t;if(!r){e(false)}n()}var u=o.shift();if(typeof u==="undefined"){if(r){e(r)}else{e(false)}}else{var f=Q(u,{env:a,dynamic_scope:t,error:i});if(f instanceof Promise){f.then(c)}else{c(f)}}})()})}),"|":function e(r,n){return R(r).or(n)},"&":function e(r,n){return R(r).and(n)},"~":function e(r){return R(r).neg()},">>":function e(r,n){return R(r).shr(n)},"<<":function e(r,n){return R(r).shl(n)},not:function e(r){if(j(r)){return true}return!r},"->":function e(r,n){for(var t=arguments.length,i=new Array(t>2?t-2:0),o=2;o1&&arguments[1]!==n?arguments[1]:{},t=r.env,i=r.dynamic_scope,o=r.error,a=o===void 0?function(){}:o;try{if(i===true){t=i=t||D}else if(t===true){t=i=D}else{t=t||D}var c={env:t,dynamic_scope:i,error:a};var u;if(L(e)){return e}if(j(e)){return A()}var f=e.car;var s=e.cdr;if(f instanceof _){u=U(Q(f,c));if(u instanceof Promise){return u.then(function(r){return Q(new _(r,e.cdr),c)})}else if(typeof u!=="function"){throw new Error(t.get("string")(u)+" is not a function")}}if(f instanceof b){u=t.get(f);if(u instanceof N){return H(u,s,c)}else if(typeof u!=="function"){if(u){var l="".concat(J(u)," `").concat(u,"' is not a function");throw new Error(l)}throw new Error("Unknown function `".concat(f.name,"'"))}}else if(typeof f==="function"){u=f}if(typeof u==="function"){var h=C(s,c);if(h instanceof Promise){return h.then(function(e){var r=i||t;return T(U(u.apply(r,e)))})}return T(U(u.apply(i||t,h)))}else if(e instanceof b){u=t.get(e);if(u==="undefined"){throw new Error("Unbound variable `"+e.name+"'")}return u}else if(e instanceof _){u=f&&f.toString();throw new Error("".concat(J(f)," ").concat(u," is not a function"))}else{return e}}catch(r){a&&a(r,e)}}function Y(e,r,n){return V.apply(this,arguments)}function V(){V=d(p.mark(function e(r,n,t){var i,o,a,c;return p.wrap(function e(u){while(1){switch(u.prev=u.next){case 0:if(t===true){n=t=n||D}else if(n===true){n=t=D}else{n=n||D}i=y(h(r));o=[];case 3:a=i.shift();if(a){u.next=9;break}return u.abrupt("return",o);case 9:u.next=11;return Q(a,{env:n,dynamic_scope:t,error:function e(r,n){r.message+="\nin code: "+n.toString();throw r}});case 11:c=u.sent;o.push(c);case 13:u.next=3;break;case 15:case"end":return u.stop()}}},e,this)}));return V.apply(this,arguments)}function z(e){var r=/[()]/;var n=h(e).filter(function(e){return e.match(r)});var t=n.filter(function(e){return e===")"});var i=n.filter(function(e){return e==="("});return t.length===i.length}_.unDry=function(e){return new _(e.car,e.cdr)};_.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};k.prototype.toDry=function(){return{value:null}};k.unDry=function(){return E};b.prototype.toDry=function(){return{value:{name:this.name}}};b.unDry=function(e){return new b(e.name)};function X(){var r="text/x-lips";if(window.document){Array.from(document.querySelectorAll("script")).forEach(function(n){var t=n.getAttribute("type");if(t===r){var i=n.getAttribute("src");if(i){e.fetch(i).then(function(e){return e.text()}).then(Y)}else{Y(n.innerHTML)}}else if(t&&t.match(/lips|lisp/)){console.warn("Expecting "+r+" found "+t)}})}}function K(e){if(typeof window!=="undefined"){if(window.addEventListener){window.addEventListener("load",e,false)}else if(window.attachEvent){window.attachEvent("onload",e)}else if(typeof window.onload==="function"){(function(r){window.onload=function(){e();r()}})(window.onload)}else{window.onload=e}}}K(function(){setTimeout(X,0)});return{version:"0.8.0",exec:Y,parse:y,tokenize:h,evaluate:Q,Environment:B,global_environment:D,env:D,balanced_parenthesis:z,Macro:N,quote:T,Pair:_,nil:E,maybe_promise:U,Symbol:b,LNumber:R}})})(); \ No newline at end of file +(function(e,r){if(typeof define==="function"&&define.amd){define(["bn.js"],function(n){return e.lips=r(e,n)})}else if((typeof module==="undefined"?"undefined":x(module))==="object"&&module.exports){module.exports=r(e,require("bn.js"))}else{e.lips=r(e,e.BN)}})(typeof window!=="undefined"?window:global,function(e,r,n){if(!e.fetch){e.fetch=function(e,r){r=r||{};return new Promise(function(n,t){var i=new XMLHttpRequest;i.open(r.method||"get",e,true);for(var o in r.headers){i.setRequestHeader(o,r.headers[o])}i.withCredentials=r.credentials=="include";i.onload=function(){n(a())};i.onerror=t;i.send(r.body||null);function a(){var e=[],r=[],n={},t;i.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(i,o,a){e.push(o=o.toLowerCase());r.push([o,a]);t=n[o];n[o]=t?"".concat(t,",").concat(a):a});return{ok:(i.status/100|0)==2,status:i.status,statusText:i.statusText,url:i.responseURL,clone:a,text:function e(){return Promise.resolve(i.responseText)},json:function e(){return Promise.resolve(i.responseText).then(JSON.parse)},blob:function e(){return Promise.resolve(new Blob([i.response]))},headers:{keys:function r(){return e},entries:function e(){return r},get:function e(r){return n[r.toLowerCase()]},has:function e(r){return r.toLowerCase()in n}}}}})}}var i=/^\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimy]*)$/;var o=/^[-+]?[0-9]+([eE][-+]?[0-9]+)?$/;var c=/^([-+]?((\.[0-9]+|[0-9]+\.[0-9]+)([eE][-+]?[0-9]+)?)|[0-9]+\.)$/;function u(e){function r(e){if(e.match(/^['"]/)){if(e==='""'||e==="''"){return""}var r=e[0];var n=new RegExp("((^|[^\\\\])(?:\\\\\\\\)*)"+r,"g");e=e.replace(n,"$1")}return JSON.parse('"'+e.replace(/\n/g,"\\n")+'"')}var n=e.match(i);if(n){return new RegExp(n[1],n[2])}else if(e.match(/['"]/)){return r(e)}else if(e.match(o)){return R(parseFloat(e))}else if(e.match(c)){return R(parseFloat(e),true)}else if(e==="nil"){return E}else if(e==="true"){return true}else if(e==="false"){return false}else{return new b(e)}}var f=/("(?:\\[\S\s]|[^"])*"|\/(?! )[^\/\\]*(?:\\[\S\s][^\/\\]*)*\/[gimy]*(?=\s|\(|\)|$)|;.*)/g;var s=/("(?:\\[\S\s]|[^"])*"|\/(?! )[^\/\\]*(?:\\[\S\s][^\/\\]*)*\/[gimy]*(?=\s|\(|\)|$)|\(|\)|'|"(?:\\[\S\s]|[^"])+|(?:\\[\S\s]|[^"])*"|;.*|(?:[-+]?(?:(?:\.[0-9]+|[0-9]+\.[0-9]+)(?:[eE][-+]?[0-9]+)?)|[0-9]+\.)[0-9]|\.|,@|,|`|[^(\s)]+)/gim;function l(e){var r=0;var n=0;var t=[];e.split(f).filter(Boolean).forEach(function(e){if(e.match(f)){if(!e.match(/^;/)){var i=(e.split(/\n/),[""]).pop().length;t.push({token:e,col:i,offset:r,line:n});r+=e.length}n+=(e.match("\n")||[]).length;return}e.split("\n").filter(Boolean).forEach(function(e,i){var o=0;e.split(s).filter(Boolean).forEach(function(e){var a={col:o,line:i+n,token:e,offset:r};o+=e.length;r+=e.length;t.push(a)})})});return t}function h(e,r){if(r){return l(e)}else{return l(e).map(function(e){return e.token.trim()}).filter(function(e){return e&&!e.match(/^;/)})}}var v={"'":new b("quote"),"`":new b("quasiquote"),",":new b("unquote"),",@":new b("unquote-splicing")};function y(e){var r=[];var n=[];var t=null;var i=Object.keys(v);var o=i.map(function(e){return v[e].name});var a=0;var c=false;var f=[];var s=[];var l=0;function h(){var e=r[r.length-1];if(e instanceof Array&&e[0]instanceof b&&o.includes(e[0].name)&&r.length>1){r.pop();if(r[r.length-1].length===1&&r[r.length-1][0]instanceof b){r[r.length-1].push(e)}else if(r[r.length-1].length===0){r[r.length-1]=e}else if(r[r.length-1]instanceof _){if(r[r.length-1].cdr instanceof _){r[r.length-1]=new _(r[r.length-1],_.fromArray(e))}else{r[r.length-1].cdr=_.fromArray(e)}}else{r[r.length-1].push(e)}}}e.forEach(function(e){var o=r[r.length-1];if(i.indexOf(e)!==-1){l++;t=e;r.push([v[t]]);if(!t){s=[]}s.push(t)}else if(e==="("){c=true;a++;if(t){f.push(s);s=[]}r.push([]);t=null;l=0}else if(e==="."&&!c){r[r.length-1]=_.fromArray(o)}else if(e===")"){a--;if(!r.length){throw new Error("Unbalanced parenthesis 1")}if(r.length===1){n.push(r.pop())}else if(r.length>1){var p=r.pop();o=r[r.length-1];if(o instanceof Array){o.push(p)}else if(o instanceof _){o.append(_.fromArray(p))}if(f.length){s=f.pop();while(s.length){h();s.pop()}}else{h()}}if(a===0&&r.length){n.push(r.pop())}}else{c=false;var d=u(e);if(t){while(l--){r[r.length-1][1]=d;d=r.pop()}l=0;t=false}o=r[r.length-1];if(o instanceof _){var y=o;while(true){if(y.cdr===E){if(d instanceof Array){y.cdr=_.fromArray(d)}else{y.cdr=d}break}else{y=y.cdr}}}else if(!r.length){n.push(d)}else{o.push(d)}}});if(r.length){console.log({end:r.slice()});throw new Error("Unbalanced parenthesis 2")}return n.map(function(e){if(e instanceof Array){return _.fromArray(e)}return e})}function m(e,r){var t=Object.prototype.toString;var i="[object Array]";var o=[];var a=r&&e||e.slice();var c;if(!e.length){return o}c=a.pop();do{if(t.call(c)===i){a.push.apply(a,c)}else{o.push(c)}}while(a.length&&(c=a.pop())!==n);o.reverse();return o}function w(e){return x(e)==="symbol"||x(e)==="object"&&Object.prototype.toString.call(e)==="[object Symbol]"}function b(e){if(typeof this!=="undefined"&&this.constructor!==b||typeof this==="undefined"){return new b(e)}this.name=e}b.is=function(e,r){return e instanceof b&&typeof r==="string"&&e.name===r};b.prototype.toJSON=b.prototype.toString=function(){if(w(this.name)){return this.name.toString()}return this.name};function k(){}k.prototype.toString=function(){return"nil"};var E=new k;function _(e,r){if(typeof this!=="undefined"&&this.constructor!==_||typeof this==="undefined"){return new _(e,r)}this.car=e;this.cdr=r}function A(){return new _(n,E)}_.prototype.flatten=function(){return _.fromArray(m(this.toArray()))};_.prototype.length=function(){if(j(this)){return 0}var e=0;var r=this;while(true){if(!r||r===E||!(r instanceof _)){break}e++;r=r.cdr}return e};_.prototype.clone=function(){var e=this.cdr;var r=this.car;if(r instanceof _){r=r.clone()}if(e instanceof _){e=this.cdr.clone()}return new _(r,e)};_.prototype.toArray=function(){if(this.isEmptyList()){return[]}var e=[];if(this.car instanceof _){e.push(this.car.toArray())}else{e.push(this.car)}if(this.cdr instanceof _){e=e.concat(this.cdr.toArray())}return e};_.prototype.isEmptyList=function(){return typeof this.car==="undefined"&&this.cdr===E};_.fromArray=function(e){if(e instanceof _){return e}if(e.length&&!(e instanceof Array)){e=g(e)}if(e.length===0){return A()}else{var r;if(e[0]instanceof Array){r=_.fromArray(e[0])}else{r=e[0]}if(e.length===1){return new _(r,E)}else{return new _(r,_.fromArray(e.slice(1)))}}};_.prototype.toObject=function(){var e=this;var r={};while(true){if(e instanceof _&&e.car instanceof _){var n=e.car;var t=n.car;if(t instanceof b){t=t.name}var i=n.cdr;if(i instanceof _){i=i.toObject()}r[t]=i;e=e.cdr}else{break}}return r};_.fromPairs=function(e){return e.reduce(function(e,r){return new _(new _(new b(r[0]),r[1]),e)},E)};_.fromObject=function(e){var r=Object.keys(e).map(function(r){return[r,e[r]]});return _.fromPairs(r)};_.prototype.reduce=function(e){var r=this;var n=E;while(true){if(r!==E){n=e(n,r.car);r=r.cdr}else{break}}return n};_.prototype.reverse=function(){var e=this;var r=E;while(e!==E){var n=e.cdr;e.cdr=r;r=e;e=n}return r};_.prototype.transform=function(e){function r(n){if(n instanceof _){if(n.replace){delete n.replace;return n}var t=e(n.car);if(t instanceof _){t=r(t)}var i=e(n.cdr);if(i instanceof _){i=r(i)}return new _(t,i)}return n}return r(this)};_.prototype.map=function(e){if(typeof this.car!=="undefined"){return new _(e(this.car),j(this.cdr)?E:this.cdr.map(e))}else{return E}};_.prototype.toString=function(){var e=["("];if(this.car!==n){if(typeof this.car==="function"){e.push("<#function "+(this.car.name||"anonymous")+">")}else if(typeof this.car==="string"){e.push(JSON.stringify(this.car))}else if(this.car instanceof b){e.push(this.car.toString())}else if(typeof this.car!=="undefined"){e.push(this.car)}if(this.cdr instanceof _){e.push(" ");e.push(this.cdr.toString().replace(/^\(|\)$/g,""))}else if(typeof this.cdr!=="undefined"&&this.cdr!==E){if(typeof this.cdr==="string"){e=e.concat([" . ",JSON.stringify(this.cdr)])}else{e=e.concat([" . ",this.cdr])}}}e.push(")");return e.join("")};_.prototype.append=function(e){if(e instanceof Array){return this.append(_.fromArray(e))}var r=this;if(r.car===n){if(e instanceof _){this.car=e.car;this.cdr=e.cdr}else{return e}}else{while(true){if(r instanceof _&&r.cdr!==E){r=r.cdr}else{break}}r.cdr=e}return this};function S(e,r){if(e instanceof R&&r instanceof R){return e.cmp(r)===0}else if(typeof e==="number"||typeof r==="number"){return R(e).cmp(R(r))}else if(e instanceof b&&r instanceof b){return e.name===r.name}else{return e===r}}function j(e){return e instanceof _&&e.isEmptyList()||e===E}function N(e,r){if(typeof this!=="undefined"&&this.constructor!==N||typeof this==="undefined"){return new N(e,r)}this.name=e;this.fn=r}N.defmacro=function(e,r){var n=new N(e,r);n.defmacro=true;return n};N.prototype.invoke=function(e,r,n){var t=r.env,i=r.dynamic_scope,o=r.error;var a={dynamic_scope:i,error:o,macro_expand:n};var c=this.fn.call(t,e,a,this.name);return n?T(c):c};N.prototype.toString=function(){return"#"};var P="define-macro";function O(e){return function(){var r=d(p.mark(function r(n,t){var i,o,a,c;return p.wrap(function r(u){while(1){switch(u.prev=u.next){case 0:a=function e(){a=d(p.mark(function e(r){var n,a,c,u,f;return p.wrap(function e(s){while(1){switch(s.prev=s.next){case 0:if(!(r instanceof _&&r.car instanceof b)){s.next=13;break}s.prev=1;n=i.get(r.car);if(!(n instanceof N&&n.defmacro)){s.next=9;break}s.next=6;return n.invoke(r.cdr,t,true);case 6:a=s.sent;if(!(a instanceof _)){s.next=9;break}return s.abrupt("return",a);case 9:s.next=13;break;case 11:s.prev=11;s.t0=s["catch"](1);case 13:c=r.car;if(!(c instanceof _)){s.next=18;break}s.next=17;return o(c);case 17:c=s.sent;case 18:u=r.cdr;if(!(u instanceof _)){s.next=23;break}s.next=22;return o(u);case 22:u=s.sent;case 23:f=new _(c,u);return s.abrupt("return",f);case 25:case"end":return s.stop()}}},e,this,[[1,11]])}));return a.apply(this,arguments)};o=function e(r){return a.apply(this,arguments)};i=t["env"]=this;c=n;if(!e){u.next=12;break}u.t0=T;u.next=8;return o(n);case 8:u.t1=u.sent.car;return u.abrupt("return",(0,u.t0)(u.t1));case 12:u.next=15;return o(n);case 15:c=u.sent;if(!(n.toString()===c.toString())){u.next=18;break}return u.abrupt("break",21);case 18:n=c;u.next=12;break;case 21:return u.abrupt("return",T(c.car));case 22:case"end":return u.stop()}}},r,this)}));return function(e,n){return r.apply(this,arguments)}}()}function L(e){return typeof e==="undefined"||e===E||e===null}function q(e){var r="let"+(e?"*":"");return N.defmacro(r,function(r,n){var t=n.dynamic_scope,i=n.error,o=n.macro_expand;var a;if(r.car instanceof b){if(!(r.cdr.car instanceof _)){throw new Error("let require list of pairs")}var c=r.cdr.car.map(function(e){return e.car});a=r.cdr.car.map(function(e){return e.cdr.car});return _.fromArray([b("let*"),[[r.car,_(b("lambda"),_(c,r.cdr.cdr))]],_(r.car,a)])}else if(o){return}var u=this;a=this.get("list->array")(r.car);var f=u.inherit("let");return new Promise(function(n){var o=[];var c=0;(function s(){var l=a[c++];function h(e){if(e instanceof Promise){o.push(e);return e.then(h)}else if(typeof e==="undefined"){f.set(l.car,E)}else{f.set(l.car,e)}}if(t){t=e?f:u}if(!l){var p=new _(new b("begin"),r.cdr);Q(p,{env:f,dynamic_scope:t,error:i}).then(function(e){n(e)})}else{var v=Q(l.cdr.car,{env:e?f:u,dynamic_scope:t,error:i});var d=h(v);if(d instanceof Promise){d.then(function(){Promise.all(o).then(s)})}else{s()}}})()})})}function R(e,t){if(e instanceof R){return e}if(typeof this!=="undefined"&&this.constructor!==R||typeof this==="undefined"){return new R(e,t===true?true:n)}if(!R.isNumber(e)){throw new Error("You can't create LNumber from "+x(e))}if(e===null){e=0}if(R.isFloat(e)){this.value=e}else if(t){this.value=e;this.float=true}else if(typeof BigInt!=="undefined"){if(typeof e!=="bigint"){this.value=BigInt(e)}else{this.value=e}}else if(typeof r!=="undefined"&&!(e instanceof r)){this.value=new r(e)}else{this.value=e}}R.isFloat=function e(r){return Number(r)===r&&r%1!==0};R.isNumber=function(e){return e instanceof R||R.isNative(e)||R.isBN(e)};R.isNative=function(e){return typeof e==="bigint"||typeof e==="number"};R.isBN=function(e){return typeof r!=="undefined"&&e instanceof r};R.prototype.toString=R.prototype.toJSON=function(){return this.value.toString()};["floor","ceil","round"].forEach(function(e){R.prototype[e]=function(){if(this.float||R.isFloat(this.value)){return R(Math[e](this.value))}else{return R(this.value)}}});R.prototype.valueOf=function(){if(R.isNative(this.value)){return Number(this.value)}else if(R.isBN(this.value)){return this.value.toNumber()}};R.prototype.coerce=function(e){if(e===null){e=0}var n;if(e instanceof R){n=e.value}else{n=e}if(R.isFloat(n)){}else if(typeof this.value==="bigint"&&typeof n!=="bigint"){n=BigInt(n)}else if(typeof r!=="undefined"&&this.value instanceof r&&!n instanceof r){n=new r(n)}return R(n)};R.prototype.op=function(e,r){var n={"*":function e(r,n){return r*n},"+":function e(r,n){return r+n},"-":function e(r,n){return r-n},"/":function e(r,n){return r/n},"%":function e(r,n){return r%n},"|":function e(r,n){return r|n},"&":function e(r,n){return r&n},"~":function e(r){return~r},">>":function e(r,n){return r>>n},"<<":function e(r,n){return r<>":"ishln"};e=i[e];return this.value.clone()[e](r,t)}};var F={"+":"add","-":"sub","*":"mul","/":"div","%":"mod","|":"or","&":"and","~":"neg","<<":"shl",">>":"shr"};Object.keys(F).forEach(function(e){R.prototype[F[e]]=function(r){return this.op(e,r)}});R.prototype.sqrt=function(){var e;if(R.isNative(this.value)){e=Math.sqrt(this.value)}else if(R.isBN(this.value)){e=this.value.sqrt()}return new R(e)};R.prototype.pow=function(e){e=this.coerce(e);if(R.isNative(this.value)){try{var r=new Function("a,b","return a**b;");e.value=r(this.value,e.value)}catch(e){throw new Error("Power operator not supported")}}else if(R.isBN(this.value)){e.value=this.value.pow(e.value)}else{e.value=Math.pow(this.value,e.value)}return e};R.prototype.neg=function(){var e=this.value;if(R.isNative(e)){e=-e}else if(R.isBN(e)){e=e.neg()}return new R(e)};R.prototype.abs=function(){var e=this.value;if(R.isNative(this.value)){if(e<0){e=-e}}else if(R.isBN(e)){e.iabs()}return new R(e)};R.prototype.isOdd=function(){if(R.isNative(this.value)){return this.value%2===1}else if(R.isBN(this.value)){return this.value.isOdd()}};R.prototype.isEven=function(){return!this.isOdd()};R.prototype.cmp=function(e){e=this.coerce(e);if(R.isNative(this.value)){if(this.value1&&arguments[1]!==n?arguments[1]:{};if(x(e)==="object"){r=e}if(!e||x(e)==="object"){e="child of "+(this.name||"unknown")}return new B(r||{},this,e)};B.prototype.get=function(r){var n;var t=false;if(r instanceof b){if(r.name in this.env){n=this.env[r.name];t=true}}else if(typeof r==="string"){if(typeof this.env[r]!=="undefined"){n=this.env[r];t=true}}if(t){if(R.isNumber(n)){return R(n)}return n}if(this.parent instanceof B){return this.parent.get(r)}else{var i;if(r instanceof b){i=r.name}else if(typeof r==="string"){i=r}if(i){var o=x(e[i]);if(o==="function"){return e[i].bind(e)}else if(o!=="undefined"){return e[i]}}}i=(i.name||i).toString();throw new Error("Unbound variable `"+i+"'")};B.prototype.set=function(e,r){if(R.isNumber(r)){r=R(r)}if(e instanceof b){e=e.name}this.env[e]=r};B.prototype.has=function(e){return typeof this.env[e]!=="undefined"};B.prototype.ref=function(e){var r=this;while(true){if(!r){break}if(r.has(e)){return r}r=r.parent}};function T(e){if(e instanceof Promise){return e.then(T)}if(e instanceof _||e instanceof b){e.data=true}return e}function I(e,r){this.value=e;this.count=r}I.prototype.toString=function(){return"<#unquote["+this.count+"] "+this.value+">"};var M=function(){var r=0;return function(){var t=arguments.length>0&&arguments[0]!==n?arguments[0]:null;if(t!==null){return new b(e.Symbol("#"+t))}r++;return new b(e.Symbol("#"+r))}}();var D=new B({nil:E,true:true,false:false,stdout:{write:function e(){var r;(r=console).log.apply(r,arguments)}},stdin:{read:function e(){return new Promise(function(e){e(prompt(""))})}},test:function e(){return Promise.resolve(n)},cons:function e(r,n){if(j(n)){n=E}return new _(r,n)},car:function e(r){if(r instanceof _){return r.car}else{throw new Error("argument to car need to be a list")}},cdr:function e(r){if(r instanceof _){return r.cdr}else{throw new Error("argument to cdr need to be a list")}},"set!":new N("set!",function(e){var r=arguments.length>1&&arguments[1]!==n?arguments[1]:{},t=r.dynamic_scope,i=r.error;if(t){t=this}var o=Q(e.cdr.car,{env:this,dynamic_scope:t,error:i});o=U(o);var a;if(e.car instanceof _&&b.is(e.car.car,".")){var c=e.car.cdr.car;var u=e.car.cdr.cdr.car;var f=Q(c,{env:this,dynamic_scope:t,error:i});var s=Q(u,{env:this,dynamic_scope:t,error:i});if(o instanceof Promise){return o.then(function(e){f[s]=e})}else{f[s]=o;return o}}if(!(e.car instanceof b)){throw new Error("set! first argument need to be a symbol")}a=this.ref(e.car.name);if(!a){a=this}if(o instanceof Promise){return o.then(function(r){return a.set(e.car,r)})}else{a.set(e.car,o)}}),"set-car!":function e(r,n){r.car=n},"set-cdr!":function e(r,n){r.cdr=n},"empty?":function e(r){return typeof r==="undefined"||j(r)},assoc:function e(r,n){if(r instanceof _&&!(n instanceof _)){throw new Error("First argument to assoc new to a key")}var t=n;while(true){if(!(t instanceof _)||this.get("empty?")(t)){break}var i=t.car.car;if(S(i,r)){return t.car}else{t=t.cdr}}return E},gensym:M,load:function r(n){var t=this;e.fetch(n).then(function(e){return e.text()}).then(function(e){t.get("eval")(t.get("read")(e))})},while:new N("while",function(){var e=d(p.mark(function e(r,n){var t,i,o,a,c,u;return p.wrap(function e(f){while(1){switch(f.prev=f.next){case 0:t=n.dynamic_scope,i=n.error;o=this;a=new _(new b("begin"),r.cdr);if(t){t=o}case 4:f.next=7;return Q(r.car,{env:o,dynamic_scope:t,error:i});case 7:u=f.sent;if(!(u&&!j(u))){f.next=14;break}f.next=11;return Q(a,{env:o,dynamic_scope:t,error:i});case 11:c=f.sent;f.next=15;break;case 14:return f.abrupt("return",c);case 15:f.next=4;break;case 17:case"end":return f.stop()}}},e,this)}));return function(r,n){return e.apply(this,arguments)}}()),if:new N("if",function(e,r){var n=r.dynamic_scope,t=r.error;if(n){n=this}var i=this;var o=function r(o){if(typeof o!=="boolean"){throw new Error("if: value need to be boolean")}if(o){var a=Q(e.cdr.car,{env:i,dynamic_scope:n,error:t});if(typeof a==="undefined"){return}return a}else{var c=Q(e.cdr.cdr.car,{env:i,dynamic_scope:n,error:t});if(typeof c==="undefined"){return false}return c}};var a=Q(e.car,{env:i,dynamic_scope:n,error:t});if(a instanceof Promise){return a.then(o)}else{return o(a)}}),"let*":q(true),let:q(false),begin:new N("begin",function(){var e=d(p.mark(function e(r,n){var t,i,o,a;return p.wrap(function e(c){while(1){switch(c.prev=c.next){case 0:t=n.dynamic_scope,i=n.error;o=this.get("list->array")(r);if(t){t=this}case 3:if(!o.length){c.next=11;break}r=o.shift();c.next=8;return Q(r,{env:this,dynamic_scope:t,error:i});case 8:a=c.sent;c.next=12;break;case 11:return c.abrupt("return",a);case 12:c.next=3;break;case 14:case"end":return c.stop()}}},e,this)}));return function(r,n){return e.apply(this,arguments)}}()),timer:new N("timer",function(e){var r=arguments.length>1&&arguments[1]!==n?arguments[1]:{},t=r.dynamic_scope,i=r.error;var o=this;if(t){t=this}return new Promise(function(r){setTimeout(function(){r(Q(e.cdr,{env:o,dynamic_scope:t,error:i}))},e.car)})}),define:N.defmacro("define",function(e,r){var n=this;if(e.car instanceof _&&e.car.car instanceof b){var t=new _(new b("define"),new _(e.car.car,new _(new _(new b("lambda"),new _(e.car.cdr,e.cdr)))));return t}else if(r.macro_expand){return}if(r.dynamic_scope){r.dynamic_scope=this}r.env=n;var i=e.cdr.car;if(i instanceof _){i=Q(i,r)}if(e.car instanceof b){if(i instanceof Promise){return i.then(function(r){n.set(e.car,r)})}else{n.set(e.car,i)}}}),"set-obj":function e(r,n,t){r[n]=t},eval:function e(r){var n=this;if(r instanceof _){return Q(r,{env:this,dynamic_scope:this,error:function e(r){return n.get("print")(r.message)}})}if(r instanceof Array){var t;r.forEach(function(e){t=Q(e,{env:n,dynamic_scope:n,error:function e(r){return n.get("print")(r.message)}})});return t}},lambda:new N("lambda",function(e){var r=arguments.length>1&&arguments[1]!==n?arguments[1]:{},t=r.dynamic_scope,i=r.error;var o=this;function a(){var r=(t?this:o).inherit("lambda");var n=e.car;var a=0;var c;if(n instanceof b||!j(n)){for(var u=arguments.length,f=new Array(u),s=0;so){o=s}if(f===u){if(e.cdr.cdr!==E){return new _(new I(e.cdr.car,s),e.cdr.cdr)}else{return new I(e.cdr.car,s)}}else if(f.cdr.cdr!==E){f.car.cdr=new _(new I(u,s),f.cdr===E?E:f.cdr.cdr)}else{f.car.cdr=new I(u,s)}return c.car}var l=e.car;if(l instanceof _){l=a(l)}var h=e.cdr;if(h instanceof _){h=a(h)}return new _(l,h)}return e}function c(e){if(e instanceof I){if(o===e.count){return Q(e.value,{env:i,dynamic_scope:n,error:t})}else{return new _(new b("unquote"),new _(c(e.value),E))}}if(e instanceof _){var r=e.car;if(r instanceof _||r instanceof I){r=c(r)}var a=e.cdr;if(a instanceof _||a instanceof I){a=c(a)}return new _(r,a)}return e}return T(c(a(e.car)))}),clone:function e(r){return r.clone()},append:function e(r,n){return r.clone().append([n])},reverse:function e(r){if(r instanceof _){var n=this.get("list->array")(r).reverse();return this.get("array->list")(n)}else if(!(r instanceof Array)){throw new Error("Invlid value for reverse")}else{return r.reverse()}},nth:function e(r,n){if(n instanceof _){var t=n;var i=0;while(iarray")(n).join(r)},split:function e(r,n){return this.get("array->list")(r.split(n))},replace:function e(r,n,t){return r.replace(n,t)},match:function e(r,n){return this.get("array->list")(r.match(n))},search:function e(r,n){return r.search(n)},string:function e(r,n){if(typeof jQuery!=="undefined"&&r instanceof jQuery.fn.init){return"<#jQuery("+r.length+")>"}if(r instanceof R){return r.value.toString()}if(typeof r==="undefined"){return"<#undefined>"}if(typeof r==="function"){if(r.toString().match(/\{\s*\[native code\]\s*\}/)){return"<#function(native)>"}return"<#function>"}if(r===E){return"nil"}if(r instanceof Array){return"["+r.map(function(r){return e(r,true)}).join(", ")+"]"}if(r===null||typeof r==="string"&&n){return JSON.stringify(r)}if(r instanceof _){return r.toString()}if(x(r)==="object"){var t=r.constructor.name;if(t!==""){return"<#"+t+">"}return"<#Object>"}if(typeof r!=="string"){return r.toString()}return r},env:function e(r){r=r||this;var t=Object.keys(r.env);var i;if(t.length){i=_.fromArray(t)}else{i=E}if(r.parent!==n){return this.get("env").call(this,r.parent).append(i)}return i},new:function e(r){for(var n=arguments.length,t=new Array(n>1?n-1:0),i=1;ilist":function e(r){return _.fromArray(r)},"list->array":function e(r){if(r instanceof _&&r.isEmptyList()){return[]}var n=[];var t=r;while(true){if(t instanceof _){n.push(t.car);t=t.cdr}else{break}}return n},apply:new N("apply",function(e){var r=this;var t=arguments.length>1&&arguments[1]!==n?arguments[1]:{},i=t.dynamic_scope,o=t.error;if(i){i=this}function a(r){if(typeof r!=="function"){var n;if(e.car instanceof b){n="Variable `"+e.car.name+"' is not a function"}else{n="Expression `"+e.car.toString()+"' is not a function"}throw new Error(n)}}var c=function n(t){a(t);var c=Q(e.cdr.car,{env:r,dynamic_scope:i,error:o});c=r.get("list->array")(c);if(c.filter(function(e){return e instanceof Promise}).length){return Promise.all(c).then(function(e){return t.apply(r,e)})}else{return t.apply(r,c)}};var u=Q(e.car,{env:this,dynamic_scope:i,error:o});if(u instanceof Promise){return u.then(c)}else{return c(u)}}),length:function e(r){if(!r){return R(0)}if(r instanceof _){return R(r.length())}if("length"in r){return R(r.length)}},find:function(){var e=d(p.mark(function e(r,n){var t,i;return p.wrap(function e(o){while(1){switch(o.prev=o.next){case 0:t=this.get("list->array")(n);i=0;case 2:if(!(iarray")(n);i=0;case 2:if(!(iarray")(n);i=[];o=0;case 3:if(!(o2&&f[2]!==n?f[2]:null;o=this.get("list->array")(t);if(!(t.length===0)){s.next=4;break}return s.abrupt("return",E);case 4:a=i;if(i===null){a=o.unshift()}c=0;case 7:if(!(carray")(n);i=[];o=0;case 3:if(!(o1?n-1:0),i=1;i=o){return r.apply(this,e)}else{return n}}return n.apply(this,arguments)}},odd:function e(r){return R(r).isOdd()},even:function e(r){return R(r).isEvent()},"*":function e(){for(var r=arguments.length,n=new Array(r),t=0;t":function e(r,n){return R(r).cmp(n)===1},"<":function e(r,n){return R(r).cmp(n)===-1},"<=":function e(r,n){return[0,-1].includes(R(r).cmp(n))},">=":function e(r,n){return[0,1].includes(R(r).cmp(n))},"eq?":S,or:new N("or",function(e,r){var n=r.dynamic_scope,t=r.error;var i=this.get("list->array")(e);var o=this;if(n){n=o}return new Promise(function(e){var r;(function a(){function c(n){r=n;if(r){e(n)}a()}var u=i.shift();if(typeof u==="undefined"){if(r){e(r)}else{e(false)}}else{var f=Q(u,{env:o,dynamic_scope:n,error:t});if(f instanceof Promise){f.then(c)}else{c(f)}}})()})}),and:new N("and",function(e){var r=arguments.length>1&&arguments[1]!==n?arguments[1]:{},t=r.dynamic_scope,i=r.error;var o=this.get("list->array")(e);var a=this;if(t){t=a}return new Promise(function(e){var r;(function n(){function c(t){r=t;if(!r){e(false)}n()}var u=o.shift();if(typeof u==="undefined"){if(r){e(r)}else{e(false)}}else{var f=Q(u,{env:a,dynamic_scope:t,error:i});if(f instanceof Promise){f.then(c)}else{c(f)}}})()})}),"|":function e(r,n){return R(r).or(n)},"&":function e(r,n){return R(r).and(n)},"~":function e(r){return R(r).neg()},">>":function e(r,n){return R(r).shr(n)},"<<":function e(r,n){return R(r).shl(n)},not:function e(r){if(j(r)){return true}return!r},"->":function e(r,n){for(var t=arguments.length,i=new Array(t>2?t-2:0),o=2;o1&&arguments[1]!==n?arguments[1]:{},t=r.env,i=r.dynamic_scope,o=r.error,a=o===void 0?function(){}:o;try{if(i===true){t=i=t||D}else if(t===true){t=i=D}else{t=t||D}var c={env:t,dynamic_scope:i,error:a};var u;if(L(e)){return e}if(j(e)){return A()}var f=e.car;var s=e.cdr;if(f instanceof _){u=U(Q(f,c));if(u instanceof Promise){return u.then(function(r){return Q(new _(r,e.cdr),c)})}else if(typeof u!=="function"){throw new Error(t.get("string")(u)+" is not a function")}}if(f instanceof b){u=t.get(f);if(u instanceof N){return H(u,s,c)}else if(typeof u!=="function"){if(u){var l="".concat(J(u)," `").concat(u,"' is not a function");throw new Error(l)}throw new Error("Unknown function `".concat(f.name,"'"))}}else if(typeof f==="function"){u=f}if(typeof u==="function"){var h=C(s,c);if(h instanceof Promise){return h.then(function(e){var r=i||t;return T(U(u.apply(r,e)))})}return T(U(u.apply(i||t,h)))}else if(e instanceof b){u=t.get(e);if(u==="undefined"){throw new Error("Unbound variable `"+e.name+"'")}return u}else if(e instanceof _){u=f&&f.toString();throw new Error("".concat(J(f)," ").concat(u," is not a function"))}else{return e}}catch(r){a&&a(r,e)}}function Y(e,r,n){return V.apply(this,arguments)}function V(){V=d(p.mark(function e(r,n,t){var i,o,a,c;return p.wrap(function e(u){while(1){switch(u.prev=u.next){case 0:if(t===true){n=t=n||D}else if(n===true){n=t=D}else{n=n||D}i=y(h(r));o=[];case 3:a=i.shift();if(a){u.next=9;break}return u.abrupt("return",o);case 9:u.next=11;return Q(a,{env:n,dynamic_scope:t,error:function e(r,n){r.code=n.toString();throw r}});case 11:c=u.sent;o.push(c);case 13:u.next=3;break;case 15:case"end":return u.stop()}}},e,this)}));return V.apply(this,arguments)}function z(e){var r=/[()]/;var n=h(e).filter(function(e){return e.match(r)});var t=n.filter(function(e){return e===")"});var i=n.filter(function(e){return e==="("});return t.length===i.length}_.unDry=function(e){return new _(e.car,e.cdr)};_.prototype.toDry=function(){return{value:{car:this.car,cdr:this.cdr}}};k.prototype.toDry=function(){return{value:null}};k.unDry=function(){return E};b.prototype.toDry=function(){return{value:{name:this.name}}};b.unDry=function(e){return new b(e.name)};function X(){var r="text/x-lips";if(window.document){Array.from(document.querySelectorAll("script")).forEach(function(n){var t=n.getAttribute("type");if(t===r){var i=n.getAttribute("src");if(i){e.fetch(i).then(function(e){return e.text()}).then(Y)}else{Y(n.innerHTML)}}else if(t&&t.match(/lips|lisp/)){console.warn("Expecting "+r+" found "+t)}})}}function K(e){if(typeof window!=="undefined"){if(window.addEventListener){window.addEventListener("load",e,false)}else if(window.attachEvent){window.attachEvent("onload",e)}else if(typeof window.onload==="function"){(function(r){window.onload=function(){e();r()}})(window.onload)}else{window.onload=e}}}K(function(){setTimeout(X,0)});return{version:"0.8.1",exec:Y,parse:y,tokenize:h,evaluate:Q,Environment:B,global_environment:D,env:D,balanced_parenthesis:z,Macro:N,quote:T,Pair:_,nil:E,maybe_promise:U,Symbol:b,LNumber:R}})})(); \ No newline at end of file diff --git a/package.json b/package.json index 11f6e1bc..017f8f75 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jcubic/lips", - "version": "0.8.0", + "version": "0.8.1", "description": "Simple Scheme Like Lisp in JavaScript", "main": "src/lips.js", "unpkg": "dist/lips.min.js", diff --git a/spec/lips.spec.js b/spec/lips.spec.js index ce804511..4f02a983 100644 --- a/spec/lips.spec.js +++ b/spec/lips.spec.js @@ -397,6 +397,7 @@ describe('evaluate', function() { }); it('should throw exception', function() { return lips.exec(code, env, env).catch(e => { + expect(e.code).toEqual('(apply f args)'); expect(e).toEqual(new Error("Unbound variable `f'")); }); }); diff --git a/src/lips.js b/src/lips.js index 4196bd61..8936cba5 100644 --- a/src/lips.js +++ b/src/lips.js @@ -2508,7 +2508,7 @@ env, dynamic_scope, error: (e, code) => { - e.message += '\nin code: ' + code.toString(); + e.code = code.toString(); throw e; } });