[Year 12 SofDev] Records and Arrays

Guy Flaherty G.Flaherty at xavier.vic.edu.au
Thu Aug 19 22:39:42 EST 2010


Wikipedia uses the term 'element' instead of 'variable' as Adrian suggested. It clarifies this to explain an element can be a value or a variable. Would that be more appropriate? So an array is a collection of elements that are referenced through an index value. Additionally, it seems important that arrays be defined with a reference to using a contiguous block in memory to store the elements.

Guy Flaherty

>>> Steven Bird  19/08/10 9:39 PM >>>
On 19 August 2010 20:53, Janson, Adrian A <
janson.adrian.a at edumail.vic.gov.au> wrote:
> A one dimensional (or 1D) array is a data structure in which variables are
grouped together under the same name...

I see a couple of problems with this definition.  First, an array can group
together things which are not variables, i.e. literals, e.g. in Python:

>>> foo = [1, 1, 2, 3, 5, 8, 13, 21]
>>> bar = ["no", "variables", "here!"]

Second, an array is an array even if it doesn't have a name, e.g. in Python:

>>> my_function(["I", "don't", "have", "a", "name"])
>>> ["indexing", "a", "literal", "array"][2]

> A record is a structure that can be used to group together variables for a
particular purpose.

This definitions shares the first problem above, but it also brings in
something extraneous: "for a particular purpose".  Surely any data structure
serves some particular purpose intended for it by a programmer.

> Indexing the elements of a record is often done via an identifier which is
declared at the same time as the record.

This is true when the record is implemented as an associative array, but not
when it is represented as a tuple.  E.g. in Python:

>>> array_of_tuples = [(1441412050, 'Alice in Wonderland', 'Lewis Carroll'),
...     (1441412341, 'Through the Looking Glass', 'Lewis Carroll')]
>>> print array_of_tuples[1][2]
Lewis Carroll

Here we accessed an element of a record using an integer.  But you're
probably ok here since you said "often", and I agree with that.

-Steven Bird


Scanned by Sonar. 
Date: 2010-08-19 21:37:47.826
From: sofdev-bounces at edulists.com.au
To: g.flaherty at xavier.vic.edu.au
Profile: Default_In
Mail id: challenge-2217629470gf7-0



"This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the Network Manager at Xavier College. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Xavier College. Whilst every attempt has been made to ensure material in this email message is free from computer viruses or other defects, the attached files are provided, and may only be used, on the basis that the user assumes all responsibility for the use of the material transmitted."



More information about the sofdev mailing list