How do I quit swift repl without using ctrl-d?

SwiftRead Eval-Print-Loop

Swift Problem Overview


I want to quit swift repl gracefully and not use ctrl-d to exit it.

For eg. python repl can be exited by typing exit(). Is there a similar way of quitting swift repl?

Swift Solutions


Solution 1 - Swift

This answer complements Ankit Goel's correct :quit answer to also (1) provide an understanding of why the : is needed and (2) other options besides :quit.

Swift REPL works in conjuction with the LLDB debugger.

: is a REPL escape prefix to execute an LLDB command. From within REPL, :help will list the available LLDB commands.

Any of the following will quit both Swift REPL and subsequently LLDB with a single command line.

:exit
:quit
:q

One can also exit REPL into LLDB with just : and, then later quit (or exit) using the LLDB command directly.

sh$ swift
  Welcome…
1> print(18 + 4)
  22
2> :
(lldb) print "hello"
  (String) $R0 = "hello"
(lldb) quit
sh$

Addendum: The LLDB command c or continue can be used to return to the Swift REPL environment.

Solution 2 - Swift

Just found out that a graceful way to quit swift repl is by using typing :quit

It does not work without the colon.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnkit GoelView Question on Stackoverflow
Solution 1 - Swiftl --marc lView Answer on Stackoverflow
Solution 2 - SwiftAnkit GoelView Answer on Stackoverflow