Reverse a list

Mike Kerner MikeKerner at roadrunner.com
Mon Feb 16 22:02:22 CET 2015


I don't think I follow on the first part.  Edinburgh says that the
complexity of the two traversals are dramatically different.  repeat for
each is somewhere between nlogn and n, and repeat with is n^2.  At least
for the case of your squares of integers, I would expect that there is a
crossover where it's going to be faster to build the list, first.  I don't
know if that is at 100, 1000, or some bigger number, but n vs. n^2 is a
very big difference.

On Mon, Feb 16, 2015 at 2:51 PM, Ben Rubinstein <benr_mc at cogapp.com> wrote:

> On 15/02/2015 02:28, Mike Kerner wrote:
>
>> I just read the dictionary entry (again), and I would say that it is not
>> at
>> all clear that there would appear to be an ENORMOUS difference.  For
>> starters, you have to read waaaaaaaay down to find the mention, it isn't
>> really called out with a NOTE or anything else to draw one's attention to
>> it, and it is definitely understated.  Even mentioning "order of
>> magnitude"
>> would be better (although it would appear to be an understatement).  I
>> literally had no idea until I ran into this, by accident, and was
>> exchanging notes with Peter.  The difference is staggering, and it really
>> should be made much more obvious.
>>
>
> I think that we need to be clear that it's not true that "repeat with" is
> massively faster than "repeat for".  They're not comparable, they're doing
> different things.
>
> What _is_ true is that if you want to iterate over the chunks of a
> variable, the most efficient way to do that is using the "repeat for each"
> construction.  But there's nothing inherently faster in the loop form, it's
> what you do with it that counts.  If you wanted to print the squares of the
> first 100 integers, "repeat with n = 1 to 100" is the way to go - don't
> make a list of those 100 integers so that you can use "repeat for each" on
> it.
>
> I'm not saying the documentation is perfect, far from it.  But what it
> says on this topic is accurate, i.e. "*if* you want to perform an action on
> each chunk in a container. This form is much faster than ... with".
>
> On 14/02/2015 22:00, Mike Kerner wrote:
>
>> You would think that Edinburgh would think about tweaking an algorithm,
>> since REPEAT WITH seems to be a special case of REPEAT FOR, and you can
>> generate the REPEAT WITH behavior by wrapping the REPEAT FOR...
>>
>
> That's exactly what (Scott Raney) did, back in the mists of time.  He
> wrote extra code to make iterating over the chunks of a variable
> exceptionally fast; and added syntax for the programmer to indicate that
> they wanted to use this algorithm (which has other disadvantages).
>
> REPEAT WITH is certainly not a special case of REPEAT FOR EACH (note
> 'repeat for' is actually something else); it's closer to the other way
> round, that is REPEAT FOR EACH could be regarded as a specialisation for a
> common case otherwise handled by REPEAT WITH.
>
> Ben
>
>
> _______________________________________________
> 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
>



-- 
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
   and did a little diving.
And God said, "This is good."


More information about the use-livecode mailing list