I'm also not sure I understand the motive for optimization at this point (2,3)-- it seems premature... but I will defer to your experience.

Thank-you. ;-)

The point is not to actually insist on optimisation at present (though part of our motivation in cleaning up the Perl syntax is to make more optimizations possible). The point is to avoid making changes now that make later optimisations impossible. Which is what unifying arrays and hashes would do.

I am certain I haven't had any problems keeping my Ruby hashes and arrays separate (4)

I'm sure. But we don't just design for programmers as clueful and competent as you. We have to consider the common mistakes made by the vast majority of Perl programmers -- whose level of experience and ability is quite low. And then consider how the changes we propose will affect them.

In my (considerable) experience with such programmers, one of their most frequent difficulties is distinguishing between container types. I've published research1 that indicates that removing syntactic cues to the differences between data types (as the Turing language did, for example) makes that problem far worse.

As to 5, I think I'll wait for Ex5, since I've not yet internalized A5, but I don't see how the brackets/brace is a problem if you are assigning a series of key/values to a hash

It isn't. In that particular case.

But that's not what I was talking about. I was talking about the case where a regex returns a "match object" (either directly, or via $0):

$match = m/complex pattern/; # match object in $match m/complex pattern>; # match object in $0

Now array accesses on (say) $match give you the numbered captures:

print "$match[1] was val for $match[0]\n"; my ($key,$val) = (0,1); print "$match[$val] was val for $match[$key]\n";

Whereas hash accesses on it give you the named captures:

print "$match{val} was val for $match{key}\n"; my ($key,$val) = ("key", "val"); print "$match{$val} was val for $match{$key}\n";

But if there's no syntactic distinction between arrays and hashes (represented here by a hypothetical, unified $match<...> accessor), how do you distinguish between hash-like and array-like look-ups on non-literal keys:

print "$match<0> was val for $match<1>\n"; # array look-u +p print "$match<'val'> was val for $match<'key'>\n"; # hash look-up print "$match<$val> was val for $match<$key>\n"; # ???

Deciding that last case on the basis of run-time type of the values in $val and $key is both much slower, and vastly more error prone (in light of Perl's free-and-easy interconversion of numbers and strings).

So people will be generally forced to make the distinction explicit anyway:

print "$match<$val> was val for $match<$key>\n"; # ??? print "$match<+$val> was val for $match<+$key>\n"; # array look-u +p print "$match<_$val> was val for $match<_$key>\n"; # hash look-up

Which is far worse than what we have now.


  1. They didn't select me to help Larry design Perl 6 just because I'm even weirder than he is, you know! Well, not solely on that basis, at least. ;-)

In reply to Re: (ichi) Re x 4: Apocalypse 5 and regexes by TheDamian
in thread Apocalypse 5 and regexes by c-era

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.