|
7 | 7 | class Nil is Cool { }
|
8 | 8 |
|
9 | 9 | The value C<Nil> may be used to fill a spot where a value would normally
|
10 |
| -go, and in so doing, explicitly indicate that no value is present. It |
| 10 | +go, and in so doing, explicitly indicate that no value is present. It |
11 | 11 | may also used as a cheaper and less explosive alternative to a
|
12 | 12 | L<C<Failure>|/type/Failure>.
|
13 | 13 |
|
14 | 14 | The class C<Nil> is the same exact thing as its only possible value, C<Nil>.
|
15 | 15 |
|
16 | 16 | say Nil === Nil.new #-> True
|
17 | 17 |
|
18 |
| -Along with C<Failure>, C<Nil> is one of the two types which may |
19 |
| -always be returned from a routine even when the routine specifies a |
20 |
| -particular return type. It may also be returned regardless of the |
21 |
| -definedness of the return type, however, C<Nil> is considered undefined |
22 |
| -for all other purposes. |
| 18 | +Along with C<Failure>, C<Nil> and its sub classes may always be returned from a |
| 19 | +routine even when the routine specifies a particular return type. It may also |
| 20 | +be returned regardless of the definedness of the return type, however, C<Nil> |
| 21 | +is considered undefined for all other purposes. |
23 | 22 |
|
24 | 23 | sub a( --> Int:D ) { return Nil }
|
25 | 24 | a().say; #-> Nil
|
@@ -48,21 +47,16 @@ C<Nil>.
|
48 | 47 | say (Nil)[100]; #-> Nil
|
49 | 48 | say (Nil){100}; #-> Nil
|
50 | 49 |
|
51 |
| -When assigned, C<Nil> will revert a container to its default value, if no such |
52 |
| -default is provided Perl 6 assumes C<Any>. This includes initializers on |
53 |
| -defined constrained types. Returning C<Nil> from a routine will break the |
54 |
| -definedness constraint. Subsequent assignments to another definedness |
55 |
| -constraint container, including L<Signature|/type/Signature>s, will properly |
56 |
| -fail. |
| 50 | +When assigned, C<Nil> and any subclass of C<Nil> will revert a container to its |
| 51 | +default value, if no such default is provided Perl 6 assumes C<Any>. Assigning |
| 52 | +to a defined constrained container will produce a L<Failure|/type/Failure>. |
57 | 53 |
|
58 | 54 | my Int $x = 42;
|
59 | 55 | $x = Nil;
|
60 | 56 | $x.say; #-> (Int)
|
61 | 57 |
|
62 |
| - sub f(-->Int:D){Nil}; |
63 |
| - my Int:D $i = f; |
64 |
| - say $i.defined; |
65 |
| - # OUTPUT«False» |
| 58 | + sub f( -->Int:D ){ Nil }; # this definedness constraint is ignored |
| 59 | + my Int:D $i = f; # this definedness contraint is not ignored |
66 | 60 |
|
67 | 61 | Because an untyped variable is type C<Any>, assigning a C<Nil> to one
|
68 | 62 | will result in an L<(Any)|/type/Any> type object.
|
|
0 commit comments