Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adds constant prefix to the Variables page
This closes #1566 although there was a pretty good section on the
Terms page, for some reason. I have added just a simple example and
linked the previous page, there's no need for duplicates.
  • Loading branch information
JJ committed Jul 29, 2018
1 parent 9ca6a17 commit 737c6eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions doc/Language/5to6-nutshell.pod6
Expand Up @@ -1213,8 +1213,8 @@ constant DEBUG = 0; # Perl 6
=for code :lang<perl5>
use constant pi => 4 * atan2(1, 1); # Perl 5
=for code
tau, pi, e, i; # built-in constants in Perl 6
τ, π, 𝑒 # and their unicode equivalents
tau, pi, e, i; # built-in constants in Perl 6
τ, π, 𝑒 # and their unicode equivalents
=head3 C<encoding>
Expand Down
13 changes: 13 additions & 0 deletions doc/Language/variables.pod6
Expand Up @@ -864,6 +864,19 @@ stay as 84 because the block returns a defined value (C<say> returns
true). Otherwise the C<die> statement will cause the block to exit
unsuccessfully, resetting the answer to 42.
X<|constant (Prefix)>
=head2 The C<constant> prefix
The C<constant> prefix declares that a container value is not going to change
during its lifetime.
=begin code :skip-test<Illustrating error>
constant $pi2 = pi * 2;
$pi2 = 6; # OUTPUT: «(exit code 1) Cannot assign to an immutable value␤
=end code
The value is assigned at compile time. Please check L<the section on constants in the Terms page|/language/terms#Constants> for additional information.
=head1 Type constraints and initialization
Variables have a type constraint via the L<container|/language/containers> they
Expand Down

0 comments on commit 737c6eb

Please sign in to comment.