Re: Option type optimizations

2017-09-29 Thread mratsim
I'd love an Option[T] without overhead, was just looking for this. I'll just use "nil" for now but that would be better.

Re: what's the different between lock and reentrant lock in Nim

2017-09-29 Thread rayman22201
Nim doesn't expose that to the end user. The official docs for Nim locks say that whether a lock is re-entrant or not is "unspecified", so where are you seeing this? @See: [https://nim-lang.org/docs/locks.html#Lock](https://nim-lang.org/docs/locks.html#Lock) A re-entrant lock is a lock that

How to "nimble install XXX" using a specific architecture (x86, instead of x64)?

2017-09-29 Thread monster
Hi all! First post... After waiting about nine months for Nim in Action to finally be delivered to me, I got it 3 days ago. In the 3rd chapter, I should start to code. So I decided the first thing to do was obviously to install some Nim editor (I'm on Win10 x64). Now, after two whole evening,

Re: Code substitution with templates

2017-09-29 Thread Araq
> It seems to me it means something is wrong with Nim's symbol lookup. Or am I > missing something? I failed to guess what example you used to produce this error. This compiles: template someCode(name: untyped): untyped = type name {.inject.} = object fname: string

Re: perfomance of set/hashset operation between python and nim

2017-09-29 Thread Lando
@boia01: If a faster hash function is used, your code is one third faster than python. For those who want to try: clone [xxHash](https://github.com/Cyan4973/xxHash.git) right next to the Nim source file and insert this below the _import_ statement: import hashes const

Re: Code substitution with templates

2017-09-29 Thread Arrrrrrrrr
Well, you have no choice than use macros. If you don't want to deal with the ast, you can still [work with strings](https://glot.io/snippets/eu2z63ru1r): import macros, strutils macro typeGen(tName, extra: untyped): untyped = var typeStr = """ type

Re: Code substitution with templates

2017-09-29 Thread dataPulverizer
The above code was just an example. In general I would like to be able to paste code using templates or macros in a similar way that you can with D's string mixins which allow you to generate strings using functions and then paste them anywhere and generate code in compile time. In the above

Re: Python-like with, context managers, and the RAII pattern

2017-09-29 Thread stisa
`with` is a keyword, so you can't use that. You could use something like this maybe? import macros macro take(args,body:untyped):untyped = result = newstmtlist() result.add(newvarstmt(args[^1],args[1])) for st in body: result.add(st) take 3 as f:

Re: Python-like with, context managers, and the RAII pattern

2017-09-29 Thread wizzardx
Thanks for the replies Is it possible to express the "withAs" template as a macro? So that my example could look like this: with open("test.txt") as f: echo f.readLine() I think it should be possible, since eg nimpylib lets you use this syntax: class

Re: Automated testing of Nim programs

2017-09-29 Thread mratsim
It's from 1999. It would probably be better to work directly with a current Nim native library like Design by contract [https://forum.nim-lang.org/t/2479](https://forum.nim-lang.org/t/2479). Also I'd rather have those graduate students develop actual libraries (with unit tests). I don't think

what's the different between lock and reentrant lock in Nim

2017-09-29 Thread mashingan
I looked at two libs docs and found it's same between those two. What's the different between those?