clojure

StackOverflowError on tail-recursive function

我怕爱的太早我们不能终老 提交于 2019-12-23 12:23:56
问题 The following piece of Clojure code results in java.lang.StackOverflowError when I call it with (avg-bids 4000 10 5). I try to figure out why, since sum-bids is written as a tail-recursive function, so that should work. Using Clojure 1.2. Anyone knows why this happens? (ns fixedprice.core (:use (incanter core stats charts))) (def *bid-mean* 100) (defn bid [x std-dev] (sample-normal x :mean *bid-mean* :sd std-dev)) (defn sum-bids [n offers std-dev] (loop [n n sum (repeat offers 0)] (if (zero?

'leiningen' related commands too slow with Mac OS X

邮差的信 提交于 2019-12-23 12:23:07
问题 I installed and run lein, but it seems to slow on My Mac (10.6.4). Running 'time lein help' gives me real 11m8.674s user 0m54.297s sys 1m32.621s I tried once more. real 15m25.560s user 1m36.087s sys 2m52.745s What's wrong with this? Is anyone experiencing similar problem? Is there anyway to check what's the problem? Added When I install, I used 'sudo lein deps', as I got some errors using 'lein deps'. I guess it caused some problem accessing files. When I run ' sudo lein SOMETHING', it works

StackOverflowError on tail-recursive function

被刻印的时光 ゝ 提交于 2019-12-23 12:21:17
问题 The following piece of Clojure code results in java.lang.StackOverflowError when I call it with (avg-bids 4000 10 5). I try to figure out why, since sum-bids is written as a tail-recursive function, so that should work. Using Clojure 1.2. Anyone knows why this happens? (ns fixedprice.core (:use (incanter core stats charts))) (def *bid-mean* 100) (defn bid [x std-dev] (sample-normal x :mean *bid-mean* :sd std-dev)) (defn sum-bids [n offers std-dev] (loop [n n sum (repeat offers 0)] (if (zero?

In Lisp, what is the relationship between a form and a file?

我怕爱的太早我们不能终老 提交于 2019-12-23 11:59:15
问题 I'm having one little hiccup in understanding Lisp. According to the Common Lisp standard, a form is an atom or list that is meant to be evaluated. That seems easy enough. In the real world, at the moment, we store programs in files. SBCL, Clojure, and the like all have the notion of a file that can also be evaluated. How is this understood? Is a file treated ultimately like a single form to be evaluated, is it a collection of forms? For some reason, this has been really confusing me. 回答1:

Clojure message handling / async, multithreaded

六眼飞鱼酱① 提交于 2019-12-23 11:53:11
问题 I have a small Clojure consumer/publisher receiving messages, processing them and sending them off to other consumers, all via RabbitMQ. I've defined a message-handler that handles messages in a separate thread (separate from the main thread that is). As can be seen in the code below, the thread synchronously receives and sends messages, all happening in an event loop started by the lcm/subscribe function. So, the question is, what would be the "Clojure way" to create a N-sized thread pool of

How to avoid having to manually evaluate defrecords and defprotocols while unit testing in Clojure?

▼魔方 西西 提交于 2019-12-23 11:13:50
问题 In my Clojure codebase, I have defined several protocols and several defrecords. I am using clojure.test to unit test the concrete functions defined within my defrecords. For example, let's say I have the following source files: In src/foo/protocols.clj: (ns foo.protocols) (defprotocol RequestAcceptability (desired-accepted-charset [this])) In src/foo/types.clj: (ns foo.types (:use [foo.protocols :only [RequestAcceptability desired-accepted-charset]]) (defrecord RequestProcessor [field-1

Can any Clojure implementation start fast?

↘锁芯ラ 提交于 2019-12-23 10:58:08
问题 $ time java -jar clojure-1.4.0.jar -e '(println "Hello world")' Hello world real 0m4.586s $ time python clojure.py -c '(py/print "Hello world")' real 0m14.690s $ time mono Clojure.Main.exe -e '(println "hello world")' hello world real 0m4.843s /* clojure-metal is not tested due to not being written at the moment */ Can Clojure startup time be little, as like when I run Perl or Python scripts? Is slow startup time an underlying framework's or Clojure's issue (which can be fixed sooner or later

Can any Clojure implementation start fast?

匆匆过客 提交于 2019-12-23 10:57:31
问题 $ time java -jar clojure-1.4.0.jar -e '(println "Hello world")' Hello world real 0m4.586s $ time python clojure.py -c '(py/print "Hello world")' real 0m14.690s $ time mono Clojure.Main.exe -e '(println "hello world")' hello world real 0m4.843s /* clojure-metal is not tested due to not being written at the moment */ Can Clojure startup time be little, as like when I run Perl or Python scripts? Is slow startup time an underlying framework's or Clojure's issue (which can be fixed sooner or later

make-keyword-map in Clojure - Idiomatic?

∥☆過路亽.° 提交于 2019-12-23 10:14:10
问题 I have been writing some Clojure recently, and I found myself using the following pattern frequently enough: (let [x (bam) y (boom)] {:x x :y y}) So I went ahead and wrote the following macro: (defmacro make-keyword-map [& syms] `(hash-map ~@(mapcat (fn [s] [(keyword (name s)) s]) syms))) With that, code now looks like: (let [x (bam) y (boom)] (make-keyword-map x y) Would this sort of macro be considered idiomatic? Or am I doing something wrong, and missing some already established pattern to

Compose multiple predicate functions into one

杀马特。学长 韩版系。学妹 提交于 2019-12-23 10:06:41
问题 Is it possible to compose for example: (defn- multiple-of-three? [n] (zero? (mod n 3)) (defn- multiple-of-five? [n] (zero? (mod n 5)) into: multiple-of-three-or-five? so I can use it for filtering: (defn sum-of-multiples [n] (->> (range 1 n) (filter multiple-of-three-or-five?) (reduce +))) Also I don't want to define it like this: (defn- multiple-of-three-or-five? [n] (or (multiple-of-three? n) (multiple-of-five? n))) For example with Javascript module Ramda it would be achieved as: http:/