Fork me on GitHub
#clr
<
2023-01-10
>
djblue05:01:29

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=>

djblue05:01:48

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)
:thinking_face:

2
djblue08:01:42

Ended going with

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

wow 2
dmiller14:01:44

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

👍 4
bobcalco14:01:16

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

dmiller15:01:21

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

👍 4
Emma Griffin15:01:03

Discussions would be great

2
djblue20:01:21

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.

❤️ 2
🎉 2