'How to remove redundancies in a multifield in CLIPS?

Suppose we have ordered multifield facts such as:

(serie-1 7 7 5 5 1 1)
(serie-2 8 3 8 3 8 3)
(serie-3 6 4 9 4 6 2)

The problem is to remove redundant fields from this ordered multifield facts to obtain:

(serie-1 7 5 1)
(serie-2 8 3)
(serie-3 6 4 9 2)

The question is: how to proceed ?



Solution 1:[1]

         CLIPS (6.4 2/9/21)
CLIPS> 
(deftemplate serie
   (slot id)
   (multislot nums))
CLIPS>    
(deffacts start
   (serie (id 1) (nums 7 7 5 5 1 1))
   (serie (id 2) (nums 8 3 8 3 8 3))
   (serie (id 3) (nums 6 4 9 4 6 2)))
CLIPS>    
(defrule remove
   ?s <- (serie (nums $?b ?n $?m ?n $?e))
   =>
   (modify ?s (nums $?b ?n $?m $?e)))
CLIPS> (reset)
CLIPS> (facts)
f-1     (serie (id 1) (nums 7 7 5 5 1 1))
f-2     (serie (id 2) (nums 8 3 8 3 8 3))
f-3     (serie (id 3) (nums 6 4 9 4 6 2))
For a total of 3 facts.
CLIPS> (run)
CLIPS> (facts)
f-1     (serie (id 1) (nums 7 5 1))
f-2     (serie (id 2) (nums 8 3))
f-3     (serie (id 3) (nums 6 4 9 2))
For a total of 3 facts.
CLIPS>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gary Riley