Objective: To implement operations with sets:

- Intersection of sets
- Union of sets
- Subtraction of sets
- The symmetric difference

Union of sets A and B is the set

A⋃B={x|x∊A or x∊B}

The intersection of sets A and B is the set

A⋂B={x|x∊A and x∊B}

The difference of sets A and B is the set

A\B={x|x∊A and x∉B}

Symmetric difference of sets A and B is the set

A-B=(A\B)⋃(B\A)

For convenience and clarity creates a class ** multitude**.

('multitude defclass) ('multitude defvar list) ('multitude defmethod list () list) ('multitude defmethod multitude (x) (nil setq list (nil if ((nil type-of x) = 'multitude) (x list) x))) ('multitude defmethod push (x) (nil setq list (nil cons x list))) ('multitude defmethod contain (x) (nil let (found) (nil try (list for i (nil if (x = i) (nil throw 'break))) break (nil setq found true)) found)) ('multitude defmethod ⋃ (m) (nil let ((union ('multitude newobject m))) (list for* x (nil if (nil not (union contain x)) (union push x))) union)) ('multitude defmethod ⋂ (m) (nil let ((inter ('multitude newobject)) (lockinter ('lock newobject))) (list for x (nil if (m contain x) (lockinter progn (inter push x)))) inter)) ('multitude defmethod \ (m) (nil let ((diff ('multitude newobject)) (lockdiff ('lock newobject))) (list for x (nil if (nil not (m contain x)) (lockdiff progn (diff push x)))) diff)) ('multitude defmethod - (m) (nil let ((a (this \ m)) (b (m \ this))) (a ⋃ b)))

The constructor can take an argument as a list or set.

Function ** contain ** uses parallelism. Way out of the parallel loop is implemented using exceptions.

Function ** ⋃ ** implements the sequential algorithm. In this task parallelism not available.

The function ** ⋂ ** can find control elements in parallel using the ** contain**. But changing the result ** inter ** is protected by a lock ** lockinter**.

Similarly, the function ** \ ** is implemented.

In the function ** - ** parallelism is achieved in the computation of variables ** a ** and ** b**.