clojure

Why are there clj and cljs folders in my lein re-frame template?

ぐ巨炮叔叔 提交于 2021-02-10 12:13:23
问题 Why are there clj and cljs folders in my lein re-frame template as below? And why do they both include files called .core that appear to use the same namespaces? I've been told this is the place to start when learning re-frame, but I cannot find any explanations of why the templates are setup the way they are or created including the content they include. There is no explanation for any of the boilerplate or code that comes with any lein template which make them very hard to use for beginners

Equivalent of Clojure's “assoc-in” and “get-in” in Common lisp

家住魔仙堡 提交于 2021-02-10 12:01:26
问题 In Clojure you can update a map (dict) with assoc-in and create key path automatically if it don't exist. (assoc-in {:a 1 :b 3} [:c :d] 33) ; {:a 1, :c {:d 33}, :b 3} Same for get-in: you can specify a path of keys (or list indices) and it will return the value specified by the path, nil if it does not exist. (get-in {:a 1, :c {:d 33}, :b 3} [:c :d]) ; 33 (get-in {:a 1, :c {:d 33}, :b 3} [:c :e]) ; nil I like to have the sugar in Common lisp,so I monkeyed a 'assoc-in' and I tested it on a

Read a file in clojure and ignore the first line?

偶尔善良 提交于 2021-02-09 11:57:43
问题 Using code from this answer, I have (defn repeat-image [n string] (println (apply str (repeat n string)))) (defn tile-image-across [x filename] (with-open [rdr (reader filename)] (doseq [line (line-seq rdr)] (repeat-image x line)))) ...to tile an ascii image horizontally. Now, how would I be able to "ignore" the first line? The reason I'm doing this is each image has the coordinates (for example "20 63") as the first line, and I don't need the line. I tried some ways (keeping an index,

How do I add CORS to a compojure-api app?

你离开我真会死。 提交于 2021-02-09 09:40:16
问题 How can I add CORS to this code snippet? (def app (api {:swagger {:ui "/docs" :spec "/swagger.json"}} (GET "/route-a" [] "a") (GET "/route-b" [] "b") (GET "/route-c" [] "c"))) I would like to use https://github.com/r0man/ring-cors and have tried this, but it did not seem to do anything. I would like to see the response header contain Access-Control-Allow-Origin but it is missing. (-> (api {:swagger {:ui "/docs" :spec "/swagger.json"}} (GET "/route-a" [] "a") (GET "/route-b" [] "b") (GET "

How do I add CORS to a compojure-api app?

大憨熊 提交于 2021-02-09 09:36:17
问题 How can I add CORS to this code snippet? (def app (api {:swagger {:ui "/docs" :spec "/swagger.json"}} (GET "/route-a" [] "a") (GET "/route-b" [] "b") (GET "/route-c" [] "c"))) I would like to use https://github.com/r0man/ring-cors and have tried this, but it did not seem to do anything. I would like to see the response header contain Access-Control-Allow-Origin but it is missing. (-> (api {:swagger {:ui "/docs" :spec "/swagger.json"}} (GET "/route-a" [] "a") (GET "/route-b" [] "b") (GET "

How do I add CORS to a compojure-api app?

邮差的信 提交于 2021-02-09 09:36:16
问题 How can I add CORS to this code snippet? (def app (api {:swagger {:ui "/docs" :spec "/swagger.json"}} (GET "/route-a" [] "a") (GET "/route-b" [] "b") (GET "/route-c" [] "c"))) I would like to use https://github.com/r0man/ring-cors and have tried this, but it did not seem to do anything. I would like to see the response header contain Access-Control-Allow-Origin but it is missing. (-> (api {:swagger {:ui "/docs" :spec "/swagger.json"}} (GET "/route-a" [] "a") (GET "/route-b" [] "b") (GET "

Make Clojure's println “thread-safe” in the same way as in Java

一笑奈何 提交于 2021-02-08 07:28:32
问题 While playing around with concurrent calls to println in Clojure I found that its behaviour is different from Java's System.out.println . What in Java I would write class Pcalls { public static void main(String[] args) { Runnable[] fns = new Runnable[3]; for (int i = 0; i < 3; i++) { fns[i] = new Runnable() { @Override public void run() { for (int i = 1; i <= 5; i++) { System.out.println("Hello iteration " + i); } } }; } for (Runnable fn : fns) new Thread(fn).start(); } } I paraphrased in

How to return a lazy sequence from a loop recur with a conditional in Clojure?

烈酒焚心 提交于 2021-02-08 07:28:28
问题 Still very new to Clojure and programming in general so forgive the stupid question. The problem is: Find n and k such that the sum of numbers up to n (exclusive) is equal to the sum of numbers from n+1 to k (inclusive). My solution (which works fine) is to define the following functions: (defn addd [x] (/ (* x (+ x 1)) 2)) (defn sum-to-n [n] (addd(- n 1))) (defn sum-to-k [n=1 k=4] (- (addd k) (addd n))) (defn is-right[n k] (= (addd (- n 1)) (sum-to-k n k))) And then run the following loop:

How to return a lazy sequence from a loop recur with a conditional in Clojure?

穿精又带淫゛_ 提交于 2021-02-08 07:27:57
问题 Still very new to Clojure and programming in general so forgive the stupid question. The problem is: Find n and k such that the sum of numbers up to n (exclusive) is equal to the sum of numbers from n+1 to k (inclusive). My solution (which works fine) is to define the following functions: (defn addd [x] (/ (* x (+ x 1)) 2)) (defn sum-to-n [n] (addd(- n 1))) (defn sum-to-k [n=1 k=4] (- (addd k) (addd n))) (defn is-right[n k] (= (addd (- n 1)) (sum-to-k n k))) And then run the following loop:

Why does “M” appear in Clojure MySQL Query Results

梦想与她 提交于 2021-02-08 05:38:14
问题 I have a Clojure query that returns a row, and here is a partial printout of the returned row (map). ({:employer_percent 0.00M, ... :premium 621.44M, ...}) These two columns are decimal(5,2) and decimal(7,2) respectively in the mysql table. Why is there an 'M' suffix at the end of each of these values? Here is the code that forms and executes the query. (def db {:classname "com.mysql.jdbc.Driver" :subprotocol "mysql" :subname "//system/app" :user "app-user" :password "pwrd"}) (defn get-recent