clojure

Problem compiling in Clojure

旧街凉风 提交于 2020-01-12 18:45:54
问题 I've been trying to compile a very simple test.clj in Clojure without any success. I have a thread on the Clojure Google Group with several responses, but nothing has helped. To quickly summarize, here is my clojure file: (ns test.test (:gen-class)) (defn -main [gre] (println (str "Hello " gre))) Basically it's the example file provided in the Clojure documentation. I have placed this file appropiately in clojure/src/test/test.clj , and should be able to compile with (compile 'test.test) ,

What are the allowed characters in a Clojure keyword?

China☆狼群 提交于 2020-01-12 13:49:09
问题 I am looking for a list of the allowed characters in a clojure keyword. Specifically I am interested to know if any of the following characters are allowed: - _ / . I am not a java programmer, so I would not know the underlying ramifications if any. I don't know if the clojure keyword is mapped to a java keyword if there is such a thing. 回答1: Edit : When I initially composed this answer, I was probably a little too heavily invested in the question of "what can you get away with?" In fairness

Trouble connecting to postgresql DB on Heroku with Korma (Clojure)

孤人 提交于 2020-01-12 07:28:14
问题 I am parsing the postgresql uri in my config settings on Heroku. But I cannot seem to get it working. Any help would be greatly appreciated, I'm probably missing something straight forward. Here is the code used. (def dev-db-info {:db "dbname" :user "username"}) (defn parse-db-uri [uri] (drop 1 (split uri #"://|:|@|/"))) (defn create-map-from-uri [uri] (let [parsed (parse-db-uri uri)] (zipmap [:user :password :host :port :db] parsed))) (defn db-info [] (if production? (create-map-from-uri

How to generate repeatable random sequences with rand-int

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-12 07:20:46
问题 I want to be able to generate repeatable numbers using rand in Clojure. (Specifically, I want results of calls to rand-nth or Incanter's sample to be repeatable, and these call rand-int which in turn calls rand ). I figured out from this question that if I use clojure.data.generators, I can reset the random state: (require '[clojure.data.generators :as gen]) (alter-var-root #'gen/*rnd* (constantly (java.util.Random. 437))) (gen/reservoir-sample 5 (range 1000)) ; => [940 591 636 12 755] (gen

What is the Scala equivalent of Clojure's Atom?

↘锁芯ラ 提交于 2020-01-12 07:01:28
问题 Clojure has an Atom for changing state between threads in a synchronous and independent manner, that is not part of the STM. You use it like this: user=> (def my-atom (atom 0)) #'user/my-atom user=> @my-atom 0 user=> (swap! my-atom inc) 1 user=> @my-atom 1 user=> (swap! my-atom (fn [n] (* (+ n n) 2))) 4 My question is: What is the Scala equivalent of Clojure's Atom? 回答1: As @Shepmaster and @om-nom-nom said, it's a wrapper around java.util.concurrent.atomic.Atomic... . An equivalent wrapper

Processing pairs of values from two sequences in Clojure

江枫思渺然 提交于 2020-01-12 05:22:13
问题 I'm trying to get into the Clojure community. I've been working a lot with Python, and one of the features I make extensive use of is the zip() method, for iterating over pairs of values. Is there a (clever and short) way of achieving the same in Clojure? 回答1: Another way is to simply use map together with some function that collects its arguments in a sequence, like this: user=> (map vector '(1 2 3) "abc") ([1 \a] [2 \b] [3 \c]) 回答2: (zipmap [:a :b :c] (range 3)) -> {:c 2, :b 1, :a 0}

Processing pairs of values from two sequences in Clojure

六月ゝ 毕业季﹏ 提交于 2020-01-12 05:22:04
问题 I'm trying to get into the Clojure community. I've been working a lot with Python, and one of the features I make extensive use of is the zip() method, for iterating over pairs of values. Is there a (clever and short) way of achieving the same in Clojure? 回答1: Another way is to simply use map together with some function that collects its arguments in a sequence, like this: user=> (map vector '(1 2 3) "abc") ([1 \a] [2 \b] [3 \c]) 回答2: (zipmap [:a :b :c] (range 3)) -> {:c 2, :b 1, :a 0}

modelling multiple many-to-many relationships in datomic

こ雲淡風輕ζ 提交于 2020-01-12 04:59:09
问题 Maybe I'm still thinking sql but I'm having trouble writing the datomic schema for a simple blog. I don't really understand the :db/cardinality attribute and what it means. In terms of this type of system, how do we model these relationships The system supports multiple users Each user may have many categories Each user may have many articles Each category may have many users Each category may have many articles Each article may have many comments Each comment has one user 回答1: Look at the

The Clojure (or Lisp) Equivalent of a Compound Boolean Test

梦想的初衷 提交于 2020-01-12 03:09:48
问题 In C++ I'd write something like this: if (a == something && b == anotherthing) { foo(); } Am I correct in thinking the Clojure equivalent is something like this: (if (= a something) (if (= b anotherthing) (foo))) Or is there another way to perform a logical "and" that I've missed? As I said the latter form seems to work correctly--I was just wondering if there's some simpler way to perform the logical and. And searching for "boolean" "logical" and "and" on the Clojure Google Group turned up

Why do I lose all symbols when using in-ns to move to a new namespace?

浪尽此生 提交于 2020-01-11 10:47:09
问题 Running the following code in a Leiningen REPL: (in-ns 'my-namespace.core) (+ 2 2) results in this error: CompilerException java.lang.RuntimeException: Unable to resolve symbol: + in this context Why? 回答1: When you create a new namespace using in-ns , the core namespace ( clojure.core ) is not referred by default. "Referring" a namespace means including it in your namespace in such a way that you can refer to that namespace's symbols as your own. It is still possible to use symbols from