@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 reply to Re: Some Insights from a Traveler Between Languages
by jonadab
in thread Some Insights from a Traveler Between Languages
by skyknight
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |