There should be a "unique" option on sort . . .

dunbarx at dunbarx at
Sun Jan 5 12:36:06 EST 2014


Did you mean something like this, for sorted data:

repeat with i = the number of lines of stuff down to 1
   if line i of stuff = line (i-1) of stuff then delete line i of stuff
next repeat

Another way would be to make an array, where placing an element of "stuff" into the array would simply overwrite any earlier placement. After that was all over, only one element of each kind would be in the array.

Not as fast, for sure, as some native implementation.


-----Original Message-----
From: Dr. Hawkins <dochawk at>
To: How to use LiveCode <use-livecode at>
Sent: Sun, Jan 5, 2014 11:19 am
Subject: Re: There should be a "unique" option on sort . . .

On Sat, Jan 4, 2014 at 8:54 PM, <dunbarx at> wrote:

> And in any case it is simple and fast to delete duplicates, if that is
> what is desired, in a few lines of code.
> The idea of singling out one instance seems more like a job for "filter".
I'd agree with that, too.

But "a few lines of code" is almost always going to be slower than
something actually built in.

What looks fastest to me (not tested) is

assuming sorted data:

repeat with i = the number of lines of stuff down to 1
   put line i of stuff into newLn
   if newLn = oldLn then delete line i of stuff
   put newLn into oldLn
next repeat

you could also

unsorted data:

repeat for each line line theLn in stuff
    if theLn is not among the lines of newStuff then put cr & theLn after
end repeat

Each of these, though, seems to be doing a search each time, while the info
was already there while the intrinsic sorted.

nice would be

repeat for each line theLn in stuff BACKWARDS

which would allow a single pass through, and an appending of non-unique
lines (with sorted data)
Dr. Richard E. Hawkins, Esq.
(702) 508-8462
use-livecode mailing list
use-livecode at
Please visit this url to subscribe, unsubscribe and manage your subscription 


More information about the Use-livecode mailing list