Delete an Array Entry?

Jim Ault JimAultWins at yahoo.com
Thu Mar 1 15:00:16 EST 2007


I agree with the versatility of associative arrays, but the conventional
array uses different functions, like in Flash, so the following may help a
new user who has experience in other programming languages.

(Forget for today abut 0-based versus 1-based array addressing)

Flash
Deleting imgArr[17] in an array of 29 elements would mean that there would
still be a 17th element, just a different content.  There would now be 28
elements.

Rev
In Rev, unless you work with a system for accessing associative arrays to
allow 'positional' references, the imgArr[17] notation won't get you where
you think.

However, in Rev, we use a natural language equivalent to the Flash array
style by referring to card 3 of this stack, line 23 of field 1 of card 9 of
this stack.  Think about what happens if you...

delete card 6 of this stack
set the name of card 6 of this stack to "User Notes"
delete card "User Notes" of this stack
put empty into line 10 of field "17"
--oops should not name fields by the numbering system, eh?  Which is it..
the 17th field or field named "17".  This is an example of positional vs
associative reference.

Most programs that use array access are like the Rev card-field-button
numbering, (1 to the number of buttons = 1 to the number of elements).
Delete button 17 on a card with 29 buttons, there are 28 buttons, and there
is a 17th button but it has a different id and probably a different name.

In Flash, using functions like pop, push, split, join to manipulate arrays
work on the basis of the 'order' in the array, rather than the 'key'.
Length(imgArr) is an important number for a programmer since it is an error
to refer to an element greater than the length of the array.  Just like
button 99 when there isn't one.

This leads to "associative and explicit confusion".  Flash has no
associative arrays, Rev has no 'positional' arrays.  You need to build your
loops and error checks differently.  Matrices, memory space in RAM and many
other operations are based on positional arrays.

I sure hope this helps someone...  It took me awhile to be able to 'get'
associative arrays.  To be fair about the documentation, it is difficult for
an experienced array user to suspend his previous concepts to absorb the
different way of thinking.  The documentation is correct, but the users
frame of reference is askew.  Kinda like the first-time TV viewer who
wonders how that person got inside such a small box.

Jim Ault
Las Vegas






More information about the use-livecode mailing list