clojure

Mature Clojure web frameworks? [closed]

拥有回忆 提交于 2019-12-17 21:24:50
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . What are the current choices of mature Clojure web frameworks? I am looking for some kind of feature matrix telling me what the popular frameworks support and to what extent, including: Response templating (response written in Clojure or in some other markup - e.g. like JSP with

Why clojure's vector function definition is so verbose?

匆匆过客 提交于 2019-12-17 20:45:33
问题 I'm really curious to see why vector's implementation is so verbose? What's the reason it can't just do [] , [a] and [a & args] ? Here is what I get from clj-1.4.0 . => (source vector) (defn vector "Creates a new vector containing the args." {:added "1.0" :static true} ([] []) ([a] [a]) ([a b] [a b]) ([a b c] [a b c]) ([a b c d] [a b c d]) ([a b c d & args] (. clojure.lang.LazilyPersistentVector (create (cons a (cons b (cons c (cons d args)))))))) nil 回答1: The first few cases have direct

Why does clojure convert dashes in names to underscores in the filesystem?

被刻印的时光 ゝ 提交于 2019-12-17 20:42:53
问题 I have been using clojure for a couple of months now and one thing I really don't understand is why dashes in namespace names must be represented as underscores in the filesystem. Can anyone explain this to me, and is it possible to be able to use dashes in the filenames too? 回答1: It's a necessary workaround for Java interoperability. When a Clojure namespace is AOT (ahead-of-time) compiled into a Java .class file, it has to have a name that is a valid Java identifier. Dashes aren't valid in

Why inserting 1000 000 values in a transient map in Clojure yields a map with 8 items in it?

感情迁移 提交于 2019-12-17 20:06:35
问题 If I try to do 1000 000 assoc! on a transient vector, I'll get a vector of 1000 000 elements (count (let [m (transient [])] (dotimes [i 1000000] (assoc! m i i)) (persistent! m))) ; => 1000000 on the other hand, if I do the same with a map, it will only have 8 items in it (count (let [m (transient {})] (dotimes [i 1000000] (assoc! m i i)) (persistent! m))) ; => 8 Is there a reason why this is happening? 回答1: The transient datatypes' operations don't guarantee that they will return the same

Clojure: How do I get a list of combinations of 'coordinates'?

孤人 提交于 2019-12-17 19:38:20
问题 Say i have a function that takes to coordinates, x and y. For x I have a sequence of values say [1 2 3] and for y I have another sequence of values say [4 5 6]. How would I get a list with all the combinations of these? So the desired result would be something like: (myfn [1 2 3] [4 5 6]) => [[1 4] [1 5] [1 6] [2 4] [2 5] [2 6] [3 4] [3 5] [3 6]] Is there an existing function for something like this? 回答1: data> (for [x [1 2 3] y [4 5 6]] (vector x y)) ([1 4] [1 5] [1 6] [2 4] [2 5] [2 6] [3 4

Can't seem to require >!! or <!! in Clojurescript?

时光毁灭记忆、已成空白 提交于 2019-12-17 18:37:41
问题 I must be missing something very obvious here but I'm trying to setup a very basic program to put an item onto a channel then block until I can take it off again. The entire program is below: (ns shopping-2.core (:require [cljs.core.async :as async :refer [>!! <!! put! chan <! close! <!!]])) (let [c (chan)] (>!! c "hello") (.write js/document (<!! c)) (close! c)) The JavaScript error I'm getting is: Uncaught TypeError: Cannot call method 'call' of undefined I had that error before when I

How can I remove an item from a sequence in Clojure?

橙三吉。 提交于 2019-12-17 17:54:24
问题 First, I assume each structure-specific sequences would have different ways to remove an item: Vectors could be by index, List could be remove first or last, Set should be passing of the actual item to remove, etc. Second, I assume there are some methods for removal that are structure agnostic; they work on seq interface. Since sequences are immutable in Clojure, I suspect what you're actually doing is making a cheap copy of the original, only without the original item. This means list

How do I connect to a MySQL database from Clojure?

吃可爱长大的小学妹 提交于 2019-12-17 17:44:21
问题 Assumption: you already have both Clojure and MySQL running on your machine. How do you make them talk? 回答1: Assumption: you already have both Clojure and MySQL running on your machine. checkout and build clojure-contrib: git clone git://github.com/richhickey/clojure-contrib.git cd clojure-contrib build Put the resulting clojure-contrib.jar on your CLASSPATH . Download MySQL Connector/J and put the mysql-connector-java-5.1.7-bin.jar on your CLASSPATH You might have to run your JVM with these

Persistent data structures in Scala

时间秒杀一切 提交于 2019-12-17 17:36:08
问题 Are all immutable data structures in Scala persistent? If not, which of them are and which not? What are the behavioural characteristics of those which are persistent? Also, how do they compare to the persistent data structures in Clojure? 回答1: Scala's immutable data structures are all persistent, in the sense that the old value is maintained by an `update' operation. In fact, I do not know of a difference between immutable and persistent; for me the two terms are aliases. Two of Scala's 2.8

How can I get Clojure :pre & :post to report their failing value?

。_饼干妹妹 提交于 2019-12-17 15:47:27
问题 (defn string-to-string [s1] {:pre [(string? s1)] :post [(string? %)]} s1) I like :pre and :post conditions, they allow me to figure out when I have put "square pegs in round holes" more quickly. Perhaps it is wrong, but I like using them as a sort of poor mans type checker. This isn't philosophy though, this is a simple question. It seems in the above code that I should easily be able to determine that s1 is a function argument in the :pre condition. Similarily, % in the :post condition is