Opposite of concatenation operator? (substracting from lists

What is the operator to substract from a list? “-” does not work as it tries to turn list items into numbers. Example:
set x to {“aaa”,“bbb”,“ccc”}
set y to {“ff”,“ccc”}
x & y adds up the lists, but what substracts?
set z to x - y does not work, as mentioned.
The result I am expecting is {“aaa”,“bbb”}

Thank you for your help


No such operators.

Unless you try XTools:

So to restate: you want a list containing every item of list x that is not in list y.

set x to {"aaa", "bbb", "ccc"}
set y to {"ff", "ccc"}

set z to DeleteItemsNotFound(x, y) --> {"aaa", "bbb"}

on DeleteItemsNotFound(mainList, searchList)
	set keepList to {}
	repeat with i from 1 to length of mainList
		set thisItem to item i of mainList
		if (thisItem is not in searchList) then
			set end of keepList to thisItem
		end if
	end repeat
	return keepList
end DeleteItemsNotFound

Um, OK, the handler could probably use a better name than “DeleteItemsNotFound.” :slight_smile:

Thank Arthur. It works great. But one has to wonder, why doesn’t Applescript just offer an operator to do that? After all they have “&” which does the opposite. It’s like having only “+” but not “-”. Applescript is so powerful, yet has so silly limitations.
Thanks again


Well strictly speaking, it doesn’t, of course. “&” is the concatenation operator. It doesn’t add items to lists or “add up” lists. It creates new objects that are notionally either lists joined end-to-end, or strings joined end-to-end, or merged records, or disparate items gathered into lists. The opposite of that is to split lists or strings (easily done) or to unmerge records.

Lists are structures whose items are referenced by their positions in the lists, not by their values. It’s also not possible to add or subtract items internally. If you want a list that contains the same values as another list unless these values appear (with others) in a third list, you have to write your own code.

I believe one or two “classic” OSAXen offered quick commands like that, but I don’t know if there are any for X.