At 04:39 PM 10/1/00 -0700, Peter Scott wrote:
>At 04:53 PM 10/1/00 -0400, Dan Sugalski wrote:
>>At 11:33 AM 10/1/00 -0700, Peter Scott wrote:
>>>But, setting aside my visceral reaction to changing array bases, you
>>>have precisely the same problem here that has scuppered my intent to
>>>file an RFC for hashes with fixed keys; how do you apply the attribute
>>>to anonymous, let alone autovivified, arrays? If I say
>>>
>>> my @a :base(1);
>>>
>>>then what of $a[1][1]? How to specify that the second level array also
>>>has a base of 1? Without it looking really ugly?
>>
>>Well, it'd be reasonable for autovivified arrays and hashes to inherit
>>the properties of their parent, so if you had:
>>
>> my int @foo;
>>
>>and accessed $foo[1][2], that new autovivified array would be of type int.
>
>Well, okay. This works better in the case of arrays, where it is much
>more likely that the programmer wants homogeneity, than in
>hashes. Consider a typical multicolumn database-type hash like:
[Snip]
>Clearly each level does not want the same restriction on its keys.
Yep. Neither would you want it for arrays of hashes or hashes of arrays.
(Though I do realize that's rather nonsensical) A 'nopropagate' attribute
might be in order, but that's kinda icky looking. Maybe forcing a
'propagate' attribute if you want the keys (or whatever) to propagate down
would be better.
>But the fact that my pet whim isn't supported by this proposal shouldn't
>detract from the advantages in other situations.
But it is an important thing to keep in mind. An idea that's 80% useful but
20% annoying needs rework.
>>As for anonymous hashes and arrays, there's no reason outside of
>>appearance that you coudn't tack on attributes after the closing
>>array/hash constructor:
>>
>> my $foo = [] : int;
>
>Looks good. What are the chances of the internals supporting user-defined
>attributes? What would the API look like?
Well, yeah, it'll sort of have to if we allow user-defined types. If you do:
my Dog $spot : male;
then the Dog package needs to be able to fetch the attributes. I've no idea
how that'd look--perhaps an attributes() function, a method in UNIVERSAL,
or something like that.
Dan
--------------------------------------"it's like this"-------------------
Dan Sugalski even samurai
[EMAIL PROTECTED] have teddy bears and even
teddy bears get drunk