Skip to content

Commit f003181

Browse files
authored
Merge pull request #3733 from Raku/eval-2905
Document EVAL $check and $filename parameters
2 parents 875dacc + 1cfc694 commit f003181

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

doc/Type/independent-routines.pod6

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ Defined as:
1313
1414
=begin code :method
1515
proto sub EVAL($code where Blob|Cool|Callable, Str() :$lang = 'Raku',
16-
PseudoStash :$context, *%n)
16+
PseudoStash :$context, Str() :$filename, Bool() :$check, *%_)
1717
=end code
1818
=begin code :method
1919
multi sub EVAL($code, Str :$lang where { ($lang // '') eq 'Perl5' },
20-
PseudoStash :$context)
20+
PseudoStash :$context, Str() :$filename, :$check)
2121
=end code
2222
23-
This routine coerces L<Cool|/type/Cool> C<$code> to L<Str|/type/Str>. If
23+
This routine executes at runtime a fragment of code, C<$code>, of a given language,
24+
C<$lang>, which defaults to C<Raku>.
25+
26+
It coerces L<Cool|/type/Cool> C<$code> to L<Str|/type/Str>. If
2427
C<$code> is a L<Blob|/type/Blob>, it'll be processed using the same encoding as
2528
the C<$lang> compiler would: for C<Raku> C<$lang>, uses C<utf-8>; for C<Perl5>,
26-
processes using the same rules as C<perl>.
29+
processes using the same rules as Perl.
2730
2831
This works as-is with a literal string parameter. More complex input,
2932
such as a variable or string with embedded code, is illegal by default.
@@ -93,19 +96,39 @@ EVAL "use v5.20; say 'Hello from perl!'", :lang<Perl5>;
9396
You need to have L<C<Inline::Perl5>|https://github.com/niner/Inline-Perl5> for
9497
this to work correctly.
9598
99+
More languages may be supported with additional
100+
modules which may be found from the
101+
L<Raku Modules Directory|https://modules.raku.org/search/?q=inline>.
102+
103+
If the optional C<$filename> parameter is given, the
104+
L«C<$?FILE>|/language/variables#index-entry-$%3FFILE» variable is set to
105+
its value. Otherwise C<$?FILE> is set to a unique and generated file name.
106+
107+
=for code
108+
use MONKEY-SEE-NO-EVAL;
109+
EVAL 'say $?FILE'; # OUTPUT: «/tmp/EVAL_0␤»
110+
EVAL 'say $?FILE', filename => '/my-eval-code'; # OUTPUT: «/my-eval-code␤»
111+
112+
If the optional C<$check> parameter is C<True>, C<$code>
113+
is processed by the C<$lang> compiler but is not actually
114+
run. For C<Raku>, L«C<BEGIN>|/language/phasers#BEGIN», and
115+
L«C<CHECK>|/language/phasers#CHECK» blocks are run. The C<EVAL> routine
116+
then returns C<Nil> if compilation was successful, otherwise an exception
117+
is thrown.
118+
96119
=head2 sub EVALFILE
97120
98121
Defined as:
99122
100-
sub EVALFILE($filename where Blob|Cool, :$lang = 'Raku')
123+
sub EVALFILE($filename where Blob|Cool, :$lang = 'Raku', :$check)
101124
102125
Slurps the specified file and evaluates it. Behaves the same way as
103-
C<EVAL> with regard to L<Blob|/type/Blob> decoding, scoping, and the C<$lang>
104-
parameter. Evaluates to the value produced by the final statement in the
105-
file.
126+
C<EVAL> with regard to L<Blob|/type/Blob> decoding, scoping, the C<$lang>
127+
parameter and the C<$check> parameter. Evaluates to the value produced
128+
by the final statement in the file when C<$check> is not C<True>.
106129
107130
=for code
108-
EVALFILE "foo.p6";
131+
EVALFILE "foo.raku";
109132
110133
=head2 sub mkdir
111134

0 commit comments

Comments
 (0)