Set: Difference between revisions

2,165 bytes added ,  1 year ago
→‎{{header|Diego}}: Added Diego entry
No edit summary
(→‎{{header|Diego}}: Added Diego entry)
Line 2,498:
S3 is subset S2 TRUE
S1 equality S2? FALSE</pre>
 
=={{header|Diego}}==
<lang diego>use_namespace(rosettacode)_me();
 
// Set creation
add_set(A)_values(🐖,🦬,🦘,🦫,🦭);
add_set(B)_values(🐈‍⬛,🦬,🦫,🦤,🐐);
add_set(C)_values(🐈‍⬛,🦫);
add_set(M)_value(🐖);
 
// Membership
ms_msg()_calc([M]∈[B])
? with_msg()_msg(set M is an element in set B);
: with_msg()_msg(set M is not an element in set B);
;
 
ms_msg()_calc(🐖∈[A])
? with_msg()_msg(🐖 is an element in set A);
: with_msg()_msg(🐖 is not an element in set A);
;
 
// Union
ms_msg()_msg(A∪B=[])_calc([A]∪[B]);
 
// Intersection
ms_msg()_msg(A∩B=[])_calc([A]∩[B]);
 
// Difference
ms_msg()_msg(A∖B=[])_calc([A]∖[B]); // U+2216 is used not U+005c (\)
ms_msg()_msg(A\\B=[])_calc([A]\\[B]); // U+005c (\) has to be escaped
 
// Subset
ms_msg()_calc([C]⊆[A])
? with_msg()_msg(set C is a subset of set A);
: with_msg()_msg(set C is not a subset of set A);
;
 
ms_msg()_calc([C]⊆[B])
? with_msg()_msg(set C is a subset of set B);
: with_msg()_msg(set C is not a subset of set B);
;
 
// Equality
ms_msg()_calc([A]=[B])
? with_msg()_msg(set A is equal to set B);
: with_msg()_msg(set A is not equal to set B);
;
 
// Test
ms_msg()_calc([A]⊂[B])_or()_calc([A]⊊[B])
? with_msg()_msg(set A is a proper subset of set B);
: with_msg()_msg(set A is not a proper subset of set B);
;
 
ms_msg()_calc([C]⊂[B]||[C]⊊[B]) // alternative syntax
? with_msg()_msg(set C is a proper subset of set B);
: with_msg()_msg(set C is not a proper subset of set B);
;
 
// Modify a mutable set (all sets are mutable)
with_set(M)_push(🦬,🦘,🦫,🦭);
ms_msg()_calc([M]=[A])
? with_msg()_msg(set M is equal to set A);
: with_msg()_msg(set M is not equal to set A);
;
 
reset_namespace[];</lang>
 
{{out}}
 
<pre>set M is an element in set B
🐖 is an element in set A
A∪B=🐖,🦬,🦘,🦫,🦭,🐈‍⬛,🦤,🐐
A∩B=🦬,🦫
A∖B=🐖,🦘,🦭
A\B=🐖,🦘,🦭
set C is not a subset of set A
set C is a subset of set B
set A is not equal to set B
set A is not a proper subset of set B
set C is a proper subset of set B
set M is equal to set A</pre>
 
=={{header|EchoLisp}}==