clr

djblue 2023-01-10T05:15:29.578059Z

Anyone have any ideas why I wouldn't be able to use the https://learn.microsoft.com/en-us/dotnet/api/system.arraysegment-1?view=net-6.0 struct, here is what I get when I try:

% clojure.main
Clojure 1.11.0
user=> System.ArraySegment
Syntax error (TypeNotFoundException) compiling at (REPL:0:0).
Unable to find type: System.ArraySegment
user=> (import 'System.ArraySegment)
Bad type
Execution error (NullReferenceException) at System.Diagnostics.StackFrame/NameForType (C:\work\clojure-clr\Clojure\Clojure\Lib\Util.cs:768).
Object reference not set to an instance of an object.
user=>

djblue 2023-01-10T08:40:42.006839Z

Ended going with

(defmacro array-segment [& args]
  `(new ~(RT/classForName "System.ArraySegment`1[System.Byte]") ~@args))
To make linters and formatters happy 👌

1
dmiller 2023-01-10T14:24:44.507399Z

yes, generic types strike again. As you noted, |System.ArraySegment`1[System.Byte]| does the job. But I'll concede it is ugly. I'd like to fix this. I originally added the |...| convention, stolen/modified from Common Lisp, just to handle type references for generics. The ungainly syntax for typenames is of course the internal .NET naming convention, not the prettified syntax that you see in C# and F#. I'm not sure there syntax is the exact thing we need, but something along those lines. Some conversation on this would be welcome. (Could be here, or I could start a conversation over on the repo.)

👍 2
bobcalco 2023-01-10T14:33:16.660669Z

@dmiller Let's definitely find someplace to have that discussion. It's probably at the repo so the topic can be easily searched/found (things go down the memory hole here).

dmiller 2023-01-10T15:14:21.939059Z

Agreed. I don't have 'settings' privileges for the ClojureCLR repo, so I'll have to ask to turn on Discussions.

👍 2
Emma Griffin (OST) 2023-01-10T15:30:03.198599Z

Discussions would be great

✅ 1
djblue 2023-01-10T20:29:21.289469Z

Outside of this and my lack of understanding of dependencies, ClojureCLR has been a joy to use, thanks for all the hard work! I'm almost done porting https://github.com/djblue/portal and am very interested in the current dependency management discussions.

❤️ 1
🎉 1
djblue 2023-01-10T05:37:48.437339Z

Ohh, I ran

(->> (.GetAssemblies System.AppDomain/CurrentDomain)
       (mapcat #(.GetTypes %))
       (map str)
       (filter #(clojure.string/includes? % "ArraySegment")))
And got back
("System.ArraySegment`1[T]" "System.ArraySegment`1+Enumerator[T]")
I guess I need to do something like
(new |System.ArraySegment`1[System.Byte]| bytes)
🤔

🤔 1
Anders Eknert 2023-01-11T14:24:40.995469Z

@djblue awesome! 😃