text: (()=>{"use strict";var __webpack_modules__={829:(e,t,r)=>{r.d(t,{z:()=>Ye});var n=r(728),a=r(376);const s=e=>"bool"===e.t?e.v:"null"!==e.t;function o(e,t,r){const{exactArity:n,maxArity:s,minArity:o}=a.m3[e],i=(n,a)=>[{e:"Arity",m:`${e} needs ${n} argument${1!==a?"s":""}, not ${t}`,errCtx:r}];if(void 0!==n){if(t!==n)return i(`exactly ${n}`,n)}else{if(o&&!s&&t<o)return i(`at least ${o}`,o);if(!o&&s&&t>s)return i(`at most ${s}`,s);if(o&&s&&(t<o||t>s))return i(`between ${o} and ${s}`,s)}}function i(e,t,r,s=!1){const{params:o,numeric:i}=a.m3[e],u=(0,n.len)(t);if(i){const o=t.findIndex((e=>!!(0,n.len)(e)&&(s?!e.find((e=>"num"===e)):"num"!==e[0])));if(-1===o)return;const i=t[o].map((e=>a.O3[e])).join(", ");return[c(`${e} takes numeric arguments only, not ${i}`,r)]}if(!o)return;const l=o.map(((e,r)=>{if(r>=u||!t[r])return!1;const o=t[r];if((0,n.isArray)(e)){if(!(0,n.len)(e)||(s?!(0,n.len)(o)||o.some((t=>(0,n.has)(e,t))):1===(0,n.len)(o)&&(0,n.has)(e,o[0])))return!1;const t=o.map((e=>a.O3[e]));return`argument ${r+1} must be either: ${e.map((e=>a.O3[e])).join(", ")}, not ${t}`}{if(s?!(0,n.len)(o)||(0,n.has)(o,e):1===(0,n.len)(o)&&e===o[0])return!1;const t=o.map((e=>a.O3[e]));return`argument ${r+1} must be ${a.O3[e]}, not ${t}`}})).filter((e=>!!e));return(0,n.len)(l)?l.map((e=>c(e,r))):void 0}const c=(e,t)=>({e:"Type",m:e,errCtx:t});function u(e,t){const r=t.map((e=>a.O3[e])).join(", ");return[c(`number as operation argument must be string, vector, or dictionary, not ${r}`,e)]}function l(e,t){const r=t.map((e=>a.O3[e])).join(", ");return[c(`keyword as operation argument must be dictionary or vector, not ${r}`,e)]}const{has:d,flat:v,push:m,slice:p,splice:f}=n,{slen:y,starts:x,sub:h,substr:_,strIdx:b,subIdx:g}=n,{isNum:A,len:C,toNum:k}=n,O={t:"null",v:void 0},E={t:"bool",v:!1},w=e=>!!e&&"errCtx"in e,P=(e,t=0)=>{if(w(e))return"";const r=e[t];return w(r)&&d(["sym","str"],r.typ)&&r.text||""},$=e=>e.map((e=>w(e)?e.text:`(${$(e)})`)).join(" "),B=(e,t)=>w(e)?K(e,t):M(e,t);function M(e,t,r=!0){if(!C(e))return[];const n=e=>B(e,t);let s=e.shift(),i=n(s);const{errCtx:c}=i[0];if(w(s)&&"sym"===s.typ){if(s.text in a.m3){const{exactArity:t,minArity:r}=a.m3[s.text],n=t??r;n&&1!==n&&C(e)+1===n&&(e.unshift(s),s={typ:"sym",text:"@",errCtx:s.errCtx})}d(["var","let"],s.text)&&C(e)&&C(e)%2&&(e.unshift(s),e.push({typ:"sym",text:"%",errCtx:s.errCtx}),s={typ:"sym",text:"#",errCtx:s.errCtx});const{text:c,errCtx:u}=s,l=(e,t=u)=>[{typ:"err",value:e,errCtx:t}];if(d(["if","if!","when","match"],c)&&!C(e))return l("provide a condition");if(d(["if","if!"],c)){if(1===C(e))return l("provide at least one branch");if(C(e)>3)return l("provide fewer than two branches");const t=e.map(n),[r,a]=t;let s=t[2];return s||(s=[{typ:"val",value:O,errCtx:u}]),[...r,..."if!"===c&&[{typ:"val",value:{t:"func",v:"!"},errCtx:u},{typ:"exe",value:1,errCtx:u}]||[],{typ:"if",value:C(a)+1,errCtx:u},...a,{typ:"jmp",value:C(s),errCtx:u},...s]}if("when"===c){if(1===C(e))return l("provide a body");const t=e.map(n),[r,a]=[t[0],p(t,1)],s=v(a);return[...r,{typ:"if",value:C(s)+1,errCtx:u},...s,{typ:"jmp",value:1,errCtx:u},{typ:"val",value:O,errCtx:u}]}if("match"===c){const t=e.map(n),[r,a]=[t[0],p(t,1)],s=C(a)%2?a.pop():[];if(!C(a))return l("provide at least one case");const o=C(s);let i=a.reduce(((e,t)=>e+C(t)),0)+(o||2)+C(a);const c=r;for(;C(a)>1;){const[e,t]=[a.shift(),a.shift()];m(c,e),c.push({typ:"mat",value:C(t)+1,errCtx:u}),m(c,t),i-=C(e)+C(t)+2,c.push({typ:"jmp",value:i,errCtx:u})}return C(s)?m(c,s):(c.push({typ:"pop",value:1,errCtx:u}),c.push({typ:"val",value:E,errCtx:u})),c}if("catch"===c){if(C(e)<2)return l("provide at least 2 arguments");if(w(e[0]))return l("argument 1 must be expression");const t=n(e[0]),r=v(p(e,1).map(n));return[...t,{typ:"cat",value:C(r),errCtx:u},...r]}if("and"===c||"or"===c||"while"===c){const t=e.map(n);let r=t.reduce(((e,t)=>e+C(t)),0);if(C(t)<2)return l("provide at least 2 arguments");const a=[];if("while"===c){a.push({typ:"val",value:O,errCtx:u}),r+=2;const[e,n]=[t[0],p(t,1)];return m(a,e),a.push({typ:"if",value:r-C(e),errCtx:u}),a.push({typ:"pop",value:C(n),errCtx:u}),m(a,v(n)),a.push({typ:"loo",value:-(r+1),errCtx:u}),a}r+=C(t),r+=k("and"===c);const s="and"===c?"if":"or";for(let e=0;e<C(t);++e)m(a,t[e]),r-=C(t[e]),a.push({typ:s,value:r,errCtx:u}),--r;return"and"===c&&m(a,[{typ:"val",value:{t:"bool",v:!0},errCtx:u},{typ:"jmp",value:1,errCtx:u}]),a.push({typ:"val",value:E,errCtx:u}),a}if("var"===c||"let"===c){const r=e.filter(((e,t)=>!(t%2))),a=e.filter(((e,t)=>!!(t%2)));if(!C(r))return l("provide at least 1 declaration name and value");if(C(r)>C(a))return l("provide a value after each declaration name");const s=[];for(let e=0,o=C(r);e<o;++e){m(s,n(a[e]));const o=r[e];if(w(o)){const n=B(r[e],t);if(C(n)>1||"ref"!==n[0].typ)return l("declaration name must be symbol",n[0].errCtx);s.push({typ:c,value:n[0].value,errCtx:u})}else{const{shape:e,errors:t}=D([o],!0);if(C(t))return t;const r="var"===c?"dva":"dle";s.push({typ:r,value:e,errCtx:u})}}return s}if("var!"===c||"let!"===c){if(C(e)<2)return l("provide 1 declaration name and 1 function");const t=e.map(n),[r,a,s]=[t[0][0],t[1],p(t,2)];if("ref"!==r.typ)return l("declaration name must be symbol",r.errCtx);const o=[{typ:"ref",value:r.value,errCtx:u}];m(o,[...v(s),...a]),o.push({typ:"exe",value:C(s)+1,errCtx:u});const i="var!"===c?"var":"let";return o.push({typ:i,value:r.value,errCtx:u}),o}if("#"===c||"@"===c||"fn"===c){const r=[];let n=$(e);if(n="fn"===c?`(fn ${n})`:`${c}(${n})`,"fn"===c){const n=D(e,!1);if(t=n.shape,m(r,n.errors),!C(e))return l("provide a body");e.unshift({typ:"sym",text:"do",errCtx:u})}"@"===c&&(e=[{typ:"sym",text:"...",errCtx:u},...e,{typ:"sym",text:"args",errCtx:u}]),m(r,M(e,t,"@"!==c));const s=r.filter((e=>"err"!==e.typ)),o=r.filter((e=>"err"===e.typ));if(C(o))return o;"fn"===c&&s.forEach((e=>{"npa"===e.typ&&(e.typ="upa")}));const i=[],d=[];for(let e=0;e<C(s);++e){const t=s[e],r="val"===t.typ&&e+1<C(s)&&"exe"===s[e+1].typ&&("func"===t.value.t&&!a.m3[t.value.v]||"str"===t.value.t);d[e]="ref"===t.typ&&!s.find((e=>"let"===e.typ&&e.value===t.value))||"npa"===t.typ||r,d[e]&&i.push(t)}return[{typ:"@"===c?"par":"clo",value:{name:n,closureIns:s,captureIns:i,captured:d},errCtx:u}]}if(a.m3[c]&&r){const t=o(c,C(e),u),r=(e,t=u)=>[{typ:"err",value:e,errCtx:t}];m(i,t?.map((e=>r(e.m)[0]))??[]),t||2===C(e)&&a.m3[`fast${c}`]&&(i=n({typ:"sym",text:`fast${c}`,errCtx:u}))}}const u=e.map(n),l=v(u);if("return"===P([s]))return[...l,{typ:"ret",value:!!C(u),errCtx:c}];if("ref"===i[0].typ){const{value:e,errCtx:t}=i[0];i[0]={typ:"val",value:{t:"str",v:e},errCtx:t}}m(l,i);const f=C(i)>1?"exa":"exe";return[...l,{typ:f,value:C(u),errCtx:c}]}function K(e,t){if(w(e)){const{errCtx:r}=e;if("str"===e.typ)return[{typ:"val",value:{t:"str",v:e.text},errCtx:r}];if("num"===e.typ)return[{typ:"val",value:{t:"num",v:k(e.text)},errCtx:r}];if("sym"===e.typ){const{text:n}=e,s=t.map((({name:e})=>e));if("true"===n||"false"===n)return[{typ:"val",value:{t:"bool",v:"true"===n},errCtx:r}];if("null"===n)return[{typ:"val",value:O,errCtx:r}];if("_"===n)return[{typ:"val",value:{t:"wild",v:void 0},errCtx:r}];if(x(n,":"))return[{typ:"val",value:{t:"key",v:n},errCtx:r}];if(x(n,"%")&&A(_(n,1))){const e=k(_(n,1));return e<0?[{typ:"val",value:O,errCtx:r}]:[{typ:"upa",value:e,errCtx:r}]}if(d(s,n)){const e=t.find((({name:e})=>e===n));return 1===C(e.position)?[{typ:"npa",value:e.position[0],errCtx:r}]:[{typ:"dpa",value:e.position,errCtx:r}]}return"args"===n?[{typ:"upa",value:-1,errCtx:r}]:"PI"===n||"E"===n?[{typ:"val",value:{t:"num",v:"PI"===n?3.141592653589793:2.718281828459045},errCtx:r}]:a.m3[n]?[{typ:"val",value:{t:"func",v:n},errCtx:r}]:[{typ:"ref",value:n,errCtx:r}]}return[]}return C(e)?M(e,t):[]}function D(e,t,r=[]){const n=[],a=[];let s=0;for(;C(e)>(t?0:1)&&(w(e[0])||"vec"===P(e[0]));){const t=e.shift();if(w(t)){const{typ:e,errCtx:o}=t;"sym"===e?n.push({name:t.text,position:[...r,s]}):a.push({typ:"err",value:"provide parameter name",errCtx:o})}else{t.shift();const e=D(t,!0,[...r,s]);m(n,e.shape),m(a,e.errors)}++s}return{shape:n,errors:a}}function I({name:e,nodes:t}){const{shape:r,errors:n}=D(t,!1),a=[...n,...v(t.map((e=>K(e,r))))];for(let e=0,t=C(a);e<t;e++){const{typ:t,value:r,errCtx:n}=a[e];if("err"===t)return{e:"Parse",m:r,errCtx:n}}return{name:e,ins:a}}function T(e){const t=[];for(let r=0,n=C(e);r<n;++r){const n=e[r];switch(n.typ){case"val":t.push({types:[n.value.t],val:n.value});break;case"exa":case"exe":{const e=t.pop(),r=f(t,C(t)-n.value,n.value),s=e=>r.findIndex((({types:t})=>t&&!e.find((e=>d(t,e))))),o=t=>e.val?e.val.t===t:e.types&&1===C(e.types)&&e.types[0]===t;if(e.val&&"func"===e.val.t){if("recur"===e.val.v){f(t,C(t)-n.value,n.value);break}const s=i(e.val.v,r.map((e=>e.types??[])),n.errCtx,!0);if(s)return s;const{returns:o,numeric:c}=a.m3[e.val.v];t.push(c&&"in only"!==c?{types:["num"]}:{types:o})}else if(o("num")){const e=s(["str","dict","vec"]);if(-1!==e)return u(n.errCtx,r[e].types);t.push({})}else if(o("key")){const e=s(["dict","vec"]);if(-1!==e)return l(n.errCtx,r[e].types);t.push({})}else o("str")||o("bool")?t.push({}):e.types||e.val||t.push({});break}case"or":t.pop(),t.push({}),r+=n.value;break;case"cat":case"var":case"let":case"dva":case"dle":case"loo":case"jmp":break;case"clo":case"par":{const e=T(n.value.closureIns);if(e)return e}case"ref":case"npa":case"upa":case"dpa":t.push({});break;case"if":{t.pop(),t.push({});const a=T(p(e,r+1,n.value+1));if(a)return a;r+=n.value-1;break}case"mat":t.pop(),t.pop(),r+=n.value,r+=e[r].value,t.push({});break;case"pop":f(t,C(t)-n.value,n.value);break;case"ret":n.value&&t.pop();break;default:(0,a.UT)(n)}}}function j(e,t){const{tokens:r,stringError:n}=function(e,t,r=!0,n=!1){const a=[],s=e=>h("0123456789",e);let[o,i,c,u]=[!1,1,0,[1,0]],[l,d,v]=[!1,!1,!1];for(let m=0,p=y(e);m<p;++m){const f=b(e,m),x=m+1!==p?b(e,m+1):"";if(++c,"\\"===f&&o){a[C(a)-1].text+={n:"\n",t:"\t",r:"\r",'"':'"'}[x]||("\\"===x?"\\":`\\${x}`),++c,++m;continue}const A={invokeId:t,line:i,col:c};if('"'===f){(o=!o)&&(u=[i,c],a.push({typ:"str",text:"",errCtx:A})),d=l=!1;continue}const k=h(" \t\n\r,",f);if(!o&&k){d=l=!1,"\n"===f&&(++i,c=0);continue}if(!o&&";"===f){const t=g(_(e,++m),"\n"),r=_(e,m,t>0?t:p-m);m+=y(r),++i,c=0,n&&a.push({typ:"rem",text:r,errCtx:A});continue}const O=h("()[]{}",f);if(d&&!s(f)){const e="x"===f&&"0"===a[C(a)-1].text;v=v||e,d="b"===f&&"0"===a[C(a)-1].text||"."===f&&!h(a[C(a)-1].text,".")||v&&(e||h("ABCDEFabcdef",f)),d||O||k||(l=!0,a[C(a)-1].typ="sym")}if(l&&O&&(l=!1),!o&&!l&&!d){if(O){const e=-1===g("[{(",f)?")":"(";a.push({typ:e,text:r?e:f,errCtx:A}),!r||"["!==f&&"{"!==f||a.push({typ:"sym",text:"["===f?"vec":"dict",errCtx:A});continue}d=s(f)||"."===f&&s(x)||"-"===f&&(s(x)||"."===x),v=l=!d;const e=l?"sym":"num";a.push({typ:e,text:"",errCtx:A})}a[C(a)-1].text+=f}return{tokens:a,stringError:o?u:void 0}}(e,t),a=function(e,t){const r=C(t)?t[0].errCtx.invokeId:"",n=[],a=(e,t)=>n.push({e:"Parse",m:e,errCtx:t});if(e){const[t,s]=e;return a("unmatched double quotation marks",{invokeId:r,line:t,col:s}),n}const s=e=>C(t.filter((({typ:t})=>t===e))),[o,i]=[s("("),s(")")];{const[e,n]=function(e,t,r){const n=r>=t,[a,s]=[n?"(":")",n?")":"("],o=n?1:-1;for(let t=C(e),r=n?0:t-1,i=0;n?r<t:r>=0;r+=o){const{typ:t,errCtx:{line:n,col:o}}=e[r];if(i+=k(t===a)-k(t===s),i<0)return[n,o]}return[0,0]}(t,o,i);e+n&&a("unmatched parenthesis",{invokeId:r,line:e,col:n})}let c;for(let e=0,r=!1;e<C(t);++e){if(r&&")"===t[e].typ){c=t[e];break}r="("===t[e].typ}return c&&a("empty expression forbidden",c.errCtx),n}(n,r);if(C(a))return{errors:a,funcs:{}};const s=[],o=[],i=function(e){const t=[],r=e=>{let t;"sym"===e[0].typ&&h("@#",e[0].text)&&(t=e.shift());const n=e.shift();if("("!==n.typ&&")"!==n.typ)return n;const a=t?[t]:[];for(;")"!==e[0].typ;)a.push(r(e));return e.shift(),a};for(;C(e);)t.push(r(e));return t}(p(r)),c=function(e){const t=[],r=[];return e.forEach((e=>{if(!w(e)&&w(e[0])&&"function"===P(e)){const r=P(e,1);r?C(e)<3&&t.push({err:"empty function body",errCtx:e[0].errCtx}):t.push({err:"nameless function",errCtx:e[0].errCtx}),t.push({name:r,nodes:p(e,2)})}else r.push(e)})),C(r)&&t.push({name:"entry",nodes:r}),t}(i),u=[];c.forEach((e=>{"err"in e?o.push({e:"Parse",m:e.err,errCtx:e.errCtx}):u.push({name:e.name,nodes:e.nodes})})),u.map(I).forEach((e=>{"e"in e?o.push(e):s.push(e)})),m(o,v(s.map((e=>T(e.ins)??[]))));const l={};return s.forEach((e=>l[e.name??""]=e)),{errors:o,funcs:l}}function L(e,t){return e.dict.has(t)?{kind:"val",value:e.dict.get(t)}:{kind:"err",err:`"${t}" not found.`}}function R(e,t,r){e.dict.set(t,r)}function U(e,t,r){return"test.function"!==t?{kind:"err",err:`operation "${t}" does not exist`}:(e.output+=r[0].v+"\n",{kind:"val",value:{t:"null",v:void 0}})}const q=[{name:"Hello, world!",code:'"Hello, world!"',out:"Hello, world!"},{name:"Say Hello, world!",code:'(print "Hello, world!")',out:"Hello, world!\nnull"},{name:"1 + 1 = 2",code:"(+ 1 1)",out:"2"},{name:"Negate 1 = -1",code:"(- 1)",out:"-1"},{name:"(1+1)+1+(1+1) = 5",code:"(+ (+ 1 1) 1 (+ 1 1))",out:"5"},{name:"Conditional head",code:"((if true + -) 12 9 1)",out:"22"},{name:"Whens",code:'[(when 123 (print "hi") 234) (when false (print "bye"))]',out:"hi\n[234 null]"},{name:"match and wildcard",code:'(match [1 2]\n             [0 0] (print "hello")\n             [0 2] (print "bye")\n             [1 _] "hey")',out:"hey"},{name:"Cond number head",code:"((if false 1 2) [:a :b :c])",out:":c"},{name:"and & short-circuit",code:'[(and true (if true null 1) (print "hi")) (and 1 2 3)]',out:"[false true]"},{name:"or & short-circuit",code:'[(or true (print "hi") 1) (or false (print-str "-> ") 1)]',out:"-> [true 1]"},{name:"String retrieve",code:'(2 "Hello")',out:"l"},{name:"Vector retrieve",code:"(2 [:a :b :c :d])",out:":c"},{name:"Key as operation",code:'[(:age {:name "Patrick" :age 24}) (:abc [:a :abc :c])]',out:"[24 :abc]"},{name:"Dictionary as op 1",code:'({"name" "Patrick" "age" 24} "age")',out:"24"},{name:"Dictionary as op 2",code:'({"name" "Patrick"} "age" 24)',out:'{"name" "Patrick", "age" 24}'},{name:"Equalities",code:'[(= 1 2 1)\n            (!= 1 2 1)\n            (= "Hello" "hello")\n            (!= "world" "world")\n            (= [0 [1]] [0 [1]])]',out:"[false 1 false false [0 [1]]]"},{name:"Define and retrieve",code:"(var a 1) a",out:"1"},{name:"Define and add",code:"(var a 1) (inc a)",out:"2"},{name:"Define op and call",code:"(var f +) (f 2 2)",out:"4"},{name:"Define vec and call",code:"(var f [1]) (f 1)",out:"1"},{name:"Define num and call",code:"(var f 1) (f [:a :b :c])",out:":b"},{name:"Apply op to var",code:"(var a 10) (var! a + 10)",out:"20"},{name:"Apply op to let",code:"(let a 10) (let! a (if true + -) (+ 2 3) 5)",out:"20"},{name:"Print simple vector",code:"[1 2 3]",out:"[1 2 3]"},{name:"Boolean select",code:"[(true 1 2) (false 1)]",out:"[1 null]"},{name:"Sum vector of numbers",code:"[(reduce + [1 2 3]) (reduce + 3 [1 2 3])]",out:"[6 9]"},{name:"Sum vectors of numbers",code:"(map + [1 2 3] [1 2 3 4])",out:"[2 4 6]"},{name:"Filter by integer",code:'(filter 2 [[1] [:a :b :c] "hello" "hi"])',out:'[[:a :b :c] "hello"]'},{name:"Comments, short decimal",code:';((print "Hello")\n           .456',out:"0.456"},{name:"Dictionary into vector",code:"(into [1 2] {3 4 5 6})",out:"[1 2 [3 4] [5 6]]"},{name:"Vector into dictionary",code:"(into {[0] 1 [2] 3} [[0] 2])",out:"{[0] 2, [2] 3}"},{name:"While loop",code:"(var n 5)\n           (while (< 0 n)\n             (print-str n)\n             (var n (dec n)))",out:"543210"},{name:"Catch error",code:'(catch\n             (:e (catch (do (let a :a) (+ 1 a)) (0 errors)))\n             (print "hi"))',out:"Type"},{name:"Define with no call",code:'(function func (print "Nothing."))'},{name:"Call greet func",code:'(function greeting (print "Hello!")) (greeting)',out:"Hello!\nnull"},{name:"Call const value func",code:"(function const 123) (const)",out:"123"},{name:"Call identity funcs",code:"(function id1 %)\n           (function id2 x x)\n           [(id1 123) (id2 456)]",out:"[123 456]"},{name:"Call greet with name",code:'(function greeting name (print "Hello, " name "!"))\n           (greeting "Patrick")',out:"Hello, Patrick!\nnull"},{name:"Call with too few args",code:"(function func a b c [a b c]) (func 1 2)",out:"[1 2 null]"},{name:"Define func and call",code:"(function func a b (+ a b)) (var f func) (f 2 2)",out:"4"},{name:"Anonymous parameters",code:"(function avg<n? (< (/ (.. + %) (len %)) %1))\n           (avg<n? [0 10 20 30 40] 5)",out:"false"},{name:"Call parameter",code:'(function f x (x "hello")) (f print)',out:"hello\nnull"},{name:"Let and retrieve",code:"(function f (let a 1) a) (f)",out:"1"},{name:"Let num op and call",code:"(function f (let n 0) (n [1])) (f)",out:"1"},{name:"Explicit return",code:"(function f (return 123) (print 456)) (f)",out:"123"},{name:"Closure 1",code:"(let x 10)\n           (let closure #(+ x x))\n           (let x 11)\n           (closure)",out:"20"},{name:"Closure 2",code:"(filter #(or (.. = args) (even? %)) (range 10) 5)",out:"[0 2 4 5 6 8]"},{name:"Closure 3",code:"(function f #(+ x x))\n           (var x 10) (let c20 (f))\n           (var x 20) (let c40 (f))\n           [(c20) (c40)]",out:"[20 40]"},{name:"Func returns closure",code:"(function f x #(x 2 2))\n           (let closure (f +))\n           (closure)",out:"4"},{name:"Dictionary closure",code:"(function f x #{x 2})\n           (let closure (f :a))\n           (closure)",out:"{:a 2}"},{name:"Vector closure",code:"(function f x #[1 x %])\n           (let closure (f 2))\n           (closure 3)",out:"[1 2 3]"},{name:"Closure as head",code:"(#[% %1 %2] 1 2 3)",out:"[1 2 3]"},{name:"Partial closure 1",code:"(@[] 1 2 3)",out:"[1 2 3]"},{name:"Partial closure 2",code:"(@((do +) 2) 2)",out:"4"},{name:"Parameterised closure 1",code:"((fn a b (+ a b)) 2 2)",out:"4"},{name:"Parameterised closure 2",code:"((fn a b (print-str a b) (+ a b)) 2 2)",out:"224"},{name:"Closure with mixed lets",code:"(let a + c 5 d 10)\n           (let closure (fn b (let d 1) (a b c d)))\n           (let a - c 4 d 11)\n           (closure 1)",out:"7"},{name:"Destructure var",code:"(var [x [y]] [1 [2]]) [y x]",out:"[2 1]"},{name:"Destructure string",code:'(let [a b c] "hello") [a b c]',out:'["h" "e" "l"]'},{name:"Destructure function",code:"(function f a [[b c] d] e [e d c b a]) (f 0 [[1 2] 3] 4)",out:"[4 3 2 1 0]"},{name:"Destructuring closure",code:"(let f (fn a [b [c]] d [d c b a])) (f 0 [1 [2]] 3)",out:"[3 2 1 0]"},{name:"Destructuring fn decoy",code:"(let f (fn a [a [a]])) (f 0)",out:"[0 [0]]"},{name:"Threading",code:"(-> 1 inc @(+ 10))",out:"12"},{name:"String instead of number",code:'(function sum (.. + args))\n           (print (sum 2 2))\n           (sum 2 "hi")',out:"4",err:["Type"]},{name:"Reference non-existing",code:"x",err:["Reference"]},{name:"Expired let retrieve",code:"(function f (let a 1) a) (f) a",err:["Reference"]},{name:"Call non-existing",code:"(x)",err:["External"]},{name:"Call budget",code:"(function f (f)) (f)",err:["Budget"]},{name:"Loop budget",code:"(var n 10000)\n           (while (< 0 n)\n             (var n (dec n)))",err:["Budget"]},{name:"Range budget",code:"(range 10000)",err:["Budget"]},{name:"Head exe arity check",code:"(((fn +)) 1)",err:["Arity"]},{name:"Fibonacci 13",code:"(function fib n\n             (if (< n 2) n\n               (+ (fib (dec n))\n                  (fib (- n 2)))))\n           (fib 13)",out:"233"},{name:"dedupe (recur)",code:"(function dedupe list -out\n             (let out (or -out []))\n             (let next (if (out (0 list)) [] [(0 list)]))\n             (if (empty? list) out\n                 (recur (sect list) (into out next))))\n           (dedupe [1 1 2 3 3 3])",out:"[1 2 3]"},{name:"frequencies",code:'(function frequencies list\n             (reduce #(push % %1 (inc (or (% %1) 0))) {} list))\n           (frequencies "12121212")',out:'{"1" 4, "2" 4}'},{name:"set get",code:"[($globals.time_offset 5.5) $globals.time_offset]",out:"[5.5 5.5]"},{name:"exe",code:"(test.function 123)",out:"123\nnull"},{name:"Empty parens",code:"()",err:["Parse"]},{name:"Imbalanced parens 1",code:'(print ("hello!")',err:["Parse"]},{name:"Imbalanced parens 2",code:'print "hello!")',err:["Parse"]},{name:"Imbalanced quotes",code:'(print "Hello)',err:["Parse"]},{name:"Function as op",code:"(function)",err:["Parse"]},{name:"Function without name",code:"(function (+))",err:["Parse"]},{name:"Function without body",code:"(function func)",err:["Parse"]},{name:"Variable not symbol",code:"(var 1 2)",err:["Parse"]},{name:"Parser type error 1",code:"(function f (+ 1 :a))",err:["Type"]},{name:"Parser type error 2",code:"(function f (+ 1 (into {} {})))",err:["Type"]},{name:"Parser type error 3",code:"(function f (if true (into 2 {}) (+ 2 2)))",err:["Type"]},{name:"Parser arity error 1",code:"(abs)",err:["Parse"]}];var W=r(183);const{abs:S,cos:N,sin:H,tan:V,sign:z,sqrt:F,floor:X,ceil:J,round:G,max:Q,min:Y}=n,{logn:Z,log2:ee,log10:te}=n,{concat:re,has:ne,flat:ae,push:se,reverse:oe,slice:ie,splice:ce,sortBy:ue}=n,{ends:le,slen:de,starts:ve,sub:me,subIdx:pe,substr:fe,upperCase:ye,lowerCase:xe}=n,{trim:he,trimStart:_e,trimEnd:be,charCode:ge,codeChar:Ae,strIdx:Ce}=n,{getTimeMs:ke,randInt:Oe,randNum:Ee}=n,{isNum:we,len:Pe,objKeys:$e,range:Be,toNum:Me}=n,Ke={};let De,Ie=[],Te=[];const je=e=>Ie.push({t:"bool",v:e}),Le=e=>Ie.push({t:"num",v:e}),Re=(e="")=>Ie.push({t:"str",v:e}),Ue=(e=[])=>Ie.push({t:"vec",v:e}),qe=e=>Ie.push({t:"dict",v:e}),We=()=>Ie.push({t:"null",v:void 0}),Se=e=>Ie.push({t:"func",v:e});const Ne=(e,t)=>[{e:"Arity",m:`${a.O3[e]} as op requires one sole argument`,errCtx:t}];function He(e,t,r,d=!0){if("str"===t.t||"func"===t.t){const u=t.v;return a.m3[u]?a.m3[u].external?e=>{const t=Ke[u](e);if("err"===t.kind)return[{e:"External",m:t.err,errCtx:r}];Ie.push(t.value)}:t=>function(e,t,r,u,l){const d=e=>[c(e,u)];if(l){const r=o(e,Pe(t),u);if(r)return r}{const r=i(e,t.map((e=>[e.t])),u);if(r)return r}switch(e){case"str":return void Ie.push({t:"str",v:(0,W.Pz)(t)});case"print":case"print-str":return r.print((0,W.Pz)(t),"print"===e),void We();case"vec":return void Ue(t);case"dict":return void Ie.push((0,W.gu)(t));case"len":return void Le("str"===t[0].t?de(t[0].v):"vec"===t[0].t?Pe(t[0].v):Pe((0,W.Ay)(t[0]).keys));case"to-num":return void(we(t[0].v)?Le(Me(t[0].v)):We());case"to-key":return void Ie.push({t:"key",v:`:${(0,W.aP)(t[0])}`});case"!":return void je(!s(t[0]));case"=":case"!=":for(let r=1,n=Pe(t);r<n;++r)if((0,W.Xy)(t[r-1],t[r])!==("="===e))return void je(!1);return void Ie.push(t[0]);case"-":return void Le(1===Pe(t)?-(0,W.OK)(t[0]):t.map(W.OK).reduce(((e,t)=>e-t)));case"**":return void Le((0,W.OK)(t[0])**(1===Pe(t)?2:(0,W.OK)(t[1])));case"+":return void Le(t.map(W.OK).reduce(((e,t)=>e+t)));case"*":return void Le(t.map(W.OK).reduce(((e,t)=>e*t)));case"/":return void Le(t.map(W.OK).reduce(((e,t)=>e/t)));case"//":return void Le(t.map(W.OK).reduce(((e,t)=>X(e/t))));case"fast=":case"fast!=":return(0,W.Xy)(t[0],t[1])!==("fast="===e)?void je(!1):void Ie.push(t[0]);case"fast-":return void Le(t[0].v-t[1].v);case"fast+":return void Le(t[0].v+t[1].v);case"fast*":return void Le(t[0].v*t[1].v);case"fast/":return void Le(t[0].v/t[1].v);case"fast//":return void Le(X(t[0].v/t[1].v));case"fast<":return void je(t[0].v<t[1].v);case"fast>":return void je(t[0].v>t[1].v);case"fast<=":return void je(t[0].v<=t[1].v);case"fast>=":return void je(t[0].v>=t[1].v);case"rem":return void Le(t.map(W.OK).reduce(((e,t)=>e%t)));case"min":return void Le(t.map(W.OK).reduce(((e,t)=>Y(e,t))));case"max":return void Le(t.map(W.OK).reduce(((e,t)=>Q(e,t))));case"<":case">":case"<=":case">=":for(let r=1,n=Pe(t);r<n;++r){const[n,a]=[t[r-1].v,t[r].v];if("<"===e&&n>=a||">"===e&&n<=a||"<="===e&&n>a||">="===e&&n<a)return void je(!1)}return void je(!0);case"inc":return void Le(t[0].v+1);case"dec":return void Le(t[0].v-1);case"abs":return void Le(S(t[0].v));case"round":if(2===Pe(t)){const e=10**t[0].v;Le(G(t[1].v*e)/e)}else Le(G(t[0].v));return;case"sin":case"cos":case"tan":case"sqrt":case"floor":case"ceil":case"logn":case"log2":case"log10":return void Le((0,{sin:H,cos:N,tan:V,sqrt:F,floor:X,ceil:J,logn:Z,log2:ee,log10:te}[e])((0,W.OK)(t[0])));case"and":return void je(t.every(s));case"or":return void je(t.some(s));case"xor":return void(s(t[0])!==s(t[1])?Ie.push(s(t[0])?t[0]:t[1]):je(!1));case"&":case"|":case"^":case"<<":case">>":case">>>":const[o,i]=[(0,W.OK)(t[0]),(0,W.OK)(t[1])];return void Le("&"===e?o&i:"|"===e?o|i:"^"===e?o^i:"<<"===e?o<<i:">>"===e?o>>i:o>>>i);case"~":return void Le(~(0,W.OK)(t[0]));case"odd?":case"even?":return void je((0,W.OK)(t[0])%2==("odd?"===e?1:0));case"pos?":case"neg?":case"zero?":{const r=(0,W.OK)(t[0]);return void je("pos?"===e?r>0:"neg?"===e?r<0:!r)}case"null?":case"num?":case"bool?":case"str?":case"dict?":case"vec?":case"key?":case"func?":case"wild?":case"ext?":{const{t:r}=t[0];return void je("func?"===e&&("func"===r||"clo"===r)||fe(e,0,de(e)-1)===r)}case"has?":return void je(me((0,W.Bd)(t[0]),(0,W.Bd)(t[1])));case"idx":{let e=-1;if("str"===t[0].t){if("str"!==t[1].t)return d("strings can only contain strings");if(!(Pe(t)<3)){const e=t[0].v.split("");return e[(0,W.OK)(t[2])]=t[1].v,void Re(e.join(""))}e=pe(t[0].v,t[1].v)}else if("vec"===t[0].t){if(!(Pe(t)<3)){const e=ie(t[0].v);return e[(0,W.OK)(t[2])]=t[1],void Ue(e)}e=t[0].v.findIndex((e=>(0,W.Xy)(e,t[1])))}return void(-1===e?We():Le(e))}case"map":case"for":case"reduce":case"filter":case"remove":case"find":case"count":{const n=He(r,t.shift(),u);if("map"===e||"for"===e){const e=t.findIndex((({t:e})=>"vec"!==e&&"str"!==e&&"dict"!==e));if(-1!==e)return d(`argument ${e+2} must be either: string, vector, dictionary, not ${a.O3[t[e].t]}`)}if("for"===e){const e=t.map(W._2),a=e.map(Pe),s=a.map(((e,t)=>ie(a,0,t+1).reduce(((e,t)=>e*t))));s.unshift(1);const o=s.pop();if(o>r.loopBudget)return[{e:"Budget",m:"would exceed loop budget",errCtx:u}];const i=[];for(let t=0;t<o;++t){const r=s.map(((e,r)=>X(t/e%a[r]))),o=n(e.map(((e,t)=>e[r[t]])));if(o)return o;i.push(Ie.pop())}return void Ue(i)}if("map"===e){const e=t.map(W._2),r=Y(...e.map(Pe)),a=[];for(let t=0;t<r;++t){const r=n(e.map((e=>e[t])));if(r)return r;a.push(Ie.pop())}return void Ue(a)}if("reduce"!==e){const r=t.shift(),a=(0,W._2)(r),o="remove"===e,i="find"===e,c="count"===e,u=[];let l=0;for(let e=0,r=Pe(a);e<r;++e){const r=n([a[e],...t]);if(r)return r;const d=s(Ie.pop());if(c)l+=d?1:0;else if(i){if(d)return void Ie.push(a[e])}else d!==o&&u.push(a[e])}switch(e){case"count":return void Le(l);case"find":return void We()}return void("str"===r.t?Re(u.map((e=>(0,W.aP)(e))).join("")):"dict"===r.t?Ie.push((0,W.gu)(ae(u.map((e=>e.v))))):Ue(u))}const o=t.pop();if(!ne(["vec","dict","str"],o.t))return d(`must reduce either: string, vector, dictionary, not ${a.O3[o.t]}`);const i=(0,W._2)(o);if(!Pe(i))return void(Pe(t)?Ie.push(t[0]):Ue());if(Pe(i)<2&&!Pe(t))return void se(Ie,i);let c=(Pe(t)?t:i).shift();for(let e=0,t=Pe(i);e<t;++e){const t=n([c,i[e]]);if(t)return t;c=Ie.pop()}return void Ie.push(c)}case"repeat":{const e=t.shift(),n=[],a=(0,W.OK)(t[0]);if(a>r.rangeBudget)return[{e:"Budget",m:"would exceed range budget",errCtx:u}];if(r.rangeBudget-=a,"func"===e.t||"clo"===e.t){const t=He(r,e,u);for(let e=0;e<a;++e){const r=t([{t:"num",v:e}]);if(r)return r;n.push(Ie.pop())}}else for(let t=0;t<a;++t)n.push(e);return void Ue(n)}case"->":Ie.push(t.shift());for(let e=0,n=Pe(t);e<n;++e){const n=He(r,t[e],u)([Ie.pop()]);if(n)return n}return;case"rand-int":case"rand":{const r=Pe(t),[n,a]=[r<2?0:(0,W.OK)(t[0]),0===r?1+Me("rand-int"===e):1===r?(0,W.OK)(t[0]):(0,W.OK)(t[1])];Le("rand-int"===e?Oe(n,a):Ee(n,a))}return;case"do":case"val":return void Ie.push("do"===e?t.pop():t.shift());case".":case"..":case"...":{const n=He(r,t.shift(),u);if("."===e)return n(t);let a=t;if(".."===e)a=ae(t.map((e=>"vec"===e.t?e.v:[e])));else{const e=a.pop();se(a,ae(["vec"===e.t?e.v:[e]]))}return n(a)}case"into":if("vec"===t[0].t)Ue(re(t[0].v,(0,W._2)(t[1])));else if("vec"===t[1].t)Ie.push((0,W.gu)(re(ae((0,W._2)(t[0]).map(W.Bh)),t[1].v)));else{const{keys:e,vals:r}=(0,W.Ay)(t[0]),n=(0,W.Ay)(t[1]);qe({keys:re(e,n.keys),vals:re(r,n.vals)})}return;case"push":if("vec"===t[0].t){const e=t[0].v;if(Pe(t)<3)Ue(re(e,[t[1]]));else{const r=(0,W.OK)(t[2]);Ue(re(re(ie(e,0,r),[t[1]]),ie(e,r)))}}else Pe(t)<3?Ie.push((0,W.uv)((0,W.Ay)(t[0]),t[1])):qe((0,W.bd)((0,W.Ay)(t[0]),t[1],t[2]));return;case"sect":{const e=t[0],r="vec"===e.t?Pe(e.v):de((0,W.Bd)(e));let n=0,a=r;switch(Pe(t)){case 1:n=1;break;case 2:{const e=(0,W.OK)(t[1]);e<0?a+=e:n+=e;break}case 3:{const e=(0,W.OK)(t[1]),s=(0,W.OK)(t[2]);n=e<0?r+e+(s<0?s:0):n+e,a=(s<0?a:n)+s;break}}return n=Q(n,0),a=Y(a,r),n>a?void("vec"===e.t?Ue:Re)():void("vec"===e.t?Ue(ie(e.v,n,a)):Re(fe((0,W.Bd)(t[0]),n,a-n)))}case"reverse":return void("str"===t[0].t?Re((0,W.Pz)(oe((0,W._2)(t[0])))):Ue(oe((0,W._2)(t[0]))));case"sort":{const e=(0,W._2)(t[0]);if(!Pe(e))return void Ue();const n=[];if(1===Pe(t))se(n,e.map((e=>[e,e])));else{const a=He(r,t.pop(),u);for(let t=0,r=Pe(e);t<r;++t){const r=a([e[t]]);if(r)return r;n.push([e[t],Ie.pop()])}}const a=n[0][1].t;return n.some((([e,{t}])=>t!==a||!ne(["num","str"],t)))?d("can only sort by all number or all string"):("num"===n[0][1].t?ue(n,(([e,t],[r,n])=>(0,W.OK)(t)>(0,W.OK)(n)?1:-1)):ue(n,(([e,t],[r,n])=>(0,W.Bd)(t)>(0,W.Bd)(n)?1:-1)),void Ue(n.map((([e])=>e))))}case"range":{const[e,n,a]=t.map(W.OK),s=a&&a<0&&e<n,[o,i]=Pe(t)>1?s?[n-1,e-1]:[e,n]:[0,e],c=z((i-o)*(a||1))*(a||1),l=J(S((i-o)/c));if(!l)return void Ue([]);if(l>r.rangeBudget)return[{e:"Budget",m:"would exceed range budget",errCtx:u}];r.rangeBudget-=l;const d=Be(l).map((e=>e*c+o));return void Ue(d.map((e=>({t:"num",v:e}))))}case"empty?":return void je(!Pe((0,W._2)(t[0])));case"keys":case"vals":return void Ue((0,W.Ay)(t[0])["keys"===e?"keys":"vals"]);case"split":return void Ue((0,W.Bd)(t[Pe(t)-1]).split(Pe(t)-1?(0,W.Bd)(t[0]):" ").map((e=>({t:"str",v:e}))));case"join":return void Re((0,W._2)(t[1]).map(W.aP).join((0,W.Bd)(t[0])));case"starts?":case"ends?":return void je(("starts?"===e?ve:le)((0,W.Bd)(t[1]),(0,W.Bd)(t[0])));case"upper-case":case"lower-case":case"trim":case"trim-start":case"trim-end":return void Re(("upper-case"===e?ye:"lower-case"===e?xe:"trim"===e?he:"trim-start"===e?_e:be)((0,W.Bd)(t[0])));case"str*":{const e=(0,W.Bd)(t[0]);return void Re(Be(Q(J((0,W.OK)(t[1])),0)).map((t=>e)).join(""))}case"char-code":if("str"===t[0].t){const e=Pe(t)>1?(0,W.OK)(t[1]):0,r=(0,W.Bd)(t[0]);de(r)<=e||e<0?We():Le(ge(Ce(r,e)))}else Re(Ae((0,W.OK)(t[0])));return;case"time":return void Le(ke());case"version":return void Le(20220103);case"tests":return void Re(function(e,t=!0){const r=[];for(let t=0;t<(0,n.len)(q);++t){const{name:a,code:s,err:o,out:i}=q[t],c={dict:new Map,output:""},u={funcs:{},vars:{}},l=(0,n.getTimeMs)(),d=e({get:e=>L(c,e),set:(e,t)=>R(c,e,t),print:(e,t)=>{c.output+=e+(t?"\n":"")},exe:(e,t)=>U(c,e,t),functions:[],env:u,loopBudget:1e4,rangeBudget:1e3,callBudget:1e3,recurBudget:1e4},s,s,!0),v="errors"===d.kind?d.errors:[],m=(o||[]).join()===v.map((({e})=>e)).join(),p=!i||(0,n.trim)(c.output)===i,f=(0,n.getTimeMs)()-l,[y,x,h,_,b]=[(0,n.padEnd)(`${t+1}`,3),(0,n.padEnd)(a,24),(0,n.padEnd)(`${f}ms`,6),p||i+"\t!=\t"+(0,n.trim)(c.output),m||v.map((({e,m:t,errCtx:{line:r,col:n}})=>`${e} ${r}:${n}: ${t}`))];r.push({okErr:m,okOut:p,elapsedMs:f,display:`${y} ${x} ${h} ${_} ${b}`})}const a=r.reduce(((e,{elapsedMs:t})=>e+t),0),s=(0,n.len)(r.filter((({okOut:e,okErr:t})=>e&&t)));return(0,n.concat)(r.filter((e=>!t||!e.okOut||!e.okErr)).map((e=>e.display)),[`---- ${s}/${(0,n.len)(r)} tests passed in ${a}ms.`])}(Je,!(Pe(t)&&s(t[0]))).join("\n"));case"symbols":return void Ue(function(e,t=!0){let r=t?["function","let","var","if","if!","when","while","match","catch"]:[];se(r,["args","PI","E"]),r=re(r,$e(a.m3)),r=re(r,$e(e.env.funcs)),r=re(r,$e(e.env.vars));const n=["entry"];return r=r.filter((e=>!ne(n,e))),ue(r,((e,t)=>e>t?1:-1))}(r,!1).map((e=>({t:"str",v:e}))));case"eval":{delete r.env.funcs.entry;const e=Pe(Ie),n=`${u.invokeId} eval`,a=Xe(r,(0,W.Bd)(t[0]),n);return a?[{e:"Eval",m:"error within evaluated code",errCtx:u},...a]:void(e===Pe(Ie)&&We())}case"recur":return void(De=t);case"reset":return r.env.vars={},r.env.funcs={},Te=[],void We()}return[{e:"Unexpected",m:"operation doesn't exist",errCtx:u}]}(u,t,e,r,d):u in e.env.funcs?t=>Fe(e,e.env.funcs[u],t):u in e.env.vars?He(e,e.env.vars[u],r):u in Te[Pe(Te)-1]?He(e,Te[Pe(Te)-1][u],r):ve(u,"$")?n=>{if(!Pe(n))return Ne(t.t,r);const a=e.set(fe(u,1),n[0]);return Ie.push(n[0]),a?[{e:"External",m:a,errCtx:r}]:void 0}:t=>{const n=e.exe(u,t);if("val"!==n.kind)return[{e:"External",m:n.err,errCtx:r}];Ie.push(n.value)}}if("clo"===t.t)return r=>Fe(e,t.v,r);if("key"===t.t)return e=>{if(!Pe(e))return Ne(t.t,r);if("dict"===e[0].t)Ie.push((0,W.k1)((0,W.Ay)(e[0]),t));else{if("vec"!==e[0].t)return l(r,[e[0].t]);{const r=(0,W.Bh)(e[0]).find((e=>(0,W.Xy)(e,t)));Ie.push(r??{t:"null",v:void 0})}}};if("num"===t.t){const e=X(t.v);return n=>{if(!Pe(n))return Ne(t.t,r);const a=n[0];if("str"!==a.t&&"vec"!==a.t&&"dict"!==a.t)return u(r,[a.t]);const s=(0,W._2)(a),o=Pe(s);e>=0&&e>=o||e<0&&-e>o?We():e<0?Ie.push(s[o+e]):Ie.push(s[e])}}if("vec"===t.t){const{v:e}=t;return n=>{if(!Pe(n))return Ne(t.t,r);const a=e.find((e=>(0,W.Xy)(e,n[0])));a?Ie.push(a):We()}}if("dict"===t.t){const e=t.v;return t=>{if(1===Pe(t))Ie.push((0,W.k1)(e,t[0]));else{if(2!==Pe(t))return[{e:"Arity",m:"provide 1 or 2 arguments for dictionary",errCtx:r}];qe((0,W.bd)(e,t[0],t[1]))}}}if("bool"===t.t){const e=t.v;return t=>{if(!Pe(t)||Pe(t)>2)return[{e:"Arity",m:"provide 1 or 2 arguments for boolean",errCtx:r}];Ie.push(e?t[0]:Pe(t)>1?t[1]:{t:"null",v:void 0})}}return e=>[{e:"Operation",m:`${(0,W.aP)(t)} is an invalid operation`,errCtx:r}]}function Ve(e){const t=(e,t,r)=>(0,W.bd)(e,{t:"key",v:t},r);return e.map((({e,m:r,errCtx:n})=>{let a=t({keys:[],vals:[]},":e",{t:"str",v:e});return a=t(a,":m",{t:"str",v:r}),a=t(a,":line",{t:"num",v:n.line}),a=t(a,":col",{t:"num",v:n.col}),{t:"dict",v:a}}))}function ze(e,t){let r=e;for(let e=0,n=Pe(t)-1;e<n;++e){const a=r[t[e]];if("vec"!==a.t)return"str"===a.t&&e+1===n&&t[e+1]<de(a.v)?{t:"str",v:Ce(a.v,t[e+1])}:{t:"null",v:void 0};r=a.v}const n=t[Pe(t)-1];return n>=Pe(r)?{t:"null",v:void 0}:r[n]}function Fe(e,t,r,n=!1){--e.callBudget,n||Te.push({});const o=Pe(Ie);for(let n=0,i=Pe(t.ins);n<i;++n){const c=t.ins[n],{errCtx:u}=t.ins[n],l=e.loopBudget<1;if(l||e.callBudget<1)return[{e:"Budget",m:(l?"looped":"called")+" too many times",errCtx:u}];switch(c.typ){case"val":Ie.push(c.value);break;case"var":e.env.vars[c.value]=Ie[Pe(Ie)-1];break;case"let":Te[Pe(Te)-1][c.value]=Ie[Pe(Ie)-1];break;case"dle":case"dva":{const t=Ie.pop();let r;c.value.forEach((({name:n,position:a})=>{r="dva"===c.typ?e.env.vars[n]=ze([t],a):Te[Pe(Te)-1][n]=ze([t],a)})),Ie.push(r);break}case"npa":case"upa":{const e=c.value;-1===e?Ue(r):Pe(r)<=e?We():Ie.push(r[e]);break}case"dpa":Ie.push(ze(r,c.value));break;case"ref":{const t=c.value;if(a.m3[t])Se(t);else if(ve(t,"$")){const r=e.get(fe(t,1));if("err"===r.kind)return[{e:"External",m:r.err,errCtx:u}];Ie.push(r.value)}else if(t in e.env.vars)Ie.push(e.env.vars[t]);else if(t in Te[Pe(Te)-1])Ie.push(Te[Pe(Te)-1][t]);else{if(!(t in e.env.funcs))return[{e:"Reference",m:`"${t}" did not exist`,errCtx:u}];Se(t)}break}case"exa":case"exe":{const a=He(e,Ie.pop(),u,"exa"===c.typ),s=c.value,o=a(ce(Ie,Pe(Ie)-s,s));if(o){const e=ie(t.ins,n).findIndex((e=>"cat"===e.typ));if(-1!==e){n+=e,Te[Pe(Te)-1].errors={t:"vec",v:Ve(o)};break}return o}if(De){if(Te[Pe(Te)-1]={},n=-1,c.value,r=De,De=void 0,--e.recurBudget,!e.recurBudget)return[{e:"Budget",m:"recurred too many times",errCtx:u}];break}break}case"or":s(Ie[Pe(Ie)-1])?n+=c.value:Ie.pop();break;case"mat":{const e=Ie[Pe(Ie)-2];(0,W.Xy)(e,Ie.pop())?Ie.pop():n+=c.value;break}case"if":s(Ie.pop())||(n+=c.value);break;case"jmp":case"cat":n+=c.value;break;case"loo":n+=c.value,--e.loopBudget;break;case"pop":ce(Ie,Pe(Ie)-c.value,c.value);break;case"ret":c.value?ce(Ie,o,Pe(Ie)-o-1):We(),n=i;break;case"clo":case"par":{const{name:t,captured:n,captureIns:a}=c.value;let{closureIns:s}=c.value;const o=[];if(Pe(a)){s=s.map(((t,r)=>{const a="val"===t.typ&&"str"===t.value.t&&(Te[Pe(Te)-1][t.value.v]??e.env.vars[t.value.v]);return n[r]=!a&&n[r],a?{typ:"val",value:a}:t}));const t=Fe(e,{ins:a},r,!0);if(t)return t;const i=Pe(a),c=ce(Ie,Pe(Ie)-i,i),l=e=>({typ:"val",value:e,errCtx:u});for(let e=0,t=0;e<Pe(n);++e)o.push(n[e]?l(c[t++]):s[e])}else se(o,s);Ie.push({t:"clo",v:{name:t,ins:o}});break}default:(0,a.UT)(c)}}n||(Te.pop(),ce(Ie,o,Pe(Ie)-(o+1)))}function Xe(e,t,r){const n=j(t,r);return Pe(n.errors)?n.errors:(e.env.funcs={...e.env.funcs,...n.funcs},"entry"in e.env.funcs?Fe(e,e.env.funcs.entry,[]):void 0)}function Je(e,t,r,n=!1){const s=function(e,t){const{callBudget:r,loopBudget:n,recurBudget:s,rangeBudget:o}=e;e.functions.forEach((({name:e,definition:t,handler:r})=>{if(a.m3[e]&&!Ke[e])throw"Redefining internal operations is disallowed.";a.m3[e]={...t,external:!0},Ke[e]=r}));const i=t();e.functions.forEach((({name:e})=>{delete a.m3[e],delete Ke[e]})),[e.callBudget,e.recurBudget]=[r,s],[e.loopBudget,e.rangeBudget]=[n,o],delete e.env.funcs.entry;const c=Ie.pop();return[Ie,Te]=[[],[]],i?{kind:"errors",errors:i}:c?{kind:"val",value:c}:{kind:"empty"}}(e,(()=>Xe(e,t,r)));return n&&"val"===s.kind&&e.print((0,W.aP)(s.value),!0),s}const Ge=new Map,Qe=/[\[\]\(\) ,]/;function Ye(e,t,r){r=r?`-${r}`:`${(0,n.getTimeMs)()}`,Ge.set(r,t);const a=Je(e,t,r,!0);if("errors"!==a.kind)return[];let s=[];const o=e=>s.push({type:"message",text:e}),i=e=>s.push({type:"error",text:e});return a.errors.forEach((({e,m:t,errCtx:{line:r,col:a,invokeId:s}})=>{const c=Ge.get(s);if(!c)return void o(`${e} Error: ${s} line ${r} col ${a}: ${t}\n`);const u=c.split("\n")[r-1],l=(0,n.substr)(u,a-1).split(Qe)[0],d=(0,n.trimStart)((0,n.substr)(u,0,a-1)),v=(0,n.starts)(s,"-")?`${(0,n.substr)(s,1)} `:"";if(o(`${v}${(0,n.padEnd)(`${r}`,4)} ${d}`),l){const e=(0,n.substr)(u,a-1+(0,n.slen)(l));i(l),o(`${e}\n`)}else{const e=(0,n.substr)(u,a);i(u[a-1]),o(`${e}\n`)}o(`${e} Error: ${t}.\n`)})),s}},728:(e,t,r)=>{r.r(t),r.d(t,{toNum:()=>n,slice:()=>a,splice:()=>s,len:()=>o,slen:()=>i,isNum:()=>c,isArray:()=>u,substr:()=>l,strIdx:()=>d,sub:()=>v,subIdx:()=>m,has:()=>p,starts:()=>f,ends:()=>y,flat:()=>x,concat:()=>h,push:()=>_,sortBy:()=>b,reverse:()=>g,lowerCase:()=>A,upperCase:()=>C,trim:()=>k,trimStart:()=>O,trimEnd:()=>E,padEnd:()=>w,charCode:()=>P,codeChar:()=>$,randNum:()=>B,randInt:()=>M,range:()=>K,objKeys:()=>D,getTimeMs:()=>I,abs:()=>T,min:()=>j,max:()=>L,sin:()=>R,cos:()=>U,tan:()=>q,sqrt:()=>W,round:()=>S,floor:()=>N,ceil:()=>H,sign:()=>V,logn:()=>z,log2:()=>F,log10:()=>X});const n=e=>Number(e),a=(e,t,r)=>e.slice(t,r),s=(e,t,r)=>e.splice(t,r),o=e=>e.length,i=e=>e.length,c=e=>!Number.isNaN(Number(e)),u=e=>Array.isArray(e),l=(e,t,r)=>e.substring(t,t+(r??e.length)),d=(e,t)=>e[t],v=(e,t)=>e.includes(t),m=(e,t)=>e.indexOf(t),p=(e,t)=>e.includes(t),f=(e,t)=>e.startsWith(t),y=(e,t)=>e.endsWith(t),x=e=>e.flat(),h=(e,t)=>e.concat(t),_=(e,t)=>e.push(...t),b=(e,t)=>e.sort(t),g=e=>e.reverse(),A=e=>e.toLowerCase(),C=e=>e.toUpperCase(),k=e=>e.trim(),O=e=>e.trimStart(),E=e=>e.trimEnd(),w=(e,t)=>e.padEnd(t),P=e=>e.charCodeAt(0),$=e=>String.fromCharCode(e),B=(e,t)=>e+Math.random()*(t-e),M=(e,t)=>Math.floor(B(e,t)),K=e=>[...Array(e).keys()],D=e=>Object.keys(e),I=()=>(new Date).getTime(),T=Math.abs,j=Math.min,L=Math.max,R=Math.sin,U=Math.cos,q=Math.tan,W=Math.sqrt,S=Math.round,N=Math.floor,H=Math.ceil,V=Math.sign,z=Math.log,F=Math.log2,X=Math.log10},376:(e,t,r)=>{r.d(t,{ib:()=>n,m3:()=>a,O3:()=>s,UT:()=>o});const n={env:{funcs:{},vars:{}},loopBudget:1e7,rangeBudget:1e6,callBudget:1e8,recurBudget:1e4},a={print:{returns:["null"]},"print-str":{returns:["null"]},"!":{exactArity:1,returns:["bool"]},"=":{minArity:2},"!=":{minArity:2},"+":{minArity:2,numeric:!0},"-":{minArity:1,numeric:!0},"*":{minArity:2,numeric:!0},"/":{minArity:2,numeric:!0},"//":{minArity:2,numeric:!0},"**":{minArity:1,maxArity:2,numeric:!0},"<":{minArity:2,numeric:!0},">":{minArity:2,numeric:!0},"<=":{minArity:2,numeric:!0},">=":{minArity:2,numeric:!0},"fast=":{exactArity:2},"fast!=":{exactArity:2},"fast+":{exactArity:2,numeric:!0},"fast-":{exactArity:2,numeric:!0},"fast*":{exactArity:2,numeric:!0},"fast/":{exactArity:2,numeric:!0},"fast//":{exactArity:2,numeric:!0},"fast<":{exactArity:2,numeric:!0},"fast>":{exactArity:2,numeric:!0},"fast<=":{exactArity:2,numeric:!0},"fast>=":{exactArity:2,numeric:!0},inc:{exactArity:1,numeric:!0},dec:{exactArity:1,numeric:!0},min:{minArity:2,numeric:!0},max:{minArity:2,numeric:!0},abs:{exactArity:1,numeric:!0},sqrt:{exactArity:1,numeric:!0},round:{minArity:1,maxArity:2,numeric:!0},floor:{exactArity:1,numeric:!0},ceil:{exactArity:1,numeric:!0},logn:{exactArity:1,numeric:!0},log2:{exactArity:1,numeric:!0},log10:{exactArity:1,numeric:!0},and:{minArity:1},or:{minArity:1},xor:{exactArity:2},"&":{exactArity:2,numeric:!0},"|":{exactArity:2,numeric:!0},"^":{exactArity:2,numeric:!0},"~":{exactArity:1,numeric:!0},"<<":{exactArity:2,numeric:!0},">>":{exactArity:2,numeric:!0},">>>":{exactArity:2,numeric:!0},"odd?":{exactArity:1,numeric:"in only",returns:["bool"]},"even?":{exactArity:1,numeric:"in only",returns:["bool"]},"pos?":{exactArity:1,numeric:"in only",returns:["bool"]},"neg?":{exactArity:1,numeric:"in only",returns:["bool"]},"zero?":{exactArity:1,numeric:"in only",returns:["bool"]},"null?":{exactArity:1,returns:["bool"]},"num?":{exactArity:1,returns:["bool"]},"bool?":{exactArity:1,returns:["bool"]},"str?":{exactArity:1,returns:["bool"]},"vec?":{exactArity:1,returns:["bool"]},"dict?":{exactArity:1,returns:["bool"]},"key?":{exactArity:1,returns:["bool"]},"func?":{exactArity:1,returns:["bool"]},"wild?":{exactArity:1,returns:["bool"]},"ext?":{exactArity:1,returns:["bool"]},rem:{minArity:2,numeric:!0},sin:{exactArity:1,numeric:!0},cos:{exactArity:1,numeric:!0},tan:{exactArity:1,numeric:!0},vec:{returns:["vec"]},dict:{returns:["dict"]},len:{exactArity:1,params:[["str","vec","dict"]],returns:["num"]},"to-num":{exactArity:1,params:[["str","num"]],returns:["num","null"]},"to-key":{exactArity:1,params:[["str","num"]],returns:["key"]},"has?":{exactArity:2,params:["str","str"],returns:["bool"]},idx:{minArity:2,maxArity:3,params:[["str","vec"]],returns:["num"]},map:{minArity:2,returns:["vec"]},for:{minArity:2,returns:["vec"]},reduce:{minArity:2,maxArity:3},filter:{minArity:2,params:[[],["vec","dict","str"]],returns:["vec","str","dict"]},remove:{minArity:2,params:[[],["vec","dict","str"]],returns:["vec","str","dict"]},find:{minArity:2,params:[[],["vec","dict","str"]]},count:{minArity:2,params:[[],["vec","dict","str"]],returns:["num"]},repeat:{minArity:2,params:[[],"num"]},"->":{minArity:2},str:{returns:["str"]},rand:{maxArity:2,numeric:!0,returns:["num"]},"rand-int":{maxArity:2,numeric:!0,returns:["num"]},".":{minArity:1},"..":{minArity:2},"...":{minArity:2},into:{exactArity:2,params:[["vec","dict"],["vec","dict"]],returns:["vec","dict"]},push:{minArity:2,maxArity:3,params:[["vec","dict"]],returns:["vec","dict"]},sect:{minArity:1,maxArity:3,params:[["vec","str"],"num","num"],returns:["vec","str"]},reverse:{exactArity:1,params:[["vec","str"]],returns:["vec","str"]},sort:{minArity:1,maxArity:2,params:[["vec","dict","str"]],returns:["vec"]},keys:{exactArity:1,params:["dict"]},vals:{exactArity:1,params:["dict"]},do:{minArity:1},val:{minArity:1},range:{minArity:1,maxArity:3,numeric:"in only",returns:["vec"]},"empty?":{exactArity:1,params:[["str","vec","dict"]],returns:["bool"]},split:{minArity:1,maxArity:2,params:["str","str"],returns:["vec"]},join:{exactArity:2,params:["str",["vec","dict","str"]],returns:["str"]},"starts?":{exactArity:2,params:["str","str"],returns:["bool"]},"ends?":{exactArity:2,params:["str","str"],returns:["bool"]},"lower-case":{exactArity:1,params:["str"],returns:["str"]},"upper-case":{exactArity:1,params:["str"],returns:["str"]},trim:{exactArity:1,params:["str"],returns:["str"]},"trim-start":{exactArity:1,params:["str"],returns:["str"]},"trim-end":{exactArity:1,params:["str"],returns:["str"]},"str*":{exactArity:2,params:["str","num"],returns:["str"]},"char-code":{minArity:1,maxArity:2,params:[["str","num"],"num"],returns:["str","num","null"]},time:{exactArity:0,returns:["num"]},version:{exactArity:0,returns:["num"]},tests:{minArity:0,maxArity:1,params:["bool"],returns:["str"]},symbols:{exactArity:0,returns:["vec"]},eval:{exactArity:1,params:["str"]},reset:{exactArity:0},recur:{}},s={null:"null",str:"string",num:"number",bool:"boolean",key:"keyword",ref:"reference",vec:"vector",dict:"dictionary",func:"function",clo:"closure",wild:"wildcard",ext:"external"},o=e=>0},183:(e,t,r)=>{r.d(t,{OK:()=>s,Bd:()=>o,Bh:()=>i,Ay:()=>c,Xy:()=>l,Pz:()=>d,aP:()=>v,_2:()=>m,gu:()=>p,k1:()=>f,bd:()=>y,uv:()=>x});var n=r(728),a=r(376);const s=({v:e})=>e,o=({v:e})=>e,i=({v:e})=>e,c=({v:e})=>e,u=(e,t)=>(0,n.len)(e)===(0,n.len)(t)&&!e.some(((e,r)=>!l(e,t[r]))),l=(e,t)=>{if("wild"===e.t||"wild"===t.t)return!0;if(e.t!==t.t)return!1;switch(e.t){case"null":return!0;case"bool":case"num":case"ext":return e.v===t.v;case"vec":return u(e.v,i(t));case"dict":{const r=c(t);return(0,n.len)(e.v.keys)===(0,n.len)(r.keys)&&u(e.v.keys,r.keys)}case"str":case"ref":case"key":case"func":return o(e)===o(t);case"clo":return e.v.name===t.v.name}return(0,a.UT)(e)},d=e=>e.reduce(((e,t)=>e+v(t)),""),v=e=>{const t=e=>"str"===e.t?`"${e.v}"`:v(e);if("clo"===e.t)return e.v.name??"";if("vec"===e.t)return`[${e.v.map(t).join(" ")}]`;if("dict"===e.t){const{keys:r,vals:n}=e.v,[a,s]=[r.map(t),n.map(t)];return`{${a.map(((e,t)=>`${e} ${s[t]}`)).join(", ")}}`}return"null"===e.t?"null":"wild"===e.t?"_":`${e.v}`},m=e=>"vec"===e.t?(0,n.slice)(e.v):"str"===e.t?[...e.v].map((e=>({t:"str",v:e}))):"dict"===e.t?e.v.keys.map(((t,r)=>({t:"vec",v:[t,e.v.vals[r]]}))):[],p=e=>{(0,n.len)(e)%2==1&&e.pop();const t=e.filter(((e,t)=>t%2==0)),r=e.filter(((e,t)=>t%2==1)),a=[],s=[];return t.forEach(((e,t)=>{const n=a.findIndex((t=>l(t,e)));-1===n?(a.push(e),s.push(r[t])):s[n]=r[t]})),{t:"dict",v:{keys:a,vals:s}}},f=({keys:e,vals:t},r)=>{const n=e.findIndex((e=>l(e,r)));return-1===n?{t:"null",v:void 0}:t[n]},y=({keys:e,vals:t},r,a)=>{const[s,o]=[(0,n.slice)(e),(0,n.slice)(t)],i=e.findIndex((e=>l(e,r)));return-1!==i?o[i]=a:(s.push(r),o.push(a)),{keys:s,vals:o}},x=({keys:e,vals:t},r)=>{const[a,s]=[(0,n.slice)(e),(0,n.slice)(t)],o=e.findIndex((e=>l(e,r)));return-1!==o&&((0,n.splice)(a,o,1),(0,n.splice)(s,o,1)),{t:"dict",v:{keys:a,vals:s}}}}},__webpack_module_cache__={};function __webpack_require__(e){var t=__webpack_module_cache__[e];if(void 0!==t)return t.exports;var r=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](r,r.exports,__webpack_require__),r.exports}__webpack_require__.d=(e,t)=>{for(var r in t)__webpack_require__.o(t,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};(()=>{var _invoker__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(829),_types__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(376),_val__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(183);const e=e=>document.querySelector(e);let state=new Map;const get=e=>state.has(e)?{kind:"val",value:state.get(e)}:nullValOrErr,set=(e,t)=>{state.set(e,t),localStorage.setItem("insitux-state",JSON.stringify([...state.entries()]))};function exe(e,t){return t.length&&"str"==t[0].t&&t[0].v.startsWith("$")?1===t.length?get(`${t[0].v.substring(1)}.${e}`):(set(`${t[0].v.substring(1)}.${e}`,t[1]),{kind:"val",value:t[1]}):{kind:"err",err:`operation ${e} does not exist`}}const nullVal={t:"null",v:void 0},nullValOrErr={kind:"val",value:nullVal},v2e=t=>"str"===t.t?e(t.v):t.v,functions=[{name:"js",definition:{minArity:1,params:["str"]},handler:params=>{const func=eval((0,_val__WEBPACK_IMPORTED_MODULE_2__.Bd)(params[0])),v=func(params.slice(1).map((e=>e.v)));let value={t:"ext",v};return"string"==typeof v&&(value={t:"str",v}),{kind:"val",value}}},{name:"html",definition:{exactArity:2,params:[["str","ext"]],returns:["str"]},handler:([e,t])=>{const r=v2e(e);return r&&(r.innerHTML=(0,_val__WEBPACK_IMPORTED_MODULE_2__.aP)(t)),nullValOrErr}},{name:"new-el",definition:{minArity:2,maxArity:3,params:["str","str","dict"],returns:["ext"]},handler:([e,t,r])=>{(0,_val__WEBPACK_IMPORTED_MODULE_2__.Bd)(e);const n=document.createElement((0,_val__WEBPACK_IMPORTED_MODULE_2__.Bd)(e));return n.innerHTML=(0,_val__WEBPACK_IMPORTED_MODULE_2__.Bd)(t),{kind:"val",value:{t:"ext",v:n}}}},{name:"new-text-el",definition:{exactArity:1,params:["str"],returns:["ext"]},handler:([e])=>({kind:"val",value:{t:"ext",v:document.createTextNode((0,_val__WEBPACK_IMPORTED_MODULE_2__.Bd)(e))}})},{name:"child-at",definition:{exactArity:2,params:[["str","ext"],"num"],returns:["ext","null"]},handler:([e,t])=>{const r=v2e(e)?.childNodes[(0,_val__WEBPACK_IMPORTED_MODULE_2__.OK)(t)];return{kind:"val",value:r?{t:"ext",v:r}:nullVal}}},{name:"append-child",definition:{exactArity:2,params:[["str","ext"],"ext"],returns:["null"]},handler:([e,t])=>(v2e(e)?.appendChild(t.v),nullValOrErr)},{name:"remove-child",definition:{exactArity:2,params:[["str","ext"],"num"],returns:["null"]},handler:([e,t])=>{if("str"===e.t){const r=v2e(e);r?.removeChild(r.childNodes[(0,_val__WEBPACK_IMPORTED_MODULE_2__.OK)(t)])}return nullValOrErr}},{name:"replace-child",definition:{exactArity:3,params:[["str","ext"],"ext","num"],returns:["null"]},handler:([e,t,r])=>{const[n,a]=[v2e(e),v2e(t)],s=n?.childNodes[(0,_val__WEBPACK_IMPORTED_MODULE_2__.OK)(r)];return n&&a&&s&&n.replaceChild(a,s),nullValOrErr}},{name:"prompt",definition:{exactArity:1,returns:["str","null"]},handler:e=>{const t=prompt((0,_val__WEBPACK_IMPORTED_MODULE_2__.aP)(e[0]));return{kind:"val",value:t?{t:"str",v:t}:nullVal}}},{name:"alert",definition:{exactArity:1,returns:["null"]},handler:e=>(alert((0,_val__WEBPACK_IMPORTED_MODULE_2__.aP)(e[0])),nullValOrErr)},{name:"interval",definition:{exactArity:2,params:["func","num"],returns:["null"]},handler:([e,t])=>(setInterval((()=>(0,_invoker__WEBPACK_IMPORTED_MODULE_0__.z)(ctx,`(${e.v})`)),(0,_val__WEBPACK_IMPORTED_MODULE_2__.OK)(t)),nullValOrErr)},{name:"timeout",definition:{exactArity:2,params:["func","num"],returns:["null"]},handler:([e,t])=>(setTimeout((()=>(0,_invoker__WEBPACK_IMPORTED_MODULE_0__.z)(ctx,`(${e.v})`)),(0,_val__WEBPACK_IMPORTED_MODULE_2__.OK)(t)),nullValOrErr)}],ctx={..._types__WEBPACK_IMPORTED_MODULE_1__.ib,exe,get,set,print:e=>console.log(e),functions},loadScript=async e=>{const t=e.src?await(await fetch(e.src)).text():e.innerHTML;window.ix(t)};window.onload=async()=>{const e=localStorage.getItem("insitux-state");state=new Map(e?JSON.parse(e):[]),console.log(state);const t=Array.from(document.querySelectorAll("script")).filter((e=>"text/insitux"===e.type));for(let e=0;e<t.length;++e)await loadScript(t[e])},window.ix=e=>{const t=(0,_invoker__WEBPACK_IMPORTED_MODULE_0__.z)(ctx,e);if(t.length>0){const e=t.map((({type:e,text:t})=>"error"===e?[...t,""].join("̲"):t));alert(`---- Insitux\n${e.join("")}`)}}})()})();
  //# sourceMappingURL=insitux.min.js.map