Difference between revisions of "ListCompare"
Jump to navigation
Jump to search
m (Wanted to add that the == 0 is not required, as the logical negation of the function means that any non-zero value will evaluate to FALSE, while /only/ zero will evaluate to TRUE.) |
Ugleh Ulrik (talk | contribs) |
||
Line 9: | Line 9: | ||
|cat1=Examples | |cat1=Examples | ||
|cat2=Library | |cat2=Library | ||
|cat3=UD_Functions | |||
|examples=<lsl>integer r = ListCompare([1, 2.0, "3"], [1, 2.0, "3"]); // Returns TRUE | |examples=<lsl>integer r = ListCompare([1, 2.0, "3"], [1, 2.0, "3"]); // Returns TRUE | ||
integer s = ListCompare([1, 2.0, 3], [1, 2.0, "3"]); // Returns FALSE | integer s = ListCompare([1, 2.0, 3], [1, 2.0, "3"]); // Returns FALSE |
Revision as of 10:41, 25 May 2010
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Summary
Function: integer ListCompare( list a, list b );
Efficiently compares two lists for equality (same contents).
Returns an integer TRUE if the lists are equal, FALSE if not.
• list | a | – | The first list to compare. | |
• list | b | – | The second list to compare. |
Examples
<lsl>integer r = ListCompare([1, 2.0, "3"], [1, 2.0, "3"]); // Returns TRUE integer s = ListCompare([1, 2.0, 3], [1, 2.0, "3"]); // Returns FALSE
integer t = ListCompare([], [1, 2.0, "3"]); // Returns FALSE</lsl>Implementation
<lsl>integer ListCompare(list a, list b) {
integer aL = a != []; if (aL != (b != [])) return 0; if (aL == 0) return 1; return !llListFindList((a = []) + a, (b = []) + b);
}</lsl>