Skip to content

Conversation

simonbyrne
Copy link
Member

By changing the show method, we can provide more useful hints (this idea is gratuitously stolen from Python):

julia> exit
Use exit(), quit() or Ctrl-D to exit

"""
quit() = exit()

# hint for people who forget parentheses
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be more repl specific?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, but I still don't really understand how display works...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually talking about something more integrated into the REPL (since that's where we need this) instead of modifying how some functions are displayed.

Something like

diff --git a/base/REPL.jl b/base/REPL.jl
index 7a4eb61b46..5ac8261dfc 100644
--- a/base/REPL.jl
+++ b/base/REPL.jl
@@ -138,7 +138,9 @@ function print_response(errio::IO, val::ANY, bt, show_value::Bool, have_color::B
                                                           errio, QuoteNode(val), bt))))
                 iserr, lasterr = false, ()
             else
-                if val !== nothing && show_value
+                if (val === exit || val === quit) && show_value && specialdisplay === nothing
+                    println("Use exit(), quit() or Ctrl-D to exit")
+                elseif val !== nothing && show_value
                     try
                         if specialdisplay === nothing
                             eval(Main, Expr(:body, Expr(:return, Expr(:call, display, QuoteNode(val)))))

This gives;

julia> exit
Use exit(), quit() or Ctrl-D to exit

julia> quit
Use exit(), quit() or Ctrl-D to exit

julia> print(exit)
exit
julia> display(exit)
exit (generic function with 2 methods)

julia> display(quit)
quit (generic function with 1 method)

Ideally we may want to do this only when the input is just quit and exit.

When trying this I realized that this will make it harder to see how many methods are defined for the two function. Hopefully it's fine...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely agree --- this should only be an interactive feature, if anything, not something that prevents you from normally showing certain functions.

Copy link
Member

@stevengj stevengj Apr 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the rare cases where you might want to overload display:

Base.display(d::Base.REPL.REPLDisplay, ::Union{typeof(exit),typeof(quit)}) = display(d, Text("Use exit(), quit(), or Ctrl-D to exit"))

will work and should only affect output in the REPL, and doesn't require hacking REPL internals.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't overload display because this way we can probably pass in additional information and only show it on certain inputs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not affect how the object is shown, it should only affect the exact input exit, not e.g. fs = [exit]; fs[1].

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, agree. print_response is just easier to find then the input handling ;-p

@ararslan ararslan added the REPL Julia's REPL (Read Eval Print Loop) label Apr 12, 2017
processes completed successfully.
"""
exit(n) = ccall(:jl_exit, Void, (Int32,), n)
exit() = exit(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we're not doing exit(n=0) = ...?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably this function pre-dates optional arguments.

Copy link
Member

@JeffBezanson JeffBezanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate special cases like this, but could maybe tolerate it if it were REPL-only. 👎

@musm
Copy link
Contributor

musm commented Dec 15, 2020

closed in favor of #38522

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

Labels

REPL Julia's REPL (Read Eval Print Loop)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants