in reply to Re^5: Perl vs C
in thread Perl vs C

1,2,3 is a list literal aka list operator. It may evaluate to a list of its items or to its last item.

@xyz is an array. As an operator, it may evaluate to a list of its elements or to its number of elements.

But the problems is, is that this confuses folks.

That's to be expected. "An array with a list" makes no sense. Arrays have elements, not lists.

How is the incorrect "@xyz is a list" any simpler than the correct "@xyz is an array"? "List" is already overloaded enough. You're doing yourself and your readers a disservice by calling arrays lists.

Replies are listed 'Best First'.
Re^7: Perl vs C
by Marshall (Canon) on Mar 16, 2009 at 11:11 UTC
    I think the main point here is that in Perl, an variable like: @array is very different than a C, Basic, Fortran or what ever array. The Perl list is very much like a linked list, but not quite. My analogy wasn't great. I don't know of a language that has a thing like a Perl list. You can push things onto the end of a Perl list, pop things from the bottom (like LIFO queue), even do the same things at the "top" of the list - hey that's what the common "shift" does!. Also it is possible to insert things in the middle, take things out of the middle. None of of those things are possible with a traditional simple "array", but are common with linked lists in C. A Perl list has all these properties and it can be sorted easily! Whoa!

    In Perl I would call an "array" of lists, a List of Lists, (LoL). This is a list of references to other lists.

    In C the most flexible representation of a 2-d numeric matrix is an array of pointer to arrays of ints. In Perl this is just a LoL, List of List.

    Since a Perl list has fundamentally different properties from a traditional "array" in other languages, I see no reason not to call this a "list".

      I think the main point here is that in Perl, an variable like: @array is very different than a C, Basic, Fortran or what ever array.

      The only difference is that it can change in size, like in C++ (vector), Java (Array), JavaScript (Array), .NET (ArrayList).

      Since you summarized your point, I'll do the same. Redefining commonly used terms (particularly the already overloaded term "list") doesn't help at all, and greatly hinders communication to the point where you're spreading misinformation.

      • There's no such thing as lists of lists in Perl. (1,2,(3,4,5),6,7) is the same thing as (1,2,3,4,5,6,7).
      • You can't use push or shift on a list. It results in a syntax error.

      If you absolutely must have another name for arrays, consider using vector (as per C++). Still confusing, but not nearly as ambiguous.

      A reply falls below the community's threshold of quality. You may see it by logging in.