I've written a frist version of the "1.1 - Literal Values" subsection
(in Michael's schema).
It discusses the different ways of creating literal numbers and
strings in perl6.
There are no tests, and the format may be outdated. I will gladly
resubmit this in a more complete form.
I have directly stolen some paragraphs from perl5 documentation.
Special prize to the one who lists all the original sources!
This is just a tentative draft, so feel free to delete/add at your own
taste.
Does it look ok? Any comments? (including grammar errors, of course)
-angel
-------------------------------------------
=subsection Literal Values
=head1 Literal numbers
=head2 Integers
Integers can be represented by its decimal representation,
such as:
my $x = 14; # stores the integer 14 in $x
You can also write the number in any other base, using the
C<radix:dddddddd> syntax.
For example:
my $x = 2:101110; #binary
my $x = 3:1210112; #tertiary
my $3 = 8:1270; #octal
my $x = 16:1E3A7; #hexadecimal
my $x = 256:255.255.255.0; #256-base
As you can see, when the base is greater than 10, there
is a need to represent digits that are greater than 9.
You can do this in two ways:
=over
=item *
Alphabetic characters: Following the standard
convention, perl will interpret the A letter as the digit 10,
the B letter as digit 11, and so on.
=item *
Separating by dots: You can also write each digit in
its decimal representation, and separate digits using the
C<.> character.
=back
For example, the integer 30 can be written in hexadecimal
base in two equivalent ways:
my $x = 16:1D
my $x = 16:1.14
This two representations are incompatible, so writing
something like C<16:D.13> will generate a compile-time error.
Finally, you can create negative integers prepending the
C<-> character.
For example:
my $x = 18;
my $x = -18;
=head2 Floating Point-Numbers
You can use the decimal representation of the number and
the standard exponental notation.
my $x = -2.542;
my $x = 7.823e12;
Perl lets you operate integer numbers with floating-point
numbers, so the following operation is correct:
print 3.5 + 2; # prints 5.5
=head1 Literal strings
Duble quotes or single quotes may be used around literal
strings:
print "Hello, world";
print 'Hello, world';
However, only double quotes "interpolate" variables and
special characters such as newlines ("\n"):
print "Hello, $name\n"; # works fine
print 'Hello, $name\n'; # prints $name\n literally
my $x = 'world';
print "Hello, $x"; # Hello, world
You can type any character including newlines and tabs
in literal strings:
my $x = 'Look mum, I can type
newlines and tabs too!';
If you use a Unicode editor to edit your program,
Unicode characters may occur directly within the
literal strings.
Unicode characters can also be added to a doble-quoted
string using the C<\x{...}> notation. The Unicode code
for the desired character, in hexadecimal, should be
placed in the braces. For instance, a smiley face is
C<\x{263A}>.
Perl provides escapes for easily inserting characters
that have a codepoint below 256:
print "\xB" # Hexadecimal - character number 16:xA
print "\024" # Octal - character number 8:33
Aditionally, you can use the C<\N{...}> notation and
put the official Unicode character name within the
braces, such as C<\N{WHITE SMILING FACE}>.
See the L<quotes> section for a full explanation
of the interpolation mechanism and a list of special
characters in doble-quoted strings.
=head2 String as vector of ordinals
Literals of the form C<v1.2.3.4> are parsed as a string
composed of characters with the specified ordinals. This
is an alternative, more readable way to construct
(possibly unicode) strings instead of interpolating
characters, as in C<\x{1}\x{2}\x{3}\x{4}>. The leading C<v>
may be omitted if there are more than two ordinals, so
C<1.2.3> is parsed the same as C<v1.2.3>.