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
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.
@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.
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
Does `debugEcho()` rather than `echo()` help?
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)?
@Hlaaftana Yes, I'd just like to omit parenthesis without losing the scope
semantics
@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
Moral of the story, this works:
let a = (block:
echo "hello"
1)
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
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
Here's a related thread:
[https://forum.nim-lang.org/t/2201](https://forum.nim-lang.org/t/2201)
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)
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
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
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
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
)()
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
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
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?
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:
Better yet, use a single seq and iterate over it as if it was NxM. It will be
more cache-friendly.
22 matches
Mail list logo