Skip to content

Commit 7ab4e7f

Browse files
committed
Add &repl
Document the &repl sub, completing one item from the 2021.06 checklist (issue #3907)
1 parent d56e6f5 commit 7ab4e7f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

doc/Type/independent-routines.pod6

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,52 @@ by the final statement in the file when C<$check> is not C<True>.
135135
=for code
136136
EVALFILE "foo.raku";
137137
138+
=head2 sub repl
139+
I<Note>: C<repl> was introduced in release 2021.06 of the Rakudo compiler.
140+
141+
Defined as:
142+
143+
sub repl()
144+
145+
Pauses execution and enters a REPL (read-eval-print loop) in the current
146+
context. This REPL is exactly like the one created when you run C<raku>
147+
L<without any arguments|Programs/04-running-raku#DESCRIPTION> except that
148+
you can access/modify the program's current context (such as lexical
149+
variables).
150+
151+
For example, if you run this code:
152+
153+
=begin code
154+
my $name = "Alice";
155+
156+
say "Hello, $name";
157+
158+
repl();
159+
160+
say "Goodbye, $name"
161+
=end code
162+
163+
then you'll get the output C<Hello, Alice> and then enter a REPL session
164+
(I<before> any output with "goodbye" is printed). Your REPL session could
165+
go as follows:
166+
167+
168+
=begin code :lang<shell>
169+
Type 'exit' to leave
170+
[0] > $name
171+
Alice
172+
[1] > $name = "Bob"
173+
Bob
174+
[2] > exit
175+
=end code
176+
177+
After exiting the REPL session, Raku will resume running the program;
178+
during this run, any changes you made in the REPL session will still be
179+
in effect. Thus, after the session above, you'd get the output
180+
C<Goodbye, Bob> rather than C<Goodbye, Alice> as you would have without
181+
the REPL session.
182+
183+
138184
=head2 sub mkdir
139185
140186
Defined as:

0 commit comments

Comments
 (0)