develooper Front page | perl.perl6.documentation | Postings from December 2002

Re: Stringification of references and objects.

Thread Previous | Thread Next
From:
Larry Wall
Date:
December 6, 2002 10:22
Subject:
Re: Stringification of references and objects.
Message ID:
20021206182205.GA23288@wall.org
On Fri, Dec 06, 2002 at 10:40:18AM -0500, Dan Sugalski wrote:
: If an aggregate and a reference to an aggregate are going to behave 
: the same, which is what Larry's indicated in the past, then 
: stringifying a reference should be the same as stringifying its 
: referent.

This is a bit of an oversimplification.  $foo and @foo do not always
behave the same, even if $foo and @foo refer to the same array object.
In particular, $foo doesn't behave like @foo in a list context.
Scalars must continue to behave like scalars in list context, even
if they're internally composite.  As in Perl 5, if you say

    for $foo {...}

the sub only gets one argument, the array ref, but if you say

    for @foo {...}

or

    for @$foo {...}

you get all of the elements.

But it's probably fair to say that $foo and @foo always behave
identically in a scalar context.

We may, in fact, have to deprecate the term "list context" and replace
it with something like "flattening context", since we can have lists
of scalars that are in some sense in a "list context" but that aren't
in a flattening context:

    my ($a,@b,%c) := (@a,$b,%c);

But "flattening" is a lousy word.  It's really more of a "variadic"
context, but that's no improvement.

At the moment I can't think of anything better than "splat" context...

Larry

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About