Skip to content

Instantly share code, notes, and snippets.

@ejackson
Created January 25, 2012 04:39
Show Gist options
  • Save ejackson/1674762 to your computer and use it in GitHub Desktop.
Save ejackson/1674762 to your computer and use it in GitHub Desktop.
Unusual behaviour of symbol-macrolet
(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])
(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