clr

dmiller 2024-11-26T16:16:32.931739Z

We are limited to what System.IO.TextReader supplies. The closest would be Peek -- I'm pretty sure that blocks. (And I just noticed a bug in the Peek implementation on clojure.lang.PushbackTextReader -- that's been sitting there for 15 years. Sigh. Next alpha.) In the REPL, that is all in clojure.main/main -- all reads are from *in* . The default binding for that is

new clojure.lang.LineNumberingTextReader(new StreamReader(System.Console.OpenStandardInput()))
Perhaps someone else has an approach to this.

2024-11-26T22:14:19.117459Z

This is helpful. I'll dig into this and try to find something that does what I need. Trying to avoid having a separate read thread, but that may be what I need to do.

dmiller 2024-11-27T05:39:00.311509Z

NetworkStream has DataAvailable. The Console directly has KeyAvailable. None of this will help in the general case. The number of times this has been asked on SO and similar places is ... lots. Sample: https://stackoverflow.com/questions/44989149/non-blocking-read-of-a-byte-from-stdin The only general solutions I've found so far involve spinning up a thread. Good luck.

2024-11-26T00:41:02.252199Z

The Clojure JVM repl has a .ready function on *in* (a LineNumberingPushbackReader)

user=> *in*
#object[clojure.lang.LineNumberingPushbackReader 0x49a64d82 "clojure.lang.LineNumberingPushbackReader@49a64d82"]
user=> (.ready *in*)
false 
However, Clojure CLR does not have a .ready -like function
user=> *in* 
#object[LineNumberingTextReader 0xa0747b "clojure.lang.LineNumberingTextReader"]
user=> (.Ready *in*)
Execution error (MissingMethodException) at System.Diagnostics.StackFrame/CallSite.Target (NO_FILE:0).
Cannot find instance field/property/member name Ready
Looking at the https://github.com/clojure/clojure-clr/blob/a281e4ac7ea26b4b99598ed81374d427e05cc7aa/Clojure/Clojure/Readers/LineNumberingTextReader.cs class (and who it inherits from), I don’t see any way to tell whether or not the reader has anything to read without calling .Read (blocking the calling thread). Two Questions: 1. Am I missing something? Is there a ready-like function here? 2. If not, how can this be achieved? What type of TextReader is passed into LineNumberingTextReader’s constructor in the cljr repl?