proc(t: typedesc): var t -- expected 'None' error

2018-03-27 Thread c0ntribut0r
I'm trying to simplify my program syntax by creating nice aliases. Cannot understand what's wrong when returning var t where t is typedesc: import tables proc getTableOf*(t: typedesc): ref Table[int, t] = var table {.global.} = newTable[int, t]() return table

Twinprimes generator that showcases Nim

2018-03-27 Thread jzakiya
It's been a long and interesting journey, but I've finally gotten this to a point where I feel I can release it. This is a `twinprimes` generator, that I did an initial version of back in 2014|5 in C++. Over time, I did a C++ parallel version using OpenMP. Then a few months ago, at the

Re: Reflection and JSON decoding

2018-03-27 Thread mashingan
I don't know your use case, but if I have to guess, you don't have to. If you only need a field or two, you can just retrieve the fields you need.

Re: Confusing behaviour with threads / channels

2018-03-27 Thread gmfawcett
Given the fact that Channels may break if they are copied, should the assignment operator / copy constructor be disabled for Channels? Are there any cases where copying a Channel makes sense?

Re: complex statement requires indentation

2018-03-27 Thread LeuGim
Didn't think about laziness, indeed, it should. template `??`[T](val, alternative: T): T = const zero = zeroval[T]() if val==zero: alternative else: when compiles(val.len): if val.len==0: alternative else: val else: val

Re: complex statement requires indentation

2018-03-27 Thread Araq
Since `??` should offer lazy evaluation, you should use a template for it. Don't you watch my talks?

Re: complex statement requires indentation

2018-03-27 Thread LeuGim
More universal, works with most types: proc zeroval[T]: T {.compiletime.} = discard proc `??`[T](val, alternative: T): T = const zero = zeroval[T]() if val==zero: return alternative when compiles(val.len): if val.len==0: return alternative val

cpp compilation into own namespace

2018-03-27 Thread adrianv
Hi, what do you think about an optional parameter to compile nim code into its own namespace "Nim" (or configurable). When compiling nim code together with a big c++ library it is very likely to get name clashes with the existing code - for example names like TFrame or Exception are used very

Re: Reflection and JSON decoding

2018-03-27 Thread diegogub
Thanks, that works..Also what I normally use in Golang is : switch v := i.(type) { case int: fmt.Printf("Twice %v is %v\n", v, v*2) case string: fmt.Printf("%q is %v bytes long\n", v, len(v)) default:

Re: Reflection and JSON decoding

2018-03-27 Thread mashingan
For newest stable version (0.18.0), there macro to defined here [https://nim-lang.org/docs/json.html#to.m,JsonNode,typedesc](https://nim-lang.org/docs/json.html#to.m,JsonNode,typedesc)

Re: Reflection and JSON decoding

2018-03-27 Thread dom96
There are two ways, by dynamically accessing each field as described [here](https://nim-lang.org/docs/json.html#dynamically-retrieving-fields-from-json) or by using the `to` macro:

Re: Addresses of variables and endian procedures

2018-03-27 Thread mratsim
A non-var argument has "no address" so that nothing inside the proc can "take the pointer and run" with an immutable parameter. If you need to, you can explicitly use unsafeAddr which means "i know what I'm doing and I won't let the parameter escape". Or if you want to mutate it, use a var

Re: Addresses of variables and endian procedures

2018-03-27 Thread lucian
see also addr vs. unsafeAddr [https://nim-lang.org/docs/system.html#unsafeAddr,T](https://nim-lang.org/docs/system.html#unsafeAddr,T)

Re: Partial code upgrades: important or meh?

2018-03-27 Thread Lando
In the JVM world, maven for Java and sbt for Scala have been used to build pretty large projects. Obviously, they run into the multi-version-dependency problem too, and they can handle it without "partial code upgrades" (not the smartest name IMHO). They use shading, which roughly means

Re: Possible misplaced paragraph in documentation

2018-03-27 Thread KevinGolding
Okay, so it looks like this has already been fixed by alaviss in version .18.1 but the website is showing .18.0 Just ignore this thread.

Re: Confusing behaviour with threads / channels

2018-03-27 Thread yglukhov
You can't copy a channel, what you're essentially doing in `var chan = arg.chanp[]`. Instead you can keep its address: `let chanp = arg.chanp`, and dereference it on recv: `var msg : InMsg = recv(chanp[])`. This is happening because Channel has mutexes, and posix mutexes don't like to be

Possible misplaced paragraph in documentation

2018-03-27 Thread KevinGolding
In the system module documentation ([https://nim-lang.org/docs/system.html#module-system](https://nim-lang.org/docs/system.html#module-system)) there is a paragraph that doesn't make much sense in the context it is shown, which is right after the heading 'Module system': "modify this variable

Re: Addresses of variables and endian procedures

2018-03-27 Thread mashingan
The argument when not stated, is using let , in other word it's like put the variable in stack, that's why it has no address. To bypass that, you must pass the var to the argument so it's using the same memory place in heap. import endians import strutils proc

Addresses of variables and endian procedures

2018-03-27 Thread sflennik
The following program generates the errors: t.nim(15, 17) template/generic instantiation from here t.nim(5, 28) Error: expression has no address Why does the expression buffer[0] have no address? import endians import strutils proc

Re: complex statement requires indentation

2018-03-27 Thread mashingan
?? operator can be defined like this: import strutils proc `??`[T](val, alternative: T): T = when T is string: if val.isNilOrEmpty: return alternative else: if val.isNil: return alternative val

Confusing behaviour with threads / channels

2018-03-27 Thread gmfawcett
I'm hoping someone can shed light on why this program occasionally fails to terminate. I compiled it with Nim 0.18.0 on Linux x64, GCC 5.4.0. During most executions, the worker threads receive their terminal message, and exit. But sometimes they don't get the message, so they are stuck in

Nim as a run time interpreter?

2018-03-27 Thread lotzz
I am looking for a way to evaluate Nim at run time, is there anything to recommend?

Re: Protocol Buffer library for Nim

2018-03-27 Thread cdome
Very useful, thank you

Re: Nim vs D

2018-03-27 Thread timothee
I've created a git repo to compare D vs nim, with the goal of having an up to date comparison of features between D and nim and 1:1 map of features and libraries to help D users learn nim and vice versa. Better as a git repo than a forum to have all info organized in 1 place. PR's are welcome

Re: Odd bug with ast and strutils.

2018-03-27 Thread Araq
It is documented behavior, watch out with `untyped`.

Re: Protocol Buffer library for Nim

2018-03-27 Thread dom96
Nice! Do add it to the Nimble packages repo when you get a chance

Re: Odd bug with ast and strutils.

2018-03-27 Thread solo989
Changing the macro name to something other then replace also works. Still seems like a bizarre interaction considering I never actually call the replace proc from strutils and the replace macro still gets called semi normally.

Re: Odd bug with ast and strutils.

2018-03-27 Thread solo989
After looking more closely it seems to only be a problem when you import replace from strutils. This works import strutils except replace

Odd bug with ast and strutils.

2018-03-27 Thread solo989
If you run this code with code with strutils imported the input arg is treated as typed instead of untyped. import macros import strutils macro replace(input: untyped, before: untyped, after: untyped) : untyped = echo treeRepr input echo treeRepr before