简体   繁体   English

在ns宏中使用:require和:use的最惯用方式是什么

[英]What's the most idiomatic way to use the :require and :use in the ns macro

What's the most idiomatic way to use the :require and :use in the ns macro? ns宏中:use :require:use的最惯用的方法是什么?

(ns app.core
  (:require [clojure.tools.logging :as log]
            [clojure.java.io :as io]
            [clojure.edn])
  (:use [compojure.core]
        [postal.core]
        [ring.adapter.jetty]
        [ring.middleware.multipart-params]))

or 要么

(ns app.core
  (:require [clojure.tools.logging :as log])
  (:require [clojure.java.io :as io])
  (:require clojure.edn)
  (:use compojure.core)
  (:use postal.core)
  (:use ring.adapter.jetty)
  (:use ring.middleware.multipart-params))

or somehow else? 还是其他方式?

Is there any common guidelines or best practices? 是否有任何通用准则或最佳做法?

Your first example is more idiomatic. 您的第一个示例更为惯用。 However, the use of use or :use is discouraged, so the most idiomatic way would be this: 但是,不鼓励use:use ,因此最惯用的方式是:

(ns app.core
  (:require [clojure.edn]
            [clojure.java.io :as io]
            [clojure.tools.logging :as log]
            [compojure.core :refer :all]
            [postal.core :refer :all]
            [ring.adapter.jetty :refer :all]
            [ring.middleware.multipart-params :refer :all]))

You may find it beneficial to try to follow the Clojure community style guide . 您可能会发现尝试遵循Clojure社区风格指南很有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ns宏中use和:use之间有什么区别 - What's the difference between use and :use in the ns macro 写这篇文章最恰当的Clojure方式是什么? - What's the most idiomatic Clojure way to write this? 在Clojure中,使用require ...而不是在ns宏中使用...是否在惯用方面是正确的 - In Clojure, Is it idiomatically correct to use require … as rather than use… in the ns macro 什么是惯用的clojure:使用 - What's idiomatic clojure for :use 在线程宏中记录值的惯用方式是什么? - What's the idiomatic way to log values in a threading macro? 在clojure中为var-args传递向量的最惯用的方法是什么? - What's the most idiomatic way to pass vectors in for var-args in clojure? 删除具有包含一个或多个给定单词集合的值的集合元素的最惯用的方法是什么? - What's the most idiomatic way to to remove collection elements with values containing one or more of a given collection of words? 在Clojure宏中评估修饰参数的惯用方式是什么? - What is the idiomatic way to evaluate a modified argument in a Clojure macro? 保证某些未知值在序列中的惯用方法是什么? - What’s the idiomatic way to guarantee some unknown value is inside a sequence? 在clojure中跟踪先前值的惯用方法是什么? - What's the idiomatic way to keep track of previous values in clojure?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM