@biz = [1, 2, 3];
In the fourth case, you end up with an array of just one element, and that element is a reference to the array that was on the RHS. Ugh... Not having mentally transitioned from Python, I fell for the trap of the fourth case.

In other words, you used the punctuation you would have used in the other language, but it meant something rather different in Perl. This is unavoidable when going from language to language, unless the syntax is so *completely* different that it doesn't overlap at all (e.g., moving from elisp to Perl does not cause this problem in my experience, because the syntax in elisp is impossible to confuse with Perl's). I assert that you would have the same type of problem suddenly moving from Perl to Python, or Perl to Ruby, or Ruby to Python, or Python to C++, or C++ to Inform, or cetera.

So, what is Perl's justification for having these latter two cases?

The third case is arguable; it's there for convenience, and it's mightily convenient, and I use it with quite significant frequency, but yes, needing to do an explicit length would not be the end of the universe.

The fourth case, OTOH, is another matter; I do not see how it would be possible for Perl to get by without the ability to assign references. Doing away with that would make Perl quite a lot less useful than it is. We're not talking about syntactic sugar here; it is absolutely *necessary* to be able to assign a reference to an annonymous array into a variable. The fact that the syntax used to do that doesn't mean the same thing in all programming languages is just a symptom of the fact that not all programming languages are identical.

So, why is length(@foo) perfectly acceptable syntax? Furthermore, since it is valid syntax, why does it do something so thoroughly dumbfounding?

Yes, I agree that length should have been overloaded. Even though there's a shorter way to take the length of an array, being able to do it explicitely would not have been a bad thing.

The Perl6 approach to fixing this is to do away with length altogether; instead you will specify $string.bytes if that is what you want, or, if your characters might not all be a single byte long, $string.graphemes or $string.codepoints or some other Unicode-related thing. For arrays, I think there will be @array.elems or somesuch. Note that this still won't solve the problem of different languages having different syntax; indeed, I expect moving back and forth between Perl5 and Perl6 to be rather painful at times.


"In adjectives, with the addition of inflectional endings, a changeable long vowel (Qamets or Tsere) in an open, propretonic syllable will reduce to Vocal Shewa. This type of change occurs when the open, pretonic syllable of the masculine singular adjective becomes propretonic with the addition of inflectional endings."  — Pratico & Van Pelt, BBHG, p68

In reply to Re: Some Insights from a Traveler Between Languages by jonadab
in thread Some Insights from a Traveler Between Languages by skyknight

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.