julia

How to alias quit() to quit?


IPython allows a pure quit as does Matlab. It would be reasonable in Julia to allow aliasing.


Solution

  • Quitting in Julia

    If you are using Julia from the command line then ctrl-d works. But if your intention is to quit by typing a command this is not possible exactly the way you want it because typing quit in the REPL already has a meaning which is return the value associated with quit, which is the function quit.

    julia> quit
    quit (generic function with 1 method)
    
    julia> typeof(quit)
    Function
    

    Also Python

    But that's not rare, for example Python has similar behavior.

    >>> quit
    Use quit() or Ctrl-D (i.e. EOF) to exit
    

    Using a macro

    Using \q might be nice in the Julia REPL like in postgres REPL, but unfortunately \ also already has a meaning. However, if you were seeking a simple way to do this, how about a macro

    julia> macro q() quit() end
    
    julia> @q
    

    Causes Julia to Quit

    If you place the macro definition in a .juliarc.jl file, it will be available every time you run the interpreter.