clr

dmiller 2024-12-22T06:15:12.319619Z

For ClojureCLR.Next, I decided I needed a break from implementing persistent, immutable collections. So I tackled [Refs](https://clojure.org/reference/refs). When I did the original version for ClojureCLR, it was a fairly direct porting job from Java to C#, meaning that a deep understanding of the code was not required. At the end, it seemed work. However, one of the goals in ClojureCLR.Next is no line of code unexamined. So I decided to really dig into the Java/C# code and make sure I knew the intent of every single line of code. That turned out to be quite a challenge. We are dealing with multi-threading, expected high amounts of resource contention requiring retrying code execution, locking strategies, and control flow via exception throwing. How hard could it be? Well, toss in a few really clever coding tricks that require a lot of thought to figure out. At one point, I discovered one of my working assumptions, regarding the how long some locks were being held, was just wrong. And I found out that there was observable consequences of that specific bit of lock management -- which I stumbled on in the documentation for ensure, where a comment at the bottom directed me to issue [CLJ-2301 - ensure can cause livelock](https://clojure.atlassian.net/jira/software/c/projects/CLJ/issues/CLJ-2301). That was enlightening. At any rate, I wrote it up, mostly for the benefit of future me. I do not ever want to have figure all this out again. This is not for the faint-hearted. In fact, I doubt it is for anyone other than future me. But if you manage to get through even a quarter of it, drop me a line. I'm reminded of a turn of phrase from a quite good professor I had in graduate school. After going through a hard proof and turning around to look at our blank stares, he'd say "well, that was a flash of darkness." Here is a flash of darkness. For the holidays. [Part 1: STM in Clojure - Design](https://dmiller.github.io/clojure-clr-next/general/2024/12/22/STM-design.html) [Part 2: STM in Clojure - Code](https://dmiller.github.io/clojure-clr-next/general/2024/12/22/STM-code.html) [Part 3: STM in Clojure -Testing](https://dmiller.github.io/clojure-clr-next/general/2024/12/22/STM-testing.html)

💯 4
1
1
dmiller 2024-12-22T14:15:29.381169Z

Just to be clear, my comments about the code should not be construed as negative. The original code is fantastic. Beyond my capability to write, likely. Within my ability to understand, barely. (I'm not terribly skilled in dealing with this kind of problem.)

djblue 2024-12-22T19:27:34.887549Z

I'm trying to run https://github.com/clojure/clr.core.cli using SDK Version: 6.0.136 on WSL and I am getting the following error:

% cljr
Execution error (FileNotFoundException) at System.Diagnostics.StackFrame/ (NO_FILE:0).
Could not locate clojure.tools.deps.util.concurrent.clj.dll, clojure.tools.deps.util.concurrent.cljc.dll, clojure/tools/deps/util/concurrent.clj or clojure/tools/deps/util/concurrent.cljc on load path.
I did notice that this namespace does exist https://github.com/clojure/clr.core.cli/blob/main/src/dotnet/Cljr/clojure/tools/deps/util/concurrent.cljr but ends in .cljr and maybe that's the issue?

2024-12-22T21:16:06.203069Z

I think you need Clojure.Main >= 1.12.0-alpha10 dotnet tool install clojure.main --version 1.12.0-alpha10

🙌 1
djblue 2024-12-22T21:16:17.901969Z

I just figured this out and was about to post 😂

👍 1