Skip to content

Commit 3f37921

Browse files
committed
Improving and restructuring documentation for dynamic variables.
This closes #2510 and also refs #2483.
1 parent b961fc7 commit 3f37921

File tree

1 file changed

+170
-87
lines changed

1 file changed

+170
-87
lines changed

doc/Language/variables.pod6

Lines changed: 170 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ successful exit means the block returned a defined value or a list.
882882
883883
In the above case, if the C<Bool.pick> returns true, the answer will
884884
stay as 84 because the block returns a defined value (C<say> returns
885-
true). Otherwise the C<die> statement will cause the block to exit
885+
C<True>). Otherwise the C<die> statement will cause the block to exit
886886
unsuccessfully, resetting the answer to 42.
887887
888888
X<|constant (Prefix)>
@@ -896,7 +896,9 @@ constant $pi2 = pi * 2;
896896
$pi2 = 6; # OUTPUT: «(exit code 1) Cannot assign to an immutable value␤
897897
=end code
898898
899-
The value is assigned at compile time. Please check L<the section on constants in the Terms page|/language/terms#Constants> for additional information.
899+
The value is assigned at compile time. Please check
900+
L<the section on constants in the Terms page|/language/terms#Constants> for
901+
additional information.
900902
901903
=head1 Type constraints and initialization
902904
@@ -911,7 +913,8 @@ L<of|/type/Variable#trait_of> to set a type constraint.
911913
# OUTPUT: «X::TypeCheck::Assignment: Type check failed in assignment to $x; expected Int but got Str ("a string")␤»
912914
913915
If a scalar variable has a type constraint but no initial value, it's
914-
initialized with the type object of the default value of the container it's bound to.
916+
initialized with the type object of the default value of the container it's
917+
bound to.
915918
916919
my Int $x;
917920
say $x.^name; # OUTPUT: «Int␤»
@@ -1201,7 +1204,11 @@ in uppercase.
12011204
X<|$*ARGFILES>X<|@*ARGS>
12021205
=head3 Argument related variables
12031206
1204-
=item C<$*ARGFILES> An L<IO::ArgFiles> (an empty subclass of L<IO::CatHandle>)
1207+
These variables are related to the arguments passed to a script.
1208+
1209+
=head4 C<$*ARGFILES>
1210+
1211+
An L<IO::ArgFiles> (an empty subclass of L<IO::CatHandle>)
12051212
that uses C<@*ARGS> as source files, if it contains any files, or C<$*IN>
12061213
otherwise. When C<$*IN> is used, its C<:nl-in>, C<:chomp>, C<:encoding>, and
12071214
C<:bin> will be set on the L<IO::ArgFiles> object.
@@ -1210,8 +1217,9 @@ As of 6.d language, C<$*ARGFILES> I<inside>
12101217
L<C«sub MAIN»|/language/functions#sub_MAIN> is always set to C<$*IN>, even
12111218
when C<@*ARGS> is not empty.
12121219
1213-
=item C<@*ARGS>
1214-
Arguments from the command line.
1220+
=head4 C<@*ARGS>
1221+
1222+
C<@*ARGS> contains the arguments from the command line.
12151223
12161224
X<|$*IN>X<|$*OUT>X<|$*ERR>
12171225
=head3 Special filehandles: C<STDIN>, C<STDOUT> and C<STDERR>
@@ -1220,7 +1228,6 @@ For more information about special filehandles please see also the L<Input and
12201228
Output|/language/io> page and the L<IO::Special> class. L<IO::Handle> contains
12211229
several examples of using C<$*IN> for reading standard input.
12221230
1223-
12241231
=item C<$*IN>
12251232
Standard input filehandle, AKA I<STDIN>.
12261233
@@ -1231,153 +1238,229 @@ Standard output filehandle, AKA I<STDOUT>.
12311238
Standard error filehandle, AKA I<STDERR>.
12321239
12331240
=head3 Runtime environment
1241+
1242+
These dynamic variables contain information related to the environment the
1243+
script or program is running in.
1244+
12341245
X<|%*ENV>
1235-
=item C<%*ENV>
1236-
Environment variables. Numeric values are provided
1246+
=head4 C<%*ENV>
1247+
1248+
Operating system environment variables. Numeric values are provided
12371249
as L<allomorphs|/language/glossary#index-entry-Allomorph>
12381250
12391251
X<|$*REPO>
1240-
=item C<$*REPO>
1241-
a variable holding information about modules installed/loaded;
1252+
=head4 C<$*REPO>
1253+
1254+
This variable holds information about modules installed/loaded.
12421255
12431256
X<|$*INIT-INSTANT>
1244-
=item C<$*INIT-INSTANT>
1245-
an Instant object representing program startup time.
1257+
=head4 C<$*INIT-INSTANT>
1258+
1259+
C<$*INIT-INSTANT> is an L<Instant> object representing program startup time.
12461260
In particular, this is when the core code starts up,
12471261
so the value of C<$*INIT-INSTANT> may be a few milliseconds
12481262
earlier than C<INIT now> or even C<BEGIN now> executed
1249-
in your program;
1263+
in your program.
12501264
12511265
X<|$*TZ>
1252-
=item C<$*TZ>
1253-
the system's local timezone offset, as the number of B<seconds> from GMT;
1266+
=head4 C<$*TZ>
1267+
1268+
C<$*TZ> contains the system's local timezone offset, as the number of B<seconds>
1269+
from GMT.
12541270
12551271
X<|$*CWD>
1256-
=item C<$*CWD>
1257-
the Current Working Directory;
1272+
=head4 C<$*CWD>
1273+
1274+
It contains the Current Working Directory.
12581275
12591276
X<|$*KERNEL>
1260-
=item C<$*KERNEL>
1261-
the current running Kernel.
1277+
=head4 C<$*KERNEL>
1278+
1279+
C<$*KERNEL> contains an object that is stringified to the current running
1280+
kernel.
1281+
1282+
say $*KERNEL; # OUTPUT: «linux (4.4.92.31.default)␤»
12621283
12631284
X<|$*DISTRO>
1264-
=item C<$*DISTRO>
1285+
=head4 C<$*DISTRO>
1286+
12651287
This object (of type C<Distro>) contains information about the current operating
1266-
system distribution (e.g. C<say "Some sort of Windows" if $*DISTRO.is-win>); in
1267-
the current Rakudo implementation, C<$*DISTRO.name> takes the following values
1268-
(which should be self-explanatory): C<mswin32>, C<macosx>, C<freebsd>, C<linux>,
1269-
C<netbsd>, C<raspbian> and C<dragonfly>. Since these names are implementation
1270-
defined and not in the specification, they could vary and change at any moment.
1271-
C<$*DISTRO> can be stringfied by printing it, for instance, C<say $*DISTRO>, it
1272-
will show additional information on the operating system and version it's using,
1273-
like C<OUTPUT: «debian (9.stretch)␤»>.
1288+
system distribution. For instance:
1289+
1290+
say "Some sort of Windows" if $*DISTRO.is-win;
1291+
1292+
C<$*DISTRO.name> takes a set of values that depend on the operating system.
1293+
These names will vary with version and implementation, so you should
1294+
double-check and test before using them in your programs; since these names are
1295+
implementation defined and not in the specification, they could vary and change
1296+
at any moment.
1297+
1298+
C<$*DISTRO> can be stringfied by printing it
1299+
1300+
say $*DISTRO; # OUTPUT: «debian (9.stretch)␤»
1301+
1302+
This shows additional information on the operating system and version it's
1303+
using, but as a matter of fact, this variable contains information which is
1304+
useful to create portable programs, such as the path separator:
1305+
1306+
say $*DISTRO.perl;
1307+
# OUTPUT: «Distro.new(release => "42.3", is-win => Bool::False,
1308+
# path-sep => ":", name => "opensuse",
1309+
# auth => "https://www.opensuse.org/", version => v42.3,
1310+
# signature => Blob, desc => "2018-12-13T08:50:59.213619+01:00")␤»
12741311
12751312
12761313
X<|$*VM>
1277-
=item C<$*VM>
1278-
contains the current virtual machine running the code;
1314+
=head4 C<$*VM>
1315+
1316+
This variable contains the current virtual machine running the code, as well as
1317+
additional information on the inner workings of aforementioned VM.
1318+
1319+
say $*VM.precomp-ext, " ", $*VM.precomp-target; # OUTPUT: «moarvm mbc␤»
1320+
1321+
These two variables, for instance, will show the extension used in the
1322+
precompiled bytecode scripts and the target used. This is what is found in the
1323+
Moar Virtual Machine, but it could also vary with version and implementation.
1324+
Other VM, such as Java, will show different values for them. C<$*VM.config>
1325+
includes all configuration values used to create the virtual machine, e.g.
1326+
1327+
say $*VM.config<versionmajor>, ".", $*VM.config<versionminor>;
1328+
# OUTPUT: «2018.11␤»
1329+
1330+
which are the version of the virtual machine, generally the same one as the one
1331+
used in the interpreter and the overall Perl 6 environment.
12791332
12801333
X<|$*PERL>
1281-
=item C<$*PERL>
1282-
the current implementation of the Perl language;
1334+
=head4 C<$*PERL>
1335+
1336+
This object contains information on the current implementation of the Perl
1337+
language:
1338+
1339+
say $*PERL.compiler.version; # OUTPUT: «v2018.11.52.g.06156.a.7.ca␤»
1340+
1341+
but it simply stringifies to the major version of the compiler:
1342+
1343+
say $*PERL;# OUTPUT: «Perl 6 (6.d)␤»
12831344
12841345
X<|$*PID>
1285-
=item C<$*PID>
1286-
the current Process IDentifier (operating system dependent);
1346+
=head4 C<$*PID>
1347+
1348+
Object containing an integer describing the current Process IDentifier
1349+
(operating system dependent).
12871350
12881351
X<|$*PROGRAM-NAME>
1289-
=item C<$*PROGRAM-NAME>
1290-
path to the current executable as it was entered on the
1291-
command line, or C<-e> if perl was invoked with the -e flag;
1352+
=head4 C<$*PROGRAM-NAME>
1353+
1354+
This contains the path to the current executable as it was entered on the
1355+
command line, or C<-e> if perl was invoked with the -e flag.
12921356
12931357
X<|$*PROGRAM>
1294-
=item C<$*PROGRAM>
1295-
location (in the form of an C<IO::Path> object) of the Perl program being executed;
1358+
=head4 C<$*PROGRAM>
1359+
1360+
Contains the location (in the form of an C<IO::Path> object) of the Perl 6
1361+
program being executed.
12961362
12971363
X<|&*EXIT>
1298-
=item C<&*EXIT> code that will be executed when doing an exit(). Intended to
1299-
be used in situations where Perl 6 is embedded in another language runtime
1300-
(such as Inline::Perl6 in Perl 5);
1364+
=head4 C<&*EXIT>
1365+
1366+
This is a L<Callable> that contains the code that will be executed when doing an
1367+
C<exit()> call. Intended to be used in situations where Perl 6 is embedded in
1368+
another language runtime (such as Inline::Perl6 in Perl 5).
13011369
13021370
X<|$*EXECUTABLE>
1303-
=item C<$*EXECUTABLE>
1304-
absolute path of the perl executable that is currently running;
1371+
=head4 C<$*EXECUTABLE>
1372+
1373+
Contains an C<IO::Path> absolute path of the perl executable that is currently
1374+
running.
13051375
13061376
X<|$*EXECUTABLE-NAME>
1307-
=item C<$*EXECUTABLE-NAME>
1308-
the name of the perl executable that is currently running.
1309-
(e.g. perl6-p, perl6-m, Niecza.exe)
1310-
Favor $*EXECUTABLE because it's not guaranteed that the perl
1311-
executable is in C<PATH>;
1377+
=head4 C<$*EXECUTABLE-NAME>
1378+
1379+
This the name of the perl executable that is currently running. (e.g. perl6-p,
1380+
perl6-m). Favor C<$*EXECUTABLE> over this one, since it's not guaranteed that
1381+
the perl executable is in C<PATH>.
13121382
13131383
X<|$*USAGE>
1314-
=item C<$*USAGE>
1315-
the default usage message generated from the
1384+
=head4 C<$*USAGE>
1385+
1386+
This is the default usage message generated from the
13161387
signatures of C<MAIN> subs available from inside
1317-
C<sub MAIN> and C<sub USAGE>. The variable is I<read-only>;
1388+
C<sub MAIN> and C<sub USAGE>. The variable is I<read-only>.
13181389
13191390
X<|$*USER>
1320-
=item C<$*USER>
1321-
the user that is running the program. It's an object
1322-
that evaluates to C<username (uid)>. It will evaluate
1323-
to the username only if treated as a string and the
1324-
numeric user id if treated as a number;
1391+
=head4 C<$*USER>
1392+
1393+
An C<Allomorph> with information about the user that is running the program.
1394+
It's an object that evaluates to C<username (uid)>. It will evaluate to the
1395+
username only if treated as a string and the numeric user id if treated as a
1396+
number.
13251397
13261398
X<|$*GROUP>
1327-
=item C<$*GROUP>
1328-
the primary group of the user who is running the program.
1399+
=head4 C<$*GROUP>
1400+
1401+
An C<Allomorph> with the primary group of the user who is running the program.
13291402
It's an object that evaluates to C<groupname (gid)>.
13301403
It will evaluate to the groupname only if treated as a
1331-
string and the numeric group id if treated as a number;
1404+
string and the numeric group id if treated as a number.
13321405
13331406
X<|$*HOME>
1334-
=item C<$*HOME>
1335-
an L<IO::Path> object representing the "home directory"
1407+
=head4 C<$*HOME>
1408+
1409+
Contains an L<IO::Path> object representing the "home directory"
13361410
of the user that is running the program. Uses
13371411
C«%*ENV<HOME>» if set. On Windows, uses
13381412
C«%*ENV<HOMEDRIVE> ~ %*ENV<HOMEPATH>». If the
1339-
home directory cannot be determined, it will be L<Any>;
1413+
home directory cannot be determined, it will be L<Any>.
13401414
13411415
X<|$*SPEC>
1342-
=item C<$*SPEC>
1343-
the appropriate L<IO::Spec> sub-class for the platform that the program is running on;
1416+
=head4 C<$*SPEC>
1417+
1418+
Contains the appropriate L<IO::Spec> sub-class for the platform that the program
1419+
is running on. This is a higher-level class for the operating system; it will
1420+
return C<Unix>, for instance, in the case of Linux (in the form of the
1421+
C<IO::Spec> class used for the current implementation).
13441422
13451423
X<|$*TMPDIR>
1346-
=item C<$*TMPDIR>
1347-
an L<IO::Path> object representing the "system temporary directory" as determined by L«C<.tmpdir IO::Spec::* method>|/routine/tmpdir»;
1424+
=head4 C<$*TMPDIR>
1425+
1426+
This is an L<IO::Path> object representing the "system temporary directory" as
1427+
determined by L«C<.tmpdir IO::Spec::* method>|/routine/tmpdir».
13481428
13491429
X<|$*TOLERANCE>
1350-
=item C<$*TOLERANCE>
1351-
used by the C<=~=> operator, and any operations that depend on it, to
1430+
=head4 C<$*TOLERANCE>
1431+
1432+
Variable used by the C<=~=> operator, and any operations that depend on it, to
13521433
decide if two values are approximately equal. Defaults to C<1e-15>;
13531434
13541435
X<|$*THREAD>
1355-
=item C<$*THREAD>
1356-
a L<Thread> object representing the currently executing thread;
1357-
1358-
X<|$*SCHEDULER>
1359-
=item C<$*SCHEDULER>
1360-
a L<ThreadPoolScheduler> object representing the current default scheduler (see note below);
1436+
=head4 C<$*THREAD>
13611437
1362-
X<|$*SAMPLER>
1363-
=item C<$*SAMPLER>: the current L<Telemetry::Sampler> used for
1364-
making snapshots of system state. Only available if L<Telemetry> has been
1365-
loaded.
1438+
Contains a L<Thread> object representing the currently executing thread;
13661439
1440+
X<|$*SCHEDULER>
1441+
=head4 C<$*SCHEDULER>
13671442
1368-
Note on usage of C<$*SCHEDULER>:
1443+
This is a L<ThreadPoolScheduler> object representing the current default
1444+
scheduler.
13691445
1370-
For the current (2018.04) Rakudo, by default this imposes a maximum of 64
1371-
threads on the methods C<.hyper>, C<.race> and other thread-pool classes that
1372-
use that scheduler such as C<Promise>s or C<Supplie>s. To change the maximum
1373-
number of threads, you can either set the environment variable
1374-
C<RAKUDO_MAX_THREADS> before running perl6 or create a scoped copy with the
1375-
default changed before using them:
1446+
By default this imposes a maximum of 64 threads on the methods C<.hyper>,
1447+
C<.race> and other thread-pool classes that use that scheduler such as
1448+
C<Promise>s or C<Supply>s. This is, however, implementation, dependent and might
1449+
be subject to change. To change the maximum number of threads, you can either
1450+
set the environment variable C<RAKUDO_MAX_THREADS> before running perl6 or
1451+
create a scoped copy with the default changed before using them:
13761452
13771453
my $*SCHEDULER = ThreadPoolScheduler.new( max_threads => 128 );
13781454
13791455
This behavior is not tested in the spec tests and is subject to change.
13801456
1457+
X<|$*SAMPLER>
1458+
=head4 C<$*SAMPLER>
1459+
1460+
The current L<Telemetry::Sampler> used for
1461+
making snapshots of system state. Only available if L<Telemetry> has been
1462+
loaded.
1463+
13811464
=head1 Naming conventions
13821465
13831466
It is helpful to know our naming conventions in order to understand what codes

0 commit comments

Comments
 (0)