What does "new result" inside a proc returning a ref object mean?

2020-03-22 Thread adnan
In this example: import db_sqlite type Database* = ref object db: DbConn proc newDatabase*(filename = "tweeter.db"): Database = new result result.db = open(filename, "", "", "") Run What doe

Re: What does "cannot be captured as it would violate memory safety" mean?

2019-12-12 Thread Araq
You can use `ptr T` instead of `var T` then, but beware, it's unsafe. It's better to do this instead: proc outer(x: var string) = proc inner(x: var string) = x.add "abc" inner(x) var g = "x" outer(g) echo g Run

Re: What does "cannot be captured as it would violate memory safety" mean?

2019-12-11 Thread marks
The variable is sent as a var to a proc where it works fine. But I then in that proc I pass it to another proc and in that one I get the error. I've also tried passing it to the other proc without var (since in that data is only read) but get the same error. Is there an alternative to var that w

Re: What does "cannot be captured as it would violate memory safety" mean?

2019-12-11 Thread mratsim
You are probably trying to use a `var` parameter somewhere you shouldn't like a closure.

What does "cannot be captured as it would violate memory safety" mean?

2019-12-11 Thread marks
In some situations I get the error message _" cannot be captured as it would violate memory safety"_. I understand that this means nim is trying to stop me shooting myself in the foot, but is there anywhere I can read an explanation and if it is possible to do what I want without triggering this

Re: {.gcsafe.}, What does {.threadvar.} do to make a function gcsafe?

2019-12-08 Thread mp035
@kidandcat Yeah, you are right, it's not an error, just a warning, sorry. I'm used to C where a warning usually means I've done something wrong. @mratsim and @rayman22201 thanks for explaining that, it seems like the issue has been thought through, so there's no point raising it.

Re: {.gcsafe.}, What does {.threadvar.} do to make a function gcsafe?

2019-12-07 Thread kidandcat
Anyway you stated you got an error accesing the global variable, if you don't compile your program with --threads:on you will get only a warning and it will compile correctly

Re: {.gcsafe.}, What does {.threadvar.} do to make a function gcsafe?

2019-12-06 Thread rayman22201
As you noted, the stdlib asynchttpserver is not multi-threaded, but httpbeast is multithreaded. But, both libraries use the same core stdlib asyncdispatch (they were written by the same author @dom96). asyncdispatch supports both single threaded and multi-threaded environments. This is why the

Re: {.gcsafe.}, What does {.threadvar.} do to make a function gcsafe?

2019-12-06 Thread mratsim
Sure, it's better to have a discussion. But I think the constraints are not on the asynchttpserver module but directly on asyncdispatch, I may be wrong though

Re: {.gcsafe.}, What does {.threadvar.} do to make a function gcsafe?

2019-12-05 Thread mp035
Thank you @mratsim. I did a lot of research and found an old github issue discussing implementing threads in asynchttpserver. Araq closed it without action noting that httpbeast is available, which is esentially a multithreaded server. Do you think I should file an issue requesting the removal o

Re: {.gcsafe.}, What does {.threadvar.} do to make a function gcsafe?

2019-12-04 Thread mratsim
Iirc the gcsafe requirement was made so that it would not be breaking in the future to make async threadsafe.

Re: {.gcsafe.}, What does {.threadvar.} do to make a function gcsafe?

2019-12-04 Thread mp035
Thank you, that explanation makes sense regarding {.threadvar.} however I am now confused as to why I need to worry about it at all. I am using **async** http server which I am assuming is concurrent (single threaded), so everything should be running in the same thread. This would explain why th

Re: {.gcsafe.}, What does {.threadvar.} do to make a function gcsafe?

2019-12-04 Thread kidandcat
The Threadvar pragma, as its name explains, marks the variable as a thread variable, then each thread you create will have its own copy of that variable, thus, even if you error has dissapeared, you will find that if you modify that variable in your thread A, and you then read it in your thread

{.gcsafe.}, What does {.threadvar.} do to make a function gcsafe?

2019-12-04 Thread mp035
er gc safe. Adding the {.threadvar.} pragma to the global variable fixed the error, but I don't know why. So: 1. How does accessing global variables make a function not gcsafe? 2. What does the threadvar pragma do to fix this? Thanks.

Re: "incRef: interiorPtrTraceback" what does it mean?

2019-11-27 Thread drkameleon
Answering to myself (after, hopefully, having fixed the issue): I was trying to access and change a ref object which was obviously not GC_ref -ed before.

"incRef: interiorPtrTraceback" what does it mean?

2019-11-27 Thread drkameleon
**Compilation options:** -d:debug -d:useSysAssert -d:useGcAssert --debugger:native --stackTrace:on --gc:refc Run **This is what I 'm getting:** [GCASSERT] incRef: interiorPtrTraceback (most recent call last) /Users/drkameleon/Docu

Re: What does the ``.inject.`` pragma do? Where is it defined?

2019-11-04 Thread zevv
Explained in [https://nim-lang.github.io/Nim/manual.html#templates-hygiene-in-templates](https://nim-lang.github.io/Nim/manual.html#templates-hygiene-in-templates) Any variables declared in a template annotated with {.inject.} will be accessible in the scope where the template is called, effecti

What does the ``.inject.`` pragma do? Where is it defined?

2019-11-04 Thread pmags
I see examples in the manual using the `{.inject.}` pragma but the behavior of this pragma doesn't seem to be defined in the manual (or I missed it). Can anyone provide a doc link or a brief explanation? Thanks!

Re: What does the asterisk do after a variable name?

2019-10-03 Thread mratsim
It makes the variable public and importable from other module/files

Re: What does the asterisk do after a variable name?

2019-10-03 Thread girng
Nice. I thought it had to do with pointers, references, etc. I was like omg lol

What does the asterisk do after a variable name?

2019-10-03 Thread girng
Example: var users* {.threadvar.}: seq[string] Run I'm brand new to nim. Just heard about it today and I'm in love with the syntax. I googled but couldn't find anything. I think I read it was something to do with exports, but not sure?

Re: What does asyncCheck do?

2018-10-08 Thread filip
Thanks guys, it all makes sense now.

Re: What does asyncCheck do?

2018-10-08 Thread dom96
Yeah... you've got a while loop that is just calling an async procedure over and over. This is just allocating new futures, the async proc doesn't have a chance to run. If you `await` it, it will run.

Re: What does asyncCheck do?

2018-10-08 Thread Hlaaftana
You know that `wait` returns `Future[void]` and not `void`, yes? From this knowledge, I can tell you that Future is an object that contains an error field which `wait` will set if any exception is raised inside it. If you just call `wait(1000)`, you will ignore this error field, meaning if the a

What does asyncCheck do?

2018-10-08 Thread filip
ached because of the asyncCheck in test()? In that case, what does asyncCheck do? proc wait(time:int){.async.} = await sleepAsync(time) echo "Done waiting:", time proc test(){.async.} = while true: asyncCheck wait(1000) waitFor test() Run

Re: What does

2017-12-29 Thread Udiknedormin
It should not forbit it but allow it. Please notice that generics are almost replaceable by () operator (it should be replaceable by [] operator but then it only works when called explicitly, not by operator syntax): template Sth(t: typedesc = int): typedesc = type `Sth t` = o

Re: What does "invalid type" error mean in this context?

2017-12-28 Thread guibar
AFAIK the compiler instantiates generics only when they are used. Here the compiler considered the generated Shape as a generic type with no parameters, which is legal, but seems unusable. type Obj[] = object # no error var x: Obj # Error: invalid type: 'Obj'

Re: What does "invalid type" error mean in this context?

2017-12-28 Thread dawkot
Thank you, that's correct. Isn't it a bug that the macro compiled without any errors as long I would not use the generated type?

Re: What does "invalid type" error mean in this context?

2017-12-28 Thread guibar
Hello, It looks like you add generic parameters to your generated type even when there isn't any. I suggest you put an Empty node when you have no generic parameters, by changing the line 147 of your pastebin by: var genericParams = if genericParXs.len == 0: newNimNode(nnkEmpty) el

Re: What does "invalid type" error mean in this context?

2017-12-28 Thread dawkot
Forgot to add that the type actually gets generated, it's just that I can't use it.

What does "invalid type" error mean in this context?

2017-12-28 Thread dawkot
variant Shape: Cube(a, b: int, c: int) None Error var x: Shape #error Here's the entire abomination of a macro: [https://pastebin.com/m2pLkCNs](https://pastebin.com/m2pLkCNs)

Re: what does macros.quote() do exactly?

2017-11-05 Thread Udiknedormin
Sorry to hear it breaks for you, it works on my compiler. But give quote + getAst at try, it's recommended over quote-do anyway, if I recall. import macros macro decDumbType(): untyped = let sym = genSym(nnkType, "Dumb") template decl(ty) = type Dumb =

Re: what does macros.quote() do exactly?

2017-10-20 Thread bkerin
Seems to give almost the same output: > type > > > Dumb112023 = ref object of RootObj > contents: int > method frobnicate(this112025: Dumb112023) {.base.} = > echo "frobnicating!" and I still don't understand why Dumb turns into Dumb112023, maybe I will later

Re: what does macros.quote() do exactly?

2017-10-18 Thread Araq
`expandMacros` with its conversion to `typed` is really fragile with today's compiler. Instead use this to see what's going on: import future import macros macro decDumbType(): untyped = result = macros.quote do: type Dumb = ref object of RootObj

what does macros.quote() do exactly?

2017-10-17 Thread bkerin
Docs say: > Quasi-quoting operator. Accepts an expression or a block and returns the AST > that represents it. Within the quoted > AST, you are able to interpolate > NimNode expressions from the surrounding scope By this, I guess it likely means it pastes the sub-tree in at the given position?

Re: What does

2016-09-19 Thread _tulayang
In my opinion, "direct hardware access in Nim" means File System API, Socket API written by C. There are equivalent wrappers in Python (written by C and wrappered by Python). If you want to write some "direct hardware access" low-level API, you should comply with the specification of these C AP

Re: What does "direct hardware access" in Nim mean?

2016-09-17 Thread jangko
I don't think modern OSes will allow any user space application to access any hardware directly. Any hardware access must be performed through system calls(low level e.g. asm), which often encapsulated into function calls(higher level). But beside normal user space application, Nim can produce

Re: What does "direct hardware access" in Nim mean?

2016-09-17 Thread jlp765
Nim also allows [Assembler statements and expressions](http://forum.nim-lang.org///nim-lang.org/docs/manual.html#statements-and-expressions-assembler-statement)

Re: What does "direct hardware access" in Nim mean?

2016-09-16 Thread Krux02
It means that when hardware has mapped itself to some data in memory, nim can just read it and use it. I don't know how such things work in Python, but in java it is always a big hassle, because java always needs these buffer objects that on one hand give what you want to do with pointers, but w

What does "direct hardware access" in Nim mean?

2016-09-16 Thread Atlas
I've been a Python programmer, far away from low-level stuffs.