Fork me on GitHub
#clojure
<
2021-04-17
>
introom06:04:26

Watching this video, what is reified mean:

seancorfield06:04:18

@i In general, “to reify” means “to make (something abstract) more concrete or real”.

seancorfield06:04:09

In this case, it means to turn each possibly implicit “event” or “state change” into an explicit, concrete record of that event that is recorded.

seancorfield06:04:40

Does that help?

introom06:04:57

I wonder how to publish datomic transaction with at least once semantics. Does datomic itself support this functionality?

raspasov08:04:14

Can you please clarify? What do you mean by “publish” ?

yuhan08:04:19

What's the recommended way to structure a project that's divided between "library" and "application" code? I see a lot of repos with /src and /app folders, but I want them to live in separate git repositories and at the same time share a common REPL and dependencies during development. Or is that a bad idea in the first place?

nate sire21:04:32

Git submodules can be really tricky.... They leave the head in a detached state. Your app code is an MVC web stack? With lib in clojure ?

yuhan22:04:14

Nothing to do with web... it's just some library code with a bunch of example uses and extensions of the library that aren't part of the main library logic. My plan now is to move them to separate git repos (not submodules) in the same parent folder.

Ben Sless05:04:07

You can use lein parent and separate directories for libs and apps. Take a look at how reitit is organized. Just split the modules directory in two. I also recommend maintaining the list of libs and the list of apps in files which you can use while scripting

borkdude08:04:34

@qythium This can be easily accomplished using deps.edn/tools.deps :local/root which allows you to develop an app and libraries in one REPL

yuhan09:04:37

Oh! great that we're already using tools.deps 🙂 Do you mean something like this:

foo/
  lib/
    .git/
    src/
    deps.edn
  app/
    .git/
    src/
    deps.edn - {:deps {foo :local/root {"../lib"}}}

yuhan09:04:12

and then I start a REPL in the app/ folder, and tell Cider to sesman-link-with-project

yuhan09:04:12

or I don't suppose you can specify :paths ["../lib"] paths in the deps.edn as well

borkdude09:04:42

no, you're not allowed to specify paths outside of the current dir. Why do you need sesman-link. Just a REPL should be sufficient

yuhan09:04:07

So I can interactively redefine things in the lib/ folder while I'm in app/

borkdude09:04:38

you can already do that

yuhan09:04:11

oh, you can indeed! Thanks for the help 🙂

introom13:04:13

How to change a process’s working directory?

andy.fingerhut13:04:36

If you mean in a running JVM process, then this StackOverflow question seems to describe some ways you can at least partially get that behavior, but perhaps not for all file accessing API calls, maybe only a subset of them: https://stackoverflow.com/questions/840190/changing-the-current-working-directory-in-java

introom13:04:27

Came across this too. Seems no easy way.

roklenarcic17:04:04

Hello all. When calling Java code from clojure, is reflection always used? I’ve come across this in my profiling: Function code: https://github.com/tel/clatrix/blob/master/src/clatrix/core.clj#L214 Profiler says it uses reflection 100% of the time:

roklenarcic17:04:18

Seems odd with all the type hints…

p-himik17:04:10

Matrix is a deftype with a field called me. Maybe if you use (.-me m) instead of (.me m) it won't use the reflection.

roklenarcic17:04:17

You might be quite right… the thing is that if I (set! *warn-on-reflection* true) and reload the namespace clatrix.core it doesn’t give any warnings

roklenarcic17:04:48

Seems like it doesn’t make a difference:

(time (do (doall (repeatedly 10000000 #(.x ^A x)))
          1))
"Elapsed time: 2543.122789 msecs"
=> 1
(time (do (doall (repeatedly 10000000 #(.-x ^A x)))
          1))
"Elapsed time: 2470.688716 msecs"
And profiler still shows:

roklenarcic17:04:54

it’s bizarre

p-himik18:04:42

If you're willing to debug the compiler, I think the relevant place is clojure.lang.Compiler$InstanceFieldExpr. Maybe someone else has some ideas on why you see that behavior, but I don't.

p-himik18:04:23

With just

(deftype X [a])
(def x (X. 1))
(.-a ^X x)
I get the compiler to not use invokeNoArgInstanceMember.

roklenarcic18:04:30

Yeah but as soon as I do this:

(time (do
        (doall (repeatedly 10000000 #(.-a ^X x)))
        1))
Then my profile says tyhat invokeNoArgInstanceMember is back

p-himik18:04:29

An unrelated thing - you can use dotimes instead of repeatedly or dorun instead of wrapping doall in do.

p-himik18:04:57

I can't reproduce it at all with Clojure 1.10.3.

p-himik18:04:17

The whole code:

(deftype X [a])
(def x (X. 1))
(defn xxx [] (.-a ^X x))
(dotimes [_ 10000000000] (xxx))

roklenarcic19:04:34

Yeah that works without reflection. But if I just go (doall (repeatedly xxx 1000000)) it is back again… it’s just weird… maybe the profiler is pulling my leg…

p-himik19:04:43

Still can't reproduce it on 1.10.3 with repeatedly. invokeNoArgInstanceMember isn't in the results at all on my end.

roklenarcic20:04:02

Yeah i dont know. I’ll keep looking

Eccentric J17:04:14

Are people using 🅰️ lein new or 🅱️ clj -X new or 🅾️ other to start projects?

🅱️ 32
🅾️ 43
🅰️ 23
seancorfield18:04:06

I checked both B and O because my O is just mkdir, cd, edit deps.edn sometimes, but it’s still a CLI/`deps.edn` project.

☝️ 5
2
NoahTheDuke23:04:18

i've been using @U04V70XH6’s clj-new. is that clj -X new or other?

seancorfield00:04:08

@UEENNMX0T it’s clj -X:new so it’s 🅱️

👍 6
cassiel15:04:18

Unless I missed something recently, Emacs/Cider still only knows how to launch a lein project, not a clj one. This is probably what keeps me on 🅰️.

nnichols16:04:33

I personally use a GitHub template repo 🅾️ that is mostly 🅰️ plus a few niceties (Default license, community docs, GH Actions, a few shell scripts) Professionally, same orchestration mechanic, but with 🅱️ (I found I always spent more time setting up the “other stuff” than the folder/project structure)

seancorfield17:04:31

@U6BUSDFMX Pretty sure Emacs/CIDER has supported Clojure CLI projects for quite a few releases at this point?

cassiel17:04:58

Oh - I found that it complained if it couldn’t find a project.clj and I had to launch the REPL externally - but Clojure CLI is pretty major now so that would be surprising. I’ll experiment again.

seancorfield17:04:34

(I haven’t used lein for years at this point — but I also haven’t used Emacs/CIDER for years either 🙂 )

Prabu Rajan16:04:01

@U04V70XH6 What editor do you use? I tried Cursive on Idea and Emacs/Cider and I like the debugging on Emacs/Cider. Atleast for a beginner its really helpful

seancorfield17:04:59

@U01UY47RD5E TL;DR: VS Code + Clover for the Socket REPL + Calva for other features with its nREPL stuff turned off. Over the years I have used a lot of different editors with Clojure. I used Emacs for a while but found the “care and feeding” aspect of its configuration too much in the end and never settled on a Clojure-focused setup that I liked (I used Emacs on and off for twenty years, so a long time prior to using it for Clojure). I’ve never liked “IDEs” but I was using Eclipse for Java-based stuff before Clojure and using CounterClockWise for a while (pretty sure that’s no longer maintained). I’ve always disliked IntelliJ (and back when I was an active blogger, JetBrains used to send me free licenses for the commercial version in the hope I would write a glowing review!). I finally switched from Emacs to Atom/ProtoREPL after seeing Jason Gilman demo it at a Clojure conference. Then to Atom/Chlorine when that appeared — and I really liked being able to jettison nREPL and the CIDER middleware and use just a Socket REPL with zero dependencies. And finally I switched to VS Code/Clover once the Chlorine maintainer had ported the cljs-based configuration over to Clover. For me, being able to use just a plain old Socket REPL in any process — local or remote — is a requirement and that means no nREPL-based solutions.

Prabu Rajan17:04:14

Cool. That is a long journey! Does VS Code / Clover support the kind of debugging where you evaluate a function, the debugger recursively takes you to internal function calls, and shows each of the forms getting evaluated and the values being passed in? I will try it out though. Thanks for the recommendation and putting out your journey

seancorfield17:04:52

I’ve never felt the need for that sort of debugger (I don’t think CIDER had that back when I was still using it?).

seancorfield17:04:55

(I prefer very minimal tooling, in general, and like to keep close to raw Clojure — so that I have the exact same UX for developing locally as I do when debugging something remotely)

Prabu Rajan17:04:19

I just tried VSCode Calva with nREPL and the debugging works just as good as Emacs! I tried installing Clover as well, but couldnt figure out the usecase yet. For now, VS Code with Calva is good enough for me. Thanks

seancorfield18:04:22

The use case for Clover is: Socket REPL. If you’re happy using nREPL, Calva is great on its own.

borkdude17:04:20

@jayzawrotny Can I vote for: none of the above? I usually bootstrap new projects just by using mkdir -p src/foo and writing a deps.edn file.

25
Eccentric J17:04:20

I think that falls into other 😛

nate sire21:04:16

@jayzawrotny lately, been using lein new app.... But building a custom scaffolding tool to setup the full stack for web dev.

👍 2