On Mon, 6 Aug 2001, Andrew Pimlott wrote:

> On Tue, Aug 07, 2001 at 12:27:50AM +0300, Ilmari Karonen wrote:
> > () is an empty list, and the fact that an empty list
> > constant evaluates to undef in *scalar* context is an explicit feature
> > of constant.pm.
> 
> It doesn't.  "()" isn't an empty list in scalar context.  "A list in
> scalar context" is nonsense in Perl terms.  This is not pedantic
> point.  From perlfunc,

Whoops, careless phrasing on my part.  The word "constant" above is
significant, and is meant to be part of the noun phrase "list constant",
which is what the constant.pm documentation calls a constant with more
(or less) than one scalar element as its value.

What you said, of course, is absolutely correct in general.


>     Remember the following important rule: There is B<no rule> that
>     relates the behavior of an expression in list context to its
>     behavior in scalar context, or vice versa.

However, constant.pm documents the particular rule that applies to the
constants defined with it.  It is essentially:

                 list context:     scalar context:
  no elements:     empty list        undef
  one element:     1-element list    the scalar element
  n>1 elements:    n-element list    (number n) 

The last behavior is documented as incidental, and may change in future
releases.  All the other cases, however, are guaranteed to be stable.
The stable cases also correspond exactly to the behavior you would get
if you defined your constants manually like this:

  sub CONSTANT_A () { return (); }
  sub CONSTANT_B () { return ('value'); }
  sub CONSTANT_C () { return ('one', 'two', 'three'); }

(This is why the last case sticks out, and may get fixed someday.)

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
"thinking about kinetic energies of a few tens of kps in this context is
 like thinking the swimming pool gets bigger if you pee in it"
                                 -- Conrad Hodson in rec.arts.sf.science


Reply via email to