This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathintersect.lcdoc
More file actions
123 lines (91 loc) · 3.53 KB
/
intersect.lcdoc
File metadata and controls
123 lines (91 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
Name: intersect
Type: command
Syntax: intersect <targetArray> with <templateArray> [recursively] [into <destinationArray>]
Summary:
Removes <element(glossary)|elements> from an <array> if they have no
corresponding <element(keyword)> in another <array>.
Introduced: 1.1
OS: mac, windows, linux, ios, android
Platforms: desktop, server, mobile
Example:
local tLeft, tRight
put "green" into tLeft["color"]
put "left" into tLeft["align"]
put "blue" into tRight["color"]
put "100" into tRight["width"]
intersect tLeft with tRight
# RESULT
# the keys of tLeft = "colour"
# tLeft["colour"] = "green"
# tRight unchanged
Example:
local tLeft, tRight
put "a" into tLeft[1][1]
put "b" into tLeft[1][2]
put "y" into tRight[1][1]
intersect tLeft with tRight -- tLeft unchanged
intersect tLeft with tRight recursively
# RESULT
# tLeft[1][1] = "a"
# tLeft[1][2] empty
# tRight unchanged
Example:
function ScriptIntersect pLeft, pRight, pRecursive
repeat for each key tKey in pLeft
if tKey is not among the keys of pRight then
delete variable pLeft[tKey]
else if pRecursive then
put ScriptIntersect(pLeft[tKey], pRight[tKey], true) into pLeft[tKey]
end if
end repeat
return pLeft
end ScriptIntersect
function EngineIntersect pLeft, pRight, pRecursive
if pRecursive then
intersect pLeft with pRight recursively
else
intersect pLeft with pRight
end if
return pLeft
end EngineIntersect
-- This function should return true for all inputs.
function CheckIntersect pLeft, pRight, pRecursive
return ScriptIntersect(pLeft, pRight, pRecursive) is EngineIntersect(pLeft, pRight, pRecursive)
end CheckIntersect
Parameters:
targetArray (array):
The value to modify.
templateArray (array):
The array to intersect <array> with.
destinationArray (optional array):
A variable to set as the destination instead of mutating <targetArray>
Description:
Use the <intersect> <command> to filter out <element(glossary)|elements>
from an <array> according to the contents of another <array>.
The recursively adverb controls whether the intersection recurses
through nested arrays or not.
Each key of <targetArray> is checked to see whether there is a matching
<key> in <templateArray>. The <element(glossary)|elements> of
<targetArray> that do not match an <element(keyword)> of the
<templateArray> are removed from <targetArray>.
After the <intersection> <command> is <execute|executed>, the <keys> of
<targetArray> consists of the logical intersection of the <keys> of the
original <targetArray> and the keys of <templateArray>.
The content of individual elements of the <templateArray> does not
affect the final result. Only which <element(glossary)|elements> exist
in the <templateArray>, not their content, controls which
<element(glossary)|elements> of <targetArray> are retained and which are
removed. If <targetArray> and <templateArray> have the same set of
<element(glossary)|elements> but different content in each
<element(keyword)>, the <intersect> <command> does not change the value
of <targetArray>.
If the into clause is used the operation of the commands is the same as
the non-into form except that <targetArray> does not have to be a
variable, and the result of the operation is placed into
<destinationArray> rather than mutating <targetArray>.
Changes:
The `into` clause was added in LiveCode 9.
References: split (command), union (command), element (glossary),
array (glossary), command (glossary), key (glossary), element (keyword),
difference (command), symmetric difference (command)
Tags: properties