clojure

Emacs (Cocoa Emacs) vs Aquamacs for running Clojure on Mac OS X

谁都会走 提交于 2019-12-17 15:35:55
问题 I used Aquamacs so far, and I need to install and run Clojure using SLIME. I googled to get some way to use Clojure on SLIME of Aquamacs, but without success. Questions Is it possible to install Clojure on Aquamacs? Or, can you guess why Clojure on Aquamacs doesn't work? Is it normal that Emacs and Aquamacs can't share the same ELPA? Is it possible to use ELPA to install Conjure on Emacs/Aquamacs? I was told that one can use 'lein swank' to run as a server, do you know how to do that?

Clojure: Semi-Flattening a nested Sequence

眉间皱痕 提交于 2019-12-17 15:29:50
问题 I have a list with embedded lists of vectors, which looks like: (([1 2]) ([3 4] [5 6]) ([7 8])) Which I know is not ideal to work with. I'd like to flatten this to ([1 2] [3 4] [5 6] [7 8]) . flatten doesn't work: it gives me (1 2 3 4 5 6 7 8) . How do I do this? I figure I need to create a new list based on the contents of each list item, not the items, and it's this part I can't find out how to do from the docs. 回答1: If you only want to flatten it one level you can use concat (apply concat

Clojure: cons (seq) vs. conj (list)

夙愿已清 提交于 2019-12-17 15:03:09
问题 I know that cons returns a seq and conj returns a collection. I also know that conj "adds" the item to the optimal end of the collection, and cons always "adds" the item to the front. This example illustrates both of these points: user=> (conj [1 2 3] 4) ; returns a collection [1 2 3 4] user=> (cons 4 [1 2 3]) ; returns a seq (4 1 2 3) For vectors, maps, and sets these differences make sense to me. However, for lists they seem identical. user=> (conj (list 3 2 1) 4) ; returns a list (4 3 2 1)

Clojure: cons (seq) vs. conj (list)

佐手、 提交于 2019-12-17 15:00:16
问题 I know that cons returns a seq and conj returns a collection. I also know that conj "adds" the item to the optimal end of the collection, and cons always "adds" the item to the front. This example illustrates both of these points: user=> (conj [1 2 3] 4) ; returns a collection [1 2 3 4] user=> (cons 4 [1 2 3]) ; returns a seq (4 1 2 3) For vectors, maps, and sets these differences make sense to me. However, for lists they seem identical. user=> (conj (list 3 2 1) 4) ; returns a list (4 3 2 1)

Why such implementation of partial in clojure.core

为君一笑 提交于 2019-12-17 14:54:51
问题 I stumbled across implementation of partial function in cojure.core . It looks like this: (defn partial "Takes a function f and fewer than the normal arguments to f, and returns a fn that takes a variable number of additional args. When called, the returned function calls f with args + additional args." {:added "1.0" :static true} ([f] f) ([f arg1] (fn [& args] (apply f arg1 args))) ([f arg1 arg2] (fn [& args] (apply f arg1 arg2 args))) ([f arg1 arg2 arg3] (fn [& args] (apply f arg1 arg2 arg3

HighGUI is missing from OpenCV 3.0.0 JAR

荒凉一梦 提交于 2019-12-17 10:47:25
问题 I was compiling OpenCV 3.0.0 with Java support. My script was: mkdir /opt/opencv /opt/opencv/opencv-build cd /opt/opencv git clone https://github.com/Itseez/opencv.git cd /opt/opencv/opencv-build export OPENCV_INSTALL_PATH=/opt/opencv export FFMPEG_PATH=/opt/ffmpeg/ffmpeg_build/lib export LD_LIBRARY_PATH=$OPENCV_INSTALL_PATH/lib:$FFMPEG_PATH:/opt/opencv/opencv/3rdparty/lib:$LD_LIBRARY_PATH export PKG_CONFIG_PATH=/opt/ffmpeg/ffmpeg_build/lib/pkgconfig cmake28 -D CMAKE_BUILD_TYPE=RELEASE -D

Fast Prime Number Generation in Clojure

大憨熊 提交于 2019-12-17 10:24:54
问题 I've been working on solving Project Euler problems in Clojure to get better, and I've already run into prime number generation a couple of times. My problem is that it is just taking way too long. I was hoping someone could help me find an efficient way to do this in a Clojure-y way. When I fist did this, I brute-forced it. That was easy to do. But calculating 10001 prime numbers took 2 minutes this way on a Xeon 2.33GHz, too long for the rules, and too long in general. Here was the

How to convert lazy sequence to non-lazy in Clojure

ⅰ亾dé卋堺 提交于 2019-12-17 08:09:54
问题 I tried the following in Clojure, expecting to have the class of a non-lazy sequence returned: (.getClass (doall (take 3 (repeatedly rand)))) However, this still returns clojure.lang.LazySeq . My guess is that doall does evaluate the entire sequence, but returns the original sequence as it's still useful for memoization. So what is the idiomatic means of creating a non-lazy sequence from a lazy one? 回答1: doall is all you need. Just because the seq has type LazySeq doesn't mean it has pending

Idiomatic clojure map lookup by keyword

无人久伴 提交于 2019-12-17 06:47:10
问题 Say I have a clojure map that uses keywords as its keys: (def my-car {:color "candy-apple red" :horsepower 450}) I know that I can look up the value associated with the keyword by either using the keyword or the map as a function and the other as its argument: (my-car :color) ; => "candy-apple red" (:color my-car) ; => "candy-apple red" I realize that both forms can come in handy for certain situations, but is one of them considered more idiomatic for straightforward usage like shown above?

Clojure: reduce vs. apply

余生长醉 提交于 2019-12-17 04:13:12
问题 I understand the conceptual difference between reduce and apply : (reduce + (list 1 2 3 4 5)) ; translates to: (+ (+ (+ (+ 1 2) 3) 4) 5) (apply + (list 1 2 3 4 5)) ; translates to: (+ 1 2 3 4 5) However, which one is more idiomatic clojure? Does it make much difference one way or the other? From my (limited) performance testing, it seems reduce is a bit faster. 回答1: reduce and apply are of course only equivalent (in terms of the ultimate result returned) for associative functions which need