Delete the first entry of an array.

Mike Bonner bonnmike at gmail.com
Fri Mar 25 08:51:40 EDT 2016


Leave things as they are, delete the first element, and keep track of an
offset value that you use to grab array elements.  If your array starts at
1, and you haven't deleted any elements from the front, the offset is 0.
If you delete 2 items, from the front, the offset is 2.  If you want to
access the 4th element, it would be arrayval[itemnum+offset]  You could
generate the offset by grabbing the keylist, sorting it, and grabbing the
first key - 1 (or use min() -1) but it would probably be far more efficient
to just keep track as you go.  You could keep the offset value in the array
too.

Of course, this doesn't help if you are removing elements from the middle
of the numerically indexed array too.  (in which case it would just make
sense to keep a sorted list of keys and preform duplicate operations on the
list. Then you can use line 3 of the keylist  as your array key for the
proper item.

Having said all that, I'm all for a feature exchange to make this sort of
thing easier.  Yes please! (I don't have much discretionary spending moola,
but this one would garner some of it)

On Fri, Mar 25, 2016 at 4:25 AM, Peter W A Wood <peterwawood at gmail.com>
wrote:

> Thanks Kay
>
> > On 25 Mar 2016, at 17:22, Kay C Lan <lan.kc.macmail at gmail.com> wrote:
> >
> > On Fri, Mar 25, 2016 at 3:33 PM, Peter W A Wood <peterwawood at gmail.com>
> wrote:
> >
> >>  delete pList[“numbers”] 1                                     ## Is
> this the correct syntax?
> >
> > No. Shouldn't it be:
> >
> > delete variable pList["number"][1]
> >
> > At least that works for me, although in your case I think, if I
> > understand it correctly, I'd tackle the problem by: (suedo-code)
> >
> > repeat with x = 2 to the number of keys in firstArray
> >  put firstArray[x] into secondArray[x - 1]
> > end repeat
> > put secondArray into firstArray
>
>
> I do something like this at the moment. I was trying to see if there was
> an easier/quicker way.
>
> Kind regards
>
> Peter
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list