An experiment in parentheses-free lisp (in JavaScript)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

1 lines
64 KiB

!function(){"use strict";function e(e){return Rn.test(e)}function t(e){return typeof e===Nn}function n(e){return e&&typeof e===Sn}function r(e){return typeof e===kn}function i(e){return typeof e===En}function o(e){return r(e)||null===e||""===e}function a(e){return Array.isArray(e)||e instanceof Array}function u(e,t){var n=Object.getOwnPropertyDescriptor(e,t);return r(e[t])||n&&n.writable}function s(e){return Cn.test(e)}function c(e,t){return Array.prototype.slice.call((t||document).querySelectorAll(e))}function f(e,t){return(t||document).querySelector(e)}function p(){return document.createDocumentFragment()}function l(){return document.createTextNode("")}function h(e){return!!e.ownerSVGElement}function d(e){return"svg"===e?document.createElementNS(An,e):document.createElement(e)}function m(e,t){if(r(e.innerHTML)){var n=(new DOMParser).parseFromString(t,"application/xml"),i=e.ownerDocument.importNode(n.documentElement,!0);e.appendChild(i)}else e.innerHTML=t}function y(e,t){e.style.display=t?"":"none",e.hidden=!t}function v(e,t){e.removeAttribute(t)}function g(e){return Object.keys(e).reduce(function(t,n){return t+" "+n+": "+e[n]+";"},"")}function x(e,t){return e.getAttribute(t)}function b(e,t,n){var r=jn.exec(t);r&&r[1]?e.setAttributeNS(On,r[1],n):e.setAttribute(t,n)}function w(e,t,n){e.insertBefore(t,n.parentNode&&n)}function _(e,t){if(e)for(var n;n=Dn.exec(e);)t(n[1].toLowerCase(),n[2]||n[3]||n[4])}function T(e,t,n){if(e){var r,i=t(e,n);if(!1===i)return;for(e=e.firstChild;e;)r=e.nextSibling,T(e,t,i),e=r}}function E(e,t){for(var n=e?e.length:0,r=0;r<n;++r)t(e[r],r);return e}function S(e,t){return-1!==e.indexOf(t)}function k(e){return e.replace(/-(\w)/g,function(e,t){return t.toUpperCase()})}function N(e,t){return e.slice(0,t.length)===t}function O(e,t,n,r){return Object.defineProperty(e,t,A({value:n,enumerable:!1,writable:!1,configurable:!0},r)),e}function A(e){for(var t,n=arguments,r=1;r<n.length;++r)if(t=n[r])for(var i in t)u(e,i)&&(e[i]=t[i]);return e}function j(e,t,n){var r=this.__.parent,i=this.__.item;if(!i)for(;r&&!i;)i=r.__.item,r=r.__.parent;if(u(n,"currentTarget")&&(n.currentTarget=e),u(n,"target")&&(n.target=n.srcElement),u(n,"which")&&(n.which=n.charCode||n.keyCode),n.item=i,t.call(this,n),Qn.autoUpdate&&!n.preventUpdate){var o=se(this);o.isMounted&&o.update()}}function I(e,t,n,r){var i,o=j.bind(r,n,t);n[e]=null,i=e.replace(Ln,""),S(r.__.listeners,n)||r.__.listeners.push(n),n[Tn]||(n[Tn]={}),n[Tn][e]&&n.removeEventListener(i,n[Tn][e]),n[Tn][e]=o,n.addEventListener(i,o,!1)}function J(e,t,n){var r,o,a,u;e.tag&&e.tagName===n?e.tag.update():(o="VIRTUAL"===e.dom.tagName,e.tag&&(o&&(a=e.tag.__.head,u=l(),a.parentNode.insertBefore(u,a)),e.tag.unmount(!0)),i(n)&&(e.impl=hn[n],r={root:e.dom,parent:t,hasImpl:!0,tagName:n},e.tag=ue(e.impl,r,e.dom.innerHTML,t),E(e.attrs,function(t){return b(e.tag.root,t.name,t.value)}),e.tagName=n,e.tag.mount(),o&&me(e.tag,u||e.tag.root),t.__.onUnmount=function(){var t=e.tag.opts.dataIs,n=e.tag.parent.tags,r=e.tag.__.parent.tags;he(n,t,e.tag),he(r,t,e.tag),e.tag.unmount()}))}function F(e){return e?(e=e.replace(mn,""),Mn[e]&&(e=Mn[e]),e):null}function L(e){if(!this.root||!x(this.root,"virtualized")){var r,i,a,u=e.dom,s=F(e.attr),c=S([wn,_n],s),f=e.root&&"VIRTUAL"===e.root.tagName,p=u&&(e.parent||u.parentNode),l="style"===s,h="class"===s;if(e._riot_id)e.isMounted?e.update():(e.mount(),f&&me(e,e.root));else{if(e.update)return e.update();if(a=Wn(e.expr,c?A({},Object.create(this.parent),this):this),r=!o(a),(i=n(a))&&(i=!h&&!l,h?a=Wn(JSON.stringify(a),this):l&&(a=g(a))),!e.attr||e.isAttrRemoved&&r&&!1!==a||(v(u,e.attr),e.isAttrRemoved=!0),e.bool&&(a=!!a&&s),e.isRtag)return J(e,this,a);if((!e.wasParsedOnce||e.value!==a)&&(e.value=a,e.wasParsedOnce=!0,!i||c)){if(o(a)&&(a=""),!s)return a+="",void(p&&(e.parent=p,"TEXTAREA"===p.tagName?(p.value=a,Un||(u.nodeValue=a)):u.nodeValue=a));t(a)?I(s,a,u,this):c?y(u,s===_n?!a:a):(e.bool&&(u[s]=a),"value"===s&&u.value!==a&&(u.value=a),r&&!1!==a&&b(u,s,a),l&&u.hidden&&y(u,!1))}}}}function C(e){E(e,L.bind(this))}function D(e,t,n,r){var i=r?Object.create(r):{};return i[e.key]=t,e.pos&&(i[e.pos]=n),i}function M(e,t){for(var n=t.length,r=e.length;n>r;)n--,R.apply(t[n],[t,n])}function R(e,t){e.splice(t,1),this.unmount(),he(this.parent,this,this.__.tagName,!0)}function U(e){var t=this;E(Object.keys(this.tags),function(n){ae.apply(t.tags[n],[n,e])})}function B(e,t,n){n?ve.apply(this,[e,t]):w(e,this.root,t.root)}function P(e,t,n){n?ye.apply(this,[e,t]):w(e,this.root,t.root)}function z(e,t){t?ye.call(this,e):e.appendChild(this.root)}function $(e,t,n){v(e,xn);var r,o=typeof x(e,bn)!==En||v(e,bn),u=fe(e),s=hn[u],c=e.parentNode,f=l(),h=ie(e),d=x(e,gn),m=[],y=[],g=!hn[u],b="VIRTUAL"===e.tagName;return n=Wn.loopKeys(n),n.isLoop=!0,d&&v(e,gn),c.insertBefore(f,e),c.removeChild(e),n.update=function(){n.value=Wn(n.val,t);var c=p(),l=n.value,v=!a(l)&&!i(l),x=f.parentNode;x&&(v?l=(r=l||!1)?Object.keys(l).map(function(e){return D(n,l[e],e)}):[]:r=!1,d&&(l=l.filter(function(e,r){return n.key&&!v?!!Wn(d,D(n,e,r,t)):!!Wn(d,A(Object.create(t),e))})),E(l,function(i,a){var f=o&&typeof i===Sn&&!r,p=y.indexOf(i),d=-1===p,v=!d&&f?p:a,w=m[v],_=a>=y.length,T=f&&d||!f&&!w;i=!r&&n.key?D(n,i,a):i,T?((w=new re(s,{parent:t,isLoop:!0,isAnonymous:g,tagName:u,root:e.cloneNode(g),item:i,index:a},e.innerHTML)).mount(),_?z.apply(w,[c||x,b]):P.apply(w,[x,m[a],b]),_||y.splice(a,0,i),m.splice(a,0,w),h&&le(t.tags,u,w,!0)):v!==a&&f&&(S(l,y[v])&&(B.apply(w,[x,m[a],b]),m.splice(a,0,m.splice(v,1)[0]),y.splice(a,0,y.splice(v,1)[0])),n.pos&&(w[n.pos]=a),!h&&w.tags&&U.call(w,a)),w.__.item=i,w.__.index=a,w.__.parent=t,T||w.update(i)}),M(l,m),y=l.slice(),x.insertBefore(c,f))},n.unmount=function(){E(m,function(e){e.unmount()})},n}function q(e,t,n){var r=this;T(e,function(t,i){var o,a,u,s=t.nodeType,c=i.parent;if(!n&&t===e)return{parent:c};if(3===s&&"STYLE"!==t.parentNode.tagName&&Wn.hasExpr(t.nodeValue)&&c.children.push({dom:t,expr:t.nodeValue}),1!==s)return i;var f="VIRTUAL"===t.tagName;if(o=x(t,xn))return f&&b(t,"loopVirtual",!0),c.children.push($(t,r,o)),!1;if(o=x(t,gn))return c.children.push(Object.create(Xn).init(t,r,o)),!1;if((a=x(t,vn))&&Wn.hasExpr(a))return c.children.push({isRtag:!0,expr:a,dom:t,attrs:[].slice.call(t.attributes)}),!1;if(u=ie(t),f&&(x(t,"virtualized")&&t.parentElement.removeChild(t),u||x(t,"virtualized")||x(t,"loopVirtual")||(u={tmpl:t.outerHTML})),u&&(t!==e||n)){if(!f||x(t,vn)){var p={root:t,parent:r,hasImpl:!0};return c.children.push(ue(u,p,t.innerHTML,r)),!1}b(t,"virtualized",!0);var l=new re({tmpl:t.outerHTML},{root:t,parent:r},t.innerHTML);c.children.push(l)}return V.apply(r,[t,t.attributes,function(e,t){t&&c.children.push(t)}]),{parent:c}},{parent:{children:t}})}function V(t,n,r){var i=this;E(n,function(n){if(!n)return!1;var o,a=n.name,u=e(a);S(yn,a)?o=Object.create(Yn).init(t,i,a,n.value):Wn.hasExpr(n.value)&&(o={dom:t,expr:n.value,attr:a,bool:u}),r(n,o)})}function H(e,t,n){var r="o"===n[0],i=r?"select>":"table>";if(e.innerHTML="<"+i+t.trim()+"</"+i,i=e.firstChild,r)i.selectedIndex=-1;else{var o=ir[n];o&&1===i.childElementCount&&(i=f(o,i))}return i}function K(e,t){if(!er.test(e))return e;var n={};return t=t&&t.replace(nr,function(e,t,r){return n[t]=n[t]||r,""}).trim(),e.replace(rr,function(e,t,r){return n[t]||r||""}).replace(tr,function(e,n){return t||n||""})}function W(e,t,n){var r=e&&e.match(/^\s*<([-\w]+)/),i=r&&r[1].toLowerCase(),o=d(n?ur:ar);return e=K(e,t),or.test(i)?o=H(o,e,i):m(o,e),o}function G(e,t){var n=this,r=n.name,i=n.tmpl,o=n.css,a=n.attrs,u=n.onCreate;return hn[r]||(Z(r,i,o,a,u),hn[r].class=this.constructor),de(e,r,t,this),o&&Vn.inject(),this}function Z(e,n,r,i,o){return t(i)&&(o=i,/^[\w\-]+\s?=/.test(r)?(i=r,r=""):i=""),r&&(t(r)?o=r:Vn.add(r)),e=e.toLowerCase(),hn[e]={name:e,tmpl:n,attrs:i,fn:o},e}function Q(e,t,n,r,i){return n&&Vn.add(n,e),hn[e]={name:e,tmpl:t,attrs:r,fn:i},e}function X(e,t,r){function o(e){if(e.tagName){var n,i=x(e,vn);t&&i!==t&&(i=t,b(e,vn,t)),(n=de(e,i||e.tagName.toLowerCase(),r))&&s.push(n)}else e.length&&E(e,o)}var a,u,s=[];if(Vn.inject(),n(t)&&(r=t,t=0),a=i(e)?(e="*"===e?u=ge():e+ge(e.split(/, */)))?c(e):[]:e,"*"===t){if(t=u||ge(),a.tagName)a=c(t,a);else{var f=[];E(a,function(e){return f.push(c(t,e))}),a=f}t=0}return o(a),s}function Y(e,i,o){if(n(e))Y("__"+fr+++"__",e,!0);else{var a=o?cr:sr;if(!i){if(r(a[e]))throw new Error("Unregistered mixin: "+e);return a[e]}a[e]=t(i)?A(i.prototype,a[e]||{})&&i:A(a[e]||{},i)}}function ee(){return E(ln,function(e){return e.update()})}function te(e){hn[e]=null}function ne(e,t,n,r,i){if(!e||!n){var o=!n&&e?this:t||this;E(i,function(e){e.expr&&C.call(o,[e.expr]),r[k(e.name).replace(mn,"")]=e.expr?e.expr.value:e.value})}}function re(e,n,r){void 0===e&&(e={}),void 0===n&&(n={});var o,a=A({},n.opts),u=n.parent,s=n.isLoop,c=!!n.isAnonymous,f=Qn.skipAnonymousTags&&c,p=pe(n.item),l=n.index,d=[],y=[],g=[],x=n.root,w=n.tagName||fe(x),T="virtual"===w,k=!T&&!e.tmpl,j=[];f||Gn(this),e.name&&x._tag&&x._tag.unmount(!0),this.isMounted=!1,O(this,"__",{isAnonymous:c,instAttrs:d,innerHTML:r,tagName:w,index:l,isLoop:s,isInline:k,listeners:[],virts:[],tail:null,head:null,parent:null,item:null}),O(this,"_riot_id",++lr),O(this,"root",x),A(this,{opts:a},p),O(this,"parent",u||null),O(this,"tags",{}),O(this,"refs",{}),k||s&&c?o=x:(T||(x.innerHTML=""),o=W(e.tmpl,r,h(x))),O(this,"update",function(e){var n={},r=this.isMounted&&!f;return e=pe(e),A(this,e),ne.apply(this,[s,u,c,n,d]),r&&this.isMounted&&t(this.shouldUpdate)&&!this.shouldUpdate(e,n)?this:(s&&c&&oe.apply(this,[this.parent,j]),A(a,n),r&&this.trigger("update",e),C.call(this,g),r&&this.trigger("updated"),this)}.bind(this)),O(this,"mixin",function(){var e=this;return E(arguments,function(n){var r,o,a=[],u=["init","__proto__"];n=i(n)?Y(n):n,r=t(n)?new n:n;var s=Object.getPrototypeOf(r);do{a=a.concat(Object.getOwnPropertyNames(o||r))}while(o=Object.getPrototypeOf(o||r));E(a,function(n){if(!S(u,n)){var i=Object.getOwnPropertyDescriptor(r,n)||Object.getOwnPropertyDescriptor(s,n),o=i&&(i.get||i.set);!e.hasOwnProperty(n)&&o?Object.defineProperty(e,n,i):e[n]=t(r[n])?r[n].bind(e):r[n]}}),r.init&&r.init.bind(e)()}),this}.bind(this)),O(this,"mount",function(){var t=this;x._tag=this,V.apply(u,[x,x.attributes,function(e,n){!c&&Yn.isPrototypeOf(n)&&(n.tag=t),e.expr=n,d.push(e)}]),y=[],_(e.attrs,function(e,t){y.push({name:e,value:t})}),V.apply(this,[x,y,function(e,t){t?g.push(t):b(x,e.name,e.value)}]),ne.apply(this,[s,u,c,a,d]);var n=Y(dn);if(n&&!f)for(var r in n)n.hasOwnProperty(r)&&t.mixin(n[r]);if(e.fn&&e.fn.call(this,a),f||this.trigger("before-mount"),q.apply(this,[o,g,c]),this.update(p),!c&&!k)for(;o.firstChild;)x.appendChild(o.firstChild);if(O(this,"root",x),O(this,"isMounted",!0),!f){if(this.parent){var i=se(this.parent);i.one(i.isMounted?"updated":"mount",function(){t.trigger("mount")})}else this.trigger("mount");return this}}.bind(this)),O(this,"unmount",function(t){var n,r=this,i=this.root,o=i.parentNode,a=ln.indexOf(this);return f||this.trigger("before-unmount"),_(e.attrs,function(e){N(e,mn)&&(e=e.slice(mn.length)),v(x,e)}),this.__.listeners.forEach(function(e){Object.keys(e[Tn]).forEach(function(t){e.removeEventListener(t,e[Tn][t])})}),-1!==a&&ln.splice(a,1),(o||T)&&(u?(n=se(u),T?Object.keys(this.tags).forEach(function(e){he(n.tags,e,r.tags[e])}):(he(n.tags,w,this),u!==n&&he(u.tags,w,this))):m(i,""),o&&!t&&o.removeChild(i)),this.__.virts&&E(this.__.virts,function(e){e.parentNode&&e.parentNode.removeChild(e)}),ce(g),E(d,function(e){return e.expr&&e.expr.unmount&&e.expr.unmount()}),this.__.onUnmount&&this.__.onUnmount(),f||(this.trigger("unmount"),this.off("*")),O(this,"isMounted",!1),delete this.root._tag,this}.bind(this))}function ie(e){return e.tagName&&hn[x(e,vn)||x(e,vn)||e.tagName.toLowerCase()]}function oe(e,t){var n=this;E(Object.keys(e),function(i){var o=!s(i)&&S(t,i);(r(n[i])||o)&&(o||t.push(i),n[i]=e[i])})}function ae(e,t){var n,r=this.parent;r&&(a(n=r.tags[e])?n.splice(t,0,n.splice(n.indexOf(this),1)[0]):le(r.tags,e,this))}function ue(e,t,n,r){var i=new re(e,t,n),o=t.tagName||fe(t.root,!0),a=se(r);return O(i,"parent",a),i.__.parent=r,le(a.tags,o,i),a!==r&&le(r.tags,o,i),i}function se(e){for(var t=e;t.__.isAnonymous&&t.parent;)t=t.parent;return t}function ce(e){E(e,function(e){e instanceof re?e.unmount(!0):e.tagName?e.tag.unmount(!0):e.unmount&&e.unmount()})}function fe(e,t){var n=ie(e),r=!t&&x(e,vn);return r&&!Wn.hasExpr(r)?r:n?n.name:e.tagName.toLowerCase()}function pe(e){if(!(e instanceof re||e&&t(e.trigger)))return e;var n={};for(var r in e)Cn.test(r)||(n[r]=e[r]);return n}function le(e,t,n,i,o){var u=e[t],s=a(u),c=!r(o);if(!u||u!==n)if(!u&&i)e[t]=[n];else if(u)if(s){var f=u.indexOf(n);if(f===o)return;-1!==f&&u.splice(f,1),c?u.splice(o,0,n):u.push(n)}else e[t]=[u,n];else e[t]=n}function he(e,t,n,r){if(a(e[t])){var i=e[t].indexOf(n);-1!==i&&e[t].splice(i,1),e[t].length?1!==e[t].length||r||(e[t]=e[t][0]):delete e[t]}else delete e[t]}function de(e,t,n,r){var i=hn[t],o=hn[t].class,a=r||(o?Object.create(o.prototype):{}),u=e._innerHTML=e._innerHTML||e.innerHTML,s=A({root:e,opts:n},{parent:n?n.parent:null});return i&&e&&re.apply(a,[i,s,u]),a&&a.mount&&(a.mount(!0),S(ln,a)||ln.push(a)),a}function me(e,t){var n=p();ye.call(e,n),t.parentNode.replaceChild(n,t)}function ye(e,t){var n,r,i=this,o=l(),a=l(),u=p();for(this.root.insertBefore(o,this.root.firstChild),this.root.appendChild(a),this.__.head=r=o,this.__.tail=a;r;)n=r.nextSibling,u.appendChild(r),i.__.virts.push(r),r=n;t?e.insertBefore(u,t.__.head):e.appendChild(u)}function ve(e,t){for(var n,r=this,i=this.__.head,o=p();i;)if(n=i.nextSibling,o.appendChild(i),(i=n)===r.__.tail){o.appendChild(i),e.insertBefore(o,t.__.head);break}}function ge(e){if(!e){var t=Object.keys(hn);return t+ge(t)}return e.filter(function(e){return!/[^-\w]/.test(e)}).reduce(function(e,t){var n=t.trim().toLowerCase();return e+",["+vn+'="'+n+'"]'},"")}function xe(e,t,n){return this.linenum=e,this.charnum=t,this.errormessage=n,this.stxerror=function(){console.log("Syntax Error\n","Line #",this.linenum,"\n","Near character #",this.charnum,"\n",this.errormessage)},this}function be(e,t,n,r){return this.linenum=e,this.charnum=t,this.errormessage=r,this.token=n,this}function we(e){return this.errormessage=e,this}function _e(e){return!!ze(e)||("Application"===e.exprType?void 0!==e.p?xr.flatten([_e(e.p),_e(e.func)]):xr.flatten([_e(e.func)]):"Name"===e.exprType||{failed:!0,stx:e})}function Te(e){for(var t=_e(e),n=0;n<t.length;n++)if(void 0!==t[n].failed&&t[n].failed)return t[n];return!0}function Ee(e,t,n,r){return this.bound_vars=e,this.free_vars=t,this.body=n,this.env=r,this.exprType="Closure",this}function Se(e,t){if(!e.every(function(e){return"Definition"===e.exprType||"FunctionDefinition"===e.exprType}))throw vr.JInternalError("let can only be used to bind things to names or functions");return this.exprType="Let",this.val=[e,t],this.pairs=e,this.body=t,this}function ke(e,t){return this.exprType="Unary",this.val=t,this.op=e,this}function Ne(e){return this.exprType="Integer",this.val=parseInt(e,10),this}function Oe(e){return this.exprType="Float",this.val=parseFloat(e,10),this}function Ae(e){return this.exprType="String",this.val=e,this}function je(e){return this.val="true"===e,this.exprType="Bool",this}function Ie(e){return this.xs=e,this.val=e,this.exprType="List",this}function Je(){return this.exprType="Nil",this}function Fe(e,t){return this.p=e,this.body=t,this.val=[e,t],this.exprType="Function",this}function Le(e){return this.op=e,this.val=this.op,this.exprType="Function",this}function Ce(e,t){return this.func=e,this.exprType="Application",t&&(this.p=t),this}function De(e){return this.ident=e,this.val=this.ident,this.exprType="Name",this}function Me(e,t){return this.ident=e,this.val=t,this.exprType="Definition",this}function Re(e,t,n){return this.ident=e,this.val=this.ident,this.params=t,this.body=n,this.exprType="FunctionDefinition",this}function Ue(e,t,n){return this.condition=e,this.thenexp=t,this.elseexp=n,this.exprType="If",this}function Be(e){return this.exprtype="TypeVar",this.name=e,this.exprType="TypeVar",this}function Pe(e){return this.name=e,this.val=e,this.exprType="TypeOperator",this}function ze(e){if(!e.exprType)throw vr.JInternalError(e);return"TypeOperator"===e.exprType||"TypeVar"===e.exprType||"TypeDeclaration"===e.exprType}function $e(e,t){if(Te(e)&&"Name"!==e.exprType)throw vr.JSyntaxError(e.linenum,e.charnum,"Left-hand-side of type declaration must not be in the type language");if(Te(t).failed)throw vr.JInternalError("Right-hand-side of type declaration must be a type expression");return this.expression=e,this.type=t,this.exprType="TypeDeclaration",this}function qe(e,t){if(Te(t).failed||!ze(e))throw vr.JSyntaxError(t.linenum,t.charnum,"Illegal type definition, both sides must be valid type expressions");return this.rhs=t,this.lhs=e,this.exprType="TypeDefinition",this}function Ve(e){if("Name"!==e.exprType)throw vr.JSyntaxError(e.linenum,e.charnum,"Expected a type variable (an identifier starting with a lowercase character), got "+e.val)}function He(e,t,n){if("TypeOperator"!==e.exprType)throw vr.JSyntaxError(e.linenum,e.charnum,"First element in a data type definition must be its name which is a type operator");if(xr.each(t,Ve),Te(n).failed)throw vr.JSyntaxError(n.linenum,n.charnum,"Body of a type definition must be a valid type expression");return this.name=e,this.params=t,this.type=n,this.exprType="TypeFuncDefinition",this}function Ke(e,t){return t?t.slice(1).reduce(function(e,t){return new Ce(e,t)},new Ce(e,t[0])):new Ce(e)}function We(e){return xr.size(e)<1}function Ge(e){return!e}function Ze(e,t){return e<t?1:e>t?-1:0}function Qe(e){return xr.groupBy(e.sort(),xr.isEqual)}function Xe(e){var t={};return e.map(function(e){t[e[0]]=e[1]}),t}function Ye(e,t){var n=xr.clone(e);return n.push.apply(n,t),n}function et(e){(e=xr.filter(e,function(e){return e.length>0})).sort(Ze);var t=e.reduce(function(e,t){return!t||t.length<1?"":e+"("+RegExp.escape(t)+")|"},""),n=new RegExp(t);return function(e){var t=n.exec(e);return!(xr.isNull(t)||!t[0])&&t[0]}}function tt(e){console.log("%j\n",e)}function nt(e){if(!e)return!1;var t=e.charCodeAt();return!isNaN(t)&&(47<t&&t<58)}function rt(e){if(!e)return!0;var t=e.charCodeAt();return!!isNaN(t)||(9===t||32===t||10===t||13===t||11===t)}function it(e){var t=e.charCodeAt();return!isNaN(t)&&41!==t&&40!==t&&125!==t&&123!==t&&93!==t&&91!==t&&44!==t&&34!==t&&t>32}function ot(e){var t=e.charCodeAt();return!isNaN(t)&&t>=65&&t<=90}function at(e,t,n){var r=[],i=e[0].charCodeAt(),o=!1,a=0;for(43===i||45===i?(r.push(e[0]),e=e.substr(1),a++):46===i&&(e=e.substr(1),a++,t++,r.push("0"),r.push("."),o=!0);nt(e[0])&&0!==e.length;)r.push(e[0]),e=e.substr(1),t++,a++;if("."===e[0]&&nt(e[1])){for(r.push("."),r.push(e[1]),e=e.substr(2),t++,t++,a++,a++;nt(e[0])&&0!==e.length;)r.push(e[0]),e=e.substr(1),a++,t++;return[a,["float",parseFloat(r.join(""),10),t,n]]}return o?[a,["float",parseFloat(r.join(""),10),t,n]]:[a,["integer",parseInt(r.join(""),10),t,n]]}function ut(e,t,n,r){for(var i=[],o=0;!rt(e[0])&&it(e[0])&&!t(e);)i.push(e[0]),e=e.substr(1),o++,n++;return i=i.join(""),[[o,["identifier",i,n,r]]]}function st(e,t,n,r){var i=ut(e,t,n,r);return i[0][1][0]="constructor",i}function ct(e,t,n){var r=[],i=1,o=t;for(e=e.substr(1);34!==e[0].charCodeAt();)if(r.push(e[0]),e=e.substr(1),i++,o++,e.length<1)throw vr.JSyntaxError(n,t,"Error: missing quotation mark");return i++,[i,["stringlit",r.join(""),o,n]]}function ft(e,t,n){if(e.length<4)return!1;var r=e.substr(0,4);return"then"===r?["thenexp","then"]:"true"===r&&["truelit","true"]}function pt(e,t,n,r,i){var o=n.length;return!(e.length<o)&&(e.substr(0,o)==n&&[t,n])}function lt(e,t){for(var n,r,i,o,a=[],u=1,s=1;e;)switch(e[0].charCodeAt()){case 59:for(;10!==e[0].charCodeAt();)e=e.substr(1);break;case 9:u++,a.push(["whitespace","\t",u,s]),e=e.substr(1);break;case 32:u++,a.push(["whitespace"," ",u,s]),e=e.substr(1);break;case 10:s++,u=1,a.push(["whitespace","\n",u,s]),e=e.substr(1);break;case 44:u++,a.push(["comma",",",u,s]),e=e.substr(1);break;case 40:u++,a.push(["left_paren","(",u,s]),e=e.substr(1);break;case 41:u++,a.push(["right_paren",")",u,s]),e=e.substr(1);break;case 123:u++,a.push(["left_brace","{",u,s]),e=e.substr(1);break;case 125:u++,a.push(["right_brace","}",u,s]),e=e.substr(1);break;case 91:u++,a.push(["left_square","[",u,s]),e=e.substr(1);break;case 93:u++,a.push(["right_square","]",u,s]),e=e.substr(1);break;case 34:var c=(r=ct(e,u,s))[1];n=r[0],a.push(c),e=e.substr(n);break;case 46:if(nt(e[1])){o=(r=at(e,u,s))[1],n=r[0],isNaN(o[1])||a.push(o),e=e.substr(n);break}case 116:if(r=ft(e)){a.push(Tr.extend(r,[u,s])),e=e.substr(4);break}case 105:var f=pt(e,"ifexp","if");if(f){a.push(Tr.extend(f,[u,s])),e=e.substr(2);break}var p=pt(e,"in","in ");if(p){a.push(Tr.extend(p,[u,s])),e=e.substr(3);break}case 100:if(pt(e,"defop","defop")){a.push(["defop","defop",u,s]),e=e.substr(5);break}if(pt(e,"deftype","deftype")){a.push(["deftype","deftype",u,s]),e=e.substr(7);break}if(pt(e,"def","def")){a.push(["def","def",u,s]),e=e.substr(3);break}case 101:if(r=pt(e,"elsexp","else")){a.push(Tr.extend(r,[u,s])),e=e.substr(4);break}case 102:if(r=pt(e,"falselit","false")){a.push(Tr.extend(r,[u,s])),e=e.substr(5);break}case 108:if(i=pt(e,"lambda","lambda")){a.push(Tr.extend(i,[u,s])),e=e.substr(6);break}var l=pt(e,"let","let");if(l){a.push(Tr.extend(l,[u,s])),e=e.substr(3);break}default:if(nt(e[0])){o=(r=at(e,u,s))[1],n=r[0],isNaN(o[1])||a.push(o),e=e.substr(n);break}var h=t(e);if(h){var d=h.length;u+=d,e=e.substr(d),a.push(["identifier",h,u,s])}else{r=ot(e[0])?st(e,t,u,s):ut(e,t,u,s);for(var m=0;m<r.length;m++)u++,a.push(r[m][1]),e=e.substr(r[m][0])}}return a}function ht(e,t,n){try{return lt(e,t).reverse().filter(function(e){return!n||"whitespace"!==e[0]})}catch(e){console.log(e.stxerror()),process.exit(1)}}function dt(e,t){return e===kr[t]}function mt(e){for(var t,n=ht(e=[Er.src,e].join(""),xr.constant(!1),!0).reverse(),r=0;r<n.length;r++)n.slice(r,r+8).map(xr.first).every(dt)&&(_r.OPInfo[n[r+5][1]]=[parseInt(n[r+1][1],10),n[r+2][1]]);return Sr=Object.keys(_r.OPInfo),t=Tr.opMatch(Sr),ht(e,t,!0)}function yt(e){return"Integer"==e.exprType||"Float"==e.exprType}function vt(e){if(e.xs.length<=0)return new _r.Nil;var t=Tt(e.xs[0]),n=e.xs.slice(1);return new _r.App(new _r.App(new _r.Name(":"),t),vt(new _r.ListT(n)))}function gt(e){return new _r.Def(e.ident,xt(e.params,e.body))}function xt(e,t){var n;return xr.isEmpty(e)?Tt(t):(n=new _r.FuncT(Tt(xr.first(e)),xt(xr.rest(e),t)),n.charnum=e.charnum,n.linenum=e.linenum,n)}function bt(e){var t=e.pairs.map(Tt);return new _r.LetExp(t,Tt(e.body))}function wt(e){var t,n;return t=e.p,n=Tt(e.func.p),n.linenum=e.linenum,n.charnum=e.charnum,new _r.TypeDecl(n,t)}function _t(e,t){var n,r=Tt(e.rhs);return t[e.lhs.name]=r,n=new _r.DefType(e.lhs,Tt(e.rhs)),n.linenum=e.linenum,n.charnum=e.charnum,n}function Tt(e,t){var n;switch(e.exprType){case"If":return e.elseexp?new _r.If(Tt(e.condition,t),Tt(e.thenexp,t),Tt(e.elseexp,t)):new _r.If(Tt(e.condition,t),Tt(e.thenexp,t));case"FunctionDefinition":return gt(e);case"Definition":return new _r.Def(e.ident,Tt(e.val,t));case"TypeDefinition":return _t(e,t);case"Name":return e;case"Application":if(void 0!==e.func.func&&"::"===e.func.func.ident){if(void 0!==(n=_r.isTypeExpr(e.p)).failed&&n.failed)throw vr.JInternalError("Type declaration error near line "+e.linenum+" at character #"+e.charnum+"\n"+n.stx.exprType+" ("+n.stx.val+") found where a type operator or type application was expected");return wt(e)}return"-"===e.func.ident&&e.p&&yt(e.p)?(console.log("Matched unary"),console.log(e),new _r.UnaryOp(Tt(e.func,t),Tt(e.p,t))):e.p?new _r.App(Tt(e.func,t),Tt(e.p,t)):new _r.App(e.func);case"Function":return xt(e.p,e.body);case"List":return vt(e);case"Bool":case"String":case"Float":case"Integer":return e;case"Let":return bt(e);default:return e}}function Et(e){switch(e.exprType){case"Integer":case"Float":case"String":case"Function":case"Nil":case"Bool":case"Let":return[];case"Unary":return xr.flatten([e.op.ident,Et(e.val)]);case"Definition":return xr.flatten(Et(e.val));case"Application":var t=xr.flatten(Et(e.p)),n=xr.flatten(Et(e.func));return xr.flatten([t,n]);case"If":if(e.elseexp){var r=Et(e.condition),i=Et(e.thenexp),o=Et(e.elseexp);return xr.flatten([r,i,o])}return xr.flatten([Et(e.condition),Et(e.thenexp)]);case"Name":return[e.ident]}}function St(e){if("Function"!==e.exprType&&"Let"!==e.exprType)throw vr.JInternalError(["Tried to calculate the free variables of","something that was not a function or let.\n","That something was a: "+e.exprType+"\n"].reduce(function(e,t){return e+" "+t},""));var t,n,r;switch(e.exprType){case"Let":r=e.pairs.map(function(e){return e.ident.ident});var i=e.pairs.map(Et),o=Et(e.body);t=xr.flatten(i),Tr.extend(t,xr.flatten(o));break;case"Function":r=[e.p.ident],t=Et(e.body)}return n=xr.difference(xr.uniq(t),r),new _r.Closure(r,n,e,[])}function kt(e){var t;switch(e.exprType){case"Let":return t=St(e),t.body.pairs=t.body.pairs.map(kt),t.body=kt(t.body.body),t;case"Function":return t=St(e),t.body.body=kt(t.body.body),t;case"Unary":return e.val=kt(e.val),e;case"Application":return e.func=kt(e.func),e.p=kt(e.p),e;case"If":return e.elseexp?(e.condition=kt(e.condition),e.thenexp=kt(e.thenexp),e.elseexp=kt(e.elseexp),e):(e.condition=kt(e.condition),e.thenexp=kt(e.thenexp),e);case"Definition":return e.val=kt(e.val),e;default:return e}}function Nt(e,t,n){return e&&0!==e.length?{linenum:At(e)[3],charnum:At(e)[2]}:{linenum:t,charnum:n}}function Ot(e,t,n,r){var i=Nt(t,n,r);return e.linenum=i.linenum,e.charnum=i.charnum,e}function At(e){return e[e.length-1]}function jt(e){return e[e.length-2]}function It(e,t,n,r){if(!At(e))throw vr.JSyntaxError(0,0,"unexpected end of source");var i=At(e)[0];return!t.some(function(e){return e===i})}function Jt(e){return function(t){return t&&e.some(function(e){return e(t)})}}function Ft(e){return function(t){return t[0]===e}}function Lt(e){return function(t){return t.exprType===e}}function Ct(e,t,n,r,i,o){if(!At(r))throw vr.JSyntaxError(i,o,"Unexpected end of source");At(r)[0];var a,u=[];if(!n(At(r)))throw vr.JSyntaxError(At(r)[3],At(r)[2],"Unexpected token: ``"+At(r)[0]+"''");if(a=e(r),u.push(a),r.length>1&&At(r)&&n(At(r)))for(;n(jt(r))&&n(At(r))&&(u.push(e(r)),t(At(u).exprType));){if(!At(r))throw vr.JSyntaxError(o,i,"Unexpected end of source");if(At(r)[0],r.length<=1)break}if(!At(r))throw vr.JSyntaxError(At(r)[3],At(r)[2],"unexpected end of source");return n(At(r))&&u.push(e(r)),u}function Dt(e,t,n,r,i){var o,a,u=Xt(n);if(!e(u))throw vr.JSyntaxError(At(n)[2],At(n)[3],"Unexpected token: ``"+At(n)[0]+"''");if(o=[u],n.length>1&&At(n)[0]===t){for(;At(n)[0]===t;){if(n.pop(),a=Xt(n),!At(n))throw vr.JSyntaxError(At(n)[3],At(n)[2],"Missing terminator: "+t);o.push(a)}return o}return o}function Mt(e,t,n){var r;if("right_square"===At(e)[0]?r=[]:"comma"===At(e)[0]?(e.pop(),r=[]):r=Dt(function(e){return!0},"comma",e,At(e)[3],At(e)[2]),!At(e)||"right_square"!==At(e)[0])throw vr.JSyntaxError(At(e)[3],At(e)[2],"list must be terminated by ]");return e.pop(),Ot(new _r.ListT(r),e,t,n)}function Rt(e,t,n){var r,i,o=Xt(e);if("Name"!==o.exprType)throw vr.JSyntaxError(t,n,"Expected an identifier in function definition");if(r="right_paren"===At(e)[0]?[]:Ct(Xt,Jr,Wt,e,n,t),!e||"right_paren"!==At(e)[0])throw vr.JSyntaxError(t,n,"Formal parameters must be followed by )");return e.pop(),i=Xt(e),Ot(new _r.DefFunc(o,r,i),e,i.linenum,i.charnum)}function Ut(e,t,n){var r,i;if(At(e)||vr.JSyntaxError(t,n,"Unexpected end of source"),r=Ct(zt,jr,Ir,e,n,t),At(e)&&"right_brace"!==At(e)[0])throw vr.JSyntaxError(At(e)[2],At(e)[3],"let/def form must have a closing }");if(!At(e))throw vr.JSyntaxError(xr.last(r).linenum,xr.last(r).charnum,"Unexpected end of source");if(e.pop(),e.length<=0)throw vr.JSyntaxError(xr.last(r).linenum,xr.last(r).charnum,"let/def form must have a body");if("Definition"===(i=Xt(e)).exprType||"FunctionDefinition"===i.exprType)throw vr.JSyntaxError(i.linenum,i.charnum,"Body of a let/def expression cannot be a definition");return Ot(new _r.LetExp(r,i),e,i.linenum,i.charnum)}function Bt(e,t,n){var r,i,o=Xt(e);if("Name"!=o.exprType)throw vr.JSyntaxError(At(e)[3],At(e)[2],"Expected an identifier in function definition");if(r="right_paren"===At(e)[0]?[]:Ct(Xt,Jr,Wt,e,n,t),"right_paren"!==At(e)[0])throw vr.JSyntaxError(t,n,"Formal parameters must be followed by )");if(e.pop(),"->"!==At(e)[1])throw vr.JSyntaxError(At(e)[3],At(e)[2],"Function parameters in let/def form must be followed by ->");return e.pop(),i=Xt(e),Ot(new _r.DefFunc(o,r,i),e,i.linenum,i.charnum)}function Pt(e,t,n){var r,i=Xt(e);if("Name"!=i.exprType)throw vr.JSyntaxError(i.linenum,i.charnum,"Expected an identifier in let/def binding");if(!At(e)||"="!==At(e)[1])throw vr.JSyntaxError(i.linenum,i.charnum,"An identifier in a let/def binding must be followed by ``=''");if(e.pop(),!It(e,["comma","arrow","right_brace","right_square"],i.linenum,i.charnum))throw vr.JSyntaxError(i.linenum,i.charnum,"The binding of "+identifier.val+" must not be followed by "+At(e)[0]);if("Definition"===(r=Xt(e)).exprType||"FunctionDefinition"===r.exprType)throw vr.JSyntaxError(r.linenum,r.charnum,"A definition cannot be the value of a binding");return Ot(new _r.Def(i,r),e,r.linenum,r.charnum)}function zt(e){var t=At(e)[3],n=At(e)[2];return At(e)&&"left_paren"===At(e)[0]?(e.pop(),Bt(e,t,n)):Pt(e,t,n)}function $t(e,t,n){var r,i=Xt(e,t,n);if("TypeOperator"!==i.exprType)throw vr.JSyntaxError(i.linenum,i.charnum,"Expected a type operator in data type definition");if("right_paren"!==At(e)[0])o=Ct(Xt,Jr,Wt,e,n,t);else var o=[];if(!e||"right_paren"!==At(e)[0])throw vr.JSyntaxError(xr.last(o).linenum,xr.last(o).charnum,"Data type parameters must be followed by )");return e.pop(),r=Xt(e),Ot(new _r.DataType(i,o,r),e,r.linenum,r.charnum)}function qt(e,t,n){var r,i;if(e.length<2)throw vr.JSyntaxError(t,n,"Unexpected end of source");if("left_paren"===At(e)[0])return e.pop(),$t(e,t,n);if(It(e,["constructor"],t,n))throw vr.JSyntaxError(t,n,"deftype must be followed by a single constructor if it is not a data type definition with type variables");if(i=Xt(e,t,n),!e)throw vr.JSyntaxError(i.linenum,i.charnum,"Unexpected end of source");if("TypeOperator"!==i.exprType)throw vr.JSyntaxError(i.linenum,i.charnum,"left-hand side of type alias was not a type operator");if("Application"!==(r=Xt(e,t,n)).exprType&&"TypeOperator"!==r.exprType)throw vr.JSyntaxError(r.linenum,r.charnum,"was expecting an application or type operator on the right-hand side of a type alias");return Ot(new _r.DefType(i,r),e,r.linenum,r.charnum)}function Vt(e,t,n){var r,i;if(e.length<2)throw vr.JSyntaxError(t,n,"Unexpected end of source");if("left_paren"===At(e)[0])return e.pop(),Rt(e,t,n);if("left_brace"===At(e)[0])return e.pop(),Ut(e,At(e)[3],At(e)[2]);if(It(e,["identifier"],t,n))throw vr.JSyntaxError(t,n,"def must be followed by identifier, not "+At(e)[0]);if(r=Xt(e),!At(e))throw vr.JSyntaxError(r.linenum,r.charnum,"Unexpected end of source");if(!It(e,["comma","arrow","right_brace","right_square"],r.linenum,r.charnum))throw vr.JSyntaxError(r.linenum,r.charnum,"def "+r.val+" must not be followed by "+At(e)[0]);if("Definition"===(i=Xt(e)).exprType||"FunctionDefinition"===i.exprType)throw vr.JSyntaxError(i.linenum,i.charnum,"A definition cannot be the value of a binding");return Ot(new _r.Def(r,i),e,i.linenum,i.charnum)}function Ht(e,t,n){var r,i;if("integer"!==At(e)[0]||At(e)[1]<1)throw vr.JSyntaxError(t,n,"defop must be followed by integer precedence >= 1");if(e.pop(),"Left"!==At(e)[1]&&"Right"!==At(e)[1])throw vr.JSyntaxError(t,n,"defop must be followed by precedence and then either Left or Right");if(e.pop(),"left_paren"!==At(e)[0])throw vr.JSyntaxError(t,n,"defop arguments must start with (");if(e.pop(),!e.slice(e.length-3,e.length).every(function(e){return"identifier"===e[0]}))throw vr.JSyntaxError(t,n,"defop must be surrounded by exactly 3 identifiers");if(i=e.slice(e.length-3,e.length),e.pop(),e.pop(),e.pop(),"right_paren"!==At(e)[0])throw vr.JSyntaxError(t,n,"defop pattern must be terminated with )");return e.pop(),(r=[new _r.Name(i[1][1]),new _r.Name(i[0][1]),new _r.Name(i[2][1])]).map(function(e){return e.linenum=t,e.charnum=n,e}),Ot(new _r.DefFunc(r[0],r.slice(1,3),Xt(e)),e,xr.last(r).linenum,xr.last(r).charnum)}function Kt(e,t,n){var r,i,o;if(It(e,["def","comma","lambda"],t,n)){if(r=Xt(e),At(e)&&"thenexp"===At(e)[0]){if(e.pop(),i=Xt(e),At(e)&&"elsexp"===At(e)[0]){if(e.pop(),xr.size(e)<1)throw vr.JSyntaxError(i.linenum,i.charnum,"Unexpected end of source");return o=Xt(e),Ot(new _r.If(r,i,o),e,o.linenum,o.charnum)}throw vr.JSyntaxError(i.linenum,i.charnum,"If expression must include an else variant")}throw vr.JSyntaxError(r.linenum,r.charnum,"if ``exp'' must be folowed by ``then'' exp, not "+jt(e)[0])}throw vr.JSyntaxError(t,n,"``if'' cannot be followed by "+At(e)[0])}function Wt(e){return"identifier"===e[0]&&"->"!==e[1]}function Gt(e,t,n){var r=Ct(Xt,Jr,Wt,e,n,t);if("->"!==At(e)[1])throw vr.JSyntaxError(xr.last(r).linenum,xr.last(r).charnum,"arrow must follow parameters in lambda, not "+At(e)[0]);e.pop();var i=Xt(e);return Ot(new _r.FuncT(r,i),e,i.linenum,i.charnum)}function Zt(e,t,n){var r,i,o,a=Xt(e);if(!At(e))throw vr.JSyntaxError(a.linenum,a.charnum,"Unexpected end of source");if(r=At(e),_r.OPInfo[r[1]]){if(i=Qt(e,1,a,a.linenum,a.charnum),At(e)&&"right_paren"===At(e)[0])return e.pop(),i;throw vr.JSyntaxError(a.linenum,a.charnum,"Mismatched parentheses or missing parenthesis on right-hand side")}if(o="right_paren"!==At(e)[0]?Ct(Xt,Cr,Lr,e,At(e)[2],At(e)[3]):[],At(e)&&"right_paren"===At(e)[0])return e.pop(),Ot(_r.makeApp(a,o),e,n,t);throw vr.JSyntaxError(At(e)[3],At(e)[2],"Mismatched parentheses or missing parenthesis on right-hand side")}function Qt(e,t,n,r,i){for(n||(n=Xt(e));;){var o=At(e);if(!o)throw vr.JSyntaxError(r,i,"Unexpected end of source");var a=_r.OPInfo[o[1]];if(!a||a[0]<t)break;var u=Ot(new _r.Name(o[1]),e,r,i),s=a[0],c="Left"===a[1]?s+1:s;e.pop();var f=Qt(e,c);n=Ot(_r.makeApp(u,[n,f]),e,f.linenum,f.charnum)}return n}function Xt(e){var t,n=At(e)[2],r=At(e)[3];At(e)?t=At(e)[0]:console.error("Tokenization error");var i=At(e)[1];if(e.pop(),"stringlit"===t)return Ot(new _r.StrT(i),e,r,n);if("left_square"===t)return Mt(e,r,n);if("lambda"===t)return Gt(e,r,n);if("integer"===t)return Ot(new _r.IntT(i),e,r,n);if("float"===t)return Ot(new _r.FloatT(i),e,r,n);if("identifier"===t)return Ot(new _r.Name(i),e,r,n);if("constructor"===t)return Ot(new _r.TypeOp(i),e,r,n);if("truelit"===t||"falselit"===t)return Ot(new _r.BoolT(i),e,r,n);if("def"===t||"let"===t)return Vt(e,r,n);if("deftype"===t)return qt(e,r,n);if("defop"===t)return Ht(e,r,n);if("ifexp"===t)return Kt(e,r,n);if("left_paren"===t){if("lambda"===At(e)[0]){e.pop();var o=Gt(e,r,n);return e.pop(),o}return Zt(e,r,n)}throw vr.JSyntaxError(r,n,"Unexpected token: ``"+t+"''")}function Yt(e){var t,n=[],r={};try{for(;e.length>0;)t=Ar.annotate_fvs(Or.desugar(Xt(e),r)),n.push(t);return{ast:n,types:r}}catch(e){void 0!==e.stxerror?(e.stxerror(),console.error("Tokenization error")):console.log(e.errormessage)}}function en(e,t){var n={};n.name=e,n.bindings={};for(var r=0;r<t.length;r++){e=t[r][0];var i=t[r][1];n.bindings[e]=i}return n}function tn(e,t){var n=t.bindings[e];if(!n)throw vr.JUnboundError(e,t.name);return n}function nn(e){return function(t){return"Nil"==t.exprType?[e]:(t.unshift(e),t)}}function rn(e,t){console.log("trying to look up "+e);var n=t.bindings[e];return console.log(n),void 0!==n.exprType?(console.log("evaluting further"),cn(n,t)):(console.log("returning it without evaluting"),n)}function on(e){var t=Dr.parseFull(Nr.tokenize(e));return console.log(t.ast[t.ast.length-1]),un(t.ast,Mr)}function an(e,t){return e(t)}function un(e,t){for(var n=e.length,r=[],i=0;i<n;i++)r.push(cn(e[i],t));return r[r.length-1]}function sn(e,t){t.bindings[e.ident.val]=cn(e.val,t)}function cn(e,t){if(console.log("here"),console.log(JSON.stringify(e)),"Application"==e.exprType)return an(n=cn(e.func,t),cn(e.p,t));if("Unary"===e.exprType){var n=cn(e.op,t);return an(n,cn(e.val,t))}return"Name"===e.exprType?rn(e.ident,t):"If"===e.exprType?cn(e.condition,t)?cn(e.thenexp,t):cn(e.elseexp,t):"Definition"===e.exprType?(sn(e,t),e):"Integer"===e.exprType||"Float"===e.exprType||"String"===e.exprType?e.val:(e.exprType,e)}var fn,pn,ln=[],hn={},dn="__global_mixin",mn="riot-",yn=["ref","data-ref"],vn="data-is",gn="if",xn="each",bn="no-reorder",wn="show",_n="hide",Tn="__riot-events__",En="string",Sn="object",kn="undefined",Nn="function",On="http://www.w3.org/1999/xlink",An="http://www.w3.org/2000/svg",jn=/^xlink:(\w+)/,In=typeof window===kn?void 0:window,Jn=/^(?:t(?:body|head|foot|[rhd])|caption|col(?:group)?|opt(?:ion|group))$/,Fn=/^(?:t(?:body|head|foot|[rhd])|caption|col(?:group)?)$/,Ln=/^on/,Cn=/^(?:_(?:item|id|parent)|update|root|(?:un)?mount|mixin|is(?:Mounted|Loop)|tags|refs|parent|opts|trigger|o(?:n|ff|ne))$/,Dn=/([-\w]+) ?= ?(?:"([^"]*)|'([^']*)|({[^}]*}))/g,Mn={viewbox:"viewBox"},Rn=/^(?:disabled|checked|readonly|required|allowfullscreen|auto(?:focus|play)|compact|controls|default|formnovalidate|hidden|ismap|itemscope|loop|multiple|muted|no(?:resize|shade|validate|wrap)?|open|reversed|seamless|selected|sortable|truespeed|typemustmatch)$/,Un=0|(In&&In.document||{}).documentMode,Bn=Object.freeze({isBoolAttr:e,isFunction:t,isObject:n,isUndefined:r,isString:i,isBlank:o,isArray:a,isWritable:u,isReservedName:s}),Pn=Object.freeze({$$:c,$:f,createFrag:p,createDOMPlaceholder:l,isSvg:h,mkEl:d,setInnerHTML:m,toggleVisibility:y,remAttr:v,styleObjectToString:g,getAttr:x,setAttr:b,safeInsert:w,walkAttrs:_,walkNodes:T}),zn={},$n=[],qn=!1;In&&(fn=function(){var e=d("style");b(e,"type","text/css");var t=f("style[type=riot]");return t?(t.id&&(e.id=t.id),t.parentNode.replaceChild(e,t)):document.getElementsByTagName("head")[0].appendChild(e),e}(),pn=fn.styleSheet);var Vn={styleNode:fn,add:function(e,t){t?zn[t]=e:$n.push(e),qn=!0},inject:function(){if(In&&qn){qn=!1;var e=Object.keys(zn).map(function(e){return zn[e]}).concat($n).join("\n");pn?pn.cssText=e:fn.innerHTML=e}}},Hn=function(){function e(e,t){for(;--t>=0&&/\s/.test(e[t]););return t}function t(t,u){var s=/.*/g,c=s.lastIndex=u++,f=s.exec(t)[0].match(o);if(f){var p=c+f[0].length,l=t[c=e(t,c)];if(c<0||~n.indexOf(l))return p;if("."===l)"."===t[c-1]&&(u=p);else if("+"===l||"-"===l)(t[--c]!==l||(c=e(t,c))<0||!a.test(t[c]))&&(u=p);else if(~i.indexOf(l)){for(var h=c+1;--c>=0&&a.test(t[c]););~r.indexOf(t.slice(c+1,h))&&(u=p)}}return u}var n="[{(,;:?=|&!^~>%*/",r=["case","default","do","else","in","instanceof","prefix","return","typeof","void","yield"],i=r.reduce(function(e,t){return e+t.slice(-1)},""),o=/^\/(?=[^*>/])[^[/\\]*(?:(?:\\.|\[(?:\\.|[^\]\\]*)*\])[^[\\/]*)*?\/[gimuy]*/,a=/[$\w]/;return t}(),Kn=function(e){function t(e){return e}function n(e,t){return t||(t=b),new RegExp(e.source.replace(/{/g,t[2]).replace(/}/g,t[3]),e.global?c:"")}function r(e){if(e===v)return g;var t=e.split(" ");if(2!==t.length||h.test(e))throw new Error('Unsupported brackets "'+e+'"');return t=t.concat(e.replace(d,"\\").split(" ")),t[4]=n(t[1].length>1?/{[\S\s]*?}/:g[4],t),t[5]=n(e.length>3?/\\({|})/g:g[5],t),t[6]=n(g[6],t),t[7]=RegExp("\\\\("+t[3]+")|([[({])|("+t[3]+")|"+m,c),t[8]=e,t}function i(e){return e instanceof RegExp?u(e):b[e]}function o(e){(e||(e=v))!==b[8]&&(b=r(e),u=e===v?t:n,b[9]=u(g[9])),x=e}function a(e){var t;t=(e=e||{}).brackets,Object.defineProperty(e,"brackets",{set:o,get:function(){return x},enumerable:!0}),s=e,o(t)}var u,s,c="g",f=/\/\*[^*]*\*+(?:[^*\/][^*]*\*+)*\//g,p=/"[^"\\]*(?:\\[\S\s][^"\\]*)*"|'[^'\\]*(?:\\[\S\s][^'\\]*)*'|`[^`\\]*(?:\\[\S\s][^`\\]*)*`/g,l=p.source+"|"+/(?:\breturn\s+|(?:[$\w\)\]]|\+\+|--)\s*(\/)(?![*\/]))/.source+"|"+/\/(?=[^*\/])[^[\/\\]*(?:(?:\[(?:\\.|[^\]\\]*)*\]|\\.)[^[\/\\]*)*?([^<]\/)[gim]*/.source,h=RegExp("[\\x00-\\x1F<>a-zA-Z0-9'\",;\\\\]"),d=/(?=[[\]()*+?.^$|])/g,m=p.source+"|"+/(\/)(?![*\/])/.source,y={"(":RegExp("([()])|"+m,c),"[":RegExp("([[\\]])|"+m,c),"{":RegExp("([{}])|"+m,c)},v="{ }",g=["{","}","{","}",/{[^}]*}/,/\\([{}])/g,/\\({)|{/g,RegExp("\\\\(})|([[({])|(})|"+m,c),v,/^\s*{\^?\s*([$\w]+)(?:\s*,\s*(\S+))?\s+in\s+(\S.*)\s*}/,/(^|[^\\]){=[\S\s]*?}/],x=void 0,b=[];return i.split=function(e,t,n){function r(e){d&&(e=d+e,d=""),t||a?p.push(e&&e.replace(n[5],"$1")):p.push(e)}function i(n,r,i){return i&&(r=Hn(e,n)),t&&r>n+2&&(c="⁗"+h.length+"~",h.push(e.slice(n,r)),d+=e.slice(u,n)+c,u=r),r}n||(n=b);var o,a,u,s,c,f,p=[],l=n[6],h=[],d="";for(a=u=l.lastIndex=0;o=l.exec(e);){if(f=l.lastIndex,s=o.index,a){if(o[2]){var m=o[2],v=y[m],g=1;for(v.lastIndex=f;o=v.exec(e);)if(o[1]){if(o[1]===m)++g;else if(!--g)break}else v.lastIndex=i(o.index,v.lastIndex,o[2]);l.lastIndex=g?e.length:v.lastIndex;continue}if(!o[3]){l.lastIndex=i(s,f,o[4]);continue}}o[1]||(r(e.slice(u,s)),u=l.lastIndex,(l=n[6+(a^=1)]).lastIndex=u)}return e&&u<e.length&&r(e.slice(u)),p.qblocks=h,p},i.hasExpr=function(e){return b[4].test(e)},i.loopKeys=function(e){var t=e.match(b[9]);return t?{key:t[1],pos:t[2],val:b[0]+t[3].trim()+b[1]}:{val:e.trim()}},i.array=function(e){return e?r(e):b},Object.defineProperty(i,"settings",{set:a,get:function(){return s}}),i.settings="undefined"!=typeof riot&&riot.settings||{},i.set=o,i.skipRegex=Hn,i.R_STRINGS=p,i.R_MLCOMMS=f,i.S_QBLOCKS=l,i.S_QBLOCK2=m,i}(),Wn=function(){function e(e,r){return e?(a[e]||(a[e]=n(e))).call(r,t.bind({data:r,tmpl:e})):e}function t(t,n){t.riotData={tagName:n&&n.__&&n.__.tagName,_riot_id:n&&n._riot_id},e.errorHandler?e.errorHandler(t):"undefined"!=typeof console&&"function"==typeof console.error&&(console.error(t.message),console.log("<%s> %s",t.riotData.tagName||"Unknown tag",this.tmpl),console.log(this.data))}function n(e){var t=r(e);return"try{return "!==t.slice(0,11)&&(t="return "+t),new Function("E",t+";")}function r(e){var t,n=Kn.split(e.replace(u,'"'),1),r=n.qblocks;if(n.length>2||n[0]){var o,a,c=[];for(o=a=0;o<n.length;++o)(t=n[o])&&(t=1&o?i(t,1,r):'"'+t.replace(/\\/g,"\\\\").replace(/\r\n?|\n/g,"\\n").replace(/"/g,'\\"')+'"')&&(c[a++]=t);t=a<2?c[0]:"["+c.join(",")+'].join("")'}else t=i(n[1],0,r);return r.length&&(t=t.replace(s,function(e,t){return r[t].replace(/\r/g,"\\r").replace(/\n/g,"\\n")})),t}function i(e,t,n){if(e=e.replace(/\s+/g," ").trim().replace(/\ ?([[\({},?\.:])\ ?/g,"$1")){for(var r,i=[],a=0;e&&(r=e.match(c))&&!r.index;){var u,s,p=/,|([[{(])|$/g;for(e=RegExp.rightContext,u=r[2]?n[r[2]].slice(1,-1).trim().replace(/\s+/g," "):r[1];s=(r=p.exec(e))[1];)!function(t,n){var r,i=1,o=f[t];for(o.lastIndex=n.lastIndex;r=o.exec(e);)if(r[0]===t)++i;else if(!--i)break;n.lastIndex=i?e.length:o.lastIndex}(s,p);s=e.slice(0,r.index),e=RegExp.rightContext,i[a++]=o(s,1,u)}e=a?a>1?"["+i.join(",")+'].join(" ").trim()':i[0]:o(e,t)}return e}function o(e,t,n){var r;return e=e.replace(l,function(e,t,n,i,o){return n&&(i=r?0:i+e.length,"this"!==n&&"global"!==n&&"window"!==n?(e=t+'("'+n+p+n,i&&(r="."===(o=o[i])||"("===o||"["===o)):i&&(r=!h.test(o.slice(i)))),e}),r&&(e="try{return "+e+"}catch(e){E(e,this)}"),n?e=(r?"function(){"+e+"}.call(this)":"("+e+")")+'?"'+n+'":""':t&&(e="function(v){"+(r?e.replace("return ","v="):"v=("+e+")")+';return v||v===0?v:""}.call(this)'),e}var a={};e.hasExpr=Kn.hasExpr,e.loopKeys=Kn.loopKeys,e.clearCache=function(){a={}},e.errorHandler=null;var u=/\u2057/g,s=/\u2057(\d+)~/g,c=/^(?:(-?[_A-Za-z\xA0-\xFF][-\w\xA0-\xFF]*)|\u2057(\d+)~):/,f={"(":/[()]/g,"[":/[[\]]/g,"{":/[{}]/g},p='"in this?this:'+("object"!=typeof window?"global":"window")+").",l=/[,{][\$\w]+(?=:)|(^ *|[^$\w\.{])(?!(?:typeof|true|false|null|undefined|in|instanceof|is(?:Finite|NaN)|void|NaN|new|Date|RegExp|Math)(?![$\w]))([$_A-Za-z][$\w]*)/g,h=/^(?=(\.[$\w]+))\1(?:[^.[(]|$)/;return e.version=Kn.version="v3.0.8",e}(),Gn=function(e){e=e||{};var t={},n=Array.prototype.slice;return Object.defineProperties(e,{on:{value:function(n,r){return"function"==typeof r&&(t[n]=t[n]||[]).push(r),e},enumerable:!1,writable:!1,configurable:!1},off:{value:function(n,r){if("*"!=n||r)if(r)for(var i,o=t[n],a=0;i=o&&o[a];++a)i==r&&o.splice(a--,1);else delete t[n];else t={};return e},enumerable:!1,writable:!1,configurable:!1},one:{value:function(t,n){function r(){e.off(t,r),n.apply(e,arguments)}return e.on(t,r)},enumerable:!1,writable:!1,configurable:!1},trigger:{value:function(r){var i,o,a,u=arguments,s=arguments.length-1,c=new Array(s);for(a=0;a<s;a++)c[a]=u[a+1];for(i=n.call(t[r]||[],0),a=0;o=i[a];++a)o.apply(e,c);return t["*"]&&"*"!=r&&e.trigger.apply(e,["*",r].concat(c)),e},enumerable:!1,writable:!1,configurable:!1}}),e},Zn=Object.freeze({each:E,contains:S,toCamel:k,startsWith:N,defineProperty:O,extend:A}),Qn=A(Object.create(Kn.settings),{skipAnonymousTags:!0,autoUpdate:!0}),Xn={init:function(e,t,n){v(e,gn),this.tag=t,this.expr=n,this.stub=l(),this.pristine=e;var r=e.parentNode;return r.insertBefore(this.stub,e),r.removeChild(e),this},update:function(){this.value=Wn(this.expr,this.tag),this.value&&!this.current?(this.current=this.pristine.cloneNode(!0),this.stub.parentNode.insertBefore(this.current,this.stub),this.expressions=[],q.apply(this.tag,[this.current,this.expressions,!0])):!this.value&&this.current&&(ce(this.expressions),this.current._tag?this.current._tag.unmount():this.current.parentNode&&this.current.parentNode.removeChild(this.current),this.current=null,this.expressions=[]),this.value&&C.call(this.tag,this.expressions)},unmount:function(){ce(this.expressions||[])}},Yn={init:function(e,t,n,r){return this.dom=e,this.attr=n,this.rawValue=r,this.parent=t,this.hasExp=Wn.hasExpr(r),this},update:function(){var e=this.value,t=this.parent&&se(this.parent),n=this.dom.__ref||this.tag||this.dom;this.value=this.hasExp?Wn(this.rawValue,this.parent):this.rawValue,!o(e)&&t&&he(t.refs,e,n),!o(this.value)&&i(this.value)?(t&&le(t.refs,this.value,n,null,this.parent.__.index),this.value!==e&&b(this.dom,this.attr,this.value)):v(this.dom,this.attr),this.dom.__ref||(this.dom.__ref=n)},unmount:function(){var e=this.tag||this.dom,t=this.parent&&se(this.parent);!o(this.value)&&t&&he(t.refs,this.value,e)}},er=/<yield\b/i,tr=/<yield\s*(?:\/>|>([\S\s]*?)<\/yield\s*>|>)/gi,nr=/<yield\s+to=['"]([^'">]*)['"]\s*>([\S\s]*?)<\/yield\s*>/gi,rr=/<yield\s+from=['"]?([-\w]+)['"]?\s*(?:\/>|>([\S\s]*?)<\/yield\s*>)/gi,ir={tr:"tbody",th:"tr",td:"tr",col:"colgroup"},or=Un&&Un<10?Jn:Fn,ar="div",ur="svg",sr={},cr=sr[dn]={},fr=0,pr=Object.freeze({Tag:G,tag:Z,tag2:Q,mount:X,mixin:Y,update:ee,unregister:te,version:"WIP"}),lr=0,hr=Object.freeze({getTag:ie,inheritFrom:oe,moveChildTag:ae,initChildTag:ue,getImmediateCustomParentTag:se,unmountAll:ce,getTagName:fe,cleanUpData:pe,arrayishAdd:le,arrayishRemove:he,mountTo:de,makeReplaceVirtual:me,makeVirtual:ye,moveVirtual:ve,selectTags:ge}),dr=Qn,mr={tmpl:Wn,brackets:Kn,styleManager:Vn,vdom:ln,styleNode:Vn.styleNode,dom:Pn,check:Bn,misc:Zn,tags:hr},yr=A({},pr,{observable:Gn,settings:dr,util:mr}),vr={JSyntaxError:xe,JTypeError:be,JInternalError:we},gr="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},xr=function(e,t){return t={exports:{}},e(t,t.exports),t.exports}(function(e,t){(function(){function n(e){function t(t,n,r,i,o,a){for(;o>=0&&o<a;o+=e){var u=i?i[o]:o;r=n(r,t[u],u,t)}return r}return function(n,r,i,o){r=w(r,o,4);var a=!O(n)&&b.keys(n),u=(a||n).length,s=e>0?0:u-1;return arguments.length<3&&(i=n[a?a[s]:s],s+=e),t(n,r,i,a,s,u)}}function r(e){return function(t,n,r){n=_(n,r);for(var i=N(t),o=e>0?0:i-1;o>=0&&o<i;o+=e)if(n(t[o],o,t))return o;return-1}}function i(e,t,n){return function(r,i,o){var a=0,u=N(r);if("number"==typeof o)e>0?a=o>=0?o:Math.max(o+u,a):u=o>=0?Math.min(o+1,u):o+u+1;else if(n&&o&&u)return o=n(r,i),r[o]===i?o:-1;if(i!==i)return o=t(l.call(r,a,u),b.isNaN),o>=0?o+a:-1;for(o=e>0?a:u-1;o>=0&&o<u;o+=e)if(r[o]===i)return o;return-1}}function o(e,t){var n=F.length,r=e.constructor,i=b.isFunction(r)&&r.prototype||c,o="constructor";for(b.has(e,o)&&!b.contains(t,o)&&t.push(o);n--;)(o=F[n])in e&&e[o]!==i[o]&&!b.contains(t,o)&&t.push(o)}var a=this,u=a._,s=Array.prototype,c=Object.prototype,f=Function.prototype,p=s.push,l=s.slice,h=c.toString,d=c.hasOwnProperty,m=Array.isArray,y=Object.keys,v=f.bind,g=Object.create,x=function(){},b=function(e){return e instanceof b?e:this instanceof b?void(this._wrapped=e):new b(e)};e.exports&&(t=e.exports=b),t._=b,b.VERSION="1.8.3";var w=function(e,t,n){if(void 0===t)return e;switch(null==n?3:n){case 1:return function(n){return e.call(t,n)};case 2:return function(n,r){return e.call(t,n,r)};case 3:return function(n,r,i){return e.call(t,n,r,i)};case 4:return function(n,r,i,o){return e.call(t,n,r,i,o)}}return function(){return e.apply(t,arguments)}},_=function(e,t,n){return null==e?b.identity:b.isFunction(e)?w(e,t,n):b.isObject(e)?b.matcher(e):b.property(e)};b.iteratee=function(e,t){return _(e,t,1/0)};var T=function(e,t){return function(n){var r=arguments,i=arguments.length;if(i<2||null==n)return n;for(var o=1;o<i;o++)for(var a=r[o],u=e(a),s=u.length,c=0;c<s;c++){var f=u[c];t&&void 0!==n[f]||(n[f]=a[f])}return n}},E=function(e){if(!b.isObject(e))return{};if(g)return g(e);x.prototype=e;var t=new x;return x.prototype=null,t},S=function(e){return function(t){return null==t?void 0:t[e]}},k=Math.pow(2,53)-1,N=S("length"),O=function(e){var t=N(e);return"number"==typeof t&&t>=0&&t<=k};b.each=b.forEach=function(e,t,n){t=w(t,n);var r,i;if(O(e))for(r=0,i=e.length;r<i;r++)t(e[r],r,e);else{var o=b.keys(e);for(r=0,i=o.length;r<i;r++)t(e[o[r]],o[r],e)}return e},b.map=b.collect=function(e,t,n){t=_(t,n);for(var r=!O(e)&&b.keys(e),i=(r||e).length,o=Array(i),a=0;a<i;a++){var u=r?r[a]:a;o[a]=t(e[u],u,e)}return o},b.reduce=b.foldl=b.inject=n(1),b.reduceRight=b.foldr=n(-1),b.find=b.detect=function(e,t,n){var r;if(void 0!==(r=O(e)?b.findIndex(e,t,n):b.findKey(e,t,n))&&-1!==r)return e[r]},b.filter=b.select=function(e,t,n){var r=[];return t=_(t,n),b.each(e,function(e,n,i){t(e,n,i)&&r.push(e)}),r},b.reject=function(e,t,n){return b.filter(e,b.negate(_(t)),n)},b.every=b.all=function(e,t,n){t=_(t,n);for(var r=!O(e)&&b.keys(e),i=(r||e).length,o=0;o<i;o++){var a=r?r[o]:o;if(!t(e[a],a,e))return!1}return!0},b.some=b.any=function(e,t,n){t=_(t,n);for(var r=!O(e)&&b.keys(e),i=(r||e).length,o=0;o<i;o++){var a=r?r[o]:o;if(t(e[a],a,e))return!0}return!1},b.contains=b.includes=b.include=function(e,t,n,r){return O(e)||(e=b.values(e)),("number"!=typeof n||r)&&(n=0),b.indexOf(e,t,n)>=0},b.invoke=function(e,t){var n=l.call(arguments,2),r=b.isFunction(t);return b.map(e,function(e){var i=r?t:e[t];return null==i?i:i.apply(e,n)})},b.pluck=function(e,t){return b.map(e,b.property(t))},b.where=function(e,t){return b.filter(e,b.matcher(t))},b.findWhere=function(e,t){return b.find(e,b.matcher(t))},b.max=function(e,t,n){var r,i,o=-1/0,a=-1/0;if(null==t&&null!=e)for(var u=0,s=(e=O(e)?e:b.values(e)).length;u<s;u++)(r=e[u])>o&&(o=r);else t=_(t,n),b.each(e,function(e,n,r){((i=t(e,n,r))>a||i===-1/0&&o===-1/0)&&(o=e,a=i)});return o},b.min=function(e,t,n){var r,i,o=1/0,a=1/0;if(null==t&&null!=e)for(var u=0,s=(e=O(e)?e:b.values(e)).length;u<s;u++)(r=e[u])<o&&(o=r);else t=_(t,n),b.each(e,function(e,n,r){((i=t(e,n,r))<a||i===1/0&&o===1/0)&&(o=e,a=i)});return o},b.shuffle=function(e){for(var t,n=O(e)?e:b.values(e),r=n.length,i=Array(r),o=0;o<r;o++)(t=b.random(0,o))!==o&&(i[o]=i[t]),i[t]=n[o];return i},b.sample=function(e,t,n){return null==t||n?(O(e)||(e=b.values(e)),e[b.random(e.length-1)]):b.shuffle(e).slice(0,Math.max(0,t))},b.sortBy=function(e,t,n){return t=_(t,n),b.pluck(b.map(e,function(e,n,r){return{value:e,index:n,criteria:t(e,n,r)}}).sort(function(e,t){var n=e.criteria,r=t.criteria;if(n!==r){if(n>r||void 0===n)return 1;if(n<r||void 0===r)return-1}return e.index-t.index}),"value")};var A=function(e){return function(t,n,r){var i={};return n=_(n,r),b.each(t,function(r,o){var a=n(r,o,t);e(i,r,a)}),i}};b.groupBy=A(function(e,t,n){b.has(e,n)?e[n].push(t):e[n]=[t]}),b.indexBy=A(function(e,t,n){e[n]=t}),b.countBy=A(function(e,t,n){b.has(e,n)?e[n]++:e[n]=1}),b.toArray=function(e){return e?b.isArray(e)?l.call(e):O(e)?b.map(e,b.identity):b.values(e):[]},b.size=function(e){return null==e?0:O(e)?e.length:b.keys(e).length},b.partition=function(e,t,n){t=_(t,n);var r=[],i=[];return b.each(e,function(e,n,o){(t(e,n,o)?r:i).push(e)}),[r,i]},b.first=b.head=b.take=function(e,t,n){if(null!=e)return null==t||n?e[0]:b.initial(e,e.length-t)},b.initial=function(e,t,n){return l.call(e,0,Math.max(0,e.length-(null==t||n?1:t)))},b.last=function(e,t,n){if(null!=e)return null==t||n?e[e.length-1]:b.rest(e,Math.max(0,e.length-t))},b.rest=b.tail=b.drop=function(e,t,n){return l.call(e,null==t||n?1:t)},b.compact=function(e){return b.filter(e,b.identity)};var j=function(e,t,n,r){for(var i=[],o=0,a=r||0,u=N(e);a<u;a++){var s=e[a];if(O(s)&&(b.isArray(s)||b.isArguments(s))){t||(s=j(s,t,n));var c=0,f=s.length;for(i.length+=f;c<f;)i[o++]=s[c++]}else n||(i[o++]=s)}return i};b.flatten=function(e,t){return j(e,t,!1)},b.without=function(e){return b.difference(e,l.call(arguments,1))},b.uniq=b.unique=function(e,t,n,r){b.isBoolean(t)||(r=n,n=t,t=!1),null!=n&&(n=_(n,r));for(var i=[],o=[],a=0,u=N(e);a<u;a++){var s=e[a],c=n?n(s,a,e):s;t?(a&&o===c||i.push(s),o=c):n?b.contains(o,c)||(o.push(c),i.push(s)):b.contains(i,s)||i.push(s)}return i},b.union=function(){return b.uniq(j(arguments,!0,!0))},b.intersection=function(e){for(var t=arguments,n=[],r=arguments.length,i=0,o=N(e);i<o;i++){var a=e[i];if(!b.contains(n,a)){for(var u=1;u<r&&b.contains(t[u],a);u++);u===r&&n.push(a)}}return n},b.difference=function(e){var t=j(arguments,!0,!0,1);return b.filter(e,function(e){return!b.contains(t,e)})},b.zip=function(){return b.unzip(arguments)},b.unzip=function(e){for(var t=e&&b.max(e,N).length||0,n=Array(t),r=0;r<t;r++)n[r]=b.pluck(e,r);return n},b.object=function(e,t){for(var n={},r=0,i=N(e);r<i;r++)t?n[e[r]]=t[r]:n[e[r][0]]=e[r][1];return n},b.findIndex=r(1),b.findLastIndex=r(-1),b.sortedIndex=function(e,t,n,r){for(var i=(n=_(n,r,1))(t),o=0,a=N(e);o<a;){var u=Math.floor((o+a)/2);n(e[u])<i?o=u+1:a=u}return o},b.indexOf=i(1,b.findIndex,b.sortedIndex),b.lastIndexOf=i(-1,b.findLastIndex),b.range=function(e,t,n){null==t&&(t=e||0,e=0),n=n||1;for(var r=Math.max(Math.ceil((t-e)/n),0),i=Array(r),o=0;o<r;o++,e+=n)i[o]=e;return i};var I=function(e,t,n,r,i){if(!(r instanceof t))return e.apply(n,i);var o=E(e.prototype),a=e.apply(o,i);return b.isObject(a)?a:o};b.bind=function(e,t){if(v&&e.bind===v)return v.apply(e,l.call(arguments,1));if(!b.isFunction(e))throw new TypeError("Bind must be called on a function");var n=l.call(arguments,2),r=function(){return I(e,r,t,this,n.concat(l.call(arguments)))};return r},b.partial=function(e){var t=l.call(arguments,1),n=function(){for(var r=arguments,i=0,o=t.length,a=Array(o),u=0;u<o;u++)a[u]=t[u]===b?r[i++]:t[u];for(;i<arguments.length;)a.push(r[i++]);return I(e,n,this,this,a)};return n},b.bindAll=function(e){var t,n,r=arguments,i=arguments.length;if(i<=1)throw new Error("bindAll must be passed function names");for(t=1;t<i;t++)e[n=r[t]]=b.bind(e[n],e);return e},b.memoize=function(e,t){var n=function(r){var i=n.cache,o=""+(t?t.apply(this,arguments):r);return b.has(i,o)||(i[o]=e.apply(this,arguments)),i[o]};return n.cache={},n},b.delay=function(e,t){var n=l.call(arguments,2);return setTimeout(function(){return e.apply(null,n)},t)},b.defer=b.partial(b.delay,b,1),b.throttle=function(e,t,n){var r,i,o,a=null,u=0;n||(n={});var s=function(){u=!1===n.leading?0:b.now(),a=null,o=e.apply(r,i),a||(r=i=null)};return function(){var c=b.now();u||!1!==n.leading||(u=c);var f=t-(c-u);return r=this,i=arguments,f<=0||f>t?(a&&(clearTimeout(a),a=null),u=c,o=e.apply(r,i),a||(r=i=null)):a||!1===n.trailing||(a=setTimeout(s,f)),o}},b.debounce=function(e,t,n){var r,i,o,a,u,s=function(){var c=b.now()-a;c<t&&c>=0?r=setTimeout(s,t-c):(r=null,n||(u=e.apply(o,i),r||(o=i=null)))};return function(){o=this,i=arguments,a=b.now();var c=n&&!r;return r||(r=setTimeout(s,t)),c&&(u=e.apply(o,i),o=i=null),u}},b.wrap=function(e,t){return b.partial(t,e)},b.negate=function(e){return function(){return!e.apply(this,arguments)}},b.compose=function(){var e=arguments,t=e.length-1;return function(){for(var n=this,r=t,i=e[t].apply(this,arguments);r--;)i=e[r].call(n,i);return i}},b.after=function(e,t){return function(){if(--e<1)return t.apply(this,arguments)}},b.before=function(e,t){var n;return function(){return--e>0&&(n=t.apply(this,arguments)),e<=1&&(t=null),n}},b.once=b.partial(b.before,2);var J=!{toString:null}.propertyIsEnumerable("toString"),F=["valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"];b.keys=function(e){if(!b.isObject(e))return[];if(y)return y(e);var t=[];for(var n in e)b.has(e,n)&&t.push(n);return J&&o(e,t),t},b.allKeys=function(e){if(!b.isObject(e))return[];var t=[];for(var n in e)t.push(n);return J&&o(e,t),t},b.values=function(e){for(var t=b.keys(e),n=t.length,r=Array(n),i=0;i<n;i++)r[i]=e[t[i]];return r},b.mapObject=function(e,t,n){t=_(t,n);for(var r,i=b.keys(e),o=i.length,a={},u=0;u<o;u++)a[r=i[u]]=t(e[r],r,e);return a},b.pairs=function(e){for(var t=b.keys(e),n=t.length,r=Array(n),i=0;i<n;i++)r[i]=[t[i],e[t[i]]];return r},b.invert=function(e){for(var t={},n=b.keys(e),r=0,i=n.length;r<i;r++)t[e[n[r]]]=n[r];return t},b.functions=b.methods=function(e){var t=[];for(var n in e)b.isFunction(e[n])&&t.push(n);return t.sort()},b.extend=T(b.allKeys),b.extendOwn=b.assign=T(b.keys),b.findKey=function(e,t,n){t=_(t,n);for(var r,i=b.keys(e),o=0,a=i.length;o<a;o++)if(r=i[o],t(e[r],r,e))return r},b.pick=function(e,t,n){var r,i,o={},a=e;if(null==a)return o;b.isFunction(t)?(i=b.allKeys(a),r=w(t,n)):(i=j(arguments,!1,!1,1),r=function(e,t,n){return t in n},a=Object(a));for(var u=0,s=i.length;u<s;u++){var c=i[u],f=a[c];r(f,c,a)&&(o[c]=f)}return o},b.omit=function(e,t,n){if(b.isFunction(t))t=b.negate(t);else{var r=b.map(j(arguments,!1,!1,1),String);t=function(e,t){return!b.contains(r,t)}}return b.pick(e,t,n)},b.defaults=T(b.allKeys,!0),b.create=function(e,t){var n=E(e);return t&&b.extendOwn(n,t),n},b.clone=function(e){return b.isObject(e)?b.isArray(e)?e.slice():b.extend({},e):e},b.tap=function(e,t){return t(e),e},b.isMatch=function(e,t){var n=b.keys(t),r=n.length;if(null==e)return!r;for(var i=Object(e),o=0;o<r;o++){var a=n[o];if(t[a]!==i[a]||!(a in i))return!1}return!0};var L=function(e,t,n,r){if(e===t)return 0!==e||1/e==1/t;if(null==e||null==t)return e===t;e instanceof b&&(e=e._wrapped),t instanceof b&&(t=t._wrapped);var i=h.call(e);if(i!==h.call(t))return!1;switch(i){case"[object RegExp]":case"[object String]":return""+e==""+t;case"[object Number]":return+e!=+e?+t!=+t:0==+e?1/+e==1/t:+e==+t;case"[object Date]":case"[object Boolean]":return+e==+t}var o="[object Array]"===i;if(!o){if("object"!=typeof e||"object"!=typeof t)return!1;var a=e.constructor,u=t.constructor;if(a!==u&&!(b.isFunction(a)&&a instanceof a&&b.isFunction(u)&&u instanceof u)&&"constructor"in e&&"constructor"in t)return!1}n=n||[],r=r||[];for(var s=n.length;s--;)if(n[s]===e)return r[s]===t;if(n.push(e),r.push(t),o){if((s=e.length)!==t.length)return!1;for(;s--;)if(!L(e[s],t[s],n,r))return!1}else{var c,f=b.keys(e);if(s=f.length,b.keys(t).length!==s)return!1;for(;s--;)if(c=f[s],!b.has(t,c)||!L(e[c],t[c],n,r))return!1}return n.pop(),r.pop(),!0};b.isEqual=function(e,t){return L(e,t)},b.isEmpty=function(e){return null==e||(O(e)&&(b.isArray(e)||b.isString(e)||b.isArguments(e))?0===e.length:0===b.keys(e).length)},b.isElement=function(e){return!(!e||1!==e.nodeType)},b.isArray=m||function(e){return"[object Array]"===h.call(e)},b.isObject=function(e){var t=typeof e;return"function"===t||"object"===t&&!!e},b.each(["Arguments","Function","String","Number","Date","RegExp","Error"],function(e){b["is"+e]=function(t){return h.call(t)==="[object "+e+"]"}}),b.isArguments(arguments)||(b.isArguments=function(e){return b.has(e,"callee")}),"function"!=typeof/./&&"object"!=typeof Int8Array&&(b.isFunction=function(e){return"function"==typeof e||!1}),b.isFinite=function(e){return isFinite(e)&&!isNaN(parseFloat(e))},b.isNaN=function(e){return b.isNumber(e)&&e!==+e},b.isBoolean=function(e){return!0===e||!1===e||"[object Boolean]"===h.call(e)},b.isNull=function(e){return null===e},b.isUndefined=function(e){return void 0===e},b.has=function(e,t){return null!=e&&d.call(e,t)},b.noConflict=function(){return a._=u,this},b.identity=function(e){return e},b.constant=function(e){return function(){return e}},b.noop=function(){},b.property=S,b.propertyOf=function(e){return null==e?function(){}:function(t){return e[t]}},b.matcher=b.matches=function(e){return e=b.extendOwn({},e),function(t){return b.isMatch(t,e)}},b.times=function(e,t,n){var r=Array(Math.max(0,e));t=w(t,n,1);for(var i=0;i<e;i++)r[i]=t(i);return r},b.random=function(e,t){return null==t&&(t=e,e=0),e+Math.floor(Math.random()*(t-e+1))},b.now=Date.now||function(){return(new Date).getTime()};var C={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},D=b.invert(C),M=function(e){var t=function(t){return e[t]},n="(?:"+b.keys(e).join("|")+")",r=RegExp(n),i=RegExp(n,"g");return function(e){return e=null==e?"":""+e,r.test(e)?e.replace(i,t):e}};b.escape=M(C),b.unescape=M(D),b.result=function(e,t,n){var r=null==e?void 0:e[t];return void 0===r&&(r=n),b.isFunction(r)?r.call(e):r};var R=0;b.uniqueId=function(e){var t=++R+"";return e?e+t:t},b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var U=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},P=/\\|'|\r|\n|\u2028|\u2029/g,z=function(e){return"\\"+B[e]};b.template=function(e,t,n){!t&&n&&(t=n),t=b.defaults({},t,b.templateSettings);var r=RegExp([(t.escape||U).source,(t.interpolate||U).source,(t.evaluate||U).source].join("|")+"|$","g"),i=0,o="__p+='";e.replace(r,function(t,n,r,a,u){return o+=e.slice(i,u).replace(P,z),i=u+t.length,n?o+="'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":r?o+="'+\n((__t=("+r+"))==null?'':__t)+\n'":a&&(o+="';\n"+a+"\n__p+='"),t}),o+="';\n",t.variable||(o="with(obj||{}){\n"+o+"}\n"),o="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+o+"return __p;\n";try{var a=new Function(t.variable||"obj","_",o)}catch(e){throw e.source=o,e}var u=function(e){return a.call(this,e,b)},s=t.variable||"obj";return u.source="function("+s+"){\n"+o+"}",u},b.chain=function(e){var t=b(e);return t._chain=!0,t};var $=function(e,t){return e._chain?b(t).chain():t};b.mixin=function(e){b.each(b.functions(e),function(t){var n=b[t]=e[t];b.prototype[t]=function(){var e=[this._wrapped];return p.apply(e,arguments),$(this,n.apply(b,e))}})},b.mixin(b),b.each(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=s[e];b.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),"shift"!==e&&"splice"!==e||0!==n.length||delete n[0],$(this,n)}}),b.each(["concat","join","slice"],function(e){var t=s[e];b.prototype[e]=function(){return $(this,t.apply(this._wrapped,arguments))}}),b.prototype.value=function(){return this._wrapped},b.prototype.valueOf=b.prototype.toJSON=b.prototype.value,b.prototype.toString=function(){return""+this._wrapped}}).call(gr)}),br={display:function(){return this.exprType+" "+this.val},type:function(){return this.exprType},linenum:0,charnum:0},wr={unify:function(e){if(this.expr===e.expr)return e.expr;console.log("Could not unify "+this.expr+" with "+e.expr)},isTypeExpr:!0,linenum:0,charnum:0};Se.prototype=br,ke.prototype=br,Ne.prototype=br,Oe.prototype=br,Ae.prototype=br,je.prototype=br,Ie.prototype=br,Je.prototype=br,Fe.prototype=br,Le.prototype=br,Ce.prototype=br,De.prototype=br,Me.prototype=br,Re.prototype=br,Ue.prototype=br,Be.prototype=wr,Pe.prototype=wr,$e.prototype=wr,qe.prototype=br;var _r={IntT:Ne,FloatT:Oe,StrT:Ae,BoolT:je,ListT:Ie,FuncT:Fe,App:Ce,Name:De,Def:Me,OpT:Le,OPInfo:{"::":[2,"Left"],",":[1,"Left"],"->":[1,"Right"]},makeApp:Ke,If:Ue,DefFunc:Re,UnaryOp:ke,Nil:Je,LetExp:Se,gensym:function(){var e=0;return function(){var t="G"+e;return e+=1,t}}(),TypeVar:Be,TypeOp:Pe,TypeDecl:$e,Closure:Ee,isTypeExpr:Te,DefType:qe,DataType:He};RegExp.escape=function(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")};var Tr={not:Ge,groupOps:Qe,opMatch:et,dict:Xe,extend:Ye,empty:We,debugPrint:tt},Er={src:"\n;; This file declares the various types used by intrinsic/prelude definitions\n;; It is sort of special in that it doesn't care whether there are any associated definitions\n;; just that there are type definitions for that particular binding's name\n"},Sr=Object.keys(_r.OPInfo),kr=["defop","integer","constructor","left_paren","identifier","identifier","identifier","right_paren"],Nr={tokenize:mt,isIdentifier:it},Or={desugar:Tt},Ar=(xr.compose(Tr.not,xr.partial(xr.equal,[])),{annotate_fvs:kt}),jr=Jt(["Definition","FunctionDefinition"].map(Lt)),Ir=xr.compose(Tr.not,Jt(["right_brace"].map(Ft))),Jr=Jt(["Name"].map(Lt)),Fr=["def","comma","right_paren","right_square","right_brace","left_brace","right_brace"].map(Ft),Lr=xr.compose(Tr.not,Jt(Fr)),Cr=xr.compose(Tr.not,Jt(["Definition"].map(Lt))),Dr={parse:function(e){return Yt(Nr.tokenize(e))},tokenize:Nr.tokenize,parseFull:Yt},Mr={lookup:tn,makeEnv:en}.makeEnv("toplevel",[["len",function(e){return e.length}],["+",function(e){return function(t){return e+t}}],["*",function(e){return function(t){return e*t}}],["-",function(e){return function(t){return e-t}}],["/",function(e){return function(t){return e/t}}],[":",nn],["a",2],["b",3]]),Rr={evaluateString:on};yr.tag2("test",'<textarea ref="input" type="text"> </textarea> <button onclick="{evaluate}"> Evaluate it </button> <p> {output} </p>',"","",function(e){var t=this;t.output="",this.evaluate=function(){var e=this.refs.input;t.update({output:JSON.stringify(Rr.evaluateString(e.value))})}.bind(this)}),yr.mount("test")}();