Container Math

Hello All–

Is there a way, in SenseTalk, to do something like this Ruby (or Perl) code?

array1 = {"one","four","seven","10"}
array2 = {"one","four","seven","Ten"}

array3 = array1 - array2

puts array3 
--> ["10","Ten"]

I’m diffing a couple of text files. I would log a pass iff array3 is empty, otherwise log a failure. I would love it if I could streamline it down to something like this:

put remoteClipboard() into container1
put file "baseline.txt" into container2

set container3 to (container1-container2)

if container3 is not empty then logwarning "Programmer Error!"

From your example, it looks like you’re trying to get a list of all of the items that are present in only one of the two lists. Here’s one way to do it:

set array1 = {"one","four","seven","10"} 
set array2 = {"one","four","seven","Ten"}

put uniqueItems(array1, array2)

to handle uniqueItems list1, list2
	repeat with each item of list1
		if it is not in list2 then insert it into uniques
	end repeat
	repeat with each item of list2
		if it is not in list1 then insert it into uniques
	end repeat
	return uniques
end uniqueItems

If the lists are coming from the remote clipboard and from a text file, keep in mind that the values you get will be text, so you’ll have to use the value() function, or maybe the split command, to turn the text into a list before calling uniqueItems.

This works!

Thanks Doug.