Fork me on GitHub
#clojure
<
2019-04-02
>
jumpnbrownweasel00:04:34

@noisesmith, that is really good to know! But undocumented, right?

noisesmith00:04:05

hmm... I thought I saw it documented somewhere, let me see if I can dig it up

noisesmith00:04:04

there are examples here and there, but I don't find anything mentioning that all the -> related macros are designed to work inside -> http://clojuredocs.org/clojure.core/as-%3E#example-568eeddae4b0f37b65a3c280

noisesmith00:04:52

oh wow this one - I never thought of using as-> with destructuring http://clojuredocs.org/clojure.core/as-%3E#example-5b5e08e9e4b00ac801ed9e3a

jumpnbrownweasel00:04:16

I guess it's implied that nesting would work, since it isn't prohibited.

jumpnbrownweasel00:04:45

That is an interesting one with as-> and :as.

raaon00:04:36

i'd like to use clojure to generate some defrecord classes (and some helper methods) that i intend to consume from Java... eg:

(ns my.core
  (:gen-class :name my.core.Support :methods [^:static [getEvents [] ...]]))

(defrecord Event [^String name ^Date date_])
(def -getEvents [] ...seq of Events...)
from Java i should be able to stuff like this:
import my.core.Event;
import my.core.Support;
...
public static void main(String[] args) {
   events = new ArrayList<Event>(Support.getEvents()); 
   // ^^ i get ClassCastException here b/c the imported Event is loaded by AppClassLoader
   //     but the Events produced by the clojure-compiled gen-class are loaded by clojure's DynamicClassLoader
   //  ... what's the best way to do this kind of thing
}

noisesmith00:04:51

don't you have to load Support before Event at the very least?

noisesmith00:04:31

I've found calling Clojure via Java to be much easier with the clojure.lang.RT static methods (var, require, etc.) rather than trying to use gen-class namespaces as classes

Alex Miller (Clojure team)03:04:46

note that this is not a public api and you should not rely on it. Instead, you should use the Clojure Java API - http://clojure.github.io/clojure/javadoc/

raaon00:04:19

hmm i do need to statically link/compile in my case.. .. wondering if there's a way to tell Clojure to load certain classes like these instead of dynamically complie them

noisesmith00:04:10

you can't call the clojure API from the java code?

noisesmith00:04:53

if you properly aot-compiled you will be able to import the classes, and the classes will in turn initialize clojure if it isn't initialized yet

yedi00:04:42

oh sweet @noisesmith didn't know you could nest ->> and as-> inside a ->... feel like i'm gonna overuse this thoroughly now

noisesmith00:04:01

(a gotcha is that with eg. lein, it assumes that your java needs to be compiled before your clojure, and here I think you really want the opposite)

noisesmith00:04:53

that's fixed with `:prep-tasks ["javac" "compile"]` :prep-tasks ["compile" "javac"] (fixed)

noisesmith01:04:54

@atdixon what type are you defining for getEvents to return in gen-class btw?

noisesmith01:04:05

(I assume java.util.Collection by context)

raaon02:04:41

interesting thx for that noisesmith, let me try something incidentally i'm using clojure-maven-plugin not lein so let me what i can find out here

raaon02:04:27

@noisesmith very cool. thank you for doing that repro. it led me to a fix... while lein excludes the .clj sources from the built target/jar files, clojure-maven-plugin (what i'm using) does not do this by default so the presence of my clj source was causing clojure to prefer loading the defrecord by dynamic compilation rather than using the .class file that the static/linker was using - so the Event loaded by the java compiled code was not the same as the Event getting dynamically produced by clojure/DynamicClassLoader anyway i'm able to configure out the clj sources so that all is getting loaded by the AppClassLoader and now i'm working---thx again !

4
danielstockton08:04:51

Anyone had issues with lein deps constantly failing with something like Could not transfer artifact amazonica:amazonica:pom:0.3.123 from/to clojars (): Connection reset during docker build and remember a solution?

danielstockton08:04:58

This particular dependency doesn't seem like the issue, it's different every time. Works fine outside of docker.

kwladyka09:04:27

sounds like issue about docker environment

kwladyka09:04:55

or your Internet connection

danielstockton13:04:33

I ended up using a multi-stage build and compiling the uberjar outside of the runtime environment. Was able to get it to work then, and with a smaller final image, so yay

kwladyka09:04:16

How to figure out how to mute logging for Java dependency? I use flyway and it make so huge mess in REPL by printing even debug info. In the past this was working (.setLevel (Logger/getLogger "org.flywaydb") Level/WARNING), but not today (new ver. of flyway? I guess they changed logger or something). How to deal with such situations?

kwladyka10:04:34

on the end jdbc use logback, flyway use who knows what, how to deal with this mess?

kwladyka12:04:24

I mean what is the one right way to set level for logging? I have to do it separately for slf4j, log4j, logback etc. or is the way to do it in one consistent way? Should I use slf4j or logback?

kwladyka12:04:22

In most of examples I see people set this levels by logback, not in slf4j even if they use it

kwladyka12:04:00

another question: If one of my dependency use log4j, but another use logback I guess logback will capture log4j input as facade.

kwladyka12:04:12

How to control it?

kwladyka12:04:42

Personally I use timbre as logger, but Java libraries make a mess sometimes

dmarjenburgh12:04:58

Looks like flyway uses slf4j bindings, so if you use logback, you should be able to set the flyway log level in your logback.xml (or whatever method you use). I haven’t tried it myself though

kwladyka15:04:48

Finally I did (.setLevel (org.slf4j.LoggerFactory/getLogger "org.flywaydb") Level/WARN) but still I don’t feel it 🙂

kwladyka15:04:17

Also I have logback because jdbc use it

kwladyka15:04:55

So probably dependency from jdbc (logback) bind slf4j to logback… who knows how this hell works 🙂

kwladyka15:04:16

I use timbre in my code

Eric Clack14:04:04

Ages ago I think I saw some people talking about the http://4clojure.com site. I'd like to contribute and get it working well, e.g. this https://github.com/4clojure/4clojure/issues/309 would be good to fix.

Eric Clack14:04:09

Anyone have any pointers?

sailowcat18:04:01

On http://repl.it one can write clojure programs, if that's what you ask.

Eric Clack18:04:01

Not quite. 4clojure is a learning platform, which works well but has some shortcomings and it seems to have been abandoned. I wondering if anyone knows the authors or has tried to get it active.

sailowcat18:04:45

aaah, I thought that you want a replacement for http://try-clojure.org

wei18:04:26

has anyone used ions in production and can vouch for it? considering using it for a small production project

Lauri Rutanen19:04:51

Does clojure have some command-line tools which are required by some clojure projects to run?

noisesmith21:04:47

yes, the core clojure project has cli-tools that are installable via your package manager (eg. homebrew on a mac)

Lennart Buit19:04:16

some projects depend on leiningen

Lauri Rutanen19:04:05

More specifically, I am trying to run 'lein repl' in one such project's root, and I get 'clojure.lang.ExceptionInfo: Could not find clojure executable {:tried-paths ["/usr/local/bin/clojure"]}' which seems to indicate I should have /usr/local/bin/clojure

Lennart Buit20:04:44

/usr/local/bin/clojure is installed by homebrew on my macos system. What are you using?

Lennart Buit20:04:54

its part of clojure itself

Lauri Rutanen20:04:25

I was trying Fulcro (following this documentation here: http://book.fulcrologic.com/#_about_this_book)

Lauri Rutanen20:04:03

So it seems it's not related to leiningen actually but how that Fulcro template is set up

Lennart Buit20:04:37

I am sorry, but I don’t know.

Lennart Buit20:04:41

maybe ask in #fulcro ^^!

Lauri Rutanen20:04:00

Yeah! good idea, thanks Lennart 🙂