## Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

# Useful (I hope) List Logic Functions

Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
06-17-2007 18:08
Whilst develeping a reletivly complex script I descoverd that, although extensive, the list manipulaton functions in LSL were lacking logical functions, especialy those that can be used in Set Theory, so I developed the following functions to solve my problem and hope they are of use to others.
CODE
`//list logic//By Very Keynes - Please use or modify freely//list l1 = ["a","b","c","d"];			//test listslist l2 = ["a","1","b","2","c","3"];list ListXorY(list lx, list ly) // add the lists eleminating duplicates{	list lz = []; integer x;	for (x = 0; x < llGetListLength(ly); ++x)	{		if (~llListFindList(lx,llList2List(ly,x,x))){;}		else {lz = lz + llList2List(ly,x,x);}	}	return lx + lz;}list ListXandY(list lx, list ly) // return a list of elements common to both lists{	list lz = []; integer x;	for (x = 0; x < llGetListLength(ly); x++)	{		if (~llListFindList(lx,llList2List(ly,x,x))){lz = lz + llList2List(ly,x,x);}		else {;}	}	return lz;}list ListXnotY(list lx, list ly) // return elements in X that are not in Y{	list lz = []; integer x;	for (x = 0; x < llGetListLength(lx); x++)	{		if (~llListFindList(ly,llList2List(lx,x,x))){;}		else {lz = lz + llList2List(lx,x,x);}	}	return lz;}list ListXxorY(list lx, list ly) // reteurn elements that are in X or Y but not both{	return ListXnotY( lx,  ly) + ListXnotY( ly,  lx);}integer ListXequY(list lx, list ly){	if(llList2CSV(ListXnotY(lx,ly))=="")return TRUE;	else return FALSE;}	integer ListXneqY(list lx, list ly){	if(llList2CSV(ListXnotY(lx,ly))=="")return FALSE;	else return TRUE;}// Code used to test the abovedefault{	state_entry()	{		llOwnerSay("testing functions");		llOwnerSay("Elements in x = " + llList2CSV(l1));		llOwnerSay("Elements in y = " + llList2CSV(l2));		llOwnerSay("Elements in x or y = " + llList2CSV(ListXorY(l1,l2)));		llOwnerSay("Elements in both x and y = " + llList2CSV(ListXandY(l1,l2)));		llOwnerSay("Elements that are in x but not in y = " + llList2CSV(ListXnotY(l1,l2)));		llOwnerSay("Elements that are in y but not in x = " + llList2CSV(ListXnotY(l2,l1)));		llOwnerSay("Elements that are in x or y but not both = " + llList2CSV(ListXxorY(l1,l2)));		llOwnerSay("list x == y = " + (string)ListXequY(l1,l2));		llOwnerSay("list x == x = " + (string)ListXequY(l1,l1));		llOwnerSay("list y != x = " + (string)ListXneqY(l2,l1));		llOwnerSay("list y != y = " + (string)ListXneqY(l2,l2));			}}`