How do you use the permute predicate to output into a list in SWI prolog?
The permutation/2 predicate only returns one result at a time.
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 want a list of all permutations, findall/3 is the way to go. If you want to print, you can use forall/2. Either case:
forall it’s a general purpose builtin, implementing a failure driven loop, amazing for its’ simplicity. I report the definition from SWI-Prolog library, I think it’s interesting.
EDIT:
As noted by false, if you have variables in your list, you should be aware of the different behaviour of findall/3 WRT bagof/3:
Note that each variable in in the second query output is different: that could be the request outcome, or not, depending on the problem at hand. Deciding the appropriate behaviour WRT the variable quantification is mandatory in the restricted class of problems where variables are data, i.e. metaprogramming, I think…