How do I clear a list?

A quick beginners question:

To empty a list that has grown up to hundreds of items, which code is recommend.
(I tried both and none of them seem to work!)

The second one should work and is the easiest approach.
Surprised to hear it doesn't work for you... test on a simple example?
Are you making a copy of the list in any way ?

2 Likes

Try to exchange "from" and "to" and set "by" to -1. Always clear a list from top to down.

2 Likes

The second should work, and the performance is much better than the first one.

1 Like

Thank you. It works. It was my fault somewhere else in the code.

1 Like

Try to exchange "from" and "to" and set "by" to -1. Always clear a list from top to down.

Thank you for the trick.
What about writing in a list? Is it better to "insert" into the beginning of the list, or add to the end of the list?

"to clear_mem1 do"- "set mem1 to" - "text " " " " " means blank

I do not know about the implementation of the list. Normally I would add to the end to avoid updating of lots of pointers or moving data around in memory. But chances are high it is designed as a (maybe doubly) linked list and a insert would just require setting of a few pointers/addresses. Should be no problem to do it the one or other way.

1 Like

AI2 default behaviour will add an item to the end of a list, this is in common with nearly all database systems.

3 Likes

liste sil