<< Back to previous view

[CLJ-372] possible binding issue in clojure.template? Created: 03/Jun/10  Updated: 01/Mar/13  Resolved: 26/Nov/10

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect
Reporter: Anonymous Assignee: Stuart Sierra
Resolution: Declined Votes: 0
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?



 Comments   
Comment by Assembla Importer [ 24/Aug/10 11:29 AM ]

Converted from http://www.assembla.com/spaces/clojure/tickets/372
Attachments:
template-local-binding.patch - https://www.assembla.com/spaces/clojure/documents/bEvfq-BS8r36foeJe5cbLA/download/bEvfq-BS8r36foeJe5cbLA

Comment by Assembla Importer [ 24/Aug/10 11:29 AM ]

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.

Comment by Assembla Importer [ 24/Aug/10 11:29 AM ]

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
Comment by Stuart Sierra [ 26/Nov/10 8:54 AM ]

Could not reproduce the reported error.

Generated at Sat Oct 25 15:55:47 CDT 2014 using JIRA 4.4#649-r158309.