Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macros define var even if not evaluated #41

Closed
marick opened this issue Aug 4, 2015 · 1 comment
Closed

Macros define var even if not evaluated #41

marick opened this issue Aug 4, 2015 · 1 comment

Comments

@marick
Copy link
Contributor

marick commented Aug 4, 2015

Midje wants to conditionally import certain vars when running in the repl. I discovered that the vars are created even when not running in the repl. Potemkin inherits this (mis)behavior from def:

user=> (if false (do (def derp3 3)))
nil
user=> ( (ns-publics *ns*) 'derp3)
#'user/derp3
user=> (deref #'derp3)
#object[clojure.lang.Var$Unbound 0x745c8706 "Unbound: #'user/derp3"]

Because of this, Potemkin's behavior is arguably correct.

Here's a simplified example of the Midje case:

user=> ( (ns-publics *ns*) 'load-config-files)
nil
user=> (if false (potemkin.namespaces/import-vars [midje.config load-config-files]))
nil
user=> ( (ns-publics *ns*) 'load-config-files)
#'user/load-config-files

;;; This is not a copy of the var. For example, the metadata is wrong:

user=> (meta ( (ns-publics *ns*) 'load-config-files))
{:ns #object[clojure.lang.Namespace 0x4d1f34a6 "user"], :name load-config-files}
user=> (meta #'midje.config/load-config-files)
{:arglists ([]), :line 131, :column 1, :file "midje/config.clj", :name load-config-files, :ns #object[clojure.lang.Namespace 0x58378d16 "midje.config"]}

;;; ... and there's no value.
user=> (deref ( (ns-publics *ns*) 'load-config-files))
#object[clojure.lang.Var$Unbound 0x94a34ff "Unbound: #'user/load-config-files"]
@ztellman
Copy link
Collaborator

ztellman commented Dec 2, 2015

This wasn't intentional, but I think it's enough of an "expected" behavior that I'm going to leave this as-is. Thanks for the report!

@ztellman ztellman closed this as completed Dec 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants