Clojure

possible binding issue in clojure.template?

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Approval:
    Screened

Description

I came across some strange behavior the other day in clojure.test/are, where the template replacement seems a bit over-eager. As a simple case:

(use 'clojure.test)

(are [x y] (= x y)
'(4 9 16) (map (fn [x] (* x x)) '(2 3 4)))

gives "java.lang.Exception: Unsupported binding form: clojure.lang.LazySeq@7bed76a7", but

(are [x y] (= x y)
'(4 9 16) (map (fn [z] (* z z)) '(2 3 4)))

is fine. It seems that all instances of the variable x get replaced, even the ones in other expressions that are doing the replacing. A macroexpand-1 traced it to clojure.template, and if I patch apply-template there to use postwalk-replace rather than prewalk-replace, clojure.test/are works as I had expected. However, the simple test case I wrote to expose this problem (wrapping deftest around the first example above) fails with what seems to me to be a bizarre error:

[java] FAIL in (can-test-using-local-bindings) (test_clojure.clj:87)
[java] but got :pass
[java] expected: (= (quote (4 9 16)) (map (fn [x] (* x x)) (quote (2 3 4))))
[java] actual: (#<core$EQ clojure.core$EQ@a947850> (4 9 16) (4 9 16))

Can anyone decipher why this fails, or come up with a better solution?

Activity

Hide
Assembla Importer added a comment -

stuart.sierra said: Reason for the bizarre error is the awkwardness of using clojure.test to test itself. clojure.test-clojure.test uses an alternate reporting function that looks at the doc string of the assertion.

This can be fixed by placing the can-test-use-local-bindings test in a different namespace.

Show
Assembla Importer added a comment - stuart.sierra said: Reason for the bizarre error is the awkwardness of using clojure.test to test itself. clojure.test-clojure.test uses an alternate reporting function that looks at the doc string of the assertion. This can be fixed by placing the can-test-use-local-bindings test in a different namespace.
Hide
Assembla Importer added a comment -

stuart.sierra said: I can't reproduce the error. This works for me:

user=> (are [x y] (= x y) '(4 9 16) (map (fn [x] (* x x)) '(2 3 4)))
true
Show
Assembla Importer added a comment - stuart.sierra said: I can't reproduce the error. This works for me:
user=> (are [x y] (= x y) '(4 9 16) (map (fn [x] (* x x)) '(2 3 4)))
true
Hide
Stuart Sierra added a comment -

Could not reproduce the reported error.

Show
Stuart Sierra added a comment - Could not reproduce the reported error.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: