简体   繁体   English

在哪里可以找到Leiningen中依赖项的有效版本号

[英]Where to find valid version numbers for dependencies in Leiningen

I'm new to Clojure and Leiningen, and I've determined that some of what I'll want to use is located in clojure.contrib.generic.math-functions. 我是Clojure和Leiningen的新手,我已经确定我想要使用的一些内容位于clojure.contrib.generic.math-functions中。 I found API information for that at http://richhickey.github.com/clojure-contrib/branch-1.1.x/math-api.html , but I can't find anything that helps me figure out what I should put into my project.clj file for that dependency. 我在http://richhickey.github.com/clojure-contrib/branch-1.1.x/math-api.html找到了API的信息,但我找不到任何可以帮助我弄清楚应该放入什么的东西我的project.clj文件用于该依赖项。

I have tried [clojure.contrib.generic.math-functions "1.1"] , [clojure.contrib.generic.math-functions "1.1.x"] , and [clojure.contrib.generic.math-functions "1.1.0"] . 我试过[clojure.contrib.generic.math-functions "1.1"][clojure.contrib.generic.math-functions "1.1.x"][clojure.contrib.generic.math-functions "1.1.0"] For each of those, I get something like... 对于每一个,我得到像......

...
Caused by: org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException: Missing:
----------
1) clojure.contrib.generic.math-functions:clojure.contrib.generic.math-functions:jar:1.1

All clojure-contrib namespaces are shipped within a single jar file, for which the dependency has to be listed like: 所有clojure-contrib命名空间都在一个jar文件中提供,其依赖关系必须列为:

[org.clojure/clojure-contrib "1.2.0"]

Please note that there are different versions available of that artifact. 请注意,该工件有不同的版本。 The 1.2.0 is the current stable release. 1.2.0是目前的稳定版本。

In order to use functions coming from the math-functions namespace in your clojure code, you need to either require or use such namespace, usually done within the ns form at the beginning of your source file: 为了使用从数学函数的命名空间功能来在您的Clojure代码,你需要或者requireuse这样的命名空间,通常是内完成ns形成在源文件的开头:

(ns my.namespace
    (:use [clojure.contrib.generic.math-functions]))

Have a look here to see the differences between use and require . 看看这里看看userequire之间的差异。

The next version of Leiningen will have a search task for precisely this purpose. 下一版Leiningen将为此目的进行搜索任务。 It will search Clojars, Maven Central, and any other repositories your project has listed, provided they offer up downloadable indices. 它将搜索Clojars,Maven Central以及您的项目列出的任何其他存储库,前提是它们提供可下载的索引。 It's already implemented, so if you run Leiningen from git you can use it. 它已经实现了,所以如果你从git运行Leiningen你可以使用它。

Also, the Leiningen tutorial covers this. 此外,Leiningen教程涵盖了这一点。 Type "lein help tutorial". 输入“lein help tutorial”。

You can generally find what you need at clojars.org - it's the default repository for leiningen. 您通常可以在clojars.org上找到所需内容 - 它是leiningen的默认存储库。 The current stable release of Clojure is 1.2.0, so you'd have this in your leiningen project.clj : 目前Clojure的稳定版本是1.2.0,所以你在leiningen project.clj有这个.clj:

[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]

To use the generic math functions in your clojure, require or use it in your namespace declaration at the top of your source file: 要在clojure中使用泛型数学函数,请在源文件顶部的名称空间声明中requireuse它:

(ns your-namespace
    (:use [clojure.contrib.generic.math-functions :as mathf]))

This allows you to refer to the functions in that namespace like this: 这允许您像这样引用该命名空间中的函数:

(mathf/abs -10) ;; => 10

:use -ing namespaces with :as is the preferred way to use functions from other namespaces in your code. :use -ing namespaces with :as是在代码中使用其他命名空间函数的首选方法。 require is ok, but you'd have to prefix your functions with the entire namespace (eg clojure.contrib.generic.math-functions/abs ) so that's not practical. require是好的,但你必须在函数clojure.contrib.generic.math-functions/abs整个命名空间(例如clojure.contrib.generic.math-functions/abs ),这是不切实际的。 Using a namespace without :as allows you to use these functions without any prefix at all (eg abs ), but you're more likely to get namespace clashes and it might be difficult to see where functions come from, especially if you :use many libraries. 使用没有:as的命名空间允许你在没有任何前缀的情况下使用这些函数(例如abs ),但你更有可能得到命名空间冲突,并且可能很难看到函数的来源,特别是如果你:use很多库。

You can browse all libraries available from the default leiningen repository by checking out http://clojars.org/repo/ . 您可以通过访问http://clojars.org/repo/浏览默认leiningen存储库中提供的所有库。 The structure of clojure-contrib will change when 1.3.0 is out, so you'll have to include the specific contrib library if you're using version 1.3.0-alpha-xx: 当1.3.0出现时, clojure-contrib的结构会发生变化,因此如果您使用的是1.3.0-alpha-xx版本,则必须包含特定的contrib库:

[org.clojure.contrib/generic "1.3.0-alpha4"]

Now that the clojure.contrib has been broken up, the math functions are in something called math.numeric-tower. 现在clojure.contrib已被分解,数学函数就是math.numeric-tower。 The lein dependency is specified like this: lein依赖项指定如下:

[org.clojure/math.numeric-tower "0.0.1"]

You can use or require as seems appropriate, for example 例如,您可以使用或要求

(use '[clojure.math.numeric-tower])

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM