clojure

Equivalent of 'lein swank' to other Lisp/Scheme implementations with emacs/slime

别等时光非礼了梦想. 提交于 2020-01-02 05:42:06
问题 I've been using emacs/slime for coding lisp, but with Clojure I found 'lein swank'. I must say that it's pretty useful, as I can connect to a server that runs clojure. How about the other Lisp implementations? What Lisp implementations provide the equivalent of 'lein swank' in Clojure? I mean, is there any other Lisp implementations that provide server connectivity so that I use 'M-x slime-connect', not just 'M-x slime'? 回答1: Non-clojure swank backends don't need a lein swank equivalent since

Mocking Clojure protocols

落花浮王杯 提交于 2020-01-02 04:39:19
问题 Can one of the popular Java mocking frameworks like EasyMock or Mockito be used to mock Clojure protocols defined with defprotocol ? If so, how? 回答1: You should be able to mock protocols using any mock library. Under the covers, every protocol uses a Java interface as an implementation detail, and you could just mock that interface. That said, don't do this! Mocking in Java is absurdly complex because of reflection, protection levels, final classes, etc. Any time you want a Clojure object

Simplest possible Clojure object that can accept a primitive and metadata?

我的梦境 提交于 2020-01-02 04:13:06
问题 I want to add metadata to a byte array in Clojure. Since this is not allowed, one option I want to try is the simplest object wrapper that could work. Here is the source code for with-meta. That made me start looking at Clojure.lang.IObj . I haven't found what I want yet. 回答1: Here's how you can create a deftype that supports metadata. (import '(java.io Writer)) (deftype Box [value _meta] clojure.lang.IObj (meta [_] _meta) (withMeta [_ m] (Box. value m)) clojure.lang.IDeref (deref [_] value)

Sandwiching Clojure between Java with Leiningen

二次信任 提交于 2020-01-02 04:12:08
问题 For a class, I need to write some JVM code, and I'm hoping to use Clojure. I got it to work with the bottom part of the software stack, but I can't manage to make it work in between the GUI layer sitting on top and the bottom part. My main problem is getting the Java GUI to recognize my Clojure files. I want to use Leiningen for this, but the Java compiling solution doesn't seem to account for this interoperation. The answer here seems to be exactly what I need. I don't understand where to

Why is line-seq returning clojure.lang.Cons instead of clojure.lang.LazySeq?

谁说我不能喝 提交于 2020-01-02 03:31:08
问题 According to the ClojureDocs entry for line-seq (http://clojuredocs.org/clojure_core/clojure.core/line-seq) and the accepted answer for the Stack question (In Clojure 1.3, How to read and write a file), line-seq should return a lazy seq when passed a java.io.BufferedReader. However when I test this in the REPL, the type is listed as clojure.lang.Cons. See the code below: => (ns stack-question (:require [clojure.java.io :as io])) nil => (type (line-seq (io/reader "test-file.txt"))) clojure

In Clojure, how to get the name string from a variable or function?

ε祈祈猫儿з 提交于 2020-01-02 02:37:15
问题 I wanna get the string representation of a variable. For example, (def my-var {}) How to get the string "my-var" from symbol my-var ? And (defn my-fun [] ...) How to get the string "my-fun" from function my-fun ? 回答1: user=> (def my-var {}) #'user/my-var user=> (defn my-fun [] ) #'user/my-fun user=> (name 'my-var) "my-var" user=> (name 'my-fun) "my-fun" user=> (doc name) ------------------------- clojure.core/name ([x]) Returns the name String of a string, symbol or keyword. nil 回答2: Every

Does hinting return types in protocols have any effect within Clojure?

假装没事ソ 提交于 2020-01-02 02:35:08
问题 You can hint a return type in a protocol (defprotocol Individual (^Integer age [this])) and the compiler will make your methods comply: (defrecord person [] Individual (^String age [this] "one")) ; CompilerException java.lang.IllegalArgumentException: Mismatched return type: age, expected: java.lang.Object, had: java.lang.String, ... But you don't have to honour the type-hint: (defrecord person [] Individual (age [this] "one")) (age (new person)) ; "one" Does the type-hint have any effect?

Clojure / Noir: Force HTTPS, redirect if the request was http:// to https://

我怕爱的太早我们不能终老 提交于 2020-01-02 02:19:28
问题 I'm trying to force SSL on my site. I want to have a ring style middle-ware to redirect the site to the same URL with https if it is only http I wrote the following code but it doesn't really do anything besides check the request scheme and print the URL it should be redirecting to. (defn https-url [request-url] (str (str (str (str "https://" (:server-name request-url) ":") (:server-port request-url))) (:uri request-url))) (defn require-https [handler] (fn [request] (let [page-request

Difference between read-string and load-string in Clojure

放肆的年华 提交于 2020-01-02 01:15:10
问题 I have some code which works after replacing read-string with load-string. It is good that the code works, but I would like to know why. What is the difference between the two clojure functions? 回答1: Use load-string to sequentially read and evaluate the set of forms contained in the string Use read-string to read one object from the string s (both quoted from Clojure API) Load-string will evaluate your string as a Clojure expression, and read-string takes the string and returns it as the

How to print each item of list in separate line clojure?

丶灬走出姿态 提交于 2020-01-02 01:10:22
问题 I'm very new in clojure. I want to print each item of list in newline. I'm trying like this: user=> (def my-list '(1 2 3 4 5 )) ;; #'user/my-list user=> my-list ;; (1 2 3 4 5) user=> (apply println my-list) ;; 1 2 3 4 5 ;; nil But I want my output must be: 1 2 3 4 5 nil can anyone tell me, How can I do this? Thanks. 回答1: This kind of use case (perform a side effect once for each member of a sequence) is the purpose of doseq. Using it here would be like (doseq [item my-list] (println item))