lotus / dist /assets /index-ygwAcZb2.js
k-l-lambda's picture
Updated frontend assets.
358e8de
class FatalError extends Error{constructor(t){super(t)}}class MaxEvaluationCountError extends FatalError{constructor(){super("[SX] evaluate: The maximum count of evaluations has been exceeded.")}}class ScriptTerminationError extends FatalError{constructor(t){super(`[SX] ${t}: Unexpected termination of script.`)}}function quote(n,t){return[{symbol:n.config.reservedNames.quote},t]}function isQuoted(n,t){if(Array.isArray(t)&&0<t.length){const e=isSymbol(t);if(e&&e.symbol===n.config.reservedNames.quote)return!0}return!1}function backquote(n,t){return[{symbol:n.config.reservedNames.backquote},t]}function isBackquoted(n,t){if(Array.isArray(t)&&0<t.length){const e=isSymbol(t);if(e&&e.symbol===n.config.reservedNames.backquote)return!0}return!1}function wrapByUnquote(n,t){return[{symbol:n.config.reservedNames.unquote},t]}function isUnquoted(n,t){if(Array.isArray(t)&&0<t.length){const e=isSymbol(t);if(e&&e.symbol===n.config.reservedNames.unquote)return!0}return!1}function spread(n,t){return[{symbol:n.config.reservedNames.spread},t]}function splice(n,t){return[{symbol:n.config.reservedNames.splice},t]}function isSymbol(n,t){return n&&typeof n=="object"&&Object.prototype.hasOwnProperty.call(n,"symbol")?t!==void 0?n.symbol===t?n:null:n:null}const defaultReservedNames={eval:"$eval",quote:"$quote",backquote:"$backquote",unquote:"$unquote",spread:"$spread",splice:"$splice",car:"$car",cdr:"$cdr",cons:"$cons",atom:"$atom",eq:"$eq",list:"$list",let:"$clisp-let",lambda:"$lambda",self:"$self",defun:"$defun",thiz:"$this",if:"$if",cond:"$cond",while:"$while",doWhile:"$do-while",until:"$until",doUntil:"$do-until",get:"$get",defvar:"$clisp-defvar",setq:"$clisp-setq",set:"$set",call:"$call",not:"$not",and:"$and",or:"$or",isSymbol:"$is-symbol",gensym:"$gensym",raise:"$raise",catch:"$catch",Template:"Template"},defaultConfig={raiseOnUnresolvedSymbol:!1,enableEvaluate:!0,enableHereDoc:!0,enableSpread:!0,enableSplice:!0,enableShorthands:!0,enableVerbatimStringLiteral:!0,enableTailCallOptimization:!0,enableRegExpMatchOperators:!0,enableCompilationOperators:!0,stripComments:!1,wrapExternalValue:!0,returnMultipleRoot:!1,maxEvalCount:0,reservedNames:defaultReservedNames,symbols:[],macros:[],funcs:[]};function isEOF(n){return typeof n=="object"&&Object.prototype.hasOwnProperty.call(n,"eof")}function isSpace(n){return typeof n=="string"&&n.trim().length===0}function isNumberFirstChar(n){return typeof n=="string"&&/^[0-9\+\-]$/.test(n)}function isNumberAfterSignChar(n){return typeof n=="string"&&/^[0-9]$/.test(n)}function isSymbolFirstChar(n){return typeof n=="string"&&!isSpace(n)&&!isNumberFirstChar(n)}function lookCurrentLineHint(n){return`line: ${n.line} / strings: ${n.index} / pos: ${n.pos} :${n.strings.length>n.index?n.strings[n.index].slice(n.pos,n.pos+20):""}`}function getChar(n,t,e){if(n.strings.length<=n.index)return{eof:!0};if(n.strings[n.index].length<=n.pos){if(!n.values||n.values.length<=n.index)return n.pos=0,n.index++,getChar(n);{const r={value:n.values[n.index]};return n.pos=0,n.index++,r}}if(t)for(const r of t){const o=n.strings[n.index].slice(n.pos,n.pos+r.length);if(o===r)return n.pos+=r.length,n.line+=o.split(`
`).length-1,{eof:!1,eofSeq:r}}{let r=n.strings[n.index].slice(n.pos,n.pos+1);if(n.pos++,r===`
`&&n.line++,!e&&r==="\\"){if(n.strings[n.index].length<=n.pos)throw new Error(`[SX] getChar: Invalid syntax at: ${lookCurrentLineHint(n)}.`);switch(r=n.strings[n.index].slice(n.pos,n.pos+1),n.pos++,r){case"b":r="\b";break;case"t":r=" ";break;case"n":r=`
`;break;case"v":r="\v";break;case"f":r="\f";break;case"r":r="\r";break;case"U":case"u":if(n.strings[n.index].slice(n.pos,n.pos+1)==="{"){let o="";for(let s=0;s<6;s++){const a=n.strings[n.index].slice(n.pos+s,n.pos+1+s);if(a==="}"){if(s===0)throw new Error(`[SX] getChar: Invalid syntax at: ${lookCurrentLineHint(n)}.`);n.pos+=s;break}else if(!/^[0-9A-Fa-f]{1}$/.test(o))throw new Error(`[SX] getChar: Invalid syntax at: ${lookCurrentLineHint(n)}.`);o+=a}if(n.strings[n.index].slice(n.pos,n.pos+1)!=="}")throw new Error(`[SX] getChar: Invalid syntax at: ${lookCurrentLineHint(n)}.`);n.pos++,r=String.fromCodePoint(Number.parseInt(o,16))}else{const o=n.strings[n.index].slice(n.pos,n.pos+4);if(!/^[0-9A-Fa-f]{4}$/.test(o))throw new Error(`[SX] getChar: Invalid syntax at: ${lookCurrentLineHint(n)}.`);n.pos+=4,r=String.fromCodePoint(Number.parseInt(o,16))}break}}return r}}function lookAheads(n,t,e,r){const o=n.index,s=n.pos,a=n.line,l=[];try{for(let i=0;i<t;i++)l.push(getChar(n,e,r))}finally{n.index=o,n.pos=s,n.line=a}return l}function lookAhead(n,t,e){const r=n.index,o=n.pos,s=n.line;let a;try{a=getChar(n,t,e)}finally{n.index=r,n.pos=o,n.line=s}return a}function skipWhitespaces(n){let t=lookAhead(n);for(;!isEOF(t)&&isSpace(t);)getChar(n),t=lookAhead(n)}function parseNumber(n,t){let e="",r=lookAhead(n,t);for(;!isEOF(r)&&typeof r=="string";){if(/^0[XxOoBb][0-9]*$/.test(e+r))getChar(n,t),e+=r;else if(/^[0-9\+\-\.EeInfinityNaN]+$/.test(e+r))getChar(n,t),e+=r;else break;r=lookAhead(n,t)}if(!/^([\+\-]?\d*\.?\d+(?:[Ee][\+\-]?\d+)?)|(0[XxOoBb][0-9]+)|([\+\-]Infinity)|(NaN)$/.test(e))throw new Error(`[SX] parseNumber: Invalid syntax at: ${lookCurrentLineHint(n)}.`);return Number(e)}function parseSymbol(n,t){let e="",r=lookAhead(n,t);for(;!isEOF(r);){if(typeof r=="string"){if(isSpace(r))break;if(r==="#"&&lookAheads(n,2,t)[1]==="|")break;if(/^[^.;()"]+$/.test(e+r))getChar(n,t),e+=r;else break}else if(typeof r=="object"&&Object.prototype.hasOwnProperty.call(r,"value"))getChar(n,t),r.value,e+=String(r);else throw new Error(`[SX] parseSymbol: Invalid syntax at: ${lookCurrentLineHint(n)}.`);r=lookAhead(n,t)}if(n.config.enableShorthands){let o=null;if(o=e.match(/^:((?:\:[^=:]+?)+?)=$/)){const s=o[1].slice(1).split(":");return[{symbol:n.config.reservedNames.splice},[{symbol:n.config.reservedNames.set},s]]}else if(o=e.match(/^:((?:\:[^@:]+?)+?)@([^@:]+?)$/)){const s=o[1].slice(1).split(":");return[{symbol:n.config.reservedNames.splice},[{symbol:n.config.reservedNames.call},[{symbol:n.config.reservedNames.get},...s],{symbol:o[2]}]]}else if(o=e.match(/^:((?:\:[^:]+?)+?)$/)){const s=o[1].slice(1).split(":");return[{symbol:n.config.reservedNames.get},...s]}}return{symbol:e}}function parseStringOrComment(n,t,e,r,o,s){const a=e?[...t,e]:t,l=[],i=[];for(;;){let m="",c=lookAhead(n,a,o);for(;!isEOF(c);){if(typeof c=="string")getChar(n,a,o),m+=c;else if(typeof c=="object"&&Object.prototype.hasOwnProperty.call(c,"value"))getChar(n,a,o),c.value,m+=String(c);else throw new Error(`[SX] parseStringOrComment: Invalid syntax at: ${lookCurrentLineHint(n)}.`);c=lookAhead(n,a,o)}if(getChar(n,a,o),c.eof===!0&&!s)throw new ScriptTerminationError("parseStringOrComment");if(l.push(m),c.eofSeq===e)i.push(parseList(n,r,[]));else break}return{strings:l,values:i}}function parseString(n,t){return parseStringOrComment(n,['"'],null,")",t,!1).strings[0]}function parseHereDoc(n,t,e){const r=[t];e&&r.push(e);const o=parseStringOrComment(n,['"""'],"%%%(",")",!1,!1);for(let s=0;s<o.strings.length;s++)r.push(o.strings[s]),s<o.values.length&&r.push(o.values[s]);return r}function parseSingleLineComment(n){return{comment:parseStringOrComment(n,["\r",`
`],null,")",!1,!0).strings[0]}}function parseMultiLineComment(n){return{comment:parseStringOrComment(n,["|#"],null,")",!1,!1).strings[0]}}function parseOneToken(n){skipWhitespaces(n);let t=lookAhead(n);for(;!isEOF(t);){switch(t){case")":throw new Error(`[SX] parseOneToken: Invalid syntax at: ${lookCurrentLineHint(n)}.`);case"(":return getChar(n),parseList(n,")",[]);case"'":case"`":case",":{getChar(n);const e=lookAhead(n);let r=!1;t===","&&e==="@"&&(getChar(n),r=!0),skipWhitespaces(n);const o=(t==="'"?quote:t==="`"?backquote:wrapByUnquote)(n,parseOneToken(n));return r?splice(n,o):o}case".":{getChar(n);const e=lookAheads(n,2);return n.config.enableSpread&&e[0]==="."&&e[1]==="."?(getChar(n),getChar(n),skipWhitespaces(n),spread(n,parseOneToken(n))):(skipWhitespaces(n),{dotted:parseOneToken(n)})}case";":return getChar(n),parseSingleLineComment(n);case"#":return lookAheads(n,2)[1]==="|"?(getChar(n),getChar(n),parseMultiLineComment(n)):parseSymbol(n);case'"':{getChar(n);const e=lookAheads(n,4);if(n.config.enableHereDoc&&e[0]==='"'&&e[1]==='"'){let r=!0;isEOF(e[2])||isSpace(e[2])||(isNumberFirstChar(e[2])?(e[2]==="+"||e[2]==="-")&&(isNumberAfterSignChar(e[3])||(r=!1)):isSymbolFirstChar(e[2])&&(r=!1)),getChar(n),getChar(n);let o=null,s=null;if(r)o={symbol:n.config.reservedNames.Template};else{if(o=parseSymbol(n,["@"]),o===null)throw new Error(`[SX] parseOneToken: Invalid syntax at: ${lookCurrentLineHint(n)}.`);if(typeof o=="number")throw new Error(`[SX] parseOneToken: Invalid syntax at: ${lookCurrentLineHint(n)}.`);const a=lookAheads(n,2);if(a[0]==="@"){if(a[1]!=="{")throw new Error(`[SX] parseOneToken: Invalid syntax at: ${lookCurrentLineHint(n)}.`);getChar(n),getChar(n);const l=parseList(n,"}",[{symbol:"@"}]);Array.isArray(l)&&(s=l)}}return parseHereDoc(n,o,s)}else return parseString(n,!1)}case"@":if(n.config.enableVerbatimStringLiteral&&lookAheads(n,2)[1]==='"')return getChar(n),getChar(n),parseString(n,!0);default:if(typeof t!="string"){if(typeof t=="object"&&Object.prototype.hasOwnProperty.call(t,"value"))return getChar(n),n.config.wrapExternalValue?t:t.value;throw new Error(`[SX] parseOneToken: Invalid syntax at: ${lookCurrentLineHint(n)}.`)}else{if(isSpace(t))break;if(isNumberFirstChar(t)){if(t==="+"||t==="-"){const e=lookAheads(n,2);if(!isNumberAfterSignChar(e[1]))return parseSymbol(n)}return parseNumber(n)}else{if(isSymbolFirstChar(t))return parseSymbol(n);throw new Error(`[SX] parseOneToken: Invalid syntax at: ${lookCurrentLineHint(n)}.`)}}}skipWhitespaces(n),t=lookAhead(n)}throw new ScriptTerminationError("parseOneToken")}function parseList(n,t,e){const r=e.slice(0);let o=!1;skipWhitespaces(n);let s=lookAhead(n);for(;!isEOF(s);){switch(s){case t:return getChar(n),o?r[0]:r;default:{const a=parseOneToken(n);if(typeof a=="object"&&Object.prototype.hasOwnProperty.call(a,"dotted")){if(r.length!==1)throw new Error(`[SX] parseList: Invalid syntax at: ${lookCurrentLineHint(n)}.`);o=!0,Array.isArray(a)?(a.unshift(r.pop()),r.push(a)):r.push({car:r.pop(),cdr:a.dotted})}else if(typeof a=="object"&&Object.prototype.hasOwnProperty.call(a,"comment"))n.config.stripComments||r.push(a);else{if(o)throw new Error(`[SX] parseList: Invalid syntax at: ${lookCurrentLineHint(n)}.`);r.push(a)}}break}skipWhitespaces(n),s=lookAhead(n)}throw new ScriptTerminationError("parseList")}function parse(n){const t=[];skipWhitespaces(n);let e=lookAhead(n);for(;!isEOF(e);){switch(e){case"(":getChar(n),t.push(parseList(n,")",[]));break;case"'":case"`":{for(getChar(n),skipWhitespaces(n);;){const r=parseOneToken(n);if(typeof r=="object"&&Object.prototype.hasOwnProperty.call(r,"comment"))n.config.stripComments||t.push(r);else{t.push((e==="'"?quote:backquote)(n,r));break}}break}case";":getChar(n),n.config.stripComments?parseSingleLineComment(n):t.push(parseSingleLineComment(n));break;case"#":lookAheads(n,2)[1]==="|"?(getChar(n),getChar(n),n.config.stripComments?parseMultiLineComment(n):t.push(parseMultiLineComment(n))):(getChar(n),n.config.stripComments?parseSingleLineComment(n):t.push(parseSingleLineComment(n)));break;case'"':{const r=lookAheads(n,3);if(r[1]==='"'&&r[2]==='"'){t.push(parseOneToken(n));break}}default:throw new Error(`[SX] parseInitialState: Invalid syntax at: ${lookCurrentLineHint(n)}.`)}skipWhitespaces(n),e=lookAhead(n)}return t}const globalObj=Function("return this")();function setEvaluationCount(n){if(n.evalCount++,n.config.maxEvalCount&&n.config.maxEvalCount<n.evalCount)throw new MaxEvaluationCountError}function checkParamsLength(n,t,e,r){if(t.length<e)throw new Error(`[SX] ${n}: Invalid argument length: expected: ${e} / args: ${t.length}.`);if(r&&r<t.length)throw new Error(`[SX] ${n}: Invalid argument length: expected: ${r} / args: ${t.length}.`);return t}const objConstructor={}.constructor,funConstructor=Function;function checkUnsafeVarNames(n,t){if(t==="__proto__"||t==="__defineGetter__"||t==="__defineSetter__"||t==="__lookupGetter__"||t==="__lookupSetter__")throw new Error(`[SX] ${n}: Invalid var name ${t}.`);if(t==="prototype"||t==="constructor")throw new Error(`[SX] ${n}: Invalid var name ${t}.`);if(objConstructor.hasOwnProperty(t))throw new Error(`[SX] ${n}: Invalid var name ${t}.`);if(t==="call"||t==="arguments"||t==="caller")throw new Error(`[SX] ${n}: Invalid var name ${t}.`);return t}function checkUnsafeVarNamesEx(n,t,e){if(t===globalObj||e==="__proto__"||e==="__defineGetter__"||e==="__defineSetter__"||e==="__lookupGetter__"||e==="__lookupSetter__")throw new Error(`[SX] ${n}: Invalid var name ${e}.`);if((e==="prototype"||e==="constructor")&&(t==null||typeof t=="function"))throw new Error(`[SX] ${n}: Invalid var name ${e}.`);if((t==null||t===objConstructor)&&objConstructor.hasOwnProperty(e))throw new Error(`[SX] ${n}: Invalid var name ${e}.`);if(t==null||t===funConstructor){let r=funConstructor;for(;r;){if(r.hasOwnProperty(e))throw new Error(`[SX] ${n}: Invalid var name ${e}.`);r=r.__proto__}}if(typeof t=="function"&&!t.hasOwnProperty(e))throw new Error(`[SX] ${n}: Invalid var name ${e}.`);return e}function toNumber(n){switch(typeof n){case"object":case"symbol":case"function":return NaN;default:return Number(n)}}function resolveUnquote(n,t){for(let e=0;e<t.length;e++)Array.isArray(t[e])&&isSymbol(t[e][0],n.config.reservedNames.unquote)&&(t=t.slice(0,e).concat([evaluate(n,t[e][1])],t.slice(e+1))),Array.isArray(t[e])&&(t=t.slice(0),t[e]=resolveUnquote(n,t[e]));return resolveSplice(n,t)}function resolveSplice(n,t){if(n.config.enableSplice)for(let e=t.length-1;e>=0;e--)Array.isArray(t[e])&&isSymbol(t[e][0],n.config.reservedNames.splice)&&(t=t.slice(0,e).concat(t[e][1],t.slice(e+1)));return t}function resolveMacro(n,t,e){const r=n.macroMap.get(t.symbol);let o=null;if(r){let s=r;const a=e.slice(1);for(;s;)if(s.formalArgs){const l=matchMacroArgs(n,t.symbol,s.formalArgs,!!s.lastIsSpread,a);if(!l.error)return{fn:s.fn(n,t.symbol,l.formalArgs),actualArgs:e.slice(0,1).concat(l.actualArgs)};o=l.error,s=s.next}else return{fn:s.fn(n,t.symbol),actualArgs:e};if(o)throw new Error(o)}return!1}function resolveFunctionSymbol(n,t){if(typeof t=="function")return t;const e=n.funcMap.get(t.symbol);if(e)return e.fn(n,t.symbol);{const r=resolveValueSymbol(n,t);if(typeof r=="function")return r;if(n.config.funcSymbolResolverFallback)return n.config.funcSymbolResolverFallback(n,t.symbol);if(n.config.raiseOnUnresolvedSymbol)throw new Error(`[SX] resolveFunctionSymbol: Unresolved symbol: ${t.symbol}.`);return t.symbol}}function resolveValueSymbolScope(n,t,e){for(let o=n.scopes.length-1;o>0;o--){const s=n.scopes[o];if(s&&Object.prototype.hasOwnProperty.call(s.scope,t.symbol))return s.scope;if(s.capturedScopes&&Object.prototype.hasOwnProperty.call(s.capturedScopes,t.symbol))return s.capturedScopes[t.symbol];if(!s.isBlockLocal)break}const r=getGlobalScope(n);return Object.prototype.hasOwnProperty.call(r.scope,t.symbol)?r.scope:e?null:getScope(n).scope}function resolveValueSymbol(n,t){const e=resolveValueSymbolScope(n,t,!0);if(e)return e[t.symbol];const r=n.symbolMap.get(t.symbol);if(r)return r.fn(n,t.symbol);if(n.config.valueSymbolResolverFallback)return n.config.valueSymbolResolverFallback(n,t.symbol);if(n.config.raiseOnUnresolvedSymbol)throw new Error(`[SX] resolveValueSymbol: Unresolved symbol: ${t.symbol}.`);return t.symbol}function collectCapturedVariables(n,t){const e={};for(const r of t){const o=resolveValueSymbolScope(n,r,!0);if(o===null)throw new Error(`[SX] collectCapturedVariables: Unresolved symbols ${r}`);checkUnsafeVarNamesEx("collectCapturedVariables",e,r.symbol),e[r.symbol]=o}return e}function getCapturedScopes(n){const t=[];for(let e=n.scopes.length-1;e>0;e--){const r=n.scopes[e];if(r.capturedScopes&&t.unshift(r.capturedScopes),!r.isBlockLocal)break}return t.length>0?Object.assign({},...t):void 0}function installScope(n,t,e,r){n.scopes.push({isBlockLocal:e,scope:t,capturedScopes:r})}function uninstallScope(n){if(n.scopes.length<2)throw new Error("[SX] uninstallScope: Unable to pop stack.");return n.scopes.pop()}function getScope(n){return n.scopes[n.scopes.length-1]}function getGlobalScope(n){return n.scopes[0]}function matchMacroArgs(n,t,e,r,o){if(e=e.slice(0),o=o.slice(0),o.length+(r?1:0)<e.length)return{error:`[SX] macro call (${t}): Actual args too short: actual ${o.length} / formal ${e.length}.`};for(let s=e.length-(r?2:1);s>=0;s--){let a=e[s].symbol;if(a.startsWith("!")){if(e[s].symbol=e[s].symbol.slice(1),a=e[s].symbol,!isSymbol(o[s]))return{error:`[SX] macro call (${t}): Actual arg(${s}: ${a}) is not symbol.`}}else if(a.startsWith("<")&&a.endsWith(">"))if(e[s].symbol=e[s].symbol.slice(1,-1),a=e[s].symbol,isSymbol(o[s],a))e=e.slice(0,s).concat(e.slice(s+1)),o=o.slice(0,s).concat(o.slice(s+1));else return{error:`[SX] macro call (${t}): Actual arg(${s}: ${a}) is not expected symbol.`};else{const l=a.lastIndexOf(":");if(0<l){const i=a.slice(l+1);switch(i){case"number":if(typeof o[s]!="number")return{error:`[SX] macro call (${t}): Actual arg(${s}: ${a}) is not number.`};break;case"string":if(typeof o[s]!="string")return{error:`[SX] macro call (${t}): Actual arg(${s}: ${a}) is not string.`};break;case"function":if(!(Array.isArray(o[s])&&isSymbol(o[s][0])))return{error:`[SX] macro call (${t}): Actual arg(${s}: ${a}) is not function.`};break;case"list":if(!Array.isArray(o[s]))return{error:`[SX] macro call (${t}): Actual arg(${s}: ${a}) is not list.`};break;case"symbol":if(!isSymbol(o[s]))return{error:`[SX] macro call (${t}): Actual arg(${s}: ${a}) is not symbol.`};break;case"any":break;default:return{error:`[SX] macro call (${t}): Formal arg(${s}: ${a}) is unknown type ${i}.`}}e[s].symbol=e[s].symbol.slice(0,l)}}}return{formalArgs:e,actualArgs:o}}function optimizeTailCall(n,t,e){if(Array.isArray(e[e.length-1])){const r=e.slice(0,e.length-1),o=e[e.length-1];if(o&&typeof o[0]=="object"&&o[0].symbol===n.config.reservedNames.if&&Array.isArray(o[3])&&typeof o[3][0]=="object"&&o[3][0].symbol===n.config.reservedNames.self){const s=`$__tempvar__$$ec${n.evalCount++}$$_`,a=t.map((l,i)=>({symbol:`${s}_$i${i}_${l.symbol}`}));return[[{symbol:n.config.reservedNames.until},o[1],[{symbol:n.config.reservedNames.let},[...a],...r,...o[3].slice(1).map((l,i)=>[{symbol:n.config.reservedNames.set},a[i],l]),...a.map((l,i)=>[{symbol:n.config.reservedNames.set},t[i],l])]],...r,o[2]]}}return e}function evaluate(n,t){if(setEvaluationCount(n),t==null)return t;let e=t;for(;Array.isArray(e);){{if(e.length===0)return e;e=resolveSplice(n,e);const r=isSymbol(e[0]);if(r){const o=resolveMacro(n,r,e);if(o)e=o.fn(o.actualArgs);else break}else break}setEvaluationCount(n)}if(Array.isArray(e)){if(e=e.slice(0),0<e.length){const r=isSymbol(e[0]);if(r){if(r.symbol===n.config.reservedNames.quote)return e.slice(1,2)[0];if(r.symbol===n.config.reservedNames.backquote)return e=e.slice(1,2)[0],Array.isArray(e)&&(e=resolveUnquote(n,e)),e;if(r.symbol===n.config.reservedNames.eval)return evaluate(n,evaluate(n,e.slice(1,2)[0]))}const o=[];for(let a=1;a<e.length;a++)if(Array.isArray(e[a])&&isSymbol(e[a][0],n.config.reservedNames.spread)){o.push(a);const i=evaluate(n,e[a][1]);e[a]=Array.isArray(i)?i:[i]}else e[a]=evaluate(n,e[a]);for(const a of o.reverse())e=e.slice(0,a).concat(e[a],e.slice(a+1));let s;if(typeof e[0]=="function"?s=e[0]:r?s=resolveFunctionSymbol(n,r):s=evaluate(n,e[0]),typeof s=="function")e=s(...e.slice(1));else throw new Error(`[SX] evaluate: First item of list is not a function: ${JSON.stringify(e)}.`)}}else if(n.config.wrapExternalValue&&Object.prototype.hasOwnProperty.call(e,"value"))e=e.value;else if(Object.prototype.hasOwnProperty.call(e,"symbol"))e=resolveValueSymbol(n,e);else if(Object.prototype.hasOwnProperty.call(e,"car")){const r=evaluate(n,e.car),o=evaluate(n,e.cdr);if(Array.isArray(o)){const s=o.slice(0);s.unshift(r),e=s}else e={car:r,cdr:o}}else Object.prototype.hasOwnProperty.call(e,"dotted")?e=[evaluate(n,e.dotted)]:Object.prototype.hasOwnProperty.call(e,"comment")&&(e=[]);return e}var __awaiter=function(n,t,e,r){function o(s){return s instanceof e?s:new e(function(a){a(s)})}return new(e||(e=Promise))(function(s,a){function l(c){try{m(r.next(c))}catch(u){a(u)}}function i(c){try{m(r.throw(c))}catch(u){a(u)}}function m(c){c.done?s(c.value):o(c.value).then(l,i)}m((r=r.apply(n,t||[])).next())})};function initState(n,t,e,r){return{strings:typeof e=="string"?[e]:e,values:r||[],index:0,pos:0,line:0,evalCount:0,scopes:[{isBlockLocal:!1,scope:t}],macroMap:new Map(n.macros.map(o=>[o.name,o])),funcMap:new Map(n.funcs.map(o=>[o.name,o])),symbolMap:new Map(n.symbols.map(o=>[o.name,o])),config:n}}function resetState(n,t,e){return n.strings=typeof t=="string"?[t]:t,n.values=e||[],n.index=0,n.pos=0,n.line=0,n.evalCount=0,n}function SExpression(n){let t=n||Object.assign({},defaultConfig),e={},r=[];const o=(a,l)=>{if(t.enableEvaluate)for(let i=0;i<l.length;i++)l[i]=evaluate(a,l[i]);return t.returnMultipleRoot?l.length===1?l[0]:l:l[l.length-1]},s=(a,...l)=>{const i=initState(t,Object.assign({},e),a,l);return o(i,r.concat(parse(i)))};return s.evaluateAST=a=>{const l=initState(t,Object.assign({},e),"");return o(l,r.concat(a))},s.repl=()=>{const a=initState(t,Object.assign({},e),"");o(a,r.slice(0));const l=(i,...m)=>(resetState(a,i,m),o(a,parse(a)));return l.sync=l,l},s.setGlobals=a=>(e=Object.assign({},a||{}),s),s.appendGlobals=a=>(e=Object.assign({},e,a||{}),s),s.setStartup=(a,...l)=>{const i=initState(t,Object.assign({},e),a,l);return r=parse(i),s},s.setStartupAST=a=>(r=a,s),s.appendStartup=(a,...l)=>{const i=initState(t,Object.assign({},e),a,l);return r=r.concat(parse(i)),s},s.appendStartupAST=a=>(r=r.concat(a),s),s.install=a=>(t=a(t),s),s}function SExpressionAsync(n){let t=n||Object.assign({},defaultConfig),e={},r=[];const o=(a,l)=>__awaiter(this,void 0,void 0,function*(){if(t.enableEvaluate)for(let i=0;i<l.length;i++)l[i]=evaluate(a,l[i]),typeof l[i]=="object"&&l[i]!==null&&typeof l[i].then=="function"&&(l[i]=yield l[i]);return t.returnMultipleRoot?l.length===1?l[0]:l:l[l.length-1]}),s=(a,...l)=>__awaiter(this,void 0,void 0,function*(){const i=initState(t,Object.assign({},e),a,l);return o(i,r.concat(parse(i)))});return s.evaluateAST=a=>{const l=initState(t,Object.assign({},e),"");return o(l,r.concat(a))},s.repl=()=>{const a=(c,u)=>{if(t.enableEvaluate)for(let f=0;f<u.length;f++)u[f]=evaluate(c,u[f]);return t.returnMultipleRoot?u.length===1?u[0]:u:u[u.length-1]},l=initState(t,Object.assign({},e),"");o(l,r.slice(0));const i=(c,...u)=>__awaiter(this,void 0,void 0,function*(){return resetState(l,c,u),o(l,parse(l))}),m=(c,...u)=>(resetState(l,c,u),a(l,parse(l)));return i.sync=m,i},s.setGlobals=a=>(e=Object.assign({},a||{}),s),s.appendGlobals=a=>(e=Object.assign({},e,a||{}),s),s.setStartup=(a,...l)=>{const i=initState(t,Object.assign({},e),a,l);return r=parse(i),s},s.setStartupAST=a=>(r=a,s),s.appendStartup=(a,...l)=>{const i=initState(t,Object.assign({},e),a,l);return r=r.concat(parse(i)),s},s.appendStartupAST=a=>(r=r.concat(a),s),s.install=a=>(t=a(t),s),s}const S=(()=>{const n=Object.assign({},defaultConfig);return n.enableEvaluate=!1,n.returnMultipleRoot=!0,SExpression(n)})();function applyMacros(n,t){let e=t;for(;Array.isArray(e);){{if(e.length===0)break;e=resolveSplice(n,e);const r=isSymbol(e[0]);if(r){const o=resolveMacro(n,r,e);if(o)e=o.fn(o.actualArgs);else break}else break}setEvaluationCount(n)}return e}function stripQuote(n,t){if(!(Array.isArray(t)&&isSymbol(t[0],n.config.reservedNames.quote)))throw new Error("[SX] stripQuote: token is not quoted.");return t[1]}function stripQuoteOrPass(n,t){return Array.isArray(t)&&isSymbol(t[0],n.config.reservedNames.quote)?t[1]:t}function getScope_stateApplied(n){return function(){return getScope(n)}}function resolveValueSymbol_dynamic(n,t){return checkUnsafeVarNames("(compiler)resolveValueSymbol_dynamic",t),function(){return resolveValueSymbol(n,{symbol:t})}}function checkUnsafeVarNames_dynamic(n){return function(t){return checkUnsafeVarNames(n,t)}}function registerOperators(n,t){const{_$_vars:e,ops:r,makeScope:o,compileToken:s}=t;r.set(n.config.reservedNames.quote,function(a,l){let i="";return e[t.varsCount]=a[1],i+=`(_$_vars[${String(t.varsCount++)}])`,i}),r.set(n.config.reservedNames.self,function(a,l){let i="";return i+=`((_$_vars[0])(${l.map(m=>s([stripQuoteOrPass(n,m)],0)).join(",")}))`,i}),r.set("$__if",function(a,l){let i="";return checkParamsLength("compileToken:$__if",l,2,3),i+=`(${s(a,1)}?(${s([stripQuote(n,a[2])],0)}):(${s([stripQuote(n,a[3])],0)}))`,i}),r.set("$__if-null",function(a,l){let i="";return checkParamsLength("compileToken:$__if-null",l,2,2),i+=`((()=>{let _$_rv=${s(a,1)};return _$_rv?_$_rv:(${s([stripQuote(n,a[2])],0)}});})())`,i}),r.set("$__cond",function(a,l){let i="";{checkParamsLength("compileToken:$__cond",l,1),i+="(";for(let m=0;m<l.length;m+=2)i+=`${s([stripQuote(n,l[m])],0)}?(${s([stripQuote(n,l[m+1])],0)}):(`;i+="null";for(let m=0;m<l.length;m+=2)i+=")";i+=")"}return i}),r.set("$__while",function(a,l){let i="";return checkParamsLength("compileToken:$__while",l,1),i+=`((()=>{let _$_rv=null;while(${s([stripQuote(n,a[1])],0)}){_$_rv=${a.slice(2).map(m=>s([stripQuote(n,m)],0)).join(",")}}return _$_rv})())`,i}),r.set("$__do-while",function(a,l){let i="";return checkParamsLength("compileToken:$__do-until",l,1),i+=`((()=>{let _$_rv=null;do{_$_rv=${a.slice(2).map(m=>s([stripQuote(n,m)],0)).join(",")}}}while(${s([stripQuote(n,a[1])],0)})return _$_rv)())`,i}),r.set("$__until",function(a,l){let i="";return checkParamsLength("compileToken:$__until",l,1),i+=`((()=>{let _$_rv=null;while(!${s([stripQuote(n,a[1])],0)}){_$_rv=${a.slice(2).map(m=>s([stripQuote(n,m)],0)).join(",")}}return _$_rv})())`,i}),r.set("$__do-until",function(a,l){let i="";return checkParamsLength("compileToken:$__do-until",l,1),i+=`((()=>{let _$_rv=null;do{_$_rv=${a.slice(2).map(m=>s([stripQuote(n,m)],0)).join(",")}}}while(!${s([stripQuote(n,a[1])],0)})return _$_rv)())`,i}),r.set("$__repeat",function(a,l){let i="";if(checkParamsLength("compileToken:$__repeat",l,2),!isSymbol(l[0]))throw new Error("[SX] compileToken: $__repeat : args[0] is not symbol.");return o(()=>{const m="v"+t.varNamesCount++;t.varNames.set(l[0].symbol,m),i+=`(((_$_n)=>{let _$_rv=null;for(let ${m}=0;${m}<_$_n;${m}++){_$_rv=${a.slice(2).map(c=>s([stripQuote(n,c)],0)).join(",")}}return _$_rv})(${s(l,1)}))`}),i}),r.set("$__for",function(a,l){let i="";if(checkParamsLength("compileToken:$__for",l,2),!isSymbol(l[0]))throw new Error("[SX] compileToken: $__for : args[0] is not symbol.");return o(()=>{const m="v"+t.varNamesCount++;t.varNames.set(l[0].symbol,m),i+=`(((_$_l)=>{let _$_rv=null;for(const ${m} of _$_l){_$_rv=${a.slice(2).map(c=>s([stripQuote(n,c)],0)).join(",")}}return _$_rv})(${s(l,1)}))`}),i}),r.set("$__scope",function(a,l){let i="";if(checkParamsLength("compileToken:$__scope",l,2),!Array.isArray(a[3]))throw new Error("[SX] compileToken: $__scope : args[2] is not array.");return o(()=>{for(const c of stripQuote(n,a[3])){let u="";if(Array.isArray(c)){if(c.length<1)throw new Error("[SX] compileToken: $__scope : args[0][?] is too short.");if(!isSymbol(c[0]))throw new Error("[SX] compileToken: $__scope : args[0][?][0] is not symbol.");u=c[0].symbol,i+=`(${"v"+t.varNamesCount}=${s(c,1)})`}else{if(!isSymbol(c))throw new Error("[SX] compileToken: $__scope : args[0][?] is not symbol.");u=c.symbol}t.varDefs+=`var v${t.varNamesCount}=void 0;`,t.varNames.set(u,"v"+t.varNamesCount++)}const m=`${a.slice(4).map(c=>s([stripQuote(n,c)],0)).join(",")}`;i+=a[2]?`[${m}]`:`(${m})`}),i}),r.set("$__try",function(a,l){let i="";return checkParamsLength("compileToken:$__try",l,1,2),i+=`((()=>{try{${s([stripQuote(n,a[1])],0)}}catch(e${t.varNamesCount}){let e${t.varNamesCount+1}=(_$_vars[${String(t.varsCount)}])();`,e[t.varsCount++]=getScope_stateApplied(n),o(()=>{t.varNames.set("$error","e"+t.varNamesCount++),t.varNames.set("$parent","e"+t.varNamesCount++),i+=`${s([stripQuote(n,a[2])],0)}}})())`}),i}),r.set(n.config.reservedNames.raise,function(a,l){let i="";return i+=`((()=>{throw ${s([stripQuoteOrPass(n,a[1])],0)}})())`,i}),r.set("$boolean",function(a,l){let i="";return checkParamsLength("compileToken:$boolean",l,1,1),i+=`((x0=${s(l,0)}),(Array.isArray(x0)&&x0.length===0?false:boolean(x0)))`,i}),r.set("$__get",function(a,l){let i="";checkParamsLength("compileToken:$__get",l,1);const m=stripQuote(n,a[1]),c=isSymbol(m)?m.symbol:typeof m=="string"?m:null;if(typeof c!="string")throw new Error(`[SX] compileToken: $__get : operand is not symbol: ${JSON.stringify(a[1])}.`);let u="";t.varNames.has(c)?u=t.varNames.get(c):(e[t.varsCount]=resolveValueSymbol_dynamic(n,c),u=`_$_vars[${String(t.varsCount++)}]`);const f=$=>(e[t.varsCount]=$,`_$_vars[${String(t.varsCount++)}]`);return i+=`((${u})${a.slice(2).map(($,p,h)=>`[${isSymbol(h[p])?f(h[p].symbol):s(h,p)}]`).join("")})`,i}),r.set("$__let",function(a,l){let i="";checkParamsLength("compileToken:$__let",l,2,2);const m=stripQuote(n,a[1]),c=isSymbol(m)?m.symbol:typeof m=="string"?m:null;if(typeof c!="string")throw new Error(`[SX] compileToken: $__let : operand is not rvalue: ${JSON.stringify(a[1])}.`);return t.varNames.has(c)||(t.varDefs+=`var v${t.varNamesCount}=void 0;`,t.varNames.set(c,"v"+t.varNamesCount++)),i+=`(${t.varNames.get(c)}=${s(a,2)})`,i}),r.set("$__set",function(a,l){let i="";checkParamsLength("compileToken:$__set",l,2);const m=stripQuote(n,a[1]),c=isSymbol(m)?m.symbol:typeof m=="string"?m:Array.isArray(m)?isSymbol(m[0])?m[0].symbol:typeof m[0]=="string"?m[0]:null:null;if(typeof c!="string")throw new Error(`[SX] compileToken: $__set : operand is not rvalue: ${JSON.stringify(a[1])}.`);let u="";t.varNames.has(c)?u=t.varNames.get(c):(e[t.varsCount]=resolveValueSymbol_dynamic(n,c),u=`_$_vars[${String(t.varsCount++)}]`);const f=b=>(e[t.varsCount]=checkUnsafeVarNames("compileToken:$__set",b),`_$_vars[${String(t.varsCount++)}]`);let $=!1,p="";const h=b=>($||(e[t.varsCount]=checkUnsafeVarNames_dynamic("compileToken:$__set"),p=String(t.varsCount++),$=!0),`(_$_vars[${p}](${b}))`);return i+=`((${u})${(Array.isArray(m)?m.slice(1):[]).map((b,d,y)=>`[${isSymbol(y[d])?f(y[d].symbol):h(s(y,d))}]`).join("")}=${s(a,2)})`,i}),r.set(n.config.reservedNames.not,function(a,l){let i="";return checkParamsLength("compileToken:$not",l,1,1),i+=`(!${s(l,0)})`,i}),r.set("$__and",function(a,l){let i="";return checkParamsLength("compileToken:$__and",l,1),i+=`(${l.map(m=>s([stripQuote(n,m)],0)).join("&&")})`,i}),r.set("$__or",function(a,l){let i="";return checkParamsLength("compileToken:$__or",l,1),i+=`(${l.map(m=>s([stripQuote(n,m)],0)).join("||")})`,i}),r.set("===",function(a,l){let i="";return checkParamsLength("compileToken:===",l,2,2),i+=`(${l.map((m,c,u)=>s(u,c)).join("===")})`,i}),r.set("!==",function(a,l){let i="";return checkParamsLength("compileToken:!==",l,2,2),i+=`(${l.map((m,c,u)=>s(u,c)).join("!==")})`,i}),r.set("==",function(a,l){let i="";return checkParamsLength("compileToken:==",l,2,2),i+=`(${l.map((m,c,u)=>s(u,c)).join("==")})`,i}),r.set("!=",function(a,l){let i="";return checkParamsLength("compileToken:!=",l,2,2),i+=`(${l.map((m,c,u)=>s(u,c)).join("!=")})`,i}),r.set("<",function(a,l){let i="";return checkParamsLength("compileToken:<",l,2,2),i+=`(${l.map((m,c,u)=>s(u,c)).join("<")})`,i}),r.set("<=",function(a,l){let i="";return checkParamsLength("compileToken:<=",l,2,2),i+=`(${l.map((m,c,u)=>s(u,c)).join("<=")})`,i}),r.set(">",function(a,l){let i="";return checkParamsLength("compileToken:>",l,2,2),i+=`(${l.map((m,c,u)=>s(u,c)).join(">")})`,i}),r.set(">=",function(a,l){let i="";return checkParamsLength("compileToken:<=",l,2,2),i+=`(${l.map((m,c,u)=>s(u,c)).join(">=")})`,i}),r.set("$concat",function(a,l){let i="";checkParamsLength("compileToken:$concat",l,1);let m="";if(Array.isArray(l[0])&&isSymbol(l[0][0],n.config.reservedNames.spread)){const c=s(l[0],1);m=`(${c}[0]).concat((${c}.length>1?${c}[1]:(typeof ${c}[0]==='string'?'':[])),`}else m=`${s(l,0)}.concat(`;return i+=`(${m}${l.slice(1).map((c,u,f)=>s(f,u)).join(",")}))`,i}),r.set("+",function(a,l){let i="";checkParamsLength("compileToken:+",l,1);let m=!1;return l.map((c,u,f)=>{Array.isArray(c)&&isSymbol(c[0],n.config.reservedNames.spread)&&(m=!0)}),m?i+=`((()=>{let _$_rv=[];${l.map((c,u,f)=>`_$_rv.push(${s(f,u)})`).join(";")};return _$_rv.reduce((x,y)=>x+y);})())`:i+=`(${l.map((c,u,f)=>s(f,u)).join("+")})`,i}),r.set("-",function(a,l){let i="";checkParamsLength("compileToken:-",l,1);let m=!1;return l.map((c,u,f)=>{Array.isArray(c)&&isSymbol(c[0],n.config.reservedNames.spread)&&(m=!0)}),m?i+=`((()=>{let _$_rv=[];${l.map((c,u,f)=>`_$_rv.push(${s(f,u)})`).join(";")};return (_$_rv.length>1?(_$_rv.reduce((x,y)=>x-y)):(_$_rv.length>0?-_$_rv[0]:NaN));})())`:i+=`(${a.length>2?l.map((c,u,f)=>s(f,u)).join("-"):`-(${String(s(a,1))})`})`,i}),r.set("*",function(a,l){let i="";checkParamsLength("compileToken:*",l,2);let m=!1;return l.map((c,u,f)=>{Array.isArray(c)&&isSymbol(c[0],n.config.reservedNames.spread)&&(m=!0)}),m?i+=`((()=>{let _$_rv=[];${l.map((c,u,f)=>`_$_rv.push(${s(f,u)})`).join(";")};return _$_rv.reduce((x,y)=>x*y);})())`:i+=`(${l.map((c,u,f)=>s(f,u)).join("*")})`,i}),r.set("**",function(a,l){let i="";checkParamsLength("compileToken:**",l,2);let m=!1;return l.map((c,u,f)=>{Array.isArray(c)&&isSymbol(c[0],n.config.reservedNames.spread)&&(m=!0)}),m?i+=`((()=>{let _$_rv=[];${l.map((c,u,f)=>`_$_rv.push(${s(f,u)})`).join(";")};return _$_rv.reduce((x,y)=>x**y);})())`:i+=`(${l.map((c,u,f)=>s(f,u)).join("**")})`,i}),r.set("/",function(a,l){let i="";checkParamsLength("compileToken:/",l,2);let m=!1;return l.map((c,u,f)=>{Array.isArray(c)&&isSymbol(c[0],n.config.reservedNames.spread)&&(m=!0)}),m?i+=`((()=>{let _$_rv=[];${l.map((c,u,f)=>`_$_rv.push(${s(f,u)})`).join(";")};return _$_rv.reduce((x,y)=>x/y);})())`:i+=`(${l.map((c,u,f)=>s(f,u)).join("/")})`,i}),r.set("%",function(a,l){let i="";checkParamsLength("compileToken:%",l,2);let m=!1;return l.map((c,u,f)=>{Array.isArray(c)&&isSymbol(c[0],n.config.reservedNames.spread)&&(m=!0)}),m?i+=`((()=>{let _$_rv=[];${l.map((c,u,f)=>`_$_rv.push(${s(f,u)})`).join(";")};return _$_rv.reduce((x,y)=>x%y);})())`:i+=`(${l.map((c,u,f)=>s(f,u)).join("%")})`,i}),r.set("<<",function(a,l){let i="";return checkParamsLength("compileToken:<<",l,2,2),i+=`(${l.map((m,c,u)=>s(u,c)).join("<<")})`,i}),r.set(">>",function(a,l){let i="";return checkParamsLength("compileToken:>>",l,2,2),i+=`(${l.map((m,c,u)=>s(u,c)).join(">>")})`,i}),r.set(">>>",function(a,l){let i="";return checkParamsLength("compileToken:>>>",l,2,2),i+=`(${l.map((m,c,u)=>s(u,c)).join(">>>")})`,i}),r.set("$bit-not",function(a,l){let i="";return checkParamsLength("compileToken:$bit-not",l,1,1),i+=`(~(${s(a,1)}))`,i}),r.set("$bit-and",function(a,l){let i="";return checkParamsLength("compileToken:$bit-and",l,2,2),i+=`(${l.map((m,c,u)=>s(u,c)).join("&")})`,i}),r.set("$bit-or",function(a,l){let i="";return checkParamsLength("compileToken:$bit-or",l,2,2),i+=`(${l.map((m,c,u)=>s(u,c)).join("|")})`,i}),r.set("$bit-xor",function(a,l){let i="";return checkParamsLength("compileToken:$bit-xor",l,2,2),i+=`(${l.map((m,c,u)=>s(u,c)).join("^")})`,i})}function compileCore(n,t,e,r,o){function s($){const p=new Map;for(const h of i.varNames.entries())p.set(h[0],h[1]);$(),i.varNames=p}function a($){let p="";if($===null)p+="(null)";else if($===void 0)p+="(void 0)";else switch(typeof $){case"boolean":case"number":p+=`(${String($)})`;break;case"object":if(isSymbol($)){const h=$;checkUnsafeVarNamesEx("(compiler)compileValue",i.varNames,h.symbol),i.varNames.has(h.symbol)?p+=`(${i.varNames.get(h.symbol)})`:(o[i.varsCount]=h.symbol,p+=`(_$_vars[${String(i.varsCount++)}])`);break}default:o[i.varsCount]=$,p+=`(_$_vars[${String(i.varsCount++)}])`;break}return p}function l($,p){let h="";const b=$[p];if(Array.isArray(b))if(0<b.length){const d=applyMacros(n,b);if(Array.isArray(d))if(0<d.length)if(isSymbol(d[0])){const y=d[0],g=d.slice(1);checkUnsafeVarNamesEx("(compiler)compileToken",m,y.symbol),m.has(y.symbol)?h+=m.get(y.symbol)(d,g):y.symbol===n.config.reservedNames.spread?h+=`...(${g.map(_=>l([stripQuoteOrPass(n,_)],0)).join(",")})`:n.funcMap.has(y.symbol)?(o[i.varsCount]=n.funcMap.get(y.symbol).fn(n,""),h+=`((_$_vars[${String(i.varsCount++)}])(${g.map(_=>l([stripQuoteOrPass(n,_)],0)).join(",")}))`):i.varNames.has(y.symbol)?h+=`(${String(i.varNames.get(y.symbol))})(${g.map(_=>l([stripQuoteOrPass(n,_)],0)).join(",")})`:(o[i.varsCount]=resolveValueSymbol_dynamic(n,y.symbol),h+=`((_$_vars[${String(i.varsCount++)}])()(${g.map(_=>l([stripQuoteOrPass(n,_)],0)).join(",")}))`)}else switch(typeof d[0]){case"function":o[i.varsCount]=d[0],h+=`((_$_vars[${String(i.varsCount++)}])(${d.slice(1).map((y,g,_)=>l([stripQuoteOrPass(n,y)],0)).join(",")}))`;break;default:throw new Error(`[SX] compileToken: First item of list is not a function: ${JSON.stringify(d[0])}.`)}else h+="([])";else h+=a(b)}else h+="([])";else h+=a(b);return h}const i={_$_vars:o,varsCount:1,varNames:new Map,varNamesCount:0,varDefs:"var x0;",ops:new Map,makeScope:s,compileToken:l};registerOperators(n,i);const m=i.ops;n.config.enableTailCallOptimization&&(r=optimizeTailCall(n,t,r)),i.varNames.set(n.config.reservedNames.thiz,"(this===(Function('return this')())?null:(this===void 0?null:this))");const c=getCapturedScopes(n);if(c)for(const $ in c)Object.prototype.hasOwnProperty.call(c,$)&&(o[i.varsCount++]=$,o[i.varsCount]=c[$],i.varNames.set($,`(_$_vars[${String(i.varsCount)}][_$_vars[${String(i.varsCount-1)}]])`),i.varsCount++);const u=`${t.map(($,p)=>(i.varNames.set(t[p].symbol,"a"+p),`${e&&p===t.length-1?"...":""}a${p}`)).join(",")}`,f=`return(${r.map(($,p)=>l(r,p)).join(",")})`;return`(function(${u}){"strict";${i.varDefs}${f}})`}function evalCompiledLambda(_$_state,_$_vars,code){return _$_vars[0]=eval(code),_$_vars[0]}function compileLambda(n,t,e,r){const o=[];return evalCompiledLambda(n,o,compileCore(n,t,e,r,o))}const $car=(n,t)=>(...e)=>{checkParamsLength("$car",e,1,1);const r=$$first(...e);if(!Array.isArray(r))throw new Error("[SX] $car: Invalid argument(s): args[0] is not array.");if(r.length===0)throw new Error("[SX] $car: Invalid argument(s): args[0] is nil.");return r[0]},$cdr=(n,t)=>(...e)=>{checkParamsLength("$cdr",e,1,1);const r=$$first(...e);if(!Array.isArray(r))throw new Error("[SX] $cdr: Invalid argument(s): args[0] is not array.");if(r.length===0)throw new Error("[SX] $cdr: Invalid argument(s): args[0] is nil.");return r.slice(1)},$cons=(n,t)=>(...e)=>{checkParamsLength("$cons",e,2,2);let{car:r,cdr:o}=$$firstAndSecond(...e);return r===null&&(r=[]),o===null&&(o=[]),Array.isArray(o)?(o=o.slice(0),o.unshift(r),o):{car:r,cdr:o}},$first=(n,t)=>(...e)=>{const r=e.slice(0,1);return r.length===1?r[0]:null},$$first=$first(),$second=(n,t)=>(...e)=>{const r=e.slice(1,2);return r.length===1?r[0]:null},$$second=$second(),$last=(n,t)=>(...e)=>{const r=e.slice(e.length-1,e.length);return r.length===1?r[0]:null},$rest=(n,t)=>(...e)=>{const r=e.slice(1);return 0<r.length?r:null},$firstAndSecond=(n,t)=>(...e)=>{let r=e.slice(0,1);r=r.length===1?r[0]:null;let o=e.slice(1,2);return o=o.length===1?o[0]:null,{car:r,cdr:o}},$$firstAndSecond=$firstAndSecond(),$atom=(n,t)=>(...e)=>{checkParamsLength("$atom",e,1,1);const r=$$first(...e);if(r==null)return!0;if(Array.isArray(r))return r.length===0;switch(typeof r){case"number":case"string":case"function":case"boolean":return!0;case"object":return!!isSymbol(r)}return!1},$eq=(n,t)=>(...e)=>{checkParamsLength("$eq",e,2,2);const{car:r,cdr:o}=$$firstAndSecond(...e);return r===o},$notEq=(n,t)=>(...e)=>{checkParamsLength("$notEq",e,2,2);const{car:r,cdr:o}=$$firstAndSecond(...e);return r!==o},$list=(n,t)=>(...e)=>e.slice(0),$__scope=(n,t,e)=>(...r)=>{checkParamsLength("$__scope",r,3);const o=$$first(...r),s=$$second(...r),{car:a,cdr:l}=$$firstAndSecond(...r.slice(2));let i=null;const m={};if(Array.isArray(a))for(const c of a)if(Array.isArray(c)){const u=$$firstAndSecond(...c),f=isSymbol(u.car),$=f?f.symbol:String(u.car);checkUnsafeVarNamesEx("$__scope",m,$),m[$]=evaluate(n,u.cdr)}else{const u=isSymbol(c),f=u?u.symbol:String(c);checkUnsafeVarNamesEx("$__scope",m,f),m[f]=null}installScope(n,m,o,e);try{if(4<r.length)if(s){i=[];for(const c of r.slice(3))i.push(evaluate(n,c))}else for(const c of r.slice(3))i=evaluate(n,c);else i=evaluate(n,l)}finally{uninstallScope(n)}return i},$__globalScope=(n,t)=>(...e)=>{checkParamsLength("$__globalScope",e,1);const r=$$first(...e),o=$$second(...e);let s=null;installScope(n,getGlobalScope(n).scope,!0);try{if(2<e.length)if(r){s=[];for(const a of e.slice(1))s.push(evaluate(n,a))}else for(const a of e.slice(1))s=evaluate(n,a);else s=evaluate(n,o)}finally{uninstallScope(n)}return s},$__capture=(n,t)=>(...e)=>{checkParamsLength("$__capture",e,1);const r=e[0];if(!Array.isArray(r))throw new Error("[SX] $__lambda: Invalid argument(s): args[0] is not array.");let o=null;const s=collectCapturedVariables(n,r);installScope(n,{},!0,s);try{for(const a of e.slice(1))o=evaluate(n,a)}finally{uninstallScope(n)}return o},$__lambda=(n,t)=>(...e)=>{checkParamsLength("$__lambda",e,2);const r=e[0];if(!Array.isArray(r))throw new Error("[SX] $__lambda: Invalid argument(s): args[0] is not array.");let o=!1;for(let i=0;i<r.length;i++){const m=r[i];if(i===r.length-1&&n.config.enableSpread&&Array.isArray(m)&&isSymbol(m[0],n.config.reservedNames.spread)){if(!isSymbol(m[1]))throw new Error(`[SX] $__lambda: Invalid formal argument(s): item(s) of args[${i}] is not symbol.`);r[i]=m[1],o=!0}else if(!isSymbol(m))throw new Error(`[SX] $__lambda: Invalid formal argument(s): item(s) of args[${i}] is not symbol.`)}let s=e.slice(1);n.config.enableTailCallOptimization&&(s=optimizeTailCall(n,r,s));const a=getCapturedScopes(n),l=function(...i){if(i.length+(o?1:0)<r.length)throw new Error(`[SX] func call: Actual args too short: actual ${i.length} / formal ${r.length}.`);return $__scope(n,t,a)(!1,!1,[[n.config.reservedNames.self,l],[n.config.reservedNames.thiz,this===globalObj||this===void 0?null:quote(n,this)],...r.map((m,c)=>[m.symbol,quote(n,o&&c===r.length-1?i.slice(c):i[c])])],...s)};return l},$comp$__lambda=(n,t)=>(...e)=>{checkParamsLength("$$__lambda",e,2);const r=e[0];if(!Array.isArray(r))throw new Error("[SX] $$__lambda: Invalid argument(s): args[0] is not array.");let o=!1;for(let a=0;a<r.length;a++){const l=r[a];if(a===r.length-1&&n.config.enableSpread&&Array.isArray(l)&&isSymbol(l[0],n.config.reservedNames.spread)){if(!isSymbol(l[1]))throw new Error(`[SX] $$__lambda: Invalid formal argument(s): item(s) of args[${a}] is not symbol.`);r[a]=l[1],o=!0}else if(!isSymbol(l))throw new Error(`[SX] $$__lambda: Invalid formal argument(s): item(s) of args[${a}] is not symbol.`)}const s=e.slice(1);return compileLambda(n,r,o,s)},$__defun=(n,t)=>(...e)=>{checkParamsLength("$__defun",e,3);const r=$$first(...e),o=$__lambda(n,t)(...e.slice(1));return checkUnsafeVarNamesEx("$__defun",n.funcMap,r.symbol),n.funcMap.set(r.symbol,{name:r.symbol,fn:(s,a)=>o}),o},$comp$__defun=(n,t)=>(...e)=>{checkParamsLength("$$__defun",e,3);const r=$$first(...e),o=$comp$__lambda(n)(...e.slice(1));return checkUnsafeVarNamesEx("$$__defun",n.funcMap,r.symbol),n.funcMap.set(r.symbol,{name:r.symbol,fn:(s,a)=>o}),o},$__refun=(n,t)=>(...e)=>{checkParamsLength("$__refun",e,1,1);const r=$$first(...e);checkUnsafeVarNamesEx("$__refun",n.funcMap,r.symbol);const o=n.funcMap.get(r.symbol);if(!o)throw new Error(`[SX] $__refun: function ${r.symbol} is not defined.`);return o.fn(n,r.symbol)},$__defmacro=(n,t)=>(...e)=>{checkParamsLength("$__defmacro",e,3);const r=$$first(...e),o=e[1];if(!Array.isArray(o))throw new Error("[SX] $__defmacro: Invalid argument(s): args[1] is not array.");let s=!1;for(let c=0;c<o.length;c++){const u=o[c];if(c===o.length-1&&n.config.enableSpread&&Array.isArray(u)&&isSymbol(u[0],n.config.reservedNames.spread)){if(!isSymbol(u[1]))throw new Error(`[SX] $__defmacro: Invalid formal argument(s): item(s) of args[${c}] is not symbol.`);o[c]=u[1],s=!0}else if(!isSymbol(u))throw new Error(`[SX] $__defmacro: Invalid formal argument(s): item(s) of args[${c}] is not symbol.`)}const a=e.slice(2),l=getCapturedScopes(n),i=c=>(...u)=>$__scope(n,t,l)(!1,!1,[[n.config.reservedNames.self,i],...c.map((f,$)=>[f.symbol,quote(n,s&&$===c.length-1?u.slice($):u[$])])],...a),m={name:r.symbol,fn:(c,u,f)=>$=>i(f)(...$.slice(1)),formalArgs:o,lastIsSpread:s};if(checkUnsafeVarNamesEx("$__defmacro",n.macroMap,r.symbol),n.macroMap.has(r.symbol)){let c=n.macroMap.get(r.symbol);if(c.next=m,c&&c.formalArgs)if(c.formalArgs.length<o.length)n.macroMap.set(r.symbol,m),m.next=c;else{let u=c;for(c=c.next;c;){if(c.formalArgs&&c.formalArgs.length<o.length){u.next=m,m.next=c;break}u=c,c=c.next}}}else n.macroMap.set(r.symbol,m);return i},$apply=(n,t)=>(...e)=>{checkParamsLength("$apply",e,1);const r=$$first(...e);if(typeof r!="function")throw new Error("[SX] $apply: Invalid argument(s): args[0] is not function.");return(...o)=>r.apply(null,e.slice(1).concat(o))},$__call=(n,t)=>(...e)=>{checkParamsLength("$__call",e,2);const{car:r,cdr:o}=$$firstAndSecond(...e),s=isSymbol(o),a=s?s.symbol:evaluate(n,o);return checkUnsafeVarNamesEx("$__call",r,a),Function.prototype.apply.call(r[a],r,e.slice(2))},$__try=(n,t)=>(...e)=>{checkParamsLength("$__try",e,1,2);let r=[];try{r=evaluate(n,e[0])}catch(o){if(o instanceof FatalError)throw o;1<e.length?r=$__scope(n)(!0,!1,[["$error",quote(n,o)],["$parent",quote(n,getScope(n))]],e[1]):r=null}return r},$raise=(n,t)=>(...e)=>{throw $$first(...e)},$__if=(n,t)=>(...e)=>{checkParamsLength("$__if",e,2,3);const r=$$first(...e);let o=[];return $$boolean(r)?o=evaluate(n,e[1]):2<e.length?o=evaluate(n,e[2]):o=null,o},$__ifNull=(n,t)=>(...e)=>{checkParamsLength("$__ifNull",e,2,2);const{car:r,cdr:o}=$$firstAndSecond(...e);let s=[];return $$ambiguousEq(r,null)?s=evaluate(n,o):s=r,s},$__cond=(n,t)=>(...e)=>{checkParamsLength("$__cond",e,1);for(let r=0;r<e.length-1;r+=2){const o=e[r],s=e[r+1];if($$boolean(evaluate(n,o)))return evaluate(n,s)}return null},$__while=(n,t)=>(...e)=>{checkParamsLength("$__while",e,1);const r=$$first(...e),o=e.slice(1);let s=null;for(;$$boolean(evaluate(n,r));)for(const a of o)s=evaluate(n,a);return s},$__doWhile=(n,t)=>(...e)=>{checkParamsLength("$__doWhile",e,1);const r=$$first(...e),o=e.slice(1);let s=null;do for(const a of o)s=evaluate(n,a);while($$boolean(evaluate(n,r)));return s},$__until=(n,t)=>(...e)=>{checkParamsLength("$__until",e,1);const r=$$first(...e),o=e.slice(1);let s=null;for(;$$not(evaluate(n,r));)for(const a of o)s=evaluate(n,a);return s},$__doUntil=(n,t)=>(...e)=>{checkParamsLength("$__doUntil",e,1);const r=$$first(...e),o=e.slice(1);let s=null;do for(const a of o)s=evaluate(n,a);while($$not(evaluate(n,r)));return s},$__repeat=(n,t)=>(...e)=>{checkParamsLength("$__repeat",e,2);const r=isSymbol($$first(...e));if(!r)throw new Error("[SX] $__repeat: Invalid argument(s): item(s) of args[0] is not symbol.");checkUnsafeVarNamesEx("$__repeat",{},r.symbol);const o=resolveValueSymbolScope(n,r,!1),s=toNumber($$second(...e)),a=e.slice(2);let l=null;for(let i=0;i<s;i++){o[r.symbol]=i;for(const m of a)l=evaluate(n,m)}return l},$__for=(n,t)=>(...e)=>{checkParamsLength("$__for",e,2);const r=isSymbol($$first(...e));if(!r)throw new Error("[SX] $__for: Invalid argument(s): item(s) of args[0] is not symbol.");checkUnsafeVarNamesEx("$__for",{},r.symbol);const o=resolveValueSymbolScope(n,r,!1),s=$$second(...e);if(!Array.isArray(s))throw new Error("[SX] $__for: Invalid argument(s): item(s) of args[1] is not array.");const a=e.slice(2);let l=null;for(const i of s){o[r.symbol]=i;for(const m of a)l=evaluate(n,m)}return l},$pipe=(n,t)=>(...e)=>{checkParamsLength("$pipe",e,1);let r=e[0];for(let o=1;o<e.length;o++)r=e[o](r);return r},$__get=(n,t)=>(...e)=>{checkParamsLength("$__get",e,1);let r=null,o=isSymbol(e[0]);if(!o)switch(typeof e[0]){case"string":case"number":o={symbol:String(e[0])};break;default:r=evaluate(n,e[0]);break}if(o){const s=resolveValueSymbolScope(n,o,!0);if(!s)throw new Error(`[SX] $__get: Invalid argument(s): args[0]: symbol "${o.symbol}" is not defined.`);r=s[o.symbol]}for(let s=1;s<e.length;s++){let a=e[s],l=!0;for(;l;)switch(typeof a){case"function":r=a(r),l=!1;break;case"object":if(Array.isArray(a))a=evaluate(n,a);else if(o=isSymbol(a),o)a=o.symbol;else if(Object.prototype.hasOwnProperty.call(a,"value"))a=evaluate(n,a);else throw new Error("[SX] $__get: Invalid argument(s): invalid name path.");break;case"number":a<0&&(a=r.length+a);case"string":checkUnsafeVarNamesEx("$__get",r,a),r=r[a],l=!1;break;default:throw new Error("[SX] $__get: Invalid argument(s): invalid name path.")}}return r},$__let=(n,t)=>(...e)=>{checkParamsLength("$__let",e,2,2);let r=isSymbol($$first(...e));if(!r)if(typeof e[0]=="string")r={symbol:e[0]};else throw new Error("[SX] $__let: Invalid argument(s): invalid name.");checkUnsafeVarNamesEx("$__let",{},r.symbol);const o=resolveValueSymbolScope(n,r,!1);return o[r.symbol]=e[1],e[1]},$__set=(n,t)=>(...e)=>{checkParamsLength("$__set",e,2,2);let r=[];Array.isArray(e[0])?r=e[0]:r.push(e[0]);let o=isSymbol(r[0]);if(!o)if(typeof r[0]=="string")checkUnsafeVarNamesEx("$__set",{},r[0]),o={symbol:r[0]};else throw new Error("[SX] $__set: Invalid argument(s): invalid name.");let s=resolveValueSymbolScope(n,o,!0);if(s===null)throw new Error(`[SX] $__set: Unresolved symbol: ${o.symbol}.`);let a=!1;for(let l=0;l<r.length;l++){let i=r[l],m=!0;const c=l===r.length-1;for(;m;)switch(typeof i){case"function":s=i(s),m=!1;break;case"object":if(Array.isArray(i))i=evaluate(n,i);else if(o=isSymbol(i),o)i=o.symbol;else if(Object.prototype.hasOwnProperty.call(i,"value"))i=evaluate(n,i);else throw new Error("[SX] $__set: Invalid argument(s): invalid name.");break;case"number":i<0&&(i=s.length+i);case"string":checkUnsafeVarNamesEx("$__set",s,i),c?(s[i]=e[1],a=!0):s=s[i],m=!1;break;default:throw new Error("[SX] $__set: Invalid argument(s): invalid name.")}}if(!a)throw new Error("[SX] $__set: Invalid argument(s): last path is not lvalue.");return e[1]},$boolean=(n,t)=>(...e)=>{checkParamsLength("$boolean",e,1,1);const r=$$first(...e);return Array.isArray(r)&&r.length===0?!1:!!r},$$boolean=$boolean(),$not=(n,t)=>(...e)=>(checkParamsLength("$not",e,1,1),!$$boolean(...e)),$$not=$not(),$__and=(n,t)=>(...e)=>{checkParamsLength("$__and",e,1);let r=null;for(let o=0;o<e.length;o++){const s=evaluate(n,e[o]);if(!$$boolean(s))return s;r=s}return r},$__or=(n,t)=>(...e)=>{checkParamsLength("$__or",e,1);let r=null;for(let o=0;o<e.length;o++){const s=evaluate(n,e[o]);if($$boolean(s))return s;r=s}return r},$ambiguousEq=(n,t)=>(...e)=>{checkParamsLength("$ambiguousEq",e,2,2);let{car:r,cdr:o}=$$firstAndSecond(...e);return Array.isArray(r)&&r.length===0&&(r=null),Array.isArray(o)&&o.length===0&&(o=null),r===void 0&&(r=null),o===void 0&&(o=null),r==o},$$ambiguousEq=$ambiguousEq(),$ambiguousNotEq=(n,t)=>(...e)=>!$$ambiguousEq(...e),$lt=(n,t)=>(...e)=>{checkParamsLength("$lt",e,2,2);const{car:r,cdr:o}=$$firstAndSecond(...e);return toNumber(r)<toNumber(o)},$le=(n,t)=>(...e)=>{checkParamsLength("$le",e,2,2);const{car:r,cdr:o}=$$firstAndSecond(...e);return toNumber(r)<=toNumber(o)},$gt=(n,t)=>(...e)=>{checkParamsLength("$gt",e,2,2);const{car:r,cdr:o}=$$firstAndSecond(...e);return toNumber(r)>toNumber(o)},$ge=(n,t)=>(...e)=>{checkParamsLength("$ge",e,2,2);const{car:r,cdr:o}=$$firstAndSecond(...e);return toNumber(r)>=toNumber(o)},$typeof=(n,t)=>(...e)=>{checkParamsLength("$typeof",e,1,1);const r=$$first(...e);if(r===null)return"null";const o=typeof r;switch(o){case"object":return Array.isArray(r)?"list":"object";case"symbol":return"js-symbol";default:return o}},$symbol=(n,t)=>(...e)=>{if(checkParamsLength("$symbol",e,1,1),typeof e[0]=="string")return{symbol:e[0]};throw new Error("[SX] $symbol: Invalid argument(s): item(s) of args[0] is not string.")},$__gensym=(n,t)=>(...e)=>{checkParamsLength("$__gensym",e,0,1);const o={symbol:`${`$__tempvar__$$ec${n.evalCount++}$$_`}_$gensym`};if(e.length===1){const s=isSymbol(e[0]);if(s)$__let(n)(s,o);else if(typeof e[0]=="string")$__let(n)({symbol:e[0]},o);else throw new Error("[SX] $__gensym: Invalid argument(s): item(s) of args[0] is not symbol.")}return o},$isSymbol=(n,t)=>(...e)=>{if(checkParamsLength("$isSymbol",e,1,2),e.length===1)return!!isSymbol(e[0]);if(typeof e[1]=="string")return!!isSymbol(e[0],e[1]);throw new Error("[SX] $isSymbol: Invalid argument(s): item(s) of args[1] is not string.")},$isNull=(n,t)=>(...e)=>(checkParamsLength("$isNull",e,1,1),$$first(...e)===null),$isNil=(n,t)=>(...e)=>{checkParamsLength("$isNil",e,1,1);const r=$$first(...e);return Array.isArray(r)&&r.length===0},$isUndefined=(n,t)=>(...e)=>(checkParamsLength("$isUndefined",e,1,1),$$first(...e)===void 0),$isList=(n,t)=>(...e)=>(checkParamsLength("$isList",e,1,1),Array.isArray($$first(...e))),$isString=(n,t)=>(...e)=>(checkParamsLength("$isString",e,1,1),typeof $$first(...e)=="string"),$isNumber=(n,t)=>(...e)=>(checkParamsLength("$isNumber",e,1,1),typeof $$first(...e)=="number"),$isNaN=(n,t)=>(...e)=>(checkParamsLength("$isNaN",e,1,1),Number.isNaN($$first(...e))),$isFinite=(n,t)=>(...e)=>(checkParamsLength("$isFinite",e,1,1),Number.isFinite($$first(...e))),$isInteger=(n,t)=>(...e)=>(checkParamsLength("$isInteger",e,1,1),Number.isInteger($$first(...e))),$toString=(n,t)=>(...e)=>(checkParamsLength("$toString",e,1,1),String($$first(...e))),$toNumber=(n,t)=>(...e)=>(checkParamsLength("$toNumber",e,1,1),toNumber($$first(...e))),$__toObject=(n,t)=>(...e)=>{const r={};for(const o of e)if(Array.isArray(o)&&0<o.length){const s=isSymbol(o[0]),a=s?s.symbol:String(evaluate(n,o[0]));checkUnsafeVarNamesEx("$__#",r,a),o.length===1?r[a]=!0:o.length===2?r[a]=evaluate(n,o[1]):r[a]=evaluate(n,[{symbol:n.config.reservedNames.list}].concat(o.slice(1)))}else throw new Error("[SX] $__toObject: Invalid argument(s): args[?] is not array.");return r},assignBlacklist=[globalObj,Object.__proto__,{}.__proto__,Function.__proto__],$objectAssign=(n,t)=>(...e)=>{if(checkParamsLength("$objectAssign",e,1),assignBlacklist.includes(e[0]))throw new Error("[SX] $objectAssign: Invalid argument: args[0] is blacklisted object.");return Object.assign(e[0],...e.slice(1))},$jsonStringify=(n,t)=>(...e)=>(checkParamsLength("$jsonStringify",e,1,1),JSON.stringify($$first(...e))),$jsonParse=(n,t)=>(...e)=>{checkParamsLength("$jsonParse",e,1,1);const r=$$first(...e);if(typeof r!="string")throw new Error("[SX] $jsonParse: Invalid argument(s): args[0] is not string.");return JSON.parse(r)},$now=(n,t)=>(...e)=>Date.now(),$datetimeFromIso=(n,t)=>(...e)=>{checkParamsLength("$datetimeFromIso",e,1,1);const r=$$first(...e);if(typeof r!="string")throw new Error("[SX] $datetimeFromIso: Invalid argument(s): args[0] is not string.");if(!/^(?:(?:-[0-9]{6,})|[0-9]{4,})-(?:[0-1][0-9])-(?:[0-3][0-9])(?:T(?:[0-2][0-9])(?:[:](?:[0-6][0-9])(?:[:](?:[0-6][0-9])(?:.[0-9]{1,})?)?)?(?:Z|[-+][0-9]{2}(?:[:]?[0-6][0-9])?)?)?$/.test(r))throw new Error(`[SX] $datetimeFromIso: Invalid datetime (pattern unmatched): ${r}.`);const o=new Date(r).getTime();if(Number.isNaN(o))throw new Error(`[SX] $datetimeFromIso: Invalid datetime: ${r}.`);return o},$datetime=(n,t)=>(...e)=>{checkParamsLength("$datetime",e,3,7);let r="";const o=Number(e[0]);o>=0?r+=String(o).padStart(4,"0"):r+="-"+String(-o).padStart(6,"0"),r+="-"+String(Number(e[1])).padStart(2,"0"),r+="-"+String(Number(e[2])).padStart(2,"0"),e.length>=4&&(r+="T"+String(Number(e[3])).padStart(2,"0"),e.length>=5?r+=":"+String(Number(e[4])).padStart(2,"0"):r+=":00",e.length>=6&&(r+=":"+String(Number(e[5])).padStart(2,"0")),e.length>=7&&(r+="."+String(Number(e[6])).padStart(3,"0").slice(0,3)),r+="Z");const s=new Date(r).getTime();if(Number.isNaN(s))throw new Error(`[SX] $datetime: Invalid datetime: ${r}.`);return s},$datetimeLc=(n,t)=>(...e)=>{checkParamsLength("$datetimeLc",e,3,7);let r="";const o=Number(e[0]);o>=0?r+=String(o).padStart(4,"0"):r+="-"+String(-o).padStart(6,"0"),r+="-"+String(Number(e[1])).padStart(2,"0"),r+="-"+String(Number(e[2])).padStart(2,"0"),e.length>=4?(r+="T"+String(Number(e[3])).padStart(2,"0"),e.length>=5?r+=":"+String(Number(e[4])).padStart(2,"0"):r+=":00",e.length>=6&&(r+=":"+String(Number(e[5])).padStart(2,"0")),e.length>=7&&(r+="."+String(Number(e[6])).padStart(3,"0").slice(0,3))):r+="T00:00:00.000";const s=new Date(r).getTime();if(Number.isNaN(s))throw new Error(`[SX] $datetimeLc: Invalid datetime: ${r}.`);return s},$datetimeToIsoString=(n,t)=>(...e)=>{checkParamsLength("$datetimeToIsoString",e,1,1);const r=$$first(...e);if(typeof r!="number")throw new Error("[SX] $datetimeToIsoString: Invalid argument(s): args[0] is not number.");const o=new Date(r);if(Number.isNaN(o.getTime()))throw new Error(`[SX] $datetimeToIsoString: Invalid datetime: ${r}.`);return o.toISOString()},$datetimeToComponents=(n,t)=>(...e)=>{checkParamsLength("$datetimeToComponents",e,1,1);const r=$$first(...e);if(typeof r!="number")throw new Error("[SX] $datetimeToComponents: Invalid argument(s): args[0] is not number.");const o=new Date(r);if(Number.isNaN(o.getTime()))throw new Error(`[SX] $datetimeToComponents: Invalid datetime: ${r}.`);return[o.getUTCFullYear(),o.getUTCMonth()+1,o.getUTCDate(),o.getUTCHours(),o.getUTCMinutes(),o.getUTCSeconds(),o.getUTCMilliseconds(),0,o.getUTCDay()]},$datetimeToComponentsLc=(n,t)=>(...e)=>{checkParamsLength("$datetimeToComponentsLc",e,1,1);const r=$$first(...e);if(typeof r!="number")throw new Error("[SX] $datetimeToComponentsLc: Invalid argument(s): args[0] is not number.");const o=new Date(r);if(Number.isNaN(o.getTime()))throw new Error(`[SX] $datetimeToComponentsLc: Invalid datetime: ${r}.`);return[o.getFullYear(),o.getMonth()+1,o.getDate(),o.getHours(),o.getMinutes(),o.getSeconds(),o.getMilliseconds(),-o.getTimezoneOffset(),o.getDay()]},$match=(n,t)=>(...e)=>{if(checkParamsLength("$match",e,2,3),!n.config.enableRegExpMatchOperators)throw new Error("[SX] $match: Operator is disabled by configuration.");return e.length===2?new RegExp(e[0]).exec(e[1]):new RegExp(e[0],e[1]).exec(e[2])},$consoleLog=(n,t)=>(...e)=>(console.log(...e),null),$consoleError=(n,t)=>(...e)=>(console.error(...e),null),$consoleTrace=(n,t)=>(...e)=>(console.trace(...e),null),$consoleTime=(n,t)=>(...e)=>(console.time(...e),null),$consoleTimeEnd=(n,t)=>(...e)=>(console.timeEnd(...e),null),$consoleTimeLog=(n,t)=>(...e)=>(console.timeLog(...e),null),operators=[{name:"$car",fn:$car},{name:"$cdr",fn:$cdr},{name:"$cons",fn:$cons},{name:"$first",fn:$first},{name:"$second",fn:$second},{name:"$last",fn:$last},{name:"$progn",fn:$last},{name:"$rest",fn:$rest},{name:"$first-and-second",fn:$firstAndSecond},{name:"$atom",fn:$atom},{name:"$eq",fn:$eq},{name:"===",fn:$eq},{name:"$not-eq",fn:$notEq},{name:"!==",fn:$notEq},{name:"$list",fn:$list},{name:"$__scope",fn:$__scope},{name:"$__global",fn:$__globalScope},{name:"$__capture",fn:$__capture},{name:"$__lambda",fn:$__lambda},{name:"$__defun",fn:$__defun},{name:"$__refun",fn:$__refun},{name:"$__defmacro",fn:$__defmacro},{name:"$apply",fn:$apply},{name:"$__call",fn:$__call},{name:"$__try",fn:$__try},{name:"$raise",fn:$raise},{name:"$__if",fn:$__if},{name:"$__if-null",fn:$__ifNull},{name:"$__cond",fn:$__cond},{name:"$__while",fn:$__while},{name:"$__do-while",fn:$__doWhile},{name:"$__until",fn:$__until},{name:"$__do-until",fn:$__doUntil},{name:"$__repeat",fn:$__repeat},{name:"$__for",fn:$__for},{name:"$pipe",fn:$pipe},{name:"$__get",fn:$__get},{name:"$__let",fn:$__let},{name:"$__set",fn:$__set},{name:"$boolean",fn:$boolean},{name:"$not",fn:$not},{name:"$__and",fn:$__and},{name:"$__or",fn:$__or},{name:"==",fn:$ambiguousEq},{name:"!=",fn:$ambiguousNotEq},{name:"<",fn:$lt},{name:"<=",fn:$le},{name:">",fn:$gt},{name:">=",fn:$ge},{name:"$typeof",fn:$typeof},{name:"$symbol",fn:$symbol},{name:"$__gensym",fn:$__gensym},{name:"$is-symbol",fn:$isSymbol},{name:"$is-null",fn:$isNull},{name:"$is-nil",fn:$isNil},{name:"$is-undefined",fn:$isUndefined},{name:"$is-list",fn:$isList},{name:"$is-string",fn:$isString},{name:"$is-number",fn:$isNumber},{name:"$is-NaN",fn:$isNaN},{name:"$is-finite",fn:$isFinite},{name:"$is-integer",fn:$isInteger},{name:"$to-string",fn:$toString},{name:"$to-number",fn:$toNumber},{name:"$__#",fn:$__toObject},{name:"$object-assign",fn:$objectAssign},{name:"$json-stringify",fn:$jsonStringify},{name:"$now",fn:$now},{name:"$datetime-from-iso",fn:$datetimeFromIso},{name:"$datetime",fn:$datetime},{name:"$datetime-lc",fn:$datetimeLc},{name:"$datetime-to-iso-string",fn:$datetimeToIsoString},{name:"$datetime-to-components",fn:$datetimeToComponents},{name:"$datetime-to-components-lc",fn:$datetimeToComponentsLc},{name:"$json-parse",fn:$jsonParse},{name:"$match",fn:$match},{name:"$console-log",fn:$consoleLog},{name:"$console-error",fn:$consoleError},{name:"$console-trace",fn:$consoleTrace},{name:"$console-time",fn:$consoleTime},{name:"$console-time-end",fn:$consoleTimeEnd},{name:"$console-time-log",fn:$consoleTimeLog}],compilationOperators=[{name:"$$__lambda",fn:$comp$__lambda},{name:"$$__defun",fn:$comp$__defun}],coreOperators=[].concat(operators,compilationOperators),macros$4=[{name:"$scope",fn:(n,t)=>e=>[{symbol:"$__scope"},e[1],e[2],...e.slice(3).map(r=>quote(n,r))]},{name:"$local",fn:(n,t)=>e=>[{symbol:"$__scope"},!0,!1,...e.slice(1).map(r=>quote(n,r))]},{name:"$global",fn:(n,t)=>e=>[{symbol:"$__global"},!1,...e.slice(1).map(r=>quote(n,r))]},{name:"$clisp-let",fn:(n,t)=>e=>[{symbol:"$__scope"},!0,!1,...e.slice(1).map(r=>quote(n,r))]},{name:"$capture",fn:(n,t)=>e=>[{symbol:"$__capture"},...e.slice(1).map(r=>quote(n,r))]},{name:"$closure",fn:(n,t)=>e=>{if(!isSymbol(e[2],"use"))throw new Error("[SX] $closure: Invalid syntax: missing 'use' keyword.");return[{symbol:"$__capture"},quote(n,e[3]),quote(n,[{symbol:"$__lambda"},quote(n,e[1]),...e.slice(4).map(o=>quote(n,o))])]}},{name:"|->",fn:(n,t)=>e=>[{symbol:"$closure"},...e.slice(1)]},{name:"$lambda",fn:(n,t)=>e=>[{symbol:"$__lambda"},...e.slice(1).map(r=>quote(n,r))]},{name:"->",fn:(n,t)=>e=>[{symbol:"$__lambda"},...e.slice(1).map(r=>quote(n,r))]},{name:"$defun",fn:(n,t)=>e=>[{symbol:"$__defun"},...e.slice(1).map(r=>quote(n,r))]},{name:"$refun",fn:(n,t)=>e=>[{symbol:"$__refun"},...e.slice(1).map(r=>quote(n,r))]},{name:"<-",fn:(n,t)=>e=>[{symbol:"$__refun"},...e.slice(1).map(r=>quote(n,r))]},{name:"$defmacro",fn:(n,t)=>e=>[{symbol:"$__defmacro"},...e.slice(1).map(r=>quote(n,r))]},{name:"$call",fn:(n,t)=>e=>(checkParamsLength("$call",e,3),[{symbol:"$__call"},e[1],quote(n,e[2]),...e.slice(3)])},{name:"$try",fn:(n,t)=>e=>[{symbol:"$__try"},...e.slice(1).map(r=>quote(n,r))]},{name:"$if",fn:(n,t)=>e=>[{symbol:"$__if"},e[1],...e.slice(2).map(r=>quote(n,r))]},{name:"$if-null",fn:(n,t)=>e=>[{symbol:"$__if-null"},e[1],...e.slice(2).map(r=>quote(n,r))]},{name:"??",fn:(n,t)=>e=>[{symbol:"$__if-null"},e[1],...e.slice(2).map(r=>quote(n,r))]},{name:"$cond",fn:(n,t)=>e=>[{symbol:"$__cond"},...e.slice(1).map(r=>quote(n,r))]},{name:"$while",fn:(n,t)=>e=>[{symbol:"$__while"},...e.slice(1).map(r=>quote(n,r))]},{name:"$do-while",fn:(n,t)=>e=>[{symbol:"$__do-while"},...e.slice(1).map(r=>quote(n,r))]},{name:"$until",fn:(n,t)=>e=>[{symbol:"$__until"},...e.slice(1).map(r=>quote(n,r))]},{name:"$do-until",fn:(n,t)=>e=>[{symbol:"$__do-until"},...e.slice(1).map(r=>quote(n,r))]},{name:"$repeat",fn:(n,t)=>e=>{if(!isSymbol(e[2],"of"))throw new Error("[SX] $repeat: Invalid syntax: missing 'of' keyword.");return[{symbol:"$__repeat"},quote(n,e[1]),e[3],...e.slice(4).map(o=>quote(n,o))]}},{name:"$for",fn:(n,t)=>e=>{if(!isSymbol(e[2],"of"))throw new Error("[SX] $for: Invalid syntax: missing 'of' keyword.");return[{symbol:"$__for"},quote(n,e[1]),e[3],...e.slice(4).map(o=>quote(n,o))]}},{name:"$get",fn:(n,t)=>e=>[{symbol:"$__get"},...e.slice(1).map(r=>quote(n,r))]},{name:"$let",fn:(n,t)=>e=>(checkParamsLength("$let",e,3,3),[{symbol:"$__let"},quote(n,e[1]),e[2]])},{name:"$clisp-defvar",fn:(n,t)=>e=>(checkParamsLength("$clisp-defvar",e,3,3),[{symbol:"$global"},[{symbol:"$__let"},quote(n,e[1]),e[2]]])},{name:"$set",fn:(n,t)=>e=>(checkParamsLength("$set",e,3,3),[{symbol:"$__set"},quote(n,e[1]),e[2]])},{name:"$clisp-setq",fn:(n,t)=>e=>(checkParamsLength("$clisp-setq",e,3,3),[{symbol:"$__set"},quote(n,e[1]),e[2]])},{name:"$and",fn:(n,t)=>e=>[{symbol:"$__and"},...e.slice(1).map(r=>quote(n,r))]},{name:"$or",fn:(n,t)=>e=>[{symbol:"$__or"},...e.slice(1).map(r=>quote(n,r))]},{name:"$gensym",fn:(n,t)=>e=>[{symbol:"$__gensym"},...e.slice(1).map(r=>quote(n,r))]},{name:"#",fn:(n,t)=>e=>[{symbol:"$__#"},...e.slice(1).map(r=>quote(n,r))]}],compilationMacros=[{name:"$$closure",fn:(n,t)=>e=>{if(!isSymbol(e[2],"use"))throw new Error("[SX] $closure: Invalid syntax: missing 'use' keyword.");return[{symbol:"$__capture"},quote(n,e[3]),quote(n,[{symbol:"$$__lambda"},quote(n,e[1]),...e.slice(4).map(o=>quote(n,o))])]}},{name:"|=>",fn:(n,t)=>e=>[{symbol:"$$closure"},...e.slice(1)]},{name:"$$lambda",fn:(n,t)=>e=>[{symbol:"$$__lambda"},...e.slice(1).map(r=>quote(n,r))]},{name:"=>",fn:(n,t)=>e=>[{symbol:"$$__lambda"},...e.slice(1).map(r=>quote(n,r))]},{name:"$$defun",fn:(n,t)=>e=>[{symbol:"$$__defun"},...e.slice(1).map(r=>quote(n,r))]}],coreMacros=[].concat(macros$4,compilationMacros),symbols$4=[{name:"nil",fn:(n,t)=>[]},{name:"null",fn:(n,t)=>null},{name:"undefined",fn:(n,t)=>{}},{name:"true",fn:(n,t)=>!0},{name:"#true",fn:(n,t)=>!0},{name:"#t",fn:(n,t)=>!0},{name:"false",fn:(n,t)=>!1},{name:"#false",fn:(n,t)=>!1},{name:"#f",fn:(n,t)=>!1},{name:"#Number:Infinity",fn:(n,t)=>Number.POSITIVE_INFINITY},{name:"+Infinity",fn:(n,t)=>Number.POSITIVE_INFINITY},{name:"-Infinity",fn:(n,t)=>Number.NEGATIVE_INFINITY},{name:"#Number:Epsilon",fn:(n,t)=>Number.EPSILON},{name:"#Number:MaxValue",fn:(n,t)=>Number.MAX_VALUE},{name:"#Number:MinValue",fn:(n,t)=>Number.MIN_VALUE},{name:"#Number:MinSafeInteger",fn:(n,t)=>Number.MAX_SAFE_INTEGER},{name:"#Number:MinSafeInteger",fn:(n,t)=>Number.MIN_SAFE_INTEGER},{name:"NaN",fn:(n,t)=>Number.NaN}];function install$4(n){return n.funcs=(n.funcs||[]).concat(operators).concat(n.enableCompilationOperators?compilationOperators:[]),n.macros=(n.macros||[]).concat(macros$4).concat(n.enableCompilationOperators?compilationMacros:[]),n.symbols=(n.symbols||[]).concat(symbols$4),n}const $bitLShift=(n,t)=>(...e)=>{checkParamsLength("$bitLShift",e,2,2);let{car:r,cdr:o}=$$firstAndSecond(...e);return r=toNumber(r),o=toNumber(o),0<=o?o<32?r<<o:0:o>-32?r>>>-o:0},$bitSRShift=(n,t)=>(...e)=>{checkParamsLength("$bitSRShift",e,2,2);let{car:r,cdr:o}=$$firstAndSecond(...e);return r=toNumber(r),o=toNumber(o),0<=o?o<32?r>>o:r&2147483648?-1:0:o>-32?r<<-o:0},$bitURShift=(n,t)=>(...e)=>{checkParamsLength("$bitURShift",e,2,2);let{car:r,cdr:o}=$$firstAndSecond(...e);return r=toNumber(r),o=toNumber(o),0<=o?o<32?r>>>o:0:o>-32?r<<-o:0},$bitNot=(n,t)=>(...e)=>{checkParamsLength("$bitNot",e,1,1);const r=$$first(...e);return~toNumber(r)},$bitAnd=(n,t)=>(...e)=>{checkParamsLength("$bitAnd",e,2);const r=$$first(...e);return e.slice(1).reduce((o,s)=>toNumber(o)&toNumber(s),toNumber(r))},$bitOr=(n,t)=>(...e)=>{checkParamsLength("$bitOr",e,2);const r=$$first(...e);return e.slice(1).reduce((o,s)=>toNumber(o)|toNumber(s),toNumber(r))},$bitXor=(n,t)=>(...e)=>{checkParamsLength("$bitXor",e,2);const r=$$first(...e);return e.slice(1).reduce((o,s)=>toNumber(o)^toNumber(s),toNumber(r))},$add=(n,t)=>(...e)=>(checkParamsLength("$add",e,1),e.reduce((r,o)=>toNumber(r)+toNumber(o),0)),$sub=(n,t)=>(...e)=>{checkParamsLength("$sub",e,1);const r=$$first(...e);return e.slice(1).length===0?-toNumber(r):e.slice(1).reduce((s,a)=>toNumber(s)-toNumber(a),toNumber(r))},$mul=(n,t)=>(...e)=>{checkParamsLength("$mul",e,2);const r=$$first(...e);return e.slice(1).reduce((o,s)=>toNumber(o)*toNumber(s),toNumber(r))},$sup=(n,t)=>(...e)=>{checkParamsLength("$sup",e,2);const r=$$first(...e);return e.slice(1).reduce((o,s)=>Math.pow(toNumber(o),toNumber(s)),toNumber(r))},$div=(n,t)=>(...e)=>{checkParamsLength("$div",e,2);const r=$$first(...e);return e.slice(1).reduce((o,s)=>toNumber(o)/toNumber(s),toNumber(r))},$mod=(n,t)=>(...e)=>{checkParamsLength("$mod",e,2);const r=$$first(...e);return e.slice(1).reduce((o,s)=>toNumber(o)%toNumber(s),toNumber(r))},$max=(n,t)=>(...e)=>Math.max(...e.map(r=>toNumber(r))),$min=(n,t)=>(...e)=>Math.min(...e.map(r=>toNumber(r))),$avg=(n,t)=>(...e)=>{const r=e.map(o=>toNumber(o));return r.length>0?r.reduce((o,s)=>o+s,0)/r.length:NaN},$floor=(n,t)=>(...e)=>(checkParamsLength("$floor",e,1,1),Math.floor(toNumber($$first(...e)))),$ceil=(n,t)=>(...e)=>(checkParamsLength("$ceil",e,1,1),Math.ceil(toNumber($$first(...e)))),$round=(n,t)=>(...e)=>(checkParamsLength("$round",e,1,1),Math.round(toNumber($$first(...e)))),$abs=(n,t)=>(...e)=>(checkParamsLength("$abs",e,1,1),Math.abs(toNumber($$first(...e)))),$sign=(n,t)=>(...e)=>(checkParamsLength("$sign",e,1,1),Math.sign(toNumber($$first(...e)))),funcs$3=[{name:"<<",fn:$bitLShift},{name:"$bit-l-shift",fn:$bitLShift},{name:">>",fn:$bitSRShift},{name:"$bit-sr-shift",fn:$bitSRShift},{name:">>>",fn:$bitURShift},{name:"$bit-ur-shift",fn:$bitURShift},{name:"$bit-not",fn:$bitNot},{name:"$bit-and",fn:$bitAnd},{name:"$bit-or",fn:$bitOr},{name:"$bit-xor",fn:$bitXor},{name:"+",fn:$add},{name:"$add",fn:$add},{name:"$sum",fn:$add},{name:"-",fn:$sub},{name:"$sub",fn:$sub},{name:"$neg",fn:$sub},{name:"*",fn:$mul},{name:"$mul",fn:$mul},{name:"**",fn:$sup},{name:"$sup",fn:$sup},{name:"/",fn:$div},{name:"$div",fn:$div},{name:"%",fn:$mod},{name:"$mod",fn:$mod},{name:"$max",fn:$max},{name:"$min",fn:$min},{name:"$avg",fn:$avg},{name:"$floor",fn:$floor},{name:"$ceil",fn:$ceil},{name:"$round",fn:$round},{name:"$abs",fn:$abs},{name:"$sign",fn:$sign}],macros$3=[{name:"$incl",fn:(n,t)=>e=>(checkParamsLength("$incl",e,2,2),[{symbol:"$set"},e[1],[{symbol:"$add"},e[1],1]])},{name:"++",fn:(n,t)=>e=>(checkParamsLength("++",e,2,2),[{symbol:"$set"},e[1],[{symbol:"$add"},e[1],1]])},{name:"$decl",fn:(n,t)=>e=>(checkParamsLength("$decl",e,2,2),[{symbol:"$set"},e[1],[{symbol:"$add"},e[1],-1]])},{name:"--",fn:(n,t)=>e=>(checkParamsLength("--",e,2,2),[{symbol:"$set"},e[1],[{symbol:"$add"},e[1],-1]])},{name:"$incln",fn:(n,t)=>e=>{if(checkParamsLength("$incln",e,3,3),typeof e[2]!="number")throw new Error("[SX] $incln: Invalid parameter: arg(1) is not number.");return[{symbol:"$set"},e[1],[{symbol:"$add"},e[1],e[2]]]}},{name:"+=",fn:(n,t)=>e=>{if(checkParamsLength("+=",e,3,3),typeof e[2]!="number")throw new Error("[SX] +=: Invalid parameter: arg(1) is not number.");return[{symbol:"$set"},e[1],[{symbol:"$add"},e[1],e[2]]]}},{name:"$decln",fn:(n,t)=>e=>{if(checkParamsLength("$decln",e,3,3),typeof e[2]!="number")throw new Error("[SX] $decln: Invalid parameter: arg(1) is not number.");return[{symbol:"$set"},e[1],[{symbol:"$add"},e[1],-e[2]]]}},{name:"-=",fn:(n,t)=>e=>{if(checkParamsLength("-=",e,3,3),typeof e[2]!="number")throw new Error("[SX] -=: Invalid parameter: arg(1) is not number.");return[{symbol:"$set"},e[1],[{symbol:"$add"},e[1],-e[2]]]}}],symbols$3=[];function install$3(n){return n.funcs=(n.funcs||[]).concat(funcs$3),n.macros=(n.macros||[]).concat(macros$3),n.symbols=(n.symbols||[]).concat(symbols$3),n}class Query{constructor(t){this.data=t}orderBy(t){let e;return Array.isArray(t)?e=(r,o)=>{for(const s of t)if(typeof s=="string"){if(r[s]>o[s])return 1;if(r[s]<o[s])return-1}else{const a=s[1]==="desc"?-1:1;if(r[s[0]]>o[s[0]])return 1*a;if(r[s[0]]<o[s[0]])return-1*a}return 0}:e=t,new Query(this.data.slice(0).sort(e))}groupBy(t){let e;Array.isArray(t)?e=(a,l)=>{for(const i of t)if(a[i]!==l[i])return!1;return!0}:e=t;const r=[];let o=0,s=1;for(;s<this.data.length;s++)e(this.data[o],this.data[s],s,this.data)||(r.push(this.data.slice(o,s)),o=s);return r.push(this.data.slice(o,s)),new Query(r)}groupEvery(t){if(typeof t=="number")return this.groupBy((e,r,o,s)=>o%t!==0);{const e=Object.assign({first:t.intermediate,last:t.intermediate},t),r=this.groupBy((o,s,a,l)=>e.single>=l.length?a%e.single!==0:a<=e.first?a%e.first!==0:(a-e.first)%e.intermediate!==0);return r.data.length===1?e.single<r.data[0].length&&r.data.push([]):e.first<r.data[0].length&&r.data.unshift([]),r.data.length>1&&r.data[r.data.length-1].length>e.last&&r.data.push([]),r}}where(t){return new Query(this.data.filter(t))}select(t){return t?this.data.map(t):this.data}}function query(n){return new Query(n)}const $range=(n,t)=>(...e)=>{checkParamsLength("$range",e,2,3);const{car:r,cdr:o}=$$firstAndSecond(...e),s=toNumber(r)||0,a=toNumber(o)||0,l=e.length>2&&toNumber(e[2])||0||(s<=a?1:-1),i=Math.sign(a-s)+Math.sign(l)!==0?Math.floor(Math.abs(a-s)/Math.abs(l))+1:0;return n.evalCount+=i,evaluate(n,0),Array.from({length:i},(m,c)=>s+c*l)},$length=(n,t)=>(...e)=>{checkParamsLength("$length",e,1,1);const r=$$first(...e);switch(typeof r){case"object":if(!("length"in r))break;case"string":return r.length}throw new Error("[SX] $length: Invalid argument type: object has no property 'length'.")},$trim=(n,t)=>(...e)=>{checkParamsLength("$trim",e,1,1);const r=$$first(...e);if(typeof r=="string")return r.trim();throw new Error("[SX] $trim: Invalid argument type: args[0] is not string.")},$trimHead=(n,t)=>(...e)=>{checkParamsLength("$trimHead",e,1,1);const r=$$first(...e);if(typeof r=="string")return r.trimLeft();throw new Error("[SX] $trimHead: Invalid argument type: args[0] is not string.")},$trimTail=(n,t)=>(...e)=>{checkParamsLength("$trimTail",e,1,1);const r=$$first(...e);if(typeof r=="string")return r.trimRight();throw new Error("[SX] $trimTail: Invalid argument type: args[0] is not string.")},$replaceAll=(n,t)=>(...e)=>{if(checkParamsLength("$replaceAll",e,3,3),typeof e[0]=="string"&&typeof e[1]=="string"&&typeof e[2]=="string")return e[0].split(e[1]).join(e[2]);throw new Error("[SX] $replaceAll: Invalid argument type: args[0] or [1] or [2] is not string.")},$split=(n,t)=>(...e)=>{if(checkParamsLength("$split",e,2,2),typeof e[0]=="string"&&typeof e[1]=="string")return e[0].split(e[1]);throw new Error("[SX] $split: Invalid argument type: args[0] or [1] is not string.")},$join=(n,t)=>(...e)=>{if(checkParamsLength("$join",e,1,2),Array.isArray(e[0]),e.length>1){if(typeof e[1]=="string")return e[0].join(e[1]);throw new Error("[SX] $join: Invalid argument type: args[1] is not string.")}else return e[0].join();throw new Error("[SX] $join: Invalid argument type: args[0] is not array.")},$concat=(n,t)=>(...e)=>{checkParamsLength("$concat",e,1);const r=$$first(...e);switch(typeof r){case"object":if(!("concat"in r))break;case"string":return r.concat(...e.slice(1))}throw new Error("[SX] $concat: Invalid argument type: object has no property 'concat'.")},$slice=(n,t)=>(...e)=>{if(checkParamsLength("$slice",e,2,3),e.length===3&&(typeof e[2]=="string"||Array.isArray(e[2])))return e[2].slice(toNumber(e[0]),toNumber(e[1]));if(e.length===2&&(typeof e[1]=="string"||Array.isArray(e[1])))return e[1].slice(toNumber(e[0]));throw new Error(`[SX] $slice: Invalid argument type: args[${e.length-1}] is not string or array.`)},$top=(n,t)=>(...e)=>{if(checkParamsLength("$top",e,2,2),typeof e[1]=="string"||Array.isArray(e[1]))return e[1].slice(0,toNumber(e[0]));throw new Error("[SX] $top: Invalid argument type: args[1] is not string or array.")},$tail=(n,t)=>(...e)=>{if(checkParamsLength("$tail",e,2,2),typeof e[1]=="string"||Array.isArray(e[1])){const r=-toNumber(e[0]);return e[1].slice(r>=0||Number.isNaN(r)?e[1].length:r)}throw new Error("[SX] $tail: Invalid argument type: args[1] is not string or array.")},$push=(n,t)=>(...e)=>{return checkParamsLength("$push",e,2,2),Array.isArray(e[0]),e[0].push(e[1]),e[0];throw new Error("[SX] $push: Invalid argument type: args[1] is not array.")},$pop=(n,t)=>(...e)=>{return checkParamsLength("$pop",e,1,1),Array.isArray(e[0]),e[0].pop();throw new Error("[SX] $pop: Invalid argument type: args[1] is not array.")},$__at=(n,t)=>(...e)=>{checkParamsLength("$__at",e,2,2);const{car:r,cdr:o}=$$firstAndSecond(...e);return o[r]},$reverse=(n,t)=>(...e)=>{checkParamsLength("$reverse",e,1,1);const r=$$first(...e);if(Array.isArray(r))return r.slice(0).reverse();throw new Error("[SX] $reverse: Invalid argument type: args[0] is not array.")},$reverseDestructive=(n,t)=>(...e)=>{checkParamsLength("$reverse!",e,1,1);const r=$$first(...e);if(Array.isArray(r))return r.reverse();throw new Error("[SX] $reverse!: Invalid argument type: args[0] is not array.")},$find=(n,t)=>(...e)=>{checkParamsLength("$find",e,2,2);const{car:r,cdr:o}=$$firstAndSecond(...e);if(Array.isArray(r))return r.find(o);throw new Error("[SX] $find: Invalid argument type: args[0] is not array.")},$filter=(n,t)=>(...e)=>{checkParamsLength("$filter",e,2,2);const{car:r,cdr:o}=$$firstAndSecond(...e);if(Array.isArray(r))return r.filter(o);throw new Error("[SX] $filter: Invalid argument type: args[0] is not array.")},$map=(n,t)=>(...e)=>{checkParamsLength("$map",e,2,2);const{car:r,cdr:o}=$$firstAndSecond(...e);if(Array.isArray(r))return r.map(o);throw new Error("[SX] $map: Invalid argument type: args[0] is not array.")},$reduce=(n,t)=>(...e)=>{checkParamsLength("$reduce",e,2,3);const{car:r,cdr:o}=$$firstAndSecond(...e);if(Array.isArray(r))return e.length<3?r.reduce(o):r.reduce(o,e[2]);throw new Error("[SX] $reduce: Invalid argument type: args[0] is not array.")},$reduceFromTail=(n,t)=>(...e)=>{checkParamsLength("$reduceFromTail",e,2,3);const{car:r,cdr:o}=$$firstAndSecond(...e);if(Array.isArray(r))return e.length<3?r.reduceRight(o):r.reduceRight(o,e[2]);throw new Error("[SX] $reduceFromTail: Invalid argument type: args[0] is not array.")},$sort=(n,t)=>(...e)=>{checkParamsLength("$sort",e,2,2);const{car:r,cdr:o}=$$firstAndSecond(...e);if(Array.isArray(r))return r.slice(0).sort(o);throw new Error("[SX] $sort: Invalid argument type: args[0] is not array.")},$sortDestructive=(n,t)=>(...e)=>{checkParamsLength("$sort!",e,2,2);const{car:r,cdr:o}=$$firstAndSecond(...e);if(Array.isArray(r))return r.sort(o);throw new Error("[SX] $sort!: Invalid argument type: args[0] is not array.")},$groupEvery=(n,t)=>(...e)=>{checkParamsLength("$group-every",e,2,2);const{car:r,cdr:o}=$$firstAndSecond(...e);if(!Array.isArray(o))throw new Error("[SX] $group-every: Invalid argument type: args[1] is not array.");return query(o).groupEvery(r).select()},$groupBy=(n,t)=>(...e)=>{checkParamsLength("$group-by",e,2,2);const{car:r,cdr:o}=$$firstAndSecond(...e);if(!Array.isArray(o))throw new Error("[SX] $group-by: Invalid argument type: args[1] is not array.");return query(o).groupBy(r).select()},$orderBy=(n,t)=>(...e)=>{checkParamsLength("$order-by",e,2,2);const{car:r,cdr:o}=$$firstAndSecond(...e);if(!Array.isArray(o))throw new Error("[SX] $order-by: Invalid argument type: args[1] is not array.");return query(o).orderBy(r).select()},$where=(n,t)=>(...e)=>{checkParamsLength("$where",e,2,2);const{car:r,cdr:o}=$$firstAndSecond(...e);if(typeof e[0]!="function")throw new Error("[SX] $where: Invalid argument type: args[0] is not function.");if(!Array.isArray(o))throw new Error("[SX] $where: Invalid argument type: args[1] is not array.");return query(o).where(r).select()},funcs$2=[{name:"$range",fn:$range},{name:"$length",fn:$length},{name:"$trim",fn:$trim},{name:"$trim-head",fn:$trimHead},{name:"$trim-tail",fn:$trimTail},{name:"$replace-all",fn:$replaceAll},{name:"$split",fn:$split},{name:"$join",fn:$join},{name:"$concat",fn:$concat},{name:"$slice",fn:$slice},{name:"$top",fn:$top},{name:"$tail",fn:$tail},{name:"$push",fn:$push},{name:"$pop",fn:$pop},{name:"$__at",fn:$__at},{name:"$reverse",fn:$reverse},{name:"$reverse!",fn:$reverseDestructive},{name:"$find",fn:$find},{name:"$filter",fn:$filter},{name:"$map",fn:$map},{name:"$reduce",fn:$reduce},{name:"$reduce-from-head",fn:$reduce},{name:"$reduce-from-tail",fn:$reduceFromTail},{name:"$sort",fn:$sort},{name:"$sort!",fn:$sortDestructive},{name:"$group-every",fn:$groupEvery},{name:"$group-by",fn:$groupBy},{name:"$order-by",fn:$orderBy},{name:"$where",fn:$where}],macros$2=[{name:"$[",fn:(n,t)=>e=>{if(!isSymbol(e[2],"]"))throw new Error("[SX] $repeat: Invalid syntax: missing ']' keyword.");return[{symbol:"$__at"},e[1],e[3]]}}],symbols$2=[];function install$2(n){return n.funcs=(n.funcs||[]).concat(funcs$2),n.macros=(n.macros||[]).concat(macros$2),n.symbols=(n.symbols||[]).concat(symbols$2),n}const $__letAsync=(n,t)=>(...e)=>{checkParamsLength("$__letAsync",e,2,2);let r=e[1];return(typeof r!="object"||typeof r.then!="function")&&(r=Promise.resolve(r)),r=r.then(o=>{try{return $__let(n,"")(e[0],o),o}catch(s){return Promise.reject(s)}}),r},$__setAsync=(n,t)=>(...e)=>{checkParamsLength("$__setAsync",e,2,2);let r=e[1];return(typeof r!="object"||typeof r.then!="function")&&(r=Promise.resolve(r)),r=r.then(o=>{try{return $__set(n,"")(e[0],o),o}catch(s){return Promise.reject(s)}}),r},$then=(n,t)=>(...e)=>{checkParamsLength("$then",e,2,3);let r=e[0];if((typeof r!="object"||typeof r.then!="function")&&(r=Promise.resolve(r)),typeof e[2]=="function")r=r.then(e[1],e[2]);else{if(typeof e[1]!="function")throw new Error("[SX] $then: Invalid argument(s): args[1] is not function.");r=r.then(e[1])}return r},$resolveAll=(n,t)=>(...e)=>{const r=e.slice(0);for(let o=0;o<r.length;o++)(typeof r[o]!="object"||typeof r[o].then!="function")&&(r[o]=Promise.resolve(r[o]));return Promise.all(r)},$resolveAny=(n,t)=>(...e)=>{const r=e.slice(0);for(let a=0;a<r.length;a++)(typeof r[a]!="object"||typeof r[a].then!="function")&&(r[a]=Promise.resolve(r[a]));const o=a=>new Promise((l,i)=>a.then(i,l));return(a=>o(Promise.all(a.map(o))))(r)},$resolvePipe=(n,t)=>(...e)=>{checkParamsLength("$resolvePipe",e,1);let r=e[0];(typeof r!="object"||typeof r.then!="function")&&(r=Promise.resolve(r));const o=e.slice(1);for(let a=0;a<o.length;a++)if(typeof o[a]!="function"){const l=o[a];o[a]=()=>l}let s=r;for(const a of o)s=s.then(a);return s},$resolveFork=(n,t)=>(...e)=>{checkParamsLength("$resolveFork",e,1);let r=e[0];(typeof r!="object"||typeof r.then!="function")&&(r=Promise.resolve(r));const o=e.slice(1);for(let i=0;i<o.length;i++)if(typeof o[i]!="function"){const m=o[i];o[i]=()=>m}const s=new Array(o.length),a=new Array(o.length),l=[];for(let i=0;i<o.length;i++)l.push(new Promise((m,c)=>{s[i]=u=>{let f=o[i](u);(typeof f!="object"||typeof f.then!="function")&&(f=Promise.resolve(f)),f.then($=>m($)).catch($=>c($))},a[i]=c}));return r.then(i=>s.forEach(m=>m(i)),i=>a.forEach(m=>m(i))),l},funcs$1=[{name:"$__let-async",fn:$__letAsync},{name:"$__set-async",fn:$__setAsync},{name:"$then",fn:$then},{name:"$resolve-all",fn:$resolveAll},{name:"$resolve-any",fn:$resolveAny},{name:"$resolve-pipe",fn:$resolvePipe},{name:"$resolve-fork",fn:$resolveFork}],macros$1=[{name:"$let-async",fn:(n,t)=>e=>(checkParamsLength("$let-async",e,3,3),[{symbol:"$__let-async"},quote(n,e[1]),e[2]])},{name:"$set-async",fn:(n,t)=>e=>(checkParamsLength("$set-async",e,3,3),[{symbol:"$__set-async"},quote(n,e[1]),e[2]])}],symbols$1=[];function install$1(n){return n.funcs=(n.funcs||[]).concat(funcs$1),n.macros=(n.macros||[]).concat(macros$1),n.symbols=(n.symbols||[]).concat(symbols$1),n}const L=(()=>{let n=Object.assign({},defaultConfig);return n.reservedNames=Object.assign({},n.reservedNames,{Template:"$concat"}),n=install$4(n),n=install$3(n),n=install$2(n),n=install$1(n),n.stripComments=!0,SExpression(n)})(),LS=L,lisp=L,L_async=(()=>{let n=Object.assign({},defaultConfig);return n.reservedNames=Object.assign({},n.reservedNames,{Template:"$concat"}),n=install$4(n),n=install$3(n),n=install$2(n),n=install$1(n),n.stripComments=!0,SExpressionAsync(n)})(),LS_async=L_async,lisp_async=L_async,LM=(()=>{let n=Object.assign({},defaultConfig);return n.reservedNames=Object.assign({},n.reservedNames,{Template:"$concat"}),n=install$4(n),n=install$3(n),n=install$2(n),n=install$1(n),n.stripComments=!0,n.returnMultipleRoot=!0,SExpression(n)})(),LM_async=(()=>{let n=Object.assign({},defaultConfig);return n.reservedNames=Object.assign({},n.reservedNames,{Template:"$concat"}),n=install$4(n),n=install$3(n),n=install$2(n),n=install$1(n),n.stripComments=!0,n.returnMultipleRoot=!0,SExpressionAsync(n)})(),$__outputIf=(n,t)=>(...e)=>{checkParamsLength("$__outputIf",e,2);const{car:r,cdr:o}=$$firstAndSecond(...e);let s=[];return $$boolean(r)&&(2<e.length?(s.push({symbol:n.config.reservedNames.Template},...e.slice(1)),s=evaluate(n,s)):s=evaluate(n,o)),s},$__outputForOf=(n,t)=>(...e)=>{checkParamsLength("$__outputForOf",e,2);const r=$$first(...e),o=[];if(Array.isArray(r))for(let s=0;s<r.length;s++){const a=r[s],l=$__scope(n)(!0,!0,[["$data",quote(n,a)],["$index",s],["$array",quote(n,r)],["$parent",quote(n,getScope(n).scope)]],...e.slice(1));2<e.length&&Array.isArray(l)?o.push(...l):o.push(l)}else throw new Error("[SX] $__outputForOf: Invalid argument(s): args[0] is not array.");return evaluate(n,[{symbol:n.config.reservedNames.Template}].concat(o.map(s=>[{symbol:n.config.reservedNames.quote},s])))},$jsxProps=(n,t)=>(...e)=>{const r={};for(const o of e)if(Array.isArray(o)&&0<o.length){const s=isSymbol(o[0]),a=s?s.symbol:String(evaluate(n,o[0]));switch(a){case"style":if(o.length===1)r[a]="";else if(o.length>=2){const l={};for(const i of o.slice(1))if(Array.isArray(i)&&1<i.length){const m=String(evaluate(n,i[0]));checkUnsafeVarNamesEx("$jsxProps",l,m),l[m]=String(evaluate(n,i[1]))}else if(typeof i=="string")for(const m of i.split(";")){const c=/^\s*(\S+)\s*:\s*(.*?)\s*$/.exec(m);c&&(checkUnsafeVarNamesEx("$jsxProps",l,c[1]),l[c[1]]=c[2])}r[a]=l}break;case"class":case"styleClass":if(o.length===1)r[a]=[];else if(o.length>=2){let l=[];for(const c of o.slice(1))Array.isArray(c)?l=l.concat(c.map(u=>evaluate(n,u))):typeof c=="string"&&(l=l.concat(c.split(" ")));const i=[],m=c=>c.forEach(u=>u==null?void 0:Array.isArray(u)?m(u):i.push(String(u)));m(l),r[a]=i}break;case"className":if(o.length===1)r[a]="";else if(o.length>=2){let l="";for(const i of o.slice(1)){let m="";if(Array.isArray(i)){const c=[],u=f=>f.map($=>evaluate(n,$)).forEach($=>$==null?void 0:Array.isArray($)?u($):c.push(String($)));u(i),m=c.join(" ")}else typeof i=="string"&&(m=i);0<l.length?l+=" "+m:l=m}r[a]=l}break;case"dangerouslySetInnerHTML":o.length===1?r[a]={__html:""}:o.length>=2?r[a]={__html:evaluate(n,o[1])}:r[a]={__html:evaluate(n,[{symbol:n.config.reservedNames.list}].concat(o.slice(1)))};break;case"setInnerText":o.length===1?r[a]={__text:""}:o.length>=2?r[a]={__text:evaluate(n,o[1])}:r[a]={__text:evaluate(n,[{symbol:n.config.reservedNames.list}].concat(o.slice(1)))};break;default:checkUnsafeVarNamesEx("$jsxProps",r,a),o.length===1?r[a]=!0:o.length===2?r[a]=evaluate(n,o[1]):r[a]=evaluate(n,[{symbol:n.config.reservedNames.list}].concat(o.slice(1)));break}}else throw new Error("[SX] $jsxProps: Invalid argument(s): args[?] is not array.");return r};function getJsxTagsParams(n,...t){let e=t,r={};return 0<t.length&&Array.isArray(t[0])&&isSymbol(t[0][0],"@")&&(r=$jsxProps(n)(...t[0].slice(1)),e=e.slice(1)),{props:r,children:e}}const $jsxStandardTag=(n,t)=>(...e)=>{const{props:r,children:o}=getJsxTagsParams(n,...e);return n.config.jsx(t,r,...o)},$jsxComponentTag=n=>(t,e)=>(...r)=>{const{props:o,children:s}=getJsxTagsParams(t,...r);return t.config.jsx(n,o,...s)},funcs=[{name:"$=__if",fn:$__outputIf},{name:"$=__for",fn:$__outputForOf}],macros=[{name:"@",fn:(n,t)=>e=>quote(n,e)},{name:"$=if",fn:(n,t)=>e=>[{symbol:"$=__if"},e[1],...e.slice(2).map(r=>quote(n,r))]},{name:"$=for",fn:(n,t)=>e=>[{symbol:"$=__for"},e[1],...e.slice(2).map(r=>quote(n,r))]}],symbols=[];function install(n,t){n.funcs=(n.funcs||[]).concat(funcs),n.macros=(n.macros||[]).concat(macros),n.symbols=(n.symbols||[]).concat(symbols);const e=Object.entries(t.components).map(r=>({name:r[0],fn:$jsxComponentTag(r[1])}));return n.funcs=n.funcs.concat({name:n.reservedNames.Template,fn:$jsxComponentTag(t.jsxFlagment)},...e),n.funcSymbolResolverFallback=$jsxStandardTag,n.jsx=t.jsx,n.JsxFragment=t.jsxFlagment,n}function LSX(n){let t=Object.assign({},defaultConfig);return t=install$4(t),t=install$3(t),t=install$2(t),t=install$1(t),t=install(t,n),t.stripComments=!0,SExpression(t)}function LSX_async(n){let t=Object.assign({},defaultConfig);return t=install$4(t),t=install$3(t),t=install$2(t),t=install$1(t),t=install(t,n),t.stripComments=!0,SExpressionAsync(t)}function runScriptTags(n,t,e="text/lisp"){const r=document.querySelectorAll(`script[type="${e}"]`),o=[];for(let s=0;s<r.length;s++)o.push(r[s].innerHTML);return n=n.appendGlobals(t||{}),n(o.join(`
`))}const builtinOperators={core:coreOperators,arithmetic:funcs$3,sequence:funcs$2,jsx:funcs,concurrent:funcs$1},builtinMacros={core:coreMacros,arithmetic:macros$3,sequence:macros$2,jsx:macros,concurrent:macros$1},builtinSymbols={core:symbols$4,arithmetic:symbols$3,sequence:symbols$2,jsx:symbols,concurrent:symbols$1};export{FatalError,L,LM,LM_async,LS,LSX,LSX_async,LS_async,L_async,MaxEvaluationCountError,S,SExpression,SExpressionAsync,ScriptTerminationError,backquote,builtinMacros,builtinOperators,builtinSymbols,defaultConfig,defaultReservedNames,install$3 as installArithmetic,install$1 as installConcurrent,install$4 as installCore,install as installJsx,install$2 as installSequence,isBackquoted,isQuoted,isSymbol,isUnquoted,lisp,lisp_async,quote,runScriptTags,splice,spread,wrapByUnquote};