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
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
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.
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?
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
Since `??` should offer lazy evaluation, you should use a template for it.
Don't you watch my talks?
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
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
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:
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)
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:
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
see also addr vs. unsafeAddr
[https://nim-lang.org/docs/system.html#unsafeAddr,T](https://nim-lang.org/docs/system.html#unsafeAddr,T)
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
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.
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
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
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
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
?? 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
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
I am looking for a way to evaluate Nim at run time, is there anything to
recommend?
Very useful, thank you
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
It is documented behavior, watch out with `untyped`.
Nice! Do add it to the Nimble packages repo when you get a chance
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.
After looking more closely it seems to only be a problem when you import
replace from strutils. This works
import strutils except replace
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
29 matches
Mail list logo