Symmetric difference: Difference between revisions

Content deleted Content added
Chikega (talk | contribs)
Demonstrating Object Pascal's 'symmetric difference' operator
Miks1965 (talk | contribs)
PascalABC.NET
 
(5 intermediate revisions by 3 users not shown)
Line 1,180:
ReadLn;
END.</syntaxhighlight>
'''Delphi/Object Pascal actually has a 'Symmetric Difference' operator `> <`: '''
<syntaxhighlight lang="pascal">
program SymmetricDifference;
Line 2,675:
Put('ListA -> ', ListA);
Put('ListB -> ', ListB);
Put('ListA >< ListB -> ', (ListA ><- ListB) + (ListB - ListA));
Put('ListA - ListB -> ', ListA - ListB);
Put('ListB - ListA -> ', ListB - ListA);
Line 2,686:
ListA - ListB -> Serena
ListB - ListA -> Jim</pre>
'''Object Pascal actually has a 'Symmetric Difference' operator `> <`: '''
<syntaxhighlight lang="pascal">
program SymmetricDifference;
Line 2,711:
a b e f
</pre>
 
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
begin
var s1: HashSet<string> := HSet('John', 'Serena', 'Bob', 'Mary', 'Serena');
var s2 := HSet('Jim', 'Mary', 'John', 'Jim', 'Bob');
Println((s1 - s2) + (s2 - s1));
Println(s1 - s2);
Println(s2 - s1);
end.
</syntaxhighlight>
{{out}}
<pre>
{Serena,Jim}
{Serena}
{Jim}
</pre>
 
 
=={{header|Perl}}==
Line 3,202 ⟶ 3,220:
</pre>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
, John Bob Mary Serena: e.A
, Jim Mary John Bob: e.B
= <Prout <Symdiff (e.A) (e.B)>>;
};
 
Symdiff {
(e.1) (e.2), <Diff (<Set e.1>) (<Set e.2>)>: e.3
, <Diff (<Set e.2>) (<Set e.1>)>: e.4
= <Union (e.3) (e.4)>;
};
 
Set {
= ;
s.1 e.1 s.1 e.2 = <Set e.1 s.1 e.2>;
s.1 e.1 = s.1 <Set e.1>;
};
 
Union {
(e.1) (e.2) = <Set e.1 e.2>;
};
 
Diff {
() (e.1) = ;
(e.1) () = e.1;
(s.1 e.1) (e.2 s.1 e.3) = <Diff (e.1) (e.2 e.3)>;
(s.1 e.1) (e.2) = s.1 <Diff (e.1) (e.2)>;
};</syntaxhighlight>
{{out}}
<pre>Serena Jim</pre>
=={{header|REXX}}==
===version 1===
Line 3,768 ⟶ 3,817:
=={{header|Wren}}==
{{libheader|Wren-set}}
<syntaxhighlight lang="ecmascriptwren">import "./set" for Set
 
var symmetricDifference = Fn.new { |a, b| a.except(b).union(b.except(a)) }