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

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



>>Could you please distinguish
>>this from "undefined"?

>You can assign an undefined _value_ to something.  But there's no concept
>of assigning an uninitialized _value_, because it is an attribute (or
>state of being).

>IOW, "uninitialized" is a stronger particular condition than "undefined".

>>Can only the scalar elements in an array
>>be uninitialized?

This is disconcerting.  In Perl lingo, we have always used the terms
"undefined" and "uninitialized" interchangeably when it came to
scalar values.

    % perl -wle 'print $a + $a' (y|n|e|a)? yes
    Use of uninitialized value at -e line 1.
    Use of uninitialized value at -e line 1.
    0

    % perl -wle 'print $H{a} + $H{a}'
    Use of uninitialized value at -e line 1.
    Use of uninitialized value at -e line 1.
    0

    % perl -wle '%H = ("a",undef); print $H{a} + $H{a}'
    Use of uninitialized value at -e line 1.
    Use of uninitialized value at -e line 1.
    0

    % perl -wle '%H = ("a",undef); print $H{a} + $H{a}; delete $H{a}; print $H{a} + $H{a};'
    Use of uninitialized value at -e line 1.
    Use of uninitialized value at -e line 1.
    0
    Use of uninitialized value at -e line 1.
    Use of uninitialized value at -e line 1.
    0

I believe there is firm precedent for understanding uninitialized
to mean undefined.  Furthermore, it would appear that introducing
a nuance between these that operating in some cases (on array
elements' scalar values) but not on others (on non-aggregate scalar
values) offers no sufficiently redeeming advantage that I have been
able to gleen which would offset the added complexity.

>>Is this all arrays, or only pseudo-hashes?
>All arrays and all pseudo-hashes.

>>What about the scalar elements in a hash?
>The change does not affect hashes.

>>Can they also be uninitialized?
>Yes, using delete() as we've always been able.

No, we've not been able to call delete() on anything but
hash elements before.

>>How does this different from a nonexistent value (undef $h{K}) or
>>a nonexistent key (delete $h{K})?

>It is the same as the difference between:
>    $h{K} = undef;  or undef $h{K};
>                vs.
>            delete $h{K}

>>Can we now delete any scalar,
>>or only elements of aggregates;

>delete() only works on elements of arrays, pseudo-hashes, and hashes.
>I don't know what it should mean on "any scalar".

>>and what about functions?
>I don't think I understand the question.  Please rephrase.

>>Can we
>>now say exists on any scalar, or only on elements of aggregates;
>exists() only works on elements of arrays, pseudo-hashes, and hashes.

>>and again, what about functions?
>I don't think I understand the question.  Please rephrase.

There's plenty of precendent that it is not intuitive to what kinds
of items you can or cannot apply exists(), defined(), undef(), or
defined().  I can check whether a scalar is defined, or a function,
but not an array or a hash or a filehandle or a package.  I can
undefine scalars if they're stand-alone or in an array or hash, and
I can also undefine arrays or hashes, but not handles or packages.
It would come as no surprise if adding the ability to use exists()
and delete() on separate elements of an array will make people want
to use them on other types of things as well, like single scalars,
handles, functions, or packages.

>>The nature of truth is becoming very blurred in my own mind, at least.

>I think I agree, but the notion of "whether an element truly exists" is
>not new.  We've had it all along for hash elements.

Why do we *care* whether space for a scalar has ever been allocated
in an array?  And if we do care so much about that, why don't we
care whether space for a scalar that's *not* in an array has ever
been allocated?  

    @array = qw/zero one two three/, undef, 'five';

Why do we care to distinguish between $array[4] and $array[17] above?
IF we undef $array[1], why should that be different that the status 
fo $array[17]?  Is there some reason why people shouldn't be expected
to simply write an expression like

	(@array < $N && defined $array[$N])

I am quite comfortable with delete and exists only applying to
hashes.  I do not understand why making them work on pseudo-hashes
requires that their semantic be stretched to cover arrays as well.
Please hit me over the head once or twice more; maybe I'll understand
then.

thanks,

--tom


Follow-Ups from:
Ted Ashton <ashted@southern.edu>
Gurusamy Sarathy <gsar@activestate.com>
"Matthias Urlichs" <smurf@noris.net>

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