Re: Reading a file line by line at compile time
Like this: import strutils macro r: untyped = for l in "input".slurp.splitLines: # process a line echo l r() Run
Reading a file line by line at compile time
Is there a way to read a file line by line at compile time? My use case is that I want to process an input file and produce Nim code via macros, but have no trace of the input file in the resulting binary. Basically, I just want to iterate over the lines and throw them away after the VM has read them.
Re: How to add a symbol to represent the infinity (∞)
@cblake \- thank you for commenting! I didn't like that exactness for `inf(0)` too, but wanted to respond with that before this thread gets into oblivion. I put there a new version, which is [YetMoreFun](https://github.com/Leu-Gim/Nim-modules/blob/master/yetmorefun.nim) and more in line with your considerations. I'll take a look at Riemann Sphere when I'll get some time, sounds as smth interesting. :)
Server-sent events in Jester
I'm trying to do [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) in Jester. What I have now is this: router index: get "/time": let data = "retry: 3000\n" & "data: {time: \'" & getClockStr() & "\'} \n\n" resp(data, "text/event-stream") Run It's working because browser is reconnecting every 3 seconds and getting new data. But in principle, the server is supposed to keep the existing connection open and send more data through it. I've found some code that does exactly what I want in [alltest.nim](https://github.com/dom96/jester/blob/5a54b5e2cc0b6b7405536fdd79b65aa133cac6c8/tests/alltest.nim#L79), but the `response` is undeclared in this context. # get "/live": # await response.sendHeaders() # for i in 0 .. 10: # await response.send("The number is: " & $i & "") # await sleepAsync(1000) # response.client.close() Run Is there any way to get `response` object inside `route`? Or is there another approach?
[RFC] Project Picasso - A multithreading runtime for Nim
> _" Good artists borrow, great artists steal." \-- Pablo Picasso_ I have put together a document that lay out the various blocks needed for an efficient multithreading runtime. You can have a (long) read here: [https://github.com/nim-lang/RFCs/issues/160](https://github.com/nim-lang/RFCs/issues/160).
Re: What text editor are you using for Nim?
Probably because there is not a windows version :-)
Re: How to add a symbol to represent the infinity (∞)
@LeuGim \- nicely done & interesting approach! I'm not sure I would have embued `inf(0)|Infinite(0)` with as precise semantics in your `for 3 .. inf(0): ...` construction. Infinity is more a process than a number. For `∞ - ∞ ~ inf(0)` to act like zero the two limiting processes have to precisely cancel out. In some abstract sense, that's much less { infinitely less? :-) } likely than being lopsided and the result being more like either `-∞` or `+∞`. Without more context there's not enough to know which (or zero). So, being undefined is probably a better choice. Also, for triple bonus extra credit along these lines you could try to do the point at infinity in the complex plane/Riemann sphere. ;-) { [https://en.wikipedia.org/wiki/Riemann_sphere](https://en.wikipedia.org/wiki/Riemann_sphere) }
Re: Using a generic type in 'raises' pragma's argument
Thanks for the reply. > For now just drop the {.raises.} annotation, the compiler can compute this on > its own. Yes, it works indeed, thanks a lot. I originally intended to make a lazy version of raiseException like this: import std/sugar proc raiseException* [E: CatchableError](e: () -> ref E; R: typedesc): (proc (): R {.raises: [E].}) = () => raise e() Run But then I ran into the same problem. It is OK though, I can work around it.