listprologxsb

XSB Prolog: write my own setof function


I need to get, from a keyboard input (list), a list without duplicates but without using the inbuild setof (or any other inbuild functions) in XSB prolog.

How do i write my own setof function?

Input and output should look like this:

|?-list([a,b,c,d,a,b,c,d,e,f],L).  

L=[a,b,c,d,e,f];

Thanks in advance.


Solution

  • Using member/2 it's so easy: just make a copy of each element, with a recursive list/2, checking the head of input list it's not already in the target list. Checking could be performed by member/2, you will need to write your own... The entire program should be 4 lines of code.