Fork me on GitHub
#clojure
<
2023-07-24
>
kishima01:07:57

Hello, I’ve read some discussions on having a feature like common lisp core images on clojure, but they are old: https://groups.google.com/g/clojure/c/qZEkdlZKNQs/m/FYkjBJFAnGUJ https://groups.google.com/g/clojure/c/CR1bWntExYo/m/5BQg-PadbXgJ https://groups.google.com/g/clojure/c/YZjbfYJhApM/m/_RS7jhJX0c4J I kind of recently learned about this Common Lisp feature so I was wondering if this is something that people have done already and I just can’t find a library to do it. Does anyone know about this? Beyond that, any recommended readings on this feature in CL? Thanks in advance!

didibus03:07:04

It's kind of limited by the JVM, since that's the runtime. So I don't Clojure could do much, unless the JVM offered a reliable feature for it.

2
didibus03:07:25

It does have some things like app-image, but they're finicky and not similar to CLs

2
John09:07:23

I couldn't find it but I think I remember reading some recent conversation on image-saving/heap-dumping for JDK, maybe as part of project Leyden ? I don't know

👀 2
kishima13:07:26

I see, so the possibility to implement this somewhat relies on the JVM at first

👍 2
kishima13:07:54

Looking at Leyden and will see if there’s related stuff that could be into it, really interesting!

Colin (fosskers)10:07:52

Regarding my last question about how to do SSL properly, I think I've managed it without hitting the pitfalls described to me by others here and by the less-awful-ssl library itself. I have a cert and key pair fetched from LetsEncrypt as-is (without converting as advertised by less-awful-ssl), to which I do:

(defn server-config [port]
  {:port port
   :join? false
   :ssl-context (ssl/ssl-context "privkey.pem" "fullchain.pem")
   :ssl-port 3001
   :client-auth :want})

(def server (ring/run-jetty (wrap-params #'handler) (server-config port)))
And this seems to work just fine both in the browser and via curl. Have I missed some landmine? If it matters, I'm current running this on Java 17.

chucklehead11:07:47

Not familiar with the library, but looking at the conversion in the readme I think you would only need it for Java 8

chucklehead11:07:14

PKCS12 keys are supported since 9

djanus10:07:54

Looks like something has changed in the JVM sometime between 11 and 20 that has affected Clojure reflection handling. (Thread/sleep (rand-int 1000)) works on 11 but throws a reflection error on 20. This is on Clojure 1.10.1 but 1.11.0, 1.11.1, and 1.12.0-alpha4 exhibit the same behaviour. I haven’t tried other JVM versions yet; I’ll post updates in comments as I gather more info. What gives? Does anyone have any idea?

djanus10:07:36

Works on OpenJDK 17.0.6 in Linux

p-himik10:07:02

You can search for Thread/sleep in this channel - it has popped up at least twice before.

thanks3 2
phill23:07:03

@UE21H2HHD I don't understand that at all. Instead of fixing Clojure's reflection bug, we're hoping to special-case every present and future case where the JDK adds an arity?

lread23:07:34

Hiya @U0HG4EHMH the problem is that the JDK changed the fn signature. I don't see it as a problem in Clojure itself. Steering folks to a convenience sleep fn seems like an OK way to address/adapt.

p-himik10:07:26

Huh, weird. Can't reproduce it now on JDK 20 and Clojure 1.11.1. Tried REPL, -i, -e, -m. Made sure that Thread/sleep does have three arities, two of them with just one argument.

vemv13:07:23

Although thankfully it's not part of my daily workflow, from time to time I have to type

(require 'foo.bar.baz)
(in-ns 'foo.bar.baz)
into a terminal, by hand. Would it not be possible for Clojure to provide a handy helper? Is it not simple for some sort of wicked repl reason?

dpsutton13:07:05

(doto 'foo.bar.baz require in-ns)

🤯 10
dpsutton13:07:26

i credit this one to noisesmith

clojure-spin 6
Reut Sharabani13:07:43

so we're not getting inquire? 😞

😆 26
valtteri14:07:37

Where is noisesmith nowadays btw? He used to be very active here

Andrew Ni19:07:11

In the https://clojuredocs.org/clojure.core/await, the wording seems to imply that an agent can send an action to another agent and wait for it to finish. However, I tried to write some code to that effect, and got an error

(def m
  (agent {:agent (agent 0)}))

(defn stepm
  [m]
  (await (send (:agent m) inc))
  m)

(send m stepm)
When I try to run this code, at first nothing happens, since @(:agent @m) evaluates to 0 still. Then, when I try to rerun the (_send_ m stepm) line, I get a runtime error saying "Can't await in agent action_."_ which seems to imply the opposite of what the clojure page says. Does anyone know what's going on? Thanks!

phronmophobic21:07:39

It's not typical to nest agents. It's not totally clear what you're trying to do. Maybe something like:

(def m
  (agent {:num 0}))

(defn stepm
  [m]
  (await (send m update :num inc))
  m)

(stepm m)

phronmophobic21:07:05

Agents are rarely used. Using atoms is much more common.

Joshua Suskalo21:07:59

It does seem like the docstring is contradicting the behavior, whether or not it's useful to do.

phronmophobic21:07:54

ohhh, I think I understand the question better now. If you wrap sendm with a try/catch, you can see the error:

(def m
  (agent {:agent (agent 0)}))

(defn stepm
  [m]
  (prn m)
  (try
    (await (send (:agent m) inc))
    (catch Exception e
      (prn e)))
  m)

(send m stepm)
;; Exception: "Can't await in agent action"
This makes sense since all agents share a thread pool, so agents awaiting other agents could cause deadlock in some cases. Either way, it's probably not what you want.

Joshua Suskalo21:07:25

Yeah, I think the specific concern is that the docstring is confusing > Blocks the current thread [...] until all actions [...] from this thread or agent [...] have occurred.

Joshua Suskalo21:07:53

There's things about await that make it far from ideal to use as well, like it never returning if a failed agent is restarted with clear-actions or when shutdown-agents are called.

Joshua Suskalo21:07:08

I'd more or less say to avoid await if you can

Andrew Ni01:07:33

ok, thanks! Should I add a note in the clojure docs about this?

👍 2
phronmophobic01:07:34

Seems reasonable. The docs have the wiki which can be helpful. You could also describe the issue on http://ask.clojure.org

Jake Jasey21:07:53

What would anyone recommend for a good Clojure course/tutorial that would provide a good base for interviewing for clojure jobs

Bobbi Towers21:07:14

Practicalli, Lambda Island (now free!), and Eric Normand's courses come to mind

Jake Jasey21:07:03

Do you have links?

nikolavojicic22:07:56

Also, watch Rich Hickey talks clojure-spin

💯 4
Jake Jasey22:07:23

@U8LB00QMD do you know where to find that Eric Normand course for free?

Jake Jasey22:07:10

Lambda Island seems really cool

Bobbi Towers22:07:56

They're professional grade courses used for company onboarding, and it's his livelihood, so unfortunately not

practicalli-johnny07:07:44

Many Clojure interviews have some kind technical test (sometime incorrect described as pairing). So practicing Clojure via small challenges may be quite useful. http://Exercism.com has lots of interesting challenges to solve and http://Practical.li has some solution walk-throughs to read that try different approaches (try solve the challenges first before though) 4Ever Clojure also has challenges to help learn the functions in the standard Clojure library https://practical.li/clojure/coding-challenges/

bherrmann13:07:59

Clojure is often used as a backend. I'd review REST and be comfortable articulating what it prescribes also where it comes up short.