>>>>> "ML" == Michael Lazzaro <[EMAIL PROTECTED]> writes:

  ML> On Friday, February 7, 2003, at 02:07  PM, Uri Guttman wrote:
  >> the whole notion is that lists are always temporary and arrays can
  >> be as
  >> permanent as you want (an array ref going quickly out of scope is very
  >> temporary). lists can't live beyond the current expression but
  >> arrays can.

  ML> Along those lines, the closest I've been able to come so far to a
  ML> usable two-sentence definition is:

  ML> -- A list is an ordered set of scalar values.
  ML> -- An array is an object that stores a list.

but you can't derive the rules about allowing push/pop/splice/slice from
that pair of defintions.

you can simplify my pair to:

a list is temporary ordered set of scalar values that lives only in a
single expression

an array is an ordered set of scalar values that is allocated and can
live between expressions.

note that i said expression and not statement. you can't have the same
list in two parts of an expression while you can with an array (ref or
plain). that implies you can't change a list since it only exists once.

another (and shorter pair) is this:
(note that this is from the whole list point of view, not its elements)

lists are read only 
arrays are read/write

that allows slices on lists but not push/pop/splice. the lvalueness of
their elements doesn't matter.


the two sets of pairs above can be combined for clarity:
(again these are from the whole list/array point of view)

a list lives in a single place in a single expression and can't be
modified.

an array can live in multiple places in multiple expressions and can be
changed

the single place makes it impossible to take a ref to a list. the
multiple places for an array implies references are possible. the array
can be changed since it has state that will store the change. a list has
no such state as it will die when the expression is done.

uri

-- 
Uri Guttman  ------  [EMAIL PROTECTED]  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class

Reply via email to