Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to quit/exit from file included in the terminal

Tags:

julia

What can I do within a file "example.jl" to exit/return from a call to include() in the command line

julia> include("example.jl")

without existing julia itself. quit() will just terminate julia itself.

Edit: For me this would be useful while interactively developing code, for example to include a test file and return from the execution to the julia prompt when a certain condition is met or do only compile the tests I am currently working on without reorganizing the code to much.

like image 776
mschauer Avatar asked Feb 05 '16 14:02

mschauer


People also ask

How do you exit a file in Terminal?

Press Esc to enter Command mode, and then type :wq to write and quit the file. The other, quicker option is to use the keyboard shortcut ZZ to write and quit.

How do I exit less in terminal?

By default, the only way to exit less is via the q command. Automatically exit the second time end-of-file is reached. By default, the only way to exit less is via the q command.


2 Answers

I'm not quite sure what you're looking to do, but it sounds like you might be better off writing your code as a function, and use a return to exit. You could even call the function in the include.

like image 150
Daniel Arndt Avatar answered Sep 18 '22 08:09

Daniel Arndt


Kristoffer will not love it, but

stop(text="Stop.") = throw(StopException(text))

struct StopException{T}
    S::T
end

function Base.showerror(io::IO, ex::StopException, bt; backtrace=true)
    Base.with_output_color(get(io, :color, false) ? :green : :nothing, io) do io
        showerror(io, ex.S)
    end
end

will give a nice, less alarming message than just throwing an error.

julia> stop("Stopped. Reason: Converged.")
ERROR: "Stopped. Reason: Converged."

Source: https://discourse.julialang.org/t/a-julia-equivalent-to-rs-stop/36568/12

like image 23
mschauer Avatar answered Sep 21 '22 08:09

mschauer