Is it possible to use :refer :all in a ClojureScript :require?
Asked Answered
B

1

33

I'm just trying out ClojureScript, starting out by converting something I wrote in Clojure into cljx.

When I try to compile it I get:

clojure.lang.ExceptionInfo: :refer must be followed by a sequence of symbols in :require 

I'm finding some oblique references online, but nowhere where it's spelled out whether I should be able to use a :refer :all in a ClojureScript program.

If I can't do it, what's the reason for this restriction?

Bolection answered 28/6, 2014 at 4:4 Comment(0)
T
50

No, it's intentionally not possible. There was a conversation on the ClojureScript mailing list recently related to :refer :all and it looks like it will never be supported.

To quote David Nolen from that thread:

It's just bad style and as far I know the only reason it hasn't changed in Clojure is because the core team is very adamant about preserving backwards compatibility when possible. The conspicuous lack of naked :use in ClojureScript was intentional.

Talky answered 28/6, 2014 at 10:28 Comment(3)
Can someone explain why it would be bad style? Is it preferred to have one large name space instead of two, even if you can see a natural division between lower level functions and higher level exported functions?Olmstead
Another problem with naked :use or refer :all is that it introduces a static phase separation. If you do (ns my-ns (:require foo.bar refer :all)) now, then add foo.bar/baz later, you might conflict with a baz already defined in my-ns. Using "all" means you must be able to enumerate the closed list of declarations in the namespace or risk super confusing interactive and partial recompilation behavior. This is especially problematic if you have macros.Seethe
It's bad style because when you try to read and understand a namespace that does this you can't tell where the functions come from. It also makes it harder to search and replace as you refactor, move things around, etc., because you don't have a common ns prefix to look for.Harley

© 2022 - 2024 — McMap. All rights reserved.