Lists within lists & one line fun

I just read through Nigel’s handler and as always, it is great. After stepping through it I understand the function but don’t understand what got him started down that line of reasoning. Top notch.

That’s why old topics should be left alone unless it’s an 100% match with a better version/question…

Here is another approach, using my. This tests comparably to the TID versions; the timed portion took less than a second on my old G4.


--generic test list generation:
set thelist to {}
repeat with i from 1 to 2000
	set end of thelist to {"A" & i, "B" & i}
end repeat
-------------------------------------------------------------------------------------
set theTime to current date

set searchAgainst to "A1000"
repeat with pairIndex from 1 to count thelist
	if my thelist's item pairIndex contains searchAgainst then exit repeat
end repeat
tell thelist's item pairIndex to if item 2 is searchAgainst then
	item 1
else
	item 2
end if

{(current date) - theTime, pairIndex, result}

Hello!

That was a nice take, fairly efficent as well! :slight_smile: It is very useful, given that the data has the right consistency, regarding uniqueness.

I post an example of how I use the handler below, to program faster really. But the final solution is quite workable still, - and much more readable! The data here is not unique, but the handler is workable still, as the list is pruned.

The script is usable too, it closes duplicate Finder windows in the current space.

Edit
The final version of this script is posted in code exchange: MacScripter / Prune Duplicate Finder Windows in current space

The script above is updated and working.

Naming the lookup function singelton is very confusing with the term singleton which means in the IT sector something else and therefore confusing to me.

I have googled it for you :wink: Singleton (mathematics) - Wikipedia, the free encyclopedia It is term for a an entity with one element. Maybe not totally precise, but it denotes the fact that it can only be one attribute with that value, so I am perfectly happy with the name.

Maybe you ever wondered where the design pattern got its name from.

I was referring to the IT sector, that is where we at right? The English wiki tells the same as the Dutch Singleton. I wasn’t saying it’s wrong, just confuses me. You can’t argue with that :stuck_out_tongue:

I thought set theory was a part of the it-sector as well. :stuck_out_tongue: Well, a singleton can denote several things, like so many other terms. Here it is used as a description of a datastructure, other times as a pattern with just one class instance. It shouldn’t be to hard for you. As I use it, as I would use a pair, a dictionary, a vector, a tree, a hashmap or a heap, for that case: as a descriptor of a datastructure with the quality that all of the pairs contains unique values within the set.

If you don’t like the name the handler, then I’m sorry to hear that, but I find it descriptive as to what the handler returns. :slight_smile:

I’m not telling you to change it, and didn’t expect you to. Just saying that it can be confusing because singleton (in math) means just one element in a list/set/array. It means the same in the IT sector but element is an instance of an class and list is the application/process itself. Your list contains multiple items and the sub lists contains also multiple items so there is no singleton whatsoever. Singleton has nothing to do with uniqueness and if you want to use mathematical terms, in AS a singleton would be a list containing just one item.

I know I have to, and will, live with it :slight_smile: but maybe you can understand the confusing, it doesn’t meet either singleton requirements.

Hello!

Well, I see where you get at, what can I say, I gave it the name when we (or at least I) saw the potential of the handler to operate on a set of pairs with unique values, then I found the name to be quite descriptive.

Since then, the handler has proven to be very versatile, and also to operate good on sets with nonunique values, (with some preparation of the data in between calls).

But its true power is with lists of singularily unique values, like in dictionary, or a list of pairs (tuples), if you find that more precise. :slight_smile:

Hi!

The script in post #44 is updated to consider Spotlight windows, that threw a runtime error as they don’t have a name for their targets.

Hello!

I have updated the script in post #44 yet again, this time with some messages, displaying the progress.

This is the fast version.

Hi, McUsr.

Could you please stop bloating these fora with unecessary and/or irrelevant scripts and update announcements?

Sure. The script is still very useful, for people like me, that sometimes ends up with whole a slew of finder windows, some of them being duplicates. :slight_smile:

What can I say? It is so easy to just open a new window by the proxy icon of the documents. :wink: