Any swift option that will let you stay in REPL after file has been executed?


(Jon Kleiser) #1

If I just start the swift REPL with a command like swift myscript.swift, then I will be returned to the shell once the myscript.swift has executed. Instead, I would like to remain in the REPL to work with the data and functions that my script has generated. Is that possible?

It would also be very useful if the script (myscript.swift) could have access to additional arguments, in case I run it with a command like swift myscript.swift arg1 arg2.


(Jordan Rose) #2

The latter does work, using CommandLine.arguments. The former is an interesting idea; today the script interpreter mode uses a different, faster execution path than what the REPL does (executing everything at once rather than line-by-line, and not saving the results). But it certainly seems like something useful. Can you file a feature request at https://bugs.swift.org?


(Jon Kleiser) #3

Thanks for your reply. I shall file a feature request.
Request here: https://bugs.swift.org/browse/SR-8793


(Joe Groff) #4

Note that you can start the REPL at any time from the debugger with the repl command. You could try compiling your program with debug info, setting a breakpoint at the end, and entering the REPL from there.