diff --git a/src/termlist.c b/src/termlist.c index c987ead..ed02bc3 100644 --- a/src/termlist.c +++ b/src/termlist.c @@ -215,6 +215,19 @@ termlistAppend (const Termlist tl, const Term term) return tl; } +//! Add a term only to a list if it wasn't in it before. +/** + * Mimics a basic set type behaviour. + */ +Termlist +termlistAddNew (const Termlist tl, const term t) +{ + if (inTermlist (tl, t)) + return tl; + else + return termlistAdd (tl, t); +} + //! Concatenates two termlists. /** * The last pointer of the first list is made to point to the second list. @@ -762,3 +775,5 @@ int termlistOrder (Termlist tl1, Termlist tl2) else return 1; } + + diff --git a/src/termlist.h b/src/termlist.h index a1958d8..6cde0e8 100644 --- a/src/termlist.h +++ b/src/termlist.h @@ -32,6 +32,7 @@ __inline__ int inTermlist (Termlist tl, const Term term); int isTermlistEqual (Termlist tl1, Termlist tl2); Termlist termlistAdd (Termlist tl, Term term); Termlist termlistAppend (const Termlist tl, const Term term); +Termlist termlistAddNew (const Termlist tl, const term t); Termlist termlistConcat (Termlist tl1, Termlist tl2); Termlist termlistDelTerm (Termlist tl); Termlist termlistConjunct (Termlist tl1, Termlist tl2);