How does one choose between bagof, setof and findall? Are there any important differences? Which is most commonly used and which is the safest? Thanks for your comments/answers.
I checked the SWI-Prolog manual page on findall/3
and found them to be very similar.
That's a great question!
I am not attempting to give an exhaustive answer, but I would like to suggest a few lines of thought that can help you to understand these predicates better:
findall/3
in terms of setof/3
? And what about the other way around? This helps to see what you need to provide at least to implement all these predicates.In addition, I recommend you read Richard O'Keefe's book The Craft of Prolog for valuable information about these predicates.
an important difference I found between findall/3
and bagof/3
, is that the latter doesn't make copies of the terms it accumulates. This can be crucial, for instance, if your list collects attributed variables, like when modelling a problem with library(clpfd)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With