clojure

Using gradle/clojuresq to build clojure

心不动则不痛 提交于 2019-12-19 09:03:20
问题 I'm trying to use gradle/Clojuresque to build clojure code, run it, and get uberjar. I use hints from http://dev.clojure.org/display/doc/Getting+Started+with+Gradle, https://bitbucket.org/kotarak/clojuresque/wiki/Getting%20Started, and 'Could not find us.bpsm:edn-java:0.4.3' error with Gradle for Clojure (Clojuresque). This is the grade script. buildscript { repositories { maven { url "http://clojars.org/repo" } mavenCentral() } dependencies { classpath "clojuresque:clojuresque:1.7.0" } }

Must Clojure circular data structures involve constructs like ref?

谁说胖子不能爱 提交于 2019-12-19 07:38:14
问题 Today I've seen some references to tying the knot and circular data structures. I've been out reading some answers, and the solutions seem to involve using a ref to point back to the head of the list. One particular SO question showed a Haskell example, but I don't know Haskell well enough to know if the example was using a the Haskell equivalent of a ref. Is there a way to make a Clojure data structure circular without using a ref or similar construct? Thanks. 回答1: I straightforwardly

How to do HTTP 302 redirects with Noir Web framework

独自空忆成欢 提交于 2019-12-19 07:09:39
问题 I'm helping to set up a Web site with Clojure's Noir framework, though I have a lot more experience with Django/Python. In Django, I'm used to URLs such as http://site/some/url being 302-redirected automagically to http://site/some/url/ Noir is more picky and does not do this. What would be the proper way to do this automatically? Since good URLs are an important way of addressing into a site, and many users will forget the trailing slash, this is basic functionality I'd like to add to my

Clojure, merging two array of maps

有些话、适合烂在心里 提交于 2019-12-19 06:56:28
问题 I have two arrays of maps 1st is [{:a 1 :b 2 :d 6} {:a 2 :b 2} {:a 7 :b 7}] 2nd is [{:a 3 :c 3 :e 9 :y 7} {:a 2 :b 6 :c 8}] depending on the value of a i.e. if its matches in 2nd array the '2nd map' should be merged with '1st map' and the resultant array of maps should be Res should be [{:a 1 :b 2 :d 6} {:a 2 :b 6 :c 8} {:a 7 :b 7} {:a 3 :c 3 :e 9 :y 7}] Can anyone help me on this. Thanks in advance. 回答1: Here you go: user> (def xs [{:a 1 :b 2 :d 6} {:a 2 :b 2} {:a 7 :b 7}]) #'user/xs user>

Clojure, merging two array of maps

泄露秘密 提交于 2019-12-19 06:56:00
问题 I have two arrays of maps 1st is [{:a 1 :b 2 :d 6} {:a 2 :b 2} {:a 7 :b 7}] 2nd is [{:a 3 :c 3 :e 9 :y 7} {:a 2 :b 6 :c 8}] depending on the value of a i.e. if its matches in 2nd array the '2nd map' should be merged with '1st map' and the resultant array of maps should be Res should be [{:a 1 :b 2 :d 6} {:a 2 :b 6 :c 8} {:a 7 :b 7} {:a 3 :c 3 :e 9 :y 7}] Can anyone help me on this. Thanks in advance. 回答1: Here you go: user> (def xs [{:a 1 :b 2 :d 6} {:a 2 :b 2} {:a 7 :b 7}]) #'user/xs user>

How to configure leiningen to use newest Clojure version for repl started outside of project?

我是研究僧i 提交于 2019-12-19 06:26:32
问题 When I start clojure repl for specific project, for leiningen is enough to specify correct clojure version in the concrete project.clj file as described here. But when I start repl outside the project then the older version is started. In my case the older version is 1.5.1 and I want to upgrade to 1.6.0 . Here has proposed not working solution, but in the comments bellow is said that in lieingen version 2.1 the problem is resolved. I'm with version 2.3.4 of leiningen but the proposed solution

Variable passed to macro gets resolved in wrong namespace?

 ̄綄美尐妖づ 提交于 2019-12-19 05:57:28
问题 The Noir macro defpage is giving me a little bit of trouble. I am trying to construct a call similar to this: (defpage [:post "some/url"] [data] ;; some stuff... ) However, instead of using the keyword :post I would like to use a variable, like this: (def my-method :post) (defpage [my-method "some/url"] [data] ;; some stuff... ) The problem is that when the macro expands, it wants to resolve the variable my-method in the compojure.core namespace instead of my own, giving me the error: No such

Why should (every? string? []) yield true?

自古美人都是妖i 提交于 2019-12-19 05:17:51
问题 Looking at the source code for every? makes clear why (every? string? []) => true This is because every? is implemented recursively and uses (nil? (seq coll)) to end recursion. But, my question is, what sense does this behaviour make? Just tripped over that. I have solved my issue using (and (seq x) (every? string? x)) 回答1: Because it functions the same as the forall-quantifier. That is, it is initially assumed true and each application of the predicate is an attempt to prove it false. The

How can I see the number of rollbacks in my STM in Clojure?

夙愿已清 提交于 2019-12-19 05:15:10
问题 How can I see the number of rollbacks in my STM in Clojure? 回答1: You can't... unless you are willing to cheat: (defmacro spy-dosync [& body] `(let [retries# (atom -1) result# (dosync (swap! retries# inc) ~@body)] (println "retries count:" @retries#) result#)) and then replace your dosync by a spy-dosync. 回答2: If you're feeling frisky, you could hack the Clojure source and rebuild (it's easy to rebuild the Clojure source). Transaction retries happen in src/jvm/clojure/lang/LockingTransaction

Printing a tree lazily in Newick format

北城以北 提交于 2019-12-19 04:14:32
问题 I wish to print a binary tree in Newick format, showing each node's distance to its parent. At the moment I haven't had an issue with the following code, which uses regular recursion, but a tree too deep may produce a stack overflow. (defn tree->newick [tree] (let [{:keys [id children to-parent]} tree dist (double to-parent)] ; to-parent may be a rational (if children (str "(" (tree->newick (first children)) "," (tree->newick (second children)) "):" dist) (str (name id) ":" dist)))) (def