Questions tagged [clojure-java-interop]

For topics related to interoperability between Clojure and Java

Programs written in Java and in Clojure run on the JVM and can therefore call each other. Use this tag to mark questions related to this interoperability.

269 questions
9
votes
1 answer

Calling clojure code from a scala sbt task

I am trying to call some clojure code as a sbt task. My build.sbt looks like, lazy val aTask = taskKey[Unit]("a task") libraryDependencies ++= Seq( "org.clojure" % "clojure" % "1.9.0" ) import clojure.java.api.Clojure import…
shakdwipeea
  • 775
  • 2
  • 7
  • 14
9
votes
1 answer

Clojure's dot special form weirdness

I'm curious why this works (as I would expect it to after reading the documentation on the dot special form): (map #(. % isInstance {}) [clojure.lang.IPersistentMap]) returns: (true) But this does not: (. clojure.lang.IPersistentMap isInstance…
at.
  • 50,922
  • 104
  • 292
  • 461
9
votes
2 answers

How to read all lines from stdin in Clojure

I'm writing a Brainf*** interpreter in Clojure. I want to pass a program in using stdin. However, I still need to read from stdin later for user input. Currently, I'm doing this: $ cat sample_programs/hello_world.bf | lein trampoline run My Clojure…
Wilfred Hughes
  • 29,846
  • 15
  • 139
  • 192
8
votes
2 answers

clojure gen-class varargs constructor

in the :constructors map and subsequent -init definitions, how do I represent a varargs constructor (assuming the superclass has multiple constructors of which one is varargs) ?
Hendekagon
  • 4,565
  • 2
  • 28
  • 43
8
votes
2 answers

How does Clojure's laziness interact with calls to Java/impure code?

We stumbled upon an issue in our code today, and couldn't answer this Clojure question: Does Clojure evaluate impure code (or calls to Java code) strictly or lazily? It seems that side-effects + lazy sequences can lead to strange behavior. Here's…
8
votes
2 answers

How do I tag a Clojure function so that I could recognize it with Java reflection

I need to somehow tag certain Clojure functions as "special" so that Java code could recognize them as such using reflection. I've tried to add an annotation to a function, but apparently that's not supported. I've tried to reify an interface…
pron
  • 1,693
  • 18
  • 28
8
votes
3 answers

Make a Java class work as a sequence in Clojure

I am using a Java class that represents a sequence of results (somewhat like a Clojure vector). I would like to use this class with the typical Clojure sequence functions (i.e. I want to have the class behave as if it supported the sequence…
mikera
  • 105,238
  • 25
  • 256
  • 415
7
votes
2 answers

How can I add a typehint in clojure to fix "ctor can't be resolved" reflection warning, i.e call to a constructor?

The following example function, which uses Clojure's special form for java interop to call a class constructor, causes a reflection warning: (defn test-reflection-err [] (new java.util.HashMap {})) That message reads: Reflection warning,…
fraxture
  • 5,113
  • 4
  • 43
  • 83
7
votes
1 answer

How to create multiple Java member variables with Clojure's gen-class

This answer to a very old question about Clojure-Java interop explains how to use gen-class with the :state and :init keywords to create a single public instance variable accessible from Java. This is enough if you only need one piece of data to be…
Mars
  • 8,689
  • 2
  • 42
  • 70
6
votes
1 answer

How to include Clojure dependencies to a Java project with Maven

I'm very new to all things JVM and want to start a Java project that involves a Clojure library as a dependency. I've seen this question on how to run Clojure code from Java, but when I try to run the jar file after mvn package, I get cannot find…
Alex Eftimiades
  • 2,527
  • 3
  • 24
  • 33
6
votes
1 answer

Cannot use class from another namespace in ns :gen-class

I have a defrecord called ConstraintLookup in sre.plan.dsl.constraint namespace. I want to use its generated class in a gen-class method placed on the sre.plan.compiler namespace: (ns sre.plan.compiler (:require [sre.plan.dsl.constraint :as…
Midiparse
  • 4,701
  • 7
  • 28
  • 48
6
votes
2 answers

leiningen: ClassNotFoundException for class present in project on “lein run” / “lein uberjar”

I am trying to implement a Java interface that is required by a legacy runtime I am using and instantiate an instance of this implementation to pass it to the runtime. But when I run lein uberjar I see an exception, that the class cannot be found.…
Matthias Wimmer
  • 3,789
  • 2
  • 22
  • 41
6
votes
1 answer

Risks of volatile-mutable fields in single-threaded contexts?

Is it safe to use the :volatile-mutable qualifier with deftype in a single-threaded program? This is a follow up to this question, this one, and this one. (It's a Clojure question, but I added the "Java" tag because Java programmers are likely to…
Mars
  • 8,689
  • 2
  • 42
  • 70
6
votes
1 answer

Clojure reify a Java interface with overloaded methods

I'm trying to implement the following Java interface in Clojure: package quickfix; public interface MessageFactory { Message create(String beginString, String msgType); Group create(String beginString, String msgType, int…
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
5
votes
1 answer

Improve performance of point cloud bounding box computation in Clojure

I am computing the bounding box of a 3d point cloud in Clojure. The point cloud is represented as a Java primitive float array, and every point in the point cloud is stored using 4 floats where the last float is unused. Like this: [x0 y0 z0 u0 x1…
Rulle
  • 4,496
  • 1
  • 15
  • 21
1
2
3
17 18