alexanderkiel / phrase

Clojure(Script) library for phrasing spec problems.
Eclipse Public License 1.0
289 stars 8 forks source link

Capture Binding Symbols Should Shadow Global Symbols in Predicates #8

Closed alexanderkiel closed 6 years ago

alexanderkiel commented 6 years ago

The following phraser doesn't work because key is a function in clojure.core and most namespaces import it:

(defphraser #(contains? % key)
  [_ _ key]
  (format "Missing %s." (name key)))

The intended behaviour is to use key as symbol to capture the actual key of the contains? predicate. The problem is that the current symbol resolution tries to resolve all symbols first and only leave the symbol alone if it fails. The solution is to not resolve capture binding symbols. The result is that key in the predicate is actually in scope of the phraser and not in global scope.