[英]Why can't I :require :refer in clojurescript?
See: https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure#namespaces 请参阅: https : //github.com/clojure/clojurescript/wiki/Differences-from-Clojure#namespaces
It bothers me that idiomatic clojure is: 习惯性的clojure是困扰我的:
(ns clojure-example
(:require [clojure.set :refer [union]]))
But idiomatic clojurescript is: 但惯用的clojurescript是:
(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! 当然,clojurescript代码也可以在clojure中工作,但是这会让恶魔们知道我应该使用
require
:refer
改为:refer
!
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). 实际上ClojureScript支持
:require :refer
并支持它很长一段时间( 这是我的提交引入支持:refer
2012年6月12日:refer
)。
That wiki page is out of date.
那个维基页面已经过时了。
I have edited the section on namespaces on the wiki to bring it up to date. 我已经在wiki上编辑了名称空间部分,以使其更新。
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. 至于什么是惯用语,当然有人不喜欢
:use
,但是经过几年的生产使用后,这几乎不会使它变得单一。 You're free to make up your own mind as to whether you prefer :require :refer
or not. 您可以自由决定是否愿意
:require :refer
与否。
(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.) (虽然使用情况
:use
实际上提供了功能, :require
不-用拉几个命名空间(:use lib.foo lib.bar lib.quux)
-确实不ClojureScript支持,通过设计)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.