Skip to content

Commit be3f2a6

Browse files
committed
First pass at Languages/REPL
1 parent d9202ea commit be3f2a6

File tree

7 files changed

+79
-19
lines changed

7 files changed

+79
-19
lines changed

doc/Language/REPL.rakudoc

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
=begin pod :kind("Language") :subkind("Language") :category("tutorial")
2+
3+
=TITLE REPL
4+
5+
=SUBTITLE Read-eval-print loop
6+
7+
=head1 Overview
8+
9+
The C<REPL> is an interactive Raku prompt. Each line of code you enter in the C<REPL>
10+
is executed, and if no output was generated, the value returned
11+
by the expression is output.
12+
13+
=head1 Trap
14+
15+
B<Note>: Running code in the C<REPL> is not equivalent to saving the code in a file and
16+
running that. Each line introduces a new scope which can confuse code that has multiple
17+
lines. See C<sub repl()> below for a way to target a REPL inside a larger script.
18+
19+
=head1 non-interactive mode
20+
21+
If invoked from the command line with C<raku --repl-mode=non-interactive>, no history or prompts
22+
are printed, and the code is not executed until you close input (on Linux, for example, you can pipe
23+
the code to it or press C<Control-d>.
24+
25+
=for code :lang<shell>
26+
$ echo "say 3" | raku --repl-mode=non-interactive
27+
3
28+
29+
=head1 sub repl()
30+
31+
This routine allows you to embed a REPL inside a larger script and have access to all
32+
the variables in context.
33+
34+
See L<sub repl()|/type/independent-routines#sub_repl> in Independent Routines for more
35+
information.
36+
37+
=head1 ENVIRONMENT Variables
38+
39+
See L<ENVIRONMENT Variables|/programs/03-environment-variables#Environment_variables_used_by_the_raku_command_line>.
40+
41+
=head2 Get command line history
42+
43+
In a fresh install, there is no command history. Running the C<REPL> in this mode will
44+
prompt you to install one of the various modules that provide this support. If enabled,
45+
you can use the arrow keys to scroll through previous commands and use standard terminal
46+
shortcuts for editing. There are currently four options:
47+
48+
=item 1
49+
50+
=for code :lang<shell>
51+
zef install Terminal::LineEditor
52+
53+
=item 2
54+
55+
=for code :lang<shell>
56+
zef install Linenoise
57+
58+
=item 3
59+
60+
=for code :lang<shell>
61+
zef install Readline # requires a readline install
62+
63+
=item 4
64+
65+
An alternative for UNIX-like systems is to install C<rlwrap>. This can
66+
be done on Debian-ish systems by running:
67+
68+
=for code :lang<shell>
69+
sudo apt-get install rlwrap
70+
71+
=end pod

doc/Language/faq.rakudoc

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -414,17 +414,6 @@ There are also L<several ecosystem modules|https://raku.land/?q=dump>
414414
that provide more control over how data structures are dumped, including
415415
support for colored output.
416416

417-
=head2 How can I get command line history in the Raku prompt (REPL)?
418-
419-
Install L<Linenoise|https://github.com/hoelzro/p6-linenoise/> from the
420-
ecosystem.
421-
422-
An alternative for UNIX-like systems is to install C<rlwrap>. This can
423-
be done on Debian-ish systems by running:
424-
425-
=for code :lang<shell>
426-
sudo apt-get install rlwrap
427-
428417
=head2 Why is the Rakudo compiler so apologetic?
429418

430419
If SORRY! is present in the output, the error is a compile time error.

doc/Language/unicode_entry.rakudoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ following key combination (whitespace has been added for clarity):
415415
=end code
416416

417417
This also the method one would use to enter unicode characters into the
418-
C<raku> REPL, if one has started the REPL inside a Unix shell.
418+
C<raku> L<REPL|/language/REPL>, if one has started the REPL inside a Unix shell.
419419

420420
=head2 Screen
421421

doc/Language/variables.rakudoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ X<|Syntax,*>X<|Syntax,$*>X<|Syntax,@*>X<|Syntax,%*>X<|Syntax,&*>
247247

248248
This twigil is used for dynamic variables which are looked up through the
249249
caller's, not through the outer, scope. Look at the example below.N<The example
250-
below cannot run correctly in the REPL, yielding an error about not finding the
250+
below cannot run correctly in the L<REPL|/language/REPL>, yielding an error about not finding the
251251
dynamic variables. Please test it by copy-pasting it into a file, then run the
252252
file.>
253253

doc/Programs/03-environment-variables.rakudoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ X<|Programs,RAKUDO_NO_PRECOMPILATION>
135135
If set to 1, precompilation will be disabled. Available as of the 2023.08
136136
release of the Rakudo compiler.
137137

138-
=head2 REPL (Read Eval Print Loop)
138+
=head2 REPL (Read-eval-print loop)
139139

140140
X<|Programs,RAKU_REPL_OUTPUT_METHOD>
141141
=item C<RAKU_REPL_OUTPUT_METHOD>
142142

143143
This specifies the name of the method that should be called on the result
144-
value of a statement in the REPL if the statement did B<not> cause any
144+
value of a statement in the L<REPL|/language/REPL> if the statement did B<not> cause any
145145
output of its own. If absent, C<gist> will be assumed. One can use
146146
C<raku> to force a more literal, parsable representation. Or C<Str> to force a
147147
complete string representation. Available as of the 2020.06 release of
@@ -150,8 +150,8 @@ the Rakudo compiler.
150150
X<|Programs,RAKUDO_LINE_EDITOR>
151151
=item C<RAKUDO_LINE_EDITOR>
152152

153-
This specifies the preferred line editor to use; valid values are C<Readline>,
154-
C<Linenoise>, and none. A value of none is useful if you want to avoid the
153+
This specifies the preferred line editor to use; valid values are C<LineEditor>,
154+
C<Readline>, C<Linenoise>, and none. A value of none is useful if you want to avoid the
155155
recommendation message upon REPL startup.
156156

157157
X<|Programs,RAKUDO_DISABLE_MULTILINE>

doc/Programs/04-running-raku.rakudoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ raku [switches] [--] [programfile] [arguments]
1616

1717
=head1 DESCRIPTION
1818

19-
With no arguments, it enters a REPL. With a C<[programfile]> or the C<-e>
19+
With no arguments, it enters a L<REPL|/language.REPL>. With a C<[programfile]> or the C<-e>
2020
option, compiles the given program and by default also executes the
2121
compiled code.
2222

doc/Type/independent-routines.rakudoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ I<Note>: C<repl> was introduced in release 2021.06 of the Rakudo compiler.
137137

138138
sub repl()
139139

140-
Pauses execution and enters a REPL (read-eval-print loop) in the current
140+
Pauses execution and enters a L<REPL|/language/REPL> (read-eval-print loop) in the current
141141
context. This REPL is exactly like the one created when you run C<raku>
142142
L<without any arguments|/programs/04-running-raku#DESCRIPTION> except that
143143
you can access/modify the program's current context (such as lexical

0 commit comments

Comments
 (0)