"; if( ("body" in document) && (document.body != null) ) { document.body.appendChild( tmp ); document.body.removeChild( tmp ); } else { if( ("documentElement" in document) && (document.documentElement != null) ) { document.documentElement.appendChild( tmp ); document.documentElement.removeChild( tmp ); } else { var body = document.getElementsByTagName( "body" )[ 0 ]; body.appendChild( tmp ); body.removeChild( tmp ); } } } catch( e ) { ; } function hop_properties_to_string( obj ) { var res = ""; var i = 0; for( var p in obj ) { if( i === 10 ) { res += p + "\n"; i = 0; } else { i++; res += p + " "; } } return res; } function hop_properties_values_to_string( obj ) { var res = ""; var i = 0; for( var p in obj ) { if( i === 10 ) { res += p + "=" + obj[ p ] + "\n"; i = 0; } else { i++; res += p + "=" + obj[ p ] + " "; } } return res; } var hop_is_html_element; if( !("HTMLElement" in window) ) { hop_is_html_element = function hop_is_html_element( obj ) { return (obj != null) && (((obj instanceof Object) || (typeof obj == "object")) && (typeof obj.innerHTML == "string")); } } else { var ifr = document.createElement( "iframe" ); if( ifr instanceof HTMLElement ) { hop_is_html_element = function hop_is_html_element( obj ) { return (obj != null) && (obj instanceof HTMLElement); } } else { var ifproto = ifr.__proto__; hop_is_html_element = function hop_is_html_element( obj ) { return (obj instanceof HTMLElement) || (obj.__proto__ == ifproto); } } } var hop_is_dom_form_element; try { if( undefined instanceof HTMLFormElement ) { hop_is_dom_form_element = function hop_is_dom_form_element( obj ) { return false; }; } else { hop_is_dom_form_element = function hop_is_dom_form_element( obj ) { return obj instanceof HTMLFormElement; }; } } catch( e ) { hop_is_dom_form_element = function hop_is_dom_form_element( obj ) { return hop_is_html_element( obj ) && (obj.tagName === "form"); }; } if( !("HTMLCollection" in window) ) { window.HTMLCollection = function() { return false; }; } if( !("HTMLInputElement" in window) ) { window.HTMLInputElement = function() { return false; }; } if( !("HTMLTextAreaElement" in window) ) { window.HTMLTextAreaElement = function() { return false; }; } if( !("HTMLSelectElement" in window) ) { window.HTMLSelectElement = function() { return false; }; } var hop_make_xml_http_request; if( "XMLHttpRequest" in window ) { var req = new XMLHttpRequest(); if( "overrideMimeType" in req ) { hop_make_xml_http_request = function hop_make_xml_http_request() { var req = new XMLHttpRequest(); return req; } } else { hop_make_xml_http_request = function hop_make_xml_http_request() { return new XMLHttpRequest(); } } } else { if( "ActiveXObject" in window ) { hop_make_xml_http_request = function hop_make_xml_http_request() { try { return new ActiveXObject( "Msxml2.XMLHTTP" ); } catch( e ) { try { return new ActiveXObject( "Microsoft.XMLHTTP" ); } catch( e ) { alert( "*** ERROR: Don't know how to create XMLHttpRequest" ); } } } } else { if( "XMLHttpRequest" in window ) { hop_make_xml_http_request = function hop_make_xml_http_request() { return new XMLHttpRequest(); } } else { hop_make_xml_http_request = function hop_make_xml_http_request() { alert( "*** ERROR: Don't know how to create XMLHttpRequest" ); } } } } var hop_header_content_type; var hop_header_autoconf = hop_make_xml_http_request(); if( typeof hop_header_autoconf.getResponseHeader == "function" ) { hop_header_content_type = function hop_header_content_type( http ) { var h = http.getResponseHeader( "Content-Type" ); if( h ) { var i = h.indexOf( ";" ); if( i >= 0 ) { return h.substring( 0, i ); } else { return h; } } else { return "application/text"; } } } else { hop_header_content_type = function hop_header_content_type( http ) { var hds = http.getAllResponseHeaders(); var i = hds.indexOf( "Content-Type" ); if( i < 0 ) i = hds.indexOf( "content-type" ); if( i < 0 ) i = hds.indexOf( "Content-type" ); if( i < 0 ) return "application/text"; var j = hds.indexOf( "\n", i + 1 ); var s = (j >= 0) ? hds.substring( i, j ) : hds.substring( i, s.length ); var m = s.match( "[ \t:]+([^ \n;]*)" ); if( m ) return m[ 1 ]; else return "application/text"; } } function node_style_set_native( obj, prop, value ) { if( (obj instanceof String) || (typeof obj === "string") ) obj = document.getElementById( obj ); if( sc_isKeyword( prop ) ) prop = sc_keyword2jsstring( prop ); if( !(value instanceof String) && (typeof value !== "string") ) { if( !value && (value != 0) ) { sc_error( "node-style-set!", "Illegal \"" + prop + "\" value", value ); } else { value = value.toString(); } } if( !obj || !obj.style ) { sc_error( "node-style-set!", "Illegal object", obj + ", " + prop + ": " + value ); } if( prop in obj.style ) { obj.style[ prop ] = value; } else { obj.style.setProperty( prop, value, "" ); } } function node_style_set_array( obj, prop, value ) { if( (obj instanceof String) || (typeof obj === "string") ) obj = document.getElementById( obj ); if( sc_isKeyword( prop ) ) prop = sc_keyword2jsstring( prop ); if( !(value instanceof String) && (typeof value !== "string") ) { if( !value && (value != 0) ) { sc_error( "node-style-set!", "Illegal \"" + prop + "\" value", value ); } else { value = value.toString(); } } obj.style[ prop ] = value; } var node_style_set = function( obj, property, value ) { if( (obj instanceof String) || (typeof obj === "string") ) obj = document.getElementById( obj ); if( "setProperty" in obj.style ) { node_style_set = node_style_set_native; return node_style_set_native( obj, property, value ); } else { node_style_set = node_style_set_array; return node_style_set_array( obj, property, value ); } } var hop_active_location_timeout = ((hop_config.cpu_speed < 66) ? 100 : 250); var hop_has_setInterval = true; try { var i = setInterval( function() { ; }, 1000 ); clearInterval( i ); } catch( e ) { var hop_has_setInterval = false; } var hop_add_native_event_listener = undefined; var hop_remove_native_event_listener = undefined; var hop_stop_propagation = undefined; var hop_has_event20 = false; try { hop_has_event20 = document.implementation.hasFeature( "Events" , "2.0" ); } catch( e ) { ; } if( hop_has_event20 ) { hop_add_native_event_listener = function( obj, event, proc, capture ) { if( "addEventListener" in obj ) { var f = hop_callback( proc ); var i = "on" + event + "hdl"; if( !(i in obj ) ) obj[ i ] = []; obj[ i ][ proc ] = f; return obj.addEventListener( event, f, capture ); } else { throw new Error( "add-event-listener!: cannot add `" + event + "' listener for object: " + obj ); } } hop_remove_native_event_listener = function( obj, event, proc, capture ) { if( "removeEventListener" in obj ) { var i = "on" + event + "hdl"; var h = obj[ i ]; if( h !== undefined ) { var p = obj[ i ][ proc ]; if( p !== undefined ) { h[ p ] = undefined; return obj.removeEventListener( event, p, capture ); } } } else { throw new Error( "remove-event-listener!: cannot remove `" + event + "' listener for object: " + obj ); } } hop_stop_propagation = function( event, def ) { if( !def ) event.preventDefault(); event.stopPropagation(); event.isStopped = true; } } else { hop_add_native_event_listener = function( obj, event, proc, capture ) { var f = hop_callback( proc ); var p = function(_) { return f( window.event ) }; var i = "on" + event + "hdl"; if( obj[ i ] === undefined ) obj[ i ] = []; obj[ i ][ proc ] = p; return obj.attachEvent( "on" + event, p ); } hop_remove_native_event_listener = function( obj, event, proc, capture ) { var i = "on" + event + "hdl"; var h = obj[ i ]; if( h !== undefined ) { var p = obj[ i ][ proc ]; if( p !== undefined ) { h[ p ] = undefined; return obj.detachEvent( "on" + event, p ); } } return false; } hop_stop_propagation = function( event, def ) { if( !def ) event.cancelBubble = true; event.returnValue = false; event.isStopped = true; } } function hop_deinline_image( el, src ) { if( !el.deinlined ) { el.deinlined = true; el.src = src; } } var hop_event_mouse_x = undefined; var hop_event_mouse_y = undefined; var hop_event_mouse_button = undefined; var hop_event_key_code = undefined; /*** META ((export event-value) (arity #t) (peephole: (postfix ".value"))) */ function hop_event_value( evt ) { return evt.value; } /*** META ((export event-response-text) (arity #t) (peephole: (postfix ".responseText"))) */ function hop_event_response_text( evt ) { return evt.responseText; } if( hop_has_event20 ) { hop_event_mouse_x = function hop_event_mouse_x( event ) { return event.pageX; } hop_event_mouse_y = function hop_event_mouse_y( event ) { return event.pageY; } hop_event_key_code = function hop_event_key_code( event ) { return event.which; } } else { hop_event_mouse_x = function hop_event_mouse_x( event ) { if( (document.body != null) && (document.documentElement.scrollLeft != null) ) { return event.clientX + document.documentElement.scrollLeft; } else { return event.clientX + document.body.scrollLeft; } } hop_event_mouse_y = function hop_event_mouse_y( event ) { if( (document.body != null) && (document.documentElement.scrollTop != null) ) { return event.clientY + document.documentElement.scrollTop; } else { return event.clientY + document.body.scrollTop; } } hop_event_key_code = function hop_event_key_code( event ) { return event.keyCode; } } switch( hop_config.mouse_left_button ) { case 0: hop_event_mouse_button = function hop_event_mouse_button( e ) { return e.button + 1; }; break; case 1: hop_event_mouse_button = function hop_event_mouse_button( e ) { return e.button; } break; default: hop_event_mouse_button = function hop_event_mouse_button( e ) { return e.button + (1 - hop_config.mouse_left_button); } } var hop_current_window_width = undefined; var hop_current_window_height = undefined; if( isNaN( window.innerWidth ) ) { hop_current_window_width = function hop_current_window_width() { return document.documentElement.clientWidth; } hop_current_window_height = function hop_current_window_height() { return document.documentElement.clientHeight; } } else { hop_current_window_width = function hop_current_window_width() { return window.innerWidth; } hop_current_window_height = function hop_current_window_height() { return window.innerHeight; } } function hop_iframe_scroll_height( e ) { if( "contentDocument" in e ) { return e.contentDocument.body.scrollHeight; } else { if( "document" in e ) { return e.document.body.scrollHeight; } else { return iframe.height; } } } function hop_iframe_scroll_width( e ) { if( "contentDocument" in e ) { return e.contentDocument.body.scrollWidth; } else { if( "document" in e ) { return e.document.body.scrollWidth; } else { return iframe.width; } } } var hop_get_selection; if( window.getSelection ) { hop_get_selection = function hop_get_selection() { return window.getSelection().toString(); } } else { if( document.getSelection ) { hop_get_selection = function hop_get_selection() { return document.getSelection().toString(); } } else { hop_get_selection = function hop_get_selection() { if( document.selection ) { return document.selection.createRange().text; } else { return ""; } } } } /* * To use write/prints/... the default-output port has to be set first. * Simply setting SC_DEFAULT_OUT and SC_ERROR_OUT to the desired values * should do the trick. * In the following example the std-out and error-port are redirected to * a DIV. function initRuntime() { function escapeHTML(s) { var tmp = s; tmp = tmp.replace(/&/g, "&"); tmp = tmp.replace(//g, ">"); tmp = tmp.replace(/ /g, " "); tmp = tmp.replace(/\n/g, "
"); tmp = tmp.replace(/\t/g, "    "); return tmp; } document.write("
"); SC_DEFAULT_OUT = new sc_GenericOutputPort( function(s) { var stdout = document.getElementById('stdout'); stdout.innerHTML = stdout.innerHTML + escapeHTML(s); }); SC_ERROR_OUT = SC_DEFAULT_OUT; } */ function sc_print_debug() { sc_print.apply(null, arguments); } var sc_JS_GLOBALS = this; var __sc_LINE=-1; var __sc_FILE=""; /*** META ((export #t) (arity -1)) */ function sc_alert() { var len = arguments.length; var s = ""; var i; for( i = 0; i < len; i++ ) { s += sc_toDisplayString(arguments[ i ]); } return alert( s ); } function sc_typeof( x ) { return typeof x; } var __sc_errorHook = false; function sc_errorHookSet( h ) { __sc_errorHook = h; } function sc_errorHook() { return __sc_errorHook; } function sc_error() { var e = new Error("sc_error"); if (arguments.length >= 1) { e.name = arguments[0]; if (arguments.length >= 2) { e.message = arguments[1]; if (arguments.length >= 3) { e.scObject = arguments[2]; } } } throw __sc_errorHook ? __sc_errorHook( e, arguments ) : e; } function sc_arity_check(fun, nbArgs) { var fun_arity = fun.sc_arity; if (fun_arity === undefined || fun_arity === false) return fun; if (fun_arity >= 0 && nbArgs == fun_arity) return fun; if (fun_arity < 0 && nbArgs >= -1-fun_arity) return fun; var errorMsg = "Wrong number of arguments: " + fun_arity + " expected, " + nbArgs + " provided"; var where = ("callee" in arguments && "caller" in arguments.callee ? ("name" in arguments.callee.caller ? arguments.callee.caller.name : arguments.callee.caller) : "arity-check"); sc_error(where, errorMsg, fun); return undefined; } function sc_raise(obj) { throw obj; } function sc_withHandlerLambda(handler, body) { try { return body(); } catch(e) { if (!e._internalException) return handler(e); else throw e; } } var sc_properties = new Object(); function sc_putpropBang(sym, key, val) { var ht = sc_properties[sym]; if (!ht) { ht = new Object(); sc_properties[sym] = ht; } ht[key] = val; } function sc_getprop(sym, key) { var ht = sc_properties[sym]; if (ht) { if (key in ht) return ht[key]; else return false; } else return false; } function sc_rempropBang(sym, key) { var ht = sc_properties[sym]; if (ht) delete ht[key]; } function sc_any2String(o) { return jsstring2string(sc_toDisplayString(o)); } /*** META ((export #t) (arity #t) (peephole (infix 2 2 "===")) (type bool)) */ function sc_isEqv(o1, o2) { return (o1 === o2); } /*** META ((export #t) (arity #t) (peephole (infix 2 2 "===")) (type bool)) */ function sc_isEq(o1, o2) { return (o1 === o2); } /*** META ((export #t) (arity #t) (type bool)) */ function sc_isNumber(n) { return (typeof n === "number"); } /*** META ((export #t) (arity #t) (type bool)) */ function sc_isComplex(n) { return sc_isNumber(n); } /*** META ((export #t) (arity #t) (type bool)) */ function sc_isReal(n) { return sc_isNumber(n); } /*** META ((export #t) (arity #t) (type bool)) */ function sc_isRational(n) { return sc_isReal(n); } /*** META ((export #t) (arity #t) (type bool)) */ function sc_isInteger(n) { return (parseInt(n) === n); } /*** META ((export #t) (arity #t) (type bool) (peephole (postfix ", false"))) */ function sc_isExact(n) { return false; } /*** META ((export #t) (arity #t) (peephole (postfix ", true")) (type bool)) */ function sc_isInexact(n) { return true; } /*** META ((export = =fx =fl) (type bool) (peephole (infix 2 2 "===")) (arity -3)) */ function sc_equal(x) { for (var i = 1; i < arguments.length; i++) if (x !== arguments[i]) return false; return true; } /*** META ((export < = arguments[i]) return false; x = arguments[i]; } return true; } /*** META ((export > >fx >fl) (type bool) (peephole (infix 2 2 ">")) (arity -3)) */ function sc_greater(x, y) { for (var i = 1; i < arguments.length; i++) { if (x <= arguments[i]) return false; x = arguments[i]; } return true; } /*** META ((export <= <=fx <=fl) (type bool) (peephole (infix 2 2 "<=")) (arity -3)) */ function sc_lessEqual(x, y) { for (var i = 1; i < arguments.length; i++) { if (x > arguments[i]) return false; x = arguments[i]; } return true; } /*** META ((export >= >=fl >=fx) (type bool) (peephole (infix 2 2 ">=")) (arity -3)) */ function sc_greaterEqual(x, y) { for (var i = 1; i < arguments.length; i++) { if (x < arguments[i]) return false; x = arguments[i]; } return true; } /*** META ((export #t) (arity #t) (type bool) (peephole (postfix "=== 0"))) */ function sc_isZero(x) { return (x === 0); } /*** META ((export #t) (arity #t) (type bool) (peephole (postfix "> 0"))) */ function sc_isPositive(x) { return (x > 0); } /*** META ((export #t) (arity #t) (type bool) (peephole (postfix "< 0"))) */ function sc_isNegative(x) { return (x < 0); } /*** META ((export #t) (arity #t) (type bool) (peephole (postfix "%2===1"))) */ function sc_isOdd(x) { return (x % 2 === 1); } /*** META ((export #t) (arity #t) (type bool) (peephole (postfix "%2===0"))) */ function sc_isEven(x) { return (x % 2 === 0); } /*** META ((export #t) (arity -2)) */ var sc_max = Math.max; /*** META ((export #t) (arity -2)) */ var sc_min = Math.min; /*** META ((export + +fx +fl) (peephole (infix 0 #f "+" "0")) (arity -1)) */ function sc_plus() { var sum = 0; for (var i = 0; i < arguments.length; i++) sum += arguments[i]; return sum; } /*** META ((export * *fx *fl) (peephole (infix 0 #f "*" "1")) (arity -1)) */ function sc_multi() { var product = 1; for (var i = 0; i < arguments.length; i++) product *= arguments[i]; return product; } /*** META ((export - -fx -fl) (peephole (minus)) (arity -2)) */ function sc_minus(x) { if (arguments.length === 1) return -x; else { var res = x; for (var i = 1; i < arguments.length; i++) res -= arguments[i]; return res; } } /*** META ((export / /fl) (peephole (div)) (arity -2)) */ function sc_div(x) { if (arguments.length === 1) return 1/x; else { var res = x; for (var i = 1; i < arguments.length; i++) res /= arguments[i]; return res; } } /*** META ((export #t) (arity 1)) */ var sc_abs = Math.abs; /*** META ((export quotient /fx) (arity #t) (peephole (hole 2 "parseInt(" x "/" y ")"))) */ function sc_quotient(x, y) { return parseInt(x / y); } /*** META ((export #t) (arity #t) (peephole (infix 2 2 "%"))) */ function sc_remainder(x, y) { return x % y; } /*** META ((export #t) (arity #t) (peephole (modulo))) */ function sc_modulo(x, y) { var remainder = x % y; if ((remainder * y) < 0) return remainder + y; else return remainder; } function sc_euclid_gcd(a, b) { var temp; if (a === 0) return b; if (b === 0) return a; if (a < 0) {a = -a;}; if (b < 0) {b = -b;}; if (b > a) {temp = a; a = b; b = temp;}; while (true) { a %= b; if(a === 0) {return b;}; b %= a; if(b === 0) {return a;}; }; return b; } /*** META ((export #t) (arity -1)) */ function sc_gcd() { var gcd = 0; for (var i = 0; i < arguments.length; i++) gcd = sc_euclid_gcd(gcd, arguments[i]); return gcd; } /*** META ((export #t) (arity -1)) */ function sc_lcm() { var lcm = 1; for (var i = 0; i < arguments.length; i++) { var f = Math.round(arguments[i] / sc_euclid_gcd(arguments[i], lcm)); lcm *= Math.abs(f); } return lcm; } /*** META ((export #t) (arity 1)) */ var sc_floor = Math.floor; /*** META ((export #t) (arity 1)) */ var sc_ceiling = Math.ceil; /*** META ((export #t) (arity 1)) */ var sc_truncate = parseInt; /*** META ((export #t) (arity 1)) */ var sc_round = Math.round; /*** META ((export #t) (arity 1)) */ var sc_exp = Math.exp; /*** META ((export #t) (arity 1)) */ var sc_log = Math.log; /*** META ((export #t) (arity 1)) */ var sc_sin = Math.sin; /*** META ((export #t) (arity 1)) */ var sc_cos = Math.cos; /*** META ((export #t) (arity 1)) */ var sc_tan = Math.tan; /*** META ((export #t) (arity 1)) */ var sc_asin = Math.asin; /*** META ((export #t) (arity 1)) */ var sc_acos = Math.acos; /*** META ((export #t) (arity -2)) */ var sc_atan = Math.atan; /*** META ((export #t) (arity 1)) */ var sc_sqrt = Math.sqrt; /*** META ((export #t) (arity 2)) */ var sc_expt = Math.pow; /*** META ((export #t) (arity #t) (peephole (id))) */ function sc_exact2inexact(x) { return x; } /*** META ((export #t) (arity #t) (peephole (postfix "<< 0"))) */ function sc_inexact2exact(x) { return x << 0; } function sc_number2jsstring(x, radix) { if (radix) return x.toString(radix); else return x.toString(); } function sc_jsstring2number(s, radix) { if (s === "") return false; if (radix) { var t = parseInt(s, radix); if (!t && t !== 0) return false; var allowedChars = "01234567890abcdefghijklmnopqrstuvwxyz".substring(0, radix+1); if ((new RegExp("^["+allowedChars+"]*$", "i")).test(s)) return t; else return false; } else { var t = +s; if (!t && t !== 0) return false; var c = s.charAt(0); // if +c is 0, but the char is not "0", then we have a whitespace. if (+c === 0 && c !== "0") return false; return t; } } /*** META ((export #t) (arity #t) (type bool) (peephole (not))) */ function sc_not(b) { return b === false; } /*** META ((export #t) (arity #t) (type bool)) */ function sc_isBoolean(b) { return (b === true) || (b === false); } function sc_Pair(car, cdr) { this.car = car; this.cdr = cdr; } sc_Pair.prototype.toString = function() { return sc_toDisplayString(this); }; sc_Pair.prototype.sc_toWriteOrDisplayString = function(writeOrDisplay) { var current = this; var res = "("; while(true) { res += writeOrDisplay(current.car); if (sc_isPair(current.cdr)) { res += " "; current = current.cdr; } else if (current.cdr !== null) { res += " . " + writeOrDisplay(current.cdr); break; } else break; } res += ")"; return res; }; sc_Pair.prototype.sc_toDisplayString = function() { return this.sc_toWriteOrDisplayString(sc_toDisplayString); }; sc_Pair.prototype.sc_toWriteString = function() { return this.sc_toWriteOrDisplayString(sc_toWriteString); }; /*** META ((export #t) (arity #t) (type bool) (peephole (postfix " instanceof sc_Pair"))) */ function sc_isPair(p) { return (p instanceof sc_Pair); } function sc_isPairEqual(p1, p2, comp) { return (comp(p1.car, p2.car) && comp(p1.cdr, p2.cdr)); } /*** META ((export #t) (arity #t) (peephole (hole 2 "new sc_Pair(" car ", " cdr ")"))) */ function sc_cons(car, cdr) { return new sc_Pair(car, cdr); } /*** META ((export cons*) (arity -2)) */ function sc_consStar() { var res = arguments[arguments.length - 1]; for (var i = arguments.length-2; i >= 0; i--) res = new sc_Pair(arguments[i], res); return res; } /*** META ((export #t) (arity #t) (peephole (postfix ".car"))) */ function sc_car(p) { return p.car; } /*** META ((export #t) (arity #t) (peephole (postfix ".cdr"))) */ function sc_cdr(p) { return p.cdr; } /*** META ((export #t) (arity #t) (peephole (hole 2 p ".car = " val))) */ function sc_setCarBang(p, val) { p.car = val; } /*** META ((export #t) (arity #t) (peephole (hole 2 p ".cdr = " val))) */ function sc_setCdrBang(p, val) { p.cdr = val; } /*** META ((export #t) (arity #t) (peephole (postfix ".car.car"))) */ function sc_caar(p) { return p.car.car; } /*** META ((export #t) (arity #t) (peephole (postfix ".cdr.car"))) */ function sc_cadr(p) { return p.cdr.car; } /*** META ((export #t) (arity #t) (peephole (postfix ".car.cdr"))) */ function sc_cdar(p) { return p.car.cdr; } /*** META ((export #t) (arity #t) (peephole (postfix ".cdr.cdr"))) */ function sc_cddr(p) { return p.cdr.cdr; } /*** META ((export #t) (arity #t) (peephole (postfix ".car.car.car"))) */ function sc_caaar(p) { return p.car.car.car; } /*** META ((export #t) (arity #t) (peephole (postfix ".car.cdr.car"))) */ function sc_cadar(p) { return p.car.cdr.car; } /*** META ((export #t) (arity #t) (peephole (postfix ".cdr.car.car"))) */ function sc_caadr(p) { return p.cdr.car.car; } /*** META ((export #t) (arity #t) (peephole (postfix ".cdr.cdr.car"))) */ function sc_caddr(p) { return p.cdr.cdr.car; } /*** META ((export #t) (arity #t) (peephole (postfix ".car.car.cdr"))) */ function sc_cdaar(p) { return p.car.car.cdr; } /*** META ((export #t) (arity #t) (peephole (postfix ".cdr.car.cdr"))) */ function sc_cdadr(p) { return p.cdr.car.cdr; } /*** META ((export #t) (arity #t) (peephole (postfix ".car.cdr.cdr"))) */ function sc_cddar(p) { return p.car.cdr.cdr; } /*** META ((export #t) (arity #t) (peephole (postfix ".cdr.cdr.cdr"))) */ function sc_cdddr(p) { return p.cdr.cdr.cdr; } /*** META ((export #t) (arity #t) (peephole (postfix ".car.car.car.car"))) */ function sc_caaaar(p) { return p.car.car.car.car; } /*** META ((export #t) (arity #t) (peephole (postfix ".car.cdr.car.car"))) */ function sc_caadar(p) { return p.car.cdr.car.car; } /*** META ((export #t) (arity #t) (peephole (postfix ".cdr.car.car.car"))) */ function sc_caaadr(p) { return p.cdr.car.car.car; } /*** META ((export #t) (arity #t) (peephole (postfix ".cdr.cdr.car.car"))) */ function sc_caaddr(p) { return p.cdr.cdr.car.car; } /*** META ((export #t) (arity #t) (peephole (postfix ".car.car.car.cdr"))) */ function sc_cdaaar(p) { return p.car.car.car.cdr; } /*** META ((export #t) (arity #t) (peephole (postfix ".car.cdr.car.cdr"))) */ function sc_cdadar(p) { return p.car.cdr.car.cdr; } /*** META ((export #t) (arity #t) (peephole (postfix ".cdr.car.car.cdr"))) */ function sc_cdaadr(p) { return p.cdr.car.car.cdr; } /*** META ((export #t) (arity #t) (peephole (postfix ".cdr.cdr.car.cdr"))) */ function sc_cdaddr(p) { return p.cdr.cdr.car.cdr; } /*** META ((export #t) (arity #t) (peephole (postfix ".car.car.cdr.car"))) */ function sc_cadaar(p) { return p.car.car.cdr.car; } /*** META ((export #t) (arity #t) (peephole (postfix ".car.cdr.cdr.car"))) */ function sc_caddar(p) { return p.car.cdr.cdr.car; } /*** META ((export #t) (arity #t) (peephole (postfix ".cdr.car.cdr.car"))) */ function sc_cadadr(p) { return p.cdr.car.cdr.car; } /*** META ((export #t) (arity #t) (peephole (postfix ".cdr.cdr.cdr.car"))) */ function sc_cadddr(p) { return p.cdr.cdr.cdr.car; } /*** META ((export #t) (arity #t) (peephole (postfix ".car.car.cdr.cdr"))) */ function sc_cddaar(p) { return p.car.car.cdr.cdr; } /*** META ((export #t) (arity #t) (peephole (postfix ".car.cdr.cdr.cdr"))) */ function sc_cdddar(p) { return p.car.cdr.cdr.cdr; } /*** META ((export #t) (arity #t) (peephole (postfix ".cdr.car.cdr.cdr"))) */ function sc_cddadr(p) { return p.cdr.car.cdr.cdr; } /*** META ((export #t) (arity #t) (peephole (postfix ".cdr.cdr.cdr.cdr"))) */ function sc_cddddr(p) { return p.cdr.cdr.cdr.cdr; } function sc_lastPair(l) { if (!sc_isPair(l)) sc_error("sc_lastPair: pair expected"); var res = l; var cdr = l.cdr; while (sc_isPair(cdr)) { res = cdr; cdr = res.cdr; } return res; } /*** META ((export #t) (arity #t) (type bool) (peephole (postfix " === null"))) */ function sc_isNull(o) { return (o === null); } /*** META ((export #t) (arity #t) (type bool)) */ function sc_isList(o) { var rabbit = o; var turtle = o; while (true) { if (rabbit === null || (rabbit instanceof sc_Pair && rabbit.cdr === null)) return true; else { if ((rabbit instanceof sc_Pair) && (rabbit.cdr instanceof sc_Pair)) { rabbit = rabbit.cdr.cdr; turtle = turtle.cdr; if (rabbit === turtle) return false; } else return false; } } } /*** META ((export #t) (arity -1)) */ function sc_list() { var res = null; var a = arguments; for (var i = a.length-1; i >= 0; i--) res = new sc_Pair(a[i], res); return res; } /*** META ((export #t) (arity -2)) */ function sc_iota(num, init) { var res = null; if (!init) init = 0; for (var i = num - 1; i >= 0; i--) res = new sc_Pair(i + init, res); return res; } /*** META ((export #t) (arity -2)) */ function sc_makeList(nbEls, fill) { var res = null; for (var i = 0; i < nbEls; i++) res = new sc_Pair(fill, res); return res; } function sc_length(l) { var res = 0; while (l !== null) { res++; l = l.cdr; } return res; } function sc_remq(o, l) { var dummy = { cdr : null }; var tail = dummy; while (l !== null) { if (l.car !== o) { tail.cdr = sc_cons(l.car, null); tail = tail.cdr; } l = l.cdr; } return dummy.cdr; } function sc_remqBang(o, l) { var dummy = { cdr : null }; var tail = dummy; var needsAssig = true; while (l !== null) { if (l.car === o) { needsAssig = true; } else { if (needsAssig) { tail.cdr = l; needsAssig = false; } tail = l; } l = l.cdr; } tail.cdr = null; return dummy.cdr; } function sc_delete(o, l) { var dummy = { cdr : null }; var tail = dummy; while (l !== null) { if (!sc_isEqual(l.car, o)) { tail.cdr = sc_cons(l.car, null); tail = tail.cdr; } l = l.cdr; } return dummy.cdr; } function sc_deleteBang(o, l) { var dummy = { cdr : null }; var tail = dummy; var needsAssig = true; while (l !== null) { if (sc_isEqual(l.car, o)) { needsAssig = true; } else { if (needsAssig) { tail.cdr = l; needsAssig = false; } tail = l; } l = l.cdr; } tail.cdr = null; return dummy.cdr; } function sc_reverseAppendBang(l1, l2) { var res = l2; while (l1 !== null) { var tmp = res; res = l1; l1 = l1.cdr; res.cdr = tmp; } return res; } function sc_dualAppend(l1, l2) { if (l1 === null) return l2; if (l2 === null) return l1; var rev = sc_reverse(l1); return sc_reverseAppendBang(rev, l2); } /*** META ((export append eappend) ;; we want eappend for the quasiquotes. (arity -1)) */ function sc_append() { if (arguments.length === 0) return null; var res = arguments[arguments.length - 1]; for (var i = arguments.length - 2; i >= 0; i--) res = sc_dualAppend(arguments[i], res); return res; } function sc_dualAppendBang(l1, l2) { if (l1 === null) return l2; if (l2 === null) return l1; var tmp = l1; while (tmp.cdr !== null) tmp=tmp.cdr; tmp.cdr = l2; return l1; } /*** META ((export #t) (arity -1)) */ function sc_appendBang() { var res = null; for (var i = 0; i < arguments.length; i++) res = sc_dualAppendBang(res, arguments[i]); return res; } function sc_reverse(l1) { var res = null; while (l1 !== null) { res = sc_cons(l1.car, res); l1 = l1.cdr; } return res; } function sc_reverseBang(l) { return sc_reverseAppendBang(l, null); } function sc_listTail(l, k) { var res = l; for (var i = 0; i < k; i++) { res = res.cdr; } return res; } function sc_listRef(l, k) { return sc_listTail(l, k).car; } /* function sc_memX(o, l, comp) { while (l != null) { if (comp(l.car, o)) return l; l = l.cdr; } return false; } function sc_memq(o, l) { return sc_memX(o, l, sc_isEq); } function sc_memv(o, l) { return sc_memX(o, l, sc_isEqv); } function sc_member(o, l) { return sc_memX(o, l, sc_isEqual); } */ function sc_memq(o, l) { while (l !== null) { if (l.car === o) return l; l = l.cdr; } return false; } function sc_memv(o, l) { while (l !== null) { if (l.car === o) return l; l = l.cdr; } return false; } function sc_member(o, l) { while (l !== null) { if (sc_isEqual(l.car,o)) return l; l = l.cdr; } return false; } /* function sc_assX(o, al, comp) { while (al != null) { if (comp(al.car.car, o)) return al.car; al = al.cdr; } return false; } function sc_assq(o, al) { return sc_assX(o, al, sc_isEq); } function sc_assv(o, al) { return sc_assX(o, al, sc_isEqv); } function sc_assoc(o, al) { return sc_assX(o, al, sc_isEqual); } */ function sc_assq(o, al) { while (al !== null) { if (al.car.car === o) return al.car; al = al.cdr; } return false; } function sc_assv(o, al) { while (al !== null) { if (al.car.car === o) return al.car; al = al.cdr; } return false; } function sc_assoc(o, al) { while (al !== null) { if (sc_isEqual(al.car.car, o)) return al.car; al = al.cdr; } return false; } function sc_isCharStringEqual(cs1, cs2) { return cs1.val === cs2.val; } function sc_isCharStringLess(cs1, cs2) { return cs1.val < cs2.val; } function sc_isCharStringGreater(cs1, cs2) { return cs1.val > cs2.val; } function sc_isCharStringLessEqual(cs1, cs2) { return cs1.val <= cs2.val; } function sc_isCharStringGreaterEqual(cs1, cs2) { return cs1.val >= cs2.val; } function sc_isCharStringCIEqual(cs1, cs2) { return cs1.val.toLowerCase() === cs2.val.toLowerCase(); } function sc_isCharStringCILess(cs1, cs2) { return cs1.val.toLowerCase() < cs2.val.toLowerCase(); } function sc_isCharStringCIGreater(cs1, cs2) { return cs1.val.toLowerCase() > cs2.val.toLowerCase(); } function sc_isCharStringCILessEqual(cs1, cs2) { return cs1.val.toLowerCase() <= cs2.val.toLowerCase(); } function sc_isCharStringCIGreaterEqual(cs1, cs2) { return cs1.val.toLowerCase() >= cs2.val.toLowerCase(); } function sc_Char(c) { var cached = sc_Char.lazy[c]; if (cached) return cached; this.val = c; sc_Char.lazy[c] = this; return undefined; } sc_Char.lazy = new Object(); sc_Char.char2readable = { "\000": "#\\null", "\007": "#\\bell", "\010": "#\\backspace", "\011": "#\\tab", "\012": "#\\newline", "\014": "#\\page", "\015": "#\\return", "\033": "#\\escape", "\040": "#\\space", "\177": "#\\delete", "\001": "#\\soh", "\002": "#\\stx", "\003": "#\\etx", "\004": "#\\eot", "\005": "#\\enq", "\006": "#\\ack", "\013": "#\\vt", "\016": "#\\so", "\017": "#\\si", "\020": "#\\dle", "\021": "#\\dc1", "\022": "#\\dc2", "\023": "#\\dc3", "\024": "#\\dc4", "\025": "#\\nak", "\026": "#\\syn", "\027": "#\\etb", "\030": "#\\can", "\031": "#\\em", "\032": "#\\sub", "\033": "#\\esc", "\034": "#\\fs", "\035": "#\\gs", "\036": "#\\rs", "\037": "#\\us"}; sc_Char.readable2char = { "null": "\000", "bell": "\007", "backspace": "\010", "tab": "\011", "newline": "\012", "page": "\014", "return": "\015", "escape": "\033", "space": "\040", "delete": "\000", "soh": "\001", "stx": "\002", "etx": "\003", "eot": "\004", "enq": "\005", "ack": "\006", "bel": "\007", "bs": "\010", "ht": "\011", "nl": "\012", "vt": "\013", "np": "\014", "cr": "\015", "so": "\016", "si": "\017", "dle": "\020", "dc1": "\021", "dc2": "\022", "dc3": "\023", "dc4": "\024", "nak": "\025", "syn": "\026", "etb": "\027", "can": "\030", "em": "\031", "sub": "\032", "esc": "\033", "fs": "\034", "gs": "\035", "rs": "\036", "us": "\037", "sp": "\040", "del": "\177"}; sc_Char.prototype.toString = function() { return this.val; }; sc_Char.prototype.sc_toWriteString = function() { var entry = sc_Char.char2readable[this.val]; if (entry) return entry; else return "#\\" + this.val; }; /*** META ((export #t) (arity #t) (type bool) (peephole (postfix "instanceof sc_Char"))) */ function sc_isChar(c) { return (c instanceof sc_Char); } /*** META ((export char=?) (arity 2) (type bool) (peephole (hole 2 c1 ".val === " c2 ".val"))) */ var sc_isCharEqual = sc_isCharStringEqual; /*** META ((export char?) (arity 2) (type bool) (peephole (hole 2 c1 ".val > " c2 ".val"))) */ var sc_isCharGreater = sc_isCharStringGreater; /*** META ((export char<=?) (arity 2) (type bool) (peephole (hole 2 c1 ".val <= " c2 ".val"))) */ var sc_isCharLessEqual = sc_isCharStringLessEqual; /*** META ((export char>=?) (arity 2) (type bool) (peephole (hole 2 c1 ".val >= " c2 ".val"))) */ var sc_isCharGreaterEqual = sc_isCharStringGreaterEqual; /*** META ((export char-ci=?) (arity 2) (type bool) (peephole (hole 2 c1 ".val.toLowerCase() === " c2 ".val.toLowerCase()"))) */ var sc_isCharCIEqual = sc_isCharStringCIEqual; /*** META ((export char-ci?) (arity 2) (type bool) (peephole (hole 2 c1 ".val.toLowerCase() > " c2 ".val.toLowerCase()"))) */ var sc_isCharCIGreater = sc_isCharStringCIGreater; /*** META ((export char-ci<=?) (arity 2) (type bool) (peephole (hole 2 c1 ".val.toLowerCase() <= " c2 ".val.toLowerCase()"))) */ var sc_isCharCILessEqual = sc_isCharStringCILessEqual; /*** META ((export char-ci>=?) (arity 2) (type bool) (peephole (hole 2 c1 ".val.toLowerCase() >= " c2 ".val.toLowerCase()"))) */ var sc_isCharCIGreaterEqual = sc_isCharStringCIGreaterEqual; var SC_NUMBER_CLASS = "0123456789"; var SC_WHITESPACE_CLASS = ' \r\n\t\f'; var SC_LOWER_CLASS = 'abcdefghijklmnopqrstuvwxyz'; var SC_UPPER_CLASS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; function sc_isCharOfClass(c, cl) { return (cl.indexOf(c) != -1); } /*** META ((export #t) (arity #t) (type bool)) */ function sc_isCharAlphabetic(c) { return sc_isCharOfClass(c.val, SC_LOWER_CLASS) || sc_isCharOfClass(c.val, SC_UPPER_CLASS); } /*** META ((export #t) (arity #t) (type bool) (peephole (hole 1 "SC_NUMBER_CLASS.indexOf(" c ".val) != -1"))) */ function sc_isCharNumeric(c) { return sc_isCharOfClass(c.val, SC_NUMBER_CLASS); } /*** META ((export #t) (arity #t) (type bool)) */ function sc_isCharWhitespace(c) { var tmp = c.val; return tmp === " " || tmp === "\r" || tmp === "\n" || tmp === "\t" || tmp === "\f"; } /*** META ((export #t) (arity #t) (type bool) (peephole (hole 1 "SC_UPPER_CLASS.indexOf(" c ".val) != -1"))) */ function sc_isCharUpperCase(c) { return sc_isCharOfClass(c.val, SC_UPPER_CLASS); } /*** META ((export #t) (arity #t) (type bool) (peephole (hole 1 "SC_LOWER_CLASS.indexOf(" c ".val) != -1"))) */ function sc_isCharLowerCase(c) { return sc_isCharOfClass(c.val, SC_LOWER_CLASS); } /*** META ((export #t) (arity #t) (peephole (postfix ".val.charCodeAt(0)"))) */ function sc_char2integer(c) { return c.val.charCodeAt(0); } /*** META ((export #t) (arity #t) (peephole (hole 1 "new sc_Char(String.fromCharCode(" n "))"))) */ function sc_integer2char(n) { return new sc_Char(String.fromCharCode(n)); } /*** META ((export #t) (arity #t) (peephole (hole 1 "new sc_Char(" c ".val.toUpperCase())"))) */ function sc_charUpcase(c) { return new sc_Char(c.val.toUpperCase()); } /*** META ((export #t) (arity #t) (peephole (hole 1 "new sc_Char(" c ".val.toLowerCase())"))) */ function sc_charDowncase(c) { return new sc_Char(c.val.toLowerCase()); } function sc_makeJSStringOfLength(k, c) { var fill; if (c === undefined) fill = " "; else fill = c; var res = ""; var len = 1; while (k >= len) { if (k & len) res = res.concat(fill); fill = fill.concat(fill); len *= 2; } return res; } function sc_makejsString(k, c) { var fill; if (c) fill = c.val; else fill = " "; return sc_makeJSStringOfLength(k, fill); } function sc_jsstring2list(s) { var res = null; for (var i = s.length - 1; i >= 0; i--) res = sc_cons(new sc_Char(s.charAt(i)), res); return res; } function sc_list2jsstring(l) { var a = new Array(); while(l !== null) { a.push(l.car.val); l = l.cdr; } return "".concat.apply("", a); } var sc_Vector = Array; sc_Vector.prototype.sc_toWriteOrDisplayString = function(writeOrDisplay) { if (this.length === 0) return "#()"; var res = "#(" + writeOrDisplay(this[0]); for (var i = 1; i < this.length; i++) res += " " + writeOrDisplay(this[i]); res += ")"; return res; }; sc_Vector.prototype.sc_toDisplayString = function() { return this.sc_toWriteOrDisplayString(sc_toDisplayString); }; sc_Vector.prototype.sc_toWriteString = function() { return this.sc_toWriteOrDisplayString(sc_toWriteString); }; /*** META ((export vector? array?) (arity #t) (type bool) (peephole (postfix " instanceof sc_Vector"))) */ function sc_isVector(v) { return (v instanceof sc_Vector); } function sc_isVectorEqual(v1, v2, comp) { if (v1.length !== v2.length) return false; for (var i = 0; i < v1.length; i++) if (!comp(v1[i], v2[i])) return false; return true; } /*** META ((export make-vector make-array) (arity -2)) */ function sc_makeVector(size, fill) { var a = new sc_Vector(size); if (fill !== undefined) sc_vectorFillBang(a, fill); return a; } /*** META ((export vector array) (arity -1) (peephole (vector))) */ function sc_vector() { var a = new sc_Vector(); for (var i = 0; i < arguments.length; i++) a.push(arguments[i]); return a; } /*** META ((export vector-length array-length) (arity #t) (peephole (postfix ".length"))) */ function sc_vectorLength(v) { return v.length; } /*** META ((export vector-ref array-ref) (arity #t) (peephole (hole 2 v "[" pos "]"))) */ function sc_vectorRef(v, pos) { return v[pos]; } /*** META ((export vector-set! array-set!) (arity #t) (peephole (hole 3 v "[" pos "] = " val))) */ function sc_vectorSetBang(v, pos, val) { v[pos] = val; } function sc_vector2list(a) { var res = null; for (var i = a.length-1; i >= 0; i--) res = sc_cons(a[i], res); return res; } function sc_list2vector(l) { var a = new sc_Vector(); while(l !== null) { a.push(l.car); l = l.cdr; } return a; } function sc_vectorFillBang(a, fill) { for (var i = 0; i < a.length; i++) a[i] = fill; } function sc_copyVector(a, len) { if (len <= a.length) return a.slice(0, len); else { var tmp = a.concat(); tmp.length = len; return tmp; } } /*** META ((export #t) (arity -2) (peephole (hole 3 a ".slice(" start "," end ")"))) */ function sc_vectorCopy(a, start, end) { return a.slice(start, end); } function sc_vectorCopyBang(target, tstart, source, sstart, send) { if (!sstart) sstart = 0; if (!send) send = source.length; if (tstart <= sstart) { for (var i = tstart, j = sstart; j < send; i++, j++) { target[i] = source[j]; } } else { var diff = send - sstart; for (var i = tstart + diff - 1, j = send - 1; j >= sstart; i--, j--) { target[i] = source[j]; } } return target; } /*** META ((export #t) (arity #t) (type bool) (peephole (hole 1 "typeof " o " === 'function'"))) */ function sc_isProcedure(o) { return (typeof o === "function"); } function sc_apply(proc) { var args = new Array(); for (var i = 1; i < arguments.length - 1; i++) args.push(arguments[i]); var l = arguments[arguments.length - 1]; while (l !== null) { args.push(l.car); l = l.cdr; } return proc.apply(null, args); } function sc_map(proc, l1) { if (l1 === undefined) return null; var nbApplyArgs = arguments.length - 1; var applyArgs = new Array(nbApplyArgs); var revres = null; while (l1 !== null) { for (var i = 0; i < nbApplyArgs; i++) { applyArgs[i] = arguments[i + 1].car; arguments[i + 1] = arguments[i + 1].cdr; } revres = sc_cons(proc.apply(null, applyArgs), revres); } return sc_reverseAppendBang(revres, null); } function sc_mapBang(proc, l1) { if (l1 === undefined) return null; var l1_orig = l1; var nbApplyArgs = arguments.length - 1; var applyArgs = new Array(nbApplyArgs); while (l1 !== null) { var tmp = l1; for (var i = 0; i < nbApplyArgs; i++) { applyArgs[i] = arguments[i + 1].car; arguments[i + 1] = arguments[i + 1].cdr; } tmp.car = proc.apply(null, applyArgs); } return l1_orig; } function sc_forEach(proc, l1) { if (l1 === undefined) return undefined; var nbApplyArgs = arguments.length - 1; var applyArgs = new Array(nbApplyArgs); while (l1 !== null) { for (var i = 0; i < nbApplyArgs; i++) { applyArgs[i] = arguments[i + 1].car; arguments[i + 1] = arguments[i + 1].cdr; } proc.apply(null, applyArgs); } return undefined; } function sc_filter(proc, l1) { var dummy = { cdr : null }; var tail = dummy; while (l1 !== null) { if (proc(l1.car) !== false) { tail.cdr = sc_cons(l1.car, null); tail = tail.cdr; } l1 = l1.cdr; } return dummy.cdr; } function sc_filterBang(proc, l1) { var head = sc_cons("dummy", l1); var it = head; var next = l1; while (next !== null) { if (proc(next.car) !== false) { it.cdr = next it = next; } next = next.cdr; } it.cdr = null; return head.cdr; } function sc_filterMap1(proc, l1) { var revres = null; while (l1 !== null) { var tmp = proc(l1.car) if (tmp !== false) revres = sc_cons(tmp, revres); l1 = l1.cdr; } return sc_reverseAppendBang(revres, null); } function sc_filterMap2(proc, l1, l2) { var revres = null; while (l1 !== null) { var tmp = proc(l1.car, l2.car); if(tmp !== false) revres = sc_cons(tmp, revres); l1 = l1.cdr; l2 = l2.cdr } return sc_reverseAppendBang(revres, null); } function sc_filterMap(proc, l1, l2, l3) { if (l2 === undefined) return sc_filterMap1(proc, l1); else if (l3 === undefined) return sc_filterMap2(proc, l1, l2); var nbApplyArgs = arguments.length - 1; var applyArgs = new Array(nbApplyArgs); var revres = null; while (l1 !== null) { for (var i = 0; i < nbApplyArgs; i++) { applyArgs[i] = arguments[i + 1].car; arguments[i + 1] = arguments[i + 1].cdr; } var tmp = proc.apply(null, applyArgs); if(tmp !== false) revres = sc_cons(tmp, revres); } return sc_reverseAppendBang(revres, null); } function sc_any1(proc, l) { var revres = null; while (l !== null) { var tmp = proc(l.car); if(tmp !== false) return tmp; l = l.cdr; } return false; } function sc_any(proc, l1, l2) { if (l1 === undefined) return false; if (l2 === undefined) return sc_any1(proc, l1); var nbApplyArgs = arguments.length - 1; var applyArgs = new Array(nbApplyArgs); while (l1 !== null) { for (var i = 0; i < nbApplyArgs; i++) { applyArgs[i] = arguments[i + 1].car; arguments[i + 1] = arguments[i + 1].cdr; } var tmp = proc.apply(null, applyArgs); if (tmp !== false) return tmp; } return false; } /*** META ((export any?) (arity -2) (peephole (hole 2 "sc_any(" proc "," l ") !== false"))) */ function sc_anyPred(proc, l) { return sc_any(proc, l) !== false; } function sc_every1(proc, l) { var revres = null; var tmp = true; while (l !== null) { tmp = proc(l.car); if (tmp === false) return false; l = l.cdr; } return tmp; } function sc_every(proc, l1, l2) { if (l1 === undefined) return true; if (l2 === undefined) return sc_every1(proc, l1); var nbApplyArgs = arguments.length - 1; var applyArgs = new Array(nbApplyArgs); var tmp = true; while (l1 !== null) { for (var i = 0; i < nbApplyArgs; i++) { applyArgs[i] = arguments[i + 1].car; arguments[i + 1] = arguments[i + 1].cdr; } var tmp = proc.apply(null, applyArgs); if (tmp === false) return false; } return tmp; } /*** META ((export every?) (arity -2) (peephole (hole 2 "sc_every(" proc "," l ") !== false"))) */ function sc_everyPred(proc, l) { var tmp = sc_every(proc, l); if (tmp !== false) return true; return false; } /*** META ((export #t) (arity #t) (peephole (postfix "()"))) */ function sc_force(o) { return o(); } function sc_makePromise(proc) { var isResultReady = false; var result = undefined; return function() { if (!isResultReady) { var tmp = proc(); if (!isResultReady) { isResultReady = true; result = tmp; } } return result; }; } function sc_Values(values) { this.values = values; } /*** META ((export #t) (arity -1) (peephole (values))) */ function sc_values() { if (arguments.length === 1) return arguments[0]; else return new sc_Values(arguments); } function sc_callWithValues(producer, consumer) { if( !sc_isProcedure(producer) ) sc_error( "callWithValue", "producer not a procedure", producer ); var produced = producer(); if (produced instanceof sc_Values) return consumer.apply(null, produced.values); else return consumer(produced); } function sc_dynamicWind(before, thunk, after) { before(); try { var res = thunk(); return res; } finally { after(); } } function sc_Struct(name) { this.name = name; } sc_Struct.prototype.sc_toDisplayString = function() { return "#"; }; sc_Struct.prototype.sc_toWriteString = sc_Struct.prototype.sc_toDisplayString; /*** META ((export #t) (arity #t) (peephole (hole 1 "new sc_Struct(" name ")"))) */ function sc_makeStruct(name) { return new sc_Struct(name); } /*** META ((export #t) (arity 1) (type bool) (peephole (postfix " instanceof sc_Struct"))) */ function sc_isStruct(o) { return (o instanceof sc_Struct); } /*** META ((export #t) (arity #t) (type bool) (peephole (hole 2 "(" 1 " instanceof sc_Struct) && ( " 1 ".name === " 0 ")"))) */ function sc_isStructNamed(name, s) { return ((s instanceof sc_Struct) && (s.name === name)); } /*** META ((export struct-field) (arity #t) (peephole (hole 3 0 "[" 2 "]"))) */ function sc_getStructField(s, name, field) { return s[field]; } /*** META ((export struct-field-set!) (arity #t) (peephole (hole 4 0 "[" 2 "] = " 3))) */ function sc_setStructFieldBang(s, name, field, val) { s[field] = val; } /*** META ((export #t) (arity #t) (peephole (prefix "~"))) */ function sc_bitNot(x) { return ~x; } /*** META ((export #t) (arity #t) (peephole (infix 2 2 "&"))) */ function sc_bitAnd(x, y) { return x & y; } /*** META ((export #t) (arity #t) (peephole (infix 2 2 "|"))) */ function sc_bitOr(x, y) { return x | y; } /*** META ((export #t) (arity #t) (peephole (infix 2 2 "^"))) */ function sc_bitXor(x, y) { return x ^ y; } /*** META ((export #t) (arity #t) (peephole (infix 2 2 "<<"))) */ function sc_bitLsh(x, y) { return x << y; } /*** META ((export #t) (arity #t) (peephole (infix 2 2 ">>"))) */ function sc_bitRsh(x, y) { return x >> y; } /*** META ((export #t) (arity #t) (peephole (infix 2 2 ">>>"))) */ function sc_bitUrsh(x, y) { return x >>> y; } /*** META ((export js-field js-property) (arity #t) (peephole (hole 2 o "[" field "]"))) */ function sc_jsField(o, field) { return o[field]; } /*** META ((export js-field-set! js-property-set!) (arity #t) (peephole (hole 3 o "[" field "] = " val))) */ function sc_setJsFieldBang(o, field, val) { return o[field] = val; } /*** META ((export js-field-delete! js-property-delete!) (arity #t) (peephole (hole 2 "delete" o "[" field "]"))) */ function sc_deleteJsFieldBang(o, field) { delete o[field]; } /*** META ((export #t) (arity -3) (peephole (jsCall))) */ function sc_jsCall(o, fun) { var args = new Array(); for (var i = 2; i < arguments.length; i++) args[i-2] = arguments[i]; return fun.apply(o, args); } /*** META ((export #t) (arity -3) (peephole (jsMethodCall))) */ function sc_jsMethodCall(o, field) { var args = new Array(); for (var i = 2; i < arguments.length; i++) args[i-2] = arguments[i]; return o[field].apply(o, args); } /*** META ((export new js-new) (arity -2) (peephole (jsNew))) */ function sc_jsNew(c) { var evalStr = "new c("; evalStr +=arguments.length > 1? "arguments[1]": ""; for (var i = 2; i < arguments.length; i++) evalStr += ", arguments[" + i + "]"; evalStr +=")"; return eval(evalStr); } function sc_pregexp(re) { return new RegExp(sc_string2jsstring(re)); } function sc_pregexpMatch(re, s) { var reg = (re instanceof RegExp) ? re : sc_pregexp(re); var tmp = reg.exec(sc_string2jsstring(s)); if (tmp == null) return false; var res = null; for (var i = tmp.length-1; i >= 0; i--) { if (tmp[i] !== null) { res = sc_cons(sc_jsstring2string(tmp[i]), res); } else { res = sc_cons(false, res); } } return res; } function sc_pregexpReplace(re, s1, s2) { var reg; var jss1 = sc_string2jsstring(s1); var jss2 = sc_string2jsstring(s2); if (re instanceof RegExp) { if (re.global) reg = re; else reg = new RegExp(re.source); } else { reg = new RegExp(sc_string2jsstring(re)); } return jss1.replace(reg, jss2); } function sc_pregexpReplaceAll(re, s1, s2) { var reg; var jss1 = sc_string2jsstring(s1); var jss2 = sc_string2jsstring(s2); if (re instanceof RegExp) { if (re.global) reg = re; else reg = new RegExp(re.source, "g"); } else { reg = new RegExp(sc_string2jsstring(re), "g"); } return jss1.replace(reg, jss2); } function sc_pregexpSplit(re, s) { var reg = ((re instanceof RegExp) ? re : new RegExp(sc_string2jsstring(re))); var jss = sc_string2jsstring(s); var tmp = jss.split(reg); if (tmp == null) return false; return sc_vector2list(tmp); } function sc_pregexpCreateCharsetMatcher(set) { if (set.length === 0 || set.length === 1) return new RegExp("[" + set + "]"); var res = "["; for (var i = 0; i < set.length; i++) { var c = set.charAt(i); if (c === "]") res += "\\]"; else if (c === "^") res += "\\^"; else if (c === "\\") res += "\\\\"; else if (c === "-") res += "\\-"; else res += c; } return new RegExp(res + "]"); } /*** META ((export #t) (arity #t) (peephole (hole 1 "Math.floor(Math.random()*" 'n ")"))) */ function sc_random(n) { return Math.floor(Math.random()*n); } /*** META ((export current-date) (arity #t) (peephole (hole 0 "new Date()"))) */ function sc_currentDate() { return new Date(); } function sc_Hashtable() { } sc_Hashtable.prototype.toString = function() { return "#{%hashtable}"; }; function sc_HashtableElement(key, val) { this.key = key; this.val = val; } /*** META ((export #t) (peephole (hole 0 "new sc_Hashtable()"))) */ function sc_makeHashtable() { return new sc_Hashtable(); } /*** META ((export #t) (arity #t) (type bool)) */ function sc_isHashtable(o) { return o instanceof sc_Hashtable; } function sc_hashtablePutBang(ht, key, val) { var hash = sc_hash(key); ht[hash] = new sc_HashtableElement(key, val); } function sc_hashtableGet(ht, key) { var hash = sc_hash(key); if (hash in ht) return ht[hash].val; else return false; } function sc_hashtableForEach(ht, f) { for (var v in ht) { if (ht[v] instanceof sc_HashtableElement) f(ht[v].key, ht[v].val); } } /*** META ((export hashtable-contains?) (arity #t) (peephole (hole 2 "sc_hash(" 1 ") in " 0))) */ function sc_hashtableContains(ht, key) { var hash = sc_hash(key); if (hash in ht) return true; else return false; } var SC_HASH_COUNTER = 0; function sc_hash(o) { if (o === null) return "null"; else if (o === undefined) return "undefined"; else if (o === true) return "true"; else if (o === false) return "false"; else if (typeof o === "number") return "num-" + o; else if (typeof o === "string") return "jsstr-" + o; else if (o.sc_getHash) return o.sc_getHash(); else return sc_counterHash.call(o); } function sc_counterHash() { if (!this.sc_hash) { this.sc_hash = "hash-" + SC_HASH_COUNTER; SC_HASH_COUNTER++; } return this.sc_hash; } function sc_Trampoline() { } sc_Trampoline.prototype.restart = function() { while (true) { this.calls = this.MAX_TAIL_CALLs-1; var res = this.f.apply(this, this.args); if (res !== this) return res; } } function sc_bindExitLambda(proc) { var escape_obj = new sc_BindExitException(); var escape = function(res) { escape_obj.res = res; throw escape_obj; }; try { return proc(escape); } catch(e) { if (e === escape_obj) { return e.res; } throw e; } } function sc_BindExitException() { this._internalException = true; } var SC_SCM2JS_GLOBALS = new Object(); var SC_TAIL_OBJECT = new sc_Trampoline(); SC_SCM2JS_GLOBALS.TAIL_OBJECT = SC_TAIL_OBJECT; function sc_EOF() { } var SC_EOF_OBJECT = new sc_EOF(); function sc_Port() { } function sc_InputPort() { } sc_InputPort.prototype = new sc_Port(); sc_InputPort.prototype.peekChar = function() { if (!("peeked" in this)) this.peeked = this.getNextChar(); return this.peeked; } sc_InputPort.prototype.readChar = function() { var tmp = this.peekChar(); delete this.peeked; return tmp; } sc_InputPort.prototype.isCharReady = function() { return true; } sc_InputPort.prototype.close = function() { } function sc_ErrorInputPort() { }; sc_ErrorInputPort.prototype = new sc_InputPort(); sc_ErrorInputPort.prototype.getNextChar = function() { throw "can't read from error-port."; }; sc_ErrorInputPort.prototype.isCharReady = function() { return false; }; function sc_StringInputPort(jsStr) { this.str = new String(jsStr); this.pos = 0; } sc_StringInputPort.prototype = new sc_InputPort(); sc_StringInputPort.prototype.getNextChar = function() { if (this.pos >= this.str.length) return SC_EOF_OBJECT; return this.str.charAt(this.pos++); }; function sc_Token(type, val, pos) { this.type = type; this.val = val; this.pos = pos; } sc_Token.EOF = 0; sc_Token.OPEN_PAR = 1; sc_Token.CLOSE_PAR = 2; sc_Token.OPEN_BRACE = 3; sc_Token.CLOSE_BRACE = 4; sc_Token.OPEN_BRACKET = 5; sc_Token.CLOSE_BRACKET = 6; sc_Token.WHITESPACE = 7; sc_Token.QUOTE = 8; sc_Token.ID = 9; sc_Token.DOT = 10; sc_Token.STRING = 11; sc_Token.NUMBER = 12; sc_Token.ERROR = 13; sc_Token.VECTOR_BEGIN = 14; sc_Token.TRUE = 15; sc_Token.FALSE = 16; sc_Token.UNSPECIFIED = 17; sc_Token.REFERENCE = 18; sc_Token.STORE = 19; sc_Token.CHAR = 20; var SC_ID_CLASS = SC_LOWER_CLASS + SC_UPPER_CLASS + "!$%*+-./:<=>?@^_~"; function sc_Tokenizer(port) { this.port = port; } sc_Tokenizer.prototype.peekToken = function() { if (this.peeked) return this.peeked; var newToken = this.nextToken(); this.peeked = newToken; return newToken; }; sc_Tokenizer.prototype.readToken = function() { var tmp = this.peekToken(); delete this.peeked; return tmp; }; sc_Tokenizer.prototype.nextToken = function() { var port = this.port; function isNumberChar(c) { return (c >= "0" && c <= "9"); }; function isIdOrNumberChar(c) { return SC_ID_CLASS.indexOf(c) != -1 || (c >= "0" && c <= "9"); } function isWhitespace(c) { return c === " " || c === "\r" || c === "\n" || c === "\t" || c === "\f"; }; function isWhitespaceOrEOF(c) { return isWhitespace(c) || c === SC_EOF_OBJECT; }; function readString() { res = ""; while (true) { var c = port.readChar(); switch (c) { case '"': return new sc_Token(11, res); case "\\": var tmp = port.readChar(); switch (tmp) { case '0': res += "\0"; break; case 'a': res += "\a"; break; case 'b': res += "\b"; break; case 'f': res += "\f"; break; case 'n': res += "\n"; break; case 'r': res += "\r"; break; case 't': res += "\t"; break; case 'v': res += "\v"; break; case '"': res += '"'; break; case '\\': res += '\\'; break; case 'x': var nb = 0; while (true) { var hexC = port.peekChar(); if (hexC >= '0' && hexC <= '9') { port.readChar(); nb = nb * 16 + hexC.charCodeAt(0) - '0'.charCodeAt(0); } else if (hexC >= 'a' && hexC <= 'f') { port.readChar(); nb = nb * 16 + hexC.charCodeAt(0) - 'a'.charCodeAt(0); } else if (hexC >= 'A' && hexC <= 'F') { port.readChar(); nb = nb * 16 + hexC.charCodeAt(0) - 'A'.charCodeAt(0); } else { res += String.fromCharCode(nb); break; } } break; default: if (tmp === SC_EOF_OBJECT) { return new sc_Token(13, "unclosed string-literal" + res); } res += tmp; } break; default: if (c === SC_EOF_OBJECT) { return new sc_Token(13, "unclosed string-literal" + res); } res += c; } } }; function readIdOrNumber(firstChar) { var res = firstChar; while (isIdOrNumberChar(port.peekChar())) res += port.readChar(); if (isNaN(res)) return new sc_Token(9, res); else return new sc_Token(12, res - 0); }; function skipWhitespaceAndComments() { var done = false; while (!done) { done = true; while (isWhitespace(port.peekChar())) port.readChar(); if (port.peekChar() === ';') { port.readChar(); done = false; while (true) { curChar = port.readChar(); if (curChar === SC_EOF_OBJECT || curChar === '\n') break; } } } }; function readDot() { if (isWhitespace(port.peekChar())) return new sc_Token(10); else return readIdOrNumber("."); }; function readSharp() { var c = port.readChar(); if (isWhitespace(c)) return new sc_Token(13, "bad #-pattern0."); if (isNumberChar(c)) { var nb = c - 0; while (isNumberChar(port.peekChar())) nb = nb*10 + (port.readChar() - 0); switch (port.readChar()) { case '#': return new sc_Token(18, nb); case '=': return new sc_Token(19, nb); default: return new sc_Token(13, "bad #-pattern1." + nb); } } if (c === "(") return new sc_Token(14); if (c === "\\") { var tmp = "" while (!isWhitespaceOrEOF(port.peekChar())) tmp += port.readChar(); switch (tmp.length) { case 0: if (sc_isEOFObject(port.peekChar)) return new sc_Token(13, "bad #-pattern2."); else return new sc_Token(20, port.readChar()); case 1: return new sc_Token(20, tmp); default: var entry = sc_Char.readable2char[tmp.toLowerCase()]; if (entry) return new sc_Token(20, entry); else return new sc_Token(13, "unknown character description: #\\" + tmp); } } var res; var needing; switch (c) { case 't': res = new sc_Token(15, true); needing = ""; break; case 'f': res = new sc_Token(16, false); needing = ""; break; case 'u': res = new sc_Token(17, undefined); needing = "nspecified"; break; default: return new sc_Token(13, "bad #-pattern3: " + c); } while(true) { c = port.peekChar(); if ((isWhitespaceOrEOF(c) || c === ')') && needing == "") return res; else if (isWhitespace(c) || needing == "") return new sc_Token(13, "bad #-pattern4 " + c + " " + needing); else if (needing.charAt(0) == c) { port.readChar(); needing = needing.slice(1); } else return new sc_Token(13, "bad #-pattern5"); } }; skipWhitespaceAndComments(); var curChar = port.readChar(); if (curChar === SC_EOF_OBJECT) return new sc_Token(0, curChar); switch (curChar) { case " ": case "\n": case "\t": return readWhitespace(); case "(": return new sc_Token(1); case ")": return new sc_Token(2); case "{": return new sc_Token(3); case "}": return new sc_Token(4); case "[": return new sc_Token(5); case "]": return new sc_Token(6); case "'": return new sc_Token(8); case "#": return readSharp(); case ".": return readDot(); case '"': return readString(); default: if (isIdOrNumberChar(curChar)) return readIdOrNumber(curChar); throw "unexpected character: " + curChar; } }; function sc_Reader(tokenizer) { this.tokenizer = tokenizer; this.backref = new Array(); } sc_Reader.prototype.read = function() { function readList(listBeginType) { function matchesPeer(open, close) { return open === 1 && close === 2 || open === 3 && close === 4 || open === 5 && close === 6; }; var res = null; while (true) { var token = tokenizer.peekToken(); switch (token.type) { case 2: case 4: case 6: if (matchesPeer(listBeginType, token.type)) { tokenizer.readToken(); return sc_reverseBang(res); } else throw "closing par doesn't match: " + listBeginType + " " + listEndType; case 0: throw "unexpected end of file"; case 10: tokenizer.readToken(); var cdr = this.read(); var par = tokenizer.readToken(); if (!matchesPeer(listBeginType, par.type)) throw "closing par doesn't match: " + listBeginType + " " + par.type; else return sc_reverseAppendBang(res, cdr); default: res = sc_cons(this.read(), res); } } }; function readQuote() { return sc_cons("quote", sc_cons(this.read(), null)); }; function readVector() { var a = new Array(); while (true) { var token = tokenizer.peekToken(); switch (token.type) { case 2: tokenizer.readToken(); return a; default: a.push(this.read()); } } }; function storeRefence(nb) { var tmp = this.read(); this.backref[nb] = tmp; return tmp; }; function readReference(nb) { if (nb in this.backref) return this.backref[nb]; else throw "bad reference: " + nb; }; var tokenizer = this.tokenizer; var token = tokenizer.readToken(); if (token.type === 13) throw token.val; switch (token.type) { case 1: case 3: case 5: return readList.call(this, token.type); case 8: return readQuote.call(this); case 11: return sc_jsstring2string(token.val); case 20: return new sc_Char(token.val); case 14: return readVector.call(this); case 18: return readReference.call(this, token.val); case 19: return storeRefence.call(this, token.val); case 9: return sc_jsstring2symbol(token.val); case 0: case 12: case 15: case 16: case 17: return token.val; default: throw "unexpected token " + token.type + " " + token.val; } }; function sc_read(port) { if (port === undefined) port = SC_DEFAULT_IN; var reader = new sc_Reader(new sc_Tokenizer(port)); return reader.read(); } function sc_readChar(port) { if (port === undefined) port = SC_DEFAULT_IN; var t = port.readChar(); return t === SC_EOF_OBJECT? t: new sc_Char(t); } function sc_peekChar(port) { if (port === undefined) port = SC_DEFAULT_IN; var t = port.peekChar(); return t === SC_EOF_OBJECT? t: new sc_Char(t); } /*** META ((export #t) (arity -1) (type bool)) */ function sc_isCharReady(port) { if (port === undefined) port = SC_DEFAULT_IN; return port.isCharReady(); } /*** META ((export #t) (arity #t) (peephole (postfix ".close()"))) */ function sc_closeInputPort(p) { return p.close(); } /*** META ((export #t) (arity #t) (type bool) (peephole (postfix " instanceof sc_InputPort"))) */ function sc_isInputPort(o) { return (o instanceof sc_InputPort); } /*** META ((export eof-object?) (arity #t) (type bool) (peephole (postfix " === SC_EOF_OBJECT"))) */ function sc_isEOFObject(o) { return o === SC_EOF_OBJECT; } /*** META ((export #t) (arity #t) (peephole (hole 0 "SC_DEFAULT_IN"))) */ function sc_currentInputPort() { return SC_DEFAULT_IN; } function sc_callWithInputFile(s, proc) { throw "can't open " + s; } function sc_callWithOutputFile(s, proc) { throw "can't open " + s; } function sc_withInputFromFile(s, thunk) { throw "can't open " + s; } function sc_withOutputToFile(s, thunk) { throw "can't open " + s; } function sc_openInputFile(s) { throw "can't open " + s; } function sc_openOutputFile(s) { throw "can't open " + s; } function sc_basename(p) { var i = p.lastIndexOf('/'); if(i >= 0) return p.substring(i + 1, p.length); else return ''; } function sc_dirname(p) { var i = p.lastIndexOf('/'); if(i >= 0) return p.substring(0, i); else return ''; } function sc_withInputFromPort(p, thunk) { try { var tmp = SC_DEFAULT_IN; SC_DEFAULT_IN = p; return thunk(); } finally { SC_DEFAULT_IN = tmp; } } function sc_withInputFromString(s, thunk) { return sc_withInputFromPort(new sc_StringInputPort(sc_string2jsstring(s)), thunk); } function sc_withOutputToPort(p, thunk) { try { var tmp = SC_DEFAULT_OUT; SC_DEFAULT_OUT = p; return thunk(); } finally { SC_DEFAULT_OUT = tmp; } } function sc_withOutputToString(thunk) { var p = new sc_StringOutputPort(); sc_withOutputToPort(p, thunk); return p.close(); } function sc_withOutputToProcedure(proc, thunk) { var t = function(s) { proc(sc_jsstring2string(s)); }; return sc_withOutputToPort(new sc_GenericOutputPort(t), thunk); } /*** META ((export #t) (arity #t) (peephole (hole 0 "new sc_StringOutputPort()"))) */ function sc_openOutputString() { return new sc_StringOutputPort(); } function sc_openInputString(str) { return new sc_StringInputPort(sc_string2jsstring(str)); } function sc_OutputPort() { } sc_OutputPort.prototype = new sc_Port(); sc_OutputPort.prototype.appendJSString = function(obj) { } sc_OutputPort.prototype.close = function() { } function sc_StringOutputPort() { this.res = ""; } sc_StringOutputPort.prototype = new sc_OutputPort(); sc_StringOutputPort.prototype.appendJSString = function(s) { this.res += s; } sc_StringOutputPort.prototype.close = function() { return sc_jsstring2string(this.res); } function sc_getOutputString(sp) { return sc_jsstring2string(sp.res); } function sc_ErrorOutputPort() { } sc_ErrorOutputPort.prototype = new sc_OutputPort(); sc_ErrorOutputPort.prototype.appendJSString = function(s) { throw "don't write on ErrorPort!"; } sc_ErrorOutputPort.prototype.close = function() { } function sc_GenericOutputPort(appendJSString, close) { this.appendJSString = appendJSString; if (close) this.close = close; } sc_GenericOutputPort.prototype = new sc_OutputPort(); /*** META ((export #t) (arity #t) (type bool) (peephole (postfix " instanceof sc_OutputPort"))) */ function sc_isOutputPort(o) { return (o instanceof sc_OutputPort); } /*** META ((export #t) (arity #t) (peephole (postfix ".close()"))) */ function sc_closeOutputPort(p) { return p.close(); } function sc_write(o, p) { if (p === undefined) p = SC_DEFAULT_OUT; p.appendJSString(sc_toWriteString(o)); } function sc_toWriteString(o) { if (o === null) return "()"; else if (o === true) return "#t"; else if (o === false) return "#f"; else if (o === undefined) return "#unspecified"; else if (o === this.window) return "window"; else if (typeof o === 'function') return "#"; else if (o.sc_toWriteString) return o.sc_toWriteString(); else return o.toString(); } function sc_escapeWriteString(s) { var res = ""; var j = 0; for (i = 0; i < s.length; i++) { switch (s.charAt(i)) { case "\0": res += s.substring(j, i) + "\\0"; j = i + 1; break; case "\b": res += s.substring(j, i) + "\\b"; j = i + 1; break; case "\f": res += s.substring(j, i) + "\\f"; j = i + 1; break; case "\n": res += s.substring(j, i) + "\\n"; j = i + 1; break; case "\r": res += s.substring(j, i) + "\\r"; j = i + 1; break; case "\t": res += s.substring(j, i) + "\\t"; j = i + 1; break; case '"': res += s.substring(j, i) + '\\"'; j = i + 1; break; case "\\": res += s.substring(j, i) + "\\\\"; j = i + 1; break; default: var c = s.charAt(i); if ("\a" !== "a" && c == "\a") { res += s.substring(j, i) + "\\a"; j = i + 1; continue; } if ("\v" !== "v" && c == "\v") { res += s.substring(j, i) + "\\v"; j = i + 1; continue; } if (s.charAt(i) < ' ') { res += s.substring(j, i) + "\\x" + s.charCodeAt(i).toString(16); j = i + 1; } } } res += s.substring(j, i); return res; } function sc_display(o, p) { if (p === undefined) p = SC_DEFAULT_OUT; p.appendJSString(sc_toDisplayString(o)); } function sc_toDisplayString(o) { if (o === null) return "()"; else if (o === true) return "#t"; else if (o === false) return "#f"; else if (o === undefined) return "#unspecified"; else if (o === this.window) return "window"; else if (typeof o === 'function') return "#"; else if (o.sc_toDisplayString) return o.sc_toDisplayString(); else return o.toString(); } function sc_newline(p) { if (p === undefined) p = SC_DEFAULT_OUT; p.appendJSString("\n"); } function sc_writeChar(c, p) { if (p === undefined) p = SC_DEFAULT_OUT; p.appendJSString(c.val); } function sc_writeCircle(o, p) { if (p === undefined) p = SC_DEFAULT_OUT; p.appendJSString(sc_toCircleString(o, sc_toWriteString)); } function sc_displayCircle(o, p) { if (p === undefined) p = SC_DEFAULT_OUT; p.appendJSString(sc_toCircleString(o, sc_toDisplayString)); } function sc_toCircleString(o, writeOrDisplay) { var symb = sc_gensym("writeCircle"); var nbPointer = new Object(); nbPointer.nb = 0; sc_prepCircle(o, symb, nbPointer); return sc_genToCircleString(o, symb, writeOrDisplay); } function sc_prepCircle(o, symb, nbPointer) { if (o instanceof sc_Pair || o instanceof sc_Vector) { if (o[symb] !== undefined) { o[symb]++; if (!o[symb + "nb"]) o[symb + "nb"] = nbPointer.nb++; return; } o[symb] = 0; if (o instanceof sc_Pair) { sc_prepCircle(o.car, symb, nbPointer); sc_prepCircle(o.cdr, symb, nbPointer); } else { for (var i = 0; i < o.length; i++) sc_prepCircle(o[i], symb, nbPointer); } } } function sc_genToCircleString(o, symb, writeOrDisplay) { if (!(o instanceof sc_Pair || o instanceof sc_Vector)) return writeOrDisplay(o); return o.sc_toCircleString(symb, writeOrDisplay); } sc_Pair.prototype.sc_toCircleString = function(symb, writeOrDisplay, inList) { if (this[symb + "use"]) { var nb = this[symb + "nb"]; if (this[symb]-- === 0) { delete this[symb]; delete this[symb + "nb"]; delete this[symb + "use"]; } if (inList) return '. #' + nb + '#'; else return '#' + nb + '#'; } if (this[symb]-- === 0) { delete this[symb]; delete this[symb + "nb"]; delete this[symb + "use"]; } var res = ""; if (this[symb] !== undefined) { this[symb + "use"] = true; if (inList) res += '. #' + this[symb + "nb"] + '='; else res += '#' + this[symb + "nb"] + '='; inList = false; } if (!inList) res += "("; res += sc_genToCircleString(this.car, symb, writeOrDisplay); if (sc_isPair(this.cdr)) { res += " " + this.cdr.sc_toCircleString(symb, writeOrDisplay, true); } else if (this.cdr !== null) { res += " . " + sc_genToCircleString(this.cdr, symb, writeOrDisplay); } if (!inList) res += ")"; return res; }; sc_Vector.prototype.sc_toCircleString = function(symb, writeOrDisplay) { if (this[symb + "use"]) { var nb = this[symb + "nb"]; if (this[symb]-- === 0) { delete this[symb]; delete this[symb + "nb"]; delete this[symb + "use"]; } return '#' + nb + '#'; } if (this[symb]-- === 0) { delete this[symb]; delete this[symb + "nb"]; delete this[symb + "use"]; } var res = ""; if (this[symb] !== undefined) { this[symb + "use"] = true; res += '#' + this[symb + "nb"] + '='; } res += "#("; for (var i = 0; i < this.length; i++) { res += sc_genToCircleString(this[i], symb, writeOrDisplay); if (i < this.length - 1) res += " "; } res += ")"; return res; }; function sc_print(s) { if (arguments.length === 1) { sc_display(s); sc_newline(); } else { for (var i = 0; i < arguments.length; i++) sc_display(arguments[i]); sc_newline(); } } function sc_format(s) { var len = s.length; var p = new sc_StringOutputPort(); var i = 0, j = 1; while( i < len ) { var i2 = s.indexOf("~", i); if (i2 == -1) { p.appendJSString( s.substring( i, len ) ); return p.close(); } else if (i2 == (len - 1)) { p.appendJSString(s.substring(i, len)); return p.close(); } else if (i2 == (len - 2) && s.charAt(i2 + 1) == ":") { p.appendJSString(s.substring(i, len)); return p.close(); } else { if (i2 > i) p.appendJSString(s.substring(i, i2)); var alternativeForm = (s.charAt(i2 + 1) == ":"); if (alternativeForm) i2++; i = i2 + 2; switch(s.charCodeAt(i2 + 1)) { case 65: case 97: if (alternativeForm) sc_displayCircle(arguments[j], p); else sc_display(arguments[j], p); j++; break; case 83: case 115: if (alternativeForm) sc_writeCircle(arguments[j], p); else sc_write(arguments[j], p); j++; break; case 86: case 118: if (alternativeForm) sc_displayCircle(arguments[j], p); else sc_display(arguments[j], p); p.appendJSString("\n"); j++; break; case 67: case 99: p.appendJSString(String.fromCharCode(arguments[j])); j++; break; case 88: case 120: p.appendJSString(arguments[j].toString(16)); j++; break; case 79: case 111: p.appendJSString(arguments[j].toString(8)); j++; break; case 66: case 98: p.appendJSString(arguments[j].toString(2)); j++; break; case 37: case 110: p.appendJSString("\n"); break; case 114: p.appendJSString("\r"); break; case 126: p.appendJSString("~"); break; default: sc_error( "format: illegal ~" + String.fromCharCode(s.charCodeAt(i2 + 1)) + " sequence" ); return ""; } } } return p.close(); } var SC_DEFAULT_IN = new sc_ErrorInputPort(); var SC_DEFAULT_OUT = new sc_ErrorOutputPort(); var SC_ERROR_OUT = new sc_ErrorOutputPort(); var sc_SYMBOL_PREFIX = "\uEBAC"; var sc_KEYWORD_PREFIX = "\uEBAD"; /*** META ((export #t) (arity #t) (peephole (id))) */ function sc_jsstring2string(s) { return s; } /*** META ((export #t) (arity #t) (peephole (prefix "'\\uEBAC' +"))) */ function sc_jsstring2symbol(s) { return sc_SYMBOL_PREFIX + s; } /*** META ((export #t) (arity #t) (peephole (id))) */ function sc_string2jsstring(s) { return s; } /*** META ((export #t) (arity #t) (peephole (symbol2jsstring_immutable))) */ function sc_symbol2jsstring(s) { return s.slice(1); } /*** META ((export #t) (arity #t) (peephole (postfix ".slice(1)"))) */ function sc_keyword2jsstring(k) { return k.slice(1); } /*** META ((export #t) (arity #t) (peephole (prefix "'\\uEBAD' +"))) */ function sc_jsstring2keyword(s) { return sc_KEYWORD_PREFIX + s; } /*** META ((export #t) (arity #t) (type bool)) */ function sc_isKeyword(s) { return (typeof s === "string") && (s.charAt(0) === sc_KEYWORD_PREFIX); } var sc_gensym = function() { var counter = 1000; return function(sym) { counter++; if (!sym) sym = sc_SYMBOL_PREFIX; return sym + "s" + counter + "~" + "^sC-GeNsYm "; }; }(); /*** META ((export #t) (arity #t) (type bool)) */ function sc_isEqual(o1, o2) { return ((o1 === o2) || (sc_isPair(o1) && sc_isPair(o2) && sc_isPairEqual(o1, o2, sc_isEqual)) || (sc_isVector(o1) && sc_isVector(o2) && sc_isVectorEqual(o1, o2, sc_isEqual))); } function sc_number2symbol(x, radix) { return sc_SYMBOL_PREFIX + sc_number2jsstring(x, radix); } var sc_number2string = sc_number2jsstring; function sc_symbol2number(s, radix) { return sc_jsstring2number(s.slice(1), radix); } var sc_string2number = sc_jsstring2number; /*** META ((export #t) (arity -2) (peephole (prefix "+" s))) ;; peephole will only apply if no radix is given. */ function sc_string2integer(s, radix) { if (!radix) return +s; return parseInt(s, radix); } /*** META ((export #t) (arity #t) (peephole (prefix "+"))) */ function sc_string2real(s) { return +s; } /*** META ((export #t) (arity #t) (type bool)) */ function sc_isSymbol(s) { return (typeof s === "string") && (s.charAt(0) === sc_SYMBOL_PREFIX); } /*** META ((export #t) (arity #t) (peephole (symbol2string_immutable))) */ function sc_symbol2string(s) { return s.slice(1); } /*** META ((export #t) (arity #t) (peephole (prefix "'\\uEBAC' +"))) */ function sc_string2symbol(s) { return sc_SYMBOL_PREFIX + s; } /*** META ((export symbol-append) (arity -1) (peephole (symbolAppend_immutable))) */ function sc_symbolAppend() { var res = sc_SYMBOL_PREFIX; for (var i = 0; i < arguments.length; i++) res += arguments[i].slice(1); return res; } /*** META ((export #t) (arity #t) (peephole (postfix ".val"))) */ function sc_char2string(c) { return c.val; } /*** META ((export #t) (arity #t) (peephole (hole 1 "'\\uEBAC' + " c ".val"))) */ function sc_char2symbol(c) { return sc_SYMBOL_PREFIX + c.val; } /*** META ((export #t) (arity #t) (type bool)) */ function sc_isString(s) { return (typeof s === "string") && (s.charAt(0) !== sc_SYMBOL_PREFIX); } var sc_makeString = sc_makejsString; function sc_string() { for (var i = 0; i < arguments.length; i++) arguments[i] = arguments[i].val; return "".concat.apply("", arguments); } /*** META ((export #t) (arity #t) (peephole (postfix ".length"))) */ function sc_stringLength(s) { return s.length; } function sc_stringRef(s, k) { return new sc_Char(s.charAt(k)); } /* there's no stringSet in the immutable version function sc_stringSet(s, k, c) */ /*** META ((export string=?) (arity #t) (type bool) (peephole (hole 2 str1 " === " str2))) */ function sc_isStringEqual(s1, s2) { return s1 === s2; } /*** META ((export string?) (arity #t) (type bool) (peephole (hole 2 str1 " > " str2))) */ function sc_isStringGreater(s1, s2) { return s1 > s2; } /*** META ((export string<=?) (arity #t) (type bool) (peephole (hole 2 str1 " <= " str2))) */ function sc_isStringLessEqual(s1, s2) { return s1 <= s2; } /*** META ((export string>=?) (arity #t) (type bool) (peephole (hole 2 str1 " >= " str2))) */ function sc_isStringGreaterEqual(s1, s2) { return s1 >= s2; } /*** META ((export string-ci=?) (arity #t) (type bool) (peephole (hole 2 str1 ".toLowerCase() === " str2 ".toLowerCase()"))) */ function sc_isStringCIEqual(s1, s2) { return s1.toLowerCase() === s2.toLowerCase(); } /*** META ((export string-ci?) (arity #t) (type bool) (peephole (hole 2 str1 ".toLowerCase() > " str2 ".toLowerCase()"))) */ function sc_isStringCIGreater(s1, s2) { return s1.toLowerCase() > s2.toLowerCase(); } /*** META ((export string-ci<=?) (arity #t) (type bool) (peephole (hole 2 str1 ".toLowerCase() <= " str2 ".toLowerCase()"))) */ function sc_isStringCILessEqual(s1, s2) { return s1.toLowerCase() <= s2.toLowerCase(); } /*** META ((export string-ci>=?) (arity #t) (type bool) (peephole (hole 2 str1 ".toLowerCase() >= " str2 ".toLowerCase()"))) */ function sc_isStringCIGreaterEqual(s1, s2) { return s1.toLowerCase() >= s2.toLowerCase(); } /*** META ((export #t) (arity #t) (peephole (hole 3 s ".substring(" start ", " end ")"))) */ function sc_substring(s, start, end) { return s.substring(start, end); } /*** META ((export #t) (arity -4)) */ function sc_isSubstring_at(str1, str2, i, len) { if (!len) len = str2.length; else if (str2.length < len) return false; if (str1.length < len + i) return false; return str2.substring(0, len) == str1.substring(i, i+len); return s2 == s1.substring(i, i+ s2.length); } /*** META ((export substring=?) (arity #t)) */ function sc_isSubstring(s1, s2, len) { if (s1.length < len) return false; if (s2.length < len) return false; return s2.substring(0, len) == s1.substring(0, len); } /*** META ((export #t) (arity -1) (peephole (infix 0 #f "+" "''"))) */ function sc_stringAppend() { return "".concat.apply("", arguments); } var sc_string2list = sc_jsstring2list; var sc_list2string = sc_list2jsstring; /*** META ((export #t) (arity #t) (peephole (id))) */ function sc_stringCopy(s) { return s; } /* there's no string-fill in the immutable version function sc_stringFill(s, c) */ /*** META ((export #t) (arity #t) (peephole (postfix ".slice(1)"))) */ function sc_keyword2string(o) { return o.slice(1); } /*** META ((export #t) (arity #t) (peephole (prefix "'\\uEBAD' +"))) */ function sc_string2keyword(o) { return sc_KEYWORD_PREFIX + o; } String.prototype.sc_toDisplayString = function() { if (this.charAt(0) === sc_SYMBOL_PREFIX) return this.slice(1); else if (this.charAt(0) === sc_KEYWORD_PREFIX) return ":" + this.slice(1); else return this.toString(); }; String.prototype.sc_toWriteString = function() { if (this.charAt(0) === sc_SYMBOL_PREFIX) return this.slice(1); else if (this.charAt(0) === sc_KEYWORD_PREFIX) return ":" + this.slice(1); else return '"' + sc_escapeWriteString(this) + '"'; }; /*** META ((export #t) (arity #t) (peephole (hole 2 1 ".indexOf(" 0 ") === 0"))) */ function sc_isStringPrefix(cs1, cs2) { return cs2.indexOf(cs1) === 0; } function sc_isStringSuffix(cs1, cs2) { var tmp = cs2.lastIndexOf(cs1); return tmp !== false && tmp >= 0 && tmp === cs2.length - cs1.length; } function sc_stringSplit(s, sep) { if (sep.length === 1) return sc_vector2list(s.split(sep)); return sc_vector2list(s.split(sc_pregexpCreateCharsetMatcher(sep))); } function sc_stringIndex(s, cset, start) { var res; if (!start) start = 0; if (cset instanceof sc_Char) { res = s.indexOf(sc_char2string(cset), start); return res >= 0 ? res : false; } if (cset.length == 1) { res = s.indexOf(cset, start); return res >= 0 ? res : false; } else { for (var i = start; i < s.length; i++ ) { if (cset.indexOf(s.charAt(i))) return i; } return false; } } function sc_stringIndexRight(s, cset, start) { var res; if (!start) start = s.length - 1; if (cset instanceof sc_Char) { res = s.lastIndexof(sc_char2string(cset), start); return res >= 0 ? res : false; } if (cset.length == 1) { res = s.lastIndexOf(cset, start); return res >= 0 ? res : false; } else { for (var i = start; i >= 0; i-- ) { if (cset.indexOf(s.charAt(i))) return i; } return false; } } function dom_add_child( node, e ) { if( hop_is_html_element( e ) ) { node.appendChild( e ); } else { if( (e instanceof String) || (typeof e == "string") || (typeof e == "number") ) { node.appendChild( document.createTextNode( e ) ); } else { if( sc_isPair( e ) ) { dom_add_child( node, e.car ); dom_add_child( node, e.cdr ); } else { if( e ) { sc_error( "dom_add_child", "illegal child node", e ); } } } } } function dom_set_child_node( parent, node ) { var childs = parent.childNodes; for( var nc = childs.length - 1; nc >=0; nc-- ) parent.removeChild( childs[ nc ] ); dom_add_child( parent, node ); return node; } /*** META ((export dom-node-element?) (peephole (postfix ".nodeType == 1")) (arity #t)) */ function dom_node_elementp( node ) { return node.nodeType == 1; } /*** META ((export dom-node-text?) (peephole (postfix ".nodeType == 3")) (arity #t)) */ function dom_node_textp( node ) { return node.nodeType == 3; } /*** META ((export dom-node-document?) (peephole (postfix ".nodeType == 9")) (arity #t)) */ function dom_node_documentp( node ) { return node.nodeType == 9; } /*** META ((export dom-node-comment?) (peephole (postfix ".nodeType == 8")) (arity #t)) */ function dom_node_commentp( node ) { return node.nodeType == 8; } /*** META ((export dom-node-document-fragment?) (peephole (postfix ".nodeType == 11")) (arity #t)) */ function dom_node_document_fragmentp( node ) { return node.nodeType == 11; } /*** META ((export dom-node-attr?) (peephole (postfix ".nodeType == 2")) (arity #t)) */ function dom_node_document_attrp( node ) { return node.nodeType == 2; } function dom_create( tag, args ) { var el = document.createElement( tag ); var l = arguments.length; var i = 1; while( i < l ) { var k = arguments[ i ]; if( sc_isKeyword( k ) ) { if( i < (l - 1) ) { var at = arguments[ i + 1 ]; var prop = sc_keyword2jsstring( k ); if( prop == "class" ) { el.className = at; } else { if( (at instanceof String) || (typeof at == "string") ) { if( sc_isSymbol( at ) ) { el.setAttribute( prop, sc_symbol2jsstring( at ) ); } else { el.setAttribute( prop, at ); } } else { el.setAttribute( prop, at + "" ); try { el[ prop ] = at; } catch( _ ) { ; } } } i += 2; } else { var prop = sc_keyword2jsstring( k ); el.setAttribute( prop, prop ); i++; } } else { dom_add_child( el, k ); i++; } } return el; } /*** META (define-macro (hop_dom_create_custom kons . args) (let loop ((args args) (attrs '()) (body '()) (listeners '())) (cond ((null? args) (let ((v (gensym))) `(let ((,v (,kons (list ,@(reverse! attrs)) (list ,@(reverse! body))))) ,@(map (lambda (listener) `(add-event-listener! ,v ,@listener)) listeners) ,v))) ((or (null? (cdr args)) (not (keyword? (car args)))) (loop (cdr args) attrs (cons (car args) body) listeners)) ((string-prefix? "on" (keyword->string (car args))) (let ((s (keyword->string (car args)))) (loop (cddr args) attrs body (cons (list (substring s 2 (string-length s)) `(lambda (event) ,(cadr args))) listeners)))) (else (loop (cddr args) (cons* (cadr args) (car args) attrs) body listeners))))) */ /*** META (define-macro (hop_dom_create tag . args) (let loop ((args args) (attrs '()) (listeners '())) (cond ((null? args) (let ((v (gensym))) `(let ((,v ((@ dom_create _) ,tag ,@(reverse! attrs)))) ,@(map (lambda (listener) `(add-event-listener! ,v ,@listener)) listeners) ,v))) ((or (null? (cdr args)) (not (keyword? (car args)))) (loop (cdr args) (cons (car args) attrs) listeners)) ((string-prefix? "on" (keyword->string (car args))) (let ((s (keyword->string (car args)))) (loop (cddr args) attrs (cons (list (substring s 2 (string-length s)) `(lambda (event) ,(cadr args))) listeners)))) (else (loop (cddr args) (cons* (cadr args) (car args) attrs) listeners))))) */ function dom_add_head_script( pathname, id ) { var head = document.getElementsByTagName( "head" )[ 0 ]; var script = document.createElement( 'script' ); script.type = 'text/javascript'; script.src = pathname; if( id != undefined ) script.id = id; head.appendChild( script ); } function hop_create_lframe( attrs, body ) { var hc = sc_jsstring2keyword( "hssclass" ); var bd = dom_create( "div", hc, "hop-lfborder", body ); return dom_create( "div", hc, "hop-lframe", bd ); } function hop_create_lflabel( attrs, body ) { var hc = sc_jsstring2keyword( "hssclass" ); var ct = dom_create( "span", body ); return dom_create( "div", hc, "hop-lflabel", ct ); } /*** META (define-macro ( . args) `(hop_dom_create "a" ,@args)) */ /*** META (define-macro ( . args) `(hop_dom_create "abbr" ,@args)) */ /*** META (define-macro ( . args) `(hop_dom_create "acronym" ,@args)) */ /*** META (define-macro ( . args) `(hop_dom_create "applet" ,@args)) */ /*** META (define-macro ( . args) `(hop_dom_create "area" ,@args)) */ /*** META (define-macro ( . args) `(hop_dom_create "b" ,@args)) */ /*** META (define-macro ( . args) `(hop_dom_create "base" ,@args)) */ /*** META (define-macro ( . args) `(hop_dom_create "basefont" ,@args)) */ /*** META (define-macro ( . args) `(hop_dom_create "bdo" ,@args)) */ /*** META (define-macro ( . args) `(hop_dom_create "big" ,@args)) */ /*** META (define-macro (
. args) `(hop_dom_create "blockquote" ,@args)) */ /*** META (define-macro ( . args) `(hop_dom_create "body" ,@args)) */ /*** META (define-macro (
. args) `(hop_dom_create "br" ,@args)) */ /*** META (define-macro (