diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-08-28 22:31:40 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-08-28 22:43:23 -0400 |
| commit | 13318ddb9ec7b51baa7d9d693f2392d1de270acc (patch) | |
| tree | b961d020fa1c0c7430f4b31b591ec28586a0e0b0 | |
| parent | d6544a57eca9d24bac9ace307c7542649f14d756 (diff) | |
Replace bqns with makebqn
| -rwxr-xr-x | bqn.js | 16 | ||||
| -rw-r--r-- | docs/bqn.js | 18 |
2 files changed, 17 insertions, 17 deletions
@@ -6,8 +6,10 @@ let fs = require('fs'); let bqn = require("./docs/bqn.js"); module.exports = bqn; -let {fmt,fmtErr,sysvals,sysargs,bqns}=bqn; +let {fmt,fmtErr,sysvals,sysargs,makebqn}=bqn; let {has,list,str,unstr,dynsys,req1str,makens}=bqn.util; +let bqn_state=makebqn((u,s,x,w)=>(u(s,w),x)); +let bqn_nostate=makebqn((u,s,x,w)=>x); let show = x => console.log(fmt(x)); sysvals.show = (x,w) => { show(x); return x; }; @@ -114,14 +116,12 @@ let update_state = (st,w) => { st.resolve=getres(st.path); st.state=list(w); st.name=w[1]; st.args=w[2]; } -let new_state = (st,w) => { st={...st}; update_state(st,w); return st; } sysvals.path=dynsys(s=>s.path); sysvals.name=dynsys(s=>s.name); sysvals.args=dynsys(s=>s.args); -let bqn_state = (st,x,w) => bqns(new_state(st,w))(x); bqn.setexec(update_state); -let bqn_file = (st,f,t,w) => bqn_state( - st, t, [ str(dir(path.dirname(f))), str(path.basename(f)), w ] +let bqn_file = (st,f,t,w) => bqn_state(st)( + t, [ str(dir(path.dirname(f))), str(path.basename(f)), w ] ); let imports = {}; sysvals.import = withres("•Import", (resolve,state) => (x,w) => { @@ -140,8 +140,8 @@ if (!module.parent) { let arg0 = args[0]; let cl_state = () => { let s = str(""); - let w = [str(dir(path.resolve('.'))), s, list([],s)]; - return new_state(sysargs, w); + update_state(sysargs, [str(dir(path.resolve('.'))), s, list([],s)]); + return sysargs; } let exec = fn => src => { try { @@ -164,7 +164,7 @@ if (!module.parent) { let f=arg0, a=list(args.slice(1).map(str)); exec(s=>bqn_file(sysargs, path.resolve(f),s,a))(fs.readFileSync(f,'utf-8')); } else if (arg0 === '-e') { - let ev=bqns(cl_state()); + let ev=bqn_nostate(cl_state()); args.slice(1).map(exec(s=>show(ev(s)))); } } diff --git a/docs/bqn.js b/docs/bqn.js index 6e90e13d..0436c5f4 100644 --- a/docs/bqn.js +++ b/docs/bqn.js @@ -429,9 +429,7 @@ let compgen = sys => { } let sysargs = {runtime, glyphs:glyphs.map(str)}; let compile = compgen(sysargs)(sysargs); -let andrun = c => src => run(...c(src)); -let bqn = andrun(compile); -let bqns = st => andrun(st.comps(st)); +let bqn = src => run(...compile(src)); runtime[42] = rtAssert; // Formatter @@ -491,10 +489,11 @@ let dojs = (x,w) => { } let update_state = (st,w)=>w; // Modified by Node version to handle •state -let makebqn = (e,fn) => st => (x,w) => { - let src = req1str(e,x,update_state(st,w)); +let makebqn = (proc,fn) => st => (x,w) => { + let src = proc(update_state,st,x,w); return fn(st.comps(st)(src)); } +let makebqnfn = (e,fn) => makebqn((u,s,x,w)=>req1str(e,x,u(s,w)), fn); let copy_state = st_old => { let st={...st_old}; st.addrt=[]; return st; } let dynsys_copy = fn => dynsys(st => fn(copy_state(st))); @@ -521,7 +520,7 @@ let rebqn = dynsys_copy(state => (x,w) => { state.runtime = list([].concat(...rt)); compgen(state); } - let cmp = makebqn("•ReBQN evaluation", r=>r)(state); + let cmp = makebqnfn("•ReBQN evaluation", r=>r)(state); if (!has(repl) || (repl=unstr(repl))==="none") { return (x,w) => run(...cmp(x,w)); @@ -549,7 +548,7 @@ let primitives = dynsys(state => { }); let sysvals = { - bqn:dynsys_copy(makebqn("•BQN",r=>run(...r))), rebqn, primitives, js:dojs, + bqn:dynsys_copy(makebqnfn("•BQN",r=>run(...r))), rebqn, primitives, js:dojs, type, glyph, decompose, fmt:fmt1, repr, unixtime, listkeys, listsys: dynsys(_ => list(Object.keys(sysvals).sort().map(str))), math: obj2ns(Math,("LN10 LN2 LOG10E LOG2E cbrt expm1 hypot log10 log1p log2 round trunc atan2 cos cosh sin sinh tan tanh").split(" "), f=>typeof f==="function"?runtime[60](f,0):f) @@ -579,8 +578,9 @@ if (typeof process!=='undefined') { if (typeof module!=='undefined') { // Node.js bqn.fmt=fmt; bqn.fmtErr=fmtErr; bqn.compile=compile; bqn.run=run; - bqn.sysargs=sysargs; bqn.bqns=bqns; - bqn.sysvals=sysvals; bqn.util={has,list,str,unstr,dynsys,req1str,makens}; + bqn.sysargs=sysargs; bqn.sysvals=sysvals; + bqn.makebqn=fn=>makebqn(fn,r=>run(...r)); + bqn.util={has,list,str,unstr,dynsys,req1str,makens}; bqn.setexec = f => { update_state=f; } module.exports=bqn; } |
