"!==k[1]||lb.test(f)?0:h:h.firstChild,e=f&&f.childNodes.length;while(e--)n.nodeName(j=f.childNodes[e],"tbody")&&!j.childNodes.length&&f.removeChild(j)}n.merge(p,h.childNodes),h.textContent="";while(h.firstChild)h.removeChild(h.firstChild);h=o.lastChild}else p.push(b.createTextNode(f));h&&o.removeChild(h),l.appendChecked||n.grep(vb(p,"input"),wb),q=0;while(f=p[q++])if((!d||-1===n.inArray(f,d))&&(g=n.contains(f.ownerDocument,f),h=vb(o.appendChild(f),"script"),g&&Ab(h),c)){e=0;while(f=h[e++])pb.test(f.type||"")&&c.push(f)}return h=null,o},cleanData:function(a,b){for(var d,e,f,g,h=0,i=n.expando,j=n.cache,k=l.deleteExpando,m=n.event.special;null!=(d=a[h]);h++)if((b||n.acceptData(d))&&(f=d[i],g=f&&j[f])){if(g.events)for(e in g.events)m[e]?n.event.remove(d,e):n.removeEvent(d,e,g.handle);j[f]&&(delete j[f],k?delete d[i]:typeof d.removeAttribute!==L?d.removeAttribute(i):d[i]=null,c.push(f))}}}),n.fn.extend({text:function(a){return W(this,function(a){return void 0===a?n.text(this):this.empty().append((this[0]&&this[0].ownerDocument||z).createTextNode(a))},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=xb(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=xb(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?n.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||n.cleanData(vb(c)),c.parentNode&&(b&&n.contains(c.ownerDocument,c)&&Ab(vb(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++){1===a.nodeType&&n.cleanData(vb(a,!1));while(a.firstChild)a.removeChild(a.firstChild);a.options&&n.nodeName(a,"select")&&(a.options.length=0)}return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return n.clone(this,a,b)})},html:function(a){return W(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a)return 1===b.nodeType?b.innerHTML.replace(gb,""):void 0;if(!("string"!=typeof a||nb.test(a)||!l.htmlSerialize&&hb.test(a)||!l.leadingWhitespace&&ib.test(a)||sb[(kb.exec(a)||["",""])[1].toLowerCase()])){a=a.replace(jb,"<$1>$2>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(n.cleanData(vb(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,n.cleanData(vb(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,k=this.length,m=this,o=k-1,p=a[0],q=n.isFunction(p);if(q||k>1&&"string"==typeof p&&!l.checkClone&&ob.test(p))return this.each(function(c){var d=m.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(k&&(i=n.buildFragment(a,this[0].ownerDocument,!1,this),c=i.firstChild,1===i.childNodes.length&&(i=c),c)){for(g=n.map(vb(i,"script"),yb),f=g.length;k>j;j++)d=i,j!==o&&(d=n.clone(d,!0,!0),f&&n.merge(g,vb(d,"script"))),b.call(this[j],d,j);if(f)for(h=g[g.length-1].ownerDocument,n.map(g,zb),j=0;f>j;j++)d=g[j],pb.test(d.type||"")&&!n._data(d,"globalEval")&&n.contains(h,d)&&(d.src?n._evalUrl&&n._evalUrl(d.src):n.globalEval((d.text||d.textContent||d.innerHTML||"").replace(rb,"")));i=c=null}return this}}),n.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){n.fn[a]=function(a){for(var c,d=0,e=[],g=n(a),h=g.length-1;h>=d;d++)c=d===h?this:this.clone(!0),n(g[d])[b](c),f.apply(e,c.get());return this.pushStack(e)}});var Db,Eb={};function Fb(b,c){var d=n(c.createElement(b)).appendTo(c.body),e=a.getDefaultComputedStyle?a.getDefaultComputedStyle(d[0]).display:n.css(d[0],"display");return d.detach(),e}function Gb(a){var b=z,c=Eb[a];return c||(c=Fb(a,b),"none"!==c&&c||(Db=(Db||n("")).appendTo(b.documentElement),b=(Db[0].contentWindow||Db[0].contentDocument).document,b.write(),b.close(),c=Fb(a,b),Db.detach()),Eb[a]=c),c}!function(){var a,b,c=z.createElement("div"),d="-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;display:block;padding:0;margin:0;border:0";c.innerHTML=" a ",a=c.getElementsByTagName("a")[0],a.style.cssText="float:left;opacity:.5",l.opacity=/^0.5/.test(a.style.opacity),l.cssFloat=!!a.style.cssFloat,c.style.backgroundClip="content-box",c.cloneNode(!0).style.backgroundClip="",l.clearCloneStyle="content-box"===c.style.backgroundClip,a=c=null,l.shrinkWrapBlocks=function(){var a,c,e,f;if(null==b){if(a=z.getElementsByTagName("body")[0],!a)return;f="border:0;width:0;height:0;position:absolute;top:0;left:-9999px",c=z.createElement("div"),e=z.createElement("div"),a.appendChild(c).appendChild(e),b=!1,typeof e.style.zoom!==L&&(e.style.cssText=d+";width:1px;padding:1px;zoom:1",e.innerHTML="
",e.firstChild.style.width="5px",b=3!==e.offsetWidth),a.removeChild(c),a=c=e=null}return b}}();var Hb=/^margin/,Ib=new RegExp("^("+T+")(?!px)[a-z%]+$","i"),Jb,Kb,Lb=/^(top|right|bottom|left)$/;a.getComputedStyle?(Jb=function(a){return a.ownerDocument.defaultView.getComputedStyle(a,null)},Kb=function(a,b,c){var d,e,f,g,h=a.style;return c=c||Jb(a),g=c?c.getPropertyValue(b)||c[b]:void 0,c&&(""!==g||n.contains(a.ownerDocument,a)||(g=n.style(a,b)),Ib.test(g)&&Hb.test(b)&&(d=h.width,e=h.minWidth,f=h.maxWidth,h.minWidth=h.maxWidth=h.width=g,g=c.width,h.width=d,h.minWidth=e,h.maxWidth=f)),void 0===g?g:g+""}):z.documentElement.currentStyle&&(Jb=function(a){return a.currentStyle},Kb=function(a,b,c){var d,e,f,g,h=a.style;return c=c||Jb(a),g=c?c[b]:void 0,null==g&&h&&h[b]&&(g=h[b]),Ib.test(g)&&!Lb.test(b)&&(d=h.left,e=a.runtimeStyle,f=e&&e.left,f&&(e.left=a.currentStyle.left),h.left="fontSize"===b?"1em":g,g=h.pixelLeft+"px",h.left=d,f&&(e.left=f)),void 0===g?g:g+""||"auto"});function Mb(a,b){return{get:function(){var c=a();if(null!=c)return c?void delete this.get:(this.get=b).apply(this,arguments)}}}!function(){var b,c,d,e,f,g,h=z.createElement("div"),i="border:0;width:0;height:0;position:absolute;top:0;left:-9999px",j="-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;display:block;padding:0;margin:0;border:0";h.innerHTML=" a ",b=h.getElementsByTagName("a")[0],b.style.cssText="float:left;opacity:.5",l.opacity=/^0.5/.test(b.style.opacity),l.cssFloat=!!b.style.cssFloat,h.style.backgroundClip="content-box",h.cloneNode(!0).style.backgroundClip="",l.clearCloneStyle="content-box"===h.style.backgroundClip,b=h=null,n.extend(l,{reliableHiddenOffsets:function(){if(null!=c)return c;var a,b,d,e=z.createElement("div"),f=z.getElementsByTagName("body")[0];if(f)return e.setAttribute("className","t"),e.innerHTML=" a ",a=z.createElement("div"),a.style.cssText=i,f.appendChild(a).appendChild(e),e.innerHTML="",b=e.getElementsByTagName("td"),b[0].style.cssText="padding:0;margin:0;border:0;display:none",d=0===b[0].offsetHeight,b[0].style.display="",b[1].style.display="none",c=d&&0===b[0].offsetHeight,f.removeChild(a),e=f=null,c},boxSizing:function(){return null==d&&k(),d},boxSizingReliable:function(){return null==e&&k(),e},pixelPosition:function(){return null==f&&k(),f},reliableMarginRight:function(){var b,c,d,e;if(null==g&&a.getComputedStyle){if(b=z.getElementsByTagName("body")[0],!b)return;c=z.createElement("div"),d=z.createElement("div"),c.style.cssText=i,b.appendChild(c).appendChild(d),e=d.appendChild(z.createElement("div")),e.style.cssText=d.style.cssText=j,e.style.marginRight=e.style.width="0",d.style.width="1px",g=!parseFloat((a.getComputedStyle(e,null)||{}).marginRight),b.removeChild(c)}return g}});function k(){var b,c,h=z.getElementsByTagName("body")[0];h&&(b=z.createElement("div"),c=z.createElement("div"),b.style.cssText=i,h.appendChild(b).appendChild(c),c.style.cssText="-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;position:absolute;display:block;padding:1px;border:1px;width:4px;margin-top:1%;top:1%",n.swap(h,null!=h.style.zoom?{zoom:1}:{},function(){d=4===c.offsetWidth}),e=!0,f=!1,g=!0,a.getComputedStyle&&(f="1%"!==(a.getComputedStyle(c,null)||{}).top,e="4px"===(a.getComputedStyle(c,null)||{width:"4px"}).width),h.removeChild(b),c=h=null)}}(),n.swap=function(a,b,c,d){var e,f,g={};for(f in b)g[f]=a.style[f],a.style[f]=b[f];e=c.apply(a,d||[]);for(f in b)a.style[f]=g[f];return e};var Nb=/alpha\([^)]*\)/i,Ob=/opacity\s*=\s*([^)]*)/,Pb=/^(none|table(?!-c[ea]).+)/,Qb=new RegExp("^("+T+")(.*)$","i"),Rb=new RegExp("^([+-])=("+T+")","i"),Sb={position:"absolute",visibility:"hidden",display:"block"},Tb={letterSpacing:0,fontWeight:400},Ub=["Webkit","O","Moz","ms"];function Vb(a,b){if(b in a)return b;var c=b.charAt(0).toUpperCase()+b.slice(1),d=b,e=Ub.length;while(e--)if(b=Ub[e]+c,b in a)return b;return d}function Wb(a,b){for(var c,d,e,f=[],g=0,h=a.length;h>g;g++)d=a[g],d.style&&(f[g]=n._data(d,"olddisplay"),c=d.style.display,b?(f[g]||"none"!==c||(d.style.display=""),""===d.style.display&&V(d)&&(f[g]=n._data(d,"olddisplay",Gb(d.nodeName)))):f[g]||(e=V(d),(c&&"none"!==c||!e)&&n._data(d,"olddisplay",e?c:n.css(d,"display"))));for(g=0;h>g;g++)d=a[g],d.style&&(b&&"none"!==d.style.display&&""!==d.style.display||(d.style.display=b?f[g]||"":"none"));return a}function Xb(a,b,c){var d=Qb.exec(b);return d?Math.max(0,d[1]-(c||0))+(d[2]||"px"):b}function Yb(a,b,c,d,e){for(var f=c===(d?"border":"content")?4:"width"===b?1:0,g=0;4>f;f+=2)"margin"===c&&(g+=n.css(a,c+U[f],!0,e)),d?("content"===c&&(g-=n.css(a,"padding"+U[f],!0,e)),"margin"!==c&&(g-=n.css(a,"border"+U[f]+"Width",!0,e))):(g+=n.css(a,"padding"+U[f],!0,e),"padding"!==c&&(g+=n.css(a,"border"+U[f]+"Width",!0,e)));return g}function Zb(a,b,c){var d=!0,e="width"===b?a.offsetWidth:a.offsetHeight,f=Jb(a),g=l.boxSizing()&&"border-box"===n.css(a,"boxSizing",!1,f);if(0>=e||null==e){if(e=Kb(a,b,f),(0>e||null==e)&&(e=a.style[b]),Ib.test(e))return e;d=g&&(l.boxSizingReliable()||e===a.style[b]),e=parseFloat(e)||0}return e+Yb(a,b,c||(g?"border":"content"),d,f)+"px"}n.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=Kb(a,"opacity");return""===c?"1":c}}}},cssNumber:{columnCount:!0,fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":l.cssFloat?"cssFloat":"styleFloat"},style:function(a,b,c,d){if(a&&3!==a.nodeType&&8!==a.nodeType&&a.style){var e,f,g,h=n.camelCase(b),i=a.style;if(b=n.cssProps[h]||(n.cssProps[h]=Vb(i,h)),g=n.cssHooks[b]||n.cssHooks[h],void 0===c)return g&&"get"in g&&void 0!==(e=g.get(a,!1,d))?e:i[b];if(f=typeof c,"string"===f&&(e=Rb.exec(c))&&(c=(e[1]+1)*e[2]+parseFloat(n.css(a,b)),f="number"),null!=c&&c===c&&("number"!==f||n.cssNumber[h]||(c+="px"),l.clearCloneStyle||""!==c||0!==b.indexOf("background")||(i[b]="inherit"),!(g&&"set"in g&&void 0===(c=g.set(a,c,d)))))try{i[b]="",i[b]=c}catch(j){}}},css:function(a,b,c,d){var e,f,g,h=n.camelCase(b);return b=n.cssProps[h]||(n.cssProps[h]=Vb(a.style,h)),g=n.cssHooks[b]||n.cssHooks[h],g&&"get"in g&&(f=g.get(a,!0,c)),void 0===f&&(f=Kb(a,b,d)),"normal"===f&&b in Tb&&(f=Tb[b]),""===c||c?(e=parseFloat(f),c===!0||n.isNumeric(e)?e||0:f):f}}),n.each(["height","width"],function(a,b){n.cssHooks[b]={get:function(a,c,d){return c?0===a.offsetWidth&&Pb.test(n.css(a,"display"))?n.swap(a,Sb,function(){return Zb(a,b,d)}):Zb(a,b,d):void 0},set:function(a,c,d){var e=d&&Jb(a);return Xb(a,c,d?Yb(a,b,d,l.boxSizing()&&"border-box"===n.css(a,"boxSizing",!1,e),e):0)}}}),l.opacity||(n.cssHooks.opacity={get:function(a,b){return Ob.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?.01*parseFloat(RegExp.$1)+"":b?"1":""},set:function(a,b){var c=a.style,d=a.currentStyle,e=n.isNumeric(b)?"alpha(opacity="+100*b+")":"",f=d&&d.filter||c.filter||"";c.zoom=1,(b>=1||""===b)&&""===n.trim(f.replace(Nb,""))&&c.removeAttribute&&(c.removeAttribute("filter"),""===b||d&&!d.filter)||(c.filter=Nb.test(f)?f.replace(Nb,e):f+" "+e)}}),n.cssHooks.marginRight=Mb(l.reliableMarginRight,function(a,b){return b?n.swap(a,{display:"inline-block"},Kb,[a,"marginRight"]):void 0}),n.each({margin:"",padding:"",border:"Width"},function(a,b){n.cssHooks[a+b]={expand:function(c){for(var d=0,e={},f="string"==typeof c?c.split(" "):[c];4>d;d++)e[a+U[d]+b]=f[d]||f[d-2]||f[0];return e}},Hb.test(a)||(n.cssHooks[a+b].set=Xb)}),n.fn.extend({css:function(a,b){return W(this,function(a,b,c){var d,e,f={},g=0;if(n.isArray(b)){for(d=Jb(a),e=b.length;e>g;g++)f[b[g]]=n.css(a,b[g],!1,d);return f}return void 0!==c?n.style(a,b,c):n.css(a,b)
+},a,b,arguments.length>1)},show:function(){return Wb(this,!0)},hide:function(){return Wb(this)},toggle:function(a){return"boolean"==typeof a?a?this.show():this.hide():this.each(function(){V(this)?n(this).show():n(this).hide()})}});function $b(a,b,c,d,e){return new $b.prototype.init(a,b,c,d,e)}n.Tween=$b,$b.prototype={constructor:$b,init:function(a,b,c,d,e,f){this.elem=a,this.prop=c,this.easing=e||"swing",this.options=b,this.start=this.now=this.cur(),this.end=d,this.unit=f||(n.cssNumber[c]?"":"px")},cur:function(){var a=$b.propHooks[this.prop];return a&&a.get?a.get(this):$b.propHooks._default.get(this)},run:function(a){var b,c=$b.propHooks[this.prop];return this.pos=b=this.options.duration?n.easing[this.easing](a,this.options.duration*a,0,1,this.options.duration):a,this.now=(this.end-this.start)*b+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),c&&c.set?c.set(this):$b.propHooks._default.set(this),this}},$b.prototype.init.prototype=$b.prototype,$b.propHooks={_default:{get:function(a){var b;return null==a.elem[a.prop]||a.elem.style&&null!=a.elem.style[a.prop]?(b=n.css(a.elem,a.prop,""),b&&"auto"!==b?b:0):a.elem[a.prop]},set:function(a){n.fx.step[a.prop]?n.fx.step[a.prop](a):a.elem.style&&(null!=a.elem.style[n.cssProps[a.prop]]||n.cssHooks[a.prop])?n.style(a.elem,a.prop,a.now+a.unit):a.elem[a.prop]=a.now}}},$b.propHooks.scrollTop=$b.propHooks.scrollLeft={set:function(a){a.elem.nodeType&&a.elem.parentNode&&(a.elem[a.prop]=a.now)}},n.easing={linear:function(a){return a},swing:function(a){return.5-Math.cos(a*Math.PI)/2}},n.fx=$b.prototype.init,n.fx.step={};var _b,ac,bc=/^(?:toggle|show|hide)$/,cc=new RegExp("^(?:([+-])=|)("+T+")([a-z%]*)$","i"),dc=/queueHooks$/,ec=[jc],fc={"*":[function(a,b){var c=this.createTween(a,b),d=c.cur(),e=cc.exec(b),f=e&&e[3]||(n.cssNumber[a]?"":"px"),g=(n.cssNumber[a]||"px"!==f&&+d)&&cc.exec(n.css(c.elem,a)),h=1,i=20;if(g&&g[3]!==f){f=f||g[3],e=e||[],g=+d||1;do h=h||".5",g/=h,n.style(c.elem,a,g+f);while(h!==(h=c.cur()/d)&&1!==h&&--i)}return e&&(g=c.start=+g||+d||0,c.unit=f,c.end=e[1]?g+(e[1]+1)*e[2]:+e[2]),c}]};function gc(){return setTimeout(function(){_b=void 0}),_b=n.now()}function hc(a,b){var c,d={height:a},e=0;for(b=b?1:0;4>e;e+=2-b)c=U[e],d["margin"+c]=d["padding"+c]=a;return b&&(d.opacity=d.width=a),d}function ic(a,b,c){for(var d,e=(fc[b]||[]).concat(fc["*"]),f=0,g=e.length;g>f;f++)if(d=e[f].call(c,b,a))return d}function jc(a,b,c){var d,e,f,g,h,i,j,k,m=this,o={},p=a.style,q=a.nodeType&&V(a),r=n._data(a,"fxshow");c.queue||(h=n._queueHooks(a,"fx"),null==h.unqueued&&(h.unqueued=0,i=h.empty.fire,h.empty.fire=function(){h.unqueued||i()}),h.unqueued++,m.always(function(){m.always(function(){h.unqueued--,n.queue(a,"fx").length||h.empty.fire()})})),1===a.nodeType&&("height"in b||"width"in b)&&(c.overflow=[p.overflow,p.overflowX,p.overflowY],j=n.css(a,"display"),k=Gb(a.nodeName),"none"===j&&(j=k),"inline"===j&&"none"===n.css(a,"float")&&(l.inlineBlockNeedsLayout&&"inline"!==k?p.zoom=1:p.display="inline-block")),c.overflow&&(p.overflow="hidden",l.shrinkWrapBlocks()||m.always(function(){p.overflow=c.overflow[0],p.overflowX=c.overflow[1],p.overflowY=c.overflow[2]}));for(d in b)if(e=b[d],bc.exec(e)){if(delete b[d],f=f||"toggle"===e,e===(q?"hide":"show")){if("show"!==e||!r||void 0===r[d])continue;q=!0}o[d]=r&&r[d]||n.style(a,d)}if(!n.isEmptyObject(o)){r?"hidden"in r&&(q=r.hidden):r=n._data(a,"fxshow",{}),f&&(r.hidden=!q),q?n(a).show():m.done(function(){n(a).hide()}),m.done(function(){var b;n._removeData(a,"fxshow");for(b in o)n.style(a,b,o[b])});for(d in o)g=ic(q?r[d]:0,d,m),d in r||(r[d]=g.start,q&&(g.end=g.start,g.start="width"===d||"height"===d?1:0))}}function kc(a,b){var c,d,e,f,g;for(c in a)if(d=n.camelCase(c),e=b[d],f=a[c],n.isArray(f)&&(e=f[1],f=a[c]=f[0]),c!==d&&(a[d]=f,delete a[c]),g=n.cssHooks[d],g&&"expand"in g){f=g.expand(f),delete a[d];for(c in f)c in a||(a[c]=f[c],b[c]=e)}else b[d]=e}function lc(a,b,c){var d,e,f=0,g=ec.length,h=n.Deferred().always(function(){delete i.elem}),i=function(){if(e)return!1;for(var b=_b||gc(),c=Math.max(0,j.startTime+j.duration-b),d=c/j.duration||0,f=1-d,g=0,i=j.tweens.length;i>g;g++)j.tweens[g].run(f);return h.notifyWith(a,[j,f,c]),1>f&&i?c:(h.resolveWith(a,[j]),!1)},j=h.promise({elem:a,props:n.extend({},b),opts:n.extend(!0,{specialEasing:{}},c),originalProperties:b,originalOptions:c,startTime:_b||gc(),duration:c.duration,tweens:[],createTween:function(b,c){var d=n.Tween(a,j.opts,b,c,j.opts.specialEasing[b]||j.opts.easing);return j.tweens.push(d),d},stop:function(b){var c=0,d=b?j.tweens.length:0;if(e)return this;for(e=!0;d>c;c++)j.tweens[c].run(1);return b?h.resolveWith(a,[j,b]):h.rejectWith(a,[j,b]),this}}),k=j.props;for(kc(k,j.opts.specialEasing);g>f;f++)if(d=ec[f].call(j,a,k,j.opts))return d;return n.map(k,ic,j),n.isFunction(j.opts.start)&&j.opts.start.call(a,j),n.fx.timer(n.extend(i,{elem:a,anim:j,queue:j.opts.queue})),j.progress(j.opts.progress).done(j.opts.done,j.opts.complete).fail(j.opts.fail).always(j.opts.always)}n.Animation=n.extend(lc,{tweener:function(a,b){n.isFunction(a)?(b=a,a=["*"]):a=a.split(" ");for(var c,d=0,e=a.length;e>d;d++)c=a[d],fc[c]=fc[c]||[],fc[c].unshift(b)},prefilter:function(a,b){b?ec.unshift(a):ec.push(a)}}),n.speed=function(a,b,c){var d=a&&"object"==typeof a?n.extend({},a):{complete:c||!c&&b||n.isFunction(a)&&a,duration:a,easing:c&&b||b&&!n.isFunction(b)&&b};return d.duration=n.fx.off?0:"number"==typeof d.duration?d.duration:d.duration in n.fx.speeds?n.fx.speeds[d.duration]:n.fx.speeds._default,(null==d.queue||d.queue===!0)&&(d.queue="fx"),d.old=d.complete,d.complete=function(){n.isFunction(d.old)&&d.old.call(this),d.queue&&n.dequeue(this,d.queue)},d},n.fn.extend({fadeTo:function(a,b,c,d){return this.filter(V).css("opacity",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){var e=n.isEmptyObject(a),f=n.speed(b,c,d),g=function(){var b=lc(this,n.extend({},a),f);(e||n._data(this,"finish"))&&b.stop(!0)};return g.finish=g,e||f.queue===!1?this.each(g):this.queue(f.queue,g)},stop:function(a,b,c){var d=function(a){var b=a.stop;delete a.stop,b(c)};return"string"!=typeof a&&(c=b,b=a,a=void 0),b&&a!==!1&&this.queue(a||"fx",[]),this.each(function(){var b=!0,e=null!=a&&a+"queueHooks",f=n.timers,g=n._data(this);if(e)g[e]&&g[e].stop&&d(g[e]);else for(e in g)g[e]&&g[e].stop&&dc.test(e)&&d(g[e]);for(e=f.length;e--;)f[e].elem!==this||null!=a&&f[e].queue!==a||(f[e].anim.stop(c),b=!1,f.splice(e,1));(b||!c)&&n.dequeue(this,a)})},finish:function(a){return a!==!1&&(a=a||"fx"),this.each(function(){var b,c=n._data(this),d=c[a+"queue"],e=c[a+"queueHooks"],f=n.timers,g=d?d.length:0;for(c.finish=!0,n.queue(this,a,[]),e&&e.stop&&e.stop.call(this,!0),b=f.length;b--;)f[b].elem===this&&f[b].queue===a&&(f[b].anim.stop(!0),f.splice(b,1));for(b=0;g>b;b++)d[b]&&d[b].finish&&d[b].finish.call(this);delete c.finish})}}),n.each(["toggle","show","hide"],function(a,b){var c=n.fn[b];n.fn[b]=function(a,d,e){return null==a||"boolean"==typeof a?c.apply(this,arguments):this.animate(hc(b,!0),a,d,e)}}),n.each({slideDown:hc("show"),slideUp:hc("hide"),slideToggle:hc("toggle"),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){n.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),n.timers=[],n.fx.tick=function(){var a,b=n.timers,c=0;for(_b=n.now();ca ",a=e.getElementsByTagName("a")[0],c=z.createElement("select"),d=c.appendChild(z.createElement("option")),b=e.getElementsByTagName("input")[0],a.style.cssText="top:1px",l.getSetAttribute="t"!==e.className,l.style=/top/.test(a.getAttribute("style")),l.hrefNormalized="/a"===a.getAttribute("href"),l.checkOn=!!b.value,l.optSelected=d.selected,l.enctype=!!z.createElement("form").enctype,c.disabled=!0,l.optDisabled=!d.disabled,b=z.createElement("input"),b.setAttribute("value",""),l.input=""===b.getAttribute("value"),b.value="t",b.setAttribute("type","radio"),l.radioValue="t"===b.value,a=b=c=d=e=null}();var mc=/\r/g;n.fn.extend({val:function(a){var b,c,d,e=this[0];{if(arguments.length)return d=n.isFunction(a),this.each(function(c){var e;1===this.nodeType&&(e=d?a.call(this,c,n(this).val()):a,null==e?e="":"number"==typeof e?e+="":n.isArray(e)&&(e=n.map(e,function(a){return null==a?"":a+""})),b=n.valHooks[this.type]||n.valHooks[this.nodeName.toLowerCase()],b&&"set"in b&&void 0!==b.set(this,e,"value")||(this.value=e))});if(e)return b=n.valHooks[e.type]||n.valHooks[e.nodeName.toLowerCase()],b&&"get"in b&&void 0!==(c=b.get(e,"value"))?c:(c=e.value,"string"==typeof c?c.replace(mc,""):null==c?"":c)}}}),n.extend({valHooks:{option:{get:function(a){var b=n.find.attr(a,"value");return null!=b?b:n.text(a)}},select:{get:function(a){for(var b,c,d=a.options,e=a.selectedIndex,f="select-one"===a.type||0>e,g=f?null:[],h=f?e+1:d.length,i=0>e?h:f?e:0;h>i;i++)if(c=d[i],!(!c.selected&&i!==e||(l.optDisabled?c.disabled:null!==c.getAttribute("disabled"))||c.parentNode.disabled&&n.nodeName(c.parentNode,"optgroup"))){if(b=n(c).val(),f)return b;g.push(b)}return g},set:function(a,b){var c,d,e=a.options,f=n.makeArray(b),g=e.length;while(g--)if(d=e[g],n.inArray(n.valHooks.option.get(d),f)>=0)try{d.selected=c=!0}catch(h){d.scrollHeight}else d.selected=!1;return c||(a.selectedIndex=-1),e}}}}),n.each(["radio","checkbox"],function(){n.valHooks[this]={set:function(a,b){return n.isArray(b)?a.checked=n.inArray(n(a).val(),b)>=0:void 0}},l.checkOn||(n.valHooks[this].get=function(a){return null===a.getAttribute("value")?"on":a.value})});var nc,oc,pc=n.expr.attrHandle,qc=/^(?:checked|selected)$/i,rc=l.getSetAttribute,sc=l.input;n.fn.extend({attr:function(a,b){return W(this,n.attr,a,b,arguments.length>1)},removeAttr:function(a){return this.each(function(){n.removeAttr(this,a)})}}),n.extend({attr:function(a,b,c){var d,e,f=a.nodeType;if(a&&3!==f&&8!==f&&2!==f)return typeof a.getAttribute===L?n.prop(a,b,c):(1===f&&n.isXMLDoc(a)||(b=b.toLowerCase(),d=n.attrHooks[b]||(n.expr.match.bool.test(b)?oc:nc)),void 0===c?d&&"get"in d&&null!==(e=d.get(a,b))?e:(e=n.find.attr(a,b),null==e?void 0:e):null!==c?d&&"set"in d&&void 0!==(e=d.set(a,c,b))?e:(a.setAttribute(b,c+""),c):void n.removeAttr(a,b))},removeAttr:function(a,b){var c,d,e=0,f=b&&b.match(F);if(f&&1===a.nodeType)while(c=f[e++])d=n.propFix[c]||c,n.expr.match.bool.test(c)?sc&&rc||!qc.test(c)?a[d]=!1:a[n.camelCase("default-"+c)]=a[d]=!1:n.attr(a,c,""),a.removeAttribute(rc?c:d)},attrHooks:{type:{set:function(a,b){if(!l.radioValue&&"radio"===b&&n.nodeName(a,"input")){var c=a.value;return a.setAttribute("type",b),c&&(a.value=c),b}}}}}),oc={set:function(a,b,c){return b===!1?n.removeAttr(a,c):sc&&rc||!qc.test(c)?a.setAttribute(!rc&&n.propFix[c]||c,c):a[n.camelCase("default-"+c)]=a[c]=!0,c}},n.each(n.expr.match.bool.source.match(/\w+/g),function(a,b){var c=pc[b]||n.find.attr;pc[b]=sc&&rc||!qc.test(b)?function(a,b,d){var e,f;return d||(f=pc[b],pc[b]=e,e=null!=c(a,b,d)?b.toLowerCase():null,pc[b]=f),e}:function(a,b,c){return c?void 0:a[n.camelCase("default-"+b)]?b.toLowerCase():null}}),sc&&rc||(n.attrHooks.value={set:function(a,b,c){return n.nodeName(a,"input")?void(a.defaultValue=b):nc&&nc.set(a,b,c)}}),rc||(nc={set:function(a,b,c){var d=a.getAttributeNode(c);return d||a.setAttributeNode(d=a.ownerDocument.createAttribute(c)),d.value=b+="","value"===c||b===a.getAttribute(c)?b:void 0}},pc.id=pc.name=pc.coords=function(a,b,c){var d;return c?void 0:(d=a.getAttributeNode(b))&&""!==d.value?d.value:null},n.valHooks.button={get:function(a,b){var c=a.getAttributeNode(b);return c&&c.specified?c.value:void 0},set:nc.set},n.attrHooks.contenteditable={set:function(a,b,c){nc.set(a,""===b?!1:b,c)}},n.each(["width","height"],function(a,b){n.attrHooks[b]={set:function(a,c){return""===c?(a.setAttribute(b,"auto"),c):void 0}}})),l.style||(n.attrHooks.style={get:function(a){return a.style.cssText||void 0},set:function(a,b){return a.style.cssText=b+""}});var tc=/^(?:input|select|textarea|button|object)$/i,uc=/^(?:a|area)$/i;n.fn.extend({prop:function(a,b){return W(this,n.prop,a,b,arguments.length>1)},removeProp:function(a){return a=n.propFix[a]||a,this.each(function(){try{this[a]=void 0,delete this[a]}catch(b){}})}}),n.extend({propFix:{"for":"htmlFor","class":"className"},prop:function(a,b,c){var d,e,f,g=a.nodeType;if(a&&3!==g&&8!==g&&2!==g)return f=1!==g||!n.isXMLDoc(a),f&&(b=n.propFix[b]||b,e=n.propHooks[b]),void 0!==c?e&&"set"in e&&void 0!==(d=e.set(a,c,b))?d:a[b]=c:e&&"get"in e&&null!==(d=e.get(a,b))?d:a[b]},propHooks:{tabIndex:{get:function(a){var b=n.find.attr(a,"tabindex");return b?parseInt(b,10):tc.test(a.nodeName)||uc.test(a.nodeName)&&a.href?0:-1}}}}),l.hrefNormalized||n.each(["href","src"],function(a,b){n.propHooks[b]={get:function(a){return a.getAttribute(b,4)}}}),l.optSelected||(n.propHooks.selected={get:function(a){var b=a.parentNode;return b&&(b.selectedIndex,b.parentNode&&b.parentNode.selectedIndex),null}}),n.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){n.propFix[this.toLowerCase()]=this}),l.enctype||(n.propFix.enctype="encoding");var vc=/[\t\r\n\f]/g;n.fn.extend({addClass:function(a){var b,c,d,e,f,g,h=0,i=this.length,j="string"==typeof a&&a;if(n.isFunction(a))return this.each(function(b){n(this).addClass(a.call(this,b,this.className))});if(j)for(b=(a||"").match(F)||[];i>h;h++)if(c=this[h],d=1===c.nodeType&&(c.className?(" "+c.className+" ").replace(vc," "):" ")){f=0;while(e=b[f++])d.indexOf(" "+e+" ")<0&&(d+=e+" ");g=n.trim(d),c.className!==g&&(c.className=g)}return this},removeClass:function(a){var b,c,d,e,f,g,h=0,i=this.length,j=0===arguments.length||"string"==typeof a&&a;if(n.isFunction(a))return this.each(function(b){n(this).removeClass(a.call(this,b,this.className))});if(j)for(b=(a||"").match(F)||[];i>h;h++)if(c=this[h],d=1===c.nodeType&&(c.className?(" "+c.className+" ").replace(vc," "):"")){f=0;while(e=b[f++])while(d.indexOf(" "+e+" ")>=0)d=d.replace(" "+e+" "," ");g=a?n.trim(d):"",c.className!==g&&(c.className=g)}return this},toggleClass:function(a,b){var c=typeof a;return"boolean"==typeof b&&"string"===c?b?this.addClass(a):this.removeClass(a):this.each(n.isFunction(a)?function(c){n(this).toggleClass(a.call(this,c,this.className,b),b)}:function(){if("string"===c){var b,d=0,e=n(this),f=a.match(F)||[];while(b=f[d++])e.hasClass(b)?e.removeClass(b):e.addClass(b)}else(c===L||"boolean"===c)&&(this.className&&n._data(this,"__className__",this.className),this.className=this.className||a===!1?"":n._data(this,"__className__")||"")})},hasClass:function(a){for(var b=" "+a+" ",c=0,d=this.length;d>c;c++)if(1===this[c].nodeType&&(" "+this[c].className+" ").replace(vc," ").indexOf(b)>=0)return!0;return!1}}),n.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error contextmenu".split(" "),function(a,b){n.fn[b]=function(a,c){return arguments.length>0?this.on(b,null,a,c):this.trigger(b)}}),n.fn.extend({hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)},bind:function(a,b,c){return this.on(a,null,b,c)},unbind:function(a,b){return this.off(a,null,b)},delegate:function(a,b,c,d){return this.on(b,a,c,d)},undelegate:function(a,b,c){return 1===arguments.length?this.off(a,"**"):this.off(b,a||"**",c)}});var wc=n.now(),xc=/\?/,yc=/(,)|(\[|{)|(}|])|"(?:[^"\\\r\n]|\\["\\\/bfnrt]|\\u[\da-fA-F]{4})*"\s*:?|true|false|null|-?(?!0\d)\d+(?:\.\d+|)(?:[eE][+-]?\d+|)/g;n.parseJSON=function(b){if(a.JSON&&a.JSON.parse)return a.JSON.parse(b+"");var c,d=null,e=n.trim(b+"");return e&&!n.trim(e.replace(yc,function(a,b,e,f){return c&&b&&(d=0),0===d?a:(c=e||b,d+=!f-!e,"")}))?Function("return "+e)():n.error("Invalid JSON: "+b)},n.parseXML=function(b){var c,d;if(!b||"string"!=typeof b)return null;try{a.DOMParser?(d=new DOMParser,c=d.parseFromString(b,"text/xml")):(c=new ActiveXObject("Microsoft.XMLDOM"),c.async="false",c.loadXML(b))}catch(e){c=void 0}return c&&c.documentElement&&!c.getElementsByTagName("parsererror").length||n.error("Invalid XML: "+b),c};var zc,Ac,Bc=/#.*$/,Cc=/([?&])_=[^&]*/,Dc=/^(.*?):[ \t]*([^\r\n]*)\r?$/gm,Ec=/^(?:about|app|app-storage|.+-extension|file|res|widget):$/,Fc=/^(?:GET|HEAD)$/,Gc=/^\/\//,Hc=/^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,Ic={},Jc={},Kc="*/".concat("*");try{Ac=location.href}catch(Lc){Ac=z.createElement("a"),Ac.href="",Ac=Ac.href}zc=Hc.exec(Ac.toLowerCase())||[];function Mc(a){return function(b,c){"string"!=typeof b&&(c=b,b="*");var d,e=0,f=b.toLowerCase().match(F)||[];if(n.isFunction(c))while(d=f[e++])"+"===d.charAt(0)?(d=d.slice(1)||"*",(a[d]=a[d]||[]).unshift(c)):(a[d]=a[d]||[]).push(c)}}function Nc(a,b,c,d){var e={},f=a===Jc;function g(h){var i;return e[h]=!0,n.each(a[h]||[],function(a,h){var j=h(b,c,d);return"string"!=typeof j||f||e[j]?f?!(i=j):void 0:(b.dataTypes.unshift(j),g(j),!1)}),i}return g(b.dataTypes[0])||!e["*"]&&g("*")}function Oc(a,b){var c,d,e=n.ajaxSettings.flatOptions||{};for(d in b)void 0!==b[d]&&((e[d]?a:c||(c={}))[d]=b[d]);return c&&n.extend(!0,a,c),a}function Pc(a,b,c){var d,e,f,g,h=a.contents,i=a.dataTypes;while("*"===i[0])i.shift(),void 0===e&&(e=a.mimeType||b.getResponseHeader("Content-Type"));if(e)for(g in h)if(h[g]&&h[g].test(e)){i.unshift(g);break}if(i[0]in c)f=i[0];else{for(g in c){if(!i[0]||a.converters[g+" "+i[0]]){f=g;break}d||(d=g)}f=f||d}return f?(f!==i[0]&&i.unshift(f),c[f]):void 0}function Qc(a,b,c,d){var e,f,g,h,i,j={},k=a.dataTypes.slice();if(k[1])for(g in a.converters)j[g.toLowerCase()]=a.converters[g];f=k.shift();while(f)if(a.responseFields[f]&&(c[a.responseFields[f]]=b),!i&&d&&a.dataFilter&&(b=a.dataFilter(b,a.dataType)),i=f,f=k.shift())if("*"===f)f=i;else if("*"!==i&&i!==f){if(g=j[i+" "+f]||j["* "+f],!g)for(e in j)if(h=e.split(" "),h[1]===f&&(g=j[i+" "+h[0]]||j["* "+h[0]])){g===!0?g=j[e]:j[e]!==!0&&(f=h[0],k.unshift(h[1]));break}if(g!==!0)if(g&&a["throws"])b=g(b);else try{b=g(b)}catch(l){return{state:"parsererror",error:g?l:"No conversion from "+i+" to "+f}}}return{state:"success",data:b}}n.extend({active:0,lastModified:{},etag:{},ajaxSettings:{url:Ac,type:"GET",isLocal:Ec.test(zc[1]),global:!0,processData:!0,async:!0,contentType:"application/x-www-form-urlencoded; charset=UTF-8",accepts:{"*":Kc,text:"text/plain",html:"text/html",xml:"application/xml, text/xml",json:"application/json, text/javascript"},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText",json:"responseJSON"},converters:{"* text":String,"text html":!0,"text json":n.parseJSON,"text xml":n.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(a,b){return b?Oc(Oc(a,n.ajaxSettings),b):Oc(n.ajaxSettings,a)},ajaxPrefilter:Mc(Ic),ajaxTransport:Mc(Jc),ajax:function(a,b){"object"==typeof a&&(b=a,a=void 0),b=b||{};var c,d,e,f,g,h,i,j,k=n.ajaxSetup({},b),l=k.context||k,m=k.context&&(l.nodeType||l.jquery)?n(l):n.event,o=n.Deferred(),p=n.Callbacks("once memory"),q=k.statusCode||{},r={},s={},t=0,u="canceled",v={readyState:0,getResponseHeader:function(a){var b;if(2===t){if(!j){j={};while(b=Dc.exec(f))j[b[1].toLowerCase()]=b[2]}b=j[a.toLowerCase()]}return null==b?null:b},getAllResponseHeaders:function(){return 2===t?f:null},setRequestHeader:function(a,b){var c=a.toLowerCase();return t||(a=s[c]=s[c]||a,r[a]=b),this},overrideMimeType:function(a){return t||(k.mimeType=a),this},statusCode:function(a){var b;if(a)if(2>t)for(b in a)q[b]=[q[b],a[b]];else v.always(a[v.status]);return this},abort:function(a){var b=a||u;return i&&i.abort(b),x(0,b),this}};if(o.promise(v).complete=p.add,v.success=v.done,v.error=v.fail,k.url=((a||k.url||Ac)+"").replace(Bc,"").replace(Gc,zc[1]+"//"),k.type=b.method||b.type||k.method||k.type,k.dataTypes=n.trim(k.dataType||"*").toLowerCase().match(F)||[""],null==k.crossDomain&&(c=Hc.exec(k.url.toLowerCase()),k.crossDomain=!(!c||c[1]===zc[1]&&c[2]===zc[2]&&(c[3]||("http:"===c[1]?"80":"443"))===(zc[3]||("http:"===zc[1]?"80":"443")))),k.data&&k.processData&&"string"!=typeof k.data&&(k.data=n.param(k.data,k.traditional)),Nc(Ic,k,b,v),2===t)return v;h=k.global,h&&0===n.active++&&n.event.trigger("ajaxStart"),k.type=k.type.toUpperCase(),k.hasContent=!Fc.test(k.type),e=k.url,k.hasContent||(k.data&&(e=k.url+=(xc.test(e)?"&":"?")+k.data,delete k.data),k.cache===!1&&(k.url=Cc.test(e)?e.replace(Cc,"$1_="+wc++):e+(xc.test(e)?"&":"?")+"_="+wc++)),k.ifModified&&(n.lastModified[e]&&v.setRequestHeader("If-Modified-Since",n.lastModified[e]),n.etag[e]&&v.setRequestHeader("If-None-Match",n.etag[e])),(k.data&&k.hasContent&&k.contentType!==!1||b.contentType)&&v.setRequestHeader("Content-Type",k.contentType),v.setRequestHeader("Accept",k.dataTypes[0]&&k.accepts[k.dataTypes[0]]?k.accepts[k.dataTypes[0]]+("*"!==k.dataTypes[0]?", "+Kc+"; q=0.01":""):k.accepts["*"]);for(d in k.headers)v.setRequestHeader(d,k.headers[d]);if(k.beforeSend&&(k.beforeSend.call(l,v,k)===!1||2===t))return v.abort();u="abort";for(d in{success:1,error:1,complete:1})v[d](k[d]);if(i=Nc(Jc,k,b,v)){v.readyState=1,h&&m.trigger("ajaxSend",[v,k]),k.async&&k.timeout>0&&(g=setTimeout(function(){v.abort("timeout")},k.timeout));try{t=1,i.send(r,x)}catch(w){if(!(2>t))throw w;x(-1,w)}}else x(-1,"No Transport");function x(a,b,c,d){var j,r,s,u,w,x=b;2!==t&&(t=2,g&&clearTimeout(g),i=void 0,f=d||"",v.readyState=a>0?4:0,j=a>=200&&300>a||304===a,c&&(u=Pc(k,v,c)),u=Qc(k,u,v,j),j?(k.ifModified&&(w=v.getResponseHeader("Last-Modified"),w&&(n.lastModified[e]=w),w=v.getResponseHeader("etag"),w&&(n.etag[e]=w)),204===a||"HEAD"===k.type?x="nocontent":304===a?x="notmodified":(x=u.state,r=u.data,s=u.error,j=!s)):(s=x,(a||!x)&&(x="error",0>a&&(a=0))),v.status=a,v.statusText=(b||x)+"",j?o.resolveWith(l,[r,x,v]):o.rejectWith(l,[v,x,s]),v.statusCode(q),q=void 0,h&&m.trigger(j?"ajaxSuccess":"ajaxError",[v,k,j?r:s]),p.fireWith(l,[v,x]),h&&(m.trigger("ajaxComplete",[v,k]),--n.active||n.event.trigger("ajaxStop")))}return v},getJSON:function(a,b,c){return n.get(a,b,c,"json")},getScript:function(a,b){return n.get(a,void 0,b,"script")}}),n.each(["get","post"],function(a,b){n[b]=function(a,c,d,e){return n.isFunction(c)&&(e=e||d,d=c,c=void 0),n.ajax({url:a,type:b,dataType:e,data:c,success:d})}}),n.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(a,b){n.fn[b]=function(a){return this.on(b,a)}}),n._evalUrl=function(a){return n.ajax({url:a,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0})},n.fn.extend({wrapAll:function(a){if(n.isFunction(a))return this.each(function(b){n(this).wrapAll(a.call(this,b))});if(this[0]){var b=n(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&1===a.firstChild.nodeType)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){return this.each(n.isFunction(a)?function(b){n(this).wrapInner(a.call(this,b))}:function(){var b=n(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=n.isFunction(a);return this.each(function(c){n(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(){return this.parent().each(function(){n.nodeName(this,"body")||n(this).replaceWith(this.childNodes)}).end()}}),n.expr.filters.hidden=function(a){return a.offsetWidth<=0&&a.offsetHeight<=0||!l.reliableHiddenOffsets()&&"none"===(a.style&&a.style.display||n.css(a,"display"))},n.expr.filters.visible=function(a){return!n.expr.filters.hidden(a)};var Rc=/%20/g,Sc=/\[\]$/,Tc=/\r?\n/g,Uc=/^(?:submit|button|image|reset|file)$/i,Vc=/^(?:input|select|textarea|keygen)/i;function Wc(a,b,c,d){var e;if(n.isArray(b))n.each(b,function(b,e){c||Sc.test(a)?d(a,e):Wc(a+"["+("object"==typeof e?b:"")+"]",e,c,d)});else if(c||"object"!==n.type(b))d(a,b);else for(e in b)Wc(a+"["+e+"]",b[e],c,d)}n.param=function(a,b){var c,d=[],e=function(a,b){b=n.isFunction(b)?b():null==b?"":b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};if(void 0===b&&(b=n.ajaxSettings&&n.ajaxSettings.traditional),n.isArray(a)||a.jquery&&!n.isPlainObject(a))n.each(a,function(){e(this.name,this.value)});else for(c in a)Wc(c,a[c],b,e);return d.join("&").replace(Rc,"+")},n.fn.extend({serialize:function(){return n.param(this.serializeArray())},serializeArray:function(){return this.map(function(){var a=n.prop(this,"elements");return a?n.makeArray(a):this}).filter(function(){var a=this.type;return this.name&&!n(this).is(":disabled")&&Vc.test(this.nodeName)&&!Uc.test(a)&&(this.checked||!X.test(a))}).map(function(a,b){var c=n(this).val();return null==c?null:n.isArray(c)?n.map(c,function(a){return{name:b.name,value:a.replace(Tc,"\r\n")}}):{name:b.name,value:c.replace(Tc,"\r\n")}}).get()}}),n.ajaxSettings.xhr=void 0!==a.ActiveXObject?function(){return!this.isLocal&&/^(get|post|head|put|delete|options)$/i.test(this.type)&&$c()||_c()}:$c;var Xc=0,Yc={},Zc=n.ajaxSettings.xhr();a.ActiveXObject&&n(a).on("unload",function(){for(var a in Yc)Yc[a](void 0,!0)}),l.cors=!!Zc&&"withCredentials"in Zc,Zc=l.ajax=!!Zc,Zc&&n.ajaxTransport(function(a){if(!a.crossDomain||l.cors){var b;return{send:function(c,d){var e,f=a.xhr(),g=++Xc;if(f.open(a.type,a.url,a.async,a.username,a.password),a.xhrFields)for(e in a.xhrFields)f[e]=a.xhrFields[e];a.mimeType&&f.overrideMimeType&&f.overrideMimeType(a.mimeType),a.crossDomain||c["X-Requested-With"]||(c["X-Requested-With"]="XMLHttpRequest");for(e in c)void 0!==c[e]&&f.setRequestHeader(e,c[e]+"");f.send(a.hasContent&&a.data||null),b=function(c,e){var h,i,j;if(b&&(e||4===f.readyState))if(delete Yc[g],b=void 0,f.onreadystatechange=n.noop,e)4!==f.readyState&&f.abort();else{j={},h=f.status,"string"==typeof f.responseText&&(j.text=f.responseText);try{i=f.statusText}catch(k){i=""}h||!a.isLocal||a.crossDomain?1223===h&&(h=204):h=j.text?200:404}j&&d(h,i,j,f.getAllResponseHeaders())},a.async?4===f.readyState?setTimeout(b):f.onreadystatechange=Yc[g]=b:b()},abort:function(){b&&b(void 0,!0)}}}});function $c(){try{return new a.XMLHttpRequest}catch(b){}}function _c(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}n.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/(?:java|ecma)script/},converters:{"text script":function(a){return n.globalEval(a),a}}}),n.ajaxPrefilter("script",function(a){void 0===a.cache&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),n.ajaxTransport("script",function(a){if(a.crossDomain){var b,c=z.head||n("head")[0]||z.documentElement;return{send:function(d,e){b=z.createElement("script"),b.async=!0,a.scriptCharset&&(b.charset=a.scriptCharset),b.src=a.url,b.onload=b.onreadystatechange=function(a,c){(c||!b.readyState||/loaded|complete/.test(b.readyState))&&(b.onload=b.onreadystatechange=null,b.parentNode&&b.parentNode.removeChild(b),b=null,c||e(200,"success"))},c.insertBefore(b,c.firstChild)},abort:function(){b&&b.onload(void 0,!0)}}}});var ad=[],bd=/(=)\?(?=&|$)|\?\?/;n.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var a=ad.pop()||n.expando+"_"+wc++;return this[a]=!0,a}}),n.ajaxPrefilter("json jsonp",function(b,c,d){var e,f,g,h=b.jsonp!==!1&&(bd.test(b.url)?"url":"string"==typeof b.data&&!(b.contentType||"").indexOf("application/x-www-form-urlencoded")&&bd.test(b.data)&&"data");return h||"jsonp"===b.dataTypes[0]?(e=b.jsonpCallback=n.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,h?b[h]=b[h].replace(bd,"$1"+e):b.jsonp!==!1&&(b.url+=(xc.test(b.url)?"&":"?")+b.jsonp+"="+e),b.converters["script json"]=function(){return g||n.error(e+" was not called"),g[0]},b.dataTypes[0]="json",f=a[e],a[e]=function(){g=arguments},d.always(function(){a[e]=f,b[e]&&(b.jsonpCallback=c.jsonpCallback,ad.push(e)),g&&n.isFunction(f)&&f(g[0]),g=f=void 0}),"script"):void 0}),n.parseHTML=function(a,b,c){if(!a||"string"!=typeof a)return null;"boolean"==typeof b&&(c=b,b=!1),b=b||z;var d=v.exec(a),e=!c&&[];return d?[b.createElement(d[1])]:(d=n.buildFragment([a],b,e),e&&e.length&&n(e).remove(),n.merge([],d.childNodes))};var cd=n.fn.load;n.fn.load=function(a,b,c){if("string"!=typeof a&&cd)return cd.apply(this,arguments);var d,e,f,g=this,h=a.indexOf(" ");return h>=0&&(d=a.slice(h,a.length),a=a.slice(0,h)),n.isFunction(b)?(c=b,b=void 0):b&&"object"==typeof b&&(f="POST"),g.length>0&&n.ajax({url:a,type:f,dataType:"html",data:b}).done(function(a){e=arguments,g.html(d?n("").append(n.parseHTML(a)).find(d):a)}).complete(c&&function(a,b){g.each(c,e||[a.responseText,b,a])}),this},n.expr.filters.animated=function(a){return n.grep(n.timers,function(b){return a===b.elem}).length};var dd=a.document.documentElement;function ed(a){return n.isWindow(a)?a:9===a.nodeType?a.defaultView||a.parentWindow:!1}n.offset={setOffset:function(a,b,c){var d,e,f,g,h,i,j,k=n.css(a,"position"),l=n(a),m={};"static"===k&&(a.style.position="relative"),h=l.offset(),f=n.css(a,"top"),i=n.css(a,"left"),j=("absolute"===k||"fixed"===k)&&n.inArray("auto",[f,i])>-1,j?(d=l.position(),g=d.top,e=d.left):(g=parseFloat(f)||0,e=parseFloat(i)||0),n.isFunction(b)&&(b=b.call(a,c,h)),null!=b.top&&(m.top=b.top-h.top+g),null!=b.left&&(m.left=b.left-h.left+e),"using"in b?b.using.call(a,m):l.css(m)}},n.fn.extend({offset:function(a){if(arguments.length)return void 0===a?this:this.each(function(b){n.offset.setOffset(this,a,b)});var b,c,d={top:0,left:0},e=this[0],f=e&&e.ownerDocument;if(f)return b=f.documentElement,n.contains(b,e)?(typeof e.getBoundingClientRect!==L&&(d=e.getBoundingClientRect()),c=ed(f),{top:d.top+(c.pageYOffset||b.scrollTop)-(b.clientTop||0),left:d.left+(c.pageXOffset||b.scrollLeft)-(b.clientLeft||0)}):d},position:function(){if(this[0]){var a,b,c={top:0,left:0},d=this[0];return"fixed"===n.css(d,"position")?b=d.getBoundingClientRect():(a=this.offsetParent(),b=this.offset(),n.nodeName(a[0],"html")||(c=a.offset()),c.top+=n.css(a[0],"borderTopWidth",!0),c.left+=n.css(a[0],"borderLeftWidth",!0)),{top:b.top-c.top-n.css(d,"marginTop",!0),left:b.left-c.left-n.css(d,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||dd;while(a&&!n.nodeName(a,"html")&&"static"===n.css(a,"position"))a=a.offsetParent;return a||dd})}}),n.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(a,b){var c=/Y/.test(b);n.fn[a]=function(d){return W(this,function(a,d,e){var f=ed(a);return void 0===e?f?b in f?f[b]:f.document.documentElement[d]:a[d]:void(f?f.scrollTo(c?n(f).scrollLeft():e,c?e:n(f).scrollTop()):a[d]=e)},a,d,arguments.length,null)}}),n.each(["top","left"],function(a,b){n.cssHooks[b]=Mb(l.pixelPosition,function(a,c){return c?(c=Kb(a,b),Ib.test(c)?n(a).position()[b]+"px":c):void 0})}),n.each({Height:"height",Width:"width"},function(a,b){n.each({padding:"inner"+a,content:b,"":"outer"+a},function(c,d){n.fn[d]=function(d,e){var f=arguments.length&&(c||"boolean"!=typeof d),g=c||(d===!0||e===!0?"margin":"border");return W(this,function(b,c,d){var e;return n.isWindow(b)?b.document.documentElement["client"+a]:9===b.nodeType?(e=b.documentElement,Math.max(b.body["scroll"+a],e["scroll"+a],b.body["offset"+a],e["offset"+a],e["client"+a])):void 0===d?n.css(b,c,g):n.style(b,c,d,g)},b,f?d:void 0,f,null)}})}),n.fn.size=function(){return this.length},n.fn.andSelf=n.fn.addBack,"function"==typeof define&&define.amd&&define("jquery",[],function(){return n});var fd=a.jQuery,gd=a.$;return n.noConflict=function(b){return a.$===n&&(a.$=gd),b&&a.jQuery===n&&(a.jQuery=fd),n},typeof b===L&&(a.jQuery=a.$=n),n});
diff --git a/docs/codox/js/page_effects.js b/docs/codox/js/page_effects.js
new file mode 100644
index 0000000..fdacbf8
--- /dev/null
+++ b/docs/codox/js/page_effects.js
@@ -0,0 +1,112 @@
+function visibleInParent(element) {
+ var position = $(element).position().top
+ return position > -50 && position < ($(element).offsetParent().height() - 50)
+}
+
+function hasFragment(link, fragment) {
+ return $(link).attr("href").indexOf("#" + fragment) != -1
+}
+
+function findLinkByFragment(elements, fragment) {
+ return $(elements).filter(function(i, e) { return hasFragment(e, fragment)}).first()
+}
+
+function scrollToCurrentVarLink(elements) {
+ var elements = $(elements);
+ var parent = elements.offsetParent();
+
+ if (elements.length == 0) return;
+
+ var top = elements.first().position().top;
+ var bottom = elements.last().position().top + elements.last().height();
+
+ if (top >= 0 && bottom <= parent.height()) return;
+
+ if (top < 0) {
+ parent.scrollTop(parent.scrollTop() + top);
+ }
+ else if (bottom > parent.height()) {
+ parent.scrollTop(parent.scrollTop() + bottom - parent.height());
+ }
+}
+
+function setCurrentVarLink() {
+ $('.secondary a').parent().removeClass('current')
+ $('.anchor').
+ filter(function(index) { return visibleInParent(this) }).
+ each(function(index, element) {
+ findLinkByFragment(".secondary a", element.id).
+ parent().
+ addClass('current')
+ });
+ scrollToCurrentVarLink('.secondary .current');
+}
+
+var hasStorage = (function() { try { return localStorage.getItem } catch(e) {} }())
+
+function scrollPositionId(element) {
+ var directory = window.location.href.replace(/[^\/]+\.html$/, '')
+ return 'scroll::' + $(element).attr('id') + '::' + directory
+}
+
+function storeScrollPosition(element) {
+ if (!hasStorage) return;
+ localStorage.setItem(scrollPositionId(element) + "::x", $(element).scrollLeft())
+ localStorage.setItem(scrollPositionId(element) + "::y", $(element).scrollTop())
+}
+
+function recallScrollPosition(element) {
+ if (!hasStorage) return;
+ $(element).scrollLeft(localStorage.getItem(scrollPositionId(element) + "::x"))
+ $(element).scrollTop(localStorage.getItem(scrollPositionId(element) + "::y"))
+}
+
+function persistScrollPosition(element) {
+ recallScrollPosition(element)
+ $(element).scroll(function() { storeScrollPosition(element) })
+}
+
+function sidebarContentWidth(element) {
+ var widths = $(element).find('.inner').map(function() { return $(this).innerWidth() })
+ return Math.max.apply(Math, widths)
+}
+
+function calculateSize(width, snap, margin, minimum) {
+ if (width == 0) {
+ return 0
+ }
+ else {
+ return Math.max(minimum, (Math.ceil(width / snap) * snap) + (margin * 2))
+ }
+}
+
+function resizeSidebars() {
+ var primaryWidth = sidebarContentWidth('.primary')
+ var secondaryWidth = 0
+
+ if ($('.secondary').length != 0) {
+ secondaryWidth = sidebarContentWidth('.secondary')
+ }
+
+ // snap to grid
+ primaryWidth = calculateSize(primaryWidth, 32, 13, 160)
+ secondaryWidth = calculateSize(secondaryWidth, 32, 13, 160)
+
+ $('.primary').css('width', primaryWidth)
+ $('.secondary').css('width', secondaryWidth).css('left', primaryWidth + 1)
+
+ if (secondaryWidth > 0) {
+ $('#content').css('left', primaryWidth + secondaryWidth + 2)
+ }
+ else {
+ $('#content').css('left', primaryWidth + 1)
+ }
+}
+
+$(window).ready(resizeSidebars)
+$(window).ready(setCurrentVarLink)
+$(window).ready(function() { persistScrollPosition('.primary')})
+$(window).ready(function() {
+ $('#content').scroll(setCurrentVarLink)
+ $(window).resize(setCurrentVarLink)
+})
diff --git a/project.clj b/project.clj
index c547395..1e3cecb 100644
--- a/project.clj
+++ b/project.clj
@@ -1,14 +1,34 @@
-(defproject beowulf "0.1.0-SNAPSHOT"
+(defproject beowulf "0.2.1-SNAPSHOT"
+ :cloverage {:output "docs/cloverage"}
+ :codox {:metadata {:doc "**TODO**: write docs"
+ :doc/format :markdown}
+ :output-path "docs/codox"
+ :source-uri "https://github.com/simon-brooke/beowulf/blob/master/{filepath}#L{line}"}
:description "An implementation of LISP 1.5 in Clojure"
- :url "http://example.com/FIXME"
:license {:name "GPL-2.0-or-later"
:url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/math.numeric-tower "0.0.4"]
+ [org.clojure/tools.cli "0.4.2"]
[org.clojure/tools.trace "0.7.10"]
[environ "1.1.0"]
[instaparse "1.4.10"]]
:main ^:skip-aot beowulf.core
- :plugins [[lein-environ "1.1.0"]]
+ :plugins [[lein-cloverage "1.1.1"]
+ [lein-codox "0.10.7"]
+ [lein-environ "1.1.0"]]
+ :profiles {:uberjar {:aot :all}}
+ :release-tasks [["vcs" "assert-committed"]
+ ["change" "version" "leiningen.release/bump-version" "release"]
+ ["vcs" "commit"]
+ ["vcs" "tag" "v." "--no-sign"]
+ ["clean"]
+ ["codox"]
+ ["cloverage"]
+ ["uberjar"]
+ ["change" "version" "leiningen.release/bump-version"]
+ ["vcs" "commit"]]
+
:target-path "target/%s"
- :profiles {:uberjar {:aot :all}})
+ :url "https://github.com/simon-brooke/the-great-game"
+ )
diff --git a/resources/lisp1.5.lsp b/resources/lisp1.5.lsp
new file mode 100644
index 0000000..e69de29
diff --git a/src/beowulf/eval.clj b/src/beowulf/bootstrap.clj
similarity index 73%
rename from src/beowulf/eval.clj
rename to src/beowulf/bootstrap.clj
index 5d78087..4e72869 100644
--- a/src/beowulf/eval.clj
+++ b/src/beowulf/bootstrap.clj
@@ -1,30 +1,55 @@
-(ns beowulf.eval
+(ns beowulf.bootstrap
+ "Lisp as defined in Chapter 1 (pages 1-14) of the
+ `Lisp 1.5 Programmer's Manual`; that is to say, a very simple Lisp language,
+ which should, I believe, be sufficient in conjunction with the functions
+ provided by `beowulf.host`, be sufficient to bootstrap the full Lisp 1.5
+ interpreter..
+
+ The convention is adopted that functions in this file with names in
+ ALLUPPERCASE are Lisp 1.5 functions (although written in Clojure) and that
+ therefore all arguments must be numbers, symbols or `beowulf.cons_cell.ConsCell`
+ objects."
(:require [clojure.tools.trace :refer :all]
[beowulf.cons-cell :refer [make-beowulf-list make-cons-cell NIL T F]]))
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;
+;;; This file is essentially Lisp as defined in Chapter 1 (pages 1-14) of the
+;;; Lisp 1.5 Programmer's Manual; that is to say, a very simple Lisp language,
+;;; which should, I believe, be sufficient in conjunction with the functions
+;;; provided by `beowulf.host`, be sufficient to bootstrap the full Lisp 1.5
+;;; interpreter.
+;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
(declare EVAL)
(def oblist
- "The default environment; modified certainly be `LABEL` (which seems to
- be Lisp 1.5's EQuivalent of `SETQ`), possibly by other things."
+ "The default environment."
(atom NIL))
-(defn NULL
- [x]
- (if (= x NIL) 'T 'F))
+(def ^:dynamic *options*
+ "Command line options from invocation."
+ {})
-(defn ATOM
- "It is not clear to me from the documentation whether `(ATOM 7)` should return
- `'T` or `'F`. I'm going to assume `'T`."
+(defmacro NULL
+ "Returns `T` if and only if the argument `x` is bound to `NIL`; else `F`."
[x]
- (if (or (symbol? x) (number? x)) 'T 'F))
+ `(if (= ~x NIL) T F))
-(defn ATOM?
- "The convention of returning `'F` from predicates, rather than `NIL`, is going
+(defmacro ATOM
+ "Returns `T` if and only is the argument `x` is bound to and atom; else `F`.
+ It is not clear to me from the documentation whether `(ATOM 7)` should return
+ `T` or `F`. I'm going to assume `T`."
+ [x]
+ `(if (or (symbol? ~x) (number? ~x)) T F))
+
+(defmacro ATOM?
+ "The convention of returning `F` from predicates, rather than `NIL`, is going
to tie me in knots. This is a variant of `ATOM` which returns `NIL`
on failure."
[x]
- (if (or (symbol? x) (number? x)) 'T NIL))
+ `(if (or (symbol? ~x) (number? ~x)) T NIL))
(defn CAR
"Return the item indicated by the first pointer of a pair. NIL is treated
@@ -94,10 +119,10 @@
(defn CDADDR [x] (uaf x (seq "dadd")))
(defn EQ
- ;; For some reason providing a doc string for this function breaks the
- ;; Clojure parser!
+ "Returns `T` if and only if both `x` and `y` are bound to the same atom,
+ else `F`."
[x y]
- (if (and (= (ATOM x) 'T) (= x y)) 'T 'F))
+ (if (and (= (ATOM x) T) (= x y)) T F))
(defn EQUAL
"This is a predicate that is true if its two arguments are identical
@@ -105,20 +130,20 @@
`EQ` is defined only for atomic arguments.) The definition of `EQUAL` is
an example of a conditional expression inside a conditional expression.
- NOTE: returns F on failure, not NIL"
+ NOTE: returns `F` on failure, not `NIL`"
[x y]
(cond
- (= (ATOM x) 'T) (EQ x y)
- (= (EQUAL (CAR x) (CAR y)) 'T) (EQUAL (CDR x) (CDR y))
- :else 'F))
+ (= (ATOM x) T) (EQ x y)
+ (= (EQUAL (CAR x) (CAR y)) T) (EQUAL (CDR x) (CDR y))
+ :else F))
(defn SUBST
"This function gives the result of substituting the S-expression `x` for
all occurrences of the atomic symbol `y` in the S-expression `z`."
[x y z]
(cond
- (= (EQUAL y z) 'T) x
- (= (ATOM? z) 'T) z ;; NIL is a symbol
+ (= (EQUAL y z) T) x
+ (= (ATOM? z) T) z ;; NIL is a symbol
:else
(make-cons-cell (SUBST x y (CAR z)) (SUBST x y (CDR z)))))
@@ -143,7 +168,7 @@
[x y]
(cond
(= y NIL) F ;; NOTE: returns F on falsity, not NIL
- (= (EQUAL x (CAR y)) 'T) 'T
+ (= (EQUAL x (CAR y)) T) T
:else (MEMBER x (CDR y))))
(defn PAIRLIS
@@ -177,7 +202,7 @@
(cond
(= NIL a) NIL ;; this clause is not present in the original but is added for
;; robustness.
- (= (EQUAL (CAAR a) x) 'T) (CAR a)
+ (= (EQUAL (CAAR a) x) T) (CAR a)
:else
(ASSOC x (CDR a))))
@@ -204,11 +229,11 @@
See page 12 of the Lisp 1.5 Programmers Manual."
[a y]
(cond
- (= (ATOM? y) 'T) (SUB2 a y)
+ (= (ATOM? y) T) (SUB2 a y)
:else
(make-cons-cell (SUBLIS a (CAR y)) (SUBLIS a (CDR y)))))
-(deftrace APPLY
+(defn APPLY
"For bootstrapping, at least, a version of APPLY written in Clojure.
All args are assumed to be symbols or `beowulf.cons-cell/ConsCell` objects.
See page 13 of the Lisp 1.5 Programmers Manual."
@@ -216,7 +241,9 @@
(cond
(=
(ATOM? function)
- 'T)(cond
+ T)(cond
+ ;; TODO: doesn't check whether `function` is bound in the environment;
+ ;; we'll need that before we can bootstrap.
(= function 'CAR) (CAAR args)
(= function 'CDR) (CDAR args)
(= function 'CONS) (make-cons-cell (CAR args) (CADR args))
@@ -261,19 +288,16 @@
(EVAL (CAR args) env)
(EVLIS (CDR args) env))))
-
-(deftrace EVAL
- "For bootstrapping, at least, a version of EVAL written in Clojure.
- All args are assumed to be symbols or `beowulf.cons-cell/ConsCell` objects.
- See page 13 of the Lisp 1.5 Programmers Manual."
+(deftrace traced-eval
+ "Essentially, identical to EVAL except traced."
[expr env]
(cond
(=
- (ATOM? expr) 'T)
+ (ATOM? expr) T)
(CDR (ASSOC expr env))
(=
(ATOM? (CAR expr))
- 'T)(cond
+ T)(cond
(= (CAR expr) 'QUOTE) (CADR expr)
(= (CAR expr) 'COND) (EVCON (CDR expr) env)
:else (APPLY
@@ -285,3 +309,30 @@
(EVLIS (CDR expr) env)
env)))
+(defn EVAL
+ "For bootstrapping, at least, a version of EVAL written in Clojure.
+ All args are assumed to be symbols or `beowulf.cons-cell/ConsCell` objects.
+ See page 13 of the Lisp 1.5 Programmers Manual."
+ [expr env]
+ (cond
+ (true? (:trace *options*))
+ (traced-eval expr env)
+ (=
+ (ATOM? expr) T)
+ (CDR (ASSOC expr env))
+ (=
+ (ATOM? (CAR expr))
+ T)(cond
+ (= (CAR expr) 'QUOTE) (CADR expr)
+ (= (CAR expr) 'COND) (EVCON (CDR expr) env)
+ :else (APPLY
+ (CAR expr)
+ (EVLIS (CDR expr) env)
+ env))
+ :else (APPLY
+ (CAR expr)
+ (EVLIS (CDR expr) env)
+ env)))
+
+
+
diff --git a/src/beowulf/cons_cell.clj b/src/beowulf/cons_cell.clj
index 86d6fce..3fd104b 100644
--- a/src/beowulf/cons_cell.clj
+++ b/src/beowulf/cons_cell.clj
@@ -1,11 +1,20 @@
(ns beowulf.cons-cell
- )
+ "The fundamental cons cell on which all Lisp structures are built.
+ Lisp 1.5 lists do not necessarily have a sequence as their CDR, so
+ cannot be implemented on top of Clojure lists.")
-(def NIL (symbol "NIL"))
+(def NIL
+ "The canonical empty list symbol."
+ (symbol "NIL"))
-(def T (symbol "T")) ;; true.
+(def T
+ "The canonical true value."
+ (symbol "T")) ;; true.
-(def F (symbol "F")) ;; false as distinct from nil
+(def F
+ "The canonical false value - different from `NIL`, which is not canonically
+ false in Lisp 1.5."
+ (symbol "F")) ;; false as distinct from nil
(deftype ConsCell [CAR CDR]
clojure.lang.ISeq
@@ -15,12 +24,13 @@
;; https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/ISeq.java
(more [this] (if
(seq? (.CDR this))
- clojure.lang.PersistentList/EMPTY
- (.CDR this)))
+ (.CDR this)
+ clojure.lang.PersistentList/EMPTY))
(next [this] (if
(seq? (.CDR this))
+ (.CDR this)
nil ;; next returns nil when empty
- (.CDR this)))
+ ))
clojure.lang.Seqable
(seq [this] this)
@@ -31,11 +41,26 @@
clojure.lang.IPersistentCollection
(count [this] (if
- (seq? (.CDR this))
- 0
- (inc (count (.CDR this)))))
- (empty [this] false)
- (equiv [this other] false))
+ (coll? (.CDR this))
+ (inc (.count (.CDR this)))
+ 1))
+ (empty [this] false) ;; a cons cell is by definition not empty.
+ (equiv [this other] (if
+ (seq? other)
+ (and
+ (if
+ (and
+ (seq? (first this))
+ (seq? (first other)))
+ (.equiv (first this) (first other))
+ (= (first this) (first other)))
+ (if
+ (and
+ (seq? (rest this))
+ (seq? (rest other)))
+ (.equiv (rest this) (rest other))
+ (= (rest this) (rest other))))
+ false)))
(defn- to-string
"Printing ConsCells gave me a *lot* of trouble. This is an internal function
@@ -103,21 +128,29 @@
-(defmethod clojure.core/print-method beowulf.cons_cell.ConsCell
+(defmethod clojure.core/print-method
+ ;;; I have not worked out how to document defmethod without blowing up the world.
+ beowulf.cons_cell.ConsCell
[this writer]
(.write writer (to-string this)))
-(defn make-cons-cell
- [a d]
- (ConsCell. a d))
+(defmacro make-cons-cell
+ "Construct a new instance of cons cell with this `car` and `cdr`."
+ [car cdr]
+ `(ConsCell. ~car ~cdr))
(defn make-beowulf-list
+ "Construct a linked list of cons cells with the same content as the
+ sequence `x`."
[x]
(cond
(empty? x) NIL
(coll? x) (ConsCell.
- (first x)
+ (if
+ (seq? (first x))
+ (make-beowulf-list (first x))
+ (first x))
(make-beowulf-list (rest x)))
:else
NIL))
diff --git a/src/beowulf/core.clj b/src/beowulf/core.clj
index 8d8cebc..6ea2757 100644
--- a/src/beowulf/core.clj
+++ b/src/beowulf/core.clj
@@ -1,21 +1,36 @@
(ns beowulf.core
- (:require [beowulf.eval :refer [EVAL oblist]]
+ "Essentially, the `-main` function and the bootstrap read-eval-print loop."
+ (:require [beowulf.bootstrap :refer [EVAL oblist *options*]]
[beowulf.read :refer [READ]]
+ [clojure.java.io :as io]
[clojure.pprint :refer [pprint]]
+ [clojure.tools.cli :refer [parse-opts]]
[environ.core :refer [env]])
(:gen-class))
+(def cli-options
+ [["-h" "--help"]
+ ["-p PROMPT" "--prompt PROMPT" "Set the REPL prompt to PROMPT"
+ :default "Sprecan::"]
+ ["-r INITFILE" "--read INITFILE" "Read Lisp functions from the file INITFILE"
+ :validate [#(and
+ (.exists (io/file %))
+ (.canRead (io/file %)))
+ "Could not find initfile"]]
+ ["-s" "--strict" "Strictly interpret the Lisp 1.5 language, without extensions."]
+ ["-t" "--trace" "Trace Lisp evaluation."]])
+
(defn repl
"Read/eval/print loop."
- []
+ [prompt]
(loop []
- (print "Sprecan:: ")
+ (print prompt)
(flush)
(try
(let [input (read-line)]
(cond
- (= input "quit") (throw (ex-info "Færwell!" {:cause :quit}))
- input (println (str "> " (EVAL (READ input) @oblist)))
+ (= input "quit") (throw (ex-info "\nFærwell!" {:cause :quit}))
+ input (println (str "> " (print-str (EVAL (READ input) @oblist))))
:else (println)))
(catch
Exception
@@ -26,28 +41,40 @@
data
(case (:cause data)
:parse-failure (println (:failure data))
+ :strict nil ;; the message, which has already been printed, is enough.
:quit (throw e)
;; default
(pprint data))))))
(recur)))
(defn -main
- [& args]
- (println
- (str
- "Hider wilcuman. Béowulf is mín nama\nSíðe "
- (System/getProperty "beowulf.version")
- "\n\n"))
- (try
- (repl)
- (catch
- Exception
- e
- (let [data (ex-data e)]
+ "Parse options, print the banner, read the init file if any, and enter the
+ read/eval/print loop."
+ [& opts]
+ (let [args (parse-opts opts cli-options)]
+ (println
+ (str
+ "\nHider wilcuman. Béowulf is mín nama.\n"
(if
- data
- (case (:cause data)
- :quit nil
- ;; default
- (pprint data))
- (println e))))))
+ (System/getProperty "beowulf.version")
+ (str "Síðe " (System/getProperty "beowulf.version") "\n"))
+ (if
+ (:help (:options args))
+ (:summary args))
+ (if (:errors args)
+ (apply str (interpose "; " (:errors args))))
+ "\nSprecan 'quit' tó laéfan\n"))
+ (binding [*options* (:options args)]
+ (try
+ (repl (str (:prompt (:options args)) " "))
+ (catch
+ Exception
+ e
+ (let [data (ex-data e)]
+ (if
+ data
+ (case (:cause data)
+ :quit nil
+ ;; default
+ (pprint data))
+ (println e))))))))
diff --git a/src/beowulf/host.clj b/src/beowulf/host.clj
new file mode 100644
index 0000000..fcd71fd
--- /dev/null
+++ b/src/beowulf/host.clj
@@ -0,0 +1,5 @@
+(ns beowulf.host
+ "provides Lisp 1.5 functions which can't be (or can't efficiently
+ be) implemented in Lisp 1.5, which therefore need to be implemented in the
+ host language, in this case Clojure.")
+
diff --git a/src/beowulf/read.clj b/src/beowulf/read.clj
index 9a91807..7490911 100644
--- a/src/beowulf/read.clj
+++ b/src/beowulf/read.clj
@@ -1,10 +1,31 @@
(ns beowulf.read
- (:require [clojure.math.numeric-tower :refer [expt]]
+ "This provides the reader required for boostrapping. It's not a bad
+ reader - it provides feedback on errors found in the input - but it isn't
+ the real Lisp reader.
+
+ Intended deviations from the behaviour of the real Lisp reader are as follows:
+
+ 1. It reads the meta-expression language `MEXPR` in addition to the
+ symbolic expression language `SEXPR`, which I do not believe the Lisp 1.5
+ reader ever did;
+ 2. It treats everything between a semi-colon and an end of line as a comment,
+ as most modern Lisps do; but I do not believe Lisp 1.5 had this feature.
+
+ Both these extensions can be disabled by using the `--strict` command line
+ switch."
+ (:require [beowulf.bootstrap :refer [*options*]]
+ [clojure.math.numeric-tower :refer [expt]]
[clojure.string :refer [starts-with? upper-case]]
[instaparse.core :as i]
- [beowulf.cons-cell :refer [make-beowulf-list make-cons-cell NIL]])
-;; (:import [beowulf.cons-cell ConsCell])
- )
+ [beowulf.cons-cell :refer [make-beowulf-list make-cons-cell NIL]]))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;
+;;; This file provides the reader required for boostrapping. It's not a bad
+;;; reader - it provides feedback on errors found in the input - but it isn't
+;;; the real Lisp reader.
+;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(declare generate)
@@ -18,7 +39,7 @@
;; mexprs. I'm pretty clear that Lisp 1.5 could never read these,
;; but it's a convenience.
- "mexpr := λexpr | fncall | defn | cond | mvar;
+ "mexpr := λexpr | fncall | defn | cond | mvar | mexpr comment;
λexpr := λ lsqb bindings semi-colon body rsqb;
λ := 'λ';
bindings := lsqb args rsqb;
@@ -35,9 +56,12 @@
mvar := #'[a-z]+';
semi-colon := ';';"
+ ;; comments. I'm pretty confident Lisp 1.5 did NOT have these.
+ "comment := opt-space <';;'> #'[^\\n\\r]*';"
+
;; sexprs. Note it's not clear to me whether Lisp 1.5 had the quote macro,
;; but I've included it on the basis that it can do little harm.
- "sexpr := quoted-expr | atom | number | dotted-pair | list;
+ "sexpr := quoted-expr | atom | number | dotted-pair | list | sexpr comment;
list := lpar sexpr rpar | lpar (sexpr sep)* rpar | lpar (sexpr sep)* dot-terminal;
dotted-pair := lpar dot-terminal ;
dot := '.';
@@ -89,6 +113,11 @@
(= context :mexpr)
[:quoted-expr p]
p)
+ :comment (if
+ (:strict *options*)
+ (throw
+ (ex-info "Cannot parse comments in strict mode"
+ {:cause :strict})))
:dotted-pair (if
(= context :mexpr)
[:fncall
@@ -97,7 +126,12 @@
(simplify (nth p 1) context)
(simplify (nth p 2) context)]]
(map simplify p))
- :mexpr (simplify (second p) :mexpr)
+ :mexpr (if
+ (:strict *options*)
+ (throw
+ (ex-info "Cannot parse meta expressions in strict mode"
+ {:cause :strict}))
+ (simplify (second p) :mexpr))
:list (if
(= context :mexpr)
[:fncall
@@ -109,7 +143,6 @@
p)))
-
;; # From Lisp 1.5 Programmers Manual, page 10
;; Note that I've retyped much of this, since copy/pasting out of PDF is less
;; than reliable. Any typos are mine. Quote starts [[
@@ -185,9 +218,7 @@
(defn gen-fn-call
"Generate a function call from this simplified parse tree fragment `p`;
- returns `nil` if `p` does not represent a (MEXPR) function call.
- TODO: I'm not yet certain but it appears that args in mexprs are
- implicitly quoted; this function does not (yet) do that."
+ returns `nil` if `p` does not represent a (MEXPR) function call."
[p]
(if
(and (coll? p)(= :fncall (first p))(= :mvar (first (second p))))
@@ -290,5 +321,7 @@
`(generate (simplify (parse ~s))))
(defn READ
+ "An implementation of a Lisp reader sufficient for bootstrapping; not necessarily
+ the final Lisp reader."
[input]
(gsp (or input (read-line))))
diff --git a/test/beowulf/bootstrap_test.clj b/test/beowulf/bootstrap_test.clj
index 57444eb..25ac23d 100644
--- a/test/beowulf/bootstrap_test.clj
+++ b/test/beowulf/bootstrap_test.clj
@@ -2,7 +2,7 @@
(:require [clojure.math.numeric-tower :refer [abs]]
[clojure.test :refer :all]
[beowulf.cons-cell :refer [make-beowulf-list make-cons-cell NIL T F]]
- [beowulf.eval :refer :all]
+ [beowulf.bootstrap :refer :all]
[beowulf.read :refer [gsp]]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -176,16 +176,24 @@
(deftest member-tests
(testing "member"
(let [expected 'T
- actual (MEMBER (gsp "ALBERT") (gsp "(ALBERT BELINDA CHARLIE DORIS ELFREDA FRED)"))]
+ actual (MEMBER
+ (gsp "ALBERT")
+ (gsp "(ALBERT BELINDA CHARLIE DORIS ELFREDA FRED)"))]
(= actual expected))
(let [expected 'T
- actual (MEMBER (gsp "BELINDA") (gsp "(ALBERT BELINDA CHARLIE DORIS ELFREDA FRED)"))]
+ actual (MEMBER
+ (gsp "BELINDA")
+ (gsp "(ALBERT BELINDA CHARLIE DORIS ELFREDA FRED)"))]
(= actual expected))
(let [expected 'T
- actual (MEMBER (gsp "ELFREDA") (gsp "(ALBERT BELINDA CHARLIE DORIS ELFREDA FRED)"))]
+ actual (MEMBER
+ (gsp "ELFREDA")
+ (gsp "(ALBERT BELINDA CHARLIE DORIS ELFREDA FRED)"))]
(= actual expected))
(let [expected 'F
- actual (MEMBER (gsp "BERTRAM") (gsp "(ALBERT BELINDA CHARLIE DORIS ELFREDA FRED)"))]
+ actual (MEMBER
+ (gsp "BERTRAM")
+ (gsp "(ALBERT BELINDA CHARLIE DORIS ELFREDA FRED)"))]
(= actual expected))))
(deftest pairlis-tests
diff --git a/test/beowulf/cons_cell_test.clj b/test/beowulf/cons_cell_test.clj
new file mode 100644
index 0000000..7476db9
--- /dev/null
+++ b/test/beowulf/cons_cell_test.clj
@@ -0,0 +1,57 @@
+(ns beowulf.core-test
+ (:require [clojure.test :refer :all]
+ [beowulf.cons-cell :refer :all]))
+
+(deftest cons-cell-tests
+ (testing "make-cons-cell"
+ (let [expected "(A . B)"
+ actual (print-str (beowulf.cons_cell.ConsCell. 'A 'B))]
+ (is (= actual expected) "Cons cells should print as cons cells, natch."))
+ (let [expected "(A . B)"
+ actual (print-str (make-cons-cell 'A 'B))]
+ (is (= actual expected) "Even if build with the macro."))
+ (let [expected beowulf.cons_cell.ConsCell
+ actual (print-str (make-cons-cell 'A 'B))]
+ (is (= actual expected) "And they should be cons cells."))
+ )
+ (testing "make-beowulf-list"
+ (let [expected "(A (B C) (D E (F) G) H)"
+ actual (print-str (make-beowulf-list '(A (B C) (D E (F) G) H)))]
+ (is (= actual expected) "Should work for clojure lists, recursively."))
+ (let [expected "(A (B C) (D E (F) G) H)"
+ actual (print-str (make-beowulf-list [A [B C] [D E [F] G] H]))]
+ (is (= actual expected) "Should work for vectors, too."))
+ (let [expected "NIL"
+ actual (print-str (make-beowulf-list []))]
+ (is (= actual expected) "An empty sequence is NIL."))
+ (let [expected beowulf.cons_cell.ConsCell
+ actual (make-beowulf-list '(A (B C) (D E (F) G) H))]
+ (is (= actual expected) "A beowulf list is made of cons cells.")))
+ (testing "pretty-print"
+ (let [expected "(A\n (B C)\n (D E (F) G) H)"
+ actual (pretty-print (make-beowulf-list '(A (B C) (D E (F) G) H)) 20 0)]
+ (is (= actual expected)))
+ (let [expected "(A (B C) (D E (F) G) H)"
+ actual (pretty-print (make-beowulf-list '(A (B C) (D E (F) G) H)))]
+ (is (= actual expected))))
+ (testing "count"
+ (let [expected 4
+ actual (count (make-beowulf-list '(A (B C) (D E (F) G) H)) 20 0)]
+ (is (= actual expected)))
+ (let [expected 1
+ actual (count (make-beowulf-list '(A)))]
+ (is (= actual expected)))
+ (let [expected 1
+ actual (count (make-cons-cell 'A 'B))]
+ (is (= actual expected))))
+ (testing "sequence functions"
+ (let [expected "A"
+ actual (print-str (first (make-beowulf-list '(A (B C) (D E (F) G) H))))]
+ (is (= actual expected)))
+ (let [expected "((B C) (D E (F) G) H)"
+ actual (print-str (more (make-beowulf-list '(A (B C) (D E (F) G) H))))]
+ (is (= actual expected)))
+ (let [expected "((B C) (D E (F) G) H)"
+ actual (print-str (next (make-beowulf-list '(A (B C) (D E (F) G) H))))]
+ (is (= actual expected)))
+ ))
diff --git a/test/beowulf/core_test.clj b/test/beowulf/core_test.clj
index 2b10204..96b55ef 100644
--- a/test/beowulf/core_test.clj
+++ b/test/beowulf/core_test.clj
@@ -1,7 +1,175 @@
(ns beowulf.core-test
- (:require [clojure.test :refer :all]
+ (:require [clojure.java.io :refer [reader]]
+ [clojure.string :refer [split]]
+ [clojure.test :refer :all]
[beowulf.core :refer :all]))
;; (deftest a-test
;; (testing "FIXME, I fail."
;; (is (= 0 1))))
+
+(defn string->stream
+ "Copied shamelessly from
+ https://stackoverflow.com/questions/38283891/how-to-wrap-a-string-in-an-input-stream"
+ ([s] (string->stream s "UTF-8"))
+ ([s encoding]
+ (-> s
+ (.getBytes encoding)
+ (java.io.ByteArrayInputStream.))))
+
+(deftest repl-tests
+ (testing "quit functionality"
+ (with-open [r (reader (string->stream "quit"))]
+ (binding [*in* r]
+ (is (thrown-with-msg? Exception #"\nFærwell!" (repl "")))))
+
+ (let [expected nil
+ actual (with-open [r (reader (string->stream "quit"))]
+ (binding [*in* r]
+ (-main)))]
+ (is (= actual expected)))))
+
+(deftest flag-tests
+ (testing "No flags"
+ (let [expected-greeting "Hider wilcuman. Béowulf is mín nama."
+ expected-quit-message "Sprecan 'quit' tó laéfan"
+ expected-error ""
+ expected-result #".*\(A \. B\)"
+ expected-prompt "Sprecan:: "
+ expected-signoff "Færwell!"
+ [_ greeting version error quit-message _ result prompt signoff]
+ (with-open [r (reader (string->stream "cons[A; B]\nquit"))]
+ (binding [*in* r]
+ (split (with-out-str (-main)) #"\n")))]
+ (is (= greeting expected-greeting))
+ (is (= error expected-error))
+ (is (re-matches expected-result result))
+ (is (= quit-message expected-quit-message))
+ (is (= prompt expected-prompt))
+ (is (= signoff expected-signoff))
+ ))
+ (testing "unknown flag"
+ (let [expected-greeting "Hider wilcuman. Béowulf is mín nama."
+ expected-quit-message "Sprecan 'quit' tó laéfan"
+ expected-error #"Unknown option:.*"
+ expected-result #".*\(A \. B\)"
+ expected-prompt "Sprecan:: "
+ expected-signoff "Færwell!"
+ [_ greeting version error quit-message _ result prompt signoff]
+ (with-open [r (reader (string->stream "cons[A; B]\nquit"))]
+ (binding [*in* r]
+ (split (with-out-str (-main "--unknown")) #"\n")))]
+ (is (= greeting expected-greeting))
+ (is (re-matches expected-error error))
+ (is (re-matches expected-result result))
+ (is (= quit-message expected-quit-message))
+ (is (= prompt expected-prompt))
+ (is (= signoff expected-signoff))
+ ))
+ (testing "help"
+ (let [expected-greeting "Hider wilcuman. Béowulf is mín nama."
+ expected-h1 " -h, --help"
+ expected-quit-message "Sprecan 'quit' tó laéfan"
+ expected-result #".*\(A \. B\)"
+ expected-prompt "Sprecan:: "
+ expected-signoff "Færwell!"
+ [_ greeting version h1 h2 h3 h4 h5 quit-message _ result prompt signoff]
+ (with-open [r (reader (string->stream "cons[A; B]\nquit"))]
+ (binding [*in* r]
+ (split (with-out-str (-main "--help")) #"\n")))]
+ (is (= greeting expected-greeting))
+ (is (= h1 expected-h1))
+ (is (re-matches expected-result result))
+ (is (= quit-message expected-quit-message))
+ (is (= prompt expected-prompt))
+ (is (= signoff expected-signoff))
+ ))
+ (testing "prompt"
+ (let [expected-greeting "Hider wilcuman. Béowulf is mín nama."
+ expected-quit-message "Sprecan 'quit' tó laéfan"
+ expected-error ""
+ expected-result #".*\(A \. B\).*"
+ expected-prompt "? "
+ expected-signoff "Færwell!"
+ [_ greeting version error quit-message _ result prompt signoff]
+ (with-open [r (reader (string->stream "cons[A; B]\nquit"))]
+ (binding [*in* r]
+ (split (with-out-str (-main "--prompt" "?")) #"\n")))]
+ (is (= greeting expected-greeting))
+ (is (= error expected-error))
+ (is (re-matches expected-result result ))
+ (is (= quit-message expected-quit-message))
+ (is (= prompt expected-prompt))
+ (is (= signoff expected-signoff))
+ ))
+ (testing "read - file not found"
+ (let [expected-greeting "Hider wilcuman. Béowulf is mín nama."
+ expected-quit-message "Sprecan 'quit' tó laéfan"
+ expected-error #"Failed to validate.*"
+ expected-result #".*\(A \. B\)"
+ expected-prompt "Sprecan:: "
+ expected-signoff "Færwell!"
+ [_ greeting version error quit-message _ result prompt signoff]
+ (with-open [r (reader (string->stream "cons[A; B]\nquit"))]
+ (binding [*in* r]
+ (split (with-out-str (-main "--read" "froboz")) #"\n")))]
+ (is (= greeting expected-greeting))
+ (is (re-matches expected-error error))
+ (is (re-matches expected-result result))
+ (is (= quit-message expected-quit-message))
+ (is (= prompt expected-prompt))
+ (is (= signoff expected-signoff))
+ ))
+ (testing "read - file found"
+ ;; TODO: there's no feedback from this because the initfile
+ ;; is not yet read. This will change
+ (let [expected-greeting "Hider wilcuman. Béowulf is mín nama."
+ expected-quit-message "Sprecan 'quit' tó laéfan"
+ expected-error ""
+ expected-result #".*\(A \. B\)"
+ expected-prompt "Sprecan:: "
+ expected-signoff "Færwell!"
+ [_ greeting version error quit-message _ result prompt signoff]
+ (with-open [r (reader (string->stream "cons[A; B]\nquit"))]
+ (binding [*in* r]
+ (split (with-out-str (-main "--read" "README.md")) #"\n")))]
+ (is (= greeting expected-greeting))
+ (is (= error expected-error))
+ (is (re-matches expected-result result))
+ (is (= quit-message expected-quit-message))
+ (is (= prompt expected-prompt))
+ (is (= signoff expected-signoff))
+ ))
+ (testing "strict"
+ (let [expected-greeting "Hider wilcuman. Béowulf is mín nama."
+ expected-quit-message "Sprecan 'quit' tó laéfan"
+ expected-error ""
+ expected-result #".*Cannot parse meta expressions in strict mode.*"
+ expected-prompt "Sprecan:: "
+ expected-signoff "Færwell!"
+ [_ greeting version error quit-message _ result prompt signoff]
+ (with-open [r (reader (string->stream "cons[A; B]\nquit"))]
+ (binding [*in* r]
+ (split (with-out-str (-main "--strict")) #"\n")))]
+ (is (= greeting expected-greeting))
+ (is (= error expected-error))
+ (is (re-matches expected-result result ))
+ (is (= quit-message expected-quit-message))
+ (is (= prompt expected-prompt))
+ (is (= signoff expected-signoff))
+ ))
+ (testing "trace"
+ (let [expected-greeting "Hider wilcuman. Béowulf is mín nama."
+ expected-quit-message "Sprecan 'quit' tó laéfan"
+ expected-error ""
+ expected-trace #".*traced-eval.*"
+ [_ greeting version error quit-message _ trace & _]
+ (with-open [r (reader (string->stream "cons[A; B]\nquit"))]
+ (binding [*in* r]
+ (split (with-out-str (-main "--trace")) #"\n")))]
+ (is (= greeting expected-greeting))
+ (is (= error expected-error))
+ (is (re-matches expected-trace trace))
+ ))
+
+ )
diff --git a/test/beowulf/mexpr_test.clj b/test/beowulf/mexpr_test.clj
index 51c062e..92dc201 100644
--- a/test/beowulf/mexpr_test.clj
+++ b/test/beowulf/mexpr_test.clj
@@ -1,6 +1,9 @@
(ns beowulf.mexpr-test
+ "These tests are taken generally from the examples on page 10 of
+ Lisp 1.5 Programmers Manual"
(:require [clojure.test :refer :all]
- [beowulf.read :refer [parse simplify generate]]))
+ [beowulf.bootstrap :refer [*options*]]
+ [beowulf.read :refer [parse simplify generate gsp]]))
;; These tests are taken generally from the examples on page 10 of
;; Lisp 1.5 Programmers Manual:
@@ -64,4 +67,10 @@
(parse "label[ff;λ[[x];[atom[x]->x; T->ff[car[x]]]]]"))))]
(is (= actual expected)))))
-;; (parse "equal[x;y] = [atom[x]->[atom[y]->eq[x;y]; T->F]; equal[car[x]; car[y]]->equal[cdr[x];cdr[y]];T->F]")
+(deftest strict-tests
+ (testing "Strict feature"
+ (binding [*options* {:strict true}]
+ (is (thrown-with-msg?
+ Exception
+ #"Cannot parse meta expressions in strict mode"
+ (gsp "label[ff;λ[[x];[atom[x]->x; T->ff[car[x]]]]]"))))))
diff --git a/test/beowulf/sexpr_test.clj b/test/beowulf/sexpr_test.clj
index 98d3358..fe665a1 100644
--- a/test/beowulf/sexpr_test.clj
+++ b/test/beowulf/sexpr_test.clj
@@ -2,7 +2,8 @@
(:require [clojure.math.numeric-tower :refer [abs]]
[clojure.test :refer :all]
[beowulf.cons-cell :refer :all]
- [beowulf.read :refer [parse simplify generate]]))
+ [beowulf.bootstrap :refer [*options*]]
+ [beowulf.read :refer [parse simplify generate gsp]]))
;; broadly, sexprs should be homoiconic
@@ -24,6 +25,32 @@
actual (generate (simplify (parse (str expected))))]
(is (= actual expected)))))
+(deftest comment-tests
+ (testing "Reading comments"
+ (let [expected 'A
+ actual (gsp "A ;; comment")]
+ (is (= actual expected)))
+ (let [expected 10
+ actual (gsp "10 ;; comment")]
+ (is (= actual expected)))
+ (let [expected 2/5
+ actual (gsp "4E-1 ;; comment")]
+ (is (= actual expected)))
+ (let [expected "(A B C)"
+ actual (print-str (gsp "(A ;; comment
+ B C)"))]
+ (is (= actual expected)
+ "Really important that comments work inside lists"))
+;; ;; TODO: Currently failing and I'm not sure why
+;; (binding [*options* {:strict true}]
+;; (is (thrown-with-msg?
+;; Exception
+;; #"Cannot parse comments in strict mode"
+;; (gsp "(A ;; comment
+;; B C)"))))
+ ))
+
+
(deftest number-tests
(testing "Reading octal numbers"
(let [expected 1