Reverse a list

Bob Sneidar bobsneidar at
Mon Feb 16 11:06:06 EST 2015

The For Each form is also quite handy as it eliminates the need for stuffing some variables in the process. As mentioned in past threads, the one downside is that you *MUST* not change the contents of the source data (and I think the each variable as well) as doing so will corrupt what ends up in the each variable.

The reason for this (and the reason this form works so fast) is that LC takes the actual contents of what you are parsing, and goes through it one time, creating memory pointers at the delimiters. Other repeat forms will have to search through the variable on each iteration and find the next delimit point. Find line 1, find line 2, etc.

Since the data you are parsing has an index of memory pointers, you can imagine the hell that would ensue if all of a sudden you change the contents of that data. The pointers will no longer be valid, and in fact it is highly likely that LC will alter the memory location of the parsed data, so that your pointers will now point at random noise.

Bob S

On Feb 14, 2015, at 15:00 , Richard Gaskin <ambassador at<mailto:ambassador at>> wrote:

The Dictionary entry for "repeat" notes that the "for each" form is much faster than "with".

> and how come this is the first time I remember EVER hearing about this
> difference?

Good question.  This comes up in the forums and/or this list almost every month or so.

The speed difference will vary according to the size of each line and the size of the lines, but "order of magnitude" is usually a pretty fair minimal expectation for the speed boost with this.

More information about the use-livecode mailing list