6.3 Counting solutions for a Prolog predicate in Elisp

Below is an example usage of the Sweep interface for calling Prolog. It shows an invocation of the non-deterministic predicate lists:permutation/2 directly from an function Elisp that counts the number of different permutations of the list (1 2 3 4 5):

(sweeprolog-open-query "user" "lists" "permutation" '(1 2 3 4 5))
(let ((num 0)
      (sol (sweeprolog-next-solution)))
  (while sol
    (setq num (1+ num))
    (setq sol (sweeprolog-next-solution)))
  (sweeprolog-close-query)
  num)