Skip to content

Instantly share code, notes, and snippets.

@lkuper
Created April 15, 2013 02:55
Show Gist options
  • Select an option

  • Save lkuper/5385382 to your computer and use it in GitHub Desktop.

Select an option

Save lkuper/5385382 to your computer and use it in GitHub Desktop.
;; Take a list of (possibly repeated) elements, and return all those
;; that appear more than once.
(include "~/repos/simple-miniKanren/mkdefs.scm")
;; Regular Scheme version for comparison
(define morethanonce
(lambda (ls)
(cond
[(null? ls) '()]
[(member (car ls) (cdr ls))
(cons (car ls) (morethanonce (cdr ls)))]
[else (morethanonce (cdr ls))])))
(define morethanonceo
(lambda (ls out)
(fresh (a d res)
(conde
[(== '() ls) (== '() out)]
[(caro ls a)
(cdro ls d)
(membero a d)
(morethanonceo d res)
(conso a res out)]
[(cdro ls d)
(morethanonceo d out)]))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment