Created
January 25, 2012 04:39
-
-
Save ejackson/1674762 to your computer and use it in GitHub Desktop.
Unusual behaviour of symbol-macrolet
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
(ns timetable.core | |
(:refer-clojure :exclude [==]) | |
(:use [clojure.core.logic] | |
[clojure.tools.macro])) | |
;; Basic form. Works | |
(run 10 [q] | |
(== [(lvar) (lvar) (lvar)] q) | |
(membero :history q) | |
(membero :math q) | |
(membero :physics q)) | |
;;([:history :math :physics] [:math :history :physics] [:history :physics :math] [:math :physics :history] [:physics :history :math] [:physics :math :history]) | |
;; Using a macrolet, also works | |
(run 10 [q] | |
(symbol-macrolet [_ (lvar)] | |
(== [_ _ _] q)) | |
(membero :history q) | |
(membero :math q) | |
(membero :physics q)) | |
;;([:history :math :physics] [:math :history :physics] [:history :physics :math] [:math :physics :history] [:physics :history :math] [:physics :math :history]) | |
;; Using a macrolet, does not work. Only difference is scope of macrolet | |
(run 10 [q] | |
(symbol-macrolet [_ (lvar)] | |
(== [_ _ _] q) | |
(membero :history q) | |
(membero :math q) | |
(membero :physics q))) | |
;; ((:physics . _.0) (_.0 :physics . _.1) (_.0 _.1 :physics . _.2) (_.0 _.1 _.2 :physics . _.3) (_.0 _.1 _.2 _.3 :physics . _.4) (_.0 _.1 _.2 _.3 _.4 :physics . _.5) (_.0 _.1 _.2 _.3 _.4 _.5 :physics . _.6) (_.0 _.1 _.2 _.3 _.4 _.5 _.6 :physics . _.7) (_.0 _.1 _.2 _.3 _.4 _.5 _.6 _.7 :physics . _.8) (_.0 _.1 _.2 _.3 _.4 _.5 _.6 _.7 _.8 :physics . _.9)) | |
;; Wrap entire thing with a macrolet. This works. | |
(symbol-macrolet [_ (lvar)] | |
(run 10 [q] | |
(== [_ _ _] q) | |
(membero :history q) | |
(membero :math q) | |
(membero :physics q))) | |
;;([:history :math :physics] [:math :history :physics] [:history :physics :math] [:math :physics :history] [:physics :history :math] [:physics :math :history]) | |
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
(defproject timetable "1.0.0-SNAPSHOT" | |
:description "FIXME: write description" | |
:dependencies [[org.clojure/clojure "1.3.0"] | |
[org.clojure/core.logic "0.6.7"] | |
[org.clojure/tools.macro "0.1.1"]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment