See: https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure#namespaces
It bothers me that idiomatic clojure is:
(ns clojure-example
(:require [clojure.set :refer [union]]))
But idiomatic clojurescript is:
(ns clojurescript-example
(:use [clojure.set :only [union]]))
Of course, the clojurescript code would work in clojure as well, but that brings out demons who say I should use require
with :refer
instead!
What is the cause of this?
Actually ClojureScript does support :require :refer
and has supported it for a long while (here's my commit introducing support for :refer
from 12 Jun 2012). That wiki page is out of date. I have edited the section on namespaces on the wiki to bring it up to date.
As for what is idiomatic, there are of course people who dislike :use
, but that hardly makes it unidiomatic after several years of production use. You're free to make up your own mind as to whether you prefer :require :refer
or not.
(Although the use case where :use
actually offers capabilities that :require
does not -- pulling in several namespaces with (:use lib.foo lib.bar lib.quux)
-- is indeed not supported in ClojureScript, by design.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With