in reply to Lists and Arrays and Boredom

'Some people say a ... is a value.' => 'l'
'Some people say a ... is a variable.' => 'a'

Badly formed question (based on weak source text). Any answer is correct because the very fact of answering the question means at least one person says it.

'You put things into ... context.' => 'l'

s/put things into/evaluate expressions in/

Expressions are evaluated in a context, not put into a context. For example, the expression "@array" evaluates to something based on context. It doesn't evaluate to something that's put into scalar context. (What would that something be? Can't be a list, cause there's no such thing as a list in scalar context.)

perlsub uses the correct terminology.

'You initialize a ... with a list.' => 'a'

You can also initialize a list with a list.

'You initialize an array with a ... ' => 'l'

In theory, I find perfectly acceptable to read "@a=@b" as "initializing array @a with array @b", so both answers would be acceptable to me.

In practice, the implementation of aassign would determine whether you can assign an array to an array.

'You "foreach()" across a ... ' => 'l'

In theory, that is the view that's presented.

In practice, not necessarily. There are many different for loops. Some don't create a list (such as for (x..y) and for (@array)), and one iterates over an array (for (@array)).

Note that you used the practical answer earlier and the theoretical answer here, which just adds to the confusion.

'A ... in scalar context behaves like the number of elements in it.' => 'a'

s/behaves like/evaluates to/, like above.

Replies are listed 'Best First'.
Re^2: Lists and Arrays and Boredom
by carol (Beadle) on May 17, 2008 at 20:14 UTC
    Thanks for your comments. The source text was a recent FAQ posting in comp.lang.perl.misc. The maintainers will be interested in your thoughts.
    There are many different for loops. Some don't create a list (such as for (x..y) and for (@array)), and one iterates over an array (for (@array))
    Isn't the array evaluated in list context and the for loop iterated over a list?

      Isn't the array evaluated in list context and the for loop iterated over a list?

      No, it's optimized. You'll notice if you add elements to the array from within the loop, the loop will iterate over them too. That's wouldn't be possible if the array had been flattened to a list (as it is in the second program below) since changing the array would have no effect on the list.

      >perl -le"@a=qw(a b); for (@a) { push @a, 'c' if /a/; print }" a b c >perl -le"@a=qw(a b); for (@a,()) { push @a, 'c' if /a/; print }" a b

      The maintainers will be interested in your thoughts.

      I might do that for "put in context" vs "evaluated in context". The rest of the comments don't apply to the FAQ. You made bad assumptions that if the FAQ mentions something about lists, it can't be the case for arrays as well (and vice-versa).

        Thank you for your explanation.
        You made bad assumptions that if the FAQ mentions something about lists, it can't be the case for arrays as well (and vice-versa).
        I did not make such an assumption at all.