Fork me on GitHub
#clojure
<
2020-04-15
>
Spaceman00:04:50

which cljc file are you referring to?

Spaceman00:04:34

There don't seem to be any cljc files in src

dpsutton00:04:06

One you write yourswlf

Setzer2207:04:30

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.

didibus08:04:51

No you can't do that

Setzer2208:04:46

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 😔

didibus08:04:43

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

didibus08:04:28

So all "build" tasks available to tools deps today are unofficial and community provided.

didibus08:04:13

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

Setzer2208:04:26

To be fair, I'd be more than happy with a community solution to this problem... 😅

Setzer2208:04:00

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!

delaguardo08:04:53

You can compile .java with javac and add compiled .class files as :paths [… "java_sources"] into deps.edn

Setzer2208:04:41

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?

delaguardo08:04:43

clj -Spath is printing out class-path

Setzer2208:04:33

I see.. thanks!

andy.fingerhut10:04:04

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

sogaiu10:04:26

i like badigeon -- but there are also other options among the following list iiuc: https://github.com/clojure/tools.deps.alpha/wiki/Tools#packaging

Alex Miller (Clojure team)11:04:52

We are working on a new tools.build that will do this as well

sogaiu11:04:57

sounds exciting 🙂

Setzer2210:04:42

Thanks all for the answers! 😄

Spaceman10:04:18

@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?

pinkfrog11:04:30

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?

4
mpenet11:04:12

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.

myguidingstar11:04:16

"my previous startup" doesn't imply they're the founder of circleci?

Cameron11:04:56

who said that's how they figured out who authored that

Cameron11:04:57

Paul Biggar is a founder of CircleCI now at darklang, and this person's account name is pbiggar

👍 4
mpenet11:04:46

then using OCaml for backend services is being brave. Be ready to reinvent a lof wheels, the ecosystem is not big

mpenet11:04:06

I love the language, but that's it

Cameron11:04:12

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

mpenet11:04:22

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

mpenet11:04:29

the list goes on

mpenet11:04:46

(my experience is from a couple of years ago, but I doubt a revolution happened)

Mitch Dzugan13:04:03

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?

Mitch Dzugan13:04:12

the record definition is in a different namespace

Mitch Dzugan13:04:53

works fine if the record is defined in the same namespace as the test. is this a limitation of records/protocols?

j13:04:15

is record namespace required properly ?

hindol13:04:13

One is test-rec, another is test_rec. Typo?

Alex Miller (Clojure team)13:04:00

no, that's correct - first is a Java class name, second is a Clojure namespace

Mitch Dzugan13:04:18

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))

Alex Miller (Clojure team)13:04:01

this looks right to me, and should be fine. just to check - are you sure you have a clean repl state?

Alex Miller (Clojure team)13:04:38

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)

Mitch Dzugan13:04:10

Don't have a repl open. just running lein test I tried rerunning after a lein clean to be sure but no luck

Mitch Dzugan13:04:50

Not that I know of. I haven't changed anything in project.clj from the https://github.com/dryewo/clojure-library-template template.

Mitch Dzugan13:04:33

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

Alex Miller (Clojure team)13:04:47

I tried what you listed and it worked for me

Mitch Dzugan13:04:23

strange... ty for trying. maybe something fishy w/ my clojure/lein version

Alex Miller (Clojure team)13:04:33

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

Alex Miller (Clojure team)13:04:39

I can repro it with leiningen though

Alex Miller (Clojure team)13:04:13

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

Alex Miller (Clojure team)13:04:34

and if I move allpa.test-rec from test/ to src/, it works

Mitch Dzugan13:04:37

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

Mitch Dzugan13:04:02

thats plenty enough for me to get my unit test working ty!

Alex Miller (Clojure team)13:04:23

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

Alex Miller (Clojure team)13:04:04

$ 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

Alex Miller (Clojure team)13:04:27

adding printlns to the namespaces makes that clearer

Mitch Dzugan13:04:53

ah nice! Ill keep that in mind for future debugging

Breno Duque Estrada17:04:47

What do you recommend to study when a intermediate level in Clojure is reached ?

Joe Lane18:04:17

Have you read "The Joy of Clojure" ?

thanks 4
metal 12
Breno Duque Estrada18:04:30

Not yet. But I know this book and it is on my read plans.

nick19:04:39

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.

4
truestory 4
mike_ananev19:04:07

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

4
hindol19:04:13

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.

12
Breno Duque Estrada23:04:59

Thank you guys! These advices were very good to me!

Breno Duque Estrada23:04:51

@U0113AVHL2W Which book did you mention, e.g ?

nick00:04:21

@U010H5U6SEM I was referring to the same book that @U0CJ19XAM mentioned. "The joy of clojure". It was released in 2011.

truestory 4
seancorfield01:04:15

The 2nd Edition came out in 2014.

seancorfield01:04:40

(and, yes, it's a great book once you have the basics down)

seancorfield01:04:21

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).

Breno Duque Estrada15:04:47

Very cool guys! Thank you!

Breno Duque Estrada15:04:48

@U04V70XH6 Do you recommend this book after reading the "The Joy of Clojure" ?

seancorfield17:04:07

@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).

Breno Duque Estrada18:04:31

Oh, I knew "The Clojure Cookbook" last week and I'm very interested

Breno Duque Estrada18:04:37

Thanks for the recommendations!

rgm23:04:31

my kingdom for a “Joy of Clojure” 3rd Ed treating spec and core.async.

rgm23:04:02

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).

rgm23:04:31

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:😘

seancorfield23:04:10

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.

seancorfield23:04:54

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'.

rgm23:04:17

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

rgm23:04:20

(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 😬).

clj 12
jjttjj19:04:35

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")

jsn19:04:37

o_O user=> (re-seq #"(?m)^A.+$" s) ("A 1" "A 2" "A 3")

p-himik19:04:59

Yep, can confirm - works for me both in CLJ and in CLJS.

jjttjj19:04:38

I'm on windows, could this be related to that?

p-himik19:04:46

Was just about to ask. :D

jjttjj19:04:49

I know there are some newline differences

p-himik19:04:55

Yep, exactly.

jsn19:04:53

I don't have Windows, but in cljs it works for me even with windows line endings

jjttjj19:04:13

Ok it looks like this might be an inf-clojure bug actually

jsn19:04:22

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")

jjttjj19:04:14

yeah it's working for me from the command line just not in emacs

andy.fingerhut19:04:53

I have a customization to inf-clojure Emacs Lisp code that does not eliminate newlines in the strings sent to REPL.

andy.fingerhut19:04:11

Default inf-clojure behavior for some of the key bindings to send expressions to REPL is to eliminate newlines.

jjttjj20:04:29

Any chance you'd be willing to share the relevant code when you have a chance?

andy.fingerhut20:04:05

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

jjttjj20:04:46

perfect, thanks!

hindol20:04:37

When using definterface, do I have to use import function instead of the (ns (:import ...)) form?

bfabry20:04:59

in the consuming ns?

hindol20:04:46

In the ns where I define the interface.

hindol20:04:54

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.

hindol20:04:34

If I don't fully qualify, that resolves to java.lang.HttpRequestMessage. Don't know why.

bfabry20:04:19

that is surprising

hindol20:04:46

And the function form (import ...) did not help either. 😕

bfabry20:04:35

try using (with-meta 'request {:tag HttpRequestMessage}) maybe...

bfabry20:04:59

the docs seem to indicate what you're trying should work

hindol20:04:06

Where do I put this? In place of the type hinted arg?

hindol20:04:40

Like this?

(definterface Functional
   (run [(with-meta 'request {:tag HttpRequestMessage})]))

hindol20:04:49

^ This removed the hint entirely, now it's Object.

hindol20:04:48

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