Joseph F. Ryan wrote: > Stéphane Payrard wrote: > > > >I think that arrays and associative tables are very > >different entities for two reasons: > > -type of keys. array keys are integers > > -cost of insertion and deletion operations: O(n) and > > lower for associative table ( O(1) if you don't care > > for key ordering, O(log(n)) if you care for ordering). > > > >This is enough to warrant different syntaxes for arrays and hash. > > I'm sure I'll get shot for saying this, but no it doesn't. > PHP arrays are simply associative arrays with a integer as > the key value.
What was the reason again which Larry rejected unifying the syntax for array and hash indexing? As Piers said, we know whether $a is an array or hash reference when we do: print $a->{foo}; Someone correct me when I go astray... Currently in Perl6 you can assign an anonymous array or hash to a scalar as follows: $a = [1,2,3]; $b = {a => 1, b => 2}; or $a = array(1,2,3); $b = hash(a => 1, b => 2); If arrays and hashes both settled on []: $a = [1,2,3]; $b = [a => 1, b => 2]; or $a = array(1,2,3); $b = hash(a => 1, b => 2); It'd mess up the explicit list and hash composer syntax [] and {}. After all if unified, what's: $b = [a => 1, b => 2]; An anonymous array of ordered key/value pairs or an anonymous hash? If this could be resolved in a way which would allow us to translate our expectations of Perl5 arrays and hashes into Perl6... Wouldn't it give us a standard syntax for working with collections? So we could punt on Bags, Sets, Dictionaries, OrderedCollections, etc. and all the variations on arrays and hashes that people are suggesting. I.e., Deliver a version of standard Perl arrays and hashes... and make provisions for, but leave the rest out of the core. $bag = bag(1,2,1); print "ok" if 2 == scalar $bag->[1]; @a = (1,2,3); %h = (a => 1); %oh is ordered = (a => 1); ©c is bag = (1,2,1); # (C) symbol or some other sigil