Fork me on GitHub
#clojure
<
2021-08-05
>
Carlo07:08:39

In ghostwheel's readme, there's this line about enabling it in a clojure project:

On Clojure – launch the REPL / build with the JVM system property -Dghostwheel.enabled=true
how would I have to edit my clojure cli repl command so that that's included? This doesn't work:
/run/current-system/sw/bin/clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.8.3"} refactor-nrepl/refactor-nrepl {:mvn/version "2.5.1"} cider/cider-nrepl {:mvn/version "0.25.9"}} :aliases {:cider/nrepl {:main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}}}' -M:cider/nrepl -Dghostwheel.enabled=true

thheller07:08:32

@meditans -Dghostwheel.enabled=true needs to be -J-Dghostwheel.enabled=true when using the clojure tool. or within the -Sdeps map :jvm-opts ["-Dghostwheel.enabled=true"]

Carlo07:08:54

Thanks for the immediate response @U05224H0W 🙂 Neither option works for me, but maybe at this point it's because I'm trying to use a projectless approach with add-libs. Here's my standalone file:

(use 'clojure.tools.deps.alpha.repl)

(add-libs {'gnl/ghostwheel {:mvn/version "0.3.9"}})

(ns user
  #:ghostwheel.core{:check true, :num-tests 10}
  (:require [ghostwheel.core :as g :refer [>defn >defn- >fdef => | <- ?]]))

(>defn addition
  [a b]
  [pos-int? pos-int? => int? | #(> % a) #(> % b)]
  (- a b))

(g/check)
;; "Ghostwheel disabled => Start the REPL with the `-Dghostwheel.enabled=true` JVM system property to enable."

Carlo07:08:45

then I jack in into cider, editing the launch command as you suggested, then I eval the buffer. Is there any known reason for which this shouldn't work?

thheller07:08:34

check (System/getProperties) if yours is actually set correctly

thheller07:08:01

(get (System/getProperties) "ghostweel.enabled")

Carlo07:08:40

hmm, no it gives me nil 😮

thheller07:08:13

where did you set it exactly? I think the position matters

Carlo07:08:02

I tried:

/run/current-system/sw/bin/clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.8.3"} refactor-nrepl/refactor-nrepl {:mvn/version "2.5.1"} cider/cider-nrepl {:mvn/version "0.25.9"}} :aliases {:cider/nrepl {:main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}}}' -M:cider/nrepl -J-Dghostwheel.enabled=true

Carlo07:08:23

and at the beginning of the -Sdeps map for the other solution

thheller07:08:49

I think the -J needs to come before the -M if anything

thheller07:08:20

but the map should be fine I think

thheller07:08:42

dunno if cider maybe starts another JVM or so to make add-lib work

Carlo07:08:06

in fact, if I put it before -M, the get function returns true. But why? And how should I have known?

thheller07:08:55

-M executes clojure.main so I think every argument coming after that is treated as an argument to clojure.main instead of the clojure script itself

thheller07:08:07

just guessing though, not sure 🙂

Carlo07:08:17

I see, thank you for your help 🙂

Carlo07:08:27

the thing as a whole doesn't work yet, as I get cannot resolve user (where user is the namespace) when I try to issue (g/check) but at least it's not a configuration problem

Carlo07:08:39

oh, but it seems that if I substitute user with interesting.user as the name of the namespace, all works 😮

Jim Newton07:08:40

Does anyone know the history of the convention that clojure projects organize themselves such that all identifiers in one namespace are defined in a single file whose name indicates the namespace? This is not a requirement of the language, but seems to be a convention presumed by several tools. I suspect that this convention developed at some point after the birth of the language. A bit of evidence to support my hypothesis is the file cl_format.clj which defines the function cl-format as well as several helper functions in its implementation. The file cl_format.clj does not define a namespace named cl-format but rather contains a line at the top (in-ns 'clojure.pprint) which to me seems like the more logical way to organize projects. I.e., group definitions such as functions, data structures, and variables into files according to the purpose they serve rather than according to which namespace they happen to belong.

👀 1
thheller07:08:12

although written for CLJS the same "content addressing" applies for clojure. things need to be discoverable by name so you can reference them. sure you can split them and use load tricks but that just becomes dirty after a while. IMHO, YMMV

Jim Newton09:08:24

content addressable vs ad-hoc loading are not the only options. but yes there needs to be a way to find the code given its name. but that mapping need not be the identity function.

thheller07:08:33

IIRC ns :require was added later and wasn't part of the language at first. so the clojure.pprint may just be a remnant of that time

thheller07:08:50

if you ask me that load style is horrible. its very very common in the JS world and re-exporting stuff all over the place. nightmare to find actual source for something sometimes. just jumping from one file to another following a trail of breadcrumbs 😛 much better to look at a name and directly know where to find it

☝️ 3
Adam Helins08:08:09

Regarding tools.build and current Deps support, when consuming external source (git or local) that has a build step, is there a way to parametrize that step at the level of the consumer? Eg. Consuming from a monorepo but I only need to build and use one of the many library it contains. Something like

{:deps {io.github.foo/bar {:git/sha   "xxxxx"
                           :exec-args [:lib/baz true]}}}

kwladyka08:08:50

Unless you mean exactly in clj code?

Adam Helins08:08:18

I mean something like this, in deps.edn:

{:deps {io.github.foo/bar {:git/sha "xxxxx" :build :some-arg}}}
So that :deps/prep-lib in the consumed repo would forward :some-arg to the build function.

Adam Helins08:08:01

As as consumer of that repo, I would have the ability to influence the build process.

Adam Helins08:08:54

I'll edit my question, it's in the context of tools.build 😉

Adam Helins08:08:11

Supposing something like this is already setup https://clojure.org/guides/tools_build#_parameterized_build

👍 3
Jim Newton09:08:33

is there a web page URL which contains the cl-format code? there is a source link on many packages in clojure.docs but not this one?

Joel14:08:26

How can i isolate clojure instances? I have dynamically loaded code that define defmethods for dispatch. However, I also want to be able to dynamically load and test code (eg. "version n+1") in a way that won't affect the previous version. Obviously I could run in a separate process, but is there something I can do short of that?

kwladyka14:08:00

with-redefs help?

Ed14:08:12

You can put the new version in a new namespace. There`s also the dark art of classloader isolation, but tbh you're better off starting a new process.

Joel17:08:31

ill take a look at with-redefs, i suspect though defmethod is problematic. yeah, i looked into classloader, but wasn't finding enough info, as you say "dark art".

Joel17:08:28

yes, i was going to rename the namespaces, but that alone didn't seem sufficient, again the defmethod would be problematic, and I'm not sure what else might be.

Joel17:08:37

i suppose i could change the defmulti :require, so that it's effectively a different defmethod, but then it all seems fragile.

Joel17:08:14

on this page, i think they mean the last line that says ;;true should be ;;false?? https://clojuredocs.org/clojure.core/*use-context-classloader*

Jan K14:08:05

On a related note, do you guys think it would make sense to run independent Clojure apps (servers) in an app server like Tomcat to save memory by sharing a JVM?

vemv14:08:25

If the apps are truly independent it's a bad idea, as they might have incompatible Maven dependency trees If 'apps' is more like 'logical services', yes. Polylith goes in that direction :) Still one has to take care of shared resources like thread pools, singletons, locks etc. Anything that might create contention

kwladyka14:08:29

memory is cheap, I think extra work will cost more, than pay for memory. At least I use docker everywhere.

Jan K14:08:38

I think Tomcat has isolated classloaders, so incompatible deps should work. I run my stuff on cheapest VPS I could find, RAM is usually the biggest constraint for me.

kwladyka14:08:11

this is my opinion: increasing complexity is not worth. I prefer to keep infrastructure simple. I believe it gives much more benefits. Try google cloud run. Probably for your needs you can run instances for free. Just guess.

kwladyka14:08:30

Many issues can be solved on infrastructure level instead of in app itself.

Jan K14:08:09

I'll have a look at cloud hosting

didibus19:08:25

I noticed that core.memoize has something called RetryableDelay and a d-lay `https://github.com/clojure/core.memoize/blob/master/src/main/clojure/clojure/core/memoize.clj#L54 It's private now, but I'm thinking this would be pretty useful for me, to have a delay that on deref exception will throw and not cache, so on the next deref it retries. Would it make sense to make this public?

seancorfield19:08:44

It's not something I would want folks to rely on as part of a public API.

seancorfield19:08:21

(I think it's nasty code but it serves a purpose)

p-himik19:08:53

You mean the concept or the implementation? Why do you think it's nasty?

seancorfield19:08:00

I'd have to go revisit it to elaborate further and I'm not working on it right now.

seancorfield19:08:54

I'll try to remember to review it in more detail and report back when I cut the next release -- because I need to bump its dependency on core.cache to pick up the LU/LRU bug fixes in that lib's 1.0.217 release from the other day.

p-himik19:08:25

Sweet, thanks!

didibus20:08:47

Ya, I think for me I was thinking it might not fit conceptually with core.memoize, I could see maybe a separate thing just having various types of delays instead. One that doesn't cache on error, one with a ttl, one that can be invalidated, etc.

Jakub Holý (HolyJak)20:08:06

Hi folks! Any idea how to fix

❯ clojure -M:serve                                                                 • [master]
Execution error (UnsatisfiedLinkError) at java.lang.ClassLoader$NativeLibrary/load0 (ClassLoader.java:-2).
/private/var/folders/06/46ycckp94db7k29k022nxjp00000gn/T/jna9260967378841025822.tmp: dlopen(/private/var/folders/06/46ycckp94db7k29k022nxjp00000gn/T/jna9260967378841025822.tmp, 1): no suitable image found.  Did find:
	/private/var/folders/06/46ycckp94db7k29k022nxjp00000gn/T/jna9260967378841025822.tmp: code signature in (/private/var/folders/06/46ycckp94db7k29k022nxjp00000gn/T/jna9260967378841025822.tmp) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.
? I have never seen this before and this worked on another machine (with a different JVM). Using openjdk 12.0.2 2019-07-16, Clojure CLI version 1.10.3.933 🙏

3
Jakub Holý (HolyJak)20:08:32

downgrading from java 12 to 11 "fixed" it