Permalink
Browse files

Simplify Nil semantics; never means () now

  • Loading branch information...
1 parent c8f2dcc commit 48958abed853ecc0e2632e6f77beaf855a4afd72 @TimToady TimToady committed Feb 23, 2013
Showing with 34 additions and 32 deletions.
  1. +15 −15 S02-bits.pod
  2. +1 −1 S03-operators.pod
  3. +10 −10 S04-control.pod
  4. +7 −5 S06-routines.pod
  5. +1 −1 S09-data.pod
View
@@ -13,8 +13,8 @@ Synopsis 2: Bits and Pieces
Created: 10 Aug 2004
- Last Modified: 9 Jan 2013
- Version: 271
+ Last Modified: 23 Feb 2013
+ Version: 272
This document summarizes Apocalypse 2, which covers small-scale
lexical items and typological issues. (These Synopses also contain
@@ -1324,8 +1324,7 @@ All user-defined classes derive from the C<Any> class by default.
The C<Whatever> type is derived from C<Any> but nothing else
is derived from it.
-Type objects stringify to their name with empty parens concatenated,
-which can be read as a coercion from C<Nil> to a value of that type.
+Type objects sometimes stringify to their name in parens, to indicate undefinedness.
Note that type objects are not classes, but may be used to name
classes when the type's associated meta-object allows it:
@@ -2261,18 +2260,18 @@ also the relative identities of several related objects. Conversely,
you can think of Perl 5 references as a degenerate form of C<Capture>
when you want to refer only to a single item.
-There is a special C<Parcel> value named C<Nil>. It means "there
+There is a special value named C<Nil>. It means "there
is no value here". It is the undefined equivalent of the empty
C<()> list, except that the latter is defined and means "there are
-0 arguments here". The C<Nil> value returns itself if you iterate
-it or try to get a positional value from it via subscripting, but
-interpolates as a null list into flat context.
-In either case, a warning is issued.
+0 arguments here". The C<Nil> value represents the absense of a value
+where there should be one, so it does not disappear in list context,
+but relies on something downstream to catch it or blow up.
+C<Nil> also indicates a failed match.
Since method calls are performed directly on any object, C<Nil>
can respond to certain method calls. C<Nil.defined> returns
C<False> (whereas C<().defined> returns C<True>). C<Nil.so> also
-returns C<False>. C<Nil.ACCEPTS> matches only a C<Nil> value. C<Nil.perl> and
+returns C<False>. C<Nil.ACCEPTS> always returns C<Nil>. C<Nil.perl> and
C<Nil.gist> return C<'Nil'>. C<Nil.Stringy> and C<Nil.Str> fail with a resumable warning
that returns a value of C<''> on resumption. C<Nil.Numeric> likewise fails
with resumable warning that returns 0 on resumption. Any undefined method call
@@ -2281,8 +2280,9 @@ call chains.
Assigning C<Nil> to any scalar container causes the container to
throw out any contents and restore itself to an uninitialized state
-(after which it will contain an object appropriate to the declared
-default of the container, where C<Any> is the default default). Binding of
+(after which it will appear to contain an object appropriate to the declared
+default of the container, where C<Any> is the default default; the element may be simply deleted
+if that's how the default can be represented in the structure). Binding of
C<Nil> with C<:=> simply puts Nil in the container. However, binding
C<Nil> to a parameter (C<::=> semantics) works more like assignment;
passing C<Nil> to a parameter with a default causes that parameter
@@ -2438,14 +2438,14 @@ To make a slice subscript return something other than values, append an
appropriate adverb to the subscript.
@array = <A B>;
- @array[0,1,2]; # returns 'A', 'B', Nil
+ @array[0,1,2]; # returns 'A', 'B', (Any)
@array[0,1,2] :p; # returns 0 => 'A', 1 => 'B'
@array[0,1,2] :kv; # returns 0, 'A', 1, 'B'
@array[0,1,2] :k; # returns 0, 1
@array[0,1,2] :v; # returns 'A', 'B'
%hash = (:a<A>, :b<B>);
- %hash<a b c>; # returns 'A', 'B', Nil
+ %hash<a b c>; # returns 'A', 'B', (Any)
%hash<a b c> :p; # returns a => 'A', b => 'B'
%hash<a b c> :kv; # returns 'a', 'A', 'b', 'B'
%hash<a b c> :k; # returns 'a', 'b'
@@ -3502,7 +3502,7 @@ constructor or composer for clarity as well as correctness:
The degenerate case C<< <> >> is disallowed as a probable attempt to
do IO in the style of Perl 5; that is now written C<lines()>. (C<< <STDIN> >>
is also disallowed.) Empty lists are better written with
-C<()> or C<Nil> in any case because C<< <> >> will often be misread
+C<()> in any case because C<< <> >> will often be misread
as meaning C<('')>. (Likewise the subscript form C<< %foo<> >>
should be written C<%foo{}> to avoid misreading as C<@foo{''}>.)
If you really want the angle form for stylistic reasons, you can
View
@@ -1819,7 +1819,7 @@ It's quite possible for a sequence to return fewer values than are
listed if the very first value matches the end test:
my $lim = 0;
- 1,2,3 ...^ * > $lim # returns Nil, since 1 > 0
+ 1,2,3 ...^ * > $lim # returns (), since 1 > 0
This operator would be fairly useless if it could only return the
literal values on the left. The power comes from generating
View
@@ -12,8 +12,8 @@ Synopsis 4: Blocks and Statements
Created: 19 Aug 2004
- Last Modified: 6 Dec 2012
- Version: 119
+ Last Modified: 23 Feb 2013
+ Version: 120
This document summarizes Apocalypse 4, which covers the block and
statement syntax of Perl.
@@ -209,8 +209,8 @@ the value of the last expression evaluated, even if that expression
was just a conditional. Unlike in Perl 5, if a final statement in
Perl 6 is a conditional that does not execute any of its branches, it
doesn't matter what the value of the conditional is, the value of that
-conditional statement is always C<Nil>. If there are no statements
-in the block at all, the result is also C<Nil>.
+conditional statement is always C<()>. If there are no statements
+in the block at all, the result is also C<()>.
=head1 Statement-ending blocks
@@ -273,7 +273,7 @@ Perl 5. However, you may omit the parentheses on the conditional:
The result of a conditional statement is the result of the block
chosen to execute. If the conditional does not execute any
-branch, the return value is C<Nil>.
+branch, the return value is C<()>.
The C<unless> statement does not allow an C<elsif> or C<else> in Perl 6.
@@ -324,7 +324,7 @@ so you can say:
and that is equivalent to:
- @x = 41, ($answer ?? 42 !! Nil), 43
+ @x = 41, ($answer ?? 42 !! ()), 43
=head1 Loop statements
@@ -339,7 +339,7 @@ Perl 5. However, the labeled forms can use method call syntax:
C<LABEL.next>, etc. The C<.next> and C<.last> methods take an
optional argument giving the final value of that loop iteration.
So the old C<next LINE> syntax is still allowed but really does
-something like C<LINE.next(Nil)> underneath. Any block object can
+something like C<LINE.next(())> underneath. Any block object can
be used, not just labels, so to return a value from this iteration
of the current block you can say:
@@ -366,9 +366,9 @@ it's either an ordinary object or a parcel containing multiple values.
Normal flat list context ignores parcel boundaries and flattens the list.
Slice context turns any parcel objects into C<Seq> objects.
-Iterations that return C<Nil> (such as by calling C<next> with no extra return
-arguments) return that C<Nil> as the next value, which will therefore disappear
-when interpolated in flat context, but will interpolate an empty C<Seq> into slice
+Iterations that return C<()> (such as by calling C<next> with no extra return
+arguments) return that C<()> as the next value, which will therefore disappear
+when interpolated in flat context, but will interpolate an empty C<Parcel> into slice
context.
For finer-grained control of which iterations return values, use
View
@@ -16,8 +16,8 @@ Synopsis 6: Subroutines
Created: 21 Mar 2003
- Last Modified: 9 Jan 2013
- Version: 156
+ Last Modified: 23 Feb 2013
+ Version: 157
This document summarizes Apocalypse 6, which covers subroutines and the
new type system.
@@ -675,7 +675,7 @@ An explicit C<return> may be used instead to evaluate the C<return>'s
arguments as the code block's return value, and leave the code block
immediately, short-circuiting the rest of the block's execution.
-If the return specification is a definite immutable value (or Nil) rather than
+If the return specification is a definite immutable value (or C<Nil>) rather than
a type, then all top-level statements in the code block are evaluated
only for their side effects; in other words, all of the statements are
evaluated in sink context, including the final statement. An explicit
@@ -1068,7 +1068,8 @@ Named parameters are optional unless marked with a following C<!>.
Default values for optional named parameters are defined in the same
way as for positional parameters, but may depend only on existing
values, including the values of parameters that have already been
-bound. Named optional parameters default to C<Nil> if they have
+bound. Named optional parameters default to C<Nil> (that is, they
+set the default of the container) if they have
no default. Named required parameters fail unless an argument pair
of that name is supplied.
@@ -3086,7 +3087,8 @@ already bound to the corresponding parameters:
Position parameters may also be primed. To skip a position argument,
pass a C<*>, which is handled specially by C<.assuming>. Passing a
C<Nil> causes priming with the default argument supplied with the
-parameter at that position in the signature, or an undefined value if
+parameter at that position in the signature, or the (presumably undefined) default
+value for the container associated with the parameter if
the parameter in question has no default. C<Nil> may also be passed
to a named argument to force priming to the default.
View
@@ -233,7 +233,7 @@ It is allowed for such a range to start one after the end, so that
@array[0..*]
-merely returns Nil if C<@array> happens to be empty. However,
+merely returns C<()> if C<@array> happens to be empty. However,
@array[1..*]

0 comments on commit 48958ab

Please sign in to comment.