62

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?

hippietrail
  • 15,848
  • 18
  • 99
  • 158
Ankit Goel
  • 6,257
  • 4
  • 36
  • 48

2 Answers2

110

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.

marc-medley
  • 8,931
  • 5
  • 60
  • 66
14

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

It does not work without the colon.

Ankit Goel
  • 6,257
  • 4
  • 36
  • 48
  • You got robbed! – Adrian Sep 30 '18 at 01:46
  • Your answer is earlier. You should have marked your own as accepted. Then all those upvotes might have come to you :) – Paul Rooney Jul 30 '19 at 23:47
  • Hmmm... I was simply thinking to provide an informative answer … to a question with no accepted answer at that time. I did upvote this answer prior to adding my response. Likewise, others may also upvote this answer ... and the question, if they so wish. – marc-medley Aug 14 '19 at 18:42