[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: exists $foo[7] and delete $foo[7]



Tom Christiansen wrote:
> 
> >You keep saying "array elements' scalar values" as though there
> >were array elements that weren't scalar values.  Is there something
> >I'm missing?
> 
> No.  Simply that scalar values occur in several places, including
> in scalar variables like $scalar, as elements in $array[N] or
> $hash{KEY}, or as temporary values in expression or return values
> from functions.  I'd like that something I can do to a scalar value
> in one place (e.g. defined) be applicable to a scalar value in all
> places that scalar values can occur.

Huh? delete() would operate on an array, not on the scalar which is an
element of the array.

But you bring up the issue of whether delete $x should be equivalent to
delete $::{x}.

1/2 ;)

Then should

$x = 1;
delete $x;
$x = 2;

issue two warnings?

Explaining delete $x[3] doesn't strike me as very difficult, unless I'm
misunderstanding something.

@x = qw(a b c d); delete $x[2]

has the same effect as @x[0,1,3] = qw(a b d). Referring to a nonexistent
value returns undef, which is just a convenience that's always existed.
exists $x[2] is not pronounced "let v be the value of $x[2]; does v
exist?". It is pronounced "does the array @x contain a value at offset
2?" @x = qw(a b c d); delete $x[3] of course shortens @x to three
elements -- @x doesn't contain a value at offset 3 any more than it
contains a value at offset 3823. scalar(@x) is a little messy, as it's
always been, because it doesn't really mean "how many elements does @x
contain?"; you could describe it as "if you put dots on a line wherever
@x has an element, how long of a line would you need?" $#x is
unproblematic, it's the index of the last element of @x as always.

My vote is no for 5.6. p5p isn't comfortable enough with the pseudohash
interface yet. I know I'm not. So I'd hate to lose the error on delete
$x[3] just to support what is possibly the wrong interface. It may be
the right thing to do even ignoring pseudohashes, but it's too late to
decide something like that for 5.6.

I respectfully decline to vote for whether it should be included for
pseudohashes only in 5.6, or for whether it should be included in
anything post-5.6.


Follow-Ups from:
pete@horus.cix.co.uk (Pete Jordan)
References to:
Tom Christiansen <tchrist@chthon.perl.com>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]