On Thu, Nov 14, 2002 at 02:29:38PM -0600, Garrett Goebel wrote:
> It is interesting that no one has yet taken the time to start defining the
> terms we're using.

Good point.  I volunteered to be keeper of the glossary a while ago,
but I never actively started creating one.  That said, let's make this
the first entry.  Comments and constructive criticisms welcomed from
all comers.

--------------------
Term:   literal

Definition: A literal is a way of writing a particular fixed
value. For example, 65 (decimal), b1000001 (binary), and 0x41
(hexadecimal) are all literals, are all constants, and are each a
different representation of the same fixed value.

Sometimes literals come in groups...most commonly in lists or arrays.
An example of a list of literals would be: (1, 2, 3). An example of an
array of literals would be: ['a', 'b', 'c'].  (*)

Note that there is a subtle difference between saying an "array of
literals" and a "literal array".  An array of literals is simply an
array that happens to contain nothing but literals.  A literal array
is a more slippery concept since an array is actually three things
strung together: a name, a memoryspace that acts as a container, and a
value (see the L<array> entry for more information).  Of these, the
name is a literal, the container is not a literal, and the values
stored in the container may or may not be literals.  (In the example
given in the L<array> section, the values 7 and 'a' are literals,
while $quux is not.)

Examples of literals: 7, 3.1415926535897932384, 'Fourscore and seven',
0xDEADBEEF, b10100011, 'z'.

Examples of non-literals: $foo, @bar, %baz, jaz()

--------------------

Term:  array

Definition: An array is a collection of Perl L<literals> and/or
variables, indexed by number using square brackets, where the first
index is 0.  Therefore, you would say @myarray[0] to retrieve the
first element, @myarray[1] to retrieve the second, and so on.

On a deeper level, an array is actually three things at once:  it is a
name, a container, and a collection of values.  For example, an array
@a which contained the values 7, 'a', and $quux would look like this:

    Name:       @a
                |
    Container:  +--------+--------+
                |        |        |
    Values:    (7)      (a)    ($quux)

Here we see that the name of this array is '@a', the name is
associated with a container in memory, and that there are currently
three values in that container.  The first two of these values are
L<literals> (specifically, the number 7 and the letter 'a'), but the
third item is another container:  a L<scalar> variable named $quux.

When accessed with an index that is a positive integer N, an array
will access the element at the N-1th place (because, remember, indices
start with 0).  When accessed with an index that is a B<negative>
integer M, an array will access the element that is at position M+1
from the B<end> of the array.  Therefore, @array[-1] returns the last
element, @array[-2] returns the second to last element, and so on.

Arrays know how to manage their own size; they will grow and shrink as
needed when you add or remove elements.  You never need to worry about
whether an array has enough space to hold the number of elements you
are about to insert.

(***)

Examples of arrays (usage):  
       @foo = (1, 2,3);  # create/init an array
       @foo[2];          # fetch last element
       @foo[-1];         # fetch last element
       undef @foo;       # destroy array, free associated memory,
                         #    and decrement reference count on each
                         #    value

--------------------


NOTES:  


(*) There was a long thread a little while ago on how arrays would be
written.  I believe the final decision was that [] was the array
composer, but I'm not sure.  Can someone confirm or deny this for me?
(I'll go dig through the archives after I send this, but if someone
knows offhand, it would save time.)

(**) There needs to be a point here explaining the difference between
"list of literals" and "literal list" (and the same for arrays), but I
find that I don't understand it well enough myself to explain it.

(***) I feel like there should be some discussion here of the fact
that an array is "really" a reference, and that when you pass it or
assign it, you are really assigning the reference--I'm just not quite
sure how to put it.  Any suggestions?


Also, a couple of questions:

First, when I originally started writing these entries, they were
substantially shorter.  As I look at them now, I wonder if I haven't
written something that is too long for a glossary entry, and would
better be used for main documentation (or bird cage liner, if you are
unkind)--what do you all think?



Second, what format should this document be kept in?  I know that POD
is the standard, but I feel that POD by itself is a poor fit for a
glossary, since a glossary needs very little presentation but a lot of
structure (for example, you want to group the definition with the
term, and you might want to include attributes--is this a beginner,
intermediate, advanced, or gurus-only concept?  Does this term refer
to a core language concept, or is it used primarily in a module?
Which module? And so on....).

Does anyone strongly object if I keep it in a mixture of XML and POD
(that is, XML containing POD)?  If so, what should I keep it in?  If
not, does anyone have suggestions on what attributes we should have?



Finally, and most importantly: many thanks to Arcadi for his excellent
summation of the component pieces of arrays/scalars/etc, which I have
blatantly stolen above.


--Dks


Reply via email to