Fork me on GitHub
#clr
<
2023-05-21
>
seancorfield17:05:30

Before I get started, has anyone else tried to port Cognitect's test-runner to work with the CLR stuff? It only depends on tools.namespace and tools.cli, both of which have been ported, and it only seems to have a couple of JVM-isms in it: .startsWith (which could/should be clojure.string/starts-with? for portability) and a couple of calls to (System/exit zero-or-one) -- what would be the CLR equivalent there?

seancorfield17:05:34

(Environment/Exit zero-or-one) -- thanks BingAI šŸ™‚

djblue20:05:28

When porting Portal to the CLR, I also had to do a bunch of searching to find jvm equivalents šŸ˜† https://github.com/djblue/portal/blob/master/src/portal/runtime/fs.cljc might be a useful reference for other things you might run into šŸ‘Œ

dmiller20:05:22

I had not yet publicized it. Not sure what its permanent home should be. It's not one of the 'official' clojure libraries, so a home in http://github.com/clojure/ with the official ports of official libraries seems not appropriate.

dmiller20:05:22

Whoops, forgot to push my changes up. Eventually need to update the deps.edn to use git coords instead of :mvn.

seancorfield20:05:19

I will take a look at your repo but if the changes are small, I wonder if the core team will take a PR to reduce forking?

seancorfield21:05:43

I would make both files .cljc and use reader conditionals, but those are pretty small differences to get things working. Plus changing :mvn/version deps to git deps. I'll talk to Alex and see how open they are to taking changes on that...

seancorfield21:05:56

@U45FQSBF1 The cljr.tools.namespace dep would need to be different between the versions, right? It would need an override since there's no possible git dep for clojure.tools.namespace it could use...

seancorfield21:05:01

I'll mention to Alex about the transitive alias issue in this context... like I say, if the CLR version of tools.deps had a bit of magic in it to apply a :clr alias (or something similar) transitively, that would solve a lot of the overriding.

djblue21:05:12

I ran into this issue with clojure/data.json. The jvm and clr libs are different but I can't currently express that in my deps.edn.

seancorfield21:05:15

The ideal situation would be for Contrib libs to be portable across Clojure/Script/CLR to some degree -- but the deps.edn issue has to be solved first for that.

seancorfield21:05:05

Obvs not all of them can be portable, but I suspect a lot of the "pure" ones could be.

šŸ’Æ 1
dmiller21:05:13

Except it's not really a core team thing. Sits under cognitect-labs rahter than clojure. At any rate, I did mention it in an email that direction on Saturday. It definitely should be converted to .cljc and conditionalized. That's what I've been doing lately. Don't know why I didn't do that here. I'll fix that and update later today. Yes, the dep for tools.namespace would have to be different. Unless, of course, they would also accept a conditionalized version of tools.namespace and tools. reader. When I did the original ports, conditionalization didn't exist. It wouldn't be hard to bring it into a shared library. But, again, I'm not sure there is interest in that.

seancorfield21:05:58

Yeah, it would be a good discussion to have with Alex and the core team.

dmiller21:05:05

[Sorry, getting out of sync with all this dialog]

seancorfield21:05:31

I noticed in tools.cli for instance that :cljr has Exception where :clj has Throwable -- but it would probably be better for :clj to use Exception -- and there has been talk in the ClojureScript world of adding Exception as an alias for :default which they currently use. Stuff like that would make portable code easier to write in general.

šŸ’Æ 1
seancorfield21:05:29

(this would allow for the :default reader case to be used where :clj and :cljr are actually in alignment)

dmiller21:05:49

There are so many simple things that drive me crazy while porting. I've done them so many times. The banes of my porting work: I/O, threading, networking. The models across the VMs are too dissimilar to come up with a common mechanism, I'm afraid. But even coding to isolate certain operations as functions that could be defined conditionally would reduce the burden. In this latest burst of porting activity, I've done that in a few places when I just couldn't take it anymore.

seancorfield21:05:47

I noticed in tools.namespace there was io/dir-info vs io/file in a couple of places -- I assume that's due to a different model underpinning the two VM environments?

dmiller21:05:46

The I/O model difference raises its head even in the interfaces libraries, and . The models are just too different. io/file is one example. The CLR has System.IO.FileInfo and System.IO.DirectoryInfo (both based on the abstract class System.IO.FileSystemInfo ). To give one example that drove me up the wall recently: java.io.File allows relative files, and that fact is used in tools.deps. The classes are always absolute paths. I'm actually not sure yet I got the changes right in tools.deps -- still testing.

seancorfield21:05:18

When I see this in a repo, how exactly is it meant to be invoked?

PM> Install-Package clojure.tools.nrepl -Version 0.1.0-alpha1
It's not plain Powershell, right? I get this error trying it in PS:
Install-Package: A parameter cannot be found that matches parameter name 'Version'.

seancorfield21:05:49

The other thing I ran into and don't know enough about the ecosystem to even begin debugging:

PowerShell 7.3.4
PS C:\Users\seanc> cd .\clojure\
PS C:\Users\seanc\clojure> Installāˆ’PackageProvider āˆ’Name Nuget āˆ’Force
Installāˆ’PackageProvider: The term 'Installāˆ’PackageProvider' is not recognized as a name of a cmdlet, function, script file, or executable program.
My original PS install was 5.1 so I installed 7.3.4 and ran that, thinking it might make those extra commands available... šŸ˜ž

dmiller21:05:12

I messed up some of the original READMEs. Those are commands for the Package Management console in Visual Studio. Which is where I spend most of my time. (https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-powershell) How you get the Install-Package cmdlet for standalone use in Powershell -- I'm not sure. I need to come up with a more general recipe. Any thoughts on that welcomed. Once I get the deps.edn tooling up, (I think) my recommendation will be to use :git coords for clojure projects, and pull in the nuget package if you are doing C#/F# work.

dmiller22:05:55

I have Install-Package running (did require nuget installation), but it can't find anything.

seancorfield22:05:22

OK, so dotnet add package clojure.tools.nrepl -v 0.1.0-alpha1 would be a close equivalent?

dmiller22:05:13

There's the rub. The dotnet package commands are mostly to modify projects. That command will add or update a package reference in a project file. You then would let the build tools pick up that reference and pull down the package for you. https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-add-package

seancorfield22:05:26

And I need a "project file" of some sort -- I can't just run that in any old folder. But Install-Package could be?

seancorfield22:05:04

PS C:\Users\seanc\clojure> Install-Package clojure.tools.nrepl
Install-Package: No match was found for the specified search criteria and package name 'clojure.tools.nrepl'. Try Get-PackageSource to see all available registered package sources.
PS C:\Users\seanc\clojure> Get-PackageSource

Name                             ProviderName     IsTrusted  Location
----                             ------------     ---------  --------
                        NuGet            False      ā€¦
PSGallery                        PowerShellGet    False      .ā€¦
My lack of familiarity with the ecosystem is blocking me here...

dmiller22:05:43

For working with nuget directly in powershell, look here: https://learn.microsoft.com/en-us/powershell/module/packagemanagement/?view=powershellget-2.x It helps to read the docs. For example, --Version is for the VS command console, one needs -RequiredVersion in PS. But I still can't get it to find clojure.tools.nrepl

PS C:\Users\dmill> Find-Package -Name clojure.tools.nrepl -AllowPrereleaseVersions -AllVersions
Find-Package : No match was found for the specified search criteria and package name 'clojure.tools.nrepl'. Try Get-PackageSource to see all available registered 
package sources.
At line:1 char:1
+ Find-Package -Name clojure.tools.nrepl -AllowPrereleaseVersions -AllV ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPackage) [Find-Package], Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage
 

seancorfield22:05:57

I read a lot of MS docs around this but there seemed to be so many caveats around versions of tools that I couldn't tell what was what. Thanks for the -RequiredVersion pointer tho'

dmiller22:05:43

And -AllowPrereleaseVersions But I'm still not finding it.

dmiller22:05:10

Or anything. I just looked for one of Microsoft's packages -- not found.

seancorfield22:05:17

OK, that makes me feel better about my Powershell ineptitude šŸ™‚

seancorfield22:05:21

clojure.tools.namespace seems to work tho':

PS C:\Users\seanc\clojure> Install-Package clojure.tools.nrepl -RequiredVersion 0.1.0-alpha1
Install-Package: No match was found for the specified search criteria and package name 'clojure.tools.nrepl'. Try Get-PackageSource to see all available registered package sources.
PS C:\Users\seanc\clojure> Install-Package clojure.tools.namespace

The package(s) come(s) from a package source that is not marked as trusted.
Are you sure you want to install software from ''?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"):      

dmiller00:05:51

Not working for me. Can you do Get-PackageSource and tell me what you see? (that's the only thing it recommends checking.)

seancorfield00:05:03

No longer at a computer. I can check tomorrow.

dmiller00:05:38

Turns out my Terminal install was defaulting to an old version of Powershell (5). Seems to find it okay under v7.

seancorfield00:05:59

Ah, that's the problem I ran into - and tried to solve by installing PS 7.x:grin:

dmiller02:05:33

Install-Package clojure.tools.nrepl -RequiredVersion 0.1.0-alpha1 -AllowPrereleaseVersions worked for me but only when I started Powershell as administrator. If not admin, it fails.

seancorfield18:05:28

On both PS 5.1 and 7.3.4:

PS C:\Users\seanc> Get-PackageSource

Name                             ProviderName     IsTrusted  Location
----                             ------------     ---------  --------
                        NuGet            False      ...
PSGallery                        PowerShellGet    False      ...

seancorfield23:05:24

I've made an initial attempt at ClojureCLR compatibility for HoneySQL https://github.com/seancorfield/honeysql/commit/84a41cba7d4d1ef38ee2aa53e9f22a0f8215412f -- if anyone feels like helping test it with ClojureCLR and provide feedback, I'd appreciate that. I haven't figured out how to actually run tests on the CLR side of things yet (I haven't even tried the above with Clojure.Main yet!).

seancorfield23:05:52

Yay! Basic HoneySQL works with the CLR:

PS Microsoft.PowerShell.Core\FileSystem::\\wsl.localhost\Ubuntu-20.04\home\sean\oss\honeysql> $Env:CLOJURE_LOAD_PATH='src'; Clojure.Main
Clojure 1.12.0-alpha7
user=> (require 'honey.sql)
nil
user=> (honey.sql/format {:select :* :from :table :where [:= :id 1]})
["SELECT * FROM table WHERE id = ?" 1]
user=>

šŸŽ‰ 8
šŸÆ 4
šŸ”„ 4
grav04:05:51

Very nice! On the topic of portability, what's the catch (no pun) of using Exception instead of Throwable in JVM? I guess it won't catch Error, right? Is that something one would usually do/avoid doing?

seancorfield05:05:25

Yeah, catching Error is a bit of a code smell, because of what it represents, and so catching Throwable is also a code smell.

šŸ‘ 2
seancorfield23:05:52

Yay! Basic HoneySQL works with the CLR:

PS Microsoft.PowerShell.Core\FileSystem::\\wsl.localhost\Ubuntu-20.04\home\sean\oss\honeysql> $Env:CLOJURE_LOAD_PATH='src'; Clojure.Main
Clojure 1.12.0-alpha7
user=> (require 'honey.sql)
nil
user=> (honey.sql/format {:select :* :from :table :where [:= :id 1]})
["SELECT * FROM table WHERE id = ?" 1]
user=>

šŸŽ‰ 8
šŸÆ 4
šŸ”„ 4