Skip to content

Instantly share code, notes, and snippets.

@lynaghk
Created April 1, 2012 06:03
Show Gist options
  • Save lynaghk/2271894 to your computer and use it in GitHub Desktop.
Save lynaghk/2271894 to your computer and use it in GitHub Desktop.
core.logic questions
(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
@swannodette
Copy link

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.

@lynaghk
Copy link
Author

lynaghk commented Apr 1, 2012

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.

@swannodette
Copy link

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