MiniKanren loto

List of twins

(define loto
  (lambda (l)
      ;; empty list
      ((nullo l) #s)
      ;; list of lists
      ((fresh (a)
        ;; The head of the list associates with a
        (caro l a)
        ;; The head of the list is twins
        (twinso a))
        ;; Then the result is if tail of is also lot
        (fresh (as)
          ;; Associate as with tail of l
          (cdro l as)
          ;; Ensure as is lot
          (loto as))))))

Defined using listofo

(define loto
  (lambda (l)
    (listofo twinso l)))