Re: How to call runForever()?

2018-01-27 Thread monster
Windows 10, x64 Microsoft Windows [Version 10.0.16299.192] (c) 2017 Microsoft Corporation. All rights reserved. C:\Users\Sebastien Diot>nim --version Nim Compiler Version 0.17.2 (2017-09-07) [Windows: amd64] Copyright (c) 2006-2017 by Andreas Rumpf git

Re: How to call runForever()?

2018-01-27 Thread dom96
Thanks for reproducing. It doesn't crash for me (macOS), what OS are you on and what Nim version are you using? btw, the `: void` is redundant for proc return types.

Re: A

2018-01-27 Thread monster
@jlp765 I believe it is an issue with how I call "runForever()". I can even reproduce the problem, as defined in my next forum thread. I now tried debugEcho() too. It makes no difference.

Re: How to call runForever()?

2018-01-27 Thread monster
I think I can. I'm not sure if it is the same problem as in my main module, but this crashes for me: import asyncdispatch import os proc runForeverThread() {.thread.} = ## Executes runForever() in a separate thread. runForever() proc

Re: A

2018-01-27 Thread jlp765
Does `debugEcho()` rather than `echo()` help?

Re: How to call runForever()?

2018-01-27 Thread dom96
Can you reproduce the crashes in a simple program that creates a new thread that calls `runForever` (and does nothing else except waiting for that thread)?

Re: block expression

2018-01-27 Thread woggioni
@Hlaaftana Yes, I'd just like to omit parenthesis without losing the scope semantics

Re: How to call runForever()?

2018-01-27 Thread monster
@Hlaaftana Thanks. That was rather "obscure"; I wouldn't have thought there were two versions of createThread(). Unfortunately, I changed the code as you suggested, and it does not make the crash go away. I think there is a single example of calling runForever() in the documentation. It is

Re: block expression

2018-01-27 Thread Hlaaftana
Moral of the story, this works: let a = (block: echo "hello" 1)

Re: How to call runForever()?

2018-01-27 Thread Hlaaftana
Adding [void] to createThread makes it call [this proc](https://nim-lang.org/docs/threads.html#createThread,Thread\[TArg\],proc\(TArg\),TArg), which needs an argument to supply to the proc. However, you should be calling [this

How to call runForever()?

2018-01-27 Thread monster
In a previous post today, I mentionned I got "unexplanable" crashes, that were not always reproducible. It turn out, the crashes seem to be caused by runForever(). I have async code in a single module, the same one where I call runForever(). If I comment out the code calling runForever(), the

Re: block expression

2018-01-27 Thread jcosborn
Here's a related thread: [https://forum.nim-lang.org/t/2201](https://forum.nim-lang.org/t/2201)

Re: block expression

2018-01-27 Thread woggioni
I also noticed another problem let a = (proc() : auto = let b = 4 6 )() echo b this clearly does not compiles since d is accessed from an outer scope. This one should be the equivalent written with templates: template bxpr(body : typed)

Re: A

2018-01-27 Thread monster
Thanks for the reply. I've made some progress. Compiling and running the same code multiple times doesn't always result in the same output. I now suspect it might be a "timing" thing; depending on how fast the program crashes, the stdout might be flushed, or not, to the terminal. Looks like

Re: A "future" LOC affects a "past" LOC!

2018-01-27 Thread dom96
I've run into things like this in the past and the reason for them usually is a stack corruption. Unfortunately I don't have any magic ways to debug this. I can see that you're using raw pointers so it's likely that you're doing something unsafe incorrectly, so I would start by carefully

Re: block expression

2018-01-27 Thread woggioni
I'll answer my own question.. It seems that I just forgot to specify the template return type: template scope(body : typed) : auto = (proc() : auto = body) () let a = scope: echo "hello" 1 this works fine. There are some things that are not very clear

block expression

2018-01-27 Thread woggioni
It would be really nice to be able to write something like this let a = block: echo "hello" 1 but this does not compile because block is a statement a trivial workaround is let a = (proc() : auto = echo "hello" 1 )()

Re: Thoughts on imports

2018-01-27 Thread GULPF
It might look useful for simple cases, but what happens when you want to import an operator? Or if you want to import a hash procedure that the `tables` module should have access to? Using a macro like that will just be an uphill battle and shouldn't be encouraged. The "import everything into

Re: Thoughts on imports

2018-01-27 Thread matkuki
This is a great macro you made **@Libman**: macro load*(modulesSeq: varargs[untyped]): untyped = result = newStmtList() for module in modulesSeq: result.add parseStmt("from " & $module & " import nil") # Usage example load os, math

Re: Making a Matrix

2018-01-27 Thread solo989
Thanks for the help. I had no idea the solution was that simple. Is declaring W and H as static automatically turn them into type parameters?

Re: Making a Matrix

2018-01-27 Thread GULPF
This works: type Matrix[width, height: static[int], T] = object data: array[width * height, T] var m : Matrix[5, 6, int] echo m.width # 5 If you dislike using real names for the type parameters you can also just add getter procs for them:

Re: How to pass a int to a matrix like: Matrix[W,H:static[int]] ?

2018-01-27 Thread Udiknedormin
Better yet, use a single seq and iterate over it as if it was NxM. It will be more cache-friendly.