clojure

Vagrant / Clojure / Emacs

霸气de小男生 提交于 2020-01-01 03:26:06
问题 I want to put together a standard environment for exploring Clojure with Emacs. Has anyone got a recipe that would suit this? I'm thinking of a Vagrant system running a flavour of Ubuntu, with NREPL and some useful EMACS support plugins. 回答1: vagrant box add preciseMinimal http://goo.gl/wxdwM Change to Clojure vagrant base folder vagrant init preciseMinimal vagrant up vagrant ssh or ssh to 127.0.0.1 port 2222 (or other port mentioned in "vagrant up" output) sudo apt-get update sudo apt-get

Why is it customary to put many closing parentheses on one line in Lisp-based languages?

霸气de小男生 提交于 2020-01-01 01:30:08
问题 Usually code looks like this: (one-thing (another-thing arg1 (f arg5 r)) (another-thing arg1 (f arg5 r))) Why doesn't it like this?: (one-thing (another-thing arg1 (f arg5 r)) (another-thing arg1 (f arg5 r)) ) It allows adding and removing "another-thing" lines more easily (without removing and re-adding trailing closing parenthesis). Also you can put a some comment on that lone closing parenthesis (such as "; end of the loop"). How bad is it when I mix by code that uses the second style with

Clojure: How do I apply a function to a subset of the entries in a hash-map?

ぃ、小莉子 提交于 2019-12-31 23:07:50
问题 I am not to Clojure and attempting to figure out how to do this. I want to create a new hash-map that for a subset of the keys in the hash-map applies a function to the elements. What is the best way to do this? (let [my-map {:hello "World" :try "This" :foo "bar"}] (println (doToMap my-map [:hello :foo] (fn [k] (.toUpperCase k))) This should then result a map with something like {:hello "WORLD" :try "This" :foo "BAR"} 回答1: (defn do-to-map [amap keyseq f] (reduce #(assoc %1 %2 (f (%1 %2)))

Declare array as return type in gen-class method declaration in Clojure

巧了我就是萌 提交于 2019-12-31 21:33:15
问题 How to declare an array in method declaration in gen-class? (ns foo.bar (:gen-class :methods [[parseString [String Object] Object]])) That works fine. But the return type is really an array. How I can declare that so Java can understand it? 回答1: Try (ns foo.bar (:gen-class :methods [[parseString [String Object] "[Ljava.lang.Object;"]])) 回答2: I needed a static Number[][] method(int, Number[][]); signature, in a similar way: (:gen-class :methods [#^{:static true} [method [int "[[Ljava.lang

Clojure/Java: Java libraries for spectrum analysis of sound? [closed]

依然范特西╮ 提交于 2019-12-31 10:35:33
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 days ago . I am looking for a library that can accept a chunk of audio data and return the average amplitude over time within a given frequency band. I've already asked this question over at comp.dsp, but it's clear to me that acquiring the know-how to build this on my own using a basic FFT library is going to require more

How does clojure class reloading work?

爷,独闯天下 提交于 2019-12-31 08:12:53
问题 I've been reading code and documentation to try to understand how class reloading works in clojure. According to many websites, such as http://tutorials.jenkov.com/java-reflection/dynamic-class-loading-reloading.html , whenever you load a class essentially you obtain the bytecode (via any data mechanism), convert the bytecode into an instance of class Class (via defineClass), and then resolve (link) the class via resolveClass. (Does defineClass implicitly call resolveClass?). Any given

Clojure: Using proxy and mutable fields

扶醉桌前 提交于 2019-12-31 03:06:23
问题 I'm using proxy in Clojure to extend a Java class. I need to set a field in the superclass, how can i do this? The code below doesn't work. (proxy [BasicPlayer] [] (open [url] (set! super/m_dataSource url))) 回答1: From the documentation for proxy: Note that while method fns can be provided to override protected methods, they have no other access to protected members, nor to super, as these capabilities cannot be proxied. Sorry, but it sounds like you're out of luck. You can call protected

Iterate over all keys of nested map

送分小仙女□ 提交于 2019-12-31 01:41:48
问题 Given: {:o {:i1 1 :i2 {:ii1 4}}} I'd like to iterate over the keys of the map in "absolute" form from the root as a vector. So I'd like: { [:o :i1] 1 [:o :i2 :ii1] 4 } As the result. Basically only get the leaf nodes. 回答1: A version that I think is rather nicer, using for instead of mapcat : (defn flatten-keys [m] (if (not (map? m)) {[] m} (into {} (for [[k v] m [ks v'] (flatten-keys v)] [(cons k ks) v'])))) The function is naturally recursive, and the most convenient base case for a non-map

Iterate over all keys of nested map

做~自己de王妃 提交于 2019-12-31 01:41:09
问题 Given: {:o {:i1 1 :i2 {:ii1 4}}} I'd like to iterate over the keys of the map in "absolute" form from the root as a vector. So I'd like: { [:o :i1] 1 [:o :i2 :ii1] 4 } As the result. Basically only get the leaf nodes. 回答1: A version that I think is rather nicer, using for instead of mapcat : (defn flatten-keys [m] (if (not (map? m)) {[] m} (into {} (for [[k v] m [ks v'] (flatten-keys v)] [(cons k ks) v'])))) The function is naturally recursive, and the most convenient base case for a non-map

Clojure syntax question re: #^

巧了我就是萌 提交于 2019-12-30 17:24:11
问题 in Rich Hickeys ant game, he has the following code: (import '(java.awt Color Graphics Dimension) '(java.awt.image BufferedImage) '(javax.swing JPanel JFrame)) (defn fill-cell [#^Graphics g x y c] (doto g (.setColor c) (.fillRect (* x scale) (* y scale) scale scale))) I can't find documentation anywhere for what #^ means in this context, any help appreciated. 回答1: The #^ is the old syntax for metadata reader macro. The syntax has changed to ^ in clojure 1.2. See http://clojure.org/reader. In