Create overloaded operator as infix

2022-02-23 Thread mardiyah
How to have overloaded operator, infix operator with two operands ? e.g `m .= n()` to mean `m = m.n()` on: std/nre template `.=`(a :var string; b :proc()) = a = a.b var p="hello world" p .= replace(re"\w+", "masked") echo p R

Must check to decide whether this current iteration in a loop is the last

2022-02-23 Thread xioren
Minor nit picky changes: for idx, item in mySeq: if idx == mySeq.high: echo "last" Run

Can Nim be made more "purely functional""...

2022-02-23 Thread Araq
> Haven't followed the rest of the discussion but just read this and wanted to > chime in. It's such a broad and odd statement. Yeah, well, read the full discussion then. I used the word in the context that I tried to setup. They are all "pretty bad" because they neglect the "essence" of progra

Must check to decide whether this current iteration in a loop is the last

2022-02-23 Thread PMunch
This came up in a recent PR, is there any reason why you're calling `items` explicitly?

Must check to decide whether this current iteration in a loop is the last

2022-02-23 Thread Araq
Use this logic to see if you need to insert a seperator: result = "" var i = 0 for it in items(collection): if i > 0: result.add ", " result.add $it inc i Run You almost never need to know if it's the "last" iteration, the "first" iteration su

Calling nim-server-code from javascript

2022-02-23 Thread PMunch
Why are you so insistant on using cookies for this? It really isn't a good way of doing it. Cookies are intended to persist, so by their very design is a poor choice for something you would like to have happen once. I assume Neel uses websockets or something similar, a technology actually intend

Calling nim-server-code from javascript

2022-02-23 Thread Hobbyman
@ Niminem. It is an interesting framework but I have my own little framework :-) I would like to hear a more elaborate, abstract explanation of how your framework works, as opposed to a recipe for usage, before i invest time in trying in out. I dont see the word cookie mentioned in your code so

Must check to decide whether this current iteration in a loop is the last

2022-02-23 Thread PMunch
Note that you can also use `mySeq.high` which is the highest index, this also means you can do non-zero indexed arrays: var x: array[5..10, int] for i, v in x: echo "x[", i, "] = ", v if i == x.len - 1: echo "Not last :(" if i == x.high: ech

Must check to decide whether this current iteration in a loop is the last

2022-02-23 Thread doofenstein
for an arbitrary iterator that's not possible unless you first save the results of every iteration into a seq. Though say if you iterate about a seq, you can do this: for i, item in pairs mySeq: if i == mySeq.len-1: echo "last" Run or if you iterate over

Must check to decide whether this current iteration in a loop is the last

2022-02-23 Thread mardiyah
How do we, in simplest Nim syntax, check and determine whether this current iteration in a loop is the last one or not ?

AsyncHttpServer running in the background, spawn & closures

2022-02-23 Thread PMunch
Haven't tried with spawn, but the way I run async code within threads is something like this: var thread: Thread[void] proc asyncStuff() {.async.} = proc myThread() {.thread.} = asyncCheck asyncStuff() runForever() createThread(thread, my

Nim 1.6.4 released

2022-02-23 Thread miran
> Can we make sure to include it in the next patch? Yes, I have backported it now and it will be part of the next 1.6 release.

Nim 1.6.4 release candidate

2022-02-23 Thread miran
> I was looking at the changes and I believe these commits should be added in > 1.6 > ... no problem having these fixes in 1.6.6. As promised earlier, these commits are now backported and will be part of the next 1.6 release.

AsyncHttpServer running in the background, spawn & closures

2022-02-23 Thread drkameleon
I have set up an AsyncHttpServer running fine (and blocking everything else): import asyncdispatch, asynchttpserver, threadpool import strformat const port = 18967 proc startServer() {.async.} = var server = newAsyncHttpServer() proc handler(req:

To get the PCRE version by executing Nim

2022-02-23 Thread xbello
import pcre echo PCRE_MAJOR, PCRE_MINOR echo version() Run