4
4
5
5
= SUBTITLE Using the types the compiler and hardware make available to you
6
6
7
- Perl 6 offers a set of I < native > types with a fixed, and known, representation
8
- in memory. This page shows which ones exist and how they can be used. Please
9
- check also the page on L < native numerics|/language/numerics#Native_Numerics > for
10
- more information on them.
7
+ Perl 6 offers a set of I < native > types with a fixed, and known,
8
+ representation in memory. This page shows which ones exist and how they
9
+ can be used. Please check also the page on L < native
10
+ numerics|/language/numerics#Native_Numerics > for more information on
11
+ them.
11
12
12
13
X < |int > X < |uint > X < |num > X < |str >
13
14
= head1 Types with native representation
14
15
15
- Some simple types in Perl 6 have a I < native > representation, indicating that
16
- they will use the C language representation provided by the compiler, operating
17
- system and machine. These are the four native types available:
16
+ Some simple types in Perl 6 have a I < native > representation, indicating
17
+ that they will use the C language representation provided by the
18
+ compiler, operating system and machine. These are the four native types
19
+ available:
18
20
19
21
= begin table
20
22
int Equivalent to Int
@@ -28,26 +30,29 @@ L<NativeCall|/language/nativecall> interface (e.g., Perl 6's C<int> can be 8
28
30
bytes but C's C < int > is only 4 bytes). Instead, the types below will have to be
29
31
used instead of the types C < int > or C < num > listed above.
30
32
31
- In general, these variables will behave in the same way as regular scalar
32
- variables, in a behavior that is called
33
- L < I < auto-boxing > |/language/numerics#Auto-Boxing> ; however, there are some
34
- differences, since what you are actually declaring is how they will be
35
- represented, not their actual type. The first one is that their type will be
36
- actually their equivalent type, not their native type.
33
+ In general, these variables will behave in the same way as regular
34
+ scalar variables, in a behavior that is called
35
+ L < I < auto-boxing > |/language/numerics#Auto-Boxing> ; however, there are
36
+ some differences, since what you are actually declaring is how they will
37
+ be represented, not their actual type. The first one is that their type
38
+ will be actually their equivalent type, not their native type.
37
39
38
40
my int $intillo = 3;
39
41
say $intillo.^name; # OUTPUT: «Int»
40
42
41
- This obviously means that they will smartmatch their equivalent, not their
42
- native type:
43
+ This obviously means that they will smartmatch their equivalent, not
44
+ their native type:
43
45
44
46
my str $strillo = "tres";
45
47
say $strillo ~~ str; # OUTPUT: «False»
46
48
say $strillo ~~ Str; # OUTPUT: «True»
47
49
48
- They cannot be bound either. Trying to do C < my num $numillo := 3.5 > will raise
49
- the exception C < Cannot bind to natively typed variable '$variable-name'; use
50
- assignment instead > .
50
+ This is due to the fact that Natives don't know their types because
51
+ they're just values, without any meta-data.
52
+
53
+ They cannot be bound either. Trying to do C < my num $numillo := 3.5 > will
54
+ raise the exception C < Cannot bind to natively typed variable
55
+ '$variable-name'; use assignment instead > .
51
56
52
57
X < |int8 > X < |int16 > X < |int32 > X < |int64 > X < |uint8 > X < |uint16 > X < |uint32 > X < |uint64 > X < |num32 > X < |num64 > X < |byte >
53
58
= head1 Types with native representation and size
0 commit comments