문제

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.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top