Fork me on GitHub
#clojure
<
2018-06-07
>
emccue03:06:19

what a world

😁 4
michaellindon03:06:02

Has anyone tried connecting to a repl that is inside a docker container?

gklijs03:06:22

Yes, started repl from de docker, connected with cursive, worked. You had a question?

michaellindon06:06:12

im kind of new to docker - how did you configure the nrepl port options?

hyankov15:06:02

I’ve also done this, connecting with cider, though. You have to expose your repl port - see docker run -p option and then connect to localhost:<exposed port>

gklijs06:06:01

I set the nrepl port with a system variable, easy to set in a docker compose

gklijs06:06:43

Just looked it up, but the port was hardcoded, and I used network_mode: host in the docker compose, so could just open the port from the docker like it was on the machine, you will need docker on linux for this to work

miro07:06:39

hey guys! A compiler question: I am compiling some java lambda code (so java sytax ) in clojure using java compiler I get via javax.tools.ToolProvider.getSystemJavaCompiler(). It turns out to be much slower (~ 10x - 100x) than just using clojure's compiler and just eval-ing clojure code using java interop (similar code, just in clojure syntax for java interop). Anybody has any ideas why I might see such difference? Is clojure compiler so tuned or are there things I can tune in the default JavaCompiler and the compilation configuration?

dottedmag12:06:13

What's the best way to call into macOS APIs from Clojure? I don't need Cocoa, only CoreFoundation and other low-level frameworks.

jumar13:06:17

@U07HVGQJ3 JNA may be the easiest approach. Check https://github.com/Chouser/clojure-jna

(def cf-current-time (jna/to-fn Double CoreFoundation/CFAbsoluteTimeGetCurrent))
  (cf-current-time)
You may also want to look at oshi (although I've never used it): https://github.com/oshi/oshi/blob/master/oshi-core/src/main/java/oshi/jna/platform/mac/CoreFoundation.java

OrenWF16:06:01

Total newb but just read something about the Graal VM ... would that have some usefulness here ?https://github.com/graalvm/

dottedmag10:06:08

@U87H0P528 Incidentally that's what I intend to do: a Mac CLI tool, compiled by GraalVM.

👍 4
dottedmag10:06:32

@U06BE1L6T Thanks, I'll try JNA.

👍 4
dottedmag10:06:24

And Graal has its own interop library: http://www.graalvm.org/sdk/javadoc/

dottedmag12:06:52

I understand they are all C, so I can write a bunch of JNI wrappers, but maybe there is some ready-made library that allows me to skip this tedious process?

ghadi14:06:01

JNR-FFI will help with the boilerplate

hyankov15:06:02

I’ve also done this, connecting with cider, though. You have to expose your repl port - see docker run -p option and then connect to localhost:<exposed port>

emccue16:06:25

@miro My hand wavey guess is that java's compiler needs to do more work. Java is a more complex language in general so i dunno maybe that affects things.

emccue16:06:46

Also curious about using clojure in lambda

emccue16:06:00

I don't see a way around that murdering start up time

emccue16:06:33

so i am curious what the tradeoffs are for you

noisesmith17:06:19

@emccue a lot of that startup time is 1) jvm spinup which lambda eliminates by leaving a vm running and 2) tooling (eg. lein) spinup which should only happen during dev never on a server

noisesmith17:06:15

clojure itself can load in ~1s which is slow but not disasterous

sobel17:06:36

java spin-up is like 100ms these days

noisesmith17:06:49

right, just saying lambda trims that

sobel17:06:48

yeah. clojure is a significant % overhead by comparison.

Mario C.18:06:44

I have a question on defrecords

Mario C.18:06:16

In a file there is a defrecord define like so

(defrecord Name [conn db]
        Database
        (do-something (hello something))) 

Mario C.18:06:43

Ive never seen an example of this online. Usually it is just defined like this in the examples

Mario C.18:06:56

(defrecord Name [conn db])

Mario C.18:06:15

Can anyone explain what is going on?

noisesmith18:06:25

the record implements a protocol or interface called Database, and that's how it implements the do-something method

noisesmith18:06:50

but that's incorrect, the method needs an arg vector (like function syntax) and it needs at least one arg for the instance itself

Mario C.18:06:45

Okay so all the methods that follow under Database are protocols being implemented?

noisesmith18:06:00

Database is the protocol, it has multiple methods

Mario C.18:06:30

Yes you are correct they actually look like this

(do-something [_ some_id] (hello something-else))

Mario C.18:06:56

The first underscore here means that we wont be using that argument, correct?

noisesmith18:06:14

the first argument is the object itself, yes

noisesmith18:06:43

and _ is a conventional name for arguments you ignore - technically it's just another name though

Mario C.18:06:22

I see, thanks again. I can google the rest since I know now what to look for

lilactown19:06:46

so I have a question about types/protocols

lilactown19:06:25

the specific instance I have, is that I want to extend reagent's atom type with some extra functionality... sometimes

lilactown19:06:12

basically, in my app I have some functions that return a ratom that represent a graphql query

(let [data (query! client some-query)]
  (fn []
    (println @data) ;; => {:loading false :data { ... }}
  ))
and I'd like to be able to programmatically refetch this query. my ideal API would be something like:
(let [data (query! client some-query)]
  (fn []
    (println @data) ;; => {:loading false :data { ... }}
    [:button {:on-click #(re-fetch! data)} "Clicky"]
  ))

lilactown19:06:37

is there some way to extend the reagent atom returned by the query! function to implement re-fetch!, without having to box the ratom in a new type and re-implement all of the protocols that RAtom uses?

tristefigure19:06:54

Using reflection, this library will generate the delegation methods for you. There is a monkey-patch of isa? though, not sure how bad this impact performance.

lilactown19:06:09

interesting!

lilactown19:06:30

yeah, this seems hairy. also not sure how it'll work in a CLJS context

lilactown19:06:26

I'm kind of tempted to stick a field into meta-data on the reagent atom with the function or object needed to refetch, and pull it out using re-fetch!

lilactown19:06:48

would that be abusing metadata? 😬