deno: Exiting the REPL should be `.exit` instead of `exit`
Currently you exit the REPL via exit. This is inconsistent with Node.js (which is .exit) and also collides with what is a valid variable name in JavaScript.
> const exit = "";
error: Uncaught SyntaxError: Identifier 'exit' has already been declared
► <unknown>:1:1
at evaluate ($deno$/repl.ts:64:34)
at Object.replLoop ($deno$/repl.ts:153:13)
> exit = "bar"
bar
>
and even funnier/dangerous, this will cause the Deno REPL to exit:
> console.log(exit)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 28 (24 by maintainers)
No,
_,_error, andhelp/_helpwork because they are just values, though automatically set. Exit is not the same, we should choose between.exitand removal (i.e. just usingDeno.exit()).Either way, if we support more REPL commands then we need a pattern for it, and
.<cmd>is the only one that would generally make sense. Consider if we added a break command for example. These are meta REPL commands, they shouldn’t be valid JS. (So what @Caesar2011 said.)Only point, forcing CTRL-D only is an accessibility issue. Being able to type something out without needing to hold another key down is always preferable from that aspect.
I think arbitrarily appropriating valid, top-level/global variables in order to use them as REPL environment commands will be an unwelcome surprise to some people.
How about just using the
_prefix? We already have_and_error, we can simply have_exit- as terse as.exitand is valid JS, and unlikely something people would name in REPLThe problem I see, and that’s why I asked about the
helpcommand. If we want to implement other commands like help or save like node. With the same problem like now with exit. And in this case we should be consistent.Deno.help()andDeno.save()do not make any sense, but.saveand.helpdoes. As special REPL commands they do not have to be compliant with JS code. And.exitis in some way also a special command - or at least - expected if we have.help,.loadand.save.I guess I am not fully on board that we must use non-JS syntax to do meta commands that also makes sense in JS like
_exit(since it make sense to be a JS thing as it could be implemented as a getter that have side effects), but I do agree for other ones beyond JS where there is room for debate. V8 uses%prefix for some operations so that would also be an interesting candidate.Preprocessing is an option, though the regex you propose might be too broad.
@Soremwar Doing everything before is not interactive. That’s the whole point of a REPL. You don’t start one with an exact plan. By the way you didn’t address
.breakand.editor. So yeah, there’s no way to avoid non-JS commands if we want those features.@Caesar2011 It doesn’t
@kitsonk Well, what do you think? In the end it’s all a matter of preference
exitcould be patched to execute only when alone, so noconst exitorconsole.log(exit)oddities. But as I said, more code to maintainThat’s the problem, you have to handle this cases in a different way you would handle JS code. That means more code to maintain
Why bother? Better to use already existing code Functions make it clear that you will execute an action (in this case well, exit XD) so that’s bonus for readability
Just my opinion though
I just checked and
Denois available in REPL. AndDeno.exit()is already implemented in 0.40.0 and works like a charm to exit REPL.Let’s make it a function then, like Python
Deno.exit()Could work wellNot sure if Deno is available in the REPL though, but including it inside (event partially) is a way better option than read stdin to provide
.commandfunctionality, or just dump variables into the namespace that may conflict with user programs if not well known@kitsonk Is right, typed commands alongside keyboard commands provide way better accessibility, and are very desirable in a REPL
agree.
It’s just that it isn’t javascript. Can we just remove it instead?
I use ctrl+d to exit. Maybe we can just print a reminder for people when the repl starts?