Type resolution improvements TL;DR: the changes in 1.12.3-alpha1 are much appreciated. Background: at my previous job the systems were built in Go and C# but I had a bunch of Clojure code snippets for all sorts of exploratory, debugging and load testing tasks. To run this code I would either run ClojureCLR on an EC2 or as a Kubernetes pod then port-forward so I could then run everything interactively from my editor using an nREPL plugin. That was my set up. Basically a csproj with a bunch of useful packages and a Program.cs stub to basically RT.Init() and start nrepl. Problem: where I got stuck was my (ns foo (:import Bar.Baz)) would fail with an "Object reference not set to an instance of an object" until I ran (assembly-load "Bar"). It was awkward and I never felt comfortable sharing this workflow with my other colleagues because it just felt a bit clunky. Solution: now with my csproj updated to use the latest alpha I can just eval (ns ...) and it works first time thanks to the new type resolution changes and it is a much better first-time experience. Here is what one of my files looked like. Previously I would eval the (ns ..), uncomment the (assembly-load ...) bits, eval them, comment them out again, then continue eval the forms thereafter. Now I can just remove all that (assembly-load ...) stuff and forget about it.
(ns com.employer.project.fixedrate3
(:use clojure.repl clojure.pprint)
(:require [clojure.walk :as walk]
[clojure.string :as string]
[clojure.clr.shell :as shell]
[ :as io])
(:import [ Path IOException]
[System.Net.Http HttpClient SocketsHttpHandler]
[System.Text Encoding]
[System.Text.Json JsonDocument JsonDocumentOptions]
[System.Security.Cryptography SHA256]
[System.Diagnostics Process]))
;(assembly-load "System.Net.Http")
;(assembly-load "System.Web.HttpUtility")
;(assembly-load "System.Text.Json")
;(assembly-load "System.Collections")
;(assembly-load "System.Collections.Concurrent")
;(assembly-load "System.Threading.Channels")
;(assembly-load "System.Threading.Tasks")
;(assembly-load "System.Security.Cryptography")
(defn sha256 [s]
(SHA256/HashData (.GetBytes Encoding/UTF8 s)))
(defn urlsafe-base64-encode [bs]
(-> bs
(Convert/ToBase64String)
(string/replace "+" "-")
(string/replace "/" "_")))
(defn urn->hash [imageUrn]
(if (string/starts-with? imageUrn "urn:)
imageUrn
(-> imageUrn
sha256
urlsafe-base64-encode
(string/replace "=" ""))))
(defn utf8bytes->string [bs]
(.GetString Encoding/UTF8 bs 0 (.Length bs)))
(defn fix-padding [s]
(let [n (count s)]
(.PadRight s (+ n (mod (- n) 4)) \=))) There's also Glojure if you want to replace all of it
Thanks for sharing! Anyway I'm at a new job as of this week and it's C# 100%.
Thanks for the example. That's outstanding.