Skip to content

Instantly share code, notes, and snippets.

@markx
Created April 17, 2017 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markx/231c1d74197611840ebd77b73701fd1a to your computer and use it in GitHub Desktop.
Save markx/231c1d74197611840ebd77b73701fd1a to your computer and use it in GitHub Desktop.
const readline = require('readline');
function READ(x) {
return x;
}
function EVAL(x) {
return x;
}
function PRINT(x) {
return x;
}
function rep(x) {
return PRINT(EVAL(READ(x)));
}
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: 'user> '
});
rl.prompt();
rl.on('line', (input) => {
const result = rep(input);
console.log(result);
rl.prompt();
});
@kanaka
Copy link

kanaka commented Apr 17, 2017

@markx regarding your query on #mal: Try setting readline.createInterface(... "terminal": false) otherwise it messes with the ability of the runtest script to test it. Also you might want that configurable because for normal interactive usage turning off terminal mode is annoying (no line editing or history). The node readline module is slightly screwy with regards to tty handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment