276 questions
3
votes
1
answer
63
views
Accessing the window from a menu item in Cljfx
How can I access the main window (:stage) from a menu click event in Cljfx? I need it for two reasons: to open a file chooser, and to resize the window.
A minimal example:
(ns a
(:require [cljfx.api ...
0
votes
1
answer
50
views
Cannot call a particular java method listed in clojure.reflect/reflect
I am having no luck calling advanceExact in various Lucene DocValues subclasses, for example:
user> (.advanceExact doc-values 1)
Execution error (IllegalArgumentException) at user/eval24512 (REPL:...
1
vote
1
answer
117
views
Creating Java Interface With Annotations, Immediately Usable in REPL
I am trying to do a few things at once with a Clojure macro but it's not working. I want to either learn how to fix it or understand why it is impossible.
I want to:
Create a Java interface in ...
0
votes
1
answer
95
views
How to use clj-kondo to get all java imports in a clojure file
I have use care where I have to process several clojure projects and find the imports of java libraries in each clojure namespace
I an invoking clj-kondo from my code for each .clj file as follows:
(...
1
vote
3
answers
80
views
Error while calling Java overloaded method Path.of from Clojure [duplicate]
I'm new to Clojure and learning. I'm trying to create a java Path object in Clojure using Path.of() method, but when I call this
(import '(java.nio.file Path))
(Path/of "~/projects")
I get ...
1
vote
1
answer
84
views
Host access to Clojure objects in GraalVM
The GraalJS documentation for host access states that its enough to add the annotation @HostAccess.Export
My code looks like this:
(ns graaljs.core
(:gen-class)
(:import (org.graalvm.polyglot ...
0
votes
2
answers
107
views
How to type hint a float?
I want to ensure I'm using unboxed and unreflected arithmetic on arrays of floats, but I can't get it to compile.
How can I type hint a float in a function like this?
(defn ff2a
^"[F" ; ...
2
votes
1
answer
198
views
How do I apply a PostgreSQL function to a query using Clojure?
(ns training-clj.querys
(:require [honey.sql :as honey]
[next.jdbc.sql :as jdbc]))
(defn get-by-username
[db username]
(let [query (honey/format {:select [:*]
...
1
vote
1
answer
95
views
ClassNotFoundException when the class is generated by gen-class macro in clojure
I've namespace myorg.helpers.fs-input-stream -Its definition is
(ns myorg.helpers.fs-input-stream)
(gen-class
:name "myorg.helpers.FsInputStream"
:extends java.io.ByteArrayInputStream
:...
1
vote
1
answer
351
views
How to select data from Google BigQuery in Clojure via Java interop?
I couldn't find any examples online. Can anyone point me to an example of how to select data from Google BigQuery in Clojure via Java interop?
[com.google.cloud/google-cloud-bigquery "2.16.0"...
1
vote
2
answers
115
views
Clojure is not generating a class
I created a new Clojure app with clojure -Tclj-new app :name myname/myapp and added the javafx deps to deps.edn
org.openjfx/javafx-controls {:mvn/version "17.0.2"}
org.openjfx/javafx-base {:...
3
votes
1
answer
380
views
how to run the clojure main from gradle application plugin
I've main clojure file -
(ns main.main
(:gen-class))
(defn -main
"I don't do a whole lot ... yet."
[& args]
(println "Hello, World!"))
I've build.gradle ...
0
votes
1
answer
195
views
Add object to a list in clojure and return
I am new to functional programming and have a use case where I have a list of Books, I want to iterate over it, do some mapping and return a new List.
My code
(defn map-book [books]
((doseq [x books]...
1
vote
0
answers
669
views
IncompatibleClassChangeError: class com.google.protobuf.Descriptors$OneofDescriptor Protobuf
I have been getting
at clojure.lang.Compiler.analyzeSeq(Compiler.java:7114)
at clojure.lang.Compiler.analyze(Compiler.java:6789)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:7094)
at ...
1
vote
1
answer
180
views
Problems calling a clojure function that takes a map as parameter from java
I'm using maven with several modules, one in java, another in clojure. I'm calling a clojure function from java and want to pass in a HashMap as a parameter and return a HashMap.
(I ran lein uberjar ...
1
vote
1
answer
1k
views
How to import local Java class at Clojure REPL?
There are existing answers to similar questions, but they tend to use Maven, which is not an option for my project. Also, I have not found any which give concrete examples of the syntax you use to ...
2
votes
1
answer
112
views
How to add a Java instance as context when using clojure as a scripting language?
I found the amazing question How can I use clojure as scripting language for a Java program? which helped tremendously, but I can't figure out how to get an existing Java instance into Clojure. The ...
-2
votes
2
answers
132
views
best performing dispatch on var value in clojure
In Clojure, it is not possible to use Case forms with Vars:
(case (resolve 'inc) #'inc 1)
Execution error (IllegalArgumentException) at user/eval2061 (REPL:1).
No matching clause: #'clojure.core/inc
...
0
votes
1
answer
139
views
How do I pass a class to new indirectly in clojure
I have a clojure class (a namespace with a (:gen-class) clause).
I then need to pass a constructed object to a java function.
this works
(java_function (my-clojure-class.))
However, if I need to ...
1
vote
0
answers
31
views
Invoke java method that accept variable args from clojure [duplicate]
I have code block in java where I am trying to add customCodecProvider for mongo
(use 'clojure.reflect 'clojure.pprint)
(pprint (reflect org.bson.codecs.configuration.CodecRegistries))
{
:bases #{...
0
votes
1
answer
123
views
convert list of strings to list of java type objects in clojure
I am using mongo java driver along with clojure for mongo connection, to establish connection in java I am using following code snippet
import com.mongodb.MongoClient;
import com.mongodb....
0
votes
0
answers
103
views
How do I prevent a ClassNotFoundException when calling Java interop from Clojure in a JNI-created thread?
I have a project that's using Clojure + JNI in order to access some operating-system specific APIs. The native code in this process runs some of its work on background threads, and when doing so ...
1
vote
0
answers
192
views
Deserialization of task fails only in test runner
I am encountering a deserialization issue that is only showing when I run my code via a test runner. Running an assembled uberjar (with AOT compilation) does not show this behavior and neither does ...
1
vote
1
answer
285
views
How to use .getObjectSize in Clojure?
In Clojure, what is the best way to determine the size of a map? Import java library "java.lang.instrument.Instrumentation" and use .getObjectSize. However, the library cannot be imported. ...
-1
votes
1
answer
1k
views
Could not locate proj/core.clj on classpath when calling clojure from java
I am trying to call some Clojure code from Java, but I get this error when trying to "require" the file:
Could not locate proj/core__init.class, proj/core.clj or proj/core.cljc on classpath.
...
1
vote
0
answers
86
views
clojure ubergraph compiling error - 'namespace 'ubergraph.core' not found
I have been using ubergraph last few weeks up until this morning, but now am having compiling problem.
In my project.clj's dependencies, ubergraph is declared:
(defproject graph-alg "0.1.0-...
0
votes
1
answer
145
views
Binding Resize event to Clojurescript using Jayq
I am trying to create a simple clojurescript which'll display the width of the browser window.
My app.cljs look like the following:
(ns acme.frontend.app
(:use [jayq.core :only [$]])
(:require-macros [...
0
votes
0
answers
53
views
Package Clojure and Java(springboot) source codes into a JAR file with leiningen
Package Clojure and Java(springboot) source codes into a JAR file with leiningen
i run lein uberjar ,
so it happen
enter image description here
2
votes
0
answers
258
views
How to call clojure code from uberjar in android app
I am working on an Android app which makes use of Clojure for carrying out some of the computation in the backend. However, I am unable to figure out a way to invoke my Clojure methods in Android.
My ...
1
vote
1
answer
243
views
Clojure json comparing [closed]
In some of my testing I am comparing json result between some http calls, today I am just comparing strings, which is too naive and not reliable for example if order changes.
Can you please recommend ...
0
votes
3
answers
178
views
clojure function call hides type information
I have a small function used for debugging:
(set! *warn-on-reflection* true)
(defn debug [x] (doto x (->> println :>)))
When I call my function in a loop, I get the following reflection ...
7
votes
2
answers
734
views
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 {}))
...
2
votes
2
answers
2k
views
Problems while creating a deps.edn file
People, I decided to rewrite this post entirely to show it in a clear way.
First of all, thanks for all the support. I appreciate that.
This is the exercise in "The Clojure Workshop - Packt" ...
2
votes
2
answers
541
views
Package Clojure and Java source codes into a JAR file with Maven
I want to use Clojure code in my Java application:
; clj.clj
(ns utils
(:gen-class
:name clj.Clj
:methods [#^{:static true} [clj [] String]])
(defn -clj []
"Hello from Clojure!")...
2
votes
1
answer
113
views
How smart is Clojure with regexp parsing/compiling?
Imagine, I've a Clojure function similar to that one
(defn ABC
[tag v]
(let [value (->> (str/split v #",")
(map str/trim)
(map u/capitalize)
...
3
votes
2
answers
919
views
convert Java objects to Clojure types
Hi Currently I am using java.data (https://github.com/clojure/java.data) to convert java pojos to clojure compatible types.
It does not work for nested objects.
For ex:
class Abc {
Map<String, ...
1
vote
1
answer
264
views
create clojure proxy of abstract java class with overloaded same-arity method
is it possible to proxy a class like this and override both methods?
public abstract class C {
...
public abstract void m(String a);
public void m(Integer a) {}
}
this doesn't work:
(proxy [C] [...
6
votes
1
answer
3k
views
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 ...
1
vote
3
answers
1k
views
How can I record time for function call in clojure
I am newbie to Clojure. I am invoking Clojure function using java and I want to record the time a particular line of clojure code execution takes:
Suppose if my clojure function is:
(defn ...
1
vote
1
answer
692
views
Calling Clojure from Java: Why is the "new" style (clojure.java.api.Clojure) better than the "old" one (gen-class)?
Something is puzzling me after reading the this great answer to a related question:
There are two possibilities to share a function that I wrote in Clojure with Java developers
The first one is ...
1
vote
2
answers
176
views
Passing a 2D array of Integers into Java from Clojure
In my Java library I have a function
void f(Integer[][] grid) {
and I want to call it from Clojure
(f (to-array-2d
[[1 0 0 0 1 0 0 0 1 0 1 0 1 0 0 1]
[0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0]...
1
vote
2
answers
388
views
Clojure: call java static method/field via instance variable or string (not class name symbol)
I can do the following and it works...
=> (. java.awt.event.KeyEvent getKeyText 10)
"Enter"
But, I have an instance of java.awt.event.KeyEvent called ev. For example,
=> (class ev)
java.awt....
0
votes
1
answer
106
views
Multiple Clojure instances from Java?
I'm trying to create a scripting language that compiles to Clojure, to then run it on the JVM. Each individual script, in the same JVM instance, but in an isolated manner.
Yet, when I see the ...
0
votes
1
answer
102
views
Is it possible to create writeable bean from Clojure that I can manage from jconsole?
I was exploring Clojure java.jmx API Reference and trying the examples mentioned there e.g.
;; Can I serve my own beans? Sure, just drop a Clojure ref
;; into an instance of clojure.java.jmx.Bean, ...
3
votes
1
answer
754
views
Dealing with Java Optional<T> in clojure
I am writing Clojure code interacting with external Java library. One of the method returns Java Optional object. Let's assume that it returns Optional<String> and I need to change the string ...
0
votes
1
answer
482
views
How do you append environment variables to a java clojure cli?
I have files which are created via clojure
frontendapp.jar
backendapp.jar
and take an environment variable, APP_PORT
What I want to understand is how do I pass variables to the jar files so that ...
2
votes
1
answer
182
views
Using imported Java libs in Clojure REPL
Twilio docs for Java lib
MVN for this lib
I'm trying to use Twilio from Clojure. Pretty new to Clojure dev, so I'm trying to get to grips with importing libs, in general.
My project.clj looks ...
1
vote
0
answers
290
views
How do I properly import the Twilio Java library in Clojure?
Twilio docs for Java lib
MVN for this lib
I'm trying to use Twilio from Clojure. Pretty new to Clojure dev, so I'm trying to get to grips with importing libs, in general.
My project.clj:
(...
1
vote
0
answers
168
views
Trouble building clara rules dynamically using instaparse
I followed this example Insta Declarative DSL where we use Clara with instaparse to use a DSL and generate rules.
everything works for me as expected but one issue. I am not able to access the ...
0
votes
1
answer
454
views
How to print EDN output in JSON format using Cheshire custom encoder
I am newbie with Clojure and I am trying to print EDN output to valid JSON format using Cheshire custom encoder for classes defined in java.
My EDN file:
{:xyz #XyzBuilder "testString"}
Clojure code:
...