From c7d8e02bc84ce92913ed0db8cca863f914419c31 Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Sun, 4 Mar 2018 09:15:12 +0100 Subject: [PATCH] version 0.2.0 --- 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 c601b875..cff9e849 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: publish test coveralls lint -VERSION=0.1.0 +VERSION=0.2.0 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 df8c9884..f7ffd3de 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&acf06f4b5cae4b8fb9ca088cda6a89e805b48569)](https://travis-ci.org/jcubic/jquery.terminal) -[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&)](https://coveralls.io/github/jcubic/lips?branch=devel) +[![npm](https://img.shields.io/badge/npm-0.2.0-blue.svg)](https://www.npmjs.com/package/@jcubic/lips) +[![travis](https://travis-ci.org/jcubic/jquery.terminal.svg?branch=master&6d5149f2f3a76a5960c78736738a05a0f30a5159)](https://travis-ci.org/jcubic/jquery.terminal) +[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=master&90f3a78d04af7d30b1ab1a6b7b5d9c13)](https://coveralls.io/github/jcubic/lips?branch=master) diff --git a/dist/lips.js b/dist/lips.js index bda784f2..a1ebda51 100644 --- a/dist/lips.js +++ b/dist/lips.js @@ -1,10 +1,10 @@ /**@license - * LIPS is Pretty Simple - version DEV + * LIPS is Pretty Simple - version 0.2.0 * * Copyright (c) 2018 Jakub Jankiewicz * Released under the MIT license * - * build: Sun, 04 Mar 2018 08:09:12 +0000 + * build: Sun, 04 Mar 2018 08:14:59 +0000 */ /* * TODO: Pair.prototype.toObject = alist to Object @@ -1168,7 +1168,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr return new _Symbol(value.name); }; return { - version: 'DEV', + version: '0.2.0', parse: parse, tokenize: tokenize, evaluate: evaluate, diff --git a/dist/lips.min.js b/dist/lips.min.js index 89bf112a..612bdeb3 100644 --- a/dist/lips.min.js +++ b/dist/lips.min.js @@ -1,9 +1,9 @@ /**@license - * LIPS is Pretty Simple - version DEV + * LIPS is Pretty Simple - version 0.2.0 * * Copyright (c) 2018 Jakub Jankiewicz * Released under the MIT license * - * build: Sun, 04 Mar 2018 08:09:12 +0000 + * build: Sun, 04 Mar 2018 08:14:59 +0000 */ -"use strict";var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(n){return typeof n}:function(n){return n&&typeof Symbol==="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n};function _toConsumableArray(n){if(Array.isArray(n)){for(var r=0,e=Array(n.length);r1){var p=r.pop();d=r[r.length-1];if(d instanceof Array){d.push(p)}else if(d instanceof l){d.append(l.fromArray(p))}if(d instanceof Array&&d[0]instanceof c&&o.includes(d[0].name)&&r.length>1){r.pop();if(r[r.length-1].length===0){r[r.length-1]=d}else if(r[r.length-1]instanceof l){if(r[r.length-1].cdr instanceof l){r[r.length-1]=new l(r[r.length-1],l.fromArray(d))}else{r[r.length-1].cdr=l.fromArray(d)}}else{r[r.length-1].push(d)}}}if(u===0&&r.length){e.push(r.pop())}}else{h=false;var v=t(n);if(i){v=[f[i],v];i=false}if(d instanceof l){var y=d;while(true){if(y.cdr===s){y.cdr=v;break}else{y=y.cdr}}}else if(!r.length){e.push(v)}else{d.push(v)}}});if(r.length){throw new Error("Unbalanced parenthesis")}return e.map(function(n){if(n instanceof Array){return l.fromArray(n)}return n})}function c(n){this.name=n}c.is=function(n,r){return n instanceof c&&typeof r==="string"&&n.name===r};c.prototype.toJSON=c.prototype.toString=function(){return this.name};function u(){}u.prototype.toString=function(){return"nil"};var s=new u;function l(n,r){this.car=n;this.cdr=r}l.prototype.length=function(){var n=0;var r=this;while(true){if(r===s){break}n++;r=r.cdr}return n};l.prototype.clone=function(){var n;if(this.cdr===s){n=s}else{n=this.cdr.clone()}return new l(this.car,n)};l.prototype.toArray=function(){if(this.cdr===s&&this.car===s){return[]}var n=[];if(this.car instanceof l){n.push(this.car.toArray())}else{n.push(this.car)}if(this.cdr instanceof l){n=n.concat(this.cdr.toArray())}return n};l.fromArray=function(n){if(n instanceof l){return n}if(n.length&&!n instanceof Array){n=[].concat(_toConsumableArray(n))}if(n.length===0){return new l(s,s)}else{var r;if(n[0]instanceof Array){r=l.fromArray(n[0])}else{r=n[0]}if(n.length===1){return new l(r,s)}else{return new l(r,l.fromArray(n.slice(1)))}}};l.prototype.toObject=function(){var n=this;var r={};while(true){if(n instanceof l&&n.car instanceof l){var e=n.car;var t=e.car;if(t instanceof c){t=t.name}r[t]=e.cdr;n=n.cdr}else{break}}return r};l.fromPairs=function(n){return n.reduce(function(n,r){return new l(new l(new c(r[0]),r[1]),n)},s)};l.fromObject=function(n){var r=Object.keys(n).map(function(r){return[r,n[r]]});return l.fromPairs(r)};l.prototype.reduce=function(n){var r=this;var e=s;while(true){if(r!==s){e=n(e,r.car);r=r.cdr}else{break}}return e};l.prototype.reverse=function(){var n=this;var r=s;while(n!==s){var e=n.cdr;n.cdr=r;r=n;n=e}return r};l.prototype.transform=function(n){var r=[];function e(t){if(t instanceof l){if(t.replace){delete t.replace;return t}var i=n(t.car);if(i instanceof l){i=e(i);r.push(i)}var a=n(t.cdr);if(a instanceof l){a=e(a);r.push(a)}return new l(i,a)}return t}return e(this)};l.prototype.toString=function(){var n=["("];if(typeof this.car==="string"){n.push(JSON.stringify(this.car))}else if(typeof this.car!=="undefined"){n.push(this.car)}if(this.cdr instanceof l){n.push(" ");n.push(this.cdr.toString().replace(/^\(|\)$/g,""))}else if(typeof this.cdr!=="undefined"&&this.cdr!==s){if(typeof this.cdr==="string"){n=n.concat([" . ",JSON.stringify(this.cdr)])}else{n=n.concat([" . ",this.cdr])}}n.push(")");return n.join("")};l.prototype.append=function(n){if(n instanceof Array){return this.append(l.fromArray(n))}var r=this;while(true){if(r instanceof l&&r.cdr!==s){r=r.cdr}else{break}}r.cdr=n;return this};function h(n){this.fn=n}h.prototype.invoke=function(n,r){return this.fn.call(r,n)};function d(n,r){this.env=n;this.parent=r}d.prototype.get=function(n){if(n instanceof c){if(typeof this.env[n.name]!=="undefined"){return this.env[n.name]}}else if(typeof n==="string"){if(typeof this.env[n]!=="undefined"){return this.env[n]}}if(this.parent instanceof d){return this.parent.get(n)}else if(n instanceof c){if(typeof window[n.name]!=="undefined"){return window[n.name]}}else if(typeof n==="string"){if(typeof window[n]!=="undefined"){return window[n]}}};d.prototype.set=function(n,r){this.env[n]=r};function p(n){this.value=n}function v(n){return new h(function(r){var e=this;var t=this.get("list->array")(r.car);var i=new d({},this);t.forEach(function(r){i.set(r.car,A(r.cdr.car,n?i:e))});var a=new l(new c("begin"),r.cdr);return new p(A(a,i))})}var y=function(){var n=0;return function(){n++;return new c("#"+n)}}();function w(r){var e=arguments.length>1&&arguments[1]!==n?arguments[1]:"GET";var t=arguments.length>2&&arguments[2]!==n?arguments[2]:{};var i=arguments.length>3&&arguments[3]!==n?arguments[3]:null;var a=new XMLHttpRequest;a.open(e,r,true);Object.keys(t).forEach(function(n){a.setRequestHeader(n,t[n])});return new Promise(function(n){a.onreadystatechange=function(){if(a.readyState===4&&a.status===200){n(a.responseText)}};if(i!==null){a.send(i)}else{a.send()}})}var g=new d({nil:s,window:window,true:true,false:false,stdout:{write:function n(){var r;(r=console).log.apply(r,arguments)}},stdin:{read:function n(){return new Promise(function(n){n(prompt(""))})}},cons:function n(r,e){return new l(r,e)},car:function n(r){if(r instanceof l){return r.car}else{throw new Error("argument to car need to be a list")}},cdr:function n(r){if(r instanceof l){return r.cdr}else{throw new Error("argument to cdr need to be a list")}},"set-car":function n(r,e){r.car=e},"set-cdr":function n(r,e){r.cdr=e},assoc:function n(r,e){var t=r;var i=e instanceof c?e.name:e;while(true){var a=t.car.car;if(a instanceof c&&a.name===i||a.name===i){return t.car}else{t=t.cdr}}},gensym:y,load:function n(r){var e=this;w(r).then(function(n){e.get("eval")(e.get("read")(n))})},while:new h(function(n){var r=this;var e=new l(new c("begin"),n.cdr);return new Promise(function(t){var i;(function a(){function f(n){if(n){var f=A(e,r);if(f instanceof Promise){f.then(function(n){i=n;a()})}else{i=f;a()}}else{t(i)}}var o=A(n.car,r);if(o instanceof Promise){o.then(f)}else{f(o)}})()})}),if:new h(function(n){var r=this;var e=function e(t){if(t){var i=A(n.cdr.car,r);if(typeof i==="undefined"){return}return i}else if(n.cdr.cdr.car instanceof l){var a=A(n.cdr.cdr.car,r);if(typeof a==="undefined"){return false}return a}else{return false}};var t=A(n.car,this);if(t instanceof Promise){return t.then(e)}else{return e(t)}}),"let*":v(true),let:v(false),begin:new h(function(n){var r=this;var e=this.get("list->array")(n);return e.reduce(function(n,e){return A(e,r)},0)}),timer:new h(function(n){var r=this;return new Promise(function(e){setTimeout(function(){e(new p(A(n.cdr,r)))},n.car)})}),define:new h(function(n){if(n.car instanceof l&&n.car.car instanceof c){var r=new l(new c("define"),new l(n.car.car,new l(new l(new c("lambda"),new l(n.car.cdr,n.cdr)))));return r}var e=n.cdr.car;if(e instanceof l){e=A(e,this)}if(n.car instanceof c){this.env[n.car.name]=e}}),set:function n(r,e,t){r[e]=t},eval:function n(r){var e=this;if(r instanceof l){return A(r,this)}if(r instanceof Array){var t;r.forEach(function(n){t=A(n,e)});return t}},lambda:new h(function(r){var e=this;return function(){var t=new d({},e);var i=r.car;var a=0;var f;while(true){if(i.car!==s){if(typeof(arguments.length<=a?n:arguments[a])==="undefined"){f=s}else{f=arguments.length<=a?n:arguments[a]}t.env[i.car.name]=f}if(i.cdr===s){break}a++;i=i.cdr}return A(r.cdr.car,t)}}),defmacro:new h(function(n){if(n.car.car instanceof c){this.env[n.car.car.name]=new h(function(r){var e=new d({},this);var t=n.car.cdr;var i=r;while(true){if(t.car!==s&&i.car!==s){e.env[t.car.name]=i.car}if(t.cdr===s){break}i=i.cdr;t=t.cdr}return A(n.cdr.car,e)})}}),quote:new h(function(n){return new p(n.car)}),quasiquote:new h(function(n){var r=this;function e(n){if(n instanceof l){var t;if(c.is(n.car.car,"unquote-splicing")){t=A(n.car.cdr.car,r);if(!t instanceof l){throw new Error("Value of unquote-splicing need"+" to be pair")}if(n.cdr instanceof l){if(t instanceof l){t.cdr.append(e(n.cdr))}else{t=new l(t,e(n.cdr))}}return t}if(c.is(n.car,"unquote-splicing")){t=A(n.cdr.car,r);if(!t instanceof l){throw new Error("Value of unquote-splicing"+" need to be pair")}return t}if(c.is(n.car,"unquote")){if(n.cdr.cdr!==s){return new l(A(n.cdr.car,r),n.cdr.cdr)}else{return A(n.cdr.car,r)}}var i=n.car;if(i instanceof l){i=e(i)}var a=n.cdr;if(a instanceof l){a=e(a)}return new l(i,a)}return n}return new p(e(n.car))}),clone:function n(r){return r.clone()},append:function n(r,e){return this.get("append!")(r.clone(),e)},"append!":function n(r,e){var t=r;while(true){if(t.cdr===s){t.cdr=e;break}t=t.cdr}return r},list:function n(){return l.fromArray([].slice.call(arguments))},concat:function n(){return[].join.call(arguments,"")},string:function n(r){if(typeof jQuery!=="undefined"&&r instanceof jQuery.fn.init){return"<#jQuery>"}if(r instanceof h){}if(typeof r==="undefined"){return"<#undefined>"}if(typeof r==="function"){return"<#function>"}if(r===s){return"nil"}if(r instanceof Array||r===null){return JSON.stringify(r)}if(r instanceof l){return r.toString()}if((typeof r==="undefined"?"undefined":_typeof(r))==="object"){var e=r.constructor.name;if(e!==""){return"<#"+e+">"}return"<#Object>"}if(typeof r!=="string"){return r.toString()}return r},env:function r(e){e=e||this;var t=Object.keys(e.env);var i;if(t.length){i=l.fromArray(t)}else{i=s}if(e.parent!==n){return this.get("env").call(this,e.parent).append(i)}return i},".":function n(r,e){var t=e instanceof c?e.name:e;var i=r[t];if(typeof i==="function"){return i.bind(r)}return i},read:function n(r){var e=this;if(typeof r==="string"){return o(a(r))}return this.get("stdin").read().then(function(n){return e.get("read").call(e,n)})},print:function n(){var r,e=this;for(var t=arguments.length,i=Array(t),a=0;alist":function n(r){return l.fromArray(r)},"list->array":function n(r){var e=[];var t=r;while(true){if(t instanceof l){e.push(t.car);t=t.cdr}else{break}}return e},filter:function n(r,e){return l.fromArray(this.get("list->array")(e).filter(r))},odd:function n(r){return r%2===1},even:function n(r){return r%2===0},apply:function n(r,e){var t=this.get("list->array")(e);return r.apply(null,t)},map:function n(r,e){var t=this.get("list->array")(e).map(r);if(t.length){return l.fromArray(t)}else{return s}},reduce:function n(r,e){var t=this.get("list->array")(e);return t.reduce(function(n,e){return r(n,e)},s)},"*":function n(){for(var r=arguments.length,e=Array(r),t=0;t":function n(r,e){return r>e},"<":function n(r,e){return r=":function n(r,e){return r>=e},or:new h(function(n){var r=this.get("list->array")(n);var e=this;return new Promise(function(n){var t;(function i(){function a(r){t=r;if(t){n(r)}i()}var f=r.shift();if(typeof f==="undefined"){if(t){n(t)}else{n(false)}}else{var o=A(f,e);if(o instanceof Promise){o.then(a)}else{a(o)}}})()})}),and:new h(function(n){var r=this.get("list->array")(n);var e=this;return new Promise(function(n){var t;(function i(){function a(r){t=r;if(!t){n(false)}i()}var f=r.shift();if(typeof f==="undefined"){if(t){n(t)}else{n(false)}}else{var o=A(f,e);if(o instanceof Promise){o.then(a)}else{a(o)}}})()})}),"++":new h(function(n){var r=this.get(n.car)+1;this.set(n.car,r);return r}),"--":new h(function(n){var r=this.get(n.car)-1;this.set(n.car,r);return r})});function m(n){if(n.length===1){return n[0]}else{var r=[];var e=m(n.slice(1));for(var t=0;t1){var p=r.pop();d=r[r.length-1];if(d instanceof Array){d.push(p)}else if(d instanceof l){d.append(l.fromArray(p))}if(d instanceof Array&&d[0]instanceof c&&o.includes(d[0].name)&&r.length>1){r.pop();if(r[r.length-1].length===0){r[r.length-1]=d}else if(r[r.length-1]instanceof l){if(r[r.length-1].cdr instanceof l){r[r.length-1]=new l(r[r.length-1],l.fromArray(d))}else{r[r.length-1].cdr=l.fromArray(d)}}else{r[r.length-1].push(d)}}}if(u===0&&r.length){e.push(r.pop())}}else{h=false;var v=t(n);if(i){v=[f[i],v];i=false}if(d instanceof l){var y=d;while(true){if(y.cdr===s){y.cdr=v;break}else{y=y.cdr}}}else if(!r.length){e.push(v)}else{d.push(v)}}});if(r.length){throw new Error("Unbalanced parenthesis")}return e.map(function(n){if(n instanceof Array){return l.fromArray(n)}return n})}function c(n){this.name=n}c.is=function(n,r){return n instanceof c&&typeof r==="string"&&n.name===r};c.prototype.toJSON=c.prototype.toString=function(){return this.name};function u(){}u.prototype.toString=function(){return"nil"};var s=new u;function l(n,r){this.car=n;this.cdr=r}l.prototype.length=function(){var n=0;var r=this;while(true){if(r===s){break}n++;r=r.cdr}return n};l.prototype.clone=function(){var n;if(this.cdr===s){n=s}else{n=this.cdr.clone()}return new l(this.car,n)};l.prototype.toArray=function(){if(this.cdr===s&&this.car===s){return[]}var n=[];if(this.car instanceof l){n.push(this.car.toArray())}else{n.push(this.car)}if(this.cdr instanceof l){n=n.concat(this.cdr.toArray())}return n};l.fromArray=function(n){if(n instanceof l){return n}if(n.length&&!n instanceof Array){n=[].concat(_toConsumableArray(n))}if(n.length===0){return new l(s,s)}else{var r;if(n[0]instanceof Array){r=l.fromArray(n[0])}else{r=n[0]}if(n.length===1){return new l(r,s)}else{return new l(r,l.fromArray(n.slice(1)))}}};l.prototype.toObject=function(){var n=this;var r={};while(true){if(n instanceof l&&n.car instanceof l){var e=n.car;var t=e.car;if(t instanceof c){t=t.name}r[t]=e.cdr;n=n.cdr}else{break}}return r};l.fromPairs=function(n){return n.reduce(function(n,r){return new l(new l(new c(r[0]),r[1]),n)},s)};l.fromObject=function(n){var r=Object.keys(n).map(function(r){return[r,n[r]]});return l.fromPairs(r)};l.prototype.reduce=function(n){var r=this;var e=s;while(true){if(r!==s){e=n(e,r.car);r=r.cdr}else{break}}return e};l.prototype.reverse=function(){var n=this;var r=s;while(n!==s){var e=n.cdr;n.cdr=r;r=n;n=e}return r};l.prototype.transform=function(n){var r=[];function e(t){if(t instanceof l){if(t.replace){delete t.replace;return t}var i=n(t.car);if(i instanceof l){i=e(i);r.push(i)}var a=n(t.cdr);if(a instanceof l){a=e(a);r.push(a)}return new l(i,a)}return t}return e(this)};l.prototype.toString=function(){var n=["("];if(typeof this.car==="string"){n.push(JSON.stringify(this.car))}else if(typeof this.car!=="undefined"){n.push(this.car)}if(this.cdr instanceof l){n.push(" ");n.push(this.cdr.toString().replace(/^\(|\)$/g,""))}else if(typeof this.cdr!=="undefined"&&this.cdr!==s){if(typeof this.cdr==="string"){n=n.concat([" . ",JSON.stringify(this.cdr)])}else{n=n.concat([" . ",this.cdr])}}n.push(")");return n.join("")};l.prototype.append=function(n){if(n instanceof Array){return this.append(l.fromArray(n))}var r=this;while(true){if(r instanceof l&&r.cdr!==s){r=r.cdr}else{break}}r.cdr=n;return this};function h(n){this.fn=n}h.prototype.invoke=function(n,r){return this.fn.call(r,n)};function d(n,r){this.env=n;this.parent=r}d.prototype.get=function(n){if(n instanceof c){if(typeof this.env[n.name]!=="undefined"){return this.env[n.name]}}else if(typeof n==="string"){if(typeof this.env[n]!=="undefined"){return this.env[n]}}if(this.parent instanceof d){return this.parent.get(n)}else if(n instanceof c){if(typeof window[n.name]!=="undefined"){return window[n.name]}}else if(typeof n==="string"){if(typeof window[n]!=="undefined"){return window[n]}}};d.prototype.set=function(n,r){this.env[n]=r};function p(n){this.value=n}function v(n){return new h(function(r){var e=this;var t=this.get("list->array")(r.car);var i=new d({},this);t.forEach(function(r){i.set(r.car,A(r.cdr.car,n?i:e))});var a=new l(new c("begin"),r.cdr);return new p(A(a,i))})}var y=function(){var n=0;return function(){n++;return new c("#"+n)}}();function w(r){var e=arguments.length>1&&arguments[1]!==n?arguments[1]:"GET";var t=arguments.length>2&&arguments[2]!==n?arguments[2]:{};var i=arguments.length>3&&arguments[3]!==n?arguments[3]:null;var a=new XMLHttpRequest;a.open(e,r,true);Object.keys(t).forEach(function(n){a.setRequestHeader(n,t[n])});return new Promise(function(n){a.onreadystatechange=function(){if(a.readyState===4&&a.status===200){n(a.responseText)}};if(i!==null){a.send(i)}else{a.send()}})}var g=new d({nil:s,window:window,true:true,false:false,stdout:{write:function n(){var r;(r=console).log.apply(r,arguments)}},stdin:{read:function n(){return new Promise(function(n){n(prompt(""))})}},cons:function n(r,e){return new l(r,e)},car:function n(r){if(r instanceof l){return r.car}else{throw new Error("argument to car need to be a list")}},cdr:function n(r){if(r instanceof l){return r.cdr}else{throw new Error("argument to cdr need to be a list")}},"set-car":function n(r,e){r.car=e},"set-cdr":function n(r,e){r.cdr=e},assoc:function n(r,e){var t=r;var i=e instanceof c?e.name:e;while(true){var a=t.car.car;if(a instanceof c&&a.name===i||a.name===i){return t.car}else{t=t.cdr}}},gensym:y,load:function n(r){var e=this;w(r).then(function(n){e.get("eval")(e.get("read")(n))})},while:new h(function(n){var r=this;var e=new l(new c("begin"),n.cdr);return new Promise(function(t){var i;(function a(){function f(n){if(n){var f=A(e,r);if(f instanceof Promise){f.then(function(n){i=n;a()})}else{i=f;a()}}else{t(i)}}var o=A(n.car,r);if(o instanceof Promise){o.then(f)}else{f(o)}})()})}),if:new h(function(n){var r=this;var e=function e(t){if(t){var i=A(n.cdr.car,r);if(typeof i==="undefined"){return}return i}else if(n.cdr.cdr.car instanceof l){var a=A(n.cdr.cdr.car,r);if(typeof a==="undefined"){return false}return a}else{return false}};var t=A(n.car,this);if(t instanceof Promise){return t.then(e)}else{return e(t)}}),"let*":v(true),let:v(false),begin:new h(function(n){var r=this;var e=this.get("list->array")(n);return e.reduce(function(n,e){return A(e,r)},0)}),timer:new h(function(n){var r=this;return new Promise(function(e){setTimeout(function(){e(new p(A(n.cdr,r)))},n.car)})}),define:new h(function(n){if(n.car instanceof l&&n.car.car instanceof c){var r=new l(new c("define"),new l(n.car.car,new l(new l(new c("lambda"),new l(n.car.cdr,n.cdr)))));return r}var e=n.cdr.car;if(e instanceof l){e=A(e,this)}if(n.car instanceof c){this.env[n.car.name]=e}}),set:function n(r,e,t){r[e]=t},eval:function n(r){var e=this;if(r instanceof l){return A(r,this)}if(r instanceof Array){var t;r.forEach(function(n){t=A(n,e)});return t}},lambda:new h(function(r){var e=this;return function(){var t=new d({},e);var i=r.car;var a=0;var f;while(true){if(i.car!==s){if(typeof(arguments.length<=a?n:arguments[a])==="undefined"){f=s}else{f=arguments.length<=a?n:arguments[a]}t.env[i.car.name]=f}if(i.cdr===s){break}a++;i=i.cdr}return A(r.cdr.car,t)}}),defmacro:new h(function(n){if(n.car.car instanceof c){this.env[n.car.car.name]=new h(function(r){var e=new d({},this);var t=n.car.cdr;var i=r;while(true){if(t.car!==s&&i.car!==s){e.env[t.car.name]=i.car}if(t.cdr===s){break}i=i.cdr;t=t.cdr}return A(n.cdr.car,e)})}}),quote:new h(function(n){return new p(n.car)}),quasiquote:new h(function(n){var r=this;function e(n){if(n instanceof l){var t;if(c.is(n.car.car,"unquote-splicing")){t=A(n.car.cdr.car,r);if(!t instanceof l){throw new Error("Value of unquote-splicing need"+" to be pair")}if(n.cdr instanceof l){if(t instanceof l){t.cdr.append(e(n.cdr))}else{t=new l(t,e(n.cdr))}}return t}if(c.is(n.car,"unquote-splicing")){t=A(n.cdr.car,r);if(!t instanceof l){throw new Error("Value of unquote-splicing"+" need to be pair")}return t}if(c.is(n.car,"unquote")){if(n.cdr.cdr!==s){return new l(A(n.cdr.car,r),n.cdr.cdr)}else{return A(n.cdr.car,r)}}var i=n.car;if(i instanceof l){i=e(i)}var a=n.cdr;if(a instanceof l){a=e(a)}return new l(i,a)}return n}return new p(e(n.car))}),clone:function n(r){return r.clone()},append:function n(r,e){return this.get("append!")(r.clone(),e)},"append!":function n(r,e){var t=r;while(true){if(t.cdr===s){t.cdr=e;break}t=t.cdr}return r},list:function n(){return l.fromArray([].slice.call(arguments))},concat:function n(){return[].join.call(arguments,"")},string:function n(r){if(typeof jQuery!=="undefined"&&r instanceof jQuery.fn.init){return"<#jQuery>"}if(r instanceof h){}if(typeof r==="undefined"){return"<#undefined>"}if(typeof r==="function"){return"<#function>"}if(r===s){return"nil"}if(r instanceof Array||r===null){return JSON.stringify(r)}if(r instanceof l){return r.toString()}if((typeof r==="undefined"?"undefined":_typeof(r))==="object"){var e=r.constructor.name;if(e!==""){return"<#"+e+">"}return"<#Object>"}if(typeof r!=="string"){return r.toString()}return r},env:function r(e){e=e||this;var t=Object.keys(e.env);var i;if(t.length){i=l.fromArray(t)}else{i=s}if(e.parent!==n){return this.get("env").call(this,e.parent).append(i)}return i},".":function n(r,e){var t=e instanceof c?e.name:e;var i=r[t];if(typeof i==="function"){return i.bind(r)}return i},read:function n(r){var e=this;if(typeof r==="string"){return o(a(r))}return this.get("stdin").read().then(function(n){return e.get("read").call(e,n)})},print:function n(){var r,e=this;for(var t=arguments.length,i=Array(t),a=0;alist":function n(r){return l.fromArray(r)},"list->array":function n(r){var e=[];var t=r;while(true){if(t instanceof l){e.push(t.car);t=t.cdr}else{break}}return e},filter:function n(r,e){return l.fromArray(this.get("list->array")(e).filter(r))},odd:function n(r){return r%2===1},even:function n(r){return r%2===0},apply:function n(r,e){var t=this.get("list->array")(e);return r.apply(null,t)},map:function n(r,e){var t=this.get("list->array")(e).map(r);if(t.length){return l.fromArray(t)}else{return s}},reduce:function n(r,e){var t=this.get("list->array")(e);return t.reduce(function(n,e){return r(n,e)},s)},"*":function n(){for(var r=arguments.length,e=Array(r),t=0;t":function n(r,e){return r>e},"<":function n(r,e){return r=":function n(r,e){return r>=e},or:new h(function(n){var r=this.get("list->array")(n);var e=this;return new Promise(function(n){var t;(function i(){function a(r){t=r;if(t){n(r)}i()}var f=r.shift();if(typeof f==="undefined"){if(t){n(t)}else{n(false)}}else{var o=A(f,e);if(o instanceof Promise){o.then(a)}else{a(o)}}})()})}),and:new h(function(n){var r=this.get("list->array")(n);var e=this;return new Promise(function(n){var t;(function i(){function a(r){t=r;if(!t){n(false)}i()}var f=r.shift();if(typeof f==="undefined"){if(t){n(t)}else{n(false)}}else{var o=A(f,e);if(o instanceof Promise){o.then(a)}else{a(o)}}})()})}),"++":new h(function(n){var r=this.get(n.car)+1;this.set(n.car,r);return r}),"--":new h(function(n){var r=this.get(n.car)-1;this.set(n.car,r);return r})});function m(n){if(n.length===1){return n[0]}else{var r=[];var e=m(n.slice(1));for(var t=0;t