This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-15
Channels
- # announcements (3)
- # architecture (1)
- # babashka (52)
- # beginners (228)
- # calva (1)
- # chlorine-clover (31)
- # cider (9)
- # clj-kondo (16)
- # cljs-dev (25)
- # cljsrn (21)
- # clojure (116)
- # clojure-argentina (8)
- # clojure-europe (18)
- # clojure-france (17)
- # clojure-germany (1)
- # clojure-nl (5)
- # clojure-spec (49)
- # clojure-uk (63)
- # clojurescript (59)
- # community-development (14)
- # conjure (89)
- # core-matrix (1)
- # cursive (18)
- # data-science (1)
- # datomic (27)
- # exercism (4)
- # figwheel-main (5)
- # fulcro (38)
- # ghostwheel (8)
- # graalvm (5)
- # hoplon (2)
- # jobs-discuss (17)
- # juxt (1)
- # lambdaisland (5)
- # luminus (1)
- # lumo (9)
- # malli (7)
- # off-topic (32)
- # planck (24)
- # re-frame (14)
- # reagent (14)
- # reitit (14)
- # rum (23)
- # shadow-cljs (80)
- # spacemacs (2)
- # sql (6)
- # unrepl (1)
- # xtdb (2)
Can I build Java source code with tools.deps? That is, I have some .java
files in my deps.edn project, and I'd like to build them so the clj code can access them.
But you can do it with lein: https://github.com/technomancy/leiningen/blob/master/doc/MIXED_PROJECTS.md
A shame... Thanks for the link though! I am in fact migrating a lein project to tools.deps, but since it's a clj/java mixed project I think I'm out of luck 😔
Ya, in theory someone could build a tools.deps based alias that can compile Java source. Tools.deps itself is not a build tool, it only handles dependency management. But with aliases, people have built build tasks as small Clojure programs that you can call with an alias and which automatically get access to your project's classpath
So all "build" tasks available to tools deps today are unofficial and community provided.
I'm fact, you can even use lein with tools.deps, where tools.deps provides lein with the dependencies instead of having lein manage them, and lein is thusnused for build tasks
I tried the lein plugin for tools.deps, but it didn't work for me with local deps, so I gave up. I'll give it another go though!
You can compile .java with javac and add compiled .class files as :paths [… "java_sources"]
into deps.edn
But is there a way I can provide javac
with the right classpath? Or do I need a separate infrastructure to resolve the dependencies and invoke javac with the right arguments?
clj -Spath
is printing out class-path
I have never used it, but this tool claims to support compiling Java sources in a project using deps.edn: https://github.com/EwenG/badigeon
i like badigeon -- but there are also other options among the following list iiuc: https://github.com/clojure/tools.deps.alpha/wiki/Tools#packaging
We are working on a new tools.build that will do this as well
@dpsutton I created my own cljc file called myapp.env in my cljc directory, in which I imported (:require [myapp.config :refer [env]], but I get the error: The required namespace "myapp.config" is not available, it was required by "myapp/env.cljc". "myapp/config.clj" was found on the classpath. Should this be a .cljs file?
I always feel circleci be a show-muscle of clojure in real world. however, yesterday I stumbled upon this post from the founder of circleci, who claims it will never use clojure, https://news.ycombinator.com/item?id=20789359 . thoughts?
The co-founder and ex cto of circleci just started a new project with clojure (griffin bank), I guess "your mileage may vary" applies here.
"my previous startup" doesn't imply they're the founder of circleci?
Paul Biggar is a founder of CircleCI now at darklang, and this person's account name is pbiggar
then using OCaml for backend services is being brave. Be ready to reinvent a lof wheels, the ecosystem is not big
yeh that's what I was thinking, although not from experience as much as that's the impression I get everytime I look into trying anything with OCaml
it's #off-topic stuff, but lack of decent multicore support, most db drivers are not up to date or seriously lacking, conflicting async or even Core libs/lingo, poor tooling etc etc
Very confused about this
(defprotocol TestProto (test-method [a]))
(extend-protocol TestProto
allpa.test_rec.Test
(test-method [_] 42))
(deftest core-api
(testing "..."
(let [obj1 (allpa.test_rec.Test.)
obj2 (allpa.test-rec/->Test)]
(is (= (test-method obj1) 42))
(is (= (test-method obj2) 42)))))
The test using obj1
passes fine but the one with obj2
fails with
actual: java.lang.IllegalArgumentException: No implementation of method: :test-method of protocol: #'allpa.test-core/TestProto found for class: allpa.test_rec.Test
am I missing something?the record definition is in a different namespace
works fine if the record is defined in the same namespace as the test. is this a limitation of records/protocols?
no, that's correct - first is a Java class name, second is a Clojure namespace
you need underscores for the java class name. My namespace looks like this which I think should be fine
(ns allpa.test-core
(:require
#?(:clj [clojure.test :refer :all]
:cljs [cljs.test :refer-macros [is are deftest testing use-fixtures]])
[allpa.test-rec :as tr])
(:import allpa.test_rec.Test))
this looks right to me, and should be fine. just to check - are you sure you have a clean repl state?
there are some situations you can get into where the protocol was extended to an old version of the record class, but you've recompiled the record class and have an instance of a new record class (even though their names are the same)
Don't have a repl open. just running lein test
I tried rerunning after a lein clean
to be sure but no luck
are you doing aot?
Not that I know of. I haven't changed anything in project.clj
from the https://github.com/dryewo/clojure-library-template template.
Not a huge deal because I believe this is working correctly in the application I'm writing that uses the library I'm writing. Just preventing me from writing unit tests for one of my macros but would be nice to understand what is happening
I tried what you listed and it worked for me
strange... ty for trying. maybe something fishy w/ my clojure/lein version
nothing has changed in this regard in either for a long time, so not sure what that would be. I'm not using leiningen though to test
I can repro it with leiningen though
it's something to do with the order lein test is loading code - I see the allpa.test-rec namespace get loaded twice, which makes it likely this is the scenario I described above
and if I move allpa.test-rec from test/ to src/, it works
cool ty! I'll get a bit cleaner repro and file a bug with leinengen. I'd guess it has to do with how leinengen sets the main namespace because I didn't have this issue when the same type of code is deep in the application instead of in the entry point of the test
interesting
thats plenty enough for me to get my unit test working ty!
I think lein test will gather all the files in test and load them - it's probably loading the test-core, which loads test-rec transitively, then it loads test-rec, then it runs test-core
makes sense
$ lein test
loading allpa.test-rec
loading allpa.test-core
loading allpa.test-rec
lein test allpa.test-core
lein test :only allpa.test-core/core-api
ERROR in (core-api) (core_deftype.clj:583)
...
expected: (= (test-method obj2) 42)
actual: java.lang.IllegalArgumentException: No implementation of method: :test-method of protocol: #'allpa.test-core/TestPro
adding printlns to the namespaces makes that clearer
ah nice! Ill keep that in mind for future debugging
What do you recommend to study when a intermediate level in Clojure is reached ?
Not yet. But I know this book and it is on my read plans.
That's what I like about Clojure Reading a book that's 9 yrs old and still makes sense 🙂 Which is rather rare these days. Technology become obsolete so fast.

1. Study (day by day) the Clojure Standard library book with many good examples: https://www.manning.com/books/clojure-the-essential-reference 2. Learn Clojure code from well known open source projects. 3. Make something practical using Clojure: your own pet project or full-time job
I read the 12th chapter "Java.next" from The Joy of Clojure yesterday. Mind blown. It shows some pretty advanced techniques and goes on to explain the "why", not just the "how". If the whole book is like this, then it is a must read.
Thank you guys! These advices were very good to me!
@U0113AVHL2W Which book did you mention, e.g ?
@U010H5U6SEM I was referring to the same book that @U0CJ19XAM mentioned. "The joy of clojure". It was released in 2011.

The 2nd Edition came out in 2014.
(and, yes, it's a great book once you have the basics down)
I'd also recommend Clojure Applied as a "next level" book (although it relies more heavily on records than its authors would now if they did a new edition).
Very cool guys! Thank you!
@U04V70XH6 Do you recommend this book after reading the "The Joy of Clojure" ?
@U010H5U6SEM Yes, I think Clojure Applied would be a good choice to read after Joy of Clojure. Other books to consider: Programming Clojure 3rd Ed (although it starts from beginner level, it's a very thorough coverage of intermediate+ stuff too), The Clojure Cookbook (some of the examples might be a bit dated but it has a lot of practical, real world Clojure usage, showcasing a number of popular libraries).
Oh, I knew "The Clojure Cookbook" last week and I'm very interested
Thanks for the recommendations!
I was also really surprised how much still-valid intermediate stuff was in the O’Reilly “Clojure Programming” book from Chas Emerick, Brian Carper, Christophe Grand (2012).
particularly if like me you’re a Java newb; I’m coming in from JS/CLJS. The stuff around avoiding object boxing for performance was :male-cook:😘
Yeah, I like that book. It was one of the first three Clojure books I bought: Joy of Clojure (1st Ed), Clojure in Action (outdated, even at the time it was published!), Clojure Programming.
I tend not to recommend it now, just because I sort of assume it might have become outdated... but I guess not. We have so many newer books tho'.
True. I think it’s the most Java-exposing, which was very good for me when I read it, since I have somehow missed using Java my entire career
(Fun story: I read Fogus’s “Functional Javascript” and thought huh, wonder if he’s written anything else, and bought Joy Of as my first clj book 😬).

How do I get each line to count as a seperate match here? Am I misunderstanding "multiline mode:?
(def s
"A 1
A 2
A 3")
(re-seq #"(?m)^A.+$" s)
;;=> ("A 1 A 2 A 3")
and this is clojure:
user=> (def s "A 1\r\nA 2\n\rA 3")
#'user/s
user=> (re-seq #"(?m)^A.+$" s)
("A 1" "A 2" "A 3")
I have a customization to inf-clojure Emacs Lisp code that does not eliminate newlines in the strings sent to REPL.
Default inf-clojure behavior for some of the key bindings to send expressions to REPL is to eliminate newlines.
You can search for occurrences of 'inf-clojure' in this Emacs Lisp file I wrote and have in a public Github repo -- those are Emacs Lisp functions I wrote that are small modifications of the built-in ones, that work the way I prefer: https://github.com/jafingerhut/dotfiles/blob/master/link/.emacs.d/lisp/fn-key-bindings.el
When using definterface
, do I have to use import
function instead of the (ns (:import ...))
form?
I have this,
(ns com.github.hindol.clj-fn.core
(:require
[clj-java-decompiler.core :as cjd])
(:import
(com.microsoft.azure.functions HttpRequestMessage
HttpResponseMessage)))
(definterface Functional
(run [^com.microsoft.azure.functions.HttpRequestMessage request]))
Note that in the interface I had to fully quality the HttpRequestMessage.If I don't fully qualify, that resolves to java.lang.HttpRequestMessage
. Don't know why.
Like this?
(definterface Functional
(run [(with-meta 'request {:tag HttpRequestMessage})]))
Okay, I hunted down the actual thing. HttpRequestMessage
is an interface. Does that change anything?
https://github.com/Azure/azure-functions-java-library/blob/dev/src/main/java/com/microsoft/azure/functions/HttpRequestMessage.java