From 2d5263c758ae9f1d0a7f63bd15314fef7c6c81ba Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 28 May 2021 21:35:14 -0400 Subject: =?UTF-8?q?Define=20=E2=80=A2state=20and=20always=20set=20state=20?= =?UTF-8?q?values=20(except=20in=20monadic=20=E2=80=A2BQN)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bqn.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'bqn.js') diff --git a/bqn.js b/bqn.js index ce5abde1..3f92e9a6 100755 --- a/bqn.js +++ b/bqn.js @@ -31,11 +31,11 @@ sysvals.fchars = withres("•FChars",fchars); sysvals.flines = withres("•FLines",flines); sysvals.fbytes = withres("•FBytes",fbytes); -let bqn_state = sysvals.bqn = (x,w) => { - w = w||[]; +let set_state = w => { + w = w||[]; sysvals.state=list(w); sysvals.path=w[0]; sysvals.name=w[1]; sysvals.args=w[2]; - return bqn(x); } +let bqn_state = sysvals.bqn = (x,w) => { set_state(w); return bqn(x); } sysvals.exit = (x,w) => process.exit(Number.isInteger(x)?x:0); sysvals.bqn = (x,w) => bqn_state(req1str("•BQN",x), w); let bqn_file = (f,t,w) => bqn_state( @@ -56,6 +56,10 @@ sysvals.import = withres("•Import", resolve => (x,w) => { if (!module.parent) { let args = process.argv.slice(2); let arg0 = args[0]; + let cl_state = () => { + let s = str(""); + return [str(path.resolve(__dirname)+'/'), s, list([],s)]; + } let exec = fn => src => { try { fn(src); @@ -64,6 +68,7 @@ if (!module.parent) { } } if (!has(arg0) || arg0==='-r') { + set_state(cl_state()); let stdin = process.stdin, repl = sysvals.makerepl(); let e = exec(s=>show(repl(str(s)))); stdin.on('end', () => { process.exit(); }); @@ -74,6 +79,7 @@ if (!module.parent) { let f=arg0, a=list(args.slice(1).map(str)); exec(s=>bqn_file(f,s,a))(fs.readFileSync(f,'utf-8')); } else if (arg0 === '-e') { - args.slice(1).map(exec(s=>show(bqn_state(s)))); + let st=cl_state(); + args.slice(1).map(exec(s=>show(bqn_state(s,st)))); } } -- cgit v1.2.3