Is there a way to add an element to a list, without caring if it already exists and the list still not containing duplicates?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you are looking for efficiency there are better data structures than lists, ready to use in SWI-Prolog. In particular, your use case fits on add_nb_set(+Key, !Set, ?New).
Argument
Newcontrols the behaviour WRT duplicates: you should usetruefor don’t care.Argument
Setmust be ‘allocated’ withempty_nb_set(Set)edit: I apologize, argument
Setmust be a free var fordon't care behaviour, like for instanceadd_nb_set(Key, Set, _), as evident for the documentation page….