Created
April 1, 2012 06:03
-
-
Save lynaghk/2271894 to your computer and use it in GitHub Desktop.
core.logic questions
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
(def form '(defmacro nom [x] (some (delicious)) forms)) | |
;;this works nicely | |
(let [x (lvar) | |
rest (lvar)] | |
(run* [q] | |
(== form (llist 'defmacro x rest)) | |
(== q x))) | |
;;=> (nom) | |
;;why not this? | |
(let [x (lvar) | |
rest (lvar)] | |
(run* [q] | |
(== form `(defmacro ~x . ~rest)) | |
(== q x))) | |
;;=> () | |
;;This doesn't work either | |
(run* [q] | |
(prep '(all | |
(== form (defmacro ?x . ?rest)) | |
(== q ?x)))) | |
;;=> java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.IFn | |
;;This also works | |
(run* [q] | |
(fresh [pat alt] | |
(membero [pat alt] | |
[(prep '[(defmacro ?x . ?rest) | |
?x])]) | |
(== pat form) | |
(== q alt))) | |
;;=> (nom) | |
;;why not this? | |
(run* [q] | |
(fresh [pat alt] | |
(membero [pat alt] | |
[(prep '[#(== % (defmacro ?x . ?rest)) | |
#(== % ?x)])]) | |
(pat form) | |
(alt q))) | |
;;=> clojure.core.logic.LVar cannot be cast to clojure.lang.IFn |
Thanks @swannodette, that is good to know.
I'm still missing something though; e.g., I have no idea why the last form doesn't work.
logic vars aren't functions, they just store values. You need to project the vars first if you want to do that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The . symbol doesn't mean anything special - that would require Clojure reader support. Macros like defne and tools like the simple unifier handle the . symbol themselves.