clr

2024-10-13T17:56:22.538429Z

Hello! I’m trying to get started with ClojureCLR with a simple "Hello World" program, but am having trouble finding resources to get a ClojureCLR project up and running. Can anyone point me to a resource or example project for this? Compile/run commands would be helpful as well.

2024-10-13T18:44:15.981699Z

I think I found a working solution, using https://github.com/anderseknert/ring-clr as an example (thank you). Still, a couple significant differences between Clojure JVM: • No deps.edn – Looks like this is what https://github.com/clojure/clr.core.cli aims to solve? • The cljr file extension isn’t recognized by Clojure.Main – still trying to figure out how this was achieved in ring-clr.

seancorfield 2024-10-13T18:56:53.778309Z

There's a cljr command-line tool that supports deps-cljr.edn and deps.edn (EDN has no reader conditionals so if you need different deps, you have to have different files).

seancorfield 2024-10-13T19:00:13.285159Z

Unfortunately, I don't remember how/where I installed cljr and can't find docs for it in the repos.

seancorfield 2024-10-13T19:01:05.746499Z

Ah, I scrolled back to May here and found the command to install it:

dotnet tool install --global Clojure.Cljr --version 0.1.0-alpha2

seancorfield 2024-10-13T19:03:07.486889Z

PS C:\Users\seanc\clojure\clojure-clr-starter> cat .\deps.edn
{:paths ["src"]
 :aliases {:dev {:extra-paths ["dev"]
                 :extra-deps {org.clojure.clr/tools.nrepl {:mvn/version "0.1.0-alpha1"}}}}}
PS C:\Users\seanc\clojure\clojure-clr-starter> cat .\src\starter\hello.cljr
(ns starter.hello
  (:require [starter.utils :as utils]))

(defn hello-world []
  (println "Hello, World!"))

(defn -main [& args]
  (hello-world)
  (println (utils/square 5)))
PS C:\Users\seanc\clojure\clojure-clr-starter> cljr -M -m starter.hello
Starting main
Hello, World!
25
PS C:\Users\seanc\clojure\clojure-clr-starter>

seancorfield 2024-10-13T19:03:25.576279Z

So there's basic nREPL support as well.

seancorfield 2024-10-13T19:03:45.158259Z

Still early days with the command-line stuff.

seancorfield 2024-10-13T19:04:22.795829Z

and

PS C:\Users\seanc\clojure\clojure-clr-starter> cat .\src\starter\utils.cljr
(ns starter.utils)

(defn square [x]
  (* x x))
Just to show multiple nses.

seancorfield 2024-10-13T19:05:26.296729Z

And here are my versions (of Clojure.Main and cljr):

PS C:\Users\seanc\clojure\clojure-clr-starter> cljr
Starting main
Clojure 1.12.0-alpha9
user=> ^Z

PS C:\Users\seanc\clojure\clojure-clr-starter> cljr -version
ClojureCLR CLI Version: 0.1.0.0

2024-10-13T19:39:12.038209Z

This is awesome–feels way more like the traditional clojure process. Thank you!

dmiller 2024-10-15T21:44:39.860099Z

A slight correction on the .edn conditionalization file: the file cljr looks for first is deps-clr.edn:

However, we cannot just read-conditionalization the deps.edn file because read-conditionalization is not supported in EDN files. The workaround is that cljr will look for a file named deps-clr.edn first, then look for deps.edn. This provides an override that cljr can see and the JVM tools will ignore.
As you work with it, observations/comments/suggestions are welcome. (I'm especially interested in the items mentioned under [Things that need work](https://github.com/clojure/clr.core.cli?tab=readme-ov-file#things-that-need-work).