Created
April 15, 2013 02:55
-
-
Save lkuper/5385382 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; 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