clojure-java-interop

Is it possible to use Clojure's case form with a Java enum?

五迷三道 提交于 2019-12-05 02:55:31
The case doc says Unlike cond and condp, case does a constant-time dispatch... All manner of constant expressions are acceptable in case. I would like to benefit from case 's constant-time dispatch to match on Java enums. Java's switch statement works well with enums, but doing the following in Clojure: (defn foo [x] (case x java.util.concurrent.TimeUnit/MILLISECONDS "yes!")) (foo java.util.concurrent.TimeUnit/MILLISECONDS) Results in: IllegalArgumentException No matching clause: MILLISECONDS Are enums not supported in case ? Am I doing something wrong? Must I resort to cond or is there a

Clojure Leining REPL OutOfMemoryError Java heap space

孤人 提交于 2019-12-04 07:18:49
I am trying to parse a fairly small (< 100MB) xml file with: (require '[clojure.data.xml :as xml] '[clojure.java.io :as io]) (xml/parse (io/reader "data/small-sample.xml")) and I am getting an error: OutOfMemoryError Java heap space clojure.lang.Numbers.byte_array (Numbers.java:1216) clojure.tools.nrepl.bencode/read-bytes (bencode.clj:101) clojure.tools.nrepl.bencode/read-netstring* (bencode.clj:153) clojure.tools.nrepl.bencode/read-token (bencode.clj:244) clojure.tools.nrepl.bencode/read-bencode (bencode.clj:254) clojure.tools.nrepl.bencode/token-seq/fn--3178 (bencode.clj:295) clojure.core

How do you configure proprietary dependencies for Leiningen?

浪子不回头ぞ 提交于 2019-12-03 15:39:09
We're working on a project that has some Clojure-Java interop. At this point we have a single class that has a variety of dependencies which we put into a user library in Eclipse for development, but of course that doesn't help when using Leiningen (2.x). Most of our dependencies are proprietary, so they aren't on a repository somewhere. What is the easiest/right way to do this? I've seen leiningen - how to add dependencies for local jars? , but it appears to be out of date? Update: So I made a local maven repository for my jar following these instructions and the lein deployment docs on

shutdown hook doesn't fire when running with “lein run”

两盒软妹~` 提交于 2019-12-03 06:03:49
I have the following code: (ns test-hook.core) (defn -main [] (.addShutdownHook (Runtime/getRuntime) (Thread. #(println "shutdown"))) (println "start") (doseq [i (range 1 6)] (Thread/sleep 1000) (println i))) and the following project.clj (defproject test-hook "1.0.0-SNAPSHOT" :aot :all :main test-hook.core :description "FIXME: write description" :dependencies [[org.clojure/clojure "1.2.0"]]) when I run it with "lein run" the shutdown hook only gets executed on normal program execution, not when receiving SIGINT (Ctrl-C) the same code when ran outside of lein successfully executes the shutdown

clojure access enum defined inside a java class

耗尽温柔 提交于 2019-12-02 11:45:23
I am trying to use the argon-jvm library for hashing in my application. By default this library uses Argon2i , However, I would like to use Argon2id . To do so, I need to pass the enum value Argon2Factory.Argon2Types.Argon2id to the overloaded create method in the Argon2Factory class. Source code for Argon2Factory.java here . From the lein repl (affter adding [de.mkammerer/argon2-jvm "2.4"] as a dependency), I can do the following: user=> (import 'de.mkammerer.argon2.Argon2Factory) de.mkammerer.argon2.Argon2Factory user=> (def argon2 (Argon2Factory/create)) #'user/argon2 user=> (def

Clojure: working with a java.util.HashMap in an idiomatic Clojure fashion

淺唱寂寞╮ 提交于 2019-11-28 20:20:01
I have a java.util.HashMap object m (a return value from a call to Java code) and I'd like to get a new map with an additional key-value pair. If m were a Clojure map, I could use: (assoc m "key" "value") But trying that on a HashMap gives: java.lang.ClassCastException: java.util.HashMap cannot be cast to clojure.lang.Associative No luck with seq either: (assoc (seq m) "key" "value") java.lang.ClassCastException: clojure.lang.IteratorSeq cannot be cast to clojure.lang.Associative The only way I managed to do it was to use HashMap 's own put , but that returns void so I have to explicitly

Why does Clojure have 5 ways to define a class instead of just one?

随声附和 提交于 2019-11-28 13:45:50
问题 Clojure has gen-class, reify, proxy and also deftype and defrecord to define new class-like datatypes. For a language that values syntactic simplicity and abhors unnecessary complexity, it seems like an aberration. Could someone explain why it is so? Could Common Lisp-style defclass have sufficed? 回答1: This is a mix of three different factors: The particular type system of the jvm The need for slightly different semantics for different use cases when defining types The fact that some of these

Java and Clojure with Leiningen

匆匆过客 提交于 2019-11-27 17:58:57
Is it possible to easily manage and compile native Java classes alongside Clojure in a project using leiningen? I am working at a pretty low level (with netty nio) and thinking that some of the plumbing classes would actually be easier to handle as raw java both in terms of constructing the code as well as performance. Alex Ott In Leiningen tutorial there is following statement For projects that include some Java code, you can set the :java-source-path key in project.clj to a directory containing Java files. Then the javac compiler will run before your Clojure code is AOT-compiled, or you can

Clojure: working with a java.util.HashMap in an idiomatic Clojure fashion

强颜欢笑 提交于 2019-11-27 12:51:19
问题 I have a java.util.HashMap object m (a return value from a call to Java code) and I'd like to get a new map with an additional key-value pair. If m were a Clojure map, I could use: (assoc m "key" "value") But trying that on a HashMap gives: java.lang.ClassCastException: java.util.HashMap cannot be cast to clojure.lang.Associative No luck with seq either: (assoc (seq m) "key" "value") java.lang.ClassCastException: clojure.lang.IteratorSeq cannot be cast to clojure.lang.Associative The only way

Java and Clojure with Leiningen

吃可爱长大的小学妹 提交于 2019-11-27 04:15:28
问题 Is it possible to easily manage and compile native Java classes alongside Clojure in a project using leiningen? I am working at a pretty low level (with netty nio) and thinking that some of the plumbing classes would actually be easier to handle as raw java both in terms of constructing the code as well as performance. 回答1: In Leiningen tutorial there is following statement For projects that include some Java code, you can set the :java-source-path key in project.clj to a directory containing