Fork me on GitHub
#clojure
<
2018-04-09
>
Aleksander09:04:03

Hey all, I would like to understand better what happens when Clojure namespaces get loaded and reloaded. I guess I need to understand more about bytecode, classloaders and Clojure compilation process. Any good resources on that?

reborg10:04:57

@dev964 see if this slide helps a bit

Aleksander10:04:51

thanks @reborg that helps a bit - I still need to understand what classloaders do though. never got to that level ...

reborg10:04:56

So one step back, something like https://www.journaldev.com/349/java-classloader or in general, search "custom classloaders in Java" to have an idea of what Clojure does on an industrial scale (one new classloader each re-evaluation)

Aleksander10:04:35

ok, thanks! I'll read up on that!

eraserhd13:04:26

I have an idea for a repl-helper library for dealing with large output in data structures ... tests, etc. To do it, I need to change the printer, but only for REPL output. I know you can dynamically bind for the REPL thread, but I think this isn't sufficient. Has anybody done this>

dominicm14:04:11

@U0ECYL0ET look at unravel, it has an ellipsis system

eraserhd14:04:05

ahh, this is nice, but seems to only be for lazy data structures. Mine are strict and huge.

dominicm14:04:41

I don't think it's only for lazy ones, it works for {} too.

dominicm14:04:50

the printer is lazy.

eraserhd14:04:58

Do you have a way to get this to work with vim-fireplace, since it's not nREPL?

dominicm14:04:04

vimpire works with it.

dominicm14:04:19

but that is a fireplace alternative, not a fireplace plugin

tony13:04:33

is there any clojure library mapping Olson time zone to .NET TimeZoneInfo ? for instance "America/New_York"----> "Eastern Standard Time"

sveri13:04:23

@tony what is a Olson time zone?

tony13:04:26

@sveri IANA in the TZDB

sveri13:04:23

@tonywang897in clojure this is the timezone library to go to: https://github.com/clj-time/clj-time I dont know if it handles timezone conversion. Otherwise I would just use the java.time package as it does timezone handling as its expected.

tony13:04:54

clj-time does't have anything like that

sveri13:04:51

https://docs.oracle.com/javase/tutorial/datetime/iso/instant.html -> LocalDateTime ldt = LocalDateTime.ofInstant(timestamp, ZoneId.systemDefault());

sveri13:04:57

java 8 made this pretty easy

ghadi13:04:36

I would anti-recommend all the Clojure time libraries (yes, every last one of them). They are at best white gloves for interop, at worst misunderstand the underlying library designs.

12
ghadi13:04:58

Just use java.time. That tutorial @sveri linked is A+

ghadi13:04:42

- Veteran Clojure programmer

sveri13:04:50

After using clj-time on and off I would agree with this

dominicm14:04:40

java time is pretty great.

dominicm14:04:49

although I'm still not sure if I "get" how to use it safely

joelsanchez14:04:23

even clj-time doesn't recommend clj-time "Note that from Java SE 8 onwards, users are asked to migrate to java.time (JSR-310) - a core part of the JDK which replaces this project."

ghadi14:04:19

you really don't need any wrapper. novice users just need to know a few java Classes, how to call instance methods and class methods (java "static" methods)

ghadi14:04:53

after that, clojure's core library takes over

juhoteperi15:04:55

I might recommend thin Cljc wrapper for Java.time + Closure library, if good one existed. Or at least library that provides Transit readers/writers and implementations for java.jdbc/clojure.jdbc read/write protocols. No reason to re-implement this in every project.

dominicm15:04:27

That would be valuable, unifying the two would probably be very difficult though? Or is there similarity?

juhoteperi15:04:04

If you don't attempt to completely abstract them away, but only provide most common functions you'd need in cljc code, it is possible. I have one for JodaTime that I should rewrite to Java8: https://github.com/metosin/metosin-common/blob/master/src/cljc/metosin/dates.cljc

viirii18:04:01

question regarding spec.alpha . For following example,

(s/fdef close-enough? :args (s/cat :m double? :n double?) :ret double?)
(defn close-enough? [m n] (< (Math/abs (- m n)) 0.0001))
(stest/instrument `close-enough?)
, both m and n have double requirement per spec. Is there another way to write the spec requirements that groups args with same type?

viirii18:04:12

similar to how in golang, you can group multiple args with same type together a la

func close-enough? (m, n double) double {
    // blahblah
}

viirii18:04:43

or is the example above of (s/cat :m double? :n double?) the most concise it can be?

Alex Miller (Clojure team)19:04:20

personally, I think this is good as is

Alex Miller (Clojure team)19:04:09

but you could also spec :args in various other ways, like (s/coll-of double? :count 2)

Alex Miller (Clojure team)19:04:29

that is less good for several reasons

Alex Miller (Clojure team)19:04:38

1) you’ve lost the arg names in the conformed version of the args, which you’ll want if you use this for docs (like (doc close-enough?)) or in a :fn spec 2) you’ve probably made it harder to evolve the spec with further arg changes 3) function signatures are syntax (heterogenous values where order matters and regex ops like cat are designed for exactly that). coll-of is really designed to represent data. So cat communicates better.

jjttjj19:04:36

Is it a general good idea/convention/idiom, when designing a mini DSL, to use lists instead of vectors in cases where the first element is special? For example I have a function which takes nested sequential data. if there is an internal list, it will check the truthiness of the first value to determine weather to include the remaining elements in the resulting flat vector.

[:key1 :key2 [(> 2 1) :key3 :key4 [(odd? 32) :key5]] :key6] => [:key1 :key2 :key3 :key4 :key6]
I currently use vectors for the nested "lists" but is this a spot where it's clearly better to force the use of lists?

Alex Miller (Clojure team)19:04:38

the major downside of using lists in a dsl is that you must quote to make literal data

jjttjj19:04:18

oh yeah, I think i just overlooked that major aspect

Alex Miller (Clojure team)19:04:19

if you’re not actually having people type it in, then that’s not a factor

jjttjj19:04:53

I was thinking this was a macro but it's a function so would require quoting

Alex Miller (Clojure team)19:04:06

even so, it does communicate different intent and I think that in this example it does read better (but may also imply eval-like things that you don’t wish to imply)

aaelony22:04:36

looks like the domain for expired today?

aaelony22:04:54

This domain name expired on 2018-04-09 19:29:37 
Click here to renew it.

mrchance23:04:01

Hi, I'm calling on the output of nios createTempDirectory, and I get > actual: java.lang.IllegalArgumentException: No implementation of method: :as-file of protocol: #'http://clojure.java.io/Coercions found for class: sun.nio.fs.UnixPath when I run it in a test. However, it seems to work when I do it in the repl. I'm confused 😄 Any ideas?

hiredman23:04:40

you are loading some code in the repl that is extending Coercions to work with a UnixPath

hiredman23:04:55

(or some other code that is part of your repl is loading it)

mrchance23:04:04

@hiredman What could that be? I am not aware of anything like that, and I also didn't do any requires or similar in the repl

hiredman23:04:06

it could be just about anything, what repl are you using?

mrchance06:04:48

Sorry, was interrupted... I am using emacs+cider, my user profile is empty