-
-
Save bsless/ef07a7ab21a614720a36c698b5121d6e to your computer and use it in GitHub Desktop.
This file contains 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
(define-syntax Zzz | |
(syntax-rules () | |
((_ g) (lambda (s/c) (lambda () (g s/c)))))) | |
(define-syntax conj+ | |
(syntax-rules () | |
((_ g) (Zzz g)) | |
((_ g0 g ...) (conj (Zzz g0) (conj+ g ...))))) | |
(define-syntax disj+ | |
(syntax-rules () | |
((_ g) (Zzz g)) | |
((_ g0 g ...) (disj (Zzz g0) (disj+ g ...))))) | |
(define-syntax fresh | |
(syntax-rules () | |
((_ () g0 g ...) (conj+ g0 g ...)) | |
((_ (x0 x ...) g0 g ...) | |
(call/fresh | |
(lambda (x0) | |
(fresh (x ...) g0 g ...)))))) | |
(define-syntax conde | |
(syntax-rules () | |
((_ (g0 g ...) ...) (disj+ (conj+ g0 g ...) ...)))) |
This file contains 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
(defmacro define-syntax-rules | |
[name & patterns] | |
`(do | |
(def ~name | |
(fn ~name [~'&form ~'&env & body#] | |
(m/rewrite ~'&form ~@patterns))) | |
(. (var ~name) (setMacro)) | |
(var ~name))) | |
(define-syntax-rules Zzz | |
(_ ?g) (fn [s] (fn [] (?g s)))) | |
(define-syntax-rules conj+ | |
(_ ?g) (Zzz ?g) | |
(_ ?g0 . !g ...) (conj (Zzz ?g0) (conj+ . !g ...))) | |
(define-syntax-rules disj+ | |
(_ ?g) (Zzz ?g) | |
(_ ?g0 . !g ...) (disj (Zzz ?g0) (disj+ . !g ...))) | |
(define-syntax-rules fresh | |
(_ [] ?g0 . !g ...) (conj+ g0 . !g ...) | |
(_ [?x0 . !x ...] ?g0 . !g ...) | |
(call-fresh | |
(fn [?x0] | |
(fresh [. !x ...] g0 . !g ...)))) | |
(define-syntax-rules conde | |
(_ . [!g ..!n] ... ) (disj+ . (conj+ . !g ..!n) ... )) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment