Symmetric difference: Difference between revisions

Added XPL0 example.
(Added Wren)
(Added XPL0 example.)
Line 2,948:
B - A = <Jim>
A △ B = <Serena, Jim>
</pre>
 
=={{header|XPL0}}==
An integer in XPL0 can represent a set of up to 32 elements, and bitwise Boolean
operations can represent union, intersection, and difference.
 
<lang XPL0>def John, Bob, Mary, Serena, Jim; \enumerate set items (0..4)
 
proc SetOut(S); \Output the elements in set
int S;
int Name, I;
[Name:= ["John", "Bob", "Mary", "Serena", "Jim"];
for I:= 0 to 31 do
if S & 1<<I then
[Text(0, Name(I)); ChOut(0, ^ )];
CrLf(0);
];
 
int A, B;
[A:= 1<<John ! 1<<Bob ! 1<<Mary ! 1<<Serena;
B:= 1<<Jim ! 1<<Mary ! 1<<John ! 1<<Bob;
Text(0, "A xor B = "); SetOut(A | B);
Text(0, "A\B = "); SetOut(A & ~B);
Text(0, "B\A = "); SetOut(B & ~A);
Text(0, "A\B U B\A = "); SetOut(A&~B ! B&~A);
]</lang>
 
{{out}}
<pre>
A xor B = Serena Jim
A\B = Serena
B\A = Jim
A\B U B\A = Serena Jim
</pre>
 
772

edits