clojure

the -> macro and partial function

安稳与你 提交于 2020-01-16 03:28:07
问题 Why can't I use a partial function or an anonymous function in a chained call with -> ? (-> "123" seq sort reverse (partial apply str)) => #<core$partial$fn__4230 clojure.core$partial$fn__4230@335f63af> I would have thought the partial function would be created and immediately applied to the previous function's result, but it's actually returned itself. A simple chaining of functions with one parameter of course works without problems: (-> "123" seq sort reverse clojure.string/join) 回答1: As -

How to remove elements from a vector in a fast way in Clojure?

百般思念 提交于 2020-01-15 13:21:16
问题 I'm trying to remove elements from a Clojure vector: Note that I'm using Clojure's operations from Kotlin val set = PersistentHashSet.create("foo") val vec = PersistentVector.create("foo", "bar") val seq = clojure.`core$remove`.invokeStatic(set, vec) as ISeq val resultVec = clojure.`core$vec`.invokeStatic(seq) as PersistentVector This is the equivalent of the following Clojure code: (remove #{"foo"} ["foo" "bar"]) The code works fine but I've noticed that creating a vector from the seq is

How to remove elements from a vector in a fast way in Clojure?

纵饮孤独 提交于 2020-01-15 13:21:13
问题 I'm trying to remove elements from a Clojure vector: Note that I'm using Clojure's operations from Kotlin val set = PersistentHashSet.create("foo") val vec = PersistentVector.create("foo", "bar") val seq = clojure.`core$remove`.invokeStatic(set, vec) as ISeq val resultVec = clojure.`core$vec`.invokeStatic(seq) as PersistentVector This is the equivalent of the following Clojure code: (remove #{"foo"} ["foo" "bar"]) The code works fine but I've noticed that creating a vector from the seq is

Serving data with Ring and Compojure

不打扰是莪最后的温柔 提交于 2020-01-15 11:55:27
问题 I am configuring and setting up a web application to serve the JSON data http://www.ericrochester.com/clj-data-analysis/data/census-race.json file statically. My dependencies: :dependencies [[org.clojure/clojure "1.5.1"] [org.clojure/clojurescript "0.0-2197"] [ring/ring-core "1.1.7"] [ring/ring-jetty-adapter "1.1.7"] [compojure "1.1.3"] [hiccup "1.0.2"] [lein-cljsbuild "0.2.10"]] As the title says I'm using Ring as a development plugin, i.e. :plugins [[lein-ring "0.8.3"]] The Leiningen

Can you set the size limit of a post request in header?

扶醉桌前 提交于 2020-01-15 11:30:07
问题 I'm trying to make a post request to my noir server but I have too many parameters and the server just responds with 413 status code. I was wondering if I could raise the character limit for the post request. I read it's possible with other services like What is the size limit of a post request? and Clojure/Ring: Using the ring jetty adapter, large requests give me a 413: FULL HEAD error. Thanks! 回答1: noir.server/start accepts a map of options as a second argument (which is itself optional).

Can't see printed values if launch script with `java`

ⅰ亾dé卋堺 提交于 2020-01-15 06:13:57
问题 I have this code: (ns test (:gen-class)) (defn -main [& args] (println "hello!")) But when I run java -cp clojure-1.6.0/clojure-1.6.0.jar clojure.main test.clj I get no output. Why? How to fix this? 回答1: Both ns and defn do not output anything. If you would like to print "hello!" by invoking the -main function, you have to add a function call at the end of the test.clj file. (ns test (:gen-class)) (defn -main [& args] (println "hello!")) (-main) 回答2: You call the -main function like so: java

nginx prod setup for Clojure WebSocket app

六月ゝ 毕业季﹏ 提交于 2020-01-15 05:33:11
问题 I'm trying to deploy my first Clojure WebSocket app and I think I'm getting close. I get a good response locally, and it looks like the endpoint wants to face the outside world (I see that the port is open when I run netstat ), but no response. I'm certain that I have something setup incorrectly in nginx . I currently already host a few other websites on this server, just want to add the necessary config to get requests made to wss://domain.com:8001 to communicate with my app. Here is the

Using midje provided in a let clause doesn't stub methods

拈花ヽ惹草 提交于 2020-01-15 05:27:44
问题 When I make a test using an outer let clause to structure some definitions and calls, the stubs don't work the way I'd expect. For example: This test fails (fact "blah" (let [x (meth1 123)] x => 246 (provided (meth2 123) => 246))) With this code (defn meth2 [x] (prn "meth2" x) (* 3 x)) (defn meth1 [x] (let [y (meth2 x)] y)) Am I not supposed to use let statements with midje? I can't understand how to get these to pass without removing the let . 回答1: First of all, your test would even fail if

How to create Clojure Zipper

孤街醉人 提交于 2020-01-15 03:56:20
问题 How could I create the following graph using Clojure Zipper ( vector-zip ): A / | \ B C D / \ E F I have tried (vector-zip ["A" ["B" "C" "D"["E" "F"]] ]) It returns [["A" ["B" "C" "D" ["E" "F"]]] nil] Is it right? 回答1: Yes it's right. Some tests of your code: (require '[clojure.zip :as zip]) (def zv (zip/vector-zip ["A" ["B" "C" "D"["E" "F"]]])) (-> zv zip/next) ; => ["A" {:l [], :pnodes [["A" ["B" "C" "D" ["E" "F"]]]], :ppath nil, :r (["B" "C" "D" ["E" "F"]])}] (-> zv zip/next zip/node) ; =>

OutOfMemoryError when parsing XML in Clojure with data.zip

泄露秘密 提交于 2020-01-14 19:36:27
问题 I want to use Clojure to extract the titles from a Wiktionary XML dump. I used head -n10000 > out-10000.xml to create smaller versions of the original monster file. Then I trimmed with a text editor to make it valid XML. I renamed the files according to the number of lines inside ( wc -l ): (def data-9764 "data/wiktionary-en-9764.xml") ; 354K (def data-99224 "data/wiktionary-en-99224.xml") ; 4.1M (def data-995066 "data/wiktionary-en-995066.xml") ; 34M (def data-7999931 "data/wiktionary-en