1
votes

In my prolog database, I have below facts:

played('Sharon rose', piano).
played('Robert Kay', piano).
played('Kelvin Cage', drums).
singer('Robert Kay').
band_leader('Sharon rose').

I want to print out all the names uniquely as a single list.

Below is my query using setof and the output:

setof(X, (played(X,_);singer(X);band_leader(X)), Output).

Output = ['Robert Kay','Sharon rose'] ? ;

Output = ['Kelvin Cage'] ? ;

Output = ['Robert Kay','Sharon rose']

yes

However, the output isn't what I want. I want it to print out the names uniquely as a list.

1
Did you intend Drums to be Drums or drums?Enigmativity
It’s drums (small letter “d”, not variable as “Drums”), was a typo. Thanks for noting that. I corrected it.niyidrums

1 Answers

1
votes

You get multiple answers due to the anonymous variable in the goal argument of setof/3. Try instead:

?- setof(X, Y^(played(X,Y);singer(X);band_leader(X)), Output).