clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
2021-04-17T06:08:26.178Z

Watching this video, what is reified mean:

seancorfield 2021-04-17T06:14:18.178600Z

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

seancorfield 2021-04-17T06:15:09.179600Z

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.

seancorfield 2021-04-17T06:15:40.179800Z

Does that help?

2021-04-17T06:45:26.179900Z

Thanks.

2021-04-17T06:45:57.180700Z

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

raspasov 2021-04-17T08:39:14.180900Z

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

raspasov 2021-04-17T08:39:14.180900Z

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

yuhan 2021-04-17T08:55:19.181700Z

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?

Ben Sless 2021-04-20T05:57:07.297200Z

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

nate sire 2021-04-20T20:08:22.325100Z

@ben.sless nice tip.

1🙏
borkdude 2021-04-17T08:59:34.182500Z

@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

yuhan 2021-04-17T09:15:37.182700Z

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"}}}

borkdude 2021-04-17T09:16:45.182900Z

yes

yuhan 2021-04-17T09:17:12.183100Z

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

yuhan 2021-04-17T09:18:12.183300Z

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

borkdude 2021-04-17T09:18:42.183500Z

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

yuhan 2021-04-17T09:20:07.183700Z

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

borkdude 2021-04-17T09:20:33.183900Z

yes

borkdude 2021-04-17T09:20:38.184100Z

you can already do that

yuhan 2021-04-17T09:25:11.184300Z

oh, you can indeed! Thanks for the help 🙂

Timofey Sitnikov 2021-04-17T10:29:14.184600Z

@vemv, Yes, this is an interesting comment, I do feel the same way. That article made me waver but every developers dream is for their website to go viral. If that happens, and multiple machines need to be spun up, scaling postgres is quick, so it is probably a better choice.

2021-04-17T13:38:13.189300Z

How to change a process’s working directory?

2021-04-17T13:53:36.189400Z

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

2021-04-17T13:54:27.189700Z

Came across this too. Seems no easy way.

roklenarcic 2021-04-17T17:16:04.194Z

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:

roklenarcic 2021-04-17T17:16:44.194200Z

roklenarcic 2021-04-17T17:17:18.194600Z

Seems odd with all the type hints…

p-himik 2021-04-17T17:27:10.194700Z

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.

roklenarcic 2021-04-17T17:34:17.194900Z

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

2021-04-17T17:41:14.197500Z

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

10🅰️13🅱️19🅾️
cassiel 2021-04-19T15:04:18.245700Z

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 🅰️.

nnichols 2021-04-19T16:41:33.253700Z

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)

seancorfield 2021-04-19T17:23:31.255200Z

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

cassiel 2021-04-19T17:31:58.257100Z

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.

seancorfield 2021-04-19T17:43:34.268400Z

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

Prabu Rajan 2021-04-29T16:54:01.278500Z

@seancorfield 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

seancorfield 2021-04-29T17:03:59.279100Z

@prabu.rajan 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 Rajan 2021-04-29T17:14:14.279400Z

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

seancorfield 2021-04-29T17:26:52.280400Z

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?).

seancorfield 2021-04-29T17:27:55.280600Z

(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 Rajan 2021-04-29T17:59:19.286600Z

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

seancorfield 2021-04-29T18:32:22.286900Z

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

Charlie Briggs 2021-04-17T17:41:53.198Z

We're using https://github.com/cookiecutter/cookiecutter

borkdude 2021-04-17T17:49:20.198800Z

@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.

11➕
2021-04-17T17:50:20.199Z

I think that falls into other 😛

borkdude 2021-04-17T17:50:52.199400Z

ok

roklenarcic 2021-04-17T17:56:48.199900Z

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:

roklenarcic 2021-04-17T17:56:54.200100Z

it’s bizarre

p-himik 2021-04-17T18:01:42.200400Z

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-himik 2021-04-17T18:08:23.200700Z

With just

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

roklenarcic 2021-04-17T18:13:30.201Z

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-himik 2021-04-17T18:17:29.201200Z

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

p-himik 2021-04-17T18:32:57.201500Z

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

p-himik 2021-04-17T18:33:17.201700Z

The whole code:

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

p-himik 2021-04-17T18:34:07.202Z

seancorfield 2021-04-17T18:41:06.202700Z

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.

2☝️1
roklenarcic 2021-04-17T19:18:34.203400Z

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-himik 2021-04-17T19:51:43.204100Z

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

roklenarcic 2021-04-17T20:20:02.205Z

Yeah i dont know. I’ll keep looking

nate sire 2021-04-17T21:23:16.205700Z

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

1👍
nate sire 2021-04-17T21:25:32.205800Z

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 ?

yuhan 2021-04-17T22:23:14.206400Z

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.

NoahTheDuke 2021-04-17T23:54:18.207100Z

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