60 lines
2.1 KiB
Plaintext
60 lines
2.1 KiB
Plaintext
proc PrintBool(Str, Test);
|
|
int Str, Test;
|
|
[Text(0, Str);
|
|
Text(0, if Test then "true" else "false");
|
|
CrLf(0);
|
|
];
|
|
|
|
proc PrintSet(Str, Set, Names);
|
|
int Str, Set, Names, I;
|
|
[Text(0, Str);
|
|
for I:= 0 to 31 do
|
|
if 1<<I & Set then
|
|
[Text(0, Names(I)); ChOut(0, ^ )];
|
|
CrLf(0);
|
|
];
|
|
|
|
int Names, Fruits, Fruits2, Fruits3, Fruits4, Fruits5;
|
|
def Apple=1<<0, Pear=1<<1, Orange=1<<2, Banana=1<<3, Melon=1<<4, Lemon=1<<5,
|
|
Gooseberry=1<<6, Elderberry=1<<7, Raspberry=1<<8, Blueberry=1<<9,
|
|
Cherry=1<<10, Guava=1<<11;
|
|
[Names:= ["Apple", "Pear", "Orange", "Banana", "Melon", "Lemon", "Gooseberry",
|
|
"Elderberry", "Raspberry", "Blueberry", "Cherry", "Guava"];
|
|
Fruits:= Apple ! Pear ! Orange ! Banana;
|
|
PrintSet("Fruits : ", Fruits, Names);
|
|
Fruits2:= Melon ! Orange ! Lemon ! Gooseberry;
|
|
PrintSet("Fruits2 : ", Fruits2, Names);
|
|
CrLf(0);
|
|
PrintBool("Fruits contains 'Banana' : ", Fruits & Banana);
|
|
PrintBool("Fruits2 contains 'Elderberry' : ", Fruits2 & Elderberry);
|
|
CrLf(0);
|
|
PrintSet("Union : ", Fruits ! Fruits2, Names);
|
|
PrintSet("Intersection : ", Fruits & Fruits2, Names);
|
|
PrintSet("Difference : ", Fruits & ~Fruits2, Names);
|
|
CrLf(0);
|
|
PrintBool("Fruits2 is a subset of Fruits : ",
|
|
(Fruits2 & Fruits) # 0 & (Fruits2 & ~Fruits) = 0);
|
|
CrLf(0);
|
|
Fruits3:= Fruits;
|
|
PrintSet("Fruits3 : ", Fruits3, Names);
|
|
CrLf(0);
|
|
PrintBool("Fruits2 and Fruits are equal : ", Fruits2 = Fruits);
|
|
PrintBool("Fruits3 and Fruits are equal : ", Fruits3 = Fruits);
|
|
CrLf(0);
|
|
Fruits4:= Apple ! Orange;
|
|
PrintSet("Fruits4 : ", Fruits4, Names);
|
|
CrLf(0);
|
|
PrintBool("Fruits3 is a proper subset of Fruits : ",
|
|
(Fruits3 & Fruits) # 0 & (Fruits3 & ~Fruits) = 0 & Fruits3 # Fruits);
|
|
PrintBool("Fruits4 is a proper subset of Fruits : ",
|
|
(Fruits4 & Fruits) # 0 & (Fruits4 & ~Fruits) = 0 & Fruits4 # Fruits);
|
|
CrLf(0);
|
|
Fruits5:= Cherry ! Blueberry ! Raspberry;
|
|
PrintSet("Fruits5 : ", Fruits5, Names);
|
|
CrLf(0);
|
|
Fruits5:= Fruits5 + Guava;
|
|
PrintSet("Fruits5 + 'Guava' : ", Fruits5, Names);
|
|
Fruits5:= Fruits5 - Cherry; \Cherry better be present!
|
|
PrintSet("Fruits5 - 'Cherry' : ", Fruits5, Names);
|
|
]
|