Array type to boolean type conversion

2022-02-12 Thread ynfle
`bool` is unnecessary

i am just saying a splitted .sendall on socket would be much clear

2022-02-12 Thread haoliang
in my use, i found those apis are a little confusing: 1. send(socket: AsyncSocket; buf: pointer; size: int; flags = {SafeDisconn}): owned( Future[void]) 2. send(socket: AsyncSocket; data: string; flags = {SafeDisconn}): owned( Future[void]) 3. send(socket: Socket; data: pointer; size: int)

after called `AsyncFuture.fail`, the future is still running

2022-02-12 Thread haoliang
> The only way you can cancel operations right now in Nim's async is by closing > the FD they are pending on. i will imprint it in my mind. so it means `.fail` should but do not behave like it claimed `Completes future with error.`. it seems there are some minefields in nim's async, and i can f

after called `AsyncFuture.fail`, the future is still running

2022-02-12 Thread haoliang
thanks for the working implementation. it goes too deep for me. i start to miss python's [trio](https://trio.readthedocs.io/en/stable/reference-core.html#a-simple-timeout-example): with trio.move_on_after(30): result = await do_http_get("https://...";) print("result

after called `AsyncFuture.fail`, the future is still running

2022-02-12 Thread haoliang
thanks for the suggestion; as just starting to learn nim, i did not find time to look into `status-im/*`, but i definitely will. when the interest comes to me, i was thought "just look how simple asyncdispatch.waitFor is, i surely can implement it simply". > That said, even if you cancel someth

Array type to boolean type conversion

2022-02-12 Thread sls1005
bool(len(arr) > 0) Run

Nim FAQ

2022-02-12 Thread demotomohiro
@haoliang @tcheran @bpr Thank you for your feedback! @bpr I will add a section about template later.

Array type to boolean type conversion

2022-02-12 Thread ynfle
`echo [] is bool`

Array type to boolean type conversion

2022-02-12 Thread demotomohiro
`echo [].len == 0`

Array type to boolean type conversion

2022-02-12 Thread mardiyah
How do we convert array to boolean type simplest way ?

after called `AsyncFuture.fail`, the future is still running

2022-02-12 Thread royneary
@dom96: Oh, I see. I think that would require writing a custom `addTimer` that returns the FD though. How about changing `addTimer` to `proc addTimer*(timeout: int, oneshot: bool, cb: Callback): AsyncFD {.discardable.}`? (and making sure `proc unregister(fd: AsyncFD)` handles timer FDs correctl

after called `AsyncFuture.fail`, the future is still running

2022-02-12 Thread dom96
@royneary there are two kinds of timers in asyncdispatch, virtual ones and OS ones. The `addTimer` proc creates the latter:

no operation on Nim syntax

2022-02-12 Thread mardiyah
How to have no operation (NOP famous abbreviation) as I'm noob just thought it is `;` so got Error: expression expected, but found ';' Please help out.

no operation on Nim syntax

2022-02-12 Thread ynfle
I think you're looking for `discard`

after called `AsyncFuture.fail`, the future is still running

2022-02-12 Thread royneary
@dom96: I don't understand how this could work. I don't think there are FDs involved in the timer implementation, at least on posix. To my solution I should add, that it _only_ works on posix systems, not on Windows.

Compressing resulting JS

2022-02-12 Thread dom96
Here is what I use for Stardust.dev's JS: task clientr, "Build JS sources": exec "nimble js -d:client -d:js -d:danger --out:out/client.js client.nim" when defined(linux): # Little hack, replace {val: 0, has: false, val: 0, has: false} exec "sed -i 's/{val:

after called `AsyncFuture.fail`, the future is still running

2022-02-12 Thread dom96
The only way you can cancel operations right now in Nim's async is by closing the FD they are pending on. This might work on the timers created by `addTimer` as well.

after called `AsyncFuture.fail`, the future is still running

2022-02-12 Thread royneary
For the special case of cancelling timers, that is futures returned by `sleepAsync`, I have an implementation. It is a bit hacky though as it manipulates the dispatcher's timer list: proc cancelTimer*(timer: Future[void], error: ref CatchableError) = let dispatcher = getGlobal

after called `AsyncFuture.fail`, the future is still running

2022-02-12 Thread arnetheduck
What you're looking for is cancellation support - you can find it in [chronos](https://github.com/status-im/nim-chronos/blob/87197230779002a2bfa8642f0e2ae07e2349e304/chronos/asyncfutures2.nim#L298), but not in asyncdispatch, last I checked. That said, even if you cancel something, it might run o

Compressing resulting JS

2022-02-12 Thread xigoi

Nim FAQ

2022-02-12 Thread bpr
Please add a section on templates before the section on macros. Outstanding work!

Compressing resulting JS

2022-02-12 Thread SolitudeSF
bad take

Compressing resulting JS

2022-02-12 Thread Hlaaftana
Just these options should give the same JS output as your arguments: --d:danger --mm:orc --overflowChecks:on Run `--checks:off` is implied by `--d:danger`. `--overflowChecks:on` overrides `--d:danger` and decreases performance/increases code size, unless you have a re

Can if statements be used as expressions everywhere?

2022-02-12 Thread Hlaaftana
The [grammar](https://nim-lang.org/docs/manual.html#syntax-grammar) is not structured in a way that supports mixing operators (like `+=`) with `case`/`if`/`block`/`try` etc expressions, so this isn't really a bug as much as unimplemented/not supported. As for the OP, the issue is that the `if`

Can if statements be used as expressions everywhere?

2022-02-12 Thread lscrd
Yes, but, nevertheless, in this case, you have to use parentheses. This is the same thing with an if expression: proc p(b: bool) = var x = if b: 3 else: 4 # Compile. var y = 1 + if b: 3 else: 4 # Doesn’t compile. var z = 1 + (if b: 3 else: 4) # Compile

Nim FAQ

2022-02-12 Thread tcheran
Awesome work. Really appreciated.

Can if statements be used as expressions everywhere?

2022-02-12 Thread AmjadBHD
I'm aware of that. But I think parens shouldn't be needed as that is a case [expression](https://nim-lang.org/docs/manual.html#statements-and-expressions-case-expression).

Compressing resulting JS

2022-02-12 Thread Araq
Live with the additional KBs that are produced and compensate for it by reducing your daily online time by 2 seconds.

Can if statements be used as expressions everywhere?

2022-02-12 Thread AmjadBHD
Yes, it seems like a bug.

Compressing resulting JS

2022-02-12 Thread planetis
You are right most of these don't help. Try:

Compressing resulting JS

2022-02-12 Thread drkameleon
I've been experiment with Nim + JS (not node.js) and wondering how to produce an even more compact, junk-free, final js output. Right now, I'm compiling with: --skipUserCfg:on --skipProjCfg:on --skipParentCfg:on --colors:off --d:danger --panics:off --mm:orc --checks:off --overflowC

dnd - bi-directional drag and drop source/target

2022-02-12 Thread adokitkat
Thanks :) I had to because I have found a bug in gintro and it has been fixed in #HEAD only IFAIK? I can make it dependent on commit tho. What do you mean by adding a nimble task? I wanted to mimic `make install` which also installs a desktop entry (for an icon).

dnd - bi-directional drag and drop source/target

2022-02-12 Thread SolitudeSF
great program. but please, dont depend on `#HEAD`, gintro is regularely tagged, or at least depend on certain commit. also, installing other files from `nimble install` is a bad move, just add nimble task for doing that.

dnd - bi-directional drag and drop source/target

2022-02-12 Thread adokitkat
I also have a question - is there a way to use `before`/`after` hooks in `.nimble` file for `nimble uninstall`? I tried but it doesn't work.

dnd - bi-directional drag and drop source/target

2022-02-12 Thread adokitkat
# dnd Hi! I was working on this project over a few weekends and I think it's finally ready. Maybe some of you can make an use of it. Please leave a feedback - issues, suggestions, etc. :) ## About [dnd](https://github.com/adokitkat/dnd) is a bi-directional drag and drop source/target inspired

Can if statements be used as expressions everywhere?

2022-02-12 Thread auxym
Not sure, but it works if you replace "+=" with ".inc". Might be a bug.

Can if statements be used as expressions everywhere?

2022-02-12 Thread lscrd
You need to use parentheses to turn the case statement into an expression: import std/strutils func score*(word: string): int = for c in word: result += (case toUpperAscii(c) of {'A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T'}: 1 of {'D', '

Nim FAQ

2022-02-12 Thread haoliang
IMHO, if "is x or not" question have a tl;dr answer like yes/no would be great.

Can if statements be used as expressions everywhere?

2022-02-12 Thread AmjadBHD
why does this produce `Error: expression expected, but found 'keyword case'` ? import std/strutils func score*(word: string): int = for c in word: result += case toUpperAscii(c) of {'A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T'}: 1 of {'D'

Nim FAQ

2022-02-12 Thread demotomohiro
I wrote FAQ about Nim: I hope it helps people learning Nim. Let me know if there is something wrong or questions that should be in FAQ.

Problem with winapi in nim

2022-02-12 Thread guibar
According to the [docs](https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getmodulebasenamew), `GetModuleBaseNameW` needs the rights `PROCESS_QUERY_INFORMATION` and `PROCESS_VM_READ`. Plus, as @araq mentionned, you should preallocate the string. Assuming you use winim, this code

Questions about creating dll with Nim

2022-02-12 Thread cblake
Of possible interest is some example code (sorry - not a foundational article) that I have for the run-time user configurable/extensible [lc](https://github.com/c-blake/lc) file lister, in particular [extensions/lcNim.nim](https://github.com/c-blake/lc/blob/master/extensions/lcNim.nim). { The e

Questions about creating dll with Nim

2022-02-12 Thread Prince213
I'd wonder if these information could make their way to the documentation, presumably as a section in the Compiler User Guide. They're currently either missing or scattered in places.

after called `AsyncFuture.fail`, the future is still running

2022-02-12 Thread haoliang
with the interest of cancellation in async , i scratched a simple implentation, just a rewrite of `asyncdispatch.waitFor`. then i encountered some problem: 1. why the `poll()` will `raise exception("An attempt was made to complete a Future more than once.")` 2. why the future is still runnin