develooper Front page | perl.perl6.language.data | Postings from October 2000

Re: Variable attributes (was Re: RFC 355 (v1) Leave $[ alone.)

Thread Next
From:
Jeremy Howard
Date:
October 1, 2000 14:39
Subject:
Re: Variable attributes (was Re: RFC 355 (v1) Leave $[ alone.)
Message ID:
004901c02bf0$e07d3020$c1252ccb@SAMANTHA
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.
>
That's exactly what we've proposed for compact multidimensional arrays, for
instance (from RFC 203):

<quote>
A list (of lists...) that contains elements of the same type can be
converted to an array by specifying its type:

  my @some_LOL = ([1,2],
                  [3,4]);
  my int @array = @some_LOL;
</quote>

I haven't got around to RFCing the more generic version (that all attributes
are inherited inside nested data types), but that would certainly be a nice
approach.



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